Re: __file__ access extremely slow

2009-06-06 Thread Zac Burns
I think I have figured this out, thanks for your input.

The time comes from lazy modules related to e-mail importing on
attribute access, which is acceptable. Hence of course
why ImportError was sometime raised.

I originally was thinking that accessing __file__ was triggering some
mechanism that caused an attempt at importing other modules, but the
lazy import explanation makes much more sense.

--
Zachary Burns
(407)590-4814
Aim - Zac256FL
Production Engineer (Digital Overlord)
Zindagi Games



On Fri, Jun 5, 2009 at 2:15 AM, Gabriel Genellina wrote:
> En Fri, 05 Jun 2009 00:12:25 -0300, John Machin 
> escribió:
>
>>> > (2) This will stop processing on the first object in sys.modules that
>>> > doesn't have a __file__ attribute. Since these objects aren't
>>> > *guaranteed* to be modules,
>>
>> Definitely not guaranteed to be modules. Python itself drops non-modules
>> in
>> there! Python 2.3 introduced four keys mapped to None -- one of these was
>> dropped in 2.4, but the other three are still there in 2.5 and 2.6:
>
> In case someone wonders what all those None are: they're a "flag" telling
> the import machinery that those modules don't exist (to avoid doing a
> directory scan over and over, because Python<2.7 attempts first to do a
> relative import, and only if unsuccessful attempts an absolute one)
>
>> C:\junk>\python23\python -c "import sys; print [k for (k, v) in
>> sys.modules.items() if v is None]"
>> ['encodings.encodings', 'encodings.codecs', 'encodings.exceptions',
>> 'encodings.types']
>
> In this case, somewhere inside the encodings package, there are statements
> like "import types" or "from types import ...", and Python could not find
> types.py in the package directory.
>
> --
> Gabriel Genellina
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Error in linalg.inv ??

2009-06-06 Thread John Machin
On Jun 6, 3:34 pm, Ajith Kumar  wrote:
> Hello,
>  I ran the following code (Using Debian 5.0)
>
> from numpy import *
> a = arange(1.,10.)
> b = reshape(a, [3,3])
> c = linalg.inv(b)
> print b
> print c
> print dot(b,c)
> print dot(c,b)
>
> And the result is
>
> [[ 1.  2.  3.]
>  [ 4.  5.  6.]
>  [ 7.  8.  9.]]
>
> [[  3.15221191e+15  -6.30442381e+15   3.15221191e+15]
>  [ -6.30442381e+15   1.26088476e+16  -6.30442381e+15]
>  [  3.15221191e+15  -6.30442381e+15   3.15221191e+15]]
>
> [[-0.5 -1.  -1. ]
>  [-1.  -2.   2. ]
>  [-1.5 -3.   1. ]]
>
> [[  5.5   8.   10.5]
>  [  3.    0.   -3. ]
>  [ -1.    0.   -3. ]]
>
> NOT the identity matrix. Any help ?

It's a longer time than I care to divulge since I took courses in
matrix algebra, but I do have a vague recollection that if determinant
(B) is zero, inverse(B) is not defined ... seeing the rows and columns
in B are linear (as are those of C), IIRC that means the determinants
are zero, and you are out of luck.

Are you ignoring exceptions? Is that _exactly_ what you typed in?
Try running it again, print the calculated determinants of B and C,
and tell what version of (a) numpy (b) Python you are using.

Isn't there a mailing list for numpy?

HTH,
John
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Error in linalg.inv ??

2009-06-06 Thread Nick Craig-Wood
Ajith Kumar  wrote:
>   I ran the following code (Using Debian 5.0)
> 
>  from numpy import *
>  a = arange(1.,10.)
>  b = reshape(a, [3,3])
>  c = linalg.inv(b)
>  print b
>  print c
>  print dot(b,c)
>  print dot(c,b)
> 
>  And the result is
> 
>  [[ 1.  2.  3.]
>   [ 4.  5.  6.]
>   [ 7.  8.  9.]]
> 
>  [[  3.15221191e+15  -6.30442381e+15   3.15221191e+15]
>   [ -6.30442381e+15   1.26088476e+16  -6.30442381e+15]
>   [  3.15221191e+15  -6.30442381e+15   3.15221191e+15]]
> 
>  [[-0.5 -1.  -1. ]
>   [-1.  -2.   2. ]
>   [-1.5 -3.   1. ]]
> 
>  [[  5.5   8.   10.5]
>   [  3.0.   -3. ]
>   [ -1.0.   -3. ]]
> 
>  NOT the identity matrix. Any help ?

The matrix you are trying to invert is singular (can't be inverted),
ie its determinant is zero.

>> a = arange(1.,10.)
>>> b = reshape(a, [3,3])
>>> linalg.det(b)
-9.5171266700777579e-16
>>>

Which is zero but with a bit of rounding errors which I guess numpy
doesn't notice.

Double checking like this

>>> a,b,c,d,e,f,g,h,i=range(1,10)
>>> a*e*i - a*f*h - b*d*i + b*f*g + c*d*h - c*e*g
0
>>>

So I guess it is a bug that numpy didn't throw

numpy.linalg.linalg.LinAlgError("Singular matrix")

Like it does normally

-- 
Nick Craig-Wood  -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: urlretrieve() failing on me

2009-06-06 Thread Peter Otten
Robert Dailey wrote:

>> Well I did not post the code because it is fairly complex and its hard
>> to give you the whole picture without giving you too much code. But
>> here you go, you get what you ask for:
>>
>> def Download( self ):
>> PrintSubStatus( 'Downloading...' )
>> destination = normalize( '{0}/{1}'.format( self._info.outdir,
>> self._info.file_ext ) )
>> print( self._info.url )
>> print( destination )
>> urlretrieve( self._info.url, destination )
>>
>> Both print statements are shown as
>> 
below:http://easynews.dl.sourceforge.net/sourceforge/wxwindows/mxMSW-2.8.10...
>> D:\IT\personal\haresvn\temp\mxMSW-2.8.10.zip
>>
>> I really can't figure out why this isn't working.
> 
> Wow how stupid... I was using:
> 
> mxMSW-2.8.10.zip
> 
> There is an "m" at the front, and it needs to be "w".

Time and again posting the code does help ;)
 
> wxMSW-2.8.10.zip
> 
> This URL isn't even valid, can't believe I didn't get an exception!

Sourceforge is (un)helpfully redirecting your request and Python is 
(un)helpfully following. I looks like you can avoid this by using a 
URLopener instead of the FancyURLopener implicitly used by urlretrieve():

>>> 
URLopener().retrieve("http://easynews.dl.sourceforge.net/sourceforge/wxwindows/mxMSW-2.8.10.zip";,
 
filename="tmp.zip")
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python3.0/urllib/request.py", line 1476, in retrieve
fp = self.open(url, data)
  File "/usr/lib/python3.0/urllib/request.py", line 1444, in open
return getattr(self, name)(url)
  File "/usr/lib/python3.0/urllib/request.py", line 1622, in open_http
return self._open_generic_http(http.client.HTTPConnection, url, data)
  File "/usr/lib/python3.0/urllib/request.py", line 1618, in 
_open_generic_http
response.status, response.reason, response.msg, data)
  File "/usr/lib/python3.0/urllib/request.py", line 1638, in http_error
return self.http_error_default(url, fp, errcode, errmsg, headers)
  File "/usr/lib/python3.0/urllib/request.py", line 1644, in 
http_error_default
raise HTTPError(url, errcode, errmsg, headers, None)
urllib.error.HTTPError: HTTP Error 302: Found

Peter

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Way to use proxies & login to site?

2009-06-06 Thread Kushal Kumaran
On Fri, Jun 5, 2009 at 10:32 PM, inVINCable  wrote:
> On May 5, 12:51 pm, Kushal Kumaran  wrote:
>> On Wed, Apr 29, 2009 at 8:21 AM, inVINCable  wrote:
>> > On Apr 27, 7:40 pm, inVINCable  wrote:
>> >> Hello,
>>
>> >> I have been using ClientForm to log in to sites & ClientCookie so I
>> >> can automatically log into my site to do some penetration testing,
>> >> although, I cannot figure out a solution to use proxies with this
>> >> logging in automatically. Does anyone have any solutions?
>>
>> >> Thanks :)
>>
>> >> Vince
>>
>> > Any ideas?
>>
>> If, like the example athttp://wwwsearch.sourceforge.net/ClientForm/,
>> you are using urllib2, you can read the documentation for that module.
>>  It also has examples for working with proxies.
>>
>
> Ok, I gotcha. Sounds neat, but the problem is, do you know if I can
> work with proxies and then connect to a site?

You can, if you read the examples section in the urllib2 documentation.

http://docs.python.org/library/urllib2.html

-- 
kushal
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Winter Madness - Passing Python objects as Strings

2009-06-06 Thread Miles Kaufmann

On Jun 4, 2009, at 3:25 AM, Hendrik van Rooyen wrote:


A can is like a pickle, in that it is a string, but anything
can be canned.
Unlike a pickle, a can cannot leave the process, though,
unless the object it points to lives in shared memory.

If you have any interest, contact me and I will
send you the source.


Sounds like di(), which can be written:

