Re: Case-insensitive dict, non-destructive, fast, anyone?

2005-04-01 Thread Raymond Hettinger
[Ville Vainio] I need a dict (well, it would be optimal anyway) class that stores the keys as strings without coercing the case to upper or lower, but still provides fast lookup (i.e. uses hash table). class S(str): def __hash__(self): return hash(self.lower()) def

Some notes about float approximations in mxNumber

2005-04-01 Thread Kay Schluehr
Hi Mark, I was a bit surprised to find the very slow Farey approximation by means of the FareyRational class in the mxNumber package. If the goal was to reconstruct a rational from a float it is not a good choice and should be replaced by a continued fractions approximation. Some time ago I

Re: Pseudocode in the wikipedia

2005-04-01 Thread Terry Reedy
[EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] The free wikipedia is adopting a standard pseudocode: http://en.wikipedia.org/wiki/Wikipedia_talk:Wikicode/Specification MShonle says something nice: Calling a feature 'baggage' is not especially nice. Neither is getting facts

Re: redundant imports

2005-04-01 Thread max(01)*
Peter Hansen wrote: max(01)* wrote: this leads me to another question. since *.pyc files are automatically created the first time an import statement in executed on a given module, i guess that if i ship a program with modules for use in a directory where the user has no write privileges then i

string goes away

2005-04-01 Thread Michael Chermside
Andreas Beyer writes: Yeeh, I was expecting something like that. The only reason to use map() at all is for improving the performance. That is lost when using list comprehensions (as far as I know). So, this is *no* option for larger jobs. Skip Montanaro replied: Did you test your

Re: numeric module

2005-04-01 Thread Terry Reedy
[EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] What's the problem with this code? I get the following error message: 2.4 or earlier? File test.py, line 26, in test print tbl[wi][bi] IndexError: index must be either an int or a sequence Longs are not ints; message implies

Creating Modules/Namespaces from C/C++ for better class/function encapsulation/cleanup

2005-04-01 Thread kanedatakeshi
Hi folks! The problem is the following: I use Python 2.1 embedded in a C++ game engine. Some of the engines complexer objects (AI, game logic, etc.) use python classes that act as an extension of those parent C++-classes. The python classes are currently loaded on demand by their parent

Re: System bell

2005-04-01 Thread Matt
Serves me right for blindlyrunning things from IDLE. This does work (tested on WinXP only): import os os.system('echo \a') -- http://mail.python.org/mailman/listinfo/python-list

Re: AttributeError: 'module' object has no attribute 'setdefaulttimeout'

2005-04-01 Thread John J. Lee
Steve Holden [EMAIL PROTECTED] writes: Peter Otten wrote: adrian wrote: urllib.socket.setdefaulttimeout(self.timeout) AttributeError: 'module' object has no attribute 'setdefaulttimeout' socket.setdefaulttimeout() was added in Python 2.3. You need to upgrade. Peter Alternatively

Re: Little Q: how to print a variable's name, not its value?

2005-04-01 Thread John J. Lee
[EMAIL PROTECTED] [EMAIL PROTECTED] writes: [...] Restating: I'm doing some debugging of some code. I want to print out the value of two variables whose names are known. Let's call them myTime and myPlace. [...] Why not simply get your editor to insert the variable name twice? I have that

Re: Decorater inside a function? Is there a way?

2005-04-01 Thread Ron_Adam
On Fri, 01 Apr 2005 13:47:06 -0500, Jeremy Bowers [EMAIL PROTECTED] wrote: On Fri, 01 Apr 2005 18:30:56 +, Ron_Adam wrote: I'm trying to figure out how to test function arguments by adding a decorator. The rest of your message then goes on to vividly demonstrate why decorators make for a

pagecrawling websites with Python

2005-04-01 Thread writeson
Hi all, We've got an application we wrote in Python called pagecrawler that generates a list of URL's based on sql queries. It then runs through this list of URL's 'browsing' one of our staging servers for all those URL's. We do this to build the site dynamically, but each page generated by the

Re: Pseudocode in the wikipedia

2005-04-01 Thread James Stroud
Is anybody else bothered by those stupid pascal-like := assignment operators? Maybe, for the sake of adding more variety to the world, wiki should come up with a new assignment operator, like ==. I like that one because then it could really be original: if (bob = 4): bob == bob + 2 See how

