From erno-news at erno.iki.fi Fri Aug 10 13:33:01 2001 From: erno-news at erno.iki.fi (Erno Kuusela) Date: 10 Aug 2001 20:33:01 +0300 Subject: problems with regex in Japanese? References: <100820011007233964%joe@strout.net> Message-ID: In article <100820011007233964%joe at strout.net>, Joe Strout writes: | [[ This message was both posted and mailed: see | the "To," "Cc," and "Newsgroups" headers for details. ]] | My company is using the PCRE library in an international product. But | we're discovering some problems with its UTF-8 support, which is | causing grief for our Japanese users (and others). Since (AIUI) Python | also uses PCRE, I'm wondering if the Python community has encountered | these problems, and how they've been handled? python no longer uses pcre, the pcre based regexp module was replaced by a new unicode-aware implementation called sre (written by Fredrik Lundh). sre is much faster too... -- erno From alf at pisces.logilab.fr Thu Aug 9 06:48:29 2001 From: alf at pisces.logilab.fr (Alexandre Fayolle) Date: Thu, 9 Aug 2001 10:48:29 +0000 (UTC) Subject: Python and AI (was: AI contest) References: <3b6d3e72$1_1@news5.uncensored-news.com> <3b725bb5.10702165@nntp.ix.netcom.com> Message-ID: On Thu, 09 Aug 2001 09:45:28 GMT, Mike Clarkson wrote: > >>IMHO the extreme flexibility of data structures and procedures makes Python >>a superb language for AI (whatever that is) > >I agree. If Python as a language works as CP4E, then it should be able >to encompass AI. You may want to give a look at the Narval project. It is the implementation of a Agent development framework in Python. The currently released version works with python 1.5.2, but a 2.x compatible version is due for release Real Soon Now[tm] http://www.logilab.org/narval/ Alexandre Fayolle -- LOGILAB, Paris (France). http://www.logilab.com http://www.logilab.fr http://www.logilab.org Narval, the first software agent available as free software (GPL). From peter at engcorp.com Sun Aug 19 03:43:27 2001 From: peter at engcorp.com (Peter Hansen) Date: Sun, 19 Aug 2001 03:43:27 -0400 Subject: constant in python? References: <3B7E5390.C6966CAD@stroeder.com> <62vf7.4717$Vs2.403505@news.pacbell.net> Message-ID: <3B7F6E1F.5F1398E6@engcorp.com> [quoting style "corrected" by reordering] liam wrote: > "Michael Str?der" wrote: > > Brian Quinlan wrote: > > > The questions is why do you need explicit language support for > > > constants? Just don't change the value and it should behave constant > > > enough for you. > > > > To avoid that another developer in the team changes the constant > > accidently? > > agreed, its fine to leave it to yourself to know not to change a constant > but if its a big project constants would be a nice plus so your associates > dont mess thing up, accidently? Two words: "coding standard" PORT_NAME = 'COM1' portName = 'COM1' Only one of these may be changed by my "associates" ... no need for a "const" keyword (nor even Alex's little gem in most cases) ... (And, as usual with Python, it still leaves the door open for those cases where someone _really_ wants to change a so-called constant, probably during an awkward debugging session, or for a special test case or something. _Enforcing_ constancy would prevent that, which would not be very Pythonic.) -- ---------------------- Peter Hansen, P.Eng. peter at engcorp.com From mats at laplaza.org Mon Aug 27 18:27:40 2001 From: mats at laplaza.org (Mats Wichmann) Date: Mon, 27 Aug 2001 22:27:40 GMT Subject: Python versions (was Re: os.execl()) References: <20010827.094906.1398295499.2106@udel.edu> <200108271445.f7REjT7k007185@smtp5.andrew.cmu.edu> <9me028$ecq$1@panix2.panix.com> Message-ID: <3b8ac950.76149527@news.laplaza.org> On Mon, 27 Aug 2001 17:54:08 GMT, Sheila King wrote: :On 27 Aug 2001 10:29:44 -0700, aahz at panix.com (Aahz Maruch) wrote in :comp.lang.python in article <9me028$ecq$1 at panix2.panix.com>: : ::In article , ::Grant Edwards wrote: ::> ::>I didn't realize we were discussing 1.5.2. I assume people are ::>using a fairly recent version unless they specify otherwise. ::>Under 2.1, spawnv is available for Unix. I don't remember if it ::>was in 2.0. :: ::Until Red Hat et al upgrade the default installation, I assume there's a ::good chance questions refer to 1.5.2. : :I will second that. This is one of the primary reasons that my webhost :will not entertain upgrading the system Python to a more recent version. :He doesn't want to risk "breaking" something, and says that Python is :"built-in" to the system, somehow. Sigh. I have this problem with my ISP, and affecting only mailman. Mailman now depends on 2.x Python and since the ISP won't upgrade Python they can't upgrade Mailman. We're sinking into a hole here... :Plus, there is the whole thing, with some people not even wanting to :touch the RH 7.x. (I don't understand all the issues around this, but :the fact is that even if RH does update their Python in their install :routines, that some people don't even want to use the latest RH, for :some reason...) Youv'e got it wrong, Sheila. The problem is that people have learned from bitter experience not to trust Red Hat x.0 releases, the .1's are marginally useful, the .2's often actually work - but by that time they're almost ready for (x+1).0. Sigh. Unfortunately Red Hat have recently decided that they won't change major versions of key packages on minor Red Hat releases... so we're stuck with Python 1.5.2 as the default until, oh, about RedHat 8.2. Folks need to be told that Linux is wonderful, but Red Hat doesn't necessarily prove that in their choice of what to bundle... Mats Wichmann From tim.one at home.com Fri Aug 24 01:00:04 2001 From: tim.one at home.com (Tim Peters) Date: Fri, 24 Aug 2001 01:00:04 -0400 Subject: enhancing slicing In-Reply-To: Message-ID: [Steve Holden] > If I can remember my Icon correctly its slicing mechanism recognised > signs as significant, Right, but not quite as you remember it. > so > > seq[a:+b] > > meant take a slice of length b starting at position a, Unary + is nothing special; the syntax Icon uses is seq[a +: b] as sugar for seq[a : a+b] but evaluating "a" only once (significant if there are side-effects); likewise seq[a -: b] as sugar for seq[a-b : a] Python *could* do the same without breaking anything. I told Guido so often that he borrowed sequence slicing from Icon that he *almost* remembers it that way too . From gerson.kurz at t-online.de Thu Aug 30 12:41:59 2001 From: gerson.kurz at t-online.de (Gerson Kurz) Date: Thu, 30 Aug 2001 16:41:59 GMT Subject: Problem in multithreading Socketserver explained (should appl y to *nix, too) References: Message-ID: <3b8e6c9d.14242343@news.t-online.de> On Thu, 30 Aug 2001 07:55:52 -0700 (PDT), wrote: >So maybe it was an indentation bug fixed between 2.1 and 2.1.1. I'll go >look at the CVS look on SF. Today I installed ActivePython 2.1.1, and it is fixed in it [With, of course, the indent solution...] From gerson.kurz at t-online.de Thu Aug 30 03:21:57 2001 From: gerson.kurz at t-online.de (Gerson Kurz) Date: Thu, 30 Aug 2001 07:21:57 GMT Subject: Is there any editor support python? References: <9mk80i$hdf$1@mail.cn99.com> Message-ID: <3b8de94b.528890@news.isar.de> On Thu, 30 Aug 2001 10:21:56 -0700, "Formalin" wrote: >Is there any editor support python? I personally like SciTE best. Its Open Source. Its available for both Win32 and Linux (GNOME based). It supports many programming languages. Its available here: http://www.scintilla.org/SciTEDownload.html From markus at schabi.de Sun Aug 12 11:45:11 2001 From: markus at schabi.de (Markus Schaber) Date: Sun, 12 Aug 2001 17:45:11 +0200 Subject: choice between quotes thoughts References: <9l12mo$m7c$1@news.mathworks.com> Message-ID: <2065929.XNkdZ6W18F@lunix.schabi.de> Hi, Tom Good schrub: > Joshua Marshall wrote in message > news:<9l12mo$m7c$1 at news.mathworks.com>... >> I always use '. Holding down shift is just far too much effort. > > My thoughts exactly. Single quote doesn't require shifting -- it is > the 'automatic transmission' of string delimiters. > > This also explains why Lists are better than Tuples: typing (1,2,3) > requires two shifts, typing [1,2,3] requires none. ;-) Happy Americans! With German keyboard layout, we have to press Shift for (), " and ' as we have to use the Alt-Gr-Key to get {}s and []s. markus -- 1) Customers cause problems. 2) Marketing is trying to create more customers. Therefore: 3) Marketing is evil. (Grand Edwards in comp.lang.python) From ron.l.johnson at home.com Mon Aug 6 04:24:49 2001 From: ron.l.johnson at home.com (Ron Johnson) Date: Mon, 06 Aug 2001 08:24:49 GMT Subject: removing duplicate spaces from a string Message-ID: Hello, Say I have the strings: 'foo bar snafu' 'fiddle faddle pip pop' Are there any builtins that will allow me to compress the duplicate spaces out so that the files look like: 'foo bar snafu' 'fiddle faddle pip pop' I could iteratively apply string.replace, replacing ' ' with ' ', but that doesn't seem the optimum course. For anyone with VMS experience, I want to emulate the DCL lexical function F$EDIT("COMPRESS"). Sincerely, Ron +------------------------------------------------------------+ | Ron Johnson, Jr. Home: ron.l.johnson at home.com | | Jefferson, LA USA http://ronandheather.dhs.org | | | | "Our computers and their computers are the same color. The | | conversion should be no problem!" | | Unknown | +------------------------------------------------------------+ From Lutz.Schroeer at kybernetik-manufaktur.de Thu Aug 16 16:51:20 2001 From: Lutz.Schroeer at kybernetik-manufaktur.de (Lutz Schroeer) Date: 16 Aug 2001 20:51:20 GMT Subject: German Book for Python Beginner References: <9lb1ut$a7i$01$1@news.t-online.com> <72lbl9.j62.ln@gargamel.hqd-internal> Message-ID: gerhard.nospam at bigfoot.de (Gerhard H?ring) wrote in news:72lbl9.j62.ln at gargamel.hqd-internal: > I'd probably go for "Einf?hrung in Python" by Mark Lutz and David > Ascher. I used this book to get addicted to Python ("anfixen" in German ;-). But be aware, this ain't no book for beginners. You should have some experience in some other programming language[s] and in the basics of object orientated programming to have fun, otherwise it's hard work (at least IMHO). It costs 69,- German Marks for 380 pages and it's one of of the special O'Reilly bounded softcovers (the "Buchr?cken" (don't know the English term) isn't destroyed if you open it 180 degrees). Buy it, enjoy it and terrorize your colleagues by repeating "In Python this would be easily done in lines" :-)) Lutz (at the time forced to learn Visual Basic by his employer) From emile at fenx.com Wed Aug 29 23:28:52 2001 From: emile at fenx.com (Emile van Sebille) Date: Wed, 29 Aug 2001 20:28:52 -0700 Subject: zope setup with @home connection References: Message-ID: <9mkc62$2ppa7$1@ID-11957.news.dfncis.de> Not! -- Emile van Sebille emile at fenx.com --------- "L" wrote in message news:e5f40188.0108291927.5ee06bdb at posting.google.com... > @home has permanently blocked all web servers because of code red, > regardless of port. From achim.domma at syynx.de Wed Aug 1 09:46:21 2001 From: achim.domma at syynx.de (Achim Domma) Date: Wed, 1 Aug 2001 15:46:21 +0200 Subject: Large pages using Zope References: <9k766t$dc0$04$1@news.t-online.com> <3B674802.C730D678@engcorp.com> <5F49B5CBF5054C94.33E4B38F094277B1.1DDFF7F8A2A4AD86@lp.airnews.net> Message-ID: <9k917d$ka6$03$1@news.t-online.com> "Cameron Laird" wrote in message news:5F49B5CBF5054C94.33E4B38F094277B1.1DDFF7F8A2A4AD86 at lp.airnews.net... > Mr. Domma, I have a similar question. Are you saying > that you're replacing client-side JScript and VBScript > with server-side Python? Architectural redesign inter- > ests me; what kinds of service were JScript and VBScript > giving you? Did they reach to your CORBA-DB back end? No, sorry for the confusion but I only spoke about server side programming. We are currently using IIS with ASP-pages written in JScript and VBScript but want to switch to a plattform independet solution. I think direct connection from the client via script to the server is only possible in a pure MS environment. The xml-datasource of IE5 should be able to get his data via http from a SQL-Server. But that is not the topic of this group ... greetings Achim From gerhard.nospam at bigfoot.de Tue Aug 21 14:52:17 2001 From: gerhard.nospam at bigfoot.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Tue, 21 Aug 2001 20:52:17 +0200 Subject: PyQt binary for Windows....but? References: <4a249347.0108131604.44a5c4fc@posting.google.com> <3112302e.0108140120.5df65f46@posting.google.com> Message-ID: <1laul9.pg1.ln@gargamel.hqd-internal> On 21 Aug 2001 13:31:44 -0500, Greg Copeland wrote: >Does the KDE libs also work? Last I looked, PyQT was really made up of >two libraries. Once was the qt lib and the other way the kde lib. Does >the KDE lib work/come with the Win distro? KDE doesn't run on native win32. IIRC there is a team to get it working on Cygwin/X11, though. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ public key at homepage public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From drew_csillag at geocities.com Fri Aug 24 09:12:39 2001 From: drew_csillag at geocities.com (Drew Csillag) Date: Fri, 24 Aug 2001 09:12:39 -0400 Subject: [ANN] SkunkWeb 3.0 Released! In-Reply-To: ; from phd@phd.pp.ru on Fri, Aug 24, 2001 at 05:01:09PM +0400 References: <20010824084053.F930@naxos.starmedia.net> Message-ID: <20010824091239.G930@naxos.starmedia.net> On Fri, Aug 24, 2001 at 05:01:09PM +0400, Oleg Broytmann wrote: > On Fri, 24 Aug 2001, Drew Csillag wrote: > > On Thu, Aug 23, 2001 at 11:37:48PM -0700, Paul Rubin wrote: > > > This sounds pretty interesting. How does it compare to Mason? > > > > Mason and SkunkWeb compare rather well with each other, as they do tend > > to attack the web serving problem in similar ways. > > > > * Mason and SkunkWeb > [skip] > > Wow! This should be published somewhere as a mini-HOWTO. Nice > observation! Funny you mention it... The beginnings of the SkunkWeb FAQ are here: http://skunkweb.sourceforge.net/FAQ.html Cheers, Drew -- print(lambda(m,d,y):['Sun','Mon','Tues','Wednes','Thurs','Fri','Satur' ][(lambda(m,d,y):(23*m/9+d+4+y/4-y/100+y/400)%7)(m<3and(m,d+y,y-1)or( m,d+(y-2),y))])(map(int,raw_input('mm/dd/yyyy>').split('/')))+'day' From michael at rcp.co.uk Wed Aug 1 03:02:47 2001 From: michael at rcp.co.uk (Michael Abbott) Date: Wed, 1 Aug 2001 07:02:47 +0000 (UTC) Subject: Typing system vs. Java References: <996641770.29578@yabetcha.sttl.drizzle.com> Message-ID: Donn Cave wrote in news:996641770.29578 at yabetcha.sttl.drizzle.com: > On a different note, explicit type annotations arguably make a program > easier to understand. I absolutely agree with this (except for the "arguably" bit :)). From rnd at onego.ru Sun Aug 5 10:06:55 2001 From: rnd at onego.ru (Roman Suzi) Date: Sun, 5 Aug 2001 18:06:55 +0400 (MSD) Subject: Issue with function keyword defaults In-Reply-To: Message-ID: On Sun, 5 Aug 2001, Morten W. Petersen wrote: >Hi, > >after trying to set an empty dictionary as a default keyword arguments' >value, this happened (same thing happened on 2.0.1 BTW): > >morten at debian:~$ python >Python 1.5.2 (#0, Apr 10 2001, 10:03:44) [GCC 2.95.3 20010219 >(prerelease)] on linux2 Copyright 1991-1995 Stichting Mathematisch >Centrum, Amsterdam >>>> import time >>>> def test(r={}): >... r[time.time()] = time.time() >... return r >... >>>> test() >{997015577.922: 997015577.922} >>>> test() >{997015578.849: 997015578.849, 997015577.922: 997015577.922} >>>> test() >{997015579.446: 997015579.446, 997015578.849: 997015578.849, > 997015577.922: 997015577.922 > >I would assume that r would be re-initialized on every call, but that's >not happening; could anyone explain this behaviour? This is widely known trap. r is ONE instance for all function calls. Better (idiomatic) approach is: def test(r=None): r = r or {} r[time.time()] = time.time() return r (Same happens for all mutable objects. The rule is not to put mutables as default values unless the effect is wanted or they aren't modified.) Sincerely yours, Roman Suzi -- _/ Russia _/ Karelia _/ Petrozavodsk _/ rnd at onego.ru _/ _/ Sunday, August 05, 2001 _/ Powered by Linux RedHat 6.2 _/ _/ "By all means, let's not confuse ourselves with the facts!" _/ From bokr at accessone.com Sun Aug 12 23:19:11 2001 From: bokr at accessone.com (Bengt Richter) Date: Mon, 13 Aug 2001 03:19:11 GMT Subject: Typing system vs. Java References: <9l0sis0k8m@enews2.newsguy.com> <3187511.KiObB369e8@lunix.schabi.de> <3b74379c.492155281@wa.news.verio.net> <1591616.O8KEF6KIFk@lunix.schabi.de> Message-ID: <3b77477b.692826211@wa.news.verio.net> On Sat, 11 Aug 2001 01:54:43 +0200, Markus Schaber wrote: >Hi, > >Bengt Richter schrub: > >> E.g., what if there were a 'restricted' keyword (or you pick one ;-) >> which allowed the compiler to assume that a function's arguments would >> always be the same types as in provided default arguments, and that >> there would be no global side effects, and global references would be >> stable as to type? It would seem you could allocate local working >> storage on the stack and avoid reference counting and lookup to a >> large extent. > >But you can't save the lookups between different objects of the same >type, because "same type" means "same interface", not "same >implementation". > I had in mind an *ignorable* hint to the compiler, so that *some* platforms could *optionally* generate platform-specific optimized code for restricted kinds of function definitions or expressions. Since this would be specially generated for a particular platform, "same type" could presumably be restricted/coerced to "same representation type". E.g., it should be possible to generate extra fast code for evaluating a polynomial expression, without writing an extension. One could even imagine an optimization mode that would speculatively (no hints in code) produce optimized code for an inferred situation with fast checks to verify assumptions and go ahead if ok, and non-optimized code to handle the case if not. There could be an optional dictionary of compilable entities with optimization levels/info that the compiler could check if present (which would amount to externalized hints). >And trickery with the reference counting may get you into problems when >using multithreading. Assume, you don't increase the reference count >for local variables - than another thread may kill the last counted >reference, and the object is freed erreaneously. > For what I hand in mind, a restricted function would be stateless and reentrant, so different threads would get their own local storage. For global references (immutable objects only), I imagine reference count would be incremented at compile time, and decremented when the compiled code object was deleted, not at execution time. Suitable global mutable objects could be copied at compile time, with that understanding. If you were writing multi-threaded stuff that depended on non-reentrant semantics, you wouldn't be able to use the restricted hint. I don't mean to say that that absolutely couldn't be loosened, but just to start somewhere. From nicoe at wanadoo.be Wed Aug 29 11:18:46 2001 From: nicoe at wanadoo.be (Nicolas Evrard) Date: Wed, 29 Aug 2001 17:18:46 +0200 Subject: strange behavior of the comparison operator In-Reply-To: <20010829171028.B8680@Nutella>; from nicoe@wanadoo.be on Wed, Aug 29, 2001 at 17:10:28 +0200 References: <20010829171028.B8680@Nutella> Message-ID: <20010829171846.E8680@Nutella> Hello everyone, this is my first post to the list and let me say that I find python really exciting ... Looks a bit like scheme but is fast and have a large community of users ... Here 's what I've done : To try the __comp__ method I've done a class for complex number (the usual example). But here are the result I've got : >>> Complex(7,2).__comp__(Complex(3,4)) 1 >>> Complex(7,2) < Complex(3,4) 1 the definition of __comp__ I've done : def __comp__(self, other) : if self.r < other.r : return -1 elif self.r == other.r : if self.i < other.i : return -1 elif self.i == other.i : return 0 else : return 1 But in the reference manual it says that __comp__ should return a positive integer if self > other ... and obviously it isn't the case. BTW i'm using python 1.5.2 -- --------------------------------------- -?) Evrard Nicolas Happily using: /\\ Li?ge (Belgium) DEBIAN GNU\LINUX _\// ------------------------------------------- From mikhael at lib-sys.com Mon Aug 20 14:03:51 2001 From: mikhael at lib-sys.com (Mikhael Loo) Date: Mon, 20 Aug 2001 14:03:51 -0400 Subject: Opening New files Message-ID: <3b814f34_3@news.chartertn.net> What code do you used to open a new file. I've been opening existing files on MSW but I'm having trouble with my files and I think that I may need to use something besides open() if the file doesn't already exists. -Mikhael From qrczak at knm.org.pl Wed Aug 1 13:36:05 2001 From: qrczak at knm.org.pl (Marcin 'Qrczak' Kowalczyk) Date: 1 Aug 2001 17:36:05 GMT Subject: 2.2 features References: Message-ID: Wed, 01 Aug 2001 09:15:27 -0700, Paul Prescod pisze: > Second, I think that this might be worth adding new syntax for one > reason. The current syntax for exception-type trapping is extremely > error prone and nasty and it is essentially the same problem. I > could imagine: > > try: > foo() > except exc isa OverflowError, ZeroDivisionError: > pass Instead of commas an operator could be used which produces an object whose __contains__ tests whether the given object belongs to either of arguments. Obvious candidates are | or +, so try: foo() except OverflowError | ZeroDivisionError: pass works and if obj in (int | float) works using the same mechanism. Or maybe with + instead of |. -- __("< Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/ \__/ ^^ SYGNATURA ZAST?PCZA QRCZAK From tim.one at home.com Fri Aug 31 13:18:35 2001 From: tim.one at home.com (Tim Peters) Date: Fri, 31 Aug 2001 13:18:35 -0400 Subject: char** to {'':('',)} In-Reply-To: <9mocc301q7f@drn.newsguy.com> Message-ID: [Tim] > The Python implementation has many examples of this, jumping to an > error label at the end when things go wrong "in the middle". [Grant Griffin] > That's a good reason. (I've also found gotos quite helpful in > converting Fortran to C .) > > I can't say I use them much, but I _am_ a big fan of the "almost-goto" > constructs like return, break, and continue. In particular, I > like to do early returns to avoid needless nesting. Ignacio is hung up on a four-letter word, and is thereby doomed to write code that's needlessly brittle. The way goto is used in Python's implementation is usually a simple by-hand compilation of the higher-level construct (which can't be coded *directly* in C): initialize temps and result to NULL try: # normal stuff, but when an error occurs, do raise error # more stuff except error: Py_XDECREF(result); result = NULL; Py_XDECREF(temp1); ... Py_XDECREF(tempn); return result; Look back at the pattern I suggested with gotos, and you'll see that it's implementing exactly that: initialize temps and result to NULL # normal stuff, but when an error occurs, do goto error; # more stuff goto normal_return; error: Py_XDECREF(result); result = NULL; /* fall-through */ normal_return: Py_XDECREF(temp1); ... Py_XDECREF(tempn); return result; It's not the gotos that make this more robust, it's the higher-level construct they're *implementing*, and that construct is exactly on-target for preventing "stupid mistakes" in letting temps leak, or letting a partial result leak in an error case. If you suffer KFG (Kneejerk Fear of Goto), I suppose you could do initialize temps and result to NULL int erroneous = 0; do { # normal stuff, but when an error occurs, do erroneous = 1; break; /* and hope we're breaking out of the 'do'! */ # more stuff } while(0); if (erroneous) { Py_XDECREF(result); result = NULL; } Py_XDECREF(temp1); ... Py_XDECREF(tempn); return result; but that's no improvement by any rational measure ... we-won't-talk-about-python's-use-of-goto-in-the-lexer-ly y'rs - tim From martin at strakt.com Wed Aug 8 06:04:12 2001 From: martin at strakt.com (Martin Sjögren) Date: Wed, 8 Aug 2001 12:04:12 +0200 Subject: Exception confusion Message-ID: <20010808120412.A13034@strakt.com> I wrote this little test script: try: raise Exception, "foo" except Exception, arg: print type(arg) And it said (i.e. the exception object) When I tried this: try: raise Exception, "foo" except Exception, (arg,): print type(arg) It said . Happy with that, I tried to raise a tuple instead: try: raise Exception, ("foo", "bar"): except Exception, (arg,): print type(arg) and it said "ValueError: unpack sequence of wrong size". try: raise Exception, ("foo", "bar"): except Exception, arg: print type(arg) still says that arg is an instance. So I manually have to do: try: raise Exception, ("foo", "bar"): except Exception, (arg1,arg2): print type(arg1), type(arg2) which says that both arg1 and arg2 are strings. Doesn't this strike anybody as inconsequent? Here's another interesting thing: try: raise Exception, ["foo"] except Exception, arg: print arg[0] says ['foo'] while try: raise Exception, ["foo"] except Exception, (arg,): print arg[0] says foo. So the exception object IS subscriptable, but it doesn't do anything?? Anybody have any comments, 'cause I'm confused... Does any of this warrant a bug report? And-I-thought-exceptions-were-confusing-before-this-ly y'rs - Martin -- Martin Sj?gren martin at strakt.com ICQ : 41245059 Phone: +46 (0)31 405242 Cell: +46 (0)739 169191 GPG key: http://www.strakt.com/~martin/gpg.html From robin at jessikat.fsnet.co.uk Sat Aug 11 06:24:00 2001 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Sat, 11 Aug 2001 11:24:00 +0100 Subject: 2.1.1 global weirds Message-ID: I have difficulty in understanding why the print n, len(getStory()), len(_story) always prints n, 0, 0 why is b2.getStory not getStory? Is it because importing from a isn't the same as the importing from the __main__ module? What is the correct way to import from the main script? when I run a.py I see 0 0 0 1 0 0 2 0 0 [1, 2] 0 #a.py _story = [] def getStory(): return _story def func(n): getStory().append(n) def run(): print 0, len(getStory()), len(_story) import b1 print 1, len(getStory()), len(_story) import b2 print 2, len(getStory()), len(_story) print b2.getStory() print b2.getStory is getStory if __name__=='__main__': run() #b1.py from a import getStory, func func(1) #b2.py from a import getStory, func func(2) -- Robin Becker From phr-n2001 at nightsong.com Thu Aug 23 01:03:33 2001 From: phr-n2001 at nightsong.com (Paul Rubin) Date: 22 Aug 2001 22:03:33 -0700 Subject: Reference counting garbage collection References: Message-ID: <7xd75nnza2.fsf@ruckus.brouhaha.com> "Brian Quinlan" writes: > Huh? It seems like the deterministic behavior of reference counting > would be of benefit to large, long-running programs. Or are you thinking > of large, long-running programs that create a lot of cyclic references? Why is determinism such an issue? From aleax at aleax.it Thu Aug 9 05:35:31 2001 From: aleax at aleax.it (Alex Martelli) Date: Thu, 9 Aug 2001 11:35:31 +0200 Subject: a break for comprehensions References: Message-ID: <9ktlh101uva@enews1.newsguy.com> "Cliff Crawford" wrote in message news:L_nc7.241033$EF2.29456854 at typhoon.nyroc.rr.com... > * Cliff Crawford menulis: > | > | Then you can do stuff like the following, which simulates the Unix 'cat' > | command (warning: untested): > | > | files = reduce(lambda x, y: x+y, GenList(iter(open(sys.argv[1:])))) > > Ooops, that should be > > files = reduce(lambda x, y: x+y, > [GenList(iter(open(filename))) for filename in sys.argv[1:]]) I think it should be files = reduce(operator.add, # whatever after an import operator somewhere, of course. I strongly suggest NOT using lambda to duplicate the functions already supplied by module operator -- it's slow and messy!-) Alex From MarkH at ActiveState.com Sun Aug 26 18:06:15 2001 From: MarkH at ActiveState.com (Mark Hammond) Date: Sun, 26 Aug 2001 22:06:15 GMT Subject: Help: using msvcrt for file locking References: <7f6hot47j69t1lggtr86bhvc6i2l5q1kn2@4ax.com> <71jiotg3cbdpb6maid4fpa4ql3tjik8euh@4ax.com> Message-ID: <3B89737D.8060901@ActiveState.com> Sheila King wrote: > On Sun, 26 Aug 2001 16:19:36 GMT, Sheila King wrote > in comp.lang.python in article > : > > : > :I really don't see any way around file locking for the type of > :application I'm trying to write. However, I guess after seeing all the > :trouble with the msvcrt module, and how it doesn't even seem to allow > :shared locking access to a file, that I will go ahead and use the > :win32all extensions. I'm supposing that will allow better control? > > It appears, after a bit more research, that this will not work for all > win32 platforms, anyway. Apparently unsupported on Win95/98/Me: > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/hh/winbase/filesio_39h4.asp > > (scroll down to just below where it says "requirements") It appears that LockFileEx is designed specifically for files that use "overlapped IO". Indeed, the "portalocker" recipe explicitly uses overlapped IO structures. Try using LockFile - the MSDN documentation implies that it is supported on all Win32 platforms, and the error you get: pywintypes.api_error: (120, 'LockFileEx', 'This function is only valid in Win32 mode.') implies you are running on Win9x. A quick look at portalocker implies you will also want to drop all references to "_overlapped" - replace them with "None". Mark. From qrczak at knm.org.pl Wed Aug 29 07:26:45 2001 From: qrczak at knm.org.pl (Marcin 'Qrczak' Kowalczyk) Date: 29 Aug 2001 11:26:45 GMT Subject: Concatenating iterators References: <9mhaee$brn$1@tyfon.itea.ntnu.no> Message-ID: Wed, 29 Aug 2001 01:45:18 +0200, Magnus Lie Hetland pisze: > Is there a standard way of concatenating iterators yet? I'm afraid it can't be done simpler than by making a function like this: def concat(*its): for it in its: for x in it: yield x -- __("< Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/ \__/ ^^ SYGNATURA ZAST?PCZA QRCZAK From phd at phd.pp.ru Tue Aug 14 12:00:15 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Tue, 14 Aug 2001 20:00:15 +0400 (MSD) Subject: =?windows-1251?Q?=CD=C0=CB=CE=C3=CE=C2=C0=DF_=CF=CE=CB=C8=D6=C8=DF_=CD=C5_=C4=D0=C5=CC=CB=C5=D2_!!!?= In-Reply-To: <216772001821415364863@Yang> Message-ID: On Tue, 14 Aug 2001, =?windows-1251?Q?=DE=F0=E8=E4=E8=F7=E5=F1=EA=E8=E9_=F6=E5=ED=F2=F0_=CC=CE=D1=D2?= wrote: [skip] It was russian spam. Please everyone complain to abuse at att.net (Administrator of network where email originates) abuse at dialtoneinternet.net (Administrator of network hosting website referenced in spam) abuse at staff.mail.com (Administrator of network hosting email address referenced in spam) (information from spamcop.net) Oleg. ---- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From ruNsOhSiPnAgM at earthling.net Wed Aug 15 17:46:57 2001 From: ruNsOhSiPnAgM at earthling.net (S11001001) Date: Wed, 15 Aug 2001 16:46:57 -0500 Subject: Newbie, need tutorial D/L References: <9ldcet01ki2@enews3.newsguy.com> Message-ID: Am aware of 2.4.8. However, the Linmodem driver from PCTEL is written for 2.2.5. I think someone patched it for 2.3.?, but not sure on that part. Therefore, am going with 2.2.5. It's better than the one I have (2.2.16)...if you have a PCTEL linmodem driver for 2.4.8, by all means tell me! Also, I noticed that the kernel bloated between 2.2.x and 2.4.x. Why is that, anyway? -- Linux is not in the public domain. Linux is a cancer that attaches itself in an intellectual property sense to everything it touches. Steve Ballmer Alex Martelli wrote in message news:9ldcet01ki2 at enews3.newsguy.com... > "S11001001" wrote in message > news:oche7.404$n57.237388 at newsfeed.slurp.net... > > I am only a newbie to python, a perl refugee, in fact. I need a > DOWNLOADABLE, > > as in one tarball or something, tutorial employing DESCRIPTION. I cannot > leave > > You may like http://diveintopython.org/download/diveintopython-pdf-3.5-1.zip > the current version of 'Dive into Python'. It's very fast-paced and it does > give > the impression that the author comes from a Perl background, too. > > > the internet connection running as I page through the tutorial at > python.org, > > so I can't go that route. Once I get kernel 2.2.5, I will be able to do > > Internet in Linux, so it will probably be alright. But I prefer to learn > > offline. > > Why 2.2.5 when the current stable version is 2.4.8...? Just curious! > > > Alex > > > From matt at mondoinfo.com Thu Aug 30 16:41:51 2001 From: matt at mondoinfo.com (Matthew Dixon Cowles) Date: Thu, 30 Aug 2001 20:41:51 GMT Subject: how do i make a grapical thingie? References: Message-ID: Dear Jeroen, >I'm using python for one day now Welcome! >and the only thing i van do is import sys and exit() and print >"hello". I want messageboxes! how? The most common graphical interface for Python is Tkinter. There's good documentation at: http://www.pythonware.com/library/tkinter/introduction/index.htm Like all graphical interfaces, using it can be a little complex. You might want to get a little more experience with Python before you started using it heavily. There's good introductory documentation linked from: http://www.python.org/doc/Intros.html Have fun with Python! Regards, Matt From sheila at spamcop.net Thu Aug 9 00:25:40 2001 From: sheila at spamcop.net (Sheila King) Date: Thu, 09 Aug 2001 04:25:40 GMT Subject: Popmail.py Need help..................... References: <%Pnc7.5649$V43.473350@e3500-atl1.usenetserver.com> Message-ID: When I used Sam Spade utilities and tried to do a traceroute on pop.mail.mia.bellsouth.net I got the message "no such host" So, I'd say that you have the hostname incorrect. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ On Thu, 9 Aug 2001 00:04:47 -0400, "Relfx" wrote in comp.lang.python in article <%Pnc7.5649$V43.473350 at e3500-atl1.usenetserver.com>: :I have tried using these modules but i'm getting some errors when i run the :script. : :Here is the code i'm using for the pop mail : : :import getpass , poplib :M = poplib.POP3('pop.mail.mia.bellsouth.net') :M.user(getpass.getuser()) :M.pass_(getpass.getpass()) :numMessages = len(M.list()[1]) :for i in range (numMessages): : for j in M.retr (i+1)[1]: : print j : :>>> :Traceback (most recent call last): : File "", line 1, in ? : File "C:\Python21\Scripts\popmail.py", line 2, in ? : M = poplib.POP3('pop.mail.mia.bellsouth.net') : File "C:\PYTHON21\lib\poplib.py", line 79, in __init__ : self.sock.connect((self.host, self.port)) : File "", line 1, in connect :error: host not found : : : From aleax at aleax.it Tue Aug 14 04:26:50 2001 From: aleax at aleax.it (Alex Martelli) Date: Tue, 14 Aug 2001 10:26:50 +0200 Subject: abstract features References: <9l954g01cpl@drn.newsguy.com> <89hhntoaqhok150qcv4v5ue9vk9sg7svlq@4ax.com> Message-ID: <9lancb018fu@enews1.newsguy.com> "Courageous" wrote in message news:89hhntoaqhok150qcv4v5ue9vk9sg7svlq at 4ax.com... ... > When I first learned slices, I thought they were just plain radical. Python gets a As I have an APL background, Python's slices seemed pretty tame to me in comparison...:-). Alex From aleaxit at yahoo.com Thu Aug 16 17:47:17 2001 From: aleaxit at yahoo.com (Alex Martelli) Date: Thu, 16 Aug 2001 23:47:17 +0200 Subject: zlib compressionobj use: what am I missing? References: <9lhcom$8ao$1@chabry.caltech.edu> Message-ID: <9lhf5e023rl@enews3.newsguy.com> "Titus Brown" wrote in message news:9lhcom$8ao$1 at chabry.caltech.edu... > Hi all, I'm working on a patch to the zlibmodule, but I can't get this > bit of code for testing compression objects to work at all. Should it? > If not, what am I doing wrong?? > zlib.decompress(compdata) Only thing I can think of, is you're throwing the result of decompress away -- with a print here, this works fine for me. Alex From rnd at onego.ru Mon Aug 13 16:17:34 2001 From: rnd at onego.ru (Roman Suzi) Date: Tue, 14 Aug 2001 00:17:34 +0400 (MSD) Subject: assignment to __class__ (was Re: Copy constructors) In-Reply-To: Message-ID: One more question. Python programmers use the following idiom: class A: # ... def __mul__(self, other): ... __rmul__ = __mul__ If I understood correctly, __rmul__ will be of different category from __mul__? This causes asymmetry... Sincerely yours, Roman Suzi -- _/ Russia _/ Karelia _/ Petrozavodsk _/ rnd at onego.ru _/ _/ Monday, August 13, 2001 _/ Powered by Linux RedHat 6.2 _/ _/ "I distinctly remember forgetting that." _/ From boudewijn at tryllian.com Mon Aug 27 04:44:38 2001 From: boudewijn at tryllian.com (Boudewijn Rempt) Date: Mon, 27 Aug 2001 10:44:38 +0200 Subject: Automating UI tests (was Re: Art of Unit Testing) References: <3B7D29E0.602AF8BD@earthlink.net> <3b88359d.7036398@nntp.ix.netcom.com> Message-ID: <3b8a0802$0$294$e4fe514c@newszilla.xs4all.nl> Mike Clarkson wrote: > > It's probably easier than you think: look at the Tk 'event' command. > It can deliver an arbitrary keyboard mouse or virtual event to any Tk > widget. > > In your UI code, setup a dictionary which contains the widgets > that you want to test by sending events to, so that you can refer to > then in the testng code. Then in the testing code, use the event > command to send thngs like events to those widgets. > > Note that if you are testing Dialogs (popped up windows with a grab) > you probably have to use the Tk 'after' command to queue up the events > before instantiating the Dialog. > > Mike. In PyQt, I use a a small extra framework to test whether signals arrive. This way, I can check whether the signals that the underlying logic sends fit what the GUI will expect. That can be extended to send signals to the GUI and check whether the GUI components do the right thing on getting them - it's a bit comparable to what you describe, but still no substitute for user tests, I'm afraid. -- Boudewijn | http://www.valdyas.org From stephen_purcell at yahoo.com Mon Aug 6 14:44:51 2001 From: stephen_purcell at yahoo.com (Steve Purcell) Date: Mon, 6 Aug 2001 20:44:51 +0200 Subject: [ANNOUNCE] PyUnit 1.4 released Message-ID: <20010806204451.A29693@freedom.puma-ag.com> Version 1.4 of the PyUnit testing framework has just been released. The primary intention of this release is to provide a standalone package of the same PyUnit code contained in the Python 2.1 standard library. This is primarily for the benefit of those who use older (or Java-flavoured) versions of Python. The release may also be of interest to Python 2.1 users who would like to run their tests using the Tkinter-based GUI test runner tool which is part of the PyUnit package but is not contained in the Python standard library. Summary of changes since version 1.3.1: - Updated documentation - main() runs all tests in the module __main__ by default - New code allows all test cases in a given module to be located and instantiated - Simplified command line syntax - Made TextTestRunner configurable with verbose and quiet options, and consequently removed obsoleted JUnitTextTestRunner - Test instantiation code now localised in a replaceable TestLoader class - Distutils 'setup.py' contributed by Bill Bumgarner - TestResult.addSuccess() method added (thanks to Frederic Corne) - Stop overridden test methods being run twice (thanks to Brian Zimmer and Maas-Marten Zeeman) - Don't expand GUI's progress bar vertically when resizing (Fred Drake) The release is available from the PyUnit homepage at http://pyunit.sourceforge.net/ or directly from http://prdownloads.sourceforge.net/pyunit/pyunit-1.4.0.tar.gz Very best wishes to all, -Steve -- Steve Purcell, Pythangelist Get testing at http://pyunit.sourceforge.net/ Test your web apps with http://webunit.sourceforge.net/ From vvainio at karhu.tp.spt.fi Wed Aug 8 01:26:52 2001 From: vvainio at karhu.tp.spt.fi (Ville Vainio) Date: 08 Aug 2001 08:26:52 +0300 Subject: Linked lists (was Re: Typing system vs. Java References: <9ko4ld013pc@enews1.newsguy.com> <3b707aa4.591122937@news.supernews.com> Message-ID: xtian at hyperactive.co.nz writes: > That's pretty spectacularly neat. Yes, it is. Gems like that should end up in the tutorial to "whet the appetite". Now all we need is an iterator for the list, no batter how tainted and impure that might be... ;-) How does this kind of list improve performance of lisp-ish recursive functions, as opposed to cdr = list[1:]? I guess there was a benchmark a while ago (some kind of "language shootout") that did use list[1:] and made Python look bad. -- Ville Vainio - http://www.tp.spt.fi/~vvainio - ICQ #115524762 Wild geese have no intention to cast a reflection Water has no mind to assume their form From drg at longhands.org Thu Aug 23 20:24:26 2001 From: drg at longhands.org (Dan Girellini) Date: 23 Aug 2001 20:24:26 -0400 Subject: dumb newbie list question References: <9lppug$k91$1@slb7.atl.mindspring.net> Message-ID: Yes this, basically what I was looking for. Thanks for all the responses. I appreciate the help. --dan. -- "AD" == Andrew Dalke writes: AD> Dan Girellini: >>> Is there an easy way to do this without building a second list of the >>> right size and concatenating them? AD> Bernd Nawothnig: >> Why will you do this? >> >> l=l+(10-len(l))*['x'] >> >> works fine and should be faster then many l.append('x') AD> If you don't want to create a new list, you could also do AD> l.extend( [None] * (10-len(l)) ) AD> (Using None is closer to the way Perl does it than using 'x'.) From jafo-pythonlist at tummy.com Wed Aug 1 01:46:55 2001 From: jafo-pythonlist at tummy.com (Sean Reifschneider) Date: Tue, 31 Jul 2001 23:46:55 -0600 Subject: decent syslog replacement? In-Reply-To: ; from henken@seas.upenn.edu on Tue, Jul 31, 2001 at 01:43:11PM -0400 References: <20010801011857.A8795@Vetinari.home> Message-ID: <20010731234655.A15852@tummy.com> On Tue, Jul 31, 2001 at 01:43:11PM -0400, Nicholas Henke wrote: >Thanks...I forgot about the syslog - thing...The main problem is the >syslog disk thrashing...I guess I wasnt really clear about that. Are there >any clean options to buffer even more than syslog might do? Adding the "-" should resolve the problem you're seeing, as was mentioned. If you want copious amounts of control over how your syslog is buffering, switch to syslog-ng. See freshmeat.net if you need a pointer. Sean -- I'd like an order of fries, a quarter-pounder with cheese, I love the light in your eyes, will you go out with me please. Sean Reifschneider, Inimitably Superfluous tummy.com - Linux Consulting since 1995. Qmail, KRUD, Firewalls, Python From rburnham at cri-inc.com Mon Aug 27 13:12:01 2001 From: rburnham at cri-inc.com (Roger Burnham) Date: Mon, 27 Aug 2001 17:12:01 GMT Subject: Suggestions for simple persistance in a web app? References: <283adf56.0108270848.3b9d159e@posting.google.com> Message-ID: <3b8a7dae.83488720@news-server.socal.rr.com> On 27 Aug 2001 09:48:47 -0700, kdahlhaus at yahoo.com (Kevin Dahlhausen) wrote: >Anway, it seems like the best bet is look into the Webware-friendly >ISPs. > I recently signed up with for a place to learn Webware and would highly recommend them. $10/month includes mysql, 100Mb and great service: within hours of asking, they installed PIL and several other libs I needed. I am having some trouble getting the Webware persistent AppServer running reliably and they (missoulaweb) have gone way beyond the call-of-duty to help sort it out (the Webware oneshot servers works flawlessly). Cheers, Roger Burnham rburnham at blennylips.com From pinard at iro.umontreal.ca Mon Aug 20 08:17:00 2001 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 20 Aug 2001 08:17:00 -0400 Subject: Fun with httpd logs and code red In-Reply-To: References: Message-ID: [Ignacio Vazquez-Abrams] > On Sun, 19 Aug 2001, Stephen Boulet wrote: > > Just for fun, I wrote the following script to check my apache log for > > recent code red queries: [...] I have a list with 873 entries. Now > > what do I do with it? ;) > Certainly the thing NOT to do is to contact the owners of the offending > sites [...] I presume you are kidding. The poor fellows probably do not even know they are infected. I guess you should warn them, in the nearly hopeless hope that we get a better network after a while. Now, the real difficulty is notifying 873 people, who often use non-resolved IP addresses (5 out of 6 in my statistics), or have their anonymity far too well "protected" by ISPs which could not care less, or do not have a clue. A saddening experience. My Python script for handling such attacks is careful to not report more than once per offending IP, unless attacks continue for more than 4 days afterwards. Failed DNS resolutions is really the bottleneck of the whole processing, so I do them within 100 threads, to get more acceptable speed. There are two next steps for me. First, I would like to find some Apache trick so a mere referencing of `/default.ida' would trigger the script in "single-event" mode. Second, and much more importantly, would be to try being clever at using "whois", because my current MX finder is a bit crude. For a while, I'm saving information on this matter. Any opinion welcome. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From relfx at hotmail.com Wed Aug 8 07:02:46 2001 From: relfx at hotmail.com (Relfx) Date: 8 Aug 2001 04:02:46 -0700 Subject: Tcl/Tk...... Message-ID: <2209a682.0108080302.44b9a5f3@posting.google.com> I have python 2.1.1 but I noticed python didn't install tcl/tk just gave a support folder for it. Do I have to download it separately or something or is built into python itself now. Can someone explain this to me please? From garry at sage.att.com Fri Aug 24 10:11:02 2001 From: garry at sage.att.com (Garry Hodgson) Date: Fri, 24 Aug 2001 14:11:02 GMT Subject: I dont get this! References: <3B85805D.BAC86944@telia.com> <3B863BF0.4AB10AD3@telia.com> Message-ID: <3B866076.60BFCD66@sage.att.com> Peter Sundling wrote: > Problem solved. > I got some answers from you and most of you wrote that the code snippet > worked > for you, but it didn't for me. > > Erik Max Francis told me that the problem could be elsewhere in the > code. > Emile van Sebille gave me the idea that maybe one or more of the > variables could be strings. And there was the problem. > I loaded some data for the low[] and high[] variable from a file and > forgot > to convert the strings to integers. I feel like the dumbest programmer > in the world. naw. the dumbest programmer in the world wouldn't admit his mistake, nor so graciously thank those who helped, and would thus be less likely to get help the next time. -- Garry Hodgson sometimes we ride on your horses Senior Hacker sometimes we walk alone Software Innovation Services sometimes the songs that we hear AT&T Labs are just songs of our own garry at sage.att.com From ph.wuidart at wol.be Sun Aug 12 07:39:34 2001 From: ph.wuidart at wol.be (ph wuidart) Date: Sun, 12 Aug 2001 13:39:34 +0200 Subject: installation tkinter help Message-ID: <9l5q01$mc0$1@news.worldonline.be> I am new to python I install python 2.1.1 to Linux Suse 7.0 (ok) and I have problem to install tkinter can you help me ! Thank you From missive at frontiernet.net Thu Aug 2 14:50:12 2001 From: missive at frontiernet.net (Lee Harr) Date: Thu, 2 Aug 2001 18:50:12 +0000 (UTC) Subject: pygimp Message-ID: I am trying to get pygimp running, but it seems that gimp is not finding the plugins. This is on FreeBSD 4.3 Anyone have the magick incantation to make this work? From rob at jam.rr.com Wed Aug 22 18:40:04 2001 From: rob at jam.rr.com (Rob Andrews) Date: Wed, 22 Aug 2001 22:40:04 GMT Subject: newbie question References: <48256545.0108221258.5882c94f@posting.google.com> Message-ID: <3B84347E.E65ADEC9@jam.rr.com> atonal wrote: > > i have beginning-to-intermediate level vb6/vba programming skills and > would like to find employment before long in a technical capacity. > > something tells me that vb is not my ticket, and i am intrigued by > python. > > for now i am somewhat wedded to ms windows and ms office, but i gather > that python can be used in many ways in place of vba, and that in > general it would offer more career opportunities. > > anyone agree or disagree? advice is welcome, and thanks in advance. Python is great. If you enjoy programming at all, you just might find that coding Python brings its own distinct pleasure. It's an elegant language, offering simple, relatively obvious solutions to many every-day problems. I believe that anyone who spends extensive time with computers might find numerous situations in which Python comes in handy. I have been offered money to use my puny skills with Python more than once lately, and these offers were from other programmers who want me to develop demo applications, GUI interfaces for their own back-end software, etc. It's a good general-purpose language, and it mixes well with other languages. It's a little like Java, only without all that Java. Rob -- Got newbies? Useless Python! http://www.lowerstandard.com/python From jafo-pythonlist at tummy.com Tue Aug 14 05:07:52 2001 From: jafo-pythonlist at tummy.com (Sean Reifschneider) Date: Tue, 14 Aug 2001 03:07:52 -0600 Subject: How do I use ssh in python? In-Reply-To: <9koma6$d8f$1@reader1.imaginet.fr>; from trong-anh.tran@wanadoo.fr on Tue, Aug 07, 2001 at 02:27:23PM +0200 References: <9koma6$d8f$1@reader1.imaginet.fr> Message-ID: <20010814030752.E14571@tummy.com> Try: data = os.popen('ssh remotehost ls').read() print 'Got dat:', data Sean -- "You can tune a file-system, but you can't tune a fish." -- Quote from tunefs(1M) man page Sean Reifschneider, Inimitably Superfluous tummy.com - Linux Consulting since 1995. Qmail, KRUD, Firewalls, Python From paulp at ActiveState.com Wed Aug 1 14:25:36 2001 From: paulp at ActiveState.com (Paul Prescod) Date: Wed, 01 Aug 2001 11:25:36 -0700 Subject: Query about Types SIG status References: Message-ID: <3B6849A0.73CBC651@ActiveState.com> Michael Abbott wrote: > >... > > There seem to be a variety of documents in varying stages of maturity, but > it's difficult to see what the current state of thinking is. There's a > document from Guido van Rossum with some early ideas, an unnumbered PEP > from Paul Prescod on an interface declaration language, and PEP-0245 by > Michel Pelletier, plus a number of other papers. However (it's difficult > to tell), most of these seem to be quite elderly! Like almost everything in the Python world, the types-sig is very personality driven. When there is a person stirring up the pot, the pot is very active. When there isn't, it isn't. > Clearly the ideas of interfaces and of static types are distinct but > closely related developments. Is this an area of active development, or is > the current consensus that it's not worth the effort? No, there is no consensus. I think it would be useful to be able to check types at module boundaries and if I could get a week of vacation I'll make some more progress on that. The Zope guys are very interested in interfaces as a documentation and introspection tool and they'll probably advance that when they get time. Static types are the least like to be reactivated any time soon because they are nightmarishly complex to try to add to the Python type system -- especially while Guido is changing the type system between version 2.1 and 2.2. -- Take a recipe. Leave a recipe. Python Cookbook! http://www.ActiveState.com/pythoncookbook From ignacio at openservices.net Thu Aug 30 20:14:06 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Thu, 30 Aug 2001 20:14:06 -0400 (EDT) Subject: How to change Windows Environment Variable In-Reply-To: Message-ID: On Fri, 31 Aug 2001, ??? wrote: > Dear all, > > How to change environment variable on Windows NT or 2000 by python? > > In Visual Basic case can setting as below: > > Private Declare Function GetEnvironmentVariable Lib "kernel32" _ > Alias "GetEnvironmentVariableA" (ByVal lpName As String, _ > ByVal lpBuffer As String, ByVal nSize As Long) As Long > > Private Declare Function SetEnvironmentVariable Lib "kernel32" _ > Alias "SetEnvironmentVariableA" (ByVal lpName As String, _ > ByVal lpValue As String) As Long > > I will waiting for good news. > Thanks. > MyeongKi Han Good news: There is a GetEnvironmentVariable() function in the win32api module. Bad news: There is no SetEnvironmentVariable() function. Good news: The source code for win32api is available via CVS (http://starship.python.net/crew/mhammond/cvs.html) so you can add the function. Bad News: You'll need Visual Studio 6 to compile it. -- Ignacio Vazquez-Abrams From JamesL at Lugoj.Com Fri Aug 3 17:45:46 2001 From: JamesL at Lugoj.Com (James Logajan) Date: Fri, 03 Aug 2001 14:45:46 -0700 Subject: PEP 238 (revised) References: Message-ID: <3B6B1B8A.EB9644AA@Lugoj.Com> Terry Reedy wrote: > > "Tim Rowe" wrote in message > news:memo.20010803215850.16469f at digitig.compulink.co.uk... > > Just a quick reminder that the reason I can't get any sysadmin to > let me > > use Python is that all the ones I encounter consider Python too > unstable > > for serious work. I see their point :-( > > Compared to what? I'm am acually curious. If I may interject: Bourne shell. C. Two trusty, reliable old tools. Neither is perfect; so what? From jdhunter at nitace.bsd.uchicago.edu Wed Aug 29 10:21:40 2001 From: jdhunter at nitace.bsd.uchicago.edu (John Hunter) Date: 29 Aug 2001 09:21:40 -0500 Subject: Troublesome PIL Installation References: Message-ID: <1rbskzt097.fsf@video.bsd.uchicago.edu> >>>>> "Christian" == Christian Lundh writes: Christian> rm -f *.o *~ rm -f *.a tags TAGS config.c Makefile.pre Christian> python sedscript rm -f *.so *.sl so_locations Christian> VERSION=`python -c "import sys; print Christian> sys.version[:3]"`; \ installdir=`python -c "import sys; Christian> print sys.prefix"`; \ exec_installdir=`python -c Christian> "import sys; print sys.exec_prefix"`; \ make -f Christian> ./Makefile.pre.in VPATH=. srcdir=. \ VERSION=$VERSION \ Christian> installdir=$installdir \ Christian> exec_installdir=$exec_installdir \ Makefile make[1]: Christian> Entering directory Christian> `/home/xistan/src/ActivePython-2.1.1-212/Extensions/Imaging' Christian> make[1]: *** No rule to make target Just a guess, but when I unpacked Imaging yesterday and went through the install, I noticed that it unpacked in Imaging-1.1.2 (version number included) and the default line in Modules/Setup ( -IExtensions/Imaging/libImaging ) has no version numbers. I made a symlink: > cd Extensions > ln -s Imaging-1.1.2 Imaging but you could also edit Modules/Setup to point to your Imaging distribution. Hope this helps, John Hunter From stojek at part-gmbh.de Thu Aug 30 10:04:17 2001 From: stojek at part-gmbh.de (Marcus Stojek) Date: Thu, 30 Aug 2001 16:04:17 +0200 Subject: two little syntax questions References: <3b8e375a$1_1@news5.uncensored-news.com> Message-ID: In article <3b8e375a$1_1 at news5.uncensored-news.com>, doug.fort at verizon.net says... perfect. Thanks a lot marcus From richard at bizarsoftware.com.au Mon Aug 13 20:02:34 2001 From: richard at bizarsoftware.com.au (Richard Jones) Date: Tue, 14 Aug 2001 10:02:34 +1000 Subject: 'python' Bash command doesn't link to 2.1.1 In-Reply-To: <3B786F77.1F6B54EE@btinternet.com> References: <3B786F77.1F6B54EE@btinternet.com> Message-ID: <0108141002340S.01694@ike> On Tuesday 14 August 2001 10:23, root wrote: > Hello, I've decided to use Python as my first programming language (as > per advice at http://www.tuxedo.org/~esr/faqs/hacker-howto.html ) and > I've run into a problem during installation. Marvellous idea :) > I cannot, however, run Python 2.1.1 using the 'python' terminal command > and there is no Python man page installed. Typing 'python' at the > command prompt brings up the 1.5.2 interpreter. I can run the 2.1.1 > interpreter by typing the path of the toplevel Python directory and then > /python (e.g. /home/root/Python-2.1.1/python) but I don't want to have > to do this every time I start the interpreter and I would also like to > have the man page installed. By default, python will be installed to /usr/local/bin. Your system will have python 1.5.2 installed in /usr/bin. That binary will be found first when you type "python" at the command line. To force using python 2.1.1, run "/usr/local/bin/python". Or, do the following (as root): cp /usr/bin/python /usr/bin/python1.5 cd /home/root/Python-2.1.1/ make distclean ./configure --prefix=/usr make install the --prefix=/usr tells the install to place python in /usr/bin (and the library files will go in /usr/lib/python2.1). Note, you'll want to remove the "other" python2.1 installation too (/usr/local/bin/python and /usr/local/lib/python2.1). The first command above just keeps the old python around just in case you need it in the future. Then you will be able to run "python" at the command prompt and get 2.1.1 :) Richard From breakfast at 10.am Thu Aug 30 16:06:25 2001 From: breakfast at 10.am (mallum) Date: Thu, 30 Aug 2001 21:06:25 +0100 Subject: Python runs fine interactively but 'locks up' with scripts In-Reply-To: References: <20010830162416.B664@10.am> Message-ID: <20010830210625.A320@10.am> on Thu, Aug 30, 2001 at 11:39:03AM -0400, Ignacio Vazquez-Abrams wrote: > > Have you tried compiling against glibc or dietlibc > (http://www.fefe.de/dietlibc/)? > The device Im devloping for only has 3mb's of space ( jffs2 compressed filesystem though so slightly more.. ) so glibc is not really an option. AFAIK dietlibc is not as developed as uClibc . mallum From aleax at aleax.it Mon Aug 27 06:21:13 2001 From: aleax at aleax.it (Alex Martelli) Date: Mon, 27 Aug 2001 12:21:13 +0200 Subject: lack of shell in Win2000 References: Message-ID: <9md6uq01ojv@enews1.newsguy.com> "Ignacio Vazquez-Abrams" wrote in message news:mailman.998772879.5363.python-list at python.org... > On Sat, 25 Aug 2001, john anon wrote: > > > at the risk of repeating an old question > > (I looked -- really -- I looked) > > > > if there is no shell in Win2000, how will we start scripts? > > from Explorer? but ... what about command-line args? > > Most likely via cmd.exe, NT/2000's command line interpreter. ...which is now hidden under start/programs/accessories (bah, "accessory" my foot!). Anyway, perhaps more common ways to pass command-line args to Python programs on Win2000 &c are: Start/Run...: you can pass a full commandline there, including arguments Shortcuts: when you make a shortcut (.LNK file) to your program you get to define all of the commandline arguments (rightclick/Properties/Shortcut, edit the Target textfield). Alex From pinard at iro.umontreal.ca Thu Aug 9 18:31:46 2001 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 09 Aug 2001 18:31:46 -0400 Subject: python-dev summary, July 16-31 In-Reply-To: <3B71D3DC.A964483@engcorp.com> References: <9kpfc9$bo8$1@animus.fel.iae.nl> <3B70515D.220DD2D1@letterror.com> <3B7085F9.28830B9A@engcorp.com> <9kro7g02r2p@enews1.newsguy.com> <3B71D3DC.A964483@engcorp.com> Message-ID: [Peter Hansen] > Fran?ois Pinard wrote: > > Really? You write parentheses all the time? > No, just when I write tuples! Yes, I *definitely* use parentheses > around tuples all the time. > (a) One obvious way to do things. > (b) I never knew there was another way at first, and the habit stuck. > (c) Fits my brain better, since I see parentheses and think "tuple". > (My brain has to pause, perhaps, when a function with arguments > is called. I don't notice the pause, apparently. :-) But in fact, your brain comes to just accept the magic of writing without parentheses, not having to resort all the time to explicit tuple packing and unpacking. Not that you forget how things work, of course, but both your writings and mind get a bit less encumbered. Let's take a small example. It is so simple to write: dictionary[index1, index2] = value everywhere, in those applications where "dictionary" is to be indexed with a 2-tuple. Just think as an associative array with two indexes, it's easier. We do know that there is only one index deep down, and that tuple packing occurs. But this is all part of the Python built-in mechanics, which you would underline by writing: dictionary[(index1, index2)] = value Do we really need to stress the inner workings everywhere? It is more relaxing to avoid doing so. And Python looks even more powerful! :-) > > Of course, for many languages, parentheses could be effectively used to > > increase legibility. But for marking tuples, Python does not need them > > in most cases, it may be more noisy than useful having them to mark tuples > > when it is not required to do so. > You haven't convinced me yet, other than the "slightly less noise" > argument. I'm not really trying to convince you, as stylistic issues are often prone to religious feelings. On the other hand, it is often good to compare styles. My own style improved faster, when I started to look at what others do. We pick and absorb little things that we like, here and there. > To do otherwise would be inconsistent, and to me > (inconsistency == unmaintainability) . Quite agreed. I'm very sensitive to inconsistent style when I read code, it hurts the pleasure I have to read, and I'm torn between the the desire to report these things, and the feeling people would badly receive my comments. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From gorny at hobbiton.org Sat Aug 25 05:20:30 2001 From: gorny at hobbiton.org (Gorny) Date: Sat, 25 Aug 2001 11:20:30 +0200 Subject: seg. fault with ext. module Message-ID: Hi, -----code------ #include static PyObject * makesock(PyObject *self, PyObject *args); static PyMethodDef gforce_methods[] = { {"makesock", makesock, METH_VARARGS}, {NULL, NULL} }; static PyObject * makesock(PyObject *self, PyObject *args) { printf("Making socket...\n"); return Py_None; } /* Initialization function for the module */ DL_EXPORT(void) initgforce(void) { (void)Py_InitModule("gforce", gforce_methods); } -----eof----- >>> import gforce >>> gforce.makesock() Making socket... >>> Ctrl-D Segmentation fault [gorny at darkstar ~/gforce]$ How do I prevent this. If i import other modules and close the python-shell it'll not end with a segmentation fault, only if it's my module.. Do i have to make an extra function in it, which `de-inits` the module..?? Greets, Gorny -- "When I was a little kid, I had this dream where a snake would rule and dominate the entire world (actually, I guess that a penguin was also part of the dream... but never mind)" -- Python Develper's Handbook, Andre Lessa http://gorny.cjb.net From a11w at SoftHome.net Mon Aug 13 04:21:57 2001 From: a11w at SoftHome.net (Jiba) Date: Mon, 13 Aug 2001 10:21:57 +0200 Subject: FEEDBACK WANTED: Type/class unification References: <3B7400C1.BA52170B@SoftHome.net> Message-ID: <3B778E25.1A873744@SoftHome.net> Guido van Rossum wrote: > That never worked, and still won't work. I don't see that as a loss. Yes it does not work... I've never tried this, but i have assumed it work... sorry for that. > > By the way, it's interesting to notice that, for wrapper, o.method() is > > not the same think than O.method(o)... > > In what sense? if O.method(arg) call, say, arg.something, if you pass the wrapper o, the method call "something" will be wrapped. If you pass the non-wrapped object oo, it won't be. For example we can do a ReadOnlyWrapper that's wrap an object and make it read-only : class ReadOnly: def __init__(self, object): self.wrappedobject = object def __getattr__(self, name): return getattr(self.wrappedobject, name) def __setattr__(self, name, value): if name == "wrappedobject": self.__dict__["wrappedobject"] = value else: pass This code DOESN'T WORK if wrappedobject has, for example, a setX(newX) method, because : >>> object = [what ever you want] >>> ReadOnlyWrapper = ReadOnly(object) >>> ReadOnlyWrapper.setX(1) will modify the object. The only way to fix that may be to call : >>> ReadOnly.setX(ReadOnlyWrapper, newX) We may change __getattr__ so it does convert automatically "ReadOnlyWrapper.setX(1)" into "ReadOnly.setX(ReadOnlyWrapper, newX)". So it can really be usefull in some very particular cases ! > --Guido van Rossum (home page: http://www.python.org/~guido/) Jiba From rnd at onego.ru Wed Aug 29 11:14:58 2001 From: rnd at onego.ru (Roman Suzi) Date: Wed, 29 Aug 2001 19:14:58 +0400 (MSD) Subject: Winer on MS scripting strategy: implications for Python.NET? In-Reply-To: Message-ID: On 29 Aug 2001, Bill Seitz wrote: > See http://www.xmlrpc.com/stories/storyReader$1957 > > Dave believes (based on discussions such as > http://wmf.editthispage.com/discuss/msgReader$5341?mode=day) that .NET > implementations will lead to forks in the underlying languages, based > on a standard embrace-extend strategy, which will lead to the .NET > versions of each language getting much bigger than the root versions. > Then they'll start nudging those .NET developers toward C#... We ourselves are choosing .NET or so it seems all this time after the NET-bubble emerged. I think even M$ will not be able to go that far. Otherwise we'd have Java everywhere - which is not the case, thanks God. In fixed N-dimensional space largest cluster always wins in the closed volume. But our "space" is not bounded in volume, nor in dimensions. So, there is no worries that everybody will use C# or whatever. > Thoughts? Sincerely yours, Roman A.Suzi -- - Petrozavodsk - Karelia - Russia - mailto:rnd at onego.ru - From rishi.roy at getiview.com Wed Aug 1 13:22:57 2001 From: rishi.roy at getiview.com (Rishi R. Roy) Date: Wed, 1 Aug 2001 17:22:57 +0000 (UTC) Subject: Question about compiling python with openSSL support Message-ID: I was hoping someone could help me with this. I'm trying to compile python but am having no success in figuring out where and what changes I need to make in order to get it to work with openSSL. I've successfully installed ssl. Also, I've seen the wrapper classes that are there - like m2crypto, but would rather have the socket.ssl function working instead. If someone could PLEASE help me I would greatly appreciate it. I've spent that last 3 days and I'm lost. Thank you. Rishi Roy -- Posted from mail.opticominc.com [208.253.136.100] via Mailgate.ORG Server - http://www.Mailgate.ORG From chapman at bioreason.com Mon Aug 6 12:17:43 2001 From: chapman at bioreason.com (Mitch Chapman) Date: Mon, 06 Aug 2001 10:17:43 -0600 Subject: Python and Gtk References: <9klkjv$1p9$1@wanadoo.fr> Message-ID: <3B6EC327.81957972@bioreason.com> Djoum? wrote: > > I begin with Python and Gtk and I have some unresolved question : > > I use Gtkinter and I have notice that a lot of gtk (or gdk) object miss in > the gtk.py module. How can I do when I need these objects (for example > Gdkfont)? Gtkinter is included with pygtk but is deprecated. It's best just to use gtk.py. The source code for pygtk includes a module called description.py. This module exists for documentation purposes only. It describes classes such as GdkFont which don't have wrappers in gtk.py, but which are used in pygtk. (These classes don't have gtk.py wrappers, but various methods in gtk.py may return instances of these classes. It's confusing...) > Where can I find the prototype (type of arguments) of a callback function > must have (for example where can I find the type of arguments of a button > pressed callback funtion)? One way to discover the interface of a callback function is to define a dummy callback which has a "wildcard" interface. For example: def buttonClickCB(*args): print "Button was clicked." print " Arguments:", args ... btn = gtk.GtkButton(label="Click me") btn.connect("clicked", buttonClickCB) When you run the program and click the button, it will print out the argument list. In fact, most of my callbacks never need the callback arguments. (They are defined as methods on Controller classes, and the Controllers keep all of the state needed in order to process the callbacks.) So I just declare callback methods using the wildcard signature and never worry about the "real" signature. Just to be redundant, here's another example: class Controller: def __init__(self): ... self.fooBtn = gtk.GtkButton(label="Foo") self.fooBtn.connect("clicked", self.fooClickedCB) ... def fooClickedCB(self, *args): ... Hope this helps... -- Mitch Chapman Mitch.Chapman at bioreason.com From erno at iki.fi Tue Aug 21 16:50:02 2001 From: erno at iki.fi (Erno Kuusela) Date: Tue, 21 Aug 2001 23:50:02 +0300 Subject: ANN: a new utility for Python developers In-Reply-To: <15234.33838.8650.343768@beluga.mojam.com>; from skip@pobox.com on Tue, Aug 21, 2001 at 10:54:22AM -0500 References: <15234.33838.8650.343768@beluga.mojam.com> Message-ID: <20010821235002.C783@fabulous.u--3.com> On Tue, 21 Aug 2001, Skip Montanaro wrote: | The time module is supposed to be a very | thin wrapper around various time-related C library functions. [snip explanation what time.time()/time.clock() do on various platforms] yeah, really thin wrapper... actually perhaps it would be better if time.time() called the c time() function and time.clock() called the c clock() function. then, new functions could be introduced for measuring time accurately and for measuring only cpu time. the former could call gettimeofday on unix and read the time stamp counter on windows, and the latter could use clock or times and fail, be absent or fall back to the performance counter on windows. | I think if there was a better solution, Guido and friends would have | found it by now. yes, but as i understand the way it works is he picks up brilliant ideas from frothing rants on the newsgroup and then gets in the time machine... and then he will have found it by now. that's why there are only pointless threads left on the newsgroup. all the sensible threads have been erased from history because whatever they were complaining about no longer exists :) | Erno> 1) it is usually better to use gettimeofday(2) than times(2) on | Erno> unix for timing code because times(2) has poor resolution and | Erno> the user/system time numbers are frequently gibberish. | | Erno> 2) the python time.clock() should return information based on | Erno> gettimeofday(2) and not times(2) on unix. | | times() is not used anywhere in timemodule.c. oops, forgot to mention that clock(3) uses times(2) on unix. -- erno From dlharris at mail.usyd.edu.au Sat Aug 25 21:15:41 2001 From: dlharris at mail.usyd.edu.au (Dave Harrison) Date: Sun, 26 Aug 2001 11:15:41 +1000 Subject: Qeury about copyright Message-ID: <20010826111541.A1006@isetroc.com> To those who know the GPL inside out and Guido as well, I am a student and when I am coding at University I have a limit placed on the amount that I can download during a single session from sites external to the uni. Now because I like to code in python and I want to encourage its use in the comp sci dept as well I have been thinking about putting up a webiste based at the uni with the python doco and maybe a few essays by various people such as Guido and other people who use and have commented on python. We currently have a Python message board, but to to make is easy for students to code in python at uni they need to have it available to them without eating up their download quota. What restrictions are there placed on the availability of the doco and varied essays ? Can I put the doco online for people to use ? Anything else I might want to know ? Thanks Dave From paul at boddie.net Thu Aug 16 07:44:38 2001 From: paul at boddie.net (Paul Boddie) Date: 16 Aug 2001 04:44:38 -0700 Subject: Module and feature dependencies Message-ID: <23891c90.0108160344.573e15c2@posting.google.com> Well, after stating that I had no interest in writing a PEP, some thoughts of mine evidently floated up into my consciousness, leading to this vague enhancement proposal. Despite the publication of certain proposals about introducing version identifiers into the Python syntax, indicating the version of Python for which a particular program is intended, such syntactic enhancements have been regarded as unpleasant or unnecessary. Indeed, in the context of the PEP 238 debate, the introduction of such identifiers to indicate that a program is to adopt the newer division semantics seems to be viewed as a "hack". However, such a debate is unlikely to entertain consideration of wider issues with the dependence of programs on particular features of Python and on other Python modules, packages and extensions. Consider Pygame (http://www.pygame.org). This package has a selection of dependencies which the author has conveniently published (and I hope he doesn't mind me using his work as an example). Unless explicit verification of those dependencies have been coded into the Pygame framework, and I'm not sure that they have been, then surprises can result for those who have not paid appropriate attention to the published documentation. These surprises can occur quite often when compiled extensions are obtained for different versions of Python or external libraries. Whilst installing a package without paying full attention to the published documentation could be considered foolish, it should be remembered that human-readable documentation residing in a particular location (in this case the package's Web site) does not necessary help users obtaining the package from other places (such as mirror sites or other media), nor does it help automated installation systems. What seems to be necessary is a general dependency tracking mechanism which will not only guard against the execution of Python programs in environments lacking the prerequisite features, modules, extensions and libraries, but also to allow the detection of dependency problems in advance (before execution or even installation is attempted). One way of achieving this may be to introduce declarations within program files which are analysed when a program is run, but which can also be analysed by other programs. Of course, many systems exist which address most of the obvious issues in this area. Package systems at the operating system level (eg. RPM, pkgadd) can track library dependencies, configuration and build tools (eg. autoconf, configure, make) can determine whether source code is appropriate for a given environment, and Python has its own emerging build infrastructure (Distutils). Nevertheless, this problem area is worth reinvestigating with attention to PEP 241 ("Metadata for Python Software Packages"), PEP 243 ("Module Repository Upload Mechanism"), as well as Distutils. This message really does state the obvious, and personally I think I manage quite well with the dependencies my works have on other things. However, outside my own mechanisms for managing such issues, such as on the rare occasion when my works are downloaded by others, the recipients of those works may not be as well protected as I am from the dangers of version mismatches. Being able to encode dependencies in a portable form could do a lot to make module and extension installations easier. Paul From peter at engcorp.com Tue Aug 14 19:36:11 2001 From: peter at engcorp.com (Peter Hansen) Date: Tue, 14 Aug 2001 19:36:11 -0400 Subject: Newbie lists question References: <3B785215.19D583C8@spam.me.not> <3B79A74F.CBEC0A9@ccvcorp.com> Message-ID: <3B79B5EB.5D4CBFE2@engcorp.com> Jeff Shannon wrote: > > Wolfe Maykut wrote: > > > for file in backupdir: > > filename = string.split(file, '/')[-1] > > prefix = string.split(filename,'.')[0] > > >>> for file in backupdir: > ... filename = os.path.split(file)[1] # you only need the filename > component, not the path component > ... prefix = os.path.splitext(filename)[0] # you only need the root > part, not the extension > > While portability may not be an issue for this particular script, it's > really a good idea to be in the habit of using os.path for all your path > manipulations, rather than the usual string functions. (It's also a good > idea to use string methods instead of the string module, unless you're > targetting older Python installations.) More important even than portability, is correct functionality. I noticed that the original code doesn't work the same as yours, probably because yours is correct. :) The original takes everything *before* the first period in the filename, while yours takes everything up to the last period. The problem with avoiding os.path is not that you are missing portability, nor even that you are needlessly reinventing the wheel. The problem is that you are probably writing buggy code, whereas os.path should be pretty reliable by now... (Same logic applies to using lots of complicated string operations when the 're' module could do it better. Not 'cause it's faster, nor easier to read, etc.... just because it's more likely to be correct.) -- ---------------------- Peter Hansen, P.Eng. peter at engcorp.com From new_name at mit.edu Wed Aug 15 11:16:10 2001 From: new_name at mit.edu (Alex) Date: 15 Aug 2001 11:16:10 -0400 Subject: Anti-spam idea Re: Attention Physicians References: Message-ID: I would go for this if it blocked any mention of division semantics, too. Alex. From dalke at acm.org Sun Aug 19 21:40:45 2001 From: dalke at acm.org (Andrew Dalke) Date: Mon, 20 Aug 2001 02:40:45 +0100 Subject: Overflow-less integer arithmetic? References: Message-ID: <9lqiks$a2v$1@slb6.atl.mindspring.net> Tim: >Do you really find such OverflowErrors more useful than not? I'm asking >because PEP 237 seeks to eradicate them: > > http://python.sf.net/peps/pep-0237.html Despite what I said yesterday, I have used and needed lont ints a few times in real code. There are two cases: 1) I expect to get large values (>2**31) frequently 2) I expect to get them infrequently Case #1 is the more common, and is solved by using an 'L' in the appropriate initialization. There have been many times when the omission of the L was not caught until the testing phase, which means automatic conversion would have been prefered. Case #2 has only occured once, where >98% of the times the value could fit in a regular integer and I wanted the faster math performance. In that case I did try: operation except OverflowError: redo the operation with longs So I have have no problems with the current 237 PEP, where int operations convert to long rather than raising an exception. Andrew dalke at dalkescientific.com From peter at engcorp.com Fri Aug 31 20:28:19 2001 From: peter at engcorp.com (Peter Hansen) Date: Fri, 31 Aug 2001 20:28:19 -0400 Subject: PING Help References: <3b8fd82e$0$19384@wodc7nh6.news.uu.net> Message-ID: <3B902BA3.90F5E5AE@engcorp.com> brian wrote: > > Hello > Kinda new to python here is what I am trying to do > working with windows nt a simple ping script > this is what I have. > _______________________________________________________ > import os > import ping Where did you see that you could import ping? There is no such module in the standard library. When you post code that doesn't work, it's far more useful to post the interactive session you used to test the code. To do that, run python interactively, then do an 'import mycode' where your code resides in a file called mycode.py (or whatever). Then cut and paste the session into your news reader and post it here. In this case, if you had done that, you would probably have seen "ImportError: no module named ping", which should have pointed you towards the answer. -- ---------------------- Peter Hansen, P.Eng. peter at engcorp.com From brian at sweetapp.com Sat Aug 11 00:49:49 2001 From: brian at sweetapp.com (Brian Quinlan) Date: Fri, 10 Aug 2001 21:49:49 -0700 Subject: Pythonwin and .NET In-Reply-To: <3B9D6654.FA287BA5@earthlink.net> Message-ID: <000b01c12221$0e8d2200$445d4540@Dell2> Ron wrote: > I have a question that I hope someone can partially answer. ActiveState > has a beta of Visual Python for .Net on their web site. I can not use it > because I do not have access to a beta of Microsoft's Visual Studio. > > However, the ActiveState beta of Visual Python must have at least basic > functionality. Visual Python is not the same is Python .NET. Visual Python is a plug-in to VisualStudio .NET that helps you develop normal CPython applications. It extends VisualStudio to offer: - Python syntax coloring - Python integrated debugging - Python syntax error checking (errors are underlined in the editor) - Python intellisense - a Python class browser Cheers, Brian From printers at sendme.cz Sat Aug 4 17:02:36 2001 From: printers at sendme.cz (Lad) Date: 4 Aug 2001 14:02:36 -0700 Subject: Beginner's questions Message-ID: Hi, I am a Perl programmer but I miss some things in Perl. For this reason I am looking for another, better (if any) programming language. Maybe Python would be my choice. Can you please answer the following? 1.How well threads are implemented in Python particularly under windows? 2.Are there any libraries for working with HTTP protocols that is modules that could help download( grab) web pages with GET methods and modules for using also POST method without necessity to program these applications with sockets? 3.Are there any libraries for SMTP, POP3 and NNTP protocols? 4. Is there a program for making executable files from python programs? 5. What modules , except Tk, can I use for GUI programming with Python? 6. Is it possible, in Python, send output from a program to a web browser directly or in other words display html file in python application? 7. Where can I find a available modules list? 8. What are best tutorials/books on Python? 9. Can you give me examples of large Python application? 10. Why do YOU use Python? 11. Is it possible to to "talk" to java applets via Python? Thank you for your answers? Ladislav From rajarshi at seed.chem.psu.edu Thu Aug 23 17:16:17 2001 From: rajarshi at seed.chem.psu.edu (Rajarshi Guha) Date: Thu, 23 Aug 2001 17:16:17 -0400 Subject: Iterating throught 2 lists at the same time Message-ID: <9m3rmg$8u55$1@ID-91520.news.dfncis.de> Hi, I have the following construct: >>> a = ['a','b','c'] >>> b = ['x','y','z'] >>> for i,j in a,b: ... print i,j ... Traceback (most recent call last): File "", line 1, in ? ValueError: unpack list of wrong size In my actual program the elements of a and b are themselves lists, but I think that does'nt really matter (or does it?) So, how can I iterate over a and b in 'parallel' (ie in the first iteration I want a[0] and b[0] and so on) I know I could maintain counters and use the index notation - but it seems a little crude for Python :) Are there any, more elegant ways? -- -- Rajarshi Guha From gerhard.nospam at bigfoot.de Mon Aug 27 13:26:07 2001 From: gerhard.nospam at bigfoot.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Mon, 27 Aug 2001 19:26:07 +0200 Subject: looping through the keys of a dictionary References: <8e84aae6.0108210651.6fdac34d@posting.google.com> <9m31f2026s8@enews4.newsguy.com> <5285736.frOyU7HbjW@lunix.schabi.de> <9md10h01g1e@enews1.newsguy.com> <9mdnrf02jv9@enews1.newsguy.com> Message-ID: On Mon, 27 Aug 2001 17:09:33 +0200, Alex Martelli wrote: > [...] >It's the stock 2.1.1 version for Windows as downloaded from comp.lang.python, >though. ... which had better been posted in alt.binaries.* ;-) Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ public key at homepage public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From no at ok.com Sun Aug 12 11:03:50 2001 From: no at ok.com (ralf blumenstein) Date: Sun, 12 Aug 2001 15:03:50 GMT Subject: CVS & python ? Message-ID: I am triing to understand if I will be able to share python sources with a Spanish programmer. Is CVS (concurrent version sytem) compatible with python ? ---- Ralf Blumenstein - www.freedomnetworks.de - Germany I support Linux - GPL and free CVS accounts @ www.e-cooperators.com From aleaxit at yahoo.com Tue Aug 14 17:47:22 2001 From: aleaxit at yahoo.com (Alex Martelli) Date: Tue, 14 Aug 2001 23:47:22 +0200 Subject: [Python-Dev] Proposed PEP: Optimizing Global Variable and Attribute Access References: Message-ID: <9lc68c1247p@enews3.newsguy.com> "Roman Suzi" wrote in message news:mailman.997817303.9616.python-list at python.org... ... > Well, I just think that probably interpreter could > optimize by just IMPLICITLY making caching of global > references, like in this (current) optimization trick: ... > That is, instead of tracking, simple implicit > localizing could be used, or not? Yes, but that would change language semantics in a non backwards compatible way. Alex From tim.one at home.com Thu Aug 16 20:40:56 2001 From: tim.one at home.com (Tim Peters) Date: Thu, 16 Aug 2001 20:40:56 -0400 Subject: Python Path Blues In-Reply-To: Message-ID: [Maan M. Hamze] > Issue resolved. > Although the search path is set in the windows NT registry, I discovered > that it was not set in: My Computer ..... Properties .... Environment. > I truly thought that the registry was enough, but apparently it is not. > Having set the PYTHONPATH in the environment the problem was resolved. > Strange: What is the point of the registry then? I'm not sure, it hasn't always been this way, and *all* behaviors for PYTHONPATH have surprised me since I first used Python on Windows. Mark Hammond has a Design here, but the only clues I know of as to exactly what it is are hiding in comments attached to bug reports on SourceForge. If you figure it out, please submit a doc patch <0.7 wink>. cheerfully y'rs - tim From sheila at spamcop.net Fri Aug 3 18:53:00 2001 From: sheila at spamcop.net (Sheila King) Date: Fri, 03 Aug 2001 22:53:00 GMT Subject: Is it new style or just lack of style? References: <23891c90.0108030118.275ea332@posting.google.com> Message-ID: <1lammtghnapd283ivdrtphc4vacphgsjen@4ax.com> On Fri, 3 Aug 2001 13:21:47 -0400 (EDT), "Steven D. Majewski" wrote in comp.lang.python in article : :In my case, I think it has more to do with my wearing bifocals than :with my editor. ( Although, if I had syntax coloring working, I might :not need the extra spaces to see clearly! ) Here is a new free editor I've been trying out (for Windows...don't know if that helps any). It comes with several sets of syntax highlighting, including Python. ConTEXT: http://www.fixedsys.com/context/ I'm curious if anyone else has tried it out and whether they liked it or not. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From quinn at retch.ugcs.caltech.edu Fri Aug 3 13:11:13 2001 From: quinn at retch.ugcs.caltech.edu (Quinn Dunkan) Date: 3 Aug 2001 17:11:13 GMT Subject: 2.2 features References: <01Aug1.191713pdt."3453"@watson.parc.xerox.com> <3B6AA06E.7060408@livinglogic.de> <3B6AA5F6.1050603@livinglogic.de> Message-ID: On Fri, 3 Aug 2001 16:05:23 +0200, Charlie Clark wrote: >I understand the problem like this: Classes keep lists of their >sub-classes *and* of their instances and "in" is a keyword which checks >for membership in sequences. > >class Programmer > pass > >class GoodProgrammer(Programmer) > pass > >class BadProgrammer(Programmer) > >guido = GoodProgrammer() >charlie = BadProgrammer() > >Is this the right way of thinking about it? If so we could then ask our >classes to list their instances and subclasses and apply membership >tests to them. > >Programmer.instance() >>>> [''] >Programmer.subclasses() >>>> ['GoodProgrammer', 'BadProgrammer'] >GoodProgrammer.instance() >>>>'Guido' >GoodProgrammer.subclass() >>>>[''] >etc. If they did, they couldn't keep them as lists of strings, because instances don't have to have names, and can have more than one, etc. If they kept track of a list of instances, it would have to be with weak references because otherwise nothing would ever die. And even if they used weak references, they wouldn't know about things coming out of a marshal or pickle (well, I'm sure pickle could call a registering routine, but it would be ugly). And, if this were implemented, 'in' wouldn't be the right operator, because you want identitiy (is), not similarity (==). And it wouldn't scale. If you say 'x in int.instances()', is the system supposed to track down every single living number and do a linear search through all of them? What if int has subclasses? It would need to track all those down too. So, no, thinking about things as if classes keep track of all their instances is not the right way, it's the other way around. In dynamically typed languages without optimizing compilers, all objects have a type tag that tells them what they are. Nice try, though, it's good to make those kind of generalizations where they make sense. Other object-oriented languages provide a 'conforms_to' or 'kind_of' message. I don't see why python couldn't do the same: x.instance_of(int) >I still don't get generators btw. What does 'yield' do that 'return' >can't `yield' can be resumed. def f(): return 1 return 2 'f' will never get to the 'return 2' no matter how many times you call it. def f(): yield 1 yield 2 First of all, the new 'f' doesn't return an integer, it returns an iterator. But the second time you call the iterator's next() method you will get a 2. From Hans.Brand at BrandInnovators.com Mon Aug 6 04:38:18 2001 From: Hans.Brand at BrandInnovators.com (Hans Brand) Date: Mon, 6 Aug 2001 10:38:18 +0200 Subject: removing duplicate spaces from a string References: Message-ID: <9kll08$2evmu$1@reader02.wxs.nl> Ron, Split() and join() should do the trick. >>> from string import * >>> a = 'fiddle faddle pip pop' >>> join(a.split()) 'fiddle faddle pip pop' >>> Greetings, Hans "Ron Johnson" wrote in message news:lvsb7.57979$oh1.21803460 at news2.rdc2.tx.home.com... > Hello, > > Say I have the strings: > 'foo bar snafu' > 'fiddle faddle pip pop' > > Are there any builtins that will allow me to compress the > duplicate spaces out so that the files look like: > 'foo bar snafu' > 'fiddle faddle pip pop' > > I could iteratively apply string.replace, replacing ' ' with > ' ', but that doesn't seem the optimum course. > > For anyone with VMS experience, I want to emulate the DCL lexical > function F$EDIT("COMPRESS"). > > Sincerely, > Ron > > +------------------------------------------------------------+ > | Ron Johnson, Jr. Home: ron.l.johnson at home.com | > | Jefferson, LA USA http://ronandheather.dhs.org | > | | > | "Our computers and their computers are the same color. The | > | conversion should be no problem!" | > | Unknown | > +------------------------------------------------------------+ From kruge at gmx.de Sat Aug 4 17:40:30 2001 From: kruge at gmx.de (Michael Briel) Date: Sat, 4 Aug 2001 23:40:30 +0200 Subject: Python for beginners Message-ID: <9khr73$5rm$03$1@news.t-online.com> Hi there! I'm generally interested in Python - can anybode point me to either a book or a page that teaches you from the beginning how to use this language? I generally know how to program computers, but I haven't done it in ages, so it better be "for Dummies"... ;o) Thanks! -- Michael Briel / www.mp3.com/briel / briel at archeb.de / ICQ: 15785108 <> From md at drawcard.com Wed Aug 8 03:01:29 2001 From: md at drawcard.com (Damian Andrews) Date: Wed, 08 Aug 01 17:01:29 +1000 Subject: Deadline for .biz & .info approaches!! Message-ID: <200108080708.RAA27601@poxy.bigpond.net.au> Dear Registrant, The most anticipated event since the first release of the dotcoms is here! If you haven't already done so it's time to pre-register your .biz and .info 'Top Level Domain Names' and stake your claim in what is fast becoming a LAND RUSH, "larger than the .com phenomena". With the deadline to pre-register your .biz Sept 17, 2001 and Sept 12, 2001 for .info domains approaching (your only real opportunity to secure a great .biz and/or .info) you must act now secure your trading or generic name(s). At the close of these periods all pre-registrations will be processed first. Up for grabs are names like; news.biz, show.biz and adult.info because of the 'Round Robin' [Not First Come First Serve] selection method adopted by ICANN, the release has effectively become "The Worlds Largest Lottery". We offer you [but only until September 18th 2001] to pre-register your selection of great names with three of the largest biz & .info registrars [Our Channel Partners] in a 3-5 minute process for one low price [as low as US$3.50 per name] this is the lowest price available anywhere including The Registrars Themselves. Heres how it works! Pre-register with one, two or all three of our channel partners at the same time and increase your chances of securing names like 'show.biz or easy.info' up to 300%. Pre-register as many names as you like and save up to 50% with volume discounts. Free.biz! Want to pre-register names like adult.biz for FREE. Easy.biz, simply go to www.drawcard.com enter in your email address at our affiliate page and I will send you an email, with your unique ID that can be forward to all in your address book then all who enter the site by way of that link will earn you US$1.00 per pre-registration. We have people registering 100+ names at a time. Now that's a good.biz! Any and all names you decide to register can come directly off your earnings or if you prefer I will send you a cheque! More_Free.info ? For every 20 names or more you pre-register we will give you free for one year a sub-domain name from the very best of our 'channels partners' like 'yourname at pro.biz', 'yourname at badboy.info'. ? Free home page with every account. ? Free email with every account. This is your very best opportunity to secure 'yourfuture.biz'. But you must Pre-Register and you must do it NOW. Want to see more: http://www.drawcard.com (If this link is not working please cut and paste the link into your browser) If you have received this mailing in error, or do not wish to receive any further mailings from us, simply click here put in your email address and add Remove to the subject line: http://www.drawcard.com/index.cfm?fuseaction=CompanyInfo Damian Andrews MD Drawcard.com From bkelley at wi.mit.edu Fri Aug 24 10:41:39 2001 From: bkelley at wi.mit.edu (Brian Kelley) Date: Fri, 24 Aug 2001 09:41:39 -0500 Subject: Is this possible: scoping question with exec References: <3B8568C4.1010204@wi.mit.edu> <3b857256.276696248@wa.news.verio.net> Message-ID: <3B8667A3.7020806@wi.mit.edu> Bengt Richter wrote: >On Thu, 23 Aug 2001 15:34:12 -0500, Brian Kelley wrote: > >>Running Python 2.1 >> >>def a(): >> return b >> >>exec "a()" in {'b':1, 'a':a} >> >>b doesn't seem to passed as a global into the function a. >> >This seems possible: > >>> exec """def a(): > ... print 'from a()' > ... return b > ... print a() > ... """ in {'b':1, 'a':a} > from a() > 1 > >I'd guess the dictionary for globals used by the function is >determined by the context of the execution of the def? > If that's the case though, I would have expected a compiler/syntax error. I was hoping that I could pass globals into a compiled function though. Guess I'll have to look at the source code and see if this is not possible. Brian Kelley Whitehead Institute for Biomedical Research From maurizio.manetti at arca.net Mon Aug 20 06:58:23 2001 From: maurizio.manetti at arca.net (Maurizio Manetti) Date: Mon, 20 Aug 2001 12:58:23 +0200 Subject: Problem with win32ui MessageBox Message-ID: <3B80ED4F.F37FA70@arca.net> I have the following dummy script: import win32con import win32ui win32ui.MessageBox("Test Message", 'Test', win32con.MB_OK) When I run it from PythonWin it works as expected. If I save it on a script ".py" file and launch it (double click, associated with pythonw) I get the following error: Pythonw has caused an error in Kernel32 I get a similar error if I launch it with "python" instead of "pythonw" If I try twice more time everything crashes and I have to reboot the computer to make something work! I found this problem on two different Win machine (Win98 with Python 2.0 and WinMe with Python 2.1.1) Does anyone know why? And how to solve the problem? Thank you in advance. From sholden at holdenweb.com Wed Aug 1 14:09:54 2001 From: sholden at holdenweb.com (Steve Holden) Date: Wed, 1 Aug 2001 14:09:54 -0400 Subject: [OT] RE: ????????? ???????????????? ?????? ? ?????? References: Message-ID: "Roman Suzi" wrote in message news:mailman.996686763.24335.python-list at python.org... > On Wed, 1 Aug 2001, Kemp Randy-W18971 wrote: > > I am glad to see international spam here to remind US people of existence > of non-US ASCII charsets ;-) > > Clearly, your answer is no more readable, Kemp, because your mail program > do not represent cyrillic characters properly. > > It's a pity computer software/hardware was (and still is) developed with > such a narrow view of the world... Maybe Unicode will solve this problem. [ ... ] Indeed it does, as Outlook Express rendered the whole thing, including the subject line, in apparently perfect Cyrillic for me. Not that that made me any more able to pay them attention. now-i-just-need-to-learn-russian(?)-ly y'rs - steve -- http://www.holdenweb.com/ From notta at chance.net Sat Aug 25 19:43:09 2001 From: notta at chance.net (john anon) Date: Sat, 25 Aug 2001 18:43:09 -0500 Subject: lack of shell in Win2000 References: Message-ID: ya but --- there is no shell ... ah ... never mind "Ignacio Vazquez-Abrams" wrote in message news:mailman.998772879.5363.python-list at python.org... > On Sat, 25 Aug 2001, john anon wrote: > > > at the risk of repeating an old question > > (I looked -- really -- I looked) > > > > if there is no shell in Win2000, how will we start scripts? > > from Explorer? but ... what about command-line args? > > Most likely via cmd.exe, NT/2000's command line interpreter. > > -- > Ignacio Vazquez-Abrams > > > > From steffen.ries at sympatico.ca Sat Aug 25 08:24:44 2001 From: steffen.ries at sympatico.ca (Steffen Ries) Date: 25 Aug 2001 08:24:44 -0400 Subject: seg. fault with ext. module References: Message-ID: "Gorny" writes: > Hi, > > -----code------ > #include > > static PyObject * makesock(PyObject *self, PyObject *args); > > static PyMethodDef gforce_methods[] = { > {"makesock", makesock, METH_VARARGS}, > {NULL, NULL} > }; > > static PyObject * makesock(PyObject *self, PyObject *args) > { > printf("Making socket...\n"); Py_INCREF(Py_None); > return Py_None; > } > > /* Initialization function for the module */ > DL_EXPORT(void) initgforce(void) > { > (void)Py_InitModule("gforce", gforce_methods); > } > -----eof----- > > >>> import gforce > >>> gforce.makesock() > Making socket... > >>> Ctrl-D > Segmentation fault > [gorny at darkstar ~/gforce]$ > > How do I prevent this. If i import other modules and close the python-shell > it'll not end with a segmentation fault, only if it's my module.. Do i have > to make an extra function in it, which `de-inits` the module..?? You forgot to increment the reference count for None, which creates a problem at termination time. See http://www.python.org/doc/current/ext/refcounts.html hth, /steffen From giannozzo at arca.net Mon Aug 20 11:13:57 2001 From: giannozzo at arca.net (Maurizio Manetti) Date: Mon, 20 Aug 2001 15:13:57 GMT Subject: Problem with win32ui MessageBox References: <3B80ED4F.F37FA70@arca.net> <9lr62m01p83@enews4.newsguy.com> Message-ID: <3B812A8C.F1A0228E@arca.net> Alex Martelli wrote: > > "Maurizio Manetti" wrote in message > news:3B80ED4F.F37FA70 at arca.net... > > I have the following dummy script: > > > > import win32con > > import win32ui > > > > win32ui.MessageBox("Test Message", 'Test', win32con.MB_OK) > > > > When I run it from PythonWin it works as expected. > > If I save it on a script ".py" file and launch it (double click, > > associated with pythonw) I get the following error: > ... > > I found this problem on two different Win machine (Win98 with Python 2.0 > > and WinMe with Python 2.1.1) > > > > Does anyone know why? And how to solve the problem? > > Works fine for me on NT4 with Python 2.1.1. I don't see any > obvious reason why it should fail so horribly, either. Yes, you are right, it's just a call to a windows API, but that's what happen to me. I also tried to reinstall pythonwin, but nothing changes. From KurtJansen at go.com Fri Aug 24 18:30:36 2001 From: KurtJansen at go.com (Kurt Jansen) Date: Fri, 24 Aug 2001 15:30:36 -0700 (PDT) Subject: Getting User Name With Apache Basic Authentication Message-ID: <5963105.998692236850.JavaMail.KurtJansen@gomailjtp01> Thanks Oleg, I had to password protect my cgi-bin directory also with .htaccess, and then this environment variable worked. I accessed it with the os.environ['REMOTE_USER'] function. Kurt -----Original Message----- From: "Oleg Broytmann" To: "Kurt Jansen" Cc: python-list at python.org Date: Fri Aug 24 01:02:22 PDT 2001 Subject: Re: Getting User Name With Apache Basic Authentication >On Thu, 23 Aug 2001, Kurt Jansen wrote: >> I would like to set up password protected directories for my Web site >> (Apache) using the htpasswd/.htaccess. This means that whenever a user >> requests a page in the protected directory, they get prompted for a >> userid/password. I would like to capture the userid that the user enters >> from within my Python CGI script. This seems like it would be a common >> thing to do, but I can't find anything in the Python library or this >> newsgroup that addresses it. Anyone have any suggestions? > > It has nothing with Python library. User name is available to a CGI >program in OS environment. Just read CGI specification and figure it out. >The variable name is REMOTE_USER. I hope you can read env vars in Python. > >Oleg. >---- > Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru > Programmers don't die, they just GOSUB without RETURN. > ___________________________________________________ GO.com Mail Get Your Free, Private E-mail at http://mail.go.com From phd at phd.pp.ru Fri Aug 24 09:43:35 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Fri, 24 Aug 2001 17:43:35 +0400 (MSD) Subject: [ANN] SkunkWeb 3.0 Released! In-Reply-To: <20010824091239.G930@naxos.starmedia.net> Message-ID: On Fri, 24 Aug 2001, Drew Csillag wrote: > Funny you mention it... The beginnings of the SkunkWeb FAQ are here: > http://skunkweb.sourceforge.net/FAQ.html Ouch! Not so good, as I though before, at least for Zope. Whether your Mason/Webware observation is good or not so good - I cannot decide, but you've missed Zope almost completely :( Let me say a few words. Don't get me wrong - I am not against SkunkWeb. But your review should be more accurate. Let me try to argue and improve it. > Like Webware, Zope uses a threaded model instead of a forking model Forking Zope would be an issue. It is too heavy. > DTML bites. It hits on making it easy to do easy things, but is too > constraining for the expert because you don't have the full flexibility > of Python in the tags. DTML is presentation language. Don't mix logic and presentation. If you need Python - just use Python, not DTML. > I know that they are working on their next templating language (ZTL) ZPT - Zope Page Templates. It is not "next", it is just another, different approach. But still - if you need Python - use Python, do not program in ZPT. > Many people have written about how having the templates in the ZODB > instead of a filesystem can be a pain because you can't use all of your > usual filesystem tools/editors/etc. Yes, this is correct. Zope Corporation has a plan to move those objects into OS filesystem. > Extending Zope is complicated Arguable. For simple extensions there are ZClasses. And writing a simple Python Product (module, component) is not a hard task. And even for more complicated Products Zope has a very nice API/classes/etc, so you don't nned to program everything. You already have persistent, web interface, etc. > SkunkWeb (like Webware) was designed to be easily extendible and > customizable. I want to read more on this! How to write a DB connector? a module? an object to be published? > To call arbitrary code from Zope templates, you have to create Python > Method objects, which let's be honest, is a pain. Where is the pain? > STML has an import tag Insecure? > I may be wrong on this one, but I don't think that Zope allows you to > cache the output of a template. There are cacheing Products. > Modularity. It's pretty difficult to pull the cool bits out of Zope It is pretty easy to use ZServer, or ZODB, or DTML, or ZPublisher outside of Zope. Now few words about Zope. Zope has an Object request Broker (may be SkunkWeb has it, too). ZServer is a multiprotocol server that already understands HTTP, PCGI, FastCGI, FTP, WebDAV protocols; it is modular, there is, for example, module for HTTPS protocol. There are many Database Adapters for relational databases: MySQL, PostgreSQL, Oracle, Informix, Interbase, Sybase, ODBC. Security integrated into Zope, and is really very well implemented. Acquisition allows you to do very powerful object publishing. ZClasses are for simple programming. ZCatalog - integrated search system. ZEO - clustering component. Many good Products. A lot of good documentation. Oleg. ---- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From just at letterror.com Fri Aug 10 06:00:32 2001 From: just at letterror.com (Just van Rossum) Date: Fri, 10 Aug 2001 12:00:32 +0200 Subject: 100,000 messages celebration? References: <3B7384D0.12FB2B35@letterror.com> Message-ID: <3B73B0C0.ECC3F567@letterror.com> Robin Becker wrote: > on the other hand > > python-byte > A Column from a Wrestling Fan who tells it like it is! If you can't > handle the truth, then don't read it! The Python's Byte is brought to > you by Colin Q. Allegedly has more members than python-list. As usual I have no idea what you're talking about. (The number of members of python-list is of course a fraction of the number of people who read it: it's gatewayed to and from comp.lang.python after all...) Just From ullrich at math.okstate.edu Tue Aug 7 10:24:16 2001 From: ullrich at math.okstate.edu (David C. Ullrich) Date: Tue, 07 Aug 2001 14:24:16 GMT Subject: combinations of variable length nested lists References: <3B6FE3B6.5020605@herts.ac.uk> Message-ID: <3b6ff692.1462602@nntp.sprynet.com> Well there's an obvious "just do it" recursive version. Something like def CartesianProduct(alist): res = [] if len(alist) < 2: for x in alist[0]: res.append([x]) else: tails = CartesianProduct(alist[1:]) for x in alist[0]: for t in tails: res.append([x]+t) return res print CartesianProduct([[1,2,3],[4,5], [6,7,8]]) seems to do what you seem to want. (That's not supposed to be an optimal solution: it makes a lot of assumptions about the input, and no doubt it can be written in far fewer lines, using the functional-programming functions and/or new-fangled Python... but it works, and I think it's easy to see why it works. A "map" in place of the first loop would probably be quicker; I have no idea whether a list comprehension in place of the second (double) loop would be faster, because they have sometimes turned out to be slower in places where you'd think they'd be faster.) On Tue, 07 Aug 2001 13:48:54 +0100, Mark Robinson wrote: >I have hurt my brain (and those who are unfortunate to sit near me ;)) >trying to formulate an algorithm for the following problem. I am sure >that someone here must be able to help me out, it seems such a trivial >problem. > >I have a nested list structure of the following format: >[[2, 3, 4, 5], > [4, 5, 6, 7, 34], > [6, 2, 7, 4] > .... > .... >] > >I want to generate all possible combinations that take one element from >each nested list > >i.e >[2, 4, 6, ..., ...] >[2, 4, 2, ..., ...] > >If I knew the length of the outermost list beforehand I could hard code >it as a series of nested for loops: > >i.e > >for i in list[0]: > for j in list[1]: > for k in list[2]: > comb = [i, j, k] > >but I can't figure a way to do this dynamically at runtime, when the >outermost list is going to be variable in length. > >If anyone can help, I'll be willing to sell my boss into slavery and >give you all the profit ;) Probably the simplest thing is if you send the check to David Ullrich at "Department of Mathematics, OSU, Stillwater, OK 74078". Thanks. >Blobby > David C. Ullrich From syt at pegasus.logilab.fr Wed Aug 22 04:15:54 2001 From: syt at pegasus.logilab.fr (Sylvain Thenault) Date: Wed, 22 Aug 2001 08:15:54 +0000 (UTC) Subject: possibly trivial newbie list/array question References: Message-ID: On Wed, 22 Aug 2001, Sylvain Thenault wrote: >On 21 Aug 2001, Michael Williams wrote: >>I'm an undergraduate doing a relatively simple bit of functional >>programming, looking at the behaviour of Lorenz attractors. My >>department recommends (or uses as standard) Pascal. I'd rather avoid >>this, and Python is something I've been looking into. >> >>(Amongst other things!) what I want to do is multiply an array of >>floating points numbers with a float elementwise, i.e. >> >>>>> [1.0, 2.0, 3.0] * 4.0 >>[4.0, 8.0, 12.0] >> > >IMHO, the faster way to do it consists in using builtin map function: > >map([1.0, 2.0, 3.0], lambda x: 4.0*x) > oops, this is better: map(lambda x: x*4.0, [1.0, 2.0, 3.0]) -- Sylvain Thenault LOGILAB From not.this at seebelow.org Mon Aug 27 13:48:13 2001 From: not.this at seebelow.org (Grant Griffin) Date: 27 Aug 2001 10:48:13 -0700 Subject: intentional tease ( was: New Python User Question) References: Message-ID: <9me14t01035@drn.newsguy.com> In article , tanzer at swing.co.at says... > > >Grant Griffin wrote: > >[delightful musings skipped] Thanks. :-) >> In Python, this function works equally well for lists, tuples, arrays, >> or Numeric arrays full of integers, floats, or longs (except that it >> always returns a float--darn!) That's beautiful. But in all honesty, >> how often do you really _need_ to do generic programming? I'm >> guessing, only a very small fraction of the time--1%, maybe? Most of >> the time, you (the programmer) really do know what types you're >> working with--even if Python doesn't, not because Python's stupid, but >> because it's not as smart as you, and you haven't told it (which, if >> you think about it, isn't really the smartest thing you ever did >> .) > >Your statement about the rarity of generic programming might apply to >you (although I doubt it) but in general its just plain wrong. Of course, this varies depending on what you're trying to do--in both general and in specific cases. In all honesty, most of what _I_ use Python for could be categorized as "text processing". Basically, I read in a file and turn it into a different file, or maybe make summaries of it. (I'd like to use Python for more.) I also once did a fairly complicated DSP simulation in Python, using NumPy. (Most DSP folks would use Matlab for ath, but I like Python because it's much more beautiful. And it's much cheaper .) Python has become an essential tool for me, but, unfortunately, due to the speed/size issue, I'm able to use it only for "offline" PC tasks like this. My own production code generally runs in embedded systems. In those cases, due to the inherent requirement for maximum speed and minimum size, one has little choice but to use a compiled language. (Historically, due to compiler availability, one has had little choice in DSP but to use C, though C++ compilers have recently become available for DSP microprocessors.) In embedded systems (and many other application domains), using an interpreter is simply not an option. Other posts in this thread have suggested that the lesser speed of Python is worth what you gain in development time. I wholeheartedly agree--at least in those cases where you can trade the two. For the offline data processing I do, it's a no-brainer: use Python. But depending on how many embedded boxes one plans to sell, the ease of development of Python can _truly_ be false economy, if it forces you to put $10 of extra computer inside the box. (Python still makes a good prototyping language, though.) More imporatantly, you sometimes simply couldn't get there from here if you used an interpreter. Although there are might be some folks who can spend 100.0% of their programming lives in Python (except when they have to write extension modules ), I suspect that _most_ folks who use Python do part of their work in Python and part in a compiled language--probably C/C++. *KEY POINT*: Anything that greatly speeds Python (and a compiler--in whatever form--is the only thing we can reasonably expect would, after 10 years of careful tweaking by lots of talented folks!) increases the percentage of programs we can write in Python. That is undeniably A Good Thing. However, in working on my little project, I've realized that even leaving dynamic variables aside, certain things in the design of Python are inherently "slow". A simple example is the fact that Python allows negative array indices. When implementing that, one can only check for a negative index, then add the length. And even if it wasn't negative, you have to bounds-check the result, to possibly raise an IndexError. (An "assert" won't do: the Python code might have been written to rely on an IndexError.) Therefore, compiled Python will always be slower than something written from scratch in C++ (which doesn't do bounds-checking: you write it where you need it rather than it happening automatically in every case). > >Using generics in Ada or templates in C++ might be difficult for the >average programmer but doing generic programming in Python is so >trivial that just about everybody does it. True. Like I said, I was doing it in Python and I didn't even know it. I guess that means it must be easy! But for the vast majority of offline text-processing tasks I do in Python, I'm not sure generic programming is of much use. In these cases, the data consists almost entirely of strings, lists of strings, dictionaries of strings, etc. And I, the programmer, know all that in advance. In such cases, I'm writing code that wants to be statically typed, and that makes it a good candidate for compilation. Although Python has a few methods common among strings, lists, and tuples, any code that uses a special string method (e.g. split) wants the string to be statically typed: you're not going to be using that code for lists, tuples, ints, floats, files, etc. I bet there's nobody who has used Python for more than a month that hasn't used a string method. Moral of the story: even those who claim to do a lot of generic programming don't do it 100.0% of the time, so even they can benefit from a little static typing. >Every time somebody >reassigns sys.stdout to something which is not a file, they are are >enjoying the benefits of generic programming. But we can do that sort of thing in C and C++, even without templates. C pointers are good for that (Python uses 'em!), and C++ virtual functions are even better. Dynamic typing is just one technique among many to do generic programming. > >> OK, so what if a system already existed that provided the benefits of >> generic programming (when you _do_ need it), without the overhead? >> What if that system wasn't Python, but, with a little work (a _lot_ of >> work actually--that's why I need your help!), could be made to _seem_ >> like Python? >> = > >> I'm seeing a speed factor that ranges from about 1:1 to 70:1, >> depending on the algorithm. Also, as compiled programs, my executables >> are a lot smaller than equivalent "frozen" Python programs, and are >> *much* harder to de-compyle. > >Now that certainly sounds interesting. Thanks. (Maybe my little dishwasher story worked .) >Will your system also allow the >use of generic programming when the need for it was not foreseen by >the original author of the code (for instance, the passing of an >object of a compatible but completely different type as an argument to >a function)? Yes. It's built on top of another system of generic programming, so that capability comes for free. Suppose you invent a new type XYZ and you want to make a list of XYZs. No problem. Suppose you want to reassign sys.stdout. Enjoy. Also, it comes with its own system of dynamic types. I'm not sure this part is really mature yet, but it does work. For example, an averaging function similar to what I posted previously accepts lists or tuples populated with integers or floats. BTW, I learned something important in this thread. I originally created my system of dynamic types mainly just to emulate Python--and also because it was a fun design problem. In all honesty, though, I didn't really think anybody would use it much if a system of static types was available. But I just learned that it _is_ important, if for no other reason than user acceptance. (When you create something like this, you have to eliminate as many excuses not to use it as you can .) But I bet the static types will be much more popular in the end. I'm not sure that my system of dynamic types will run a whole lot faster than Python's. (I haven't benchmarked it yet.) Instead, I think the real "bang-for-the-buck" of my system (in terms of speed) is due its option of using static types. >If not I'd rather stay with Python. I'm not trying to replace Python, just expand it's universe. When the benefits of speedier, smaller-than-"frozen", more obscured executables are not of interest, Interpreted Python will *always* be a better choice than my system. Interpreted Python will always have more features, and will always be more mature. I don't have any plans to stop using Interpreted Python myself. However, I suspect that one or more of the benefits of Compyled Python will be of interest to nearly everybody at some time or another. (Just ask yourself: If such a thing existed, worked well, and were free, would I use it? Honest answer for most folks: yes, at least every now-and-then.) Remember, folks, I come not to bury* Ceasar, but to praise him. filching-is-the-sincerest-form-of-flattery-ly y'rs, =g2 *or depose _____________________________________________________________________ Grant R. Griffin g2 at dspguru.com Publisher of dspGuru http://www.dspguru.com Iowegian International Corporation http://www.iowegian.com From aleax at aleax.it Thu Aug 9 05:41:05 2001 From: aleax at aleax.it (Alex Martelli) Date: Thu, 9 Aug 2001 11:41:05 +0200 Subject: Python2.2 doesn't give members of a list References: Message-ID: <9ktlrf01vcs@enews1.newsguy.com> "Tim Peters" wrote in message news:mailman.997328534.2490.python-list at python.org... ... > The new scheme is better because more consistent and predictable, but the > change in dir(builtin_object) is starting to look like it *may* be a bad > incompatibility with 2.1. Much as I hate doing it, for this reason I'm > going to look into hacking inconsistent surprises back into dir(). It's a *GOOD* incompatibility, albeit a definite one, so might we PRETTY PLEASE get a from-future-import hack so we can have the right behavior for dir in the future without breaking stuff now...? Alex From reqhye72zux at mailexpire.com Mon Aug 20 10:44:52 2001 From: reqhye72zux at mailexpire.com (Robert Amesz) Date: Mon, 20 Aug 2001 14:44:52 GMT Subject: MSHTML References: Message-ID: Jay Parlar wrote: > For the application that my colleague and I are working on, it is > necessary that we be able to take the raw HTML of some document and > pull out just the text, with all tags removed. > > [COM stuff snip'd] > > My question: Is there any method to supress all the other IE stuff > so I can essentially use MSHTML as a pure replacement to > HTMLParser? All that trouble just to get at the plain text of HTML-documents? That sounds a bit over the top to me. The only possibe reason I can think of to justify it is if Javascript or VBScript issues document.write()'s or modifies some part of the DOM directly. (That might also have something to do with why the thing crashes every now and again: perhaps concurrent access to the DOM tree isn't too reliable. Perhaps there's a property which you can query to check if the document is fully loaded and processed.) I am afraid I don't know how to suppress all that IE stuff, but I presume that at least for some of those nag-messages properties can be set to get rid of those, along with other security-related settings. You really need to get some documentation about the HTML COM object, I guess searching the MSDN site would be a good place to start. But I'd be willing to bet you can't get rid of all unwanted behaviour. Alternatively, why not run an HTML file through W3C's Tidy first, that will get rid of most of the errors (providing it doesn't get too confused) and continue to use Python's HTML (or SGML) parser. That would seem like a much more robust (and portable) scheme. Robert Amesz From aleaxit at yahoo.com Sun Aug 12 06:02:32 2001 From: aleaxit at yahoo.com (Alex Martelli) Date: Sun, 12 Aug 2001 12:02:32 +0200 Subject: from __future__ import generators References: Message-ID: <9l5k630luj@enews4.newsguy.com> "Fran?ois Pinard" wrote in message news:mailman.997568899.18926.python-list at python.org... > [Guido van Rossum] > > > If enough people prefer to always have the 'yield' keyword enabled, we can > > do that. I thought that there would be a huge opposition against breaking > > code this way, but maybe it's OK. At least 'yield' is not a silent break. > > My voice is surely not representative, but it is a voice nevertheless. > When the direction is good, I prefer to see things moving forward, and > would avoid `from __future__' here. Yet, I also understand the concerns you > have about not disturbing other Python users. My opinion is that globally > replacing `yield' by something else, using about any editor, is an easy > challenge. It could be advised somewhere in the transition documentation. Since this is apparently a straw vote or something, let me add my voice to Fran?ois's -- particularly since I was the one originally opining that a 'from __future__' would be needed anyway, and I was wrong. Yes: given that it's not a SILENT break, it's probably OK to make yield a keyword "cold turkey". I do have a couple of uses of it (curiously with quite different semantics) but a global search and replace will fix them. Alex From andy_todd at spam.free.yahoo.com Mon Aug 6 02:25:33 2001 From: andy_todd at spam.free.yahoo.com (Andy Todd) Date: Mon, 06 Aug 2001 06:25:33 GMT Subject: NEWBIE TIP: Displaying the contents of an imported module...from ENGSOL References: Message-ID: wrote in <: > >I think I'm hung up on the substitution thing again. If I wanted to >name this 'show.py' and be able to use 'python show.py math' on the >command line - how do I get "import sys.argv[1]" to work. (and I would >already have imported 'sys.') I tried 'eval()' without success - kept >getting "invalid syntax" although the proper string was shown. > > - fleet - OK, using the code below and encapsulating it in a function, we get something like; """ def getDoc(moduleName): "Print all of the doc strings for a module" module=__import__(moduleName) for x in dir(module): try: print "%s\n%s\n%s\n" % (x, '-'*35, module.__dict__[x].__doc__) except AttributeError: print "*** no __doc__ for %s.%s\n" % (moduleName, x) """ If you want to put this into an executable (getdoc.py for instance), add this at the bottom of the file; """ if __name__=="__main__": if sys.argv[1]: getDoc(sys.argv[1]) """ And Bob's your Auntie's live in lover. Of course, you need to import sys and os at the top of the file for it to actually work. Oh, and there are a couple of smalls problem with the function 'getDoc' as it stands; - It prints the __doc__ strings of all of the modules that are imported by module. Thats potentially an awful lot of output. Do you really want to see all of it? - It doesn't print the __doc__ string of module. It will try to print module.__doc__.__doc__ which will always (probably) raise an AttributeError. I leave the resolution of those two 'issues' to the reader ;-) > >> From: Tom Robinson >>Subject: Re: NEWBIE TIP: Displaying the contents of an imported >>module...from ENGSOL >> >>Here's a hack to show the __doc__ for everything in a module: >> >>import os >> >>for x in dir(os): >> try: >> print "%s\n%s\n%s\n" % (x, '-'*35, os.__dict__[x].__doc__) >> except AttributeError: >> print "*** no __doc__ for os.%s\n" % (x) >> >>-- >>tom at alkali.spamfree.org >>remove 'spamfree.' to respond >>-- > > > Regards, Andy -- Content free posts a speciality From skip at pobox.com Fri Aug 31 09:11:57 2001 From: skip at pobox.com (Skip Montanaro) Date: Fri, 31 Aug 2001 08:11:57 -0500 Subject: Formatting question : printing numbers with thousands separators ? In-Reply-To: References: Message-ID: <15247.36125.220801.298960@beluga.mojam.com> Fred> how do I print 246814345 as 246,814,345 (or 246 814 345) ? I'm sure there are more clever ways, but this seems to work: def separate(n, sep=','): ln = list(str(n)) ln.reverse() newn = [] while len(ln) > 3: newn.extend(ln[:3]) newn.append(sep) ln = ln[3:] newn.extend(ln) newn.reverse() return "".join(newn) >>> separate("2342342342344567") '2,342,342,342,344,567' >>> separate("2342342342344567", sep=' ') '2 342 342 342 344 567' >>> separate(5) '5' >>> separate(35) '35' >>> separate(235) '235' >>> separate(1235) '1,235' >>> separate(1235, ' ') '1 235' -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From dnjjones at yahoo.com Wed Aug 8 20:02:23 2001 From: dnjjones at yahoo.com (Jeremy Jones) Date: Thu, 09 Aug 2001 00:02:23 GMT Subject: dynamic naming for hierarchical data problem Message-ID: I apologize if this is a dupe. I tried to post earlier and it appeared not to send out. I want to be able to dynamically build a hierarchical set of data. (Forgive me if I am not using the proper terminology or if what I mean by a term is completely different from what the rest of you mean by the same term. I am still a very new newbie and am just converting to Python after a couple of years of perl. I will try to clarify what I mean.) By hierarchical, I mean that there will be parent-child relationships and that the parents and children should be aware of one another in their respective relationships (i.e. the parent should be aware of its children and children should be aware of their parents). By dynamic, I mean that the names in the set of data will very likely be extracted from a text file or entered in by a user at run time. I also mean that the number of levels in the hierarchy will potentially be variable and will be defined at run time. I would prefer this set of data to be contained in one object. Right now, I have the following, which is a three tier set of dictionaries that are associated with each other: ################################ cs1_cmd1 = {'OPEN': 'RESULTS'} cs1_cmd2 = {'CLOSE': 'RESULTS'} cs2_cmd1 = {'OPEN': 'RESULTS'} cs2_cmd2 = {'CLOSE': 'RESULTS'} cs2_cmd3 = {'CLOSE2': 'RESULTS'} cs3_cmd1 = {'OPEN': 'RESULTS'} cs3_cmd2 = {'CLOSE': 'RESULTS'} command_set1 = {'cmd1': cs1_cmd1, 'cmd2': cs1_cmd2} command_set2 = {'cmd1': cs2_cmd1, 'cmd2': cs2_cmd2, 'cmd3': cs2_cmd3} command_set3 = {'cmd1': cs3_cmd1, 'cmd2': cs3_cmd2} test_set = {'TEST1': command_set1,'TEST2': command_set2,'TEST3': command_set3} ################################# which I can manipulate with much weeping gnashing of teeth. A couple of problems with this (other than the fact that it is just plain hideous to look at): 1) A child doesn't really know who its parent is. 2) The data is not dynamic: it has to be built from within the script at design time and not run time. 3) On the dynamic topic, I can't just add a child. I have to create kind of a reference in the parent to another dictionary. 4) It is scattered across 11 dictionaries (even though it has one base dictionary that acts as the root parent). I want to do the above more elegantly, more concisely and less painfully. I have read the python FAQ, searched usenet, searched Google, scoured www.python.org and have only come up with a few possibilities for doing what I want to do (such as metaclasses and acquisition and some virtual file systems), but I am not sure that they will address the solution for the problem that I have. Does anyone have any ideas on how I can begin to attack my problem? Does anyone have any ideas on specific methodologies for dynamically named hierarchical data? Can anyone point me in the direction of documentation that might aid me in my quest? Does anyone know of similar projects that I may be able to look at? Any assistance would be most appreciated. Thanks in advance. Jeremy Jones From aleaxit at yahoo.com Thu Aug 16 16:10:13 2001 From: aleaxit at yahoo.com (Alex Martelli) Date: Thu, 16 Aug 2001 22:10:13 +0200 Subject: Newbie question Python on Windows ME References: <3b7bf8e9.8917437@news.t-online.de> Message-ID: <9lh9cl01qmi@enews3.newsguy.com> "Gerson Kurz" wrote in message news:3b7bf8e9.8917437 at news.t-online.de... > On 16 Aug 2001 09:39:51 -0700, s.franke at flowstate.com (stefan) wrote: > > > Are there any tutorials for beginners on the internet that are > >specifically written for Windows? > > For windows I would recommend using the Pythonwin IDE that is part of > www.activestate.com/activepython. [There was I think a standalone > distro of Pythonwin although I don't know of its status]. It's still available, as part of Activestate's win32all add-on to the standard Python distribution. In other words, if you start with the standard Python distribution, you can later download from ActiveState, and install later, win32all, and get pretty close to where ActivePython would have gotten you in the first place (not quite, though). > - Pythonwin is an excellent GUI ide - on Windows most people don't > like the commandline, and especially on the 9x/ME series the > commandline is seriously lacking in features. It has a builtin editor But IDLE comes with standard Python and works fine (you'll prefer PythonWin if you like the MDI style, but that's now passe on Win32). > with syntax highlighting, folding, etc. It has a nice debugger. It > integrates with SourceSafe etc. > - Searchable (CHM) Helpfiles You can get good CHM files at http://www.orgmf.com.ar/condor/pytstuff.html. It may be worth doing even if you have ActivePython, since those add more material, such as the FAQs and /F's Tkinter intro. > - ActivePython has much deeper Windows integration. (eg, you can use > COM objects in it, use it for client-side browser scripting and all > sorts of fine stuff) You get all this with the win32all add-on, too. Don't get me wrong: ActivePython is excellent -- I'm just pointing out that there are interesting alternatives, too (though they'd all be almost for naught were it not for win32all...:-). Alex From max at alcyone.com Thu Aug 9 02:14:36 2001 From: max at alcyone.com (Erik Max Francis) Date: Wed, 08 Aug 2001 23:14:36 -0700 Subject: Interesting problem - can it be done References: Message-ID: <3B722A4C.F8D9005C@alcyone.com> Mark Sass wrote: > I have a list of strings and the strings are functions that I want > to > call on an object. So you mean methods. > How do I call the functions without hardcoding the > function call? Here is an example > > funclist = ['func1()', 'func2()', 'func3()'] > x = len(funclist) > y = 0 > while y < x: > value = testobj.funclist[y] > y = y +1 What you want is the getattr function, which takes an object and a string representing an attribute name (but with no parentheses). You can then call that. Another obvious thing missing is the for idiom, which iterates over list. This means you can avoid the while loops and the iteration variable: methods = ['method1', 'method2', 'method3'] for method in methods: value = apply(getattr(testobj, method), ()) getattr turns the instance and the string attribute name into a bound object, then apply calls it. The () is the tuple of arguments, which in this case is empty. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Love is like war: easy to begin but very hard to stop. \__/ H.L. Mencken Maths reference / http://www.alcyone.com/max/reference/maths/ A mathematics reference. From robin at jessikat.fsnet.co.uk Tue Aug 7 12:20:37 2001 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Tue, 7 Aug 2001 17:20:37 +0100 Subject: Zope python paths References: <0q4MdKA6m+b7Ewpm@jessikat.demon.co.uk> <9kotiu$265g$1@norfair.nerim.net> Message-ID: In article <9kotiu$265g$1 at norfair.nerim.net>, Gillou writes >Robin, > >Have a look at this registry key (for me, it's in Win2K): > >HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.1\PythonPath > >I think a python 2.1 engine for Windows will find the python path here at >startup. >Make some changes to this key (i.e, add any directory) and see what happends >in your Zope test. >If it changes in your Zope test too, perhaps you should provide a PYTHONPATH >in the script that starts Zope to override this. >Or make a small change in the Z2.py > >--Gilles .... OK it seems to ignore 2.1\PythonPath default value C:\Python\Lib\plat-win;C:\Python\Lib;C:\Python\DLLs;C:\Python\Lib\lib-tk but the subkeys PythonWin=C:\Python\Pythonwin win32=C:\Python\win32;C:\Python\win32\lib win32com=C:\Python seem to be respected. I have changed z2.py to eliminate these and my path now looks OK. Seems to me like an official 'install' should take care to eliminate initial paths which aren't below sw_home\bin. -- Robin Becker From aleaxit at yahoo.com Thu Aug 2 10:54:41 2001 From: aleaxit at yahoo.com (Alex Martelli) Date: Thu, 2 Aug 2001 16:54:41 +0200 Subject: Typing system vs. Java References: <9kb8mq02bd2@enews1.newsguy.com> Message-ID: <9kbpjj0kb@enews1.newsguy.com> "Michael Abbott" wrote in message news:Xns90F19B5D37704michaelrcpcouk at 194.238.50.13... > [posted and mailed] > > Alex, I'd like to say more in response to your very interesting message > below, but it's difficult to know where to begin. I agree wholeheartedly > with your sentiments, but I'm wondering if you're aware of just how > difficult what you're describing is to achieve!? I suspect we may be talking at cross-purposes -- I don't request a language that will in fact absolutely CHECK assertions containing universal or existential quantifiers, nor one that will always be able to take advantage of them to further optimization or other type-inference goals: just one that will let me *express* such assertions simply, which, per se, isn't all that hard. Surely it wouldn't be the first time a language let me express design-intent aspects without committing any implementation of the language to doing anything in particular about them! Don't you recall the 'register' keyword in C, for example? Nowadays compilers do their own register allocation -- but I still get to express my design intent "and, I believe this thing here should live in a register" to my heart's content. Not much, as far as expression design intentions goes, but, a start. Similarly, I recall BSD variants where my programs were ALLOWED to give hints to the operating systems about their intentions wrt some files or memory areas -- "I think I'll just read this file right through" or "I'll jump up and down all over this file in random-access so I don't think I would bother doing any prefetch if I were you", and so on, and so forth. Sometimes, when reading such programs, such expressions of design intent were illuminating, in ways that comments and other forms of documentation rarely are. And, hey, maybe SOME versions of the system did/will take advantage of my design-hints, so, why not? We may have gotten too focused on the imperative and declarative to exploit the value of *design-intent hints*. The assertions I'd like to be able to make aren't just hints, but even if they work like no more than that, I still think they'd be a pre-req before one can state a language has types in a meaningful sense. Eventually, 'checking modes' where some of the assertions were partially checked (maybe just at runtime, maybe just during some kinds of very thorough tests...), and 'optimizing modes' where some of the assertions were relied upon for possible optimizations (maybe just when compiling with "optimize all you can please" flags), might emerge. Automatic deductions and inferences would be a potential further step. But I think the key step is the first one -- ALLOWING me to express those design-intent constraints! I won't pay a dime extra to be able to say something pretty useless such as "I intend X to be a list" (particularly because it's *NOT* what I _really_ should intend -- 'a mutable sequence', MAYBE:-); I might be much better disposed could I express "I intend X to be a mutable sequence with an odd number of items such that at all times items with an even positive index are strictly greater than either of their neighbors" -- now *THAT* is what I'd call "typing". (No, I wouldn't insist on THAT being checked at compile-time... even checking it at RUN time might be expensive enough that I'd be quite content with only checking partially, and/or only when using certain flags, if at all -- but my point is that, THIS is the kind of things I find myself wishing I *COULD* usefully express, *NOT* 'X is a list', 'Y is a complex', 'Z is a tuple of float'... so, I think that for languages to claim they're doing 'typing checks' for me, when such trivialities is all they can or do check, violates truth in advertising!-). Alex From SPMSXsunkcosts at pobox.com Thu Aug 23 16:20:49 2001 From: SPMSXsunkcosts at pobox.com (Steve) Date: Thu, 23 Aug 2001 15:20:49 -0500 Subject: Python Books References: <3B850C4E.CE483F1A@jam.rr.com> Message-ID: <230820011520496447%SPMSXsunkcosts@pobox.com> In article <3B850C4E.CE483F1A at jam.rr.com>, Rob Andrews wrote: > *Teach Yourself Python in 24 Hours* (published by SAMS) is actually a > nice beginner text. I was skeptical because of the title, but it has > turned out to be a local favorite. I am about midway through this, and I have to give a newbie thumbs down to this one. The author seems earnest enough in wanting to spread the Python love. He also gives you solid advice in approaching Python programming from a 50K foot level. But the methodology and examples are a real drag for a newbie like me. Too much time is wasted on general conceptual history and theory when discussing Python components, and not enough time spent on giving a lot of examples of Python code in understandable settings. As soon as a newbie builds that first, tiny app that makes their life a tad bit easier, they'll be hungry to learn more, and they'll process new info that much faster. You can't get this rush by talking about theory, and the author's personal, eclectic interests can be a real drag if you're not interested in the same thing (Mayan calendars, number theory, programming history, etc.) It's not just me; check out the Amazon reviews on this book. You'll see a similar theme. Steve From ignacio at openservices.net Fri Aug 31 03:32:49 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Fri, 31 Aug 2001 03:32:49 -0400 (EDT) Subject: Overflow error when printing long values In-Reply-To: Message-ID: On Fri, 31 Aug 2001, Michael Teo wrote: > Thanks for your help. > However, I noticed that Python 2.1 does not give a trailing 'L' for str(l). > Is there any solution which will work well for Python 1.5.2 and Python 2.1 ? s=str(n) if s[-1]=='L': s=s[:-1] -- Ignacio Vazquez-Abrams From heikowu at ceosg.de Wed Aug 22 19:43:03 2001 From: heikowu at ceosg.de (Heiko Wundram) Date: Thu, 23 Aug 2001 01:43:03 +0200 Subject: IRC Client : Where to begin In-Reply-To: References: Message-ID: <01082301430300.00436@phoenix> On Wednesday 22 August 2001 23:16, you wrote: > [lots of tiny little (unimportant) development remarks removed] Dear Relfx, it is true, or does it only appear to me, that you have never programmed seriously (better: larger projects) in Python (or in any other language) before? (Your question whether it is better to partition a project into separate files or not) Nor had any contact with the basic layer of TCP/IP communication (which the module asynchat adresses)? (Your question of where to begin with all the documentation that was offered) Nor had any contact with the low layer of the IRC protocol (not that what mIRC offers you)? (You asked it directly) Nor had any contact with a different OS than Windows 98-2000? (Your question concerning GUI vs. Non-GUI; Windows is actually always GUI, except for DOS-mode, which dropped out in 2000 anyway) Sorry to have to say it that way, but you're missing on all the important programming principles that are the basis when trying to write a program that serves as a client for the Internet Relay Chat Network. I guess that you want to start to learn programming Python, but why not try something smaller (and different) for a start? What I'll try to do here is layout something I did when I started programming back in the 80's. (I was in primary school back then) I had started programming an external interface I got for running my model-train, but I never knew what I did, I just had a big hunk of documentation that was with the interface and I always kept typing in commands they listed (used GWBasic back then). <--- Ad 1-4: That's the situation you are facing now. People sent you lots of documentation info that you actually don't know how to use because you don't know about the basics. ---> Well, I wasn't too satisfied with that, I wanted to do something on my own. But as I didn't know what all those commands were doing, I realized that I would first have to walk my way up the ladder with something different. I chose something that I thought would be handy in school, a little program that would ask me maths-questions like (200/40?) and would wait for an input and then compare that to the true result. If it matched, it would say 'OK!', otherwise it would beep and say 'Wrong...'. Well those were (I think, I wouldn't be able to reproduce them today anyways... ;)) 10-20 lines of Code in GWBasic, but I knew exactly what they were doing. Some days later I expanded the whole thing. I added a loop that would ask a question at least three times before giving up with 'Wrong...', some days later again I expanded the whole thing with a scoring system based on the time it took to answer, some days later again I expanded the whole thing with a system that would only give you a certain amount of time to answer a question, etc. etc. etc. Then in '88 I got MS QuickBasic 4.5. I ported the whole thing (yep, Basic was incompatible with Basic), and tried to add some fancier text-mode graphics such as a text-mode banner which could only be viewed well when I put my PC on slow mode (I had an 80386 SX-16 back then, man was that fast ;)) When in '91 I got access to Turbo C++ 3.0 (a different programming language), I ported the whole thing to C++. And in time I added support for TurboVision, that was a text-based GUI-Interface they were shipping along. And I added DOS-mode sound support using direct writes to the SoundBlaster (yes, direct hardware programming was still in back then) Then in '94 I got access to MS C++ 6.0 (I think it was...). And thats when I did my first step towards GUI-programming, still using the old Windows API. I didn't come far here, btw. It actually stagnated my programming for three years... ;) And when in '97 I got access to MS Visual C++ 5.0 (yet a different programming language), I ported the whole thing and again added support for a GUI based on the MFC. And I added support for TTS and Voice-Control of the program using the stuff that they shipped with MS Visual C++ 5.0 Enterprise. And also in '97 I started with Tcl (and esp. Linux), to which I ported the whole thing again (of course without all the fancy features of TTS, etc.) ... blablabla I could continue now, but I think you get the point. Start off small (to learn the basics), and then always keep adding things on top. You have to start this way bottom up, only a true genius will succeed top down. Why not take a small project that might come in handy for you in daily life (you choose one), then go and buy a good book on Python, and then learn Python and especially good programming practice step by step by implementing something like I did above? Please, please, please, take my advice seriously! Don't let yourself be disencouraged (and I know its a stony road), but please start from bottom up! For one you have an actual feeling of success when you have built a small project, and secondly you feel even more success when you manage to add a feature to the project. On another note: I really don't understand why you still keep asking people in this newsgroup/mailinglist for help, as noone has so far offered help besides giving you references to documentation, but which you yourself say don't (yet) mean much to you. I'm also going to give you documentation at the end, but this documentation is not about anything concerning your IRC-client project, but rather something general about programming and Python. And on a third note: I guess people here actually aren't all that fancied by the idea of having an IRC-client that is scriptable through Python (or written in Python). It sounds hard, but that's Usenet. People will only get annoyed when you continue "bugging" them in this fashion. Believe me, I've had this experience more than once, and it's absolutely no fun to be on thetarget list of a mail-loop. ;) Don't flame me for this message; in my eyes this had to be said. And Relfx don't let my words discourage you, Python is a way cool programming language which is easy to learn, and fun to discover. (btw. I'm new to Python too, started looking into it about 3 Months ago after I felt angry with Perl once too often... ;)) And if anyone is interested, the little program that I still try to write in every language I move to is called "KOPF". ("Kopfrechnen" means calculating in your head in German... ;)) -- Yours sincerely, Heiko Wundram Head and founding-member of the "Celler Open Source Gemeinde" (Celle Open Source Community) From mestesso100 at yahoo.com Sat Aug 25 01:57:23 2001 From: mestesso100 at yahoo.com (FunkyTritone) Date: 24 Aug 2001 22:57:23 -0700 Subject: Can zope do this? Message-ID: <71550321.0108242157.2ee16aa8@posting.google.com> Sorry if this is off topic, I couldn't find a zope specific ng. I'm learning Zope these days, and I'd like to put up a server with it, but before I invest time and money I'd like to know if Zope is the correct tool for what I'm trying to do: I'm trying to semplify the creation of "standard" company sites. With standard I mean the they need a subset of the usual services (news, catalogs, user registration). The PHP + MySQL solution works fine but it takes too much time to build everthing. And using Zope I could use their wonderful admin as back office. So I'd like to create with zope these services (catalog, ...), and somehow create the new site putting all these pieces together, and giving the site administrator (the one who controls the site contents) some specific access (to insert new products, etc..) to the zope admin. Can it be done? Is a good idea giving the site admin some access to the zope admin? Or should I build some back office interface from scratch? (I'd love to use Zope's admin, it's just wonderful) How many sites do you think I could serve from such a Zope server (usually small sites, few megs of data, around 1000 hits a day)? Any answers will be really appreciated! Thanks :-) Giovanni From ignacio at openservices.net Sun Aug 26 22:13:30 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Sun, 26 Aug 2001 22:13:30 -0400 (EDT) Subject: Python Packages for Complex Numbers and Matrix Math In-Reply-To: <7xhi7.178110$g_3.31431688@typhoon.austin.rr.com> Message-ID: On Mon, 27 Aug 2001, Maan Hamze wrote: > > "Ignacio Vazquez-Abrams" wrote in message > news:mailman.998866419.18595.python-list at python.org... > > On Sun, 26 Aug 2001, Maan Hamze wrote: > > > > > 2. Also, > > > >>> x = 4 + 7j > > > >>> x.imag = 6 > > > error: object has a read-only attrib > > > >>> x.real = 7 > > > same error of read-olny attrib > > > > > > why? > > > > Because. I could look into the source (or point you to the source), but > the > > answer would still simply be "Because". > > > So to pass a value to either the imag or real part: > >>> a=1 > >>> b=2 > >>> c=complex(a,b) > >>> b = 3 > >>> c=complex(a,b) > and so on........ > or something like: > >>> def PassValue(a,b): > ... r=complex(a,b) > ... return r > Maan Yeah. Or you could do something like 'r=complex(r.real, 6)', or 'r=complex(7, r.imag)', or 'r=complex(-(r.imag), r.real)', etc. -- Ignacio Vazquez-Abrams From xauau at yahoo.com.au Sat Aug 4 03:14:08 2001 From: xauau at yahoo.com.au (xauau) Date: 04 Aug 2001 17:14:08 +1000 Subject: Typing system vs. Java References: <4197FA5DD22AD5118ADE00805F6FA62F3B67FD@eden.vmlabs.com> <5k1nmts15l7nsio00bmht2gnp12tbuq3qn@4ax.com> Message-ID: <87u1zoe1q7.fsf@xeno.localhost> Courageous writes: > [...] I've concluded that comprehensible tersness trumps all > other measures of merit. Sounds good to me, Joe. > I believe that there is a sort of Occam's Razor of Coding, as it were, > where given two different programs which execute identically, the one > which is shorter, simpler, and easier to understand is the better > program, notwithstanding any principles it may or may not adhere to. > > Various different rules which have crept up over the years such as > "don't use global variables," and "practice strong encapsulation," > and so forth are all only distractions and are useless to the degree > that in any particular context they don't satisfy Sir Occam's relentless > blade. I've also been thinking similar thoughts for some time. I regularly see people going to extreme lengths to protect themselves from themselves. It often fails because it adds unnecessary bulk and complexity in exchange for the false sense of security that following a method brings with it. Take "information hiding" as one small example. In theory it's reasonable that _some_ data should be encapsulated and accessed only through strictly defined interfaces. In practice, though, it's often a case of interring trivial functionality deep inside a perilously constructed wall of cruft. I've seen lots of C++ and Java programs that really should have been very simple and clean. They end up being complicated because the majority of the program consists of small pieces of simple functionality trying desperately to contact each other through nearly impenetrable walls of "protection". When you're not in the mood to laugh at it, it's a truly pitiful spectacle. -- And there's a dreadful law here -- it was made by mistake, but there it is -- that if anyone asks for machinery they have to have it and keep on using it. From rtexier at elikya.com Fri Aug 10 08:06:52 2001 From: rtexier at elikya.com (Romuald Texier) Date: Fri, 10 Aug 2001 14:06:52 +0200 Subject: pyFlash References: Message-ID: <9l0igv$ke4$1@news.irisa.fr> MNX tech services wrote: > Would it make sense to use static Flash 5.0 pages as a browser-based GUI > against a Python backend? Wouldn't it have the advantage of displaying > absolutely uniformly across all platforms, along with providing a vast > array of widgets? > > KSmith > > Do you know about B.Y.P. ? http://web.interpuntonet.it/bypserver/ -- Romuald Texier http://iprotools.elikya.com From m.1.robinson at herts.ac.uk Sun Aug 5 09:23:55 2001 From: m.1.robinson at herts.ac.uk (Mark Robinson) Date: Sun, 05 Aug 2001 14:23:55 +0100 Subject: why no ++? References: <3B6A6B97.2060306@herts.ac.uk> <3B6AA8A1.4000907@herts.ac.uk> <9kf46r014ba@drn.newsguy.com> <3B6C22DC.7060509@herts.ac.uk> Message-ID: <3B6D48EB.9080001@herts.ac.uk> Courageous wrote: >> Well, never one to simply take someones word I have performed a small >> scale experiment to test your previous statement. I conclude that it >> needs a small modification. It isn't strictly true that you can't pick >> your friends nose, but it is surely true that you shouldn't. > > > I'm not sure about that. Perhaps your approach was all wrong. I recommend > the following experiment. Approach 100 women at random in your local mall. > Kindly ask permission to pick their nose. Report your results back here. unfortunately if you ask for permission you end up with a sample size of zero. Guess it is probably a fundamental limitation of science blobby From dcinege at psychosis.com Sun Aug 19 19:27:48 2001 From: dcinege at psychosis.com (Dave Cinege) Date: Sun, 19 Aug 2001 19:27:48 -0400 Subject: Changing argv of the python process References: <6barntgq6dnednsa03d5f9elbo0vip2mkt@4ax.com> <2133453.fYGdeWWPft@lunix.schabi.de> Message-ID: <3B804B74.E8CBFC3C@psychosis.com> Markus Schaber wrote: > > > Right. That is EXACTLY why he wants to alter argv. At this moment I have no need to alter argv for anything. I just found it odd python by default limited your control of modifing the true argv and listed common reason's why it's a desirable option to be able to do so. > But there's always a moment where another user can gather the unaltered > argv. Yes, for a millisecond, and that someone must have access to the process tree, and must be able to run a user process in a race condition to attempt to grab such info, probably with no idea when execution will commence, making the servers load average of *10* quite obvious to even the dumbest admin. Generally, this means that user must have unlimited shell access, and generally only trusted users should be allowed such access to a server in the first place. And after all of this high speed parsing roulette, odds are they'll likely miss grabing the fucking thing anyway... So, thank you and the others for continuing the offtopic answer to my question... (Which should have been, "No it's not built in, and no their's no 3rd party modules to do it.") While you all were mentally masturbating over the security consequences of *not limiting a programmer* from modifing argv, I went and wrote a patch to sys to allow argv modification. I will be posting it to the list when I get a chance to make a proper diff and document it. From michael at rcp.co.uk Tue Aug 28 11:11:44 2001 From: michael at rcp.co.uk (Michael Abbott) Date: Tue, 28 Aug 2001 15:11:44 +0000 (UTC) Subject: Stackless Python and Python 2.x Message-ID: What's the current status of Stackless Python in relation to the developing Python 2.x implementation? I can see that there's a patched version of Stackless Python for version 2.0 (http://www.stackless.com/) and there's PEP 219 describing an inspiration for this idea. However, I also see that PEP 219 is marked as deferred and that PEP 220 (which covers the details) contains a brief abstract only. Of course, we now have generators (PEP 255) in Python 2.2, which takes us part of the way there, but the gap remains big! So, my question is whether coroutines are likely to make it into Python in the forseeable future? From rob at jam.rr.com Wed Aug 29 10:03:32 2001 From: rob at jam.rr.com (Rob Andrews) Date: Wed, 29 Aug 2001 14:03:32 GMT Subject: Python Books - Which one? References: <3B8CF4D9.B9D0D4@cyberway.com.sg> Message-ID: <3B8CF5F2.8050505@jam.rr.com> Graham Ashton wrote: > In article <3B8CF4D9.B9D0D4 at cyberway.com.sg>, "Paul Lim" > wrote: > > >>I am a newbie in Python programming. I hope the guru can adivse me. >> Here's my advise: Whatever books and tutorials you choose, take good advantage of the Python Tutor list (http://mail.python.org/mailman/listinfo/tutor). If you have questions about the material you encounter, you can ask. And when you see someone ask a question you just figured out, you get the joy of being able to answer it! > > Are you a newbie to programming too, or just Python? I'd be after advice > from somebody who has just been through the process that you are about to > start, rather than a coding guru who won't need the same kind of book as > you. > > >>I would like to acquire a book for my python programming. There are >>generally three main books in my mind >> >>1. Programming Python by O'Reilly >>2. The Quick Python Book >> > > What's the third? > > I've not seen the Quick Python Book so can't comment on it. I've got > Programming Python though (second edition). I think it's a very good book > but it's not a tutorial by any means. It is packed full of extensive > examples however, which teach application design as well as Python syntax. > > If you've got prior programming experience and understand the language > constructs covered in the Python tutorial (http://www.python.org/doc/) and > Dive Into Python (http://diveintopython.org/) then Programming Python > wouldn't be a bad choice. It is very thick though and I'm finding that I > sometimes don't have the patience to read the coverage of each topic > fully, partly because I'm impatient, partly because the coverage (in > parts) is a little too waffly for my taste. > I tend to think of Programming Python 2nd ed. as an incredible *second* Python book. I'd say it does have a tutorial feel to it, but on the intermediate level. > My favourite book for learning more Python is currently the Python > Essential Reference which has an approach similar to O'Reilly's nutshell > series (i.e. concise overview of language followed by library reference). > It's by no means verbose but that's not usually a problem. Another > excellent book is Python Standard Library. There is quite a bit of overlap > between those last two though. > > I hear that Wesley Chun's book is very good (I think it's called Core > Python Programming). I nearly bought that instead of Programming Python, > and still wonder whether I should have. I didn't get it because I didn't > like the layout that much - I know, it shouldn't be so important to me, > but I didn't find the text quite so accessible (personal quirkiness on my > part). > Core Python Programming seems like a dandy first Python book. I also add to that list Alan Gauld's Learn to Program Using Python. When it is released soon, Python How To Program (Prentice Hall) is also going to be a fine offering for beginners and introductory classes. > >>Can anyone recommend to me which is better? Or is there any better book >>out there? I am looking for a book that is reader friendly but contain >>substantial material that will last me quite some time. >> From what I've seen, any up-to-date Python book you find will have enough material to engage for quite some time, especially if used as a compliment to the many online tutorials, HOWTOs and discussion forums. Quality and volume of content do not seem to be problems for Python books right now. And a quick search for "Python" at your favorite bookseller's website should reveal a very healthy variety of offerings currently available. > > Well, what level of experience do you have? > > So you can gauge my comments a bit, I did Perl for five years before > trying Python in earnest about 3 or 4 months ago. > > -- > Graham > -- Learning to program is fun again. Useless Python! http://www.lowerstandard.com/python From list.adam at twardoch.com Tue Aug 21 06:09:06 2001 From: list.adam at twardoch.com (Adam Twardoch) Date: Tue, 21 Aug 2001 03:09:06 -0700 Subject: [Q/newbie] Converting object names to strings and back? References: <9lt4c601feq@enews4.newsguy.com> Message-ID: "Alex Martelli" > Of course, it's horribly dangerous to evaluate just any expression > unless you're *REALLY* sure about where it's coming from -- which > is part of why it's quite unlikely that this is what you should > really be doing. Thank you. Eval was indeed what I was looking for. I did read some FAQs, and two books but you know -- it's so much stuff that you easily get confused. I do occasional programming, and each time it's got to be a different programming language (Java, PHP, VB, JavaScript, Perl, and now Python). Basic syntax of a language is easy, but it's really hard to keep track on all the ready built-in functions etc. which usually make out the real power of a language. In this very case, the code will be from a trusted source. The project is not intended for public access, but rather for some internal work. And even if the code breaks occasionally, it doesn't matter. :) > the 1.5.2 part, > which means you're forced to use a release that's years > old Yes, but that's the version which is built into the application that I'm scripting. Thank you so much! Adam From phd at phd.pp.ru Fri Aug 10 06:17:55 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Fri, 10 Aug 2001 14:17:55 +0400 (MSD) Subject: the usage of pickle In-Reply-To: Message-ID: On Fri, 10 Aug 2001, Dino Hsu wrote: > >>> def f(): > return '123456' > >>> f > > > >>> pickle.dump(f,'test.txt') 1st error - you cannot dump a function, only a data object. You can dump/load code objects with marshall module. > Traceback (most recent call last): > File "", line 1, in ? > pickle.dump(f,'test.txt') > File "c:\python21\lib\pickle.py", line 939, in dump > Pickler(file, bin).dump(object) > File "c:\python21\lib\pickle.py", line 104, in __init__ > self.write = file.write > AttributeError: write 2ns error - you've passed text string as 2nd parameter. pickle.dump expects open file-like object. Examples: pickle.dump(f, open('test.txt', 'w')) or s = StringIO.StringIO() pickle.dump(f, s) # now use s.getvalu() as string dump. Or just use pickle.dumps(f) :) Oleg. ---- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From digitig at cix.co.uk Fri Aug 3 20:42:00 2001 From: digitig at cix.co.uk (Tim Rowe) Date: Sat, 4 Aug 2001 01:42 +0100 (BST) Subject: Language change and code breaks References: Message-ID: In article , jschmitt at vmlabs.com (John Schmitt) wrote: > > -----Original Message----- > > From: Guido van Rossum [mailto:guido at python.org] > > Sent: Tuesday, July 24, 2001 12:51 PM > > To: python-list at python.org > > Subject: Re: Language change and code breaks > [...] > > The language would remain case-sensitive, and you would be free to use > > it that way in any tool you chose, but there would be a separate tool > > available that enforced case-preserving case-sensitivity for those who > > prefer it. > [...] > > There you have it folks. This is the same thing that Guido ended with > the > last time this issue came up. > > To summarise: The language will not change to be case-insensitive. > Python, > the programming language, will remain case-sensitive. > > Thank you very much, Guido, for stating it. I'm hoping that we can keep > this message and quote it as the BDFL proclamation on this issue the > next > time it arises. > > Personally, I'm happy to hear that the language will stay > case-sensitive and > that I can choose to use or ignore a tool that provides > case-insensitivity. > Hopefully a tool that would provide this isn't tied to something I would > like to use. Seconded. Actually, I'd be happy of the tool that did this did so optionally, so I could still use it with that feature turned off :-) From tim.one at home.com Wed Aug 15 23:45:11 2001 From: tim.one at home.com (Tim Peters) Date: Wed, 15 Aug 2001 23:45:11 -0400 Subject: Dumb python questions In-Reply-To: <7xu1z8pv9t.fsf@ruckus.brouhaha.com> Message-ID: [Paul Rubin] > ... > Here's something I don't understand: why is it that the default > value of a function arg is evaluated just once, instead of whenever > the function is called? Simply because that seemed most useful most often, and is most consistent with the rest of the language: default arguments are a kind of binding performed at function definition time, and there are no instances of "delayed assignment" anywhere in the language. Note that "def" is an executable statement in Python, not a declaration ("class" is also executable, btw -- the only declaration in Python is the "global" stmt). Note that this pattern is common: import math def angular(angle=math.pi): whatever del math # get this out of the module namespace If the default arg were evaluated every time angular was called, the only result of calling angular would be a runtime NameError (since "math" is history by the time angular is called). > The manual has a warning about that and examples of how to program > around it, but it seems like poor design to need such a warning. If it evaluated defaults every time the function got called, the manual would have to give a warning about *that*, and examples of how to program around it. Since neither behavior is wholly compelling, you pick one and point out that it isn't the other, or you drop the whole idea. If we were afraid of operations someone might think work in a way other than they actually do, we'd have to drop, oh, subscripting, addition and input from Python too . The question to me isn't whether a behavior may be surprising, but whether it's easy to *remember* after you first learn it. Everyone gets bit by the default argument rule once; few people seem to get bit by it twice; and I *expect* they'd get bit more often if Guido had picked the other rule. adders = [] for i in range(10): def an_adder(a, b=i): return a+b adders.append(an_adder) all-behaviors-are-exploitable-and-exploited-ly y'rs - tim From sandysj at asme.org Fri Aug 17 10:34:04 2001 From: sandysj at asme.org (Jeff Sandys) Date: Fri, 17 Aug 2001 14:34:04 GMT Subject: Art of Unit Testing References: Message-ID: <3B7D2B5B.AACB14B3@asme.org> Jesse W wrote: > Do you have any suggestions on how to deal with learning > to use unit testing in this way, or examples of setting > up games with this kind of unit testing, or GUI programs? There is a great example from pyunit.sourceforge.net http://diveintopython.org/roman_divein.html I think that unit tests have there greatest value in refactoring and later when the code needs a revision for new functionality. Thanks, Jeff Sandys From just at letterror.com Sat Aug 11 10:54:38 2001 From: just at letterror.com (Just van Rossum) Date: Sat, 11 Aug 2001 16:54:38 +0200 Subject: 2.1.1 global weirds References: <9l35hb03081@enews1.newsguy.com> Message-ID: <3B75472D.42A3B1B4@letterror.com> Robin Becker wrote: > not exactly good programming though if I later I import run from a in a > different main script. > > Isn't this a wart? That sentence certainly is ;-) Just From michael at stroeder.com Tue Aug 28 14:48:10 2001 From: michael at stroeder.com (Michael =?iso-8859-1?Q?Str=F6der?=) Date: Tue, 28 Aug 2001 20:48:10 +0200 Subject: Multithreading support for BaseHTTPServer References: <3b8b7daf.699296734@news.isar.de> Message-ID: <3B8BE76A.C74B0D27@stroeder.com> Gerson Kurz wrote: > > class HTTPServer(SocketServer.TCPServer): > [..] > File "D:\Python21\Lib\BaseHTTPServer.py", line 262, in handle > self.raw_requestline = self.rfile.readline() > File "d:\python21\lib\socket.py", line 233, in readline > new = self._sock.recv(self._rbufsize) > AttributeError: 'int' object has no attribute 'recv' > > Any ideas? Any simple method of multithreading BaseHTTPServer? Python 2.1? Grab 2.1.1 which probably contains the fix for that. Ciao, Michael. From guido at python.org Fri Aug 10 23:36:29 2001 From: guido at python.org (Guido van Rossum) Date: Sat, 11 Aug 2001 03:36:29 GMT Subject: 100,000 messages celebration? References: <3B7384D0.12FB2B35@letterror.com> <3B742612.BCEFB452@letterror.com> Message-ID: > > Is the Y axis a cumulative total, or messages per unit > > time. > > Per unit time. It's straight from the numbers at > http://groups.yahoo.com/group/python-list/ But notice that since it's exponential, the curve would have the same shape if it was a cumulative total. :-) --Guido van Rossum (home page: http://www.python.org/~guido/) From sheila at spamcop.net Wed Aug 29 22:53:57 2001 From: sheila at spamcop.net (Sheila King) Date: Thu, 30 Aug 2001 02:53:57 GMT Subject: Follow-up: Win32/Posix file locking References: Message-ID: <3farotcj9dg3fee0mt76ekkforqr71je1n@4ax.com> On Wed, 29 Aug 2001 20:20:44 -0400 (EDT), Ignacio Vazquez-Abrams wrote in comp.lang.python in article : :On Wed, 29 Aug 2001, Sheila King wrote: :> def getReadLock(self): :> start_time = time() :> while time() - start_time < MAXTIME: :> try: :> self.f = open(self.filename, 'r') :> self.fd = self.f.fileno() :> fcntl.lockf(self.fd, fcntl.LOCK_SH | fcntl.LOCK_NB) :> return 1 :> except: :> self.f.close() :> del self.fd : :Ouch. I would put a short delay in here so that CPU usage doesn't go through :the roof by accident. What sort of time interval would you suggest? 0.1 seconds, perhaps? Or is that too short? :> ----------------------(begin winMutexFile.py)---------------------- :> ... :> import os :> from time import time :> :> try: :> import win32file :> from win32con import GENERIC_READ, GENERIC_WRITE,\ :> FILE_SHARE_READ, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL :> except ImportError, e: :> print e :> print "winMutexFile.py requires ActiveState.com Python win32 :> extensions" : :Hmm. I'm thinking that you need some sort of a raise here so that it stops. Yikes! Thanks for catching that. Duh. : :Looks good. Just two other things: : :1) I'm wondering if assigning None to fd might be faster than deleting it and : recreating it. :2) The error messages use string concatenation when using a format string : might be cleaner. : :Other than those few things it looks very good. Thanks for looking it over, and for the suggestions. One other thing I've decided to change, is to move the file open out of the loop in getReadLock in the posixMutexFile.py module. Somewhere in the newsgroup someone posted in an article about a multi-thread profiler, that file opening is expensive. So, I changed the way I handled that a bit. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From loewis at informatik.hu-berlin.de Thu Aug 2 12:30:13 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 02 Aug 2001 18:30:13 +0200 Subject: is there a JDOM like library? References: Message-ID: "David" writes: > Is there a DOM/XML GPL'd library for Python that is as easy to use as JDOM? > Element root = doc.getRootElement(); > Element child = root.getChild("foo"); > String text = child.getText(); >>> from xml.dom.minidom import parseString >>> doc = parseString("Hallo") >>> root = doc.documentElement >>> root.childNodes[0].nodeValue u'Hallo' Regards, Martin From ykingma at accessforall.nl Tue Aug 7 18:18:59 2001 From: ykingma at accessforall.nl (Ype Kingma) Date: Tue, 07 Aug 2001 23:18:59 +0100 Subject: questions.part #2 References: <9kpj1s$pp1$1@usenet.otenet.gr> Message-ID: <3B70691A.9D93282B@accessforall.nl> Dear reader, whats_really_hot wrote: > > This is the second post of mine. First, I would like to thank all u that > responded to first post. Here I repeat some of the questions of my first > post, because they were not properly answered or cause I didn't get straight > answers. > In the first post u answered me that in Unix based platforms "cat" command > starts the creation of a module. OK, now I go on with some more queries. > On Unix I'd prefer to use vi over cat. Others use other editors like emacs, or the editor in the Python development environment. But this subject is off topic here. > 1. When we type "dir()" in the interactive command line prompt get among all > the others the module "__name__" which really tell us the name of the module > that we are . But now we are in the interactive command line prompt, which > is a module with the name "__main__". Now, my question is, why isn't > __name__ = __main__? (Why isn't __name__ substituted by __main__? > This is simply a difference between interactive interpreter and the 'main python program' interpreter. The difference is not specified by the language, it is just that these environments are not completely the same: any python interpretation may start with some variables predefined. > Sorry for repeating this question but I didn't really get a clear answer. > Even the docs are bit terse about this. > 2. What is the difference between "!=" and "<>" (which really mean > "different")? > I think only their origins are different: != comes from C, <> comes from Pascal (who remembers Jensen and Wirth nowadays?). In python they are equivalent, but it is possible that one of them is more favoured. > 3. Are the built-in tools (such as "len", "sort" etc) maintained in a folder > into the Python directory, so as I can access and edit them? > They are implemented as functions in the implementation language, currently C or Java. You can access them by extracting the sources during python installation. In case you need the precise names of the equivalent functions, just ask here. > 4. What is the difference between "%d" and "%i" (which really point > integer values)? > Pass, my C usage is too far in the past. See the docs on the % operator. > 5. What does it mean that Python is a "high-level language" and other > languages, such as C, are low-level? > In python you don't need to declare variables and a variable can be set to a reference to a value of any type. When the parser does not detect syntax error in Python, everything is executed until an uncaught exception occurs. Execution of a declaration or import has the effect of adding name(s) to the namespace used by the interpreter. Other statements change the references/values of the names in the applicable namespace. > Sorry for the simplicity of some of the above questions, but are crucial for > me for the full understanding of Python. > > Thanks again for ur attention and immediate responds. My pleasure. > > Mail me: whats_really_hot at hotmail.com By request. Please see the newsgroup for more answers. Good luck, Ype -- email at xs4all.nl From joonas at olen.to Fri Aug 31 07:38:52 2001 From: joonas at olen.to (Joonas Paalasmaa) Date: Fri, 31 Aug 2001 14:38:52 +0300 Subject: Integrating HTTPServer and GUI Message-ID: <3B8F774C.C2E900F2@olen.to> I have made a httpserver that prints all its logs into Tkinter Text window. The only problem is that when the GUI reads data from the server with os.read, the GUI is blocked. Any suggestions how to solve this? Is there any other ways to implement realtime communication between threads than os.pipe and using globals. - Joonas #!/usr/bin/python import threading, time, sys, BaseHTTPServer, os from Tkinter import * PORT = 80 log_lines = 20 requests = 0 pipein, pipeout = os.pipe() class HTTPWrapper(BaseHTTPServer.BaseHTTPRequestHandler): def do_GET(self): global requests requests += 1 self.send_response(200) self.send_header("Content-type","text/html") self.end_headers() self.wfile.write("it works!") def log_message(self, format, *args): os.write(pipeout, "%s - - [%s] %s\n" % (self.address_string(), self.log_date_time_string(), format%args)) class SimpleWidget(Frame): def add_line(self, line): if self.number_of_lines >= log_lines: self.text.delete("1.0", "2.0") self.text.insert(END, line+"\n") self.number_of_lines += 1 self.infolabel.set(str(requests)+" requests since startup") def get_server_info(self): self.update() self.new_char = os.read(pipein, 1) #this blocks the GUI if self.new_char == "\n": self.add_line(self.linebuffer) self.linebuffer = "" else: self.linebuffer += self.new_char self.get_server_info() def __init__(self): self.number_of_lines = 0 self.linebuffer = "" Frame.__init__(self) self.pack() self.infolabel = StringVar() Label(self, textvariable=self.infolabel).pack(side=TOP) self.infolabel.set("foo") Button(self,text="Shut down server", command=self.quit).pack() self.text = Text(self) self.text.pack() self.get_server_info() httpd = BaseHTTPServer.HTTPServer(("", PORT), HTTPWrapper) threading.Thread( target=httpd.serve_forever ).start() SimpleWidget().mainloop() From aleaxit at yahoo.com Wed Aug 15 04:12:47 2001 From: aleaxit at yahoo.com (Alex Martelli) Date: Wed, 15 Aug 2001 10:12:47 +0200 Subject: Dumb python questions References: <7xd75xlv86.fsf@ruckus.brouhaha.com> Message-ID: <9ldauj01j69@enews3.newsguy.com> "Paul Rubin" wrote in message news:7xd75xlv86.fsf at ruckus.brouhaha.com... > I just started playing with python and haven't been able to figure > out the following things from the docs I've found: > > 1) Suppose I have a complex number like a = 3+4j. How do I get the > real and imaginary parts separately? I guess I could say > x = (a + a.conjugate())/2 > y = (a - a.conjugate())/2 > but I can't take this language seriously if that's what the designers intended. The a.real and a.imag read-only attributes of a are what you're looking for. > 2) Is there a way I can tell if a value is of an integer type? That is, > I want to write a function is_int(x) so that > is_int(3) = 1 # 3 is an integer type > is_int(3L) = 1 # 3L is an integer type > is_int(3.0) = 0 # 3.0 is float type > is_int(3+2j) = 0 # 3+2j is complex type There are several approaches you can take for this. type(x) returns the type object for x, and you could compare that for equality with type(1) or type(1L), but this is probably the worst approach. The builtin function isinstance(x,type(1)) currently has the same results as the typetest type(x)==type(1) but should work better in the future when it becomes possible to inherit from all builtin types. With the current behavior of division, def isinteger(x): return 0==x/(x+x) would work, as integer division truncates, but that's slated to change so I wouldn't rely on this. (This would raise an exception if x==0, too, so that would have to be tested separately). See also the newly revised PEP on long/integer unification: http://python.sourceforge.net/peps/pep-0237.html eventually, isinstance(i, integer) should do exactly what you ask for, but I get the impression it won't be in 2.2 yet. > 3) Are the complex math functions specified to have any particular > branch cuts? If they're unspecified, what happens in the actual cmath > implementation? If they're unspecified, I'd like to propose that the > Scheme/Common Lisp conventions be adopted in a future version. Fully specified at http://python.sourceforge.net/devel-docs/lib/module-cmath.html for example: acos(x) Return the arc cosine of x. There are two branch cuts: One extends right from 1 along the real axis to ?, continuous from below. The other extends left from -1 along the real axis to -?, continuous from above. and so on. Alex From MarkH at ActiveState.com Mon Aug 6 20:02:47 2001 From: MarkH at ActiveState.com (Mark Hammond) Date: Tue, 07 Aug 2001 00:02:47 GMT Subject: win32com: get error 80004005 in attempt to use a pythom COM serve r References: Message-ID: <3B6F3096.8020201@ActiveState.com> LArbilla at pav.com wrote: > I'm seriously stuck (2 days now) at my first attempt to use win32com to > write a com server in python. > I've search and read all I could find and I still don't see how to solve the > problem: ... > and it didn't make a difference > - I also tried commenting out the line "_reg_class_spec", which > has the only reference to "raecom" and it didn't make a difference Try re-registering the class without this _reg_class_spec_ attribute - it should them work correctly. Also, look for posts of mine on this newsgroup detailing how to debug PythonCOM servers - you should then be able to see all tracebacks generated by the PythonCOM framework. Mark. From ullrich at math.okstate.edu Wed Aug 1 09:32:52 2001 From: ullrich at math.okstate.edu (David C. Ullrich) Date: Wed, 01 Aug 2001 13:32:52 GMT Subject: (in)exactness of complex numbers References: <3b62cc78.3396597@nntp.sprynet.com> <3B676D3A.E436943A@cosc.canterbury.ac.nz> Message-ID: <3b6803bd.349341@nntp.sprynet.com> On Wed, 01 Aug 2001 14:45:14 +1200, Greg Ewing wrote: >"David C. Ullrich" wrote: >> >> But why should the real and imag of a complex be required to be >> floats in the first place? Why shouldn't they be allowed to be >> floats or rationals or integers? > >A complex number, in the mathematical sense, is >not a pair of other numbers -- that's just one >way of *representing* a complex number. Well thanks for clarifying _that_. Duh. (Not that it makes any difference here, but since you undertstand the math so much better than I do: Exactly what definition of "complex number" do you have in mind here? The _standard_ definition _is_ "pair of real numbers".) >If you have some application for which you >need pairs of numbers that are restricted to >being integers or whatever, they're not really >complex numbers, and so you can't blame Python's >complex type for not helping you. What a silly point of view. Suppose that the only "real" numbers in Python were floats, no integers. Someone says that exact integers would be nice. You point out that an integer is not really a real number (which is true in some sense) and therefore we can't expect Python "real numbers" to include ints as well as floats. I mean I've said _many_ times that this was not an actual request. But the fact that an integer-complex is in some sense not "really" a complex number seems exactly as pertinent to the question of how Python should work as the fact that an integer is in some sense not a real number. >-- >Greg Ewing, Computer Science Dept, University of Canterbury, >Christchurch, New Zealand >To get my email address, please visit my web page: >http://www.cosc.canterbury.ac.nz/~greg David C. Ullrich From borcis at geneva-link.ch Wed Aug 22 09:37:13 2001 From: borcis at geneva-link.ch (Borcis) Date: Wed, 22 Aug 2001 15:37:13 +0200 Subject: Deposing Dictactors References: Message-ID: <3B83B589.2AC3C421@geneva-link.ch> Tim Peters wrote: > It's all the same to *you* in the end anyway, because I'll die much sooner > than Guido > all's-for-the-best-in-this-best-of-all-possible-worlds-ly y'rs - tim Pick answers to : (a) Yes, but isn't it a classical (e.g. pre-quantum) fallacy, to have world possibility not concieved as a matter of viewpoint ? (b) You mean you expect Guido to finish his life as immortal software ? (c) If by hypothesis you were to decide to mean (b), do you think this should suffice to make (a) otherwise irrelevant in context, from logical grounds ? (d) what bounds can you prove, to the cardinality of the class of expected states of ultimate fact equivalent to that state of ultimate fact hoped-for in (b), for the purpose of maintaining invariance of your answer to (c) ? (e) what should happen if we exchange "expected ultimate statement of fact" for "expected state of ultimate fact" in (d), together with a coordinated transform of "that state of ultimate fact hoped-for in (b)" to "the statement of hope in (b)" ? aesthetical-sense-is-to-soul-as-eye-is-to-physical-viewpoint-ly yours, Boris Borcic From iddwb at imap1.asu.edu Wed Aug 1 16:36:25 2001 From: iddwb at imap1.asu.edu (David Bear) Date: Wed, 1 Aug 2001 13:36:25 -0700 Subject: mod-python or pypython Message-ID: was wanting to enhance apache with faster cgi. I intent to exclusively use python for scripting. I was wondering which would be a better way to go, using mod-python or pypython.. any one have recommendations? David Bear Support Systems Analyst, ASU internet: David.Bear at Asu.Edu voice: (602)-965-8257 fax: (602)-965-9189 From sholden at holdenweb.com Sat Aug 4 19:20:13 2001 From: sholden at holdenweb.com (Steve Holden) Date: Sat, 4 Aug 2001 19:20:13 -0400 Subject: XOR two bytes? References: <3B6C5985.EA285A07@pacbell.net> Message-ID: [posted & mailed] "Tim Rowe" wrote in message news:memo.20010805001357.60291M at digitig.compulink.co.uk... > In article <3B6C5985.EA285A07 at pacbell.net>, sntial at pacbell.net (Jeanne) > wrote: > > > Does anyone know if there is a function to quickly Xor two bytes > > together? > > I have been searching in the docs, but havent' been able to find it. > > Please cc: my cris_paltenghe at yahoo.com address as I don't hang out in > > this newsgroup often. Thanks for your help! Cris > > Do you mean '^'? If the bytes are single-character strings then the ord() and chr() builtin functions complete the picture. >>> def xorchars(c1, c2): ... return chr(ord(c1) ^ ord(c2)) ... >>> xorchars("A", "a") ' ' >>> xorchars("A", "c") '"' >>> regards Steve -- http://www.holdenweb.com/ From erno-news at erno.iki.fi Mon Aug 20 15:26:22 2001 From: erno-news at erno.iki.fi (Erno Kuusela) Date: 20 Aug 2001 22:26:22 +0300 Subject: ANN: a new utility for Python developers References: Message-ID: In article , "Tim Peters" writes: | The Python profiler is written in Python, and uses Python's | time.clock() mouldn't it be better to use something with a little more resolution on non-win32 platforms, like gettimeofday() ? -- erno From aleaxit at yahoo.com Fri Aug 17 14:44:57 2001 From: aleaxit at yahoo.com (Alex Martelli) Date: Fri, 17 Aug 2001 20:44:57 +0200 Subject: Novice Question on HTTP Session Persistence References: Message-ID: <9ljon012h1e@enews2.newsguy.com> "chief crazy bLanKeT" wrote in message news:mailman.998069439.9056.python-list at python.org... > Hi, > > Is there a document on how to persist objects (like username and login > information for ex.) into the HTTP session ? See module Cookie in the standard Python library (2.1 and later, I believe). Alex From nospam at nospam.com Sat Aug 18 16:32:08 2001 From: nospam at nospam.com (Grace) Date: Sun, 19 Aug 2001 05:32:08 +0900 Subject: Art of Unit Testing References: <3b7ccedc$0$2974$e4fe514c@newszilla.xs4all.nl> <3B7D6351.2B6B2031@ccvcorp.com><5hsqnt08u6n3cu7921c66cokcr6mkv79pn@4ax.com> Message-ID: "David Goodger" wrote in message news:B7A3F696.16481%goodger at users.sourceforge.net... > Paul Moore wrote on 2001-08-18 08:19: > > On Fri, 17 Aug 2001 11:32:49 -0700, Jeff Shannon wrote: > >> Well, the alternative argument could be that, if you don't need to setup and > >> teardown in between various tests, then they could be coded as subtests of a > >> single, larger test... OTOH, if you *do* have high setup/teardown overhead, > >> which *does* require being redone for each test, then coding it each time > >> would be a pain. Lumping subtests together is easier than multiple copies of > >> setup/teardown... > > > > I'm not sure I agree. The long and short of it is that both cases can happen. > > But look at my example "for real" (sort of) > > > > class testSimpleQueries(unittest.TestCase): > > def setUp(self): > > # May take seconds to execute... > > self.connection = DB.Connect(connect_str) > > def tearDown(self): > > self.connection.Disconnect() > > def exec_query(self, q): > > "Trivial helper to run a query" > > return self.connection.Execute(q) > > def testQ1(self): > > "Simple query" > > q = "select 1 from dual" > > assertEqual(1, self.exec_query(q)) > > def testQ2(self): > > "Exception when no rows returned" > > q = "select 1 from dual where 1=0" > > assertRaises(DB.Error, self.exec_query(q)) > > # And 100 more trivial queries... > > > > You get the idea. The setup costs a *lot* in relative terms of time (each test > > query takes, say, 0.01 second). You really want to only do that once. But you > > don't really want to code a single huge test - it destroys the reporting of > > the individual test docstrings by unittest.main(). What do you do? > > The setUp/tearDown mechanism can ensure that each test is independent of any > state left over from any other test. If you know your tests won't leave any > state behind, you could put your DB.connect() call in > testSimpleQueries.__init__. (Don't forget to call unittest.TestCase.__init__ > though.) Again, this assumes that none of the individual tests will change > the state of the connection. To close the connection, you could put the > self.connection.Disconnect() call in testSimpleQueries.__del__; but there's > no guarantee when (or even if?) this will be called. No, it won't work. The __init__ is called for each test method for the class that inherits TestCase -- PyUnit creates as much instaces of TestCase class as the number of test methods, in this case those starting with "test-". One of the golden rules of unit testing is "make it fast." Most of the time, it shouldn't take more than a few mins at one run -- C3 had over 1300 unit tests, performing over 13,000 individual checks altogether, which ran in about 10 minutes in visual works. The fastness of running unit tests is necessary for TestDrivenDesign and MercilessRefactoring. To make it fast, you should do high-cost things such as db connection, insert/delete, as infrequent as possible. Yet you want to test as much as possible. One alternative to using live dbs is using small test dbs, but after all it can lead to a real mess if a multiple of developers and test cases trying to do the db test. (you could in-line the db in the test code instead) Another one is using shunt pattern. When I look at your code, it seems like it's testing DB itself rather than the python code. PyUnit is not intended for testing DB engines per se. "Some tests make sure that the lowest layer of database access works as planned. Then I write a suite based on the assumptions demonstrated by the first suite. It assumes that I can get things into and out of the real database, so I don't have to have the real database there. That way I can create an in-memory impostor for the database and exercise the higher level objects." [PPR] Putting lots of SQL statements at a higher layer would, as one of many disadvantages, reduce code testability enormously. (refer to http://www.c2.com/cgi/wiki?BadFormedPersistenceLayer) From R.Brodie at rl.ac.uk Mon Aug 13 08:50:12 2001 From: R.Brodie at rl.ac.uk (Richard Brodie) Date: Mon, 13 Aug 2001 13:50:12 +0100 Subject: string bug/oddity? References: <3B77150B.9F8FC079@engcorp.com> <9l7k5i$5eh$1@panix2.panix.com> <9l7tt9012o@enews2.newsguy.com> Message-ID: <9l8ie6$nu2@newton.cc.rl.ac.uk> "Alex Martelli" wrote in message news:9l7tt9012o at enews2.newsguy.com... > Simpler, yes. Not necessarily faster, and I was surprised when I > actually measured iteration on .keys vs iteration on .items: the > allocation/building of the N pairs may apparently take longer > than the N [] indexing operations. Measure the two alternatives > if you do need top speed at this point... On a quick test with a large dictionary, items() was slowest. Using iterators to avoid building the large list, iteritems() was fastest. From orib at writeme.com Wed Aug 15 19:21:38 2001 From: orib at writeme.com (Ori Berger) Date: Thu, 16 Aug 2001 02:21:38 +0300 Subject: string hash, and an email to stimpy. Message-ID: <3B7B0402.38DA26A6@writeme.com> Disclaimer: It's been over 2 years since I was last regularly reading c.l.p (drop "regularly" for all practical purposes); I've gone through the last 200 posts or so, and so no mention of what I'm about to post, but it _may_ be old news. (I didn't see any mention of Guido's time machine either, nor Moshe's "which fun to me, I'm not signing permanent" signature. At least Tim's -ly yours style is still here). And to the point: I was browsing 2.2a1 CVS repository through source forge's web interface. I looked at exactly two files, and found exactly two puzzling things: -------------- File: [Development] / python / python / dist / src / Objects / stringobject.c (download) (as text) Revision 2.122 , Thu Aug 2 04:15:00 2001 UTC (13 days, 18 hours ago) by tim_one Branch: MAIN CVS Tags: after-descr-branch-merge, HEAD Changes since 2.121: +50 -26 lines Merge of descr-branch back into trunk. --- (somewhere down below, inside string_hash) len = a->ob_size; p = (unsigned char *) a->ob_sval; x = *p << 7; while (--len >= 0) x = (1000003*x) ^ *p++; x ^= a->ob_size; --- Do you really mean that hash function? Do you trust compilers to optimize that multiplication well enough? Won't a hashpjw-style hash be faster to compute? Will the direction of entropy reverse? The following CVS entry is the only reference I could find (and it took me quite some time to find, since I searched for "hash" rather than "hach" ....) is: --- Revision 2.31 / (download) / (as text) - annotate - [select for diffs] , Wed Sep 11 20:22:48 1996 UTC (4 years, 11 months ago) by guido Branch: MAIN Changes since 2.30: +1 -1 lines Diff to previous 2.30 --- Multiply by 1000003 instead of 3 in string hach --- I'm quite sure it gives a more uniform distribution, but 1000003 has 6 or 7 bits set, which means it will probably compile to a real multiplication on most architectures. Second thing: ---File: [Development] / python / python / dist / src / Lib / smtpd.py (download) (as text) Revision 1.7 , Mon Aug 13 21:18:01 2001 UTC (2 days, 2 hours ago) by bwarsaw Branch: MAIN CVS Tags: HEAD Changes since 1.6: +2 -1 lines found_terminator(): Add a debug print showing the data. --- (somewhere down below, inside smtp_RCPT...) ... if address.lower().startswith('stimpy'): self.push('503 You suck %s' % address) return ... --- Who's the aforementioned stimpy figure? (No, I don't watch TV if it's related - you'll have to give me all the details). OriB. (please cc:me on your reply - I suspect my news server is not that good). From ylee12 at uiuc.edu Fri Aug 17 18:44:42 2001 From: ylee12 at uiuc.edu (Young-Jin Lee) Date: Fri, 17 Aug 2001 15:44:42 -0700 Subject: [Q] Python and Path Message-ID: Hi, I have a question on Python and path. How can I tell Python to search a python source file in a specify directory? I created a python test code in my working directory and I lauchched the Python interpreter from the desktop shortcut. I need to be able to specify the path (similar to Java's classpath), but I don't know how. Thanks in advance. YL From SBrunning at trisystems.co.uk Tue Aug 21 04:04:09 2001 From: SBrunning at trisystems.co.uk (Simon Brunning) Date: Tue, 21 Aug 2001 09:04:09 +0100 Subject: Python NEWBIE! Message-ID: <31575A892FF6D1118F5800600846864D78BFEA@intrepid> > From: Dev Null [SMTP:dev__nu11 at hotmail.com] > Anyone know of good resources (on or offline) for one such as myself? No need to shout! If you haven't programmed before, check out Alan Gauld's 'Learning to Program' at , or 'How to think like a Computer Scientist', at . These are aimed at teaching programming using Python to complete beginners. If you have programmed before, try 'Dive into Python at or the Python Tutorial at . Links to *loads* of tutorials can be found at . And don't forget the Python tutor mailing list, at . Well worth joining if you are learning Python! Cheers, Simon Brunning TriSystems Ltd. sbrunning at trisystems.co.uk ----------------------------------------------------------------------- The information in this email is confidential and may be legally privileged. It is intended solely for the addressee. Access to this email by anyone else is unauthorised. If you are not the intended recipient, any disclosure, copying, distribution, or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful. TriSystems Ltd. cannot accept liability for statements made which are clearly the senders own. From cjc26 at nospam.cornell.edu Sun Aug 26 13:51:54 2001 From: cjc26 at nospam.cornell.edu (Cliff Crawford) Date: Sun, 26 Aug 2001 17:51:54 GMT Subject: Whats wrong with this code? References: <3B88403B.9BF2CADE@telocity.com> Message-ID: <_Gai7.356549$EF2.45476331@typhoon.nyroc.rr.com> * Adonis Vargas menulis: | it will connect; and send the data; but i am not receiving anything? it | did work prior to me tinkering with it; but it is now back to how it | was; and no cigar? | | [snip] | pirc.send('NICK %s\r'%pirc_nick) | pirc.send('USER %s %s %s :%s\r'%(pirc_user, socket.gethostname(), | pirc_serv, pirc_name)) You're connecting to an IRC server, right? I think the lines need to be terminated with \r\n, not just \r. Try changing the above two lines to: pirc.send('NICK %s\r\n' % pirc_nick) pirc.send('USER %s %s %s :%s\r\n' % (pirc_user, socket.gethostname(), pirc_serv, pirc_name)) -- Cliff Crawford :: http://www.sowrong.org/ "Sheila can keep the balloons away." -- Thomas From kseehof at neuralintegrator.com Wed Aug 1 01:30:21 2001 From: kseehof at neuralintegrator.com (Ken Seehof) Date: Tue, 31 Jul 2001 22:30:21 -0700 Subject: Generator Comprehensions? was Re: a break for comprehensions References: <3B66FFEC.5335E1C8@destiny.com> <3B670BB3.48D4A5A5@ActiveState.com> <010f01c11a13$3a930920$6501a8c0@pacbell.net> <200108010326.XAA18273@cj20424-a.reston1.va.home.com> Message-ID: <002c01c11a4b$1ab01020$6501a8c0@pacbell.net> From: "Guido van Rossum" > > > How about if we combine your ideas: > > > > > > y = [yield x*2 for x in g()] > > > > Geeze, that's like, way obvious. Why didn't I say that in the first place? > > Good stuff is always way obvious. Nice one Paul :-) > > > > What do you think Guido? => CVS? > > I don't think so. Generators are most useful when they do more than > iterate over a pre-existing sequence, so I doubt that this would be a > common pattern. Also I'm not sure I like overloading of the [...] > brackets, which (to me) very strongly say "real concrete list here". > > --Guido van Rossum (home page: http://www.python.org/~guido/) I'm assuming that this would be used mostly when g() is a generator, but the sequence being iterated could be any lazy or non-lazy sequence. In practice, this puts a filter on an existing lazy sequence. Unfortunately the filter is limited to a one-to-one mapping of the input sequence, but that's true of list comprehensions too isn't it? I think the yield keyword clearly (to me) disambiguates the expression. Well, come to think of it, I can't think of a really good use for generator comprehensions anyway, but you have to admit the idea is cute. :-) - Ken Seehof http://www.neuralintegrator.com/kseehof From gregj at pdxperts.com Fri Aug 10 07:16:19 2001 From: gregj at pdxperts.com (Greg Jorgensen) Date: Fri, 10 Aug 2001 11:16:19 GMT Subject: Idiom for consecutive loops? References: Message-ID: <7oPc7.30$vW2.21083@news1.sttln1.wa.home.com> "Harald Kirsch" wrote: >>> When programming in C I find myself writing consecutive loops like for(i=0; i Hello, If I run this code: l = []; print l[1], I get a traceback. If I change it to: import sys l = [] try: print l[1] except: print sys.exc_info() I get a tuple, 3rd element of which is the traceback object. How do i print it? I tried doing print sys.exc_info()[2]() but that doesn't work. I also read libref and langref and i couldn't find anything enlightening on this. I found a post where paul prescott asks a similar question and gvr tells him that you basically have to read code for some debugger, or something of this sort.. that's over my head, i'm afraid. The reason i ask is that my program (cymbaline) doesn't print out exceptions that it raises. I have no idea why.. I don't have any big chunks in try: except: catch-all blocks.. So, alternatively, if i knew what else could be causing this, i wouldn't need the answer the my first question. I just need the answer to either one :P Thanks, - Andrei -- Cymbaline: intelligent learning mp3 player - python, linux, console. get it at: http://silmarill.org/cymbaline From ignacio at openservices.net Fri Aug 31 01:04:31 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Fri, 31 Aug 2001 01:04:31 -0400 (EDT) Subject: Usage of wave module Message-ID: Does anyone have any sample code that uses a wave.Wave_read object to play .wav files under Linux and/or Win32? It would be much appreciated. TIA -- Ignacio Vazquez-Abrams From sntial at pacbell.net Sat Aug 4 16:18:37 2001 From: sntial at pacbell.net (Jeanne) Date: Sat, 04 Aug 2001 20:18:37 GMT Subject: XOR two bytes? Message-ID: <3B6C5985.EA285A07@pacbell.net> Does anyone know if there is a function to quickly Xor two bytes together? I have been searching in the docs, but havent' been able to find it. Please cc: my cris_paltenghe at yahoo.com address as I don't hang out in this newsgroup often. Thanks for your help! Cris From skip at pobox.com Sun Aug 5 12:36:38 2001 From: skip at pobox.com (Skip Montanaro) Date: Sun, 5 Aug 2001 11:36:38 -0500 Subject: Syntax Errors on make install In-Reply-To: References: Message-ID: <15213.30230.168434.717296@beluga.mojam.com> midnight> I downloaded the version 2.1.1 tarball. Configure, make and midnight> test seemed to run smoothly, but make install gave some syntax midnight> errors which scrolled off the screen before I could read them midnight> properly. The interpreter works fine, as far as I can tell. midnight> Should I be concerned about those syntax errors? My system is midnight> Debian woody, kernel 2.2.18, libc6 2.1.3-18, gcc 2.95.2-13. No, they are test cases that are supposed to contain SyntaxErrors. When Python is installed, the Lib/test directory is also installed. midnight> Incidentally, something on my system unzipped the tarball midnight> without my knowledge, but left the filename unchanged midnight> (Python-2.1.1.tgz). I downloaded the tarball in Mozilla midnight> (M18-3) using HTTP, so I suppose Mozilla is the obvious midnight> suspect. Any ideas? Mozilla. Netscape has had this problem at one time or another as well. -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From lkvam at venix.com Thu Aug 30 11:44:38 2001 From: lkvam at venix.com (Lloyd Kvam) Date: Thu, 30 Aug 2001 11:44:38 -0400 Subject: Is Python powerful enough for this? References: <3B8E4794.9988.1181E6F@localhost> Message-ID: <3B8E5F66.8C785DB1@venix.com> Python is a terrific CGI scripting language. Make sure your web server is properly configured for running Python. A good starting point for how to do Python CGI scripts is: http://www.python.org/doc/essays/ppt/sd99east/ A wrote: > > Hi, > I have some webpages that contain FORMS. Each form has input > fields and also some hidden fields. > How can I easily get urlencoded string from all these fields > like > Key1=Value1&Key2=Value2&Key3=Value3 > > For example: > I have a following web page > > > > > >
>

>

>

>

type="reset" value="Reset" name="B2">

>
> > > > >From the above > I would like to receive > T1=&S1=&C1=&B1=Submit > > Thank you for help. > Ladislav > _______________________________________________ > ActivePython mailing list > ActivePython at listserv.ActiveState.com > http://listserv.ActiveState.com/mailman/listinfo/activepython -- Lloyd Kvam Venix Corp. 1 Court Street, Suite 378 Lebanon, NH 03766-1358 voice: 603-443-6155 fax: 801-459-9582 From gerson.kurz at t-online.de Wed Aug 15 04:40:08 2001 From: gerson.kurz at t-online.de (Gerson Kurz) Date: Wed, 15 Aug 2001 08:40:08 GMT Subject: "Interpreter not initialized (version mismatch?)" References: Message-ID: <3b7a34dc.3927984@news.t-online.de> On 14 Aug 2001 02:34:45 -0700, jlcolom at hotmail.com (Josep L. Colom) wrote: >Hello, > >Under Windows 2000, I've written a extension module in C++ (Visual C++ >6.0) and I've used the last stable SWIG version (1.3.6, from july >2001). >I'm using python 2.1.1. > >Then, when I try to import the DLL (extension module) I get the error: > "Interpreter not initialized (version mismatch?)" Assuming you did call Py_Initialize(), this error can come if you try to call a python method from a different (NT native) thread. For example, you have a python method that gets a callback, and you want to issue it later from a different thread -> you'll have to initialize the interpreter for that thread first. Getting threads to work with the python runtime seems one of the least documented areas in C/Python :( From erno-news at erno.iki.fi Wed Aug 1 01:30:55 2001 From: erno-news at erno.iki.fi (Erno Kuusela) Date: 01 Aug 2001 08:30:55 +0300 Subject: sleep command/function & searching the python docs References: <9k6ilm$2sed8$1@ID-91520.news.dfncis.de> Message-ID: In article <9k6ilm$2sed8$1 at ID-91520.news.dfncis.de>, Rajarshi Guha writes: | Hi, | is there a sleep function in the Python library. I've beens earching | throught the modules but could'nt seem to find one. BTW, is there any way | to search the Python docs for a specific function/module etc? Or is there | any resource on the web that provides a searchable interface? the library reference index is good for finding things. -- erno From loewis at informatik.hu-berlin.de Sat Aug 11 06:06:14 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 11 Aug 2001 12:06:14 +0200 Subject: Compiling Python 2.1.1 without 16-bit integer type References: Message-ID: "Tim Peters" writes: > Try current CVS. It so happens I removed the last "exactly 2 bytes wide" > assumption from the Unicode implementation last night. It hasn't been > *tested* on a box without a 2-byte integral type, though. On top of the current CVS, there is also a pending patch to disable Unicode types completely. Of course, if you are not using Unicode, you are probably happy if it compiles at all - then current CVS will should work for you; just make sure to pass --enable-unicode=ucs4. Regards, Martin From aleax at aleax.it Wed Aug 29 10:32:06 2001 From: aleax at aleax.it (Alex Martelli) Date: Wed, 29 Aug 2001 16:32:06 +0200 Subject: Hello people. I have some questions References: <3B8C9863.A489278F@el_simpatico.be> Message-ID: <9miud701gsp@enews1.newsguy.com> "jeroen paul goudsmit" wrote in message news:XO2j7.19$Cz3.314 at pollux.casema.net... > > I can read, write, speak , hear, understand english. I'm dutch, so dutch > still is easier for me. That's why I asked for dutch books. Funny enough, while Python's inventor and architect is Dutch, and so are some of the major figures in the Python community, e.g. Boudewijn Rempt (see http://stage.linuxports.com/pyqt/book1.htm), I don't know of any Python resource in Dutch -- Bulgarian, Chinese, Czechoslovakian, Esperanto, French, German, Hungarian, Italian, Japanese, Korean, Norwegian, Portuguese, Russian, Spanish and Swedish, yes, but not Dutch. Maybe that's the downside of you guys being so good at English -- none of you has bothered setting up Dutch-language mailing lists, sites, book translations and so on...? > so if i got it right, python is easier then vb. Only one thing is not easy. Nope, I would say a tiny bit more than one. Most have good and bad aspects, but they can be seen as "not easy". It IS a handful of things out of the thousands details of each language, though. > You can't just put a control on a form. But there are special thingies in > python who can. Yes, depending on the GUI toolkit you choose. "not easy" thing number one is that there are so *MANY* Python extensions for such tools as GUI's and web work that choosing between them is hard! Of course, this also has good sides -- nice to have choice. Other "not easy" thing are: -- in Python, case is significant: words such as "english" (adjective) and "English" (noun) are distinct even though they only differ in case (upper/lower). Visual Basic is more forgiving in this. Good side, well, this is hotly debated in the Python community, and some of us are convinced that case-sensitivity was a design error (it's not gonna change -- backwards compatibility is generally maintained in Python!), but most Pythonistas love it (I guess they have Unix backgrounds -- so do I but I still prefer case-insensitivity!-), so I guess it must have some. -- in Python, division TRUNCATES when it's between integers: print 1/2 emits 0, NOT 0.5 as most people expect. In Visual Basic, the result of 1/2 is indeed 0.5. In Python you have to use a . somewhere to indicate a non-integer number, e.g. 1./2 or 1/2. or 1./2. (or just write 0.5), or explicitly ask to float one or both numbers one way or another. Another hotly-contentious item in the Python community. -- in Visual Basic (non-strict mode) you can just use a variable you've never mentioned before and it will just spring into life with a default value (it's never very clear if that default value is an empty string or the number 0, or something different yet, and this often does confuse things, of course). In Python a variable appears when it's *assigned* to -- you can't use a variable that has never been assigned, Python will detect an error if you try to do that. This DOES in the mid-long term make things easier (no wondering about what kind of default value has sprung up from nowhere!) but beginners sometimes have a slightly hard time coming to terms with the idea that any name must have been created before you use it. > And i've got one more question. What's the limit of python. What can you not > make in it. Vb stops somewere, c++ stops later. Weere stops python? VB (and Python) stop where there's no runtime environment to support them (C++, like C, is designed to be able to do without a support environment -- it does need a *compiler* to prepare the program for execution, but once compiled and prepared the program can run on the environments it was prepared for, which may be "such and such machine without any other software AT ALL", e.g. "embedded" applications). Say you'd like a little program of yours to run in the browser of anybody who looks at your site. VB will stop at any browser that lacks VB runtime support (Internet Explorer, recent versions, has it, albeit, reasonably, limited to the VBScript subset; Netscape and Opera do not; etc, etc). Python will stop at any browser that lacks Python runtime support (and, apart from the old Grail browser that was written entirely in Python, I know of no browser that *COMES WITH* Python runtime support -- you could easily ADD such support to Internet Explorer, or Mozilla 6, since they're highly-modular browsers, but you probably cannot count on the visitors to your webpage having done so!). I see other posters have mentioned and are debating "OS modules". It's again just a question of runtime support -- no more, no less: if an OS had runtime support for VB, or for Python, you could use VB, or Python, to write modules for that OS, period. There's no "conceptual" block -- just that, in practice, I know of no such OS (for either language). Apart from the "deployment" issue of "is there runtime support", both languages are capable of any task whatsoever -- so called "Turing-complete" (within the hardware limits of the systems they're using). One will be much more PRODUCTIVE than the other for certain tasks, but that's a different issue from "stopping". Alex From aahz at panix.com Thu Aug 9 12:38:33 2001 From: aahz at panix.com (Aahz Maruch) Date: 9 Aug 2001 09:38:33 -0700 Subject: encapsulation? References: <3B704ED1.EFA6AEA8@demog.berkeley.edu> Message-ID: <9kuea9$nkv$1@panix2.panix.com> In article <3B704ED1.EFA6AEA8 at demog.berkeley.edu>, Lloyd Goldwasser wrote: > >As a recent convert to Python (I have C, Objective-C, and Scheme, among >others, in my past), I'm curious about its lack of encapsulation. 'Way >back when I was using Objective-C -- and many other OO languages seem to >have a similar perspective -- there was a lot of emphasis on the ability >to keep the contents of objects independent of outside influence except >via well-delineated mechanisms. Security and reliability were cited as >major benefits of this approach: every object knew exactly what the >outside world was going to see and exactly how the outside world might >act to change its state. Python provides only the private variable >name-mangling mechanism for "encapsulating" the contents of objects, and >it's weak enough that dir(ClassName) announces all of those "hidden" >contents to the world, at which point they can be altered at will. I >wonder whether this approach, making encapsulation a matter of >convention rather than something that's provided by the language, is a >liability. It would seem to make Python ineligible for use in projects >that need a more reliable separation between objects and outside >access. How hard (or desirable) would it be to provide a stronger kind >of encapsulation in Python? Side note: the canonical way in Python of indicating "private" is to use a single leading underscore. Use name-mangling only when you must. -- --- Aahz <*> (Copyright 2001 by aahz at pobox.com) Hugs and backrubs -- I break Rule 6 http://www.rahul.net/aahz/ Androgynous poly kinky vanilla queer het Pythonista "i-write-best-when-the-audience-is-me-ly y'rs - tim" From ignacio at openservices.net Sat Aug 25 17:49:29 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Sat, 25 Aug 2001 17:49:29 -0400 (EDT) Subject: PyGTK - 1.5.2 not 2.1 In-Reply-To: Message-ID: On Sat, 25 Aug 2001, Adam 'Vonlia' Seyfarth wrote: > Hi python people - > I was trying to find a gfx package for Python, and I tried it. > I have python aliased to /usr/local/bin/python2.1 and running python on > their examples said it couldn't find the module gtk. But after > unalias-ing it, they worked, and it is cool! I would rather use > Python2.1 if I can, but I don't use it's features, so I don't care much. > But, do other people use PyGTK with 2.1? Back in November 2000 a very similar question was asked on the PyGTK mailing list, except it was with Python 2.0. The answer was basically "recompile it with the newer version of Python". Try that and see if it works. OTOH, it may be that the PyGTK libraries only exist in your Python 1.5 site-packages directory. Check that, but I suggest the recompile. -- Ignacio Vazquez-Abrams From howard at eegsoftware.com Mon Aug 20 01:11:36 2001 From: howard at eegsoftware.com (Howard Lightstone) Date: Mon, 20 Aug 2001 05:11:36 GMT Subject: fun with floppy disks (Windows) Message-ID: <3B809C02.72CDEB0B@eegsoftware.com> I am trying to port across some C code to Python which (among many other things) needs to know when a user puts a floppy into the drive and closes the door. The old code used _DISK_VERIFY mode to check for a floppy since (I am led to believe from comments) it fails without the Abort/Retry junk if there is no floppy. Also, I guess I need to poll the status of the floppy. Since I am using Tkinter, what is the usual way to poll and still process events (ala mainloop, etc.)? From ignacio at openservices.net Sun Aug 26 12:59:09 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Sun, 26 Aug 2001 12:59:09 -0400 (EDT) Subject: Help: using msvcrt for file locking In-Reply-To: <7f6hot47j69t1lggtr86bhvc6i2l5q1kn2@4ax.com> Message-ID: On Sun, 26 Aug 2001, Sheila King wrote: > I am intending to use this for programs that will access databases. > Specifically, CGI scripts using the Berkeley data base hash. The > Berkeley Sleepy Cat that I have access to doesn't support concurrent > write access. I have to handle the file locking myself. I'm just curious as to why you're not using a database server for this. Any specific reason? -- Ignacio Vazquez-Abrams From teo at crepido.com Thu Aug 2 11:07:04 2001 From: teo at crepido.com (teo) Date: 2 Aug 2001 08:07:04 -0700 Subject: indent in xml References: Message-ID: try this one: doc.parse(s) # s is the xmlfile... thedoc = doc.documentElement books = thedoc.getElementsByTagName("book") # returns a list of all childs # with tagName == 'Book' :) for book in books: title_list = book.getElementsByTagName("title") print title_list[0].firstChild.data.strip() print book.firstChild.firstChild.data.strip() I think this is what you want to do.:) /teodor "sdf" wrote in message news:... > I want to get the first child node of one node,but because of the indent > problem(I think so),the first two child is not what i want ,but the '\n' > and '',the xml file is: > > book> > Pierre: The Ambiguities > Herman Melville > 9.99 > > > The Republic > Plato > 12.99 > > > The Republic > Plato > 15.99 > > > > and my py file is > > >>> from xml.dom.minidom import parse, parseString > >>> s="d:\\i.xml" > >>> doc=parse(s) > >>> doc.childNodeTypes > (1, 7, 8, 10) > >>> doc.nodeName > '#document' > >>> doc.childNodes > [] > >>> book=doc.firstChild > >>> book.childNodes > [, , , , , , , , , , , , , , , , , , , , , , , , , , , ] > ############### how can I delete the and > ## and what is the meaning of (1, 7, 8, 10)(the reslut of doc.childNodeTypes) > > > __________________________________________ > > DVD??????????10?? http://shopping.263.net/category02.htm > ?????????????????????? http://shopping.263.net/category10.htm From dmercer at zembu.com Tue Aug 14 17:50:38 2001 From: dmercer at zembu.com (Dan Mercer) Date: Tue, 14 Aug 2001 14:50:38 -0700 Subject: Wild-eyed thinking aloud: Python System Management Infrastructure Message-ID: <20010814145038.A6540@mailhub.z.zembu.com> Greetings, Over the past year, my coworkers and I have developed a systems management suite that is similar in many respects to what has been discussed in this thread, and I've found the discourse here to be quite valuable and interesting. We originally developed our tools to support the deployment of Zembu's distributed application infrastructure, but recently the decision has been made to productize this software, making it available to the public. Our Infrastructure Manager is composed of a number of components, including a serial terminal server and physical power control (when the appropriate hardware is available), a densely-meshed VPN based on the KAME projects IPSec implementation using a Kerberos KDC for key management, and other features, but the functionality that most applies to this discussion is a configuration management system written in Python. The core of our system uses a simple XML-based declaration language to describe the properties of and relationships between components that comprise the managed infrastructure. W3 XSL documents are applied to this data to generate a variety of configuration files and specialized scripts that determine how the manager configures it's managed hosts. This mechanism is used to setup the management system to bootstrap new Solaris and Linux systems in an automated manner, and to generate the appropriate configuration files and package/patch adds needed to make the new system match a described profile. The idea is to provide a configuration revision control system that allows admins to rapidly duplicate a profile onto dozens of hosts. A portable, lightweight management library is installed on each managed host that allows communication with the manager via SSL encrypted XmlRpc. The management library can be 'taught' new methods as packages are installed for instance, the install of an apache package would add methods for starting, stopping and getting the status of the apache server. This code is also written in Python, which is really wonderful for cross-platform systems work. Currently, a UNIX style command line interface is available, along with a specialized 'shell' environment that restricts access of users to specific subsets of the IM's functionality. Currently a web based user interface is also under development, which will allow for the same functionality available on the commandline, including the editing/adding/removing of components to be configured without editing a single line of XML. Since our marketing department is just now beginning to put together the positioning for this software, it'd be very useful to us to hear your opinions on what functionality you think would be useful, or what systems you think we should support most quickly. If you are interested in trying out some of this software pre-release, and could answer some questions about your own infrastructure, it would be of great benefit to us. We'd like to provide a user-extensible, 'no snake oil' management solution that solves the problems of sysadmins and doesn't require a complete overhaul of your environment and thousands of dollars to implement. If you'd like to provide input please respond to this message, or send mail to karin at zembu.com. We will be releasing initial support for Solaris 7/8 and Redhat 6.2. We've really only tested sun4u systems, but I expect old sun4m/c stuff should work as well. For intel systems the only requirement for managed hosts is Intel (PXE) compliant network interfaces. The release date is currently 10/1/2001. Dan Mercer Systems Engineering - Zembu Labs http://www.zembu.com/ From rnd at onego.ru Fri Aug 3 02:12:08 2001 From: rnd at onego.ru (Roman Suzi) Date: Fri, 3 Aug 2001 10:12:08 +0400 (MSD) Subject: Is it new style or just lack of style? Message-ID: Hello! More and more I am starting to see people adding extra blanks in ( ). Recent example (from Steven's post): ''' def Files( start ): for file in listdir( start ): file = path.join( start, file ) if path.isfile( file ): yield file elif path.isdir(file): for more in Files( file ): yield more ''' Is it new style? I am sure this contradicts Python Style Guide, but where from this new style appeared? I saw Java programs with the same ugly padding... And what about: ''' class E : pass ''' It is not right style too... Any ideas? Sincerely yours, Roman Suzi -- _/ Russia _/ Karelia _/ Petrozavodsk _/ rnd at onego.ru _/ _/ Friday, August 03, 2001 _/ Powered by Linux RedHat 6.2 _/ _/ "MACINTOSH - Most Apps Crash, If Not, Then Operating System Hangs" _/ From watchtheclosingdoors at yahoo.com Wed Aug 22 16:58:34 2001 From: watchtheclosingdoors at yahoo.com (atonal) Date: 22 Aug 2001 13:58:34 -0700 Subject: newbie question Message-ID: <48256545.0108221258.5882c94f@posting.google.com> i have beginning-to-intermediate level vb6/vba programming skills and would like to find employment before long in a technical capacity. something tells me that vb is not my ticket, and i am intrigued by python. for now i am somewhat wedded to ms windows and ms office, but i gather that python can be used in many ways in place of vba, and that in general it would offer more career opportunities. anyone agree or disagree? advice is welcome, and thanks in advance. From mmhamze at pleiades.net Tue Aug 21 16:30:17 2001 From: mmhamze at pleiades.net (Maan M. Hamze) Date: Tue, 21 Aug 2001 15:30:17 -0500 Subject: Inconsistency in CGI Documentation???? References: Message-ID: "Roman Suzi" wrote in message news:mailman.998412271.8345.python-list at python.org... > On Tue, 21 Aug 2001, Maan M. Hamze wrote: > > >Question: How do you provide this argument? > >Test_Form=cgi.FieldStorage(keep_blank_values)?? This is not working. > > OK. Trying this: > > >>> import os > >>> os.environ['QUERY_STRING']="aaa=1&b=&c=12" > >>> Test_Form = cgi.FieldStorage() > >>> Test_Form.keys() > ['aaa', 'c'] > >>> Test_Form = cgi.FieldStorage(keep_blank_values=1) Ok. I see. I tried the example. Thanks for this information. I see how this works now. > >>> Test_Form.keys() > ['aaa', 'b', 'c'] > > I can't see any inconsitencies... > nb. the way keep_blank_values are given (it's a named argument). > > >Ok! I am not going to provide this argument. So, the Text Input element > >that I left empty and had not provided a vlaue for should NOT make it into > >FieldStorage() if user does not type some characters in it. Right? I tried > >it. It does not make it. > >Even if I provide a value of " " (is " " an empty string??) > > > >2. BUT, read on: > >check http://www.python.org/doc/essays/ppt/sd99east/sld041.htm Slide # 40 > >
> >Your first name: > > > > > > > > You can > Ignacio provided an answer to the seemingly contradictory issue. I'll just have to figure out why I am not getting the value with a white space in the list of keys. Thanks, Maan From maxm at normik.dk Tue Aug 21 10:07:23 2001 From: maxm at normik.dk (=?iso-8859-1?Q?Max_M=F8ller_Rasmussen?=) Date: Tue, 21 Aug 2001 16:07:23 +0200 Subject: Needs advise for good structure for discussion class (Long) Message-ID: <7BD10B680501D411B9DF009027E06F32197DF9@exchange> Although this message is about Zope it is mainly about Python, so I send it here instead of on the Zope list. I belive that the general problem is interresting enough to get discussed in c.l.py, so here goes. I am trying to build the "ultimate threaded discussion module" for Zope. I belive that the monolithic frameworks that exists today are _evil_ :-) and that what is needed is more flexible modules. My main design criteria is: 1) It must easy to "skin". By this I mean that it should be simple to write new dtml that gives it a new functionality and look. 2) It should be as flexible as possible. 3) it should be easy to write/change dtml script for a beginner. In python a simple code snippet for listing the messages would be:: for msg in sortedMessages: print msg.indentLevel*' ' + msg.content In dtml it would be::
'sortedMessages' is a method that takes two optional arguments. 'threadOrder' and 'messageOrder'. Either can be 'forward' or 'reverse'. getSortedMessages(self, threadOrder='reverse', messageOrder='forward') This is to support all the ways a discussion can list the messages according to user preferences. Typically:: Thread 1 Re: Thread 1 Re: Re: Thread 1 Thread 2 Re: Thread 2 Re: Thread 2 (Messages that has no parents are threads, messages that has parents are just messages.) So the idea is to get the class to return a sorted list of message objects. Each message has it's 'indentLevel' property assigned dynamically in accordance to how the messages are sorted. This makes it very simple to script it in dtml and Python. No ugly and evil recursion ;-) Naturally this will cause me problems because Python use referenced objects, s? if two users are trying to get the list with different sorts, all hell is loose. I haven't figured out just yet how to solve this. Probably the 'indentLevel' should not be a property of the message class. The short of the long is that I have written the below class to play around with different solutions. And I have realised that I really am in need for some ideas as to how I should structure the program. Some qustions I have: - Will it be easier/faster to sort the messages by iteration or recursion? - Should the message class have a 'child' parameter too, so it would be easier to sort it in a recursive manner. - Should I just put the parent and child objects into the messages? - Should I sort the list in the 4 possible combinations on insert insted of what I do now? - Does anybody has any ideas as to the smartes way to structure this idea? - Is this to stupid to ask in the newsgroup? ANY ideas, comments and solutions will be welcome. Sometimes the fluidity of Python makes solutions much simpler than other approaches that are inspired by other tools and languages. They can just be hard to discover sometimes. What I really hope for is some "Blinding flash of the obvious". But anything else will be appreciated. Meanwhile I will continue to work on the problem myself. regards Max M ############################################### class message: def __init__(self, id, content, parent): self.id = id self.content = content self.parent = parent self.indentLevel = 0 class messages: def __init__(self): self.mesgDict = {} def addMsg(self, id, content='No content', parent=0): self.mesgDict[id] = message(id, content, parent) def getSortedMessages(self, threadOrder='reverse', messageOrder='forward'): # find the threads (parent messages) threads = [msg for msg in self.mesgDict.values() if msg.parent==0] threads.sort() # so far i only returns the first message in all threads return threads if __name__ == '__main__': """ Thread 1 Re: Thread 1 Re: Re: Thread 1 Thread 2 Re: Thread 2 Re: Thread 2 """ diskus = messages() diskus.addMsg(0, 'Thread 1') diskus.addMsg(1, 'Thread 2') diskus.addMsg(2, 'Re: Thread 1', 1) diskus.addMsg(3, 'Re: Thread 2', 1) diskus.addMsg(4, 'Re: Thread 2', 1) diskus.addMsg(4, 'Re: Re: Thread 1', 2) sortedMessages = diskus.getSortedMessages() for msg in sortedMessages: print msg.indentLevel*' ' + msg.content - N?rg?rd Mikkelsen a/s - www.normik.dk - Vandv?rksvej 18 - DK 5000 Odense C Tlf (+45) 66 14 14 80 - Fax (+45) 66 14 19 43 Max M - Direkte (+45) 63 14 47 15 From karthikg at aztec.soft.net Sat Aug 18 05:15:51 2001 From: karthikg at aztec.soft.net (Karthik Gurumurthy) Date: Sat, 18 Aug 2001 14:45:51 +0530 Subject: can i safely assume that __del__ will always be called Message-ID: Unlike Java where am not really sure when finalize will be called, can i be sure that __del__ of my resource w'd be called when someone does a del(ref) as long as ref in the only refernce to the Resource object. def useResouuce(): res = DBResource() #use DBresource del(res) Even if someone does'nt do a del, __del__ w'd be immdiately called when the scope of function useResource completes?? If that is the case i need not rely on the client to do clean-up of the source explicitly?. thanks, karthik. From paulp at ActiveState.com Mon Aug 27 22:53:44 2001 From: paulp at ActiveState.com (Paul Prescod) Date: Mon, 27 Aug 2001 19:53:44 -0700 Subject: XML-RPC/SOAP vs. plain-old URLs References: <09Ai7.3369$1T5.45479@news1.oke.nextra.no> Message-ID: <3B8B07B8.9506EDCD@ActiveState.com> Thomas Weholt wrote: > > Just read > http://www.byte.com/documents/s=1113/byt20010816s0002/0820_udell.html and it > got me thinking. I'm in the middle of a project using alot of XML-RPC for > communication between servers. The article clearly shows that there's a > significant overhead using XML-RPC ( guess much of the same would apply to > SOAP implementations too ). I don't think that the point of the article was that there is overhead. I think that the point is that most arguments to functions are simple and return values are often much more complex. >... > Could somebody point out limitations when using URLs instead of XML-RPC ? > Datatypes? Data structures? Yes and yes. But maybe you con't care about those. They don't matter for many apps. > Will the overhead of XML-RPC/SOAP make them slower than plain URLs? I think you're comparing apples and oranges. When you get back data from the server it still must be structured somehow. The defacto and de jure standard for that is XML (whether or not you are using XML-RPC). >.... I'll probably keep on using > XML-RPC for some stuff, but I'll definitly look into creating a module for > writing/reading simple datastructures using a simpler standard than xml. I can't imagine a much simpler standard than XML-RPC data types...maybe less verbose but not simpler! But you can use XML-RPC data types without actually using XML-RPC to do the call. Other XML data typing standards include WDDX, SOAP, XMLPickle etc. Sure, standard Python pickle works if you know that your clients are always going to be only Python programs. But I think it would be safer to use something language neutral just in case. -- Take a recipe. Leave a recipe. Python Cookbook! http://www.ActiveState.com/pythoncookbook From mhoward at mahoward.com Wed Aug 15 12:29:20 2001 From: mhoward at mahoward.com (Michael A. Howard) Date: Wed, 15 Aug 2001 09:29:20 -0700 Subject: Need Help with COM References: Message-ID: <9le863$t2r$1@news.apple.com> Thanks, that resolved the problem. Mike "Stefan Schukat" wrote in message news:mailman.997854502.16411.python-list at python.org... > The object you are using is returing a parameter by reference. > Since this is not supportted in Python MarkH uses tuples to > return out values in COM calls. So in your case you should try > something like this: > > o.Application.ActiveMenuBar.Menus.Item(1)[0].Caption > > to access the first return value which is probably your > object. > > > Stefan Schukat > > > > "Mark_Pryor" wrote in message > > news:sVie7.10397$ZM2.950970 at newsread2.prod.itd.earthlink.net... > > Hi, > > Michael A. Howard wrote in message <9lc9t0$fo4$1 at news.apple.com>... > > >I'm coming to Python from VB and trying to understand how > > the COM stuff > > >works. > > > > > >I have a COM server (not written by me) that supports in VB the call > > >oAppPC.AppItem.Properties.Item(1).Caption > > >Which returns the caption of this item as I can see it from > > the object > > >browser in VB > > > > > >The same call in python returns: > > >Traceback (most recent call last): > > > File "", line 1, in ? > > >AttributeError: 'tuple' object has no attribute 'Caption' > > > > > >If I use Excel as an example i.e. > > >o.Application.ActiveMenuBar.Menus.Item(1).Caption > > >I get u'&File' > > >Which is also what I get in VB (well &File anyway) > > > > > >So what am I doing wrong? > > > > Thanks for the response but I get the same error message > > using that example. > > > > Unfortunately the COM object is a black box (no source) to me > > so I can't > > change it. > > > > Mike > > > > Either write the call like this (to handle the tuple): > > ( junk, mycap ) = oAppPC.AppItem.Properties.Item(1).Caption > > > > or redesign the Item method to pass the index by value! > > You might have to switch the vars above. > > > > hth, > > Mark Pryor > > pgp KeyID: 0x1A966EC5 > > > > > > > > > > > > > > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > From owen at astro.washington.edu Wed Aug 15 18:08:55 2001 From: owen at astro.washington.edu (Russell E. Owen) Date: Wed, 15 Aug 2001 15:08:55 -0700 Subject: problem calling functions with default arguments References: <9lee98$34p0$1@nntp6.u.washington.edu> <3B7AC3B9.D6FB66@wohnheim.fh-wedel.de> Message-ID: In article <3B7AC3B9.D6FB66 at wohnheim.fh-wedel.de>, Dietmar Lang wrote: >... >It has to do with the fact that we have just one list object here: The >one created when atest() was first executed. It seems that Python >doesn't create a new list every time, so it keeps growing with each >append. > >You can though, move the default value into the function body. For >example: > >def atest(alist = None): > if alist is None: > alist = [] > print 'alist =', alist > alist.append('test') > >Now it should work. Thanks to my O'Reilly book for pointing that one out >on me before I had to come face to face with it. :-) > >Kudos, Dietmar Thank you very much. I can certainly see it if the default argument was a named variable pointing to the desired default list (since Python doesn't have the equivalent of C's "const"), but I didn't expect it for a constant such as [] or {}. Anyway, your fix works and all is well. I did look in the FAQs before posting, but if it's there, I managed to miss it. Regards, -- Russell From m.1.robinson at herts.ac.uk Wed Aug 8 07:07:23 2001 From: m.1.robinson at herts.ac.uk (Mark Robinson) Date: Wed, 08 Aug 2001 12:07:23 +0100 Subject: How to iterate throuhg dictionary References: <9kqvaa$tbl$1@zeus.man.szczecin.pl> Message-ID: <3B711D6B.3030902@herts.ac.uk> Hi Piotr, you might try something like: for key in d.keys(): print 'key:' for value in d[key]: print value Piotr Legiecki wrote: > Hi > > I'v created dictionary named d={}. Its structure is like this: > > {key, [list]} > > I'd like to print all values stored in 'd'. What is the easiest way to do > it? > > Regards > Piotr Legiecki From gerhard.nospam at bigfoot.de Sun Aug 5 06:20:02 2001 From: gerhard.nospam at bigfoot.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Sun, 5 Aug 2001 12:20:02 +0200 Subject: wow! (generators) - suggestion (yield saved) References: Message-ID: On Sun, 5 Aug 2001 11:49:53 +0400 (MSD), Roman Suzi wrote: > >Hello! > >The following code is from CGI script and provides way to have >nice calendar: > >------------------------------------------------------------ >from __future__ import generators >import calendar, string >def calt(year, month): > month_cal = calendar.monthcalendar(year, month) > yield """%s.%s""" % (month, year) > yield """""" > for week in month_cal: > yield """\n""" > for day in week: > yield """""" % (day or " ") > yield """""" > yield """
%s
""" > >print string.join(calt(2001, 8), "") >-------------------------------------------------------- > Like in most of the cases I played with generators, you could have replaced them with a simple s = "" at the beginning, replace every yield with s += and a return s at the end. I think you can always do this if all you want is a list. >I like generators :-) I like them, too :-) >(Probably Python should use "black bullet" or "*" instead of "yield": I prefer "yield". Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://highqualdev.com public key at homepage public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y: x+y, [chr(ord(x)^42) for x in list('zS^BED\nX_FOY\x0b')]) From rupe at metro.yak.net Mon Aug 13 19:16:50 2001 From: rupe at metro.yak.net (Rupert Scammell) Date: 13 Aug 2001 16:16:50 -0700 Subject: Dictionary viewer and editor References: <79179cf5.0108101306.739764ee@posting.google.com> Message-ID: <79179cf5.0108131516.36284efd@posting.google.com> Guido van Rossum wrote in message news:... > rupe at metro.yak.net (Rupert Scammell) writes: > > > Are there any programs out there that can take in a dictionary object > > of arbitrary depth, and display it in a text or graphical tree format? > > Martin von Loewis writes: > > > I think Pythonwin's object browser can. > > IDLE's TreeWidget can too. It's used by Stack Viewer in the Debug > menu. > > --Guido van Rossum (home page: http://www.python.org/~guido/) Thanks for the pointer Guido. I'll give it a go. --- Rupert Rupert Scammell rupe at metro.yak.net http://metro.yak.net:8080 From cmiller at math.cudenver.edu Wed Aug 22 16:00:25 2001 From: cmiller at math.cudenver.edu (cary miller) Date: Wed, 22 Aug 2001 14:00:25 -0600 (MDT) Subject: When is a module imported from the standard library? Message-ID: How about this? import os mod = eval('os') mod.__file__ Ignacio Vazquez-Abrams wrote: > #! /usr/bin/python > > import os > import string > > print os.path.dirname(string.split(`os`, "'")[3]) > --- > > I tested it under 1.5.2. Does it also work under 2.x? It seems to (though I used `os`.split() instead of importing string)--I'm using 2.0 However, I would be worried about this being somewhat fragile, as it's depending on the specific format of a module's repr()--it seems to be constant across versions, but I'd hate to presume that it will stay so. Jeff Shannon Technician/Programmer Credit International -- Cary Miller Math Deparment University of Colorado - Denver cmiller at math.cudenver.edu http://www-math.cudenver.edu/~cmiller From fig at localhost.localdomain Fri Aug 10 11:31:13 2001 From: fig at localhost.localdomain (Stephen R. Figgins) Date: Fri, 10 Aug 2001 15:31:13 -0000 Subject: Python at sourceforge References: <3B73DD07.8576A76F@chello.nl> Message-ID: On Fri, 10 Aug 2001 12:57:36 GMT, Roeland Rengelink wrote: >Reactions? Cool. I just wrote an article on Python at Sourceforge. It should be on the Python DevCenter now. Can we see your script? -Stephen From peter at engcorp.com Thu Aug 23 03:21:05 2001 From: peter at engcorp.com (Peter Hansen) Date: Thu, 23 Aug 2001 03:21:05 -0400 Subject: newbie question References: <48256545.0108221258.5882c94f@posting.google.com> Message-ID: <3B84AEE1.7E0B5C68@engcorp.com> George Garnett wrote: > > I'm not a python programmer, ... > > Python has been re-written into jpython in which the language closely > parallels the java language. The main difference is java enforces strong > type casting (which is good), where jpython does not (its a gimmick to not > scare off non professional programmers who don't want to take the time to > verify every line of code is type casted correctly (this is the part where > I'll get beat up on) ). Darn tootin'! :-) If you weren't obviously trolling for some controversy on this one, I would have said your comments on this subject are just plain idiotic. Instead I'll just call your straight-faced delivery refreshingly droll. I'm not only a professional programmer, but I lead a team of sixteen professional *Python* programmers. Let me assure you that we do not consider the dynamic typing of Python (and here you are also quite wrong: as has been discussed recently and thoroughly here, Python is *strongly* but *dynamically* typed, while Java is *strongly* but *statically* typed) to be a gimmick, but in fact an extremely valuable feature for improving programmer productivity, the quality of the resulting code, and programmer morale (all related to each other of course). I also happen to know from reading this group for a while that this feature was never designed as a mere "gimmick". > numbered!). JPython is Python's attempt to hold onto all its python > developers and will provide them with a transition path to java (this is the > part where I'll get beat up on too) At least you know when you're going to get punished. :-) Actually, I don't think I'm even going to bother with this one, since it is so easily disproven. > Both java/JSP and python require knowledge of html/javascript/java/ > jsp/xml/web design. A very interesting statement, but again entirely false. I don't even know where you got this one. Just because many Python developers happen to use XML, or program for the web, or used to use Java, that's no reason to state that Python *requires* knowledge of any of those things. (I'll assume you just got tired of writing "Here I'll get beaten up again." ...) -- ---------------------- Peter Hansen, P.Eng. peter at engcorp.com From vcardon at siue.edu Mon Aug 13 23:30:36 2001 From: vcardon at siue.edu (Victor R. Cardona) Date: Mon, 13 Aug 2001 22:30:36 -0500 Subject: installation tkinter help In-Reply-To: <9l5q01$mc0$1@news.worldonline.be>; from ph.wuidart@wol.be on Sun, Aug 12, 2001 at 01:39:34PM +0200 References: <9l5q01$mc0$1@news.worldonline.be> Message-ID: <20010813223036.A18556@client156-52.ll.siue.edu> On Sun, Aug 12, 2001 at 01:39:34PM +0200, ph wuidart wrote: > I am new to python > I install python 2.1.1 to Linux Suse 7.0 (ok) and I have problem to install > tkinter > can you help me ! > Thank you I could send you my Modules/Setup file. It is setup for a SuSE 7.1 system, but I doubt there would be any major changes in the file. - v -- Victor R. Cardona 10:28pm up 4 days, 7:03, 2 users, load average: 0.00, 0.03, 0.00 Powered by SuSE Linux 7.1 (i386) 2.4.5-64GB-SMP From jeff at ccvcorp.com Wed Aug 29 14:10:56 2001 From: jeff at ccvcorp.com (Jeff Shannon) Date: Wed, 29 Aug 2001 11:10:56 -0700 Subject: strange behavior of the comparison operator References: <20010829171028.B8680@Nutella> Message-ID: <3B8D302F.55F421C6@ccvcorp.com> Nicolas Evrard wrote: > Hello everyone, this is my first post to the list and let me say that I > find python really exciting ... Looks a bit like scheme but is fast and > have a large community of users ... > > Here 's what I've done : > > To try the __comp__ method I've done a class for complex number (the usual > example). But here are the result I've got : > ... I think that the real problem here, is that you actually want to be defining __cmp__ (no 'o'). Your __comp__ method works just fine, but is not called when using less-than (<) (or any other comparison operator, of course). Jeff Shannon Technician/Programmer Credit International From steve at lurking.demon.co.uk Mon Aug 6 21:52:39 2001 From: steve at lurking.demon.co.uk (Stephen Horne) Date: Tue, 07 Aug 2001 02:52:39 +0100 Subject: Deposing Dictators References: <56fqmtcl20tg64aradbnarkj9kl514kg67@4ax.com> Message-ID: <459umtohbc1q062j2sgflcc0pmond739vv@4ax.com> On Sun, 5 Aug 2001 17:59:53 -0400, "Tim Peters" wrote: >> I believe PEP0238 is wrong in principle because... >> >> 1. The fact that mathematicians have had many views on integers >> and division, > >Factually incorrect; mathematicians have no disagreement over the meaning of >int/int (it's a rational). Python uses '/' as a division operator - not a way to denote rationals. Should the Python scanner ever recognise '1/2' as a rational literal rather than an expression containing a division operator, maybe you'll have some justification to that claim - the type of a rational literal clearly being rational, and thus clearly implying working in the domain of rationals rather than integers. Mathematicians *have* had *many* views on division, however, depending on the particular branch of mathematics. Yes, even at least two for integer division - allow a remainder, or disallow integer division altogether. Division has been applied in many numeric and symbolic domains, and each has its own set of assumptions. The remainder in polynomial division, for instance, has an algorithmic relationship to the remainder in integer division (the same long division algorithm is applied in both cases) - but if you know the numeric values of the numerator and denominator expressions and do numeric division with those the remainder will have no relationship with the previous polynomial division remainder - assuming the domain is reals, there will be no remainder from the numeric division. >> and the one that is in most non-specialist mindsets > >Hard to know what this means, but the idea that the majority of >non-specialists see "2/3" and think "0" is absurd on the face of it, if >that's what it means. The notation 2/3 in mathematics represents a rational number, and therefore is not even the same type as integer 0. However... In the domain of integers : 2 ? 3 = 0 remainder 2 In the domain of rationals : 2 ? 3 = 2/3 >> doesn't meet the pragmatic requirements for several fields of >> mathematics, is understood. That doesn't make the other >> definitions from less demanding, more down-to-earth fields >> invalid. > >PEP 238 retains an operator for flooring division (assuming that's what you >mean). I was referring to the way that some people claimed integer division was 'wrong' division and did not exist in mathematics - a claim made by some people because of specialist areas such as field theory, as if field theory was the whole of mathematics. IIRC, you did not go so far as to claim integer division is non-existent but you did claim that all integer division requires a floor or ceiling notation just because such notations are required in certain areas of mathematics, so you can hardly claim to be unaware of that issue - but then maybe I'm confusing Tims again. >> 2. It particularly does not invalidate the practical view which most >> people can easily understand, which is taught to everyone at >> a very early age and which also happens to work extremely well >> for typical programming tasks (not just specialist applications). > >PEP 238 doesn't dispute the utility of flooring division (assuming etc). I was refering again to the expressed views of certain PEP238 advocates that take particular specialist fields of mathematics to be the whole of mathematics. The word 'particularly' in English tends to imply that you are following on from the previous point. I am fully aware of what PEP238 says. >> Doesn't the pro-pep views insistence on the most pragmatic >> possible definition of discrete integer division seem more than a >> little inconsistent with their sloppy attitude to the much more >> fundamental difference between discrete and continuous >> mathematics? >> >> Just because it isn't the unnecessarily pragmatic (for normal >> programming tasks) field of mathematics that a few people >> subscribe to, it doesn't make it wrong. It is simply from a less >> specialised, more basic and more generally useful field that >> doesn't address the specialist problems of the minority over the >> general day-to-day practicality of the majority. > >If that were English, it would be easier to make a response . Read it again. The awkwardly precise wording was forced by some people willingness to force a wedge into the slightest imprecision in wording. The facts are quite simple, though. Some on the pro-PEP have tried to use field theory as a justification for the claim that integer division does not exist in mathematics, and should therefore be supported only through a distinct operator. Yet they are quite happy to lose the distinctions between numeric domains by discarding the metadata implicit in types, apparently simply to suit the needs of heavy users of floats and first-day programmers. >> 3. Practically all programs use discrete integer quantities - >> indices, subscripts, counters, sizes and more - whereas numerics >> is a particular specialist field. > >You've got some private definitions for these terms I was never able to >grok. Look them up in a kiddies math dictionary. The difference between working in a discrete domain and working in a continuous domain are well recognised. Loop indices, list subscripts, counters and sizes of lists, strings and other structures are all integers, and working with them implies working in a discrete domain - specifically the integer domain. >> Making life more awkward for the majority just to suit a few >> specialist fields is not rational. It's the specialists dealing >> with specialist fields who should have to deal with awkward >> special case syntax and semantics - not the everyday user. > >The idea that a majority of non-specialists believe 2/3 means 0 has not been >established, and IMO is almost certainly false. Of course, in maths the rational number 2/3 is not an integer at all, let alone zero. But the division operator, which is represented by '/' in Python, can be used in any numeric domain except those specialist domains (such as fields) that explicitly ban it. That includes the integer domain in which, using a common mathematical notation, '2 ? 3 = 0 remainder 2' - just as in the rational domain '2 ? 3 = 2/3'. >> 4. Discrete measures and continuous measures are not the same thing >> and should not be arbitrarily confused. > >PEP 238 suggests two distinct operators in order to reduce confusion(!). Great. Lets also have different operators for rationals when they are added, to further reduce confusion then. After all, float arithmetic has limited precision and we discard the remainder - different to what is done for both integers and rationals. Or alternately, we can carry on doing what we already do - carrying meta-data about the numeric domain in the type of the values and not bothering with an arbitrary range of special-case division operators. >> Discrete integer division makes perfect sense despite the fact >> that specialist fields have outlawed it for specialist reasons >> relating to specialist problems. > >Nobody has "outlawed" any meaning for division, "specialist" or otherwise. I didn't say a meaning of division was outlawed - I said that division itself was outlawed in certain specialist fields. An example is field theory, which outlaws division in all fields (except those based on modulo arithmetic with a prime base, IIRC) because division cannot be a perfect inverse of multiplication in such fields. That is the argument I was countering. >> This is much more fundamental than just switching between >> different representations of continuous measures. > >"This" doesn't appear to have a sensible referent. The prior paragraph was... """ 4. Discrete measures and continuous measures are not the same thing and should not be arbitrarily confused. Discrete integer division makes perfect sense despite the fact that specialist fields have outlawed it for specialist reasons relating to specialist problems. """ To give a simple example, the difference between working in the discrete integer domain and the continuous real domain is much more fundamental than whether you use a float, rational or fixed point representation to approximate values in the real domain. >> The pro-pep groups arbitrarily application of continuous measure >> division principles with a discrete integer type is wrong in >> mathematics, > >Factually incorrect. Oh - so, when working in the integer domain, it is perfectly valid to produce non-integer results then? >> and it is wrong in engineering, > >Whether it's velocity = distance/time, or voltage = watts/amps, engineers >rarely have "discrete" division in mind. So "wrong" is wrong here too. Your naming of a few examples of real measures does not disprove the existence of integer measures in engineering. Having half a support to hold up a bridge would be pretty pointless, wouldn't it? Or how about distributing the weight of an aircraft between its 2.7 wheels, 1.8 of them being under the 1.4 wings? Rather naff examples, but having worked in an engineering field for some years in the past I can assure you that integer measures/scales/the integer domain/whatever occurs quite frequently. >> and it is wrong in programming. > >The meaning of division a program needs depends entirely on context. Any >meaning is "wrong" in some programming contexts. I said *arbitrary* application of assumptions from a particular a particular numeric domain was wrong. >> My use of more practical day-to-day discrete principles for >> discrete integer arithmetic than would be appropriate in field >> theory - or even 16-year-old pure mathematics, I fully agree >> - is not the same thing at all. > >Couldn't parse that one. It refers back again to claims made by certain pro-PEP238 people that integer division does not exist, or always requires additional notations which are used in certain specialist mathematical fields, or whatever. >> 5. Having established that division on the discrete integer type >> should work in the only practical way that makes sense > >LOL! I hope that was *meant* to be tongue-in-cheek. The integer type is the only way we have to indicate we are working in the integer domain, as (despite your best attempts to twist my words) my message stated. But then, as you are so convinced that arithmetic in the integer domain should be allowed to produce non-integer results, I can see how you would find this statement laughable. Personally, I find your suggestion laughable - you are arbitrarily applying principles from the real domain to the integer domain where they don't apply again. >This is too time-consuming, Steve, and I think it's clear why you didn't get >support for the kinds of arguments above even from the anti-PEP camp. I absolutely agree - far too time-consuming. There are none so blind as those who will not see. It's not even as if I'm claiming that your view is invalid - only that the alterative view has equal validity, and that it is possible to counter any position in support of your viewpoint just as it is possible to counter any position in support of mine, as is the nature of any religious debate. I'm simply disappointed that no-one has come up with a sufficiently strong counter that it breaks the self-consistency of my view - arguments against my view have almost entirely relied on ignoring the meaning of my words, and that is very tiring. >Code breakage was and remains a strong anti-PEP argument. You once thought >it was supremely important to "do what other scripting languages do", but >since the JavaScript and VB examples backfired you don't mention that claim >anymore. I thought that was a marginal but plausible argument, and still >do. No other anti-PEP argument survived my personal credibility cutoff. I once thought it was important to consider what other programming languages (not just scripting languages) did based on sheer numbers. Note that's particularly not just scripting languages as a Python user is much more likely to be using C, VB, Java or Delphi along with Python - most are unlikely to be using loads of different scripting languages at the same time? I made the mistake of thinking Visual BASIC (the most used single programming language for some time) followed the pattern of C, C++ and Java. I was wrong, and the numbers of Visual BASIC and Delphi users certainly make the issue uncertain. So it's not that the issue is unimportant (though of course it is a relatively minor issue), just that it cannot provide a clear answer in the way I once thought it could. I explicitly admitted my mistake when that error was pointed out. Guido then raised the view that other languages would only be relevant if we knew the rationale for the change. At which point I noted that Java deliberately kept the division behaviour from C and C++ whereas Ada deliberately changed from the two-division-operators used in Pascal etc. That is, where a language has been created based on a deliberate attempt to take past languages and clean them up, the only two examples I'm aware of have shown a clear preference to division the same way that Python currently does it. And the rationales are available on the web if you care to look. At that point the result was silence, and it has continued to be silence when I re-raised it in response to another pro-PEP238 distortion similar to your "since the JavaScript and VB examples backfired you don't mention that claim anymore" claim from above, and in at least one other case where I reraised it quite recently. Similarly, when someone pointed out an error in a pro-PEP238 claim about Ruby, the result was again silence. How many people around here have explicitly admitted they are wrong when they are wrong? I have on several occasions. Care to name anyone else? The general pattern is that when I point out that working in the integer domain is different to working in the real domain, people accuse me of claiming that the rational 2/3 is equal to the integer 0. And when I contradict a claim that integer division does not exist, I get accused of claiming that PEP238 will not allow integer division. And so on. Even when they read the words, they certainly ignore the meaning. >if-you-still-feel-ignored-it's-not-because-you're-ignored-ly > y'rs - tim No? - you also seem to have done a pretty good job of reading the words and ignoring the meaning. From polopunk209 at hotmail.com Sat Aug 11 01:15:10 2001 From: polopunk209 at hotmail.com (Josh) Date: 10 Aug 2001 22:15:10 -0700 Subject: Installing .TGZ File I Got From Python.org.... Message-ID: I need help installing the .TGZ file that's distributed at Python.org. I have the base .EXE running, but I'm stumped for answers concerning what to do with this file. I have WinZip 8.0, and my OS is Win98 SE. (I would be running Mandrake, but my parents are attached to Windows. The teenage years really are traumatic...) Also, where do I unzip the Debug.zip file? Any help would be appreciated, and I wouldn't be asking this question if the UseNet search had turned up anything helpful, so I apologize for polluting the board with lame questions. -Josh P.S. If you didn't gather this from my first post on the board, I'm a newbie. From db3l at fitlinxx.com Thu Aug 2 19:34:31 2001 From: db3l at fitlinxx.com (David Bolen) Date: 02 Aug 2001 19:34:31 -0400 Subject: Map generation/plotting References: Message-ID: "Andrew Henshaw" writes: > May not fit with your OS of choice, but I've used Python to drive Microsoft > MapPoint through a COM interface. Pretty slick. Yeah, I was perusing that a bit last night - does it embed nicely within another application or will it always want to control it's own window? -- -- 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 urner at alumni.princeton.edu Tue Aug 14 17:08:48 2001 From: urner at alumni.princeton.edu (Kirby Urner) Date: Tue, 14 Aug 2001 14:08:48 -0700 Subject: Python CGI on WinMe/98/95 Message-ID: I had a sudden need to play with cgi and MySQLdb on a personal Windows (not a server jobber). I installed the Microsoft Personal Webserver first, and fought with it for awhile, then wiped it and went with Savant. Making a long story short, I'm running both Perl and Python scripts in a cgi-bin subdirectory. However, I wanted to mention what seemed to be a problem and MIGHT be a gotcha for others out there in Python world. In my File Associations for .py and .pyw files, the string I had under open | edit was something like d:/program files/python21.exe "%1" %1* That looks a little weird, and indeed, which I'd say OK, I'd get a warning about file not found. And yet when double-clicking on a py file Windows Explorer (a.k.a. the file manager), I'd get my python scripts to work (not using cgi mind you, just running regular old stuff outside the IDLE environment). When I finally went back to that file association string and made it more what Windows expects, i.e. "d:/program files/python21.exe" %1 %1 then Savant started working, and I bet PWS would have too. I'm thinking if this is a problem more generic than "just me", it's got to do with the Python installer trying to deal with users opting to install in a directory with a space in the path name. Probably most users just opt for c:\python21 or at words x:\python21 (some other drive). But this x:\program files\... business means trouble (maybe -- did for me). Kirby From tanzer at swing.co.at Fri Aug 24 11:26:13 2001 From: tanzer at swing.co.at (tanzer at swing.co.at) Date: Fri, 24 Aug 2001 17:26:13 +0200 Subject: When to use exceptions (was Re: reducing if statements...) In-Reply-To: Your message of "Thu, 23 Aug 2001 13:10:59 BST." <9m3kqi$hor$1@slb4.atl.mindspring.net> Message-ID: "Andrew Dalke" wrote: > Christian Tanzer: > > I'd strongly prefer a IOError exception hierarchy with one exception > > class for each different errno value to the current situation. You > > could still catch IOError, but you could also just catch the odd > > DeviceFull or PermissionDenied exception and leave all others to your > > caller. > > Paul Rubin: > >This makes sense to me. > > I believe though that it's complicated to implement while not > giving much additional power. > > How would it be implemented? There would need to be a mapping > from errno to class, and you want the classes to be named DeviceFull > or similarly readable names, rather than ENOSPC. So all C-level > code raising an exception would need to call this mapping and > construct the appropriate subclass. And if the errno doesn't > exists, fall back to use the IOError class it uses now. class NoSuchFail(IOError) : pass class PermissionDenied(IOError) : pass class NotADirectory(IOError) : pass IO_Exception_Map = { 2 : NoSuchFile , ... , 13 : PermissionDenied , ... , 20 : NotADirectory } The code raising an I/O exception just would use the C equivalent of raise IO_Exception_Map.get(errno, IOError), (errno, message) > That's doable, just more complicated, but the advantage is being > able to do > > try: > f(x) > except DeviceFull: > ... > except PermissionDenied: > ... > except TextBusy: > ... Looks much better to me than catching IOError and then analysing the errno. > Now suppose you're on a system which doesn't have a TextBusy > (errno == ETXTBSY, "if one tries to exec() a file that is currently > open for writing"). Since the errno doesn't exist, should the > TextBusy subclass exist? If it doesn't, then on some machines > there will be a NameError for TextBusy. > > So to catch those problems you'll need to have a generic > > def check(err): > return errno.errcode.get(err.errno) > > > except IOError, err: > if check(err) == "ETXTBSY": > ... I can't follow. The IO_Exception_Map could still map ETXTBSY to TextBusy -- that this exception isn't raised on a specific system shouldn't be a problem for anybody, should it? -- Christian Tanzer tanzer at swing.co.at Glasauergasse 32 Tel: +43 1 876 62 36 A-1130 Vienna, Austria Fax: +43 1 877 66 92 From phr-n2001 at nightsong.com Tue Aug 14 19:20:57 2001 From: phr-n2001 at nightsong.com (Paul Rubin) Date: 14 Aug 2001 16:20:57 -0700 Subject: Integer division and remainder Message-ID: <7x3d6ui5ye.fsf@ruckus.brouhaha.com> I've just started reading/playing with Python and I notice that integer division and remainder in python works differently than in most languages. In python, division always returns the floor, i.e. non-integer quotients are always rounded downwards, towards negative infinity: 7 / 3 = 2 -7 / 3 = -3 This is kind of strange. Normally you expect (-a)/b to be the same as -(a/b). That's what happens in most languages, where division rounds towards zero: 7 / 3 = 2 -7 / 3 = -2 I think the motivation was so that % would work as a "mod" function instead of the more normal "remainder" function. Python: -7 % 3 = 2 Most other languages: -7 % 3 = -1 The mod operation is useful for many things, but I think assigning it to % in Python shows some confusion in Python. The result of % is an ordinary integer, not an integer mod N. I think it would have been better to leave / and % alone, and define a new pair of operators (maybe /_ and %_) to implement what Python does. That's similar to Common Lisp, which provides the trunc-mod and floor-mod functions to implement remainder and modulus respectively. I don't remember if CL has a floor-div function, but it might as well. From guido at python.org Sat Aug 11 21:35:16 2001 From: guido at python.org (Guido van Rossum) Date: Sun, 12 Aug 2001 01:35:16 GMT Subject: Copy constructors References: Message-ID: Glyph Lefkowitz writes: > Am I correct in understanding from this thread that there is an intent to > remove the ability to assign an instance's __class__ attribute? Yes, I'd like to remove this. See my previous post in this thread for more of an explanation of the problem. But I haven't decided yet! This thread will help me figure out how big of a deal it will be. Also note that nothing will change (yet) for classic classes -- in 2.2, classic classes will use a different metaclass from "new-style" classes, and the classic metaclass will provide the same semantics for classes and instance as before. The class statement creates a classic class by default -- unless you explicitly subclass from a built-in type or a new-style class. In a sense, in 2.2 the new-style classes will still be experimental, and it's quite likely that based upon feedback from users they will change (for the better) in later versions. > > Let's just say that use of this feature is at your own risk. It was > > an experiment. I *could* restore it partially (see below) but I'd > > rather not, given that better alternatives are available. > > Are there any features that we can use any longer that are not 'at our own > risk'? Division will be changed, __class__ assignment is going away, > type() means something different, even the rules of scope... But you're getting so much in return! Subclassing built-in types, get/set methods, class and static methods, uniform introspection... > Also, as far as I know, better alternatives do not exist; for example, > "promise" objects from a database which are latently initialized when they > are accessed. If you know the type it's going to be eventually, you can use C.__new__() to create an uninitialized C instance. > One module that I use *all the time*; > twisted.python.rebuild.rebuild, is based entirely upon this "trick". I guess the name ("twisted") says it all. :-) > One > of the eye-popping cool features of Python is the ability to change code > and have existing instances update to use the new methods automatically. You will still be able to modify *classes* dynamically -- although you have to declare this option by putting __dynamic__ = 1 in your class statement. > Smalltalk's Object>>become: is highly useful for similiar reasons; is > there a new way to emulate this without __class__ assignment? Probably not -- although I don't know what that does. > > I'm sure I'd be able to come up with some kind of check that works. It > > would probably be very similar to the check I already use to determine > > whether two base classes are compatible -- the check that stops you > > from doing "class C(list, dictionary)". But I repeat: I'd rather not. > > Is there a discussion somewhere of why you'd rather not? This is > *essential* functionality for me, especially since it sounds like it won't > be able to be completely replicated through some other mechanism. I'd rather not because it's a complicated check to write, and it may be difficult to explain the restrictions. Here's an example of the kind of restriction that is unavoidable. I don't know how familiar you are with Python's C-level internals. If you are, you'll appreciate the problem if I took a list object and changed its type pointer to the dictionary type -- the instance lay-out of a dictionary is different, and all the methods would be using the list data as if it were dictionary data. Recipe for disaster. Likewise, changing a featureless object into a list or dict would at the very least require growing the size of the instance; this would require a realloc(), which may move the object in memory. But if there are other references to the object, these would all have to be updated. Python's run-time architecture just doesn't support that. > (If you implement "reference.become(other)", for example, I won't > mind nearly so much <0.5 wink>) I'm not sure what that means, but if you could live with weak references, we could easily add a way to change the referent of a weak reference object. > > That depends on how much of a slowdown it is. :) > > I don't know about others who use this feature, but the way I use it I > could afford to wait 0.5 seconds for each __class__ assignment and not be > too upset about it. Losing this ability entirely, however, would remove a > significant feature from Twisted when used with a later python version. > I implore you not to remove it. Understood. Nevertheless, all evidence suggests that Twisted is not typical Python code. :-) I guess I have a bit of a hidden agenda: Python is more dynamic than the language I *wanted* to design. Some of the dynamicism was simply a implementation trick. Some of the dynamicism is getting in the way of optimizing code, because the optimizer can never prove that certain variables won't be changed. So I'm trying to look for ways that pin down things a bit more. I'm making assumptions about how "typical" Python code uses the dynamic features, and I'm slowly trying to introduce restrictions in the language that make the optimizer's life easier without affecting "typical" code. For example, we're looking into optimizing access to builtins. For this, we need to assume that the __builtin__ module is immutable; in addition, if a module doesn't have a global 'len', for example, we have to assume that such a global won't be inserted into the module dynamically. I'm only aware of a very small number of applications that violate this constraint; I'd rather provide a separate explicit mechanism to override built-in functions so that the optimizer can be aware of a potential change and avoid it. --Guido van Rossum (home page: http://www.python.org/~guido/) From mark21rowe at yahoo.com Fri Aug 10 00:40:30 2001 From: mark21rowe at yahoo.com (Mark Rowe) Date: Fri, 10 Aug 2001 16:40:30 +1200 Subject: get-a-cup-of-coffee slow (fwd) References: <3B735049.4547EC3E@seebelow.org> Message-ID: <3b737128@news.actrix.gen.nz> Hi, The first example should be written: >>> l=[0,1,2,3,4] >>> f=open('e', 'w') >>> f.write(''.join(l)) and the second should be something like: >>> l=[0,1,2,3,4] >>> f=open('e', 'w') >>> l2 = map(str, l) >>> f.writelines(l2) This is because f.write() takes a expects a string argument, not a list, and f.writelines() expects a list of strings, not a list of integers. Mark "Grant Griffin" wrote in message news:3B735049.4547EC3E at seebelow.org... > Quinn Dunkan wrote: > > > > On Thu, 09 Aug 2001 18:12:31 -0400, Lulu of the Lotus-Eaters > > wrote: > > >Grant Griffin wrote: > > >|Also, I tried writing something like this with a list (which are presumably more > > >|suited to being appended), but then I realized that I didn't know how to write > > >|the contents of a list to a file as a stream of bytes. There's probably a > > >|simple way to do that: what is it? > > > > > >''.join(lst) # Python 2.0+ > > >string.join(lst,'') # Python 1.4+ (or something) > > > > There is also file.writelines(lst). It's not documented in my version of > > python, so maybe you're not supposed to use it, but why put it there then? > > It's been there for quite a while now. > > The other day I had tried that with "write". It went something like > this: > > Python 2.0.1 (#18, Jun 30 2001, 10:36:44) [MSC 32 bit (Intel)] on > win32 > Type "copyright", "credits" or "license" for more information. > >>> l=[0,1,2,3,4] > >>> f=open('e', 'w') > >>> f.write(l) > Traceback (most recent call last): > File "", line 1, in ? > TypeError: read-only character buffer, list > > but maybe it should have been "writelines" instead: > > >>> f.writelines(l) > Traceback (most recent call last): > File "", line 1, in ? > TypeError: writelines() requires sequences of strings > >>> > > what-part-of-'Traceback'-don't-I-understand?--ly y'rs, > > =g2 > -- > _____________________________________________________________________ > > Grant R. Griffin g2 at dspguru.com > Publisher of dspGuru http://www.dspguru.com > Iowegian International Corporation http://www.iowegian.com From s713221 at student.gu.edu.au Wed Aug 8 06:25:38 2001 From: s713221 at student.gu.edu.au (Joal Heagney) Date: Wed, 08 Aug 2001 20:25:38 +1000 Subject: PNG images in PhotoImage labels References: Message-ID: <3B7113A2.E66A3C9C@student.gu.edu.au> moonlite56 at yahoo.com wrote: > > I am learning Python this summer, and kind of ran into a rut when I > tried to display .png images in a simple label test. This is what I > have so far: > > from Tkinter import * > > top = Tk() > top.title("Kuti") > top.geometry("200x100") > > iKuti = PhotoImage(file = "gameboy.png") > lHello = Label(top, image = iKuti) > lHello.grid(row = 1, col = 1, sticky = W) > bQuit = Button(top, text="Quit", command = top.quit) > bQuit.grid(row = 1, col = 2, sticky = E) > > top.mainloop() > > This works with gameboy.gif, but gameboy.png displays an error: > > Traceback (most recent call last): > File "tkinter.py", line 9, in ? > iKuti = PhotoImage(file = "gameboy.png") > File "/usr/lib/python2.0/lib-tk/Tkinter.py", line 2974, in __init__ > apply(Image.__init__, (self, 'photo', name, cnf, master), kw) > File "/usr/lib/python2.0/lib-tk/Tkinter.py", line 2930, in __init__ > self.tk.call(('image', 'create', imgtype, name,) + options) > TclError: couldn't recognize data in image file "gameboy.png" > > How do I get this to work with PNG images? This is because the underlying tcl/tk (if it is standard tk) only recognises gifs, *hunts for reference book* pgm and ppm formats. You can use png's if you install the python imaging library (PIL). With PIL installed, do the following (After you've created a Tk instance or you get a RuntimeError returned on the second line.): import Image,ImageTk iKuti = ImageTk.PhotoImage(Image.open("gameboy.png")) # You're using Image.open("gameboy.png") instead of the file = "gameboy.png" bit. Isn't Tkinter cool?!!! -- Joal Heagney is: _____ _____ /\ _ __ __ _ | | _ ___ | /__\|\ || ||__ |\ || |___|/_\|___] | / \ \_||__ ||___| \_|! | | \ \ ! From aahz at panix.com Mon Aug 27 16:20:30 2001 From: aahz at panix.com (Aahz Maruch) Date: 27 Aug 2001 13:20:30 -0700 Subject: Python version dilemma References: <9me54u$4a3$1@flood.xnet.com> Message-ID: <9mea2e$q9s$1@panix2.panix.com> In article , Skip Montanaro wrote: > > > I have a set of scripts that use 2.1 syntax. Now, I'd really like > > these scripts to, when run by the 1.5 interpreter, gracefully state > > that version 2 is required. However, my code fails during the > > compilation stage with the 1.5 interpreter (SyntaxError's and such), > > and so never gets the chanced to execute a code portion that might > > print a pretty (or at least useful) error message. > >What you might want to do is push your version dependent code into separate >modules. Suppose your module is named "mod". In mod.py do this: > > try: > from mod21 import * > except SyntaxError: > from mod15 import * Eww. That would mask a real syntax error (say, introduced by a typo). Use an if statement. -- --- Aahz <*> (Copyright 2001 by aahz at pobox.com) Hugs and backrubs -- I break Rule 6 http://www.rahul.net/aahz/ Androgynous poly kinky vanilla queer het Pythonista "Plus ca change, plus c'est la meme chose." From richard at bizarsoftware.com.au Sun Aug 26 22:44:30 2001 From: richard at bizarsoftware.com.au (Richard Jones) Date: Mon, 27 Aug 2001 12:44:30 +1000 Subject: Facilities Management Software. In-Reply-To: <3B89ACD7.46D3BCD8@vu.edu.au> References: <3B89ACD7.46D3BCD8@vu.edu.au> Message-ID: <01082712443001.01423@ike> On Monday 27 August 2001 12:13, Bart Bartels wrote: > THANK you. I think that I will take your advice. This sounds like a good > way to do the initial development and I will also take John Socha's advise > and take the minimalist approach i.e. start using the software as soon as > it starts to work and refine from there. Please consider using an existing tool as a starting point. I'm the lead developer of a Roundup implementation project - see: http://roundup.sourceforge.net/ Roundup is a very well designed issue tracking system that has a very flexible database backend allowing almost any conceivable issue tracking application to use it (bug tracking, support issues and your requests scenario). It comes with two example schemas (the extended one is actually in use here as our bug/support tracking system) and is easy to add new ones. It has command-line, CGI and e-mail gateways. And more... Roundup will allow you to achieve all the requirements that Andrae gives in his message, and then some. I'd be happy to expand on that if you like. There is a users mailing list that you may subscribe to for more help. I send you this message just so that you don't go off and re-invent the wheel unnecessarily :) Richard From new_name at mit.edu Fri Aug 3 15:59:07 2001 From: new_name at mit.edu (Alex) Date: 03 Aug 2001 15:59:07 -0400 Subject: rexec questions References: Message-ID: Try doing something embarrassing with it: >>> import rexec >>> rexec.RExec().r_exec("import popen2; popen2.os.execvp('echo', ('foo',))") Traceback (most recent call last): File "", line 1, in ? File "/mit/python/arch/i386_linux22/lib/python2.1/rexec.py", line 264, in r_exec exec code in m.__dict__ File "", line 1, in ? File "/mit/python/arch/i386_linux22/lib/python2.1/os.py", line 291, in execvp _execvpe(file, args) File "/mit/python/arch/i386_linux22/lib/python2.1/os.py", line 310, in _execvpe func = execv NameError: global name 'execv' is not defined >>> I think in this context, 'ok_builtin_modules' means modules statically linked into python. In that case, 'os' isn't a builtin module. Alex. From sheila at spamcop.net Tue Aug 28 17:25:51 2001 From: sheila at spamcop.net (Sheila King) Date: Tue, 28 Aug 2001 21:25:51 GMT Subject: Question: posix fcntl module Message-ID: I have a question about file locking aspect of the fcntl module for Unix systems. I was checking out the man pages on the Linux system that I use (my webhost), and under man flock(2) it mentions (among other things): NOTES flock(2) does not lock files over NFS. Use fcntl(2) instead: that does work over NFS, given a sufficiently recent version of Linux and a server which supports locking. flock(2) and fcntl(2) locks have different semantics with respect to forked processes and dup(2). Python docs for the fcntl module state: lockf(fd, operation, [len, [start, [whence]]]) This is essentially a wrapper around the fcntl() locking calls. fd is the file descriptor of the file to lock or unlock, and... Am I correct, then, in interpreting these together, to mean, that I will get greater portability/control if I use fcntl.lockf than if I use fcntl.flock? Because, as I read this, fcntl.lockf may work in situations where fcntl.flock does not (especially over NFS?). Please advise. Thanks, -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From a11w at SoftHome.net Fri Aug 17 05:01:57 2001 From: a11w at SoftHome.net (Jiba) Date: Fri, 17 Aug 2001 11:01:57 +0200 Subject: PEP 252: __slots__ inappropriate References: Message-ID: <3B7CDD85.6EA764EA@SoftHome.net> Roman Suzi wrote: > No, this is not good, because slot is ooptimization hack involving > low-levels of Python implementation. (I am not at all happy it appears in > Python.) I totally agree with you. I think all those hacks are contrary to the dynamic Python philosophy. Yes, 90% of Python code can be wrtitten without any dynamic features, but the 10% left require the whole code to be dynamic, and it is those 10% that are really interesting. And if we do need speed, i don't think *this* is the right way ! Think rather multithreading, event, ... Jiba From anamax at earthlink.net Sun Aug 5 01:47:50 2001 From: anamax at earthlink.net (Andy Freeman) Date: 4 Aug 2001 22:47:50 -0700 Subject: Typing system vs. Java References: Message-ID: <8bbd9ac3.0108042147.5f0c4059@posting.google.com> Christopher Barber wrote in message > You didn't respond to my comments on potential for performance gains. Can I > assume that I scored a point? ;-) Only if you've already exhausted algorithm/architecture/infrastructure improvements and "decrease run-time at any cost" really is the primary consideration. I figure that there are about five applications in the world that qualify, and they're written in assembler. (The other candidates have migrated to hardware.) They, and their techniques, are less relevant to most of us than F1 racecars. Type systems have certain benefits. They also have certain costs. For almost all of us, the performance "potential" isn't a benefit. I suppose someone should have mentioned the costs of inappropriate attention to performance. Chosing a language because you hope that its type system will help with performance seems to qualify. -andy From brian at sweetapp.com Sat Aug 18 14:27:52 2001 From: brian at sweetapp.com (Brian Quinlan) Date: Sat, 18 Aug 2001 11:27:52 -0700 Subject: constant in python? In-Reply-To: <7xhev5z291.fsf@ruckus.brouhaha.com> Message-ID: <002001c12813$7fa676b0$445d4540@D1XYVL01> Paul Rubin: > I dislike the runtime system and the doctrinaire OO culture that's > grown up around Java, but having constants, and rigorously enforcing > protection of private class members and methods is one thing Java did > right. If you believe that then Python might not be the language for you. The problem with enforcing privacy is that the designer can seldom anticipate all of the possible uses of their code and placing arbitrary access restriction can make it impossible for the user to accomplish their task. > It makes the "applet sandbox" very straightforward. This > is useful for web browser extensions but also for security coprocessors > (Dallas Java iButton, Nci) Python is a general purpose programming language and its design should not be significantly compromised to make a particular (uncommon) usage more convenient i.e. security environments. Cheers, Brian From peter at engcorp.com Sat Aug 11 11:41:43 2001 From: peter at engcorp.com (Peter Hansen) Date: Sat, 11 Aug 2001 11:41:43 -0400 Subject: Newbee question here. References: <20010811011037.21887.00002980@ng-dd1.aol.com> Message-ID: <3B755237.166CF075@engcorp.com> Patio87 wrote: > > When I downloaded Medusa, and I had finished winziping it I got like 50 of > those snake icons and they all did the same thing. They all just went into > Python for like a half second and went out. I have no Idea on how to use Medusa > If someone could help me I would much appreciate it Thanks, Pat This is rather droll, considering who Medusa was in Greek mythology. -stonily-avoid-the-real-question-ly yr's, Peter From ctavares at develop.com Sat Aug 4 14:28:25 2001 From: ctavares at develop.com (Chris Tavares) Date: Sat, 04 Aug 2001 18:28:25 GMT Subject: Typing system vs. Java References: <4197FA5DD22AD5118ADE00805F6FA62F3B67FD@eden.vmlabs.com> <5k1nmts15l7nsio00bmht2gnp12tbuq3qn@4ax.com> <38aomtc8if8v3avgglck50ii72phtd9kaf@4ax.com> Message-ID: "Courageous" wrote in message news:38aomtc8if8v3avgglck50ii72phtd9kaf at 4ax.com... > > >Since I can write more powerful programs in smaller, more readable > >chunks, I think I write less buggy code. If we have to reduce the > >simplicity/expressiveness of the language in order to add type-checking, > >then I think the tradeoff is not worth it. > > I emphatically agree. Syntactic type declaration is considerably out of > place with Python. > > Although I was thinking about about something which might be useful. > What if Python were to support a type consistency check on containers? > > >>> mylist = [1,2,"alpha"]! > Type Consistency Error: > >>> > > Note the exclamation point. > > C// > > Doesn't the array module already do this? >>> a = array.array( 'i', [1, 2, "hello world"]) Traceback (most recent call last): File "", line 1, in ? TypeError: an integer is required >>> -Chris From rburnham at cri-inc.com Mon Aug 6 12:41:35 2001 From: rburnham at cri-inc.com (Roger Burnham) Date: Mon, 06 Aug 2001 16:41:35 GMT Subject: Python Job Posting: Boston, MA Message-ID: <3b6ec699.11408674@news-server.socal.rr.com> Cambridge Research & Instrumentation, Inc. (Boston, MA, USA) SENIOR SOFTWARE ENGINEER/Working Supervisor CRi's Instrument Division is looking for a highly competent, self-motivated software engineer to lead and contribute to our growing and results-driven software team in the design and development of our technically-advanced, high-performance biotech and spectral imaging products. Our ideal candidate will have a B.S./M.S. in a technical discipline, such as Electrical Engineering, Computer Engineering, Computer Science, Math or Physics, with the following requirements: *) 5+ years hands-on experience developing robust software products in all phases from requirements and design to coding. *) Extensive experience and proficiency in Python and C/C++. *) 2+ years technical team leadership with strong cross-functional communication skills *) Proven track record of architectural experience *) Ability to communicate with scientists to implement needed algorithms. *) Must have Windows or Unix experience, both is a plus *) Experience in real-time instrument control and data acquisition. In addition to proven experience with the requirements listed in the above description, a knowledge of and/or interest in biotech instrumentation would be an added plus. CRi is a fast-growing pre-IPO company with divisions focused on biotech instrumentation and telecom components, modules, and instruments. Our innovative instrument products are primarily based on state-of-the-art tunable liquid crystal devices that we manufacture. We offer a stimulating and challenging work environment, competitive salary and benefits package, including stock options, incentive bonuses and a company-matched 401(k). Please submit applications to Mary Ann Ryan at MRyan at cri-inc.com. For further information on CRI, visit www.cri-inc.com phone: (888) 372-1242 fax: (781) 935-3388 Roger Burnham rburnham at cri-inc.com From phd at phd.pp.ru Wed Aug 8 09:17:43 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Wed, 8 Aug 2001 17:17:43 +0400 (MSD) Subject: Remote Access Python Interpreter using Telnet In-Reply-To: Message-ID: On Wed, 8 Aug 2001, Steve Holden wrote: > Sam Rushing's Medusa distribution does contain some information on it, but > the real documentation is the comments in the code. Reading that should > enable you to connect to a working Medusa server (and hence, presumaby, to a > working Zope). Do I understand it right that we are talking about Medusa monitor and monitor client? Oleg. ---- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From phd at phd.pp.ru Wed Aug 15 08:37:31 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Wed, 15 Aug 2001 16:37:31 +0400 (MSD) Subject: need definitive answer: capture a keypress In-Reply-To: <90qkntktle172v8vdl6jgi9eh646of3n8f@4ax.com> Message-ID: On Wed, 15 Aug 2001 robin at brainexeculink.com wrote: > On Linux, I can use curses and getch(). But there appears to be no way > of checking for a hit, equivalent to kbhit(). http://groups.google.com/groups?safe=off&th=fe6a3930cf390c66,5&seekm=m38zxqyrxr.fsf%40atrus.jesus.cam.ac.uk#p Oleg. ---- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From root at rainerdeyke.com Wed Aug 29 12:04:23 2001 From: root at rainerdeyke.com (Rainer Deyke) Date: Wed, 29 Aug 2001 16:04:23 GMT Subject: How to write string (float) to file? References: <9mfm1l$gs3$1@zeus.man.szczecin.pl> <9mfqmi$ko4$1@thorium.cix.co.uk> <9ZOi7.53225$c8.23251519@news1.denver1.co.home.com> Message-ID: "Grant Edwards" wrote in message news:slrn9ops86.ks3.grante at grante.comtrol.com... > In article <9ZOi7.53225$c8.23251519 at news1.denver1.co.home.com>, Rainer Deyke wrote: > > wrote in message > > news:9mfqmi$ko4$1 at thorium.cix.co.uk... > >> c = '%.2f'%(float(a)/b) > > > > That's unreliable. Use this instead: > > After reading a handful of follow-ups, I'm still curious what > you mean when you say that's unreliable. >>> def foo(a, b): return '%.2f' % (float(a)/b) ... >>> foo(1, 200) '0.01' >>> foo(3, 200) '0.01' >>> foo(5, 200) '0.03' >>> foo(10000000000000000000000000000000000000000l, 2) '5000000000000000200000000000000000000000.00' -- Rainer Deyke (root at rainerdeyke.com) Shareware computer games - http://rainerdeyke.com "In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor From skip at pobox.com Tue Aug 21 12:01:33 2001 From: skip at pobox.com (Skip Montanaro) Date: Tue, 21 Aug 2001 11:01:33 -0500 Subject: how to stop a server (TCPServer, for example) In-Reply-To: <002f01c12a54$d1281910$4cc809c0@pckrumm.com> References: <002f01c12a54$d1281910$4cc809c0@pckrumm.com> Message-ID: <15234.34269.179375.245793@beluga.mojam.com> Huayin> How to make the server clean itself up and exit? Huayin> Do I need to implment an exit method for the server? That's typical. In my serve_forever method I have (effectively) while self.serving: r,w,e = select.select([self.socket], [], [], self.pause) if r: self.handle_request() My exit method simply sets self.serving to 0. -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From reqhye72zux at mailexpire.com Wed Aug 15 16:53:34 2001 From: reqhye72zux at mailexpire.com (Robert Amesz) Date: Wed, 15 Aug 2001 20:53:34 GMT Subject: Integer division and remainder References: <7x3d6ui5ye.fsf@ruckus.brouhaha.com> Message-ID: Marcin 'Qrczak' Kowalczyk wrote: > 14 Aug 2001 16:20:57 -0700, Paul Rubin > pisze: > >> 7 / 3 = 2 >> -7 / 3 = -3 >> >> This is kind of strange. Normally you expect (-a)/b to be the >> same as -(a/b). That's what happens in most languages, where >> division rounds towards zero: > > Donald Knuth says that Python is right and C is wrong, and I agree > with him here. I expect a%b for positive b to return a value in the > range [0, b). You might be interested to know that a well-known and widely used formula for calculating the day of the week, Zeller's congruence, failed on many systems for dates >= 2000 just because on most systems the mod-function gave the wrong results for negative values. On Python the problem wouldn't have occurred, its mod-function is mathematically correct. Robert Amesz From kirschh at lionbioscience.com Wed Aug 8 03:18:10 2001 From: kirschh at lionbioscience.com (Harald Kirsch) Date: 08 Aug 2001 09:18:10 +0200 Subject: Replacing text for all files in a directory References: Message-ID: Kemp Randy-W18971 writes: > Since I don't write Python every day, here is a simple question. > I have a directory called test, containing files A, B, ..., Z, and I want to > replace all occurrences of the text "Have a good day" to "jump off a cliff." > This is a comic example, but I need to do something similar in real life. > How can I do this in Python, running on Unix? > Everyone, (even me) seems to be sure that this calls for something sh/sed/awk like. Nevertheless, I'll try a Python one. import glob import re ## loop over all file names in the current directory for fname in glob.glob("*"): ## slurp in the whole file fin = open(fname) text = fin.read() fin.close() ## do the replacement in memory s = re.sub("your pattern here", "the replacement text", text) ## dump it out fout = open(fname, "w") # WATCH OUT, THIS DELETES THE OLD FILE fout.write(s) fout.close() This is UNTESTED code. Use at your own risk. Harald Kirsch -- ----------------+------------------------------------------------------ Harald Kirsch | kirschh at lionbioscience.com | "How old is the epsilon?" LION bioscience | +49 6221 4038 172 | -- Paul Erd?s *** Please do not send me copies of your posts. *** From m.1.robinson at herts.ac.uk Tue Aug 7 10:59:27 2001 From: m.1.robinson at herts.ac.uk (Mark Robinson) Date: Tue, 07 Aug 2001 15:59:27 +0100 Subject: scope question Message-ID: <3B70024F.1020606@herts.ac.uk> Can anyone explain the following behaviour to me if I type: count = 0 def function(): print count function() that works fine, however, if I type this: count = 0 def function(): count += 1 print count function() I get the following exception UnboundLocalError: local variable 'count' referenced before assignment why does it find the global variable in the first case and not in the second? blobby From nospam at bigfoot.com Tue Aug 7 10:27:51 2001 From: nospam at bigfoot.com (Gillou) Date: Tue, 7 Aug 2001 16:27:51 +0200 Subject: Zope python paths References: <0q4MdKA6m+b7Ewpm@jessikat.demon.co.uk> Message-ID: <9kotiu$265g$1@norfair.nerim.net> Robin, Have a look at this registry key (for me, it's in Win2K): HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.1\PythonPath I think a python 2.1 engine for Windows will find the python path here at startup. Make some changes to this key (i.e, add any directory) and see what happends in your Zope test. If it changes in your Zope test too, perhaps you should provide a PYTHONPATH in the script that starts Zope to override this. Or make a small change in the Z2.py --Gilles "Robin Becker" a ?crit dans le message news: 0q4MdKA6m+b7Ewpm at jessikat.demon.co.uk... > I have just installed Zope 2.4 and am trying to get some packages to run > with it. These are failing fairly miserably with really strange errors > such as can't find module asyncore. > > I suspect path confusion with my existing Python 2.1 setup. > > A simple check with an external method > > def pythonPath(): > import sys > s='path=\n' > for p in sys.path: > s += p + '\n' > return s > > give me that the path inside this method is > > path= > C:\Python\WebSite\lib\python\ZopeZODB3 > C:\Python\WebSite\lib\python > C:\Python\WebSite > C:\Python\WebSite/lib/python > C:\Python\WebSite/bin/lib > C:\Python\WebSite/bin/lib/plat-win > C:\Python\WebSite/bin/lib/win32 > C:\Python\WebSite/bin/lib/win32/lib > C:\Python\WebSite > C:\Python\WebSite > c:\python\pythonwin ! > c:\python\win32 ! > c:\python\win32\lib ! > c:\python ! > c:\python\website\bin\dlls > c:\python\website\bin\lib > c:\python\website\bin\lib\plat-win > c:\python\website\bin\lib\lib-tk > c:\python\website\bin > > the bits marked with ! are obviously causing some confusion as they > relate to my existing installation. Is there an obvious way to inhibit > this erroneous path pickup if I can determine where it comes from? > > I don't seem to have a PYTHONPATH environment variable set in the .cmd > file that runs zope. > -- > Robin Becker From dnjjones at yahoo.com Sat Aug 11 12:03:39 2001 From: dnjjones at yahoo.com (Jeremy Jones) Date: Sat, 11 Aug 2001 16:03:39 GMT Subject: dynamic naming for hierarchical problem References: <87ofppnax8.fsf@xeno.localhost> <015501c12204$bf0872a0$d3bd6ac2@zko> <008d01c1220f$141bbae0$6401a8c0@atl.mediaone.net> <9l2uqm0eub@enews2.newsguy.com> Message-ID: Alex Martelli wrote in message news:9l2uqm0eub at enews2.newsguy.com... > "gzeljko" wrote in message > news:mailman.997499838.6140.python-list at python.org... > > From: Jeremy and Debra Jones > > > > > > It seems like if you were to do it in a rdbms, you would need at least > two > > > tables: > ... > > No, one table: > > TBL > > ( PARENT, CHILD, CHILD_ATRIBUTE1,.., > > PRIMARY KEY (PARENT, CHILD)) I really hadn't thought of it like that. That would work...I learn something new every day (especially in this news group :-) > Something wrong with this constraint, since it implies a child may > have multiple parents. I think CHILD by itself needs to be the > primary key. That would work. >Otherwise I agree -- no need to use multiple tables > for a parent/child relationship. Rather, since children appear to > have varying attributes, you'll need to split THOSE off into a table > of their own (with CHILD as a foreign key). In the example that I was working on, the children (not of the same parent, but in different tiers of the hierarchy) were of differing types and would have different attributes and different quantities of attributes. I don't know if I spelled that out exactly like that initially, but immediately under the root would be test sets. The test sets right now don't have any attributes of their own, but they do have children - tests. The tests would have an attribute of pass/fail and a reason why and commands as children. The commands would have attributes of expected result, pass/fail, actual result. I suppose you could hack together a table that would accomodate all of those different attributes and have CHILD as a foreign key, but it seems it would be a pain to give it room to grow if I needed it to. (I just KNOW that I am setting myself up here for you guys to show me some dynamite way to accomodate a dynamic set of varying numbers of attributes since it is obvious that both of you have worked a lot more with databases than I have. When you prove me wrong, I will gratefully accept the humiliation :-) I appreciate the posts. They have definitely spurred me on to think differently. I am still inclined to think that the DOM/XML route will be a more simple route for my specific problem. From sdm7g at Virginia.EDU Thu Aug 2 15:57:14 2001 From: sdm7g at Virginia.EDU (Steven D. Majewski) Date: Thu, 2 Aug 2001 15:57:14 -0400 (EDT) Subject: What's the standard way to turn a code object into a function ? In-Reply-To: <903e2d53.0108021136.77c07e25@posting.google.com> Message-ID: I don't know if there is a "standard" way -- it's not something that is routinely done. But take a look at the 'new' module. >>> import new >>> dir(new) ['__doc__', '__file__', '__name__', 'classobj', 'code', 'function', 'instance', 'instancemethod', 'module'] >>> new.function.__doc__ 'Create a function object from (CODE, GLOBALS, [NAME [, ARGDEFS]]).' See the library reference manual for a more complete description. -- Steve Majewski From kuntsi at cc.helsinki.fi.Spam.Me.Not Mon Aug 27 15:16:37 2001 From: kuntsi at cc.helsinki.fi.Spam.Me.Not (Antti Kuntsi) Date: 27 Aug 2001 19:16:37 GMT Subject: Pysol (python solitaire game) References: <3B888F33.2CB036F6@student.gu.edu.au> Message-ID: Joal Heagney wrote: > Simon Brunning wrote: > > What are you - some kind of Luddite? Next you'll be telling me that you > > think meeting people is better than email! > Welll .... *grins* There's just SOME things you can't do over email! Isn't that why IRC and all kinds of chats were invented ;-) .antti -- /"\ | iki. \ / ASCII Ribbon Campaign | fi/ X Against HTML Mail | mickut / \ From nospam at bigfoot.com Mon Aug 20 05:46:18 2001 From: nospam at bigfoot.com (Gillou) Date: Mon, 20 Aug 2001 11:46:18 +0200 Subject: Python 2.1 CGI engine for PWS (Win98) => Error 500 (FIXED) References: <9losla$2mns$1@norfair.nerim.net> Message-ID: <9lqlut$864$1@norfair.nerim.net> OK it's fixed... My cgi-bin virtual directory was located in the wwwroot (/) for documents. Now it's outside and it works... Thanks evrybody and sorry for the disturbance. --Gillou "Maan Hamze" a ?crit dans le message news: tA_f7.478045$lq1.92070980 at typhoon.austin.rr.com... > Gillou > change the key to something like .gcp > reboot, and see if it works. > Try it with a very simple script: > print 'Content-type: text/html' > print 'testing python cgi' > > for the value, try: > "C:\Python21\python.exe %s %s" > or > "C:\Python21\python.exe -u %s %s" From quinn at retch.ugcs.caltech.edu Fri Aug 3 18:35:37 2001 From: quinn at retch.ugcs.caltech.edu (Quinn Dunkan) Date: 3 Aug 2001 22:35:37 GMT Subject: counting occurrences References: <9kf2l60uic@drn.newsguy.com> Message-ID: On 3 Aug 2001 13:47:34 -0700, Grant Griffin wrote: >This then usually leads to a need to "sort keys by value"--something like this: > > itemlist = [(value, key) for (key, value) in counter.items()] > itemlist.sort() > itemlist.reverse() ... >For me, this sort of thing comes up so often that it qualifies as an "idiom". So put it in a function. >However, the sorting thing is a pain (at least a first--then you get so you >like to impress people by having finally found a use for list >comprehensions), so I mentioned to a friend that it would sure be nice >if Python dictionaries had an "items_sorted_by_value" method. But, among >other things, my friend (who has been using Python for a *long* time) said >that he has never wanted such a thing, because he doesn't see counting >occurrences "as a dictionary operation". > >So how do you think he does it? Here's how I would probably do it: def occurrences(pred, seq): # (t -> Boolean) -> [t] -> [(Int, t)] d = {} for elt in seq: if pred(elt): d[elt] = d.get(elt, 0) + 1 a = [ (v, k) for (k, v) in d.items() ] a.sort() a.reverse() return a Use it like so: from __future__ import nested_scopes def count_word(w, fp): punctuation = ',."\';:-/()[]{}' kill_punctuation = string.maketrans(punctuation, ' ' * len(punctuation)) def word_in_line(s): return s in s.translate(kill_punctuation).split() return occurrences(word_in_line, fp.readlines()) Note that generators can make generating the 'seq' argument easier. This is probably a more functional approach. An object-oriented approach would be to make a "counter" object which wraps your dict and presents a 'item(e)' to count a new item, 'occurrences(e)' to show how many times 'e' has been item()ed, 'historgram()' to give a list of frequencies, etc. From r.b.rigilink at chello.nl Fri Aug 10 08:57:36 2001 From: r.b.rigilink at chello.nl (Roeland Rengelink) Date: Fri, 10 Aug 2001 12:57:36 GMT Subject: Python at sourceforge Message-ID: <3B73DD07.8576A76F@chello.nl> Hi, I've wasted an afternoon getting to know htmllib. In the process I gathered the following information that readers of this newsgroup might find interesting One measure of the relative popularity of programming languages in the open source community may be the number of sourceforge projects that use these programming languages. I have extracted the following statistics on Python, Perl, Java and C from the sourceforge trove listing. http://sourceforge.net/softwaremap/trove_list.php The absolute numbers refer to the number of projects --with a registration date before the date in the table-- that list the given language as (one of) their programming languages. Relative numbers are given with respect to the number of projects at 01-jan-2000 and with respect to the number of python projects. date absolute numbers relative numbers rel. numbers (00-01-01 = 1.00) (python = 1.00) Pyth Perl Java C Py Perl Java C Perl Java C 00-01-01 28 63 32 185 1.0 1.0 1.0 1.0 2.25 1.14 6.61 00-02-01 63 122 91 365 2.2 1.9 2.8 2.0 1.94 1.44 5.79 00-03-01 91 169 135 516 3.2 2.7 4.2 2.8 1.86 1.48 5.67 00-04-01 121 242 210 719 4.3 3.8 6.6 3.9 2.00 1.74 5.94 00-05-01 157 317 281 934 5.6 5.0 8.8 5.0 2.02 1.79 5.95 00-06-01 213 413 368 1203 7.6 6.6 11.5 6.5 1.94 1.73 5.65 00-07-01 258 527 479 1462 9.2 8.4 15.0 7.9 2.04 1.86 5.67 00-08-01 311 642 602 1727 11.1 10.2 18.8 9.3 2.06 1.94 5.55 00-09-01 366 782 760 2020 13.1 12.4 23.8 10.9 2.14 2.08 5.52 00-10-01 414 908 900 2270 14.8 14.4 28.1 12.3 2.19 2.17 5.48 00-11-01 464 1030 1081 2542 16.6 16.3 33.8 13.7 2.22 2.33 5.48 00-12-01 520 1174 1265 2813 18.6 18.6 39.5 15.2 2.26 2.43 5.41 01-01-01 566 1294 1438 3044 20.2 20.5 44.9 16.5 2.29 2.54 5.38 01-02-01 637 1435 1638 3368 22.8 22.8 51.2 18.2 2.25 2.57 5.29 01-03-01 695 1578 1846 3681 24.8 25.0 57.7 19.9 2.27 2.66 5.30 01-04-01 758 1734 2115 4018 27.1 27.5 66.1 21.7 2.29 2.79 5.30 01-05-01 813 1888 2318 4339 29.0 30.0 72.4 23.5 2.32 2.85 5.34 01-06-01 887 2005 2533 4605 31.7 31.8 79.2 24.9 2.26 2.86 5.19 01-07-01 936 2130 2708 4858 33.4 33.8 84.6 26.3 2.28 2.89 5.19 01-08-01 997 2243 2916 5130 35.6 35.6 91.1 27.7 2.25 2.92 5.15 01-09-01 1014 2278 2963 5202 36.2 36.2 92.6 28.1 2.25 2.92 5.13 Interesting conclusions: - The relative number of Python and Perl projects have remained constant over the past two years - Java was initially the most rapidly growing of the four languages, but relative numbers with respect to Python an Perl have stabelized over the last 5 months. - The relative number of C projects has been declining slowly but steadily A big caveat: Listed are the number of projects that have been started, no attempt has been made to weigh the succesfullness of these projects (measured for instance by either current status or activity ranking) Reactions? Roeland -- r.b.rigilink at chello.nl "Half of what I say is nonsense. Unfortunately I don't know which half" From jpet at eskimo.com Sun Aug 26 03:53:10 2001 From: jpet at eskimo.com (Jeff Petkau) Date: Sun, 26 Aug 2001 07:53:10 GMT Subject: Comment on PEP-0238 References: Message-ID: > But there are dimisishing returns. Integer division isn't that > common, ... I find that awfully hard to believe. I just scanned through the Python-2.0 source for integer division. Out of 1055 .py files, 111 use integer division and will be need to be fixed for the new division behavior. I didn't count the exact number that used floating division, but it was much smaller--maybe 20 files or so. The majority didn't use any division at all. There are whole fields of computing where you might never encounter a floating point number, but I can't imagine any where you'll never need integer division. Anyway, since I wasted an hour counting them, here's the breakage list: Demo/classes/md5driver.py Demo/classes/dates.py Demo/classes/Range.py Demo/zlib/minigzip.py Demo/tkinter/guido/electrons.py Demo/tkinter/guido/hanoi.py Demo/tkinter/guido/solitaire.py Demo/tkinter/guido/sortvisu.py Demo/rpc/xdr.py Demo/scripts/fact.py (ok if exact results yield integers, eg. 6/3 is 2) Demo/scripts/ftpstats.py Demo/scripts/lpwatch.py Demo/scripts/markov.py Demo/scripts/pi.py Demo/scripts/unbirthday.py Demo/sgi/al/intercom.py Demo/sgi/al/playaiff.py Demo/sgi/video/DisplayVideoIn.py Demo/sgi/video/Dsend.py Demo/sgi/video/LiveVideoIn.py Demo/sgi/video/LiveVideoOut.py Demo/sgi/video/VCR.py Demo/sgi/video/VFile.py Demo/sgi/video/Vb.py Demo/sgi/video/Vcopy.py Demo/sgi/video/Vfix.py Demo/sgi/video/Vinfo.py Demo/sgi/video/Vmkjpeg.py Demo/sgi/video/Vplay.py Demo/sgi/video/Vrec.py Demo/sgi/video/Vrecb.py Demo/sgi/video/Vunjpeg.py Demo/sgi/video/aplay.py Demo/sgi/video/video2rgb.py Demo/sgi/sv/burstcapt.py Demo/sgi/sv/contcapt.py Demo/sgi/sv/rgbgrab.py Demo/sgi/gl/mclock.py Demo/sockets/ftp.py Demo/threads/Generator.py Doc/tools/buildindex.py Doc/tools/keywords.py Doc/ref/reswords.py Lib/aifc.py Lib/audiodev.py Lib/bdb.py Lib/binhex.py Lib/bisect.py Lib/calendar.py Lib/dumbdbm.py Lib/ftplib.py Lib/imaplib.py Lib/pstats.py Lib/quopri.py Lib/repr.py Lib/rfc822.py Lib/sndhdr.py Lib/stringold.py Lib/sunau.py Lib/tabnanny.py Lib/tokenize.py Lib/uu.py Lib/wave.py Lib/whrandom.py Lib/xdrlib.py Lib/zipfile.py Lib/dos-8x3/stringol.py Lib/dos-8x3/test_aud.py Lib/dos-8x3/test_aug.py Lib/dos-8x3/test_bin.py Lib/dos-8x3/test_exc.py Lib/dos-8x3/test_gra.py Lib/dos-8x3/test_img.py Lib/dos-8x3/test_lon.py Lib/dos-8x3/test_opc.py Lib/lib-old/para.py Lib/lib-old/cmp.py Lib/lib-old/poly.py Lib/lib-old/rand.py Lib/plat-aix3/FCNTL.py Lib/plat-aix3/TERMIOS.py Lib/plat-aix4/FCNTL.py Lib/plat-aix4/TERMIOS.py Lib/plat-beos5/IN.py Lib/plat-beos5/SOCKET.py Lib/plat-irix5/SOCKET.py Lib/plat-irix5/cddb.py Lib/plat-irix6/SOCKET.py Lib/plat-irix6/cddb.py Lib/plat-linux1/FCNTL.py Lib/plat-linux2/FCNTL.py Lib/plat-linux2/IN.py Lib/plat-linux2/SOCKET.py Lib/plat-linux2/TERMIOS.py Lib/plat-sunos5/SOCKET.py Lib/plat-sunos5/STROPTS.py Lib/test/pystone.py Lib/test/sortperf.py Lib/test/test_audioop.py Lib/test/test_augassign.py Lib/test/test_binascii.py Lib/test/test_imgfile.py Lib/test/test_long.py Lib/test/test_mmap.py Lib/test/test_opcodes.py Lib/test/test_pty.py Tools/pynche/ListViewer.py Tools/scripts/byteyears.py Tools/scripts/ftpmirror.py Tools/idle/AutoIndent.py Tools/idle/EditorWindow.py --Jeff Petkau (jpet at eskimo.com) From ws at dohao.org Fri Aug 31 01:26:21 2001 From: ws at dohao.org (Du Wellsun) Date: 30 Aug 2001 22:26:21 -0700 Subject: help me Message-ID: hi, I'm a big new fan of python. I want to be a master in python. I've read two books,such as Learning Python and Python Developer's Handbook. Could anybody tell me where I can find example source code on large project ? and UML Tools to do with python. or better example code tips . Thanks a lot. I like python. I hava a dream ,I want to make python's interactive modle replace my operating system. Every task finished by python. Can it come true ? I also want to make friends with everybody here. I don't like Java , Perl , Php and VB, they make me tired much more, though advantages. From new_name at mit.edu Tue Aug 28 17:56:17 2001 From: new_name at mit.edu (Alex) Date: 28 Aug 2001 17:56:17 -0400 Subject: unittest / pdb tricks? References: Message-ID: Hi, Sam. Below is the subclass of TestCase that I use to make unittests throw an exception and drop back into the interpreter when they fail. You can turn this behaviour off on a case-by-case basis by overriding the value of __stopOnError__. I find it useful to do that for some tests whose failures don't indicate such urgent problems, like the CVS repository not being completely up-to-date. Alex. class TestCase(unittest.TestCase): """Version of TestCase that can be easily run independantly of the testing framework.""" __stopOnError__ = 1 def __init__(self, *args, **kw): if args: apply(unittest.TestCase.__init__, (self,) + args, kw) def throwsException(self, test_function, expected_exc): """True if 'test_function()' throws 'expected_exc'""" try: test_function() except expected_exc: return 1 def __call__(self, result=None): if self.__stopOnError__: result.startTest(self) self.setUp(); self.__testMethod(); self.tearDown(); print else: unittest.TestCase.__call__(self, result) From jmg at ecs.soton.ac.uk Mon Aug 13 12:35:13 2001 From: jmg at ecs.soton.ac.uk (Jacek Generowicz) Date: 13 Aug 2001 17:35:13 +0100 Subject: 100,000 messages celebration? References: <3B7384D0.12FB2B35@letterror.com> <3B742612.BCEFB452@letterror.com> Message-ID: Guido van Rossum writes: > > > Is the Y axis a cumulative total, or messages per unit > > > time. > > > > Per unit time. It's straight from the numbers at > > http://groups.yahoo.com/group/python-list/ > > But notice that since it's exponential, the curve would have the same > shape if it was a cumulative total. :-) Except that it would have to be monotonically increasing (which this one ain't), unless you admit antimessages into the picture . . . Jacek From mats at laplaza.org Wed Aug 22 12:42:56 2001 From: mats at laplaza.org (Mats Wichmann) Date: Wed, 22 Aug 2001 16:42:56 GMT Subject: libpython and position-independent code References: Message-ID: <3b83dfcf.47010627@news.laplaza.org> On Tue, 21 Aug 2001 16:06:36 -0400, "Gregory (Grisha) Trubetskoy" wrote: : :Hello there - : :I am a bit puzzled by what significance PIC code has in shared libraries. :(This is Solaris 8, but I'm intersted in how this applies to other OS's :too) : :While tinkering with libtool, I found that it wouldn't link libpython into :a shared library (mod_python.so), because libpython might not be PIC. Shared libraries need to be PIC (position-independent code) since the address they're loaded at can't be guaranteed. Static libraries will have some final address calculations done when they're bound into the program by the linker, so they don't need to be PIC. Mats Wichmann (Anti-spam stuff: to reply remove the "xyz" from the address xyzmats at laplaza.org. Not that it helps much...) From cbarber at curl.com Fri Aug 10 09:13:27 2001 From: cbarber at curl.com (Christopher Barber) Date: 10 Aug 2001 09:13:27 -0400 Subject: Typing system vs. Java References: <8bbd9ac3.0108042147.5f0c4059@posting.google.com> <9kmffa017qc@enews4.newsguy.com> Message-ID: "Alex Martelli" writes: > "Christopher Barber" wrote in message > > Sometimes you can write C extensions for the slow parts, > > but in some cases you will have to start over. > > Applications whose "performance bottleneck" is _100%_ of their code?! > Never heard of any such thing. 10% to 20% seems to be common. What > counter-examples do you have in mind? Not a bottleneck, but a continuous degredation of performance across the entire application due to memory use, overhead for method dispatching, etc. This situation is only likely to happen in very large OO applications. There are also deployment situations where you might not be allowed to make use of C extensions. > > Don't get me wrong, Python is a great language and is useful for many > types of > > applications, but it is ridiculous to say that there aren't a significant > > number of applications for which it does not have the required > performance. > > Not by itself, surely -- but, when using Python together with lower-level > languages for that 10% to 20% of code whose speed really matters, I > can't easily think of examples. But why can't Python be fast enough without resorting to extensions? Forcing users to learn C in order to make their Python code fast detracts from Python's advantage as a simple, easy-to-use language. I think that adding features to allow Python powerful enough to remove the need for extensions would be worth a little bit of extra complexity. I personally don't think that type declarations would add much complexity, but I guess I can see how someone new to them might be confused. Of course, that same person would be lost once they had to learn C. - Christopher From ykingma at accessforall.nl Thu Aug 9 17:22:13 2001 From: ykingma at accessforall.nl (Ype Kingma) Date: Thu, 09 Aug 2001 22:22:13 +0100 Subject: Interesting problem - can it be done References: Message-ID: <3B72FF00.A5C005C4@accessforall.nl> Mark, you wrote: > > Hi all, > I have a list of strings and the strings are functions that I want to > call on an object. How do I call the functions without hardcoding the > function call? Here is an example > > funclist = ['func1()', 'func2()', 'func3()'] > x = len(funclist) > y = 0 > while y < x: > value = testobj.funclist[y] > y = y +1 > > This way I could grow the list of functions to be called without coding more > like the way I am doing it now. I would like to avoid doing the following: > > value = testobj.func1() > value = testobj.func2() > value = testobj.func3() > All the getattr() stuff is great. For testing it has been coded for you in PyUnit.py. It will do your while loop (above), administer your test results and a lot more, when you are willing to declare your test methods in a subclass of an imported testing base class. Elaborate example: http://diveintopython.org/roman_divein.html You can get it here: http://pyunit.sourceforge.net/ Have fun, Ype -- email at xs4all.nl From marcj at zwallet.com Fri Aug 17 19:28:48 2001 From: marcj at zwallet.com (marcj at zwallet.com) Date: Fri, 17 Aug 2001 23:28:48 GMT Subject: This is a test Message-ID: test -- SUBMIT YOUR AD HERE! http://www.adtrackclassifieds.com/index.cfm?u=3690361 From timr at probo.com Sun Aug 12 20:44:36 2001 From: timr at probo.com (Tim Roberts) Date: Sun, 12 Aug 2001 17:44:36 -0700 Subject: win32 screen captures References: <5Np$EWAgs5c7EwiQ@jessikat.fsnet.co.uk> <3b73ed53.977798@nntp.sprynet.com> Message-ID: dgallion1 at yahoo.com (Darrell) wrote: >Robin Becker wrote: >> I have also managed to get a PDF App to pop up using COM directly, but >> can't seem to get an open document into it, whine >> > >Untested code cut from another app: > >import os, re, thread, sys > >assoc=os.popen("assoc .pdf").read() >assocA=re.findall("=(.*)\012",assoc)[0] >ftype=os.popen("ftype %s"%assocA).read() >ftypeA=re.findall('=(".*?")', ftype)[0] Unfortunately, "assoc" and "ftype" are on Windows NT only. They aren't available on Win98 or, of course, Unix. You can achieve the same end on all Windows systems with win32api.ShellExecute. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From syt at pegasus.logilab.fr Fri Aug 3 09:01:47 2001 From: syt at pegasus.logilab.fr (Sylvain Thenault) Date: Fri, 3 Aug 2001 13:01:47 +0000 (UTC) Subject: pure Python vs extending module ? Message-ID: hi! I am working on a xmldiff tool written in python. The main loop essentially consists in creating lists and reading values in those lists. The problem is that there is a high complexity, and the loop body should easily be called more than 1 000 000 times Would this work take less time with the main loop written in a C extension module ? thanks -- Sylvain Thenault LOGILAB From peter at engcorp.com Thu Aug 23 03:07:18 2001 From: peter at engcorp.com (Peter Hansen) Date: Thu, 23 Aug 2001 03:07:18 -0400 Subject: vi % alternive command References: <3B8417F8.1B469E91@bioeng.ucsd.edu> Message-ID: <3B84ABA6.E312EAB5@engcorp.com> "Matthew D. Wood" wrote: > > Um... Not quite, but sort of. > > you can use your open lines as a sort of cheat. for instance '}' should > move you to the next empty line. Thus, >} will indent the rest of the > section you're in. Unfortunately, it doesn't work as well as you would > like. > > There was a VIM script at : > http://vim.sf.net/scripts/script.php?script_id=30 > > but I don't think it works like I would like it to. Maybe somebody could reimplement the script using the Python scripted version of VIM, thus not only solving the problem of the OP, but also preventing this from being a completely off-topic thread.... (?) -- ---------------------- Peter Hansen, P.Eng. peter at engcorp.com From tjreedy at home.com Mon Aug 13 23:34:06 2001 From: tjreedy at home.com (Terry Reedy) Date: Tue, 14 Aug 2001 03:34:06 GMT Subject: Another two examples of using changing classes References: <637b94bc.0108131426.48c84b3d@posting.google.com> Message-ID: "Itamar Shtull-Trauring" wrote in message news:637b94bc.0108131426.48c84b3d at posting.google.com... > Changing classes at runtime can be useful at times, and I've done it > myself at times. And since Twisted uses it and I intend to use Twisted > for my server architecture, that's a 3rd use as well. > > > == 1 == > I have a proxy class that forwards network requests to a remote > server. When it gets disconnected, it still needs to respond to > commands, albeit with failure responses. > > However, if a certains commands are given to the instance it can > reconnect and start working normally again. > > The other way to do this is to have two classes - Connected and > Disconnected, and the instance switches between the classes to change > the way it works. Doing this without changing classes would require > having a frontend instance and a changing backend instance, and double > the number of function calls done with every operation. A third way is to have a 'connected' variable and make every function conditional on the state variable. Changing class is much cleaner. An analogous use in games is when characters get killed and hang around until resurrection or dissapation of the corpse. > == 2 == > Consider a (SocketServer) network server that supports multiple > protocols on the same port. When a connection is opened the first > message tells the handler what protocol to use, and the handler then > changes its class to the appropriate handler class. In many games, players start as generic players before selection/earning a profession/class which adds additional behaviours. Sometimes there is a second transition to a specialty.This is naturally modeled as a class hierarchy with transitions implemented by a class change. Nice examples. Terry J. Reedy From Bart.Bartels at vu.edu.au Thu Aug 23 03:53:48 2001 From: Bart.Bartels at vu.edu.au (Bart Bartels) Date: Thu, 23 Aug 2001 17:53:48 +1000 Subject: Facilities Management software References: Message-ID: <3B84B68C.C84D9C12@vu.edu.au> G'Day It is interesting to do a google search on this and related topics. The Uni that I work for has $A300 mil worth of building and $A??? mil in plant and equipment, managed by less then 30 people. Look for Facility Management software in the Free Software/Open source movement and there is very little. Do a Help desk search and it is overwhelmingly IT related. There are billions of $ worth of building out there and millions who are trying to run and maintain them and it is hard to find software to help us. I did a search for CA's Advanced Help Desk and it is propriety (CA gives nothing away) and is probably a good product. It is IT focused. If it was Free Software/Open sourced the I would be able to look at it and change to suit me (assuming I knew the programing language). I manage buildings and services. I want a tool that I can afford and modify to suit my self. I have an itch and it seems that nobody has a back-scratcher and hence I have started to make my own. Any one else itchy? Talk to me and wE'LL build ouR OWN YOU BEAUT BACK-SCRATCHER... pant, pant, pant Sorry, getting all worked up :-) Bart BTW. a cultural question? Which is your given name i.e. which name do people use when they talk to you. In the west it is the first one. In my case it is Bart GADGIL PRASAD /INFRA/INFOTECH wrote: > > > hello, > > we are currently useing a sw 'Advanced Help Desk' (CA) which > is a sort of Object Ori. Framework for the inter-organization > helpdesk tasks. The IT req is currently automated. Though > FM will also be interesting to be added to it's tasks. > > I am more involved in customisation of this OO framework sw > and from what I have seen, has a fairly clean design. > > this effort seems interesting, if only to learn python to me. > btw AHD uses, rdbms in backend, a java OR web-clnt to connect > to the AHD server to log calls update them etc. > > /psg -------------- next part -------------- An HTML attachment was scrubbed... URL: From aahz at panix.com Tue Aug 21 15:19:39 2001 From: aahz at panix.com (Aahz Maruch) Date: 21 Aug 2001 12:19:39 -0700 Subject: Extension module crashes when Py_BEGIN_ALLOW_THREADS is used in Windows event loop. References: Message-ID: <9luc8b$h2d$1@panix2.panix.com> In article , Parzival Herzog wrote: > >Can anyone shed some light on what the problem here could be? What version of Python are you using? Try using Python 2.1.1 to see if that makes any difference. -- --- Aahz <*> (Copyright 2001 by aahz at pobox.com) Hugs and backrubs -- I break Rule 6 http://www.rahul.net/aahz/ Androgynous poly kinky vanilla queer het Pythonista "I now regard a fact as a hypothesis that people don't bother to argue about anymore." --John Burn, quoted in Lawrence Wright's _Twins_ From tim.one at home.com Thu Aug 16 20:33:17 2001 From: tim.one at home.com (Tim Peters) Date: Thu, 16 Aug 2001 20:33:17 -0400 Subject: Deposing Dictactors In-Reply-To: <5396362c.0108161256.7d3b7380@posting.google.com> Message-ID: [sburrious] > I think what he's saying is that your use of the plural (see above) > implies a BOFL (benevolent oligarchy for life), rather than a BDFL. A > BOFL for life would be deplorable. There would be endless morbid > discussions about which combination of bus accidents should bring the > oligarchy to an end. > > I shudder to think of it. > > but-just-in-case-voting-for-guido+tim'ly yours, sburrious I don't know about this. Would the switch to an oligarchy be accompanied by a switch to paying the oligarchy? And paying them well? If so, then screw Guido, I'll volunteer to be OOFL (Oligarchy of One For Life)! It's all the same to *you* in the end anyway, because I'll die much sooner than Guido, so you'll be back to the old unpaid BDFL before most people even notice that the oppressor has changed. The difference to me is that I'll be able to afford a headstone for my grave, maybe even with a nice engraving illustrating proper indentation, for the continued instruction of the living. all's-for-the-best-in-this-best-of-all-possible-worlds-ly y'rs - tim From aleax at aleax.it Tue Aug 14 11:54:28 2001 From: aleax at aleax.it (Alex Martelli) Date: Tue, 14 Aug 2001 17:54:28 +0200 Subject: Python 2.1 quick reference References: Message-ID: <9lbhjn0282c@enews1.newsguy.com> "Simon Brunning" wrote in message news:mailman.997798281.28806.python-list at python.org... > > From: Oleg Broytmann [SMTP:phd at phd.pp.ru] > > On 8 Aug 2001, Simon Brunning wrote: > > > A preliminary of a Python version quick reference is now available at > > > . > > > > The ZIP file is broken. Please recreate it and let us know. > > Fixed now. Also, text and PDF versions now available. I have also fixed 1 > (one) spelling mistake (thanks, Andrew), so if you have already got the > HTML, I wouldn't bother getting it again. > > Anyone find any other problems? Paging down the PDF file (with Acrobat Reader 4 working as a plug-in to IE 5.5) at page 5 I get an error messagebox: "There was an error processing a page. Too few operands." then on clicking OK to that, another: "An unrecognized token 285.8.Tw was found" and page 5 appears totally white. So there would seem to be some problem with the PDF version. Alex From tanzer at swing.co.at Tue Aug 28 03:08:08 2001 From: tanzer at swing.co.at (Christian Tanzer) Date: Tue, 28 Aug 2001 09:08:08 +0200 Subject: intentional tease ( was: New Python User Question) In-Reply-To: Your message of "27 Aug 2001 10:48:13 PDT." <9me14t01035@drn.newsguy.com> Message-ID: Grant Griffin wrote: > Python has become an essential tool for me, but, unfortunately, due to > the speed/size issue, I'm able to use it only for "offline" PC tasks > like this. My own production code generally runs in embedded systems. > In those cases, due to the inherent requirement for maximum speed and > minimum size, one has little choice but to use a compiled language. > (Historically, due to compiler availability, one has had little choice > in DSP but to use C, though C++ compilers have recently become > available for DSP microprocessors.) > > In embedded systems (and many other application domains), using an > interpreter is simply not an option. Other posts in this thread have > suggested that the lesser speed of Python is worth what you gain in > development time. I wholeheartedly agree--at least in those cases > where you can trade the two. For the offline data processing I do, > it's a no-brainer: use Python. > > But depending on how many embedded boxes one plans to sell, the ease > of development of Python can _truly_ be false economy, if it forces > you to put $10 of extra computer inside the box. (Python still makes a > good prototyping language, though.) More imporatantly, you sometimes > simply couldn't get there from here if you used an interpreter. True. Incidentally, I'm programming design tools for high-volume embedded systems. In our market, they fight to shave of cents (for some nodes, the whole embedded CPU costs a few dollars). So for some embedded code, we use Python to generate C code to be embedded . > Although there are might be some folks who can spend 100.0% of their > programming lives in Python (except when they have to write extension > modules ), I suspect that _most_ folks who use Python do part of > their work in Python and part in a compiled language--probably C/C++. Since about two years, I'm one of the lucky 95%+ Python programmers. Sometimes I do reviews of C code... > *KEY POINT*: Anything that greatly speeds Python (and a compiler--in > whatever form--is the only thing we can reasonably expect would, after > 10 years of careful tweaking by lots of talented folks!) increases the > percentage of programs we can write in Python. That is undeniably A > Good Thing. Agreed. As long as it doesn't take away Python's strengths. > However, in working on my little project, I've realized that even > leaving dynamic variables aside, certain things in the design of > Python are inherently "slow". A simple example is the fact that Python > allows negative array indices. When implementing that, one can only > check for a negative index, then add the length. And even if it wasn't > negative, you have to bounds-check the result, to possibly raise an > IndexError. (An "assert" won't do: the Python code might have been > written to rely on an IndexError.) > > Therefore, compiled Python will always be slower than something > written from scratch in C++ (which doesn't do bounds-checking: you > write it where you need it rather than it happening automatically in > every case). I don't agree with this. Two points: - In a former life, I implemented a big C++ system. The code used Eiffel-style assertions (implemented as C macros). For the production code, only preconditions were enabled -- postconditions and invariants were checked during testing. Disabling the preconditions increased application performance by about 10% -- not worth the gain, IMHO. OTOH, making a key class (linked list) non-dynamic (i.e., removing all inheritance relations and virtual statements) increased application performance by about 20% -- still not worth the pain, IMNSHO. The real bottleneck of that application lies somewhere in the depths of a flex-generated module doing macro expansions -- pure C and very hard too fix. - If your compare Python and C++ programs implementing exactly the same algorithm, C++ will always be faster. But that's a unrealistic case. Normally, the Python program will be ready to run in a fraction of the time of the C++ program. Even in the first version, the Python program might use smarter algorithms -- due to the lower cognitive overhead of Python, the programmer has more cycles left to think about the application at hand. And long before the C++ version is ready, the hot spots of the Python version might have seen multiple rounds of optimization... > Although Python has a few methods common among strings, lists, and > tuples, any code that uses a special string method (e.g. split) wants > the string to be statically typed: you're not going to be using that > code for lists, tuples, ints, floats, files, etc. > > I bet there's nobody who has used Python for more than a month that > hasn't used a string method. Moral of the story: even those who claim > to do a lot of generic programming don't do it 100.0% of the time, so > even they can benefit from a little static typing. Except for the little difference between "" and u"". -- Christian Tanzer tanzer at swing.co.at Glasauergasse 32 Tel: +43 1 876 62 36 A-1130 Vienna, Austria Fax: +43 1 877 66 92 From quinn at retch.ugcs.caltech.edu Mon Aug 6 20:16:12 2001 From: quinn at retch.ugcs.caltech.edu (Quinn Dunkan) Date: 7 Aug 2001 00:16:12 GMT Subject: Clearing The Interactive Python Environment References: <8beb91f5.0108061409.49f480e8@posting.google.com> Message-ID: On 6 Aug 2001 15:09:07 -0700, Ben C wrote: >Hi, > >Sorry to bother the group with such a trivial Q but for some reason I >can not find an answer to this in the docs ... how does one 'clear' >the Python environment .... so all loaded modules and variables are >freed? (ie return the Python environment back to its initial state at >start up) I assumed it would have been in the sys module? The command is actually in the os module: os.execvp('python', ('python',)) It would be difficult to reset the system "live". You'd have to unload all the modules (remove them out of the namespace, and also remove their sys.modules entries). Then you'd have to clear out the rest of the namespace, except things like __builtins__ and None (you want to keep __builtins__ so you don't lose access to __import__), and manually import the modules the toplevel automatically imports when it starts (such as site and exceptions (well, not exceptions any more, I guess)). And probably a bunch of other things I forgot. From michael at stroeder.com Sun Aug 19 08:07:03 2001 From: michael at stroeder.com (Michael =?iso-8859-1?Q?Str=F6der?=) Date: Sun, 19 Aug 2001 14:07:03 +0200 Subject: Python CGI and multiple forms on a web page References: Message-ID: <3B7FABE7.565A6E77@stroeder.com> Ignacio Vazquez-Abrams wrote: > > Only the data in the submitted form is sent to the server. The other forms may > as well not exist. > The long answer: > I dug around in the W3C's info about HTML, and although the above is implied, > it's never spelled out explicitly. Take a look if you want: > http://www.w3.org/TR/html4/interact/forms.html#h17-13. >From the examples there I can't imagine how data from several different forms, say
..
..
, should ever be mixed. Ciao, Michael. From aleax at aleax.it Thu Aug 23 09:52:49 2001 From: aleax at aleax.it (Alex Martelli) Date: Thu, 23 Aug 2001 15:52:49 +0200 Subject: Newbie Question About Python References: <9ljge2523oi@enews2.newsguy.com> <9ll45901ib6@enews2.newsguy.com> <3B84C21B.5080@yahoo.com> Message-ID: <9m31sd0279a@enews4.newsguy.com> "Fumari" wrote in message news:3B84C21B.5080 at yahoo.com... > Ive been starting to learn Python by looking over some tuts linked from > the offical site. Now it seems to me Python is like perl as in the > system must have perl installed in order to run the program? is this > correct, in python you right out the code then command line it? Is > there a way to make an exe file? Sure, although of course it's quite an advanced task (I would never suggest a newbie to attempt it!-), see http://starship.python.net/crew/theller/py2exe/ for example. Python has a wonderful file of Frequently Asked Question (FAQ), by the way, and this is definitely one of them. See e.g. http://www.python.org/cgi-bin/faqw.py?req=show&file=faq04.028.htp for your specific question, and http://www.python.org/cgi-bin/faqw.py?req=all to get the whole FAQ file to read on your machine. Alex From sholden at holdenweb.com Mon Aug 6 13:16:37 2001 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 6 Aug 2001 13:16:37 -0400 Subject: Loaded module list and attributes References: Message-ID: "Dale Strickland-Clark" wrote in message news:o2mamt4qtis8r77maqnsmjg7h193aa80t4 at 4ax.com... > How do I itterate through all the loaded modules and find the name of the module and a value of a > local attribute (__version__ in this case)? > > I'm writing a small debugging routine and Python internals are still a bit of a black box to me. > > Thanks. > -- You need to be a little careful, as the modules table contains None for some modules and so won't have the attribute you are looking for. With that caveat, try something along the lines of this, which prints the length of each module's directory: >>> for n, md in sys.modules.items(): ... if md: ... print n, len(dir(md)) Obviously you can use hasattr() to check whether the particular module has the attribute you seek. regards Steve -- http://www.holdenweb.com/ From gReGlAnDrUm at earthlink.net Fri Aug 31 09:36:50 2001 From: gReGlAnDrUm at earthlink.net (Greg Landrum) Date: Fri, 31 Aug 2001 06:36:50 -0700 Subject: debug Python interpreter work with the debug swig dll References: <97592a5.0108310521.3c226a62@posting.google.com> Message-ID: <9mo3n4$4r9$1@slb7.atl.mindspring.net> "Irina Kotlova" wrote in message news:97592a5.0108310521.3c226a62 at posting.google.com... > Hello All, > > Could anyone advise how to make debug Python interpreter "python_d" to > import the previously built dll with a module? The module is the > interface file "employee.i" with the simple C++ class inside. The dll > build procedure consists of swig generating wrappers for Python and > then compiling and linking of a class along with the wrappers. > One of the joys of developing under windows is that when you use python_d, *all* extension module DLLs used must be debug versions. This means they all have to have _d appended to their names.[1] If you modify your project to produce employee_d.dll (or .pyd, or whatever) when building in Debug mode things should be okay. Well, at least until you try to import some other extension module that you don't have a debug version of. Note: if you are just interested in debugging your *own* code (not Python itself), you are perfectly safe just using standard python (not python_d). You can set a breakpoint in your code and have MSVC invoke python on some script which calls the relevant methods and everything will work fine. -greg [1] My initial experience with this a couple of years ago caused me to curse the names of the python-powers-that-be quite loudly until Mark Hammond calmly explained to me why it was required. I don't really remember his explanation, but it must have been good because my acceptance continues to this day. From boud at rempt.xs4all.nl Wed Aug 29 15:42:51 2001 From: boud at rempt.xs4all.nl (Boudewijn Rempt) Date: 29 Aug 2001 19:42:51 GMT Subject: [PyQt] Dropping on ListView References: <9mis87$fkb$1@news.netcologne.de> Message-ID: <9mjgjr$o2u$1@news1.xs4all.nl> Toralf Wittner wrote: > Hello world, > consider the following code fragment that is supposed to print the > pointer to the QListViewItem a text is dropped on. Unfortunatly it > doesn't work. I used the function 'QListViewItem* itemAt(const QPoint & > screenPos)' that should return the QListViewItem, but it just doesn't do it. > Maybe someone is able to tell me what's wrong here and how I could master > this problem. Thanks for any comments! Well, first of all, it's really the QListView that should accept the drops, not the main widget - you can just as easily use a QListView as a main widget, so I moved the dropEvent code to the QListView. Then, the header takes up some space, too. You need to subtract the height of the header from the drop location. Below is some code that works (only because it rather messes about to generate drop events, it'll segfault nine times out of ten - never mind about that). #!/usr/bin/env python from sys import argv from qt import * class DropDemo(QListView): def __init__(self,parent=None,name=None): QListView.__init__(self,parent,name) self.setAcceptDrops(1) self.setGeometry(10,10,100,60) self.addColumn("Column 1") self.i = QListViewItem(self, "Hello") self.ii = QListViewItem(self, "Hello 2") print "header", self.header().height() r = self.itemRect(self.i) print self.i, r.x(), r.y(), r.x() + r.width(), r.y() + r.height() r = self.itemRect(self.ii) print self.ii, r.x(), r.y(), r.x() + r.width(), r.y() + r.height() def dragEnterEvent(self, event): event.accept(QTextDrag.canDecode(event)) def dropEvent(self, event): text = QString() print event.pos().x(), event.pos().y()- self.header().height() pos = QPoint(event.pos().x(), event.pos().y() - self.header().height()) item = self.itemAt(pos) print item def mouseMoveEvent(self, event): self.startDrag() def startDrag(self): d = QTextDrag("blabla",self) # keep a reference to d d.dragCopy() if __name__ == '__main__': a = QApplication(argv) w = DropDemo() w.setCaption("Drag and Drop Test") w.resize(120,80) a.setMainWidget(w) w.show() a.exec_loop() -- Boudewijn Rempt | http://www.valdyas.org From thecalm at NOSPAM.btinternet.com Fri Aug 24 15:17:22 2001 From: thecalm at NOSPAM.btinternet.com (G. Willoughby) Date: Fri, 24 Aug 2001 20:17:22 +0100 Subject: Tkinter window displaying the time? Message-ID: <9m698a$t90$1@neptunium.btinternet.com> How can i display the time (continually updating) in title bar on windows (WinME), this is the code im using: from Tkinter import * from time import * currentTime=asctime(localtime(time())) timeZone="GMT: " hours=strftime("%I",localtime(time())) minutes=strftime("%M",localtime(time())) seconds=strftime("%S",localtime(time())) amPm=" "+strftime("%p",localtime(time())) seperator=":" root=Tk() root.iconify() root.title(timeZone+hours+seperator+minutes+amPm) root.mainloop() I thought of using a while 1: loop and providing a 1 second delay with sleep(1) to update the title but this don't seem to be working, any ideas??? G. Willoughby From phr-n2001 at nightsong.com Mon Aug 27 08:33:59 2001 From: phr-n2001 at nightsong.com (Paul Rubin) Date: 27 Aug 2001 05:33:59 -0700 Subject: S/MIME keys (was: What Are Some Good Projects For Novices?) References: <3B7FF0F9.9567B635@stroeder.com> <68562b94.0108220938.4939935b@posting.google.com> <7xd75ovsbk.fsf@ruckus.brouhaha.com> <68562b94.0108221909.2a794b85@posting.google.com> <7x66be2vk9.fsf@ruckus.brouhaha.com> <3B890102.1A772D0E@stroeder.com> Message-ID: <7xzo8l7kco.fsf@ruckus.brouhaha.com> Michael Str?der writes: > > The downside of CRL checking is it means every single one of your > > secure site visits gets reported to the CA. > > Nonsens. Learn that CRL means Certificate Revocation List before > spreading fud. Browser CRL checking (at least in MSIE 5.x) works by checking incoming certificates against a CRL at the CA, from what I understand. From nhodgson at bigpond.net.au Sun Aug 5 19:18:08 2001 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Sun, 05 Aug 2001 23:18:08 GMT Subject: Deposing Dictators References: <008A6F18.N22121@rsmi.com> <56fqmtcl20tg64aradbnarkj9kl514kg67@4ax.com> Message-ID: Stephen Horne: > I'd like to point out that the large number of 'viruses' I've been > e-mailed over the last couple of weeks won't affect my viewpoint. I > thought this was an innocent case of other people being infected at > first, but it's rather strange that when I reply to these e-mails to > warn people that their machines have been infected the addresses > mysteriously don't exist and the messages consistently bounce. This is not restricted to you. Large numbers of people have been receiving these probably due to the Sircam worm/virus. I've received some and I'm for the division change. On the net, general vandalism is a much more likely cause of attack than malice directed at an individual. > Fortunately, I'm not stupid enough to run untrusted attachments (no, > not *even* when they have two extensions to try to fool stupid people > into thinking they are documents), and even if I was I always have > up-to-date backups. And yes, I do understand a little Spanish, so > could the person who sent that mail please reconsider who the 'pajero > retrasado' is. That does look like Sircam which uses random English and Spanish messages. See http://www.zdnet.com/zdhelp/stories/main/0,5594,2776123,00.html Neil From konrad.hinsen at laposte.net Fri Aug 10 13:50:44 2001 From: konrad.hinsen at laposte.net (Konrad Hinsen) Date: 10 Aug 2001 10:50:44 -0700 Subject: Compiling Python 2.1.1 without 16-bit integer type Message-ID: <1bcfff91.0108100950.26c0d273@posting.google.com> I am trying to install Python 2.1.1 on a Cray T3E, whose C compiler doesn't have a 16-bit integer type (char is 1 byte, short is 4, everything else is 8). Compilation then stops with the message: Fatal Python error: Unicode configuration error: sizeof(Py_UNICODE) != 2 bytes I don't need Unicode support on the Cray, but can I disable it? If not, could I use a two-byte structure to represent wide characters? Any other suggestions? Konrad. From robin at jessikat.fsnet.co.uk Sun Aug 12 06:17:05 2001 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Sun, 12 Aug 2001 11:17:05 +0100 Subject: 2.1.1 global weirds References: <9l35hb03081@enews1.newsguy.com> <9l3f170adp@enews1.newsguy.com> <9l40tk01pfn@enews4.newsguy.com> Message-ID: In article <9l40tk01pfn at enews4.newsguy.com>, Alex Martelli writes >"Robin Becker" wrote in message >news:XhJ0PWAkCVd7Ewsg at jessikat.fsnet.co.uk... .... >> I suppose there is some overriding implementation issue, but it seems to > >Not really, more of a logical issue. When I "import floop", I expect >floop's module-level code to have executed fully by the time I get >to execute the next statement after the import, so I can use (e.g.) >all functions defined in floop by def statements, etc. When imports >are circular, this just can't be -- call it an "overriding implementation >issue" if you will, but you just can't meet the expected "module-level >code of imported module has fully executed by the time the statement >right after import executes" for BOTH modules that import each other. > >Circular imports (and circular dependencies in general) are a horror >and there's little any language can do to make things rosy and peachy. >Maybe they should be forbidden (i.e., I'm neutral on the thesis "any >allowance for circularity is a wart", as I said), but as long as they're >allowed I find Python's behavior in the matter quite reasonable. > Since circularity is already a potential danger (whether or not the main script is involved) I don't think it really adds to the clarity of the language that the 'main' script gets treated differently. For example if I have #a.py print 'in a' import b #b.py print 'in b' import c #c.py print 'in c' import a then running a.py produces C:\Tmp>a.py in a in b in c in a ie a.py is executed twice, if the circularity is not involving a (change c.py #c.py print 'in c' import b then running a.py doesn't execute any module twice C:\Tmp>a.py in a in b in c I consider that a bit strange since it seems that the special case of main script circularity is harder to detect/avoid; I believe that's onlyc caused by the special module name. >Alex -- Robin Becker From aleaxit at yahoo.com Thu Aug 2 07:11:38 2001 From: aleaxit at yahoo.com (Alex Martelli) Date: Thu, 2 Aug 2001 13:11:38 +0200 Subject: Typing system vs. Java References: <9k95fh0q0n@enews2.newsguy.com> Message-ID: <9kbchb02equ@enews1.newsguy.com> "Steve Holden" wrote in message news:f8Z97.12190$9i1.1016409 at e420r-atl1.usenetserver.com... ... > Suppose, in your mission-critical program, you use an int to hold a value > which should only ever be between 32 and 213. The only way you have to > exercise that level of semantic control is to declare a class, and test that > no assignments violate the required constraint (unless you are using a > Pascal derivative, which allowed that kind of thing quite nicely, or you are ...but handles it *at runtime* in the general case, of course (even though a few special-cases can be hoisted up to compile-time). Not to mention the peculiar implication of having INTEGER ranges as a built-in language feature, and REAL ranges nowhere to be seen -- isn't it just as important to be able to state that a REAL (in Pascal terms: float, in Python) variable x ensures A<=x using program proof techniques, which are of little use to the > mathematically-deficient). So run-time value testing is required even if you > force the compiler to do type testing. Yes, by far most interesting things can't be compile-time tested. > Type safety completely fails to live up to whatever promise it might have > unless programmers exercise adequate care to define types which do exactly > what they want. And most programmers are somewhat sloppy about that. And most languages (all that I know) just give programmers NO way to make the type-assertions that really matter ("this function is antisymmetric", and so on -- all requiring existential and/or universal quantifiers...). > and-i'm-no-better-than-the-rest-ly y'rs - steve > > PS: Alex, I'm sorry about the "if type()..."s! You're forgiven, Steve, as long as you undertake to sin no more...!-) Alex From aleax at aleax.it Thu Aug 30 06:20:18 2001 From: aleax at aleax.it (Alex Martelli) Date: Thu, 30 Aug 2001 12:20:18 +0200 Subject: Hello people. I have some questions References: <3B8CF936.4E20B7E8@student.gu.edu.au> Message-ID: <9ml41301p5t@enews1.newsguy.com> "jeroen paul goudsmit" wrote in message news:Ak9j7.72$Cz3.594 at pollux.casema.net... > Thank you all so much. I'll just go to www.python.org to download it all. > > (my pc is: os - Windows ME (it sucks!) Alas, yes, it does. I don't go in for Microsoft-bashing, and I find Win98 somewhat usable (not stable, sigh, but, oh well), and NT4 in the latest SP more than usable, but ME is definitely the pits, and I'm not too convinced about /2000 either. If you have some diskspace to spare, you might want to look into http://www.winlinux.net/2001/ (there are other excellent Linux versions designed to fit in well with Microsoft OS's, but AFAIK Winlinux/2001 is the only one that specifically supports ME). Python runs just as well on Win/* systems as on Linux, BSD, &c ones, but it cannot fully compensate for lack of underlying OS quality -- and Unix-like OS's are just heads and shoulders above MS's offers in the /95/98/ME line. Winlinux won't give you the FULL potential benefits of Linux -- it's designed so that you don't have to repartition your disk, etc, so it shares the weak FAT-based filesystem common to those MS OS's -- a Linux running on its own filesystem (particularly on its own partitions) would enhance your box by much more, BUT you wouldn't be moving so smoothly between the Win side (where you presumably have some applications you want to keep using) and the Linux side (where there are zillions of excellent free applications, and things in general run so much better). > processor - AMD duron 800 mhz (sucks too) No way -- it's a great little chip. No Athlon, sure, but it still beats the pants off any (BAH) Celeron and most Pentiums too. Depending on your motherboard/BIOS details, the stepping level of your Duron chip, how good are your power supply, your RAM, and particularly your cooling-system, you may well be able to overclock your machine and squeeze another 10% or 20% of raw CPU performance from it, by the way. Right now, as my home-LAN's router/firewall/gateway/proxybox, I'm setting up an old Pentium-90, 64MB-RAM machine (with Linux, so far, though I _am_ looking hard at OpenBSD, for that sense of total security it gives:-), but I'm also hungrily eyeing a special offer at my local supermarket -- US$500 for a Duron-900, 128M RAM, 20G IDE disk, fast CDROM, decent monitor/video/sound/&c (which I don't need for its job, though), *and a PCI bus* (rather than the bad old ISA in my old box) so I could mount 2 or 3 cheap ethernet cards without hassles. This way I could run a decently configured Squid and other 'heavy' proxies right on the box... (not really consistent with maximum-security ideas, but...). > RAM - 128 (getting 128 extra next saturday...) The more the merrier, *as long as* your OS doesn't get its knickers in a twist the way /95/98/ME sometimes do. Unix-like OS's are particularly good at exploiting whatever amount of RAM you have, and Win NT and 2000 not too bad at it, but the cheaper/home-oriented MS OS's aren't quite as clever about it. > I'm 14 years old and program only form the fun. Programming is the most fun-filled activity I've ever tried (and I've tried many, as my life's been quite a big longer than yours so far:-), *particularly* with Python. Overclocking and playing with Unix-ish OS's aren't too far behind, though!-) Alex From aleaxit at yahoo.com Wed Aug 1 07:15:17 2001 From: aleaxit at yahoo.com (Alex Martelli) Date: Wed, 1 Aug 2001 13:15:17 +0200 Subject: how can use mkdir to override the old one References: Message-ID: <9k8occ09ec@enews2.newsguy.com> "sdf" wrote in message news:mailman.996651362.9838.python-list at python.org... > I use mkdir('doc'),but this directory is exists,so it throw an err. > how can force to do this No operating system that I know has the concept of "overriding" an existing directory. If the directory that already exists is good, just catch the OSError that mkdir raises with a try/except. If you want to rename the existing directory then create a new one of the same name, do so. And so on, and so forth; your description and implication of your desires and problems is far too short and unclear for me to be of any more help. Alex From ullrich at math.okstate.edu Wed Aug 8 09:39:48 2001 From: ullrich at math.okstate.edu (David C. Ullrich) Date: Wed, 08 Aug 2001 13:39:48 GMT Subject: (in)exactness of complex numbers References: <3b62cc78.3396597@nntp.sprynet.com> <3B676D3A.E436943A@cosc.canterbury.ac.nz> <3b6803bd.349341@nntp.sprynet.com> <3b688808.1019964571@wa.news.verio.net> <3b69521b.850594@nntp.sprynet.com> <3b6ea347.838398@nntp.sprynet.com> Message-ID: <3b71404b.1075769@nntp.sprynet.com> On Wed, 8 Aug 2001 08:46:17 +0000 (UTC), Michael Abbott wrote: >ullrich at math.okstate.edu (David C. Ullrich) wrote in >news:3b6ea347.838398 at nntp.sprynet.com: > >> On Mon, 6 Aug 2001 07:18:56 +0000 (UTC), Michael Abbott >> wrote: >> >> Why "probably": Of course it's impossible to use the mathematical >> R[X]/(X^2+1) literally; the elements are equivalence classes of >> polynomials, in particular a complex number is an infinite set >> of polynomials, and hence would take too much storage space. > >No, no, it's not impossible at all. You simply use one representative at a >time to represent a value, but use the relation when you need to decide >whether or not two values are equal. Of course. I _said_ that. You _quote_ part of where I said that below. (Doesn't matter, though - we have a special diss-pensation for off-topic posts. Um, ...) >So, if we want to represent S/R where S is a set and R is an equivalence >relation on S then we simply use elements of S, but use R to implement the >equality test. > >Obviously, if there's a canonical choice of a representative, then we can >just use that and not take time to compute R. > >> Here there _is_ a natural choice of one polynomial to use >> from each equivalence class, but if you use that one your >> complex numbers have become precisely pairs of reals. > >Quite so. > David C. Ullrich From phr-n2001 at nightsong.com Thu Aug 23 04:34:08 2001 From: phr-n2001 at nightsong.com (Paul Rubin) Date: 23 Aug 2001 01:34:08 -0700 Subject: Reference counting garbage collection References: <7xlmkbfr8d.fsf@ruckus.brouhaha.com> <2759044.iTtaCxCBeP@lunix.schabi.de> Message-ID: <7xae0ri39b.fsf@ruckus.brouhaha.com> Markus Schaber writes: > > I guess that might be the case, at least with the current body of > > Python programs. I'm thinking of Python's implementation in terms of > > whether it's suitable for large, long-running programs, and it's > > not clear whether anyone really writes those in Python. > > Zope comes in my mind... Yes, Zope is probably a good example. I'm told it's slow ;). I'd like to get around to playing with it sometime though. > Maybe your docs describe Python 1.5 (which is still the default python > for debian, e. G.), but today, python 2.1.1 is stable and 2.2.X is > cutting edge :-) I think it was the 2.1 docs I was looking in, that said cyclic structures weren't gc'd. Maybe I missed something, or maybe it needs an update. From phr-n2001 at nightsong.com Fri Aug 31 13:31:25 2001 From: phr-n2001 at nightsong.com (Paul Rubin) Date: 31 Aug 2001 10:31:25 -0700 Subject: Hello people. I have some questions References: <9mo3k6030th@enews2.newsguy.com> Message-ID: <7xbskwnnki.fsf@ruckus.brouhaha.com> "Alex Martelli" writes: > The doubts come mainly from Python considerations - it's very easy > to drive/automate Microsoft Office via Python, but I still haven't > managed to do the same for StarOffice; if it does have COM at all, > it's a strange object model, and I can't find good docs, examples, > etc. Admittedly I haven't looked very deeply. But maybe they're > not COM- centric *because* they're portable... it's easier for MS > (they do have COM on the Mac too, although I think it's not > available to 3rd parties). There's a faction (Gnome) trying to automate GNU/Linux desktop apps with CORBA, which is like COM only fancier. I don't know of any attempts yet to gnomify Star Office though. >Maybe I should look into the Java (Jython) side of things instead. That would be going to the dark side. From peter at engcorp.com Tue Aug 14 08:35:13 2001 From: peter at engcorp.com (Peter Hansen) Date: Tue, 14 Aug 2001 08:35:13 -0400 Subject: Reading Tapes References: <9l855u$bba$1@talia.mad.ttd.net> <3B789CC6.2FD7FFB5@engcorp.com> <3b78b4b2@news.actrix.gen.nz> Message-ID: <3B791B01.6E694928@engcorp.com> Mark Rowe wrote: > > Windows NT: You can use the CreateFile function to open a disk drive or a > partition on a disk drive. The function returns a handle to the disk device; > that handle can be used with the DeviceIOControl function. The following > requirements must be met in order for such a call to succeed: > > The lpFileName string should be of the form \\.\PHYSICALDRIVEx to open the > hard disk x. That explains part of the situation. :) Live and learn. But I still wonder whether any of this applies to a TAPE drive under NT. I wonder whether you've answered the original question, however, with the part about "The caller must have administrative privileges for the operation to succeed on a hard disk drive." ? -- ---------------------- Peter Hansen, P.Eng. peter at engcorp.com From tbryan at python.net Thu Aug 16 11:39:05 2001 From: tbryan at python.net (Tom Bryan) Date: Thu, 16 Aug 2001 20:39:05 +0500 Subject: PLEAC project References: <9lgqmj0ttb@enews4.newsguy.com> Message-ID: <9lhoo8$75h$1@nntp9.atl.mindspring.net> Alex Martelli wrote: > I dispute this, given FAQ number 6 at > http://pleac.sourceforge.net/pleac-faq.html > > It gives a Ruby example, but basically it boils down to: since > Perl automatically initializes unbound variables, and "it is > -very- important" that PLEAC snippets do just the same as the > Perl Cookbook snippets, then it's not acceptable to use the > various languages in the normal way -- presumably (not spelled > out, but what else could it mean?) *every* variable being used, > e.g. in Ruby or Python, needs a try/except (in Python's terms) > to simulate Perl's "convenient" 'auto-initialization'. That's now how I read that sentence. It seems to indicate that he needs the program to function properly. That is, you can't simply translate $a = $b || $c to Python's a = b or c That is, as in translating human language, capture the intent and style of a solution. That is, don't solve a completely different problem, and don't solve the problems in a completely different way, but don't do a word for word translation. Sounds worthwhile. For all of the Perl programmers, they can then compare the Perl solution to the Python solution when they're stuck in a "I know how to do this in Perl" situation, but they're trying to use Python. ---Tom From garth_grimm at hp.com Wed Aug 15 14:00:32 2001 From: garth_grimm at hp.com (Garth Grimm) Date: Wed, 15 Aug 2001 11:00:32 -0700 Subject: Check URL --> Simply? References: <3B7A6B92.B18EEE3E@engcorp.com> Message-ID: <9ledc0$111$1@web1.cup.hp.com> That's about the best solution possible. Unfortunately, there are some dynamic sites that actually trap what should be a 404, and instead return a valid 200 and a web page document. Broadvision being one notable culprit, which often is configured so that a request to a page that doesn't exist is responded to with the home page of the web site. As far as a human user is concerned, this is a dead link, but it's next to impossible to detect in programming code. You end up having to make customized solutions in this case. -- Garth "Andy McKay" wrote in message news:mailman.997892665.9674.python-list at python.org... > Just check the headers, this means you dont get the document, saving > bandwith and solving the 404 file problem (assuming the set the right > headers) > > from httplib import HTTP > from urlparse import urlparse > > def checkURL(url): > p = urlparse(url) > h = HTTP(p[1]) > h.putrequest('HEAD', p[2]) > h.endheaders() > if h.getreply()[0] == 200: return 1 > else: return 0 > > if __name__ == '__main__': > assert checkURL('http://slashdot.org') > assert not checkURL('http://slashdot.org/notadirectory') > > -- > Andy McKay > > From piercew at hushmail.com Mon Aug 20 08:14:41 2001 From: piercew at hushmail.com (Wayne) Date: 20 Aug 2001 05:14:41 -0700 Subject: Python COM local server as .exe possible? References: Message-ID: <9d848d5d.0108200414.44ff9a1c@posting.google.com> "Bill Bell" wrote in message news:... > Can someone tell if I can expect to do this conversion with py2exe, > freeze or another products of this kind? > > Thanks for your advice. ?? I don't know if I understood what you are trying to do, create an .exe from your .py COM server? I used Standalone.py when I need to make a .exe, it should work with COM and the win32 extensions. Standalone.py will create a directory called "dist_" which will contain all the files you need for your application. http://starship.python.net/crew/gmcm/distribute.html Wayne From BgPorter at NOartlogicSPAM.com Fri Aug 17 16:23:21 2001 From: BgPorter at NOartlogicSPAM.com (Brett g Porter) Date: Fri, 17 Aug 2001 20:23:21 GMT Subject: Automating UI tests (was Re: Art of Unit Testing) References: <3B7D29E0.602AF8BD@earthlink.net> Message-ID: ----- Original Message ----- From: "Joseph Andrew Knapka" Newsgroups: comp.lang.python Sent: Friday, August 17, 2001 2:33 PM Subject: Automating UI tests (was Re: Art of Unit Testing) > So that means I'd need to write code that actually drives > the Tk widgets "from outside", as it were, either by synthesizing > events somehow at the OS/window-system level, or by knowing > enough about the Tk internals to convince the widgets that they're > being clicked on, typed at, etc. And at that point it looks like > a lot more effort than it's worth. Depending on platform there may be tools that do exactly this -- Rational Visual Test and NuMega TestPartner on Windows come to mind. I've never looked for corresponding tools on other platforms... // Brett g Porter * Lead Engineer, Development Practices // BgPorter @ artlogic . com * http://www.artlogic.com // Art & Logic * Custom software solutions for hardware products // Windows * MacOS * Embedded Systems From mikael at isy.liu.se Wed Aug 15 08:17:30 2001 From: mikael at isy.liu.se (Mikael Olofsson) Date: Wed, 15 Aug 2001 14:17:30 +0200 (MET DST) Subject: eof? In-Reply-To: <3B7A4C7C.CF1A3C3A@wohnheim.fh-wedel.de> Message-ID: On 15-Aug-2001 Dietmar Lang wrote: > > for line in fh.xreadlines(): > > process(line) > > Is xreadlines something I missed or is it a misspelled readlines? > Because as far as I know readlines reads in the whole file into a list > containing the lines, which might not be so practical if the file is > waay big? That is exacly the situation that xreadlines is for. It does not read the whole file into memoryas readlines do, but serves the lines of the file one by one, with the same syntax as readlines. Compare this to range and xrange. Others can give a more detailed description. /Mikael ----------------------------------------------------------------------- E-Mail: Mikael Olofsson WWW: http://www.dtr.isy.liu.se/dtr/staff/mikael Phone: +46 - (0)13 - 28 1343 Telefax: +46 - (0)13 - 28 1339 Date: 15-Aug-2001 Time: 14:14:01 /"\ \ / ASCII Ribbon Campaign X Against HTML Mail / \ This message was sent by XF-Mail. ----------------------------------------------------------------------- Link?pings kammark?r: www.kammarkoren.com From root at rainerdeyke.com Mon Aug 13 00:52:38 2001 From: root at rainerdeyke.com (Rainer Deyke) Date: Mon, 13 Aug 2001 04:52:38 GMT Subject: Copy constructors References: Message-ID: "Glyph Lefkowitz" wrote in message news:mailman.997671441.2464.python-list at python.org... > Let me underscore this once, and put it in the terms I think of it in: > with these changes, you will be introducing the worst design error of C++ > into Python. Indeed, the _central_ problem with C++ is that it always > prefers efficiency over dynamism, even in its so-called "high level" > features. I strongly disagree here. Quite aside from the efficiency issue, C++'s lack of dynamism is a feature, not a bug. (This does not change the fact that C++ is an unholy mess.) Such a feature would not be appropriate for Python, however. -- Rainer Deyke (root at rainerdeyke.com) Shareware computer games - http://rainerdeyke.com "In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor From aleax at aleax.it Mon Aug 20 10:15:50 2001 From: aleax at aleax.it (Alex Martelli) Date: Mon, 20 Aug 2001 16:15:50 +0200 Subject: embed python in C++ References: <9ktmkt020cq@enews1.newsguy.com> Message-ID: <9lr62n11p83@enews4.newsguy.com> "wkuang" wrote in message news:Pine.GSO.4.21.0108101436070.18685-100000 at aludra.usc.edu... > Is there anyone know how to install boost.python. The website said most > boost libary are implemented entirely within their header files, but the > makefile for linux have libboost_python.a, so I assume boost.python is one > of the exception. Basically, I havenot been able to run a single example > successfully. Any idea? Thanks. > > I am using linux 7.1 with KCC 4.0e, gcc2.96 is kind of ok. Right. Go to boost_1_23_0\libs\python\build where you've unpacked the sources and you'll see a file named linux_gcc.mak. Run GNU make, specifying that file as the makefile, and off you go. Alex From johnroth at ameritech.net Sun Aug 26 22:38:31 2001 From: johnroth at ameritech.net (John Roth) Date: Sun, 26 Aug 2001 19:38:31 -0700 Subject: Question about indentation and bugs References: <3B85E13D.72427622@engcorp.com> <3B882E32.41643FEB@engcorp.com> Message-ID: "Peter Hansen" wrote in message news:3B882E32.41643FEB at engcorp.com... > Lines indented twelve characters > should have four spaces and a TAB (not three TABs). I presume you meant a tab and four spaces, no? According to your definition (which I snipped above), four spaces and a tab should result in an indent of 8, not 12. BTW - I agree with the definition of how tabs work - that's how mechanical typewriters and mechanical teletypes worked, after all. The full name is "tab stop," and that's exactly what they did - they put a little metal clip in the carriage mechanism. John Roth > > > ---------------------- > Peter Hansen, P.Eng. > peter at engcorp.com From tim.one at home.com Wed Aug 15 02:52:16 2001 From: tim.one at home.com (Tim Peters) Date: Wed, 15 Aug 2001 02:52:16 -0400 Subject: Dumb python questions In-Reply-To: <7xd75xlv86.fsf@ruckus.brouhaha.com> Message-ID: [Paul Rubin] > ... > 1) Suppose I have a complex number like a = 3+4j. How do I get the > real and imaginary parts separately? >>> x = 3+4j >>> x.real 3.0 >>> x.imag 4.0 >>> > 2) Is there a way I can tell if a value is of an integer type? >>> import types >>> isinstance(4, types.IntType) 1 >>> Etc. > 3) Are the complex math functions specified to have any particular > branch cuts? No. > If they're unspecified, what happens in the actual cmath > implementation? Study the actual cmath implementation -- that's the only docs there are. cmath wasn't written by a numeric expert, alas. > If they're unspecified, I'd like to propose that the Scheme/Common > Lisp conventions be adopted in a future version. While you're at it, propose that they don't suffer spurious overflow or underflow errors either . That is, cmath is the end result of what volunteers have made it, and indeed that's all it will ever become. Since C99 mandates most of the same functions, it may get a dramatic quality boost almost for free -- provided the C vendors all get around to taking C99 seriously (BTW, I haven't compared the C99 spec to CL's, but if they differ Python will almost certainly go with C99's, just because Python is coded in C and cmath volunteers are historically conspicuous by absence). From tdelaney at avaya.com Thu Aug 23 01:16:39 2001 From: tdelaney at avaya.com (Delaney, Timothy) Date: Thu, 23 Aug 2001 15:16:39 +1000 Subject: newbie question Message-ID: > Anyway, the issue is what is the future of jpython, and what > is its future > relative to JSP (and also relative to javascript, which is > also developing > into its own full language)? Also, what role should each > language play in a > design, if they are used together. I suggest looking on-line > for computer > magazine articles rather than relying on user's opinions > (including myself). > Try to find sources that aren't focused solely on java (such as 'java > world') or python (such as 'python world'?). No doubt jpython > will fill a > specific market niche just like java. However, I've seen many > companies go > belly up and I wonder about jpython. How can they compete > with an upcoming > powerhouse like JSP in the long term? Java will be very time > consuming to Methinks you have completely the wrong idea about Jython (note - the current version is called Jython - JPython is a trademark of CNRI). Jython is simply an implementation of the Python language running on the Java VM. As such it behaves the same as CPython in most ways (however, it uses the VM's garbage collection, and there are a few other differences). It is not intended to be a competitor to JSP, or anything else. It can be used quite happily in conjunction with those technologies however. I personally am using Jython right this instant to prototype a Swing application (well, and refreshing myself on Swing). I find it is a lot faster to code and easier to read the prototype in Python than in Java. For example, I don't need to worry about setting up my ActionListeners, etc ... import javax.swing as swing def func (event): print 'Hello, world!' panel = swing.JPanel() panel.add(swing.JButton('OK', actionPerformed=func)) and a proxy ActionListener is automatically set up which calls the specified func when an ActionEvent is received. The corresponding Java is along the lines of import javax.swing.*; import java.awt.event.*; class MyActionListener implements ActionListener { public void actionPerformed (ActionEvent event) { System.out.println("Hello, world!"); } } JPanel panel = new JPanel(); JButton button = new JButton('OK'); button.setActionListener(new MyActionListener()); and I'm pretty sure I've forgotten a throws clause. That's 5 useful lines to 8 (using .* imports in Java), and I don't have crufty braces breaking up the look of the code. In addition, I don't need to compile each Python file to a Java class before I can use it - leading to a faster prototype/test cycle. And I am guaranteed than any changes to other Python modules will be picked up on the next run - unlike Java where any changed files need to be recompiled - and it's likely that some will be missed if you compile with dependencies. Finally, I can compile all the Python code to Java .class files, package them up in a .jar, etc - just like I can do with Java code. When you look at it that way, you start to ask yourself why there's a need to code it in Java at all ... Tim Delaney From edcjones at erols.com Thu Aug 9 19:48:16 2001 From: edcjones at erols.com (Edward C. Jones) Date: Thu, 09 Aug 2001 19:48:16 -0400 Subject: Yet another Numeric Swig core dump problem Message-ID: <3B732140.7040609@erols.com> The following Python / SWIG / Numeric program dumps core. I use RedHat Linux on a PC. Python 2.1, Numeric 20.0.0, SWIG 1.1 build 883, gcc 2.96. The output looks like: > testdb.py called import_array L11 Segmentation fault (core dumped) >KLTfeatures.KLTSelectGoodFeatures() > The program files are: ----------- testdb.py: #! /usr/bin/python import Numeric, KLTfeatures KLTfeatures.KLTSelectGoodFeatures() ----------- KLTfeatures.h: #include "Python.h" #include "/usr/include/python2.1/Numeric/arrayobject.h" void KLTSelectGoodFeatures(void); ----------- KLTfeatures.i: %module KLTfeatures %{ #include "KLTfeatures.h" %} %init %{ import_array(); printf("called import_array\n"); %} void KLTSelectGoodFeatures(void); ----------- KLTfeaturesmodule.c: #include "KLTfeatures.h" void KLTSelectGoodFeatures() { PyArrayObject *pao; int dims[2]; dims[0] = 100; dims[1] = 200; printf("L11\n"); pao = (PyArrayObject*) PyArray_FromDims(2, dims, PyArray_UBYTE); printf("L17\n"); Py_DECREF(pao); } ---------- How to compile: swig -python KLTfeatures.i gcc -c -Wall KLTfeaturesmodule.c KLTfeatures_wrap.c -I/usr/include/python2.1 ld -shared KLTfeaturesmodule.o KLTfeatures_wrap.o -o KLTfeatures.so From doug_bartholomew99 at yahoo.com Wed Aug 8 22:42:25 2001 From: doug_bartholomew99 at yahoo.com (doug) Date: 8 Aug 2001 19:42:25 -0700 Subject: New Type in Extension Module Not Accessing PyNumberMethods??? Message-ID: im trying to write a python extension type which i am basically modeling on xxmodule.c that comes with the source. however, for the life of me, i cannot get the numeric operations to work (just simple addition and subtraction here) and i cannot see what im doing wrong. Isnt the following what one has to do to get numeric operations??? ***BEGIN CODE SNIPPET*** static PyObject* MyObject_add(MyObject *Self, PyObject *Arg) { long c_long; MyObject* rv; if ( !PyInt_Check(Arg) ) { PyErr_SetString(PyExc_TypeError, "Should add a number to MyObject"); return NULL; } c_long = PyInt_AS_LONG(Arg); rv = newMyObject(Self->my_num + c_long); if ( rv == NULL ) return NULL; return (PyObject *)rv; } static PyObject* MyObject_sub(MyObject *Self, PyObject *Arg) { MyObject* rv = NULL; if ( PyInt_Check(Arg) ) { long c_long = PyInt_AS_LONG(Arg); rv = newMyObject(Self->my_num - c_long); } else if ( MyObject_Check(Arg) ) { rv = newMyObject(Self->my_num - ((MyObject*)Arg)->my_num); } else { PyErr_SetString(PyExc_TypeError, "Only a number or another MyObject can be subtracted from a MyObject"); return NULL; } if ( rv == NULL ) return NULL; return (PyObject *)rv; } static PyNumberMethods MyObject_as_number = { (binaryfunc)MyObject_add, (binaryfunc)MyObject_sub, (binaryfunc)0, (binaryfunc)0, (binaryfunc)0, (binaryfunc)0, (ternaryfunc)0, (unaryfunc)0, (unaryfunc)0, (unaryfunc)0, (inquiry)0, (unaryfunc)0, (binaryfunc)0, (binaryfunc)0, (binaryfunc)0, (binaryfunc)0, (binaryfunc)0, 0, (unaryfunc)0, (unaryfunc)0, (unaryfunc)0, (unaryfunc)0, (unaryfunc)0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static PyTypeObject MyObject_Type = { PyObject_HEAD_INIT(NULL) 0, "MyObject", sizeof(MyObject), 0, (destructor) MyObject_dealloc, (printfunc) MyObject_print, (getattrfunc) MyObject_getattr, (setattrfunc) MyObject_setattr, (cmpfunc) MyObject_compare, (reprfunc) 0, &MyObject_as_number, 0, 0, (hashfunc) 0, (ternaryfunc) 0, (reprfunc) 0, }; ***END CODE SNIPPET*** And in my python session i get the following error: C:\test>python ActivePython 2.1.1, build 212 (ActiveState) Python 2.1.1 (#20, Jul 26 2001, 11:38:51) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information. >>> from MyObject_Module import * >>> foo = MyObject(9) >>> print foo 9 >>> foo + 8 Traceback (most recent call last): File "", line 1, in ? TypeError: unsupported operand types for + >>> im posting the full module (MyObject_Module.c) below. Any help is appreciated greatly. Thanks very much, Doug doug_bartholomew99 at yahoo.com ***********MyObject_Module.c*********** #include "Python.h" static PyObject *ErrorObject; typedef struct { PyObject_HEAD long my_num; PyObject *x_attr; } MyObject; staticforward PyTypeObject MyObject_Type; #define MyObject_Check(v) ((v)->ob_type == &MyObject_Type) static MyObject * newMyObject(const long arg_int) { MyObject *Self; Self = PyObject_New(MyObject, &MyObject_Type); if (Self == NULL) return NULL; Self->my_num = arg_int; Self->x_attr = NULL; return Self; } static void MyObject_dealloc(MyObject *Self) { Py_XDECREF(Self->x_attr); PyObject_Del(Self); } static int MyObject_print(MyObject *Self, FILE *fp, int flags) /* flags -- not used but required by interface */ { flags; fprintf(fp, "%d", Self->my_num); return 0; } static PyObject * MyObject_demo(MyObject *Self, PyObject *Args) { if (!PyArg_ParseTuple(Args, ":demo")) return NULL; Py_INCREF(Py_None); return Py_None; } static PyMethodDef MyObject_methods[] = { {"demo", (PyCFunction)MyObject_demo, METH_VARARGS}, {NULL, NULL} }; static PyObject * MyObject_getattr(MyObject *self, char *name) { if (self->x_attr != NULL) { PyObject *v = PyDict_GetItemString(self->x_attr, name); if (v != NULL) { Py_INCREF(v); return v; } } return Py_FindMethod(MyObject_methods, (PyObject *)self, name); } static int MyObject_setattr(MyObject *self, char *name, PyObject *v) { if (self->x_attr == NULL) { self->x_attr = PyDict_New(); if (self->x_attr == NULL) return -1; } if (v == NULL) { int rv = PyDict_DelItemString(self->x_attr, name); if (rv < 0) PyErr_SetString(PyExc_AttributeError, "delete non-existing attribute"); return rv; } else return PyDict_SetItemString(self->x_attr, name, v); } static int MyObject_compare(MyObject *Right, MyObject *Left) { return ( Right->my_num < Left->my_num ) ? -1 : (( Right->my_num > Left->my_num ) ? +1 : 0); } static PyObject* MyObject_add(MyObject *Self, PyObject *Arg) { long c_long; MyObject* rv; if ( !PyInt_Check(Arg) ) { PyErr_SetString(PyExc_TypeError, "Should add a number to MyObject"); return NULL; } c_long = PyInt_AS_LONG(Arg); rv = newMyObject(Self->my_num + c_long); if ( rv == NULL ) return NULL; return (PyObject *)rv; } static PyObject* MyObject_sub(MyObject *Self, PyObject *Arg) { MyObject* rv = NULL; if ( PyInt_Check(Arg) ) { long c_long = PyInt_AS_LONG(Arg); rv = newMyObject(Self->my_num - c_long); } else if ( MyObject_Check(Arg) ) { rv = newMyObject(Self->my_num - ((MyObject*)Arg)->my_num); } else { PyErr_SetString(PyExc_TypeError, "Only a number or another MyObject can be subtracted from a MyObject"); return NULL; } if ( rv == NULL ) return NULL; return (PyObject *)rv; } static PyNumberMethods MyObject_as_number = { (binaryfunc)MyObject_add, (binaryfunc)MyObject_sub, (binaryfunc)0, (binaryfunc)0, (binaryfunc)0, (binaryfunc)0, (ternaryfunc)0, (unaryfunc)0, (unaryfunc)0, (unaryfunc)0, (inquiry)0, (unaryfunc)0, (binaryfunc)0, (binaryfunc)0, (binaryfunc)0, (binaryfunc)0, (binaryfunc)0, 0, (unaryfunc)0, (unaryfunc)0, (unaryfunc)0, (unaryfunc)0, (unaryfunc)0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static PyTypeObject MyObject_Type = { PyObject_HEAD_INIT(NULL) 0, "MyObject", sizeof(MyObject), 0, (destructor) MyObject_dealloc, (printfunc) MyObject_print, (getattrfunc) MyObject_getattr, (setattrfunc) MyObject_setattr, (cmpfunc) MyObject_compare, (reprfunc) 0, &MyObject_as_number, 0, 0, (hashfunc) 0, (ternaryfunc) 0, (reprfunc) 0, }; static PyObject * MyObject_Module_new(PyObject *Self, PyObject *Args) { MyObject *rv; long arg_long; if ( PyArg_ParseTuple(Args, "l:MyObject", &arg_long) ) rv = newMyObject(arg_long); else if ( PyArg_ParseTuple(Args, ":MyObject") ) { PyErr_Clear(); rv = newMyObject(0); } else return NULL; if ( rv == NULL ) return NULL; return (PyObject *)rv; } static PyMethodDef MyObject_Module_methods[] = { {"MyObject", MyObject_Module_new, METH_VARARGS}, {NULL, NULL} /* sentinel */ }; #ifdef __cplusplus extern "C" #endif __declspec(dllexport) void initMyObject_Module(void) { PyObject *m, *d; MyObject_Type.ob_type = &PyType_Type; m = Py_InitModule("MyObject_Module", MyObject_Module_methods); d = PyModule_GetDict(m); ErrorObject = PyErr_NewException("MyObject_Module.error", NULL, NULL); PyDict_SetItemString(d, "error", ErrorObject); } From jeff at ccvcorp.com Thu Aug 23 12:45:57 2001 From: jeff at ccvcorp.com (Jeff Shannon) Date: Thu, 23 Aug 2001 09:45:57 -0700 Subject: base classes References: <9m04of$csk$1@news2.ipartners.pl> <9m0ccg$hqp$1@news2.ipartners.pl> <9m2ct9$1hej$1@news2.ipartners.pl> Message-ID: <3B853345.61AF64F1@ccvcorp.com> Pete wrote: > Oh, the problem was if I use two classes and the first is a standard > python's class and second is written by me I need to use distinct members in > my class. Otherwise some strange things may occur... This is definately true. It is most likely true for *every* language which allows multiple inheritance. I suppose you *could* do a really ugly workaround like: >>> class A: ... def foo(self): ... print "foo!" ... >>> class B: ... def foo(self): ... print "bar!" ... >>> class C(A,B): ... pass ... >>> c = C() >>> B.foo(c) bar! >>> A.foo(c) foo! But then, the whole point of inheritance is that you shouldn't have to care about whether a method is in a base class, or *which* base class it's in. Jeff Shannon Technician/Programmer Credit International From cjw at sympatico.ca Tue Aug 14 15:30:57 2001 From: cjw at sympatico.ca (Colin J. Williams) Date: Tue, 14 Aug 2001 15:30:57 -0400 Subject: Deposing Dictactors References: <96lintosv5j966334hj45tpeu94iot3m0o@4ax.com> Message-ID: <3B797C71.A8FD3B80@sympatico.ca> An HTML attachment was scrubbed... URL: From jkn at nicorp.f9.co.uk Thu Aug 23 03:58:50 2001 From: jkn at nicorp.f9.co.uk (Jon Nicoll) Date: 23 Aug 2001 00:58:50 -0700 Subject: low level device control References: <3B83C1A8.4010608@telusplanet.net> Message-ID: <8351bb33.0108222358.59e32b3b@posting.google.com> Hi Greg The answers to your questions depend on what Hardware and Operating System you are using. - are you saying that you will have a serial device to be able to read PIN1/PIN2 and to write to PIN3/PIN4? from your description of the problem it doesn't sound like a match for a 'standard' RS-232 serial port (ie. COM1:, COM2 etc. on the PC), but you will know more about this than I. If this is right, then your problem becomes - how to control a serial device (COM port) from Python. Then if you are running under Windows, look at Mark Hammond's Win32Comm stuff (built into he ActiveState distribution of Python). There is also an alternative 'Serial' class - look in the Vaults of Parnassus website. Under Unix ... I'm not so clued up - sorry. If you can't use the standard COM ports, then you may need to write a custom driver/interface to whatever Serial device you are using. Again, more specifics would be useful. HTH jon Nicoll From aleaxit at yahoo.com Fri Aug 17 11:24:51 2001 From: aleaxit at yahoo.com (Alex Martelli) Date: Fri, 17 Aug 2001 17:24:51 +0200 Subject: __del__ ignores exception in 2.1? References: <3B7D186A.A3E3FB9E@iit.demokritos.gr> Message-ID: <9ljgdr323oi@enews2.newsguy.com> "Vassilis Virvilis" wrote in message news:3B7D186A.A3E3FB9E at iit.demokritos.gr... ... > Exception exceptions.NameError: "global name 'badsnake' is not defined" in > ignored > It continues > > Why? Shouldn't the exception make python abort? Python prefers to ignores exceptions (possibly with a warning) in cases where they couldn't be handled, such as in __del__ special-methods, rather than aborting (as is more typical in C++, e.g. when an exception is raised while another one is propagating). This isn't new in 2.1 -- it's been that way for quite a while. Alex From db3l at fitlinxx.com Thu Aug 23 17:22:27 2001 From: db3l at fitlinxx.com (David Bolen) Date: 23 Aug 2001 17:22:27 -0400 Subject: sys._exit() References: <998544414.810105@yabetcha.drizzle.com> Message-ID: Donn Cave writes: > Well, note that the fork runs in a separate address space and can't > modify the parent's state. No, but system resources like file handles are just copied literally into the client's address space (not 'dup'd). So if the client were to close a common handle, the parent's handle would then become invalid. (Thus the typical create pipe, fork, and then have parent/child carefully close opposite ends of the pipe handles before using the other set of handles). -- -- 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 rnd at onego.ru Sat Aug 4 06:34:09 2001 From: rnd at onego.ru (Roman Suzi) Date: Sat, 4 Aug 2001 14:34:09 +0400 (MSD) Subject: Q: Code Review Checklist? In-Reply-To: Message-ID: On Sat, 4 Aug 2001, Albert Brandl wrote: >Roman Suzi wrote: > >> O! Just put motivating subject and you will have a long-long checklist. If >> you just cite some items here from the original - you will get more in >> return ;-) > >Have a look at http://cs.wwc.edu/~aabyan/435/PSP/CodeReviewGuide.html >There you find the checklist used in Humphrey's book "A Discipline for >Software Engineering". Yes, already found that link. PSP seem to be some kind of personal SEI CMM. AFAIK, there is only one or two companies which are toplevel in CMM. IIRC, Motorola is/was one of them. >Some items are irrelevant - in Python, you don't need to check whether >pointers are initialized NULL, only deleted after new and always deleted >after use if new. > >OTOH, the checklist requires you to e.g. test your logic operators: >- Verify the proper user of ==, =, || etc >- check every logic function for proper () >This would have caught your "<" vs ">" error. No more than the statement: check your program logic. >> Personally, I think that Python programmers do their checks while they >> write code, because in Python you do not write that many LOC. > >I'm not sure what you mean. Do you suggest that Python is only >used for tasks so simple that it's impossible to get it wrong? Or >does "not that many LOC" mean that you split up your code in >many little methods that can easily be verified? I mean that in higher-level language errors tend to be logic ones, because parts are larger and there is no need to worry about lists, hashes or to reimplement them (which adds errors). Also Python program of 100 lines is capable of doing what C program does in 500 Lines Of Code. Some authors argue that even best programmers make 1 error per 7-10 LOC (I can't believe that, though. Maybe KLOC was meant). Maybe I program too slowly, but I do not make so many errors. Those error with "<" vs. ">=" was exception which is why I remembered it ;-) Usually my Python programs run first time correctly even syntactically. (This still amazes me). >> There is >> Python Style Guide which will teach you how to write Pythonic Python >> programs. Python idioms also help to keep programs readable. Applying >> PyChecker could find some problems... > >In the PSP, there is a item called Standards: "Ensure that the code >conforms to the coding standards". You are right: The Python Style >Guide is a good starting point to define the standards. > >As for PyChecker: I've been using this tool for some time and like it very >much. Unfortunately, automated tools can only detect certain classes of >errors. There is an interesting technique to estimate how many errors the program has: add 10 errors to somebody's program and let it be debugged. If he found 15 errors of which 5 were artificial, then it is possible to estimate that there are other 15 errors still there. >A general checklist should contain all kinds of error that are specific to >Python and hard to find. It takes e.g. much time to realize that two >variables reference the same object. It would be interesting to know >if such a list is already "out there", but the response has not yet been >overwhelming... > >> So, I can't think of any checklist to review my own code... > >Building a personal checklist is relatively easy: The next time you sit >down and start the interpreter, note every error you stumble across. >You'll soon see some patterns emerge, .e.g. spelling errors, infinite >loops, off-by-one-errors, no "self" variable in the head of a function, >logic errors, etc. - at least that's what I've experienced. Extract these >patterns into a checklist and correct all problems you find _before_ >you start the interpreter. But it is so much faster to let interpreter tell me syntactic errors and obvious errors first. Then more accurate program checking could start. Some parts of the program I even prefer to check by mathematical means. For example, proper tarification when different tariff intervals are crossed. The code is not large but it needed more than usual checks because of it's importance. Also, many errors occur when environment is not up to program's expectation. I had several such mishaps this year, because some parameters were changed without notice. > Best regards, > > Albert > Sincerely yours, Roman Suzi -- _/ Russia _/ Karelia _/ Petrozavodsk _/ rnd at onego.ru _/ _/ Saturday, August 04, 2001 _/ Powered by Linux RedHat 6.2 _/ _/ "Experience: a name everyone gives to his mistakes." _/ From jim.vickroy at noaa.gov Mon Aug 27 11:28:14 2001 From: jim.vickroy at noaa.gov (jim.vickroy) Date: Mon, 27 Aug 2001 09:28:14 -0600 Subject: MS Windows COM error - access denied References: <3B8A5D9B.D4F80131@noaa.gov> <3b8a607b.7966140@news.t-online.de> Message-ID: <3B8A670E.C38F139C@noaa.gov> Thanks for the suggestions. I tried dcomcnfg.exe, but that did not fix the "access denied" error; perhaps because I'm not using DCOM at this point. For the present, all this is happening on a single machine. As for security settings and access permissions, that sounds promising. I poked around a little in the Component Services interface under Administrative Tools, but I really do not know what I'm doing or even if this is the right place. Any suggestions on how I can come up to speed on these types of issues? Thanks again. Gerson Kurz wrote: > On Mon, 27 Aug 2001 08:47:55 -0600, "jim.vickroy" > wrote: > > > > >the following exception is raised: > > > > com_error: (-2147024891, 'Access is denied.', None, None) > > > >Any ideas what I'm doing wrong? > Have you started dcomcnfg.exe (its part of W2K) and played with the > security settings ? Like default access permissions and such. From aleaxit at yahoo.com Sun Aug 5 04:43:32 2001 From: aleaxit at yahoo.com (Alex Martelli) Date: Sun, 5 Aug 2001 10:43:32 +0200 Subject: Using Multiple Constructors References: <3b6b0d1e_1@news.chartertn.net> Message-ID: <9kj15i02gdm@enews4.newsguy.com> "Steve Holden" wrote in message news:GU_a7.11610$5j7.678446 at e420r-atl1.usenetserver.com... > "Alex" wrote in message > news:etdu1zoddw4.fsf at lola-granola.mit.edu... ... > > if type(initarg) == types.StringType: > > self.Constructor1(initarg) > > What were you saying last week about people who used this construct needing > to be stood up against the wall and shot (I'm paraphrasing a little here)? I think you may be confusing the Alex who writes from mit.edu with the Alex Martelli who writes from yahoo.com. Despite persistent rumors, we're really two distinct people, honest! That being said -- if there's a place anywhere for typetests, it's probably when trying to recode in Python an existing C++ or Java program that relies on function overloading by argument-types. Much in the same spirit as my "assign and test" cookbook recipe: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66061 you can't "natively" assign-and-test in Python, since = is not an operator, but Python's powerful enough to let you use 'alien' idioms with little conceptual overhead, in many cases. Of course, type tests should still be coded better than type(a)==type(b) (or even the preferable type(a) is type(b)...:-). At the very least, one would use isinstance -- at some point in the type/class unification story, isinstance may let you use subtypes of (e.g.) strings where equality or identity of typeobjects would still trip you up. Probably better is however a variation of 'accurate look-before-you-leap', see my recipe at: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52291 although, curiously, nobody was interested enough to rate it, even unfavourably, in the 4+ months it's been out there. It's admittedly rather a lot of work, but the point is, getting some sort of operational definition of what it means, for overloading purposes, for an argument to "BE-A" string (or whatever) by determining what operations the argument must support. The Pythonic way is not to overload by type: use factory functions rather than the bare constructor, and distinguish them by name. But sometimes such recoding is too vast, it takes you too far from the original (e.g.) C++ code that you're trying to recast into Python (for didactical purposes or whatever). In this case, SOME sorts of type tests may be more of a help than a hindrance -- but it's unlikely that type(a)==type(b) can ever qualify (maybe a lintlike utility could warn against those, suggesting at least isinstance as alternative:-). Alex From skip at pobox.com Thu Aug 23 09:28:30 2001 From: skip at pobox.com (Skip Montanaro) Date: Thu, 23 Aug 2001 08:28:30 -0500 Subject: Reference counting garbage collection In-Reply-To: <7xbsl7a167.fsf@ruckus.brouhaha.com> References: <7xbsl7a167.fsf@ruckus.brouhaha.com> Message-ID: <15237.1278.534015.958197@beluga.mojam.com> >> ain't-nothin'-obvious-about-gc-strategies-ly y'rs - tim Paul> That's for sure--there's a large literature of GC research that Paul> goes back for decades. It's not appropriate to ignore everything Paul> that's been tried. I don't think anything's been ignored. It's just that nothing made it into the language beyond the Neil's cyclical GC stuff. Skip From aleaxit at yahoo.com Thu Aug 16 16:39:59 2001 From: aleaxit at yahoo.com (Alex Martelli) Date: Thu, 16 Aug 2001 22:39:59 +0200 Subject: PEP 266: Optimizing Global Variable/Attribute Access References: <5rpe7.42284$O8.6453125@news1.busy1.on.home.com> <9ldakm01ioq@enews3.newsguy.com> <_lGe7.43578$O8.6622552@news1.busy1.on.home.com> Message-ID: <9lhb6a01spe@enews3.newsguy.com> "Peter Caven" wrote in message news:_lGe7.43578$O8.6622552 at news1.busy1.on.home.com... > Thanks Alex, You're welcome! > I sometimes forget how completely dynamic Python actually is! ...or "was" (although it will be for a while longer) -- performance issues may well dictate a gradual (and hopefully only partial) loss of some of that little-used dynamism, as forcefully argued by Guido (and a few supporters) in a couple of recent threads. At some point there will be classes you cannot change, and that will give higher performance when you explicitly tell the compiler those classes are not dynamic (or maybe, it's still possible, the non-dynamic will be the default, and you'll explicitly have to ask for backwards-compatible dynamism instead). Interesting times...!-) Alex From charles at a3a.com.br Thu Aug 30 09:23:02 2001 From: charles at a3a.com.br (Charles) Date: Thu, 30 Aug 2001 09:23:02 -0400 Subject: Python GUI In-Reply-To: <9ml98q0234u@enews1.newsguy.com> References: <3b8dc97b.60293093@news.isar.de> <9ml98q0234u@enews1.newsguy.com> Message-ID: <01083009230200.21251@magneto> Hi What's the best (more complete) GUI library to use with python ? Tkinter ? wxPython ? PyKDE ? ... Thanks ! From angelina1974 at hotmail.com Sun Aug 26 05:45:30 2001 From: angelina1974 at hotmail.com (Angelina Jolie) Date: 26 Aug 2001 09:45:30 GMT Subject: Angelina Jolie NAKED! Hacked and Ripped! Message-ID: <9magfq$chk$5571@news.castel.nl> Pics from here, right from PAY TV! http://angelina.redlights.tv Also: Silvia Saint http://silvia.redlights.tv From guido at python.org Fri Aug 31 17:28:47 2001 From: guido at python.org (Guido van Rossum) Date: Fri, 31 Aug 2001 21:28:47 GMT Subject: AttributeError: last_traceback References: <3B8FFD16.E388525E@bioeng.ucsd.edu> Message-ID: Curtis Jensen writes: > I have a section of code similar to this: > > try: > exec( ) > except: > print traceback.print_exc() > > This is so exceptions don't bring down my program. And some errors, I > can ignor. However, some errors I need to debug. For the errors I want > to debug, I'd like to uses "pdb.pm()" however, I always get > "AttributeError: last_traceback" with "pdb.pm()" Understandably, this > is because noe exception was loged, because I caught it. > > Is there a way I can catch exceptions and still use pdb.pm()? import sys try: exec except: sys.last_type, sys.last_value, sys.last_traceback = sys.exc_info() print traceback.print_exc() --Guido van Rossum (home page: http://www.python.org/~guido/) From s.schwarzer at ndh.net Sat Aug 11 18:22:01 2001 From: s.schwarzer at ndh.net (Stefan Schwarzer) Date: Sat, 11 Aug 2001 23:22:01 +0100 Subject: encapsulation? References: <3B704ED1.EFA6AEA8@demog.berkeley.edu> Message-ID: <3B75B009.1A42DA3E@ndh.net> Hello Lloyd Lloyd Goldwasser schrieb: > As a recent convert to Python (I have C, Objective-C, and Scheme, among > others, in my past), I'm curious about its lack of encapsulation. 'Way > back when I was using Objective-C -- and many other OO languages seem to > have a similar perspective -- there was a lot of emphasis on the ability > to keep the contents of objects independent of outside influence except > via well-delineated mechanisms. Security and reliability were cited as > major benefits of this approach: every object knew exactly what the > outside world was going to see and exactly how the outside world might > act to change its state. [...] There was a nice posting/thread on this some time ago: http://groups.google.com/groups?q=ken+seehof+encapsulation&hl=en&group=comp.lang.python.*&safe=off&rnum=1&selm=39491494.671DC3D9%40sightreader.com Stefan From smt at pacific.net.hk Fri Aug 31 04:53:41 2001 From: smt at pacific.net.hk (Kenneth Tsang) Date: Fri, 31 Aug 2001 16:53:41 +0800 Subject: Thanks Python References: <3b8e7183.15496437@news.t-online.de> Message-ID: <9mnje8$bdj$1@hfc.pacific.net.hk> And the force be with you -- -- Kenneth Tsang email: smt at pacific.net.hk tel: +852 9468 4772 "Gerson Kurz" wrote in message news:3b8e7183.15496437 at news.t-online.de... > On 30 Aug 2001 04:24:50 -0700, ws at dohao.org (Du Wellsun) wrote: > > >Python is very nice! I like it. > me to :) > > And now to something completely different: Where can I get the python > shirts in germany? Does anybody import them (no pun intended)? From piotrlg at sci.pam.szczecin.pl Fri Aug 3 06:21:59 2001 From: piotrlg at sci.pam.szczecin.pl (Piotr Legiecki) Date: Fri, 03 Aug 2001 12:21:59 +0200 Subject: Is this the *right* way of exception handling? Message-ID: <9kdr21$rao$1@zeus.man.szczecin.pl> Hi I wonder if the way I use exceptions is the right way or very problematic one (anyway it works of course). I have one class and fill it with a data. If data are wrong i raise my exception: class A: my_exception='my_exception' ....... def f(self,a): if a !=0 raise my_exception, 'a must be 0' def f1() ... try: x=A() x.f(1) except A.my_exception, val: print 'wow, eror', val #!!now, what to do here, i want to stop my program, but should clean something (close files etc) before, so sys.exit() is not a good idea another raise? def main(): ... use some resources, open files etc f1() close resources, files etc Thanx Piotr Legiecki From dalke at acm.org Sun Aug 19 01:38:58 2001 From: dalke at acm.org (Andrew Dalke) Date: Sun, 19 Aug 2001 06:38:58 +0100 Subject: Dumb python questions References: <7xy9okeeha.fsf@ruckus.brouhaha.com> <9lfpu9$fv6$1@newshost.accu.uu.nl> <7xr8u96tni.fsf@ruckus.brouhaha.com> <9lmtir01jlq@enews1.newsguy.com> <7x66bkjzbj.fsf@ruckus.brouhaha.com> Message-ID: <9loc7g$dmm$1@slb7.atl.mindspring.net> Paul Rubin: > It's kind of a strange idea though, that >Python has built-in long ints but I have to use an add-on package if I >want to do simple operations like find out how large a number is. Now my chance to ask a dumb question. When do you need to know how many bits are used for a number? I admit to never needing that functionality, but then again, I've almost never used long integers in real code. Though the very first Python code I wrote was something like: primes = (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) def godel(s): n = 1L for i in range(len(s)): n = n * long(primes[i])**(ord(s[i])-ord("A")+1) return n so "CAB" == 600L "ANDREW" == 65468565968763894209893994715140738242806825295981758750L (because of the fundamential theorem of algebra -- prime factorization is unique -- this number can be turned back into its original value). Andrew dalke at dalkescientific.com From john at cs.york.ac.uk Fri Aug 24 12:58:53 2001 From: john at cs.york.ac.uk (john at cs.york.ac.uk) Date: 24 Aug 2001 16:58:53 GMT Subject: ImportError: No module named _tkinter Message-ID: <998672333.20565846@cs.york.ac.uk> I've just successfully compiled Python 2.2a1 from source on a Linux system, and got it to work with Tcl/Tk 8.3.3 without any problem. When I do the same on a Solaris 2.6 system - the difference being the location of the various include and library files, I get the (well-known) messages: $ python calc1.py Traceback (most recent call last): File "calc1.py", line 1, in ? from Tkinter import * File "/usr/local/python-2.2a1/lib/python2.2/lib-tk/Tkinter.py", line 35, in ? import _tkinter # If this fails your Python may not be configured for Tk $ I've stared at the alterations to the copy of the text from the Setup file I've made in Setup.local, and can't see my mistake. I've read the Python FAQ, and google(-grouped) for a similar problem encountered by someone else. I've tested my installation of Tcl/Tk and it's fine. I've tried an earlier version of Tcl/Tk I had installed, and Python fails with the same error messages. If all else fails, how can one debug the Python Tkinter configuration? John A. Murdie From gbreed at cix.compulink.co.uk Thu Aug 23 09:46:33 2001 From: gbreed at cix.compulink.co.uk (gbreed at cix.compulink.co.uk) Date: Thu, 23 Aug 2001 13:46:33 +0000 (UTC) Subject: enhancing slicing References: <9m2sij$1f8s$1@ID-102451.news.dfncis.de> Message-ID: <9m31fp$27s$1@thorium.cix.co.uk> In article <9m2sij$1f8s$1 at ID-102451.news.dfncis.de>, juanv at posta.unizar.es (Juan Vali?o) wrote: > My proposal is to introduce a new operator, for instance # (count): > v[5 # 2] > Extract 2 elements starting at 5: [ v[5], v[6] ]. Equivalent to v[5:5+2] I don't think # is right, because it's already used for comments. But perhaps :][: would do the trick. So it'd be v[5 :][: 2]. It's more complex, but looks nice. And doesn't introduce any new punctuation into the language. Shall I start on the PEP? > v[5 # -2] > Extract 2 elements ending at (but not including the) 5: [ v[3], v[4] ]. > Equivalent to v[5-2:5] I'm not sure the the :][: operator would be appropriate here, but maybe the variation v[:5 ][ -2:] could be made to work. > I think that this little syntactic sugar allows programs more compact > and > readable. Also, I had less "start and end point paranoias". I suppose > that > the implementation is easy and the current programs are not affected at > all. Would my suggestions be much harder to implement? Graham From emile at fenx.com Sat Aug 25 16:29:30 2001 From: emile at fenx.com (Emile van Sebille) Date: Sat, 25 Aug 2001 13:29:30 -0700 Subject: lack of shell in Win2000 References: Message-ID: <9m923o$vcue$1@ID-11957.news.dfncis.de> ?? Start|Run|cmd should get you to a shell... -- Emile van Sebille emile at fenx.com --------- "john anon" wrote in message news:jGTh7.21$Ks5.40555 at nnrp2.sbc.net... > at the risk of repeating an old question > (I looked -- really -- I looked) > > if there is no shell in Win2000, how will we start scripts? > from Explorer? but ... what about command-line args? > > From loewis at informatik.hu-berlin.de Thu Aug 16 11:17:18 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 16 Aug 2001 17:17:18 +0200 Subject: Extension modules and SIGINT References: Message-ID: com-nospam at ccraig.org (Christopher A. Craig) writes: > I have an extension module that does a _lot_ of math with > PyLongObjects. I'm pretty sure that I'm catching every instance where > a failure could occur in a PyNumber call, but I still get bus errors > when I send a keyboard interrupt. > > Is this normal, or have I made a mistake? You made a mistake, probably failing to check for a null pointer. If a sigint occurs, functions may randomly return NULL, and you need to check every single one. I recommend to use a debugger to analyse where it crashes. Regards, Martin From nospam at bigfoot.com Sat Aug 11 13:57:30 2001 From: nospam at bigfoot.com (Gillou) Date: Sat, 11 Aug 2001 19:57:30 +0200 Subject: popen3 and ssh References: <3B73E5C6.2080200@f2s.com> Message-ID: <9l3rc4$2ago$1@norfair.nerim.net> Hi, Sorry, I've no answer to your question but I'm looking for a way to send a shell command and retrieve the result to a ssh server (you already succeeded). Can you please tell how ? TIA --Gillou glenfant at bigfoot.com Warning: the "sender" of this message is a "no spam" address. "Michele Campeotto" a ?crit dans le message news: 3B73E5C6.2080200 at f2s.com... > Hi, I'm trying to connect to CVS via SSH from a Python script, it > works fine when used over a network, but on a local machine it seems > that SSH doesn't get the password that I'm sending... anybody can give > an hint? > > cvs_input.write(self.password + '\n') > > (cvs_input comes from the popen3 call) > > -- > Michele - www.moleskine.f2s.com > From BPettersen at NAREX.com Wed Aug 15 17:07:18 2001 From: BPettersen at NAREX.com (Bjorn Pettersen) Date: Wed, 15 Aug 2001 15:07:18 -0600 Subject: Which is the best way... Message-ID: <6957F6A694B49A4096F7CFD0D900042F27DBB0@admin56.narex.com> > From: Matthew D. Wood [mailto:woodm at equire.com] > > I have an interesting code-correctness question. I firmly believe in > doing things 'The Right Way' and I'm not sure which of these > 3 blocks is > better. So, if you code-guru's could help me out I would definitely > appreciate it. > [snip] > > # Works, but how much overhead is there in the slicing of the > range list? > def first_non_ordered_2 (my_list) : > for index in range(len(my_list))[:-1] : > if my_list[index] > my_list[index + 1] : > return index + 1 > > else : > return None you could always do range( len(my_list)-1 ), and you don't really need the else: def first_non_ordered_2 (my_list) : for index in range( len(my_list)-1 ): if my_list[index] > my_list[index + 1] : return index + 1 return None -- bjorn From donn at drizzle.com Wed Aug 22 01:03:40 2001 From: donn at drizzle.com (Donn Cave) Date: Wed, 22 Aug 2001 05:03:40 -0000 Subject: asynchronous callback References: Message-ID: <998456619.231561@yabetcha.drizzle.com> Quoth Silvio Arcangeli : ... | In my case the callback function should actually be a Python method. | So I added a C callback function to my extension module: it just converts | the parameters, and then calls the Python method. ... | Anyway, the C function correctly retrieves the Python method from the | dictionary, but then when it calls it it gets blocked. | I think that this is probably due to the fact that the C callback function | is called asynchronously (that means it runs in a different thread from the | interpreter's one). | How can I make it work? I don't know if I would have expected it to block, but at any rate, any healthy callback needs to acquire the interpreter's lock before proceeding. Here's how mine do it - /* Before the thread starts, get a thread state object for it. */ PyEval_InitThreads(); tstate = PyThreadState_New(PyThreadState_Get()->interp); /* From that thread, about to call from C into Python. */ PyEval_AcquireThread(tstate); /* After Python function returns. */ PyEval_ReleaseThread(tstate); Meanwhile, of course functions that call out to C for any length of time must release the interpreter lock first, so your callback can get it! Usually done with macros, Py_BEGIN_ALLOW_THREADS and Py_END_ALLOW_THREADS. I hope that's right, it has been a while since I had to wrestle with this. Donn Cave, donn at drizzle.com From cce at clarkevans.com Sun Aug 12 21:19:30 2001 From: cce at clarkevans.com (Clark C . Evans) Date: Sun, 12 Aug 2001 21:19:30 -0400 Subject: to implement a cache: is there a thread safe map? Message-ID: <20010812211930.A16527@doublegemini.com> Pardon my ignorance here. I'm rather new to threading and I have the following situation: 1. I have multiple threads. 2. I have several constructs ("objects") which are very common, costly to construct, and should be kept around for a while. 3. These objects are static once created, they are tuples of strings). 4. The objects are used frequently, and thus will be requested all of the time. 5. I can't predict what combination of objects will be required at compile time. To be a bit more pragmatic, suppose I have the following function... def make(args): """ A function that constructs a complicated object based on its parameters. The object constructed is a constant (non-mutable) object, and the parameters are also non-mutable. This is a brain-dead version. """ return args How could I go about building a "generic", thread-safe cashe object around the following function. Thus, I'd like... cashedmake = CashedFunction(make) obj = cashedmake('a') class CashedFunction: def __init__(self,func): self.func = func self.cache = {} def __call__(self,arg): ret = self.cache.get(arg,None) if not(res): ret = self.func(arg) self.cashe[arg] = ret return ret My problem: (Yes, the above probably isn't right) 1. How do I make something like the above thread safe? I would add: self.lock = threading.Lock() to the __init__ and then surround self.lock.acquire() ret = self.func(arg) self.cashe[arg] = ret self.loc.release() Is this right? a) It seems that if two threads hit the lock.acquire() at the same time, I'll construct the object twice... is there a way around this? b) It looks like the map could be altered mid "get", does the entire function need to be locked, or can I just lock the mutating portion? c) What other concerns am I missing? 2. Dropping items from the cashe. I suppose I could make my entries in the map (created,value) to store the time it was created, periodically sweeping through the map to clear entries. Would a weak reference help here? Would it be better to keep another map with the last time that a given object was accessed? In short... what is the interaction of a map object and multiple threads. What do I have to be concerned about? Thank you so much, Clark From mmhamze at pleiades.net Mon Aug 27 17:22:24 2001 From: mmhamze at pleiades.net (Maan M. Hamze) Date: Mon, 27 Aug 2001 16:22:24 -0500 Subject: Real.py where is it? References: Message-ID: "Tim Peters" wrote in message news:mailman.998944859.10075.python-list at python.org... > [Maan M. Hamze] > > All web links to this module are broken. Where can I find it? > > This has sure become a popular module lately! Yes a collectible - a rare scarce resource :) Let us hope it works with the Python complex number implementation in what I am cooking. > In the case of Jurgen's module, Keith Briggs saved a copy, linked to from: > > http://www.btexact.com/people/briggsk2/XR.html > Look for "python code by Jurjen N.E. Bos". Thanks! A nice site that I was not aware of. Maan From peter.sundling at telia.com Thu Aug 23 18:16:49 2001 From: peter.sundling at telia.com (Peter Sundling) Date: Thu, 23 Aug 2001 22:16:49 GMT Subject: I dont get this! Message-ID: <3B85805D.BAC86944@telia.com> Help! :) I have been programming in python for some time now, and today i found a strange bug in my code i cant get rid of... Here is a code snippet where something is wrong somewhere: def check_hilo(i): if value[i] < low[i]: return 1 if value[i] > high[i]: return 2 return 0 ...Simple, huh? I have never had any trouble with something like this before. The thing is that this procedure always returns 1. I have tried to rewrite this little source code a couple of times, in many different ways, and it still returns 1! If i compare value to high before i compare it to low, it still returns 1. As an example: value[i] was 103, low[i] was 25 and high[i] was 35. As far as i know, 103 is greater than 25. But python seemes to disagree on that... ( if i start the python alone and writes print 103 < 25 it responds 0, But what the hell is wrong now??) /Peter (The dumbest programmer on the face of the earth) From phd at phd.pp.ru Thu Aug 9 11:44:31 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Thu, 9 Aug 2001 19:44:31 +0400 (MSD) Subject: newbie-ness upgrade woes In-Reply-To: <90F914D54nemirCUTTHIShotmaild@61.9.128.12> Message-ID: On Thu, 9 Aug 2001, nemir wrote: > I hope you can forgive the newbie-ness of all this, but I have decided to > run with Python as my learn first programming language now that I have been > told to run a redhat apache server. You are welcome! > Lemme give you the rundown: > > Installed an out of the box RedHat 7.1 server (WITHOUT a GUI) which comes > with Python 1.5.2. A little outdated I thought, so I determined that now > the rest of the box is stable I will upgrade. I go get the Python- > 2.1.1.tgz file, run > > tar xfvz Python-2.1.1.tgz > > And it all uncompressed great. > > I CD to the new Python-2.1.1 directory. > > I try to run > > python setup.py install Instead, run ./configure make Then go root and run make install Hope this helps. Oleg. ---- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From chrishbarker at home.net Mon Aug 27 15:14:54 2001 From: chrishbarker at home.net (Chris Barker) Date: Mon, 27 Aug 2001 12:14:54 -0700 Subject: LaTeX class howto.cls? References: Message-ID: <3B8A9C2E.4C4961BD@home.net> Tim Roberts wrote: > I recently fetched the mimelib Python module. I went to print out the > documentation, and decided the LaTeX version would be the most convenient > way. Your question has been answered, but unless you are planning on editing the document, you are probably better off with the pdf or postscipt version (This from a big LaTeX user, who has also edited some of the Python docs) -Chris -- Christopher Barker, Ph.D. ChrisHBarker at home.net --- --- --- http://members.home.net/barkerlohmann ---@@ -----@@ -----@@ ------@@@ ------@@@ ------@@@ Oil Spill Modeling ------ @ ------ @ ------ @ Water Resources Engineering ------- --------- -------- Coastal and Fluvial Hydrodynamics -------------------------------------- ------------------------------------------------------------------------ From donn at u.washington.edu Wed Aug 1 18:49:12 2001 From: donn at u.washington.edu (Donn Cave) Date: 1 Aug 2001 22:49:12 GMT Subject: Typing system vs. Java References: Message-ID: <9ka118$mj8$1@nntp6.u.washington.edu> Quoth : ... | Right. My assertion is that this causes more problems than it solves | because you seldom know your "intent" in that much detail, much less your | future intent. Seems like ultra strict type checking might work well in | cases where you have very precise requirements and once built, your | software won't be changing any time soon (a la space shuttle software). | Most programs don't fall into that category. OK, another example, happy to be able to accommodate your request. >From today's comp.lang.python, someone asks, how come my program doesn't work? His case seems a ways away from space station control. His point of failure looks like this, arg = parse(data) if arg[0] == 'privmsg': ... elif arg[0] == 'ping': ... And the run time error is a TypeError: unsubscriptable object. He's baffled enough by this to post to comp.lang.python instead of figure it out himself. Here's his code: ----- def parse(self, data): if string.find(string.lower(data), 'privmsg') >= 0: garbage,middle,msg = string.split(data,':') sender,cmd,rcpt = string.split(middle) arg=[string.lower(cmd),sender,rcpt,msg] return arg elif string.find(string.lower(data), 'ping') >= 0: sender,cmd,pong = string.split(data[1:]) arg=[string.lower(cmd),sender,pong] return arg ----- And similar in OCaml: ----- let ulfind str data = try let n = Str.search_forward (Str.regexp_case_fold str) data 0 in true with Not_found -> false let parse data = if ulfind "privmsg" data then let wl = Str.split (Str.regexp ":") data in match wl with garbage::middle::msg::[] -> let wl = Str.split (Str.regexp "[ \t]+") middle in begin match wl with sender::cmd::rcpt::[] -> Some [(String.lowercase cmd); sender; rcpt; msg] | _ -> None end | _ -> None else if ulfind "ping" data then let wl = Str.split (Str.regexp "[ \t]+") (Str.string_after data 1) in match wl with sender::cmd::pong::[] -> Some [(String.lowercase cmd); sender; pong] | _ -> None else None let main () = let data = begin print_string "parse me: "; read_line () end in let argl = parse data in match argl with Some [] -> Printf.printf "Empty\n" | None -> Printf.printf "unexpected input \"%s\"\n" data | Some (cmd::argtl) -> Printf.printf "Command \"%s\"\n" cmd ;; main () ----- It's probably a suboptimal expression of the idea, as I am very new to OCaml. OCaml's type checking catches his error - if I leave the last "else" out of the parse function, the compiler notices the void return, in a context where void is not accounted for. I used a None/Some option for the return just to show how that would work, but that one bit of explicit typing isn't really necessary, an empty list or an exception would have worked fine. That's a complete, working program. Hope you find this useful. Donn Cave, donn at u.washington.edu From rajarshi at seed.chem.psu.edu Mon Aug 6 16:20:36 2001 From: rajarshi at seed.chem.psu.edu (Rajarshi Guha) Date: Mon, 6 Aug 2001 16:20:36 -0400 Subject: removing duplicate spaces from a string References: Message-ID: <9kmu1b$5e404$1@ID-91520.news.dfncis.de> Ron Johnson wrote: > Say I have the strings: > 'foo bar snafu' > 'fiddle faddle pip pop' > > Are there any builtins that will allow me to compress the > duplicate spaces out so that the files look like: > 'foo bar snafu' > 'fiddle faddle pip pop' say the string is s, then you could proceed as follows: o = '' s = string.split(s,' ') for i in s: if (i != ' '): o = o + i + ' ' This code segment will give you the final required ouput in o -- Rajarshi Guha From brueckd at tbye.com Wed Aug 15 23:25:53 2001 From: brueckd at tbye.com (brueckd at tbye.com) Date: Wed, 15 Aug 2001 20:25:53 -0700 (PDT) Subject: Debugging Multi-Threaded Python Programs In-Reply-To: <270c68fe.0108151628.42f78be7@posting.google.com> Message-ID: On 15 Aug 2001, Alan Green wrote: > Has anyone out there had luck with interactively debugging > multi-threaded Python programs? On Windows? Is there an alternative to > implementing my own GUI debugger (which won't happen)? Hi Alan, I had the same problem awhile back with using the profiler with threads - the current profiler function doesn't get "inherited" from the parent thread when a child thread is created. I filed a bug on sourceforge and whoever looked at it set it to an enhancement (meaning, I suppose, that if it's really important to me then I should get my butt in gear and submit a two line patch to fix it). Why don't you submit a patch for the debugging problem and fix my profiler bug at the same time? ;-) Anyway, for profiling I got around it by importing the thread module and replacing its start_thread (or whatever it's called) function with my own that called the old function and then, in the new thread, set the profiler function to that of the parent. I seem to remember a few other little tweaks needed to get it to work but that was the main one. I don't know if the same thing would work with the debugger, but I thought I'd at least toss it out as an idea. -Dave (if you wait long enough, maybe I'll need to profile a multi-threaded program again and I'll get around to submitting a patch ) From runyaga at thisbox.com Tue Aug 7 17:36:01 2001 From: runyaga at thisbox.com (alan runyan) Date: Tue, 07 Aug 2001 21:36:01 GMT Subject: Wild-eyed thinking aloud: Python System Management Infrastructure References: <9kjoq6$4jb$1@clematis.singnet.com.sg> Message-ID: <5bZb7.46110$g_3.6706340@typhoon.austin.rr.com> > This problem has been around long before the first Internet gold rush - > many skilled people have attacked it. Find something you can get going, > e.g., cfengine, Big Brother, even the old venerable Nocol. > > Join Usenix and SAGE. Check out the material of Usenix's sysadmin > conferences from years past. Behold the diversity. It doesn't have to be > Python. but it can be Python. http://sourceforge.net/projects/qos/ this is the monitoring system that was used at egroups, iirc. whats unfortunate is how hidden this project is ;( ~runyaga From tanzer at swing.co.at Wed Aug 1 12:25:29 2001 From: tanzer at swing.co.at (Christian Tanzer) Date: Wed, 01 Aug 2001 18:25:29 +0200 Subject: FEEDBACK WANTED: Type/class unification In-Reply-To: Your message of "Tue, 31 Jul 2001 12:50:38 BST." <9k6uoa$3sv$1@slb7.atl.mindspring.net> Message-ID: "Andrew Dalke" wrote: > Hernan M. Foffani wrote: > > One minor suggestion: > > I think it would help if you set a convention for the name > > of the first argument in classmethods. Like self for standard > > methods. Well, even self can "work" here, too. > > Guido: > >I think 'self' would be confusing. I'd like to propose 'cls'. > > What's wrong with 'klass'? Other than that it looks either > like a typo or like German. Several of the standard libraries > use 'klass' when refering to a class and I've seen code outside > the std. library using 'klass' as well. Whereas 'cls' is less > frequently used in the std. library to hold a class, but I've > not seen external uses of that name for that purpose elsewhere. `klass` is broken German . Might be correct Dutch, though. To me it seems wrong to use a non-english token in a programming languages using English for all other names. There were lots of proposals for this, all of them contentious to someone or another: arg-name pro con -------------------------------------------------------------------- class obvious meaning clash with keyword Class obvious meaning case sensitive cls BDFL's choice pronunciation, non-obvious clas closest to class non-obvious self standard convention confusion between instance and class methods Self follows a common convention case sensitive (class name capitalized, instance name lower case) type obvious meaning clash with builtin cat cute (class and type) cute, non-obvious acronym I'm glad that nobody proposed `class_` yet :-) As the first argument can immediately signify a class method if the same name is used by everybody it would be nice if an uncontentious name popped up. -- Christian Tanzer tanzer at swing.co.at Glasauergasse 32 Tel: +43 1 876 62 36 A-1130 Vienna, Austria Fax: +43 1 877 66 92 From krel at is-antisocial.net Thu Aug 2 16:23:56 2001 From: krel at is-antisocial.net (krel) Date: Thu, 02 Aug 2001 20:23:56 GMT Subject: https proto module? Message-ID: Is there a module out there to deal with the https (http with an 's' on the end) protocol? I'd love it if there were. -krel From aleaxit at yahoo.com Fri Aug 17 12:25:57 2001 From: aleaxit at yahoo.com (Alex Martelli) Date: Fri, 17 Aug 2001 18:25:57 +0200 Subject: where is doctest module References: <3O7f7.3258$D4.222704@newsread1.prod.itd.earthlink.net> Message-ID: <9ljgid02429@enews2.newsguy.com> "robin and jim" wrote in message news:3O7f7.3258$D4.222704 at newsread1.prod.itd.earthlink.net... > How do I get a copy of the doctest module? I was not able to locate it > starting from www.python.org. In Python 2.1 and later, it's part of the standard Python library, as Lib/doctest.py. You can get it from CVS if you have an older Python: e.g. try, just one URL: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/python/dist/src/Lib/do ctest.py?rev=1.16&content-type=text/vnd.viewcvs-markup Alex From jkonicki at harris.com Tue Aug 7 11:02:39 2001 From: jkonicki at harris.com (Konicki, Jason) Date: Tue, 7 Aug 2001 11:02:39 -0400 Subject: execfile environment?? Message-ID: I am trying to call a module with the execfile function. Is there a way to specify the paths to search for the module I am calling? For example: def call_module(module_name): # addition checks required before executing print "Executing "+module_name execfile(module_name) When I call this function, I want it to find "module_name", i.e testing.py, within the sys.path. Is this possible, or do I have to include the entire path of module_name when using execfile?? Jason From richard at bizarsoftware.com.au Thu Aug 23 20:32:02 2001 From: richard at bizarsoftware.com.au (Richard Jones) Date: Fri, 24 Aug 2001 10:32:02 +1000 Subject: optional args for getopt() In-Reply-To: <3B859647.B62A861B@uniserve.com> References: <3B847188.F403FEA3@uniserve.com> <0108231343520N.28818@ike> <3B859647.B62A861B@uniserve.com> Message-ID: <0108241032020Z.28818@ike> On Friday 24 August 2001 09:48, bvdpoel at uniserve.com wrote: > Richard Jones wrote: > > On Thursday 23 August 2001 12:59, bvdpoel at uniserve.com wrote: > > > Is there a way to signal that the arg for getopt in optional. In C I > > > can set an option string to something like: > > > > Sorry, to answer this question directly - I don't believe it's possible > > in the current getopt code. Your best bet would possibly be to locally > > change getopt to do qhat you need (and at the same time, generate a patch > > that can be submitted to python.sf.net). > > > > Richard > > Thanks. I really was hoping NOT to have to reinvent the wheel. For now > I'll just leave well enough alone and do my own parsing.... but if any > maintainers are reading this, it would be nice to have GNU compatibility > in this. I wasn't talking about re-inventing the wheel... I was talking about a minor change to an existing one. OK, attached is a simple patch against the getopt module from the 2.1 distribution (encoded so mail systems don't mess with the formatting). I've submitted this to the sourceforge patch repository. BTW: in a large number of cases in the python library - we, the python community, are the "maintainers" of the code. Modules get extended when someone has a need and submits the code the python maintainers. Note: I've only implemented this behaviour - none of the other GNU extensions. Hope it's useful for you. Richard -------------- next part -------------- A non-text attachment was scrubbed... Name: getopt.py.diff Type: text/x-diff Size: 2227 bytes Desc: not available URL: From paul at boddie.net Mon Aug 6 05:35:01 2001 From: paul at boddie.net (Paul Boddie) Date: 6 Aug 2001 02:35:01 -0700 Subject: PSP, Cheetah, PTL, ZOPE, etc ... References: <112e9d13.0108011014.1fb2241a@posting.google.com> <3dofpzk3vq.fsf@ute.cnri.reston.va.us> <23891c90.0108020149.1c07ddfa@posting.google.com> <3dd76bk8ik.fsf@ute.cnri.reston.va.us> Message-ID: <23891c90.0108060135.4ecb27bf@posting.google.com> Andrew Kuchling wrote in message news:<3dd76bk8ik.fsf at ute.cnri.reston.va.us>... > > The assumption I'm talking about isn't that the output is assumed to > be HTML or text, but that templates are assumed to be mostly plain > HTML with only occasional escapes into program code or variable > expansions. That assumption may have once been true, and still is if > all you're doing is inserting the current date or picking a random > quotation; one and you're done, but for most modern, > heavily dynamic Web sites I expect the density of program code is much > higher. It depends on your architecture, I suppose. Whilst it's possible that the user interface of your application might employ a fair amount of code to access and manipulate different generic components (eg. business/application objects), and that code might be incorporated into resources residing in your templates, I think there are advantages in having another layer to do all this, with the templates doing a very simple "translation" of the components in that new layer to the "display". My reasoning is that, especially when considering many different types of user interface, there are likely to be activities and components which support user interfaces in general. Once you're resigned to dedicating a layer for these activities and components, what else is left for the template system to do? > > But doesn't this help to obscure the form of the final document? I was > > once an advocate of building pages up from well-defined, "trusted" > > components which represent a particular concept, but there are some > > situations where logical components of a document don't just fit into > > a self-contained part of a document; for example, attributes of > > objects that one is trying to represent may be mixed together into > > adjacent cells in an HTML table. > > I'm not clear on what you mean; can you give a clearer example? > Surely the code to generate the entire table can be rolled up into a > single function, which answers much the same purpose. Well, in the PTL architecture, I presume you can treat groups of objects differently to individual objects. For example, in a collection of order lines (the classic example), where each line contains a product, some details, and perhaps a delivery address, you would want to create a specific representation of the order line which mixes together attributes from the components inside it, rather than rely on whatever representations you might previously have chosen for those components. So, a product may have its own inate representation such as:

Product code: product code (product description)

And a delivery address may have its own representation as:

Address: first lines
Town: town
Postcode: postcode

But in an order line, you would want to mix them in a previously unforeseen way: product code product description first lines
town
postcode In an over-simplistic, self-contained, "this object gets put here in the document" system, you wouldn't be able to change the "context of representation" so easily. Am I still making sense at this point? ;-) > Incidentally, it strikes me that Quixote might be easier to use with > Jython than Zope is. The hardest part would be translating the PTL > template generator because that uses the compiler module to generate > Python bytecodes; perhaps it could be changed to generate straight > Python output which could then be run through Jython's compiler. I > see no way to give that acceptable performance, though. I'm also not entirely convinced by the preprocessing phase of certain template systems. Although a well-managed development environment can always provide the means for templates to get rebuilt when they change, it seems like another thing to remember and another thing to go wrong when you least expect. ;-) For me, a good template system should support operation anywhere (not just in some strange application server environment) so that I can always test my templates in advance, but I'm not convinced that it should require preprocessing. But then, I'm clearly not into the kind of templates that would benefit so much from preprocessing... Paul From opennopri at yahoo.com Thu Aug 23 03:57:08 2001 From: opennopri at yahoo.com (noprianto) Date: Thu, 23 Aug 2001 00:57:08 -0700 (PDT) Subject: simple ping program Message-ID: <20010823075708.89056.qmail@web14903.mail.yahoo.com> hello all, Does anyone know how to make a very simple ping program, with option to set the packet size.... please... __________________________________________________ Do You Yahoo!? Make international calls for as low as $.04/minute with Yahoo! Messenger http://phonecard.yahoo.com/ From bokr at accessone.com Thu Aug 23 17:58:19 2001 From: bokr at accessone.com (Bengt Richter) Date: Thu, 23 Aug 2001 21:58:19 GMT Subject: Really stupid question regarding PEP 252 and type/class unification References: <8a12e538.0108221144.5b74df26@posting.google.com> <8a12e538.0108230607.30481024@posting.google.com> <9m34eb029s8@enews4.newsguy.com> <3b85511b.268189646@wa.news.verio.net> Message-ID: <3b857a06.278664778@wa.news.verio.net> On 23 Aug 2001 21:00:15 GMT, Marcin 'Qrczak' Kowalczyk wrote: >Thu, 23 Aug 2001 19:30:44 GMT, Bengt Richter pisze: > >> lhs = rhs >> Is it cast in concrete *for always and forever* that the >> old binding of the lhs will *always* be discarded in favor of a new >> binding to the rhs without regard to the previous binding? > >I think yes. The old binding doesn't need to exist at all. > In which case there would be no object to check for a preemption method, so that wouldn't hurt anything. [...] >> IOW, one could conceive of a check for an attribute of the old >> binding's object which if present would mean that the old object >> gets to handle the reference to the new rhs and leave the old >> binding alone. > >IMHO it would be confusing to have an extremely rare case where the >= operator means something different. I would not use this operator >for this case. It always meant rebinding of a name. The old binding >is irrelevant - the object doesn't need to exist at all. > I guess I have to agree that one meaning for '=' is best. Perhaps ':=' could be used to access a lhs object's assignment/rebinding method, if such a thing were useful (which I think it might be. A concise way of talking to a particular kind of object method is usually nice). Something like '+=' with a different meaning. From bokr at accessone.com Fri Aug 17 23:54:53 2001 From: bokr at accessone.com (Bengt Richter) Date: Sat, 18 Aug 2001 03:54:53 GMT Subject: why no ++? References: <9kf46r014ba@drn.newsguy.com> <9kmt1n01r0g@enews4.newsguy.com> <3B75B3C0.965E6E2E@ndh.net> <9lan1301822@enews1.newsguy.com> Message-ID: <3b7de709.3497459@wa.news.verio.net> On Tue, 14 Aug 2001 10:20:50 +0200, "Alex Martelli" wrote: >"Michael Abbott" wrote in message >news:Xns90FD5728D9CDAmichaelrcpcouk at 194.238.50.13... > ... >> Oops! Very true. I should have rewritten it as >> >> e = 'wow' >> b,c,d = 'wow' >> a = 'wow' >> >> Hmm. The argument about obfuscation versus repetition comes more clearly >> into focus. I still think multiple assignment is a bad thing... > >So now consider: > > y.a = b,c,d = x.e = wower() > >How would you like to rewrite _this_?-) There is *NO* rewrite >that ensures constant semantics except by introducing _another_ >temporary variable -- *yecch*!-) > >Seriously now -- multiple assignment is a very minor thing, but >handy when you do need it, and not error-prone. So, why not? > > Considering your proposed example, can you state with assurance exactly what order things are done, including side effects? From patrick.fichou at galactica.it Thu Aug 23 09:44:07 2001 From: patrick.fichou at galactica.it (Patrick) Date: Thu, 23 Aug 2001 15:44:07 +0200 Subject: REQ : Real.py References: <9m2td3$h1k$1@pegasus.tiscalinet.it> <7xheuzue16.fsf@ruckus.brouhaha.com> Message-ID: Paul, I received a link that works in my mailbox... Here it is : < http://www.itp.ac.cn/software/mirror/python/contrib/Math/real-accurate.pyar > This module extends the capactity of Python with 'real numbers' : compute with 1000's of digits what you want. IMPRESSIVE ! Try it, Patrick "Paul Rubin" a ?crit dans le message news: 7xheuzue16.fsf at ruckus.brouhaha.com... > "Patrick" writes: > > Does someone knows where is the 'real.py' module that seems very useful and > > fast for number crunching ? The link on the Python Homepage is not valid ( > > ftp://ftp.python.org/pub/python/contrib/Math/real-accurate.pyar ). > > Do you mean NumPy (Numeric Python)? Check www.vex.net/parnassus in > the math section :) From bill-bell at bill-bell.hamilton.on.ca Thu Aug 2 20:56:35 2001 From: bill-bell at bill-bell.hamilton.on.ca (Bill Bell) Date: Thu, 2 Aug 2001 20:56:35 -0400 Subject: Zope In-Reply-To: <996780871.363.88696.l8@yahoogroups.com> Message-ID: <3B69BE83.11749.CB1F95@localhost> > Roar> I've resently begun to learn Zope (and therefore Phyton). My > Roar> question: Is there any newsgroup aimed at Zope? Send Zope mailing list submissions to zope at zope.org To subscribe or unsubscribe via the World Wide Web, visit http://lists.zope.org/mailman/listinfo/zope or, via email, send a message with subject or body 'help' to zope-request at zope.org You can reach the person managing the list at zope-admin at zope.org Bill Bell, Software Developer From kseehof at neuralintegrator.com Sat Aug 4 18:31:15 2001 From: kseehof at neuralintegrator.com (Ken Seehof) Date: Sat, 4 Aug 2001 15:31:15 -0700 Subject: Beginner's questions References: Message-ID: <003501c11d35$2cbc61a0$6501a8c0@pacbell.net> From: "Lad" > Hi, > I am a Perl programmer but I miss some things in Perl. For this > reason I am looking for another, better (if any) programming > language. Maybe Python would be my choice. Can you please > answer the following? Yes. > 1.How well threads are implemented in Python particularly under > windows? Threads work fine. There is a global interpreter lock that prevents the python code interpretation from truly running in parallel (but library/extension code underneath is running in parallel, so this is really no big deal and you do get some parallelism). Threads are easy to use. > 2.Are there any libraries for working with HTTP protocols that is > modules that could help download( grab) web pages with GET > methods and modules for using also POST method without > necessity to program these applications with sockets? Yes. The httplib does what you want. In fact you can go higher level than that by using the urllib module, which will open any url as if it were a file. > 3.Are there any libraries for SMTP, POP3 and NNTP protocols? yes, yes, yes... see the modules list > 4. Is there a program for making executable files from python > programs? Yes. A few. The one I use is Installer. http://starship.python.net/crew/gmcm/distribute.html > 5. What modules , except Tk, can I use for GUI programming with > Python? Several. I like wxPython the best. It's a seamless wrapper on the wxWindows GUI: www.wxpython.org > 6. Is it possible, in Python, send output from a program to a web > browser directly or in other words display html file in python > application? Yes. Most of the various python GUIs have widgets for that In wxPython there is a wxHtmlWindow and a whole suite of support objects. > 7. Where can I find a available modules list? http://www.python.org/doc/ > 8. What are best tutorials/books on Python? http://www.amk.ca/bookstore/ > 9. Can you give me examples of large Python application? www.zope.org http://www.python.org/psa/Users.html > 10. Why do YOU use Python? It's really that good. My first mindblowing experience was using Mark Hammonds win32ui and PythonWin. Not just because of the module itself, but because it proves that MFC can be seamlessly wrapped in python! If something as nasty as MFC can be wrapped, anything can. (Now I use wxPython instead of win32ui, because it is similar to MFC, but way cleaner, and it is multi-platform.) > 11. Is it possible to to "talk" to java applets via Python? Yes. There are several protocols that both languages support. You can also make and use java classes in Jython. http://www.jython.org/ > Thank you for your answers? > > Ladislav You're welcome. All this info and more is available at www.python.org, where you should spend the next few hours. And download python. It's really easy to download and get started. - Ken Seehof kseehof at neuralintegrator.com www.neuralintegrator.com/kseehof From vvainio at karhu.tp.spt.fi Wed Aug 1 07:55:50 2001 From: vvainio at karhu.tp.spt.fi (Ville Vainio) Date: 01 Aug 2001 14:55:50 +0300 Subject: Non-Programmers (was: Changing the Division Operator) References: Message-ID: markus at kepler.ibp.de writes: > We obviously need a good name. What about the traditional name for non-programmer, the one invented several years ago: lam3r? Sorry, couldn't resist ;-) . I'm well aware of the need for casual programming, esp. for scripting. I think Perl people have used the term "accidental programmer" a while now (isn't it used in the Camel book?). -- Ville Vainio - http://www.tp.spt.fi/~vvainio - ICQ #115524762 Wild geese have no intention to cast a reflection Water has no mind to assume their form From ahoffman at linux.announce.com Mon Aug 20 19:49:41 2001 From: ahoffman at linux.announce.com (Allen Ahoffman) Date: 20 Aug 2001 19:49:41 -0400 Subject: python internet development platforms for less Message-ID: <3b81a215$1@news2.thevalkyrie.com> Announce Communications Inc POB 2308 Hyattsville, MD 20784 301-731-5786 kelly at announce.com Please review the below offerings, and if it meets your needs for a web development, test bed, production server, or just play box, let us know. If neither of these works for you, talk with us we aim to please. Rspecial Rspecial2 From m at moshez.org Sat Aug 4 09:37:53 2001 From: m at moshez.org (Moshe Zadka) Date: Sat, 04 Aug 2001 16:37:53 +0300 Subject: Deposing Dictators In-Reply-To: <9kgnqa22p9u@enews4.newsguy.com> References: <9kgnqa22p9u@enews4.newsguy.com>, Message-ID: On Sat, 4 Aug 2001 10:08:07 +0200, "Alex Martelli" wrote: > So instead of adding features let's remove restrictions. And I don't > think you can state with a straight face that there aren't any > restrictions -- look at the complications such as StringIO vs cStringIO > and pickle vs cPickle that are forced by the restriction "thou shalt > not subclass a c-coded type":-). How many people actually need to subclass StringIO? I think the real reason StringIO stayed is "if you have trouble porting the C code, here's some Python instead" pickle is a bit more likely to be subclassed, but not much more. Again, I think the argument is that as long as we can, we want Python code to do the same thing for all the good reasons you know... -- Moshe Zadka - http://moshez.geek (if you're not cool, http://moshez.org is still working) From slhath at home.com Mon Aug 13 21:34:43 2001 From: slhath at home.com (Scott Hathaway) Date: Tue, 14 Aug 2001 01:34:43 GMT Subject: simple question about classes References: <3b783669.0@216.0.152.7> <9l9gn102ufh@enews4.newsguy.com> Message-ID: You guys are awesome! That is what I needed. Thanks, Scott "Alex Martelli" wrote in message news:9l9gn102ufh at enews4.newsguy.com... > "Scott Hathaway" wrote in message > news:3b783669.0 at 216.0.152.7... > > If I have a class, is there a way to iterate through the name of all of > the > > properties (public variables) of the class which would include public vars > > that were added at the time of instantiation? > > Yes, of course -- but your example show that you want to > iterate on the attributes of an *instance*, not really those > of the *class* itself. > > > > class a(): > > Wrong syntax (empty parentheses forbidden here, sigh). > > > getPublicVars(self): > > # loop here that prints each variable and it's value > for varname in a.__dict__.keys(): > print varname, getattr(a,varname) > > This gives only the attributes of the instance -- no check on whether > they're callable (methods rather than properties) and no check on > further attributes that belong to the class or its bases. It's easy > to restrict the list by forbidding callables: > for varname in a.__dict__.keys(): > value = getattr(a, varname) > if not callable(value): > print varname, value > and it's not too hard to similarly check self.__class__ and > (recursively upwards) its __bases__ while avoiding duplicates, > but it starts to get hairy -- maybe dir() in 2.2 will do that for > you (Tim and Guido were mooting that as a possibility, and > clearly it WOULD be handy here). > > You do specify ''public'' properties so you may want to filter > further: > for varname in a.__dict__.keys(): > if varname.startswith('_'): continue > value = getattr(a, varname) > if not callable(value): > print varname, value > > > Alex > > > From wtanksle at dolphin.openprojects.net Mon Aug 27 19:32:03 2001 From: wtanksle at dolphin.openprojects.net (William Tanksley) Date: Mon, 27 Aug 2001 23:32:03 GMT Subject: Art of Unit Testing: Part 2 References: Message-ID: On Sun, 26 Aug 2001 21:26:34 -0700, Jesse W wrote: >William Tanksley wrote: >> On Fri, 24 Aug 2001 16:59:41 -0700, Jesse F. W wrote: >> >William Tanksley wrote: >> >> On Fri, 24 Aug 2001 11:51:07 -0700, Jesse F. W wrote: >> >> >if self.app.cnt_player.battle.kind=='stop': how would this be >> >> >tested? >> >> The problem is that each object should have an interface to do >> >> everything it needs to do. You shouldn't have to reach inside any >> >> object to inspect how it's doing its job. The above code should >> >> look like 'if self.app.anyPlayersInStoppedBattles():' (I'm assuming >> >> that's an appropriate name). >Ok. This still seems somewhat excessive to me, but I'll let it go for >now. If it looks excessive to you, it's definitely wrong for what you're doing. You shouldn't violate the law of Demeter, but you can find a solution which doesn't appear excessive to you and which doesn't violate the law. One of the main tenets of extreme programming is that programming should be fun; if the design of your program is making you uncomfortable it's a bad design. I suggested that name based on a guess. I now know a lot more about your code; not only could I suggest a better name, I could possibly suggest a different design which would make sense to both of us. >Now, although your point that if you could not understand what the >code did, it was probably written wrong has value, and especially if I >have to try twice before I can explain it correctly, I am going to try >and explain it again. :-) Your explanation was perfect this time. Thank you. > The game I am making is a card game representing a auto >race. The battle part of the above line refers to the top card in a pile >of cards called the battle pile(hence the name). All cards have a >attribute called kind which represents(and I know this is confusing, >and should be refactored) the general type of the card. In your >terms, the method should be called >"CurrentPlayerHasAStopTypeCardOnTopOfTheirBattlePile". (Ooh, >that looks sort of like I am being sarcastic. Since this is email, I will >specifically say, I do not mean to be.) It doesn't look at all sarcastic; I know programmers who write names like that without wincing. I can tell that you don't like it, and neither do I. Unfortunately, coming up with a better name requires me to know a little more of the context. Right now all I know is that this information is a property of an object named 'app'. App doesn't mean _anything_ to me, but I'm going to guess that it means "application". I don't know why an application should be able to know whether a player in a game is stopped, so the first thing I'd do is rename "app" to "theGame". Perhaps it makes sense to say "theGame.currentPlayerStopped()". What do you think? (You answer below, so let's see:) >> >I don't see how the method could work if there was no >> >current player object. >> The existance of a 'currentPlayer' wouldn't matter to this object if >> theGame had a method to answer this important question. In order for >> me to write this code, though, I have to know what it means to theGame >> when the current player is stopped. >I don't think it would mean anything to the game if the current player >was stopped. The current player could play different cards, but I >don't think the game would care. Okay. If the game doesn't care about whether the current player is stopped, then nothing above the level of the game should ever care. (Since the game is the only thing that knows about the current player.) >By the way, I use the self.app object mainly as a central storehouse of >links to the various subparts of the total program. The app object does >not really know or do much. Ah. I would consider the app object unworthy of existance, then. Every object should have a meaning of its own. However, if you absolutely cannot find a way to give it a meaning, you must violate the law of demeter every time you use it. >> I can rewite some code right now, though: >> class Player: >> def isStopped(): >> return self.battle.kind == 'stop' >> Now we can reasonably talk about a player being stopped -- players can >> tell you whether or not they're stopped. >I was going to write here, "I really don't understand what this >changes", but just as I was writing it, I understood. It adds a level of >abstraction, allowing the name battle to be changed, and even the >name kind or its value, could be set to something else. Yes, that's a good insight. It also allows the code to look like our speech. You mentioned to me that the current player was stopped; to me, that indicates that you picture a player as being able to be stopped. >From this it's natural to give players the ability to tell whether they're stopped. >> Of course, you'll recognise that I'm still violating the law of >> Demeter. The reason I'm doing that is that I don't know why each >> player needs a "battle". Are you implying that there's a battle going >> on inside every player? Perhaps your battles should contain players, >> rather than your players containing battles. At any rate, what does >> it mean to ask a player's battle whether it is of the stopped kind? >> Why does having a stopped battle also stop the player? I understand now that every player has a number of decks, and one of them is the battle deck. Yes, I've played this game before :-). Given that, I think my implementation of isStopped is sufficient, and doesn't violate the law of demeter. >> 2. When you're testing an object, test ONLY properties of >> that object, never properties of contained objects. >Ok; that's the law of Demeter. Yes, the law of Demeter does require that. >> 3. Test ALL of the properties of the object which will be used by any >> other object. If a property hasn't been tested, don't ever use it; if >> you're about to use a property in a manner which hasn't been tested, write >> a test for that property and add that test to the object's unit tests. >Ok; but how to you "test the properties" without testing the implemented? Let's look at one of the properties of a Player in your game. I just decided that "isStopped" would make a good property. Now, in order to write a test I have to create a player, put him into a non-stopped mode, check that isStopped isn't true, and then put him into a stopped mode. Probably the best way to do this is to force the Player to play a Go, then play a Stop onto his battle stack (typical in Mille Bournes), then have him play another Go. Note that I'm speaking in terms of the Player object; it sees the world in terms of a complete set of game rules. When I play a Stop against him, the Player *knows* that it goes on his battle deck; nothing else needs to know about the existance of the battle deck. In fact, you may not actually use a real deck (that is, a complete history of all cards); you might simply use a 'stopped' state and a most-recently-played card. Oh, and a speed limit. The point is that only the Player needs to know how he's keeping track of those details. -- -William "Billy" Tanksley From wolf359_ at gmx.net Sat Aug 4 08:51:45 2001 From: wolf359_ at gmx.net (Thomas Weidner) Date: Sat, 4 Aug 2001 14:51:45 +0200 Subject: no do...while ? Message-ID: <9kgr1i$qh$01$1@news.t-online.com> Hi NG, I think everybody knows what a do{...}while(...); loop in c is,but is there something like that in python ? From ljohnson at resgen.com Tue Aug 7 15:20:29 2001 From: ljohnson at resgen.com (Lyle Johnson) Date: Tue, 7 Aug 2001 14:20:29 -0500 Subject: Checking for attribute in the current module with getattr( ) References: Message-ID: > Now, as indicated I don't really know what object to send in to the > hasattr function, indicated with "???" - is what I'm trying to do > possible, and how should I in case do it? How about: if globals().has_key("func1"): print "This module defines func1" else: print "This one doesn't" Hope this helps, Lyle From joonas at olen.to Sun Aug 26 16:59:24 2001 From: joonas at olen.to (Joonas Paalasmaa) Date: Sun, 26 Aug 2001 23:59:24 +0300 Subject: Text Formating in Python References: <1cdcc92f.0108252020.20aaa02e@posting.google.com> Message-ID: <3B89632C.9FF6A6E@olen.to> Lee Hulbert wrote: > > Is there a simple way to format a text string before printing to the > screen? > > Specifically, I have a list of 80 numbers, and I want to print the > list, with each number a different color if it is positive, negative, > or 0. curses module can do the job. http://www.python.org/doc/current/lib/module-curses.html From gcash at luncheonmeat.cfl.rr.com Wed Aug 29 20:09:29 2001 From: gcash at luncheonmeat.cfl.rr.com (gcash) Date: Thu, 30 Aug 2001 00:09:29 GMT Subject: language lawyering - doc strings Message-ID: <66b6xvc0.fsf@cfl.rr.com> I know this is being pedantic, but where's the syntactical spec for documentation strings in the language reference? I was looking at the 2.1.1 docs and I'd expect it to be in "4.1 Code blocks, execution frames, and namespaces" but the only reference to documentation strings is where it mentions the __doc__ attribute. I noticed this when someone asserted you can't have doc strings for classes. -gc -- Favorite god: Thor Favorite song: "Hammer Time" Motto: "Use a bigger hammer" In my toolbox: 1 screwdriver, 6 hammers. Often heard saying: "... then I used a hammer on it" From mikael at isy.liu.se Thu Aug 23 10:42:30 2001 From: mikael at isy.liu.se (Mikael Olofsson) Date: Thu, 23 Aug 2001 16:42:30 +0200 (MET DST) Subject: enhancing slicing In-Reply-To: <9m31fp$27s$1@thorium.cix.co.uk> Message-ID: On 23-Aug-2001 gbreed at cix.compulink.co.uk wrote: > v[5 :][: 2] Yuck! > v[:5 ][ -2:] Double yuck!! Besides being ugly (for your purpose), it's already valid syntax: >>> v=[[1,2,3],[4,5,6],[7,8,9]] >>> v[1:][:1] [[4, 5, 6]] >>> v[:1][1:] [] > Shall I start on the PEP? Please don't. Spend your time on something that at least has a slight chance of being accepted instead. See other comments in this thread. /Mikael ----------------------------------------------------------------------- E-Mail: Mikael Olofsson WWW: http://www.dtr.isy.liu.se/dtr/staff/mikael Phone: +46 - (0)13 - 28 1343 Telefax: +46 - (0)13 - 28 1339 Date: 23-Aug-2001 Time: 16:31:57 /"\ \ / ASCII Ribbon Campaign X Against HTML Mail / \ This message was sent by XF-Mail. ----------------------------------------------------------------------- Link?pings kammark?r: www.kammarkoren.com From markus.schaber at student.uni-ulm.de Fri Aug 3 08:44:44 2001 From: markus.schaber at student.uni-ulm.de (Markus Schaber) Date: Fri, 03 Aug 2001 14:44:44 +0200 Subject: 2.2 features References: <15206.48884.18637.676324@beluga.mojam.com> <200107311705.NAA16444@cj20424-a.reston1.va.home.com> <15206.61485.360973.566871@beluga.mojam.com> <200107311904.PAA17115@cj20424-a.reston1.va.home.com> <15207.1733.965818.91745@beluga.mojam.com> <200107312309.TAA17435@cj20424-a.reston1.va.home.com> <20010731202441.M19610@tux.distro.conectiva> <3B6A2951.71F325D0@cosc.canterbury.ac.nz> Message-ID: <3B6A9CBC.EAF5CC6A@student.uni-ulm.de> Hi, Greg Ewing wrote: > > If you insist. I think "x in type" is cleaner than isinstance(x,type). > > The main problem with the second one is that it requires memory of the > > order of the arguments, as well as the name of the syntax. > > How about > > x in class c > > for isinstance, and > > class c1 in class c2 > > for issubclass? Reads very smooth in my eyes. markus -- Markus Schaber -- http://www.schabi.de/ -- ICQ: 22042130 +-------------------------------------------------------------+ | Allgemeine Sig-Verletzung 0815/4711 | +-------------------------------------------------------------+ From gerhard.nospam at bigfoot.de Mon Aug 6 20:01:52 2001 From: gerhard.nospam at bigfoot.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Tue, 7 Aug 2001 02:01:52 +0200 Subject: Newbie Question! References: Message-ID: On Mon, 06 Aug 2001 20:51:36 -0000, ksunair at yahoo.com wrote: >Hello, > >I am new to Python and interested to develop a new website using only >Python. I would like to know, few things > >1. Is there a simple example out there to print 'Hello World' on web? >like the one in PHP > #!/usr/bin/env python print "Content-type: text/html\n" print "hello World" The above is an equivalent Python cgi script. >2. Is there a tutorial or documentation available anywhere on the >net, how to use MySql with Python? The closest thing is the DB-API documentation (MySQLdb is an implementation of the DB-API). You can find the docs on www.python.org -> Docs -> Topic Guides -> Database - I'm too lazy to check it in my browser now :-) The mySQLdb module contains some examples, but I'm not aware of an all-beginner tutorial, the docs suppose you're already fairly familiar with SQL. Basically it works like this: import MySQLdb # or whatever other PostgrSQL/Oracle/... module # Open database connection con = MySQLdb.connect( host = "dbserver", user = "me", passwd = "secret" ) # Get a cursor object cur = con.cursor() # Make a select/insert/update cursor.execute( "select * from test where id>50" ) # In case of a select, fetch the results and do something with them print cursor.fetchall() con.close() Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://highqualdev.com public key at homepage public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y: x+y, [chr(ord(x)^42) for x in list('zS^BED\nX_FOY\x0b')]) From guignot at wanadoo.fr Sat Aug 11 19:55:23 2001 From: guignot at wanadoo.fr (Capitaliste Guignot) Date: Sat, 11 Aug 2001 23:55:23 +0000 Subject: Python + Windows + Webserver References: <9l3sdq$5as$1@cyan.nl.gxn.net> Message-ID: <3B75C5EB.DEA76048@wanadoo.fr> chris liechti wrote: > > "Chris Eidhof" wrote in > news:9l3sdq$5as$1 at cyan.nl.gxn.net: > > Hello, I'm looking for a *simple* way to set up a webserver under > > win98, the webserver must handle python scripts. I've tried apache, but > > it didn't work. Who can help me? > > Please reply by email. > > www.zope.org zope is not really a web server. From goldwasser at demog.berkeley.edu Tue Aug 7 16:25:53 2001 From: goldwasser at demog.berkeley.edu (Lloyd Goldwasser) Date: Tue, 07 Aug 2001 13:25:53 -0700 Subject: encapsulation? Message-ID: <3B704ED1.EFA6AEA8@demog.berkeley.edu> As a recent convert to Python (I have C, Objective-C, and Scheme, among others, in my past), I'm curious about its lack of encapsulation. 'Way back when I was using Objective-C -- and many other OO languages seem to have a similar perspective -- there was a lot of emphasis on the ability to keep the contents of objects independent of outside influence except via well-delineated mechanisms. Security and reliability were cited as major benefits of this approach: every object knew exactly what the outside world was going to see and exactly how the outside world might act to change its state. Python provides only the private variable name-mangling mechanism for "encapsulating" the contents of objects, and it's weak enough that dir(ClassName) announces all of those "hidden" contents to the world, at which point they can be altered at will. I wonder whether this approach, making encapsulation a matter of convention rather than something that's provided by the language, is a liability. It would seem to make Python ineligible for use in projects that need a more reliable separation between objects and outside access. How hard (or desirable) would it be to provide a stronger kind of encapsulation in Python? Lloyd -- Lloyd Goldwasser Department of Demography goldwasser at demog.berkeley.edu 2232 Piedmont Ave. #2120 (510) 642-0525 University of California fax: (510) 643-8558 Berkeley, CA 94720-2120 From aleaxit at yahoo.com Tue Aug 7 10:44:39 2001 From: aleaxit at yahoo.com (Alex Martelli) Date: Tue, 7 Aug 2001 16:44:39 +0200 Subject: [Python-Help] data entry validation with Tkinter References: <997178610.17738.39.camel@lewis> Message-ID: <011701c11f4f$7cfc6e00$102b2bc1@cadlab.it> "Ken Guest" writes: ... > attempts at specifying python procedures for vcmd and invcmd only seem > to be called when the app in initialising and don't exactly work. If you call a function (or other callable), it will indeed be called; so: > For example, with > > self.__entry = Entry(newframe, validate='key', vcmd=self.validate('%P'), > invcmd=self.invalid()) this immediately calls self.validate and self.invalid, because their mention is followed by parentheses '()' with arguments in between. Then arguments vcmd and invcmd are set to the RESULTS of these calls. What you need to do is, set the argument to a CALLABLE (an object that can be called, such as a function). If you want self.invalid to be called without arguments when invcmd 'happens', invcmd=self.invalid will work just fine. It's a little bit more work when you want to pre-specify some of the arguments to be passed to the callable you want (technically called 'currying', in honor of the great mathematician Haskell Curry: look for "currying" in the search engine of activestate's "Python Cookbook" site, there's a couple useful general recipes about it). Some Python programmers like 'lambda' for that purpose. Me, I prefer to give a name to the functions I write, so I'd write a little local function definition and then pass that local function -- in Python 2.2, that's: def validate(whatever): return self.validate('%P', whatever) self.__entry = Entry(newframe, validate='key', vcmd=validate, invcmd = self.invalid) In Python 2.1 it's slightly more work (unless you have a from __future__ import nested_scopes at the start of your module), and in 2.0 or earlier you do need the extra work anyway, because there was no support for nested scopes (so from within the validate local function name 'self' was not implicitly defined), e.g.: def validate(whatever, self=self): return self.validate('%P', whatever) and the setting of self.__entry just as above. This assumes that when vcmd 'happens' it will supply an argument to the callable you set for it in the Entry(...) call (correct if that isn't so -- I'm no Tkinter expert:-). Another possibility, since you ARE using a bound-method (self.validate) anyway, is to hold the '%P' as part of self's state (self.pattern='%P', say) and just use cmd=self.validate just as shown for invcmd. That wouldn't work well if you want to use self.validate to validate many fields with different patterns, though (but you could have a method per validation pattern, if there aren't too many). Alex From bsass at freenet.edmonton.ab.ca Fri Aug 17 14:27:38 2001 From: bsass at freenet.edmonton.ab.ca (Bruce Sass) Date: Fri, 17 Aug 2001 12:27:38 -0600 (MDT) Subject: Any comments? My draft of a new PEP. In-Reply-To: <3llhl9.u49.ln@gargamel.hqd-internal> Message-ID: On Fri, 17 Aug 2001, Gerhard H?ring wrote: > On Thu, 16 Aug 2001 22:44:34 GMT, Courageous wrote: > >> [me] > >> To avoid long transition periods when a new Python feature requires a new > >> keyword, this PEP proposes to reserve a set of keywords "in advance". > > > > A good idea overall, IMO. > > > >> abstract, directive, foreign, interface, static, yield > > > >I think we'd have to talk seriously about _which_ keywords, and peronally > >believe that Guido and team should handle the whole thing. > > I agree. But they should IMHO reserve any keywords they might possible use in > future versions in a bunch. This would avoid from __future__ kludges and reduce > the temptation of "clever" reusing of existing keywords. It may reduce "__future__ kludges", but __future__ can do more than just tie up keywords... I don't thing many uses of __future__ would be avoided. In a sense, it would be like trading a working time machine for prescient visions. - Bruce From skip at pobox.com Sat Aug 25 18:12:36 2001 From: skip at pobox.com (Skip Montanaro) Date: Sat, 25 Aug 2001 17:12:36 -0500 Subject: Question about indentation and bugs In-Reply-To: References: <3B85E13D.72427622@engcorp.com> Message-ID: <15240.8916.650451.753935@beluga.mojam.com> Paul> On Fri, 24 Aug 2001 01:08:13 -0400, Peter Hansen Paul> wrote: >> Dave Swegen wrote: >> Maybe more importantly, if you don't actually use TABs, >> or you consistently treat TABs as eight spaces, the problem >> won't arise. Paul> Four spaces is now the "standard" according to PEP 8, replacing Paul> the old style guide. Paul> http://python.sourceforge.net/peps/pep-0008.html Paul> But then, the style guide says the same thing... How long ago was Paul> 8 considered the norm? Paul> Good thing they reduced it ... it doesn't take too many levels of Paul> indentation to get pretty cramped in a typical 80-character Paul> window! You're talking about two different things. The standard indentation is four spaces, but if you treat a TAB character as eight spaces you'll be okay (though with "python -t" you might get some indentation warnings). It's when you treat a TAB character as something other than 8 spaces that mixing spaces and TABs becomes a problem. -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From jknapka at earthlink.net Thu Aug 9 15:49:52 2001 From: jknapka at earthlink.net (Joseph A. Knapka) Date: Thu, 09 Aug 2001 19:49:52 GMT Subject: iterating through lists to delete elements References: Message-ID: <3B72E960.921F097C@earthlink.net> Bjorn Pettersen wrote: > > > From: Mark Robinson [mailto:m.1.robinson at herts.ac.uk] > > > > Can anyone advise me the best way to iterate through a list > > and deleting > > elements that don't meet a certain criteria. > > You can use either filter or list comprehensions: So it seems that (shudder) There's More Than One Way To Do It. Isn't there supposed to be one (obvious) way? -- Joe Knapka "You know how many remote castles there are along the gorges? You can't MOVE for remote castles!" -- Lu Tze re. Uberwald // Linux MM Documentation in progress: // http://home.earthlink.net/~jknapka/linux-mm/vmoutline.html 2nd Lbl A + 1 = 2nd Pause 2nd Prt GTO 2 R/S From peter at engcorp.com Mon Aug 6 20:54:07 2001 From: peter at engcorp.com (Peter Hansen) Date: Mon, 06 Aug 2001 20:54:07 -0400 Subject: Clearing The Interactive Python Environment References: <8beb91f5.0108061409.49f480e8@posting.google.com> Message-ID: <3B6F3C2F.9DB68902@engcorp.com> Ben C wrote: > > Sorry to bother the group with such a trivial Q but for some reason I > can not find an answer to this in the docs ... how does one 'clear' > the Python environment .... so all loaded modules and variables are > freed? (ie return the Python environment back to its initial state at > start up) I assumed it would have been in the sys module? Since the subject mentions "Interactive", the answer is: On Unix: Ctrl-D then 'python' On Windows: Ctrl-Z then 'python' :-) (No other options are guaranteed effective.) From robin at jessikat.fsnet.co.uk Sat Aug 18 04:00:15 2001 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Sat, 18 Aug 2001 09:00:15 +0100 Subject: FEEDBACK WANTED: Type/class unification References: <3B7400C1.BA52170B@SoftHome.net> <1rjctgABtPe7Ewxc@jessikat.demon.co.uk> Message-ID: In article , Guido van Rossum writes >Robin Becker writes: > >> >If you could subclass modules (you can't yet in 2.2a1, but you will in >> >2.2), you could do this for module attribute references, but global >> >variable references don't go through __getattr__ and __setattr__ on >> >the module -- they use the C APIs PyDict_GetItem and PyDict_SetItem >> >and you can't override those. >> > >> >--Guido van Rossum (home page: http://www.python.org/~guido/) >> >> OK I'll bite. What's a module attribute? I naively thought that >> >> #M.py >> X=3 >> .... >> >> makes X a global in M and also an attribute of module M? Obviously I'm >> wrong. Are there things (apart from builtins etc) which are more global >> than X in M's scope? > >It's purely a syntactical question. When used from inside the module, >it's a global. When used from the outside as M.X, it's a module >attribute. > >--Guido van Rossum (home page: http://www.python.org/~guido/) Ok so is the implication that external references to M.X could possibly be controllable by get/set mechanisms, but inside M such controls wouldn't work? Inside M you could presumably import M and work with M.X. -- Robin Becker From nas at python.ca Thu Aug 23 14:01:38 2001 From: nas at python.ca (Neil Schemenauer) Date: Thu, 23 Aug 2001 11:01:38 -0700 Subject: Really stupid question regarding PEP 252 and type/class unification In-Reply-To: ; from jacobkm@dont.spam.me.cats.ucsc.edu on Thu, Aug 23, 2001 at 05:59:04PM +0100 References: <8a12e538.0108221144.5b74df26@posting.google.com> <8a12e538.0108230607.30481024@posting.google.com> Message-ID: <20010823110138.A10830@glacier.fnational.com> Jacob Kaplan-Moss wrote: > I think I see what Russel is getting at here... the point is, myInt is > an instance of class MyInt when it is first created, but what if I want > to change the value of myInt without modifying the class? You can't. ints are immutable. > >>> class MyInt(int): > ... pass > >>> x = MyInt() > >>> isinstance(x, MyInt) > 1 > > So here x is still a MyInt object. Now I want to change the x so that x > holds the value 5 but is still a myInt object. So I try: > > >>> x = 5 You are quite confused about how Python works. The above statement binds the name "x" to the object "5". > So, the question is, can I treat a MyInt the same way as I can treat an > int? Or do I have to do something like "x.set(5)" or "x = MyInt(5)"? Eventually you should be able to treat it just like an int. Neil From grante at visi.com Fri Aug 10 23:51:11 2001 From: grante at visi.com (Grant Edwards) Date: Sat, 11 Aug 2001 03:51:11 GMT Subject: Question about Tkinter References: <9l03s7$6q9f0$1@ID-54723.news.dfncis.de> <9l07a201rdj@enews4.newsguy.com> <9l1fnr01f4d@enews2.newsguy.com> Message-ID: On Fri, 10 Aug 2001 22:20:08 +0200, Alex Martelli wrote: > ... >> > Use different callables for the callbacks -- if it must be > ... >> A slightly different way is to use lamgda. It's best for >> simple cases where you just want to pass a few arguments that > >I disagree with your claim that it's best. My phrasing was bad. What I meant was that of the various situations where one might use lambda the simplest cases are the best candidates for lambda usage. I wasn't claiming that lambda is the best option compared to curry or local defs. >> 15 b.bind("",lambda event,xx=x,yy=y: board.toggleSpace(xx,yy)) > >I'd code this (assuming no nested scope, just as you're >assuming): > > def togglethis(event, xx=x,yy=y): > board.toggleSpace(xx,yy) > b.bind("", togglethis) That's definitely better. For some reason (undoubtedly due to restrictions in other languages) I often forget that I can use a "def" inside the body of a function. In this case, it's probably a lambda because this program was translated from Scheme, and it was already a lambda. :) >Same for my favourite solution, except that there is no lambda >form -- the local def takes lambda's place. > >> Curry is probably a more readable solution to a non-Schemer. >> ;) > >I am or used to be enough of a schemer that our common-lisp >friend recently caught me out as an adorer of tail recursion, Yup, I was recentlry caught with my Scheme history showing when I assumed that recursion was a preferred flow-control mechanism in CL. >but I still dislike _Python's_ lambda, with all of its limits >and issues. It's obscure _and_ crippled. One or the other could be tolerated. I've been tripped up by lambda's scoping issues more than once (but local def's have the same problem -- at least for now). >A local def appears to me to be a preferable solution in just >about every case. I can't really come up with an example where a lamba is superior to a local def for anything that's not completely trivial. The only place a lamba seems like a good option is applying a trivial function using map() or filter(). But, that usage has been made largely redundant with list comprehensions. But -- since there's no such thing as tuple-comprehensions, you still need filter() if you're working with tuples, so maybe lambda still has some utility is situations like: t2 = filter(lambda x: x>0, t1) On a completely different topic, I don't quite understand why, when passed a tuple, map() returns a list and filter() returns a tuple. I was quite surprised that they do different things. -- Grant Edwards grante Yow! NEWARK has been at REZONED!! DES MOINES has visi.com been REZONED!! From nhodgson at bigpond.net.au Sat Aug 4 20:01:47 2001 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Sun, 05 Aug 2001 00:01:47 GMT Subject: Case insensitivity References: Message-ID: Tim Rowe: > But the sort of changes being > /discussed/ (but mercifully mainly not implemented) would be more like the > transition from BCPL to B to C, and would merit completely different > names. Are you saying that some changes are reasonable while keeping the Python name but others are not? The problem here is different views on the impact and benefits of various changes. IMO, the change from deterministic finalisation to indeterministic finalisation, which occurred first in Jython and then when Python got garbage collection (was that in 2.0? the past is all a blur now) was more significant than either case sensitivity or int on int division. The world of software is changing quite rapidly with techniques that were formerly resisted because of cost (such as garbage collection, machine independent code, and verifiable execution environments) now accepted because of improvements in implementation and in hardware speed. If Python doesn't change then other languages which are new or which adapt will be more attractive. I don't want to see Python frozen into irrelevance. Neil From anthony at interlink.com.au Thu Aug 23 01:55:45 2001 From: anthony at interlink.com.au (Anthony Baxter) Date: Thu, 23 Aug 2001 15:55:45 +1000 Subject: newbie question In-Reply-To: Message from "George Garnett" of "Thu, 23 Aug 2001 04:42:44 GMT." <8R%g7.29820$1p1.2181194@bgtnsc04-news.ops.worldnet.att.net> Message-ID: <200108230555.f7N5tjJ06610@mbuna.arbhome.com.au> >>> "George Garnett" wrote > I suggest looking on-line for computer > magazine articles rather than relying on user's opinions (including myself). How are "computer magazine articles" any more relevant than user opinions. At least with user opinions you're hopefully going to get someone who's used the technology, and isn't just regurgitating someone else's press release. > specific market niche just like java. However, I've seen many companies go > belly up and I wonder about jpython. How can they compete with an upcoming > powerhouse like JSP in the long term? You seem to have some wierd idea that a) jython (not jpython) is driven by some wierd commercial success need where it must control all and destroy all competition. b) it's created by a company. It's _open_ _source_. There's no company to go belly up. > By the way, for all you python people out there, I did read 'thinking in > java' by Eckel and about 1/4 of a book on jpython (ok, so I borrowed the > book). I've read about 25 books on java an its related languages so far. I > guess I was just turned off by its C language like low level programming > syntax. I prefer java's low level syntax instead (again, not that I'm biased > in any way!). ?? Python's got a C language like syntax, compared to Java? What _are_ you on? That you needed to read 25 books on Java would also suggest, to me, part of the problem with Java, C++ and the like - they're just too damn complex. Rather than reading "1/4 of a book on jpython", why not try reading something on python - for instance, the excellent on line "Dive Into Python" text at www.diveintopython.org. Jython is just Python, implemented on top of the JVM. Jython and Java are complementary languages, in the same way that CPython and C are complementary. If MS's .NET succeeds, well, then, Python.NET will still be there, and will run on top of the .NET VM. And it's still Python. Anthony -- Anthony Baxter It's never too late to have a happy childhood. From boud at rempt.xs4all.nl Mon Aug 27 05:15:07 2001 From: boud at rempt.xs4all.nl (Boudewijn Rempt) Date: 27 Aug 2001 09:15:07 GMT Subject: Qt licensing hell! References: Message-ID: <9md32r$80k$1@news1.xs4all.nl> Bruce Sass wrote: > If TrollTech wants you to make all that stuff available, then you > really have little choice except to make it available... but I doubt > anyone will insist you package it up in the same file a your app. They don't. Article 1 of the non-commercial license allows you to redistribute their Non-commercial windows distribution of the development environment for Qt, provided you don't leave things out. So, if you want to put non-commercial Qt for Windows on your ftp server, you can. You don't have to, not even if you want to distribute an app you made with it. Article 4 allows you to develop apps with Qt and distribute them with all necessary runtime components, provided that your app is gratis and people can get at the source. You don't even have to bundle the binary and the source of your app together, just making the source available somehwere is enough. See the license at: http://www.trolltech.com/products/download/freelicense/noncomm-license.html The only complicated point is where it relates to developing scripting wrappers - they put that in especially for PyQt, I'm afraid, to ensure that apps developed with PyQt and the non-commercial edition of Qt fall under this license. -- Boudewijn Rempt | http://www.valdyas.org From Paul.Greer1 at btinternet.com Sun Aug 26 20:20:30 2001 From: Paul.Greer1 at btinternet.com (Paul Greer) Date: Mon, 27 Aug 2001 01:20:30 +0100 Subject: problem with pythonwin32 Message-ID: <9mc3m3$jk3$1@plutonium.btinternet.com> Might sound like a silly question but how do I get a script to run as a program from an Icon on windows. When ever I do the DOS box opens and immediately closes. the same in linux I change the py file with chmod -x and set the path but i cant seem to get the program to run by just typing the name? Id appreciate the help From tim.one at home.com Tue Aug 7 20:30:27 2001 From: tim.one at home.com (Tim Peters) Date: Tue, 7 Aug 2001 20:30:27 -0400 Subject: combinations of variable length nested lists In-Reply-To: <3B6FE3B6.5020605@herts.ac.uk> Message-ID: [Mark Robinson] > ... > I have a nested list structure of the following format: > [[2, 3, 4, 5], > [4, 5, 6, 7, 34], > [6, 2, 7, 4] > .... > .... > ] > > I want to generate all possible combinations that take one element from > each nested list > > i.e > [2, 4, 6, ..., ...] > [2, 4, 2, ..., ...] You've seen many interesting approaches to this. Cool! Here's one for brevity, but relying on 2.2: from __future__ import generators from test.test_generators import conjoin alist = [[2, 3, 4, 5], [4, 5, 6, 7, 34], [6, 2, 7, 4]] count = 0 for one in conjoin(map(lambda x: lambda: iter(x), alist)): count += 1 if count < 6 or count > 75: print "%2d: %s" % (count, one) elif count == 6: print "..." That prints: 1: [2, 4, 6] 2: [2, 4, 2] 3: [2, 4, 7] 4: [2, 4, 4] 5: [2, 5, 6] ... 76: [5, 7, 4] 77: [5, 34, 6] 78: [5, 34, 2] 79: [5, 34, 7] 80: [5, 34, 4] The "conjoin" imported there is a simple but general backtracking schema, named in honor of Icon's "conjunction" operator. It marches over all cross-products of a list of no-argument functions that return iterators (think that real fast 10 times ), and generating a full cross-product is the simplest thing you can do with it. test_generators.py builds some fancier things on top of it, and has 3 distinct implementations of conjoin() (from purely recursive to purely iterative). Since the implementation is generator-based, you don't have to compute all the results at once: >>> get = conjoin(map(lambda x: lambda: iter(x), alist)).next >>> get() [2, 4, 6] >>> get() [2, 4, 2] >>> get() [2, 4, 7] >>> get() [2, 4, 4] >>> get() [2, 5, 6] >>> Note that since "get" is also an iterator, nothing to stop you from feeding it back into conjoin, either! The disgusting possibilities are left to sicker imaginations than mine. cute-but-not-mandatory-ly y'rs - tim From brueckd at tbye.com Thu Aug 16 11:19:35 2001 From: brueckd at tbye.com (brueckd at tbye.com) Date: Thu, 16 Aug 2001 08:19:35 -0700 (PDT) Subject: newbie question: using Python to coordinate C++ program and use gnuplot In-Reply-To: <3B771A9C.3BB8317@princeton.edu> Message-ID: On Sun, 12 Aug 2001, Eduardo Zea wrote: > 2) A python program that opens gnuplot in a new terminal, and sends to > it a comand like "plot output.txt". And re-issues this command each time > it updates output.txt, so that gnuplot displays the data as it is being > produced by the program. Hi Eduardo, Have you tried Gnuplot.py yet? (It's the first link that shows up when you search on Google for 'python gnuplot'). Anyway, it's _very_ easy to use and works great. While you're on sourceforge downloading Gnuplot.py, also go get Numerical Python if you don't have it already as Gnuplot.py needs it. -Dave From learnpython at hotmail.com Mon Aug 13 03:29:53 2001 From: learnpython at hotmail.com (Learn Python) Date: Mon, 13 Aug 2001 07:29:53 +0000 Subject: wxPython Or Tkinter Advise PLEASEEEEEEEEE Message-ID: hi all, I know that this is a redundant question. I started off with Tkinter from Programming Python book ( explained in detail). I liked it. Then i stumbled across wxPython and the kind of qoutes/comments i found on the web site were so impressive. for eg : "Why the hell hasn't wxPython become the standard GUI for Python yet?" -- Eric S. Raymond Am so confused??? the docs were OK. There does'nt seem to be a book on it either :-( Then can anyone answer the above question: "Why the hell hasn't wxPython become the standard GUI for Python yet?" :-) what s'd i be doing? I have to say here that i dont use python @ work but am learning out of my own interest. But w'd like to master atleast one GUI package. thanks in advance, karthik _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp From dalke at acm.org Thu Aug 16 11:04:04 2001 From: dalke at acm.org (Andrew Dalke) Date: Thu, 16 Aug 2001 16:04:04 +0100 Subject: Dumb python questions References: <7xd75xlv86.fsf@ruckus.brouhaha.com> <7xwv45sqhk.fsf@ruckus.brouhaha.com> <7xofphd4ql.fsf@ruckus.brouhaha.com> <3B7A6E28.7EB7A9FF@engcorp.com> <7xu1z8pv9t.fsf@ruckus.brouhaha.com> <9lfq7c$kn0$1@slb5.atl.mindspring.net> <9lhbpk01tgd@enews3.newsguy.com> Message-ID: <9lhg5f$8oe$1@slb6.atl.mindspring.net> Me: >> Huh? "right now?" There's almost nothing being dicussed except >> for '/' which will break even 5+ year old code. The new keyword, Alex: >Hmmm -- it looks to me we were VERY close to a BDFL pronouncement >that assignment to aninstance.__class__ was going away, Err, yeah, and that. :) And __getattr__ will be called for all attribute lookups. That shatters a lot of my code. Andrew From m.1.robinson at herts.ac.uk Wed Aug 8 11:29:36 2001 From: m.1.robinson at herts.ac.uk (Mark Robinson) Date: Wed, 08 Aug 2001 16:29:36 +0100 Subject: How to iterate throuhg dictionary References: <9kqvaa$tbl$1@zeus.man.szczecin.pl> <3B711D6B.3030902@herts.ac.uk> <3B7147BB.2000201@herts.ac.uk> Message-ID: <3B715AE0.2060402@herts.ac.uk> Sorry to be a pain in the rear, but I have tried this with dicts containing nultiply nested lists and it is still printing it all on one line. Strange.......and annoying cos it sounds like something I would use alot cheers blobby Fran?ois Pinard wrote: >> Fran?ois Pinard wrote: > >>> It is often nice to do: >>> import pprint >>> pprint.pprint(d) >> > > [Mark Robinson] > >> I just had a quick play with that, and I can't see any difference between >> your example verbatum and simply print d. > > > Oh, then your `d' should be simple. `pprint.pprint' would print long or > complex structures on multiple lines, all nicely indented. Dictionaries > entries are shown sorted by key. I find it so useful that I forever had: > > import pprint > pp = pprint.pprint > > in my `.pythonrc' filean I could use thinks like `pp(d)' interactively. > From skip at pobox.com Wed Aug 22 08:24:40 2001 From: skip at pobox.com (Skip Montanaro) Date: Wed, 22 Aug 2001 07:24:40 -0500 Subject: eval errors tracing In-Reply-To: References: Message-ID: <15235.42120.175174.969952@beluga.mojam.com> Sergey> I don't want to get errors printed as the standard tools do. I Sergey> want to get the line number and do some complicated Sergey> manupulations with it (they are really more than just Sergey> string.zfill(lineno, 4)). For now I use a dirty hack: get Sergey> str(exc_info()[1]), then find by a regexp the line number, then Sergey> do what I want. But I consider dirty hacks aren't the best Sergey> solutions. Check out the print_tb code in Lib/traceback.py. It doesn't use dirty hacks to get the line number. It extracts them from the relevant code object using traceback.tb_lineno(): n = 0 while tb is not None and (limit is None or n < limit): f = tb.tb_frame lineno = tb_lineno(tb) # <--- here ... tb = tb.tb_next n = n+1 use-the-source-luke-ly y'rs, -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From cliechti at mails.ch Tue Aug 14 16:29:14 2001 From: cliechti at mails.ch (chris liechti) Date: 14 Aug 2001 22:29:14 +0200 Subject: Typo in Python Tutorial? References: <79179cf5.0108141146.1ce6e2ee@posting.google.com> Message-ID: [posted and mailed] rupe at metro.yak.net (Rupert Scammell) wrote in news:79179cf5.0108141146.1ce6e2ee at posting.google.com: > In the Python Tutorial > (http://www.python.org/doc/current/tut/tut.html), Section 5.1, I > noticed that the pop() method for lists is documented as: > > pop([i]) > Remove the item at the given position in the list, and return it. If > no index is specified, a.pop() returns the last item in the list. The > item is also removed from the list. > > I tried the following: >>>> mylist = ['one','two','three'] list_item = mylist.pop([0]) > Traceback (most recent call last): > File "", line 1, in ? > TypeError: an integer is required the "[]" are there to indicate an optional argument not a python list. this means that you can use pop with either no argument or an integer which specifies which element to pop. if you compare it with http://www.brunningonline.net/simon/python/PQR2.1.html you will see that optional args are indicated with bold brackets to make a clear distinction to python lists. -- chris From qrczak at knm.org.pl Wed Aug 15 04:45:07 2001 From: qrczak at knm.org.pl (Marcin 'Qrczak' Kowalczyk) Date: 15 Aug 2001 08:45:07 GMT Subject: Integer division and remainder References: <7x3d6ui5ye.fsf@ruckus.brouhaha.com> Message-ID: 14 Aug 2001 16:20:57 -0700, Paul Rubin pisze: > 7 / 3 = 2 > -7 / 3 = -3 > > This is kind of strange. Normally you expect (-a)/b to be the same as -(a/b). > That's what happens in most languages, where division rounds towards zero: Donald Knuth says that Python is right and C is wrong, and I agree with him here. I expect a%b for positive b to return a value in the range [0, b). -- __("< Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/ \__/ ^^ SYGNATURA ZAST?PCZA QRCZAK From skip at pobox.com Sun Aug 5 12:41:58 2001 From: skip at pobox.com (Skip Montanaro) Date: Sun, 5 Aug 2001 11:41:58 -0500 Subject: PyGTK/PyGNOME questions In-Reply-To: References: Message-ID: <15213.30550.33763.752382@beluga.mojam.com> Robert> Howdy, all. I'm a long-time C/C++ programmer, still fairly new Robert> to Python. I've got some code I've written using the Robert> PyGTK/PyGNOME bindings, and while they're reasonably Robert> straightforward, I have some questions. Namely, once I use the Robert> create_toolbar or create_menus methods, how do I get a reference Robert> back to an individual button so that I can manipulate it later? I'm not sure, since my PyGtk experience hasn't gotten that far. My first guess would be that if Gtk doesn't provide explicit functions to extract particular child widgets that you'll have to muck around in the output of the containers' children() methods. I suspect you're more likely to get a useful answer from the pygtk at daa.com.au mailing list, however. -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From garrett at cs.colostate.edu Wed Aug 1 23:27:36 2001 From: garrett at cs.colostate.edu (Deon Garrett) Date: Thu, 02 Aug 2001 03:27:36 GMT Subject: Converting from strings to integers References: Message-ID: On 1 Aug 2001 17:49:31 -0700, Stephen Smith wrote: > Hi, I'm new to Python and am just trying out an example of file I/O. > I am trying to read a file (successfully), and then multiply a value > by another static variable. The value from the file was outputting in > the 'string' format, and I need to convert it into an integer. I > tried using the int(x) command, but it doesn't seem to care, it is > still in the string format. The number is a plain integer (87, for > example). How on earth do you convert the value to an integer? > Thanks for your help! use the "atoi" function of the string module. >>> s = "87" >>> type (s) >>> import string >>> i = string.atoi (s) >>> type (i) There is also an atof function in the same module that converts to floats and an atol to convert to Python Long ints. From mike_haspert at credence.com Wed Aug 1 12:37:35 2001 From: mike_haspert at credence.com (Mike Haspert) Date: 1 Aug 2001 09:37:35 -0700 Subject: importing win32com.client.Dispatch with embedded interpreter References: Message-ID: When I saw this in the help (1.4 Embedding Python), I assumed I'd be OK as long as I matched each call to Py_Initialize() with a call to Py_Finalize(); "Sometimes, it is desirable to ``uninitialize'' Python. For instance, the application may want to start over (make another call to Py_Initialize()) or the application is simply done with its use of Python and wants to free all memory allocated by Python. This can be accomplished by calling Py_Finalize(). " Adding a call to Py_IsInitialized() before each Py_Initialize() verifies that it is not initialized, yet my problem persists. Other modules import: For example, usecom.py doesn't throw an exception doing import traceback,string,sys which is what I used to report the exception from trying to import win32com. So we're back to my lack of understanding regarding the message: Traceback (most recent call last): File "c:\scripts\usecom.py", line 4, in f1 from win32com.client import Dispatch File "C:\Python21\win32com\__init__.py", line 95, in ? SetupEnvironment() TypeError: this constructor takes no arguments WAG: Perhaps I have to do something to shut down/finalize the win32com module before it will correctly import a second time?? If so, I've found no clue in the doc,yet. I was hoping to embed Python as a scripting language in a significant automated-test-equipment app, but without the ability to stop/restart the interpreter at will, I'm out of luck. Gordon McMillan wrote in message news:... > [posted and mailed] > > Mike Haspert wrote: > > > The minimal function f1(), below in usecom.py, runs fine from the > > command line, but when I use the C API for the interpreter, it runs > > the first time and fails thereafter. Can anyone see what I'm doing > > wrong? The error message "TypeError: this constructor takes no > > arguments" has me stumped. > > [snip] > > > int minimal(char* modname) > > { > > bool success = false; > > PyObject *mod,*func,*args,*rvals; > > Py_Initialize(); > > [snip] > > It's got nothing to do with f1. > > You can't Py_Initialize() twice. > > - Gordon From mcfletch at home.com Mon Aug 27 06:07:29 2001 From: mcfletch at home.com (Mike C. Fletcher) Date: Mon, 27 Aug 2001 06:07:29 -0400 Subject: Comparing a lot of data efficiently In-Reply-To: Message-ID: <001001c12ee0$1584eef0$0202a8c0@MikeySpace> Um, why not use the (index, index, index) values as _keys_ instead of values in the dictionary? That is: trione = { (i1,i2,i3): triNumber } tritwo = { (i1,i2,i3): triNumber } # not really necessary, see below Then, to iterate: for line in file2: key, localName = getIndices( line ) # key being (i1,i2,i3) for the line otherName = trione.get( key ) if otherName is not None: out.write("%i;%i \n" % (otherName, localName,)) So you don't load up all of the second file, just one line at a time. If you need to check for 1,2,3 == 2,3,1 then just check the various combinations by doing gets for the other possible combinations. HTH, Mike -----Original Message----- From: python-list-admin at python.org [mailto:python-list-admin at python.org]On Behalf Of Marcus Stojek Sent: August 27, 2001 05:34 To: python-list at python.org Subject: Comparing a lot of data efficiently Hi, first let me say that I'm new to Python and that I really love it. Finally I can spend my time solving my problems and not fighting with the programming language. Okay, here is what I do. I have two files (ASCII), each of them containing a huge amount (let's say 100.000) triangles. The format is: Number of triangle,number of first node, number of second node , number of third node \n node are corners of the triangle here. Each node has three coordinates in space, but we don't need them here. The two files are describing exactly the same group of triangles, but the triangles are numbered differently in the two files. So the triangle containing the nodes (12,49583,331) has the number 5 in one file and the number 23094 in the other one. As two triangles can share two nodes I have to compare all three nodes for all triangles. I have two dictonaries: trione={number triangel:1.node,2.node,3.node} (key and values are integer) tritwo=as trione def common(list1,list2): hit=0 for i in list1: for j in list2: if i==j: hit +=1 return hit for t1 in trione.keys(): for t2 in tritwo.keys(): if common(trione[t1],tritwo[t2])>=3: out.write("%i;%i \n" % (t1,t2)) Works fine but it takes years. I tried to remove from the dictionaries the triangles that already have been identified to reduce data. (using pop or slicing) but this slowed the process even more. I know I could speed up things by breaking the loops in common() when one node from list1 is not in list2, but for future use I have to deal with shapes containing more than three nodes. Any idea how I could significantly improve perfomance? In "Programming Python" I learned about tuple stacks, binary search trees and graphs but I'm not sure whether one of those will help. Do I really have to creep back to C? If so, can anyone tell me how to get my dictonaries into a C routine? (I know I have to use SWIG, but a little example would help a lot.) Thanks in advance. Marcus -- http://mail.python.org/mailman/listinfo/python-list From jkraska1 at san.rr.com Sun Aug 19 09:48:52 2001 From: jkraska1 at san.rr.com (Courageous) Date: Sun, 19 Aug 2001 13:48:52 GMT Subject: Experiences converting Python to C++ References: <82399a9.0108190144.cffeff7@posting.google.com> Message-ID: On 19 Aug 2001 02:44:50 -0700, aito at carenet.co.jp (Akio Ito) wrote: >henrik_ekelund at yahoo.com (Henrik Ekelund) wrote in message news:... >> We have to convert a large system (10000 lines) ... Hah. I just read this for the second time. I saw "large system" and so of course saw this as "100,000 lines". A 10,000 line program is a "large system"? Surely thou jesteth? C// From zopista at zopezen.org Wed Aug 22 01:28:56 2001 From: zopista at zopezen.org (Zopista) Date: Tue, 21 Aug 2001 22:28:56 -0700 Subject: Python & IRC : Is it a fantasy or reality References: Message-ID: <008501c12acb$579bf1d0$abcc4e18@cr582427a> A bot for irc has been written in Zope, meaning someone has taken the time to write the modules to connect to irc. A good starting point might be there. http://www.zope.org/Members/TheJester/IrcBot -- Andy McKay From nas at python.ca Mon Aug 20 16:27:13 2001 From: nas at python.ca (Neil Schemenauer) Date: Mon, 20 Aug 2001 13:27:13 -0700 Subject: Lists into lists In-Reply-To: <200820011058375200%mday@apple.com>; from mday@apple.com on Mon, Aug 20, 2001 at 10:58:37AM -0700 References: <200820011058375200%mday@apple.com> Message-ID: <20010820132713.A3297@glacier.fnational.com> Mark Day wrote: > As another poster mentioned, you could use list(y) instead of y[:]. > > Can anyone offer guidance about which one to choose? Are there subtle > differences in behavior? Is one better than the other when y is a > user-defined class (such as a UserList derivative) vs. a built-in type? list(y) returns an object of type "list". y[:] returns a copy of the sequence, maintaing the type. Use list() if you want to be sure you get a list otherwise use the slice notation. If you don't like the slice notation use copy.copy(). Neil From aleax at aleax.it Fri Aug 31 05:48:30 2001 From: aleax at aleax.it (Alex Martelli) Date: Fri, 31 Aug 2001 11:48:30 +0200 Subject: n is a object,what means: s='n' ? References: <9mnd72$i8$1@mail.cn99.com> Message-ID: <9mnmhf0291i@enews2.newsguy.com> "Formalin" wrote in message news:9mnd72$i8$1 at mail.cn99.com... > class now: > .... > .... > .... > n=now() > s='n' > print s > > > the result:<__main__.now instance at 00B2EB0C> > > what means????? You probably used reverse quotes: s = `n` rather than plain quotes: s = 'n' Reverse-quotes are an operator, which is equivalent to the repr() built-in function: they return a string representation of the object to which they're applied. Alex From SBrunning at trisystems.co.uk Thu Aug 16 07:07:23 2001 From: SBrunning at trisystems.co.uk (Simon Brunning) Date: Thu, 16 Aug 2001 12:07:23 +0100 Subject: Python 2.1 quick reference Message-ID: <31575A892FF6D1118F5800600846864D78BFBB@intrepid> > From: Robin Becker [SMTP:robin at jessikat.fsnet.co.uk] > I just downloaded the html and although dark magenta and green are > mentioned as indicating change at the top I don't see any other > indications of it being used either in the source or on the screen. Bugger. Something has stripped the tags out. I'll put them back! > -should have that beer soon-ly yrs- > Robin Becker Any-time-you-like-just-so-long-as-we-don't-have-to-talk-about-integer-divisi on-ly Y'rs Simon B. ----------------------------------------------------------------------- The information in this email is confidential and may be legally privileged. It is intended solely for the addressee. Access to this email by anyone else is unauthorised. If you are not the intended recipient, any disclosure, copying, distribution, or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful. TriSystems Ltd. cannot accept liability for statements made which are clearly the senders own. From antoine at 2le.net Wed Aug 22 06:07:44 2001 From: antoine at 2le.net (Antoine JOSSERAND) Date: Wed, 22 Aug 2001 12:07:44 +0200 Subject: freezing a python script Message-ID: <001d01c12af2$49cb5880$7801a8c0@technopole.fr> Hi, I have a problem to make an executable file from a python script. I tried with py2exe and McMillan's installer and I had the same problem with both. The .exe file which I obtain works fine on my computer but not an another machine. It says "DLL load failed" despite the DLL's are in the c:\windows\system directory and in my program's directory. If you can give me a hand with this it could be great. Antoine. -------------- next part -------------- An HTML attachment was scrubbed... URL: From MHAMZE at austin.rr.com Sun Aug 19 02:58:18 2001 From: MHAMZE at austin.rr.com (Maan Hamze) Date: Sun, 19 Aug 2001 06:58:18 GMT Subject: Python CGI and multiple forms on a web page Message-ID: I have a web page with many separate forms on it. Each form is associated with a Post action that runs the same or a different Python CGI script. I am using the module cgi.py For each script, I am using FieldStorage to access a form's elements. I want to be sure of the following: Does FieldStorage in the CGI script that is being run by submitting Form A (remember, the web page has many forms: A, B, C etc....) apply strictly on Form A so that the Dictionary available to me has only the elements of Form A? I know, the question sounds naive (and it may be), but I want to be sure. Thanks, Maan From boud at rempt.xs4all.nl Wed Aug 8 17:38:07 2001 From: boud at rempt.xs4all.nl (Boudewijn Rempt) Date: 8 Aug 2001 21:38:07 GMT Subject: PyQt install problem References: <3B70BAB7.A9C3061C@ucdavis.edu> <9kqm4t$6q9$1@news1.xs4all.nl> <3B716A1F.6DA99D39@ucdavis.edu> Message-ID: <9ksbfv$sl8$2@news1.xs4all.nl> Bruce Wolk wrote: > Good suggestion. When I run ldd on libqtcmodule.so as root and as user I get > different results for libqt.so.2: > root > libqt.so.2 => /usr/lib/qt-2.3.0/lib/libqt.so.2 (0x40505000) > user > libqt.so.2 => /usr/local/qt/lib/libqt.so.2 (0x404f6000) > I don't understand why this is so. It seems that the qt libraries are in > fact in both locations--both version 2.3. I am not sure how that happened. > So what should I do now? > I also get many additional libraries as root that I don't get as user: > libXft.so.1 => /usr/X11R6/lib/libXft.so.1 (0x40ec9000) > libpng.so.2 => /usr/lib/libpng.so.2 (0x40eee000) > libz.so.1 => /usr/lib/libz.so.1 (0x40f0f000) > libjpeg.so.62 => /usr/lib/libjpeg.so.62 (0x40f1e000) > libmng.so.1 => /usr/lib/libmng.so.1 (0x40f3d000) > libXrender.so.1 => /usr/X11R6/lib/libXrender.so.1 (0x41018000) > libfreetype.so.6 => /usr/lib/libfreetype.so.6 (0x4101e000) This is logical and consistent with your earlier report. The Qt root uses (which is presumably part of your OS installation) is compiled to support Xft - the new, anti-aliased font protocol for X. Your X doesn't support that (or it does, but your graphics card doesn't), and that causes the error message you get when you run PyQt apps as root. However, I'd search your user account configuration (particularly .bashrc) for references to /usr/local/qt... - I think you might have compiled and installed a qt as a user, and set the qt directory to that place. It might be best to just remove the qt in /usr/local and let everything point to the one in /usr. -- Boudewijn Rempt | http://www.valdyas.org From jeff at ccvcorp.com Fri Aug 10 16:51:50 2001 From: jeff at ccvcorp.com (Jeff Shannon) Date: Fri, 10 Aug 2001 13:51:50 -0700 Subject: from __future__ import generators References: Message-ID: <3B744965.52328B32@ccvcorp.com> gzeljko wrote: > > Is 1 'yield' worth 100000 'from __future__ import generators' ? :) > Well, you only need 'from __future__ ...' in modules that actually use generators, so the ratio is a lot closer to 1:1. Hm... I don't have 2.2a installed or I'd just try this, but... if I've got a module that declares a generator: --------- gen1.py ---------- from __future__ import generators def g(): for i in xrange(100): yield i ---------------------------- And then a second module that imports gen1 and uses that generator.... -------- gen2.py ----------- import gen1 for n in gen1.g(): foo(n) ------------------------ Would gen2.py also require the __future__ statement? Or, is gen1.g() returning a "plain" iterator, thus rendering the __future__ irrelevant in gen2.py ?? (Gotta install 2.2a sometime soon.... ) Jeff Shannon Technician/Programmer Credit International From skip at pobox.com Wed Aug 22 19:58:11 2001 From: skip at pobox.com (Skip Montanaro) Date: Wed, 22 Aug 2001 18:58:11 -0500 Subject: where is doctest module In-Reply-To: <9m1ca5$un$1@panix2.panix.com> References: <3O7f7.3258$D4.222704@newsread1.prod.itd.earthlink.net> <9m1ca5$un$1@panix2.panix.com> Message-ID: <15236.18195.974220.101672@beluga.mojam.com> >> How do I get a copy of the doctest module? I was not able to locate >> it starting from www.python.org. Aahz> the Python Imaging Library comes with a version; It might be easier to get piecemeal by browsing the CVS source at sourceforge: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/ While you're at it you might find the pydoc and inspect modules interesting as well. -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From rob at jam.rr.com Tue Aug 14 12:26:18 2001 From: rob at jam.rr.com (Rob Andrews) Date: Tue, 14 Aug 2001 16:26:18 GMT Subject: Python 2.1 quick reference References: <9lbhjn0282c@enews1.newsguy.com> Message-ID: <3B7950D2.60828E15@jam.rr.com> > > Paging down the PDF file (with Acrobat Reader 4 working as a > plug-in to IE 5.5) at page 5 I get an error messagebox: > "There was an error processing a page. Too few operands." > then on clicking OK to that, another: > "An unrecognized token 285.8.Tw was found" > and page 5 appears totally white. So there would seem to > be some problem with the PDF version. > > Alex Same experience here. Rob -- A {} is a terrible thing to waste. Useless Python! http://www.lowerstandard.com/python From Tom_Good1 at excite.com Fri Aug 10 19:22:59 2001 From: Tom_Good1 at excite.com (Tom Good) Date: 10 Aug 2001 16:22:59 -0700 Subject: choice between quotes thoughts References: <9l12mo$m7c$1@news.mathworks.com> Message-ID: Joshua Marshall wrote in message news:<9l12mo$m7c$1 at news.mathworks.com>... > I always use '. Holding down shift is just far too much effort. My thoughts exactly. Single quote doesn't require shifting -- it is the 'automatic transmission' of string delimiters. This also explains why Lists are better than Tuples: typing (1,2,3) requires two shifts, typing [1,2,3] requires none. ;-) Tom From paul at boddie.net Fri Aug 10 05:30:03 2001 From: paul at boddie.net (Paul Boddie) Date: 10 Aug 2001 02:30:03 -0700 Subject: Python2.2 doesn't give members of a list References: <23891c90.0108090758.43454748@posting.google.com> <3b72da7f.423135777@news.laplaza.org> Message-ID: <23891c90.0108100130.67e6be2a@posting.google.com> Guido van Rossum wrote in message news:... > > Hm. How about making dir() incompatible in the other direction, and > letting it return a sorted list of *all* attributes (that one can > reasonably deduce)? [...] > >>> print dir([]) > ['__add__', '__class__', '__contains__', '__delitem__', '__eq__', '__ge__', '__getattr__', '__getitem__', '__getslice__', '__gt__', '__iadd__', '__imul__', '__init__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__repr__', '__rmul__', '__setitem__', '__setslice__', 'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort'] > >>> > > Note that print dir(list) would print the same. Just an idea... It looks great to me! Of course, as we all know, there's no real way of discovering "dynamic" attributes implemented using __getattr__ and __setattr__, but then after doing some work with them, I came round to the conclusion that those special methods can quickly lead to the "slip road onto the motorway of obfuscation" [1]. ;-) One might argue that people could "roll their own" dir if they really wanted something like this, but your code looks so nice and useful, it really does merit being part of standard Python or at least part of a standard module. If you don't want to "corrupt" dir's existing or proposed meaning, I suppose you could call it something else: xdir perhaps? Paul [1] In U.S. English, I suppose you'd say "on ramp onto the highway of obfuscation". ;-) From hlboey at pl.jaring.my Thu Aug 2 11:43:50 2001 From: hlboey at pl.jaring.my (Boey Pak Cheong) Date: Thu, 02 Aug 2001 23:43:50 +0800 Subject: Building Python2.1 - LONG_BIT error message Message-ID: <3B697536.7B97EC04@pl.jaring.my> I have a serious problem trying to build Python 2.1 on my Athlon running Linux (RH 7.0). Make fails with error message : 'LONG_BIT definitions appear wrong for platform (bad gcc/glibc config?)' >From my limited knowledge, I looked at pyport.h and figured that LONG_BIT must be defined somewhere else since sizeof(long) is defined as 4. But I just can't figure out where. Has anyone faced this problem and found a solution or workaround. Please help. Thanks. P.C. Boey From sheila at spamcop.net Tue Aug 21 02:07:49 2001 From: sheila at spamcop.net (Sheila King) Date: Tue, 21 Aug 2001 06:07:49 GMT Subject: simple graphics lib References: Message-ID: On 20 Aug 2001 19:37:25 -0700, k98jh01 at kzoo.edu (Bignose3) wrote in comp.lang.python in article : :I am a student learning python on my own, coming from a C++ backgroud. : I am working on a simple project, a simulation of fish, as a way to :gain experience using python. I am looking for a simple graphics lib :that will allow me to display objects- like circles or squares to :represent the objects I am coding. Is anyone aware of a lib that will :allow me to do this. When learning C++ I used the CMU Graphics Lib :which worked great. Let me know if anyone has any ideas. : :Thank You :Joe For something along the lines of the CMU Graphics package, try this: Look in your Python2x/Lib/lib-tk/ folder for the turtle.py module. Run it. Then look at the code. Let us know if you have any questions. You might also want to check out the Python Tutor list. http://mail.python.org/mailman/listinfo/tutor Good luck, -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From m.1.robinson at herts.ac.uk Wed Aug 8 03:32:26 2001 From: m.1.robinson at herts.ac.uk (Mark Robinson) Date: Wed, 08 Aug 2001 08:32:26 +0100 Subject: combinations of variable length nested lists References: <3B83E9E3@twigger.nl> Message-ID: <3B70EB0A.8030407@herts.ac.uk> Thanks Terry, I was thinking that was nasty. It's little things like that, that can save you hours of heartache Terry Reedy wrote: > "Mark Robinson" wrote in message > news:mailman.997195091.27673.python-list at python.org... > >> def comb(list, *pos): >> if not pos: >> pos = 0 >> else: >> pos = pos[0] > > > Slightly more idiomatic: > > def comb(lists, pos=None): > if pos == None: > pos = 0 > > Masking a builtin function by reusing its name leads to trouble when > you later try to use that builtin. I try to avoid it. Some like > living dangerously. Your choice. > > Terry J. Reedy From emile at fenx.com Sat Aug 25 07:51:22 2001 From: emile at fenx.com (Emile van Sebille) Date: Sat, 25 Aug 2001 04:51:22 -0700 Subject: Re and Me. References: Message-ID: <9m83nh$qjn2$1@ID-11957.news.dfncis.de> Check out http://py-howto.sourceforge.net/regex/regex.html import re p = re.compile('url=(\w)&', re.IGNORECASE) print p.findall("""this is url=a& test this is URL=b& test this is url=c& test this is Url=D& test""") -- Emile van Sebille emile at fenx.com --------- "epoch7" wrote in message news:toevhkp1hlem92 at corp.supernews.com... > This is day 2 of my programming expereience, so please bear with my > newbie-ishness. > I'm trying to search for a string inside a file. The string will be > different > but the characters marking its beginning and end are the same (url= and &). > I've spent all day and night just learning the ins and outs of python so > this is still a little beyond me. > re.split() would return the values between just one pattern correct? So > there must be some other way. > I could put an if statement in there that if it finds "&" it would output > that string to file and continue with the search > but that waaay beyond me :) > > will > > > From loewis at informatik.hu-berlin.de Wed Aug 1 05:46:01 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 01 Aug 2001 11:46:01 +0200 Subject: Unicode File References: <3B66179D.1D55B27C@yahoo.com> <3B66ECA8.60313BD0@yahoo.com> Message-ID: Tksee Lhsoh writes: > How do you know the encoding of a file ? > > Is it specific to the application which generated the file? Indeed it is. Sometimes, some higher-level protocol will tell you, e.g. the charset= attribute in a MIME Content-Type:. In other cases, the encoding is given inside the file, e.g. the encoding= attribute in an I am just wondering, since I am now joining python and it's greatness, why don't the developers of Python make Python just as fast(if not faster) than the older, more low-level lanquage. Yes, there are advantages using the interpreter style programs, but isn't there a way to incorporate the speed of compiled programs with the debugging and clearness of Interpreter to make Python a much faster lanquage. There might be a way, but I'm pretty new so I don't know. Any answers, thank you for listening? From loewis at informatik.hu-berlin.de Thu Aug 9 13:19:46 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 09 Aug 2001 19:19:46 +0200 Subject: calling applications from python References: <3b72ba42_1@nnrp1.news.uk.psi.net> Message-ID: "Jesper Olsen" writes: > It is possible to call applications from a python program using, e.g. > the os.system command: > > os.system("ls -l") > > Is it possible to attach the output from this command to a file? > I would like to be able to read this output, instead of just sending it to > stdout. Certainly, that would be p = os.popen("ls -l") output = p.read() Of course, if it is really ls(1) that you are after, I recommend to use os.listdir instead, combined with os.stat. Regards, Martin From nstalkie at tvd.be Wed Aug 8 16:21:20 2001 From: nstalkie at tvd.be (Sammy Mannaert) Date: Wed, 08 Aug 2001 20:21:20 GMT Subject: Emacs? VIM! References: <3B71598C.F55E6873@alcyone.com> <3B7183A2.16217381@noaa.gov> Message-ID: <3B71A15D.A025AFDA@tvd.be> Quinn Dunkan wrote: > > On Wed, 8 Aug 2001 14:53:43 -0400, Steve Holden wrote: > >> > > > code, following the indenting standards (depressing). Does anybody > >> know > >> > > > of another editor that has Python stuff (or a file that enables > >Python > >> > > > stuff)? I think I heard that Zeus does... > >> > > > >> > > What about nedit. > >> > > >> > Aha, another one, so far we have: > >> > > >> > Emacs, > >> > Vim, > >> > Alpha, > >> > Jed, > >> > Nedit, > >> > > >> > that's a pretty formidable list! Any others? > >> > > >> Scintilla. > > > >TextPad > > wily, > acme (scripted by anything that can read and write files) cooledit ... this editor even has it's scripting done in python and you can program scripts for the editor in python. nice coloring modes too ... it's my favourite programming editor :) From db3l at fitlinxx.com Thu Aug 30 20:12:18 2001 From: db3l at fitlinxx.com (David Bolen) Date: 30 Aug 2001 20:12:18 -0400 Subject: Window NT: need to allow client to make system call via CGI script References: <93d52e82.0108280835.1933ba58@posting.google.com> <9mhsps$2a133$1@ID-11957.news.dfncis.de> <93d52e82.0108290421.3008647a@posting.google.com> <3b8ea450.14522632@wa.news.verio.net> Message-ID: bokr at accessone.com (Bengt Richter) writes: > But isn't this substituting for pcAnywhere rather than allowing the CGI > to execute the script, unless either the server is 'impersonating' the > user who has access, or IUSR_ (the server services' own > user login account for anonymous access -- which you should not give > additional privileges to unless you have a *very* protected environment > with no external access) has rights to the share (which would mean it was > effectively a pretty public share). No - this would be a way to run the script on the _client_ machine, in a way that the same script would run on any client machine without worrying about local drive mappings. One would presume that other necessary files on the server could be published on shares with appropriate access to network authenticated users (for which the clients on the network would likely have already authenticated to upon login to their local machine). > Or did I miss some discussion? If I read the original request right, part of the whole reason to even want the script to execute on the server (and thus the current pcAnywhere workaround) was to avoid having to deal with drive mappings - running locally on the server was a controllable environment. If you just use UNCs then, barring network access problems the same script can run locally on the requester's machine. But this is just an alternative potential solution to the underlying problem, assuming that executing on the server is itself already a secondary problem attempting to address the original issue -- -- 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 alice at homegiant.d2g.com Fri Aug 10 04:46:56 2001 From: alice at homegiant.d2g.com (Alice Lin (Home Giant)) Date: 10 Aug 2001 16:46:56 +0800 Subject: Furniture Hardware Message-ID: An HTML attachment was scrubbed... URL: From NeXTStep at programmatic.de Fri Aug 24 13:38:00 2001 From: NeXTStep at programmatic.de (Joerg Sauer) Date: Fri, 24 Aug 2001 17:38:00 GMT Subject: boost::python sharing native c++ object with python Message-ID: <3b868b2b.160761963@news.netcologne.de> Hi, hopefully the subject is attracting!? I know how to create an extension module using boost and how to make a class wrapper using python::class_builder. That works fine! Now that I have an extension DLL I want to embed python in my application. How can I create an c++ class object in the c++ app and export this object to the python instance (not as function parameter but as object at global or module level)? Suggest I have ---myclass.h------------- class DLLAPI myclass { public: myclass(){} void setval(int x){_x=x;} int getval(){return _x;} private: int _x; }; ---myboostmod.h------------ #include "myclass.h" BOOST_PYTHON_MODULE_INIT(mymod) { python::module_builder this_module("mymod"); // Create the Python type object for our extension class. python::class_builder myclass_class(this_module, "myclass"); myclass_class.def(python::constructor()); myclass_class.def(&myclass::setval, "setval"); myclass_class.def(&myclass::getval, "getval"); } now I have a main programm ----------main.cpp----------- #include #include #include "myboostmod.h" //???? or just #include "myclass.h" using std::cout; int main(int argc, char** argv) { PyObject *pMod, *pDict, *pObject; Py_Initialize(); pMod = PyImport_ImportModule("mymod"); // Now that I have python up and ready, I want to export a c++ // class myclass mc1; mc1.setval(5); // I would like to export this object with the python name mc1 // too -->>> export mc1 to python with name mc1. // Now I want to run a simple python statement PyRun_SimpleString("print mc1.getval()"); PyRun_SimpleString("print mc1.setval(12345)"); // here the object should keep the value set in python cout << "Now mc1 is:" << mc1.getval() << "\n"; Py_Exit(0); }; Does anybody has a sollution or some hints? Thanks in advance Joerg From quinn at retch.ugcs.caltech.edu Sat Aug 4 02:06:58 2001 From: quinn at retch.ugcs.caltech.edu (Quinn Dunkan) Date: 4 Aug 2001 06:06:58 GMT Subject: Is this the *right* way of exception handling? References: <9kdr21$rao$1@zeus.man.szczecin.pl> <3B6B3F57.65BA307B@alcyone.com> Message-ID: On Fri, 03 Aug 2001 17:18:31 -0700, Erik Max Francis wrote: >Quinn Dunkan wrote: > >> Unfortunately, python's >> assertion mechanism is not well integrated with the exception >> mechanism, so >> assertions that should really raise a ValueError will always raise an >> AssertionError. A possible third argument to 'assert'? > >Are you suggesting some kind of difference between logic asserts (logic >faults) and data asserts (bad data, has to be handled properly)? In >Python, the latter should definitely not be presented as asserts, but >rather as just raising some other (possibly custom) exception. Logic >asserts mean something's broken; data asserts just means someone sent it >bad input data and need to be handled properly by the program in any >case. I'm suggesting that an assertion can assert many things. It can assert a class invariant, or a proper value, or the consistency of data on disk. But these are all flattened into a generic "AssertionError". Python provides two ways to do the same thing: if not foo: raise bar and assert foo The difference is that asserts can be turned off. I use asserts to describe sanity checks which are redundant and unnecessary in a working program, and 'raise' for everything else. I don't think your logic and data asserts dichotomy makes much sense, since logic faults are usually manifested as bad data. If someone sent you bad data, it either came from the outside world, in which case you have to deal with it, or it came from your program, in which case it's a bug. And at a certain programmer and program defined point, it's a bug if data from the outside world hasn't been checked for errors. Python style is often to just toss the data in, and see if it's good by whether it blows up or not (the "better to ask forgiveness" philosophy), but it can be handy to catch things before that point, especially when the consistency of a filesystem or database is at stake. And sometimes those checks can be very expensive, so it's handy to be able to turn them off when everything's been tested. On the other hand, if it's a "bug" error, you usually shouldn't be catching it, so it shouldn't be an ordinary exception type. I dunno. In any case, I'm happy the way things are and don't want yet another little convenient feature. I can still write "if __debug__: if foo: raise bar", but hardly ever do. So I take it all back :) Yeah, it has to be decided by the programmer. Some bad arguments can be caused contract violations are the result of > >-- > Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ > __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE >/ \ The basis of optimism is sheer terror. >\__/ Oscar Wilde > Rules for Buh / http://www.alcyone.com/max/projects/cards/buh.html > The official rules to the betting card game, Buh. From tim.one at home.com Mon Aug 27 02:26:00 2001 From: tim.one at home.com (Tim Peters) Date: Mon, 27 Aug 2001 02:26:00 -0400 Subject: Single Instance of app In-Reply-To: Message-ID: [Tim Hammerquist] > ... > While I'm at it, I've never actually seen (nor needed, thus far) Python > code to get an atomic lock on a file. What's the idiom in Python? I'm not sure exactly what's meant by "atomic lock on a file", but you can study the std tempfile.py module for the excruciating dance needed to create temp files safely. From Lance.Ellinghaus at eConnections.com Thu Aug 9 17:19:03 2001 From: Lance.Ellinghaus at eConnections.com (Lance.Ellinghaus at eConnections.com) Date: Thu, 9 Aug 2001 16:19:03 -0500 Subject: iterating through lists to delete elements Message-ID: As you will learn through the years as a programmer, there is normally more than one way to do anything in software. It becomes a personal choice based on previous programming and personal philosophy. -- Lance Ellinghaus Phone: 940-466-7251 Pager: 800-226-4526 or lellinghaus at imcingular.com Sr. Architect - eConnections, Inc. "Joseph A. Knapka" cc: Sent by: Subject: Re: iterating through lists to delete elements python-list-admin@ python.org 08/09/01 02:49 PM Bjorn Pettersen wrote: > > > From: Mark Robinson [mailto:m.1.robinson at herts.ac.uk] > > > > Can anyone advise me the best way to iterate through a list > > and deleting > > elements that don't meet a certain criteria. > > You can use either filter or list comprehensions: So it seems that (shudder) There's More Than One Way To Do It. Isn't there supposed to be one (obvious) way? -- Joe Knapka "You know how many remote castles there are along the gorges? You can't MOVE for remote castles!" -- Lu Tze re. Uberwald // Linux MM Documentation in progress: // http://home.earthlink.net/~jknapka/linux-mm/vmoutline.html 2nd Lbl A + 1 = 2nd Pause 2nd Prt GTO 2 R/S -- http://mail.python.org/mailman/listinfo/python-list From aleaxit at yahoo.com Tue Aug 14 17:26:43 2001 From: aleaxit at yahoo.com (Alex Martelli) Date: Tue, 14 Aug 2001 23:26:43 +0200 Subject: Typing system vs. Java References: <8bbd9ac3.0108042147.5f0c4059@posting.google.com> <9kmffa017qc@enews4.newsguy.com> <8bbd9ac3.0108101407.4bd1c716@posting.google.com> <8bbd9ac3.0108131541.3cc051d9@posting.google.com> <997763429.579495@yabetcha.drizzle.com> <8bbd9ac3.0108141204.1518e81c@posting.google.com> Message-ID: <9lc5bh022j2@enews3.newsguy.com> "Andy Freeman" wrote in message news:8bbd9ac3.0108141204.1518e81c at posting.google.com... ... > Moreover, it's not clear that language changes are required for interesting > speedups. Alex has mentioned ways to significantly speed up dispatch, > which happens to be one of the biggest opportunities for using type > information to increase performance. There's also type inference, which And let's not forget Skip Montanaro's much more concrete proposed-PEP for object-tracking (posted to Python-DEV, though briefly discussed here today). That one seems bright and beautiful to me, and much closer to practical implementability than my own blue-sky babblings about method-caching. > While there's some work being done on python performance, it isn't getting > nearly the attention that one would expect given the opportunities if > performance really was a significant problem. It's possible that Guido > et al's priorities are completely wrong or that they don't see the > opportunities, but .... It seems to me that a very significant fraction of the restrictions that appear to be due to fall upon Python in the near future are very much motivated by performance "getting attention" -- we're going to lose a portion of Python's dynamic abilities, and some of the remaining ones will not be active by default any more, basically to ease optimization tasks (and secondarily to protect "typical users" from potential errors that, in my experience teaching Python and helping "typical users", don't really happen -- accidentally changing a class's attribute or an instance's class... I don't think I've ever seen that happen actually). So much for Eckel's "Why I Love Python"... e.g. his arguments about Python being superior to Java because of the "necessary for speed" type-awkwardness of the latter, while in Python speed is obtained through an escape mechanism (extensions) while the language has "no compromises: it's all about making me more productive". I find I'm naturally brought to speak about the Python I love (just as much as Eckel does) in the past tense, even though the actual fall of the axe is scheduled for the future -- 2.2 still leaves me "classic classes" that are smoothly and seamlessly dynamic, it's only for 3.0 that they're going to be yanked away, and even then, if I'm lucky, I might get a backwards-compatibility metaclass so I can keep playing in my sandbox, maybe... what's really very frightening is the "performance getting attention" aspect -- and the predictably-destructive backlash against some of the most interesting, although, for now, peripheral, parts of the language. (Even with the peripheral nature of these changes, I think they'll still push us to more front-loaded gotta-foresee-all design and against XP-ish just-in-time-design -- with a substantial negative impact on overall productivity larger than the 'marginal' nature of the affected areas would seem to justify). Oh well, maybe I'm just being pessimistic tonight. Alex From jkraska1 at san.rr.com Tue Aug 7 01:20:04 2001 From: jkraska1 at san.rr.com (Courageous) Date: Tue, 07 Aug 2001 05:20:04 GMT Subject: probs w/ building python extensions on free Microsoft.NET SDK References: <280f26fb.0108061915.54ea1e98@posting.google.com> <9knqsc$drr$1@slb5.atl.mindspring.net> Message-ID: >> I've tried unsuccessfully in the past to compile python extensions >> using cygwin, but failed for more than one reason or the other and... One. Get _Python Essential Reference_. It has the best guide to extending and embedding in Python that I've ever seen. Two. If you're fizzling around with Cygwin and GNU and can't figure it out, please take that to the appropriate newsgroups. Three. You've claimed to be new to C. You're going to have to learn quite a bit about C, first. The Python documentation does not take on the task of teaching C while it explains the extension mechanisms. C// From s.schwarzer at ndh.net Sat Aug 11 18:59:44 2001 From: s.schwarzer at ndh.net (Stefan Schwarzer) Date: Sat, 11 Aug 2001 23:59:44 +0100 Subject: Reloading modules into interpreter References: <9l48os$dg3$1@slb6.atl.mindspring.net> Message-ID: <3B75B8E0.A3F3969E@ndh.net> Hello Joe jsnyder schrieb: > Hello, I'm a newbie at Python and the solution to the following seems to > escape me at the moment: > > Running from Pythonwin, I am importing a module and then calling its method. > Then I change the module code and run it again, but the old code still runs, > not the new code. The only way I have been able to get the new code is to > shut down the interpreter, restart it and reimport the module. Surely there > is an easier way. You may use reload(module) if you earlier did import module However, that would cause problems if some code had changed the module's contents and relies on them. Therefore, I use reload only for tests in the interactive interpreter. Stefan From tjreedy at home.com Sun Aug 19 19:10:10 2001 From: tjreedy at home.com (Terry Reedy) Date: Sun, 19 Aug 2001 23:10:10 GMT Subject: Stop assignment of a class attribute? References: <9lpcnh02991@enews1.newsguy.com> Message-ID: "Al Gonzalez" wrote in message news:9lpcnh02991 at enews1.newsguy.com... > I can overload the __setattr__ and __delattr__ to make instance attributes > immutable, but I don't see how it can be done for class attributes. Can't for normal classes. > Does anyone have any ideas? It may be possible with metaclasses, but I cannot help you there. Terry J. Reedy From s713221 at student.gu.edu.au Mon Aug 27 06:26:34 2001 From: s713221 at student.gu.edu.au (Joal Heagney) Date: Mon, 27 Aug 2001 20:26:34 +1000 Subject: PyGTK - 1.5.2 not 2.1x References: <15241.575.772954.842109@beluga.mojam.com> Message-ID: <3B8A205A.E5076D1F@student.gu.edu.au> Adam 'Vonlia' Seyfarth wrote: > > I don't know whether you are the person that has been responding before, > but I heard that 2 variables have to be changed to compile with 2.1. He > wouldn't tell me which ones, and when I searched for version with case > insensitivity on, I found PYTHON_VERSION = 1.5 and changed it to 2.1. > It still won't do anything with python2.1... Try this on a clean build directory PYTHON=/usr/local/bin/python ./configure --prefix=/usr/local Then the rest of it. -- Joal Heagney is: _____ _____ /\ _ __ __ _ | | _ ___ | /__\|\ || ||__ |\ || |___|/_\|___] | / \ \_||__ ||___| \_|! | | \ \ ! From m.1.robinson at herts.ac.uk Wed Aug 8 05:52:58 2001 From: m.1.robinson at herts.ac.uk (Mark Robinson) Date: Wed, 08 Aug 2001 10:52:58 +0100 Subject: How to call java from python? References: Message-ID: <3B710BFA.3070807@herts.ac.uk> Larry, there is an implementation of python in java called jython which can do what you are wanting and much much more. I think you will like check out www.jython.org and enjoy :) blobby Larry Han wrote: > Is there any way to use java method from python? > Like calling C from python, it seems reasonable to > drag java and python closer. > > Thanks, > Larry From peter at engcorp.com Sat Aug 11 12:56:18 2001 From: peter at engcorp.com (Peter Hansen) Date: Sat, 11 Aug 2001 12:56:18 -0400 Subject: dynamic naming for hierarchical problem References: <87ofppnax8.fsf@xeno.localhost> <015501c12204$bf0872a0$d3bd6ac2@zko> <008d01c1220f$141bbae0$6401a8c0@atl.mediaone.net> <9l2uqm0eub@enews2.newsguy.com> Message-ID: <3B7563B2.AC539489@engcorp.com> Jeremy Jones wrote: > > In the example that I was working on, the children (not of the same parent, > but in different tiers of the hierarchy) were of differing types and would > have different attributes and different quantities of attributes. I don't > know if I spelled that out exactly like that initially, but immediately > under the root would be test sets. The test sets right now don't have any > attributes of their own, but they do have children - tests. The tests would > have an attribute of pass/fail and a reason why and commands as children. > The commands would have attributes of expected result, pass/fail, actual > result. I suppose you could hack together a table that would accomodate all > of those different attributes and have CHILD as a foreign key, but it seems > it would be a pain to give it room to grow if I needed it to. [...] > I appreciate the posts. They have definitely spurred me on to think > differently. I am still inclined to think that the DOM/XML route will be a > more simple route for my specific problem. One of the reasons I suggested the XML route is this. Over the last year and a half, one of our projects has been the development of an automated factory test system. It interfaces with instruments using GPIB and executes a variety of tests on the device under test (DUT). All results are written out as XML. The input is (currently partially) XML also. One of the primary requirements leading to the choice of XML was the expectation that we would have substantial growth and change over the first implementation. By using XML, we handle this easily. (Coincidentally, although our input doesn't have pass/fail, the output has an element which contains PASS or FAIL or COMPLETE and an optional element which contains text describing why a test failed, sort of as you were thinking.) The code, of course, is in Python (with calldll). Another reason I keep picking XML for this kind of thing is that I can gradually leverage more and more all these tools being developed for XML processing. If I need to compare two XML trees... hey, somebody just made Xmldiff (http://www.logilab.org/xmldiff/ ... thanks Alexandre! :-) and that will do the trick. If I need to display it quickly I can just fire up IE (ugh). If I want to print it, I can write some XSL stuff with FOP to convert to PDF. And if I need to edit the data by hand (and sometimes I still do), I can fire up a Plain Old Text Editor. Although there are some limitations relative to other, special-purpose or more mature technologies, the synergy I'm beginning to see with all these tools and standards is really starting to prove (at least to me) the sheer power of a universal standard which is general enough to adapt and handle diverse applications. A relational database might give you better performance. Maybe even a slightly simpler solution -- for now. When you look back after a year and see how warped your system has become because of this initial choice of a "brittle" solution, you might rewrite with XML (or something else) anyway. (Of course, follow XP principles regardless: if you have to spend significant time learning and implementing the solution with XML, don't go there. Just pick something simple, as Alex said and you agreed, and get it working. You can always plan on refactoring once the basic thing is working and you can focus on learning XML without the pressures of trying to make the system work at the same time.) -- ---------------------- Peter Hansen, P.Eng. peter at engcorp.com From grahamd at dscpl.com.au Wed Aug 1 22:15:17 2001 From: grahamd at dscpl.com.au (Graham Dumpleton) Date: 1 Aug 2001 19:15:17 -0700 Subject: PSP, Cheetah, PTL, ZOPE, etc ... References: <112e9d13.0108011014.1fb2241a@posting.google.com> <3dofpzk3vq.fsf@ute.cnri.reston.va.us> Message-ID: Andrew Kuchling wrote in message news:<3dofpzk3vq.fsf at ute.cnri.reston.va.us>... > ChuckEsterbrook at yahoo.com (Chuck Esterbrook) writes: > Of course, we don't care about people using graphical HTML editors; > that would be impossible to accommodate with PTL. Which is an issue which I had actually been considering. In that respect, I had been looking at a scheme which extended the idea of server side includes as implemented by Apache. In order to accomodate servlet or Bean type access to back end services, was considering using tag and for Python script require stuff to be in