Re: How to access elemenst in a list of lists?

2011-05-10 Thread Algis Kabaila
On Tuesday 10 May 2011 11:25:59 Terry Reedy wrote:
> On 5/9/2011 8:44 PM, Algis Kabaila wrote:
> > The method of double indexing in the manner
> > a[i][j]
> > for the (i, j) -th element of multi-dimensional array is
> > well known and widely used. But how to enable the
> > "standard" matrix notation a[i, j]
> > in Python 3.2 in the manner of numpy (and other matrix
> > packages)? Is it subclassing of "special methods"
> > 
> > __getitem__() # to get
> > 
> > __setitem__()  # to set
> 
> Yes.
> 
> class listwrap:
>  def __init__(self, lis):
>  self._list = lis
>  def __getitem__(self, dex):
>  i,j = dex
>  return self._list[i][j]
>  # __setitem__: exercise for reader
> 
> l = listwrap([[1,2,3],['a','b','c']])
> print(l[0,2],l[1,0])
> # 3 a
> 
> IMO, Hardly worth it for two dimensions.

Terry,

Thank you for your response.  I have to confess that I do have 
the cludge of an answer to my own quesion, but it is a cludge; 
Your method looks much better, though I don't think it is 
complete - this subclassing of __getitem__ appears to stop 
simple list access, i.e. if li = [1, 2 ,3], it seems to me that 
print(li[2])
would raise an exception, no?
However,  the method that you have indicated is a neat way to 
solve the problem -- thank you for it!

OldAl

PS: just to confirm your method and the limitation of it "as 
is": It is NOT a criticism, just a mere observation,  Good 
method, nice examle, great contribution!

>>> 
3 a
Showing limitation of "as is" in this
great method for access of list of lists
Traceback (most recent call last):
  File "/dat/work/linalg/dim2.py", line 15, in 
print(ll[1])
  File "/dat/work/linalg/dim2.py", line 6, in __getitem__
i,j = dex
TypeError: 'int' object is not iterable
>>> 
-- 
Algis
http://akabaila.pcug.org.au/StructuralAnalysis.pdf
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to access elemenst in a list of lists?

2011-05-10 Thread Algis Kabaila
On Tuesday 10 May 2011 17:22:42 Algis Kabaila wrote:
> On Tuesday 10 May 2011 11:25:59 Terry Reedy wrote:
> > On 5/9/2011 8:44 PM, Algis Kabaila wrote:
> > > The method of double indexing in the manner
> > > a[i][j]
> > > for the (i, j) -th element of multi-dimensional array is
> > > well known and widely used. But how to enable the
> > > "standard" matrix notation a[i, j]
> > > in Python 3.2 in the manner of numpy (and other matrix
> > > packages)? Is it subclassing of "special methods"
> > > 
> > > __getitem__() # to get
> > > 
> > > __setitem__()  # to set
> > 
> > Yes.
> > 
> > class listwrap:
> >  def __init__(self, lis):
> >  self._list = lis
> >  
> >  def __getitem__(self, dex):
> >  i,j = dex
> >  return self._list[i][j]
> >  
> >  # __setitem__: exercise for reader
> > 
> > l = listwrap([[1,2,3],['a','b','c']])
> > print(l[0,2],l[1,0])
> > # 3 a
> > 
> > IMO, Hardly worth it for two dimensions.
> 
> Terry,
> 
> Thank you for your response.  I have to confess that I do
> have the cludge of an answer to my own question, but it is a
> cludge; Your method looks much better, though I don't think
> it is complete - this subclassing of __getitem__ appears to
> stop simple list access, i.e. if li = [1, 2 ,3], it seems to
> me that print(li[2])
> would raise an exception, no?
> However,  the method that you have indicated is a neat way to
> solve the problem -- thank you for it!
> 
> OldAl
> 
> PS: just to confirm your method and the limitation of it "as
> is": It is NOT a criticism, just a mere observation,  Good
> method, nice example, great contribution!
> 
> 
> 3 a
> Showing limitation of "as is" in this
> great method for access of list of lists
> Traceback (most recent call last):
>   File "/dat/work/linalg/dim2.py", line 15, in 
> print(ll[1])
>   File "/dat/work/linalg/dim2.py", line 6, in __getitem__
> i,j = dex
> TypeError: 'int' object is not iterable

Apologies for accidental mail sending before it was completed:
The original code and additional data is as follows 

l = listwrap([[1,2,3],['a','b','c']])
print(l[0,2],l[1,0])
print('''Showing limitation of "as is" in this
great method for access of list of lists''')
ll = listwrap([1,2,3])
print(ll[1])

Above is the output.
Thank you again,

Al.
-- 
Algis
http://akabaila.pcug.org.au/StructuralAnalysis.pdf
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to access elemenst in a list of lists?

2011-05-10 Thread Terry Reedy

On 5/10/2011 3:22 AM, Algis Kabaila wrote:

On Tuesday 10 May 2011 11:25:59 Terry Reedy wrote:



 > class listwrap:
 >  def __init__(self, lis):
 >   self._list = lis
 >  def __getitem__(self, dex):
 >   i,j = dex
 >   return self._list[i][j]

 > # __setitem__: exercise for reader



 > l = listwrap([[1,2,3],['a','b','c']])
 > print(l[0,2],l[1,0])
 > # 3 a



Thank you for your response. I have to confess that I do have the cludge
of an answer to my own quesion, but it is a cludge; Your method looks
much better, though I don't think it is complete - this subclassing of
__getitem__ appears to stop simple list access, i.e. if li = [1, 2 ,3],
it seems to me that print(li[2]) would raise an exception, no?


