[issue31652] make install fails: no module _ctypes

2019-07-26 Thread Thomas Dybdahl Ahle
Thomas Dybdahl Ahle added the comment: Installing libffi-dev worked for me. -- nosy: +thomasahle ___ Python tracker <https://bugs.python.org/issue31652> ___ ___

[issue37682] random.sample should support iterators

2019-07-25 Thread Thomas Dybdahl Ahle
New submission from Thomas Dybdahl Ahle : Given a generator `f()` we can use `random.sample(list(f()), 10)` to get a uniform sample of the values generated. This is fine, and fast, as long as `list(f())` easily fits in memory. However, if it doesn't, one has to implement the reservoir sampling

[issue33447] Asynchronous lambda syntax

2018-05-31 Thread Thomas Dybdahl Ahle
Thomas Dybdahl Ahle added the comment: Just wanted to add another use-case. In a project I'm working on, we are building a lot of graphs using code like this: ``` nodes = [ Node('node-name1', children=[...], classifier=has_foo), Node('node-name2', children

[issue21592] Make statistics.median run in linear time

2014-06-02 Thread Thomas Dybdahl Ahle
Thomas Dybdahl Ahle added the comment: I don't know if it's worth the overhead to implement a multiselect, given we only expose a median function. I've rewritten select2 to be intro, just falling back on sorting. This doesn't appear to degrade the performance. I also added np.median

[issue21592] Make statistics.median run in linear time

2014-05-31 Thread Thomas Dybdahl Ahle
Thomas Dybdahl Ahle added the comment: I think minimize expected-case time is a good goal. If we wanted minimize worst-case time we would have to use k-means rather than quickselect. My trials on random data, where sort arguably has a disadvantage, suggests sorting is about twice as fast

[issue21592] Make statistics.median run in linear time

2014-05-30 Thread Thomas Dybdahl Ahle
Thomas Dybdahl Ahle added the comment: If you have a good, realistic test set, we can try testing quick-select vs sorting. If it's still not good, I can also reimplement it in C. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org

[issue21592] Make statistics.median run in linear time

2014-05-28 Thread Thomas Dybdahl Ahle
New submission from Thomas Dybdahl Ahle: The statistics module currently contains the following comment: FIXME: investigate ways to calculate medians without sorting? Quickselect? This is important, because users expect standard library functions to use state of the art implementations

[issue21592] Make statistics.median run in linear time

2014-05-28 Thread Thomas Dybdahl Ahle
Thomas Dybdahl Ahle added the comment: I have written some proof of concept code here [1], I would appreciate you commenting on it, before I turn it into a patch, as I haven't contributed code to Python before. I have tried to write it as efficiently as possible, but it is of course possible

[issue457066] pow(a,b,c) should accept b0