import _ctypes
di = _ctypes.PyObj_FromPtr

def can(o): return str(id(o))
def uncan(s): return di(int(s))

http://www.friday.com/bbum/2007/08/24/python-di/

-Miles

--
http://mail.python.org/mailman/listinfo/python-list


Re: Scope objects

2009-06-06 Thread Gabriel Genellina

En Sat, 06 Jun 2009 03:03:34 -0300,  escribió:

On Jun 5, 8:56 pm, Robert Dailey  wrote:



Is it possible to create an object in Python that will clean itself up
at function exit? I realize destruction of objects may not occur
immediately and can be garbage collected, but this functionality would
still be great to have.


I don't know what you mean by:

"I realize destruction of objects may not occur immediately and can be
garbage collected"

Aren't you just missing ordinary destructors (__del__() methods)?
These are closest to C++ destructors AFAICS. As far as I know, these
are guaranteed to be called when an object goes out of scope. (Note
that destruction and garbage collection are different operations; an
object may be destructed without being immediately garbage-collected
afterwards.)


No, that's not how it works in Python (and I think you're mistaken for C++  
too).
See http://docs.python.org/reference/datamodel.html and specially  
http://docs.python.org/reference/datamodel.html#object.__del__


"Objects are never explicitly destroyed; however, when they become  
unreachable they may be garbage-collected. An implementation is allowed to  
postpone garbage collection or omit it altogether."


CPython uses a "reference count" scheme - an object is destroyed as soon  
as it loses its last reference. Other implementations may choose another  
strategy - in fact, Jython relies on garbage collection instead; object  
destruction may be delayed an arbitrary amount of time. (CPython has a  
garbage collector too, but its purpose is to detect and break object  
cycles.)


So the OP is right - you can't rely on object destruction to perform any  
cleanup; use try/finally or a with statement instead.




import sys
class Simple:

... def __init__(self): sys.stdout.write("Simple.__init__()\n")
... def __del__(self):  sys.stdout.write("Simple.__del__()\n")
...

def f():

... s = Simple()
... sys.stdout.write("f()\n")
... # 's' now going out of scope...
...

f()

Simple.__init__()
f()
Simple.__del__()


This behaviour isn't guaranteed and you should not rely on it. Also, try  
again with:


def f():
  s = Simple()
  t = Simple()
  s.x = t
  t.x = s
  sys.stdout.write("f()\n")

--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list


Re: A simpler logging configuration file format?

2009-06-06 Thread Lawrence D'Oliveiro
In message 
<30db8a0b-5b19-47e4-9364-54cbd7a7c...@h23g2000vbc.googlegroups.com>, 
geoff.ba...@gmail.com wrote:

> At the moment, if I want to add a new logger "foo" writing to its own
> file "foo" to my config file, I have to repeat the name 7(!) times,
> editing 3 different sections in the process:

I suppose there's always the Sendmail solution: stick an m4 wrapper on top 
to hide the details of the process. :)

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Christian Audigier Bikinis

2009-06-06 Thread Lawrence D'Oliveiro
In message , tanvo...@gmail.com wrote:

> Please check our web ...

Wow, you have a web. I always wanted to have one of those.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Messing up with classes and their namespace

2009-06-06 Thread Dave Angel

Jean-Michel Pichavant wrote:
Scott 
David Daniels wrote:

Jean-Michel Pichavant wrote:

Hello world,

I had recently a very nasty bug in my python application. The 
context is quite complex, but in the end the problem can be resume 
as follow:


2 files in the same directory :

lib.py:
 >import foo
 >foo.Foo.BOOM='lib'

foo.py:
 >class Foo:
 >BOOM = 'F'
 >
 >if __name__=='__main__':
 >import lib # I'm expecting BOOM to be set to 'lib'
 >print Foo.BOOM

I was expecting 'lib' as output, but I got 'Fooo'. I don't really 
understand what python mechanism I'm messing with but I have the 
feeling I've misunderstood a very basic concept about class, 
namespace or whatever import notion.




I guess there is 2 different objects for the same class Foo. How I 
do I make both Foo objects the same object ?


OK, here is one solution (from which you may infer the problem):

lib.py:
import __main__
__main__.Foo.BOOM = 'lib'

foo.py:
class Foo:
BOOM = 'F'

if __name__ == '__main__':
import lib # I'm expecting BOOM to be set to 'lib'
print(Foo.BOOM)

Here is another solution:

lib.py:
import foo
foo.Foo.BOOM = 'lib'

foo.py:
class Foo:
BOOM = 'F'

if __name__ == '__main__':
import sys
sys.modules['foo'] = sys.modules['__main__']
import lib # I'm expecting BOOM to be set to 'lib'
print(Foo.BOOM)

Here is a demo of what is actually going wrong:

foo.py:
class Foo:
inside = __name__

import foo

if __name__ == '__main__':
print(Foo is foo.Foo)
print(Foo.inside, foo.Foo.inside)

And here is a fix
foo.py:
if __name__ == '__main__':
import sys
sys.modules['foo'] = sys.modules['__main__']

class Foo:
inside = __name__

import foo

if __name__ == '__main__':
print(Foo is foo.Foo)
print(Foo.inside, foo.Foo.inside)


--Scott David Daniels
scott.dani...@acm.org


Thanks for the explanation. I'll have to give it a second thought, I'm 
still missing something but I'll figure it out.


Jean-Michel



In general, two or more modules with mutual imports can cause problems.  
If  modulea.py imports moduleb, and moduleb.py imports modulea, you can 
end up with difficulties.


But even more gross difficulties come from importing the module that 
started the execution, as it's got another name, "__main__"   If you 
import it again with its traditional name, these two do not get 
combined, and you end up with multiple instances of things you thought 
were safe.


Scott has given you a solution for the second problem.  But the first 
problem is more general, and should perhaps be the one you try first.


The simplest answer in many cases is to factor the script into two 
separate files.  One will have "library" functions and classes, like the 
Foo in your example.  And the other will have the logic for parsing 
command line arguments and suchlike.


The general problem isn't unique to Python.  You can also end up with 
problems in C, where one header includes a second one, which re-includes 
the first.  The workarounds for it are well known, but most of them also 
contain subtle difficulties.


If it's possible, factor out mutual dependencies into a separate module.

--
http://mail.python.org/mailman/listinfo/python-list


Re: Winter Madness - Passing Python objects as Strings

2009-06-06 Thread Hendrik van Rooyen
"Gabriel Genellina"  wrote:

> From your description of the problem, it seems you are acting upon  
>messages received from a serial port. You have to process the message  
>*before* the next one arrives -- but you gain nothing doing that much  
>faster. In other words, even with a blazingly fast processor, you can't do  
>things faster than the rate of incoming messages.

This is what I said, but it is only half of the truth. The actual code 
is a little bit better.  What I have been describing here for 
simplicity's sake, is the path taken when there is actually something 
in the queue.  The non blocking queue.get() sits in a try except, 
and if the queue is empty, it actually gathers the inputs and then 
examines them for change.  If there are changes, it makes up 
response messages to the various clients and puts them on the 
output queues.  If there are no changes, and if it has been a 
while since the last responses were sent, it sends responses as 
well.  Else it sleeps for a very short time and then examines the 
incoming queue again.

This arrangement minimises the network usage to what is essential,
while also reassuring the clients that all is well when nothing is
happening. It also uses the time when there is no new output to
scan the inputs, and it is this that I was talking about when I 
defined the responsiveness.

>
>In any case, you have to test-and-branch in the code. Either with  
>isinstance(rec,str), either with rec_list[0]=="B", or something. I'm  

Yes - but this is the second test, that is only reached in the very
seldom case that the first one is not true, so it does not add to
the normal critical timing path.

>unsure if this is the fastest approach - intuition doesn't play well with  
>timings in Python, better to actually measure times.
>

You have never said a truer thing - at one stage I was using a loop
in C to scan the inputs and put them in memory, but I went back to
python because it was faster to use a small time.sleep than the
equivalent usleep in C.  I still do not understand how that could be,
but my oscilloscope does not lie.

8<

>If it works and you feel it's adequate, that's fine. I cannot count how  
>many times I've used an integer property to attach a pointer to another  
>object (in other languages), but I felt "dirty" doing that. And never did  
>something like that in Python...

I think that the dirty feeling is caused by the FUD that has been created
by C's pointer types, and the magic that happens when you add 1 to 
a pointer and it actually increments by the size of a whole structure,
invisibly.  It makes one forget that the pointer is just a number representing
a memory address. And we have all been bitten in some way or another
by pointer arithmetic.  And if you look at this thread's title, it is not
called Winter Madness by accident... :-)

8<

