[ANN] pyxser-0.2r --- Python XML Serialization

2009-04-19 Thread Daniel Molina Wegener
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA512

Hello,

I'm pleased to announce pyxser-0.2r, a Python-Object to XML
serializer and deserializer. This package it's completly
written in C and licensed under LGPLv3.

The tested Python versions are 2.5.X and 2.6.X.

* home page:
  http://coder.cl/software/pyxser

* hosted at:
  https://sourceforge.net/projects/pyxser/

The current ChangeLog is as follows:

0.2r (2009.04.18):

Daniel Molina Wegener d...@coder.cl
* Removed memory leaks concerning libxml2 usage.
* Removed memory leaks concerning Python C/API usage.
* Improved fault detection.
* Improved pointer checking deallocations.
* Added unit test test-utf8-prof.py with 50.000 cilces ;)
* Every serilization is made into unicode objects.

Feel free to use and test. You can modify test-utf8-prof.py
to use more than 50.000 cicles depending on your libxml2
version.

Best regards,
- -- 
 .O. | Daniel Molina Wegener   | FreeBSD  Linux
 ..O | dmw [at] coder [dot] cl | Open Standards
 OOO | http://coder.cl/| FOSS Developer

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (FreeBSD)

iQIcBAEBCgAGBQJJ6r9KAAoJEHxqfq6Y4O5NP7IQAM87ngHCTEMabwP7CgdPWjcH
thCkhdWVr+ri6L9HRZfKel8dhG1MharBWCBJjrPH+NA0aV03g0Rk2gw69DPJ3HuF
WsLx8jI0NQEGI4nYHPmP8tq+A7r2iI/3UHz9HL2rMMxpHbn/Jzcsidtf8irffLhQ
XBzyMpfhS6HaAJxmRY1SxbgFiim5egvfo0kQ+ywgmDKLs6tbaJLOpdeYBFZMLCzQ
Q6UAdQZf7yN+zqNWuL3tW+Bp4nJZP1BqCXXpiT6U69TmBtnM5SzrHjBzEUEGycDd
xDkszjRBU/k159dLbsItC50VhdfBdrcHK/FPS+4oPrdUkIH2Ue/l2/OekxFXKI7X
DlcqnYqECskzIyQeaaR0DOXeO8nq8LJVU2Sg3kXlsddTLY+f2cdp7IvQ6e1krynA
U/2KMiXYqyMe1VtxyPzp7W/yrFJa7yWrPXQtBrPnUsiYIjD08XH/C+DOdPN65nTG
NFL7Hulz4toJYz29G3CCsUgObQ2XrMG2iY361pe/lNuoW7GcFF5leiKBHInFIEit
Kz7owCGfpAN4jXtAQRYpfnqIM2M+ixgKbMLrzds5tCByeOixlfBVJveeko5csLRV
IXyQgDHJaFXU9w0oXdFSE9r2nbIE100iuYyaX8kP98HFbHnEL6cq7Cw4pA0eSn2Y
jU0mjTQJDW2ic2zyZvte
=sDDJ
-END PGP SIGNATURE-
--
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


[ANN] pyxser-0.2r --- Python XML Serialization

2009-04-19 Thread Daniel Molina Wegener
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA512

Hello,

I'm pleased to announce pyxser-0.2r, a Python-Object to XML
serializer and deserializer. This package it's completly
written in C and licensed under LGPLv3.

The tested Python versions are 2.5.X and 2.6.X.

* home page:
  http://coder.cl/software/pyxser

* hosted at:
  https://sourceforge.net/projects/pyxser/

The current ChangeLog is as follows:

0.2r (2009.04.18):

Daniel Molina Wegener d...@coder.cl
* Removed memory leaks concerning libxml2 usage.
* Removed memory leaks concerning Python C/API usage.
* Improved fault detection.
* Improved pointer checking deallocations.
* Added unit test test-utf8-prof.py with 50.000 cilces ;)
* Every serilization is made into unicode objects.

Feel free to use and test. You can modify test-utf8-prof.py
to use more than 50.000 cicles depending on your libxml2
version.

Best regards,
- -- 
 .O. | Daniel Molina Wegener   | FreeBSD  Linux
 ..O | dmw [at] coder [dot] cl | Open Standards
 OOO | http://coder.cl/| FOSS Developer

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (FreeBSD)

iQIcBAEBCgAGBQJJ6r8/AAoJEHxqfq6Y4O5Nw5EP/0HTk0Wi5Sjlo/Hk+xPmPmK5
GGNg9f/oUL2I6iPZgTwscZAY0E0AZmmdsQz4NsiBvjtwT0b9IQ5r2+O8aSn1kkdj
0Sf+v94FGyCE7yqOuxwpYgg2MyPUDxX4g4BHLyuLkWYhIqEKJdUbXxFXtzdTlzku
jETk3SSpyvQjGzoqFOycnEOfBnfJvm6invds1Je/LEylvBjznbTLXhFCylz26Bns
LubjOULZC9ONLZ5uEScss3ac1LsphXqm1yVktTlgUUs4XIG1H5udNl/+fQF4LeCx
vpF9b6eOsf+WTp8ggSumxbB/RRxCl/QGPxGr2x4QmMJjLQeL/HolzGKXg344fEs9
6c34+R0e6WC8aAeuQjYvz01Puv+q6ZydwUyTLvpEYc1eZ2JZv/zSLM/U0IdQ3mc4
5/c9pDIQAjj/sObf4QNLNQzWFV+OS7AVOQ3wlPZPovfZNg4dQbFqPsLmhm9A50oS
bDPurcPBaoS1vTf01M6gnaidHeqzn+5gkpJC7HFJYwlsFCbvNIpdTWLqw26SYFuF
WOzEKnvVxABlzMP9uao7Ve/4AmTaadCbdwdkBH3H4TxgcW22vEwgpZW5pywCH+0n
NIndKXmOURlUfiduoBkHkR9PB9EdT8JEV8hW8K3v0e0PFIjiFfc9JwNcGowlTENq
9eaiXjqOFz/j2q0OacTu
=cLLy
-END PGP SIGNATURE-
--
http://mail.python.org/mailman/listinfo/python-list


Re: send() to a generator in a for loop with continue(val)??

2009-04-19 Thread Michele Simionato
On Apr 18, 5:19 pm, a...@pythoncraft.com (Aahz) wrote:
 Okay, I'm curious, is the argument that you shouldn't use generators for
 coroutines or something else?

Yes, there is certainly the confusion between generators
and coroutines (the ones David Beazley warns about).

At first, I was a supported of yield
expressions. After they entered in Python 2.5 and I
had occasion to play with them in practice, I realized that we
did not gain much from them. In an ideal world (one
that would never happen) I would like to remove
yield expressions and keep generators simple. OTOH,
I would like a simple coroutine library in the standard
library, with a trampoline and a scheduler. Coroutines,
however, would be implemented as simple objects with
a .send and .recv method, not by abusing yield expression.
May be we would lose a tot percent of performance, but
that should not be a concern for a Pythonista.
I dunno if Peter Otten thinks the same or has other
ideas, but this is what I have in mind. The important
addition in Python 2.5 was the introduction of
GeneratorExit and the ability to use yield inside
try .. finally blocks. This was a needed language level change.
Coroutines instead could have been implemented as
a library, without requiring any language change.

But the point is moot, anyway, and certainly I did not
think of it at the time yield expressions were introduced.

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


Can some1 review my code?

2009-04-19 Thread zaheer . agadi
hi

I am from java background, I have written some code that actually
works :)
Need to some one to look at it and tell me if there are better ways of
doing same things

Will some one help?

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


Re: Can some1 review my code?

2009-04-19 Thread Jeroen Ruigrok van der Werven
-On [20090419 08:20], zaheer.ag...@gmail.com (zaheer.ag...@gmail.com) wrote:
Need to some one to look at it and tell me if there are better ways of
doing same things

Just post the snippets of code you want review of.

-- 
Jeroen Ruigrok van der Werven asmodai(-at-)in-nomine.org / asmodai
イェルーン ラウフロック ヴァン デル ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/ | GPG: 2EAC625B
Nobilitas sola est atque unica virtus...
--
http://mail.python.org/mailman/listinfo/python-list


Re: need to start a new project , can python do all that ?

2009-04-19 Thread Jeroen Ruigrok van der Werven
-On [20090415 14:25], Deep_Feelings (doctore...@gmail.com) wrote:
4- support of international languages

http://babel.edgewall.org/

-- 
Jeroen Ruigrok van der Werven asmodai(-at-)in-nomine.org / asmodai
イェルーン ラウフロック ヴァン デル ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/ | GPG: 2EAC625B
Hope is a letter that never arrives, delivered by the postman of my
fear...
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a programming language that is combination of Python and Basic?

2009-04-19 Thread Steven D'Aprano
On Sun, 19 Apr 2009 06:33:23 +0100, Tim Wintle wrote:

 On Sun, 2009-04-19 at 05:08 +, Zaphod wrote:
 Well, most of the Linux kernel is written in C and while there *is* a
 jump (often JMP) in most asms, you should only do so if you really need
 to.  JSR (jump sub routine) is a better idea in many (most?) cases.
 
 Have to say that I feel jump is more than justified in some situations
 (when it's jumping to within 10-20 lines of the start position, and it's
 a routine that needs to be highly optimised - I'm thinking tail
 recursion etc.)
 
 (btw, how come nobody has mentioned python bytecode? Most flow control
 is jumps)


I wrote yesterday:

GOTO, after all, is just a jump, and we use jumps in Python all the time:

raise Exception
break
continue
if... elif... else...
for... else...
etc.




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


Re: Can some1 review my code?

2009-04-19 Thread Steven D'Aprano
On Sat, 18 Apr 2009 23:18:32 -0700, zaheer.agadi wrote:

 hi
 
 I am from java background, I have written some code that actually works
 :)
 Need to some one to look at it and tell me if there are better ways of
 doing same things
 
 Will some one help?

Are you offering to pay or are you after free advice?

How large is your code? Ten lines, ten thousand lines, ten million lines?

What does it do?


How about if you start with a small, self-contained function (say, 20 to 
50 lines) that can be understood in isolation from the rest of your code, 
and we'll comment on that.





-- 
Steven


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


Re: [ANN] pyxser-0.2r --- Python XML Serialization

2009-04-19 Thread Stefan Behnel
Daniel Molina Wegener wrote:
 * Every serilization is made into unicode objects.

Hmm, does that mean that when I serialise, I get a unicode object back?
What about the XML declaration? How can a user create well-formed XML from
your output? Or is that not the intention?

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


Re: Can some1 review my code?

2009-04-19 Thread zaheer . agadi
On Apr 19, 11:29 am, Steven D'Aprano st...@remove-this-
cybersource.com.au wrote:
 On Sat, 18 Apr 2009 23:18:32 -0700, zaheer.agadi wrote:
  hi

  I am from java background, I have written some code that actually works
  :)
  Need to some one to look at it and tell me if there are better ways of
  doing same things

  Will some one help?

 Are you offering to pay or are you after free advice?

 How large is your code? Ten lines, ten thousand lines, ten million lines?

 What does it do?

 How about if you start with a small, self-contained function (say, 20 to
 50 lines) that can be understood in isolation from the rest of your code,
 and we'll comment on that.

 --
 Steven

Thanks guys,
I am asking free advice,The program is not very complex it is around
500 lines with most the code being reused, I am bit hesitant to post
the code publicly, is it ok if I send part of  code say a function. Or
does it makes more sense if I send the complete code to you guys
personally?
--
http://mail.python.org/mailman/listinfo/python-list


Re: send() to a generator in a for loop with continue(val)??

2009-04-19 Thread Michele Simionato
On Apr 19, 8:09 am, Michele Simionato wrote:
 Coroutines instead could have been implemented as
 a library, without requiring any syntax change.

Here is a proof of principle, just to make clearer
what I have in mind. Suppose you have the following
library:

$ cat coroutine.py
from abc import abstractmethod

class Coroutine(object):
@abstractmethod
def main(self):
yield

def send(self, value):
if not hasattr(self, '_it'): # first call
self._it = self.main()
self._value = value
return self._it.next()

def recv(self):
return self._value

def close(self):
self._it.close()
del self._it
del self._value

Then you could write coroutines as follows:

$ cat coroutine_example.py
from coroutine import Coroutine

class C(Coroutine):
def main(self):
while True:
val = self.recv()
if not isinstance(val, int):
raise TypeError('Not an integer: %r' % val)
if val % 2 == 0:
yield 'even'
else:
yield 'odd'

if __name__ == '__main__':
c = C()
for val in (1, 2, 'x', 3):
try:
out = c.send(val)
except StopIteration:
break
except Exception, e:
print e
else:
print out

This is not really worse of what we do today with the yield
expression:

$ cat coroutine_today.py
def coroutine():
val = yield
while True:
if not isinstance(val, int):
raise TypeError('Not an integer: %r' % val)
if val % 2 == 0:
val = yield 'even'
else:
val = yield 'odd'

if __name__ == '__main__':
c = coroutine()
c.next()
for val in (1, 2, 'x', 3):
try:
out = c.send(val)
except StopIteration:
break
except Exception, e:
print e
else:
print out

Actually it is clearer, since it avoids common mistakes
such as forgetting the ``val = yield`` line in the coroutine
function and the ``c.next`` line right after instantiation
of the coroutine object, which are needed to initialize
the coroutine correctly.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a programming language that is combination of Python andBasic?

2009-04-19 Thread Hendrik van Rooyen
 Steven D'Aprano steveource.com.au wrote:

COMEFROM on the other hand is just the purest evil imaginable.

*grin* - I expect you say this because it is a bit like COBOL's
alter - you cannot *see* it in place when you read the code, and 
the effect is only apparent at run time after the distant statement 
has been executed.

