Python-URL! - weekly Python news and links (Nov 16)

2009-11-17 Thread Gabriel Genellina
QOTW:  The promise is 'batteries included.'  Nobody promised you a
nickel metal hydride battery that you can use as a replacement in your
Prius. - Stephen J. Turnbull
http://mail.python.org/pipermail/python-dev/2009-November/094014.html


Google's new language, Go, has similarities to Python:
http://groups.google.com/group/comp.lang.python/t/c1c4a8fe741c689a/

Is Python scalable enough for Google (or any other huge application)?
http://groups.google.com/group/comp.lang.python/t/ceef2ae6b4472b61/

Is it possible to get the physical memory address of a variable in python?
http://groups.google.com/group/comp.lang.python/t/969462b9a3b452/

Serialize objects as Python code:
http://groups.google.com/group/comp.lang.python/t/98536e7910e65256/

Overriding __getitem__ for a subclass of dict:
http://groups.google.com/group/comp.lang.python/t/d9b822119fc0917c/

Ensure a script is run with a certain range of Python versions:
http://groups.google.com/group/comp.lang.python/t/d21a492be99c90e8/

How to install applications when Python is not already present:
http://groups.google.com/group/comp.lang.python/t/495794a40d18fbc/

Turtle graphics are just for kids - or not? Its advantages when teaching
Python programming:
http://groups.google.com/group/comp.lang.python/t/d55388b0fdd9ed2f/

Using dynamic property names:
http://groups.google.com/group/comp.lang.python/t/f7b8829c97dcc3f9/

How can a module react differently when imported from one place or another?
http://groups.google.com/group/comp.lang.python/t/da162dc08f1c3550/

Sharing distributed objects between Python and C++:
http://groups.google.com/group/comp.lang.python/t/5a567a1a180511eb/

Beware: threads + import don't mix well!
http://groups.google.com/group/comp.lang.python/t/a60c83590a016528/

locals() and frame.f_locals return old data:
http://groups.google.com/group/comp.lang.python/t/fa17941218c6e89e/

Instantiate classes using names from the command line:
http://groups.google.com/group/comp.lang.python/t/d597a1a42b88c0d1/

New syntax proposal: if some_expression as x: do_something_with(x)
http://groups.google.com/group/comp.lang.python/t/55e7578903747dc4/



Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily

Just beginning with Python?  This page is a great place to start:
http://wiki.python.org/moin/BeginnersGuide/Programmers

The Python Papers aims to publish the efforts of Python enthusiasts:
http://pythonpapers.org/
The Python Magazine is a technical monthly devoted to Python:
http://pythonmagazine.com

Readers have recommended the Planet site:
http://planet.python.org

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.
http://groups.google.com/group/comp.lang.python.announce/topics

Python411 indexes podcasts ... to help people learn Python ...
Updates appear more-than-weekly:
http://www.awaretek.com/python/index.html

The Python Package Index catalogues packages.
http://www.python.org/pypi/

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
responsibility for Python's development and maintenance.
http://www.python.org/psf/
Among the ways you can support PSF is with a donation.
http://www.python.org/psf/donations/

The Summary of Python Tracker Issues is an automatically generated
report summarizing new bugs, closed ones, and patch submissions. 

http://search.gmane.org/?author=status%40bugs.python.orggroup=gmane.comp.python.develsort=date

Although unmaintained since 2002, the Cetus collection of Python
hyperlinks retains a few gems.
http://www.cetus-links.org/oo_python.html

Python FAQTS
http://python.faqts.com/

The Cookbook is a collaborative effort to capture useful and
interesting recipes.

Re: faster than list.extend()

2009-11-17 Thread Hyunchul Kim
Thank Tim, Raymond, and all.

In my test, Tim's t1 was fastest and Raymond's triple3 is very near to Tim's
t1.
Anyway both of them took only 6~7% time of my original .extend() version.

I think that following n_ple() is a good generalized function that was 1~3%
slower than t1() and triple3() for triple.

*
from itertools import *
def n_ple(inputlist, n):
chain_from_iterable = chain.from_iterable; izip = izip
return chain_from_iterable(izip(*[inputlist]*n))
*

 def t2(i):
   r = range(3)
   return (x for x in i for _ in r)
 def t2_1(i):
   r = range(3)
   return [x for x in i for _ in r]

I didn't know that list(t2(inputlist)) is much faster than t2_1(inputlist),
it's gonna be a helpful tip for me.

Thank you all.

Hyunchul


On Tue, Nov 17, 2009 at 7:55 AM, Tim Chase python.l...@tim.thechases.comwrote:

 Hyunchul Kim wrote:

 Hi, all.

 I want to improve speed of following simple function.
 Any suggestion?

 **
 def triple(inputlist):
  results = []
  for x in inputlist:
results.extend([x,x,x])
  return results
 **


 Several ways occur to me:

  def t1(i):
for x in i:
  yield x
  yield x
  yield x

  def t2(i):
r = range(3)
return (x for x in i for _ in r)


 I prefer to return generators in case the input is large, but in both
 cases, you can just wrap it in list() like

  list(t1(inputlist))

 or in t2(), you can just change it to use

return [x for x in i for _ in r]

 -tkc





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


Re: Python Go

2009-11-17 Thread Donn
On Saturday 14 November 2009 22:23:40 Paul Rubin wrote:
 they'll have to call it Go2
Lol.
Or we could fork it and call it Gosub ... and never return!

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


Re: Get attribute this way

2009-11-17 Thread Diez B. Roggisch

King schrieb:

eval can solve this problem right away but I am concerned about
security issues. If not eval could you suggest something more
efficient way. It won't be a big deal to change the format as
application is still at development stage?


If you don't want to use eval (which is a good thing not to want), you'd 
end up (as Chris already told you) writing your own parser for python 
subexpressions. Which is laborous.


Or you create a XML-representation of these expressions, which saves you 
the parser, but not the evaluator, and bloats the XML. It could look 
like this:


Connection
   node name=node1
 attribute name=gradient
   attribute name=colors
 item index=0 kind=int
   item index=1 kind=int/
 ... # close them all
   /node
   node ... # and the destination

/Connection

Is this *really* all worth doing, or can't you just overcome your 
preconceptions - and use pickle, as it has been suggested to you before? 
Potentially with __getstate__/__setstate__ overridden for specific objects.



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


Re: Get attribute this way

2009-11-17 Thread Carl Banks
On Nov 16, 11:37 pm, King animator...@gmail.com wrote:
 eval can solve this problem right away but I am concerned about
 security issues. If not eval could you suggest something more
 efficient way. It won't be a big deal to change the format as
 application is still at development stage?


You are stuck parsing it yourself, then.  Apart from eval, there's not
a really handy way to do what you want.

Here's something that might help you get started; it is not by any
means a final solution.

First of all, for simplicity's sake, change the subscript notation to
attribute notation; that is, change gradient.positions[0] to
gradient.positions.0.  Then you can find the object you're seeking
like this (untested):


obj = self
while '.' in attr:
next,attr = attr.split('.',1)
try:
index = int(next)
except TypeError:
obj = getattr(obj,next)
else:
obj = obj[index]


Notice what's happening: we're splitting the string at the dot and
using getattr to descend further into the structure.  Also, if the
part of the string before the dot is an integer, we index instead.

Hopefully this example will help you understand what doing this
entails and what you have to do to get it work.


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


Re: ZipFile - file adding API incomplete?

2009-11-17 Thread Diez B. Roggisch

Glenn Maynard schrieb:

I want to do something fairly simple: read files from one ZIP and add
them to another, so I can remove and replace files.  This led me to a
couple things that seem to be missing from the API.

The simple approach would be to open each file in the source ZIP, and
hand it off to newzip.write().  There's a missing piece, though:
there's no API that lets me pass in a file-like object and a ZipInfo,
to preserve metadata.  zip.write() only takes the filename and
compression method, not a ZipInfo; writestr takes a ZipInfo but only
accepts a string, not a file.  Is there an API call I'm missing?
(This seems like the fundamental API for adding files, that write and
writestr should be calling.)

The correct approach is to copy the data directly, so it's not
recompressed.  This would need two new API calls: rawopen(), acting
like open() but returning a direct file slice and not decompressing
data; and rawwrite(zinfo, file), to pass in pre-compressed data, where
the compression method in zinfo matches the compression type used.

I was surprised that I couldn't find the former.  The latter is an
advanced one, important for implementing any tool that modifies large
ZIPs.  Short-term, at least, I'll probably implement these externally.


No idea why the write doesn't accept an open file - OTOH, as passing a 
string is just



  writestr(info, in_file.read())


I don't think that's *that* much of an inconvenience..

And regarding your second idea: can that really work? Intuitively, I 
would have thought that compression is adaptive, and based on prior 
additions to the file. I might be wrong with this though.


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


Accessing a Web server --- how?

2009-11-17 Thread Virgil Stokes

If one goes to the following URL:
http://www.nordea.se/Privat/Spara%2boch%2bplacera/Strukturerade%2bprodukter/Aktieobligation%2bNr%2b99%2bEuropa%2bAlfa/973822.html

it contains a link (click on Current courses NBD AT99 3113A) to:
http://service.nordea.com/nordea-openpages/six.action?target=/nordea.public/bond/nordeabond.pagemagic=%28cc+%28detail+%28tsid+310746%29%29%29;

and if you now click on the tab labeled history and compare this will 
take you to:

http://service.nordea.com/nordea-openpages/six.action?target=/nordea.public/bond/nordeabond.pagemagic=%28cc+%28detail+%28tsid+310746%29+%28view+hist%29%29%29;

Finally...This is where I would like to connect to the data on a daily 
basis or to gather data over different time intervals. I believe that if 
I can get some help on this, then I will be able to customize the code 
as needed for my own purposes.


It should be clear that this is financial data on a fond managed by 
Nordea Bank AB. Nordea is one of the largest banks in Scandinavia.


Note, that I do have some experience with Python (2.6 mainly), and find 
it a very useful and powerful language. However, I have no experience 
with it in the area of Web services. Any suggestions/comments on how to 
set up this financial data service project would be greatly appreciated, 
and I would be glad to share this project with any interested parties.


Note, I posted a similar message to the list pywebsvcs; but, received no 
responses.

-- V. Stokes


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


TODO and FIXME tags

2009-11-17 Thread Yasser Almeida Hernández

Hi all..
Sorry if this question sound elemental.
How is the sintaxis for set the TODO and FIXME tags...?

Thanks

--
Lic. Yasser Almeida Hernández
Center of Molecular Inmunology (CIM)
Nanobiology Group
P.O.Box 16040, Havana, Cuba
Phone: (537) 271-7933, ext. 221


Correo FENHI



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


Re: A different take on finding primes

2009-11-17 Thread Tobiah

 Let me
 be clear, given 2min, how many primes can you find, they need not be in
 order or consecutive.

Do they have to go from low to high?   :( )
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Logic operators with in statement

2009-11-17 Thread Richard Brodie

Mr.SpOOn mr.spoo...@gmail.com wrote in message 
news:mailman.492.1258380560.2873.python-l...@python.org...

 In [13]: ('b3' and '5') in l or ('3' and 'b3') in l
 Out[13]: True

For anything more than the simplest cases, you might want use sets.

That might be the correct data type from the start, depending on
whether the ordering is important anywhere. 


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


Please recommend the books that might be helpful to learn Python :)

2009-11-17 Thread Psi
as the subject says,

any books?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Accessing a Web server --- how?

2009-11-17 Thread Chris Rebert
On Mon, Nov 16, 2009 at 2:14 AM, Virgil Stokes v...@it.uu.se wrote:
 If one goes to the following URL:
 http://www.nordea.se/Privat/Spara%2boch%2bplacera/Strukturerade%2bprodukter/Aktieobligation%2bNr%2b99%2bEuropa%2bAlfa/973822.html

 it contains a link (click on Current courses NBD AT99 3113A) to:
 http://service.nordea.com/nordea-openpages/six.action?target=/nordea.public/bond/nordeabond.pagemagic=%28cc+%28detail+%28tsid+310746%29%29%29;

 and if you now click on the tab labeled history and compare this will take
 you to:
 http://service.nordea.com/nordea-openpages/six.action?target=/nordea.public/bond/nordeabond.pagemagic=%28cc+%28detail+%28tsid+310746%29+%28view+hist%29%29%29;

 Finally...This is where I would like to connect to the data on a daily
 basis or to gather data over different time intervals. I believe that if I
 can get some help on this, then I will be able to customize the code as
 needed for my own purposes.

HTML parsing: http://www.crummy.com/software/BeautifulSoup/
Downloading webpages: http://docs.python.org/library/urllib.html#urllib.urlopen

BeautifulSoup is excellently documented:
http://www.crummy.com/software/BeautifulSoup/documentation.html
You'll probably be interested in the sections on searching and
navigating the parse tree.

Cheers,
Chris
--
IANAL and do not condone violating website TOSes
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TODO and FIXME tags

2009-11-17 Thread Chris Rebert
2009/11/16 Yasser Almeida Hernández pedro...@fenhi.uh.cu:
 Hi all..
 Sorry if this question sound elemental.
 How is the sintaxis for set the TODO and FIXME tags...?

There is no special syntax for those. Some people use them in
comments, but it's just a convention.

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Create object from variable indirect reference?

2009-11-17 Thread jhermann
On 10 Nov., 17:03, NickC reply...@works.fine.invalid wrote:
 Many thanks for the replies.  getattr() works great:

You can get a little more versatile and even specify the location of
the name (i.e. the module / package name) without pre-importing it,
like this...

def importName(modulename, name=None):
 Import identifier C{name} from module C{modulename}.

If name is omitted, modulename must contain the name after the
module path, delimited by a colon.

@param modulename: Fully qualified module name, e.g. C{x.y.z}.
@param name: Name to import from C{modulename}.
@return: Requested object.
@rtype: object

if name is None:
modulename, name = modulename.split(':', 1)
module = __import__(modulename, globals(), {}, [name])
return getattr(module, name)

print importName(socket:gethostname)()


This is especially useful if you want to specify factory classes or
the like in a non-python config file. The syntax is the same as that
of setuptools entry points.

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


Re: TODO and FIXME tags

2009-11-17 Thread Ben Finney
Chris Rebert c...@rebertia.com writes:

 2009/11/16 Yasser Almeida Hernández pedro...@fenhi.uh.cu:
  How is the sintaxis for set the TODO and FIXME tags...?

 There is no special syntax for those. Some people use them in
 comments, but it's just a convention.

This is true. However, the convention is fairly well established, and
many text editor default configurations will highlight the strings
‘TODO’, ‘FIXME’, and others wherever they appear in comments.

There's no widely-followed “syntax” for this convention, though.

