Re: Fortran (Was: The "does Python have variables?" debate)

2014-05-12 Thread Alain Ketterlin
Mark H Harris writes: > On 5/11/14 12:05 PM, Alain Ketterlin wrote: >>> Julia is Matlab and R, Python, Lisp, Scheme; all rolled together on >>> steroids. Its amazing as a dynamic language, and its fast, like >>> lightning fast as well as multiprocessing (parall

Re: Fortran

2014-05-13 Thread Alain Ketterlin
Mark H Harris writes: > On 5/12/14 3:44 AM, Alain Ketterlin wrote: >> When you are doing scientific computation, this overhead is >> unacceptable, because you'll have zillions of computations to perform. > > I'm still trying to sort that out. I have not teste

Re: Fortran

2014-05-14 Thread Alain Ketterlin
Marko Rauhamaa writes: > Alain Ketterlin : > >> The real nice thing that makes Julia a different language is the >> optional static typing, which the JIT can use to produce efficient code. >> It's the only meaningful difference with the current state of python.

Re: outputting time in microseconds or milliseconds

2013-08-04 Thread Alain Ketterlin
matt.doolittl...@gmail.com writes: >self.logfile.write('%s\t'%(str(time( [...] > 2013-08-0323:59:341375588774.89 [...] > Why is it only giving me the centisecond precision? the docs say i > should get microsecond precision with the code i put together. Because of str()'s defau

Re: Tail recursion to while iteration in 2 easy steps

2013-10-02 Thread Alain Ketterlin
Terry Reedy writes: > Part of the reason that Python does not do tail call optimization is > that turning tail recursion into while iteration is almost trivial, > once you know the secret of the two easy steps. Here it is. > > Assume that you have already done the work of turning a body recursive

Re: Tail recursion to while iteration in 2 easy steps

2013-10-02 Thread Alain Ketterlin
rusi writes: > On Wednesday, October 2, 2013 3:00:41 AM UTC+5:30, Terry Reedy wrote: >> Part of the reason that Python does not do tail call optimization is >> that turning tail recursion into while iteration is almost trivial, once >> you know the secret of the two easy steps. Here it is. > >

Re: Tail recursion to while iteration in 2 easy steps

2013-10-04 Thread Alain Ketterlin
Mark Janssen writes: > def fact(n): return 1 if n <= 1 else n * fact(n-1) >> class Strange: >> ... >> def __le__(dummy): >> global fact >> fact = someotherfun # this is "binding" >> return false >> You cannot prevent this in python. > No, but you can't prevent a lot of bad

Re: Tail recursion to while iteration in 2 easy steps

2013-10-07 Thread Alain Ketterlin
Terry Reedy writes: > On 10/4/2013 5:49 AM, Alain Ketterlin wrote: > >> I think allowing rebinding of function names is extremely strange, > > Steven already countered the 'is extremely strange' part by showing > that such rebinding is common, generally useful, an

Re: Tail recursion to while iteration in 2 easy steps

2013-10-08 Thread Alain Ketterlin
random...@fastmail.us writes: > On Mon, Oct 7, 2013, at 13:15, Alain Ketterlin wrote: >> That's fine. My point was: you can't at the same time have full >> dynamicity *and* procedural optimizations (like tail call opt). >> Everybody should be clear about the trad

Re: Tail recursion to while iteration in 2 easy steps

2013-10-08 Thread Alain Ketterlin
Antoon Pardon writes: > Op 07-10-13 19:15, Alain Ketterlin schreef: [...] >> That's fine. My point was: you can't at the same time have full >> dynamicity *and* procedural optimizations (like tail call opt). >> Everybody should be clear about the trade-off. >

Re: Basic Python Questions - Oct. 31, 2013

2013-10-31 Thread Alain Ketterlin
"E.D.G." writes: > The calculation speed question just involves relatively simple > math such as multiplications and divisions and trig calculations such > as sin and tan etc. These are not "simple" computations. Any compiled language (Fortran, C, C++, typically) will probably go much fas

Re: Basic Python Questions - Oct. 31, 2013

2013-10-31 Thread Alain Ketterlin
Chris Angelico writes: > On Fri, Nov 1, 2013 at 12:17 AM, Alain Ketterlin > wrote: >> "E.D.G." writes: >> >>> The calculation speed question just involves relatively simple >>> math such as multiplications and divisions and trig calculation

Re: Basic Python Questions - Oct. 31, 2013

2013-10-31 Thread Alain Ketterlin
Mark Lawrence writes: > On 31/10/2013 13:17, Alain Ketterlin wrote: >> "E.D.G." writes: >> >>>The calculation speed question just involves relatively simple >>> math such as multiplications and divisions and trig calculations such >>

Re: Best search algorithm to find condition within a range

2015-04-09 Thread Alain Ketterlin
Marko Rauhamaa writes: > Dave Angel : > >> So the C standard can specify such things as undefined. The >> architecture still will do something specific, right or wrong, and >> that's what Marko's claim was about. The C compiler has separate types >> for unsigned and for signed, while the underlyi

Re: Best search algorithm to find condition within a range

2015-04-09 Thread Alain Ketterlin
Marko Rauhamaa writes: > Alain Ketterlin : > >> No, it would not work for signed integers (i.e., with lo and hi of >> int64_t type), because overflow is undefined behavior for signed. > > All architectures I've ever had dealings with have used 2's-complement &g

Re: Best search algorithm to find condition within a range

2015-04-09 Thread Alain Ketterlin
Marko Rauhamaa writes: > The basic arithmetic algorithms are independent of the base. Right. > For example, here's how you can add two 128-bit integers in C using > 64-bit digits: > > typedef struct { > uint64_t lo, hi; > } uint128_t; > > uint128_t add128(uint128_t x, uint12

Re: Best search algorithm to find condition within a range

2015-04-09 Thread Alain Ketterlin
Chris Angelico writes: > On Thu, Apr 9, 2015 at 11:57 PM, Alain Ketterlin > wrote: >> Because, in: >> >> z = x+y; // all signed ints >> if ( z < x ) >> ... >> >> either there was no overflow (and the condition is false), or

Re: Am I missing something here? ipaddress vs socket

2015-05-01 Thread Alain Ketterlin
the.lo...@gmail.com writes: > Given the following code: > > import ipaddress > import socket > > ip = ipaddress.ip_address(mystring) > sock_family = ip. > socket = socket.socket(sock_family, socket.SOCK_STREAM) > > Am I crazy or is this undoable? > > sock.AF_INET == 2 > sock.AF_INET6 == 10 > i

Re: Throw the cat among the pigeons

2015-05-06 Thread Alain Ketterlin
Paul Rubin writes: > Steven D'Aprano writes: >> Multiplying upwards seems to be more expensive than multiplying >> downwards... I can only guess that it has something to do with the way >> multiplication is implemented, or perhaps the memory management >> involved, or something. Who the hell kno

Re: Throw the cat among the pigeons

2015-05-07 Thread Alain Ketterlin
Dave Angel writes: > On 05/06/2015 11:36 AM, Alain Ketterlin wrote: >> Yes, plus the time for memory allocation. Since the code uses "r *= >> ...", space is reallocated when the result doesn't fit. The new size is >> probably proportional to the current (in

Re: subprocess.Popen zombie

2015-05-20 Thread Alain Ketterlin
Robin Becker writes: > As part of a long running PyQT process running as a window app in Arch > linux I needed an alert sound, I decided to use the beep command and > the app code then looked like > > pid = Popen(['/home/robin/bin/mybeep', '-r3', '-f750', '-l100', '-d75']).pid > > the mybeep scri

Re: Using Python instead of Bash

2015-05-31 Thread Alain Ketterlin
Cecil Westerhof writes: > I help someone that has problems reading. For this I take photo's of > text, use convert from ImageMagick to make a good contrast (original > paper is grey) and use lpr to print it a little bigger. > import glob > import subprocess > > treshold = 66 > co

Re: fork/exec & close file descriptors

2015-06-02 Thread Alain Ketterlin
Skip Montanaro writes: > Reviving (and concluding) a thread I started a couple weeks ago, I asked: > >> The basic fork/exec dance is not a problem, but how do I discover >> all the open file descriptors in the new child process to make sure >> they get closed? Do I simply start at fd 3 and call o

Re: fork/exec & close file descriptors

2015-06-02 Thread Alain Ketterlin
Marko Rauhamaa writes: > Alain Ketterlin : > >> The close(2) manpage has the following warning on my Linux system: >> >> | Not checking the return value of close() is a common but >> | nevertheless serious programming error. It is quite possible that >> | err

Re: fork/exec & close file descriptors

2015-06-03 Thread Alain Ketterlin
Chris Angelico writes: > On Wed, Jun 3, 2015 at 7:06 AM, Alain Ketterlin > wrote: >> I've no idea what the OP's program was doing, so I'm not going to split >> hairs. I can't imagine why one would like to mass-close an arbitrary set >> of file desc

Re: fork/exec & close file descriptors

2015-06-03 Thread Alain Ketterlin
Marko Rauhamaa writes: > Alain Ketterlin : > >> Marko Rauhamaa writes: >>> First, if close() fails, what's a poor program to do? >> >> Warn the user? Not assume everything went well? It all depends on the >> application, and what the file descripto

Re: fork/exec & close file descriptors

2015-06-03 Thread Alain Ketterlin
random...@fastmail.us writes: > On Wed, Jun 3, 2015, at 03:11, Alain Ketterlin wrote: >> Thank you, I know this. What I mean is: what are the reasons that you >> cannot access your file descriptors one by one? To me closing a range of >> descriptors has absolutely no me

Re: Can Python function return multiple data?

2015-06-04 Thread Alain Ketterlin
Steven D'Aprano writes: [...] > But you still find a few people here and there who have been exposed to Java > foolishness, and will argue that Python is "pass by value, where the value > is an implementation dependent reference to the thing that you thought was > the value". I find this clear a

Re: Can Python function return multiple data?

2015-06-05 Thread Alain Ketterlin
Steven D'Aprano writes: > On Fri, 5 Jun 2015 04:17 am, Alain Ketterlin wrote: > >> Steven D'Aprano writes: >> >> [...] >>> But you still find a few people here and there who have been exposed to >>> Java foolishness, and will argue that

Re: Can Python function return multiple data?

2015-06-05 Thread Alain Ketterlin
Grant Edwards writes: [...] > Or to be a bit obtuse: Python parameters are passed by value, but all > values are references. Exactly, that's a perfect description. There's is no need for a new name. As a corollary, all names (including "variables" and object attributes) are references. -- Alain

Re: Can Python function return multiple data?

2015-06-05 Thread Alain Ketterlin
Marko Rauhamaa writes: > Alain Ketterlin : > >> Grant Edwards writes: >> >> [...] >>> Or to be a bit obtuse: Python parameters are passed by value, but all >>> values are references. >> >> Exactly, that's a perfect description. Ther

Re: A new module for performing tail-call elimination

2015-07-16 Thread Alain Ketterlin
Antoon Pardon writes: > On 07/13/2015 05:44 PM, Th. Baruchel wrote: >> Hi, after having spent much time thinking about tail-call elimination >> in Python (see for instance http://baruchel.github.io/blog/ ), I finally >> decided to write a module for that. You may find it at: >> >> https://githu

Re: OT: This Swift thing

2014-06-05 Thread Alain Ketterlin
Sturla Molden writes: > Dear Apple, > > Why should I be exited about an illegitmate child of Python, Go and > JavaScript? [...] Type safety. (And with it comes better performance ---read battery life--- and better static analysis tools, etc.) LLVM (an Apple-managed project) for the middle- and b

Re: OT: This Swift thing

2014-06-05 Thread Alain Ketterlin
Chris Angelico writes: > On Thu, Jun 5, 2014 at 6:14 PM, Alain Ketterlin > wrote: >> Swift's memory management is similar to python's (ref. counting). Which >> makes me think that a subset of python with the same type safety would >> be an instant success.

Re: OT: This Swift thing

2014-06-05 Thread Alain Ketterlin
Sturla Molden writes: > On 05/06/14 10:14, Alain Ketterlin wrote: > >> Type safety. > > Perhaps. Python has strong type safety. Come on. [...] >>(And with it comes better performance ---read battery >> life--- and better static analysis tools, etc.) > > Pe

Re: OT: This Swift thing

2014-06-05 Thread Alain Ketterlin
Chris Angelico writes: > On Thu, Jun 5, 2014 at 7:42 PM, Alain Ketterlin > wrote: >> Chris Angelico writes: >> >>> On Thu, Jun 5, 2014 at 6:14 PM, Alain Ketterlin >>> wrote: >>>> Swift's memory management is similar to python's (

Re: OT: This Swift thing

2014-06-05 Thread Alain Ketterlin
Chris Angelico writes: > On Fri, Jun 6, 2014 at 6:07 AM, Alain Ketterlin > wrote: >>> Perhaps, perhaps not. My experience is that only a small percentage of >>> the CPU time is spent in the Python interpreter. >> >> Basically, you're saying that a major

Re: OT: This Swift thing

2014-06-06 Thread Alain Ketterlin
Travis Griggs writes: >> On Jun 5, 2014, at 1:14, Alain Ketterlin wrote: >> >> Swift's memory management is similar to python's (ref. counting). Which >> makes me think that a subset of python with the same type safety would >> be an instant success.

Re: OT: This Swift thing

2014-06-06 Thread Alain Ketterlin
Terry Reedy writes: > On 6/5/2014 4:07 PM, Alain Ketterlin wrote: > >>> When I compile Cython modules I use LLVM on this computer. >> >> Cython is not Python, it is another language, with an incompatible >> syntax. > > Cython compiles Python with optional e

Re: OT: This Swift thing

2014-06-06 Thread Alain Ketterlin
Sturla Molden writes: > Alain Ketterlin wrote: > >> Many of these students suggest Python as the >> development language (they learned it and liked it), and the suggestion >> is (almost) always rejected, in favor of Java or C# or C/C++. > > And it was almost a

Re: OT: This Swift thing

2014-06-06 Thread Alain Ketterlin
Chris Angelico writes: > On Fri, Jun 6, 2014 at 7:23 AM, Mark Lawrence wrote: >> On 05/06/2014 21:07, Alain Ketterlin wrote: >>> >>> Sturla Molden writes: >>> >>>> On 05/06/14 10:14, Alain Ketterlin wrote: >>>> >>>>>

Re: OT: This Swift thing

2014-06-06 Thread Alain Ketterlin
Sturla Molden writes: > On 05/06/14 22:27, Alain Ketterlin wrote: >> I have seen dozens of projects where Python was dismissed because of the >> lack of static typing, and the lack of static analysis tools. [...] > When is static analysis actually needed and for what purpose?

Re: OT: This Swift thing

2014-06-07 Thread Alain Ketterlin
Sturla Molden writes: > Alain Ketterlin wrote: >> Sturla Molden writes: >> >>> Alain Ketterlin wrote: >>> >>>> Many of these students suggest Python as the >>>> development language (they learned it and liked it), and the suggestio

Re: OT: This Swift thing

2014-06-07 Thread Alain Ketterlin
Mark Lawrence writes: > On 07/06/2014 09:20, Alain Ketterlin wrote: >> Sturla Molden writes: >>>>>> Many of these students suggest Python as the >>>>>> development language (they learned it and liked it), and the suggestion >>>>>

Re: your mail

2014-10-18 Thread Alain Ketterlin
Terry Reedy writes: > On 10/17/2014 6:43 AM, Cameron Simpson wrote: >> On 17Oct2014 11:45, Dhananjay wrote: > >>> 2.1576318858 -1.8651195165 4.2333428278 >>> ... >>> (total of 200 lines) >>> >>> Columns 1,2,3 corresponds to x,y,z axis data points. > >>for line in open('flooding-psiphi.dat','

Re: Python without a tty

2011-09-29 Thread Alain Ketterlin
Steven D'Aprano writes: > I have a Python script which I would like to test without a tty attached > to the process. I could run it as a cron job, but is there an easier way? > > I am running Linux. Isn't os.setsid() what you're looking for? It makes the calling process have no controlling term

Re: Python without a tty

2011-09-29 Thread Alain Ketterlin
Steven D'Aprano writes: > Alain Ketterlin wrote: >>> I have a Python script which I would like to test without a tty attached >>> to the process. I could run it as a cron job, but is there an easier way? >> Isn't os.setsid() what you're looki

Re: Usefulness of the "not in" operator

2011-10-08 Thread Alain Ketterlin
candide writes: > Python provides > > -- the not operator, meaning logical negation > -- the in operator, meaning membership > > On the other hand, Python provides the not in operator meaning > non-membership. However, it seems we can reformulate any "not in" > expression using only "not"

Re: Usefulness of the "not in" operator

2011-10-10 Thread Alain Ketterlin
Alec Taylor writes: > On Sun, Oct 9, 2011 at 3:08 AM, Steven D'Aprano > wrote: >> def true(x, y): >>    return x >> >> def false(x, y): >>    return y [...] >> def Nand(a, b): >>    return (lambda c: lambda x, y: c(y, x))(a(b, a)) >> >> and we're done. [...] > Awesome Yes, that's how Church d

Re: xml tree writing with ElementTree; prepends elements with ns0

2011-10-11 Thread Alain Ketterlin
"Alex van der Spek" writes: > When reading a tree and writing it back to a new file all the elements are > prepended with the string ns0: That's a namespace prefix. > > Why is it prepended and how can I suppress this? See http://effbot.org/zone/element-namespaces.htm I'm not sure you can def

Re: xml tree writing with ElementTree; prepends elements with ns0

2011-10-11 Thread Alain Ketterlin
Alain Ketterlin writes: > "Alex van der Spek" writes: > >> When reading a tree and writing it back to a new file all the elements are >> prepended with the string ns0: > > That's a namespace prefix. > >> >> Why is it prepended and how can I

Re: Opportunity missed by Python ?

2011-10-13 Thread Alain Ketterlin
Chris Angelico writes: > On Thu, Oct 13, 2011 at 8:45 PM, candide wrote: >> Dart is the very new language created by Google to replace Javascript. >> So Python was not able to do the job? Or may be they don't know about Python >> at Google ;) ? > > Python, as I found out to my detriment, is prac

Re: Python as a replacement to PL/SQL

2011-10-24 Thread Alain Ketterlin
Alec Taylor writes: > Is there a set of libraries for python which can be used as a complete > replacement to PL/SQL? This doesn't make much sense: PL/SQL lets you write server-side code, i.e., executed by the DBMS. Oracle can't execute python code directly, so python can only be used on the cli

Re: Question about 'iterable cursors'

2011-11-06 Thread Alain Ketterlin
"Frank Millman" writes: > I am using a few DB_API adaptors - ceODBC for Sql Server, psycopg2 for > PostgreSQL, and sqlite3 for sqlite3. > > They all offer the feature that if a cursor executes a SELECT, the > cursor returns an iterator which can be used to fetch one row at a > time. I have been u

Re: Random and fork

2013-02-06 Thread Alain Ketterlin
Julien Le Goff writes: > Today I came accross a behaviour I did not expect in python (I am > using 2.7). In my program, random.random() always seemed to return the > same number; it turned out to be related to the fact that I was using > os.fork. The random number generator is initialized once,

Re: Monitoring updating directory for image for GUI

2013-02-07 Thread Alain Ketterlin
ciscorucin...@gmail.com writes: > Basically I am creating a program that will stream musical notes into > a program called Lilypond one-by-one and it will create the sheet > music for that stream of music via OS command. Your understanding of > Lilypond is not needed, but you need to know that for

Re: Doing both regex match and assignment within a If loop?

2013-03-29 Thread Alain Ketterlin
Victor Hooi writes: > expression1 = re.compile(r'') > expression2 = re.compile(r'') [...] Just a quick remark: regular expressions are pretty powerful at representing alternatives. You could just stick everything inside a single re, as in '...|...' Then use the returned match to

Re: subprocess question re waiting

2013-04-08 Thread Alain Ketterlin
loial writes: > I want to call a child process to run a shell script and wait for that > script to finish. Will the code below wait for the script to finish? > If not then how do I make it wait? [...] > process = subprocess.Popen(command, > stdin=subprocess.PIPE,stdout=subprocess.PIPE, stderr=su

Re: python simply not scaleable enough for google?

2009-11-11 Thread Alain Ketterlin
Terry Reedy writes: > I can imagine a day when code compiled from Python is routinely > time-competitive with hand-written C. Have a look at http://code.google.com/p/unladen-swallow/downloads/detail?name=Unladen_Swallow_PyCon.pdf&can=2&q= Slide 6 is impressive. The bottom of slide/page 22 expla

Re: Repost: Read a running process output

2010-02-05 Thread Alain Ketterlin
Ashok Prabhu writes: > from subprocess import * > p1=Popen('/usr/sunvts/bin/64/vtsk -d',stdout=PIPE,shell=True) Use Popen(['/usr/...','-d'],stdout=PIPE), i.e., no shell. -- Alain. -- http://mail.python.org/mailman/listinfo/python-list

Re: Repost: Read a running process output

2010-02-05 Thread Alain Ketterlin
Ashok Prabhu writes: >> > p1=Popen('/usr/sunvts/bin/64/vtsk -d',stdout=PIPE,shell=True) >> >> Use Popen(['/usr/...','-d'],stdout=PIPE), i.e., no shell. >> >> -- Alain. > Thanks for the response. However it throws an error. Please find > below. > from subprocess import * p1=Popen('/usr/

Re: Large regular expressions

2010-03-15 Thread Alain Ketterlin
Nathan Harmston writes: [...] > Could anyone suggest other methods of these kind of string matching in > Python? I m trying to see if my swigged alphabet trie is faster than > whats possible in Python! Since you mention using a trie, I guess it's just a big alternative of fixed strings. You may

Re: GIF89A and PIL

2010-03-27 Thread Alain Ketterlin
Stephen Hansen writes: > Is it possible to get PIL to save GIF's in GIF89A format, instead of > GIF87A? GIF89 was patented. I guess that is why it isn't used by PIL. (The patent has expired now, IIRC.) Anyway, PNG was supposed to replace GIF. > If not, are there any decent other image libraries

Incorrect scope of list comprehension variables

2010-04-03 Thread Alain Ketterlin
Hi all, I've just spent a few hours debugging code similar to this: d = dict() for r in [1,2,3]: d[r] = [r for r in [4,5,6]] print d THe problem is that the "r" in d[r] somehow captures the value of the "r" in the list comprehension, and somehow kills the loop interator. The (unexpected) re

Re: SQLite3 and lastrowid

2010-11-19 Thread Alain Ketterlin
Alexander Gattin writes: >> The proper way to get the number of rows is to >> use the COUNT aggregate function, e.g., "SELECT >> COUNT(*) FROM TABLE1", which will return a >> single row with a single column containing the >> number of rows in table1. > > It's better to select count(1) instead of

Re: SQLite3 and lastrowid

2010-11-19 Thread Alain Ketterlin
Alexander Gattin writes: > On Fri, Nov 19, 2010 at 12:32:19PM +0100, Alain > Ketterlin wrote: >> Alexander Gattin writes: >> > It's better to select count(1) instead of >> > count(*). The latter may skip rows consisting >> > entirely of NULLs IIR

Re: PIL how to enlarge image

2010-12-04 Thread Alain Ketterlin
robos85 writes: > Hi, I try to enlarge original image. > I have image in size: 100x100 and I want to make it 120x120. > But resize() doesn't make it bigger. Is there any method for that? You have to use i.transform() -- Alain. -- http://mail.python.org/mailman/listinfo/python-list

Re: simple threading.Thread and Semaphores hang

2010-12-06 Thread Alain Ketterlin
lnenov writes: > My application hangs on exit. > I have isoleted this piece of code that reproduces the error: (the > time module is extra and not needed to reproduce) > > import threading > import time > > def func(): > b = threading.Semaphore(value=0) > b.acquire() This waits for the s

Re: Newbie needs regex help

2010-12-06 Thread Alain Ketterlin
Dan M writes: > I took at look at http://docs.python.org/howto/regex.html, especially the > section titled "The Backslash Plague". I started out trying : import re r = re.compile('x([0-9a-fA-F]{2})') a = "This \xef file \xef has \x20 a bunch \xa0 of \xb0 crap \xc0 The backs

Re: How to populate all possible hierarchical clusterings from a set of elements?

2011-01-13 Thread Alain Ketterlin
justin writes: > Suppose I have [1,2,3,4,5], then there are many ways of making > clustering. > Among them, I want to pair up terminals until there is only one left > at the end. Are you trying "ascending hierarchical clustering" by any chance? In that case you're supposed to use some kind of di

Re: How to populate all possible hierarchical clusterings from a set of elements?

2011-01-13 Thread Alain Ketterlin
DevPlayer writes: > def maketup(lst): > > if len(lst) == 1: > return lst[0] > > elif len(lst) == 2: > return (lst[0],lst[1]) > > elif len(lst) > 2: > return ( (maketup(lst[:-2]), lst[-2]), lst[-1]) The OP wants all binary trees over the elements, not just one.

Re: How to populate all possible hierarchical clusterings from a set of elements?

2011-01-13 Thread Alain Ketterlin
Richard Thomas writes: > On Jan 13, 10:02 am, Alain Ketterlin >> def clusterings(l): >>     if len(l) == 1: >>         print repr(l) >>     else: >>         n = len(l) >>         for i in xrange(n): >>             for j in xrange(i+1,n): >&g

Re: Perl Hacker, Python Initiate

2011-02-02 Thread Alain Ketterlin
Gary Chambers writes: > Given the following Perl script: [41 lines of Perl removed] Sorry, I'm lucky enough to be able to completely ignore Perl. > Will someone please provide some insight on how to accomplish that task in > Python? >From what I understood in the comments of your script, here

Re: Incorrect scope of list comprehension variables

2010-04-06 Thread Alain Ketterlin
Alain Ketterlin writes: > d = dict() > for r in [1,2,3]: > d[r] = [r for r in [4,5,6]] > print d Thanks to Chris and Paul for the details (the list comp. r actually leaks). I should have found this by myself. My background is more on functional programming languages, that

Re: Incorrect scope of list comprehension variables

2010-04-06 Thread Alain Ketterlin
Steven D'Aprano writes: >> d = dict() >> for r in [1,2,3]: >> d[r] = [r for r in [4,5,6]] >> print d > > This isn't directly relevant to your problem, but why use a list > comprehension in the first place? [r for r in [4,5,6]] is just [4,5,6], > only slower. Sure. But I've actually spent s

Re: Incorrect scope of list comprehension variables

2010-04-17 Thread Alain Ketterlin
Steven D'Aprano writes: > On Fri, 16 Apr 2010 08:48:03 -0700, Aahz wrote: > >>>Nevertheless, it is a common intuition that the list comp variable >>>should *not* be exposed outside of the list comp, and that the for-loop >>>variable should. Perhaps it makes no sense, but it is very common -- >>>I

Re: Incorrect scope of list comprehension variables

2010-04-17 Thread Alain Ketterlin
Steven D'Aprano writes: > On Sat, 17 Apr 2010 12:05:03 +0200, Alain Ketterlin wrote: > >>> I don't know of any language that creates a new scope for loop >>> variables, but perhaps that's just my ignorance... >> >> I think Pascal and

Re: Kindly show me a better way to do it

2010-05-08 Thread Alain Ketterlin
Oltmans writes: > a = [ [1,2,3,4], [5,6,7,8] ] > > Currently, I'm iterating through it like > > for i in [k for k in a]: > for a in i: > print a I would prefer: for i in a: for v in i: print v i.e., not messing with a and avoiding an additional list. > but I wa

Re: solve a newspaper quiz

2010-05-09 Thread Alain Ketterlin
superpollo writes: > "if a b c are digits, solve ab:c=a*c+b" > > solved in one minute with no thought: Obviously. > for a in range(10): > for b in range(10): > for c in range(10): > try: > if (10.*a+b)/c==a*c+b: > print "%i%i:%i=%i*%i+

Re: if, continuation and indentation

2010-05-27 Thread Alain Ketterlin
HH writes: > if (width == 0 and > height == 0 and > color == 'red' and > emphasis == 'strong' or > highlight > 100): > raise ValueError("sorry, you lose") I prefer to see the "and" at the beginning of continuation lines, and usually group related items

Re: map is useless!

2010-06-06 Thread Alain Ketterlin
rantingrick writes: > Python map is just completely useless. [...] import time def test1(): > l = range(1) > t1 = time.time() > map(lambda x:x+1, l) > t2= time.time() > print t2-t1 def test2(): > l = range(1) > t1 = time.time() >

Re: a +b ?

2010-06-11 Thread Alain Ketterlin
yanhua writes: > it's a simple question: > input two integers A and B in a line,output A+B? > > this is my program: > s = input() input() is probably not what you think it is. Check raw_input instead. > t = s.split() > a = int(t[0]) > b = int(t[1]) > print(a+b) > > but i think it's too complex,

Re: pythonize this!

2010-06-15 Thread Alain Ketterlin
superpollo writes: > goal (from e.c.m.): evaluate > 1^2+2^2+3^2-4^2-5^2+6^2+7^2+8^2-9^2-10^2+...-2010^2, where each three > consecutive + must be followed by two - (^ meaning ** in this context) > > my solution: > s = 0 for i in range(1, 2011): > ... s += i**2 > ... if not (i+1)

Re: Normalizing A Vector

2010-07-30 Thread Alain Ketterlin
Lawrence D'Oliveiro writes: > Say a vector V is a tuple of 3 numbers, not all zero. You want to normalize > it (scale all components by the same factor) so its magnitude is 1. > > The usual way is something like this: > > L = math.sqrt(V[0] * V[0] + V[1] * V[1] + V[2] * V[2]) > V = (V[0]

Re: Normalizing A Vector

2010-07-31 Thread Alain Ketterlin
Lawrence D'Oliveiro writes: >>> What I don’t like is having that intermediate variable L leftover after >>> the computation. >> >> Well, it also guarantees that the square root is computed once. > > OK, this version should solve that problem, without requiring any new > language features: > >

Re: Normalizing A Vector

2010-08-01 Thread Alain Ketterlin
Lawrence D'Oliveiro writes: >>> V = tuple \ >>> ( >>> x >>> / >>> l >>>for x in V >>>for l in >>>(math.sqrt(reduce(lambda a, b : a + b, (y * y for y in V), >>>0)),) >>> ) >> >> You got the order wrong (it has

Re: Normalizing A Vector

2010-08-02 Thread Alain Ketterlin
"Bartc" writes: >> def norm(V): >>L = math.sqrt( sum( [x**2 for x in V] ) ) >>return [ x/L for x in V ] > > There's a cost involved in using those fancy constructions. Sure. The above has three loops that take some time. > I found the following to be about twice as fast, when vectors ar

Re: path to data files

2010-08-19 Thread Alain Ketterlin
Daniel Fetchinson writes: > If a python module requires a data file to run how would I reference > this data file in the source in a way that does not depend on whether > the module is installed system-wide, installed in $HOME/.local or is > just placed in a directory from where the interpreter i

Re: Fibonacci: How to think recursively

2010-08-29 Thread Alain Ketterlin
Baba writes: > Level: beginner > > I would like to know how to approach the following Fibonacci problem: > How may rabbits do i have after n months? > > I'm not looking for the code as i could Google that very easily. I'm > looking for a hint to put me on the right track to solve this myself > wi

Re: Fibonacci: returning a selection of the series

2010-08-29 Thread Alain Ketterlin
Baba writes: > i would like to return a selection of the Fibonacci series. > example: > start = 5 ; end = 55 > the function should then return [5, 8, 13, 21, 34, 55] [...] > my questios: > - would you agree that recursive is not ideal for generating a list? > (in this particular case and in gene

Re: Speed-up for loops

2010-09-08 Thread Alain Ketterlin
Steven D'Aprano writes: >> With Python 3 and def f(x): return x+1, unrolling this loop 4x improved >> speed by 15%; 4.00 minutes reduces to 3.30 minutes. > I'm afraid that I can't replicate those figures. In my test, unrolling > the loop causes a massive SLOWDOWN of 37%, not a speed up. Here is

Re: analysis of algoritms

2010-09-09 Thread Alain Ketterlin
Baba writes: > In below code "the outer loop test in step 4 will execute ( n + 1 ) > times (note that an extra step is required to terminate the for loop, > hence n + 1 and not n executions), which will consume T4( n + 1 ) > time." (from http://en.wikipedia.org/wiki/Analysis_of_algorithms) > > 1

Re: how to kill a subprocess

2010-09-09 Thread Alain Ketterlin
cerr writes: > I'm calling a python script from a php script which again calls a perl > script with subprocess.popen(). > This seems to work fine so far only that once the python script > completed it is becoming a zombie because the perl script in the > background is still running... so before i

Re: how to kill a subprocess

2010-09-09 Thread Alain Ketterlin
cerr writes: >> x.terminate() (and then x.wait()) where x is the value returned by >> subprocess.Popen(). > Well, this is what I have: > > writelog("starting GPS simulator") > commandlist=[GPSsim,proto,GPSfile] > writelog(commandlist[0]+" "+commandlist[1]+" "+commandlist[2]) > process=sub

Re: reading multiple files

2010-09-09 Thread Alain Ketterlin
Mag Gam writes: > I have 3 files which are constantly being updated therefore I use tail > -f /var/log/file1, tail -f /var/log/file2, and tail -f /var/log/file3 > > For 1 file I am able to manage by > tail -f /var/log/file1 | python prog.py > > prog.py looks like this: > f=sys.stdin > for line in

Re: memory management - avoid swapping/paging

2010-10-21 Thread Alain Ketterlin
Jon Clements writes: > Is there a cross-platform way using Python to guarantee that an object > will never be swapped/paged to disk? I'll be honest and say I'm really > not sure if this is a particular language question or rather specific > to an OS. > > Under linux it appears I could create a r

Re: Land Of Lisp is out

2010-10-28 Thread Alain Ketterlin
Lawrence D'Oliveiro writes: >>> Would it be right to say that the only Lisp still in common use is the >>> Elisp built into Emacs? >> >> There is a new version of Lisp called Clojure that runs on the Java >> Virtual Machine (JVM) that is on the upswing. > > Now is not exactly a good time to buil

Re: openmp do loops

2010-11-04 Thread Alain Ketterlin
Stefan Behnel writes: >> !$OMP PARALLEL DO default(private) shared(hkltable, fcalctable,hklsize) >> do i=1,hklsize >> fcalctable(i)=structfact(hkltable(1,i),hkltable(2,i),hkltable(3,i)) >> end do >> !$OMP END PARALLEL DO (This is Fortan, BTW.) > Seeing this makes me seriously happy that I can w

Re: Popen Question

2010-11-04 Thread Alain Ketterlin
moogyd writes: import os, subprocess os.environ['MYVAR'] = "myval" p = subprocess.Popen(['echo', '$MYVAR'],shell=True) p = subprocess.Popen(['echo', '$MYVAR']) $MYVAR > p = subprocess.Popen('echo $MYVAR',shell=True) myval > p = subprocess.Popen('echo $

Re: Compare source code

2010-11-05 Thread Alain Ketterlin
Terry Reedy writes: > If you add the normally redundant information in the form of explicit > dedents (anything starting with '#' and distinguishable from normal > comments), then it is not too hard to re-indent even after all indents > have been removed. I actually use such a trick in emacs, no

<    1   2   3   >