Kind of fun...

- Hendrik


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


Re: Is there a programming language that is combination of Python andBasic?

2009-04-19 Thread Hendrik van Rooyen
 Aaron Brady casti.@gmail.com wrote:


On Apr 18, 4:44 am, Hendrik van Rooyen m...@microcorp.co.za wrote:

 to untangle some spaghetti code. He did not mention if
 the spaghetti was actually doing it's job, bug free, which
 IMO is the only rational test for the quality of a piece

I don't use 'rational' in the same way.  Do you mean objective?  Do
readability, brevity, simplicity, purity, etc. contribute to quality?
Is program quality equivalent (or identical) to code quality?

This paragraph illustrates the problem, I think:

Is there a significant difference between rational and objective?
Define readability, brevity, simplicity, purity, etc as applied
to the quality of a programme - it leads, inevitably, to a floundering
around in a wash of words.

However, to stop playing Devil's Advocate, there is such a thing
as code quality, but it cannot be defined, just like quality in general 
terms cannot be defined - as soon as you try, it turns to dross in
your hands.  Read Robert Pfirsig's Zen and the art of motorcycle
maintenance for a full explanation of this effect.

 I do not agree with the reasoning that effectively says:
 If it is difficult to comprehend, it must be wrong

Wrong no, but impractical, possibly or probably or almost certainly,
notwithstanding the subject-dependence of ease of comprehension.
Simple code is more future-resilient than that which is difficult to
comprehend, even holding the language (version) constant.  It is a

I think that the emphasis on future proofing code is actually overrated.

We try to code as if we are building pyramids, for all time, but the sad
experience is that only a tiny percentage of application code written has
a life of longer than about eight years.

8--

that of exploration, pioneering, research, and development.  However,
even in simplest terms, some structures e.g. recursion, may be
difficult to comprehend, but that doesn't mean they would be better
more complicated.

This is true - the one does not imply the other, but the subtlety is that
it cuts either way - not more complicated, and not more simple.  One
has to strike a balance, and this is closer to an art than a science.
That said, however, throwing out the goto ( or even the more intriguing
comefrom ) is forcing the artist to paint while removing an element from
his palette - he has to work around the lack.

- Hendrik



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


Re: Is there a programming language that is combination of Python andBasic?

2009-04-19 Thread Hendrik van Rooyen
 BJörn Lindqvist b...@gmail.com wrote:

I can somewhat sympathise with the op, neither python nor any other
mainstream language can still do this:

SCREEN 13
PSET 160,100,255

Oh come on! Don't be like that!
Tell us what it does, please.

- Hendrik

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


Re: Is there a programming language that is combination of PythonandBasic?

2009-04-19 Thread Hendrik van Rooyen
 Brian Blais   wrote:

On Apr 18, 2009, at 5:44 , Hendrik van Rooyen wrote:

to untangle some spaghetti code.  He did not mention if
the spaghetti was actually doing it's job, bug free, which
IMO is the only rational test for the quality of a piece
of code, because it is the reason for its existence.  
The aesthetics are, like all aesthetics, a matter of opinion.


Actually, I strongly disagree with this statement.  
In my experience, there has been very very few 
pieces of  code that I've written that I hadn't wanted 
to *modify* at some point: extend it to a new set of 
circumstances,  cover a different case, change the 
output, etc...  The quality of a piece of code is not just 
if it works right  now, but if you can reasonably extend 
it for the future.  

Your experience is different from mine - in what I mostly
do, which is struggling around in embedded assembler,
by the time the thing works it is stable, and I very
seldom have to go back to fiddle with it. 

On the other hand, I understand what you are talking about,
but I think that the origen of the frustration that one feels
when having to battle with some old code, is actually inside
oneself - the code is the same, but I have changed, and I am 
no longer the same as I was when I wrote it.

I toyed with Perl for a year or so, but couldn't give it 
my full attention.  As a result, every few weeks when I 
wanted to modify what I wrote, I had to re-learn the 
code all over again because the syntax was so terse.
The same is true for the typical use of a goto: you have 
to relearn the program, because the flow jumps around.
It's not just about aesthetics, but about being able to 
work with a piece of code.

In my defense of the goto, I would like to make clear
that I do not support its use to produce spaghetti.
In general, muddled thinking, coupled with expediency,
is what I think are the true precursors of spaghetti code.
The goto is an innocent tool that can be used for good
or evil.

- Hendrik


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


Re: Can some1 review my code?

2009-04-19 Thread bearophileHUGS
zaheer.ag...:
 I am asking free advice,The program is not very complex it is around
 500 lines with most the code being reused,

500 lines is not a small Python program :-)
If you don't want to show it, then you can write another program, a
smaller one, for the purpose of letting people review it.

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


Re: Is there a programming language that is combination of Python andBasic?

2009-04-19 Thread Hendrik van Rooyen
Mensanator mens...@aol.com wrote:

8 -- description of bugs in spaghetti ---

Looks like that design really needed sorting out!

A programmer once said to me Why should I run it, I know
how it works, I wrote it.

Are you serious? 
In my opinion, anybody who says this is not a programmer,
but merely an arrogant idiot with a lot of misplaced self-
confidence - somewhat like a permanent force corporal.


My reply: You only THINK you know how it works. _I_, on
the other hand, ACTUALLY know how it works because I've
run it.

How did you manage to keep your reply so meek?
You must be a really well brought up person.
:-)

- Hendrik


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


Re: Can some1 review my code?

2009-04-19 Thread liangguanhui
On 4月19日, 下午2时18分, zaheer.ag...@gmail.com wrote:
 hi

 I am from java background, I have written some code that actually
 works :)
 Need to some one to look at it and tell me if there are better ways of
 doing same things

 Will some one help?

 Thanks

Post first, then someone will review, I think.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Useful MySQL Routines

2009-04-19 Thread Tino Wildenhain

Lawrence D'Oliveiro wrote:
I've done a writeup on some of the basic routines I frequently use here 
http://codecodex.com/wiki/index.php?title=Useful_MySQL_Routines.


Why is that specific to mysql?

Btw, the bulkinserter could be better done by using executemany
and select usefull batch sizes. If you allow query construnction
better don't forget appropriate quoting of table- and column names
too to be on the safe side.

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


Re: send() to a generator in a for loop with continue(val)??

2009-04-19 Thread Peter Otten
Aahz wrote:

 In article
 07ad771b-a6d1-4f08-b16c-07caf7462...@e18g2000yqo.googlegroups.com,
 Michele Simionato  michele.simion...@gmail.com wrote:
On Apr 18, 3:03=A0pm, a...@pythoncraft.com (Aahz) wrote:
 In article gsc7e1$rj6$0...@news.t-online.com,
 Peter Otten =A0__pete...@web.de wrote:

If it were up to me I'd rip out send() immediatly. At first I thought I
would see a compelling use case and be enlightened, but it never
happened.

 Too late -- it's likely to get an upgrade for 3.1 and 2.7. Basically,

Could you give some details or a link?

 send() is useful for coroutines, and if you haven't yet read
http://dabeaz.com/coroutines/
 you really should (assuming you want to continue arguing).

I only just started reading Beazley's presentation, it looks interesting.
Thanks for the hint!

Are you currently using coroutines in Python? If so, what kind of practical
problems do they simplify for you?

I suspect Peter knows everything about coroutines and still he is not
convinced about .send. FWIW, I am sympathic with him.
 
 Okay, I'm curious, is the argument that you shouldn't use generators for
 coroutines or something else?

I don't know nearly as much about coroutines as Michele thinks; in
particular I have no practical experience with them. 

What I've seen so far is that the once beautifully simple generator
mechanism has become very complex with the recent additions for ressource
management and coroutines.

Generators as filters and synthetic sequences are now ubiquitous, the with
statement is spreading like wildfire.

The send()/yield-expression duo on the other hand is limping along, and
someone like Michele who is definitely in the intended audience for the
more arcane features of Python says that you can do it with a library.
If that is possible shouldn't it have been the first step to put such a
library into the stdlib and see how it fares?

Generators at the moment seem to have turned into what in German we call
an eierlegende Wollmilchsau*.

Peter

(*)
http://www.pollux.franken.de/fileadmin/user_upload/images/eier-legende-wollmilchsau.jpg
--
http://mail.python.org/mailman/listinfo/python-list


Re: Useful MySQL Routines

2009-04-19 Thread Lawrence D'Oliveiro
In message mailman.4148.1240135989.11746.python-l...@python.org, Tino 
Wildenhain wrote:

 Lawrence D'Oliveiro wrote:
 I've done a writeup on some of the basic routines I frequently use here
 http://codecodex.com/wiki/index.php?title=Useful_MySQL_Routines.
 
 Why is that specific to mysql?

Because that's all I've used so far. Though sqlite looks interesting for 
single-user stuff...

 Btw, the bulkinserter could be better done by using executemany
 and select usefull batch sizes.

Hmm, I've never bothered with executemany. The code as written copes 
comfortably with 10,000 records or so.

 If you allow query construnction
 better don't forget appropriate quoting of table- and column names
 too to be on the safe side.

Hmm, I never worried about that, because I was I tried to be careful in the 
names I chose. And I've never allowed object names to come from user input 
:).

Besides, how do you deal with characters that are still illegal when quoted 
http://dev.mysql.com/doc/refman/5.0/en/identifiers.html?

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


can python access OS level features like bash scripting?

2009-04-19 Thread Krishnakant
Hello all,
Right now I am a bit confused on a final stage of my project.

I need to create an installer and an executable file for my python
program for gnu/linux.

The install script has to put the package into site-packages folder
where all other libraries reside.  Then put the executable file
into /usr/bin as other files.

The installer must also do the basic task of creating the database and
setting up password for on postgresql.
now here comes the main problem.
I believe putting files into proper places is pritty easy (may be some
one will instantly reply to the issue of putting the executable file and
libraries in place ).  But to do the database based activities, I need
python-psycopg2 module for postgresql in the first place.  So is it
possible for python to self download and install all the necessary
modules on to the client machine?

What further complicates the system is the fact that I want in future to
create 2 deb files, one for installing the gtk based client application
and the other to install the server side app made in python-twisted for
rpc.  Now the obvious problem is that first my python installation
(either 2.5 or 2.4) must check for itself if the modules are present or
not and if they are not present, my install utility must either download
it from net or if that's not the recommended approach then compile the
module from the source.

how do I achieve all this in python?
I know bash could be used to do such things but I don't want to use bash
because it is to clunky and won't run easily on windows.
Moreover I want to create a deb file as I said before so I want to keep
it as simple as possible.

Even regarding the executable, I am confused on using bash as the script
for writing the executable which can then do some thing like python -c
and call the modules, or write this executable code in a main.py and put
that file into the executable path i.e /usr/bin.

Please clear this mater so that I can go ahead.

I know the python list is pritty busy and I must thank all the members
who keep the spirit of the community and the professional organisations
alive so may be I will get a solution to my problem soon.

happy hacking.
Krishnakant.


  







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


Re: Can some1 review my code?

2009-04-19 Thread Martin P. Hellwig

zaheer.ag...@gmail.com wrote:

hi

I am from java background, I have written some code that actually
works :)
Need to some one to look at it and tell me if there are better ways of
doing same things

Will some one help?

Thanks


My crystal ball is a bit cloudy today so forgive me if my suggestions 
may seem off-topic in your request.


I find that reviewing code that hasn't conform to 'standards' distracts 
me from the original intent. Parsing your code through a lint like 
PyLint will suggest 'standard' way of doing things (aim for 10/10) it 
will make things easier to read.


Also code that is unnecessary bloated (e.g. conditions that are never 
executed) can confuse the issue even more so. A good way would be to 
write unit-test against your code out of the perspective of the intended 
use (so not just to execute stuff because it is there) then run it 
through a coverage program. This will display nicely what code is 
executed and what not. The not part is what you look for in this 
perspective since if all the unit-test have what you need, why should 
the uncalled code be included?


Next stop comments, I am all for comments except if you need them to 
translate what the piece of code is doing there, if you can refactor 
your code so it looks more English and is understandable without 
comments (which should be still in there though) then do so.


For example:
range_8 = range(8)
for number in range_8:
# Loop through 0 to 7 and print it.
print(number)

instead of:
r = range(8)
for i in r:
# print i in range(8) loop
print(i)

* note this is a bad code example, only to clarify what I mean in general

Then look at your code from a functional perspective, if there are 
multiple functions that act in a similar way can you replace them with a 
single function? Then do so.


Is there functionality that looks so common that you think it should be 
in the standard library? It probably is then, make use of it.


Performance; run your code through a execution analyser like profile, do 
the numbers make sense? If not try to figure out why and replace the 
affected algorithm with one that makes more sense.


Finally memory;  Can you scrap duplicate entries of essential the same 
data, without affecting all the above? Might be a good idea to do so.


When done all this you might feel it is not necessary to review the code 
any more, which is then is a good moment to actually request a review :-)


I'll be happy to have a look at it though you might consider posting it 
here, more chance of useful feedback ;-)


--
MPH
http://blog.dcuktec.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a programming language that is combination of PythonandBasic?

2009-04-19 Thread Brian Blais

On Apr 19, 2009, at 4:35 , Hendrik van Rooyen wrote:


 Brian Blais   wrote:


On Apr 18, 2009, at 5:44 , Hendrik van Rooyen wrote:



to untangle some spaghetti code.  He did not mention if
the spaghetti was actually doing it's job, bug free, which
IMO is the only rational test for the quality of a piece
of code, because it is the reason for its existence.
The aesthetics are, like all aesthetics, a matter of opinion.