-- 
 \ “I must say that I find television very educational. The minute |
  `\   somebody turns it on, I go to the library and read a book.” |
_o__)—Groucho Marx |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Get attribute this way

2009-11-17 Thread Bruno Desthuilliers

King a écrit :

Python's getattr, setattr and __getattribute__ commands


s/commands/functions/


works fine
with python types.
For example:
print o.__getattribute__(name)


A very few corner cases set aside - the main one being inside a custom 
__getattribute__ method -, you should not directly access 
__getattribute__ (nor most __magic_methods__ FWIW).



print getattr(o, name)
This is the easiest way to get an attribute using a string.

In my case the Node class load/creates all the attributes from a xml
file.
Example
Input name=position type=float value=0.5/
Input name=color type=color value=0,0,0/

There are certain atrributes of compound type.


There's no compound type in Python. There are only objects, objects 
and objects.



Example:
# Array of colors, Here we are referring first color and second element
(green)
self.gradient.colors[0][1] = 0.5
# Array of floats, referring first element
self.gradient.positions[0] = 1.0

Color, color array and floats are all custom classes.

Now question is how to get these compound attributes using string as
we do with default singular attributes.
Example:
getattr(o, gradient.colors[0][1] )


You can't (at least OOTB). the expression:

  gradient.colors[0][1]

is a shortcut for:

  colors = gradients.__getattribute__(color)
  colors_0 = colors.__getitem__(0)
  colors_0_1 = colors_0.__getitem__(1)

You can of course do something like

  g = getattr(o, gradient)
  c = getattr(g, colors)
  # etc...

but I guess this is not what you're after.


I need this to save the data of nodes-attributes into a custom xml
format,  when loading this data back, I create the node first and then
setup values from the saved xml file.


I really don't think you need anything like this to serialize / 
unserialize your objects (whatever the format FWIW).  You should really 
google for +python +serialize +XML, I bet you'd find at least a couple 
helpful articles on that topic.

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


Re: overriding __getitem__ for a subclass of dict

2009-11-17 Thread Steve Howell
On Nov 16, 10:11 pm, Carl Banks pavlovevide...@gmail.com wrote:
 On Nov 16, 10:32 am, Steve Howell showel...@yahoo.com wrote:



  On Nov 16, 2:35 am, Carl Banks pavlovevide...@gmail.com wrote:

   On Nov 15, 2:52 pm, Steve Howell showel...@yahoo.com wrote:

Does anybody have any links that points to the rationale for ignoring
instance definitions of __getitem__ when new-style classes are
involved?  I assume it has something to do with performance or
protecting us from our own mistakes?

   Not important enough to justify complexity of implementation.

   I doubt they would have left if out of new-style classes if it had
   been straightforward to implement (if for no other reason than to
   retain backwards compatibility), but it wasn't.  The way attribute
   lookups work meant it would have required all kinds of double lookups
   and edge cases.  Some regarded it as dubious to begin with.  And it's
   easily worked around by simply having __getitem__ call another method,
   as you've seen.  Given all this it made better sense to just leave it
   out of new-style classes.

  Actually, the __getitem__ workaround that I proposed earlier only
  works on subclasses of dict, not dict themselves.  So given a pure
  dictionary object, it is impossible to hook into attribute lookups
  after instantiation in debugging/tracing code.  I know it's not a
  super common thing to do, but it is a legitimate use case from my
  perspective.  But I understand the tradeoffs.  They seem kind of 20th
  century to me, but with Moore's Law declining and all, maybe it's a
  bad time to bring up the flexibility trumps performance
  argument. ;)

 It's not performance, it's code complexity.

 Implementing this would have to added a lot of extra code to the
 Python codebase--more than you seem to realize--all in support of a
 dubious behavior.  This would have meant more opporunities for bugs,
 and an increased maintainence burden.

  The backward compatibility argument also seems a little
  dubious, because if anybody *had* put __getitem__ on a dictionary
  instance before, it would have already been broken code, and if they
  hadn't done it, there would be no semantic change, just a performance
  hit, albeit a pervasive one.

 Wrong.  It's only dubious from your narrow mindset that focuses on
 your own problem and ignores the greater problem.  When new-style
 classes were introduced, they made a decision that magic methods would
 no longer work when defined on any instance.  It affected a *lot* more
 than just your dictionary use-case.

 So please spare me any suggestions that the change didn't carry a
 significant backwards incompatibility.  It did, and they made the
 change anyway.  That should tell you how difficult it would have been
 to implement.


I am sorry having for a narrow mindset, and I apologize for not
seeming to realize how much extra code would go into the Python
codebase to allow me to hook into attribute lookups after
instantiation in debugging/tracing code.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: faster than list.extend()

2009-11-17 Thread Peter Otten
Gabriel Genellina wrote:

 En Mon, 16 Nov 2009 19:30:27 -0300, Hyunchul Kim
 hyunchul.mail...@gmail.com escribió:
 
 I want to improve speed of following simple function.
 Any suggestion?

 **
 def triple(inputlist):
   results = []
   for x in inputlist:
 results.extend([x,x,x])
   return results
 **
 
 These are my best attempts:
 
 def triple3(inputlist):
 results = []
 append = results.append
 for x in inputlist:
   append(x); append(x); append(x)
 return results
 
 def triple4(inputlist, _three=xrange(3)):
return [x for x in inputlist for _ in _three]
 
 For a 400-items list, triple3 is 40% faster and triple4 25% faster than
 yours.

[I didn't see the original post]

If inputlist is actually a list or tuple the following should beat them all:

def triple_repeat(items):
result = [None] * (3*len(items))
result[::3] = result[1::3] = result[2::3] = items
return result

For small n the generalization should still be quite competitive:

def n_repeat(items, n):
items = tuple(items)
result = [None]*(len(items) * n)
for offset in range(n):
result[offset::n] = items
return result

Some measurements:

$ cat extend.py
from itertools import *

def triple_repeat(items):
result = [None] * (3*len(items))
result[::3] = result[1::3] = result[2::3] = items
return result

def n_repeat(items, n):
items = tuple(items)
result = [None]*(len(items) * n)
for offset in range(n):
result[offset::n] = items
return result

def t1(i):
for x in i:
yield x
yield x
yield x

def triple3(inputlist, list=list, chain_from_iterable=chain.from_iterable, 
izip=izip):
return list(chain_from_iterable(izip(inputlist, inputlist, inputlist)))

data = range(1000)


$ python -m timeit -s 'from extend import triple_repeat, data'  
'triple_repeat(data)'
1 loops, best of 3: 52.4 usec per loop  
 
$ python -m timeit -s 'from extend import n_repeat, data'  'n_repeat(data, 3)'
1 loops, best of 3: 60.7 usec per loop
$ python -m timeit -s 'from extend import t1, data'  'list(t1(data))'
1000 loops, best of 3: 337 usec per loop
$ python -m timeit -s 'from extend import triple3, data'  'triple3(data)'
1000 loops, best of 3: 231 usec per loop

Peter

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


YIELD_VALUE Byte Code

2009-11-17 Thread Andreas Löscher
Hi,
I am not sure if this is the right newsgroup, so if not don't hesitate
to tell me.

I am developed a Python to C compiler, so that Byte Code files
automatically can be translated into C Extension Modules. (And it works
pretty well -- http://www.coremountains.com/products/bytecoat/)

While developing, I found something strange concerning the YIELD_VALUE
OpCode.

Since Python Version 2.5 it behaves the following:
1. pop yield value from stack and return it to
a former gen_send_ex() call from Objects/genobject.c

2. push the yield value on the stack in gen_send_ex() and return
it

3. when the generator is executed again, the yield value is
'poped' from the stack again with the POP_TOP opcode

Now I found that a little strange:
1. why is the value removed from the stack, than pushed on the 
stack to remove it finally again? the combination of 
YIELD_VALUE and TOP_POP seems hard coded in compile.c
which means that a TOP_POP follows every YIELD_VALUE 
TOP_POP

2. If the semantic of the YIELD_VALUE OpCode has changed, why
is this reached by using another function? Such thing 
should be done in the OpCode.

(e.a.: instead of retval = POP() 
-- retval = TOP(); Py_INCREF(retval); )


I am a little confused about this.

Best,
Andreas

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


Re: Unexpected python exception

2009-11-17 Thread Andreas Löscher
Hi,
unfortunatley I cannot reproduce your error. Which Python Version do you
use?

The expected case in this scenario is that the exception is thrown, as
you import os in A() where it is stored in the local namespace of the
function.

I tested it with Python 2.4, 2.5 and 2.6 and in both cases an exception
is thrown.

Best,
Andreas

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


Re: Unexpected python exception

2009-11-17 Thread Andreas Löscher
Python searches for Variables not only in local or global scoop but also
in __builtins__. If you do something like __builtins__.os = os, than
this variable should be accessible global. 

If you then write something like:
def B():
os.stat(/)
import os

Python recognises on compile time, that os is a local variable in B and
allocates memory for it. All reading or writing now goes to the local
variable and not the one in __builtins__. And the local variable has
never been assigned to a value and an Exception is thrown.

Best

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


Re: TODO and FIXME tags

2009-11-17 Thread Martin P. Hellwig

Ben Finney wrote:

Chris Rebert c...@rebertia.com writes:


2009/11/16 Yasser Almeida Hernández pedro...@fenhi.uh.cu:

How is the sintaxis for set the TODO and FIXME tags...?

There is no special syntax for those. Some people use them in
comments, but it's just a convention.


This is true. However, the convention is fairly well established, and
many text editor default configurations will highlight the strings
‘TODO’, ‘FIXME’, and others wherever they appear in comments.

There's no widely-followed “syntax” for this convention, though.



Except for _not_ doing what is suggested in those comments, which 
appears to be the biggest convention :-)


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


Re: Calling Python functions from Excel

2009-11-17 Thread Chris Withers

Cannonbiker wrote:

Hi,
unfortunately is my question about server COM (win32com)
http://groups.google.com/group/comp.lang.python/browse_thread/thread/ee804cec7f58c6a7#
without answer.

Please I need Calling Python functions from Excel and receive result
back in Excel. Can me somebody advise simplest solution please? I am
more VBA programmer than Python.


Try http://code.google.com/p/pyinex/

cheers,

Chris

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


Re: Logic operators with in statement

2009-11-17 Thread Mr.SpOOn
Thanks everybody for all the answers and explanations.

In the end maybe it is simpler if I use sets for these tests.

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


Re: Code for finding the 1000th prime

2009-11-17 Thread Stefan Behnel
Robert P. J. Day, 15.11.2009 15:44:
 On Sun, 15 Nov 2009, mrholtsr wrote:
 
 I am absolutely new to python and barely past beginner in programming.
 Also I am not a mathematician. Can some one give me pointers for
 finding the 1000th. prime for a course I am taking over the internet
 on Introduction to Computer Science and Programming. Thanks, Ray
 
   it's 7919.

Now, all that's left to do is write a prime number generator (a random
number generator will do, too, but writing a good one isn't easy), run it
repeatedly in a loop, and check if the returned number is 7919. Once it
compares equal, you can print the result and you're done.

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


Re: python simply not scaleable enough for google?

2009-11-17 Thread Aaron Watters

 I don't think Python and Go address the same set of programmer
 desires.  For example, Go has a static type system.  Some programmers
 find static type systems to be useless or undesirable.  Others find
 them extremely helpful and want to use them them.  If you're a
 programmer who wants a static type system, you'll probably prefer Go
 to Python, and vice versa.  That has nothing to do with implementation
 speed or development expenditures.  If Google spent a million dollars
 adding static types to Python, it wouldn't be Python any more.

... and I still have an issue with the whole Python is slow
meme.  The reason NASA doesn't build a faster Python is because
Python *when augmented with FORTRAN libraries that have been
tested and optimized for decades and are worth billions of dollars
and don't need to be rewritten* is very fast.

The reason they don't replace the Python drivers with Java is
because that would be very difficult and just stupid and I'd be
willing to bet that when they were done the result would actually
be *slower* especially when you consider things like process
start-up time.

And when someone implements a Mercurial replacement in GO (or C#
or Java) which is faster and more useful than Mercurial, I'll
be very impressed.  Let me know when it happens (but I'm not
holding my breath).

By the way if it hasn't happened and if he isn't afraid
of public speaking someone should invite Matt Mackall
to give a Python conference keynote.  Or how about
Bram Cohen for that matter...

   -- Aaron Watters http://listtree.appspot.com/

===
if you want a friend, get a dog.  -Truman




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


Re: python gui builders

2009-11-17 Thread me

Read the OP. No, read it again.

sturlamolden wrote:

On 16 Nov, 11:39, sturlamolden sturlamol...@yahoo.no wrote:


If you are fine with Microsoft only, you can use Windows Forms with MS
Visual Studio and IronPython.


I also forgot to mention:

If you can restrict yourself to Windows, you can always use Visual
Basic or Borland Delphi with pywin32. Either expose your GUI as an
ActiveX to pywin32 (you have e.g. an MFC binding) or expose your
Python as an ActiveX to VB/Delphi. The same approach should work (with
a little bit more work) for C# and VB.NET.

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


XML root node attributes

2009-11-17 Thread Slafs
Hi

I'm little confused about adding attributes to the root node when
creating an XML document.
Can I do this using minidom or something else.
I can't find anything that would fit my needs.

i would like to have something like this:
?xml ... ?
root a=v b=v2 c=v3
d ...  /d
   
/root

Please help.

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


Re: python simply not scaleable enough for google?

2009-11-17 Thread David Cournapeau
On Tue, Nov 17, 2009 at 10:48 PM, Aaron Watters aaron.watt...@gmail.com wrote:

 I don't think Python and Go address the same set of programmer
 desires.  For example, Go has a static type system.  Some programmers
 find static type systems to be useless or undesirable.  Others find
 them extremely helpful and want to use them them.  If you're a
 programmer who wants a static type system, you'll probably prefer Go
 to Python, and vice versa.  That has nothing to do with implementation
 speed or development expenditures.  If Google spent a million dollars
 adding static types to Python, it wouldn't be Python any more.

 ... and I still have an issue with the whole Python is slow
 meme.  The reason NASA doesn't build a faster Python is because
 Python *when augmented with FORTRAN libraries that have been
 tested and optimized for decades and are worth billions of dollars
 and don't need to be rewritten* is very fast.

It is a bit odd to dismiss python is slow by saying that you can
extend it with fortran. One of the most significant point of python
IMO is its readability, even for people not familiar with it, and
that's important when doing scientific work. Relying on a lot of
compiled libraries goes against it.

I think that python with its scientific extensions is a fantastic
tool, but I would certainly not mind if it were ten times faster. In
particular, the significant cost of function calls makes it quickly
unusable for code which cannot be easily vectorized - we have to
resort to using C, etc... to circumvent this ATM.

Another point which has not been mentioned much, maybe because it is
obvious: it seems that it is possible to makes high level languages
quite fast, but doing so while keeping memory usage low is very
difficult. Incidentally, the same tradeoff appears when working with
vectorized code in numpy/scipy.

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


Re: ZipFile - file adding API incomplete?

2009-11-17 Thread Dave Angel



Diez B. Roggisch wrote:
div class=moz-text-flowed style=font-family: -moz-fixedGlenn 
Maynard schrieb:

I want to do something fairly simple: read files from one ZIP and add
them to another, so I can remove and replace files.  This led me to a
couple things that seem to be missing from the API.

snip

The correct approach is to copy the data directly, so it's not
recompressed.  This would need two new API calls: rawopen(), acting
like open() but returning a direct file slice and not decompressing
data; and rawwrite(zinfo, file), to pass in pre-compressed data, where
the compression method in zinfo matches the compression type used.

I was surprised that I couldn't find the former.  The latter is an
advanced one, important for implementing any tool that modifies large
ZIPs.  Short-term, at least, I'll probably implement these externally.


snip

And regarding your second idea: can that really work? Intuitively, I 
would have thought that compression is adaptive, and based on prior 
additions to the file. I might be wrong with this though.



I'm pretty sure that the ZIP format uses independent compression for 
each contained file (member).  You can add and remove members from an 
existing ZIP, and use several different compression methods within the 
same file.  So the adaptive tables start over for each new member.


What isn't so convenient is that the sizes are apparently at the end.  
So if you're trying to unzip over the wire you can't readily do it 
without somehow seeking to the end.  That same feature is a good thing 
when it comes to spanning zip files across multiple disks.


The zip file format is documented on the net, but I haven't read the 
spec in at least 15 years.


DaveA

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


Re: Code for finding the 1000th prime

2009-11-17 Thread Carsten Haese
Stefan Behnel wrote:
 Robert P. J. Day, 15.11.2009 15:44:
 On Sun, 15 Nov 2009, mrholtsr wrote:

 I am absolutely new to python and barely past beginner in programming.
 Also I am not a mathematician. Can some one give me pointers for
 finding the 1000th. prime for a course I am taking over the internet
 on Introduction to Computer Science and Programming. Thanks, Ray
   it's 7919.
 
 Now, all that's left to do is write a prime number generator (a random
 number generator will do, too, but writing a good one isn't easy), run it
 repeatedly in a loop, and check if the returned number is 7919. Once it
 compares equal, you can print the result and you're done.

Just do a brute-force search:

for i in range(1):
if i==7919:
# Found it!
print i

;-)

--
Carsten Haese
http://informixdb.sourceforge.net

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


Re: XML root node attributes

2009-11-17 Thread Stefan Behnel
Slafs, 17.11.2009 15:19:
 I'm little confused about adding attributes to the root node when
 creating an XML document.
 Can I do this using minidom or something else.

Yes, you /can/, but you /should/ use something else.


 I can't find anything that would fit my needs.
 
 i would like to have something like this:
 ?xml ... ?
 root a=v b=v2 c=v3
 d ...  /d

 /root

Use ElementTree:

import xml.etree.ElementTree as ET
root = ET.Element(root, dict(a='v', b='v2', c='v3'))
root.SubElement('d')

print ET.tostring(root)

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


RE: XML root node attributes

2009-11-17 Thread Matt Mitchell



 
---
The information contained in this electronic message and any attached 
document(s) is intended only for the personal and confidential use of the 
designated recipients named above. This message may be confidential. If the 
reader of this message is not the intended recipient, you are hereby notified 
that you have received this document in error, and that any review, 
dissemination, distribution, or copying of this message is strictly prohibited. 
If you have received this communication in error, please notify sender 
immediately by telephone (603) 262-6300 or by electronic mail immediately. 
Thank you.
 
-Original Message-
From: python-list-bounces+mmitchell=transparent@python.org
[mailto:python-list-bounces+mmitchell=transparent@python.org] On
Behalf Of Slafs
Sent: Tuesday, November 17, 2009 9:20 AM
To: python-list@python.org
Subject: XML root node attributes

Hi

I'm little confused about adding attributes to the root node when
creating an XML document.
Can I do this using minidom or something else.
I can't find anything that would fit my needs.

i would like to have something like this:
?xml ... ?
root a=v b=v2 c=v3
d ...  /d
   
/root

Please help.

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


Hi,

I'm sure someone will point out a better way to do it but yes, you can
do it with minidom.

from xml.dom.minidom import Document

doc = Document()

root = doc.createElement('root')
root.setAttribute('a', 'v')
root.setAttribute('b', 'v2')
root.setAttribute('c', '3')
doc.appendChild(root)

d = doc.createElement('d')
root.appendChild(d)

print doc.toprettyxml()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Please recommend the books that might be helpful to learn Python :)

2009-11-17 Thread silvercl
On Nov 17, 7:18 am, Psi kev0...@gmail.com wrote:
 as the subject says,

 any books?

This is one of the good books available on the internet...
http://diveintopython.org/
I myself liked this book very much (to start with).
Also, on the website, on the right-hand-side it mentions about other
books.


--
Silver, Chandrakant.
-- 
http://mail.python.org/mailman/listinfo/python-list


ast manipulation

2009-11-17 Thread Tsize
Hello,

I am hoping for a little help.  I have been playing with the python
ast module and have run into
an issue that I need a little push on.  I would like to be able to
change a specific element in a
specific node in an ast then compile the resulting ast.  Consider the
simplified example below
with its output. In this example I would like a way to change a
specific addition operation.  With the NodeTransformer I see how to
change every addition operator but not how to change a specific one.
I would like this to work on both the 2.6 and 3.1 branches.  Ideally I
would like to read a file, count the instances of an operation of
interest and then use an index to make the
changes.

I am probably missing something simple but I am lost right now.

import ast

class SwitchMinusPlus(ast.NodeTransformer):

def visit_BinOp(self, node):
node = self.generic_visit(node)
if isinstance(node.op, ast.Add):
node.op = ast.Sub()
return node

myfile = open('trivial.py').read()
print myfile
tree = compile(myfile, 'string', 'exec', ast.PyCF_ONLY_AST)
print ast.dump(tree, annotate_fields=False, include_attributes=False)
node = SwitchMinusPlus().visit(ast.parse(myfile))
print ast.dump(node, annotate_fields=False, include_attributes=False)

Which gives the following output:  Note that this code changes the
addition operator to an
subtraction operator at the AST level for every instance.

a = 8
b = 6
c = b + a
d =  c + a
Module([Assign([Name('a', Store())], Num(8)), Assign([Name('b', Store
())], Num(6)),
Assign([Name('c', Store())], BinOp(Name('b', Load()), Add(), Name('a',
Load(,
Assign([Name('d', Store())], BinOp(Name('c', Load()), Add(), Name('a',
Load(])

Module([Assign([Name('a', Store())], Num(8)), Assign([Name('b', Store
())], Num(6)),
Assign([Name('c', Store())], BinOp(Name('b', Load()), Sub(), Name('a',
Load(,
Assign([Name('d', Store())], BinOp(Name('c', Load()), Sub(), Name('a',
Load(])

Thanks in advance,
Thomas
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: overriding __getitem__ for a subclass of dict

2009-11-17 Thread Scott David Daniels

Steve Howell wrote:
...

Eventually, I realized that it was easier to just monkeypatch Django
while I was in test mode to get a more direct hook into the behavior I
was trying to monitor, and then I didn't need to bother with
overriding __getitem__ or creating complicated wrapper objects


Since nobody else has mentioned it, I'd point you at Mock objects:
http://python-mock.sourceforge.net/
for another way to skin the cat that it sounds like has been
biting you.  They are surprisingly useful for exploratory
and regression testing.

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


Re: Accessing a Web server --- how?

2009-11-17 Thread Dave Angel



Virgil Stokes wrote:
div class=moz-text-flowed style=font-family: -moz-fixedIf one 
goes to the following URL:
http://www.nordea.se/Privat/Spara%2boch%2bplacera/Strukturerade%2bprodukter/Aktieobligation%2bNr%2b99%2bEuropa%2bAlfa/973822.html 



it contains a link (click on Current courses NBD AT99 3113A) to:
http://service.nordea.com/nordea-openpages/six.action?target=/nordea.public/bond/nordeabond.pagemagic=%28cc+%28detail+%28tsid+310746%29%29%29; 



and if you now click on the tab labeled history and compare this 
will take you to:
http://service.nordea.com/nordea-openpages/six.action?target=/nordea.public/bond/nordeabond.pagemagic=%28cc+%28detail+%28tsid+310746%29+%28view+hist%29%29%29; 



Finally...This is where I would like to connect to the data on a 
daily basis or to gather data over different time intervals. I believe 
that if I can get some help on this, then I will be able to customize 
the code as needed for my own purposes.


It should be clear that this is financial data on a fond managed by 
Nordea Bank AB. Nordea is one of the largest banks in Scandinavia.


Note, that I do have some experience with Python (2.6 mainly), and 
find it a very useful and powerful language. However, I have no 
experience with it in the area of Web services. Any 
suggestions/comments on how to set up this financial data service 
project would be greatly appreciated, and I would be glad to share 
this project with any interested parties.


Note, I posted a similar message to the list pywebsvcs; but, received 
no responses.


-- V. Stokes


I still say you should contact the bank and see if they have any API or 
interface defined, so you don't have to do web-scraping.


The following text is on the XHTML page for that last link:

table class=tableb3 summary=Kurser för en obligation.
caption class=hideNordea Bank Finland Abp utfärdad av Nordea Bank Finland 
Abp/caption
thead
tr

th  class=alignleft scope=colBörskod/th
th  class=alignright scope=colKöp/th
th  class=alignright scope=colSälj/th
th  class=alignright scope=colSenast/th
th  class=alignright scope=colFörfallodag/th
th  class=alignright scope=colTid/th
/tr
/thead
tbody
tr
td class=alignleftnbsp;NBF AT99 3113A/td

td class=nowrap alignrightnbsp;95,69/td
td class=nowrap alignrightnbsp;97,69/td
td class=nowrap alignrightnbsp;95,69/td
td class=alignrightnbsp;2011-06-03/td
td class=alignrightnbsp;12:33/td
/tr
/tbody
/table



I didn't try it, but you could presumably use urllib2 to download that 
url (prob. to a file, so you can repeat the test often without loading 
the server).  One caution, it did ask to store a cookie, and I know 
nothing about cookie handling in Python.


Several cautions:  I don't know how target= and magic= were derived, or 
whether they'll remain stable for more than a day or so.  So you can 
download this file and figure how to parse it, but you'll probably need 
to also parse the earlier pages, and that could be easier or harder.


This page format is very straightforward.  If you know you're looking 
for NBF AT99, you could look for that particular line, then just parse 
all the td's till the next /tr.   No XML logic needed.  If you don't 
know the NBF string, you could look for  


Börskod  instead.

But the big risk you run is the bank could easily change this format quite 
drastically, at any time.  Those td
elements don't have to be on separate lines, the browser doesn't care.  And the 
class attribute could change
if the CSS also changes correspondingly.  Or they could come up with an 
entirely different way to display the
data.  All they care about is whether it's readable by the human looking at the 
browser page.

Using xml..elementtree would be a good start;  You could build the DOM, look for the table of class 'tableb3', 
and go in from there


But you still run the risk of them changing things.  The class name, for 
example, is just a link to the CSS page which
describes how that class object should be displayed.  If the name is changed at both ends, no change occurs, 
except to your script.



At this point, you need to experiment.  But build a sloppy skeleton 
first, so you don't invest too much time in any one aspect of the 
problem.  Make sure you can cover the corner cases, then fill in the 
tough parts.


I'd say roughly this order:
1.   write code that download the page to a file, given an exact URL.  
For now, keep that code separate, as it'll probably end up

being much more complex, walking through other pages.

2.  parse that page, using a simple for loop that looks for some of the 
key strings mentioned above.


3. Repeat that for a few different URL's, presumably one per bond fund.

4. Make sure the URL's don't go stale over a few days.  If they do, 
you'll have to back up to an earlier link (URL), and parse forward from 
there.



Keep the various pieces in different modules, so that when an assumption 
breaks, you can recode that assumption pretty much independent of the 
others.



HTH
DaveA

--

Re: python gui builders

2009-11-17 Thread Scott David Daniels

me wrote:

I have looked at the Tk stuff that is built into Python - not 
acceptable. 

Such insightful analysis, and it is _so_ helpful in stating your needs.


[a lot of guff about unacceptable things]


What Python gui builder is well supported, does not require me to learn 
another framework/library, and can crank out stuff for multiple platforms ?


Well, let's see.  You want to do gui work without learning things.
Good luck with that.  If you discover how, I'd like to learn tensor
analysis without using symbols or operations more complex than
addition and subtraction.  Maybe your groundwork can help me out
with that.

I must be in a really cranky mood today.

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


Re: Language mavens: Is there a programming with if then else ENDIF syntax?

2009-11-17 Thread sjm
On Nov 16, 12:54 pm, Steve Ferg steve.ferg.bitbuc...@gmail.com
wrote:
snip
 Does anybody know a language with this kind of syntax for
 ifThenElseEndif?

Modern-day COBOL:

IF  some-condition
do-something
ELSE
do-something-else
END-IF.

The period is also meaningful as a statement terminator in COBOL,
so it's not as clean as one might like.

I, too, like the Python way.

Cheers,
  Steve J. Martin
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: New syntax for blocks

2009-11-17 Thread Jonathan Saxton
On Thu, 12 Nov 2009 21:27:31 +0100, Bruno Desthuilliers wrote:

 Congratulations, you just reinvented one of the most infamous source of
 bugs in C, C++, Java, PHP, javascript and quite a few other languages.
 Believe it or not, but not allowing this in Python was a very deliberate
 design choice.

 Oh, but those hundreds of thousands of man-hours lost to bugs caused by 
 assignment-as-an-expression is nothing compared to the dozens of man-
 minutes saved by having one fewer line of code!


 *wink*

And if I ever find the genius who had the brilliant idea of using = to mean 
assignment then I have a particularly nasty dungeon reserved just for him.  
Also a foul-smelling leech-infested swamp for those language designers and 
compiler writers who followed his example.  (Come to think of it, plagiarizing 
a bad idea is probably the worse evil.)


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


Time travel

2009-11-17 Thread Lee Merrill
I'm seeing an anomaly in the python time function on March 9, 2008
(the spring foward time):

 time.mktime((2008, 3, 9, 2, 59, 59, 0, 0, -1))
1205049599.0
 time.mktime((2008, 3, 9, 3, 0, 0, 0, 0, -1))
1205046000.0

Does anyone have an idea as to what might cause a 4000 seconds
backwards jump on March 9th of last year? I would have expected 3600
seconds.

Thanks,
Lee

P.S. A full program demonstrating the question:

#!/usr/bin/env python

import time, datetime

d1 = datetime.datetime(2008, 3, 9, 2, 59, 0).timetuple()
#!/usr/bin/env python

import time, datetime

d1 = datetime.datetime(2008, 3, 9, 2, 59, 0).timetuple()
d2 = datetime.datetime(2008, 3, 9, 3, 0, 0).timetuple()
t1 = time.mktime(d1)
t2 = time.mktime(d2)

print t1, t2
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Code for finding the 1000th prime

2009-11-17 Thread Himanshu
2009/11/15 mrholtsr mrhol...@gmail.com:
 I am absolutely new to python and barely past beginner in programming.
 Also I am not a mathematician. Can some one give me pointers for
 finding the 1000th. prime for a course I am taking over the internet
 on Introduction to Computer Science and Programming. Thanks, Ray
 --
 http://mail.python.org/mailman/listinfo/python-list


Consider skipping such mathematically oriented exercises in an
introductory course on python if targeted to a general audience.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ZipFile - file adding API incomplete?

2009-11-17 Thread Scott David Daniels

Glenn Maynard wrote:

I want to do something fairly simple: read files from one ZIP and add
them to another, so I can remove and replace files.  This led me to a
couple things that seem to be missing from the API.

 zip.write() only takes the filename and
compression method, not a ZipInfo; writestr takes a ZipInfo but only
accepts a string, not a file.  Is there an API call I'm missing?
(This seems like the fundamental API for adding files, that write and
writestr should be calling.)


Simple answer: its not there in the API.

Defining that API correctly is tricky, and fraught with issues about
access to the ZipFile object (from both the same thread and from other
threads) while it is mid-modification.  Nonetheless, a carefully done
API that addresses those issues would be valuable.  If you do spend the
time to get something reliable going, put it someplace public and I
predict it will get use.

The approach I fiddled with was:
* Define a calls to read _portions_ of the raw (compressed,
  encrypted, whatever) data.
* Define a call that locks the ZipFile object and returns a
  write handle for a single new file.  At that point the
  new file doesn't exist, but reading of other portions of
  the zip file are allowed.
* Only on successful close of the write handle is the new
  directory written.
Unfortunately, I never worked very hard at the directory entries,
and I realize that the big flaw in this design is that from the moment 
you start overwriting the existing master directory until you write

a new master at the end, your do not have a valid zip file.

Also note that you'll have to research standards about _exactly_ what
the main header should look like if you use particular features.  My
stuff did bzip compression as well, and about the find which bits
means what was where my process broke down.

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


Re: Time travel

2009-11-17 Thread Lee Merrill
And I can't do arithmetic, it is actually about 3600--never mind!


On Nov 17, 10:37 am, Lee Merrill lee_merr...@yahoo.com wrote:
 I'm seeing an anomaly in the python time function on March 9, 2008
 (the spring foward time):

  time.mktime((2008, 3, 9, 2, 59, 59, 0, 0, -1))
 1205049599.0
  time.mktime((2008, 3, 9, 3, 0, 0, 0, 0, -1))

 1205046000.0

 Does anyone have an idea as to what might cause a 4000 seconds
 backwards jump on March 9th of last year? I would have expected 3600
 seconds.

 Thanks,
 Lee

 P.S. A full program demonstrating the question:

 #!/usr/bin/env python

 import time, datetime

 d1 = datetime.datetime(2008, 3, 9, 2, 59, 0).timetuple()
 #!/usr/bin/env python

 import time, datetime

 d1 = datetime.datetime(2008, 3, 9, 2, 59, 0).timetuple()
 d2 = datetime.datetime(2008, 3, 9, 3, 0, 0).timetuple()
 t1 = time.mktime(d1)
 t2 = time.mktime(d2)

 print t1, t2

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


Re: python simply not scaleable enough for google?

2009-11-17 Thread Paul Boddie
On 17 Nov, 14:48, Aaron Watters aaron.watt...@gmail.com wrote:

 ... and I still have an issue with the whole Python is slow
 meme.  The reason NASA doesn't build a faster Python is because
 Python *when augmented with FORTRAN libraries that have been
 tested and optimized for decades and are worth billions of dollars
 and don't need to be rewritten* is very fast.

That's why I wrote that Python's extensibility using C, C++ and
Fortran [has] helped adoption of the language considerably, and
Python was particularly attractive to early adopters of the language
precisely because of the scripting functionality it could give to
existing applications, but although there are some reasonable
solutions for writing bottlenecks of a system in lower-level
programming languages, it can be awkward if those bottlenecks aren't
self-contained components or if the performance issues permeate the
entire system.

[...]

 And when someone implements a Mercurial replacement in GO (or C#
 or Java) which is faster and more useful than Mercurial, I'll
 be very impressed.  Let me know when it happens (but I'm not
 holding my breath).

Mercurial is a great example of a Python-based tool with good
performance. However, it's still interesting to consider why the
implementers chose to rewrite precisely those parts that are
implemented using C. I'm sure many people have had the experience of
looking at a piece of code and being quite certain of what that code
does, and yet wondering why it's so inefficient in vanilla Python.
It's exactly this kind of issue that has never really been answered
convincingly, other than claims that Python must be that dynamic and
no less and it's doing so much more than you think, leaving people
to try and mitigate the design issues using clever implementation
techniques as best they can.

 By the way if it hasn't happened and if he isn't afraid
 of public speaking someone should invite Matt Mackall
 to give a Python conference keynote.  Or how about
 Bram Cohen for that matter...

Bryan O'Sullivan gave a talk on Mercurial at EuroPython 2006, and
although I missed that talk for various reasons beyond my control, I
did catch his video lightning talk which emphasized performance.
That's not to say that we couldn't do with more talks of this nature
at Python conferences, however.

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


Re: SCGIServer and unusal termination

2009-11-17 Thread Diez B. Roggisch
Eden Kirin wrote:

 Hi there,
 
 I'm playing with SCGIServer
 (http://vmlinux.org/cgi-bin/dwww/usr/share/doc/python-scgi/guide.html),
 everything works just fine, but one thing bothers me. All prints after
 try-except block are executed twice after the Ctrl+C is pressed!
 
 test.py:
 #-
 from scgi.scgi_server import SCGIServer
 
 n = 0
 print Starting server.
 
 try:
  SCGIServer().serve()
 except (KeyboardInterrupt, SystemExit):
  print Exception!
 
 # print lines are executed twice (?!)
 n += 1
 print Terminating server, attempt %d. % n
 n += 1
 print Check n: %d. % n
 #-
 
 This is the output:
 
 e...@sunce:~/data/project/ScgiServer/src python test.py
 Starting server.
 ^CException!
 Exception!
 Terminating server, attempt 1.
 Check n: 2.
 Terminating server, attempt 1.
 Check n: 2.
 e...@sunce:~/data/project/ScgiServer/src
 
 
 If I put something else in try-except block, code after is executed
 normally:
 
 try:
  while 1:
  pass
 except (KeyboardInterrupt, SystemExit):
  print Exception!
 
 e...@sunce:~/data/project/ScgiServer/src python test.py
 Starting server.
 ^CException!
 Terminating server, attempt 1.
 Check n: 2.
 e...@sunce:~/data/project/ScgiServer/src
 
 Environment is 64bit Ubuntu with Python v2.6.4.
 
 Is there some reasonable explanation for this behaviour? Thanks in
 advance.

I can only guess that SCGIServer does something to stdout. Your code isn't
executed twice, so the doubling seems to come from writing it twice.

Try e.g. redirecting stdout and stderr to different files, and see if things
appear once in both.

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


Re: overriding __getitem__ for a subclass of dict

2009-11-17 Thread Steve Howell
On Nov 17, 7:11 am, Scott David Daniels scott.dani...@acm.org wrote:
 Steve Howell wrote:

 ...

  Eventually, I realized that it was easier to just monkeypatch Django
  while I was in test mode to get a more direct hook into the behavior I
  was trying to monitor, and then I didn't need to bother with
  overriding __getitem__ or creating complicated wrapper objects

 Since nobody else has mentioned it, I'd point you at Mock objects:
      http://python-mock.sourceforge.net/
 for another way to skin the cat that it sounds like has been
 biting you.  They are surprisingly useful for exploratory
 and regression testing.


Thanks, Scott.  We do indeed use mocks in our development, and they
are useful.  In a way I am trying to emulate some of what mock objects
do, but in more on an integration testing mode.  For testing the
rendering of whole templates, it sometimes becomes convenient for at
least some of the objects that your code depends on to maintain their
implementation under the hood, but you also want to see where they're
going, which is why I want to be able to hook into the dictionary
lookup mechanism.

Even outside of pure unit testing, mock objects have been pretty
versatile in terms of giving us the lay of the land, even when we
start getting down into the Django template stack.  It is mostly when
you start interacting with the ORM that you want to start using real
objects.  On the one hand you want to isolate yourselves from the ORM
behavior to validate the rest of your code, but sometimes it is
difficult to emulate the exact semantics of the ORM, or maybe you are
trying to get a handle on where the ORM is hitting the database,
etc.

The so-called real world situations are when you start wanting a
messy hybrid of mock objects, merely-spied-on objects, real objects,
etc.


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


Re: Calling Python functions from Excel

2009-11-17 Thread Mark Tolonen


Chris Withers ch...@simplistix.co.uk wrote in message 
news:4b028ac1.8020...@simplistix.co.uk...

Cannonbiker wrote:

Hi,
unfortunately is my question about server COM (win32com)
http://groups.google.com/group/comp.lang.python/browse_thread/thread/ee804cec7f58c6a7#
without answer.

Please I need Calling Python functions from Excel and receive result
back in Excel. Can me somebody advise simplest solution please? I am
more VBA programmer than Python.


Try http://code.google.com/p/pyinex/


The book Python: Programming on Win32 has a whole chapter on COM, and a 
section on COM servers.


-Mark 



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


Re: Code for finding the 1000th prime

2009-11-17 Thread Peter Otten
mrholtsr wrote:

 I am absolutely new to python and barely past beginner in programming.
 Also I am not a mathematician. Can some one give me pointers for
 finding the 1000th. prime for a course I am taking over the internet
 on Introduction to Computer Science and Programming. Thanks, Ray

When you encounter a problem that you find hard try to split it into simpler 
subproblems. Example:

To find the 1000th prime start with a program that finds all integers

i = 1
while True:
print i
i = i + 1

If you run that it will print integers until you hit Ctrl-C. Python offers 
an elegant construct that helps you encapsulate the logic of a loop, called 
generator. With that we can rewrite the all-integers program as

def all_natural_numbers():
i = 1
while True:
yield i
i = i + 1

for i in all_natural_numbers():
print i

Now let's tackle the next step: we want only prime numbers, but don't know 
how to check for them. How can we postpone that problem and still continue 
with our program? Easy: introduce a function where the check will ultimately 
go but have it do something that we do understand right now:

def isprime(candidate):
return candidate != 42

Why not check for candidate == 42? We would only ever get one pseudo-
prime, but we need at least 1000 of them. With the above bold assumption 
the program becomes

def isprime(candidate):
return candidate != 42

def all_natural_numbers():
i = 1
while True:
yield i
i = i + 1

for i in all_natural_numbers():
if isprime(i):
print i

While the actual output is a bit unorthodox we now have the structure to 
print all prime numbers. Again we can wrap the logic into a generator:

def isprime(candidate):
return candidate != 42

def all_natural_numbers():
i = 1
while True:
yield i
i = i + 1

def all_prime_numbers():
for i in all_natural_numbers():
if isprime(i):
yield i

for p in all_prime_numbers():
print p

We are actually only interested in the 1000th prime. We can find that by 
counting over all prime numbers:

i = 1
for p in all_prime_numbers():
if i == 1000:
print p
break
i = i + 1

We can wrap this step in a function for future reuse:

# all_natural_numbers(), all_prime_numbers(), 
# and isprime() as before

def nth_item(items, n):
i = 1
for item in items:
if i == n:
return item
i = i + 1
# raise Exception(here be dragons)

print nth_item(all_prime_numbers(), 1000)

OK, we now have a nice clean python script that tells us that the 1000th 
prime number is 1001, a finding that will meet some opposition among 
mathematicians. Let's turn to wikipedia for help:


a prime number (or a prime) is a natural number which has exactly two 
distinct natural number divisors: 1 and itself. 
...
The number 1 is by definition not a prime number.


Translated into Python:

def isprime(candidate):
if candidate == 1:
return False # 1 is not a prime
for potential_divisor in range(2, candidate):
if int(candidate/potential_divisor)*potential_divisor == candidate:
# candidate could be divided by potential divisor
# without rest, so it's not a prime 
return False
# we didn't find a divisor for candidate
# -- it must be a prime
return True

Now while this test for primality is not the most beautiful code I've ever 
written it should give you the correct result. As a first step to improve it 
have a look at the % (modulo) operator in your textbook. Then try to 
reduce the number of potential divisors.

Peter

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


Re: SCGIServer and unusal termination

2009-11-17 Thread Eden Kirin

Diez B. Roggisch wrote:


Is there some reasonable explanation for this behaviour? Thanks in
advance.


I can only guess that SCGIServer does something to stdout. Your code isn't
executed twice, so the doubling seems to come from writing it twice.


Yes I know that code isn't executed twice since the value of n remains 
the same, only print lines are doubled.



Try e.g. redirecting stdout and stderr to different files, and see if things
appear once in both.


Redirection of stdout:

e...@sunce:~/data/project/ScgiServer/test python test.py 1 output.txt
^ce...@sunce:~/data/project/ScgiServer/test cat output.txt
Starting server.
Exception!
Terminating server, attempt 1.
Check n: 2.
Starting server.
Exception!
Terminating server, attempt 1.
Check n: 2.

Redirecting stderr creates an empty file. I still haven't found the 
solution.


--
www.vikendi.net -/- www.supergrupa.com
--
http://mail.python.org/mailman/listinfo/python-list


Vim breaks after Python upgrade

2009-11-17 Thread NickC

Perhaps OT, but I figure here is where people have seen this commonly.

I upgraded Python from my distro's default of 2.5.2 to 2.6.2.  Vim is now 
complaining every startup about missing exec libraries, presumably as 
some plugins run some python code on initialisation.  I'm guessing vim is 
complaining as it was compiled with python support, and that was 2.5.2, 
and the compiled-in python library locations no longer exist.

I compiled a new vim, so things are ok-ish, but now my system is even 
further away from standard distro.  I'm also a little surprised vim is so 
clunky as to use hard-coded locations.  Do I really have to compile a new 
vim every python upgrade?

'strings vim' shows some ascii that could be the python library 
locations.  Being quite ignorant of how the linux loader works, could I in 
future use sed on the vim binary to change every string of 2.5.2 to 
2.6.2, or are the library locations used by the loader coded in binary 
rather than ascii (and so, harder to find)?

Thanks,

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


Re: TODO and FIXME tags

2009-11-17 Thread Falcolas
On Nov 17, 4:27 am, Martin P. Hellwig martin.hell...@dcuktec.org
wrote:
 Ben Finney wrote:
  Chris Rebert c...@rebertia.com writes:

  2009/11/16 Yasser Almeida Hernández pedro...@fenhi.uh.cu:
  How is the sintaxis for set the TODO and FIXME tags...?
  There is no special syntax for those. Some people use them in
  comments, but it's just a convention.

  This is true. However, the convention is fairly well established, and
  many text editor default configurations will highlight the strings
  ‘TODO’, ‘FIXME’, and others wherever they appear in comments.

  There's no widely-followed “syntax” for this convention, though.

I have noticed that within Python XXX as an identifier is fairly
popular as well - it's used throughout the standard libraries, and is
recognized by many syntax highlighting schemes, as well as Pylint.

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


Re: Calling Python functions from Excel

2009-11-17 Thread Chris Withers

Mark Tolonen wrote:



Please I need Calling Python functions from Excel and receive result
back in Excel. Can me somebody advise simplest solution please? I am
more VBA programmer than Python.


Try http://code.google.com/p/pyinex/


The book Python: Programming on Win32 has a whole chapter on COM, and a 
section on COM servers.


...and it's generally accepted that COM sucks rocks through straws, so 
explore alternatives when they're available ;-)


Chris

--
Simplistix - Content Management, Batch Processing  Python Consulting
   - http://www.simplistix.co.uk
--
http://mail.python.org/mailman/listinfo/python-list


Re: Choosing GUI Module for Python

2009-11-17 Thread Dietmar Schwertberger

sturlamolden schrieb:

On 14 Nov, 15:35, Dietmar Schwertberger n...@schwertberger.de wrote:


   self.m_toolBar1 = self.CreateToolBar( wx.TB_HORIZONTAL, wx.ID_ANY )
   self.m_button1 = wx.Button( self.m_toolBar1, wx.ID_ANY, uMyButton,
wx.DefaultPosition, wx.DefaultSize, 0 )
   m_toolBar1.AddControl( m_button1 )


I can confirm this. There seems to be a bug in the generation of
Python code for wxToolBar.


If anybody faces this problem before a new revision of wxFormBuilder
will be available: an XML file need to be updated to correctly
include self.

The modification:

wxformbuilder\output\plugins\common\xml\menutoolbar.pythoncode:

codegen language=Python
  templates class=wxWindow
template name=toolbar_addself.#parent $name.AddControl( 
self.$name )/template

  /templates



Regards,

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


Re: python simply not scaleable enough for google?

2009-11-17 Thread Rustom Mody
Language L is (in)efficient. No! Only implementations are (in)efficient

I am reminded of a personal anecdote.  It happened about 20 years ago
but is still fresh and this thread reminds me of it.

I was attending some workshop on theoretical computer science.
I gave a talk on Haskell.

I showed off all the good-stuff -- pattern matching, lazy lists,
infinite data structures, etc etc.
Somebody asked me: Isnt all this very inefficient?
Now at that time I was a strong adherent of the Dijkstra-religion and
this viewpoint efficiency has nothing to do with languages, only
implementations traces to him. So I quoted that.

Slowing the venerable P S Thiagarajan got up and asked me:
Lets say that I have a language with a type 'Proposition'
And I have an operation on proposition called sat [ sat(p) returns
true if p is satisfiable]...

I wont complete the tale other than to say that Ive never had the wind
in my sails taken out so completely!

So Vincent? I wonder what you would have said in my place?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python simply not scaleable enough for google?

2009-11-17 Thread J Kenneth King
David Cournapeau courn...@gmail.com writes:

 On Tue, Nov 17, 2009 at 10:48 PM, Aaron Watters aaron.watt...@gmail.com 
 wrote:

 I don't think Python and Go address the same set of programmer
 desires.  For example, Go has a static type system.  Some programmers
 find static type systems to be useless or undesirable.  Others find
 them extremely helpful and want to use them them.  If you're a
 programmer who wants a static type system, you'll probably prefer Go
 to Python, and vice versa.  That has nothing to do with implementation
 speed or development expenditures.  If Google spent a million dollars
 adding static types to Python, it wouldn't be Python any more.

 ... and I still have an issue with the whole Python is slow
 meme.  The reason NASA doesn't build a faster Python is because
 Python *when augmented with FORTRAN libraries that have been
 tested and optimized for decades and are worth billions of dollars
 and don't need to be rewritten* is very fast.

 It is a bit odd to dismiss python is slow by saying that you can
 extend it with fortran. One of the most significant point of python
 IMO is its readability, even for people not familiar with it, and
 that's important when doing scientific work. Relying on a lot of
 compiled libraries goes against it.

 I think that python with its scientific extensions is a fantastic
 tool, but I would certainly not mind if it were ten times faster. In
 particular, the significant cost of function calls makes it quickly
 unusable for code which cannot be easily vectorized - we have to
 resort to using C, etc... to circumvent this ATM.

 Another point which has not been mentioned much, maybe because it is
 obvious: it seems that it is possible to makes high level languages
 quite fast, but doing so while keeping memory usage low is very
 difficult. Incidentally, the same tradeoff appears when working with
 vectorized code in numpy/scipy.

I think this is the only interesting point in the whole conversation so
far.

It is possible for highly dynamic languages to be optimized, compiled,
and run really fast.

The recent versions of SBCL can compile Common Lisp into really fast and
efficient binaries.  And Lisp could be considered even more dynamic than
Python (but that is debateable and I have very little evidence... so
grain of salt on that statement).  It's possible, it just hasn't been
done yet.

PyPy is getting there, but development is slow and they could probably
use a hand.  Instead of waiting on the sidelines for a company to back
PyPy developemnt, the passionate Python programmers worth a salt that
care about Python development should contribute at least a patch or two.

The bigger problem though is probably attention span.  A lot of
developers today are more apt to simply try the next new language than
to roll of their sleeves and think deeply enough to improve the tools
they're already invested in.


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


Re: Easy way to play single musical notes in Python

2009-11-17 Thread James Harris
On 15 Nov, 05:41, r rt8...@gmail.com wrote:
 On Nov 14, 6:21 pm, James Harris james.harri...@googlemail.com
 wrote:

  Is there a simple way to play musical notes in Python? Something like
    voice.play(c4)

 Uhh, tksnack is pretty easy to use IMO, see this link... 
 http://www.daniweb.com/code/snippet216655.html

 No python does not have access to cross platform soundcard
 capabilities built into the language. I think there is a wrapper for
 csound somewhere. But there are many 3rd party modules that do have
 capabilities to some extent. You could make calls to the underlying OS
 machinery and there is the winsound module (not exactly what you want
 though). Just look over this Google splooge...

 http://www.google.com/search?hl=enrlz=1C1CHMI_enUS340US340q=Python+...

As I say I was hoping to avoid tk. Thanks for the feedback though. If
nothing else is suggested I'll have to try snack.

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


FYI: ConfigParser, ordered options, PEP 372 and OrderedDict + big thank you

2009-11-17 Thread Jonathan Fine

Hi

A big thanks to Armin Ronacher and Raymond Hettinger for
   PEP 372: Adding an ordered dictionary to collections

I'm using ConfigParser and I just assumed that the options in a section 
were returned in the order they were given.  In fact, I relied on this fact.

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

And then when I came to test the code it went wrong.  After some anguish 
I looked at ConfigParser and saw I could pass it a dict_type.  So I 
could fix the problem myself by writing an OrderDict.  Which I duly 
prototyped (in about an hour).


I then thought - maybe someone has been down this path before.  A Google 
search quickly led me to PEP 372 and hence to

http://docs.python.org/dev/py3k/library/configparser.html
which says
class configparser.RawConfigParser(defaults=None,
   dict_type=collections.OrderedDict)

So all that I want has been done already, and will be waiting for me 
when I move to Python3.


So a big thank you is in order.

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


CTypes problem.

2009-11-17 Thread Martijn Arts
 I wanted to use PyWiiUse, but, well, it sucks

Then I thought; it can't be THAT hard, can it? So I began porting WiiUse to
Python using ctypes, but apparently, I did something wrong.

poll() gives back an event, *but* (there's always a but) the event doesn't
register. Or... Well... See for yourself, I think it has something to do
with Pointers, but I have no idea, really ;)

So, here's the code:
Code :-P http://plaatscode.be/138026/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Code for finding the 1000th prime

2009-11-17 Thread Diez B. Roggisch
Stefan Behnel wrote:

 Robert P. J. Day, 15.11.2009 15:44:
 On Sun, 15 Nov 2009, mrholtsr wrote:
 
 I am absolutely new to python and barely past beginner in programming.
 Also I am not a mathematician. Can some one give me pointers for
 finding the 1000th. prime for a course I am taking over the internet
 on Introduction to Computer Science and Programming. Thanks, Ray
 
   it's 7919.
 
 Now, all that's left to do is write a prime number generator (a random
 number generator will do, too, but writing a good one isn't easy), run it
 repeatedly in a loop, and check if the returned number is 7919. Once it
 compares equal, you can print the result and you're done.

That reminds me of the only algorithm I really invented myself: debil sort.


It goes like this:

L = list of comparable items

while not sorted(L):
   p = generate_random_permutation(len(L))
   L = apply_permutation(L, p)

print L


Great algorithm. Actually works. And the saddest thing: somebody out there
certainly has written something like that by accident... I've spotted
sorting in O(n^3) (with non-deterministic exceptional termination
conditions) already in the wild.

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


Re: New syntax for blocks

2009-11-17 Thread MRAB

Jonathan Saxton wrote:

On Thu, 12 Nov 2009 21:27:31 +0100, Bruno Desthuilliers wrote:


Congratulations, you just reinvented one of the most infamous
source of bugs in C, C++, Java, PHP, javascript and quite a few
other languages. Believe it or not, but not allowing this in
Python was a very deliberate design choice.

Oh, but those hundreds of thousands of man-hours lost to bugs
caused by assignment-as-an-expression is nothing compared to the
dozens of man- minutes saved by having one fewer line of code!


*wink*


And if I ever find the genius who had the brilliant idea of using =
to mean assignment then I have a particularly nasty dungeon reserved
just for him.  Also a foul-smelling leech-infested swamp for those
language designers and compiler writers who followed his example.
(Come to think of it, plagiarizing a bad idea is probably the worse
evil.)


C was derived from BCPL, which used := and =.

Fortran uses = and .EQ., probably because (some) earlier autocodes
did.

It's a pity that Guido chose to follow C.
--
http://mail.python.org/mailman/listinfo/python-list


Re: SCGIServer and unusal termination

2009-11-17 Thread Diez B. Roggisch
Eden Kirin wrote:

 Diez B. Roggisch wrote:
 
 Is there some reasonable explanation for this behaviour? Thanks in
 advance.
 
 I can only guess that SCGIServer does something to stdout. Your code
 isn't executed twice, so the doubling seems to come from writing it
 twice.
 
 Yes I know that code isn't executed twice since the value of n remains
 the same, only print lines are doubled.
 
 Try e.g. redirecting stdout and stderr to different files, and see if
 things appear once in both.
 
 Redirection of stdout:
 
 e...@sunce:~/data/project/ScgiServer/test python test.py 1 output.txt
 ^ce...@sunce:~/data/project/ScgiServer/test cat output.txt
 Starting server.
 Exception!
 Terminating server, attempt 1.
 Check n: 2.
 Starting server.
 Exception!
 Terminating server, attempt 1.
 Check n: 2.
 
 Redirecting stderr creates an empty file. I still haven't found the
 solution.
 

Then 

 - save a reference to sys.stdout *before* invoking the server
 - compare to it after interruption. If it has changed, you at least know
that somebody messed with it, and can beat him or whatever you see fit.

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


Re: Language mavens: Is there a programming with if then else ENDIF syntax?

2009-11-17 Thread nn
On Nov 16, 11:54 am, Steve Ferg steve.ferg.bitbuc...@gmail.com
wrote:
 This is a question for the language mavens that I know hang out here.
 It is not Python related, except that recent comparisons of Python to
 Google's new Go language brought it to mind.

 NOTE that this is *not* a suggestion to change Python.  I like Python
 just the way it is.  I'm just curious about language design.

 For a long time I've wondered why languages still use blocks
 (delimited by do/end, begin/end, { } , etc.) in ifThenElse statements.

 I've often thought that a language with this kind of block-free syntax
 would be nice and intuitive:

     if condition then
         do stuff
     elif condition then
         do stuff
     else
         do stuff
     endif

 Note that you do not need block delimiters.

 Obviously, you could make a more Pythonesque syntax by using a colon
 rather then then for the condition terminator.  You could make it
 more PL/I-like by using do, etc.

 You can write shell scripts using if ... fi, but other than that I
 don't recall a language with this kind of syntax.

 Does anybody know a language with this kind of syntax for
 ifThenElseEndif?

 Is there any particular reason why this might be a *bad* language-
 design idea?

I personally like the END X syntax (not that I would want it for
Python mind you). It makes it easier to read programs backwards.
Foxpro used that syntax form extensively:

http://msdn.microsoft.com/en-us/library/b660264t%28VS.80%29.aspx

DO CASE ... ENDCASE
DO WHILE ... ENDDO
FOR EACH ... ENDFOR
FOR ... ENDFOR
IF ... ENDIF
PRINTJOB ... ENDPRINTJOB
SCAN ... ENDSCAN
TEXT ... ENDTEXT
WITH ... ENDWITH
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Code for finding the 1000th prime

2009-11-17 Thread Chris Rebert
On Tue, Nov 17, 2009 at 9:27 AM, Diez B. Roggisch de...@nospam.web.de wrote:
 Stefan Behnel wrote:
 Robert P. J. Day, 15.11.2009 15:44:
 Now, all that's left to do is write a prime number generator (a random
 number generator will do, too, but writing a good one isn't easy), run it
 repeatedly in a loop, and check if the returned number is 7919. Once it
 compares equal, you can print the result and you're done.

 That reminds me of the only algorithm I really invented myself: debil sort.

There's prior art for this algorithm:
http://en.wikipedia.org/wiki/Bogosort

 It goes like this:

 L = list of comparable items

 while not sorted(L):
   p = generate_random_permutation(len(L))
   L = apply_permutation(L, p)

 print L


 Great algorithm. Actually works. And the saddest thing: somebody out there
 certainly has written something like that by accident... I've spotted
 sorting in O(n^3) (with non-deterministic exceptional termination
 conditions) already in the wild.

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Vim breaks after Python upgrade

2009-11-17 Thread Nick Stinemates
At least with Gentoo, there's a command to recompile all of the plugins
you have installed when upgrading python versions.

Your issue is probably related to that. I don't think VIM uses hardcoded
locations for scripts at the core.

If you have any specific questions about the errors you're receiving,
feel free to submit to the VIM mailing list or stop by the IRC channel:
#vim on irc.freenode.org

On Tue, Nov 17, 2009 at 04:33:30PM +, NickC wrote:
 
 Perhaps OT, but I figure here is where people have seen this commonly.
 
 I upgraded Python from my distro's default of 2.5.2 to 2.6.2.  Vim is now 
 complaining every startup about missing exec libraries, presumably as 
 some plugins run some python code on initialisation.  I'm guessing vim is 
 complaining as it was compiled with python support, and that was 2.5.2, 
 and the compiled-in python library locations no longer exist.
 
 I compiled a new vim, so things are ok-ish, but now my system is even 
 further away from standard distro.  I'm also a little surprised vim is so 
 clunky as to use hard-coded locations.  Do I really have to compile a new 
 vim every python upgrade?
 
 'strings vim' shows some ascii that could be the python library 
 locations.  Being quite ignorant of how the linux loader works, could I in 
 future use sed on the vim binary to change every string of 2.5.2 to 
 2.6.2, or are the library locations used by the loader coded in binary 
 rather than ascii (and so, harder to find)?
 
 Thanks,
 
 -- 
 NickC
 -- 
 http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


_winreg error on open key (64bit) - proper usage of _winreg.DisableReflectionKey

2009-11-17 Thread Randall Walls
Greetings,

I'm writing a python script to automate creating ODBC connections on a
Windows2008 Server (64bit) platform. I created an ODBC manually (using the
GUI), for the purposes of fleshing out the 'check for existing' section of
the script.

Problem: though I can see the key in regedit
(HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\DRSQL2000_mu), calling an
_winreg.OpenKey returns 'WindowsError: [Error 2] The system cannot find the
file specified'. Googling the error brought up the possibility that this key
is being impacted by registry redirection (
http://mail.python.org/pipermail/python-win32/2009-February/008862.html),
and thus the need to use _winreg.DisableReflectionKey to correct this.

I'm new to using _winreg (but not new to python), and though it sounds
simple, I can't figure out how to properly use _winreg.DisableReflectionKey
to make the _winreg.OpenKey work properly, and there is nearly 0
documentation on how to use _winreg.DisableReflectionKey (though I would be
happy to write something up if I could figure the damned thing out).

any help is appreciated. Has anyone else run into this before? I realize
that Server 2008 is new and that _winreg.DisableReflectionKey was just
added, but I'm still hoping SOMEBODY has run into this before.

Many thanks,

-- 
Randall Walls
Tyler Technologies, Inc
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: _winreg error on open key (64bit) - proper usage of _winreg.DisableReflectionKey

2009-11-17 Thread Nick Stinemates
From _winreg.c:

Disables registry reflection for 32-bit processes running on a 64-bit 
OperatingSystem. Will generally raise NotImplemented if executed on a 32-bit 
Operating System. If the key is not on the reflection list, the function 
succeeds but has noeffect. Disabling reflection for a key does not affect 
reflection of any subkeys.

Are there any subkeys which you also need to disable? Parent keys?


On Tue, Nov 17, 2009 at 01:51:12PM -0500, Randall Walls wrote:
 Greetings,
 
 I'm writing a python script to automate creating ODBC connections on a
 Windows2008 Server (64bit) platform. I created an ODBC manually (using the
 GUI), for the purposes of fleshing out the 'check for existing' section of
 the script.
 
 Problem: though I can see the key in regedit
 (HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\DRSQL2000_mu), calling an
 _winreg.OpenKey returns 'WindowsError: [Error 2] The system cannot find the
 file specified'. Googling the error brought up the possibility that this key
 is being impacted by registry redirection (
 http://mail.python.org/pipermail/python-win32/2009-February/008862.html),
 and thus the need to use _winreg.DisableReflectionKey to correct this.
 
 I'm new to using _winreg (but not new to python), and though it sounds
 simple, I can't figure out how to properly use _winreg.DisableReflectionKey
 to make the _winreg.OpenKey work properly, and there is nearly 0
 documentation on how to use _winreg.DisableReflectionKey (though I would be
 happy to write something up if I could figure the damned thing out).
 
 any help is appreciated. Has anyone else run into this before? I realize
 that Server 2008 is new and that _winreg.DisableReflectionKey was just
 added, but I'm still hoping SOMEBODY has run into this before.
 
 Many thanks,
 
 -- 
 Randall Walls
 Tyler Technologies, Inc

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

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


Re: YIELD_VALUE Byte Code

2009-11-17 Thread Terry Reedy

Andreas Löscher wrote:

Hi,
I am not sure if this is the right newsgroup, so if not don't hesitate
to tell me.


Since there is no CPython internals list, this is the right place to 
start, even though you might end up having to post a slightly off-topic 
query to python-devel just to get the attention of whoever has the 
answer. But there are a few deveoopers who read and post here also.



I am developed a Python to C compiler, so that Byte Code files
automatically can be translated into C Extension Modules. (And it works
pretty well -- http://www.coremountains.com/products/bytecoat/)

While developing, I found something strange concerning the YIELD_VALUE
OpCode.

Since Python Version 2.5 it behaves the following:
1. pop yield value from stack and return it to
a former gen_send_ex() call from Objects/genobject.c

2. push the yield value on the stack in gen_send_ex() and return
it

3. when the generator is executed again, the yield value is
'poped' from the stack again with the POP_TOP opcode

Now I found that a little strange:
	1. why is the value removed from the stack, than pushed on the 
		stack to remove it finally again? the combination of 
		YIELD_VALUE and TOP_POP seems hard coded in compile.c
		which means that a TOP_POP follows every YIELD_VALUE 
		TOP_POP


2. If the semantic of the YIELD_VALUE OpCode has changed, why
		is this reached by using another function? Such thing 
		should be done in the OpCode.


		(e.a.: instead of retval = POP() 
			-- retval = TOP(); Py_INCREF(retval); )


I am a little confused about this.


I suspect that what you see reflects the 2.5 change of 'yield x' from a 
statement to an expression to enable gen.send(). It is possible that 
someone did the simplest thing that worked, rather than properly 
rewriting the code. Or maybe the trickery is needed. You can always try 
a simplyfing patch against the test suite and even submit it if it passes.


Terry Jan Reedy


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


ANN: Urwid 0.9.9 - Console UI Library

2009-11-17 Thread Ian Ward
Announcing Urwid 0.9.9
--

Urwid home page:
  http://excess.org/urwid/

Updated screen shots:
  http://excess.org/urwid/examples.html

Tarball:
  http://excess.org/urwid/urwid-0.9.9.tar.gz

RSS:
  http://excess.org/feeds/tag/urwid/


About this release:
===

This release includes many new features developed since the last major
release.  Urwid now supports 256 and 88 color terminals.  A new MainLoop
class has been introduced to tie together widgets, user input, screen
display and an event loop.  Twisted and GLib-based event loops are now
supported directly.  A new AttrMap class now allows mapping any
attribute to any other attribute.  Most of the code base has been
cleaned up and now has better documentation and testing.  Lots of other
improvements are listed below.


New in this release:


  * New support for 256 and 88 color terminals with raw_display
and html_fragment display modules

  * New palette_test example program to demonstrate high color
modes

  * New AttrSpec class for specifying specific colors instead of
using attributes defined in the screen's palette

  * New MainLoop class ties together widgets, user input, screen
display and one of a number of new event loops, removing the
need for tedious, error-prone boilerplate code

  * New GLibEventLoop allows running Urwid applications with GLib
(makes D-Bus integration easier)

  * New TwistedEventLoop allows running Urwid with a Twisted reactor

  * Added new docstrings and doctests to many widget classes

  * New AttrMap widget supports mapping any attribute to any other
attribute, replaces AttrWrap widget

  * New WidgetDecoration base class for AttrMap, BoxAdapter, Padding,
Filler and LineBox widgets creates a common method for accessing
and updating their contained widgets

  * New left and right values may be specified in Padding widgets

  * New command_map for specifying which keys cause actions such as
clicking Button widgets and scrolling ListBox widgets

  * New tty_signal_keys() method of raw_display.Screen and
curses_display.Screen allows changing or disabling the keys used
to send signals to the application

  * Added helpful __repr__ for many widget classes

  * Updated all example programs to use MainLoop class

  * Updated tutorial with MainLoop usage and improved examples

  * Renamed WidgetWrap.w to _w, indicating its intended use as a way
to implement a widget with other widgets, not necessarily as
a container for other widgets

  * Replaced all tabs with 4 spaces, code is now more aerodynamic
(and PEP 8 compliant)

  * Added saving of stdin and stdout in raw_display module allowing
the originals to be redirected

  * Updated BigText widget's HalfBlock5x4Font

  * Fixed graph example CPU usage when animation is stopped

  * Fixed a memory leak related to objects listening for signals

  * Fixed a Popen3 deprecation warning


About Urwid
===

Urwid is a console UI library for Python. It features fluid interface
resizing, UTF-8 support, multiple text layouts, simple attribute markup,
powerful scrolling list boxes and flexible interface design.

Urwid is released under the GNU LGPL.








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


Is there a way to load multiple wxhtmlwindow at the same time?

2009-11-17 Thread Abe
All -
  I'm working on a program that loads a series of web pages so the
user can view them quickly one after another.  I'm using python and
wxhtmlwindow, and the page loading is really slow.  Is there a simple
way to load up the next few pages in the queue while the user is
looking at the current page?

thanks!
- Abe

PS - If the answer involves threading, can you please point me to some
resources on threading in wx?  I know the basics of GUI programming in
wx and threading in python, but I have no idea how to put them
together.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New syntax for blocks

2009-11-17 Thread r
On Nov 17, 9:28 am, Jonathan Saxton jsax...@appsecinc.com wrote:

 And if I ever find the genius who had the brilliant idea of using = to mean 
 assignment then I have a particularly nasty dungeon reserved just for him.  
 Also a foul-smelling leech-infested swamp for those language designers and 
 compiler writers who followed his example.  (Come to think of it, 
 plagiarizing a bad idea is probably the worse evil.)

I think every new programmer wrestles with this dilemma in their first
days but very soon after accepts it as reality. As for me it made
perfect sense from day one to have '=' mean assignment and '==' to
mean equality. Programming is not mathematics (on the contrary) they
are two sides of a mountain forever unknowing of each other but
sharing the same space. I think the syntax was chosen because the
alternatives are even worse AND since assignment is SO common in
programming, would you *really* rather type two chars instead of one?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python gui builders

2009-11-17 Thread Simon Hibbs
On 16 Nov, 10:06, me not_h...@nowhere.com wrote:

 What Python gui builder is well supported, does not require me
 to learn another framework/library, and can crank out stuff for
 multiple platforms ?

You're looking for a framework/library that doesn't require you to
learn it. OK

I've had this problem for a few years. I've tried PythonCard,
WxWidgets with WxDesigner, BoaConstructor, etc. None of them come
anywhere close to PyQT/QTDesigner.

Dion't get Blackadder It hasn't been updated for several years and is
a dead project. In any case it uses QTDesigner for GUI layout anyway.
You're better off using Eric or Wing if you want a decent IDE.

QT does have a learning curve of course, but you get a lot of power
back in return for the investment. I'm just coming to grips with it's
MVC framework and the book Rapid GUI Programming with Python and Qt
is very helpful with that.

I wouldn't completely dismiss Tkinter. It's too simple for complex
GUIs but I still think it has it's place for basic utilities.

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


Re: 2.6.4 Mac x86_64 ?

2009-11-17 Thread chris grebeldinger
On Nov 14, 12:53 am, Zvezdan Petkovic zvez...@zope.com wrote:
 On Nov 13, 2009, at 3:58 PM, chris grebeldinger wrote:

  Hi All,
  I've been having some trouble getting ax86_64/i386 universal
  readline.so to build against libedit, on MacOS 10.5.6 as Apple does.
  Does anyone have any pointers about what changes I need to make to
  setup.py or readline.c to achive this?
  Has someone already done this and would like to share it?

 The fix for use of native editline (readline emulation) was done and is 
 already implemented on the trunk (2.7).
 Please see:http://bugs.python.org/issue6877
 You can find the patch in that tracker issue or 
 here:http://svn.python.org/view?view=revrevision=74970

 It was marked for a backport to a future 2.6.5 release too.

  Are there any plans to provide 64 bit support in future Mac OS 2.6.x
  releases?

 AFAIK, it is already supported.
 Perhaps you should specify the exact problems you have.
 I believe that a more appropriate place for that would be pythonmac-sig 
 mailing list, though.

 Best regards,

         Zvezdan

Thank-you, doing a manual backport was easy once I knew where to find
the diff =)

- Chris


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


Re: python gui builders

2009-11-17 Thread r
On Nov 17, 12:20 pm, Simon Hibbs simon.hi...@gmail.com wrote:

 I wouldn't completely dismiss Tkinter. It's too simple for complex
 GUIs but I still think it has it's place for basic utilities.

Agreed! Tkinter (besides myself) seems to be the whipping boy of
c.l.py. Tkinter has it's place in Python because of the same
simplicity people laboriously lament about! Until something else comes
along that can offer the same benefits of Tkinter and a little extra,
we are going to keep seeing Tkinter release after release. Guido knows
what he is doing people, don't sell the guy short!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python gui builders

2009-11-17 Thread CM
On Nov 16, 5:06 am, me not_h...@nowhere.com wrote:
 Good People

 I do not write stuff for humans, as it has been my job to remove
 humans from the loop. But I have to make a front end to a
 component database where everything was built in Python.

 I have looked at the Tk stuff that is built into Python - not
 acceptable. So looking at wxGlade, Boa Constructor, Python Card.
 Also looked at the frames/forms created with QtDesigner, which
 can be used by Python via pyuic. BlackAdder IDE seems to have
 this built-in, but am loathe to buy into another GUI tool for a
 single job.

 I have not been able to find a decent Python gui builder. The

What was your issue with Boa Constructor?  It produces wxPython
code and I find it works quite well (less well on Linux, but if
you use it in Windows, the app will run in Linux w/ minimal need
for changes).

Of course, whatever route you go, you have to learn the widget
toolkit.

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


Re: New syntax for blocks

2009-11-17 Thread Nobody
On Tue, 17 Nov 2009 17:31:18 +, MRAB wrote:

 And if I ever find the genius who had the brilliant idea of using =
 to mean assignment then I have a particularly nasty dungeon reserved
 just for him.  Also a foul-smelling leech-infested swamp for those
 language designers and compiler writers who followed his example.
 (Come to think of it, plagiarizing a bad idea is probably the worse
 evil.)
 
 C was derived from BCPL, which used := and =.

ISTR that Ritchie said that he chose = because assignment is more common
than testing for equality, so C's approach meant less typing.

 Fortran uses = and .EQ., probably because (some) earlier autocodes
 did.
 
 It's a pity that Guido chose to follow C.

OTOH, functional languages use = for binding (let x = ... in ...), which
is more like C initialisation (which also uses =).

Python's = is somewhere between assignment and binding. It's arguable
that Python should also have := for in-place modification (as opposed to
re-binding a name). E.g. for an array, foo := bar would be equivalent to
foo[:] = bar.

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


Re: directory wildcard

2009-11-17 Thread Nobody
On Mon, 16 Nov 2009 14:19:16 -0800, hong zhang wrote:

         print f, mcs
 
 This assigns decimal value, how can I assign Hex here to mcs?

print f, %x % mcs

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


Re: _winreg error on open key (64bit) - proper usage of _winreg.DisableReflectionKey

2009-11-17 Thread Randall Walls
I don't believe so, but it seems like I'm in a catch 22, where I need to
_winreg.OpenKey the key first before I can pass it to
_winreg.DisableReflectionKey, but it doesn't exist, so I can't open it.

I did find out that I can open the key using:
hKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, rSOFTWARE\ODBC\ODBC.INI\
DRSQL2000_mu0100\\, 0, _winreg.KEY_READ | _winreg.KEY_WOW64_64KEY)

The 'trick' was adding _winreg.KEY_WOW64_64KEY, which apparently tells the
system to look in the 64bit key area, and not under the Wow6432Node. That
brings up problem #2, though... I can't seem to CREATE a key in the above
path, and _winreg.CreateKey doesn't accept _winreg.KEY_WOW64_64KEY (in fact
it doesn't accept any options other than key, sub_key). _winreg.CreateKey
does work, it just puts the key in SOFTWARE\Wow6432Node\ODBC\ODBC.INI. So
I'm in a quandry... I'd like to use one or the other, and not have to
account for both.

much obliged

On Tue, Nov 17, 2009 at 2:18 PM, Nick Stinemates n...@stinemates.orgwrote:

 From _winreg.c:

 Disables registry reflection for 32-bit processes running on a 64-bit
 OperatingSystem. Will generally raise NotImplemented if executed on a 32-bit
 Operating System. If the key is not on the reflection list, the function
 succeeds but has noeffect. Disabling reflection for a key does not affect
 reflection of any subkeys.

 Are there any subkeys which you also need to disable? Parent keys?


 On Tue, Nov 17, 2009 at 01:51:12PM -0500, Randall Walls wrote:
  Greetings,
 
  I'm writing a python script to automate creating ODBC connections on a
  Windows2008 Server (64bit) platform. I created an ODBC manually (using
 the
  GUI), for the purposes of fleshing out the 'check for existing' section
 of
  the script.
 
  Problem: though I can see the key in regedit
  (HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\DRSQL2000_mu), calling an
  _winreg.OpenKey returns 'WindowsError: [Error 2] The system cannot find
 the
  file specified'. Googling the error brought up the possibility that this
 key
  is being impacted by registry redirection (
  http://mail.python.org/pipermail/python-win32/2009-February/008862.html
 ),
  and thus the need to use _winreg.DisableReflectionKey to correct this.
 
  I'm new to using _winreg (but not new to python), and though it sounds
  simple, I can't figure out how to properly use
 _winreg.DisableReflectionKey
  to make the _winreg.OpenKey work properly, and there is nearly 0
  documentation on how to use _winreg.DisableReflectionKey (though I would
 be
  happy to write something up if I could figure the damned thing out).
 
  any help is appreciated. Has anyone else run into this before? I realize
  that Server 2008 is new and that _winreg.DisableReflectionKey was just
  added, but I'm still hoping SOMEBODY has run into this before.
 
  Many thanks,
 
  --
  Randall Walls
  Tyler Technologies, Inc

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




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


Re: Command line arguments??

2009-11-17 Thread Nobody
On Mon, 16 Nov 2009 23:30:09 +, Rhodri James wrote:

 Quote the filenames or escape the spaces:
 
 C:\Python26\Python.exe C:\echo.py C:\New Folder\text.txt
 
 We've been living with this pain ever since windowed GUIs encouraged users  
 to put spaces in their file names (Apple, I'm looking at you!).   
 Fundamentally, if people want the pretty they have to live with the  
 consequences.

We've been living with much worse ever since Unix allowed users to put
not only spaces but even newlines in their filenames.

At least, those of us who prefer works over sort of works most of the
time have.

Then Python 3 decides to pretend that argv and environ and stdin contain
text rather than bytes, thereby ensuring that Python 2 will outlive Python
3.

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


Re: Language mavens: Is there a programming with if then else ENDIF syntax?

2009-11-17 Thread steven.oldner
Along the COBOl line is ABAP, the 4gl language from SAP.

If today = 'Mon'.
  message 'oh boy'.
elseif today = 'Wed'.
  message 'Hump day'.
elseif today = 'Fri'.
  message 'TGIF'.
else.
  message 'get to work'.
endif.

The period is the statement teminator. Indentation and separte lines
are just to make it readable.

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


Re: New syntax for blocks

2009-11-17 Thread Russ P.
On Nov 17, 7:28 am, Jonathan Saxton jsax...@appsecinc.com wrote:
 On Thu, 12 Nov 2009 21:27:31 +0100, Bruno Desthuilliers wrote:
  Congratulations, you just reinvented one of the most infamous source of
  bugs in C, C++, Java, PHP, javascript and quite a few other languages.
  Believe it or not, but not allowing this in Python was a very deliberate
  design choice.

  Oh, but those hundreds of thousands of man-hours lost to bugs caused by
  assignment-as-an-expression is nothing compared to the dozens of man-
  minutes saved by having one fewer line of code!

  *wink*

 And if I ever find the genius who had the brilliant idea of using = to mean 
 assignment then I have a particularly nasty dungeon reserved just for him.  
 Also a foul-smelling leech-infested swamp for those language designers and 
 compiler writers who followed his example.  (Come to think of it, 
 plagiarizing a bad idea is probably the worse evil.)

There is absolutely nothing wrong with using = for assignment. The
problem in C was allowing an assignment within a conditional
expression. Now *that* was a bonehead idea! (Hingsight is 20/20, of
course.) Python does not allow that, so there is no problem. Nor do
most other languages allow it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Command line arguments??

2009-11-17 Thread Gerry
On Nov 17, 2:26 pm, Nobody nob...@nowhere.com wrote:
 On Mon, 16 Nov 2009 23:30:09 +, Rhodri James wrote:
  Quote the filenames or escape the spaces:

  C:\Python26\Python.exe C:\echo.py C:\New Folder\text.txt

  We've been living with this pain ever since windowed GUIs encouraged users  
  to put spaces in their file names (Apple, I'm looking at you!).  
  Fundamentally, if people want the pretty they have to live with the  
  consequences.

 We've been living with much worse ever since Unix allowed users to put
 not only spaces but even newlines in their filenames.

 At least, those of us who prefer works over sort of works most of the
 time have.

 Then Python 3 decides to pretend that argv and environ and stdin contain
 text rather than bytes, thereby ensuring that Python 2 will outlive Python
 3.

How about this:

lastarg =  .join(sys.argv[2:])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Code for finding the 1000th prime

2009-11-17 Thread Edward A. Falk
In article aecf2132-05a9-4144-81a8-952bb435e...@a32g2000yqm.googlegroups.com,
mrholtsr  mrhol...@gmail.com wrote:
I am absolutely new to python and barely past beginner in programming.
Also I am not a mathematician. Can some one give me pointers for
finding the 1000th. prime for a course I am taking over the internet
on Introduction to Computer Science and Programming. Thanks, Ray

OK, newbie soccer is over.

http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes

Everything you need is in there.

-- 
-Ed Falk, f...@despams.r.us.com
http://thespamdiaries.blogspot.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: Urwid 0.9.9 - Console UI Library

2009-11-17 Thread Ian Ward

Announcing Urwid 0.9.9
--

Urwid home page:
  http://excess.org/urwid/

Updated screen shots:
  http://excess.org/urwid/examples.html

Tarball:
  http://excess.org/urwid/urwid-0.9.9.tar.gz

RSS:
  http://excess.org/feeds/tag/urwid/


About this release:
===

This release includes many new features developed since the last major
release.  Urwid now supports 256 and 88 color terminals.  A new MainLoop
class has been introduced to tie together widgets, user input, screen
display and an event loop.  Twisted and GLib-based event loops are now
supported directly.  A new AttrMap class now allows mapping any
attribute to any other attribute.  Most of the code base has been
cleaned up and now has better documentation and testing.  Lots of other
improvements are listed below.


New in this release:


  * New support for 256 and 88 color terminals with raw_display
and html_fragment display modules

  * New palette_test example program to demonstrate high color
modes

  * New AttrSpec class for specifying specific colors instead of
using attributes defined in the screen's palette

  * New MainLoop class ties together widgets, user input, screen
display and one of a number of new event loops, removing the
need for tedious, error-prone boilerplate code

  * New GLibEventLoop allows running Urwid applications with GLib
(makes D-Bus integration easier)

  * New TwistedEventLoop allows running Urwid with a Twisted reactor

  * Added new docstrings and doctests to many widget classes

  * New AttrMap widget supports mapping any attribute to any other
attribute, replaces AttrWrap widget

  * New WidgetDecoration base class for AttrMap, BoxAdapter, Padding,
Filler and LineBox widgets creates a common method for accessing
and updating their contained widgets

  * New left and right values may be specified in Padding widgets

  * New command_map for specifying which keys cause actions such as
clicking Button widgets and scrolling ListBox widgets

  * New tty_signal_keys() method of raw_display.Screen and
curses_display.Screen allows changing or disabling the keys used
to send signals to the application

  * Added helpful __repr__ for many widget classes

  * Updated all example programs to use MainLoop class

  * Updated tutorial with MainLoop usage and improved examples

  * Renamed WidgetWrap.w to _w, indicating its intended use as a way
to implement a widget with other widgets, not necessarily as
a container for other widgets

  * Replaced all tabs with 4 spaces, code is now more aerodynamic
(and PEP 8 compliant)

  * Added saving of stdin and stdout in raw_display module allowing
the originals to be redirected

  * Updated BigText widget's HalfBlock5x4Font

  * Fixed graph example CPU usage when animation is stopped

  * Fixed a memory leak related to objects listening for signals

  * Fixed a Popen3 deprecation warning


About Urwid
===

Urwid is a console UI library for Python. It features fluid interface
resizing, UTF-8 support, multiple text layouts, simple attribute markup,
powerful scrolling list boxes and flexible interface design.

Urwid is released under the GNU LGPL.







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


ANN: Urwid 0.9.9 - Console UI Library

2009-11-17 Thread Ian Ward

Announcing Urwid 0.9.9
--

Urwid home page:
  http://excess.org/urwid/

Updated screen shots:
  http://excess.org/urwid/examples.html

Tarball:
  http://excess.org/urwid/urwid-0.9.9.tar.gz

RSS:
  http://excess.org/feeds/tag/urwid/


About this release:
===

This release includes many new features developed since the last major
release.  Urwid now supports 256 and 88 color terminals.  A new MainLoop
class has been introduced to tie together widgets, user input, screen
display and an event loop.  Twisted and GLib-based event loops are now
supported directly.  A new AttrMap class now allows mapping any
attribute to any other attribute.  Most of the code base has been
cleaned up and now has better documentation and testing.  Lots of other
improvements are listed below.


New in this release:


  * New support for 256 and 88 color terminals with raw_display
and html_fragment display modules

  * New palette_test example program to demonstrate high color
modes

  * New AttrSpec class for specifying specific colors instead of
using attributes defined in the screen's palette

  * New MainLoop class ties together widgets, user input, screen
display and one of a number of new event loops, removing the
need for tedious, error-prone boilerplate code

  * New GLibEventLoop allows running Urwid applications with GLib
(makes D-Bus integration easier)

  * New TwistedEventLoop allows running Urwid with a Twisted reactor

  * Added new docstrings and doctests to many widget classes

  * New AttrMap widget supports mapping any attribute to any other
attribute, replaces AttrWrap widget

  * New WidgetDecoration base class for AttrMap, BoxAdapter, Padding,
Filler and LineBox widgets creates a common method for accessing
and updating their contained widgets

  * New left and right values may be specified in Padding widgets

  * New command_map for specifying which keys cause actions such as
clicking Button widgets and scrolling ListBox widgets

  * New tty_signal_keys() method of raw_display.Screen and
curses_display.Screen allows changing or disabling the keys used
to send signals to the application

  * Added helpful __repr__ for many widget classes

  * Updated all example programs to use MainLoop class

  * Updated tutorial with MainLoop usage and improved examples

  * Renamed WidgetWrap.w to _w, indicating its intended use as a way
to implement a widget with other widgets, not necessarily as
a container for other widgets

  * Replaced all tabs with 4 spaces, code is now more aerodynamic
(and PEP 8 compliant)

  * Added saving of stdin and stdout in raw_display module allowing
the originals to be redirected

  * Updated BigText widget's HalfBlock5x4Font

  * Fixed graph example CPU usage when animation is stopped

  * Fixed a memory leak related to objects listening for signals

  * Fixed a Popen3 deprecation warning


About Urwid
===

Urwid is a console UI library for Python. It features fluid interface
resizing, UTF-8 support, multiple text layouts, simple attribute markup,
powerful scrolling list boxes and flexible interface design.

Urwid is released under the GNU LGPL.







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


Re: Code for finding the 1000th prime

2009-11-17 Thread Terry Reedy



On Sun, 15 Nov 2009, mrholtsr wrote:


I am absolutely new to python and barely past beginner in programming.
Also I am not a mathematician. Can some one give me pointers for
finding the 1000th. prime for a course I am taking over the internet
on Introduction to Computer Science and Programming. Thanks, Ray


Now for a serious answer ;-)

The intent of the problem is that you write a function prime_n(n) that 
returns the nth prime, where 2 is the first. This is different from 
prime(n), which would return True/False depending on whether n is a 
prime or not. Then you are to execute prime_n(1000) and submit that.


The person who set the problem expects that you will have learned and 
still remember the definition of prime numbers and a few basic facts 
about them. Or that you will look these up on a site such as Wikipedia. 
Since you are not taking a math course, you should expect that the basic 
facts will be enough.


For this problem, the relevant fact is that there is no formula that 
will directly compute the nth prime from n. Instead, one must generate 
the first, the second, the third, , until reaching the nth. The 
easiest and direct way to do this is to use primes 1 to i to test 
whether counts greater than prime i are primes, until you find the 
(i+1)th prime.


You may find references to the Sieve of Eratosthenes. It generates all 
the primes up to a certain number N by testing prime divisors in a 
different order. But to use it find the nth, one has to guess that some 
N will be larger than the nth, run the Sieve, and see whether you got 
the nth or have to try a larger value of N. For the 1000th, it turns out 
that N=1 works. In general picking an N such that N * log(N) is 
'comfortably' larger than n will work. But this guessing is not actually 
necessary in Python which has *expandable* arrays.


A different approach, at least as difficult, is to write a program that 
looks up the answer by accessing a public database of primes.

http://en.wikipedia.org/wiki/List_of_primes
lists some of these in its External Links section.

Terry Jan Reedy

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


Anything equivalent to cassert in C++?

2009-11-17 Thread Peng Yu
There are some assertion code (testing if a condition is false, if it
is false, raise an Error object) in my python, which is useful when I
test my package.  But such case would never occur when in the produce
code. If I keep them in if statement, it will take some runtime. I'm
wondering what is the practice that take care of the assertion code in
python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python gui builders

2009-11-17 Thread Joel Davis
On Nov 16, 5:06 am, me not_h...@nowhere.com wrote:
 Good People

 I do not write stuff for humans, as it has been my job to remove
 humans from the loop. But I have to make a front end to a
 component database where everything was built in Python.

 I have looked at the Tk stuff that is built into Python - not
 acceptable. So looking at wxGlade, Boa Constructor, Python Card.
 Also looked at the frames/forms created with QtDesigner, which
 can be used by Python via pyuic. BlackAdder IDE seems to have
 this built-in, but am loathe to buy into another GUI tool for a
 single job.

 I have not been able to find a decent Python gui builder. The
 last time I did gui garbage was with Borland C++ Builder which
 was ok because I was only using win boxen for that project. This
 time I am using both Linux and Win.

 What Python gui builder is well supported, does not require me
 to learn another framework/library, and can crank out stuff for
 multiple platforms ?

 thanks much,
 me

Glade is pretty easy to use, especially for a simple front end, if you
already know python, then the amount of GTK you'd have to learn would
be very minimal (5-15 minute crash course in it should suffice.) build
your GUI in Glade, link the python code to the xml file, and the go
back to coding non-gui stuff in no time. The Glade utility is free
software so there's no expense (unless you get charged by the byte on
your downloads.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python gui builders

2009-11-17 Thread Ben Finney
Scott David Daniels scott.dani...@acm.org writes:

 Well, let's see. You want to do gui work without learning things. Good
 luck with that. If you discover how, I'd like to learn tensor analysis
 without using symbols or operations more complex than addition and
 subtraction. Maybe your groundwork can help me out with that.

 I must be in a really cranky mood today.

Yeah, it seems that way. Best to let such replies stew in your “Drafts”
folder, get the catharsis from having vented your frustration, then
delete them unsent once you feel better. Works wonders for me :-)

-- 
 \  “If society were bound to invent technologies which could only |
  `\   be used entirely within the law, then we would still be sitting |