Yes, there really should be a guard condition: if isinstance(x tuple)
or try: len(x) == 2. A __getattr__ method could be added to forwar other 
list methods to the wrapped list. One could try subclassing instead of 
wrapping, but some special methods have a fast path access for builtins 
that bypasses subclass methods. I think __getitem__ may be one such. 
Wrapping is safe in that respect.


--
Terry Jan Reedy

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


Re: What other languages use the same data model as Python?

2011-05-10 Thread Gregory Ewing

Steven D'Aprano wrote:

All very good, but that's not what takes place at the level of Python 
code. It's all implementation.


Actually, you're right. What I've presented is a paper-and-pencil
implementation of the Python data model. Together with a set of
rules for manipulating the diagram under the direction of Python
code, you have a complete implementation of Python that you can
execute in your head.

And you NEED such an implementation in order to reason correctly
about Python programs under all circumstances.

I find it very difficult to imagine *any* implementation of
Python, computer-based or otherwise, that doesn't have something
equivalent to references. Whether you call them that, or pointers,
or arrows, or object bindings, or something else, the concept
needs to be there in some form.

But surely, if a = 1234 creates a reference from a to the big 
box 1234, then b = a should create a reference from b to the box a?


 +-+
   +---+ | |
 a | --+>| |
   +---+ | |
 ^   +-+
 |
   +-|-+
 b | | |
   +---+


You can't expect anyone to draw correct conclusions from the
diagram alone; you also need to explain the rules for manipulating
the diagram under control of Python code.

Here, the explanation goes something like this:

1. The right hand side of an assignment denotes a big box. The
literal 1234 in a program denotes a big box containing the integer
value 1234.

2. The left hand side of an assignment denotes a little box. The
effect of an assignment is to make the arrow from the left hand
side's little box point to the big box denoted by the right hand
side.

So the assignment a = 1234 results in

  +-+
+---+ | |
  a | --+>|   1234  |
+---+ | |
  +-+

3. When a name is used on the right hand side, it denotes whichever
big box is pointed to by the arrow from its little box. So given
the above diagram, the assignment b = a results in

  +-+
+---+ | |
  a | --+>|   1234  |
+---+ | |
  +-+
 ^
+---+|
  b | --+-
+---+

Furthermore, from rule 2 alone it's evident that no assignment
can ever make an arrow lead from one little box to another
little box. Arrows can only lead from a little box to a big
box.

That's how it works in C and Pascal (well, at least with the appropriate 
type declarations).


Um, no, it doesn't, really. There's no way 'b = a' can give
you that in C; you would have to write 'b = &a'. And you
couldn't do it at all in standard Pascal, because there is
no equivalent to the & operator there.

Your model is closer to what the CPython implementation 
actually does,


I think it's close -- actually, I would say isomorphic --
to what *any conceivable* Python implementation would do in
some form.


n = len('hello world')

What about outside len? Where's the little box 
pointing to 'hello world'?



So it seems your model fails to deal with sufficiently anonymous objects.


Anonymous objects are fine. You just draw a little box and
don't write any label beside it. Or you don't bother drawing
a little box at all and just draw a big box until such time
as some little box that you care about needs to point to it.

If that's a problem, then you have the same problem talking
about names bound to objects. An anonymous object obviously
doesn't have any name bound to it. So you have to admit that
objects can exist, at least temporarily, without being bound
to anything, or bound to some anonymous thing.

Both the call to len and the call to func push their results onto the 
stack. There's no little box pointing to the result.


If you want to model things at that level of detail, then the
stack itself is an array of little boxes inside a frame object.
And the frame object is pointed to by a little box in its
calling frame object, etc. until you get to some global little
box, that doesn't have a name in Python, but exists somewhere
and keeps the chain of active stack frames alive.

But you don't have to draw any of that if you don't want to.

For practical reasons, there must be some sort of 
indirection. But that's implementation and not the VM's model.


No, it's not just implementation. Indirection is needed for
*correct semantics*, not just practicality.

There is a problem with my model of free-floating objects in space: it 
relies on objects being able to be in two places at once,


Yes, that's the point I'm trying to make. While it might be
possible to make such a model wor

Re: Overuse of try/except/else?

2011-05-10 Thread Jean-Michel Pichavant

James Mills wrote:

On Tue, May 10, 2011 at 10:40 AM, Kyle T. Jones
 wrote:
  

It has been hard for me to determine what would constitute overuse.



A rule of thumb I always follow and practice is:

"Let the error lie where it occurred."

or

"Don't hide errors.".

It's good practice to follow IHMO as it makes it easier to find
the source of defects in your function(s). If you constantly
do things like try/except/log then it makes finding the source
harder and may make it harder to identify what caused it.
  

You can reraise the exception without loosing the stack trace.

try:
...
except SomeException, exc:
log(exc)
print 'Hello world'
raise # "raise exc" would loose the original stack trace

JM

PS : "code that crashes could use improvement, but incorrect code that 
doesn’t crash is a horrible nightmare." (I don't know the author)


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


Re: What other languages use the same data model as Python?

2011-05-10 Thread Chris Angelico
On Tue, May 10, 2011 at 12:29 AM, Steven D'Aprano
 wrote:
> If objects can be in two places at once, why can't names? Just because.

Because then you'd need some way to identify which object you wanted
to refer to - something like name[0] and name[1]. A tuple is one
effective way to do this (sort of - actually, the name points at the
tuple and the tuple points at each of the objects).

On Tue, May 10, 2011 at 12:47 PM, MRAB  wrote:
> I had heard something about the meaning of the word "gift", so I
> checked in Google Translate. For Swedish "gift" it says:
>
> noun
> 1. POISON
> 2. VENOM
> 3. TOXIN
> 4. VIRUS