>Ok, what if you split *before* putting in the queue? In the receiving side  
>of the queue, just remove the split(",") part (it's already done). This  
>does not add anything to the critical path - the split must be done anyway.

This is good thinking, thank you. It cuts the knot.

>
>Now, instead of building a fake string "B,cannedobject" and uncanning on  
>the other side, you can simply put a tuple in the queue ("B", the_object)  
>and just get the object on the other side. If I'm not misunderstanding  
>your problem, I think this is the cleanest way to do that.

You are spot on, and you are not misunderstanding anything.
This will work, and work well. Thank you again.

So now I have two viable alternatives to the can -
yours, and Scott's.

So it looks like it is time to can the Can.

So I can have a productive day throwing code away.

Thanks again.

- Hendrik


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Winter Madness - Passing Python objects as Strings

2009-06-06 Thread Hendrik van Rooyen
"Scott David Daniels"  wrote:

> I can think of use cases for can, and from that use an alternate
> construct.   The use case is passing a reference out over a wire
> (TCP port?) that will be used later.

This will work, provided the thing is still alive and in the same place
when the can eventually finds its way back and gets uncanned.
As it is now, no attempt has been made to handle refcounting
issues.

> Sub cases:
> (1) Handing work over the wire along with a callback to invoke
>  with the results.
> (2) Handing work over the wire along with a progress callback.
> (3) Handing work over the wire along with a pair of result functions,
>  where the choice of functions is made on the far side of the wire.
> 
> The "can" can be used to send the function(s) out.
> Alternatively, for use case 1:
> 
>  class Holder(object):
>  def __init__(self):
>  self.key = 0
>  self.holds = {}
>  def handle(self, something):
>  key = str(self.key) # may need to lock w/ next for threads
>  self.key += 1
>  self.holds[key] = something
>  return key
>  def use(self, handle):
>  return self.holds.pop(handle)

This is nice - you are making a simple index.

Dammit! why did I not think of something like this -
It keeps it all in Python, without a C extension.
In my case I would need a global so that I would
know where to look it up in, but that is a non issue
as it can be made at startup.  

I really should keep the maxim in mind:

There is no problem in computer science that can
not be solved by means of the introduction of another
layer of indirection.

:-)

Thanks for this post Scott - it has helped to straighten
out my one track minded thinking - I got hung up on the 
idea of passing the reference, to the extent that I expended
what was for me heroic effort to get it across.

What causes me real chagrin is that I am already keeping
a list of queues - the active queue list that keeps the list
of output queues for the various clients that have connected.
And I am too dim witted to think of a dict...

> 
> Otherwise a simple dictionary with separate removal may be needed.
> If you might abandon an element w/o using it, use a weakref dictionary,
> but then you need a scheme to keep the thing alive long enough
> for needed operations (as you also need with a can).

In my use case the queue would have stayed alive because
the thread that created it would have kept it going until
it was no longer needed, as would the reference created
by the binding of the local name in the thread.

> 
> In use case 1, the dictionary becomes that holding point.
> The counter-as-key idea allows you to keep separate references
> to the same thing, so the reference is held for precisely as long
> as needed.  It (counter-as-key) beats the str(id(obj)) of can
> because it tracks the actual object, not simply the id that can
> be reused.

The can just looks like str(id(obj)) - at the C level, it
actually comes from the PyObject *, gets stringified,
and the uncan returns the original PyObject *. So
if I understand it correctly, after the uncanning, it 
__is__ the original object. (if it is still there)

As I said above, I have paid no attention to refcounting
issues, - it really needs someone knowledgeable to
work over my C code, as this was my first venture into
the wonderful world of extending python.

But it hardly seems worth while now...

- Hendrik


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Winter Madness - Passing Python objects as Strings

2009-06-06 Thread Hendrik van Rooyen
"Miles Kaufmann"  wrote:
> On Jun 4, 2009, at 3:25 AM, Hendrik van Rooyen wrote:
> 
> > A can is like a pickle, in that it is a string, but anything
> > can be canned.
> > Unlike a pickle, a can cannot leave the process, though,
> > unless the object it points to lives in shared memory.
> >
> > If you have any interest, contact me and I will
> > send you the source.
> 
> Sounds like di(), which can be written:
> 
> import _ctypes
> di = _ctypes.PyObj_FromPtr
> 
> def can(o): return str(id(o))
> def uncan(s): return di(int(s))
> 
> http://www.friday.com/bbum/2007/08/24/python-di/

There is nothing new...

Normally it takes a long time before something is
re invented. 
In this case it looks like less than two years.

Thank you for the link

- Hendrik

-- 
http://mail.python.org/mailman/listinfo/python-list


interval arithmetic libraries

2009-06-06 Thread srepmub
Hi all,

I'm looking for libraries that allow one to calculate with sets of
(date) intervals. So for example, I'd like to be able to calculate the
overlap between two sets of intervals, the union etc. Preferrably,
this works with datetime objects, is written in pure Python, and has
reasonably good (algorithmic) performance. The neatest library I've
found so far is this one:

http://members.cox.net/apoco/interval/