Actually, I strongly disagree with this statement.
In my experience, there has been very very few
pieces of  code that I've written that I hadn't wanted
to *modify* at some point: extend it to a new set of
circumstances,  cover a different case, change the
output, etc...  The quality of a piece of code is not just
if it works right  now, but if you can reasonably extend
it for the future.


Your experience is different from mine - in what I mostly
do, which is struggling around in embedded assembler,
by the time the thing works it is stable, and I very
seldom have to go back to fiddle with it.

On the other hand, I understand what you are talking about,
but I think that the origen of the frustration that one feels
when having to battle with some old code, is actually inside
oneself - the code is the same, but I have changed, and I am
no longer the same as I was when I wrote it.


You're right about the person changing, not the code...for me it's  
mostly forgetting.  :)  I have found that python lets me re-learn my  
old code much faster (usually there is no re-learning necessary -  
just re-reading) then Perl, C, and Matlab.


As for fiddling with code, most of the code I write for work is for  
exploring ideas in theoretical neuroscience.  Once you have something  
that works, and you understand the problem, the next things out of  
your mouth is I wonder what happens if this is changed?.  Change is  
the norm




In my defense of the goto, I would like to make clear
that I do not support its use to produce spaghetti.
In general, muddled thinking, coupled with expediency,
is what I think are the true precursors of spaghetti code.
The goto is an innocent tool that can be used for good
or evil.



as is true of any tool, but I think that the goto is a little too  
convenient for the sloppy thinker, and shouldn't be lying around to  
be picked up by just anyone.  :)



bb


--
Brian Blais
bbl...@bryant.edu
http://web.bryant.edu/~bblais



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


Re: pyqt4 qTableWidget add items help

2009-04-19 Thread Sebastian Wiesner
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

ookrin – Samstag, 18. April 2009 20:16
 from PyQt4 import  ?? QtGui? QtCore? Those are already loaded   other
 options are pyqtconfig and uic and those don't sound correct...

from PyQt4 import QtGui
QtGui.QTableWidgetItem

See [1] for an example.

[1] 
http://hg.lunaryorn.de/snippets/file/3272fdd93736/qt4_table_header_alignment.py

- -- 
Freedom is always the freedom of dissenters.
  (Rosa Luxemburg)
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.11 (GNU/Linux)

iEYEARECAAYFAknrGyYACgkQGV4vxEMMOxceGQCgky6GtUAOlyKxLLYCBWGYhwez
2zoAmgN9OecHib4imoxyn/FsLGaEIDw6
=EIsK
-END PGP SIGNATURE-

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


Re: Is there a programming language that is combination of Python and Basic?

2009-04-19 Thread Tim Wintle
On Sun, 2009-04-19 at 06:26 +, Steven D'Aprano wrote:
  (btw, how come nobody has mentioned python bytecode? Most flow
 control is jumps)
 
 
 I wrote yesterday:
 
 GOTO, after all, is just a jump, and we use jumps in Python all the
 time:
 
 raise Exception
 break
 continue
 if... elif... else...
 for... else...
 etc.

Ah - apologies 

Tim

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


Re: can python access OS level features like bash scripting?

2009-04-19 Thread News123
Hi,

I think you got lost in the wrong thread.
Though your subject line is correct your post threads under Is there a
programming language, that . . . 

Perhaps you 'replied' to above thread and changed 'just' the subject line.

Chances to get an answer might be higher if you repost your question
without replying to an existing thread.



Krishnakant wrote:
 Hello all,
 Right now I am a bit confused on a final stage of my project.
 
 I need to create an installer and an executable file for my python
 program for gnu/linux.
 
 The install script has to put the package into site-packages folder
 where all other libraries reside.  Then put the executable file
 into /usr/bin as other files.
 
 The installer must also do the basic task of creating the database and
 setting up password for on postgresql.
 now here comes the main problem.
 I believe putting files into proper places is pritty easy (may be some
 one will instantly reply to the issue of putting the executable file and
 libraries in place ).  But to do the database based activities, I need
 python-psycopg2 module for postgresql in the first place.  So is it
 possible for python to self download and install all the necessary
 modules on to the client machine?
 
 What further complicates the system is the fact that I want in future to
 create 2 deb files, one for installing the gtk based client application
 and the other to install the server side app made in python-twisted for
 rpc.  Now the obvious problem is that first my python installation
 (either 2.5 or 2.4) must check for itself if the modules are present or
 not and if they are not present, my install utility must either download
 it from net or if that's not the recommended approach then compile the
 module from the source.
 
 how do I achieve all this in python?
 I know bash could be used to do such things but I don't want to use bash
 because it is to clunky and won't run easily on windows.
 Moreover I want to create a deb file as I said before so I want to keep
 it as simple as possible.
 
 Even regarding the executable, I am confused on using bash as the script
 for writing the executable which can then do some thing like python -c
 and call the modules, or write this executable code in a main.py and put
 that file into the executable path i.e /usr/bin.
 
 Please clear this mater so that I can go ahead.
 
 I know the python list is pritty busy and I must thank all the members
 who keep the spirit of the community and the professional organisations
 alive so may be I will get a solution to my problem soon.
 
 happy hacking.
 Krishnakant.
 
 
   
 
 
 
 
 
 
 
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a programming language that is combination of Python and Basic?

2009-04-19 Thread D'Arcy J.M. Cain
On Sun, 19 Apr 2009 05:08:32 GMT
Zaphod zap...@beeblebrox.net wrote:
 Friend of mine made a really nice asm development environment for his 
 home made OS.  Too bad he didn't have any marketing skills.

Was your friend's name Gary Kildall? :-)

-- 
D'Arcy J.M. Cain da...@druid.net |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
--
http://mail.python.org/mailman/listinfo/python-list


Re: send() to a generator in a for loop with continue(val)??

2009-04-19 Thread Aahz
In article gsetb1$jop$0...@news.t-online.com,
Peter Otten  __pete...@web.de wrote:
Aahz wrote:
 In article
 07ad771b-a6d1-4f08-b16c-07caf7462...@e18g2000yqo.googlegroups.com,
 Michele Simionato  michele.simion...@gmail.com wrote:
On Apr 18, 3:03=A0pm, a...@pythoncraft.com (Aahz) wrote:
 In article gsc7e1$rj6$0...@news.t-online.com,
 Peter Otten =A0__pete...@web.de wrote:

If it were up to me I'd rip out send() immediatly. At first I thought I
would see a compelling use case and be enlightened, but it never
happened.

 Too late -- it's likely to get an upgrade for 3.1 and 2.7.

Could you give some details or a link?

http://mail.python.org/pipermail/python-ideas/2009-April/004189.html

(You'll need to backtrack considerably to see the full discussion.)

Are you currently using coroutines in Python? If so, what kind of practical
problems do they simplify for you?

I'm not; I avoid coroutines like the plague.  ;-)  I much prefer nice,
simple threading...

What I've seen so far is that the once beautifully simple generator
mechanism has become very complex with the recent additions for ressource
management and coroutines.

The send()/yield-expression duo on the other hand is limping along, and
someone like Michele who is definitely in the intended audience for the
more arcane features of Python says that you can do it with a library.
If that is possible shouldn't it have been the first step to put such a
library into the stdlib and see how it fares?

You have a point; I wasn't paying much attention when send() was first
added, so I can't argue for it.  I'm just referring you to material I
happen to have handy that discusses use for it.
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

If you think it's expensive to hire a professional to do the job, wait
until you hire an amateur.  --Red Adair
--
http://mail.python.org/mailman/listinfo/python-list


Re: send() to a generator in a for loop with continue(val)??

2009-04-19 Thread Aahz
In article gsetb1$jop$0...@news.t-online.com,
Peter Otten  __pete...@web.de wrote:

Generators at the moment seem to have turned into what in German we call
an eierlegende Wollmilchsau*.

One more point: there has always been a tension within the Python
community between people pushing the bleeding edge and people who prefer
to keep things simple.  Unfortunately, the former group tends to be much
more active.  :-(  There really needs to be a solid core of people who
are fundamentally conservative.  I like to think that I'm one of them
(and probably so do many other people in the python-dev community), but
each of us has our own hobby horses that we like to push, and none of us
keeps completely on top of everything.
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

If you think it's expensive to hire a professional to do the job, wait
until you hire an amateur.  --Red Adair
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a programming language that is combination of Python and Basic?

2009-04-19 Thread Tim Hoffman
I started my commercial programming in Business Basic, (actually MAI
Basic 4, and it's equivalent on primos (can't think of it's name at
the moment) then later BBX (Basis)

We ran the same code (all development on MAI, and then translated the
few differences programatically between MAI and Prime) and moved the
code via 1/4 tape to prime.

This was general ledger, policy and claims systems for an Insurance
Broker, we had about 300 + users on the two machines running over a
wide area serial network)

Then we moved to BBX on Unix.

Whilst we had goto, no such thing as string arrays (until BBX) etc
we really formally codified all of our devlopment standards, such that
even line number ranges where for specific tasks  (we had a limit of
64K per program, 1 -  for line numbers) and all initialisation had
to be in lines 1000 - 1099.   We where only allowed to use goto within
a routine and only as a last resort,. We could only have one return
from a gosub, etc. on mai we could only have two letter or letter
and digit variable names and they where global for the probram
so if you wanted loop local, or subroutine variables you could safely
use then x[1-9]  and y[1-9]
where safe, all initialisation setup use i[1-9] etc 

There where 3 programmers and we had to peer review everything.

We built rock solid systems, if I say so myself ;-)

You can write well structured and easily understood code in any
language, it just takes more discipline in some environments more than
others.

Having said that I would hate to go back to it from Python ;-)

See ya

T



On Apr 18, 4:52 am, a...@pythoncraft.com (Aahz) wrote:
 In article 
 f222fcd3-56a4-4b2f-9bf8-3c9c17664...@e18g2000yqo.googlegroups.com,

 baykus  baykusde...@gmail.com wrote:

 I am looking for one of those experimental languages that might be
 combination of python+basic. Now thta sounds weird and awkward I know.
 The reason I am asking is that I always liked how I could reference-
 call certain line number back in the days. It would be interesting to
 get similar functionality in Python.

 Why do you want to do that?  Before you answer, make sure to read this:

 http://www.u.arizona.edu/~rubinson/copyright_violations/Go_To_Conside...
 --
 Aahz (a...@pythoncraft.com)           *        http://www.pythoncraft.com/

 If you think it's expensive to hire a professional to do the job, wait
 until you hire an amateur.  --Red Adair

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


Re: can python access OS level features like bash scripting?

2009-04-19 Thread Krishnakant

sorry, but I was not replying to another thread.

My mistake.

happy hacking.
Krishnakant.



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


Re: Can some1 review my code?

2009-04-19 Thread zaheer . agadi

 When done all this you might feel it is not necessary to review the code
 any more, which is then is a good moment to actually request a review :-)


 I'll be happy to have a look at it though you might consider posting it
 here, more chance of useful feedback ;-)

Great, Thanks a lot I will make sure that I complete what ever you
have listed here and then
request for a review. Well I understand that refusing to post the code
here in the mailing list might
annoy people and posting code here will only help it making it more
robust and clean. I am just being cautious that I don't break any of
the laws at my workplace.


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


Re: wxPython 2.8 for Python 2.6 on Linux

2009-04-19 Thread David Robinow
On Sun, Apr 19, 2009 at 1:58 AM, Kenny x xarv...@gmail.com wrote:
 Hello, I use Ubuntu 8.10 and the latest version of Python.

 I started programming wxPython on my Windows computer,

 but now I have access to my ubuntu box, and want wxPython for 2.6

 All the debs in the package manager are for 2.5, not 2.6

 How can I Install wxPython for Python 2.6 without building from the source?

 Any help appreciated, I need this solved! :)

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


I don't know. Why don't you ask Ubuntu?
How come you don't want to build from source?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Condition.wait(0.5) doesn't respect it's timeout

2009-04-19 Thread Piet van Oostrum
 stephane.bisin...@gmail.com (sb) wrote:

sb I'll also file a bug report because I am more and more convinced this
sb is a bug, if anything else at least in the documentation...

I looked at it more closely, and I found that the Condition.wait is
stuck on obtaining the GIL while the main thread executes the gobject
main loop. Therefore it also blocks on notifications, not only on the
timeout. 

It appears that GTK and Python threads are incompatible UNLESS you call
gtk.gdk.threads_init() before gtk.main(). In your case you can do it
after the import gtk in contact_list.py. Then it should work.

By the way, I wonder why you need a timeout in your wait. I think the
notifications should be sufficient to keep the gui updated.
-- 
Piet van Oostrum p...@cs.uu.nl
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a programming language that is combination of Python andBasic?

2009-04-19 Thread Aaron Brady
On Apr 19, 3:05 am, Hendrik van Rooyen m...@microcorp.co.za wrote:
  Aaron Brady casti.@gmail.com wrote:

 On Apr 18, 4:44 am, Hendrik van Rooyen m...@microcorp.co.za wrote:

  to untangle some spaghetti code. He did not mention if
  the spaghetti was actually doing it's job, bug free, which
  IMO is the only rational test for the quality of a piece

 I don't use 'rational' in the same way.  Do you mean objective?  Do
 readability, brevity, simplicity, purity, etc. contribute to quality?
 Is program quality equivalent (or identical) to code quality?

 This paragraph illustrates the problem, I think:

 Is there a significant difference between rational and objective?
 Define readability, brevity, simplicity, purity, etc as applied
 to the quality of a programme - it leads, inevitably, to a floundering
 around in a wash of words.

It is an old philosopher's problem, that is, a problem of old
philosophers: do all rational wo/men behave the same given the same
situations, or more specifically, analogously given related
situations?