Beware of Swedes bearing gifts!

On Tue, May 10, 2011 at 5:41 PM, Gregory Ewing
 wrote:
> Anonymous objects are fine. You just draw a little box and
> don't write any label beside it. Or you don't bother drawing
> a little box at all and just draw a big box until such time
> as some little box that you care about needs to point to it.
>
> If that's a problem, then you have the same problem talking
> about names bound to objects. An anonymous object obviously
> doesn't have any name bound to it. So you have to admit that
> objects can exist, at least temporarily, without being bound
> to anything, or bound to some anonymous thing.

There has to be a way to get from some mythical "home" location (which
we know in Python as locals()+globals()+current expression - the
"current namespace") to your object. That might involve several names,
or none at all, but if there's no such path, the object is
unreferenced and must be disposed of. IIRC that's not just an
implementation detail (the garbage collector), but a language
guarantee (that the __del__ method will be called).

Names are immaterial to that.

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


Re: A suggestion for an easy logger

2011-05-10 Thread TheSaint
Vinay Sajip wrote:

> No, you can pass keyword arguments in any order - that's what makes
> them keyword, as opposed to positional, arguments.

I getting puzzled :)
==code==
myself@laptop-~> python
Python 3.2 (r32:88445, Apr 15 2011, 11:09:05) 
[GCC 4.5.2 20110127 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import logging, sys
>>> logging.basicConfig(level=logging.DEBUG, format='%(message)s')
>>> sh = logging.StreamHandler(sys.stdout)
>>> sh.terminator = ''
>>> logging.getLogger().addHandler(sh)
>>> logging.debug('here we are')
here we are
here we are>>> print(logging.__version__)
0.5.1.2
==code==

Terminator is removed, but as you stated it's doing double print-out
One more point is, if you'd have the time to look back to one of the first 
posts, that the leading *"DEBUG:root:"* doesn't show :-/
It's reported herein the version of Python and logging module's version.

For my thinking I'd go to look into the code and docs as well, to understand 
what I should do to have my 4 way of logging.
I repeat, I'm very new on using logging module, but I should go in that way, 
it isn't necessary to re-invent the wheel :).
Also I'd like to say that's only for my own learning, which I do as hobby.

-- 
goto /dev/null 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: can't get urllib2 or httplib to work with tor & privoxy

2011-05-10 Thread Chris Angelico
On Tue, May 10, 2011 at 4:20 AM, Bob Fnord  wrote:
> Both methods give me a 503 error...

As a networking geek, my first thought would be to fire up a tiny
little "snoop server" and see what, exactly, the two methods are
doing. (Ignore the HTTPS options as they're more complicated to snoop
on; you're almost certainly going to see exactly the same on the
HTTP.)

A snoop server is simply an HTTP server that dumps its requests to
stdout or a file, utterly raw. You can write one in Python fairly
easily, or use another program; if I'm working on Windows, I'll
generally use my own RosMud MUD client, but you'll be able to whip up
a cross-platform one in half a page of code in any decent high level
language. I recommend you work at the sockets level, rather than using
an HTTP library, unless you have one that can emit the entire request,
exactly as it came from the client.

Once you've found the difference(s) between Lynx and your script, you
can see what's causing the 503 (Service Unavailable) error; it may be
that you need to authenticate with the proxy.

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


Re: How to access elemenst in a list of lists?

2011-05-10 Thread Algis Kabaila
On Tuesday 10 May 2011 17:44:44 Terry Reedy wrote:
> On 5/10/2011 3:22 AM, Algis Kabaila wrote:
> > On Tuesday 10 May 2011 11:25:59 Terry Reedy wrote:
> >  > class listwrap:
> >  >  def __init__(self, lis):
> >  >   self._list = lis
> >  >  
> >  >  def __getitem__(self, dex):
> >  >   i,j = dex
> >  >   return self._list[i][j]
> >  > 
> >  > # __setitem__: exercise for reader
> >  > 
> >  > l = listwrap([[1,2,3],['a','b','c']])
> >  > print(l[0,2],l[1,0])
> >  > # 3 a
> > 
> > Thank you for your response. I have to confess that I do
> > have the cludge of an answer to my own quesion, but it is
> > a cludge; Your method looks much better, though I don't
> > think it is complete - this subclassing of __getitem__
> > appears to stop simple list access, i.e. if li = [1, 2
> > ,3], it seems to me that print(li[2]) would raise an
> > exception, no?
> 
> Yes, there really should be a guard condition: if
> isinstance(x tuple) or try: len(x) == 2. A __getattr__
> method could be added to forwar other list methods to the
> wrapped list. One could try subclassing instead of wrapping,
> but some special methods have a fast path access for
> builtins that bypasses subclass methods. I think __getitem__
> may be one such. Wrapping is safe in that respect.

Actually, I am working on an array class that subclasses list. 
My interest is to have a module that deals with matrices with 
pure Python 3.2 or higher.  The class would need to deal with 
many different arrays and matrix operations between them.

In since Array subclasses list, any modifications of __getitem__ 
ir __setitem__ would naturally be in the array class and would 
in fact subclass the list special methods if implemented in the 
Array class.  And, to my chagrin, I do manage to mess it up...

Thanks for your bright suggestion,

OldAl.

-- 
Algis
http://akabaila.pcug.org.au/StructuralAnalysis.pdf
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Overuse of try/except/else?

2011-05-10 Thread Adam Tauno Williams
On Mon, 2011-05-09 at 19:40 -0500, Kyle T. Jones wrote:
> It has been hard for me to determine what would constitute overuse.

The chronic problem is under use; so I wouldn't worry much about it.

try/except should occur as often as is required for the application to
either deal gracefully with the condition or report *meaningful* error
messages to the user/administrator.

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


Re: Testing tools classification

2011-05-10 Thread rusi
On May 10, 8:55 am, "Gabriel Genellina" 
wrote:
> En Sat, 07 May 2011 02:21:02 -0300, rusi  escribió:
>
> > There is this nice page of testing tools taxonomy:
> >http://pycheesecake.org/wiki/PythonTestingToolsTaxonomy
>
> > But it does not list staf:http://staf.sourceforge.net/index.php.
>
> The good thing about wikis is, you can add it yourself.
>
> --
> Gabriel Genellina

Could not figure out how to get edit rights.
[Which is all for the good considering what a testing-ignoramus I
am :-) ]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Overuse of try/except/else?