2012-01-22 Thread Thomas Dybdahl Ahle
Thomas Dybdahl Ahle lob...@gmail.com added the comment: For anyone who finds this through google, if you are finding the inverse mod a prime, you can use fermats little theorem: pow(a, -1, mod) = pow(a, a-2, mod). (You also need that mod doesn't divide a). -- nosy: +Thomas.Dybdahl.Ahle

[issue7522] random.choice should accept a set as input

2010-05-06 Thread Thomas Dybdahl Ahle
Thomas Dybdahl Ahle lob...@gmail.com added the comment: Why not just add support to the set container? As far as I know, it is a binary search tree, so supporting random picking in O(logn) should be easy. -- nosy: +Thomas.Dybdahl.Ahle ___ Python

Re: Feature suggestion: sum() ought to use a compensated summation algorithm

2008-05-03 Thread Thomas Dybdahl Ahle
On Sat, 2008-05-03 at 21:37 +, Ivan Illarionov wrote: On Sat, 03 May 2008 20:44:19 +0200, Szabolcs Horvát wrote: Arnaud Delobelle wrote: sum() works for any sequence of objects with an __add__ method, not just floats! Your algorithm is specific to floats. This occurred to me

Re: Rounding a number to nearest even

2008-04-15 Thread Thomas Dybdahl Ahle
On Fri, 2008-04-11 at 03:14 -0700, bdsatish wrote: The built-in function round( ) will always round up, that is 1.5 is rounded to 2.0 and 2.5 is rounded to 3.0. If I want to round to the nearest even, that is my_round(1.5) = 2# As expected my_round(2.5) = 2# Not 3, which

Re: Why does python behave so? (removing list items)

2008-03-26 Thread Thomas Dybdahl Ahle
On Wed, 2008-03-26 at 23:04 +0100, Michał Bentkowski wrote: Why does python create a reference here, not just copy the variable? Python, like most other oo languages, will always make references for =, unless you work on native types (numbers and strings). Instead use one of: k = j[:] or k =

Adding more warnings

2008-02-20 Thread Thomas Dybdahl Ahle
I tend to make a lot of mistakes of misspelled variable names. Is it possible to make python warn me about those at compile time? Very few times I use dynamic variable initialization. I can live with getting a warning for those as well. -- Best Regards, Med Venlig Hilsen, Thomas --

Announcement: PyChess Philidor 0.8 final

2008-02-19 Thread Thomas Dybdahl Ahle
PyChess Philidor 0.8 has been released. This happens after nearly a year coding, and a rewrite of large parts of the codebase for stability and features. If you haven't already beaten fruit, gnuchess, pychess-engine and your friend with PyChess, now is time to! The most prominent new features

Re: OT: Speed of light [was Re: Why not a Python compiler?]

2008-02-09 Thread Thomas Dybdahl Ahle
On Sat, 2008-02-09 at 14:56 +0100, Martin P. Hellwig wrote: Propagate, travel, what's the difference? Unfortunately, I didn't study any of this but I sure do remember the answer one drunk physic said to me in a bar when I ask him the question: Does light travel or propagate? He

[issue1722344] Thread shutdown exception in Thread.notify()

2008-02-06 Thread Thomas Dybdahl Ahle
Thomas Dybdahl Ahle added the comment: which means no global namespace access Does that mean that you cannot use len and range in a Thread? -- nosy: +lobais _ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1722344

Re: Python GUI toolkit

2008-02-03 Thread Thomas Dybdahl Ahle
On Sun, 2008-02-03 at 15:18 +, [EMAIL PROTECTED] wrote: what would be the best python GUI toolkit, it must be cross platform. i have tried gtk, but it interface are real bad and its coding was difficult so i dropped it, I came from Sving to Gtk, so for me also it was a real brainbreak.

Re: Does anyone else use this little idiom?

2008-02-03 Thread Thomas Dybdahl Ahle
On Sat, 2008-02-02 at 18:03 -0800, [EMAIL PROTECTED] wrote: for _ in xrange (1,n): some code I'd always use i for loop variables I don't know what to call. It stands for iterator or something. In a nested loop the next variable would simply be called j and so on. I also tend to use _, but

Re: Project naming suggestions?

2008-02-03 Thread Thomas Dybdahl Ahle
On Sun, 2008-02-03 at 10:17 -0800, [EMAIL PROTECTED] wrote: I'm considering writing a little interpreter for a python-like language and I'm looking for name suggestions. :-) Basically, I don't want to change a whole lot about Python. In fact, I see myself starting with the compiler module

Bit Scan Forward and Reverse

2008-01-18 Thread Thomas Dybdahl Ahle
Hi, I'm writing an app in python, and I'm storing some a lot of data in bitmaps. I need a way to find the first or latest set bit in a 64bit number, and for that I've implemented a small routine. Thing is that this routine is not as fast as I'd wish. I know most processors implement BSF

[issue1731] Random errors on interpreter shutdown

2008-01-03 Thread Thomas Dybdahl Ahle
Thomas Dybdahl Ahle added the comment: The fix looks nice. I'll just implement it locally in my app for python 2.4. Thanks __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1731

[issue1731] Random errors on interpreter shutdown

2008-01-03 Thread Thomas Dybdahl Ahle
Thomas Dybdahl Ahle added the comment: I run this now in the beginning of my code. As far as I can see it works fine. if not hasattr(Thread, _Thread__bootstrap_inner): class SafeThread (Thread): def encaps(self): try: self._Thread__bootstrap_inner

Re: building a GUI

2007-09-23 Thread Thomas Dybdahl Ahle
Den Sun, 23 Sep 2007 17:28:38 +0200 skrev stef mientki: yadin wrote: if i were up to make a GUI chich are the advantages of choosing python over matlab or java? The best is Delphi, second is VB, That sounds mostly like a personal preference :) I would certainly suggest Python very much

Untrusted python code

2007-09-23 Thread Thomas Dybdahl Ahle
Hi, I have an application for which I want users to be able to make themes. I've planed a rather advanced model (in xml), which gives themes the option to redefine various drawing methods. Now I don't want those themes to be able to take over the current user, but I'd still like the scripts to

distutils install-data-hook