Rational and objective are related, I think.  An objective test of
code would be a process anyone can follow and derive the same result,
such as how many identifiers it contains.  A rational test involves
some sort of abstraction of humans, such as what the ultimately
rational human likes most, etc.  Objective partial credit on an exam,
for example, must come from a black-and-white rubric with exactly no
room for interpretation.  Rational partial credit could involve
inferences, guesses, and context, esp. acquaintance with the taker.

I agree that many of those traits are matters of degree and multi-
dimensional.  I am looking for an objective metric of code: code X has
traits P, Q, and R.  Period.  It would probably be simpler to start
describing code objectively, rather than trying to square-peg-round-
hole existing words.  However, there may be no objective test of
especially large sizes of code, and may fall to some sort of
interpretation or assessment of the most rational wo/man.

If I disagree with your measuring of a code with objective criteria,
we merely walk through the measurement, and resolve our disagreement
from the criteria upon discovering it.  If I disagree with your
measuring of it with rational criteria, we have to take into account
all sorts of trade-offs, such as long-short term, one-many readers,
different consequences, etc.  I'm speculating a little bit in defining
those words.

I advance that two equifunctional programs (same input- same output)
can be compared w.r.t. brevity, to take an example, up to isomorphism
of identifier names, control structures, and statement order.  That
is, we can determine how brief code X is, disregarding identifier
names, and statement order where irrelevant.  Control structure
brevity might be something we're trying to measure:

while 1:
  if cond(): break

while not cond():
  ...

Are these equally brief, assuming they accomplish the same thing?  If
we don't have unanimous agreement on the answer to that question, we
must conclude that even brevity is a composite trait and we'll have to
start simpler.  A theory of traits would have to make concrete
predictions about *something*.  If some code has trait P, it will Q.

 However, to stop playing Devil's Advocate, there is such a thing
 as code quality, but it cannot be defined, just like quality in general
 terms cannot be defined - as soon as you try, it turns to dross in
 your hands.  Read Robert Pfirsig's Zen and the art of motorcycle
 maintenance for a full explanation of this effect.

Are you saying that quality reduces to how pleasant a particular
reader, or composite of multiple readers, finds the code?

In the 1960s, programmers gave goto statements an average rating of 6
out of 10, 10 being most pleasing.  In the 70s, that rating dropped to
5 out of 10.  Subroutines were initially disliked, but came to be
favored, advancing from 4/10 in the 60s to 7/10 in the 80s and on.
Possible confounding variables include the increase in processor speed
and thus the increased forgivingness of running time of gosubs; the
prevalence of languages capable of generating subroutine calls; and
the efficiency of the particular calls generated, surveys of which
were not attempted.  --Fabrication

  I do not agree with the reasoning that effectively says:
  If it is difficult to comprehend, it must be wrong

 Wrong no, but impractical, possibly or probably or almost certainly,
 notwithstanding the subject-dependence of ease of comprehension.
 Simple code is more future-resilient than that which is difficult to
 comprehend, even holding the language (version) constant.  It is a

 I think that the emphasis on future proofing code is actually overrated.

 We try to code as if we are building pyramids, for all time, but the sad
 experience is that only a tiny percentage of application code written has
 a life of longer than about eight years.

Project managers should, I judge, be versed in 

Re: Passing all extra commandline arguments to python program, Optparse raises exception

2009-04-19 Thread David Stanek
On Thu, Apr 16, 2009 at 10:05 AM, sapsi saptarshi.g...@gmail.com wrote:
 Hello,
 Im using optparse and python 2.6 to parse some options, my commandline
 looks like

 prog [options] start|stop extra-args-i-will-pas-on

 The options are --b --c --d

 The extra options are varied are are passed onto another program e.g --
 quiet --no-command , my program doesnt care what these are but instead
 passes them onto another program.

 I know these will always follow start|stop.

 However optparse tries to process them and throws an exception - how
 can i prevent this without placing all the extra-args in quotes.



In Linux (maybe in Windows) you can tell an application to stop
processing args by using '--'. Given this code:
import sys
from optparse import OptionParser
op = OptionParser()
op.add_option('--a', dest='a', action='store_true', default=False)
op.add_option('--b', dest='b', action='store_true', default=False)
opts, args = op.parse_args(sys.argv)
print 'opts:', opts
print 'args:', args

Here is an example use:
eee0:~% python junk.py --a -- --c
{'a': True, 'b': False}
['junk.py', '--c']


-- 
David
blog: http://www.traceback.org
twitter: http://twitter.com/dstanek
--
http://mail.python.org/mailman/listinfo/python-list


Re: can python access OS level features like bash scripting?

2009-04-19 Thread Krishnakant
hi very sorry for that 

On Sun, 2009-04-19 at 14:50 +0200, News123 wrote:
 Hi,
 
 I think you got lost in the wrong thread.
 Though your subject line is correct your post threads under Is there a
 programming language, that . . . 
 
 Perhaps you 'replied' to above thread and changed 'just' the subject line.
 
 Chances to get an answer might be higher if you repost your question
 without replying to an existing thread.
 I did not mean to do so, may be just missed out on removing the lines of the 
 previous thread.

sorry again.
I hope this becomes a new thread now and I get some productive reply.
happy hacking.
Krishnakant.




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


Re: Condition.wait(0.5) doesn't respect it's timeout

2009-04-19 Thread stephane . bisinger
On Apr 18, 8:29 pm, Piet van Oostrum p...@cs.uu.nl wrote:
 2. Importing in a thread is discouraged. I think it is cleaner to put
    the import sys in the top of the module.

Yes I know I shouldn't import inside of threads, but that is something
that is going away, it's just for debugging this issue.

On Apr 19, 2:31 pm, Piet van Oostrum p...@cs.uu.nl wrote:
 I looked at it more closely, and I found that the Condition.wait is
 stuck on obtaining the GIL while the main thread executes the gobject
 main loop. Therefore it also blocks on notifications, not only on the
 timeout.

Ah-ha! My suspicions were right, then, I remembered something about
gobject being incompatible with python threads... but I couldn't find
anything in the docs, not even those of gobject, so I assumed my
memory was failing me...

 It appears that GTK and Python threads are incompatible UNLESS you call
 gtk.gdk.threads_init() before gtk.main(). In your case you can do it
 after the import gtk in contact_list.py. Then it should work.

I'll try to do that

 By the way, I wonder why you need a timeout in your wait. I think the
 notifications should be sufficient to keep the gui updated.

The reason is simple: when first downloading the contactss list,  I
receive a swarm of *Updated() calls, so if I redraw every time I get a
very bad visual effect and I waste a lot of CPU redrawing something
that will change in a very very short time. Hence the time
constraint... I couldn't come up with something smarter, so...

Anyway I wanted to really thank you for your time and your precious
advice, I really appreciate it!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Condition.wait(0.5) doesn't respect it's timeout

2009-04-19 Thread stephane . bisinger
On Apr 19, 2:31 pm, Piet van Oostrum p...@cs.uu.nl wrote:
 It appears that GTK and Python threads are incompatible UNLESS you call
 gtk.gdk.threads_init() before gtk.main(). In your case you can do it
 after the import gtk in contact_list.py. Then it should work.

Ok here's the deal: I'm not ending up in the gtk frontend. My code is
for the ncurses frontend, so there is no import gtk and gtk.main()
that gets executed in that case. But it is definitely around the
gobject thing, I'll try to search for this!
--
http://mail.python.org/mailman/listinfo/python-list


wxPython 2.8 for Python 2.6

2009-04-19 Thread Kenny x
I hate building from the source.

Especially when wxPython has all these flags and I don't know what they
mean.

Is there any way?

I hate building from the source, and want to use Python 2.6 with wxPython
2.8
--
http://mail.python.org/mailman/listinfo/python-list


Re: Condition.wait(0.5) doesn't respect it's timeout

2009-04-19 Thread stephane . bisinger
On Apr 19, 3:14 pm, stephane.bisin...@gmail.com wrote:
 Ok here's the deal: I'm not ending up in the gtk frontend. My code is
 for the ncurses frontend, so there is no import gtk and gtk.main()
 that gets executed in that case. But it is definitely around the
 gobject thing, I'll try to search for this!

gobject.threads_init() is what was missing, now everything works as
expected! Thanks!
--
http://mail.python.org/mailman/listinfo/python-list


imaplib and smtplib

2009-04-19 Thread Vistro
I want to download a message from my Gmail inbox with imaplib, then forward
(basically resend it) with smtplib. I can log in with both. I just need to
know how to download a message with imaplib, and what needs to be converted
into what to be able to send it with smtplib.

For a good time, go to Start:Run and type in format Chttp://www.vistro.net/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Useful MySQL Routines

2009-04-19 Thread Tino Wildenhain

Lawrence D'Oliveiro wrote:
In message mailman.4148.1240135989.11746.python-l...@python.org, Tino 
Wildenhain wrote:



Lawrence D'Oliveiro wrote:

I've done a writeup on some of the basic routines I frequently use here
http://codecodex.com/wiki/index.php?title=Useful_MySQL_Routines.

Why is that specific to mysql?


Because that's all I've used so far. Though sqlite looks interesting for 
single-user stuff...


There are other more powerfull free alternatives to MySQL as well :)


Btw, the bulkinserter could be better done by using executemany
and select usefull batch sizes.


Hmm, I've never bothered with executemany. The code as written copes 
comfortably with 10,000 records or so.


Would be interesting to see the difference. However executemany
would be much more portable - and as I see it transfers at least
a bit less data over the wire.


If you allow query construnction
better don't forget appropriate quoting of table- and column names
too to be on the safe side.


Hmm, I never worried about that, because I was I tried to be careful in the 
names I chose. And I've never allowed object names to come from user input 
:).


Not you, but if others use it, it might be that they don't see a problem
and then - oops :)


Besides, how do you deal with characters that are still illegal when quoted 
http://dev.mysql.com/doc/refman/5.0/en/identifiers.html?


Don't know. I personally avoid dealing with mysql altogether (I mean, 
commands hidden in sql comments? Heaven! :)


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


Re: can python access OS level features like bash scripting?

2009-04-19 Thread Chris Jones
On Sun, Apr 19, 2009 at 09:55:08AM EDT, Krishnakant wrote:
 hi very sorry for that 
 
 On Sun, 2009-04-19 at 14:50 +0200, News123 wrote:
  Hi,
  
  I think you got lost in the wrong thread.
  Though your subject line is correct your post threads under Is there a
  programming language, that . . . 
  
  Perhaps you 'replied' to above thread and changed 'just' the subject line.
  
  Chances to get an answer might be higher if you repost your question
  without replying to an existing thread.
  I did not mean to do so, may be just missed out on removing the lines of 
  the previous thread.
 
 sorry again.
 I hope this becomes a new thread now and I get some productive reply.
 happy hacking.
 Krishnakant.

No big deal, mature mailers such as mutt let you break threads into
subthreads via a painless Alt-B.

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


Re: Is there a programming language that is combination of Python andBasic?

2009-04-19 Thread Scott David Daniels

Hendrik van Rooyen wrote:

Mensanator mens...@aol.com wrote:

8 -- description of bugs in spaghetti ---

Looks like that design really needed sorting out!


A programmer once said to me Why should I run it, I know
how it works, I wrote it.


Are you serious? 
In my opinion, anybody who says this is not a programmer,

but merely an arrogant idiot with a lot of misplaced self-
confidence - somewhat like a permanent force corporal.


My reply: You only THINK you know how it works. _I_, on
the other hand, ACTUALLY know how it works because I've
run it.


How did you manage to keep your reply so meek?
You must be a really well brought up person.
:-)


Possibly because the proper reply was probably, You only THINK
you know how it works. _I_, on the other hand, know how it behaves,
even if I don't know how it was supposed to work.

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


Re: Is there a programming language that is combination of PythonandBasic?

2009-04-19 Thread Scott David Daniels

Hendrik van Rooyen wrote:

In my defense of the goto, I would like to make clear
that I do not support its use to produce spaghetti.
In general, muddled thinking, coupled with expediency,
is what I think are the true precursors of spaghetti code.
The goto is an innocent tool that can be used for good
or evil.


The goto is a sharp, spiky dangerous tool that seduces
people into thinking of using it far too often.  It should
be used with the same respect you approach beautiful well-
armed people of questionable morals who you find attractive.

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


Re: Condition.wait(0.5) doesn't respect it's timeout

2009-04-19 Thread Aahz
In article 6c04c7da-6b54-4a49-803f-aac3126e3...@f19g2000yqh.googlegroups.com,
 stephane.bisin...@gmail.com wrote:
On Apr 18, 8:29=A0pm, Piet van Oostrum p...@cs.uu.nl wrote:
 
 By the way, I wonder why you need a timeout in your wait. I think the
 notifications should be sufficient to keep the gui updated.

The reason is simple: when first downloading the contactss list,  I
receive a swarm of *Updated() calls, so if I redraw every time I get a
very bad visual effect and I waste a lot of CPU redrawing something
that will change in a very very short time. Hence the time
constraint... I couldn't come up with something smarter, so...

The redraw thread should keep track of the last time it did a redraw;
each time it receives an update event, it should check to see whether it
has been more than a specified period of time since the last redraw.
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

If you think it's expensive to hire a professional to do the job, wait
until you hire an amateur.  --Red Adair
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a programming language that is combination of PythonandBasic?

2009-04-19 Thread Chris Jones
On Sun, Apr 19, 2009 at 04:35:27AM EDT, Hendrik van Rooyen wrote:
  Brian Blais   wrote:
 
 On Apr 18, 2009, at 5:44 , Hendrik van Rooyen wrote:

 to untangle some spaghetti code.  He did not mention if the
 spaghetti was actually doing it's job, bug free, which IMO is the
 only rational test for the quality of a piece of code, because it is
 the reason for its existence.  The aesthetics are, like all
 aesthetics, a matter of opinion.

 Actually, I strongly disagree with this statement.  In my experience,
 there has been very very few pieces of  code that I've written that I
 hadn't wanted to *modify* at some point: extend it to a new set of
 circumstances,  cover a different case, change the output, etc...
 The quality of a piece of code is not just if it works right  now,
 but if you can reasonably extend it for the future.  