2011-05-10 Thread Hans Georg Schaathun
On Tue, 10 May 2011 07:36:42 -0400, Adam Tauno Williams
   wrote:
:  On Mon, 2011-05-09 at 19:40 -0500, Kyle T. Jones wrote:
: > It has been hard for me to determine what would constitute overuse.
: 
:  The chronic problem is under use; so I wouldn't worry much about it.
: 
:  try/except should occur as often as is required for the application to
:  either deal gracefully with the condition or report *meaningful* error
:  messages to the user/administrator.

So overuse is really when you cannot do anything meaningful about 
the exception.  The two interesting questions are really
  1. where and when to catch a given exception
  2. at what stage of the development cycle catching a particular
(class of) exception should become a priority

There is a potential overuse of exceptions, where they are used for
quite ordinary and frequent (i.e. not exceptional) conditions, and
the information could be passed through the return value instead.
Exceptions is a very flexible, but also rather expensive means of
communications.  You can, actually, write any program using raise 
instead of return.  That would be overuse.

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


Re: What other languages use the same data model as Python?

2011-05-10 Thread Grant Edwards
On 2011-05-10, Gregory Ewing  wrote:
> Steven D'Aprano wrote:
>
>> It's just that the term "variable" is so useful and so familiar that it's 
>> easy to use it even for languages that don't have variables in the C/
>> Pascal/Fortran/etc sense.
>
> Who says it has to have the Pascal/Fortran/etc sense?

Because it's easier to communicate if everybody agrees on what a word
means.

-- 
Grant Edwards   grant.b.edwardsYow! The SAME WAVE keeps
  at   coming in and COLLAPSING
  gmail.comlike a rayon MUU-MUU ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: string formatting

2011-05-10 Thread Chris Angelico
On Wed, May 11, 2011 at 12:15 AM, Web Dreamer  wrote:
> I was unsure of the difference between deprecated and obsolete.
>
> So now, if I understand well, obsolete comes before deprecated, such that if
> a feature is obsolete it will be deprecated in an unknown future, after
> which it will be removed once it has been deprecated (a certain time after
> it was rendered obsolete)?
> (might need an aspirin to read that one :-) )
>
> So If I'm right, old string formatting "could" one day be deprecated but it
> is not yet?

I wouldn't say that obsolete features "will be" deprecated. That
expression makes little sense (I know, for I have seen it in eBay's
API documentation, and it did not fill me with joy). Deprecation is
(usually) a formal procedure that clearly states that a feature should
not be used. It may be accompanied by a strict cutoff ("will be
removed in version X"), or just left vague, but linting tools can
identify all use of deprecated features.

Obsolete, however, is simply a description. Sopwith Camels were
obsolete in the second world war, and VHS has been obsoleted by
optical disc media. However, if you wish to fly a Camel or play a VHS,
nothing's stopping you. The sky will still accept your Camel, and your
VHS player will still talk to your television. (The analogy breaks
down a bit in that your obsolete VHS player may be using a deprecated
cabling style, but it's coax that's deprecated, not VHS.) There's no
"projected end date" for them.

Generally, a feature is obsolete before it's deprecated, but
technically that's not a requirement, and API designers can sometimes
be quite arbitrary. On the other hand, obsolescence is quite informal,
and people can disagree about whether or not something is. (Hi Ken,
your continued use of inches is noted. Thank you.)

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


Re: What other languages use the same data model as Python?

2011-05-10 Thread Hans Georg Schaathun
On Tue, 10 May 2011 14:05:34 + (UTC), Grant Edwards
   wrote:
:  Because it's easier to communicate if everybody agrees on what a word
:  means.

Why should we agree on that particular word?  Are there any other words
we agree about?  Other key words, such as class, object, or function don't
have universal meanings.

:-)

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


Re: What other languages use the same data model as Python?

2011-05-10 Thread Grant Edwards
On 2011-05-10, Hans Georg Schaathun  wrote:
> On Tue, 10 May 2011 14:05:34 + (UTC), Grant Edwards
>   wrote:
>:  Because it's easier to communicate if everybody agrees on what a word
>:  means.
>
> Why should we agree on that particular word?  Are there any other words
> we agree about?  Other key words, such as class, object, or function don't
> have universal meanings.

And what do we mean by "agree"?

What do we mean by "mean"?

It's turtles all they down...

-- 
Grant Edwards   grant.b.edwardsYow!
  at   
  gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What other languages use the same data model as Python?

2011-05-10 Thread Chris Angelico
On Wed, May 11, 2011 at 1:16 AM, Grant Edwards  wrote:
> And what do we mean by "agree"?
>
> What do we mean by "mean"?
>
> It's turtles all they down...