Re: tkinter destroy()

2005-04-01 Thread max(01)*
also the app seems to have too many variables and widgets defined as self objects. That isn't necessary unless they will be used outside the method they were created in (which labels and buttons usually aren't), so all you are doing is using up more memory than necessary. you are right, and at

Re: how to close a gzip.GzipFile?

2005-04-01 Thread Justin Guerin
On Friday 01 April 2005 11:54, Justin Guerin wrote: Hello list, gzip documentation states that calling the .close() method on a GzipFile doesn't really close it. If I'm really through with it, what's the best way to close it? I'm using Python2.2 (but the gzip module doesn't seem to be any

Re: string goes away

2005-04-01 Thread Ivan Van Laningham
Hi All-- Michael Chermside wrote: The REAL lesson here is that you shouldn't follow any optimization rules without actually testing them. If you don't have time to test, then just don't optimize... write whatever is most readable. If you NEED more speed, then profiling and testing will show

Re: Pseudocode in the wikipedia

2005-04-01 Thread Bill Mill
On Apr 1, 2005 3:15 PM, James Stroud [EMAIL PROTECTED] wrote: Is anybody else bothered by those stupid pascal-like := assignment operators? I actually like them. I think that the = should be a comparison operator, not a silly ==. I think that comparisons using = are much clearer, especially

Re: Pseudocode in the wikipedia

2005-04-01 Thread Ron_Adam
On Fri, 1 Apr 2005 12:15:35 -0800, James Stroud [EMAIL PROTECTED] wrote: Is anybody else bothered by those stupid pascal-like := assignment operators? Maybe, for the sake of adding more variety to the world, wiki should come up with a new assignment operator, like ==. I like that one because

Re: how to close a gzip.GzipFile?

2005-04-01 Thread Sidharth
GzipFile has a parameter 'fileobj' which you could use. GzipFile( [filename[, mode[, compresslevel[, fileobj) For iteratng over the file how about : line = oldfileobj.readline() while line !=: oldmd5.update(line) line = oldfileobj.readline() --

Attributes and built-in types

2005-04-01 Thread Dave Opstad
Is it just an implementation limitation that attributes cannot be assigned to instances of internal types? --- x = 4 type(x) type 'int' class Test(int): ... pass ... y = Test(4) type(y) class '__main__.Test' y.someattr = 10 x.someattr = 10 Traceback (most recent

Re: Pseudocode in the wikipedia

2005-04-01 Thread Gabriel Cooper
Ron_Adam wrote: To me := could mean to create a copy of an object... or should it be =: ? Or how about :=) to mean is equal and :=( to mean it's not. Then there is ;=), to indicate 'True', and ':=O' to indicate 'False' Not to mention (_ | _) for asserts! --

Re: Attributes and built-in types

2005-04-01 Thread Sidharth
You might find this usefull specifically the stuff on subclassing built-in types. http://www.python.org/2.2/descrintro.html -- http://mail.python.org/mailman/listinfo/python-list

Re: StopIteration in the if clause of a generator expression

2005-04-01 Thread Bengt Richter
On Fri, 01 Apr 2005 16:34:32 GMT, Raymond Hettinger [EMAIL PROTECTED] wrote: [Peter Otten] a StopIteration raised in a generator expression silently terminates that generator: def stop(): raise StopIteration ... list(i for i in range(10) if i 5 or stop()) [0, 1, 2, 3, 4] In a list

Re: Ternary Operator in Python

2005-04-01 Thread Erik Max Francis
Ron_Adam wrote: I've used boolean opperations to do it. result = (v == value) * first + (v != value) * second Same as: if v == value: result = first else: result = second No, it isn't, because it isn't short circuiting. If first or second had side effects, then the two would not be

Who said that? (was Re: string goes away)

2005-04-01 Thread Peter Hansen
Ivan Van Laningham wrote: Tim Peters sayeth, Premature Optimization is the Root of All Evil. And he is not kidding. And just to forestall another long thread about who actually said that originally, it was really Mark Twain, quoting Churchill. Tim just added a wink. -Peter --

Re: numeric module

2005-04-01 Thread David M. Cooke
[EMAIL PROTECTED] writes: Hello, What's the problem with this code? I get the following error message: File test.py, line 26, in test print tbl[wi][bi] IndexError: index must be either an int or a sequence ---code snippet from Numeric import * tbl = zeros((32, 16)) def

Re: numeric module

2005-04-01 Thread David M. Cooke
coffeebug [EMAIL PROTECTED] writes: I cannot import numarray and I cannot import numeric using python 2.3.3 numarray and Numeric are separate modules available at http://numpy.sourceforge.net/ If you're doing anything numerical in Python, you'll want them :-) -- ||\/|

Re: redundant importr

2005-04-01 Thread Peter Hansen
max(01)* wrote: Peter Hansen wrote: Not required except for performance reasons. If the .pyc files don't exist, the .py files are recompiled and the resulting bytecode is simply held in memory and not cached and the next startup will recompile all over again. but the other files *are* compiled,

Re: Ternary Operator in Python

2005-04-01 Thread Carl Banks
Terry Reedy wrote: praba kar [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Dear All, I am new to Python. I want to know how to work with ternary operator in Python. I cannot find any ternary operator in Python. So Kindly clear my doubt regarding this A unary

Re: Decorater inside a function? Is there a way?

2005-04-01 Thread Jeremy Bowers
On Fri, 01 Apr 2005 19:56:55 +, Ron_Adam wrote: On Fri, 01 Apr 2005 13:47:06 -0500, Jeremy Bowers [EMAIL PROTECTED] wrote: Is this an April Fools gag? If so, it's not a very good one as it's quite in line with the sort of question I've seen many times before. I have a hammer, how do I use

Re: try / except not worknig correctly

2005-04-01 Thread Jeremy Bowers
On Sat, 12 Mar 2005 17:06:17 -0800, '@'.join([..join(['fred','dixon']),..join(['gmail','com'])]) wrote: I'd also suggest validInput = ABCDEFGHIJKL # and there are more clever ways to do this, # but this will do myInput = raw_input( .join(validInput) + ?) if

Re: Pseudocode in the wikipedia

2005-04-01 Thread Jeremy Bowers
On Fri, 01 Apr 2005 16:02:53 -0500, Gabriel Cooper wrote: Ron_Adam wrote: To me := could mean to create a copy of an object... or should it be =: ? Or how about :=) to mean is equal and :=( to mean it's not. Then there is ;=), to indicate 'True', and ':=O' to indicate 'False' Not to

Re: How To Do It Faster?!?

2005-04-01 Thread Jeremy Bowers
On Thu, 31 Mar 2005 13:38:34 +0200, andrea.gavana wrote: Hello NG, in my application, I use os.walk() to walk on a BIG directory. I need to retrieve the files, in each sub-directory, that are owned by a particular user. Noting that I am on Windows (2000 or XP), this is what I

Re: decorator syntax polling suggestion

2005-04-01 Thread Jeremy Bowers
On Fri, 13 Aug 2004 16:49:53 +1000, Anthony Baxter wrote: The people who hate pie-decorators post a _lot_ - most people seem to either not care, or else post once or twice and then disappear. I just posted on another mailing list about how posting the same message, over and over, is

Re: decorator syntax polling suggestion

2005-04-01 Thread Jeremy Bowers
On Fri, 01 Apr 2005 16:52:52 -0500, Jeremy Bowers wrote: Oops, sorry, some send later messages I thought were gone got sent. Sorry. Didn't mean to revive dead threads. -- http://mail.python.org/mailman/listinfo/python-list

Re: decorator syntax polling suggestion

2005-04-01 Thread D H
Jeremy Bowers wrote: On Fri, 01 Apr 2005 16:52:52 -0500, Jeremy Bowers wrote: Oops, sorry, some send later messages I thought were gone got sent. Sorry. Didn't mean to revive dead threads. At least it happened on April Fool's. Or should I say: @aprilfools def happened: at least --

Re: Lambda: the Ultimate Design Flaw

2005-04-01 Thread Ulrich Hobelmann
alex goldman wrote: Daniel Silva wrote: At any rate, FOLD must fold. I personally think GOTO was unduly criticized by Dijkstra. With the benefit of hindsight, we can see that giving up GOTO in favor of other primitives failed to solve the decades-old software crisis. The fault of goto in

Re: that is it is not it (logic in Python)

2005-04-01 Thread F. Petitjean
Le Fri, 1 Apr 2005 13:39:47 -0500, Terry Reedy a écrit : F. Petitjean [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] iterable = range(10) it = iter(iterable) that = iter(it) that is it True# Good! that is it is not it This is equivalent to '(that is it) and (it is

Re: Case-insensitive dict, non-destructive, fast, anyone?

2005-04-01 Thread Bengt Richter
On Fri, 01 Apr 2005 18:52:00 GMT, Raymond Hettinger [EMAIL PROTECTED] wrote: [Ville Vainio] I need a dict (well, it would be optimal anyway) class that stores the keys as strings without coercing the case to upper or lower, but still provides fast lookup (i.e. uses hash table). class

Re: Pseudocode in the wikipedia

2005-04-01 Thread Ivan Van Laningham
Hi All-- Jeremy Bowers wrote: Your ass is your identity function. Python 2.3.5 (#1, Mar 3 2005, 17:32:12) [GCC 3.4.3 (Gentoo Linux 3.4.3, ssp-3.4.3-0, pie-8.7.6.6)] on linux2 Type help, copyright, credits or license for more information. 25 25 (_ | _) 25 There's clearly some

Help with splitting

2005-04-01 Thread RickMuller
I'm trying to split a string into pieces on whitespace, but I want to save the whitespace characters rather than discarding them. For example, I want to split the string '12' into ['1','','2']. I was certain that there was a way to do this using the standard string functions, but I just

Re: Help with splitting

2005-04-01 Thread Jeremy Bowers
On Fri, 01 Apr 2005 14:20:51 -0800, RickMuller wrote: I'm trying to split a string into pieces on whitespace, but I want to save the whitespace characters rather than discarding them. For example, I want to split the string '12' into ['1','','2']. I was certain that there was a way

Re: that is it is not it (logic in Python)

2005-04-01 Thread Jeremy Bowers
On Fri, 01 Apr 2005 22:01:25 +, F. Petitjean wrote: Le Fri, 1 Apr 2005 13:39:47 -0500, Terry Reedy a crit : This is equivalent to '(that is it) and (it is not it)' which is clearly false. False # What ? Reread the ref manual on chained comparison operators. And see the date of

Re: unittest vs py.test?

2005-04-01 Thread Colin J. Williams
Grig Gheorghiu wrote: In my mind, practicing TDD is what matters most. Which framework you choose is a function of your actual needs. The fact that there are 3 of them doesn't really bother me. I think it's better to have a choice from a small number of frameworks rather than have no choice or

Re: System bell

2005-04-01 Thread Mr6
Bengt Richter wrote: On Fri, 01 Apr 2005 02:06:07 -0500, Steve Holden [EMAIL PROTECTED] wrote: Trent Mick wrote: [Baza wrote] Am I right in thinking that print \a should sound the system, 'bell'? It works on the shell on Windows for me (WinXP). Trent Interesting. From a Cygwin bash shell I got

How To Do It Faster?!?

2005-04-01 Thread andrea_gavana
Hello Jeremy NG, * Poke around in the Windows API for a function that does what you want, and hope it can do it faster due to being in the kernel. I could try it, but I think I have to explain a little bit more my problem. If you post more information about how you are using this data, I can

Re: Help with splitting

2005-04-01 Thread Brian Beck
RickMuller wrote: There's a chance I was instead thinking of something in the re module, but I also spent some time there without luck. Could someone point me to the right function, if it exists? The re solution Jeremy Bowers is what you want. Here's another (probably much slower) way for fun

Re: Case-insensitive dict, non-destructive, fast, anyone?

2005-04-01 Thread Raymond Hettinger
[Bengt Richter] I wonder if a dict with a general override hook for hashing all keys would be useful. E.g., a dict.__keyhash__ that would take key as arg and default as now returning key.__hash__() but that you could override. Seems like this could potentially be more efficient than key

Re: Queue.Queue-like class without the busy-wait

2005-04-01 Thread David Bolen
Paul L. Du Bois [EMAIL PROTECTED] writes: Has anyone written a Queue.Queue replacement that avoids busy-waiting? It doesn't matter if it uses os-specific APIs (eg WaitForMultipleObjects). I did some googling around and haven't found anything so far. This isn't a Queue.Queue replacement, but

Re: that is it is not it (logic in Python)

2005-04-01 Thread F. Petitjean
Le Fri, 01 Apr 2005 17:42:30 -0500, Jeremy Bowers a écrit : On Fri, 01 Apr 2005 22:01:25 +, F. Petitjean wrote: Le Fri, 1 Apr 2005 13:39:47 -0500, Terry Reedy a écrit : This is equivalent to '(that is it) and (it is not it)' which is clearly false. False # What ? Reread the ref

Re: unittest vs py.test?

2005-04-01 Thread Peter Hansen
Colin J. Williams wrote: unittest seems rather heavy. I don't like mixing tests with documentation, it gives the whole thing a cluttered look. unittest can really be rather light. Most of our test cases are variations on the following, with primarily application-specific code added rather than

Re: Help with splitting

2005-04-01 Thread Raymond Hettinger
[Brian Beck] py from itertools import groupby py [''.join(g) for k, g in groupby(' test ing ', lambda x: x.isspace())] [' ', 'test', ' ', 'ing', ' '] Brilliant solution! That leads to a better understanding of groupby as a tool for identifying transitions without consuming them. I tried

Re: Help with splitting

2005-04-01 Thread Jeremy Bowers
On Fri, 01 Apr 2005 18:01:49 -0500, Brian Beck wrote: py from itertools import groupby py [''.join(g) for k, g in groupby(' test ing ', lambda x: x.isspace())] [' ', 'test', ' ', 'ing', ' '] I tried replacing the lambda thing with an attrgetter, but apparently my understanding of that

Re: Ternary Operator in Python

2005-04-01 Thread Terry Reedy
Carl Banks [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] A unary operator has one operand; a binary operator has two operands; ternary operator has three operands. Python has none built-in, Not so fast, my friend. What about the expression 0.0 a 1.0? Gee, what about 0.0 a

Re: unittest vs py.test?

2005-04-01 Thread Roy Smith
Peter Hansen [EMAIL PROTECTED] wrote: unittest can really be rather light. Most of our test cases are variations on the following, with primarily application-specific code added rather than boilerplate or other unittest-related stuff: import unittest class TestCase(unittest.TestCase):

Re: How To Do It Faster?!?

2005-04-01 Thread Jeremy Bowers
On Sat, 02 Apr 2005 01:00:34 +0200, andrea_gavana wrote: Hello Jeremy NG, ... I hope to have been clearer this time... I really welcome all your suggestions. Yes, clearer, though I still don't know what you're *doing* with that data :-) Here's an idea to sort of come at the problem from

Re: System bell

2005-04-01 Thread Trent Mick
[Mr6 wrote] It's a weird thing. But if I run print \a from idle it does not work. But if I save as a file, say, sound.py. Then run that with python sound.py it does. Why is that? The IDLE stdout/stderr handling is not invoking a system bell when it sees '\a'. I suppose that one could

Re: Case-insensitive dict, non-destructive, fast, anyone?

2005-04-01 Thread Bengt Richter
On Fri, 01 Apr 2005 23:04:42 GMT, Raymond Hettinger [EMAIL PROTECTED] wrote: [Bengt Richter] I wonder if a dict with a general override hook for hashing all keys would be useful. E.g., a dict.__keyhash__ that would take key as arg and default as now returning key.__hash__() but that you could

Re: that is it is not it (logic in Python)

2005-04-01 Thread Terry Reedy
F. Petitjean [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Le Fri, 1 Apr 2005 13:39:47 -0500, Terry Reedy a écrit : Reread the ref manual on chained comparison operators. And see the date of the post :-) Ditto for the reply ;-) TJR --

Re: Ternary Operator in Python

2005-04-01 Thread Roy Smith
In article [EMAIL PROTECTED], Carl Banks [EMAIL PROTECTED] wrote: Terry Reedy wrote: praba kar [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Dear All, I am new to Python. I want to know how to work with ternary operator in Python. I cannot find any ternary

Re: Grouping code by indentation - feature or ******?

2005-04-01 Thread Steve Holden
Javier Bezos wrote: Myles Strous [EMAIL PROTECTED] escribió en el mensaje news:[EMAIL PROTECTED] satisfy some handy properties, the first of which being: l[:n] + l[n:] = l I don't think l[:5] + l[5:] = l is a handy property and to me is clearly counterintuitive. Further, It can be quite useful

Re: [python-perl] Translation review?

2005-04-01 Thread Steve Holden
Traceback (most recent call last): File stdin, line 19, in ? IOError: [Errno 2] No such file or directory: 'stdin' (in both Windows 2.4 and Cygwin 2.4) regards Steve TSO wrote: Hi there, I've recently tried to translate some Perl code into Python - code is below. Is there a more Pythonic form?

Re: New to programming question

2005-04-01 Thread Steve Holden
Joal Heagney wrote: Bengt Richter wrote: On Fri, 01 Apr 2005 07:46:41 GMT, Joal Heagney [EMAIL PROTECTED] wrote: Oh goddammmni. I seem to be doing this a lot today. Look below for the extra addition to the code I posted. Joal Heagney wrote: Here's my contribution anycase: count = 0 # Get

Re: Case-insensitive dict, non-destructive, fast, anyone?

2005-04-01 Thread Raymond Hettinger
Taken together, these six attributes/methods could cover many wished for features for the 10% of the cases where a regular dictionary doesn't provide the best solution. You think as much as 10% ? Rounded up from 9.6 ;-) More important than the percentage is the clarity of the resulting code

Re: StopIteration in the if clause of a generator expression

2005-04-01 Thread Raymond Hettinger
I assumed that all standard sequence consumers (including list, of course) would intercept the StopIteration of a sequence given them in the form of a generator expression, so your lyst example would have an analogue for other sequence consumers as well, right? I.e., there's not a hidden

Re: unittest vs py.test?

2005-04-01 Thread Raymond Hettinger
[Peter Hansen] unittest can really be rather light. Most of our test cases are variations on the following, with primarily application-specific code added rather than boilerplate or other unittest-related stuff: import unittest class TestCase(unittest.TestCase): def test01(self):

Re: unittest vs py.test?

2005-04-01 Thread Peter Hansen
Raymond Hettinger wrote: BTW, the above code simplifies to: from py.test import raises assert a == b raises(Error, func, args) This is pretty, but I *want* my tests to be contained in separate functions or methods. The trivial amount of extra overhead that unittest requires fits with the way I

Re: Looking for Benchmarklets to improve pyvm

2005-04-01 Thread Skip Montanaro
Stelios I'm collecting small testlets to benchmark it, discover Stelios bottlenecks and improve it. They should be small and not use Stelios any crazy modules. Only [sys, os, itertools, thread, Stelios threading, math, random] for now. Take a look around for Marc Andre

Re: Help with splitting

2005-04-01 Thread RickMuller
Thanks to everyone who responded!! I guess I have to study my regular expressions a little more closely. -- http://mail.python.org/mailman/listinfo/python-list

Re: Lambda: the Ultimate Design Flaw

2005-04-01 Thread Aahz
In article [EMAIL PROTECTED], =?iso-8859-1?Q?Fran=E7ois?= Pinard [EMAIL PROTECTED] wrote: [Sunnan] [...] for Pythons ideal of having one canonical, explicit way to program. No doubt it once was true, but I guess this ideal has been abandoned a few years ago. My honest feeling is that it

Re: Ternary Operator in Python

2005-04-01 Thread Carl Banks
Terry Reedy wrote: Carl Banks [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] A unary operator has one operand; a binary operator has two operands; ternary operator has three operands. Python has none built-in, Not so fast, my friend. What about the expression 0.0 a 1.0?

Re: unittest vs py.test?

2005-04-01 Thread Roy Smith
In article [EMAIL PROTECTED], Peter Hansen [EMAIL PROTECTED] wrote: As for Roy's comments: I use a small internally developed driver script which uses os.walk to find all the files matching tests/*_unit.py or tests/story*.py in all subfolders of the project, and which runs them in separate

[Newbie] Search-and-delete text processing problem...

2005-04-01 Thread Todd_Calhoun
I'm trying to learn about text processing in Python, and I'm trying to tackle what should be a simple task. I have long text files of books with a citation between each paragraph, which might be like Bill D. Smith, History through the Ages, p.5. So, I need to search for every line that starts

Re: Lambda: the Ultimate Design Flaw

2005-04-01 Thread Tom Breton
Daniel Silva [EMAIL PROTECTED] writes: [...] So now FOLD. This is actually the one we've always hated most, because, apart from a few examples involving + or *, almost every time we see a FOLD call with a non-trivial function argument, we have to grab pen and paper and imagine the *result*

Re: Ternary Operator in Python

2005-04-01 Thread gene . tani
The good ol' DiveInto says: http://diveintopython.org/power_of_introspection/and_or.html#d0e9975 http://aspn.activestate.com/ASPN/Python/Cookbook/Recipe/52310 Diez B. Roggisch wrote: praba kar wrote: Dear All, I am new to Python. I want to know how to work with ternary operator in

Re: Search-and-delete text processing problem...

2005-04-01 Thread lostboard2001
Close: if line[:4] == 'Bill': . ^^ line == ' ' -- http://mail.python.org/mailman/listinfo/python-list

FAM and Python? (was Re: How To Do It Faster?!?)

2005-04-01 Thread Jeremy Bowers
On Sat, 02 Apr 2005 02:02:31 +0200, andrea_gavana wrote: Hello Jeremy NG, Every user of thsi big directory works on big studies regarding oil fields. Knowing the amount of data (and number of files) we have to deal with (produced by simulators, visualization tools, and so on) and knowing

Installing Python on a Windows 2000 Server

2005-04-01 Thread Mike Moum
Hi, I'm a civil engineer who also doubles as chief programmer for technical applications at my company. Most of our software is written in Visual Basic because our VP in charge of I.T. likes to have consistency, and at the moment we're a Microsoft shop. He has assigned me the task of

Re: Case-insensitive dict, non-destructive, fast, anyone?

2005-04-01 Thread Terry Reedy
Raymond Hettinger [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] More important than the percentage is the clarity of the resulting code and the avoidance of continous reinvention of workarounds. Separating tool features into a basic and an advanced version is common solution

Re: Decorater inside a function? Is there a way?

2005-04-01 Thread Ron_Adam
On Fri, 01 Apr 2005 16:46:14 -0500, Jeremy Bowers [EMAIL PROTECTED] wrote: On Fri, 01 Apr 2005 19:56:55 +, Ron_Adam wrote: On Fri, 01 Apr 2005 13:47:06 -0500, Jeremy Bowers [EMAIL PROTECTED] wrote: Is this an April Fools gag? If so, it's not a very good one as it's quite in line with the

Re: Search-and-delete text processing problem...

2005-04-01 Thread M.E.Farmer
Strings have many methods that are worth learning. If you haven't already discovered dir(str) try it. Also I am not sure if you were just typing in some pseudocode, but your use of writelines is incorrect. help(file.writelines) Help on built-in function writelines: writelines(...)

Module subprocess: How to communicate more than once?

2005-04-01 Thread Edward C. Jones
I have a program named octave (a Matlab clone). It runs in a terminal, types a prompt and waits for the user to type something. If I try # Run octave. oct = subprocess.Popen(octave, stdin=subprocess.PIPE) # Run an octave called startup. oct.communicate(startup) # Change directory inside octave.

(win32) speedfan api control

2005-04-01 Thread tlviewer
hello, If you run the Mainboard monitor, speedfan, here is an ActivePython script to force automatic fan control. http://www.almico.com/speedfan.php It's a great example of how clean the WinApi interface is in ActivePython. The script sets focus to the checkbox of interest and toggles the

Re: Lambda: the Ultimate Design Flaw

2005-04-01 Thread Bengt Richter
On 1 Apr 2005 20:00:13 -0500, [EMAIL PROTECTED] (Aahz) wrote: In article [EMAIL PROTECTED], =?iso-8859-1?Q?Fran=E7ois?= Pinard [EMAIL PROTECTED] wrote: [Sunnan] [...] for Pythons ideal of having one canonical, explicit way to program. No doubt it once was true, but I guess this ideal has

Re: Search-and-delete text processing problem...

2005-04-01 Thread M.E.Farmer
My apologies you did indeed use writelines correctly ;) dohhh! I had a gut reaction to this. Pyf = ['hij\n','efg\n','abc\n'] Py for i in f: ... if i.startswith('a'): ... i == '' Py f ['hij\n', 'efg\n', 'abc\n'] Notice that it does not modify the list in any way. You are trying to loop

boring the reader to death (wasRe: Lambda: the Ultimate Design Flaw

2005-04-01 Thread Sunnan
Aahz wrote: The joy of coding Python should be in seeing short, concise, readable classes that express a lot of action in a small amount of clear code -- not in reams of trivial code that bores the reader to death. --GvR Can anyone please point me to the text that quote was taken from? I tried

Re: Ternary Operator in Python

2005-04-01 Thread Sunnan
Terry Reedy wrote: Gee, what about 0.0 a 1.0 b 2.0? I see both as synthesized multinary operators, but your are right in that this combination does act differently than a+b+c. Is really multinary in python? It looks binary to me, just like +. (a+b)+c (((0.0 a) 1.0) b ) 2.0 Sunnan --

Re: Ternary Operator in Python

2005-04-01 Thread Robert Kern
Sunnan wrote: Terry Reedy wrote: Gee, what about 0.0 a 1.0 b 2.0? I see both as synthesized multinary operators, but your are right in that this combination does act differently than a+b+c. Is really multinary in python? It looks binary to me, just like +. (a+b)+c (((0.0 a) 1.0) b )

Re: Pseudocode in the wikipedia

2005-04-01 Thread Sunnan
James Stroud wrote: bob == (carol = 2): if bob = (bob or carol): bob == 4 But no one could figure out what bob was supposed to equal anyway. Wouldn't bob equal the boolean result of the expression (carol = 2)? -- http://mail.python.org/mailman/listinfo/python-list

Re: [Newbie] Search-and-delete text processing problem...

2005-04-01 Thread Bengt Richter
On Fri, 1 Apr 2005 17:33:59 -0800, Todd_Calhoun [EMAIL PROTECTED] wrote: I'm trying to learn about text processing in Python, and I'm trying to tackle what should be a simple task. I have long text files of books with a citation between each paragraph, Most text files aren't long enough to

Re: New to programming question

2005-04-01 Thread Ben
Thanks for your help. It is much appreciated. -- http://mail.python.org/mailman/listinfo/python-list

Re: New to programming question

2005-04-01 Thread Ben
Thanks for your input. -- http://mail.python.org/mailman/listinfo/python-list

Re: New to programming question

2005-04-01 Thread Ben
Thanks for your reply. -- http://mail.python.org/mailman/listinfo/python-list

Re: New to programming question

2005-04-01 Thread Joal Heagney
Steve Holden wrote: Joal Heagney wrote: Bengt Richter wrote: On Fri, 01 Apr 2005 07:46:41 GMT, Joal Heagney [EMAIL PROTECTED] wrote: Oh goddammmni. I seem to be doing this a lot today. Look below for the extra addition to the code I posted. Joal Heagney wrote: Here's my contribution

Re: Python plug-in Frameworks like Eclipse RCP...

2005-04-01 Thread Jim Hargrave
Hum, maybe my question was too specific. What I would really like to know is what is the best way to implement a Python application with a pluggable architecture. In particular, I would like to use wxPython and have plug ins automatically register themselves with the GUI by adding themselves

Re: Queue.Queue-like class without the busy-wait

2005-04-01 Thread Paul Rubin
Have you looked at this? A paper about adding asynchronous exceptions to Python. http://www.cs.williams.edu/~freund/papers/02-lwl2.ps -- http://mail.python.org/mailman/listinfo/python-list

Re: boring the reader to death (wasRe: Lambda: the Ultimate Design Flaw

2005-04-01 Thread Tim Peters
[Aahz] The joy of coding Python should be in seeing short, concise, readable classes that express a lot of action in a small amount of clear code -- not in reams of trivial code that bores the reader to death. --GvR [Sunnan] Can anyone please point me to the text that quote was taken from? I

Simple thread-safe counter?

2005-04-01 Thread Paul Rubin
I'd like to have a function (or other callable object) that returns 0, 1, 2, etc. on repeated calls. That is: print f() # prints 0 print f() # prints 1 print f() # prints 2 # etc. There should never be any possibility of any number getting returned twice, or getting

Re: Lambda: the Ultimate Design Flaw

2005-04-01 Thread François Pinard
[Aahz] =?iso-8859-1?Q?Fran=E7ois?= Pinard [EMAIL PROTECTED] wrote: No doubt it once was true, but I guess this ideal has been abandoned a few years ago. My honest feeling is that it would be a mis-representation of Python, assertng today that this is still one of the Python's ideals.

Re: New to programming question

2005-04-01 Thread Joal Heagney
Joal Heagney wrote: Steve Holden wrote: I suppose this would be far too easy to understand, then: pr =['Guess my name', 'Wrong, try again', 'Last chance'] for p in pr: name = raw_input(p+: ) if name == Ben: print You're right! break else: print Loser: no more tries for you regards

<    1   2   3   >