+1 .. obfuscated code never remains bug-free for long.

 Your experience is different from mine - in what I mostly do, which is
 struggling around in embedded assembler, by the time the thing works
 it is stable, and I very seldom have to go back to fiddle with it. 

Intellectually, assembler programming is the less demanding since its
level of abstraction does not go any further than mapping a few binary
numbers to a small set of usually well-chosen mnemonics. 

Unless it features a powerful macro-language that lets the apprentice
create his own high-level patois on top of the assembler, that is.

 On the other hand, I understand what you are talking about, but I
 think that the origen of the frustration that one feels when having to
 battle with some old code, is actually inside oneself - the code is
 the same, but I have changed, and I am no longer the same as I was
 when I wrote it.

 I toyed with Perl for a year or so, but couldn't give it my full
 attention.  As a result, every few weeks when I wanted to modify what
 I wrote, I had to re-learn the code all over again because the syntax
 was so terse.  The same is true for the typical use of a goto: you
 have to relearn the program, because the flow jumps around.  It's not
 just about aesthetics, but about being able to work with a piece of
 code.

 In my defense of the goto, I would like to make clear that I do not
 support its use to produce spaghetti.  In general, muddled thinking,
 coupled with expediency, is what I think are the true precursors of
 spaghetti code.  The goto is an innocent tool that can be used for
 good or evil.

How true.

At least goto's have the merit of naming their target.

I have dealt with C code built on the original author's partiality for
200-line+ nested loops where it looked like every other line or so was
either a break or a continue, goto's without the name that don't
clearly state where they are going.

Thank goodness he was not familiar with setjmp/longjmp.

:-)

CJ

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


Python interpreter speed

2009-04-19 Thread Ryniek90

Hi.

Standard Python interpreter's implementation is written in C language. C 
code while compilation, is compilled into machine code (the fastest 
code). Python code is compiled into into byte-code which is also some 
sort of fast machine code. So why Python interpreter is slower than Java 
VM? Being written in C and compilled into machine code, it should be as 
fast as C/Asm code.

What's wrong with that?

Greets and thank you.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a programming language that is combination of PythonandBasic?

2009-04-19 Thread MRAB

Chris Jones wrote:

On Sun, Apr 19, 2009 at 04:35:27AM EDT, Hendrik van Rooyen wrote:

 Brian Blais   wrote:


[snip]

In my defense of the goto, I would like to make clear that I do not
support its use to produce spaghetti.  In general, muddled thinking,
coupled with expediency, is what I think are the true precursors of
spaghetti code.  The goto is an innocent tool that can be used for
good or evil.


How true.

At least goto's have the merit of naming their target.


Except in (classic) Pascal where they are unsigned integers (they still
need to be declared).


I have dealt with C code built on the original author's partiality for
200-line+ nested loops where it looked like every other line or so was
either a break or a continue, goto's without the name that don't
clearly state where they are going.

Thank goodness he was not familiar with setjmp/longjmp.


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


Re: Python interpreter speed

2009-04-19 Thread Krishnakant
I don't mean to start a flame war, but a productive debate will be
wonderful.  I have been writing heavy applications in java for a few
years untill recent past.
My experience is that python is not just fast but also zippy and smooth
when it comes to running the applications.

Infact I have a couple of softwares which were re coded in python for
this very reason.  So I would like to know real facts on this arguement.

Let me mention that out of these 2 apps one is a distributed application
with an rpc layer and other is a normal back and front end database
driven software.  both have heavy load on them and do a lot of number
crunching and complex calculations.

happy hacking.
Krishnakant.

On Sun, 2009-04-19 at 18:11 +0200, Ryniek90 wrote:
 Hi.
 
 Standard Python interpreter's implementation is written in C language. C 
 code while compilation, is compilled into machine code (the fastest 
 code). Python code is compiled into into byte-code which is also some 
 sort of fast machine code. So why Python interpreter is slower than Java 
 VM? Being written in C and compilled into machine code, it should be as 
 fast as C/Asm code.
 What's wrong with that?
 
 Greets and thank you.
 --
 http://mail.python.org/mailman/listinfo/python-list

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


Re: [ANN] pyxser-0.2r --- Python XML Serialization

2009-04-19 Thread Daniel Molina Wegener
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA512

Stefan Behnel stefan...@behnel.de
on Sunday 19 April 2009 02:25
wrote in comp.lang.python:


 Daniel Molina Wegener wrote:
 * Every serilization is made into unicode objects.
 
 Hmm, does that mean that when I serialise, I get a unicode object back?
 What about the XML declaration? How can a user create well-formed XML from
 your output? Or is that not the intention?

  Yes, if you serialize an object you get an XML string as
unicode object, since unicode objects supports UTF-8 and
some other encodings. Also you can deserialize the object ---
I mean convert the XML back to python object tree. Take a
look on the serializer output:

  http://coder.cl/software/pyxser/#id_example

 
 Stefan


Best regards,
- -- 
 .O. | Daniel Molina Wegener   | FreeBSD  Linux
 ..O | dmw [at] coder [dot] cl | Open Standards
 OOO | http://coder.cl/| FOSS Developer

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (FreeBSD)

iQIcBAEBCgAGBQJJ61B1AAoJEHxqfq6Y4O5N3qEQANT07GTyO17rFGMRhVsQ9IzK
qKcJl7tv15dYnLjJ+TPLRJ44ENPbQfUfrSevsY6ZTKK+MEqKcUej+41JKwImc8RT
GDILehrn1SgttALryKJyZlIWFFoVlIHflJL883bUd1S2nppY9yz5o9wBoq98KIbt
Rs3Azb8ZxVE9yABDQJbKhsBPZfa65wEzQo+MeDI+2xz301Rr9EttPJCFLMJFBeBt
0uvhwGXHOTKLwGsOOf//T1XNpg14QouEJJKGC1LjTSfAWvcXKsKdgLu4aAn6JGtW
zHqG2Uw3LvpBjgCwA5i1CTpmJxx8HhrDmVQyO6jdw65j5Ms9nCFD3BSezvvuYwtd
bvd0L7cHx/9TwGRifDDhAhBjdqR8lX8XyK8VSaNpjyf0ZCPmXk+AIDgINGzk2bG3
CkC8VfFDRJubwX0tFbtqXx8A1M7s5pu4DMdi8e9h5Bw+b/qfC0hCHIB7bViq2gH1
ELsC0xoffW1LxxowqjDlMDK1FymTLmErssQ7qCFLXBzxS7UHCcRMwKC+9v/NAbyU
wUuQNxRPASYnvfxVyQJdAurK9NNXQ5A58fclli6H/5Su+knDxOElXZ4ZMJt2Bbdg
9W2l99rBL1n50pfwiLezeRH3fhDXByNZiAPO2+ahdyDjyMekc/kqtTD898v841oG
UJyGm+fyw/kxEpI0R3E5
=mXFf
-END PGP SIGNATURE-
--
http://mail.python.org/mailman/listinfo/python-list


Re: Condition.wait(0.5) doesn't respect it's timeout

2009-04-19 Thread stephane . bisinger
On Apr 19, 4:50 pm, a...@pythoncraft.com (Aahz) wrote:
 The redraw thread should keep track of the last time it did a redraw;
 each time it receives an update event, it should check to see whether it
 has been more than a specified period of time since the last redraw.

That's what I do ;)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python interpreter speed

2009-04-19 Thread Pascal Chambon

Hello

I'm not expert in low level languages, but I'd say that Python and Java 
are compiled to bytecodes of similar level. The difference lies in the 
information contained in those bytecodes : java is statically typed, so 
attribute access and other basic operations are rather quick, allowing 
few levels of indirection. Whereas a python attribute lookup can involve 
a big number of operations (browsing the inheritance tree, querying 
__getattribute__, __get__ and all those magic methods...). That's in 
this magic of python that we have a loss of performance I think - 
that's both the power and the drawback of this (awesome) language.


Regards,
Pascal

PS : I guess core python developpers will have much more accurate things 
to say about it ^^


Ryniek90 a écrit :


Hi.

Standard Python interpreter's implementation is written in C language. 
C code while compilation, is compilled into machine code (the fastest 
code). Python code is compiled into into byte-code which is also some 
sort of fast machine code. So why Python interpreter is slower than 
Java VM? Being written in C and compilled into machine code, it should 
be as fast as C/Asm code.

What's wrong with that?

Greets and thank you.
--
http://mail.python.org/mailman/listinfo/python-list





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


The Python standard library and PEP8

2009-04-19 Thread Emmanuel Surleau
Hi there,

Exploring the Python standard library, I was surprised to see that several 
packages (ConfigParser, logging...) use mixed case for methods all over the 
place. I assume that they were written back when the Python styling 
guidelines were not well-defined.

Given that it's rather irritating (not to mention violating the principle of 
least surprise) to have this inconsistency, wouldn't it make sense to clean 
up the API by marking old-style, mixed-case methods as deprecated (but 
keep them around anyway) and add equivalent methods following the 
lowercase_with_underscores convention?

On an unrelated note, it would be *really* nice to have a length property on 
strings. Even Java has that!

Cheers,

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


Re: Is there a programming language that is combination of Python andBasic?

2009-04-19 Thread Mensanator
On Apr 19, 3:51�am, Hendrik van Rooyen m...@microcorp.co.za wrote:
 Mensanator mens...@aol.com wrote:

 8 -- description of bugs in spaghetti ---

 Looks like that design really needed sorting out!

Since I was translating to Pascal, I couldn't
emulate that code if I wanted to.


 A programmer once said to me Why should I run it, I know
 how it works, I wrote it.

 Are you serious?

Absolutely.

 In my opinion, anybody who says this is not a programmer,
 but merely an arrogant idiot with a lot of misplaced self-
 confidence - somewhat like a permanent force corporal.

That might have contributed to the reason why we
din't sell too many systems.

The last product developed ran on an IBM RISC PC
using the PICK operating system. We sold nearly one.




 My reply: You only THINK you know how it works. _I_, on
 the other hand, ACTUALLY know how it works because I've
 run it.

 How did you manage to keep your reply so meek?

He got paid more than I did.

 You must be a really well brought up person.
 :-)

But not behind their backs. A program I created that
tested anuther programmer's attempt at making a hash
table was labeled HASHIT.

Said programmer was long gone when the customer called
and wanted to know why his 1 record database was
saying it was full when only 3000 employees had been
entered. Turned out that the hashing algorithm could
not access any more than 3000 of the 1 available
records. This isn't the kind of thing Field Service
is supposed to have to deal with.


 - Hendrik

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


Re: Is there a programming language that is combination of Python andBasic?

2009-04-19 Thread Mensanator
On Apr 19, 10:12�am, Scott David Daniels scott.dani...@acm.org
wrote:
 Hendrik van Rooyen wrote:
  Mensanator mens...@aol.com wrote:

  8 -- description of bugs in spaghetti ---

  Looks like that design really needed sorting out!

  A programmer once said to me Why should I run it, I know
  how it works, I wrote it.

  Are you serious?
  In my opinion, anybody who says this is not a programmer,
  but merely an arrogant idiot with a lot of misplaced self-
  confidence - somewhat like a permanent force corporal.

  My reply: You only THINK you know how it works. _I_, on
  the other hand, ACTUALLY know how it works because I've
  run it.

  How did you manage to keep your reply so meek?
  You must be a really well brought up person.
  :-)

 Possibly because the proper reply was probably, You only THINK
 you know how it works. _I_, on the other hand, know how it behaves,
 even if I don't know how it was supposed to work.

Probably more accurate as his .exe file crashed
immediately when executed. That's what lead me to
supect he never ran it.


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


print as a function in 2.5 ?

2009-04-19 Thread Stef Mientki

hello,

For several reasons I still use Python version 2.5.
I understand that the print-statement will be replaced in Python version 
3.0.


At the moment I want to extend the print statement with an optional 
traceback.

So I've 2 options:
1- make a new function, like eprint (), where e stands for extended 
print

2- make a function print() that has the extended features

Now I guess that one of the reasons to change print from a statement to 
a function,

is the option to override and extend it.
If that's so, choice 2 would be the best choice.
Is that assumption correct ?

Suppose the second choice is the best,
I can now create a function print,
and have the best of 2 worlds, get my extension and being prepared for 
the future.


def print ( *args ) :
   for arg in args :
   print arg,
   print (' Print Traceback ')
   do_extended printer actions