When I use a word, it means just what I choose it to mean - neither
more nor less.
-- Humpty Dumpty.

Language is for communication. If we're not using the same meanings
for words, we will have problems.

Chris Angelico
PS. By "mean", I mean average. Except when I mean mean. But now I'm
just being mean.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What other languages use the same data model as Python?

2011-05-10 Thread Hans Georg Schaathun
On Wed, 11 May 2011 01:27:36 +1000, Chris Angelico
   wrote:
:  Language is for communication. If we're not using the same meanings
:  for words, we will have problems.

So if you adopt the word class to mean a type (or composite type),
as in python, what word would you use for a class of types (as in
haskell or ada)?

I think there are too many meanings and too few words ...

That's why some languages support overloading.

I am afraid we just need to cope with it, overloading I mean.

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


Re: What other languages use the same data model as Python?

2011-05-10 Thread Chris Angelico
On Wed, May 11, 2011 at 1:40 AM, Hans Georg Schaathun  
wrote:
> On Wed, 11 May 2011 01:27:36 +1000, Chris Angelico
>   wrote:
> :  Language is for communication. If we're not using the same meanings
> :  for words, we will have problems.
>
> So if you adopt the word class to mean a type (or composite type),
> as in python, what word would you use for a class of types (as in
> haskell or ada)?
>
> I think there are too many meanings and too few words ...
>
> That's why some languages support overloading.

Of course. Nobody ever said that one name had to point to one value... oh wait.

Yes, Virginia, there is overloading.

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


Re: scipy

2011-05-10 Thread Hans Georg Schaathun
On Sun, 8 May 2011 03:44:06 -0700 (PDT), pb
   wrote:
:  I', having trouble with scipy.  I have followed the instructions at
:  scipy website and have installed the following on my mac osx 10.6.6
: (...)
:  I'm assuming I have the wrong version of something, would that be
:  right?
:  Does anyone know how I can fix this?

I had the same problem, but assumed that it was more likely to be
a bug in the unit tests than a bug anywhere else.  But then I mainly
use linux boxen to run the stuff, so a bug on the mac installation
does not bother me much.  Installing software on a mac is just painful.


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


Non Programming in python

2011-05-10 Thread rusi
Sorry for a silly subject change: A better one will be welcome -- cant
think of a name myself.

There is this whole area of python that may be called the non-
programming side of programming:

Is there some central site where all such is put up?
What if any should such a bundle of things be called?

-

  | Area | Tool(s)|
  |--+|
  | packaging| distutils, setuptools, |
  |  | distutils2, distribute |
  |  | Native tools (eg apt)  |
  | versioning   | hg, git, bzr   |
  | multiple pythons | virtualenv |
  | ??   | tox|
  | testing  | unittest, nose, pytest |
  | build| scons, make... |
  | deployment   | fabric |

--
* Primary Development tools/aids

  1. Help
  2. Completion ('intellisense')
  3. Tags (Jumping)
  4. Refactoring
  5. Integration with 'non-programming' above (eg VCSes, packagers
etc)

* Other Development Tools
  - Debugger
  - Profiler
  - Heap Profiler
  - Coverage
-- 
http://mail.python.org/mailman/listinfo/python-list


Python-URL! - weekly Python news and links (May 10)

2011-05-10 Thread Cameron Laird
[This content provided by Gabriel Genellina, despite what the "From:"
line says.]

QOTW:  "Often, the cleverness of people is inversely proportional to
the
amount of CPU power and RAM that they have in their computer.

Unfortunately, the difficulty in debugging and maintaining code is
often
directly proportional to the cleverness exhibited by the original
programmer." - Irmen de Jong and Grant Edwards
   http://groups.google.com/group/comp.lang.python/t/58559ead6dc82448


   Looking for "The Coolest Python Recipe of All Times":
   http://groups.google.com/group/comp.lang.python/t/141fdde77caab932

   A nice and clever probabilistic data structure:
   http://groups.google.com/group/comp.lang.python/t/58559ead6dc82448

   Development tools and best practices (continued from previous
week):
   http://groups.google.com/group/comp.lang.python/t/836537e6c25cf027

   Things to be aware of when using dictionary views:
   http://groups.google.com/group/comp.lang.python/t/b9c6ded7522e7425

   Python3 and absolute/relative imports:
   http://groups.google.com/group/comp.lang.python/t/9470dbdacc138709

   Another gotcha when using import with packages:
   http://groups.google.com/group/comp.lang.python/t/961a90219a61e19d

   Fibonacci, recursion, and the 'P' conspiracy theory:
   http://groups.google.com/group/comp.lang.python/t/b713b14e3e0d9872

   The preferred way for string formatting:
   http://groups.google.com/group/comp.lang.python/t/f0cd2717ffe13560

   Checking if a list is empty - and how to think "the Python way":
   http://groups.google.com/group/comp.lang.python/t/d36dcd2e2e175d1e

   Classics never die: What other languages use the same data model as
Python?
   http://groups.google.com/group/comp.lang.python/t/4b8b0e06a2d5cfcc



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

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

   Planet Python:  you want to visit there:
   http://planet.python.org
   But don't confuse it with Planet SciPy:
   http://planet.scipy.org
   And don't confuse *that* with SciPyTip, a high-quality daily (!)
tip
   for the numerically-inclined:
   http://twitter.com/SciPyTip

   Python Insider is the official blog of the Python core development
   team:
   
http://pyfound.blogspot.com/2011/03/python-dev-launches-python-insider-blog.html

   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/
   Keep up with the PSF at "Python Software Foundation News":
   http://pyfound.blogspot.com

   The Python Papers aims to publish "the efforts of Python