_o__)   in caves sucking our feet.” —Gene Kan, creator of Gnutella |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python gui builders

2009-11-17 Thread Tim Daneliuk
Simon Hibbs wrote:
 On 16 Nov, 10:06, me not_h...@nowhere.com wrote:
 
 What Python gui builder is well supported, does not require me
 to learn another framework/library, and can crank out stuff for
 multiple platforms ?
 
 You're looking for a framework/library that doesn't require you to
 learn it. OK
 
 I've had this problem for a few years. I've tried PythonCard,
 WxWidgets with WxDesigner, BoaConstructor, etc. None of them come
 anywhere close to PyQT/QTDesigner.
 
 Dion't get Blackadder It hasn't been updated for several years and is
 a dead project. In any case it uses QTDesigner for GUI layout anyway.
 You're better off using Eric or Wing if you want a decent IDE.
 
 QT does have a learning curve of course, but you get a lot of power
 back in return for the investment. I'm just coming to grips with it's
 MVC framework and the book Rapid GUI Programming with Python and Qt
 is very helpful with that.
 
 I wouldn't completely dismiss Tkinter. It's too simple for complex
 GUIs but I still think it has it's place for basic utilities.
 
 Simon Hibbs

+1 Tkinter for the simple stuff

-- 

Tim Daneliuk tun...@tundraware.com
PGP Key: http://www.tundraware.com/PGP/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Anything equivalent to cassert in C++?