Now doesn't seem to be allowed,
nor is there an import from __future__  :-(

What's the best solution (other than moving to 2.6 or up ?

thanks,
Stef Mientki
--
http://mail.python.org/mailman/listinfo/python-list


Interest in generational GC for Python

2009-04-19 Thread Borked Pseudo Mailed
Hello,

Is there any interest in generational garbage collection in Python these days ?

Anyone working on it ?

Thanks

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


Re: Is there a programming language that is combination of Python and Basic?

2009-04-19 Thread Zaphod
On Sun, 19 Apr 2009 09:09:07 -0400, D'Arcy J.M. Cain wrote:

 On Sun, 19 Apr 2009 05:08:32 GMT
 Zaphod zap...@beeblebrox.net wrote:
 Friend of mine made a really nice asm development environment for his
 home made OS.  Too bad he didn't have any marketing skills.
 
 Was your friend's name Gary Kildall? :-)

Nope - Craig Carmichael.  The OS was originally called OMEN but later 
changed to Oases and was initially designed to run on 68k based 
machines.  Craig just loves 68k assembly - less hair pulling required 
than x86.
--
http://mail.python.org/mailman/listinfo/python-list


Re: The Python standard library and PEP8

2009-04-19 Thread Pascal Chambon
I agree that there are still some styling inconsistencies in python 
stdlib, but I'm not advocating a cleaning because I've always found 
camelCase much prettier than those multi_underscore_methods :p


Concerning the length property of strings, isn't the __len__() method 
sufficient ?
I know they're not usual in OOP languages, but builtins like len() and 
iter() might be better anyway, since they deal with some magical 
problems (CF special attributes lookups in the python documentation)



Regards,
Pascal

Emmanuel Surleau a écrit :

Hi there,

Exploring the Python standard library, I was surprised to see that several 
packages (ConfigParser, logging...) use mixed case for methods all over the 
place. I assume that they were written back when the Python styling 
guidelines were not well-defined.


Given that it's rather irritating (not to mention violating the principle of 
least surprise) to have this inconsistency, wouldn't it make sense to clean 
up the API by marking old-style, mixed-case methods as deprecated (but 
keep them around anyway) and add equivalent methods following the 
lowercase_with_underscores convention?


On an unrelated note, it would be *really* nice to have a length property on 
strings. Even Java has that!


Cheers,

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


  







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


Re: print as a function in 2.5 ?

2009-04-19 Thread Christian Heimes
Stef Mientki wrote:
 Now doesn't seem to be allowed,
 nor is there an import from __future__  :-(
 
 What's the best solution (other than moving to 2.6 or up ?

The word 'print' is a reserved word like is, class or def. You can't
have a function named 'print' in Python 2.5. You have to call your
function eprint() or print_().

Christian

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


Re: The Python standard library and PEP8

2009-04-19 Thread Gabriel Genellina
En Sun, 19 Apr 2009 13:43:10 -0300, Emmanuel Surleau  
emmanuel.surl...@gmail.com escribió:


Exploring the Python standard library, I was surprised to see that  
several
packages (ConfigParser, logging...) use mixed case for methods all over  
the

place. I assume that they were written back when the Python styling
guidelines were not well-defined.


The name policy changed in March 2004. Before that, PEP8 said:

Function Names

  Plain functions exported by a module can either use the CapWords
  style or lowercase (or lower_case_with_underscores).  There is
  no strong preference, but it seems that the CapWords style is
  used for functions that provide major functionality
  (e.g. nstools.WorldOpen()), while lowercase is used more for
  utility functions (e.g. pathhack.kos_root()).

The current version says:

Function Names

  Function names should be lowercase, with words separated by  
underscores

  as necessary to improve readability.

  mixedCase is allowed only in contexts where that's already the
  prevailing style (e.g. threading.py), to retain backwards  
compatibility.


Given that it's rather irritating (not to mention violating the  
principle of
least surprise) to have this inconsistency, wouldn't it make sense to  
clean

up the API by marking old-style, mixed-case methods as deprecated (but
keep them around anyway) and add equivalent methods following the
lowercase_with_underscores convention?


The threading module has such aliases, but there are no plans for mass  
renaming all the stdlib that I know of. You'll have to live with this  
inconsistency.


On an unrelated note, it would be *really* nice to have a length  
property on

strings. Even Java has that!


Why would it be nice to have? I never missed it...

--
Gabriel Genellina

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


Re: print as a function in 2.5 ?

2009-04-19 Thread Pascal Chambon

Hello,

I had found some article on this some months ago, can't remember where 
exactly...


But if you don't want harassments, I'd just advise you to create a 
function with a properly specific name (like exprint()), and to make 
it mimic closely the signature and behaviour of Py3k's print() function.
That way, if one day you switch to upper versions, a simple mass text 
replacing operation on all your files will do it in an instant B-)


Regards,
Pascal

Stef Mientki a écrit :


hello,

For several reasons I still use Python version 2.5.
I understand that the print-statement will be replaced in Python 
version 3.0.


At the moment I want to extend the print statement with an optional 
traceback.

So I've 2 options:
1- make a new function, like eprint (), where e stands for 
extended print

2- make a function print() that has the extended features

Now I guess that one of the reasons to change print from a statement 
to a function,

is the option to override and extend it.
If that's so, choice 2 would be the best choice.
Is that assumption correct ?

Suppose the second choice is the best,
I can now create a function print,
and have the best of 2 worlds, get my extension and being prepared for 
the future.


def print ( *args ) :
   for arg in args :
   print arg,
   print (' Print Traceback ')
   do_extended printer actions

Now doesn't seem to be allowed,
nor is there an import from __future__  :-(

What's the best solution (other than moving to 2.6 or up ?

thanks,
Stef Mientki
--
http://mail.python.org/mailman/listinfo/python-list





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


Re: The Python standard library and PEP8

2009-04-19 Thread Paul Hankin
On Apr 19, 7:37 pm, Gabriel Genellina gagsl-...@yahoo.com.ar
wrote:
 The threading module has such aliases, but there are no plans for mass  
 renaming all the stdlib that I know of. You'll have to live with this  
 inconsistency.

It's been fixed in Python 3.0!

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


Re: can python access OS level features like bash scripting?

2009-04-19 Thread Gabriel Genellina
En Sun, 19 Apr 2009 08:16:15 -0300, Krishnakant hackin...@gmail.com  
escribió:



I need to create an installer and an executable file for my python
program for gnu/linux.

The install script has to put the package into site-packages folder
where all other libraries reside.  Then put the executable file
into /usr/bin as other files.


Write a setup.py script using the distutils package:
http://docs.python.org/distutils/index.html


I believe putting files into proper places is pritty easy (may be some
one will instantly reply to the issue of putting the executable file and
libraries in place ).  But to do the database based activities, I need
python-psycopg2 module for postgresql in the first place.  So is it
possible for python to self download and install all the necessary
modules on to the client machine?


You said you want to create a .deb -- list the required dependencies there.


Even regarding the executable, I am confused on using bash as the script
for writing the executable which can then do some thing like python -c
and call the modules, or write this executable code in a main.py and put
that file into the executable path i.e /usr/bin.


I've seen both a bash script with a single line: python path/to/main.py,  
and a Python script that just imports some modules and then calls the main  
function. Perhaps bash is more useful if your program (or any library)  
requires some environment variables to be set.


--
Gabriel Genellina

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


Re: The Python standard library and PEP8

2009-04-19 Thread Gabriel Genellina
En Sun, 19 Apr 2009 14:52:23 -0300, Paul Hankin paul.han...@gmail.com  
escribió:



On Apr 19, 7:37 pm, Gabriel Genellina gagsl-...@yahoo.com.ar
wrote:

The threading module has such aliases, but there are no plans for mass  
renaming all the stdlib that I know of. You'll have to live with this  
inconsistency.


It's been fixed in Python 3.0!


What do you mean fixed?

Python 3.0.1 (r301:69561, Feb 13 2009, 20:04:18) [MSC v.1500 32 bit  
(Intel)] on win32

Type help, copyright, credits or license for more information.

from threading import Thread
t = Thread()
t.name = foo
t.getName()

'foo'

t.setName(bar)
t.name

'bar'

Both the old camelCase methods and the new property are still there.  
They're not even deprecated yet.


--
Gabriel Genellina

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


Re: Is there a programming language that is combination of PythonandBasic?

2009-04-19 Thread Scott David Daniels

Chris Jones wrote:

...
Intellectually, assembler programming is the less demanding since its
level of abstraction does not go any further than mapping a few binary
numbers to a small set of usually well-chosen mnemonics. 


Unless it features a powerful macro-language that lets the apprentice
create his own high-level patois on top of the assembler, that is.


No, I've dealt with an assembler named 'SLOE' that had an elaborate
mechanism for laying out code in memory in a way that the CPU would
be happy with.  Between that and the instruction prefect, the thing
was famously called immune to programming.

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


Re: Condition.wait(0.5) doesn't respect it's timeout

2009-04-19 Thread Piet van Oostrum
 stephane.bisin...@gmail.com (sb) wrote:

 By the way, I wonder why you need a timeout in your wait. I think the
 notifications should be sufficient to keep the gui updated.

sb The reason is simple: when first downloading the contactss list,  I
sb receive a swarm of *Updated() calls, so if I redraw every time I get a
sb very bad visual effect and I waste a lot of CPU redrawing something
sb that will change in a very very short time. Hence the time
sb constraint... I couldn't come up with something smarter, so...

while time.time() - t  0.5 or not self._modified:
print  sys.stderr, Going to sleep\n
self._mod_lock.wait(timeout=1)
print  sys.stderr, Ok time to see if we must repaint
self.__repaint()
t = time.time()

But the timeout thing will continue after that, so you have a continuous
polling loop which wastes some CPU time. I think what you want can be
more easily achieved by doing a sleep(0.5) before the outer while loop,
i.e. as the first statement in __thread_run.
-- 
Piet van Oostrum p...@cs.uu.nl
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: Interest in generational GC for Python

2009-04-19 Thread Scott David Daniels

Borked Pseudo Mailed wrote:

Hello,

Is there any interest in generational garbage collection in Python these days ?

Anyone working on it ?

Thanks


Not really all that useful for CPython (you cannot move live objects,
without breaking faith with C-coded extensions).  PyPy would be where
to look for that work (and perhaps FePy or unladen swallow).

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


Re: Overriding methods per-object

2009-04-19 Thread Pavel Panchekha
On Apr 18, 9:43 pm, Aaron Brady castiro...@gmail.com wrote:
 On Apr 17, 9:41 pm, Steven D'Aprano st...@remove-this-

 cybersource.com.au wrote:
  On Fri, 17 Apr 2009 18:22:49 -0700, Pavel Panchekha wrote:
   I've got an object which has a method, __nonzero__ The problem is, that
   method is attached to that object not that class

   a = GeneralTypeOfObject()
   a.__nonzero__ = lambda: False
   a.__nonzero__()
   False

   But:

   bool(a)
   True

   What to do?

  (1) Don't do that.

  (2) If you *really* have to do that, you can tell the class to look at
  the instance:

  class GeneralTypeOfObject(object):
      def __nonzero__(self):
          try:
              return self.__dict__['__nonzero__']
          except KeyError:
              return something

 snip

 I think you need to call the return, unlike you would in
 '__getattr__'.
              return self.__dict__['__nonzero__']( )

 You're free to use a different name for the method too.
              return self.custom_bool( )

 And you don't even have to implement an ABC.  Er... /have/ to, that
 is.

I got it working. Thanks!
--
http://mail.python.org/mailman/listinfo/python-list


Re: The Python standard library and PEP8

2009-04-19 Thread Emmanuel Surleau
On Sunday 19 April 2009 19:37:59 Gabriel Genellina wrote:
 En Sun, 19 Apr 2009 13:43:10 -0300, Emmanuel Surleau

 emmanuel.surl...@gmail.com escribió:
  Exploring the Python standard library, I was surprised to see that
  several
  packages (ConfigParser, logging...) use mixed case for methods all over
  the
  place. I assume that they were written back when the Python styling
  guidelines were not well-defined.

 The name policy changed in March 2004. Before that, PEP8 said:

  Function Names

Plain functions exported by a module can either use the CapWords
style or lowercase (or lower_case_with_underscores).  There is
no strong preference, but it seems that the CapWords style is
used for functions that provide major functionality
(e.g. nstools.WorldOpen()), while lowercase is used more for
utility functions (e.g. pathhack.kos_root()).

 The current version says:

  Function Names

Function names should be lowercase, with words separated by
 underscores
as necessary to improve readability.

mixedCase is allowed only in contexts where that's already the
prevailing style (e.g. threading.py), to retain backwards
 compatibility.

Ah, that makes sense.

  Given that it's rather irritating (not to mention violating the
  principle of
  least surprise) to have this inconsistency, wouldn't it make sense to
  clean
  up the API by marking old-style, mixed-case methods as deprecated (but
  keep them around anyway) and add equivalent methods following the
  lowercase_with_underscores convention?

 The threading module has such aliases, but there are no plans for mass
 renaming all the stdlib that I know of. You'll have to live with this
 inconsistency.

Damn.

  On an unrelated note, it would be *really* nice to have a length
  property on
  strings. Even Java has that!

 Why would it be nice to have? I never missed it...

First off, it's pretty commonplace in OO languages. Secondly, given the 
number of methods available for the string objects, it is only natural to 
assume that dir(a) would show me a len() or length() or size() method. 
Having to use a function for such a mundane operation feels unnatural and 
not OO.

Cheers,

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


Re: [ANN] pyxser-0.2r --- Python XML Serialization

2009-04-19 Thread Stefan Behnel
Daniel Molina Wegener wrote:
 Stefan Behnel stefan...@behnel.de
 on Sunday 19 April 2009 02:25
 wrote in comp.lang.python:
 
 
 Daniel Molina Wegener wrote:
 * Every serilization is made into unicode objects.
 Hmm, does that mean that when I serialise, I get a unicode object back?
 What about the XML declaration? How can a user create well-formed XML from
 your output? Or is that not the intention?
 
   Yes, if you serialize an object you get an XML string as
 unicode object, since unicode objects supports UTF-8 and
 some other encodings.

That's not what I meant. I was wondering why you chose to use a unicode
string instead of a byte string (which XML is defined for). If your only
intention is to deserialise the unicode string into a tree, that may be
acceptable. However, as soon as you start writing the data to a file or
through a network pipe, or pass it to an XML parser, you'd better make it
well-formed XML. So you either need to encode it as UTF-8 (for which you do
not need a declaration), or you will need to encode it in a different byte
encoding, and then prepend a declaration yourself. In any case, this is a
lot more overhead (and cumbersome for users) than writing out a correctly
serialised byte string directly.