enthusiasts":
   http://pythonpapers.org/

   Doug Hellman's "Module of the week" is essential reading:
   http://www.doughellmann.com/PyMOTW/

   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 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.org&group=gmane.comp.python.devel&sort=date

   nullege is an interesting search Web application, with the
intelligence
   to distinguish between Python code and comments.  It provides what
   appear to be relevant results, and demands neither Java nor CSS be
   enabled:
   http://www.nullege.com

   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:
   http://code.activestate.com/recipes/langs/python/

Re: Dictionary Views -- good examples? [was Re: Python 3 dict question]

2011-05-10 Thread Ethan Furman

Ian Kelly wrote:

On Fri, May 6, 2011 at 4:49 PM, Ethan Furman wrote:

Anybody care to chime in with their usage of this construct?


You should start with PEP 3106.  The main idea is that dict.keys() and
dict.items() can be treated as frozensets, while still being more
lightweight than lists.  That lets you do nifty things like "a.keys()
== b.keys()" which, if a and b are Python 3 dicts, will tell you
whether they contain the same keys.


Cool, thanks.

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


Re: string formatting

2011-05-10 Thread Raymond Hettinger
> Which is the preferred way of string formatting?
>
> (1) "the %s is %s" % ('sky', 'blue')
>
> (2) "the {0} is {1}".format('sky', 'blue')
>
> (3) "the {} is {}".format('sky', 'blue')
>
> As I know (1) is old style. (2) and (3) are new but (3) is only
> supported from Python 2.7+.
>
> Which one should be used?


Sometimes, I use both ;-)
That can save you from ugly escapes such as %%s or {{0}}.

Here's an example from the standard library:
http://hg.python.org/cpython/file/7254c03b7180/Lib/collections.py#l235

Note the template has both {typename} formatting for the first pass
and %r style formatting in the generated code.

Raymond


follow my tips and recipes on twitter: @raymondh
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3 dict question

2011-05-10 Thread Raymond Hettinger
On May 6, 12:40 pm, dmitrey  wrote:
> hi all,
> suppose I have Python dict myDict and I know it's not empty.
> I have to get any (key, value) pair from the dict (no matter which
> one) and perform some operation.
> In Python 2 I used mere
> key, val = myDict.items()[0]
> but in Python 3 myDict.items() return iterator.
> Of course, I could use
> for key, val in myDict.items():
>    do_something
>    break
> but maybe there is any better way?

If your use case allows the item to be removed, then use:

   key, val = myDict.popitem()

Otherwise, use:

   key, val = next(iter(MyDict.items()))

The latter is nice because next() allows you to supply a default
argument in case the dictionary is emtpy:

   key, val = next(iter(MyDict.items()), (None, None))

Raymond

-
follow my tips and recipes on twitter: @raymondh


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


Re: vertical ordering of functions

2011-05-10 Thread Hans Georg Schaathun
On Tue, 3 May 2011 18:08:27 -0400, Jabba Laci
   wrote:
:  I'm just reading Robert M. Martin's book entitled "Clean Code". In Ch.
:  5 he says that a function that is called should be below a function
:  that does the calling. This creates a nice flow down from top to
:  bottom.

My advice would be to order it in the same way as you would if you
were presenting the algorithm in a paper.

>From such a viewpoint, it depends on whether you consider the called
names to be terms which need definitions, or operations with an
intutive purpose, merely requiring an explanation (implentation) of
how it is done.

In a paper that means that definitions must come before the theorems
and lemmata very often between the theorem and its proof.  If you
don't write papers, that may not be particularly useful :-)

In programming, it means that names which have self-explanatory name
may very well be called first and defined later.  The caller will
give a high-level view of what is going on.  The callees are building
blocks whose purpose can be understood immediately, and whose inner
workings can be sought further down the file.  Fundamental definitions
which may be as easy to implement as explain may often come first.

The question here, is didactics and not programming per se.
A simple rule does not make complex code significantly easier to read,
but a thought structure of the code (with comments and choice of names)
over-all does.

And let's not forget that calls may be circular or otherwise convolved
in a way that does not allow consistent sorting of caller before/after
callee.

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


This it is the code of tmb_import.py (to matter of .tmb to blender) I need tmb_exporter.py (to export of blender to .tmb) Thanks.

2011-05-10 Thread Jean Carlos Páez Ramírez

 I need help.
Hello.




The attached file is script of blender fact in python that .tmb serves to
concern archives (secondly attached file), unloadings to blender and uses
script and concerns the second file that you shipment you see so that it.
Everything can be published and, but it is not possible to be exported again to
.tmb 



To unload in this Link: http://www.blender.org/

script: http://www.mediafire.com/?clmdgkymsfooddd

secondly attached file: http://www.mediafire.com/?lbmj594ru6r4b67



PD: I need script to export in extension .tmb



Thanks.





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


Re: What other languages use the same data model as Python?

2011-05-10 Thread Terry Reedy

On 5/10/2011 3:41 AM, Gregory Ewing wrote:


Actually, you're right. What I've presented is a paper-and-pencil
implementation of the Python data model. Together with a set of
rules for manipulating the diagram under the direction of Python
code, you have a complete implementation of Python that you can
execute in your head.


I think that it would be both fun and useful to have an animated 
graphical tutorial that used and box and arrow model. Names should be in 
ovals (instead of the little boxes used here due to text limitations) to 
differentiate them from objects. Immutable objects could have solid 
boundaries and mutables a broken line boundary. Collection objects would 
have dotted lines to separate slots. Ovals could also use different 
lines for builtins, globals, and locals.



And you NEED such an implementation in order to reason correctly
about Python programs under all circumstances.