2009-11-17 Thread Simon Forman
On Tue, Nov 17, 2009 at 4:19 PM, Peng Yu pengyu...@gmail.com wrote:
 There are some assertion code (testing if a condition is false, if it
 is false, raise an Error object) in my python, which is useful when I
 test my package.  But such case would never occur when in the produce
 code. If I keep them in if statement, it will take some runtime. I'm
 wondering what is the practice that take care of the assertion code in
 python.

Read the manual:

http://docs.python.org/reference/simple_stmts.html#the-assert-statement

In the current implementation, the built-in variable __debug__ is
True under normal circumstances, False when optimization is requested
(command line option -O). The current code generator emits no code for
an assert statement when optimization is requested at compile time.

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


Re: Command line arguments??

2009-11-17 Thread Nobody
On Tue, 17 Nov 2009 11:47:46 -0800, Gerry wrote:

 How about this:
 
 lastarg =  .join(sys.argv[2:])

What about it?

IOW, why would you want to do that?

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


Beautifulsoup code that is not running

2009-11-17 Thread Zeynel
Hello,

Please help with this code suggested in the beautifulsoup group
http://groups.google.com/group/beautifulsoup/browse_frm/thread/d288555c6992ceaa

 from BeautifulSoup import BeautifulSoup

 soup = BeautifulSoup (file(test.html).read())
 title = soup.find('title')
 titleString = title.string
 open('extract.text', 'w').write(titleString)