You seemed to be very interested in good performance, so I don't quite
understand why you want to require an additional step with a relatively
high performance impact that only makes it harder for users to use the tool
correctly.

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


Re: PEP 401

2009-04-19 Thread Stefan Behnel
alessiogiovanni.bar...@gmail.com wrote:
 Are 19 days that I read this PEP; it's all true?

Yep. Actually, the Cython project was lucky that the FLUFL did not
recognise it as an alternative implementation of Python. That way, we can
easily finish up world domination, say, 10-20 years before Python on Parrot
reaches 2.7 feature completeness.

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


Re: How to create a virtual serial port?

2009-04-19 Thread Nick Craig-Wood
Grant Edwards gra...@visi.com wrote:
  On 2009-04-12, JanC use...@janc.invalid wrote:
  Grant Edwards wrote:
 
  On 2009-04-10, Stuart Davenport stuart.davenp...@gmail.com wrote:
 
  I am trying to work out if its possible, to create a virtual serial
  port with Python?
 
  On Linux: no.
 
  I wonder if there is no way to emulate ptys from userspace?
 
  Didn't I just answer that question?
 
  On Linux: no.

Actually you could do it with an LD_PRELOAD library

Intercept open(/dev/ttyS0,...).  You'd need to intercept ioctl(),
read(), write(), close() etc too.

Messy but possible.

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


How can I get path/name of the softlink to my python script when executing it

2009-04-19 Thread Saravanan Shanmugham (sarvi)
 
Hi,
I am writiing a script say wabexec in python
I will then have softlinks from other softlinks like  ls, waf,hello,
etc that are in the same directory and pointing to wabexec.
 
When some executes ./waf or ./hello and wabexec gets invoked because of
the softlink, how do I find out from within wabexec how it was invoked?
was it throug waf or hello, etc.
 
both __file__ and sys.arg0[] seem to have wabexec not the name of the
softlink.
 
Any ideas?
 
Sarvi
--
http://mail.python.org/mailman/listinfo/python-list


Re: Condition.wait(0.5) doesn't respect it's timeout

2009-04-19 Thread stephane . bisinger
On Apr 19, 7:21 pm, Piet van Oostrum p...@cs.uu.nl wrote:
                 while time.time() - t  0.5 or not self._modified:
                     print  sys.stderr, Going to sleep\n
                     self._mod_lock.wait(timeout=1)
                     print  sys.stderr, Ok time to see if we must repaint
                 self.__repaint()
                 t = time.time()

 But the timeout thing will continue after that, so you have a continuous
 polling loop which wastes some CPU time. I think what you want can be
 more easily achieved by doing a sleep(0.5) before the outer while loop,
 i.e. as the first statement in __thread_run.

Two boolean checks every half second is not a great waste; but
thinking about your solution I've come to agree that it is smarter and
more effective. Thank you again!
--
http://mail.python.org/mailman/listinfo/python-list


Re: The Python standard library and PEP8

2009-04-19 Thread Christian Heimes
Emmanuel Surleau wrote:
 First off, it's pretty commonplace in OO languages. Secondly, given the 
 number of methods available for the string objects, it is only natural to 
 assume that dir(a) would show me a len() or length() or size() method. 
 Having to use a function for such a mundane operation feels unnatural and 
 not OO.

If you replace the term OO with Java in your posting, then I'm going
to agree with you. Neither Java nor Python are pure object oriented
languages. A while ago a friend of mine called Java a class centric
programming language. I think that describes Java's coding philosophy
very good. Python has a different coding philosphy. You can't assume
that Java style development works with Python (and vice versa).

Now to your rant about len(). Python class may implement several
protocols with magic methods like __len__(), __iter__() or
__getitem__(). The magic methods start and begin with two _. When a
method implements the __len__() method then it supports len(). In Python
readability counts. Try import this in a Python shell.

PEP 8 is a coding guideline for the standard library. It's not a law.
Some modules are older than the PEP, other modules and libraries were
developed outside the core and added later. We had a long discussion
about PEP8'ing more code but eventually we decided against it. More
chances would break too much 3rd party code.

Christian

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


Re: The Python standard library and PEP8

2009-04-19 Thread Gabriel Genellina
En Sun, 19 Apr 2009 15:41:02 -0300, Emmanuel Surleau  
emmanuel.surl...@gmail.com escribió:

On Sunday 19 April 2009 19:37:59 Gabriel Genellina wrote:

En Sun, 19 Apr 2009 13:43:10 -0300, Emmanuel Surleau



 On an unrelated note, it would be *really* nice to have a length
 property on
 strings. Even Java has that!



Why would it be nice to have? I never missed it...


First off, it's pretty commonplace in OO languages. Secondly, given the
number of methods available for the string objects, it is only natural to
assume that dir(a) would show me a len() or length() or size() method.
Having to use a function for such a mundane operation feels unnatural and
not OO.


Perhaps in statically typed languages. Python is dynamic, so a x.length()  
requires a method lookup and that's expensive. len(x) on the contrary, can  
be optimized on a case by case basis -- it DOESN'T translate to  
x.__len__() as some might think.
See  
http://www.python.org/doc/faq/general/#why-does-python-use-methods-for-some-functionality-e-g-list-index-but-functions-for-other-e-g-len-list


On a side note, there is an alternative to dir(), more human-friendly:  
http://inky.github.com/see/


py see(a)
  ?   []   in   +   *   %  =   ==   !=  =   len()
.capitalize()
  .center()   .count()   .decode()   .encode()   .endswith()
.expandtabs()

  .find()   .format()   .index()   .isalnum()   .isalpha()   .isdigit()
  .islower()   .isspace()   .istitle()   .isupper()   .join()   .ljust()
  .lower()   .lstrip()   .partition()   .replace()   .rfind()   .rindex()
  .rjust()   .rpartition()   .rsplit()   .rstrip()   .split()
.splitlines()
  .startswith()   .strip()   .swapcase()   .title()   .translate()
.upper()

  .zfill()

You can see len() there.

--
Gabriel Genellina

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


Re: print as a function in 2.5 ?

2009-04-19 Thread Tino Wildenhain

Stef Mientki wrote:

hello,

For several reasons I still use Python version 2.5.
I understand that the print-statement will be replaced in Python version 
3.0.


At the moment I want to extend the print statement with an optional 
traceback.

So I've 2 options:
1- make a new function, like eprint (), where e stands for extended 
print

2- make a function print() that has the extended features


There is a 3rd option: hook yourself in the output stream and just
climb the call stack in the write() method. This works (done that
myself for easy debugging)

The other way if you want to selectively do so, either use
a form of log (because why must it be print if the output
is debugging information?) or instead of hooking sys.stdout,
use another output stream and print debug, ... to it.

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


Re: print as a function in 2.5 ?

2009-04-19 Thread Stef Mientki

Tino Wildenhain wrote:

Stef Mientki wrote:

hello,

For several reasons I still use Python version 2.5.
I understand that the print-statement will be replaced in Python 
version 3.0.


At the moment I want to extend the print statement with an optional 
traceback.

So I've 2 options:
1- make a new function, like eprint (), where e stands for 
extended print

2- make a function print() that has the extended features


There is a 3rd option: hook yourself in the output stream and just
climb the call stack in the write() method. This works (done that
myself for easy debugging)

The other way if you want to selectively do so, either use
a form of log (because why must it be print if the output
is debugging information?) or instead of hooking sys.stdout,
use another output stream and print debug, ... to it.


thanks guys,
for the moment I'll stick to another name v3print so it can easily be 
replaced.

The third option (by Tino) looks interesting,
but is not suitable in my case,
because the program I'm writing is a kind of IDE (Integrated Development 
Environment),

where the user can create programs, and must have full control over stdout.

cheers,
Stef


Regards
Tino


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


Re: The Python standard library and PEP8

2009-04-19 Thread Carl Banks
On Apr 19, 11:41 am, Emmanuel Surleau emmanuel.surl...@gmail.com
wrote:
 First off, it's pretty commonplace in OO languages. Secondly, given the
 number of methods available for the string objects, it is only natural to
 assume that dir(a) would show me a len() or length() or size() method.
 Having to use a function for such a mundane operation feels unnatural and
 not OO.


My advice in this situation is to think of len() as an operator that
has the syntax of a regular function.  Apart from not having special
syntax, len() is no different from any other operator.  It has an
associated method, __len__(), that allows objects to customize their
behavior when the operator is applied to them.

As to why they made len() and operator, it is really just a language
design decision.  By making len() into a function, rather than a
method, GvR was essentially saying, Determining length of a sequence
is a common and familiar enough operation that it deserves status
above a mere method call, even if we don't have a special syntax for
it.

I am not, mind you, arguing either for or against len being an
operator (I don't really think it matters much either way); I'm just
saying there is a rationale behind it.


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


Re: The Python standard library and PEP8

2009-04-19 Thread Aahz
In article mailman.4175.1240166489.11746.python-l...@python.org,
Emmanuel Surleau  emmanuel.surl...@gmail.com wrote:
On Sunday 19 April 2009 19:37:59 Gabriel Genellina wrote:
 En Sun, 19 Apr 2009 13:43:10 -0300, Emmanuel Surleau
 emmanuel.surl...@gmail.com escribi=F3:
 
 On an unrelated note, it would be *really* nice to have a length
 property on strings. Even Java has that!

 Why would it be nice to have? I never missed it...

First off, it's pretty commonplace in OO languages.

What makes you think Python is an OO language?  What kind of OO
language allows you to do this:

def square(x):
return x*x

for i in range(10):
print square(x)
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

If you think it's expensive to hire a professional to do the job, wait
until you hire an amateur.  --Red Adair
--
http://mail.python.org/mailman/listinfo/python-list


Re: The Python standard library and PEP8

2009-04-19 Thread Emmanuel Surleau
 Perhaps in statically typed languages. Python is dynamic, so a x.length()
 requires a method lookup and that's expensive. len(x) on the contrary, can
 be optimized on a case by case basis -- it DOESN'T translate to
 x.__len__() as some might think.
 See
 http://www.python.org/doc/faq/general/#why-does-python-use-methods-
for-some
-functionality-e-g-list-index-but-functions-for-other-e-g-len-list

I don't know... the gist of the FAQ you link to is that's legacy code and we 
don't want to change it in order not to break code. It doesn't try to justify 
the continued existence of len() and friends with technical arguments. I'll 
grant you that avoiding a method lookup is cheaper, another question is 
whether the difference would be noticeable in practice. I'd say that if 
methods were such a bad thing, that would put in question the 
implementation of the whole OO paradigm in Python, no?

 On a side note, there is an alternative to dir(), more human-friendly:
 http://inky.github.com/see/

 py see(a)
?   []   in   +   *   %  =   ==   !=  =   len()
 .capitalize()
.center()   .count()   .decode()   .encode()   .endswith()
 .expandtabs()
.find()   .format()   .index()   .isalnum()   .isalpha()   .isdigit()
.islower()   .isspace()   .istitle()   .isupper()   .join()   .ljust()
.lower()   .lstrip()   .partition()   .replace()   .rfind()   .rindex()
.rjust()   .rpartition()   .rsplit()   .rstrip()   .split()
 .splitlines()
.startswith()   .strip()   .swapcase()   .title()   .translate()
 .upper()
.zfill()

 You can see len() there.

Nice! That's indeed more readable than dir().

Cheers,

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


Re: The Python standard library and PEP8

2009-04-19 Thread Emmanuel Surleau
On Sunday 19 April 2009 21:46:46 Christian Heimes wrote:
 Emmanuel Surleau wrote:
  First off, it's pretty commonplace in OO languages. Secondly, given the
  number of methods available for the string objects, it is only natural to
  assume that dir(a) would show me a len() or length() or size() method.
  Having to use a function for such a mundane operation feels unnatural 
and
  not OO.

 If you replace the term OO with Java in your posting, then I'm going
 to agree with you. Neither Java nor Python are pure object oriented
 languages. A while ago a friend of mine called Java a class centric
 programming language. I think that describes Java's coding philosophy
 very good. Python has a different coding philosphy. You can't assume
 that Java style development works with Python (and vice versa).

I don't know if it's Java-style development - you use a method to retrieve 
the length of a string in C++, Ruby or Javascript. Are you trying to say that 
having len() as a method/property is not object-oriented? The FAQ link in 
Gabriel Genellina's posting justifies the existence len as a function as 
historical. It does not seem to serve much purpose now. If there is a deeper 
reason why len as a function makes more sense than len as a method, 
I'd be (genuinely) curious to hear it.

 Now to your rant about len(). Python class may implement several
 protocols with magic methods like __len__(), __iter__() or
 __getitem__(). The magic methods start and begin with two _. When a
 method implements the __len__() method then it supports len(). In Python
 readability counts. Try import this in a Python shell.

Not trying to attack you, but I'm not sure of what you're trying to say here. 
That len(a) is more readable than a.len()?

 PEP 8 is a coding guideline for the standard library. It's not a law.
 Some modules are older than the PEP, other modules and libraries were
 developed outside the core and added later. We had a long discussion
 about PEP8'ing more code but eventually we decided against it. More
 chances would break too much 3rd party code.

I was not suggesting breaking. What's wrong with aliasing and marking as 
deprecated?

Also, given that Python 3000 breaks backward compatibility anyway, I don't 
see the point in not cleaning up the standard library completely and get rid 
of CamelCase once and for all.

Cheers,

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


Re: The Python standard library and PEP8

2009-04-19 Thread Emmanuel Surleau
 What makes you think Python is an OO language? 

Python is a dynamic object-oriented programming language that can be used 
for many kinds of software development.

First line on the Python official website. Was this a trick question?

 What kind of OO
 language allows you to do this:

 def square(x):
 return x*x

 for i in range(10):
 print square(x)

Ruby, for instance.

Allowing for procedural-style programming does not mean that a language 
does not implement (even imperfectly) an OO paradigm.

Cheers,

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


Re: How can I get path/name of the softlink to my python script when executing it

2009-04-19 Thread Pascal Chambon

Hello

I fear that in this case the whole indirection operations on softlink 
occur only in the shell, and that the final command is only executed as 
if it were called directly on the real file...


Have you tried typing python ./waf, to see how the resolution occurs 
in that case ?


Regards,
Pascal



Saravanan Shanmugham (sarvi) a écrit :
 
Hi,

I am writiing a script say wabexec in python
I will then have softlinks from other softlinks like  ls, 
waf,hello, etc that are in the same directory and pointing to wabexec.
 
When some executes ./waf or ./hello and wabexec gets invoked because 
of the softlink, how do I find out from within wabexec how it was 
invoked? was it throug waf or hello, etc.
 
both __file__ and sys.arg0[] seem to have wabexec not the name of the 
softlink.
 
Any ideas?
 
Sarvi



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


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


Re: can python access OS level features like bash scripting?

2009-04-19 Thread Krishnakant
On Sun, 2009-04-19 at 14:55 -0300, Gabriel Genellina wrote:

 Write a setup.py script using the distutils package:
 http://docs.python.org/distutils/index.html
 
So that can distutil do the work of setting up the database and can it
find for itself if psycopg2 and other related libraries are installed?
I am going to create a deb file, so is it a good idea to some how have
the deb rules execute the setup.py file of the distutils?

Besides, I will also like to create a single file containing all the
modules i need as dependencies so even if a user does not have internet,
we can still install the package on that machine.

So will it be a good idea to let distutils do every thing I had
described about putting files in the place and having the script copyed
to /usr/bin etc?

happy hacking.
Krishnakant.
 


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


Re: send() to a generator in a for loop with continue(val)??

2009-04-19 Thread Dale Roberts
On Apr 17, 10:07 pm, Aaron Brady castiro...@gmail.com wrote:
 You can do it with a wrapping generator.  I'm not sure if it
 interferes with your needs.  It calls 'next' the first time, then just
 calls 'send' on the parameter with the value you send it.

Aaron,

Thanks for the hint. I'd made a modified version of my generator that
was for loop aware and had two yields in it, but this seemed very
fragile and hackish to me, and left my generator only usable inside a
for loop.

The wrapper method seems to be a much better way to go.

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


ANN: Mock 0.5.0 Release

2009-04-19 Thread Fuzzyman
Mock 0.5.0 has just been released.

* Mock Homepage http://www.voidspace.org.uk/python/mock/
* Download Mock 0.5.0 release (zip) 
http://www.voidspace.org.uk/downloads/mock-0.5.0.zip
* Mock Documentation as a PDF http://www.voidspace.org.uk/downloads/mock.pdf
* Mock entry on PyPI http://pypi.python.org/pypi/mock/
* Repository and Issue Tracker on Google Code http://code.google.com/p/mock/

This *isn't* backwards compatible as it cleans up the API in a few
ways, but they're all good changes I promise. {sm;:wink:}

One of the new features is that the Mock class now supports wrapping
objects; using the ``wraps`` keyword.

One of the other big changes is that the documentation is now built
with the ever-wonderful Sphinx, so the homepage is new and there also
a PDF of the documentation.

Mock is a library for the creation of simple mock objects that track
how they are used so that you can make assertions. It uses the action -
 assertion pattern rather than the record - replay pattern. Action -
 assertion puts your tests after you have used the objects, which
seems more natural and means that you can make assertions about only
the behavior you are interested in. Mock also contains two decorators
(``patch`` and ``patch_object``) which make it easy to safely mock out
dependencies in the module under test purely within the scope of the
test itself (unpatching is done automatically on exit whether or not
the test passes). One of the changes in this release is that these
decorators also become context managers allowing them to be used with
the 'with statement'.

Mock can be installed with:

``easy_install mock``

The changelog for all changes in this release is:

* Made DEFAULT part of the public api.
* Documentation built with Sphinx.
* ``side_effect`` is now called with the same arguments as the mock is
called with and
  if returns a non-DEFAULT value that is automatically set as the
``mock.return_value``.
* ``wraps`` keyword argument used for wrapping objects (and passing
calls through to the wrapped object).
* ``Mock.reset`` renamed to ``Mock.reset_mock``, as reset is a common
API name.
* ``patch`` / ``patch_object`` are now context managers and can be
used with ``with``.
* A new 'create' keyword argument to patch and patch_object that
allows them to patch
  (and unpatch) attributes that don't exist. (Potentially unsafe to
use - it can allow
  you to have tests that pass when they are testing an API that
doesn't exist - use at
  your own risk!)