I find it very difficult to imagine *any* implementation of
Python, computer-based or otherwise, that doesn't have something
equivalent to references. Whether you call them that, or pointers,
or arrows, or object bindings, or something else, the concept
needs to be there in some form.


Since namespaces link names in a namespace with objects not in the 
namespace, any practical implementation needs a third entity to link or 
associated each name with an object. This is pretty much needed to 
explain multiple links without objects being in multiple locations. It 
is also needed to explain how an object can link to itself.


--
Terry Jan Reedy

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


Re: Non Programming in python

2011-05-10 Thread Terry Reedy

On 5/10/2011 12:41 PM, rusi wrote:

Sorry for a silly subject change: A better one will be welcome -- cant
think of a name myself.


Associated tools. I might separate them into development tools (up to 
the production of python.exe) and usage tools (everything thereafter). 
On Windows, this is a pretty clean separation. On Linux, less so since 
users sometimes build their own binaries and therefore use some of the 
development tools.


Assuming that there is not one already, this could be the beginning of a 
useful overview wiki page with links to existing pages on the specific 
topics ('areas') listed below.



There is this whole area of python that may be called the non-
programming side of programming:

Is there some central site where all such is put up?
What if any should such a bundle of things be called?

-

   | Area | Tool(s)|
   |--+|
   | packaging| distutils, setuptools, |
   |  | distutils2, distribute |
   |  | Native tools (eg apt)  |
   | versioning   | hg, git, bzr   |
   | multiple pythons | virtualenv |
   | ??   | tox|
   | testing  | unittest, nose, pytest |
   | build| scons, make... |
   | deployment   | fabric |

--


I would reorder this list in the typical order used, starting with editors.


* Primary Development tools/aids

   1. Help
   2. Completion ('intellisense')
   3. Tags (Jumping)
   4. Refactoring
   5. Integration with 'non-programming' above (eg VCSes, packagers
etc)

* Other Development Tools
   - Debugger
   - Profiler
   - Heap Profiler
   - Coverage



--
Terry Jan Reedy

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


Re: What other languages use the same data model as Python?

2011-05-10 Thread Gregory Ewing

Chris Angelico wrote:


There has to be a way to get from some mythical "home" location (which
we know in Python as locals()+globals()+current expression - the
"current namespace") to your object. That might involve several names,
or none at all, but if there's no such path, the object is
unreferenced and must be disposed of.


Yes, that's what I mean by "bound to some anonymous thing".
Somewhere in the implementation there must be one or more
"root" references, but they don't necessarily have any names
that you can refer to from Python.

When I say "not bound to any name", I just mean that it's
okay to leave some bindings out of your diagram if they're
not pertinent to what you're trying to illustrate. For
example, you can draw a box representing a string object
and trust that something will keep it alive long enough
for you to draw an arrow to it from the name you're
assigning it to.

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


Re: Non Programming in python

2011-05-10 Thread Steven D'Aprano
On Tue, 10 May 2011 09:41:19 -0700, rusi wrote:

> Sorry for a silly subject change: A better one will be welcome -- cant
> think of a name myself.
> 
> There is this whole area of python that may be called the non-
> programming side of programming:
> 
> Is there some central site where all such is put up? What if any should
> such a bundle of things be called?

Documentation.

Check the Python wiki.




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


Python backup programs?

2011-05-10 Thread Dan Stromberg
What are your favorite backup programs written, in whole or in part, in
Python?

What do you like about them?  Dislike about them?

Are there any features you wish your backup program had, whether in Python
or not?

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


Re: Python backup programs?

2011-05-10 Thread James Mills
On Wed, May 11, 2011 at 9:00 AM, Dan Stromberg  wrote:
>
> What are your favorite backup programs written, in whole or in part, in
> Python?
>
> What do you like about them?  Dislike about them?
>
> Are there any features you wish your backup program had, whether in Python
> or not?

Recently I wrote a simple backup system for a client using
a mixture of Python and Bash using rsync, ssh and pptp.

(Not packaged well enough to show source though)

It works very well and does the job.

cheers
James

-- 
-- James Mills
--
-- "Problems are solved by method"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: This it is the code of tmb_import.py (to matter of .tmb to blender) I need tmb_exporter.py (to export of blender to .tmb) Thanks.

2011-05-10 Thread Gabriel Genellina
En Tue, 10 May 2011 15:51:03 -0300, Jean Carlos Páez Ramírez  
 escribió:



The attached file is script of blender fact in python that .tmb serves to
concern archives (secondly attached file), unloadings to blender and uses


Por lo que pude entender, tu problema es bastante específico de Blender,  
así que tal vez te convenga preguntar en un foro como:

http://www.g-blender.org/
(específicamente dedicado a Blender 3D en español)

También está la comunidad de Python Argentina: http://python.org.ar/pyar/  
(busca la lista de correo)


Suerte!

--
Gabriel Genellina

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


Re: Overuse of try/except/else?

2011-05-10 Thread Paul Probert

On 05/09/2011 07:40 PM, Kyle T. Jones wrote:


It has been hard for me to determine what would constitute overuse.

Cheers.
Well, for me the power of exceptions is that it lets me write much more 
concise code. For example, suppose I call a routine I wrote over and 
over, and I have to check for errors on each call. Then you have a long 
block of code like:

if err == 0:
  x1,err=somefunction(1)
if err == o:
  x2,err=somefunction(2)
...
...
but if somefunction just raises an exception on error, then you do
try:
  x1=somefunction(1)
  x2=somefunction(2)
  ...
  ...
except:
  blah blah