This runs without an error, but nothing is written into the
extract.text file. test.html has title/title tags in it.

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


Re: python simply not scaleable enough for google?

2009-11-17 Thread David Cournapeau
On Wed, Nov 18, 2009 at 5:48 AM, Paul Rubin
http://phr...@nospam.invalid wrote:


 What about Git?  Some people prefer it.

Git is an interesting example, because it both really pushes
performance into its core structure and reasonably complete
implementations exist in other languages. In particular, jgit is
implemented in java by one of the core git developer, here is what he
has to say:

http://marc.info/?l=gitm=124111702609723w=2

I found the comment on optimizing 5% here and 5 % there interesting.
It is often claimed that optimization should be done after having
found the hotspot, but that does not always apply, and I think git is
a good example of that.

In those cases, using python as the main language does not work well,
at least in my experience. Rewriting the slow parts in a compiled
language only works if you can identify the slow parts, and even in
numerical code, that's not always possible (this tends to happen when
you need to deal with many objects interacting together, for example).

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


Re: ast manipulation

2009-11-17 Thread Terry Reedy

Tsize wrote:

Hello,

I am hoping for a little help.  I have been playing with the python
ast module and have run into
an issue that I need a little push on.  I would like to be able to
change a specific element in a
specific node in an ast then compile the resulting ast.