* The methods keyword argument to Mock has been removed and merged
with spec. The spec
  argument can now be a list of methods or an object to take the spec
from.
* Nested patches may now be applied in a different order (created
mocks passed
  in the opposite order). This is actually a bugfix.
* patch and patch_object now take a spec keyword argument. If spec is
  passed in as 'True' then the Mock created will take the object it is
replacing
  as its spec object. If the object being replaced is a class, then
the return
  value for the mock will also use the class as a spec.
* A Mock created without a spec will not attempt to mock any magic
methods / attributes
  (they will raise an ``AttributeError`` instead).

Many thanks to all those who gave feedback, feature requests and
patches!

What *isn't* in 0.5.0 is support for mocking magic methods. I do have
a technique in mind for this, which I implemented for the container
methods. It is very clean, but different from the pattern used to mock
out other methods. As I'm not currently using it I'm going to wait
until I need it and see if it works well in practise.

If you're interested in trying it, the code (with full documentation)
in a 'magics branch':

* http://code.google.com/p/mock/source/browse/#svn/branches/magics
--
http://mail.python.org/mailman/listinfo/python-list


RE: How can I get path/name of the softlink to my python script when executing it

2009-04-19 Thread Saravanan Shanmugham (sarvi)
Sorry. I should have responded earlier to close this thread. It was my 
programming error.
 
Both sys.argv[0] and __file__ do point to the name and path of the softlink and 
not the actual program it is linked to.
 
So. Soryy. My bad programming got in my way.
 
Sarvi



From: Pascal Chambon [mailto:chambon.pas...@wanadoo.fr] 
Sent: Sunday, April 19, 2009 2:36 PM
To: Saravanan Shanmugham (sarvi)
Cc: python-list@python.org
Subject: Re: How can I get path/name of the softlink to my python script when 
executing it
Importance: High


Hello

I fear that in this case the whole indirection operations on softlink occur 
only in the shell, and that the final command is only executed as if it were 
called directly on the real file...

Have you tried typing python ./waf, to see how the resolution occurs in that 
case ?

Regards, 
Pascal



Saravanan Shanmugham (sarvi) a écrit : 

 
Hi,
I am writiing a script say wabexec in python
I will then have softlinks from other softlinks like  ls, 
waf,hello, etc that are in the same directory and pointing to wabexec.
 
When some executes ./waf or ./hello and wabexec gets invoked because of 
the softlink, how do I find out from within wabexec how it was invoked? was it 
throug waf or hello, etc.
 
both __file__ and sys.arg0[] seem to have wabexec not the name of the 
softlink.
 
Any ideas?
 
Sarvi




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


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


Re: send() to a generator in a for loop with continue(val)??

2009-04-19 Thread Dale Roberts
On Apr 19, 6:10 am, Peter Otten __pete...@web.de wrote:
 ...
 I only just started reading Beazley's presentation, it looks interesting.
 Thanks for the hint!

 Are you currently using coroutines in Python? If so, what kind of practical
 problems do they simplify for you?

I thought I'd chime in with an application too. I am using this
mechanism to implement a state machine. I read through Beazley's
presentation too - wow, lots of ideas in there.

For my simple state machine, I am using a very simple trampoline
function (see his slides starting at about #172). My run routine is
a bit different, but the idea is similar.

I'm using this to present images to a test subject (a person looking
at a computer screen), and the person's responses guide the state
machine. So I need to get data in (the subject responses) and out (the
next image to be presented).

So I have violated The Beazley Principle of slide #195:

Keeping it Straight
  • If you are going to use coroutines, it is critically
important to not mix programming paradigms
together
  • There are three main uses of yield
 • Iteration (a producer of data)
 • Receiving messages (a consumer)
 • A trap (cooperative multitasking)
  • Do NOT write generator functions that try to
do more than one of these at once

...whoops!

But I think this is a valid use of the mechanism, in that it is very
localized and self contained to just the few routines that make up the
state machine. It works very well, makes it easy to implement the
state machine clearly, and is easy to understand and maintain.

I can see where it could get very confusing to use this mechanism in a
more general way.

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


Re: The Python standard library and PEP8

2009-04-19 Thread Martin P. Hellwig

Emmanuel Surleau wrote:
What makes you think Python is an OO language? 


Python is a dynamic object-oriented programming language that can be used 
for many kinds of software development.


First line on the Python official website. Was this a trick question?


What kind of OO
language allows you to do this:

def square(x):
return x*x

for i in range(10):
print square(x)


Ruby, for instance.

Allowing for procedural-style programming does not mean that a language 
does not implement (even imperfectly) an OO paradigm.




Besides, calling Python Object-Orientated is a bit of an insult :-). I 
would say that Python is Ego-Orientated, it allows me to do what I want.


--
MPH
http://blog.dcuktec.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a programming language that is combination of Python and Basic?

2009-04-19 Thread Tim Rowe
2009/4/19 Steven D'Aprano st...@remove-this-cybersource.com.au:

 GOTO, after all, is just a jump, and we use jumps in Python all the time:

 raise Exception
 break
 continue
 if... elif... else...
 for... else...
 etc.

So as a syllogism:
P1: GOTO is a jump;
P2: GOTO is bad.
C: Jumps are  bad.

And then by showing the conclusion is false, you believe you have
shown a contradiction? Try looking up Affirming the consequent!

GOTO is an /unstructured/ jump. Raise, break, continue, if, for and so
an are all /structured/ jumps.

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


Keyerror addhandler

2009-04-19 Thread Steven Macintyre
Hi all,

I'm wondering if anyone can assist me with this as I am very confused about
it now.

I am getting the following error;

Traceback (most recent call last):
  File /usr/lib/python2.4/logging/config.py, line 191, in fileConfig
logger.addHandler(handlers[hand])
KeyError: 'handler_mylogfileHandler'

My code:

import logging
import logging.config
import logging.handlers

#parse config file
logging.config.fileConfig(logging.conf)

#create logger
logger = logging.getLogger(pythonacro)

my config:

[loggers]
keys=root,pythonacro

[handlers]
keys=consoleHandler,mylogfileHandler

[formatters]
keys=simpleFormatter

[logger_root]
level=DEBUG
handlers=consoleHandler

[logger_pythonacro]
level=DEBUG
handlers=consoleHandler,mylogfileHandler
propagate=1
qualname=pythonacro

[handler_consoleHandler]
class=StreamHandler
level=DEBUG
formatter=simpleFormatter
args=(sys.stdout,)

[handler_mylogfileHandler]
class=RotatingFileHandler
level=DEBUG
formatter=simpleFormatter
args=('python_acro.log', 'a', 125829120, 5)
filename=python_acro.log
mode=a

[formatter_simpleFormatter]
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
datefmt=

As far as I can tell, this is correct according to logging-config-fileformat
and documentation found on google.

Any ideas?

Many thanks

Steven



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


Re: Keyerror addhandler

2009-04-19 Thread Diez B. Roggisch

Steven Macintyre schrieb:

Hi all,

I'm wondering if anyone can assist me with this as I am very confused about
it now.

I am getting the following error;

Traceback (most recent call last):
  File /usr/lib/python2.4/logging/config.py, line 191, in fileConfig
logger.addHandler(handlers[hand])
KeyError: 'handler_mylogfileHandler'


For me, that fails with

mac-dir:tmp deets$ python2.5 test.py
Traceback (most recent call last):
  File test.py, line 6, in module
logging.config.fileConfig(logging.conf)
  File 
/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/logging/config.py, 
line 84, in fileConfig

handlers = _install_handlers(cp, formatters)
  File 
/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/logging/config.py, 
line 149, in _install_handlers

klass = eval(klass, vars(logging))
  File string, line 1, in module
NameError: name 'RotatingFileHandler' is not defined
mac-dir:tmp deets$

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


Re: Useful MySQL Routines

2009-04-19 Thread Lawrence D'Oliveiro
In message mailman.4160.1240152762.11746.python-l...@python.org, Tino 
Wildenhain wrote:

 Lawrence D'Oliveiro wrote:

 In message mailman.4148.1240135989.11746.python-l...@python.org, Tino
 Wildenhain wrote:
 
 Btw, the bulkinserter could be better done by using executemany
 and select usefull batch sizes.
 
 Hmm, I've never bothered with executemany. The code as written copes
 comfortably with 10,000 records or so.
 
 Would be interesting to see the difference.

Go on, give it a try and let us know how it goes.

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


Re: QT , Wxwidgets are not just UI framework ?

2009-04-19 Thread Deep_Feelings
thank you so much

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


Re: The Python standard library and PEP8

2009-04-19 Thread Dan Sommers
On Sun, 19 Apr 2009 18:43:10 +0200, Emmanuel Surleau wrote:

 On an unrelated note, it would be *really* nice to have a length
 property on strings. Even Java has that!

And even in Java, they have sin(x) rather than x.sin().

Dan

-- 
Dan Sommers   A death spiral goes clock-
http://www.tombstonezero.net/dan/   wise north of the equator.
Atoms are not things. -- Werner Heisenberg  -- Dilbert's PHB

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


  1   2   >