[Tutor] Kill a socket doing a recvfrom

2010-01-13 Thread Michael Bernhard Arp Sørensen
Greetings my masters. How do I kill a socket which is locked in a recvfrom? My effort to kill it failed. The socket is running in its own thread. Any bright ideas? Med venlig hilsen/Kind regards Michael B. Arp Sørensen Programmer / BOFH "If you want to enter my network while I'm out, you can f

[Tutor] help using f2py

2010-01-13 Thread Jose Amoreira
Hello! I posted this question on the f2py list but since I haven't got any answers (yet), I thought I'd try my luck here. I'm having a hard time wrapping a fortran subroutine into a python module. The problem seems to be related to having a subroutine argument to the fortran subroutine. A simpl

Re: [Tutor] samples on sort method of sequence object.

2010-01-13 Thread Albert-Jan Roskam
Interesting. Can this also be used to make sorting of alphanumerical list items in a 'numerical' way easier? E.g.: >>> x ['var_0', 'var_13', 'var_11', 'var_9', 'var_4', 'var_1', 'var_5', 'var_6', 'var_7', 'var_14', 'var_2', 'var_3', 'var_8', 'var_10', 'var_12'] >>> x.sort() >>> x ['var_0', 'var_1

Re: [Tutor] samples on sort method of sequence object.

2010-01-13 Thread Stefan Behnel
Albert-Jan Roskam, 13.01.2010 13:51: Interesting. Can this also be used to make sorting of alphanumerical list items in a 'numerical' way easier? E.g.: x ['var_0', 'var_13', 'var_11', 'var_9', 'var_4', 'var_1', 'var_5', 'var_6', 'var_7', 'var_14', 'var_2', 'var_3', 'var_8', 'var_10', 'var_12'

Re: [Tutor] samples on sort method of sequence object.

2010-01-13 Thread Sander Sweers
2010/1/13 Albert-Jan Roskam > > Interesting. Can this also be used to make sorting of alphanumerical list > items in a 'numerical' way easier? > >>> x > ['var_0', 'var_13', 'var_11', 'var_9', 'var_4', 'var_1', 'var_5', 'var_6', > 'var_7', 'var_14', 'var_2', 'var_3', 'var_8', 'var_10', 'var_12']

Re: [Tutor] samples on sort method of sequence object.

2010-01-13 Thread Albert-Jan Roskam
Very concise == neat solutions. Yummy. ;-) Thanks for your replies! Cheers!! Albert-Jan ~~ In the face of ambiguity, refuse the temptation to guess. ~~ --- On W

Re: [Tutor] samples on sort method of sequence object.

2010-01-13 Thread Hugo Arts
I should note that this doesn't solve the general case of mixed numeric/alphabetic sorting: >>> a = ['a_1', 'a_2', 'a_3', 'a_4', 'a_10', 'b_1', 'b_2', 'b_3', 'b_4', 'b_10'] >>> a.sort(key=lambda x: int(x.split('_')[-1])) >>> a ['a_1', 'b_1', 'a_2', 'b_2', 'a_3', 'b_3', 'a_4', 'b_4', 'a_10', 'b_10'

[Tutor] how to sort a tab delim file

2010-01-13 Thread Hs Hs
Hi: I have a tab-delim file: col1 col2 col3 andrew1987 1990 jake 1974 1980 jim 1964 1970 lance1984 1992 how can I sort column 2 and get : jim 1964 1970 jake 1974 1980 lance1984 1992 andrew1987 1990 I know

Re: [Tutor] how to sort a tab delim file

2010-01-13 Thread vince spicer
On Wed, Jan 13, 2010 at 9:21 AM, Hs Hs wrote: > Hi: > > I have a tab-delim file: > > col1 col2 col3 > andrew1987 1990 > jake 1974 1980 > jim 1964 1970 > lance1984 1992 > > > how can I sort column 2 and get : > jim 1964 1970 > jake

Re: [Tutor] how to sort a tab delim file

2010-01-13 Thread vince spicer
On Wed, Jan 13, 2010 at 9:21 AM, Hs Hs wrote: > Hi: > > I have a tab-delim file: > > col1 col2 col3 > andrew1987 1990 > jake 1974 1980 > jim 1964 1970 > lance1984 1992 > > > how can I sort column 2 and get : > jim 1964 1970 > jake

[Tutor] Searching in a file

2010-01-13 Thread Paul Melvin
did use enumerate and was wondering if I could use the line number, or maybe I could use an re iterator. Any advice would be much appreciated. Thanks paul __ Information from ESET Smart Security, version of virus signature database 4767 (20100113) __ The mess

Re: [Tutor] samples on sort method of sequence object.

2010-01-13 Thread Stefan Behnel
Hugo Arts, 13.01.2010 15:25: Here is my solution for the general case: from itertools import groupby def alphanum_key(string): t = [] for isdigit, group in groupby(string, str.isdigit): group = ''.join(group) t.append(int(group) if isdigit else group) return t Note

Re: [Tutor] samples on sort method of sequence object.

2010-01-13 Thread Hugo Arts
On Wed, Jan 13, 2010 at 8:21 PM, Stefan Behnel wrote: > Hugo Arts, 13.01.2010 15:25: >> >> Here is my solution for the general case: >> >> from itertools import groupby >> def alphanum_key(string): >>    t = [] >>    for isdigit, group in groupby(string, str.isdigit): >>        group = ''.join(gro

Re: [Tutor] how to sort a tab delim file

2010-01-13 Thread wesley chun
> I have a tab-delim file: > > col1 col2 col3 > andrew    1987   1990 > jake 1974   1980 > jim   1964   1970 > lance    1984   1992 > > how can I sort column 2 and get : > jim   1964   1970 > jake 1974   1980 > lance    1984   1992 > andrew    198

Re: [Tutor] Searching in a file

2010-01-13 Thread wesley chun
> I have a file generated from a webpage. > I want to search that file for a specific keyword, in my case 'NEW'. > Once I have found that keyword I want to retrieve information below it, e.g. > web link, size of file etc. > When I have this information I move off until I find another 'NEW' and the

Re: [Tutor] Searching in a file

2010-01-13 Thread Emile van Sebille
Emile I did use enumerate and was wondering if I could use the line number, or maybe I could use an re iterator. Any advice would be much appreciated. Thanks paul __ Information from ESET Smart Security, version of virus signature database 4767 (20100113) __

Re: [Tutor] samples on sort method of sequence object.

2010-01-13 Thread Kent Johnson
On Wed, Jan 13, 2010 at 2:21 PM, Stefan Behnel wrote: > Hugo Arts, 13.01.2010 15:25: >> >> Here is my solution for the general case: >> >> from itertools import groupby >> def alphanum_key(string): >>    t = [] >>    for isdigit, group in groupby(string, str.isdigit): >>        group = ''.join(gro

Re: [Tutor] Searching in a file

2010-01-13 Thread Hugo Arts
On Wed, Jan 13, 2010 at 6:49 PM, Paul Melvin wrote: > Hi, > > I have a file generated from a webpage. > > I want to search that file for a specific keyword, in my case 'NEW'. > > Once I have found that keyword I want to retrieve information below it, e.g. > web link, size of file etc. > > When I h

Re: [Tutor] Searching in a file

2010-01-13 Thread Alan Gauld
"Hugo Arts" wrote the most obvious answer would be to take a look at the 'next()' function, that should solve this immediate problem. This would be nmy advice too, but you need to get an explicit iterator to use it. it = open(.) for line in it: if 'NEW' in line: ln = it.next

Re: [Tutor] Searching in a file

2010-01-13 Thread Hugo Arts
On Thu, Jan 14, 2010 at 12:05 AM, Alan Gauld wrote: > > I prefer the next() approach. Rightfully so. IMO, The while loop with readline is basically the C version of that, for the poor people who don't have iterators. > But a third option is to use a split and apply it to the whole file as > a st

Re: [Tutor] samples on sort method of sequence object.

2010-01-13 Thread Lie Ryan
On 01/14/10 06:56, Hugo Arts wrote: > On Wed, Jan 13, 2010 at 8:21 PM, Stefan Behnel wrote: >> Hugo Arts, 13.01.2010 15:25: >>> >>> Here is my solution for the general case: >>> >>> from itertools import groupby >>> def alphanum_key(string): >>>t = [] >>>for isdigit, group in groupby(strin

Re: [Tutor] samples on sort method of sequence object.

2010-01-13 Thread Hugo Arts
On Thu, Jan 14, 2010 at 1:47 AM, Lie Ryan wrote: > On 01/14/10 06:56, Hugo Arts wrote: >> On Wed, Jan 13, 2010 at 8:21 PM, Stefan Behnel wrote: >>> Hugo Arts, 13.01.2010 15:25: Here is my solution for the general case: from itertools import groupby def alphanum_key(string

[Tutor] Keeping a list of attributes of a certain type

2010-01-13 Thread Guilherme P. de Freitas
Hi everybody, Here is my problem. I have two classes, 'Body' and 'Member', and some attributes of 'Body' can be of type 'Member', but some may not. The precise attributes that 'Body' has depend from instance to instance, and they can be added or deleted. I need any instance of 'Body' to keep an up

[Tutor] confidence interval

2010-01-13 Thread Andrew Fithian
Hi tutor, I have this code for generating a confidence interval from an array of values: import numpy as np import scipy as sp def mean_confidence_interval(data, confidence=0.95): a = 1.0*np.array(data) n = len(a) m, se = np.mean(a), sp.stats.stderr(a) h = se * sp.stats.t._pp

Re: [Tutor] Keeping a list of attributes of a certain type

2010-01-13 Thread Guilherme P. de Freitas
Ok, I got something that seems to work for me. Any comments are welcome. class Member(object): def __init__(self): pass class Body(object): def __init__(self): self.members = [] def __setattr__(self, obj, value): if isinstance(value, Member): sel