2007-09-14 Thread Thomas Dybdahl Ahle
Hey I have this pythonapp I'm trying to pack, and I've read in the Gnome specifications that I should run update-icon-cache after install, in order to get the menus and stuff correctly updated. Is there a way to specify a (list of) commands to be run after installation? --

Re: subprocess leaves child living

2007-06-07 Thread Thomas Dybdahl Ahle
Den Thu, 07 Jun 2007 07:00:53 + skrev reed: On Jun 5, 7:58 am, Thomas Dybdahl Ahle [EMAIL PROTECTED] wrote: Hi, When I do a small program like from subprocess import Popen popen = Popen([ping, google.com]) from time import sleep sleep(100) start it and kill it, the ping process lives

Re: subprocess leaves child living

2007-06-06 Thread Thomas Dybdahl Ahle
Den Tue, 05 Jun 2007 17:41:47 -0500 skrev Michael Bentley: On Jun 5, 2007, at 5:13 PM, Michael Bentley wrote: On Jun 5, 2007, at 4:17 PM, Thomas Dybdahl Ahle wrote: Den Tue, 05 Jun 2007 15:46:39 -0500 skrev Michael Bentley: But actually *that* is an orphan process. When a parent

subprocess leaves child living

2007-06-05 Thread Thomas Dybdahl Ahle
Hi, When I do a small program like from subprocess import Popen popen = Popen([ping, google.com]) from time import sleep sleep(100) start it and kill it, the ping process lives on. Is there a way to ensure that the ping process is always killed when the python process is? I can't use atexit, as

Re: subprocess leaves child living

2007-06-05 Thread Thomas Dybdahl Ahle
Den Tue, 05 Jun 2007 14:07:44 +0200 skrev Stefan Sonnenberg-Carstens: Thomas Dybdahl Ahle schrieb: Hi, When I do a small program like from subprocess import Popen popen = Popen([ping, google.com]) from time import sleep sleep(100) start it and kill it, the ping process lives

Re: subprocess leaves child living

2007-06-05 Thread Thomas Dybdahl Ahle
Den Tue, 05 Jun 2007 07:06:15 -0700 skrev Rob Wolfe: Thomas Dybdahl Ahle wrote: Problem is - I can't do that when I get killed. Isn't it possible to open processes in such a way like terminals? If I kill the terminal, everything open in it will die too. On POSIX platform you can use

Strange errors on exit

