Re: comparing two lists and returning position

2007-06-25 Thread Charles Sanders
hiro wrote: bare in mind that I have a little over 10 million objects in my list (l2) and l1 contains around 4 thousand objects.. (i have enough ram in my computer so memory is not a problem) Glad to see you solved the problem with the trailing space. Just one minor point, I did say or

Re: comparing two lists and returning position

2007-06-21 Thread Charles Sanders
Paul Rubin wrote: from itertools import izip pos = map(dict(izip(l2, count())).__getitem__, l1) or probably less efficiently ... l1 = [ 'abc', 'ghi', 'mno' ] l2 = [ 'abc', 'def', 'ghi', 'jkl', 'mno', 'pqr'] pos = [ l2.index(i) for i in l1 ] print pos [0, 2, 4] Charles --

Re: ctypes: error passing a list of str to a fortran dll

2007-06-04 Thread Charles Sanders
luis wrote: I'm using ctypes to call a fortran dll from python. I have no problems passing integer and double arryas, but I have an error with str arrys. For example: [snip] I do not know about Microsoft Fortran compilers (your mention of dll indicates you are probably using MS), nor much

Re: Is PEP-8 a Code or More of a Guideline?

2007-05-30 Thread Charles Sanders
Dave Hansen wrote: The date is about right (actually, a little early: ASR-33, 1965; C, about 1970), but you can't program C on an ASR-33. Keywords are all lower case, and always have been. IF is a syntax error... But the Unix terminal drivers of the day for upper case only

Re: installing cx_Oracle.

2007-05-24 Thread Charles Sanders
Doug Phillips wrote: It also works the other way around, at least on the non-empty set of systems that contains my workstation. export simply marks the variable name for automatic export to the environment of subsequent commands. The value at that time doesn't matter. What matters is the

Re: Regexes: How to handle escaped characters

2007-05-18 Thread Charles Sanders
Torsten Bronger wrote: Hallöchen! [...] Example string: uHollo, escaped positions: [4]. Thus, the second o is escaped and must not be found be the regexp searches. Instead of re.search, I call the function guarded_search(pattern, text, offset) which takes care of escaped caracters. Thus,

Re: preferred windows text editor?

2007-05-10 Thread Charles Sanders
Ant wrote: What method of executing code snippets in a Python shell do other Vim users use? Other than just copy/paste? Not vim, but good old vi so should work in vim 1. Mark the start of the fragment, for exampls ms (to mark with label s). Labels a through z are available. 2. Move to the

Re: interesting exercise

2007-05-09 Thread Charles Sanders
Michael Tobis wrote: Here is the bloated mess I came up with. I did see that it had to be recursive, and was proud of myself for getting it pretty much on the first try, but the thing still reeks of my sorry old fortran-addled mentality. Recursion is not necessary, but is much, much clearer.

Re: Multiple regex match idiom

2007-05-09 Thread Charles Sanders
Hrvoje Niksic wrote: I often have the need to match multiple regexes against a single string, typically a line of input, like this: if (matchobj = re1.match(line)): ... re1 matched; do something with matchobj ... elif (matchobj = re2.match(line)): ... re2 matched; do something with

Re: interesting exercise

2007-05-09 Thread Charles Sanders
[EMAIL PROTECTED] wrote: On May 9, 1:13 am, Charles Sanders [EMAIL PROTECTED] wrote: [snip] or even this monstrosity ... def permute2( s, n ): return [ ''.join([ s[int(i/len(s)**j)%len(s)] for j in range(n-1,-1,-1)]) for i in range(len(s)**n) ] print permute2('abc',2

Re: 4 quadrant atan

2007-05-03 Thread Charles Sanders
Roel Schroeven wrote: I might be wrong of course, but can't you just use atan2? Only problem is that it returns negative angles for quadrants 3 and 4, but that is easily solved. In Python: from math import atan2, pi, fmod def vectorAngle(x, y): return fmod(atan2(y, x) + 2*pi, 2*pi)

Re: Lazy evaluation: overloading the assignment operator?

2007-05-02 Thread Charles Sanders
Diez B. Roggisch wrote: I fail to see where laziness has anything to do with this. In C++, this problem can be remedied with the so called temporary base class idiom. I have seen this referred to as lazy evaluation in C++, so I suspect that Diez and Sturia are using Lazy evaluation

Re: scaling

2007-05-01 Thread Charles Sanders
Gabriel Genellina wrote: [snip] if xminvalue: yield 0 elif xmaxvalue: yield top else: yield (x-minvalue)*top/(maxvalue-minvalue) [snip] Personally, I find yield min(top,max(0,(x-minvalue)*top/(maxvalue-minvalue))) or scaled_value =

Re: Python not giving free memory back to the os get's me in real problems ...

2007-04-25 Thread Charles Sanders
Grant Edwards wrote: Assuming the python interpreter free()s the memory, my understanding is that on Unixes the memory is returned to the pool used by malloc(), but is not returned to the OS since there isn't a practical way to ensure that the memory at the end of the data segment is not

Re: Strange terminal behavior after quitting Tkinter application

2007-04-24 Thread Charles Sanders
Chris wrote: ... Quitting by typing 'sys.exit()' in the interpreter also works fine. Only quitting via the GUI seems to cause the problem. As previously stated, I know nothing about Tkinter, but it definitely looks like there is some cleanup being skipped on a GUI exit that is in fact

Re: Compare regular expressions

2007-04-19 Thread Charles Sanders
Thomas Dybdahl Ahle wrote: Hi, I'm writing a program with a large data stream to which modules can connect using regular expressions. Now I'd like to not have to test all expressions every time I get a line, as most of the time, one of them having a match means none of the others can

Re: Strange terminal behavior after quitting Tkinter application

2007-04-18 Thread Charles Sanders
Chris wrote: But does anyone know why the Tkinter program is doing this to the terminal in the first place? I don't want to have to tell users of my program that they must recover their terminal's sanity each time after running my program. I don't know about Tkinter, but my guess

Re: strange behaviour sys.argv

2007-04-17 Thread Charles Sanders
schnupfy wrote: ok, thanks for the answers. I try to hand over the 3rd part (the long trap) as one cmd argument. I will ask in a shell ng. Thanks again. Cheers Should be as simple as removing the backslashes /root/mk/services.py $HOST $SEVERITY $TRAP should pass TRAP as a single

Re: strange behaviour sys.argv

2007-04-16 Thread Charles Sanders
Michael Hoffman wrote: schnupfy wrote: I am not used to python and I am wondering about this thing: This is not a Python question. It is a question about how to use bash. [snip] Michael is correct, it is a bash thing, nothing to do with python. bash (and other *nix like shells) generally

Re: Problem with algorithm

2007-04-13 Thread Charles Sanders
Paul Rubin wrote: [snip] def a(n): if n==0: yield '' return for c in s: for r in a(n-1): yield c+r print list(a(3)) Of course, obvious in retrospect, recursion instead of iteration. I have yet to completely

Re: Problem with algorithm

2007-04-12 Thread Charles Sanders
[EMAIL PROTECTED] wrote: On Apr 12, 10:16�pm, Jia Lu [EMAIL PROTECTED] wrote: Hi all. �I want to create a large list like: ~ Is there any good algorithm to do this? Sure. test = '01' for m in test: for n in test: for o in test: for p in test:

How to tell easy_install that a package is already installed

2007-03-21 Thread Charles Sanders
I am not sure if this is the right forum to ask this. If it is not, could someone pleas point me to a more appropriate newsgroup. I am attempting to install dap.plugins.netcdf using easy_install on HP-UX 11. As a user, I do not have access to root so have followed the easy_install recommendation