Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Heiko Wundram
Am Mittwoch, 30. Juli 2008 08:30:48 schrieb Russ P.:
> On Jul 29, 11:09 pm, Erik Max Francis <[EMAIL PROTECTED]> wrote:
> > I'm getting this sneaking suspicion that you guys are all putting us on.
>
> As I said in an earlier post, I realize that this would only work if
> there were only one copy of "empty" (as there is only one copy of
> "None"). I don't know off hand if that is feasible or not.
>
> You reply reeks of the kind of pedantic snobbishness that makes me
> sick.

I can understand (and pretty much sympathise) that you get this kind of reply, 
simply because the point you and Carl Banks (formulated somewhat differently) 
put up has been answered again and again (in this thread), and I can only 
repeat it once more:

__nonzero__(), i.e. the "cast" to boolean, is THE WAY to test whether a 
container is empty or not. Like this design decision, or don't like it, but 
the discussion is not going to go anywhere unless you concede that there is a 
(very explicit!) way to test for non-emptiness of a container already, and 
you're currently simply discussing about adding/using syntactic sugar 
(different means of expressing the test) to suit your own personal taste 
better. Anyway, check the documentation for __nonzero__(): if the object 
doesn't implement that, but implements __len__(), the interpreter "replaces" 
the __nonzero__() test by __len__()>0, so I guess someone in the design 
department must've seen it logical for the truth value of a container to 
express the test "len(x)>0" at some point in time to make this interpretation 
for the truth value of a container.

There cannot be an argument about missing/misplaced functionality (that's what 
you make it sound like), if the functionality for doing what you want to do 
is there and you simply don't like the syntax, which I can somewhat relate to 
because style is a personal thing, even though I don't see either points made 
by you or Carl Banks, because implicit casting to bool is so common in pretty 
much every programming language to test for "truth" of an object, and IMHO 
it's completely logical to extend that idea to containers to mean 
empty/non-empty.

Eric Max Francis tried to explain why your syntactic "enhancement" would come 
at a much greater price than its worth, and he's absolutely right in that, as 
it's an abuse of the "is" operator, but again, that's a somewhat different 
point. It changes nothing about the fact that all this discussion centers 
around something that is a non-point, but simply a matter of personal taste.

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


Re: I CAN connect socket to any localhost port but I shouldn't be able to

2008-07-30 Thread qvx
On Jul 30, 4:48 am, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Tue, 29 Jul 2008 14:56:08 -0300, qvx <[EMAIL PROTECTED]> escribi :
>
> > I don't have server listening on port 8084 but I can open socket to it
> > (and to many other ports, tested for all<8000)
>
> Your example fails -as expected- on my PC running Python 2.5.2 + Windows  
> XP SP2. It may be something specific to your setup or your platform.
>
> py> test(8084)
> Traceback (most recent call last):
>    File "", line 1, in 
>    File "", line 5, in test
>    File "", line 1, in connect
> socket.error: (10061, 'Connection refused')
> --
> Gabriel Genellina

Thanks for confirmation. There is a similar function in CherryPy
server which won't start anymore but it used to. I am currently
examining Windows and any recently installed software.
--
Tvrtko
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python embedding question (2).

2008-07-30 Thread Pierre-Alain Dorange
Thomas Troeger <[EMAIL PROTECTED]> wrote:

> I've managed to put together a small pyGame program, it runs smoothly
> and seems to be exactly what I wanted. It's fast! Even with 100 moving
> objects it still runs so fast that I can consider using Python/pyGame
> for the whole project.
> 
> There are still some questions left which I haven't found out by myself,
> so maybe someone here can answer them:
> 
> - I can't see how to create more sophisticated text output, it seems the
> built in font render facilities are limited to simple strings. Is that
> true?

Yes, for my part i start to make a (small) library myself for my little
game in development (simple).
Supporting bidirectionnal in such a case is not a big deal, but markups
will be not trivial (but python has tools to parse text, this can help).

Also have a look at somme gui library for pygame : 



It seems PGU is one of the most used.


> - Is there some way to reserve screen areas so they are excluded from a
> blit, or do I have to manage stuff like this myself?

You can blit any rectangle it's trivial. for example group.draw render
the sprites in it, into the surface given, this surface can be the
screen or any other "virtual surface". You just have to render this
"virtual" on screen whn done.

You can also used the more sophisticate "dirty rect"
(group.RenderUdates) or even better group.LayeredUpdates. 
I start with but a can not make all things work properly at that time.

> I am thinking about 
> several graphic layers where each layer is painted on top of the next
> layer, for example to draw a gui in front of a background image.

For this is simply create sprite groups (one per layer) and than call
group render (group.draw) in the order i need. Easy and efficient.

> - There seems to be support for video overlay, i.e. is it possible to
> have an external program paint an image from a camera into a portion of
> the screen while pyGame is running?

Don't know...

-- 
Pierre-Alain Dorange

Ce message est sous licence Creative Commons "by-nc-sa-2.0"

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


Re: Native Code vs. Python code for modules

2008-07-30 Thread Paddy
On Jul 30, 4:56 am, koblas <[EMAIL PROTECTED]> wrote:
> Ruby has been getting pummeled for the last year or more on the
> performance subject.  They've been working hard at improving it.  From
> my arm chair perspective Python is sitting on it's laurels and not
> taking this as seriously as it probably should.

I personally DON'T think that the developers should be chasing down
every micro-benchmark. Someone has to look-up and see the bigger
picture.
If you take a look at a larger set of micro benchmarks, then Ruby
is below par when compared to Python and Perl on speed. I had the
misfortune to read their development group entries when a critical
bug was 'fixed' by a release from Japan that didn't have enough
testing and so think the Ruby development 'group' have problems of
quality that they also need to address. (And are doing I think by
adding to their test-suite).

PyPy and previous tools like Psyco are ways in which Python
developers are continuing to see above the eternal grind of micro-
optimising the C-interpreter to try and give us tools that can
approach compiled language speeds from the language we love.
I like to think of it as working smarter rather than harder - the
brains a much better muscle :-)

- Paddy.


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


Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Russ P.
On Jul 30, 12:03 am, Heiko Wundram <[EMAIL PROTECTED]> wrote:
> Am Mittwoch, 30. Juli 2008 08:30:48 schrieb Russ P.:
>
> > On Jul 29, 11:09 pm, Erik Max Francis <[EMAIL PROTECTED]> wrote:
> > > I'm getting this sneaking suspicion that you guys are all putting us on.
>
> > As I said in an earlier post, I realize that this would only work if
> > there were only one copy of "empty" (as there is only one copy of
> > "None"). I don't know off hand if that is feasible or not.
>
> > You reply reeks of the kind of pedantic snobbishness that makes me
> > sick.
>
> I can understand (and pretty much sympathise) that you get this kind of reply,
> simply because the point you and Carl Banks (formulated somewhat differently)
> put up has been answered again and again (in this thread), and I can only
> repeat it once more:
>
> __nonzero__(), i.e. the "cast" to boolean, is THE WAY to test whether a
> container is empty or not. Like this design decision, or don't like it, but
> the discussion is not going to go anywhere unless you concede that there is a
> (very explicit!) way to test for non-emptiness of a container already, and
> you're currently simply discussing about adding/using syntactic sugar
> (different means of expressing the test) to suit your own personal taste
> better. Anyway, check the documentation for __nonzero__(): if the object
> doesn't implement that, but implements __len__(), the interpreter "replaces"
> the __nonzero__() test by __len__()>0, so I guess someone in the design
> department must've seen it logical for the truth value of a container to
> express the test "len(x)>0" at some point in time to make this interpretation
> for the truth value of a container.
>
> There cannot be an argument about missing/misplaced functionality (that's what
> you make it sound like), if the functionality for doing what you want to do
> is there and you simply don't like the syntax, which I can somewhat relate to
> because style is a personal thing, even though I don't see either points made
> by you or Carl Banks, because implicit casting to bool is so common in pretty
> much every programming language to test for "truth" of an object, and IMHO
> it's completely logical to extend that idea to containers to mean
> empty/non-empty.
>
> Eric Max Francis tried to explain why your syntactic "enhancement" would come
> at a much greater price than its worth, and he's absolutely right in that, as
> it's an abuse of the "is" operator, but again, that's a somewhat different
> point. It changes nothing about the fact that all this discussion centers
> around something that is a non-point, but simply a matter of personal taste.
>
> --
> Heiko Wundram