If you can identify the specific nodes you want to change, no problem


 Consider the simplified example below
with its output. In this example I would like a way to change a
specific addition operation.  With the NodeTransformer I see how to
change every addition operator but not how to change a specific one.


Which specific one or one?


I would like this to work on both the 2.6 and 3.1 branches.  Ideally I
would like to read a file, count the instances of an operation of
interest and then use an index to make the changes.


If 'specific one' means number i, great. In not, not.


I am probably missing something simple but I am lost right now.


You have not said what 'specific one' means.
Nor what your general goal is, why you want to change asts.


import ast

class SwitchMinusPlus(ast.NodeTransformer):

def visit_BinOp(self, node):
node = self.generic_visit(node)
if isinstance(node.op, ast.Add):


  if isinstance(node.op, ast.Add) and isspecificnode(node):


node.op = ast.Sub()
return node

myfile = open('trivial.py').read()
print myfile
tree = compile(myfile, 'string', 'exec', ast.PyCF_ONLY_AST)
print ast.dump(tree, annotate_fields=False, include_attributes=False)
node = SwitchMinusPlus().visit(ast.parse(myfile))
print ast.dump(node, annotate_fields=False, include_attributes=False)

Which gives the following output:  Note that this code changes the
addition operator to an
subtraction operator at the AST level for every instance.