>From an API standpoint, it looks rather nice, but the performance
could be better (for example, calculating an overlap now involves
looping quadratically over both interval sets), and it doesn't work
fully with datetime objects (Inf doesn't work).


Thanks for any pointers,
Mark Dufour.
(author of Shedskin, an experimental (restricted-)Python-to-C++
compiler, http://shedskin.googlecode.com)


-- 
http://mail.python.org/mailman/listinfo/python-list


py3k printing generators -- not!

2009-06-06 Thread samwyse
The one thing that's killing me in Python 3000 is that every time I
try to print something, it seems like I get  at 0x01BAF508>.  Googling only found one reference, a
posting elsewhere by one Carl Johnson (aka carlj7,
http://www.artima.com/forums/flat.jsp?forum=106&thread=211200#275387),
which apparently was never answered.  Is anyone else finding this
bothersome, or is it entirely due to my FP background?

Always saying "print(','.join(x))" gets tiresome in a hurry.  I've
thought about defining my own function "prnt" that wraps print and
fixes generators, but that requires me to get their type, which
despite the claims of "help(type(x for x in range(0)))" cannot be
found in builtins.  How are other solving this?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: MD6 in Python

2009-06-06 Thread Aahz
In article ,
Terry Reedy   wrote:
>Aahz wrote:
>>
>> Um, what?  You mean 3.1rc1, right?  Nevertheless, my understanding is
>> that 2.7 is mostly restricted to code landed in 3.1, so your second
>> statement is roughly correct.
>
>My understanding is that 2.7 will come out about the same time as 3.2 
>and will contain 3.2 backports also.  New features are being marked on 
>the issue tracker as for 2.7/3.2.  There may or may not be a 2.8.
>
>(It was once intended that 2.7 come out with 3.1, but that changed when 
>it was decided to cut the life of 3.0 and bring out 3.1 after 6 months.)

Right, but it was my understanding that work on releasing 2.7 would
commence immediately after 3.1, and that 3.2 would happen after 2.7.
Maybe we should take this to python-dev...  ;-)
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"If you don't know what your program is supposed to do, you'd better not
start writing it."  --Dijkstra
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: py3k printing generators -- not!

2009-06-06 Thread Carl Banks
On Jun 6, 5:28 am, samwyse  wrote:
> The one thing that's killing me in Python 3000 is that every time I
> try to print something, it seems like I get   at 0x01BAF508>.  Googling only found one reference, a
> posting elsewhere by one Carl Johnson (aka 
> carlj7,http://www.artima.com/forums/flat.jsp?forum=106&thread=211200#275387),
> which apparently was never answered.  Is anyone else finding this
> bothersome, or is it entirely due to my FP background?
>
> Always saying "print(','.join(x))" gets tiresome in a hurry.  

What about print(list(x))

> I've
> thought about defining my own function "prnt" that wraps print and
> fixes generators, but that requires me to get their type, which
> despite the claims of "help(type(x for x in range(0)))" cannot be
> found in builtins.

Interestingly, the fact that it wasn't in builtins didn't stop you
from being able to pass the type to the help() function.  I wonder if
you can use the same trick to obtain the type for use in your prnt()
function.

(Failing that, you could use "from types import GeneratorType".)

> How are other solving this?

In my experience, if you want a custom print function that prints
things the way you want, you have to write it yourself.  People's
expectations are too different.


Carl Banks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: py3k printing generators -- not!

2009-06-06 Thread bearophileHUGS
samwyse:
> Always saying "print(','.join(x))" gets tiresome in a hurry.  I've
> thought about defining my own function "prnt" that wraps print and
> fixes generators, but that requires me to get their type,

Why do you need to know their type?
Isn't something like this enough?

def pr(it):
txt = "".join(map(str, it))
print(txt)

That little function can be improved in many ways.


> despite the claims of "help(type(x for x in range(0)))"
> cannot be found in builtins.

Python can yield mixed types (nearly never recommended):

def foo():
  yield 1
  yield "hello"
  yield 1.5

Bye,
bearophile
-- 
http://mail.python.org/mailman/listinfo/python-list


PyQt icon problem

2009-06-06 Thread Pieter Provoost
Hi,

My application has a QSystemTrayIcon, which needs to be changed once in a
while. The PNG icons are converted into a module using pyrcc4. When I run
the Python script on my Windows system everything works fine, but when run
it on Ubuntu or when I use py2exe, the icons are not visible (there's only
empty space in the tray).

Any thoughts?
Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: py3k printing generators -- not!

2009-06-06 Thread bearophileHUGS
Carl Banks:
> What about print(list(x))

Right, better than mine :-)

Bye,
bearophile
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: openhook

2009-06-06 Thread Scott David Daniels

Gaudha wrote:

Can anybody tell me what is meant by 'openhook' ?

Certainly someone can.
--
http://mail.python.org/mailman/listinfo/python-list


Re: py3k printing generators -- not!

2009-06-06 Thread samwyse
On Jun 6, 7:58 am, Carl Banks  wrote:
> On Jun 6, 5:28 am, samwyse  wrote:

> > Always saying "print(','.join(x))" gets tiresome in a hurry.  
>
> What about print(list(x))

Yeah, I like that.  Or, to save some typing:
  prnt = lambda x: print(list(x))

> Interestingly, the fact that it wasn't in builtins didn't stop you
> from being able to pass the type to the help() function.  I wonder if
> you can use the same trick to obtain the type for use in your prnt()
> function.

Of course, but it would mean evaluating an expression every time I
defined my function.  That just seems unhygenic

> (Failing that, you could use "from types import GeneratorType".)

Ah!  I should've thought of that.

> In my experience, if you want a custom print function that prints
> things the way you want, you have to write it yourself.  People's
> expectations are too different.

Well, that's why I rferenced the other article,
http://www.artima.com/forums/flat.jsp?forum=106&thread=211200#275387),
to show that other people have the same expectations.  (In the
article, Carl Johnson correctly points out that the real problem is
that str() responds to generators differently than do the other
collection types.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Iterating Over Dictionary From Arbitrary Location

2009-06-06 Thread akindo

Hi all. I am new to Python and have a problem regarding data structures.

In my application I will be having several messages and my own type of  
IDs (Lamport clocks) to go with these messages. I will need to  
frequently ask for specific messages based on the ID. Hence a  
dictionary seems a better choice than a list, as I will be using my  
own IDs to index into the data structure. However, the problem is that  
I will also at times ask for a specific message based on the ID key,  
but then want _all_ messages with a higher ID returned as  
well. :shock: From my research, there are two problems with a  
dictionary then: 1. it can't be sorted (only returns a sorted list),  
2. even if it was possible to sort a dictionary, it is not possible to  
iterate over it from a given location.


So, it seems I want the best of both worlds: specific indexing using  
my own IDs/keys (not just by list element location), sorting and the  
ability to start iterating from a specific location. I am trying to  
prevent having to scan through a list from the beginning to find the  
desired ID, and then return all elements after that. Is there another  
data structure or design pattern which will do what I want? Thanks a  
lot for any help! :)



--
http://mail.python.org/mailman/listinfo/python-list


Re: can it be shorter?

2009-06-06 Thread Steven D'Aprano
On Sat, 06 Jun 2009 23:07:58 +0800, tsangpo wrote:

> I want to ensure that the url ends with a '/', now I have to do thisa
> like below.
> url = url + '' if url[-1] == '/' else '/'
> 
> Is there a better way?


if not url.endswith('/'):
url += '/'


-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: openhook

2009-06-06 Thread Steven D'Aprano
On Sat, 06 Jun 2009 06:47:34 -0700, Scott David Daniels wrote:

> Gaudha wrote:
>> Can anybody tell me what is meant by 'openhook' ?
> Certainly someone can.

It's just like closehook, only different.


-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyQt icon problem

2009-06-06 Thread Pieter Provoost
Correction: when using py2exe, no icon, empty space or message is visible
(the app is running though). On Ubuntu, there is an empty space but messages
are not displayed.

2009/6/6 Pieter Provoost 

> Hi,
>
> My application has a QSystemTrayIcon, which needs to be changed once in a
> while. The PNG icons are converted into a module using pyrcc4. When I run
> the Python script on my Windows system everything works fine, but when run
> it on Ubuntu or when I use py2exe, the icons are not visible (there's only
> empty space in the tray).
>
> Any thoughts?
> Thanks
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Iterating Over Dictionary From Arbitrary Location

2009-06-06 Thread Diez B. Roggisch

akindo schrieb:

Hi all. I am new to Python and have a problem regarding data structures.

In my application I will be having several messages and my own type of 
IDs (Lamport clocks) to go with these messages. I will need to 
frequently ask for specific messages based on the ID. Hence a dictionary 
seems a better choice than a list, as I will be using my own IDs to 
index into the data structure. However, the problem is that I will also 
at times ask for a specific message based on the ID key, but then want 
_all_ messages with a higher ID returned as well. :shock: From my 
research, there are two problems with a dictionary then: 1. it can't be 
sorted (only returns a sorted list), 2. even if it was possible to sort 
a dictionary, it is not possible to iterate over it from a given location.


So, it seems I want the best of both worlds: specific indexing using my 
own IDs/keys (not just by list element location), sorting and the 
ability to start iterating from a specific location. I am trying to 
prevent having to scan through a list from the beginning to find the 
desired ID, and then return all elements after that. Is there another 
data structure or design pattern which will do what I want? Thanks a lot 
for any help! :)


you could use a list which is sorted and then use the bisect-module to 
look up your keys in O(log n). You could also map keys to list-indices.


Diez
--
http://mail.python.org/mailman/listinfo/python-list


Re: can it be shorter?

2009-06-06 Thread kj
In  "tsangpo"  
writes:

>I want to ensure that the url ends with a '/', now I have to do thisa like 
>below.
>url = url + '' if url[-1] == '/' else '/'

>Is there a better way? 

It's a pity that in python regexes are an "extra", as it were.
Otherwise I'd propose:

url = re.sub("/?$", "/", url)

kynn (lowest-of-the-low python noob)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Iterating Over Dictionary From Arbitrary Location

2009-06-06 Thread bearophileHUGS
akindo:
> So, it seems I want the best of both worlds: specific indexing using  
> my own IDs/keys (not just by list element location), sorting and the  
> ability to start iterating from a specific location.

A sorted associative map may be fit. A data structure based on a
search tree, like a red-black tree, etc.
The Python std lib doesn't contain such data structure.
Do you need to add items to your data structure? Diez has suggested a
possible solution. You can keep a copy of the items in a sorted list,
but this isn't handy if you have to add and remove items frequently.
Or you may be able to find somewhere a sorted associative array data
structure (tree-based).

Bye,
bearophile
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: openhook

2009-06-06 Thread Martin P. Hellwig

Steven D'Aprano wrote:

On Sat, 06 Jun 2009 06:47:34 -0700, Scott David Daniels wrote:


Gaudha wrote:

Can anybody tell me what is meant by 'openhook' ?

Certainly someone can.


It's just like closehook, only different.




Just like the flipflophook, the quantumhook and captain hook.

--
MPH
http://blog.dcuktec.com
'If consumed, best digested with added seasoning to own preference.'
--
http://mail.python.org/mailman/listinfo/python-list


Re: can it be shorter?

2009-06-06 Thread tsangpo


"kj"  写入消息 news:h0e3p9$85...@reader1.panix.com...
In  "tsangpo" 
 writes:



I want to ensure that the url ends with a '/', now I have to do thisa like
below.
url = url + '' if url[-1] == '/' else '/'



Is there a better way?


It's a pity that in python regexes are an "extra", as it were.
Otherwise I'd propose:

url = re.sub("/?$", "/", url)

kynn (lowest-of-the-low python noob)


look nice, but:


re.sub('/?$/', '/', 'aaabbb')

'aaabbb'

has no effect. what a pity. 


--
http://mail.python.org/mailman/listinfo/python-list


Re: py3k printing generators -- not!

2009-06-06 Thread Steven D'Aprano
On Sat, 06 Jun 2009 05:28:30 -0700, samwyse wrote:

> The one thing that's killing me in Python 3000 

Python 3000 was vapourware. When the vapour condensed into liquid, it was 
renamed Python 3. Right now, the only vapourware is Python4000, which may 
or may not be created by Guido's heir some time in the 2020s.


> is that every time I try
> to print something, it seems like I get  at
> 0x01BAF508>.

"Every time"? Really? Even when you print an object which isn't a 
generator?


> Googling only found one reference, a posting elsewhere by
> one Carl Johnson (aka carlj7,
> http://www.artima.com/forums/flat.jsp?forum=106&thread=211200#275387),
> which apparently was never answered.

Ignoring Carl's totally pointless "mycond()" function, he apparently 
wants type(iterable)(i for i in iterable) to give iterable:

>>> it = [1, 2]
>>> type(it)(i for i in it)
[1, 2]


But that can't work for arbitrary iterables:

>>> it = {1:2, 3:4}
>>> type(it)(i for i in it)
Traceback (most recent call last):
  File "", line 1, in 
TypeError: cannot convert dictionary update sequence element #0 to a 
sequence


Nor will it work for generator objects themselves:

>>> it = (1+x for x in range(5))
>>> type(it)(i for i in it)
Traceback (most recent call last):
  File "", line 1, in 
TypeError: cannot create 'generator' instances


So Carl's suggestion can't be applied universally, it can only hold for 
some iterables. It doesn't even hold for all sequences, with strings a 
conspicuous example. In fact, that's what Carl is complaining about:

>>> it = "abc"
>>> type(it)(i for i in it)
' at 0xb7ce3d24>'


He apparently would prefer str(i for i in "abc") to return "abc". 
However, you seem to prefer "a,b,c" instead. So what you would prefer, 
and what Carl would prefer, are different.

Either way though, there's a fatal flaw in the idea: printing an object 
shouldn't consume the object, but that's what you want. Unlike a list or 
a tuple, a generator is *code*, not a data type. It produces values when 
and as asked. So there's no way to peek inside a generator and see the 
values that it will produce, consequently, for str() to behave as you and 
Carl want, it has to run the generator to completion, performing an 
arbitrarily large amount of work (and perhaps, for non-terminating 
generators, never finishing!) before you can print it. And then, having 
printed it, the generator is now exhausted. Try to print it again, and 
you'll get the empty string.

Calling list() on a generator is different: it is *designed* to exhaust 
the generator. I'd be upset if print() and/or str() did the same thing.

I'd also be upset if generators looked like a string when they're not:

>>> x = (c.lower() for c in "ABC")
>>> x
'abc'
>>> x.upper()  # x looks like a string, but it isn't
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'generator' object has no attribute 'upper'



[...]
> I've
> thought about defining my own function "prnt" that wraps print and fixes
> generators, but that requires me to get their type, which despite the
> claims of "help(type(x for x in range(0)))" cannot be found in builtins.
>  How are other solving this?

I'm not "solving" this, because I don't think this is a problem that 
needs solving. But if you want a custom print function, this should work:

def print(*values, **kwargs):
from builtins import print as pr
gen = type(x for x in [1,2])
values = [','.join(str(s) for s in obj) if type(obj) is gen 
 else obj for obj in values]
pr(*values, **kwargs)




-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


python repository?

2009-06-06 Thread woodchips
Hi,

I've written a large body of my work in MATLAB over the years. But it
looks like I'll need to move to Python soon. Is there a common
resource where people can post files for others to use such as the
MATLAB central file exchange?

Thanks,
John
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: can it be shorter?

2009-06-06 Thread Steven D'Aprano
On Sat, 06 Jun 2009 15:59:37 +, kj wrote:

> In  "tsangpo"
>  writes:
> 
>>I want to ensure that the url ends with a '/', now I have to do thisa
>>like below.
>>url = url + '' if url[-1] == '/' else '/'
> 
>>Is there a better way?
> 
> It's a pity that in python regexes are an "extra", as it were. Otherwise
> I'd propose:
> 
> url = re.sub("/?$", "/", url)


Thank goodness regexs are an "extra" in Python, because it discourages 
noobs from pulling out the 80 pound sledgehammer of the regex engine to 
crack the peanut of a test-and-concatenate:


>>> from timeit import Timer
>>> min(Timer(
... "if not s.endswith('/'): s += '/'", "s = 'abcd/efgh'").repeat())
0.70030903816223145
>>> min(Timer(
... "sub('/?$', '/', s)", "from re import sub; s = 'abcd/efgh'").repeat())
7.6922709941864014


That's more than ten times slower. Really, a regex is massive overkill 
for a task that simple.



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: openhook

2009-06-06 Thread Emile van Sebille

On 6/6/2009 6:47 AM Scott David Daniels said...

Gaudha wrote:

Can anybody tell me what is meant by 'openhook' ?

Certainly someone can.



OK -- kidding aside, the only python related reference I find is in a 
proposal and patch [1] made by Anthony Roy for changes to the fileinput 
module.  It's an argument passed into FileInput class initialization and 
apparently allows for a custom file open routine to be used to open the 
target file -- ergo openhook - a hook for opening.


Emile



[1] http://bugs.python.org/issue1613500

--
http://mail.python.org/mailman/listinfo/python-list


Re: can it be shorter?

2009-06-06 Thread Steven D'Aprano
On Sun, 07 Jun 2009 00:21:45 +0800, tsangpo wrote:

> "kj"  写入消息 news:h0e3p9$85t
$...@reader1.panix.com...
>> In  "tsangpo"
>>  writes:
>>
>>>I want to ensure that the url ends with a '/', now I have to do thisa
>>>like below.
>>>url = url + '' if url[-1] == '/' else '/'
>>
>>>Is there a better way?
>>
>> It's a pity that in python regexes are an "extra", as it were.
>> Otherwise I'd propose:
>>
>> url = re.sub("/?$", "/", url)
>>
>> kynn (lowest-of-the-low python noob)
> 
> look nice, but:
> 
 re.sub('/?$/', '/', 'aaabbb')
> 'aaabbb'
> 
> has no effect. what a pity.


That's because you're doing it wrong. You've added an extra slash: you're 
asking the regex engine to match a backslash *after* the end of the 
string. Obviously that will never match.

>>> re.sub('/?$/', '/', 'aaabbb')  # extra /
'aaabbb'
>>> re.sub('/?$', '/', 'aaabbb')  # no extra /
'aaabbb/'



But before you get too excited, see my previous post: the regex solution 
is more than ten times slower than test-and-concatenate.



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: pyTenjin 0.8.0 - much faster template engine than Django

2009-06-06 Thread kwatch
I have released pyTenjin 0.8.0
http://www.kuwata-lab.com/tenjin/

pyTenjin is the fastest template engine for Python.

* Very fast (about 10 times faster than Django template engine)
* Easy to learn (no need to learn template-original language)
* Full-featured (layout template, partial template,
preprocessing, ...)
* Very small (only 1,200 lines, one file)
* Goole AppEngine supported.
  http://www.kuwata-lab.com/tenjin/pytenjin-faq.html#faq-google-appengine



Changes from 0.7.0
--

  * !!IMPORTANT!!
HTML helper function 'tagattr()' is renamed to 'tagattrs()'.
(Notice that new 'tagattr()' is added. See below.)

  * 'tagattrs()' is changed to add ' ' (space) at the first character.
ex.
  (0.7.0)  tagattr(klass='error') #=> 'class="error"'
  (0.7.1)  tagattrs(klass='error')#=> ' class="error"'

  * 'tagattrs()' is changed to handle 'checked', 'selected', and
'disabled' attributes.
ex.
   >>> from tenjin.helpers.html import *
   >>> tagattrs(checked=True, selected='Y', disabled=1)
   ' checked="checked" selected="selected" disabled="disabled"'
   >>> tagattrs(checked=False, selected='', disabled=0)
   ''


Bugfix
--

  * !!IMPORTANT!!
Template caching is changed to keep template file's timestamp
instead of create time of cached object. See

http://groups.google.com/group/kuwata-lab-products/browse_thread/thread/a0d447c282fb383d#msg_de39557405c9b656
for details. (Thanks Steve)


Enhancements


  * Add new HTML helper function 'tagattr()'.
(Notice that 'tagattr()' in 0.7.0 is renamed into 'tagattrs()'.)
ex.
  >>> from tenjin.helpers.html import *
  >>> tagattr('size', 20)
  ' size="20"'
  >>> tagattr('size', 0)
  ''
  >>> tagattr('size', 20, 'large')
  ' size="large"'
  >>> size = 20# you can use tagattrs() instead of tagattr
()
  >>> tagattrs(size=(size and 'large'))
  ' size="large"'

  * Add new HTML helper function 'new_cycle()'.
ex.
  >>> from tenjin.helpers.html import *
  >>> cycle = new_cycle('odd, 'even')
  >>> cycle()
  'odd'
  >>> cycle()
  'even'
  >>> cycle()
  'odd'
  >>> cycle()
  'even'

  * (experimental) Template converter is changed to add dummy if-
statement
when first Python statement is indented. (Thanks Steve)
ex.
  $ cat ex.pyhtml
  

  

${item}

  

  
  $ pytenjin -sb ex.pyhtml
  _buf.extend(('''

  \n''', ));
  if True: ## dummy
for item in items:
_buf.extend(('''  ''', escape(to_str(item)),
'''\n''', ));
#end
_buf.extend(('''

  \n''', ));

  * Update User's Guide and FAQ.


Have fun!

--
regards,
makoto kuwata

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Programming language comparison examples?

2009-06-06 Thread Simon Brunning
2009/6/5  :
> someone:
>> I thought there was a website which demonstrated how to program a bunch of
>> small problems in a number of different languages.
>
> http://www.rosettacode.org/wiki/Main_Page
> http://en.literateprograms.org/LiteratePrograms:Welcome
> http://www.codecodex.com/wiki/index.php?title=Main_Page
> http://merd.sourceforge.net/pixel/language-study/scripting-language/
> http://pleac.sourceforge.net/
> http://www.angelfire.com/tx4/cus/shapes/index.html

And my favorite: http://99-bottles-of-beer.net/

-- 
Cheers,
Simon B.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: can it be shorter?

2009-06-06 Thread kj
In <023a8d04$0$20636$c3e8...@news.astraweb.com> Steven D'Aprano 
 writes:

>On Sat, 06 Jun 2009 15:59:37 +, kj wrote:

>> In  "tsangpo"
>>  writes:
>> 
>>>I want to ensure that the url ends with a '/', now I have to do thisa
>>>like below.
>>>url = url + '' if url[-1] == '/' else '/'
>> 
>>>Is there a better way?
>> 
>> It's a pity that in python regexes are an "extra", as it were. Otherwise
>> I'd propose:
>> 
>> url = re.sub("/?$", "/", url)


>Thank goodness regexs are an "extra" in Python, because it discourages 
>noobs from pulling out the 80 pound sledgehammer of the regex engine to 
>crack the peanut of a test-and-concatenate:

I was just responding to the OP's subject line.  Whatever else one
may say about my proposal, it *is* shorter.

But thanks for the tip with timeit.  That looks like a good module
to know.

kynn

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python repository?

2009-06-06 Thread Benjamin Kaplan
On Saturday, June 6, 2009,   wrote:
> Hi,
>
> I've written a large body of my work in MATLAB over the years. But it
> looks like I'll need to move to Python soon. Is there a common
> resource where people can post files for others to use such as the
> MATLAB central file exchange?
>
> Thanks,
> John
> --

For small code snippets that solve general problems, look at the
recipies on ActiveState's website (code.activestate.com). Large
projects are listed on the python package index (pypi.python.org)
though they aren't hosted there.

> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: openhook

2009-06-06 Thread Nick Craig-Wood
Gaudha  wrote:
>  Can anybody tell me what is meant by 'openhook' ?

http://docs.python.org/library/fileinput.html?highlight=openhook

Maybe ;-)

-- 
Nick Craig-Wood  -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: can it be shorter?

2009-06-06 Thread Nick Craig-Wood
tsangpo  wrote:
> 
>  "kj"  写入消息 news:h0e3p9$85...@reader1.panix.com...
> > In  "tsangpo" 
> >  writes:
> >
> >>I want to ensure that the url ends with a '/', now I have to do thisa like
> >>below.
> >>url = url + '' if url[-1] == '/' else '/'
> >
> >>Is there a better way?
> >
> > It's a pity that in python regexes are an "extra", as it were.
> > Otherwise I'd propose:
> >
> > url = re.sub("/?$", "/", url)
> >
> > kynn (lowest-of-the-low python noob)
> 
>  look nice, but:
> 
> >>> re.sub('/?$/', '/', 'aaabbb')
>  'aaabbb'
> 
>  has no effect. what a pity. 

That is because you typoed what kynn wrote.

>>> re.sub('/?$', '/', 'aaabbb')
'aaabbb/'
>>>

That solution is very perl-ish I'd say, IMHO

if not url.endswith("/"):
url += "/"

is much more pythonic and immediately readable.  In fact even someone
who doesn't know python could understand what it does, unlike the
regexp solution which requires a little bit of thought.

-- 
Nick Craig-Wood  -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: multi-core software

2009-06-06 Thread George Neuner
On Fri, 05 Jun 2009 16:26:37 -0700, Roedy Green
 wrote:

>On Fri, 5 Jun 2009 18:15:00 + (UTC), Kaz Kylheku
> wrote, quoted or indirectly quoted someone who
>said :
>
>>Even for problems where it appears trivial, there can be hidden
>>issues, like false cache coherency communication where no actual
>>sharing is taking place. Or locks that appear to have low contention and
>>negligible performance impact on ``only'' 8 processors suddenly turn into
>>bottlenecks. Then there is NUMA. A given address in memory may be
>>RAM attached to the processor accessing it, or to another processor,
>>with very different access costs.
>
>Could what you are saying be summed up by saying, "The more threads
>you have the more important it is to keep your threads independent,
>sharing as little data as possible."

And therein lies the problem of leveraging many cores.  There is a lot
of potential parallelism in programs (even in Java :) that is lost
because it is too fine a grain for threads.  Even the lightest weight
user space ("green") threads need a few hundred instructions, minimum,
to amortize the cost of context switching.

Add to that the fact that programmers have shown themselves, on
average, to be remarkably bad at figuring out what _should_ be done in
parallel - as opposed to what _can_ be done - and you've got a clear
indicator that threads, as we know them, are not scalable except under
a limited set of conditions. 

George
-- 
http://mail.python.org/mailman/listinfo/python-list


Is it possible to use multidimensional arrays ?

2009-06-06 Thread pdlemper
All attempts have failed.

import WConio
import array

screen = array.array('H',[0]*75,[0]*24) 
  ERR  array takes at most 2 arguments

screen = array.array('H',[0]*75[0]*24)
TypeErr  int object is unsubscriptable

screen = array.array('H',[0]*75)('H',[0]*24) 
 ERR  object is not callable

screen - array.array('H',[0]*75*24)
Goes through but results are, of course, unacceptable 
On-line docs and Programming in Python 3 are no help.
Should I give up on arrays and use lists, or go to NumPy ? Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: multi-core software

2009-06-06 Thread John Thingstad
På Sat, 06 Jun 2009 21:46:51 +0200, skrev George Neuner  
:



On Fri, 05 Jun 2009 16:26:37 -0700, Roedy Green

Add to that the fact that programmers have shown themselves, on
average, to be remarkably bad at figuring out what _should_ be done in
parallel - as opposed to what _can_ be done - and you've got a clear
indicator that threads, as we know them, are not scalable except under
a limited set of conditions.

George


I find the dataflow model of concurrency on Oz to be interesting and to  
address many of the issues you just mentioned.
See in particular: 'Dataflow variables and declarative concurrency' and  
onward.

http://en.wikipedia.org/wiki/Oz_(programming_language)


-
John Thingstad
--
http://mail.python.org/mailman/listinfo/python-list


Servizio aziende : messaggio per python-list@python.org

2009-06-06 Thread v . donati






Offriamo :
Servizi di consulenza  per :  marketing ,  informatica , 
traduzioni 
Assistenza nazionale ed internazionale
Per maggiori informazioni e preventivi mailto:sm...@woomail.com"; 
;>clicca qui
Per reclami inviare mail a mailto:matteoro...@gawab.com"; 
;>SMINI
Se non vuoi ricevere altri messaggi invia una mail a mailto:smini_un...@gawab.com"; ;>SMINI UNSUBSCRIBE
Messaggio per : python-list@python.org


We offer :
Consulting for : marketing , information , translating services 
National and international assistance
To ask for further information and estimates mailto:sm...@woomail.com"; ;>click here
To complain send an email to mailto:matteoro...@gawab.com"; 
;>SMINI
In case you do not want to receive further messages, send a mail tomailto:smini_un...@gawab.com"; ;>SMINI UNSUBSCRIBE
Message for : python-list@python.org







 --
 Caselle da 1GB, trasmetti allegati fino a 3GB e in piu' IMAP, POP3 e SMTP 
autenticato? GRATIS solo con Email.it http://www.email.it/f

 Sponsor:
 Legal.email.it: posta elettronica certificata per l'invio di email con valore 
legale e SMS di notifica
 Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid‰78&d=6-6
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is it possible to use multidimensional arrays ?

2009-06-06 Thread kj
In  pdlem...@earthlink.net writes:

>All attempts have failed.

>import WConio
>import array

>screen = array.array('H',[0]*75,[0]*24) 
>  ERR  array takes at most 2 arguments

>screen = array.array('H',[0]*75[0]*24)
>TypeErr  int object is unsubscriptable

>screen = array.array('H',[0]*75)('H',[0]*24) 
> ERR  object is not callable

>screen - array.array('H',[0]*75*24)
>Goes through but results are, of course, unacceptable 
>On-line docs and Programming in Python 3 are no help.
>Should I give up on arrays and use lists, or go to NumPy ? Thanks

I guess you could do something like

screen = [array.array('H', [0]*75) for i in range(24)]

but I doubt that the resulting structure would be that much more
efficient than the pure-list equivalent...

kynn -- lowest-of-the-low python noob
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Error in linalg.inv ??

2009-06-06 Thread Robert Kern

On 2009-06-06 00:34, Ajith Kumar wrote:

Hello,
I ran the following code (Using Debian 5.0)

from numpy import *


Please ask numpy questions on the numpy mailing list, not here:

  http://www.scipy.org/Mailing_Lists


a = arange(1.,10.)
b = reshape(a, [3,3])
c = linalg.inv(b)
print b
print c
print dot(b,c)
print dot(c,b)

And the result is

[[ 1. 2. 3.]
[ 4. 5. 6.]
[ 7. 8. 9.]]

[[ 3.15221191e+15 -6.30442381e+15 3.15221191e+15]
[ -6.30442381e+15 1.26088476e+16 -6.30442381e+15]
[ 3.15221191e+15 -6.30442381e+15 3.15221191e+15]]

[[-0.5 -1. -1. ]
[-1. -2. 2. ]
[-1.5 -3. 1. ]]

[[ 5.5 8. 10.5]
[ 3. 0. -3. ]
[ -1. 0. -3. ]]

NOT the identity matrix. Any help ?


You have a very singular matrix (2*a[1] - a[0] == a[2]). You cannot invert it 
numerically and expect sensible results.


--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

--
http://mail.python.org/mailman/listinfo/python-list


Re: Is it possible to use multidimensional arrays ?

2009-06-06 Thread Robert Kern

On 2009-06-06 14:48, pdlem...@earthlink.net wrote:

All attempts have failed.

 import WConio
 import array

 screen = array.array('H',[0]*75,[0]*24)
   ERR  array takes at most 2 arguments

 screen = array.array('H',[0]*75[0]*24)
 TypeErr  int object is unsubscriptable

 screen = array.array('H',[0]*75)('H',[0]*24)
  ERR  object is not callable

 screen - array.array('H',[0]*75*24)
 Goes through but results are, of course, unacceptable
On-line docs and Programming in Python 3 are no help.
Should I give up on arrays and use lists, or go to NumPy ? Thanks


Go to numpy, probably.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

--
http://mail.python.org/mailman/listinfo/python-list


Re: Odd closure issue for generators

2009-06-06 Thread Terry Reedy

Michele Simionato wrote:


Yes, most functional languages have the concept of streams.
You can even define a stream-comprehension that looks like
Python generator comprehension but it is an essentially different
thing. See for instance

http://www.artima.com/weblogs/viewpost.jsp?thread=251159


I read that.  It seems that streams are virtual or lazy linked-lists(1). 
 I think, though, that comparing them to iterators is misleading.  They 
are iterables, but with a different iteration protocol.  Python 
iterables are generally reiterable just like streams.


chars = 'abc'
for c in chars: print(c,end=' ')
for c in chars: print(c,end=' ')

produces repeatable output just like your stream example.  Python 
*could* have given iterables .first and .rest methods instead of 
.__iter__, but that works best for linked lists and awfully for arrays.


Anyway, I realize now that having generator comprehensions produce an 
*iterator* rathar than an *iterable* or *generator function* is 
something of an anomaly  Set, dict, and list comprehensions in Python 
produce iterables, of course, as does a stream comprehension in Scheme 
and, I presume, comprehensions in other languages.


A generator expression could have been defined in Python to just produce 
a generator function, without calling it, but the intent of the 
abbreviation was for one-use situations.  Multi-use gfs should be 
defined with a def statement.


Terry Jan Reedy

(1) Calling the first and rest methods 'car' and 'cdr' convinces me that 
schemers really do not want scheme to be popular, but prefer it to 
remain a small cult language.


--
http://mail.python.org/mailman/listinfo/python-list


Re: can it be shorter?

2009-06-06 Thread kj
In  kj  writes:

>In <023a8d04$0$20636$c3e8...@news.astraweb.com> Steven D'Aprano 
> writes:

>>On Sat, 06 Jun 2009 15:59:37 +, kj wrote:

>>> In  "tsangpo"
>>>  writes:
>>> 
I want to ensure that the url ends with a '/', now I have to do thisa
like below.
url = url + '' if url[-1] == '/' else '/'
>>> 
Is there a better way?
>>> 
>>> It's a pity that in python regexes are an "extra", as it were. Otherwise
>>> I'd propose:
>>> 
>>> url = re.sub("/?$", "/", url)


>>Thank goodness regexs are an "extra" in Python, because it discourages 
>>noobs from pulling out the 80 pound sledgehammer of the regex engine to 
>>crack the peanut of a test-and-concatenate:

>I was just responding to the OP's subject line.  Whatever else one
>may say about my proposal, it *is* shorter.

>But thanks for the tip with timeit.  That looks like a good module
>to know.



And actually, if speed is the criterion, then one should also avoid endswith:

>>> from timeit import Timer
>>> min(Timer("if s[-1] != '/': s += '/'", "s = 'abcd/efgh'").repeat())
0.18654584884643555
>>> min(Timer("if not s.endswith('/'): s += '/'", "s = 'abcd/efgh'").repeat())
0.43395113945007324

kynn

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Error in linalg.inv ??

2009-06-06 Thread Terry Reedy

Ajith Kumar wrote:


[[ 1.  2.  3.]
[ 4.  5.  6.]
[ 7.  8.  9.]]


Another way to see that this is singular is notice or calculate that
(1,2,3) - 2*(4,5,6) + (7,8,9) = (0,0,0)
Same is true for the columns.

--
http://mail.python.org/mailman/listinfo/python-list


Re: Error in linalg.inv ??

2009-06-06 Thread John Machin
Robert Kern  gmail.com> writes:

> 
> On 2009-06-06 00:34, Ajith Kumar wrote:

> > from numpy import *
> 
> Please ask numpy questions on the numpy mailing list, not here:
> 
>http://www.scipy.org/Mailing_Lists
> 
> > a = arange(1.,10.)
> > b = reshape(a, [3,3])
> > c = linalg.inv(b)
> >
> > And the result is
> >
> > [[ 3.15221191e+15 -6.30442381e+15 3.15221191e+15]
> > [ -6.30442381e+15 1.26088476e+16 -6.30442381e+15]
> > [ 3.15221191e+15 -6.30442381e+15 3.15221191e+15]]

(gibberish)

> 
> You have a very singular matrix (2*a[1] - a[0] == a[2]). You cannot invert it 
> numerically and expect sensible results.

Is raising an exception (as documented
(http://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.inv.html)) not
a "sensible result"? 




-- 
http://mail.python.org/mailman/listinfo/python-list


Re: can it be shorter?

2009-06-06 Thread MRAB

kj wrote:

In  kj  writes:


In <023a8d04$0$20636$c3e8...@news.astraweb.com> Steven D'Aprano 
 writes:



On Sat, 06 Jun 2009 15:59:37 +, kj wrote:



In  "tsangpo"
 writes:


I want to ensure that the url ends with a '/', now I have to do thisa
like below.
url = url + '' if url[-1] == '/' else '/'
Is there a better way?

It's a pity that in python regexes are an "extra", as it were. Otherwise
I'd propose:

url = re.sub("/?$", "/", url)



Thank goodness regexs are an "extra" in Python, because it discourages 
noobs from pulling out the 80 pound sledgehammer of the regex engine to 
crack the peanut of a test-and-concatenate:



I was just responding to the OP's subject line.  Whatever else one
may say about my proposal, it *is* shorter.



But thanks for the tip with timeit.  That looks like a good module
to know.




And actually, if speed is the criterion, then one should also avoid endswith:


from timeit import Timer
min(Timer("if s[-1] != '/': s += '/'", "s = 'abcd/efgh'").repeat())

0.18654584884643555

min(Timer("if not s.endswith('/'): s += '/'", "s = 'abcd/efgh'").repeat())

0.43395113945007324


If there's any chance that the string could be empty (len(s) == 0) then
use:

if s[-1 : ] != '/'
s += '/'
--
http://mail.python.org/mailman/listinfo/python-list


Re: can it be shorter?

2009-06-06 Thread Scott David Daniels

kj wrote:

... And actually, if speed is the criterion, then one should also avoid 
endswith:


from timeit import Timer
min(Timer("if s[-1] != '/': s += '/'", "s = 'abcd/efgh'").repeat())

0.18654584884643555

min(Timer("if not s.endswith('/'): s += '/'", "s = 'abcd/efgh'").repeat())

0.43395113945007324


_but_, try this with s = '', and you are in trouble.
So, try:

if s[-1:] != '/':
s += '/'

To be a trifle more reliable. But, for more normal semantics,
you might prefer either:
if s[-1:] != '/':
s = (s or '.') + '/'
or:
if s and s[-1] != '/':
s += '/'

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: Error in linalg.inv ??

2009-06-06 Thread Robert Kern

On 2009-06-06 17:09, John Machin wrote:

Robert Kern  gmail.com>  writes:


On 2009-06-06 00:34, Ajith Kumar wrote:



from numpy import *

Please ask numpy questions on the numpy mailing list, not here:

http://www.scipy.org/Mailing_Lists


a = arange(1.,10.)
b = reshape(a, [3,3])
c = linalg.inv(b)

And the result is

[[ 3.15221191e+15 -6.30442381e+15 3.15221191e+15]
[ -6.30442381e+15 1.26088476e+16 -6.30442381e+15]
[ 3.15221191e+15 -6.30442381e+15 3.15221191e+15]]


(gibberish)


You have a very singular matrix (2*a[1] - a[0] == a[2]). You cannot invert it
numerically and expect sensible results.


Is raising an exception (as documented
(http://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.inv.html)) not
a "sensible result"?


That's not the way I was using the phrase, but you have a point.

We depend on the underlying LAPACK routine to tell us if the array is singular 
or not. It will inform us if it stopped prematurely because of singularity. In 
this case, I think it happens to complete simply because it is so small and the 
subroutine did not detect the singularity. A (5,5) matrix constructed the same 
way will raise the exception, for example.


However, the condition number of a matrix is not a binary property. A matrix can 
be poorly conditioned but not precisely singular, and the inversion routine will 
give you a correct result (within the limits of floating point arithmetic) 
rather than an exception, but you will still get mostly nonsense out if you try 
to use that result. You still need to apply care in interpreting the result and 
not rely on our throwing an exception even if we could catch all singular inputs.


--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

--
http://mail.python.org/mailman/listinfo/python-list


Re: Is it possible to use multidimensional arrays ?

2009-06-06 Thread bearophileHUGS
pdlem...@earthlink.net, if you are using Psyco and you aren't using
NumPy and you want max speed you may use:

NROWS = 24
NCOLS = 75
screen = array("H", [0]) * (NROWS * NCOLS)

and then you can use items like this:
screen[r * NCOLS + c]
(If NCOLS is equal or a bit lower than a power of 2 it's better to use
a shift).

But in most situations using lists of lists or NumPy is better.

Bye,
bearophile
-- 
http://mail.python.org/mailman/listinfo/python-list


#! to two different pythons?

2009-06-06 Thread mh
I've got a bunch of python programs on linux that start with:

#!/usr/anim/menv/bin/pypix

Now I'm moving some to the mac, where I'm changing that to:

#!/Users/mh/py/bin/python

What's the best way to handle this?  I've got an install script
that rewrites the first line, but if I could eliminate that step I
would be quite happy, since it's the only thing the install step
does.

TIA!!
Mark

-- 
Mark Harrison
Pixar Animation Studios
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: py3k printing generators -- not!

2009-06-06 Thread Terry Reedy

samwyse wrote:

The one thing that's killing me in Python 3000


py3.0 or py3.1, but the 'problem' you complain about has nothing to do 
with those versions in particular.



is that every time I try to print something, it seems like I get  at 0x01BAF508>.


Nor does it have anything is particular to do with generator objects. 
Str(function/class/module/and-many-others) prints similarly. Since 
forever, str(ob) == ob.__str__() == type(ob).__str__(ob).  And what you 
see above is the default template filled in for a particular object.


Built-in concrete collections over-ride the default and return a string 
with their contents because they can do that without harm other than 
possibly producing a very long string.  When the collections are large, 
one might want a custom function that instead formats a string with a 
limited number of examples and the total count.


A 3.0 range object, a virtual collection, could do that too, but since 
there is a regular pattern, it prints a condensed representation. 
Aren't you glad, actually, that range(10) prints as "range(0, 
10)" instead of listing the billion numbers it produces when 
iterated, as you seem to be asking for?



 Googling only found one reference, a
posting elsewhere by one Carl Johnson (aka carlj7,
http://www.artima.com/forums/flat.jsp?forum=106&thread=211200#275387),


A bogus complaint that the constructor for highly specialized class str 
acts differently from those of the general collection classes set, 
tuple, and list.  Str is actually not a collection class in the way that 
set, tuple, list, dict, and many others are.


Terry Jan Reedy

--
http://mail.python.org/mailman/listinfo/python-list


Re: #! to two different pythons?

2009-06-06 Thread Benjamin Peterson
  pixar.com> writes:

> What's the best way to handle this?

#!/usr/bin/env python




-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Error in linalg.inv ??

2009-06-06 Thread Carl Banks
On Jun 6, 3:31 pm, Robert Kern  wrote:
> On 2009-06-06 17:09, John Machin wrote:
> > Robert Kern  gmail.com>  writes:
> >> You have a very singular matrix (2*a[1] - a[0] == a[2]). You cannot invert 
> >> it
> >> numerically and expect sensible results.
>
> > Is raising an exception (as documented
> > (http://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.inv)) 
> > not
> > a "sensible result"?
>
> That's not the way I was using the phrase, but you have a point.
>
> We depend on the underlying LAPACK routine to tell us if the array is singular
> or not.

Perhaps the documentation should be updated to say "Raises LinAlgError
if inv() detects that 'a' a singular matrix".

Anyone with much experience with linear algebra libraries should know
that these routines are shaky when ill-conditioned, but it could help
newbies and computer science experts to be explicit about it.


Carl Banks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Error in linalg.inv ??

2009-06-06 Thread Robert Kern

On 2009-06-06 18:08, Carl Banks wrote:

On Jun 6, 3:31 pm, Robert Kern  wrote:

On 2009-06-06 17:09, John Machin wrote:

Robert Kerngmail.com>writes:

You have a very singular matrix (2*a[1] - a[0] == a[2]). You cannot invert it
numerically and expect sensible results.

Is raising an exception (as documented
(http://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.inv)) not
a "sensible result"?

That's not the way I was using the phrase, but you have a point.

We depend on the underlying LAPACK routine to tell us if the array is singular
or not.


Perhaps the documentation should be updated to say "Raises LinAlgError
if inv() detects that 'a' a singular matrix".

Anyone with much experience with linear algebra libraries should know
that these routines are shaky when ill-conditioned, but it could help
newbies and computer science experts to be explicit about it.


By all means, please do.

http://docs.scipy.org/numpy/Front%20Page/

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

--
http://mail.python.org/mailman/listinfo/python-list


Re: Odd closure issue for generators

2009-06-06 Thread Aahz
In article ,
Terry Reedy   wrote:
>
>(1) Calling the first and rest methods 'car' and 'cdr' convinces me that 
>schemers really do not want scheme to be popular, but prefer it to 
>remain a small cult language.

What, you don't get a warm, fuzzy feeling from saying, "Today is the car
of the cdr of your life"?
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"If you don't know what your program is supposed to do, you'd better not
start writing it."  --Dijkstra
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: #! to two different pythons?

2009-06-06 Thread mh
Benjamin Peterson  wrote:
> #!/usr/bin/env python

But how can I handle this with two differently named pythons?

#!/usr/anim/menv/bin/pypix
#!/Users/mh/py/bin/python

Thanks!
Mark

-- 
Mark Harrison
Pixar Animation Studios
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: #! to two different pythons?

2009-06-06 Thread Cameron Simpson
On 06Jun2009 23:46, m...@pixar.com  wrote:
| Benjamin Peterson  wrote:
| > #!/usr/bin/env python
| 
| But how can I handle this with two differently named pythons?
| 
| #!/usr/anim/menv/bin/pypix
| #!/Users/mh/py/bin/python

Well, it depends _why_ you have a python named "pypix", but two
solutions suggest themselves:

  - Keep the "#!/usr/bin/env python" and then:
  ln -s /usr/anim/menv/bin/pypix /usr/local/bin/python
Presumes no other python, and /usr/local/bin might become ~/bin
or something like that.

  - Write a small wrapper shell script and use:
  #!/usr/bin/env my-wrapper-script

Regarding the first approach, on a personal basis I have two bin
directories: ~/bin and ~/bin-local on the machines I use. The former it
copied from my home account and is always the same - a bunch of useful
scripts. The latter is per-host customisation and is largely symlinks
to preferred versions of apps, apps installed out of the main paths,
and host-specific wrapper scripts.

Cheers,
-- 
Cameron Simpson  DoD#743
http://www.cskk.ezoshosting.com/cs/

Soon, Grasshopper, all will understand. And dispair.  The government that
defines what is good for you, will also dictate what is bad.
- Curt Howland  "Ace"   DoD#0663  EGFC#011  EFF#569
  howl...@priss.com   '82 V45 Sabre
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: #! to two different pythons?

2009-06-06 Thread mh
Cameron Simpson  wrote:
>   - Keep the "#!/usr/bin/env python" and then:
>   ln -s /usr/anim/menv/bin/pypix /usr/local/bin/python

Ah, that's a good idea.  The pypix is a company-wide maintained
python, but ln -s python pypix on my local Mac laptop python
install  makes the env work quite nicely.

The ~/bin and ~/bin-local is a great idea too... I've symlinked
to my dropbox account for bonus convenience.

thanks!!!
Mark
-- 
Mark Harrison
Pixar Animation Studios
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Making the case for repeat

2009-06-06 Thread Tim Roberts
Steven D'Aprano  wrote:
>
>Why is it that it's (almost) always newbies with about five minutes' 
>worth of experience with Python that come up with these grandiose plans 
>to replace entire modules with a single function?

Well, many great innovations in history have come from people who did not
have enough experience to know that what they were doing was impossible...
-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: multi-core software

2009-06-06 Thread Jeff M.
On Jun 6, 9:58 pm, Paul Rubin  wrote:
> George Neuner  writes:
> > Even the lightest weight
> > user space ("green") threads need a few hundred instructions, minimum,
> > to amortize the cost of context switching.
>
> I thought the definition of green threads was that multiplexing them
> doesn't require context switches.

There's always a context switch. It's just whether or not you are
switching in/out a virtual stack and registers for the context or the
hardware stack/registers.

Jeff M.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Making the case for repeat

2009-06-06 Thread Terry Reedy

Tim Roberts wrote:

Steven D'Aprano  wrote:
Why is it that it's (almost) always newbies with about five minutes' 
worth of experience with Python that come up with these grandiose plans 
to replace entire modules with a single function?


Well, many great innovations in history have come from people who did not
have enough experience to know that what they were doing was impossible...


Along with many of the great follies and frauds ;-)

--
http://mail.python.org/mailman/listinfo/python-list


Re: Making the case for repeat

2009-06-06 Thread Steven D'Aprano
On Sat, 06 Jun 2009 19:32:31 -0700, Tim Roberts wrote:

> Steven D'Aprano  wrote:
>>
>>Why is it that it's (almost) always newbies with about five minutes'
>>worth of experience with Python that come up with these grandiose plans
>>to replace entire modules with a single function?
> 
> Well, many great innovations in history have come from people who did
> not have enough experience to know that what they were doing was
> impossible...

So the old saw goes. Like most old saws, it's a load of codswallop. If 
you scratch beneath the surface, you soon discover that the people who 
supposedly "didn't know it was impossible" actually had a great deal of 
experience of what was and wasn't possible in the subject at hand. They 
might have been outsiders, but they were *knowledgeable* outsiders.

e.g. the Wright Brothers weren't lone inventors working at a time when 
everyone knew powered flight was impossible, they were experienced 
engineers and glider-pilots who paid a lot of attention to research done 
by their many competitors.



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list