So for my uses, its handy to let things raise exceptions willy nilly in 
the lower level functions, and do the catching in the higher level function.


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


Re: Overuse of try/except/else?

2011-05-10 Thread James Mills
On Tue, May 10, 2011 at 7:34 PM, Jean-Michel Pichavant
 wrote:
> You can reraise the exception without loosing the stack trace.
>
> try:
> ...
> except SomeException, exc:
> log(exc)
> print 'Hello world'
> raise # "raise exc" would loose the original stack trace

Valid point :) However I was referring to real experience
where I've seen code that "catches all any any exception"
and simply logs it.

cheers
James

-- 
-- James Mills
--
-- "Problems are solved by method"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Non Programming in python

2011-05-10 Thread rusi
On May 11, 12:28 am, Terry Reedy  wrote:
> On 5/10/2011 12:41 PM, rusi wrote:
>
> > Sorry for a silly subject change: A better one will be welcome -- cant
> > think of a name myself.
>
> Associated tools. I might separate them into development tools (up to
> the production of python.exe) and usage tools (everything thereafter).
> On Windows, this is a pretty clean separation. On Linux, less so since
> users sometimes build their own binaries and therefore use some of the
> development tools.

Can you elaborate? I dont understand

>
> Assuming that there is not one already, this could be the beginning of a
> useful overview wiki page with links to existing pages on the specific
> topics ('areas') listed below.
>
>
>
> > There is this whole area of python that may be called the non-
> > programming side of programming:
>
> > Is there some central site where all such is put up?
> > What if any should such a bundle of things be called?
>
> > -
>
> >    | Area             | Tool(s)                |
> >    |--+|
> >    | packaging        | distutils, setuptools, |
> >    |                  | distutils2, distribute |
> >    |                  | Native tools (eg apt)  |
> >    | versioning       | hg, git, bzr           |
> >    | multiple pythons | virtualenv             |
> >    | ??               | tox                    |
> >    | testing          | unittest, nose, pytest |
> >    | build            | scons, make...         |
> >    | deployment       | fabric                 |
>
> > --
>
> I would reorder this list in the typical order used, starting with editors.
>
> > * Primary Development tools/aids
>
> >    1. Help
> >    2. Completion ('intellisense')
> >    3. Tags (Jumping)
> >    4. Refactoring
> >    5. Integration with 'non-programming' above (eg VCSes, packagers
> > etc)
>
> > * Other Development Tools
> >    - Debugger
> >    - Profiler
> >    - Heap Profiler
> >    - Coverage


Some more 'areas':
1. Which python 'form' does one use?
At the least python vs pythonw on windows.

But more generally scripting vs REPL. In REPL python vs ipython
Note 1. I am often unnerved by how even experienced python programmers
think that the only way to 'do' python is like C -- write a main, not
appreciating the luxury of an unstructured, exploratory mode that an
REPL makes possible.
Note 2. ruby makes this distinction more obvious by distinguishing the
scripting engine -- ruby -- form the interactive interpreter (REPL) --
irb.

2. Literate Programming: When the primary purpose of the program is
not the program but (some form of) discussion around it

3. Program namespace lookup and structuring: sys.path is the interior
program view but there is also the 'exterior' view -- PYTHONPATH, .pth
files etc.

Finally some thoughts on how to name this list of areas:
a. Software Engineering? : Inasmuch as real program development is
programming + 'something-else' and SE is that 'something else'
b. Python Development Environment? Similar to above

[Cannot say I like these names too much but at least its more specific
than Steven's vanilla 'documentation' :-) ]
-- 
http://mail.python.org/mailman/listinfo/python-list


Merge multiple source directories into one package with distutils?

2011-05-10 Thread Gregory Ewing

Is there a straightforward way to tell distutils to merge
.py files from more than one source directory into a single
package when installing?

PyGUI consists of some generic modules and some platform
specific ones, that conceptually all live at the same level
within a single package. In the source, there is a subdirectory
for each platform containing the platform-dependent files.
When run from the source, __path__ manipulation is done to
make the appropriate platform subdirectory appear to be part
of the main package.

However, when installing, I would like to just copy the
generic files plus the relevant platform ones directly into
the destination package directory, so that __path__ fiddling
is not needed. This is so that bundling tools such as py2app
and py2exe can find all the relevant modules without requiring
any hacking.

But distutils doesn't appear to support this. Unless I'm
missing something, you only get to specify one source directory
for each package.

Anyone have any ideas for getting around this?

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


Re: Python backup programs?

2011-05-10 Thread Laurent Claessens

Le 11/05/2011 01:57, James Mills a écrit :
> On Wed, May 11, 2011 at 9:00 AM, Dan Stromberg 
wrote:

>>
>>  What are your favorite backup programs written, in whole or in part, in
>>  Python?

My favorite one is the one I wrote myself for myself ;)

The point I like :

1. the backup is a simple copy. I can retrieve it without any specific 
programs.
2. if a file changed, before to be copied, the backup file is moved to a 
specific repertory
   whose name is the date and hour. So if I destroy a file and backup 
the destroyed one, the old

   non-destroyed one is still available.
3. Since the program is anyway performing a long os.walk operation, in 
the same time, it performs `git commit`

   in the directories that need it.
4. My program is command-line only. Works fine in tty

Points that are of no importance (very personal and adapted to my 
specific case !) :


1. time. One backup takes between 10 minutes and one hour. I don't 
really care.
2. space. Since my backup is a copy (and copy of copies), my backup 
directory takes ~150Go

   while my home is about 25 Go.

Hope it answer your question.

Have a nice day
Laurent
--
http://mail.python.org/mailman/listinfo/python-list