a = 8
b = 6
c = b + a
d =  c + a
Module([Assign([Name('a', Store())], Num(8)), Assign([Name('b', Store
())], Num(6)),
Assign([Name('c', Store())], BinOp(Name('b', Load()), Add(), Name('a',
Load(,
Assign([Name('d', Store())], BinOp(Name('c', Load()), Add(), Name('a',
Load(])

Module([Assign([Name('a', Store())], Num(8)), Assign([Name('b', Store
())], Num(6)),
Assign([Name('c', Store())], BinOp(Name('b', Load()), Sub(), Name('a',
Load(,
Assign([Name('d', Store())], BinOp(Name('c', Load()), Sub(), Name('a',
Load(])


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


Re: Vim breaks after Python upgrade

2009-11-17 Thread Terry Reedy

NickC wrote:

Perhaps OT, but I figure here is where people have seen this commonly.

I upgraded Python from my distro's default of 2.5.2 to 2.6.2.  Vim is now 
complaining every startup about missing exec libraries, presumably as 
some plugins run some python code on initialisation.  I'm guessing vim is 
complaining as it was compiled with python support, and that was 2.5.2, 
and the compiled-in python library locations no longer exist.


I believe you should have added 2.6.2 as an alternate installation and 
left 2.5.x alone. There have been several threads discussing this.


I compiled a new vim, so things are ok-ish, but now my system is even 
further away from standard distro.  I'm also a little surprised vim is so 
clunky as to use hard-coded locations.  Do I really have to compile a new 
vim every python upgrade?


Not if you add rather than substitute.


'strings vim' shows some ascii that could be the python library 
locations.  Being quite ignorant of how the linux loader works, could I in 
future use sed on the vim binary to change every string of 2.5.2 to 
2.6.2, or are the library locations used by the loader coded in binary 
rather than ascii (and so, harder to find)?


Thanks,



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


Pydev 1.5.1 Released

2009-11-17 Thread Fabio Zadrozny
Hi All,

Pydev 1.5.1 has been released

Details on Pydev: http://pydev.org
Details on its development: http://pydev.blogspot.com

Release Highlights:
---

* Improvements in the AST rewriter
* Improvements on the refactoring engine:
  o No longer using BRM
  o Merged with the latest PEPTIC
  o Inline local available
  o Extract method bug-fixes
  o Extract local on multi-line
  o Generating properties using coding style defined in preferences
  o Add after current method option added to extract method
  o A bunch of other corner-case situations were fixed
* Bug-fixes:
  o Minor editor improvements
  o Adding default forced builtins on all platforms (e.g.: time,
math, etc) which wouldn't be on sys.builtin_module_names on some
python installations
  o Adding 'numpy' and 'Image' to the forced builtins always
  o Ctrl+1: Generate docstring minor fixes
  o Ctrl+1: Assign to local now follows coding style preferences properly
  o Exponential with uppercase E working on code-formatting
  o When a set/get method is found in code-completion for a java
class an NPE is no longer thrown
  o Backspace properly treated in block mode
  o Setting IRONPYTHONPATH when dealing with Iron Python (projects
could not be referenced)
  o No longer giving spurious 'statement has no effect' inside of
lambda and decorators
  o Fixed new exec in python 3k
  o Fixed NPE when breakpoint is related to a resource in a removed project
  o Fixed import problem on regexp that could lead to a recursion.
  o No longer giving NPE when debugging with the register view open
  o List access be treated as __getitem__() in the list -- patch
from Tassilo Barth
  o Fix for invalid auto-self added when typing


What is PyDev?
---

PyDev is a plugin that enables users to use Eclipse for Python, Jython
and Iron Python development -- making Eclipse a first class Python IDE
-- It comes with many goodies such as code completion, syntax
highlighting, syntax analysis, refactor, debug and many others.


Cheers,

-- 
Fabio Zadrozny
--
Software Developer

Aptana
http://aptana.com/python

Pydev - Python Development Environment for Eclipse
http://pydev.org
http://pydev.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: PyGUI 2.1

2009-11-17 Thread greg

r wrote:


I really like this!

But after looking over your pyGUI it does seem that Tkinter has a
richer widget set.


PyGUI is a work in progress. I plan to add more widgets,
but it will take a while to catch up with what's available
in Tkinter and other GUI toolkits.

I tend to add widgets as and when I need them for something
I'm doing. If anyone has a widget they particularly want,
let me know and I'll try to give it priority.
--
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: Urwid 0.9.9 - Console UI Library

2009-11-17 Thread Daniel Fetchinson
On 11/16/09, Ian Ward i...@excess.org wrote:
 Announcing Urwid 0.9.9
 --

 Urwid home page:
http://excess.org/urwid/

 Updated screen shots:
http://excess.org/urwid/examples.html

How did you make the html 'screenshots'? I guess you have some kind of
urwid2html tool or some such or is it plain ncurses?

Urwid is really cool!

Cheers,
Daniel

 Tarball:
http://excess.org/urwid/urwid-0.9.9.tar.gz

 RSS:
http://excess.org/feeds/tag/urwid/


 About this release:
 ===

 This release includes many new features developed since the last major
 release.  Urwid now supports 256 and 88 color terminals.  A new MainLoop
 class has been introduced to tie together widgets, user input, screen
 display and an event loop.  Twisted and GLib-based event loops are now
 supported directly.  A new AttrMap class now allows mapping any
 attribute to any other attribute.  Most of the code base has been
 cleaned up and now has better documentation and testing.  Lots of other
 improvements are listed below.


 New in this release:
 

* New support for 256 and 88 color terminals with raw_display
  and html_fragment display modules

* New palette_test example program to demonstrate high color
  modes

* New AttrSpec class for specifying specific colors instead of
  using attributes defined in the screen's palette

* New MainLoop class ties together widgets, user input, screen
  display and one of a number of new event loops, removing the
  need for tedious, error-prone boilerplate code

* New GLibEventLoop allows running Urwid applications with GLib
  (makes D-Bus integration easier)

* New TwistedEventLoop allows running Urwid with a Twisted reactor

* Added new docstrings and doctests to many widget classes

* New AttrMap widget supports mapping any attribute to any other
  attribute, replaces AttrWrap widget

* New WidgetDecoration base class for AttrMap, BoxAdapter, Padding,
  Filler and LineBox widgets creates a common method for accessing
  and updating their contained widgets

* New left and right values may be specified in Padding widgets

* New command_map for specifying which keys cause actions such as
  clicking Button widgets and scrolling ListBox widgets

* New tty_signal_keys() method of raw_display.Screen and
  curses_display.Screen allows changing or disabling the keys used
  to send signals to the application

* Added helpful __repr__ for many widget classes

* Updated all example programs to use MainLoop class

* Updated tutorial with MainLoop usage and improved examples

* Renamed WidgetWrap.w to _w, indicating its intended use as a way
  to implement a widget with other widgets, not necessarily as
  a container for other widgets

* Replaced all tabs with 4 spaces, code is now more aerodynamic
  (and PEP 8 compliant)

* Added saving of stdin and stdout in raw_display module allowing
  the originals to be redirected

* Updated BigText widget's HalfBlock5x4Font

* Fixed graph example CPU usage when animation is stopped

* Fixed a memory leak related to objects listening for signals

* Fixed a Popen3 deprecation warning


 About Urwid
 ===

 Urwid is a console UI library for Python. It features fluid interface
 resizing, UTF-8 support, multiple text layouts, simple attribute markup,
 powerful scrolling list boxes and flexible interface design.

 Urwid is released under the GNU LGPL.







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



-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python simply not scaleable enough for google?

2009-11-17 Thread greg

David Cournapeau wrote:


It is a bit odd to dismiss python is slow by saying that you can
extend it with fortran. One of the most significant point of python
IMO is its readability, even for people not familiar with it, and
that's important when doing scientific work. Relying on a lot of
compiled libraries goes against it.


If it were necessary to write a new compiled library every
time you wanted to solve a new problem, that would be true.
But it's not like that if you pick the right libraries.

NumPy, for example, is *extremely* flexible. Someone put
in the effort, once, to write it and make it fast -- and
now an endless variety of programs can be written very easily
in Python to make use of it.

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


  1   2   3   >