2007-06-05 Thread Thomas Dybdahl Ahle
When I close my (gtk) program, I get errors like the below. It seams that when the interpreter shuts down, it sets every variable to None, but continues running the threads, (seems only in cases where they've just been asleep) I don't think this would be intended behavior? Exception in thread

Re: subprocess leaves child living

2007-06-05 Thread Thomas Dybdahl Ahle
Den Tue, 05 Jun 2007 22:01:44 +0200 skrev Rob Wolfe: Thomas Dybdahl Ahle [EMAIL PROTECTED] writes: But you can't ever catch sigkill. There is no protection against sigkill. Isn't there a way to make sure the os kills the childprocess when the parrent dies? If the parent dies

Re: subprocess leaves child living

2007-06-05 Thread Thomas Dybdahl Ahle
Den Tue, 05 Jun 2007 15:46:39 -0500 skrev Michael Bentley: But actually *that* is an orphan process. When a parent process dies and the child continues to run, the child becomes an orphan and is adopted by init. Orphan processes can be cleaned up on most Unices with 'init q' (or something

Re: Compare regular expressions

2007-04-17 Thread Thomas Dybdahl Ahle
Den Mon, 16 Apr 2007 11:50:40 +0200 skrev Thomas Dybdahl Ahle: 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

Re: Compare regular expressions

2007-04-17 Thread Thomas Dybdahl Ahle
Den Tue, 17 Apr 2007 11:59:15 -0700 skrev Paddy: On Apr 17, 9:17 am, Diez B. Roggisch [EMAIL PROTECTED] wrote: Paddy schrieb: you could OR all the individual RE's test them all at once then find out which matched. big_re = |.join( r(?P__match_%i__%s) % (i, r) for i,r

Re: Binary file output using python

2007-04-17 Thread Thomas Dybdahl Ahle
Den Tue, 17 Apr 2007 11:07:38 -0700 skrev kyosohma: On Apr 17, 12:41 pm, Chi Yin Cheung [EMAIL PROTECTED] wrote: Hi, Is there a way in python to output binary files? I need to python to write out a stream of 5 million floating point numbers, separated by some separator, but it seems that all

Compare regular expressions

2007-04-16 Thread Thomas Dybdahl Ahle
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 have so. But ofcource there are

Re: Sending ECHO_REQUEST (pinging) with python

2007-03-26 Thread Thomas Dybdahl Ahle
Den Mon, 26 Mar 2007 11:24:34 +0200 skrev Michal 'vorner' Vaner: On Mon, Mar 26, 2007 at 08:30:16AM +0200, Thomas Dybdahl Ahle wrote: Do anybody know how to do this in python? You need root for that and the ping command is allowed to have them by suid bit. You can execute ping from inside

Re: Sending ECHO_REQUEST (pinging) with python

2007-03-26 Thread Thomas Dybdahl Ahle
Den Mon, 26 Mar 2007 06:30:04 -0500 skrev Nick Craig-Wood: Michael Bentley [EMAIL PROTECTED] wrote: On Mar 26, 2007, at 1:30 AM, Thomas Dybdahl Ahle wrote: It seems however that I have to be root to send those imcp packages, but I guess there must be a workaround since I can easily use

Kill thread or at least socket.getaddrinfo

2007-03-26 Thread Thomas Dybdahl Ahle
Hi, I'm writing an application that connects to the internet. Something like this: for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM): af, socktype, proto, canonname, sa = res try: self.sock = socket.socket(af, socktype, proto) Now if the user press the cancel

Sending ECHO_REQUEST (pinging) with python

2007-03-25 Thread Thomas Dybdahl Ahle
Hi, I've writing a python application in which I'd like to have a small ping label, to always tell the current ping time to the server. It seems however that I have to be root to send those imcp packages, but I guess there must be a workaround since I can easily use the ping command as

Exception passing

2007-03-23 Thread Thomas Dybdahl Ahle
Hi, I have a function, which looks like the following: connecting = False def func (): global connecting connecting = True try: # Do lot of network stuff except Exception, e: connecting = False raise e This works quite good, but it is a hell to debug.

Re: Exception passing

2007-03-23 Thread Thomas Dybdahl Ahle
Den Fri, 23 Mar 2007 07:38:47 -0700 skrev Alex Martelli: Thomas Dybdahl Ahle [EMAIL PROTECTED] wrote: This works quite good, but it is a hell to debug. Instead of getting a log message to the line which originally raised the exception. As you see, the traceback is maintained when you just

Re: Sort with extra variables

2007-03-03 Thread Thomas Dybdahl Ahle
Den Sat, 03 Mar 2007 11:26:08 +0100 skrev Diez B. Roggisch: Well, you'd have to define the function inside the sortMoves function, as it is where the variables exists. def sortMoves(board, table, ply, moves): def sortKey(move): return getMoveValue(board, table, ply, move)

Sort with extra variables

2007-03-02 Thread Thomas Dybdahl Ahle
I have a sort function in a python chess program. Currently it looks like this: def sortMoves (board, table, ply, moves): f = lambda move: getMoveValue (board, table, ply, move) moves.sort(key=f, reverse=True) return moves However I'd really like not to use the lambda, as it slows

Re: Sort with extra variables

2007-03-02 Thread Thomas Dybdahl Ahle
Den Fri, 02 Mar 2007 21:13:02 +0100 skrev Bjoern Schliessmann: Thomas Dybdahl Ahle wrote: However I'd really like not to use the lambda, as it slows down the code. Did you check how much the slowdown is? Yes, the lambda adds 50% -- http://mail.python.org/mailman/listinfo/python-list

Re: Sort with extra variables

2007-03-02 Thread Thomas Dybdahl Ahle
Den Fri, 02 Mar 2007 11:44:27 -0800 skrev Paul Rubin: Thomas Dybdahl Ahle [EMAIL PROTECTED] writes: Do you have any ideas how I can sort these moves the fastest? One idea: if you're using alpha-beta pruning, maybe you can use something like heapq instead of sorting, since a lot of the time

Re: Sort with extra variables

2007-03-02 Thread Thomas Dybdahl Ahle
Den Fri, 02 Mar 2007 20:33:45 +0100 skrev Diez B. Roggisch: Thomas Dybdahl Ahle schrieb: I have a sort function in a python chess program. Currently it looks like this: def sortMoves (board, table, ply, moves): f = lambda move: getMoveValue (board, table, ply, move) moves.sort(key

Re: Sort with extra variables

2007-03-02 Thread Thomas Dybdahl Ahle
Den Fri, 02 Mar 2007 15:20:33 -0800 skrev MonkeeSage: On Mar 2, 5:11 pm, Thomas Dybdahl Ahle [EMAIL PROTECTED] wrote: Wouldn't that be just as slow? Well, I'm not sure about speed, but with the lambda you're creating a new callable for f every time you call sortMoves. Intuitively

Re: classes and functions

2007-03-02 Thread Thomas Dybdahl Ahle
Den Fri, 02 Mar 2007 19:26:08 -0300 skrev Silver Rock: Friends, I don´t see why using classes.. functions does everything already. I read the Rossum tutotial and two other already. Maybe this is because I am only writing small scripts, or some more serious misunderstandings of the

Re: How *extract* data from XHTML Transitional web pages? got xml.dom.minidom troubles..

2007-03-02 Thread Thomas Dybdahl Ahle
Den Fri, 02 Mar 2007 15:32:58 -0800 skrev [EMAIL PROTECTED]: I'm trying to extract some data from an XHTML Transitional web page. xml.dom.minidom.parseString(text of web page) gives errors about it not being well formed XML. Do I just need to add something like ?xml ...? or what? As many

Re: Sort with extra variables

2007-03-02 Thread Thomas Dybdahl Ahle
Den Fri, 02 Mar 2007 16:27:47 -0800 skrev MonkeeSage: On Mar 2, 5:51 pm, Thomas Dybdahl Ahle [EMAIL PROTECTED] wrote: I guess the thing is that I'd have to create a new callable no matter how, as it is the only way to bring the extra variables into the getValue function when called by sort

Re: Sort with extra variables

2007-03-02 Thread Thomas Dybdahl Ahle
Den Fri, 02 Mar 2007 16:46:05 -0800 skrev Paul Rubin: Thomas Dybdahl Ahle [EMAIL PROTECTED] writes: Do you mean that I add my moves something like this? from heapq import heappush, heappop heap = [] for move in genAll(): heappush(heap, (-getMoveValue (board, table, ply, move), move

Re: Python daemon process

2006-08-29 Thread Thomas Dybdahl Ahle
when the parrentprocess is still running. I know this is called a daemon thread in java. 2006/8/26, Thomas Dybdahl Ahle [EMAIL PROTECTED]: Hi, I'm writing a program, using popen4(gnuchess), The problem is, that gnuchess keeps running after program exit. I know about the atexit module

Python daemon process

2006-08-26 Thread Thomas Dybdahl Ahle
Hi, I'm writing a program, using popen4(gnuchess), The problem is, that gnuchess keeps running after program exit. I know about the atexit module, but in java, you could make a process a daemon process, and it would only run as long as the real processes ran. I think this is a better way to stop

Re: Decrypt DES by password

2006-05-16 Thread Thomas Dybdahl Ahle
Den Mon, 15 May 2006 11:32:47 -0700. skrev Paul Rubin: Thomas Dybdahl Ahle [EMAIL PROTECTED] writes: byte[] array2 = bytes1.CryptDeriveKey(DES, MD5, 0, array1); Anybody know how to do this in python? I'm not aware of a standard that says how CryptDeriveKey is supposed to work. Or rather

Decrypt DES by password

2006-05-15 Thread Thomas Dybdahl Ahle
Hi, I've got some DES encrypted data, for which I know the password. The problem is that I have to generate an 8byte key from the password. I use python-crypto-2.0.1. I also know, that the C# way to do the decryption is: PasswordDeriveBytes bytes1 = new PasswordDeriveBytes(passwordString, null);

Re: Getting module location

2006-01-05 Thread Thomas Dybdahl Ahle
Den Thu, 05 Jan 2006 14:53:40 +0800. skrev limodou: 2006/1/5, Thomas Dybdahl Ahle [EMAIL PROTECTED]: Is it possible for an imported module to find its own location? you can access __file__(missing for built-in modules) or __path__(used for a package) attribute to find a module's location

Getting module location

2006-01-04 Thread Thomas Dybdahl Ahle
Is it possible for an imported module to find its own location? -- Programmers should realize their critical importance and responsibility in a world gone digital. They are in many ways similar to the priests and monks of Europe's Dark Ages; they are the only ones with the training and insight to

gdesklets __import__ problem

2006-01-03 Thread Thomas Dybdahl Ahle
Hi, I'm writing a gdesklets control, that dynamicly uses __import__ and getattr to get the right classes based on userinput. The problem is, that my control is somehow being run from somewhere unknown. This means that __import__ can't find the modules. I tried putting an