Oh, Lordy. I understand perfectly well how boolean tests, __len__, and
__nonzero__ work in Python. It's very basic stuff. You can quit
patronizing me (and Carl too, I'm sure).

The point that you seem to be missing, or refuse to acknowledge for
some reason, is that  "if x" can be mistakenly applied to any object
when the programmer thinks that x is a list -- and the programmer will
receive no feedback on the error.

I have made errors like that, and I could have saved some time had I
used an "empty" method that only applies to a list or other sequence.

Is that an important issue? I don't know. I'm not claiming it is. But
you cannot just sweep it away as nothing.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Heiko Wundram
Am Mittwoch, 30. Juli 2008 09:18:48 schrieb Russ P.:
> Oh, Lordy. I understand perfectly well how boolean tests, __len__, and
> __nonzero__ work in Python. It's very basic stuff. You can quit
> patronizing me (and Carl too, I'm sure).

I'll stop repeating what the current state is (which might sound like I'm 
patronizing, but that's not the real intent actually, I'm just trying to get 
the discussion straight with what is fact, namely that there already exists 
an explicit way which doesn't seem to be recognized by some people here) if 
you agree to my point that we're not talking about a problem with Python, but 
about a personal stylistic issue with the language design. That's just what I 
said in my last mail: I can concede that you, personally, have an issue with 
the current state, but for me and seemingly also for a majority of people who 
have posted in this thread, that's a non-issue.

> The point that you seem to be missing, or refuse to acknowledge for
> some reason, is that  "if x" can be mistakenly applied to any object
> when the programmer thinks that x is a list -- and the programmer will
> receive no feedback on the error.
>
> I have made errors like that, and I could have saved some time had I
> used an "empty" method that only applies to a list or other sequence.

For me, I've never had this kind of problem, simply because if I test for the 
truth value of something, I'm going to do something with it later on, and as 
soon as I'm doing something with it, I'll see whether the object supports the 
interface I want it to support (and get an error there if the object doesn't 
support the basic notions of a sequence type, for example, i.e. __iter__()). 
Testing for truth is IMHO not doing something with an object, and as such I'm 
more than happy that it's "foolproof". This is one thing that I personally 
find attractive about Python's way of duck-typing.

But, if you personally have been bitten by this, give an example, and I'm sure 
that we can start discussing from there. I've already given an example why 
the explicit test for length is less polymorphic than the explicit test for 
truth of a container elsewhere as a proof for the point I'm trying to make.

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


Re: Using McMillan Installer, PyInstall or py2exe cross-platform?

2008-07-30 Thread Hartmut Goebel

Paul Boddie schrieb:

On 15 Jul, 23:00, Hartmut Goebel <[EMAIL PROTECTED]> wrote:

I started working on cross-pyinstall today.


Let us know how you get on! In theory, one should be able to build
Python (and derived works) using the mingw32 libraries and a suitable
cross-compiler on platforms other than Windows, but I've never
bothered to do so myself.


Pyinstaller trunk is now able to build exe for Windows on Linux/Unix. 
This includes only the "bundling" of scripts and modules into an exe, 
not compiling anything.


--
Schönen Gruß - Regards
Hartmut Goebel

Goebel Consult
Spezialist für IT-Sicherheit in komplexen Umgebungen
http://www.goebel-consult.de
--
http://mail.python.org/mailman/listinfo/python-list


Re: Questions about asyncore

2008-07-30 Thread Frank Millman
On Jul 29, 3:40 pm, "Giampaolo Rodola'" <[EMAIL PROTECTED]> wrote:
> On 29 Lug, 13:09, Frank Millman <[EMAIL PROTECTED]> wrote:

Thanks for the reply, Giampaolo.

>
> The benefit of asynchat is that it automatically handles the buffering
> of both input and output.
> Aside from set/found_terminator() the other two methods you could want
> to look at are push() and push_with_producer().
> push() is a buffered version of asyncore.send(), push_with_producer()
> accepts a data-producer object you can use in case you want to deal
> with something other than strings (e.g. files, lists, generators, and
> so on...).
>

I looked at push() and push_with_producer(). To be honest I don't
fully understand why I would want to use them yet - I will have to go
over them a few more times. However, my handle_write() method seems to
be working ok and is not complicated, so I will stick with that for
now.

>
> I'm not sure to understand but I doubt you have to use a thread.
> If you "have to wait for the reply before continuing" just implement
> this logic into handle_read() or found_terminator() method.
>

Maybe I am a bit slow, but I cannot figure out how to do this without
adding a lot of complication. I will try to give a simple example.

My server is a database server. It sits between the actual database
and the client, and implements access control, automatic handling of
foreign keys, etc. It accepts messages to read, update, and write
data, and returns the results.

For testing purposes, I want the client to send and receive messages
such as the following (pseudocode) -

-> Read Customer record with CustNo = 'A001'.
<- Print data, check that it is correct. [1]
-> Read customer's Branch record.
<- Print data, check that it is correct.
-> Update Customer record with new Branch code. [2]
-> Read Branch code from Customer record.
<- Print code, check that it has changed.
-> Read customer's Branch record.
<- Print data, check that it belongs to the new Branch.

[1] Amongst other things, the server returns the id of the record
[2] The update request uses the record id to identify which record to
update

These are just examples of the tests I might want to throw at the
server. With my multi-threaded approach, the asyncore loop runs in the
background, and in the foreground I can easily send any message I like
and check the results. I cannot see how to implement this using
handle_read() and found_terminator().

Maybe you can give a simple example of an alternative approach.

Thanks

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


Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Russ P.
On Jul 30, 12:49 am, Heiko Wundram <[EMAIL PROTECTED]> wrote:
> Am Mittwoch, 30. Juli 2008 09:18:48 schrieb Russ P.:
>
> > Oh, Lordy. I understand perfectly well how boolean tests, __len__, and
> > __nonzero__ work in Python. It's very basic stuff. You can quit
> > patronizing me (and Carl too, I'm sure).
>
> I'll stop repeating what the current state is (which might sound like I'm
> patronizing, but that's not the real intent actually, I'm just trying to get
> the discussion straight with what is fact, namely that there already exists
> an explicit way which doesn't seem to be recognized by some people here) if
> you agree to my point that we're not talking about a problem with Python, but
> about a personal stylistic issue with the language design. That's just what I
> said in my last mail: I can concede that you, personally, have an issue with
> the current state, but for me and seemingly also for a majority of people who
> have posted in this thread, that's a non-issue.
>
> > The point that you seem to be missing, or refuse to acknowledge for
> > some reason, is that  "if x" can be mistakenly applied to any object
> > when the programmer thinks that x is a list -- and the programmer will
> > receive no feedback on the error.
>
> > I have made errors like that, and I could have saved some time had I
> > used an "empty" method that only applies to a list or other sequence.
>
> For me, I've never had this kind of problem, simply because if I test for the
> truth value of something, I'm going to do something with it later on, and as
> soon as I'm doing something with it, I'll see whether the object supports the
> interface I want it to support (and get an error there if the object doesn't
> support the basic notions of a sequence type, for example, i.e. __iter__()).
> Testing for truth is IMHO not doing something with an object, and as such I'm
> more than happy that it's "foolproof". This is one thing that I personally
> find attractive about Python's way of duck-typing.
>
> But, if you personally have been bitten by this, give an example, and I'm sure
> that we can start discussing from there. I've already given an example why
> the explicit test for length is less polymorphic than the explicit test for
> truth of a container elsewhere as a proof for the point I'm trying to make.
>
> --
> Heiko Wundram

Fair enough. I have no dog in this particular fight. I just think it
wouldn't hurt to add an "isempty()" or "isnonempty()" method to the
list type, and let people use it if they wish, or continue using "if
x" if that's what they prefer.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Erik Max Francis

Russ P. wrote:


On Jul 29, 11:36 pm, Erik Max Francis <[EMAIL PROTECTED]> wrote:

Russ P. wrote:

Come to think of it, shouldn't the list type have an "isempty" method?
Or does it?

Yes.  It's written:

if not aList:
...


As you know, that is not quite exactly the same thing. An "isempty"
method would fail if aList were an integer, and such failure might be
desirable if someone mistakenly had aList pointing to an integer.


If you're that concerned about what the type is, then you can do 
explicit typechecks.  Those are discouraged precisely because of 
Python's dynamism.  But knock yourself out.


--
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
 San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis
  The actor is not quite a human being -- but then, who is?
   -- George Sanders
--
http://mail.python.org/mailman/listinfo/python-list


Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Erik Max Francis

Carl Banks wrote:


I mean in general.  I wouldn't spell it like that.  I would prefer if
empty(x), with an __empty__ method.  (And support __nonzero__ aka
__bool__ dropped completely.)


So your argument is purely about style, then.  You just wish it were 
written differently.


--
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
 San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis
  The actor is not quite a human being -- but then, who is?
   -- George Sanders
--
http://mail.python.org/mailman/listinfo/python-list


Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Erik Max Francis

Russ P. wrote:


Oh, Lordy. I understand perfectly well how boolean tests, __len__, and
__nonzero__ work in Python. It's very basic stuff. You can quit
patronizing me (and Carl too, I'm sure).


You suggested a syntax for testing non-emptiness (`x is not empty`) 
which indicated a profound misunderstanding of what the `is` operator does.


You then acknowledged that there might be a problem because of the 
implication if the `is` operator and weren't sure whether it would work 
or not:


| But I guess that could only work if there were only one empty list
| that represents all empty lists (as there is only one actual "None").
| I don't know if that makes sense or not.

This ends with you still sounding confused about what the operator does, 
because that can't make sense if you take into account the meaning of 
the `is` operator (surely not all empty lists are the same object) and 
polymorphism (not all empty containers are empty lists).


Hey, everybody goofs.  But pointing figures here doesn't help, since 
it's not unreasonable to assume that someone who says something clearly 
misunderstanding a feature of the language, and followups to responses 
_continuing to be confused about it_, is, in fact, confused.  The only 
reason anyone thought you were confused was by your bizarre suggestion 
about the `empty` syntax and then your confused responses afterwards.


Maybe chalk it up to experience and move on?


The point that you seem to be missing, or refuse to acknowledge for
some reason, is that  "if x" can be mistakenly applied to any object
when the programmer thinks that x is a list -- and the programmer will
receive no feedback on the error.

I have made errors like that, and I could have saved some time had I
used an "empty" method that only applies to a list or other sequence.


Well, that's what you get when you use a dynamic language.  There are 
times when `x + y` doesn't mean numeric addition, or in fact anything 
like it.  Or `x % y` where it _really_ doesn't mean anything like the 
modulus operator.  In dynamic languages, the effect of operations depend 
on their types.  There's really no way around that, and Boolean testing 
if an object as in `if x: ...` is no different.  It means different 
things depending on what `x` is.


--
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
 San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis
  The actor is not quite a human being -- but then, who is?
   -- George Sanders
--
http://mail.python.org/mailman/listinfo/python-list


Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Ethan Furman

Russ P. wrote:

Oh, Lordy. I understand perfectly well how boolean tests, __len__, and
__nonzero__ work in Python. It's very basic stuff. You can quit
patronizing me (and Carl too, I'm sure).

The point that you seem to be missing, or refuse to acknowledge for
some reason, is that  "if x" can be mistakenly applied to any object
when the programmer thinks that x is a list -- and the programmer will
receive no feedback on the error.


You know... or maybe you don't, since you did just say what you just 
said... that is such a ridiculous point it only barely qualifies as 
deserving comment.  Rather than be really rude, I'll just say:  test 
it's type() if the function is that specific, or your code that brittle. 
 Python is not there to catch your logic mistakes, that's up to you.



I have made errors like that, and I could have saved some time had I
used an "empty" method that only applies to a list or other sequence.

Is that an important issue? I don't know. I'm not claiming it is. But
you cannot just sweep it away as nothing.


I don't sweep it away as nothing -- I sweep it away as stupid.  The 
programmer is responsible for his (or her) program.  An analogy would be 
a driver and a car -- if the driver cannot handle the power and speed of 
a fancy car (python :), then the driver should get a different car 
better matched to his abilities.  It's not up to the car to say "oh, the 
speed limit is 50 here, I better apply the brakes for the driver."


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


Re: static variables in Python?

2008-07-30 Thread Alan Franzoni
kj was kind enough to say:

> In this case, foo is defined by assigning to it a closure that has
> an associated variable, $x, in its scope.
> 
> Is there an equivalent in Python?

There've been plenty of answers, and I'm not absolutely sure about what you
want... but closures are available in Python as well and you can use them,
and by combining them through the partial module you can get a sort of
closure factory:

from functools import partial

def getfunc(expensive_call, myfunc):
val = expensive_call()

f = partial(myfunc, val)

return f



you can then do something like that:

>> f = getfunc(lambda: 1, lambda x,y:x*y)
>> f(2)
6





-- 
Alan Franzoni <[EMAIL PROTECTED]>
-
Remove .xyz from my email in order to contact me.
-
GPG Key Fingerprint:
5C77 9DC3 BD5B 3A28 E7BC 921A 0255 42AA FE06 8F3E
--
http://mail.python.org/mailman/listinfo/python-list


Correct Attribute Assignment Methodology?

2008-07-30 Thread Tim Cook
Say I have these classes:

class Parent(object):
  """Parent is abstract"""
  a=None
  def showA():
   return self.a

class Child(Parent):
  """inherits a and showA from Parent"""

  def __init__(self,a,b):
self.a=a   
self.b=b

  def showAB():
   return self.a,self.b


class GrandChild(Child):
  """inherits all of the above"""

  def __init__(self,a,b,c):
   self.a=a
   self.b=b  
   """should this be Child.__init__(a,b)? or Child.__init__(b)?""  
   """if so; why? if not why not?"""
   self.c=c

Thanks for answering these very basic questions but I am not certain
about the correct way.  I know that in Python, assignment in the
GrandChild class will work but is that correct?

--Tim

 

-- 
**
Join the OSHIP project.  It is the standards based, open source
healthcare application platform in Python.
Home page: https://launchpad.net/oship/ 
Wiki: http://www.openehr.org/wiki/display/dev/Python+developer%27s+page 
**


signature.asc
Description: This is a digitally signed message part
--
http://mail.python.org/mailman/listinfo/python-list

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Maric Michaud
Le Tuesday 29 July 2008 23:48:31 [EMAIL PROTECTED], vous avez écrit :
> Here's a function, print_members.  It's just something that takes some
> iterable and prints its members in XML.  It's special-cased so that an
> empty iterable gets an empty tag.  (This is a bit of a trivial
> example, I admit; the point is that the empty iterable is a special
> case.)
>
> def print_members(iterable):
>     if not iterable:
>         print ''
>         return
>     print ''
>     for item in iterable:
>         print '%s' % item
>     print ''
>
>
... 
> So print_members can work on iterables that have no len(), and handle
> the special case of an empty iterable, as long as __nonzero__ is
> implemented.
>

But iterables can have no notion of emptiness too :

>>>[25]: print_members((e for e in range(0)))



Your function is just wrong assuming that, it should be written :

>>>[31]: def print_members(iterable):
print ''
print '%s' % item
print empty and '/>' or ''
   :
   :

>>>[40]: print_members((e for e in range(0)))


>>>[41]: print_members((e for e in range(1)))

0




> Counterexample:
>
> While "if x" works well in some circumstances, I don't like using it
> for purely numeric types.  For instance, I have a mutable Signal class
> for doing some basic DSP.  Among other things, I can apply a DC offset
> to the signal (it just adds the offset to all the samples).  I have a
> special case for an offset of 0 so I don't have to loop through all
> the samples (I also have a two-pass remove_offset method that
> subtracts the average; if it's already properly centred, I can skip a
> step).
>
> class Signal:
>     [...]
>     def dc_offset(self, amount):
>         if amount == 0:
>             return
>         self.samples = [sample + amount for sample in self.samples]

This function is also wrong assuming that because amount compare to zero, it 
can be added to sample.

If you want to make type checking just check the type or convert your 
parameter to an int, but the test "== 0" is of no help here.

The only valuable point I see for this idiom is to make more explicit I am 
testing a numerical value.
But your example is a good objection to this, with well chosen name, ie. 
amount, it's quite clear "if not amount :" is testing the zero value of a 
numerical value.

-- 
_

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


Re: Python parsing iTunes XML/COM

2008-07-30 Thread pyshib
If you want to convert the file names which use standard URL encoding
(with %20 for space, etc) use:

from urllib import unquote
new_filename = unquote(filename)

I have found this does not convert encoded characters of the form
'&#CC;' so you may have to do that manually. I think these are just
ascii encodings in hexadecimal.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Change PC to Win or Windows

2008-07-30 Thread Antoon Pardon
On 2008-07-21, Derek Martin <[EMAIL PROTECTED]> wrote:
>
> --tsOsTdHNUZQcU9Ye
> Content-Type: text/plain; charset=iso-8859-1
> Content-Disposition: inline
> Content-Transfer-Encoding: quoted-printable
>
> On Sat, Jul 19, 2008 at 02:56:07AM -0700, Lie wrote:
>> On Jul 19, 6:14=A0am, Derek Martin <[EMAIL PROTECTED]> wrote:
>> > On Fri, Jul 18, 2008 at 03:46:13PM -0700, Joel Teichroeb wrote:
>> > Much like the English word "bank" (and numerous others), the term "PC"
>> > has come to have several meanings, one of which is the above. =A0You may
>> > not like it, but we're pretty much stuck with the term, so you may as
>> > well get used to it.
>>
>> That's not the point,=20
>
> It very much IS the point.  Language evolves based on common usage
> patterns of the people who use it.  The term "PC" is commonly used in
> English, in the United States and other English speaking countries, to
> mean a computer running Microsoft Windows.

You mean the same computer is no longer considered a PC if someone
install linux on it?

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


Re: proxy class and __add__ method

2008-07-30 Thread Magnus Schuster

>__magic__ methods on new style classes are searched in the class, *not* in  
>the instance. prx_i+1 looks for __add__ in type(prx_i), that is, in the  
>proxy class. 

With this explanation the behaviour is absolutely clear. Can I find some
documentation anywhere containing more background information how magic
functions are resolved? I haven't been successful with the Python Language
Reference.

>Try implementing a similar __getattr__ method in a metaclass.

I am totally clueless how to do this. Below you find my attempt. Neither
__getattr__ nor __add__ of the metaclass 'meta' are ever called. May I ask
you for some more guidance or corrections to the code below?

Regards,
Magnus

2nd attempt:
--- BEGIN ---
class meta(type):
def __getattr__( self, name ):
print "meta.__getattr__"
return getattr( self.__subject, name )
def __add__( self, y ):
print "meta.__add__"
return self+y

class proxy(object):
__metaclass__=meta;
def __init__( self, subject ):
self.__subject = subject
def __getattr__( self, name ):
print "proxy.__getattr__"
return getattr( self.__subject, name )

prx_i=proxy(1)
k=prx_i+1
--- END ---

The error is the same as before. Please note that I want to avoid
reimplementing all methods of 'int', because the proxy class should be
universal. (The meta.__add__ method is for testing only).

-- 
View this message in context: 
http://www.nabble.com/proxy-class-and-__add__-method-tp18715799p18730676.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Python Modules To convert PDF files to HTML files

2008-07-30 Thread srinivasan srinivas
Hi,
could someone tel me any python modules which can be used to convert PDF files 
to HTML files??
Thanks,
Srini


  Unlimited freedom, unlimited storage. Get it now, on 
http://help.yahoo.com/l/in/yahoo/mail/yahoomail/tools/tools-08.html/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Continuous integration for Python projects

2008-07-30 Thread BlueBird
On Jul 29, 4:56 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> Hussein B wrote:
> > Hi.
> > Please correct my if I'm wrong but it seems to me that the major
> > continuous integration servers (Hudson, CruiseControl, TeamCity ..)
> > don't support Python based application.
> > It seems they mainly support Java, .NET and Ruby.
> > Can I use one of the previous listed servers for Python project?
>
> Hudson can, and AFAIK CC as well - they only invoke shell-scripts (at least
> hudson does, and CC you can convince doing that using ANT)
>

I have CC almost running here with python tests and there is no
technical problem in front. You must package your test scripts so that
they exit with something different than 0 in case of failure, and then
just use the Exec runner of CC to run them.

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


variable expansion with sqlite

2008-07-30 Thread marc wyburn
Hi I'm using SQlite and the CSV module and trying to create a class
that converts data from CSV file into a SQLite table.

My script curently uses functions for everything and I'm trying to
improve my class programming.  The problem I'm having is with variable
expansion.

self.cursor.executemany('INSERT INTO test VALUES (?)', CSVinput)

If CSVinput is a tuple with only 1 value, everything is fine.  If I
want to use a tuple with more than 1 value, I need to add more
question marks.  As I'm writing a class I don't want to hard code a
specific number of ?s into the INSERT statement.

The two solutions I can think of are;
using python subsitution to create a number of question marks, but
this seems very dirty
 or
finding someway to substitue tuples or lists into the statement - I'm
not sure if this should be done using Python or SQLite substitution
though.

Any tips on where to start looking?

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


Re: Proxy server?

2008-07-30 Thread Gary

"Diez B. Roggisch" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Gary schrieb:
> > "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote in message
> > news:[EMAIL PROTECTED]

> You can't make any TCP/IP communication run through a proxy, unless it's
> transparent.

Thanks for all the info.

I'm puzzled though that a such a transaction isn't possible by rewriting the
headers. So client X connects to my PS, which passes on the data to the
target but with the header changed to indicate the PS as the original
source. The intended target responds to the PS, this is then resent to
client X with the header modified so that the transaction appears
transparent. So it's *effectively* transparent target>client but
non-transparent client>target, if you see what I mean.

Can you please explain why this wouldn't work?

Thanks,
Gary


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


Re: variable expansion with sqlite

2008-07-30 Thread Tim Golden

marc wyburn wrote:

Hi I'm using SQlite and the CSV module and trying to create a class
that converts data from CSV file into a SQLite table.

My script curently uses functions for everything and I'm trying to
improve my class programming.  The problem I'm having is with variable
expansion.

self.cursor.executemany('INSERT INTO test VALUES (?)', CSVinput)

If CSVinput is a tuple with only 1 value, everything is fine.  If I
want to use a tuple with more than 1 value, I need to add more
question marks.  As I'm writing a class I don't want to hard code a
specific number of ?s into the INSERT statement.

The two solutions I can think of are;
using python subsitution to create a number of question marks, but
this seems very dirty
 or
finding someway to substitue tuples or lists into the statement - I'm
not sure if this should be done using Python or SQLite substitution
though.



I do this kind of thing sometimes:


a,b,c
1,2,3
4,5,6



import csv
import sqlite3

reader = csv.reader (open ("test.csv", "rb"))
csv_colnames = reader.next ()

db = sqlite3.connect (":memory:")
coldefs = ", ".join ("%s VARCHAR (200)" % c for c in csv_colnames)
db.execute ("CREATE TABLE test (%s)" % coldefs)

insert_cols = ", ".join (csv_colnames)
insert_qmarks = ", ".join ("?" for _ in csv_colnames)
insert_sql = "INSERT INTO test (%s) VALUES (%s)" % (insert_cols, insert_qmarks)

db.executemany (insert_sql, list (reader))
for row in db.execute ("SELECT * FROM test"):
 print row



Obviously, this is a proof-of-concept code. I'm (ab)using
the convenience functions at database level, I'm hardcoding
the column definitions, and I'm  making a few other assumptions, 
but I think it serves as an illustration.


Of course, you're only a few steps away from something
like sqlalchemy, but sometimes rolling your own is good.

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


Re: Continuous integration for Python projects

2008-07-30 Thread Alan Franzoni
Hussein B was kind enough to say:

> Hi.
> Please correct my if I'm wrong but it seems to me that the major
> continuous integration servers (Hudson, CruiseControl, TeamCity ..)
> don't support Python based application.

If you want, you can use ant as a build script, and then define the usual
targets (build, dist, test), ecc. and then use xmlrunner to publish them in
a junit-like format which can be read through cruisecontrol or other CI
tools.

-- 
Alan Franzoni <[EMAIL PROTECTED]>
-
Remove .xyz from my email in order to contact me.
-
GPG Key Fingerprint:
5C77 9DC3 BD5B 3A28 E7BC 921A 0255 42AA FE06 8F3E
--
http://mail.python.org/mailman/listinfo/python-list


Re: Defunct when using subprocess.Popen

2008-07-30 Thread Bruce Frederiksen
On Wed, 30 Jul 2008 01:56:28 -0300, Gabriel Genellina wrote:

> You should call os.waitpid() after killing the child process, to let the  
> OS free the resources allocated to it.
>

The subprocess.Popen object supports a 'wait' method directly.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Proxy server?

2008-07-30 Thread Heiko Wundram
Am Mittwoch, 30. Juli 2008 13:48:08 schrieb Gary:
> "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>
> > Gary schrieb:
> > > "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote in message
> > > news:[EMAIL PROTECTED]
> >
> > You can't make any TCP/IP communication run through a proxy, unless it's
> > transparent.
>
> Thanks for all the info.

This is not entirely true. There are libc-plugins (i.e. LD_PRELOAD hacks) 
which use SOCKS (which is a generic proxying protocol for [TCP/]IP) to 
redirect all locally originating TCP/IP traffic _which is managed through the 
socket interface of the libc_ in the application that you applied the 
LD_PRELOAD hack to through a specified SOCKS-proxy (this should capture 
pretty much everything, except for communication originating in the 
*nix-kernel itself). I seem to recall that something similar exists for 
WinSock, but I wouldn't know for sure.

Check the web for documentation on setting up a SOCKS proxy, and for the 
respective libc-plugins or WinSock SOCKS "hack".

If you cannot make the user use SOCKS through a means like this (in which case 
there has to be no application support) or by instructing a specific 
application to use a SOCKS proxy directly (which all browsers can out of the 
box AFAIK), and you don't have the possibility to put yourself somewhere in 
the middle by means of a transparent proxy (i.e., a firewall applicance which 
does this; I seem to recall that there was some FreeBSD-based software which 
basically did just this kind of transparent proxying for a network), you're 
out of luck, just like Diez said.

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


Re: Insert character at a fixed position of lines

2008-07-30 Thread Lie
On Jul 27, 10:02 am, alex23 <[EMAIL PROTECTED]> wrote:
> Ugh, and in pointing our your inaccurate code I posted my own:
>
> > >>> f = open('dummy.txt','w')
> > >>> f.write(line = 'this doesn't work')
>
> >   File "", line 1
> >     f.write(line = 'this doesn't work')
> >                                ^
> > SyntaxError: invalid syntax
>
> That should be:
>
> >>> f.write(line = "this doesn't work")
>
> Traceback (most recent call last):
>   File "", line 1, in 
> TypeError: write() takes no keyword arguments
>
> Sorry about that :)

Lessons learned, should test codes even if you thought it seemed
trivial.
--
http://mail.python.org/mailman/listinfo/python-list


Standard module for parsing emails?

2008-07-30 Thread Phillip B Oldham
Is there a standard library for parsing emails that can cope with the
different way email clients quote?
--
http://mail.python.org/mailman/listinfo/python-list


Re: elementtree and rounding questions

2008-07-30 Thread jyoung79
Thank you very much Gabriel and Stefan for your help!  I really appreciate the 
excellent examples you've shared which is helping me understand how all this 
works.  Again, thank you for taking the time to help me with this.

Jay



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


Re: Standard module for parsing emails?

2008-07-30 Thread Diez B. Roggisch
Phillip B Oldham wrote:

> Is there a standard library for parsing emails that can cope with the
> different way email clients quote?

AFAIK not - as unfortunately that's something the user can configure, and
thus no atrocity is unimaginable. Hard to write a module for that...

All you can try is to apply a heuristic like "if there are lines all
starting with a certain prefix that contains non-alphanumeric characters".
But then if the user configures to quote using 

XX

you're doomed...



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


Re: Build tool for Python

2008-07-30 Thread Sion Arrowsmith
Hussein B  <[EMAIL PROTECTED]> wrote:
>Apache Ant is the de facto building tool for Java (whether JSE, JEE
>and JME) application.
>With Ant you can do what ever you want: [ ... ]

... bash your head against your desk for hours trying to make sense
of its classloader system, struggle for days on end trying to make
it understand building anything outside the Java world, write piles
of tedious and often boilerplate XML, wonder what happened to javac's
ability to resolve dependencies to make this necessary ...

Put it like this, my experience has lead me to regard Ant as a
retrograde step compared to make. I can't understand why anyone
would want to inflict such a thing on a Python project.

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
   "Frankly I have no feelings towards penguins one way or the other"
-- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
--
http://mail.python.org/mailman/listinfo/python-list

Re: variable expansion with sqlite

2008-07-30 Thread Gerhard Häring

Tim Golden wrote:

marc wyburn wrote:

Hi I'm using SQlite and the CSV module and trying to create a class
that converts data from CSV file into a SQLite table.

My script curently uses functions for everything and I'm trying to
improve my class programming.  The problem I'm having is with variable
expansion.

self.cursor.executemany('INSERT INTO test VALUES (?)', CSVinput)

If CSVinput is a tuple with only 1 value, everything is fine.  If I
want to use a tuple with more than 1 value, I need to add more
question marks.  As I'm writing a class I don't want to hard code a
specific number of ?s into the INSERT statement.

The two solutions I can think of are;
using python subsitution to create a number of question marks, but
this seems very dirty
 or
finding someway to substitue tuples or lists into the statement - I'm
not sure if this should be done using Python or SQLite substitution
though.



I do this kind of thing sometimes:


a,b,c
1,2,3
4,5,6



import csv
import sqlite3

reader = csv.reader (open ("test.csv", "rb"))
csv_colnames = reader.next ()

db = sqlite3.connect (":memory:")
coldefs = ", ".join ("%s VARCHAR (200)" % c for c in csv_colnames)
db.execute ("CREATE TABLE test (%s)" % coldefs)

insert_cols = ", ".join (csv_colnames)
insert_qmarks = ", ".join ("?" for _ in csv_colnames)
insert_sql = "INSERT INTO test (%s) VALUES (%s)" % (insert_cols, 
insert_qmarks)


db.executemany (insert_sql, list (reader))
for row in db.execute ("SELECT * FROM test"):
 print row



Obviously, this is a proof-of-concept code. I'm (ab)using
the convenience functions at database level, I'm hardcoding
the column definitions, and I'm  making a few other assumptions, but I 
think it serves as an illustration. [..]


My code would probably look very similar. Btw you don't need to use 
list() on an iterable to pass to executemany(). pysqlite's executemany() 
accepts anything iterable (so generators work fine, too).


Also, with SQLite you can just skip data type definitions like 
VARCHAR(200). They're ignored anyway.


-- Gerhard

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


Re: Standard module for parsing emails?

2008-07-30 Thread Ben Finney
Phillip B Oldham <[EMAIL PROTECTED]> writes:

> Is there a standard library for parsing emails that can cope with
> the different way email clients quote?

"Cope with" in what sense? i.e., what would the behaviour of such a
library be? What would it do?

Note also that it's not merely the mail client that does the quoting;
frequently the user composing the message will have a heavy hand in
how the quoted material appears.

-- 
 \ “Time flies like an arrow. Fruit flies like a banana.” —Groucho |
  `\  Marx |
_o__)  |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list

Re: variable expansion with sqlite

2008-07-30 Thread Tim Golden

Gerhard Häring wrote:
My code would probably look very similar. Btw you don't need to use 
list() on an iterable to pass to executemany(). pysqlite's executemany() 
accepts anything iterable (so generators work fine, too).


Thanks for that. My finger-memory told me to do that, possibly
because some *other* dbapi interface only accepts lists. Can't
quite remember. I'm usually all in favour of non-crystallised 
iterators.


Also, with SQLite you can just skip data type definitions like 
VARCHAR(200). They're ignored anyway.


Heh. Once again, finger memory forced me to put *something*
in there. I've been developing Enterprise databases for too
long :)

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


Re: Native Code vs. Python code for modules

2008-07-30 Thread Sion Arrowsmith
alex23  <[EMAIL PROTECTED]> wrote:
>On Jul 30, 1:56=A0pm, koblas <[EMAIL PROTECTED]> wrote:
>> Ruby has been getting pummeled for the last year or more on the
>> performance subject. =A0They've been working hard at improving it. =A0Fro=
>m
>> my arm chair perspective Python is sitting on it's laurels and not
>> taking this as seriously as it probably should.
>
>Well, the snarky response is most Python developers are too busy
>working on actual real world projects :)

The follow-up snarky response is that working on actual real world
projects has lead Python developers to realise that most real world
bottlenecks arise from disk access, network speed, and user
interaction, and you should only sweat about code speed in the rare
case when you *know* that it's not its interface to the real world
that's slow.

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
   "Frankly I have no feelings towards penguins one way or the other"
-- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
--
http://mail.python.org/mailman/listinfo/python-list

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread giltay
On Jul 30, 5:09 am, Maric Michaud <[EMAIL PROTECTED]> wrote:
> Le Tuesday 29 July 2008 23:48:31 [EMAIL PROTECTED], vous avez écrit :
> > def print_members(iterable):
> >     if not iterable:
> >         print ''
> >         return
> >     print ''
> >     for item in iterable:
> >         print '%s' % item
> >     print ''
>
> But iterables can have no notion of emptiness too :
>
> >>>[25]: print_members((e for e in range(0)))
>
> 
> 

Ack!  Maybe I meant "container" rather than "iterable".  Or maybe I'd
be wrong on that count, too.  Other people have come up with better
examples, so I won't try to fix my hasty code (although I'll keep that
in mind if I have to write a custom XML writer).

> > class Signal:
> >     [...]
> >     def dc_offset(self, amount):
> >         if amount == 0:
> >             return
> >         self.samples = [sample + amount for sample in self.samples]
>
> This function is also wrong assuming that because amount compare to zero, it
> can be added to sample.

Not quite.  I'm assuming that if amount equals 0, then amount is some
scalar.  In fact, only if that comparison fails will I get my
exception: since [] != 0, it will then try to add sample + [], which
will raise TypeError.

> If you want to make type checking just check the type or convert your
> parameter to an int, but the test "== 0" is of no help here.

I'm not going for type checking here because I want Signal to support
int and float samples (and numpy.int16, &c.).

> The only valuable point I see for this idiom is to make more explicit I am
> testing a numerical value.

That's one of the reasons I wrote it that way.  Signal has other
methods that take lists (like mix and envelope), which I could get
confused with the ones that take scalars (offset and change volume).

 Cheers,
Geoff G-T
--
http://mail.python.org/mailman/listinfo/python-list


Re: Standard module for parsing emails?

2008-07-30 Thread Thomas Guettler

Phillip B Oldham schrieb:

Is there a standard library for parsing emails that can cope with the
different way email clients quote?


What do you mean with "quote" here?
 1. Encode utf8/latin1 to ascii
 2. Prefix of quoted text like your text above in my mail

 Thomas


--
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de
--
http://mail.python.org/mailman/listinfo/python-list


Re: iterating "by twos"

2008-07-30 Thread giltay
On Jul 29, 4:11 pm, Erik Max Francis <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > for x, y in zip(a, a[1:]):
> >     frob(x, y)
>
> What you meant was this:
>
>  >>> [(x, y) for x, y in zip(a[::2], a[1::2])]
> [(0, 1), (2, 3), (4, 5), (6, 7), (8, 9)]
>
> but this creates three sublists through slicing and zip.  The use of
> islice and izip is better, particularly if the list that's being
> iterated over is large.

 The lists I use it with are generally pretty small (a few
thousand items at most) so I decided to go with simple rather than
clever.  That said, I use it enough that it should become its own
function, at which point I'll probably grab something from this
thread.

 Cheers,
Geoff G-T
--
http://mail.python.org/mailman/listinfo/python-list


Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Hyuga
On Jul 30, 3:53 am, "Russ P." <[EMAIL PROTECTED]> wrote:
> Fair enough. I have no dog in this particular fight. I just think it
> wouldn't hurt to add an "isempty()" or "isnonempty()" method to the
> list type, and let people use it if they wish, or continue using "if
> x" if that's what they prefer.

Go right on ahead.  You could implement it like this:

class superenhancedlist(list):
def isempty(self):
return not self

>>> a = superenhancedlist()
>>> a.isempty()
True
>>> a.append(1)
>>> a.isempty()
False

Amazingly useful!  Go ahead and use that in all your code.  Anyone
else who comes along and looks at it or tries to maintain it will
really love you for it.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Standard module for parsing emails?

2008-07-30 Thread Phillip B Oldham
On Jul 30, 2:36 pm, Thomas Guettler <[EMAIL PROTECTED]> wrote:
> What do you mean with "quote" here?
>   2. Prefix of quoted text like your text above in my mail

Basically, just be able to parse an email into its actual and "quoted"
parts - lines which have been prefixed to indent from a previous
email.

Most clients use ">" which is easy to check for, but I've seen some
which use "|" and some which *don't* quote at all. Its causing us
nightmares in parsing responses to system-generated emails. I was
hoping someone might've seen the problem previously and released some
code.
--
http://mail.python.org/mailman/listinfo/python-list


New CMS in Python

2008-07-30 Thread :-)
HI

I am Glad to announce you that I am creating New CMS for Python.

I'll post it after Python 3 release.

Currently I only the Developer/Team Lead/Project Lead/Organization :)

It would be

Very lightweight
Fast
Easy to Use
Ajax Enabled
new?? Done.


Please send me how U expect your new CMS would be?

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


Re: Native Code vs. Python code for modules

2008-07-30 Thread pruebauno
On Jul 29, 11:56 pm, koblas <[EMAIL PROTECTED]> wrote:
> better if there was a way that if I have an "interface compatible"
> native (aka C) module that has better performance that there could be
> a way that python would give it preference.
>
> e.g.
>
>   import random(version=1.2, lang=c)
> or
>   import random(version=1.2, lang=py)   # use the python version by
> default
> or
>   import random #  use the latest version in the "fastest" code (C
> given preference)
>
> where there could be a nice set of "standard" key value pairs that
> could provide addtional hints as to what language and version of a
> library was to be used.

I will only make a comment on automatic cModule importing. Some of
what you are suggesting already happens (e.g. Elementree). In Python
3.0 more of the "legacy" modules (e.g. StringIO) should also work that
way. I don't know what the current status for Pickle is  because
cPickle had some additional internal functionality not available in
regular Pickle that Zope was dependent on.
--
http://mail.python.org/mailman/listinfo/python-list


Is it possible to consume UTF8 XML documents using xml.dom.pulldom?

2008-07-30 Thread Simon Willison
I'm having a horrible time trying to get xml.dom.pulldom to consume a
UTF8 encoded XML file. Here's what I've tried so far:

>>> xml_utf8 = """
Simon\xe2\x80\x99s XML nightmare
"""
>>> from xml.dom import pulldom
>>> parser = pulldom.parseString(xml_utf8)
>>> parser.next()
('START_DOCUMENT', )
>>> parser.next()
('START_ELEMENT', )
>>> parser.next()
...
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in
position 21: ordinal not in range(128)

xml.dom.minidom can handle the string just fine:

>>> from xml.dom import minidom
>>> dom = minidom.parseString(xml_utf8)
>>> dom.toxml()
u'Simon\u2019s XML nightmare'

If I pass a unicode string to pulldom instead of a utf8 encoded
bytestring it still breaks:

>>> xml_unicode = u'Simon\u2019s XML nightmare'
>>> parser = pulldom.parseString(xml_unicode)
...
/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/
xml/dom/pulldom.py in parseString(string, parser)
346
347 bufsize = len(string)
--> 348 buf = StringIO(string)
349 if not parser:
350 parser = xml.sax.make_parser()
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in
position 32: ordinal not in range(128)

Is it possible to consume utf8 or unicode using xml.dom.pulldom or
should I try something else?

Thanks,

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


SVN access with pysvn under Cygwin (Installation problems)

2008-07-30 Thread Andy Dingley
I'm building Python tools to wrap up access to our Subversion / SVN
source control system. It's to run on my desktop (Cygwin under Windows
XP) and then later under Redhat.

Trying to install the pysvn module I'm running into problems getting
it to work under Cygwin. Works fine from a Windows command prompt,
with both the svn_cmd.py example and my own Python code. Under Cygwin
though I just get import failures. pysvn/__init__.py   seems to be
invoked happily enough, but then fails when it tries to import
_pysvn_2_5.pyd

$ python svn_cmd.py
Traceback (most recent call last):
  File "svn_cmd.py", line 10, in 
import pysvn
  File "/usr/lib/python2.5/pysvn/__init__.py", line 104, in 
import _pysvn_2_5
ImportError: No module named _pysvn_2_5

Is there some trick to getting .pyd to work under Cygwin?  I've tried
the obvious twiddling with environment variables (and regedit), but
I'm just guessing blindly.

Thanks for any assistance.
--
http://mail.python.org/mailman/listinfo/python-list


Pointers/References in Python?

2008-07-30 Thread [EMAIL PROTECTED]
Hello,

I have a long list of memory-heavy objects that I would like to access
in differently sorted order. Let's say I'd like to have lists called
by_date or by_size that I can use to access the objects in the
specified order.

Of course I can just build those lists naively by creating copies of
the original list and then sorting them according to my wishes. But
that would create huge memory overhead. Of course I could use lists of
indices into the "master" list, just as in C I'd create lists or
arrays of pointers into the original data.

Is there a clever Python way to do this, or should I just use lists of
indices?

I know there is a thing called "shallow copy" that has something to do
with not duplicating memory content but I don't understand the
concept. Maybe that's what would help here, too.

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


Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Maric Michaud
Le Wednesday 30 July 2008 15:31:28 [EMAIL PROTECTED], vous avez écrit :
> > > class Signal:
> > >     [...]
> > >     def dc_offset(self, amount):
> > >         if amount == 0:
> > >             return
> > >         self.samples = [sample + amount for sample in self.samples]
> >
> > This function is also wrong assuming that because amount compare to zero,
> > it can be added to sample.
>
> Not quite.  I'm assuming that if amount equals 0, then amount is some
> scalar.  In fact, only if that comparison fails will I get my
> exception: since [] != 0, it will then try to add sample + [], which
> will raise TypeError.
>
> > If you want to make type checking just check the type or convert your
> > parameter to an int, but the test "== 0" is of no help here.
>
> I'm not going for type checking here because I want Signal to support
> int and float samples (and numpy.int16, &c.).

Ok, but the fact that amount == 0 passes, doesn't ensure you didn't a 
programming error, this add just some relative robustness (protect you from 
passing an empty list). And a reader would probably not see your intention 
here (he already expect a scalar due to the name of the variable).

This is exactly the problem ABC is intended to solve.

Without ABC, to explicitly ensure amount is a scalar, just doing a int(amount) 
or int(abs(amount)) if you want to deal with complex numbers too, at the 
begining of the function is a common idiom.

-- 
_

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


undo a dictionary

2008-07-30 Thread mmm
I found code to undo a dictionary association.

def undict(dd, name_space=globals()):
for key, value in dd.items():
exec "%s = %s" % (key, repr(value)) in name_space

So if i run

>>> dx= { 'a':1, 'b': 'B'}
>>> undict(dx)

I get
>>> print A, B
1 B

Here,  a=1 and b='B'

This works well enough for simple tasks and I understand the role of
globals() as the default names space, but creating local variables is
a problem. Also having no output arguemtns to undict() seems
counterintuitive.  Also, the function fails if the key has spaces or
operand characters (-,$,/,%).  Finally I know I will have cases where
not clearing (del(a,b)) each key-value pair might create problems in a
loop.

So I wonder if anyone has more elegant code to do the task that is
basically the opposite of creating a dictionary from a set of
globally assigned variables.  And for that matter a way to create a
dictionary from a set of variables (local or global).  Note I am not
simply doing and  undoing dict(zip(keys,values))
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python parsing iTunes XML/COM

2008-07-30 Thread william tanksley
Thank you for the response. Here's some more info, including a little
that you didn't ask me for but which might be useful.

John Machin <[EMAIL PROTECTED]> wrote:
> william tanksley <[EMAIL PROTECTED]> wrote:
> > To ask another way: how do I convert from a file:// URL to a local
> > path in a standard way, so that filepaths from two different sources
> > will work the same way in a dictionary?
> > The problems occur when the filenames have non-ascii characters in
> > them -- I suspect that the URLs are having some encoding placed on
> > them that Python's decoder doesn't know about.

> # track_id = url2pathname(urlparse(track_id).path)
> print repr(track_id)
> parse_result = urlparse(track_id).path
> print repr(parse_result)
> track_id_replacement = url2pathname(parse_result)
> print repr(track_id_replacement)

The "important" value here is track_id_replacement; it contains the
data that's throwing me. It appears that some UTF-8 characters are
being read as multiple bytes by ElementTree rather than being decoded
into Unicode. Could this be a bug in ElementTree's Unicode support? If
so, can I work around it?

Here's one example. The others are similar -- they have the same
things that look like problems to me.

"Buffett Time - Annual Shareholders\xc2\xa0L.mp3"

Note some problems here:

1. This isn't Unicode; it's missing the u"" (I printed using repr).
2. It's got the UTF-8 bytes there in the middle.

I tried doing track_id.encode("utf-8"), but it doesn't seem to make
any difference at all.

Of course, my ultimate goal is to compare the track_id to the track_id
I get from iTunes' COM interface, including hashing to the same value
for dict lookups.

> and copy/paste the results into your next posting.

In addition to the above results, while trying to get more diagnostic
printouts I got the following warning from Python:

C:\projects\podcasts\podstrand\podcast.py:280: UnicodeWarning: Unicode
equal comparison failed to convert both arguments to Unicode -
interpreting them as being unequal
  return track.databaseID == trackLocation

The code that triggered this is as follows:

if trackLocation in self.podcasts:
track = self.podcasts[trackLocation]
if trackRelease:
track.release_date = trackRelease
elif track.is_podcast:
print "No release date:", repr(track.name)
else:
# For the sake of diagnostics, try to find the track.
def track_has_location(track):
return track.databaseID == trackLocation
fillers = filter(track_has_location, self.fillers)
if len(fillers):
return
disabled = filter(track_has_location, self.deferred)
if len(disabled):
return
print "Location not known:", repr(trackLocation)

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


Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Terry Reedy



Carl Banks wrote:


That's not what I was asking for.  I was asking for a use case for "if
x" that can't be replaced by a simple explicit test.  Your example
didn't satisfy that.


But I believe my example of an iterator with __bool__ but not with 
__len__ does.


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


Re: Pointers/References in Python?

2008-07-30 Thread Brian Blais

On Jul 30, 2008, at 10:46 , [EMAIL PROTECTED] wrote:


Of course I can just build those lists naively by creating copies of
the original list and then sorting them according to my wishes. But
that would create huge memory overhead.


If the list itself is not memory intensive, but only the objects,  
then you shouldn't have to worry.  For example,


In [1]:big_object=[0.0]*int(1e7)  # about 40 meg

In [2]:big_object2=[0.0]*int(1e7) # another 40 meg

In [3]:list1=[big_object,big_object2]  # maybe a few bytes more, but  
no copy


In [4]:list2=[big_object2,big_object]  # maybe a few bytes more, but  
no copy



after this, my python process takes about 80 meg.  names like  
big_object are just names, and they reference an object in memory.   
if you say a=big_object, you are saying that the name "a" should also  
reference that same object.




bb




--
Brian Blais
[EMAIL PROTECTED]
http://web.bryant.edu/~bblais



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

Re: Pointers/References in Python?

2008-07-30 Thread Brian Blais

On Jul 30, 2008, at 10:46 , [EMAIL PROTECTED] wrote:


Of course I can just build those lists naively by creating copies of
the original list and then sorting them according to my wishes. But
that would create huge memory overhead.


If the list itself is not memory intensive, but only the objects,  
then you shouldn't have to worry.  For example,


In [1]:big_object=[0.0]*int(1e7)  # about 40 meg

In [2]:big_object2=[0.0]*int(1e7) # another 40 meg

In [3]:list1=[big_object,big_object2]  # maybe a few bytes more, but  
no copy


In [4]:list2=[big_object2,big_object]  # maybe a few bytes more, but  
no copy



after this, my python process takes about 80 meg.  names like  
big_object are just names, and they reference an object in memory.   
if you say a=big_object, you are saying that the name "a" should also  
reference that same object.




bb




--
Brian Blais
[EMAIL PROTECTED]
http://web.bryant.edu/~bblais



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

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Matthew Fitzgibbons

Carl Banks wrote:

On Jul 30, 1:58 am, "Russ P." <[EMAIL PROTECTED]> wrote:

On Jul 29, 10:33 pm, Carl Banks <[EMAIL PROTECTED]> wrote:


On Jul 30, 1:15 am, "Russ P." <[EMAIL PROTECTED]> wrote:

Having said that, it would sure be nice to be able to write
if myList is not empty:
instead of
if len(myList) != 0:

I can agree with this.

But I guess that could only work if there were only one empty list
that represents all empty lists (as there is only one actual "None").
I don't know if that makes sense or not.


I mean in general.  I wouldn't spell it like that.  I would prefer if
empty(x), with an __empty__ method.  (And support __nonzero__ aka
__bool__ dropped completely.)


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



__nonzero__ is not only meaningful for sequence types.

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


Re: Python parsing iTunes XML/COM

2008-07-30 Thread Jerry Hill
On Wed, Jul 30, 2008 at 10:58 AM, william tanksley
<[EMAIL PROTECTED]> wrote:
> Here's one example. The others are similar -- they have the same
> things that look like problems to me.
>
> "Buffett Time - Annual Shareholders\xc2\xa0L.mp3"
>
> Note some problems here:
>
> 1. This isn't Unicode; it's missing the u"" (I printed using repr).
> 2. It's got the UTF-8 bytes there in the middle.
>
> I tried doing track_id.encode("utf-8"), but it doesn't seem to make
> any difference at all.

I don't have anything to say about your iTunes problems, but encode()
is the wrong method to turn a byte string into a unicode string.
Instead, use decode(), like this:

>>> track_id = "Buffett Time - Annual Shareholders\xc2\xa0L.mp3"
>>> utrack_id = track_id.decode('utf-8')
>>> type(utrack_id)

>>> print utrack_id
Buffett Time - Annual Shareholders L.mp3
>>> print repr(utrack_id)
u'Buffett Time - Annual Shareholders\xa0L.mp3'
>>>

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


Re: Is it allowed to use function results as default arguments ?

2008-07-30 Thread Terry Reedy



fred.haab wrote:

Well, others have answered the question, but I thought I'd throw in
that it would be more pythonic to do something like:

def Get_Relative_Path(target, base = None):
if base is None:
base = os.curdir
...


Since os.curdir is a constant, this is nonesensical.  One only needs the 
dummy default when one wants an expression re-evaluated with each call.


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


Re: Pointers/References in Python?

2008-07-30 Thread bearophileHUGS
boblatest:
> I have a long list of memory-heavy objects that I would like to access
> in differently sorted order. Let's say I'd like to have lists called
> by_date or by_size that I can use to access the objects in the
> specified order.

Just create a new list with a different sorting order, for example
using:

from operator import attrgetter
by_date = sorted(input_data, key=attrgetter("date"))
by_size = sorted(input_data, key=attrgetter("size"))

Python doesn't copy by value by default, so you end having just a
light list of references.

To understand the situation better, there's a FAQ about how Python
associates names to things.

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


Re: Standard module for parsing emails?

2008-07-30 Thread Phillip B Oldham
If there isn't a standard library for parsing emails, is there one for
connecting to a pop/imap resource and reading the mailbox?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is it possible to consume UTF8 XML documents using xml.dom.pulldom?

2008-07-30 Thread Simon Willison
Follow up question: what's the best way of incrementally consuming XML
in Python that's character encoding aware? I have a very large file to
consume but I'd rather not have to fall back to the raw SAX API.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Pointers/References in Python?

2008-07-30 Thread Maric Michaud
Le Wednesday 30 July 2008 16:46:37 [EMAIL PROTECTED], vous avez écrit :
> Hello,
>
> I have a long list of memory-heavy objects that I would like to access
> in differently sorted order. Let's say I'd like to have lists called
> by_date or by_size that I can use to access the objects in the
> specified order.
>
...
> I know there is a thing called "shallow copy" that has something to do
> with not duplicating memory content but I don't understand the
> concept. Maybe that's what would help here, too.
>

In fact, all containers in python contains references of objects.

>>>[54]: a = [1]

>>>[55]: b = [a]

>>>[56]: c = list(sorted(b))

>>>[57]: b, c
...[57]: ([[1]], [[1]])

>>>[58]: b.append(3)

>>>[59]: b, c
...[59]: ([[1], 3], [[1]])

>>>[60]: a.append(0)

>>>[61]: b, c
...[61]: ([[1, 0], 3], [[1, 0]])

This is if you want to make a true copy (called deep copy) that you'll have to 
do extra steps (using copy module for example).

-- 
_

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


Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Matthew Fitzgibbons

Russ P. wrote:

On Jul 30, 12:03 am, Heiko Wundram <[EMAIL PROTECTED]> wrote:

Am Mittwoch, 30. Juli 2008 08:30:48 schrieb Russ P.:


On Jul 29, 11:09 pm, Erik Max Francis <[EMAIL PROTECTED]> wrote:

I'm getting this sneaking suspicion that you guys are all putting us on.

As I said in an earlier post, I realize that this would only work if
there were only one copy of "empty" (as there is only one copy of
"None"). I don't know off hand if that is feasible or not.
You reply reeks of the kind of pedantic snobbishness that makes me
sick.

I can understand (and pretty much sympathise) that you get this kind of reply,
simply because the point you and Carl Banks (formulated somewhat differently)
put up has been answered again and again (in this thread), and I can only
repeat it once more:

__nonzero__(), i.e. the "cast" to boolean, is THE WAY to test whether a
container is empty or not. Like this design decision, or don't like it, but
the discussion is not going to go anywhere unless you concede that there is a
(very explicit!) way to test for non-emptiness of a container already, and
you're currently simply discussing about adding/using syntactic sugar
(different means of expressing the test) to suit your own personal taste
better. Anyway, check the documentation for __nonzero__(): if the object
doesn't implement that, but implements __len__(), the interpreter "replaces"
the __nonzero__() test by __len__()>0, so I guess someone in the design
department must've seen it logical for the truth value of a container to
express the test "len(x)>0" at some point in time to make this interpretation
for the truth value of a container.

There cannot be an argument about missing/misplaced functionality (that's what
you make it sound like), if the functionality for doing what you want to do
is there and you simply don't like the syntax, which I can somewhat relate to
because style is a personal thing, even though I don't see either points made
by you or Carl Banks, because implicit casting to bool is so common in pretty
much every programming language to test for "truth" of an object, and IMHO
it's completely logical to extend that idea to containers to mean
empty/non-empty.

Eric Max Francis tried to explain why your syntactic "enhancement" would come
at a much greater price than its worth, and he's absolutely right in that, as
it's an abuse of the "is" operator, but again, that's a somewhat different
point. It changes nothing about the fact that all this discussion centers
around something that is a non-point, but simply a matter of personal taste.

--
Heiko Wundram


Oh, Lordy. I understand perfectly well how boolean tests, __len__, and
__nonzero__ work in Python. It's very basic stuff. You can quit
patronizing me (and Carl too, I'm sure).

The point that you seem to be missing, or refuse to acknowledge for
some reason, is that  "if x" can be mistakenly applied to any object
when the programmer thinks that x is a list -- and the programmer will
receive no feedback on the error.

I have made errors like that, and I could have saved some time had I
used an "empty" method that only applies to a list or other sequence.

Is that an important issue? I don't know. I'm not claiming it is. But
you cannot just sweep it away as nothing.
--
http://mail.python.org/mailman/listinfo/python-list



See, I can agree with this. If you're expecting a list (and only a list) 
then your point makes sense. 'if x' can get you into trouble if you 
_don't_ want its polymorphism.


Although, if my function is expecting a list, my preference is to do:

if not isinstance(x, list):
raise SomeMeaningfulException()
# do stuff with the list

I put my type checking at the top of the function, so readers can 
reference it easily.


However, Carl's point is that 'if x' is never preferable to the more 
verbose and slower "simple test". I do not agree with this.


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


Re: undo a dictionary

2008-07-30 Thread Kay Schluehr
On 30 Jul., 16:51, mmm <[EMAIL PROTECTED]> wrote:
> I found code to undo a dictionary association.
>
> def undict(dd, name_space=globals()):
> for key, value in dd.items():
> exec "%s = %s" % (key, repr(value)) in name_space
>
> So if i run
>
> >>> dx= { 'a':1, 'b': 'B'}
> >>> undict(dx)
>
> I get>>> print A, B
>
> 1 B
>
> Here,  a=1 and b='B'
>
> This works well enough for simple tasks and I understand the role of
> globals() as the default names space, but creating local variables is
> a problem.

Python is lexically scoped. You can't create locals at runtime.

> Also having no output arguemtns to undict() seems
> counterintuitive.  Also, the function fails if the key has spaces or
> operand characters (-,$,/,%).

Python names can't have punctuation with the exception of underscores.

> Finally I know I will have cases where
> not clearing (del(a,b)) each key-value pair might create problems in a
> loop.
>
> So I wonder if anyone has more elegant code to do the task that is
> basically the opposite of creating a dictionary from a set of
> globally assigned variables.  And for that matter a way to create a
> dictionary from a set of variables (local or global).  Note I am not
> simply doing and  undoing dict(zip(keys,values))

May I ask what's wrong with having namespaces in a language?


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


Re: Pointers/References in Python?

2008-07-30 Thread Gary Herron

[EMAIL PROTECTED] wrote:

Hello,

I have a long list of memory-heavy objects that I would like to access
in differently sorted order. Let's say I'd like to have lists called
by_date or by_size that I can use to access the objects in the
specified order.

Of course I can just build those lists naively by creating copies of
the original list and then sorting them according to my wishes. But
that would create huge memory overhead. Of course I could use lists of
indices into the "master" list, just as in C I'd create lists or
arrays of pointers into the original data.

Is there a clever Python way to do this, or should I just use lists of
indices?
  


No need.  A Python list contains *references* to objects, not copies of 
objects.  (The same is true of variables, dictionaries, sets, and so 
on...). 

For example, in the following code,  only one copy of HeavyObject 
exists, however, it is referred to many times.


a = HeavyObject()
b = a
A = [a,b]
B = [b,a]
C = set([a,b])
D = {1:a, 2:b}
... and do on


Implementation wise, a long list consumes about 4 bytes per list element 
(that's one address per), plus a tine amount of overhead.



Gary Herron



I know there is a thing called "shallow copy" that has something to do
with not duplicating memory content but I don't understand the
concept. Maybe that's what would help here, too.

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


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


Re: undo a dictionary

2008-07-30 Thread bockman
On 30 Lug, 16:51, mmm <[EMAIL PROTECTED]> wrote:
> I found code to undo a dictionary association.
>
> def undict(dd, name_space=globals()):
>     for key, value in dd.items():
>         exec "%s = %s" % (key, repr(value)) in name_space
>
> So if i run
>
> >>> dx= { 'a':1, 'b': 'B'}
> >>> undict(dx)
>
> I get>>> print A, B
>
> 1 B
>
> Here,  a=1 and b='B'
>
> This works well enough for simple tasks and I understand the role of
> globals() as the default names space, but creating local variables is
> a problem. Also having no output arguemtns to undict() seems
> counterintuitive.  Also, the function fails if the key has spaces or
> operand characters (-,$,/,%).  Finally I know I will have cases where
> not clearing (del(a,b)) each key-value pair might create problems in a
> loop.
>
> So I wonder if anyone has more elegant code to do the task that is
> basically the opposite of creating a dictionary from a set of
> globally assigned variables.  And for that matter a way to create a
> dictionary from a set of variables (local or global).  Note I am not
> simply doing and  undoing dict(zip(keys,values))


Maybe you can use objects as pseudo name spaces and do sommething like
this:

>>> class Scope(object):
def dict(self):
res = dict()
for k, v in self.__dict__.items(): res[k] = v
return res
def undict(self, dict):
for k,v in dict.items():
setattr(self, k, v )


>>> myscope = Scope()
>>> myscope.undict(dict(A=1, B=2))
>>> myscope.A
1
>>> myscope.B
2
>>> myscope.dict()
{'A': 1, 'B': 2}
>>>


Ciao
--
FB


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


Re: variable expansion with sqlite

2008-07-30 Thread marc wyburn
Hi and thanks,

I was hoping to avoid having to weld qmarks together but I guess
that's why people use things like SQL alchemy instead.  It's a good
lesson anyway.

Thanks, Marc.


On Jul 30, 2:24 pm, Tim Golden <[EMAIL PROTECTED]> wrote:
> Gerhard Häring wrote:
> > My code would probably look very similar. Btw you don't need to use
> > list() on an iterable to pass to executemany(). pysqlite's executemany()
> > accepts anything iterable (so generators work fine, too).
>
> Thanks for that. My finger-memory told me to do that, possibly
> because some *other* dbapi interface only accepts lists. Can't
> quite remember. I'm usually all in favour of non-crystallised
> iterators.
>
> > Also, with SQLite you can just skip data type definitions like
> > VARCHAR(200). They're ignored anyway.
>
> Heh. Once again, finger memory forced me to put *something*
> in there. I've been developing Enterprise databases for too
> long :)
>
> TJG

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


RE: interpreter vs. compiled

2008-07-30 Thread Dino Viehland
It looks like the pickle differences are due to two issues.  First IronPython 
doesn't have ASCII strings so it serializes strings as Unicode.  Second there 
are dictionary ordering differences.  If you just do:

{ 'a': True, 'b': set( ) }

Cpy prints: {'a': True, 'b': set([])}
Ipy prints: {'b': set([]), 'a': True}

The important thing is that we interop - and indeed you can send either pickle 
string to either implementation and the correct results are deserialized 
(modulo getting Unicode strings).

For your more elaborate example you're right that there could be a problem 
here.  But the DLR actually recognizes this sort of pattern and optimizes for 
it.  All of the additions in your code are what I've been calling serially 
monomorphic call sites.  That is they see the same types for a while, maybe 
even just once as in your example, and then they switch to a new type - never 
to return to the old one.  When IronPython gives the DLR the code for the call 
site the DLR can detect when the code only differs by constants - in this case 
type version checks.  It will then re-write the code turning the changing 
constants into variables.  The next time through when it sees the same code 
again it'll re-use the existing compiled code with the new sets of constants.

That's still slower than we were in 1.x so we'll need to push on this more in 
the future - for example producing a general rule instead of a type-specific 
rule.  But for the time being having the DLR automatically handle this has been 
working good enough for these situations.

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of castironpi
Sent: Tuesday, July 29, 2008 11:40 PM
To: [email protected]
Subject: Re: interpreter vs. compiled

I note that IronPython and Python's pickle.dumps do not return the
same value.  Perhaps this relates to the absence of interpreter loop.

>>> p.dumps( { 'a': True, 'b': set( ) } )
IPy: '(dp0\nVb\np1\nc__builtin__\nset\np3\n((lp4\ntp5\nRp2\nsVa
\np6\nI01\ns.'
CPy: "(dp0\nS'a'\np1\nI01\nsS'b'\np2\nc__builtin__\nset
\np3\n((lp4\ntp5\nRp6\ns."

You make me think of a more elaborate example.

for k in range( 100 ):
  i= j()
  g= h+ i
  e= f+ g
  c= d+ e
  a= b+ c

Here, j creates a new class dynamically, and returns an instance of
it.  Addition is defined on it but the return type from it varies.

If I read you correctly, IPy can leave hundreds of different addition
stubs laying around at the end of the for-loop, each of which only
gets executed once or twice, each of which was compiled for the exact
combination of types it was called for.

I might construe this to be a degenerate case, and the majority of
times, you'll reexecute stubs enough to outweigh the length of time
the compilation step takes.  If you still do the bounds checking, it
takes extra instructions (C doesn't), but operation switch-case
BINARY_ADD, (PyInt_CheckExact(v) && PyInt_CheckExact(w)), and POP and
TOP, are all handled by the selection of stubs from $addSite.

I'm read from last April:
>>> The most interesting cases to me are the 5 tests where CPython is more than 
>>> 3x faster than IronPython and the other 5 tests where IronPython is more 
>>> than 3x faster than CPython.  CPython's strongest performance is in 
>>> dictionaries with integer and string keys, list slicing, small tuples and 
>>> code that actually throws and catches exceptions.  IronPython's strongest 
>>> performance is in calling builtin functions, if/then/else blocks, calling 
>>> python functions, deep recursion, and try/except blocks that don't actually 
>>> catch an exception.
<<< 
http://lists.ironpython.com/pipermail/users-ironpython.com/2007-April/004773.html

It's interesting that CPython can make those gains still by using a
stack implementation.

I'll observe that IronPython has the additional dependency of the
full .NET runtime.  (It was my point 7/18 about incorporating the GNU
libs, that to compile to machine-native, as a JIT does, you need the
instruction set of the machine.)   Whereas, CPython can disregard
them, having already been compiled for it.

I think what I was looking for is that IronPython employs the .NET to
compile to machine instructions, once it's known what the values of
the variables are that are the operands.  The trade-off is compilation
time + type checks + stub look-up.

What I want to know is, if __add__ performs an attribute look-up, is
that optimized in any way, after the IP is already in compiled code?

After all that, I don't feel so guilty about stepping on Tim's toes.

On Jul 30, 12:12 am, Dino Viehland <[EMAIL PROTECTED]>
wrote:
> IronPython doesn't have an interpreter loop and therefore has no POP / TOP / 
> etc...   Instead what IronPython has is a method call Int32Ops.Add which 
> looks like:
>
> public static object Add(Int32 x, Int32 y) {
> long result = (long) x + y;
> if (Int32.MinValue <= result && result <= Int32.MaxValue) {
> return 

Re: Is it possible to consume UTF8 XML documents using xml.dom.pulldom?

2008-07-30 Thread Paul Boddie
On 30 Jul, 16:32, Simon Willison <[EMAIL PROTECTED]> wrote:
> I'm having a horrible time trying to get xml.dom.pulldom to consume a
> UTF8 encoded XML file. Here's what I've tried so far:
>
> >>> xml_utf8 = """
>
> Simon\xe2\x80\x99s XML nightmare
> """>>> from xml.dom import pulldom
> >>> parser = pulldom.parseString(xml_utf8)
> >>> parser.next()
>
> ('START_DOCUMENT', )>>> 
> parser.next()
>
> ('START_ELEMENT', )>>> parser.next()
>
> ...
> UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in
> position 21: ordinal not in range(128)

I can't reproduce this on Python 2.3.6 or 2.4.4 on RHEL 4. Instead, I
get the usual...

('CHARACTERS', )

And I can get the content of the text node as a proper Unicode object.

[...]

> Is it possible to consume utf8 or unicode using xml.dom.pulldom or
> should I try something else?

Yes, it is possible, at least in Python 2.3.6 and 2.4.4 configured
with --enable-unicode=ucs4 (which is what Red Hat does and expects).

Paul

P.S. You shouldn't try and pass Unicode to the parser, since XML
parsing in its entirety deals with byte sequences and character
encodings, although I suppose that there's some kind of character-
based (ie. Unicode value-based) parsing method defined somewhere by
some committee or other.
--
http://mail.python.org/mailman/listinfo/python-list


ANN: Google custom search engine for Python

2008-07-30 Thread Gerard flanagan

What is it?
---

A Google custom search engine which targets only the following sites:

+ `The Hazel Tree `__
+ `The Python standard library docs `__
+ `The Python wiki `__
+ `Python Package Index `__

Where can I access it?
--

The home page of the search engine is here:

http://www.google.com/coop/cse?cx=002031040340806163079:nkigkp_irqk

As well as accessing it from its home page, you can link to it from your
own web sites, or add it as a gadget to your Google home page (if you 
have one) - see the above link for details.


No ads
--

`The Hazel Tree `__ is a not-for-profit site
and no ads will appear in the search results.

Using refinements
-

To refine the search to any of the individual sites, you can specify a
refinement using the following labels: stdlib, wiki, pypi, thehazeltree

So, to just search the python wiki, you would do:

   somesearchterm more:wiki

and similarly:

   somesearchterm more:stdlib
   somesearchterm more:pypi
   somesearchterm more:thehazeltree

About http://thehazeltree.org
-

`The Hazel Tree `__ is a collection of popular
Python texts that I have converted to reStructuredText and put together
using `Sphinx `__. It's in a publishable state,
but not as polished as I'd like, and since I'll be mostly offline for 
the next month it will have to remain as it is for the present. 
However, the search engine is ready now and the clock is ticking on its
subscription (one year, renewal depending on success of site), so if 
it's useful to anyone, it's all yours (and a link back to

http://thehazeltree.org would be appreciated).

Cheers,

G.

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


Re: Standard module for parsing emails?

2008-07-30 Thread Maric Michaud
Le Wednesday 30 July 2008 17:15:07 Phillip B Oldham, vous avez écrit :
> If there isn't a standard library for parsing emails, is there one for
> connecting to a pop/imap resource and reading the mailbox?
> --
> http://mail.python.org/mailman/listinfo/python-list

There are both shipped with python, email module and poplib, both very well 
documented in the official doc (with examples and all).

email module is rather easy to use, and really powerful, but you'l need to 
manage yourself the many ways email clients compose a message, and broken php 
webmails that doesn't respect RFCs (notably about encoding)...

-- 
_

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


Re: Standard module for parsing emails?

2008-07-30 Thread Aspersieman
Phillip B Oldham wrote:
> If there isn't a standard library for parsing emails, is there one for
> connecting to a pop/imap resource and reading the mailbox?
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>   
The search [1] yielded these results:
1) http://docs.python.org/lib/module-email.html
2)
http://www.devshed.com/c/a/Python/Python-Email-Libraries-SMTP-and-Email-Parsing/

I have used the email module very successfully.

Also you can try the following to connect to mailboxes:
1) poplib
2) smtplib

For parsing the mails I would recommend pyparsing.


[1]
http://www.google.com/search?client=opera&rls=en&q=python+email&sourceid=opera&ie=utf-8&oe=utf-8

Regards

Nicolaas

-- 

The three things to remember about Llamas:
1) They are harmless
2) They are deadly
3) They are made of lava, and thus nice to cuddle. 


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


Re: Is it possible to consume UTF8 XML documents using xml.dom.pulldom?

2008-07-30 Thread Simon Willison
On Jul 30, 4:43 pm, Paul Boddie <[EMAIL PROTECTED]> wrote:
> I can't reproduce this on Python 2.3.6 or 2.4.4 on RHEL 4. Instead, I
> get the usual...
>
> ('CHARACTERS', )

I'm using Python 2.5.1 on OS X Leopard:

$ python
Python 2.5.1 (r251:54863, Feb  4 2008, 21:48:13)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin

I just tried it out on Python 2.4.2 on an Ubuntu machine and it worked
fine! I guess this must be an OS X Python bug. How absolutely
infuriating.

Thanks,

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


Re: Standard module for parsing emails?

2008-07-30 Thread Maric Michaud
Le Wednesday 30 July 2008 17:55:35 Aspersieman, vous avez écrit :
> For parsing the mails I would recommend pyparsing.

Why ? email module is a great parser IMO.

-- 
_

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


Re: interpreter vs. compiled

2008-07-30 Thread Terry Reedy



castironpi wrote:


The current CPython VM does not compile code.


CPython compiles Python code to bytecode for its CPython *hardware 
independent* VM using standard compiler methdods and tools (lexer, 
parser, code generator, and optimizer).  That VM (interpreter) is 
written in portable-as-possible C, with machine/OS #ifdefs added as 
needed.



WHY NOT?  Why doesn't CPython do it?


1. Portability: The Microsoft C# JIT compiler runs under Windows .NET on 
x86/amd64 and maybe it64 and what else?  Just porting .NET to run 0n 
Linux on the same processors was/is a bit task.  Does MONO have a JIT also?


There is a JIT for Python: Psyco.  It originally only worked on x86.  I 
am not sure what else.  It originated as a PhD project, working with 
CPython, and was developed further as part of PyPy, but I do not know if 
there is any current progress.


Python VM runs on numerous platforms.

2. Money: C#, its JIT, and IronPython were and are funded by MS. 
Getting JIT right is hard and tedious.


CPython is mostly a volunteer project. It is also the Python development 
platform.  So it has to be simple enough for volunteers to pick up on 
its innards and for experimentation to be possible.  Give the PSF more 
resources and


tjr


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


Re: Is it possible to consume UTF8 XML documents using xml.dom.pulldom?

2008-07-30 Thread Simon Willison
On Jul 30, 4:59 pm, Simon Willison <[EMAIL PROTECTED]> wrote:
> I just tried it out on Python 2.4.2 on an Ubuntu machine and it worked
> fine! I guess this must be an OS X Python bug. How absolutely
> infuriating.

Some very useful people in #python on Freenode pointed out that my bug
occurs because I'm trying to display things interactively in the
console. Saving to a variable instead fixes the problem.

Thanks for your help,

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


Re: Correct Attribute Assignment Methodology?

2008-07-30 Thread Terry Reedy



Tim Cook wrote:

Say I have these classes:

class Parent(object):
  """Parent is abstract"""
  a=None
  def showA():
   return self.a

class Child(Parent):
  """inherits a and showA from Parent"""

  def __init__(self,a,b):
self.a=a   
self.b=b


  def showAB():
   return self.a,self.b


class GrandChild(Child):
  """inherits all of the above"""

  def __init__(self,a,b,c):
   self.a=a
   self.b=b  
   """should this be Child.__init__(a,b)? or Child.__init__(b)?""  


Child.__init__(self,a,b) # requires all three params.


   """if so; why? if not why not?"""


In this simple case, I would probably do what you did.  But a reason to 
call the baseclass init would be to not repeat yourself and keep the 
derived class in sync.  Suppose, for instance, Child.__init__ had 
'self.frob = math.sin(a) + math.cos(b) - math.sqrt(a*a+b*b)', and then 
you realize that the formula needs to be changed.  Better to have it in 
one place.



   self.c=c

Thanks for answering these very basic questions but I am not certain
about the correct way.  I know that in Python, assignment in the
GrandChild class will work but is that correct?


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


Is there a such Python module ?

2008-07-30 Thread Johny
Is there a Python module that can help with reading SMS message from a
mobile phone?
Or is there an example how to read SMS message using a program written
in Python,C, or any other language?
Thank you very much for help
L.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Matthew Fitzgibbons

Carl Banks wrote:

On Jul 29, 6:42 pm, Matthew Fitzgibbons <[EMAIL PROTECTED]> wrote:

Carl Banks wrote:

Much like in Steven D'Aprano's example, still the only actual code
snippet I've seen, it seems that this can easily be done with a simple
explicit test by having all no-advance filters return None and testing
with "if x is not None".  So it doesn't pass my criterion of being not
replaceable with simple explicit test.
Maybe that's not workable for some reason.  Perhaps if you'd post a
code example that shows this, rather than just talking about it, you
might be more persuasive.
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list

The no-advance filters have to return the object because I don't just
forget about it; I evaluate whether I pass it to the next filter or drop
it in a completely different queue for use in the next stage of the
operation. True means 'I'm ready to move on to the next stage,' False
means 'Do the filter thing some more.'


I think I see what you're saying, and yeah I guess that could really
take advantage of polymorphism between very different types.


Furthermore, the argument that I should just change my API to make a
'simple test' work is not very convincing.


I wasn't suggesting you change it: I was trying to ascertain whether
it would have suffered much if you had written it with explicit tests
in the first place, or if Python didn't even have magical booleans.


Yes it would have suffered. I chose the implementation I did because it 
made the most sense to me and was the most flexible (a key requirement). 
Instead of cobbling together my own way, I used the way that Python gave me.


Python doesn't have magic booleans. They are instead a very well-defined 
language mechanism that isn't perfect for every circumstance, but is 
pretty good for the most part. I wanted to do meaningful boolean tests 
on various objects, so I used the mechanism that my language gave me.





The natural, obvious way for
a filter to work is to pass through the data it operates on; why on
Earth would it return None? I want to DO something with the data. In
this case, make a decision about where to pass the data next.


If you don't mind me asking: what do you do actually DO with a zero or
empty list?


Depends on exactly what the next stage is. Typically, zeros and empty 
lists are not meaningful for the next stage, so they get dropped then if 
they make it through. I don't want to restrict what gets passed through, 
though, because I could end up with several meaningful data types, 
making a simple test again impossible. So I pass everything through and 
let the next stage decide.





In Java,
to accomplish this I would have to do lots of introspection and value
checking (adding more any time I came up with a new kind of input), or
make a new kind of interface that gives me a method so I can do a
'simple test' (including wrappers for ints and arrays and anything else
I decide to pass in down the road). But Python supports duck typing and
gives me a handy __nonzero__ method; I can rebind __nonzero__ in my
filters for my own classes, and ints and lists are handled how I want
them to be by default. So why jump through hoops instead of just using
'if x'?


Ah, so it's just happens to work.  Still, just happening to work
works. (shrug)


Nonono. The point you seem to be missing is that 'if x' is very well 
defined. There is nothing magic or arbitrary about what it does. It 
works here and elsewhere because Python (a) chooses good default 
behavior (its treatment of lists and ints, etc) and (b) gives you a way, 
__nonzero__, to change the behavior to suit your needs.





I don't have any postable code (it's in a half way state and I haven't
touched it for a while), but I'll see if I can't find the time to bang
something up to give you the gist.


I wouldn't bother at this point.  I was looking to see if someone
could come up with something to disprove my belief on the polymorphic
uselessness of "if x" relative to explicit tests, and if (as I
anticipated) they did not, I could claim that "if x" is really just a
glorified keystroke saver.  But I now realize that the failure of this
bunch doesn't prove anything.  I don't think most people even realize
why answering the question I asked would demonstrate the usefulness of
"if x".


Of course you don't _need_ to have 'if x'; after all, REAL 
programmers code in machine language. The whole point of a 
high-level language is to make life easier. Python is very dynamic and 
allows duck typing so that you can use these tools to do clever things 
that would otherwise be very difficult. It even gives you a handy 
polymorphic mechanism to do boolean tests, which my example illustrates.


You asked for a use case for a polymorphic 'if x' that can't be easily 
replaced by a simple test. I gave one. Then you asked for a code sample, 
but now have dismissed my sample as not compelling without having seen 
it. But here it is anyway (attached). It's pret

Syntax error in my script

2008-07-30 Thread laredotornado
Hi,

This might be more relevant for another group, but since this is a
Python script, thought I'd start here.  I'm trying to write a WLST
script for WebLogic 9.2. I coped one directly from WebLogic's site
(http://e-docs.bea.com/wls/docs90/config_scripting/
using_WLST.html#1078952), but I'm getting errors.  Specifically, I'm
getting

$HOSTNAME:"$PWD"->sh run_setup_cluster.sh

Initializing WebLogic Scripting Tool (WLST) ...

Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands

Problem invoking WLST - Traceback (innermost last):
(no code object) at line 0
File "/export/third-party/etsbea/home/etsbea/tests/npsconfig/
createcluster.py", line 2
from javax.management import *
^
SyntaxError: invalid syntax


Below is my script. I know nothing about Python but cutting and
pasting from BEA's site isn't cutting it.

Begin createcluster.py file===
from java.util import *
from javax.management import *
import javax.management.Attribute

print 'starting the script  '

connect('system','weblogic','t3://localhost:7001')
clusters = "NPSCONFIG_GUI_Cluster"
ms1 = {'managed1':7019:8020,'managed2':7020:8021}

clustHM = HashMap()
edit()
startEdit()

for c in clusters:
print 'creating cluster '+c
clu = create(c,'Cluster')
clustHM.put(c,clu)
cd('Clusters/' + c)
set('MulticastAddress', '237.0.0.101')
set('MulticastPort', 9200)
set('WeblogicPluginEnabled', 'true')

cd('..\..')

clus1 = clustHM.get(clusters[0])

for m, lp, ssl_lp in ms1.items():
managedServer = create(m,'Server')
print 'creating managed server '+m
managedServer.setListenAddress('10.61.6.134')
managedServer.setListenPort(lp)
managedServer.setEnabled(0)
cd('SSL/cgServer')
managedServer.setEnabled(1)
managedServer.setListenPort(ssl_lp)
managedServer.setCluster(clus1)

save()
activate(block="true")
disconnect()
print 'End of script ...'
exit()
==End cretaecluster.py file===
--
http://mail.python.org/mailman/listinfo/python-list


Non Continuous Subsequences

2008-07-30 Thread bearophileHUGS
This post is not about practical stuff, so if you have little time,
you may ignore it.

This is a task of the rosettacode.org site:
http://www.rosettacode.org/wiki/Non_Continuous_Subsequences

A subsequence contains some subset of the elements of this sequence,
in the same order. A continuous subsequence is one in which no
elements are missing between the first and last elements of the
subsequence. The task is to enumerate all non-continuous subsequences
for a given sequence.

Translating the Scheme code to Python was easy (and I think this is
quite more readable than the Scheme version):

def ncsub(seq, s=0):
if seq:
x = seq[:1]
xs = seq[1:]
p2 = s % 2
p1 = not p2
return [x + ys for ys in ncsub(xs, s + p1)] + ncsub(xs, s +
p2)
else:
return [[]] if s >= 3 else []

Output:

>>> ncsub(range(1, 4))
[[1, 3]]
>>> ncsub(range(1, 5))
[[1, 2, 4], [1, 3, 4], [1, 3], [1, 4], [2, 4]]
>>> ncsub(range(1, 6))
[[1, 2, 3, 5], [1, 2, 4, 5], [1, 2, 4], [1, 2, 5], [1, 3, 4, 5], [1,
3, 4], [1, 3, 5], [1, 3], [1, 4, 5], [1, 4], [1, 5], [2, 3, 5], [2, 4,
5], [2, 4], [2, 5], [3, 5]]


To test its speed I use this:

from sys import argv

def ncsub(seq, s=0):
if seq:
x = seq[:1]
xs = seq[1:]
p2 = s % 2
p1 = not p2
return [x + ys for ys in ncsub(xs, s + p1)] + ncsub(xs, s +
p2)
else:
return [[]] if s >= 3 else []

import psyco; psyco.bind(ncsub)
print len( ncsub(range(1, int(argv[1]))) )


On a 2 GHz CPU it needs 6.4s with n=20 (the output contains 524_097
sublists!), and 7.8s without Psyco, so I think the speed isn't bad.

With the libs I have written for D, translating the Python code is not
difficult (with n=20 it runs in 3.72s with the last DMD compiler):

import d.all;

T[][] ncsub(T)(T[] seq, int s=0) {
if (seq.length) {
T[] xs = seq[1..$];
int p2 = s % 2;
int p1 = !p2;
return map((T[] ys){return seq[0]~ys;}, ncsub(xs, s+p1)) ~
ncsub(xs, s+p2);
} else
return s >= 3 ? [DA!(T)] : null;
}

void main() {
foreach (m; xrange(4, 7))
putr(ncsub(range(1, m)));
}


But with normal D the program is short enough anyway (but a slower to
run (4.7s with n=20) and faster to compile, about 0.1s with full
optimizations and about 0.07s without):

import std.stdio: writefln;

T[][] ncsub(T)(T[] seq, int s=0) {
if (seq.length) {
T[][] aux;
foreach (ys; ncsub(seq[1..$], s + !(s % 2)))
aux ~= seq[0] ~ ys;
return aux ~ ncsub(seq[1..$], s + s % 2);
} else
return s >= 3 ? [new T[0]] : null;
}

void main() {
writefln(ncsub([1, 2, 3]));
writefln(ncsub([1, 2, 3, 4]));
writefln(ncsub([1, 2, 3, 4, 5]));
}


The Scheme version is eager, it comes from the first Haskell version,
that I think is lazy.

In Python the management of lazy iterables feels almost bolted-on
compared to Haskell, for example in Haskell lazy iterables don't
exhaust like in Python (because they are immutable), and while you
create a lazy list you can refer to the items already created.

But in many cases you can create a lazy code in Python too, even if
that may be harder. So I have tried to create a lazy version for
Python, hoping to speed up the code avoiding the creation and joining
of most/all sublists, but I have failed so far (once I have created a
lazy Python version, I can probably create a short lazy version in D
too, my D libs contain most of itertools module too).

In my failed attempts I have used chain() to join the sublists,
islice() to slice their items, and iter() to make the management more
uniform when the input seq is a Python list instead of an xrange, etc.

The:

if seq:

can be replaced by something like:

try:
x = seq2.next()
except StopIteration:
...
else:
...

If you have some time to waste you may suggest me how to write a lazy
version in Python :-)

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


Re: Pointers/References in Python?

2008-07-30 Thread Terry Reedy



[EMAIL PROTECTED] wrote:

Hello,

I have a long list of memory-heavy objects that I would like to access
in differently sorted order. Let's say I'd like to have lists called
by_date or by_size that I can use to access the objects in the
specified order.

Of course I can just build those lists naively by creating copies of
the original list and then sorting them according to my wishes. But
that would create huge memory overhead. Of course I could use lists of
indices into the "master" list, just as in C I'd create lists or
arrays of pointers into the original data.

Is there a clever Python way to do this, or should I just use lists of
indices?

I know there is a thing called "shallow copy" that has something to do
with not duplicating memory content but I don't understand the
concept. Maybe that's what would help here, too.


A containers/collections contain/collect references to objects, not the 
objects themselves.


lcopy = somelist[:] # or list(somelist)

makes a shallow copy, which only copies the references.

There are applications for lists of indexes, but they are fairly 
specialized.


tjr

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


Reasoning behind 'self' parameter in classes?

2008-07-30 Thread Robert Dailey
Hi,

I want to point out first of all that I'm not as familiar with Python as I
should be, and for that reason I question a lot of things because I'm mainly
a C++ programmer and I'm used to certain conveniences. Having said that...

I've always been curious (more so than annoyed) as to why one must
explicitly specify a "self" parameter for member functions in a class in
Python. This seems very "C" like to me, since to do object oriented
programming in C you must devote one parameter to the object itself. In a
higher order language like Python, I would not have expected (and thus am
rather surprised) that this pattern would apply. Is there any particular
reason why 'self' parameters must be specified explicitly? I am curious to
understand the philosophy and design behind this.

In Python 3 will there be any plans to eliminate this syntactic artifact? As
I said, it's not terribly annoying to me but it seems like more of a hack
than anything else. I would feel a bit better if I didn't have to see it. I
don't mean to start any syntax wars or anything, so I hope everyone will
keep an open mind and simply explain the design, rather than defend it. I'm
interested in only facts, and not opinions.

This is an example of a response I'm looking for:
"The self parameter is required because the parser is a bit old and needs to
know the exact object you're referencing"

This is _not_ an example of what I'm looking for:
"Specifying self is a great mysterious thing that we should never question.
Do not question the language! The language is mighty! Don't bring C++ to
Python!"

I appreciate the community's time.
--
http://mail.python.org/mailman/listinfo/python-list

Re: Is it possible to consume UTF8 XML documents using xml.dom.pulldom?

2008-07-30 Thread Paul Boddie
On 30 Jul, 18:17, Simon Willison <[EMAIL PROTECTED]> wrote:
>
> Some very useful people in #python on Freenode pointed out that my bug
> occurs because I'm trying to display things interactively in the
> console. Saving to a variable instead fixes the problem.

What's strange about that is how the object is represented when
displayed:

('CHARACTERS', )

Here, there's no attempt made to encode \u2019 as an ASCII byte
sequence. Does the OS X version of Python do anything special with
string representations?

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


Re: Is there a such Python module ?

2008-07-30 Thread Matthew Fitzgibbons

Johny wrote:

Is there a Python module that can help with reading SMS message from a
mobile phone?
Or is there an example how to read SMS message using a program written
in Python,C, or any other language?
Thank you very much for help
L.
--
http://mail.python.org/mailman/listinfo/python-list



There is a Python distro for Symbian, if your phone is running that. You 
can do things like send/receive SMS messages, control the camera, etc. 
http://wiki.opensource.nokia.com/projects/PyS60. Can't speak to anything 
else.

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


Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Ethan Furman

Carl Banks wrote:

On Jul 29, 6:42 pm, Matthew Fitzgibbons <[EMAIL PROTECTED]> wrote:

I don't have any postable code (it's in a half way state and I haven't
touched it for a while), but I'll see if I can't find the time to bang
something up to give you the gist.


I wouldn't bother at this point.  I was looking to see if someone
could come up with something to disprove my belief on the polymorphic
uselessness of "if x" relative to explicit tests, and if (as I
anticipated) they did not, I could claim that "if x" is really just a
glorified keystroke saver.  But I now realize that the failure of this
bunch doesn't prove anything.  I don't think most people even realize
why answering the question I asked would demonstrate the usefulness of
"if x".

Your example isn't exactly the smoking gun I was looking for, but I
guess we'll have to admit that at least one usage will suffer for not
having it.

Carl Banks


Even for those that did realize, and in fact hoped that that is what you 
were attempting to accomplish, it was still quite frustrating to see you 
ignoring all the non-code, yet perfectly valid examples of why "if x" 
was not only valid, but the most pythonic[1] way to get the task done. 
I think it would have been a better discussion if you had responded with 
reasons why, and not just parroted the "show me the code!" line over and 
over and over and ...  It seemed as if you thought you were the 
professor, impatiently trying to teach a class full of idiots by playing 
the devil's advocate.  I was sure hoping someone would get the actual 
code example and post it, partly because I enjoy learning, but mostly 
because it would (hopefully) shut you up and move the conversation 
along.  In fact, somebody did post some code about a custom matrix 
class, where __len__ was useless, and still you kept on with...  pah. 
It's late, so before I say something stupid I'll finish this.  My last 
thought on the matter -- up until this thread I had looked forward to 
your posts, Carl.  I think you did more damage than good to yourself 
with this stunt.

~Ethan~

[1] by pythonic I mean using the features of the language that make 
sense.  In this case, the __nonzero__ function to have the object in 
question tell us whether or not it's empty.  This seems so basic (the 
__nonzero__ function, that is, and its purpose) -- do you really need 
code to prove it to yourself?



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


Re: Build tool for Python

2008-07-30 Thread Tim Arnold
"Terry Reedy" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>
>
> Hussein B wrote:
>> Hi.
>> Apache Ant is the de facto building tool for Java (whether JSE, JEE
>> and JME) application.
>> With Ant you can do what ever you want: compile, generate docs,
>> generate code, packing, deploy, connecting to remote servers and every
>> thing.
>> Do we have such a tool for Python projects?
>
> Also see thread Continuous integration for Python projects and mention of 
> buildbot.

Surprised no one has mentioned SCons, http://www.scons.org/
I've used it a bit and found it pretty good, out of the box.

--Tim Arnold


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


Interbase

2008-07-30 Thread Mike Hjorleifsson
Has anyone gotten python working with Interbase database platform ?  I
need to query some info from an interbase database on another server
need  a lil help getting started.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Reasoning behind 'self' parameter in classes?

2008-07-30 Thread Matthew Fitzgibbons

Robert Dailey wrote:

Hi,

I want to point out first of all that I'm not as familiar with Python as 
I should be, and for that reason I question a lot of things because I'm 
mainly a C++ programmer and I'm used to certain conveniences. Having 
said that...


I've always been curious (more so than annoyed) as to why one must 
explicitly specify a "self" parameter for member functions in a class in 
Python. This seems very "C" like to me, since to do object oriented 
programming in C you must devote one parameter to the object itself. In 
a higher order language like Python, I would not have expected (and thus 
am rather surprised) that this pattern would apply. Is there any 
particular reason why 'self' parameters must be specified explicitly? I 
am curious to understand the philosophy and design behind this.


In Python 3 will there be any plans to eliminate this syntactic 
artifact? As I said, it's not terribly annoying to me but it seems like 
more of a hack than anything else. I would feel a bit better if I didn't 
have to see it. I don't mean to start any syntax wars or anything, so I 
hope everyone will keep an open mind and simply explain the design, 
rather than defend it. I'm interested in only facts, and not opinions.


This is an example of a response I'm looking for:
"The self parameter is required because the parser is a bit old and 
needs to know the exact object you're referencing"


This is _not_ an example of what I'm looking for:
"Specifying self is a great mysterious thing that we should never 
question. Do not question the language! The language is mighty! Don't 
bring C++ to Python!"


I appreciate the community's time.




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


There was a massive thread "attack a sacred python cow" that brought up 
a lot of reasons why this is the case. If you can ignore the flames, 
you'll find some good info there. But it might not be wise to bring it 
up again a week after it happened last time.


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


Re: like py2exe, but on a mac

2008-07-30 Thread William McBrine
On Tue, 29 Jul 2008 12:24:49 -0700, Russell E. Owen wrote:

> That is exactly what py2app does by default if you run py2app with the
> system python.

Thanks. I see that it* avoids the issue with Tk starting in the 
background that I get with Platypus, too.

In fact, it looks like the bundlebuilder module is adequate for my needs. 
It does put in a version-specific #! line, but if I change that to
#!/usr/bin/env python, the app still works, and it seems to me that it 
will work for any version of Python on OS 10.4, 10.5, and maybe 10.3.

* I still haven't actually tried "it" (py2app), since I realized that I 
already had bundlebuilder, but I'm assuming it's the same in this respect.

-- 
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0 -- pass it on
--
http://mail.python.org/mailman/listinfo/python-list


Re: undo a dictionary

2008-07-30 Thread Terry Reedy



mmm wrote:

I found code to undo a dictionary association.

def undict(dd, name_space=globals()):
for key, value in dd.items():
exec "%s = %s" % (key, repr(value)) in name_space


You are not undoing anything.  You are updating globals() from another 
dict.  But why repr(value)?  Without that, globals().update(dd) would 
work.  In 2.6?/3.0, replace 'dd' with '{a:b for a,b in dd.items()}


dd = { 'a':1, 'b': 'B'}
globals().update({a:b for a,b in dd.items()})
print(a,b)
# 1,B


dx= { 'a':1, 'b': 'B'}
undict(dx)


I get

print A, B

1 B

Here,  a=1 and b='B'


Don't fake interactive output.  You would have to "print a,b".  Above 
gives a NameError.



This works well enough for simple tasks and I understand the role of
globals() as the default names space, but creating local variables is
a problem.


Within functions, yes. Just access the values in the dict.

> Also having no output arguemtns to undict() seems

counterintuitive.


In Python, this is standard for functions that mutate.

> Also, the function fails if the key has spaces or

operand characters (-,$,/,%).


Exec is tricky.  Most people hardly ever use it.

> Finally I know I will have cases where

not clearing (del(a,b)) each key-value pair might create problems in a
loop.


You cannot mutate a dict while iterating through it.


So I wonder if anyone has more elegant code to do the task that is
basically the opposite of creating a dictionary from a set of
globally assigned variables.


See above.


And for that matter a way to create a
dictionary from a set of variables (local or global).


You have to be more specific: there are {} displays and dict(args) call 
and other methods.  Read the manual.


tjr

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


Re: Is it possible to consume UTF8 XML documents using xml.dom.pulldom?

2008-07-30 Thread Peter Otten
Paul Boddie wrote:

> On 30 Jul, 18:17, Simon Willison <[EMAIL PROTECTED]> wrote:
>>
>> Some very useful people in #python on Freenode pointed out that my bug
>> occurs because I'm trying to display things interactively in the
>> console. Saving to a variable instead fixes the problem.
> 
> What's strange about that is how the object is represented when
> displayed:
> 
> ('CHARACTERS', )
> 
> Here, there's no attempt made to encode \u2019 as an ASCII byte
> sequence. Does the OS X version of Python do anything special with
> string representations?

I'm on Kubuntu 7.10 and see the same error as Simon. The problem is in the
minidom.CharacterData class which has the following method

def __repr__(self):
data = self.data
if len(data) > 10:
dotdotdot = "..."
else:
dotdotdot = ""
return "" % (
self.__class__.__name__, data[0:10], dotdotdot)

The data attribute is a unicode instance...

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


Re: Standard module for parsing emails?

2008-07-30 Thread MRAB
On Jul 30, 3:11 pm, Phillip B Oldham <[EMAIL PROTECTED]> wrote:
> On Jul 30, 2:36 pm, Thomas Guettler <[EMAIL PROTECTED]> wrote:
>
> > What do you mean with "quote" here?
> >   2. Prefix of quoted text like your text above in my mail
>
> Basically, just be able to parse an email into its actual and "quoted"
> parts - lines which have been prefixed to indent from a previous
> email.
>
> Most clients use ">" which is easy to check for, but I've seen some
> which use "|" and some which *don't* quote at all. Its causing us
> nightmares in parsing responses to system-generated emails. I was
> hoping someone might've seen the problem previously and released some
> code.

The problem is that sometimes lines might start with ">" for other
reasons, eg text copied from an interactive Python session, which
could occur in ... um ... _this_ newsgroup. :-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Syntax error in my script

2008-07-30 Thread Alan Franzoni
laredotornado was kind enough to say:

[cut]

Indentation counts in Python. You're probably doing something wrong with
whitespace/tab/carriage return.



-- 
Alan Franzoni <[EMAIL PROTECTED]>
-
Remove .xyz from my email in order to contact me.
-
GPG Key Fingerprint:
5C77 9DC3 BD5B 3A28 E7BC 921A 0255 42AA FE06 8F3E
--
http://mail.python.org/mailman/listinfo/python-list


Re: Standard module for parsing emails?

2008-07-30 Thread Diez B. Roggisch
Maric Michaud wrote:

> Le Wednesday 30 July 2008 17:55:35 Aspersieman, vous avez écrit :
>> For parsing the mails I would recommend pyparsing.
> 
> Why ? email module is a great parser IMO.

He talks about parsing the *content*, not the email envelope and possible
mime-body.

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

Re: Is it possible to consume UTF8 XML documents using xml.dom.pulldom?

2008-07-30 Thread Stefan Behnel
Simon Willison wrote:
> Follow up question: what's the best way of incrementally consuming XML
> in Python that's character encoding aware?

iterparse(), as implemented in (c)ElementTree and lxml. Note that ElementTree
and cElementTree are part of Python 2.5, in the xml.etree package.


> I have a very large file to
> consume but I'd rather not have to fall back to the raw SAX API.

Large is fairly relative. Both cElementTree and lxml are pretty memory
friendly, even when parsing into an in-memory tree.

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


Re: Syntax error in my script

2008-07-30 Thread laredotornado
On Jul 30, 11:26 am, Alan Franzoni
<[EMAIL PROTECTED]> wrote:
> laredotornadowas kind enough to say:
>
> [cut]
>
> Indentation counts in Python. You're probably doing something wrong with
> whitespace/tab/carriage return.
>
> --
> Alan Franzoni <[EMAIL PROTECTED]>
> -
> Remove .xyz from my email in order to contact me.
> -
> GPG Key Fingerprint:
> 5C77 9DC3 BD5B 3A28 E7BC 921A 0255 42AA FE06 8F3E

That was it.  Thanks, -
--
http://mail.python.org/mailman/listinfo/python-list


Possible to have multiple loop variables?

2008-07-30 Thread laredotornado
I don't know why I thought this would work, but I would like to have 3
variables in my for loop per iteration.  Those familiar will know that
this

ms1 = {'managed1':7019:8020,'managed2':7020:8021}
for m, lp, ssl_lp in ms1.items():
  managedServer = create(m,'Server')
  print 'creating managed server '+m
  managedServer.setListenAddress('147.191.71.70')
  managedServer.setListenPort(lp)
  managedServer.setEnabled(0)
  cd('SSL/cgServer')
  managedServer.setEnabled(1)
  managedServer.setListenPort(ssl_lp)
  managedServer.setCluster(clus1)

causes

  File "/export/third-party/etsbea/home/etsbea/tests/wlst/
createcluster.py", line 9
ms1 = {'managed1':7019:8020,'managed2':7020:8021}
  ^
SyntaxError: invalid syntax


How would I set up the ms1 array such that I can use three items per
object?

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


Re: Questions about asyncore

2008-07-30 Thread Giampaolo Rodola'
On 30 Lug, 09:49, Frank Millman <[EMAIL PROTECTED]> wrote:
> On Jul 29, 3:40 pm, "Giampaolo Rodola'" <[EMAIL PROTECTED]> wrote:
>
> > On 29 Lug, 13:09, Frank Millman <[EMAIL PROTECTED]> wrote:
>
> Thanks for the reply, Giampaolo.

Glad to help.

> > The benefit of asynchat is that it automatically handles the buffering
> > of both input and output.
> > Aside from set/found_terminator() the other two methods you could want
> > to look at are push() and push_with_producer().
> > push() is a buffered version of asyncore.send(), push_with_producer()
> > accepts a data-producer object you can use in case you want to deal
> > with something other than strings (e.g. files, lists, generators, and
> > so on...).
>
> I looked at push() and push_with_producer(). To be honest I don't
> fully understand why I would want to use them yet - I will have to go
> over them a few more times. However, my handle_write() method seems to
> be working ok and is not complicated, so I will stick with that for
> now.

I don't know whether you need to use them. I've just introduced the
benefits of asynchat over asyncore.
If you're already ok with your handle_read() implementation you
probably don't need anything different.

> > I'm not sure to understand but I doubt you have to use a thread.
> > If you "have to wait for the reply before continuing" just implement
> > this logic into handle_read() or found_terminator() method.
>
> Maybe I am a bit slow

Or maybe my English is not good enough to properly understand what you
need (it wouldn't be the first time, after all... =)).

> ...but I cannot figure out how to do this without
> adding a lot of complication. I will try to give a simple example.
>
> My server is a database server. It sits between the actual database
> and the client, and implements access control, automatic handling of
> foreign keys, etc. It accepts messages to read, update, and write
> data, and returns the results.
>
> For testing purposes, I want the client to send and receive messages
> such as the following (pseudocode) -
>
> -> Read Customer record with CustNo = 'A001'.
> <- Print data, check that it is correct. [1]
> -> Read customer's Branch record.
> <- Print data, check that it is correct.
> -> Update Customer record with new Branch code. [2]
> -> Read Branch code from Customer record.
> <- Print code, check that it has changed.
> -> Read customer's Branch record.
> <- Print data, check that it belongs to the new Branch.
>
> [1] Amongst other things, the server returns the id of the record
> [2] The update request uses the record id to identify which record to
> update
>
> These are just examples of the tests I might want to throw at the
> server. With my multi-threaded approach, the asyncore loop runs in the
> background, and in the foreground I can easily send any message I like
> and check the results. I cannot see how to implement this using
> handle_read() and found_terminator().
>
> Maybe you can give a simple example of an alternative approach.
>
> Thanks
>
> Frank

I pretty much have the same overview I had before.
As far as I can tell the only reason you want to use a thread is when
you have to do something which requires a consistent amount of time to
complete so that the asyncore loop gets blocked.
The question is: is there anything like that in your code?
If the answer is no then you don't need to use threads.
Maybe you are just not used to the asynchronous approach where "wait
for server to respond" or "wait for the response to be complete"
doesn't mean that YOU have to wait.
It means that when a specific condition occurs (e.g. some data is
received) a certain method of the framework you're using will be
called and then it will be up to you deciding what do to.
For example, if you're supposed to do something when a string of 5
digits is received, overwrite the handle_read() method and check if
that's happened.
If not instead of waiting for it to happen just "pass" and wait for
handle_read() to be called again.
This way you don't do anything which blocks the asynchronous loop and
every peer (clients, servers or both) you have in your list of
watchable channels will be served.


If my response hasn't helped you any further try to post some code so
that me or someone else could see what exactly you're trying to do.
Hope this helps, anyway.


--- Giampaolo
http://code.google.com/p/pyftpdlib

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


Re: static variables in Python?

2008-07-30 Thread Rhamphoryncus
On Jul 29, 2:40 pm, kj <[EMAIL PROTECTED]> wrote:
> Yet another noob question...
>
> Is there a way to mimic C's static variables in Python?  Or something
> like it?  The idea is to equip a given function with a set of
> constants that belong only to it, so as not to clutter the global
> namespace with variables that are not needed elsewhere.

I'd go ahead and use globals.  If these really are constant you should
just name them clearly (and possibly use all caps).

If they have a possibility of becoming non-constant in the future,
write a class.  No fancy tricks needed to store state.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is it possible to consume UTF8 XML documents using xml.dom.pulldom?

2008-07-30 Thread Paul Boddie
On 30 Jul, 19:23, Peter Otten <[EMAIL PROTECTED]> wrote:
>
> I'm on Kubuntu 7.10 and see the same error as Simon. The problem is in the
> minidom.CharacterData class which has the following method
>
>     def __repr__(self):
>         data = self.data
>         if len(data) > 10:
>             dotdotdot = "..."
>         else:
>             dotdotdot = ""
>         return "" % (
>             self.__class__.__name__, data[0:10], dotdotdot)
>
> The data attribute is a unicode instance...

Who wants to be first to submit a patch? ;-)

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


Re: proxy class and __add__ method

2008-07-30 Thread Rhamphoryncus
On Jul 29, 10:23 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Tue, 29 Jul 2008 13:13:51 -0300, Magnus Schuster  
> <[EMAIL PROTECTED]> escribi :
>
>
>
> > Hello,
> > I have written the following small proxy class which I expect to pass all
> > function calls to the 'original' object:
>
> > --- BEGIN ---
> > class proxy(object):
> >     def __init__( self, subject ):
> >         self.__subject = subject
> >     def __getattr__( self, name ):
> >         return getattr( self.__subject, name )
>
> > prx_i=proxy(1)
> > print hasattr(prx_i,'__add__')
> > j=prx_i.__add__(1)
> > k=prx_i+1
> > --- END ---
>
> > Actually the "hasattr(prx_i,'__add__')" returns "True" as expected, and
> > "j=prx_i.__add__(1)" sets j=2.
>
> > But "k=prx_i+1" raises a
> > : unsupported operand type(s) for +: 'proxy'
> > and 'int'.
>
> > How is this addition different from the previous line "j=..."? And how  
> > can I
> > modify the proxy class so that all methods are passed on, which are not
> > explicitly overloaded?
>
> __magic__ methods on new style classes are searched in the class, *not* in  
> the instance. prx_i+1 looks for __add__ in type(prx_i), that is, in the  
> proxy class.

This much is true.


> Try implementing a similar __getattr__ method in a metaclass.

But I don't think they use __getattr__.. they bypass it.  Effectively
they catch the assignment to __add__ and cache it.  You'll have to
always define it in the class and have it be ineffectual in some cases.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Reasoning behind 'self' parameter in classes?

2008-07-30 Thread Brett g Porter

Robert Dailey wrote:


This is an example of a response I'm looking for:
"The self parameter is required because the parser is a bit old and 
needs to know the exact object you're referencing"


This is _not_ an example of what I'm looking for:
"Specifying self is a great mysterious thing that we should never 
question. Do not question the language! The language is mighty! Don't 
bring C++ to Python!"




Fredrik Lundh has written a  very clear explanation of this at 
http://effbot.org/pyfaq/why-must-self-be-used-explicitly-in-method-definitions-and-calls.htm


(or http://bit.ly/3EUiCf if you don't feel like stitching that URL back 
together...)


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


  1   2   >